@yuriai/web 0.1.2-beta.2 → 0.1.3

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.
Files changed (66) hide show
  1. package/dist/assets/{AssistantView-CdO4imc6.js → AssistantView-BJyGm9Js.js} +3 -3
  2. package/dist/assets/{DiagramView-ALA0pyKm.js → DiagramView-BRK8rzVX.js} +1 -1
  3. package/dist/assets/{ImageLoadingPlaceholder-BPp8BN0a.js → ImageLoadingPlaceholder-CGHGcrEo.js} +1 -1
  4. package/dist/assets/{LoadingImage-DvtPqFRw.js → LoadingImage-BG9q4Tm_.js} +1 -1
  5. package/dist/assets/MarkdownRenderer-D4Ba9SUF.js +2 -0
  6. package/dist/assets/{MarkdownRendererImpl-XEO441ER.js → MarkdownRendererImpl-Dt0t56Yx.js} +1 -1
  7. package/dist/assets/{MarkstreamRendererImpl-C_-nyQrd.js → MarkstreamRendererImpl-rGcpWsHj.js} +1 -1
  8. package/dist/assets/{MobileDetailNavigation-nJl1j85R.js → MobileDetailNavigation-Cyp_3Hha.js} +1 -1
  9. package/dist/assets/{MobileShareBridge-DZ-a1-hd.js → MobileShareBridge-BQnwoSB3.js} +1 -1
  10. package/dist/assets/MobileTabPageHeader-CDFE4Ws4.js +2 -0
  11. package/dist/assets/{MultiRunWindow-D5HKvioh.js → MultiRunWindow-rggd5jvJ.js} +1 -1
  12. package/dist/assets/{SettingsView-ulmuNYxi.js → SettingsView-DWeiBwOG.js} +10 -10
  13. package/dist/assets/{SettingsWindow-C6iznJxw.js → SettingsWindow-1csE2lF6.js} +1 -1
  14. package/dist/assets/{TerminalView-CWZCDRxs.js → TerminalView-mF-mbAzo.js} +1 -1
  15. package/dist/assets/{ToolOutputDialog-DAwoBF6c.js → ToolOutputDialog-BvgdBVst.js} +1 -1
  16. package/dist/assets/{appThemeRegistry-Cxk6QddU.js → appThemeRegistry-CiQ61T5d.js} +1 -1
  17. package/dist/assets/{capgoAdapter-KNLHDj7G.js → capgoAdapter-DLi2tcmI.js} +1 -1
  18. package/dist/assets/{fileMentionTouchSelection-COw28yPf.js → fileMentionTouchSelection-C9jpvVUn.js} +1 -1
  19. package/dist/assets/{gitApi-D0t8KXsn.js → gitApi-nArpJO6q.js} +1 -1
  20. package/dist/assets/{image-loading-CVq5GLEY.js → image-loading-23c-W-bq.js} +1 -1
  21. package/dist/assets/{insertionBoundaries-UMFkRmkG.js → insertionBoundaries-BgHgsc1p.js} +1 -1
  22. package/dist/assets/{main-DZSusaPd.js → main-D5JkjH8k.js} +22 -22
  23. package/dist/assets/{main-B_h17HmQ.js → main-R2wbcT-3.js} +2 -2
  24. package/dist/assets/{mcpQueries-CCU0buGG.js → mcpQueries-W-LFzCOw.js} +1 -1
  25. package/dist/assets/{miniChat-B1i0B5Ml.js → miniChat-ChGISVuo.js} +2 -2
  26. package/dist/assets/{mobile-C-PKN6lA.js → mobile-Dv3wbcd9.js} +2 -2
  27. package/dist/assets/{mobileBackNavigation-CBPY3q34.js → mobileBackNavigation-BnipJtFo.js} +1 -1
  28. package/dist/assets/{multirun-BTBDMVOl.js → multirun-DvSn-icg.js} +1 -1
  29. package/dist/assets/{projectMeta---vfnScT.js → projectMeta-Cm0n6vtB.js} +1 -1
  30. package/dist/assets/renderElectronMiniChatApp-BjQyp-u8.js +2 -0
  31. package/dist/assets/{renderMobileApp-DaFhnxuq.js → renderMobileApp-BEkWDH7L.js} +6 -6
  32. package/dist/assets/runtimeConfig-D3moXtPz.js +2 -0
  33. package/dist/assets/{runtimeEndpointReset-CBcDor5H.js → runtimeEndpointReset-BYn28E2A.js} +5 -5
  34. package/dist/assets/{sessionChangeSummary-DTa1NhbK.js → sessionChangeSummary-DXpoQiGE.js} +1 -1
  35. package/dist/assets/{sessionLookup-xGVDWmBL.js → sessionLookup-BYycaYEQ.js} +1 -1
  36. package/dist/assets/{speechSettingsQueries-Chq_vO6e.js → speechSettingsQueries-Bv08BFlI.js} +1 -1
  37. package/dist/assets/src-CmermOKP.css +2 -0
  38. package/dist/assets/types-Q_utERET.js +2 -0
  39. package/dist/assets/{useAppFontEffects-CzYFu1JQ.js → useAppFontEffects-HYIeI-xf.js} +40 -40
  40. package/dist/assets/{useDesktopWindowControlsLayout-DML3uW6M.js → useDesktopWindowControlsLayout-Cc-2uuN5.js} +1 -1
  41. package/dist/assets/{useEffectiveDirectory-CYhf9ITQ.js → useEffectiveDirectory-BBb97raM.js} +1 -1
  42. package/dist/assets/{useMobileNavigationStore-DvSdigrK.js → useMobileNavigationStore-CEVJSNnR.js} +3 -3
  43. package/dist/assets/{useWorkerHighlightedLines-BThWzx-h.js → useWorkerHighlightedLines-D8JkeSuf.js} +1 -1
  44. package/dist/index.html +12 -12
  45. package/dist/mini-chat.html +6 -6
  46. package/dist/mobile.html +8 -8
  47. package/package.json +1 -1
  48. package/server/lib/content-search/DOCUMENTATION.md +5 -1
  49. package/server/lib/content-search/runtime.js +1 -0
  50. package/server/lib/content-search/runtime.test.js +43 -0
  51. package/server/lib/notifications/APNS.md +13 -0
  52. package/server/lib/notifications/DOCUMENTATION.md +4 -0
  53. package/server/lib/notifications/apns-runtime.js +45 -24
  54. package/server/lib/notifications/apns-runtime.test.js +57 -1
  55. package/server/lib/notifications/routes.js +6 -2
  56. package/server/lib/opencode/DOCUMENTATION.md +2 -0
  57. package/server/lib/opencode/pwa-manifest-routes.js +2 -2
  58. package/server/lib/opencode/settings-runtime.js +1 -1
  59. package/server/lib/opencode/settings-runtime.test.js +15 -0
  60. package/server/lib/opencode/static-routes-runtime.js +6 -6
  61. package/dist/assets/MarkdownRenderer-QKxUWu_S.js +0 -2
  62. package/dist/assets/MobileTabPageHeader-sOgdUSiO.js +0 -2
  63. package/dist/assets/renderElectronMiniChatApp-CBZ5TGG8.js +0 -2
  64. package/dist/assets/runtimeConfig-DTzs5NCT.js +0 -2
  65. package/dist/assets/src-BEVRKYT8.css +0 -2
  66. package/dist/assets/types-BuiqMmh_.js +0 -1
@@ -1,21 +1,21 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-DAwoBF6c.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-ef9W7A43.js","assets/runtime-switch-CAZiOV2G.js","assets/queryRuntime-DKGLQtb9.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/persistence-Dzooc9Xg.js","assets/vendor-zustand-o69pgTEK.js","assets/vendor-base-ui-CdzJ6My_.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useUIStore-NMQx_cnG.js","assets/vendor-react-BP2cRVqX.js","assets/vendor-pathe-vBmvQE8f.js","assets/platform-7bX6qtBV.js","assets/vendor-opencode-client-MF2GBrFx.js","assets/runtime-file-resource-C1k5nbWb.js","assets/vendor-tanstack-react-query-CdqCAt40.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-download-DAOam_oV.js","assets/vendor-pierre-diffs-DPBtNDJ5.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-reactuses-core-BpfIZ1tg.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-C3292Ee6.js","assets/store-CZu30-QE.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-8jhE4Zyk.js","assets/Icon-jsQQXouE.js","assets/dialog-DrgcVFLG.js","assets/image-loading-CVq5GLEY.js","assets/image-loading-D9Z_BASK.css","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-Cxk6QddU.js","assets/useMobileNavigationStore-DvSdigrK.js","assets/vendor-sonner-ZS8XIOVl.js","assets/useAssistantUIStore-D7JZlg_Q.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/MarkdownRenderer-QKxUWu_S.js","assets/useEffectiveDirectory-CYhf9ITQ.js","assets/markdownHeightCache-BwSTMSRn.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-CkO3sT4Y.js","assets/ImageLoadingPlaceholder-BPp8BN0a.js","assets/useWorkerHighlightedLines-BThWzx-h.js","assets/tooltip-DGUZtHif.js","assets/vendor-tanstack-react-virtual-B_EO--9t.js","assets/markdownTheme-DHoKvD6O.js","assets/mobileBackNavigation-CBPY3q34.js","assets/ToolOutputDialog-CbGuK5bP.css","assets/TerminalView-CWZCDRxs.js","assets/terminalApi-BHXvha-U.js","assets/vendor-ghostty-web-DbBrwBII.js","assets/OverlayScrollbar-C4VUlRzo.js","assets/sortable-tabs-strip-BMrSDJob.js","assets/vendor-dnd-kit-core-5pNnzVdw.js","assets/vendor-dnd-kit-accessibility-COSwgjFs.js","assets/vendor-dnd-kit-sortable-Dm50I0m7.js","assets/useFontPreferences-D9PX5t6Y.js","assets/projectActions-BX0cjZoq.js","assets/DiagramView-ALA0pyKm.js","assets/diagram-Ddq5F6R_.js","assets/vendor-react-drawio-Ck9ZKdNN.js","assets/SettingsView-ulmuNYxi.js","assets/desktopHosts-BDyl2P7W.js","assets/desktopRelayRestore-C_23nlKD.js","assets/vendor-codemirror-autocomplete-7c2L_4dM.js","assets/MobileShareBridge-DZ-a1-hd.js","assets/MobileDetailNavigation-nJl1j85R.js","assets/AgentAvatar-1UO8KpCd.js","assets/vendor-dicebear-core-CV95S5Pg.js","assets/vendor-dicebear-styles-7lEG-JsF.js","assets/projectMeta---vfnScT.js","assets/gitApi-D0t8KXsn.js","assets/input-DaOOTCQd.js","assets/textarea-BcA4uouw.js","assets/vendor-framer-motion-D-oiwsxL.js","assets/speechSettingsQueries-Chq_vO6e.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/dropdown-menu.styles-CeLR2UTs.js","assets/url-Be8VCT8M.js","assets/MobileTabPageHeader-sOgdUSiO.js","assets/types-BuiqMmh_.js","assets/vendor-codemirror-lang-angular-DXOgWEVj.js","assets/vendor-codemirror-lang-json-mLulNbwB.js","assets/vendor-codemirror-lang-markdown-CV1IO6Qs.js","assets/vendor-codemirror-lang-python-YM2WVLHF.js","assets/vendor-codemirror-legacy-modes-DwltVFbT.js","assets/mcpQueries-CCU0buGG.js","assets/collapsible-B0yvtXQR.js","assets/vendor-codemirror-commands-B8KrBQ9B.js","assets/vendor-codemirror-search-ZqtrPLjU.js","assets/vendor-replit-codemirror-vim-DDj0dSVY.js","assets/vendor-codemirror-language-data-Ctd4WxgW.js","assets/scheduledTaskNavigation-C6UYwVbD.js","assets/vendor-yaml-C9KlJAlj.js","assets/vendor-qrcode-D7jBCyl-.js","assets/vendor-dijkstrajs-BAzPDGZM.js","assets/SettingsWindow-C6iznJxw.js","assets/MultiRunWindow-D5HKvioh.js","assets/multirun-BTBDMVOl.js","assets/insertionBoundaries-UMFkRmkG.js","assets/fileMentionTouchSelection-COw28yPf.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/AssistantView-CdO4imc6.js","assets/sessionChangeSummary-DTa1NhbK.js","assets/LoadingImage-DvtPqFRw.js","assets/sessionChangeSummary-CRYRvpy7.css","assets/vendor-motion-88WXBOBf.js","assets/sessionLookup-xGVDWmBL.js","assets/assistant-attachment-cache-CLnqffXU.js","assets/OnboardingScreen-DTr_WxYY.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,p as r,t as i,v as a,w as o}from"./runtime-auth-ef9W7A43.js";import{c as s,f as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./runtime-switch-CAZiOV2G.js";import{c as h,s as g,u as _}from"./queryRuntime-DKGLQtb9.js";import{$t as v,An as y,Cn as b,D as x,Dn as S,En as C,Nt as w,O as T,On as E,Rt as D,Vt as O,Xt as k,Yt as A,Zt as j,_n as M,cn as N,ct as P,en as F,et as I,hn as L,i as R,in as z,kn as B,ln as V,nn as ee,r as H,rn as te,sn as ne,t as re,un as U,vn as ie}from"./persistence-Dzooc9Xg.js";import{f as ae,h as W,l as oe,r as se,v as ce}from"./desktopHosts-BDyl2P7W.js";import{a as G,i as le,t as ue}from"./vendor-zustand-o69pgTEK.js";import{D as de,E as fe,F as pe,I as me,L as he,P as ge,a as _e,c as ve,d as ye,f as be,i as xe,it as Se,k as Ce,l as we,nt as Te,p as Ee,rt as De,u as Oe}from"./vendor-base-ui-CdzJ6My_.js";import{Ar as ke,Cr as Ae,Ct as je,Dt as Me,Et as Ne,Hn as K,Mr as Pe,Mt as Fe,Nr as Ie,Nt as Le,St as Re,Tt as ze,Vn as Be,Xn as Ve,_n as He,br as Ue,hn as We,wr as Ge,wt as Ke,xr as qe,zn as Je}from"./platform-7bX6qtBV.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{S as Ye,b as Xe,n as q,r as Ze,x as Qe}from"./useUIStore-NMQx_cnG.js";import{n as $e,t as et}from"./vendor-react-BP2cRVqX.js";import{c as tt}from"./vendor-tanstack-query-core-BWz0ose6.js";import{n as nt,o as rt,s as it}from"./vendor-tanstack-react-query-CdqCAt40.js";import{A as at,j as ot,r as st,s as ct,v as lt,x as ut}from"./runtime-file-resource-C1k5nbWb.js";import{o as dt}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as ft}from"./terminalApi-BHXvha-U.js";/* empty css */import{H as pt,ot as mt}from"./vendor-codemirror-autocomplete-7c2L_4dM.js";import{a as ht}from"./vendor-pierre-diffs-DPBtNDJ5.js";import{f as gt,n as _t,r as vt,t as yt}from"./vendor-reactuses-core-BpfIZ1tg.js";import{_ as bt,a as xt,c as St,d as Ct,f as wt,g as Tt,h as Et,i as Dt,l as Ot,m as kt,o as At,p as jt,r as J,s as Mt,t as Y}from"./button-C3292Ee6.js";import{n as Nt}from"./store-CZu30-QE.js";import{S as Pt,_ as Ft,w as It}from"./MobileDetailNavigation-nJl1j85R.js";import{$n as Lt,An as Rt,Ar as zt,Bt,C as Vt,Co as Ht,Er as Ut,Gt as Wt,Ir as Gt,Kn as Kt,Li as qt,Lr as Jt,Lt as Yt,Mt as Xt,Nr as Zt,Nt as Qt,Or as $t,Pr as en,Ra as tn,Ri as nn,Rr as X,Rt as rn,S as an,Sa as on,So as sn,Ur as cn,Ut as ln,Vi as un,Wt as dn,Xn as fn,Yn as pn,Yr as mn,_ as hn,_n as gn,an as _n,b as vn,bi as yn,bo as bn,d as xn,da as Sn,dn as Cn,dr as wn,en as Tn,er as En,f as Dn,fa as On,fn as kn,fo as An,ga as jn,h as Mn,hr as Nn,in as Pn,jr as Fn,kr as In,li as Ln,ln as Rn,lr as zn,m as Bn,on as Vn,p as Hn,pn as Un,qn as Wn,sn as Gn,ti as Kn,tn as qn,ui as Jn,vn as Yn,w as Xn,wa as Zn,wo as Qn,x as $n,xi as er,xo as tr,xr as nr,yn as rr,zi as ir}from"./useMobileNavigationStore-DvSdigrK.js";import{n as ar}from"./useAssistantUIStore-D7JZlg_Q.js";import{n as or}from"./useThemeSystem-8jhE4Zyk.js";import{n as Z,t as sr}from"./Icon-jsQQXouE.js";import{a as cr,i as lr,n as ur,o as dr,r as fr,t as pr}from"./dialog-DrgcVFLG.js";import{A as mr,C as hr,D as gr,O as _r,P as vr,T as yr,a as br,f as xr,h as Sr,i as Cr,j as wr,k as Tr,m as Er,o as Dr,p as Or,r as kr,t as Ar,w as jr,y as Mr}from"./gitApi-D0t8KXsn.js";import{$ as Nr,A as Pr,At as Fr,Ct as Ir,D as Lr,Dt as Rr,E as zr,Et as Br,F as Vr,G as Hr,It as Ur,Lt as Wr,M as Gr,Mt as Kr,N as qr,Nt as Jr,O as Yr,Ot as Xr,P as Zr,Pt as Qr,Q as $r,S as ei,St as ti,Tt as ni,U as ri,W as ii,Z as ai,_ as oi,at as si,b as ci,bt as li,c as ui,d as di,et as fi,f as pi,ft as mi,g as hi,gt as gi,h as _i,ht as vi,it as yi,j as bi,jt as xi,k as Si,kt as Ci,l as wi,m as Ti,mt as Ei,nt as Di,o as Oi,ot as ki,p as Ai,pt as ji,r as Mi,rt as Ni,s as Pi,t as Fi,tt as Ii,u as Li,ut as Ri,v as zi,vt as Bi,w as Vi,wt as Hi,x as Ui,xt as Wi,y as Gi,z as Ki}from"./useAppFontEffects-CzYFu1JQ.js";import{O as qi,T as Ji,_ as Yi,a as Xi,b as Zi,f as Qi,h as $i,i as ea,l as ta,m as na,n as ra,p as ia,s as aa,x as oa}from"./projectMeta---vfnScT.js";import{t as sa}from"./input-DaOOTCQd.js";import{i as ca,n as la,r as ua,t as da}from"./tooltip-DGUZtHif.js";import{A as fa,Ct as pa,D as ma,E as ha,I as ga,K as _a,L as va,N as ya,O as ba,Rt as xa,S as Sa,T as Ca,Yt as wa,_ as Ta,_t as Ea,at as Da,b as Oa,d as ka,ft as Aa,g as ja,gt as Ma,h as Na,it as Pa,j as Fa,l as Ia,lt as La,mt as Ra,on as za,ot as Ba,p as Va,q as Ha,rt as Ua,s as Wa,u as Ga,ut as Ka,v as qa,vt as Ja,w as Ya,wt as Xa,x as Za,y as Qa,yt as $a}from"./speechSettingsQueries-Chq_vO6e.js";import{i as eo,o as to}from"./OverlayScrollbar-C4VUlRzo.js";import{d as no}from"./image-loading-CVq5GLEY.js";import{_ as ro,b as io,i as ao,n as oo,r as so,t as co,v as lo,x as uo}from"./dropdown-menu.styles-CeLR2UTs.js";import{n as fo,r as po}from"./textarea-BcA4uouw.js";import{r as mo,t as ho}from"./sessionChangeSummary-DTa1NhbK.js";import{n as go,o as _o}from"./vendor-framer-motion-D-oiwsxL.js";import{A as vo,_ as yo,b as bo,f as xo,g as So,h as Co,k as wo,m as To,v as Eo,y as Do}from"./insertionBoundaries-UMFkRmkG.js";import{n as Oo,t as ko}from"./appThemeRegistry-Cxk6QddU.js";import{n as Ao,o as jo}from"./MarkdownRenderer-QKxUWu_S.js";import{_ as Mo,i as No,l as Po,n as Fo,s as Io,t as Lo,v as Ro,y as zo}from"./vendor-dnd-kit-core-5pNnzVdw.js";import{a as Bo,n as Vo,o as Ho,s as Uo,t as Wo}from"./vendor-dnd-kit-sortable-Dm50I0m7.js";import{a as Go}from"./url-Be8VCT8M.js";import{c as Ko,d as qo,f as Jo,l as Yo,p as Xo,u as Zo}from"./markdown-worker-CkO3sT4Y.js";import{n as Qo,t as $o}from"./useEffectiveDirectory-CYhf9ITQ.js";import{t as es}from"./ImageLoadingPlaceholder-BPp8BN0a.js";import{t as ts}from"./LoadingImage-DvtPqFRw.js";import{g as ns}from"./useWorkerHighlightedLines-BThWzx-h.js";import{t as rs}from"./sortable-tabs-strip-BMrSDJob.js";import{t as is}from"./vendor-tanstack-react-virtual-B_EO--9t.js";import{t as as}from"./vendor-motion-88WXBOBf.js";import{A as os,B as ss,C as cs,D as ls,E as us,F as ds,I as fs,O as ps,S as ms,T as hs,U as gs,V as _s,_ as vs,a as ys,b as bs,c as xs,d as Ss,f as Cs,h as ws,i as Ts,k as Es,l as Ds,m as Os,n as ks,o as As,p as js,s as Ms,w as Ns,y as Ps,z as Fs}from"./MobileTabPageHeader-sOgdUSiO.js";import{i as Is,n as Ls,r as Rs,t as zs}from"./useDesktopWindowControlsLayout-DML3uW6M.js";import{n as Bs}from"./useFontPreferences-D9PX5t6Y.js";import{B as Vs,C as Hs,E as Us,H as Ws,J as Gs,K as Ks,L as qs,Q as Js,R as Ys,S as Xs,T as Zs,U as Qs,V as $s,W as ec,X as tc,Z as nc,_ as rc,a as ic,at as ac,b as oc,c as sc,ct as cc,d as lc,dt as uc,et as dc,f as fc,ft as pc,g as mc,h as hc,ht as gc,i as _c,it as vc,l as yc,lt as bc,m as xc,mt as Sc,n as Cc,nt as wc,o as Tc,ot as Ec,pt as Dc,q as Oc,r as kc,rt as Ac,s as jc,st as Mc,tt as Nc,u as Pc,ut as Fc,v as Ic,w as Lc,x as Rc,y as zc,z as Bc}from"./runtimeEndpointReset-CBcDor5H.js";import{a as Vc,c as Hc,l as Uc,o as Wc,s as Gc}from"./scheduledTaskNavigation-C6UYwVbD.js";import{i as Kc}from"./sessionLookup-xGVDWmBL.js";import{n as qc,r as Jc,t as Yc}from"./collapsible-B0yvtXQR.js";import{a as Xc,o as Zc,r as Qc,s as $c,t as el}from"./projectActions-BX0cjZoq.js";import{t as tl}from"./diagram-Ddq5F6R_.js";import{a as nl,i as rl,n as il,o as al,r as ol,t as sl}from"./multirun-BTBDMVOl.js";import{t as cl}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as ll,t as ul}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(Se(),1),dl=et(),fl=$e(),$=De();function pl(e){let t=(0,fl.c)(14),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({size:i,className:n,style:a,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=typeof i==`number`?`${i}px`:i,s=typeof i==`number`?`${i}px`:i,c;t[5]!==a||t[6]!==o||t[7]!==s?(c={width:o,height:s,...a},t[5]=a,t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.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`}),t[9]=l):l=t[9];let u;return t[10]!==n||t[11]!==r||t[12]!==c?(u=(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 256 256`,fill:`currentColor`,className:n,style:c,...r,children:l}),t[10]=n,t[11]=r,t[12]=c,t[13]=u):u=t[13],u}var ml=[{id:`finder`,label:`Finder`,appName:`Finder`},{id:`terminal`,label:`Terminal`,appName:`Terminal`},{id:`iterm2`,label:`iTerm2`,appName:`iTerm`},{id:`ghostty`,label:`Ghostty`,appName:`Ghostty`},{id:`vscode`,label:`VS Code`,appName:`Visual Studio Code`},{id:`vscode-insiders`,label:`VS Code Insiders`,appName:`Visual Studio Code - Insiders`},{id:`intellij`,label:`IntelliJ`,appName:`IntelliJ IDEA`},{id:`visual-studio`,label:`Visual Studio`,appName:`Visual Studio`},{id:`cursor`,label:`Cursor`,appName:`Cursor`},{id:`android-studio`,label:`Android Studio`,appName:`Android Studio`},{id:`pycharm`,label:`PyCharm`,appName:`PyCharm`},{id:`xcode`,label:`Xcode`,appName:`Xcode`},{id:`sublime-text`,label:`Sublime`,appName:`Sublime Text`},{id:`webstorm`,label:`WebStorm`,appName:`WebStorm`},{id:`rider`,label:`Rider`,appName:`Rider`},{id:`zed`,label:`Zed`,appName:`Zed`},{id:`phpstorm`,label:`PhpStorm`,appName:`PhpStorm`},{id:`eclipse`,label:`Eclipse`,appName:`Eclipse`},{id:`windsurf`,label:`Windsurf`,appName:`Windsurf`},{id:`vscodium`,label:`VSCodium`,appName:`VSCodium`},{id:`rustrover`,label:`RustRover`,appName:`RustRover`},{id:`kiro`,label:`Kiro`,appName:`Kiro`},{id:`antigravity`,label:`Antigravity`,appName:`Antigravity`},{id:`trae`,label:`Trae`,appName:`Trae`}],hl=`finder`,gl=new Set([`finder`,`terminal`]),_l=e=>typeof window<`u`&&window.__YURI_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,vl=e=>{if(!e)return null;let t=ml.find(t=>t.id===e)??null;return t?_l(t):null},yl=()=>ml.filter(e=>gl.has(e.id)).map(e=>({..._l(e)})),bl=()=>{if(typeof window>`u`)return hl;let e=window.localStorage.getItem(`openInAppId`);return e&&vl(e)?e:hl},xl=!1,Sl=!1,Cl=!1,wl=0,Tl=null,El=()=>{Tl&&=(clearTimeout(Tl),null)},Dl=G()((e,t)=>({selectedAppId:bl(),availableApps:yl(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(xl||typeof window>`u`)return;xl=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:yl(),hasLoadedApps:n});return}let r=new Set(t.map(e=>e.name)),i=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0]));e({availableApps:ml.filter(e=>r.has(e.appName)||gl.has(e.id)).map(e=>({..._l(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!F()||Sl||t().hasLoadedApps&&!i)return;let a=ml.map(e=>e.appName);El(),i&&e({hasLoadedApps:!1}),Sl=!0,Cl=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await O(a,i),l=o&&!s&&t.length===0&&wl<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][wl]??3200;wl+=1,Cl=!0,Tl=setTimeout(()=>{r()},e);return}wl=0,Cl=!1;return}if(wl<3){let e=[1e3,3e3,7e3][wl]??7e3;wl+=1,Cl=!0,Tl=setTimeout(()=>{r()},e)}}finally{Sl=!1,Cl||e({isScanning:!1})}};r(),window.addEventListener(`yuri:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&vl(n.openInAppId)?n.openInAppId:null;r&&(window.localStorage.setItem(`openInAppId`,r),e({selectedAppId:r}))}),window.addEventListener(`yuri:app-ready`,()=>{r()}),window.addEventListener(`yuri:installed-apps-updated`,t=>{let r=t.detail;Array.isArray(r)&&(wl=3,Cl=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__yuriAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(xl||t().initialize(),!F()||Sl||t().hasLoadedApps&&!n)return;let r=ml.map(e=>e.appName);El(),n&&e({hasLoadedApps:!1}),Sl=!0,Cl=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await O(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=ml.filter(e=>o.has(e.appName)||gl.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:yl(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{Sl=!1,Cl||e({isScanning:!1})}},selectApp:async t=>{vl(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await R({openInAppId:t}))}})),Ol=(e=f(),t=l())=>{let n=e.startsWith(`host:`)?e.slice(5):null;return{queryKey:[t,`ssh-editor-apps`,n],enabled:F()&&k()&&n!==null,queryFn:async({signal:e})=>{let t=await j(`desktop_ssh_editor_apps`,{hostId:n});return e.throwIfAborted(),t?{hostId:n,appIds:t.appIds}:null}}},kl=()=>{let e=(0,fl.c)(3),t=(0,Q.useSyncExternalStore)(s,f,Al),n=(0,Q.useSyncExternalStore)(s,l,jl),r;return e[0]!==t||e[1]!==n?(r=Ol(t,n),e[0]=t,e[1]=n,e[2]=r):r=e[2],it(r)};function Al(){return``}function jl(){return``}var Ml=`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`,Nl=`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`,Pl=e=>({...e,fallbackIconDataUrl:e.id===`finder`&&window.__YURI_PLATFORM__!==`win32`?Ml:e.id===`terminal`?Nl:void 0}),Fl=e=>{let t=(0,fl.c)(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=e,[a,o]=Q.useState(!1),s;t[0]===n?s=t[1]:(s=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=s);let c=s,l=r||i;if(l&&!a){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>o(!0),t[2]=e):e=t[2];let n;return t[3]===l?n=t[4]:(n=(0,$.jsx)(`img`,{src:l,alt:``,className:`h-4 w-4 rounded-sm`,onError:e}),t[3]=l,t[4]=n),n}let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(`h-4 w-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=u):u=t[5];let d;return t[6]===c?d=t[7]:(d=(0,$.jsx)(`span`,{className:u,children:c}),t[6]=c,t[7]=d),d},Il=({directory:e,className:t})=>{let{t:n}=wt(),r=Dl(e=>e.selectedAppId),i=Dl(e=>e.availableApps),a=Dl(e=>e.isCacheStale),o=Dl(e=>e.isScanning),s=Dl(e=>e.initialize),c=Dl(e=>e.loadInstalledApps),l=Dl(e=>e.selectApp),{data:u}=kl(),d=Q.useMemo(()=>u?i.filter(e=>u.appIds.includes(e.id)):i,[i,u]);Q.useEffect(()=>{s()},[s]);let f=F()&&v(),p=Q.useMemo(()=>{let e=d.find(e=>e.id===r)??d.find(e=>e.id===`finder`)??d[0];return e?Pl(e):null},[d,r]);if(!f&&!u||!e)return null;let m=async t=>{try{let r=await U(e,t.id,t.appName,u?.hostId);!r&&!u?await V(e,t.appName):r||X.error(n(`filesView.toast.openInAppFailed`,{app:t.label}))}catch(e){X.error(n(String(e).includes(`SSH_EDITOR_CONFIG_REQUIRED`)?`openInApp.errors.sshConfigRequired`:`filesView.toast.openInAppFailed`,{app:t.label}))}},h=async e=>{await l(e.id),await m(e)},g=async()=>{await Ct(e)};return(0,$.jsxs)(`div`,{className:J(`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`,t),children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>void(p?m(p):g()),className:J(`inline-flex h-full items-center px-2.5 typography-ui-label font-medium`,`text-foreground hover:bg-interactive-hover transition-colors`,o&&`animate-pulse`),"aria-label":p?n(`openInApp.actions.openInAria`,{app:p.label}):n(`openInApp.actions.copyPath`),children:p?(0,$.jsx)(Fl,{label:p.label,iconDataUrl:p.iconDataUrl,fallbackIconDataUrl:p.fallbackIconDataUrl}):(0,$.jsx)(Z,{name:`file-copy`,className:`h-4 w-4`})}),(0,$.jsxs)(Ua,{children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`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`),"aria-label":n(`openInApp.actions.chooseAppAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4`})})}),(0,$.jsxs)(Pa,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>void g(),children:[(0,$.jsx)(Z,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`openInApp.actions.copyPath`)})]}),(0,$.jsx)(La,{}),d.map(e=>{let t=Pl(e);return(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>void h(e),children:[(0,$.jsx)(Fl,{label:e.label,iconDataUrl:e.iconDataUrl,fallbackIconDataUrl:t.fallbackIconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label}),p?.id===e.id?(0,$.jsx)(Z,{name:`check`,className:`ml-auto h-4 w-4 text-primary`}):null]},e.id)}),a?(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>void c(!0),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`openInApp.actions.refreshApps`)})]}):null]})]})]})},Ll=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Rl=[`dev`,`start`,`preview`,`serve`];async function zl(e,t,n){if(!e)return null;let r=Hl(t);if(r)return{command:r.command,label:r.name||`Start Preview`,actionId:r.id};if(n){let t=Ul(n);if(t){let n=await Wl(e);return{command:`${n===`npm`?`npm run`:n===`yarn`?`yarn`:n===`pnpm`?`pnpm`:n===`bun`?`bun run --shell=bun`:`npm run`} ${t}`,label:`Start (${t})`}}}if(await Bl(e)){let e=await Vl(),t=typeof e==`number`&&Number.isFinite(e)&&e>0?e:8e3;return{command:`python3 -m http.server ${t}`,label:`Static preview`,previewUrlHint:`http://127.0.0.1:${t}/`}}return null}async function Bl(e){let t=await Gl(`${e}/index.html`,e);return typeof t==`string`&&t.trim().length>0}async function Vl(){try{let e=await _(`/api/system/free-port`,{cache:`no-store`});if(!e.ok)return null;let t=await e.json().catch(()=>null),n=typeof t?.port==`number`?t.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Hl(e){for(let t of e){let e=`${t.name} ${t.command}`.toLowerCase();if(Rl.some(t=>e.includes(t)))return t}return null}function Ul(e){for(let{pattern:t}of Ll)for(let n of Object.keys(e))if(t.test(n))return n;return null}async function Wl(e){let t=await Gl(`${e}/package.json`,e);if(t)try{let e=JSON.parse(t),n=typeof e.packageManager==`string`?e.packageManager.toLowerCase():``;if(n.startsWith(`bun@`))return`bun`;if(n.startsWith(`pnpm@`))return`pnpm`;if(n.startsWith(`yarn@`))return`yarn`;if(n.startsWith(`npm@`))return`npm`}catch{}for(let[t,n]of[[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`pnpm-lock.yaml`,`pnpm`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]]){let r=await Gl(`${e}/${t}`,e);if(typeof r==`string`&&r.trim().length>0)return n}return`npm`}async function Gl(e,t){if(t?.trim())try{let n=new URLSearchParams({path:e,directory:t,optional:`true`}),r=await _(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(r.ok)return r.text()}catch{}let n=g()?.files;if(n?.readFile)try{let t=await n.readFile(e,{optional:!0});return typeof t?.content==`string`?t.content:null}catch{return null}try{let t=await _(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:`no-store`});return t.ok?t.text():null}catch{return null}}async function Kl(e){try{let t=await Gl(`${e}/package.json`,e);if(t==null)return null;let n=JSON.parse(t).scripts;return n&&typeof n==`object`&&!Array.isArray(n)?n:null}catch{return null}}var ql=e=>new Promise(t=>{window.setTimeout(t,e)}),Jl=RegExp(`\x1B\\[[0-9;?]*[ -/]*[@-~]`,`g`),Yl=/https?:\/\/[^\s<>'"`]+/gi,Xl=`__yuri_auto_discover_preview__`,Zl=15e3,Ql=e=>{let t=``;for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(t+=e[n])}return t},$l=e=>{let t=(e||``).trim();if(!t)return null;let n=/^https?:\/\//i.test(t)?t:`http://${t}`;try{let e=new URL(n);return e.protocol!==`http:`&&e.protocol!==`https:`?null:e.toString()}catch{return null}},eu=e=>{let t=e.replace(Jl,``).match(Yl);if(!t||t.length===0)return null;let n=t.map(e=>e.replace(/[),.;]+$/,``)).filter(Boolean);if(n.length===0)return null;let r=[];for(let e of n)try{let t=new URL(e);t.port&&t.port.length>0&&r.push({raw:e,parsed:t})}catch{}if(r.length>0){let e=e=>{let{parsed:t}=e,n=t.hostname.toLowerCase(),r=n===`localhost`||n===`127.0.0.1`||n===`0.0.0.0`||n===`::1`,i=t.pathname||`/`,a=i.split(`/`).filter(Boolean).length,o=i===`/`||i===``,s=!!(t.search||t.hash),c=0;return r&&(c+=50),o&&(c+=30),c-=Math.min(a*5,20),s&&(c-=10),c};return r.sort((t,n)=>e(n)-e(t)),r[0]?.parsed.origin??r[0]?.raw??null}return n[0]??null},tu=({projectRef:e,directory:t,className:n,compact:r=!1,allowMobile:i=!1})=>{let{t:a}=wt(),{terminal:o,runtime:s}=at(),{isMobile:c}=eo(),l=Q.useMemo(()=>F(),[]),u=bs(e=>e.instances),d=bs(e=>e.load),f=q(e=>e.setBottomTerminalOpen),p=q(e=>e.setActiveMainTab),m=q(e=>e.setSettingsPage),h=q(e=>e.setSettingsDialogOpen),g=q(e=>e.setSettingsProjectsSelectedId),_=q(e=>e.openContextPreview),v=Bs(e=>e.sessions),y=Bs(e=>e.ensureDirectory),b=Bs(e=>e.setTabLabel),x=Bs(e=>e.setTabIconKey),S=Bs(e=>e.setActiveTab),C=Bs(e=>e.setConnecting),w=Bs(e=>e.setTabSessionId),T=Bs(e=>e.setTabPreviewUrl),E=Bs(e=>e.projectActionRuns),D=Bs(e=>e.setProjectActionRun),O=Bs(e=>e.updateProjectActionRunStatus),k=Bs(e=>e.removeProjectActionRun),[A,j]=Q.useState([]),[M,N]=Q.useState(null),[P,I]=Q.useState(!1),L=Q.useRef({}),R=Q.useRef({}),z=Q.useRef({}),B=Q.useRef({}),V=Q.useRef(0),ee=e?.id??null,H=e?.path??``,te=Q.useMemo(()=>ee?{id:ee,path:H}:null,[ee,H]);Q.useEffect(()=>{l&&d().catch(()=>void 0)},[l,d]);let ne=Q.useCallback(async e=>{await Go(e)},[]),re=Q.useCallback(async()=>{if(!te)return;let e=V.current+1;V.current=e,I(!0);try{let t=await En(te);if(V.current!==e)return;let n=t.actions;j(n),N(e=>e===Xl||e&&n.some(t=>t.id===e)?e:null)}catch{if(V.current!==e)return}finally{V.current===e&&I(!1)}},[te]),U=Q.useMemo(()=>Xc(t||te?.path||``),[t,te?.path]),ie=Q.useMemo(()=>M?A.find(e=>e.id===M)??null:null,[A,M]),ae=Q.useMemo(()=>({id:Xl,name:a(`projectActions.actions.autoDiscover`),command:``,icon:`search`,autoOpenUrl:!0}),[a]),W=!c,oe=Q.useMemo(()=>W?[ae,...A]:A,[A,ae,W]);Q.useEffect(()=>{re()},[re]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;ee&&(t?.projectId&&t.projectId!==ee||re())};return window.addEventListener(el,e),()=>{window.removeEventListener(el,e)}},[re,ee]),Q.useEffect(()=>{M&&(M===Xl&&W||A.some(e=>e.id===M)||N(null))},[A,W,M]),Q.useEffect(()=>{for(let[e,t]of Object.entries(E)){let n=v.get(t.directory)?.tabs.find(e=>e.id===t.tabId);(!n||n.terminalSessionId!==t.sessionId)&&k(e)}},[E,k,v]),Q.useEffect(()=>{for(let[e,t]of Object.entries(E)){let n=R.current[e]??{lastSeenChunkId:null,openedUrl:!1,tail:``,openInPreview:!1};R.current[e]=n;let r=oe.find(e=>e.id===t.actionId);if(!r)continue;let i=v.get(t.directory)?.tabs.find(e=>e.id===t.tabId);if(!i||!Array.isArray(i.bufferChunks)||i.bufferChunks.length===0)continue;let o=i.bufferChunks.filter(e=>n.lastSeenChunkId===null||e.id>n.lastSeenChunkId);if(o.length===0)continue;let s=o.map(e=>e.data).join(``),c=`${n.tail}${s}`,l=!n.openedUrl&&r.autoOpenUrl===!0?eu(c):null;if(n.lastSeenChunkId=o[o.length-1]?.id??n.lastSeenChunkId,n.tail=c.slice(-512),l)if(n.openedUrl=!0,n.openInPreview){let t=E[e];t&&(T(t.directory,t.tabId,l,{locked:!1,autoOpened:!1}),t.status===`waiting-for-preview`&&O(e,`running`),window.clearTimeout(B.current[e]),delete B.current[e],_(t.directory,l))}else ne(l),X.success(a(`projectActions.toast.openedUrlFromOutput`));R.current[e]=n}for(let e of Object.keys(R.current))E[e]||(delete R.current[e],window.clearTimeout(B.current[e]),delete B.current[e])},[oe,_,ne,E,T,a,v,O]);let se=Q.useCallback(async(e,t={})=>{if(!U)throw Error(a(`projectActions.error.noActiveDirectory`));let n=$c(U,e.id);y(U);let r=Bs.getState(),i=r.getDirectoryState(U),o=L.current[n]||null,s=o?!!i?.tabs.some(e=>e.id===o):!1;(!o||!s)&&(o=r.createTab(U),L.current[n]=o),b(U,o,`Action: ${e.name}`),x(U,o,e.icon||`play`),t.revealTerminal!==!1&&(S(U,o),f(!0),p(`terminal`));let c=Bs.getState().getDirectoryState(U)?.tabs.find(e=>e.id===o);return{key:n,tabId:o,sessionId:c?.terminalSessionId??null}},[y,U,p,S,f,x,b,a]),ce=Q.useCallback(async e=>{if(s.isVSCode||!i&&c)return;if(!U){X.error(a(`projectActions.error.noActiveDirectoryForAction`));return}let t=$c(U,e.id),n=E[t];if(!(n&&n.status===`running`))try{let t=e.id===Xl?await(async()=>{let[e,t]=await Promise.all([En({id:te?.id??``,path:U}),Kl(U)]),n=await zl(U,e.actions,t);if(!n)throw Error(a(`contextPanel.preview.noDevServer`));return{id:Xl,name:a(`projectActions.actions.autoDiscover`),command:n.command,icon:`search`,autoOpenUrl:!0,openUrl:n.previewUrlHint||``}})():e,n=t.autoOpenUrl===!0&&(t.openUrl||``).trim().length>0,{key:r,tabId:i,sessionId:s}=await se(t,{revealTerminal:!n&&e.id!==Xl}),c=s,d=!1;if(!c){C(U,i,!0);try{c=(await o.createSession({cwd:U})).sessionId,d=!0,w(U,i,c)}finally{C(U,i,!1)}}if(!c)throw Error(a(`projectActions.error.failedToCreateTerminalSession`));d&&await ql(350),t.id===Xl&&(z.current[r]?.(),C(U,i,!0),z.current[r]=ft(c,e=>{e.type===`data`&&typeof e.data==`string`&&e.data.length>0&&Bs.getState().appendToBuffer(U,i,e.data),e.type===`exit`&&(Bs.getState().setTabLifecycle(U,i,`exited`),Bs.getState().setConnecting(U,i,!1),Bs.getState().removeProjectActionRun(r),delete R.current[r],z.current[r]?.(),delete z.current[r],window.clearTimeout(B.current[r]),delete B.current[r])},()=>{Bs.getState().setConnecting(U,i,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));let f=t.autoOpenUrl===!0&&l&&(t.desktopOpenSshForward||``).trim().length>0,p=t.autoOpenUrl?$l(t.openUrl):null,m=t.autoOpenUrl&&l?Zc(t.desktopOpenSshForward,u):null;D({key:r,directory:U,actionId:t.id,tabId:i,sessionId:c,status:t.id===Xl&&!p?`waiting-for-preview`:`running`}),window.clearTimeout(B.current[r]),delete B.current[r],t.id===Xl&&!p&&(B.current[r]=window.setTimeout(()=>{Bs.getState().updateProjectActionRunStatus(r,`running`),delete B.current[r]},Zl)),m?(T(U,i,null,{locked:!0}),ne(m),X.success(a(`projectActions.toast.openedForwardedUrl`))):p?(T(U,i,p,{locked:!0,autoOpened:!0}),_(U,p),X.success(a(`projectActions.toast.openedActionUrl`))):n?(T(U,i,null,{locked:!0}),X.error(a(`projectActions.error.invalidCustomUrlFormat`))):f?(T(U,i,null,{locked:!0}),X.error(a(`projectActions.error.selectedDesktopSshForwardUnavailable`))):T(U,i,null,{locked:!1,autoOpened:!1}),R.current[r]={lastSeenChunkId:null,openedUrl:!!m||!!p||n,tail:``,openInPreview:t.id===Xl};let h=Ql(t.command.trim().replace(/\r\n|\r/g,`
3
- `));await o.sendInput(c,`${h}\r`)}catch(e){k(t),delete R.current[t],z.current[t]?.(),delete z.current[t],window.clearTimeout(B.current[t]),delete B.current[t],X.error(e instanceof Error?e.message:a(`projectActions.error.failedToRunAction`))}},[u,se,i,c,l,U,ne,_,E,s.isVSCode,k,C,D,T,w,te?.id,a,o]),G=Q.useCallback(async e=>{let t=$c(U,e.id),n=E[t];if(n){O(t,`stopping`);try{await o.sendInput(n.sessionId,``)}catch{}if(await new Promise(e=>{window.setTimeout(e,1e3)}),Bs.getState().getDirectoryState(n.directory)?.tabs.find(e=>e.id===n.tabId)?.terminalSessionId===n.sessionId){if(typeof o.forceKill==`function`)try{await o.forceKill({sessionId:n.sessionId})}catch{}else try{await o.close(n.sessionId)}catch{}w(n.directory,n.tabId,null)}k(t),delete R.current[t],z.current[t]?.(),delete z.current[t],window.clearTimeout(B.current[t]),delete B.current[t]}},[U,E,k,w,o,O]),le=Q.useCallback(()=>{let e=ie??oe[0];if(!e)return;let t=$c(U,e.id),n=E[t];if(n?.status!==`stopping`){if(n){G(e);return}ce(e)}},[oe,U,ce,E,ie,G]),ue=Q.useCallback((e,t=!1)=>{if(N(e.id),!t){ce(e);return}let n=$c(U,e.id),r=E[n];if(r?.status!==`stopping`){if(r){G(e);return}ce(e)}},[U,ce,E,G]),de=Q.useCallback(()=>{te?.id&&(g(te.id),m(`projects`),h(!0))},[h,m,g,te?.id]);if(s.isVSCode||!i&&c||!te||!U)return null;let fe=ie??oe[0]??null;if(!fe)return null;let pe=fe.icon||`play`,me=fe.id===Xl?`search`:Qc[pe]||`play`,he=E[$c(U,fe.id)],ge=he?.status===`stopping`,_e=he?.status===`waiting-for-preview`,ve=he?v.get(he.directory)?.tabs.find(e=>e.id===he.tabId)?.previewUrl??null:null,ye=!!(he&&ve),be=()=>{!he||!ve||_(he.directory,ve)};return r?(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:P||ge,className:J(`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:le,"aria-label":a(he?`projectActions.actions.stopNamedAria`:`projectActions.actions.runNamedAria`,{name:fe.name}),children:ge||_e?(0,$.jsx)(Z,{name:`loader-4`,className:`h-5 w-5 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(Z,{name:`stop`,className:`h-5 w-5 text-[var(--status-warning)]`}):(0,$.jsx)(Z,{name:me,className:`h-5 w-5`})}),ye?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":a(`projectActions.actions.openPreview`),onClick:be,children:(0,$.jsx)(Z,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(Ua,{children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":a(`projectActions.actions.chooseActionAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})}),(0,$.jsxs)(Pa,{align:`end`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(La,{}),oe.map(e=>{let t=e.icon||`play`,n=e.id===Xl?`search`:Qc[t]||`play`,r=$c(U,e.id),i=E[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(Z,{name:n,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:e.name}),o||i?.status===`waiting-for-preview`?(0,$.jsx)(Z,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(Z,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]}):(0,$.jsxs)(`div`,{className:J(`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:[(0,$.jsx)(`button`,{type:`button`,onClick:le,disabled:P||ge,className:J(`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":a(he?`projectActions.actions.stopNamedAria`:`projectActions.actions.runNamedAria`,{name:fe.name}),children:(0,$.jsx)(`span`,{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center`,children:ge||_e?(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(Z,{name:`stop`,className:`h-4 w-4 text-[var(--status-warning)]`}):(0,$.jsx)(Z,{name:me,className:`h-4 w-4`})})}),ye?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:be,className:J(r?`inline-flex h-full w-8 items-center justify-center`:`inline-flex h-full w-7 items-center justify-center`,`border-l border-[var(--interactive-border)] text-foreground`,`hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),"aria-label":a(`projectActions.actions.openPreview`),children:(0,$.jsx)(Z,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(Ua,{children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(r?`inline-flex h-full w-8 items-center justify-center`:`inline-flex h-full w-7 items-center justify-center`,`border-l border-[var(--interactive-border)] text-muted-foreground`,`hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),"aria-label":a(`projectActions.actions.chooseActionAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4`})})}),(0,$.jsxs)(Pa,{align:`start`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(La,{}),oe.map(e=>{let t=e.icon||`play`,n=e.id===Xl?`search`:Qc[t]||`play`,r=$c(U,e.id),i=E[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(Z,{name:n,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:e.name}),o||i?.status===`waiting-for-preview`?(0,$.jsx)(Z,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(Z,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]})};function nu(e){return e.isOpen&&e.activeTab===e.targetTab?{open:!1,tab:e.activeTab}:{open:!0,tab:e.targetTab}}var ru=`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`,iu=`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`,au=Q.memo(function(e){let t=(0,fl.c)(17),{visible:n,title:r,ariaLabel:i,onClick:a,className:o,Icon:s,iconClassName:c,pressed:l}=e,u=n===void 0||n,d=l!==void 0&&l;if(!u)return null;let f=o??ru,p=d&&`bg-interactive-selection text-interactive-selection-foreground`,m;t[0]!==f||t[1]!==p?(m=J(f,p),t[0]=f,t[1]=p,t[2]=m):m=t[2];let h=c??`h-[18px] w-[18px]`,g;t[3]!==s||t[4]!==h?(g=(0,$.jsx)(Z,{name:s,className:h}),t[3]=s,t[4]=h,t[5]=g):g=t[5];let _;t[6]!==i||t[7]!==a||t[8]!==d||t[9]!==m||t[10]!==g?(_=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a,"aria-label":i,"aria-pressed":d,className:m,children:g})}),t[6]=i,t[7]=a,t[8]=d,t[9]=m,t[10]=g,t[11]=_):_=t[11];let v;t[12]===r?v=t[13]:(v=(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:r})}),t[12]=r,t[13]=v);let y;return t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(da,{children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16],y}),ou=Q.memo(function(e){let t=(0,fl.c)(42),{isMobile:n,githubAuthStatus:r,githubAccounts:i,githubAvatarUrl:a,githubLogin:o,isSwitchingGitHubAccount:s,handleGitHubAccountSwitch:c}=e,{t:l}=wt();if(!r?.connected||n)return null;if(i.length>1){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=J(ru,`h-6 w-6 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0`),t[0]=e):e=t[0];let n;t[1]!==o||t[2]!==l?(n=o?l(`header.github.connectedWithLogin`,{login:o}):l(`header.github.connected`),t[1]=o,t[2]=l,t[3]=n):n=t[3];let r;t[4]!==a||t[5]!==o||t[6]!==l?(r=a?(0,$.jsx)(`img`,{src:a,alt:o?l(`header.github.avatarWithLogin`,{login:o}):l(`header.github.avatar`),className:`h-full w-full object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(Z,{name:`github-fill`,className:`h-3.5 w-3.5 text-foreground`}),t[4]=a,t[5]=o,t[6]=l,t[7]=r):r=t[7];let u;t[8]!==s||t[9]!==n||t[10]!==r?(u=(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:e,title:n,disabled:s,children:r})}),t[8]=s,t[9]=n,t[10]=r,t[11]=u):u=t[11];let d;t[12]===l?d=t[13]:(d=l(`header.github.accountsTitle`),t[12]=l,t[13]=d);let f;t[14]===d?f=t[15]:(f=(0,$.jsx)(Ba,{className:`typography-ui-header font-semibold text-foreground`,children:d}),t[14]=d,t[15]=f);let p;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(La,{}),t[16]=p):p=t[16];let m;if(t[17]!==i||t[18]!==c||t[19]!==s||t[20]!==l){let e;t[22]!==c||t[23]!==s||t[24]!==l?(e=e=>{let t=e.user,n=!!e.current,r=e.source===`gh-cli`?l(`header.github.accountSource.cli`):l(`header.github.accountSource.oauth`);return(0,$.jsxs)(Da,{className:`gap-2`,disabled:s,onSelect:()=>{n||c(e.id)},children:[t?.avatarUrl?(0,$.jsx)(`img`,{src:t.avatarUrl,alt:t.login?l(`header.github.avatarWithLogin`,{login:t.login}):l(`header.github.avatar`),className:`h-6 w-6 rounded-full border border-border/60 bg-muted object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(`div`,{className:`flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted`,children:(0,$.jsx)(Z,{name:`github-fill`,className:`h-3 w-3 text-muted-foreground`})}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:t?.name?.trim()||t?.login||`GitHub`}),t?.login?(0,$.jsxs)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:t.login}),(0,$.jsx)(`span`,{className:`mx-1 opacity-50`,children:`·`}),(0,$.jsx)(`span`,{children:r})]}):null]}),n?(0,$.jsx)(Z,{name:`check`,className:`h-4 w-4 text-primary`}):null]},e.id)},t[22]=c,t[23]=s,t[24]=l,t[25]=e):e=t[25],m=i.map(e),t[17]=i,t[18]=c,t[19]=s,t[20]=l,t[21]=m}else m=t[21];let h;t[26]!==f||t[27]!==m?(h=(0,$.jsxs)(Pa,{align:`end`,className:`w-64`,children:[f,p,m]}),t[26]=f,t[27]=m,t[28]=h):h=t[28];let g;return t[29]!==u||t[30]!==h?(g=(0,$.jsxs)(Ua,{children:[u,h]}),t[29]=u,t[30]=h,t[31]=g):g=t[31],g}let u;t[32]!==o||t[33]!==l?(u=o?l(`header.github.connectedWithLogin`,{login:o}):l(`header.github.connected`),t[32]=o,t[33]=l,t[34]=u):u=t[34];let d;t[35]!==a||t[36]!==o||t[37]!==l?(d=a?(0,$.jsx)(`img`,{src:a,alt:o?l(`header.github.avatarWithLogin`,{login:o}):l(`header.github.avatar`),className:`h-full w-full object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(Z,{name:`github-fill`,className:`h-3.5 w-3.5 text-foreground`}),t[35]=a,t[36]=o,t[37]=l,t[38]=d):d=t[38];let f;return t[39]!==u||t[40]!==d?(f=(0,$.jsx)(`div`,{className:`app-region-no-drag flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80`,title:u,children:d}),t[39]=u,t[40]=d,t[41]=f):f=t[41],f}),su=Q.memo(function(e){let t=(0,fl.c)(55),{isDesktopApp:n,currentInstanceSupportsUpdate:r,isDesktopServicesOpen:i,setIsDesktopServicesOpen:a,refreshCurrentInstanceLabel:o,desktopServicesTab:s,setDesktopServicesTab:c,fetchAllQuotas:l,servicesTabItems:u,quotaLastUpdated:d,quotaDisplayMode:f,quotaDisplayTabItems:p,handleDisplayModeChange:m,handleUsageRefresh:h,isQuotaLoading:g,isUsageRefreshSpinning:_,hasRateLimits:v,rateLimitGroups:y,expandedFamilies:b,toggleFamilyExpanded:x,remoteUpdateInfo:S,remoteUpdateChecking:C,remoteUpdateError:w,onOpenRemoteUpdate:T,showPredValues:E,timeFormatPreference:D,anchorRef:O}=e,{t:k}=wt(),A;t[0]!==s||t[1]!==l||t[2]!==d||t[3]!==o||t[4]!==a?(A=e=>{a(e),e&&(o(),s===`usage`&&d===null&&l())},t[0]=s,t[1]=l,t[2]=d,t[3]=o,t[4]=a,t[5]=A):A=t[5];let j;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-hidden":!0,tabIndex:-1,className:`pointer-events-none absolute h-px w-px overflow-hidden opacity-0`})}),t[6]=j):j=t[6];let M;t[7]!==l||t[8]!==d||t[9]!==c?(M=e=>{let t=e;c(t),t===`usage`&&d===null&&l()},t[7]=l,t[8]=d,t[9]=c,t[10]=M):M=t[10];let N;t[11]!==s||t[12]!==u||t[13]!==M?(N=(0,$.jsx)(`div`,{className:`sticky top-0 z-20 px-2 pt-1.5 pb-px`,children:(0,$.jsx)(`div`,{className:`h-9`,children:(0,$.jsx)(rs,{items:u,activeId:s,onSelect:M,layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,activePillButtonClassName:`h-8`,className:`h-full`})})}),t[11]=s,t[12]=u,t[13]=M,t[14]=N):N=t[14];let P;t[15]!==r||t[16]!==s||t[17]!==n||t[18]!==i||t[19]!==T||t[20]!==C||t[21]!==w||t[22]!==S||t[23]!==a||t[24]!==k?(P=n&&s===`instance`?(0,$.jsxs)(`div`,{children:[r?(0,$.jsx)(`div`,{className:`border-b border-[var(--interactive-border)] px-4 py-2.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:k(`header.services.remoteUpdate.title`)}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:S?.available?k(`header.services.remoteUpdate.available`,{version:S.version||``}):C?k(`header.services.remoteUpdate.checking`):w||k(`header.services.remoteUpdate.upToDate`)})]}),S?.available?(0,$.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:T,children:k(`header.services.remoteUpdate.actions.open`)}):null]})}):null,(0,$.jsx)(Jr,{embedded:!0,open:i&&s===`instance`,onOpenChange:pu,onHostSwitched:()=>a(!1)})]}):null,t[15]=r,t[16]=s,t[17]=n,t[18]=i,t[19]=T,t[20]=C,t[21]=w,t[22]=S,t[23]=a,t[24]=k,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==i?(F=s===`mcp`?(0,$.jsx)(Dc,{active:i&&s===`mcp`}):null,t[26]=s,t[27]=i,t[28]=F):F=t[28];let I;t[29]!==s||t[30]!==b||t[31]!==m||t[32]!==h||t[33]!==v||t[34]!==g||t[35]!==_||t[36]!==f||t[37]!==p||t[38]!==d||t[39]!==y||t[40]!==E||t[41]!==k||t[42]!==D||t[43]!==x?(I=s===`usage`?(0,$.jsxs)(`div`,{className:`overflow-x-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold text-foreground`,children:k(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:lu(d,D)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`div`,{className:`h-7 w-[10.5rem]`,children:(0,$.jsx)(rs,{items:p,activeId:f,onSelect:e=>void m(e),layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,className:`h-full`})}),(0,$.jsx)(`button`,{type:`button`,className:J(`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:h,disabled:g||_,"aria-label":k(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(Z,{name:`refresh`,className:J(`h-4 w-4`,_&&`animate-spin`)})})]})]}),v?null:(0,$.jsx)(`div`,{className:`px-4 py-5 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:k(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`space-y-2 px-3 py-2.5`,children:y.map(e=>{let t=b[e.providerId]??[];return(0,$.jsxs)(`div`,{className:`min-w-0 rounded-xl bg-[var(--surface-muted)] p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pb-2`,children:[(0,$.jsx)(Ji,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??k(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[e.entries.map(t=>{let[n,r]=t,i=f===`remaining`?r.remainingPercent:r.usedPercent,a=r.disablePace?null:ba(r.usedPercent,r.resetAt,r.windowSeconds,n),o=a?.dailyAllocationPercent==null?null:f===`remaining`?100-ma(a.elapsedRatio):ma(a.elapsedRatio),s=Fa(r.valueLabel,i),c=fa(r.resetAt,r.resetAfterFormatted??r.resetAtFormatted,D);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground break-words`,children:ya(r.label??n)}),c?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:c}):null]}),(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(Ds,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&E?(0,$.jsx)(xs,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)}),e.modelFamilies&&e.modelFamilies.length>0?(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(n=>{let r=n.familyId??`other`,i=t.includes(r);return(0,$.jsxs)(Yc,{open:i,onOpenChange:()=>x(e.providerId,r),children:[(0,$.jsxs)(Jc,{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:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:n.familyLabel}),i?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(qc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:n.models.map(t=>{let[n,r]=t,i=f===`remaining`?r.remainingPercent:r.usedPercent,a=ba(r.usedPercent,r.resetAt,r.windowSeconds),o=a?.dailyAllocationPercent==null?null:f===`remaining`?100-ma(a.elapsedRatio):ma(a.elapsedRatio),s=Fa(r.valueLabel,i);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:Os(n)}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(Ds,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&E?(0,$.jsx)(xs,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)})})})]},r)})}):null]})]},e.providerId)})})]}):null,t[29]=s,t[30]=b,t[31]=m,t[32]=h,t[33]=v,t[34]=g,t[35]=_,t[36]=f,t[37]=p,t[38]=d,t[39]=y,t[40]=E,t[41]=k,t[42]=D,t[43]=x,t[44]=I):I=t[44];let L;t[45]!==O||t[46]!==N||t[47]!==P||t[48]!==F||t[49]!==I?(L=(0,$.jsxs)(Pa,{anchor:O,align:`start`,sideOffset:6,collisionPadding:12,className:`w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0`,children:[N,P,F,I]}),t[45]=O,t[46]=N,t[47]=P,t[48]=F,t[49]=I,t[50]=L):L=t[50];let R;return t[51]!==i||t[52]!==A||t[53]!==L?(R=(0,$.jsxs)(Ua,{open:i,onOpenChange:A,children:[j,L]}),t[51]=i,t[52]=A,t[53]=L,t[54]=R):R=t[54],R}),cu=(e,t)=>e===t?!0:!e||!t?!1:e.totalTokens===t.totalTokens&&e.pending===t.pending&&e.percentage===t.percentage&&e.contextLimit===t.contextLimit&&(e.outputLimit??0)===(t.outputLimit??0)&&(e.normalizedOutput??0)===(t.normalizedOutput??0)&&e.thresholdLimit===t.thresholdLimit&&(e.lastMessageId??``)===(t.lastMessageId??``),lu=(e,t)=>{if(!e)return`-`;try{return va(e,t,{fallback:`-`})}catch{return`-`}},uu=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},du=e=>!e?.isOpen||!Array.isArray(e.tabs)||e.tabs.length===0?null:(e.tabs.find(t=>t.id===e.activeTabId)??e.tabs[e.tabs.length-1])?.mode??null,fu=({onToggleLeftDrawer:e,onToggleRightDrawer:n,leftDrawerOpen:r,rightDrawerOpen:i})=>{let{t:a}=wt(),o=q(e=>e.setSessionSwitcherOpen),s=q(e=>e.toggleSidebar),c=q(e=>e.isSidebarOpen),l=q(e=>e.toggleBottomTerminal),u=q(e=>e.toggleRightSidebar),d=q(e=>e.openContextOverview),f=q(e=>e.openContextBrowser),p=q(e=>e.openContextPanelTab),h=q(e=>e.closeContextPanel),g=q(e=>e.contextPanelByDirectory),y=q(e=>e.activeMainTab),x=q(e=>e.setActiveMainTab),S=q(e=>e.shortcutOverrides),C=q(e=>e.timeFormatPreference),w=Zn(e=>e.getCurrentModel),T=at(),E=xn(e=>!!e.newSessionDraft?.open),O=xn(e=>e.currentSessionId),k=Rn(O??``),M=ln(O),N=An(e=>e.activeProjectId?e.projects.find(t=>t.id===e.activeProjectId)??null:null),P=Q.useMemo(()=>{if(!N)return null;let e=N.path.split(/[\\/]/).filter(Boolean);return e[e.length-1]??null},[N]),I=Cs(e=>e.results),L=Cs(e=>e.fetchAllQuotas),z=Cs(e=>e.isLoading),B=Cs(e=>e.lastUpdated),V=Cs(e=>e.displayMode),ee=Cs(e=>e.showPredValues),H=Cs(e=>e.dropdownProviderIds),ne=Cs(e=>e.loadSettings),re=Cs(e=>e.setDisplayMode),{isMobile:U}=eo(),ie=_a().data??null,G=Ms(e=>e.setStatus),le=Q.useRef(null),[ue,de]=Q.useState(()=>typeof window>`u`?!1:F()),fe=Q.useMemo(()=>D(),[]),pe=ue&&A()===`win32`,me=to(),[he,ge]=Q.useState(!1),_e=Q.useMemo(()=>typeof navigator>`u`?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||``),[]),{usesFramelessChrome:ve,side:ye}=zs(),be=Q.useMemo(()=>{if(typeof window>`u`)return null;let e=window.__YURI_MACOS_MAJOR__;if(typeof e==`number`&&Number.isFinite(e)&&e>0)return e;if(typeof navigator>`u`)return null;let t=(navigator.userAgent||``).match(/Mac OS X (\d+)[._](\d+)/);if(!t)return null;let n=Number.parseInt(t[1],10),r=Number.parseInt(t[2],10);return Number.isNaN(n)?null:n===10?r:n},[]);(0,Q.useEffect)(()=>{typeof window>`u`||de(F())},[]);let xe=w(),Se=xe&&typeof xe.limit==`object`&&xe.limit!==null?xe.limit:null,Ce=Se&&typeof Se.context==`number`?Se.context:0,we=Se&&typeof Se.output==`number`?Se.output:0,Te=qn(O??``,Ce,we),Ee=E?null:Te,[De,Oe]=Q.useState(null),ke=!O||k;(0,Q.useEffect)(()=>{if(!O){Oe(e=>e===null?e:null);return}if(Ee){Oe(e=>cu(e,Ee)?e:Ee);return}ke&&Oe(e=>e===null?e:null)},[Ee,O,ke]);let Ae=q(e=>e.isSessionSwitcherOpen),je=ie?.connected?ie.user?.avatarUrl??null:null,Me=ie?.connected?ie.user?.login??null:null,Ne=ie?.accounts??[],[K,Pe]=Q.useState(!1),[Fe,Ie]=Q.useState(!1),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(`Local`),[Ue,We]=Q.useState(!1),[Ge,Ke]=Q.useState(!1),[qe,Je]=Q.useState(null),[Ye,Xe]=Q.useState(!1),[Ze,Qe]=Q.useState(null),[$e,et]=Q.useState(ue?`instance`:`usage`),[tt,nt]=Q.useState(`usage`);(0,Q.useEffect)(()=>{!ue&&$e===`instance`&&et(`usage`)},[$e,ue]);let rt=Q.useMemo(()=>te(),[]),it=q(e=>e.workStatusPanelEnabled),ot=q(e=>e.workStatusPanelFits),st=q(e=>e.workStatusOverlayOpen),ct=q(e=>e.setWorkStatusPanelEnabled),lt=q(e=>e.setWorkStatusOverlayOpen),ut=it&&ot||st,dt=_t(()=>{if(it&&!ot){lt(!st);return}ct(!it)}),ft=!rt&&y===`chat`&&!!De,pt=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,mt=_t(async()=>{if(!(typeof window>`u`||!ue))try{if(v()){He(`Local`),We(!1);return}let e=await se(),t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,n=m();if(n&&ae(n,t)){He(`Local`),We(!1);return}let r=e.hosts.find(e=>n?ae(n,oe(e)):!1);if(r&&!r.relay){let e=await wa();if(m()!==n)return;We(ce(r,new Set(e.instances.map(e=>e.id))))}else We(!1);if(r?.label?.trim()){He(W(r.label.trim()));return}He(`Instance`)}catch{He(`Local`),We(!1)}});(0,Q.useEffect)(()=>{mt()},[ue]);let ht=_t(async()=>{if(!Ue){Je(null),Qe(null);return}Xe(!0),Qe(null);try{let e=new URLSearchParams({appType:`web`,instanceMode:`remote`}),t=await _(`/api/yuri/update-check?${e.toString()}`,{method:`GET`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(`Server responded with ${t.status}`);let n=await t.json();Je({available:n.available??!1,version:n.version,currentVersion:n.currentVersion??`unknown`,body:n.body,nextSuggestedCheckInSec:typeof n.nextSuggestedCheckInSec==`number`?n.nextSuggestedCheckInSec:void 0,packageManager:n.packageManager,updateCommand:n.updateCommand})}catch(e){Je(null),Qe(e instanceof Error?e.message:a(`header.services.remoteUpdate.error`))}finally{Xe(!1)}});Q.useEffect(()=>{Je(null),Qe(null),Ke(!1)},[Ue,Ve]),Q.useEffect(()=>{if(!ue||!Ue)return;let e=36e5,t=!1,n=null,r=i=>{n=window.setTimeout(()=>{if(t||typeof document<`u`&&document.visibilityState!==`visible`){r(e);return}ht().finally(()=>{t||r(e)})},i)};return r(3e3),()=>{t=!0,n!==null&&window.clearTimeout(n)}},[Ue,Ve,ue]);let gt=_t(()=>{if(Ue){if(qe?.available){Ke(!0);return}ht()}});Ss();let vt=Cs(e=>e.selectedModels),yt=Cs(e=>e.expandedFamilies),bt=Cs(e=>e.toggleFamilyExpanded),xt=Q.useMemo(()=>{let e=[];for(let t of gs(I)){if(!H.includes(t.id))continue;let n=I.find(e=>e?.providerId===t.id),r=n?.usage?.windows??{},i=n?.usage?.models,o=Object.entries(r),s={providerId:t.id,providerName:t.name,entries:o,error:n&&!n.ok&&n.configured?n.error:void 0};if(i&&Object.keys(i).length>0){let e=vt[t.id]??[],n=e.length>0,r=ws(i,t.id),o=js(t.id),c=vs(o);s.modelFamilies=[];for(let t of c){let a=r.get(t.id)??[];if(a.length===0)continue;let o=n?a.filter(t=>e.includes(t)):a;if(o.length===0)continue;let c=[];for(let e of o){let t=i[e];if(t?.windows){let n=Object.entries(t.windows);n.length>0&&c.push([e,n[0][1]])}}c.length>0&&s.modelFamilies.push({familyId:t.id,familyLabel:t.label,models:c})}let l=r.get(null)??[],u=n?l.filter(t=>e.includes(t)):l;if(u.length>0){let e=[];for(let t of u){let n=i[t];if(n?.windows){let r=Object.entries(n.windows);r.length>0&&e.push([t,r[0][1]])}}e.length>0&&s.modelFamilies.push({familyId:null,familyLabel:a(`header.services.modelFamily.other`),models:e})}}(o.length>0||s.modelFamilies&&s.modelFamilies.length>0||s.error)&&e.push(s)}return e},[H,I,vt,a]),Ct=xt.length>0;Q.useEffect(()=>{ne()},[ne]);let Tt=Q.useCallback(async e=>{re(e);try{await R({usageDisplayMode:e})}catch(e){console.warn(`Failed to update usage display mode:`,e)}},[re]),Et=Q.useCallback(()=>{if(ze)return;Be(!0);let e=new Promise(e=>setTimeout(e,500));Promise.all([L(),e]).finally(()=>{Be(!1)})},[L,ze]),Dt=xn(e=>O?e.worktreeMetadata.get(O)?.path??``:``),Ot=Q.useMemo(()=>uu(Dt||``),[Dt]),kt=Q.useMemo(()=>uu((typeof M?.directory==`string`?M.directory:``)||``),[M?.directory]),At=xn(e=>e.newSessionDraft?.open?uu(e.newSessionDraft.bootstrapPendingDirectory??e.newSessionDraft.directoryOverride??``):``),jt=Q.useMemo(()=>Ot||kt||At,[At,kt,Ot]),Mt=Qo(),Y=Q.useMemo(()=>uu(Mt||jt||N?.path||``),[N?.path,Mt,jt]),Nt=Q.useMemo(()=>{if(!O)return P??`Yuri`;let e=M?.title?.trim();return e&&e.length>0?e:`Untitled Session`},[P,M?.title,O]),Pt=Q.useMemo(()=>uu(jt||N?.path||``),[N?.path,jt]),Ft=Q.useMemo(()=>N?{id:N.id,path:N.path}:null,[N]),It=Q.useRef(null);Q.useEffect(()=>{!Ft||!Pt||(It.current={projectRef:Ft,directory:Pt})},[Pt,Ft]);let Lt=Q.useMemo(()=>Ft&&Pt?{projectRef:Ft,directory:Pt}:It.current,[Pt,Ft]),Rt=Q.useCallback(async e=>{if(!(!e||K)){Pe(!0);try{let t=T.github?await T.github.authActivate(e):await(async()=>{let t=await _(`/api/github/auth/activate`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({accountId:e})}),n=await t.json().catch(()=>null);if(!t.ok||!n)throw Error(n?.error||t.statusText);return n})();G(t)}catch(e){console.error(`Failed to switch GitHub account:`,e)}finally{Pe(!1)}}},[K,T.github,G]),zt=Q.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(!e)return;let t=e.tagName;(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)&&e.blur()},[]),Bt=Q.useCallback(()=>{if(U){zt(),o(!Ae);return}s()},[zt,U,Ae,o,s]),Vt=Q.useCallback(()=>{j(`desktop_open_draft_mini_chat_window`,{directory:uu(jt||N?.path||``),projectId:N?.id??null,apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open draft mini chat window`,e)})},[N?.id,N?.path,jt]),Ht=Q.useCallback(()=>{if(E){Vt();return}O&&j(`desktop_open_session_mini_chat_window`,{sessionId:O,directory:uu(jt||N?.path||``),apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open session mini chat window`,e)})},[N?.path,O,Vt,E,jt]),Ut=Q.useCallback(()=>{let e=Y;if(!e)return;let t=g[e];if(du(t)===`context`){h(e);return}d(e)},[h,Y,g,d]),Wt=Q.useMemo(()=>{let e=Y;if(!e)return!1;let t=g[e];return du(t)===`context`},[Y,g]),Gt=Q.useCallback(()=>{let e=Y;if(!e)return;let t=g[e];if(du(t)===`diff`){h(e);return}p(e,{mode:`diff`,stagedDiff:!1})},[h,Y,g,p]),Kt=Q.useCallback(()=>{let e=Y;if(!e)return;let t=g[e];if(du(t)===`browser`){h(e);return}f(e)},[h,Y,g,f]),qt=Q.useMemo(()=>{let e=Y;if(!e)return!1;let t=g[e];return du(t)===`browser`},[Y,g]),Jt=ru,Yt=iu,Xt=Q.useMemo(()=>Fe?`services`:r?`sessions`:i?`git`:y,[y,Fe,r,i]),Zt=Q.useCallback(()=>{Ie(!1),r&&e&&e(),i&&n&&n(),!e&&Ae&&o(!1)},[Ae,r,e,n,i,o]),Qt=Q.useCallback(()=>{r||Ie(!1),e?.()},[r,e]),$t=Q.useCallback(()=>{i||Ie(!1),n?.()},[n,i]),en=Q.useMemo(()=>ue&&_e&&!he?`5.5rem`:me?`max(calc(0.75rem + var(--yuri-wco-left-inset, 0px)), 5.5rem)`:(!ue||ve)&&!rt?`calc(0.75rem + var(--yuri-wco-left-inset, 0px))`:`0.75rem`,[ue,he,_e,me,rt,ve]);(0,Q.useEffect)(()=>{typeof document>`u`||document.documentElement.style.setProperty(`--yuri-titlebar-left-inset`,en)},[en]);let tn=c?`0.75rem`:`var(--yuri-titlebar-left-inset, 0.75rem)`,nn=c?`0px`:`calc(var(--yuri-titlebar-controls-width, 5.5rem) + 0.5rem)`;(0,Q.useEffect)(()=>{if(!ue||!_e){ge(!1);return}let e=!1,t=async()=>{try{let t=await j(`desktop_is_window_fullscreen`);e||ge(t===!0)}catch{e||ge(!1)}},n=()=>{t()};return t(),window.addEventListener(`yuri:window-resized`,n),()=>{e=!0,window.removeEventListener(`yuri:window-resized`,n)}},[ue,_e]);let X=Q.useMemo(()=>!ue||!_e||be===null?``:be>=26?`h-12`:be<=15?`h-14`:``,[ue,_e,be]),rn=Q.useMemo(()=>{if(!(ue&&!ve||rt))return{paddingRight:`calc(0.75rem + var(--yuri-wco-right-inset, 0px))`,minHeight:`max(3rem, var(--yuri-wco-titlebar-height, 0px))`,height:`max(3rem, var(--yuri-wco-titlebar-height, 0px))`}},[ue,rt,ve]),an=Q.useCallback(()=>{if(typeof document>`u`)return;let e=le.current?.getBoundingClientRect().height;e&&document.documentElement.style.setProperty(`--yuri-header-height`,`${e}px`)},[]);(0,Q.useEffect)(()=>{if(typeof window>`u`)return;an();let e=le.current;if(!e||typeof ResizeObserver>`u`)return()=>{};let t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,an()})},r=new ResizeObserver(n);return r.observe(e),window.addEventListener(`resize`,n),window.addEventListener(`orientationchange`,n),()=>{t&&cancelAnimationFrame(t),r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`orientationchange`,n)}},[an]),(0,Q.useEffect)(()=>{an()},[an,U,X]);let on=Q.useCallback(async e=>{let t=e.target;t.closest(`.app-region-no-drag`)||t.closest(`button, a, input, select, textarea`)||e.button===0&&ue&&await b()},[ue]),sn=Q.useMemo(()=>{if(U){let e=[{id:`chat`,label:a(`layout.mainTab.chat`),icon:`chat-thread`}];return e.push({id:`diff`,label:a(`layout.mainTab.diff`),icon:`diff`},{id:`files`,label:a(`layout.mainTab.files`),icon:`folder-6`},{id:`terminal`,label:a(`layout.mainTab.terminal`),icon:`terminal-box`},{id:`diagram`,label:a(`layout.mainTab.diagram`),icon:`file`}),e}return[]},[U,a]),cn=Q.useCallback(e=>Ra(Ma(e,S)),[S]);(0,Q.useEffect)(()=>{!U&&(y===`git`||y===`terminal`||y===`diff`||y===`files`)&&x(`chat`)},[y,U,x]);let un=Q.useMemo(()=>{let e=[];return ue&&e.push({value:`instance`,label:a(`layout.services.instance`),icon:(0,$.jsx)(Z,{name:`server`,className:`h-3.5 w-3.5`})}),e.push({value:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`})},{value:`mcp`,label:`MCP`,icon:(0,$.jsx)(_s,{className:`h-3.5 w-3.5`})}),e},[ue,a]),dn=Q.useMemo(()=>un.map(e=>({id:e.value,label:e.label,icon:e.icon})),[un]),fn=Q.useMemo(()=>[{value:`usage`,label:a(`header.services.used`)},{value:`remaining`,label:a(`header.services.remaining`)}],[a]),pn=Q.useMemo(()=>fn.map(e=>({id:e.value,label:e.label})),[fn]),mn=Q.useMemo(()=>[{id:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`})},{id:`mcp`,label:`MCP`,icon:(0,$.jsx)(_s,{className:`h-3.5 w-3.5`})}],[a]);(0,Q.useEffect)(()=>{let e=e=>{if(St(e)&&!e.shiftKey&&!e.altKey){let t=parseInt(e.key,10);t>=1&&t<=sn.length&&(e.preventDefault(),U&&(zt(),Zt()),x(sn[t-1].id))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[zt,Zt,U,x,sn]);let hn=_t(e=>{et(e),Re(!0),mt(),e===`usage`&&B===null&&L()});(0,Q.useEffect)(()=>{let e=e=>{let t=Ma(`toggle_services_menu`,S);if(Aa(e,t)){e.preventDefault();let t=nu({isOpen:Le,activeTab:$e,targetTab:ue?`instance`:`usage`});t.open?hn(t.tab):Re(!1);return}let n=Ma(`cycle_services_tab`,S);if(Aa(e,n)){e.preventDefault();let t=un.map(e=>e.value);if(t.length===0)return;let n=t.indexOf($e),r=t[n===-1?0:(n+1)%t.length];et(r),Re(!0),mt(),r===`usage`&&B===null&&L();return}let r=Ma(`open_usage`,S);if(Aa(e,r)){e.preventDefault();let t=nu({isOpen:Le,activeTab:$e,targetTab:`usage`});t.open?hn(t.tab):Re(!1);return}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,ue,Le,$e,un,B,L,mt,hn]);let gn=e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon,i=e.id===`chat`,a=e=>n?(0,$.jsx)(pl,{size:e}):r?(0,$.jsx)(Z,{name:r,className:`h-${e/4} w-${e/4}`}):null,o=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(e.id),className:J(`relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors`,t?`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`,i&&!U&&`min-w-[100px] justify-center`),"aria-label":e.label,"aria-selected":t,role:`tab`,children:[U?a(20):(0,$.jsxs)($.Fragment,{children:[a(16),(0,$.jsx)(`span`,{className:`header-tab-label`,children:e.label})]}),e.badge!==void 0&&e.badge>0&&(0,$.jsx)(`span`,{className:`header-tab-badge typography-micro text-status-info font-medium`,children:e.badge})]});return(0,$.jsx)(Q.Fragment,{children:o},e.id)},_n=fe&&(E||!!O),vn=Q.useCallback(e=>{window.setTimeout(e,0)},[]),yn=Q.useCallback(e=>{hn(e)},[hn]),bn=Q.useRef(null),Sn=(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,children:[(0,$.jsx)(`div`,{ref:bn,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center`,children:(0,$.jsxs)(Ua,{children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.actions.sessionMenuAria`),className:J(Jt,`text-muted-foreground`),children:(0,$.jsx)(Z,{name:`more-2`,className:`h-[18px] w-[18px]`})})})}),(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:a(`header.actions.sessionMenu`)})})]}),(0,$.jsxs)(Pa,{align:`start`,className:`min-w-[14rem]`,children:[rt?null:(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(Gt),children:[(0,$.jsx)(Z,{name:`layout-column`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.toggleChangesPanel`)})]}),_n?(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(Ht),children:[(0,$.jsx)(Z,{name:`picture-in-picture-2`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(E?`header.actions.newMiniChat`:`header.actions.openSessionMiniChat`)})]}):null,ue?(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(()=>yn(`instance`)),children:[(0,$.jsx)(Z,{name:`stack`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a(`header.actions.sessionMenu.servicesWithInstance`,{current:Ve})}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`toggle_services_menu`)})]}):null,(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(()=>yn(`usage`)),children:[(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.sessionMenu.viewUsage`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`open_usage`)})]}),(0,$.jsx)(La,{}),(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(l),children:[(0,$.jsx)(Z,{name:`terminal-box`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.toggleTerminalPanel`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`toggle_terminal`)})]}),(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>vn(Kt),children:[(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`contextPanel.browser.open`)}),qt?(0,$.jsx)(Z,{name:`check`,className:`h-3.5 w-3.5 text-foreground`}):null]})]})]})}),(0,$.jsx)(su,{isDesktopApp:ue,currentInstanceSupportsUpdate:Ue,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Re,refreshCurrentInstanceLabel:mt,desktopServicesTab:$e,setDesktopServicesTab:et,fetchAllQuotas:L,servicesTabItems:dn,quotaLastUpdated:B,quotaDisplayMode:V,showPredValues:ee,quotaDisplayTabItems:pn,handleDisplayModeChange:Tt,handleUsageRefresh:Et,isQuotaLoading:z,isUsageRefreshSpinning:ze,hasRateLimits:Ct,rateLimitGroups:xt,expandedFamilies:yt,toggleFamilyExpanded:bt,remoteUpdateInfo:qe,remoteUpdateChecking:Ye,remoteUpdateError:Ze,onOpenRemoteUpdate:gt,timeFormatPreference:C,anchorRef:bn})]}),Cn=(0,$.jsxs)($.Fragment,{children:[!U&&!rt&&y===`chat`?(0,$.jsx)(`button`,{type:`button`,"data-work-status-toggle":`true`,"aria-pressed":ut,"aria-label":a(`header.workStatusPanel.toggleAria`),title:a(`header.workStatusPanel.toggleAria`),onClick:dt,className:J(`app-region-no-drag group inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors`,ut?`text-foreground`:`text-muted-foreground/50`),children:(0,$.jsx)(Z,{name:`settings-2`,className:`size-4`})}):null,(0,$.jsx)(Il,{directory:Pt}),(0,$.jsx)(au,{title:a(`header.actions.rightSidebarWithShortcut`,{shortcut:cn(`toggle_right_sidebar`)}),ariaLabel:a(`header.actions.toggleRightSidebarAria`),onClick:u,className:`app-region-no-drag group inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover hover:text-foreground transition-colors`,Icon:`layout-left-rounded`,iconClassName:`size-4 -scale-x-100 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),(0,$.jsx)(ou,{isMobile:U,githubAuthStatus:ie,githubAccounts:Ne,githubAvatarUrl:je,githubLogin:Me,isSwitchingGitHubAccount:K,handleGitHubAccountSwitch:Rt})]}),wn=()=>(0,$.jsxs)(`div`,{onMouseDown:on,className:J(`app-region-drag relative flex h-12 select-none items-center pr-3`,X),style:rn,role:`tablist`,"aria-label":a(`header.navigation.mainAria`),children:[(0,$.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:tn}}),(0,$.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:nn}}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,$.jsxs)(`div`,{className:`app-region-no-drag mr-3 flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Ls,{children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sessions.switcher.openAria`),className:`inline-flex h-8 min-w-0 max-w-full items-center rounded-md px-2.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-primary`,children:(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground`,children:E?a(`sessions.switcher.draftTitle`):Nt})})}),Sn]}),sn.length>0&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1`,children:sn.map(e=>gn(e))}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[ft&&De?(0,$.jsx)(Is,{pending:De.pending,totalTokens:De.totalTokens,percentage:pt,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:`compact`,appearance:`subtle`,onClick:Ut,pressed:Wt}):null,Cn,(0,$.jsx)(Rs,{visible:ve&&ye===`right`,position:`right`})]})]})]}),Tn=()=>(0,$.jsxs)(`div`,{className:`app-region-drag relative flex items-center gap-2 px-3 py-2 select-none`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e?(0,$.jsx)(`button`,{type:`button`,onClick:Qt,className:J(Yt,Xt===`sessions`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":a(r?`header.actions.closeSessionsAria`:`header.actions.openSessionsAria`),children:(0,$.jsx)(Z,{name:`layout-left`,className:`h-5 w-5`})}):Ae?(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active`,"aria-label":a(`header.actions.backAria`),children:(0,$.jsx)(Z,{name:`arrow-left-s`,className:`h-5 w-5`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Bt,className:`app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active`,"aria-label":a(`header.actions.openSessionsAria`),children:(0,$.jsx)(Z,{name:`play-list-add`,className:`h-5 w-5`})}),!e&&Ae&&(0,$.jsx)(`span`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`header.sessions.title`)})]}),(!Ae||!!e)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`app-region-no-drag flex min-w-0 flex-1 items-center`,children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain`,children:(0,$.jsx)(`div`,{className:`flex w-max items-center gap-1 pr-1`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5`,role:`tablist`,"aria-label":a(`header.navigation.mainAria`),children:sn.map(e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon;return(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U&&(zt(),Zt()),x(e.id)},"aria-label":e.label,"aria-selected":t,role:`tab`,className:J(Yt,`relative rounded-lg`,Xt===e.id&&`bg-interactive-selection text-interactive-selection-foreground`),children:[n?(0,$.jsx)(pl,{className:`h-5 w-5`}):r?(0,$.jsx)(Z,{name:r,className:`h-5 w-5`}):null,e.badge!==void 0&&e.badge>0&&(0,$.jsx)(`span`,{className:`absolute -top-1 -right-1 text-[10px] font-semibold text-primary`,children:e.badge}),e.showDot&&(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary`,"aria-label":a(`header.changes.availableAria`)})]})}),(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:e.label})})]},e.id)})})})})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[Lt&&(0,$.jsx)(tu,{projectRef:Lt.projectRef,directory:Lt.directory,compact:!0,allowMobile:!0,className:`h-9`}),(0,$.jsxs)(Ua,{open:Fe,onOpenChange:t=>{t&&(r&&e&&e(),i&&n&&n()),Ie(t),t&&B===null&&L()},children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.services.viewAria`),className:J(Yt,Xt===`services`&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(Z,{name:`stack`,className:`h-5 w-5`})})})}),(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:a(`header.services.title`)})})]}),(0,$.jsx)(Pa,{align:`end`,sideOffset:0,positionerClassName:`!fixed !bottom-0 !left-0 !right-0 !top-[var(--yuri-header-height,56px)] !transform-none`,className:`h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`flex h-full flex-col bg-[var(--surface-elevated)]`,children:[(0,$.jsx)(`div`,{className:`sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-0`,children:[(0,$.jsx)(`div`,{className:`h-10 min-w-0 flex-1`,children:(0,$.jsx)(rs,{items:mn,activeId:tt,onSelect:e=>{let t=e;nt(t),t===`usage`&&B===null&&L()},layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,activePillButtonClassName:`h-8`,className:`h-full`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Ie(!1),className:`inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover`,"aria-label":a(`header.services.closeAria`),children:(0,$.jsx)(Z,{name:`close`,className:`h-5 w-5`})})]})}),tt===`mcp`&&(0,$.jsx)(Dc,{active:Fe&&tt===`mcp`}),tt===`usage`&&(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]`,children:[(0,$.jsx)(`div`,{className:`border-b border-[var(--interactive-border)]`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col min-w-0 gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold text-foreground`,children:a(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:lu(B,C)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center h-6`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Tt(`usage`),className:J(`typography-ui-label px-1 pb-0.5 transition-colors`,V===`usage`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:a(`header.services.used`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground typography-ui-label px-0.5`,children:`·`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Tt(`remaining`),className:J(`typography-ui-label px-1 pb-0.5 transition-colors`,V===`remaining`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:a(`header.services.remaining`)})]}),(0,$.jsx)(`button`,{type:`button`,className:J(`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:Et,disabled:z||ze,"aria-label":a(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(Z,{name:`refresh`,className:J(`h-4 w-4`,ze&&`animate-spin`)})})]})]})}),!Ct&&(0,$.jsx)(`div`,{className:`px-4 py-6 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:a(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`py-1`,children:xt.map((e,t)=>(0,$.jsxs)(Q.Fragment,{children:[t>0?(0,$.jsx)(`div`,{className:`mx-4 my-1 border-t border-[var(--interactive-border)]`}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2`,children:[(0,$.jsx)(Ji,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{className:`px-4 pb-2`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??a(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3 px-4 pb-2`,children:[e.entries.map(([t,n])=>{let r=V===`remaining`?n.remainingPercent:n.usedPercent,i=n.disablePace?null:ba(n.usedPercent,n.resetAt,n.windowSeconds,t),a=i?.dailyAllocationPercent==null?null:V===`remaining`?100-ma(i.elapsedRatio):ma(i.elapsedRatio),o=Fa(n.valueLabel,r),s=fa(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,C);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground break-words`,children:ya(n.label??t)}),s?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:s}):null]}),(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(Ds,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ee?(0,$.jsx)(xs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)}),e.modelFamilies&&e.modelFamilies.length>0&&(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(t=>{let n=(yt[e.providerId]??[]).includes(t.familyId??`other`);return(0,$.jsxs)(Yc,{open:n,onOpenChange:()=>bt(e.providerId,t.familyId??`other`),children:[(0,$.jsxs)(Jc,{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:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:t.familyLabel}),n?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(qc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:t.models.map(([t,n])=>{let r=V===`remaining`?n.remainingPercent:n.usedPercent,i=ba(n.usedPercent,n.resetAt,n.windowSeconds),a=i?.dailyAllocationPercent==null?null:V===`remaining`?100-ma(i.elapsedRatio):ma(i.elapsedRatio),o=Fa(n.valueLabel,r);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:Os(t)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(Ds,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ee?(0,$.jsx)(xs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)})})})]},t.familyId??`other`)})})]})]},e.providerId))})]})]})})]}),n?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:$t,className:J(Yt,`relative`,Xt===`git`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":i?`Close git sidebar`:`Open git sidebar`,children:(0,$.jsx)(Z,{name:`layout-right`,className:`h-5 w-5`})})}),(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:i?`Close git sidebar`:`Open git sidebar`})})]}):null]})]})]}),En=J(`header-safe-area relative z-10 bg-background`,pe&&`bg-[var(--surface-background)] backdrop-blur-none`,U&&`yuri-layout-divider-b`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`header`,{ref:le,className:En,style:{"--padding-scale":`1`},children:U?Tn():wn()}),(0,$.jsx)(ds,{open:Ue&&Ge,onOpenChange:Ke,info:qe,downloading:!1,downloaded:!1,progress:null,error:Ze,onDownload:()=>{},onRestart:()=>{},runtimeType:`web`})]})};function pu(){}var mu=180,hu=640,gu=110,_u=e=>{let t=(0,fl.c)(44),{isOpen:n,isMobile:r,children:i}=e,{t:a}=wt(),o=q(vu),s=q(yu),c=q(bu),l=q(xu),[u,d]=Q.useState(null),[f,p]=Q.useState(!1),m=Q.useRef(null),h=Q.useRef(0),g=Q.useRef(o||300),_=Math.min(hu,Math.max(mu,o||300)),v,y;t[0]===n?(v=t[1],y=t[2]):(v=()=>{n||(d(null),p(!1))},y=[n],t[0]=n,t[1]=v,t[2]=y),Q.useEffect(v,y);let b,x;t[3]!==s||t[4]!==r||t[5]!==n?(b=()=>{if(r||!n||!s)return;let e=()=>{let e=m.current?.parentElement?.getBoundingClientRect().height;if(!e||e<=0)return;let t=Math.max(0,Math.round(e));d(e=>e===t?e:t)};e();let t=m.current?.parentElement;if(!t)return;let i=new ResizeObserver(e);return i.observe(t),()=>{i.disconnect()}},x=[s,r,n],t[3]=s,t[4]=r,t[5]=n,t[6]=b,t[7]=x):(b=t[6],x=t[7]),Q.useEffect(b,x);let S,C;if(t[8]!==s||t[9]!==r||t[10]!==f||t[11]!==c||t[12]!==l?(S=()=>{if(r||!f||s)return;let e=e=>{let t=h.current-e.clientY,n=Math.min(hu,Math.max(mu,g.current+t));c(n)},t=()=>{p(!1),q.getState().bottomTerminalHeight<=gu&&l(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},C=[s,r,f,c,l],t[8]=s,t[9]=r,t[10]=f,t[11]=c,t[12]=l,t[13]=S,t[14]=C):(S=t[13],C=t[14]),Q.useEffect(S,C),r)return null;let w=n?s?Math.max(0,u??_):_:0,T=n&&s,E;t[15]!==w||t[16]!==s||t[17]!==n?(E=e=>{!n||s||(p(!0),h.current=e.clientY,g.current=w,e.preventDefault())},t[15]=w,t[16]=s,t[17]=n,t[18]=E):E=t[18];let D=E,O=T?`absolute inset-x-0 bottom-0 z-40`:`relative`,k=f?`transition-none`:`transition-[height] duration-300 ease-in-out`,A=(!n||T)&&`border-t-0`,j;t[19]!==A||t[20]!==O||t[21]!==k?(j=J(`flex overflow-hidden border-t border-border bg-sidebar`,O,k,A),t[19]=A,t[20]=O,t[21]=k,t[22]=j):j=t[22];let M;t[23]!==w||t[24]!==T?(M=T?{top:0}:{height:`${w}px`,minHeight:`${w}px`,maxHeight:`${w}px`},t[23]=w,t[24]=T,t[25]=M):M=t[25];let N=!n||!s&&w===0,P;t[26]!==D||t[27]!==s||t[28]!==n||t[29]!==f||t[30]!==a?(P=n&&!s&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,f&&`bg-[var(--interactive-border)]`),onPointerDown:D,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`terminalView.bottomDock.resizeAria`)}),t[26]=D,t[27]=s,t[28]=n,t[29]=f,t[30]=a,t[31]=P):P=t[31];let F=!n&&`pointer-events-none select-none opacity-0`,I;t[32]===F?I=t[33]:(I=J(`relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out`,F),t[32]=F,t[33]=I);let L=!n,R;t[34]!==i||t[35]!==I||t[36]!==L?(R=(0,$.jsx)(`div`,{className:I,"aria-hidden":L,children:i}),t[34]=i,t[35]=I,t[36]=L,t[37]=R):R=t[37];let z;return t[38]!==j||t[39]!==M||t[40]!==N||t[41]!==P||t[42]!==R?(z=(0,$.jsxs)(`section`,{ref:m,className:j,style:M,"aria-hidden":N,children:[P,R]}),t[38]=j,t[39]=M,t[40]=N,t[41]=P,t[42]=R,t[43]=z):z=t[43],z};function vu(e){return e.bottomTerminalHeight}function yu(e){return e.isBottomTerminalExpanded}function bu(e){return e.setBottomTerminalHeight}function xu(e){return e.setBottomTerminalOpen}var Su=260,Cu=260,wu=500,Tu=({isOpen:e,isMobile:t,children:n,className:r,topBar:i})=>{let{t:a}=wt(),o=q(e=>e.sidebarWidth),s=q(e=>e.setSidebarWidth),[c,l]=Q.useState(!1),u=Q.useRef(0),d=Q.useRef(o||Su),f=Q.useRef(null),p=Q.useRef(null),m=Q.useRef(null),h=Q.useCallback(e=>Math.min(wu,Math.max(Cu,e)),[]),g=Q.useCallback(e=>{let t=m.current;t&&(t.style.width=`${e}px`,t.style.minWidth=`${e}px`,t.style.maxWidth=`${e}px`,t.style.setProperty(`--yuri-left-sidebar-width`,`${e}px`))},[]);if(Q.useEffect(()=>{t&&c&&l(!1)},[t,c]),Q.useEffect(()=>{c||(f.current=null,p.current=null)},[c]),t)return null;let _=Math.min(wu,Math.max(Cu,o||Su)),v=e?_:0,y=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}p.current=t.pointerId,l(!0),u.current=t.clientX,d.current=v,f.current=v,g(v),t.preventDefault()}},b=e=>{if(t||!c||p.current!==e.pointerId)return;let n=e.clientX-u.current,r=h(d.current+n);f.current!==r&&(f.current=r,g(r))},x=e=>{if(p.current!==e.pointerId||t)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let n=h(f.current??v);p.current=null,f.current=null,l(!1),s(n)},S=c?f.current??v:v;return(0,$.jsxs)(`aside`,{ref:m,className:J(`relative flex h-full overflow-hidden yuri-layout-divider-r will-change-[width] motion-reduce:transition-none`,`bg-sidebar yuri-vibrancy-surface`,!e&&`border-r-0`,r),style:{width:`${S}px`,minWidth:`${S}px`,maxWidth:`${S}px`,"--yuri-left-sidebar-width":`${c?S:_}px`,overflowX:`clip`,transitionProperty:c?`none`:`width, min-width, max-width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||v===0,children:[e&&(0,$.jsx)(`div`,{className:J(`absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,c&&`bg-[var(--interactive-border)]`),onPointerDown:y,onPointerMove:b,onPointerUp:x,onPointerCancel:x,role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`sidebar.resize.leftPanelAria`)}),(0,$.jsxs)(`div`,{className:J(`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`,c&&`pointer-events-none`,!e&&`pointer-events-none select-none opacity-0`),style:{width:`var(--yuri-left-sidebar-width)`,overflowX:`hidden`},"aria-hidden":!e,children:[i,(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(pa,{children:n})})]})]})},Eu=()=>{let e=(0,fl.c)(3),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={height:`var(--yuri-header-height, 3rem)`},e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-drag shrink-0`,style:{width:`var(--yuri-titlebar-left-inset, 0.75rem)`}}),e[1]=n):n=e[1];let r;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsxs)(`div`,{className:`flex shrink-0`,style:t,children:[n,(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-no-drag shrink-0`,style:{width:`calc(var(--yuri-titlebar-controls-width, 5.5rem) + 0.5rem)`}}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-drag flex-1`})]}),e[2]=r):r=e[2],r},Du=e=>{let t=(0,fl.c)(21),{className:n}=e,r=ys(Ou),i,a,o,s,c,l,u;if(t[0]!==n||t[1]!==r){u=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.trim().split(/\s+/).filter(Boolean);if(e.length===0){u=null;break bb0}t[9]===n?l=t[10]:(l=J(`flex min-w-0 items-center overflow-hidden px-2 pb-2 pt-1`,n),t[9]=n,t[10]=l),i=`img`,a=e.join(` `),o=`inline-flex min-w-0 items-baseline gap-[0.25em] overflow-hidden whitespace-nowrap text-foreground`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(s={fontFamily:`"Bodoni 72", Didot, "Times New Roman", serif`,fontSize:`1.0625rem`,fontWeight:700,letterSpacing:`-0.02em`,lineHeight:1},t[11]=s):s=t[11],c=e.map(ku)}t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8];if(u!==Symbol.for(`react.early_return_sentinel`))return u;let d;t[12]!==i||t[13]!==a||t[14]!==o||t[15]!==s||t[16]!==c?(d=(0,$.jsx)(`span`,{role:i,"aria-label":a,className:o,style:s,children:c}),t[12]=i,t[13]=a,t[14]=o,t[15]=s,t[16]=c,t[17]=d):d=t[17];let f;return t[18]!==l||t[19]!==d?(f=(0,$.jsx)(`div`,{className:l,children:d}),t[18]=l,t[19]=d,t[20]=f):f=t[20],f};function Ou(e){return e.sidebarBrandName}function ku(e,t){return(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex shrink-0 items-baseline`,children:e===`Yuri`?(0,$.jsx)(bc,{width:`2.44814cap`,className:`translate-y-[0.046875cap]`}):e},t)}var Au=`app-region-no-drag inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover hover:text-foreground transition-colors`,ju=()=>{let e=(0,fl.c)(46),{t}=wt(),n=q(Mu),r=q(Nu),i=q(Pu),a=q(Fu),o=ys(Iu),s=Q.useRef(null),c=Ra(Ma(`toggle_sidebar`,a)),{usesFramelessChrome:l,side:u}=zs(),d;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=F(),e[0]=d):d=e[0];let f=d,p=!f||!n||!o,m;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=z()&&!f&&!te(),e[1]=m):m=e[1];let h=m,g=Ru,_,v;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{if(typeof document>`u`)return;let e=s.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect().width;document.documentElement.style.setProperty(`--yuri-titlebar-controls-width`,`${Math.round(t)}px`)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},v=[],e[2]=_,e[3]=v):(_=e[2],v=e[3]),Q.useEffect(_,v);let y=h&&n?`${r||260}px`:void 0,b;e[4]===y?b=e[5]:(b={height:`var(--yuri-header-height, 3rem)`,paddingLeft:`var(--yuri-titlebar-left-inset, 0.75rem)`,width:y},e[4]=y,e[5]=b);let x=h&&n&&`w-full justify-between`,S;e[6]===x?S=e[7]:(S=J(`flex items-center gap-2`,x),e[6]=x,e[7]=S);let C;e[8]===n?C=e[9]:(C=h&&n?(0,$.jsx)(Du,{className:`flex min-w-0 items-center p-0`}):null,e[8]=n,e[9]=C);let w;e[10]!==l||e[11]!==u?(w=l&&u===`left`?(0,$.jsx)(Rs,{visible:!0,position:`left`}):null,e[10]=l,e[11]=u,e[12]=w):w=e[12];let T;e[13]!==t||e[14]!==l?(T=l?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:g,"aria-label":t(`header.actions.openAppMenuAria`),className:J(Au,`shrink-0`),children:(0,$.jsx)(Z,{name:`menu-2`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(la,{children:(0,$.jsx)(`p`,{children:t(`header.actions.openAppMenu`)})})]}):null,e[13]=t,e[14]=l,e[15]=T):T=e[15];let E;e[16]===p?E=e[17]:(E=p?(0,$.jsx)(yc,{}):null,e[16]=p,e[17]=E);let D=da,O;e[18]===t?O=e[19]:(O=t(`header.actions.openSessionsAria`),e[18]=t,e[19]=O);let k,A;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(k=J(Au,`group shrink-0`),A=(0,$.jsx)(Z,{name:`layout-left-rounded`,className:`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),e[20]=k,e[21]=A):(k=e[20],A=e[21]);let j;e[22]!==O||e[23]!==i?(j=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,"aria-label":O,className:k,children:A})}),e[22]=O,e[23]=i,e[24]=j):j=e[24];let M=la,N=t(`header.actions.openSessionsWithShortcut`,{shortcut:c}),P;e[25]===N?P=e[26]:(P=(0,$.jsx)(`p`,{children:N}),e[25]=N,e[26]=P);let I;e[27]!==M||e[28]!==P?(I=(0,$.jsx)(M,{children:P}),e[27]=M,e[28]=P,e[29]=I):I=e[29];let L;e[30]!==D||e[31]!==j||e[32]!==I?(L=(0,$.jsxs)(D,{children:[j,I]}),e[30]=D,e[31]=j,e[32]=I,e[33]=L):L=e[33];let R;e[34]!==E||e[35]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[E,L]}),e[34]=E,e[35]=L,e[36]=R):R=e[36];let B;e[37]!==w||e[38]!==T||e[39]!==R||e[40]!==S||e[41]!==C?(B=(0,$.jsxs)(`div`,{ref:s,className:S,children:[C,w,T,R]}),e[37]=w,e[38]=T,e[39]=R,e[40]=S,e[41]=C,e[42]=B):B=e[42];let V;return e[43]!==B||e[44]!==b?(V=(0,$.jsx)(`div`,{className:`app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2`,style:b,children:B}),e[43]=B,e[44]=b,e[45]=V):V=e[45],V};function Mu(e){return e.isSidebarOpen}function Nu(e){return e.sidebarWidth}function Pu(e){return e.toggleSidebar}function Fu(e){return e.shortcutOverrides}function Iu(e){return e.sidebarBrandName.trim().length>0}function Lu(e){console.warn(`[titlebar] failed to open app menu`,e)}function Ru(e){let t=e.currentTarget.getBoundingClientRect();j(`desktop_show_app_menu`,{x:t.left,y:t.bottom}).catch(Lu)}var zu=420,Bu=({isOpen:e,children:t,className:n})=>{let{t:r}=wt(),i=q(e=>e.rightSidebarWidth),a=q(e=>e.setRightSidebarWidth),[o,s]=Q.useState(!1),c=Q.useRef(0),l=Q.useRef(i||zu),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),p=Q.useCallback(e=>Math.min(860,Math.max(360,e)),[]),m=Q.useCallback(e=>{let t=f.current;t&&(t.style.width=`${e}px`,t.style.minWidth=`${e}px`,t.style.maxWidth=`${e}px`,t.style.setProperty(`--yuri-right-sidebar-width`,`${e}px`))},[]),h=Math.min(860,Math.max(360,i||zu)),g=e?h:0;Q.useLayoutEffect(()=>{if(o)return;let e=f.current;e&&(e.style.minWidth=``,e.style.maxWidth=``)},[e,o,h]);let _=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}d.current=t.pointerId,s(!0),c.current=t.clientX,l.current=g,u.current=g,m(g),t.preventDefault()}},v=e=>{if(!o||d.current!==e.pointerId)return;let t=c.current-e.clientX,n=p(l.current+t);u.current!==n&&(u.current=n,m(n))},y=e=>{if(d.current!==e.pointerId)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=p(u.current??g);d.current=null,u.current=null,s(!1),a(t)},b=o?u.current??g:g;return(0,$.jsxs)(`aside`,{ref:f,className:J(`relative flex h-full overflow-hidden yuri-layout-divider-l will-change-[width] motion-reduce:transition-none`,`bg-sidebar`,!e&&`border-l-0`,n),style:{width:`${b}px`,"--yuri-right-sidebar-width":`${o?b:h}px`,overflowX:`clip`,transitionProperty:o?`none`:`width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||g===0,children:[e&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,o&&`bg-[var(--interactive-border)]`),onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:y,role:`separator`,"aria-orientation":`vertical`,"aria-label":r(`sidebar.resize.rightPanelAria`)}),(0,$.jsx)(`div`,{className:J(`relative z-10 flex h-full min-h-0 shrink-0 flex-col pt-2 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,o&&`pointer-events-none`,!e&&`pointer-events-none select-none opacity-0`),style:{width:`var(--yuri-right-sidebar-width)`},"aria-hidden":!e,children:e?t:null})]})},Vu=12,Hu=[{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`}],Uu=e=>{let t=(0,fl.c)(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:o,onComplete:s}=e,c=r===void 0?0:r,l=a===void 0?900:a,u=o===void 0?Hu:o,d=Q.useRef(!1),f,p;t[0]!==n||t[1]!==s?(f=()=>{!n&&d.current&&s?.(),n&&(d.current=!0)},p=[n,s],t[0]=n,t[1]=s,t[2]=f,t[3]=p):(f=t[2],p=t[3]),Q.useEffect(f,p);let m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=Array.from({length:Vu},Wu),t[4]=m):m=t[4];let h=m;if(!n)return null;let g;t[5]===i?g=t[6]:(g=J(`fireworks-overlay pointer-events-none`,i),t[5]=i,t[6]=g);let _;if(t[7]!==c||t[8]!==u||t[9]!==l){let e;t[11]!==c||t[12]!==l?(e=e=>{let t={"--burst-delay":`${e.delay}ms`,"--burst-x":`${e.x}%`,"--burst-y":`${e.y}%`,"--firework-color":`var(${e.colorVar})`,"--firework-duration":`${l}ms`};return(0,$.jsx)(`div`,{className:`firework-burst`,style:t,children:h.map((t,n)=>{let r=t.x*e.radius,i=t.y*e.radius,a={"--translate-x":`${r}px`,"--translate-y":`${i}px`,"--particle-delay":`${t.delay}ms`,color:`var(${e.colorVar})`};return(0,$.jsx)(`span`,{className:`firework-particle`,style:a},`${e.id}-${n}-${c}`)})},`${e.id}-${c}`)},t[11]=c,t[12]=l,t[13]=e):e=t[13],_=u.map(e),t[7]=c,t[8]=u,t[9]=l,t[10]=_}else _=t[10];let v;return t[14]!==c||t[15]!==g||t[16]!==_?(v=(0,$.jsx)(`div`,{className:g,"aria-hidden":`true`,"data-burst-key":c,children:_}),t[14]=c,t[15]=g,t[16]=_,t[17]=v):v=t[17],v};function Wu(e,t){let n=Math.PI*2*t/Vu;return{x:Math.cos(n),y:Math.sin(n),delay:t*18}}var Gu=e=>{let t=(0,fl.c)(13),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{durationMs:r}=n,i=r===void 0?3400:r,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a={isActive:!1,cycle:0},t[2]=a):a=t[2];let[o,s]=Q.useState(a),c=Q.useRef(null),l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{c.current&&=(window.clearTimeout(c.current),null)},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{u(),s(Ku)},t[4]=d):d=t[4];let f=d,p;t[5]===i?p=t[6]:(p=()=>{u(),s(qu),c.current=window.setTimeout(()=>{s(Ju),c.current=null},i)},t[5]=i,t[6]=p);let m=p,h,g;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>()=>u(),g=[u],t[7]=h,t[8]=g):(h=t[7],g=t[8]),Q.useEffect(h,g);let _;return t[9]!==o.cycle||t[10]!==o.isActive||t[11]!==m?(_={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:m,dismissFireworks:f},t[9]=o.cycle,t[10]=o.isActive,t[11]=m,t[12]=_):_=t[12],_};function Ku(e){return e.isActive?{...e,isActive:!1}:e}function qu(e){return{isActive:!0,cycle:e.cycle+1}}function Ju(e){return e.isActive?{...e,isActive:!1}:e}var Yu=Q.createContext(void 0),Xu=e=>{let t=(0,fl.c)(10),{children:n}=e,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=Gu(),s;t[0]!==o||t[1]!==a?(s={triggerFireworks:a,dismissFireworks:o},t[0]=o,t[1]=a,t[2]=s):s=t[2];let c=s,l;t[3]!==i||t[4]!==r?(l=(0,$.jsx)(Uu,{isActive:r,burstKey:i}),t[3]=i,t[4]=r,t[5]=l):l=t[5];let u;return t[6]!==n||t[7]!==l||t[8]!==c?(u=(0,$.jsxs)(Yu.Provider,{value:c,children:[n,l]}),t[6]=n,t[7]=l,t[8]=c,t[9]=u):u=t[9],u},Zu=()=>{let e=Q.useContext(Yu);if(!e)throw Error(`useFireworksCelebration must be used within FireworksProvider`);return e},Qu=`gitmojiCache`,$u=6048e5,ed=`1`,td=`https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json`,nd=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.emoji==`string`&&typeof t.code==`string`&&typeof t.description==`string`},rd=()=>{if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(Qu);if(!e)return null;let t=JSON.parse(e);return!t||t.version!==ed||typeof t.fetchedAt!=`number`||!Array.isArray(t.gitmojis)?null:{gitmojis:t.gitmojis.filter(nd),fetchedAt:t.fetchedAt,version:t.version}}catch{return null}},id=e=>{if(!(typeof window>`u`))try{let t={gitmojis:e,fetchedAt:Date.now(),version:ed};window.localStorage.setItem(Qu,JSON.stringify(t))}catch{return}},ad=e=>Date.now()-e.fetchedAt<$u,od=null,sd=new Set,cd=async()=>{if(od)return od;let e=(async()=>{try{let e=await fetch(td);if(!e.ok)throw Error(`Failed to load gitmojis: ${e.statusText}`);let t=await e.json(),n=Array.isArray(t.gitmojis)?t.gitmojis.filter(nd):[];return id(n),sd.forEach(e=>e(n)),n}catch(e){console.warn(`Failed to load gitmoji list:`,e);let t=[];return sd.forEach(e=>e(t)),t}finally{od=null}})();return od=e,e},ld=e=>{let[t,n]=Q.useState(()=>e?rd()?.gitmojis??[]:[]),[r,i]=Q.useState(!1),a=Q.useRef(e);return a.current=e,Q.useEffect(()=>{if(!e){sd.delete(n),n([]),i(!1);return}let t=rd();if(t&&(n(t.gitmojis),ad(t)))return;sd.add(n),i(!0);let r=!1;return cd().finally(()=>{!r&&a.current&&i(!1)}),()=>{r=!0,sd.delete(n)}},[e]),{gitmojis:t,isLoading:r,ensureLoaded:Q.useCallback(async()=>{if(!a.current)return[];if(t.length>0)return t;let e=rd();return e&&ad(e)?e.gitmojis:cd()},[t])}},ud=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)};function dd(e,t,n){let r=(0,fl.c)(5),[i,a]=Q.useState(),o,s;return r[0]!==n||r[1]!==e||r[2]!==t?(o=()=>{if(t){a(void 0);return}if(!e){a(void 0);return}a(void 0);let r=!1;return(async()=>{let[t,i]=await Promise.all([Tr(e),mr(e)]).catch(fd);if(r)return;let o=ud(t),s=ud(i);if(!o||!s||s===o)return;let c=n||``,l=s.split(`/`).filter(Boolean).pop()||s;a({source:`sdk`,path:s,projectDirectory:o,branch:c,label:c||l,name:l,worktreeRoot:s,worktreeStatus:`ready`,headState:c?`branch`:`unborn`,worktreeSource:`existing`})})(),()=>{r=!0}},s=[e,t,n],r[0]=n,r[1]=e,r[2]=t,r[3]=o,r[4]=s):(o=r[3],s=r[4]),Q.useEffect(o,s),t??i}function fd(){return[``,``]}var pd=({open:e,onOpenChange:t,directory:n,hasUncommittedChanges:r,hasStagedChanges:i=!1,uncommittedFileCount:a,onChanged:o})=>{let{t:s}=wt(),[c,l]=Q.useState([]),[u,d]=Q.useState(!1),[f,p]=Q.useState(``),[m,h]=Q.useState(``),[g,_]=Q.useState(null),[v,y]=Q.useState({}),b=Q.useCallback(async()=>{if(n){d(!0);try{let e=await hr(n);l(e.stashes),y({})}catch(e){X.error(e instanceof Error?e.message:s(`gitView.stashes.toast.loadFailed`))}finally{d(!1)}}},[n,s]);Q.useEffect(()=>{e&&b()},[b,e]),Q.useEffect(()=>{if(!e||!n||c.length===0)return;let t=!1,r=c.map(e=>e.ref);return br(n,r).then(e=>{t||y(e.counts)}).catch(()=>void 0),()=>{t=!0}},[n,e,c]);let x=Q.useMemo(()=>{let e=f.trim().toLowerCase();return e?c.filter(t=>`${t.ref} ${t.message} ${t.relativeTime}`.toLowerCase().includes(e)):c},[f,c]),S=Q.useCallback(async e=>{await b(),await o?.(e)},[b,o]),C=async()=>{if(!(!n||g)){_(`create`);try{let e=await vr(n,{message:m.trim()||void 0});e.created?(X.success(s(`gitView.stashes.toast.created`)),h(``)):X.info(s(`gitView.stashes.toast.noChanges`)),await S({affectsIndex:!!(e.created&&i)})}catch(e){X.error(e instanceof Error?e.message:s(`gitView.stashes.toast.createFailed`))}finally{_(null)}}},w=async(e,t)=>{if(!(!n||g)&&!(t===`drop`&&!window.confirm(s(`gitView.stashes.confirm.drop`,{ref:e.ref})))){_(`${t}:${e.ref}`);try{t===`apply`&&await Ar(n,{ref:e.ref}),t===`pop`&&await yr(n,{ref:e.ref}),t===`drop`&&await xr(n,{ref:e.ref});let r=t===`apply`?`gitView.stashes.toast.applySuccess`:t===`pop`?`gitView.stashes.toast.popSuccess`:`gitView.stashes.toast.dropSuccess`;X.success(s(r)),await S({affectsIndex:t!==`drop`})}catch(e){let n=t===`apply`?`gitView.stashes.toast.applyFailed`:t===`pop`?`gitView.stashes.toast.popFailed`:`gitView.stashes.toast.dropFailed`;X.error(e instanceof Error?e.message:s(n)),await S({affectsIndex:t!==`drop`})}finally{_(null)}}},T=g!==null;return(0,$.jsx)(pr,{open:e,onOpenChange:t,children:(0,$.jsxs)(ur,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(cr,{children:[(0,$.jsxs)(dr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`h-5 w-5`}),s(`gitView.stashes.title`)]}),(0,$.jsx)(fr,{children:s(`gitView.stashes.description`)})]}),(0,$.jsxs)(`div`,{className:`mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(sa,{value:m,onChange:e=>h(e.target.value),placeholder:s(`gitView.stashes.messagePlaceholder`),disabled:T||!r,className:`flex-1`}),(0,$.jsxs)(Y,{onClick:C,disabled:!r||T||!n,children:[g===`create`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`inbox-archive`,className:`size-4`}),s(`gitView.stashes.actions.stashCurrentWithCount`,{count:a})]})]}),(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:s(`gitView.stashes.includeUntrackedHint`)})]}),(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(Z,{name:`search`,className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(sa,{value:f,onChange:e=>p(e.target.value),placeholder:s(`gitView.stashes.searchPlaceholder`),className:`pl-9`})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:u?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-10 text-muted-foreground`,children:(0,$.jsx)(Z,{name:`loader-4`,className:`size-5 animate-spin`})}):x.length===0?(0,$.jsx)(`div`,{className:`py-8 text-center text-muted-foreground`,children:s(f?`gitView.stashes.empty.search`:`gitView.stashes.empty.list`)}):x.map((e,t)=>(0,$.jsxs)(`div`,{className:`group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 pl-2`,children:[(0,$.jsx)(`p`,{className:`typography-small truncate text-foreground`,children:e.message||s(`gitView.stashes.untitled`)}),(0,$.jsxs)(`p`,{className:`typography-meta truncate text-muted-foreground`,children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{children:t===0&&!f.trim()?s(`gitView.stashes.latestLabel`):s(`gitView.stashes.itemNumber`,{number:t+1})})}),(0,$.jsx)(la,{sideOffset:6,children:e.ref})]}),` · `,e.relativeTime,` · `,typeof v[e.ref]==`number`?s(`gitView.stashes.fileCount`,{count:v[e.ref]}):s(`gitView.stashes.fileCountLoading`)]})]}),(0,$.jsxs)(`div`,{className:`mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100`,children:[(0,$.jsx)(md,{label:s(`gitView.stashes.actions.apply`),loading:g===`apply:${e.ref}`,onClick:()=>w(e,`apply`),disabled:T,children:(0,$.jsx)(Z,{name:`inbox-unarchive`,className:`size-4`})}),(0,$.jsx)(md,{label:s(`gitView.stashes.actions.pop`),loading:g===`pop:${e.ref}`,onClick:()=>w(e,`pop`),disabled:T,children:(0,$.jsx)(Z,{name:`inbox-unarchive-fill`,className:`size-4`})}),(0,$.jsx)(md,{label:s(`gitView.stashes.actions.drop`),loading:g===`drop:${e.ref}`,onClick:()=>w(e,`drop`),disabled:T,destructive:!0,children:(0,$.jsx)(Z,{name:`delete-bin`,className:`size-4`})})]})]},e.ref))})]})})},md=e=>{let t=(0,fl.c)(17),{label:n,loading:r,disabled:i,destructive:a,onClick:o,children:s}=e,c=r||void 0,l=a?`text-[var(--status-error)] hover:text-[var(--status-error)]`:`text-muted-foreground hover:text-foreground`,u;t[0]===l?u=t[1]:(u=J(`flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50`,l),t[0]=l,t[1]=u);let d;t[2]!==s||t[3]!==r?(d=r?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):s,t[2]=s,t[3]=r,t[4]=d):d=t[4];let f;t[5]!==i||t[6]!==n||t[7]!==o||t[8]!==c||t[9]!==u||t[10]!==d?(f=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":n,"aria-busy":c,className:u,onClick:o,disabled:i,children:d})}),t[5]=i,t[6]=n,t[7]=o,t[8]=c,t[9]=u,t[10]=d,t[11]=f):f=t[11];let p;t[12]===n?p=t[13]:(p=(0,$.jsx)(la,{sideOffset:6,children:n}),t[12]=n,t[13]=p);let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(da,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m},hd=e=>{let t=(0,fl.c)(16),{onOpenStashes:n}=e,{t:r}=wt(),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Z,{name:`git-commit`,className:`size-10 text-muted-foreground/70 mb-4`}),t[0]=i):i=t[0];let a;t[1]===r?a=t[2]:(a=r(`gitView.empty.cleanTitle`),t[1]=r,t[2]=a);let o;t[3]===a?o=t[4]:(o=(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground mb-1`,children:a}),t[3]=a,t[4]=o);let s;t[5]===r?s=t[6]:(s=r(`gitView.empty.cleanDescription`),t[5]=r,t[6]=s);let c;t[7]===s?c=t[8]:(c=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground mb-4`,children:s}),t[7]=s,t[8]=c);let l;t[9]!==n||t[10]!==r?(l=n?(0,$.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,onClick:n,className:`gap-1.5`,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`size-4`}),r(`gitView.stashes.title`)]}):null,t[9]=n,t[10]=r,t[11]=l):l=t[11];let u;return t[12]!==o||t[13]!==c||t[14]!==l?(u=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-10 px-4 text-center`,children:[i,o,c,l]}),t[12]=o,t[13]=c,t[14]=l,t[15]=u):u=t[15],u},gd=8,_d=e=>{let t=(0,fl.c)(18),{laned:n,totalLanes:r,isExpanded:i}=e,{lane:a,color:o,connectors:s}=n,c=Math.max(r,a+1)*gd+gd/2,l=Q.useRef(null),u=Q.useRef(null),d;t[0]!==o||t[1]!==s||t[2]!==a||t[3]!==c?(d=()=>{let e=l.current,t=u.current;if(!e||!t)return;let n=e.offsetHeight;if(n===0)return;let r=window.devicePixelRatio||1;t.width=c*r,t.height=n*r;let i=t.getContext(`2d`);if(!i)return;i.scale(r,r),i.clearRect(0,0,c,n);let d=n/2,f=a*gd+gd/2,p=getComputedStyle(t),m=p.getPropertyValue(`--surface-muted-foreground`).trim()||p.color,h=e=>{if(!e.startsWith(`var(`))return e;let t=e.slice(4,-1).trim();return p.getPropertyValue(t).trim()||m},g=[...s].sort(yd);for(let e of g){let t=e.fromLane*gd+gd/2,r=e.toLane*gd+gd/2,a=e.type===`passing`?.72:e.type===`branch-out`||e.type===`merge-in`?.95:1;i.beginPath(),i.strokeStyle=h(e.color),i.globalAlpha=a,i.lineWidth=1.25,i.lineCap=`round`;bb64:switch(e.type){case`passing`:case`commit-lane`:i.moveTo(t,0),i.lineTo(t,n);break bb64;case`top-stub`:i.moveTo(t,0),i.lineTo(t,d);break bb64;case`bottom-stub`:i.moveTo(t,d),i.lineTo(t,n);break bb64;case`branch-out`:{let e=(d+n)/2;i.moveTo(f,d),i.bezierCurveTo(f,e,r,e,r,n);break bb64}case`merge-in`:{let e=d/2;i.moveTo(t,0),i.bezierCurveTo(t,e,f,e,f,d);break bb64}default:continue}i.stroke(),i.globalAlpha=1}let _=p.getPropertyValue(`--background`).trim()||p.getPropertyValue(`--surface-background`).trim();i.beginPath(),i.arc(f,d,4,0,Math.PI*2),i.fillStyle=h(o),i.fill(),i.beginPath(),i.arc(f,d,5,0,Math.PI*2),i.strokeStyle=_||m,i.lineWidth=2,i.stroke()},t[0]=o,t[1]=s,t[2]=a,t[3]=c,t[4]=d):d=t[4];let f;t[5]!==o||t[6]!==s||t[7]!==i||t[8]!==a||t[9]!==n||t[10]!==r||t[11]!==c?(f=[n,a,o,s,r,i,c],t[5]=o,t[6]=s,t[7]=i,t[8]=a,t[9]=n,t[10]=r,t[11]=c,t[12]=f):f=t[12],Q.useLayoutEffect(d,f);let p;t[13]===c?p=t[14]:(p={width:c,height:`100%`,position:`relative`,flexShrink:0,overflow:`hidden`},t[13]=c,t[14]=p);let m;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`canvas`,{ref:u,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,display:`block`}}),t[15]=m):m=t[15];let h;return t[16]===p?h=t[17]:(h=(0,$.jsx)(`div`,{ref:l,style:p,children:m}),t[16]=p,t[17]=h),h};function vd(e){return e===`branch-out`||e===`merge-in`}function yd(e,t){let n=vd;return!!n(e.type)-+!!n(t.type)}var bd=15e3,xd=500,Sd=12,Cd=8388608,wd=e=>typeof e==`string`?0:(e.original?.length??0)+(e.modified?.length??0),Td=e=>{if(e.size<=Sd){let t=0;for(let n of e.values())t+=wd(n);if(t<=Cd)return e}let t=Array.from(e.entries()).reverse(),n=new Map,r=0;for(let[e,i]of t){if(n.size>=Sd)continue;let t=wd(i);r+t>Cd&&n.size>0||(n.set(e,i),r+=t)}return new Map(Array.from(n.entries()).reverse())};function Ed(e,t){let n=new Date(e);return Number.isNaN(n.getTime())?e:ga(n,t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function Dd(e){switch(e){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 Od(e){return e?e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.startsWith(`HEAD ->`);return{label:t?e.replace(`HEAD -> `,``):e.replace(`tag: `,``),isHead:t,isTag:e.startsWith(`tag: `)}}):[]}var kd=Q.memo(({entry:e,mode:t=`history`,laned:n,totalLanes:r,isExpanded:i,onToggle:a,files:o,isLoadingFiles:s,onCopyHash:c,directory:l,onConflict:u,onActionSuccess:d})=>{let{t:f}=wt(),p=q(e=>e.timeFormatPreference),m=t===`graph`,[h,g]=Q.useState(null),[_,v]=Q.useState(!1),[y,b]=Q.useState(``),[x,S]=Q.useState(null),[C,w]=Q.useState(new Set),[T,E]=Q.useState(new Map),[D,O]=Q.useState(new Set),k=async()=>{if(l){g(`checkout`);try{await kr(l,e.hash),X.success(f(`gitView.history.actions.detachedHead`)),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},A=async()=>{if(!(!l||!y.trim())){g(`createBranch`);try{await Dr(l,y.trim(),e.hash),v(!1),b(``),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},j=async()=>{if(l){g(`cherryPick`);try{let t=await Cr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`cherry-pick`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},M=async()=>{if(l){g(`revert`);try{let t=await wr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`revert`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},N=async(t,n=!1)=>{if(!(!l||h!==null)){g(`reset`);try{await _r(l,e.hash,t,n),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},P=async()=>{if(!x)return;let e=x;switch(S(null),e){case`checkout`:return k();case`cherryPick`:return j();case`revert`:return M();case`merge`:return F();case`rebase`:return I();case`resetSoft`:return N(`soft`);case`resetMixed`:return N(`mixed`);case`resetHard`:return N(`hard`,!0)}},F=async()=>{if(l){g(`merge`);try{let t=await jr(l,{branch:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`merge`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},I=async()=>{if(l){g(`rebase`);try{let t=await gr(l,{onto:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`rebase`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},L=Q.useCallback(async t=>{let n=t.path;if(!l){E(e=>new Map(e).set(n,`error`));return}E(e=>Td(new Map(e).set(n,`loading`)));try{let r=Er(l,e.hash,t.path,!1),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${bd}ms`)),bd)}),a=await Promise.race([r,i]);E(e=>Td(new Map(e).set(n,a)))}catch{E(e=>new Map(e).set(n,`error`))}},[l,e.hash]),R=Q.useCallback(async e=>{let t=e.path;if(e.changeType===`R`||e.isBinary){w(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n});return}let n=T.get(t);if(C.has(t)&&n&&n!==`error`){w(e=>{let n=new Set(e);return n.delete(t),n});return}w(e=>{let n=new Set(e);return n.add(t),n}),!(n&&n!==`error`)&&(e.insertions+e.deletions>xd&&!D.has(t)||await L(e))},[T,D,L,C]);return(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:J(`w-full flex items-start gap-3 px-3 py-2 text-left transition-colors`,m?`hover:bg-[var(--interactive-hover)]/40`:i?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[m&&n&&r!==void 0?(0,$.jsx)(`div`,{className:`-my-2 shrink-0 self-stretch`,children:(0,$.jsx)(_d,{laned:n,totalLanes:r,isExpanded:i})}):(0,$.jsx)(`div`,{className:`h-2 w-2 translate-y-2 rounded-full shrink-0`,style:{backgroundColor:`var(--status-success)`},"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[m?(()=>{let t=Od(e.refs);return t.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-0.5`,children:t.map(e=>(0,$.jsx)(`span`,{className:J(`inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium`,e.isHead?`bg-[var(--chart-1)] text-[var(--primary-foreground)]`:e.isTag?`bg-[var(--chart-5)] text-[var(--primary-foreground)]`:`bg-[var(--interactive-hover)] text-[var(--foreground)]`),children:e.label},e.label))}):null})():null,(0,$.jsx)(`p`,{className:`typography-ui-label font-medium text-foreground line-clamp-1`,children:e.message}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 typography-meta text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 truncate`,children:[(0,$.jsx)(`span`,{className:`truncate min-w-[3ch]`,title:e.author_name,children:e.author_name}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`span`,{className:`truncate min-w-0`,title:Ed(e.date,p),children:Ed(e.date,p)})]}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`code`,{className:`shrink-0 font-mono`,children:e.hash.slice(0,8)}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-5 px-1 shrink-0`,onClick:t=>{t.stopPropagation(),c(e.hash)},children:(0,$.jsx)(Z,{name:`file-copy`,className:`size-3`})})}),(0,$.jsx)(la,{sideOffset:8,children:f(`gitView.history.copySha`)})]})]})]})]}),i&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 pl-8 border-t border-border/40`,children:[m&&x?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2 border-b border-border/30 mb-2`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground flex-1 min-w-0`,children:f(`gitView.history.actions.${x}Confirm`)}),(0,$.jsxs)(Y,{variant:`destructive`,size:`xs`,className:`h-6 shrink-0`,disabled:h!==null,onClick:e=>{e.stopPropagation(),P()},children:[h===null?null:(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}),f(`gitView.history.actions.confirmButton`)]}),(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:`h-6 shrink-0`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(null)},children:f(`gitView.history.actions.cancelButton`)})]}):m?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2`,children:[(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`checkout`)},children:f(`gitView.history.actions.checkout`)}),_?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A(),e.key===`Escape`&&(v(!1),b(``))},placeholder:f(`gitView.history.actions.createBranchPlaceholder`),className:`h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32`}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:!y.trim()||h!==null,onClick:e=>{e.stopPropagation(),A()},children:[h===`createBranch`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.createBranchConfirm`)]})]}):(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,onClick:e=>{e.stopPropagation(),v(!0)},children:f(`gitView.history.actions.createBranch`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`cherryPick`)},children:f(`gitView.history.actions.cherryPick`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`revert`)},children:f(`gitView.history.actions.revert`)}),(0,$.jsxs)(Ua,{children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>e.stopPropagation(),children:[h===`reset`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.reset`)]})}),(0,$.jsx)(Pa,{align:`start`,className:`min-w-max`,children:[`soft`,`mixed`,`hard`].map(e=>(0,$.jsx)(Da,{disabled:h!==null,onSelect:t=>{t.stopPropagation(),S(`reset${e.charAt(0).toUpperCase()+e.slice(1)}`)},children:f(`gitView.history.actions.reset${e.charAt(0).toUpperCase()+e.slice(1)}`)},e))})]}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`merge`)},children:f(`gitView.history.actions.merge`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`rebase`)},children:f(`gitView.history.actions.rebase`)})]}):null,s?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:f(`gitView.history.loadingFiles`)})]}):o.length===0?(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground py-2`,children:f(`gitView.history.noFiles`)}):(0,$.jsx)(`ul`,{className:`space-y-0.5 py-2`,children:o.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>R(e),className:J(`w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1`,C.has(e.path)?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[(0,$.jsx)(`span`,{className:J(`font-semibold w-3 text-center shrink-0`,Dd(e.changeType)),children:e.changeType}),(0,$.jsx)(`span`,{className:`truncate text-foreground min-w-0`,title:e.path,children:e.path}),!e.isBinary&&(0,$.jsxs)(`span`,{className:`shrink-0`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.insertions]}),(0,$.jsx)(`span`,{className:`text-muted-foreground mx-0.5`,children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.deletions]})]}),e.isBinary&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:f(`gitView.history.binary`)}),(0,$.jsx)(Z,{name:C.has(e.path)?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),C.has(e.path)&&(0,$.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:e.changeType===`R`?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.renamedNoDiff`)}):e.isBinary?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.binaryNoDiff`)}):(()=>{let t=e.insertions+e.deletions;if(!D.has(e.path)&&t>xd)return(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:f(`gitView.history.largeDiffTitle`,{count:t})}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:f(`gitView.history.largeDiffDescription`)}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`xs`,className:`h-6 px-0 text-primary hover:bg-transparent hover:underline`,onClick:()=>{O(t=>new Set(t).add(e.path)),L(e)},children:f(`gitView.history.renderDiffAnyway`)})]});let n=T.get(e.path);return n===`loading`||n===void 0?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.loadingDiff`)}):n===`error`?(0,$.jsx)(`button`,{type:`button`,onClick:()=>R(e),className:`w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors`,children:f(`gitView.history.diffError`)}):(0,$.jsx)(dc,{original:n.original,modified:n.modified,language:Yo(e.path)||``,fileName:e.path,renderSideBySide:!1,layout:`inline`,enableComments:!1})})()})]},e.path))})]})]})}),Ad=[`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 jd(e){return Ad[e%Ad.length]}function Md(e){if(e.length===0)return[];let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r],a=[];for(let e=0;e<t.length;e++)t[e]===i.hash&&a.push(e);let o=a.length>0?a[0]:-1;if(o===-1){let e=t.indexOf(null);e===-1?(o=t.length,t.push(null)):o=e}let s=a.slice(1),c=jd(o),l=t[o]===i.hash,u=i.parents.length>0;u?t[o]=i.parents[0]:t[o]=null;let d=[];for(let e=1;e<i.parents.length;e++){let n=i.parents[e],r=t.indexOf(n);if(r!==-1)d.push(r);else{let e=t.indexOf(null),r=e===-1?t.length:e;t[r]=n,r===t.length&&t.push(n),d.push(r)}}let f=[];l&&u?f.push({fromLane:o,toLane:o,color:c,type:`commit-lane`}):l&&!u?f.push({fromLane:o,toLane:o,color:c,type:`top-stub`}):!l&&u&&f.push({fromLane:o,toLane:o,color:c,type:`bottom-stub`});for(let e of s)f.push({fromLane:e,toLane:o,color:jd(e),type:`merge-in`}),t[e]=null;for(let e of d)f.push({fromLane:o,toLane:e,color:jd(e),type:`branch-out`});for(let e=0;e<t.length;e++)t[e]!==null&&e!==o&&(d.includes(e)||f.push({fromLane:e,toLane:e,color:jd(e),type:`passing`}));n.push({commit:i,lane:o,color:c,connectors:f})}return n}var Nd=[{labelKey:`gitView.history.logSize25`,value:25},{labelKey:`gitView.history.logSize50`,value:50},{labelKey:`gitView.history.logSize100`,value:100}],Pd=e=>{let t=(0,fl.c)(84),{mode:n,log:r,isLogLoading:i,logMaxCount:a,onLogMaxCountChange:o,expandedCommitHashes:s,onToggleCommit:c,commitFilesMap:l,loadingCommitHashes:u,onCopyHash:d,directory:f,showHeader:p,contentMaxHeightClassName:m,branchDivider:h,onConflict:g,onActionSuccess:_}=e,v=n===void 0?`history`:n,y=p===void 0||p,b=m===void 0?`max-h-[50vh]`:m,x=h===void 0?null:h,{t:S}=wt(),[C,w]=Q.useState(!0),T=v===`graph`,E;t[0]!==T||t[1]!==r?(E=T&&r?Md(r.all):[],t[0]=T,t[1]=r,t[2]=E):E=t[2];let D=E,O;t[3]===D?O=t[4]:(O=Math.max(1,...D.map(Fd)),t[3]=D,t[4]=O);let k=O,A;t[5]===D?A=t[6]:(A=new Map(D.map(Id)),t[5]=D,t[6]=A);let j=A;if(!r)return null;let M=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<r.all.length,N=x!==null&&x.insertBeforeIndex===r.all.length,P=M||N,F;t[7]!==x||t[8]!==M||t[9]!==N||t[10]!==r.all?(F=M?r.all.slice(0,x.insertBeforeIndex):N?r.all:[],t[7]=x,t[8]=M,t[9]=N,t[10]=r.all,t[11]=F):F=t[11];let I=F,L;if(t[12]!==x||t[13]!==l||t[14]!==b||t[15]!==f||t[16]!==s||t[17]!==M||t[18]!==P||t[19]!==T||t[20]!==i||t[21]!==j||t[22]!==u||t[23]!==r.all||t[24]!==a||t[25]!==k||t[26]!==v||t[27]!==_||t[28]!==g||t[29]!==d||t[30]!==o||t[31]!==c||t[32]!==S||t[33]!==I){let e=M?r.all.slice(x.insertBeforeIndex):[],n;t[35]===x?.direction?n=t[36]:(n=x?.direction===`down`?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-3.5`}):(0,$.jsx)(Z,{name:`arrow-up`,className:`size-3.5`}),t[35]=x?.direction,t[36]=n);let p=n,m;t[37]!==l||t[38]!==f||t[39]!==s||t[40]!==T||t[41]!==j||t[42]!==u||t[43]!==k||t[44]!==v||t[45]!==_||t[46]!==g||t[47]!==d||t[48]!==c?(m=e=>(0,$.jsx)(`ul`,{className:`divide-y divide-border/60`,children:e.map(e=>(0,$.jsx)(kd,{entry:e,mode:v,laned:T?j.get(e.hash):void 0,totalLanes:T?k:void 0,isExpanded:s.has(e.hash),onToggle:()=>c(e.hash),files:l.get(e.hash)??[],isLoadingFiles:u.has(e.hash),onCopyHash:d,directory:f,onConflict:g,onActionSuccess:_},e.hash))}),t[37]=l,t[38]=f,t[39]=s,t[40]=T,t[41]=j,t[42]=u,t[43]=k,t[44]=v,t[45]=_,t[46]=g,t[47]=d,t[48]=c,t[49]=m):m=t[49];let h=m,y;t[50]!==i||t[51]!==r.all.length||t[52]!==a||t[53]!==o||t[54]!==S?(y=r.all.length>=a?(0,$.jsx)(`div`,{className:`flex justify-center py-2 border-t border-border/40`,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>o(a+25),disabled:i,className:`px-3 text-muted-foreground hover:text-foreground`,children:i?(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin`}),S(`gitView.history.loadingMore`)]}):S(`gitView.history.loadMore`)})}):null,t[50]=i,t[51]=r.all.length,t[52]=a,t[53]=o,t[54]=S,t[55]=y):y=t[55];let C=y;L=(0,$.jsx)(fo,{outerClassName:`min-h-0 ${b}`,className:`h-full w-full`,children:r.all.length===0?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:S(`gitView.history.noCommits`)})}):P&&x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0`,children:[I.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(I)}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsxs)(`span`,{className:`inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate`,title:x.branchName,children:x.branchName}),p]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`})]}),e.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(e)}):null]}),C]}):(0,$.jsxs)($.Fragment,{children:[h(r.all),C]})}),t[12]=x,t[13]=l,t[14]=b,t[15]=f,t[16]=s,t[17]=M,t[18]=P,t[19]=T,t[20]=i,t[21]=j,t[22]=u,t[23]=r.all,t[24]=a,t[25]=k,t[26]=v,t[27]=_,t[28]=g,t[29]=d,t[30]=o,t[31]=c,t[32]=S,t[33]=I,t[34]=L}else L=t[34];let R=L;if(!y){if(P){let e;return t[56]===R?e=t[57]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0`,children:R}),t[56]=R,t[57]=e),e}let e;return t[58]===R?e=t[59]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:R}),t[58]=R,t[59]=e),e}let z;t[60]===S?z=t[61]:(z=S(`gitView.history.title`),t[60]=S,t[61]=z);let B;t[62]===z?B=t[63]:(B=(0,$.jsx)(`h3`,{className:`typography-ui-header font-semibold text-foreground`,children:z}),t[62]=z,t[63]=B);let V;t[64]!==i||t[65]!==C||t[66]!==a||t[67]!==o||t[68]!==S?(V=C&&(0,$.jsx)(`div`,{onClick:Ld,onPointerDown:Rd,children:(0,$.jsxs)(na,{value:String(a),onValueChange:e=>o(Number(e)),disabled:i,children:[(0,$.jsx)(Zi,{size:`sm`,className:`data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0`,disabled:i,children:(0,$.jsx)(oa,{placeholder:S(`gitView.history.commitsPlaceholder`)})}),(0,$.jsx)($i,{children:Nd.map(e=>(0,$.jsx)(Yi,{value:String(e.value),children:S(e.labelKey)},e.value))})]})}),t[64]=i,t[65]=C,t[66]=a,t[67]=o,t[68]=S,t[69]=V):V=t[69];let ee;t[70]===C?ee=t[71]:(ee=C?(0,$.jsx)(Z,{name:`arrow-up-s`,className:`size-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-4 text-muted-foreground`}),t[70]=C,t[71]=ee);let H;t[72]!==V||t[73]!==ee?(H=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V,ee]}),t[72]=V,t[73]=ee,t[74]=H):H=t[74];let te;t[75]!==B||t[76]!==H?(te=(0,$.jsxs)(Jc,{className:`flex w-full items-center justify-between px-3 h-10 hover:bg-transparent`,children:[B,H]}),t[75]=B,t[76]=H,t[77]=te):te=t[77];let ne;t[78]===R?ne=t[79]:(ne=(0,$.jsx)(qc,{children:R}),t[78]=R,t[79]=ne);let re;return t[80]!==C||t[81]!==te||t[82]!==ne?(re=(0,$.jsxs)(Yc,{open:C,onOpenChange:w,className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[te,ne]}),t[80]=C,t[81]=te,t[82]=ne,t[83]=re):re=t[83],re};function Fd(e){return e.lane+1}function Id(e){return[e.commit.hash,e]}function Ld(e){return e.stopPropagation()}function Rd(e){return e.stopPropagation()}var zd=e=>{let t=(0,fl.c)(150),{open:n,onOpenChange:r,conflictFiles:i,directory:a,operation:o,onAbort:s,onClearState:c}=e,l;t[0]===i?l=t[1]:(l=i===void 0?[]:i,t[0]=i,t[1]=l);let u=l,{t:d}=wt(),f=xn(Bd),p=xn(Vd),m=bn(Hd),h=bn(Ud),g=q(Wd),[_,v]=Q.useState(!1),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C,w;t[2]!==a||t[3]!==n||t[4]!==d?(C=()=>{!n||!a||(v(!0),S(null),b(null),Sr(a).then(e=>{b(e)}).catch(e=>{let t=e instanceof Error?e.message:d(`gitView.conflict.loadFailed`);S(t)}).finally(()=>{v(!1)}))},w=[n,a,d],t[2]=a,t[3]=n,t[4]=d,t[5]=C,t[6]=w):(C=t[5],w=t[6]),Q.useEffect(C,w);let T;t[7]!==y||t[8]!==a||t[9]!==o?(T=async()=>{if(!y)return null;let e=o===`merge`?`merge`:`rebase`,t=y.headInfo||(o===`merge`?`MERGE_HEAD`:`REBASE_HEAD`),n=o===`merge`?`git commit --no-edit`:`git rebase --continue`;return{visibleText:await jn(`git.conflict.resolve.visible`,{operation_label:e,head_ref:t}),instructionsText:await jn(`git.conflict.resolve.instructions`,{operation_label:e,directory:a,operation:o,head_info:y.headInfo||`N/A`,continue_cmd:n}),payloadText:`${e} conflict context (JSON)\n${JSON.stringify({directory:a,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`}},t[7]=y,t[8]=a,t[9]=o,t[10]=T):T=t[10];let E=T,D;t[11]!==s||t[12]!==r?(D=()=>{s(),r(!1)},t[11]=s,t[12]=r,t[13]=D):D=t[13];let O=D,k;t[14]!==c||t[15]!==r?(k=()=>{c?.(),r(!1)},t[14]=c,t[15]=r,t[16]=k):k=t[16];let A=k,j;t[17]!==E||t[18]!==p||t[19]!==c||t[20]!==r||t[21]!==g||t[22]!==m||t[23]!==h||t[24]!==d?(j=async()=>{let e=await E();if(!e){X.error(d(`gitView.conflict.noDetailsAvailable`));return}if(!p){X.error(d(`gitView.conflict.noActiveSession`),{description:d(`gitView.conflict.noActiveSessionDescription`)});return}m(e.visibleText,`replace`),h([{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]),g(`chat`),c?.(),r(!1)},t[17]=E,t[18]=p,t[19]=c,t[20]=r,t[21]=g,t[22]=m,t[23]=h,t[24]=d,t[25]=j):j=t[25];let M=j,N;t[26]!==E||t[27]!==a||t[28]!==c||t[29]!==r||t[30]!==f||t[31]!==g||t[32]!==d?(N=async()=>{let e=await E();if(!e){X.error(d(`gitView.conflict.noDetailsAvailable`));return}f({directoryOverride:a,initialPrompt:e.visibleText,syntheticParts:[{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]}),g(`chat`),c?.(),r(!1)},t[26]=E,t[27]=a,t[28]=c,t[29]=r,t[30]=f,t[31]=g,t[32]=d,t[33]=N):N=t[33];let P=N,F,I,L,R,z,B,V,ee,H,te,ne,re,U,ie,ae,W,oe,se,ce,G,le,ue;if(t[34]!==y||t[35]!==u||t[36]!==p||t[37]!==O||t[38]!==A||t[39]!==M||t[40]!==P||t[41]!==_||t[42]!==x||t[43]!==r||t[44]!==n||t[45]!==o||t[46]!==d){let e=d(o===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),i=y?.unmergedFiles||u;L=pr,le=n,ue=r,I=ur,G=`max-w-md w-[calc(100vw-2rem)]`,ie=`flex flex-col gap-4 overflow-hidden`;let a;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Z,{name:`alert`,className:`size-5 shrink-0 text-[var(--status-warning)]`}),t[69]=a):a=t[69];let s=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a,(0,$.jsx)(dr,{children:d(`gitView.conflict.detectedTitle`,{operation:e})})]}),c;t[70]!==o||t[71]!==d?(c=d(`gitView.conflict.detectedDescription`,{operation:o}),t[70]=o,t[71]=d,t[72]=c):c=t[72];let l;t[73]===c?l=t[74]:(l=(0,$.jsx)(fr,{children:c}),t[73]=c,t[74]=l),t[75]!==s||t[76]!==l?(ae=(0,$.jsxs)(cr,{children:[s,l]}),t[75]=s,t[76]=l,t[77]=ae):ae=t[77],t[78]!==_||t[79]!==d?(W=_&&(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-4 text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:d(`gitView.conflict.loading`)})]}),t[78]=_,t[79]=d,t[80]=W):W=t[80],t[81]!==x||t[82]!==d?(oe=x&&(0,$.jsx)(`div`,{className:`rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words`,children:d(`gitView.conflict.errorLoadingDetails`,{message:x})}),t[81]=x,t[82]=d,t[83]=oe):oe=t[83],t[84]!==i||t[85]!==d?(se=i.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:d(`gitView.conflict.conflictedFiles`)}),(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground`,children:i.length})]}),(0,$.jsx)(`div`,{className:`bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden`,children:(0,$.jsx)(`ul`,{className:`space-y-1`,children:i.map(Gd)})})]}),t[84]=i,t[85]=d,t[86]=se):se=t[86],t[87]!==y||t[88]!==d?(ce=y?.headInfo&&(0,$.jsxs)(`div`,{className:`space-y-1 overflow-hidden`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:d(`gitView.conflict.headInfo`)}),(0,$.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:y.headInfo})]}),t[87]=y,t[88]=d,t[89]=ce):ce=t[89],ne=`flex flex-col gap-2 pt-2`;let f;t[90]===P?f=t[91]:(f=()=>{P()},t[90]=P,t[91]=f);let m=_||!y,h;t[92]===_?h=t[93]:(h=_?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`add`,className:`size-4`}),t[92]=_,t[93]=h);let g;t[94]===d?g=t[95]:(g=d(`gitView.conflict.resolveNewSession`),t[94]=d,t[95]=g),t[96]!==f||t[97]!==m||t[98]!==h||t[99]!==g?(re=(0,$.jsxs)(Y,{variant:`default`,onClick:f,disabled:m,className:`w-full gap-2`,children:[h,g]}),t[96]=f,t[97]=m,t[98]=h,t[99]=g,t[100]=re):re=t[100];let v;t[101]===M?v=t[102]:(v=()=>void M(),t[101]=M,t[102]=v);let b=_||!y||!p,S;t[103]===_?S=t[104]:(S=_?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`chat-1`,className:`size-4`}),t[103]=_,t[104]=S);let C;t[105]===d?C=t[106]:(C=d(`gitView.conflict.resolveCurrentSession`),t[105]=d,t[106]=C),t[107]!==v||t[108]!==b||t[109]!==S||t[110]!==C?(U=(0,$.jsxs)(Y,{variant:`outline`,onClick:v,disabled:b,className:`w-full gap-2`,children:[S,C]}),t[107]=v,t[108]=b,t[109]=S,t[110]=C,t[111]=U):U=t[111],H=`flex gap-2 pt-1`;let w;t[112]===d?w=t[113]:(w=d(`gitView.conflict.continueLater`),t[112]=d,t[113]=w),t[114]!==A||t[115]!==w?(te=(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:A,className:`flex-1`,children:w}),t[114]=A,t[115]=w,t[116]=te):te=t[116],F=Y,R=`destructive`,z=`sm`,B=O,V=`flex-1`,ee=d(`gitView.conflict.abortOperation`,{operation:e}),t[34]=y,t[35]=u,t[36]=p,t[37]=O,t[38]=A,t[39]=M,t[40]=P,t[41]=_,t[42]=x,t[43]=r,t[44]=n,t[45]=o,t[46]=d,t[47]=F,t[48]=I,t[49]=L,t[50]=R,t[51]=z,t[52]=B,t[53]=V,t[54]=ee,t[55]=H,t[56]=te,t[57]=ne,t[58]=re,t[59]=U,t[60]=ie,t[61]=ae,t[62]=W,t[63]=oe,t[64]=se,t[65]=ce,t[66]=G,t[67]=le,t[68]=ue}else F=t[47],I=t[48],L=t[49],R=t[50],z=t[51],B=t[52],V=t[53],ee=t[54],H=t[55],te=t[56],ne=t[57],re=t[58],U=t[59],ie=t[60],ae=t[61],W=t[62],oe=t[63],se=t[64],ce=t[65],G=t[66],le=t[67],ue=t[68];let de;t[117]!==F||t[118]!==R||t[119]!==z||t[120]!==B||t[121]!==V||t[122]!==ee?(de=(0,$.jsx)(F,{variant:R,size:z,onClick:B,className:V,children:ee}),t[117]=F,t[118]=R,t[119]=z,t[120]=B,t[121]=V,t[122]=ee,t[123]=de):de=t[123];let fe;t[124]!==H||t[125]!==te||t[126]!==de?(fe=(0,$.jsxs)(`div`,{className:H,children:[te,de]}),t[124]=H,t[125]=te,t[126]=de,t[127]=fe):fe=t[127];let pe;t[128]!==ne||t[129]!==re||t[130]!==U||t[131]!==fe?(pe=(0,$.jsxs)(`div`,{className:ne,children:[re,U,fe]}),t[128]=ne,t[129]=re,t[130]=U,t[131]=fe,t[132]=pe):pe=t[132];let me;t[133]!==ie||t[134]!==ae||t[135]!==W||t[136]!==oe||t[137]!==se||t[138]!==ce||t[139]!==pe?(me=(0,$.jsxs)(`div`,{className:ie,children:[ae,W,oe,se,ce,pe]}),t[133]=ie,t[134]=ae,t[135]=W,t[136]=oe,t[137]=se,t[138]=ce,t[139]=pe,t[140]=me):me=t[140];let he;t[141]!==I||t[142]!==G||t[143]!==me?(he=(0,$.jsx)(I,{className:G,children:me}),t[141]=I,t[142]=G,t[143]=me,t[144]=he):he=t[144];let ge;return t[145]!==L||t[146]!==le||t[147]!==ue||t[148]!==he?(ge=(0,$.jsx)(L,{open:le,onOpenChange:ue,children:he}),t[145]=L,t[146]=le,t[147]=ue,t[148]=he,t[149]=ge):ge=t[149],ge};function Bd(e){return e.openNewSessionDraft}function Vd(e){return e.currentSessionId}function Hd(e){return e.setPendingInputText}function Ud(e){return e.setPendingSyntheticParts}function Wd(e){return e.setActiveMainTab}function Gd(e){return(0,$.jsx)(`li`,{className:`typography-micro text-foreground font-mono truncate block`,title:e,children:e},e)}var Kd=({mergeInProgress:e,rebaseInProgress:t,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{let{t:s}=wt(),[c,l]=Q.useState(null),u=e&&e.head,d=t&&(t.headName||t.onto),f=u?`merge`:d?`rebase`:null;if(!f)return null;let p=async()=>{l(`continue`);try{await n()}finally{l(null)}},m=async()=>{l(`abort`);try{await r()}finally{l(null)}},h=c!==null,g=s(f===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),_=f===`merge`?`git-merge`:`git-branch`,v=``;return e?v=e.message?s(`gitView.operation.mergingMessage`,{message:e.message}):s(`gitView.operation.mergeInProgressWithHead`,{head:e.head}):t&&(v=t.headName?s(`gitView.operation.rebasingOnto`,{headName:t.headName,onto:t.onto||``}):s(`gitView.operation.rebaseInProgress`)),(0,$.jsx)(`div`,{className:`bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsx)(Z,{name:_,className:`size-4 text-[var(--status-warning)] shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`typography-label text-[var(--status-warning)]`,children:s(`gitView.operation.inProgressTitle`,{operation:g})}),v&&(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground truncate`,children:v})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a&&i&&(0,$.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:i,disabled:h||o,className:`gap-1.5`,children:[(0,$.jsx)(Z,{name:`sparkling`,className:`size-4`}),s(`gitView.operation.resolveWithAi`)]}),c!==`continue`&&(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:m,disabled:h||o,className:`gap-1.5`,children:[c===`abort`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`close`,className:`size-4`}),s(`gitView.operation.abort`)]}),!a&&(0,$.jsxs)(Y,{variant:`default`,size:`sm`,onClick:p,disabled:h||o,className:`gap-1.5`,children:[c===`continue`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`check`,className:`size-4`}),s(`gitView.operation.continue`)]})]}),a&&(0,$.jsx)(`p`,{className:`typography-micro text-[var(--status-warning)]`,children:s(`gitView.operation.resolveConflictsHint`)})]})})},qd=({runMutation:e,onMutationComplete:t,onMutationError:n,onPathsComplete:r,scheduleFlush:i})=>{let a=[],o=!1;return{enqueue:e=>{let t=a[a.length-1];if(t?.directory===e.directory&&t.direction===e.direction){e.paths.forEach(e=>t.paths.add(e));return}a.push(e)},flush:()=>{if(o)return;let s=a.shift();if(!s)return;o=!0;let c={directory:s.directory,direction:s.direction,paths:Array.from(s.paths),rollback:s.rollback};(async()=>{try{await e(c),t(c)}catch(e){n(c,e)}finally{r(c.paths),o=!1,a.length>0&&i()}})()},clear:()=>{a.length=0},size:()=>a.length,isRunning:()=>o}},Jd=15e3,Yd=40,Xd=20,Zd={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:`},Qd=(e,t)=>{let n=e.toLowerCase(),r=n.match(/^([a-z]+)(?:\(.*\))?!?:/);if(r){let e=Zd[r[1]];if(e)return t.find(t=>t.code===e)||null}let i=Zd[n.split(` `)[0]];return i&&t.find(e=>e.code===i)||null},$d=20,ef=new Map,tf=(e,t)=>{if(ef.delete(e),ef.set(e,t),ef.size>$d){let e=ef.keys().next().value;e!==void 0&&ef.delete(e)}},nf=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),rf=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},af=e=>{let t=e.working_dir?.trim(),n=e.index?.trim();return!!(t||n===`?`)},of=({isActive:e})=>{let{t}=wt(),{git:n}=at(),r=Qo(),[i,a]=Q.useState(null),[o,s]=Q.useState(!1),c=xn(e=>e.currentSessionId),l=xn(e=>e.newSessionDraft),u=xn(e=>e.setDraftBootstrapPendingDirectory),d=xn(e=>e.worktreeMetadata),f=xn(e=>e.availableWorktrees),p=nf(r),m=Q.useMemo(()=>{if(!p)return;let e=f.find(e=>nf(e.path)===p);if(e)return e;for(let e of d.values())if(nf(e.path)===p)return e},[f,p,d]),h=Q.useMemo(()=>{if(c)return d.get(c)??m;if(l?.open)return m},[c,m,l?.open,d]),g=bo(r??null),_=Eo(r??null),v=an(e=>c?e.getAttachment(c):void 0),y=v?$n(v):[],b=v&&!v.degraded&&!v.legacy?v.worktreeRoot??void 0:void 0,x=dd(r,h,_?.current??void 0),S=xo(r??null),C=So(r??null),w=Co(r??null),T=To(r??null),{setActiveDirectory:E,fetchAll:D,ensureAll:O,fetchStatus:k,fetchBranches:A,fetchLog:j,setLogMaxCount:M,prefetchDiffs:N,moveStatusPathsOptimistically:P,restoreStatus:F,bumpIndexRevision:I}=Do(ue(e=>({setActiveDirectory:e.setActiveDirectory,fetchAll:e.fetchAll,ensureAll:e.ensureAll,fetchStatus:e.fetchStatus,fetchBranches:e.fetchBranches,fetchLog:e.fetchLog,setLogMaxCount:e.setLogMaxCount,prefetchDiffs:e.prefetchDiffs,moveStatusPathsOptimistically:e.moveStatusPathsOptimistically,restoreStatus:e.restoreStatus,bumpIndexRevision:e.bumpIndexRevision}))),L=q(e=>e.isMobile),R=q(e=>e.openContextFileDiff),z=q(e=>e.navigateToDiff),B=q(e=>e.setRightSidebarOpen),V=Q.useRef(null),ee=Q.useRef(null),H=Q.useRef(null),te=Q.useRef(null),ne=Q.useRef(!0);Q.useEffect(()=>()=>{ne.current=!1},[]);let re=Q.useCallback(()=>{ee.current!==null&&(window.clearTimeout(ee.current),ee.current=null)},[]),U=Q.useCallback(e=>{re(),ee.current=window.setTimeout(()=>{ee.current=null,nf(e)===nf(r)&&k(e,n,{silent:!0})},Jd)},[re,r,k,n]);Q.useEffect(()=>re,[re]);let ie=Q.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),ae=Q.useCallback(()=>{H.current===null&&(H.current=window.setTimeout(()=>{H.current=null,te.current?.()},0))},[]),W=Q.useCallback(async(e,t,r)=>{if(t===`stage`){if(n.stageGitFiles){await n.stageGitFiles(e,r);return}await Promise.all(r.map(t=>n.stageGitFile(e,t)));return}if(n.unstageGitFiles){await n.unstageGitFiles(e,r);return}await Promise.all(r.map(t=>n.unstageGitFile(e,t)))},[n]),oe=Q.useMemo(()=>qd({runMutation:({directory:e,direction:t,paths:n})=>W(e,t,n),onMutationComplete:({directory:e})=>{I(e),U(e)},onMutationError:({directory:e,direction:n,rollback:r},i)=>{r?.(),I(e),U(e);let a=t(n===`stage`?`gitView.toast.stageFileFailed`:`gitView.toast.unstageFileFailed`);X.error(i instanceof Error?i.message:a)},onPathsComplete:e=>{Ie(t=>{let n=new Set(t);return e.forEach(e=>n.delete(e)),n})},scheduleFlush:ae}),[I,W,ae,U,t]);Q.useEffect(()=>(te.current=oe.flush,()=>{te.current=null}),[oe]),Q.useEffect(()=>()=>oe.clear(),[oe]),Q.useEffect(()=>ie,[ie]),Q.useEffect(()=>{if(!e)return;if(!r){a(null),s(!1);return}let t=!1,n=wn(r);n&&a(n.status);let i=Nn((e,n)=>{t||nf(e)===nf(r)&&a(n.status)});return Mr(r).then(e=>{if(t)return;zn(r,e);let n=wn(r);a(n?.status??e.status)}).catch(()=>{!t&&!wn(r)&&a(null)}),()=>{t=!0,i()}},[e,r]),Q.useEffect(()=>{let e=V.current;V.current=i,!(!r||!n)&&(e===`pending`&&i===`ready`&&(s(!0),D(r,n).finally(()=>{window.setTimeout(()=>{s(!1)},1200)})),i===`failed`&&(u(null),s(!1)))},[r,D,n,u,i]);let se=nf(l?.bootstrapPendingDirectory??null),ce=!!(r&&se&&se===nf(r)),G=!!(r&&(i===`pending`||ce))||o,le=Q.useMemo(()=>r?ef.get(r)??null:null,[r]),de=Zn(e=>e.settingsGitmojiEnabled),[fe,pe]=Q.useState(null),{gitmojis:me}=ld(de);Q.useEffect(()=>{let e=b||x?.projectDirectory;if(!e){pe(null);return}let t=!1;return Qi(e).then(e=>{if(t)return;let n=e.trim();pe(n&&n!==`HEAD`?n:null)}).catch(()=>{t||pe(null)}),()=>{t=!0}},[b,x?.projectDirectory]);let[he,ge]=Q.useState(le?.commitMessage??``),[_e,ve]=Q.useState([]),[ye,be]=Q.useState(!1),xe=mc(_)&&!ye,[Se,Ce]=Q.useState(!1),we=Q.useRef(null),[Te,Ee]=Q.useState(null),[De,Oe]=Q.useState(!1),[ke,Ae]=Q.useState(null),[je,Me]=Q.useState(25),{triggerFireworks:Ne}=Zu(),[K,Pe]=Q.useState(new Set),[Fe,Ie]=Q.useState(new Set),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(le?.generatedHighlights??[]),Ue=Fe.size>0||oe.size()>0||oe.isRunning(),We=Q.useCallback(()=>{let e=we.current;e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight,behavior:`smooth`})})})},[]),Ge=Q.useCallback(()=>{He([])},[]),[Ke,qe]=Q.useState(new Set),[Je,Ye]=Q.useState(new Map),[Xe,Ze]=Q.useState(new Set),Qe=Q.useRef(Je),$e=Q.useRef(Xe),[et,tt]=Q.useState(null),[nt,rt]=Q.useState(null),[it,ot]=Q.useState(``),[st,ct]=Q.useState(null),[lt,ut]=Q.useState([]),[dt,ft]=Q.useState(!1),[pt,mt]=Q.useState([]),[ht,gt]=Q.useState(`merge`),[_t,vt]=Q.useState(null),[yt,bt]=Q.useState(!1),[xt,St]=Q.useState(100),Tt=Q.useMemo(()=>c?`yuri.conflict:${c}`:null,[c]),Et=Q.useCallback((e,t,n)=>{if(!Tt||typeof window>`u`)return;let r={directory:e,conflictFiles:t,operation:n};window.localStorage.setItem(Tt,JSON.stringify(r))},[Tt]),Dt=Q.useCallback(()=>{!Tt||typeof window>`u`||window.localStorage.removeItem(Tt)},[Tt]);Q.useEffect(()=>{if(!Tt||typeof window>`u`||!r)return;let e=window.localStorage.getItem(Tt);if(e)try{let t=JSON.parse(e);if(t.directory!==r){window.localStorage.removeItem(Tt);return}mt(t.conflictFiles??[]),gt(t.operation??`merge`),ft(!0)}catch{window.localStorage.removeItem(Tt)}},[Tt,r]);let Ot=Q.useCallback(e=>{Ct(e).then(e=>{if(e.ok){X.success(t(`gitView.toast.commitHashCopied`));return}X.error(t(`gitView.toast.copyFailed`))})},[t]),kt=Q.useCallback(e=>{qe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);Q.useEffect(()=>{Qe.current=Je},[Je]),Q.useEffect(()=>{$e.current=Xe},[Xe]),Q.useEffect(()=>{if(!r||!n)return;let e=Array.from(Ke).filter(e=>!Qe.current.has(e)&&!$e.current.has(e));if(e.length===0)return;let t=!1;return Ze(t=>{let n=new Set(t);for(let t of e)n.add(t);return $e.current=n,n}),Promise.all(e.map(e=>n.getCommitFiles(r,e).then(t=>({hash:e,files:t.files})).catch(t=>(console.error(`Failed to fetch commit files:`,t),{hash:e,files:[]})))).then(e=>{t||(Ye(t=>{let n=new Map(t);for(let{hash:t,files:r}of e)n.set(t,r);return Qe.current=n,n}),Ze(t=>{let n=new Set(t);for(let{hash:t}of e)n.delete(t);return $e.current=n,n}))}),()=>{t=!0,Ze(t=>{let n=!1,r=new Set(t);for(let t of e)r.delete(t)&&(n=!0);return n?($e.current=r,r):t})}},[Ke,r,n]),Q.useEffect(()=>{r&&tf(r,{directory:r,commitMessage:he,generatedHighlights:Ve})},[he,r,Ve]),Q.useEffect(()=>{if(!e)return;if(!r||!n?.getRemoteUrl){rt(null);return}let t=!1;return n.getRemoteUrl(r).then(e=>{t||rt(e)}).catch(()=>{t||rt(null)}),()=>{t=!0}},[e,r,n]);let At=Q.useCallback(async()=>{if(!r||!n?.getRemotes){ut([]);return}try{let e=await n.getRemotes(r);ne.current&&ut(e)}catch{ne.current&&ut([])}},[r,n]);Q.useEffect(()=>{e&&At()},[e,At]),Q.useEffect(()=>{e&&r&&(E(r),O(r,n))},[e,r,E,O,n]),Q.useEffect(()=>{if(e&&r)return yn.onGitRefreshHint(e=>{nf(e.directory)===nf(r)&&k(r,n)})},[e,r,k,n]);let jt=Q.useCallback(async(e=!0)=>{if(r)try{await Promise.all([k(r,n),A(r,n,{force:!0})])}catch(n){if(e){let e=n instanceof Error?n.message:t(`gitView.toast.refreshRepositoryFailed`);X.error(e)}}},[r,n,k,A,t]),Mt=Q.useCallback(async()=>{r&&await j(r,n,je)},[r,n,j,je]),Y=Q.useMemo(()=>!_||xe?[]:[..._.files??[]].sort((e,t)=>e.path.localeCompare(t.path)),[_,xe]),Nt=Q.useMemo(()=>Y.filter(rf),[Y]),Pt=Q.useMemo(()=>Y.filter(af),[Y]),{deferredStagedCount:Ft,deferredUnstagedCount:It}=Q.useMemo(()=>{if(!xe||!_)return{deferredStagedCount:0,deferredUnstagedCount:0};let e=0,t=0;for(let n of _.files??[])rf(n)&&(e+=1),af(n)&&(t+=1);return{deferredStagedCount:e,deferredUnstagedCount:t}},[xe,_]);Q.useEffect(()=>{if(!r||Y.length===0)return;let e=[],t=new Set,i=n=>{!n||t.has(n)||(t.add(n),e.push(n))};if(Nt.forEach(e=>i(e.path)),_e.forEach(i),Y.slice(0,Xd).forEach(e=>i(e.path)),e.length===0)return;let a=window.setTimeout(()=>{N(r,n,e,{maxFiles:Yd})},120);return()=>{window.clearTimeout(a)}},[Y,r,n,N,Nt,_e]);let Lt=e=>e?.pushed[0]?.remote||_?.tracking?.split(`/`)[0]||qt.find(e=>e.name===`origin`)?.name||qt[0]?.name||`origin`,Rt=async(e,i)=>{if(r){Ee(e);try{let a=e=>{let t=`${e.name}/`,n=_?.tracking?.startsWith(t)?_.tracking.slice(t.length):void 0;return{remote:e.name,branch:n,rebase:!0}};if(e===`fetch`){if(!i)throw Error(`No remote available for fetch`);await n.gitFetch(r,{remote:i.name}),X.success(t(`gitView.toast.fetchedFromRemote`,{name:i.name}))}else if(e===`pull`){if(!i)throw Error(`No remote available for pull`);let e=await n.gitPull(r,a(i));X.success(e.files.length===1?t(`gitView.toast.pulledFilesSingle`,{count:e.files.length,name:i.name}):t(`gitView.toast.pulledFilesPlural`,{count:e.files.length,name:i.name}))}else if(e===`push`){let e=await n.gitPush(r);X.success(t(`gitView.toast.pushedToUpstream`,{name:Lt(e)}))}else if(e===`sync`){if(!i)throw Error(`No remote available for sync`);let e=0,o=!1;await n.gitFetch(r,{remote:i.name});let s=await n.getGitStatus(r);if((s.behind??0)>0){if((s.files?.length??0)>0){X.error(t(`gitView.toast.commitOrStashBeforeSync`));return}e=(await n.gitPull(r,a(i))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),o=!0),e>0&&o?X.success(t(e===1?`gitView.toast.syncedPulledSingleAndPushed`:`gitView.toast.syncedPulledPluralAndPushed`,{count:e,name:i.name})):e>0?X.success(t(e===1?`gitView.toast.pulledFilesSingle`:`gitView.toast.pulledFilesPlural`,{count:e,name:i.name})):o?X.success(t(`gitView.toast.pushedToUpstream`,{name:i.name})):X.success(t(`gitView.toast.alreadyUpToDate`))}await jt(!1),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.syncActionFailed`,{action:e===`sync`?t(`gitView.sync.syncChanges`):e===`pull`?t(`gitView.sync.pull`):e});X.error(r)}finally{Ee(null)}}},zt=async(e={})=>{if(!r)return;if(!he.trim()){X.error(t(`gitView.toast.enterCommitMessage`));return}let i=Nt.map(e=>e.path).sort();if(i.length===0){X.error(t(`gitView.toast.stageFileToCommit`));return}let a=e.pushAfter?`commitAndPush`:`commit`;Ae(a);try{if(await n.createGitCommit(r,he.trim(),{files:i,stageFiles:[]}),I(r),X.success(t(`gitView.toast.commitCreated`)),ge(``),Ge(),await jt(),e.pushAfter){let e=_?.tracking?.split(`/`)[0],i=qt.find(t=>t.name===e)??qt[0];if(!i)throw Error(t(`mobile.changes.noRemote`));Ee(`sync`);let a=`${i.name}/`,o=_?.tracking?.startsWith(a)?_.tracking.slice(a.length):void 0;await n.gitFetch(r,{remote:i.name});let s=await n.getGitStatus(r);if((s.behind??0)>0){if((s.files?.length??0)>0){X.error(t(`gitView.toast.commitOrStashBeforeSync`)),await jt(!1);return}await n.gitPull(r,{remote:i.name,branch:o,rebase:!0})}let c=await n.getGitStatus(r),l;(c.ahead??0)>0&&(l=await n.gitPush(r)),X.success(t(`gitView.toast.pushedToUpstream`,{name:Lt(l)})),Ne(),await jt(!1)}else await jt(!1);await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createCommitFailed`);X.error(n)}finally{Ae(null),e.pushAfter&&Ee(null)}},Bt=Q.useCallback(async()=>{if(!r)return;let e=Nt.map(e=>e.path).sort();if(e.length===0){X.error(t(`gitView.toast.stageFileToDescribe`));return}console.error(`[git-generation][browser] generate button clicked`,{directory:r,selectedFiles:e.length}),Be(!0);try{let{message:t}=await Or(r,e),n=t.subject?.trim()??``,i=Array.isArray(t.highlights)?t.highlights:[];if(n){let e=n;if(de&&me.length>0){let t=Qd(n,me);if(t){let{code:r,emoji:i}=t;!n.startsWith(r)&&!n.startsWith(i)&&(e=`${r} ${n}`)}}ge(e)}He(i),We()}catch(e){console.error(`[git-generation][browser] GitView generate handler failed`,{message:e instanceof Error?e.message:String(e),error:e});let n=e instanceof Error?e.message:t(`gitView.toast.generateCommitMessageFailed`);X.error(n)}finally{Be(!1)}},[r,Nt,de,me,We,t]),Vt=e=>e.reason===`attention`?`${e.attentionReason} in progress`:e.reason===`missing`?`worktree is missing`:`worktree is invalid`,Ht=async(e,i)=>{if(!r||!_)return;let a=vn(v);if(a.length>0){X.error(t(`gitView.toast.cannotCreateBranch`,{reason:Vt(a[0])}));return}let o=_.current??null,s=i?.name??`origin`;try{await n.createBranch(r,e,o??`HEAD`),X.success(t(`gitView.toast.createdBranch`,{name:e})),await n.checkoutBranch(r,e);let i=!1;try{await n.gitPush(r,{remote:s,branch:e,options:[`--set-upstream`]}),i=!0}catch(e){let n=e instanceof Error?e.message:`Unable to push new branch to ${s}.`;X.warning(t(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsxs)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:[`Upstream setup failed: `,n]})})}await jt(),await Mt(),i&&X.success(t(`gitView.toast.upstreamSet`,{branch:e,remote:s}))}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createBranchFailed`);throw X.error(n),e}},Ut=async(e,i)=>{if(!r)return;let a=vn(v);if(a.length>0){X.error(t(`gitView.toast.cannotRenameBranch`,{reason:Vt(a[0])}));return}try{await n.renameBranch(r,e,i),X.success(t(`gitView.toast.renamedBranch`,{oldName:e,newName:i})),await jt(),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.renameBranchFailed`,{oldName:e,newName:i});X.error(r)}},Wt=async e=>{if(!r)return;let i=vn(v);if(i.length>0){X.error(t(`gitView.toast.cannotCheckout`,{reason:Vt(i[0])}));return}let a=e.replace(/^remotes\//,``);if(_?.current!==a)try{await n.checkoutBranch(r,a),X.success(t(`gitView.toast.checkedOut`,{name:a})),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.checkoutFailed`,{name:a});X.error(n)}},Gt=Q.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),Kt=Q.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),qt=Q.useMemo(()=>{if(lt.length>0)return lt;let e=new Set,t=_?.tracking?.trim();t&&t.includes(`/`)&&e.add(t.split(`/`)[0]);for(let t of Kt){let n=t.indexOf(`/`);n>0&&e.add(t.slice(0,n))}return e.size===0&&nt&&e.add(`origin`),Array.from(e).map(e=>({name:e,fetchUrl:nt??``,pushUrl:nt??``}))},[lt,Kt,nt,_?.tracking]),Jt=Q.useMemo(()=>{let e=new Set(qt.map(e=>e.name)),t=t=>{if(!t)return``;let n=t.trim();if(!n||n===`HEAD`)return``;if(Gt.includes(n))return n;n.startsWith(`refs/heads/`)&&(n=n.slice(11)),n.startsWith(`heads/`)&&(n=n.slice(6)),n.startsWith(`remotes/`)&&(n=n.slice(8));let r=n.indexOf(`/`);if(r>0){let t=n.slice(0,r);if(e.has(t)){let e=n.slice(r+1).trim();e&&(n=e)}}return n};return t(typeof x?.createdFromBranch==`string`?x.createdFromBranch:``)||t(typeof fe==`string`?fe:``)||(Gt.includes(`main`)?`main`:Gt.includes(`master`)?`master`:Gt.includes(`develop`)?`develop`:`main`)},[qt,Gt,fe,x?.createdFromBranch]),Yt=Nt.length,Xt=_?.current??null;Q.useEffect(()=>{if(!r||!n||!C?.all?.length||!Xt||!Jt||Xt===Jt){tt(null);return}let e=!1;return(async()=>{try{let t=await n.getGitLog(r,{from:Jt,to:`HEAD`,maxCount:je});if(e)return;let i=new Set((t?.all??[]).map(e=>e.hash).filter(e=>typeof e==`string`&&e.length>0));if(i.size===0){tt(null);return}let a=C.all.findIndex(e=>!i.has(e.hash));if(a===0){tt(null);return}if(a===-1){tt({insertBeforeIndex:C.all.length,branchName:Xt,direction:`up`});return}tt({insertBeforeIndex:a,branchName:Xt,direction:`up`})}catch{e||tt(null)}})(),()=>{e=!0}},[Jt,Xt,r,n,C,je]),Q.useEffect(()=>{vt(null)},[r]),Q.useEffect(()=>{if(st!==`graph`||!r){st!==`graph`&&vt(null);return}let e=!1;return bt(!0),n.getGitLog(r,{maxCount:xt,all:!0}).then(t=>{e||vt(t)}).catch(e=>{console.error(`Failed to fetch graph log:`,e)}).finally(()=>{e||bt(!1)}),()=>{e=!0}},[st,r,xt,n]);let Zt=Q.useCallback((e,t)=>{if(!r||e.length===0)return;let n=Array.from(new Set(e));Ie(e=>{let t=new Set(e);return n.forEach(e=>t.add(e)),t});let i=P(r,n,t);oe.enqueue({directory:r,direction:t,paths:new Set(n),rollback:()=>F(r,i)}),ae()},[r,oe,P,F,ae]),Qt=Q.useCallback(async e=>{if(r){Pe(t=>{let n=new Set(t);return n.add(e),n});try{await n.revertGitFile(r,e,{scope:`working`}),X.success(t(`gitView.toast.revertedFile`,{path:e})),await jt(!1)}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.revertFailed`);X.error(n)}finally{Pe(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,jt,n,t]),$t=Q.useCallback(async(e,i,a=`all`)=>{if(!r||e.length===0)return;let o=Array.from(new Set(e));if(Le||o.some(e=>K.has(e)))return;let s=new Set(Nt.map(e=>e.path)),c=a===`all`&&o.some(e=>s.has(e));i&&Re(!0),Pe(e=>{let t=new Set(e);return o.forEach(e=>t.add(e)),t});let l=[];try{if(await Promise.all(o.map(async e=>{try{await n.revertGitFile(r,e,{scope:a})}catch(n){l.push({path:e,message:n instanceof Error?n.message:t(`gitView.toast.revertFailed`)})}})),c&&l.length<o.length&&I(r),await jt(!1),l.length===0)X.success(o.length===1?t(`gitView.toast.revertedFilesSingle`,{count:o.length}):t(`gitView.toast.revertedFilesPlural`,{count:o.length}));else if(l.length===o.length)X.error(l[0]?.message||t(`gitView.toast.revertFailed`));else{let e=o.length-l.length;X.warning(t(e===1?`gitView.toast.revertedSomeSingle`:`gitView.toast.revertedSomePlural`,{success:e,failed:l.length}))}}finally{Pe(e=>{let t=new Set(e);return o.forEach(e=>t.delete(e)),t}),i&&Re(!1)}},[I,r,n,Le,jt,K,Nt,t]),en=Q.useCallback(async e=>{await $t(e,!0)},[$t]),tn=Q.useCallback(async e=>{await $t(e,!1,`working`)},[$t]),nn=Q.useCallback((e,t)=>{if(r&&!L){R(r,e,t);return}z(e,t),L&&B(!1)},[r,L,z,R,B]),rn=Q.useCallback(()=>Oe(!0),[]),on=Q.useMemo(()=>{let e=[];return Nt.length>0&&e.push({id:`staged`,title:t(`gitView.changes.stagedTitle`),entries:Nt,actionSymbol:`-`,actionAllLabel:t(`gitView.changes.unstageAllAria`),getActionLabel:e=>t(`gitView.changes.unstageFileAria`,{path:e}),onActionFile:e=>void Zt([e],`unstage`),onActionAll:e=>void Zt(e,`unstage`),onViewDiff:e=>nn(e,!0),onRevertFile:Qt,showRevertActions:!1,accent:!0}),Pt.length>0&&e.push({id:`unstaged`,title:t(`gitView.changes.title`),entries:Pt,actionSymbol:`+`,actionAllLabel:t(`gitView.changes.stageAllAria`),getActionLabel:e=>t(`gitView.changes.stageFileAria`,{path:e}),onActionFile:e=>void Zt([e],`stage`),onActionAll:e=>void Zt(e,`stage`),onViewDiff:e=>nn(e,!1),onRevertFile:Qt}),e},[Qt,nn,Zt,Nt,t,Pt]),sn=Q.useCallback(e=>{if(e.length===0)return;let t=e.map(e=>e.trim()).filter(Boolean);if(t.length===0){Ge();return}ge(e=>{let n=e.trim();return`${n}${n.length>0?`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-BvgdBVst.js","assets/rolldown-runtime-hePW80VL.js","assets/runtime-auth-ef9W7A43.js","assets/runtime-switch-CAZiOV2G.js","assets/queryRuntime-DKGLQtb9.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/persistence-Dzooc9Xg.js","assets/vendor-zustand-o69pgTEK.js","assets/vendor-base-ui-CdzJ6My_.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useUIStore-NMQx_cnG.js","assets/vendor-react-BP2cRVqX.js","assets/vendor-pathe-vBmvQE8f.js","assets/platform-7bX6qtBV.js","assets/vendor-opencode-client-MF2GBrFx.js","assets/runtime-file-resource-C1k5nbWb.js","assets/vendor-tanstack-react-query-CdqCAt40.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/runtime-file-download-DAOam_oV.js","assets/vendor-pierre-diffs-DPBtNDJ5.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-reactuses-core-BpfIZ1tg.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-C3292Ee6.js","assets/store-CZu30-QE.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/useThemeSystem-8jhE4Zyk.js","assets/Icon-jsQQXouE.js","assets/dialog-DrgcVFLG.js","assets/image-loading-23c-W-bq.js","assets/image-loading-D9Z_BASK.css","assets/MobileWindowStack-DGLdgoGr.js","assets/appThemeRegistry-CiQ61T5d.js","assets/useMobileNavigationStore-CEVJSNnR.js","assets/vendor-sonner-ZS8XIOVl.js","assets/useAssistantUIStore-D7JZlg_Q.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/agentColors-DWSbQXy2.js","assets/rasterizePng-056Poix7.js","assets/MarkdownRenderer-D4Ba9SUF.js","assets/useEffectiveDirectory-BBb97raM.js","assets/markdownHeightCache-BwSTMSRn.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-CkO3sT4Y.js","assets/ImageLoadingPlaceholder-CGHGcrEo.js","assets/useWorkerHighlightedLines-D8JkeSuf.js","assets/tooltip-DGUZtHif.js","assets/vendor-tanstack-react-virtual-B_EO--9t.js","assets/markdownTheme-DHoKvD6O.js","assets/mobileBackNavigation-BnipJtFo.js","assets/ToolOutputDialog-CbGuK5bP.css","assets/TerminalView-mF-mbAzo.js","assets/terminalApi-BHXvha-U.js","assets/vendor-ghostty-web-DbBrwBII.js","assets/OverlayScrollbar-C4VUlRzo.js","assets/sortable-tabs-strip-BMrSDJob.js","assets/vendor-dnd-kit-core-5pNnzVdw.js","assets/vendor-dnd-kit-accessibility-COSwgjFs.js","assets/vendor-dnd-kit-sortable-Dm50I0m7.js","assets/useFontPreferences-D9PX5t6Y.js","assets/projectActions-BX0cjZoq.js","assets/DiagramView-BRK8rzVX.js","assets/diagram-Ddq5F6R_.js","assets/vendor-react-drawio-Ck9ZKdNN.js","assets/SettingsView-DWeiBwOG.js","assets/desktopHosts-BDyl2P7W.js","assets/desktopRelayRestore-C_23nlKD.js","assets/types-Q_utERET.js","assets/vendor-codemirror-autocomplete-7c2L_4dM.js","assets/MobileShareBridge-BQnwoSB3.js","assets/MobileDetailNavigation-Cyp_3Hha.js","assets/AgentAvatar-1UO8KpCd.js","assets/vendor-dicebear-core-CV95S5Pg.js","assets/vendor-dicebear-styles-7lEG-JsF.js","assets/projectMeta-Cm0n6vtB.js","assets/gitApi-nArpJO6q.js","assets/input-DaOOTCQd.js","assets/textarea-BcA4uouw.js","assets/vendor-framer-motion-D-oiwsxL.js","assets/speechSettingsQueries-Bv08BFlI.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/dropdown-menu.styles-CeLR2UTs.js","assets/url-Be8VCT8M.js","assets/MobileTabPageHeader-CDFE4Ws4.js","assets/vendor-codemirror-lang-angular-DXOgWEVj.js","assets/vendor-codemirror-lang-json-mLulNbwB.js","assets/vendor-codemirror-lang-markdown-CV1IO6Qs.js","assets/vendor-codemirror-lang-python-YM2WVLHF.js","assets/vendor-codemirror-legacy-modes-DwltVFbT.js","assets/mcpQueries-W-LFzCOw.js","assets/collapsible-B0yvtXQR.js","assets/vendor-codemirror-commands-B8KrBQ9B.js","assets/vendor-codemirror-search-ZqtrPLjU.js","assets/vendor-replit-codemirror-vim-DDj0dSVY.js","assets/vendor-codemirror-language-data-Ctd4WxgW.js","assets/scheduledTaskNavigation-C6UYwVbD.js","assets/vendor-yaml-C9KlJAlj.js","assets/vendor-qrcode-D7jBCyl-.js","assets/vendor-dijkstrajs-BAzPDGZM.js","assets/SettingsWindow-1csE2lF6.js","assets/MultiRunWindow-rggd5jvJ.js","assets/multirun-DvSn-icg.js","assets/insertionBoundaries-BgHgsc1p.js","assets/fileMentionTouchSelection-C9jpvVUn.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/AssistantView-BJyGm9Js.js","assets/sessionChangeSummary-DXpoQiGE.js","assets/LoadingImage-BG9q4Tm_.js","assets/sessionChangeSummary-CRYRvpy7.css","assets/vendor-motion-88WXBOBf.js","assets/sessionLookup-BYycaYEQ.js","assets/assistant-attachment-cache-CLnqffXU.js","assets/OnboardingScreen-DTr_WxYY.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,p as r,t as i,v as a,w as o}from"./runtime-auth-ef9W7A43.js";import{c as s,f as c,i as l,n as u,o as d,r as f,s as p,t as m}from"./runtime-switch-CAZiOV2G.js";import{c as h,s as g,u as _}from"./queryRuntime-DKGLQtb9.js";import{$t as v,An as y,Cn as b,D as x,Dn as S,En as C,Nt as w,O as T,On as E,Rt as D,Vt as O,Xt as k,Yt as A,Zt as j,_n as M,cn as N,ct as P,en as F,et as I,hn as L,i as R,in as z,kn as B,ln as V,nn as ee,r as H,rn as te,sn as ne,t as re,un as U,vn as ie}from"./persistence-Dzooc9Xg.js";import{f as ae,h as W,l as oe,r as se,v as ce}from"./desktopHosts-BDyl2P7W.js";import{a as G,i as le,t as ue}from"./vendor-zustand-o69pgTEK.js";import{D as de,E as fe,F as pe,I as me,L as he,P as ge,a as _e,c as ve,d as ye,f as be,i as xe,it as Se,k as Ce,l as we,nt as Te,p as Ee,rt as De,u as Oe}from"./vendor-base-ui-CdzJ6My_.js";import{Ar as ke,Cr as Ae,Ct as je,Dt as Me,Et as Ne,Hn as K,Mr as Pe,Mt as Fe,Nr as Ie,Nt as Le,St as Re,Tt as ze,Vn as Be,Xn as Ve,_n as He,br as Ue,hn as We,wr as Ge,wt as Ke,xr as qe,zn as Je}from"./platform-7bX6qtBV.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{S as Ye,b as Xe,n as q,r as Ze,x as Qe}from"./useUIStore-NMQx_cnG.js";import{n as $e,t as et}from"./vendor-react-BP2cRVqX.js";import{c as tt}from"./vendor-tanstack-query-core-BWz0ose6.js";import{n as nt,o as rt,s as it}from"./vendor-tanstack-react-query-CdqCAt40.js";import{A as at,j as ot,r as st,s as ct,v as lt,x as ut}from"./runtime-file-resource-C1k5nbWb.js";import{o as dt}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{n as ft}from"./terminalApi-BHXvha-U.js";import{a as pt}from"./types-Q_utERET.js";/* empty css */import{H as mt,ot as ht}from"./vendor-codemirror-autocomplete-7c2L_4dM.js";import{a as gt}from"./vendor-pierre-diffs-DPBtNDJ5.js";import{f as _t,n as vt,r as yt,t as bt}from"./vendor-reactuses-core-BpfIZ1tg.js";import{_ as xt,a as St,c as Ct,d as wt,f as Tt,g as Et,h as Dt,i as Ot,l as kt,m as At,o as jt,p as Mt,r as J,s as Nt,t as Y}from"./button-C3292Ee6.js";import{n as Pt}from"./store-CZu30-QE.js";import{S as Ft,_ as It,w as Lt}from"./MobileDetailNavigation-Cyp_3Hha.js";import{$n as Rt,An as zt,Ar as Bt,Bt as Vt,C as Ht,Co as Ut,Er as Wt,Gt,Ir as Kt,Kn as qt,Li as Jt,Lr as Yt,Lt as Xt,Mt as Zt,Nr as Qt,Nt as $t,Or as en,Pr as tn,Ra as nn,Ri as rn,Rr as X,Rt as an,S as on,Sa as sn,So as cn,Ur as ln,Ut as un,Vi as dn,Wt as fn,Xn as pn,Yn as mn,Yr as hn,_ as gn,_n,an as vn,b as yn,bi as bn,bo as xn,d as Sn,da as Cn,dn as wn,dr as Tn,en as En,er as Dn,f as On,fa as kn,fn as An,fo as jn,ga as Mn,h as Nn,hr as Pn,in as Fn,jr as In,kr as Ln,li as Rn,ln as zn,lr as Bn,m as Vn,on as Hn,p as Un,pn as Wn,qn as Gn,sn as Kn,ti as qn,tn as Jn,ui as Yn,vn as Xn,w as Zn,wa as Qn,wo as $n,x as er,xi as tr,xo as nr,xr as rr,yn as ir,zi as ar}from"./useMobileNavigationStore-CEVJSNnR.js";import{n as or}from"./useAssistantUIStore-D7JZlg_Q.js";import{n as sr}from"./useThemeSystem-8jhE4Zyk.js";import{n as Z,t as cr}from"./Icon-jsQQXouE.js";import{a as lr,i as ur,n as dr,o as fr,r as pr,t as mr}from"./dialog-DrgcVFLG.js";import{A as hr,C as gr,D as _r,O as vr,P as yr,T as br,a as xr,f as Sr,h as Cr,i as wr,j as Tr,k as Er,m as Dr,o as Or,p as kr,r as Ar,t as jr,w as Mr,y as Nr}from"./gitApi-nArpJO6q.js";import{$ as Pr,A as Fr,At as Ir,B as Lr,C as Rr,Ct as zr,D as Br,Dt as Vr,Et as Hr,F as Ur,Ft as Wr,G as Gr,I as Kr,K as qr,Lt as Jr,M as Yr,Mt as Xr,N as Zr,Nt as Qr,O as $r,Ot as ei,P as ti,Pt as ni,Q as ri,Rt as ii,S as ai,St as oi,T as si,Tt as ci,W as li,_ as ui,_t as di,at as fi,b as pi,c as mi,d as hi,dt as gi,et as _i,f as vi,g as yi,gt as bi,h as xi,ht as Si,i as Ci,it as wi,j as Ti,jt as Ei,k as Di,kt as Oi,l as ki,m as Ai,mt as ji,n as Mi,nt as Ni,ot as Pi,p as Fi,pt as Ii,rt as Li,s as Ri,st as zi,t as Bi,tt as Vi,u as Hi,v as Ui,wt as Wi,x as Gi,xt as Ki,y as qi,yt as Ji}from"./useAppFontEffects-HYIeI-xf.js";import{O as Yi,T as Xi,_ as Zi,a as Qi,b as $i,f as ea,h as ta,i as na,l as ra,m as ia,n as aa,p as oa,s as sa,x as ca}from"./projectMeta-Cm0n6vtB.js";import{t as la}from"./input-DaOOTCQd.js";import{i as ua,n as da,r as fa,t as pa}from"./tooltip-DGUZtHif.js";import{A as ma,Ct as ha,D as ga,E as _a,I as va,K as ya,L as ba,N as xa,O as Sa,Rt as Ca,S as wa,T as Ta,Yt as Ea,_ as Da,_t as Oa,at as ka,b as Aa,d as ja,ft as Ma,g as Na,gt as Pa,h as Fa,it as Ia,j as La,l as Ra,lt as za,mt as Ba,on as Va,ot as Ha,p as Ua,q as Wa,rt as Ga,s as Ka,u as qa,ut as Ja,v as Ya,vt as Xa,w as Za,wt as Qa,x as $a,y as eo,yt as to}from"./speechSettingsQueries-Bv08BFlI.js";import{i as no,o as ro}from"./OverlayScrollbar-C4VUlRzo.js";import{d as io}from"./image-loading-23c-W-bq.js";import{_ as ao,b as oo,i as so,n as co,r as lo,t as uo,v as fo,x as po}from"./dropdown-menu.styles-CeLR2UTs.js";import{n as mo,r as ho}from"./textarea-BcA4uouw.js";import{r as go,t as _o}from"./sessionChangeSummary-DXpoQiGE.js";import{n as vo,o as yo}from"./vendor-framer-motion-D-oiwsxL.js";import{A as bo,_ as xo,b as So,f as Co,g as wo,h as To,k as Eo,m as Do,v as Oo,y as ko}from"./insertionBoundaries-BgHgsc1p.js";import{n as Ao,t as jo}from"./appThemeRegistry-CiQ61T5d.js";import{n as Mo,o as No}from"./MarkdownRenderer-D4Ba9SUF.js";import{_ as Po,i as Fo,l as Io,n as Lo,s as Ro,t as zo,v as Bo,y as Vo}from"./vendor-dnd-kit-core-5pNnzVdw.js";import{a as Ho,n as Uo,o as Wo,s as Go,t as Ko}from"./vendor-dnd-kit-sortable-Dm50I0m7.js";import{a as qo}from"./url-Be8VCT8M.js";import{c as Jo,d as Yo,f as Xo,l as Zo,p as Qo,u as $o}from"./markdown-worker-CkO3sT4Y.js";import{n as es,t as ts}from"./useEffectiveDirectory-BBb97raM.js";import{t as ns}from"./ImageLoadingPlaceholder-CGHGcrEo.js";import{t as rs}from"./LoadingImage-BG9q4Tm_.js";import{g as is}from"./useWorkerHighlightedLines-D8JkeSuf.js";import{t as as}from"./sortable-tabs-strip-BMrSDJob.js";import{t as os}from"./vendor-tanstack-react-virtual-B_EO--9t.js";import{t as ss}from"./vendor-motion-88WXBOBf.js";import{A as cs,B as ls,C as us,D as ds,E as fs,F as ps,I as ms,L as hs,O as gs,R as _s,S as vs,T as ys,_ as bs,a as xs,b as Ss,c as Cs,d as ws,f as Ts,h as Es,i as Ds,k as Os,l as ks,m as As,n as js,o as Ms,p as Ns,s as Ps,w as Fs,y as Is}from"./MobileTabPageHeader-CDFE4Ws4.js";import{i as Ls,n as Rs,r as zs,t as Bs}from"./useDesktopWindowControlsLayout-Cc-2uuN5.js";import{n as Vs}from"./useFontPreferences-D9PX5t6Y.js";import{B as Hs,C as Us,E as Ws,H as Gs,J as Ks,K as qs,L as Js,Q as Ys,R as Xs,S as Zs,T as Qs,U as $s,V as ec,W as tc,X as nc,Z as rc,_ as ic,a as ac,at as oc,b as sc,c as cc,ct as lc,d as uc,dt as dc,et as fc,f as pc,ft as mc,g as hc,h as gc,ht as _c,i as vc,it as yc,l as bc,lt as xc,m as Sc,mt as Cc,n as wc,nt as Tc,o as Ec,ot as Dc,pt as Oc,q as kc,r as Ac,rt as jc,s as Mc,st as Nc,tt as Pc,u as Fc,ut as Ic,v as Lc,w as Rc,x as zc,y as Bc,z as Vc}from"./runtimeEndpointReset-BYn28E2A.js";import{a as Hc,c as Uc,l as Wc,o as Gc,s as Kc}from"./scheduledTaskNavigation-C6UYwVbD.js";import{i as qc}from"./sessionLookup-BYycaYEQ.js";import{n as Jc,r as Yc,t as Xc}from"./collapsible-B0yvtXQR.js";import{a as Zc,o as Qc,r as $c,s as el,t as tl}from"./projectActions-BX0cjZoq.js";import{t as nl}from"./diagram-Ddq5F6R_.js";import{a as rl,i as il,n as al,o as ol,r as sl,t as cl}from"./multirun-DvSn-icg.js";import{t as ll}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as ul,t as dl}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(Se(),1),fl=et(),pl=$e(),$=De();function ml(e){let t=(0,pl.c)(14),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({size:i,className:n,style:a,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=typeof i==`number`?`${i}px`:i,s=typeof i==`number`?`${i}px`:i,c;t[5]!==a||t[6]!==o||t[7]!==s?(c={width:o,height:s,...a},t[5]=a,t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.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`}),t[9]=l):l=t[9];let u;return t[10]!==n||t[11]!==r||t[12]!==c?(u=(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 256 256`,fill:`currentColor`,className:n,style:c,...r,children:l}),t[10]=n,t[11]=r,t[12]=c,t[13]=u):u=t[13],u}var hl=[{id:`finder`,label:`Finder`,appName:`Finder`},{id:`terminal`,label:`Terminal`,appName:`Terminal`},{id:`iterm2`,label:`iTerm2`,appName:`iTerm`},{id:`ghostty`,label:`Ghostty`,appName:`Ghostty`},{id:`vscode`,label:`VS Code`,appName:`Visual Studio Code`},{id:`vscode-insiders`,label:`VS Code Insiders`,appName:`Visual Studio Code - Insiders`},{id:`intellij`,label:`IntelliJ`,appName:`IntelliJ IDEA`},{id:`visual-studio`,label:`Visual Studio`,appName:`Visual Studio`},{id:`cursor`,label:`Cursor`,appName:`Cursor`},{id:`android-studio`,label:`Android Studio`,appName:`Android Studio`},{id:`pycharm`,label:`PyCharm`,appName:`PyCharm`},{id:`xcode`,label:`Xcode`,appName:`Xcode`},{id:`sublime-text`,label:`Sublime`,appName:`Sublime Text`},{id:`webstorm`,label:`WebStorm`,appName:`WebStorm`},{id:`rider`,label:`Rider`,appName:`Rider`},{id:`zed`,label:`Zed`,appName:`Zed`},{id:`phpstorm`,label:`PhpStorm`,appName:`PhpStorm`},{id:`eclipse`,label:`Eclipse`,appName:`Eclipse`},{id:`windsurf`,label:`Windsurf`,appName:`Windsurf`},{id:`vscodium`,label:`VSCodium`,appName:`VSCodium`},{id:`rustrover`,label:`RustRover`,appName:`RustRover`},{id:`kiro`,label:`Kiro`,appName:`Kiro`},{id:`antigravity`,label:`Antigravity`,appName:`Antigravity`},{id:`trae`,label:`Trae`,appName:`Trae`}],gl=`finder`,_l=new Set([`finder`,`terminal`]),vl=e=>typeof window<`u`&&window.__YURI_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,yl=e=>{if(!e)return null;let t=hl.find(t=>t.id===e)??null;return t?vl(t):null},bl=()=>hl.filter(e=>_l.has(e.id)).map(e=>({...vl(e)})),xl=()=>{if(typeof window>`u`)return gl;let e=window.localStorage.getItem(`openInAppId`);return e&&yl(e)?e:gl},Sl=!1,Cl=!1,wl=!1,Tl=0,El=null,Dl=()=>{El&&=(clearTimeout(El),null)},Ol=G()((e,t)=>({selectedAppId:xl(),availableApps:bl(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Sl||typeof window>`u`)return;Sl=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:bl(),hasLoadedApps:n});return}let r=new Set(t.map(e=>e.name)),i=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0]));e({availableApps:hl.filter(e=>r.has(e.appName)||_l.has(e.id)).map(e=>({...vl(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!F()||Cl||t().hasLoadedApps&&!i)return;let a=hl.map(e=>e.appName);Dl(),i&&e({hasLoadedApps:!1}),Cl=!0,wl=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await O(a,i),l=o&&!s&&t.length===0&&Tl<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][Tl]??3200;Tl+=1,wl=!0,El=setTimeout(()=>{r()},e);return}Tl=0,wl=!1;return}if(Tl<3){let e=[1e3,3e3,7e3][Tl]??7e3;Tl+=1,wl=!0,El=setTimeout(()=>{r()},e)}}finally{Cl=!1,wl||e({isScanning:!1})}};r(),window.addEventListener(`yuri:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&yl(n.openInAppId)?n.openInAppId:null;r&&(window.localStorage.setItem(`openInAppId`,r),e({selectedAppId:r}))}),window.addEventListener(`yuri:app-ready`,()=>{r()}),window.addEventListener(`yuri:installed-apps-updated`,t=>{let r=t.detail;Array.isArray(r)&&(Tl=3,wl=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__yuriAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Sl||t().initialize(),!F()||Cl||t().hasLoadedApps&&!n)return;let r=hl.map(e=>e.appName);Dl(),n&&e({hasLoadedApps:!1}),Cl=!0,wl=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await O(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=hl.filter(e=>o.has(e.appName)||_l.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:bl(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{Cl=!1,wl||e({isScanning:!1})}},selectApp:async t=>{yl(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await R({openInAppId:t}))}})),kl=(e=f(),t=l())=>{let n=e.startsWith(`host:`)?e.slice(5):null;return{queryKey:[t,`ssh-editor-apps`,n],enabled:F()&&k()&&n!==null,queryFn:async({signal:e})=>{let t=await j(`desktop_ssh_editor_apps`,{hostId:n});return e.throwIfAborted(),t?{hostId:n,appIds:t.appIds}:null}}},Al=()=>{let e=(0,pl.c)(3),t=(0,Q.useSyncExternalStore)(s,f,jl),n=(0,Q.useSyncExternalStore)(s,l,Ml),r;return e[0]!==t||e[1]!==n?(r=kl(t,n),e[0]=t,e[1]=n,e[2]=r):r=e[2],it(r)};function jl(){return``}function Ml(){return``}var Nl=`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`,Pl=`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`,Fl=e=>({...e,fallbackIconDataUrl:e.id===`finder`&&window.__YURI_PLATFORM__!==`win32`?Nl:e.id===`terminal`?Pl:void 0}),Il=e=>{let t=(0,pl.c)(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=e,[a,o]=Q.useState(!1),s;t[0]===n?s=t[1]:(s=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=s);let c=s,l=r||i;if(l&&!a){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>o(!0),t[2]=e):e=t[2];let n;return t[3]===l?n=t[4]:(n=(0,$.jsx)(`img`,{src:l,alt:``,className:`h-4 w-4 rounded-sm`,onError:e}),t[3]=l,t[4]=n),n}let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(`h-4 w-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=u):u=t[5];let d;return t[6]===c?d=t[7]:(d=(0,$.jsx)(`span`,{className:u,children:c}),t[6]=c,t[7]=d),d},Ll=({directory:e,className:t})=>{let{t:n}=Tt(),r=Ol(e=>e.selectedAppId),i=Ol(e=>e.availableApps),a=Ol(e=>e.isCacheStale),o=Ol(e=>e.isScanning),s=Ol(e=>e.initialize),c=Ol(e=>e.loadInstalledApps),l=Ol(e=>e.selectApp),{data:u}=Al(),d=Q.useMemo(()=>u?i.filter(e=>u.appIds.includes(e.id)):i,[i,u]);Q.useEffect(()=>{s()},[s]);let f=F()&&v(),p=Q.useMemo(()=>{let e=d.find(e=>e.id===r)??d.find(e=>e.id===`finder`)??d[0];return e?Fl(e):null},[d,r]);if(!f&&!u||!e)return null;let m=async t=>{try{let r=await U(e,t.id,t.appName,u?.hostId);!r&&!u?await V(e,t.appName):r||X.error(n(`filesView.toast.openInAppFailed`,{app:t.label}))}catch(e){X.error(n(String(e).includes(`SSH_EDITOR_CONFIG_REQUIRED`)?`openInApp.errors.sshConfigRequired`:`filesView.toast.openInAppFailed`,{app:t.label}))}},h=async e=>{await l(e.id),await m(e)},g=async()=>{await wt(e)};return(0,$.jsxs)(`div`,{className:J(`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`,t),children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>void(p?m(p):g()),className:J(`inline-flex h-full items-center px-2.5 typography-ui-label font-medium`,`text-foreground hover:bg-interactive-hover transition-colors`,o&&`animate-pulse`),"aria-label":p?n(`openInApp.actions.openInAria`,{app:p.label}):n(`openInApp.actions.copyPath`),children:p?(0,$.jsx)(Il,{label:p.label,iconDataUrl:p.iconDataUrl,fallbackIconDataUrl:p.fallbackIconDataUrl}):(0,$.jsx)(Z,{name:`file-copy`,className:`h-4 w-4`})}),(0,$.jsxs)(Ga,{children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`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`),"aria-label":n(`openInApp.actions.chooseAppAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4`})})}),(0,$.jsxs)(Ia,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>void g(),children:[(0,$.jsx)(Z,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`openInApp.actions.copyPath`)})]}),(0,$.jsx)(za,{}),d.map(e=>{let t=Fl(e);return(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>void h(e),children:[(0,$.jsx)(Il,{label:e.label,iconDataUrl:e.iconDataUrl,fallbackIconDataUrl:t.fallbackIconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label}),p?.id===e.id?(0,$.jsx)(Z,{name:`check`,className:`ml-auto h-4 w-4 text-primary`}):null]},e.id)}),a?(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>void c(!0),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`openInApp.actions.refreshApps`)})]}):null]})]})]})},Rl=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],zl=[`dev`,`start`,`preview`,`serve`];async function Bl(e,t,n){if(!e)return null;let r=Ul(t);if(r)return{command:r.command,label:r.name||`Start Preview`,actionId:r.id};if(n){let t=Wl(n);if(t){let n=await Gl(e);return{command:`${n===`npm`?`npm run`:n===`yarn`?`yarn`:n===`pnpm`?`pnpm`:n===`bun`?`bun run --shell=bun`:`npm run`} ${t}`,label:`Start (${t})`}}}if(await Vl(e)){let e=await Hl(),t=typeof e==`number`&&Number.isFinite(e)&&e>0?e:8e3;return{command:`python3 -m http.server ${t}`,label:`Static preview`,previewUrlHint:`http://127.0.0.1:${t}/`}}return null}async function Vl(e){let t=await Kl(`${e}/index.html`,e);return typeof t==`string`&&t.trim().length>0}async function Hl(){try{let e=await _(`/api/system/free-port`,{cache:`no-store`});if(!e.ok)return null;let t=await e.json().catch(()=>null),n=typeof t?.port==`number`?t.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Ul(e){for(let t of e){let e=`${t.name} ${t.command}`.toLowerCase();if(zl.some(t=>e.includes(t)))return t}return null}function Wl(e){for(let{pattern:t}of Rl)for(let n of Object.keys(e))if(t.test(n))return n;return null}async function Gl(e){let t=await Kl(`${e}/package.json`,e);if(t)try{let e=JSON.parse(t),n=typeof e.packageManager==`string`?e.packageManager.toLowerCase():``;if(n.startsWith(`bun@`))return`bun`;if(n.startsWith(`pnpm@`))return`pnpm`;if(n.startsWith(`yarn@`))return`yarn`;if(n.startsWith(`npm@`))return`npm`}catch{}for(let[t,n]of[[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`pnpm-lock.yaml`,`pnpm`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]]){let r=await Kl(`${e}/${t}`,e);if(typeof r==`string`&&r.trim().length>0)return n}return`npm`}async function Kl(e,t){if(t?.trim())try{let n=new URLSearchParams({path:e,directory:t,optional:`true`}),r=await _(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(r.ok)return r.text()}catch{}let n=g()?.files;if(n?.readFile)try{let t=await n.readFile(e,{optional:!0});return typeof t?.content==`string`?t.content:null}catch{return null}try{let t=await _(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:`no-store`});return t.ok?t.text():null}catch{return null}}async function ql(e){try{let t=await Kl(`${e}/package.json`,e);if(t==null)return null;let n=JSON.parse(t).scripts;return n&&typeof n==`object`&&!Array.isArray(n)?n:null}catch{return null}}var Jl=e=>new Promise(t=>{window.setTimeout(t,e)}),Yl=RegExp(`\x1B\\[[0-9;?]*[ -/]*[@-~]`,`g`),Xl=/https?:\/\/[^\s<>'"`]+/gi,Zl=`__yuri_auto_discover_preview__`,Ql=15e3,$l=e=>{let t=``;for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(t+=e[n])}return t},eu=e=>{let t=(e||``).trim();if(!t)return null;let n=/^https?:\/\//i.test(t)?t:`http://${t}`;try{let e=new URL(n);return e.protocol!==`http:`&&e.protocol!==`https:`?null:e.toString()}catch{return null}},tu=e=>{let t=e.replace(Yl,``).match(Xl);if(!t||t.length===0)return null;let n=t.map(e=>e.replace(/[),.;]+$/,``)).filter(Boolean);if(n.length===0)return null;let r=[];for(let e of n)try{let t=new URL(e);t.port&&t.port.length>0&&r.push({raw:e,parsed:t})}catch{}if(r.length>0){let e=e=>{let{parsed:t}=e,n=t.hostname.toLowerCase(),r=n===`localhost`||n===`127.0.0.1`||n===`0.0.0.0`||n===`::1`,i=t.pathname||`/`,a=i.split(`/`).filter(Boolean).length,o=i===`/`||i===``,s=!!(t.search||t.hash),c=0;return r&&(c+=50),o&&(c+=30),c-=Math.min(a*5,20),s&&(c-=10),c};return r.sort((t,n)=>e(n)-e(t)),r[0]?.parsed.origin??r[0]?.raw??null}return n[0]??null},nu=({projectRef:e,directory:t,className:n,compact:r=!1,allowMobile:i=!1})=>{let{t:a}=Tt(),{terminal:o,runtime:s}=at(),{isMobile:c}=no(),l=Q.useMemo(()=>F(),[]),u=Ss(e=>e.instances),d=Ss(e=>e.load),f=q(e=>e.setBottomTerminalOpen),p=q(e=>e.setActiveMainTab),m=q(e=>e.setSettingsPage),h=q(e=>e.setSettingsDialogOpen),g=q(e=>e.setSettingsProjectsSelectedId),_=q(e=>e.openContextPreview),v=Vs(e=>e.sessions),y=Vs(e=>e.ensureDirectory),b=Vs(e=>e.setTabLabel),x=Vs(e=>e.setTabIconKey),S=Vs(e=>e.setActiveTab),C=Vs(e=>e.setConnecting),w=Vs(e=>e.setTabSessionId),T=Vs(e=>e.setTabPreviewUrl),E=Vs(e=>e.projectActionRuns),D=Vs(e=>e.setProjectActionRun),O=Vs(e=>e.updateProjectActionRunStatus),k=Vs(e=>e.removeProjectActionRun),[A,j]=Q.useState([]),[M,N]=Q.useState(null),[P,I]=Q.useState(!1),L=Q.useRef({}),R=Q.useRef({}),z=Q.useRef({}),B=Q.useRef({}),V=Q.useRef(0),ee=e?.id??null,H=e?.path??``,te=Q.useMemo(()=>ee?{id:ee,path:H}:null,[ee,H]);Q.useEffect(()=>{l&&d().catch(()=>void 0)},[l,d]);let ne=Q.useCallback(async e=>{await qo(e)},[]),re=Q.useCallback(async()=>{if(!te)return;let e=V.current+1;V.current=e,I(!0);try{let t=await Dn(te);if(V.current!==e)return;let n=t.actions;j(n),N(e=>e===Zl||e&&n.some(t=>t.id===e)?e:null)}catch{if(V.current!==e)return}finally{V.current===e&&I(!1)}},[te]),U=Q.useMemo(()=>Zc(t||te?.path||``),[t,te?.path]),ie=Q.useMemo(()=>M?A.find(e=>e.id===M)??null:null,[A,M]),ae=Q.useMemo(()=>({id:Zl,name:a(`projectActions.actions.autoDiscover`),command:``,icon:`search`,autoOpenUrl:!0}),[a]),W=!c,oe=Q.useMemo(()=>W?[ae,...A]:A,[A,ae,W]);Q.useEffect(()=>{re()},[re]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;ee&&(t?.projectId&&t.projectId!==ee||re())};return window.addEventListener(tl,e),()=>{window.removeEventListener(tl,e)}},[re,ee]),Q.useEffect(()=>{M&&(M===Zl&&W||A.some(e=>e.id===M)||N(null))},[A,W,M]),Q.useEffect(()=>{for(let[e,t]of Object.entries(E)){let n=v.get(t.directory)?.tabs.find(e=>e.id===t.tabId);(!n||n.terminalSessionId!==t.sessionId)&&k(e)}},[E,k,v]),Q.useEffect(()=>{for(let[e,t]of Object.entries(E)){let n=R.current[e]??{lastSeenChunkId:null,openedUrl:!1,tail:``,openInPreview:!1};R.current[e]=n;let r=oe.find(e=>e.id===t.actionId);if(!r)continue;let i=v.get(t.directory)?.tabs.find(e=>e.id===t.tabId);if(!i||!Array.isArray(i.bufferChunks)||i.bufferChunks.length===0)continue;let o=i.bufferChunks.filter(e=>n.lastSeenChunkId===null||e.id>n.lastSeenChunkId);if(o.length===0)continue;let s=o.map(e=>e.data).join(``),c=`${n.tail}${s}`,l=!n.openedUrl&&r.autoOpenUrl===!0?tu(c):null;if(n.lastSeenChunkId=o[o.length-1]?.id??n.lastSeenChunkId,n.tail=c.slice(-512),l)if(n.openedUrl=!0,n.openInPreview){let t=E[e];t&&(T(t.directory,t.tabId,l,{locked:!1,autoOpened:!1}),t.status===`waiting-for-preview`&&O(e,`running`),window.clearTimeout(B.current[e]),delete B.current[e],_(t.directory,l))}else ne(l),X.success(a(`projectActions.toast.openedUrlFromOutput`));R.current[e]=n}for(let e of Object.keys(R.current))E[e]||(delete R.current[e],window.clearTimeout(B.current[e]),delete B.current[e])},[oe,_,ne,E,T,a,v,O]);let se=Q.useCallback(async(e,t={})=>{if(!U)throw Error(a(`projectActions.error.noActiveDirectory`));let n=el(U,e.id);y(U);let r=Vs.getState(),i=r.getDirectoryState(U),o=L.current[n]||null,s=o?!!i?.tabs.some(e=>e.id===o):!1;(!o||!s)&&(o=r.createTab(U),L.current[n]=o),b(U,o,`Action: ${e.name}`),x(U,o,e.icon||`play`),t.revealTerminal!==!1&&(S(U,o),f(!0),p(`terminal`));let c=Vs.getState().getDirectoryState(U)?.tabs.find(e=>e.id===o);return{key:n,tabId:o,sessionId:c?.terminalSessionId??null}},[y,U,p,S,f,x,b,a]),ce=Q.useCallback(async e=>{if(s.isVSCode||!i&&c)return;if(!U){X.error(a(`projectActions.error.noActiveDirectoryForAction`));return}let t=el(U,e.id),n=E[t];if(!(n&&n.status===`running`))try{let t=e.id===Zl?await(async()=>{let[e,t]=await Promise.all([Dn({id:te?.id??``,path:U}),ql(U)]),n=await Bl(U,e.actions,t);if(!n)throw Error(a(`contextPanel.preview.noDevServer`));return{id:Zl,name:a(`projectActions.actions.autoDiscover`),command:n.command,icon:`search`,autoOpenUrl:!0,openUrl:n.previewUrlHint||``}})():e,n=t.autoOpenUrl===!0&&(t.openUrl||``).trim().length>0,{key:r,tabId:i,sessionId:s}=await se(t,{revealTerminal:!n&&e.id!==Zl}),c=s,d=!1;if(!c){C(U,i,!0);try{c=(await o.createSession({cwd:U})).sessionId,d=!0,w(U,i,c)}finally{C(U,i,!1)}}if(!c)throw Error(a(`projectActions.error.failedToCreateTerminalSession`));d&&await Jl(350),t.id===Zl&&(z.current[r]?.(),C(U,i,!0),z.current[r]=ft(c,e=>{e.type===`data`&&typeof e.data==`string`&&e.data.length>0&&Vs.getState().appendToBuffer(U,i,e.data),e.type===`exit`&&(Vs.getState().setTabLifecycle(U,i,`exited`),Vs.getState().setConnecting(U,i,!1),Vs.getState().removeProjectActionRun(r),delete R.current[r],z.current[r]?.(),delete z.current[r],window.clearTimeout(B.current[r]),delete B.current[r])},()=>{Vs.getState().setConnecting(U,i,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));let f=t.autoOpenUrl===!0&&l&&(t.desktopOpenSshForward||``).trim().length>0,p=t.autoOpenUrl?eu(t.openUrl):null,m=t.autoOpenUrl&&l?Qc(t.desktopOpenSshForward,u):null;D({key:r,directory:U,actionId:t.id,tabId:i,sessionId:c,status:t.id===Zl&&!p?`waiting-for-preview`:`running`}),window.clearTimeout(B.current[r]),delete B.current[r],t.id===Zl&&!p&&(B.current[r]=window.setTimeout(()=>{Vs.getState().updateProjectActionRunStatus(r,`running`),delete B.current[r]},Ql)),m?(T(U,i,null,{locked:!0}),ne(m),X.success(a(`projectActions.toast.openedForwardedUrl`))):p?(T(U,i,p,{locked:!0,autoOpened:!0}),_(U,p),X.success(a(`projectActions.toast.openedActionUrl`))):n?(T(U,i,null,{locked:!0}),X.error(a(`projectActions.error.invalidCustomUrlFormat`))):f?(T(U,i,null,{locked:!0}),X.error(a(`projectActions.error.selectedDesktopSshForwardUnavailable`))):T(U,i,null,{locked:!1,autoOpened:!1}),R.current[r]={lastSeenChunkId:null,openedUrl:!!m||!!p||n,tail:``,openInPreview:t.id===Zl};let h=$l(t.command.trim().replace(/\r\n|\r/g,`
3
+ `));await o.sendInput(c,`${h}\r`)}catch(e){k(t),delete R.current[t],z.current[t]?.(),delete z.current[t],window.clearTimeout(B.current[t]),delete B.current[t],X.error(e instanceof Error?e.message:a(`projectActions.error.failedToRunAction`))}},[u,se,i,c,l,U,ne,_,E,s.isVSCode,k,C,D,T,w,te?.id,a,o]),G=Q.useCallback(async e=>{let t=el(U,e.id),n=E[t];if(n){O(t,`stopping`);try{await o.sendInput(n.sessionId,``)}catch{}if(await new Promise(e=>{window.setTimeout(e,1e3)}),Vs.getState().getDirectoryState(n.directory)?.tabs.find(e=>e.id===n.tabId)?.terminalSessionId===n.sessionId){if(typeof o.forceKill==`function`)try{await o.forceKill({sessionId:n.sessionId})}catch{}else try{await o.close(n.sessionId)}catch{}w(n.directory,n.tabId,null)}k(t),delete R.current[t],z.current[t]?.(),delete z.current[t],window.clearTimeout(B.current[t]),delete B.current[t]}},[U,E,k,w,o,O]),le=Q.useCallback(()=>{let e=ie??oe[0];if(!e)return;let t=el(U,e.id),n=E[t];if(n?.status!==`stopping`){if(n){G(e);return}ce(e)}},[oe,U,ce,E,ie,G]),ue=Q.useCallback((e,t=!1)=>{if(N(e.id),!t){ce(e);return}let n=el(U,e.id),r=E[n];if(r?.status!==`stopping`){if(r){G(e);return}ce(e)}},[U,ce,E,G]),de=Q.useCallback(()=>{te?.id&&(g(te.id),m(`projects`),h(!0))},[h,m,g,te?.id]);if(s.isVSCode||!i&&c||!te||!U)return null;let fe=ie??oe[0]??null;if(!fe)return null;let pe=fe.icon||`play`,me=fe.id===Zl?`search`:$c[pe]||`play`,he=E[el(U,fe.id)],ge=he?.status===`stopping`,_e=he?.status===`waiting-for-preview`,ve=he?v.get(he.directory)?.tabs.find(e=>e.id===he.tabId)?.previewUrl??null:null,ye=!!(he&&ve),be=()=>{!he||!ve||_(he.directory,ve)};return r?(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:P||ge,className:J(`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:le,"aria-label":a(he?`projectActions.actions.stopNamedAria`:`projectActions.actions.runNamedAria`,{name:fe.name}),children:ge||_e?(0,$.jsx)(Z,{name:`loader-4`,className:`h-5 w-5 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(Z,{name:`stop`,className:`h-5 w-5 text-[var(--status-warning)]`}):(0,$.jsx)(Z,{name:me,className:`h-5 w-5`})}),ye?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":a(`projectActions.actions.openPreview`),onClick:be,children:(0,$.jsx)(Z,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(Ga,{children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"aria-label":a(`projectActions.actions.chooseActionAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})}),(0,$.jsxs)(Ia,{align:`end`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(za,{}),oe.map(e=>{let t=e.icon||`play`,n=e.id===Zl?`search`:$c[t]||`play`,r=el(U,e.id),i=E[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(Z,{name:n,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:e.name}),o||i?.status===`waiting-for-preview`?(0,$.jsx)(Z,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(Z,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]}):(0,$.jsxs)(`div`,{className:J(`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:[(0,$.jsx)(`button`,{type:`button`,onClick:le,disabled:P||ge,className:J(`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":a(he?`projectActions.actions.stopNamedAria`:`projectActions.actions.runNamedAria`,{name:fe.name}),children:(0,$.jsx)(`span`,{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center`,children:ge||_e?(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(Z,{name:`stop`,className:`h-4 w-4 text-[var(--status-warning)]`}):(0,$.jsx)(Z,{name:me,className:`h-4 w-4`})})}),ye?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:be,className:J(r?`inline-flex h-full w-8 items-center justify-center`:`inline-flex h-full w-7 items-center justify-center`,`border-l border-[var(--interactive-border)] text-foreground`,`hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),"aria-label":a(`projectActions.actions.openPreview`),children:(0,$.jsx)(Z,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(Ga,{children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(r?`inline-flex h-full w-8 items-center justify-center`:`inline-flex h-full w-7 items-center justify-center`,`border-l border-[var(--interactive-border)] text-muted-foreground`,`hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),"aria-label":a(`projectActions.actions.chooseActionAria`),children:(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4`})})}),(0,$.jsxs)(Ia,{align:`start`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(za,{}),oe.map(e=>{let t=e.icon||`play`,n=e.id===Zl?`search`:$c[t]||`play`,r=el(U,e.id),i=E[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(Z,{name:n,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground truncate`,children:e.name}),o||i?.status===`waiting-for-preview`?(0,$.jsx)(Z,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(Z,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]})};function ru(e){return e.isOpen&&e.activeTab===e.targetTab?{open:!1,tab:e.activeTab}:{open:!0,tab:e.targetTab}}var iu=`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`,au=`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`,ou=Q.memo(function(e){let t=(0,pl.c)(17),{visible:n,title:r,ariaLabel:i,onClick:a,className:o,Icon:s,iconClassName:c,pressed:l}=e,u=n===void 0||n,d=l!==void 0&&l;if(!u)return null;let f=o??iu,p=d&&`bg-interactive-selection text-interactive-selection-foreground`,m;t[0]!==f||t[1]!==p?(m=J(f,p),t[0]=f,t[1]=p,t[2]=m):m=t[2];let h=c??`h-[18px] w-[18px]`,g;t[3]!==s||t[4]!==h?(g=(0,$.jsx)(Z,{name:s,className:h}),t[3]=s,t[4]=h,t[5]=g):g=t[5];let _;t[6]!==i||t[7]!==a||t[8]!==d||t[9]!==m||t[10]!==g?(_=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a,"aria-label":i,"aria-pressed":d,className:m,children:g})}),t[6]=i,t[7]=a,t[8]=d,t[9]=m,t[10]=g,t[11]=_):_=t[11];let v;t[12]===r?v=t[13]:(v=(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:r})}),t[12]=r,t[13]=v);let y;return t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(pa,{children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16],y}),su=Q.memo(function(e){let t=(0,pl.c)(42),{isMobile:n,githubAuthStatus:r,githubAccounts:i,githubAvatarUrl:a,githubLogin:o,isSwitchingGitHubAccount:s,handleGitHubAccountSwitch:c}=e,{t:l}=Tt();if(!r?.connected||n)return null;if(i.length>1){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=J(iu,`h-6 w-6 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0`),t[0]=e):e=t[0];let n;t[1]!==o||t[2]!==l?(n=o?l(`header.github.connectedWithLogin`,{login:o}):l(`header.github.connected`),t[1]=o,t[2]=l,t[3]=n):n=t[3];let r;t[4]!==a||t[5]!==o||t[6]!==l?(r=a?(0,$.jsx)(`img`,{src:a,alt:o?l(`header.github.avatarWithLogin`,{login:o}):l(`header.github.avatar`),className:`h-full w-full object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(Z,{name:`github-fill`,className:`h-3.5 w-3.5 text-foreground`}),t[4]=a,t[5]=o,t[6]=l,t[7]=r):r=t[7];let u;t[8]!==s||t[9]!==n||t[10]!==r?(u=(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:e,title:n,disabled:s,children:r})}),t[8]=s,t[9]=n,t[10]=r,t[11]=u):u=t[11];let d;t[12]===l?d=t[13]:(d=l(`header.github.accountsTitle`),t[12]=l,t[13]=d);let f;t[14]===d?f=t[15]:(f=(0,$.jsx)(Ha,{className:`typography-ui-header font-semibold text-foreground`,children:d}),t[14]=d,t[15]=f);let p;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(za,{}),t[16]=p):p=t[16];let m;if(t[17]!==i||t[18]!==c||t[19]!==s||t[20]!==l){let e;t[22]!==c||t[23]!==s||t[24]!==l?(e=e=>{let t=e.user,n=!!e.current,r=e.source===`gh-cli`?l(`header.github.accountSource.cli`):l(`header.github.accountSource.oauth`);return(0,$.jsxs)(ka,{className:`gap-2`,disabled:s,onSelect:()=>{n||c(e.id)},children:[t?.avatarUrl?(0,$.jsx)(`img`,{src:t.avatarUrl,alt:t.login?l(`header.github.avatarWithLogin`,{login:t.login}):l(`header.github.avatar`),className:`h-6 w-6 rounded-full border border-border/60 bg-muted object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(`div`,{className:`flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted`,children:(0,$.jsx)(Z,{name:`github-fill`,className:`h-3 w-3 text-muted-foreground`})}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:t?.name?.trim()||t?.login||`GitHub`}),t?.login?(0,$.jsxs)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:t.login}),(0,$.jsx)(`span`,{className:`mx-1 opacity-50`,children:`·`}),(0,$.jsx)(`span`,{children:r})]}):null]}),n?(0,$.jsx)(Z,{name:`check`,className:`h-4 w-4 text-primary`}):null]},e.id)},t[22]=c,t[23]=s,t[24]=l,t[25]=e):e=t[25],m=i.map(e),t[17]=i,t[18]=c,t[19]=s,t[20]=l,t[21]=m}else m=t[21];let h;t[26]!==f||t[27]!==m?(h=(0,$.jsxs)(Ia,{align:`end`,className:`w-64`,children:[f,p,m]}),t[26]=f,t[27]=m,t[28]=h):h=t[28];let g;return t[29]!==u||t[30]!==h?(g=(0,$.jsxs)(Ga,{children:[u,h]}),t[29]=u,t[30]=h,t[31]=g):g=t[31],g}let u;t[32]!==o||t[33]!==l?(u=o?l(`header.github.connectedWithLogin`,{login:o}):l(`header.github.connected`),t[32]=o,t[33]=l,t[34]=u):u=t[34];let d;t[35]!==a||t[36]!==o||t[37]!==l?(d=a?(0,$.jsx)(`img`,{src:a,alt:o?l(`header.github.avatarWithLogin`,{login:o}):l(`header.github.avatar`),className:`h-full w-full object-cover`,loading:`lazy`,referrerPolicy:`no-referrer`}):(0,$.jsx)(Z,{name:`github-fill`,className:`h-3.5 w-3.5 text-foreground`}),t[35]=a,t[36]=o,t[37]=l,t[38]=d):d=t[38];let f;return t[39]!==u||t[40]!==d?(f=(0,$.jsx)(`div`,{className:`app-region-no-drag flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80`,title:u,children:d}),t[39]=u,t[40]=d,t[41]=f):f=t[41],f}),cu=Q.memo(function(e){let t=(0,pl.c)(55),{isDesktopApp:n,currentInstanceSupportsUpdate:r,isDesktopServicesOpen:i,setIsDesktopServicesOpen:a,refreshCurrentInstanceLabel:o,desktopServicesTab:s,setDesktopServicesTab:c,fetchAllQuotas:l,servicesTabItems:u,quotaLastUpdated:d,quotaDisplayMode:f,quotaDisplayTabItems:p,handleDisplayModeChange:m,handleUsageRefresh:h,isQuotaLoading:g,isUsageRefreshSpinning:_,hasRateLimits:v,rateLimitGroups:y,expandedFamilies:b,toggleFamilyExpanded:x,remoteUpdateInfo:S,remoteUpdateChecking:C,remoteUpdateError:w,onOpenRemoteUpdate:T,showPredValues:E,timeFormatPreference:D,anchorRef:O}=e,{t:k}=Tt(),A;t[0]!==s||t[1]!==l||t[2]!==d||t[3]!==o||t[4]!==a?(A=e=>{a(e),e&&(o(),s===`usage`&&d===null&&l())},t[0]=s,t[1]=l,t[2]=d,t[3]=o,t[4]=a,t[5]=A):A=t[5];let j;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-hidden":!0,tabIndex:-1,className:`pointer-events-none absolute h-px w-px overflow-hidden opacity-0`})}),t[6]=j):j=t[6];let M;t[7]!==l||t[8]!==d||t[9]!==c?(M=e=>{let t=e;c(t),t===`usage`&&d===null&&l()},t[7]=l,t[8]=d,t[9]=c,t[10]=M):M=t[10];let N;t[11]!==s||t[12]!==u||t[13]!==M?(N=(0,$.jsx)(`div`,{className:`sticky top-0 z-20 px-2 pt-1.5 pb-px`,children:(0,$.jsx)(`div`,{className:`h-9`,children:(0,$.jsx)(as,{items:u,activeId:s,onSelect:M,layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,activePillButtonClassName:`h-8`,className:`h-full`})})}),t[11]=s,t[12]=u,t[13]=M,t[14]=N):N=t[14];let P;t[15]!==r||t[16]!==s||t[17]!==n||t[18]!==i||t[19]!==T||t[20]!==C||t[21]!==w||t[22]!==S||t[23]!==a||t[24]!==k?(P=n&&s===`instance`?(0,$.jsxs)(`div`,{children:[r?(0,$.jsx)(`div`,{className:`border-b border-[var(--interactive-border)] px-4 py-2.5`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground`,children:k(`header.services.remoteUpdate.title`)}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:S?.available?k(`header.services.remoteUpdate.available`,{version:S.version||``}):C?k(`header.services.remoteUpdate.checking`):w||k(`header.services.remoteUpdate.upToDate`)})]}),S?.available?(0,$.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:T,children:k(`header.services.remoteUpdate.actions.open`)}):null]})}):null,(0,$.jsx)(ni,{embedded:!0,open:i&&s===`instance`,onOpenChange:mu,onHostSwitched:()=>a(!1)})]}):null,t[15]=r,t[16]=s,t[17]=n,t[18]=i,t[19]=T,t[20]=C,t[21]=w,t[22]=S,t[23]=a,t[24]=k,t[25]=P):P=t[25];let F;t[26]!==s||t[27]!==i?(F=s===`mcp`?(0,$.jsx)(Oc,{active:i&&s===`mcp`}):null,t[26]=s,t[27]=i,t[28]=F):F=t[28];let I;t[29]!==s||t[30]!==b||t[31]!==m||t[32]!==h||t[33]!==v||t[34]!==g||t[35]!==_||t[36]!==f||t[37]!==p||t[38]!==d||t[39]!==y||t[40]!==E||t[41]!==k||t[42]!==D||t[43]!==x?(I=s===`usage`?(0,$.jsxs)(`div`,{className:`overflow-x-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold text-foreground`,children:k(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:uu(d,D)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`div`,{className:`h-7 w-[10.5rem]`,children:(0,$.jsx)(as,{items:p,activeId:f,onSelect:e=>void m(e),layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,className:`h-full`})}),(0,$.jsx)(`button`,{type:`button`,className:J(`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:h,disabled:g||_,"aria-label":k(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(Z,{name:`refresh`,className:J(`h-4 w-4`,_&&`animate-spin`)})})]})]}),v?null:(0,$.jsx)(`div`,{className:`px-4 py-5 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:k(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`space-y-2 px-3 py-2.5`,children:y.map(e=>{let t=b[e.providerId]??[];return(0,$.jsxs)(`div`,{className:`min-w-0 rounded-xl bg-[var(--surface-muted)] p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pb-2`,children:[(0,$.jsx)(Xi,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??k(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[e.entries.map(t=>{let[n,r]=t,i=f===`remaining`?r.remainingPercent:r.usedPercent,a=r.disablePace?null:Sa(r.usedPercent,r.resetAt,r.windowSeconds,n),o=a?.dailyAllocationPercent==null?null:f===`remaining`?100-ga(a.elapsedRatio):ga(a.elapsedRatio),s=La(r.valueLabel,i),c=ma(r.resetAt,r.resetAfterFormatted??r.resetAtFormatted,D);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground break-words`,children:xa(r.label??n)}),c?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:c}):null]}),(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(ks,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&E?(0,$.jsx)(Cs,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)}),e.modelFamilies&&e.modelFamilies.length>0?(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(n=>{let r=n.familyId??`other`,i=t.includes(r);return(0,$.jsxs)(Xc,{open:i,onOpenChange:()=>x(e.providerId,r),children:[(0,$.jsxs)(Yc,{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:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:n.familyLabel}),i?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(Jc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:n.models.map(t=>{let[n,r]=t,i=f===`remaining`?r.remainingPercent:r.usedPercent,a=Sa(r.usedPercent,r.resetAt,r.windowSeconds),o=a?.dailyAllocationPercent==null?null:f===`remaining`?100-ga(a.elapsedRatio):ga(a.elapsedRatio),s=La(r.valueLabel,i);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:As(n)}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(ks,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&E?(0,$.jsx)(Cs,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)})})})]},r)})}):null]})]},e.providerId)})})]}):null,t[29]=s,t[30]=b,t[31]=m,t[32]=h,t[33]=v,t[34]=g,t[35]=_,t[36]=f,t[37]=p,t[38]=d,t[39]=y,t[40]=E,t[41]=k,t[42]=D,t[43]=x,t[44]=I):I=t[44];let L;t[45]!==O||t[46]!==N||t[47]!==P||t[48]!==F||t[49]!==I?(L=(0,$.jsxs)(Ia,{anchor:O,align:`start`,sideOffset:6,collisionPadding:12,className:`w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0`,children:[N,P,F,I]}),t[45]=O,t[46]=N,t[47]=P,t[48]=F,t[49]=I,t[50]=L):L=t[50];let R;return t[51]!==i||t[52]!==A||t[53]!==L?(R=(0,$.jsxs)(Ga,{open:i,onOpenChange:A,children:[j,L]}),t[51]=i,t[52]=A,t[53]=L,t[54]=R):R=t[54],R}),lu=(e,t)=>e===t?!0:!e||!t?!1:e.totalTokens===t.totalTokens&&e.pending===t.pending&&e.percentage===t.percentage&&e.contextLimit===t.contextLimit&&(e.outputLimit??0)===(t.outputLimit??0)&&(e.normalizedOutput??0)===(t.normalizedOutput??0)&&e.thresholdLimit===t.thresholdLimit&&(e.lastMessageId??``)===(t.lastMessageId??``),uu=(e,t)=>{if(!e)return`-`;try{return ba(e,t,{fallback:`-`})}catch{return`-`}},du=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},fu=e=>!e?.isOpen||!Array.isArray(e.tabs)||e.tabs.length===0?null:(e.tabs.find(t=>t.id===e.activeTabId)??e.tabs[e.tabs.length-1])?.mode??null,pu=({onToggleLeftDrawer:e,onToggleRightDrawer:n,leftDrawerOpen:r,rightDrawerOpen:i})=>{let{t:a}=Tt(),o=q(e=>e.setSessionSwitcherOpen),s=q(e=>e.toggleSidebar),c=q(e=>e.isSidebarOpen),l=q(e=>e.toggleBottomTerminal),u=q(e=>e.toggleRightSidebar),d=q(e=>e.openContextOverview),f=q(e=>e.openContextBrowser),p=q(e=>e.openContextPanelTab),h=q(e=>e.closeContextPanel),g=q(e=>e.contextPanelByDirectory),y=q(e=>e.activeMainTab),x=q(e=>e.setActiveMainTab),S=q(e=>e.shortcutOverrides),C=q(e=>e.timeFormatPreference),w=Qn(e=>e.getCurrentModel),T=at(),E=Sn(e=>!!e.newSessionDraft?.open),O=Sn(e=>e.currentSessionId),k=zn(O??``),M=un(O),N=jn(e=>e.activeProjectId?e.projects.find(t=>t.id===e.activeProjectId)??null:null),P=Q.useMemo(()=>{if(!N)return null;let e=N.path.split(/[\\/]/).filter(Boolean);return e[e.length-1]??null},[N]),I=Ts(e=>e.results),L=Ts(e=>e.fetchAllQuotas),z=Ts(e=>e.isLoading),B=Ts(e=>e.lastUpdated),V=Ts(e=>e.displayMode),ee=Ts(e=>e.showPredValues),H=Ts(e=>e.dropdownProviderIds),ne=Ts(e=>e.loadSettings),re=Ts(e=>e.setDisplayMode),{isMobile:U}=no(),ie=ya().data??null,G=Ps(e=>e.setStatus),le=Q.useRef(null),[ue,de]=Q.useState(()=>typeof window>`u`?!1:F()),fe=Q.useMemo(()=>D(),[]),pe=ue&&A()===`win32`,me=ro(),[he,ge]=Q.useState(!1),_e=Q.useMemo(()=>typeof navigator>`u`?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||``),[]),{usesFramelessChrome:ve,side:ye}=Bs(),be=Q.useMemo(()=>{if(typeof window>`u`)return null;let e=window.__YURI_MACOS_MAJOR__;if(typeof e==`number`&&Number.isFinite(e)&&e>0)return e;if(typeof navigator>`u`)return null;let t=(navigator.userAgent||``).match(/Mac OS X (\d+)[._](\d+)/);if(!t)return null;let n=Number.parseInt(t[1],10),r=Number.parseInt(t[2],10);return Number.isNaN(n)?null:n===10?r:n},[]);(0,Q.useEffect)(()=>{typeof window>`u`||de(F())},[]);let xe=w(),Se=xe&&typeof xe.limit==`object`&&xe.limit!==null?xe.limit:null,Ce=Se&&typeof Se.context==`number`?Se.context:0,we=Se&&typeof Se.output==`number`?Se.output:0,Te=Jn(O??``,Ce,we),Ee=E?null:Te,[De,Oe]=Q.useState(null),ke=!O||k;(0,Q.useEffect)(()=>{if(!O){Oe(e=>e===null?e:null);return}if(Ee){Oe(e=>lu(e,Ee)?e:Ee);return}ke&&Oe(e=>e===null?e:null)},[Ee,O,ke]);let Ae=q(e=>e.isSessionSwitcherOpen),je=ie?.connected?ie.user?.avatarUrl??null:null,Me=ie?.connected?ie.user?.login??null:null,Ne=ie?.accounts??[],[K,Pe]=Q.useState(!1),[Fe,Ie]=Q.useState(!1),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(`Local`),[Ue,We]=Q.useState(!1),[Ge,Ke]=Q.useState(!1),[qe,Je]=Q.useState(null),[Ye,Xe]=Q.useState(!1),[Ze,Qe]=Q.useState(null),[$e,et]=Q.useState(ue?`instance`:`usage`),[tt,nt]=Q.useState(`usage`);(0,Q.useEffect)(()=>{!ue&&$e===`instance`&&et(`usage`)},[$e,ue]);let rt=Q.useMemo(()=>te(),[]),it=q(e=>e.workStatusPanelEnabled),ot=q(e=>e.workStatusPanelFits),st=q(e=>e.workStatusOverlayOpen),ct=q(e=>e.setWorkStatusPanelEnabled),lt=q(e=>e.setWorkStatusOverlayOpen),ut=it&&ot||st,dt=vt(()=>{if(it&&!ot){lt(!st);return}ct(!it)}),ft=!rt&&y===`chat`&&!!De,pt=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,mt=vt(async()=>{if(!(typeof window>`u`||!ue))try{if(v()){He(`Local`),We(!1);return}let e=await se(),t=window.__YURI_LOCAL_ORIGIN__||window.location.origin,n=m();if(n&&ae(n,t)){He(`Local`),We(!1);return}let r=e.hosts.find(e=>n?ae(n,oe(e)):!1);if(r&&!r.relay){let e=await Ea();if(m()!==n)return;We(ce(r,new Set(e.instances.map(e=>e.id))))}else We(!1);if(r?.label?.trim()){He(W(r.label.trim()));return}He(`Instance`)}catch{He(`Local`),We(!1)}});(0,Q.useEffect)(()=>{mt()},[ue]);let ht=vt(async()=>{if(!Ue){Je(null),Qe(null);return}Xe(!0),Qe(null);try{let e=new URLSearchParams({appType:`web`,instanceMode:`remote`}),t=await _(`/api/yuri/update-check?${e.toString()}`,{method:`GET`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(`Server responded with ${t.status}`);let n=await t.json();Je({available:n.available??!1,version:n.version,currentVersion:n.currentVersion??`unknown`,body:n.body,nextSuggestedCheckInSec:typeof n.nextSuggestedCheckInSec==`number`?n.nextSuggestedCheckInSec:void 0,packageManager:n.packageManager,updateCommand:n.updateCommand})}catch(e){Je(null),Qe(e instanceof Error?e.message:a(`header.services.remoteUpdate.error`))}finally{Xe(!1)}});Q.useEffect(()=>{Je(null),Qe(null),Ke(!1)},[Ue,Ve]),Q.useEffect(()=>{if(!ue||!Ue)return;let e=36e5,t=!1,n=null,r=i=>{n=window.setTimeout(()=>{if(t||typeof document<`u`&&document.visibilityState!==`visible`){r(e);return}ht().finally(()=>{t||r(e)})},i)};return r(3e3),()=>{t=!0,n!==null&&window.clearTimeout(n)}},[Ue,Ve,ue]);let gt=vt(()=>{if(Ue){if(qe?.available){Ke(!0);return}ht()}});ws();let _t=Ts(e=>e.selectedModels),yt=Ts(e=>e.expandedFamilies),bt=Ts(e=>e.toggleFamilyExpanded),xt=Q.useMemo(()=>{let e=[];for(let t of ls(I)){if(!H.includes(t.id))continue;let n=I.find(e=>e?.providerId===t.id),r=n?.usage?.windows??{},i=n?.usage?.models,o=Object.entries(r),s={providerId:t.id,providerName:t.name,entries:o,error:n&&!n.ok&&n.configured?n.error:void 0};if(i&&Object.keys(i).length>0){let e=_t[t.id]??[],n=e.length>0,r=Es(i,t.id),o=Ns(t.id),c=bs(o);s.modelFamilies=[];for(let t of c){let a=r.get(t.id)??[];if(a.length===0)continue;let o=n?a.filter(t=>e.includes(t)):a;if(o.length===0)continue;let c=[];for(let e of o){let t=i[e];if(t?.windows){let n=Object.entries(t.windows);n.length>0&&c.push([e,n[0][1]])}}c.length>0&&s.modelFamilies.push({familyId:t.id,familyLabel:t.label,models:c})}let l=r.get(null)??[],u=n?l.filter(t=>e.includes(t)):l;if(u.length>0){let e=[];for(let t of u){let n=i[t];if(n?.windows){let r=Object.entries(n.windows);r.length>0&&e.push([t,r[0][1]])}}e.length>0&&s.modelFamilies.push({familyId:null,familyLabel:a(`header.services.modelFamily.other`),models:e})}}(o.length>0||s.modelFamilies&&s.modelFamilies.length>0||s.error)&&e.push(s)}return e},[H,I,_t,a]),St=xt.length>0;Q.useEffect(()=>{ne()},[ne]);let wt=Q.useCallback(async e=>{re(e);try{await R({usageDisplayMode:e})}catch(e){console.warn(`Failed to update usage display mode:`,e)}},[re]),Et=Q.useCallback(()=>{if(ze)return;Be(!0);let e=new Promise(e=>setTimeout(e,500));Promise.all([L(),e]).finally(()=>{Be(!1)})},[L,ze]),Dt=Sn(e=>O?e.worktreeMetadata.get(O)?.path??``:``),Ot=Q.useMemo(()=>du(Dt||``),[Dt]),kt=Q.useMemo(()=>du((typeof M?.directory==`string`?M.directory:``)||``),[M?.directory]),At=Sn(e=>e.newSessionDraft?.open?du(e.newSessionDraft.bootstrapPendingDirectory??e.newSessionDraft.directoryOverride??``):``),jt=Q.useMemo(()=>Ot||kt||At,[At,kt,Ot]),Mt=es(),Nt=Q.useMemo(()=>du(Mt||jt||N?.path||``),[N?.path,Mt,jt]),Y=Q.useMemo(()=>{if(!O)return P??`Yuri`;let e=M?.title?.trim();return e&&e.length>0?e:`Untitled Session`},[P,M?.title,O]),Pt=Q.useMemo(()=>du(jt||N?.path||``),[N?.path,jt]),Ft=Q.useMemo(()=>N?{id:N.id,path:N.path}:null,[N]),It=Q.useRef(null);Q.useEffect(()=>{!Ft||!Pt||(It.current={projectRef:Ft,directory:Pt})},[Pt,Ft]);let Lt=Q.useMemo(()=>Ft&&Pt?{projectRef:Ft,directory:Pt}:It.current,[Pt,Ft]),Rt=Q.useCallback(async e=>{if(!(!e||K)){Pe(!0);try{let t=T.github?await T.github.authActivate(e):await(async()=>{let t=await _(`/api/github/auth/activate`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({accountId:e})}),n=await t.json().catch(()=>null);if(!t.ok||!n)throw Error(n?.error||t.statusText);return n})();G(t)}catch(e){console.error(`Failed to switch GitHub account:`,e)}finally{Pe(!1)}}},[K,T.github,G]),zt=Q.useCallback(()=>{if(typeof document>`u`)return;let e=document.activeElement;if(!e)return;let t=e.tagName;(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)&&e.blur()},[]),Bt=Q.useCallback(()=>{if(U){zt(),o(!Ae);return}s()},[zt,U,Ae,o,s]),Vt=Q.useCallback(()=>{j(`desktop_open_draft_mini_chat_window`,{directory:du(jt||N?.path||``),projectId:N?.id??null,apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open draft mini chat window`,e)})},[N?.id,N?.path,jt]),Ht=Q.useCallback(()=>{if(E){Vt();return}O&&j(`desktop_open_session_mini_chat_window`,{sessionId:O,directory:du(jt||N?.path||``),apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open session mini chat window`,e)})},[N?.path,O,Vt,E,jt]),Ut=Q.useCallback(()=>{let e=Nt;if(!e)return;let t=g[e];if(fu(t)===`context`){h(e);return}d(e)},[h,Nt,g,d]),Wt=Q.useMemo(()=>{let e=Nt;if(!e)return!1;let t=g[e];return fu(t)===`context`},[Nt,g]),Gt=Q.useCallback(()=>{let e=Nt;if(!e)return;let t=g[e];if(fu(t)===`diff`){h(e);return}p(e,{mode:`diff`,stagedDiff:!1})},[h,Nt,g,p]),Kt=Q.useCallback(()=>{let e=Nt;if(!e)return;let t=g[e];if(fu(t)===`browser`){h(e);return}f(e)},[h,Nt,g,f]),qt=Q.useMemo(()=>{let e=Nt;if(!e)return!1;let t=g[e];return fu(t)===`browser`},[Nt,g]),Jt=iu,Yt=au,Xt=Q.useMemo(()=>Fe?`services`:r?`sessions`:i?`git`:y,[y,Fe,r,i]),Zt=Q.useCallback(()=>{Ie(!1),r&&e&&e(),i&&n&&n(),!e&&Ae&&o(!1)},[Ae,r,e,n,i,o]),Qt=Q.useCallback(()=>{r||Ie(!1),e?.()},[r,e]),$t=Q.useCallback(()=>{i||Ie(!1),n?.()},[n,i]),en=Q.useMemo(()=>ue&&_e&&!he?`5.5rem`:me?`max(calc(0.75rem + var(--yuri-wco-left-inset, 0px)), 5.5rem)`:(!ue||ve)&&!rt?`calc(0.75rem + var(--yuri-wco-left-inset, 0px))`:`0.75rem`,[ue,he,_e,me,rt,ve]);(0,Q.useEffect)(()=>{typeof document>`u`||document.documentElement.style.setProperty(`--yuri-titlebar-left-inset`,en)},[en]);let tn=c?`0.75rem`:`var(--yuri-titlebar-left-inset, 0.75rem)`,nn=c?`0px`:`calc(var(--yuri-titlebar-controls-width, 5.5rem) + 0.5rem)`;(0,Q.useEffect)(()=>{if(!ue||!_e){ge(!1);return}let e=!1,t=async()=>{try{let t=await j(`desktop_is_window_fullscreen`);e||ge(t===!0)}catch{e||ge(!1)}},n=()=>{t()};return t(),window.addEventListener(`yuri:window-resized`,n),()=>{e=!0,window.removeEventListener(`yuri:window-resized`,n)}},[ue,_e]);let rn=Q.useMemo(()=>!ue||!_e||be===null?``:be>=26?`h-12`:be<=15?`h-14`:``,[ue,_e,be]),X=Q.useMemo(()=>{if(!(ue&&!ve||rt))return{paddingRight:`calc(0.75rem + var(--yuri-wco-right-inset, 0px))`,minHeight:`max(3rem, var(--yuri-wco-titlebar-height, 0px))`,height:`max(3rem, var(--yuri-wco-titlebar-height, 0px))`}},[ue,rt,ve]),an=Q.useCallback(()=>{if(typeof document>`u`)return;let e=le.current?.getBoundingClientRect().height;e&&document.documentElement.style.setProperty(`--yuri-header-height`,`${e}px`)},[]);(0,Q.useEffect)(()=>{if(typeof window>`u`)return;an();let e=le.current;if(!e||typeof ResizeObserver>`u`)return()=>{};let t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,an()})},r=new ResizeObserver(n);return r.observe(e),window.addEventListener(`resize`,n),window.addEventListener(`orientationchange`,n),()=>{t&&cancelAnimationFrame(t),r.disconnect(),window.removeEventListener(`resize`,n),window.removeEventListener(`orientationchange`,n)}},[an]),(0,Q.useEffect)(()=>{an()},[an,U,rn]);let on=Q.useCallback(async e=>{let t=e.target;t.closest(`.app-region-no-drag`)||t.closest(`button, a, input, select, textarea`)||e.button===0&&ue&&await b()},[ue]),sn=Q.useMemo(()=>{if(U){let e=[{id:`chat`,label:a(`layout.mainTab.chat`),icon:`chat-thread`}];return e.push({id:`diff`,label:a(`layout.mainTab.diff`),icon:`diff`},{id:`files`,label:a(`layout.mainTab.files`),icon:`folder-6`},{id:`terminal`,label:a(`layout.mainTab.terminal`),icon:`terminal-box`},{id:`diagram`,label:a(`layout.mainTab.diagram`),icon:`file`}),e}return[]},[U,a]),cn=Q.useCallback(e=>Ba(Pa(e,S)),[S]);(0,Q.useEffect)(()=>{!U&&(y===`git`||y===`terminal`||y===`diff`||y===`files`)&&x(`chat`)},[y,U,x]);let ln=Q.useMemo(()=>{let e=[];return ue&&e.push({value:`instance`,label:a(`layout.services.instance`),icon:(0,$.jsx)(Z,{name:`server`,className:`h-3.5 w-3.5`})}),e.push({value:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`})},{value:`mcp`,label:`MCP`,icon:(0,$.jsx)(_s,{className:`h-3.5 w-3.5`})}),e},[ue,a]),dn=Q.useMemo(()=>ln.map(e=>({id:e.value,label:e.label,icon:e.icon})),[ln]),fn=Q.useMemo(()=>[{value:`usage`,label:a(`header.services.used`)},{value:`remaining`,label:a(`header.services.remaining`)}],[a]),pn=Q.useMemo(()=>fn.map(e=>({id:e.value,label:e.label})),[fn]),mn=Q.useMemo(()=>[{id:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`})},{id:`mcp`,label:`MCP`,icon:(0,$.jsx)(_s,{className:`h-3.5 w-3.5`})}],[a]);(0,Q.useEffect)(()=>{let e=e=>{if(Ct(e)&&!e.shiftKey&&!e.altKey){let t=parseInt(e.key,10);t>=1&&t<=sn.length&&(e.preventDefault(),U&&(zt(),Zt()),x(sn[t-1].id))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[zt,Zt,U,x,sn]);let hn=vt(e=>{et(e),Re(!0),mt(),e===`usage`&&B===null&&L()});(0,Q.useEffect)(()=>{let e=e=>{let t=Pa(`toggle_services_menu`,S);if(Ma(e,t)){e.preventDefault();let t=ru({isOpen:Le,activeTab:$e,targetTab:ue?`instance`:`usage`});t.open?hn(t.tab):Re(!1);return}let n=Pa(`cycle_services_tab`,S);if(Ma(e,n)){e.preventDefault();let t=ln.map(e=>e.value);if(t.length===0)return;let n=t.indexOf($e),r=t[n===-1?0:(n+1)%t.length];et(r),Re(!0),mt(),r===`usage`&&B===null&&L();return}let r=Pa(`open_usage`,S);if(Ma(e,r)){e.preventDefault();let t=ru({isOpen:Le,activeTab:$e,targetTab:`usage`});t.open?hn(t.tab):Re(!1);return}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,ue,Le,$e,ln,B,L,mt,hn]);let gn=e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon,i=e.id===`chat`,a=e=>n?(0,$.jsx)(ml,{size:e}):r?(0,$.jsx)(Z,{name:r,className:`h-${e/4} w-${e/4}`}):null,o=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(e.id),className:J(`relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors`,t?`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`,i&&!U&&`min-w-[100px] justify-center`),"aria-label":e.label,"aria-selected":t,role:`tab`,children:[U?a(20):(0,$.jsxs)($.Fragment,{children:[a(16),(0,$.jsx)(`span`,{className:`header-tab-label`,children:e.label})]}),e.badge!==void 0&&e.badge>0&&(0,$.jsx)(`span`,{className:`header-tab-badge typography-micro text-status-info font-medium`,children:e.badge})]});return(0,$.jsx)(Q.Fragment,{children:o},e.id)},_n=fe&&(E||!!O),vn=Q.useCallback(e=>{window.setTimeout(e,0)},[]),yn=Q.useCallback(e=>{hn(e)},[hn]),bn=Q.useRef(null),xn=(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,children:[(0,$.jsx)(`div`,{ref:bn,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center`,children:(0,$.jsxs)(Ga,{children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.actions.sessionMenuAria`),className:J(Jt,`text-muted-foreground`),children:(0,$.jsx)(Z,{name:`more-2`,className:`h-[18px] w-[18px]`})})})}),(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:a(`header.actions.sessionMenu`)})})]}),(0,$.jsxs)(Ia,{align:`start`,className:`min-w-[14rem]`,children:[rt?null:(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(Gt),children:[(0,$.jsx)(Z,{name:`layout-column`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.toggleChangesPanel`)})]}),_n?(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(Ht),children:[(0,$.jsx)(Z,{name:`picture-in-picture-2`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(E?`header.actions.newMiniChat`:`header.actions.openSessionMiniChat`)})]}):null,ue?(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(()=>yn(`instance`)),children:[(0,$.jsx)(Z,{name:`stack`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a(`header.actions.sessionMenu.servicesWithInstance`,{current:Ve})}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`toggle_services_menu`)})]}):null,(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(()=>yn(`usage`)),children:[(0,$.jsx)(Z,{name:`timer`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.sessionMenu.viewUsage`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`open_usage`)})]}),(0,$.jsx)(za,{}),(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(l),children:[(0,$.jsx)(Z,{name:`terminal-box`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.toggleTerminalPanel`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:cn(`toggle_terminal`)})]}),(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>vn(Kt),children:[(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`contextPanel.browser.open`)}),qt?(0,$.jsx)(Z,{name:`check`,className:`h-3.5 w-3.5 text-foreground`}):null]})]})]})}),(0,$.jsx)(cu,{isDesktopApp:ue,currentInstanceSupportsUpdate:Ue,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Re,refreshCurrentInstanceLabel:mt,desktopServicesTab:$e,setDesktopServicesTab:et,fetchAllQuotas:L,servicesTabItems:dn,quotaLastUpdated:B,quotaDisplayMode:V,showPredValues:ee,quotaDisplayTabItems:pn,handleDisplayModeChange:wt,handleUsageRefresh:Et,isQuotaLoading:z,isUsageRefreshSpinning:ze,hasRateLimits:St,rateLimitGroups:xt,expandedFamilies:yt,toggleFamilyExpanded:bt,remoteUpdateInfo:qe,remoteUpdateChecking:Ye,remoteUpdateError:Ze,onOpenRemoteUpdate:gt,timeFormatPreference:C,anchorRef:bn})]}),Cn=(0,$.jsxs)($.Fragment,{children:[!U&&!rt&&y===`chat`?(0,$.jsx)(`button`,{type:`button`,"data-work-status-toggle":`true`,"aria-pressed":ut,"aria-label":a(`header.workStatusPanel.toggleAria`),title:a(`header.workStatusPanel.toggleAria`),onClick:dt,className:J(`app-region-no-drag group inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors`,ut?`text-foreground`:`text-muted-foreground/50`),children:(0,$.jsx)(Z,{name:`settings-2`,className:`size-4`})}):null,(0,$.jsx)(Ll,{directory:Pt}),(0,$.jsx)(ou,{title:a(`header.actions.rightSidebarWithShortcut`,{shortcut:cn(`toggle_right_sidebar`)}),ariaLabel:a(`header.actions.toggleRightSidebarAria`),onClick:u,className:`app-region-no-drag group inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover hover:text-foreground transition-colors`,Icon:`layout-left-rounded`,iconClassName:`size-4 -scale-x-100 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),(0,$.jsx)(su,{isMobile:U,githubAuthStatus:ie,githubAccounts:Ne,githubAvatarUrl:je,githubLogin:Me,isSwitchingGitHubAccount:K,handleGitHubAccountSwitch:Rt})]}),wn=()=>(0,$.jsxs)(`div`,{onMouseDown:on,className:J(`app-region-drag relative flex h-12 select-none items-center pr-3`,rn),style:X,role:`tablist`,"aria-label":a(`header.navigation.mainAria`),children:[(0,$.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:tn}}),(0,$.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:nn}}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,$.jsxs)(`div`,{className:`app-region-no-drag mr-3 flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Rs,{children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`sessions.switcher.openAria`),className:`inline-flex h-8 min-w-0 max-w-full items-center rounded-md px-2.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-primary`,children:(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground`,children:E?a(`sessions.switcher.draftTitle`):Y})})}),xn]}),sn.length>0&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1`,children:sn.map(e=>gn(e))}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[ft&&De?(0,$.jsx)(Ls,{pending:De.pending,totalTokens:De.totalTokens,percentage:pt,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:`compact`,appearance:`subtle`,onClick:Ut,pressed:Wt}):null,Cn,(0,$.jsx)(zs,{visible:ve&&ye===`right`,position:`right`})]})]})]}),Tn=()=>(0,$.jsxs)(`div`,{className:`app-region-drag relative flex items-center gap-2 px-3 py-2 select-none`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e?(0,$.jsx)(`button`,{type:`button`,onClick:Qt,className:J(Yt,Xt===`sessions`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":a(r?`header.actions.closeSessionsAria`:`header.actions.openSessionsAria`),children:(0,$.jsx)(Z,{name:`layout-left`,className:`h-5 w-5`})}):Ae?(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active`,"aria-label":a(`header.actions.backAria`),children:(0,$.jsx)(Z,{name:`arrow-left-s`,className:`h-5 w-5`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Bt,className:`app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active`,"aria-label":a(`header.actions.openSessionsAria`),children:(0,$.jsx)(Z,{name:`play-list-add`,className:`h-5 w-5`})}),!e&&Ae&&(0,$.jsx)(`span`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`header.sessions.title`)})]}),(!Ae||!!e)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`app-region-no-drag flex min-w-0 flex-1 items-center`,children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain`,children:(0,$.jsx)(`div`,{className:`flex w-max items-center gap-1 pr-1`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5`,role:`tablist`,"aria-label":a(`header.navigation.mainAria`),children:sn.map(e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon;return(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U&&(zt(),Zt()),x(e.id)},"aria-label":e.label,"aria-selected":t,role:`tab`,className:J(Yt,`relative rounded-lg`,Xt===e.id&&`bg-interactive-selection text-interactive-selection-foreground`),children:[n?(0,$.jsx)(ml,{className:`h-5 w-5`}):r?(0,$.jsx)(Z,{name:r,className:`h-5 w-5`}):null,e.badge!==void 0&&e.badge>0&&(0,$.jsx)(`span`,{className:`absolute -top-1 -right-1 text-[10px] font-semibold text-primary`,children:e.badge}),e.showDot&&(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary`,"aria-label":a(`header.changes.availableAria`)})]})}),(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:e.label})})]},e.id)})})})})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[Lt&&(0,$.jsx)(nu,{projectRef:Lt.projectRef,directory:Lt.directory,compact:!0,allowMobile:!0,className:`h-9`}),(0,$.jsxs)(Ga,{open:Fe,onOpenChange:t=>{t&&(r&&e&&e(),i&&n&&n()),Ie(t),t&&B===null&&L()},children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.services.viewAria`),className:J(Yt,Xt===`services`&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(Z,{name:`stack`,className:`h-5 w-5`})})})}),(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:a(`header.services.title`)})})]}),(0,$.jsx)(Ia,{align:`end`,sideOffset:0,positionerClassName:`!fixed !bottom-0 !left-0 !right-0 !top-[var(--yuri-header-height,56px)] !transform-none`,className:`h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`flex h-full flex-col bg-[var(--surface-elevated)]`,children:[(0,$.jsx)(`div`,{className:`sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-0`,children:[(0,$.jsx)(`div`,{className:`h-10 min-w-0 flex-1`,children:(0,$.jsx)(as,{items:mn,activeId:tt,onSelect:e=>{let t=e;nt(t),t===`usage`&&B===null&&L()},layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,activePillButtonClassName:`h-8`,className:`h-full`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Ie(!1),className:`inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover`,"aria-label":a(`header.services.closeAria`),children:(0,$.jsx)(Z,{name:`close`,className:`h-5 w-5`})})]})}),tt===`mcp`&&(0,$.jsx)(Oc,{active:Fe&&tt===`mcp`}),tt===`usage`&&(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]`,children:[(0,$.jsx)(`div`,{className:`border-b border-[var(--interactive-border)]`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col min-w-0 gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-header font-semibold text-foreground`,children:a(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:uu(B,C)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center h-6`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>wt(`usage`),className:J(`typography-ui-label px-1 pb-0.5 transition-colors`,V===`usage`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:a(`header.services.used`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground typography-ui-label px-0.5`,children:`·`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>wt(`remaining`),className:J(`typography-ui-label px-1 pb-0.5 transition-colors`,V===`remaining`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:a(`header.services.remaining`)})]}),(0,$.jsx)(`button`,{type:`button`,className:J(`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:Et,disabled:z||ze,"aria-label":a(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(Z,{name:`refresh`,className:J(`h-4 w-4`,ze&&`animate-spin`)})})]})]})}),!St&&(0,$.jsx)(`div`,{className:`px-4 py-6 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:a(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`py-1`,children:xt.map((e,t)=>(0,$.jsxs)(Q.Fragment,{children:[t>0?(0,$.jsx)(`div`,{className:`mx-4 my-1 border-t border-[var(--interactive-border)]`}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2`,children:[(0,$.jsx)(Xi,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{className:`px-4 pb-2`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??a(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3 px-4 pb-2`,children:[e.entries.map(([t,n])=>{let r=V===`remaining`?n.remainingPercent:n.usedPercent,i=n.disablePace?null:Sa(n.usedPercent,n.resetAt,n.windowSeconds,t),a=i?.dailyAllocationPercent==null?null:V===`remaining`?100-ga(i.elapsedRatio):ga(i.elapsedRatio),o=La(n.valueLabel,r),s=ma(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,C);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground break-words`,children:xa(n.label??t)}),s?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:s}):null]}),(0,$.jsx)(`span`,{className:`shrink-0 whitespace-nowrap typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(ks,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ee?(0,$.jsx)(Cs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)}),e.modelFamilies&&e.modelFamilies.length>0&&(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(t=>{let n=(yt[e.providerId]??[]).includes(t.familyId??`other`);return(0,$.jsxs)(Xc,{open:n,onOpenChange:()=>bt(e.providerId,t.familyId??`other`),children:[(0,$.jsxs)(Yc,{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:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:t.familyLabel}),n?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(Jc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:t.models.map(([t,n])=>{let r=V===`remaining`?n.remainingPercent:n.usedPercent,i=Sa(n.usedPercent,n.resetAt,n.windowSeconds),a=i?.dailyAllocationPercent==null?null:V===`remaining`?100-ga(i.elapsedRatio):ga(i.elapsedRatio),o=La(n.valueLabel,r);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:As(t)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(ks,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ee?(0,$.jsx)(Cs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)})})})]},t.familyId??`other`)})})]})]},e.providerId))})]})]})})]}),n?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:$t,className:J(Yt,`relative`,Xt===`git`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":i?`Close git sidebar`:`Open git sidebar`,children:(0,$.jsx)(Z,{name:`layout-right`,className:`h-5 w-5`})})}),(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:i?`Close git sidebar`:`Open git sidebar`})})]}):null]})]})]}),En=J(`header-safe-area relative z-10 bg-background`,pe&&`bg-[var(--surface-background)] backdrop-blur-none`,U&&`yuri-layout-divider-b`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`header`,{ref:le,className:En,style:{"--padding-scale":`1`},children:U?Tn():wn()}),(0,$.jsx)(ps,{open:Ue&&Ge,onOpenChange:Ke,info:qe,downloading:!1,downloaded:!1,progress:null,error:Ze,onDownload:()=>{},onRestart:()=>{},runtimeType:`web`})]})};function mu(){}var hu=180,gu=640,_u=110,vu=e=>{let t=(0,pl.c)(44),{isOpen:n,isMobile:r,children:i}=e,{t:a}=Tt(),o=q(yu),s=q(bu),c=q(xu),l=q(Su),[u,d]=Q.useState(null),[f,p]=Q.useState(!1),m=Q.useRef(null),h=Q.useRef(0),g=Q.useRef(o||300),_=Math.min(gu,Math.max(hu,o||300)),v,y;t[0]===n?(v=t[1],y=t[2]):(v=()=>{n||(d(null),p(!1))},y=[n],t[0]=n,t[1]=v,t[2]=y),Q.useEffect(v,y);let b,x;t[3]!==s||t[4]!==r||t[5]!==n?(b=()=>{if(r||!n||!s)return;let e=()=>{let e=m.current?.parentElement?.getBoundingClientRect().height;if(!e||e<=0)return;let t=Math.max(0,Math.round(e));d(e=>e===t?e:t)};e();let t=m.current?.parentElement;if(!t)return;let i=new ResizeObserver(e);return i.observe(t),()=>{i.disconnect()}},x=[s,r,n],t[3]=s,t[4]=r,t[5]=n,t[6]=b,t[7]=x):(b=t[6],x=t[7]),Q.useEffect(b,x);let S,C;if(t[8]!==s||t[9]!==r||t[10]!==f||t[11]!==c||t[12]!==l?(S=()=>{if(r||!f||s)return;let e=e=>{let t=h.current-e.clientY,n=Math.min(gu,Math.max(hu,g.current+t));c(n)},t=()=>{p(!1),q.getState().bottomTerminalHeight<=_u&&l(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},C=[s,r,f,c,l],t[8]=s,t[9]=r,t[10]=f,t[11]=c,t[12]=l,t[13]=S,t[14]=C):(S=t[13],C=t[14]),Q.useEffect(S,C),r)return null;let w=n?s?Math.max(0,u??_):_:0,T=n&&s,E;t[15]!==w||t[16]!==s||t[17]!==n?(E=e=>{!n||s||(p(!0),h.current=e.clientY,g.current=w,e.preventDefault())},t[15]=w,t[16]=s,t[17]=n,t[18]=E):E=t[18];let D=E,O=T?`absolute inset-x-0 bottom-0 z-40`:`relative`,k=f?`transition-none`:`transition-[height] duration-300 ease-in-out`,A=(!n||T)&&`border-t-0`,j;t[19]!==A||t[20]!==O||t[21]!==k?(j=J(`flex overflow-hidden border-t border-border bg-sidebar`,O,k,A),t[19]=A,t[20]=O,t[21]=k,t[22]=j):j=t[22];let M;t[23]!==w||t[24]!==T?(M=T?{top:0}:{height:`${w}px`,minHeight:`${w}px`,maxHeight:`${w}px`},t[23]=w,t[24]=T,t[25]=M):M=t[25];let N=!n||!s&&w===0,P;t[26]!==D||t[27]!==s||t[28]!==n||t[29]!==f||t[30]!==a?(P=n&&!s&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,f&&`bg-[var(--interactive-border)]`),onPointerDown:D,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`terminalView.bottomDock.resizeAria`)}),t[26]=D,t[27]=s,t[28]=n,t[29]=f,t[30]=a,t[31]=P):P=t[31];let F=!n&&`pointer-events-none select-none opacity-0`,I;t[32]===F?I=t[33]:(I=J(`relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out`,F),t[32]=F,t[33]=I);let L=!n,R;t[34]!==i||t[35]!==I||t[36]!==L?(R=(0,$.jsx)(`div`,{className:I,"aria-hidden":L,children:i}),t[34]=i,t[35]=I,t[36]=L,t[37]=R):R=t[37];let z;return t[38]!==j||t[39]!==M||t[40]!==N||t[41]!==P||t[42]!==R?(z=(0,$.jsxs)(`section`,{ref:m,className:j,style:M,"aria-hidden":N,children:[P,R]}),t[38]=j,t[39]=M,t[40]=N,t[41]=P,t[42]=R,t[43]=z):z=t[43],z};function yu(e){return e.bottomTerminalHeight}function bu(e){return e.isBottomTerminalExpanded}function xu(e){return e.setBottomTerminalHeight}function Su(e){return e.setBottomTerminalOpen}var Cu=260,wu=260,Tu=500,Eu=({isOpen:e,isMobile:t,children:n,className:r,topBar:i})=>{let{t:a}=Tt(),o=q(e=>e.sidebarWidth),s=q(e=>e.setSidebarWidth),[c,l]=Q.useState(!1),u=Q.useRef(0),d=Q.useRef(o||Cu),f=Q.useRef(null),p=Q.useRef(null),m=Q.useRef(null),h=Q.useCallback(e=>Math.min(Tu,Math.max(wu,e)),[]),g=Q.useCallback(e=>{let t=m.current;t&&(t.style.width=`${e}px`,t.style.minWidth=`${e}px`,t.style.maxWidth=`${e}px`,t.style.setProperty(`--yuri-left-sidebar-width`,`${e}px`))},[]);if(Q.useEffect(()=>{t&&c&&l(!1)},[t,c]),Q.useEffect(()=>{c||(f.current=null,p.current=null)},[c]),t)return null;let _=Math.min(Tu,Math.max(wu,o||Cu)),v=e?_:0,y=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}p.current=t.pointerId,l(!0),u.current=t.clientX,d.current=v,f.current=v,g(v),t.preventDefault()}},b=e=>{if(t||!c||p.current!==e.pointerId)return;let n=e.clientX-u.current,r=h(d.current+n);f.current!==r&&(f.current=r,g(r))},x=e=>{if(p.current!==e.pointerId||t)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let n=h(f.current??v);p.current=null,f.current=null,l(!1),s(n)},S=c?f.current??v:v;return(0,$.jsxs)(`aside`,{ref:m,className:J(`relative flex h-full overflow-hidden yuri-layout-divider-r will-change-[width] motion-reduce:transition-none`,`bg-sidebar yuri-vibrancy-surface`,!e&&`border-r-0`,r),style:{width:`${S}px`,minWidth:`${S}px`,maxWidth:`${S}px`,"--yuri-left-sidebar-width":`${c?S:_}px`,overflowX:`clip`,transitionProperty:c?`none`:`width, min-width, max-width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||v===0,children:[e&&(0,$.jsx)(`div`,{className:J(`absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,c&&`bg-[var(--interactive-border)]`),onPointerDown:y,onPointerMove:b,onPointerUp:x,onPointerCancel:x,role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`sidebar.resize.leftPanelAria`)}),(0,$.jsxs)(`div`,{className:J(`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`,c&&`pointer-events-none`,!e&&`pointer-events-none select-none opacity-0`),style:{width:`var(--yuri-left-sidebar-width)`,overflowX:`hidden`},"aria-hidden":!e,children:[i,(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(ha,{children:n})})]})]})},Du=()=>{let e=(0,pl.c)(3),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={height:`var(--yuri-header-height, 3rem)`},e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-drag shrink-0`,style:{width:`var(--yuri-titlebar-left-inset, 0.75rem)`}}),e[1]=n):n=e[1];let r;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsxs)(`div`,{className:`flex shrink-0`,style:t,children:[n,(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-no-drag shrink-0`,style:{width:`calc(var(--yuri-titlebar-controls-width, 5.5rem) + 0.5rem)`}}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-drag flex-1`})]}),e[2]=r):r=e[2],r},Ou=e=>{let t=(0,pl.c)(10),{className:n}=e,r=xs(ku).trim().split(/\s+/).filter(Boolean),i=r.some(Au);if(Q.useEffect(()=>{i&&Mi()},[i]),r.length===0)return null;let a;t[0]===n?a=t[1]:(a=J(`flex min-w-0 items-center overflow-hidden px-2 pb-2 pt-1`,n),t[0]=n,t[1]=a);let o=r.join(` `),s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s={fontFamily:`"Syne", var(--font-sans, system-ui, sans-serif)`,fontSize:`1.0625rem`,fontWeight:700,letterSpacing:`0.08em`,lineHeight:1},t[2]=s):s=t[2];let c=r.map(ju),l;t[3]!==o||t[4]!==s||t[5]!==c?(l=(0,$.jsx)(`span`,{role:`img`,"aria-label":o,className:`inline-flex min-w-0 items-baseline gap-[0.28em] overflow-hidden whitespace-nowrap text-foreground`,style:s,children:c}),t[3]=o,t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;return t[7]!==a||t[8]!==l?(u=(0,$.jsx)(`div`,{className:a,children:l}),t[7]=a,t[8]=l,t[9]=u):u=t[9],u};function ku(e){return e.sidebarBrandName}function Au(e){return e!==`Yuri`}function ju(e,t){return(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex shrink-0 items-baseline`,children:e===`Yuri`?(0,$.jsx)(xc,{width:`2.44814cap`,className:`translate-y-[0.046875cap]`}):e},t)}var Mu=`app-region-no-drag inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover hover:text-foreground transition-colors`,Nu=()=>{let e=(0,pl.c)(46),{t}=Tt(),n=q(Pu),r=q(Fu),i=q(Iu),a=q(Lu),o=xs(Ru),s=Q.useRef(null),c=Ba(Pa(`toggle_sidebar`,a)),{usesFramelessChrome:l,side:u}=Bs(),d;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=F(),e[0]=d):d=e[0];let f=d,p=!f||!n||!o,m;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=z()&&!f&&!te(),e[1]=m):m=e[1];let h=m,g=Bu,_,v;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{if(typeof document>`u`)return;let e=s.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect().width;document.documentElement.style.setProperty(`--yuri-titlebar-controls-width`,`${Math.round(t)}px`)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},v=[],e[2]=_,e[3]=v):(_=e[2],v=e[3]),Q.useEffect(_,v);let y=h&&n?`${r||260}px`:void 0,b;e[4]===y?b=e[5]:(b={height:`var(--yuri-header-height, 3rem)`,paddingLeft:`var(--yuri-titlebar-left-inset, 0.75rem)`,width:y},e[4]=y,e[5]=b);let x=h&&n&&`w-full justify-between`,S;e[6]===x?S=e[7]:(S=J(`flex items-center gap-2`,x),e[6]=x,e[7]=S);let C;e[8]===n?C=e[9]:(C=h&&n?(0,$.jsx)(Ou,{className:`flex min-w-0 items-center p-0`}):null,e[8]=n,e[9]=C);let w;e[10]!==l||e[11]!==u?(w=l&&u===`left`?(0,$.jsx)(zs,{visible:!0,position:`left`}):null,e[10]=l,e[11]=u,e[12]=w):w=e[12];let T;e[13]!==t||e[14]!==l?(T=l?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:g,"aria-label":t(`header.actions.openAppMenuAria`),className:J(Mu,`shrink-0`),children:(0,$.jsx)(Z,{name:`menu-2`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(da,{children:(0,$.jsx)(`p`,{children:t(`header.actions.openAppMenu`)})})]}):null,e[13]=t,e[14]=l,e[15]=T):T=e[15];let E;e[16]===p?E=e[17]:(E=p?(0,$.jsx)(bc,{}):null,e[16]=p,e[17]=E);let D=pa,O;e[18]===t?O=e[19]:(O=t(`header.actions.openSessionsAria`),e[18]=t,e[19]=O);let k,A;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(k=J(Mu,`group shrink-0`),A=(0,$.jsx)(Z,{name:`layout-left-rounded`,className:`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),e[20]=k,e[21]=A):(k=e[20],A=e[21]);let j;e[22]!==O||e[23]!==i?(j=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,"aria-label":O,className:k,children:A})}),e[22]=O,e[23]=i,e[24]=j):j=e[24];let M=da,N=t(`header.actions.openSessionsWithShortcut`,{shortcut:c}),P;e[25]===N?P=e[26]:(P=(0,$.jsx)(`p`,{children:N}),e[25]=N,e[26]=P);let I;e[27]!==M||e[28]!==P?(I=(0,$.jsx)(M,{children:P}),e[27]=M,e[28]=P,e[29]=I):I=e[29];let L;e[30]!==D||e[31]!==j||e[32]!==I?(L=(0,$.jsxs)(D,{children:[j,I]}),e[30]=D,e[31]=j,e[32]=I,e[33]=L):L=e[33];let R;e[34]!==E||e[35]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[E,L]}),e[34]=E,e[35]=L,e[36]=R):R=e[36];let B;e[37]!==w||e[38]!==T||e[39]!==R||e[40]!==S||e[41]!==C?(B=(0,$.jsxs)(`div`,{ref:s,className:S,children:[C,w,T,R]}),e[37]=w,e[38]=T,e[39]=R,e[40]=S,e[41]=C,e[42]=B):B=e[42];let V;return e[43]!==B||e[44]!==b?(V=(0,$.jsx)(`div`,{className:`app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2`,style:b,children:B}),e[43]=B,e[44]=b,e[45]=V):V=e[45],V};function Pu(e){return e.isSidebarOpen}function Fu(e){return e.sidebarWidth}function Iu(e){return e.toggleSidebar}function Lu(e){return e.shortcutOverrides}function Ru(e){return e.sidebarBrandName.trim().length>0}function zu(e){console.warn(`[titlebar] failed to open app menu`,e)}function Bu(e){let t=e.currentTarget.getBoundingClientRect();j(`desktop_show_app_menu`,{x:t.left,y:t.bottom}).catch(zu)}var Vu=420,Hu=({isOpen:e,children:t,className:n})=>{let{t:r}=Tt(),i=q(e=>e.rightSidebarWidth),a=q(e=>e.setRightSidebarWidth),[o,s]=Q.useState(!1),c=Q.useRef(0),l=Q.useRef(i||Vu),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),p=Q.useCallback(e=>Math.min(860,Math.max(360,e)),[]),m=Q.useCallback(e=>{let t=f.current;t&&(t.style.width=`${e}px`,t.style.minWidth=`${e}px`,t.style.maxWidth=`${e}px`,t.style.setProperty(`--yuri-right-sidebar-width`,`${e}px`))},[]),h=Math.min(860,Math.max(360,i||Vu)),g=e?h:0;Q.useLayoutEffect(()=>{if(o)return;let e=f.current;e&&(e.style.minWidth=``,e.style.maxWidth=``)},[e,o,h]);let _=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}d.current=t.pointerId,s(!0),c.current=t.clientX,l.current=g,u.current=g,m(g),t.preventDefault()}},v=e=>{if(!o||d.current!==e.pointerId)return;let t=c.current-e.clientX,n=p(l.current+t);u.current!==n&&(u.current=n,m(n))},y=e=>{if(d.current!==e.pointerId)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=p(u.current??g);d.current=null,u.current=null,s(!1),a(t)},b=o?u.current??g:g;return(0,$.jsxs)(`aside`,{ref:f,className:J(`relative flex h-full overflow-hidden yuri-layout-divider-l will-change-[width] motion-reduce:transition-none`,`bg-sidebar`,!e&&`border-l-0`,n),style:{width:`${b}px`,"--yuri-right-sidebar-width":`${o?b:h}px`,overflowX:`clip`,transitionProperty:o?`none`:`width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||g===0,children:[e&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,o&&`bg-[var(--interactive-border)]`),onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:y,role:`separator`,"aria-orientation":`vertical`,"aria-label":r(`sidebar.resize.rightPanelAria`)}),(0,$.jsx)(`div`,{className:J(`relative z-10 flex h-full min-h-0 shrink-0 flex-col pt-2 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,o&&`pointer-events-none`,!e&&`pointer-events-none select-none opacity-0`),style:{width:`var(--yuri-right-sidebar-width)`},"aria-hidden":!e,children:e?t:null})]})},Uu=12,Wu=[{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`}],Gu=e=>{let t=(0,pl.c)(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:o,onComplete:s}=e,c=r===void 0?0:r,l=a===void 0?900:a,u=o===void 0?Wu:o,d=Q.useRef(!1),f,p;t[0]!==n||t[1]!==s?(f=()=>{!n&&d.current&&s?.(),n&&(d.current=!0)},p=[n,s],t[0]=n,t[1]=s,t[2]=f,t[3]=p):(f=t[2],p=t[3]),Q.useEffect(f,p);let m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=Array.from({length:Uu},Ku),t[4]=m):m=t[4];let h=m;if(!n)return null;let g;t[5]===i?g=t[6]:(g=J(`fireworks-overlay pointer-events-none`,i),t[5]=i,t[6]=g);let _;if(t[7]!==c||t[8]!==u||t[9]!==l){let e;t[11]!==c||t[12]!==l?(e=e=>{let t={"--burst-delay":`${e.delay}ms`,"--burst-x":`${e.x}%`,"--burst-y":`${e.y}%`,"--firework-color":`var(${e.colorVar})`,"--firework-duration":`${l}ms`};return(0,$.jsx)(`div`,{className:`firework-burst`,style:t,children:h.map((t,n)=>{let r=t.x*e.radius,i=t.y*e.radius,a={"--translate-x":`${r}px`,"--translate-y":`${i}px`,"--particle-delay":`${t.delay}ms`,color:`var(${e.colorVar})`};return(0,$.jsx)(`span`,{className:`firework-particle`,style:a},`${e.id}-${n}-${c}`)})},`${e.id}-${c}`)},t[11]=c,t[12]=l,t[13]=e):e=t[13],_=u.map(e),t[7]=c,t[8]=u,t[9]=l,t[10]=_}else _=t[10];let v;return t[14]!==c||t[15]!==g||t[16]!==_?(v=(0,$.jsx)(`div`,{className:g,"aria-hidden":`true`,"data-burst-key":c,children:_}),t[14]=c,t[15]=g,t[16]=_,t[17]=v):v=t[17],v};function Ku(e,t){let n=Math.PI*2*t/Uu;return{x:Math.cos(n),y:Math.sin(n),delay:t*18}}var qu=e=>{let t=(0,pl.c)(13),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{durationMs:r}=n,i=r===void 0?3400:r,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a={isActive:!1,cycle:0},t[2]=a):a=t[2];let[o,s]=Q.useState(a),c=Q.useRef(null),l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{c.current&&=(window.clearTimeout(c.current),null)},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{u(),s(Ju)},t[4]=d):d=t[4];let f=d,p;t[5]===i?p=t[6]:(p=()=>{u(),s(Yu),c.current=window.setTimeout(()=>{s(Xu),c.current=null},i)},t[5]=i,t[6]=p);let m=p,h,g;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>()=>u(),g=[u],t[7]=h,t[8]=g):(h=t[7],g=t[8]),Q.useEffect(h,g);let _;return t[9]!==o.cycle||t[10]!==o.isActive||t[11]!==m?(_={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:m,dismissFireworks:f},t[9]=o.cycle,t[10]=o.isActive,t[11]=m,t[12]=_):_=t[12],_};function Ju(e){return e.isActive?{...e,isActive:!1}:e}function Yu(e){return{isActive:!0,cycle:e.cycle+1}}function Xu(e){return e.isActive?{...e,isActive:!1}:e}var Zu=Q.createContext(void 0),Qu=e=>{let t=(0,pl.c)(10),{children:n}=e,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=qu(),s;t[0]!==o||t[1]!==a?(s={triggerFireworks:a,dismissFireworks:o},t[0]=o,t[1]=a,t[2]=s):s=t[2];let c=s,l;t[3]!==i||t[4]!==r?(l=(0,$.jsx)(Gu,{isActive:r,burstKey:i}),t[3]=i,t[4]=r,t[5]=l):l=t[5];let u;return t[6]!==n||t[7]!==l||t[8]!==c?(u=(0,$.jsxs)(Zu.Provider,{value:c,children:[n,l]}),t[6]=n,t[7]=l,t[8]=c,t[9]=u):u=t[9],u},$u=()=>{let e=Q.useContext(Zu);if(!e)throw Error(`useFireworksCelebration must be used within FireworksProvider`);return e},ed=`gitmojiCache`,td=6048e5,nd=`1`,rd=`https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json`,id=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.emoji==`string`&&typeof t.code==`string`&&typeof t.description==`string`},ad=()=>{if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(ed);if(!e)return null;let t=JSON.parse(e);return!t||t.version!==nd||typeof t.fetchedAt!=`number`||!Array.isArray(t.gitmojis)?null:{gitmojis:t.gitmojis.filter(id),fetchedAt:t.fetchedAt,version:t.version}}catch{return null}},od=e=>{if(!(typeof window>`u`))try{let t={gitmojis:e,fetchedAt:Date.now(),version:nd};window.localStorage.setItem(ed,JSON.stringify(t))}catch{return}},sd=e=>Date.now()-e.fetchedAt<td,cd=null,ld=new Set,ud=async()=>{if(cd)return cd;let e=(async()=>{try{let e=await fetch(rd);if(!e.ok)throw Error(`Failed to load gitmojis: ${e.statusText}`);let t=await e.json(),n=Array.isArray(t.gitmojis)?t.gitmojis.filter(id):[];return od(n),ld.forEach(e=>e(n)),n}catch(e){console.warn(`Failed to load gitmoji list:`,e);let t=[];return ld.forEach(e=>e(t)),t}finally{cd=null}})();return cd=e,e},dd=e=>{let[t,n]=Q.useState(()=>e?ad()?.gitmojis??[]:[]),[r,i]=Q.useState(!1),a=Q.useRef(e);return a.current=e,Q.useEffect(()=>{if(!e){ld.delete(n),n([]),i(!1);return}let t=ad();if(t&&(n(t.gitmojis),sd(t)))return;ld.add(n),i(!0);let r=!1;return ud().finally(()=>{!r&&a.current&&i(!1)}),()=>{r=!0,ld.delete(n)}},[e]),{gitmojis:t,isLoading:r,ensureLoaded:Q.useCallback(async()=>{if(!a.current)return[];if(t.length>0)return t;let e=ad();return e&&sd(e)?e.gitmojis:ud()},[t])}},fd=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)};function pd(e,t,n){let r=(0,pl.c)(5),[i,a]=Q.useState(),o,s;return r[0]!==n||r[1]!==e||r[2]!==t?(o=()=>{if(t){a(void 0);return}if(!e){a(void 0);return}a(void 0);let r=!1;return(async()=>{let[t,i]=await Promise.all([Er(e),hr(e)]).catch(md);if(r)return;let o=fd(t),s=fd(i);if(!o||!s||s===o)return;let c=n||``,l=s.split(`/`).filter(Boolean).pop()||s;a({source:`sdk`,path:s,projectDirectory:o,branch:c,label:c||l,name:l,worktreeRoot:s,worktreeStatus:`ready`,headState:c?`branch`:`unborn`,worktreeSource:`existing`})})(),()=>{r=!0}},s=[e,t,n],r[0]=n,r[1]=e,r[2]=t,r[3]=o,r[4]=s):(o=r[3],s=r[4]),Q.useEffect(o,s),t??i}function md(){return[``,``]}var hd=({open:e,onOpenChange:t,directory:n,hasUncommittedChanges:r,hasStagedChanges:i=!1,uncommittedFileCount:a,onChanged:o})=>{let{t:s}=Tt(),[c,l]=Q.useState([]),[u,d]=Q.useState(!1),[f,p]=Q.useState(``),[m,h]=Q.useState(``),[g,_]=Q.useState(null),[v,y]=Q.useState({}),b=Q.useCallback(async()=>{if(n){d(!0);try{let e=await gr(n);l(e.stashes),y({})}catch(e){X.error(e instanceof Error?e.message:s(`gitView.stashes.toast.loadFailed`))}finally{d(!1)}}},[n,s]);Q.useEffect(()=>{e&&b()},[b,e]),Q.useEffect(()=>{if(!e||!n||c.length===0)return;let t=!1,r=c.map(e=>e.ref);return xr(n,r).then(e=>{t||y(e.counts)}).catch(()=>void 0),()=>{t=!0}},[n,e,c]);let x=Q.useMemo(()=>{let e=f.trim().toLowerCase();return e?c.filter(t=>`${t.ref} ${t.message} ${t.relativeTime}`.toLowerCase().includes(e)):c},[f,c]),S=Q.useCallback(async e=>{await b(),await o?.(e)},[b,o]),C=async()=>{if(!(!n||g)){_(`create`);try{let e=await yr(n,{message:m.trim()||void 0});e.created?(X.success(s(`gitView.stashes.toast.created`)),h(``)):X.info(s(`gitView.stashes.toast.noChanges`)),await S({affectsIndex:!!(e.created&&i)})}catch(e){X.error(e instanceof Error?e.message:s(`gitView.stashes.toast.createFailed`))}finally{_(null)}}},w=async(e,t)=>{if(!(!n||g)&&!(t===`drop`&&!window.confirm(s(`gitView.stashes.confirm.drop`,{ref:e.ref})))){_(`${t}:${e.ref}`);try{t===`apply`&&await jr(n,{ref:e.ref}),t===`pop`&&await br(n,{ref:e.ref}),t===`drop`&&await Sr(n,{ref:e.ref});let r=t===`apply`?`gitView.stashes.toast.applySuccess`:t===`pop`?`gitView.stashes.toast.popSuccess`:`gitView.stashes.toast.dropSuccess`;X.success(s(r)),await S({affectsIndex:t!==`drop`})}catch(e){let n=t===`apply`?`gitView.stashes.toast.applyFailed`:t===`pop`?`gitView.stashes.toast.popFailed`:`gitView.stashes.toast.dropFailed`;X.error(e instanceof Error?e.message:s(n)),await S({affectsIndex:t!==`drop`})}finally{_(null)}}},T=g!==null;return(0,$.jsx)(mr,{open:e,onOpenChange:t,children:(0,$.jsxs)(dr,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(lr,{children:[(0,$.jsxs)(fr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`h-5 w-5`}),s(`gitView.stashes.title`)]}),(0,$.jsx)(pr,{children:s(`gitView.stashes.description`)})]}),(0,$.jsxs)(`div`,{className:`mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(la,{value:m,onChange:e=>h(e.target.value),placeholder:s(`gitView.stashes.messagePlaceholder`),disabled:T||!r,className:`flex-1`}),(0,$.jsxs)(Y,{onClick:C,disabled:!r||T||!n,children:[g===`create`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`inbox-archive`,className:`size-4`}),s(`gitView.stashes.actions.stashCurrentWithCount`,{count:a})]})]}),(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:s(`gitView.stashes.includeUntrackedHint`)})]}),(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(Z,{name:`search`,className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(la,{value:f,onChange:e=>p(e.target.value),placeholder:s(`gitView.stashes.searchPlaceholder`),className:`pl-9`})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:u?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-10 text-muted-foreground`,children:(0,$.jsx)(Z,{name:`loader-4`,className:`size-5 animate-spin`})}):x.length===0?(0,$.jsx)(`div`,{className:`py-8 text-center text-muted-foreground`,children:s(f?`gitView.stashes.empty.search`:`gitView.stashes.empty.list`)}):x.map((e,t)=>(0,$.jsxs)(`div`,{className:`group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 pl-2`,children:[(0,$.jsx)(`p`,{className:`typography-small truncate text-foreground`,children:e.message||s(`gitView.stashes.untitled`)}),(0,$.jsxs)(`p`,{className:`typography-meta truncate text-muted-foreground`,children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{children:t===0&&!f.trim()?s(`gitView.stashes.latestLabel`):s(`gitView.stashes.itemNumber`,{number:t+1})})}),(0,$.jsx)(da,{sideOffset:6,children:e.ref})]}),` · `,e.relativeTime,` · `,typeof v[e.ref]==`number`?s(`gitView.stashes.fileCount`,{count:v[e.ref]}):s(`gitView.stashes.fileCountLoading`)]})]}),(0,$.jsxs)(`div`,{className:`mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100`,children:[(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.apply`),loading:g===`apply:${e.ref}`,onClick:()=>w(e,`apply`),disabled:T,children:(0,$.jsx)(Z,{name:`inbox-unarchive`,className:`size-4`})}),(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.pop`),loading:g===`pop:${e.ref}`,onClick:()=>w(e,`pop`),disabled:T,children:(0,$.jsx)(Z,{name:`inbox-unarchive-fill`,className:`size-4`})}),(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.drop`),loading:g===`drop:${e.ref}`,onClick:()=>w(e,`drop`),disabled:T,destructive:!0,children:(0,$.jsx)(Z,{name:`delete-bin`,className:`size-4`})})]})]},e.ref))})]})})},gd=e=>{let t=(0,pl.c)(17),{label:n,loading:r,disabled:i,destructive:a,onClick:o,children:s}=e,c=r||void 0,l=a?`text-[var(--status-error)] hover:text-[var(--status-error)]`:`text-muted-foreground hover:text-foreground`,u;t[0]===l?u=t[1]:(u=J(`flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50`,l),t[0]=l,t[1]=u);let d;t[2]!==s||t[3]!==r?(d=r?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):s,t[2]=s,t[3]=r,t[4]=d):d=t[4];let f;t[5]!==i||t[6]!==n||t[7]!==o||t[8]!==c||t[9]!==u||t[10]!==d?(f=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":n,"aria-busy":c,className:u,onClick:o,disabled:i,children:d})}),t[5]=i,t[6]=n,t[7]=o,t[8]=c,t[9]=u,t[10]=d,t[11]=f):f=t[11];let p;t[12]===n?p=t[13]:(p=(0,$.jsx)(da,{sideOffset:6,children:n}),t[12]=n,t[13]=p);let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(pa,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m},_d=e=>{let t=(0,pl.c)(16),{onOpenStashes:n}=e,{t:r}=Tt(),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Z,{name:`git-commit`,className:`size-10 text-muted-foreground/70 mb-4`}),t[0]=i):i=t[0];let a;t[1]===r?a=t[2]:(a=r(`gitView.empty.cleanTitle`),t[1]=r,t[2]=a);let o;t[3]===a?o=t[4]:(o=(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground mb-1`,children:a}),t[3]=a,t[4]=o);let s;t[5]===r?s=t[6]:(s=r(`gitView.empty.cleanDescription`),t[5]=r,t[6]=s);let c;t[7]===s?c=t[8]:(c=(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground mb-4`,children:s}),t[7]=s,t[8]=c);let l;t[9]!==n||t[10]!==r?(l=n?(0,$.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,onClick:n,className:`gap-1.5`,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`size-4`}),r(`gitView.stashes.title`)]}):null,t[9]=n,t[10]=r,t[11]=l):l=t[11];let u;return t[12]!==o||t[13]!==c||t[14]!==l?(u=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-10 px-4 text-center`,children:[i,o,c,l]}),t[12]=o,t[13]=c,t[14]=l,t[15]=u):u=t[15],u},vd=8,yd=e=>{let t=(0,pl.c)(18),{laned:n,totalLanes:r,isExpanded:i}=e,{lane:a,color:o,connectors:s}=n,c=Math.max(r,a+1)*vd+vd/2,l=Q.useRef(null),u=Q.useRef(null),d;t[0]!==o||t[1]!==s||t[2]!==a||t[3]!==c?(d=()=>{let e=l.current,t=u.current;if(!e||!t)return;let n=e.offsetHeight;if(n===0)return;let r=window.devicePixelRatio||1;t.width=c*r,t.height=n*r;let i=t.getContext(`2d`);if(!i)return;i.scale(r,r),i.clearRect(0,0,c,n);let d=n/2,f=a*vd+vd/2,p=getComputedStyle(t),m=p.getPropertyValue(`--surface-muted-foreground`).trim()||p.color,h=e=>{if(!e.startsWith(`var(`))return e;let t=e.slice(4,-1).trim();return p.getPropertyValue(t).trim()||m},g=[...s].sort(xd);for(let e of g){let t=e.fromLane*vd+vd/2,r=e.toLane*vd+vd/2,a=e.type===`passing`?.72:e.type===`branch-out`||e.type===`merge-in`?.95:1;i.beginPath(),i.strokeStyle=h(e.color),i.globalAlpha=a,i.lineWidth=1.25,i.lineCap=`round`;bb64:switch(e.type){case`passing`:case`commit-lane`:i.moveTo(t,0),i.lineTo(t,n);break bb64;case`top-stub`:i.moveTo(t,0),i.lineTo(t,d);break bb64;case`bottom-stub`:i.moveTo(t,d),i.lineTo(t,n);break bb64;case`branch-out`:{let e=(d+n)/2;i.moveTo(f,d),i.bezierCurveTo(f,e,r,e,r,n);break bb64}case`merge-in`:{let e=d/2;i.moveTo(t,0),i.bezierCurveTo(t,e,f,e,f,d);break bb64}default:continue}i.stroke(),i.globalAlpha=1}let _=p.getPropertyValue(`--background`).trim()||p.getPropertyValue(`--surface-background`).trim();i.beginPath(),i.arc(f,d,4,0,Math.PI*2),i.fillStyle=h(o),i.fill(),i.beginPath(),i.arc(f,d,5,0,Math.PI*2),i.strokeStyle=_||m,i.lineWidth=2,i.stroke()},t[0]=o,t[1]=s,t[2]=a,t[3]=c,t[4]=d):d=t[4];let f;t[5]!==o||t[6]!==s||t[7]!==i||t[8]!==a||t[9]!==n||t[10]!==r||t[11]!==c?(f=[n,a,o,s,r,i,c],t[5]=o,t[6]=s,t[7]=i,t[8]=a,t[9]=n,t[10]=r,t[11]=c,t[12]=f):f=t[12],Q.useLayoutEffect(d,f);let p;t[13]===c?p=t[14]:(p={width:c,height:`100%`,position:`relative`,flexShrink:0,overflow:`hidden`},t[13]=c,t[14]=p);let m;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`canvas`,{ref:u,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,display:`block`}}),t[15]=m):m=t[15];let h;return t[16]===p?h=t[17]:(h=(0,$.jsx)(`div`,{ref:l,style:p,children:m}),t[16]=p,t[17]=h),h};function bd(e){return e===`branch-out`||e===`merge-in`}function xd(e,t){let n=bd;return!!n(e.type)-+!!n(t.type)}var Sd=15e3,Cd=500,wd=12,Td=8388608,Ed=e=>typeof e==`string`?0:(e.original?.length??0)+(e.modified?.length??0),Dd=e=>{if(e.size<=wd){let t=0;for(let n of e.values())t+=Ed(n);if(t<=Td)return e}let t=Array.from(e.entries()).reverse(),n=new Map,r=0;for(let[e,i]of t){if(n.size>=wd)continue;let t=Ed(i);r+t>Td&&n.size>0||(n.set(e,i),r+=t)}return new Map(Array.from(n.entries()).reverse())};function Od(e,t){let n=new Date(e);return Number.isNaN(n.getTime())?e:va(n,t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function kd(e){switch(e){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 Ad(e){return e?e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.startsWith(`HEAD ->`);return{label:t?e.replace(`HEAD -> `,``):e.replace(`tag: `,``),isHead:t,isTag:e.startsWith(`tag: `)}}):[]}var jd=Q.memo(({entry:e,mode:t=`history`,laned:n,totalLanes:r,isExpanded:i,onToggle:a,files:o,isLoadingFiles:s,onCopyHash:c,directory:l,onConflict:u,onActionSuccess:d})=>{let{t:f}=Tt(),p=q(e=>e.timeFormatPreference),m=t===`graph`,[h,g]=Q.useState(null),[_,v]=Q.useState(!1),[y,b]=Q.useState(``),[x,S]=Q.useState(null),[C,w]=Q.useState(new Set),[T,E]=Q.useState(new Map),[D,O]=Q.useState(new Set),k=async()=>{if(l){g(`checkout`);try{await Ar(l,e.hash),X.success(f(`gitView.history.actions.detachedHead`)),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},A=async()=>{if(!(!l||!y.trim())){g(`createBranch`);try{await Or(l,y.trim(),e.hash),v(!1),b(``),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},j=async()=>{if(l){g(`cherryPick`);try{let t=await wr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`cherry-pick`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},M=async()=>{if(l){g(`revert`);try{let t=await Tr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`revert`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},N=async(t,n=!1)=>{if(!(!l||h!==null)){g(`reset`);try{await vr(l,e.hash,t,n),d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},P=async()=>{if(!x)return;let e=x;switch(S(null),e){case`checkout`:return k();case`cherryPick`:return j();case`revert`:return M();case`merge`:return F();case`rebase`:return I();case`resetSoft`:return N(`soft`);case`resetMixed`:return N(`mixed`);case`resetHard`:return N(`hard`,!0)}},F=async()=>{if(l){g(`merge`);try{let t=await Mr(l,{branch:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`merge`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},I=async()=>{if(l){g(`rebase`);try{let t=await _r(l,{onto:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`rebase`}):d?.()}catch(e){X.error(String(e.message))}finally{g(null)}}},L=Q.useCallback(async t=>{let n=t.path;if(!l){E(e=>new Map(e).set(n,`error`));return}E(e=>Dd(new Map(e).set(n,`loading`)));try{let r=Dr(l,e.hash,t.path,!1),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${Sd}ms`)),Sd)}),a=await Promise.race([r,i]);E(e=>Dd(new Map(e).set(n,a)))}catch{E(e=>new Map(e).set(n,`error`))}},[l,e.hash]),R=Q.useCallback(async e=>{let t=e.path;if(e.changeType===`R`||e.isBinary){w(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n});return}let n=T.get(t);if(C.has(t)&&n&&n!==`error`){w(e=>{let n=new Set(e);return n.delete(t),n});return}w(e=>{let n=new Set(e);return n.add(t),n}),!(n&&n!==`error`)&&(e.insertions+e.deletions>Cd&&!D.has(t)||await L(e))},[T,D,L,C]);return(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:J(`w-full flex items-start gap-3 px-3 py-2 text-left transition-colors`,m?`hover:bg-[var(--interactive-hover)]/40`:i?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[m&&n&&r!==void 0?(0,$.jsx)(`div`,{className:`-my-2 shrink-0 self-stretch`,children:(0,$.jsx)(yd,{laned:n,totalLanes:r,isExpanded:i})}):(0,$.jsx)(`div`,{className:`h-2 w-2 translate-y-2 rounded-full shrink-0`,style:{backgroundColor:`var(--status-success)`},"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[m?(()=>{let t=Ad(e.refs);return t.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-0.5`,children:t.map(e=>(0,$.jsx)(`span`,{className:J(`inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium`,e.isHead?`bg-[var(--chart-1)] text-[var(--primary-foreground)]`:e.isTag?`bg-[var(--chart-5)] text-[var(--primary-foreground)]`:`bg-[var(--interactive-hover)] text-[var(--foreground)]`),children:e.label},e.label))}):null})():null,(0,$.jsx)(`p`,{className:`typography-ui-label font-medium text-foreground line-clamp-1`,children:e.message}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 typography-meta text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 truncate`,children:[(0,$.jsx)(`span`,{className:`truncate min-w-[3ch]`,title:e.author_name,children:e.author_name}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`span`,{className:`truncate min-w-0`,title:Od(e.date,p),children:Od(e.date,p)})]}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`code`,{className:`shrink-0 font-mono`,children:e.hash.slice(0,8)}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-5 px-1 shrink-0`,onClick:t=>{t.stopPropagation(),c(e.hash)},children:(0,$.jsx)(Z,{name:`file-copy`,className:`size-3`})})}),(0,$.jsx)(da,{sideOffset:8,children:f(`gitView.history.copySha`)})]})]})]})]}),i&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 pl-8 border-t border-border/40`,children:[m&&x?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2 border-b border-border/30 mb-2`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground flex-1 min-w-0`,children:f(`gitView.history.actions.${x}Confirm`)}),(0,$.jsxs)(Y,{variant:`destructive`,size:`xs`,className:`h-6 shrink-0`,disabled:h!==null,onClick:e=>{e.stopPropagation(),P()},children:[h===null?null:(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}),f(`gitView.history.actions.confirmButton`)]}),(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:`h-6 shrink-0`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(null)},children:f(`gitView.history.actions.cancelButton`)})]}):m?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2`,children:[(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`checkout`)},children:f(`gitView.history.actions.checkout`)}),_?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A(),e.key===`Escape`&&(v(!1),b(``))},placeholder:f(`gitView.history.actions.createBranchPlaceholder`),className:`h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32`}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:!y.trim()||h!==null,onClick:e=>{e.stopPropagation(),A()},children:[h===`createBranch`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.createBranchConfirm`)]})]}):(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,onClick:e=>{e.stopPropagation(),v(!0)},children:f(`gitView.history.actions.createBranch`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`cherryPick`)},children:f(`gitView.history.actions.cherryPick`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`revert`)},children:f(`gitView.history.actions.revert`)}),(0,$.jsxs)(Ga,{children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>e.stopPropagation(),children:[h===`reset`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.reset`)]})}),(0,$.jsx)(Ia,{align:`start`,className:`min-w-max`,children:[`soft`,`mixed`,`hard`].map(e=>(0,$.jsx)(ka,{disabled:h!==null,onSelect:t=>{t.stopPropagation(),S(`reset${e.charAt(0).toUpperCase()+e.slice(1)}`)},children:f(`gitView.history.actions.reset${e.charAt(0).toUpperCase()+e.slice(1)}`)},e))})]}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`merge`)},children:f(`gitView.history.actions.merge`)}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`rebase`)},children:f(`gitView.history.actions.rebase`)})]}):null,s?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:f(`gitView.history.loadingFiles`)})]}):o.length===0?(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground py-2`,children:f(`gitView.history.noFiles`)}):(0,$.jsx)(`ul`,{className:`space-y-0.5 py-2`,children:o.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>R(e),className:J(`w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1`,C.has(e.path)?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[(0,$.jsx)(`span`,{className:J(`font-semibold w-3 text-center shrink-0`,kd(e.changeType)),children:e.changeType}),(0,$.jsx)(`span`,{className:`truncate text-foreground min-w-0`,title:e.path,children:e.path}),!e.isBinary&&(0,$.jsxs)(`span`,{className:`shrink-0`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.insertions]}),(0,$.jsx)(`span`,{className:`text-muted-foreground mx-0.5`,children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.deletions]})]}),e.isBinary&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:f(`gitView.history.binary`)}),(0,$.jsx)(Z,{name:C.has(e.path)?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),C.has(e.path)&&(0,$.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:e.changeType===`R`?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.renamedNoDiff`)}):e.isBinary?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.binaryNoDiff`)}):(()=>{let t=e.insertions+e.deletions;if(!D.has(e.path)&&t>Cd)return(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:f(`gitView.history.largeDiffTitle`,{count:t})}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:f(`gitView.history.largeDiffDescription`)}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`xs`,className:`h-6 px-0 text-primary hover:bg-transparent hover:underline`,onClick:()=>{O(t=>new Set(t).add(e.path)),L(e)},children:f(`gitView.history.renderDiffAnyway`)})]});let n=T.get(e.path);return n===`loading`||n===void 0?(0,$.jsx)(`div`,{className:`px-3 py-2 text-sm text-muted-foreground`,children:f(`gitView.history.loadingDiff`)}):n===`error`?(0,$.jsx)(`button`,{type:`button`,onClick:()=>R(e),className:`w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors`,children:f(`gitView.history.diffError`)}):(0,$.jsx)(fc,{original:n.original,modified:n.modified,language:Zo(e.path)||``,fileName:e.path,renderSideBySide:!1,layout:`inline`,enableComments:!1})})()})]},e.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 Nd(e){return Md[e%Md.length]}function Pd(e){if(e.length===0)return[];let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r],a=[];for(let e=0;e<t.length;e++)t[e]===i.hash&&a.push(e);let o=a.length>0?a[0]:-1;if(o===-1){let e=t.indexOf(null);e===-1?(o=t.length,t.push(null)):o=e}let s=a.slice(1),c=Nd(o),l=t[o]===i.hash,u=i.parents.length>0;u?t[o]=i.parents[0]:t[o]=null;let d=[];for(let e=1;e<i.parents.length;e++){let n=i.parents[e],r=t.indexOf(n);if(r!==-1)d.push(r);else{let e=t.indexOf(null),r=e===-1?t.length:e;t[r]=n,r===t.length&&t.push(n),d.push(r)}}let f=[];l&&u?f.push({fromLane:o,toLane:o,color:c,type:`commit-lane`}):l&&!u?f.push({fromLane:o,toLane:o,color:c,type:`top-stub`}):!l&&u&&f.push({fromLane:o,toLane:o,color:c,type:`bottom-stub`});for(let e of s)f.push({fromLane:e,toLane:o,color:Nd(e),type:`merge-in`}),t[e]=null;for(let e of d)f.push({fromLane:o,toLane:e,color:Nd(e),type:`branch-out`});for(let e=0;e<t.length;e++)t[e]!==null&&e!==o&&(d.includes(e)||f.push({fromLane:e,toLane:e,color:Nd(e),type:`passing`}));n.push({commit:i,lane:o,color:c,connectors:f})}return n}var Fd=[{labelKey:`gitView.history.logSize25`,value:25},{labelKey:`gitView.history.logSize50`,value:50},{labelKey:`gitView.history.logSize100`,value:100}],Id=e=>{let t=(0,pl.c)(84),{mode:n,log:r,isLogLoading:i,logMaxCount:a,onLogMaxCountChange:o,expandedCommitHashes:s,onToggleCommit:c,commitFilesMap:l,loadingCommitHashes:u,onCopyHash:d,directory:f,showHeader:p,contentMaxHeightClassName:m,branchDivider:h,onConflict:g,onActionSuccess:_}=e,v=n===void 0?`history`:n,y=p===void 0||p,b=m===void 0?`max-h-[50vh]`:m,x=h===void 0?null:h,{t:S}=Tt(),[C,w]=Q.useState(!0),T=v===`graph`,E;t[0]!==T||t[1]!==r?(E=T&&r?Pd(r.all):[],t[0]=T,t[1]=r,t[2]=E):E=t[2];let D=E,O;t[3]===D?O=t[4]:(O=Math.max(1,...D.map(Ld)),t[3]=D,t[4]=O);let k=O,A;t[5]===D?A=t[6]:(A=new Map(D.map(Rd)),t[5]=D,t[6]=A);let j=A;if(!r)return null;let M=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<r.all.length,N=x!==null&&x.insertBeforeIndex===r.all.length,P=M||N,F;t[7]!==x||t[8]!==M||t[9]!==N||t[10]!==r.all?(F=M?r.all.slice(0,x.insertBeforeIndex):N?r.all:[],t[7]=x,t[8]=M,t[9]=N,t[10]=r.all,t[11]=F):F=t[11];let I=F,L;if(t[12]!==x||t[13]!==l||t[14]!==b||t[15]!==f||t[16]!==s||t[17]!==M||t[18]!==P||t[19]!==T||t[20]!==i||t[21]!==j||t[22]!==u||t[23]!==r.all||t[24]!==a||t[25]!==k||t[26]!==v||t[27]!==_||t[28]!==g||t[29]!==d||t[30]!==o||t[31]!==c||t[32]!==S||t[33]!==I){let e=M?r.all.slice(x.insertBeforeIndex):[],n;t[35]===x?.direction?n=t[36]:(n=x?.direction===`down`?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-3.5`}):(0,$.jsx)(Z,{name:`arrow-up`,className:`size-3.5`}),t[35]=x?.direction,t[36]=n);let p=n,m;t[37]!==l||t[38]!==f||t[39]!==s||t[40]!==T||t[41]!==j||t[42]!==u||t[43]!==k||t[44]!==v||t[45]!==_||t[46]!==g||t[47]!==d||t[48]!==c?(m=e=>(0,$.jsx)(`ul`,{className:`divide-y divide-border/60`,children:e.map(e=>(0,$.jsx)(jd,{entry:e,mode:v,laned:T?j.get(e.hash):void 0,totalLanes:T?k:void 0,isExpanded:s.has(e.hash),onToggle:()=>c(e.hash),files:l.get(e.hash)??[],isLoadingFiles:u.has(e.hash),onCopyHash:d,directory:f,onConflict:g,onActionSuccess:_},e.hash))}),t[37]=l,t[38]=f,t[39]=s,t[40]=T,t[41]=j,t[42]=u,t[43]=k,t[44]=v,t[45]=_,t[46]=g,t[47]=d,t[48]=c,t[49]=m):m=t[49];let h=m,y;t[50]!==i||t[51]!==r.all.length||t[52]!==a||t[53]!==o||t[54]!==S?(y=r.all.length>=a?(0,$.jsx)(`div`,{className:`flex justify-center py-2 border-t border-border/40`,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>o(a+25),disabled:i,className:`px-3 text-muted-foreground hover:text-foreground`,children:i?(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-3 animate-spin`}),S(`gitView.history.loadingMore`)]}):S(`gitView.history.loadMore`)})}):null,t[50]=i,t[51]=r.all.length,t[52]=a,t[53]=o,t[54]=S,t[55]=y):y=t[55];let C=y;L=(0,$.jsx)(mo,{outerClassName:`min-h-0 ${b}`,className:`h-full w-full`,children:r.all.length===0?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:S(`gitView.history.noCommits`)})}):P&&x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0`,children:[I.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(I)}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsxs)(`span`,{className:`inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate`,title:x.branchName,children:x.branchName}),p]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`})]}),e.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(e)}):null]}),C]}):(0,$.jsxs)($.Fragment,{children:[h(r.all),C]})}),t[12]=x,t[13]=l,t[14]=b,t[15]=f,t[16]=s,t[17]=M,t[18]=P,t[19]=T,t[20]=i,t[21]=j,t[22]=u,t[23]=r.all,t[24]=a,t[25]=k,t[26]=v,t[27]=_,t[28]=g,t[29]=d,t[30]=o,t[31]=c,t[32]=S,t[33]=I,t[34]=L}else L=t[34];let R=L;if(!y){if(P){let e;return t[56]===R?e=t[57]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0`,children:R}),t[56]=R,t[57]=e),e}let e;return t[58]===R?e=t[59]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:R}),t[58]=R,t[59]=e),e}let z;t[60]===S?z=t[61]:(z=S(`gitView.history.title`),t[60]=S,t[61]=z);let B;t[62]===z?B=t[63]:(B=(0,$.jsx)(`h3`,{className:`typography-ui-header font-semibold text-foreground`,children:z}),t[62]=z,t[63]=B);let V;t[64]!==i||t[65]!==C||t[66]!==a||t[67]!==o||t[68]!==S?(V=C&&(0,$.jsx)(`div`,{onClick:zd,onPointerDown:Bd,children:(0,$.jsxs)(ia,{value:String(a),onValueChange:e=>o(Number(e)),disabled:i,children:[(0,$.jsx)($i,{size:`sm`,className:`data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0`,disabled:i,children:(0,$.jsx)(ca,{placeholder:S(`gitView.history.commitsPlaceholder`)})}),(0,$.jsx)(ta,{children:Fd.map(e=>(0,$.jsx)(Zi,{value:String(e.value),children:S(e.labelKey)},e.value))})]})}),t[64]=i,t[65]=C,t[66]=a,t[67]=o,t[68]=S,t[69]=V):V=t[69];let ee;t[70]===C?ee=t[71]:(ee=C?(0,$.jsx)(Z,{name:`arrow-up-s`,className:`size-4 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-4 text-muted-foreground`}),t[70]=C,t[71]=ee);let H;t[72]!==V||t[73]!==ee?(H=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V,ee]}),t[72]=V,t[73]=ee,t[74]=H):H=t[74];let te;t[75]!==B||t[76]!==H?(te=(0,$.jsxs)(Yc,{className:`flex w-full items-center justify-between px-3 h-10 hover:bg-transparent`,children:[B,H]}),t[75]=B,t[76]=H,t[77]=te):te=t[77];let ne;t[78]===R?ne=t[79]:(ne=(0,$.jsx)(Jc,{children:R}),t[78]=R,t[79]=ne);let re;return t[80]!==C||t[81]!==te||t[82]!==ne?(re=(0,$.jsxs)(Xc,{open:C,onOpenChange:w,className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[te,ne]}),t[80]=C,t[81]=te,t[82]=ne,t[83]=re):re=t[83],re};function Ld(e){return e.lane+1}function Rd(e){return[e.commit.hash,e]}function zd(e){return e.stopPropagation()}function Bd(e){return e.stopPropagation()}var Vd=e=>{let t=(0,pl.c)(150),{open:n,onOpenChange:r,conflictFiles:i,directory:a,operation:o,onAbort:s,onClearState:c}=e,l;t[0]===i?l=t[1]:(l=i===void 0?[]:i,t[0]=i,t[1]=l);let u=l,{t:d}=Tt(),f=Sn(Hd),p=Sn(Ud),m=xn(Wd),h=xn(Gd),g=q(Kd),[_,v]=Q.useState(!1),[y,b]=Q.useState(null),[x,S]=Q.useState(null),C,w;t[2]!==a||t[3]!==n||t[4]!==d?(C=()=>{!n||!a||(v(!0),S(null),b(null),Cr(a).then(e=>{b(e)}).catch(e=>{let t=e instanceof Error?e.message:d(`gitView.conflict.loadFailed`);S(t)}).finally(()=>{v(!1)}))},w=[n,a,d],t[2]=a,t[3]=n,t[4]=d,t[5]=C,t[6]=w):(C=t[5],w=t[6]),Q.useEffect(C,w);let T;t[7]!==y||t[8]!==a||t[9]!==o?(T=async()=>{if(!y)return null;let e=o===`merge`?`merge`:`rebase`,t=y.headInfo||(o===`merge`?`MERGE_HEAD`:`REBASE_HEAD`),n=o===`merge`?`git commit --no-edit`:`git rebase --continue`;return{visibleText:await Mn(`git.conflict.resolve.visible`,{operation_label:e,head_ref:t}),instructionsText:await Mn(`git.conflict.resolve.instructions`,{operation_label:e,directory:a,operation:o,head_info:y.headInfo||`N/A`,continue_cmd:n}),payloadText:`${e} conflict context (JSON)\n${JSON.stringify({directory:a,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`}},t[7]=y,t[8]=a,t[9]=o,t[10]=T):T=t[10];let E=T,D;t[11]!==s||t[12]!==r?(D=()=>{s(),r(!1)},t[11]=s,t[12]=r,t[13]=D):D=t[13];let O=D,k;t[14]!==c||t[15]!==r?(k=()=>{c?.(),r(!1)},t[14]=c,t[15]=r,t[16]=k):k=t[16];let A=k,j;t[17]!==E||t[18]!==p||t[19]!==c||t[20]!==r||t[21]!==g||t[22]!==m||t[23]!==h||t[24]!==d?(j=async()=>{let e=await E();if(!e){X.error(d(`gitView.conflict.noDetailsAvailable`));return}if(!p){X.error(d(`gitView.conflict.noActiveSession`),{description:d(`gitView.conflict.noActiveSessionDescription`)});return}m(e.visibleText,`replace`),h([{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]),g(`chat`),c?.(),r(!1)},t[17]=E,t[18]=p,t[19]=c,t[20]=r,t[21]=g,t[22]=m,t[23]=h,t[24]=d,t[25]=j):j=t[25];let M=j,N;t[26]!==E||t[27]!==a||t[28]!==c||t[29]!==r||t[30]!==f||t[31]!==g||t[32]!==d?(N=async()=>{let e=await E();if(!e){X.error(d(`gitView.conflict.noDetailsAvailable`));return}f({directoryOverride:a,initialPrompt:e.visibleText,syntheticParts:[{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]}),g(`chat`),c?.(),r(!1)},t[26]=E,t[27]=a,t[28]=c,t[29]=r,t[30]=f,t[31]=g,t[32]=d,t[33]=N):N=t[33];let P=N,F,I,L,R,z,B,V,ee,H,te,ne,re,U,ie,ae,W,oe,se,ce,G,le,ue;if(t[34]!==y||t[35]!==u||t[36]!==p||t[37]!==O||t[38]!==A||t[39]!==M||t[40]!==P||t[41]!==_||t[42]!==x||t[43]!==r||t[44]!==n||t[45]!==o||t[46]!==d){let e=d(o===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),i=y?.unmergedFiles||u;L=mr,le=n,ue=r,I=dr,G=`max-w-md w-[calc(100vw-2rem)]`,ie=`flex flex-col gap-4 overflow-hidden`;let a;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(Z,{name:`alert`,className:`size-5 shrink-0 text-[var(--status-warning)]`}),t[69]=a):a=t[69];let s=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a,(0,$.jsx)(fr,{children:d(`gitView.conflict.detectedTitle`,{operation:e})})]}),c;t[70]!==o||t[71]!==d?(c=d(`gitView.conflict.detectedDescription`,{operation:o}),t[70]=o,t[71]=d,t[72]=c):c=t[72];let l;t[73]===c?l=t[74]:(l=(0,$.jsx)(pr,{children:c}),t[73]=c,t[74]=l),t[75]!==s||t[76]!==l?(ae=(0,$.jsxs)(lr,{children:[s,l]}),t[75]=s,t[76]=l,t[77]=ae):ae=t[77],t[78]!==_||t[79]!==d?(W=_&&(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-4 text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:d(`gitView.conflict.loading`)})]}),t[78]=_,t[79]=d,t[80]=W):W=t[80],t[81]!==x||t[82]!==d?(oe=x&&(0,$.jsx)(`div`,{className:`rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words`,children:d(`gitView.conflict.errorLoadingDetails`,{message:x})}),t[81]=x,t[82]=d,t[83]=oe):oe=t[83],t[84]!==i||t[85]!==d?(se=i.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:d(`gitView.conflict.conflictedFiles`)}),(0,$.jsx)(`span`,{className:`typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground`,children:i.length})]}),(0,$.jsx)(`div`,{className:`bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden`,children:(0,$.jsx)(`ul`,{className:`space-y-1`,children:i.map(qd)})})]}),t[84]=i,t[85]=d,t[86]=se):se=t[86],t[87]!==y||t[88]!==d?(ce=y?.headInfo&&(0,$.jsxs)(`div`,{className:`space-y-1 overflow-hidden`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:d(`gitView.conflict.headInfo`)}),(0,$.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:y.headInfo})]}),t[87]=y,t[88]=d,t[89]=ce):ce=t[89],ne=`flex flex-col gap-2 pt-2`;let f;t[90]===P?f=t[91]:(f=()=>{P()},t[90]=P,t[91]=f);let m=_||!y,h;t[92]===_?h=t[93]:(h=_?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`add`,className:`size-4`}),t[92]=_,t[93]=h);let g;t[94]===d?g=t[95]:(g=d(`gitView.conflict.resolveNewSession`),t[94]=d,t[95]=g),t[96]!==f||t[97]!==m||t[98]!==h||t[99]!==g?(re=(0,$.jsxs)(Y,{variant:`default`,onClick:f,disabled:m,className:`w-full gap-2`,children:[h,g]}),t[96]=f,t[97]=m,t[98]=h,t[99]=g,t[100]=re):re=t[100];let v;t[101]===M?v=t[102]:(v=()=>void M(),t[101]=M,t[102]=v);let b=_||!y||!p,S;t[103]===_?S=t[104]:(S=_?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`chat-1`,className:`size-4`}),t[103]=_,t[104]=S);let C;t[105]===d?C=t[106]:(C=d(`gitView.conflict.resolveCurrentSession`),t[105]=d,t[106]=C),t[107]!==v||t[108]!==b||t[109]!==S||t[110]!==C?(U=(0,$.jsxs)(Y,{variant:`outline`,onClick:v,disabled:b,className:`w-full gap-2`,children:[S,C]}),t[107]=v,t[108]=b,t[109]=S,t[110]=C,t[111]=U):U=t[111],H=`flex gap-2 pt-1`;let w;t[112]===d?w=t[113]:(w=d(`gitView.conflict.continueLater`),t[112]=d,t[113]=w),t[114]!==A||t[115]!==w?(te=(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:A,className:`flex-1`,children:w}),t[114]=A,t[115]=w,t[116]=te):te=t[116],F=Y,R=`destructive`,z=`sm`,B=O,V=`flex-1`,ee=d(`gitView.conflict.abortOperation`,{operation:e}),t[34]=y,t[35]=u,t[36]=p,t[37]=O,t[38]=A,t[39]=M,t[40]=P,t[41]=_,t[42]=x,t[43]=r,t[44]=n,t[45]=o,t[46]=d,t[47]=F,t[48]=I,t[49]=L,t[50]=R,t[51]=z,t[52]=B,t[53]=V,t[54]=ee,t[55]=H,t[56]=te,t[57]=ne,t[58]=re,t[59]=U,t[60]=ie,t[61]=ae,t[62]=W,t[63]=oe,t[64]=se,t[65]=ce,t[66]=G,t[67]=le,t[68]=ue}else F=t[47],I=t[48],L=t[49],R=t[50],z=t[51],B=t[52],V=t[53],ee=t[54],H=t[55],te=t[56],ne=t[57],re=t[58],U=t[59],ie=t[60],ae=t[61],W=t[62],oe=t[63],se=t[64],ce=t[65],G=t[66],le=t[67],ue=t[68];let de;t[117]!==F||t[118]!==R||t[119]!==z||t[120]!==B||t[121]!==V||t[122]!==ee?(de=(0,$.jsx)(F,{variant:R,size:z,onClick:B,className:V,children:ee}),t[117]=F,t[118]=R,t[119]=z,t[120]=B,t[121]=V,t[122]=ee,t[123]=de):de=t[123];let fe;t[124]!==H||t[125]!==te||t[126]!==de?(fe=(0,$.jsxs)(`div`,{className:H,children:[te,de]}),t[124]=H,t[125]=te,t[126]=de,t[127]=fe):fe=t[127];let pe;t[128]!==ne||t[129]!==re||t[130]!==U||t[131]!==fe?(pe=(0,$.jsxs)(`div`,{className:ne,children:[re,U,fe]}),t[128]=ne,t[129]=re,t[130]=U,t[131]=fe,t[132]=pe):pe=t[132];let me;t[133]!==ie||t[134]!==ae||t[135]!==W||t[136]!==oe||t[137]!==se||t[138]!==ce||t[139]!==pe?(me=(0,$.jsxs)(`div`,{className:ie,children:[ae,W,oe,se,ce,pe]}),t[133]=ie,t[134]=ae,t[135]=W,t[136]=oe,t[137]=se,t[138]=ce,t[139]=pe,t[140]=me):me=t[140];let he;t[141]!==I||t[142]!==G||t[143]!==me?(he=(0,$.jsx)(I,{className:G,children:me}),t[141]=I,t[142]=G,t[143]=me,t[144]=he):he=t[144];let ge;return t[145]!==L||t[146]!==le||t[147]!==ue||t[148]!==he?(ge=(0,$.jsx)(L,{open:le,onOpenChange:ue,children:he}),t[145]=L,t[146]=le,t[147]=ue,t[148]=he,t[149]=ge):ge=t[149],ge};function Hd(e){return e.openNewSessionDraft}function Ud(e){return e.currentSessionId}function Wd(e){return e.setPendingInputText}function Gd(e){return e.setPendingSyntheticParts}function Kd(e){return e.setActiveMainTab}function qd(e){return(0,$.jsx)(`li`,{className:`typography-micro text-foreground font-mono truncate block`,title:e,children:e},e)}var Jd=({mergeInProgress:e,rebaseInProgress:t,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{let{t:s}=Tt(),[c,l]=Q.useState(null),u=e&&e.head,d=t&&(t.headName||t.onto),f=u?`merge`:d?`rebase`:null;if(!f)return null;let p=async()=>{l(`continue`);try{await n()}finally{l(null)}},m=async()=>{l(`abort`);try{await r()}finally{l(null)}},h=c!==null,g=s(f===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),_=f===`merge`?`git-merge`:`git-branch`,v=``;return e?v=e.message?s(`gitView.operation.mergingMessage`,{message:e.message}):s(`gitView.operation.mergeInProgressWithHead`,{head:e.head}):t&&(v=t.headName?s(`gitView.operation.rebasingOnto`,{headName:t.headName,onto:t.onto||``}):s(`gitView.operation.rebaseInProgress`)),(0,$.jsx)(`div`,{className:`bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,$.jsx)(Z,{name:_,className:`size-4 text-[var(--status-warning)] shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`typography-label text-[var(--status-warning)]`,children:s(`gitView.operation.inProgressTitle`,{operation:g})}),v&&(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground truncate`,children:v})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a&&i&&(0,$.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:i,disabled:h||o,className:`gap-1.5`,children:[(0,$.jsx)(Z,{name:`sparkling`,className:`size-4`}),s(`gitView.operation.resolveWithAi`)]}),c!==`continue`&&(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:m,disabled:h||o,className:`gap-1.5`,children:[c===`abort`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`close`,className:`size-4`}),s(`gitView.operation.abort`)]}),!a&&(0,$.jsxs)(Y,{variant:`default`,size:`sm`,onClick:p,disabled:h||o,className:`gap-1.5`,children:[c===`continue`?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(Z,{name:`check`,className:`size-4`}),s(`gitView.operation.continue`)]})]}),a&&(0,$.jsx)(`p`,{className:`typography-micro text-[var(--status-warning)]`,children:s(`gitView.operation.resolveConflictsHint`)})]})})},Yd=({runMutation:e,onMutationComplete:t,onMutationError:n,onPathsComplete:r,scheduleFlush:i})=>{let a=[],o=!1;return{enqueue:e=>{let t=a[a.length-1];if(t?.directory===e.directory&&t.direction===e.direction){e.paths.forEach(e=>t.paths.add(e));return}a.push(e)},flush:()=>{if(o)return;let s=a.shift();if(!s)return;o=!0;let c={directory:s.directory,direction:s.direction,paths:Array.from(s.paths),rollback:s.rollback};(async()=>{try{await e(c),t(c)}catch(e){n(c,e)}finally{r(c.paths),o=!1,a.length>0&&i()}})()},clear:()=>{a.length=0},size:()=>a.length,isRunning:()=>o}},Xd=15e3,Zd=40,Qd=20,$d={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:`},ef=(e,t)=>{let n=e.toLowerCase(),r=n.match(/^([a-z]+)(?:\(.*\))?!?:/);if(r){let e=$d[r[1]];if(e)return t.find(t=>t.code===e)||null}let i=$d[n.split(` `)[0]];return i&&t.find(e=>e.code===i)||null},tf=20,nf=new Map,rf=(e,t)=>{if(nf.delete(e),nf.set(e,t),nf.size>tf){let e=nf.keys().next().value;e!==void 0&&nf.delete(e)}},af=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),of=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},sf=e=>{let t=e.working_dir?.trim(),n=e.index?.trim();return!!(t||n===`?`)},cf=({isActive:e})=>{let{t}=Tt(),{git:n}=at(),r=es(),[i,a]=Q.useState(null),[o,s]=Q.useState(!1),c=Sn(e=>e.currentSessionId),l=Sn(e=>e.newSessionDraft),u=Sn(e=>e.setDraftBootstrapPendingDirectory),d=Sn(e=>e.worktreeMetadata),f=Sn(e=>e.availableWorktrees),p=af(r),m=Q.useMemo(()=>{if(!p)return;let e=f.find(e=>af(e.path)===p);if(e)return e;for(let e of d.values())if(af(e.path)===p)return e},[f,p,d]),h=Q.useMemo(()=>{if(c)return d.get(c)??m;if(l?.open)return m},[c,m,l?.open,d]),g=So(r??null),_=Oo(r??null),v=on(e=>c?e.getAttachment(c):void 0),y=v?er(v):[],b=v&&!v.degraded&&!v.legacy?v.worktreeRoot??void 0:void 0,x=pd(r,h,_?.current??void 0),S=Co(r??null),C=wo(r??null),w=To(r??null),T=Do(r??null),{setActiveDirectory:E,fetchAll:D,ensureAll:O,fetchStatus:k,fetchBranches:A,fetchLog:j,setLogMaxCount:M,prefetchDiffs:N,moveStatusPathsOptimistically:P,restoreStatus:F,bumpIndexRevision:I}=ko(ue(e=>({setActiveDirectory:e.setActiveDirectory,fetchAll:e.fetchAll,ensureAll:e.ensureAll,fetchStatus:e.fetchStatus,fetchBranches:e.fetchBranches,fetchLog:e.fetchLog,setLogMaxCount:e.setLogMaxCount,prefetchDiffs:e.prefetchDiffs,moveStatusPathsOptimistically:e.moveStatusPathsOptimistically,restoreStatus:e.restoreStatus,bumpIndexRevision:e.bumpIndexRevision}))),L=q(e=>e.isMobile),R=q(e=>e.openContextFileDiff),z=q(e=>e.navigateToDiff),B=q(e=>e.setRightSidebarOpen),V=Q.useRef(null),ee=Q.useRef(null),H=Q.useRef(null),te=Q.useRef(null),ne=Q.useRef(!0);Q.useEffect(()=>()=>{ne.current=!1},[]);let re=Q.useCallback(()=>{ee.current!==null&&(window.clearTimeout(ee.current),ee.current=null)},[]),U=Q.useCallback(e=>{re(),ee.current=window.setTimeout(()=>{ee.current=null,af(e)===af(r)&&k(e,n,{silent:!0})},Xd)},[re,r,k,n]);Q.useEffect(()=>re,[re]);let ie=Q.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),ae=Q.useCallback(()=>{H.current===null&&(H.current=window.setTimeout(()=>{H.current=null,te.current?.()},0))},[]),W=Q.useCallback(async(e,t,r)=>{if(t===`stage`){if(n.stageGitFiles){await n.stageGitFiles(e,r);return}await Promise.all(r.map(t=>n.stageGitFile(e,t)));return}if(n.unstageGitFiles){await n.unstageGitFiles(e,r);return}await Promise.all(r.map(t=>n.unstageGitFile(e,t)))},[n]),oe=Q.useMemo(()=>Yd({runMutation:({directory:e,direction:t,paths:n})=>W(e,t,n),onMutationComplete:({directory:e})=>{I(e),U(e)},onMutationError:({directory:e,direction:n,rollback:r},i)=>{r?.(),I(e),U(e);let a=t(n===`stage`?`gitView.toast.stageFileFailed`:`gitView.toast.unstageFileFailed`);X.error(i instanceof Error?i.message:a)},onPathsComplete:e=>{Ie(t=>{let n=new Set(t);return e.forEach(e=>n.delete(e)),n})},scheduleFlush:ae}),[I,W,ae,U,t]);Q.useEffect(()=>(te.current=oe.flush,()=>{te.current=null}),[oe]),Q.useEffect(()=>()=>oe.clear(),[oe]),Q.useEffect(()=>ie,[ie]),Q.useEffect(()=>{if(!e)return;if(!r){a(null),s(!1);return}let t=!1,n=Tn(r);n&&a(n.status);let i=Pn((e,n)=>{t||af(e)===af(r)&&a(n.status)});return Nr(r).then(e=>{if(t)return;Bn(r,e);let n=Tn(r);a(n?.status??e.status)}).catch(()=>{!t&&!Tn(r)&&a(null)}),()=>{t=!0,i()}},[e,r]),Q.useEffect(()=>{let e=V.current;V.current=i,!(!r||!n)&&(e===`pending`&&i===`ready`&&(s(!0),D(r,n).finally(()=>{window.setTimeout(()=>{s(!1)},1200)})),i===`failed`&&(u(null),s(!1)))},[r,D,n,u,i]);let se=af(l?.bootstrapPendingDirectory??null),ce=!!(r&&se&&se===af(r)),G=!!(r&&(i===`pending`||ce))||o,le=Q.useMemo(()=>r?nf.get(r)??null:null,[r]),de=Qn(e=>e.settingsGitmojiEnabled),[fe,pe]=Q.useState(null),{gitmojis:me}=dd(de);Q.useEffect(()=>{let e=b||x?.projectDirectory;if(!e){pe(null);return}let t=!1;return ea(e).then(e=>{if(t)return;let n=e.trim();pe(n&&n!==`HEAD`?n:null)}).catch(()=>{t||pe(null)}),()=>{t=!0}},[b,x?.projectDirectory]);let[he,ge]=Q.useState(le?.commitMessage??``),[_e,ve]=Q.useState([]),[ye,be]=Q.useState(!1),xe=hc(_)&&!ye,[Se,Ce]=Q.useState(!1),we=Q.useRef(null),[Te,Ee]=Q.useState(null),[De,Oe]=Q.useState(!1),[ke,Ae]=Q.useState(null),[je,Me]=Q.useState(25),{triggerFireworks:Ne}=$u(),[K,Pe]=Q.useState(new Set),[Fe,Ie]=Q.useState(new Set),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(le?.generatedHighlights??[]),Ue=Fe.size>0||oe.size()>0||oe.isRunning(),We=Q.useCallback(()=>{let e=we.current;e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight,behavior:`smooth`})})})},[]),Ge=Q.useCallback(()=>{He([])},[]),[Ke,qe]=Q.useState(new Set),[Je,Ye]=Q.useState(new Map),[Xe,Ze]=Q.useState(new Set),Qe=Q.useRef(Je),$e=Q.useRef(Xe),[et,tt]=Q.useState(null),[nt,rt]=Q.useState(null),[it,ot]=Q.useState(``),[st,ct]=Q.useState(null),[lt,ut]=Q.useState([]),[dt,ft]=Q.useState(!1),[pt,mt]=Q.useState([]),[ht,gt]=Q.useState(`merge`),[_t,vt]=Q.useState(null),[yt,bt]=Q.useState(!1),[xt,St]=Q.useState(100),Ct=Q.useMemo(()=>c?`yuri.conflict:${c}`:null,[c]),Et=Q.useCallback((e,t,n)=>{if(!Ct||typeof window>`u`)return;let r={directory:e,conflictFiles:t,operation:n};window.localStorage.setItem(Ct,JSON.stringify(r))},[Ct]),Dt=Q.useCallback(()=>{!Ct||typeof window>`u`||window.localStorage.removeItem(Ct)},[Ct]);Q.useEffect(()=>{if(!Ct||typeof window>`u`||!r)return;let e=window.localStorage.getItem(Ct);if(e)try{let t=JSON.parse(e);if(t.directory!==r){window.localStorage.removeItem(Ct);return}mt(t.conflictFiles??[]),gt(t.operation??`merge`),ft(!0)}catch{window.localStorage.removeItem(Ct)}},[Ct,r]);let Ot=Q.useCallback(e=>{wt(e).then(e=>{if(e.ok){X.success(t(`gitView.toast.commitHashCopied`));return}X.error(t(`gitView.toast.copyFailed`))})},[t]),kt=Q.useCallback(e=>{qe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);Q.useEffect(()=>{Qe.current=Je},[Je]),Q.useEffect(()=>{$e.current=Xe},[Xe]),Q.useEffect(()=>{if(!r||!n)return;let e=Array.from(Ke).filter(e=>!Qe.current.has(e)&&!$e.current.has(e));if(e.length===0)return;let t=!1;return Ze(t=>{let n=new Set(t);for(let t of e)n.add(t);return $e.current=n,n}),Promise.all(e.map(e=>n.getCommitFiles(r,e).then(t=>({hash:e,files:t.files})).catch(t=>(console.error(`Failed to fetch commit files:`,t),{hash:e,files:[]})))).then(e=>{t||(Ye(t=>{let n=new Map(t);for(let{hash:t,files:r}of e)n.set(t,r);return Qe.current=n,n}),Ze(t=>{let n=new Set(t);for(let{hash:t}of e)n.delete(t);return $e.current=n,n}))}),()=>{t=!0,Ze(t=>{let n=!1,r=new Set(t);for(let t of e)r.delete(t)&&(n=!0);return n?($e.current=r,r):t})}},[Ke,r,n]),Q.useEffect(()=>{r&&rf(r,{directory:r,commitMessage:he,generatedHighlights:Ve})},[he,r,Ve]),Q.useEffect(()=>{if(!e)return;if(!r||!n?.getRemoteUrl){rt(null);return}let t=!1;return n.getRemoteUrl(r).then(e=>{t||rt(e)}).catch(()=>{t||rt(null)}),()=>{t=!0}},[e,r,n]);let At=Q.useCallback(async()=>{if(!r||!n?.getRemotes){ut([]);return}try{let e=await n.getRemotes(r);ne.current&&ut(e)}catch{ne.current&&ut([])}},[r,n]);Q.useEffect(()=>{e&&At()},[e,At]),Q.useEffect(()=>{e&&r&&(E(r),O(r,n))},[e,r,E,O,n]),Q.useEffect(()=>{if(e&&r)return bn.onGitRefreshHint(e=>{af(e.directory)===af(r)&&k(r,n)})},[e,r,k,n]);let jt=Q.useCallback(async(e=!0)=>{if(r)try{await Promise.all([k(r,n),A(r,n,{force:!0})])}catch(n){if(e){let e=n instanceof Error?n.message:t(`gitView.toast.refreshRepositoryFailed`);X.error(e)}}},[r,n,k,A,t]),Mt=Q.useCallback(async()=>{r&&await j(r,n,je)},[r,n,j,je]),Nt=Q.useMemo(()=>!_||xe?[]:[..._.files??[]].sort((e,t)=>e.path.localeCompare(t.path)),[_,xe]),Y=Q.useMemo(()=>Nt.filter(of),[Nt]),Pt=Q.useMemo(()=>Nt.filter(sf),[Nt]),{deferredStagedCount:Ft,deferredUnstagedCount:It}=Q.useMemo(()=>{if(!xe||!_)return{deferredStagedCount:0,deferredUnstagedCount:0};let e=0,t=0;for(let n of _.files??[])of(n)&&(e+=1),sf(n)&&(t+=1);return{deferredStagedCount:e,deferredUnstagedCount:t}},[xe,_]);Q.useEffect(()=>{if(!r||Nt.length===0)return;let e=[],t=new Set,i=n=>{!n||t.has(n)||(t.add(n),e.push(n))};if(Y.forEach(e=>i(e.path)),_e.forEach(i),Nt.slice(0,Qd).forEach(e=>i(e.path)),e.length===0)return;let a=window.setTimeout(()=>{N(r,n,e,{maxFiles:Zd})},120);return()=>{window.clearTimeout(a)}},[Nt,r,n,N,Y,_e]);let Lt=e=>e?.pushed[0]?.remote||_?.tracking?.split(`/`)[0]||qt.find(e=>e.name===`origin`)?.name||qt[0]?.name||`origin`,Rt=async(e,i)=>{if(r){Ee(e);try{let a=e=>{let t=`${e.name}/`,n=_?.tracking?.startsWith(t)?_.tracking.slice(t.length):void 0;return{remote:e.name,branch:n,rebase:!0}};if(e===`fetch`){if(!i)throw Error(`No remote available for fetch`);await n.gitFetch(r,{remote:i.name}),X.success(t(`gitView.toast.fetchedFromRemote`,{name:i.name}))}else if(e===`pull`){if(!i)throw Error(`No remote available for pull`);let e=await n.gitPull(r,a(i));X.success(e.files.length===1?t(`gitView.toast.pulledFilesSingle`,{count:e.files.length,name:i.name}):t(`gitView.toast.pulledFilesPlural`,{count:e.files.length,name:i.name}))}else if(e===`push`){let e=await n.gitPush(r);X.success(t(`gitView.toast.pushedToUpstream`,{name:Lt(e)}))}else if(e===`sync`){if(!i)throw Error(`No remote available for sync`);let e=0,o=!1;await n.gitFetch(r,{remote:i.name});let s=await n.getGitStatus(r);if((s.behind??0)>0){if((s.files?.length??0)>0){X.error(t(`gitView.toast.commitOrStashBeforeSync`));return}e=(await n.gitPull(r,a(i))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),o=!0),e>0&&o?X.success(t(e===1?`gitView.toast.syncedPulledSingleAndPushed`:`gitView.toast.syncedPulledPluralAndPushed`,{count:e,name:i.name})):e>0?X.success(t(e===1?`gitView.toast.pulledFilesSingle`:`gitView.toast.pulledFilesPlural`,{count:e,name:i.name})):o?X.success(t(`gitView.toast.pushedToUpstream`,{name:i.name})):X.success(t(`gitView.toast.alreadyUpToDate`))}await jt(!1),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.syncActionFailed`,{action:e===`sync`?t(`gitView.sync.syncChanges`):e===`pull`?t(`gitView.sync.pull`):e});X.error(r)}finally{Ee(null)}}},zt=async(e={})=>{if(!r)return;if(!he.trim()){X.error(t(`gitView.toast.enterCommitMessage`));return}let i=Y.map(e=>e.path).sort();if(i.length===0){X.error(t(`gitView.toast.stageFileToCommit`));return}let a=e.pushAfter?`commitAndPush`:`commit`;Ae(a);try{if(await n.createGitCommit(r,he.trim(),{files:i,stageFiles:[]}),I(r),X.success(t(`gitView.toast.commitCreated`)),ge(``),Ge(),await jt(),e.pushAfter){let e=_?.tracking?.split(`/`)[0],i=qt.find(t=>t.name===e)??qt[0];if(!i)throw Error(t(`mobile.changes.noRemote`));Ee(`sync`);let a=`${i.name}/`,o=_?.tracking?.startsWith(a)?_.tracking.slice(a.length):void 0;await n.gitFetch(r,{remote:i.name});let s=await n.getGitStatus(r);if((s.behind??0)>0){if((s.files?.length??0)>0){X.error(t(`gitView.toast.commitOrStashBeforeSync`)),await jt(!1);return}await n.gitPull(r,{remote:i.name,branch:o,rebase:!0})}let c=await n.getGitStatus(r),l;(c.ahead??0)>0&&(l=await n.gitPush(r)),X.success(t(`gitView.toast.pushedToUpstream`,{name:Lt(l)})),Ne(),await jt(!1)}else await jt(!1);await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createCommitFailed`);X.error(n)}finally{Ae(null),e.pushAfter&&Ee(null)}},Bt=Q.useCallback(async()=>{if(!r)return;let e=Y.map(e=>e.path).sort();if(e.length===0){X.error(t(`gitView.toast.stageFileToDescribe`));return}console.error(`[git-generation][browser] generate button clicked`,{directory:r,selectedFiles:e.length}),Be(!0);try{let{message:t}=await kr(r,e),n=t.subject?.trim()??``,i=Array.isArray(t.highlights)?t.highlights:[];if(n){let e=n;if(de&&me.length>0){let t=ef(n,me);if(t){let{code:r,emoji:i}=t;!n.startsWith(r)&&!n.startsWith(i)&&(e=`${r} ${n}`)}}ge(e)}He(i),We()}catch(e){console.error(`[git-generation][browser] GitView generate handler failed`,{message:e instanceof Error?e.message:String(e),error:e});let n=e instanceof Error?e.message:t(`gitView.toast.generateCommitMessageFailed`);X.error(n)}finally{Be(!1)}},[r,Y,de,me,We,t]),Vt=e=>e.reason===`attention`?`${e.attentionReason} in progress`:e.reason===`missing`?`worktree is missing`:`worktree is invalid`,Ht=async(e,i)=>{if(!r||!_)return;let a=yn(v);if(a.length>0){X.error(t(`gitView.toast.cannotCreateBranch`,{reason:Vt(a[0])}));return}let o=_.current??null,s=i?.name??`origin`;try{await n.createBranch(r,e,o??`HEAD`),X.success(t(`gitView.toast.createdBranch`,{name:e})),await n.checkoutBranch(r,e);let i=!1;try{await n.gitPush(r,{remote:s,branch:e,options:[`--set-upstream`]}),i=!0}catch(e){let n=e instanceof Error?e.message:`Unable to push new branch to ${s}.`;X.warning(t(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsxs)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:[`Upstream setup failed: `,n]})})}await jt(),await Mt(),i&&X.success(t(`gitView.toast.upstreamSet`,{branch:e,remote:s}))}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createBranchFailed`);throw X.error(n),e}},Ut=async(e,i)=>{if(!r)return;let a=yn(v);if(a.length>0){X.error(t(`gitView.toast.cannotRenameBranch`,{reason:Vt(a[0])}));return}try{await n.renameBranch(r,e,i),X.success(t(`gitView.toast.renamedBranch`,{oldName:e,newName:i})),await jt(),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.renameBranchFailed`,{oldName:e,newName:i});X.error(r)}},Wt=async e=>{if(!r)return;let i=yn(v);if(i.length>0){X.error(t(`gitView.toast.cannotCheckout`,{reason:Vt(i[0])}));return}let a=e.replace(/^remotes\//,``);if(_?.current!==a)try{await n.checkoutBranch(r,a),X.success(t(`gitView.toast.checkedOut`,{name:a})),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.checkoutFailed`,{name:a});X.error(n)}},Gt=Q.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),Kt=Q.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),qt=Q.useMemo(()=>{if(lt.length>0)return lt;let e=new Set,t=_?.tracking?.trim();t&&t.includes(`/`)&&e.add(t.split(`/`)[0]);for(let t of Kt){let n=t.indexOf(`/`);n>0&&e.add(t.slice(0,n))}return e.size===0&&nt&&e.add(`origin`),Array.from(e).map(e=>({name:e,fetchUrl:nt??``,pushUrl:nt??``}))},[lt,Kt,nt,_?.tracking]),Jt=Q.useMemo(()=>{let e=new Set(qt.map(e=>e.name)),t=t=>{if(!t)return``;let n=t.trim();if(!n||n===`HEAD`)return``;if(Gt.includes(n))return n;n.startsWith(`refs/heads/`)&&(n=n.slice(11)),n.startsWith(`heads/`)&&(n=n.slice(6)),n.startsWith(`remotes/`)&&(n=n.slice(8));let r=n.indexOf(`/`);if(r>0){let t=n.slice(0,r);if(e.has(t)){let e=n.slice(r+1).trim();e&&(n=e)}}return n};return t(typeof x?.createdFromBranch==`string`?x.createdFromBranch:``)||t(typeof fe==`string`?fe:``)||(Gt.includes(`main`)?`main`:Gt.includes(`master`)?`master`:Gt.includes(`develop`)?`develop`:`main`)},[qt,Gt,fe,x?.createdFromBranch]),Yt=Y.length,Xt=_?.current??null;Q.useEffect(()=>{if(!r||!n||!C?.all?.length||!Xt||!Jt||Xt===Jt){tt(null);return}let e=!1;return(async()=>{try{let t=await n.getGitLog(r,{from:Jt,to:`HEAD`,maxCount:je});if(e)return;let i=new Set((t?.all??[]).map(e=>e.hash).filter(e=>typeof e==`string`&&e.length>0));if(i.size===0){tt(null);return}let a=C.all.findIndex(e=>!i.has(e.hash));if(a===0){tt(null);return}if(a===-1){tt({insertBeforeIndex:C.all.length,branchName:Xt,direction:`up`});return}tt({insertBeforeIndex:a,branchName:Xt,direction:`up`})}catch{e||tt(null)}})(),()=>{e=!0}},[Jt,Xt,r,n,C,je]),Q.useEffect(()=>{vt(null)},[r]),Q.useEffect(()=>{if(st!==`graph`||!r){st!==`graph`&&vt(null);return}let e=!1;return bt(!0),n.getGitLog(r,{maxCount:xt,all:!0}).then(t=>{e||vt(t)}).catch(e=>{console.error(`Failed to fetch graph log:`,e)}).finally(()=>{e||bt(!1)}),()=>{e=!0}},[st,r,xt,n]);let Zt=Q.useCallback((e,t)=>{if(!r||e.length===0)return;let n=Array.from(new Set(e));Ie(e=>{let t=new Set(e);return n.forEach(e=>t.add(e)),t});let i=P(r,n,t);oe.enqueue({directory:r,direction:t,paths:new Set(n),rollback:()=>F(r,i)}),ae()},[r,oe,P,F,ae]),Qt=Q.useCallback(async e=>{if(r){Pe(t=>{let n=new Set(t);return n.add(e),n});try{await n.revertGitFile(r,e,{scope:`working`}),X.success(t(`gitView.toast.revertedFile`,{path:e})),await jt(!1)}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.revertFailed`);X.error(n)}finally{Pe(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,jt,n,t]),$t=Q.useCallback(async(e,i,a=`all`)=>{if(!r||e.length===0)return;let o=Array.from(new Set(e));if(Le||o.some(e=>K.has(e)))return;let s=new Set(Y.map(e=>e.path)),c=a===`all`&&o.some(e=>s.has(e));i&&Re(!0),Pe(e=>{let t=new Set(e);return o.forEach(e=>t.add(e)),t});let l=[];try{if(await Promise.all(o.map(async e=>{try{await n.revertGitFile(r,e,{scope:a})}catch(n){l.push({path:e,message:n instanceof Error?n.message:t(`gitView.toast.revertFailed`)})}})),c&&l.length<o.length&&I(r),await jt(!1),l.length===0)X.success(o.length===1?t(`gitView.toast.revertedFilesSingle`,{count:o.length}):t(`gitView.toast.revertedFilesPlural`,{count:o.length}));else if(l.length===o.length)X.error(l[0]?.message||t(`gitView.toast.revertFailed`));else{let e=o.length-l.length;X.warning(t(e===1?`gitView.toast.revertedSomeSingle`:`gitView.toast.revertedSomePlural`,{success:e,failed:l.length}))}}finally{Pe(e=>{let t=new Set(e);return o.forEach(e=>t.delete(e)),t}),i&&Re(!1)}},[I,r,n,Le,jt,K,Y,t]),en=Q.useCallback(async e=>{await $t(e,!0)},[$t]),tn=Q.useCallback(async e=>{await $t(e,!1,`working`)},[$t]),nn=Q.useCallback((e,t)=>{if(r&&!L){R(r,e,t);return}z(e,t),L&&B(!1)},[r,L,z,R,B]),rn=Q.useCallback(()=>Oe(!0),[]),an=Q.useMemo(()=>{let e=[];return Y.length>0&&e.push({id:`staged`,title:t(`gitView.changes.stagedTitle`),entries:Y,actionSymbol:`-`,actionAllLabel:t(`gitView.changes.unstageAllAria`),getActionLabel:e=>t(`gitView.changes.unstageFileAria`,{path:e}),onActionFile:e=>void Zt([e],`unstage`),onActionAll:e=>void Zt(e,`unstage`),onViewDiff:e=>nn(e,!0),onRevertFile:Qt,showRevertActions:!1,accent:!0}),Pt.length>0&&e.push({id:`unstaged`,title:t(`gitView.changes.title`),entries:Pt,actionSymbol:`+`,actionAllLabel:t(`gitView.changes.stageAllAria`),getActionLabel:e=>t(`gitView.changes.stageFileAria`,{path:e}),onActionFile:e=>void Zt([e],`stage`),onActionAll:e=>void Zt(e,`stage`),onViewDiff:e=>nn(e,!1),onRevertFile:Qt}),e},[Qt,nn,Zt,Y,t,Pt]),sn=Q.useCallback(e=>{if(e.length===0)return;let t=e.map(e=>e.trim()).filter(Boolean);if(t.length===0){Ge();return}ge(e=>{let n=e.trim();return`${n}${n.length>0?`
4
4
 
5
5
  `:``}${t.join(`
6
- `)}`.trim()}),Ge()},[Ge]),cn=Q.useCallback((e,t)=>{let n=t||e;ge(r=>{let i=r.trimStart();return i.startsWith(e)||t&&i.startsWith(t)?r:`${n.endsWith(` `)?n:`${n} `}${r}`.trimStart()}),ot(``),Ce(!1)},[]),ln=Q.useCallback(async()=>{if(r)try{ht===`merge`?(await n.abortMerge(r),X.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),X.success(t(`gitView.toast.rebaseAborted`))),Dt(),await jt(),await Mt()}catch(e){let t=e instanceof Error?e.message:`Failed to abort ${ht}`;X.error(t)}},[r,n,ht,jt,Mt,Dt,t]),un=Q.useMemo(()=>_?.files?_.files.some(e=>e.index===`U`||e.working_dir===`U`||e.index===`A`&&e.working_dir===`A`||e.index===`D`&&e.working_dir===`D`):!1,[_?.files]),dn=Q.useCallback(async()=>{if(r)try{let e=!!_?.mergeInProgress?.head,i=!!(_?.rebaseInProgress?.headName||_?.rebaseInProgress?.onto);if(e){let e=await n.continueMerge(r);e.conflict?(mt(e.conflictFiles??[]),gt(`merge`),ft(!0),Et(r,e.conflictFiles??[],`merge`),X.error(t(`gitView.toast.mergeConflictsDetected`))):(Dt(),X.success(t(`gitView.toast.mergeCompleted`)),await jt(),await Mt())}else if(i){let e=await n.continueRebase(r);e.conflict?(mt(e.conflictFiles??[]),gt(`rebase`),ft(!0),Et(r,e.conflictFiles??[],`rebase`),X.error(t(`gitView.toast.rebaseConflictsDetected`))):(Dt(),X.success(t(`gitView.toast.rebaseStepCompleted`)),await jt(),await Mt())}}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.continueOperationFailed`);X.error(n)}},[r,n,_,jt,Mt,Et,Dt,t]),fn=Q.useCallback(async()=>{if(r)try{_?.mergeInProgress?.head?(await n.abortMerge(r),X.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),X.success(t(`gitView.toast.rebaseAborted`))),Dt(),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.abortOperationFailed`);X.error(n)}},[r,n,_,jt,Mt,Dt,t]),pn=Q.useCallback(()=>{if(!r)return;let e=_?.mergeInProgress?.head?`merge`:`rebase`,t=_?.files?.filter(e=>e.index===`U`||e.working_dir===`U`).map(e=>e.path)??[];t.length>0&&mt(t),gt(e),ft(!0)},[r,_]),mn=Q.useCallback(e=>{Me(e),r&&(M(r,e),j(r,n,e))},[r,j,n,M]),hn=Q.useCallback(e=>{St(e)},[]),gn=Q.useCallback(()=>{ct(null),r&&(k(r,n),A(r,n,{force:!0}),j(r,n,je))},[r,k,A,j,je,n]),_n=Q.useCallback(e=>{if(e.conflict){if(e.operation===`cherry-pick`||e.operation===`revert`){X.error(t(`gitView.history.actions.conflictToastTitle`),{description:t(`gitView.history.actions.conflictToastDescription`,{files:e.conflictFiles?.join(`, `)??`unknown files`})}),r&&(k(r,n),A(r,n,{force:!0}),j(r,n,je));return}mt(e.conflictFiles??[]),gt(e.operation),ft(!0),r&&Et(r,e.conflictFiles??[],e.operation)}},[t,mt,gt,ft,Et,r,k,A,j,je,n]);if(!r)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:t(`gitView.empty.selectSessionOrDirectory`)})});if(g===null||g===!0&&!_)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:t(`gitView.loading.checkingRepository`)})]})});if(g===!1)return G?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-4 text-center`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`mb-3 size-6 animate-spin text-muted-foreground`}),(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.worktreeSetupInProgress`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1 text-muted-foreground`,children:t(`gitView.empty.worktreeSetupDescription`)})]}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-4 text-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`mb-3 size-6 text-muted-foreground`}),(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.notGitRepository`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1 text-muted-foreground`,children:t(`gitView.empty.notGitRepositoryDescription`)}),y.includes(`open-without-worktree-features`)?(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:t(`gitView.empty.worktreeFeaturesUnavailable`)}):null]});let bn=_?x?(0,$.jsx)(Hs,{currentBranch:_.current,onRename:Ut,iconOnly:!0}):(0,$.jsx)(Nr,{currentBranch:_.current,localBranches:Gt,remoteBranches:Kt,branchInfo:S?.branches,onCheckout:Wt,onCreate:Ht,remotes:qt,iconOnly:!0}):null,Sn=_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Xs,{syncAction:Te,remotes:qt,onSync:e=>Rt(`sync`,e),disabled:!_,aheadCount:_.ahead,behindCount:_.behind,trackingRemoteName:_.tracking?.split(`/`)[0],hasUncommittedChanges:(_.files?.length??0)>0}),(0,$.jsxs)(Ua,{children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,"aria-label":t(`gitView.header.repositoryViews`),children:(0,$.jsx)(Z,{name:`git-repository`,className:`size-3.5`})})})}),(0,$.jsx)(la,{sideOffset:8,children:t(`gitView.header.repositoryViews`)})]}),(0,$.jsxs)(Pa,{align:`end`,children:[(0,$.jsxs)(Da,{onSelect:()=>ct(`history`),children:[(0,$.jsx)(Z,{name:`history`,className:`size-4`}),t(`gitView.history.title`)]}),(0,$.jsxs)(Da,{onSelect:()=>ct(`graph`),children:[(0,$.jsx)(Z,{name:`git-merge`,className:`size-4`}),t(`gitView.graph.title`)]}),(0,$.jsxs)(Da,{onSelect:rn,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`size-4`}),t(`gitView.stashes.title`)]})]})]})]}):null,Cn=_?(0,$.jsxs)($.Fragment,{children:[bn,Sn]}):null;return(0,$.jsxs)(`div`,{className:J(`flex h-full flex-col overflow-hidden`),children:[r&&(_?.mergeInProgress?.head||_?.rebaseInProgress?.headName||_?.rebaseInProgress?.onto)&&(0,$.jsx)(Kd,{mergeInProgress:_?.mergeInProgress,rebaseInProgress:_?.rebaseInProgress,onContinue:dn,onAbort:fn,onResolveWithAI:pn,hasUnresolvedConflicts:un,isLoading:w}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full min-h-0 flex flex-col`,children:(0,$.jsx)(`div`,{className:J(`min-w-0 min-h-0 h-full flex flex-col`),children:(0,$.jsx)(fo,{as:po,ref:we,outerClassName:`flex-1 min-h-0`,className:J(`px-4`,`pt-2 pb-4`),disableHorizontal:!0,preventOverscroll:!0,children:(0,$.jsx)(`div`,{className:`flex h-full min-h-0 flex-col gap-2`,children:xe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex h-8 shrink-0 items-center bg-background pr-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:t(`gitView.changes.deferredTitle`,{count:_?.files?.length??0})}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Cn})]}),(0,$.jsx)(rc,{stagedCount:Ft,unstagedCount:It,onLoad:()=>be(!0)})]}):(Y?.length??0)>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,$.jsx)(Ic,{groups:on,diffStats:_?.diffStats,revertingPaths:K,isRevertingAll:Le,onVisiblePathsChange:ve,onRevertAll:en,onRevertDirectory:tn,headerBackgroundClassName:`bg-background`,headerLeadingActions:bn,headerActions:Sn})}),(0,$.jsx)(hc,{stagedCount:Yt,commitMessage:he,onCommitMessageChange:ge,generatedHighlights:Ve,onInsertHighlights:sn,onGenerateMessage:Bt,isGeneratingMessage:ze,onCommit:()=>zt({pushAfter:!1}),onCommitAndPush:()=>zt({pushAfter:!0}),commitAction:ke,hasPendingIndexMutation:Ue,gitmojiEnabled:de,onOpenGitmojiPicker:()=>Ce(!0)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex h-8 shrink-0 items-center bg-background pr-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.cleanTitle`)}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Cn})]}),(0,$.jsx)(hd,{onOpenStashes:()=>Oe(!0)})]})})})})})}),(0,$.jsx)(pr,{open:st!==null,onOpenChange:e=>{e||ct(null)},children:(0,$.jsxs)(ur,{className:`max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,$.jsxs)(cr,{children:[(0,$.jsx)(dr,{children:t(st===`graph`?`gitView.graph.title`:`gitView.history.title`)}),(0,$.jsx)(fr,{children:t(`gitView.history.dialogDescription`)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,$.jsx)(Pd,{mode:st===`graph`?`graph`:`history`,log:st===`graph`?_t??C:C,isLogLoading:st===`graph`&&yt||T,logMaxCount:st===`graph`?xt:je,onLogMaxCountChange:st===`graph`?hn:mn,expandedCommitHashes:Ke,onToggleCommit:kt,commitFilesMap:Je,loadingCommitHashes:Xe,onCopyHash:Ot,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:`h-full max-h-none`,branchDivider:st===`graph`?null:et,onConflict:st===`graph`?_n:void 0,onActionSuccess:st===`graph`?gn:void 0})})]})}),(0,$.jsx)(pd,{open:De,onOpenChange:Oe,directory:r,hasUncommittedChanges:(_?.files?.length??0)>0,hasStagedChanges:Nt.length>0,uncommittedFileCount:_?.files?.length??0,onChanged:async e=>{r&&e?.affectsIndex&&I(r),await jt(!1),await Mt()}}),(0,$.jsx)(pr,{open:Se,onOpenChange:Ce,children:(0,$.jsxs)(ur,{className:`max-w-md p-0 overflow-hidden`,children:[(0,$.jsx)(cr,{className:`px-4 pt-4`,children:(0,$.jsx)(dr,{children:t(`gitView.gitmoji.title`)})}),(0,$.jsxs)(fi,{className:`h-[420px]`,children:[(0,$.jsx)(Ni,{placeholder:t(`gitView.gitmoji.searchPlaceholder`),value:it,onValueChange:ot}),(0,$.jsxs)(si,{children:[(0,$.jsx)(Ii,{children:t(`gitView.gitmoji.empty`)}),(0,$.jsx)(Di,{children:(me.length===0?[]:me.filter(e=>{let t=it.trim().toLowerCase();return!t||e.emoji.includes(t)||e.code.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)})).map(e=>(0,$.jsxs)(yi,{onSelect:()=>cn(e.emoji,e.code),children:[(0,$.jsx)(`span`,{className:`text-lg`,children:e.emoji}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.code}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.description})]},e.code))})]})]})]})}),r&&(0,$.jsx)(zd,{open:dt,onOpenChange:ft,conflictFiles:pt,directory:r,operation:ht,onAbort:ln,onClearState:Dt})]})},sf=1,cf=8e3,lf={refreshAuth:()=>r(),clearUrlAuthToken:n,openSocket:e=>Re(c().websocket(Ia(e)))},uf=class{providerId;handlers;dependencies;socket=null;pendingFrame=null;reconnectTimer=null;failures=0;generation=0;disposed=!1;ended=!1;constructor(e,t,n=lf){this.providerId=e,this.handlers=t,this.dependencies=n}start(){this.handlers.onConnection({status:`connecting`}),this.connect()}dispose(){this.disposed=!0,this.generation+=1,this.cancelReconnect();let e=this.socket;this.socket=null,e?.close()}ack(e){this.send({type:`ack`,seq:e})}sendInput(e){return e.length!==0&&this.send({type:`input`,events:e})}release(){this.send({type:`release`})}resize(e,t){e<1||t<1||this.send({type:`resize`,width:Math.round(e),height:Math.round(t)})}retry(){this.disposed||(this.ended=!1,this.failures=0,this.generation+=1,this.socket?.close(),this.socket=null,this.handlers.onConnection({status:`connecting`}),this.connect())}send(e){let t=this.socket;if(!t||t.readyState!==sf)return!1;try{return t.send(JSON.stringify(e)),!0}catch{return!1}}async connect(){if(this.disposed||this.ended)return;let e=this.generation;try{await this.dependencies.refreshAuth()}catch{this.scheduleReconnect();return}if(e!==this.generation||this.disposed||this.ended)return;let t;try{t=this.dependencies.openSocket(this.providerId)}catch{this.scheduleReconnect();return}t.binaryType=`arraybuffer`,this.socket=t;let n=!1;t.onopen=()=>{this.socket===t&&(n=!0,this.failures=0,this.pendingFrame=null,this.handlers.onConnection({status:`open`}))},t.onmessage=e=>{this.socket===t&&this.handleMessage(e.data)},t.onerror=()=>{this.dependencies.clearUrlAuthToken()},t.onclose=()=>{this.socket===t&&(this.socket=null),!(this.disposed||this.ended)&&(n&&(this.failures=Math.max(this.failures,1)),this.scheduleReconnect())}}handleMessage(e){if(e instanceof ArrayBuffer){let t=this.pendingFrame;if(this.pendingFrame=null,!t||e.byteLength!==t.bytes)return;this.handlers.onFrame({...t,bytes:e});return}if(typeof e!=`string`)return;let t;try{t=JSON.parse(e)}catch{return}let n=Ga(t);n&&this.applyHostMessage(n)}applyHostMessage(e){if(e.type===`frame`){this.pendingFrame=e;return}if(e.type===`control`){this.handlers.onControl({controller:e.controller,mine:e.mine});return}e.type===`ended`&&(this.ended=!0,this.cancelReconnect(),this.handlers.onConnection({status:`ended`,reason:e.reason}),this.handlers.onEnded?.(e.reason),this.socket?.close())}scheduleReconnect(){if(this.disposed||this.ended||this.reconnectTimer)return;this.failures+=1;let e=this.failures;this.handlers.onConnection({status:`reconnecting`,attempt:e});let t=Math.min(cf,250*2**Math.min(e,5));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},t)}cancelReconnect(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}},df=250,ff=e=>({alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey}),pf=e=>(e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()===`v`,mf=(e,t)=>new uf(e,t),hf=({provider:e,clientFactory:t=mf})=>{let{t:n}=wt(),r=Q.useRef(null),i=Q.useRef(null),a=Q.useRef(null),o=Q.useRef(null),s=Q.useRef([]),c=Q.useRef(null),l=Q.useRef({controller:`none`,mine:!1}),u=Q.useRef(null),[d,f]=Q.useState({status:`connecting`}),[p,m]=Q.useState({controller:`none`,mine:!1}),[h,g]=Q.useState(``),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),C=_t(e=>{l.current=e,m(e)}),w=_t(async e=>{let t=i.current,n=a.current;if(!(!t||!n))try{let n=await createImageBitmap(new Blob([e.bytes],{type:e.mime}));(t.width!==e.width||t.height!==e.height)&&(t.width=e.width,t.height=e.height),t.getContext(`2d`)?.drawImage(n,0,0,e.width,e.height),n.close(),o.current={width:e.width,height:e.height},b(!0),g(e.title??``),v(e.agentActive)}catch{}finally{n.ack(e.seq)}}),T=Q.useRef({onFrame:e=>{w(e)},onControl:C,onConnection:f});T.current={onFrame:e=>{w(e)},onControl:C,onConnection:f};let E=Q.useRef(t);E.current=t,Q.useEffect(()=>{if(!e.surface)return;let t=E.current(e.id,{onFrame:e=>{T.current.onFrame(e)},onControl:e=>{T.current.onControl(e)},onConnection:e=>{T.current.onConnection(e)}});return a.current=t,t.start(),()=>{t.dispose(),a.current===t&&(a.current=null),c.current!==null&&cancelAnimationFrame(c.current),c.current=null,s.current=[],o.current=null,b(!1),f({status:`connecting`}),C({controller:`none`,mine:!1})}},[e.id,e.surface,C]);let D=_t(()=>{let t=r.current;!t||!e.surface||(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null;let e=t.getBoundingClientRect(),n=window.devicePixelRatio||1,r=Math.round(e.width*n),i=Math.round(e.height*n);r>0&&i>0&&a.current?.resize(r,i)},df))});gt(e.surface?r:null,D);let O=_t(e=>{s.current.push(e),c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;let e=s.current;s.current=[],a.current?.sendInput(e)}))}),k=e=>{let t=i.current,n=o.current;if(!t||!n)return null;let r=t.getBoundingClientRect();return r.width===0||r.height===0?null:{x:Math.round((e.clientX-r.left)/r.width*n.width),y:Math.round((e.clientY-r.top)/r.height*n.height)}},A=e=>t=>{if(!y||e===`move`&&t.buttons===0&&!(l.current.controller===`user`&&l.current.mine))return;let n=k(t);n&&(e===`down`?(r.current?.focus(),t.currentTarget.setPointerCapture(t.pointerId)):e===`up`&&t.currentTarget.hasPointerCapture(t.pointerId)&&t.currentTarget.releasePointerCapture(t.pointerId),t.preventDefault(),O({type:`pointer`,action:e,x:n.x,y:n.y,button:e===`move`?-1:t.button,buttons:t.buttons,modifiers:ff(t)}))},j=e=>{if(!y)return;let t=k(e);t&&(e.preventDefault(),O({type:`wheel`,x:t.x,y:t.y,deltaX:e.deltaX,deltaY:e.deltaY,modifiers:ff(e)}))},M=e=>t=>{!y||pf(t)||(t.preventDefault(),t.stopPropagation(),O({type:`key`,action:e,key:t.key,code:t.code,modifiers:ff(t)}))},N=e=>{if(!y)return;let t=e.clipboardData.getData(`text/plain`);e.preventDefault(),t&&O({type:`text`,text:t})},P=_t(()=>{a.current?.release()}),F=_t(()=>{a.current?.retry()});if(!e.surface)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:n(`layout.browserProvider.noSurface`,{name:e.name})});let I=d.status===`connecting`?`layout.browserProvider.status.connecting`:d.status===`reconnecting`?`layout.browserProvider.status.reconnecting`:d.status===`ended`?d.reason===`service-stopped`?`layout.browserProvider.ended.service-stopped`:d.reason===`extension-unavailable`?`layout.browserProvider.ended.extension-unavailable`:`layout.browserProvider.ended.host-shutdown`:p.controller===`user`?p.mine?`layout.browserProvider.status.youControl`:`layout.browserProvider.status.otherControls`:p.controller===`agent`||_?`layout.browserProvider.status.agentWorking`:x?`layout.browserProvider.status.readyFocused`:`layout.browserProvider.status.ready`,L=p.controller===`user`&&p.mine;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2 border-b border-border px-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-foreground`,title:h||e.name,children:h||e.name}),(0,$.jsx)(`span`,{className:J(`shrink-0 truncate text-xs`,L?`text-foreground`:`text-muted-foreground`),"aria-live":`polite`,children:n(I)}),L?(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:P,children:n(`layout.browserProvider.handBack`)}):null,d.status===`ended`?(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:F,children:n(`layout.browserProvider.retry`)}):null]}),(0,$.jsxs)(`div`,{ref:r,tabIndex:0,role:`application`,"aria-label":n(`layout.browserProvider.canvasAria`,{name:e.name}),className:J(`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden outline-none`,x&&`ring-1 ring-inset ring-[var(--interactive-selection-border)]`),onFocus:()=>S(!0),onBlur:()=>S(!1),onKeyDown:M(`down`),onKeyUp:M(`up`),onPaste:N,children:[(0,$.jsx)(`canvas`,{ref:i,className:J(`max-h-full max-w-full`,y?`block`:`hidden`,p.controller===`user`&&!p.mine?`cursor-not-allowed`:`cursor-default`),onPointerDown:A(`down`),onPointerMove:A(`move`),onPointerUp:A(`up`),onWheel:j,onContextMenu:e=>e.preventDefault()}),!y||d.status!==`open`?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:n(d.status===`ended`?d.reason===`service-stopped`?`layout.browserProvider.ended.service-stopped`:d.reason===`extension-unavailable`?`layout.browserProvider.ended.extension-unavailable`:`layout.browserProvider.ended.host-shutdown`:d.status===`reconnecting`?`layout.browserProvider.status.reconnecting`:`layout.browserProvider.status.connecting`)}):null]})]})},gf=(e,t)=>{let n=lt(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},_f=(e,t,n=10)=>{let r=ut(e);if(!r||n<1)return[];let i=new Set,a=[];for(let e of Object.values(t))if(e)for(let t of e){if(t.type!==`directory`)continue;let e=ut(t.path);if(!e||i.has(e))continue;let o=gf(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},vf=e=>e.some(e=>!!ut(e)),yf=(e,t)=>{let n=new Set(t.map(e=>ut(e)).filter(Boolean));return e.filter(e=>!n.has(e))},bf=(e,t,n)=>t.length===0?e.length===0:yf(e,t).length>0?!1:t.every(e=>n.has(ut(e))),xf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),Sf=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},Cf=(e,t)=>{let n=Sf(t),r=Sf(e).replace(/\/+$/,``);return n===r?`.`:!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},wf=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Tf=new Set([`node_modules`]),Ef=e=>Tf.has(e),Df=e=>{let t=Sf(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Of=8,kf=new Map,Af=e=>{let t=kf.get(e);return t?(t.touchedAt=Date.now(),kf.delete(e),kf.set(e,t),t):null},jf=e=>{let t=kf.get(e);if(t)return t.touchedAt=Date.now(),t;if(kf.size>=Of){let e=kf.keys().next().value;e!==void 0&&kf.delete(e)}let n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return kf.set(e,n),n},Mf=e=>{kf.delete(e)},Nf=(e,t)=>(0,$.jsx)(Bi,{filePath:e,extension:t,className:`size-3.5`}),Pf=e=>{let t=(0,fl.c)(3),{status:n}=e,r;t[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)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},Ff=Q.memo(e=>{let t=(0,fl.c)(73),{node:n,root:r,isExpanded:i,isActive:a,status:o,badge:s,permissions:c,downloadFile:l,onSelect:u,onToggle:d,onRevealPath:f,onOpenDialog:p}=e,{t:m}=wt(),h=n.type===`directory`,{canRename:g,canCreateFile:_,canCreateFolder:v,canDelete:y,canReveal:b}=c,[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),T;t[0]!==_||t[1]!==v||t[2]!==y||t[3]!==g||t[4]!==b?(T=e=>{!g&&!_&&!v&&!y&&!b||(e?.preventDefault(),w(!0))},t[0]=_,t[1]=v,t[2]=y,t[3]=g,t[4]=b,t[5]=T):T=t[5];let E=T,D;t[6]!==h||t[7]!==n||t[8]!==u||t[9]!==d?(D=()=>{h?d(n.path):u(n)},t[6]=h,t[7]=n,t[8]=u,t[9]=d,t[10]=D):D=t[10];let O=D,k;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(k=e=>{e.stopPropagation(),w(!1),S(!0)},t[11]=k):k=t[11];let A=k,j;t[12]!==_||t[13]!==v||t[14]!==y||t[15]!==g||t[16]!==b||t[17]!==l||t[18]!==h||t[19]!==n||t[20]!==p||t[21]!==f||t[22]!==m?(j=e=>{let{Item:t,Separator:r}=e;return(0,$.jsxs)($.Fragment,{children:[g&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`rename`,n)},children:[(0,$.jsx)(Z,{name:`edit`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),Ct(n.path).then(e=>{e.ok||X.error(m(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.copyPath`)]}),!h&&l&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),l(n.path).catch(e=>{console.error(`Download failed:`,e),X.error(m(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(Z,{name:`download`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.save`)]}),b&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),f(n.path)},children:[(0,$.jsx)(Z,{name:`folder-received`,className:`mr-2 h-4 w-4`}),` `,m(Mt())]}),h&&(_||v)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(r,{}),_&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`createFile`,n)},children:[(0,$.jsx)(Z,{name:`file-add`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.newFile`)]}),v&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`createFolder`,n)},children:[(0,$.jsx)(Z,{name:`folder-add`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.newFolder`)]})]}),y&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(r,{}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`delete`,n)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.delete`)]})]})]})},t[12]=_,t[13]=v,t[14]=y,t[15]=g,t[16]=b,t[17]=l,t[18]=h,t[19]=n,t[20]=p,t[21]=f,t[22]=m,t[23]=j):j=t[23];let M=j,N;t[24]!==n.path||t[25]!==r?(N=e=>{let t=Cf(r,n.path);!t||t===`.`||(e.dataTransfer.setData(`application/x-yuri-file-path`,t),e.dataTransfer.effectAllowed=`copy`)},t[24]=n.path,t[25]=r,t[26]=N):N=t[26];let P=N,F;t[27]===E?F=t[28]:(F=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:E}),t[27]=E,t[28]=F);let I=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,L;t[29]===I?L=t[30]:(L=J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,I,`cursor-grab active:cursor-grabbing`),t[29]=I,t[30]=L);let R;t[31]!==h||t[32]!==i||t[33]!==n.extension||t[34]!==n.path?(R=h?i?(0,$.jsx)(Z,{name:`folder-open-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`folder-3-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):Nf(n.path,n.extension),t[31]=h,t[32]=i,t[33]=n.extension,t[34]=n.path,t[35]=R):R=t[35];let z;t[36]!==n.name||t[37]!==n.path?(z=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,title:n.path,children:n.name}),t[36]=n.name,t[37]=n.path,t[38]=z):z=t[38];let B;t[39]!==h||t[40]!==o?(B=!h&&o&&(0,$.jsx)(Pf,{status:o}),t[39]=h,t[40]=o,t[41]=B):B=t[41];let V;t[42]!==s||t[43]!==h?(V=h&&s&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[s.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,s.modified]}),s.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,s.added]})]}),t[42]=s,t[43]=h,t[44]=V):V=t[44];let ee;t[45]!==E||t[46]!==P||t[47]!==O||t[48]!==z||t[49]!==B||t[50]!==V||t[51]!==L||t[52]!==R?(ee=(0,$.jsxs)(`button`,{type:`button`,onClick:O,onContextMenu:E,draggable:!0,onDragStart:P,className:L,children:[R,z,B,V]}),t[45]=E,t[46]=P,t[47]=O,t[48]=z,t[49]=B,t[50]=V,t[51]=L,t[52]=R,t[53]=ee):ee=t[53];let H;t[54]!==_||t[55]!==v||t[56]!==y||t[57]!==g||t[58]!==b||t[59]!==x||t[60]!==M||t[61]!==m?(H=(g||_||v||y||b)&&(0,$.jsx)(`div`,{className:`absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100`,children:(0,$.jsxs)(Ua,{open:x,onOpenChange:S,children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:A,title:m(`sidebarFilesTree.actions.fileMenuTitle`),"aria-label":m(`sidebarFilesTree.actions.fileMenuTitle`),children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`h-4 w-4`})})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:m(`sidebarFilesTree.actions.fileMenuTitle`)})]}),(0,$.jsx)(Pa,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>S(!1),children:M({Item:Da,Separator:La})})]})}),t[54]=_,t[55]=v,t[56]=y,t[57]=g,t[58]=b,t[59]=x,t[60]=M,t[61]=m,t[62]=H):H=t[62];let te;t[63]!==ee||t[64]!==H||t[65]!==F?(te=(0,$.jsxs)(Uc,{render:F,children:[ee,H]}),t[63]=ee,t[64]=H,t[65]=F,t[66]=te):te=t[66];let ne;t[67]===M?ne=t[68]:(ne=(0,$.jsx)(Wc,{className:`min-w-[180px]`,children:M({Item:Gc,Separator:Hc})}),t[67]=M,t[68]=ne);let re;return t[69]!==C||t[70]!==te||t[71]!==ne?(re=(0,$.jsxs)(Vc,{open:C,onOpenChange:w,children:[te,ne]}),t[69]=C,t[70]=te,t[71]=ne,t[72]=re):re=t[72],re},(e,t)=>e.node===t.node&&e.root===t.root&&e.isExpanded===t.isExpanded&&e.isActive===t.isActive&&e.status===t.status&&e.badge===t.badge&&e.permissions===t.permissions&&e.downloadFile===t.downloadFile&&e.onSelect===t.onSelect&&e.onToggle===t.onToggle&&e.onRevealPath===t.onRevealPath&&e.onOpenDialog===t.onOpenDialog),If=()=>{let{t:e}=wt(),{files:t}=at(),n=Qo()??``,r=Sf(n.trim()),i=T(),a=x(),o=Fe(e=>e.searchFiles),s=q(e=>e.openContextFile),c=Eo(n),[l,u]=Q.useState(``),d=wo(l,200),f=Q.useRef(null),[p,m]=Q.useState([]),[h,g]=Q.useState(!1),[_,v]=Q.useState({}),[y,b]=Q.useState({}),S=Q.useRef(new Set),C=Q.useRef(new Set),w=Q.useRef(null),E=Q.useRef(!1);Q.useEffect(()=>{if(!r){v({}),b({}),S.current=new Set;return}let e=Af(r);e?(v({...e.childrenByDir}),b({...e.loadErrorsByDir}),S.current=new Set(e.loadedDirs)):(v({}),b({}),S.current=new Set)},[r]),Q.useEffect(()=>{if(!r)return;let e=jf(r);e.childrenByDir=_},[r,_]),Q.useEffect(()=>{if(!r)return;let e=jf(r);e.loadErrorsByDir=y},[r,y]),Q.useEffect(()=>{if(!r)return;let e=jf(r);e.loadedDirs=new Set(S.current)},[r,_,y]),Q.useEffect(()=>()=>{if(!r)return;let e=kf.get(r);e&&e.loadedDirs.size===0&&Object.keys(e.childrenByDir).length===0&&Mf(r)},[r]);let D=Q.useMemo(()=>[],[]),O=Q.useMemo(()=>[],[]),k=vo(e=>r?e.byRoot[r]?.expandedPaths??D:D),A=vo(e=>r?e.byRoot[r]?.selectedPath??null:null),j=vo(e=>e.setSelectedPath),M=vo(e=>e.addOpenPath),N=vo(e=>e.removeOpenPathsByPrefix),P=vo(e=>e.removeExpandedPathsByPrefix),F=vo(e=>e.toggleExpandedPath),I=vo(e=>e.expandPaths),L=q(e=>r?e.contextPanelByDirectory[r]?.tabs??O:O),R=Q.useMemo(()=>new Set(L.map(e=>e.mode===`file`?e.targetPath:null).filter(e=>typeof e==`string`&&e.length>0).map(e=>Sf(e))),[L]),[z,B]=Q.useState(null),[V,ee]=Q.useState(null),[H,te]=Q.useState(``),[ne,re]=Q.useState(!1),U=!!t.writeFile,ie=!!t.createDirectory,ae=!!t.rename,W=!!t.delete,oe=!!t.revealPath,se=Q.useMemo(()=>({canRename:ae,canCreateFile:U,canCreateFolder:ie,canDelete:W,canReveal:oe}),[ae,U,ie,W,oe]),ce=Q.useCallback(n=>{t.revealPath&&t.revealPath(n).catch(()=>{X.error(e(`sidebarFilesTree.toast.revealFailed`))})},[t,e]),G=Q.useCallback((e,t)=>{B(e),ee(t),te(e===`rename`&&t.name||``),re(!1)},[]),le=Q.useCallback((e,t)=>xf(t.filter(e=>e&&typeof e.name==`string`&&e.name.length>0).filter(e=>i||!e.name.startsWith(`.`)).filter(e=>a||!Ef(e.name)).map(t=>{let n=t.name,r=Sf(t.path||``),i=r?wf(r)?r:Sf(`${e}/${r}`):Sf(`${e}/${n}`),a=t.isDirectory?`directory`:`file`;return{name:n,path:i,type:a,extension:a===`file`&&n.includes(`.`)?n.split(`.`).pop()?.toLowerCase():void 0}})),[a,i]),ue=Q.useCallback(async(e,n)=>{let r=Sf(e.trim());if(!r||S.current.has(r)||C.current.has(r))return;C.current=new Set(C.current),C.current.add(r);let i=t.listDirectory?t.listDirectory(r).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):Le.listLocalDirectory(r).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})));try{let e=await i;if(n?.())return;let t=le(r,e);S.current=new Set(S.current),S.current.add(r),b(e=>{if(!e[r])return e;let t={...e};return delete t[r],t}),v(e=>({...e,[r]:t}))}catch(e){if(n?.())return;let t=e instanceof Error?e.message:String(e??``);console.error(`Failed to load sidebar directory:`,e),b(e=>({...e,[r]:t}))}finally{C.current=new Set(C.current),C.current.delete(r)}},[t,le]),de=Q.useCallback(async()=>{if(!r)return;w.current?.abort();let e=new AbortController;w.current=e;try{let t=(vo.getState().byRoot[r]?.expandedPaths??[]).map(e=>Sf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)),n=[r,...t];S.current=new Set(S.current);for(let e of n)S.current.delete(e);b(e=>{if(Object.keys(e).length===0)return e;let t={...e},r=!1;for(let e of n)e in t&&(delete t[e],r=!0);return r?t:e});let i=()=>e.signal.aborted;await ue(r,i);for(let n=0;n<t.length&&!e.signal.aborted;n+=3){let e=t.slice(n,n+3);await Promise.all(e.map(e=>ue(e,i)))}}catch(t){if(e.signal.aborted)return;console.error(`Failed to refresh sidebar tree:`,t)}finally{w.current===e&&(w.current=null)}},[ue,r]),fe=Q.useCallback(async e=>{if(!e){await de();return}let t=Sf(e);S.current=new Set(S.current),S.current.delete(t),C.current=new Set(C.current),C.current.delete(t),await ue(t)},[ue,de]);Q.useEffect(()=>{r&&(w.current?.abort(),E.current=!1,S.current=new Set,C.current=new Set,b({}),v(e=>Object.keys(e).length===0?e:{}),ue(r))},[ue,r,i,a]),Q.useEffect(()=>{if(!r||k.length===0)return;let e=k.map(e=>Sf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)&&!S.current.has(e)&&!C.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1,n=()=>t;return(async()=>{for(let r=0;r<e.length&&!t;r+=3){let t=e.slice(r,r+3);await Promise.all(t.map(e=>ue(e,n)))}})(),()=>{t=!0}},[k,ue,r]),Q.useEffect(()=>{if(!n){m([]),g(!1);return}let e=d.trim();if(!e){m([]),g(!1);return}let t=!1;return g(!0),o(n,e,150,{includeHidden:i,respectGitignore:!a,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>a||!Df(e.path)).map(e=>({name:e.name,path:Sf(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));m(n)}).catch(()=>{t||m([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[n,d,o,i,a]);let pe=Q.useMemo(()=>{let e=new Map;if(!c?.files)return e;for(let t of c.files)t.index===`A`||t.working_dir===`?`?e.set(t.path,`git-added`):t.index===`D`?e.set(t.path,`git-deleted`):(t.index===`M`||t.working_dir===`M`)&&e.set(t.path,`git-modified`);return e},[c]),me=Q.useMemo(()=>{let e=new Map;if(!c?.files||!r)return e;for(let t of c.files){let n=t.index===`M`||t.working_dir===`M`,i=t.index===`A`||t.working_dir===`?`;if(!n&&!i)continue;let a=t.path.split(`/`);if(a.length<=1)continue;let o=r;for(let t=0;t<a.length-1;t++){o=`${o}/${a[t]}`;let r=e.get(o);r||(r={modified:0,added:0},e.set(o,r)),n&&r.modified++,i&&r.added++}}return e},[c,r]),he=Q.useCallback(e=>{if(R.has(e))return`open`;if(pe.size===0)return null;let t=e.startsWith(r+`/`)?e.slice(r.length+1):e;return pe.get(t)??null},[R,pe,r]),ge=Q.useCallback(e=>{if(me.size===0)return null;let t=me.get(e);return t&&t.modified+t.added>0?t:null},[me]),_e=Q.useCallback(async e=>{if(!r)return;let n=await cc(t,e.path);if(!n.ok){X.error(Mc(n.reason));return}j(r,e.path),M(r,e.path),s(r,e.path)},[M,t,s,r,j]),ve=Q.useCallback(async e=>{let t=Sf(e);r&&(F(r,t),S.current.has(t)||await ue(t))},[ue,r,F]),ye=Q.useMemo(()=>r?_f(r,_):[],[_,r]),be=Q.useMemo(()=>new Set(k.map(e=>Sf(e))),[k]),xe=vf(k),Se=Q.useCallback(()=>{if(r){if(xe){E.current=!1,P(r,r);return}E.current=!0,I(r,ye)}},[xe,ye,I,P,r]);Q.useEffect(()=>{if(!r||!E.current)return;let e=yf(ye,k);if(e.length>0){I(r,e);return}let t=new Set([...S.current,...Object.keys(y)]);bf(ye,k,t)&&(E.current=!1)},[ye,I,k,y,r]);let Ce=Q.useCallback(async n=>{if(n?.preventDefault(),!V||!z)return;re(!0);let i=()=>re(!1),a=()=>B(null);if(z===`createFile`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.filenameRequired`)),i();return}if(!t.writeFile){X.error(e(`sidebarFilesTree.toast.writeNotSupported`)),i();return}let n=V.path,r=Sf(`${n?`${n}/`:``}${H.trim()}`);await t.writeFile(r,``).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.fileCreated`)),await fe(n)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`createFolder`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.folderNameRequired`)),i();return}let n=V.path,r=Sf(`${n?`${n}/`:``}${H.trim()}`);await t.createDirectory(r).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.folderCreated`)),await fe(n)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`rename`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.nameRequired`)),i();return}if(!t.rename){X.error(e(`sidebarFilesTree.toast.renameNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`),s=Sf(`${o?`${o}/`:``}${H.trim()}`);await t.rename(n,s).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.renamedSuccessfully`)),await fe(o),r&&N(r,n),(A===n||A&&A.startsWith(`${n}/`))&&j(r,null)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`delete`){if(!t.delete){X.error(e(`sidebarFilesTree.toast.deleteNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`);await t.delete(n).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.deletedSuccessfully`)),await fe(o),r&&N(r,n),(A===n||A&&A.startsWith(n+`/`))&&j(r,null)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}i()},[z,V,H,t,fe,N,r,A,j,e]);function we(n,i){return(_[n]??[]).map(n=>{let a=n.type===`directory`,o=a&&be.has(Sf(n.path)),s=A===n.path;return(0,$.jsxs)(`li`,{className:`relative`,children:[i>0&&(0,$.jsx)(`span`,{className:`absolute top-3 left-[-12px] h-px w-3 bg-border/40`}),(0,$.jsx)(Ff,{node:n,root:r,isExpanded:o,isActive:s,status:a?void 0:he(n.path),badge:a?ge(n.path):void 0,permissions:se,downloadFile:t.downloadFile,onSelect:_e,onToggle:ve,onRevealPath:ce,onOpenDialog:G}),a&&o&&(0,$.jsxs)(`ul`,{className:`relative ml-3 flex flex-col border-l border-border/40 pl-3`,children:[y[n.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:y[n.path],children:y[n.path]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void fe(n.path),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):null,we(n.path,i+1)]})]},n.path)})}let Te=!!(r&&_[r]),Ee=r?y[r]:null,De=e(xe?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`);return(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(sa,{ref:f,value:l,onChange:e=>u(e.target.value),placeholder:e(`sidebarFilesTree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),l.trim().length>0?(0,$.jsx)(`button`,{type:`button`,"aria-label":e(`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:()=>{u(``),f.current?.focus()},children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})}):null]}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-0.5`,children:[U&&(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>G(`createFile`,{path:n,type:`directory`}),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.newFileTitle`),"aria-label":e(`sidebarFilesTree.actions.newFileTitle`),children:(0,$.jsx)(Z,{name:`file-add`,className:`size-3.5`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFileTitle`)})]}),ie&&(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>G(`createFolder`,{path:n,type:`directory`}),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.newFolderTitle`),"aria-label":e(`sidebarFilesTree.actions.newFolderTitle`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`size-3.5`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFolderTitle`)})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>void de(),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.refreshTitle`),"aria-label":e(`sidebarFilesTree.actions.refreshTitle`),children:(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.refreshTitle`)})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:Se,disabled:ye.length===0&&k.length===0,className:`w-6 flex-shrink-0 p-0`,title:De,"aria-label":De,children:(0,$.jsx)(Z,{name:xe?`contract-up-down`:`expand-up-down`,className:`size-3.5`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:De})]})]})]}),(0,$.jsx)(fo,{outerClassName:`flex-1 min-h-0`,className:`p-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:h?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),e(`sidebarFilesTree.state.searching`)]}):p.length>0?p.map(e=>{let t=A===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_e(e),draggable:!0,onDragStart:t=>{let n=e.relativePath||Cf(r??``,e.path);!n||n===`.`||(t.dataTransfer.setData(`application/x-yuri-file-path`,n),t.dataTransfer.effectAllowed=`copy`)},className:J(`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`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),title:e.path,children:[Nf(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,style:{direction:`rtl`,textAlign:`left`},children:e.relativePath??e.path})]})},e.path)}):Ee?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:Ee}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void de(),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):Te&&r?we(r,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-code text-muted-foreground`,children:e(`sidebarFilesTree.state.loading`)})})}),(0,$.jsx)(pr,{open:!!z,onOpenChange:e=>!e&&B(null),children:(0,$.jsxs)(ur,{children:[(0,$.jsxs)(cr,{children:[(0,$.jsxs)(dr,{children:[z===`createFile`&&e(`sidebarFilesTree.dialog.createFile.title`),z===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.title`),z===`rename`&&e(`sidebarFilesTree.dialog.rename.title`),z===`delete`&&e(`sidebarFilesTree.dialog.delete.title`)]}),(0,$.jsxs)(fr,{children:[z===`createFile`&&e(`sidebarFilesTree.dialog.createFile.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),z===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),z===`rename`&&e(`sidebarFilesTree.dialog.rename.description`,{name:V?.name??``}),z===`delete`&&e(`sidebarFilesTree.dialog.delete.description`,{name:V?.name??``})]})]}),z!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(sa,{value:H,onChange:e=>te(e.target.value),placeholder:e(z===`rename`?`sidebarFilesTree.dialog.rename.placeholder`:`sidebarFilesTree.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&Ce()},autoFocus:!0})}),(0,$.jsxs)(lr,{children:[(0,$.jsx)(Y,{variant:`outline`,onClick:()=>B(null),disabled:ne,children:e(`sidebarFilesTree.dialog.cancel`)}),(0,$.jsx)(Y,{variant:z===`delete`?`destructive`:`default`,onClick:()=>void Ce(),disabled:ne||z!==`delete`&&!H.trim(),children:ne?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):e(z===`delete`?`sidebarFilesTree.dialog.delete.confirm`:`sidebarFilesTree.dialog.confirm`)})]})]})})]})},Lf=()=>!(typeof document<`u`&&document.hidden||typeof navigator<`u`&&!navigator.onLine);function Rf(e,t,n,r){let i=(0,fl.c)(6),{git:a}=at(),o=Do(zf),s=!!(e&&a&&t&&n===`git`&&r!==`git`),c,l;i[0]!==e||i[1]!==o||i[2]!==a||i[3]!==s?(c=()=>{if(!s||!e||!a)return;o(e,a);let t=window.setInterval(()=>{Lf()&&o(e,a)},1e4);return()=>window.clearInterval(t)},l=[s,e,a,o],i[0]=e,i[1]=o,i[2]=a,i[3]=s,i[4]=c,i[5]=l):(c=i[4],l=i[5]),Q.useEffect(c,l)}function zf(e){return e.ensureStatus}var Bf=()=>{let e=(0,fl.c)(48),{t}=wt(),n=q(Vf),r=q(Hf),i=q(Uf),a=q(Wf),o=Qo(),s=Wa(),c;e[0]!==s.data?.providers||e[1]!==s.data?.selectedId?(c=s.data?.providers.find(e=>e.id===s.data?.selectedId)??null,e[0]=s.data?.providers,e[1]=s.data?.selectedId,e[2]=c):c=e[2];let l=c,u;e[3]===s.data?u=e[4]:(u=ka(s.data),e[3]=s.data,e[4]=u);let d=u;Rf(o,i,n,a);let f=a===`git`,p;e[5]!==f||e[6]!==d?(p=ci({hideGit:f,showBrowser:d}),e[5]=f,e[6]=d,e[7]=p):p=e[7];let m=p,h,g;e[8]!==n||e[9]!==r||e[10]!==m?(h=()=>{m.includes(n)||r(m[0]??`files`)},g=[n,r,m],e[8]=n,e[9]=r,e[10]=m,e[11]=h,e[12]=g):(h=e[11],g=e[12]),Q.useEffect(h,g);let _;if(e[13]!==t||e[14]!==m){let n;e[16]===t?n=e[17]:(n=e=>({id:e,label:t(e===`git`?`layout.rightSidebar.git`:e===`files`?`layout.rightSidebar.files`:`layout.rightSidebar.browser`),icon:(0,$.jsx)(Z,{name:e===`git`?`git-branch`:e===`files`?`folder-3`:`global`,className:`h-3.5 w-3.5`})}),e[16]=t,e[17]=n),_=m.map(n),e[13]=t,e[14]=m,e[15]=_}else _=e[15];let v=_,y=i&&n===`git`&&!f,b;e[18]!==r||e[19]!==m?(b=e=>{Gi(e)&&m.includes(e)&&r(e)},e[18]=r,e[19]=m,e[20]=b):b=e[20];let x=b,S;e[21]!==x||e[22]!==n||e[23]!==v?(S=(0,$.jsx)(`div`,{className:`h-9 bg-background pt-1 px-2`,children:(0,$.jsx)(rs,{items:v,activeId:n,onSelect:x,layoutMode:`fit`,variant:`active-pill`,activePillLowercase:!1,className:`h-full`})}),e[21]=x,e[22]=n,e[23]=v,e[24]=S):S=e[24];let C=n!==`git`&&`hidden`,w;e[25]===C?w=e[26]:(w=J(`h-full`,C),e[25]=C,e[26]=w);let T;e[27]===y?T=e[28]:(T=(0,$.jsx)(of,{isActive:y}),e[27]=y,e[28]=T);let E;e[29]!==T||e[30]!==w?(E=(0,$.jsx)(`div`,{className:w,children:T}),e[29]=T,e[30]=w,e[31]=E):E=e[31];let D=n!==`files`&&`hidden`,O;e[32]===D?O=e[33]:(O=J(`h-full`,D),e[32]=D,e[33]=O);let k;e[34]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(If,{}),e[34]=k):k=e[34];let A;e[35]===O?A=e[36]:(A=(0,$.jsx)(`div`,{className:O,children:k}),e[35]=O,e[36]=A);let j;e[37]!==n||e[38]!==l||e[39]!==d?(j=d&&l?(0,$.jsx)(`div`,{className:J(`h-full`,n!==`browser`&&`hidden`),children:(0,$.jsx)(hf,{provider:l})}):null,e[37]=n,e[38]=l,e[39]=d,e[40]=j):j=e[40];let M;e[41]!==E||e[42]!==A||e[43]!==j?(M=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[E,A,j]}),e[41]=E,e[42]=A,e[43]=j,e[44]=M):M=e[44];let N;return e[45]!==M||e[46]!==S?(N=(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[S,M]}),e[45]=M,e[46]=S,e[47]=N):N=e[47],N};function Vf(e){return e.rightSidebarTab}function Hf(e){return e.setRightSidebarTab}function Uf(e){return e.isRightSidebarOpen}function Wf(e){return e.activeMainTab}var Gf=(e,t)=>{if(!t)return null;let n=Number.parseInt(e.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,t.state.doc.lines)},Kf=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},qf=(e,t,n)=>{let r=e.state.doc.line(t),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;e.dispatch({selection:mt.cursor(a),effects:pt.scrollIntoView(a,{y:`center`})})};function Jf({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=wt(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>Gf(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Kf(n,n.state.selection),o(``))},[e,n]),Q.useEffect(()=>{e&&window.requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()})},[e]),Q.useEffect(()=>{if(!(!e||!n||!s.current)){if(d===null){let{selection:e}=s.current;n.dispatch({selection:e,effects:pt.scrollIntoView(e.main.from,{y:`center`})});return}qf(n,d,s.current.character)}},[d,e,n]);let f=Q.useCallback(()=>{if(!n||c.current||!s.current)return;let{selection:e}=s.current;n.dispatch({selection:e,effects:pt.scrollIntoView(e.main.from,{y:`center`})})},[n]),p=Q.useCallback(e=>{e||f(),t(e)},[t,f]),m=Q.useCallback(()=>{!n||d===null||!s.current||(c.current=!0,qf(n,d,s.current.character),t(!1),n.focus())},[d,t,n]);Q.useEffect(()=>{if(!e)return;let t=e=>{let t=l.current,n=e.target;!t||!(n instanceof Node)||t.contains(n)||p(!1)},n=e=>{e.key===`Escape`&&(e.preventDefault(),p(!1))};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n,!0),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n,!0)}},[p,e,r]);let h=Q.useMemo(()=>{if(!n)return i(`goToLineDialog.helper.editorUnavailable`);if(d===null){let e=s.current??Kf(n,n.state.selection);return i(`goToLineDialog.helper.currentLineRange`,{current:e.lineNumber,max:n.state.doc.lines})}return i(`goToLineDialog.helper.goToLine`,{line:d})},[d,i,n]);return r===`inline`?e?(0,$.jsxs)(`div`,{ref:l,className:`ml-1 flex h-6 items-center gap-1`,children:[(0,$.jsx)(sa,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholderShort`),className:`h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta`}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,onClick:m,disabled:!n||d===null,className:`h-6 px-2`,children:i(`goToLineDialog.actions.go`)})]}):null:(0,$.jsx)(`div`,{ref:l,className:J(`absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all`,e?`pointer-events-auto translate-y-0 opacity-100`:`pointer-events-none -translate-y-1 opacity-0`),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(sa,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholder`),className:`h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label`}),(0,$.jsx)(`div`,{className:`mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95`,children:h})]})})}var Yf=jo(()=>dt(()=>import(`./ToolOutputDialog-DAwoBF6c.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]))),Xf=e=>{let t=$f(e);if(!t)return``;if(t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return t;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},Zf=e=>{let t=(0,fl.c)(8),{label:n,iconDataUrl:r}=e,[i,a]=Q.useState(!1),o;t[0]===n?o=t[1]:(o=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=o);let s=o;if(r&&!i){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>a(!0),t[2]=e):e=t[2];let n;return t[3]===r?n=t[4]:(n=(0,$.jsx)(`img`,{src:r,alt:``,className:`size-4 rounded-sm`,onError:e}),t[3]=r,t[4]=n),n}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`size-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=c):c=t[5];let l;return t[6]===s?l=t[7]:(l=(0,$.jsx)(`span`,{className:c,children:s}),t[6]=s,t[7]=l),l},Qf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),$f=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},ep=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),tp=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,np=(e,t)=>{let n=$f(t),r=$f(e);if(!n||!r)return!1;let i=tp(n),a=tp(r);return a===i||a.startsWith(`${i}/`)},rp=(e,t)=>{let n=$f(t),r=$f(e);if(!np(r,n))return[];let i=r.slice(n.length).replace(/^\//,``).split(`/`),a=[],o=n;for(let e=0;e<i.length-1;e++)o=o?`${o}/${i[e]}`:i[e],a.push(o);return a},ip=(e,t)=>{if(!t)return``;let n=$f(t);if(!e||!np(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},ap=new Set([`node_modules`]),op=e=>{let t=(0,fl.c)(3),{status:n}=e,r;t[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)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`size-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},sp=e=>{let t=(0,fl.c)(11),{name:n}=e,r=Q.useRef(null),i=Q.useRef(null),[a,o]=Q.useState(!1),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=r.current,t=i.current;if(!e||!t)return;let n=()=>{o(t.scrollWidth>e.clientWidth+1)};n();let a=new ResizeObserver(n);return a.observe(e),a.observe(t),()=>{a.disconnect()}},t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=[n],t[1]=n,t[2]=c),Q.useLayoutEffect(s,c);let l;t[3]===n?l=t[4]:(l=(0,$.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:`invisible absolute whitespace-nowrap`,children:n}),t[3]=n,t[4]=l);let u;t[5]!==n||t[6]!==a?(u=a?(0,$.jsxs)(`span`,{className:`open-file-name-marquee-track`,children:[(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,children:n}),(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,"aria-hidden":`true`,children:n})]}):(0,$.jsx)(`span`,{className:`block min-w-0 truncate`,children:n}),t[5]=n,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`span`,{ref:r,className:`relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d},cp=e=>ap.has(e),lp=e=>{let t=$f(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},up=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},dp=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`file not found`)||t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`does not exist`)},fp=2e5,pp=`yuri:files:auto-save-enabled`,mp=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
6
+ `)}`.trim()}),Ge()},[Ge]),cn=Q.useCallback((e,t)=>{let n=t||e;ge(r=>{let i=r.trimStart();return i.startsWith(e)||t&&i.startsWith(t)?r:`${n.endsWith(` `)?n:`${n} `}${r}`.trimStart()}),ot(``),Ce(!1)},[]),ln=Q.useCallback(async()=>{if(r)try{ht===`merge`?(await n.abortMerge(r),X.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),X.success(t(`gitView.toast.rebaseAborted`))),Dt(),await jt(),await Mt()}catch(e){let t=e instanceof Error?e.message:`Failed to abort ${ht}`;X.error(t)}},[r,n,ht,jt,Mt,Dt,t]),un=Q.useMemo(()=>_?.files?_.files.some(e=>e.index===`U`||e.working_dir===`U`||e.index===`A`&&e.working_dir===`A`||e.index===`D`&&e.working_dir===`D`):!1,[_?.files]),dn=Q.useCallback(async()=>{if(r)try{let e=!!_?.mergeInProgress?.head,i=!!(_?.rebaseInProgress?.headName||_?.rebaseInProgress?.onto);if(e){let e=await n.continueMerge(r);e.conflict?(mt(e.conflictFiles??[]),gt(`merge`),ft(!0),Et(r,e.conflictFiles??[],`merge`),X.error(t(`gitView.toast.mergeConflictsDetected`))):(Dt(),X.success(t(`gitView.toast.mergeCompleted`)),await jt(),await Mt())}else if(i){let e=await n.continueRebase(r);e.conflict?(mt(e.conflictFiles??[]),gt(`rebase`),ft(!0),Et(r,e.conflictFiles??[],`rebase`),X.error(t(`gitView.toast.rebaseConflictsDetected`))):(Dt(),X.success(t(`gitView.toast.rebaseStepCompleted`)),await jt(),await Mt())}}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.continueOperationFailed`);X.error(n)}},[r,n,_,jt,Mt,Et,Dt,t]),fn=Q.useCallback(async()=>{if(r)try{_?.mergeInProgress?.head?(await n.abortMerge(r),X.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),X.success(t(`gitView.toast.rebaseAborted`))),Dt(),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.abortOperationFailed`);X.error(n)}},[r,n,_,jt,Mt,Dt,t]),pn=Q.useCallback(()=>{if(!r)return;let e=_?.mergeInProgress?.head?`merge`:`rebase`,t=_?.files?.filter(e=>e.index===`U`||e.working_dir===`U`).map(e=>e.path)??[];t.length>0&&mt(t),gt(e),ft(!0)},[r,_]),mn=Q.useCallback(e=>{Me(e),r&&(M(r,e),j(r,n,e))},[r,j,n,M]),hn=Q.useCallback(e=>{St(e)},[]),gn=Q.useCallback(()=>{ct(null),r&&(k(r,n),A(r,n,{force:!0}),j(r,n,je))},[r,k,A,j,je,n]),_n=Q.useCallback(e=>{if(e.conflict){if(e.operation===`cherry-pick`||e.operation===`revert`){X.error(t(`gitView.history.actions.conflictToastTitle`),{description:t(`gitView.history.actions.conflictToastDescription`,{files:e.conflictFiles?.join(`, `)??`unknown files`})}),r&&(k(r,n),A(r,n,{force:!0}),j(r,n,je));return}mt(e.conflictFiles??[]),gt(e.operation),ft(!0),r&&Et(r,e.conflictFiles??[],e.operation)}},[t,mt,gt,ft,Et,r,k,A,j,je,n]);if(!r)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:t(`gitView.empty.selectSessionOrDirectory`)})});if(g===null||g===!0&&!_)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:t(`gitView.loading.checkingRepository`)})]})});if(g===!1)return G?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-4 text-center`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`mb-3 size-6 animate-spin text-muted-foreground`}),(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.worktreeSetupInProgress`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1 text-muted-foreground`,children:t(`gitView.empty.worktreeSetupDescription`)})]}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-4 text-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`mb-3 size-6 text-muted-foreground`}),(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.notGitRepository`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1 text-muted-foreground`,children:t(`gitView.empty.notGitRepositoryDescription`)}),y.includes(`open-without-worktree-features`)?(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:t(`gitView.empty.worktreeFeaturesUnavailable`)}):null]});let vn=_?x?(0,$.jsx)(Us,{currentBranch:_.current,onRename:Ut,iconOnly:!0}):(0,$.jsx)(_i,{currentBranch:_.current,localBranches:Gt,remoteBranches:Kt,branchInfo:S?.branches,onCheckout:Wt,onCreate:Ht,remotes:qt,iconOnly:!0}):null,xn=_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Zs,{syncAction:Te,remotes:qt,onSync:e=>Rt(`sync`,e),disabled:!_,aheadCount:_.ahead,behindCount:_.behind,trackingRemoteName:_.tracking?.split(`/`)[0],hasUncommittedChanges:(_.files?.length??0)>0}),(0,$.jsxs)(Ga,{children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,"aria-label":t(`gitView.header.repositoryViews`),children:(0,$.jsx)(Z,{name:`git-repository`,className:`size-3.5`})})})}),(0,$.jsx)(da,{sideOffset:8,children:t(`gitView.header.repositoryViews`)})]}),(0,$.jsxs)(Ia,{align:`end`,children:[(0,$.jsxs)(ka,{onSelect:()=>ct(`history`),children:[(0,$.jsx)(Z,{name:`history`,className:`size-4`}),t(`gitView.history.title`)]}),(0,$.jsxs)(ka,{onSelect:()=>ct(`graph`),children:[(0,$.jsx)(Z,{name:`git-merge`,className:`size-4`}),t(`gitView.graph.title`)]}),(0,$.jsxs)(ka,{onSelect:rn,children:[(0,$.jsx)(Z,{name:`archive-stack`,className:`size-4`}),t(`gitView.stashes.title`)]})]})]})]}):null,Cn=_?(0,$.jsxs)($.Fragment,{children:[vn,xn]}):null;return(0,$.jsxs)(`div`,{className:J(`flex h-full flex-col overflow-hidden`),children:[r&&(_?.mergeInProgress?.head||_?.rebaseInProgress?.headName||_?.rebaseInProgress?.onto)&&(0,$.jsx)(Jd,{mergeInProgress:_?.mergeInProgress,rebaseInProgress:_?.rebaseInProgress,onContinue:dn,onAbort:fn,onResolveWithAI:pn,hasUnresolvedConflicts:un,isLoading:w}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full min-h-0 flex flex-col`,children:(0,$.jsx)(`div`,{className:J(`min-w-0 min-h-0 h-full flex flex-col`),children:(0,$.jsx)(mo,{as:ho,ref:we,outerClassName:`flex-1 min-h-0`,className:J(`px-4`,`pt-2 pb-4`),disableHorizontal:!0,preventOverscroll:!0,children:(0,$.jsx)(`div`,{className:`flex h-full min-h-0 flex-col gap-2`,children:xe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex h-8 shrink-0 items-center bg-background pr-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:t(`gitView.changes.deferredTitle`,{count:_?.files?.length??0})}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Cn})]}),(0,$.jsx)(ic,{stagedCount:Ft,unstagedCount:It,onLoad:()=>be(!0)})]}):(Nt?.length??0)>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,$.jsx)(Lc,{groups:an,diffStats:_?.diffStats,revertingPaths:K,isRevertingAll:Le,onVisiblePathsChange:ve,onRevertAll:en,onRevertDirectory:tn,headerBackgroundClassName:`bg-background`,headerLeadingActions:vn,headerActions:xn})}),(0,$.jsx)(gc,{stagedCount:Yt,commitMessage:he,onCommitMessageChange:ge,generatedHighlights:Ve,onInsertHighlights:sn,onGenerateMessage:Bt,isGeneratingMessage:ze,onCommit:()=>zt({pushAfter:!1}),onCommitAndPush:()=>zt({pushAfter:!0}),commitAction:ke,hasPendingIndexMutation:Ue,gitmojiEnabled:de,onOpenGitmojiPicker:()=>Ce(!0)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-1 flex h-8 shrink-0 items-center bg-background pr-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:t(`gitView.empty.cleanTitle`)}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Cn})]}),(0,$.jsx)(_d,{onOpenStashes:()=>Oe(!0)})]})})})})})}),(0,$.jsx)(mr,{open:st!==null,onOpenChange:e=>{e||ct(null)},children:(0,$.jsxs)(dr,{className:`max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,$.jsxs)(lr,{children:[(0,$.jsx)(fr,{children:t(st===`graph`?`gitView.graph.title`:`gitView.history.title`)}),(0,$.jsx)(pr,{children:t(`gitView.history.dialogDescription`)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,$.jsx)(Id,{mode:st===`graph`?`graph`:`history`,log:st===`graph`?_t??C:C,isLogLoading:st===`graph`&&yt||T,logMaxCount:st===`graph`?xt:je,onLogMaxCountChange:st===`graph`?hn:mn,expandedCommitHashes:Ke,onToggleCommit:kt,commitFilesMap:Je,loadingCommitHashes:Xe,onCopyHash:Ot,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:`h-full max-h-none`,branchDivider:st===`graph`?null:et,onConflict:st===`graph`?_n:void 0,onActionSuccess:st===`graph`?gn:void 0})})]})}),(0,$.jsx)(hd,{open:De,onOpenChange:Oe,directory:r,hasUncommittedChanges:(_?.files?.length??0)>0,hasStagedChanges:Y.length>0,uncommittedFileCount:_?.files?.length??0,onChanged:async e=>{r&&e?.affectsIndex&&I(r),await jt(!1),await Mt()}}),(0,$.jsx)(mr,{open:Se,onOpenChange:Ce,children:(0,$.jsxs)(dr,{className:`max-w-md p-0 overflow-hidden`,children:[(0,$.jsx)(lr,{className:`px-4 pt-4`,children:(0,$.jsx)(fr,{children:t(`gitView.gitmoji.title`)})}),(0,$.jsxs)(Vi,{className:`h-[420px]`,children:[(0,$.jsx)(wi,{placeholder:t(`gitView.gitmoji.searchPlaceholder`),value:it,onValueChange:ot}),(0,$.jsxs)(Pi,{children:[(0,$.jsx)(Ni,{children:t(`gitView.gitmoji.empty`)}),(0,$.jsx)(Li,{children:(me.length===0?[]:me.filter(e=>{let t=it.trim().toLowerCase();return!t||e.emoji.includes(t)||e.code.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)})).map(e=>(0,$.jsxs)(fi,{onSelect:()=>cn(e.emoji,e.code),children:[(0,$.jsx)(`span`,{className:`text-lg`,children:e.emoji}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.code}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.description})]},e.code))})]})]})]})}),r&&(0,$.jsx)(Vd,{open:dt,onOpenChange:ft,conflictFiles:pt,directory:r,operation:ht,onAbort:ln,onClearState:Dt})]})},lf=1,uf=8e3,df={refreshAuth:()=>r(),clearUrlAuthToken:n,openSocket:e=>Re(c().websocket(Ra(e)))},ff=class{providerId;handlers;dependencies;socket=null;pendingFrame=null;reconnectTimer=null;failures=0;generation=0;disposed=!1;ended=!1;constructor(e,t,n=df){this.providerId=e,this.handlers=t,this.dependencies=n}start(){this.handlers.onConnection({status:`connecting`}),this.connect()}dispose(){this.disposed=!0,this.generation+=1,this.cancelReconnect();let e=this.socket;this.socket=null,e?.close()}ack(e){this.send({type:`ack`,seq:e})}sendInput(e){return e.length!==0&&this.send({type:`input`,events:e})}release(){this.send({type:`release`})}resize(e,t){e<1||t<1||this.send({type:`resize`,width:Math.round(e),height:Math.round(t)})}retry(){this.disposed||(this.ended=!1,this.failures=0,this.generation+=1,this.socket?.close(),this.socket=null,this.handlers.onConnection({status:`connecting`}),this.connect())}send(e){let t=this.socket;if(!t||t.readyState!==lf)return!1;try{return t.send(JSON.stringify(e)),!0}catch{return!1}}async connect(){if(this.disposed||this.ended)return;let e=this.generation;try{await this.dependencies.refreshAuth()}catch{this.scheduleReconnect();return}if(e!==this.generation||this.disposed||this.ended)return;let t;try{t=this.dependencies.openSocket(this.providerId)}catch{this.scheduleReconnect();return}t.binaryType=`arraybuffer`,this.socket=t;let n=!1;t.onopen=()=>{this.socket===t&&(n=!0,this.failures=0,this.pendingFrame=null,this.handlers.onConnection({status:`open`}))},t.onmessage=e=>{this.socket===t&&this.handleMessage(e.data)},t.onerror=()=>{this.dependencies.clearUrlAuthToken()},t.onclose=()=>{this.socket===t&&(this.socket=null),!(this.disposed||this.ended)&&(n&&(this.failures=Math.max(this.failures,1)),this.scheduleReconnect())}}handleMessage(e){if(e instanceof ArrayBuffer){let t=this.pendingFrame;if(this.pendingFrame=null,!t||e.byteLength!==t.bytes)return;this.handlers.onFrame({...t,bytes:e});return}if(typeof e!=`string`)return;let t;try{t=JSON.parse(e)}catch{return}let n=qa(t);n&&this.applyHostMessage(n)}applyHostMessage(e){if(e.type===`frame`){this.pendingFrame=e;return}if(e.type===`control`){this.handlers.onControl({controller:e.controller,mine:e.mine});return}e.type===`ended`&&(this.ended=!0,this.cancelReconnect(),this.handlers.onConnection({status:`ended`,reason:e.reason}),this.handlers.onEnded?.(e.reason),this.socket?.close())}scheduleReconnect(){if(this.disposed||this.ended||this.reconnectTimer)return;this.failures+=1;let e=this.failures;this.handlers.onConnection({status:`reconnecting`,attempt:e});let t=Math.min(uf,250*2**Math.min(e,5));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},t)}cancelReconnect(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}},pf=250,mf=e=>({alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey}),hf=e=>(e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()===`v`,gf=(e,t)=>new ff(e,t),_f=({provider:e,clientFactory:t=gf})=>{let{t:n}=Tt(),r=Q.useRef(null),i=Q.useRef(null),a=Q.useRef(null),o=Q.useRef(null),s=Q.useRef([]),c=Q.useRef(null),l=Q.useRef({controller:`none`,mine:!1}),u=Q.useRef(null),[d,f]=Q.useState({status:`connecting`}),[p,m]=Q.useState({controller:`none`,mine:!1}),[h,g]=Q.useState(``),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),C=vt(e=>{l.current=e,m(e)}),w=vt(async e=>{let t=i.current,n=a.current;if(!(!t||!n))try{let n=await createImageBitmap(new Blob([e.bytes],{type:e.mime}));(t.width!==e.width||t.height!==e.height)&&(t.width=e.width,t.height=e.height),t.getContext(`2d`)?.drawImage(n,0,0,e.width,e.height),n.close(),o.current={width:e.width,height:e.height},b(!0),g(e.title??``),v(e.agentActive)}catch{}finally{n.ack(e.seq)}}),T=Q.useRef({onFrame:e=>{w(e)},onControl:C,onConnection:f});T.current={onFrame:e=>{w(e)},onControl:C,onConnection:f};let E=Q.useRef(t);E.current=t,Q.useEffect(()=>{if(!e.surface)return;let t=E.current(e.id,{onFrame:e=>{T.current.onFrame(e)},onControl:e=>{T.current.onControl(e)},onConnection:e=>{T.current.onConnection(e)}});return a.current=t,t.start(),()=>{t.dispose(),a.current===t&&(a.current=null),c.current!==null&&cancelAnimationFrame(c.current),c.current=null,s.current=[],o.current=null,b(!1),f({status:`connecting`}),C({controller:`none`,mine:!1})}},[e.id,e.surface,C]);let D=vt(()=>{let t=r.current;!t||!e.surface||(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null;let e=t.getBoundingClientRect(),n=window.devicePixelRatio||1,r=Math.round(e.width*n),i=Math.round(e.height*n);r>0&&i>0&&a.current?.resize(r,i)},pf))});_t(e.surface?r:null,D);let O=vt(e=>{s.current.push(e),c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;let e=s.current;s.current=[],a.current?.sendInput(e)}))}),k=e=>{let t=i.current,n=o.current;if(!t||!n)return null;let r=t.getBoundingClientRect();return r.width===0||r.height===0?null:{x:Math.round((e.clientX-r.left)/r.width*n.width),y:Math.round((e.clientY-r.top)/r.height*n.height)}},A=e=>t=>{if(!y||e===`move`&&t.buttons===0&&!(l.current.controller===`user`&&l.current.mine))return;let n=k(t);n&&(e===`down`?(r.current?.focus(),t.currentTarget.setPointerCapture(t.pointerId)):e===`up`&&t.currentTarget.hasPointerCapture(t.pointerId)&&t.currentTarget.releasePointerCapture(t.pointerId),t.preventDefault(),O({type:`pointer`,action:e,x:n.x,y:n.y,button:e===`move`?-1:t.button,buttons:t.buttons,modifiers:mf(t)}))},j=e=>{if(!y)return;let t=k(e);t&&(e.preventDefault(),O({type:`wheel`,x:t.x,y:t.y,deltaX:e.deltaX,deltaY:e.deltaY,modifiers:mf(e)}))},M=e=>t=>{!y||hf(t)||(t.preventDefault(),t.stopPropagation(),O({type:`key`,action:e,key:t.key,code:t.code,modifiers:mf(t)}))},N=e=>{if(!y)return;let t=e.clipboardData.getData(`text/plain`);e.preventDefault(),t&&O({type:`text`,text:t})},P=vt(()=>{a.current?.release()}),F=vt(()=>{a.current?.retry()});if(!e.surface)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:n(`layout.browserProvider.noSurface`,{name:e.name})});let I=d.status===`connecting`?`layout.browserProvider.status.connecting`:d.status===`reconnecting`?`layout.browserProvider.status.reconnecting`:d.status===`ended`?d.reason===`service-stopped`?`layout.browserProvider.ended.service-stopped`:d.reason===`extension-unavailable`?`layout.browserProvider.ended.extension-unavailable`:`layout.browserProvider.ended.host-shutdown`:p.controller===`user`?p.mine?`layout.browserProvider.status.youControl`:`layout.browserProvider.status.otherControls`:p.controller===`agent`||_?`layout.browserProvider.status.agentWorking`:x?`layout.browserProvider.status.readyFocused`:`layout.browserProvider.status.ready`,L=p.controller===`user`&&p.mine;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center gap-2 border-b border-border px-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-foreground`,title:h||e.name,children:h||e.name}),(0,$.jsx)(`span`,{className:J(`shrink-0 truncate text-xs`,L?`text-foreground`:`text-muted-foreground`),"aria-live":`polite`,children:n(I)}),L?(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:P,children:n(`layout.browserProvider.handBack`)}):null,d.status===`ended`?(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:F,children:n(`layout.browserProvider.retry`)}):null]}),(0,$.jsxs)(`div`,{ref:r,tabIndex:0,role:`application`,"aria-label":n(`layout.browserProvider.canvasAria`,{name:e.name}),className:J(`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden outline-none`,x&&`ring-1 ring-inset ring-[var(--interactive-selection-border)]`),onFocus:()=>S(!0),onBlur:()=>S(!1),onKeyDown:M(`down`),onKeyUp:M(`up`),onPaste:N,children:[(0,$.jsx)(`canvas`,{ref:i,className:J(`max-h-full max-w-full`,y?`block`:`hidden`,p.controller===`user`&&!p.mine?`cursor-not-allowed`:`cursor-default`),onPointerDown:A(`down`),onPointerMove:A(`move`),onPointerUp:A(`up`),onWheel:j,onContextMenu:e=>e.preventDefault()}),!y||d.status!==`open`?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:n(d.status===`ended`?d.reason===`service-stopped`?`layout.browserProvider.ended.service-stopped`:d.reason===`extension-unavailable`?`layout.browserProvider.ended.extension-unavailable`:`layout.browserProvider.ended.host-shutdown`:d.status===`reconnecting`?`layout.browserProvider.status.reconnecting`:`layout.browserProvider.status.connecting`)}):null]})]})},vf=(e,t)=>{let n=lt(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},yf=(e,t,n=10)=>{let r=ut(e);if(!r||n<1)return[];let i=new Set,a=[];for(let e of Object.values(t))if(e)for(let t of e){if(t.type!==`directory`)continue;let e=ut(t.path);if(!e||i.has(e))continue;let o=vf(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},bf=e=>e.some(e=>!!ut(e)),xf=(e,t)=>{let n=new Set(t.map(e=>ut(e)).filter(Boolean));return e.filter(e=>!n.has(e))},Sf=(e,t,n)=>t.length===0?e.length===0:xf(e,t).length>0?!1:t.every(e=>n.has(ut(e))),Cf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),wf=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},Tf=(e,t)=>{let n=wf(t),r=wf(e).replace(/\/+$/,``);return n===r?`.`:!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Ef=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Df=new Set([`node_modules`]),Of=e=>Df.has(e),kf=e=>{let t=wf(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Af=8,jf=new Map,Mf=e=>{let t=jf.get(e);return t?(t.touchedAt=Date.now(),jf.delete(e),jf.set(e,t),t):null},Nf=e=>{let t=jf.get(e);if(t)return t.touchedAt=Date.now(),t;if(jf.size>=Af){let e=jf.keys().next().value;e!==void 0&&jf.delete(e)}let n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return jf.set(e,n),n},Pf=e=>{jf.delete(e)},Ff=(e,t)=>(0,$.jsx)(Ji,{filePath:e,extension:t,className:`size-3.5`}),If=e=>{let t=(0,pl.c)(3),{status:n}=e,r;t[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)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},Lf=Q.memo(e=>{let t=(0,pl.c)(73),{node:n,root:r,isExpanded:i,isActive:a,status:o,badge:s,permissions:c,downloadFile:l,onSelect:u,onToggle:d,onRevealPath:f,onOpenDialog:p}=e,{t:m}=Tt(),h=n.type===`directory`,{canRename:g,canCreateFile:_,canCreateFolder:v,canDelete:y,canReveal:b}=c,[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),T;t[0]!==_||t[1]!==v||t[2]!==y||t[3]!==g||t[4]!==b?(T=e=>{!g&&!_&&!v&&!y&&!b||(e?.preventDefault(),w(!0))},t[0]=_,t[1]=v,t[2]=y,t[3]=g,t[4]=b,t[5]=T):T=t[5];let E=T,D;t[6]!==h||t[7]!==n||t[8]!==u||t[9]!==d?(D=()=>{h?d(n.path):u(n)},t[6]=h,t[7]=n,t[8]=u,t[9]=d,t[10]=D):D=t[10];let O=D,k;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(k=e=>{e.stopPropagation(),w(!1),S(!0)},t[11]=k):k=t[11];let A=k,j;t[12]!==_||t[13]!==v||t[14]!==y||t[15]!==g||t[16]!==b||t[17]!==l||t[18]!==h||t[19]!==n||t[20]!==p||t[21]!==f||t[22]!==m?(j=e=>{let{Item:t,Separator:r}=e;return(0,$.jsxs)($.Fragment,{children:[g&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`rename`,n)},children:[(0,$.jsx)(Z,{name:`edit`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),wt(n.path).then(e=>{e.ok||X.error(m(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.copyPath`)]}),!h&&l&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),l(n.path).catch(e=>{console.error(`Download failed:`,e),X.error(m(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(Z,{name:`download`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.save`)]}),b&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),f(n.path)},children:[(0,$.jsx)(Z,{name:`folder-received`,className:`mr-2 h-4 w-4`}),` `,m(Nt())]}),h&&(_||v)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(r,{}),_&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`createFile`,n)},children:[(0,$.jsx)(Z,{name:`file-add`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.newFile`)]}),v&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`createFolder`,n)},children:[(0,$.jsx)(Z,{name:`folder-add`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.newFolder`)]})]}),y&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(r,{}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`delete`,n)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.delete`)]})]})]})},t[12]=_,t[13]=v,t[14]=y,t[15]=g,t[16]=b,t[17]=l,t[18]=h,t[19]=n,t[20]=p,t[21]=f,t[22]=m,t[23]=j):j=t[23];let M=j,N;t[24]!==n.path||t[25]!==r?(N=e=>{let t=Tf(r,n.path);!t||t===`.`||(e.dataTransfer.setData(`application/x-yuri-file-path`,t),e.dataTransfer.effectAllowed=`copy`)},t[24]=n.path,t[25]=r,t[26]=N):N=t[26];let P=N,F;t[27]===E?F=t[28]:(F=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:E}),t[27]=E,t[28]=F);let I=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,L;t[29]===I?L=t[30]:(L=J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,I,`cursor-grab active:cursor-grabbing`),t[29]=I,t[30]=L);let R;t[31]!==h||t[32]!==i||t[33]!==n.extension||t[34]!==n.path?(R=h?i?(0,$.jsx)(Z,{name:`folder-open-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`folder-3-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):Ff(n.path,n.extension),t[31]=h,t[32]=i,t[33]=n.extension,t[34]=n.path,t[35]=R):R=t[35];let z;t[36]!==n.name||t[37]!==n.path?(z=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,title:n.path,children:n.name}),t[36]=n.name,t[37]=n.path,t[38]=z):z=t[38];let B;t[39]!==h||t[40]!==o?(B=!h&&o&&(0,$.jsx)(If,{status:o}),t[39]=h,t[40]=o,t[41]=B):B=t[41];let V;t[42]!==s||t[43]!==h?(V=h&&s&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[s.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,s.modified]}),s.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,s.added]})]}),t[42]=s,t[43]=h,t[44]=V):V=t[44];let ee;t[45]!==E||t[46]!==P||t[47]!==O||t[48]!==z||t[49]!==B||t[50]!==V||t[51]!==L||t[52]!==R?(ee=(0,$.jsxs)(`button`,{type:`button`,onClick:O,onContextMenu:E,draggable:!0,onDragStart:P,className:L,children:[R,z,B,V]}),t[45]=E,t[46]=P,t[47]=O,t[48]=z,t[49]=B,t[50]=V,t[51]=L,t[52]=R,t[53]=ee):ee=t[53];let H;t[54]!==_||t[55]!==v||t[56]!==y||t[57]!==g||t[58]!==b||t[59]!==x||t[60]!==M||t[61]!==m?(H=(g||_||v||y||b)&&(0,$.jsx)(`div`,{className:`absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100`,children:(0,$.jsxs)(Ga,{open:x,onOpenChange:S,children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:A,title:m(`sidebarFilesTree.actions.fileMenuTitle`),"aria-label":m(`sidebarFilesTree.actions.fileMenuTitle`),children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`h-4 w-4`})})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:m(`sidebarFilesTree.actions.fileMenuTitle`)})]}),(0,$.jsx)(Ia,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>S(!1),children:M({Item:ka,Separator:za})})]})}),t[54]=_,t[55]=v,t[56]=y,t[57]=g,t[58]=b,t[59]=x,t[60]=M,t[61]=m,t[62]=H):H=t[62];let te;t[63]!==ee||t[64]!==H||t[65]!==F?(te=(0,$.jsxs)(Wc,{render:F,children:[ee,H]}),t[63]=ee,t[64]=H,t[65]=F,t[66]=te):te=t[66];let ne;t[67]===M?ne=t[68]:(ne=(0,$.jsx)(Gc,{className:`min-w-[180px]`,children:M({Item:Kc,Separator:Uc})}),t[67]=M,t[68]=ne);let re;return t[69]!==C||t[70]!==te||t[71]!==ne?(re=(0,$.jsxs)(Hc,{open:C,onOpenChange:w,children:[te,ne]}),t[69]=C,t[70]=te,t[71]=ne,t[72]=re):re=t[72],re},(e,t)=>e.node===t.node&&e.root===t.root&&e.isExpanded===t.isExpanded&&e.isActive===t.isActive&&e.status===t.status&&e.badge===t.badge&&e.permissions===t.permissions&&e.downloadFile===t.downloadFile&&e.onSelect===t.onSelect&&e.onToggle===t.onToggle&&e.onRevealPath===t.onRevealPath&&e.onOpenDialog===t.onOpenDialog),Rf=()=>{let{t:e}=Tt(),{files:t}=at(),n=es()??``,r=wf(n.trim()),i=T(),a=x(),o=Fe(e=>e.searchFiles),s=q(e=>e.openContextFile),c=Oo(n),[l,u]=Q.useState(``),d=Eo(l,200),f=Q.useRef(null),[p,m]=Q.useState([]),[h,g]=Q.useState(!1),[_,v]=Q.useState({}),[y,b]=Q.useState({}),S=Q.useRef(new Set),C=Q.useRef(new Set),w=Q.useRef(null),E=Q.useRef(!1);Q.useEffect(()=>{if(!r){v({}),b({}),S.current=new Set;return}let e=Mf(r);e?(v({...e.childrenByDir}),b({...e.loadErrorsByDir}),S.current=new Set(e.loadedDirs)):(v({}),b({}),S.current=new Set)},[r]),Q.useEffect(()=>{if(!r)return;let e=Nf(r);e.childrenByDir=_},[r,_]),Q.useEffect(()=>{if(!r)return;let e=Nf(r);e.loadErrorsByDir=y},[r,y]),Q.useEffect(()=>{if(!r)return;let e=Nf(r);e.loadedDirs=new Set(S.current)},[r,_,y]),Q.useEffect(()=>()=>{if(!r)return;let e=jf.get(r);e&&e.loadedDirs.size===0&&Object.keys(e.childrenByDir).length===0&&Pf(r)},[r]);let D=Q.useMemo(()=>[],[]),O=Q.useMemo(()=>[],[]),k=bo(e=>r?e.byRoot[r]?.expandedPaths??D:D),A=bo(e=>r?e.byRoot[r]?.selectedPath??null:null),j=bo(e=>e.setSelectedPath),M=bo(e=>e.addOpenPath),N=bo(e=>e.removeOpenPathsByPrefix),P=bo(e=>e.removeExpandedPathsByPrefix),F=bo(e=>e.toggleExpandedPath),I=bo(e=>e.expandPaths),L=q(e=>r?e.contextPanelByDirectory[r]?.tabs??O:O),R=Q.useMemo(()=>new Set(L.map(e=>e.mode===`file`?e.targetPath:null).filter(e=>typeof e==`string`&&e.length>0).map(e=>wf(e))),[L]),[z,B]=Q.useState(null),[V,ee]=Q.useState(null),[H,te]=Q.useState(``),[ne,re]=Q.useState(!1),U=!!t.writeFile,ie=!!t.createDirectory,ae=!!t.rename,W=!!t.delete,oe=!!t.revealPath,se=Q.useMemo(()=>({canRename:ae,canCreateFile:U,canCreateFolder:ie,canDelete:W,canReveal:oe}),[ae,U,ie,W,oe]),ce=Q.useCallback(n=>{t.revealPath&&t.revealPath(n).catch(()=>{X.error(e(`sidebarFilesTree.toast.revealFailed`))})},[t,e]),G=Q.useCallback((e,t)=>{B(e),ee(t),te(e===`rename`&&t.name||``),re(!1)},[]),le=Q.useCallback((e,t)=>Cf(t.filter(e=>e&&typeof e.name==`string`&&e.name.length>0).filter(e=>i||!e.name.startsWith(`.`)).filter(e=>a||!Of(e.name)).map(t=>{let n=t.name,r=wf(t.path||``),i=r?Ef(r)?r:wf(`${e}/${r}`):wf(`${e}/${n}`),a=t.isDirectory?`directory`:`file`;return{name:n,path:i,type:a,extension:a===`file`&&n.includes(`.`)?n.split(`.`).pop()?.toLowerCase():void 0}})),[a,i]),ue=Q.useCallback(async(e,n)=>{let r=wf(e.trim());if(!r||S.current.has(r)||C.current.has(r))return;C.current=new Set(C.current),C.current.add(r);let i=t.listDirectory?t.listDirectory(r).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):Le.listLocalDirectory(r).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})));try{let e=await i;if(n?.())return;let t=le(r,e);S.current=new Set(S.current),S.current.add(r),b(e=>{if(!e[r])return e;let t={...e};return delete t[r],t}),v(e=>({...e,[r]:t}))}catch(e){if(n?.())return;let t=e instanceof Error?e.message:String(e??``);console.error(`Failed to load sidebar directory:`,e),b(e=>({...e,[r]:t}))}finally{C.current=new Set(C.current),C.current.delete(r)}},[t,le]),de=Q.useCallback(async()=>{if(!r)return;w.current?.abort();let e=new AbortController;w.current=e;try{let t=(bo.getState().byRoot[r]?.expandedPaths??[]).map(e=>wf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)),n=[r,...t];S.current=new Set(S.current);for(let e of n)S.current.delete(e);b(e=>{if(Object.keys(e).length===0)return e;let t={...e},r=!1;for(let e of n)e in t&&(delete t[e],r=!0);return r?t:e});let i=()=>e.signal.aborted;await ue(r,i);for(let n=0;n<t.length&&!e.signal.aborted;n+=3){let e=t.slice(n,n+3);await Promise.all(e.map(e=>ue(e,i)))}}catch(t){if(e.signal.aborted)return;console.error(`Failed to refresh sidebar tree:`,t)}finally{w.current===e&&(w.current=null)}},[ue,r]),fe=Q.useCallback(async e=>{if(!e){await de();return}let t=wf(e);S.current=new Set(S.current),S.current.delete(t),C.current=new Set(C.current),C.current.delete(t),await ue(t)},[ue,de]);Q.useEffect(()=>{r&&(w.current?.abort(),E.current=!1,S.current=new Set,C.current=new Set,b({}),v(e=>Object.keys(e).length===0?e:{}),ue(r))},[ue,r,i,a]),Q.useEffect(()=>{if(!r||k.length===0)return;let e=k.map(e=>wf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)&&!S.current.has(e)&&!C.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1,n=()=>t;return(async()=>{for(let r=0;r<e.length&&!t;r+=3){let t=e.slice(r,r+3);await Promise.all(t.map(e=>ue(e,n)))}})(),()=>{t=!0}},[k,ue,r]),Q.useEffect(()=>{if(!n){m([]),g(!1);return}let e=d.trim();if(!e){m([]),g(!1);return}let t=!1;return g(!0),o(n,e,150,{includeHidden:i,respectGitignore:!a,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>a||!kf(e.path)).map(e=>({name:e.name,path:wf(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));m(n)}).catch(()=>{t||m([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[n,d,o,i,a]);let pe=Q.useMemo(()=>{let e=new Map;if(!c?.files)return e;for(let t of c.files)t.index===`A`||t.working_dir===`?`?e.set(t.path,`git-added`):t.index===`D`?e.set(t.path,`git-deleted`):(t.index===`M`||t.working_dir===`M`)&&e.set(t.path,`git-modified`);return e},[c]),me=Q.useMemo(()=>{let e=new Map;if(!c?.files||!r)return e;for(let t of c.files){let n=t.index===`M`||t.working_dir===`M`,i=t.index===`A`||t.working_dir===`?`;if(!n&&!i)continue;let a=t.path.split(`/`);if(a.length<=1)continue;let o=r;for(let t=0;t<a.length-1;t++){o=`${o}/${a[t]}`;let r=e.get(o);r||(r={modified:0,added:0},e.set(o,r)),n&&r.modified++,i&&r.added++}}return e},[c,r]),he=Q.useCallback(e=>{if(R.has(e))return`open`;if(pe.size===0)return null;let t=e.startsWith(r+`/`)?e.slice(r.length+1):e;return pe.get(t)??null},[R,pe,r]),ge=Q.useCallback(e=>{if(me.size===0)return null;let t=me.get(e);return t&&t.modified+t.added>0?t:null},[me]),_e=Q.useCallback(async e=>{if(!r)return;let n=await lc(t,e.path);if(!n.ok){X.error(Nc(n.reason));return}j(r,e.path),M(r,e.path),s(r,e.path)},[M,t,s,r,j]),ve=Q.useCallback(async e=>{let t=wf(e);r&&(F(r,t),S.current.has(t)||await ue(t))},[ue,r,F]),ye=Q.useMemo(()=>r?yf(r,_):[],[_,r]),be=Q.useMemo(()=>new Set(k.map(e=>wf(e))),[k]),xe=bf(k),Se=Q.useCallback(()=>{if(r){if(xe){E.current=!1,P(r,r);return}E.current=!0,I(r,ye)}},[xe,ye,I,P,r]);Q.useEffect(()=>{if(!r||!E.current)return;let e=xf(ye,k);if(e.length>0){I(r,e);return}let t=new Set([...S.current,...Object.keys(y)]);Sf(ye,k,t)&&(E.current=!1)},[ye,I,k,y,r]);let Ce=Q.useCallback(async n=>{if(n?.preventDefault(),!V||!z)return;re(!0);let i=()=>re(!1),a=()=>B(null);if(z===`createFile`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.filenameRequired`)),i();return}if(!t.writeFile){X.error(e(`sidebarFilesTree.toast.writeNotSupported`)),i();return}let n=V.path,r=wf(`${n?`${n}/`:``}${H.trim()}`);await t.writeFile(r,``).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.fileCreated`)),await fe(n)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`createFolder`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.folderNameRequired`)),i();return}let n=V.path,r=wf(`${n?`${n}/`:``}${H.trim()}`);await t.createDirectory(r).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.folderCreated`)),await fe(n)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`rename`){if(!H.trim()){X.error(e(`sidebarFilesTree.toast.nameRequired`)),i();return}if(!t.rename){X.error(e(`sidebarFilesTree.toast.renameNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`),s=wf(`${o?`${o}/`:``}${H.trim()}`);await t.rename(n,s).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.renamedSuccessfully`)),await fe(o),r&&N(r,n),(A===n||A&&A.startsWith(`${n}/`))&&j(r,null)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(z===`delete`){if(!t.delete){X.error(e(`sidebarFilesTree.toast.deleteNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`);await t.delete(n).then(async t=>{t.success&&(X.success(e(`sidebarFilesTree.toast.deletedSuccessfully`)),await fe(o),r&&N(r,n),(A===n||A&&A.startsWith(n+`/`))&&j(r,null)),a()}).catch(()=>X.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}i()},[z,V,H,t,fe,N,r,A,j,e]);function we(n,i){return(_[n]??[]).map(n=>{let a=n.type===`directory`,o=a&&be.has(wf(n.path)),s=A===n.path;return(0,$.jsxs)(`li`,{className:`relative`,children:[i>0&&(0,$.jsx)(`span`,{className:`absolute top-3 left-[-12px] h-px w-3 bg-border/40`}),(0,$.jsx)(Lf,{node:n,root:r,isExpanded:o,isActive:s,status:a?void 0:he(n.path),badge:a?ge(n.path):void 0,permissions:se,downloadFile:t.downloadFile,onSelect:_e,onToggle:ve,onRevealPath:ce,onOpenDialog:G}),a&&o&&(0,$.jsxs)(`ul`,{className:`relative ml-3 flex flex-col border-l border-border/40 pl-3`,children:[y[n.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:y[n.path],children:y[n.path]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void fe(n.path),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):null,we(n.path,i+1)]})]},n.path)})}let Te=!!(r&&_[r]),Ee=r?y[r]:null,De=e(xe?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`);return(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(la,{ref:f,value:l,onChange:e=>u(e.target.value),placeholder:e(`sidebarFilesTree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),l.trim().length>0?(0,$.jsx)(`button`,{type:`button`,"aria-label":e(`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:()=>{u(``),f.current?.focus()},children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})}):null]}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-0.5`,children:[U&&(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>G(`createFile`,{path:n,type:`directory`}),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.newFileTitle`),"aria-label":e(`sidebarFilesTree.actions.newFileTitle`),children:(0,$.jsx)(Z,{name:`file-add`,className:`size-3.5`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFileTitle`)})]}),ie&&(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>G(`createFolder`,{path:n,type:`directory`}),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.newFolderTitle`),"aria-label":e(`sidebarFilesTree.actions.newFolderTitle`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`size-3.5`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFolderTitle`)})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:()=>void de(),className:`w-6 flex-shrink-0 p-0`,title:e(`sidebarFilesTree.actions.refreshTitle`),"aria-label":e(`sidebarFilesTree.actions.refreshTitle`),children:(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.refreshTitle`)})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,onClick:Se,disabled:ye.length===0&&k.length===0,className:`w-6 flex-shrink-0 p-0`,title:De,"aria-label":De,children:(0,$.jsx)(Z,{name:xe?`contract-up-down`:`expand-up-down`,className:`size-3.5`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:De})]})]})]}),(0,$.jsx)(mo,{outerClassName:`flex-1 min-h-0`,className:`p-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:h?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),e(`sidebarFilesTree.state.searching`)]}):p.length>0?p.map(e=>{let t=A===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_e(e),draggable:!0,onDragStart:t=>{let n=e.relativePath||Tf(r??``,e.path);!n||n===`.`||(t.dataTransfer.setData(`application/x-yuri-file-path`,n),t.dataTransfer.effectAllowed=`copy`)},className:J(`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`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),title:e.path,children:[Ff(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,style:{direction:`rtl`,textAlign:`left`},children:e.relativePath??e.path})]})},e.path)}):Ee?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:Ee}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void de(),children:[(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):Te&&r?we(r,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-code text-muted-foreground`,children:e(`sidebarFilesTree.state.loading`)})})}),(0,$.jsx)(mr,{open:!!z,onOpenChange:e=>!e&&B(null),children:(0,$.jsxs)(dr,{children:[(0,$.jsxs)(lr,{children:[(0,$.jsxs)(fr,{children:[z===`createFile`&&e(`sidebarFilesTree.dialog.createFile.title`),z===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.title`),z===`rename`&&e(`sidebarFilesTree.dialog.rename.title`),z===`delete`&&e(`sidebarFilesTree.dialog.delete.title`)]}),(0,$.jsxs)(pr,{children:[z===`createFile`&&e(`sidebarFilesTree.dialog.createFile.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),z===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),z===`rename`&&e(`sidebarFilesTree.dialog.rename.description`,{name:V?.name??``}),z===`delete`&&e(`sidebarFilesTree.dialog.delete.description`,{name:V?.name??``})]})]}),z!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(la,{value:H,onChange:e=>te(e.target.value),placeholder:e(z===`rename`?`sidebarFilesTree.dialog.rename.placeholder`:`sidebarFilesTree.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&Ce()},autoFocus:!0})}),(0,$.jsxs)(ur,{children:[(0,$.jsx)(Y,{variant:`outline`,onClick:()=>B(null),disabled:ne,children:e(`sidebarFilesTree.dialog.cancel`)}),(0,$.jsx)(Y,{variant:z===`delete`?`destructive`:`default`,onClick:()=>void Ce(),disabled:ne||z!==`delete`&&!H.trim(),children:ne?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):e(z===`delete`?`sidebarFilesTree.dialog.delete.confirm`:`sidebarFilesTree.dialog.confirm`)})]})]})})]})},zf=()=>!(typeof document<`u`&&document.hidden||typeof navigator<`u`&&!navigator.onLine);function Bf(e,t,n,r){let i=(0,pl.c)(6),{git:a}=at(),o=ko(Vf),s=!!(e&&a&&t&&n===`git`&&r!==`git`),c,l;i[0]!==e||i[1]!==o||i[2]!==a||i[3]!==s?(c=()=>{if(!s||!e||!a)return;o(e,a);let t=window.setInterval(()=>{zf()&&o(e,a)},1e4);return()=>window.clearInterval(t)},l=[s,e,a,o],i[0]=e,i[1]=o,i[2]=a,i[3]=s,i[4]=c,i[5]=l):(c=i[4],l=i[5]),Q.useEffect(c,l)}function Vf(e){return e.ensureStatus}var Hf=()=>{let e=(0,pl.c)(48),{t}=Tt(),n=q(Uf),r=q(Wf),i=q(Gf),a=q(Kf),o=es(),s=Ka(),c;e[0]!==s.data?.providers||e[1]!==s.data?.selectedId?(c=s.data?.providers.find(e=>e.id===s.data?.selectedId)??null,e[0]=s.data?.providers,e[1]=s.data?.selectedId,e[2]=c):c=e[2];let l=c,u;e[3]===s.data?u=e[4]:(u=ja(s.data),e[3]=s.data,e[4]=u);let d=u;Bf(o,i,n,a);let f=a===`git`,p;e[5]!==f||e[6]!==d?(p=Gi({hideGit:f,showBrowser:d}),e[5]=f,e[6]=d,e[7]=p):p=e[7];let m=p,h,g;e[8]!==n||e[9]!==r||e[10]!==m?(h=()=>{m.includes(n)||r(m[0]??`files`)},g=[n,r,m],e[8]=n,e[9]=r,e[10]=m,e[11]=h,e[12]=g):(h=e[11],g=e[12]),Q.useEffect(h,g);let _;if(e[13]!==t||e[14]!==m){let n;e[16]===t?n=e[17]:(n=e=>({id:e,label:t(e===`git`?`layout.rightSidebar.git`:e===`files`?`layout.rightSidebar.files`:`layout.rightSidebar.browser`),icon:(0,$.jsx)(Z,{name:e===`git`?`git-branch`:e===`files`?`folder-3`:`global`,className:`h-3.5 w-3.5`})}),e[16]=t,e[17]=n),_=m.map(n),e[13]=t,e[14]=m,e[15]=_}else _=e[15];let v=_,y=i&&n===`git`&&!f,b;e[18]!==r||e[19]!==m?(b=e=>{pi(e)&&m.includes(e)&&r(e)},e[18]=r,e[19]=m,e[20]=b):b=e[20];let x=b,S;e[21]!==x||e[22]!==n||e[23]!==v?(S=(0,$.jsx)(`div`,{className:`h-9 bg-background pt-1 px-2`,children:(0,$.jsx)(as,{items:v,activeId:n,onSelect:x,layoutMode:`fit`,variant:`active-pill`,activePillLowercase:!1,className:`h-full`})}),e[21]=x,e[22]=n,e[23]=v,e[24]=S):S=e[24];let C=n!==`git`&&`hidden`,w;e[25]===C?w=e[26]:(w=J(`h-full`,C),e[25]=C,e[26]=w);let T;e[27]===y?T=e[28]:(T=(0,$.jsx)(cf,{isActive:y}),e[27]=y,e[28]=T);let E;e[29]!==T||e[30]!==w?(E=(0,$.jsx)(`div`,{className:w,children:T}),e[29]=T,e[30]=w,e[31]=E):E=e[31];let D=n!==`files`&&`hidden`,O;e[32]===D?O=e[33]:(O=J(`h-full`,D),e[32]=D,e[33]=O);let k;e[34]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(Rf,{}),e[34]=k):k=e[34];let A;e[35]===O?A=e[36]:(A=(0,$.jsx)(`div`,{className:O,children:k}),e[35]=O,e[36]=A);let j;e[37]!==n||e[38]!==l||e[39]!==d?(j=d&&l?(0,$.jsx)(`div`,{className:J(`h-full`,n!==`browser`&&`hidden`),children:(0,$.jsx)(_f,{provider:l})}):null,e[37]=n,e[38]=l,e[39]=d,e[40]=j):j=e[40];let M;e[41]!==E||e[42]!==A||e[43]!==j?(M=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[E,A,j]}),e[41]=E,e[42]=A,e[43]=j,e[44]=M):M=e[44];let N;return e[45]!==M||e[46]!==S?(N=(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[S,M]}),e[45]=M,e[46]=S,e[47]=N):N=e[47],N};function Uf(e){return e.rightSidebarTab}function Wf(e){return e.setRightSidebarTab}function Gf(e){return e.isRightSidebarOpen}function Kf(e){return e.activeMainTab}var qf=(e,t)=>{if(!t)return null;let n=Number.parseInt(e.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,t.state.doc.lines)},Jf=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Yf=(e,t,n)=>{let r=e.state.doc.line(t),i=Math.max(1,Math.min(n,r.length+1)),a=r.from+i-1;e.dispatch({selection:ht.cursor(a),effects:mt.scrollIntoView(a,{y:`center`})})};function Xf({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=Tt(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>qf(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Jf(n,n.state.selection),o(``))},[e,n]),Q.useEffect(()=>{e&&window.requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()})},[e]),Q.useEffect(()=>{if(!(!e||!n||!s.current)){if(d===null){let{selection:e}=s.current;n.dispatch({selection:e,effects:mt.scrollIntoView(e.main.from,{y:`center`})});return}Yf(n,d,s.current.character)}},[d,e,n]);let f=Q.useCallback(()=>{if(!n||c.current||!s.current)return;let{selection:e}=s.current;n.dispatch({selection:e,effects:mt.scrollIntoView(e.main.from,{y:`center`})})},[n]),p=Q.useCallback(e=>{e||f(),t(e)},[t,f]),m=Q.useCallback(()=>{!n||d===null||!s.current||(c.current=!0,Yf(n,d,s.current.character),t(!1),n.focus())},[d,t,n]);Q.useEffect(()=>{if(!e)return;let t=e=>{let t=l.current,n=e.target;!t||!(n instanceof Node)||t.contains(n)||p(!1)},n=e=>{e.key===`Escape`&&(e.preventDefault(),p(!1))};return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n,!0),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n,!0)}},[p,e,r]);let h=Q.useMemo(()=>{if(!n)return i(`goToLineDialog.helper.editorUnavailable`);if(d===null){let e=s.current??Jf(n,n.state.selection);return i(`goToLineDialog.helper.currentLineRange`,{current:e.lineNumber,max:n.state.doc.lines})}return i(`goToLineDialog.helper.goToLine`,{line:d})},[d,i,n]);return r===`inline`?e?(0,$.jsxs)(`div`,{ref:l,className:`ml-1 flex h-6 items-center gap-1`,children:[(0,$.jsx)(la,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholderShort`),className:`h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta`}),(0,$.jsx)(Y,{variant:`outline`,size:`xs`,onClick:m,disabled:!n||d===null,className:`h-6 px-2`,children:i(`goToLineDialog.actions.go`)})]}):null:(0,$.jsx)(`div`,{ref:l,className:J(`absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all`,e?`pointer-events-auto translate-y-0 opacity-100`:`pointer-events-none -translate-y-1 opacity-0`),children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(la,{ref:u,type:`number`,min:1,step:1,inputMode:`numeric`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())},placeholder:i(`goToLineDialog.field.linePlaceholder`),className:`h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label`}),(0,$.jsx)(`div`,{className:`mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95`,children:h})]})})}var Zf=No(()=>dt(()=>import(`./ToolOutputDialog-BvgdBVst.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]))),Qf=e=>{let t=tp(e);if(!t)return``;if(t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return t;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},$f=e=>{let t=(0,pl.c)(8),{label:n,iconDataUrl:r}=e,[i,a]=Q.useState(!1),o;t[0]===n?o=t[1]:(o=n.trim().slice(0,1).toUpperCase()||`?`,t[0]=n,t[1]=o);let s=o;if(r&&!i){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>a(!0),t[2]=e):e=t[2];let n;return t[3]===r?n=t[4]:(n=(0,$.jsx)(`img`,{src:r,alt:``,className:`size-4 rounded-sm`,onError:e}),t[3]=r,t[4]=n),n}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`size-4 rounded-sm flex items-center justify-center`,`bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground`),t[5]=c):c=t[5];let l;return t[6]===s?l=t[7]:(l=(0,$.jsx)(`span`,{className:c,children:s}),t[6]=s,t[7]=l),l},ep=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),tp=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},np=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),rp=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,ip=(e,t)=>{let n=tp(t),r=tp(e);if(!n||!r)return!1;let i=rp(n),a=rp(r);return a===i||a.startsWith(`${i}/`)},ap=(e,t)=>{let n=tp(t),r=tp(e);if(!ip(r,n))return[];let i=r.slice(n.length).replace(/^\//,``).split(`/`),a=[],o=n;for(let e=0;e<i.length-1;e++)o=o?`${o}/${i[e]}`:i[e],a.push(o);return a},op=(e,t)=>{if(!t)return``;let n=tp(t);if(!e||!ip(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},sp=new Set([`node_modules`]),cp=e=>{let t=(0,pl.c)(3),{status:n}=e,r;t[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)`},t[0]=r):r=t[0];let i=r[n],a;return t[1]===i?a=t[2]:(a=(0,$.jsx)(`span`,{className:`size-2 rounded-full`,style:{backgroundColor:i}}),t[1]=i,t[2]=a),a},lp=e=>{let t=(0,pl.c)(11),{name:n}=e,r=Q.useRef(null),i=Q.useRef(null),[a,o]=Q.useState(!1),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=r.current,t=i.current;if(!e||!t)return;let n=()=>{o(t.scrollWidth>e.clientWidth+1)};n();let a=new ResizeObserver(n);return a.observe(e),a.observe(t),()=>{a.disconnect()}},t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=[n],t[1]=n,t[2]=c),Q.useLayoutEffect(s,c);let l;t[3]===n?l=t[4]:(l=(0,$.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:`invisible absolute whitespace-nowrap`,children:n}),t[3]=n,t[4]=l);let u;t[5]!==n||t[6]!==a?(u=a?(0,$.jsxs)(`span`,{className:`open-file-name-marquee-track`,children:[(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,children:n}),(0,$.jsx)(`span`,{className:`open-file-name-marquee-item`,"aria-hidden":`true`,children:n})]}):(0,$.jsx)(`span`,{className:`block min-w-0 truncate`,children:n}),t[5]=n,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`span`,{ref:r,className:`relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d},up=e=>sp.has(e),dp=e=>{let t=tp(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},fp=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},pp=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`file not found`)||t.includes(`enoent`)||t.includes(`no such file`)||t.includes(`does not exist`)},mp=2e5,hp=`yuri:files:auto-save-enabled`,gp=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
7
7
  `:`
8
- `},hp=e=>e.replace(/\r\n/g,`
8
+ `},_p=e=>e.replace(/\r\n/g,`
9
9
  `).replace(/\r/g,`
10
- `),gp=(e,t)=>{let n=hp(e);return t===`\r
10
+ `),vp=(e,t)=>{let n=_p(e);return t===`\r
11
11
  `?n.replace(/\n/g,`\r
12
- `):n},_p=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(pp)!==`false`}catch{return!0}},vp=(e,t)=>(0,$.jsx)(Bi,{filePath:e,extension:t}),yp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},bp=e=>{let t=(0,fl.c)(83),{node:n,root:r,isExpanded:i,isActive:a,isMobile:o,alwaysShowActions:s,status:c,badge:l,permissions:u,downloadFile:d,contextMenuPath:f,setContextMenuPath:p,rightClickMenuPath:m,setRightClickMenuPath:h,onSelect:g,onToggle:_,onRevealPath:v,onOpenDialog:y}=e,{t:b}=wt(),x=n.type===`directory`,{canRename:S,canCreateFile:C,canCreateFolder:w,canDelete:T,canReveal:E}=u,D;t[0]!==C||t[1]!==w||t[2]!==T||t[3]!==S||t[4]!==E||t[5]!==n.path||t[6]!==h?(D=e=>{!S&&!C&&!w&&!T&&!E||(e?.preventDefault(),h(n.path))},t[0]=C,t[1]=w,t[2]=T,t[3]=S,t[4]=E,t[5]=n.path,t[6]=h,t[7]=D):D=t[7];let O=D,k;t[8]!==x||t[9]!==n||t[10]!==g||t[11]!==_?(k=()=>{x?_(n.path):g(n)},t[8]=x,t[9]=n,t[10]=g,t[11]=_,t[12]=k):k=t[12];let A=k,j;t[13]!==n.path||t[14]!==p||t[15]!==h?(j=e=>{e.stopPropagation(),h(null),p(n.path)},t[13]=n.path,t[14]=p,t[15]=h,t[16]=j):j=t[16];let M=j,N;t[17]!==C||t[18]!==w||t[19]!==T||t[20]!==S||t[21]!==E||t[22]!==d||t[23]!==x||t[24]!==n||t[25]!==y||t[26]!==v||t[27]!==r||t[28]!==b?(N=e=>{let{Item:t,Separator:i}=e;return(0,$.jsxs)($.Fragment,{children:[S&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`rename`,n)},children:[(0,$.jsx)(Z,{name:`edit`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),Ct(n.path).then(e=>{e.ok||X.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.copyPath`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation();let t=ip(r,n.path)||n.path;Ct(t).then(e=>{if(e.ok){X.success(b(`filesView.toast.relativePathCopied`));return}X.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy-2`,className:`mr-2 size-4`}),` `,b(`filesView.tree.menu.copyRelativePath`)]}),!x&&d&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),d(n.path).catch(e=>{console.error(`Download failed:`,e),X.error(b(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(Z,{name:`download`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.save`)]}),E&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),v(n.path)},children:[(0,$.jsx)(Z,{name:`folder-received`,className:`mr-2 size-4`}),` `,b(Mt())]}),x&&(C||w)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),C&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFile`,n)},children:[(0,$.jsx)(Z,{name:`file-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFile`)]}),w&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFolder`,n)},children:[(0,$.jsx)(Z,{name:`folder-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFolder`)]})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`delete`,n)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.delete`)]})]})]})},t[17]=C,t[18]=w,t[19]=T,t[20]=S,t[21]=E,t[22]=d,t[23]=x,t[24]=n,t[25]=y,t[26]=v,t[27]=r,t[28]=b,t[29]=N):N=t[29];let P=N,F=m===n.path,I;t[30]!==n.path||t[31]!==h?(I=e=>h(e?n.path:null),t[30]=n.path,t[31]=h,t[32]=I):I=t[32];let L=o?void 0:O,R;t[33]===L?R=t[34]:(R=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:L}),t[33]=L,t[34]=R);let z=o?void 0:O,B=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,V;t[35]===B?V=t[36]:(V=J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,B),t[35]=B,t[36]=V);let ee;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(ee=x?i?(0,$.jsx)(Z,{name:`folder-open-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`folder-3-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):vp(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=ee):ee=t[41];let H;t[42]!==n.name||t[43]!==n.path?(H=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,title:n.path,children:n.name}),t[42]=n.name,t[43]=n.path,t[44]=H):H=t[44];let te;t[45]!==x||t[46]!==c?(te=!x&&c&&(0,$.jsx)(op,{status:c}),t[45]=x,t[46]=c,t[47]=te):te=t[47];let ne;t[48]!==l||t[49]!==x?(ne=x&&l&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[l.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,l.modified]}),l.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,l.added]})]}),t[48]=l,t[49]=x,t[50]=ne):ne=t[50];let re;t[51]!==A||t[52]!==V||t[53]!==ee||t[54]!==H||t[55]!==te||t[56]!==ne||t[57]!==z?(re=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:z,className:V,children:[ee,H,te,ne]}),t[51]=A,t[52]=V,t[53]=ee,t[54]=H,t[55]=te,t[56]=ne,t[57]=z,t[58]=re):re=t[58];let U;t[59]!==s||t[60]!==C||t[61]!==w||t[62]!==T||t[63]!==S||t[64]!==E||t[65]!==f||t[66]!==M||t[67]!==o||t[68]!==n.path||t[69]!==P||t[70]!==p?(U=(S||C||w||T||E)&&(0,$.jsx)(`div`,{className:J(`absolute right-1 top-1/2 -translate-y-1/2`,s?`opacity-100`:`opacity-0 focus-within:opacity-100 group-hover:opacity-100`),children:(0,$.jsxs)(Ua,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:M,children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`size-4`})})}),(0,$.jsx)(Pa,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:Da,Separator:La})})]})}),t[59]=s,t[60]=C,t[61]=w,t[62]=T,t[63]=S,t[64]=E,t[65]=f,t[66]=M,t[67]=o,t[68]=n.path,t[69]=P,t[70]=p,t[71]=U):U=t[71];let ie;t[72]!==re||t[73]!==U||t[74]!==R?(ie=(0,$.jsxs)(Uc,{render:R,children:[re,U]}),t[72]=re,t[73]=U,t[74]=R,t[75]=ie):ie=t[75];let ae;t[76]===P?ae=t[77]:(ae=(0,$.jsx)(Wc,{className:`min-w-[180px]`,children:P({Item:Gc,Separator:Hc})}),t[76]=P,t[77]=ae);let W;return t[78]!==ie||t[79]!==ae||t[80]!==F||t[81]!==I?(W=(0,$.jsxs)(Vc,{open:F,onOpenChange:I,children:[ie,ae]}),t[78]=ie,t[79]=ae,t[80]=F,t[81]=I,t[82]=W):W=t[82],W},xp=e=>{let t=(0,fl.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=wt(),d=!!n,f;t[0]===c?f=t[1]:(f=e=>!e&&c(),t[0]=c,t[1]=f);let p;t[2]!==n||t[3]!==u?(p=n===`createFile`&&u(`filesView.dialog.createFile.title`),t[2]=n,t[3]=u,t[4]=p):p=t[4];let m;t[5]!==n||t[6]!==u?(m=n===`createFolder`&&u(`filesView.dialog.createFolder.title`),t[5]=n,t[6]=u,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u?(h=n===`rename`&&u(`filesView.dialog.rename.title`),t[8]=n,t[9]=u,t[10]=h):h=t[10];let g;t[11]!==n||t[12]!==u?(g=n===`delete`&&u(`filesView.dialog.delete.title`),t[11]=n,t[12]=u,t[13]=g):g=t[13];let _;t[14]!==p||t[15]!==m||t[16]!==h||t[17]!==g?(_=(0,$.jsxs)(dr,{children:[p,m,h,g]}),t[14]=p,t[15]=m,t[16]=h,t[17]=g,t[18]=_):_=t[18];let v;t[19]!==n||t[20]!==r?.path||t[21]!==u?(v=n===`createFile`&&u(`filesView.dialog.createFile.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[19]=n,t[20]=r?.path,t[21]=u,t[22]=v):v=t[22];let y;t[23]!==n||t[24]!==r?.path||t[25]!==u?(y=n===`createFolder`&&u(`filesView.dialog.createFolder.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[23]=n,t[24]=r?.path,t[25]=u,t[26]=y):y=t[26];let b;t[27]!==n||t[28]!==r?.name||t[29]!==u?(b=n===`rename`&&u(`filesView.dialog.rename.description`,{name:r?.name??``}),t[27]=n,t[28]=r?.name,t[29]=u,t[30]=b):b=t[30];let x;t[31]!==n||t[32]!==r?.name||t[33]!==u?(x=n===`delete`&&u(`filesView.dialog.delete.description`,{name:r?.name??``}),t[31]=n,t[32]=r?.name,t[33]=u,t[34]=x):x=t[34];let S;t[35]!==b||t[36]!==x||t[37]!==v||t[38]!==y?(S=(0,$.jsxs)(fr,{children:[v,y,b,x]}),t[35]=b,t[36]=x,t[37]=v,t[38]=y,t[39]=S):S=t[39];let C;t[40]!==S||t[41]!==_?(C=(0,$.jsxs)(cr,{children:[_,S]}),t[40]=S,t[41]=_,t[42]=C):C=t[42];let w;t[43]!==n||t[44]!==i||t[45]!==l||t[46]!==a||t[47]!==s||t[48]!==u?(w=n!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(sa,{value:i,onChange:e=>a(e.target.value),placeholder:u(n===`rename`?`filesView.dialog.rename.placeholder`:`filesView.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&s()},ref:l})}),t[43]=n,t[44]=i,t[45]=l,t[46]=a,t[47]=s,t[48]=u,t[49]=w):w=t[49];let T;t[50]===u?T=t[51]:(T=u(`filesView.dialog.cancel`),t[50]=u,t[51]=T);let E;t[52]!==o||t[53]!==c||t[54]!==T?(E=(0,$.jsx)(Y,{variant:`outline`,onClick:c,disabled:o,children:T}),t[52]=o,t[53]=c,t[54]=T,t[55]=E):E=t[55];let D=n===`delete`?`destructive`:`default`,O;t[56]===s?O=t[57]:(O=()=>void s(),t[56]=s,t[57]=O);let k;t[58]!==n||t[59]!==i||t[60]!==o?(k=o||n!==`delete`&&!i.trim(),t[58]=n,t[59]=i,t[60]=o,t[61]=k):k=t[61];let A;t[62]!==n||t[63]!==o||t[64]!==u?(A=o?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):u(n===`delete`?`filesView.dialog.delete.confirm`:`filesView.dialog.confirm`),t[62]=n,t[63]=o,t[64]=u,t[65]=A):A=t[65];let j;t[66]!==D||t[67]!==O||t[68]!==k||t[69]!==A?(j=(0,$.jsx)(Y,{variant:D,onClick:O,disabled:k,children:A}),t[66]=D,t[67]=O,t[68]=k,t[69]=A,t[70]=j):j=t[70];let M;t[71]!==E||t[72]!==j?(M=(0,$.jsxs)(lr,{children:[E,j]}),t[71]=E,t[72]=j,t[73]=M):M=t[73];let N;t[74]!==l||t[75]!==C||t[76]!==w||t[77]!==M?(N=(0,$.jsxs)(ur,{initialFocus:l,children:[C,w,M]}),t[74]=l,t[75]=C,t[76]=w,t[77]=M,t[78]=N):N=t[78];let P;return t[79]!==d||t[80]!==f||t[81]!==N?(P=(0,$.jsx)(pr,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},Sp=(e,t,n)=>e&&!!t&&n===t,Cp=(e,t,n)=>{let o=(0,fl.c)(8),[s,c]=Q.useState(``),[l,u]=Q.useState(0),d,f;o[0]!==e||o[1]!==n||o[2]!==t?(d=()=>{if(!e){c(``);return}let o=!1;c(``);let s=m(),l=i(s);r(s).then(n=>{o||!n||(c(e),t(null))}).catch(r=>{o||(t(r instanceof Error?r.message:n),c(e))});let d=a(()=>{o||(c(e),u(Tp),t(null))});return()=>{o=!0,l(),d()}},f=[e,t,n],o[0]=e,o[1]=n,o[2]=t,o[3]=d,o[4]=f):(d=o[3],f=o[4]),Q.useEffect(d,f);let p;return o[5]!==l||o[6]!==s?(p={readyKey:s,nonce:l},o[5]=l,o[6]=s,o[7]=p):p=o[7],p},wp=({mode:e=`full`,isActive:t=!0,targetPath:n})=>{let{t:r}=wt(),{files:i,runtime:a}=at(),{currentTheme:s,availableThemes:c,lightThemeId:l,darkThemeId:u}=or(),{isMobile:d,isTablet:f,screenWidth:p}=eo(),m=d||f,h=T(),g=x(),v=Qo()??``,y=$f(v.trim()),b=d||e!==`editor-only`,S=e===`editor-only`&&!d,C=Fe(e=>e.searchFiles),w=Eo(v),[E,D]=Q.useState(``),O=wo(E,200),k=Q.useRef(null),[A,j]=Q.useState(!1),[M,F]=Q.useState(!0),[I,L]=Q.useState(!1),[R,z]=Q.useState(!1),[B,ee]=Q.useState(!1),[H,te]=Q.useState({open:!1,title:``,content:``}),ne=Q.useRef(null),re=Q.useRef(0),U=Q.useCallback(e=>{re.current=Math.max(0,re.current+(e?1:-1))},[]),ie=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!B)return;let e=e=>{re.current>0||ie(e.target)||ne.current&&!ne.current.contains(e.target)&&ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ie,B]);let[ae,W]=Q.useState(`edit`),[oe,se]=Q.useState(`edit`),[ce,G]=Q.useState(`edit`),[le,ue]=Q.useState(`preview`),[de,fe]=Q.useState(0),pe=Q.useRef({}),me=Q.useRef({}),he=Q.useRef({}),ge=Q.useRef({}),_e=Q.useMemo(()=>c.find(e=>e.metadata.id===l)??no(!1),[c,l]),ve=Q.useMemo(()=>c.find(e=>e.metadata.id===u)??no(!0),[c,u]);Q.useEffect(()=>{ko(_e),ko(ve)},[_e,ve]);let ye=Q.useMemo(()=>[],[]),be=vo(e=>y?e.byRoot[y]?.openPaths??ye:ye),xe=vo(e=>y?e.byRoot[y]?.selectedPath??null:null),Se=vo(e=>y?e.byRoot[y]?.expandedPaths??ye:ye),Ce=vo(e=>e.addOpenPath),we=vo(e=>e.removeOpenPath),Te=vo(e=>e.removeOpenPathsByPrefix),Ee=vo(e=>e.removeExpandedPathsByPrefix),De=vo(e=>e.setSelectedPath),Oe=vo(e=>e.toggleExpandedPath),ke=vo(e=>e.expandPaths),Ae=Q.useCallback(e=>{let t=$f(e),n=t.split(`/`),r=n[n.length-1]||t;return{name:r,path:t,type:`file`,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0}},[]),je=Q.useMemo(()=>be.map(Ae),[be,Ae]),Me=e===`editor-only`&&n?$f(n):null,Ne=Q.useMemo(()=>{if(Me)return Me;if(xe){let e=tp(xe);if(be.some(t=>tp(t)===e))return xe}return be[0]??null},[Me,be,xe]),K=Q.useMemo(()=>Ne?Ae(Ne):null,[Ne,Ae]),Pe=K?.path??``;Q.useEffect(()=>{if(!y||!xe)return;let e=tp(xe);be.some(t=>tp(t)===e)||De(y,be[0]??null)},[be,y,xe,De]);let Ie=!!(y&&Pe&&!np(Pe,y)),Re=Ie?ri(Pe):void 0,ze=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&Ie,outsideFileGrant:Re,directory:y||void 0}),[e,Ie,Re,y]),Be=Q.useRef(null),[Ve,He]=Q.useState({left:!1,right:!1}),Ue=Q.useCallback(()=>{let e=Be.current;e&&He({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),We=Q.useRef(Ue);We.current=Ue,Q.useEffect(()=>{let e=Be.current;if(!e)return;let t=()=>We.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[je.length]);let[Ge,Ke]=Q.useState({}),[qe,Je]=Q.useState({}),Ye=Q.useRef(new Set),Xe=Q.useRef(new Set),Ze=Q.useRef(!1),Qe=Q.useRef(new Map),$e=Q.useRef(0),[et,tt]=Q.useState([]),[nt,rt]=Q.useState(!1),[it,ot]=Q.useState(``),{isPlaying:lt,play:ut,stop:dt}=Ki(),[ft,mt]=Q.useState(!1),[gt,vt]=Q.useState(null),[yt,bt]=Q.useState(``),xt=Q.useRef(``),[Tt,Et]=Q.useState(null),[Dt,Ot]=Q.useState(null),[kt,jt]=Q.useState(``),[Mt,Nt]=Q.useState(!1),[Pt,Ft]=Q.useState(`
13
- `),It=Q.useRef(null),Lt=Q.useRef(null),Rt=Q.useRef(null),zt=Q.useRef(``),Bt=Q.useRef(``),Vt=Q.useRef(null),Ht=Q.useRef(null),Ut=Q.useRef(null),Wt=Q.useRef(0),Gt=Q.useRef(null),[Kt,qt]=Q.useState(`idle`),[Jt,Yt]=Q.useState(!1),[Xt,Zt]=Q.useState(_p),[Qt,$t]=Q.useState(!1),en=Q.useRef(null),tn=Q.useRef(null),nn=Q.useRef(null),rn=Q.useRef(!1),an=Q.useRef(null),on=Q.useRef(null),sn=Q.useRef(null),cn=Q.useRef(null),[ln,un]=Q.useState(0),dn=Q.useRef(null),fn=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{dn.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(dn.current),dn.current=null)},[]);let[pn,mn]=Q.useState(null),[hn,gn]=Q.useState(null),[_n,vn]=Q.useState(``),[yn,xn]=Q.useState(!1),[Sn,Cn]=Q.useState(null),[wn,Tn]=Q.useState(null),[En,Dn]=Q.useState(!1),[On,kn]=Q.useState(!1),[An,jn]=Q.useState(!1),[Mn,Nn]=Q.useState(!1),[Pn,Fn]=Q.useState(null),In=bn(e=>e.addCodeSelectionAttachment),Ln=bn(e=>e.setPendingInputText),Rn=!!i.writeFile,zn=!!i.createDirectory,Bn=!!i.rename,Vn=!!i.delete,Hn=!!i.revealPath,Un=Dl(e=>e.availableApps),Wn=Dl(e=>e.isCacheStale),Gn=Dl(e=>e.initialize),Kn=Dl(e=>e.loadInstalledApps);Q.useEffect(()=>{Gn()},[Gn]);let qn=Q.useCallback(e=>{i.revealPath&&i.revealPath(e).catch(()=>{X.error(r(`sidebarFilesTree.toast.revealFailed`))})},[i,r]),Jn=Q.useCallback(async e=>{if(!K?.path||await N(K.path,e.id,e.appName)||await V(K.path,e.appName))return;let t=Xf(K.path)||y;t&&await V(t,e.appName)||X.error(r(`filesView.toast.openInAppFailed`,{app:e.appName}))},[y,K?.path,r]),Yn=Q.useCallback((e,t)=>{mn(e),gn(t),vn(e===`rename`&&t.name||``),xn(!1)},[]),[Xn,Qn]=Q.useState(null),$n=Q.useRef(!1),er=Q.useRef(null),[tr,nr]=Q.useState(!1),rr=q(e=>e.setMainTabGuard),ir=q(e=>e.pendingFileNavigation),ar=q(e=>e.setPendingFileNavigation),sr=q(e=>e.pendingFileFocusPath),mr=q(e=>e.setPendingFileFocusPath),hr=q(e=>e.pendingFileViewerMode),gr=q(e=>e.setPendingFileViewerMode),_r=q(e=>e.shortcutOverrides),vr=q(e=>e.fileEditorKeymap),yr=Zn(e=>e.settingsDefaultFileViewerPreview),br=Zn(e=>e.showMessageTTSButtons),xr=q(e=>e.expandedEditorToolbar);Q.useEffect(()=>{let e=()=>{$n.current=!1,er.current=null,nr(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]),Q.useEffect(()=>()=>{an.current!==null&&window.clearTimeout(an.current),on.current!==null&&window.clearTimeout(on.current)},[]);let Sr=Q.useCallback((e,t)=>{let n=e.split(`
12
+ `):n},yp=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(hp)!==`false`}catch{return!0}},bp=(e,t)=>(0,$.jsx)(Ji,{filePath:e,extension:t}),xp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},Sp=e=>{let t=(0,pl.c)(83),{node:n,root:r,isExpanded:i,isActive:a,isMobile:o,alwaysShowActions:s,status:c,badge:l,permissions:u,downloadFile:d,contextMenuPath:f,setContextMenuPath:p,rightClickMenuPath:m,setRightClickMenuPath:h,onSelect:g,onToggle:_,onRevealPath:v,onOpenDialog:y}=e,{t:b}=Tt(),x=n.type===`directory`,{canRename:S,canCreateFile:C,canCreateFolder:w,canDelete:T,canReveal:E}=u,D;t[0]!==C||t[1]!==w||t[2]!==T||t[3]!==S||t[4]!==E||t[5]!==n.path||t[6]!==h?(D=e=>{!S&&!C&&!w&&!T&&!E||(e?.preventDefault(),h(n.path))},t[0]=C,t[1]=w,t[2]=T,t[3]=S,t[4]=E,t[5]=n.path,t[6]=h,t[7]=D):D=t[7];let O=D,k;t[8]!==x||t[9]!==n||t[10]!==g||t[11]!==_?(k=()=>{x?_(n.path):g(n)},t[8]=x,t[9]=n,t[10]=g,t[11]=_,t[12]=k):k=t[12];let A=k,j;t[13]!==n.path||t[14]!==p||t[15]!==h?(j=e=>{e.stopPropagation(),h(null),p(n.path)},t[13]=n.path,t[14]=p,t[15]=h,t[16]=j):j=t[16];let M=j,N;t[17]!==C||t[18]!==w||t[19]!==T||t[20]!==S||t[21]!==E||t[22]!==d||t[23]!==x||t[24]!==n||t[25]!==y||t[26]!==v||t[27]!==r||t[28]!==b?(N=e=>{let{Item:t,Separator:i}=e;return(0,$.jsxs)($.Fragment,{children:[S&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`rename`,n)},children:[(0,$.jsx)(Z,{name:`edit`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),wt(n.path).then(e=>{e.ok||X.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.copyPath`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation();let t=op(r,n.path)||n.path;wt(t).then(e=>{if(e.ok){X.success(b(`filesView.toast.relativePathCopied`));return}X.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(Z,{name:`file-copy-2`,className:`mr-2 size-4`}),` `,b(`filesView.tree.menu.copyRelativePath`)]}),!x&&d&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),d(n.path).catch(e=>{console.error(`Download failed:`,e),X.error(b(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(Z,{name:`download`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.save`)]}),E&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),v(n.path)},children:[(0,$.jsx)(Z,{name:`folder-received`,className:`mr-2 size-4`}),` `,b(Nt())]}),x&&(C||w)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),C&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFile`,n)},children:[(0,$.jsx)(Z,{name:`file-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFile`)]}),w&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFolder`,n)},children:[(0,$.jsx)(Z,{name:`folder-add`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.newFolder`)]})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`delete`,n)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.delete`)]})]})]})},t[17]=C,t[18]=w,t[19]=T,t[20]=S,t[21]=E,t[22]=d,t[23]=x,t[24]=n,t[25]=y,t[26]=v,t[27]=r,t[28]=b,t[29]=N):N=t[29];let P=N,F=m===n.path,I;t[30]!==n.path||t[31]!==h?(I=e=>h(e?n.path:null),t[30]=n.path,t[31]=h,t[32]=I):I=t[32];let L=o?void 0:O,R;t[33]===L?R=t[34]:(R=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:L}),t[33]=L,t[34]=R);let z=o?void 0:O,B=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,V;t[35]===B?V=t[36]:(V=J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,B),t[35]=B,t[36]=V);let ee;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(ee=x?i?(0,$.jsx)(Z,{name:`folder-open-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`folder-3-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):bp(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=ee):ee=t[41];let H;t[42]!==n.name||t[43]!==n.path?(H=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,title:n.path,children:n.name}),t[42]=n.name,t[43]=n.path,t[44]=H):H=t[44];let te;t[45]!==x||t[46]!==c?(te=!x&&c&&(0,$.jsx)(cp,{status:c}),t[45]=x,t[46]=c,t[47]=te):te=t[47];let ne;t[48]!==l||t[49]!==x?(ne=x&&l&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[l.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,l.modified]}),l.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,l.added]})]}),t[48]=l,t[49]=x,t[50]=ne):ne=t[50];let re;t[51]!==A||t[52]!==V||t[53]!==ee||t[54]!==H||t[55]!==te||t[56]!==ne||t[57]!==z?(re=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:z,className:V,children:[ee,H,te,ne]}),t[51]=A,t[52]=V,t[53]=ee,t[54]=H,t[55]=te,t[56]=ne,t[57]=z,t[58]=re):re=t[58];let U;t[59]!==s||t[60]!==C||t[61]!==w||t[62]!==T||t[63]!==S||t[64]!==E||t[65]!==f||t[66]!==M||t[67]!==o||t[68]!==n.path||t[69]!==P||t[70]!==p?(U=(S||C||w||T||E)&&(0,$.jsx)(`div`,{className:J(`absolute right-1 top-1/2 -translate-y-1/2`,s?`opacity-100`:`opacity-0 focus-within:opacity-100 group-hover:opacity-100`),children:(0,$.jsxs)(Ga,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:M,children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`size-4`})})}),(0,$.jsx)(Ia,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:ka,Separator:za})})]})}),t[59]=s,t[60]=C,t[61]=w,t[62]=T,t[63]=S,t[64]=E,t[65]=f,t[66]=M,t[67]=o,t[68]=n.path,t[69]=P,t[70]=p,t[71]=U):U=t[71];let ie;t[72]!==re||t[73]!==U||t[74]!==R?(ie=(0,$.jsxs)(Wc,{render:R,children:[re,U]}),t[72]=re,t[73]=U,t[74]=R,t[75]=ie):ie=t[75];let ae;t[76]===P?ae=t[77]:(ae=(0,$.jsx)(Gc,{className:`min-w-[180px]`,children:P({Item:Kc,Separator:Uc})}),t[76]=P,t[77]=ae);let W;return t[78]!==ie||t[79]!==ae||t[80]!==F||t[81]!==I?(W=(0,$.jsxs)(Hc,{open:F,onOpenChange:I,children:[ie,ae]}),t[78]=ie,t[79]=ae,t[80]=F,t[81]=I,t[82]=W):W=t[82],W},Cp=e=>{let t=(0,pl.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=Tt(),d=!!n,f;t[0]===c?f=t[1]:(f=e=>!e&&c(),t[0]=c,t[1]=f);let p;t[2]!==n||t[3]!==u?(p=n===`createFile`&&u(`filesView.dialog.createFile.title`),t[2]=n,t[3]=u,t[4]=p):p=t[4];let m;t[5]!==n||t[6]!==u?(m=n===`createFolder`&&u(`filesView.dialog.createFolder.title`),t[5]=n,t[6]=u,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u?(h=n===`rename`&&u(`filesView.dialog.rename.title`),t[8]=n,t[9]=u,t[10]=h):h=t[10];let g;t[11]!==n||t[12]!==u?(g=n===`delete`&&u(`filesView.dialog.delete.title`),t[11]=n,t[12]=u,t[13]=g):g=t[13];let _;t[14]!==p||t[15]!==m||t[16]!==h||t[17]!==g?(_=(0,$.jsxs)(fr,{children:[p,m,h,g]}),t[14]=p,t[15]=m,t[16]=h,t[17]=g,t[18]=_):_=t[18];let v;t[19]!==n||t[20]!==r?.path||t[21]!==u?(v=n===`createFile`&&u(`filesView.dialog.createFile.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[19]=n,t[20]=r?.path,t[21]=u,t[22]=v):v=t[22];let y;t[23]!==n||t[24]!==r?.path||t[25]!==u?(y=n===`createFolder`&&u(`filesView.dialog.createFolder.description`,{path:r?.path??u(`filesView.dialog.rootFallback`)}),t[23]=n,t[24]=r?.path,t[25]=u,t[26]=y):y=t[26];let b;t[27]!==n||t[28]!==r?.name||t[29]!==u?(b=n===`rename`&&u(`filesView.dialog.rename.description`,{name:r?.name??``}),t[27]=n,t[28]=r?.name,t[29]=u,t[30]=b):b=t[30];let x;t[31]!==n||t[32]!==r?.name||t[33]!==u?(x=n===`delete`&&u(`filesView.dialog.delete.description`,{name:r?.name??``}),t[31]=n,t[32]=r?.name,t[33]=u,t[34]=x):x=t[34];let S;t[35]!==b||t[36]!==x||t[37]!==v||t[38]!==y?(S=(0,$.jsxs)(pr,{children:[v,y,b,x]}),t[35]=b,t[36]=x,t[37]=v,t[38]=y,t[39]=S):S=t[39];let C;t[40]!==S||t[41]!==_?(C=(0,$.jsxs)(lr,{children:[_,S]}),t[40]=S,t[41]=_,t[42]=C):C=t[42];let w;t[43]!==n||t[44]!==i||t[45]!==l||t[46]!==a||t[47]!==s||t[48]!==u?(w=n!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(la,{value:i,onChange:e=>a(e.target.value),placeholder:u(n===`rename`?`filesView.dialog.rename.placeholder`:`filesView.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&s()},ref:l})}),t[43]=n,t[44]=i,t[45]=l,t[46]=a,t[47]=s,t[48]=u,t[49]=w):w=t[49];let T;t[50]===u?T=t[51]:(T=u(`filesView.dialog.cancel`),t[50]=u,t[51]=T);let E;t[52]!==o||t[53]!==c||t[54]!==T?(E=(0,$.jsx)(Y,{variant:`outline`,onClick:c,disabled:o,children:T}),t[52]=o,t[53]=c,t[54]=T,t[55]=E):E=t[55];let D=n===`delete`?`destructive`:`default`,O;t[56]===s?O=t[57]:(O=()=>void s(),t[56]=s,t[57]=O);let k;t[58]!==n||t[59]!==i||t[60]!==o?(k=o||n!==`delete`&&!i.trim(),t[58]=n,t[59]=i,t[60]=o,t[61]=k):k=t[61];let A;t[62]!==n||t[63]!==o||t[64]!==u?(A=o?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):u(n===`delete`?`filesView.dialog.delete.confirm`:`filesView.dialog.confirm`),t[62]=n,t[63]=o,t[64]=u,t[65]=A):A=t[65];let j;t[66]!==D||t[67]!==O||t[68]!==k||t[69]!==A?(j=(0,$.jsx)(Y,{variant:D,onClick:O,disabled:k,children:A}),t[66]=D,t[67]=O,t[68]=k,t[69]=A,t[70]=j):j=t[70];let M;t[71]!==E||t[72]!==j?(M=(0,$.jsxs)(ur,{children:[E,j]}),t[71]=E,t[72]=j,t[73]=M):M=t[73];let N;t[74]!==l||t[75]!==C||t[76]!==w||t[77]!==M?(N=(0,$.jsxs)(dr,{initialFocus:l,children:[C,w,M]}),t[74]=l,t[75]=C,t[76]=w,t[77]=M,t[78]=N):N=t[78];let P;return t[79]!==d||t[80]!==f||t[81]!==N?(P=(0,$.jsx)(mr,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},wp=(e,t,n)=>e&&!!t&&n===t,Tp=(e,t,n)=>{let o=(0,pl.c)(8),[s,c]=Q.useState(``),[l,u]=Q.useState(0),d,f;o[0]!==e||o[1]!==n||o[2]!==t?(d=()=>{if(!e){c(``);return}let o=!1;c(``);let s=m(),l=i(s);r(s).then(n=>{o||!n||(c(e),t(null))}).catch(r=>{o||(t(r instanceof Error?r.message:n),c(e))});let d=a(()=>{o||(c(e),u(Dp),t(null))});return()=>{o=!0,l(),d()}},f=[e,t,n],o[0]=e,o[1]=n,o[2]=t,o[3]=d,o[4]=f):(d=o[3],f=o[4]),Q.useEffect(d,f);let p;return o[5]!==l||o[6]!==s?(p={readyKey:s,nonce:l},o[5]=l,o[6]=s,o[7]=p):p=o[7],p},Ep=({mode:e=`full`,isActive:t=!0,targetPath:n})=>{let{t:r}=Tt(),{files:i,runtime:a}=at(),{currentTheme:s,availableThemes:c,lightThemeId:l,darkThemeId:u}=sr(),{isMobile:d,isTablet:f,screenWidth:p}=no(),m=d||f,h=T(),g=x(),v=es()??``,y=tp(v.trim()),b=d||e!==`editor-only`,S=e===`editor-only`&&!d,C=Fe(e=>e.searchFiles),w=Oo(v),[E,D]=Q.useState(``),O=Eo(E,200),k=Q.useRef(null),[A,j]=Q.useState(!1),[M,F]=Q.useState(!0),[I,L]=Q.useState(!1),[R,z]=Q.useState(!1),[B,ee]=Q.useState(!1),[H,te]=Q.useState({open:!1,title:``,content:``}),ne=Q.useRef(null),re=Q.useRef(0),U=Q.useCallback(e=>{re.current=Math.max(0,re.current+(e?1:-1))},[]),ie=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!B)return;let e=e=>{re.current>0||ie(e.target)||ne.current&&!ne.current.contains(e.target)&&ee(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ie,B]);let[ae,W]=Q.useState(`edit`),[oe,se]=Q.useState(`edit`),[ce,G]=Q.useState(`edit`),[le,ue]=Q.useState(`preview`),[de,fe]=Q.useState(0),pe=Q.useRef({}),me=Q.useRef({}),he=Q.useRef({}),ge=Q.useRef({}),_e=Q.useMemo(()=>c.find(e=>e.metadata.id===l)??io(!1),[c,l]),ve=Q.useMemo(()=>c.find(e=>e.metadata.id===u)??io(!0),[c,u]);Q.useEffect(()=>{jo(_e),jo(ve)},[_e,ve]);let ye=Q.useMemo(()=>[],[]),be=bo(e=>y?e.byRoot[y]?.openPaths??ye:ye),xe=bo(e=>y?e.byRoot[y]?.selectedPath??null:null),Se=bo(e=>y?e.byRoot[y]?.expandedPaths??ye:ye),Ce=bo(e=>e.addOpenPath),we=bo(e=>e.removeOpenPath),Te=bo(e=>e.removeOpenPathsByPrefix),Ee=bo(e=>e.removeExpandedPathsByPrefix),De=bo(e=>e.setSelectedPath),Oe=bo(e=>e.toggleExpandedPath),ke=bo(e=>e.expandPaths),Ae=Q.useCallback(e=>{let t=tp(e),n=t.split(`/`),r=n[n.length-1]||t;return{name:r,path:t,type:`file`,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0}},[]),je=Q.useMemo(()=>be.map(Ae),[be,Ae]),Me=e===`editor-only`&&n?tp(n):null,Ne=Q.useMemo(()=>{if(Me)return Me;if(xe){let e=rp(xe);if(be.some(t=>rp(t)===e))return xe}return be[0]??null},[Me,be,xe]),K=Q.useMemo(()=>Ne?Ae(Ne):null,[Ne,Ae]),Pe=K?.path??``;Q.useEffect(()=>{if(!y||!xe)return;let e=rp(xe);be.some(t=>rp(t)===e)||De(y,be[0]??null)},[be,y,xe,De]);let Ie=!!(y&&Pe&&!ip(Pe,y)),Re=Ie?li(Pe):void 0,ze=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&Ie,outsideFileGrant:Re,directory:y||void 0}),[e,Ie,Re,y]),Be=Q.useRef(null),[Ve,He]=Q.useState({left:!1,right:!1}),Ue=Q.useCallback(()=>{let e=Be.current;e&&He({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),We=Q.useRef(Ue);We.current=Ue,Q.useEffect(()=>{let e=Be.current;if(!e)return;let t=()=>We.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[je.length]);let[Ge,Ke]=Q.useState({}),[qe,Je]=Q.useState({}),Ye=Q.useRef(new Set),Xe=Q.useRef(new Set),Ze=Q.useRef(!1),Qe=Q.useRef(new Map),$e=Q.useRef(0),[et,tt]=Q.useState([]),[nt,rt]=Q.useState(!1),[it,ot]=Q.useState(``),{isPlaying:lt,play:ut,stop:dt}=Lr(),[ft,pt]=Q.useState(!1),[ht,_t]=Q.useState(null),[yt,bt]=Q.useState(``),xt=Q.useRef(``),[St,Et]=Q.useState(null),[Dt,Ot]=Q.useState(null),[kt,At]=Q.useState(``),[Mt,Nt]=Q.useState(!1),[Pt,Ft]=Q.useState(`
13
+ `),It=Q.useRef(null),Lt=Q.useRef(null),Rt=Q.useRef(null),zt=Q.useRef(``),Bt=Q.useRef(``),Vt=Q.useRef(null),Ht=Q.useRef(null),Ut=Q.useRef(null),Wt=Q.useRef(0),Gt=Q.useRef(null),[Kt,qt]=Q.useState(`idle`),[Jt,Yt]=Q.useState(!1),[Xt,Zt]=Q.useState(yp),[Qt,$t]=Q.useState(!1),en=Q.useRef(null),tn=Q.useRef(null),nn=Q.useRef(null),rn=Q.useRef(!1),an=Q.useRef(null),on=Q.useRef(null),sn=Q.useRef(null),cn=Q.useRef(null),[ln,un]=Q.useState(0),dn=Q.useRef(null),fn=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{dn.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(dn.current),dn.current=null)},[]);let[pn,mn]=Q.useState(null),[hn,gn]=Q.useState(null),[_n,vn]=Q.useState(``),[yn,bn]=Q.useState(!1),[Sn,Cn]=Q.useState(null),[wn,Tn]=Q.useState(null),[En,Dn]=Q.useState(!1),[On,kn]=Q.useState(!1),[An,jn]=Q.useState(!1),[Mn,Nn]=Q.useState(!1),[Pn,Fn]=Q.useState(null),In=xn(e=>e.addCodeSelectionAttachment),Ln=xn(e=>e.setPendingInputText),Rn=!!i.writeFile,zn=!!i.createDirectory,Bn=!!i.rename,Vn=!!i.delete,Hn=!!i.revealPath,Un=Ol(e=>e.availableApps),Wn=Ol(e=>e.isCacheStale),Gn=Ol(e=>e.initialize),Kn=Ol(e=>e.loadInstalledApps);Q.useEffect(()=>{Gn()},[Gn]);let qn=Q.useCallback(e=>{i.revealPath&&i.revealPath(e).catch(()=>{X.error(r(`sidebarFilesTree.toast.revealFailed`))})},[i,r]),Jn=Q.useCallback(async e=>{if(!K?.path||await N(K.path,e.id,e.appName)||await V(K.path,e.appName))return;let t=Qf(K.path)||y;t&&await V(t,e.appName)||X.error(r(`filesView.toast.openInAppFailed`,{app:e.appName}))},[y,K?.path,r]),Yn=Q.useCallback((e,t)=>{mn(e),gn(t),vn(e===`rename`&&t.name||``),bn(!1)},[]),[Xn,Zn]=Q.useState(null),$n=Q.useRef(!1),er=Q.useRef(null),[tr,nr]=Q.useState(!1),rr=q(e=>e.setMainTabGuard),ir=q(e=>e.pendingFileNavigation),ar=q(e=>e.setPendingFileNavigation),or=q(e=>e.pendingFileFocusPath),cr=q(e=>e.setPendingFileFocusPath),hr=q(e=>e.pendingFileViewerMode),gr=q(e=>e.setPendingFileViewerMode),_r=q(e=>e.shortcutOverrides),vr=q(e=>e.fileEditorKeymap),yr=Qn(e=>e.settingsDefaultFileViewerPreview),br=Qn(e=>e.showMessageTTSButtons),xr=q(e=>e.expandedEditorToolbar);Q.useEffect(()=>{let e=()=>{$n.current=!1,er.current=null,nr(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]),Q.useEffect(()=>()=>{an.current!==null&&window.clearTimeout(an.current),on.current!==null&&window.clearTimeout(on.current)},[]);let Sr=Q.useCallback((e,t)=>{let n=e.split(`
14
14
  `),r=Math.max(1,t.start),i=Math.min(n.length,t.end);return r>i?``:n.slice(r-1,i).join(`
15
- `)},[]),{drafts:Cr,commentText:wr,setCommentText:Tr,editingDraftId:Er,setSelection:Dr,saveComment:Or,cancel:kr,reset:Ar,startEdit:jr,deleteDraft:Mr}=vc({source:`file`,fileLabel:K?.path??null,language:K?.path&&Yo(K.path)||`text`,getCodeForRange:e=>Sr(it,Ac(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Qn(null),Ar(),rr(null),jt(``),Nt(!1)},[K?.path,Ar,rr]),Q.useEffect(()=>{Dr(Xn)},[Xn,Dr]),Q.useEffect(()=>{if(!Xn&&!Er)return;let e=e=>{let t=e.target;t.closest(`[data-comment-input="true"]`)||t.closest(`[data-comment-card="true"]`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||wr.trim()||(Qn(null),kr())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[kr,wr,Er,Xn]);let Nr=Q.useCallback((e,t)=>{let n=t??Xn??void 0;t&&Qn(t),Or(e,n),Qn(null)},[Xn,Or]),Pr=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!h&&r.name.startsWith(`.`)||!g&&cp(r.name))continue;let t=r.name,i=$f(r.path||``),a=i?ep(i)?i:$f(`${e}/${i}`):$f(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return Qf(n)},[g,h]),Fr=Q.useCallback(async e=>{let t=$f(e.trim());if(!t||Ye.current.has(t)||Xe.current.has(t))return;Xe.current=new Set(Xe.current),Xe.current.add(t);let n=$e.current+1;$e.current=n,Qe.current=new Map(Qe.current),Qe.current.set(t,n);let r=()=>Qe.current.get(t)===n;await(i.listDirectory?i.listDirectory(t).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):Le.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!r())return;let n=Pr(t,e);Ye.current=new Set(Ye.current),Ye.current.add(t),Je(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ke(e=>({...e,[t]:n}))}).catch(e=>{if(!r())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&y&&t!==y){Ee(y,t),Je(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Je(e=>({...e,[t]:n}))}).finally(()=>{r()&&(Qe.current=new Map(Qe.current),Qe.current.delete(t),Xe.current=new Set(Xe.current),Xe.current.delete(t))})},[i,Pr,Ee,y]),Ir=Q.useCallback(async()=>{y&&(Ye.current=new Set,Xe.current=new Set,Qe.current=new Map,Je({}),Ke(e=>Object.keys(e).length===0?e:{}),await Fr(y))},[Fr,y]),Lr=Q.useCallback(async e=>{if(!e){await Ir();return}let t=$f(e);Ye.current=new Set(Ye.current),Ye.current.delete(t),Xe.current=new Set(Xe.current),Xe.current.delete(t),await Fr(t)},[Fr,Ir]),Rr=Q.useRef(``),zr=Q.useRef(``);Q.useEffect(()=>{if(!y)return;let e=`${y}|h${h?`1`:`0`}|g${g?`1`:`0`}`,t=Rr.current!==y,n=zr.current!==e;!t&&!n||(t&&(Rr.current=y,ot(``),vt(null),bt(``),Et(null),j(!1)),n&&(zr.current=e,Ze.current=!1,Ye.current=new Set,Xe.current=new Set,Qe.current=new Map,Je({}),Ke(e=>Object.keys(e).length===0?e:{}),Fr(y)))},[Fr,y,g,h]),Q.useEffect(()=>{if(!i.listDirectory)return;let e=()=>{if(!document.hidden&&Se.length>0)for(let e of Se)Lr(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Se,i.listDirectory,Lr]),Q.useEffect(()=>{if(!y||Se.length===0)return;let e=Se.map(e=>$f(e)).filter(e=>!!e&&e!==y&&e.startsWith(`${y}/`)&&!Ye.current.has(e)&&!Xe.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1;return(async()=>{for(let n=0;n<e.length&&!t;n+=3){let t=e.slice(n,n+3);await Promise.all(t.map(e=>Fr(e)))}})(),()=>{t=!0}},[Se,Fr,y]);let Br=Q.useCallback(async e=>{if(e?.preventDefault(),!hn||!pn)return;xn(!0);let t=()=>{mn(null)},n=e=>{X.error(e)},a=()=>{xn(!1)};if(pn===`createFile`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!i.writeFile){n(r(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=hn.path,o=$f(`${e?`${e}/`:``}${_n.trim()}`);await i.writeFile(o,``).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.fileCreated`)),await Lr(e)),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`createFolder`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=hn.path,o=$f(`${e?`${e}/`:``}${_n.trim()}`);await i.createDirectory(o).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.folderCreated`)),await Lr(e)),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`rename`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!i.rename){n(r(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=hn.path,o=e.split(`/`).slice(0,-1).join(`/`),s=$f(`${o?`${o}/`:``}${_n.trim()}`);await i.rename(e,s).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.renamedSuccessfully`)),await Lr(o),y&&Te(y,e),(K?.path===e||K?.path.startsWith(`${e}/`))&&(y&&De(y,null),ot(``),vt(null),bt(``),Et(null),d&&j(!1))),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`delete`){if(!i.delete){n(r(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=hn.path,o=e.split(`/`).slice(0,-1).join(`/`);await i.delete(e).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.deletedSuccessfully`)),await Lr(o),y&&Te(y,e),(K?.path===e||K?.path.startsWith(`${e}/`))&&(y&&De(y,null),ot(``),vt(null),bt(``),Et(null),d&&j(!1))),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[pn,hn,_n,i,Lr,d,Te,y,K?.path,De,r]);Q.useEffect(()=>{if(!v){tt([]),rt(!1);return}let e=O.trim();if(!e){tt([]),rt(!1);return}let t=!1;return rt(!0),C(v,e,150,{includeHidden:h,respectGitignore:!g,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>g||!lp(e.path)).map(e=>({name:e.name,path:$f(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));tt(n)}).catch(()=>{t||tt([])}).finally(()=>{t||rt(!1)}),()=>{t=!0}},[v,O,C,h,g]);let Vr=Q.useCallback(async(e,t)=>{if(i.readFile)return(await i.readFile(e,{...t??{},directory:y||void 0})).content??``;let n=new URLSearchParams({path:e});t?.allowOutsideWorkspace&&n.set(`allowOutsideWorkspace`,`true`),t?.outsideFileGrant&&n.set(`outsideFileGrant`,t.outsideFileGrant),t?.optional&&n.set(`optional`,`true`),y&&n.set(`directory`,y);let a=await _(`/api/fs/read?${n.toString()}`,{cache:t?.optional?`no-store`:`default`});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||r(`filesView.error.readFileFailed`))}return a.text()},[i,y,r]),Hr=Q.useCallback(async(e,t)=>{if(i.statFile){let n=await i.statFile(e,{...t??{},directory:y||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[i,y]);Q.useEffect(()=>{if(!y||!i.statFile||be.length===0)return;let e=!1,t=be.filter(e=>e!==Pe||Jo(e)&&!e.toLowerCase().endsWith(`.svg`)||Xo(e));return Promise.all(t.map(async t=>{try{let n=await i.statFile?.(t,{directory:y||void 0});!e&&n&&!n.isFile&&Te(y,t)}catch(n){!e&&dp(n)&&Te(y,t)}})),()=>{e=!0}},[i,be,Te,y,Pe]);let Ur=Q.useMemo(()=>it.length>fp?`${it.slice(0,fp)}\n\n… truncated …`:it,[it]),Wr=kt!==Ur,Gr=Q.useCallback(async()=>{if(!K||!i.writeFile)return X.error(r(`filesView.toast.savingNotSupported`)),!1;if(!Wr)return!0;if(kt===``&&it!==``&&Tt!==K.path)return console.warn(`[saveDraft] refusing to save empty draft for "${K.path}" (${it.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;Nt(!0);try{let e=gp(kt,Pt);return(await i.writeFile(K.path,e))?.success?(ot(kt),K?.path&&Zo(K.path)&&(zt.current=kt,Bt.current=kt),Hr(K.path).then(e=>{e&&(Ut.current=e)}).catch(()=>{}),!0):(X.error(r(`filesView.toast.writeFileFailed`)),!1)}catch(e){return X.error(e instanceof Error?e.message:r(`filesView.toast.saveFailed`)),!1}finally{Nt(!1)}},[kt,it,i,Wr,Pt,Tt,Hr,K,r]);Q.useEffect(()=>{if(!Wr){rr(null);return}let e=(e,t)=>rn.current?(rn.current=!1,!0):($t(!0),tn.current=t??e,!1);return rr(e),()=>{q.getState().mainTabGuard===e&&rr(null)}},[Wr,rr]),Q.useEffect(()=>{try{window.localStorage.setItem(pp,Xt?`true`:`false`)}catch{}},[Xt]),Q.useEffect(()=>{Xt||(qt(`idle`),Lt.current&&=(clearTimeout(Lt.current),null))},[Xt]);let Kr=1500;Q.useEffect(()=>{let e=!!(K&&i.writeFile);if(!(!Xt||!Wr||!e||Mt))return Lt.current=setTimeout(()=>{Gr().then(e=>{e&&(qt(`saved`),setTimeout(()=>qt(`idle`),2e3))})},Kr),()=>{Lt.current&&=(clearTimeout(Lt.current),null)}},[Xt,kt,Wr,K,i.writeFile,Mt,Gr]),Q.useEffect(()=>{qt(`idle`)},[K?.path]),Q.useEffect(()=>{let e=e=>{St(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Lt.current&&=(clearTimeout(Lt.current),null),Mt||Gr().then(e=>{e&&(qt(`saved`),setTimeout(()=>qt(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),z(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Mt,Gr]);let qr=_t(e=>{q.setState(t=>{let n=$f(t.pendingFileFocusPath??``)===e,r=$f(t.pendingFileNavigation?.path??``)===e;return!n&&!r?t:{...n?{pendingFileFocusPath:null,pendingFileViewerMode:null}:{},...r?{pendingFileNavigation:null}:{}}})}),Jr=_t(async t=>{let n=Wt.current+1;Wt.current=n;let i=()=>{if(!y)return!1;let e=vo.getState().byRoot[y],r=Me??e?.selectedPath??e?.openPaths[0]??null;return Wt.current===n&&r===t.path};vt(null),Ot(null),bt(``),Et(null);let o=Jo(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Xo(t.path);if(d&&j(!0),a.isDesktop&&o&&!s){ot(``),jt(``),mt(!0);return}if(!a.isDesktop&&o&&!s){ot(``),jt(``),Et(t.path),mt(!1);return}if(c){ot(``),jt(``),Et(t.path),mt(!1);return}mt(!0);let l=ri(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!y&&!np(t.path,y),outsideFileGrant:l};Gt.current=t.path,await Vr(t.path,u).then(e=>{if(!i())return;let n=hp(e);Ft(mp(e)),ot(n),zt.current=n,Bt.current=n,jt(n.length>fp?`${n.slice(0,fp)}\n\n… truncated …`:n),Et(t.path),Hr(t.path,u).then(e=>{e&&i()&&(Ut.current=e)}).catch(()=>{})}).catch(n=>{if(!i())return;qr(t.path),Gt.current=null,mt(!1),Ot(t.path),ot(``),jt(``),Ut.current=null;let a=n instanceof Error?n.message:r(`filesView.error.readFileFailed`);if(vt(a),e===`editor-only`){y&&up(n)?we(y,t.path):y&&dp(n)&&Te(y,t.path);return}if(up(n)){if(y&&we(y,t.path),vt(null),E.trim().length>0&&D(``),d&&j(!1),y){let e=[...rp(t.path,y),t.path];e.length>0&&ke(y,e);for(let t of e)Ye.current.has(t)||Fr(t)}return}if(dp(n)){y&&Te(y,t.path),vt(null),d&&j(!1);return}}).finally(()=>{i()&&(Gt.current=null,mt(!1))})}),Yr=Q.useCallback(async(e,t)=>{if(!y)return;let n=rp(e,y),r=t?[...n,e]:n;r.length>0&&ke(y,r);let i=r.map(e=>{if(!Ye.current.has(e))return Fr(e)}).filter(Boolean);await Promise.all(i)},[ke,Fr,y]),Xr=Q.useCallback((e,t)=>{let n=t.findIndex(t=>t.path===e);return n===-1||t.length<=1?null:t[n+1]??t[n-1]??null},[]),Zr=Q.useCallback(async e=>{if(rn.current)rn.current=!1;else if(Wr){$t(!0),en.current=e;return}y&&(De(y,e.path),Ce(y,e.path),Yr(e.path,!1)),vt(null),bt(``),ot(``),zt.current=``,Bt.current=``,jt(``),Et(null),Ot(null),d&&j(!0)},[Ce,Yr,Wr,d,y,De]);Q.useEffect(()=>{K?.path&&Yr(K.path,!1)},[Yr,K?.path]),Q.useEffect(()=>{if(!K){Wt.current+=1,mt(!1);return}Tt!==K.path&&Dt!==K.path&&Gt.current!==K.path&&Jr(K)},[i,e,y,a.isDesktop,d,Jr,Tt,Dt,K]),Q.useEffect(()=>()=>{Wt.current+=1,Gt.current=null},[y,Pe]);let Qr=Q.useRef(Wr);Qr.current=Wr,Q.useEffect(()=>{let e=K?.path??``;if(!Sp(t,e,Tt))return;let n=!1,r=window.setInterval(()=>{document.hidden||Hr(e,ze).then(t=>{if(n||!t)return;let r=Ut.current;if(!r||r.path!==e){Ut.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Qr.current||(Ut.current=t,Et(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,Tt,Hr,K?.path,ze]);let $r=Q.useCallback(()=>{let e=en.current,t=tn.current,n=nn.current;if(en.current=null,tn.current=null,nn.current=null,rn.current=!0,$t(!1),jt(Ur),n){y&&we(y,n),K?.path===n&&(e?Zr(e):(y&&De(y,null),ot(``),vt(null),bt(``),Et(null),d&&j(!1)));return}if(e){Zr(e);return}t&&(rr(null),typeof t==`function`?(rn.current=!1,t()):q.getState().setActiveMainTab(t))},[Ur,Zr,d,we,y,K?.path,rr,De]),ei=Q.useCallback(async()=>{let e=en.current,t=tn.current,n=nn.current;if(!await Gr()){rn.current=!1;return}if(en.current=null,tn.current=null,nn.current=null,rn.current=!0,$t(!1),n){y&&we(y,n),K?.path===n&&(e?await Zr(e):(y&&De(y,null),ot(``),vt(null),bt(``),Et(null),d&&j(!1)));return}if(e){await Zr(e);return}t&&(rr(null),typeof t==`function`?(rn.current=!1,t()):q.getState().setActiveMainTab(t))},[Zr,d,we,y,Gr,K?.path,rr,De]),ti=_t(()=>{if(Mt)return;let e=en.current;e&&qr(e.path),en.current=null,tn.current=null,nn.current=null,rn.current=!1,$t(!1)}),ni=_t(()=>{!K||ft||(Ot(null),vt(null),Et(null),mt(!0))}),ii=Q.useCallback(e=>{let t=K?.path===e,n=Xr(e,je);if(t&&Wr){$t(!0),en.current=n,nn.current=e;return}if(y&&we(y,e),t){if(n){Zr(n);return}y&&De(y,null),ot(``),vt(null),bt(``),Et(null),d&&j(!1)}},[Xr,Zr,Wr,d,je,we,y,K?.path,De]),ai=Q.useCallback(e=>{if(be.includes(e))return`open`;if(w?.files){let t=e.startsWith(y+`/`)?e.slice(y.length+1):e,n=w.files.find(e=>e.path===t);if(n){if(n.index===`A`||n.working_dir===`?`)return`git-added`;if(n.index===`D`)return`git-deleted`;if(n.index===`M`||n.working_dir===`M`)return`git-modified`}}return null},[be,w,y]),oi=Q.useCallback(e=>{if(!w?.files)return null;let t=e.startsWith(y+`/`)?e.slice(y.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of w.files)e.path.startsWith(n)&&((e.index===`M`||e.working_dir===`M`)&&r++,(e.index===`A`||e.working_dir===`?`)&&i++);return r+i>0?{modified:r,added:i}:null},[w,y]),si=Q.useCallback(async e=>{let t=$f(e);y&&(Oe(y,t),Ye.current.has(t)||await Fr(t))},[Fr,y,Oe]),ci=Q.useMemo(()=>y?_f(y,Ge):[],[Ge,y]),li=Q.useMemo(()=>new Set(Se.map(e=>$f(e))),[Se]),ui=vf(Se),di=Q.useCallback(()=>{if(y){if(ui){Ze.current=!1,Ee(y,y);return}Ze.current=!0,ke(y,ci)}},[ui,ci,ke,Ee,y]);Q.useEffect(()=>{if(!y||!Ze.current)return;let e=yf(ci,Se);if(e.length>0){ke(y,e);return}let t=new Set([...Ye.current,...Object.keys(qe)]);bf(ci,Se,t)&&(Ze.current=!1)},[ci,ke,Se,qe,y]);let fi=Q.useMemo(()=>({canRename:Bn,canCreateFile:Rn,canCreateFolder:zn,canDelete:Vn,canReveal:Hn}),[Bn,Rn,zn,Vn,Hn]);function pi(e,t){let n=Ge[e]??[];return n.map((e,a)=>{let o=e.type===`directory`,s=o&&li.has($f(e.path)),c=K?.path===e.path,l=a===n.length-1;return(0,$.jsxs)(`li`,{className:`relative`,children:[t>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`absolute top-3.5 left-[-12px] w-3 h-px bg-border/40`}),l&&(0,$.jsx)(`span`,{className:`absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background`})]}),(0,$.jsx)(bp,{node:e,root:y,isExpanded:s,isActive:c,isMobile:d,alwaysShowActions:m,status:o?void 0:ai(e.path),badge:o?oi(e.path):void 0,permissions:fi,downloadFile:i.downloadFile,contextMenuPath:Sn,setContextMenuPath:Cn,rightClickMenuPath:wn,setRightClickMenuPath:Tn,onSelect:Zr,onToggle:si,onRevealPath:qn,onOpenDialog:Yn}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[qe[e.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:qe[e.path],children:qe[e.path]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void Lr(e.path),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`}),r(`filesView.tree.actions.refreshTitle`)]})]}):null,pi(e.path,t+1)]})]},e.path)})}let mi=!!(K?.path&&Jo(K.path)),hi=!!(K?.path&&K.path.toLowerCase().endsWith(`.svg`)),_i=!!(K?.path&&Xo(K.path)),vi=Q.useMemo(()=>$f(ir?.path??``),[ir?.path]),yi=!!(ir&&vi&&Pe&&Pe===vi&&!ft&&!gt&&!mi&&!_i),bi=Q.useMemo(()=>ip(y,Pe),[Pe,y]),xi=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(Nn(e=>e===t?e:t),!t){Fn(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Fn({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),Si=Q.useCallback(()=>{let e=sn.current,t=e?.state.selection.main;if(!e||!t||t.empty||!K)return;let n=e.state.sliceDoc(t.from,t.to),r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(Math.max(t.from,t.to-1)).number,a=r===i?`${r}`:`${r}-${i}`,o=`${K.name}:${a}`;In(K.path,o,n),Ln(P(o),`append-inline`),Fn(null),q.getState().setActiveMainTab(`chat`)},[In,K,Ln]),Ci=Q.useCallback(e=>{if(!K)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=kt.split(`
15
+ `)},[]),{drafts:Cr,commentText:wr,setCommentText:Tr,editingDraftId:Er,setSelection:Dr,saveComment:Or,cancel:kr,reset:Ar,startEdit:jr,deleteDraft:Mr}=yc({source:`file`,fileLabel:K?.path??null,language:K?.path&&Zo(K.path)||`text`,getCodeForRange:e=>Sr(it,jc(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Zn(null),Ar(),rr(null),At(``),Nt(!1)},[K?.path,Ar,rr]),Q.useEffect(()=>{Dr(Xn)},[Xn,Dr]),Q.useEffect(()=>{if(!Xn&&!Er)return;let e=e=>{let t=e.target;t.closest(`[data-comment-input="true"]`)||t.closest(`[data-comment-card="true"]`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||wr.trim()||(Zn(null),kr())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[kr,wr,Er,Xn]);let Nr=Q.useCallback((e,t)=>{let n=t??Xn??void 0;t&&Zn(t),Or(e,n),Zn(null)},[Xn,Or]),Pr=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!h&&r.name.startsWith(`.`)||!g&&up(r.name))continue;let t=r.name,i=tp(r.path||``),a=i?np(i)?i:tp(`${e}/${i}`):tp(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return ep(n)},[g,h]),Fr=Q.useCallback(async e=>{let t=tp(e.trim());if(!t||Ye.current.has(t)||Xe.current.has(t))return;Xe.current=new Set(Xe.current),Xe.current.add(t);let n=$e.current+1;$e.current=n,Qe.current=new Map(Qe.current),Qe.current.set(t,n);let r=()=>Qe.current.get(t)===n;await(i.listDirectory?i.listDirectory(t).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):Le.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!r())return;let n=Pr(t,e);Ye.current=new Set(Ye.current),Ye.current.add(t),Je(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ke(e=>({...e,[t]:n}))}).catch(e=>{if(!r())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&y&&t!==y){Ee(y,t),Je(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Je(e=>({...e,[t]:n}))}).finally(()=>{r()&&(Qe.current=new Map(Qe.current),Qe.current.delete(t),Xe.current=new Set(Xe.current),Xe.current.delete(t))})},[i,Pr,Ee,y]),Ir=Q.useCallback(async()=>{y&&(Ye.current=new Set,Xe.current=new Set,Qe.current=new Map,Je({}),Ke(e=>Object.keys(e).length===0?e:{}),await Fr(y))},[Fr,y]),Rr=Q.useCallback(async e=>{if(!e){await Ir();return}let t=tp(e);Ye.current=new Set(Ye.current),Ye.current.delete(t),Xe.current=new Set(Xe.current),Xe.current.delete(t),await Fr(t)},[Fr,Ir]),zr=Q.useRef(``),Br=Q.useRef(``);Q.useEffect(()=>{if(!y)return;let e=`${y}|h${h?`1`:`0`}|g${g?`1`:`0`}`,t=zr.current!==y,n=Br.current!==e;!t&&!n||(t&&(zr.current=y,ot(``),_t(null),bt(``),Et(null),j(!1)),n&&(Br.current=e,Ze.current=!1,Ye.current=new Set,Xe.current=new Set,Qe.current=new Map,Je({}),Ke(e=>Object.keys(e).length===0?e:{}),Fr(y)))},[Fr,y,g,h]),Q.useEffect(()=>{if(!i.listDirectory)return;let e=()=>{if(!document.hidden&&Se.length>0)for(let e of Se)Rr(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Se,i.listDirectory,Rr]),Q.useEffect(()=>{if(!y||Se.length===0)return;let e=Se.map(e=>tp(e)).filter(e=>!!e&&e!==y&&e.startsWith(`${y}/`)&&!Ye.current.has(e)&&!Xe.current.has(e)).sort((e,t)=>e.split(`/`).length-t.split(`/`).length);if(e.length===0)return;let t=!1;return(async()=>{for(let n=0;n<e.length&&!t;n+=3){let t=e.slice(n,n+3);await Promise.all(t.map(e=>Fr(e)))}})(),()=>{t=!0}},[Se,Fr,y]);let Vr=Q.useCallback(async e=>{if(e?.preventDefault(),!hn||!pn)return;bn(!0);let t=()=>{mn(null)},n=e=>{X.error(e)},a=()=>{bn(!1)};if(pn===`createFile`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!i.writeFile){n(r(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=hn.path,o=tp(`${e?`${e}/`:``}${_n.trim()}`);await i.writeFile(o,``).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.fileCreated`)),await Rr(e)),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`createFolder`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=hn.path,o=tp(`${e?`${e}/`:``}${_n.trim()}`);await i.createDirectory(o).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.folderCreated`)),await Rr(e)),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`rename`){if(!_n.trim()){n(r(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!i.rename){n(r(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=hn.path,o=e.split(`/`).slice(0,-1).join(`/`),s=tp(`${o?`${o}/`:``}${_n.trim()}`);await i.rename(e,s).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.renamedSuccessfully`)),await Rr(o),y&&Te(y,e),(K?.path===e||K?.path.startsWith(`${e}/`))&&(y&&De(y,null),ot(``),_t(null),bt(``),Et(null),d&&j(!1))),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(pn===`delete`){if(!i.delete){n(r(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=hn.path,o=e.split(`/`).slice(0,-1).join(`/`);await i.delete(e).then(async n=>{n.success&&(X.success(r(`sidebarFilesTree.toast.deletedSuccessfully`)),await Rr(o),y&&Te(y,e),(K?.path===e||K?.path.startsWith(`${e}/`))&&(y&&De(y,null),ot(``),_t(null),bt(``),Et(null),d&&j(!1))),t()}).catch(()=>n(r(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[pn,hn,_n,i,Rr,d,Te,y,K?.path,De,r]);Q.useEffect(()=>{if(!v){tt([]),rt(!1);return}let e=O.trim();if(!e){tt([]),rt(!1);return}let t=!1;return rt(!0),C(v,e,150,{includeHidden:h,respectGitignore:!g,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>g||!dp(e.path)).map(e=>({name:e.name,path:tp(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));tt(n)}).catch(()=>{t||tt([])}).finally(()=>{t||rt(!1)}),()=>{t=!0}},[v,O,C,h,g]);let Hr=Q.useCallback(async(e,t)=>{if(i.readFile)return(await i.readFile(e,{...t??{},directory:y||void 0})).content??``;let n=new URLSearchParams({path:e});t?.allowOutsideWorkspace&&n.set(`allowOutsideWorkspace`,`true`),t?.outsideFileGrant&&n.set(`outsideFileGrant`,t.outsideFileGrant),t?.optional&&n.set(`optional`,`true`),y&&n.set(`directory`,y);let a=await _(`/api/fs/read?${n.toString()}`,{cache:t?.optional?`no-store`:`default`});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||r(`filesView.error.readFileFailed`))}return a.text()},[i,y,r]),Ur=Q.useCallback(async(e,t)=>{if(i.statFile){let n=await i.statFile(e,{...t??{},directory:y||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[i,y]);Q.useEffect(()=>{if(!y||!i.statFile||be.length===0)return;let e=!1,t=be.filter(e=>e!==Pe||Xo(e)&&!e.toLowerCase().endsWith(`.svg`)||Qo(e));return Promise.all(t.map(async t=>{try{let n=await i.statFile?.(t,{directory:y||void 0});!e&&n&&!n.isFile&&Te(y,t)}catch(n){!e&&pp(n)&&Te(y,t)}})),()=>{e=!0}},[i,be,Te,y,Pe]);let Wr=Q.useMemo(()=>it.length>mp?`${it.slice(0,mp)}\n\n… truncated …`:it,[it]),Gr=kt!==Wr,Kr=Q.useCallback(async()=>{if(!K||!i.writeFile)return X.error(r(`filesView.toast.savingNotSupported`)),!1;if(!Gr)return!0;if(kt===``&&it!==``&&St!==K.path)return console.warn(`[saveDraft] refusing to save empty draft for "${K.path}" (${it.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;Nt(!0);try{let e=vp(kt,Pt);return(await i.writeFile(K.path,e))?.success?(ot(kt),K?.path&&$o(K.path)&&(zt.current=kt,Bt.current=kt),Ur(K.path).then(e=>{e&&(Ut.current=e)}).catch(()=>{}),!0):(X.error(r(`filesView.toast.writeFileFailed`)),!1)}catch(e){return X.error(e instanceof Error?e.message:r(`filesView.toast.saveFailed`)),!1}finally{Nt(!1)}},[kt,it,i,Gr,Pt,St,Ur,K,r]);Q.useEffect(()=>{if(!Gr){rr(null);return}let e=(e,t)=>rn.current?(rn.current=!1,!0):($t(!0),tn.current=t??e,!1);return rr(e),()=>{q.getState().mainTabGuard===e&&rr(null)}},[Gr,rr]),Q.useEffect(()=>{try{window.localStorage.setItem(hp,Xt?`true`:`false`)}catch{}},[Xt]),Q.useEffect(()=>{Xt||(qt(`idle`),Lt.current&&=(clearTimeout(Lt.current),null))},[Xt]);let qr=1500;Q.useEffect(()=>{let e=!!(K&&i.writeFile);if(!(!Xt||!Gr||!e||Mt))return Lt.current=setTimeout(()=>{Kr().then(e=>{e&&(qt(`saved`),setTimeout(()=>qt(`idle`),2e3))})},qr),()=>{Lt.current&&=(clearTimeout(Lt.current),null)}},[Xt,kt,Gr,K,i.writeFile,Mt,Kr]),Q.useEffect(()=>{qt(`idle`)},[K?.path]),Q.useEffect(()=>{let e=e=>{Ct(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Lt.current&&=(clearTimeout(Lt.current),null),Mt||Kr().then(e=>{e&&(qt(`saved`),setTimeout(()=>qt(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),z(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Mt,Kr]);let Jr=vt(e=>{q.setState(t=>{let n=tp(t.pendingFileFocusPath??``)===e,r=tp(t.pendingFileNavigation?.path??``)===e;return!n&&!r?t:{...n?{pendingFileFocusPath:null,pendingFileViewerMode:null}:{},...r?{pendingFileNavigation:null}:{}}})}),Yr=vt(async t=>{let n=Wt.current+1;Wt.current=n;let i=()=>{if(!y)return!1;let e=bo.getState().byRoot[y],r=Me??e?.selectedPath??e?.openPaths[0]??null;return Wt.current===n&&r===t.path};_t(null),Ot(null),bt(``),Et(null);let o=Xo(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Qo(t.path);if(d&&j(!0),a.isDesktop&&o&&!s){ot(``),At(``),pt(!0);return}if(!a.isDesktop&&o&&!s){ot(``),At(``),Et(t.path),pt(!1);return}if(c){ot(``),At(``),Et(t.path),pt(!1);return}pt(!0);let l=li(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!y&&!ip(t.path,y),outsideFileGrant:l};Gt.current=t.path,await Hr(t.path,u).then(e=>{if(!i())return;let n=_p(e);Ft(gp(e)),ot(n),zt.current=n,Bt.current=n,At(n.length>mp?`${n.slice(0,mp)}\n\n… truncated …`:n),Et(t.path),Ur(t.path,u).then(e=>{e&&i()&&(Ut.current=e)}).catch(()=>{})}).catch(n=>{if(!i())return;Jr(t.path),Gt.current=null,pt(!1),Ot(t.path),ot(``),At(``),Ut.current=null;let a=n instanceof Error?n.message:r(`filesView.error.readFileFailed`);if(_t(a),e===`editor-only`){y&&fp(n)?we(y,t.path):y&&pp(n)&&Te(y,t.path);return}if(fp(n)){if(y&&we(y,t.path),_t(null),E.trim().length>0&&D(``),d&&j(!1),y){let e=[...ap(t.path,y),t.path];e.length>0&&ke(y,e);for(let t of e)Ye.current.has(t)||Fr(t)}return}if(pp(n)){y&&Te(y,t.path),_t(null),d&&j(!1);return}}).finally(()=>{i()&&(Gt.current=null,pt(!1))})}),Xr=Q.useCallback(async(e,t)=>{if(!y)return;let n=ap(e,y),r=t?[...n,e]:n;r.length>0&&ke(y,r);let i=r.map(e=>{if(!Ye.current.has(e))return Fr(e)}).filter(Boolean);await Promise.all(i)},[ke,Fr,y]),Zr=Q.useCallback((e,t)=>{let n=t.findIndex(t=>t.path===e);return n===-1||t.length<=1?null:t[n+1]??t[n-1]??null},[]),Qr=Q.useCallback(async e=>{if(rn.current)rn.current=!1;else if(Gr){$t(!0),en.current=e;return}y&&(De(y,e.path),Ce(y,e.path),Xr(e.path,!1)),_t(null),bt(``),ot(``),zt.current=``,Bt.current=``,At(``),Et(null),Ot(null),d&&j(!0)},[Ce,Xr,Gr,d,y,De]);Q.useEffect(()=>{K?.path&&Xr(K.path,!1)},[Xr,K?.path]),Q.useEffect(()=>{if(!K){Wt.current+=1,pt(!1);return}St!==K.path&&Dt!==K.path&&Gt.current!==K.path&&Yr(K)},[i,e,y,a.isDesktop,d,Yr,St,Dt,K]),Q.useEffect(()=>()=>{Wt.current+=1,Gt.current=null},[y,Pe]);let $r=Q.useRef(Gr);$r.current=Gr,Q.useEffect(()=>{let e=K?.path??``;if(!wp(t,e,St))return;let n=!1,r=window.setInterval(()=>{document.hidden||Ur(e,ze).then(t=>{if(n||!t)return;let r=Ut.current;if(!r||r.path!==e){Ut.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||$r.current||(Ut.current=t,Et(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,St,Ur,K?.path,ze]);let ei=Q.useCallback(()=>{let e=en.current,t=tn.current,n=nn.current;if(en.current=null,tn.current=null,nn.current=null,rn.current=!0,$t(!1),At(Wr),n){y&&we(y,n),K?.path===n&&(e?Qr(e):(y&&De(y,null),ot(``),_t(null),bt(``),Et(null),d&&j(!1)));return}if(e){Qr(e);return}t&&(rr(null),typeof t==`function`?(rn.current=!1,t()):q.getState().setActiveMainTab(t))},[Wr,Qr,d,we,y,K?.path,rr,De]),ti=Q.useCallback(async()=>{let e=en.current,t=tn.current,n=nn.current;if(!await Kr()){rn.current=!1;return}if(en.current=null,tn.current=null,nn.current=null,rn.current=!0,$t(!1),n){y&&we(y,n),K?.path===n&&(e?await Qr(e):(y&&De(y,null),ot(``),_t(null),bt(``),Et(null),d&&j(!1)));return}if(e){await Qr(e);return}t&&(rr(null),typeof t==`function`?(rn.current=!1,t()):q.getState().setActiveMainTab(t))},[Qr,d,we,y,Kr,K?.path,rr,De]),ni=vt(()=>{if(Mt)return;let e=en.current;e&&Jr(e.path),en.current=null,tn.current=null,nn.current=null,rn.current=!1,$t(!1)}),ri=vt(()=>{!K||ft||(Ot(null),_t(null),Et(null),pt(!0))}),ii=Q.useCallback(e=>{let t=K?.path===e,n=Zr(e,je);if(t&&Gr){$t(!0),en.current=n,nn.current=e;return}if(y&&we(y,e),t){if(n){Qr(n);return}y&&De(y,null),ot(``),_t(null),bt(``),Et(null),d&&j(!1)}},[Zr,Qr,Gr,d,je,we,y,K?.path,De]),ai=Q.useCallback(e=>{if(be.includes(e))return`open`;if(w?.files){let t=e.startsWith(y+`/`)?e.slice(y.length+1):e,n=w.files.find(e=>e.path===t);if(n){if(n.index===`A`||n.working_dir===`?`)return`git-added`;if(n.index===`D`)return`git-deleted`;if(n.index===`M`||n.working_dir===`M`)return`git-modified`}}return null},[be,w,y]),oi=Q.useCallback(e=>{if(!w?.files)return null;let t=e.startsWith(y+`/`)?e.slice(y.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of w.files)e.path.startsWith(n)&&((e.index===`M`||e.working_dir===`M`)&&r++,(e.index===`A`||e.working_dir===`?`)&&i++);return r+i>0?{modified:r,added:i}:null},[w,y]),si=Q.useCallback(async e=>{let t=tp(e);y&&(Oe(y,t),Ye.current.has(t)||await Fr(t))},[Fr,y,Oe]),ci=Q.useMemo(()=>y?yf(y,Ge):[],[Ge,y]),ui=Q.useMemo(()=>new Set(Se.map(e=>tp(e))),[Se]),fi=bf(Se),pi=Q.useCallback(()=>{if(y){if(fi){Ze.current=!1,Ee(y,y);return}Ze.current=!0,ke(y,ci)}},[fi,ci,ke,Ee,y]);Q.useEffect(()=>{if(!y||!Ze.current)return;let e=xf(ci,Se);if(e.length>0){ke(y,e);return}let t=new Set([...Ye.current,...Object.keys(qe)]);Sf(ci,Se,t)&&(Ze.current=!1)},[ci,ke,Se,qe,y]);let mi=Q.useMemo(()=>({canRename:Bn,canCreateFile:Rn,canCreateFolder:zn,canDelete:Vn,canReveal:Hn}),[Bn,Rn,zn,Vn,Hn]);function hi(e,t){let n=Ge[e]??[];return n.map((e,a)=>{let o=e.type===`directory`,s=o&&ui.has(tp(e.path)),c=K?.path===e.path,l=a===n.length-1;return(0,$.jsxs)(`li`,{className:`relative`,children:[t>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`absolute top-3.5 left-[-12px] w-3 h-px bg-border/40`}),l&&(0,$.jsx)(`span`,{className:`absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background`})]}),(0,$.jsx)(Sp,{node:e,root:y,isExpanded:s,isActive:c,isMobile:d,alwaysShowActions:m,status:o?void 0:ai(e.path),badge:o?oi(e.path):void 0,permissions:mi,downloadFile:i.downloadFile,contextMenuPath:Sn,setContextMenuPath:Cn,rightClickMenuPath:wn,setRightClickMenuPath:Tn,onSelect:Qr,onToggle:si,onRevealPath:qn,onOpenDialog:Yn}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[qe[e.path]?(0,$.jsxs)(`li`,{className:`flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--status-error)]`,title:qe[e.path],children:qe[e.path]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void Rr(e.path),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`}),r(`filesView.tree.actions.refreshTitle`)]})]}):null,hi(e.path,t+1)]})]},e.path)})}let gi=!!(K?.path&&Xo(K.path)),_i=!!(K?.path&&K.path.toLowerCase().endsWith(`.svg`)),vi=!!(K?.path&&Qo(K.path)),yi=Q.useMemo(()=>tp(ir?.path??``),[ir?.path]),bi=!!(ir&&yi&&Pe&&Pe===yi&&!ft&&!ht&&!gi&&!vi),xi=Q.useMemo(()=>op(y,Pe),[Pe,y]),Si=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(Nn(e=>e===t?e:t),!t){Fn(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Fn({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),Ci=Q.useCallback(()=>{let e=sn.current,t=e?.state.selection.main;if(!e||!t||t.empty||!K)return;let n=e.state.sliceDoc(t.from,t.to),r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(Math.max(t.from,t.to-1)).number,a=r===i?`${r}`:`${r}-${i}`,o=`${K.name}:${a}`;In(K.path,o,n),Ln(P(o),`append-inline`),Fn(null),q.getState().setActiveMainTab(`chat`)},[In,K,Ln]),wi=Q.useCallback(e=>{if(!K)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=kt.split(`
16
16
  `).slice(t-1,n).join(`
17
- `);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${K.name}:${i}`;In(K.path,a,r),Ln(P(a),`append-inline`),q.getState().setActiveMainTab(`chat`)},[In,kt,K,Ln]),wi=!!(K&&(!mi||hi)&&!_i&&it.length>0),Ti=!!(K&&bi.length>0),Ei=!!(K&&!Ie&&!mi&&!_i&&i.writeFile&&it.length<=fp),Di=!!(K?.path&&yp(K.path)),Oi=!!(K?.path&&qo(K.path)),ki=!!(K?.path&&Zo(K.path)),Ai=!!(K&&!mi&&!_i),ji=Ai&&!Di&&!ki&&!(Oi&&ce===`preview`),Mi=Di&&oe===`edit`||Oi&&ce===`edit`||!Di&&!Oi&&ae===`edit`,Ni=Q.useMemo(()=>Pe?hs(Pe):null,[Pe]),[Pi,Fi]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=K?.path;if(!t||Ni){Fi(null);return}return Fi(null),us(t).then(t=>{e||Fi(t)}),()=>{e=!0}},[K?.path,Ni]),Q.useEffect(()=>{!Ei&&ae===`edit`&&W(`view`)},[Ei,ae]);let Ii=`yuri:files:md-viewer-mode`,Li=`yuri:files:html-viewer-mode`;Q.useEffect(()=>{let e=K?.path;if(!e)return;W(pe.current[e]??`edit`);let t=yr?`preview`:`edit`;try{let e=localStorage.getItem(Ii);(e===`preview`||e===`edit`)&&(t=e)}catch{}se(me.current[e]??t);let n=yr?`preview`:`edit`;try{let e=localStorage.getItem(Li);(e===`preview`||e===`edit`)&&(n=e)}catch{}hr&&qo(e)&&sr===e&&(he.current[e]=hr,gr(null)),G(he.current[e]??n),ue(ge.current[e]??(yr?`preview`:`edit`))},[sr,hr,K?.path,gr,yr]);let Ri=Q.useCallback(e=>{let t=K?.path;t&&(pe.current[t]=e),W(e)},[K?.path]),zi=Q.useCallback(e=>{let t=K?.path;t&&(me.current[t]=e),se(e);try{localStorage.setItem(Ii,e)}catch{}},[K?.path]),Vi=Q.useCallback(()=>oe,[oe]),Hi=Q.useCallback(e=>{let t=K?.path;t&&(he.current[t]=e),G(e);try{localStorage.setItem(Li,e)}catch{}},[K?.path]),Ui=Q.useCallback(e=>{let t=K?.path;if(t&&(ge.current[t]=e),Rt.current&&=(clearTimeout(Rt.current),null),Vt.current!==null&&(cancelAnimationFrame(Vt.current),Vt.current=null),e===`edit`)jt(zt.current||it),ue(e);else{zt.current=kt;let e=t;ue(`edit`),Vt.current=requestAnimationFrame(()=>{Vt.current=requestAnimationFrame(()=>{Vt.current=null,!(y&&e&&vo.getState().byRoot[y]?.selectedPath!==e)&&(fe(e=>e+1),ue(`preview`))})});return}},[kt,it,y,K?.path]),Wi=Q.useCallback(async(e,t)=>{if(!i.writeFile||t===Bt.current)return!1;if(!(await i.writeFile(e,t))?.success)return X.error(r(`filesView.toast.writeFileFailed`)),!1;zt.current=t,Bt.current=t,jt(t);let n=await Hr(e,ze).catch(()=>null);return n&&(Ut.current=n),!0},[i,Hr,ze,r]);Q.useEffect(()=>()=>{Rt.current&&=(clearTimeout(Rt.current),null),Vt.current!==null&&(cancelAnimationFrame(Vt.current),Vt.current=null)},[le,K?.path]);let Gi=Q.useCallback(e=>{if(zt.current=e,!K?.path||le!==`preview`||!i.writeFile)return;Rt.current&&clearTimeout(Rt.current);let t=K.path;Rt.current=setTimeout(()=>{Rt.current=null,Wi(t,e).then(e=>{e&&(Yt(!0),setTimeout(()=>Yt(!1),1500))}).catch(e=>{X.error(e instanceof Error?e.message:r(`filesView.toast.saveFailed`))})},Kr)},[le,i.writeFile,Wi,K?.path,r]),qi=Q.useMemo(()=>ki&&(zt.current||kt)||it,[kt,it,ki]),Ji=Q.useCallback(()=>ce,[ce]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of be)pe.current[e]=`edit`,yp(e)&&(me.current[e]=t),qo(e)&&(he.current[e]=t),Zo(e)&&(ge.current[e]=t);W(`edit`),se(t),G(t),ue(t);try{localStorage.setItem(Ii,t),localStorage.setItem(Li,t)}catch{}},t=t=>{let n=!!t.detail?.enabled;e(n)};return window.addEventListener(`yuri:file-viewer-preview-mode-changed`,t),()=>{window.removeEventListener(`yuri:file-viewer-preview-mode-changed`,t)}},[be]),Q.useEffect(()=>{if(!ir||!y)return;let e=()=>{typeof window>`u`||dn.current===null&&(dn.current=window.requestAnimationFrame(()=>{dn.current=null,un(e=>e+1)}))},t=(e,t)=>{if(e.state.doc.length!==t.length)return!1;if(t.length===0)return!0;let n=Math.min(128,t.length);if(e.state.sliceDoc(0,n)!==t.slice(0,n))return!1;let r=Math.max(0,t.length-n);return e.state.sliceDoc(r,t.length)===t.slice(r)},n=$f(ir.path);if(Dt===n){qr(n),fn.current={key:``,attempts:0};return}if(!n){ar(null),fn.current={key:``,attempts:0};return}let r=`${n}:${ir.line}:${ir.column??1}`;if(fn.current.key!==r&&(fn.current={key:r,attempts:0}),K?.path!==n){if(Qt)return;Zr(Ae(n));return}if(ft||Tt!==n)return;if(gt||mi||_i){ar(null),fn.current={key:``,attempts:0};return}if(!Ei)return;if(ae!==`edit`){W(`edit`);return}let i=sn.current;if(!i){e();return}if(!t(i,kt)){e();return}let a=Math.max(1,Math.min(ir.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,ir.column||1),c=Math.max(0,o.to-o.from),l=Math.min(c,s-1),u=o.from+l;if(i.state.selection.main.head!==u||fn.current.attempts===0){fn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:pt.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=sn.current;e&&(e.dispatch({selection:{anchor:u},effects:pt.scrollIntoView(u,{y:`center`})}),e.focus())}),ar(null),fn.current={key:``,attempts:0}},[Ei,qr,Qt,kt,ln,gt,Dt,ft,mi,_i,Tt,Zr,ir,y,K?.path,ar,ae,Ae]),Q.useEffect(()=>{if(!sr||!y)return;let e=$f(sr);if(Dt===e){qr(e);return}if(!e){mr(null);return}if(K?.path!==e){if(Qt)return;Zr(Ae(e));return}if(!(ft||Tt!==e||gt||mi||_i)){if(Ei&&ae===`edit`){let e=sn.current;if(!e)return;e.focus()}mr(null)}},[Ei,qr,Qt,gt,Dt,ft,Zr,mi,_i,Tt,sr,y,K?.path,mr,ae,Ae]);let Yi=Q.useCallback(e=>{if(!d||!e||!e.hasFocus||typeof window>`u`)return;let t=window.visualViewport;if(!t)return;let n=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,n-(t.offsetTop+t.height))<=0)return;let r=e.state.selection.main.head,i=e.coordsAtPos(r);if(!i)return;let a=Math.round(t.offsetTop+t.height),o=i.bottom+20-a;o<=0||(e.scrollDOM.scrollTop+=o)},[d]);Q.useEffect(()=>{if(!d||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{Yi(sn.current)})},t=window.visualViewport;return t?.addEventListener(`resize`,e),t?.addEventListener(`scroll`,e,{passive:!0}),document.addEventListener(`selectionchange`,e),()=>{t?.removeEventListener(`resize`,e),t?.removeEventListener(`scroll`,e),document.removeEventListener(`selectionchange`,e)}},[d,Yi]),Q.useEffect(()=>{if(ae!==`edit`||d)return;let e=Ma(`open_go_to_line`,_r),t=t=>{let n=t.target;if(n?.closest(`[role="dialog"]`))return;let r=!!n?.closest(`.cm-editor`);if(!(n?.closest(`input, textarea, [contenteditable="true"], [role="textbox"]`)&&!r||!document.activeElement?.closest(`.cm-editor`))){if(Aa(t,e)){t.preventDefault(),jn(!0);return}if(Aa(t,`mod+l`)){let e=sn.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),Si())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[Si,d,_r,ae]);let Xi=q(e=>e.editorFontSize),Zi=Q.useMemo(()=>{if(!K?.path)return[Ns(s,{fontSize:Xi})];let e=Yo(K.path),t=[Ns(s,e?{syntaxColors:!1,fontSize:Xi}:{fontSize:Xi})],n=Ni??Pi;return n&&t.push(n),e&&t.push(cs({language:e,themeName:s.metadata.id,theme:Oo(s)})),M&&t.push(pt.lineWrapping),t.push(pt.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&xi(e.view)})),d&&t.push(pt.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{Yi(e.view)})})),t},[s,K?.path,Ni,Pi,M,d,Yi,Xi,xi]),Qi=Q.useMemo(()=>({light:_e.metadata.id,dark:ve.metadata.id}),[_e.metadata.id,ve.metadata.id]),$i=K?.path&&mi&&!a.isDesktop&&!hi?`${K.path}|${ze.allowOutsideWorkspace?`outside`:`workspace`}|${ze.outsideFileGrant??``}`:``,ea=K?.path&&_i?`${K.path}|${ze.allowOutsideWorkspace?`outside`:`workspace`}|${ze.outsideFileGrant??``}`:``,ta=a.isVSCode||o(),na=K?.path&&Oi&&ce===`preview`&&!ta?K.path:``,ra=r(`filesView.error.readFileFailed`),{readyKey:ia,nonce:aa}=Cp($i,vt,ra),{readyKey:oa,nonce:ua}=Cp(na,vt,ra),{readyKey:fa,nonce:ma}=Cp(ea,vt,ra),ha=!!($i&&ia!==$i),ga=!!(na&&oa!==na),_a=!!(ea&&fa!==ea),va=K?.path&&mi?a.isDesktop?hi?`data:${Ko(K.path)};utf8,${encodeURIComponent(it)}`:yt:hi?`data:${Ko(K.path)};utf8,${encodeURIComponent(it)}`:ia===$i?st(`/api/fs/raw`,{path:K.path,allowOutsideWorkspace:ze.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:ze.outsideFileGrant,directory:y||void 0}).url:``:``,ya=_t(e=>{if(!K?.path||!mi)return;let t=hi?va:K.path||va;if(!t)return;let n=K.name||K.path;te({open:!0,title:n,content:``,previewSource:e.currentTarget.querySelector(`img`)??void 0,metadata:{tool:`image-preview`,filename:n,mime:Ko(K.path)},image:{url:t,mimeType:Ko(K.path),filename:n}})}),ba=Q.useCallback(e=>{te(t=>t.open===e?t:{...t,open:e})},[]),xa=Q.useCallback((e,t)=>{let n=e.name||r(`filesView.editor.imageAltFallback`);return(0,$.jsx)(`div`,{className:J(`flex items-center justify-center`,t?.fullHeight?`h-full p-4`:`h-full p-3`),children:(0,$.jsx)(`button`,{type:`button`,className:`max-h-full max-w-full cursor-zoom-in rounded-md border-0 bg-transparent p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:ya,"aria-label":n,disabled:!va,children:(0,$.jsx)(ts,{src:va,alt:n,className:J(`object-contain rounded-md border border-border/30 bg-primary/10`,t?.fullHeight?`max-h-full max-w-full`:`max-h-[70vh] max-w-full`),draggable:!1},aa)})})},[aa,va,ya,r]),Sa=K?.path&&_i&&fa===ea?st(`/api/fs/raw`,{path:K.path,allowOutsideWorkspace:ze.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:ze.outsideFileGrant,directory:y||void 0}).url:``,Ca=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:Sa,className:`h-full w-full border-0`,title:e.name},ma)}),[Sa,ma]);Q.useEffect(()=>{let e=!1,t=async()=>{if(!a.isDesktop||!K?.path||!mi||hi){xt.current&&=(URL.revokeObjectURL(xt.current),``),bt(``);return}vt(null),xt.current&&=(URL.revokeObjectURL(xt.current),``),await(async()=>{let t=await ct({path:K.path,...ze,directory:y||void 0,signal:n.signal});if(!t.ok)throw Error(r(`filesView.error.readFileFailed`));let i=await t.blob(),a=URL.createObjectURL(i);return e?(URL.revokeObjectURL(a),``):(xt.current=a,a)})().then(t=>{e||(bt(t),Et(K.path))}).catch(t=>{xt.current&&=(URL.revokeObjectURL(xt.current),``),e||(bt(``),vt(t instanceof Error?t.message:r(`filesView.error.readFileFailed`)),Et(null))}).finally(()=>{e||mt(!1)})},n=new AbortController;return t(),()=>{e=!0,n.abort()}},[i,mi,hi,y,a.isDesktop,K?.path,ze,r]),Q.useEffect(()=>()=>{xt.current&&=(URL.revokeObjectURL(xt.current),``)},[]);let wa=Q.useCallback(()=>mn(null),[]),Ta=Q.useMemo(()=>wc({drafts:Cr,editingDraftId:Er,commentText:wr,onTextChange:Tr,selection:Xn,isDragging:tr,fileLabel:K?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Nr,onCancel:()=>{Qn(null),kr()},onEdit:e=>{jr(e),Qn({start:e.startLine,end:e.endLine})},onDelete:Mr,onAddToChat:Ci}),[Ci,kr,wr,Mr,Er,Cr,Nr,tr,Xn,K?.path,Tr,jr]),Ea=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(ht,{file:{name:e.name,contents:t,lang:Yo(e.path)||void 0},options:{disableFileHeader:!0,overflow:M?`wrap`:`scroll`,theme:Qi,themeType:s.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[s.metadata.variant,Qi,M]),Oa=({exitFullscreenOnly:t=!1,layout:n=`floating`}={})=>{if(!K)return null;let a=n===`docked`?`pointer-events-auto flex flex-wrap items-center gap-1`:`pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm`,o=(e,t)=>(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[Ei&&Mi&&(0,$.jsxs)($.Fragment,{children:[Mt?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-muted-foreground typography-meta`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-3.5 animate-spin`}),r(`filesView.editor.saving`)]}):Xt&&Kt===`saved`&&!Wr?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta`,children:[(0,$.jsx)(Z,{name:`check`,className:`size-3.5`}),r(`filesView.editor.saved`)]}):Wr?o(r(Xt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${At()}+S`}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>void Gr(),className:`h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,title:r(Xt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${At()}+S`}),"aria-label":r(`filesView.editor.saveAria`,{shortcut:`${At()}+S`}),children:(0,$.jsx)(Z,{name:`save-3`,className:`size-4`})})):null,o(r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Zt(e=>!e),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Xt?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Xt?(0,$.jsx)(Z,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(Z,{name:`file-check`,className:`size-4`})}))]}),Ai&&Mn?o(`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ra(`mod+l`)})`,(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:Si,className:`h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,title:`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ra(`mod+l`)})`,"aria-label":`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ra(`mod+l`)})`,children:[(0,$.jsx)(Z,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{children:r(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(gi,{shortcut:Ra(`mod+l`)})]})):null,(0,$.jsxs)(Ua,{onOpenChange:U,children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.openInDesktopApp`),"aria-label":r(`filesView.editor.openInDesktopApp`),children:(0,$.jsx)(Z,{name:`file-transfer`,className:`size-4`})})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(Pa,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Un.map(e=>(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>void Jn(e),children:[(0,$.jsx)(Zf,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),Wn?(0,$.jsxs)(Da,{className:`flex items-center gap-2`,onClick:()=>void Kn(!0),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:r(`filesView.editor.refreshApps`)})]}):null]})]}),!mi&&!_i&&(0,$.jsxs)($.Fragment,{children:[o(r(M?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>F(!M),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,M?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(M?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(Z,{name:`text-wrap`,className:`size-4`})})),ae===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(r(`filesView.editor.findInFile`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:e=>{z(!R),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.findInFile`),children:(0,$.jsx)(Z,{name:`search`,className:`size-4`})})),o(r(`filesView.editor.goToLine`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:e=>{jn(e=>!e),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.goToLine`),children:(0,$.jsx)(Z,{name:`menu-fold-2`,className:`size-4`})})),(0,$.jsx)(Jf,{open:An,onOpenChange:jn,view:sn.current,variant:`inline`})]})]}),ji&&Ei&&!Oi&&(0,$.jsx)(ms,{currentMode:ae===`view`?`preview`:`edit`,onToggle:()=>{Ri(ae===`view`?`edit`:`view`)}}),Di&&o(r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>zi(Vi()===`preview`?`edit`:`preview`),className:J(`size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]`,Vi()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Z,{name:Vi()===`preview`?`eye`:`eye-off`,className:`size-4`})})),qo(K?.path??``)&&(0,$.jsx)(ms,{currentMode:Ji(),onToggle:()=>{Hi(Ji()===`preview`?`edit`:`preview`)}}),Di&&Vi()===`preview`&&br&&(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,"aria-label":r(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{lt?dt():it.trim()&&ut(it)},children:lt?(0,$.jsx)(Z,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(la,{sideOffset:8,children:r(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),ki&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ms,{currentMode:le,onToggle:()=>Ui(le===`preview`?`edit`:`preview`)}),le===`preview`&&(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=Ht.current?.getXml();if(Rt.current&&=(clearTimeout(Rt.current),null),K?.path&&e){if(!await Wi(K.path,e))return;Yt(!0),setTimeout(()=>Yt(!1),1500)}},className:`size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.diagram.saveDiagram`),children:Jt?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`save-3`,className:`size-4`})})]}),wi&&o(r(`filesView.editor.copyFileContents`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{(await Ct(it)).ok?(Dn(!0),an.current!==null&&window.clearTimeout(an.current),an.current=window.setTimeout(()=>{Dn(!1)},1200)):X.error(r(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.copyFileContents`),"aria-label":r(`filesView.editor.copyFileContents`),children:En?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`clipboard`,className:`size-4`})})),Ti&&o(r(`filesView.editor.copyFilePathTitle`,{path:bi}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{(await Ct(bi)).ok?(kn(!0),on.current!==null&&window.clearTimeout(on.current),on.current=window.setTimeout(()=>{kn(!1)},1200)):X.error(r(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.copyFilePathTitle`,{path:bi}),"aria-label":r(`filesView.editor.copyFilePathTitle`,{path:bi}),children:On?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`file-copy-2`,className:`size-4`})})),i.downloadFile&&o(r(`filesView.editor.saveFile`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>{let e=i.downloadFile;e&&e(K.path).catch(e=>{console.error(`Download failed:`,e),X.error(r(`sidebarFilesTree.toast.operationFailed`))})},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.saveFile`),"aria-label":r(`filesView.editor.saveFile`),children:(0,$.jsx)(Z,{name:`download`,className:`size-4`})})),t?o(r(`filesView.editor.exitFullscreen`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.exitFullscreen`),"aria-label":r(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`size-4`})})):!d&&e===`full`&&o(r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!I),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:I?(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(Z,{name:`fullscreen`,className:`size-4`})}))]})},ka=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(pr,{open:Qt,onOpenChange:e=>{e||ti()},children:(0,$.jsxs)(ur,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(cr,{children:[(0,$.jsx)(dr,{children:r(`filesView.unsaved.title`)}),(0,$.jsx)(fr,{children:r(`filesView.unsaved.description`)})]}),(0,$.jsxs)(lr,{children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ti,disabled:Mt,children:r(`filesView.dialog.cancel`)}),(0,$.jsx)(Y,{variant:`outline`,onClick:()=>void ei(),disabled:Mt,className:`border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,children:r(`filesView.unsaved.saveChanges`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:$r,disabled:Mt,children:r(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:J(`flex flex-col flex-shrink-0`,b&&`border-b border-border/40`),children:[b?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[d&&A&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>j(!1),"aria-label":r(`filesView.editor.back`),className:`inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:(0,$.jsx)(Z,{name:`arrow-left-s`,className:`size-5`})}),d?K?(0,$.jsxs)(Ua,{children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium`,"aria-label":r(`filesView.editor.openFilesAria`),children:[(0,$.jsx)(Bi,{filePath:K.path,extension:K.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(sp,{name:K.name}),(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Pa,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:je.map(e=>{let t=K?.path===e.path;return(0,$.jsxs)(Da,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Zr(e)},className:J(`flex min-w-0 items-center justify-between gap-2 overflow-hidden`,t&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.jsx)(Bi,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(sp,{name:e.name})]}),(0,$.jsx)(`button`,{type:`button`,"data-close-open-file":!0,onPointerDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.preventDefault(),t.stopPropagation(),ii(e.path)},className:`inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,"aria-label":r(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Z,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:r(`filesView.editor.selectFile`)}):je.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[Ve.left&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent`}),Ve.right&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent`}),(0,$.jsx)(`div`,{ref:Be,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:je.map(e=>{let t=K?.path===e.path;return(0,$.jsxs)(`div`,{title:ip(y,e.path),className:J(`group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap`,t?`bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]`:`bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]`),children:[(0,$.jsx)(Bi,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Zr(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),ii(e.path)},className:J(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!m&&`opacity-0 group-hover:opacity-100`),"aria-label":r(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Z,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:r(`filesView.editor.selectFile`)})]}):null,xr&&!d&&K?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1`,children:[bi?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:bi,children:bi}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:Oa({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[K&&!R&&!(xr&&!d)&&(0,$.jsx)(`div`,{ref:ne,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{re.current>0||ee(!1)},children:B?Oa():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Di?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>zi(Vi()===`preview`?`edit`:`preview`),className:J(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Vi()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Z,{name:Vi()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>ee(!0),children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>ee(!0),className:`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground`,"aria-label":r(`filesView.editor.showControlsAria`),title:r(`filesView.editor.controlsTitle`),children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`size-4`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(fo,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:K?ft||ha||_a?mi?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-3`,children:(0,$.jsx)(es,{className:`size-48 max-w-full rounded-md`})}):S?(0,$.jsx)(`div`,{className:`p-3`}):(0,$.jsxs)(`div`,{className:`p-3 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.loading`)]}):gt?(0,$.jsxs)(`div`,{role:`alert`,className:`p-3 typography-ui text-[color:var(--status-error)]`,children:[(0,$.jsx)(`div`,{children:gt}),Dt===Pe&&(0,$.jsx)(Y,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:ni,children:r(`contextPanel.preview.actions.retry`)})]}):mi&&K?xa(K):_i?Ca(K):K&&ki&&le===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(tl,{ref:Ht,xml:qi,onChange:Gi},`${K.path}:${de}`)}):K&&Di&&Vi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:r(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(pa,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:r(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:r(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Ao,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):K&&Oi&&ce===`preview`?ga?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground typography-ui-label`,children:r(`common.loading`)}):(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(`iframe`,{src:!ta&&oa===na?(()=>{let e=K.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return st(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`).url})():void 0,srcDoc:ta?(()=>{if(!a.isVSCode)return it;let e=K.path.substring(0,K.path.lastIndexOf(`/`)+1);return e?it.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):it})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:r(`filesView.editor.htmlPreviewTitle`)},ua)}):K&&ji&&ae===`view`?Ea(K,kt):(0,$.jsxs)(`div`,{className:J(`relative h-full`,yi&&`overflow-hidden`),ref:cn,children:[(0,$.jsx)(`div`,{className:J(`h-full`,yi&&`invisible`),children:(0,$.jsx)(ls,{value:kt,onChange:jt,readOnly:!Ei,vimMode:vr===`vim`,extensions:Zi,className:`h-full`,blockWidgets:Ta,onViewReady:e=>{sn.current=e,xi(e),un(e=>e+1),window.requestAnimationFrame(()=>{Yi(e)})},onViewDestroy:()=>{sn.current&&=null,Nn(!1),Fn(null),un(e=>e+1)},enableSearch:!0,searchOpen:R,onSearchOpenChange:z,highlightLines:Xn?{start:Math.min(Xn.start,Xn.end),end:Math.max(Xn.start,Xn.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.button!==0)return!1;n.preventDefault();let r=e.state.doc.lineAt(t.from).number;if(Xn&&!n.shiftKey&&Math.min(Xn.start,Xn.end)===r&&Math.max(Xn.start,Xn.end)===r)return Qn(null),kr(),$n.current=!1,er.current=null,nr(!1),!0;if(d&&Xn&&!n.shiftKey){let e=Math.min(Xn.start,Xn.end,r),t=Math.max(Xn.start,Xn.end,r);return Qn({start:e,end:t}),$n.current=!1,er.current=null,nr(!1),!0}if($n.current=!0,er.current=r,nr(!0),Xn&&n.shiftKey){let e=Math.min(Xn.start,r),t=Math.max(Xn.end,r);Qn({start:e,end:t})}else Qn({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!$n.current||er.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(er.current,r),a=Math.max(er.current,r);return Qn({start:i,end:a}),nr(!0),!1},mouseup:()=>($n.current=!1,er.current=null,nr(!1),!1)}}})}),yi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.openingFileAtChange`)]})})]}):(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:r(`filesView.editor.pickFileFromTree`)})})]})]}),ja=!!(y&&Ge[y]),Na=y?qe[y]:null,Fa=(0,$.jsxs)(`section`,{className:J(`flex min-h-0 flex-col overflow-hidden`,d?`h-full w-full bg-background`:`h-full rounded-xl border border-border/60 bg-background/70`),children:[(0,$.jsx)(`div`,{className:J(`flex flex-col gap-2 py-2`,d?`px-3`:`px-2`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`}),(0,$.jsx)(sa,{ref:k,value:E,onChange:e=>D(e.target.value),placeholder:r(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),E.trim().length>0&&(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`filesView.tree.search.clearAria`),className:`absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground`,onClick:()=>{D(``),k.current?.focus()},children:(0,$.jsx)(Z,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Yn(`createFile`,{path:v,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.newFileTitle`),"aria-label":r(`filesView.tree.actions.newFileTitle`),children:(0,$.jsx)(Z,{name:`file-add`,className:`size-4`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Yn(`createFolder`,{path:v,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.newFolderTitle`),"aria-label":r(`filesView.tree.actions.newFolderTitle`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`size-4`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>void Ir(),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.refreshTitle`),"aria-label":r(`filesView.tree.actions.refreshTitle`),children:(0,$.jsx)(Z,{name:`refresh`,className:`size-4`})})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:di,disabled:ci.length===0&&Se.length===0,className:`size-8 flex-shrink-0 p-0`,title:r(ui?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":r(ui?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(Z,{name:ui?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:6,children:r(ui?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(fo,{outerClassName:`flex-1 min-h-0`,className:J(`py-2`,d?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:nt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.tree.search.searching`)]}):et.length>0?et.map(e=>{let t=K?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Zr(e),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),children:[vp(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,style:{direction:`rtl`,textAlign:`left`},title:e.path,children:e.relativePath??e.path})]})},e.path)}):Na?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-[var(--status-error)]`,children:Na}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void Ir(),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`}),r(`filesView.tree.actions.refreshTitle`)]})]}):ja?pi(y,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:r(`filesView.state.loading`)})})})]}),Ia=e===`full`&&I&&K&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col bg-background`,children:(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-30`,children:Oa({exitFullscreenOnly:!0})}),(0,$.jsx)(fo,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:ft||ha||_a?mi?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(es,{className:`size-48 max-w-full rounded-md`})}):S?(0,$.jsx)(`div`,{className:`p-4`}):(0,$.jsxs)(`div`,{className:`p-4 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),`Loading…`]}):gt?(0,$.jsxs)(`div`,{role:`alert`,className:`p-4 typography-ui text-[color:var(--status-error)]`,children:[(0,$.jsx)(`div`,{children:gt}),Dt===Pe&&(0,$.jsx)(Y,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:ni,children:r(`contextPanel.preview.actions.retry`)})]}):mi?xa(K,{fullHeight:!0}):_i?Ca(K):Di&&Vi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:r(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(pa,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:r(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:r(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Ao,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):ji&&ae===`view`?Ea(K,kt):(0,$.jsxs)(`div`,{className:J(`relative h-full`,yi&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:J(`h-full`,yi&&`invisible`),children:(0,$.jsx)(ls,{value:kt,onChange:jt,readOnly:!Ei,vimMode:vr===`vim`,extensions:Zi,className:`h-full`,onViewReady:e=>{sn.current=e,xi(e),window.requestAnimationFrame(()=>{Yi(e)})},onViewDestroy:()=>{sn.current&&=null,Nn(!1),Fn(null)}})}),yi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.openingFileAtChange`)]})})]})})]})});return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 overflow-hidden bg-background relative`,children:[(0,$.jsx)(xp,{activeDialog:pn,dialogData:hn,dialogInputValue:_n,onDialogInputChange:vn,isDialogSubmitting:yn,onDialogSubmit:Br,onClose:wa,inputRef:It}),Ia,Pn?(0,$.jsx)(Nc,{position:Pn,onDismiss:()=>Fn(null),onAddToChat:Si}):null,H.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Yf,{popup:H,onOpenChange:ba,isMobile:d})}):null,d?A?ka:Fa:e===`editor-only`?(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden bg-background`,children:ka})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[p>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:Fa}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:ka})]})]})};function Tp(e){return e+1}var Ep=e=>e,Dp=e=>{let t=Ep(e).type;return typeof t==`string`?t:``},Op=e=>{let t=Ep(e).tool;return typeof t==`string`?t:``},kp=e=>{let t=Ep(e).text;return typeof t==`string`?t:``},Ap=e=>{let t=Dp(e);return t===`tool`?Op(e).trim().toLowerCase()||`tool`:t||`unknown`},jp=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Ap(n);t.includes(e)||t.push(e)}return t.join(` + `)},Mp=e=>e.replace(/\s+/g,` `).trim(),Np=e=>{for(let t of e)if(Dp(t)===`text`){let e=Mp(kp(t));if(e.length===0)continue;return e}let t=e.filter(e=>Dp(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Pp=(e,t,n)=>`${n(e)} / ${n(t)}`,Fp=(e,t,n,r)=>{let i=Pp(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},Ip=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},Lp=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=Ip(t);return new Date(e).toLocaleString(void 0,{month:`numeric`,day:`numeric`,hour:n===!1?`2-digit`:`numeric`,minute:`2-digit`,...n===void 0?{}:{hour12:n}})},Rp={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},zp={user:0,assistant:0,tool:0,other:0},Bp=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,Vp=e=>{let t=e.info.tokens,n=t===void 0?e.parts.find(e=>e.tokens!==void 0)?.tokens:t;if(typeof n==`number`)return{...Rp,total:Bp(n)};if(!n||typeof n!=`object`)return Rp;let r=n,i=Bp(r.input),a=Bp(r.output),o=Bp(r.reasoning),s=Bp(r.cache?.read),c=Bp(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},Hp=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},Up=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+Up(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+Up(t),0):0,Wp=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...zp,assistant:Up(n.text)+Up(n.content)};let i=Hp(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:Up(n.input)+Up(n.output)+Up(n.error)+Up(n.call?.input)+Up(n.call?.output)+Up(n.call?.error)+Up(n.raw)+Math.round(Up(n.metadata)*.25)+Math.round(Up(n.state)*.1),other:0}:t===`user`?{user:i.length,assistant:0,tool:0,other:0}:t===`assistant`?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},Gp=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),Kp=e=>{let t=Gr(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},qp=(e,t)=>{if(e.length===0)return{...zp};let n=e.reduce((e,t)=>{let n=Kp(t),r={...zp};for(let e of t.parts)r=Gp(r,Wp(e,n));return Gp(e,r)},{...zp});return n.user+=t.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)}},Jp=e=>e.toLocaleString(jt()),Yp=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(jt(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(jt(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),Xp=(e,t)=>!e||!Number.isFinite(e)?`-`:ga(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),Zp=(e,t,n)=>{let r=e.find(e=>e.id===t),i=r?.models?.find(e=>e.id===n);return{providerName:r?.name||t||`-`,modelName:i?.name||n||`-`,contextLimit:typeof i?.limit?.context==`number`?i.limit.context:null}},Qp=()=>{let e=(0,fl.c)(262),{t}=wt(),n=q($p),r=q(em),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={},e[0]=i):i=e[0];let[a,o]=Q.useState(i),[s,c]=Q.useState(null),l=Q.useRef(null),u=xn(tm),d=Yn(),f=Gn(u??``),p=Zn(nm),m;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(rm),c(null)},e[1]=m):m=e[1];let h;e[2]===u?h=e[3]:(h=[u],e[2]=u,e[3]=h),Q.useEffect(m,h);let g,_;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},_=[],e[4]=g,e[5]=_):(g=e[4],_=e[5]),Q.useEffect(g,_);let v;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=async(e,t)=>{(await Ct(t)).ok?(c(e),l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{c(t=>t===e?null:t),l.current=null},2e3)):c(null)},e[6]=v):v=e[6];let y=v,b;e[7]!==u||e[8]!==d?(b=u?d.find(e=>e.id===u)??null:null,e[7]=u,e[8]=d,e[9]=b):b=e[9];let x=b,S,C,w,T,E,D,O,k,A;if(e[10]!==p||e[11]!==f||e[12]!==r){S=f.filter(im);let t;e[22]===f?t=e[23]:(t=f.filter(am),e[22]=f,e[23]=t),A=t;let n=r?bi(f):null,i=null;for(let e=S.length-1;e>=0;--e){let t=S[e];if(Vp(t).total>0){i=t;break}}O=i?Vp(i):Rp,w=Ei({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=S.reduce(om,0),C=new Map;let a=[];for(let e of n?.turns??[]){let t=e.assistantMessages.map(sm),n=Zr(t);for(let t=0;t<n.length;t+=1){let r=n[t],i=e.assistantMessageIds[t];r!==null&&i&&C.set(i,Vr(r))}let r=n[n.length-1]??null;e.completionDisposition!==`active`&&r!==null&&a.push(...t)}let o=qr(a);E=o===null?null:Vr(o);let s=i?n?.indexes.messageToTurnId.get(i.info.id):void 0,c=s?n?.indexes.turnById.get(s):void 0,l=c?.assistantMessageIds[c.assistantMessageIds.length-1];T=l?C.get(l)??null:null;let u=i?.info??null;D=Zp(p,u?.providerID||``,u?.modelID||``),e[10]=p,e[11]=f,e[12]=r,e[13]=S,e[14]=C,e[15]=w,e[16]=T,e[17]=E,e[18]=D,e[19]=O,e[20]=k,e[21]=A}else S=e[13],C=e[14],w=e[15],T=e[16],E=e[17],D=e[18],O=e[19],k=e[20],A=e[21];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===f?P=e[25]:(P=qp(f,[...f].reverse().find(cm)?.info?.system||``),e[24]=f,e[25]=P);let F=P,I=F.user,L=F.assistant,R=F.tool,z=Math.max(0,O.input-I-L-R),B=I+L+R+z,V=f[0]?.info?.time?.created,ee=f.length>0?f[f.length-1]?.info?.time?.created:null,H;e[26]!==x?.title||e[27]!==t?(H=x?.title||t(`contextSidebar.session.untitled`),e[26]=x?.title,e[27]=t,e[28]=H):H=e[28];let te=x?.time?.created??V??null,ne=ee??x?.time?.created??null,re=E&&E.length>0?E:null,U=T&&T.length>0?T:null,ie;e[29]!==L||e[30]!==z||e[31]!==R||e[32]!==I?(ie={user:I,assistant:L,tool:R,other:z},e[29]=L,e[30]=z,e[31]=R,e[32]=I,e[33]=ie):ie=e[33];let ae;e[34]!==S.length||e[35]!==C||e[36]!==B||e[37]!==w||e[38]!==M||e[39]!==j||e[40]!==f.length||e[41]!==te||e[42]!==ne||e[43]!==re||e[44]!==U||e[45]!==ie||e[46]!==H||e[47]!==O||e[48]!==k||e[49]!==N||e[50]!==A.length?(ae={sessionTitle:H,messagesCount:f.length,userMessagesCount:A.length,assistantMessagesCount:S.length,createdAt:te,lastActivityAt:ne,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,assistantTpsByMessageID:C,sessionTpsLabel:re,lastAssistantTpsLabel:U,contextLimit:M,breakdown:ie,breakdownTotal:B},e[34]=S.length,e[35]=C,e[36]=B,e[37]=w,e[38]=M,e[39]=j,e[40]=f.length,e[41]=te,e[42]=ne,e[43]=re,e[44]=U,e[45]=ie,e[46]=H,e[47]=O,e[48]=k,e[49]=N,e[50]=A.length,e[51]=ae):ae=e[51];let W=ae;if(!u){let n;e[52]===t?n=e[53]:(n=t(`contextSidebar.empty.openSession`),e[52]=t,e[53]=n);let r;return e[54]===n?r=e[55]:(r=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground`,children:n}),e[54]=n,e[55]=r),r}let oe;e[56]===t?oe=e[57]:(oe=t(`contextSidebar.breakdown.user`),e[56]=t,e[57]=oe);let se;e[58]!==oe||e[59]!==W.breakdown.user?(se={key:`user`,label:oe,value:W.breakdown.user,color:`var(--status-success)`},e[58]=oe,e[59]=W.breakdown.user,e[60]=se):se=e[60];let ce;e[61]===t?ce=e[62]:(ce=t(`contextSidebar.breakdown.assistant`),e[61]=t,e[62]=ce);let G;e[63]!==ce||e[64]!==W.breakdown.assistant?(G={key:`assistant`,label:ce,value:W.breakdown.assistant,color:`var(--primary-base)`},e[63]=ce,e[64]=W.breakdown.assistant,e[65]=G):G=e[65];let le;e[66]===t?le=e[67]:(le=t(`contextSidebar.breakdown.toolCalls`),e[66]=t,e[67]=le);let ue;e[68]!==le||e[69]!==W.breakdown.tool?(ue={key:`tool`,label:le,value:W.breakdown.tool,color:`var(--status-warning)`},e[68]=le,e[69]=W.breakdown.tool,e[70]=ue):ue=e[70];let de;e[71]===t?de=e[72]:(de=t(`contextSidebar.breakdown.other`),e[71]=t,e[72]=de);let fe;e[73]!==de||e[74]!==W.breakdown.other?(fe={key:`other`,label:de,value:W.breakdown.other,color:`var(--surface-muted-foreground)`},e[73]=de,e[74]=W.breakdown.other,e[75]=fe):fe=e[75];let pe;e[76]!==se||e[77]!==G||e[78]!==ue||e[79]!==fe?(pe=[se,G,ue,fe],e[76]=se,e[77]=G,e[78]=ue,e[79]=fe,e[80]=pe):pe=e[80];let me=pe,he;e[81]===W.sessionTitle?he=e[82]:(he=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:W.sessionTitle}),e[81]=W.sessionTitle,e[82]=he);let ge;e[83]!==W.providerModel.modelName||e[84]!==W.providerModel.providerName?(ge=(0,$.jsxs)(`span`,{children:[W.providerModel.providerName,` / `,W.providerModel.modelName]}),e[83]=W.providerModel.modelName,e[84]=W.providerModel.providerName,e[85]=ge):ge=e[85];let _e;e[86]!==n||e[87]!==W.createdAt?(_e=W.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:Xp(W.createdAt,n)})]}),e[86]=n,e[87]=W.createdAt,e[88]=_e):_e=e[88];let ve;e[89]!==ge||e[90]!==_e?(ve=(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70`,children:[ge,_e]}),e[89]=ge,e[90]=_e,e[91]=ve):ve=e[91];let ye;e[92]!==he||e[93]!==ve?(ye=(0,$.jsxs)(`div`,{className:`mb-6`,children:[he,ve]}),e[92]=he,e[93]=ve,e[94]=ye):ye=e[94];let be;e[95]===t?be=e[96]:(be=t(`contextSidebar.section.context`),e[95]=t,e[96]=be);let xe;e[97]===be?xe=e[98]:(xe=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:be}),e[97]=be,e[98]=xe);let Se;e[99]===W.tokenBreakdown.total?Se=e[100]:(Se=Jp(W.tokenBreakdown.total),e[99]=W.tokenBreakdown.total,e[100]=Se);let Ce;e[101]===W.contextLimit?Ce=e[102]:(Ce=W.contextLimit?` / ${Jp(W.contextLimit)}`:``,e[101]=W.contextLimit,e[102]=Ce);let we;e[103]!==Se||e[104]!==Ce?(we=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[Se,Ce]}),e[103]=Se,e[104]=Ce,e[105]=we):we=e[105];let Te;e[106]!==xe||e[107]!==we?(Te=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[xe,we]}),e[106]=xe,e[107]=we,e[108]=Te):Te=e[108];let Ee;e[109]===W.usagePercent?Ee=e[110]:(Ee=W.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[109]=W.usagePercent,e[110]=Ee);let De;e[111]===Ee?De=e[112]:(De=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:Ee}),e[111]=Ee,e[112]=De);let Oe;e[113]!==t||e[114]!==W.usagePercent?(Oe=t(`contextSidebar.context.percentUsed`,{percent:W.usagePercent.toFixed(1)}),e[113]=t,e[114]=W.usagePercent,e[115]=Oe):Oe=e[115];let ke;e[116]===Oe?ke=e[117]:(ke=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:Oe}),e[116]=Oe,e[117]=ke);let Ae;e[118]!==Te||e[119]!==De||e[120]!==ke?(Ae=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[Te,De,ke]}),e[118]=Te,e[119]=De,e[120]=ke,e[121]=Ae):Ae=e[121];let je;e[122]===t?je=e[123]:(je=t(`contextSidebar.stats.messages`),e[122]=t,e[123]=je);let Me;e[124]===W.messagesCount?Me=e[125]:(Me=Jp(W.messagesCount),e[124]=W.messagesCount,e[125]=Me);let Ne;e[126]!==je||e[127]!==Me?(Ne={label:je,value:Me},e[126]=je,e[127]=Me,e[128]=Ne):Ne=e[128];let K;e[129]===t?K=e[130]:(K=t(`contextSidebar.stats.user`),e[129]=t,e[130]=K);let Pe;e[131]===W.userMessagesCount?Pe=e[132]:(Pe=Jp(W.userMessagesCount),e[131]=W.userMessagesCount,e[132]=Pe);let Fe;e[133]!==K||e[134]!==Pe?(Fe={label:K,value:Pe},e[133]=K,e[134]=Pe,e[135]=Fe):Fe=e[135];let Ie;e[136]===t?Ie=e[137]:(Ie=t(`contextSidebar.stats.assistant`),e[136]=t,e[137]=Ie);let Le;e[138]===W.assistantMessagesCount?Le=e[139]:(Le=Jp(W.assistantMessagesCount),e[138]=W.assistantMessagesCount,e[139]=Le);let Re;e[140]!==Ie||e[141]!==Le?(Re={label:Ie,value:Le},e[140]=Ie,e[141]=Le,e[142]=Re):Re=e[142];let ze;e[143]!==Ne||e[144]!==Fe||e[145]!==Re?(ze=[Ne,Fe,Re],e[143]=Ne,e[144]=Fe,e[145]=Re,e[146]=ze):ze=e[146];let Be=ze,Ve;e[147]===Be?Ve=e[148]:(Ve=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:Be.map(lm)}),e[147]=Be,e[148]=Ve);let He=r?`grid-cols-2`:`grid-cols-1`,Ue;e[149]===He?Ue=e[150]:(Ue=J(`grid gap-2`,He),e[149]=He,e[150]=Ue);let We;e[151]===t?We=e[152]:(We=t(`contextSidebar.stats.cost`),e[151]=t,e[152]=We);let Ge;e[153]===We?Ge=e[154]:(Ge=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:We}),e[153]=We,e[154]=Ge);let Ke;e[155]===W.totalAssistantCost?Ke=e[156]:(Ke=Yp(W.totalAssistantCost),e[155]=W.totalAssistantCost,e[156]=Ke);let qe;e[157]===Ke?qe=e[158]:(qe=(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:Ke}),e[157]=Ke,e[158]=qe);let Je;e[159]!==Ge||e[160]!==qe?(Je=(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[Ge,qe]}),e[159]=Ge,e[160]=qe,e[161]=Je):Je=e[161];let Ye;e[162]!==r||e[163]!==t||e[164]!==W.sessionTpsLabel?(Ye=r?(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:t(`contextSidebar.stats.sessionTps`)}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:W.sessionTpsLabel??`—`})]}):null,e[162]=r,e[163]=t,e[164]=W.sessionTpsLabel,e[165]=Ye):Ye=e[165];let Xe;e[166]!==Ue||e[167]!==Je||e[168]!==Ye?(Xe=(0,$.jsxs)(`div`,{className:Ue,children:[Je,Ye]}),e[166]=Ue,e[167]=Je,e[168]=Ye,e[169]=Xe):Xe=e[169];let Ze;e[170]!==Ve||e[171]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Ve,Xe]}),e[170]=Ve,e[171]=Xe,e[172]=Ze):Ze=e[172];let Qe;e[173]===t?Qe=e[174]:(Qe=t(`contextSidebar.section.lastAssistantMessage`),e[173]=t,e[174]=Qe);let $e;e[175]===Qe?$e=e[176]:($e=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:Qe}),e[175]=Qe,e[176]=$e);let et;e[177]===t?et=e[178]:(et=t(`contextSidebar.tokens.input`),e[177]=t,e[178]=et);let tt;e[179]!==et||e[180]!==W.tokenBreakdown.input?(tt={label:et,value:W.tokenBreakdown.input,format:`count`},e[179]=et,e[180]=W.tokenBreakdown.input,e[181]=tt):tt=e[181];let nt;e[182]===t?nt=e[183]:(nt=t(`contextSidebar.tokens.output`),e[182]=t,e[183]=nt);let rt;e[184]!==nt||e[185]!==W.tokenBreakdown.output?(rt={label:nt,value:W.tokenBreakdown.output,format:`count`},e[184]=nt,e[185]=W.tokenBreakdown.output,e[186]=rt):rt=e[186];let it;e[187]===t?it=e[188]:(it=t(`contextSidebar.tokens.reasoning`),e[187]=t,e[188]=it);let at;e[189]!==it||e[190]!==W.tokenBreakdown.reasoning?(at={label:it,value:W.tokenBreakdown.reasoning,format:`count`},e[189]=it,e[190]=W.tokenBreakdown.reasoning,e[191]=at):at=e[191];let ot;e[192]===t?ot=e[193]:(ot=t(`contextSidebar.tokens.cacheRead`),e[192]=t,e[193]=ot);let st;e[194]!==ot||e[195]!==W.tokenBreakdown.cacheRead?(st={label:ot,value:W.tokenBreakdown.cacheRead,format:`count`},e[194]=ot,e[195]=W.tokenBreakdown.cacheRead,e[196]=st):st=e[196];let ct;e[197]===t?ct=e[198]:(ct=t(`contextSidebar.tokens.cacheWrite`),e[197]=t,e[198]=ct);let lt;e[199]!==ct||e[200]!==W.tokenBreakdown.cacheWrite?(lt={label:ct,value:W.tokenBreakdown.cacheWrite,format:`count`},e[199]=ct,e[200]=W.tokenBreakdown.cacheWrite,e[201]=lt):lt=e[201];let ut;e[202]===t?ut=e[203]:(ut=t(`contextSidebar.tokens.cacheHit`),e[202]=t,e[203]=ut);let dt=W.cacheHitRate.hasInput?W.cacheHitRate.percent:null,ft;e[204]!==ut||e[205]!==dt?(ft={label:ut,value:dt,format:`percent`},e[204]=ut,e[205]=dt,e[206]=ft):ft=e[206];let pt;e[207]!==r||e[208]!==t||e[209]!==W.lastAssistantTpsLabel?(pt=r?[{label:t(`contextSidebar.tokens.tps`),value:W.lastAssistantTpsLabel,format:`text`}]:[],e[207]=r,e[208]=t,e[209]=W.lastAssistantTpsLabel,e[210]=pt):pt=e[210];let mt;e[211]!==tt||e[212]!==rt||e[213]!==at||e[214]!==st||e[215]!==lt||e[216]!==ft||e[217]!==pt?(mt=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[tt,rt,at,st,lt,ft,...pt].map(um)}),e[211]=tt,e[212]=rt,e[213]=at,e[214]=st,e[215]=lt,e[216]=ft,e[217]=pt,e[218]=mt):mt=e[218];let ht;e[219]!==$e||e[220]!==mt?(ht=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[$e,mt]}),e[219]=$e,e[220]=mt,e[221]=ht):ht=e[221];let gt;e[222]!==me||e[223]!==W.breakdownTotal?(gt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:me.map(e=>e.value<=0||W.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/W.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[222]=me,e[223]=W.breakdownTotal,e[224]=gt):gt=e[224];let _t;e[225]!==me||e[226]!==W.breakdownTotal?(_t=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:me.map(e=>{let t=W.breakdownTotal>0?e.value/W.breakdownTotal*100:0;return(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{backgroundColor:e.color}}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70`,children:[e.label,` `,(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[t.toFixed(0),`%`]})]})]},e.key)})}),e[225]=me,e[226]=W.breakdownTotal,e[227]=_t):_t=e[227];let vt;e[228]!==gt||e[229]!==_t?(vt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[gt,_t]}),e[228]=gt,e[229]=_t,e[230]=vt):vt=e[230];let yt;e[231]===t?yt=e[232]:(yt=t(`contextSidebar.section.rawMessages`),e[231]=t,e[232]=yt);let bt;e[233]===yt?bt=e[234]:(bt=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:yt}),e[233]=yt,e[234]=bt);let xt;if(e[235]!==s||e[236]!==a||e[237]!==f||e[238]!==r||e[239]!==t||e[240]!==n||e[241]!==W.assistantTpsByMessageID){let i;e[243]!==s||e[244]!==a||e[245]!==r||e[246]!==t||e[247]!==n||e[248]!==W.assistantTpsByMessageID?(i=e=>{let i=Gr(e.info).role,c=i===`assistant`,l=i===`user`,u=a[e.info.id]===!0,d=s===e.info.id,f=e.info.time?.created??null,p=jp(e.parts),m=c?Vp({info:e.info,parts:e.parts}):null,h=l?Np(e.parts):``,g=Lp(f,n),_=p||`—`,v=!r||!c?null:W.assistantTpsByMessageID.get(e.info.id)??null,b=m?Fp(m.input,m.output,Jp,v):``,x=i||`unknown`,S=p?`${x}: ${p}`:x,C=u?JSON.stringify({info:e.info,parts:e.parts},null,2):``;return(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70`,children:[(0,$.jsx)(`button`,{type:`button`,className:`w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"aria-expanded":u,onClick:()=>{o(t=>({...t,[e.info.id]:t[e.info.id]!==!0}))},children:(0,$.jsxs)(`div`,{className:`grid items-center gap-x-2 whitespace-nowrap typography-micro`,style:{gridTemplateColumns:c?`minmax(0, 1fr) minmax(7.5rem, max-content) max-content`:`minmax(0, 1fr) max-content`},children:[l?(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:`user:`}),` `,h]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:c?_:S}),c&&(0,$.jsx)(`span`,{className:`text-right text-muted-foreground tabular-nums`,children:b})]}),(0,$.jsx)(`span`,{className:`text-right text-muted-foreground`,children:g})]})}),u&&(0,$.jsx)(`div`,{className:`border-t border-[var(--surface-subtle)] p-0`,children:(0,$.jsxs)(`div`,{className:`group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]`,children:[(0,$.jsx)(`div`,{className:`absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100`,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground`,onClick:t=>{t.stopPropagation(),y(e.info.id,C)},"aria-label":t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copyJson`),title:t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copy`),children:d?(0,$.jsx)(Z,{name:`check`,className:`size-3.5`}):(0,$.jsx)(Z,{name:`file-copy`,className:`size-3.5`})})}),(0,$.jsx)(ns,{language:`json`,code:C,style:{margin:0,padding:`0.75rem`,background:`transparent`,fontSize:`var(--text-micro)`,lineHeight:`1.35`},wrap:!0})]})})]},e.info.id)},e[243]=s,e[244]=a,e[245]=r,e[246]=t,e[247]=n,e[248]=W.assistantTpsByMessageID,e[249]=i):i=e[249],xt=[...f].reverse().map(i),e[235]=s,e[236]=a,e[237]=f,e[238]=r,e[239]=t,e[240]=n,e[241]=W.assistantTpsByMessageID,e[242]=xt}else xt=e[242];let St;e[250]===xt?St=e[251]:(St=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:xt}),e[250]=xt,e[251]=St);let Tt;e[252]!==bt||e[253]!==St?(Tt=(0,$.jsxs)(`div`,{children:[bt,St]}),e[252]=bt,e[253]=St,e[254]=Tt):Tt=e[254];let Et;return e[255]!==ye||e[256]!==Ae||e[257]!==Ze||e[258]!==ht||e[259]!==vt||e[260]!==Tt?(Et=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[ye,Ae,Ze,ht,vt,Tt]})}),e[255]=ye,e[256]=Ae,e[257]=Ze,e[258]=ht,e[259]=vt,e[260]=Tt,e[261]=Et):Et=e[261],Et};function $p(e){return e.timeFormatPreference}function em(e){return e.showAssistantTps}function tm(e){return e.currentSessionId}function nm(e){return e.providers}function rm(e){return Object.keys(e).length>0?{}:e}function im(e){return Gr(e.info).role===`assistant`}function am(e){return Gr(e.info).isUser}function om(e,t){return e+Bp(t.info.cost)}function sm(e){let{info:t}=e;return{createdAt:t.time.created,streamedAt:t.time.streamed,outputTokens:t.tokens?.output,reasoningTokens:t.tokens?.reasoning}}function cm(e){return Gr(e.info).isUser&&typeof e.info.system==`string`}function lm(e){return(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.value})]},e.label)}function um(e){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.format===`text`?typeof e.value==`string`&&e.value.length>0?e.value:`—`:e.value!==null&&e.value!==void 0?e.format===`percent`?`${Number(e.value).toFixed(1)}%`:Jp(Number(e.value)):`—`})]},e.label)}var dm=e=>{let t=e.trim().replace(/\\/g,`/`);if(!t)return``;let n=t.startsWith(`//`),r=t.replace(/\/+$/g,``).replace(/\/+/g,`/`);return n&&!r.startsWith(`//`)?`/${r}`:r||(t.startsWith(`/`)?`/`:``)},fm=()=>`react-surface`,pm=(e,t)=>JSON.stringify([dm(e),t]),mm=(e,t,n,r)=>JSON.stringify([e,t,dm(n),r]),hm=(e,t,n)=>n?t:e===t?e:null,gm=(e,t)=>e.sessionId===t.sessionId&&dm(e.directory)===dm(t.directory),_m=(e,t)=>dm(e)===dm(t),vm=e=>({anchor:e,current:e,stack:[]}),ym=(e,t)=>e??vm(t),bm=(e,t)=>e?.current.sessionId??t,xm=(e,t)=>gm(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},Sm=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Cm=(e,t,n)=>!_m(e.anchor.directory,t.directory)||!_m(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:xm(e,t)},wm=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Cm(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Tm=(e,t)=>{let n=!1,r={};for(let[i,a]of Object.entries(e)){if(!t.has(i)){n=!0;continue}r[i]=a}return n?r:e},Em=e=>e.directoryMatches?e.error?e.messageCount>0?`partial-error`:`fatal-error`:!e.renderable&&e.requested?`cold-loading`:e.messageCount===0?e.working?`working-empty`:`authoritative-empty`:`transcript`:`directory-mismatch`,Dm=e=>e===`retry`,Om=e=>e.active&&e.visible&&e.messageCount<=0,km=e=>e?`load-more`:`ensure`,Am=e=>e.kind===`has-more`,jm=(e,t)=>`${e}\n${t}`,Mm=(e,t,n,r)=>r&&!e.has(jm(t,n)),Nm=(e,t)=>({scrollHeight:e,scrollTop:t}),Pm=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Fm=(e,t)=>e&&!t,Im=e=>e,Lm=e=>!e,Rm=e=>!Fm(e.hasMore,e.isLoading)||!Lm(e.historyVirtualized)?null:Nm(e.scrollHeight,e.scrollTop),zm=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),Bm=33554432,Vm=e=>Math.min(Bm,262144+Math.max(0,Math.ceil(e))*64*1024),Hm=e=>Math.min(Bm,Math.max(0,Math.round(Number.isFinite(e)?e:0))),Um=e=>{let t=Object.values(e.mountedViews),n=t.length,r=t.reduce((e,t)=>e+t.estimatedBytes,0),i=new Set,a=t.filter(t=>t.viewKey!==e.activeViewKey).sort((e,t)=>e.lastAccessed-t.lastAccessed);for(let e of a){if(n<=3&&r<=33554432)break;i.add(e.viewKey),--n,r-=e.estimatedBytes}if(i.size===0)return e;let o={...e.mountedViews};return i.forEach(e=>delete o[e]),{...e,mountedViews:o}},Wm=(e,t)=>{if(t.type===`close-tab`){let n=Object.values(e.mountedViews).filter(e=>e.tabId===t.tabId);if(!e.tabs[t.tabId]&&n.length===0)return e;let r={...e.tabs},i={...e.mountedViews};return delete r[t.tabId],n.forEach(e=>delete i[e.viewKey]),{activeViewKey:n.some(t=>t.viewKey===e.activeViewKey)?null:e.activeViewKey,tabs:r,mountedViews:i}}if(t.type===`activate`){if(t.viewKey===e.activeViewKey)return e;let n=t.viewKey?e.mountedViews[t.viewKey]:void 0;if(t.viewKey&&!n)return e;if(!n)return{...e,activeViewKey:null};let r=n.lastAccessed===t.now?e.mountedViews:{...e.mountedViews,[n.viewKey]:{...n,lastAccessed:t.now}};return Um({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=Hm(t.estimatedBytes);return!n||n.estimatedBytes===r?e:Um({...e,mountedViews:{...e.mountedViews,[n.viewKey]:{...n,estimatedBytes:r}}})}let n=e.tabs[t.tab.tabId],r=e.mountedViews[t.view.viewKey],i=n&&n.sessionId===t.tab.sessionId&&n.directory===t.tab.directory&&n.title===t.tab.title,a=r&&r.tabId===t.view.tabId&&r.surfaceId===t.view.surfaceId&&r.lastAccessed===t.now;return i&&a&&e.activeViewKey===t.view.viewKey?e:Um({...e,activeViewKey:t.view.viewKey,tabs:i?e.tabs:{...e.tabs,[t.tab.tabId]:t.tab},mountedViews:{...e.mountedViews,[t.view.viewKey]:{...t.view,estimatedBytes:r?.estimatedBytes??Vm(0),lastAccessed:t.now}}})},Gm=e=>{let t=(0,fl.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=wt();if(n===`cold-loading`||n===`working-empty`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`})}),t[0]=e):e=t[0],e}if(n===`fatal-error`||n===`directory-mismatch`){let e;t[1]!==r||t[2]!==a?(e=r||a(`chat.emptyState.opencodeUnreachable`),t[1]=r,t[2]=a,t[3]=e):e=t[3];let o;t[4]===e?o=t[5]:(o=(0,$.jsx)(`div`,{className:`text-center`,children:e}),t[4]=e,t[5]=o);let s;t[6]!==i||t[7]!==n||t[8]!==a?(s=n===`fatal-error`?(0,$.jsx)(Y,{type:`button`,variant:`secondary`,size:`sm`,onClick:i,children:a(`chat.history.retry`)}):null,t[6]=i,t[7]=n,t[8]=a,t[9]=s):s=t[9];let c;return t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-sm text-muted-foreground`,children:[o,s]}),t[10]=o,t[11]=s,t[12]=c):c=t[12],c}let o;t[13]===a?o=t[14]:(o=a(`chat.timeline.empty.session`),t[13]=a,t[14]=o);let s;return t[15]===o?s=t[16]:(s=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:o}),t[15]=o,t[16]=s),s},Km=e=>{let t=(0,fl.c)(173),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:o,onNavigateSession:s,onNavigateBack:c,onEstimateBytes:l,syncDirectory:u}=e,{t:d}=wt(),p=Wi(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=f(),m=dm(i),g=mm(h,n,m,r),t[0]=i,t[1]=r,t[2]=n,t[3]=m,t[4]=h,t[5]=g):(m=t[3],h=t[4],g=t[5]);let _=g,v=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(0),[x,S]=Q.useState(null),C;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(C=new Set,t[6]=C):C=t[6];let w=Q.useRef(C),T=_n(r,u),E=Gn(r,u),D=Zn(Jm),O;t[7]===E?O=t[8]:(O=Vi(E),t[7]=E,t[8]=O);let k=O,A;bb0:{if(!k.modelId){let e;t[9]===d?e=t[10]:(e=d(`common.unavailable`),t[9]=d,t[10]=e),A=e;break bb0}let e;if(t[11]!==k.modelId||t[12]!==k.providerId||t[13]!==D){let n;t[15]===k.providerId?n=t[16]:(n=e=>e.id===k.providerId,t[15]=k.providerId,t[16]=n);let r=D.find(n);e=r?.models.some(e=>e.id===k.modelId)&&tn(r,k.modelId)||k.modelId,t[11]=k.modelId,t[12]=k.providerId,t[13]=D,t[14]=e}else e=t[14];A=e}let j=A,M=Un(r,u),N=Pn(r,u).renderable,P;t[17]===r?P=t[18]:(P=e=>!!e.session.find(e=>e.id===r)?.parentID,t[17]=r,t[18]=P);let F=Wt(P,u),[I,L]=Q.useState(null),R,z;t[19]!==F||t[20]!==_?(R=()=>{L(e=>hm(e,_,F))},z=[F,_],t[19]=F,t[20]=_,t[21]=R,t[22]=z):(R=t[21],z=t[22]),Q.useLayoutEffect(R,z);let B=F||I===_,V=Vn(r,u),ee;t[23]===r?ee=t[24]:(ee=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=ee);let H=Rt(ee),te;t[25]===H?te=t[26]:(te=e=>H?e.messageStreamStates.get(H)?.phase??null:null,t[25]=H,t[26]=te);let ne=Rt(te),re=M?.type===`busy`||M?.type===`retry`,U;t[27]!==a||t[28]!==r||t[29]!==re||t[30]!==T||t[31]!==_?(U={scrollControllerRef:v,enabled:a,currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:re,isMobile:!1},t[27]=a,t[28]=r,t[29]=re,t[30]=T,t[31]=_,t[32]=U):U=t[32];let{scrollRef:ie,notifyContentChange:ae,getAnimationHandlers:W,goToBottom:oe,restoreSnapshot:se,showScrollButton:ce}=Yr(U),G;t[33]===oe?G=t[34]:(G=e=>{oe(e===void 0?`instant`:e)},t[33]=oe,t[34]=G);let le=_t(G),ue;t[35]!==r||t[36]!==p?(ue=e=>{p.ensureSessionRenderable(r,Dm(e))},t[35]=r,t[36]=p,t[37]=ue):ue=t[37];let de=_t(ue),fe,pe;t[38]!==a||t[39]!==de?(fe=()=>{a&&de(`active`)},pe=[a,de],t[38]=a,t[39]=de,t[40]=fe,t[41]=pe):(fe=t[40],pe=t[41]),Q.useEffect(fe,pe);let me,he;t[42]!==a||t[43]!==de||t[44]!==T?(me=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();Om({active:a,visible:e,messageCount:T})&&de(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},he=[a,de,T],t[42]=a,t[43]=de,t[44]=T,t[45]=me,t[46]=he):(me=t[45],he=t[46]),Q.useEffect(me,he);let ge,_e;t[47]!==l||t[48]!==T||t[49]!==_?(ge=()=>{l?.(_,Vm(T))},_e=[l,T,_],t[47]=l,t[48]=T,t[49]=_,t[50]=ge,t[51]=_e):(ge=t[50],_e=t[51]),Q.useEffect(ge,_e);let ve,ye;t[52]!==N||t[53]!==se||t[54]!==r||t[55]!==_?(ve=()=>{if(!Mm(w.current,r,_,N))return;let e=jm(r,_);w.current.add(e),se()},ye=[N,se,r,_],t[52]=N,t[53]=se,t[54]=r,t[55]=_,t[56]=ve,t[57]=ye):(ve=t[56],ye=t[57]),Q.useEffect(ve,ye);let be;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(be=()=>{y.current=null,S(null)},t[58]=be):be=t[58];let xe;t[59]===_?xe=t[60]:(xe=[_],t[59]=_,t[60]=xe),Q.useLayoutEffect(be,xe);let Se;t[61]!==x||t[62]!==ie||t[63]!==_?(Se=()=>{let e=y.current,t=ie.current;if(zm(e,x,_)){if(!t||!Lm(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Pm(e.anchor,t.scrollHeight),y.current=null}},t[61]=x,t[62]=ie,t[63]=_,t[64]=Se):Se=t[64];let Ce;t[65]!==x||t[66]!==ie||t[67]!==E||t[68]!==_?(Ce=[x,ie,E,_],t[65]=x,t[66]=ie,t[67]=E,t[68]=_,t[69]=Ce):Ce=t[69],Q.useLayoutEffect(Se,Ce);let we;t[70]===m?we=t[71]:(we={directory:m},t[70]=m,t[71]=we);let Te=we,Ee=gn(r,u).boundary,De;t[72]===Ee?De=t[73]:(De=Am(Ee),t[72]=Ee,t[73]=De);let Oe=De,ke;t[74]!==V?.status||t[75]!==Te||t[76]!==r||t[77]!==p?(ke=V?.status===`loading`||p.isLoading(r,Te),t[74]=V?.status,t[75]=Te,t[76]=r,t[77]=p,t[78]=ke):ke=t[78];let Ae=ke,je;t[79]!==m||t[80]!==h||t[81]!==r?(je=[`context-panel-load-older`,h,m,r],t[79]=m,t[80]=h,t[81]=r,t[82]=je):je=t[82];let Me;t[83]!==Ee||t[84]!==r||t[85]!==u?(Me=async()=>{Ee.kind===`unknown`&&await Ue(u,r),await qe(u,r)},t[83]=Ee,t[84]=r,t[85]=u,t[86]=Me):Me=t[86];let Ne;t[87]!==je||t[88]!==Me?(Ne={mutationKey:je,mutationFn:Me},t[87]=je,t[88]=Me,t[89]=Ne):Ne=t[89];let K=nt(Ne),Pe=K.isPending,Fe;t[90]!==Ae||t[91]!==Oe||t[92]!==Pe||t[93]!==K||t[94]!==ie||t[95]!==d||t[96]!==_?(Fe=()=>{if(!Fm(Oe,Pe||Ae)||K.isPending)return;let e=b.current+1;b.current=e;let t=ie.current,n=t?Rm({hasMore:Oe,isLoading:Pe,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,K.mutateAsync().then(()=>{S(e)},()=>{S(e),X.error(d(`chat.history.loadOlderFailed`))})},t[90]=Ae,t[91]=Oe,t[92]=Pe,t[93]=K,t[94]=ie,t[95]=d,t[96]=_,t[97]=Fe):Fe=t[97];let Ie=_t(Fe),Le=V?.status===`error`?V.error:void 0,Re;t[98]!==a||t[99]!==N||t[100]!==re||t[101]!==E.length||t[102]!==Le?(Re=Em({directoryMatches:!0,requested:a,renderable:N,messageCount:E.length,working:re,error:Le}),t[98]=a,t[99]=N,t[100]=re,t[101]=E.length,t[102]=Le,t[103]=Re):Re=t[103];let ze=Re,Be;t[104]!==a||t[105]!==m||t[106]!==s||t[107]!==r||t[108]!==n?(Be={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:mi,navigateSession:s},t[104]=a,t[105]=m,t[106]=s,t[107]=r,t[108]=n,t[109]=Be):Be=t[109];let Ve=Be,He;t[110]!==de||t[111]!==Oe||t[112]!==Ie?(He=()=>{if(km(Oe)===`load-more`){Ie();return}de(`retry`)},t[110]=de,t[111]=Oe,t[112]=Ie,t[113]=He):He=t[113];let We=_t(He),Ge;t[114]!==V?.error||t[115]!==We||t[116]!==d||t[117]!==ze?(Ge=ze===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:V?.error}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,size:`xs`,onClick:We,children:d(`chat.history.retry`)})]}):null,t[114]=V?.error,t[115]=We,t[116]=d,t[117]=ze,t[118]=Ge):Ge=t[118];let Ke=Ge,Je;t[119]!==Oe||t[120]!==Pe||t[121]!==Ie||t[122]!==d?(Je=Im(Oe)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,size:`sm`,onClick:Ie,disabled:Pe,children:[Pe?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):null,d(`chat.history.loadOlder`)]})}):null,t[119]=Oe,t[120]=Pe,t[121]=Ie,t[122]=d,t[123]=Je):Je=t[123];let Ye=Je,Xe;t[124]===Symbol.for(`react.memo_cache_sentinel`)?(Xe=(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:Si},"aria-hidden":`true`}),t[124]=Xe):Xe=t[124];let q=Xe,Ze;t[125]===le?Ze=t[126]:(Ze=()=>le(`instant`),t[125]=le,t[126]=Ze);let Qe;t[127]!==ne||t[128]!==W||t[129]!==Pe||t[130]!==ae||t[131]!==ie||t[132]!==r||t[133]!==re||t[134]!==E||t[135]!==H||t[136]!==u||t[137]!==Ze||t[138]!==_?(Qe=(0,$.jsx)(Pr,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:re,activeStreamingMessageId:H,activeStreamingPhase:ne,onMessageContentChange:ae,getAnimationHandlers:W,isLoadingOlder:Pe,scrollToBottom:Ze,scrollRef:ie,directory:u,enableSendPark:!1}),t[127]=ne,t[128]=W,t[129]=Pe,t[130]=ae,t[131]=ie,t[132]=r,t[133]=re,t[134]=E,t[135]=H,t[136]=u,t[137]=Ze,t[138]=_,t[139]=Qe):Qe=t[139];let $e=Qe,et;t[140]===le?et=t[141]:(et=()=>le(`smooth`),t[140]=le,t[141]=et);let tt;t[142]!==ce||t[143]!==et?(tt=(0,$.jsx)(Ri,{visible:ce,onClick:et}),t[142]=ce,t[143]=et,t[144]=tt):tt=t[144];let rt=tt,it;t[145]!==o||t[146]!==c||t[147]!==d?(it=o?(0,$.jsxs)(Y,{type:`button`,variant:`outline`,size:`xs`,onClick:c,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":d(`chat.container.returnToParent.aria`),title:d(`chat.container.returnToParent.title`),children:[(0,$.jsx)(Z,{name:`arrow-left`,className:`h-4 w-4`}),d(`chat.container.returnToParent.label`)]}):null,t[145]=o,t[146]=c,t[147]=d,t[148]=it):it=t[148];let at;t[149]!==de||t[150]!==Ye||t[151]!==Ke||t[152]!==V?.error||t[153]!==ie||t[154]!==rt||t[155]!==$e||t[156]!==ze?(at=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:ze===`cold-loading`||ze===`working-empty`||ze===`authoritative-empty`||ze===`fatal-error`?(0,$.jsx)(Gm,{state:ze,error:V?.error,onRetry:()=>de(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(po,{ref:ie,className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll overlay-scrollbar-target`,observeMutations:!1,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:`relative min-h-full`,children:[Ke,Ye,$e,q]})}),rt]})}),t[149]=de,t[150]=Ye,t[151]=Ke,t[152]=V?.error,t[153]=ie,t[154]=rt,t[155]=$e,t[156]=ze,t[157]=at):at=t[157];let ot;t[158]!==k.agentName||t[159]!==k.modelId||t[160]!==k.providerId||t[161]!==j||t[162]!==B?(ot=B?(0,$.jsx)(ii,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[158]=k.agentName,t[159]=k.modelId,t[160]=k.providerId,t[161]=j,t[162]=B,t[163]=ot):ot=t[163];let st;t[164]!==r||t[165]!==n||t[166]!==it||t[167]!==at||t[168]!==ot?(st=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":r,"data-surface-id":n,children:[it,at,ot]}),t[164]=r,t[165]=n,t[166]=it,t[167]=at,t[168]=ot,t[169]=st):st=t[169];let ct;return t[170]!==Ve||t[171]!==st?(ct=(0,$.jsx)(ji.Provider,{value:Ve,children:st}),t[170]=Ve,t[171]=st,t[172]=ct):ct=t[172],ct},qm=e=>{let t=(0,fl.c)(22),n=rr(),{t:r}=wt(),i;t[0]===e.directory?i=t[1]:(i=dm(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===dm(n),s;t[2]!==a||t[3]!==e.active||t[4]!==e.onNavigateSession||t[5]!==e.sessionId||t[6]!==e.surfaceId?(s={kind:`panel`,surfaceId:e.surfaceId,sessionId:e.sessionId,directory:a,active:e.active,capabilities:mi,navigateSession:e.onNavigateSession},t[2]=a,t[3]=e.active,t[4]=e.onNavigateSession,t[5]=e.sessionId,t[6]=e.surfaceId,t[7]=s):s=t[7];let c=s;if(!o){let n=e.sessionId,i=e.surfaceId,a;t[8]===r?a=t[9]:(a=r(`chat.emptyState.opencodeUnreachable`),t[8]=r,t[9]=a);let o;t[10]===a?o=t[11]:(o=(0,$.jsx)(Gm,{state:`directory-mismatch`,onRetry:Ym,error:a}),t[10]=a,t[11]=o);let s;t[12]!==e.sessionId||t[13]!==e.surfaceId||t[14]!==o?(s=(0,$.jsx)(`div`,{className:`h-full`,"data-context-session-surface":`true`,"data-session-id":n,"data-surface-id":i,children:o}),t[12]=e.sessionId,t[13]=e.surfaceId,t[14]=o,t[15]=s):s=t[15];let l;return t[16]!==c||t[17]!==s?(l=(0,$.jsx)(ji.Provider,{value:c,children:s}),t[16]=c,t[17]=s,t[18]=l):l=t[18],l}let l;return t[19]!==e||t[20]!==n?(l=(0,$.jsx)(Km,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function Jm(e){return e.providers}function Ym(){}var Xm=e=>{let t=e.trim();if(!t)return`about:blank`;try{let e=new URL(t.includes(`://`)?t:`https://${t}`);return e.protocol!==`http:`&&e.protocol!==`https:`?`about:blank`:e.toString()}catch{return`about:blank`}},Zm=(e,t)=>{let n=Xm(e),r=n===`about:blank`?``:n;return!r||r===t?null:r},Qm=e=>!!e.isElectron&&!e.relayActive,$m=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},eh=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),th=e=>{if(!e||typeof e!=`object`)return!1;let t=e,n=t.bounds;return typeof t.tag==`string`&&typeof t.text==`string`&&typeof t.selector==`string`&&typeof t.path==`string`&&!!n&&typeof n?.x==`number`&&typeof n?.y==`number`&&typeof n?.width==`number`&&typeof n?.height==`number`&&$m(t.center)&&eh(t.attributes)&&eh(t.computedStyle)&&Array.isArray(t.ancestry)},nh=({pageUrl:e,viewport:t,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{let o=r.text.trim(),s=Object.entries(r.attributes).map(([e,t])=>`${e}="${t}"`).join(` `),c=r.computedStyle,l=r.bounds,u=r.center,d=a.replace(/[.:]+$/g,``),f=r.ancestry.map(e=>e.selectorPart).join(` > `);return[`${d}:`,`Page: ${e||`preview`}`,`Viewport: ${t.width}x${t.height}, DPR ${n}`,`Screenshot: ${i?`attached`:`not attached`}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,s?`- Attributes: ${s}`:null,`- Bounds: x=${Math.round(l.x)}, y=${Math.round(l.y)}, width=${Math.round(l.width)}, height=${Math.round(l.height)}`,`- Center: x=${Math.round(u.x)}, y=${Math.round(u.y)}`,`Styles: display=${c.display}; position=${c.position}; font=${c.fontWeight} ${c.fontSize} / ${c.lineHeight} ${c.fontFamily}; color=${c.color}; background=${c.backgroundColor}; z-index=${c.zIndex}`].filter(e=>typeof e==`string`).join(`
18
- `)},rh=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await j(`desktop_capture_page_rect`,{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw Error(`Desktop screenshot capture is not available`);let i=new Image;await new Promise((e,t)=>{i.onload=()=>e(),i.onerror=()=>t(Error(`Failed to load desktop preview screenshot`)),i.src=`data:${r.mime};base64,${r.base64}`});let a=Math.max(1,i.naturalWidth||r.width||Math.floor(n.width)),o=Math.max(1,i.naturalHeight||r.height||Math.floor(n.height)),s=Math.min(1,1200/a),c=document.createElement(`canvas`);c.width=Math.floor(a*s),c.height=Math.floor(o*s);let l=c.getContext(`2d`);if(!l)return null;l.scale(s,s),l.drawImage(i,0,0,a,o);let u=a/Math.max(1,n.width),d=o/Math.max(1,n.height);l.fillStyle=`rgba(37, 99, 235, 0.28)`,l.strokeStyle=`rgb(37, 99, 235)`,l.lineWidth=Math.max(2,2*u),l.fillRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d),l.strokeRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d);let f=await new Promise(e=>c.toBlob(e,`image/jpeg`,.82));return f?new File([f],`preview-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch(e){return console.warn(`[preview] failed to capture annotation screenshot:`,e),null}return await Ph(e,t)},ih=async(e,t,n,r,i,a)=>{if(!e)return null;try{let o=new Image;await new Promise((t,n)=>{o.onload=()=>t(),o.onerror=()=>n(Error(`Failed to load desktop browser screenshot`)),o.src=`data:image/jpeg;base64,${e}`});let s=Math.max(1,o.naturalWidth||t),c=Math.max(1,o.naturalHeight||n),l=Math.min(1,1200/s),u=document.createElement(`canvas`);u.width=Math.floor(s*l),u.height=Math.floor(c*l);let d=u.getContext(`2d`);if(!d)return null;d.scale(l,l),d.drawImage(o,0,0,s,c);let f=s/Math.max(1,r||s),p=c/Math.max(1,i||c);d.fillStyle=`rgba(37, 99, 235, 0.14)`,d.strokeStyle=`rgb(37, 99, 235)`,d.lineWidth=Math.max(2,2*f),d.fillRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p),d.strokeRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p);let m=await new Promise(e=>u.toBlob(e,`image/jpeg`,.82));return m?new File([m],`browser-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch{return null}},ah=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,oh=new Map,sh=new Map,ch=3e4,lh=e=>{let t=oh.get(e);return t?t.expiresAt-Date.now()<=ch?(oh.delete(e),null):t:null},uh=e=>{try{return new URL(e).origin}catch{return e}};function dh(e){let t=e.defaultView??window;try{let n=e.body?t.getComputedStyle(e.body).backgroundColor:``;if(n&&n!==`rgba(0, 0, 0, 0)`&&n!==`transparent`)return n;let r=t.getComputedStyle(e.documentElement).backgroundColor;if(r&&r!==`rgba(0, 0, 0, 0)`&&r!==`transparent`)return r}catch{}return`#ffffff`}var fh=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:ah),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),ph=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await fh(n)).split(`,`,2)[1]||``},mh=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},hh=(...e)=>{mh()&&[...e]},gh=(e,t=8)=>{let n=[];try{let r=e.querySelectorAll(`*`);for(let e of r){let r=e.scrollTop||0,i=e.scrollLeft||0;if(r<=0&&i<=0)continue;let a=e.tagName.toLowerCase(),o=e.id?`#${e.id}`:``,s=typeof e.className==`string`&&e.className?`.${e.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;if(n.push({selector:`${a}${o}${s}`,scrollTop:r,scrollLeft:i,clientWidth:e.clientWidth,clientHeight:e.clientHeight,scrollWidth:e.scrollWidth,scrollHeight:e.scrollHeight}),n.length>=t)break}}catch{}return n},_h=`data-yuri-fixed-pin`,vh=(e,t,n)=>{if(t<=0&&n<=0)return()=>{};let r=e.defaultView;if(!r)return()=>{};let i=[],a=[];try{for(let o of e.querySelectorAll(`*`)){if(r.getComputedStyle(o).position!==`fixed`)continue;let e=o.getBoundingClientRect();if(!(e.width>0&&e.height>0))continue;o.setAttribute(_h,JSON.stringify({top:e.top+n,left:e.left+t,width:e.width,height:e.height})),i.push(o);let s=o.tagName.toLowerCase(),c=typeof o.className==`string`&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;a.push({selector:`${s}${c}`,top:Math.round(e.top),left:Math.round(e.left),width:Math.round(e.width),height:Math.round(e.height)})}}catch{}return hh(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(_h)}catch{}}},yh={name:`yuri-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${_h}]`)){let t;try{t=JSON.parse(e.getAttribute(_h)||``)}catch{continue}e.style.setProperty(`position`,`absolute`,`important`),e.style.setProperty(`top`,`${t.top}px`,`important`),e.style.setProperty(`left`,`${t.left}px`,`important`),e.style.setProperty(`right`,`auto`,`important`),e.style.setProperty(`bottom`,`auto`,`important`),e.style.setProperty(`width`,`${t.width}px`,`important`),e.style.setProperty(`height`,`${t.height}px`,`important`),e.removeAttribute(_h)}}},bh=`data-yuri-scroll-pin`,xh=e=>{let t=[],n=gh(e,64);try{let n=e.documentElement,r=e.body;for(let i of e.querySelectorAll(`*`)){let e=i.scrollTop||0,a=i.scrollLeft||0;if(e<=0&&a<=0)continue;let o=i!==n&&i!==r;o&&i.setAttribute(bh,JSON.stringify({top:e,left:a})),t.push({el:i,top:e,left:a,tagged:o})}}catch{}return{reapply:()=>{for(let e of t)try{e.el.scrollHeight,e.el.scrollTop!==e.top&&(e.el.scrollTop=e.top),e.el.scrollLeft!==e.left&&(e.el.scrollLeft=e.left)}catch{}},cleanup:()=>{for(let e of t)if(e.tagged)try{e.el.removeAttribute(bh)}catch{}},snapshot:n}},Sh={name:`yuri-nested-scroll`,afterClone(e){let t=e?.clone;if(!t||typeof t.querySelectorAll!=`function`)return;let n=t.ownerDocument;if(n)for(let e of t.querySelectorAll(`[${bh}]`)){let t;try{t=JSON.parse(e.getAttribute(bh)||``)}catch{e.removeAttribute(bh);continue}let r=`translate(${-t.left}px, ${-t.top}px)`,i=e.children.length===1&&e.firstElementChild instanceof HTMLElement&&e.firstElementChild.style.willChange===`transform`?e.firstElementChild:null;if(i)i.style.transform=r;else{e.style.overflow=`hidden`;let t=n.createElement(`div`);for(t.style.transform=r,t.style.willChange=`transform`,t.style.display=`inline-block`,t.style.width=`100%`;e.firstChild;)t.appendChild(e.firstChild);e.appendChild(t)}e.removeAttribute(bh)}}},Ch=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await fh(await n.blob()):null}catch{return null}},wh=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=lh(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=sh.get(t),i=r??(async()=>{try{let n=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return oh.delete(t),null;let r=await n.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i)return oh.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return oh.set(t,o),o}catch{return oh.delete(t),null}finally{sh.delete(t)}})();r||sh.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Th=async(e,t)=>{if(!e||e.startsWith(`data:`))return e;try{let n=new URL(e,t.baseURI);if(n.origin===window.location.origin||n.protocol!==`http:`&&n.protocol!==`https:`)return await Ch(n.toString(),`include`)??ah;let r=await wh(n);return(r?await Ch(r,`include`):null)||(await Ch(n.toString(),`omit`)??ah)}catch{return ah}},Eh=async(e,t)=>{if(!e||e===`none`||!e.includes(`url(`))return e;let n=Array.from(e.matchAll(/url\((['"]?)(.*?)\1\)/g)),r=e;for(let e of n){let n=e[2]||``;if(!n||n.startsWith(`data:`))continue;let i=await Th(n,t);r=r.replace(e[0],`url("${i}")`)}return r},Dh=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Oh=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},kh=e=>{let t=Number.parseFloat(e.lineHeight);if(Number.isFinite(t)&&t>0)return t;let n=Number.parseFloat(e.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},Ah=(e,t,n)=>{let r=[],i=e.defaultView??window,a=Array.from(e.querySelectorAll(`button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *`));for(let e of a){let a=e.textContent?.replace(/\s+/g,` `).trim()??``;if(!a||!a.includes(` `))continue;let o=e.getBoundingClientRect();if(o.width<=0||o.height<=0||o.right<0||o.bottom<0||o.left>t||o.top>n)continue;let s=i.getComputedStyle(e);if(s.display===`none`||s.visibility===`hidden`||Number(s.opacity)===0)continue;let c=s.getPropertyValue(`text-wrap`),l=s.getPropertyValue(`text-wrap-mode`),u=s.whiteSpace.includes(`nowrap`)||c===`nowrap`||l===`nowrap`,d=o.height<=kh(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Oh(e)),e.style.whiteSpace=`nowrap`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.setProperty(`text-wrap`,`nowrap`),e.style.setProperty(`text-wrap-mode`,`nowrap`))}return()=>{for(let e=r.length-1;e>=0;--e)r[e]?.()}},jh=(e,t,n,r)=>{let i=[],a=e.defaultView??window,o=a.scrollX||e.documentElement.scrollLeft||e.body?.scrollLeft||0,s=a.scrollY||e.documentElement.scrollTop||e.body?.scrollTop||0,c=Array.from(e.querySelectorAll(`*`)).filter(e=>{let r=a.getComputedStyle(e);if(r.position!==`fixed`||r.display===`none`||r.visibility===`hidden`||Number(r.opacity)===0)return!1;let i=e.getBoundingClientRect();return i.width>0&&i.height>0&&i.right>=0&&i.bottom>=0&&i.left<=t&&i.top<=n}).filter((e,t,n)=>!n.some((n,r)=>r<t&&n.contains(e)));for(let e of c){let t=e.getBoundingClientRect(),n=a.getComputedStyle(e),c=Math.ceil(t.width)+8,l=Math.ceil(t.height)+2;r?.add(e),i.push(Oh(e)),e.style.position=`absolute`,e.style.top=`${t.top+s}px`,e.style.left=`${t.left+o}px`,e.style.right=`auto`,e.style.bottom=`auto`,e.style.width=`${c}px`,e.style.minWidth=`${c}px`,e.style.height=`${l}px`,e.style.minHeight=`${l}px`,e.style.margin=`0`,e.style.boxSizing=`border-box`,e.style.transform=`none`,n.zIndex!==`auto`&&(e.style.zIndex=n.zIndex)}return()=>{for(let e=i.length-1;e>=0;--e)i[e]?.()}},Mh=async(e,t,n,r={})=>{let i=[],a=e.defaultView??window,o=r=>{if(r===e.documentElement||r===e.body)return!0;try{let e=r.getBoundingClientRect();return e.width>0&&e.height>0&&e.right>=0&&e.bottom>=0&&e.left<=t&&e.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){let r=new WeakSet;i.push(jh(e,t,n,r)),i.push(Ah(e,t,n))}let s=new Map;for(let t of Array.from(e.images))s.set(t,t.currentSrc||t.src||t.getAttribute(`src`)||``);let c=Array.from(e.querySelectorAll(`picture`));for(let e of c){let t=Array.from(e.querySelectorAll(`source`));if(t.length===0)continue;let n=t.map(e=>({source:e,srcset:e.getAttribute(`srcset`),sizes:e.getAttribute(`sizes`)}));i.push(()=>{for(let e of n)e.srcset===null?e.source.removeAttribute(`srcset`):e.source.setAttribute(`srcset`,e.srcset),e.sizes===null?e.source.removeAttribute(`sizes`):e.source.setAttribute(`sizes`,e.sizes)});for(let e of t)e.removeAttribute(`srcset`),e.removeAttribute(`sizes`)}let l=Array.from(e.images).filter(e=>o(e));await Promise.all(l.map(async t=>{let n=s.get(t)||t.currentSrc||t.src||t.getAttribute(`src`)||``;if(!n)return;await Dh(t);let r=await Th(n,e),a={src:t.getAttribute(`src`),srcset:t.getAttribute(`srcset`),sizes:t.getAttribute(`sizes`)};i.push(()=>{a.src===null?t.removeAttribute(`src`):t.setAttribute(`src`,a.src),a.srcset===null?t.removeAttribute(`srcset`):t.setAttribute(`srcset`,a.srcset),a.sizes===null?t.removeAttribute(`sizes`):t.setAttribute(`sizes`,a.sizes)}),t.removeAttribute(`srcset`),t.removeAttribute(`sizes`),t.setAttribute(`src`,r||ah),await Dh(t)}));let u=Array.from(e.querySelectorAll(`*`)).filter(o);return await Promise.all(u.map(async t=>{let n=a.getComputedStyle(t).backgroundImage;if(!n||n===`none`||!n.includes(`url(`))return;let r=await Eh(n,e);if(r===n)return;let o=t.style.backgroundImage;i.push(()=>{t.style.backgroundImage=o}),t.style.backgroundImage=r})),()=>{for(let e=i.length-1;e>=0;--e)try{i[e]?.()}catch{}}};async function Nh(e,t){try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=r.body,l=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,u=n.scrollX||0,d=n.scrollY||0,f=n.pageXOffset||0,p=n.pageYOffset||0,m=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,h=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=i.scrollLeft||0,_=i.scrollTop||0,v=c?.scrollLeft||0,y=c?.scrollTop||0,b=l?.scrollLeft||0,x=l?.scrollTop||0,S=Math.max(u,f,m,g,v,b),C=Math.max(d,p,h,_,y,x);hh(`scroll sources`,{windowScrollX:u,windowScrollY:d,pageScrollX:f,pageScrollY:p,visualViewportScrollX:m,visualViewportScrollY:h,rootScrollX:g,rootScrollY:_,bodyScrollX:v,bodyScrollY:y,scrollingElementScrollX:b,scrollingElementScrollY:x,scrollingElementTag:l?.tagName?.toLowerCase()??null,resolvedScrollX:S,resolvedScrollY:C,nestedScrolledElements:gh(r)});let w=Math.max(o,i.scrollWidth||0,c?.scrollWidth||0,Math.ceil(i.getBoundingClientRect().width||0)),T=Math.max(s,i.scrollHeight||0,c?.scrollHeight||0,Math.ceil(i.getBoundingClientRect().height||0)),E=Math.min(2,Math.max(1,window.devicePixelRatio||1)),D=i.style.scrollBehavior,O=c?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,c&&(c.style.scrollBehavior=`auto`);let k=xh(r);hh(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await Mh(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=vh(r,S,C),k.reapply();let e={backgroundColor:dh(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[yh,Sh],quality:.82,width:w},a=await(await cl(i,e)).toCanvas();if(!a.width||!a.height)return null;let c=a.width/Math.max(1,w),l=a.height/Math.max(1,T),u=Math.min(a.width,Math.max(1,Math.round(o*c))),d=Math.min(a.height,Math.max(1,Math.round(s*l))),f=Math.max(0,a.width-u),p=Math.max(0,a.height-d),m=Math.min(f,Math.max(0,Math.round(S*c))),h=Math.min(p,Math.max(0,Math.round(C*l)));hh(`capture geometry`,{viewportWidth:o,viewportHeight:s,captureWidth:w,captureHeight:T,canvasWidth:a.width,canvasHeight:a.height,xScale:c,yScale:l,sourceX:m,sourceY:h,sourceWidth:u,sourceHeight:d});let g=r.createElement(`canvas`);g.width=u,g.height=d;let _=g.getContext(`2d`);if(!_)return null;_.drawImage(a,m,h,u,d,0,0,u,d);let v=await ph(g,.82);return v?await ih(v,o,s,o,s,t):null}finally{j(),k.cleanup(),A(),n.scrollTo(S,C),k.reapply(),i.style.scrollBehavior=D,c&&(c.style.scrollBehavior=O)}}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot with snapDOM:`,e),null}}async function Ph(e,t){let n=await Nh(e,t);if(n)return n;try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=n.scrollX||r.documentElement.scrollLeft||r.body?.scrollLeft||0,l=n.scrollY||r.documentElement.scrollTop||r.body?.scrollTop||0,u=r.body,d=Math.max(s,i.scrollHeight||0,u?.scrollHeight||0),f=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=i.style.scrollBehavior,m=u?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,u&&(u.style.scrollBehavior=`auto`);let h=``,g=()=>{};try{await r.fonts?.ready.catch(()=>void 0),g=await Mh(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await ul(i).catch(()=>``);h=await ll(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:dh(r),imagePlaceholder:ah,fontEmbedCSS:e||void 0,style:{transform:`translate(${-c}px, ${-l}px)`,transformOrigin:`top left`,minWidth:`${o}px`,minHeight:`${d}px`},cacheBust:!0})}finally{g(),n.scrollTo(c,l),i.style.scrollBehavior=p,u&&(u.style.scrollBehavior=m)}let _=h.split(`,`,2)[1]||``;return _?await ih(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var Fh=/^[a-z][a-z\d+.-]*:\/\//i,Ih=`/api/preview/proxy/`,Lh=e=>{if(typeof e!=`string`||!e)return!1;let t=e.split(`?`,1)[0]||``;if(t.includes(`\\`)||t.includes(`\0`))return!1;try{let e=new URL(t,`http://127.0.0.1`);return e.hostname===`127.0.0.1`&&e.pathname.startsWith(Ih)}catch{return!1}},Rh=e=>{let t=typeof e.authenticatedAssetUrl==`string`?e.authenticatedAssetUrl:``;if(!t)return``;if(!e.relayActive)return t;let n=typeof e.gatewayOrigin==`string`?e.gatewayOrigin.trim():``;if(!n)return t;try{let e=new URL(n);if(e.protocol!==`http:`&&e.protocol!==`https:`||e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`)return t;let r=Fh.test(t)?new URL(t):new URL(t,`http://yuri.local`);return r.pathname.startsWith(Ih)?`${e.origin}${r.pathname}${r.search}${r.hash}`:t}catch{return t}},zh=`yuri:preview-gateway-request`,Bh=`yuri:preview-gateway-abort`,Vh=`yuri:preview-gateway-ws-open`,Hh=`yuri:preview-gateway-ws-message`,Uh=`yuri:preview-gateway-ws-close`,Wh=e=>typeof e==`function`,Gh=()=>{if(typeof window>`u`)return null;let e=window.__YURI_DESKTOP__?.previewGateway;return!e||!Wh(e.ensure)||!Wh(e.begin)||!Wh(e.push)||!Wh(e.end)||!Wh(e.abort)?null:e},Kh=()=>{if(typeof window>`u`)return null;let e=window.__YURI_DESKTOP__;return Wh(e?.listen)?e.listen:null},qh=()=>Gh()!==null,Jh=e=>{let t={};return e.forEach((e,n)=>{let r=n.toLowerCase();r!==`set-cookie`&&r!==`set-cookie2`&&r!==`content-length`&&r!==`content-encoding`&&(t[r]=e)}),t},Yh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId==`string`&&t.requestId.length>0&&typeof t.method==`string`&&typeof t.path==`string`&&Lh(t.path)},Xh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.requestId!=`string`||!t.requestId||typeof t.path!=`string`||!Lh(t.path)||t.protocols!==void 0&&(!Array.isArray(t.protocols)||!t.protocols.every(e=>typeof e==`string`)))},Zh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId!=`string`||!t.requestId||typeof t.binary!=`boolean`?!1:!!(typeof t.data==`string`||t.data instanceof ArrayBuffer||ArrayBuffer.isView(t.data))},Qh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId==`string`&&t.requestId.length>0&&typeof t.code==`number`&&typeof t.reason==`string`},$h=new Map,eg=new Map,tg=null,ng=[],rg=null,ig=()=>{for(let e of ng)try{e()}catch{}ng=[];for(let e of $h.values())try{e.abort()}catch{}$h.clear();for(let[e,t]of eg.entries()){eg.delete(e);try{t.close(1001,`gateway detach`)}catch{}}},ag=e=>{let t=e,n=``,r=e.indexOf(`?`);r>=0&&(t=e.slice(0,r),n=e.slice(r+1));let i=new URLSearchParams(n);i.delete(`yuri_url_token`);let a={};return i.forEach((e,t)=>{a[t]=e}),c().websocket(t,a)},og=async e=>{let t=Gh();if(!t)return;if(!o()){try{await t.abort(e.requestId)}catch{}return}let n=$h.get(e.requestId);n&&(n.abort(),$h.delete(e.requestId));let r=new AbortController;$h.set(e.requestId,r);try{let n=await _(e.path,{method:e.method||`GET`,signal:r.signal,credentials:`omit`,cache:`no-store`,redirect:`manual`});if(r.signal.aborted){try{await t.abort(e.requestId)}catch{}return}if(await t.begin({requestId:e.requestId,status:n.status,headers:Jh(n.headers)}),e.method.toUpperCase()===`HEAD`||!n.body){await t.end(e.requestId);return}let i=n.body.getReader();try{for(;;){if(r.signal.aborted){try{await i.cancel()}catch{}try{await t.abort(e.requestId)}catch{}return}let{done:n,value:a}=await i.read();if(n)break;if(!a||a.byteLength===0)continue;let o=a.byteOffset===0&&a.byteLength===a.buffer.byteLength?a:a.slice();await t.push(e.requestId,o)}await t.end(e.requestId)}catch(n){if(r.signal.aborted){try{await t.abort(e.requestId)}catch{}return}try{await t.abort(e.requestId)}catch{}throw n}}catch{if(!r.signal.aborted)try{await t.abort(e.requestId)}catch{}}finally{$h.delete(e.requestId)}},sg=(e,t=1e3,n=``)=>{let r=eg.get(e);if(r){eg.delete(e);try{r.close(t,n)}catch{}}},cg=async e=>{let t=Gh();if(!(!t||!Wh(t.wsOpened)||!Wh(t.wsSend)||!Wh(t.wsClose))){if(!o()){try{await t.wsClose(e.requestId,{code:1011,reason:`relay inactive`})}catch{}return}sg(e.requestId,1001,`replaced`);try{try{await r()}catch{}let n=ag(e.path),i=e.protocols&&e.protocols.length>0?e.protocols:void 0,a=Re(n,i);eg.set(e.requestId,a),a.onopen=()=>{eg.get(e.requestId)===a&&t.wsOpened?.({requestId:e.requestId}).catch(()=>{sg(e.requestId,1011,`wsOpened failed`)})},a.onmessage=n=>{if(eg.get(e.requestId)!==a)return;let r=n.data;if(typeof r==`string`){t.wsSend?.(e.requestId,r,!1).catch(()=>{});return}if(r instanceof ArrayBuffer){t.wsSend?.(e.requestId,r,!0).catch(()=>{});return}if(ArrayBuffer.isView(r)){let n=r,i=n.byteOffset===0&&n.byteLength===n.buffer.byteLength?n.buffer:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);t.wsSend?.(e.requestId,i,!0).catch(()=>{})}},a.onerror=()=>{},a.onclose=n=>{eg.get(e.requestId)===a&&eg.delete(e.requestId),t.wsClose?.(e.requestId,{code:typeof n?.code==`number`?n.code:1006,reason:typeof n?.reason==`string`?n.reason:``}).catch(()=>{})}}catch{try{await t.wsClose?.(e.requestId,{code:1011,reason:`tunnel open failed`})}catch{}}}},lg=e=>{if(e instanceof ArrayBuffer)return e;let t=e,n=new Uint8Array(t.byteLength);return n.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),n.buffer},ug=e=>{let t=eg.get(e.requestId);if(t)try{if(typeof e.data==`string`){t.send(e.data);return}let n=ArrayBuffer.isView(e.data)||e.data instanceof ArrayBuffer?lg(e.data):null;if(!n)return;if(!e.binary){t.send(new TextDecoder().decode(n));return}t.send(n)}catch{}},dg=e=>{sg(e.requestId,e.code,e.reason)},fg=e=>{let t=e?.payload;Yh(t)&&og(t)},pg=e=>{let t=e?.payload;if(!t||typeof t!=`object`)return;let n=t.requestId;if(typeof n!=`string`||!n)return;let r=$h.get(n);r&&(r.abort(),$h.delete(n))},mg=e=>{let t=e?.payload;Xh(t)&&cg(t)},hg=e=>{let t=e?.payload;Zh(t)&&ug(t)},gg=e=>{let t=e?.payload;Qh(t)&&dg(t)},_g=()=>tg||(tg=(async()=>{let e=Gh(),t=Kh();if(!e||!t){tg=null;return}ig();let n=async(e,n)=>{let r=await t(e,n);typeof r==`function`&&ng.push(r)};await n(zh,fg),await n(Bh,pg),await n(Vh,mg),await n(Hh,hg),await n(Uh,gg)})().catch(e=>{throw tg=null,e}),tg),vg=async()=>{if(!o())return null;let e=Gh();return e?(await _g(),rg||(rg=(async()=>{try{let t=await e.ensure(),n=typeof t?.origin==`string`?t.origin.trim():``;if(!n)return null;try{let e=new URL(n);if(e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`)return null}catch{return null}return n}catch{return null}finally{rg=null}})(),rg)):null},yg=380,bg=1400,xg=600,Sg=24,Cg=new Map,wg=200,Tg=(e,t)=>t===`all`?!0:t===`errors`?e.level===`error`||e.level===`runtime`||e.level===`resource`:t===`warnings`?e.level===`warn`:e.level===`log`||e.level===`info`||e.level===`debug`,Eg=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},Dg=e=>Number.isFinite(e)?Math.min(bg,Math.max(yg,Math.round(e))):xg,Og=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},kg=(e,t)=>{let n=Dg(e),r=Og(t);return r===null?n:Math.min(n,Math.max(1,r))},Ag=(e,t)=>{if(!e)return``;let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`).replace(/\/+$/,``);return r&&n.startsWith(r+`/`)?n.slice(r.length+1):n},jg=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`btw`?`chat.btw.title`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),Mg=e=>{if(!e)return null;let t=e.replace(/\\/g,`/`).trim();if(!t)return null;let n=t.split(`/`).filter(Boolean);return n.length===0?t:n[n.length-1]||null},Ng=(e,t,n)=>{if(e.mode===`chat`){let r=Fg(e.dedupeKey);if(r){let e=t.get(r)?.trim();if(e)return e}return e.sessionTitleFallback?.trim()||n(`contextPanel.mode.chat`)}if(e.label)return e.label;if(e.mode===`file`)return Mg(e.targetPath)||n(`contextPanel.mode.files`);if(e.mode===`preview`){let t=e.targetPath;if(t)try{let e=new URL(t);return e.host||e.hostname||n(`contextPanel.mode.preview`)}catch{}return n(`contextPanel.mode.preview`)}return e.mode===`diff`?n(`contextPanel.mode.diff`):e.mode===`file-diff`?Mg(e.targetPath)||n(`contextPanel.mode.diff`):jg(e.mode,n)},Pg=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Bi,{filePath:e.targetPath,className:`h-3.5 w-3.5`}):void 0;if(e.mode===`diff`||e.mode===`file-diff`)return(0,$.jsx)(Z,{name:`arrow-left-right`,className:`h-3.5 w-3.5`});if(e.mode===`context`)return(0,$.jsx)(Z,{name:`file-list-2`,className:`h-3.5 w-3.5`});if(e.mode===`chat`)return(0,$.jsx)(Z,{name:`chat-thread`,className:`h-3.5 w-3.5`});if(e.mode===`preview`)return(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5 text-[var(--status-info)]`});if(e.mode===`browser`)return(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5`})},Fg=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,Ig=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},Lg=(e,t)=>{if(t.length===0)return Cg;let n=new Set(t),r=new Map;for(let t of e){if(!n.has(t.id))continue;let e=t.title?.trim();e&&r.set(t.id,e)}return r.size===0?Cg:r},Rg=(e,t)=>{let n=dn(e),r=Q.useRef(Cg),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=Lg(n.getState().session,i.current);return Ig(r.current,e)?r.current:(r.current=e,e)},[n]),()=>Cg)},zg=`new Promise((resolve) => {
17
+ `);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${K.name}:${i}`;In(K.path,a,r),Ln(P(a),`append-inline`),q.getState().setActiveMainTab(`chat`)},[In,kt,K,Ln]),Ti=!!(K&&(!gi||_i)&&!vi&&it.length>0),Ei=!!(K&&xi.length>0),Di=!!(K&&!Ie&&!gi&&!vi&&i.writeFile&&it.length<=mp),Oi=!!(K?.path&&xp(K.path)),ki=!!(K?.path&&Yo(K.path)),Ai=!!(K?.path&&$o(K.path)),ji=!!(K&&!gi&&!vi),Mi=ji&&!Oi&&!Ai&&!(ki&&ce===`preview`),Ni=Oi&&oe===`edit`||ki&&ce===`edit`||!Oi&&!ki&&ae===`edit`,Pi=Q.useMemo(()=>Pe?ys(Pe):null,[Pe]),[Fi,Ii]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=K?.path;if(!t||Pi){Ii(null);return}return Ii(null),fs(t).then(t=>{e||Ii(t)}),()=>{e=!0}},[K?.path,Pi]),Q.useEffect(()=>{!Di&&ae===`edit`&&W(`view`)},[Di,ae]);let Li=`yuri:files:md-viewer-mode`,Ri=`yuri:files:html-viewer-mode`;Q.useEffect(()=>{let e=K?.path;if(!e)return;W(pe.current[e]??`edit`);let t=yr?`preview`:`edit`;try{let e=localStorage.getItem(Li);(e===`preview`||e===`edit`)&&(t=e)}catch{}se(me.current[e]??t);let n=yr?`preview`:`edit`;try{let e=localStorage.getItem(Ri);(e===`preview`||e===`edit`)&&(n=e)}catch{}hr&&Yo(e)&&or===e&&(he.current[e]=hr,gr(null)),G(he.current[e]??n),ue(ge.current[e]??(yr?`preview`:`edit`))},[or,hr,K?.path,gr,yr]);let zi=Q.useCallback(e=>{let t=K?.path;t&&(pe.current[t]=e),W(e)},[K?.path]),Bi=Q.useCallback(e=>{let t=K?.path;t&&(me.current[t]=e),se(e);try{localStorage.setItem(Li,e)}catch{}},[K?.path]),Vi=Q.useCallback(()=>oe,[oe]),Hi=Q.useCallback(e=>{let t=K?.path;t&&(he.current[t]=e),G(e);try{localStorage.setItem(Ri,e)}catch{}},[K?.path]),Ui=Q.useCallback(e=>{let t=K?.path;if(t&&(ge.current[t]=e),Rt.current&&=(clearTimeout(Rt.current),null),Vt.current!==null&&(cancelAnimationFrame(Vt.current),Vt.current=null),e===`edit`)At(zt.current||it),ue(e);else{zt.current=kt;let e=t;ue(`edit`),Vt.current=requestAnimationFrame(()=>{Vt.current=requestAnimationFrame(()=>{Vt.current=null,!(y&&e&&bo.getState().byRoot[y]?.selectedPath!==e)&&(fe(e=>e+1),ue(`preview`))})});return}},[kt,it,y,K?.path]),Wi=Q.useCallback(async(e,t)=>{if(!i.writeFile||t===Bt.current)return!1;if(!(await i.writeFile(e,t))?.success)return X.error(r(`filesView.toast.writeFileFailed`)),!1;zt.current=t,Bt.current=t,At(t);let n=await Ur(e,ze).catch(()=>null);return n&&(Ut.current=n),!0},[i,Ur,ze,r]);Q.useEffect(()=>()=>{Rt.current&&=(clearTimeout(Rt.current),null),Vt.current!==null&&(cancelAnimationFrame(Vt.current),Vt.current=null)},[le,K?.path]);let Gi=Q.useCallback(e=>{if(zt.current=e,!K?.path||le!==`preview`||!i.writeFile)return;Rt.current&&clearTimeout(Rt.current);let t=K.path;Rt.current=setTimeout(()=>{Rt.current=null,Wi(t,e).then(e=>{e&&(Yt(!0),setTimeout(()=>Yt(!1),1500))}).catch(e=>{X.error(e instanceof Error?e.message:r(`filesView.toast.saveFailed`))})},qr)},[le,i.writeFile,Wi,K?.path,r]),Ki=Q.useMemo(()=>Ai&&(zt.current||kt)||it,[kt,it,Ai]),qi=Q.useCallback(()=>ce,[ce]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of be)pe.current[e]=`edit`,xp(e)&&(me.current[e]=t),Yo(e)&&(he.current[e]=t),$o(e)&&(ge.current[e]=t);W(`edit`),se(t),G(t),ue(t);try{localStorage.setItem(Li,t),localStorage.setItem(Ri,t)}catch{}},t=t=>{let n=!!t.detail?.enabled;e(n)};return window.addEventListener(`yuri:file-viewer-preview-mode-changed`,t),()=>{window.removeEventListener(`yuri:file-viewer-preview-mode-changed`,t)}},[be]),Q.useEffect(()=>{if(!ir||!y)return;let e=()=>{typeof window>`u`||dn.current===null&&(dn.current=window.requestAnimationFrame(()=>{dn.current=null,un(e=>e+1)}))},t=(e,t)=>{if(e.state.doc.length!==t.length)return!1;if(t.length===0)return!0;let n=Math.min(128,t.length);if(e.state.sliceDoc(0,n)!==t.slice(0,n))return!1;let r=Math.max(0,t.length-n);return e.state.sliceDoc(r,t.length)===t.slice(r)},n=tp(ir.path);if(Dt===n){Jr(n),fn.current={key:``,attempts:0};return}if(!n){ar(null),fn.current={key:``,attempts:0};return}let r=`${n}:${ir.line}:${ir.column??1}`;if(fn.current.key!==r&&(fn.current={key:r,attempts:0}),K?.path!==n){if(Qt)return;Qr(Ae(n));return}if(ft||St!==n)return;if(ht||gi||vi){ar(null),fn.current={key:``,attempts:0};return}if(!Di)return;if(ae!==`edit`){W(`edit`);return}let i=sn.current;if(!i){e();return}if(!t(i,kt)){e();return}let a=Math.max(1,Math.min(ir.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,ir.column||1),c=Math.max(0,o.to-o.from),l=Math.min(c,s-1),u=o.from+l;if(i.state.selection.main.head!==u||fn.current.attempts===0){fn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:mt.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=sn.current;e&&(e.dispatch({selection:{anchor:u},effects:mt.scrollIntoView(u,{y:`center`})}),e.focus())}),ar(null),fn.current={key:``,attempts:0}},[Di,Jr,Qt,kt,ln,ht,Dt,ft,gi,vi,St,Qr,ir,y,K?.path,ar,ae,Ae]),Q.useEffect(()=>{if(!or||!y)return;let e=tp(or);if(Dt===e){Jr(e);return}if(!e){cr(null);return}if(K?.path!==e){if(Qt)return;Qr(Ae(e));return}if(!(ft||St!==e||ht||gi||vi)){if(Di&&ae===`edit`){let e=sn.current;if(!e)return;e.focus()}cr(null)}},[Di,Jr,Qt,ht,Dt,ft,Qr,gi,vi,St,or,y,K?.path,cr,ae,Ae]);let Yi=Q.useCallback(e=>{if(!d||!e||!e.hasFocus||typeof window>`u`)return;let t=window.visualViewport;if(!t)return;let n=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,n-(t.offsetTop+t.height))<=0)return;let r=e.state.selection.main.head,i=e.coordsAtPos(r);if(!i)return;let a=Math.round(t.offsetTop+t.height),o=i.bottom+20-a;o<=0||(e.scrollDOM.scrollTop+=o)},[d]);Q.useEffect(()=>{if(!d||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{Yi(sn.current)})},t=window.visualViewport;return t?.addEventListener(`resize`,e),t?.addEventListener(`scroll`,e,{passive:!0}),document.addEventListener(`selectionchange`,e),()=>{t?.removeEventListener(`resize`,e),t?.removeEventListener(`scroll`,e),document.removeEventListener(`selectionchange`,e)}},[d,Yi]),Q.useEffect(()=>{if(ae!==`edit`||d)return;let e=Pa(`open_go_to_line`,_r),t=t=>{let n=t.target;if(n?.closest(`[role="dialog"]`))return;let r=!!n?.closest(`.cm-editor`);if(!(n?.closest(`input, textarea, [contenteditable="true"], [role="textbox"]`)&&!r||!document.activeElement?.closest(`.cm-editor`))){if(Ma(t,e)){t.preventDefault(),jn(!0);return}if(Ma(t,`mod+l`)){let e=sn.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),Ci())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[Ci,d,_r,ae]);let Xi=q(e=>e.editorFontSize),Zi=Q.useMemo(()=>{if(!K?.path)return[Fs(s,{fontSize:Xi})];let e=Zo(K.path),t=[Fs(s,e?{syntaxColors:!1,fontSize:Xi}:{fontSize:Xi})],n=Pi??Fi;return n&&t.push(n),e&&t.push(us({language:e,themeName:s.metadata.id,theme:Ao(s)})),M&&t.push(mt.lineWrapping),t.push(mt.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&Si(e.view)})),d&&t.push(mt.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{Yi(e.view)})})),t},[s,K?.path,Pi,Fi,M,d,Yi,Xi,Si]),Qi=Q.useMemo(()=>({light:_e.metadata.id,dark:ve.metadata.id}),[_e.metadata.id,ve.metadata.id]),$i=K?.path&&gi&&!a.isDesktop&&!_i?`${K.path}|${ze.allowOutsideWorkspace?`outside`:`workspace`}|${ze.outsideFileGrant??``}`:``,ea=K?.path&&vi?`${K.path}|${ze.allowOutsideWorkspace?`outside`:`workspace`}|${ze.outsideFileGrant??``}`:``,ta=a.isVSCode||o(),na=K?.path&&ki&&ce===`preview`&&!ta?K.path:``,ra=r(`filesView.error.readFileFailed`),{readyKey:ia,nonce:aa}=Tp($i,_t,ra),{readyKey:oa,nonce:sa}=Tp(na,_t,ra),{readyKey:ca,nonce:fa}=Tp(ea,_t,ra),ma=!!($i&&ia!==$i),ga=!!(na&&oa!==na),_a=!!(ea&&ca!==ea),va=K?.path&&gi?a.isDesktop?_i?`data:${Jo(K.path)};utf8,${encodeURIComponent(it)}`:yt:_i?`data:${Jo(K.path)};utf8,${encodeURIComponent(it)}`:ia===$i?st(`/api/fs/raw`,{path:K.path,allowOutsideWorkspace:ze.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:ze.outsideFileGrant,directory:y||void 0}).url:``:``,ya=vt(e=>{if(!K?.path||!gi)return;let t=_i?va:K.path||va;if(!t)return;let n=K.name||K.path;te({open:!0,title:n,content:``,previewSource:e.currentTarget.querySelector(`img`)??void 0,metadata:{tool:`image-preview`,filename:n,mime:Jo(K.path)},image:{url:t,mimeType:Jo(K.path),filename:n}})}),ba=Q.useCallback(e=>{te(t=>t.open===e?t:{...t,open:e})},[]),xa=Q.useCallback((e,t)=>{let n=e.name||r(`filesView.editor.imageAltFallback`);return(0,$.jsx)(`div`,{className:J(`flex items-center justify-center`,t?.fullHeight?`h-full p-4`:`h-full p-3`),children:(0,$.jsx)(`button`,{type:`button`,className:`max-h-full max-w-full cursor-zoom-in rounded-md border-0 bg-transparent p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:ya,"aria-label":n,disabled:!va,children:(0,$.jsx)(rs,{src:va,alt:n,className:J(`object-contain rounded-md border border-border/30 bg-primary/10`,t?.fullHeight?`max-h-full max-w-full`:`max-h-[70vh] max-w-full`),draggable:!1},aa)})})},[aa,va,ya,r]),Sa=K?.path&&vi&&ca===ea?st(`/api/fs/raw`,{path:K.path,allowOutsideWorkspace:ze.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:ze.outsideFileGrant,directory:y||void 0}).url:``,Ca=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:Sa,className:`h-full w-full border-0`,title:e.name},fa)}),[Sa,fa]);Q.useEffect(()=>{let e=!1,t=async()=>{if(!a.isDesktop||!K?.path||!gi||_i){xt.current&&=(URL.revokeObjectURL(xt.current),``),bt(``);return}_t(null),xt.current&&=(URL.revokeObjectURL(xt.current),``),await(async()=>{let t=await ct({path:K.path,...ze,directory:y||void 0,signal:n.signal});if(!t.ok)throw Error(r(`filesView.error.readFileFailed`));let i=await t.blob(),a=URL.createObjectURL(i);return e?(URL.revokeObjectURL(a),``):(xt.current=a,a)})().then(t=>{e||(bt(t),Et(K.path))}).catch(t=>{xt.current&&=(URL.revokeObjectURL(xt.current),``),e||(bt(``),_t(t instanceof Error?t.message:r(`filesView.error.readFileFailed`)),Et(null))}).finally(()=>{e||pt(!1)})},n=new AbortController;return t(),()=>{e=!0,n.abort()}},[i,gi,_i,y,a.isDesktop,K?.path,ze,r]),Q.useEffect(()=>()=>{xt.current&&=(URL.revokeObjectURL(xt.current),``)},[]);let wa=Q.useCallback(()=>mn(null),[]),Ta=Q.useMemo(()=>Tc({drafts:Cr,editingDraftId:Er,commentText:wr,onTextChange:Tr,selection:Xn,isDragging:tr,fileLabel:K?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Nr,onCancel:()=>{Zn(null),kr()},onEdit:e=>{jr(e),Zn({start:e.startLine,end:e.endLine})},onDelete:Mr,onAddToChat:wi}),[wi,kr,wr,Mr,Er,Cr,Nr,tr,Xn,K?.path,Tr,jr]),Ea=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(gt,{file:{name:e.name,contents:t,lang:Zo(e.path)||void 0},options:{disableFileHeader:!0,overflow:M?`wrap`:`scroll`,theme:Qi,themeType:s.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[s.metadata.variant,Qi,M]),Da=({exitFullscreenOnly:t=!1,layout:n=`floating`}={})=>{if(!K)return null;let a=n===`docked`?`pointer-events-auto flex flex-wrap items-center gap-1`:`pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm`,o=(e,t)=>(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[Di&&Ni&&(0,$.jsxs)($.Fragment,{children:[Mt?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-muted-foreground typography-meta`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-3.5 animate-spin`}),r(`filesView.editor.saving`)]}):Xt&&Kt===`saved`&&!Gr?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta`,children:[(0,$.jsx)(Z,{name:`check`,className:`size-3.5`}),r(`filesView.editor.saved`)]}):Gr?o(r(Xt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${jt()}+S`}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>void Kr(),className:`h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,title:r(Xt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${jt()}+S`}),"aria-label":r(`filesView.editor.saveAria`,{shortcut:`${jt()}+S`}),children:(0,$.jsx)(Z,{name:`save-3`,className:`size-4`})})):null,o(r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Zt(e=>!e),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Xt?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":r(Xt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Xt?(0,$.jsx)(Z,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(Z,{name:`file-check`,className:`size-4`})}))]}),ji&&Mn?o(`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ba(`mod+l`)})`,(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:Ci,className:`h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,title:`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ba(`mod+l`)})`,"aria-label":`${r(`chat.textSelection.title.addToCurrentChat`)} (${Ba(`mod+l`)})`,children:[(0,$.jsx)(Z,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{children:r(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(di,{shortcut:Ba(`mod+l`)})]})):null,(0,$.jsxs)(Ga,{onOpenChange:U,children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.openInDesktopApp`),"aria-label":r(`filesView.editor.openInDesktopApp`),children:(0,$.jsx)(Z,{name:`file-transfer`,className:`size-4`})})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(Ia,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Un.map(e=>(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>void Jn(e),children:[(0,$.jsx)($f,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),Wn?(0,$.jsxs)(ka,{className:`flex items-center gap-2`,onClick:()=>void Kn(!0),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:r(`filesView.editor.refreshApps`)})]}):null]})]}),!gi&&!vi&&(0,$.jsxs)($.Fragment,{children:[o(r(M?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>F(!M),className:J(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,M?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(M?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(Z,{name:`text-wrap`,className:`size-4`})})),ae===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(r(`filesView.editor.findInFile`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:e=>{z(!R),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.findInFile`),children:(0,$.jsx)(Z,{name:`search`,className:`size-4`})})),o(r(`filesView.editor.goToLine`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:e=>{jn(e=>!e),e.currentTarget.blur()},className:`size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.goToLine`),children:(0,$.jsx)(Z,{name:`menu-fold-2`,className:`size-4`})})),(0,$.jsx)(Xf,{open:An,onOpenChange:jn,view:sn.current,variant:`inline`})]})]}),Mi&&Di&&!ki&&(0,$.jsx)(vs,{currentMode:ae===`view`?`preview`:`edit`,onToggle:()=>{zi(ae===`view`?`edit`:`view`)}}),Oi&&o(r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Bi(Vi()===`preview`?`edit`:`preview`),className:J(`size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]`,Vi()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]`:`text-muted-foreground opacity-65 hover:opacity-100`),title:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Z,{name:Vi()===`preview`?`eye`:`eye-off`,className:`size-4`})})),Yo(K?.path??``)&&(0,$.jsx)(vs,{currentMode:qi(),onToggle:()=>{Hi(qi()===`preview`?`edit`:`preview`)}}),Oi&&Vi()===`preview`&&br&&(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent`,"aria-label":r(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{lt?dt():it.trim()&&ut(it)},children:lt?(0,$.jsx)(Z,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(da,{sideOffset:8,children:r(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),Ai&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(vs,{currentMode:le,onToggle:()=>Ui(le===`preview`?`edit`:`preview`)}),le===`preview`&&(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=Ht.current?.getXml();if(Rt.current&&=(clearTimeout(Rt.current),null),K?.path&&e){if(!await Wi(K.path,e))return;Yt(!0),setTimeout(()=>Yt(!1),1500)}},className:`size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.diagram.saveDiagram`),children:Jt?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`save-3`,className:`size-4`})})]}),Ti&&o(r(`filesView.editor.copyFileContents`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{(await wt(it)).ok?(Dn(!0),an.current!==null&&window.clearTimeout(an.current),an.current=window.setTimeout(()=>{Dn(!1)},1200)):X.error(r(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.copyFileContents`),"aria-label":r(`filesView.editor.copyFileContents`),children:En?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`clipboard`,className:`size-4`})})),Ei&&o(r(`filesView.editor.copyFilePathTitle`,{path:xi}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:async()=>{(await wt(xi)).ok?(kn(!0),on.current!==null&&window.clearTimeout(on.current),on.current=window.setTimeout(()=>{kn(!1)},1200)):X.error(r(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.copyFilePathTitle`,{path:xi}),"aria-label":r(`filesView.editor.copyFilePathTitle`,{path:xi}),children:On?(0,$.jsx)(Z,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(Z,{name:`file-copy-2`,className:`size-4`})})),i.downloadFile&&o(r(`filesView.editor.saveFile`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>{let e=i.downloadFile;e&&e(K.path).catch(e=>{console.error(`Download failed:`,e),X.error(r(`sidebarFilesTree.toast.operationFailed`))})},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.saveFile`),"aria-label":r(`filesView.editor.saveFile`),children:(0,$.jsx)(Z,{name:`download`,className:`size-4`})})),t?o(r(`filesView.editor.exitFullscreen`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(`filesView.editor.exitFullscreen`),"aria-label":r(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`size-4`})})):!d&&e===`full`&&o(r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!I),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":r(I?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:I?(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(Z,{name:`fullscreen`,className:`size-4`})}))]})},Oa=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(mr,{open:Qt,onOpenChange:e=>{e||ni()},children:(0,$.jsxs)(dr,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(lr,{children:[(0,$.jsx)(fr,{children:r(`filesView.unsaved.title`)}),(0,$.jsx)(pr,{children:r(`filesView.unsaved.description`)})]}),(0,$.jsxs)(ur,{children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ni,disabled:Mt,children:r(`filesView.dialog.cancel`)}),(0,$.jsx)(Y,{variant:`outline`,onClick:()=>void ti(),disabled:Mt,className:`border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,children:r(`filesView.unsaved.saveChanges`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:ei,disabled:Mt,children:r(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:J(`flex flex-col flex-shrink-0`,b&&`border-b border-border/40`),children:[b?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[d&&A&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>j(!1),"aria-label":r(`filesView.editor.back`),className:`inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:(0,$.jsx)(Z,{name:`arrow-left-s`,className:`size-5`})}),d?K?(0,$.jsxs)(Ga,{children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium`,"aria-label":r(`filesView.editor.openFilesAria`),children:[(0,$.jsx)(Ji,{filePath:K.path,extension:K.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(lp,{name:K.name}),(0,$.jsx)(Z,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ia,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:je.map(e=>{let t=K?.path===e.path;return(0,$.jsxs)(ka,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Qr(e)},className:J(`flex min-w-0 items-center justify-between gap-2 overflow-hidden`,t&&`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.jsx)(Ji,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(lp,{name:e.name})]}),(0,$.jsx)(`button`,{type:`button`,"data-close-open-file":!0,onPointerDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.preventDefault(),t.stopPropagation(),ii(e.path)},className:`inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,"aria-label":r(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Z,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:r(`filesView.editor.selectFile`)}):je.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[Ve.left&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent`}),Ve.right&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent`}),(0,$.jsx)(`div`,{ref:Be,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:je.map(e=>{let t=K?.path===e.path;return(0,$.jsxs)(`div`,{title:op(y,e.path),className:J(`group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap`,t?`bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]`:`bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]`),children:[(0,$.jsx)(Ji,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Qr(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),ii(e.path)},className:J(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!m&&`opacity-0 group-hover:opacity-100`),"aria-label":r(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(Z,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:r(`filesView.editor.selectFile`)})]}):null,xr&&!d&&K?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1`,children:[xi?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:xi,children:xi}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:Da({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[K&&!R&&!(xr&&!d)&&(0,$.jsx)(`div`,{ref:ne,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{re.current>0||ee(!1)},children:B?Da():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Oi?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Bi(Vi()===`preview`?`edit`:`preview`),className:J(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Vi()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(Z,{name:Vi()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(Vi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>ee(!0),children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>ee(!0),className:`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground`,"aria-label":r(`filesView.editor.showControlsAria`),title:r(`filesView.editor.controlsTitle`),children:(0,$.jsx)(Z,{name:`more-2-fill`,className:`size-4`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(mo,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:K?ft||ma||_a?gi?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-3`,children:(0,$.jsx)(ns,{className:`size-48 max-w-full rounded-md`})}):S?(0,$.jsx)(`div`,{className:`p-3`}):(0,$.jsxs)(`div`,{className:`p-3 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.loading`)]}):ht?(0,$.jsxs)(`div`,{role:`alert`,className:`p-3 typography-ui text-[color:var(--status-error)]`,children:[(0,$.jsx)(`div`,{children:ht}),Dt===Pe&&(0,$.jsx)(Y,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:ri,children:r(`contextPanel.preview.actions.retry`)})]}):gi&&K?xa(K):vi?Ca(K):K&&Ai&&le===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(nl,{ref:Ht,xml:Ki,onChange:Gi},`${K.path}:${de}`)}):K&&Oi&&Vi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:r(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(ha,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:r(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:r(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mo,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):K&&ki&&ce===`preview`?ga?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground typography-ui-label`,children:r(`common.loading`)}):(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(`iframe`,{src:!ta&&oa===na?(()=>{let e=K.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return st(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`).url})():void 0,srcDoc:ta?(()=>{if(!a.isVSCode)return it;let e=K.path.substring(0,K.path.lastIndexOf(`/`)+1);return e?it.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):it})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:r(`filesView.editor.htmlPreviewTitle`)},sa)}):K&&Mi&&ae===`view`?Ea(K,kt):(0,$.jsxs)(`div`,{className:J(`relative h-full`,bi&&`overflow-hidden`),ref:cn,children:[(0,$.jsx)(`div`,{className:J(`h-full`,bi&&`invisible`),children:(0,$.jsx)(ds,{value:kt,onChange:At,readOnly:!Di,vimMode:vr===`vim`,extensions:Zi,className:`h-full`,blockWidgets:Ta,onViewReady:e=>{sn.current=e,Si(e),un(e=>e+1),window.requestAnimationFrame(()=>{Yi(e)})},onViewDestroy:()=>{sn.current&&=null,Nn(!1),Fn(null),un(e=>e+1)},enableSearch:!0,searchOpen:R,onSearchOpenChange:z,highlightLines:Xn?{start:Math.min(Xn.start,Xn.end),end:Math.max(Xn.start,Xn.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.button!==0)return!1;n.preventDefault();let r=e.state.doc.lineAt(t.from).number;if(Xn&&!n.shiftKey&&Math.min(Xn.start,Xn.end)===r&&Math.max(Xn.start,Xn.end)===r)return Zn(null),kr(),$n.current=!1,er.current=null,nr(!1),!0;if(d&&Xn&&!n.shiftKey){let e=Math.min(Xn.start,Xn.end,r),t=Math.max(Xn.start,Xn.end,r);return Zn({start:e,end:t}),$n.current=!1,er.current=null,nr(!1),!0}if($n.current=!0,er.current=r,nr(!0),Xn&&n.shiftKey){let e=Math.min(Xn.start,r),t=Math.max(Xn.end,r);Zn({start:e,end:t})}else Zn({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!$n.current||er.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(er.current,r),a=Math.max(er.current,r);return Zn({start:i,end:a}),nr(!0),!1},mouseup:()=>($n.current=!1,er.current=null,nr(!1),!1)}}})}),bi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.openingFileAtChange`)]})})]}):(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:r(`filesView.editor.pickFileFromTree`)})})]})]}),Aa=!!(y&&Ge[y]),ja=y?qe[y]:null,Na=(0,$.jsxs)(`section`,{className:J(`flex min-h-0 flex-col overflow-hidden`,d?`h-full w-full bg-background`:`h-full rounded-xl border border-border/60 bg-background/70`),children:[(0,$.jsx)(`div`,{className:J(`flex flex-col gap-2 py-2`,d?`px-3`:`px-2`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`}),(0,$.jsx)(la,{ref:k,value:E,onChange:e=>D(e.target.value),placeholder:r(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),E.trim().length>0&&(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`filesView.tree.search.clearAria`),className:`absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground`,onClick:()=>{D(``),k.current?.focus()},children:(0,$.jsx)(Z,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Yn(`createFile`,{path:v,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.newFileTitle`),"aria-label":r(`filesView.tree.actions.newFileTitle`),children:(0,$.jsx)(Z,{name:`file-add`,className:`size-4`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>Yn(`createFolder`,{path:v,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.newFolderTitle`),"aria-label":r(`filesView.tree.actions.newFolderTitle`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`size-4`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>void Ir(),className:`size-8 p-0 flex-shrink-0`,title:r(`filesView.tree.actions.refreshTitle`),"aria-label":r(`filesView.tree.actions.refreshTitle`),children:(0,$.jsx)(Z,{name:`refresh`,className:`size-4`})})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:pi,disabled:ci.length===0&&Se.length===0,className:`size-8 flex-shrink-0 p-0`,title:r(fi?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":r(fi?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(Z,{name:fi?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:6,children:r(fi?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(mo,{outerClassName:`flex-1 min-h-0`,className:J(`py-2`,d?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:nt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.tree.search.searching`)]}):et.length>0?et.map(e=>{let t=K?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Qr(e),className:J(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors`,t?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`),children:[bp(e.path,e.extension),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta`,style:{direction:`rtl`,textAlign:`left`},title:e.path,children:e.relativePath??e.path})]})},e.path)}):ja?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-[var(--status-error)]`,children:ja}),(0,$.jsxs)(Y,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void Ir(),children:[(0,$.jsx)(Z,{name:`refresh`,className:`size-3.5`}),r(`filesView.tree.actions.refreshTitle`)]})]}):Aa?hi(y,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:r(`filesView.state.loading`)})})})]}),Fa=e===`full`&&I&&K&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col bg-background`,children:(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-30`,children:Da({exitFullscreenOnly:!0})}),(0,$.jsx)(mo,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:ft||ma||_a?gi?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(ns,{className:`size-48 max-w-full rounded-md`})}):S?(0,$.jsx)(`div`,{className:`p-4`}):(0,$.jsxs)(`div`,{className:`p-4 flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),`Loading…`]}):ht?(0,$.jsxs)(`div`,{role:`alert`,className:`p-4 typography-ui text-[color:var(--status-error)]`,children:[(0,$.jsx)(`div`,{children:ht}),Dt===Pe&&(0,$.jsx)(Y,{variant:`outline`,size:`sm`,className:`mt-2`,onClick:ri,children:r(`contextPanel.preview.actions.retry`)})]}):gi?xa(K,{fullHeight:!0}):vi?Ca(K):Oi&&Vi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:r(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(ha,{fallback:(0,$.jsxs)(`div`,{className:`rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 font-medium text-destructive`,children:r(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:r(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(Mo,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):Mi&&ae===`view`?Ea(K,kt):(0,$.jsxs)(`div`,{className:J(`relative h-full`,bi&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:J(`h-full`,bi&&`invisible`),children:(0,$.jsx)(ds,{value:kt,onChange:At,readOnly:!Di,vimMode:vr===`vim`,extensions:Zi,className:`h-full`,onViewReady:e=>{sn.current=e,Si(e),window.requestAnimationFrame(()=>{Yi(e)})},onViewDestroy:()=>{sn.current&&=null,Nn(!1),Fn(null)}})}),bi&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center bg-background`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-ui text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}),r(`filesView.state.openingFileAtChange`)]})})]})})]})});return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 overflow-hidden bg-background relative`,children:[(0,$.jsx)(Cp,{activeDialog:pn,dialogData:hn,dialogInputValue:_n,onDialogInputChange:vn,isDialogSubmitting:yn,onDialogSubmit:Vr,onClose:wa,inputRef:It}),Fa,Pn?(0,$.jsx)(Pc,{position:Pn,onDismiss:()=>Fn(null),onAddToChat:Ci}):null,H.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Zf,{popup:H,onOpenChange:ba,isMobile:d})}):null,d?A?Oa:Na:e===`editor-only`?(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden bg-background`,children:Oa})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[p>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:Na}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:Oa})]})]})};function Dp(e){return e+1}var Op=e=>e,kp=e=>{let t=Op(e).type;return typeof t==`string`?t:``},Ap=e=>{let t=Op(e).tool;return typeof t==`string`?t:``},jp=e=>{let t=Op(e).text;return typeof t==`string`?t:``},Mp=e=>{let t=kp(e);return t===`tool`?Ap(e).trim().toLowerCase()||`tool`:t||`unknown`},Np=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=Mp(n);t.includes(e)||t.push(e)}return t.join(` + `)},Pp=e=>e.replace(/\s+/g,` `).trim(),Fp=e=>{for(let t of e)if(kp(t)===`text`){let e=Pp(jp(t));if(e.length===0)continue;return e}let t=e.filter(e=>kp(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},Ip=(e,t,n)=>`${n(e)} / ${n(t)}`,Lp=(e,t,n,r)=>{let i=Ip(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},Rp=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},zp=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=Rp(t);return new Date(e).toLocaleString(void 0,{month:`numeric`,day:`numeric`,hour:n===!1?`2-digit`:`numeric`,minute:`2-digit`,...n===void 0?{}:{hour12:n}})},Bp={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Vp={user:0,assistant:0,tool:0,other:0},Hp=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,Up=e=>{let t=e.info.tokens,n=t===void 0?e.parts.find(e=>e.tokens!==void 0)?.tokens:t;if(typeof n==`number`)return{...Bp,total:Hp(n)};if(!n||typeof n!=`object`)return Bp;let r=n,i=Hp(r.input),a=Hp(r.output),o=Hp(r.reasoning),s=Hp(r.cache?.read),c=Hp(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},Wp=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},Gp=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+Gp(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+Gp(t),0):0,Kp=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...Vp,assistant:Gp(n.text)+Gp(n.content)};let i=Wp(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:Gp(n.input)+Gp(n.output)+Gp(n.error)+Gp(n.call?.input)+Gp(n.call?.output)+Gp(n.call?.error)+Gp(n.raw)+Math.round(Gp(n.metadata)*.25)+Math.round(Gp(n.state)*.1),other:0}:t===`user`?{user:i.length,assistant:0,tool:0,other:0}:t===`assistant`?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},qp=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),Jp=e=>{let t=Zr(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},Yp=(e,t)=>{if(e.length===0)return{...Vp};let n=e.reduce((e,t)=>{let n=Jp(t),r={...Vp};for(let e of t.parts)r=qp(r,Kp(e,n));return qp(e,r)},{...Vp});return n.user+=t.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)}},Xp=e=>e.toLocaleString(Mt()),Zp=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(Mt(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(Mt(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),Qp=(e,t)=>!e||!Number.isFinite(e)?`-`:va(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),$p=(e,t,n)=>{let r=e.find(e=>e.id===t),i=r?.models?.find(e=>e.id===n);return{providerName:r?.name||t||`-`,modelName:i?.name||n||`-`,contextLimit:typeof i?.limit?.context==`number`?i.limit.context:null}},em=()=>{let e=(0,pl.c)(262),{t}=Tt(),n=q(tm),r=q(nm),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={},e[0]=i):i=e[0];let[a,o]=Q.useState(i),[s,c]=Q.useState(null),l=Q.useRef(null),u=Sn(rm),d=Xn(),f=Kn(u??``),p=Qn(im),m;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(am),c(null)},e[1]=m):m=e[1];let h;e[2]===u?h=e[3]:(h=[u],e[2]=u,e[3]=h),Q.useEffect(m,h);let g,_;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},_=[],e[4]=g,e[5]=_):(g=e[4],_=e[5]),Q.useEffect(g,_);let v;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=async(e,t)=>{(await wt(t)).ok?(c(e),l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{c(t=>t===e?null:t),l.current=null},2e3)):c(null)},e[6]=v):v=e[6];let y=v,b;e[7]!==u||e[8]!==d?(b=u?d.find(e=>e.id===u)??null:null,e[7]=u,e[8]=d,e[9]=b):b=e[9];let x=b,S,C,w,T,E,D,O,k,A;if(e[10]!==p||e[11]!==f||e[12]!==r){S=f.filter(om);let t;e[22]===f?t=e[23]:(t=f.filter(sm),e[22]=f,e[23]=t),A=t;let n=r?Yr(f):null,i=null;for(let e=S.length-1;e>=0;--e){let t=S[e];if(Up(t).total>0){i=t;break}}O=i?Up(i):Bp,w=Si({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=S.reduce(cm,0),C=new Map;let a=[];for(let e of n?.turns??[]){let t=e.assistantMessages.map(lm),n=Ur(t);for(let t=0;t<n.length;t+=1){let r=n[t],i=e.assistantMessageIds[t];r!==null&&i&&C.set(i,Kr(r))}let r=n[n.length-1]??null;e.completionDisposition!==`active`&&r!==null&&a.push(...t)}let o=ti(a);E=o===null?null:Kr(o);let s=i?n?.indexes.messageToTurnId.get(i.info.id):void 0,c=s?n?.indexes.turnById.get(s):void 0,l=c?.assistantMessageIds[c.assistantMessageIds.length-1];T=l?C.get(l)??null:null;let u=i?.info??null;D=$p(p,u?.providerID||``,u?.modelID||``),e[10]=p,e[11]=f,e[12]=r,e[13]=S,e[14]=C,e[15]=w,e[16]=T,e[17]=E,e[18]=D,e[19]=O,e[20]=k,e[21]=A}else S=e[13],C=e[14],w=e[15],T=e[16],E=e[17],D=e[18],O=e[19],k=e[20],A=e[21];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===f?P=e[25]:(P=Yp(f,[...f].reverse().find(um)?.info?.system||``),e[24]=f,e[25]=P);let F=P,I=F.user,L=F.assistant,R=F.tool,z=Math.max(0,O.input-I-L-R),B=I+L+R+z,V=f[0]?.info?.time?.created,ee=f.length>0?f[f.length-1]?.info?.time?.created:null,H;e[26]!==x?.title||e[27]!==t?(H=x?.title||t(`contextSidebar.session.untitled`),e[26]=x?.title,e[27]=t,e[28]=H):H=e[28];let te=x?.time?.created??V??null,ne=ee??x?.time?.created??null,re=E&&E.length>0?E:null,U=T&&T.length>0?T:null,ie;e[29]!==L||e[30]!==z||e[31]!==R||e[32]!==I?(ie={user:I,assistant:L,tool:R,other:z},e[29]=L,e[30]=z,e[31]=R,e[32]=I,e[33]=ie):ie=e[33];let ae;e[34]!==S.length||e[35]!==C||e[36]!==B||e[37]!==w||e[38]!==M||e[39]!==j||e[40]!==f.length||e[41]!==te||e[42]!==ne||e[43]!==re||e[44]!==U||e[45]!==ie||e[46]!==H||e[47]!==O||e[48]!==k||e[49]!==N||e[50]!==A.length?(ae={sessionTitle:H,messagesCount:f.length,userMessagesCount:A.length,assistantMessagesCount:S.length,createdAt:te,lastActivityAt:ne,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,assistantTpsByMessageID:C,sessionTpsLabel:re,lastAssistantTpsLabel:U,contextLimit:M,breakdown:ie,breakdownTotal:B},e[34]=S.length,e[35]=C,e[36]=B,e[37]=w,e[38]=M,e[39]=j,e[40]=f.length,e[41]=te,e[42]=ne,e[43]=re,e[44]=U,e[45]=ie,e[46]=H,e[47]=O,e[48]=k,e[49]=N,e[50]=A.length,e[51]=ae):ae=e[51];let W=ae;if(!u){let n;e[52]===t?n=e[53]:(n=t(`contextSidebar.empty.openSession`),e[52]=t,e[53]=n);let r;return e[54]===n?r=e[55]:(r=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground`,children:n}),e[54]=n,e[55]=r),r}let oe;e[56]===t?oe=e[57]:(oe=t(`contextSidebar.breakdown.user`),e[56]=t,e[57]=oe);let se;e[58]!==oe||e[59]!==W.breakdown.user?(se={key:`user`,label:oe,value:W.breakdown.user,color:`var(--status-success)`},e[58]=oe,e[59]=W.breakdown.user,e[60]=se):se=e[60];let ce;e[61]===t?ce=e[62]:(ce=t(`contextSidebar.breakdown.assistant`),e[61]=t,e[62]=ce);let G;e[63]!==ce||e[64]!==W.breakdown.assistant?(G={key:`assistant`,label:ce,value:W.breakdown.assistant,color:`var(--primary-base)`},e[63]=ce,e[64]=W.breakdown.assistant,e[65]=G):G=e[65];let le;e[66]===t?le=e[67]:(le=t(`contextSidebar.breakdown.toolCalls`),e[66]=t,e[67]=le);let ue;e[68]!==le||e[69]!==W.breakdown.tool?(ue={key:`tool`,label:le,value:W.breakdown.tool,color:`var(--status-warning)`},e[68]=le,e[69]=W.breakdown.tool,e[70]=ue):ue=e[70];let de;e[71]===t?de=e[72]:(de=t(`contextSidebar.breakdown.other`),e[71]=t,e[72]=de);let fe;e[73]!==de||e[74]!==W.breakdown.other?(fe={key:`other`,label:de,value:W.breakdown.other,color:`var(--surface-muted-foreground)`},e[73]=de,e[74]=W.breakdown.other,e[75]=fe):fe=e[75];let pe;e[76]!==se||e[77]!==G||e[78]!==ue||e[79]!==fe?(pe=[se,G,ue,fe],e[76]=se,e[77]=G,e[78]=ue,e[79]=fe,e[80]=pe):pe=e[80];let me=pe,he;e[81]===W.sessionTitle?he=e[82]:(he=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:W.sessionTitle}),e[81]=W.sessionTitle,e[82]=he);let ge;e[83]!==W.providerModel.modelName||e[84]!==W.providerModel.providerName?(ge=(0,$.jsxs)(`span`,{children:[W.providerModel.providerName,` / `,W.providerModel.modelName]}),e[83]=W.providerModel.modelName,e[84]=W.providerModel.providerName,e[85]=ge):ge=e[85];let _e;e[86]!==n||e[87]!==W.createdAt?(_e=W.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:Qp(W.createdAt,n)})]}),e[86]=n,e[87]=W.createdAt,e[88]=_e):_e=e[88];let ve;e[89]!==ge||e[90]!==_e?(ve=(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70`,children:[ge,_e]}),e[89]=ge,e[90]=_e,e[91]=ve):ve=e[91];let ye;e[92]!==he||e[93]!==ve?(ye=(0,$.jsxs)(`div`,{className:`mb-6`,children:[he,ve]}),e[92]=he,e[93]=ve,e[94]=ye):ye=e[94];let be;e[95]===t?be=e[96]:(be=t(`contextSidebar.section.context`),e[95]=t,e[96]=be);let xe;e[97]===be?xe=e[98]:(xe=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:be}),e[97]=be,e[98]=xe);let Se;e[99]===W.tokenBreakdown.total?Se=e[100]:(Se=Xp(W.tokenBreakdown.total),e[99]=W.tokenBreakdown.total,e[100]=Se);let Ce;e[101]===W.contextLimit?Ce=e[102]:(Ce=W.contextLimit?` / ${Xp(W.contextLimit)}`:``,e[101]=W.contextLimit,e[102]=Ce);let we;e[103]!==Se||e[104]!==Ce?(we=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[Se,Ce]}),e[103]=Se,e[104]=Ce,e[105]=we):we=e[105];let Te;e[106]!==xe||e[107]!==we?(Te=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[xe,we]}),e[106]=xe,e[107]=we,e[108]=Te):Te=e[108];let Ee;e[109]===W.usagePercent?Ee=e[110]:(Ee=W.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[109]=W.usagePercent,e[110]=Ee);let De;e[111]===Ee?De=e[112]:(De=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:Ee}),e[111]=Ee,e[112]=De);let Oe;e[113]!==t||e[114]!==W.usagePercent?(Oe=t(`contextSidebar.context.percentUsed`,{percent:W.usagePercent.toFixed(1)}),e[113]=t,e[114]=W.usagePercent,e[115]=Oe):Oe=e[115];let ke;e[116]===Oe?ke=e[117]:(ke=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:Oe}),e[116]=Oe,e[117]=ke);let Ae;e[118]!==Te||e[119]!==De||e[120]!==ke?(Ae=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[Te,De,ke]}),e[118]=Te,e[119]=De,e[120]=ke,e[121]=Ae):Ae=e[121];let je;e[122]===t?je=e[123]:(je=t(`contextSidebar.stats.messages`),e[122]=t,e[123]=je);let Me;e[124]===W.messagesCount?Me=e[125]:(Me=Xp(W.messagesCount),e[124]=W.messagesCount,e[125]=Me);let Ne;e[126]!==je||e[127]!==Me?(Ne={label:je,value:Me},e[126]=je,e[127]=Me,e[128]=Ne):Ne=e[128];let K;e[129]===t?K=e[130]:(K=t(`contextSidebar.stats.user`),e[129]=t,e[130]=K);let Pe;e[131]===W.userMessagesCount?Pe=e[132]:(Pe=Xp(W.userMessagesCount),e[131]=W.userMessagesCount,e[132]=Pe);let Fe;e[133]!==K||e[134]!==Pe?(Fe={label:K,value:Pe},e[133]=K,e[134]=Pe,e[135]=Fe):Fe=e[135];let Ie;e[136]===t?Ie=e[137]:(Ie=t(`contextSidebar.stats.assistant`),e[136]=t,e[137]=Ie);let Le;e[138]===W.assistantMessagesCount?Le=e[139]:(Le=Xp(W.assistantMessagesCount),e[138]=W.assistantMessagesCount,e[139]=Le);let Re;e[140]!==Ie||e[141]!==Le?(Re={label:Ie,value:Le},e[140]=Ie,e[141]=Le,e[142]=Re):Re=e[142];let ze;e[143]!==Ne||e[144]!==Fe||e[145]!==Re?(ze=[Ne,Fe,Re],e[143]=Ne,e[144]=Fe,e[145]=Re,e[146]=ze):ze=e[146];let Be=ze,Ve;e[147]===Be?Ve=e[148]:(Ve=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:Be.map(dm)}),e[147]=Be,e[148]=Ve);let He=r?`grid-cols-2`:`grid-cols-1`,Ue;e[149]===He?Ue=e[150]:(Ue=J(`grid gap-2`,He),e[149]=He,e[150]=Ue);let We;e[151]===t?We=e[152]:(We=t(`contextSidebar.stats.cost`),e[151]=t,e[152]=We);let Ge;e[153]===We?Ge=e[154]:(Ge=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:We}),e[153]=We,e[154]=Ge);let Ke;e[155]===W.totalAssistantCost?Ke=e[156]:(Ke=Zp(W.totalAssistantCost),e[155]=W.totalAssistantCost,e[156]=Ke);let qe;e[157]===Ke?qe=e[158]:(qe=(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:Ke}),e[157]=Ke,e[158]=qe);let Je;e[159]!==Ge||e[160]!==qe?(Je=(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[Ge,qe]}),e[159]=Ge,e[160]=qe,e[161]=Je):Je=e[161];let Ye;e[162]!==r||e[163]!==t||e[164]!==W.sessionTpsLabel?(Ye=r?(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:t(`contextSidebar.stats.sessionTps`)}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:W.sessionTpsLabel??`—`})]}):null,e[162]=r,e[163]=t,e[164]=W.sessionTpsLabel,e[165]=Ye):Ye=e[165];let Xe;e[166]!==Ue||e[167]!==Je||e[168]!==Ye?(Xe=(0,$.jsxs)(`div`,{className:Ue,children:[Je,Ye]}),e[166]=Ue,e[167]=Je,e[168]=Ye,e[169]=Xe):Xe=e[169];let Ze;e[170]!==Ve||e[171]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Ve,Xe]}),e[170]=Ve,e[171]=Xe,e[172]=Ze):Ze=e[172];let Qe;e[173]===t?Qe=e[174]:(Qe=t(`contextSidebar.section.lastAssistantMessage`),e[173]=t,e[174]=Qe);let $e;e[175]===Qe?$e=e[176]:($e=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:Qe}),e[175]=Qe,e[176]=$e);let et;e[177]===t?et=e[178]:(et=t(`contextSidebar.tokens.input`),e[177]=t,e[178]=et);let tt;e[179]!==et||e[180]!==W.tokenBreakdown.input?(tt={label:et,value:W.tokenBreakdown.input,format:`count`},e[179]=et,e[180]=W.tokenBreakdown.input,e[181]=tt):tt=e[181];let nt;e[182]===t?nt=e[183]:(nt=t(`contextSidebar.tokens.output`),e[182]=t,e[183]=nt);let rt;e[184]!==nt||e[185]!==W.tokenBreakdown.output?(rt={label:nt,value:W.tokenBreakdown.output,format:`count`},e[184]=nt,e[185]=W.tokenBreakdown.output,e[186]=rt):rt=e[186];let it;e[187]===t?it=e[188]:(it=t(`contextSidebar.tokens.reasoning`),e[187]=t,e[188]=it);let at;e[189]!==it||e[190]!==W.tokenBreakdown.reasoning?(at={label:it,value:W.tokenBreakdown.reasoning,format:`count`},e[189]=it,e[190]=W.tokenBreakdown.reasoning,e[191]=at):at=e[191];let ot;e[192]===t?ot=e[193]:(ot=t(`contextSidebar.tokens.cacheRead`),e[192]=t,e[193]=ot);let st;e[194]!==ot||e[195]!==W.tokenBreakdown.cacheRead?(st={label:ot,value:W.tokenBreakdown.cacheRead,format:`count`},e[194]=ot,e[195]=W.tokenBreakdown.cacheRead,e[196]=st):st=e[196];let ct;e[197]===t?ct=e[198]:(ct=t(`contextSidebar.tokens.cacheWrite`),e[197]=t,e[198]=ct);let lt;e[199]!==ct||e[200]!==W.tokenBreakdown.cacheWrite?(lt={label:ct,value:W.tokenBreakdown.cacheWrite,format:`count`},e[199]=ct,e[200]=W.tokenBreakdown.cacheWrite,e[201]=lt):lt=e[201];let ut;e[202]===t?ut=e[203]:(ut=t(`contextSidebar.tokens.cacheHit`),e[202]=t,e[203]=ut);let dt=W.cacheHitRate.hasInput?W.cacheHitRate.percent:null,ft;e[204]!==ut||e[205]!==dt?(ft={label:ut,value:dt,format:`percent`},e[204]=ut,e[205]=dt,e[206]=ft):ft=e[206];let pt;e[207]!==r||e[208]!==t||e[209]!==W.lastAssistantTpsLabel?(pt=r?[{label:t(`contextSidebar.tokens.tps`),value:W.lastAssistantTpsLabel,format:`text`}]:[],e[207]=r,e[208]=t,e[209]=W.lastAssistantTpsLabel,e[210]=pt):pt=e[210];let mt;e[211]!==tt||e[212]!==rt||e[213]!==at||e[214]!==st||e[215]!==lt||e[216]!==ft||e[217]!==pt?(mt=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[tt,rt,at,st,lt,ft,...pt].map(fm)}),e[211]=tt,e[212]=rt,e[213]=at,e[214]=st,e[215]=lt,e[216]=ft,e[217]=pt,e[218]=mt):mt=e[218];let ht;e[219]!==$e||e[220]!==mt?(ht=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[$e,mt]}),e[219]=$e,e[220]=mt,e[221]=ht):ht=e[221];let gt;e[222]!==me||e[223]!==W.breakdownTotal?(gt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:me.map(e=>e.value<=0||W.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/W.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[222]=me,e[223]=W.breakdownTotal,e[224]=gt):gt=e[224];let _t;e[225]!==me||e[226]!==W.breakdownTotal?(_t=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:me.map(e=>{let t=W.breakdownTotal>0?e.value/W.breakdownTotal*100:0;return(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{backgroundColor:e.color}}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70`,children:[e.label,` `,(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[t.toFixed(0),`%`]})]})]},e.key)})}),e[225]=me,e[226]=W.breakdownTotal,e[227]=_t):_t=e[227];let vt;e[228]!==gt||e[229]!==_t?(vt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[gt,_t]}),e[228]=gt,e[229]=_t,e[230]=vt):vt=e[230];let yt;e[231]===t?yt=e[232]:(yt=t(`contextSidebar.section.rawMessages`),e[231]=t,e[232]=yt);let bt;e[233]===yt?bt=e[234]:(bt=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:yt}),e[233]=yt,e[234]=bt);let xt;if(e[235]!==s||e[236]!==a||e[237]!==f||e[238]!==r||e[239]!==t||e[240]!==n||e[241]!==W.assistantTpsByMessageID){let i;e[243]!==s||e[244]!==a||e[245]!==r||e[246]!==t||e[247]!==n||e[248]!==W.assistantTpsByMessageID?(i=e=>{let i=Zr(e.info).role,c=i===`assistant`,l=i===`user`,u=a[e.info.id]===!0,d=s===e.info.id,f=e.info.time?.created??null,p=Np(e.parts),m=c?Up({info:e.info,parts:e.parts}):null,h=l?Fp(e.parts):``,g=zp(f,n),_=p||`—`,v=!r||!c?null:W.assistantTpsByMessageID.get(e.info.id)??null,b=m?Lp(m.input,m.output,Xp,v):``,x=i||`unknown`,S=p?`${x}: ${p}`:x,C=u?JSON.stringify({info:e.info,parts:e.parts},null,2):``;return(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70`,children:[(0,$.jsx)(`button`,{type:`button`,className:`w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]`,"aria-expanded":u,onClick:()=>{o(t=>({...t,[e.info.id]:t[e.info.id]!==!0}))},children:(0,$.jsxs)(`div`,{className:`grid items-center gap-x-2 whitespace-nowrap typography-micro`,style:{gridTemplateColumns:c?`minmax(0, 1fr) minmax(7.5rem, max-content) max-content`:`minmax(0, 1fr) max-content`},children:[l?(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:`user:`}),` `,h]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:c?_:S}),c&&(0,$.jsx)(`span`,{className:`text-right text-muted-foreground tabular-nums`,children:b})]}),(0,$.jsx)(`span`,{className:`text-right text-muted-foreground`,children:g})]})}),u&&(0,$.jsx)(`div`,{className:`border-t border-[var(--surface-subtle)] p-0`,children:(0,$.jsxs)(`div`,{className:`group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]`,children:[(0,$.jsx)(`div`,{className:`absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100`,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground`,onClick:t=>{t.stopPropagation(),y(e.info.id,C)},"aria-label":t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copyJson`),title:t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copy`),children:d?(0,$.jsx)(Z,{name:`check`,className:`size-3.5`}):(0,$.jsx)(Z,{name:`file-copy`,className:`size-3.5`})})}),(0,$.jsx)(is,{language:`json`,code:C,style:{margin:0,padding:`0.75rem`,background:`transparent`,fontSize:`var(--text-micro)`,lineHeight:`1.35`},wrap:!0})]})})]},e.info.id)},e[243]=s,e[244]=a,e[245]=r,e[246]=t,e[247]=n,e[248]=W.assistantTpsByMessageID,e[249]=i):i=e[249],xt=[...f].reverse().map(i),e[235]=s,e[236]=a,e[237]=f,e[238]=r,e[239]=t,e[240]=n,e[241]=W.assistantTpsByMessageID,e[242]=xt}else xt=e[242];let St;e[250]===xt?St=e[251]:(St=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:xt}),e[250]=xt,e[251]=St);let Ct;e[252]!==bt||e[253]!==St?(Ct=(0,$.jsxs)(`div`,{children:[bt,St]}),e[252]=bt,e[253]=St,e[254]=Ct):Ct=e[254];let Et;return e[255]!==ye||e[256]!==Ae||e[257]!==Ze||e[258]!==ht||e[259]!==vt||e[260]!==Ct?(Et=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[ye,Ae,Ze,ht,vt,Ct]})}),e[255]=ye,e[256]=Ae,e[257]=Ze,e[258]=ht,e[259]=vt,e[260]=Ct,e[261]=Et):Et=e[261],Et};function tm(e){return e.timeFormatPreference}function nm(e){return e.showAssistantTps}function rm(e){return e.currentSessionId}function im(e){return e.providers}function am(e){return Object.keys(e).length>0?{}:e}function om(e){return Zr(e.info).role===`assistant`}function sm(e){return Zr(e.info).isUser}function cm(e,t){return e+Hp(t.info.cost)}function lm(e){let{info:t}=e;return{createdAt:t.time.created,streamedAt:t.time.streamed,outputTokens:t.tokens?.output,reasoningTokens:t.tokens?.reasoning}}function um(e){return Zr(e.info).isUser&&typeof e.info.system==`string`}function dm(e){return(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.value})]},e.label)}function fm(e){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.format===`text`?typeof e.value==`string`&&e.value.length>0?e.value:`—`:e.value!==null&&e.value!==void 0?e.format===`percent`?`${Number(e.value).toFixed(1)}%`:Xp(Number(e.value)):`—`})]},e.label)}var pm=e=>{let t=e.trim().replace(/\\/g,`/`);if(!t)return``;let n=t.startsWith(`//`),r=t.replace(/\/+$/g,``).replace(/\/+/g,`/`);return n&&!r.startsWith(`//`)?`/${r}`:r||(t.startsWith(`/`)?`/`:``)},mm=()=>`react-surface`,hm=(e,t)=>JSON.stringify([pm(e),t]),gm=(e,t,n,r)=>JSON.stringify([e,t,pm(n),r]),_m=(e,t,n)=>n?t:e===t?e:null,vm=(e,t)=>e.sessionId===t.sessionId&&pm(e.directory)===pm(t.directory),ym=(e,t)=>pm(e)===pm(t),bm=e=>({anchor:e,current:e,stack:[]}),xm=(e,t)=>e??bm(t),Sm=(e,t)=>e?.current.sessionId??t,Cm=(e,t)=>vm(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},wm=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Tm=(e,t,n)=>!ym(e.anchor.directory,t.directory)||!ym(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Cm(e,t)},Em=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Tm(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Dm=(e,t)=>{let n=!1,r={};for(let[i,a]of Object.entries(e)){if(!t.has(i)){n=!0;continue}r[i]=a}return n?r:e},Om=e=>e.directoryMatches?e.error?e.messageCount>0?`partial-error`:`fatal-error`:!e.renderable&&e.requested?`cold-loading`:e.messageCount===0?e.working?`working-empty`:`authoritative-empty`:`transcript`:`directory-mismatch`,km=e=>e===`retry`,Am=e=>e.active&&e.visible&&e.messageCount<=0,jm=e=>e?`load-more`:`ensure`,Mm=e=>e.kind===`has-more`,Nm=(e,t)=>`${e}\n${t}`,Pm=(e,t,n,r)=>r&&!e.has(Nm(t,n)),Fm=(e,t)=>({scrollHeight:e,scrollTop:t}),Im=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),Lm=(e,t)=>e&&!t,Rm=e=>e,zm=e=>!e,Bm=e=>!Lm(e.hasMore,e.isLoading)||!zm(e.historyVirtualized)?null:Fm(e.scrollHeight,e.scrollTop),Vm=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),Hm=33554432,Um=e=>Math.min(Hm,262144+Math.max(0,Math.ceil(e))*64*1024),Wm=e=>Math.min(Hm,Math.max(0,Math.round(Number.isFinite(e)?e:0))),Gm=e=>{let t=Object.values(e.mountedViews),n=t.length,r=t.reduce((e,t)=>e+t.estimatedBytes,0),i=new Set,a=t.filter(t=>t.viewKey!==e.activeViewKey).sort((e,t)=>e.lastAccessed-t.lastAccessed);for(let e of a){if(n<=3&&r<=33554432)break;i.add(e.viewKey),--n,r-=e.estimatedBytes}if(i.size===0)return e;let o={...e.mountedViews};return i.forEach(e=>delete o[e]),{...e,mountedViews:o}},Km=(e,t)=>{if(t.type===`close-tab`){let n=Object.values(e.mountedViews).filter(e=>e.tabId===t.tabId);if(!e.tabs[t.tabId]&&n.length===0)return e;let r={...e.tabs},i={...e.mountedViews};return delete r[t.tabId],n.forEach(e=>delete i[e.viewKey]),{activeViewKey:n.some(t=>t.viewKey===e.activeViewKey)?null:e.activeViewKey,tabs:r,mountedViews:i}}if(t.type===`activate`){if(t.viewKey===e.activeViewKey)return e;let n=t.viewKey?e.mountedViews[t.viewKey]:void 0;if(t.viewKey&&!n)return e;if(!n)return{...e,activeViewKey:null};let r=n.lastAccessed===t.now?e.mountedViews:{...e.mountedViews,[n.viewKey]:{...n,lastAccessed:t.now}};return Gm({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=Wm(t.estimatedBytes);return!n||n.estimatedBytes===r?e:Gm({...e,mountedViews:{...e.mountedViews,[n.viewKey]:{...n,estimatedBytes:r}}})}let n=e.tabs[t.tab.tabId],r=e.mountedViews[t.view.viewKey],i=n&&n.sessionId===t.tab.sessionId&&n.directory===t.tab.directory&&n.title===t.tab.title,a=r&&r.tabId===t.view.tabId&&r.surfaceId===t.view.surfaceId&&r.lastAccessed===t.now;return i&&a&&e.activeViewKey===t.view.viewKey?e:Gm({...e,activeViewKey:t.view.viewKey,tabs:i?e.tabs:{...e.tabs,[t.tab.tabId]:t.tab},mountedViews:{...e.mountedViews,[t.view.viewKey]:{...t.view,estimatedBytes:r?.estimatedBytes??Um(0),lastAccessed:t.now}}})},qm=e=>{let t=(0,pl.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=Tt();if(n===`cold-loading`||n===`working-empty`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`})}),t[0]=e):e=t[0],e}if(n===`fatal-error`||n===`directory-mismatch`){let e;t[1]!==r||t[2]!==a?(e=r||a(`chat.emptyState.opencodeUnreachable`),t[1]=r,t[2]=a,t[3]=e):e=t[3];let o;t[4]===e?o=t[5]:(o=(0,$.jsx)(`div`,{className:`text-center`,children:e}),t[4]=e,t[5]=o);let s;t[6]!==i||t[7]!==n||t[8]!==a?(s=n===`fatal-error`?(0,$.jsx)(Y,{type:`button`,variant:`secondary`,size:`sm`,onClick:i,children:a(`chat.history.retry`)}):null,t[6]=i,t[7]=n,t[8]=a,t[9]=s):s=t[9];let c;return t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-sm text-muted-foreground`,children:[o,s]}),t[10]=o,t[11]=s,t[12]=c):c=t[12],c}let o;t[13]===a?o=t[14]:(o=a(`chat.timeline.empty.session`),t[13]=a,t[14]=o);let s;return t[15]===o?s=t[16]:(s=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:o}),t[15]=o,t[16]=s),s},Jm=e=>{let t=(0,pl.c)(173),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:o,onNavigateSession:s,onNavigateBack:c,onEstimateBytes:l,syncDirectory:u}=e,{t:d}=Tt(),p=oi(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=f(),m=pm(i),g=gm(h,n,m,r),t[0]=i,t[1]=r,t[2]=n,t[3]=m,t[4]=h,t[5]=g):(m=t[3],h=t[4],g=t[5]);let _=g,v=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(0),[x,S]=Q.useState(null),C;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(C=new Set,t[6]=C):C=t[6];let w=Q.useRef(C),T=vn(r,u),E=Kn(r,u),D=Qn(Xm),O;t[7]===E?O=t[8]:(O=si(E),t[7]=E,t[8]=O);let k=O,A;bb0:{if(!k.modelId){let e;t[9]===d?e=t[10]:(e=d(`common.unavailable`),t[9]=d,t[10]=e),A=e;break bb0}let e;if(t[11]!==k.modelId||t[12]!==k.providerId||t[13]!==D){let n;t[15]===k.providerId?n=t[16]:(n=e=>e.id===k.providerId,t[15]=k.providerId,t[16]=n);let r=D.find(n);e=r?.models.some(e=>e.id===k.modelId)&&nn(r,k.modelId)||k.modelId,t[11]=k.modelId,t[12]=k.providerId,t[13]=D,t[14]=e}else e=t[14];A=e}let j=A,M=Wn(r,u),N=Fn(r,u).renderable,P;t[17]===r?P=t[18]:(P=e=>!!e.session.find(e=>e.id===r)?.parentID,t[17]=r,t[18]=P);let F=Gt(P,u),[I,L]=Q.useState(null),R,z;t[19]!==F||t[20]!==_?(R=()=>{L(e=>_m(e,_,F))},z=[F,_],t[19]=F,t[20]=_,t[21]=R,t[22]=z):(R=t[21],z=t[22]),Q.useLayoutEffect(R,z);let B=F||I===_,V=Hn(r,u),ee;t[23]===r?ee=t[24]:(ee=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=ee);let H=zt(ee),te;t[25]===H?te=t[26]:(te=e=>H?e.messageStreamStates.get(H)?.phase??null:null,t[25]=H,t[26]=te);let ne=zt(te),re=M?.type===`busy`||M?.type===`retry`,U;t[27]!==a||t[28]!==r||t[29]!==re||t[30]!==T||t[31]!==_?(U={scrollControllerRef:v,enabled:a,currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:re,isMobile:!1},t[27]=a,t[28]=r,t[29]=re,t[30]=T,t[31]=_,t[32]=U):U=t[32];let{scrollRef:ie,notifyContentChange:ae,getAnimationHandlers:W,goToBottom:oe,restoreSnapshot:se,showScrollButton:ce}=Di(U),G;t[33]===oe?G=t[34]:(G=e=>{oe(e===void 0?`instant`:e)},t[33]=oe,t[34]=G);let le=vt(G),ue;t[35]!==r||t[36]!==p?(ue=e=>{p.ensureSessionRenderable(r,km(e))},t[35]=r,t[36]=p,t[37]=ue):ue=t[37];let de=vt(ue),fe,pe;t[38]!==a||t[39]!==de?(fe=()=>{a&&de(`active`)},pe=[a,de],t[38]=a,t[39]=de,t[40]=fe,t[41]=pe):(fe=t[40],pe=t[41]),Q.useEffect(fe,pe);let me,he;t[42]!==a||t[43]!==de||t[44]!==T?(me=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();Am({active:a,visible:e,messageCount:T})&&de(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},he=[a,de,T],t[42]=a,t[43]=de,t[44]=T,t[45]=me,t[46]=he):(me=t[45],he=t[46]),Q.useEffect(me,he);let ge,_e;t[47]!==l||t[48]!==T||t[49]!==_?(ge=()=>{l?.(_,Um(T))},_e=[l,T,_],t[47]=l,t[48]=T,t[49]=_,t[50]=ge,t[51]=_e):(ge=t[50],_e=t[51]),Q.useEffect(ge,_e);let ve,ye;t[52]!==N||t[53]!==se||t[54]!==r||t[55]!==_?(ve=()=>{if(!Pm(w.current,r,_,N))return;let e=Nm(r,_);w.current.add(e),se()},ye=[N,se,r,_],t[52]=N,t[53]=se,t[54]=r,t[55]=_,t[56]=ve,t[57]=ye):(ve=t[56],ye=t[57]),Q.useEffect(ve,ye);let be;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(be=()=>{y.current=null,S(null)},t[58]=be):be=t[58];let xe;t[59]===_?xe=t[60]:(xe=[_],t[59]=_,t[60]=xe),Q.useLayoutEffect(be,xe);let Se;t[61]!==x||t[62]!==ie||t[63]!==_?(Se=()=>{let e=y.current,t=ie.current;if(Vm(e,x,_)){if(!t||!zm(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=Im(e.anchor,t.scrollHeight),y.current=null}},t[61]=x,t[62]=ie,t[63]=_,t[64]=Se):Se=t[64];let Ce;t[65]!==x||t[66]!==ie||t[67]!==E||t[68]!==_?(Ce=[x,ie,E,_],t[65]=x,t[66]=ie,t[67]=E,t[68]=_,t[69]=Ce):Ce=t[69],Q.useLayoutEffect(Se,Ce);let we;t[70]===m?we=t[71]:(we={directory:m},t[70]=m,t[71]=we);let Te=we,Ee=_n(r,u).boundary,De;t[72]===Ee?De=t[73]:(De=Mm(Ee),t[72]=Ee,t[73]=De);let Oe=De,ke;t[74]!==V?.status||t[75]!==Te||t[76]!==r||t[77]!==p?(ke=V?.status===`loading`||p.isLoading(r,Te),t[74]=V?.status,t[75]=Te,t[76]=r,t[77]=p,t[78]=ke):ke=t[78];let Ae=ke,je;t[79]!==m||t[80]!==h||t[81]!==r?(je=[`context-panel-load-older`,h,m,r],t[79]=m,t[80]=h,t[81]=r,t[82]=je):je=t[82];let Me;t[83]!==Ee||t[84]!==r||t[85]!==u?(Me=async()=>{Ee.kind===`unknown`&&await Ue(u,r),await qe(u,r)},t[83]=Ee,t[84]=r,t[85]=u,t[86]=Me):Me=t[86];let Ne;t[87]!==je||t[88]!==Me?(Ne={mutationKey:je,mutationFn:Me},t[87]=je,t[88]=Me,t[89]=Ne):Ne=t[89];let K=nt(Ne),Pe=K.isPending,Fe;t[90]!==Ae||t[91]!==Oe||t[92]!==Pe||t[93]!==K||t[94]!==ie||t[95]!==d||t[96]!==_?(Fe=()=>{if(!Lm(Oe,Pe||Ae)||K.isPending)return;let e=b.current+1;b.current=e;let t=ie.current,n=t?Bm({hasMore:Oe,isLoading:Pe,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,K.mutateAsync().then(()=>{S(e)},()=>{S(e),X.error(d(`chat.history.loadOlderFailed`))})},t[90]=Ae,t[91]=Oe,t[92]=Pe,t[93]=K,t[94]=ie,t[95]=d,t[96]=_,t[97]=Fe):Fe=t[97];let Ie=vt(Fe),Le=V?.status===`error`?V.error:void 0,Re;t[98]!==a||t[99]!==N||t[100]!==re||t[101]!==E.length||t[102]!==Le?(Re=Om({directoryMatches:!0,requested:a,renderable:N,messageCount:E.length,working:re,error:Le}),t[98]=a,t[99]=N,t[100]=re,t[101]=E.length,t[102]=Le,t[103]=Re):Re=t[103];let ze=Re,Be;t[104]!==a||t[105]!==m||t[106]!==s||t[107]!==r||t[108]!==n?(Be={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:Ii,navigateSession:s},t[104]=a,t[105]=m,t[106]=s,t[107]=r,t[108]=n,t[109]=Be):Be=t[109];let Ve=Be,He;t[110]!==de||t[111]!==Oe||t[112]!==Ie?(He=()=>{if(jm(Oe)===`load-more`){Ie();return}de(`retry`)},t[110]=de,t[111]=Oe,t[112]=Ie,t[113]=He):He=t[113];let We=vt(He),Ge;t[114]!==V?.error||t[115]!==We||t[116]!==d||t[117]!==ze?(Ge=ze===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:V?.error}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,size:`xs`,onClick:We,children:d(`chat.history.retry`)})]}):null,t[114]=V?.error,t[115]=We,t[116]=d,t[117]=ze,t[118]=Ge):Ge=t[118];let Ke=Ge,Je;t[119]!==Oe||t[120]!==Pe||t[121]!==Ie||t[122]!==d?(Je=Rm(Oe)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,size:`sm`,onClick:Ie,disabled:Pe,children:[Pe?(0,$.jsx)(Z,{name:`loader-4`,className:`size-4 animate-spin`}):null,d(`chat.history.loadOlder`)]})}):null,t[119]=Oe,t[120]=Pe,t[121]=Ie,t[122]=d,t[123]=Je):Je=t[123];let Ye=Je,Xe;t[124]===Symbol.for(`react.memo_cache_sentinel`)?(Xe=(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:Fr},"aria-hidden":`true`}),t[124]=Xe):Xe=t[124];let q=Xe,Ze;t[125]===le?Ze=t[126]:(Ze=()=>le(`instant`),t[125]=le,t[126]=Ze);let Qe;t[127]!==ne||t[128]!==W||t[129]!==Pe||t[130]!==ae||t[131]!==ie||t[132]!==r||t[133]!==re||t[134]!==E||t[135]!==H||t[136]!==u||t[137]!==Ze||t[138]!==_?(Qe=(0,$.jsx)(Ti,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:re,activeStreamingMessageId:H,activeStreamingPhase:ne,onMessageContentChange:ae,getAnimationHandlers:W,isLoadingOlder:Pe,scrollToBottom:Ze,scrollRef:ie,directory:u,enableSendPark:!1}),t[127]=ne,t[128]=W,t[129]=Pe,t[130]=ae,t[131]=ie,t[132]=r,t[133]=re,t[134]=E,t[135]=H,t[136]=u,t[137]=Ze,t[138]=_,t[139]=Qe):Qe=t[139];let $e=Qe,et;t[140]===le?et=t[141]:(et=()=>le(`smooth`),t[140]=le,t[141]=et);let tt;t[142]!==ce||t[143]!==et?(tt=(0,$.jsx)(gi,{visible:ce,onClick:et}),t[142]=ce,t[143]=et,t[144]=tt):tt=t[144];let rt=tt,it;t[145]!==o||t[146]!==c||t[147]!==d?(it=o?(0,$.jsxs)(Y,{type:`button`,variant:`outline`,size:`xs`,onClick:c,className:`absolute left-3 top-3 z-20 !font-normal bg-[var(--surface-background)]/95`,"aria-label":d(`chat.container.returnToParent.aria`),title:d(`chat.container.returnToParent.title`),children:[(0,$.jsx)(Z,{name:`arrow-left`,className:`h-4 w-4`}),d(`chat.container.returnToParent.label`)]}):null,t[145]=o,t[146]=c,t[147]=d,t[148]=it):it=t[148];let at;t[149]!==de||t[150]!==Ye||t[151]!==Ke||t[152]!==V?.error||t[153]!==ie||t[154]!==rt||t[155]!==$e||t[156]!==ze?(at=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:ze===`cold-loading`||ze===`working-empty`||ze===`authoritative-empty`||ze===`fatal-error`?(0,$.jsx)(qm,{state:ze,error:V?.error,onRetry:()=>de(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ho,{ref:ie,className:`absolute inset-0 overflow-y-auto overflow-x-hidden chat-scroll overlay-scrollbar-target`,observeMutations:!1,"data-scroll-shadow":`true`,"data-scrollbar":`chat`,children:(0,$.jsxs)(`div`,{className:`relative min-h-full`,children:[Ke,Ye,$e,q]})}),rt]})}),t[149]=de,t[150]=Ye,t[151]=Ke,t[152]=V?.error,t[153]=ie,t[154]=rt,t[155]=$e,t[156]=ze,t[157]=at):at=t[157];let ot;t[158]!==k.agentName||t[159]!==k.modelId||t[160]!==k.providerId||t[161]!==j||t[162]!==B?(ot=B?(0,$.jsx)(Gr,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[158]=k.agentName,t[159]=k.modelId,t[160]=k.providerId,t[161]=j,t[162]=B,t[163]=ot):ot=t[163];let st;t[164]!==r||t[165]!==n||t[166]!==it||t[167]!==at||t[168]!==ot?(st=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":r,"data-surface-id":n,children:[it,at,ot]}),t[164]=r,t[165]=n,t[166]=it,t[167]=at,t[168]=ot,t[169]=st):st=t[169];let ct;return t[170]!==Ve||t[171]!==st?(ct=(0,$.jsx)(ji.Provider,{value:Ve,children:st}),t[170]=Ve,t[171]=st,t[172]=ct):ct=t[172],ct},Ym=e=>{let t=(0,pl.c)(22),n=ir(),{t:r}=Tt(),i;t[0]===e.directory?i=t[1]:(i=pm(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===pm(n),s;t[2]!==a||t[3]!==e.active||t[4]!==e.onNavigateSession||t[5]!==e.sessionId||t[6]!==e.surfaceId?(s={kind:`panel`,surfaceId:e.surfaceId,sessionId:e.sessionId,directory:a,active:e.active,capabilities:Ii,navigateSession:e.onNavigateSession},t[2]=a,t[3]=e.active,t[4]=e.onNavigateSession,t[5]=e.sessionId,t[6]=e.surfaceId,t[7]=s):s=t[7];let c=s;if(!o){let n=e.sessionId,i=e.surfaceId,a;t[8]===r?a=t[9]:(a=r(`chat.emptyState.opencodeUnreachable`),t[8]=r,t[9]=a);let o;t[10]===a?o=t[11]:(o=(0,$.jsx)(qm,{state:`directory-mismatch`,onRetry:Zm,error:a}),t[10]=a,t[11]=o);let s;t[12]!==e.sessionId||t[13]!==e.surfaceId||t[14]!==o?(s=(0,$.jsx)(`div`,{className:`h-full`,"data-context-session-surface":`true`,"data-session-id":n,"data-surface-id":i,children:o}),t[12]=e.sessionId,t[13]=e.surfaceId,t[14]=o,t[15]=s):s=t[15];let l;return t[16]!==c||t[17]!==s?(l=(0,$.jsx)(ji.Provider,{value:c,children:s}),t[16]=c,t[17]=s,t[18]=l):l=t[18],l}let l;return t[19]!==e||t[20]!==n?(l=(0,$.jsx)(Jm,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function Xm(e){return e.providers}function Zm(){}var Qm=e=>{let t=e.trim();if(!t)return`about:blank`;try{let e=new URL(t.includes(`://`)?t:`https://${t}`);return e.protocol!==`http:`&&e.protocol!==`https:`?`about:blank`:e.toString()}catch{return`about:blank`}},$m=(e,t)=>{let n=Qm(e),r=n===`about:blank`?``:n;return!r||r===t?null:r},eh=e=>!!e.isElectron&&!e.relayActive,th=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},nh=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),rh=e=>{if(!e||typeof e!=`object`)return!1;let t=e,n=t.bounds;return typeof t.tag==`string`&&typeof t.text==`string`&&typeof t.selector==`string`&&typeof t.path==`string`&&!!n&&typeof n?.x==`number`&&typeof n?.y==`number`&&typeof n?.width==`number`&&typeof n?.height==`number`&&th(t.center)&&nh(t.attributes)&&nh(t.computedStyle)&&Array.isArray(t.ancestry)},ih=({pageUrl:e,viewport:t,devicePixelRatio:n,target:r,screenshotAttached:i,intro:a})=>{let o=r.text.trim(),s=Object.entries(r.attributes).map(([e,t])=>`${e}="${t}"`).join(` `),c=r.computedStyle,l=r.bounds,u=r.center,d=a.replace(/[.:]+$/g,``),f=r.ancestry.map(e=>e.selectorPart).join(` > `);return[`${d}:`,`Page: ${e||`preview`}`,`Viewport: ${t.width}x${t.height}, DPR ${n}`,`Screenshot: ${i?`attached`:`not attached`}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,s?`- Attributes: ${s}`:null,`- Bounds: x=${Math.round(l.x)}, y=${Math.round(l.y)}, width=${Math.round(l.width)}, height=${Math.round(l.height)}`,`- Center: x=${Math.round(u.x)}, y=${Math.round(u.y)}`,`Styles: display=${c.display}; position=${c.position}; font=${c.fontWeight} ${c.fontSize} / ${c.lineHeight} ${c.fontFamily}; color=${c.color}; background=${c.backgroundColor}; z-index=${c.zIndex}`].filter(e=>typeof e==`string`).join(`
18
+ `)},ah=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await j(`desktop_capture_page_rect`,{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw Error(`Desktop screenshot capture is not available`);let i=new Image;await new Promise((e,t)=>{i.onload=()=>e(),i.onerror=()=>t(Error(`Failed to load desktop preview screenshot`)),i.src=`data:${r.mime};base64,${r.base64}`});let a=Math.max(1,i.naturalWidth||r.width||Math.floor(n.width)),o=Math.max(1,i.naturalHeight||r.height||Math.floor(n.height)),s=Math.min(1,1200/a),c=document.createElement(`canvas`);c.width=Math.floor(a*s),c.height=Math.floor(o*s);let l=c.getContext(`2d`);if(!l)return null;l.scale(s,s),l.drawImage(i,0,0,a,o);let u=a/Math.max(1,n.width),d=o/Math.max(1,n.height);l.fillStyle=`rgba(37, 99, 235, 0.28)`,l.strokeStyle=`rgb(37, 99, 235)`,l.lineWidth=Math.max(2,2*u),l.fillRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d),l.strokeRect(t.bounds.x*u,t.bounds.y*d,t.bounds.width*u,t.bounds.height*d);let f=await new Promise(e=>c.toBlob(e,`image/jpeg`,.82));return f?new File([f],`preview-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch(e){return console.warn(`[preview] failed to capture annotation screenshot:`,e),null}return await Ih(e,t)},oh=async(e,t,n,r,i,a)=>{if(!e)return null;try{let o=new Image;await new Promise((t,n)=>{o.onload=()=>t(),o.onerror=()=>n(Error(`Failed to load desktop browser screenshot`)),o.src=`data:image/jpeg;base64,${e}`});let s=Math.max(1,o.naturalWidth||t),c=Math.max(1,o.naturalHeight||n),l=Math.min(1,1200/s),u=document.createElement(`canvas`);u.width=Math.floor(s*l),u.height=Math.floor(c*l);let d=u.getContext(`2d`);if(!d)return null;d.scale(l,l),d.drawImage(o,0,0,s,c);let f=s/Math.max(1,r||s),p=c/Math.max(1,i||c);d.fillStyle=`rgba(37, 99, 235, 0.14)`,d.strokeStyle=`rgb(37, 99, 235)`,d.lineWidth=Math.max(2,2*f),d.fillRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p),d.strokeRect(a.bounds.x*f,a.bounds.y*p,a.bounds.width*f,a.bounds.height*p);let m=await new Promise(e=>u.toBlob(e,`image/jpeg`,.82));return m?new File([m],`browser-annotation-${Date.now()}.jpg`,{type:`image/jpeg`}):null}catch{return null}},sh=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,ch=new Map,lh=new Map,uh=3e4,dh=e=>{let t=ch.get(e);return t?t.expiresAt-Date.now()<=uh?(ch.delete(e),null):t:null},fh=e=>{try{return new URL(e).origin}catch{return e}};function ph(e){let t=e.defaultView??window;try{let n=e.body?t.getComputedStyle(e.body).backgroundColor:``;if(n&&n!==`rgba(0, 0, 0, 0)`&&n!==`transparent`)return n;let r=t.getComputedStyle(e.documentElement).backgroundColor;if(r&&r!==`rgba(0, 0, 0, 0)`&&r!==`transparent`)return r}catch{}return`#ffffff`}var mh=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:sh),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),hh=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await mh(n)).split(`,`,2)[1]||``},gh=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},_h=(...e)=>{gh()&&[...e]},vh=(e,t=8)=>{let n=[];try{let r=e.querySelectorAll(`*`);for(let e of r){let r=e.scrollTop||0,i=e.scrollLeft||0;if(r<=0&&i<=0)continue;let a=e.tagName.toLowerCase(),o=e.id?`#${e.id}`:``,s=typeof e.className==`string`&&e.className?`.${e.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;if(n.push({selector:`${a}${o}${s}`,scrollTop:r,scrollLeft:i,clientWidth:e.clientWidth,clientHeight:e.clientHeight,scrollWidth:e.scrollWidth,scrollHeight:e.scrollHeight}),n.length>=t)break}}catch{}return n},yh=`data-yuri-fixed-pin`,bh=(e,t,n)=>{if(t<=0&&n<=0)return()=>{};let r=e.defaultView;if(!r)return()=>{};let i=[],a=[];try{for(let o of e.querySelectorAll(`*`)){if(r.getComputedStyle(o).position!==`fixed`)continue;let e=o.getBoundingClientRect();if(!(e.width>0&&e.height>0))continue;o.setAttribute(yh,JSON.stringify({top:e.top+n,left:e.left+t,width:e.width,height:e.height})),i.push(o);let s=o.tagName.toLowerCase(),c=typeof o.className==`string`&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(`.`)}`:``;a.push({selector:`${s}${c}`,top:Math.round(e.top),left:Math.round(e.left),width:Math.round(e.width),height:Math.round(e.height)})}}catch{}return _h(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(yh)}catch{}}},xh={name:`yuri-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${yh}]`)){let t;try{t=JSON.parse(e.getAttribute(yh)||``)}catch{continue}e.style.setProperty(`position`,`absolute`,`important`),e.style.setProperty(`top`,`${t.top}px`,`important`),e.style.setProperty(`left`,`${t.left}px`,`important`),e.style.setProperty(`right`,`auto`,`important`),e.style.setProperty(`bottom`,`auto`,`important`),e.style.setProperty(`width`,`${t.width}px`,`important`),e.style.setProperty(`height`,`${t.height}px`,`important`),e.removeAttribute(yh)}}},Sh=`data-yuri-scroll-pin`,Ch=e=>{let t=[],n=vh(e,64);try{let n=e.documentElement,r=e.body;for(let i of e.querySelectorAll(`*`)){let e=i.scrollTop||0,a=i.scrollLeft||0;if(e<=0&&a<=0)continue;let o=i!==n&&i!==r;o&&i.setAttribute(Sh,JSON.stringify({top:e,left:a})),t.push({el:i,top:e,left:a,tagged:o})}}catch{}return{reapply:()=>{for(let e of t)try{e.el.scrollHeight,e.el.scrollTop!==e.top&&(e.el.scrollTop=e.top),e.el.scrollLeft!==e.left&&(e.el.scrollLeft=e.left)}catch{}},cleanup:()=>{for(let e of t)if(e.tagged)try{e.el.removeAttribute(Sh)}catch{}},snapshot:n}},wh={name:`yuri-nested-scroll`,afterClone(e){let t=e?.clone;if(!t||typeof t.querySelectorAll!=`function`)return;let n=t.ownerDocument;if(n)for(let e of t.querySelectorAll(`[${Sh}]`)){let t;try{t=JSON.parse(e.getAttribute(Sh)||``)}catch{e.removeAttribute(Sh);continue}let r=`translate(${-t.left}px, ${-t.top}px)`,i=e.children.length===1&&e.firstElementChild instanceof HTMLElement&&e.firstElementChild.style.willChange===`transform`?e.firstElementChild:null;if(i)i.style.transform=r;else{e.style.overflow=`hidden`;let t=n.createElement(`div`);for(t.style.transform=r,t.style.willChange=`transform`,t.style.display=`inline-block`,t.style.width=`100%`;e.firstChild;)t.appendChild(e.firstChild);e.appendChild(t)}e.removeAttribute(Sh)}}},Th=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await mh(await n.blob()):null}catch{return null}},Eh=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=dh(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=lh.get(t),i=r??(async()=>{try{let n=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return ch.delete(t),null;let r=await n.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i)return ch.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return ch.set(t,o),o}catch{return ch.delete(t),null}finally{lh.delete(t)}})();r||lh.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Dh=async(e,t)=>{if(!e||e.startsWith(`data:`))return e;try{let n=new URL(e,t.baseURI);if(n.origin===window.location.origin||n.protocol!==`http:`&&n.protocol!==`https:`)return await Th(n.toString(),`include`)??sh;let r=await Eh(n);return(r?await Th(r,`include`):null)||(await Th(n.toString(),`omit`)??sh)}catch{return sh}},Oh=async(e,t)=>{if(!e||e===`none`||!e.includes(`url(`))return e;let n=Array.from(e.matchAll(/url\((['"]?)(.*?)\1\)/g)),r=e;for(let e of n){let n=e[2]||``;if(!n||n.startsWith(`data:`))continue;let i=await Dh(n,t);r=r.replace(e[0],`url("${i}")`)}return r},kh=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Ah=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},jh=e=>{let t=Number.parseFloat(e.lineHeight);if(Number.isFinite(t)&&t>0)return t;let n=Number.parseFloat(e.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},Mh=(e,t,n)=>{let r=[],i=e.defaultView??window,a=Array.from(e.querySelectorAll(`button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *`));for(let e of a){let a=e.textContent?.replace(/\s+/g,` `).trim()??``;if(!a||!a.includes(` `))continue;let o=e.getBoundingClientRect();if(o.width<=0||o.height<=0||o.right<0||o.bottom<0||o.left>t||o.top>n)continue;let s=i.getComputedStyle(e);if(s.display===`none`||s.visibility===`hidden`||Number(s.opacity)===0)continue;let c=s.getPropertyValue(`text-wrap`),l=s.getPropertyValue(`text-wrap-mode`),u=s.whiteSpace.includes(`nowrap`)||c===`nowrap`||l===`nowrap`,d=o.height<=jh(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Ah(e)),e.style.whiteSpace=`nowrap`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.setProperty(`text-wrap`,`nowrap`),e.style.setProperty(`text-wrap-mode`,`nowrap`))}return()=>{for(let e=r.length-1;e>=0;--e)r[e]?.()}},Nh=(e,t,n,r)=>{let i=[],a=e.defaultView??window,o=a.scrollX||e.documentElement.scrollLeft||e.body?.scrollLeft||0,s=a.scrollY||e.documentElement.scrollTop||e.body?.scrollTop||0,c=Array.from(e.querySelectorAll(`*`)).filter(e=>{let r=a.getComputedStyle(e);if(r.position!==`fixed`||r.display===`none`||r.visibility===`hidden`||Number(r.opacity)===0)return!1;let i=e.getBoundingClientRect();return i.width>0&&i.height>0&&i.right>=0&&i.bottom>=0&&i.left<=t&&i.top<=n}).filter((e,t,n)=>!n.some((n,r)=>r<t&&n.contains(e)));for(let e of c){let t=e.getBoundingClientRect(),n=a.getComputedStyle(e),c=Math.ceil(t.width)+8,l=Math.ceil(t.height)+2;r?.add(e),i.push(Ah(e)),e.style.position=`absolute`,e.style.top=`${t.top+s}px`,e.style.left=`${t.left+o}px`,e.style.right=`auto`,e.style.bottom=`auto`,e.style.width=`${c}px`,e.style.minWidth=`${c}px`,e.style.height=`${l}px`,e.style.minHeight=`${l}px`,e.style.margin=`0`,e.style.boxSizing=`border-box`,e.style.transform=`none`,n.zIndex!==`auto`&&(e.style.zIndex=n.zIndex)}return()=>{for(let e=i.length-1;e>=0;--e)i[e]?.()}},Ph=async(e,t,n,r={})=>{let i=[],a=e.defaultView??window,o=r=>{if(r===e.documentElement||r===e.body)return!0;try{let e=r.getBoundingClientRect();return e.width>0&&e.height>0&&e.right>=0&&e.bottom>=0&&e.left<=t&&e.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){let r=new WeakSet;i.push(Nh(e,t,n,r)),i.push(Mh(e,t,n))}let s=new Map;for(let t of Array.from(e.images))s.set(t,t.currentSrc||t.src||t.getAttribute(`src`)||``);let c=Array.from(e.querySelectorAll(`picture`));for(let e of c){let t=Array.from(e.querySelectorAll(`source`));if(t.length===0)continue;let n=t.map(e=>({source:e,srcset:e.getAttribute(`srcset`),sizes:e.getAttribute(`sizes`)}));i.push(()=>{for(let e of n)e.srcset===null?e.source.removeAttribute(`srcset`):e.source.setAttribute(`srcset`,e.srcset),e.sizes===null?e.source.removeAttribute(`sizes`):e.source.setAttribute(`sizes`,e.sizes)});for(let e of t)e.removeAttribute(`srcset`),e.removeAttribute(`sizes`)}let l=Array.from(e.images).filter(e=>o(e));await Promise.all(l.map(async t=>{let n=s.get(t)||t.currentSrc||t.src||t.getAttribute(`src`)||``;if(!n)return;await kh(t);let r=await Dh(n,e),a={src:t.getAttribute(`src`),srcset:t.getAttribute(`srcset`),sizes:t.getAttribute(`sizes`)};i.push(()=>{a.src===null?t.removeAttribute(`src`):t.setAttribute(`src`,a.src),a.srcset===null?t.removeAttribute(`srcset`):t.setAttribute(`srcset`,a.srcset),a.sizes===null?t.removeAttribute(`sizes`):t.setAttribute(`sizes`,a.sizes)}),t.removeAttribute(`srcset`),t.removeAttribute(`sizes`),t.setAttribute(`src`,r||sh),await kh(t)}));let u=Array.from(e.querySelectorAll(`*`)).filter(o);return await Promise.all(u.map(async t=>{let n=a.getComputedStyle(t).backgroundImage;if(!n||n===`none`||!n.includes(`url(`))return;let r=await Oh(n,e);if(r===n)return;let o=t.style.backgroundImage;i.push(()=>{t.style.backgroundImage=o}),t.style.backgroundImage=r})),()=>{for(let e=i.length-1;e>=0;--e)try{i[e]?.()}catch{}}};async function Fh(e,t){try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=r.body,l=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,u=n.scrollX||0,d=n.scrollY||0,f=n.pageXOffset||0,p=n.pageYOffset||0,m=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,h=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=i.scrollLeft||0,_=i.scrollTop||0,v=c?.scrollLeft||0,y=c?.scrollTop||0,b=l?.scrollLeft||0,x=l?.scrollTop||0,S=Math.max(u,f,m,g,v,b),C=Math.max(d,p,h,_,y,x);_h(`scroll sources`,{windowScrollX:u,windowScrollY:d,pageScrollX:f,pageScrollY:p,visualViewportScrollX:m,visualViewportScrollY:h,rootScrollX:g,rootScrollY:_,bodyScrollX:v,bodyScrollY:y,scrollingElementScrollX:b,scrollingElementScrollY:x,scrollingElementTag:l?.tagName?.toLowerCase()??null,resolvedScrollX:S,resolvedScrollY:C,nestedScrolledElements:vh(r)});let w=Math.max(o,i.scrollWidth||0,c?.scrollWidth||0,Math.ceil(i.getBoundingClientRect().width||0)),T=Math.max(s,i.scrollHeight||0,c?.scrollHeight||0,Math.ceil(i.getBoundingClientRect().height||0)),E=Math.min(2,Math.max(1,window.devicePixelRatio||1)),D=i.style.scrollBehavior,O=c?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,c&&(c.style.scrollBehavior=`auto`);let k=Ch(r);_h(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await Ph(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=bh(r,S,C),k.reapply();let e={backgroundColor:ph(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[xh,wh],quality:.82,width:w},a=await(await ll(i,e)).toCanvas();if(!a.width||!a.height)return null;let c=a.width/Math.max(1,w),l=a.height/Math.max(1,T),u=Math.min(a.width,Math.max(1,Math.round(o*c))),d=Math.min(a.height,Math.max(1,Math.round(s*l))),f=Math.max(0,a.width-u),p=Math.max(0,a.height-d),m=Math.min(f,Math.max(0,Math.round(S*c))),h=Math.min(p,Math.max(0,Math.round(C*l)));_h(`capture geometry`,{viewportWidth:o,viewportHeight:s,captureWidth:w,captureHeight:T,canvasWidth:a.width,canvasHeight:a.height,xScale:c,yScale:l,sourceX:m,sourceY:h,sourceWidth:u,sourceHeight:d});let g=r.createElement(`canvas`);g.width=u,g.height=d;let _=g.getContext(`2d`);if(!_)return null;_.drawImage(a,m,h,u,d,0,0,u,d);let v=await hh(g,.82);return v?await oh(v,o,s,o,s,t):null}finally{j(),k.cleanup(),A(),n.scrollTo(S,C),k.reapply(),i.style.scrollBehavior=D,c&&(c.style.scrollBehavior=O)}}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot with snapDOM:`,e),null}}async function Ih(e,t){let n=await Fh(e,t);if(n)return n;try{let n=e.contentWindow,r=e.contentDocument??n?.document,i=r?.documentElement;if(!n||!r||!i)return null;let a=e.getBoundingClientRect(),o=Math.max(1,Math.ceil(n.innerWidth||e.clientWidth||a.width)),s=Math.max(1,Math.ceil(n.innerHeight||e.clientHeight||a.height)),c=n.scrollX||r.documentElement.scrollLeft||r.body?.scrollLeft||0,l=n.scrollY||r.documentElement.scrollTop||r.body?.scrollTop||0,u=r.body,d=Math.max(s,i.scrollHeight||0,u?.scrollHeight||0),f=Math.min(2,Math.max(1,window.devicePixelRatio||1)),p=i.style.scrollBehavior,m=u?.style.scrollBehavior??``;i.style.scrollBehavior=`auto`,u&&(u.style.scrollBehavior=`auto`);let h=``,g=()=>{};try{await r.fonts?.ready.catch(()=>void 0),g=await Ph(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await dl(i).catch(()=>``);h=await ul(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:ph(r),imagePlaceholder:sh,fontEmbedCSS:e||void 0,style:{transform:`translate(${-c}px, ${-l}px)`,transformOrigin:`top left`,minWidth:`${o}px`,minHeight:`${d}px`},cacheBust:!0})}finally{g(),n.scrollTo(c,l),i.style.scrollBehavior=p,u&&(u.style.scrollBehavior=m)}let _=h.split(`,`,2)[1]||``;return _?await oh(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var Lh=/^[a-z][a-z\d+.-]*:\/\//i,Rh=`/api/preview/proxy/`,zh=e=>{if(typeof e!=`string`||!e)return!1;let t=e.split(`?`,1)[0]||``;if(t.includes(`\\`)||t.includes(`\0`))return!1;try{let e=new URL(t,`http://127.0.0.1`);return e.hostname===`127.0.0.1`&&e.pathname.startsWith(Rh)}catch{return!1}},Bh=e=>{let t=typeof e.authenticatedAssetUrl==`string`?e.authenticatedAssetUrl:``;if(!t)return``;if(!e.relayActive)return t;let n=typeof e.gatewayOrigin==`string`?e.gatewayOrigin.trim():``;if(!n)return t;try{let e=new URL(n);if(e.protocol!==`http:`&&e.protocol!==`https:`||e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`)return t;let r=Lh.test(t)?new URL(t):new URL(t,`http://yuri.local`);return r.pathname.startsWith(Rh)?`${e.origin}${r.pathname}${r.search}${r.hash}`:t}catch{return t}},Vh=`yuri:preview-gateway-request`,Hh=`yuri:preview-gateway-abort`,Uh=`yuri:preview-gateway-ws-open`,Wh=`yuri:preview-gateway-ws-message`,Gh=`yuri:preview-gateway-ws-close`,Kh=e=>typeof e==`function`,qh=()=>{if(typeof window>`u`)return null;let e=window.__YURI_DESKTOP__?.previewGateway;return!e||!Kh(e.ensure)||!Kh(e.begin)||!Kh(e.push)||!Kh(e.end)||!Kh(e.abort)?null:e},Jh=()=>{if(typeof window>`u`)return null;let e=window.__YURI_DESKTOP__;return Kh(e?.listen)?e.listen:null},Yh=()=>qh()!==null,Xh=e=>{let t={};return e.forEach((e,n)=>{let r=n.toLowerCase();r!==`set-cookie`&&r!==`set-cookie2`&&r!==`content-length`&&r!==`content-encoding`&&(t[r]=e)}),t},Zh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId==`string`&&t.requestId.length>0&&typeof t.method==`string`&&typeof t.path==`string`&&zh(t.path)},Qh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.requestId!=`string`||!t.requestId||typeof t.path!=`string`||!zh(t.path)||t.protocols!==void 0&&(!Array.isArray(t.protocols)||!t.protocols.every(e=>typeof e==`string`)))},$h=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId!=`string`||!t.requestId||typeof t.binary!=`boolean`?!1:!!(typeof t.data==`string`||t.data instanceof ArrayBuffer||ArrayBuffer.isView(t.data))},eg=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.requestId==`string`&&t.requestId.length>0&&typeof t.code==`number`&&typeof t.reason==`string`},tg=new Map,ng=new Map,rg=null,ig=[],ag=null,og=()=>{for(let e of ig)try{e()}catch{}ig=[];for(let e of tg.values())try{e.abort()}catch{}tg.clear();for(let[e,t]of ng.entries()){ng.delete(e);try{t.close(1001,`gateway detach`)}catch{}}},sg=e=>{let t=e,n=``,r=e.indexOf(`?`);r>=0&&(t=e.slice(0,r),n=e.slice(r+1));let i=new URLSearchParams(n);i.delete(`yuri_url_token`);let a={};return i.forEach((e,t)=>{a[t]=e}),c().websocket(t,a)},cg=async e=>{let t=qh();if(!t)return;if(!o()){try{await t.abort(e.requestId)}catch{}return}let n=tg.get(e.requestId);n&&(n.abort(),tg.delete(e.requestId));let r=new AbortController;tg.set(e.requestId,r);try{let n=await _(e.path,{method:e.method||`GET`,signal:r.signal,credentials:`omit`,cache:`no-store`,redirect:`manual`});if(r.signal.aborted){try{await t.abort(e.requestId)}catch{}return}if(await t.begin({requestId:e.requestId,status:n.status,headers:Xh(n.headers)}),e.method.toUpperCase()===`HEAD`||!n.body){await t.end(e.requestId);return}let i=n.body.getReader();try{for(;;){if(r.signal.aborted){try{await i.cancel()}catch{}try{await t.abort(e.requestId)}catch{}return}let{done:n,value:a}=await i.read();if(n)break;if(!a||a.byteLength===0)continue;let o=a.byteOffset===0&&a.byteLength===a.buffer.byteLength?a:a.slice();await t.push(e.requestId,o)}await t.end(e.requestId)}catch(n){if(r.signal.aborted){try{await t.abort(e.requestId)}catch{}return}try{await t.abort(e.requestId)}catch{}throw n}}catch{if(!r.signal.aborted)try{await t.abort(e.requestId)}catch{}}finally{tg.delete(e.requestId)}},lg=(e,t=1e3,n=``)=>{let r=ng.get(e);if(r){ng.delete(e);try{r.close(t,n)}catch{}}},ug=async e=>{let t=qh();if(!(!t||!Kh(t.wsOpened)||!Kh(t.wsSend)||!Kh(t.wsClose))){if(!o()){try{await t.wsClose(e.requestId,{code:1011,reason:`relay inactive`})}catch{}return}lg(e.requestId,1001,`replaced`);try{try{await r()}catch{}let n=sg(e.path),i=e.protocols&&e.protocols.length>0?e.protocols:void 0,a=Re(n,i);ng.set(e.requestId,a),a.onopen=()=>{ng.get(e.requestId)===a&&t.wsOpened?.({requestId:e.requestId}).catch(()=>{lg(e.requestId,1011,`wsOpened failed`)})},a.onmessage=n=>{if(ng.get(e.requestId)!==a)return;let r=n.data;if(typeof r==`string`){t.wsSend?.(e.requestId,r,!1).catch(()=>{});return}if(r instanceof ArrayBuffer){t.wsSend?.(e.requestId,r,!0).catch(()=>{});return}if(ArrayBuffer.isView(r)){let n=r,i=n.byteOffset===0&&n.byteLength===n.buffer.byteLength?n.buffer:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);t.wsSend?.(e.requestId,i,!0).catch(()=>{})}},a.onerror=()=>{},a.onclose=n=>{ng.get(e.requestId)===a&&ng.delete(e.requestId),t.wsClose?.(e.requestId,{code:typeof n?.code==`number`?n.code:1006,reason:typeof n?.reason==`string`?n.reason:``}).catch(()=>{})}}catch{try{await t.wsClose?.(e.requestId,{code:1011,reason:`tunnel open failed`})}catch{}}}},dg=e=>{if(e instanceof ArrayBuffer)return e;let t=e,n=new Uint8Array(t.byteLength);return n.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),n.buffer},fg=e=>{let t=ng.get(e.requestId);if(t)try{if(typeof e.data==`string`){t.send(e.data);return}let n=ArrayBuffer.isView(e.data)||e.data instanceof ArrayBuffer?dg(e.data):null;if(!n)return;if(!e.binary){t.send(new TextDecoder().decode(n));return}t.send(n)}catch{}},pg=e=>{lg(e.requestId,e.code,e.reason)},mg=e=>{let t=e?.payload;Zh(t)&&cg(t)},hg=e=>{let t=e?.payload;if(!t||typeof t!=`object`)return;let n=t.requestId;if(typeof n!=`string`||!n)return;let r=tg.get(n);r&&(r.abort(),tg.delete(n))},gg=e=>{let t=e?.payload;Qh(t)&&ug(t)},_g=e=>{let t=e?.payload;$h(t)&&fg(t)},vg=e=>{let t=e?.payload;eg(t)&&pg(t)},yg=()=>rg||(rg=(async()=>{let e=qh(),t=Jh();if(!e||!t){rg=null;return}og();let n=async(e,n)=>{let r=await t(e,n);typeof r==`function`&&ig.push(r)};await n(Vh,mg),await n(Hh,hg),await n(Uh,gg),await n(Wh,_g),await n(Gh,vg)})().catch(e=>{throw rg=null,e}),rg),bg=async()=>{if(!o())return null;let e=qh();return e?(await yg(),ag||(ag=(async()=>{try{let t=await e.ensure(),n=typeof t?.origin==`string`?t.origin.trim():``;if(!n)return null;try{let e=new URL(n);if(e.hostname!==`127.0.0.1`&&e.hostname!==`localhost`)return null}catch{return null}return n}catch{return null}finally{ag=null}})(),ag)):null},xg=380,Sg=1400,Cg=600,wg=24,Tg=new Map,Eg=200,Dg=(e,t)=>t===`all`?!0:t===`errors`?e.level===`error`||e.level===`runtime`||e.level===`resource`:t===`warnings`?e.level===`warn`:e.level===`log`||e.level===`info`||e.level===`debug`,Og=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},kg=e=>Number.isFinite(e)?Math.min(Sg,Math.max(xg,Math.round(e))):Cg,Ag=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},jg=(e,t)=>{let n=kg(e),r=Ag(t);return r===null?n:Math.min(n,Math.max(1,r))},Mg=(e,t)=>{if(!e)return``;let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`).replace(/\/+$/,``);return r&&n.startsWith(r+`/`)?n.slice(r.length+1):n},Ng=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`btw`?`chat.btw.title`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),Pg=e=>{if(!e)return null;let t=e.replace(/\\/g,`/`).trim();if(!t)return null;let n=t.split(`/`).filter(Boolean);return n.length===0?t:n[n.length-1]||null},Fg=(e,t,n)=>{if(e.mode===`chat`){let r=Lg(e.dedupeKey);if(r){let e=t.get(r)?.trim();if(e)return e}return e.sessionTitleFallback?.trim()||n(`contextPanel.mode.chat`)}if(e.label)return e.label;if(e.mode===`file`)return Pg(e.targetPath)||n(`contextPanel.mode.files`);if(e.mode===`preview`){let t=e.targetPath;if(t)try{let e=new URL(t);return e.host||e.hostname||n(`contextPanel.mode.preview`)}catch{}return n(`contextPanel.mode.preview`)}return e.mode===`diff`?n(`contextPanel.mode.diff`):e.mode===`file-diff`?Pg(e.targetPath)||n(`contextPanel.mode.diff`):Ng(e.mode,n)},Ig=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Ji,{filePath:e.targetPath,className:`h-3.5 w-3.5`}):void 0;if(e.mode===`diff`||e.mode===`file-diff`)return(0,$.jsx)(Z,{name:`arrow-left-right`,className:`h-3.5 w-3.5`});if(e.mode===`context`)return(0,$.jsx)(Z,{name:`file-list-2`,className:`h-3.5 w-3.5`});if(e.mode===`chat`)return(0,$.jsx)(Z,{name:`chat-thread`,className:`h-3.5 w-3.5`});if(e.mode===`preview`)return(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5 text-[var(--status-info)]`});if(e.mode===`browser`)return(0,$.jsx)(Z,{name:`global`,className:`h-3.5 w-3.5`})},Lg=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,Rg=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},zg=(e,t)=>{if(t.length===0)return Tg;let n=new Set(t),r=new Map;for(let t of e){if(!n.has(t.id))continue;let e=t.title?.trim();e&&r.set(t.id,e)}return r.size===0?Tg:r},Bg=(e,t)=>{let n=fn(e),r=Q.useRef(Tg),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=zg(n.getState().session,i.current);return Rg(r.current,e)?r.current:(r.current=e,e)},[n]),()=>Tg)},Vg=`new Promise((resolve) => {
19
19
  const existing = document.getElementById('__yuri_desktop_browser_overlay');
20
20
  if (existing) existing.remove();
21
21
  if (typeof window.__yuriDesktopBrowserCancelInspect === 'function') {
@@ -99,14 +99,14 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,p as r,t
99
99
  window.addEventListener('mousemove', move, true);
100
100
  window.addEventListener('click', click, true);
101
101
  window.addEventListener('keydown', keydown, true);
102
- });`,Bg=`(() => {
102
+ });`,Hg=`(() => {
103
103
  if (typeof window.__yuriDesktopBrowserCancelInspect === 'function') {
104
104
  window.__yuriDesktopBrowserCancelInspect();
105
105
  return;
106
106
  }
107
107
  const overlay = document.getElementById('__yuri_desktop_browser_overlay');
108
108
  if (overlay) overlay.remove();
109
- })()`,Vg=`(() => {
109
+ })()`,Ug=`(() => {
110
110
  if (window.__yuriSameWebviewNavigationInstalled) return;
111
111
  window.__yuriSameWebviewNavigationInstalled = true;
112
112
 
@@ -138,24 +138,24 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,p as r,t
138
138
  event.preventDefault();
139
139
  event.stopPropagation();
140
140
  }, true);
141
- })()`,Hg=async(e,t)=>{let n=e.contentWindow;if(!n)throw Error(`Iframe window is not available`);let r=n.eval.call(n,t);return await Promise.resolve(r)},Ug=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,Wg=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},Gg=(e,t,n)=>{let r=Wg(t);e.postMessage(n,r)},Kg=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`yuri_preview_token`),t.searchParams.delete(`yuri_client_token`),t.searchParams.delete(`yuri_url_token`),t.toString()}catch{return e}},qg=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`yuriPreview`),t.searchParams.delete(`yuri_preview_token`),t.searchParams.delete(`yuri_client_token`),t.searchParams.delete(`yuri_url_token`),t.toString()}catch{return e}},Jg=({rawUrl:e,onNavigate:t})=>{let{t:n}=wt(),{currentTheme:i}=or(),[a,s]=Q.useReducer(e=>e+1,0),[l,u]=Q.useReducer(e=>e+1,0),[d,f]=Q.useState({status:`idle`}),[p,h]=Q.useState(``),g=Q.useRef(null),v=Q.useRef(1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(`all`),[T,E]=Q.useState([]),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),j=xn(e=>e.currentSessionId),M=xn(e=>e.newSessionDraft?.open),N=li(e=>e.addDraft),P=bn(e=>e.addAttachedFile),F=null;try{F=e?new URL(e):null}catch{F=null}let I=F?F.hostname===`localhost`||F.hostname===`127.0.0.1`||F.hostname===`::1`||F.hostname===`[::1]`||F.hostname===`0.0.0.0`:!1,L=F?F.hostname===`0.0.0.0`?new URL(F.toString().replace(`0.0.0.0`,`127.0.0.1`)):F:null,R=L?L.toString():``,z=R?`${m()||`same-origin`}|${R}`:``,B=i.metadata.variant;Q.useEffect(()=>{if(!R||!I){f({status:`idle`});return}let e=lh(z);if(e?.previewToken){f({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&oh.delete(z);let t=!1;return f({status:`loading`}),(async()=>{try{let e=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:R})});if(!e.ok){oh.delete(z);let n=await e.json().catch(()=>({})),r=typeof n?.error==`string`?n.error:`HTTP ${e.status}`;t||f({status:`error`,message:r});return}let r=await e.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.previewToken==`string`?r.previewToken:``,o=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i||!a){oh.delete(z),t||f({status:`error`,message:n(`contextPanel.preview.proxyError`)});return}oh.set(z,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||f({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(oh.delete(z),!t){let t=e instanceof Error?e.message:String(e);f({status:`error`,message:t})}}})(),()=>{t=!0}},[I,z,l,n,R]);let V=L&&(L.protocol===`http:`||L.protocol===`https:`)?L.toString():``,ee=I&&d.status===`ready`?`${d.proxyBasePath}|${d.previewToken||``}|${a}`:``;Q.useEffect(()=>{if(!ee){h(``);return}let e=!1;return h(``),r(m()).then(t=>{!e&&t&&h(ee)}).catch(()=>{}),()=>{e=!0}},[ee]);let H=I&&d.status===`ready`&&L&&p===ee?(()=>{let e=L.pathname||`/`,t=new URLSearchParams(L.search);t.delete(`yuri_url_token`),t.delete(`yuri_client_token`),t.set(`yuriPreview`,String(a)),t.set(`yuri_preview_token`,d.previewToken||``);let n=t.toString(),r=L.hash||``;return c().authenticatedAsset(`${d.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,te=I&&o()&&qh(),[ne,re]=Q.useState(``);Q.useEffect(()=>{if(!te){re(``);return}let e=!1;return re(``),vg().then(t=>{!e&&t&&re(t)}).catch(()=>{e||re(``)}),()=>{e=!0}},[te,ee]);let U=I?Rh({relayActive:te,gatewayOrigin:ne||null,authenticatedAssetUrl:H}):``,ie=te&&!!H&&!ne,ae=I?ie?``:U:V,W=I?Kg(U||H):V,oe=I&&(d.status===`loading`||d.status===`idle`||p!==ee||ie),se=I&&d.status===`error`,ce=Q.useCallback(t=>{let r=j??(M?`draft`:null);if(!r){X.error(n(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||ae||``,a=typeof window<`u`?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},o=typeof window<`u`?window.devicePixelRatio:1;(async()=>{let e=!1;try{let n=g.current,r=n?await rh(n,t):null;r&&(await P(r),e=!0)}catch{e=!1}N({sessionKey:r,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:nh({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:n(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),X.success(n(`contextPanel.preview.inspect.attached`))})()},[P,N,j,ae,M,e,n]);Q.useEffect(()=>{b(!1),E([]),S(!1),w(`all`),O(!1),A(null),v.current=1},[ae]),Q.useEffect(()=>{let e=g.current?.contentWindow;!y||!e||Gg(e,ae||H,{source:`yuri-preview-parent`,version:1,type:`set-inspect-mode`,enabled:D})},[y,ae,D,H]),Q.useEffect(()=>{let e=g.current?.contentWindow;!y||!e||Gg(e,ae||H,{source:`yuri-preview-parent`,version:1,type:`set-color-scheme`,scheme:B})},[y,ae,B,H]),Q.useEffect(()=>{if(!D||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[D]),Q.useEffect(()=>{if(!I||typeof window>`u`)return;let e=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},r=e=>{let t=v.current;v.current+=1,E(n=>{let r=[...n,{...e,id:t}];return r.length>wg?r.slice(r.length-wg):r})},i=i=>{if(i.source!==g.current?.contentWindow)return;let a=i.data;if(!(!a||a.source!==`yuri-preview-bridge`||a.version!==1)){if(a.type===`ready`){b(!0);return}if(a.type===`console`){let t=a.level===`error`||a.level===`warn`||a.level===`info`||a.level===`debug`?a.level:`log`,n=Array.isArray(a.args)?a.args.map(e).filter(Boolean):[];r({level:t,message:n.join(` `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`runtime-error`){let t=e(a.filename),i=typeof a.line==`number`?a.line:null,o=typeof a.column==`number`?a.column:null,s=t?`${t}${i===null?``:`:${i}${o===null?``:`:${o}`}`}`:``,c=e(a.stack);r({level:`runtime`,message:e(a.message)||n(`contextPanel.preview.console.runtimeError`),details:[s,c].filter(Boolean).join(`
142
- `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`resource-error`){let t=e(a.tag)||`resource`,n=e(a.url);r({level:`resource`,message:n?`${t}: ${n}`:t,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){A(th(a.target)?a.target:null);return}if(a.type===`select`&&th(a.target)){A(a.target),O(!1),ce(a.target);return}if(a.type===`navigate-preview`){let e=typeof a.url==`string`?a.url:``,n=a.navigation===`external`?`external`:`proxy`;if(e&&n===`external`){Go(e);return}e&&t(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[ce,I,t,n]);let G=T.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,le=T.filter(e=>Tg(e,C)),ue=Q.useCallback(()=>{let t=[`Preview URL: ${e||ae||``}`,`Events: ${T.length}`,``].join(`
141
+ })()`,Wg=async(e,t)=>{let n=e.contentWindow;if(!n)throw Error(`Iframe window is not available`);let r=n.eval.call(n,t);return await Promise.resolve(r)},Gg=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,Kg=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},qg=(e,t,n)=>{let r=Kg(t);e.postMessage(n,r)},Jg=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`yuri_preview_token`),t.searchParams.delete(`yuri_client_token`),t.searchParams.delete(`yuri_url_token`),t.toString()}catch{return e}},Yg=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`yuriPreview`),t.searchParams.delete(`yuri_preview_token`),t.searchParams.delete(`yuri_client_token`),t.searchParams.delete(`yuri_url_token`),t.toString()}catch{return e}},Xg=({rawUrl:e,onNavigate:t})=>{let{t:n}=Tt(),{currentTheme:i}=sr(),[a,s]=Q.useReducer(e=>e+1,0),[l,u]=Q.useReducer(e=>e+1,0),[d,f]=Q.useState({status:`idle`}),[p,h]=Q.useState(``),g=Q.useRef(null),v=Q.useRef(1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(`all`),[T,E]=Q.useState([]),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),j=Sn(e=>e.currentSessionId),M=Sn(e=>e.newSessionDraft?.open),N=Ki(e=>e.addDraft),P=xn(e=>e.addAttachedFile),F=null;try{F=e?new URL(e):null}catch{F=null}let I=F?F.hostname===`localhost`||F.hostname===`127.0.0.1`||F.hostname===`::1`||F.hostname===`[::1]`||F.hostname===`0.0.0.0`:!1,L=F?F.hostname===`0.0.0.0`?new URL(F.toString().replace(`0.0.0.0`,`127.0.0.1`)):F:null,R=L?L.toString():``,z=R?`${m()||`same-origin`}|${R}`:``,B=i.metadata.variant;Q.useEffect(()=>{if(!R||!I){f({status:`idle`});return}let e=dh(z);if(e?.previewToken){f({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&ch.delete(z);let t=!1;return f({status:`loading`}),(async()=>{try{let e=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:R})});if(!e.ok){ch.delete(z);let n=await e.json().catch(()=>({})),r=typeof n?.error==`string`?n.error:`HTTP ${e.status}`;t||f({status:`error`,message:r});return}let r=await e.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.previewToken==`string`?r.previewToken:``,o=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i||!a){ch.delete(z),t||f({status:`error`,message:n(`contextPanel.preview.proxyError`)});return}ch.set(z,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||f({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(ch.delete(z),!t){let t=e instanceof Error?e.message:String(e);f({status:`error`,message:t})}}})(),()=>{t=!0}},[I,z,l,n,R]);let V=L&&(L.protocol===`http:`||L.protocol===`https:`)?L.toString():``,ee=I&&d.status===`ready`?`${d.proxyBasePath}|${d.previewToken||``}|${a}`:``;Q.useEffect(()=>{if(!ee){h(``);return}let e=!1;return h(``),r(m()).then(t=>{!e&&t&&h(ee)}).catch(()=>{}),()=>{e=!0}},[ee]);let H=I&&d.status===`ready`&&L&&p===ee?(()=>{let e=L.pathname||`/`,t=new URLSearchParams(L.search);t.delete(`yuri_url_token`),t.delete(`yuri_client_token`),t.set(`yuriPreview`,String(a)),t.set(`yuri_preview_token`,d.previewToken||``);let n=t.toString(),r=L.hash||``;return c().authenticatedAsset(`${d.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,te=I&&o()&&Yh(),[ne,re]=Q.useState(``);Q.useEffect(()=>{if(!te){re(``);return}let e=!1;return re(``),bg().then(t=>{!e&&t&&re(t)}).catch(()=>{e||re(``)}),()=>{e=!0}},[te,ee]);let U=I?Bh({relayActive:te,gatewayOrigin:ne||null,authenticatedAssetUrl:H}):``,ie=te&&!!H&&!ne,ae=I?ie?``:U:V,W=I?Jg(U||H):V,oe=I&&(d.status===`loading`||d.status===`idle`||p!==ee||ie),se=I&&d.status===`error`,ce=Q.useCallback(t=>{let r=j??(M?`draft`:null);if(!r){X.error(n(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||ae||``,a=typeof window<`u`?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},o=typeof window<`u`?window.devicePixelRatio:1;(async()=>{let e=!1;try{let n=g.current,r=n?await ah(n,t):null;r&&(await P(r),e=!0)}catch{e=!1}N({sessionKey:r,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:ih({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:n(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),X.success(n(`contextPanel.preview.inspect.attached`))})()},[P,N,j,ae,M,e,n]);Q.useEffect(()=>{b(!1),E([]),S(!1),w(`all`),O(!1),A(null),v.current=1},[ae]),Q.useEffect(()=>{let e=g.current?.contentWindow;!y||!e||qg(e,ae||H,{source:`yuri-preview-parent`,version:1,type:`set-inspect-mode`,enabled:D})},[y,ae,D,H]),Q.useEffect(()=>{let e=g.current?.contentWindow;!y||!e||qg(e,ae||H,{source:`yuri-preview-parent`,version:1,type:`set-color-scheme`,scheme:B})},[y,ae,B,H]),Q.useEffect(()=>{if(!D||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[D]),Q.useEffect(()=>{if(!I||typeof window>`u`)return;let e=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},r=e=>{let t=v.current;v.current+=1,E(n=>{let r=[...n,{...e,id:t}];return r.length>Eg?r.slice(r.length-Eg):r})},i=i=>{if(i.source!==g.current?.contentWindow)return;let a=i.data;if(!(!a||a.source!==`yuri-preview-bridge`||a.version!==1)){if(a.type===`ready`){b(!0);return}if(a.type===`console`){let t=a.level===`error`||a.level===`warn`||a.level===`info`||a.level===`debug`?a.level:`log`,n=Array.isArray(a.args)?a.args.map(e).filter(Boolean):[];r({level:t,message:n.join(` `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`runtime-error`){let t=e(a.filename),i=typeof a.line==`number`?a.line:null,o=typeof a.column==`number`?a.column:null,s=t?`${t}${i===null?``:`:${i}${o===null?``:`:${o}`}`}`:``,c=e(a.stack);r({level:`runtime`,message:e(a.message)||n(`contextPanel.preview.console.runtimeError`),details:[s,c].filter(Boolean).join(`
142
+ `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`resource-error`){let t=e(a.tag)||`resource`,n=e(a.url);r({level:`resource`,message:n?`${t}: ${n}`:t,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){A(rh(a.target)?a.target:null);return}if(a.type===`select`&&rh(a.target)){A(a.target),O(!1),ce(a.target);return}if(a.type===`navigate-preview`){let e=typeof a.url==`string`?a.url:``,n=a.navigation===`external`?`external`:`proxy`;if(e&&n===`external`){qo(e);return}e&&t(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[ce,I,t,n]);let G=T.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,le=T.filter(e=>Dg(e,C)),ue=Q.useCallback(()=>{let t=[`Preview URL: ${e||ae||``}`,`Events: ${T.length}`,``].join(`
143
143
  `),r=T.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
144
- `);Ct(`${t}${r}`).then(e=>{e.ok?X.success(n(`contextPanel.preview.console.copied`)):X.error(n(`contextPanel.preview.console.copyFailed`))})},[T,ae,e,n]),de=Q.useCallback(()=>{let t=j??(M?`draft`:null);if(!t){X.error(n(`contextPanel.preview.console.attachNoSession`));return}let r=[`Preview URL: ${e||ae||``}`,`Events: ${T.length}`,``].join(`
144
+ `);wt(`${t}${r}`).then(e=>{e.ok?X.success(n(`contextPanel.preview.console.copied`)):X.error(n(`contextPanel.preview.console.copyFailed`))})},[T,ae,e,n]),de=Q.useCallback(()=>{let t=j??(M?`draft`:null);if(!t){X.error(n(`contextPanel.preview.console.attachNoSession`));return}let r=[`Preview URL: ${e||ae||``}`,`Events: ${T.length}`,``].join(`
145
145
  `),i=T.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
146
- `);N({sessionKey:t,source:`preview-console`,fileLabel:e||ae||`preview`,startLine:1,endLine:Math.max(1,T.length),code:`${r}${i}`,language:`text`,text:n(`contextPanel.preview.console.attachAnnotation`)}),X.success(n(`contextPanel.preview.console.attached`))},[N,T,j,ae,M,e,n]),[fe,pe]=Q.useState(`unknown`),me=Q.useRef(0),he=Q.useRef(0);Q.useEffect(()=>{if(!H){pe(`unknown`),me.current=0,he.current=0;return}let e=!1;return me.current||(me.current=Date.now(),he.current=0),pe(`unknown`),(async()=>{let t=await(async()=>{try{return await _(H,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){pe(`unreachable`);return}if(t.status===403||t.status===404){oh.delete(z),f({status:`loading`}),u();return}if(t.status!==502){pe(`reachable`);return}let n=me.current||Date.now();if(Date.now()-n<15e3){pe(`starting`),he.current+=1;let t=he.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||s()},n).unref?.();return}pe(`unreachable`)})(),()=>{e=!0}},[z,H,a]);let ge=I&&d.status===`ready`&&(fe===`unknown`||fe===`starting`),_e=I&&d.status===`ready`&&fe===`unreachable`,ve=Q.useCallback(e=>{if(!I||d.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=Wg(ae||H);if(e.origin!==n||e.pathname.startsWith(d.proxyBasePath))return;let r=`${d.proxyBasePath}${e.pathname}${e.search}${e.hash}`;t.location.replace(r)}catch{}},[ae,I,H,d]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,title:W||e,children:W||e||n(`contextPanel.preview.empty`)}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>s(),title:n(`contextPanel.preview.actions.reload`),"aria-label":n(`contextPanel.preview.actions.reload`),disabled:!ae,children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>{V&&Go(V)},title:n(`contextPanel.preview.actions.openExternal`),"aria-label":n(`contextPanel.preview.actions.openExternal`),disabled:!V,children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})}),I?(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:D?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>O(e=>!e),title:n(`contextPanel.preview.inspect.toggle`),"aria-label":n(`contextPanel.preview.inspect.toggle`),disabled:!y,children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,I?(0,$.jsxs)(Y,{type:`button`,size:`sm`,variant:x?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>S(e=>!e),title:n(y?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":n(y?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!y&&T.length===0,children:[(0,$.jsx)(Z,{name:`terminal-box`,className:`h-3.5 w-3.5`}),G>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:G}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[ge?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.startingServerHint`)})]}):_e?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>s(),children:n(`contextPanel.preview.actions.retry`)})]}):ae&&(!I||fe===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:g,src:ae,title:n(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:B},onLoad:ve,sandbox:I?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${ae}:${a}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.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:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):oe?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.loading`)}):se?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.proxyError`)}),d.status===`error`?(0,$.jsx)(`div`,{className:`text-center text-xs opacity-70`,children:d.message}):null]}):(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.invalidUrl`)}),x?(0,$.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:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:de,disabled:T.length===0,children:n(`contextPanel.preview.console.attach`)}),(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:ue,disabled:T.length===0,children:n(`contextPanel.preview.console.copy`)}),(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>E([]),disabled:T.length===0,children:n(`contextPanel.preview.console.clear`)})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/30 px-3 py-1.5`,children:[`all`,`errors`,`warnings`,`logs`].map(e=>(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:C===e?`secondary`:`ghost`,onClick:()=>w(e),children:n(e===`all`?`contextPanel.preview.console.filter.all`:e===`errors`?`contextPanel.preview.console.filter.errors`:e===`warnings`?`contextPanel.preview.console.filter.warnings`:`contextPanel.preview.console.filter.logs`)},e))}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-auto p-2 typography-code text-xs`,children:T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.empty`)}):le.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.noFilteredEvents`)}):le.map(e=>(0,$.jsx)(`div`,{className:`border-b border-border/30 px-2 py-1 last:border-b-0`,children:(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:J(`shrink-0 uppercase`,e.level===`error`||e.level===`runtime`||e.level===`resource`?`text-status-error`:e.level===`warn`?`text-status-warning`:`text-muted-foreground`),children:e.level}),(0,$.jsx)(`span`,{className:`min-w-0 break-words text-foreground`,children:e.message})]})},e.id))})]}):null]})]})},Yg=()=>typeof window<`u`&&!!window.__YURI_ELECTRON__,Xg=({initialUrl:e,directory:t,tabID:n})=>{let{t:i}=wt(),a=Q.useRef(null),s=q(e=>e.setContextPanelTabTargetPath),l=Xm(e),u=l===`about:blank`?``:l,[d,f]=Q.useState(u),[p,h]=Q.useState(u),[g,v]=Q.useState(u),[y,b]=Q.useState(()=>u?[u]:[]),[x,S]=Q.useState(()=>u?0:-1),[C,w]=Q.useReducer(e=>e+1,0),[T,E]=Q.useState(!!u),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState({status:`idle`}),[N,P]=Q.useState(``),F=xn(e=>e.currentSessionId),I=xn(e=>e.newSessionDraft?.open),L=li(e=>e.addDraft),R=bn(e=>e.addAttachedFile),z=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||s(t,n,e)},[t,n,s]),B=Q.useCallback((e,t)=>{let n=Xm(e),r=n===`about:blank`?``:n;h(r),f(r),t?.inFrame?E(!1):(v(r),E(!!r)),z(r),b(e=>{if(!r)return S(-1),[];if(t?.replaceHistory)return e;let n=x>=0?e.slice(0,x+1):[];if(n[n.length-1]===r)return S(n.length-1),n;let i=[...n,r];return S(i.length-1),i})},[x,z]),V=Q.useRef(p);V.current=p,Q.useEffect(()=>{let t=Zm(e,V.current);t!==null&&B(t)},[e,B]);let ee=Q.useCallback(e=>{let t=y[e];t&&(S(e),h(t),v(t),f(t),E(!0),z(t))},[y,z]),H=Q.useCallback(()=>{if(p){E(!0);try{a.current?.contentWindow?.location.reload()}catch{w()}}},[p]);Q.useEffect(()=>{if(!g){M({status:`idle`});return}let e=uh(g),t=lh(e);if(t?.previewToken){M({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&oh.delete(e);let n=!1;return M({status:`loading`}),E(!0),(async()=>{try{let t=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:g,allowExternal:!0})});if(!t.ok){let e=await t.json().catch(()=>({})),r=typeof e?.error==`string`?e.error:`HTTP ${t.status}`;n||M({status:`error`,message:r});return}let r=await t.json(),a=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,o=typeof r.previewToken==`string`?r.previewToken:``,s=typeof r.expiresAt==`number`?r.expiresAt:0;if(!a||!o){n||M({status:`error`,message:i(`contextPanel.preview.proxyError`)});return}oh.set(e,{proxyBasePath:a,previewToken:o,expiresAt:s}),n||M({status:`ready`,proxyBasePath:a,previewToken:o,expiresAt:s})}catch(e){if(!n){let t=e instanceof Error?e.message:String(e);M({status:`error`,message:t})}}})(),()=>{n=!0}},[g,i]);let te=g&&j.status===`ready`?`${j.proxyBasePath}|${j.previewToken||``}|${C}`:``;Q.useEffect(()=>{if(!te){P(``);return}let e=!1;return P(``),r(m()).then(t=>{!e&&t&&P(te)}).catch(()=>{}),()=>{e=!0}},[te]);let ne=Q.useMemo(()=>{if(N!==te||!g||j.status!==`ready`)return``;try{let e=new URL(g),t=e.pathname||`/`,n=new URLSearchParams(e.search);n.delete(`yuri_url_token`),n.delete(`yuri_client_token`),n.set(`yuriPreview`,String(C)),n.set(`yuri_preview_token`,j.previewToken||``);let r=n.toString();return c().authenticatedAsset(`${j.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,j,te,C,N]),re=o()&&qh(),[U,ie]=Q.useState(``);Q.useEffect(()=>{if(!re){ie(``);return}let e=!1;return ie(``),vg().then(t=>{!e&&t&&ie(t)}).catch(()=>{e||ie(``)}),()=>{e=!0}},[re,te]);let ae=ne?Rh({relayActive:re,gatewayOrigin:U||null,authenticatedAssetUrl:ne}):``,W=re&&!!ne&&!U,oe=W?``:ae||(j.status===`error`&&!re?g:``),se=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath,r=Wg(oe||ne);if(!(t.origin===window.location.origin||r&&t.origin===r)||!t.pathname.startsWith(n))return``;let i=t.pathname.slice(n.length)||`/`,a=new URL(g).origin;return qg(new URL(`${i}${t.search}${t.hash}`,a).toString())}catch{return``}},[oe,g,ne,j]),ce=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=new URL(g).origin,r=Wg(oe||ne);if(!(t.origin===window.location.origin||r&&t.origin===r)||n===window.location.origin)return``;let i=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath;return t.pathname.startsWith(i)?``:qg(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[oe,g,ne,j]),G=Q.useCallback(e=>{let t=a.current?.contentWindow;t&&Gg(t,oe||ne,{source:`yuri-preview-parent`,version:1,type:`set-inspect-mode`,enabled:e})},[oe,ne]),le=Q.useCallback(async e=>{let t=F??(I?`draft`:null);if(!t){X.error(i(`contextPanel.preview.inspect.attachNoSession`));return}let n=a.current,r=n?.contentWindow,o=n?.getBoundingClientRect(),s={width:Number.isFinite(r?.innerWidth)?r?.innerWidth??o?.width??0:o?.width??0,height:Number.isFinite(r?.innerHeight)?r?.innerHeight??o?.height??0:o?.height??0},c=n?await rh(n,e):null,l=!!c;c&&await R(c),L({sessionKey:t,source:`preview-annotation`,fileLabel:p||`browser`,startLine:1,endLine:1,code:nh({pageUrl:p,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:i(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),X.success(i(`contextPanel.preview.inspect.attached`))},[R,L,F,p,I,i]),ue=Q.useCallback(()=>{let e=a.current;A(null),G(!1),e&&Hg(e,Bg).catch(()=>{})},[G]);Q.useEffect(()=>{if(!D)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1),ue())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ue,D]),Q.useEffect(()=>()=>ue(),[ue]),Q.useEffect(()=>{let e=e=>{if(e.source!==a.current?.contentWindow)return;let t=e.data;if(!(!t||t.source!==`yuri-preview-bridge`||t.version!==1)){if(t.type===`ready`){let e=typeof t.url==`string`?t.url:``,n=se(e);n&&n!==p&&B(n,{inFrame:!0});return}if(t.type===`hover`){A(th(t.target)?t.target:null);return}if(t.type===`select`&&th(t.target)){A(null),O(!1),G(!1),le(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ce(e);if(n){B(n);return}e&&B(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[B,le,p,se,ce,G]);let de=Q.useCallback(()=>{let e=a.current;if(!(!e||!p)){if(D){O(!1),ue();return}if(ne){A(null),O(!0),G(!0);return}O(!0),(async()=>{try{let t=await Hg(e,zg);if(O(!1),!t||!th(t))return;await le(t)}catch{O(!1),X.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[le,ue,p,D,G,ne,i]),fe=Q.useCallback(()=>{try{let e=a.current?.contentWindow?.location.href||``,t=ce(e);if(t){B(t,{inFrame:!0});return}}catch{}E(!1),D&&ne&&G(!0)},[B,ce,D,G,ne]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<=0,onClick:()=>ee(x-1),children:(0,$.jsx)(Z,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<0||x>=y.length-1,onClick:()=>ee(x+1),children:(0,$.jsx)(Z,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:H,children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),B(d)},children:(0,$.jsx)(`input`,{value:d,onChange:e=>f(e.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":i(`contextPanel.browser.addressAria`)})}),(0,$.jsx)(Y,{type:`button`,variant:D?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:de,title:i(`contextPanel.preview.inspect.toggle`),"aria-label":i(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:()=>void Go(p),children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[oe?(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(`iframe`,{ref:a,src:oe,title:i(`contextPanel.browser.empty`),className:`absolute inset-0 h-full w-full border-0 bg-background`,allow:`clipboard-read; clipboard-write; fullscreen`,allowFullScreen:!0,onLoad:fe},`${n}:${C}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.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:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(xa,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:i(`contextPanel.browser.empty`)}),(0,$.jsx)(`span`,{className:`max-w-sm typography-micro text-muted-foreground`,children:i(`contextPanel.browser.emptyHint`)}),(0,$.jsx)(`span`,{className:`max-w-md typography-micro leading-relaxed text-status-warning/70`,children:i(`contextPanel.browser.trustNotice`)})]}),T||W?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:i(`common.loading`)}):null]})]})},Zg=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=wt(),i=Q.useRef(null),a=q(e=>e.setContextPanelTabTargetPath),o=Xm(e),s=o===`about:blank`?``:o,c=Q.useRef(Xm(e)),[l,u]=Q.useState(s),[d,f]=Q.useState(s),[p,m]=Q.useState(!1),[h,g]=Q.useState(!0),_=Q.useRef(null),v=h,y=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||a(t,n,e)},[t,n,a]),b=xn(e=>e.currentSessionId),x=xn(e=>e.newSessionDraft?.open),S=li(e=>e.addDraft),C=bn(e=>e.addAttachedFile);Q.useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{try{let t=e.getURL();t&&t!==`about:blank`&&(f(t),u(t),y(t))}catch{}},n=e=>{let t=e.detail;typeof t?.url==`string`&&t.url&&(f(t.url),u(t.url),y(t.url))},r=()=>{_.current&&clearTimeout(_.current),_.current=setTimeout(()=>g(!0),200)},a=()=>{_.current&&clearTimeout(_.current),g(!1),t()},o=e=>{let t=e.detail;if(t?.disposition===`new-window`||t?.disposition===`foreground-tab`||t?.disposition===`background-tab`){e.preventDefault();let n=i.current;typeof n?.loadURL==`function`&&t.url&&n.loadURL(t.url)}},s=()=>{try{e.executeJavaScript?.(Vg,!0).catch(()=>{})}catch{}};e.addEventListener(`did-navigate`,n),e.addEventListener(`did-navigate-in-page`,n),e.addEventListener(`did-start-loading`,r),e.addEventListener(`did-stop-loading`,a),e.addEventListener(`new-window`,o),e.addEventListener(`dom-ready`,s);try{e.isLoading()||(g(!1),t())}catch{}return s(),()=>{_.current&&clearTimeout(_.current),e.removeEventListener(`did-navigate`,n),e.removeEventListener(`did-navigate-in-page`,n),e.removeEventListener(`did-start-loading`,r),e.removeEventListener(`did-stop-loading`,a),e.removeEventListener(`new-window`,o),e.removeEventListener(`dom-ready`,s)}},[y]),Q.useEffect(()=>{let e=setTimeout(()=>g(!1),3e4);return()=>clearTimeout(e)},[]),Q.useEffect(()=>{if(!p)return;let e=e=>{if(e.key!==`Escape`)return;e.preventDefault(),e.stopImmediatePropagation(),m(!1);let t=i.current;try{t?.executeJavaScript?.(Bg).catch(()=>{})}catch{}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[p]),Q.useEffect(()=>{let e=i.current;return()=>{try{let r=e?.getURL?.();r&&r!==`about:blank`&&a(t,n,r)}catch{}try{e?.executeJavaScript?.(Bg).catch(()=>{})}catch{}}},[t,n,a]);let w=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=Xm(e);try{t.loadURL(n)}catch{}},[]),T=Q.useRef(d);T.current=d,Q.useEffect(()=>{let t=Zm(e,T.current);t!==null&&(f(t),u(t),g(!0),w(t))},[e,w]);let E=Q.useCallback(()=>{let e=i.current;if(e){if(p){m(!1);try{e.executeJavaScript?.(Bg).catch(()=>{})}catch{}return}m(!0),e.executeJavaScript?.(zg,!0).then(async t=>{if(m(!1),!t||!th(t))return;let n=b??(x?`draft`:null);if(!n){X.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await bt(`desktop_browser_capture_page`,{webContentsId:i}),o=await e.executeJavaScript?.(`({ width: window.innerWidth, height: window.innerHeight })`,!0).catch(()=>null),s=Number.isFinite(o?.width)?o.width:a.width,c=Number.isFinite(o?.height)?o.height:a.height,l=await ih(a.base64,a.width,a.height,s,c,t),u=!!l;l&&await C(l),S({sessionKey:n,source:`preview-annotation`,fileLabel:d||`browser`,startLine:1,endLine:1,code:nh({pageUrl:d,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),X.success(r(`contextPanel.preview.inspect.attached`))}).catch(()=>m(!1))}},[C,S,b,d,p,x,r]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goBack?.()}catch{}},children:(0,$.jsx)(Z,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goForward?.()}catch{}},children:(0,$.jsx)(Z,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.reload?.()}catch{}},children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),w(l)},children:(0,$.jsx)(`input`,{value:l,onChange:e=>u(e.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`)})}),(0,$.jsx)(Y,{type:`button`,variant:p?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:E,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>void Go(d),children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[(0,$.jsx)(`webview`,{ref:i,src:c.current,partition:`persist:yuri-browser`,allowpopups:!0,style:{width:`100%`,height:`100%`,border:`none`}}),(!d||d===`about:blank`)&&!h?(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(xa,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)})]}):null,v?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:r(`common.loading`)}):null]})]})},Qg=({directory:e})=>{let{t}=wt(),n=xn(e=>e.currentSessionId),r=Qo()??``,i=e?.trim()||r,a=Q.useMemo(()=>Eg(i),[i]),s=q(e=>a?e.contextPanelByDirectory[a]:void 0),c=q(e=>a?e.contextToolDiffByDirectory[a]:void 0),l=q(e=>e.closeContextPanel),u=q(e=>e.closeContextPanelTab),d=q(e=>e.openContextPanelTab),p=q(e=>e.toggleContextPanelExpanded),m=q(e=>e.setContextPanelWidth),h=q(e=>e.setActiveContextPanelTab),g=q(e=>e.reorderContextPanelTabs),_=vo(e=>e.setSelectedPath),v=q(e=>e.openContextPreview),y=q(e=>e.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:x,lightThemeId:S,darkThemeId:C,currentTheme:w}=or(),T=Q.useMemo(()=>s?.tabs??[],[s?.tabs]),E=T.find(e=>e.id===s?.activeTabId)??T[T.length-1]??null,D=!!(s?.isOpen&&E),O=!!(D&&s?.expanded),k=Dg(s?.width??xg),A=Q.useMemo(()=>{let e=[];for(let t of T){if(t.mode!==`chat`)continue;let n=Fg(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[T]),j=Rg(a||void 0,A),[M,N]=Q.useState(!1),[P,F]=Q.useState(!1),I=Q.useRef(0),L=Q.useRef(k),R=Q.useRef(null),z=Q.useRef(null),B=Q.useRef(null),V=Q.useRef(new Map),ee=Q.useRef(new Map),H=Q.useRef(!1),te=Q.useRef(D),ne=Q.useRef(null),[re,U]=Q.useState({}),ie=Q.useRef(re);ie.current=re;let[ae,W]=Q.useReducer(Wm,{activeViewKey:null,tabs:{},mountedViews:{}}),oe=fm(),se=f(),ce=Q.useCallback(e=>{let t=ie.current,n=e(t);return n!==t&&(ie.current=n,U(n),!0)},[]),G=Q.useCallback(e=>{if(!a)return;if(q.getState().contextPanelByDirectory[a]?.tabs.find(t=>t.id===e)?.mode===`btw`){let e=xn.getState().currentSessionId;e&&ai.getState().clear({sessionId:e,directory:a})}W({type:`close-tab`,tabId:e});let t=pm(a,e);ce(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),u(a,e)},[u,ce,a]),le=Q.useCallback(()=>{F(!0),ne.current!==null&&window.cancelAnimationFrame(ne.current),ne.current=window.requestAnimationFrame(()=>{ne.current=null,F(!1)})},[]);Q.useEffect(()=>()=>{ne.current!==null&&window.cancelAnimationFrame(ne.current)},[]),Q.useLayoutEffect(()=>{let e=te.current;if(te.current=D,!D){F(!1);return}e||le()},[D,le]),Q.useEffect(()=>{if(!D||H.current){H.current=D;return}let e=window.requestAnimationFrame(()=>{let e=B.current;e&&!e.contains(document.activeElement)&&e.focus({preventScroll:!0})});return H.current=!0,()=>window.cancelAnimationFrame(e)},[D]);let ue=Q.useCallback(e=>{let t=B.current;t&&t.style.setProperty(`--yuri-context-panel-width`,`${kg(e,t)}px`)},[]),de=Q.useCallback(e=>{if(!(!D||O||!a)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}z.current=e.pointerId,N(!0),I.current=e.clientX,L.current=k,R.current=k,ue(k),e.preventDefault()}},[ue,a,O,D,k]),fe=Q.useCallback(e=>{if(!M||z.current!==e.pointerId)return;let t=I.current-e.clientX,n=kg(L.current+t,B.current);R.current!==n&&(R.current=n,ue(n))},[ue,M]),pe=Q.useCallback(e=>{if(z.current!==e.pointerId||!a)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=kg(R.current??k,B.current);le(),ue(t),R.current=t,m(a,t),N(!1),z.current=null},[ue,a,m,le,k]);Q.useEffect(()=>{M||(R.current=null)},[M]);let me=Q.useCallback(()=>{if(!a)return;let e=xn.getState().currentSessionId;e&&ai.getState().cancel({sessionId:e,directory:a}),l(a)},[l,a]),he=Q.useCallback(()=>{a&&p(a)},[a,p]),ge=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&E&&a){e.preventDefault(),e.stopPropagation(),G(E.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),me())},[E,G,a,me]);Q.useEffect(()=>{if(!(!a||!E)&&E.mode===`file`&&E.targetPath){_(a,E.targetPath,{allowOutsideRoot:!0});return}},[E,a,_]);let _e=E?.mode===`chat`?E.id:null,ve=bm(_e?re[pm(a,_e)]:void 0,_e?Fg(E?.dedupeKey):null);Q.useEffect(()=>{if(!D||!a||!ve){Yt(``,null);return}return Yt(a,ve),()=>{Yt(``,null)}},[ve,a,D]),Q.useEffect(()=>{if(!D||!a||!ve||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){rn(a,ve,!1);return}Wn(ve),rn(a,ve,!0)};e();let t=window.setInterval(e,1e4);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),document.addEventListener(`visibilitychange`,e),()=>{window.clearInterval(t),window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e),document.removeEventListener(`visibilitychange`,e),rn(a,ve,!1)}},[ve,a,D]);let ye=Q.useCallback((e,t,n)=>io(ee.current,e,t,a||null,n,{mode:b,lightThemeId:S,darkThemeId:C,currentTheme:w}),[w,C,a,S,b]);Q.useEffect(()=>{let e=new Set(T.map(e=>e.id));for(let t of ee.current.keys())e.has(t)||ee.current.delete(t)},[T]);let be=Q.useCallback(e=>{!a||E?.mode!==`diff`&&E?.mode!==`file-diff`||d(a,{mode:E.mode,targetPath:E.targetPath,stagedDiff:e===`staged`,diffScope:e})},[E,a,d]),xe=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:b,lightThemeId:S,darkThemeId:C,currentTheme:w};for(let t of V.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__yuriApplyThemeSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`yuri:theme-sync`,payload:e},window.location.origin)}},[w,C,S,b]),Se=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:y};for(let t of V.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__yuriApplyChatSettingsSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`yuri:chat-settings-sync`,payload:e},window.location.origin)}},[y]),Ce=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of V.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:_e===e},i=n.__yuriSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:ro,payload:r},window.location.origin)}},[_e]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(V.current.values()).some(t=>t.contentWindow===e.source))return;let t=e.data;if(t?.type===`yuri:close-embedded-session-chat`){let t=Array.from(V.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&a&&G(t[0]);return}if(t?.type===`yuri:chat-settings-request`){Se();return}if(t?.type===`yuri:embedded-visibility-request`){Ce();return}if(t?.type!==`yuri:cycle-theme-request`)return;let n=[`light`,`dark`,`system`],r=(n.indexOf(b)+1)%n.length;x(n[r])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[G,a,Se,Ce,x,b]),Q.useLayoutEffect(()=>{T.some(e=>e.mode===`chat`)&&(xe(),Se(),Ce())},[C,S,Se,Ce,xe,T,b]);let we=Q.useMemo(()=>T.map(e=>{let n=Ng(e,j,t),r=Ug(n,Sg),a=Ag(e.targetPath,i);return{id:e.id,label:r,icon:Pg(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:r})}}),[i,j,t,T]),Te=E?.mode===`btw`?n?(0,$.jsx)(Hr,{scope:{sessionId:n,directory:a}}):(0,$.jsx)(`p`,{className:`p-4 text-muted-foreground`,children:t(`chat.btw.sessionRequired`)}):E?.mode===`context`?(0,$.jsx)(Qp,{}):E?.mode===`preview`?(0,$.jsx)(Jg,{rawUrl:E.targetPath??``,onNavigate:e=>v(i,e)}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(Z,{name:`global`,className:`h-12 w-12 text-muted-foreground/50`}),(0,$.jsx)(`div`,{className:`typography-ui-header text-foreground`,children:t(`contextPanel.preview.title`)}),(0,$.jsx)(`div`,{className:`max-w-sm typography-micro text-muted-foreground`,children:t(`contextPanel.preview.description`)})]}),Ee=Q.useMemo(()=>T.filter(e=>e.mode===`chat`),[T]),De=Q.useMemo(()=>T.filter(e=>e.mode===`browser`),[T]),Oe=Q.useMemo(()=>T.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[T]),ke=Qm({isElectron:Yg(),relayActive:o()})?Zg:Xg,Ae=D&&E?.mode===`browser`&&ke===Zg;Q.useLayoutEffect(()=>{if(!Ae)return;let e=document.documentElement;return e.setAttribute(`data-yuri-native-browser-visible`,``),()=>e.removeAttribute(`data-yuri-native-browser-visible`)},[Ae]);let je=Q.useMemo(()=>T.some(e=>e.mode===`file`),[T]),Me=E?.mode===`file`,[Ne,K]=Q.useState(null),Pe=Me?E.targetPath:Ne?.directory===a&&T.some(e=>e.mode===`file`&&e.targetPath===Ne.path)?Ne.path:null;Q.useEffect(()=>{K(e=>e?.directory===a&&e.path===Pe?e:{directory:a,path:Pe??null})},[a,Pe]);let Fe=Me?E?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(Ee.map(e=>pm(a,e.id)));ce(t=>{let n=!1,r={};for(let e of Ee){let i=Fg(e.dedupeKey);if(!i)continue;let o=pm(a,e.id),s=t[o];r[o]=s??vm({sessionId:i,directory:a}),n||=!s}let i=Tm(t,e);return n||=i!==t,n?{...i,...r}:t});for(let t of Object.keys(ae.tabs))(!e.has(pm(a,t))||ae.tabs[t]?.directory!==a)&&W({type:`close-tab`,tabId:t})},[Ee,ce,a,ae.tabs]);let Ie=_e?pm(a,_e):null,Le=_e?Fg(E?.dedupeKey):null,Re=Ie&&Le?ym(re[Ie],{sessionId:Le,directory:a}):void 0,ze=Re&&Ie?mm(se,Ie,Re.current.directory,Re.current.sessionId):null;Q.useLayoutEffect(()=>{if(oe!==`react-surface`||!D||!_e||!Re||!Ie||!ze){oe===`react-surface`&&W({type:`activate`,viewKey:null,now:Date.now()});return}ce(e=>e[Ie]?e:{...e,[Ie]:Re}),W({type:`touch`,tab:{tabId:_e,sessionId:Re.anchor.sessionId,directory:Re.anchor.directory},view:{tabId:_e,surfaceId:Ie,sessionId:Re.current.sessionId,directory:Re.current.directory,viewKey:ze},now:Date.now()})},[Re,Ie,_e,ze,oe,ce,D]);let Be=Q.useCallback((e,t,n)=>{let r=pm(a,e),i=!1;return ce(e=>{let a=wm(e,r,{sessionId:t,directory:n});return i=a.accepted,a.navigationBySurfaceId}),i},[ce,a]),Ve=Q.useCallback(e=>{let t=pm(a,e);ce(e=>{let n=e[t];if(!n)return e;let r=Sm(n);return r===n?e:{...e,[t]:r}})},[ce,a]),He=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(rs,{items:we,activeId:E?.id??null,onSelect:e=>{a&&h(a,e)},onClose:e=>{G(e)},onReorder:(e,t)=>{a&&g(a,e,t)},layoutMode:`scrollable`,variant:`default`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:he,className:`h-7 w-7 p-0`,title:t(O?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":t(O?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:O?(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`fullscreen`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:me,className:`h-7 w-7 p-0`,title:t(`contextPanel.actions.closePanel`),"aria-label":t(`contextPanel.actions.closePanel`),children:(0,$.jsx)(Z,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),Ue=D?O?{"--yuri-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--yuri-context-panel-width), 100%)`,minWidth:`min(${yg}px, 100%)`,maxWidth:`100%`,"--yuri-context-panel-width":`${M?R.current??k:k}px`}:{"--yuri-context-panel-width":`${M?R.current??k:k}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:`hidden`,visibility:`hidden`};return(0,$.jsxs)(`aside`,{ref:B,"data-context-panel":`true`,"data-native-browser-visible":Ae?`true`:void 0,tabIndex:-1,inert:!D||void 0,className:J(`flex min-h-0 flex-col overflow-hidden bg-background`,!O&&`yuri-layout-divider-l`,O?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!D&&`pointer-events-none`,M||!D||P?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:ge,style:Ue,children:[!O&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80`,M&&`bg-[var(--interactive-border)]`),onPointerDown:de,onPointerMove:fe,onPointerUp:pe,onPointerCancel:pe,role:`separator`,"aria-orientation":`vertical`,"aria-label":t(`contextPanel.actions.resizePanelAria`)}),He,Fe===`turn-diff-outside-workspace`?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-status-info/20 bg-status-info/10 px-3 py-2 typography-meta text-status-info`,children:t(`contextPanel.file.notice.turnDiffOutsideWorkspace`)}):null,(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1 overflow-hidden`,M&&`pointer-events-none`),children:[je&&Pe?(0,$.jsx)(`div`,{className:J(`absolute inset-0`,Me?`block`:`hidden`),children:(0,$.jsx)(wp,{mode:`editor-only`,targetPath:Pe,isActive:D&&Me},`${a}:${Pe??``}`)}):null,oe===`legacy-iframe`&&Ee.map(e=>{let n=Fg(e.dedupeKey);if(!n)return null;let r=ye(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){V.current.delete(e.id);return}V.current.set(e.id,t)},src:r,title:t(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:J(`absolute inset-0 h-full w-full border-0 bg-background`,_e===e.id?`block`:`hidden`),onLoad:()=>{xe(),Se(),Ce()}},e.id):null}),oe===`react-surface`?Object.values(ae.mountedViews).map(e=>{let t=re[pm(a,e.tabId)],n=D&&_e===e.tabId&&ze===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(qm,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:n,canNavigateBack:n&&!!t?.stack.length,onNavigateSession:(t,n)=>Be(e.tabId,t,n),onNavigateBack:()=>Ve(e.tabId),onEstimateBytes:(e,t)=>W({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,De.map(e=>(0,$.jsx)(`div`,{className:J(`absolute inset-0`,E?.id!==e.id&&`hidden`),children:(0,$.jsx)(ke,{initialUrl:e.targetPath??``,directory:a,tabID:e.id})},e.id)),Oe.map(e=>{let t=e.mode===`diff`&&c?.targetPath===e.targetPath&&c.turnMessageId===e.diffTurnMessageId?c.patches:null;return(0,$.jsx)(`div`,{className:J(`absolute inset-0`,E?.id!==e.id&&`hidden`),children:(0,$.jsx)(Js,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:a,onDiffScopeChange:be,targetFilePath:e.targetPath,targetLine:e.diffTargetLine??null,toolPatches:t,navigationRequestKey:e.touchedAt,flushContent:!0,singleFileView:e.mode===`file-diff`,preloadFullFiles:e.mode===`file-diff`})},e.id)}),E?.mode!==`chat`&&!Me&&E?.mode!==`browser`&&E?.mode!==`diff`&&E?.mode!==`file-diff`?Te:null]})]})},$g=(e,t,n)=>$a(e)?Ea(e,n).map(Ra):t,e_=()=>{let e=(0,fl.c)(69),{t}=wt(),n=q(t_),r=q(n_),i=q(r_),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=Ja(),e[0]=a):a=e[0];let o=a,s;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=te(),e[1]=s):s=e[1];let c=s,l,u,d,f,p,m,h,g,_;if(e[2]!==n||e[3]!==r||e[4]!==i||e[5]!==t){let a=[{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:`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 + ${o} + 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:`previous_session`,descriptionKey:`helpDialog.item.previousSession`,icon:`arrow-left`,keys:``},{id:`next_session`,descriptionKey:`helpDialog.item.nextSession`,icon:`arrow-right`,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.leaderChords`,items:[{keys:`Ctrl+X → M`,descriptionKey:`helpDialog.item.leaderOpenModel`,icon:`ai-generate-2`},{keys:`Ctrl+X → A`,descriptionKey:`helpDialog.item.leaderOpenAgent`,icon:`ai-agent`},{keys:`Ctrl+X → N`,descriptionKey:`helpDialog.item.leaderNewSession`,icon:`add`},{keys:`Ctrl+X → C`,descriptionKey:`helpDialog.item.leaderCompact`,icon:`scissors`}]},{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:`cycle_right_sidebar_tab`,descriptionKey:`helpDialog.item.cycleRightSidebarTab`,icon:`layout-right`,keys:``},{id:`close_context_panel_tab`,descriptionKey:`helpDialog.item.closeContextPanelTab`,icon:`close`,keys:``},{id:`toggle_terminal`,descriptionKey:`helpDialog.item.toggleTerminal`,icon:`window`,keys:``},{id:`new_terminal_tab`,descriptionKey:`helpDialog.item.newTerminalTab`,icon:`terminal-box`,keys:``},{id:`open_new_terminal`,descriptionKey:`helpDialog.item.openNewTerminal`,icon:`terminal-box`,keys:``},{id:`previous_terminal_tab`,descriptionKey:`helpDialog.item.previousTerminalTab`,icon:`arrow-left`,keys:``},{id:`next_terminal_tab`,descriptionKey:`helpDialog.item.nextTerminalTab`,icon:`arrow-right`,keys:``},{id:`toggle_bottom_panel`,descriptionKey:`helpDialog.item.toggleBottomPanel`,icon:`window`,keys:``},{id:`toggle_terminal_expanded`,descriptionKey:`helpDialog.item.toggleTerminalExpanded`,icon:`window`,keys:``}]},{categoryKey:`helpDialog.section.interface`,items:[{id:`cycle_theme`,descriptionKey:`helpDialog.item.cycleTheme`,icon:`palette`,keys:``},{id:`zoom_in`,descriptionKey:`helpDialog.item.zoomIn`,icon:`add`,keys:``},{id:`zoom_out`,descriptionKey:`helpDialog.item.zoomOut`,icon:`subtract`,keys:``},{id:`zoom_reset`,descriptionKey:`helpDialog.item.zoomReset`,icon:`restart`,keys:``},{keys:[`${o} + 1...9`],descriptionKey:`helpDialog.item.switchSession`,icon:`layout-left`},{id:`toggle_services_menu`,descriptionKey:`helpDialog.item.toggleServicesMenu`,icon:`stack`,keys:``},{id:`open_usage`,descriptionKey:`helpDialog.item.openUsage`,icon:`timer`,keys:``},{id:`cycle_services_tab`,descriptionKey:`helpDialog.item.cycleServicesTab`,icon:`stack`,keys:``},{id:`open_settings`,descriptionKey:`helpDialog.item.openSettings`,icon:`settings-3`,keys:``}]}];u=pr,g=n,_=r,l=ur,m=`max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden`;let s;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Z,{name:`settings-3`,className:`h-5 w-5`}),e[15]=s):s=e[15];let v;e[16]===t?v=e[17]:(v=t(`helpDialog.title`),e[16]=t,e[17]=v);let y;e[18]===v?y=e[19]:(y=(0,$.jsxs)(dr,{className:`flex items-center gap-2`,children:[s,v]}),e[18]=v,e[19]=y);let b;e[20]===t?b=e[21]:(b=t(`helpDialog.description`),e[20]=t,e[21]=b);let x;e[22]===b?x=e[23]:(x=(0,$.jsx)(fr,{children:b}),e[22]=b,e[23]=x),e[24]!==y||e[25]!==x?(h=(0,$.jsxs)(cr,{children:[y,x]}),e[24]=y,e[25]=x,e[26]=h):h=e[26],p=`flex-1 overflow-y-auto mt-3 pr-1`,d=`space-y-4`,f=a.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:t(e.categoryKey)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:e.items.filter(e=>!(c&&e.id===`toggle_prompt_navigator`)).map(e=>{let n=e.id?$g(e.id,Array.isArray(e.keys)?e.keys[0]:e.keys,i):Array.isArray(e.keys)?e.keys:e.keys.split(` / `);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1 px-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,$.jsx)(Z,{name:e.icon,className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:t(e.descriptionKey)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(Array.isArray(n)?n:[n]).map((e,n)=>(0,$.jsxs)(Q.Fragment,{children:[n>0&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground mx-1`,children:t(`helpDialog.keyCombiner.or`)}),(0,$.jsx)(gi,{shortcut:e})]},`${e}-${n}`))})]},e.id||e.descriptionKey)})})]},e.categoryKey)),e[2]=n,e[3]=r,e[4]=i,e[5]=t,e[6]=l,e[7]=u,e[8]=d,e[9]=f,e[10]=p,e[11]=m,e[12]=h,e[13]=g,e[14]=_}else l=e[6],u=e[7],d=e[8],f=e[9],p=e[10],m=e[11],h=e[12],g=e[13],_=e[14];let v;e[27]!==d||e[28]!==f?(v=(0,$.jsx)(`div`,{className:d,children:f}),e[27]=d,e[28]=f,e[29]=v):v=e[29];let y;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Z,{name:`question`,className:`h-3.5 w-3.5 text-muted-foreground mt-0.5`}),e[30]=y):y=e[30];let b;e[31]===t?b=e[32]:(b=t(`helpDialog.proTips.title`),e[31]=t,e[32]=b);let x;e[33]===b?x=e[34]:(x=(0,$.jsx)(`p`,{className:`font-medium mb-1`,children:b}),e[33]=b,e[34]=x);let S;e[35]!==i||e[36]!==t?(S=t(`helpDialog.proTips.commandPalette`,{shortcut:Ra(Ea(`open_command_palette`,i)[0]??``)}),e[35]=i,e[36]=t,e[37]=S):S=e[37];let C;e[38]===S?C=e[39]:(C=(0,$.jsxs)(`li`,{children:[`• `,S]}),e[38]=S,e[39]=C);let w;e[40]===t?w=e[41]:(w=t(`helpDialog.proTips.recentSessions`),e[40]=t,e[41]=w);let T;e[42]===w?T=e[43]:(T=(0,$.jsxs)(`li`,{children:[`• `,w]}),e[42]=w,e[43]=T);let E;e[44]===t?E=e[45]:(E=t(`helpDialog.proTips.themeCycling`),e[44]=t,e[45]=E);let D;e[46]===E?D=e[47]:(D=(0,$.jsxs)(`li`,{children:[`• `,E]}),e[46]=E,e[47]=D);let O;e[48]!==C||e[49]!==T||e[50]!==D?(O=(0,$.jsxs)(`ul`,{className:`space-y-0.5 typography-meta`,children:[C,T,D]}),e[48]=C,e[49]=T,e[50]=D,e[51]=O):O=e[51];let k;e[52]!==x||e[53]!==O?(k=(0,$.jsx)(`div`,{className:`mt-4 p-2 bg-muted/30 rounded-xl`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[y,(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground`,children:[x,O]})]})}),e[52]=x,e[53]=O,e[54]=k):k=e[54];let A;e[55]!==k||e[56]!==p||e[57]!==v?(A=(0,$.jsxs)(`div`,{className:p,children:[v,k]}),e[55]=k,e[56]=p,e[57]=v,e[58]=A):A=e[58];let j;e[59]!==l||e[60]!==A||e[61]!==m||e[62]!==h?(j=(0,$.jsxs)(l,{className:m,children:[h,A]}),e[59]=l,e[60]=A,e[61]=m,e[62]=h,e[63]=j):j=e[63];let M;return e[64]!==u||e[65]!==j||e[66]!==g||e[67]!==_?(M=(0,$.jsx)(u,{open:g,onOpenChange:_,children:j}),e[64]=u,e[65]=j,e[66]=g,e[67]=_,e[68]=M):M=e[68],M};function t_(e){return e.isHelpDialogOpen}function n_(e){return e.setHelpDialogOpen}function r_(e){return e.shortcutOverrides}var i_=()=>{let e=(0,fl.c)(32),{t}=wt(),n=q(a_),r=q(o_),i=q(s_),a;e[0]!==i||e[1]!==t?(a=async()=>{if(i){if((await Ct(i)).ok){X.success(t(`openCodeStatusDialog.toast.copiedTitle`),{description:t(`openCodeStatusDialog.toast.copiedDescription`)});return}X.error(t(`openCodeStatusDialog.toast.copyFailed`))}},e[0]=i,e[1]=t,e[2]=a):a=e[2];let o=a,s;e[3]===t?s=e[4]:(s=t(`openCodeStatusDialog.title`),e[3]=t,e[4]=s);let c;e[5]===s?c=e[6]:(c=(0,$.jsx)(dr,{children:s}),e[5]=s,e[6]=c);let l;e[7]===t?l=e[8]:(l=t(`openCodeStatusDialog.description`),e[7]=t,e[8]=l);let u;e[9]===l?u=e[10]:(u=(0,$.jsx)(fr,{children:l}),e[9]=l,e[10]=u);let d;e[11]!==c||e[12]!==u?(d=(0,$.jsxs)(cr,{children:[c,u]}),e[11]=c,e[12]=u,e[13]=d):d=e[13];let f;e[14]===t?f=e[15]:(f=t(`openCodeStatusDialog.actions.copy`),e[14]=t,e[15]=f);let p;e[16]!==o||e[17]!==f?(p=(0,$.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,$.jsx)(`button`,{type:`button`,onClick:o,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:f})}),e[16]=o,e[17]=f,e[18]=p):p=e[18];let m;e[19]!==i||e[20]!==t?(m=i||t(`openCodeStatusDialog.empty.noData`),e[19]=i,e[20]=t,e[21]=m):m=e[21];let h;e[22]===m?h=e[23]:(h=(0,$.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap`,children:m}),e[22]=m,e[23]=h);let g;e[24]!==d||e[25]!==p||e[26]!==h?(g=(0,$.jsxs)(ur,{className:`max-w-2xl`,children:[d,p,h]}),e[24]=d,e[25]=p,e[26]=h,e[27]=g):g=e[27];let _;return e[28]!==n||e[29]!==r||e[30]!==g?(_=(0,$.jsx)(pr,{open:n,onOpenChange:r,children:g}),e[28]=n,e[29]=r,e[30]=g,e[31]=_):_=e[31],_};function a_(e){return e.isOpenCodeStatusDialogOpen}function o_(e){return e.setOpenCodeStatusDialogOpen}function s_(e){return e.openCodeStatusText}function c_(){let e=(0,fl.c)(2),t=It(),n;return e[0]===t?n=e[1]:(n=t?(0,$.jsx)(Bc,{className:`ml-auto`}):null,e[0]=t,e[1]=n),n}function l_(){let e=(0,fl.c)(2),t=Pt(),n;return e[0]===t?n=e[1]:(n=t?(0,$.jsx)(Bc,{}):null,e[0]=t,e[1]=n),n}var u_=e=>{let t=(0,fl.c)(12),{normalizedProjects:n,ownership:r,isSessionsLoading:i,fullCatalogSessionIds:a,fullCatalogGeneration:o,foldersMap:s,createFolder:c,addSessionToFolder:l,cleanupSessions:u,enabled:d}=e,f=d===void 0||d,p,m;t[0]!==l||t[1]!==u||t[2]!==c||t[3]!==f||t[4]!==s||t[5]!==o||t[6]!==a||t[7]!==i||t[8]!==n||t[9]!==r?(p=()=>{!f||i||n.forEach(e=>{let t=Oa(e.normalizedPath),n=r.archivedSessionsByProject.get(e.id)??[],i=s[t]??[],d=new Map(i.map(d_));n.forEach(n=>{let r=ha(n,e.normalizedPath),i=r.toLowerCase(),a=d.get(i);a||(a=c(t,r),d.set(i,a)),a.sessionIds.includes(n.id)||l(t,a.id,n.id)}),o>0&&u(t,a)})},m=[f,n,r,i,o,a,s,c,l,u],t[0]=l,t[1]=u,t[2]=c,t[3]=f,t[4]=s,t[5]=o,t[6]=a,t[7]=i,t[8]=n,t[9]=r,t[10]=p,t[11]=m):(p=t[10],m=t[11]),Q.useEffect(p,m)};function d_(e){return[e.name.toLowerCase(),e]}var f_=e=>{let t=(0,fl.c)(7),{isSessionsLoading:n,fullCatalogSessionIds:r,fullCatalogGeneration:i,normalizedProjects:a,cleanupSessions:o}=e,s,c;t[0]!==o||t[1]!==i||t[2]!==r||t[3]!==n||t[4]!==a?(s=()=>{if(n||i===0)return;let e=nr.getState().foldersMap;new Set([...Object.keys(e),...a.map(p_)]).forEach(e=>{o(e,r)})},c=[o,i,r,n,a],t[0]=o,t[1]=i,t[2]=r,t[3]=n,t[4]=a,t[5]=s,t[6]=c):(s=t[5],c=t[6]),Q.useEffect(s,c)};function p_(e){return Oa(e.normalizedPath)}var m_=Q.memo(function(e){let t=(0,fl.c)(17),{normalizedProjects:n,ownership:r,enabled:i}=e;xc();let a=en(h_),o=en(g_),s=xn(__),c=nr(v_),l=nr(y_),u=nr(b_),d=nr(x_),f;t[0]!==d||t[1]!==o||t[2]!==a||t[3]!==s||t[4]!==n?(f={normalizedProjects:n,fullCatalogSessionIds:a,fullCatalogGeneration:o,isSessionsLoading:s,cleanupSessions:d},t[0]=d,t[1]=o,t[2]=a,t[3]=s,t[4]=n,t[5]=f):f=t[5],f_(f);let p;return t[6]!==u||t[7]!==d||t[8]!==l||t[9]!==i||t[10]!==c||t[11]!==o||t[12]!==a||t[13]!==s||t[14]!==n||t[15]!==r?(p={normalizedProjects:n,ownership:r,enabled:i,fullCatalogSessionIds:a,fullCatalogGeneration:o,isSessionsLoading:s,foldersMap:c,createFolder:l,addSessionToFolder:u,cleanupSessions:d},t[6]=u,t[7]=d,t[8]=l,t[9]=i,t[10]=c,t[11]=o,t[12]=a,t[13]=s,t[14]=n,t[15]=r,t[16]=p):p=t[16],u_(p),null});function h_(e){return e.fullCatalogSessionIds}function g_(e){return e.fullCatalogGeneration}function __(e){return e.isLoading}function v_(e){return e.foldersMap}function y_(e){return e.createFolder}function b_(e){return e.addSessionToFolder}function x_(e){return e.cleanupSessions}var S_=new WeakMap,C_=e=>{let{normalizedProjects:t,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:i,projectRepoStatus:a,projectRootBranches:o,lastRepoStatus:s,buildGroupedSessions:c,hasSessionSearchQuery:l,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:d,buildGroupSearchText:f,foldersMap:p}=e,m=Q.useRef([]),h=Q.useMemo(()=>{let e=new Map(m.current.map(e=>[e.project.id,e])),l=t.map(t=>{let l=e.get(t.id),u=Ta([...n(t.id),...r(t.id)]),d=i.get(t.normalizedPath)??[],f=a.has(t.id)?!!a.get(t.id):s,p=new Map(l?.groups.map(e=>[e.id,e])),m=c(u,t.normalizedPath,d,o.get(t.id)??null,f).map(e=>tt(p.get(e.id),e));return tt(l,{project:t,groups:m})});return l.length===m.current.length&&l.every((e,t)=>e===m.current[t])?m.current:l},[t,n,r,i,a,s,c,o]);Q.useLayoutEffect(()=>{m.current=h},[h]);let g=Q.useMemo(()=>h,[h]),_=Q.useMemo(()=>{if(!l)return S_;let e=new WeakMap,t=e=>e.reduce((e,n)=>e+1+t(n.children),0);return g.forEach(n=>{n.groups.forEach(n=>{let r=d(n.sessions,u),i=t(r),a=f(n).includes(u),o=I(n.directory??null),s=(o?p[o]??[]:[]).filter(e=>e.name.toLowerCase().includes(u)).length;e.set(n,{filteredNodes:r,matchedSessionCount:i,folderNameMatchCount:s,groupMatches:a,hasMatch:a||i>0||s>0})})}),e},[l,g,d,u,f,p]),v=Q.useMemo(()=>l?g.map(e=>({...e,groups:e.groups.filter(e=>_.get(e)?.hasMatch===!0)})).filter(e=>e.groups.length>0):g,[l,g,_]),y=l?v:g;return{projectSections:h,visibleProjectSections:g,groupSearchDataByGroup:_,searchableProjectSections:v,sectionsForRender:y,searchMatchCount:Q.useMemo(()=>l?y.reduce((e,t)=>e+t.groups.reduce((e,t)=>{let n=_.get(t);if(!n)return e;let r=n.folderNameMatchCount+ +!!n.groupMatches;return e+n.matchedSessionCount+r},0),0):0,[l,y,_])}},w_=e=>{let t=(0,fl.c)(26),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:a,currentSessionId:o,handleSessionSelect:s,newSessionDraftOpen:c,mobileVariant:l,openNewSessionDraft:u,setActiveMainTab:d,setSessionSwitcherOpen:f}=e,p,m;if(t[0]!==n){m=new Map,p=new Map;let e=(t,n,r,i)=>{m.has(t)||m.set(t,new Map);let a=m.get(t);i.forEach(i=>{let o=I(i.worktree?.path??i.session.directory??r??n);a.set(i.session.id,{directory:o}),p.has(t)||p.set(t,{id:i.session.id,directory:o}),i.children.length>0&&e(t,n,o,i.children)})};n.forEach(t=>{t.groups.forEach(n=>{e(t.project.id,t.project.normalizedPath,n.directory,n.sessions)})}),t[0]=n,t[1]=p,t[2]=m}else p=t[1],m=t[2];let h;t[3]!==p||t[4]!==m?(h={metaByProject:m,firstSessionByProject:p},t[3]=p,t[4]=m,t[5]=h):h=t[5];let g=h,_=Q.useRef(null),v,y;t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==s||t[10]!==l||t[11]!==c||t[12]!==u||t[13]!==n||t[14]!==g||t[15]!==d||t[16]!==a||t[17]!==f?(v=()=>{if(!r||c||q.getState().isNewWorktreeDialogOpen||_.current===r)return;let e=n.find(e=>e.project.id===r);if(!e)return;_.current=r;let t=g.metaByProject.get(r);if(o&&t&&t.has(o)){a(e=>{if(e.get(r)===o)return e;let t=new Map(e);return t.set(r,o),t});return}if(o&&t)return;if(!t||t.size===0){d(`chat`),l&&f(!1),u({directoryOverride:e.project.normalizedPath});return}let p=i.get(r),m=p&&t.has(p)?p:null,h=g.firstSessionByProject.get(r)?.id??null,v=m??h;if(!v||v===o)return;let y=t.get(v)?.directory??null;s(v,y,r)},y=[r,i,o,s,c,l,u,n,g,d,f,a],t[6]=r,t[7]=i,t[8]=o,t[9]=s,t[10]=l,t[11]=c,t[12]=u,t[13]=n,t[14]=g,t[15]=d,t[16]=a,t[17]=f,t[18]=v,t[19]=y):(v=t[18],y=t[19]),Q.useLayoutEffect(v,y);let b,x;t[20]!==r||t[21]!==o||t[22]!==g||t[23]!==a?(b=()=>{if(!r||!o)return;let e=g.metaByProject.get(r);!e||!e.has(o)||a(e=>{if(e.get(r)===o)return e;let t=new Map(e);return t.set(r,o),t})},x=[r,o,g,a],t[20]=r,t[21]=o,t[22]=g,t[23]=a,t[24]=b,t[25]=x):(b=t[24],x=t[25]),Q.useEffect(b,x)},T_=e=>{let t=Lt(e=>e.orderByProject);return{getOrderedGroups:Q.useMemo(()=>(n,r)=>{let i=e.get(n),a=t[n];if(!i?.length&&!a?.length)return r;let o=new Map(r.map(e=>[e.id,e])),s=[];if(i?.forEach(e=>{let t=o.get(e);t&&(s.push(t),o.delete(e))}),r.forEach(e=>{o.has(e.id)&&s.push(e)}),!a?.length)return s;let c=new Map(a.map((e,t)=>[I(e),t])),l=s.filter(e=>e.worktree&&!e.isMain);l.sort((e,t)=>(c.get(I(e.directory))??2**53-1)-(c.get(I(t.directory))??2**53-1));let u=0;return s.map(e=>e.worktree&&!e.isMain?l[u++]:e)},[e,t])}},E_=e=>{let{t}=wt(),n=Q.useCallback(e=>[e.label,e.branch??``,e.description??``,e.directory??``].join(` `).toLowerCase(),[]),r=Q.useCallback(e=>{let n=I(e.directory??null)??``;return`${(e.title||t(`sessions.sidebar.session.untitled`)).trim()} ${n}`.toLowerCase()},[t]),i=Q.useCallback((e,t)=>t?e.flatMap(e=>{if(r(e.session).includes(t))return[e];let n=i(e.children,t);return n.length===0?[]:[{...e,children:n}]}):e,[r]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:i,buildGroupedSessions:Q.useCallback((n,r,i,a,o)=>{let s=I(r??null),c=new Map;i.forEach(e=>{if(e.path){let t=I(e.path)??e.path;c.set(t,e)}});let l=kc(n,{pinnedSessionIds:e.pinnedSessionIds,omitPinnedSessions:!1,getWorktree:t=>{let n=I(t.directory??null),r=e.worktreeMetadata.get(t.id)??null;if(r)return r;if(n){let e=c.get(n)??null;if(e&&n!==s)return e}return null}}),u=new Map,d=`__archived__`,f=t=>{if(t.time?.archived)return d;if(e.isVSCode)return s??`__project_root__`;let n=I(e.worktreeMetadata.get(t.id)?.path??null)??Fn(t);return n?n!==s&&c.has(n)?n:n===s?s??`__project_root__`:d:d};l.forEach(e=>{let t=f(e.session);u.has(t)||u.set(t,[]),u.get(t)?.push(e)});let p=s??`__project_root__`,m=[{id:`root`,label:o&&a&&a!==`HEAD`?t(`sessions.sidebar.grouping.projectRootWithBranch`,{branch:a}):t(`sessions.sidebar.grouping.projectRoot`),branch:a??null,description:s?xt(s,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:s,folderScopeKey:s,sessions:u.get(p)??[]}],h=new Map;i.forEach(e=>{let t=I(e.path)??e.path,n=u.get(t)??[],r=n.length>0,i=n.reduce((e,t)=>{let n=on(t.session);return Number.isFinite(n)?Math.max(e,n):e},0);h.set(t,{hasActiveSession:r,lastUpdatedAt:i})});let g=[...i].sort((e,t)=>{let n=I(e.path)??e.path,r=I(t.path)??t.path,i=h.get(n)??{hasActiveSession:!1,lastUpdatedAt:0},a=h.get(r)??{hasActiveSession:!1,lastUpdatedAt:0};if(i.hasActiveSession!==a.hasActiveSession)return i.hasActiveSession?-1:1;if(i.hasActiveSession&&a.hasActiveSession)return a.lastUpdatedAt-i.lastUpdatedAt;let o=(e.label||e.branch||e.name||e.path||``).toLowerCase(),s=(t.label||t.branch||t.name||t.path||``).toLowerCase();return o.localeCompare(s)});(e.isVSCode?[]:g).forEach(t=>{let n=I(t.path)??t.path,r=e.gitBranches.get(n)?.trim()||null,i=t.branch?.trim()||null,a=r&&i&&t.label&&Ya(t.label)===Ya(i)?r:t.label||t.name||Dt(n,e.homeDirectory)||n;m.push({id:`worktree:${n}`,label:a,branch:r||i,description:xt(n,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:t,directory:n,folderScopeKey:n,sessions:u.get(n)??[]})});let _=u.get(d)??[];return m.push({id:`archived`,label:t(`sessions.sidebar.grouping.archived`),branch:null,description:t(`sessions.sidebar.grouping.archivedDescription`),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!e.isVSCode&&s?Oa(s):null,sessions:_}),m},[e.homeDirectory,e.worktreeMetadata,e.pinnedSessionIds,e.gitBranches,e.isVSCode,t])}},D_=e=>{let t=(0,fl.c)(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:i,sessionSearchContainerRef:a}=e,o,s;t[0]!==n||t[1]!==i?(o=()=>{if(!n||typeof window>`u`)return;let e=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(e)},s=[n,i],t[0]=n,t[1]=i,t[2]=o,t[3]=s):(o=t[2],s=t[3]),Q.useEffect(o,s);let c,l;t[4]!==n||t[5]!==a||t[6]!==r?(c=()=>{if(!n||typeof document>`u`)return;let e=e=>{a.current&&(a.current.contains(e.target)||r(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},l=[n,r,a],t[4]=n,t[5]=a,t[6]=r,t[7]=c,t[8]=l):(c=t[7],l=t[8]),Q.useEffect(c,l)},O_=e=>{let t=(0,fl.c)(42),{t:n}=wt(),[r,i]=Q.useState(null),a=Q.useRef(null),o,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>()=>{a.current&&clearTimeout(a.current)},s=[],t[0]=o,t[1]=s):(o=t[0],s=t[1]),Q.useEffect(o,s);let c;t[2]===e?c=t[3]:(c=(t,n,r)=>{let i=()=>{!e.isSessionSearchOpen&&e.sessionSearchQuery.length===0||(e.setSessionSearchQuery(``),e.setIsSessionSearchOpen(!1))};if(r&&r!==e.activeProjectId&&e.setActiveProjectIdOnly(r),n&&n!==e.currentDirectory&&e.setDirectory(n,{showOverlay:!1}),e.setActiveMainTab(`chat`)){if(e.mobileVariant&&e.setSessionSwitcherOpen(!1),t===e.currentSessionId){e.allowReselect&&e.onSessionSelected?.(t),i();return}e.setCurrentSession(t,n??null),e.onSessionSelected?.(t),i()}},t[2]=e,t[3]=c);let l=c,u;t[4]===e?u=t[5]:(u=(t,n)=>{e.setEditingId(t),e.setEditTitle(n)},t[4]=e,t[5]=u);let d=u,f;t[6]===e?f=t[7]:(f=async t=>{if(!e.editingId)return;let n=(t??e.editTitle).trim();n&&await e.updateSessionTitle(e.editingId,n),e.setEditingId(null),e.setEditTitle(``)},t[6]=e,t[7]=f);let p=f,m;t[8]===e?m=t[9]:(m=()=>{e.setEditingId(null),e.setEditTitle(``)},t[8]=e,t[9]=m);let h=m,g;t[10]!==e||t[11]!==n?(g=async t=>{let r=await e.shareSession(t.id);r&&r.share?.url?X.success(n(`sessions.sidebar.session.share.successTitle`),{description:n(`sessions.sidebar.session.share.successDescription`)}):X.error(n(`sessions.sidebar.session.share.error`))},t[10]=e,t[11]=n,t[12]=g):g=t[12];let _=g,v;t[13]===n?v=t[14]:(v=(e,t)=>{Ct(e).then(e=>{if(!e.ok){X.error(n(`sessions.sidebar.session.share.copyUrlError`));return}i(t),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{i(null),a.current=null},2e3)}).catch(()=>{X.error(n(`sessions.sidebar.session.share.copyUrlError`))})},t[13]=n,t[14]=v);let y=v,b;t[15]!==e||t[16]!==n?(b=async t=>{await e.unshareSession(t)?X.success(n(`sessions.sidebar.session.unshare.success`)):X.error(n(`sessions.sidebar.session.unshare.error`))},t[15]=e,t[16]=n,t[17]=b):b=t[17];let x=b,S;t[18]===e.childrenMap?S=t[19]:(S=t=>{let n=[],r=t=>{(e.childrenMap.get(t)??[]).forEach(e=>{n.push(e),r(e.id)})};return r(t),n},t[18]=e.childrenMap,t[19]=S);let C=S,w=A_,T;t[20]!==e||t[21]!==C||t[22]!==n?(T=async(t,r,i)=>{let a=r?.archivedBucket===!0||r?.hardDelete===!0,o=i?.descendantIds??w(C(t.id),a).map(j_);if(o.length===0){if(a){qs({sessionIds:[t.id],message:n(`sessions.sidebar.session.delete.success`),undoLabel:n(`sessions.sidebar.undo`),commitFailedMessage:n(`sessions.sidebar.session.delete.error`)});return}await e.archiveSession(t.id)?Ys({sessionIds:[t.id],message:n(`sessions.sidebar.session.archive.success`),undoLabel:n(`sessions.sidebar.undo`),settingsLabel:n(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:n(`sessions.sidebar.session.archive.undoFailed`)}):X.error(n(`sessions.sidebar.session.archive.error`));return}let s=[t.id,...o];if(a){qs({sessionIds:s,message:s.length===1?n(`sessions.sidebar.bulkActions.deletedSingle`,{count:s.length}):n(`sessions.sidebar.bulkActions.deletedPlural`,{count:s.length}),undoLabel:n(`sessions.sidebar.undo`),commitFailedMessage:n(`sessions.sidebar.session.delete.error`)});return}let{archivedIds:c,failedIds:l}=await e.archiveSessions(s);c.length>0&&Ys({sessionIds:c,message:c.length===1?n(`sessions.sidebar.bulkActions.archivedSingle`,{count:c.length}):n(`sessions.sidebar.bulkActions.archivedPlural`,{count:c.length}),undoLabel:n(`sessions.sidebar.undo`),settingsLabel:n(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:c.length===1?n(`sessions.sidebar.session.archive.undoFailed`):n(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:c.length})}),l.length>0&&X.error(l.length===1?n(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:l.length}):n(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:l.length}))},t[20]=e,t[21]=C,t[22]=n,t[23]=T):T=t[23];let E=T,D;t[24]!==e||t[25]!==C||t[26]!==E?(D=(t,n)=>{let r=n?.archivedBucket===!0||n?.hardDelete===!0,i=w(C(t.id),r).map(M_);if(!r||!e.showDeletionDialog||n?.skipConfirm===!0){E(t,n,{descendantIds:i});return}e.setDeleteSessionConfirm({session:t,descendantCount:i.length,descendantIds:i,archivedBucket:r})},t[24]=e,t[25]=C,t[26]=E,t[27]=D):D=t[27];let O=D,k;t[28]!==e||t[29]!==E?(k=async()=>{if(!e.deleteSessionConfirm)return;let{session:t,archivedBucket:n,descendantIds:r}=e.deleteSessionConfirm;e.setDeleteSessionConfirm(null),await E(t,{archivedBucket:n},{descendantIds:r})},t[28]=e,t[29]=E,t[30]=k):k=t[30];let A=k,j;return t[31]!==A||t[32]!==r||t[33]!==h||t[34]!==y||t[35]!==O||t[36]!==p||t[37]!==d||t[38]!==l||t[39]!==_||t[40]!==x?(j={copiedSessionId:r,handleSessionSelect:l,handleSessionDoubleClick:d,handleSaveEdit:p,handleCancelEdit:h,handleShareSession:_,handleCopyShareUrl:y,handleUnshareSession:x,handleDeleteSession:O,confirmDeleteSession:A},t[31]=A,t[32]=r,t[33]=h,t[34]=y,t[35]=O,t[36]=p,t[37]=d,t[38]=l,t[39]=_,t[40]=x,t[41]=j):j=t[41],j};function k_(e){return!e.time?.archived}function A_(e,t){return t?e:e.filter(k_)}function j_(e){return e.id}function M_(e){return e.id}var N_=[`project:active:`,`project:archived:`,`pinned:active:`,`pinned:archived:`],P_=e=>{let{isVSCode:t,safeStorage:n,keys:r,groupOrderByProject:i,activeSessionByProject:a,collapsedGroups:o,setExpandedParents:s,setCollapsedProjects:c}=e,l=Q.useRef(null),u=Q.useRef(null),[d,f]=Q.useState(!1),p=Q.useCallback(()=>{if(t)return;let e=u.current;if(u.current=null,l.current=null,!e)return;let{projects:n}=An.getState(),r=n.map(t=>({...t,sidebarCollapsed:e.has(t.id)}));R({projects:r}).catch(()=>{})},[t]),m=Q.useCallback(e=>{typeof window>`u`||t||(u.current=e,l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{p()},700))},[t,p]);return Q.useEffect(()=>()=>{typeof window<`u`&&l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=null},[]),Q.useEffect(()=>{try{let e=n.getItem(r.sessionExpanded);if(e){let t=JSON.parse(e);Array.isArray(t)&&s(new Set(t.filter(e=>typeof e==`string`)))}else{let e=n.getItem(r.sessionExpandedLegacy);if(e){try{let t=JSON.parse(e);if(Array.isArray(t)){let e=new Set;if(t.forEach(t=>{typeof t==`string`&&t.length!==0&&N_.forEach(n=>e.add(`${n}${t}`))}),e.size>0){s(e);try{n.setItem(r.sessionExpanded,JSON.stringify(Array.from(e)))}catch{}}}}catch{}try{n.removeItem?.(r.sessionExpandedLegacy)}catch{}}}let t=n.getItem(r.projectCollapse);if(t){let e=JSON.parse(t);Array.isArray(e)&&c(new Set(e.filter(e=>typeof e==`string`)))}}catch{}finally{f(!0)}},[r.projectCollapse,r.sessionExpanded,r.sessionExpandedLegacy,n,c,s]),Q.useEffect(()=>{try{let e=Object.fromEntries(i.entries());n.setItem(r.groupOrder,JSON.stringify(e))}catch{}},[i,r.groupOrder,n]),Q.useEffect(()=>{try{let e=Object.fromEntries(a.entries());n.setItem(r.projectActiveSession,JSON.stringify(e))}catch{}},[a,r.projectActiveSession,n]),Q.useEffect(()=>{try{n.setItem(r.groupCollapse,JSON.stringify(Array.from(o)))}catch{}},[o,r.groupCollapse,n]),{scheduleCollapsedProjectsPersist:m,hasRestoredProjectCollapse:d}},F_=async(e,t,n)=>{if(e.length===0)return[];let r=Math.max(1,Math.min(t,e.length)),i=Array(e.length),a=0,o=async()=>{for(;;){let t=a;if(a+=1,t>=e.length)return;i[t]=await n(e[t])}};return await Promise.all(Array.from({length:r},()=>o())),i},I_=e=>{let{normalizedProjects:t,activeProjectId:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a,enabled:o=!0}=e,{git:s}=at(),c=Do(e=>e.ensureStatus),l=Q.useMemo(()=>o?t.filter(e=>e.id===n):[],[n,o,t]);Q.useEffect(()=>{if(!o||!s||l.length===0){if(!o)return;i(e=>e.size===0?e:new Map);return}l.forEach(e=>{c(e.normalizedPath,s)})},[l,o,s,c,i]),Q.useEffect(()=>{let e=new Map;l.forEach(t=>{e.set(t.id,r.get(t.normalizedPath)?.isGitRepo??null)}),i(t=>t.size===e.size&&[...e].every(([e,n])=>t.has(e)&&t.get(e)===n)?t:e)},[l,r,i]);let u=Q.useMemo(()=>l.map(e=>{let t=r.get(e.normalizedPath)?.branch??``;return`${e.id}:${t}`}).join(`|`),[l,r]),d=Q.useRef(new Map),f=Q.useRef(new Map);Q.useEffect(()=>{let e=!1,t=setTimeout(()=>{(async()=>{let t=new Set(l.map(e=>e.id));for(let e of d.current.keys())t.has(e)||(d.current.delete(e),f.current.delete(e));let n=Date.now(),i=l.filter(e=>{let t=r.get(e.normalizedPath);if(t?.isGitRepo===!1)return d.current.delete(e.id),f.current.delete(e.id),!1;if(t?.isGitRepo!==!0||t.branch===null)return!1;let i=t.branch.trim(),a=`${e.normalizedPath}\0${i}`,o=d.current.get(e.id);if(o===a){let t=f.current.get(e.id);return t&&(t.at=n),!1}return!(o!==void 0&&n-(f.current.get(e.id)?.at??0)<3e5)});if(i.length===0)return;let o=await F_(i,2,async e=>{let t=r.get(e.normalizedPath)?.branch?.trim()??``,n=`${e.normalizedPath}\0${t}`,i=await Qi(e.normalizedPath,t?{knownBranch:t}:void 0).catch(()=>null);return{id:e.id,inputKey:n,branch:i}});if(e)return;let s=o.filter(e=>e.branch);if(s.length===0)return;let c=Date.now();a(e=>{let t=e;return s.forEach(({id:n,branch:r})=>{r&&e.get(n)!==r&&(t===e&&(t=new Map(e)),t.set(n,r))}),t}),s.forEach(({id:e,inputKey:t,branch:n})=>{d.current.set(e,t),n&&f.current.set(e,{branch:n,at:c})})})()},150);return()=>{e=!0,clearTimeout(t)}},[l,u,r,a])},L_=e=>{let t=(0,fl.c)(7),{ownership:n}=e,r;t[0]===n?r=t[1]:(r=e=>n.sessionsByProject.get(e)??[],t[0]=n,t[1]=r);let i=r,a;t[2]===n?a=t[3]:(a=e=>n.archivedSessionsByProject.get(e)??[],t[2]=n,t[3]=a);let o=a,s;return t[4]!==o||t[5]!==i?(s={getSessionsForProject:i,getArchivedSessionsForProject:o},t[4]=o,t[5]=i,t[6]=s):s=t[6],s},R_=e=>{let t=(0,fl.c)(10),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:i,enabled:a}=e,o=a===void 0||a,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=new Set,t[0]=s):s=t[0];let[c,l]=Q.useState(s),u;t[1]!==o||t[2]!==n||t[3]!==i?(u=()=>{if(!o||!n){l(z_);return}let e=new IntersectionObserver(e=>{e.forEach(e=>{let t=e.target.dataset.projectId;t&&l(n=>{let r=new Set(n);return e.isIntersecting?r.delete(t):r.add(t),r})})},{threshold:0});return i.current.forEach(t=>{t&&e.observe(t)}),()=>e.disconnect()},t[1]=o,t[2]=n,t[3]=i,t[4]=u):u=t[4];let d;return t[5]!==o||t[6]!==n||t[7]!==i||t[8]!==r?(d=[o,n,i,r],t[5]=o,t[6]=n,t[7]=i,t[8]=r,t[9]=d):d=t[9],Q.useEffect(u,d),c};function z_(e){return e.size===0?e:new Set}var B_=9e4,V_=15e3,H_=3e5,U_=[2e3,5e3],W_=6e4,G_=12e4,K_=3e5,q_=4,J_=432e5,Y_=`yuri.github-pr-status`,X_=e=>e===`closed`||e===`merged`,Z_=e=>{let t=e?.checks;return t?t.state===`pending`||t.pending>0:!1},Q_=(e,t,n)=>`${e}::${t}`,$_=new Map,ev=new Map,tv=new Set,nv=new Map,rv=2,iv=0,av=[],ov=()=>iv<rv?(iv+=1,Promise.resolve()):new Promise(e=>{av.push(e)}),sv=()=>{let e=av.shift();if(e){e();return}iv=Math.max(0,iv-1)},cv=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),lv=e=>e?.params?.directory&&e.params.branch?{directory:e.params.directory,branch:e.params.branch,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null}:!e?.identity?.directory||!e.identity.branch?null:e.identity,uv=e=>{let t=lv(e);return!t?.directory||!t.branch?null:`${t.directory}::${t.branch}`},dv=(e,t)=>Object.entries(e).filter(([,e])=>uv(e)===t).map(([e])=>e),fv=(e,t)=>{let n=t.remoteName??e.params?.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null;return{...e,params:e.params?{...e.params,...t,remoteName:n}:{...t,remoteName:n},identity:{directory:t.directory,branch:t.branch,remoteName:n}}},pv=e=>!e?.params?.canShow||!e.params.github?.prStatus?null:{...e.params,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null},mv=(e,t,n)=>{let r=dv(e,t),i=r.map(t=>pv(e[t])).filter(e=>!!e);if(i.length===0)return null;let a=pv(e[n]);if(a&&uv(e[n])===t)return a;let o=r.map(t=>e[t]).find(e=>!!(e?.resolvedRemoteName&&pv(e)));return o?pv(o):i.find(e=>!!e.remoteName)||(i[0]??null)},hv=e=>({status:e.status,isInitialStatusResolved:e.isInitialStatusResolved,lastRefreshAt:e.lastRefreshAt,lastDiscoveryPollAt:e.lastDiscoveryPollAt,identity:lv(e),resolvedRemoteName:e.resolvedRemoteName??e.status?.resolvedRemoteName??null}),gv=e=>({...cv(),status:e?.status??null,isInitialStatusResolved:e?.isInitialStatusResolved??!1,lastRefreshAt:e?.lastRefreshAt??0,lastDiscoveryPollAt:e?.lastDiscoveryPollAt??0,identity:e?.identity??null,resolvedRemoteName:e?.resolvedRemoteName??e?.status?.resolvedRemoteName??null}),_v=G()(le((e,t)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:t=>{e(e=>e.entries[t]?e:{entries:{...e.entries,[t]:cv()}})},setParams:(t,n)=>{e(e=>{let r=e.entries[t]??cv();return{entries:{...e.entries,[t]:fv(r,n)}}})},startWatching:n=>{if(e(e=>{let t=e.entries[n]??cv();return{entries:{...e.entries,[n]:{...t,watchers:t.watchers+1}}}}),$_.has(n))return;let r=e=>{let r=window.setTimeout(()=>{if(typeof document<`u`&&document.visibilityState!==`visible`)return;let e=t().entries[n];!e||e.watchers<=0||e.status?.pr||t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},e),i=ev.get(n)??[];i.push(r),ev.set(n,i)};t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),U_.forEach(e=>r(e));let i=window.setInterval(()=>{if(typeof document<`u`&&document.visibilityState!==`visible`)return;let r=t().entries[n];if(!(!r||r.watchers<=0)){if(!r.status?.pr){let i=Date.now();if(i-r.lastDiscoveryPollAt<H_)return;e(e=>{let t=e.entries[n];return t?{entries:{...e.entries,[n]:{...t,lastDiscoveryPollAt:i}}}:e}),t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}X_(r.status?.pr?.state)||Date.now()-r.lastRefreshAt<(Z_(r.status)?W_:r.status?.checks&&r.status.checks.state!==`pending`?K_:G_)||t().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})}},V_);$_.set(n,i)},stopWatching:n=>{e(e=>{let t=e.entries[n];if(!t)return e;let r=Math.max(0,t.watchers-1);return{entries:{...e.entries,[n]:{...t,watchers:r}}}});let r=t().entries[n];if(r&&r.watchers>0)return;let i=$_.get(n);typeof i==`number`&&window.clearInterval(i),$_.delete(n);let a=ev.get(n);a&&a.length>0&&a.forEach(e=>{window.clearTimeout(e)}),ev.delete(n)},refresh:async(n,r)=>{let i=t(),a=i.entries[n],o=uv(a);if(!a||!o)return;let s=dv(i.entries,o),c=s.some(e=>!!i.entries[e]?.status?.pr);if(r?.onlyExistingPr&&!c)return;let l=nv.get(o)??0;if(!r?.force&&Date.now()-l<B_||tv.has(o))return;let u=mv(i.entries,o,n);if(u){if(tv.add(o),nv.set(o,Date.now()),e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,lastRefreshAt:Date.now(),isLoading:!r?.silent||n.isLoading,error:null})}),{entries:t}}),u.githubAuthChecked&&u.githubConnected===!1){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:{connected:!1},error:null,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),tv.delete(o);return}if(!u.github?.prStatus){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:null,error:`GitHub runtime API unavailable`,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),tv.delete(o);return}try{e(e=>({...e,activeRequestCount:e.activeRequestCount+1,totalRequestCount:e.totalRequestCount+1})),await ov();let t;try{t=await u.github.prStatus(u.directory,u.branch,u.remoteName??void 0,{force:r?.force})}finally{sv()}e(e=>{let n={...e.entries};return s.forEach(e=>{let i=n[e];if(!i)return;let a=i.status?.pr,o=t.pr,s=o&&a&&o.number===a.number&&(!o.body||!o.body.trim())&&typeof a.body==`string`&&a.body.trim().length>0&&o&&a?.body?{...t,pr:{...o,body:a.body}}:t,c=s.resolvedRemoteName??i.resolvedRemoteName??u.remoteName??null,l=lv(i)??{directory:u.directory,branch:u.branch,remoteName:u.remoteName??null};n[e]={...i,status:s,error:null,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved,resolvedRemoteName:c,identity:{...l,remoteName:c??l.remoteName??null}}}),{entries:n}})}catch(t){let n=t instanceof Error?t.message:String(t);e(e=>{let t={...e.entries};return s.forEach(e=>{let i=t[e];i&&(t[e]={...i,error:n||`Failed to load PR status`,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved})}),{entries:t}})}finally{tv.delete(o),e(e=>({...e,activeRequestCount:Math.max(0,e.activeRequestCount-1)}))}}},refreshTargets:async(e,n)=>{await F_(Array.from(new Set(e.map(e=>{let t=e.directory.trim(),n=e.branch.trim();return!t||!n?null:Q_(t,n,e.remoteName??null)}).filter(e=>!!e))),q_,e=>t().refresh(e,n))},updateStatus:(t,n)=>{e(e=>{let r=e.entries[t]??cv();return{entries:{...e.entries,[t]:{...r,status:n(r.status)}}}})}}),{name:Y_,storage:Xe(),partialize:e=>({entries:Object.fromEntries(Object.entries(e.entries).filter(([,e])=>{let t=lv(e);if(!t?.directory||!t.branch)return!1;let n=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return n===0||Date.now()-n<J_}).map(([e,t])=>[e,hv(t)]))}),merge:(e,t)=>{let n=e?.entries??{};return{...t,entries:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,gv(t)]))}}})),vv=e=>{let t=e?.pr;if(!t)return null;if(t.state===`merged`)return`merged`;if(t.state===`closed`)return`closed`;if(t.draft)return`draft`;let n=e?.checks?.state===`failure`,r=typeof t.mergeableState==`string`?t.mergeableState:``,i=t.mergeable===!1||r===`blocked`||r===`dirty`;return n||i?`blocked`:`open`},yv=e=>{let t=vv(e.status??null),n=e.status?.pr;return!t||!n?.number?null:{number:n.number,visualState:t,prState:n.state,draft:!!n.draft,title:typeof n.title==`string`&&n.title.trim().length>0?n.title:null,url:typeof n.url==`string`&&n.url.trim().length>0?n.url:null,base:typeof n.base==`string`&&n.base.trim().length>0?n.base:null,head:typeof n.head==`string`&&n.head.trim().length>0?n.head:null,checks:e.status?.checks?{state:e.status.checks.state,total:e.status.checks.total,success:e.status.checks.success,failure:e.status.checks.failure,pending:e.status.checks.pending}:null,canMerge:typeof e.status?.canMerge==`boolean`?e.status.canMerge:null,mergeableState:typeof n.mergeableState==`string`?n.mergeableState:null,repo:e.status?.repo?{owner:e.status.repo.owner,repo:e.status.repo.repo}:null}},bv=e=>`${e.number}:${e.visualState}:${e.prState}:${e.draft}:${e.title??``}:${e.url??``}:${e.base??``}:${e.head??``}:${e.canMerge??``}:${e.mergeableState??``}:${e.checks?.state??``}:${e.checks?.total??``}:${e.checks?.success??``}:${e.checks?.failure??``}:${e.checks?.pending??``}:${e.repo?.owner??``}:${e.repo?.repo??``}`,xv=new Map,Sv=new Map,Cv=e=>{let t=(0,fl.c)(2),n;return t[0]===e?n=t[1]:(n=t=>{let n=new Map,r=new Map;for(let i of e){let e=t.entries[i];if(!e)continue;let a=yv(e);if(!a)continue;let o=bv(a);n.set(i,o),r.set(i,a)}if(n.size===xv.size){let e=!0;for(let[t,r]of n)if(xv.get(t)!==r){e=!1;break}if(e)return Sv}return xv=n,Sv=r,r},t[0]=e,t[1]=n),_v(n)},wv=e=>{let t=(0,fl.c)(10),{open:n,onOpenChange:r,project:i,onSave:a}=e,o;t[0]!==a||t[1]!==n||t[2]!==i?(o=n&&i?(0,$.jsx)(Ps,{project:i,onIdentitySave:a}):null,t[0]=a,t[1]=n,t[2]=i,t[3]=o):o=t[3];let s;t[4]===o?s=t[5]:(s=(0,$.jsx)(ur,{className:`w-full max-w-2xl gap-0 overflow-hidden p-0`,children:(0,$.jsx)(fo,{outerClassName:`max-h-[min(90vh,48rem)]`,className:`w-full bg-background`,children:(0,$.jsx)(`div`,{className:`w-full p-3 sm:p-6 sm:pt-8`,children:o})})}),t[4]=o,t[5]=s);let c;return t[6]!==r||t[7]!==n||t[8]!==s?(c=(0,$.jsx)(pr,{open:n,onOpenChange:r,children:s}),t[6]=r,t[7]=n,t[8]=s,t[9]=c):c=t[9],c},Tv=Q.memo(e=>{let t=(0,fl.c)(96),{folder:n,sessions:r,subFolderItems:i,isCollapsed:a,onToggle:o,onRename:s,onDelete:c,renderSessionNode:l,getRenderExtras:u,groupDirectory:d,projectId:f,mobileVariant:p,alwaysShowActions:m,isRenaming:h,renameDraft:g,onRenameDraftChange:_,onRenameSave:v,onRenameCancel:y,droppableRef:b,isDropTarget:x,onNewSession:S,onNewSubFolder:C,depth:w,hideActions:T,archivedBucket:E,sessionSecondaryMeta:D}=e,O=m===void 0?p!==void 0&&p:m,k=h!==void 0&&h,A=g===void 0?``:g,j=x!==void 0&&x,M=w===void 0?0:w,N=T!==void 0&&T,P=E!==void 0&&E,F=D===void 0?null:D,{t:I}=wt(),[L,R]=Q.useState(!1),[z,B]=Q.useState(``),V=Q.useRef(null),ee=k||L,H=k?A:z,te;t[0]===n.name?te=t[1]:(te=()=>{B(n.name),R(!0)},t[0]=n.name,t[1]=te);let ne=te,re;t[2]!==H||t[3]!==n.name||t[4]!==k||t[5]!==s||t[6]!==v?(re=()=>{let e=H.trim();e&&e!==n.name&&s(e),k&&v&&v(),R(!1),B(``)},t[2]=H,t[3]=n.name,t[4]=k,t[5]=s,t[6]=v,t[7]=re):re=t[7];let U=re,ie;t[8]!==k||t[9]!==y?(ie=()=>{k&&y&&y(),R(!1),B(``)},t[8]=k,t[9]=y,t[10]=ie):ie=t[10];let ae=ie,W;t[11]!==k||t[12]!==_?(W=e=>{if(k&&_){_(e);return}B(e)},t[11]=k,t[12]=_,t[13]=W):W=t[13];let oe=W,se,ce;t[14]===k?(se=t[15],ce=t[16]):(se=()=>{if(!k)return;let e=()=>{let e=V.current;e&&(e.focus(),e.select())},t=requestAnimationFrame(e),n=window.setTimeout(e,0);return()=>{cancelAnimationFrame(t),window.clearTimeout(n)}},ce=[k],t[14]=k,t[15]=se,t[16]=ce),Q.useEffect(se,ce);let G;t[17]===M?G=t[18]:(G=Za(M),t[17]=M,t[18]=G);let le=G,ue=!a,de;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(de=J(`yuri-folder`),t[19]=de):de=t[19];let fe=j&&`bg-primary/10 ring-1 ring-inset ring-primary/30`,pe;t[20]===fe?pe=t[21]:(pe=J(`group/folder relative my-0.5 flex items-center justify-between gap-1.5 py-1.5 pr-2 min-w-0 rounded-lg`,`cursor-pointer`,Na,fe),t[20]=fe,t[21]=pe);let me;t[22]===le?me=t[23]:(me={paddingLeft:le},t[22]=le,t[23]=me);let he=ee?void 0:o,ge=ee?void 0:`button`,_e=ee?void 0:0,ve;t[24]!==o||t[25]!==ee?(ve=ee?void 0:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},t[24]=o,t[25]=ee,t[26]=ve):ve=t[26];let ye;t[27]!==n.name||t[28]!==a||t[29]!==I?(ye=I(a?`sessions.sidebar.folderItem.expandAria`:`sessions.sidebar.folderItem.collapseAria`,{folderName:n.name}),t[27]=n.name,t[28]=a,t[29]=I,t[30]=ye):ye=t[30];let be=P?O?`pr-7`:`group-hover/folder:pr-7 group-focus-within/folder:pr-7`:``,xe;t[31]===be?xe=t[32]:(xe=J(`min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]`,be),t[31]=be,t[32]=xe);let Se=j?`text-primary`:`text-muted-foreground`,Ce;t[33]===Se?Ce=t[34]:(Ce=J(`h-4 w-4 flex-shrink-0`,Se),t[33]=Se,t[34]=Ce);let we;t[35]===Ce?we=t[36]:(we=(0,$.jsx)(Z,{name:`folder-open`,className:Ce}),t[35]=Ce,t[36]=we);let Te;t[37]!==H||t[38]!==n.name||t[39]!==ae||t[40]!==oe||t[41]!==U||t[42]!==a||t[43]!==j||t[44]!==ee||t[45]!==r.length||t[46]!==I?(Te=ee?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-1 items-center gap-1`,onPointerDown:Ev,onMouseDown:Dv,onSubmit:e=>{e.preventDefault(),U()},children:[(0,$.jsx)(`input`,{ref:V,value:H,onChange:e=>oe(e.target.value),className:`flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground`,autoFocus:!0,placeholder:I(`sessions.sidebar.folderItem.namePlaceholder`),onClick:Ov,onPointerDown:kv,onMouseDown:Av,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),ae();return}(e.key===` `||e.key===`Enter`)&&e.stopPropagation()}}),(0,$.jsx)(`button`,{type:`submit`,className:`shrink-0 text-muted-foreground hover:text-foreground`,onClick:jv,onPointerDown:Mv,onMouseDown:Nv,children:(0,$.jsx)(Z,{name:`check`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ae()},onPointerDown:Pv,onMouseDown:Fv,className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`min-w-0 flex items-center gap-1.5 flex-1`,children:[(0,$.jsx)(`span`,{className:J(`typography-ui-label font-semibold truncate`,j?`text-primary`:`text-muted-foreground`),children:n.name}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70 flex-shrink-0`,children:[`• `,r.length]}),a?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`})]}),t[37]=H,t[38]=n.name,t[39]=ae,t[40]=oe,t[41]=U,t[42]=a,t[43]=j,t[44]=ee,t[45]=r.length,t[46]=I,t[47]=Te):Te=t[47];let Ee;t[48]!==xe||t[49]!==we||t[50]!==Te?(Ee=(0,$.jsxs)(`div`,{className:xe,children:[we,Te]}),t[48]=xe,t[49]=we,t[50]=Te,t[51]=Ee):Ee=t[51];let De;t[52]!==O||t[53]!==P||t[54]!==M||t[55]!==n.name||t[56]!==ne||t[57]!==N||t[58]!==c||t[59]!==S||t[60]!==C||t[61]!==ee||t[62]!==I?(De=!ee&&(!N||P)?(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 px-0.5`,children:(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 transition-opacity`,O?`opacity-100`:`opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100`,P&&`absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0`),children:[!P&&S?(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},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":I(`sessions.sidebar.folderItem.newSessionAria`,{folderName:n.name}),title:I(`sessions.sidebar.project.actions.newSession`),children:(0,$.jsx)(Z,{name:`add`,className:`h-3.5 w-3.5`})}):null,!P&&C&&M===0?(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),C()},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":I(`sessions.sidebar.folderItem.newSubfolderAria`,{folderName:n.name}),title:I(`sessions.sidebar.folderItem.newSubfolder`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`h-3.5 w-3.5`})}):null,P?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne()},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":I(`sessions.sidebar.folderItem.renameAria`,{folderName:n.name}),children:(0,$.jsx)(Z,{name:`pencil-ai`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},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":I(P?`sessions.sidebar.folderItem.deleteArchivedInFolderAria`:`sessions.sidebar.folderItem.deleteFolderAria`,{folderName:n.name}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-3.5 w-3.5`})})]})}):null,t[52]=O,t[53]=P,t[54]=M,t[55]=n.name,t[56]=ne,t[57]=N,t[58]=c,t[59]=S,t[60]=C,t[61]=ee,t[62]=I,t[63]=De):De=t[63];let Oe;t[64]!==b||t[65]!==pe||t[66]!==me||t[67]!==he||t[68]!==ge||t[69]!==_e||t[70]!==ve||t[71]!==ye||t[72]!==Ee||t[73]!==De?(Oe=(0,$.jsxs)(`div`,{ref:b,className:pe,style:me,onClick:he,role:ge,tabIndex:_e,onKeyDown:ve,"aria-label":ye,children:[Ee,De]}),t[64]=b,t[65]=pe,t[66]=me,t[67]=he,t[68]=ge,t[69]=_e,t[70]=ve,t[71]=ye,t[72]=Ee,t[73]=De,t[74]=Oe):Oe=t[74];let ke=a||void 0,Ae;t[75]!==P||t[76]!==M||t[77]!==u||t[78]!==d||t[79]!==f||t[80]!==l||t[81]!==F||t[82]!==r||t[83]!==i||t[84]!==I?(Ae=r.length>0?r.map(e=>l(e,M+1,d??null,f??null,P,F,`project`,u?.(e))):i?null:(0,$.jsx)(`div`,{className:`py-1.5 pr-2 text-left typography-micro text-muted-foreground/70`,style:{paddingLeft:Za(M+1)},children:I(`sessions.sidebar.folderItem.emptyFolder`)}),t[75]=P,t[76]=M,t[77]=u,t[78]=d,t[79]=f,t[80]=l,t[81]=F,t[82]=r,t[83]=i,t[84]=I,t[85]=Ae):Ae=t[85];let je;t[86]!==i||t[87]!==Ae?(je=(0,$.jsxs)(`div`,{className:`pb-1`,children:[i,Ae]}),t[86]=i,t[87]=Ae,t[88]=je):je=t[88];let Me;t[89]!==ke||t[90]!==je?(Me=(0,$.jsx)(qc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ke,children:je}),t[89]=ke,t[90]=je,t[91]=Me):Me=t[91];let Ne;return t[92]!==ue||t[93]!==Oe||t[94]!==Me?(Ne=(0,$.jsxs)(Yc,{open:ue,className:de,children:[Oe,Me]}),t[92]=ue,t[93]=Oe,t[94]=Me,t[95]=Ne):Ne=t[95],Ne});function Ev(e){return e.stopPropagation()}function Dv(e){return e.stopPropagation()}function Ov(e){return e.stopPropagation()}function kv(e){return e.stopPropagation()}function Av(e){return e.stopPropagation()}function jv(e){return e.stopPropagation()}function Mv(e){return e.stopPropagation()}function Nv(e){return e.stopPropagation()}function Pv(e){return e.stopPropagation()}function Fv(e){return e.stopPropagation()}var Iv=3e4,Lv=e=>{let t=e,n=t.metadata?.yuri?.titleRefresh,r=on(e)||0;return[e.title??``,e.share?e.share.url??`1`:``,t.hasChildren?`1`:``,t.parentID??``,t.metadata?.yuri?.assistant?`1`:``,n?.isGenerating?`1`:``,String(n?.lastError??``),String(n?.failedAt??``),Math.floor(r/Iv)].join(`\0`)},Rv=(e,t,n)=>{if(!t)return;let r=e=>{let i=e.session.id===t;for(let t of e.children)i=r(t)||i;return i&&n.add(e.session.id),i};for(let t of e)r(t)},zv=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(let n of e.children)if(zv(n,t))return!0;return!1},Bv=e=>e.children.length===0?``:e.children.map(e=>e.children.length===0?e.session.id:`${e.session.id}:${Bv(e)}`).join(`|`),Vv=(e,t,n,r)=>{if(!t)return null;let i=r?`archived`:`active`,a=null,o=e=>{if(`${n}:${i}:${e.session.id}`===t)return a=e.session.id,!0;for(let t of e.children)if(o(t))return!0;return!1};return e.forEach(e=>o(e)),a},Hv=50,Uv=30,Wv=28,Gv=[],Kv=(e,t)=>t?e.sessions.some(e=>zv(e,t)):!1,qv=(e,t,n)=>{let r=e=>{let i=e.session.id;return t.has(i)!==n.has(i)||e.children.some(r)};return e.sessions.some(r)},Jv=(e,t,n)=>{let r=e=>{let i=e.session.id;return t.has(i)!==n.has(i)||e.children.some(r)};return e.sessions.some(r)},Yv=(e,t,n)=>{let r=i=>{let a=i.session.id,o=e.folderScopeKey??I(e.directory??null);return(o?t[o]?.indexOf(a):-1)!==(o?n[o]?.indexOf(a):-1)||i.children.some(r)};return e.sessions.some(r)},Xv=(e,t,n)=>{let r=e.folderScopeKey??I(e.directory??null);return!!(r&&t[r]!==n[r])},Zv=(e,t,n)=>{let r=e.isArchivedBucket?`archived`:`active`,i=e=>{let a=`project:${r}:${e.session.id}`;return t.has(a)!==n.has(a)||e.children.some(i)};return e.sessions.some(i)},Qv=(e,t,n)=>{let r=e=>{let i=e.session.id,a=t.get(i)??e.session,o=n.get(i)??e.session;return a!==o&&Lv(a)!==Lv(o)||e.children.some(r)};return e.sessions.some(r)},$v=e=>{if(e.projectId)return e.projectRepoStatus.has(e.projectId)?e.projectRepoStatus.get(e.projectId):void 0},ey=e=>{let t=new WeakMap,n=e=>{t.set(e,Bv(e));for(let t of e.children)n(t)};return e.forEach(n),t},ty=e=>{let t=[],n=e=>{e.forEach(e=>{t.push(e.session),e.children.length>0&&n(e.children)})};return n(e),t},ny=(e,t)=>{if(e.group!==t.group||e.groupKey!==t.groupKey||e.isArchivedLoading!==t.isArchivedLoading||e.projectId!==t.projectId||e.hideGroupLabel!==t.hideGroupLabel||e.compactBodyPadding!==t.compactBodyPadding||e.groupSearchDataByGroup.get(e.group)!==t.groupSearchDataByGroup.get(t.group)||e.visibleSessionCount!==t.visibleSessionCount||e.collapsedGroups!==t.collapsedGroups&&e.collapsedGroups.has(e.groupKey)!==t.collapsedGroups.has(t.groupKey)||e.projectRepoStatus!==t.projectRepoStatus&&$v(e)!==$v(t)||e.pinnedSessionIds!==t.pinnedSessionIds&&qv(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&Zv(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderByScope!==t.sessionOrderByScope&&Yv(t.group,e.sessionOrderByScope,t.sessionOrderByScope)||e.sessionOrderActivityByScope!==t.sessionOrderActivityByScope&&Xv(t.group,e.sessionOrderActivityByScope,t.sessionOrderActivityByScope)||e.currentSessionId!==t.currentSessionId&&(Kv(e.group,e.currentSessionId)||Kv(t.group,t.currentSessionId))||e.editingId!==t.editingId&&(Kv(e.group,e.editingId)||Kv(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Kv(e.group,e.editingId)||Kv(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Vv(e.group.sessions,e.openSidebarMenuKey,`project`,!!e.group.isArchivedBucket),r=Vv(t.group.sessions,t.openSidebarMenuKey,`project`,!!t.group.isArchivedBucket);if(n||r)return!1}if(e.liveSessionById!==t.liveSessionById&&Qv(t.group,e.liveSessionById,t.liveSessionById)||e.alwaysVisibleSessionIds!==t.alwaysVisibleSessionIds&&Jv(t.group,e.alwaysVisibleSessionIds,t.alwaysVisibleSessionIds))return!1;if(e.prVisualStateByDirectoryBranch!==t.prVisualStateByDirectoryBranch){let n=e.group?.directory&&e.group?.branch?e.prVisualStateByDirectoryBranch.get(`${e.group.directory}::${e.group.branch.trim()}`):void 0,r=t.group?.directory&&t.group?.branch?t.prVisualStateByDirectoryBranch.get(`${t.group.directory}::${t.group.branch.trim()}`):void 0;if(!Object.is(n,r))return!1}return e.hasSessionSearchQuery===t.hasSessionSearchQuery&&e.normalizedSessionSearchQuery===t.normalizedSessionSearchQuery&&e.collapsedFolderIds===t.collapsedFolderIds&&e.toggleFolderCollapse===t.toggleFolderCollapse&&e.renameFolder===t.renameFolder&&e.deleteFolder===t.deleteFolder&&e.showDeletionDialog===t.showDeletionDialog&&e.setDeleteFolderConfirm===t.setDeleteFolderConfirm&&e.renderSessionNode===t.renderSessionNode&&e.lastRepoStatus===t.lastRepoStatus&&e.showMoreGroupSessions===t.showMoreGroupSessions&&e.resetGroupSessionLimit===t.resetGroupSessionLimit&&e.mobileVariant===t.mobileVariant&&e.alwaysShowActions===t.alwaysShowActions&&e.activeProjectId===t.activeProjectId&&e.setActiveProjectIdOnly===t.setActiveProjectIdOnly&&e.setActiveMainTab===t.setActiveMainTab&&e.setSessionSwitcherOpen===t.setSessionSwitcherOpen&&e.openNewSessionDraft===t.openNewSessionDraft&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.renamingFolderId===t.renamingFolderId&&e.renameFolderDraft===t.renameFolderDraft&&e.setRenameFolderDraft===t.setRenameFolderDraft&&e.setRenamingFolderId===t.setRenamingFolderId&&e.onToggleCollapsedGroup===t.onToggleCollapsedGroup&&e.onReorderSessions===t.onReorderSessions&&e.dragHandleProps===t.dragHandleProps&&e.scrollContainerRef===t.scrollContainerRef&&e.shortcutTargetSessionId===t.shortcutTargetSessionId&&e.shortcutTargetVisibleIndex===t.shortcutTargetVisibleIndex};function ry(e){let{t}=wt(),{group:n,groupKey:r,isArchivedLoading:i=!1,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:s,normalizedSessionSearchQuery:c,groupSearchDataByGroup:l,visibleSessionCount:u,collapsedGroups:d,collapsedFolderIds:f,toggleFolderCollapse:p,renameFolder:m,deleteFolder:h,showDeletionDialog:g,setDeleteFolderConfirm:_,renderSessionNode:v,projectRepoStatus:y,lastRepoStatus:b,showMoreGroupSessions:x,resetGroupSessionLimit:S,mobileVariant:C,alwaysShowActions:w,activeProjectId:T,setActiveProjectIdOnly:E,setActiveMainTab:D,setSessionSwitcherOpen:O,openNewSessionDraft:k,addSessionToFolder:A,createFolderAndStartRename:j,renamingFolderId:M,renameFolderDraft:N,setRenameFolderDraft:P,setRenamingFolderId:F,pinnedSessionIds:L,expandedParents:R,sessionOrderByScope:z,sessionOrderActivityByScope:B,onReorderSessions:V,currentSessionId:ee,shortcutTargetSessionId:H=null,shortcutTargetVisibleIndex:ne=null,editingId:re,openSidebarMenuKey:U,prVisualStateByDirectoryBranch:ie,onToggleCollapsedGroup:ae,dragHandleProps:W,compactBodyPadding:oe=!1,scrollContainerRef:se,alwaysVisibleSessionIds:ce}=e,G=n.folderScopeKey??I(n.directory??null),le=Q.useMemo(()=>Gs(n.sessions,G?z[G]:void 0,G?B[G]:void 0,L),[G,n.sessions,L,B,z]),ue=s?l.get(n):null,de=Kt(e=>e.displayMode),fe=nr(e=>G?e.foldersMap[G]??Gv:Gv),pe=de===`minimal`&&!te(),me=n.isArchivedBucket?null:I(n.directory??null),he=en(e=>me?e.activePaginationByDirectory.get(me):void 0),ge=!s&&d.has(r),_e=Ws(),ve=Math.max(_e,u??_e),ye=s?ue?.groupMatches===!0:!1,be=s,xe=Q.useMemo(()=>[...be?ue?.filteredNodes??[]:n.sessions].sort(le),[le,n.sessions,ue?.filteredNodes,be]),Se=Q.useMemo(()=>{let e=new Map,t=n=>{n.forEach(n=>{e.set(n.session.id,n),n.children.length>0&&t(n.children)})};return t(xe),e},[xe]),Ce=Q.useMemo(()=>fe.map(e=>({folder:e,nodes:e.sessionIds.map(e=>Se.get(e)).filter(e=>!!e).sort(le)})),[fe,Se,le]),we=Q.useMemo(()=>{let e=new Map(Ce.map(e=>[e.folder.id,e])),t=new Map;for(let{folder:e}of Ce){if(!e.parentId)continue;let n=t.get(e.parentId);n?n.push(e.id):t.set(e.parentId,[e.id])}let r=new Map,i=a=>{let o=r.get(a);if(o!==void 0)return o;let l=e.get(a);if(!l)return r.set(a,!1),!1;let u=t.get(a)??[];if(n.isArchivedBucket&&l.nodes.length===0){let e=u.some(e=>i(e));return r.set(a,e),e}if(!s||l.folder.name.toLowerCase().includes(c)||l.nodes.length>0)return r.set(a,!0),!0;let d=u.some(e=>i(e));return r.set(a,d),d};return Ce.filter(({folder:e})=>i(e.id))},[Ce,n.isArchivedBucket,s,c]),Te=Q.useMemo(()=>new Set(we.flatMap(e=>e.folder.sessionIds)),[we]),Ee=Q.useMemo(()=>xe.filter(e=>!Te.has(e.session.id)),[xe,Te]),De=Q.useMemo(()=>we.filter(({folder:e})=>!e.parentId),[we]),Oe=`project`,ke=Q.useMemo(()=>{let e=new Set;return Rv(xe,ee,e),we.forEach(({nodes:t})=>{Rv(t,ee,e)}),e},[xe,we,ee]),Ae=Q.useMemo(()=>{let e=new Set;return Rv(xe,re,e),we.forEach(({nodes:t})=>{Rv(t,re,e)}),e},[xe,we,re]),je=Q.useMemo(()=>{if(!U)return null;let e=Vv(xe,U,Oe,!!n.isArchivedBucket);if(e)return e;for(let{nodes:e}of we){let t=Vv(e,U,Oe,!!n.isArchivedBucket);if(t)return t}return null},[U,xe,we,n.isArchivedBucket]),Me=Q.useMemo(()=>ey(xe),[xe]),Ne=Q.useMemo(()=>{let e=new WeakMap;return we.forEach(({nodes:t})=>{t.forEach(t=>e.set(t,Bv(t)))}),e},[we]),K=Q.useMemo(()=>e=>Me.get(e)??Ne.get(e)??``,[Me,Ne]),Pe=Q.useMemo(()=>e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e)}),[ke,Ae,je,K]),Fe=Ee.length,Ie=n.isArchivedBucket||s?Ee:Ee.slice(0,ve),Le=n.isArchivedBucket||s?Ee:ec(Ee,ve,ce),Re=Fe-Le.length,ze=Q.useMemo(()=>Oc({folders:we,visibleUngroupedNodes:Le,collapsedFolderIds:f,hasSessionSearchQuery:s}),[we,f,s,Le]),Be=he?.hasMore===!0,Ve=he?.loadingMore===!0,He=u===void 0||u<=_e,Ue=!n.isArchivedBucket&&!s&&Fe>_e&&!He,We=n.isArchivedBucket===!0&&!s&&Le.length>=Hv,Ge=n.isArchivedBucket!==!0&&!s&&Le.length>=Uv,Ke=We||Ge,qe=n.isArchivedBucket?`archived`:`active`,Je=Ke&&Le.some(e=>{if(e.children.length===0)return!1;let t=`project:${qe}:${e.session.id}`;return R.has(t)}),Ye=Q.useRef(null),[Xe,q]=Q.useState(null),[,Ze]=Q.useState(0),Qe=_t(e=>{Ye.current=e,Ze(e=>e+1)});gt(Ke?Ye:null,()=>{Ze(e=>e+1)}),Q.useLayoutEffect(()=>{if(!Ke){q(e=>e===null?e:null);return}let e=Ye.current;if(!e){q(e=>e===null?e:null);return}let t=null,n=se?.current??null;if(n&&n.contains(e))t=n;else{let n=e.parentElement;for(;n;){let e=window.getComputedStyle(n);if(e.overflowY===`auto`||e.overflowY===`scroll`){t=n;break}n=n.parentElement}}if(!t){q(e=>e===null?e:null);return}let r=e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop;q(n=>n?.container===e&&n.scrollElement===t&&Math.abs(n.scrollMargin-r)<1?n:{container:e,scrollElement:t,scrollMargin:r})});let $e=Ye.current,et=se?.current??null,tt=Ke&&Xe!==null&&Xe.container===$e&&Xe.scrollElement.contains($e)&&(et===null||Xe.scrollElement===et),nt=Xe?.scrollElement??null,rt=Xe?.scrollMargin??0;vt(`transitionend`,e=>{e.propertyName===`height`&&e.target instanceof HTMLElement&&e.target.hasAttribute(`data-sidebar-collapse`)&&Ze(e=>e+1)},tt?nt:null);let it=is({count:Le.length,enabled:tt,getScrollElement:()=>nt,initialOffset:()=>nt?.scrollTop??0,estimateSize:()=>Wv,overscan:Je?20:8,scrollMargin:rt,getItemKey:e=>Le[e]?.session.id??e}),at=Qs(Le,H,ne);Q.useLayoutEffect(()=>{!tt||!H||at===null||it.getVirtualItems().some(e=>e.index===at)||it.scrollToIndex(at,{align:`auto`,behavior:`auto`})},[rt,it,H,at,tt]);let ot=Q.useMemo(()=>ty(xe),[xe]),st=Q.useMemo(()=>{if(!n.isArchivedBucket)return new Map;let e=new Map,t=new Map;for(let{folder:e}of we){if(!e.parentId)continue;let n=t.get(e.parentId)??[];n.push(e.id),t.set(e.parentId,n)}let r=(e,n)=>{if(n.has(e))return[];n.add(e);let i=we.find(({folder:t})=>t.id===e),a=i?ty(i.nodes):[],o=t.get(e)??[];for(let e of o)a.push(...r(e,n));return a};for(let{folder:t}of we)e.set(t.id,r(t.id,new Set));return e},[we,n.isArchivedBucket]),ct=Q.useMemo(()=>({projectLabel:n.isMain?null:n.label,branchLabel:n.branch&&n.branch!==`HEAD`?n.branch:null}),[n.branch,n.isMain,n.label]),lt=_t(e=>{e.preventDefault(),e.stopPropagation();let t=I(n.directory??null),r=n.branch?.trim()??null,i=t&&r?ie.get(`${t}::${r}`)?.url??null:null;i&&Go(i)});if(s&&!ye&&De.length===0&&Ee.length===0)return null;let ut=a&&y.has(a)?!!y.get(a):b,dt=I(n.directory??null),ft=n.branch?.trim()??null,pt=dt&&ft?ie.get(`${dt}::${ft}`)??null:null,mt=!!(pt&&n.branch),ht=!pt&&!n.isMain&&!!n.branch,yt=pt&&pt.state===`open`&&pt.checks?t(`sessions.sidebar.group.pr.checksPassed`,{success:pt.checks.success,total:pt.checks.total}):null,bt=pt&&pt.state===`open`&&pt.checks?[pt.checks.failure>0?t(`sessions.sidebar.group.pr.failingCount`,{count:pt.checks.failure}):null,pt.checks.pending>0?t(`sessions.sidebar.group.pr.pendingCount`,{count:pt.checks.pending}):null].filter(e=>!!e).join(`, `):null,xt=pt&&pt.state===`open`?pt.mergeableState===`blocked`||pt.mergeableState===`dirty`?t(`sessions.sidebar.group.pr.conflictsOrBlocked`):pt.mergeableState===`clean`||pt.canMerge===!0?t(`sessions.sidebar.group.pr.mergeable`):null:null,St=pt&&pt.state===`open`&&pt.mergeableState?t(`sessions.sidebar.group.pr.mergeState`,{state:pt.mergeableState}):null,Ct=pt?.base??null,Tt=pt?.head??null,Et=(()=>{if(!pt)return n.branch&&Sa(n.branch,n.label)?{label:n.branch,color:null}:null;switch(pt.visualState){case`merged`:return{label:t(`sessions.sidebar.group.pr.status.merged`),color:`var(--pr-merged)`};case`open`:return pt.canMerge===!0||pt.mergeableState===`clean`||pt.checks?.state===`success`?{label:t(`sessions.sidebar.group.pr.status.readyToMerge`),color:`var(--pr-open)`}:{label:t(`sessions.sidebar.group.pr.status.open`),color:`var(--pr-open)`};case`blocked`:return{label:pt.mergeableState===`dirty`?t(`sessions.sidebar.group.pr.status.mergeConflicts`):t(`sessions.sidebar.group.pr.status.mergeBlocked`),color:`var(--pr-blocked)`};case`draft`:return{label:t(`sessions.sidebar.group.pr.status.draft`),color:`var(--pr-draft)`};case`closed`:return{label:t(`sessions.sidebar.group.pr.status.closed`),color:`var(--pr-closed)`};default:return null}})(),Dt=(e,t,r)=>{let i=we.filter(({folder:t})=>t.parentId===e.id),o=i.length>0?(0,$.jsx)($.Fragment,{children:i.map(({folder:e,nodes:t})=>Dt(e,t,r+1))}):void 0,c=st.get(e.id)??[];return(0,$.jsx)(lc,{folderId:e.id,children:(i,l)=>(0,$.jsx)(Tv,{folder:e,sessions:t,subFolderItems:o,isCollapsed:!s&&f.has(e.id),onToggle:()=>p(e.id),onRename:t=>{G&&m(G,e.id,t)},onDelete:()=>{if(n.isArchivedBucket){yn.requestDelete({sessions:c,mode:`session`});return}if(!G)return;if(!g){h(G,e.id);return}let r=we.filter(({folder:t})=>t.parentId===e.id).length,i=t.length;_({scopeKey:G,folderId:e.id,folderName:e.name,subFolderCount:r,sessionCount:i})},renderSessionNode:v,getRenderExtras:K?e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe}):void 0,groupDirectory:n.directory,projectId:a,mobileVariant:C,alwaysShowActions:w,isRenaming:M===e.id,renameDraft:M===e.id?N:void 0,onRenameDraftChange:e=>P(e),onRenameSave:()=>{let t=N.trim();t&&G&&m(G,e.id,t),F(null),P(``)},onRenameCancel:()=>{F(null),P(``)},droppableRef:i,isDropTarget:l,depth:r,onNewSession:()=>{a&&a!==T&&E(a),D(`chat`),C&&O(!1),k({directoryOverride:n.directory,targetFolderId:e.id})},onNewSubFolder:r===0?()=>{G&&j(G,e.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0,sessionSecondaryMeta:{projectLabel:e.name,branchLabel:n.branch&&n.branch!==`HEAD`?n.branch:null}})},e.id)},Ot=+!o,kt=o?1:Ot,At=()=>De.map(({folder:e,nodes:t})=>Dt(e,t,kt)),jt=!!(!n.isMain&&n.worktree),Mt=w?jt?`pr-14`:`pr-7`:pe?jt?`pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-2`:jt?`pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-5`,Y=(0,$.jsxs)(fc,{scopeKey:G,sessionIds:ze.sessionIds,folderIdBySessionId:ze.folderIdBySessionId,onSessionDroppedOnFolder:(e,t)=>{G&&A(G,t,e)},onSessionsReordered:(e,t)=>{V(n,ze.sessionIds,e,t,Ks(n.sessions.map(e=>e.session)))},children:[At(),Ke?(0,$.jsx)(`div`,{ref:Qe,children:tt?(0,$.jsx)(`div`,{style:{height:it.getTotalSize(),position:`relative`},children:it.getVirtualItems().map(e=>{let t=Le[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:it.measureElement,className:`[&_[data-session-row]]:my-px`,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start-rt}px)`},children:v(t,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(t),childRenderExtrasFor:Pe})},t.session.id):null})}):Le.map(e=>v(e,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe}))}):Le.map(e=>v(e,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe})),Fe===0&&we.length===0?(0,$.jsx)(`div`,{className:Va,style:{paddingLeft:Za(kt)},children:i?t(`sessions.sidebar.project.loadingSessions`):n.isArchivedBucket?t(`sessions.sidebar.group.empty.noArchivedSessions`):t(`sessions.sidebar.group.empty.noSessionsInWorkspace`)}):null,Re>0||Be||Ue?(0,$.jsxs)(`div`,{className:J(Va,`flex w-full items-center gap-3 text-muted-foreground/60`),style:{paddingLeft:Za(kt)},children:[Re>0||Be?(0,$.jsx)(`button`,{type:`button`,onClick:()=>x(n,r,Ie.length,Fe),disabled:Ve,className:J(`text-left transition-colors hover:text-muted-foreground/80 disabled:pointer-events-none`,Ve&&`animate-pulse`),children:t(`sessions.sidebar.group.showMore`)}):null,Ue?(0,$.jsx)(`button`,{type:`button`,onClick:()=>S(r),className:`text-left transition-colors hover:text-muted-foreground/80`,children:t(`sessions.sidebar.group.showFewer`)}):null]}):null]}),Nt=o?oe?`pb-0`:`pb-0.5`:oe?`pb-1`:`pb-1.5`,Pt=Za(Ot);return o?(0,$.jsx)(`div`,{className:`yuri-group`,children:(0,$.jsx)(`div`,{className:J(`yuri-group-body`,Nt),children:Y})}):(0,$.jsxs)(Yc,{open:!ge,className:`yuri-group`,children:[(0,$.jsxs)(`div`,{"data-mobile-press-feedback":W?`none`:void 0,className:J(`group/gh relative flex min-w-0 cursor-pointer items-start justify-between gap-1.5 rounded-lg py-1.5 pr-2`,Na),style:{paddingLeft:Pt},onClick:()=>ae(n,r,a),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ae(n,r,a))},"aria-label":t(ge?`sessions.sidebar.group.expandAria`:`sessions.sidebar.group.collapseAria`,{label:n.label}),"aria-expanded":!ge,children:[(0,$.jsx)(`div`,{ref:W?.setActivatorNodeRef,className:J(`min-w-0 flex flex-1 items-start gap-1.5 overflow-hidden transition-[padding] cursor-grab active:cursor-grabbing`,Mt),...W?.listeners??{},children:(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden`,children:[(0,$.jsx)(`p`,{className:`text-[14px] font-normal truncate text-foreground/92`,children:mt&&pt?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center`,children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 leading-none align-middle`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),pt.url?(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center leading-none`,onMouseDown:e=>e.stopPropagation(),onClick:lt,children:[`#`,pt.number]}):(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center leading-none`,children:[`#`,pt.number]})]})}),(0,$.jsx)(la,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||Tt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&Tt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(Z,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:Tt})]}):(0,$.jsx)(`span`,{children:Ct??Tt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||yt?(0,$.jsxs)(`div`,{className:`text-muted-foreground truncate`,children:[xt??``,xt&&yt?` • `:``,yt??``,bt?` (${bt})`:``]}):null]})})]}),(0,$.jsx)(`span`,{className:`ml-1 min-w-0 flex-1 truncate leading-none align-middle`,children:n.branch})]}):n.isArchivedBucket?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`archive`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ca(n.label,c)})]}):!n.isMain||n.worktree?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ca(n.label,c)})]}):Ca(n.label,c)}),ht&&Et?(0,$.jsxs)(`span`,{className:J(`inline-flex min-w-0 items-center gap-1.5 leading-tight`,!Et.color&&`text-muted-foreground`),style:Et.color?{color:Et.color}:void 0,children:[n.isArchivedBucket?(0,$.jsx)(Z,{name:`archive`,className:`h-3.5 w-3.5 flex-shrink-0`}):!n.isMain||ut?mt&&pt?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center`,children:(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(la,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||Tt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&Tt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(Z,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:Tt})]}):(0,$.jsx)(`span`,{children:Ct??Tt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||yt?(0,$.jsxs)(`div`,{className:`text-muted-foreground truncate`,children:[xt??``,xt&&yt?` • `:``,yt??``,bt?` (${bt})`:``]}):null]})})]}):(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5 flex-shrink-0`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[11px] font-medium`,children:Et.label})]}):null]})}),n.isArchivedBucket&&ot.length>0?(0,$.jsx)(`div`,{className:J(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),yn.requestDelete({sessions:ot,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":t(`sessions.sidebar.group.actions.deleteArchivedInGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.group.actions.deleteArchivedSessions`)})})]})}):null,n.directory&&!n.isMain&&n.worktree?(0,$.jsx)(`div`,{className:J(`absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),yn.requestDelete({sessions:ot,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":t(`sessions.sidebar.group.actions.deleteGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.group.actions.deleteWorktree`)})})]})}):null,n.directory?(0,$.jsx)(`div`,{className:J(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a&&a!==T&&E(a),D(`chat`),C&&O(!1),k({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":t(`sessions.sidebar.group.actions.newDraftInGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.project.actions.newDraftSession`)})})]})}):null]}),(0,$.jsx)(qc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ge||void 0,children:(0,$.jsx)(`div`,{className:J(`yuri-group-body`,Nt),children:Y})})]})}var iy=Q.memo(ry,ny);function ay(e){let t=(0,fl.c)(36),{t:n}=wt(),{hideDirectoryControls:r,isSessionSearchOpen:i,setIsSessionSearchOpen:a,sessionSearchInputRef:o,sessionSearchQuery:s,setSessionSearchQuery:c,hasSessionSearchQuery:l,searchMatchCount:u}=e;if(r||!i)return null;let d;t[0]!==l||t[1]!==u||t[2]!==n?(d=l?(0,$.jsx)(`span`,{children:n(u===1?`sessions.sidebar.header.search.matchCountSingle`:`sessions.sidebar.header.search.matchCountPlural`,{count:u})}):(0,$.jsx)(`span`,{}),t[0]=l,t[1]=u,t[2]=n,t[3]=d):d=t[3];let f;t[4]===n?f=t[5]:(f=n(`sessions.sidebar.header.search.escapeHint`),t[4]=n,t[5]=f);let p;t[6]===f?p=t[7]:(p=(0,$.jsx)(`span`,{children:f}),t[6]=f,t[7]=p);let m;t[8]!==d||t[9]!==p?(m=(0,$.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80`,children:[d,p]}),t[8]=d,t[9]=p,t[10]=m):m=t[10];let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),t[11]=h):h=t[11];let g;t[12]===c?g=t[13]:(g=e=>c(e.target.value),t[12]=c,t[13]=g);let _;t[14]===n?_=t[15]:(_=n(`sessions.sidebar.header.search.placeholder`),t[14]=n,t[15]=_);let v;t[16]!==l||t[17]!==a||t[18]!==c?(v=e=>{e.key===`Escape`&&(e.stopPropagation(),l?c(``):a(!1))},t[16]=l,t[17]=a,t[18]=c,t[19]=v):v=t[19];let y;t[20]!==o||t[21]!==s||t[22]!==g||t[23]!==_||t[24]!==v?(y=(0,$.jsx)(`input`,{ref:o,value:s,onChange:g,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:v}),t[20]=o,t[21]=s,t[22]=g,t[23]=_,t[24]=v,t[25]=y):y=t[25];let b;t[26]!==s.length||t[27]!==c||t[28]!==n?(b=s.length>0?(0,$.jsx)(`button`,{type:`button`,onClick:()=>c(``),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:(0,$.jsx)(Z,{name:`close`,className:`h-3.5 w-3.5`})}):null,t[26]=s.length,t[27]=c,t[28]=n,t[29]=b):b=t[29];let x;t[30]!==y||t[31]!==b?(x=(0,$.jsxs)(`div`,{className:`relative`,children:[h,y,b]}),t[30]=y,t[31]=b,t[32]=x):x=t[32];let S;return t[33]!==x||t[34]!==m?(S=(0,$.jsx)(`div`,{className:`select-none flex-shrink-0 px-3 py-1`,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[m,x]})}),t[33]=x,t[34]=m,t[35]=S):S=t[35],S}function oy(e){let t=(0,fl.c)(13),{title:n,accessory:r,isFirst:i,onToggle:a,expanded:o,className:s}=e,c=i!==void 0&&i?`pt-1 pb-1`:`pt-4 pb-1`,l;t[0]!==s||t[1]!==c?(l=J(`group/section flex w-full items-center gap-1 px-2`,c,s),t[0]=s,t[1]=c,t[2]=l):l=t[2];let u;t[3]!==o||t[4]!==a||t[5]!==n?(u=a?(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:`group/toggle flex min-w-0 flex-1 items-center gap-1 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,"aria-expanded":o,children:[(0,$.jsx)(`span`,{className:`typography-micro font-normal tracking-wide text-muted-foreground/80`,children:n}),(0,$.jsx)(Z,{name:o?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 opacity-0 transition-opacity group-hover/toggle:opacity-100 group-focus-visible/toggle:opacity-100`})]}):(0,$.jsx)(`span`,{className:J(`flex min-w-0 flex-1 items-center gap-1`,`typography-micro font-normal tracking-wide text-muted-foreground/80`),children:n}),t[3]=o,t[4]=a,t[5]=n,t[6]=u):u=t[6];let d;t[7]===r?d=t[8]:(d=r?(0,$.jsx)(`div`,{className:`ml-auto -mr-2 flex shrink-0 items-center`,children:r}):null,t[7]=r,t[8]=d);let f;return t[9]!==l||t[10]!==u||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:l,children:[u,d]}),t[9]=l,t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function sy(e){let t=(0,fl.c)(60),{items:n,reorderEnabled:r,onSessionsReordered:i,inProgressItems:a,renderSessionNode:o,currentSessionId:s,editingId:c,openSidebarMenuKey:l,headerAccessory:u,onVisibleSessionIdsChange:d}=e,f=r!==void 0&&r,p;t[0]===a?p=t[1]:(p=a===void 0?[]:a,t[0]=a,t[1]=p);let m=p,{t:h}=wt(),[g,_]=Q.useState(!1),v=f&&!c&&n.length>1&&!!i,y;t[2]===n?y=t[3]:(y=n.map(hy),t[2]=n,t[3]=y);let b=y,x;t[4]===b?x=t[5]:(x=new Map(b.map(my)),t[4]=b,t[5]=x);let S=x,C=oi(py),w,T;t[6]!==g||t[7]!==m||t[8]!==n||t[9]!==d?(w=()=>{if(g){d?.([]);return}d?.([...n.map(fy),...m.map(dy)])},T=[g,m,n,d],t[6]=g,t[7]=m,t[8]=n,t[9]=d,t[10]=w,t[11]=T):(w=t[10],T=t[11]),Q.useLayoutEffect(w,T);let E,D;t[12]!==m||t[13]!==n||t[14]!==C?(E=()=>{C&&(n.some(e=>e.node.session.id===C)||m.some(e=>e.node.session.id===C))&&_(!1)},D=[m,n,C],t[12]=m,t[13]=n,t[14]=C,t[15]=E,t[16]=D):(E=t[15],D=t[16]),Q.useLayoutEffect(E,D);let O,k,A,j;if(t[17]!==s||t[18]!==c||t[19]!==m||t[20]!==n||t[21]!==l){let e=[...n,...m].map(uy);A=new Set,Rv(e,s,A),j=new Set,Rv(e,c,j),O=Vv(e,l,`pinned`,!1),k=new WeakMap;let r=e=>{k.set(e,Bv(e)),e.children.forEach(r)};e.forEach(r),t[17]=s,t[18]=c,t[19]=m,t[20]=n,t[21]=l,t[22]=O,t[23]=k,t[24]=A,t[25]=j}else O=t[22],k=t[23],A=t[24],j=t[25];let M;t[26]!==O||t[27]!==k||t[28]!==A||t[29]!==j?(M=e=>({subtreeContainsActive:A,subtreeContainsEditing:j,menuOpenSessionId:O,nodeStructureKey:k.get(e)??``,childRenderExtrasFor:M}),t[26]=O,t[27]=k,t[28]=A,t[29]=j,t[30]=M):M=t[30];let N;t[31]!==M||t[32]!==O||t[33]!==k||t[34]!==A||t[35]!==j?(N=e=>({subtreeContainsActive:A,subtreeContainsEditing:j,menuOpenSessionId:O,nodeStructureKey:k.get(e)??``,childRenderExtrasFor:M}),t[31]=M,t[32]=O,t[33]=k,t[34]=A,t[35]=j,t[36]=N):N=t[36];let P=N;if(n.length+m.length===0)return null;let F;t[37]!==P||t[38]!==o?(F=e=>e.map(e=>{let t=o(e.node,0,e.groupDirectory,e.projectId,!1,e.secondaryMeta,`pinned`,P(e.node));return(0,$.jsx)(Q.Fragment,{children:t},e.node.session.id)}),t[37]=P,t[38]=o,t[39]=F):F=t[39];let I=F,L;t[40]!==m.length||t[41]!==h?(L=m.length>0?h(`directoryTree.section.pinnedInProgress`):h(`directoryTree.section.pinned`),t[40]=m.length,t[41]=h,t[42]=L):L=t[42];let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>_(ly),t[43]=R):R=t[43];let z=!g,B;t[44]!==u||t[45]!==L||t[46]!==z?(B=(0,$.jsx)(oy,{title:L,onToggle:R,expanded:z,accessory:u}),t[44]=u,t[45]=L,t[46]=z,t[47]=B):B=t[47];let V;t[48]!==v||t[49]!==g||t[50]!==S||t[51]!==m||t[52]!==n||t[53]!==i||t[54]!==I||t[55]!==b?(V=g?null:(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[v?(0,$.jsx)(fc,{scopeKey:ic,sessionIds:b,folderIdBySessionId:S,onSessionDroppedOnFolder:cy,onSessionsReordered:(e,t)=>i?.(e,t),children:I(n)}):I(n),I(m)]}),t[48]=v,t[49]=g,t[50]=S,t[51]=m,t[52]=n,t[53]=i,t[54]=I,t[55]=b,t[56]=V):V=t[56];let ee;return t[57]!==B||t[58]!==V?(ee=(0,$.jsx)(ua,{delay:0,closeDelay:150,timeout:600,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[B,V]})}),t[57]=B,t[58]=V,t[59]=ee):ee=t[59],ee}function cy(){}function ly(e){return!e}function uy(e){return e.node}function dy(e){return e.node.session.id}function fy(e){return e.node.session.id}function py(e){return e.focus?.scope===`pinned`?e.focus.sessionId:null}function my(e){return[e,null]}function hy(e){return e.node.session.id}function gy(e){let t=(0,fl.c)(41),{collapseAllProjects:n,expandAllProjects:r,buttonClassName:i,iconClassName:a}=e,{t:o}=wt(),s;t[0]===i?s=t[1]:(s=J(`size-6 p-0 text-muted-foreground`,i),t[0]=i,t[1]=s);let c;t[2]===o?c=t[3]:(c=o(`sessions.sidebar.header.actions.sessionDisplayMode`),t[2]=o,t[3]=c);let l;t[4]===a?l=t[5]:(l=J(`h-3.5 w-3.5`,a),t[4]=a,t[5]=l);let u;t[6]===l?u=t[7]:(u=(0,$.jsx)(Z,{name:`more-2-fill`,className:l}),t[6]=l,t[7]=u);let d;t[8]!==s||t[9]!==c||t[10]!==u?(d=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:s,"aria-label":c,onClick:_y,children:u})})}),t[8]=s,t[9]=c,t[10]=u,t[11]=d):d=t[11];let f;t[12]===o?f=t[13]:(f=o(`sessions.sidebar.header.displayMode.label`),t[12]=o,t[13]=f);let p;t[14]===f?p=t[15]:(p=(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f})}),t[14]=f,t[15]=p);let m;t[16]!==d||t[17]!==p?(m=(0,$.jsxs)(da,{children:[d,p]}),t[16]=d,t[17]=p,t[18]=m):m=t[18];let h;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Z,{name:`contract-up-down`,className:`h-4 w-4`}),t[19]=h):h=t[19];let g;t[20]===o?g=t[21]:(g=o(`sessions.sidebar.header.displayMode.collapseAll`),t[20]=o,t[21]=g);let _;t[22]===g?_=t[23]:(_=(0,$.jsx)(`span`,{children:g}),t[22]=g,t[23]=_);let v;t[24]!==n||t[25]!==_?(v=(0,$.jsxs)(Da,{onClick:n,className:`flex items-center gap-2`,children:[h,_]}),t[24]=n,t[25]=_,t[26]=v):v=t[26];let y;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Z,{name:`expand-up-down`,className:`h-4 w-4`}),t[27]=y):y=t[27];let b;t[28]===o?b=t[29]:(b=o(`sessions.sidebar.header.displayMode.expandAll`),t[28]=o,t[29]=b);let x;t[30]===b?x=t[31]:(x=(0,$.jsx)(`span`,{children:b}),t[30]=b,t[31]=x);let S;t[32]!==r||t[33]!==x?(S=(0,$.jsxs)(Da,{onClick:r,className:`flex items-center gap-2`,children:[y,x]}),t[32]=r,t[33]=x,t[34]=S):S=t[34];let C;t[35]!==v||t[36]!==S?(C=(0,$.jsxs)(Pa,{align:`end`,className:`min-w-[160px]`,children:[v,S]}),t[35]=v,t[36]=S,t[37]=C):C=t[37];let w;return t[38]!==C||t[39]!==m?(w=(0,$.jsxs)(Ua,{children:[m,C]}),t[38]=C,t[39]=m,t[40]=w):w=t[40],w}function _y(e){e.stopPropagation()}var vy=()=>rt({queryKey:[l(),u(),`device-connections`],queryFn:async({signal:e})=>{let t=await _(`/api/client-auth/clients`,{signal:e});if(!t.ok)throw Error(`Device list unavailable`);let n=await t.json();if(!Array.isArray(n.clients))throw Error(`Invalid device list`);if(n.clients.some(e=>typeof e.connected!=`boolean`))throw Error(`Presence unavailable`);return n.clients.filter(e=>!e.revokedAt&&e.connected&&e.clientKind!==`desktop-local`&&e.id!==n.currentClientId)},staleTime:0,retry:!1});function yy(){let e=(0,fl.c)(53),{t}=wt(),{clientAuth:n}=at(),[r,i]=(0,Q.useState)(!1),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=vy(),e[0]=a):a=e[0];let o=r&&!!n,s=r?5e3:!1,c;e[1]!==o||e[2]!==s?(c={...a,enabled:o,refetchInterval:s},e[1]=o,e[2]=s,e[3]=c):c=e[3];let l=it(c),u;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{i(!1);let e=q.getState();e.setSettingsRemoteInstancesSelectedId(null),e.setSettingsPage(`remote-instances`),q.setState({devicePairingRequested:!0}),e.setSettingsDialogOpen(!0)},e[4]=u):u=e[4];let d=_t(u);if(!n)return null;let f;e[5]===t?f=e[6]:(f=t(`settings.remoteInstances.quick.title`),e[5]=t,e[6]=f);let p;e[7]===f?p=e[8]:(p=(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`group size-7 rounded-md text-foreground/55 hover:bg-interactive-hover hover:text-foreground`,"aria-label":f}),e[7]=f,e[8]=p);let m;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Z,{name:`devices-connected`,className:`size-[18px]`}),e[9]=m):m=e[9];let h;e[10]===p?h=e[11]:(h=(0,$.jsx)(be,{openOnHover:!0,delay:180,closeDelay:200,render:p,children:m}),e[10]=p,e[11]=h);let g;e[12]===t?g=e[13]:(g=t(`settings.remoteInstances.quick.title`),e[12]=t,e[13]=g);let _;e[14]===g?_=e[15]:(_=(0,$.jsx)(ve,{className:`typography-ui-label font-medium`,children:g}),e[14]=g,e[15]=_);let v;e[16]===l.data?v=e[17]:(v=l.data&&l.data.length>0?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground tabular-nums`,children:l.data.length}):null,e[16]=l.data,e[17]=v);let y;e[18]!==_||e[19]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 pb-2 pt-4`,children:[_,v]}),e[18]=_,e[19]=v,e[20]=y):y=e[20];let b;e[21]!==l.isPending||e[22]!==t?(b=l.isPending?(0,$.jsx)(`p`,{className:`px-2 py-3 typography-meta text-muted-foreground`,children:t(`common.loading`)}):null,e[21]=l.isPending,e[22]=t,e[23]=b):b=e[23];let x;e[24]!==l.isError||e[25]!==t?(x=l.isError?(0,$.jsx)(`p`,{className:`px-2 py-3 typography-meta text-muted-foreground`,children:t(`settings.remoteInstances.quick.error`)}):null,e[24]=l.isError,e[25]=t,e[26]=x):x=e[26];let S;e[27]!==l.data?.length||e[28]!==l.isError||e[29]!==t?(S=!l.isError&&l.data?.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center px-5 pb-5 pt-6 text-center`,children:[(0,$.jsx)(Z,{name:`devices-connected`,className:`mb-4 size-16 text-muted-foreground/45`}),(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:t(`settings.remoteInstances.clientAuth.state.empty`)}),(0,$.jsx)(`p`,{className:`mt-2 typography-meta leading-relaxed text-muted-foreground`,children:t(`settings.remoteInstances.quick.emptyHint`)})]}):null,e[27]=l.data?.length,e[28]=l.isError,e[29]=t,e[30]=S):S=e[30];let C;e[31]!==l.data||e[32]!==t?(C=l.data?.map(e=>{let n=e.devicePlatform?.toLowerCase();return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-muted)] px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center text-muted-foreground`,children:(0,$.jsx)(Z,{name:n===`ios`?`device-ios`:n===`android`?`device-android`:`device-desktop`,className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate typography-ui-label`,children:e.label}),(0,$.jsx)(`p`,{className:`mt-0.5 truncate typography-micro text-[var(--status-success)]`,children:t(`desktopHostSwitcher.status.connected`)})]})]},e.id)}),e[31]=l.data,e[32]=t,e[33]=C):C=e[33];let w;e[34]!==b||e[35]!==x||e[36]!==S||e[37]!==C?(w=(0,$.jsxs)(`div`,{className:`max-h-64 space-y-2 overflow-y-auto px-3 pb-2`,"aria-live":`polite`,children:[b,x,S,C]}),e[34]=b,e[35]=x,e[36]=S,e[37]=C,e[38]=w):w=e[38];let T;e[39]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Z,{name:`add`,className:`size-4`}),e[39]=T):T=e[39];let E;e[40]===t?E=e[41]:(E=t(`settings.remoteInstances.clientAuth.actions.addDevice`),e[40]=t,e[41]=E);let D;e[42]!==d||e[43]!==E?(D=(0,$.jsx)(`div`,{className:`px-3 pb-3 pt-1`,children:(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,className:`w-full justify-center gap-2 rounded-xl`,onClick:d,children:[T,E]})}),e[42]=d,e[43]=E,e[44]=D):D=e[44];let O;e[45]!==y||e[46]!==w||e[47]!==D?(O=(0,$.jsx)(ye,{children:(0,$.jsx)(Oe,{side:`top`,align:`start`,sideOffset:10,className:`z-50`,children:(0,$.jsxs)(we,{className:`w-72 max-w-[calc(100vw-24px)] origin-[var(--transform-origin)] overflow-hidden rounded-2xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-foreground shadow-lg outline-none transition-[opacity,transform] duration-150 data-[starting-style]:translate-y-1 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0`,children:[y,w,D]})})}),e[45]=y,e[46]=w,e[47]=D,e[48]=O):O=e[48];let k;return e[49]!==r||e[50]!==O||e[51]!==h?(k=(0,$.jsxs)(Ee,{open:r,onOpenChange:i,children:[h,O]}),e[49]=r,e[50]=O,e[51]=h,e[52]=k):k=e[52],k}var by=`group size-7 rounded-md text-muted-foreground/75 transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary`,xy=`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`;function Sy(e){let t=(0,fl.c)(12),{onOpenSettings:n,onOpenShortcuts:r,onOpenUpdate:i,showRuntimeButtons:a,showUpdateButton:o}=e,s=a===void 0||a,c=o!==void 0&&o,{t:l}=wt(),u;t[0]!==n||t[1]!==r||t[2]!==s||t[3]!==l?(u=s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:by,onClick:n,"aria-label":l(`sessions.sidebar.footer.actions.settings`),children:(0,$.jsx)(Z,{name:`settings-3`,className:xy})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.settings`)})]}),(0,$.jsx)(yy,{}),(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:by,onClick:r,"aria-label":l(`sessions.sidebar.footer.actions.shortcuts`),children:(0,$.jsx)(Z,{name:`question`,className:xy})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.shortcuts`)})]})]}):null,t[0]=n,t[1]=r,t[2]=s,t[3]=l,t[4]=u):u=t[4];let d;t[5]!==i||t[6]!==c||t[7]!==l?(d=c&&i?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:`ml-auto size-6 rounded-full [corner-shape:round] supports-[corner-shape:squircle]:rounded-full border border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)] active:bg-[var(--primary-hover)]`,onClick:i,"aria-label":l(`sessions.sidebar.footer.actions.update`),children:(0,$.jsx)(Z,{name:`download`,className:`size-3.5`})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:l(`sessions.sidebar.footer.actions.update`)})})]}):null,t[5]=i,t[6]=c,t[7]=l,t[8]=d):d=t[8];let f;return t[9]!==u||t[10]!==d?(f=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-start gap-1 px-2.5 py-2`,children:[u,d]}),t[9]=u,t[10]=d,t[11]=f):f=t[11],f}var Cy=Q.memo(function(e){let t=(0,fl.c)(64),{id:n,disabled:r,projectLabel:i,projectDescription:a,projectIcon:o,projectColor:s,projectIconImage:c,isCollapsed:l,isActiveProject:u,isSessionsLoading:d,isRepo:f,isDesktopShell:p,isStuck:m,hideDirectoryControls:h,alwaysShowActions:g,onToggle:_,onNewSession:v,onNewWorktreeSession:y,onSyncSessions:b,onRenameStart:x,onClose:S,sentinelRef:C,children:w,showCreateButtons:T,hideHeader:E,openSidebarMenuKey:D,setOpenSidebarMenuKey:O,reorderEnabled:k}=e,A=r!==void 0&&r,j=d!==void 0&&d,M=T===void 0||T,N=E!==void 0&&E,P=k===void 0||k,{t:F}=wt(),I=A||!P,L;t[0]!==n||t[1]!==I?(L={id:n,disabled:I},t[0]=n,t[1]=I,t[2]=L):L=t[2];let{attributes:R,listeners:z,setNodeRef:B,transform:V,transition:ee,isDragging:H}=Ho(L),te=Q.useRef(!1),ne=`project:${n}`,re=D===ne,[U,ie]=Q.useState(!1),ae=o?ea[o]:null,W=s?ra[s]:void 0,oe=ae??`folder-open`,se;t[3]===W?se=t[4]:(se=W?{color:W}:void 0,t[3]=W,t[4]=se);let ce;t[5]!==oe||t[6]!==se?(ce=(0,$.jsx)(Z,{name:oe,className:`h-4 w-4`,style:se}),t[5]=oe,t[6]=se,t[7]=ce):ce=t[7];let G=ce,le;t[8]!==ne||t[9]!==O?(le=e=>{e&&ie(!1),O(e?ne:null)},t[8]=ne,t[9]=O,t[10]=le):le=t[10];let ue=le,de;t[11]!==h||t[12]!==f||t[13]!==S||t[14]!==v||t[15]!==x||t[16]!==b||t[17]!==M||t[18]!==F?(de=e=>(0,$.jsxs)($.Fragment,{children:[M&&!f&&!h&&v&&(0,$.jsxs)(e,{onClick:v,children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.newSession`)]}),(0,$.jsxs)(e,{onClick:b,children:[(0,$.jsx)(Z,{name:`refresh`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.syncSessions`)]}),(0,$.jsxs)(e,{onClick:x,children:[(0,$.jsx)(Z,{name:`pencil-ai`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.edit`)]}),(0,$.jsxs)(e,{onClick:S,className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.closeProject`)]})]}),t[11]=h,t[12]=f,t[13]=S,t[14]=v,t[15]=x,t[16]=b,t[17]=M,t[18]=F,t[19]=de):de=t[19];let fe=de,pe=Ty,me=Ey,he=Dy,ge;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>{(e.button===2||e.button===0&&e.ctrlKey)&&(te.current=!0)},t[20]=ge):ge=t[20];let _e=ge,ve;t[21]===_?ve=t[22]:(ve=()=>{if(te.current){te.current=!1;return}_()},t[21]=_,t[22]=ve);let ye=ve,be;t[23]===V?be=t[24]:(be=zo.Transform.toString(V),t[23]=V,t[24]=be);let xe;t[25]!==be||t[26]!==ee?(xe={transform:be,transition:ee},t[25]=be,t[26]=ee,t[27]=xe):xe=t[27];let Se=H&&`opacity-30`,Ce;t[28]===Se?Ce=t[29]:(Ce=J(`relative`,Se),t[28]=Se,t[29]=Ce);let we;t[30]!==g||t[31]!==R||t[32]!==ue||t[33]!==ye||t[34]!==h||t[35]!==N||t[36]!==n||t[37]!==u||t[38]!==l||t[39]!==U||t[40]!==p||t[41]!==re||t[42]!==f||t[43]!==j||t[44]!==m||t[45]!==z||t[46]!==v||t[47]!==y||t[48]!==a||t[49]!==G||t[50]!==c||t[51]!==i||t[52]!==fe||t[53]!==P||t[54]!==C||t[55]!==M||t[56]!==F?(we=N?null:(0,$.jsxs)($.Fragment,{children:[p&&(0,$.jsx)(`div`,{ref:C,"data-project-id":n,className:`absolute top-0 h-px w-full pointer-events-none`,"aria-hidden":`true`}),(0,$.jsxs)(Vc,{open:U,onOpenChange:ie,children:[(0,$.jsx)(Uc,{render:(0,$.jsx)(`div`,{className:J(`w-full text-left group/project select-none`),style:{backgroundColor:p&&m?`transparent`:void 0},onContextMenu:e=>{h||(e.preventDefault(),ie(!0))}}),children:(0,$.jsxs)(`div`,{className:J(`relative flex items-center gap-1.5 rounded-lg px-2 py-1.5`,Na),...R,children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onMouseDown:_e,onClick:ye,...P?z:{},className:J(`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 transition-[padding]`,P?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,f&&!h?g?`pr-20`:`pr-7 group-hover/project:pr-20 group-has-[:focus-visible]/project:pr-20`:g?`pr-14`:`pr-7 group-hover/project:pr-14 group-has-[:focus-visible]/project:pr-14`),children:[(0,$.jsx)(`span`,{className:`inline-flex h-4 w-4 flex-shrink-0 items-center justify-center overflow-hidden text-foreground`,children:j?(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin`,"aria-label":F(`sessions.sidebar.project.loadingSessions`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:J(`h-4 w-4 items-center justify-center`,g?`inline-flex`:`hidden group-hover/project:inline-flex group-has-[:focus-visible]/project:inline-flex`),children:l?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:J(g?`hidden`:`group-hover/project:hidden group-has-[:focus-visible]/project:hidden`),children:c?(0,$.jsx)(Xi,{project:{id:n,iconImage:c},className:`size-full object-contain`,fallback:G}):G})]})}),(0,$.jsx)(`span`,{className:J(`text-[14px] font-normal truncate lowercase`,u?`text-foreground`:`text-foreground group-hover/project:text-foreground`),children:i})]})}),(0,$.jsx)(la,{side:`right`,sideOffset:8,children:a})]}),(0,$.jsxs)(`div`,{className:J(`absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1`,M?`right-7`:`right-0.5`),children:[M&&f&&!h&&y?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y()},className:J(`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`,g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(`sessions.sidebar.project.actions.newWorktree`),children:(0,$.jsx)(Z,{name:`node-tree`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(`sessions.sidebar.project.actions.newWorktreeEllipsis`)})})]}):null,h?null:(0,$.jsxs)(Ua,{open:re,onOpenChange:ue,children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`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`,re?`opacity-100 pointer-events-auto`:g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(`sessions.sidebar.project.actions.projectMenu`),onPointerDown:me,onMouseDown:he,onClick:pe,children:(0,$.jsx)(Z,{name:`more-2`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Pa,{align:`end`,className:`min-w-[180px]`,children:fe(Da)})]})]}),M&&v?(0,$.jsx)(`div`,{className:`absolute right-0.5 top-1/2 z-10 -translate-y-1/2`,children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},className:J(`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`,g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`),children:(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(la,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`)})})]})}):null]})}),(0,$.jsx)(Wc,{className:`min-w-[180px]`,children:fe(Gc)})]})]}),t[30]=g,t[31]=R,t[32]=ue,t[33]=ye,t[34]=h,t[35]=N,t[36]=n,t[37]=u,t[38]=l,t[39]=U,t[40]=p,t[41]=re,t[42]=f,t[43]=j,t[44]=m,t[45]=z,t[46]=v,t[47]=y,t[48]=a,t[49]=G,t[50]=c,t[51]=i,t[52]=fe,t[53]=P,t[54]=C,t[55]=M,t[56]=F,t[57]=we):we=t[57];let Te;return t[58]!==w||t[59]!==B||t[60]!==xe||t[61]!==Ce||t[62]!==we?(Te=(0,$.jsxs)(`div`,{ref:B,style:xe,className:Ce,children:[we,w]}),t[58]=w,t[59]=B,t[60]=xe,t[61]=Ce,t[62]=we,t[63]=Te):Te=t[63],Te}),wy=Q.memo(e=>{let t=(0,fl.c)(21),{id:n,disabled:r,children:i}=e,a=r!==void 0&&r,o;t[0]!==a||t[1]!==n?(o={id:n,disabled:a},t[0]=a,t[1]=n,t[2]=o):o=t[2];let{listeners:s,setNodeRef:c,setActivatorNodeRef:l,transform:u,transition:d,isDragging:f}=Ho(o),p;t[3]!==s||t[4]!==l?(p={listeners:s,setActivatorNodeRef:l},t[3]=s,t[4]=l,t[5]=p):p=t[5];let m=p,h;t[6]===u?h=t[7]:(h=zo.Transform.toString(u),t[6]=u,t[7]=h);let g;t[8]!==h||t[9]!==d?(g={transform:h,transition:d},t[8]=h,t[9]=d,t[10]=g):g=t[10];let _=f&&`opacity-50`,v;t[11]===_?v=t[12]:(v=J(`space-y-0.5 rounded-md`,_),t[11]=_,t[12]=v);let y;t[13]!==i||t[14]!==m?(y=typeof i==`function`?i(m):i,t[13]=i,t[14]=m,t[15]=y):y=t[15];let b;return t[16]!==c||t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsx)(`div`,{ref:c,style:g,className:v,children:y}),t[16]=c,t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20],b});function Ty(e){e.stopPropagation()}function Ey(e){e.stopPropagation()}function Dy(e){e.stopPropagation()}var Oy={activationConstraint:{distance:8}},ky={coordinateGetter:Bo},Ay=e=>{let t=(0,fl.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(ua,{delay:0,closeDelay:150,timeout:600,children:n}),t[0]=n,t[1]=r),r};function jy(e){let{t}=wt(),n=Ro(Mo(Io,Oy),Mo(No,ky)),r=e.hasSessionSearchQuery?null:(0,$.jsx)(oy,{title:t(`sessions.sidebar.projectsTitle`),isFirst:!e.hasLeadingSection,accessory:e.headerAccessory}),i=Q.useRef(null),a=Q.useRef(new Map),o=Q.useRef(e.getOrderedGroups);o.current!==e.getOrderedGroups&&(o.current=e.getOrderedGroups,a.current.clear());let s=(t,n)=>{let r=a.current,i=r.get(t);if(i&&i.groups===n)return i.ordered;let o=e.getOrderedGroups(t,n);if(r.set(t,{groups:n,ordered:o}),r.size>256){let e=r.keys().next().value;e!==void 0&&r.delete(e)}return o};return e.sharedSessionsOnly?(0,$.jsx)(Ay,{children:(0,$.jsxs)(fo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:[e.topContent,e.hasSharedSessions?null:e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState]})}):e.projectSections.length===0?(0,$.jsx)(Ay,{children:(0,$.jsxs)(fo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:[e.topContent,r,e.emptyState]})}):e.sectionsForRender.length===0?(0,$.jsx)(Ay,{children:(0,$.jsx)(fo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:e.searchEmptyState})}):(0,$.jsx)(Ay,{children:(0,$.jsxs)(fo,{ref:i,useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1 [overflow-anchor:none]`,(e.mobileVariant,``)),children:[e.topContent,e.showOnlyMainWorkspace?(0,$.jsx)(`div`,{className:`space-y-[0.6rem] py-1`,children:(()=>{let n=e.sectionsForRender.find(t=>t.project.id===e.activeProjectId)??e.sectionsForRender[0];if(!n)return e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState;let r=n.groups.find(e=>e.isMain&&e.sessions.length>0)??n.groups.find(e=>e.sessions.length>0)??n.groups.find(e=>e.isMain)??n.groups[0];if(!r)return(0,$.jsx)(`div`,{className:Va,children:t(`sessions.sidebar.empty.noSessions.title`)});let a=n.groups.find(e=>e.isArchivedBucket);return[r,...a&&a.id!==r.id?[a]:[]].map(t=>{let a=`${n.project.id}:${t.id}`,o=t.id===r.id;return(0,$.jsx)(Q.Fragment,{children:e.renderGroupSessions(t,a,n.project.id,o,null,!0,i)},a)})})()}):(0,$.jsxs)($.Fragment,{children:[r,(0,$.jsxs)(Lo,{sensors:n,collisionDetection:Po,onDragEnd:t=>{if(e.isInlineEditing||e.projectSortOrder!==`manual`)return;let{active:n,over:r}=t;!r||n.id===r.id||e.reorderProjects(String(n.id),String(r.id))},children:[(0,$.jsx)(Wo,{items:e.sectionsForRender.map(e=>e.project.id),strategy:Uo,children:e.sectionsForRender.map(t=>{let n=t.project,r=n.id;return(0,$.jsx)(My,{project:n,orderedGroups:s(r,t.groups),isCollapsed:e.collapsedProjects.has(r),isActiveProject:r===e.activeProjectId,isRepo:!!e.projectRepoStatus.get(r),isDesktopShellRuntime:e.isDesktopShellRuntime,isStuck:e.stuckProjectHeaders.has(r),hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,toggleProject:e.toggleProject,setActiveProjectIdOnly:e.setActiveProjectIdOnly,setActiveMainTab:e.setActiveMainTab,setSessionSwitcherOpen:e.setSessionSwitcherOpen,openNewSessionDraft:e.openNewSessionDraft,openNewWorktreeDialog:e.openNewWorktreeDialog,syncProjectSessions:e.syncProjectSessions,openProjectEditDialog:e.openProjectEditDialog,removeProject:e.removeProject,projectHeaderSentinelRefs:e.projectHeaderSentinelRefs,openSidebarMenuKey:e.openSidebarMenuKey===`project:${r}`?e.openSidebarMenuKey:null,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,projectReorderEnabled:e.projectReorderEnabled,projectSortOrder:e.projectSortOrder,isInlineEditing:e.isInlineEditing,setGroupOrderByProject:e.setGroupOrderByProject,renderGroupSessions:e.renderGroupSessions,scrollContainerRef:i,homeDirectory:e.homeDirectory},r)})}),(0,$.jsx)(Fo,{dropAnimation:null})]})]})]})})}var My=Q.memo(function(e){let t=(0,fl.c)(114),{t:n}=wt(),{project:r,orderedGroups:i,isCollapsed:a,renderGroupSessions:o,scrollContainerRef:s,isInlineEditing:c}=e,l=r.id,u;t[0]===r.normalizedPath?u=t[1]:(u=e=>te()?void 0:e.availableWorktreesByProject.get(r.normalizedPath),t[0]=r.normalizedPath,t[1]=u);let d=xn(u),f;t[2]!==r.normalizedPath||t[3]!==d?(f=[r.normalizedPath,...(d??[]).flatMap(Ny)],t[2]=r.normalizedPath,t[3]=d,t[4]=f):f=t[4];let p=f,m;t[5]===p?m=t[6]:(m=e=>p.some(t=>e.loadingDirectories.has(t)),t[5]=p,t[6]=m);let h=en(m),g;t[7]===p?g=t[8]:(g=e=>p.some(t=>e.refreshingDirectories.has(t)),t[7]=p,t[8]=g);let _=en(g),v=Ro(Mo(Io,Oy)),y;t[9]===i?y=t[10]:(y=i.find(Py)??null,t[9]=i,t[10]=y);let b=y,x;t[11]!==i||t[12]!==b?(x=b?i.filter(e=>e.id!==b.id):i,t[11]=i,t[12]=b,t[13]=x):x=t[13];let S=x,C;t[14]!==l||t[15]!==e?(C=()=>e.toggleProject(l),t[14]=l,t[15]=e,t[16]=C):C=t[16];let w=_t(C),T;t[17]!==r.normalizedPath||t[18]!==l||t[19]!==e?(T=()=>{e.isActiveProject||e.setActiveProjectIdOnly(l),e.setActiveMainTab(`chat`),e.mobileVariant&&e.setSessionSwitcherOpen(!1),e.openNewSessionDraft({directoryOverride:r.normalizedPath})},t[17]=r.normalizedPath,t[18]=l,t[19]=e,t[20]=T):T=t[20];let E=_t(T),D;t[21]!==l||t[22]!==e?(D=()=>{e.isActiveProject||e.setActiveProjectIdOnly(l),e.setActiveMainTab(`chat`),e.openNewWorktreeDialog()},t[21]=l,t[22]=e,t[23]=D):D=t[23];let O=_t(D),k;t[24]!==l||t[25]!==e?(k=()=>e.syncProjectSessions(l),t[24]=l,t[25]=e,t[26]=k):k=t[26];let A=_t(k),j;t[27]!==l||t[28]!==e?(j=()=>e.openProjectEditDialog(l),t[27]=l,t[28]=e,t[29]=j):j=t[29];let M=_t(j),N;t[30]!==l||t[31]!==e?(N=()=>e.removeProject(l),t[30]=l,t[31]=e,t[32]=N):N=t[32];let P=_t(N),F;t[33]!==l||t[34]!==e.projectHeaderSentinelRefs.current?(F=t=>{e.projectHeaderSentinelRefs.current.set(l,t)},t[33]=l,t[34]=e.projectHeaderSentinelRefs.current,t[35]=F):F=t[35];let I=_t(F),L;t[36]!==c||t[37]!==S||t[38]!==r.normalizedPath||t[39]!==l||t[40]!==e||t[41]!==b?(L=t=>{if(c)return;let{active:n,over:i}=t;if(!i||n.id===i.id)return;let a=S.findIndex(e=>e.id===n.id),o=S.findIndex(e=>e.id===i.id);if(a===-1||o===-1||a===o)return;let s=Vo(S,a,o).map(Fy),u=b?[b.id,...s]:s,d=new Map(S.map(Iy));Lt.getState().setWorktreeOrder(l,r.normalizedPath,s.flatMap(e=>{let t=d.get(e);return t?.worktree&&t.directory?[t.directory]:[]})),e.setGroupOrderByProject(e=>new Map(e).set(l,u))},t[36]=c,t[37]=S,t[38]=r.normalizedPath,t[39]=l,t[40]=e,t[41]=b,t[42]=L):L=t[42];let R=_t(L),z;t[43]!==l||t[44]!==o||t[45]!==b||t[46]!==s?(z=b?o(b,`${l}:${b.id}`,l,!0,null,void 0,s):null,t[43]=l,t[44]=o,t[45]=b,t[46]=s,t[47]=z):z=t[47];let B;t[48]===S?B=t[49]:(B=S.map(Ly),t[48]=S,t[49]=B);let V;if(t[50]!==c||t[51]!==S||t[52]!==l||t[53]!==o||t[54]!==s){let e;t[56]!==c||t[57]!==l||t[58]!==o||t[59]!==s?(e=e=>(0,$.jsx)(wy,{id:e.id,disabled:c,children:t=>o(e,`${l}:${e.id}`,l,!1,t,void 0,s)},e.id),t[56]=c,t[57]=l,t[58]=o,t[59]=s,t[60]=e):e=t[60],V=S.map(e),t[50]=c,t[51]=S,t[52]=l,t[53]=o,t[54]=s,t[55]=V}else V=t[55];let ee;t[61]!==B||t[62]!==V?(ee=(0,$.jsx)(Wo,{items:B,strategy:Uo,children:V}),t[61]=B,t[62]=V,t[63]=ee):ee=t[63];let H;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(Fo,{dropAnimation:null}),t[64]=H):H=t[64];let ne;t[65]!==v||t[66]!==R||t[67]!==z||t[68]!==ee?(ne=(0,$.jsxs)(Lo,{sensors:v,collisionDetection:Po,onDragEnd:R,children:[z,ee,H]}),t[65]=v,t[66]=R,t[67]=z,t[68]=ee,t[69]=ne):ne=t[69];let re=ne,U=e.projectSortOrder!==`manual`,ie;t[70]===r.normalizedPath?ie=t[71]:(ie=Dt(r.normalizedPath)||r.normalizedPath,t[70]=r.normalizedPath,t[71]=ie);let ae;t[72]!==r.normalizedPath||t[73]!==e.homeDirectory?(ae=xt(r.normalizedPath,e.homeDirectory),t[72]=r.normalizedPath,t[73]=e.homeDirectory,t[74]=ae):ae=t[74];let W=h||_,oe=e.projectReorderEnabled??!1,se=!a,ce=a||void 0,G;t[75]!==re||t[76]!==h||t[77]!==i.length||t[78]!==n?(G=(0,$.jsx)(`div`,{className:`space-y-0 pt-0 pb-0.5`,children:i.length>0?re:h?(0,$.jsx)(`div`,{className:`box-border w-full py-1.5 text-left typography-ui-label font-normal text-muted-foreground/80 animate-pulse select-none`,style:{paddingLeft:Za(1)},role:`status`,"aria-live":`polite`,children:n(`sessions.sidebar.project.loadingSessions`)}):(0,$.jsx)(`div`,{className:Va,children:n(`sessions.sidebar.empty.noSessions.title`)})}),t[75]=re,t[76]=h,t[77]=i.length,t[78]=n,t[79]=G):G=t[79];let le;t[80]!==ce||t[81]!==G?(le=(0,$.jsx)(qc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ce,children:G}),t[80]=ce,t[81]=G,t[82]=le):le=t[82];let ue;t[83]!==se||t[84]!==le?(ue=(0,$.jsx)(Yc,{open:se,children:le}),t[83]=se,t[84]=le,t[85]=ue):ue=t[85];let de;return t[86]!==a||t[87]!==P||t[88]!==E||t[89]!==O||t[90]!==M||t[91]!==A||t[92]!==w||t[93]!==r.color||t[94]!==r.icon||t[95]!==r.iconImage||t[96]!==l||t[97]!==e.alwaysShowActions||t[98]!==e.hideDirectoryControls||t[99]!==e.isActiveProject||t[100]!==e.isDesktopShellRuntime||t[101]!==e.isRepo||t[102]!==e.isStuck||t[103]!==e.mobileVariant||t[104]!==e.openSidebarMenuKey||t[105]!==e.setOpenSidebarMenuKey||t[106]!==I||t[107]!==U||t[108]!==ie||t[109]!==ae||t[110]!==W||t[111]!==oe||t[112]!==ue?(de=(0,$.jsx)(Cy,{id:l,disabled:U,projectLabel:ie,projectDescription:ae,projectIcon:r.icon,projectColor:r.color,projectIconImage:r.iconImage,isCollapsed:a,isActiveProject:e.isActiveProject,isSessionsLoading:W,isRepo:e.isRepo,isDesktopShell:e.isDesktopShellRuntime,isStuck:e.isStuck,hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,onToggle:w,onNewSession:E,onNewWorktreeSession:O,onSyncSessions:A,onRenameStart:M,onClose:P,sentinelRef:I,showCreateButtons:!0,openSidebarMenuKey:e.openSidebarMenuKey,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,reorderEnabled:oe,children:ue}),t[86]=a,t[87]=P,t[88]=E,t[89]=O,t[90]=M,t[91]=A,t[92]=w,t[93]=r.color,t[94]=r.icon,t[95]=r.iconImage,t[96]=l,t[97]=e.alwaysShowActions,t[98]=e.hideDirectoryControls,t[99]=e.isActiveProject,t[100]=e.isDesktopShellRuntime,t[101]=e.isRepo,t[102]=e.isStuck,t[103]=e.mobileVariant,t[104]=e.openSidebarMenuKey,t[105]=e.setOpenSidebarMenuKey,t[106]=I,t[107]=U,t[108]=ie,t[109]=ae,t[110]=W,t[111]=oe,t[112]=ue,t[113]=de):de=t[113],de});function Ny(e){let t=I(e.path);return t?[t]:[]}function Py(e){return e.isMain}function Fy(e){return e.id}function Iy(e){return[e.id,e]}function Ly(e){return e.id}function Ry(e){if(typeof e!=`number`||!Number.isFinite(e))return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toLocaleString(jt(),{month:`short`})} ${t.getDate()}, ${t.getFullYear()}, ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function zy(e){if(e.info.role===`user`)return``;let t=typeof e.info.providerID==`string`?e.info.providerID.trim():``,n=typeof e.info.modelID==`string`?e.info.modelID.trim():``;return t&&n?`${t}/${n}`:n||t}function By(e){let t=e.info.role===`user`?`User`:`Assistant`,n=Ry(e.info.time?.created),r=zy(e),i=n&&r?`${n} (${r})`:n||r;return i?`**${t}**\n\n*${i}*`:`**${t}**`}function Vy(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(``)}function Hy(e){let t=By(e),n=Vy(e.parts).trim();return n?`${t}\n\n${n}`:``}function Uy(e,t){let n=`#`.repeat(Math.min(t+1,6)),r=e.agent?` — ${e.agent}`:``,i=[`${n} Sub-agent: ${e.title}${r}\n\n---\n\n`+e.records.map(Hy).filter(Boolean).join(`
146
+ `);N({sessionKey:t,source:`preview-console`,fileLabel:e||ae||`preview`,startLine:1,endLine:Math.max(1,T.length),code:`${r}${i}`,language:`text`,text:n(`contextPanel.preview.console.attachAnnotation`)}),X.success(n(`contextPanel.preview.console.attached`))},[N,T,j,ae,M,e,n]),[fe,pe]=Q.useState(`unknown`),me=Q.useRef(0),he=Q.useRef(0);Q.useEffect(()=>{if(!H){pe(`unknown`),me.current=0,he.current=0;return}let e=!1;return me.current||(me.current=Date.now(),he.current=0),pe(`unknown`),(async()=>{let t=await(async()=>{try{return await _(H,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){pe(`unreachable`);return}if(t.status===403||t.status===404){ch.delete(z),f({status:`loading`}),u();return}if(t.status!==502){pe(`reachable`);return}let n=me.current||Date.now();if(Date.now()-n<15e3){pe(`starting`),he.current+=1;let t=he.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||s()},n).unref?.();return}pe(`unreachable`)})(),()=>{e=!0}},[z,H,a]);let ge=I&&d.status===`ready`&&(fe===`unknown`||fe===`starting`),_e=I&&d.status===`ready`&&fe===`unreachable`,ve=Q.useCallback(e=>{if(!I||d.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=Kg(ae||H);if(e.origin!==n||e.pathname.startsWith(d.proxyBasePath))return;let r=`${d.proxyBasePath}${e.pathname}${e.search}${e.hash}`;t.location.replace(r)}catch{}},[ae,I,H,d]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,title:W||e,children:W||e||n(`contextPanel.preview.empty`)}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>s(),title:n(`contextPanel.preview.actions.reload`),"aria-label":n(`contextPanel.preview.actions.reload`),disabled:!ae,children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>{V&&qo(V)},title:n(`contextPanel.preview.actions.openExternal`),"aria-label":n(`contextPanel.preview.actions.openExternal`),disabled:!V,children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})}),I?(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:D?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>O(e=>!e),title:n(`contextPanel.preview.inspect.toggle`),"aria-label":n(`contextPanel.preview.inspect.toggle`),disabled:!y,children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,I?(0,$.jsxs)(Y,{type:`button`,size:`sm`,variant:x?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>S(e=>!e),title:n(y?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":n(y?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!y&&T.length===0,children:[(0,$.jsx)(Z,{name:`terminal-box`,className:`h-3.5 w-3.5`}),G>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:G}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[ge?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.startingServerHint`)})]}):_e?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>s(),children:n(`contextPanel.preview.actions.retry`)})]}):ae&&(!I||fe===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:g,src:ae,title:n(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:B},onLoad:ve,sandbox:I?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${ae}:${a}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.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:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):oe?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.loading`)}):se?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.proxyError`)}),d.status===`error`?(0,$.jsx)(`div`,{className:`text-center text-xs opacity-70`,children:d.message}):null]}):(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.invalidUrl`)}),x?(0,$.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:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:de,disabled:T.length===0,children:n(`contextPanel.preview.console.attach`)}),(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:ue,disabled:T.length===0,children:n(`contextPanel.preview.console.copy`)}),(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>E([]),disabled:T.length===0,children:n(`contextPanel.preview.console.clear`)})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/30 px-3 py-1.5`,children:[`all`,`errors`,`warnings`,`logs`].map(e=>(0,$.jsx)(Y,{type:`button`,size:`xs`,variant:C===e?`secondary`:`ghost`,onClick:()=>w(e),children:n(e===`all`?`contextPanel.preview.console.filter.all`:e===`errors`?`contextPanel.preview.console.filter.errors`:e===`warnings`?`contextPanel.preview.console.filter.warnings`:`contextPanel.preview.console.filter.logs`)},e))}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-auto p-2 typography-code text-xs`,children:T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.empty`)}):le.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.noFilteredEvents`)}):le.map(e=>(0,$.jsx)(`div`,{className:`border-b border-border/30 px-2 py-1 last:border-b-0`,children:(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:J(`shrink-0 uppercase`,e.level===`error`||e.level===`runtime`||e.level===`resource`?`text-status-error`:e.level===`warn`?`text-status-warning`:`text-muted-foreground`),children:e.level}),(0,$.jsx)(`span`,{className:`min-w-0 break-words text-foreground`,children:e.message})]})},e.id))})]}):null]})]})},Zg=()=>typeof window<`u`&&!!window.__YURI_ELECTRON__,Qg=({initialUrl:e,directory:t,tabID:n})=>{let{t:i}=Tt(),a=Q.useRef(null),s=q(e=>e.setContextPanelTabTargetPath),l=Qm(e),u=l===`about:blank`?``:l,[d,f]=Q.useState(u),[p,h]=Q.useState(u),[g,v]=Q.useState(u),[y,b]=Q.useState(()=>u?[u]:[]),[x,S]=Q.useState(()=>u?0:-1),[C,w]=Q.useReducer(e=>e+1,0),[T,E]=Q.useState(!!u),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState({status:`idle`}),[N,P]=Q.useState(``),F=Sn(e=>e.currentSessionId),I=Sn(e=>e.newSessionDraft?.open),L=Ki(e=>e.addDraft),R=xn(e=>e.addAttachedFile),z=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||s(t,n,e)},[t,n,s]),B=Q.useCallback((e,t)=>{let n=Qm(e),r=n===`about:blank`?``:n;h(r),f(r),t?.inFrame?E(!1):(v(r),E(!!r)),z(r),b(e=>{if(!r)return S(-1),[];if(t?.replaceHistory)return e;let n=x>=0?e.slice(0,x+1):[];if(n[n.length-1]===r)return S(n.length-1),n;let i=[...n,r];return S(i.length-1),i})},[x,z]),V=Q.useRef(p);V.current=p,Q.useEffect(()=>{let t=$m(e,V.current);t!==null&&B(t)},[e,B]);let ee=Q.useCallback(e=>{let t=y[e];t&&(S(e),h(t),v(t),f(t),E(!0),z(t))},[y,z]),H=Q.useCallback(()=>{if(p){E(!0);try{a.current?.contentWindow?.location.reload()}catch{w()}}},[p]);Q.useEffect(()=>{if(!g){M({status:`idle`});return}let e=fh(g),t=dh(e);if(t?.previewToken){M({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&ch.delete(e);let n=!1;return M({status:`loading`}),E(!0),(async()=>{try{let t=await _(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:g,allowExternal:!0})});if(!t.ok){let e=await t.json().catch(()=>({})),r=typeof e?.error==`string`?e.error:`HTTP ${t.status}`;n||M({status:`error`,message:r});return}let r=await t.json(),a=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,o=typeof r.previewToken==`string`?r.previewToken:``,s=typeof r.expiresAt==`number`?r.expiresAt:0;if(!a||!o){n||M({status:`error`,message:i(`contextPanel.preview.proxyError`)});return}ch.set(e,{proxyBasePath:a,previewToken:o,expiresAt:s}),n||M({status:`ready`,proxyBasePath:a,previewToken:o,expiresAt:s})}catch(e){if(!n){let t=e instanceof Error?e.message:String(e);M({status:`error`,message:t})}}})(),()=>{n=!0}},[g,i]);let te=g&&j.status===`ready`?`${j.proxyBasePath}|${j.previewToken||``}|${C}`:``;Q.useEffect(()=>{if(!te){P(``);return}let e=!1;return P(``),r(m()).then(t=>{!e&&t&&P(te)}).catch(()=>{}),()=>{e=!0}},[te]);let ne=Q.useMemo(()=>{if(N!==te||!g||j.status!==`ready`)return``;try{let e=new URL(g),t=e.pathname||`/`,n=new URLSearchParams(e.search);n.delete(`yuri_url_token`),n.delete(`yuri_client_token`),n.set(`yuriPreview`,String(C)),n.set(`yuri_preview_token`,j.previewToken||``);let r=n.toString();return c().authenticatedAsset(`${j.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,j,te,C,N]),re=o()&&Yh(),[U,ie]=Q.useState(``);Q.useEffect(()=>{if(!re){ie(``);return}let e=!1;return ie(``),bg().then(t=>{!e&&t&&ie(t)}).catch(()=>{e||ie(``)}),()=>{e=!0}},[re,te]);let ae=ne?Bh({relayActive:re,gatewayOrigin:U||null,authenticatedAssetUrl:ne}):``,W=re&&!!ne&&!U,oe=W?``:ae||(j.status===`error`&&!re?g:``),se=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath,r=Kg(oe||ne);if(!(t.origin===window.location.origin||r&&t.origin===r)||!t.pathname.startsWith(n))return``;let i=t.pathname.slice(n.length)||`/`,a=new URL(g).origin;return Yg(new URL(`${i}${t.search}${t.hash}`,a).toString())}catch{return``}},[oe,g,ne,j]),ce=Q.useCallback(e=>{if(!e||!g||j.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=new URL(g).origin,r=Kg(oe||ne);if(!(t.origin===window.location.origin||r&&t.origin===r)||n===window.location.origin)return``;let i=j.proxyBasePath.endsWith(`/`)?j.proxyBasePath.slice(0,-1):j.proxyBasePath;return t.pathname.startsWith(i)?``:Yg(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[oe,g,ne,j]),G=Q.useCallback(e=>{let t=a.current?.contentWindow;t&&qg(t,oe||ne,{source:`yuri-preview-parent`,version:1,type:`set-inspect-mode`,enabled:e})},[oe,ne]),le=Q.useCallback(async e=>{let t=F??(I?`draft`:null);if(!t){X.error(i(`contextPanel.preview.inspect.attachNoSession`));return}let n=a.current,r=n?.contentWindow,o=n?.getBoundingClientRect(),s={width:Number.isFinite(r?.innerWidth)?r?.innerWidth??o?.width??0:o?.width??0,height:Number.isFinite(r?.innerHeight)?r?.innerHeight??o?.height??0:o?.height??0},c=n?await ah(n,e):null,l=!!c;c&&await R(c),L({sessionKey:t,source:`preview-annotation`,fileLabel:p||`browser`,startLine:1,endLine:1,code:ih({pageUrl:p,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:i(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),X.success(i(`contextPanel.preview.inspect.attached`))},[R,L,F,p,I,i]),ue=Q.useCallback(()=>{let e=a.current;A(null),G(!1),e&&Wg(e,Hg).catch(()=>{})},[G]);Q.useEffect(()=>{if(!D)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),O(!1),ue())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ue,D]),Q.useEffect(()=>()=>ue(),[ue]),Q.useEffect(()=>{let e=e=>{if(e.source!==a.current?.contentWindow)return;let t=e.data;if(!(!t||t.source!==`yuri-preview-bridge`||t.version!==1)){if(t.type===`ready`){let e=typeof t.url==`string`?t.url:``,n=se(e);n&&n!==p&&B(n,{inFrame:!0});return}if(t.type===`hover`){A(rh(t.target)?t.target:null);return}if(t.type===`select`&&rh(t.target)){A(null),O(!1),G(!1),le(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ce(e);if(n){B(n);return}e&&B(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[B,le,p,se,ce,G]);let de=Q.useCallback(()=>{let e=a.current;if(!(!e||!p)){if(D){O(!1),ue();return}if(ne){A(null),O(!0),G(!0);return}O(!0),(async()=>{try{let t=await Wg(e,Vg);if(O(!1),!t||!rh(t))return;await le(t)}catch{O(!1),X.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[le,ue,p,D,G,ne,i]),fe=Q.useCallback(()=>{try{let e=a.current?.contentWindow?.location.href||``,t=ce(e);if(t){B(t,{inFrame:!0});return}}catch{}E(!1),D&&ne&&G(!0)},[B,ce,D,G,ne]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<=0,onClick:()=>ee(x-1),children:(0,$.jsx)(Z,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:x<0||x>=y.length-1,onClick:()=>ee(x+1),children:(0,$.jsx)(Z,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:H,children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),B(d)},children:(0,$.jsx)(`input`,{value:d,onChange:e=>f(e.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":i(`contextPanel.browser.addressAria`)})}),(0,$.jsx)(Y,{type:`button`,variant:D?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:de,title:i(`contextPanel.preview.inspect.toggle`),"aria-label":i(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!p,onClick:()=>void qo(p),children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[oe?(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(`iframe`,{ref:a,src:oe,title:i(`contextPanel.browser.empty`),className:`absolute inset-0 h-full w-full border-0 bg-background`,allow:`clipboard-read; clipboard-write; fullscreen`,allowFullScreen:!0,onLoad:fe},`${n}:${C}`),D&&k?(0,$.jsx)(`div`,{className:`pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35`,style:{left:k.bounds.x,top:k.bounds.y,width:k.bounds.width,height:k.bounds.height},children:(0,$.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:[k.tag,k.text?` · ${k.text}`:``]})}):null]}):(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(Ca,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:i(`contextPanel.browser.empty`)}),(0,$.jsx)(`span`,{className:`max-w-sm typography-micro text-muted-foreground`,children:i(`contextPanel.browser.emptyHint`)}),(0,$.jsx)(`span`,{className:`max-w-md typography-micro leading-relaxed text-status-warning/70`,children:i(`contextPanel.browser.trustNotice`)})]}),T||W?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:i(`common.loading`)}):null]})]})},$g=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=Tt(),i=Q.useRef(null),a=q(e=>e.setContextPanelTabTargetPath),o=Qm(e),s=o===`about:blank`?``:o,c=Q.useRef(Qm(e)),[l,u]=Q.useState(s),[d,f]=Q.useState(s),[p,m]=Q.useState(!1),[h,g]=Q.useState(!0),_=Q.useRef(null),v=h,y=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||a(t,n,e)},[t,n,a]),b=Sn(e=>e.currentSessionId),x=Sn(e=>e.newSessionDraft?.open),S=Ki(e=>e.addDraft),C=xn(e=>e.addAttachedFile);Q.useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{try{let t=e.getURL();t&&t!==`about:blank`&&(f(t),u(t),y(t))}catch{}},n=e=>{let t=e.detail;typeof t?.url==`string`&&t.url&&(f(t.url),u(t.url),y(t.url))},r=()=>{_.current&&clearTimeout(_.current),_.current=setTimeout(()=>g(!0),200)},a=()=>{_.current&&clearTimeout(_.current),g(!1),t()},o=e=>{let t=e.detail;if(t?.disposition===`new-window`||t?.disposition===`foreground-tab`||t?.disposition===`background-tab`){e.preventDefault();let n=i.current;typeof n?.loadURL==`function`&&t.url&&n.loadURL(t.url)}},s=()=>{try{e.executeJavaScript?.(Ug,!0).catch(()=>{})}catch{}};e.addEventListener(`did-navigate`,n),e.addEventListener(`did-navigate-in-page`,n),e.addEventListener(`did-start-loading`,r),e.addEventListener(`did-stop-loading`,a),e.addEventListener(`new-window`,o),e.addEventListener(`dom-ready`,s);try{e.isLoading()||(g(!1),t())}catch{}return s(),()=>{_.current&&clearTimeout(_.current),e.removeEventListener(`did-navigate`,n),e.removeEventListener(`did-navigate-in-page`,n),e.removeEventListener(`did-start-loading`,r),e.removeEventListener(`did-stop-loading`,a),e.removeEventListener(`new-window`,o),e.removeEventListener(`dom-ready`,s)}},[y]),Q.useEffect(()=>{let e=setTimeout(()=>g(!1),3e4);return()=>clearTimeout(e)},[]),Q.useEffect(()=>{if(!p)return;let e=e=>{if(e.key!==`Escape`)return;e.preventDefault(),e.stopImmediatePropagation(),m(!1);let t=i.current;try{t?.executeJavaScript?.(Hg).catch(()=>{})}catch{}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[p]),Q.useEffect(()=>{let e=i.current;return()=>{try{let r=e?.getURL?.();r&&r!==`about:blank`&&a(t,n,r)}catch{}try{e?.executeJavaScript?.(Hg).catch(()=>{})}catch{}}},[t,n,a]);let w=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=Qm(e);try{t.loadURL(n)}catch{}},[]),T=Q.useRef(d);T.current=d,Q.useEffect(()=>{let t=$m(e,T.current);t!==null&&(f(t),u(t),g(!0),w(t))},[e,w]);let E=Q.useCallback(()=>{let e=i.current;if(e){if(p){m(!1);try{e.executeJavaScript?.(Hg).catch(()=>{})}catch{}return}m(!0),e.executeJavaScript?.(Vg,!0).then(async t=>{if(m(!1),!t||!rh(t))return;let n=b??(x?`draft`:null);if(!n){X.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await xt(`desktop_browser_capture_page`,{webContentsId:i}),o=await e.executeJavaScript?.(`({ width: window.innerWidth, height: window.innerHeight })`,!0).catch(()=>null),s=Number.isFinite(o?.width)?o.width:a.width,c=Number.isFinite(o?.height)?o.height:a.height,l=await oh(a.base64,a.width,a.height,s,c,t),u=!!l;l&&await C(l),S({sessionKey:n,source:`preview-annotation`,fileLabel:d||`browser`,startLine:1,endLine:1,code:ih({pageUrl:d,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),X.success(r(`contextPanel.preview.inspect.attached`))}).catch(()=>m(!1))}},[C,S,b,d,p,x,r]);return(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goBack?.()}catch{}},children:(0,$.jsx)(Z,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goForward?.()}catch{}},children:(0,$.jsx)(Z,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.reload?.()}catch{}},children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),w(l)},children:(0,$.jsx)(`input`,{value:l,onChange:e=>u(e.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`)})}),(0,$.jsx)(Y,{type:`button`,variant:p?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:E,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(Z,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>void qo(d),children:(0,$.jsx)(Z,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[(0,$.jsx)(`webview`,{ref:i,src:c.current,partition:`persist:yuri-browser`,allowpopups:!0,style:{width:`100%`,height:`100%`,border:`none`}}),(!d||d===`about:blank`)&&!h?(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center`,children:[(0,$.jsx)(Ca,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)})]}):null,v?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground`,children:r(`common.loading`)}):null]})]})},e_=({directory:e})=>{let{t}=Tt(),n=Sn(e=>e.currentSessionId),r=es()??``,i=e?.trim()||r,a=Q.useMemo(()=>Og(i),[i]),s=q(e=>a?e.contextPanelByDirectory[a]:void 0),c=q(e=>a?e.contextToolDiffByDirectory[a]:void 0),l=q(e=>e.closeContextPanel),u=q(e=>e.closeContextPanelTab),d=q(e=>e.openContextPanelTab),p=q(e=>e.toggleContextPanelExpanded),m=q(e=>e.setContextPanelWidth),h=q(e=>e.setActiveContextPanelTab),g=q(e=>e.reorderContextPanelTabs),_=bo(e=>e.setSelectedPath),v=q(e=>e.openContextPreview),y=q(e=>e.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:x,lightThemeId:S,darkThemeId:C,currentTheme:w}=sr(),T=Q.useMemo(()=>s?.tabs??[],[s?.tabs]),E=T.find(e=>e.id===s?.activeTabId)??T[T.length-1]??null,D=!!(s?.isOpen&&E),O=!!(D&&s?.expanded),k=kg(s?.width??Cg),A=Q.useMemo(()=>{let e=[];for(let t of T){if(t.mode!==`chat`)continue;let n=Lg(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[T]),j=Bg(a||void 0,A),[M,N]=Q.useState(!1),[P,F]=Q.useState(!1),I=Q.useRef(0),L=Q.useRef(k),R=Q.useRef(null),z=Q.useRef(null),B=Q.useRef(null),V=Q.useRef(new Map),ee=Q.useRef(new Map),H=Q.useRef(!1),te=Q.useRef(D),ne=Q.useRef(null),[re,U]=Q.useState({}),ie=Q.useRef(re);ie.current=re;let[ae,W]=Q.useReducer(Km,{activeViewKey:null,tabs:{},mountedViews:{}}),oe=mm(),se=f(),ce=Q.useCallback(e=>{let t=ie.current,n=e(t);return n!==t&&(ie.current=n,U(n),!0)},[]),G=Q.useCallback(e=>{if(!a)return;if(q.getState().contextPanelByDirectory[a]?.tabs.find(t=>t.id===e)?.mode===`btw`){let e=Sn.getState().currentSessionId;e&&ri.getState().clear({sessionId:e,directory:a})}W({type:`close-tab`,tabId:e});let t=hm(a,e);ce(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),u(a,e)},[u,ce,a]),le=Q.useCallback(()=>{F(!0),ne.current!==null&&window.cancelAnimationFrame(ne.current),ne.current=window.requestAnimationFrame(()=>{ne.current=null,F(!1)})},[]);Q.useEffect(()=>()=>{ne.current!==null&&window.cancelAnimationFrame(ne.current)},[]),Q.useLayoutEffect(()=>{let e=te.current;if(te.current=D,!D){F(!1);return}e||le()},[D,le]),Q.useEffect(()=>{if(!D||H.current){H.current=D;return}let e=window.requestAnimationFrame(()=>{let e=B.current;e&&!e.contains(document.activeElement)&&e.focus({preventScroll:!0})});return H.current=!0,()=>window.cancelAnimationFrame(e)},[D]);let ue=Q.useCallback(e=>{let t=B.current;t&&t.style.setProperty(`--yuri-context-panel-width`,`${jg(e,t)}px`)},[]),de=Q.useCallback(e=>{if(!(!D||O||!a)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}z.current=e.pointerId,N(!0),I.current=e.clientX,L.current=k,R.current=k,ue(k),e.preventDefault()}},[ue,a,O,D,k]),fe=Q.useCallback(e=>{if(!M||z.current!==e.pointerId)return;let t=I.current-e.clientX,n=jg(L.current+t,B.current);R.current!==n&&(R.current=n,ue(n))},[ue,M]),pe=Q.useCallback(e=>{if(z.current!==e.pointerId||!a)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=jg(R.current??k,B.current);le(),ue(t),R.current=t,m(a,t),N(!1),z.current=null},[ue,a,m,le,k]);Q.useEffect(()=>{M||(R.current=null)},[M]);let me=Q.useCallback(()=>{if(!a)return;let e=Sn.getState().currentSessionId;e&&ri.getState().cancel({sessionId:e,directory:a}),l(a)},[l,a]),he=Q.useCallback(()=>{a&&p(a)},[a,p]),ge=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&E&&a){e.preventDefault(),e.stopPropagation(),G(E.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),me())},[E,G,a,me]);Q.useEffect(()=>{if(!(!a||!E)&&E.mode===`file`&&E.targetPath){_(a,E.targetPath,{allowOutsideRoot:!0});return}},[E,a,_]);let _e=E?.mode===`chat`?E.id:null,ve=Sm(_e?re[hm(a,_e)]:void 0,_e?Lg(E?.dedupeKey):null);Q.useEffect(()=>{if(!D||!a||!ve){Xt(``,null);return}return Xt(a,ve),()=>{Xt(``,null)}},[ve,a,D]),Q.useEffect(()=>{if(!D||!a||!ve||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){an(a,ve,!1);return}Gn(ve),an(a,ve,!0)};e();let t=window.setInterval(e,1e4);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),document.addEventListener(`visibilitychange`,e),()=>{window.clearInterval(t),window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e),document.removeEventListener(`visibilitychange`,e),an(a,ve,!1)}},[ve,a,D]);let ye=Q.useCallback((e,t,n)=>oo(ee.current,e,t,a||null,n,{mode:b,lightThemeId:S,darkThemeId:C,currentTheme:w}),[w,C,a,S,b]);Q.useEffect(()=>{let e=new Set(T.map(e=>e.id));for(let t of ee.current.keys())e.has(t)||ee.current.delete(t)},[T]);let be=Q.useCallback(e=>{!a||E?.mode!==`diff`&&E?.mode!==`file-diff`||d(a,{mode:E.mode,targetPath:E.targetPath,stagedDiff:e===`staged`,diffScope:e})},[E,a,d]),xe=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:b,lightThemeId:S,darkThemeId:C,currentTheme:w};for(let t of V.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__yuriApplyThemeSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`yuri:theme-sync`,payload:e},window.location.origin)}},[w,C,S,b]),Se=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:y};for(let t of V.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__yuriApplyChatSettingsSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`yuri:chat-settings-sync`,payload:e},window.location.origin)}},[y]),Ce=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of V.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:_e===e},i=n.__yuriSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:ao,payload:r},window.location.origin)}},[_e]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(V.current.values()).some(t=>t.contentWindow===e.source))return;let t=e.data;if(t?.type===`yuri:close-embedded-session-chat`){let t=Array.from(V.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&a&&G(t[0]);return}if(t?.type===`yuri:chat-settings-request`){Se();return}if(t?.type===`yuri:embedded-visibility-request`){Ce();return}if(t?.type!==`yuri:cycle-theme-request`)return;let n=[`light`,`dark`,`system`],r=(n.indexOf(b)+1)%n.length;x(n[r])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[G,a,Se,Ce,x,b]),Q.useLayoutEffect(()=>{T.some(e=>e.mode===`chat`)&&(xe(),Se(),Ce())},[C,S,Se,Ce,xe,T,b]);let we=Q.useMemo(()=>T.map(e=>{let n=Fg(e,j,t),r=Gg(n,wg),a=Mg(e.targetPath,i);return{id:e.id,label:r,icon:Ig(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:r})}}),[i,j,t,T]),Te=E?.mode===`btw`?n?(0,$.jsx)(qr,{scope:{sessionId:n,directory:a}}):(0,$.jsx)(`p`,{className:`p-4 text-muted-foreground`,children:t(`chat.btw.sessionRequired`)}):E?.mode===`context`?(0,$.jsx)(em,{}):E?.mode===`preview`?(0,$.jsx)(Xg,{rawUrl:E.targetPath??``,onNavigate:e=>v(i,e)}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(Z,{name:`global`,className:`h-12 w-12 text-muted-foreground/50`}),(0,$.jsx)(`div`,{className:`typography-ui-header text-foreground`,children:t(`contextPanel.preview.title`)}),(0,$.jsx)(`div`,{className:`max-w-sm typography-micro text-muted-foreground`,children:t(`contextPanel.preview.description`)})]}),Ee=Q.useMemo(()=>T.filter(e=>e.mode===`chat`),[T]),De=Q.useMemo(()=>T.filter(e=>e.mode===`browser`),[T]),Oe=Q.useMemo(()=>T.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[T]),ke=eh({isElectron:Zg(),relayActive:o()})?$g:Qg,Ae=D&&E?.mode===`browser`&&ke===$g;Q.useLayoutEffect(()=>{if(!Ae)return;let e=document.documentElement;return e.setAttribute(`data-yuri-native-browser-visible`,``),()=>e.removeAttribute(`data-yuri-native-browser-visible`)},[Ae]);let je=Q.useMemo(()=>T.some(e=>e.mode===`file`),[T]),Me=E?.mode===`file`,[Ne,K]=Q.useState(null),Pe=Me?E.targetPath:Ne?.directory===a&&T.some(e=>e.mode===`file`&&e.targetPath===Ne.path)?Ne.path:null;Q.useEffect(()=>{K(e=>e?.directory===a&&e.path===Pe?e:{directory:a,path:Pe??null})},[a,Pe]);let Fe=Me?E?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(Ee.map(e=>hm(a,e.id)));ce(t=>{let n=!1,r={};for(let e of Ee){let i=Lg(e.dedupeKey);if(!i)continue;let o=hm(a,e.id),s=t[o];r[o]=s??bm({sessionId:i,directory:a}),n||=!s}let i=Dm(t,e);return n||=i!==t,n?{...i,...r}:t});for(let t of Object.keys(ae.tabs))(!e.has(hm(a,t))||ae.tabs[t]?.directory!==a)&&W({type:`close-tab`,tabId:t})},[Ee,ce,a,ae.tabs]);let Ie=_e?hm(a,_e):null,Le=_e?Lg(E?.dedupeKey):null,Re=Ie&&Le?xm(re[Ie],{sessionId:Le,directory:a}):void 0,ze=Re&&Ie?gm(se,Ie,Re.current.directory,Re.current.sessionId):null;Q.useLayoutEffect(()=>{if(oe!==`react-surface`||!D||!_e||!Re||!Ie||!ze){oe===`react-surface`&&W({type:`activate`,viewKey:null,now:Date.now()});return}ce(e=>e[Ie]?e:{...e,[Ie]:Re}),W({type:`touch`,tab:{tabId:_e,sessionId:Re.anchor.sessionId,directory:Re.anchor.directory},view:{tabId:_e,surfaceId:Ie,sessionId:Re.current.sessionId,directory:Re.current.directory,viewKey:ze},now:Date.now()})},[Re,Ie,_e,ze,oe,ce,D]);let Be=Q.useCallback((e,t,n)=>{let r=hm(a,e),i=!1;return ce(e=>{let a=Em(e,r,{sessionId:t,directory:n});return i=a.accepted,a.navigationBySurfaceId}),i},[ce,a]),Ve=Q.useCallback(e=>{let t=hm(a,e);ce(e=>{let n=e[t];if(!n)return e;let r=wm(n);return r===n?e:{...e,[t]:r}})},[ce,a]),He=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(as,{items:we,activeId:E?.id??null,onSelect:e=>{a&&h(a,e)},onClose:e=>{G(e)},onReorder:(e,t)=>{a&&g(a,e,t)},layoutMode:`scrollable`,variant:`default`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5`,children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:he,className:`h-7 w-7 p-0`,title:t(O?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":t(O?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:O?(0,$.jsx)(Z,{name:`fullscreen-exit`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`fullscreen`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:me,className:`h-7 w-7 p-0`,title:t(`contextPanel.actions.closePanel`),"aria-label":t(`contextPanel.actions.closePanel`),children:(0,$.jsx)(Z,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),Ue=D?O?{"--yuri-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--yuri-context-panel-width), 100%)`,minWidth:`min(${xg}px, 100%)`,maxWidth:`100%`,"--yuri-context-panel-width":`${M?R.current??k:k}px`}:{"--yuri-context-panel-width":`${M?R.current??k:k}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:`hidden`,visibility:`hidden`};return(0,$.jsxs)(`aside`,{ref:B,"data-context-panel":`true`,"data-native-browser-visible":Ae?`true`:void 0,tabIndex:-1,inert:!D||void 0,className:J(`flex min-h-0 flex-col overflow-hidden bg-background`,!O&&`yuri-layout-divider-l`,O?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!D&&`pointer-events-none`,M||!D||P?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:ge,style:Ue,children:[!O&&(0,$.jsx)(`div`,{className:J(`absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80`,M&&`bg-[var(--interactive-border)]`),onPointerDown:de,onPointerMove:fe,onPointerUp:pe,onPointerCancel:pe,role:`separator`,"aria-orientation":`vertical`,"aria-label":t(`contextPanel.actions.resizePanelAria`)}),He,Fe===`turn-diff-outside-workspace`?(0,$.jsx)(`div`,{className:`shrink-0 border-b border-status-info/20 bg-status-info/10 px-3 py-2 typography-meta text-status-info`,children:t(`contextPanel.file.notice.turnDiffOutsideWorkspace`)}):null,(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1 overflow-hidden`,M&&`pointer-events-none`),children:[je&&Pe?(0,$.jsx)(`div`,{className:J(`absolute inset-0`,Me?`block`:`hidden`),children:(0,$.jsx)(Ep,{mode:`editor-only`,targetPath:Pe,isActive:D&&Me},`${a}:${Pe??``}`)}):null,oe===`legacy-iframe`&&Ee.map(e=>{let n=Lg(e.dedupeKey);if(!n)return null;let r=ye(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){V.current.delete(e.id);return}V.current.set(e.id,t)},src:r,title:t(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:J(`absolute inset-0 h-full w-full border-0 bg-background`,_e===e.id?`block`:`hidden`),onLoad:()=>{xe(),Se(),Ce()}},e.id):null}),oe===`react-surface`?Object.values(ae.mountedViews).map(e=>{let t=re[hm(a,e.tabId)],n=D&&_e===e.tabId&&ze===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(Ym,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:n,canNavigateBack:n&&!!t?.stack.length,onNavigateSession:(t,n)=>Be(e.tabId,t,n),onNavigateBack:()=>Ve(e.tabId),onEstimateBytes:(e,t)=>W({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,De.map(e=>(0,$.jsx)(`div`,{className:J(`absolute inset-0`,E?.id!==e.id&&`hidden`),children:(0,$.jsx)(ke,{initialUrl:e.targetPath??``,directory:a,tabID:e.id})},e.id)),Oe.map(e=>{let t=e.mode===`diff`&&c?.targetPath===e.targetPath&&c.turnMessageId===e.diffTurnMessageId?c.patches:null;return(0,$.jsx)(`div`,{className:J(`absolute inset-0`,E?.id!==e.id&&`hidden`),children:(0,$.jsx)(Ys,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:a,onDiffScopeChange:be,targetFilePath:e.targetPath,targetLine:e.diffTargetLine??null,toolPatches:t,navigationRequestKey:e.touchedAt,flushContent:!0,singleFileView:e.mode===`file-diff`,preloadFullFiles:e.mode===`file-diff`})},e.id)}),E?.mode!==`chat`&&!Me&&E?.mode!==`browser`&&E?.mode!==`diff`&&E?.mode!==`file-diff`?Te:null]})]})},t_=(e,t,n)=>to(e)?Oa(e,n).map(Ba):t,n_=()=>{let e=(0,pl.c)(69),{t}=Tt(),n=q(r_),r=q(i_),i=q(a_),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=Xa(),e[0]=a):a=e[0];let o=a,s;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=te(),e[1]=s):s=e[1];let c=s,l,u,d,f,p,m,h,g,_;if(e[2]!==n||e[3]!==r||e[4]!==i||e[5]!==t){let a=[{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:`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 + ${o} + 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:`previous_session`,descriptionKey:`helpDialog.item.previousSession`,icon:`arrow-left`,keys:``},{id:`next_session`,descriptionKey:`helpDialog.item.nextSession`,icon:`arrow-right`,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.leaderChords`,items:[{keys:`Ctrl+X → M`,descriptionKey:`helpDialog.item.leaderOpenModel`,icon:`ai-generate-2`},{keys:`Ctrl+X → A`,descriptionKey:`helpDialog.item.leaderOpenAgent`,icon:`ai-agent`},{keys:`Ctrl+X → N`,descriptionKey:`helpDialog.item.leaderNewSession`,icon:`add`},{keys:`Ctrl+X → C`,descriptionKey:`helpDialog.item.leaderCompact`,icon:`scissors`}]},{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:`cycle_right_sidebar_tab`,descriptionKey:`helpDialog.item.cycleRightSidebarTab`,icon:`layout-right`,keys:``},{id:`close_context_panel_tab`,descriptionKey:`helpDialog.item.closeContextPanelTab`,icon:`close`,keys:``},{id:`toggle_terminal`,descriptionKey:`helpDialog.item.toggleTerminal`,icon:`window`,keys:``},{id:`new_terminal_tab`,descriptionKey:`helpDialog.item.newTerminalTab`,icon:`terminal-box`,keys:``},{id:`open_new_terminal`,descriptionKey:`helpDialog.item.openNewTerminal`,icon:`terminal-box`,keys:``},{id:`previous_terminal_tab`,descriptionKey:`helpDialog.item.previousTerminalTab`,icon:`arrow-left`,keys:``},{id:`next_terminal_tab`,descriptionKey:`helpDialog.item.nextTerminalTab`,icon:`arrow-right`,keys:``},{id:`toggle_bottom_panel`,descriptionKey:`helpDialog.item.toggleBottomPanel`,icon:`window`,keys:``},{id:`toggle_terminal_expanded`,descriptionKey:`helpDialog.item.toggleTerminalExpanded`,icon:`window`,keys:``}]},{categoryKey:`helpDialog.section.interface`,items:[{id:`cycle_theme`,descriptionKey:`helpDialog.item.cycleTheme`,icon:`palette`,keys:``},{id:`zoom_in`,descriptionKey:`helpDialog.item.zoomIn`,icon:`add`,keys:``},{id:`zoom_out`,descriptionKey:`helpDialog.item.zoomOut`,icon:`subtract`,keys:``},{id:`zoom_reset`,descriptionKey:`helpDialog.item.zoomReset`,icon:`restart`,keys:``},{keys:[`${o} + 1...9`],descriptionKey:`helpDialog.item.switchSession`,icon:`layout-left`},{id:`toggle_services_menu`,descriptionKey:`helpDialog.item.toggleServicesMenu`,icon:`stack`,keys:``},{id:`open_usage`,descriptionKey:`helpDialog.item.openUsage`,icon:`timer`,keys:``},{id:`cycle_services_tab`,descriptionKey:`helpDialog.item.cycleServicesTab`,icon:`stack`,keys:``},{id:`open_settings`,descriptionKey:`helpDialog.item.openSettings`,icon:`settings-3`,keys:``}]}];u=mr,g=n,_=r,l=dr,m=`max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden`;let s;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Z,{name:`settings-3`,className:`h-5 w-5`}),e[15]=s):s=e[15];let v;e[16]===t?v=e[17]:(v=t(`helpDialog.title`),e[16]=t,e[17]=v);let y;e[18]===v?y=e[19]:(y=(0,$.jsxs)(fr,{className:`flex items-center gap-2`,children:[s,v]}),e[18]=v,e[19]=y);let b;e[20]===t?b=e[21]:(b=t(`helpDialog.description`),e[20]=t,e[21]=b);let x;e[22]===b?x=e[23]:(x=(0,$.jsx)(pr,{children:b}),e[22]=b,e[23]=x),e[24]!==y||e[25]!==x?(h=(0,$.jsxs)(lr,{children:[y,x]}),e[24]=y,e[25]=x,e[26]=h):h=e[26],p=`flex-1 overflow-y-auto mt-3 pr-1`,d=`space-y-4`,f=a.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:t(e.categoryKey)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:e.items.filter(e=>!(c&&e.id===`toggle_prompt_navigator`)).map(e=>{let n=e.id?t_(e.id,Array.isArray(e.keys)?e.keys[0]:e.keys,i):Array.isArray(e.keys)?e.keys:e.keys.split(` / `);return(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1 px-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,$.jsx)(Z,{name:e.icon,className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-meta`,children:t(e.descriptionKey)})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(Array.isArray(n)?n:[n]).map((e,n)=>(0,$.jsxs)(Q.Fragment,{children:[n>0&&(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground mx-1`,children:t(`helpDialog.keyCombiner.or`)}),(0,$.jsx)(di,{shortcut:e})]},`${e}-${n}`))})]},e.id||e.descriptionKey)})})]},e.categoryKey)),e[2]=n,e[3]=r,e[4]=i,e[5]=t,e[6]=l,e[7]=u,e[8]=d,e[9]=f,e[10]=p,e[11]=m,e[12]=h,e[13]=g,e[14]=_}else l=e[6],u=e[7],d=e[8],f=e[9],p=e[10],m=e[11],h=e[12],g=e[13],_=e[14];let v;e[27]!==d||e[28]!==f?(v=(0,$.jsx)(`div`,{className:d,children:f}),e[27]=d,e[28]=f,e[29]=v):v=e[29];let y;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Z,{name:`question`,className:`h-3.5 w-3.5 text-muted-foreground mt-0.5`}),e[30]=y):y=e[30];let b;e[31]===t?b=e[32]:(b=t(`helpDialog.proTips.title`),e[31]=t,e[32]=b);let x;e[33]===b?x=e[34]:(x=(0,$.jsx)(`p`,{className:`font-medium mb-1`,children:b}),e[33]=b,e[34]=x);let S;e[35]!==i||e[36]!==t?(S=t(`helpDialog.proTips.commandPalette`,{shortcut:Ba(Oa(`open_command_palette`,i)[0]??``)}),e[35]=i,e[36]=t,e[37]=S):S=e[37];let C;e[38]===S?C=e[39]:(C=(0,$.jsxs)(`li`,{children:[`• `,S]}),e[38]=S,e[39]=C);let w;e[40]===t?w=e[41]:(w=t(`helpDialog.proTips.recentSessions`),e[40]=t,e[41]=w);let T;e[42]===w?T=e[43]:(T=(0,$.jsxs)(`li`,{children:[`• `,w]}),e[42]=w,e[43]=T);let E;e[44]===t?E=e[45]:(E=t(`helpDialog.proTips.themeCycling`),e[44]=t,e[45]=E);let D;e[46]===E?D=e[47]:(D=(0,$.jsxs)(`li`,{children:[`• `,E]}),e[46]=E,e[47]=D);let O;e[48]!==C||e[49]!==T||e[50]!==D?(O=(0,$.jsxs)(`ul`,{className:`space-y-0.5 typography-meta`,children:[C,T,D]}),e[48]=C,e[49]=T,e[50]=D,e[51]=O):O=e[51];let k;e[52]!==x||e[53]!==O?(k=(0,$.jsx)(`div`,{className:`mt-4 p-2 bg-muted/30 rounded-xl`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[y,(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground`,children:[x,O]})]})}),e[52]=x,e[53]=O,e[54]=k):k=e[54];let A;e[55]!==k||e[56]!==p||e[57]!==v?(A=(0,$.jsxs)(`div`,{className:p,children:[v,k]}),e[55]=k,e[56]=p,e[57]=v,e[58]=A):A=e[58];let j;e[59]!==l||e[60]!==A||e[61]!==m||e[62]!==h?(j=(0,$.jsxs)(l,{className:m,children:[h,A]}),e[59]=l,e[60]=A,e[61]=m,e[62]=h,e[63]=j):j=e[63];let M;return e[64]!==u||e[65]!==j||e[66]!==g||e[67]!==_?(M=(0,$.jsx)(u,{open:g,onOpenChange:_,children:j}),e[64]=u,e[65]=j,e[66]=g,e[67]=_,e[68]=M):M=e[68],M};function r_(e){return e.isHelpDialogOpen}function i_(e){return e.setHelpDialogOpen}function a_(e){return e.shortcutOverrides}var o_=()=>{let e=(0,pl.c)(32),{t}=Tt(),n=q(s_),r=q(c_),i=q(l_),a;e[0]!==i||e[1]!==t?(a=async()=>{if(i){if((await wt(i)).ok){X.success(t(`openCodeStatusDialog.toast.copiedTitle`),{description:t(`openCodeStatusDialog.toast.copiedDescription`)});return}X.error(t(`openCodeStatusDialog.toast.copyFailed`))}},e[0]=i,e[1]=t,e[2]=a):a=e[2];let o=a,s;e[3]===t?s=e[4]:(s=t(`openCodeStatusDialog.title`),e[3]=t,e[4]=s);let c;e[5]===s?c=e[6]:(c=(0,$.jsx)(fr,{children:s}),e[5]=s,e[6]=c);let l;e[7]===t?l=e[8]:(l=t(`openCodeStatusDialog.description`),e[7]=t,e[8]=l);let u;e[9]===l?u=e[10]:(u=(0,$.jsx)(pr,{children:l}),e[9]=l,e[10]=u);let d;e[11]!==c||e[12]!==u?(d=(0,$.jsxs)(lr,{children:[c,u]}),e[11]=c,e[12]=u,e[13]=d):d=e[13];let f;e[14]===t?f=e[15]:(f=t(`openCodeStatusDialog.actions.copy`),e[14]=t,e[15]=f);let p;e[16]!==o||e[17]!==f?(p=(0,$.jsx)(`div`,{className:`flex items-center justify-end`,children:(0,$.jsx)(`button`,{type:`button`,onClick:o,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:f})}),e[16]=o,e[17]=f,e[18]=p):p=e[18];let m;e[19]!==i||e[20]!==t?(m=i||t(`openCodeStatusDialog.empty.noData`),e[19]=i,e[20]=t,e[21]=m):m=e[21];let h;e[22]===m?h=e[23]:(h=(0,$.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap`,children:m}),e[22]=m,e[23]=h);let g;e[24]!==d||e[25]!==p||e[26]!==h?(g=(0,$.jsxs)(dr,{className:`max-w-2xl`,children:[d,p,h]}),e[24]=d,e[25]=p,e[26]=h,e[27]=g):g=e[27];let _;return e[28]!==n||e[29]!==r||e[30]!==g?(_=(0,$.jsx)(mr,{open:n,onOpenChange:r,children:g}),e[28]=n,e[29]=r,e[30]=g,e[31]=_):_=e[31],_};function s_(e){return e.isOpenCodeStatusDialogOpen}function c_(e){return e.setOpenCodeStatusDialogOpen}function l_(e){return e.openCodeStatusText}function u_(){let e=(0,pl.c)(2),t=Lt(),n;return e[0]===t?n=e[1]:(n=t?(0,$.jsx)(Vc,{className:`ml-auto`}):null,e[0]=t,e[1]=n),n}function d_(){let e=(0,pl.c)(2),t=Ft(),n;return e[0]===t?n=e[1]:(n=t?(0,$.jsx)(Vc,{}):null,e[0]=t,e[1]=n),n}var f_=e=>{let t=(0,pl.c)(12),{normalizedProjects:n,ownership:r,isSessionsLoading:i,fullCatalogSessionIds:a,fullCatalogGeneration:o,foldersMap:s,createFolder:c,addSessionToFolder:l,cleanupSessions:u,enabled:d}=e,f=d===void 0||d,p,m;t[0]!==l||t[1]!==u||t[2]!==c||t[3]!==f||t[4]!==s||t[5]!==o||t[6]!==a||t[7]!==i||t[8]!==n||t[9]!==r?(p=()=>{!f||i||n.forEach(e=>{let t=Aa(e.normalizedPath),n=r.archivedSessionsByProject.get(e.id)??[],i=s[t]??[],d=new Map(i.map(p_));n.forEach(n=>{let r=_a(n,e.normalizedPath),i=r.toLowerCase(),a=d.get(i);a||(a=c(t,r),d.set(i,a)),a.sessionIds.includes(n.id)||l(t,a.id,n.id)}),o>0&&u(t,a)})},m=[f,n,r,i,o,a,s,c,l,u],t[0]=l,t[1]=u,t[2]=c,t[3]=f,t[4]=s,t[5]=o,t[6]=a,t[7]=i,t[8]=n,t[9]=r,t[10]=p,t[11]=m):(p=t[10],m=t[11]),Q.useEffect(p,m)};function p_(e){return[e.name.toLowerCase(),e]}var m_=e=>{let t=(0,pl.c)(7),{isSessionsLoading:n,fullCatalogSessionIds:r,fullCatalogGeneration:i,normalizedProjects:a,cleanupSessions:o}=e,s,c;t[0]!==o||t[1]!==i||t[2]!==r||t[3]!==n||t[4]!==a?(s=()=>{if(n||i===0)return;let e=rr.getState().foldersMap;new Set([...Object.keys(e),...a.map(h_)]).forEach(e=>{o(e,r)})},c=[o,i,r,n,a],t[0]=o,t[1]=i,t[2]=r,t[3]=n,t[4]=a,t[5]=s,t[6]=c):(s=t[5],c=t[6]),Q.useEffect(s,c)};function h_(e){return Aa(e.normalizedPath)}var g_=Q.memo(function(e){let t=(0,pl.c)(17),{normalizedProjects:n,ownership:r,enabled:i}=e;Sc();let a=tn(__),o=tn(v_),s=Sn(y_),c=rr(b_),l=rr(x_),u=rr(S_),d=rr(C_),f;t[0]!==d||t[1]!==o||t[2]!==a||t[3]!==s||t[4]!==n?(f={normalizedProjects:n,fullCatalogSessionIds:a,fullCatalogGeneration:o,isSessionsLoading:s,cleanupSessions:d},t[0]=d,t[1]=o,t[2]=a,t[3]=s,t[4]=n,t[5]=f):f=t[5],m_(f);let p;return t[6]!==u||t[7]!==d||t[8]!==l||t[9]!==i||t[10]!==c||t[11]!==o||t[12]!==a||t[13]!==s||t[14]!==n||t[15]!==r?(p={normalizedProjects:n,ownership:r,enabled:i,fullCatalogSessionIds:a,fullCatalogGeneration:o,isSessionsLoading:s,foldersMap:c,createFolder:l,addSessionToFolder:u,cleanupSessions:d},t[6]=u,t[7]=d,t[8]=l,t[9]=i,t[10]=c,t[11]=o,t[12]=a,t[13]=s,t[14]=n,t[15]=r,t[16]=p):p=t[16],f_(p),null});function __(e){return e.fullCatalogSessionIds}function v_(e){return e.fullCatalogGeneration}function y_(e){return e.isLoading}function b_(e){return e.foldersMap}function x_(e){return e.createFolder}function S_(e){return e.addSessionToFolder}function C_(e){return e.cleanupSessions}var w_=new WeakMap,T_=e=>{let{normalizedProjects:t,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:i,projectRepoStatus:a,projectRootBranches:o,lastRepoStatus:s,buildGroupedSessions:c,hasSessionSearchQuery:l,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:d,buildGroupSearchText:f,foldersMap:p}=e,m=Q.useRef([]),h=Q.useMemo(()=>{let e=new Map(m.current.map(e=>[e.project.id,e])),l=t.map(t=>{let l=e.get(t.id),u=Da([...n(t.id),...r(t.id)]),d=i.get(t.normalizedPath)??[],f=a.has(t.id)?!!a.get(t.id):s,p=new Map(l?.groups.map(e=>[e.id,e])),m=c(u,t.normalizedPath,d,o.get(t.id)??null,f).map(e=>tt(p.get(e.id),e));return tt(l,{project:t,groups:m})});return l.length===m.current.length&&l.every((e,t)=>e===m.current[t])?m.current:l},[t,n,r,i,a,s,c,o]);Q.useLayoutEffect(()=>{m.current=h},[h]);let g=Q.useMemo(()=>h,[h]),_=Q.useMemo(()=>{if(!l)return w_;let e=new WeakMap,t=e=>e.reduce((e,n)=>e+1+t(n.children),0);return g.forEach(n=>{n.groups.forEach(n=>{let r=d(n.sessions,u),i=t(r),a=f(n).includes(u),o=I(n.directory??null),s=(o?p[o]??[]:[]).filter(e=>e.name.toLowerCase().includes(u)).length;e.set(n,{filteredNodes:r,matchedSessionCount:i,folderNameMatchCount:s,groupMatches:a,hasMatch:a||i>0||s>0})})}),e},[l,g,d,u,f,p]),v=Q.useMemo(()=>l?g.map(e=>({...e,groups:e.groups.filter(e=>_.get(e)?.hasMatch===!0)})).filter(e=>e.groups.length>0):g,[l,g,_]),y=l?v:g;return{projectSections:h,visibleProjectSections:g,groupSearchDataByGroup:_,searchableProjectSections:v,sectionsForRender:y,searchMatchCount:Q.useMemo(()=>l?y.reduce((e,t)=>e+t.groups.reduce((e,t)=>{let n=_.get(t);if(!n)return e;let r=n.folderNameMatchCount+ +!!n.groupMatches;return e+n.matchedSessionCount+r},0),0):0,[l,y,_])}},E_=e=>{let t=(0,pl.c)(26),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:a,currentSessionId:o,handleSessionSelect:s,newSessionDraftOpen:c,mobileVariant:l,openNewSessionDraft:u,setActiveMainTab:d,setSessionSwitcherOpen:f}=e,p,m;if(t[0]!==n){m=new Map,p=new Map;let e=(t,n,r,i)=>{m.has(t)||m.set(t,new Map);let a=m.get(t);i.forEach(i=>{let o=I(i.worktree?.path??i.session.directory??r??n);a.set(i.session.id,{directory:o}),p.has(t)||p.set(t,{id:i.session.id,directory:o}),i.children.length>0&&e(t,n,o,i.children)})};n.forEach(t=>{t.groups.forEach(n=>{e(t.project.id,t.project.normalizedPath,n.directory,n.sessions)})}),t[0]=n,t[1]=p,t[2]=m}else p=t[1],m=t[2];let h;t[3]!==p||t[4]!==m?(h={metaByProject:m,firstSessionByProject:p},t[3]=p,t[4]=m,t[5]=h):h=t[5];let g=h,_=Q.useRef(null),v,y;t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==s||t[10]!==l||t[11]!==c||t[12]!==u||t[13]!==n||t[14]!==g||t[15]!==d||t[16]!==a||t[17]!==f?(v=()=>{if(!r||c||q.getState().isNewWorktreeDialogOpen||_.current===r)return;let e=n.find(e=>e.project.id===r);if(!e)return;_.current=r;let t=g.metaByProject.get(r);if(o&&t&&t.has(o)){a(e=>{if(e.get(r)===o)return e;let t=new Map(e);return t.set(r,o),t});return}if(o&&t)return;if(!t||t.size===0){d(`chat`),l&&f(!1),u({directoryOverride:e.project.normalizedPath});return}let p=i.get(r),m=p&&t.has(p)?p:null,h=g.firstSessionByProject.get(r)?.id??null,v=m??h;if(!v||v===o)return;let y=t.get(v)?.directory??null;s(v,y,r)},y=[r,i,o,s,c,l,u,n,g,d,f,a],t[6]=r,t[7]=i,t[8]=o,t[9]=s,t[10]=l,t[11]=c,t[12]=u,t[13]=n,t[14]=g,t[15]=d,t[16]=a,t[17]=f,t[18]=v,t[19]=y):(v=t[18],y=t[19]),Q.useLayoutEffect(v,y);let b,x;t[20]!==r||t[21]!==o||t[22]!==g||t[23]!==a?(b=()=>{if(!r||!o)return;let e=g.metaByProject.get(r);!e||!e.has(o)||a(e=>{if(e.get(r)===o)return e;let t=new Map(e);return t.set(r,o),t})},x=[r,o,g,a],t[20]=r,t[21]=o,t[22]=g,t[23]=a,t[24]=b,t[25]=x):(b=t[24],x=t[25]),Q.useEffect(b,x)},D_=e=>{let t=Rt(e=>e.orderByProject);return{getOrderedGroups:Q.useMemo(()=>(n,r)=>{let i=e.get(n),a=t[n];if(!i?.length&&!a?.length)return r;let o=new Map(r.map(e=>[e.id,e])),s=[];if(i?.forEach(e=>{let t=o.get(e);t&&(s.push(t),o.delete(e))}),r.forEach(e=>{o.has(e.id)&&s.push(e)}),!a?.length)return s;let c=new Map(a.map((e,t)=>[I(e),t])),l=s.filter(e=>e.worktree&&!e.isMain);l.sort((e,t)=>(c.get(I(e.directory))??2**53-1)-(c.get(I(t.directory))??2**53-1));let u=0;return s.map(e=>e.worktree&&!e.isMain?l[u++]:e)},[e,t])}},O_=e=>{let{t}=Tt(),n=Q.useCallback(e=>[e.label,e.branch??``,e.description??``,e.directory??``].join(` `).toLowerCase(),[]),r=Q.useCallback(e=>{let n=I(e.directory??null)??``;return`${(e.title||t(`sessions.sidebar.session.untitled`)).trim()} ${n}`.toLowerCase()},[t]),i=Q.useCallback((e,t)=>t?e.flatMap(e=>{if(r(e.session).includes(t))return[e];let n=i(e.children,t);return n.length===0?[]:[{...e,children:n}]}):e,[r]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:i,buildGroupedSessions:Q.useCallback((n,r,i,a,o)=>{let s=I(r??null),c=new Map;i.forEach(e=>{if(e.path){let t=I(e.path)??e.path;c.set(t,e)}});let l=Ac(n,{pinnedSessionIds:e.pinnedSessionIds,omitPinnedSessions:!1,getWorktree:t=>{let n=I(t.directory??null),r=e.worktreeMetadata.get(t.id)??null;if(r)return r;if(n){let e=c.get(n)??null;if(e&&n!==s)return e}return null}}),u=new Map,d=`__archived__`,f=t=>{if(t.time?.archived)return d;if(e.isVSCode)return s??`__project_root__`;let n=I(e.worktreeMetadata.get(t.id)?.path??null)??In(t);return n?n!==s&&c.has(n)?n:n===s?s??`__project_root__`:d:d};l.forEach(e=>{let t=f(e.session);u.has(t)||u.set(t,[]),u.get(t)?.push(e)});let p=s??`__project_root__`,m=[{id:`root`,label:o&&a&&a!==`HEAD`?t(`sessions.sidebar.grouping.projectRootWithBranch`,{branch:a}):t(`sessions.sidebar.grouping.projectRoot`),branch:a??null,description:s?St(s,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:s,folderScopeKey:s,sessions:u.get(p)??[]}],h=new Map;i.forEach(e=>{let t=I(e.path)??e.path,n=u.get(t)??[],r=n.length>0,i=n.reduce((e,t)=>{let n=sn(t.session);return Number.isFinite(n)?Math.max(e,n):e},0);h.set(t,{hasActiveSession:r,lastUpdatedAt:i})});let g=[...i].sort((e,t)=>{let n=I(e.path)??e.path,r=I(t.path)??t.path,i=h.get(n)??{hasActiveSession:!1,lastUpdatedAt:0},a=h.get(r)??{hasActiveSession:!1,lastUpdatedAt:0};if(i.hasActiveSession!==a.hasActiveSession)return i.hasActiveSession?-1:1;if(i.hasActiveSession&&a.hasActiveSession)return a.lastUpdatedAt-i.lastUpdatedAt;let o=(e.label||e.branch||e.name||e.path||``).toLowerCase(),s=(t.label||t.branch||t.name||t.path||``).toLowerCase();return o.localeCompare(s)});(e.isVSCode?[]:g).forEach(t=>{let n=I(t.path)??t.path,r=e.gitBranches.get(n)?.trim()||null,i=t.branch?.trim()||null,a=r&&i&&t.label&&Za(t.label)===Za(i)?r:t.label||t.name||Ot(n,e.homeDirectory)||n;m.push({id:`worktree:${n}`,label:a,branch:r||i,description:St(n,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:t,directory:n,folderScopeKey:n,sessions:u.get(n)??[]})});let _=u.get(d)??[];return m.push({id:`archived`,label:t(`sessions.sidebar.grouping.archived`),branch:null,description:t(`sessions.sidebar.grouping.archivedDescription`),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!e.isVSCode&&s?Aa(s):null,sessions:_}),m},[e.homeDirectory,e.worktreeMetadata,e.pinnedSessionIds,e.gitBranches,e.isVSCode,t])}},k_=e=>{let t=(0,pl.c)(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:i,sessionSearchContainerRef:a}=e,o,s;t[0]!==n||t[1]!==i?(o=()=>{if(!n||typeof window>`u`)return;let e=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(e)},s=[n,i],t[0]=n,t[1]=i,t[2]=o,t[3]=s):(o=t[2],s=t[3]),Q.useEffect(o,s);let c,l;t[4]!==n||t[5]!==a||t[6]!==r?(c=()=>{if(!n||typeof document>`u`)return;let e=e=>{a.current&&(a.current.contains(e.target)||r(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},l=[n,r,a],t[4]=n,t[5]=a,t[6]=r,t[7]=c,t[8]=l):(c=t[7],l=t[8]),Q.useEffect(c,l)},A_=e=>{let t=(0,pl.c)(42),{t:n}=Tt(),[r,i]=Q.useState(null),a=Q.useRef(null),o,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>()=>{a.current&&clearTimeout(a.current)},s=[],t[0]=o,t[1]=s):(o=t[0],s=t[1]),Q.useEffect(o,s);let c;t[2]===e?c=t[3]:(c=(t,n,r)=>{let i=()=>{!e.isSessionSearchOpen&&e.sessionSearchQuery.length===0||(e.setSessionSearchQuery(``),e.setIsSessionSearchOpen(!1))};if(r&&r!==e.activeProjectId&&e.setActiveProjectIdOnly(r),n&&n!==e.currentDirectory&&e.setDirectory(n,{showOverlay:!1}),e.setActiveMainTab(`chat`)){if(e.mobileVariant&&e.setSessionSwitcherOpen(!1),t===e.currentSessionId){e.allowReselect&&e.onSessionSelected?.(t),i();return}e.setCurrentSession(t,n??null),e.onSessionSelected?.(t),i()}},t[2]=e,t[3]=c);let l=c,u;t[4]===e?u=t[5]:(u=(t,n)=>{e.setEditingId(t),e.setEditTitle(n)},t[4]=e,t[5]=u);let d=u,f;t[6]===e?f=t[7]:(f=async t=>{if(!e.editingId)return;let n=(t??e.editTitle).trim();n&&await e.updateSessionTitle(e.editingId,n),e.setEditingId(null),e.setEditTitle(``)},t[6]=e,t[7]=f);let p=f,m;t[8]===e?m=t[9]:(m=()=>{e.setEditingId(null),e.setEditTitle(``)},t[8]=e,t[9]=m);let h=m,g;t[10]!==e||t[11]!==n?(g=async t=>{let r=await e.shareSession(t.id);r&&r.share?.url?X.success(n(`sessions.sidebar.session.share.successTitle`),{description:n(`sessions.sidebar.session.share.successDescription`)}):X.error(n(`sessions.sidebar.session.share.error`))},t[10]=e,t[11]=n,t[12]=g):g=t[12];let _=g,v;t[13]===n?v=t[14]:(v=(e,t)=>{wt(e).then(e=>{if(!e.ok){X.error(n(`sessions.sidebar.session.share.copyUrlError`));return}i(t),a.current&&clearTimeout(a.current),a.current=window.setTimeout(()=>{i(null),a.current=null},2e3)}).catch(()=>{X.error(n(`sessions.sidebar.session.share.copyUrlError`))})},t[13]=n,t[14]=v);let y=v,b;t[15]!==e||t[16]!==n?(b=async t=>{await e.unshareSession(t)?X.success(n(`sessions.sidebar.session.unshare.success`)):X.error(n(`sessions.sidebar.session.unshare.error`))},t[15]=e,t[16]=n,t[17]=b):b=t[17];let x=b,S;t[18]===e.childrenMap?S=t[19]:(S=t=>{let n=[],r=t=>{(e.childrenMap.get(t)??[]).forEach(e=>{n.push(e),r(e.id)})};return r(t),n},t[18]=e.childrenMap,t[19]=S);let C=S,w=M_,T;t[20]!==e||t[21]!==C||t[22]!==n?(T=async(t,r,i)=>{let a=r?.archivedBucket===!0||r?.hardDelete===!0,o=i?.descendantIds??w(C(t.id),a).map(N_);if(o.length===0){if(a){Js({sessionIds:[t.id],message:n(`sessions.sidebar.session.delete.success`),undoLabel:n(`sessions.sidebar.undo`),commitFailedMessage:n(`sessions.sidebar.session.delete.error`)});return}await e.archiveSession(t.id)?Xs({sessionIds:[t.id],message:n(`sessions.sidebar.session.archive.success`),undoLabel:n(`sessions.sidebar.undo`),settingsLabel:n(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:n(`sessions.sidebar.session.archive.undoFailed`)}):X.error(n(`sessions.sidebar.session.archive.error`));return}let s=[t.id,...o];if(a){Js({sessionIds:s,message:s.length===1?n(`sessions.sidebar.bulkActions.deletedSingle`,{count:s.length}):n(`sessions.sidebar.bulkActions.deletedPlural`,{count:s.length}),undoLabel:n(`sessions.sidebar.undo`),commitFailedMessage:n(`sessions.sidebar.session.delete.error`)});return}let{archivedIds:c,failedIds:l}=await e.archiveSessions(s);c.length>0&&Xs({sessionIds:c,message:c.length===1?n(`sessions.sidebar.bulkActions.archivedSingle`,{count:c.length}):n(`sessions.sidebar.bulkActions.archivedPlural`,{count:c.length}),undoLabel:n(`sessions.sidebar.undo`),settingsLabel:n(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:c.length===1?n(`sessions.sidebar.session.archive.undoFailed`):n(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:c.length})}),l.length>0&&X.error(l.length===1?n(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:l.length}):n(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:l.length}))},t[20]=e,t[21]=C,t[22]=n,t[23]=T):T=t[23];let E=T,D;t[24]!==e||t[25]!==C||t[26]!==E?(D=(t,n)=>{let r=n?.archivedBucket===!0||n?.hardDelete===!0,i=w(C(t.id),r).map(P_);if(!r||!e.showDeletionDialog||n?.skipConfirm===!0){E(t,n,{descendantIds:i});return}e.setDeleteSessionConfirm({session:t,descendantCount:i.length,descendantIds:i,archivedBucket:r})},t[24]=e,t[25]=C,t[26]=E,t[27]=D):D=t[27];let O=D,k;t[28]!==e||t[29]!==E?(k=async()=>{if(!e.deleteSessionConfirm)return;let{session:t,archivedBucket:n,descendantIds:r}=e.deleteSessionConfirm;e.setDeleteSessionConfirm(null),await E(t,{archivedBucket:n},{descendantIds:r})},t[28]=e,t[29]=E,t[30]=k):k=t[30];let A=k,j;return t[31]!==A||t[32]!==r||t[33]!==h||t[34]!==y||t[35]!==O||t[36]!==p||t[37]!==d||t[38]!==l||t[39]!==_||t[40]!==x?(j={copiedSessionId:r,handleSessionSelect:l,handleSessionDoubleClick:d,handleSaveEdit:p,handleCancelEdit:h,handleShareSession:_,handleCopyShareUrl:y,handleUnshareSession:x,handleDeleteSession:O,confirmDeleteSession:A},t[31]=A,t[32]=r,t[33]=h,t[34]=y,t[35]=O,t[36]=p,t[37]=d,t[38]=l,t[39]=_,t[40]=x,t[41]=j):j=t[41],j};function j_(e){return!e.time?.archived}function M_(e,t){return t?e:e.filter(j_)}function N_(e){return e.id}function P_(e){return e.id}var F_=[`project:active:`,`project:archived:`,`pinned:active:`,`pinned:archived:`],I_=e=>{let{isVSCode:t,safeStorage:n,keys:r,groupOrderByProject:i,activeSessionByProject:a,collapsedGroups:o,setExpandedParents:s,setCollapsedProjects:c}=e,l=Q.useRef(null),u=Q.useRef(null),[d,f]=Q.useState(!1),p=Q.useCallback(()=>{if(t)return;let e=u.current;if(u.current=null,l.current=null,!e)return;let{projects:n}=jn.getState(),r=n.map(t=>({...t,sidebarCollapsed:e.has(t.id)}));R({projects:r}).catch(()=>{})},[t]),m=Q.useCallback(e=>{typeof window>`u`||t||(u.current=e,l.current!==null&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{p()},700))},[t,p]);return Q.useEffect(()=>()=>{typeof window<`u`&&l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=null},[]),Q.useEffect(()=>{try{let e=n.getItem(r.sessionExpanded);if(e){let t=JSON.parse(e);Array.isArray(t)&&s(new Set(t.filter(e=>typeof e==`string`)))}else{let e=n.getItem(r.sessionExpandedLegacy);if(e){try{let t=JSON.parse(e);if(Array.isArray(t)){let e=new Set;if(t.forEach(t=>{typeof t==`string`&&t.length!==0&&F_.forEach(n=>e.add(`${n}${t}`))}),e.size>0){s(e);try{n.setItem(r.sessionExpanded,JSON.stringify(Array.from(e)))}catch{}}}}catch{}try{n.removeItem?.(r.sessionExpandedLegacy)}catch{}}}let t=n.getItem(r.projectCollapse);if(t){let e=JSON.parse(t);Array.isArray(e)&&c(new Set(e.filter(e=>typeof e==`string`)))}}catch{}finally{f(!0)}},[r.projectCollapse,r.sessionExpanded,r.sessionExpandedLegacy,n,c,s]),Q.useEffect(()=>{try{let e=Object.fromEntries(i.entries());n.setItem(r.groupOrder,JSON.stringify(e))}catch{}},[i,r.groupOrder,n]),Q.useEffect(()=>{try{let e=Object.fromEntries(a.entries());n.setItem(r.projectActiveSession,JSON.stringify(e))}catch{}},[a,r.projectActiveSession,n]),Q.useEffect(()=>{try{n.setItem(r.groupCollapse,JSON.stringify(Array.from(o)))}catch{}},[o,r.groupCollapse,n]),{scheduleCollapsedProjectsPersist:m,hasRestoredProjectCollapse:d}},L_=async(e,t,n)=>{if(e.length===0)return[];let r=Math.max(1,Math.min(t,e.length)),i=Array(e.length),a=0,o=async()=>{for(;;){let t=a;if(a+=1,t>=e.length)return;i[t]=await n(e[t])}};return await Promise.all(Array.from({length:r},()=>o())),i},R_=e=>{let{normalizedProjects:t,activeProjectId:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a,enabled:o=!0}=e,{git:s}=at(),c=ko(e=>e.ensureStatus),l=Q.useMemo(()=>o?t.filter(e=>e.id===n):[],[n,o,t]);Q.useEffect(()=>{if(!o||!s||l.length===0){if(!o)return;i(e=>e.size===0?e:new Map);return}l.forEach(e=>{c(e.normalizedPath,s)})},[l,o,s,c,i]),Q.useEffect(()=>{let e=new Map;l.forEach(t=>{e.set(t.id,r.get(t.normalizedPath)?.isGitRepo??null)}),i(t=>t.size===e.size&&[...e].every(([e,n])=>t.has(e)&&t.get(e)===n)?t:e)},[l,r,i]);let u=Q.useMemo(()=>l.map(e=>{let t=r.get(e.normalizedPath)?.branch??``;return`${e.id}:${t}`}).join(`|`),[l,r]),d=Q.useRef(new Map),f=Q.useRef(new Map);Q.useEffect(()=>{let e=!1,t=setTimeout(()=>{(async()=>{let t=new Set(l.map(e=>e.id));for(let e of d.current.keys())t.has(e)||(d.current.delete(e),f.current.delete(e));let n=Date.now(),i=l.filter(e=>{let t=r.get(e.normalizedPath);if(t?.isGitRepo===!1)return d.current.delete(e.id),f.current.delete(e.id),!1;if(t?.isGitRepo!==!0||t.branch===null)return!1;let i=t.branch.trim(),a=`${e.normalizedPath}\0${i}`,o=d.current.get(e.id);if(o===a){let t=f.current.get(e.id);return t&&(t.at=n),!1}return!(o!==void 0&&n-(f.current.get(e.id)?.at??0)<3e5)});if(i.length===0)return;let o=await L_(i,2,async e=>{let t=r.get(e.normalizedPath)?.branch?.trim()??``,n=`${e.normalizedPath}\0${t}`,i=await ea(e.normalizedPath,t?{knownBranch:t}:void 0).catch(()=>null);return{id:e.id,inputKey:n,branch:i}});if(e)return;let s=o.filter(e=>e.branch);if(s.length===0)return;let c=Date.now();a(e=>{let t=e;return s.forEach(({id:n,branch:r})=>{r&&e.get(n)!==r&&(t===e&&(t=new Map(e)),t.set(n,r))}),t}),s.forEach(({id:e,inputKey:t,branch:n})=>{d.current.set(e,t),n&&f.current.set(e,{branch:n,at:c})})})()},150);return()=>{e=!0,clearTimeout(t)}},[l,u,r,a])},z_=e=>{let t=(0,pl.c)(7),{ownership:n}=e,r;t[0]===n?r=t[1]:(r=e=>n.sessionsByProject.get(e)??[],t[0]=n,t[1]=r);let i=r,a;t[2]===n?a=t[3]:(a=e=>n.archivedSessionsByProject.get(e)??[],t[2]=n,t[3]=a);let o=a,s;return t[4]!==o||t[5]!==i?(s={getSessionsForProject:i,getArchivedSessionsForProject:o},t[4]=o,t[5]=i,t[6]=s):s=t[6],s},B_=e=>{let t=(0,pl.c)(10),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:i,enabled:a}=e,o=a===void 0||a,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=new Set,t[0]=s):s=t[0];let[c,l]=Q.useState(s),u;t[1]!==o||t[2]!==n||t[3]!==i?(u=()=>{if(!o||!n){l(V_);return}let e=new IntersectionObserver(e=>{e.forEach(e=>{let t=e.target.dataset.projectId;t&&l(n=>{let r=new Set(n);return e.isIntersecting?r.delete(t):r.add(t),r})})},{threshold:0});return i.current.forEach(t=>{t&&e.observe(t)}),()=>e.disconnect()},t[1]=o,t[2]=n,t[3]=i,t[4]=u):u=t[4];let d;return t[5]!==o||t[6]!==n||t[7]!==i||t[8]!==r?(d=[o,n,i,r],t[5]=o,t[6]=n,t[7]=i,t[8]=r,t[9]=d):d=t[9],Q.useEffect(u,d),c};function V_(e){return e.size===0?e:new Set}var H_=9e4,U_=15e3,W_=3e5,G_=[2e3,5e3],K_=6e4,q_=12e4,J_=3e5,Y_=4,X_=432e5,Z_=`yuri.github-pr-status`,Q_=e=>e===`closed`||e===`merged`,$_=e=>{let t=e?.checks;return t?t.state===`pending`||t.pending>0:!1},ev=(e,t,n)=>`${e}::${t}`,tv=new Map,nv=new Map,rv=new Set,iv=new Map,av=2,ov=0,sv=[],cv=()=>ov<av?(ov+=1,Promise.resolve()):new Promise(e=>{sv.push(e)}),lv=()=>{let e=sv.shift();if(e){e();return}ov=Math.max(0,ov-1)},uv=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),dv=e=>e?.params?.directory&&e.params.branch?{directory:e.params.directory,branch:e.params.branch,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null}:!e?.identity?.directory||!e.identity.branch?null:e.identity,fv=e=>{let t=dv(e);return!t?.directory||!t.branch?null:`${t.directory}::${t.branch}`},pv=(e,t)=>Object.entries(e).filter(([,e])=>fv(e)===t).map(([e])=>e),mv=(e,t)=>{let n=t.remoteName??e.params?.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null;return{...e,params:e.params?{...e.params,...t,remoteName:n}:{...t,remoteName:n},identity:{directory:t.directory,branch:t.branch,remoteName:n}}},hv=e=>!e?.params?.canShow||!e.params.github?.prStatus?null:{...e.params,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null},gv=(e,t,n)=>{let r=pv(e,t),i=r.map(t=>hv(e[t])).filter(e=>!!e);if(i.length===0)return null;let a=hv(e[n]);if(a&&fv(e[n])===t)return a;let o=r.map(t=>e[t]).find(e=>!!(e?.resolvedRemoteName&&hv(e)));return o?hv(o):i.find(e=>!!e.remoteName)||(i[0]??null)},_v=e=>({status:e.status,isInitialStatusResolved:e.isInitialStatusResolved,lastRefreshAt:e.lastRefreshAt,lastDiscoveryPollAt:e.lastDiscoveryPollAt,identity:dv(e),resolvedRemoteName:e.resolvedRemoteName??e.status?.resolvedRemoteName??null}),vv=e=>({...uv(),status:e?.status??null,isInitialStatusResolved:e?.isInitialStatusResolved??!1,lastRefreshAt:e?.lastRefreshAt??0,lastDiscoveryPollAt:e?.lastDiscoveryPollAt??0,identity:e?.identity??null,resolvedRemoteName:e?.resolvedRemoteName??e?.status?.resolvedRemoteName??null}),yv=G()(le((e,t)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:t=>{e(e=>e.entries[t]?e:{entries:{...e.entries,[t]:uv()}})},setParams:(t,n)=>{e(e=>{let r=e.entries[t]??uv();return{entries:{...e.entries,[t]:mv(r,n)}}})},startWatching:n=>{if(e(e=>{let t=e.entries[n]??uv();return{entries:{...e.entries,[n]:{...t,watchers:t.watchers+1}}}}),tv.has(n))return;let r=e=>{let r=window.setTimeout(()=>{if(typeof document<`u`&&document.visibilityState!==`visible`)return;let e=t().entries[n];!e||e.watchers<=0||e.status?.pr||t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},e),i=nv.get(n)??[];i.push(r),nv.set(n,i)};t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),G_.forEach(e=>r(e));let i=window.setInterval(()=>{if(typeof document<`u`&&document.visibilityState!==`visible`)return;let r=t().entries[n];if(!(!r||r.watchers<=0)){if(!r.status?.pr){let i=Date.now();if(i-r.lastDiscoveryPollAt<W_)return;e(e=>{let t=e.entries[n];return t?{entries:{...e.entries,[n]:{...t,lastDiscoveryPollAt:i}}}:e}),t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}Q_(r.status?.pr?.state)||Date.now()-r.lastRefreshAt<($_(r.status)?K_:r.status?.checks&&r.status.checks.state!==`pending`?J_:q_)||t().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})}},U_);tv.set(n,i)},stopWatching:n=>{e(e=>{let t=e.entries[n];if(!t)return e;let r=Math.max(0,t.watchers-1);return{entries:{...e.entries,[n]:{...t,watchers:r}}}});let r=t().entries[n];if(r&&r.watchers>0)return;let i=tv.get(n);typeof i==`number`&&window.clearInterval(i),tv.delete(n);let a=nv.get(n);a&&a.length>0&&a.forEach(e=>{window.clearTimeout(e)}),nv.delete(n)},refresh:async(n,r)=>{let i=t(),a=i.entries[n],o=fv(a);if(!a||!o)return;let s=pv(i.entries,o),c=s.some(e=>!!i.entries[e]?.status?.pr);if(r?.onlyExistingPr&&!c)return;let l=iv.get(o)??0;if(!r?.force&&Date.now()-l<H_||rv.has(o))return;let u=gv(i.entries,o,n);if(u){if(rv.add(o),iv.set(o,Date.now()),e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,lastRefreshAt:Date.now(),isLoading:!r?.silent||n.isLoading,error:null})}),{entries:t}}),u.githubAuthChecked&&u.githubConnected===!1){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:{connected:!1},error:null,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),rv.delete(o);return}if(!u.github?.prStatus){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:null,error:`GitHub runtime API unavailable`,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),rv.delete(o);return}try{e(e=>({...e,activeRequestCount:e.activeRequestCount+1,totalRequestCount:e.totalRequestCount+1})),await cv();let t;try{t=await u.github.prStatus(u.directory,u.branch,u.remoteName??void 0,{force:r?.force})}finally{lv()}e(e=>{let n={...e.entries};return s.forEach(e=>{let i=n[e];if(!i)return;let a=i.status?.pr,o=t.pr,s=o&&a&&o.number===a.number&&(!o.body||!o.body.trim())&&typeof a.body==`string`&&a.body.trim().length>0&&o&&a?.body?{...t,pr:{...o,body:a.body}}:t,c=s.resolvedRemoteName??i.resolvedRemoteName??u.remoteName??null,l=dv(i)??{directory:u.directory,branch:u.branch,remoteName:u.remoteName??null};n[e]={...i,status:s,error:null,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved,resolvedRemoteName:c,identity:{...l,remoteName:c??l.remoteName??null}}}),{entries:n}})}catch(t){let n=t instanceof Error?t.message:String(t);e(e=>{let t={...e.entries};return s.forEach(e=>{let i=t[e];i&&(t[e]={...i,error:n||`Failed to load PR status`,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved})}),{entries:t}})}finally{rv.delete(o),e(e=>({...e,activeRequestCount:Math.max(0,e.activeRequestCount-1)}))}}},refreshTargets:async(e,n)=>{await L_(Array.from(new Set(e.map(e=>{let t=e.directory.trim(),n=e.branch.trim();return!t||!n?null:ev(t,n,e.remoteName??null)}).filter(e=>!!e))),Y_,e=>t().refresh(e,n))},updateStatus:(t,n)=>{e(e=>{let r=e.entries[t]??uv();return{entries:{...e.entries,[t]:{...r,status:n(r.status)}}}})}}),{name:Z_,storage:Xe(),partialize:e=>({entries:Object.fromEntries(Object.entries(e.entries).filter(([,e])=>{let t=dv(e);if(!t?.directory||!t.branch)return!1;let n=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return n===0||Date.now()-n<X_}).map(([e,t])=>[e,_v(t)]))}),merge:(e,t)=>{let n=e?.entries??{};return{...t,entries:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,vv(t)]))}}})),bv=e=>{let t=e?.pr;if(!t)return null;if(t.state===`merged`)return`merged`;if(t.state===`closed`)return`closed`;if(t.draft)return`draft`;let n=e?.checks?.state===`failure`,r=typeof t.mergeableState==`string`?t.mergeableState:``,i=t.mergeable===!1||r===`blocked`||r===`dirty`;return n||i?`blocked`:`open`},xv=e=>{let t=bv(e.status??null),n=e.status?.pr;return!t||!n?.number?null:{number:n.number,visualState:t,prState:n.state,draft:!!n.draft,title:typeof n.title==`string`&&n.title.trim().length>0?n.title:null,url:typeof n.url==`string`&&n.url.trim().length>0?n.url:null,base:typeof n.base==`string`&&n.base.trim().length>0?n.base:null,head:typeof n.head==`string`&&n.head.trim().length>0?n.head:null,checks:e.status?.checks?{state:e.status.checks.state,total:e.status.checks.total,success:e.status.checks.success,failure:e.status.checks.failure,pending:e.status.checks.pending}:null,canMerge:typeof e.status?.canMerge==`boolean`?e.status.canMerge:null,mergeableState:typeof n.mergeableState==`string`?n.mergeableState:null,repo:e.status?.repo?{owner:e.status.repo.owner,repo:e.status.repo.repo}:null}},Sv=e=>`${e.number}:${e.visualState}:${e.prState}:${e.draft}:${e.title??``}:${e.url??``}:${e.base??``}:${e.head??``}:${e.canMerge??``}:${e.mergeableState??``}:${e.checks?.state??``}:${e.checks?.total??``}:${e.checks?.success??``}:${e.checks?.failure??``}:${e.checks?.pending??``}:${e.repo?.owner??``}:${e.repo?.repo??``}`,Cv=new Map,wv=new Map,Tv=e=>{let t=(0,pl.c)(2),n;return t[0]===e?n=t[1]:(n=t=>{let n=new Map,r=new Map;for(let i of e){let e=t.entries[i];if(!e)continue;let a=xv(e);if(!a)continue;let o=Sv(a);n.set(i,o),r.set(i,a)}if(n.size===Cv.size){let e=!0;for(let[t,r]of n)if(Cv.get(t)!==r){e=!1;break}if(e)return wv}return Cv=n,wv=r,r},t[0]=e,t[1]=n),yv(n)},Ev=e=>{let t=(0,pl.c)(10),{open:n,onOpenChange:r,project:i,onSave:a}=e,o;t[0]!==a||t[1]!==n||t[2]!==i?(o=n&&i?(0,$.jsx)(Is,{project:i,onIdentitySave:a}):null,t[0]=a,t[1]=n,t[2]=i,t[3]=o):o=t[3];let s;t[4]===o?s=t[5]:(s=(0,$.jsx)(dr,{className:`w-full max-w-2xl gap-0 overflow-hidden p-0`,children:(0,$.jsx)(mo,{outerClassName:`max-h-[min(90vh,48rem)]`,className:`w-full bg-background`,children:(0,$.jsx)(`div`,{className:`w-full p-3 sm:p-6 sm:pt-8`,children:o})})}),t[4]=o,t[5]=s);let c;return t[6]!==r||t[7]!==n||t[8]!==s?(c=(0,$.jsx)(mr,{open:n,onOpenChange:r,children:s}),t[6]=r,t[7]=n,t[8]=s,t[9]=c):c=t[9],c},Dv=Q.memo(e=>{let t=(0,pl.c)(96),{folder:n,sessions:r,subFolderItems:i,isCollapsed:a,onToggle:o,onRename:s,onDelete:c,renderSessionNode:l,getRenderExtras:u,groupDirectory:d,projectId:f,mobileVariant:p,alwaysShowActions:m,isRenaming:h,renameDraft:g,onRenameDraftChange:_,onRenameSave:v,onRenameCancel:y,droppableRef:b,isDropTarget:x,onNewSession:S,onNewSubFolder:C,depth:w,hideActions:T,archivedBucket:E,sessionSecondaryMeta:D}=e,O=m===void 0?p!==void 0&&p:m,k=h!==void 0&&h,A=g===void 0?``:g,j=x!==void 0&&x,M=w===void 0?0:w,N=T!==void 0&&T,P=E!==void 0&&E,F=D===void 0?null:D,{t:I}=Tt(),[L,R]=Q.useState(!1),[z,B]=Q.useState(``),V=Q.useRef(null),ee=k||L,H=k?A:z,te;t[0]===n.name?te=t[1]:(te=()=>{B(n.name),R(!0)},t[0]=n.name,t[1]=te);let ne=te,re;t[2]!==H||t[3]!==n.name||t[4]!==k||t[5]!==s||t[6]!==v?(re=()=>{let e=H.trim();e&&e!==n.name&&s(e),k&&v&&v(),R(!1),B(``)},t[2]=H,t[3]=n.name,t[4]=k,t[5]=s,t[6]=v,t[7]=re):re=t[7];let U=re,ie;t[8]!==k||t[9]!==y?(ie=()=>{k&&y&&y(),R(!1),B(``)},t[8]=k,t[9]=y,t[10]=ie):ie=t[10];let ae=ie,W;t[11]!==k||t[12]!==_?(W=e=>{if(k&&_){_(e);return}B(e)},t[11]=k,t[12]=_,t[13]=W):W=t[13];let oe=W,se,ce;t[14]===k?(se=t[15],ce=t[16]):(se=()=>{if(!k)return;let e=()=>{let e=V.current;e&&(e.focus(),e.select())},t=requestAnimationFrame(e),n=window.setTimeout(e,0);return()=>{cancelAnimationFrame(t),window.clearTimeout(n)}},ce=[k],t[14]=k,t[15]=se,t[16]=ce),Q.useEffect(se,ce);let G;t[17]===M?G=t[18]:(G=$a(M),t[17]=M,t[18]=G);let le=G,ue=!a,de;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(de=J(`yuri-folder`),t[19]=de):de=t[19];let fe=j&&`bg-primary/10 ring-1 ring-inset ring-primary/30`,pe;t[20]===fe?pe=t[21]:(pe=J(`group/folder relative my-0.5 flex items-center justify-between gap-1.5 py-1.5 pr-2 min-w-0 rounded-lg`,`cursor-pointer`,Fa,fe),t[20]=fe,t[21]=pe);let me;t[22]===le?me=t[23]:(me={paddingLeft:le},t[22]=le,t[23]=me);let he=ee?void 0:o,ge=ee?void 0:`button`,_e=ee?void 0:0,ve;t[24]!==o||t[25]!==ee?(ve=ee?void 0:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},t[24]=o,t[25]=ee,t[26]=ve):ve=t[26];let ye;t[27]!==n.name||t[28]!==a||t[29]!==I?(ye=I(a?`sessions.sidebar.folderItem.expandAria`:`sessions.sidebar.folderItem.collapseAria`,{folderName:n.name}),t[27]=n.name,t[28]=a,t[29]=I,t[30]=ye):ye=t[30];let be=P?O?`pr-7`:`group-hover/folder:pr-7 group-focus-within/folder:pr-7`:``,xe;t[31]===be?xe=t[32]:(xe=J(`min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]`,be),t[31]=be,t[32]=xe);let Se=j?`text-primary`:`text-muted-foreground`,Ce;t[33]===Se?Ce=t[34]:(Ce=J(`h-4 w-4 flex-shrink-0`,Se),t[33]=Se,t[34]=Ce);let we;t[35]===Ce?we=t[36]:(we=(0,$.jsx)(Z,{name:`folder-open`,className:Ce}),t[35]=Ce,t[36]=we);let Te;t[37]!==H||t[38]!==n.name||t[39]!==ae||t[40]!==oe||t[41]!==U||t[42]!==a||t[43]!==j||t[44]!==ee||t[45]!==r.length||t[46]!==I?(Te=ee?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-1 items-center gap-1`,onPointerDown:Ov,onMouseDown:kv,onSubmit:e=>{e.preventDefault(),U()},children:[(0,$.jsx)(`input`,{ref:V,value:H,onChange:e=>oe(e.target.value),className:`flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground`,autoFocus:!0,placeholder:I(`sessions.sidebar.folderItem.namePlaceholder`),onClick:Av,onPointerDown:jv,onMouseDown:Mv,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),ae();return}(e.key===` `||e.key===`Enter`)&&e.stopPropagation()}}),(0,$.jsx)(`button`,{type:`submit`,className:`shrink-0 text-muted-foreground hover:text-foreground`,onClick:Nv,onPointerDown:Pv,onMouseDown:Fv,children:(0,$.jsx)(Z,{name:`check`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ae()},onPointerDown:Iv,onMouseDown:Lv,className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`min-w-0 flex items-center gap-1.5 flex-1`,children:[(0,$.jsx)(`span`,{className:J(`typography-ui-label font-semibold truncate`,j?`text-primary`:`text-muted-foreground`),children:n.name}),(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground/70 flex-shrink-0`,children:[`• `,r.length]}),a?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`})]}),t[37]=H,t[38]=n.name,t[39]=ae,t[40]=oe,t[41]=U,t[42]=a,t[43]=j,t[44]=ee,t[45]=r.length,t[46]=I,t[47]=Te):Te=t[47];let Ee;t[48]!==xe||t[49]!==we||t[50]!==Te?(Ee=(0,$.jsxs)(`div`,{className:xe,children:[we,Te]}),t[48]=xe,t[49]=we,t[50]=Te,t[51]=Ee):Ee=t[51];let De;t[52]!==O||t[53]!==P||t[54]!==M||t[55]!==n.name||t[56]!==ne||t[57]!==N||t[58]!==c||t[59]!==S||t[60]!==C||t[61]!==ee||t[62]!==I?(De=!ee&&(!N||P)?(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 px-0.5`,children:(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 transition-opacity`,O?`opacity-100`:`opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100`,P&&`absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0`),children:[!P&&S?(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},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":I(`sessions.sidebar.folderItem.newSessionAria`,{folderName:n.name}),title:I(`sessions.sidebar.project.actions.newSession`),children:(0,$.jsx)(Z,{name:`add`,className:`h-3.5 w-3.5`})}):null,!P&&C&&M===0?(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),C()},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":I(`sessions.sidebar.folderItem.newSubfolderAria`,{folderName:n.name}),title:I(`sessions.sidebar.folderItem.newSubfolder`),children:(0,$.jsx)(Z,{name:`folder-add`,className:`h-3.5 w-3.5`})}):null,P?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne()},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":I(`sessions.sidebar.folderItem.renameAria`,{folderName:n.name}),children:(0,$.jsx)(Z,{name:`pencil-ai`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},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":I(P?`sessions.sidebar.folderItem.deleteArchivedInFolderAria`:`sessions.sidebar.folderItem.deleteFolderAria`,{folderName:n.name}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-3.5 w-3.5`})})]})}):null,t[52]=O,t[53]=P,t[54]=M,t[55]=n.name,t[56]=ne,t[57]=N,t[58]=c,t[59]=S,t[60]=C,t[61]=ee,t[62]=I,t[63]=De):De=t[63];let Oe;t[64]!==b||t[65]!==pe||t[66]!==me||t[67]!==he||t[68]!==ge||t[69]!==_e||t[70]!==ve||t[71]!==ye||t[72]!==Ee||t[73]!==De?(Oe=(0,$.jsxs)(`div`,{ref:b,className:pe,style:me,onClick:he,role:ge,tabIndex:_e,onKeyDown:ve,"aria-label":ye,children:[Ee,De]}),t[64]=b,t[65]=pe,t[66]=me,t[67]=he,t[68]=ge,t[69]=_e,t[70]=ve,t[71]=ye,t[72]=Ee,t[73]=De,t[74]=Oe):Oe=t[74];let ke=a||void 0,Ae;t[75]!==P||t[76]!==M||t[77]!==u||t[78]!==d||t[79]!==f||t[80]!==l||t[81]!==F||t[82]!==r||t[83]!==i||t[84]!==I?(Ae=r.length>0?r.map(e=>l(e,M+1,d??null,f??null,P,F,`project`,u?.(e))):i?null:(0,$.jsx)(`div`,{className:`py-1.5 pr-2 text-left typography-micro text-muted-foreground/70`,style:{paddingLeft:$a(M+1)},children:I(`sessions.sidebar.folderItem.emptyFolder`)}),t[75]=P,t[76]=M,t[77]=u,t[78]=d,t[79]=f,t[80]=l,t[81]=F,t[82]=r,t[83]=i,t[84]=I,t[85]=Ae):Ae=t[85];let je;t[86]!==i||t[87]!==Ae?(je=(0,$.jsxs)(`div`,{className:`pb-1`,children:[i,Ae]}),t[86]=i,t[87]=Ae,t[88]=je):je=t[88];let Me;t[89]!==ke||t[90]!==je?(Me=(0,$.jsx)(Jc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ke,children:je}),t[89]=ke,t[90]=je,t[91]=Me):Me=t[91];let Ne;return t[92]!==ue||t[93]!==Oe||t[94]!==Me?(Ne=(0,$.jsxs)(Xc,{open:ue,className:de,children:[Oe,Me]}),t[92]=ue,t[93]=Oe,t[94]=Me,t[95]=Ne):Ne=t[95],Ne});function Ov(e){return e.stopPropagation()}function kv(e){return e.stopPropagation()}function Av(e){return e.stopPropagation()}function jv(e){return e.stopPropagation()}function Mv(e){return e.stopPropagation()}function Nv(e){return e.stopPropagation()}function Pv(e){return e.stopPropagation()}function Fv(e){return e.stopPropagation()}function Iv(e){return e.stopPropagation()}function Lv(e){return e.stopPropagation()}var Rv=3e4,zv=e=>{let t=e,n=t.metadata?.yuri?.titleRefresh,r=sn(e)||0;return[e.title??``,e.share?e.share.url??`1`:``,t.hasChildren?`1`:``,t.parentID??``,t.metadata?.yuri?.assistant?`1`:``,n?.isGenerating?`1`:``,String(n?.lastError??``),String(n?.failedAt??``),Math.floor(r/Rv)].join(`\0`)},Bv=(e,t,n)=>{if(!t)return;let r=e=>{let i=e.session.id===t;for(let t of e.children)i=r(t)||i;return i&&n.add(e.session.id),i};for(let t of e)r(t)},Vv=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(let n of e.children)if(Vv(n,t))return!0;return!1},Hv=e=>e.children.length===0?``:e.children.map(e=>e.children.length===0?e.session.id:`${e.session.id}:${Hv(e)}`).join(`|`),Uv=(e,t,n,r)=>{if(!t)return null;let i=r?`archived`:`active`,a=null,o=e=>{if(`${n}:${i}:${e.session.id}`===t)return a=e.session.id,!0;for(let t of e.children)if(o(t))return!0;return!1};return e.forEach(e=>o(e)),a},Wv=50,Gv=30,Kv=28,qv=[],Jv=(e,t)=>t?e.sessions.some(e=>Vv(e,t)):!1,Yv=(e,t,n)=>{let r=e=>{let i=e.session.id;return t.has(i)!==n.has(i)||e.children.some(r)};return e.sessions.some(r)},Xv=(e,t,n)=>{let r=e=>{let i=e.session.id;return t.has(i)!==n.has(i)||e.children.some(r)};return e.sessions.some(r)},Zv=(e,t,n)=>{let r=i=>{let a=i.session.id,o=e.folderScopeKey??I(e.directory??null);return(o?t[o]?.indexOf(a):-1)!==(o?n[o]?.indexOf(a):-1)||i.children.some(r)};return e.sessions.some(r)},Qv=(e,t,n)=>{let r=e.folderScopeKey??I(e.directory??null);return!!(r&&t[r]!==n[r])},$v=(e,t,n)=>{let r=e.isArchivedBucket?`archived`:`active`,i=e=>{let a=`project:${r}:${e.session.id}`;return t.has(a)!==n.has(a)||e.children.some(i)};return e.sessions.some(i)},ey=(e,t,n)=>{let r=e=>{let i=e.session.id,a=t.get(i)??e.session,o=n.get(i)??e.session;return a!==o&&zv(a)!==zv(o)||e.children.some(r)};return e.sessions.some(r)},ty=e=>{if(e.projectId)return e.projectRepoStatus.has(e.projectId)?e.projectRepoStatus.get(e.projectId):void 0},ny=e=>{let t=new WeakMap,n=e=>{t.set(e,Hv(e));for(let t of e.children)n(t)};return e.forEach(n),t},ry=e=>{let t=[],n=e=>{e.forEach(e=>{t.push(e.session),e.children.length>0&&n(e.children)})};return n(e),t},iy=(e,t)=>{if(e.group!==t.group||e.groupKey!==t.groupKey||e.isArchivedLoading!==t.isArchivedLoading||e.projectId!==t.projectId||e.hideGroupLabel!==t.hideGroupLabel||e.compactBodyPadding!==t.compactBodyPadding||e.groupSearchDataByGroup.get(e.group)!==t.groupSearchDataByGroup.get(t.group)||e.visibleSessionCount!==t.visibleSessionCount||e.collapsedGroups!==t.collapsedGroups&&e.collapsedGroups.has(e.groupKey)!==t.collapsedGroups.has(t.groupKey)||e.projectRepoStatus!==t.projectRepoStatus&&ty(e)!==ty(t)||e.pinnedSessionIds!==t.pinnedSessionIds&&Yv(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&$v(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderByScope!==t.sessionOrderByScope&&Zv(t.group,e.sessionOrderByScope,t.sessionOrderByScope)||e.sessionOrderActivityByScope!==t.sessionOrderActivityByScope&&Qv(t.group,e.sessionOrderActivityByScope,t.sessionOrderActivityByScope)||e.currentSessionId!==t.currentSessionId&&(Jv(e.group,e.currentSessionId)||Jv(t.group,t.currentSessionId))||e.editingId!==t.editingId&&(Jv(e.group,e.editingId)||Jv(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Jv(e.group,e.editingId)||Jv(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Uv(e.group.sessions,e.openSidebarMenuKey,`project`,!!e.group.isArchivedBucket),r=Uv(t.group.sessions,t.openSidebarMenuKey,`project`,!!t.group.isArchivedBucket);if(n||r)return!1}if(e.liveSessionById!==t.liveSessionById&&ey(t.group,e.liveSessionById,t.liveSessionById)||e.alwaysVisibleSessionIds!==t.alwaysVisibleSessionIds&&Xv(t.group,e.alwaysVisibleSessionIds,t.alwaysVisibleSessionIds))return!1;if(e.prVisualStateByDirectoryBranch!==t.prVisualStateByDirectoryBranch){let n=e.group?.directory&&e.group?.branch?e.prVisualStateByDirectoryBranch.get(`${e.group.directory}::${e.group.branch.trim()}`):void 0,r=t.group?.directory&&t.group?.branch?t.prVisualStateByDirectoryBranch.get(`${t.group.directory}::${t.group.branch.trim()}`):void 0;if(!Object.is(n,r))return!1}return e.hasSessionSearchQuery===t.hasSessionSearchQuery&&e.normalizedSessionSearchQuery===t.normalizedSessionSearchQuery&&e.collapsedFolderIds===t.collapsedFolderIds&&e.toggleFolderCollapse===t.toggleFolderCollapse&&e.renameFolder===t.renameFolder&&e.deleteFolder===t.deleteFolder&&e.showDeletionDialog===t.showDeletionDialog&&e.setDeleteFolderConfirm===t.setDeleteFolderConfirm&&e.renderSessionNode===t.renderSessionNode&&e.lastRepoStatus===t.lastRepoStatus&&e.showMoreGroupSessions===t.showMoreGroupSessions&&e.resetGroupSessionLimit===t.resetGroupSessionLimit&&e.mobileVariant===t.mobileVariant&&e.alwaysShowActions===t.alwaysShowActions&&e.activeProjectId===t.activeProjectId&&e.setActiveProjectIdOnly===t.setActiveProjectIdOnly&&e.setActiveMainTab===t.setActiveMainTab&&e.setSessionSwitcherOpen===t.setSessionSwitcherOpen&&e.openNewSessionDraft===t.openNewSessionDraft&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.renamingFolderId===t.renamingFolderId&&e.renameFolderDraft===t.renameFolderDraft&&e.setRenameFolderDraft===t.setRenameFolderDraft&&e.setRenamingFolderId===t.setRenamingFolderId&&e.onToggleCollapsedGroup===t.onToggleCollapsedGroup&&e.onReorderSessions===t.onReorderSessions&&e.dragHandleProps===t.dragHandleProps&&e.scrollContainerRef===t.scrollContainerRef&&e.shortcutTargetSessionId===t.shortcutTargetSessionId&&e.shortcutTargetVisibleIndex===t.shortcutTargetVisibleIndex};function ay(e){let{t}=Tt(),{group:n,groupKey:r,isArchivedLoading:i=!1,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:s,normalizedSessionSearchQuery:c,groupSearchDataByGroup:l,visibleSessionCount:u,collapsedGroups:d,collapsedFolderIds:f,toggleFolderCollapse:p,renameFolder:m,deleteFolder:h,showDeletionDialog:g,setDeleteFolderConfirm:_,renderSessionNode:v,projectRepoStatus:y,lastRepoStatus:b,showMoreGroupSessions:x,resetGroupSessionLimit:S,mobileVariant:C,alwaysShowActions:w,activeProjectId:T,setActiveProjectIdOnly:E,setActiveMainTab:D,setSessionSwitcherOpen:O,openNewSessionDraft:k,addSessionToFolder:A,createFolderAndStartRename:j,renamingFolderId:M,renameFolderDraft:N,setRenameFolderDraft:P,setRenamingFolderId:F,pinnedSessionIds:L,expandedParents:R,sessionOrderByScope:z,sessionOrderActivityByScope:B,onReorderSessions:V,currentSessionId:ee,shortcutTargetSessionId:H=null,shortcutTargetVisibleIndex:ne=null,editingId:re,openSidebarMenuKey:U,prVisualStateByDirectoryBranch:ie,onToggleCollapsedGroup:ae,dragHandleProps:W,compactBodyPadding:oe=!1,scrollContainerRef:se,alwaysVisibleSessionIds:ce}=e,G=n.folderScopeKey??I(n.directory??null),le=Q.useMemo(()=>Ks(n.sessions,G?z[G]:void 0,G?B[G]:void 0,L),[G,n.sessions,L,B,z]),ue=s?l.get(n):null,de=qt(e=>e.displayMode),fe=rr(e=>G?e.foldersMap[G]??qv:qv),pe=de===`minimal`&&!te(),me=n.isArchivedBucket?null:I(n.directory??null),he=tn(e=>me?e.activePaginationByDirectory.get(me):void 0),ge=!s&&d.has(r),_e=Gs(),ve=Math.max(_e,u??_e),ye=s?ue?.groupMatches===!0:!1,be=s,xe=Q.useMemo(()=>[...be?ue?.filteredNodes??[]:n.sessions].sort(le),[le,n.sessions,ue?.filteredNodes,be]),Se=Q.useMemo(()=>{let e=new Map,t=n=>{n.forEach(n=>{e.set(n.session.id,n),n.children.length>0&&t(n.children)})};return t(xe),e},[xe]),Ce=Q.useMemo(()=>fe.map(e=>({folder:e,nodes:e.sessionIds.map(e=>Se.get(e)).filter(e=>!!e).sort(le)})),[fe,Se,le]),we=Q.useMemo(()=>{let e=new Map(Ce.map(e=>[e.folder.id,e])),t=new Map;for(let{folder:e}of Ce){if(!e.parentId)continue;let n=t.get(e.parentId);n?n.push(e.id):t.set(e.parentId,[e.id])}let r=new Map,i=a=>{let o=r.get(a);if(o!==void 0)return o;let l=e.get(a);if(!l)return r.set(a,!1),!1;let u=t.get(a)??[];if(n.isArchivedBucket&&l.nodes.length===0){let e=u.some(e=>i(e));return r.set(a,e),e}if(!s||l.folder.name.toLowerCase().includes(c)||l.nodes.length>0)return r.set(a,!0),!0;let d=u.some(e=>i(e));return r.set(a,d),d};return Ce.filter(({folder:e})=>i(e.id))},[Ce,n.isArchivedBucket,s,c]),Te=Q.useMemo(()=>new Set(we.flatMap(e=>e.folder.sessionIds)),[we]),Ee=Q.useMemo(()=>xe.filter(e=>!Te.has(e.session.id)),[xe,Te]),De=Q.useMemo(()=>we.filter(({folder:e})=>!e.parentId),[we]),Oe=`project`,ke=Q.useMemo(()=>{let e=new Set;return Bv(xe,ee,e),we.forEach(({nodes:t})=>{Bv(t,ee,e)}),e},[xe,we,ee]),Ae=Q.useMemo(()=>{let e=new Set;return Bv(xe,re,e),we.forEach(({nodes:t})=>{Bv(t,re,e)}),e},[xe,we,re]),je=Q.useMemo(()=>{if(!U)return null;let e=Uv(xe,U,Oe,!!n.isArchivedBucket);if(e)return e;for(let{nodes:e}of we){let t=Uv(e,U,Oe,!!n.isArchivedBucket);if(t)return t}return null},[U,xe,we,n.isArchivedBucket]),Me=Q.useMemo(()=>ny(xe),[xe]),Ne=Q.useMemo(()=>{let e=new WeakMap;return we.forEach(({nodes:t})=>{t.forEach(t=>e.set(t,Hv(t)))}),e},[we]),K=Q.useMemo(()=>e=>Me.get(e)??Ne.get(e)??``,[Me,Ne]),Pe=Q.useMemo(()=>e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e)}),[ke,Ae,je,K]),Fe=Ee.length,Ie=n.isArchivedBucket||s?Ee:Ee.slice(0,ve),Le=n.isArchivedBucket||s?Ee:tc(Ee,ve,ce),Re=Fe-Le.length,ze=Q.useMemo(()=>kc({folders:we,visibleUngroupedNodes:Le,collapsedFolderIds:f,hasSessionSearchQuery:s}),[we,f,s,Le]),Be=he?.hasMore===!0,Ve=he?.loadingMore===!0,He=u===void 0||u<=_e,Ue=!n.isArchivedBucket&&!s&&Fe>_e&&!He,We=n.isArchivedBucket===!0&&!s&&Le.length>=Wv,Ge=n.isArchivedBucket!==!0&&!s&&Le.length>=Gv,Ke=We||Ge,qe=n.isArchivedBucket?`archived`:`active`,Je=Ke&&Le.some(e=>{if(e.children.length===0)return!1;let t=`project:${qe}:${e.session.id}`;return R.has(t)}),Ye=Q.useRef(null),[Xe,q]=Q.useState(null),[,Ze]=Q.useState(0),Qe=vt(e=>{Ye.current=e,Ze(e=>e+1)});_t(Ke?Ye:null,()=>{Ze(e=>e+1)}),Q.useLayoutEffect(()=>{if(!Ke){q(e=>e===null?e:null);return}let e=Ye.current;if(!e){q(e=>e===null?e:null);return}let t=null,n=se?.current??null;if(n&&n.contains(e))t=n;else{let n=e.parentElement;for(;n;){let e=window.getComputedStyle(n);if(e.overflowY===`auto`||e.overflowY===`scroll`){t=n;break}n=n.parentElement}}if(!t){q(e=>e===null?e:null);return}let r=e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop;q(n=>n?.container===e&&n.scrollElement===t&&Math.abs(n.scrollMargin-r)<1?n:{container:e,scrollElement:t,scrollMargin:r})});let $e=Ye.current,et=se?.current??null,tt=Ke&&Xe!==null&&Xe.container===$e&&Xe.scrollElement.contains($e)&&(et===null||Xe.scrollElement===et),nt=Xe?.scrollElement??null,rt=Xe?.scrollMargin??0;yt(`transitionend`,e=>{e.propertyName===`height`&&e.target instanceof HTMLElement&&e.target.hasAttribute(`data-sidebar-collapse`)&&Ze(e=>e+1)},tt?nt:null);let it=os({count:Le.length,enabled:tt,getScrollElement:()=>nt,initialOffset:()=>nt?.scrollTop??0,estimateSize:()=>Kv,overscan:Je?20:8,scrollMargin:rt,getItemKey:e=>Le[e]?.session.id??e}),at=$s(Le,H,ne);Q.useLayoutEffect(()=>{!tt||!H||at===null||it.getVirtualItems().some(e=>e.index===at)||it.scrollToIndex(at,{align:`auto`,behavior:`auto`})},[rt,it,H,at,tt]);let ot=Q.useMemo(()=>ry(xe),[xe]),st=Q.useMemo(()=>{if(!n.isArchivedBucket)return new Map;let e=new Map,t=new Map;for(let{folder:e}of we){if(!e.parentId)continue;let n=t.get(e.parentId)??[];n.push(e.id),t.set(e.parentId,n)}let r=(e,n)=>{if(n.has(e))return[];n.add(e);let i=we.find(({folder:t})=>t.id===e),a=i?ry(i.nodes):[],o=t.get(e)??[];for(let e of o)a.push(...r(e,n));return a};for(let{folder:t}of we)e.set(t.id,r(t.id,new Set));return e},[we,n.isArchivedBucket]),ct=Q.useMemo(()=>({projectLabel:n.isMain?null:n.label,branchLabel:n.branch&&n.branch!==`HEAD`?n.branch:null}),[n.branch,n.isMain,n.label]),lt=vt(e=>{e.preventDefault(),e.stopPropagation();let t=I(n.directory??null),r=n.branch?.trim()??null,i=t&&r?ie.get(`${t}::${r}`)?.url??null:null;i&&qo(i)});if(s&&!ye&&De.length===0&&Ee.length===0)return null;let ut=a&&y.has(a)?!!y.get(a):b,dt=I(n.directory??null),ft=n.branch?.trim()??null,pt=dt&&ft?ie.get(`${dt}::${ft}`)??null:null,mt=!!(pt&&n.branch),ht=!pt&&!n.isMain&&!!n.branch,gt=pt&&pt.state===`open`&&pt.checks?t(`sessions.sidebar.group.pr.checksPassed`,{success:pt.checks.success,total:pt.checks.total}):null,bt=pt&&pt.state===`open`&&pt.checks?[pt.checks.failure>0?t(`sessions.sidebar.group.pr.failingCount`,{count:pt.checks.failure}):null,pt.checks.pending>0?t(`sessions.sidebar.group.pr.pendingCount`,{count:pt.checks.pending}):null].filter(e=>!!e).join(`, `):null,xt=pt&&pt.state===`open`?pt.mergeableState===`blocked`||pt.mergeableState===`dirty`?t(`sessions.sidebar.group.pr.conflictsOrBlocked`):pt.mergeableState===`clean`||pt.canMerge===!0?t(`sessions.sidebar.group.pr.mergeable`):null:null,St=pt&&pt.state===`open`&&pt.mergeableState?t(`sessions.sidebar.group.pr.mergeState`,{state:pt.mergeableState}):null,Ct=pt?.base??null,wt=pt?.head??null,Et=(()=>{if(!pt)return n.branch&&wa(n.branch,n.label)?{label:n.branch,color:null}:null;switch(pt.visualState){case`merged`:return{label:t(`sessions.sidebar.group.pr.status.merged`),color:`var(--pr-merged)`};case`open`:return pt.canMerge===!0||pt.mergeableState===`clean`||pt.checks?.state===`success`?{label:t(`sessions.sidebar.group.pr.status.readyToMerge`),color:`var(--pr-open)`}:{label:t(`sessions.sidebar.group.pr.status.open`),color:`var(--pr-open)`};case`blocked`:return{label:pt.mergeableState===`dirty`?t(`sessions.sidebar.group.pr.status.mergeConflicts`):t(`sessions.sidebar.group.pr.status.mergeBlocked`),color:`var(--pr-blocked)`};case`draft`:return{label:t(`sessions.sidebar.group.pr.status.draft`),color:`var(--pr-draft)`};case`closed`:return{label:t(`sessions.sidebar.group.pr.status.closed`),color:`var(--pr-closed)`};default:return null}})(),Dt=(e,t,r)=>{let i=we.filter(({folder:t})=>t.parentId===e.id),o=i.length>0?(0,$.jsx)($.Fragment,{children:i.map(({folder:e,nodes:t})=>Dt(e,t,r+1))}):void 0,c=st.get(e.id)??[];return(0,$.jsx)(uc,{folderId:e.id,children:(i,l)=>(0,$.jsx)(Dv,{folder:e,sessions:t,subFolderItems:o,isCollapsed:!s&&f.has(e.id),onToggle:()=>p(e.id),onRename:t=>{G&&m(G,e.id,t)},onDelete:()=>{if(n.isArchivedBucket){bn.requestDelete({sessions:c,mode:`session`});return}if(!G)return;if(!g){h(G,e.id);return}let r=we.filter(({folder:t})=>t.parentId===e.id).length,i=t.length;_({scopeKey:G,folderId:e.id,folderName:e.name,subFolderCount:r,sessionCount:i})},renderSessionNode:v,getRenderExtras:K?e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe}):void 0,groupDirectory:n.directory,projectId:a,mobileVariant:C,alwaysShowActions:w,isRenaming:M===e.id,renameDraft:M===e.id?N:void 0,onRenameDraftChange:e=>P(e),onRenameSave:()=>{let t=N.trim();t&&G&&m(G,e.id,t),F(null),P(``)},onRenameCancel:()=>{F(null),P(``)},droppableRef:i,isDropTarget:l,depth:r,onNewSession:()=>{a&&a!==T&&E(a),D(`chat`),C&&O(!1),k({directoryOverride:n.directory,targetFolderId:e.id})},onNewSubFolder:r===0?()=>{G&&j(G,e.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0,sessionSecondaryMeta:{projectLabel:e.name,branchLabel:n.branch&&n.branch!==`HEAD`?n.branch:null}})},e.id)},Ot=+!o,kt=o?1:Ot,At=()=>De.map(({folder:e,nodes:t})=>Dt(e,t,kt)),jt=!!(!n.isMain&&n.worktree),Mt=w?jt?`pr-14`:`pr-7`:pe?jt?`pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-2`:jt?`pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-5`,Nt=(0,$.jsxs)(pc,{scopeKey:G,sessionIds:ze.sessionIds,folderIdBySessionId:ze.folderIdBySessionId,onSessionDroppedOnFolder:(e,t)=>{G&&A(G,t,e)},onSessionsReordered:(e,t)=>{V(n,ze.sessionIds,e,t,qs(n.sessions.map(e=>e.session)))},children:[At(),Ke?(0,$.jsx)(`div`,{ref:Qe,children:tt?(0,$.jsx)(`div`,{style:{height:it.getTotalSize(),position:`relative`},children:it.getVirtualItems().map(e=>{let t=Le[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:it.measureElement,className:`[&_[data-session-row]]:my-px`,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start-rt}px)`},children:v(t,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(t),childRenderExtrasFor:Pe})},t.session.id):null})}):Le.map(e=>v(e,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe}))}):Le.map(e=>v(e,kt,n.directory,a,n.isArchivedBucket===!0,ct,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:K(e),childRenderExtrasFor:Pe})),Fe===0&&we.length===0?(0,$.jsx)(`div`,{className:Ua,style:{paddingLeft:$a(kt)},children:i?t(`sessions.sidebar.project.loadingSessions`):n.isArchivedBucket?t(`sessions.sidebar.group.empty.noArchivedSessions`):t(`sessions.sidebar.group.empty.noSessionsInWorkspace`)}):null,Re>0||Be||Ue?(0,$.jsxs)(`div`,{className:J(Ua,`flex w-full items-center gap-3 text-muted-foreground/60`),style:{paddingLeft:$a(kt)},children:[Re>0||Be?(0,$.jsx)(`button`,{type:`button`,onClick:()=>x(n,r,Ie.length,Fe),disabled:Ve,className:J(`text-left transition-colors hover:text-muted-foreground/80 disabled:pointer-events-none`,Ve&&`animate-pulse`),children:t(`sessions.sidebar.group.showMore`)}):null,Ue?(0,$.jsx)(`button`,{type:`button`,onClick:()=>S(r),className:`text-left transition-colors hover:text-muted-foreground/80`,children:t(`sessions.sidebar.group.showFewer`)}):null]}):null]}),Y=o?oe?`pb-0`:`pb-0.5`:oe?`pb-1`:`pb-1.5`,Pt=$a(Ot);return o?(0,$.jsx)(`div`,{className:`yuri-group`,children:(0,$.jsx)(`div`,{className:J(`yuri-group-body`,Y),children:Nt})}):(0,$.jsxs)(Xc,{open:!ge,className:`yuri-group`,children:[(0,$.jsxs)(`div`,{"data-mobile-press-feedback":W?`none`:void 0,className:J(`group/gh relative flex min-w-0 cursor-pointer items-start justify-between gap-1.5 rounded-lg py-1.5 pr-2`,Fa),style:{paddingLeft:Pt},onClick:()=>ae(n,r,a),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ae(n,r,a))},"aria-label":t(ge?`sessions.sidebar.group.expandAria`:`sessions.sidebar.group.collapseAria`,{label:n.label}),"aria-expanded":!ge,children:[(0,$.jsx)(`div`,{ref:W?.setActivatorNodeRef,className:J(`min-w-0 flex flex-1 items-start gap-1.5 overflow-hidden transition-[padding] cursor-grab active:cursor-grabbing`,Mt),...W?.listeners??{},children:(0,$.jsxs)(`div`,{className:`min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden`,children:[(0,$.jsx)(`p`,{className:`text-[14px] font-normal truncate text-foreground/92`,children:mt&&pt?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center`,children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 leading-none align-middle`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),pt.url?(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center leading-none`,onMouseDown:e=>e.stopPropagation(),onClick:lt,children:[`#`,pt.number]}):(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center leading-none`,children:[`#`,pt.number]})]})}),(0,$.jsx)(da,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(Z,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||gt?(0,$.jsxs)(`div`,{className:`text-muted-foreground truncate`,children:[xt??``,xt&&gt?` • `:``,gt??``,bt?` (${bt})`:``]}):null]})})]}),(0,$.jsx)(`span`,{className:`ml-1 min-w-0 flex-1 truncate leading-none align-middle`,children:n.branch})]}):n.isArchivedBucket?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`archive`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ta(n.label,c)})]}):!n.isMain||n.worktree?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:J(`h-3.5 w-3.5 shrink-0`,w?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:J(`h-3.5 w-3.5 items-center justify-center`,w?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ta(n.label,c)})]}):Ta(n.label,c)}),ht&&Et?(0,$.jsxs)(`span`,{className:J(`inline-flex min-w-0 items-center gap-1.5 leading-tight`,!Et.color&&`text-muted-foreground`),style:Et.color?{color:Et.color}:void 0,children:[n.isArchivedBucket?(0,$.jsx)(Z,{name:`archive`,className:`h-3.5 w-3.5 flex-shrink-0`}):!n.isMain||ut?mt&&pt?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center`,children:(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(da,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(Z,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||gt?(0,$.jsxs)(`div`,{className:`text-muted-foreground truncate`,children:[xt??``,xt&&gt?` • `:``,gt??``,bt?` (${bt})`:``]}):null]})})]}):(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5 flex-shrink-0`}):null,(0,$.jsx)(`span`,{className:`min-w-0 truncate text-[11px] font-medium`,children:Et.label})]}):null]})}),n.isArchivedBucket&&ot.length>0?(0,$.jsx)(`div`,{className:J(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),bn.requestDelete({sessions:ot,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":t(`sessions.sidebar.group.actions.deleteArchivedInGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.group.actions.deleteArchivedSessions`)})})]})}):null,n.directory&&!n.isMain&&n.worktree?(0,$.jsx)(`div`,{className:J(`absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),bn.requestDelete({sessions:ot,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":t(`sessions.sidebar.group.actions.deleteGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.group.actions.deleteWorktree`)})})]})}):null,n.directory?(0,$.jsx)(`div`,{className:J(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,w?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a&&a!==T&&E(a),D(`chat`),C&&O(!1),k({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":t(`sessions.sidebar.group.actions.newDraftInGroupAria`,{label:n.label}),children:(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.project.actions.newDraftSession`)})})]})}):null]}),(0,$.jsx)(Jc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ge||void 0,children:(0,$.jsx)(`div`,{className:J(`yuri-group-body`,Y),children:Nt})})]})}var oy=Q.memo(ay,iy);function sy(e){let t=(0,pl.c)(36),{t:n}=Tt(),{hideDirectoryControls:r,isSessionSearchOpen:i,setIsSessionSearchOpen:a,sessionSearchInputRef:o,sessionSearchQuery:s,setSessionSearchQuery:c,hasSessionSearchQuery:l,searchMatchCount:u}=e;if(r||!i)return null;let d;t[0]!==l||t[1]!==u||t[2]!==n?(d=l?(0,$.jsx)(`span`,{children:n(u===1?`sessions.sidebar.header.search.matchCountSingle`:`sessions.sidebar.header.search.matchCountPlural`,{count:u})}):(0,$.jsx)(`span`,{}),t[0]=l,t[1]=u,t[2]=n,t[3]=d):d=t[3];let f;t[4]===n?f=t[5]:(f=n(`sessions.sidebar.header.search.escapeHint`),t[4]=n,t[5]=f);let p;t[6]===f?p=t[7]:(p=(0,$.jsx)(`span`,{children:f}),t[6]=f,t[7]=p);let m;t[8]!==d||t[9]!==p?(m=(0,$.jsxs)(`div`,{className:`mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80`,children:[d,p]}),t[8]=d,t[9]=p,t[10]=m):m=t[10];let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Z,{name:`search`,className:`pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),t[11]=h):h=t[11];let g;t[12]===c?g=t[13]:(g=e=>c(e.target.value),t[12]=c,t[13]=g);let _;t[14]===n?_=t[15]:(_=n(`sessions.sidebar.header.search.placeholder`),t[14]=n,t[15]=_);let v;t[16]!==l||t[17]!==a||t[18]!==c?(v=e=>{e.key===`Escape`&&(e.stopPropagation(),l?c(``):a(!1))},t[16]=l,t[17]=a,t[18]=c,t[19]=v):v=t[19];let y;t[20]!==o||t[21]!==s||t[22]!==g||t[23]!==_||t[24]!==v?(y=(0,$.jsx)(`input`,{ref:o,value:s,onChange:g,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:v}),t[20]=o,t[21]=s,t[22]=g,t[23]=_,t[24]=v,t[25]=y):y=t[25];let b;t[26]!==s.length||t[27]!==c||t[28]!==n?(b=s.length>0?(0,$.jsx)(`button`,{type:`button`,onClick:()=>c(``),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:(0,$.jsx)(Z,{name:`close`,className:`h-3.5 w-3.5`})}):null,t[26]=s.length,t[27]=c,t[28]=n,t[29]=b):b=t[29];let x;t[30]!==y||t[31]!==b?(x=(0,$.jsxs)(`div`,{className:`relative`,children:[h,y,b]}),t[30]=y,t[31]=b,t[32]=x):x=t[32];let S;return t[33]!==x||t[34]!==m?(S=(0,$.jsx)(`div`,{className:`select-none flex-shrink-0 px-3 py-1`,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[m,x]})}),t[33]=x,t[34]=m,t[35]=S):S=t[35],S}function cy(e){let t=(0,pl.c)(13),{title:n,accessory:r,isFirst:i,onToggle:a,expanded:o,className:s}=e,c=i!==void 0&&i?`pt-1 pb-1`:`pt-4 pb-1`,l;t[0]!==s||t[1]!==c?(l=J(`group/section flex w-full items-center gap-1 px-2`,c,s),t[0]=s,t[1]=c,t[2]=l):l=t[2];let u;t[3]!==o||t[4]!==a||t[5]!==n?(u=a?(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:`group/toggle flex min-w-0 flex-1 items-center gap-1 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,"aria-expanded":o,children:[(0,$.jsx)(`span`,{className:`typography-micro font-normal tracking-wide text-muted-foreground/80`,children:n}),(0,$.jsx)(Z,{name:o?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 opacity-0 transition-opacity group-hover/toggle:opacity-100 group-focus-visible/toggle:opacity-100`})]}):(0,$.jsx)(`span`,{className:J(`flex min-w-0 flex-1 items-center gap-1`,`typography-micro font-normal tracking-wide text-muted-foreground/80`),children:n}),t[3]=o,t[4]=a,t[5]=n,t[6]=u):u=t[6];let d;t[7]===r?d=t[8]:(d=r?(0,$.jsx)(`div`,{className:`ml-auto -mr-2 flex shrink-0 items-center`,children:r}):null,t[7]=r,t[8]=d);let f;return t[9]!==l||t[10]!==u||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:l,children:[u,d]}),t[9]=l,t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function ly(e){let t=(0,pl.c)(60),{items:n,reorderEnabled:r,onSessionsReordered:i,inProgressItems:a,renderSessionNode:o,currentSessionId:s,editingId:c,openSidebarMenuKey:l,headerAccessory:u,onVisibleSessionIdsChange:d}=e,f=r!==void 0&&r,p;t[0]===a?p=t[1]:(p=a===void 0?[]:a,t[0]=a,t[1]=p);let m=p,{t:h}=Tt(),[g,_]=Q.useState(!1),v=f&&!c&&n.length>1&&!!i,y;t[2]===n?y=t[3]:(y=n.map(_y),t[2]=n,t[3]=y);let b=y,x;t[4]===b?x=t[5]:(x=new Map(b.map(gy)),t[4]=b,t[5]=x);let S=x,C=Ui(hy),w,T;t[6]!==g||t[7]!==m||t[8]!==n||t[9]!==d?(w=()=>{if(g){d?.([]);return}d?.([...n.map(my),...m.map(py)])},T=[g,m,n,d],t[6]=g,t[7]=m,t[8]=n,t[9]=d,t[10]=w,t[11]=T):(w=t[10],T=t[11]),Q.useLayoutEffect(w,T);let E,D;t[12]!==m||t[13]!==n||t[14]!==C?(E=()=>{C&&(n.some(e=>e.node.session.id===C)||m.some(e=>e.node.session.id===C))&&_(!1)},D=[m,n,C],t[12]=m,t[13]=n,t[14]=C,t[15]=E,t[16]=D):(E=t[15],D=t[16]),Q.useLayoutEffect(E,D);let O,k,A,j;if(t[17]!==s||t[18]!==c||t[19]!==m||t[20]!==n||t[21]!==l){let e=[...n,...m].map(fy);A=new Set,Bv(e,s,A),j=new Set,Bv(e,c,j),O=Uv(e,l,`pinned`,!1),k=new WeakMap;let r=e=>{k.set(e,Hv(e)),e.children.forEach(r)};e.forEach(r),t[17]=s,t[18]=c,t[19]=m,t[20]=n,t[21]=l,t[22]=O,t[23]=k,t[24]=A,t[25]=j}else O=t[22],k=t[23],A=t[24],j=t[25];let M;t[26]!==O||t[27]!==k||t[28]!==A||t[29]!==j?(M=e=>({subtreeContainsActive:A,subtreeContainsEditing:j,menuOpenSessionId:O,nodeStructureKey:k.get(e)??``,childRenderExtrasFor:M}),t[26]=O,t[27]=k,t[28]=A,t[29]=j,t[30]=M):M=t[30];let N;t[31]!==M||t[32]!==O||t[33]!==k||t[34]!==A||t[35]!==j?(N=e=>({subtreeContainsActive:A,subtreeContainsEditing:j,menuOpenSessionId:O,nodeStructureKey:k.get(e)??``,childRenderExtrasFor:M}),t[31]=M,t[32]=O,t[33]=k,t[34]=A,t[35]=j,t[36]=N):N=t[36];let P=N;if(n.length+m.length===0)return null;let F;t[37]!==P||t[38]!==o?(F=e=>e.map(e=>{let t=o(e.node,0,e.groupDirectory,e.projectId,!1,e.secondaryMeta,`pinned`,P(e.node));return(0,$.jsx)(Q.Fragment,{children:t},e.node.session.id)}),t[37]=P,t[38]=o,t[39]=F):F=t[39];let I=F,L;t[40]!==m.length||t[41]!==h?(L=m.length>0?h(`directoryTree.section.pinnedInProgress`):h(`directoryTree.section.pinned`),t[40]=m.length,t[41]=h,t[42]=L):L=t[42];let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>_(dy),t[43]=R):R=t[43];let z=!g,B;t[44]!==u||t[45]!==L||t[46]!==z?(B=(0,$.jsx)(cy,{title:L,onToggle:R,expanded:z,accessory:u}),t[44]=u,t[45]=L,t[46]=z,t[47]=B):B=t[47];let V;t[48]!==v||t[49]!==g||t[50]!==S||t[51]!==m||t[52]!==n||t[53]!==i||t[54]!==I||t[55]!==b?(V=g?null:(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[v?(0,$.jsx)(pc,{scopeKey:ac,sessionIds:b,folderIdBySessionId:S,onSessionDroppedOnFolder:uy,onSessionsReordered:(e,t)=>i?.(e,t),children:I(n)}):I(n),I(m)]}),t[48]=v,t[49]=g,t[50]=S,t[51]=m,t[52]=n,t[53]=i,t[54]=I,t[55]=b,t[56]=V):V=t[56];let ee;return t[57]!==B||t[58]!==V?(ee=(0,$.jsx)(fa,{delay:0,closeDelay:150,timeout:600,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[B,V]})}),t[57]=B,t[58]=V,t[59]=ee):ee=t[59],ee}function uy(){}function dy(e){return!e}function fy(e){return e.node}function py(e){return e.node.session.id}function my(e){return e.node.session.id}function hy(e){return e.focus?.scope===`pinned`?e.focus.sessionId:null}function gy(e){return[e,null]}function _y(e){return e.node.session.id}function vy(e){let t=(0,pl.c)(41),{collapseAllProjects:n,expandAllProjects:r,buttonClassName:i,iconClassName:a}=e,{t:o}=Tt(),s;t[0]===i?s=t[1]:(s=J(`size-6 p-0 text-muted-foreground`,i),t[0]=i,t[1]=s);let c;t[2]===o?c=t[3]:(c=o(`sessions.sidebar.header.actions.sessionDisplayMode`),t[2]=o,t[3]=c);let l;t[4]===a?l=t[5]:(l=J(`h-3.5 w-3.5`,a),t[4]=a,t[5]=l);let u;t[6]===l?u=t[7]:(u=(0,$.jsx)(Z,{name:`more-2-fill`,className:l}),t[6]=l,t[7]=u);let d;t[8]!==s||t[9]!==c||t[10]!==u?(d=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:s,"aria-label":c,onClick:yy,children:u})})}),t[8]=s,t[9]=c,t[10]=u,t[11]=d):d=t[11];let f;t[12]===o?f=t[13]:(f=o(`sessions.sidebar.header.displayMode.label`),t[12]=o,t[13]=f);let p;t[14]===f?p=t[15]:(p=(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f})}),t[14]=f,t[15]=p);let m;t[16]!==d||t[17]!==p?(m=(0,$.jsxs)(pa,{children:[d,p]}),t[16]=d,t[17]=p,t[18]=m):m=t[18];let h;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Z,{name:`contract-up-down`,className:`h-4 w-4`}),t[19]=h):h=t[19];let g;t[20]===o?g=t[21]:(g=o(`sessions.sidebar.header.displayMode.collapseAll`),t[20]=o,t[21]=g);let _;t[22]===g?_=t[23]:(_=(0,$.jsx)(`span`,{children:g}),t[22]=g,t[23]=_);let v;t[24]!==n||t[25]!==_?(v=(0,$.jsxs)(ka,{onClick:n,className:`flex items-center gap-2`,children:[h,_]}),t[24]=n,t[25]=_,t[26]=v):v=t[26];let y;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Z,{name:`expand-up-down`,className:`h-4 w-4`}),t[27]=y):y=t[27];let b;t[28]===o?b=t[29]:(b=o(`sessions.sidebar.header.displayMode.expandAll`),t[28]=o,t[29]=b);let x;t[30]===b?x=t[31]:(x=(0,$.jsx)(`span`,{children:b}),t[30]=b,t[31]=x);let S;t[32]!==r||t[33]!==x?(S=(0,$.jsxs)(ka,{onClick:r,className:`flex items-center gap-2`,children:[y,x]}),t[32]=r,t[33]=x,t[34]=S):S=t[34];let C;t[35]!==v||t[36]!==S?(C=(0,$.jsxs)(Ia,{align:`end`,className:`min-w-[160px]`,children:[v,S]}),t[35]=v,t[36]=S,t[37]=C):C=t[37];let w;return t[38]!==C||t[39]!==m?(w=(0,$.jsxs)(Ga,{children:[m,C]}),t[38]=C,t[39]=m,t[40]=w):w=t[40],w}function yy(e){e.stopPropagation()}var by=()=>rt({queryKey:[l(),u(),`device-connections`],queryFn:async({signal:e})=>{let t=await _(`/api/client-auth/clients`,{signal:e});if(!t.ok)throw Error(`Device list unavailable`);let n=await t.json();if(!Array.isArray(n.clients))throw Error(`Invalid device list`);if(n.clients.some(e=>typeof e.connected!=`boolean`))throw Error(`Presence unavailable`);return n.clients.filter(e=>!e.revokedAt&&e.connected&&e.clientKind!==`desktop-local`&&e.id!==n.currentClientId)},staleTime:0,retry:!1});function xy(){let e=(0,pl.c)(53),{t}=Tt(),{clientAuth:n}=at(),[r,i]=(0,Q.useState)(!1),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=by(),e[0]=a):a=e[0];let o=r&&!!n,s=r?5e3:!1,c;e[1]!==o||e[2]!==s?(c={...a,enabled:o,refetchInterval:s},e[1]=o,e[2]=s,e[3]=c):c=e[3];let l=it(c),u;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{i(!1);let e=q.getState();e.setSettingsRemoteInstancesSelectedId(null),e.setSettingsPage(`remote-instances`),q.setState({devicePairingRequested:!0}),e.setSettingsDialogOpen(!0)},e[4]=u):u=e[4];let d=vt(u);if(!n)return null;let f;e[5]===t?f=e[6]:(f=t(`settings.remoteInstances.quick.title`),e[5]=t,e[6]=f);let p;e[7]===f?p=e[8]:(p=(0,$.jsx)(Y,{variant:`ghost`,size:`icon`,className:`group size-7 rounded-md text-foreground/55 hover:bg-interactive-hover hover:text-foreground`,"aria-label":f}),e[7]=f,e[8]=p);let m;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Z,{name:`devices-connected`,className:`size-[18px]`}),e[9]=m):m=e[9];let h;e[10]===p?h=e[11]:(h=(0,$.jsx)(be,{openOnHover:!0,delay:180,closeDelay:200,render:p,children:m}),e[10]=p,e[11]=h);let g;e[12]===t?g=e[13]:(g=t(`settings.remoteInstances.quick.title`),e[12]=t,e[13]=g);let _;e[14]===g?_=e[15]:(_=(0,$.jsx)(ve,{className:`typography-ui-label font-medium`,children:g}),e[14]=g,e[15]=_);let v;e[16]===l.data?v=e[17]:(v=l.data&&l.data.length>0?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground tabular-nums`,children:l.data.length}):null,e[16]=l.data,e[17]=v);let y;e[18]!==_||e[19]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 pb-2 pt-4`,children:[_,v]}),e[18]=_,e[19]=v,e[20]=y):y=e[20];let b;e[21]!==l.isPending||e[22]!==t?(b=l.isPending?(0,$.jsx)(`p`,{className:`px-2 py-3 typography-meta text-muted-foreground`,children:t(`common.loading`)}):null,e[21]=l.isPending,e[22]=t,e[23]=b):b=e[23];let x;e[24]!==l.isError||e[25]!==t?(x=l.isError?(0,$.jsx)(`p`,{className:`px-2 py-3 typography-meta text-muted-foreground`,children:t(`settings.remoteInstances.quick.error`)}):null,e[24]=l.isError,e[25]=t,e[26]=x):x=e[26];let S;e[27]!==l.data?.length||e[28]!==l.isError||e[29]!==t?(S=!l.isError&&l.data?.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center px-5 pb-5 pt-6 text-center`,children:[(0,$.jsx)(Z,{name:`devices-connected`,className:`mb-4 size-16 text-muted-foreground/45`}),(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:t(`settings.remoteInstances.clientAuth.state.empty`)}),(0,$.jsx)(`p`,{className:`mt-2 typography-meta leading-relaxed text-muted-foreground`,children:t(`settings.remoteInstances.quick.emptyHint`)})]}):null,e[27]=l.data?.length,e[28]=l.isError,e[29]=t,e[30]=S):S=e[30];let C;e[31]!==l.data||e[32]!==t?(C=l.data?.map(e=>{let n=e.devicePlatform?.toLowerCase();return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-muted)] px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center text-muted-foreground`,children:(0,$.jsx)(Z,{name:n===`ios`?`device-ios`:n===`android`?`device-android`:`device-desktop`,className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate typography-ui-label`,children:e.label}),(0,$.jsx)(`p`,{className:`mt-0.5 truncate typography-micro text-[var(--status-success)]`,children:t(`desktopHostSwitcher.status.connected`)})]})]},e.id)}),e[31]=l.data,e[32]=t,e[33]=C):C=e[33];let w;e[34]!==b||e[35]!==x||e[36]!==S||e[37]!==C?(w=(0,$.jsxs)(`div`,{className:`max-h-64 space-y-2 overflow-y-auto px-3 pb-2`,"aria-live":`polite`,children:[b,x,S,C]}),e[34]=b,e[35]=x,e[36]=S,e[37]=C,e[38]=w):w=e[38];let T;e[39]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Z,{name:`add`,className:`size-4`}),e[39]=T):T=e[39];let E;e[40]===t?E=e[41]:(E=t(`settings.remoteInstances.clientAuth.actions.addDevice`),e[40]=t,e[41]=E);let D;e[42]!==d||e[43]!==E?(D=(0,$.jsx)(`div`,{className:`px-3 pb-3 pt-1`,children:(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,className:`w-full justify-center gap-2 rounded-xl`,onClick:d,children:[T,E]})}),e[42]=d,e[43]=E,e[44]=D):D=e[44];let O;e[45]!==y||e[46]!==w||e[47]!==D?(O=(0,$.jsx)(ye,{children:(0,$.jsx)(Oe,{side:`top`,align:`start`,sideOffset:10,className:`z-50`,children:(0,$.jsxs)(we,{className:`w-72 max-w-[calc(100vw-24px)] origin-[var(--transform-origin)] overflow-hidden rounded-2xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] text-foreground shadow-lg outline-none transition-[opacity,transform] duration-150 data-[starting-style]:translate-y-1 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0`,children:[y,w,D]})})}),e[45]=y,e[46]=w,e[47]=D,e[48]=O):O=e[48];let k;return e[49]!==r||e[50]!==O||e[51]!==h?(k=(0,$.jsxs)(Ee,{open:r,onOpenChange:i,children:[h,O]}),e[49]=r,e[50]=O,e[51]=h,e[52]=k):k=e[52],k}var Sy=`group size-7 rounded-md text-muted-foreground/75 transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary`,Cy=`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`;function wy(e){let t=(0,pl.c)(12),{onOpenSettings:n,onOpenShortcuts:r,onOpenUpdate:i,showRuntimeButtons:a,showUpdateButton:o}=e,s=a===void 0||a,c=o!==void 0&&o,{t:l}=Tt(),u;t[0]!==n||t[1]!==r||t[2]!==s||t[3]!==l?(u=s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:Sy,onClick:n,"aria-label":l(`sessions.sidebar.footer.actions.settings`),children:(0,$.jsx)(Z,{name:`settings-3`,className:Cy})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.settings`)})]}),(0,$.jsx)(xy,{}),(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:Sy,onClick:r,"aria-label":l(`sessions.sidebar.footer.actions.shortcuts`),children:(0,$.jsx)(Z,{name:`question`,className:Cy})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.shortcuts`)})]})]}):null,t[0]=n,t[1]=r,t[2]=s,t[3]=l,t[4]=u):u=t[4];let d;t[5]!==i||t[6]!==c||t[7]!==l?(d=c&&i?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon`,className:`ml-auto size-6 rounded-full [corner-shape:round] supports-[corner-shape:squircle]:rounded-full border border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)] active:bg-[var(--primary-hover)]`,onClick:i,"aria-label":l(`sessions.sidebar.footer.actions.update`),children:(0,$.jsx)(Z,{name:`download`,className:`size-3.5`})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:l(`sessions.sidebar.footer.actions.update`)})})]}):null,t[5]=i,t[6]=c,t[7]=l,t[8]=d):d=t[8];let f;return t[9]!==u||t[10]!==d?(f=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-start gap-1 px-2.5 py-2`,children:[u,d]}),t[9]=u,t[10]=d,t[11]=f):f=t[11],f}var Ty=Q.memo(function(e){let t=(0,pl.c)(64),{id:n,disabled:r,projectLabel:i,projectDescription:a,projectIcon:o,projectColor:s,projectIconImage:c,isCollapsed:l,isActiveProject:u,isSessionsLoading:d,isRepo:f,isDesktopShell:p,isStuck:m,hideDirectoryControls:h,alwaysShowActions:g,onToggle:_,onNewSession:v,onNewWorktreeSession:y,onSyncSessions:b,onRenameStart:x,onClose:S,sentinelRef:C,children:w,showCreateButtons:T,hideHeader:E,openSidebarMenuKey:D,setOpenSidebarMenuKey:O,reorderEnabled:k}=e,A=r!==void 0&&r,j=d!==void 0&&d,M=T===void 0||T,N=E!==void 0&&E,P=k===void 0||k,{t:F}=Tt(),I=A||!P,L;t[0]!==n||t[1]!==I?(L={id:n,disabled:I},t[0]=n,t[1]=I,t[2]=L):L=t[2];let{attributes:R,listeners:z,setNodeRef:B,transform:V,transition:ee,isDragging:H}=Wo(L),te=Q.useRef(!1),ne=`project:${n}`,re=D===ne,[U,ie]=Q.useState(!1),ae=o?na[o]:null,W=s?aa[s]:void 0,oe=ae??`folder-open`,se;t[3]===W?se=t[4]:(se=W?{color:W}:void 0,t[3]=W,t[4]=se);let ce;t[5]!==oe||t[6]!==se?(ce=(0,$.jsx)(Z,{name:oe,className:`h-4 w-4`,style:se}),t[5]=oe,t[6]=se,t[7]=ce):ce=t[7];let G=ce,le;t[8]!==ne||t[9]!==O?(le=e=>{e&&ie(!1),O(e?ne:null)},t[8]=ne,t[9]=O,t[10]=le):le=t[10];let ue=le,de;t[11]!==h||t[12]!==f||t[13]!==S||t[14]!==v||t[15]!==x||t[16]!==b||t[17]!==M||t[18]!==F?(de=e=>(0,$.jsxs)($.Fragment,{children:[M&&!f&&!h&&v&&(0,$.jsxs)(e,{onClick:v,children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.newSession`)]}),(0,$.jsxs)(e,{onClick:b,children:[(0,$.jsx)(Z,{name:`refresh`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.syncSessions`)]}),(0,$.jsxs)(e,{onClick:x,children:[(0,$.jsx)(Z,{name:`pencil-ai`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.edit`)]}),(0,$.jsxs)(e,{onClick:S,className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.closeProject`)]})]}),t[11]=h,t[12]=f,t[13]=S,t[14]=v,t[15]=x,t[16]=b,t[17]=M,t[18]=F,t[19]=de):de=t[19];let fe=de,pe=Dy,me=Oy,he=ky,ge;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>{(e.button===2||e.button===0&&e.ctrlKey)&&(te.current=!0)},t[20]=ge):ge=t[20];let _e=ge,ve;t[21]===_?ve=t[22]:(ve=()=>{if(te.current){te.current=!1;return}_()},t[21]=_,t[22]=ve);let ye=ve,be;t[23]===V?be=t[24]:(be=Vo.Transform.toString(V),t[23]=V,t[24]=be);let xe;t[25]!==be||t[26]!==ee?(xe={transform:be,transition:ee},t[25]=be,t[26]=ee,t[27]=xe):xe=t[27];let Se=H&&`opacity-30`,Ce;t[28]===Se?Ce=t[29]:(Ce=J(`relative`,Se),t[28]=Se,t[29]=Ce);let we;t[30]!==g||t[31]!==R||t[32]!==ue||t[33]!==ye||t[34]!==h||t[35]!==N||t[36]!==n||t[37]!==u||t[38]!==l||t[39]!==U||t[40]!==p||t[41]!==re||t[42]!==f||t[43]!==j||t[44]!==m||t[45]!==z||t[46]!==v||t[47]!==y||t[48]!==a||t[49]!==G||t[50]!==c||t[51]!==i||t[52]!==fe||t[53]!==P||t[54]!==C||t[55]!==M||t[56]!==F?(we=N?null:(0,$.jsxs)($.Fragment,{children:[p&&(0,$.jsx)(`div`,{ref:C,"data-project-id":n,className:`absolute top-0 h-px w-full pointer-events-none`,"aria-hidden":`true`}),(0,$.jsxs)(Hc,{open:U,onOpenChange:ie,children:[(0,$.jsx)(Wc,{render:(0,$.jsx)(`div`,{className:J(`w-full text-left group/project select-none`),style:{backgroundColor:p&&m?`transparent`:void 0},onContextMenu:e=>{h||(e.preventDefault(),ie(!0))}}),children:(0,$.jsxs)(`div`,{className:J(`relative flex items-center gap-1.5 rounded-lg px-2 py-1.5`,Fa),...R,children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onMouseDown:_e,onClick:ye,...P?z:{},className:J(`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 transition-[padding]`,P?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,f&&!h?g?`pr-20`:`pr-7 group-hover/project:pr-20 group-has-[:focus-visible]/project:pr-20`:g?`pr-14`:`pr-7 group-hover/project:pr-14 group-has-[:focus-visible]/project:pr-14`),children:[(0,$.jsx)(`span`,{className:`inline-flex h-4 w-4 flex-shrink-0 items-center justify-center overflow-hidden text-foreground`,children:j?(0,$.jsx)(Z,{name:`loader-4`,className:`h-4 w-4 animate-spin`,"aria-label":F(`sessions.sidebar.project.loadingSessions`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:J(`h-4 w-4 items-center justify-center`,g?`inline-flex`:`hidden group-hover/project:inline-flex group-has-[:focus-visible]/project:inline-flex`),children:l?(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:J(g?`hidden`:`group-hover/project:hidden group-has-[:focus-visible]/project:hidden`),children:c?(0,$.jsx)(Qi,{project:{id:n,iconImage:c},className:`size-full object-contain`,fallback:G}):G})]})}),(0,$.jsx)(`span`,{className:J(`text-[14px] font-normal truncate lowercase`,u?`text-foreground`:`text-foreground group-hover/project:text-foreground`),children:i})]})}),(0,$.jsx)(da,{side:`right`,sideOffset:8,children:a})]}),(0,$.jsxs)(`div`,{className:J(`absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1`,M?`right-7`:`right-0.5`),children:[M&&f&&!h&&y?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y()},className:J(`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`,g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(`sessions.sidebar.project.actions.newWorktree`),children:(0,$.jsx)(Z,{name:`node-tree`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(`sessions.sidebar.project.actions.newWorktreeEllipsis`)})})]}):null,h?null:(0,$.jsxs)(Ga,{open:re,onOpenChange:ue,children:[(0,$.jsx)(Ja,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`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`,re?`opacity-100 pointer-events-auto`:g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(`sessions.sidebar.project.actions.projectMenu`),onPointerDown:me,onMouseDown:he,onClick:pe,children:(0,$.jsx)(Z,{name:`more-2`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Ia,{align:`end`,className:`min-w-[180px]`,children:fe(ka)})]})]}),M&&v?(0,$.jsx)(`div`,{className:`absolute right-0.5 top-1/2 z-10 -translate-y-1/2`,children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},className:J(`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`,g?`opacity-100`:`opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-has-[:focus-visible]/project:opacity-100 group-has-[:focus-visible]/project:pointer-events-auto`),"aria-label":F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`),children:(0,$.jsx)(Z,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(da,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`)})})]})}):null]})}),(0,$.jsx)(Gc,{className:`min-w-[180px]`,children:fe(Kc)})]})]}),t[30]=g,t[31]=R,t[32]=ue,t[33]=ye,t[34]=h,t[35]=N,t[36]=n,t[37]=u,t[38]=l,t[39]=U,t[40]=p,t[41]=re,t[42]=f,t[43]=j,t[44]=m,t[45]=z,t[46]=v,t[47]=y,t[48]=a,t[49]=G,t[50]=c,t[51]=i,t[52]=fe,t[53]=P,t[54]=C,t[55]=M,t[56]=F,t[57]=we):we=t[57];let Te;return t[58]!==w||t[59]!==B||t[60]!==xe||t[61]!==Ce||t[62]!==we?(Te=(0,$.jsxs)(`div`,{ref:B,style:xe,className:Ce,children:[we,w]}),t[58]=w,t[59]=B,t[60]=xe,t[61]=Ce,t[62]=we,t[63]=Te):Te=t[63],Te}),Ey=Q.memo(e=>{let t=(0,pl.c)(21),{id:n,disabled:r,children:i}=e,a=r!==void 0&&r,o;t[0]!==a||t[1]!==n?(o={id:n,disabled:a},t[0]=a,t[1]=n,t[2]=o):o=t[2];let{listeners:s,setNodeRef:c,setActivatorNodeRef:l,transform:u,transition:d,isDragging:f}=Wo(o),p;t[3]!==s||t[4]!==l?(p={listeners:s,setActivatorNodeRef:l},t[3]=s,t[4]=l,t[5]=p):p=t[5];let m=p,h;t[6]===u?h=t[7]:(h=Vo.Transform.toString(u),t[6]=u,t[7]=h);let g;t[8]!==h||t[9]!==d?(g={transform:h,transition:d},t[8]=h,t[9]=d,t[10]=g):g=t[10];let _=f&&`opacity-50`,v;t[11]===_?v=t[12]:(v=J(`space-y-0.5 rounded-md`,_),t[11]=_,t[12]=v);let y;t[13]!==i||t[14]!==m?(y=typeof i==`function`?i(m):i,t[13]=i,t[14]=m,t[15]=y):y=t[15];let b;return t[16]!==c||t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsx)(`div`,{ref:c,style:g,className:v,children:y}),t[16]=c,t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20],b});function Dy(e){e.stopPropagation()}function Oy(e){e.stopPropagation()}function ky(e){e.stopPropagation()}var Ay={activationConstraint:{distance:8}},jy={coordinateGetter:Ho},My=e=>{let t=(0,pl.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(fa,{delay:0,closeDelay:150,timeout:600,children:n}),t[0]=n,t[1]=r),r};function Ny(e){let{t}=Tt(),n=Bo(Po(Ro,Ay),Po(Fo,jy)),r=e.hasSessionSearchQuery?null:(0,$.jsx)(cy,{title:t(`sessions.sidebar.projectsTitle`),isFirst:!e.hasLeadingSection,accessory:e.headerAccessory}),i=Q.useRef(null),a=Q.useRef(new Map),o=Q.useRef(e.getOrderedGroups);o.current!==e.getOrderedGroups&&(o.current=e.getOrderedGroups,a.current.clear());let s=(t,n)=>{let r=a.current,i=r.get(t);if(i&&i.groups===n)return i.ordered;let o=e.getOrderedGroups(t,n);if(r.set(t,{groups:n,ordered:o}),r.size>256){let e=r.keys().next().value;e!==void 0&&r.delete(e)}return o};return e.sharedSessionsOnly?(0,$.jsx)(My,{children:(0,$.jsxs)(mo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:[e.topContent,e.hasSharedSessions?null:e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState]})}):e.projectSections.length===0?(0,$.jsx)(My,{children:(0,$.jsxs)(mo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:[e.topContent,r,e.emptyState]})}):e.sectionsForRender.length===0?(0,$.jsx)(My,{children:(0,$.jsx)(mo,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:e.searchEmptyState})}):(0,$.jsx)(My,{children:(0,$.jsxs)(mo,{ref:i,useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:J(`space-y-1 px-3 pb-1 [overflow-anchor:none]`,(e.mobileVariant,``)),children:[e.topContent,e.showOnlyMainWorkspace?(0,$.jsx)(`div`,{className:`space-y-[0.6rem] py-1`,children:(()=>{let n=e.sectionsForRender.find(t=>t.project.id===e.activeProjectId)??e.sectionsForRender[0];if(!n)return e.hasSessionSearchQuery?e.searchEmptyState:e.emptyState;let r=n.groups.find(e=>e.isMain&&e.sessions.length>0)??n.groups.find(e=>e.sessions.length>0)??n.groups.find(e=>e.isMain)??n.groups[0];if(!r)return(0,$.jsx)(`div`,{className:Ua,children:t(`sessions.sidebar.empty.noSessions.title`)});let a=n.groups.find(e=>e.isArchivedBucket);return[r,...a&&a.id!==r.id?[a]:[]].map(t=>{let a=`${n.project.id}:${t.id}`,o=t.id===r.id;return(0,$.jsx)(Q.Fragment,{children:e.renderGroupSessions(t,a,n.project.id,o,null,!0,i)},a)})})()}):(0,$.jsxs)($.Fragment,{children:[r,(0,$.jsxs)(zo,{sensors:n,collisionDetection:Io,onDragEnd:t=>{if(e.isInlineEditing||e.projectSortOrder!==`manual`)return;let{active:n,over:r}=t;!r||n.id===r.id||e.reorderProjects(String(n.id),String(r.id))},children:[(0,$.jsx)(Ko,{items:e.sectionsForRender.map(e=>e.project.id),strategy:Go,children:e.sectionsForRender.map(t=>{let n=t.project,r=n.id;return(0,$.jsx)(Py,{project:n,orderedGroups:s(r,t.groups),isCollapsed:e.collapsedProjects.has(r),isActiveProject:r===e.activeProjectId,isRepo:!!e.projectRepoStatus.get(r),isDesktopShellRuntime:e.isDesktopShellRuntime,isStuck:e.stuckProjectHeaders.has(r),hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,toggleProject:e.toggleProject,setActiveProjectIdOnly:e.setActiveProjectIdOnly,setActiveMainTab:e.setActiveMainTab,setSessionSwitcherOpen:e.setSessionSwitcherOpen,openNewSessionDraft:e.openNewSessionDraft,openNewWorktreeDialog:e.openNewWorktreeDialog,syncProjectSessions:e.syncProjectSessions,openProjectEditDialog:e.openProjectEditDialog,removeProject:e.removeProject,projectHeaderSentinelRefs:e.projectHeaderSentinelRefs,openSidebarMenuKey:e.openSidebarMenuKey===`project:${r}`?e.openSidebarMenuKey:null,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,projectReorderEnabled:e.projectReorderEnabled,projectSortOrder:e.projectSortOrder,isInlineEditing:e.isInlineEditing,setGroupOrderByProject:e.setGroupOrderByProject,renderGroupSessions:e.renderGroupSessions,scrollContainerRef:i,homeDirectory:e.homeDirectory},r)})}),(0,$.jsx)(Lo,{dropAnimation:null})]})]})]})})}var Py=Q.memo(function(e){let t=(0,pl.c)(114),{t:n}=Tt(),{project:r,orderedGroups:i,isCollapsed:a,renderGroupSessions:o,scrollContainerRef:s,isInlineEditing:c}=e,l=r.id,u;t[0]===r.normalizedPath?u=t[1]:(u=e=>te()?void 0:e.availableWorktreesByProject.get(r.normalizedPath),t[0]=r.normalizedPath,t[1]=u);let d=Sn(u),f;t[2]!==r.normalizedPath||t[3]!==d?(f=[r.normalizedPath,...(d??[]).flatMap(Fy)],t[2]=r.normalizedPath,t[3]=d,t[4]=f):f=t[4];let p=f,m;t[5]===p?m=t[6]:(m=e=>p.some(t=>e.loadingDirectories.has(t)),t[5]=p,t[6]=m);let h=tn(m),g;t[7]===p?g=t[8]:(g=e=>p.some(t=>e.refreshingDirectories.has(t)),t[7]=p,t[8]=g);let _=tn(g),v=Bo(Po(Ro,Ay)),y;t[9]===i?y=t[10]:(y=i.find(Iy)??null,t[9]=i,t[10]=y);let b=y,x;t[11]!==i||t[12]!==b?(x=b?i.filter(e=>e.id!==b.id):i,t[11]=i,t[12]=b,t[13]=x):x=t[13];let S=x,C;t[14]!==l||t[15]!==e?(C=()=>e.toggleProject(l),t[14]=l,t[15]=e,t[16]=C):C=t[16];let w=vt(C),T;t[17]!==r.normalizedPath||t[18]!==l||t[19]!==e?(T=()=>{e.isActiveProject||e.setActiveProjectIdOnly(l),e.setActiveMainTab(`chat`),e.mobileVariant&&e.setSessionSwitcherOpen(!1),e.openNewSessionDraft({directoryOverride:r.normalizedPath})},t[17]=r.normalizedPath,t[18]=l,t[19]=e,t[20]=T):T=t[20];let E=vt(T),D;t[21]!==l||t[22]!==e?(D=()=>{e.isActiveProject||e.setActiveProjectIdOnly(l),e.setActiveMainTab(`chat`),e.openNewWorktreeDialog()},t[21]=l,t[22]=e,t[23]=D):D=t[23];let O=vt(D),k;t[24]!==l||t[25]!==e?(k=()=>e.syncProjectSessions(l),t[24]=l,t[25]=e,t[26]=k):k=t[26];let A=vt(k),j;t[27]!==l||t[28]!==e?(j=()=>e.openProjectEditDialog(l),t[27]=l,t[28]=e,t[29]=j):j=t[29];let M=vt(j),N;t[30]!==l||t[31]!==e?(N=()=>e.removeProject(l),t[30]=l,t[31]=e,t[32]=N):N=t[32];let P=vt(N),F;t[33]!==l||t[34]!==e.projectHeaderSentinelRefs.current?(F=t=>{e.projectHeaderSentinelRefs.current.set(l,t)},t[33]=l,t[34]=e.projectHeaderSentinelRefs.current,t[35]=F):F=t[35];let I=vt(F),L;t[36]!==c||t[37]!==S||t[38]!==r.normalizedPath||t[39]!==l||t[40]!==e||t[41]!==b?(L=t=>{if(c)return;let{active:n,over:i}=t;if(!i||n.id===i.id)return;let a=S.findIndex(e=>e.id===n.id),o=S.findIndex(e=>e.id===i.id);if(a===-1||o===-1||a===o)return;let s=Uo(S,a,o).map(Ly),u=b?[b.id,...s]:s,d=new Map(S.map(Ry));Rt.getState().setWorktreeOrder(l,r.normalizedPath,s.flatMap(e=>{let t=d.get(e);return t?.worktree&&t.directory?[t.directory]:[]})),e.setGroupOrderByProject(e=>new Map(e).set(l,u))},t[36]=c,t[37]=S,t[38]=r.normalizedPath,t[39]=l,t[40]=e,t[41]=b,t[42]=L):L=t[42];let R=vt(L),z;t[43]!==l||t[44]!==o||t[45]!==b||t[46]!==s?(z=b?o(b,`${l}:${b.id}`,l,!0,null,void 0,s):null,t[43]=l,t[44]=o,t[45]=b,t[46]=s,t[47]=z):z=t[47];let B;t[48]===S?B=t[49]:(B=S.map(zy),t[48]=S,t[49]=B);let V;if(t[50]!==c||t[51]!==S||t[52]!==l||t[53]!==o||t[54]!==s){let e;t[56]!==c||t[57]!==l||t[58]!==o||t[59]!==s?(e=e=>(0,$.jsx)(Ey,{id:e.id,disabled:c,children:t=>o(e,`${l}:${e.id}`,l,!1,t,void 0,s)},e.id),t[56]=c,t[57]=l,t[58]=o,t[59]=s,t[60]=e):e=t[60],V=S.map(e),t[50]=c,t[51]=S,t[52]=l,t[53]=o,t[54]=s,t[55]=V}else V=t[55];let ee;t[61]!==B||t[62]!==V?(ee=(0,$.jsx)(Ko,{items:B,strategy:Go,children:V}),t[61]=B,t[62]=V,t[63]=ee):ee=t[63];let H;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(Lo,{dropAnimation:null}),t[64]=H):H=t[64];let ne;t[65]!==v||t[66]!==R||t[67]!==z||t[68]!==ee?(ne=(0,$.jsxs)(zo,{sensors:v,collisionDetection:Io,onDragEnd:R,children:[z,ee,H]}),t[65]=v,t[66]=R,t[67]=z,t[68]=ee,t[69]=ne):ne=t[69];let re=ne,U=e.projectSortOrder!==`manual`,ie;t[70]===r.normalizedPath?ie=t[71]:(ie=Ot(r.normalizedPath)||r.normalizedPath,t[70]=r.normalizedPath,t[71]=ie);let ae;t[72]!==r.normalizedPath||t[73]!==e.homeDirectory?(ae=St(r.normalizedPath,e.homeDirectory),t[72]=r.normalizedPath,t[73]=e.homeDirectory,t[74]=ae):ae=t[74];let W=h||_,oe=e.projectReorderEnabled??!1,se=!a,ce=a||void 0,G;t[75]!==re||t[76]!==h||t[77]!==i.length||t[78]!==n?(G=(0,$.jsx)(`div`,{className:`space-y-0 pt-0 pb-0.5`,children:i.length>0?re:h?(0,$.jsx)(`div`,{className:`box-border w-full py-1.5 text-left typography-ui-label font-normal text-muted-foreground/80 animate-pulse select-none`,style:{paddingLeft:$a(1)},role:`status`,"aria-live":`polite`,children:n(`sessions.sidebar.project.loadingSessions`)}):(0,$.jsx)(`div`,{className:Ua,children:n(`sessions.sidebar.empty.noSessions.title`)})}),t[75]=re,t[76]=h,t[77]=i.length,t[78]=n,t[79]=G):G=t[79];let le;t[80]!==ce||t[81]!==G?(le=(0,$.jsx)(Jc,{"data-sidebar-collapse":!0,className:`h-[var(--collapsible-panel-height)] transition-[height] duration-200 ease-out data-[starting-style]:h-0 data-[ending-style]:h-0 data-[open]:animate-none data-[closed]:animate-none motion-reduce:transition-none`,inert:ce,children:G}),t[80]=ce,t[81]=G,t[82]=le):le=t[82];let ue;t[83]!==se||t[84]!==le?(ue=(0,$.jsx)(Xc,{open:se,children:le}),t[83]=se,t[84]=le,t[85]=ue):ue=t[85];let de;return t[86]!==a||t[87]!==P||t[88]!==E||t[89]!==O||t[90]!==M||t[91]!==A||t[92]!==w||t[93]!==r.color||t[94]!==r.icon||t[95]!==r.iconImage||t[96]!==l||t[97]!==e.alwaysShowActions||t[98]!==e.hideDirectoryControls||t[99]!==e.isActiveProject||t[100]!==e.isDesktopShellRuntime||t[101]!==e.isRepo||t[102]!==e.isStuck||t[103]!==e.mobileVariant||t[104]!==e.openSidebarMenuKey||t[105]!==e.setOpenSidebarMenuKey||t[106]!==I||t[107]!==U||t[108]!==ie||t[109]!==ae||t[110]!==W||t[111]!==oe||t[112]!==ue?(de=(0,$.jsx)(Ty,{id:l,disabled:U,projectLabel:ie,projectDescription:ae,projectIcon:r.icon,projectColor:r.color,projectIconImage:r.iconImage,isCollapsed:a,isActiveProject:e.isActiveProject,isSessionsLoading:W,isRepo:e.isRepo,isDesktopShell:e.isDesktopShellRuntime,isStuck:e.isStuck,hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,onToggle:w,onNewSession:E,onNewWorktreeSession:O,onSyncSessions:A,onRenameStart:M,onClose:P,sentinelRef:I,showCreateButtons:!0,openSidebarMenuKey:e.openSidebarMenuKey,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,reorderEnabled:oe,children:ue}),t[86]=a,t[87]=P,t[88]=E,t[89]=O,t[90]=M,t[91]=A,t[92]=w,t[93]=r.color,t[94]=r.icon,t[95]=r.iconImage,t[96]=l,t[97]=e.alwaysShowActions,t[98]=e.hideDirectoryControls,t[99]=e.isActiveProject,t[100]=e.isDesktopShellRuntime,t[101]=e.isRepo,t[102]=e.isStuck,t[103]=e.mobileVariant,t[104]=e.openSidebarMenuKey,t[105]=e.setOpenSidebarMenuKey,t[106]=I,t[107]=U,t[108]=ie,t[109]=ae,t[110]=W,t[111]=oe,t[112]=ue,t[113]=de):de=t[113],de});function Fy(e){let t=I(e.path);return t?[t]:[]}function Iy(e){return e.isMain}function Ly(e){return e.id}function Ry(e){return[e.id,e]}function zy(e){return e.id}function By(e){if(typeof e!=`number`||!Number.isFinite(e))return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toLocaleString(Mt(),{month:`short`})} ${t.getDate()}, ${t.getFullYear()}, ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function Vy(e){if(e.info.role===`user`)return``;let t=typeof e.info.providerID==`string`?e.info.providerID.trim():``,n=typeof e.info.modelID==`string`?e.info.modelID.trim():``;return t&&n?`${t}/${n}`:n||t}function Hy(e){let t=e.info.role===`user`?`User`:`Assistant`,n=By(e.info.time?.created),r=Vy(e),i=n&&r?`${n} (${r})`:n||r;return i?`**${t}**\n\n*${i}*`:`**${t}**`}function Uy(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(``)}function Wy(e){let t=Hy(e),n=Uy(e.parts).trim();return n?`${t}\n\n${n}`:``}function Gy(e,t){let n=`#`.repeat(Math.min(t+1,6)),r=e.agent?` — ${e.agent}`:``,i=[`${n} Sub-agent: ${e.title}${r}\n\n---\n\n`+e.records.map(Wy).filter(Boolean).join(`
147
147
 
148
148
  ---
149
149
 
150
- `)];for(let n of e.children)i.push(Uy(n,t+1));return i.join(`
150
+ `)];for(let n of e.children)i.push(Gy(n,t+1));return i.join(`
151
151
 
152
152
  ---
153
153
 
154
- `)}function Wy(e,t,n){let r=`# ${t?.trim()||`Session`}\n\n*Exported on ${new Date().toISOString().split(`T`)[0]}*\n\n---\n\n`+e.map(Hy).filter(Boolean).join(`
154
+ `)}function Ky(e,t,n){let r=`# ${t?.trim()||`Session`}\n\n*Exported on ${new Date().toISOString().split(`T`)[0]}*\n\n---\n\n`+e.map(Wy).filter(Boolean).join(`
155
155
 
156
156
  ---
157
157
 
158
- `);if(n&&n.length>0){let e=n.map(e=>Uy(e,1)).join(`
158
+ `);if(n&&n.length>0){let e=n.map(e=>Gy(e,1)).join(`
159
159
 
160
160
  ---
161
161
 
@@ -163,7 +163,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,p as r,t
163
163
 
164
164
  ---
165
165
 
166
- `+e}return r}function Gy(e,t){let n=new Blob([e],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function Ky(e,t){let n=await ie(t,e);if(n)return n;if(!te())return null;try{let n=await g()?.vscode?.saveMarkdown?.({fileName:t,content:e});if(!n||n.saved!==!0)return null;let r=typeof n.path==`string`?n.path.trim():``;return r.length>0?r:null}catch{return null}}async function qy(e){let t=g()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await M(e)?!0:V(e)}function Jy(){return Mt()}function Yy(e){return`${(e?.trim()||`session`).normalize(`NFKC`).toLowerCase().replace(/[^\p{L}\p{N}]+/gu,`-`).replace(/^-+|-+$/g,``).slice(0,60)||`session`}-${new Date().toISOString().split(`T`)[0]}.md`}var Xy=(e,t)=>{if(!t)return Array.from(e);let n=[],r=new Set;for(let i of e){r.has(i)||(r.add(i),n.push(i));let e=t.get(i);if(e)for(let t of e)r.has(t)||(r.add(t),n.push(t))}return n},Zy=G()((e,t)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{t().enabled||e({enabled:!0})},disable:()=>{e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{t().enabled?e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):e({enabled:!0})},toggleSelected:(n,r,i)=>{let a=t(),o=new Set(a.selectedIds),s=a.scopeKey,c=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(o.clear(),s=r,c=null):s===null&&r!==null&&(s=r);let l=i&&i.length>0?[n,...i]:[n];if(o.has(n)){for(let e of l)o.delete(e);c===n&&(c=null)}else{for(let e of l)o.add(e);c=n}o.size===0?e({selectedIds:o,scopeKey:null,anchorId:null}):e({selectedIds:o,scopeKey:s,anchorId:c})},setRange:(n,r,i,a,o)=>{let s=t();if(i.length===0)return;let c=n&&i.includes(n)?n:i[0],l=i.indexOf(c),u=i.indexOf(r);if(l<0||u<0)return;let[d,f]=l<=u?[l,u]:[u,l],p=Xy(i.slice(d,f+1),o),m=a!==null&&s.scopeKey!==null&&a!==s.scopeKey?new Set:new Set(s.selectedIds);for(let e of p)m.add(e);e({selectedIds:m,scopeKey:a??s.scopeKey,anchorId:c})},replaceAll:(t,n)=>{if(t.length===0){e({selectedIds:new Set,scopeKey:null,anchorId:null});return}e({selectedIds:new Set(t),scopeKey:n,anchorId:t[0]??null})},clear:()=>{e({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{let r=t();if(r.selectedIds.size===0||n.length===0)return;let i=new Set(r.selectedIds);for(let e of n)i.delete(e);i.size!==r.selectedIds.size&&(i.size===0?e({selectedIds:i,scopeKey:null,anchorId:null}):e({selectedIds:i}))}})),Qy=!1,$y=new Set,eb=!1;function tb(){for(let e of $y)e()}function nb(e){Qy!==e&&(Qy=e,tb())}function rb(e){e.key===`Shift`&&nb(!0)}function ib(e){e.key===`Shift`&&nb(!1)}function ab(){nb(!1)}function ob(){eb||typeof window>`u`||(eb=!0,window.addEventListener(`keydown`,rb),window.addEventListener(`keyup`,ib),window.addEventListener(`blur`,ab))}function sb(e){return ob(),$y.add(e),()=>{$y.delete(e)}}function cb(){return Qy}function lb(){return!1}function ub(){return(0,Q.useSyncExternalStore)(sb,cb,lb)}var db=!1,fb=!1,pb=new Set;function mb(){pb.forEach(e=>e())}function hb(e){db!==e&&(db=e,mb())}function gb(e){return Ot()?e.key===`Meta`:e.key===`Control`}var _b=(({setVisible:e,schedule:t=(e,t)=>setTimeout(e,t),cancel:n=e=>clearTimeout(e)})=>{let r=!1,i=null,a=()=>{i!==null&&(n(i),i=null)};return{press(){r||(r=!0,a(),i=t(()=>{i=null,r&&e(!0)},500))},release(){r=!1,a(),e(!1)}}})({setVisible:hb});function vb(e){gb(e)&&_b.press()}function yb(){_b.release()}function bb(e){gb(e)&&yb()}function xb(){document.visibilityState!==`visible`&&yb()}function Sb(){fb||typeof window>`u`||(fb=!0,window.addEventListener(`keydown`,vb),window.addEventListener(`keyup`,bb),window.addEventListener(`blur`,yb),document.addEventListener(`visibilitychange`,xb))}function Cb(e){return Sb(),pb.add(e),()=>pb.delete(e)}function wb(){return db}function Tb(){return!1}function Eb(){return(0,Q.useSyncExternalStore)(Cb,wb,Tb)}var Db=(e,t,n)=>{let r=e.session.title?.trim()||e.session.id;return`\n\n--- RESULT ${n+1}: ${r} ---\n${t.trim()}\n--- END RESULT ${n+1} ---`},Ob=(e,t)=>xn.getState().getWorktreeMetadata(e)?.projectDirectory??t,kb=e=>e.type===`assistant`?On(e.content??[]).trim():``,Ab=async e=>{let t=e.directory??void 0,n=Be(e.session.id,t);if(n.length===0&&e.directory){let t=await Le.withDirectory(e.directory,()=>Le.getSdkClient().message.list({sessionID:e.session.id,limit:50})),n=Array.isArray(t.data)?t.data:[];for(let e=n.length-1;e>=0;--e){let t=kb(n[e]);if(t)return t}return``}for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.role===`assistant`)return On(K(r.id,t)).trim()}return``};function jb({session:e,open:t,onOpenChange:n}){let{t:r}=wt(),i=Bt(),a=en(e=>e.activeSessions),o=en(e=>e.archivedSessions),s=Zn(e=>e.providers),c=Zn(e=>e.currentProviderId),l=Zn(e=>e.currentModelId),u=Zn(e=>e.currentAgentName),[d,f]=Q.useState(c??``),[p,m]=Q.useState(l??``),[h,g]=Q.useState(()=>c&&l?[{providerID:c,modelID:l,instanceId:rl()}]:[]),[_,v]=Q.useState(``),[y,b]=Q.useState(u??``),[x,S]=Q.useState([]),[C,w]=Q.useState(!1),T=Q.useMemo(()=>al(e.title),[e.title]),E=Q.useMemo(()=>{let t=new Map;for(let e of i)t.set(e.id,e);for(let e of a)t.set(e.id,e);for(let e of o)t.set(e.id,e);return e.id&&t.set(e.id,e),Array.from(t.values())},[a,o,i,e]);Q.useEffect(()=>{if(!t||!T)return;let n=xn.getState().getDirectoryForSession(e.id),r=Ob(e.id,n),i=E.map(e=>{let t=al(e.title);if(!t||t.groupSlug!==T.groupSlug||t.fusion||(t.runGroup??null)!==(T.runGroup??null))return null;let n=xn.getState().getDirectoryForSession(e.id)??Fn(e),i=Ob(e.id,n);return r&&i&&r!==i?null:{session:e,directory:n,projectDirectory:i}}).filter(e=>e!==null).sort((e,t)=>(e.session.time?.created??0)-(t.session.time?.created??0));S(i)},[E,t,T,e.id]);let D=s.find(e=>e.id===d)?.models.find(e=>e.id===p),O=D?.variants?Object.keys(D.variants):[],k=!!(T&&d&&p&&x.length>0&&!C),A=Q.useCallback(e=>{g([e]),f(e.providerID),m(e.modelID),v(``)},[]),j=h[0]?.displayName||h[0]?.modelID||r(`multirun.fusion.model.placeholder`);return(0,$.jsx)(pr,{open:t,onOpenChange:n,children:(0,$.jsxs)(ur,{className:`max-w-xl overflow-visible`,children:[(0,$.jsxs)(cr,{children:[(0,$.jsx)(dr,{children:r(`multirun.fusion.title`)}),(0,$.jsx)(fr,{children:r(`multirun.fusion.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`max-w-full`,children:(0,$.jsx)(ol,{selectedModels:h,onAdd:A,onUpdate:(e,t)=>A(t),onRemove:()=>{g([]),f(``),m(``),v(``)},maxModels:1,addButtonLabel:j,showChips:!1,addButtonClassName:`h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5`,dropdownSide:`bottom`,dropdownClassName:`w-[min(28rem,calc(100vw-8rem))]`,triggerIcon:d||p?(0,$.jsx)(qi,{modelId:p,providerId:d,className:`h-3.5 w-3.5 mr-1`}):void 0})}),O.length>0?(0,$.jsxs)(na,{value:_||`__default__`,onValueChange:e=>v(e===`__default__`?``:e),children:[(0,$.jsxs)(Zi,{size:`lg`,className:`h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5`,children:[(0,$.jsx)(Z,{name:`brain-ai-3`,className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(oa,{children:e=>e===`__default__`?r(`multirun.modelMultiSelect.variant.default`):e})]}),(0,$.jsxs)($i,{fitContent:!0,portalToBody:!0,children:[(0,$.jsx)(Yi,{value:`__default__`,children:r(`multirun.modelMultiSelect.variant.default`)}),O.map(e=>(0,$.jsx)(Yi,{value:e,children:e},e))]})]}):null,(0,$.jsx)(il,{value:y,onChange:b,portalToBody:!0,className:`h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5`})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground`,children:r(`multirun.fusion.sources.label`,{count:x.length})}),(0,$.jsx)(`div`,{className:`max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1`,children:x.map(e=>{let t=al(e.session.title);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta`,children:[(0,$.jsx)(qi,{modelId:t?.modelID,providerId:t?.providerID,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.session.title||e.session.id}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>S(t=>t.filter(t=>t.session.id!==e.session.id)),className:`text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})})]},e.session.id)})})]}),(0,$.jsxs)(lr,{children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:()=>n(!1),children:r(`multirun.fusion.actions.cancel`)}),(0,$.jsx)(Y,{onClick:async()=>{if(!(!T||!d||!p)){w(!0);try{let e=await Promise.all(x.map(e=>Ab(e))),t=x.map((t,n)=>({source:t,text:e[n]??``})).filter(e=>e.text.trim().length>0);if(t.length===0){X.error(r(`multirun.fusion.toast.noOutputs`));return}let i=x[0]?.projectDirectory??x[0]?.directory??null,a=nl(T.groupSlug,d,p,T.runGroup),[o,s]=await Promise.all([jn(`session.fusion.visible`),jn(`session.fusion.instructions`)]),c=await xn.getState().createSession(a,i,null);if(!c)throw Error(`Failed to create fusion session`);xn.getState().setCurrentSession(c.id,i),n(!1),await Le.sendMessage({id:c.id,providerID:d,modelID:p,variant:_||void 0,agent:y||void 0,text:o,additionalParts:[{text:s,synthetic:!0},...t.map((e,t)=>({text:Db(e.source,e.text,t),synthetic:!0})),{text:`
166
+ `+e}return r}function qy(e,t){let n=new Blob([e],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function Jy(e,t){let n=await ie(t,e);if(n)return n;if(!te())return null;try{let n=await g()?.vscode?.saveMarkdown?.({fileName:t,content:e});if(!n||n.saved!==!0)return null;let r=typeof n.path==`string`?n.path.trim():``;return r.length>0?r:null}catch{return null}}async function Yy(e){let t=g()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await M(e)?!0:V(e)}function Xy(){return Nt()}function Zy(e){return`${(e?.trim()||`session`).normalize(`NFKC`).toLowerCase().replace(/[^\p{L}\p{N}]+/gu,`-`).replace(/^-+|-+$/g,``).slice(0,60)||`session`}-${new Date().toISOString().split(`T`)[0]}.md`}var Qy=(e,t)=>{if(!t)return Array.from(e);let n=[],r=new Set;for(let i of e){r.has(i)||(r.add(i),n.push(i));let e=t.get(i);if(e)for(let t of e)r.has(t)||(r.add(t),n.push(t))}return n},$y=G()((e,t)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{t().enabled||e({enabled:!0})},disable:()=>{e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{t().enabled?e({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):e({enabled:!0})},toggleSelected:(n,r,i)=>{let a=t(),o=new Set(a.selectedIds),s=a.scopeKey,c=a.anchorId;r!==null&&a.scopeKey!==null&&r!==a.scopeKey?(o.clear(),s=r,c=null):s===null&&r!==null&&(s=r);let l=i&&i.length>0?[n,...i]:[n];if(o.has(n)){for(let e of l)o.delete(e);c===n&&(c=null)}else{for(let e of l)o.add(e);c=n}o.size===0?e({selectedIds:o,scopeKey:null,anchorId:null}):e({selectedIds:o,scopeKey:s,anchorId:c})},setRange:(n,r,i,a,o)=>{let s=t();if(i.length===0)return;let c=n&&i.includes(n)?n:i[0],l=i.indexOf(c),u=i.indexOf(r);if(l<0||u<0)return;let[d,f]=l<=u?[l,u]:[u,l],p=Qy(i.slice(d,f+1),o),m=a!==null&&s.scopeKey!==null&&a!==s.scopeKey?new Set:new Set(s.selectedIds);for(let e of p)m.add(e);e({selectedIds:m,scopeKey:a??s.scopeKey,anchorId:c})},replaceAll:(t,n)=>{if(t.length===0){e({selectedIds:new Set,scopeKey:null,anchorId:null});return}e({selectedIds:new Set(t),scopeKey:n,anchorId:t[0]??null})},clear:()=>{e({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{let r=t();if(r.selectedIds.size===0||n.length===0)return;let i=new Set(r.selectedIds);for(let e of n)i.delete(e);i.size!==r.selectedIds.size&&(i.size===0?e({selectedIds:i,scopeKey:null,anchorId:null}):e({selectedIds:i}))}})),eb=!1,tb=new Set,nb=!1;function rb(){for(let e of tb)e()}function ib(e){eb!==e&&(eb=e,rb())}function ab(e){e.key===`Shift`&&ib(!0)}function ob(e){e.key===`Shift`&&ib(!1)}function sb(){ib(!1)}function cb(){nb||typeof window>`u`||(nb=!0,window.addEventListener(`keydown`,ab),window.addEventListener(`keyup`,ob),window.addEventListener(`blur`,sb))}function lb(e){return cb(),tb.add(e),()=>{tb.delete(e)}}function ub(){return eb}function db(){return!1}function fb(){return(0,Q.useSyncExternalStore)(lb,ub,db)}var pb=!1,mb=!1,hb=new Set;function gb(){hb.forEach(e=>e())}function _b(e){pb!==e&&(pb=e,gb())}function vb(e){return kt()?e.key===`Meta`:e.key===`Control`}var yb=(({setVisible:e,schedule:t=(e,t)=>setTimeout(e,t),cancel:n=e=>clearTimeout(e)})=>{let r=!1,i=null,a=()=>{i!==null&&(n(i),i=null)};return{press(){r||(r=!0,a(),i=t(()=>{i=null,r&&e(!0)},500))},release(){r=!1,a(),e(!1)}}})({setVisible:_b});function bb(e){vb(e)&&yb.press()}function xb(){yb.release()}function Sb(e){vb(e)&&xb()}function Cb(){document.visibilityState!==`visible`&&xb()}function wb(){mb||typeof window>`u`||(mb=!0,window.addEventListener(`keydown`,bb),window.addEventListener(`keyup`,Sb),window.addEventListener(`blur`,xb),document.addEventListener(`visibilitychange`,Cb))}function Tb(e){return wb(),hb.add(e),()=>hb.delete(e)}function Eb(){return pb}function Db(){return!1}function Ob(){return(0,Q.useSyncExternalStore)(Tb,Eb,Db)}var kb=(e,t,n)=>{let r=e.session.title?.trim()||e.session.id;return`\n\n--- RESULT ${n+1}: ${r} ---\n${t.trim()}\n--- END RESULT ${n+1} ---`},Ab=(e,t)=>Sn.getState().getWorktreeMetadata(e)?.projectDirectory??t,jb=e=>e.type===`assistant`?kn(e.content??[]).trim():``,Mb=async e=>{let t=e.directory??void 0,n=Be(e.session.id,t);if(n.length===0&&e.directory){let t=await Le.withDirectory(e.directory,()=>Le.getSdkClient().message.list({sessionID:e.session.id,limit:50})),n=Array.isArray(t.data)?t.data:[];for(let e=n.length-1;e>=0;--e){let t=jb(n[e]);if(t)return t}return``}for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.role===`assistant`)return kn(K(r.id,t)).trim()}return``};function Nb({session:e,open:t,onOpenChange:n}){let{t:r}=Tt(),i=Vt(),a=tn(e=>e.activeSessions),o=tn(e=>e.archivedSessions),s=Qn(e=>e.providers),c=Qn(e=>e.currentProviderId),l=Qn(e=>e.currentModelId),u=Qn(e=>e.currentAgentName),[d,f]=Q.useState(c??``),[p,m]=Q.useState(l??``),[h,g]=Q.useState(()=>c&&l?[{providerID:c,modelID:l,instanceId:il()}]:[]),[_,v]=Q.useState(``),[y,b]=Q.useState(u??``),[x,S]=Q.useState([]),[C,w]=Q.useState(!1),T=Q.useMemo(()=>ol(e.title),[e.title]),E=Q.useMemo(()=>{let t=new Map;for(let e of i)t.set(e.id,e);for(let e of a)t.set(e.id,e);for(let e of o)t.set(e.id,e);return e.id&&t.set(e.id,e),Array.from(t.values())},[a,o,i,e]);Q.useEffect(()=>{if(!t||!T)return;let n=Sn.getState().getDirectoryForSession(e.id),r=Ab(e.id,n),i=E.map(e=>{let t=ol(e.title);if(!t||t.groupSlug!==T.groupSlug||t.fusion||(t.runGroup??null)!==(T.runGroup??null))return null;let n=Sn.getState().getDirectoryForSession(e.id)??In(e),i=Ab(e.id,n);return r&&i&&r!==i?null:{session:e,directory:n,projectDirectory:i}}).filter(e=>e!==null).sort((e,t)=>(e.session.time?.created??0)-(t.session.time?.created??0));S(i)},[E,t,T,e.id]);let D=s.find(e=>e.id===d)?.models.find(e=>e.id===p),O=D?.variants?Object.keys(D.variants):[],k=!!(T&&d&&p&&x.length>0&&!C),A=Q.useCallback(e=>{g([e]),f(e.providerID),m(e.modelID),v(``)},[]),j=h[0]?.displayName||h[0]?.modelID||r(`multirun.fusion.model.placeholder`);return(0,$.jsx)(mr,{open:t,onOpenChange:n,children:(0,$.jsxs)(dr,{className:`max-w-xl overflow-visible`,children:[(0,$.jsxs)(lr,{children:[(0,$.jsx)(fr,{children:r(`multirun.fusion.title`)}),(0,$.jsx)(pr,{children:r(`multirun.fusion.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`max-w-full`,children:(0,$.jsx)(sl,{selectedModels:h,onAdd:A,onUpdate:(e,t)=>A(t),onRemove:()=>{g([]),f(``),m(``),v(``)},maxModels:1,addButtonLabel:j,showChips:!1,addButtonClassName:`h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5`,dropdownSide:`bottom`,dropdownClassName:`w-[min(28rem,calc(100vw-8rem))]`,triggerIcon:d||p?(0,$.jsx)(Yi,{modelId:p,providerId:d,className:`h-3.5 w-3.5 mr-1`}):void 0})}),O.length>0?(0,$.jsxs)(ia,{value:_||`__default__`,onValueChange:e=>v(e===`__default__`?``:e),children:[(0,$.jsxs)($i,{size:`lg`,className:`h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5`,children:[(0,$.jsx)(Z,{name:`brain-ai-3`,className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(ca,{children:e=>e===`__default__`?r(`multirun.modelMultiSelect.variant.default`):e})]}),(0,$.jsxs)(ta,{fitContent:!0,portalToBody:!0,children:[(0,$.jsx)(Zi,{value:`__default__`,children:r(`multirun.modelMultiSelect.variant.default`)}),O.map(e=>(0,$.jsx)(Zi,{value:e,children:e},e))]})]}):null,(0,$.jsx)(al,{value:y,onChange:b,portalToBody:!0,className:`h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5`})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-foreground`,children:r(`multirun.fusion.sources.label`,{count:x.length})}),(0,$.jsx)(`div`,{className:`max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1`,children:x.map(e=>{let t=ol(e.session.title);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta`,children:[(0,$.jsx)(Yi,{modelId:t?.modelID,providerId:t?.providerID,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.session.title||e.session.id}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>S(t=>t.filter(t=>t.session.id!==e.session.id)),className:`text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})})]},e.session.id)})})]}),(0,$.jsxs)(ur,{children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:()=>n(!1),children:r(`multirun.fusion.actions.cancel`)}),(0,$.jsx)(Y,{onClick:async()=>{if(!(!T||!d||!p)){w(!0);try{let e=await Promise.all(x.map(e=>Mb(e))),t=x.map((t,n)=>({source:t,text:e[n]??``})).filter(e=>e.text.trim().length>0);if(t.length===0){X.error(r(`multirun.fusion.toast.noOutputs`));return}let i=x[0]?.projectDirectory??x[0]?.directory??null,a=rl(T.groupSlug,d,p,T.runGroup),[o,s]=await Promise.all([Mn(`session.fusion.visible`),Mn(`session.fusion.instructions`)]),c=await Sn.getState().createSession(a,i,null);if(!c)throw Error(`Failed to create fusion session`);Sn.getState().setCurrentSession(c.id,i),n(!1),await Le.sendMessage({id:c.id,providerID:d,modelID:p,variant:_||void 0,agent:y||void 0,text:o,additionalParts:[{text:s,synthetic:!0},...t.map((e,t)=>({text:kb(e.source,e.text,t),synthetic:!0})),{text:`
167
167
 
168
168
  --- FUSION INPUTS END ---
169
- Now write the final fused answer.`,synthetic:!0}],directory:i??Le.getDirectory()})}catch(e){console.error(`[MultiRunFusion] Failed to start fusion`,e),X.error(r(`multirun.fusion.toast.failed`))}finally{w(!1)}}},disabled:!k,children:r(C?`multirun.fusion.actions.starting`:`multirun.fusion.actions.start`)})]})]})})}function Mb(e){let t=(0,fl.c)(13),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=[`yuri-icon`,n].filter(Boolean),t[3]=n,t[4]=i);let a=i.join(` `),o,s,c,l,u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.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`}),s=(0,$.jsx)(`path`,{d:`M9.25 7.25 12 4.5l2.75 2.75`}),c=(0,$.jsx)(`circle`,{cx:`4`,cy:`17.25`,r:`1.55`}),l=(0,$.jsx)(`circle`,{cx:`12`,cy:`17.25`,r:`1.55`}),u=(0,$.jsx)(`circle`,{cx:`20`,cy:`17.25`,r:`1.55`}),t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u):(o=t[5],s=t[6],c=t[7],l=t[8],u=t[9]);let d;return t[10]!==r||t[11]!==a?(d=(0,$.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:sr,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:a,...r,children:[o,s,c,l,u]}),t[10]=r,t[11]=a,t[12]=d):d=t[12],d}var Nb=1/3,Pb=1,Fb=({containerScrollTop:e,containerClientHeight:t,containerScrollHeight:n,rowOffsetFromViewportTop:r})=>{let i=e+(r-t*Nb),a=Math.max(0,n-t);return Math.min(a,Math.max(0,i))},Ib=()=>typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Lb=e=>{let t=e.closest(`.overlay-scrollbar-target`);if(t)return t;let n=e.parentElement;for(;n&&n!==document.body;){let e=window.getComputedStyle(n).overflowY;if(e===`auto`||e===`scroll`||e===`overlay`)return n;n=n.parentElement}return null},Rb=(e,t)=>{let n=Lb(e),r=t?.behavior??Ib();if(!n){e.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:r});return}let i=e.getBoundingClientRect(),a=n.getBoundingClientRect().top+n.clientTop,o=a+n.clientHeight;if(i.top>=a&&i.bottom<=o)return;let s=Fb({containerScrollTop:n.scrollTop,containerClientHeight:n.clientHeight,containerScrollHeight:n.scrollHeight,rowOffsetFromViewportTop:i.top-a});Math.abs(s-n.scrollTop)<Pb||n.scrollTo({top:s,behavior:r})},zb=e(Te(),1),Bb=null,Vb=!1,Hb=(e,t=oi.getState().focus)=>e===null?null:typeof e==`string`?t?.sessionId===e?t:Ti(e):e,Ub=e=>{typeof window>`u`||(e.commitFrame!==null&&window.cancelAnimationFrame(e.commitFrame),e.paintFrame!==null&&window.cancelAnimationFrame(e.paintFrame),e.fallbackTimer!==null&&window.clearTimeout(e.fallbackTimer))},Wb=()=>{Bb&&=(Ub(Bb),null)},Gb=(e,t)=>{Wb(),Mn(!0);let n=Hb(e);if(!n)return;Vb=!0;let r;try{r=Dn(n.sessionId)}finally{Vb=!1}Bb={commit:t,commitFrame:null,fallbackTimer:null,focus:n,intent:r,paintFrame:null,scheduled:!1},(0,zb.flushSync)(()=>{oi.getState().setFocus(n)}),typeof window<`u`&&(Bb.fallbackTimer=window.setTimeout(()=>{Kb(n)},150))},Kb=e=>{let t=Bb,n=Hb(e);if(!t||!hi(t.focus,n)||t.scheduled)return;t.scheduled=!0,typeof window<`u`&&t.fallbackTimer!==null&&(window.clearTimeout(t.fallbackTimer),t.fallbackTimer=null);let r=()=>{Bb===t&&Hn()===t.intent&&(Bb=null,hn(),t.commit())};if(typeof window>`u`){r();return}t.commitFrame=window.requestAnimationFrame(()=>{Bb===t&&Hn()===t.intent&&(t.paintFrame=window.requestAnimationFrame(r))})},qb=e=>{if(Bb)return;let t=oi.getState();t.setFocus(Hb(e,t.focus))};Bn(e=>{if(Vb)return;let t=Bb;if(t?.intent===e)return;t&&Wb();let n=oi.getState();n.setFocus(Hb(e.sessionId,n.focus))});var Jb=e=>{let t=[],n=e=>{e.children.forEach(e=>{t.push(e.session.id),n(e)})};return n(e),t},Yb=Q.memo(function(e){let t=(0,fl.c)(21),{pinned:n,pinLabel:r,buttonSizeClass:i,iconSizeClass:a,onPointerDown:o,onMouseDown:s,onPin:c}=e,l=n?`text-foreground`:`text-muted-foreground`,u;t[0]!==i||t[1]!==l?(u=J(`inline-flex items-center justify-center rounded-md hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,l,i),t[0]=i,t[1]=l,t[2]=u):u=t[2];let d=n?`pushpin-2-fill`:`pushpin-2`,f=!n&&`rotate-45`,p;t[3]!==a||t[4]!==f?(p=J(a,f),t[3]=a,t[4]=f,t[5]=p):p=t[5];let m;t[6]!==d||t[7]!==p?(m=(0,$.jsx)(Z,{name:d,className:p}),t[6]=d,t[7]=p,t[8]=m):m=t[8];let h;t[9]!==s||t[10]!==c||t[11]!==o||t[12]!==r||t[13]!==u||t[14]!==m?(h=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:u,"aria-label":r,onPointerDown:o,onMouseDown:s,onClick:c,onKeyDown:cx,children:m})}),t[9]=s,t[10]=c,t[11]=o,t[12]=r,t[13]=u,t[14]=m,t[15]=h):h=t[15];let g;t[16]===r?g=t[17]:(g=(0,$.jsx)(la,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:r}),t[16]=r,t[17]=g);let _;return t[18]!==h||t[19]!==g?(_=(0,$.jsxs)(da,{children:[h,g]}),t[18]=h,t[19]=g,t[20]=_):_=t[20],_}),Xb=Q.memo(function(e){let t=(0,fl.c)(24),{archiveLabel:n,deleteLabel:r,deleteOnly:i,buttonSizeClass:a,iconSizeClass:o,revealClassName:s,onPointerDown:c,onMouseDown:l,onArchive:u,onDelete:d}=e,f=i!==void 0&&i,p=ub(),m=f||p,h=m?r:n,g;t[0]!==f||t[1]!==u||t[2]!==d||t[3]!==p?(g=e=>{if(f||p||e.shiftKey){d(e);return}u(e)},t[0]=f,t[1]=u,t[2]=d,t[3]=p,t[4]=g):g=t[4];let _=g,v=m?`text-destructive hover:text-destructive hover:bg-[color-mix(in_srgb,var(--status-error)_12%,transparent)]`:`text-muted-foreground hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,y;t[5]!==a||t[6]!==s||t[7]!==v?(y=J(`inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,v,a,s),t[5]=a,t[6]=s,t[7]=v,t[8]=y):y=t[8];let b=m?`delete-bin`:`inbox-archive`,x;t[9]!==o||t[10]!==b?(x=(0,$.jsx)(Z,{name:b,className:o}),t[9]=o,t[10]=b,t[11]=x):x=t[11];let S;t[12]!==_||t[13]!==h||t[14]!==l||t[15]!==c||t[16]!==y||t[17]!==x?(S=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:y,"aria-label":h,onPointerDown:c,onMouseDown:l,onClick:_,onKeyDown:lx,children:x})}),t[12]=_,t[13]=h,t[14]=l,t[15]=c,t[16]=y,t[17]=x,t[18]=S):S=t[18];let C;t[19]===h?C=t[20]:(C=(0,$.jsx)(la,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:h}),t[19]=h,t[20]=C);let w;return t[21]!==S||t[22]!==C?(w=(0,$.jsxs)(da,{children:[S,C]}),t[21]=S,t[22]=C,t[23]=w):w=t[23],w}),Zb=Q.memo(function(e){let t=(0,fl.c)(3),{number:n}=e;if(!Eb())return null;let r=Ot()?`⌘${n}`:`Ctrl+${n}`,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(vi,{"data-sidebar-shortcut-number":n,className:`h-3.5 min-w-0 shrink-0 rounded-full border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] px-1.5 font-sans text-[10px] font-medium tracking-tight text-muted-foreground/65 shadow-none`,"aria-hidden":`true`,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i});function Qb(e){let{t:n}=wt(),{node:r,depth:i=0,groupDirectory:a,projectId:o,archivedBucket:s=!1,pinnedSessionIds:c,expandedParents:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:d,editingId:f,setEditingId:p,editTitle:h,setEditTitle:g,handleSaveEdit:_,handleCancelEdit:v,toggleParent:y,handleSessionSelect:b,handleSessionDoubleClick:x,togglePinnedSession:S,handleShareSession:C,copiedSessionId:w,handleCopyShareUrl:T,handleUnshareSession:E,setOpenSidebarMenuKey:O,renamingFolderId:k,getFoldersForScope:A,getSessionFolderId:M,removeSessionFromFolder:N,addSessionToFolder:P,createFolderAndStartRename:F,openContextPanelTab:L,handleDeleteSession:R,mobileVariant:z,alwaysShowActions:B,renderSessionNode:V,secondaryMeta:ee,renderContext:H=`project`,subtreeContainsActive:ne,subtreeContainsEditing:re,menuOpenSessionId:U,childRenderExtrasFor:ie,liveSessionById:ae,shortcutNumber:W=null}=e,oe=!!ee?.projectLabel,se=!!ee?.branchLabel,ce=Kt(e=>e.displayMode),G=Q.useMemo(()=>te(),[]),le=ce===`minimal`||G,ue=Q.useMemo(()=>D(),[]),ve=Q.useContext(ot),ye=G?`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`,be=G,Se=H===`pinned`&&c.has(r.session.id),we=!Se&&!s&&!z,Te=`h-5 w-5`,Ee=`h-3.5 w-3.5`,De=(we||Se?1:0)+ +!!be+1,Oe=De>=3?`group-hover:pr-18 group-focus-within:pr-18`:De>=2?`group-hover:pr-12 group-focus-within:pr-12`:`group-hover:pr-7 group-focus-within:pr-7`,je=De>=2?`pr-12`:`pr-8`,Me=Q.useRef(!1),Ne=Q.useRef(!1),[K,Pe]=Q.useState(!1),Fe=Q.useRef(f);Fe.current=f;let Le=Q.useRef(null),Re=Q.useRef(_);Re.current=_;let[ze,Be]=Q.useState(h),[He,Ue]=Q.useState(null),We=Q.useRef(ze);We.current=ze;let Ge=Q.useRef(null),Ke=Q.useRef(null),qe=Q.useRef(null),Je=r.session,Ye=ae.get(Je.id)??Je,Xe=!!Ye.metadata?.yuri?.assistant,q=I(Je.directory??null)??I(a??null),Ze=dn(q??void 0,{bootstrap:!1}),Qe=Wi(),$e=Zy(e=>e.enabled),et=Zy(Q.useMemo(()=>e=>e.selectedIds.has(Je.id),[Je.id])),tt=Zy(e=>e.toggleSelected),nt=Zy(e=>e.setRange),[rt,it]=Q.useState(!1),[at,st]=Q.useState(!0),[ct,lt]=Q.useState(!1),[ut,dt]=Q.useState(!1),ft=`${H}:${s?`archived`:`active`}:${Je.id}`,pt=Vt(Q.useMemo(()=>e=>!!e.sessionMemoryState.get(Xn(Je.id))?.isZombie,[Je.id])),mt=Tn(Je.id),ht=Cn(Je.id,q??void 0,{bootstrap:!1}),gt=kn(Je.id,q??void 0,{bootstrap:!1}),vt=Q.useMemo(()=>({scope:H,sessionId:Je.id,projectId:o??null}),[o,H,Je.id]),bt=Q.useMemo(()=>_i(vt)??``,[vt]),xt=Q.useRef(null),St=oi(Q.useMemo(()=>e=>hi(e.focus,vt),[vt]));Q.useLayoutEffect(()=>{if(!St)return;let e=xt.current;e&&(z?e.scrollIntoView({block:`nearest`,inline:`nearest`}):Rb(e)),Kb(vt)},[St,z,vt]);let Ct=Ye.title||n(`sessions.sidebar.session.untitled`),Tt=ho(mo(Ye)),Et=Ye.metadata?.yuri?.titleRefresh,Dt=typeof Et?.lastError==`string`?Et.lastError:null,Ot=typeof Et?.failedAt==`number`?Et.failedAt:null;Q.useEffect(()=>{!Dt||Ot===null||(Ue(null),console.warn(`[session-title] generation failed for ${Je.id}: ${Dt}`))},[Je.id,Dt,Ot]),Q.useEffect(()=>{if(He===null)return;if(Ct!==He){Ue(null);return}let e=window.setTimeout(()=>Ue(null),3e4);return()=>window.clearTimeout(e)},[He,Ct]);let kt=r.children.length>0||!!(Ye.hasChildren??Je.hasChildren),At=c.has(Je.id),jt=ft,Mt=u?!0:l.has(jt),Nt=!!Ye.parentID,Pt=H===`pinned`,Ft=fn(Je.id)>0&&!Nt,It=on(Ye)||Date.now(),Lt=Qa(It),Rt=qa(It),[zt,Bt]=Q.useState(!1),Ht=zt,Ut=Q.useMemo(()=>al(Ye.title)!==null,[Ye.title]),[Wt,Gt]=Q.useState(!1),qt=Q.useMemo(()=>Jb(r).length,[r]),Jt=_t(e=>{let t=q??``,n=(Ae()??ke(t,Ze)).getTranscript(Ie(t,e)),r=Ze.getState().session.find(t=>t.id===e)?.revert?.messageID;return Qt({sessionID:e,messages:Ve(n),parts:n.partsByMessageID,revertMessageID:r}).list}),Yt=_t(async e=>{let t=[],r=0;for(let i of e)try{await Qe.ensureSessionRenderable(i.session.id);let e=Jt(i.session.id),a=i.session.title||n(`sessions.sidebar.session.export.untitledSubagent`),o=i.session.agent,s=await Yt(i.children);r+=s.skipped,t.push({title:a,agent:o,records:e,children:s.children})}catch{r+=Jb(i).length+1}return{children:t,skipped:r}}),Xt=_t(e=>{e<=0||X.warning(n(e===1?`sessions.sidebar.session.export.skippedSubtaskSingle`:`sessions.sidebar.session.export.skippedSubtaskMany`,{count:e}))}),Zt=_t(async e=>{if(!q){X.error(n(`sessions.sidebar.session.export.nothingToExport`));return}await Qe.ensureSessionRenderable(Je.id);let t=Jt(Je.id);if(t.length===0){X.error(n(`sessions.sidebar.session.export.nothingToExport`));return}let i,a=0;if(e&&r.children.length>0){let e=await Yt(r.children);i=e.children,a=e.skipped}let o=Wy(t,Ye.title??null,i),s=Yy(Ye.title??null),c=await Ky(o,s);if(c){X.success(n(`sessions.sidebar.session.export.success`),{action:{label:n(Jy()),onClick:()=>{qy(c).then(e=>{e||X.error(n(`sessions.sidebar.session.export.failedRevealPath`))})}}}),Xt(a);return}Gy(o,s),X.success(n(`sessions.sidebar.session.export.success`)),Xt(a)}),$t=_t(async()=>{if(r.children.length>0){st(!0),it(!0);return}await Zt(!1)}),en=_t(()=>{q&&j(`desktop_open_session_mini_chat_window`,{sessionId:Je.id,directory:q,apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[session-sidebar] failed to open mini chat window`,e)})});yt(Ke,()=>{Re.current(We.current)},f===Je.id),Q.useLayoutEffect(()=>{if(f!==Je.id){Ge.current===Je.id&&(Ge.current=null);return}Ge.current!==Je.id&&(Ge.current=Je.id,Be(h),queueMicrotask(()=>qe.current?.select()))},[f,h,Je.id]);let tn=_t(e=>{if(!e&&Le.current){let{id:e,title:t}=Le.current;Le.current=null,p(e),g(t)}}),nn=_t(e=>{Bt(e)}),rn=_t(e=>{e.preventDefault(),e.stopPropagation()}),an=_t(e=>{e.preventDefault(),e.stopPropagation()}),sn=_t(e=>{e.preventDefault(),e.stopPropagation(),O(null),S(Je.id)}),cn=_t(e=>{e.preventDefault(),e.stopPropagation(),O(null),R(Je,{archivedBucket:s})}),ln=_t(e=>{e.preventDefault(),e.stopPropagation(),O(null),R(Je,{archivedBucket:s,hardDelete:!0,skipConfirm:!0})}),un=_t(e=>{e.preventDefault(),e.stopPropagation(),O(null),S(Je.id)}),pn=_t(()=>{!q||ct||(lt(!0),(async()=>{try{await Qe.refreshSessionTranscript(Je.id,{directory:q}),X.success(n(`sessions.sidebar.session.menu.refreshTranscriptSuccess`))}catch{X.error(n(`sessions.sidebar.session.menu.refreshTranscriptFailed`))}finally{lt(!1)}})())}),mn=_t(e=>{e.preventDefault(),e.stopPropagation()}),hn=_t(e=>{e.preventDefault(),e.stopPropagation()}),gn=_t(e=>{e.preventDefault(),e.stopPropagation(),ve?.vscode?.executeCommand(`yuri.openSessionInEditor`,Je.id,Ct)}),_n=_t(e=>{if(Me.current){Me.current=!1;return}if($e){if(e?.preventDefault(),e?.stopPropagation(),e?.shiftKey){let e=(typeof document<`u`?Array.from(document.querySelectorAll(`[data-session-row]`)):[]).map(e=>e.getAttribute(`data-session-row`)).filter(e=>typeof e==`string`&&e.length>0),t=Zy.getState().anchorId,n=new Map;n.set(Je.id,Jb(r)),nt(t,Je.id,e,q??null,n);return}tt(Je.id,q??null,Jb(r));return}b(Je.id,q,o,H)}),vn=_t(e=>{e.defaultPrevented||e.target?.closest(`button, a, input, [role="menuitem"], [role="menu"]`)||_n(e)}),yn=_t(e=>{(e.button===2||e.button===0&&e.ctrlKey&&!$e)&&(Me.current=!0)}),bn=_t(e=>{Ne.current=e.pointerType===`mouse`,z&&e.pointerType===`touch`&&Pe(!0)}),xn=_t(e=>{z&&e.pointerType===`touch`&&Pe(!1)}),Sn=_t(e=>{e.key!==`Enter`||!Ne.current||(e.preventDefault(),e.stopPropagation(),x(Je.id,Ct))}),wn=_t(e=>{if(_n(e),!Ne.current)return;let t=e.currentTarget;window.requestAnimationFrame(()=>{Ne.current=!0,t.focus({preventScroll:!0})})}),En=_t(()=>{Ne.current=!1}),Dn=_t(e=>{if(!Ne.current)return;let t=e.relatedTarget;if(t instanceof Node&&e.currentTarget.contains(t))return;let n=document.activeElement;!(n instanceof HTMLElement)||!e.currentTarget.contains(n)||(n.blur(),Ne.current=!1)}),On=_t(()=>{!Mt&&!ut&&(dt(!0),Qe.loadChildren(Je.id,q).catch(()=>X.error(n(`sessions.sidebar.session.subsessions.loadFailed`))).finally(()=>dt(!1))),y(jt)});if(f===Je.id){let e=async()=>{Ue(Ct),v();try{await Ln(Je.id)}catch(e){Ue(null),console.warn(`[session-sidebar] failed to request smart title:`,e)}};return(0,$.jsx)(`div`,{className:`group relative my-0.5 flex items-center rounded-lg py-1.5 pr-2`,style:{paddingLeft:Za(i)},children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0`,children:[(0,$.jsxs)(`form`,{ref:Ke,className:`flex w-full items-center gap-2`,onSubmit:e=>{e.preventDefault(),_(ze)},children:[(0,$.jsx)(`input`,{ref:qe,value:ze,onChange:e=>Be(e.target.value),className:`flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground`,autoFocus:!0,placeholder:n(`sessions.sidebar.session.menu.rename`),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Escape`){v();return}}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},"aria-label":n(`sessions.sidebar.session.rename.smartTitle`),title:n(`sessions.sidebar.session.rename.smartTitle`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`ai-generate-2`,className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`submit`,"aria-label":n(`sessions.sidebar.session.rename.save`),title:n(`sessions.sidebar.session.rename.save`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`check`,className:`size-3.5`})})]}),le?null:(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight`,style:{fontSize:`calc(var(--text-ui-label) * 0.85)`},children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[kt&&!Pt&&!Nt?(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center flex-shrink-0`,children:Mt?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,(0,$.jsx)(`span`,{className:`flex-shrink-0`,children:Lt}),oe?(0,$.jsx)(`span`,{className:`truncate`,children:ee?.projectLabel}):null,se?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.branchLabel})]}):null]})})]})},Je.id)}let An=mt,jn=He!==null||Et?.isGenerating===!0,Mn=ht.length,Nn=gt.length>0,Pn=Nn||An||!Nn&&!An&&Ft,Fn=!B||G,In=Nn?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.questionRequired`),title:n(`sessions.sidebar.session.status.questionRequired`),children:(0,$.jsx)(Z,{name:`question`,className:`h-3.5 w-3.5 text-primary`})}):An?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.active`),title:n(`sessions.sidebar.session.status.active`),children:(0,$.jsx)(Bc,{})}):(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.unread`),title:n(`sessions.sidebar.session.status.unread`),children:(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-[var(--status-info)]`})}),Rn=!Pt&&!Nt&&kt,zn=Rn&&!B&&!ut,Bn=Za(Math.max(0,i-1)),Vn=Rn?(0,$.jsx)(`span`,{role:`button`,tabIndex:0,"aria-expanded":Mt,"aria-busy":ut,onClick:e=>{e.stopPropagation(),e.currentTarget.blur(),On()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),On())},style:{minWidth:14,minHeight:14,left:Bn},className:J(`absolute inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity`,le?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,zn?`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":n(Mt?`sessions.sidebar.session.subsessions.collapse`:`sessions.sidebar.session.subsessions.expand`),children:ut?(0,$.jsx)(Bc,{size:12}):Mt?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,Hn=pt?(0,$.jsx)(Z,{name:`error-warning`,className:`h-4 w-4 text-status-warning`}):null,Un=(0,$.jsx)(pe,{children:(0,$.jsx)(ge,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(me,{"data-slot":`dropdown-menu-content`,finalFocus:()=>!(k||Fe.current),style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:J(oo,`min-w-[180px]`),children:(({Item:e,Separator:t,Sub:r,SubTrigger:i,SubContent:a})=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(e,{onClick:()=>{Le.current={id:Je.id,title:Ct}},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`pencil-ai`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.rename`)]}),(0,$.jsxs)(e,{onClick:()=>S(Je.id),className:`[&>svg]:mr-1`,children:[At?(0,$.jsx)(Z,{name:`unpin`,className:`mr-1 h-4 w-4`}):(0,$.jsx)(Z,{name:`pushpin`,className:`mr-1 h-4 w-4`}),n(At?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`)]}),er()&&!Ye.share?(0,$.jsxs)(e,{onClick:()=>C(Ye),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`share-2`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.share`)]}):er()&&Ye.share?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onClick:()=>{Ye.share?.url&&T(Ye.share.url,Je.id)},className:`[&>svg]:mr-1`,children:w===Je.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{name:`check`,className:`mr-1 h-4 w-4`,style:{color:`var(--status-success)`}}),n(`sessions.sidebar.session.menu.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.copyLink`)]})}),(0,$.jsxs)(e,{onClick:()=>E(Je.id),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`link-unlink-m`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.unshare`)]})]}):null,(0,$.jsxs)(e,{onClick:()=>{$t()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`download`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.exportMarkdown`)]}),(0,$.jsxs)(e,{disabled:!q||ct,onClick:()=>{pn()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`refresh`,className:J(`mr-1 h-4 w-4`,ct&&`animate-spin`)}),n(`sessions.sidebar.session.menu.refreshTranscript`)]}),Ut?(0,$.jsxs)(e,{onClick:()=>Gt(!0),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Mb,{className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.runFusion`)]}):null,q&&!s?(()=>{let o=A(q),s=M(q,Je.id);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(t,{}),(0,$.jsxs)(r,{children:[(0,$.jsxs)(i,{className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`folder`,className:`h-4 w-4`}),n(`sessions.sidebar.folders.moveToFolder`)]}),(0,$.jsxs)(a,{className:`min-w-[180px]`,children:[o.length===0?(0,$.jsx)(e,{disabled:!0,className:`text-muted-foreground`,children:n(`sessions.sidebar.folders.none`)}):o.map(t=>(0,$.jsxs)(e,{onClick:()=>{s===t.id?N(q,Je.id):P(q,t.id,Je.id)},children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),s===t.id?(0,$.jsx)(Z,{name:`check`,className:`ml-2 h-3.5 w-3.5 text-primary flex-shrink-0`}):null]},t.id)),(0,$.jsx)(t,{}),(0,$.jsxs)(e,{onClick:()=>{let e=F(q);e&&P(q,e.id,Je.id)},children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.newFolderEllipsis`)]}),s?(0,$.jsxs)(e,{onClick:()=>{N(q,Je.id)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]})]})})():null,G?null:(0,$.jsxs)(e,{disabled:!q,onClick:()=>{q&&L(q,{mode:`chat`,dedupeKey:`session:${Je.id}`,label:Ct,sessionTitleFallback:Ct})},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`chat-thread`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`sessions.sidebar.session.menu.openInSidePanel`)}),(0,$.jsx)(`span`,{className:`shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10`,children:n(`sessions.sidebar.session.menu.betaBadge`)})]}),ue?(0,$.jsxs)(e,{disabled:!q,onClick:en,className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`window`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`sessions.sidebar.session.menu.openMiniChatWindow`)})]}):null,(0,$.jsx)(t,{}),s?null:(0,$.jsxs)(e,{className:`[&>svg]:mr-1`,onClick:()=>R(Je,{archivedBucket:s}),children:[(0,$.jsx)(Z,{name:`inbox-archive`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.bulkActions.archive`)]}),(0,$.jsxs)(e,{className:`text-destructive focus:text-destructive [&>svg]:mr-1`,onClick:()=>R(Je,{archivedBucket:s,hardDelete:!0}),children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.bulkActions.delete`)]})]}))({Item:({className:e,...t})=>(0,$.jsx)(he,{className:J(co,e),...t}),Separator:({className:e,...t})=>(0,$.jsx)(de,{className:J(so,e),...t}),Sub:Ce,SubTrigger:({className:e,children:t,...n})=>(0,$.jsxs)(fe,{className:J(ao,e),...n,children:[t,(0,$.jsx)(Z,{name:`arrow-right-s`,className:`ml-auto size-3.5`})]}),SubContent:({className:e,children:t,...n})=>(0,$.jsx)(pe,{children:(0,$.jsx)(ge,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(me,{"data-slot":`dropdown-menu-sub-content`,style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:J(oo,e),...n,children:t})})})})})})});return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(Pc,{sessionId:Je.id,sessionDirectory:q??null,sessionTitle:Ct,children:(0,$.jsxs)(_e,{open:zt,onOpenChange:nn,onOpenChangeComplete:tn,children:[(0,$.jsxs)(xe,{render:(0,$.jsx)(`div`,{ref:xt,"data-session-row":Je.id,"data-session-scope":q??``,"data-session-focus-scope":H,"data-session-focus-key":bt,"data-session-project-id":o??``,"data-session-archived":s?`1`:`0`,"data-session-depth":i,onClick:vn,onMouseLeave:Dn,className:J(`group relative my-0.5 flex cursor-pointer items-center rounded-lg py-1.5 pr-2`,St&&!et&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,et&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,!St&&!et&&`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_3.5%,transparent)] dark:hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`)}),children:[Vn,(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,style:{paddingLeft:Za(i)},children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onPointerDown:bn,onPointerUp:xn,onPointerCancel:xn,onMouseDown:yn,onKeyDown:Sn,onBlur:En,onClick:wn,onDoubleClick:e=>{e.stopPropagation(),x(Je.id,Ct)},className:J(`relative flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none has-[[data-sidebar-shortcut-number]]:!pr-0`,K&&`bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,B?G?Oe:je:Oe),children:(0,$.jsxs)(`div`,{className:`flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden`,children:[(0,$.jsx)(`div`,{className:J(`block min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground`,jn&&`animate-text-shimmer`),"aria-busy":jn||void 0,children:Ca(Ct,d)}),Tt?(0,$.jsx)(`span`,{className:`shrink-0 typography-micro tabular-nums text-muted-foreground`,children:Tt}):null,Xe?(0,$.jsx)(Z,{name:`ai-agent`,className:`size-3 shrink-0 text-muted-foreground`,"aria-label":`Assistant`}):null,Mn>0?(0,$.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:n(`sessions.sidebar.session.status.permissionRequired`),"aria-label":n(`sessions.sidebar.session.status.permissionRequired`),children:[(0,$.jsx)(Z,{name:`shield`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`leading-none`,children:Mn})]}):null,Pn?(0,$.jsx)(`span`,{className:J(`inline-flex shrink-0 items-center justify-center transition-none`,Fn?J(`group-hover:hidden group-focus-within:hidden`,Ht?`hidden`:``):Ht?`invisible`:``),children:In}):null,W?(0,$.jsx)(Zb,{number:W}):null]})})}),G?null:(0,$.jsx)(la,{side:`right`,align:`start`,sideOffset:8,className:`w-64 max-w-[min(16rem,calc(100vw-2rem))] px-3 py-2.5 text-left shadow-md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-left`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 break-words typography-ui-label font-medium text-foreground`,children:Ct}),(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:Rt})]}),oe?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`folder-open`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.projectLabel})]}):null,se?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.branchLabel})]}):null]})})]})})}),Hn&&!z?(0,$.jsx)(`div`,{className:J(`absolute top-1/2 -translate-y-1/2 z-10`,le?`right-0`:`right-[30px]`),children:Hn}):null,(0,$.jsxs)(`div`,{className:J(`absolute right-1 top-1/2 z-10 flex -translate-y-1/2 items-center gap-1 transition-none group-has-[[data-sidebar-shortcut-number]]:hidden`,Ht||B&&!G?`opacity-100`:J(`opacity-0`,ye)),children:[we?(0,$.jsx)(Yb,{pinned:At,pinLabel:n(At?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`),buttonSizeClass:Te,iconSizeClass:Ee,onPointerDown:rn,onMouseDown:an,onPin:sn}):null,Se?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`inline-flex items-center justify-center rounded-md text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,Te),"aria-label":n(`sessions.sidebar.session.actions.pinned`),onPointerDown:rn,onMouseDown:an,onClick:un,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(Z,{name:`pushpin-2-fill`,className:Ee})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n(`sessions.sidebar.session.actions.pinned`)})]}):null,be?(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,Te),"aria-label":n(`sessions.sidebar.session.actions.openInEditor`),onPointerDown:mn,onMouseDown:hn,onClick:gn,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(Z,{name:`external-link`,className:Ee})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n(`sessions.sidebar.session.actions.openInEditor`)})]}):null,(0,$.jsx)(Xb,{archiveLabel:n(`sessions.sidebar.bulkActions.archive`),deleteLabel:n(`sessions.sidebar.bulkActions.delete`),deleteOnly:s===!0,buttonSizeClass:Te,iconSizeClass:Ee,revealClassName:le&&!B&&!Ht?J(`opacity-0`,ye):`opacity-100`,onPointerDown:rn,onMouseDown:an,onArchive:cn,onDelete:ln})]})]}),Un]})}),!Pt&&kt&&Mt?r.children.map(e=>{let t=ie?ie(e):{subtreeContainsActive:ne,subtreeContainsEditing:re,menuOpenSessionId:U,nodeStructureKey:``};return V(e,i+1,q??a,o,s,void 0,H,t)}):null,(0,$.jsx)(pr,{open:rt,onOpenChange:it,children:(0,$.jsxs)(ur,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[(0,$.jsxs)(cr,{children:[(0,$.jsx)(dr,{children:n(`sessions.sidebar.session.export.dialog.title`)}),(0,$.jsx)(fr,{children:n(qt===1?`sessions.sidebar.session.export.dialog.descriptionSingle`:`sessions.sidebar.session.export.dialog.descriptionMany`,{count:qt})})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:at,onChange:e=>st(e.target.checked),className:`h-4 w-4 rounded border-border accent-primary`}),n(`sessions.sidebar.session.export.dialog.includeSubtasks`)]}),(0,$.jsxs)(lr,{children:[(0,$.jsx)(Y,{type:`button`,onClick:()=>it(!1),variant:`outline`,size:`sm`,children:n(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{type:`button`,onClick:()=>{it(!1),Zt(at)},size:`sm`,children:n(`sessions.sidebar.session.export.dialog.confirm`)})]})]})}),Ut?(0,$.jsx)(jb,{session:Ye,open:Wt,onOpenChange:Gt}):null]},Je.id)}var $b=e=>I(e.session.directory??null),ex=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null),tx=e=>{if(!e.openSidebarMenuKey)return null;let t=e.archivedBucket?`archived`:`active`,n=`${e.renderContext??`project`}:${t}:`;return e.openSidebarMenuKey.startsWith(n)?e.openSidebarMenuKey.slice(n.length):null},nx=e=>e.menuOpenSessionId??tx(e),rx=(e,t,n)=>t?n.has(e.node.session.id)?!0:zv(e.node,t):!1,ix=(e,t,n,r,i)=>{if(e.session.id!==t.session.id)return!0;let a=i(e);if(n.has(a)!==r.has(a)||e.children.length!==t.children.length)return!0;for(let a=0;a<e.children.length;a+=1)if(ix(e.children[a],t.children[a],n,r,i))return!0;return!1},ax=(e,t,n,r)=>{if(e.session.id!==t.session.id)return!0;let i=e.session.id,a=n.get(i)??e.session,o=r.get(i)??t.session;if(a!==o&&Lv(a)!==Lv(o)||e.children.length!==t.children.length)return!0;for(let i=0;i<e.children.length;i+=1)if(ax(e.children[i],t.children[i],n,r))return!0;return!1},ox=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;let n=e.archivedBucket?`archived`:`active`,r=t.archivedBucket?`archived`:`active`;return ix(e.node,t.node,e.expandedParents,t.expandedParents,t=>`${e.renderContext??`project`}:${n}:${t.session.id}`)||ix(e.node,t.node,e.expandedParents,t.expandedParents,e=>`${t.renderContext??`project`}:${r}:${e.session.id}`)},sx=Q.memo(Qb,(e,t)=>{if(e.node.session.id!==t.node.session.id||e.depth!==t.depth||e.groupDirectory!==t.groupDirectory||e.projectId!==t.projectId||e.archivedBucket!==t.archivedBucket||(e.renderContext??`project`)!==(t.renderContext??`project`)||e.mobileVariant!==t.mobileVariant||e.alwaysShowActions!==t.alwaysShowActions||e.shortcutNumber!==t.shortcutNumber||e.hasSessionSearchQuery!==t.hasSessionSearchQuery||e.normalizedSessionSearchQuery!==t.normalizedSessionSearchQuery||e.notifyOnSubtasks!==t.notifyOnSubtasks||e.nodeStructureKey!==t.nodeStructureKey||e.node.session.hasChildren!==t.node.session.hasChildren||$b(e.node)!==$b(t.node)||!ex(e.secondaryMeta,t.secondaryMeta)||e.liveSessionById!==t.liveSessionById&&ax(e.node,t.node,e.liveSessionById,t.liveSessionById)||e.pinnedSessionIds!==t.pinnedSessionIds&&ix(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e=>e.session.id)||e.expandedParents!==t.expandedParents&&ox(e,t)||e.currentSessionId!==t.currentSessionId&&(rx(e,e.currentSessionId,e.subtreeContainsActive)||rx(t,t.currentSessionId,t.subtreeContainsActive))||e.editingId!==t.editingId&&(rx(e,e.editingId,e.subtreeContainsEditing)||rx(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(rx(e,e.editingId,e.subtreeContainsEditing)||rx(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(zv(e.node,e.copiedSessionId)||zv(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=nx(e),r=nx(t);if(zv(e.node,n)||zv(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){let n=nx(e),r=nx(t);if(zv(e.node,n)||zv(t.node,r))return!1}return e.setEditingId===t.setEditingId&&e.setEditTitle===t.setEditTitle&&e.handleSaveEdit===t.handleSaveEdit&&e.handleCancelEdit===t.handleCancelEdit&&e.toggleParent===t.toggleParent&&e.handleSessionSelect===t.handleSessionSelect&&e.handleSessionDoubleClick===t.handleSessionDoubleClick&&e.togglePinnedSession===t.togglePinnedSession&&e.handleShareSession===t.handleShareSession&&e.handleCopyShareUrl===t.handleCopyShareUrl&&e.handleUnshareSession===t.handleUnshareSession&&e.setOpenSidebarMenuKey===t.setOpenSidebarMenuKey&&e.getFoldersForScope===t.getFoldersForScope&&e.getSessionFolderId===t.getSessionFolderId&&e.removeSessionFromFolder===t.removeSessionFromFolder&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.openContextPanelTab===t.openContextPanelTab&&e.handleDeleteSession===t.handleDeleteSession&&e.renderSessionNode===t.renderSessionNode});function cx(e){return e.stopPropagation()}function lx(e){return e.stopPropagation()}function ux(e){let t=(0,fl.c)(71),{t:n}=wt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:s}=e,c,l,u,d,f,p,m,h,g,_;if(t[0]!==i||t[1]!==n||t[2]!==r){let e=n(`sessions.sidebar.session.untitled`);d=pr,g=!!r,t[13]===i?_=t[14]:(_=e=>{e||i(null)},t[13]=i,t[14]=_),u=ur,m=!1,h=`max-w-sm gap-5`,l=cr;let a;t[15]!==n||t[16]!==r?.archivedBucket?(a=r?.archivedBucket?n(`sessions.sidebar.dialogs.deleteSession.title`):n(`sessions.sidebar.dialogs.archiveSession.title`),t[15]=n,t[16]=r?.archivedBucket,t[17]=a):a=t[17],t[18]===a?p=t[19]:(p=(0,$.jsx)(dr,{children:a}),t[18]=a,t[19]=p),c=fr,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n(`sessions.sidebar.dialogs.deleteSession.withOneSubtask`,{sessionTitle:r.session.title||e,count:r.descendantCount}):n(`sessions.sidebar.dialogs.deleteSession.withManySubtasks`,{sessionTitle:r.session.title||e,count:r.descendantCount}):r.descendantCount===1?n(`sessions.sidebar.dialogs.archiveSession.withOneSubtask`,{sessionTitle:r.session.title||e,count:r.descendantCount}):n(`sessions.sidebar.dialogs.archiveSession.withManySubtasks`,{sessionTitle:r.session.title||e,count:r.descendantCount}):r?.archivedBucket?n(`sessions.sidebar.dialogs.deleteSession.single`,{sessionTitle:r?.session.title||e}):n(`sessions.sidebar.dialogs.archiveSession.single`,{sessionTitle:r?.session.title||e}),t[0]=i,t[1]=n,t[2]=r,t[3]=c,t[4]=l,t[5]=u,t[6]=d,t[7]=f,t[8]=p,t[9]=m,t[10]=h,t[11]=g,t[12]=_}else c=t[3],l=t[4],u=t[5],d=t[6],f=t[7],p=t[8],m=t[9],h=t[10],g=t[11],_=t[12];let v;t[20]!==c||t[21]!==f?(v=(0,$.jsx)(c,{children:f}),t[20]=c,t[21]=f,t[22]=v):v=t[22];let y;t[23]!==l||t[24]!==p||t[25]!==v?(y=(0,$.jsxs)(l,{children:[p,v]}),t[23]=l,t[24]=p,t[25]=v,t[26]=y):y=t[26];let b;t[27]!==o||t[28]!==a?(b=()=>o(!a),t[27]=o,t[28]=a,t[29]=b):b=t[29];let x=!a,S;t[30]===a?S=t[31]:(S=a?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`h-4 w-4 text-primary`}),t[30]=a,t[31]=S);let C;t[32]===n?C=t[33]:(C=n(`sessions.sidebar.dialogs.neverAsk`),t[32]=n,t[33]=C);let w;t[34]!==S||t[35]!==C||t[36]!==b||t[37]!==x?(w=(0,$.jsxs)(`button`,{type:`button`,onClick:b,className:`inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,"aria-pressed":x,children:[S,C]}),t[34]=S,t[35]=C,t[36]=b,t[37]=x,t[38]=w):w=t[38];let T;t[39]===i?T=t[40]:(T=()=>i(null),t[39]=i,t[40]=T);let E;t[41]===n?E=t[42]:(E=n(`sessions.sidebar.dialogs.cancel`),t[41]=n,t[42]=E);let D;t[43]!==T||t[44]!==E?(D=(0,$.jsx)(`button`,{type:`button`,onClick:T,className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:E}),t[43]=T,t[44]=E,t[45]=D):D=t[45];let O;t[46]===s?O=t[47]:(O=()=>void s(),t[46]=s,t[47]=O);let k;t[48]!==n||t[49]!==r?.archivedBucket?(k=r?.archivedBucket?n(`sessions.sidebar.bulkActions.delete`):n(`sessions.sidebar.bulkActions.archive`),t[48]=n,t[49]=r?.archivedBucket,t[50]=k):k=t[50];let A;t[51]!==O||t[52]!==k?(A=(0,$.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:k}),t[51]=O,t[52]=k,t[53]=A):A=t[53];let j;t[54]!==D||t[55]!==A?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[D,A]}),t[54]=D,t[55]=A,t[56]=j):j=t[56];let M;t[57]!==w||t[58]!==j?(M=(0,$.jsxs)(lr,{className:`w-full sm:items-center sm:justify-between`,children:[w,j]}),t[57]=w,t[58]=j,t[59]=M):M=t[59];let N;t[60]!==u||t[61]!==m||t[62]!==M||t[63]!==h||t[64]!==y?(N=(0,$.jsxs)(u,{showCloseButton:m,className:h,children:[y,M]}),t[60]=u,t[61]=m,t[62]=M,t[63]=h,t[64]=y,t[65]=N):N=t[65];let P;return t[66]!==d||t[67]!==N||t[68]!==g||t[69]!==_?(P=(0,$.jsx)(d,{open:g,onOpenChange:_,children:N}),t[66]=d,t[67]=N,t[68]=g,t[69]=_,t[70]=P):P=t[70],P}function dx(e){let t=(0,fl.c)(57),{t:n}=wt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:s}=e,c=r?.archivedBucket===!0,l=r?.sessionCount??0,u;t[0]!==c||t[1]!==l||t[2]!==n?(u=n(c?l===1?`sessions.sidebar.dialogs.deleteSession.title`:`sessions.sidebar.dialogs.deleteSessions.title`:l===1?`sessions.sidebar.dialogs.archiveSession.title`:`sessions.sidebar.dialogs.archiveSessions.title`),t[0]=c,t[1]=l,t[2]=n,t[3]=u):u=t[3];let d=u,f;t[4]!==c||t[5]!==l||t[6]!==n?(f=n(c?l===1?`sessions.sidebar.dialogs.deleteSessions.singleDescription`:`sessions.sidebar.dialogs.deleteSessions.pluralDescription`:l===1?`sessions.sidebar.dialogs.archiveSessions.singleDescription`:`sessions.sidebar.dialogs.archiveSessions.pluralDescription`,{count:l}),t[4]=c,t[5]=l,t[6]=n,t[7]=f):f=t[7];let p=f,m=!!r,h;t[8]===i?h=t[9]:(h=e=>{e||i(null)},t[8]=i,t[9]=h);let g;t[10]===d?g=t[11]:(g=(0,$.jsx)(dr,{children:d}),t[10]=d,t[11]=g);let _;t[12]===p?_=t[13]:(_=(0,$.jsx)(fr,{children:p}),t[12]=p,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,$.jsxs)(cr,{children:[g,_]}),t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==o||t[18]!==a?(y=()=>o(!a),t[17]=o,t[18]=a,t[19]=y):y=t[19];let b=!a,x;t[20]===a?x=t[21]:(x=a?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`h-4 w-4 text-primary`}),t[20]=a,t[21]=x);let S;t[22]===n?S=t[23]:(S=n(`sessions.sidebar.dialogs.neverAsk`),t[22]=n,t[23]=S);let C;t[24]!==S||t[25]!==y||t[26]!==b||t[27]!==x?(C=(0,$.jsxs)(`button`,{type:`button`,onClick:y,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":b,children:[x,S]}),t[24]=S,t[25]=y,t[26]=b,t[27]=x,t[28]=C):C=t[28];let w;t[29]===i?w=t[30]:(w=()=>i(null),t[29]=i,t[30]=w);let T;t[31]===n?T=t[32]:(T=n(`sessions.sidebar.dialogs.cancel`),t[31]=n,t[32]=T);let E;t[33]!==w||t[34]!==T?(E=(0,$.jsx)(`button`,{type:`button`,onClick:w,className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:T}),t[33]=w,t[34]=T,t[35]=E):E=t[35];let D;t[36]===s?D=t[37]:(D=()=>void s(),t[36]=s,t[37]=D);let O;t[38]!==c||t[39]!==n?(O=n(c?`sessions.sidebar.bulkActions.delete`:`sessions.sidebar.bulkActions.archive`),t[38]=c,t[39]=n,t[40]=O):O=t[40];let k;t[41]!==D||t[42]!==O?(k=(0,$.jsx)(`button`,{type:`button`,onClick:D,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}),t[41]=D,t[42]=O,t[43]=k):k=t[43];let A;t[44]!==E||t[45]!==k?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[E,k]}),t[44]=E,t[45]=k,t[46]=A):A=t[46];let j;t[47]!==C||t[48]!==A?(j=(0,$.jsxs)(lr,{className:`w-full sm:items-center sm:justify-between`,children:[C,A]}),t[47]=C,t[48]=A,t[49]=j):j=t[49];let M;t[50]!==j||t[51]!==v?(M=(0,$.jsxs)(ur,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[v,j]}),t[50]=j,t[51]=v,t[52]=M):M=t[52];let N;return t[53]!==m||t[54]!==M||t[55]!==h?(N=(0,$.jsx)(pr,{open:m,onOpenChange:h,children:M}),t[53]=m,t[54]=M,t[55]=h,t[56]=N):N=t[56],N}function fx(e){let t=(0,fl.c)(36),{t:n}=wt(),{value:r,setValue:i,onConfirm:a}=e,o=!!r,s;t[0]===i?s=t[1]:(s=e=>{e||i(null)},t[0]=i,t[1]=s);let c;t[2]===n?c=t[3]:(c=n(`sessions.sidebar.dialogs.deleteFolder.title`),t[2]=n,t[3]=c);let l;t[4]===c?l=t[5]:(l=(0,$.jsx)(dr,{children:c}),t[4]=c,t[5]=l);let u;t[6]!==n||t[7]!==r?(u=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??``}),t[6]=n,t[7]=r,t[8]=u):u=t[8];let d;t[9]===u?d=t[10]:(d=(0,$.jsx)(fr,{children:u}),t[9]=u,t[10]=d);let f;t[11]!==l||t[12]!==d?(f=(0,$.jsxs)(cr,{children:[l,d]}),t[11]=l,t[12]=d,t[13]=f):f=t[13];let p;t[14]===i?p=t[15]:(p=()=>i(null),t[14]=i,t[15]=p);let m;t[16]===n?m=t[17]:(m=n(`sessions.sidebar.dialogs.cancel`),t[16]=n,t[17]=m);let h;t[18]!==p||t[19]!==m?(h=(0,$.jsx)(`button`,{type:`button`,onClick:p,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:m}),t[18]=p,t[19]=m,t[20]=h):h=t[20];let g;t[21]===n?g=t[22]:(g=n(`sessions.sidebar.bulkActions.delete`),t[21]=n,t[22]=g);let _;t[23]!==a||t[24]!==g?(_=(0,$.jsx)(`button`,{type:`button`,onClick:a,className:`inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50`,children:g}),t[23]=a,t[24]=g,t[25]=_):_=t[25];let v;t[26]!==_||t[27]!==h?(v=(0,$.jsxs)(lr,{children:[h,_]}),t[26]=_,t[27]=h,t[28]=v):v=t[28];let y;t[29]!==v||t[30]!==f?(y=(0,$.jsxs)(ur,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[f,v]}),t[29]=v,t[30]=f,t[31]=y):y=t[31];let b;return t[32]!==o||t[33]!==s||t[34]!==y?(b=(0,$.jsx)(pr,{open:o,onOpenChange:s,children:y}),t[32]=o,t[33]=s,t[34]=y,t[35]=b):b=t[35],b}var px=e=>{let t=(0,fl.c)(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:o,onCreateFolderAndMove:s,onRemoveFromFolder:c,canRemoveFromFolder:l,onDelete:u,onDone:d}=e,{t:f}=wt(),p=!!r&&!a,m;t[0]!==a||t[1]!==f?(m=f(a?`sessions.sidebar.bulkActions.delete`:`sessions.sidebar.bulkActions.archive`),t[0]=a,t[1]=f,t[2]=m):m=t[2];let h=m,g;t[3]!==n||t[4]!==f?(g=f(`sessions.sidebar.bulkActions.selectedCount`,{count:n}),t[3]=n,t[4]=f,t[5]=g):g=t[5];let _;t[6]===g?_=t[7]:(_=(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground whitespace-nowrap`,children:g}),t[6]=g,t[7]=_);let v;t[8]!==p||t[9]!==l||t[10]!==s||t[11]!==o||t[12]!==c||t[13]!==i||t[14]!==f?(v=p?(0,$.jsxs)(Ua,{children:[(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Ka,{asChild:!0,children:(0,$.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":f(`sessions.sidebar.bulkActions.moveToFolder`),children:(0,$.jsx)(Z,{name:`folder`,className:`h-4 w-4`})})})}),(0,$.jsx)(la,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f(`sessions.sidebar.bulkActions.moveToFolder`)})})]}),(0,$.jsxs)(Pa,{align:`end`,className:`min-w-[180px]`,children:[i.length===0?(0,$.jsx)(Da,{disabled:!0,className:`text-muted-foreground`,children:f(`sessions.sidebar.folders.none`)}):i.map(e=>(0,$.jsx)(Da,{onClick:()=>o(e.id),children:(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})},e.id)),(0,$.jsx)(La,{}),(0,$.jsxs)(Da,{onClick:s,children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.newFolderEllipsis`)]}),l?(0,$.jsxs)(Da,{onClick:c,className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]}):null,t[8]=p,t[9]=l,t[10]=s,t[11]=o,t[12]=c,t[13]=i,t[14]=f,t[15]=v):v=t[15];let y;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(y=J(`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`),t[16]=y):y=t[16];let b;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`}),t[17]=b):b=t[17];let x;t[18]!==h||t[19]!==u?(x=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:u,className:y,"aria-label":h,children:b})}),t[18]=h,t[19]=u,t[20]=x):x=t[20];let S;t[21]===h?S=t[22]:(S=(0,$.jsx)(la,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:h})}),t[21]=h,t[22]=S);let C;t[23]!==x||t[24]!==S?(C=(0,$.jsxs)(da,{children:[x,S]}),t[23]=x,t[24]=S,t[25]=C):C=t[25];let w;t[26]===f?w=t[27]:(w=f(`sessions.sidebar.header.actions.exitSelection`),t[26]=f,t[27]=w);let T;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`}),t[28]=T):T=t[28];let E;t[29]!==d||t[30]!==w?(E=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:d,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":w,children:T})}),t[29]=d,t[30]=w,t[31]=E):E=t[31];let D;t[32]===f?D=t[33]:(D=f(`sessions.sidebar.header.actions.exitSelection`),t[32]=f,t[33]=D);let O;t[34]===D?O=t[35]:(O=(0,$.jsx)(la,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:D})}),t[34]=D,t[35]=O);let k;t[36]!==E||t[37]!==O?(k=(0,$.jsxs)(da,{children:[E,O]}),t[36]=E,t[37]=O,t[38]=k):k=t[38];let A;t[39]!==k||t[40]!==v||t[41]!==C?(A=(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[v,C,k]}),t[39]=k,t[40]=v,t[41]=C,t[42]=A):A=t[42];let j;return t[43]!==A||t[44]!==_?(j=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5`,children:[_,A]}),t[43]=A,t[44]=_,t[45]=j):j=t[45],j},mx=e=>{let{t}=wt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,addSessionsToFolder:a,removeSessionsFromFolders:o,createFolderAndStartRename:s,archiveSessions:c,setBulkDeleteConfirm:l}=e,u=Zy(e=>e.enabled),d=Zy(e=>e.selectedIds.size),f=d>0,p=Zy(e=>e.selectedIds),m=Zy(e=>e.scopeKey),h=Q.useCallback(()=>{Zy.getState().toggleMode()},[]),g=Q.useCallback(()=>{Zy.getState().disable()},[]),_=Q.useMemo(()=>{if(!f||typeof document>`u`)return!1;let e=!1,t=!1;for(let n of p){let r=document.querySelectorAll(`[data-session-row="${CSS.escape(n)}"]`);for(let n of r)n.getAttribute(`data-session-archived`)===`1`?t=!0:e=!0}return t&&!e},[f,p]),v=Q.useMemo(()=>{if(m)return m;if(!f||typeof document>`u`)return null;for(let e of p){let t=document.querySelector(`[data-session-row="${CSS.escape(e)}"]`)?.getAttribute(`data-session-scope`);if(t&&t.length>0)return t}return null},[f,p,m]),y=Q.useMemo(()=>v?i[v]??[]:[],[i,v]),b=Q.useMemo(()=>{if(!v||!f)return!1;let e=i[v]??[];for(let t of e)for(let e of t.sessionIds)if(p.has(e))return!0;return!1},[i,v,f,p]),x=Q.useCallback(e=>{!v||!f||a(v,e,Array.from(p))},[a,p,v,f]),S=Q.useCallback(()=>{if(!v||!f)return;let e=s(v);e&&a(v,e.id,Array.from(p))},[a,s,p,v,f]),C=Q.useCallback(()=>{!v||!f||o(v,Array.from(p))},[o,p,v,f]),w=Q.useCallback(async()=>{let e=Array.from(p);if(e.length!==0){if(_)qs({sessionIds:e,message:e.length===1?t(`sessions.sidebar.bulkActions.deletedSingle`,{count:e.length}):t(`sessions.sidebar.bulkActions.deletedPlural`,{count:e.length}),undoLabel:t(`sessions.sidebar.undo`),commitFailedMessage:e.length===1?t(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:e.length}):t(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:e.length})});else{let{archivedIds:n,failedIds:r}=await c(e);n.length>0&&Ys({sessionIds:n,message:n.length===1?t(`sessions.sidebar.bulkActions.archivedSingle`,{count:n.length}):t(`sessions.sidebar.bulkActions.archivedPlural`,{count:n.length}),undoLabel:t(`sessions.sidebar.undo`),settingsLabel:t(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:n.length===1?t(`sessions.sidebar.session.archive.undoFailed`):t(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:n.length})}),r.length>0&&X.error(r.length===1?t(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:r.length}):t(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:r.length}))}Zy.getState().clear()}},[c,_,p,t]),T=Q.useCallback(()=>{if(!f)return;let e=p.size;if(!_||!r){w();return}l({sessionCount:e,archivedBucket:_})},[_,w,p,r,l,f]),E=Q.useCallback(async()=>{l(null),await w()},[w]);return Q.useEffect(()=>{if(!u)return;let e=typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``),t=t=>{if(n)return;let r=t.target;if(r&&(r.tagName===`INPUT`||r.tagName===`TEXTAREA`||r.isContentEditable))return;let i=e?t.metaKey:t.ctrlKey;if(t.key===`Escape`){t.preventDefault(),Zy.getState().disable();return}if(i&&t.key===`Backspace`){t.preventDefault(),T();return}if(i&&(t.key===`a`||t.key===`A`)){let e=typeof document<`u`?Array.from(document.querySelectorAll(`[data-session-row]`)):[];if(e.length===0)return;t.preventDefault();let n=Zy.getState().scopeKey??e[0]?.getAttribute(`data-session-scope`)??null,r=e.filter(e=>!n||e.getAttribute(`data-session-scope`)===n).map(e=>e.getAttribute(`data-session-row`)).filter(e=>typeof e==`string`&&e.length>0);if(r.length===0)return;Zy.getState().replaceAll(r,n||null)}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,n,u]),{selectionModeEnabled:u,hasSelection:f,selectedIdsSize:d,bulkScopeIsArchived:_,derivedSelectionScope:v,bulkScopeFolders:y,bulkCanRemoveFromFolder:b,handleToggleSelectionMode:h,handleExitSelectionMode:g,handleBulkMoveToFolder:x,handleBulkCreateFolderAndMove:S,handleBulkRemoveFromFolder:C,handleBulkDelete:T,confirmBulkDelete:E}},hx=(e,t,n)=>{let r=[],i=new Set,a=e=>{let t=I(e??null);!t||i.has(t)||(i.add(t),r.push(t))};if(a(e),a(n?.workspaceRoot),a(n?.currentDirectory),n?.includeWorktrees!==!1)for(let e of t)a(e.path);return r},gx=(e,t,n,r)=>{let i=e.filter(e=>e.sessionId===t);if(i.length===0)return null;if(n){let e=i.find(e=>e.projectId===n);if(e)return e}if(r){let e=i.find(e=>e.projectId===r);if(e)return e}return i[0]??null},_x=({currentSessionId:e,focus:t,pinnedFocuses:n,projectFocuses:r,fallbackProjectId:i})=>{if(!e)return null;let a=t?.sessionId===e,o=a?t.projectId:null,s=gx(r,e,o,i)??{scope:`project`,sessionId:e,projectId:i};return!a||t.scope===`project`?s:gx(n,e,o,i)??s};function vx(e,t,n=null){if(!e||e.scope!==`project`||!e.sessionId)return null;if(e.projectId){let n=t.find(t=>t.sessionId===e.sessionId&&t.projectId===e.projectId);if(n)return n}if(n){let r=t.find(t=>t.sessionId===e.sessionId&&t.projectId===n);if(r)return r}return t.find(t=>t.sessionId===e.sessionId)??null}var yx=`yuri.sessions.projectCollapse`,bx=`yuri.sessions.groupOrder`,xx=`yuri.sessions.groupCollapse`,Sx=`yuri.sessions.activeSessionByProject`,Cx=`yuri.sessions.expandedParents.v2`,wx=`yuri.sessions.expandedParents`,Tx=w(Qe()),Ex=e=>{try{let t=Tx.getItem(e);if(!t)return new Set;let n=JSON.parse(t);return new Set(Array.isArray(n)?n.filter(e=>typeof e==`string`):[])}catch{return new Set}},Dx=e=>{try{let t=Tx.getItem(e);if(!t)return new Map;let n=JSON.parse(t),r=new Map;return!n||typeof n!=`object`||Array.isArray(n)||Object.entries(n).forEach(([e,t])=>{typeof t==`string`&&t.length>0&&r.set(e,t)}),r}catch{return new Map}},Ox=e=>{try{let t=Tx.getItem(e);if(!t)return new Map;let n=JSON.parse(t),r=new Map;return!n||typeof n!=`object`||Array.isArray(n)||Object.entries(n).forEach(([e,t])=>{Array.isArray(t)&&r.set(e,t.filter(e=>typeof e==`string`))}),r}catch{return new Map}},kx=(e,t,n)=>{let r=new Set;for(let t of e){let e=I(t.path)?.toLowerCase();e&&r.add(e)}if(n?.includeWorktrees===!1)return r;for(let e of t.values())for(let t of e){let e=I(t.path)?.toLowerCase();e&&r.add(e)}return r},Ax=(e,t,n)=>{if(e.time?.archived)return!0;let r=I(Fn(e))?.toLowerCase();return r?t.size===0?n?.allowEmptyDirectorySet??!0:t.has(r):n?.allowUnknownDirectory??!0},jx=3e5,Mx=new Set,Nx=[],Px={},Fx=e=>{let t=Q.useRef(e);return t.current=e,Q.useMemo(()=>(...e)=>t.current(...e),[])},Ix=Q.memo(function(e){let t=(0,fl.c)(3),{onOpenChange:n}=e,r=fs(ue(Rx)),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(ds,{open:!0,onOpenChange:n,...r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}),Lx=Q.memo(function({mobileVariant:e=!1,onSessionSelected:t,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1,isVisible:a=!0}){let{t:o}=wt(),[c,l]=Q.useState(!1),[u,d]=Q.useState(!1),[f,m]=Q.useState(``),h=Q.useRef(null),g=Q.useRef(null),_=Q.useRef(new Set),[v,y]=Q.useState(null),[b,x]=Q.useState(``),[S,C]=Q.useState(null),[w,T]=Q.useState(new Set),E=Q.useMemo(()=>Tx,[]),[D,O]=Q.useState(new Set),[k,A]=Q.useState(new Map),[j,M]=Q.useState(new Map),N=q(e=>e.isNewWorktreeDialogOpen),P=q(e=>e.setNewWorktreeDialogOpen),[L,R]=Q.useState(null),[z,B]=Q.useState(null),[V,ee]=Q.useState(``),[H,ne]=Q.useState(null),[re,U]=Q.useState(null),[ie,ae]=Q.useState(null),W=Gt(),oe=Jt(),[se,ce]=Q.useState(()=>Ex(xx)),[G,le]=Q.useState(()=>Ox(bx)),[ue,de]=Q.useState(()=>Dx(Sx));Q.useEffect(()=>s(e=>{p(e)&&(ce(Ex(xx)),le(Ox(bx)),de(Dx(Sx)),O(Ex(yx)),T(Ex(Cx)))}),[]);let[fe,pe]=Q.useState(new Map),me=Q.useRef(new Map),he=Q.useRef(0),ge=je(e=>e.homeDirectory),_e=je(e=>e.currentDirectory),ve=je(e=>e.setDirectory),ye=An(e=>e.projects),be=An(e=>e.activeProjectId),xe=An(e=>e.removeProject),Se=An(e=>e.setActiveProjectIdOnly),Ce=An(e=>e.updateProjectMeta),we=An(e=>e.reorderProjectsById),Te=q(e=>e.setActiveMainTab),Ee=q(e=>e.activeMainTab),De=Ft(),Oe=q(e=>e.openContextPanelTab),ke=q(e=>e.setSettingsDialogOpen),Ae=q(e=>e.toggleHelpDialog),Me=q(e=>e.setSessionSwitcherOpen),Ne=q(e=>e.setScheduledTasksDialogOpen),K=q(e=>e.notifyOnSubtasks),Pe=q(e=>e.showDeletionDialog),Fe=q(e=>e.setShowDeletionDialog),Ie=wo(f,120),Le=Q.useMemo(()=>Ie.trim().toLowerCase(),[Ie]),Re=Le.length>0,ze=fs(e=>e.available&&(e.runtimeType===`desktop`||e.runtimeType===`web`)),Be=nr(e=>e.collapsedFolderIds),Ve=nr(e=>e.foldersMap),He=nr(e=>e.sessionOrderByScope),Ue=nr(e=>e.sessionOrderActivityByScope),We=nr(e=>e.getFoldersForScope),Ge=nr(e=>e.createFolder),Ke=nr(e=>e.renameFolder),qe=nr(e=>e.deleteFolder),Je=nr(e=>e.addSessionToFolder),Ye=nr(e=>e.addSessionsToFolder),Xe=nr(e=>e.removeSessionFromFolder),Ze=nr(e=>e.removeSessionsFromFolders),Qe=nr(e=>e.toggleFolderCollapse),$e=nr(e=>e.getSessionFolderId),et=nr(e=>e.reorderSessions);D_({isSessionSearchOpen:a&&u,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchContainerRef:h});let tt=Q.useMemo(()=>new Map,[]),nt=Bt({enabled:a,includeChildren:!0}),rt=tc({enabled:a}),it=nc({enabled:a}),ot=pn(e=>a?e.index.session.unseenCount:Px),st=Q.useMemo(()=>te(),[]),ct=en(e=>e.status),lt=en(e=>e.activeSessions),ut=en(e=>e.archivedSessions),dt=en(e=>e.loadingDirectories.size>0||e.refreshingDirectories.size>0),ft=en(e=>e.archivedLoadingDirectories),pt=Q.useDeferredValue(lt),mt=Q.useDeferredValue(ut),ht=xn(e=>e.currentSessionId),gt=oi(e=>e.focus),vt=Q.useSyncExternalStore(Bn,Hn,Hn),yt=xn(e=>!!e.newSessionDraft?.open),bt=xn(e=>e.setCurrentSession),xt=xn(e=>e.updateSessionTitle),St=xn(e=>e.shareSession),Ct=xn(e=>e.unshareSession),Tt=xn(e=>e.worktreeMetadata),Et=xn(e=>e.availableWorktreesByProject),Ot=xn(e=>e.openNewSessionDraft),kt=_t(e=>{Ot(e),st&&window.dispatchEvent(new CustomEvent(`yuri:navigate`,{detail:{view:`chat`}}))}),At=Q.useMemo(()=>kx(ye,Et,{includeWorktrees:!st}),[Et,st,ye]),jt=Q.useMemo(()=>{let e=new Map(nt.map(e=>[e.id,e])),t=pt.map(t=>{let n=e.get(t.id);return n?$t(n,t):t}),n=new Set(t.map(e=>e.id));return nt.forEach(e=>{n.has(e.id)||t.push(e)}),t.filter(e=>Ax(e,At,{allowUnknownDirectory:!st,allowEmptyDirectorySet:!st}))},[pt,st,At,nt]),Mt=Q.useMemo(()=>nt.map(e=>{let t=I(e.directory??null)??``;return`${e.id}:${e.title??``}:${+!!e.time?.archived}:${t}`}).join(`|`),[nt]),Nt=Q.useRef(nt);Q.useEffect(()=>{Nt.current=nt},[Mt,nt]);let Pt=Q.useMemo(()=>new Map(nt.map(e=>[e.id,e])),[nt]);Q.useEffect(()=>{let e=null,t=Qn(t=>{t.type===`scheduled-task-ran`&&(e&&clearTimeout(e),e=setTimeout(()=>{let e=An.getState().projects.find(e=>e.id===t.projectId),n=I(e?.path??null);if(!n)return;let r=[n];(xn.getState().availableWorktreesByProject.get(n)??[]).forEach(e=>{let t=I(e.path);t&&r.push(t)}),zt(r,Nt.current)},500))});return()=>{e&&clearTimeout(e),t()}},[]);let It=Q.useMemo(()=>F(),[]),Lt=ys(e=>e.sidebarBrandName.trim().length>0),{isTablet:Rt}=eo(),Vt=e||Rt,{buildGroupSearchText:Ht,filterSessionNodesForSearch:Wt,buildGroupedSessions:qt}=E_({homeDirectory:ge,worktreeMetadata:Tt,pinnedSessionIds:W,gitBranches:tt,isVSCode:st}),{scheduleCollapsedProjectsPersist:Yt,hasRestoredProjectCollapse:Xt}=P_({isVSCode:st,safeStorage:E,keys:{sessionExpanded:Cx,sessionExpandedLegacy:wx,projectCollapse:yx,groupOrder:bx,projectActiveSession:Sx,groupCollapse:xx},groupOrderByProject:G,activeSessionByProject:ue,collapsedGroups:se,setExpandedParents:T,setCollapsedProjects:O}),Qt=Q.useMemo(()=>[...jt].sort((e,t)=>ja(e,t,W)),[jt,W]),tn=Q.useMemo(()=>{let e=new Map;return Qt.forEach(t=>{let n=t.parentID;if(!n)return;let r=e.get(n)??[];r.push(t),e.set(n,r)}),e.forEach(e=>e.sort((e,t)=>ja(e,t,W))),e},[Qt,W]),nn=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:o(`sessions.sidebar.empty.noSessions.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:o(`sessions.sidebar.empty.noSessions.description`)})]}),rn=Q.useMemo(()=>ye.find(e=>e.id===S)??null,[ye,S]),an=Q.useCallback(e=>{S&&Ce(S,{label:e.label,icon:e.icon,color:e.color,iconBackground:e.iconBackground,defaultModel:e.defaultModel??null})},[S,Ce]),on=Q.useCallback(()=>{P(!0)},[P]),sn=Q.useCallback((t,n)=>{if(Te(`chat`),e&&Me(!1),n?.sessionId){bt(n.sessionId,t);return}Ot({directoryOverride:t,preserveDirectoryOverride:!0})},[e,Ot,Te,bt,Me]),cn=_t(()=>{let e=fs.getState();if(e.available&&e.info){l(!0);return}e.checkForUpdates().then(()=>{let{available:e,error:t}=fs.getState();if(t){X.error(o(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}if(!e){X.success(o(`sessions.sidebar.updateCheck.latestVersion`));return}l(!0)})}),ln=Q.useCallback(()=>{e&&Me(!1),ke(!0)},[e,Me,ke]),un=Q.useCallback(()=>{Te(`chat`),Ot(),e&&Me(!1)},[e,Ot,Te,Me]),dn=Q.useCallback(()=>{if(!e){Te(`schedule`);return}Ne(!0),Me(!1)},[e,Te,Ne,Me]),fn=Q.useCallback(()=>{ar(),e&&Me(!1)},[e,Me]),mn=xn(e=>e.archiveSession),hn=xn(e=>e.archiveSessions),{copiedSessionId:gn,handleSessionSelect:_n,handleSessionDoubleClick:vn,handleSaveEdit:bn,handleCancelEdit:Sn,handleShareSession:Cn,handleCopyShareUrl:wn,handleUnshareSession:Tn,handleDeleteSession:En,confirmDeleteSession:On}=O_({activeProjectId:be,currentDirectory:_e,currentSessionId:ht,mobileVariant:e,allowReselect:n,onSessionSelected:t,isSessionSearchOpen:u,sessionSearchQuery:f,setSessionSearchQuery:m,setIsSessionSearchOpen:d,setActiveProjectIdOnly:Se,setDirectory:ve,setActiveMainTab:Te,setSessionSwitcherOpen:Me,setCurrentSession:bt,updateSessionTitle:xt,shareSession:St,unshareSession:Ct,archiveSession:mn,archiveSessions:hn,childrenMap:tn,showDeletionDialog:Pe,setDeleteSessionConfirm:ne,deleteSessionConfirm:H,setEditingId:y,setEditTitle:x,editingId:v,editTitle:b}),kn=Q.useCallback((e,t,n,r=`project`)=>{let i={sessionId:e,scope:r,projectId:n??null};if(e===ht){Dn(e),qb(i),_n(e,t,n);return}Gb(i,()=>_n(e,t,n))},[_n,ht]);Q.useEffect(()=>()=>{Wb()},[]);let jn=Q.useCallback(()=>{if(!re)return;let{scopeKey:e,folderId:t}=re;U(null),qe(e,t)},[re,qe]);Q.useEffect(()=>{if(!ht)return;let e=jt.find(e=>e.id===ht)?.parentID;if(!e)return;let t=[`project:active:${e}`,`project:archived:${e}`,`recent:active:${e}`,`recent:archived:${e}`];T(e=>{if(t.every(t=>e.has(t)))return e;let n=new Set(e);t.forEach(e=>n.add(e));try{E.setItem(Cx,JSON.stringify(Array.from(n)))}catch{}return n})},[ht,jt,E]);let Mn=Q.useCallback(e=>{T(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{E.setItem(Cx,JSON.stringify(Array.from(n)))}catch{}return n})},[E]),Nn=Q.useCallback((e,t)=>{if(!e)return null;t&&Be.has(t)&&Qe(t);let n=Ge(e,o(`sessions.sidebar.folder.newFolderName`),t);return B(n.id),ee(n.name),n},[Be,Qe,Ge,o]),Pn=_t(kn),Ln=_t(vn),Rn=_t(bn),zn=_t(Sn),Vn=_t(Cn),Un=_t(wn),Wn=_t(Tn),Gn=_t(En),Kn=_t(Nn),qn=_t((e,t,n,r)=>{let i=Ws(),a=Math.max(i,n)+7;if(M(e=>{let r=Math.max(i,e.get(t)??i,n),a=new Map(e);return a.set(t,r+7),a}),e.isArchivedBucket||a<r)return;let o=I(e.directory??null);if(!o)return;let s=en.getState().activePaginationByDirectory.get(o);s?.hasMore&&!s.loadingMore&&Ut(o)}),Jn=_t(e=>{M(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})}),Yn=_t(e=>{M(t=>{let n=!1,r=new Map(t),i=`${e}:`;for(let e of r.keys())e.startsWith(i)&&(r.delete(e),n=!0);return n?r:t})}),Xn=Q.useMemo(()=>e=>{let t=ye.find(t=>t.id===e),n=I(t?.path??null);if(!n)return[];let r=[n];return st||(Et.get(n)??[]).forEach(e=>{let t=I(e.path);t&&r.push(t)}),r},[Et,st,ye]),Zn=_t(e=>{let t=Xn(e);if(t.length===0)return;let n=en.getState().loadedDirectories,r=t.filter(e=>!n.has(e));r.length!==0&&zt(r,Nt.current)}),$n=_t(e=>{let t=ye.find(t=>t.id===e);t&&(async()=>{let e=[];if(!st)try{e=(await aa({id:t.id,path:t.path})).worktrees}catch(n){console.warn(`[SessionSidebar] Worktree refresh before session sync failed:`,n);let r=I(t.path);e=r?xn.getState().availableWorktreesByProject.get(r)??[]:[]}let n=hx(t.path,e,{currentDirectory:_e,workspaceRoot:t.path,includeWorktrees:!st});n.length!==0&&await Zt(n,Nt.current)})()});Q.useEffect(()=>{if(!Xt)return;let e=en.getState(),t=ye.flatMap(t=>D.has(t.id)?[]:Xn(t.id).filter(t=>!e.loadedDirectories.has(t)&&!e.loadingDirectories.has(t)&&!e.refreshingDirectories.has(t)));t.length>0&&zt(t,Nt.current)},[D,Xn,Xt,ye]);let er=_t(()=>{he.current=Date.now()+150,M(new Map),O(()=>{let e=new Set(ye.map(e=>e.id));try{E.setItem(yx,JSON.stringify(Array.from(e)))}catch{}return st||Yt(e),e})}),tr=_t(()=>{he.current=Date.now()+150,M(new Map),O(()=>{let e=new Set;try{E.setItem(yx,JSON.stringify([]))}catch{}return st||Yt(e),e});let e=en.getState().loadedDirectories,t=ye.flatMap(t=>Xn(t.id).filter(t=>!e.has(t)));t.length>0&&zt(t,Nt.current)}),rr=_t(e=>{he.current=Date.now()+150,Yn(e),O(t=>{let n=new Set(t);n.has(e)?(n.delete(e),queueMicrotask(()=>Zn(e))):n.add(e);try{E.setItem(yx,JSON.stringify(Array.from(n)))}catch{}return st||Yt(n),n})}),ir=_t(e=>{he.current=Date.now()+150,Zn(e),O(t=>{if(!t.has(e))return t;let n=new Set(t);n.delete(e);try{E.setItem(yx,JSON.stringify(Array.from(n)))}catch{}return st||Yt(n),n})}),or=Q.useMemo(()=>ye.map(e=>({...e,normalizedPath:I(e.path)})).filter(e=>!!e.normalizedPath),[ye]),sr=Q.useMemo(()=>or.map(e=>e.normalizedPath),[or]),cr=Q.useMemo(()=>{let e=new Set(or.map(e=>e.normalizedPath));if(!st)for(let t of Et.values())for(let n of t){let t=I(n.path);t&&e.add(t)}return[...e].sort()},[Et,st,or]),lr=Q.useRef(null);Q.useEffect(()=>{let e=new Set(cr),t=lr.current;if(lr.current=e,!t)return;let n=cr.filter(e=>!t.has(e));if(n.length===0)return;let r=en.getState().loadedDirectories,i=I(_e),a=or.find(e=>e.id===be)??or.find(e=>e.normalizedPath===i)??null,o=new Set;i&&o.add(i),a?.normalizedPath&&(o.add(a.normalizedPath),st||(Et.get(a.normalizedPath)??[]).forEach(e=>{let t=I(e.path);t&&o.add(t)}));let s=n.filter(e=>o.has(e)&&!r.has(e));s.length!==0&&zt(s,Nt.current)},[be,Et,_e,st,or,cr]);let{github:ur}=at(),dr=_a(),fr=dr.data??null,pr=dr.isFetched,mr=yo(a?sr:Nx),hr=_v(e=>e.ensureEntry),gr=_v(e=>e.setParams),_r=_v(e=>e.refreshTargets);I_({normalizedProjects:or,activeProjectId:be,gitRepoStatus:mr,setProjectRepoStatus:A,setProjectRootBranches:pe,enabled:a});let vr=Q.useMemo(()=>Ts(jt,or,Et,st,mt),[mt,Et,st,or,jt]),{getSessionsForProject:yr,getArchivedSessionsForProject:br}=L_({ownership:vr}),xr=dt||ct===`idle`||ct===`loading`,Sr=Q.useRef(!1);be&&k.has(be)&&(Sr.current=!!k.get(be));let Cr=Kt(e=>e.projectSortOrder),wr=Q.useMemo(()=>_c(or,Cr),[or,Cr]),{projectSections:Tr,groupSearchDataByGroup:Er,sectionsForRender:Dr,searchMatchCount:Or}=C_({normalizedProjects:wr,getSessionsForProject:yr,getArchivedSessionsForProject:br,availableWorktreesByProject:Et,projectRepoStatus:k,projectRootBranches:fe,lastRepoStatus:Sr.current,buildGroupedSessions:qt,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,filterSessionNodesForSearch:Wt,buildGroupSearchText:Ht,foldersMap:Ve}),kr=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:o(`sessions.sidebar.empty.noMatches.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:o(`sessions.sidebar.empty.noMatches.description`)})]});w_({projectSections:Tr,activeProjectId:be,activeSessionByProject:ue,setActiveSessionByProject:de,currentSessionId:ht,handleSessionSelect:_n,newSessionDraftOpen:yt,mobileVariant:e,openNewSessionDraft:Ot,setActiveMainTab:Te,setSessionSwitcherOpen:Me});let{getOrderedGroups:Ar}=T_(G),jr=Q.useRef(!1);Q.useEffect(()=>{if(jr.current||Tr.length===0)return;let e=Tr.flatMap(e=>e.groups.filter(e=>e.isArchivedBucket).map(t=>`${e.project.id}:${t.id}`));e.length>0&&ce(t=>new Set([...t,...e])),jr.current=!0},[Tr]);let Mr=Q.useMemo(()=>{let e=new Map,t=new Map;return Tr.forEach(n=>{let r=Dt(n.project.normalizedPath)||n.project.normalizedPath;n.groups.forEach(i=>{let a=i.branch&&i.branch!==`HEAD`&&i.branch!==r?i.branch:null,o={projectLabel:r,branchLabel:a},s=r=>{r.forEach(r=>{let a=n.project.normalizedPath.length;a<(t.get(r.session.id)??-1)||(e.set(r.session.id,{node:r,projectId:n.project.id,groupDirectory:i.directory,secondaryMeta:o}),t.set(r.session.id,a),r.children.length>0&&s(r.children))})};s(i.sessions)})}),e},[Tr]);Q.useLayoutEffect(()=>{if(!ht){qb(null);return}let e=oi.getState().focus;if(e?.sessionId===ht){e.scope===`project`&&!e.projectId&&qb({...e,projectId:Mr.get(ht)?.projectId??null});return}qb({scope:`project`,sessionId:ht,projectId:Mr.get(ht)?.projectId??null})},[ht,Mr]);let Nr=Q.useMemo(()=>st?[]:Tc(jt,W,He[ic]),[st,W,jt,He]),Pr=_t((e,t)=>{v||et(ic,Nr.map(e=>e.id),e,t,{}).catch(()=>X.error(o(`sessions.order.saveFailed`)))}),Fr=Q.useMemo(()=>Re?[]:jc(jt,W,it,ot),[Re,W,it,jt,ot]),{pinnedItems:Ir,inProgressItems:Lr}=Q.useMemo(()=>{let e=e=>{let t=Mr.get(e.id),n=I(e.directory??null),r={session:e,children:[],worktree:Tt.get(e.id)??null};if(Re&&Wt([r],Le).length===0)return null;let i=vr.bySessionId.get(e.id),a=i?wr.find(e=>e.id===i.projectId):void 0,o=a?Dt(a.normalizedPath)||a.normalizedPath:t?.secondaryMeta?.projectLabel??null,s=sc({projectLabel:o,owner:i,sessionWorktree:Tt.get(e.id)??null,worktrees:a?Et.get(a.normalizedPath)??[]:[],projectRootBranch:i?fe.get(i.projectId)??(a?mr.get(a.normalizedPath)?.branch:null)??null:null,isVSCode:st})??t?.secondaryMeta??null;return{node:r,projectId:i?.projectId??t?.projectId??null,groupDirectory:i?.scopeDirectory??t?.groupDirectory??n,secondaryMeta:s}},t=t=>t.map(e).filter(e=>e!==null);return{pinnedItems:st?[]:t(Nr),inProgressItems:t(Fr)}},[Et,Wt,mr,Re,Fr,st,Le,Nr,fe,vr,Mr,wr,Tt]),Rr=Q.useMemo(()=>Dr.map(e=>({...e,groups:e.groups.filter(e=>!e.isArchivedBucket)})),[Dr]),zr=Q.useMemo(()=>{let e=Re?Rr.map(e=>({...e,groups:e.groups.map(e=>({...e,sessions:Er.get(e)?.filteredNodes??[]}))})):Rr;if(!i)return e;let t=e.find(e=>e.project.id===be)??e[0];if(!t)return[];let n=t.groups.find(e=>e.isMain&&e.sessions.length>0)??t.groups.find(e=>e.sessions.length>0)??t.groups.find(e=>e.isMain)??t.groups[0];return n?[{...t,groups:[n]}]:[]},[be,Er,Re,Rr,i]),Br=Q.useMemo(()=>Vs({sections:zr,foldersMap:Ve,getOrderedGroups:Ar,pinnedSessionIds:W,sessionOrderByScope:He,sessionOrderActivityByScope:Ue}),[Ve,Ar,zr,W,Ue,He]),Vr=Q.useMemo(()=>$s({targets:Br,collapsedProjectIds:D,collapsedGroupKeys:se,collapsedFolderIds:Be,visibleSessionCountByGroup:j,defaultVisibleSessionCount:Ws(),hasSessionSearchQuery:Re,alwaysVisibleSessionIds:rt}),[rt,Be,se,D,Re,Br,j]),Hr=Q.useMemo(()=>Re?[]:[...Ir,...Lr].map((e,t)=>{let n=e.node.session;return{scope:`pinned`,sessionId:n.id,projectId:e.projectId,directory:I(Fn(n))??e.groupDirectory??null,visibleIndex:t}}),[Re,Lr,Ir]),[Ur,Wr]=Q.useState(null),Gr=Q.useCallback(e=>{Wr(t=>t&&t.length===e.length&&t.every((t,n)=>t===e[n])?t:[...e])},[]),Kr=Q.useMemo(()=>{if(!Ur)return Hr;let e=new Set(Ur);return Hr.filter(t=>e.has(t.sessionId))},[Hr,Ur]),qr=Q.useMemo(()=>e?[]:Oi({pinnedTargets:Kr,projectTargets:Vr}),[e,Kr,Vr]),Jr=Q.useCallback(e=>{Te(`chat`),Me(!1),e.scope===`project`&&e.projectId&&Se(e.projectId),kn(e.sessionId,e.directory,e.projectId,e.scope)},[kn,Te,Se,Me]);Q.useLayoutEffect(()=>ui({targets:qr,activate:Jr}),[Jr,qr]);let Yr=Q.useMemo(()=>{let e=new Map;return qr.forEach(t=>{let n=_i({scope:t.scope,sessionId:t.sessionId,projectId:t.projectId});n&&e.set(n,Pi(qr,t)??0)}),e},[qr]),Xr=Q.useMemo(()=>{if(!ht||Re)return[];let e=[],t=(n,r)=>{if(n.session.id===ht){e.push({scope:`pinned`,sessionId:ht,projectId:r});return}n.children.forEach(e=>t(e,r))};return Ir.forEach(e=>t(e.node,e.projectId)),Lr.forEach(e=>t(e.node,e.projectId)),e},[ht,Re,Lr,Ir]),Zr=Q.useMemo(()=>{if(!ht)return[];let e=[],t=(n,r)=>{if(n.session.id===ht){e.push({scope:`project`,sessionId:ht,projectId:r});return}n.children.forEach(e=>t(e,r))};return Tr.forEach(e=>{e.groups.forEach(n=>{n.sessions.forEach(n=>t(n,e.project.id))})}),e},[ht,Tr]);Q.useLayoutEffect(()=>Ai({pinned:Kr,project:Vr}),[Kr,Vr]),Q.useLayoutEffect(()=>{xr||qb(_x({currentSessionId:ht,focus:gt,pinnedFocuses:Xr,projectFocuses:Zr,fallbackProjectId:ht?Mr.get(ht)?.projectId??null:null}))},[ht,xr,Zr,Xr,gt,Mr]);let Qr=Q.useMemo(()=>{let e=gt?.sessionId?Mr.get(gt.sessionId)?.projectId??null:null;return vx(gt,Br,e)},[Br,gt,Mr]),ei=Q.useRef(null),ti=Q.useRef(null);Q.useEffect(()=>{ti.current&&ti.current!==ht&&(ti.current=null)},[ht]),Q.useLayoutEffect(()=>{if(!Qr?.projectId)return;let e=Qr.sessionId,t=vt.sessionId===e;if(!(!t&&ht!==e)){if(t){if(ei.current===vt.revision)return;ei.current=vt.revision,ti.current=e}else{if(ti.current===e)return;ti.current=e}if(ir(Qr.projectId),Qr.groupKey&&ce(e=>{if(!e.has(Qr.groupKey))return e;let t=new Set(e);return t.delete(Qr.groupKey),t}),Qr.folderAncestorIds?.forEach(e=>{let t=nr.getState();t.collapsedFolderIds.has(e)&&t.toggleFolderCollapse(e)}),Qr.groupKey&&Qr.visibleIndex!==void 0){let e=Qr.visibleIndex+1;M(t=>{if((t.get(Qr.groupKey)??0)>=e)return t;let n=new Map(t);return n.set(Qr.groupKey,e),n})}}},[ht,Qr,vt]);let ni=Cv(Q.useMemo(()=>{let e=new Set;return Rr.forEach(t=>{D.has(t.project.id)||t.groups.forEach(n=>{if(se.has(`${t.project.id}:${n.id}`))return;let r=I(n.directory??null),i=n.branch?.trim()||tt.get(r||``)?.trim();!r||!i||e.add(Q_(r,i))})}),[...e]},[se,D,tt,Rr]));Q.useEffect(()=>{if(!a||!pr||!fr?.connected||!ur)return;let e=[],t=Date.now();if(Rr.forEach(n=>{D.has(n.project.id)||n.groups.forEach(r=>{if(se.has(`${n.project.id}:${r.id}`))return;let i=I(r.directory??null),a=r.branch?.trim()||tt.get(i||``)?.trim();if(!i||!a)return;let o=Q_(i,a),s=_v.getState().entries[o],c=!!s?.status?.pr,l=`${i}::${a}`,u=Math.max(s?.lastRefreshAt??0,s?.lastDiscoveryPollAt??0),d=!!(s?.isInitialStatusResolved&&!c&&(!_.current.has(l)||t-u>=jx));(!s||!s.isInitialStatusResolved||d)&&(d&&_.current.add(l),e.push({directory:i,branch:a}))})}),e.length===0)return;let n=new Map;e.forEach(e=>{let t=Q_(e.directory,e.branch,e.remoteName??null);n.has(t)||n.set(t,e)}),n.forEach((e,t)=>{hr(t),gr(t,{directory:e.directory,branch:e.branch,remoteName:e.remoteName??null,canShow:!0,github:ur,githubAuthChecked:pr,githubConnected:fr.connected})}),_r([...n.values()],{silent:!0,markInitialResolved:!0})},[D,se,hr,ur,pr,fr?.connected,tt,a,_r,Rr,gr]);let ri=R_({isDesktopShellRuntime:It,projectSections:Tr,projectHeaderSentinelRefs:me,enabled:a}),ii=Fx((t,n=0,r,i,a=!1,o,s=`project`,c)=>(0,$.jsx)(sx,{node:t,depth:n,groupDirectory:r,projectId:i,archivedBucket:a,currentSessionId:ht,pinnedSessionIds:W,expandedParents:w,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,notifyOnSubtasks:K,editingId:v,setEditingId:y,editTitle:b,setEditTitle:x,handleSaveEdit:Rn,handleCancelEdit:zn,toggleParent:Mn,handleSessionSelect:Pn,handleSessionDoubleClick:Ln,togglePinnedSession:oe,handleShareSession:Vn,copiedSessionId:gn,handleCopyShareUrl:Un,handleUnshareSession:Wn,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,renamingFolderId:z,getFoldersForScope:We,getSessionFolderId:$e,removeSessionFromFolder:Xe,addSessionToFolder:Je,createFolderAndStartRename:Kn,openContextPanelTab:Oe,handleDeleteSession:Gn,mobileVariant:e,alwaysShowActions:Vt,renderSessionNode:ii,secondaryMeta:o,renderContext:s,subtreeContainsActive:c?.subtreeContainsActive??Mx,subtreeContainsEditing:c?.subtreeContainsEditing??Mx,menuOpenSessionId:c?.menuOpenSessionId??null,nodeStructureKey:c?.nodeStructureKey??``,childRenderExtrasFor:c?.childRenderExtrasFor,liveSessionById:Pt,shortcutNumber:Yr.get(_i({scope:s,sessionId:t.session.id,projectId:i??null})??``)??null},`${s}:${i??``}:${t.session.id}`)),ai=Q.useCallback(e=>{Jn(e),ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[Jn]),si=Q.useCallback(e=>{let t=Xn(e);if(t.length===0)return;let n=en.getState(),r=t.filter(e=>!n.archivedLoadedDirectories.has(e));r.length>0&&In(r)},[Xn]),ci=Q.useMemo(()=>{let e=new Map;for(let[t,n]of ni)e.set(t,{visualState:n.visualState,number:n.number,url:n.url,state:n.prState,draft:n.draft,title:n.title,base:n.base,head:n.head,checks:n.checks,canMerge:n.canMerge,mergeableState:n.mergeableState,repo:n.repo});return e},[ni]),li=_t((e,t,n,r,i)=>{let a=e.folderScopeKey??I(e.directory??null);a&&et(a,t,n,r,i).catch(()=>X.error(o(`sessions.order.saveFailed`)))}),di=_t((e,t,n)=>{e.isArchivedBucket&&se.has(t)&&n&&si(n),ai(t)}),fi=Q.useMemo(()=>(t,n,r,i,a,o,s)=>(0,$.jsx)(iy,{group:t,groupKey:n,isArchivedLoading:!!(t.isArchivedBucket&&r&&Xn(r).some(e=>ft.has(e))),projectId:r,hideGroupLabel:i,compactBodyPadding:o,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,groupSearchDataByGroup:Er,visibleSessionCount:j.get(n),collapsedGroups:se,collapsedFolderIds:Be,toggleFolderCollapse:Qe,renameFolder:Ke,deleteFolder:qe,showDeletionDialog:Pe,setDeleteFolderConfirm:U,renderSessionNode:ii,projectRepoStatus:k,lastRepoStatus:Sr.current,showMoreGroupSessions:qn,resetGroupSessionLimit:Jn,mobileVariant:e,alwaysShowActions:Vt,activeProjectId:be,setActiveProjectIdOnly:Se,setActiveMainTab:Te,setSessionSwitcherOpen:Me,openNewSessionDraft:kt,addSessionToFolder:Je,createFolderAndStartRename:Kn,renamingFolderId:z,renameFolderDraft:V,setRenameFolderDraft:ee,setRenamingFolderId:B,pinnedSessionIds:W,expandedParents:w,sessionOrderByScope:He,sessionOrderActivityByScope:Ue,onReorderSessions:li,currentSessionId:ht,shortcutTargetSessionId:Qr?.groupKey===n?Qr.sessionId:null,shortcutTargetVisibleIndex:Qr?.groupKey===n?Qr.visibleIndex??null:null,editingId:v,editTitle:b,openSidebarMenuKey:L,liveSessionById:Pt,alwaysVisibleSessionIds:rt,prVisualStateByDirectoryBranch:ci,onToggleCollapsedGroup:di,dragHandleProps:a,scrollContainerRef:s}),[Re,Le,Er,ft,Xn,j,se,Be,Qe,Ke,qe,Pe,ii,k,qn,Jn,e,Vt,be,Se,Te,Me,kt,Je,Kn,z,V,W,w,He,Ue,li,ht,Qr,v,b,L,Pt,rt,ci,di]),pi=r?null:(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(gy,{collapseAllProjects:er,expandAllProjects:tr}),(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:`size-6 p-0 text-muted-foreground`,"aria-label":o(`sessions.sidebar.header.actions.addProject`),title:o(`sessions.sidebar.header.actions.addProject`),onClick:yn.requestDirectoryDialog,children:(0,$.jsx)(Z,{name:`add`,className:`size-4`})})]}),mi=It&&Lt&&!st&&!Re?(0,$.jsx)(`div`,{className:`shrink-0 px-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(Du,{className:`min-w-0 flex-1`}),(0,$.jsx)(yc,{className:`ml-auto shrink-0`})]})}):null,hi=!st&&!Re,gi=!Re&&(Ir.length>0||Lr.length>0),vi=hi||gi?(0,$.jsxs)($.Fragment,{children:[hi?(0,$.jsxs)($.Fragment,{children:[e&&Lt?(0,$.jsx)(Du,{}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5 py-1`,children:[(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,e&&`h-11`),onClick:un,children:[(0,$.jsx)(Z,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`sessions.sidebar.header.actions.newSession`)})]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,Ee===`schedule`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:dn,children:[(0,$.jsx)(Z,{name:`time`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`sessions.sidebar.header.actions.scheduledTasks`)}),a?(0,$.jsx)(c_,{}):null]}),De.data?.supported&&De.data?.enabled?(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,Ee===`assistant`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:fn,children:[(0,$.jsx)(Z,{name:`ai-agent`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`assistants.title`)}),(0,$.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,$.jsx)(Kc,{}),a?(0,$.jsx)(l_,{}):null]})]}):null]})]}):null,gi?(0,$.jsx)(sy,{items:Ir,reorderEnabled:!0,onSessionsReordered:Pr,inProgressItems:Lr,renderSessionNode:ii,currentSessionId:ht,editingId:v,openSidebarMenuKey:L,onVisibleSessionIdsChange:Gr}):null]}):null,yi=!!(z||v||S),{selectionModeEnabled:bi,hasSelection:xi,selectedIdsSize:Si,bulkScopeIsArchived:Ci,derivedSelectionScope:wi,bulkScopeFolders:Ti,bulkCanRemoveFromFolder:Ei,handleExitSelectionMode:Di,handleBulkMoveToFolder:ki,handleBulkCreateFolderAndMove:ji,handleBulkRemoveFromFolder:Mi,handleBulkDelete:Ni,confirmBulkDelete:Fi}=mx({isInlineEditing:yi,showDeletionDialog:Pe,foldersMap:Ve,addSessionsToFolder:Ye,removeSessionsFromFolders:Ze,createFolderAndStartRename:Nn,archiveSessions:hn,setBulkDeleteConfirm:ae});return(0,$.jsxs)(`div`,{ref:h,className:J(`yuri-session-sidebar relative flex h-full flex-col text-foreground overflow-x-hidden`,e?``:`bg-transparent`),children:[(0,$.jsx)(ay,{hideDirectoryControls:r,isSessionSearchOpen:u,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchQuery:f,setSessionSearchQuery:m,hasSessionSearchQuery:Re,searchMatchCount:Or}),mi,a?(0,$.jsx)(jy,{topContent:vi,hasLeadingSection:vi!==null&&(Ir.length>0||Lr.length>0),headerAccessory:pi,sectionsForRender:Rr,projectSections:Tr,activeProjectId:be,showOnlyMainWorkspace:i,hasSessionSearchQuery:Re,emptyState:nn,searchEmptyState:kr,renderGroupSessions:fi,homeDirectory:ge,collapsedProjects:D,hideDirectoryControls:r,projectRepoStatus:k,isDesktopShellRuntime:It,stuckProjectHeaders:ri,mobileVariant:e,alwaysShowActions:Vt,toggleProject:rr,setActiveProjectIdOnly:Se,setActiveMainTab:Te,setSessionSwitcherOpen:Me,openNewSessionDraft:kt,openNewWorktreeDialog:on,syncProjectSessions:$n,openProjectEditDialog:C,removeProject:xe,projectHeaderSentinelRefs:me,projectReorderEnabled:Cr===`manual`,reorderProjects:we,projectSortOrder:Cr,getOrderedGroups:Ar,setGroupOrderByProject:le,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,isInlineEditing:yi}):null,bi&&xi?(0,$.jsx)(px,{selectedCount:Si,scopeKey:wi,scopeFolders:Ti,archivedBucket:Ci,onMoveToFolder:ki,onCreateFolderAndMove:ji,onRemoveFromFolder:Mi,canRemoveFromFolder:Ei,onDelete:Ni,onDone:Di}):null,(0,$.jsx)(m_,{normalizedProjects:or,ownership:vr,enabled:a}),(0,$.jsx)(Sy,{onOpenSettings:ln,onOpenShortcuts:Ae,onOpenUpdate:cn,showRuntimeButtons:!st,showUpdateButton:ze}),c?(0,$.jsx)(Ix,{onOpenChange:l}):null,rn?(0,$.jsx)(wv,{open:!0,onOpenChange:e=>{e||C(null)},project:rn,onSave:an}):null,N?(0,$.jsx)($r,{open:!0,onOpenChange:P,onWorktreeCreated:sn}):null,(0,$.jsx)(zc,{}),(0,$.jsx)(ks,{}),(0,$.jsx)(ux,{value:H,setValue:ne,showDeletionDialog:Pe,setShowDeletionDialog:Fe,onConfirm:On}),(0,$.jsx)(fx,{value:re,setValue:U,onConfirm:jn}),(0,$.jsx)(dx,{value:ie,setValue:ae,showDeletionDialog:Pe,setShowDeletionDialog:Fe,onConfirm:Fi})]})});function Rx(e){return{info:e.info,downloading:e.downloading,downloaded:e.downloaded,progress:e.progress,error:e.error,runtimeType:e.runtimeType,onDownload:e.downloadUpdate,onRestart:e.restartToUpdate}}var zx=e=>e?(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:e}):void 0,Bx=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Vx=()=>{let{t:e}=wt(),[t,n]=Q.useState(!1),[r,i]=Q.useState(!1),[a,o]=Q.useState(null),[s,c]=Q.useState([]),[l,u]=Q.useState(!1),[d,f]=Q.useState(!1),[p,m]=Q.useState(!1),[h,g]=Q.useState(!1),[_,v]=Q.useState(new Set),y=xn(e=>e.getWorktreeMetadata),b=xn(e=>e.newSessionDraft),x=xn(e=>e.setNewSessionDraftTarget),S=xn(e=>e.setDraftBootstrapPendingDirectory),C=Kn,w=xn(e=>e.archiveSessions),T=q(e=>e.showDeletionDialog),E=q(e=>e.setShowDeletionDialog),D=je(e=>e.currentDirectory),O=je(e=>e.homeDirectory),k=je(e=>e.isHomeReady),A=An(e=>e.projects),j=An(e=>e.activeProjectId),{isMobile:M,isTablet:N,hasTouchInput:P}=eo(),F=M||N||P,I=Q.useMemo(()=>Bx((j?A.find(e=>e.id===j)??null:null)?.path??D),[j,D,A]),L=Q.useCallback(e=>{let t=Bx(e.projectDirectory)||I;return{id:(A.find(e=>Bx(e.path)===t)??null)?.id??`path:${t}`,path:t}},[I,A]),R=h&&_.size>0,z=Q.useMemo(()=>{let e=a?.worktree;return e&&typeof e.branch==`string`&&e.branch.trim().length>0?!0:s.length>0&&s.every(({metadata:e})=>typeof e.branch==`string`&&e.branch.trim().length>0)},[a?.worktree,s]),B=a?.mode===`worktree`,V=B,ee=p||!B||!z,H=p||!B;Q.useEffect(()=>{r||!k||A.length>0||(i(!0),n(!0))},[r,k,A.length]);let te=Q.useCallback(e=>{o({sessions:e.sessions,dateLabel:e.dateLabel,mode:e.mode??`session`,worktree:e.worktree??null})},[]),ne=Q.useCallback(()=>{o(null),c([]),u(!1),f(!1),m(!1),g(!1),v(new Set)},[]),re=Q.useCallback(t=>{if(t.sessions.length===0)return;let n=t.sessions.map(e=>e.id);qs({sessionIds:n,message:n.length===1?e(`sessions.sidebar.session.delete.success`):e(`sessions.sidebar.bulkActions.deletedPlural`,{count:n.length}),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:n.length===1?e(`sessions.sidebar.session.delete.error`):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:n.length})})},[e]);Q.useEffect(()=>yn.onDeleteRequest(e=>{if(!T&&(e.mode??`session`)===`session`){re(e);return}te(e)}),[te,T,re]),Q.useEffect(()=>yn.onDirectoryRequest(()=>{n(!0)}),[]),Q.useEffect(()=>{if(!a){c([]),u(!1),f(!1),g(!1),v(new Set);return}let e=a.sessions.map(e=>{let t=y(e.id);return t?{session:e,metadata:t}:null}).filter(e=>!!e);c(e),u(!1),g(!1),v(new Set);let t=new Map;if(a.worktree?.path&&t.set(Bx(a.worktree.path),a.worktree),e.forEach(({metadata:e})=>{e.path&&t.set(Bx(e.path),e)}),t.size===0){g(!0);return}let n=!1;return(async()=>{let e=new Map,r=new Set;await Promise.all(Array.from(t.entries()).map(async([t,n])=>{try{let i=await ia(n.path);e.set(t,i),i?.isDirty&&r.add(t)}catch{n.status&&(e.set(t,n.status),n.status.isDirty&&r.add(t))}})).catch(e=>{console.warn(`Failed to inspect worktree status before deletion:`,e)}),!n&&(v(r),g(!0),o(t=>{if(!t?.worktree?.path)return t;let n=Bx(t.worktree.path),r=e.get(n);if(!r)return t;let i=t.worktree.status;return i?.isDirty===r.isDirty&&i?.ahead===r.ahead&&i?.behind===r.behind&&i?.upstream===r.upstream?t:{...t,worktree:{...t.worktree,status:r}}}),c(t=>t.map(t=>{let n=Bx(t.metadata.path),r=e.get(n);return r?{session:t.session,metadata:{...t.metadata,status:r}}:t})))})(),()=>{n=!0}},[a,y]),Q.useEffect(()=>{z||u(!1)},[z]);let U=Q.useCallback(async(t,n)=>{let r=l&&z,i=L(t),a=Bx(t.path),o=Bx(i.path);try{await ta(i,t,{deleteRemoteBranch:r,deleteLocalBranch:n});let e=Bx(b?.directoryOverride);return b?.open&&a&&e===a&&o&&(S(null),x({projectId:i.id,directoryOverride:o},{force:!0})),Bx(D)===a&&o&&je.getState().setDirectory(o,{showOverlay:!1}),!0}catch(t){return X.error(e(`sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle`),{description:zx(t instanceof Error?t.message:e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),!1}},[z,D,l,L,b?.directoryOverride,b?.open,S,x,e]),ie=Q.useCallback((t,n)=>{let r=l&&z;(async()=>{if(!await U(t,n))return;let i=e(r?`sessions.sidebar.sessionDialogs.worktree.removedWithRemote`:`sessions.sidebar.sessionDialogs.worktree.removed`);X.success(e(`sessions.sidebar.sessionDialogs.worktree.removedTitle`),{description:zx(i)})})()},[z,l,U,e]),ae=Q.useCallback(async()=>{if(a){m(!0);try{let t=V&&d;if(a.sessions.length===0&&B&&a.worktree){ie(a.worktree,t),ne();return}if(a.sessions.length===1){let t=a.sessions[0];if(B){if(!await C(t.id)){X.error(e(`sessions.sidebar.session.archive.error`)),m(!1);return}Ys({sessionIds:[t.id],message:e(`sessions.sidebar.session.archive.success`),undoLabel:e(`sessions.sidebar.undo`),settingsLabel:e(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:e(`sessions.sidebar.session.archive.undoFailed`)})}else qs({sessionIds:[t.id],message:e(`sessions.sidebar.session.delete.success`),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:e(`sessions.sidebar.session.delete.error`)})}else{let n=a.sessions.map(e=>e.id),r=[],i=[];if(B){let e=await w(n);r=e.archivedIds,i=e.failedIds}else qs({sessionIds:n,message:n.length===1?e(`sessions.sidebar.bulkActions.deletedSingle`,{count:n.length}):e(`sessions.sidebar.bulkActions.deletedPlural`,{count:n.length}),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:n.length===1?e(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:n.length}):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:n.length})}),r=n,i=[];if(B&&a.worktree&&i.length===0&&ie(a.worktree,t),B&&r.length>0&&Ys({sessionIds:r,message:r.length===1?e(`sessions.sidebar.bulkActions.archivedSingle`,{count:r.length}):e(`sessions.sidebar.bulkActions.archivedPlural`,{count:r.length}),undoLabel:e(`sessions.sidebar.undo`),settingsLabel:e(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:r.length===1?e(`sessions.sidebar.session.archive.undoFailed`):e(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:r.length})}),i.length>0&&(X.error(B?i.length===1?e(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:i.length}):e(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:i.length}):i.length===1?e(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:i.length}):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:i.length}),{description:zx(e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),r.length===0)){m(!1);return}}B&&a.sessions.length===1&&a.worktree&&ie(a.worktree,t),ne()}finally{m(!1)}}},[a,d,C,w,ne,V,B,ie,e]),W=a?.worktree??s[0]?.metadata??null,oe=a?a.mode===`worktree`?a.sessions.length===0?e(`sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked`):a.sessions.length===1?e(`sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked`,{count:a.sessions.length}):e(`sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked`,{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?e(`sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate`,{dateLabel:a.dateLabel}):e(`sessions.sidebar.dialogs.sessionDelete.descriptionOne`):a.dateLabel?e(`sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate`,{count:a.sessions.length,dateLabel:a.dateLabel}):e(`sessions.sidebar.dialogs.sessionDelete.descriptionMany`,{count:a.sessions.length}):``,se=a?(0,$.jsxs)(`div`,{className:J(B?`space-y-3`:`space-y-2`),children:[a.sessions.length>0&&(0,$.jsxs)(`div`,{className:J(B?`rounded-lg bg-muted/30 p-3`:`space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3`),children:[B&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:a.sessions.length===1?e(`sessions.sidebar.sessionDialogs.linkedSessionSingle`):e(`sessions.sidebar.sessionDialogs.linkedSessionPlural`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground/70`,children:a.sessions.length})]}),(0,$.jsxs)(`ul`,{className:J(B?`mt-2 space-y-1`:`space-y-0.5`),children:[a.sessions.slice(0,5).map(t=>(0,$.jsxs)(`li`,{className:J(B?`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:[(0,$.jsx)(`span`,{className:J(!B&&`hidden`),children:`•`}),(0,$.jsx)(`span`,{className:`truncate`,children:t.title||e(`sessions.sidebar.session.untitled`)})]},t.id)),a.sessions.length>5&&(0,$.jsx)(`li`,{className:J(B?`px-2.5 py-1 text-xs text-muted-foreground/70`:`typography-micro text-muted-foreground/70`),children:e(`sessions.sidebar.dialogs.sessionList.more`,{count:a.sessions.length-5})})]})]}),B?(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg bg-muted/30 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e(`sessions.sidebar.sessionDialogs.worktree.label`)}),W?.label?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground/70`,children:W.label}):null]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground/80 break-all`,children:W?xt(W.path,O):e(`sessions.sidebar.sessionDialogs.worktree.pathUnavailable`)}),R&&(0,$.jsx)(`p`,{className:`typography-micro text-status-warning`,children:e(`sessions.sidebar.sessionDialogs.worktree.uncommittedWarning`)})]}):(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/60 p-3`,children:(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/80`,children:e(`sessions.sidebar.sessionDialogs.delete.note`)})})]}):null,ce=B?z?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ee||u(e=>!e)},disabled:ee,className:J(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,ee?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[l?(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}),e(`sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch`)]}):(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70`,children:e(`sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable`)}):null,G=B?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{H||f(e=>!e)},disabled:H,className:J(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,H?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[d?(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}),e(`sessions.sidebar.sessionDialogs.actions.deleteLocalBranch`)]}):null,le=B?(0,$.jsxs)(`div`,{className:`flex w-full items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[G,ce]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ne,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:ae,disabled:p,children:e(p?`sessions.sidebar.sessionDialogs.actions.deleting`:`sessions.sidebar.sessionDialogs.actions.deleteWorktree`)})]})]}):(0,$.jsxs)(`div`,{className:`flex w-full items-center justify-between gap-3`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>E(!T),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":!T,children:[T?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}),e(`sessions.sidebar.dialogs.neverAsk`)]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ne,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:ae,disabled:p,children:p?e(`sessions.sidebar.sessionDialogs.actions.deleting`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`)})]})]}),ue=B?e(`sessions.sidebar.sessionDialogs.actions.deleteWorktree`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`);return(0,$.jsxs)($.Fragment,{children:[F?(0,$.jsx)(Ha,{open:!!a,onClose:()=>{p||ne()},title:ue,footer:(0,$.jsx)(`div`,{className:`flex justify-end gap-2`,children:le}),children:(0,$.jsxs)(`div`,{className:`space-y-2 pb-2`,children:[oe&&(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/80`,children:oe}),se]})}):(0,$.jsx)(pr,{open:!!a,onOpenChange:e=>{if(!e){if(p)return;ne()}},children:(0,$.jsxs)(ur,{className:J(B?`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:[(0,$.jsxs)(cr,{children:[(0,$.jsxs)(dr,{className:J(B&&`flex items-center gap-2`),children:[B&&(0,$.jsx)(Z,{name:`delete-bin`,className:`h-5 w-5`}),ue]}),oe&&(0,$.jsx)(fr,{children:oe})]}),(0,$.jsx)(`div`,{className:J(B&&`flex-1 min-h-0 overflow-y-auto space-y-2`),children:se}),(0,$.jsx)(lr,{className:`mt-2 gap-2 pt-1 pb-1`,children:le})]})}),(0,$.jsx)(Rc,{open:t,onOpenChange:n})]})},Hx=Q.createContext(null),Ux=e=>{let t=(0,fl.c)(3),{children:n,value:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Hx.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Wx=jo(()=>dt(()=>import(`./TerminalView-CWZCDRxs.js`).then(e=>({default:e.TerminalView})),__vite__mapDeps([63,1,4,2,3,5,6,7,8,9,10,11,12,13,16,17,18,64,14,15,65,33,34,35,36,44,45,30,31,32,46,47,48,37,38,66,52,67,68,69,70,71,72]))),Gx=jo(()=>dt(()=>import(`./DiagramView-ALA0pyKm.js`).then(e=>({default:e.DiagramView})),__vite__mapDeps([73,1,3,2,8,11,7,9,10,17,5,16,4,12,18,45,33,6,13,34,35,36,38,52,14,15,44,30,31,32,46,47,48,74,75]))),Kx=jo(()=>dt(()=>import(`./SettingsView-ulmuNYxi.js`).then(e=>e.n).then(e=>({default:e.SettingsView})),__vite__mapDeps([76,1,2,3,4,5,6,7,8,9,10,11,12,13,77,78,14,15,16,17,18,79,45,30,31,32,33,34,35,36,80,81,44,46,47,48,38,82,49,83,84,54,37,39,50,85,86,87,58,66,88,89,42,68,69,70,90,91,92,43,20,21,22,23,24,25,26,27,28,29,51,52,53,93,55,67,94,95,96,97,98,99,100,101,102,103,104,105,106,72,107,61,108,109,110]))),qx=jo(()=>dt(()=>import(`./SettingsWindow-C6iznJxw.js`).then(e=>({default:e.SettingsWindow})),__vite__mapDeps([111,1,8,12,33,6,2,3,4,5,7,9,10,11,13,34,18,35,36,76,77,78,14,15,16,17,79,45,30,31,32,80,81,44,46,47,48,38,82,49,83,84,54,37,39,50,85,86,87,58,66,88,89,42,68,69,70,90,91,92,43,20,21,22,23,24,25,26,27,28,29,51,52,53,93,55,67,94,95,96,97,98,99,100,101,102,103,104,105,106,72,107,61,108,109,110]))),Jx=jo(()=>dt(()=>import(`./MultiRunWindow-D5HKvioh.js`).then(e=>({default:e.MultiRunWindow})),__vite__mapDeps([112,1,8,12,33,6,2,3,4,5,7,9,10,11,13,34,18,35,36,38,113,14,15,16,17,30,31,32,44,45,46,47,48,86,85,87,58,66,88,89,42,68,69,70,114,82,49,83,84,54,37,115,116,102]))),Yx=jo(()=>dt(()=>import(`./AssistantView-CdO4imc6.js`).then(e=>e.n).then(e=>({default:e.AssistantView})),__vite__mapDeps([117,1,3,2,6,4,5,7,8,9,10,11,12,13,14,15,16,17,18,45,30,31,32,33,34,35,36,80,81,44,46,47,48,38,82,49,83,84,54,37,39,50,66,40,41,88,89,42,118,92,119,56,120,115,116,51,52,53,121,107,122,123]))),Xx=()=>{let e=1220,t=q(e=>e.isSidebarOpen),n=q(e=>e.isRightSidebarOpen),r=q(e=>e.isBottomTerminalOpen),i=q(e=>e.setRightSidebarOpen),a=q(e=>e.setBottomTerminalOpen),o=q(e=>e.activeMainTab),s=q(e=>e.setIsMobile),c=q(e=>e.isSessionSwitcherOpen),l=q(e=>e.isSettingsDialogOpen),u=q(e=>e.setSettingsDialogOpen),d=q(e=>e.isMultiRunLauncherOpen),f=q(e=>e.setMultiRunLauncherOpen),{isMobile:p,isTablet:m}=eo(),h=Q.useRef(!1),g=Q.useRef(!1),_=Q.useRef(!1),[v,y]=Q.useState(!1),[b,x]=Q.useState(!1),[S,C]=Q.useState(!1),[w,T]=Q.useState(!1),E=Q.useCallback(e=>{y(e),q.getState().setSessionSwitcherOpen(e)},[]),D=Q.useRef(!1),O=Q.useRef(typeof window>`u`?0:window.innerWidth),k=go(-O.current),A=(0,Q.useRef)(0),j=go(O.current),M=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{p&&(A.current=window.innerWidth,M.current=window.innerWidth)},[p]),(0,Q.useEffect)(()=>{if(!p){C(!1);return}v&&C(!0),_o(k,v?0:-A.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[v,p,k]),(0,Q.useEffect)(()=>{if(!p){T(!1);return}D.current=b,b&&T(!0),_o(j,b?0:M.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[p,b,j]),(0,Q.useEffect)(()=>{if(p)return k.on(`change`,e=>{let t=A.current||O.current,n=v||e>-t+.5;C(e=>e===n?e:n)})},[p,k,v]),(0,Q.useEffect)(()=>{if(p)return j.on(`change`,e=>{let t=M.current||O.current,n=b||e<t-.5;T(e=>e===n?e:n)})},[p,b,j]),(0,Q.useEffect)(()=>{p&&!c&&v&&E(!1)},[c,p,v,E]),(0,Q.useEffect)(()=>{if(!p){_.current=!1;return}_.current||(_.current=!0,E(!1),x(!1),q.getState().isRightSidebarOpen&&i(!1))},[p,E,i]),(0,Q.useEffect)(()=>{if(!p||o!==`chat`||v||b||l)return;let e=!1,t,n=r=>{t=window.setTimeout(()=>{if(e)return;let t=xn.getState(),r=q.getState();if(!(r.activeMainTab!==`chat`||r.isSettingsDialogOpen||t.currentSessionId||t.newSessionDraft?.open)){if(t.isLoading){n(250);return}t.openNewSessionDraft()}},r)};return n(500),()=>{e=!0,t!==void 0&&window.clearTimeout(t)}},[o,p,l,v,b]),(0,Q.useEffect)(()=>{!p||!l||(E(!1),x(!1),n&&i(!1))},[p,l,n,E,i]),Q.useEffect(()=>{q.getState().isMobile!==p&&s(p)},[p,s]),Q.useEffect(()=>{if(typeof window>`u`)return;let e,t=()=>{e===void 0&&(e=window.requestAnimationFrame(()=>{e=void 0,q.getState().updateProportionalSidebarWidths()}))};return window.addEventListener(`resize`,t),()=>{window.removeEventListener(`resize`,t),e!==void 0&&window.cancelAnimationFrame(e)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let t,n=()=>{let t=q.getState(),n=window.innerWidth,r=window.innerHeight;!p&&!m&&(n<1140?t.isRightSidebarOpen&&(i(!1),h.current=!0):n>=e&&h.current&&(i(!0),h.current=!1),r<640?t.isBottomTerminalOpen&&(a(!1),g.current=!0):r>=700&&g.current&&(a(!0),g.current=!1))},r=()=>{t===void 0&&(t=window.requestAnimationFrame(()=>{t=void 0,n()}))};return n(),window.addEventListener(`resize`,r),()=>{window.removeEventListener(`resize`,r),t!==void 0&&window.cancelAnimationFrame(t)}},[p,m,a,i]),Q.useEffect(()=>{if(typeof window>`u`)return;let t=q.subscribe((t,n)=>{let r=window.innerWidth,i=window.innerHeight,a=r>=e,o=i>=700;t.isRightSidebarOpen!==n.isRightSidebarOpen&&a&&(h.current=!1),t.isBottomTerminalOpen!==n.isBottomTerminalOpen&&o&&(g.current=!1)});return()=>{t()}},[p,m,a,i]);let N=Q.useCallback(()=>{v&&E(!1),x(!b)},[v,b,E]),P=Q.useMemo(()=>{switch(o){case`git`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(of,{isActive:!b})});case`diff`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Js,{})});case`terminal`:return r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Wx,{})});case`files`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wp,{})});case`diagram`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Gx,{})});default:return null}},[o,r,b]),F=o===`schedule`,I=o===`assistant`,L=F||I,R=o===`chat`,z=!L&&!l;return(0,$.jsx)(gc,{children:(0,$.jsxs)(`div`,{"data-page-scroll-lock":`true`,className:J(`main-content-safe-area`,p?`flex h-[100dvh] flex-col`:`relative flex h-[100dvh]`,`bg-background`),children:[(0,$.jsx)(Ec,{}),(0,$.jsx)(e_,{}),(0,$.jsx)(i_,{}),(0,$.jsx)(Vx,{}),p?(0,$.jsxs)(Ux,{value:{leftDrawerOpen:v,rightDrawerOpen:b,toggleLeftDrawer:()=>{let e=!v;b&&x(!1),E(e)},toggleRightDrawer:N,leftDrawerX:k,rightDrawerX:j,leftDrawerWidth:A,rightDrawerWidth:M,setMobileLeftDrawerOpen:E,setRightSidebarOpen:x},children:[!l&&!L&&(0,$.jsx)(fu,{onToggleLeftDrawer:()=>{let e=!v;b&&x(!1),E(e)},onToggleRightDrawer:()=>{N()},leftDrawerOpen:v,rightDrawerOpen:b}),(0,$.jsx)(`div`,{"data-page-scroll-lock":`true`,className:J(`flex flex-1 overflow-hidden relative`,l&&`hidden`),children:(0,$.jsxs)(`main`,{className:`w-full h-full overflow-hidden bg-background relative`,"data-page-scroll-lock":`true`,children:[F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(oc,{})})})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Yx,{})})})}),z&&(0,$.jsx)(`div`,{className:J(`absolute inset-0`,!R&&`invisible`),children:(0,$.jsx)(pa,{children:(0,$.jsx)(ac,{})})}),z&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(pa,{children:P})}),d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(pa,{children:(0,$.jsx)(sl,{onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),(0,$.jsx)(as.div,{className:J(`absolute inset-0 z-20 bg-sidebar`,!S&&`pointer-events-none invisible`),"data-page-scroll-lock":`true`,style:{x:k},"aria-hidden":!v,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Lx,{mobileVariant:!0,isVisible:S})})}),w&&(0,$.jsx)(as.div,{className:`absolute inset-0 z-20 bg-sidebar`,"data-page-scroll-lock":`true`,style:{x:j},"aria-hidden":!b,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(of,{isActive:b})})})})]})}),l&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,style:{paddingTop:`var(--yuri-safe-area-top, 0px)`},children:(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Kx,{onClose:()=>u(!1)})})})}),(0,$.jsx)(pa,{children:(0,$.jsx)(Us,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ju,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(Tu,{isOpen:t,isMobile:p,className:`border-border/50`,topBar:(0,$.jsx)(Eu,{}),children:(0,$.jsx)(Lx,{isVisible:t})}),(0,$.jsx)(`div`,{className:`relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:L?(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:I?(0,$.jsx)(Yx,{}):(0,$.jsx)(oc,{})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fu,{}),(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-h-0 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-w-0 flex-col overflow-hidden yuri-layout-divider-t bg-background`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-h-0 min-w-0 overflow-hidden`,"data-page-scroll-lock":`true`,"data-chat-area":!0,children:[(0,$.jsxs)(`main`,{className:`flex-1 overflow-hidden bg-background relative`,"data-page-scroll-lock":`true`,children:[z&&(0,$.jsx)(`div`,{className:J(`absolute inset-0`,!R&&`invisible`),children:(0,$.jsx)(pa,{children:(0,$.jsx)(ac,{})})}),z&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(pa,{children:P})})]}),(0,$.jsx)(Qg,{})]})}),(0,$.jsx)(_u,{isOpen:r,isMobile:p,children:r?(0,$.jsx)(pa,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Wx,{})})}):null})]}),(0,$.jsx)(Bu,{isOpen:n,className:`bg-background yuri-layout-divider-t`,children:(0,$.jsx)(pa,{children:(0,$.jsx)(Bf,{})})})]})]})})]}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(qx,{open:l,onOpenChange:u})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Jx,{open:d,onOpenChange:f})})]})]})})},Zx=e=>{if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},Qx=e=>{let t=(0,fl.c)(8),{label:n,value:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`div`,{className:`typography-meta text-[var(--surface-muted-foreground)]`,children:n}),t[1]=n,t[2]=a);let o;t[3]===r?o=t[4]:(o=(0,$.jsx)(`div`,{className:`typography-markdown font-semibold text-[var(--surface-foreground)]`,children:r}),t[3]=r,t[4]=o);let s;return t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`rounded-md p-2`,style:i,children:[a,o]}),t[5]=a,t[6]=o,t[7]=s):s=t[7],s},$x=e=>{let t=(0,fl.c)(43),{title:n,snapshot:r,emptyLabel:i}=e,{t:a}=wt(),o;if(t[0]!==i||t[1]!==r.durationMs||t[2]!==r.entries||t[3]!==r.lastUpdatedAt||t[4]!==r.startedAt||t[5]!==a||t[6]!==n){let e=r.entries.slice(0,12),s;t[8]===r.entries?s=t[9]:(s=r.entries.reduce(tS,0),t[8]=r.entries,t[9]=s);let c=s,l;t[10]===n?l=t[11]:(l=(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:n}),t[10]=n,t[11]=l);let u;t[12]!==r.durationMs||t[13]!==r.startedAt||t[14]!==a?(u=r.startedAt?Zx(r.durationMs):a(`memoryDebugPanel.common.idle`),t[12]=r.durationMs,t[13]=r.startedAt,t[14]=a,t[15]=u):u=t[15];let d;t[16]===u?d=t[17]:(d=(0,$.jsx)(`div`,{className:`typography-meta text-[var(--surface-muted-foreground)]`,children:u}),t[16]=u,t[17]=d);let f;t[18]!==l||t[19]!==d?(f=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[l,d]}),t[18]=l,t[19]=d,t[20]=f):f=t[20];let p;t[21]===a?p=t[22]:(p=a(`memoryDebugPanel.metric.metrics`),t[21]=a,t[22]=p);let m;t[23]!==r.entries.length||t[24]!==p?(m=(0,$.jsx)(Qx,{label:p,value:r.entries.length}),t[23]=r.entries.length,t[24]=p,t[25]=m):m=t[25];let h;t[26]===a?h=t[27]:(h=a(`memoryDebugPanel.metric.samples`),t[26]=a,t[27]=h);let g;t[28]!==h||t[29]!==c?(g=(0,$.jsx)(Qx,{label:h,value:c}),t[28]=h,t[29]=c,t[30]=g):g=t[30];let _;t[31]===a?_=t[32]:(_=a(`memoryDebugPanel.metric.lastUpdate`),t[31]=a,t[32]=_);let v;t[33]!==r.lastUpdatedAt||t[34]!==a?(v=r.lastUpdatedAt?a(`memoryDebugPanel.common.live`):a(`memoryDebugPanel.common.notAvailable`),t[33]=r.lastUpdatedAt,t[34]=a,t[35]=v):v=t[35];let y;t[36]!==_||t[37]!==v?(y=(0,$.jsx)(Qx,{label:_,value:v}),t[36]=_,t[37]=v,t[38]=y):y=t[38];let b;t[39]!==g||t[40]!==y||t[41]!==m?(b=(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[m,g,y]}),t[39]=g,t[40]=y,t[41]=m,t[42]=b):b=t[42],o=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0`,children:[f,b,e.length===0?(0,$.jsx)(`div`,{className:`rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]`,style:{backgroundColor:`color-mix(in srgb, var(--surface-muted) 45%, transparent)`},children:i}):(0,$.jsx)(fo,{outerClassName:`max-h-64`,className:`pr-1`,children:(0,$.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-[var(--interactive-border)] p-2`,style:{backgroundColor:`color-mix(in srgb, var(--surface-elevated) 88%, transparent)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)] break-all`,children:e.metric}),(0,$.jsxs)(`div`,{className:`mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]`,children:[(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.countValue`,{value:e.count})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.avgValue`,{value:e.avg})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.maxValue`,{value:e.max})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.totalValue`,{value:e.total})})]})]},e.metric))})})]}),t[0]=i,t[1]=r.durationMs,t[2]=r.entries,t[3]=r.lastUpdatedAt,t[4]=r.startedAt,t[5]=a,t[6]=n,t[7]=o}else o=t[7];return o},eS=e=>{let t=(0,fl.c)(104),{onClose:n}=e,{t:r}=wt(),[i,a]=Q.useState(`memory`),[o,s]=Q.useState(`idle`),c=xn(nS),l=Vt(rS),u=Yn(),d=rr(),[f,p]=Q.useState(iS),m,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>Pe(()=>{p(Ge())}),h=[],t[0]=m,t[1]=h):(m=t[0],h=t[1]),Q.useEffect(m,h);let g;if(t[2]!==d||t[3]!==u){bb0:{let e=Ae(),t={};if(!e){g=t;break bb0}let n=e.getCacheBudget?.(),r=n?n.listCanonical().map(aS):u.map(e=>({directory:d,sessionID:e.id}));for(let n of r){if(d&&n.directory!==d)continue;let r=e.getTranscript(Ie(n.directory,n.sessionID));t[n.sessionID]=r.messageOrder.map(e=>r.messagesByID[e]).filter(oS)}g=t}t[2]=d,t[3]=u,t[4]=g}else g=t[4];let _=g,v=_v(sS),[y,b]=Q.useState(cS),[x,S]=Q.useState(lS),C;t[5]===y.entries?C=t[6]:(C=new Map,y.entries.forEach(e=>{C.set(e.metric,e.count)}),t[5]=y.entries,t[6]=C);let w;t[7]===C?w=t[8]:(w=C.get(`ui.message_list.render`)??0,t[7]=C,t[8]=w);let T;t[9]===C?T=t[10]:(T=C.get(`ui.message_list.render.streaming`)??0,t[9]=C,t[10]=T);let E;t[11]===C?E=t[12]:(E=C.get(`ui.chat_message.render`)??0,t[11]=C,t[12]=E);let D;t[13]===C?D=t[14]:(D=C.get(`ui.chat_message.render.streaming`)??0,t[13]=C,t[14]=D);let O;t[15]===C?O=t[16]:(O=C.get(`ui.chat_message.render.static_during_stream`)??0,t[15]=C,t[16]=O);let k;t[17]===C?k=t[18]:(k=C.get(`ui.chat_message.render.static_outside_active_turn_during_stream`)??0,t[17]=C,t[18]=k);let A;t[19]!==w||t[20]!==T||t[21]!==E||t[22]!==D||t[23]!==O||t[24]!==k?(A={messageListRender:w,messageListRenderStreaming:T,chatMessageRender:E,chatMessageRenderStreaming:D,chatMessageRenderStaticDuringStream:O,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},t[19]=w,t[20]=T,t[21]=E,t[22]=D,t[23]=O,t[24]=k,t[25]=A):A=t[25];let j=A,M,N;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>{let e=()=>{b(Ke()),S(ze())};e();let t=window.setInterval(e,500);return()=>window.clearInterval(t)},N=[],t[26]=M,t[27]=N):(M=t[26],N=t[27]),Q.useEffect(M,N);let P,F;t[28]===o?(P=t[29],F=t[30]):(P=()=>{if(o===`idle`)return;let e=window.setTimeout(()=>{s(`idle`)},1500);return()=>window.clearTimeout(e)},F=[o],t[28]=o,t[29]=P,t[30]=F),Q.useEffect(P,F);let I=0,L=0,R=0;for(let e of Object.keys(_)){let t=_[e]??[];L+=t.length;for(let e of t)e.role===`user`?R+=1:e.role===`assistant`&&(I+=1)}let z;t[31]!==I||t[32]!==L||t[33]!==R?(z={assistant:I,total:L,user:R},t[31]=I,t[32]=L,t[33]=R,t[34]=z):z=t[34];let B=z,V;if(t[35]!==c||t[36]!==_||t[37]!==l||t[38]!==u||t[39]!==r){let e;t[41]!==c||t[42]!==_||t[43]!==l||t[44]!==r?(e=e=>{let t=_[e.id]??[],n=0,i=0;for(let e of t)e.role===`user`?i+=1:e.role===`assistant`&&(n+=1);let a=l.get(e.id);return{id:e.id,title:e.title||r(`memoryDebugPanel.common.untitled`),assistantMessageCount:n,messageCount:t.length,userMessageCount:i,isStreaming:a?.isStreaming||!1,isZombie:a?.isZombie||!1,backgroundCount:a?.backgroundMessageCount||0,lastAccessed:a?.lastAccessedAt||0,isCurrent:e.id===c}},t[41]=c,t[42]=_,t[43]=l,t[44]=r,t[45]=e):e=t[45],V=u.map(e).sort(uS),t[35]=c,t[36]=_,t[37]=l,t[38]=u,t[39]=r,t[40]=V}else V=t[40];let ee=V,H;t[46]===_?H=t[47]:(H=Object.keys(_),t[46]=_,t[47]=H);let te=H.length,ne;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(ne=async()=>{try{let e={generatedAt:new Date().toISOString(),ui:Ke(),vscode:ze()};await navigator.clipboard.writeText(JSON.stringify(e,null,2)),s(`copied`)}catch{s(`error`)}},t[48]=ne):ne=t[48];let re=ne,U;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(U={backgroundColor:`color-mix(in srgb, var(--surface-background) 94%, transparent)`},t[49]=U):U=t[49];let ie;t[50]===i?ie=t[51]:(ie=i===`memory`?(0,$.jsx)(Z,{name:`database-2`,className:`h-4 w-4 text-[var(--surface-foreground)]`}):(0,$.jsx)(Z,{name:`bar-chart-box`,className:`h-4 w-4 text-[var(--surface-foreground)]`}),t[50]=i,t[51]=ie);let ae;t[52]===r?ae=t[53]:(ae=r(`memoryDebugPanel.title`),t[52]=r,t[53]=ae);let W;t[54]===ae?W=t[55]:(W=(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:ae}),t[54]=ae,t[55]=W);let oe;t[56]!==ie||t[57]!==W?(oe=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ie,W]}),t[56]=ie,t[57]=W,t[58]=oe):oe=t[58];let se;t[59]===i?se=t[60]:(se=i===`streaming`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{size:`xs`,variant:`ghost`,onClick:re,children:(0,$.jsx)(Z,{name:`file-copy`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{size:`xs`,variant:`ghost`,onClick:()=>{Ne(),b(Ke()),S(ze())},children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})})]}):null,t[59]=i,t[60]=se);let ce;t[61]===n?ce=t[62]:(ce=n?(0,$.jsx)(Y,{size:`icon`,variant:`ghost`,className:`h-6 w-6`,onClick:n,children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})}):null,t[61]=n,t[62]=ce);let G;t[63]!==se||t[64]!==ce?(G=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[se,ce]}),t[63]=se,t[64]=ce,t[65]=G):G=t[65];let le;t[66]!==oe||t[67]!==G?(le=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[oe,G]}),t[66]=oe,t[67]=G,t[68]=le):le=t[68];let ue;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(ue={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[69]=ue):ue=t[69];let de=i===`memory`?`secondary`:`ghost`,fe;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(fe=()=>a(`memory`),t[70]=fe):fe=t[70];let pe;t[71]===r?pe=t[72]:(pe=r(`memoryDebugPanel.tabs.memory`),t[71]=r,t[72]=pe);let me;t[73]!==de||t[74]!==pe?(me=(0,$.jsx)(Y,{size:`sm`,variant:de,className:`flex-1`,onClick:fe,children:pe}),t[73]=de,t[74]=pe,t[75]=me):me=t[75];let he=i===`streaming`?`secondary`:`ghost`,ge;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(ge=()=>a(`streaming`),t[76]=ge):ge=t[76];let _e;t[77]===r?_e=t[78]:(_e=r(`memoryDebugPanel.tabs.streaming`),t[77]=r,t[78]=_e);let ve;t[79]!==he||t[80]!==_e?(ve=(0,$.jsx)(Y,{size:`sm`,variant:he,className:`flex-1`,onClick:ge,children:_e}),t[79]=he,t[80]=_e,t[81]=ve):ve=t[81];let ye;t[82]!==me||t[83]!==ve?(ye=(0,$.jsxs)(`div`,{className:`mb-3 flex gap-1 rounded-md p-1`,style:ue,children:[me,ve]}),t[82]=me,t[83]=ve,t[84]=ye):ye=t[84];let be;t[85]!==i||t[86]!==te||t[87]!==o||t[88]!==c||t[89]!==_||t[90]!==B||t[91]!==l||t[92]!==ee||t[93]!==u||t[94]!==j||t[95]!==y||t[96]!==r||t[97]!==v||t[98]!==x?(be=i===`memory`?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 typography-meta`,children:[(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.totalMessages`),value:B.total}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.cachedSessions`),value:`${te} / ${zr.MAX_SESSIONS}`}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.userMessages`),value:B.user}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.assistantMessages`),value:B.assistant})]}),(0,$.jsxs)(`div`,{className:`typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.viewportWindow`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.messagesValue`,{count:Lr()})})]}),(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.zombieTimeout`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.minutesValue`,{count:zr.ZOMBIE_TIMEOUT/1e3/60})})]}),(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.githubTotalRequests`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:v})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 typography-meta font-semibold text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.section.sessionsInMemory`)}),(0,$.jsx)(fo,{outerClassName:`max-h-48`,className:`space-y-1 pr-1`,children:ee.map(e=>(0,$.jsxs)(`div`,{className:`typography-meta flex items-center justify-between rounded p-1.5`,style:{backgroundColor:e.isCurrent?`color-mix(in srgb, var(--interactive-selection) 22%, transparent)`:`color-mix(in srgb, var(--surface-muted) 35%, transparent)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[var(--surface-foreground)]`,children:e.title}),e.isStreaming?(0,$.jsx)(Z,{name:`pulse`,className:`h-3 w-3 animate-pulse text-[var(--status-info)]`}):null,e.isZombie?(0,$.jsx)(`span`,{className:`text-[var(--status-warning)]`,children:`!`}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.roleMsgsValue`,{assistant:e.assistantMessageCount,user:e.userMessageCount})}),(0,$.jsx)(`span`,{className:`font-mono text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.msgsValue`,{count:e.messageCount})}),e.backgroundCount>0?(0,$.jsxs)(`span`,{className:`text-[var(--status-info)]`,children:[`+`,e.backgroundCount]}):null]})]},e.id))})]}),(0,$.jsx)(`div`,{className:`flex gap-2 border-t border-[var(--interactive-border)] pt-2`,children:(0,$.jsxs)(da,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Y,{size:`sm`,variant:`outline`,className:`typography-meta`,onClick:()=>{u.map(dS),Object.keys(_),ee.map(fS),Object.fromEntries(l)},children:r(`memoryDebugPanel.actions.logState`)})}),(0,$.jsx)(la,{side:`top`,children:r(`memoryDebugPanel.tooltip.logCurrentState`)})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.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:[(0,$.jsx)(`span`,{children:r(o===`copied`?`memoryDebugPanel.streaming.copy.copied`:o===`error`?`memoryDebugPanel.streaming.copy.failed`:`memoryDebugPanel.streaming.copy.hint`)}),(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:re,children:r(`memoryDebugPanel.actions.copyJson`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.uiMetrics`),value:y.entries.length}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.vscodeMetrics`),value:x.entries.length}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.messageListRenders`),value:j.messageListRender}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.messageListStreamRenders`),value:j.messageListRenderStreaming}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.chatMessageRenders`),value:j.chatMessageRender}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.chatMessageStreamRenders`),value:j.chatMessageRenderStreaming}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.chatMessageStaticDuringStream`),value:j.chatMessageRenderStaticDuringStream}),(0,$.jsx)(Qx,{label:r(`memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn`),value:j.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),(0,$.jsx)($x,{title:r(`memoryDebugPanel.section.uiStreamingMetrics`),snapshot:y,emptyLabel:r(`memoryDebugPanel.section.noUiSamples`)}),x.entries.length>0?(0,$.jsx)($x,{title:r(`memoryDebugPanel.section.vscodeBridgeMetrics`),snapshot:x,emptyLabel:r(`memoryDebugPanel.section.noVscodeSamples`)}):null]}),t[85]=i,t[86]=te,t[87]=o,t[88]=c,t[89]=_,t[90]=B,t[91]=l,t[92]=ee,t[93]=u,t[94]=j,t[95]=y,t[96]=r,t[97]=v,t[98]=x,t[99]=be):be=t[99];let xe;return t[100]!==le||t[101]!==ye||t[102]!==be?(xe=(0,$.jsxs)(Xa,{className:`fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area`,style:U,children:[le,ye,be]}),t[100]=le,t[101]=ye,t[102]=be,t[103]=xe):xe=t[103],xe};function tS(e,t){return e+t.count}function nS(e){return e.currentSessionId}function rS(e){return e.sessionMemoryState}function iS(){return Ge()}function aS(e){return e.scope}function oS(e){return!!e}function sS(e){return e.totalRequestCount}function cS(){return Ke()}function lS(){return ze()}function uS(e,t){return t.lastAccessed-e.lastAccessed}function dS(e){return{id:e.id,title:e.title}}function fS(e){return{id:e.id,title:e.title,total:e.messageCount,user:e.userMessageCount,assistant:e.assistantMessageCount}}var pS=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=q.getState();if(e)return;let n=$o();n&&t(n)||D()&&j(`desktop_close_current_window`).catch(e=>{console.warn(`[menu-actions] failed to close current window`,e)})},mS=()=>{if(typeof document>`u`)return``;let e=document.activeElement;if(e instanceof HTMLTextAreaElement)return e.value.slice(e.selectionStart??0,e.selectionEnd??0);if(e instanceof HTMLInputElement){let t=e.type?.toLowerCase()??`text`;if([`text`,`search`,`url`,`tel`,`password`].includes(t))return e.value.slice(e.selectionStart??0,e.selectionEnd??0)}return e instanceof HTMLElement&&e.isContentEditable?e.ownerDocument.defaultView?.getSelection?.()?.toString()??``:``},hS=async()=>{let e=mS()||window.getSelection()?.toString()||``;if(!e.trim())return!1;try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}return document.execCommand(`copy`)},gS=`yuri:menu-action`,_S=`yuri:check-for-updates`,vS=e=>typeof e?.listen==`function`?`bridge`:`dom`,yS=e=>{let t=xn(e=>e.openNewSessionDraft),n=q(e=>e.toggleCommandPalette),r=q(e=>e.setCommandPaletteOpen),i=q(e=>e.toggleHelpDialog),a=q(e=>e.toggleSidebar),o=q(e=>e.setSessionSwitcherOpen),s=q(e=>e.setActiveMainTab),c=q(e=>e.setSettingsDialogOpen),l=q(e=>e.setSettingsPage),u=q(e=>e.setAboutDialogOpen),d=q(e=>e.toggleRightSidebar),f=q(e=>e.setRightSidebarOpen),p=q(e=>e.setRightSidebarTab),m=q(e=>e.toggleBottomTerminal),h=q(e=>e.setBottomTerminalExpanded),g=fs(e=>e.checkForUpdates),{setThemeMode:_}=or(),{t:v}=wt(),y=Q.useRef(!1),b=typeof window>`u`?null:window.__YURI_DESKTOP__,x=vS(b),S=Q.useCallback(()=>{y.current||(y.current=!0,g().then(()=>{let{available:e,error:t}=fs.getState();if(t){X.error(v(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}e||X.success(v(`sessions.sidebar.updateCheck.latestVersion`))}).finally(()=>{y.current=!1}))},[g,v]),C=Q.useCallback(()=>{yn.requestDirectoryDialog()},[]),w=Q.useCallback(e=>{pi(e,xn.getState().currentSessionId,e=>{s(`chat`),o(!1),xn.getState().setCurrentSession(e.sessionId,e.directory)})},[s,o]),T=Q.useCallback(e=>{let{activeProjectId:t,projects:n,setActiveProject:r}=An.getState();if(n.length===0)return;let i=n.findIndex(e=>e.id===t),a=e>0?0:n.length-1;i>=0&&(a=(i+e+n.length)%n.length);let o=n[a];o&&r(o.id)},[]),E=Q.useCallback(g=>{switch(g){case`about`:u(!0);break;case`settings`:c(!0);break;case`switch-instance`:l(`remote-instances`),c(!0);break;case`command-palette`:n();break;case`quick-open`:r(!0);break;case`new-session`:s(`chat`),o(!1),t();break;case`new-worktree-session`:s(`chat`),o(!1),ki();break;case`change-workspace`:C();break;case`close-tab-or-window`:pS();break;case`toggle-right-sidebar`:d();break;case`open-right-sidebar-git`:f(!0),p(`git`);break;case`open-right-sidebar-files`:f(!0),p(`files`);break;case`toggle-terminal`:m();break;case`toggle-terminal-expanded`:h(!q.getState().isBottomTerminalExpanded);break;case`copy`:{let e=new Event(`yuri:copy`,{cancelable:!0});window.dispatchEvent(e)&&hS();break}case`theme-light`:_(`light`);break;case`theme-dark`:_(`dark`);break;case`theme-system`:_(`system`);break;case`toggle-sidebar`:a();break;case`toggle-memory-debug`:e?.();break;case`zoom-in`:Li();break;case`zoom-out`:di();break;case`zoom-reset`:wi();break;case`go-back`:je.getState().goBack();break;case`go-forward`:je.getState().goForward();break;case`previous-session`:w(-1);break;case`next-session`:w(1);break;case`previous-project`:T(-1);break;case`next-project`:T(1);break;case`help-dialog`:i();break;case`download-logs`:zi().catch(()=>{X.error(`Failed to collect OpenCode status`)})}},[C,T,w,e,t,u,s,o,r,c,l,h,f,p,_,m,n,i,d,a]);Q.useEffect(()=>{if(x!==`dom`)return;let e=e=>{let t=e.detail;t&&E(t)},t=()=>{S()};return window.addEventListener(gS,e),window.addEventListener(_S,t),()=>{window.removeEventListener(gS,e),window.removeEventListener(_S,t)}},[E,S,x]),Q.useEffect(()=>{if(x!==`bridge`)return;let e=b?.listen;if(typeof e!=`function`)return;let t=null,n=null;return e(`yuri:menu-action`,e=>{let t=e?.payload;typeof t==`string`&&E(t)}).then(e=>{t=e}).catch(()=>{}),e(`yuri:check-for-updates`,S).then(e=>{n=e}).catch(()=>{}),()=>{(async()=>{try{let e=t?.();e instanceof Promise&&await e}catch{}try{let e=n?.();e instanceof Promise&&await e}catch{}})()}},[b,E,S,x])},bS=(e,t)=>e<t?-1:+(e>t),xS=e=>JSON.stringify([...e.entries()].map(([e,t])=>[e,[...new Set(t)].sort(bS)]).sort(([e],[t])=>bS(e,t)));async function SS({targets:e,isReady:t,fetchStatus:n,applySnapshot:r,concurrency:i=2,isDisposed:a=()=>!1}){if(!t()||a())return;let o=[...e.entries()],s=0,c=Math.min(Math.max(1,i),o.length),l=async()=>{for(;s<o.length&&t()&&!a();){let e=o[s];if(s+=1,!e)return;let[t,i]=e,c=await n(t);c===null||a()||r(t,c,i)}};await Promise.all(Array.from({length:c},()=>l()))}var CS=`yuri:tray-action`,wS=3e4,TS=120,ES=20,DS=()=>{if(typeof window>`u`)return!1;let e=window.__YURI_PLATFORM__;return e===`darwin`||e===`win32`},OS=e=>{let t=typeof e.permission==`string`?e.permission:`Permission`,n=Array.isArray(e.patterns)?e.patterns.find(e=>typeof e==`string`&&e.trim()):``;return n?`${t}: ${n}`:t},kS=e=>{let t=Array.isArray(e.questions)?e.questions[0]:void 0;return t?.header||t?.question||`Question`},AS=e=>on(e),jS=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},MS=(e,t,n,r)=>{if(!e)return``;let i=un(t,n,e),a=jS(i?i.path:e),o=ir(e),s=o&&r.get(o)||``;if(!s){for(let[e,t]of Do.getState().directories)if(ir(e)===o){s=t.status?.current??``;break}}if(!s)for(let e of n.values()){let t=e.find(e=>ir(e.path)===o);if(t?.branch){s=t.branch;break}}return s?`${a} · ${s}`:a},NS=()=>{let{results:e,dropdownProviderIds:t,displayMode:n}=Cs.getState(),r=n===`remaining`?`remaining`:`usage`;if(!t.length)return{mode:r,groups:[]};let i=new Map(e.map(e=>[e?.providerId,e])),a=[];for(let n of gs(e)){if(!t.includes(n.id))continue;let e=i.get(n.id);if(!e||e.configured!==!0)continue;let o=[];for(let[t,n]of Object.entries(e.usage?.windows??{})){let e=r===`remaining`?n.remainingPercent:n.usedPercent;o.push({label:ya(n.label??t),value:Fa(n.valueLabel,e)})}let s=!e.ok&&e.error?e.error:o.length===0?`No rate limits reported`:null;a.push({provider:n.name,rows:o,status:s})}return{mode:r,groups:a}},PS=async()=>{try{if(v())return`Local Yuri`;let e=window.__YURI_LOCAL_ORIGIN__||window.location.origin,t=m();if(t&&ae(t,e))return`Local Yuri`;let n=(await se()).hosts.find(e=>t?ae(t,oe(e)):!1);return n?.label?.trim()?W(n.label.trim()):`Instance`}catch{return``}},FS=()=>{let e=new Map,t=new Map,n=[],r=new Map,i;try{i=Je()}catch{return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}}for(let[a,o]of i.children.entries()){let i=o.getState(),s=typeof i.vcs?.branch==`string`?i.vcs.branch:typeof i.vcs?.branch?.current==`string`?i.vcs.branch.current:``;s&&t.set(ir(a)??a,s);for(let e of i.session)!e?.id||!e.title||r.set(e.id,e.title);for(let[t,n]of Object.entries(i.session_status??{})){let r=n?.type,i=r===`busy`?`busy`:r===`retry`?`retry`:`idle`,a=e.get(t);(!a||a===`idle`)&&e.set(t,i)}for(let[e,t]of Object.entries(i.permission??{}))for(let r of t??[]){if(!r?.id)continue;let t=r.sessionID||e;n.push({kind:`permission`,id:r.id,sessionId:t,sessionTitle:``,label:OS(r),directory:a})}for(let[e,t]of Object.entries(i.question??{}))for(let r of t??[]){if(!r?.id)continue;let t=r.sessionID||e;n.push({kind:`question`,id:r.id,sessionId:t,sessionTitle:``,label:kS(r),directory:a})}}return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}},IS=()=>{let e=en.getState().activeSessions,t=new Set;e.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>AS(t)-AS(e)).slice(0,ES).forEach(e=>{let n=Fn(e);n&&t.add(n)});let n=new Map;for(let r of e){if(!r?.id)continue;let e=Fn(r);if(!e||!t.has(e))continue;let i=n.get(e)??[];i.push(r.id),n.set(e,i)}return n},LS=e=>{let t=FS(),n=pn.getState().index.session,r=en.getState().activeSessions,i=new Map(t.titleById),a=new Map;for(let e of r)if(e?.id&&(e.title&&i.set(e.id,e.title),e.parentID)){let t=a.get(e.parentID)??[];t.push(e.id),a.set(e.parentID,t)}let o=e=>{let t=[],n=[...a.get(e)??[]],r=new Set;for(;n.length;){let e=n.pop();r.has(e)||(r.add(e),t.push(e),n.push(...a.get(e)??[]))}return t},s=nn.getState().statusById,c=e=>{let n=t.statusById.get(e);return n&&n!==`idle`?n:s.get(e)?.status??n??`idle`},l=e=>{let t=e.map(e=>c(e));return t.includes(`busy`)?`busy`:t.includes(`retry`)?`retry`:`idle`},u=An.getState().projects,d=xn.getState().availableWorktreesByProject,f=r.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>AS(t)-AS(e)).slice(0,ES).map(e=>{let r=[e.id,...o(e.id)],i=Fn(e)??``;return{id:e.id,title:e.title||`Untitled session`,status:l(r),branch:i?t.branchByDirectory.get(i)??``:``,unseen:n.unseenCount[e.id]??0,hasError:n.unseenHasError[e.id]??!1,directory:i,subtitle:MS(i,u,d,t.branchByDirectory)}}),p=t.approvals.map(e=>({...e,sessionTitle:i.get(e.sessionId)||``})),m=q.getState(),h=0;if(m.dockBadgeEnabled)for(let e of r)!e?.id||e.parentID||(n.unseenCount[e.id]??0)>0&&(h+=1);return{sessions:f,approvals:p,instanceName:e,usage:NS(),dockBadgeCount:h}},RS=()=>{Q.useEffect(()=>{if(!DS()||!D())return;let e=!1,t=``,n=null,r=``,i=()=>{if(e)return;let n=LS(r),i=JSON.stringify(n);i!==t&&(t=i,j(`desktop_tray_update`,n))};PS().then(t=>{e||(r=t,i())});let a=null,o=``,s=()=>{let e=Zn.getState();return e.isConnected&&e.connectionPhase===`connected`},c=()=>{if(a)return a;let t=IS();return o=xS(t),a=SS({targets:t,isReady:s,concurrency:2,isDisposed:()=>e,fetchStatus:async()=>{try{let e=await Le.getSdkClient().session.active();if(!e||typeof e!=`object`||Array.isArray(e))return null;let t={};for(let[n,r]of Object.entries(e))r?.type===`running`&&(t[n]={type:`busy`});return t}catch{return null}},applySnapshot:(e,t,n)=>{qt(e,t,[...n])}}).finally(()=>{a=null;let t=IS();!e&&s()&&xS(t)!==o&&c()}),a},l=()=>{e||n!==null||(n=window.setTimeout(()=>{n=null,i()},TS))},u=new Map,d=()=>{if(e)return;let t;try{t=Je()}catch{return}let n=new Set;for(let[e,r]of t.children.entries())n.add(e),u.has(e)||u.set(e,r.subscribe(()=>l()));for(let[e,t]of u)n.has(e)||(t(),u.delete(e))},f=null;try{f=Je().subscribeRegistry(()=>{d(),l()})}catch{}d();let p=pn.subscribe(()=>l()),m=en.subscribe(()=>{l(),s()&&xS(IS())!==o&&c()}),h=An.subscribe(()=>l()),g=xn.subscribe(()=>l()),_=Do.subscribe(()=>l()),v=q.subscribe(()=>l()),y=nn.subscribe(()=>l()),b=s(),x=Zn.subscribe(()=>{let e=s();e&&!b&&c(),b=e});b&&c();let S=Cs.subscribe(()=>l());Cs.getState().loadSettings().then(()=>{if(e)return;let{dropdownProviderIds:t,results:n}=Cs.getState();t.length>0&&t.some(e=>!n.some(t=>t?.providerId===e))&&Cs.getState().fetchAllQuotas()});let C=window.setInterval(()=>{let e=Cs.getState();e.autoRefresh&&e.dropdownProviderIds.length>0&&e.fetchAllQuotas()},Math.max(3e4,Cs.getState().refreshIntervalMs||6e4)),w=window.setInterval(()=>{d(),i()},wS);return i(),()=>{e=!0,n!==null&&window.clearTimeout(n),window.clearInterval(w),window.clearInterval(C),p(),m(),h(),g(),_(),v(),y(),x(),S(),f?.();for(let e of u.values())e();u.clear()}},[]),Q.useEffect(()=>{if(!DS()||typeof window>`u`)return;let e=window.__YURI_DESKTOP__?.listen;if(typeof e!=`function`)return;let t=e=>{e.type===`respond-permission`&&Jn(e.sessionId,e.id,e.response).catch(()=>{X.error(`Failed to respond to permission request`)})},n=null;return e(CS,e=>{let n=e?.payload;!n||typeof n!=`object`||typeof n.type!=`string`||t(n)}).then(e=>{n=e}).catch(()=>{}),()=>{try{let e=n?.();e instanceof Promise&&e.catch(()=>{})}catch{}}},[])},zS=`/api/notifications/stream`,BS=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),VS=e=>{if(!e||typeof e!=`object`)return null;let t=e,n=t.properties&&typeof t.properties==`object`?t.properties:null;return t.type!==`yuri: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,requireHidden:n.requireHidden===!0||n.requireHidden!==!1&&void 0}},HS=e=>{let t=(0,fl.c)(3),n=e?.enabled??!0,r,i;t[0]===n?(r=t[1],i=t[2]):(r=()=>{if(!n||F()||!z()||typeof window>`u`||typeof EventSource>`u`)return;let e=new EventSource(c().sse(zS));return e.onmessage=US,()=>{e.close()}},i=[n],t[0]=n,t[1]=r,t[2]=i),Q.useEffect(r,i)};function US(e){let t;try{t=JSON.parse(e.data)}catch{return}let n=q.getState();if(!n.nativeNotificationsEnabled)return;let r=VS(t);r&&((r.requireHidden??n.notificationMode!==`always`)&&BS()||g()?.notifications?.notifyAgentCompletion(r))}var WS=`pwa-install-toast-shown`,GS=`pwa-install-toast-dismissed`,KS=()=>{let e=(0,fl.c)(6),{browserTab:t}=As(),{t:n}=wt(),r=Q.useRef(n),i,a;e[0]===n?(i=e[1],a=e[2]):(i=()=>{r.current=n},a=[n],e[0]=n,e[1]=i,e[2]=a),Q.useEffect(i,a);let o,s;e[3]===t?(o=e[4],s=e[5]):(o=()=>{if(typeof window>`u`||!z()||!t)return;let e=null,n=null,i=()=>{n!==null&&(X.dismiss(n),n=null)},a=async()=>{if(!e)return;let t=e;e=null,i(),await t.prompt();let{outcome:n}=await t.userChoice;n===`accepted`&&X.success(r.current(`pwa.installPrompt.started`))},o=t=>{let o=t;if(typeof o.prompt!=`function`)return;o.preventDefault(),e=o;let s=Qe(),c=Ye();pc({dismissed:s.getItem(GS),sessionShown:c.getItem(WS),hasActiveToast:n!==null})&&(c.setItem(WS,`true`),n=X.info(r.current(`pwa.installPrompt.description`),{duration:1/0,action:{label:r.current(`pwa.installPrompt.action`),onClick:()=>{a()}},cancel:{label:r.current(`pwa.installPrompt.dismiss`),onClick:()=>{Qe().setItem(GS,`true`),i()}}}))},s=()=>{e=null,i(),X.success(r.current(`pwa.installPrompt.installed`))};return window.addEventListener(`beforeinstallprompt`,o),window.addEventListener(`appinstalled`,s),()=>{i(),window.removeEventListener(`beforeinstallprompt`,o),window.removeEventListener(`appinstalled`,s)}},s=[t],e[3]=t,e[4]=o,e[5]=s),Q.useEffect(o,s)};function qS(e){let t=typeof e?.sessionId==`string`?e.sessionId.trim():``;if(!t)return;let n=typeof e?.directory==`string`&&e.directory.trim().length>0?e.directory.trim():null;q.getState().setActiveMainTab(`chat`),xn.getState().setCurrentSession(t,n)}var JS=({open:e,onOpenChange:t})=>{let{t:n}=wt(),[r,i]=Q.useState(null),[a,o]=Q.useState(null);Q.useEffect(()=>{e&&(async()=>{try{let e=await _(`/api/system/info`);if(e.ok){let t=await e.json();if(typeof t.yuriVersion==`string`&&t.yuriVersion.trim()){i(t.yuriVersion);return}}}catch{}i(await Tt())})()},[e]),Q.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await _(`/api/opencode/upgrade-status`,{headers:{Accept:`application/json`}});if(!e.ok)return;let n=await e.json().catch(()=>null),r=typeof n?.currentVersion==`string`?n.currentVersion.trim():``;!t&&r&&o(r)}catch{}})(),()=>{t=!0}},[e]);let s=r;return(0,$.jsx)(pr,{open:e,onOpenChange:t,children:(0,$.jsx)(ur,{className:`max-w-xs p-5`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-center`,children:[(0,$.jsx)(xa,{width:48,height:48}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Yuri`}),(0,$.jsxs)(`div`,{className:`space-y-0.5 typography-meta text-muted-foreground`,children:[s&&(0,$.jsx)(`p`,{children:n(`aboutDialog.yuriVersionLabel`,{version:s})}),a&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openCodeVersionLabel`,{version:a})})]})]}),(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsxs)(`a`,{href:`https://github.com/yee94/yuri`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors`,children:[(0,$.jsx)(Z,{name:`github-fill`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:`GitHub`})]})}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground/60`,children:n(`aboutDialog.footerNote`)})]})})})},YS=(e,t)=>{let n=e.get(t);return typeof n==`string`&&n.trim()||null},XS=(e,t)=>{let n=e instanceof Error?e.message:t;return/oauth state required/i.test(n)?`Authorization session expired or was cleared during reload. Return to Yuri and click Authorize again.`:n},ZS=()=>{let e=ss(e=>e.completeAuth),[t,n]=Q.useState(`working`),[r,i]=Q.useState(`Completing MCP authorization...`);return Q.useEffect(()=>{if(typeof window>`u`){n(`error`),i(`Browser context unavailable.`);return}let t=new URLSearchParams(window.location.search),r=YS(t,`code`),a=Es(t),o=os(t),s=YS(t,`error`),c=YS(t,`error_description`);if(s){o&&_(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(c??s);return}(async()=>{try{if(!r)throw Error(`Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Yuri manually.`);let t=a;if(!t&&o){let e=await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`);if(e.ok){let n=await e.json().catch(()=>null);n?.name?.trim()&&(t={name:n.name.trim(),directory:typeof n.directory==`string`&&n.directory.trim()?n.directory.trim():null})}}if(!t?.name)throw Error(`Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Yuri manually.`);await e(t.name,r,t.directory),o&&await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`success`),i(`Authorization completed. You can close this tab and return to Yuri.`)}catch(e){o&&await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(XS(e,`Failed to complete MCP authorization.`))}})()},[e]),(0,$.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm dark:shadow-none`,children:[(0,$.jsxs)(`div`,{className:`space-y-3 text-center`,children:[(0,$.jsx)(`div`,{className:t===`error`?`text-[var(--status-error)]`:t===`success`?`text-[var(--status-success)]`:`text-[var(--status-info)]`,children:(0,$.jsx)(`h1`,{className:`typography-hero font-semibold`,children:t===`working`?`Completing Authorization`:t===`success`?`Authorization Complete`:`Authorization Failed`})}),(0,$.jsx)(`p`,{className:`typography-body text-muted-foreground`,children:r})]}),t!==`working`&&(0,$.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,$.jsx)(Y,{type:`button`,onClick:()=>{typeof window>`u`||window.location.replace(`/`)},children:`Return to Yuri`})})]})})},QS=()=>{let e=en(e=>e.startupSyncProgress.active),t=en(e=>e.startupSyncProgress.phase),n=en(e=>e.startupSyncProgress.completed),r=en(e=>e.startupSyncProgress.total),{locale:i,t:a}=wt(),[o,s]=Q.useState(!0),c=kt(i).startingApi;Q.useEffect(()=>{let e=!1,t=async()=>{try{let t=await(await _(`/health`,{signal:AbortSignal.timeout(4e3)})).json().catch(()=>null);if(e)return;let n=t?.openCodeStarting===!0||t?.isOpenCodeReady!==!0&&!t?.lastOpenCodeError;s(n)}catch{e||s(!0)}};t();let n=window.setInterval(()=>{t()},750);return()=>{e=!0,window.clearInterval(n)}},[]);let l=r>0?Math.round(n/r*100):0,u=t===`restoring`?a(`common.loading`):a(`sessions.startupSync.progress`,{completed:n,total:r});return Q.useLayoutEffect(()=>{let t=document.getElementById(`startup-session-progress`),i=document.getElementById(`startup-session-progress-track`),s=document.getElementById(`startup-session-progress-fill`),d=document.getElementById(`startup-session-progress-text`);if(!(!t||!i||!s||!d)){if(e){t.hidden=!1,s.style.width=`${l}%`,i.setAttribute(`aria-label`,a(`sessions.startupSync.title`)),i.setAttribute(`aria-valuemax`,String(Math.max(r,1))),i.setAttribute(`aria-valuenow`,String(n)),i.setAttribute(`aria-valuetext`,u),d.textContent=u;return}if(o){t.hidden=!1,s.style.width=`30%`,i.setAttribute(`aria-label`,c),i.setAttribute(`aria-valuetext`,c),d.textContent=c;return}t.hidden=!0}},[e,n,o,l,u,c,a,r]),null},$S=(e,t,n,r=350)=>n?Math.max(0,r-Math.max(0,t-e)):null;function eC(e){let t=(0,fl.c)(21),{transition:n,ready:r}=e,{t:i}=wt(),a=za(),[o,s]=Q.useState(0),c=n.epoch>o,l=a||c,u,d;if(t[0]!==c||t[1]!==a||t[2]!==r||t[3]!==n.epoch||t[4]!==n.startedAt?(u=()=>{if(!c||a)return;let e=$S(n.startedAt,Date.now(),r);if(e===null)return;let t=window.setTimeout(()=>{s(e=>Math.max(e,n.epoch))},e);return()=>window.clearTimeout(t)},d=[c,a,r,n.epoch,n.startedAt],t[0]=c,t[1]=a,t[2]=r,t[3]=n.epoch,t[4]=n.startedAt,t[5]=u,t[6]=d):(u=t[5],d=t[6]),Q.useEffect(u,d),!l)return null;let f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 opacity-70`,"aria-hidden":`true`,children:[(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 size-[28rem] -translate-x-1/2 -translate-y-1/2 rounded-full border border-[var(--interactive-border)]/40`}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 size-72 -translate-x-1/2 -translate-y-1/2 rounded-full bg-[var(--interactive-selection)]/10 blur-3xl`})]}),t[7]=f):f=t[7];let p;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`div`,{className:`mb-7 flex size-28 items-center justify-center rounded-[2rem] border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)]/75 shadow-2xl shadow-background/40`,children:(0,$.jsx)(xa,{width:76,height:76,isAnimated:!0})}),t[8]=p):p=t[8];let m;t[9]===i?m=t[10]:(m=i(`desktopHostSwitcher.transition.title`),t[9]=i,t[10]=m);let h;t[11]===m?h=t[12]:(h=(0,$.jsx)(`h1`,{className:`typography-title text-foreground`,children:m}),t[11]=m,t[12]=h);let g;t[13]===i?g=t[14]:(g=i(`desktopHostSwitcher.transition.description`),t[13]=i,t[14]=g);let _;t[15]===g?_=t[16]:(_=(0,$.jsx)(`p`,{className:`mt-2 typography-body text-muted-foreground`,children:g}),t[15]=g,t[16]=_);let v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`div`,{className:`mt-7 h-1 w-28 overflow-hidden rounded-full bg-[var(--surface-muted)]`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`h-full w-1/2 animate-pulse rounded-full bg-[var(--status-info)] motion-reduce:animate-none`})}),t[17]=v):v=t[17];let y;return t[18]!==h||t[19]!==_?(y=(0,$.jsxs)(`div`,{className:`fixed inset-0 z-[9998] flex items-center justify-center overflow-hidden bg-background/95 px-6 backdrop-blur-xl`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[f,(0,$.jsxs)(`div`,{className:`relative flex max-w-md animate-in flex-col items-center text-center fade-in zoom-in-95 duration-300 motion-reduce:animate-none`,children:[p,h,_,v]})]}),t[18]=h,t[19]=_,t[20]=y):y=t[20],y}var tC=jo(()=>dt(()=>import(`./OnboardingScreen-DTr_WxYY.js`).then(e=>({default:e.OnboardingScreen})),__vite__mapDeps([124,1,4,2,3,5,6,7,8,9,10,11,12,13,77,33,34,18,35,36,38,39,87]))),nC=36e5,rC=12e5,iC=()=>{let e=(0,fl.c)(3),t=q(dC),n=q(fC),r;return e[0]!==t||e[1]!==n?(r=(0,$.jsx)(JS,{open:t,onOpenChange:n}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r},aC=e=>{let t=(0,fl.c)(21),{onRetry:n,isRetrying:r}=e,{t:i}=wt(),a;t[0]===i?a=t[1]:(a=i(`startup.initRecovery.title`),t[0]=i,t[1]=a);let o;t[2]===a?o=t[3]:(o=(0,$.jsx)(`h1`,{className:`typography-title text-foreground`,children:a}),t[2]=a,t[3]=o);let s;t[4]===i?s=t[5]:(s=i(`startup.initRecovery.description`),t[4]=i,t[5]=s);let c;t[6]===s?c=t[7]:(c=(0,$.jsx)(`p`,{className:`typography-body text-muted-foreground`,children:s}),t[6]=s,t[7]=c);let l;t[8]!==o||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[o,c]}),t[8]=o,t[9]=c,t[10]=l):l=t[10];let u;t[11]!==r||t[12]!==i?(u=i(r?`startup.initRecovery.retrying`:`startup.initRecovery.retry`),t[11]=r,t[12]=i,t[13]=u):u=t[13];let d;t[14]!==r||t[15]!==n||t[16]!==u?(d=(0,$.jsx)(Y,{type:`button`,onClick:n,disabled:r,children:u}),t[14]=r,t[15]=n,t[16]=u,t[17]=d):d=t[17];let f;return t[18]!==l||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background px-6 text-foreground`,children:(0,$.jsxs)(`div`,{className:`flex max-w-md flex-col items-center gap-4 text-center`,children:[l,d]})}),t[18]=l,t[19]=d,t[20]=f):f=t[20],f},oC=e=>e?e.replace(/\\/g,`/`).replace(/\/+$/g,``):``,sC=()=>{if(typeof window>`u`||!uo())return null;let e=new URLSearchParams(window.location.search),t=e.get(`sessionId`),n=typeof t==`string`?t.trim():``;if(!n)return null;let r=e.get(`directory`);return{sessionId:n,directory:typeof r==`string`&&r.trim().length>0?r.trim():null,readOnly:e.get(`readOnly`)===`1`||e.get(`readOnly`)===`true`}},cC=()=>typeof window>`u`?!1:window.location.pathname===ps,lC=e=>{let t=(0,fl.c)(22),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=e,a=je(pC),o=xn(mC),s=xn(hC),c=Wi(),l=Q.useRef(null),u;t[0]===n.directory?u=t[1]:(u=oC(n.directory),t[0]=n.directory,t[1]=u);let d=u,f;t[2]===a?f=t[3]:(f=oC(a),t[2]=a,t[3]=f);let p=f,m,h;if(t[4]!==p||t[5]!==o||t[6]!==n.directory||t[7]!==n.sessionId||t[8]!==d||t[9]!==r||t[10]!==s||t[11]!==c?(m=()=>{if(r||d&&p!==d)return;let e=`${d}\n${n.sessionId}`;l.current===e&&o||(l.current=e,s(n.sessionId,n.directory),c.ensureSessionRenderable(n.sessionId,!0))},h=[p,o,n.directory,n.sessionId,d,r,s,c],t[4]=p,t[5]=o,t[6]=n.directory,t[7]=n.sessionId,t[8]=d,t[9]=r,t[10]=s,t[11]=c,t[12]=m,t[13]=h):(m=t[12],h=t[13]),Q.useEffect(m,h),d&&p!==d)return null;let g;t[14]===i?g=t[15]:(g=(0,$.jsx)(Mi,{embeddedBackgroundWorkEnabled:i}),t[14]=i,t[15]=g);let _;t[16]===n.readOnly?_=t[17]:(_=(0,$.jsx)(ac,{readOnly:n.readOnly}),t[16]=n.readOnly,t[17]=_);let v;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(ti,{}),t[18]=v):v=t[18];let y;return t[19]!==g||t[20]!==_?(y=(0,$.jsxs)($.Fragment,{children:[g,_,v]}),t[19]=g,t[20]=_,t[21]=y):y=t[21],y};function uC({apis:e}){Q.useEffect(()=>{We(`App:mounted`),He()},[]),Q.useEffect(()=>cn(),[]);let t=Zn(e=>e.initializeApp),n=Zn(e=>e.isInitialized),r=Zn(e=>e.isConnected),i=xn(e=>e.error),a=xn(e=>e.clearError),o=xn(e=>!(e.newSessionDraft?.open&&e.currentSessionId===null)),c=je(e=>e.currentDirectory),l=je(e=>e.setDirectory),u=je(e=>e.isSwitchingDirectory),[p,m]=Q.useState(!1),g=Ms(e=>e.refreshStatus),[_,b]=Q.useState(()=>e.runtime.isVSCode),[x,w]=Q.useState(!1),[T,D]=Q.useState(!1),[O,k]=Q.useState(0),[A,M]=Q.useState(0),[N,P]=Q.useState({epoch:0,startedAt:0}),[I,R]=Q.useState(!1),z=Q.useRef(!1),V=q(e=>e.wideChatLayoutEnabled),H=q(e=>e.mobileKeyboardMode),te=Q.useMemo(()=>F(),[]),re=en(e=>e.hasCachedSessionIndex),U=en(e=>e.hasHydratedSessionIndex),[ie,ae]=Q.useState(()=>S()),[W,oe]=Q.useState(()=>{let e=E();return e===null?null:B({isDesktopShell:!0,bootOutcome:e})}),se=Q.useRef(!1),ce=Q.useMemo(()=>sC(),[]),G=!ce||x,le=Q.useMemo(()=>cC(),[]);Q.useEffect(()=>(Me(p),()=>{Me(!1)}),[p]),Q.useEffect(()=>{Ze(H)},[H]),Q.useEffect(()=>{b(e.runtime.isVSCode)},[e.runtime.isVSCode]),Q.useEffect(()=>{let e=Qr(e=>{d(e)&&(te&&P(e=>({epoch:e.epoch+1,startedAt:Date.now()})),Cc(e),M(e=>e+1),D(!1),k(e=>e+1))}),t=s(t=>e.schedule(t));return()=>{t(),e.cancel()}},[te]);let ue=Sn(e=>{let t=f();return Object.values(e.runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t).map(e=>`${e.originalSessionID}:${e.phase}:${e.lastForwardedMessageID??``}:${e.expectedAssistantParentID??``}`).sort().join(`|`)});Q.useEffect(()=>{if(ce)return;let e=!1;return Ht().then(()=>{if(e)return;let t=f(),n=Object.values(Sn.getState().runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t);for(let e of n)mn(e.originalSessionID)}),()=>{e=!0}},[ue,ce,A]),Q.useEffect(()=>(document.documentElement.classList.toggle(`wide-chat-layout`,V),()=>{document.documentElement.classList.remove(`wide-chat-layout`)}),[V]),Q.useEffect(()=>(h(e),()=>h(null)),[e]),Q.useEffect(()=>{if(ce)return;let t=!1;return Ht().then(()=>{t||g(e.github,{force:!0})}),()=>{t=!0}},[e.github,ce,g]),Fi();let de=ie===`valid`,fe=W?.screen===`main`;Q.useEffect(()=>{if(!G||!C({isDesktopShell:te,isInitialized:te&&fe?re||n&&U:n,bootOutcomeKnown:de,bootViewIsMain:fe}))return;let e,t=setTimeout(()=>{let t=document.getElementById(`initial-loading`);t&&(t.classList.add(`fade-out`),e=setTimeout(()=>{t.remove()},300))},150);return()=>{clearTimeout(t),e&&clearTimeout(e)}},[G,te,n,de,fe,re,U]),Q.useEffect(()=>{if(!te||ie!==`malformed`)return;let e=document.getElementById(`initial-loading`);e&&(e.textContent=`Desktop startup failed — please restart the app.`)},[te,ie]),Q.useEffect(()=>{if(!G||te)return;let e,t=setTimeout(()=>{let t=document.getElementById(`initial-loading`);t&&!n&&(t.classList.add(`fade-out`),e=setTimeout(()=>{t.remove()},300))},5e3);return()=>{clearTimeout(t),e&&clearTimeout(e)}},[G,te,n]),Q.useEffect(()=>{if(!G||_)return;let e=!1;return Ht().then(()=>{if(!e)return t()}),()=>{e=!0}},[G,t,_]),Q.useEffect(()=>{if(!G||_||n)return;let e=!0,t,r=0,i=1e3,a=async()=>{if(!e)return;if(r>=10){D(!0);return}let n=Zn.getState();if(n.isInitialized){D(!1);return}if(r+=1,await Ht(),!e)return;await n.initializeApp();let o=Zn.getState();if(!e)return;if(o.isInitialized){D(!1);return}if(r>=10){D(!0);return}let s=Math.min(i*2**(r-1),16e3);t=setTimeout(a,s)};return t=setTimeout(a,i),()=>{e=!1,t&&clearTimeout(t)}},[G,O,n,_]),Q.useEffect(()=>{G&&n&&D(!1)},[G,n]),Q.useEffect(()=>{if(!G||!T)return;let e=document.getElementById(`initial-loading`);if(e){e.classList.add(`fade-out`);let t=setTimeout(()=>{e.remove()},300);return()=>clearTimeout(t)}},[G,T]),Hi({enabled:G&&!_,source:`startupRecovery`}),Q.useEffect(()=>{u||_||r&&Le.setDirectory(c)},[c,u,r,_]),Q.useEffect(()=>{if(!ce||typeof window>`u`)return;let e=e=>{let t=e?.visible===!0;w(t)},t=t=>{if(t.origin!==window.location.origin)return;let n=t.data;n?.type===`yuri:embedded-visibility`&&e(n.payload)},n=window;return n.__yuriSetEmbeddedVisibility=e,window.addEventListener(`message`,t),window.parent&&window.parent!==window&&window.parent.postMessage({type:lo},window.location.origin),()=>{window.removeEventListener(`message`,t),n.__yuriSetEmbeddedVisibility===e&&delete n.__yuriSetEmbeddedVisibility}},[ce]),Q.useEffect(()=>{!ce?.directory||_||c!==ce.directory&&l(ce.directory,{showOverlay:!1})},[c,ce,_,l]),Q.useEffect(()=>{if(!ce||typeof window>`u`)return;let e=e=>{e.storageArea===window.localStorage&&e.key===`ui-store`&&q.persist.rehydrate()};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}},[ce]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;qS(t??{})},t=e=>{let t=e.detail?.assistantID;typeof t==`string`&&t.trim()&&ar(t.trim())};return window.addEventListener(`yuri:open-session`,e),window.addEventListener(`yuri:open-assistant`,t),()=>{window.removeEventListener(`yuri:open-session`,e),window.removeEventListener(`yuri:open-assistant`,t)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=je.getState().currentDirectory,{activeProjectId:t,projects:n}=An.getState(),r=n.find(e=>e.id===t)??null;j(`desktop_open_draft_mini_chat_window`,{directory:e||r?.path||``,projectId:r?.id??null})};return window.addEventListener(`yuri:open-mini-chat`,e),()=>window.removeEventListener(`yuri:open-mini-chat`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=xn.getState().currentSessionId;e&&Wn(e)};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail,n=typeof t?.directory==`string`&&t.directory.trim().length>0?t.directory.trim():null,r=typeof t?.projectId==`string`&&t.projectId.trim().length>0?t.projectId.trim():null,i=typeof t?.initialPrompt==`string`&&t.initialPrompt.trim().length>0?t.initialPrompt.trim():void 0;q.getState().setActiveMainTab(`chat`),q.getState().setSessionSwitcherOpen(!1),xn.getState().openNewSessionDraft({selectedProjectId:r,directoryOverride:n,preserveDirectoryOverride:!!n,ensureProjectForDirectory:!!n,initialPrompt:i})};return window.addEventListener(`yuri:open-draft-session`,e),()=>window.removeEventListener(`yuri:open-draft-session`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail,n=typeof t?.projectPath==`string`?t.projectPath.trim():``;if(!n)return;let r=An.getState(),i=r.projects.find(e=>e.path===n);i?r.setActiveProject(i.id):r.addProject(n)};return window.addEventListener(`yuri:open-project`,e),()=>window.removeEventListener(`yuri:open-project`,e)},[]),Q.useEffect(()=>{typeof window>`u`||!G||!n||u||se.current||(se.current=!0,window.__yuriAppReady=!0,window.dispatchEvent(new Event(`yuri:app-ready`)))},[G,n,u]),ei({enabled:G}),HS({enabled:G}),KS(),Ui(),Zs(),yS(_t(()=>{m(e=>!e)})),Q.useEffect(()=>{ee()&&Fs().then(async e=>{e&&await ne(e)}).catch(console.warn)},[]),Q.useEffect(()=>{if(!n||!ee()||z.current)return;z.current=!0;let e=!1,t=null,r=null;fs.getState().subscribeDesktopUpdateEvents().then(t=>{if(e){t();return}r=t});let i=()=>{let e=fs.getState();e.checking||e.checkForUpdates()},a=n=>{t=window.setTimeout(()=>{e||(document.visibilityState===`visible`&&i(),a(nC))},n)},o=()=>{if(e||document.visibilityState!==`visible`)return;let t=fs.getState().lastChecked;t!=null&&Date.now()-t<rC||i()};return a(0),window.addEventListener(`focus`,o),()=>{e=!0,t!==null&&window.clearTimeout(t),window.removeEventListener(`focus`,o),r&&r()}},[n]),RS(),Q.useEffect(()=>{if(ce)return;let e=e=>{St(e)&&e.shiftKey&&!e.altKey&&(e.code===`KeyD`||e.key.toLowerCase()===`d`)&&(e.preventDefault(),m(e=>!e))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ce]),Q.useEffect(()=>{ce||i&&setTimeout(()=>a(),5e3)},[a,ce,i]),Q.useEffect(()=>{if(!te||ie!==`not-injected`)return;let e=!1,t=0,n=()=>{if(e)return;t++;let r=S();if(r!==`not-injected`){if(e=!0,ae(r),r===`valid`){let e=E();e&&oe(B({isDesktopShell:!0,bootOutcome:e}))}return}let i=Math.min(200*1.1**t,2e3);if(t>=50){let e=document.getElementById(`initial-loading`);e&&!e.textContent?.includes(`taking longer`)&&(e.textContent=`Desktop startup is taking longer than expected...`)}window.setTimeout(n,i)};return window.setTimeout(n,200),()=>{e=!0}},[te,ie]);let pe=_t(async()=>{if(y({isDesktopShell:F(),isDesktopLocalOriginActive:v()})){await L();return}window.location.reload()}),me=_t(async()=>{if(!I){D(!1),R(!0);try{await Ht(),await Zn.getState().initializeApp()}finally{R(!1)}Zn.getState().isInitialized||k(e=>e+1)}}),he=e=>{if(e.screen===`recovery`)return e.variant};if(te&&W&&W.screen!==`main`){if(W.screen===`chooser`)return(0,$.jsx)(pa,{children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-transparent`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-full`}),children:(0,$.jsx)(tC,{mode:`first-launch`,onCliAvailable:pe,onChooseRemote:()=>{}})})})});let e=he(W),t=W.screen===`recovery`&&`url`in W?W.url:void 0;return(0,$.jsx)(pa,{children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-transparent`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-full`}),children:(0,$.jsx)(tC,{mode:`recovery`,recoveryVariant:e,recoveryHostUrl:t,recoveryHostLabel:void 0,onCliAvailable:pe})})})})}if(ce)return sn(),(0,$.jsx)(pa,{children:(0,$.jsx)(Xt,{sdk:Le.getSdkClient(),directory:c||``,bootstrapDirectory:o,children:(0,$.jsx)(Ir,{apis:e,children:(0,$.jsx)(ua,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-background`,children:(0,$.jsx)(lC,{embeddedSessionChat:ce,isVSCodeRuntime:_,embeddedBackgroundWorkEnabled:G})})})})},A)});if(le)return(0,$.jsx)(pa,{children:(0,$.jsx)(ZS,{})});if(T&&!n&&!_&&!ce)return(0,$.jsx)(pa,{children:(0,$.jsx)(aC,{onRetry:()=>{me()},isRetrying:I})});let ge=!n&&!te;return(0,$.jsx)(pa,{children:(0,$.jsx)(Xt,{sdk:Le.getSdkClient(),directory:c||``,bootstrapDirectory:o,children:(0,$.jsx)(Ir,{apis:e,children:(0,$.jsx)(Xu,{children:(0,$.jsx)(ua,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsxs)(`div`,{className:te?`h-full text-foreground bg-transparent`:`h-full text-foreground bg-background`,children:[(0,$.jsx)(Mi,{embeddedBackgroundWorkEnabled:G}),(0,$.jsx)(Lc,{}),(0,$.jsx)(uc,{}),(0,$.jsx)(Xx,{}),te&&(0,$.jsx)(eC,{transition:N,ready:n&&r}),(0,$.jsx)(QS,{}),(0,$.jsx)(ti,{}),!ge&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Fc,{}),(0,$.jsx)(Sc,{}),(0,$.jsx)(iC,{}),p&&(0,$.jsx)(eS,{onClose:()=>m(!1)})]})]})})})})},A)})}function dC(e){return e.isAboutDialogOpen}function fC(e){return e.setAboutDialogOpen}function pC(e){return e.currentDirectory}function mC(e){return e.currentSessionId}function hC(e){return e.setCurrentSession}if(typeof window<`u`&&!window.__YURI_REFRESH_DEBUG_INSTALLED__){window.__YURI_REFRESH_DEBUG_INSTALLED__=!0;let e=performance.getEntriesByType(`navigation`)[0];console.warn(`[refresh-debug] renderer-entry`,{navigationType:e?.type??`unknown`,protocol:window.location.protocol}),window.addEventListener(`beforeunload`,()=>{console.warn(`[refresh-debug] beforeunload`,{visibilityState:document.visibilityState})}),window.addEventListener(`pagehide`,e=>{console.warn(`[refresh-debug] pagehide`,{persisted:e.persisted})})}var gC=typeof window<`u`&&window.__YURI_RUNTIME_APIS__||(()=>{throw Error(`Runtime APIs not provided for legacy UI entrypoint.`)})();Nt(),F()&&tr(),Ur({runtimeKey:f(),initializeAppearance:re,syncSettings:H,applyDirectory:Wr,startWatchers:()=>{Xr(),Rr(),Br()},onError:(e,t)=>{console.error(e===`appearance`?`[main] appearance init failed:`:`[main] settings init failed:`,t)}});var _C=document.getElementById(`root`);if(!_C)throw Error(`Root element not found`);(0,dl.createRoot)(_C).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(ni,{children:(0,$.jsx)(Et,{children:(0,$.jsx)(Ci,{children:(0,$.jsx)(Fr,{children:(0,$.jsx)(xi,{children:(0,$.jsx)(Kr,{children:(0,$.jsx)(uC,{apis:gC})})})})})})})}));
169
+ Now write the final fused answer.`,synthetic:!0}],directory:i??Le.getDirectory()})}catch(e){console.error(`[MultiRunFusion] Failed to start fusion`,e),X.error(r(`multirun.fusion.toast.failed`))}finally{w(!1)}}},disabled:!k,children:r(C?`multirun.fusion.actions.starting`:`multirun.fusion.actions.start`)})]})]})})}function Pb(e){let t=(0,pl.c)(13),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=[`yuri-icon`,n].filter(Boolean),t[3]=n,t[4]=i);let a=i.join(` `),o,s,c,l,u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.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`}),s=(0,$.jsx)(`path`,{d:`M9.25 7.25 12 4.5l2.75 2.75`}),c=(0,$.jsx)(`circle`,{cx:`4`,cy:`17.25`,r:`1.55`}),l=(0,$.jsx)(`circle`,{cx:`12`,cy:`17.25`,r:`1.55`}),u=(0,$.jsx)(`circle`,{cx:`20`,cy:`17.25`,r:`1.55`}),t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u):(o=t[5],s=t[6],c=t[7],l=t[8],u=t[9]);let d;return t[10]!==r||t[11]!==a?(d=(0,$.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:cr,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:a,...r,children:[o,s,c,l,u]}),t[10]=r,t[11]=a,t[12]=d):d=t[12],d}var Fb=1/3,Ib=1,Lb=({containerScrollTop:e,containerClientHeight:t,containerScrollHeight:n,rowOffsetFromViewportTop:r})=>{let i=e+(r-t*Fb),a=Math.max(0,n-t);return Math.min(a,Math.max(0,i))},Rb=()=>typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,zb=e=>{let t=e.closest(`.overlay-scrollbar-target`);if(t)return t;let n=e.parentElement;for(;n&&n!==document.body;){let e=window.getComputedStyle(n).overflowY;if(e===`auto`||e===`scroll`||e===`overlay`)return n;n=n.parentElement}return null},Bb=(e,t)=>{let n=zb(e),r=t?.behavior??Rb();if(!n){e.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:r});return}let i=e.getBoundingClientRect(),a=n.getBoundingClientRect().top+n.clientTop,o=a+n.clientHeight;if(i.top>=a&&i.bottom<=o)return;let s=Lb({containerScrollTop:n.scrollTop,containerClientHeight:n.clientHeight,containerScrollHeight:n.scrollHeight,rowOffsetFromViewportTop:i.top-a});Math.abs(s-n.scrollTop)<Ib||n.scrollTo({top:s,behavior:r})},Vb=e(Te(),1),Hb=null,Ub=!1,Wb=(e,t=Ui.getState().focus)=>e===null?null:typeof e==`string`?t?.sessionId===e?t:xi(e):e,Gb=e=>{typeof window>`u`||(e.commitFrame!==null&&window.cancelAnimationFrame(e.commitFrame),e.paintFrame!==null&&window.cancelAnimationFrame(e.paintFrame),e.fallbackTimer!==null&&window.clearTimeout(e.fallbackTimer))},Kb=()=>{Hb&&=(Gb(Hb),null)},qb=(e,t)=>{Kb(),Nn(!0);let n=Wb(e);if(!n)return;Ub=!0;let r;try{r=On(n.sessionId)}finally{Ub=!1}Hb={commit:t,commitFrame:null,fallbackTimer:null,focus:n,intent:r,paintFrame:null,scheduled:!1},(0,Vb.flushSync)(()=>{Ui.getState().setFocus(n)}),typeof window<`u`&&(Hb.fallbackTimer=window.setTimeout(()=>{Jb(n)},150))},Jb=e=>{let t=Hb,n=Wb(e);if(!t||!ui(t.focus,n)||t.scheduled)return;t.scheduled=!0,typeof window<`u`&&t.fallbackTimer!==null&&(window.clearTimeout(t.fallbackTimer),t.fallbackTimer=null);let r=()=>{Hb===t&&Un()===t.intent&&(Hb=null,gn(),t.commit())};if(typeof window>`u`){r();return}t.commitFrame=window.requestAnimationFrame(()=>{Hb===t&&Un()===t.intent&&(t.paintFrame=window.requestAnimationFrame(r))})},Yb=e=>{if(Hb)return;let t=Ui.getState();t.setFocus(Wb(e,t.focus))};Vn(e=>{if(Ub)return;let t=Hb;if(t?.intent===e)return;t&&Kb();let n=Ui.getState();n.setFocus(Wb(e.sessionId,n.focus))});var Xb=e=>{let t=[],n=e=>{e.children.forEach(e=>{t.push(e.session.id),n(e)})};return n(e),t},Zb=Q.memo(function(e){let t=(0,pl.c)(21),{pinned:n,pinLabel:r,buttonSizeClass:i,iconSizeClass:a,onPointerDown:o,onMouseDown:s,onPin:c}=e,l=n?`text-foreground`:`text-muted-foreground`,u;t[0]!==i||t[1]!==l?(u=J(`inline-flex items-center justify-center rounded-md hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,l,i),t[0]=i,t[1]=l,t[2]=u):u=t[2];let d=n?`pushpin-2-fill`:`pushpin-2`,f=!n&&`rotate-45`,p;t[3]!==a||t[4]!==f?(p=J(a,f),t[3]=a,t[4]=f,t[5]=p):p=t[5];let m;t[6]!==d||t[7]!==p?(m=(0,$.jsx)(Z,{name:d,className:p}),t[6]=d,t[7]=p,t[8]=m):m=t[8];let h;t[9]!==s||t[10]!==c||t[11]!==o||t[12]!==r||t[13]!==u||t[14]!==m?(h=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:u,"aria-label":r,onPointerDown:o,onMouseDown:s,onClick:c,onKeyDown:ux,children:m})}),t[9]=s,t[10]=c,t[11]=o,t[12]=r,t[13]=u,t[14]=m,t[15]=h):h=t[15];let g;t[16]===r?g=t[17]:(g=(0,$.jsx)(da,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:r}),t[16]=r,t[17]=g);let _;return t[18]!==h||t[19]!==g?(_=(0,$.jsxs)(pa,{children:[h,g]}),t[18]=h,t[19]=g,t[20]=_):_=t[20],_}),Qb=Q.memo(function(e){let t=(0,pl.c)(24),{archiveLabel:n,deleteLabel:r,deleteOnly:i,buttonSizeClass:a,iconSizeClass:o,revealClassName:s,onPointerDown:c,onMouseDown:l,onArchive:u,onDelete:d}=e,f=i!==void 0&&i,p=fb(),m=f||p,h=m?r:n,g;t[0]!==f||t[1]!==u||t[2]!==d||t[3]!==p?(g=e=>{if(f||p||e.shiftKey){d(e);return}u(e)},t[0]=f,t[1]=u,t[2]=d,t[3]=p,t[4]=g):g=t[4];let _=g,v=m?`text-destructive hover:text-destructive hover:bg-[color-mix(in_srgb,var(--status-error)_12%,transparent)]`:`text-muted-foreground hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,y;t[5]!==a||t[6]!==s||t[7]!==v?(y=J(`inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,v,a,s),t[5]=a,t[6]=s,t[7]=v,t[8]=y):y=t[8];let b=m?`delete-bin`:`inbox-archive`,x;t[9]!==o||t[10]!==b?(x=(0,$.jsx)(Z,{name:b,className:o}),t[9]=o,t[10]=b,t[11]=x):x=t[11];let S;t[12]!==_||t[13]!==h||t[14]!==l||t[15]!==c||t[16]!==y||t[17]!==x?(S=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:y,"aria-label":h,onPointerDown:c,onMouseDown:l,onClick:_,onKeyDown:dx,children:x})}),t[12]=_,t[13]=h,t[14]=l,t[15]=c,t[16]=y,t[17]=x,t[18]=S):S=t[18];let C;t[19]===h?C=t[20]:(C=(0,$.jsx)(da,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:h}),t[19]=h,t[20]=C);let w;return t[21]!==S||t[22]!==C?(w=(0,$.jsxs)(pa,{children:[S,C]}),t[21]=S,t[22]=C,t[23]=w):w=t[23],w}),$b=Q.memo(function(e){let t=(0,pl.c)(3),{number:n}=e;if(!Ob())return null;let r=kt()?`⌘${n}`:`Ctrl+${n}`,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(bi,{"data-sidebar-shortcut-number":n,className:`h-3.5 min-w-0 shrink-0 rounded-full border-0 bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] px-1.5 font-sans text-[10px] font-medium tracking-tight text-muted-foreground/65 shadow-none`,"aria-hidden":`true`,children:r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i});function ex(e){let{t:n}=Tt(),{node:r,depth:i=0,groupDirectory:a,projectId:o,archivedBucket:s=!1,pinnedSessionIds:c,expandedParents:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:d,editingId:f,setEditingId:p,editTitle:h,setEditTitle:g,handleSaveEdit:_,handleCancelEdit:v,toggleParent:y,handleSessionSelect:b,handleSessionDoubleClick:x,togglePinnedSession:S,handleShareSession:C,copiedSessionId:w,handleCopyShareUrl:T,handleUnshareSession:E,setOpenSidebarMenuKey:O,renamingFolderId:k,getFoldersForScope:A,getSessionFolderId:M,removeSessionFromFolder:N,addSessionToFolder:P,createFolderAndStartRename:F,openContextPanelTab:L,handleDeleteSession:R,mobileVariant:z,alwaysShowActions:B,renderSessionNode:V,secondaryMeta:ee,renderContext:H=`project`,subtreeContainsActive:ne,subtreeContainsEditing:re,menuOpenSessionId:U,childRenderExtrasFor:ie,liveSessionById:ae,shortcutNumber:W=null}=e,oe=!!ee?.projectLabel,se=!!ee?.branchLabel,ce=qt(e=>e.displayMode),G=Q.useMemo(()=>te(),[]),le=ce===`minimal`||G,ue=Q.useMemo(()=>D(),[]),ve=Q.useContext(ot),ye=G?`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`,be=G,Se=H===`pinned`&&c.has(r.session.id),we=!Se&&!s&&!z,Te=`h-5 w-5`,Ee=`h-3.5 w-3.5`,De=(we||Se?1:0)+ +!!be+1,Oe=De>=3?`group-hover:pr-18 group-focus-within:pr-18`:De>=2?`group-hover:pr-12 group-focus-within:pr-12`:`group-hover:pr-7 group-focus-within:pr-7`,je=De>=2?`pr-12`:`pr-8`,Me=Q.useRef(!1),Ne=Q.useRef(!1),[K,Pe]=Q.useState(!1),Fe=Q.useRef(f);Fe.current=f;let Le=Q.useRef(null),Re=Q.useRef(_);Re.current=_;let[ze,Be]=Q.useState(h),[He,Ue]=Q.useState(null),We=Q.useRef(ze);We.current=ze;let Ge=Q.useRef(null),Ke=Q.useRef(null),qe=Q.useRef(null),Je=r.session,Ye=ae.get(Je.id)??Je,Xe=!!Ye.metadata?.yuri?.assistant,q=I(Je.directory??null)??I(a??null),Ze=fn(q??void 0,{bootstrap:!1}),Qe=oi(),$e=$y(e=>e.enabled),et=$y(Q.useMemo(()=>e=>e.selectedIds.has(Je.id),[Je.id])),tt=$y(e=>e.toggleSelected),nt=$y(e=>e.setRange),[rt,it]=Q.useState(!1),[at,st]=Q.useState(!0),[ct,lt]=Q.useState(!1),[ut,dt]=Q.useState(!1),ft=`${H}:${s?`archived`:`active`}:${Je.id}`,pt=Ht(Q.useMemo(()=>e=>!!e.sessionMemoryState.get(Zn(Je.id))?.isZombie,[Je.id])),mt=En(Je.id),ht=wn(Je.id,q??void 0,{bootstrap:!1}),gt=An(Je.id,q??void 0,{bootstrap:!1}),_t=Q.useMemo(()=>({scope:H,sessionId:Je.id,projectId:o??null}),[o,H,Je.id]),yt=Q.useMemo(()=>yi(_t)??``,[_t]),xt=Q.useRef(null),St=Ui(Q.useMemo(()=>e=>ui(e.focus,_t),[_t]));Q.useLayoutEffect(()=>{if(!St)return;let e=xt.current;e&&(z?e.scrollIntoView({block:`nearest`,inline:`nearest`}):Bb(e)),Jb(_t)},[St,z,_t]);let Ct=Ye.title||n(`sessions.sidebar.session.untitled`),wt=_o(go(Ye)),Et=Ye.metadata?.yuri?.titleRefresh,Dt=typeof Et?.lastError==`string`?Et.lastError:null,Ot=typeof Et?.failedAt==`number`?Et.failedAt:null;Q.useEffect(()=>{!Dt||Ot===null||(Ue(null),console.warn(`[session-title] generation failed for ${Je.id}: ${Dt}`))},[Je.id,Dt,Ot]),Q.useEffect(()=>{if(He===null)return;if(Ct!==He){Ue(null);return}let e=window.setTimeout(()=>Ue(null),3e4);return()=>window.clearTimeout(e)},[He,Ct]);let kt=r.children.length>0||!!(Ye.hasChildren??Je.hasChildren),At=c.has(Je.id),jt=ft,Mt=u?!0:l.has(jt),Nt=!!Ye.parentID,Pt=H===`pinned`,Ft=pn(Je.id)>0&&!Nt,It=sn(Ye)||Date.now(),Lt=eo(It),Rt=Ya(It),[zt,Bt]=Q.useState(!1),Vt=zt,Ut=Q.useMemo(()=>ol(Ye.title)!==null,[Ye.title]),[Wt,Gt]=Q.useState(!1),Kt=Q.useMemo(()=>Xb(r).length,[r]),Jt=vt(e=>{let t=q??``,n=(Ae()??ke(t,Ze)).getTranscript(Ie(t,e)),r=Ze.getState().session.find(t=>t.id===e)?.revert?.messageID;return $t({sessionID:e,messages:Ve(n),parts:n.partsByMessageID,revertMessageID:r}).list}),Yt=vt(async e=>{let t=[],r=0;for(let i of e)try{await Qe.ensureSessionRenderable(i.session.id);let e=Jt(i.session.id),a=i.session.title||n(`sessions.sidebar.session.export.untitledSubagent`),o=i.session.agent,s=await Yt(i.children);r+=s.skipped,t.push({title:a,agent:o,records:e,children:s.children})}catch{r+=Xb(i).length+1}return{children:t,skipped:r}}),Xt=vt(e=>{e<=0||X.warning(n(e===1?`sessions.sidebar.session.export.skippedSubtaskSingle`:`sessions.sidebar.session.export.skippedSubtaskMany`,{count:e}))}),Zt=vt(async e=>{if(!q){X.error(n(`sessions.sidebar.session.export.nothingToExport`));return}await Qe.ensureSessionRenderable(Je.id);let t=Jt(Je.id);if(t.length===0){X.error(n(`sessions.sidebar.session.export.nothingToExport`));return}let i,a=0;if(e&&r.children.length>0){let e=await Yt(r.children);i=e.children,a=e.skipped}let o=Ky(t,Ye.title??null,i),s=Zy(Ye.title??null),c=await Jy(o,s);if(c){X.success(n(`sessions.sidebar.session.export.success`),{action:{label:n(Xy()),onClick:()=>{Yy(c).then(e=>{e||X.error(n(`sessions.sidebar.session.export.failedRevealPath`))})}}}),Xt(a);return}qy(o,s),X.success(n(`sessions.sidebar.session.export.success`)),Xt(a)}),Qt=vt(async()=>{if(r.children.length>0){st(!0),it(!0);return}await Zt(!1)}),en=vt(()=>{q&&j(`desktop_open_session_mini_chat_window`,{sessionId:Je.id,directory:q,apiBaseUrl:m(),clientToken:t()}).catch(e=>{console.warn(`[session-sidebar] failed to open mini chat window`,e)})});bt(Ke,()=>{Re.current(We.current)},f===Je.id),Q.useLayoutEffect(()=>{if(f!==Je.id){Ge.current===Je.id&&(Ge.current=null);return}Ge.current!==Je.id&&(Ge.current=Je.id,Be(h),queueMicrotask(()=>qe.current?.select()))},[f,h,Je.id]);let tn=vt(e=>{if(!e&&Le.current){let{id:e,title:t}=Le.current;Le.current=null,p(e),g(t)}}),nn=vt(e=>{Bt(e)}),rn=vt(e=>{e.preventDefault(),e.stopPropagation()}),an=vt(e=>{e.preventDefault(),e.stopPropagation()}),on=vt(e=>{e.preventDefault(),e.stopPropagation(),O(null),S(Je.id)}),cn=vt(e=>{e.preventDefault(),e.stopPropagation(),O(null),R(Je,{archivedBucket:s})}),ln=vt(e=>{e.preventDefault(),e.stopPropagation(),O(null),R(Je,{archivedBucket:s,hardDelete:!0,skipConfirm:!0})}),un=vt(e=>{e.preventDefault(),e.stopPropagation(),O(null),S(Je.id)}),dn=vt(()=>{!q||ct||(lt(!0),(async()=>{try{await Qe.refreshSessionTranscript(Je.id,{directory:q}),X.success(n(`sessions.sidebar.session.menu.refreshTranscriptSuccess`))}catch{X.error(n(`sessions.sidebar.session.menu.refreshTranscriptFailed`))}finally{lt(!1)}})())}),mn=vt(e=>{e.preventDefault(),e.stopPropagation()}),hn=vt(e=>{e.preventDefault(),e.stopPropagation()}),gn=vt(e=>{e.preventDefault(),e.stopPropagation(),ve?.vscode?.executeCommand(`yuri.openSessionInEditor`,Je.id,Ct)}),_n=vt(e=>{if(Me.current){Me.current=!1;return}if($e){if(e?.preventDefault(),e?.stopPropagation(),e?.shiftKey){let e=(typeof document<`u`?Array.from(document.querySelectorAll(`[data-session-row]`)):[]).map(e=>e.getAttribute(`data-session-row`)).filter(e=>typeof e==`string`&&e.length>0),t=$y.getState().anchorId,n=new Map;n.set(Je.id,Xb(r)),nt(t,Je.id,e,q??null,n);return}tt(Je.id,q??null,Xb(r));return}b(Je.id,q,o,H)}),vn=vt(e=>{e.defaultPrevented||e.target?.closest(`button, a, input, [role="menuitem"], [role="menu"]`)||_n(e)}),yn=vt(e=>{(e.button===2||e.button===0&&e.ctrlKey&&!$e)&&(Me.current=!0)}),bn=vt(e=>{Ne.current=e.pointerType===`mouse`,z&&e.pointerType===`touch`&&Pe(!0)}),xn=vt(e=>{z&&e.pointerType===`touch`&&Pe(!1)}),Sn=vt(e=>{e.key!==`Enter`||!Ne.current||(e.preventDefault(),e.stopPropagation(),x(Je.id,Ct))}),Cn=vt(e=>{if(_n(e),!Ne.current)return;let t=e.currentTarget;window.requestAnimationFrame(()=>{Ne.current=!0,t.focus({preventScroll:!0})})}),Tn=vt(()=>{Ne.current=!1}),Dn=vt(e=>{if(!Ne.current)return;let t=e.relatedTarget;if(t instanceof Node&&e.currentTarget.contains(t))return;let n=document.activeElement;!(n instanceof HTMLElement)||!e.currentTarget.contains(n)||(n.blur(),Ne.current=!1)}),On=vt(()=>{!Mt&&!ut&&(dt(!0),Qe.loadChildren(Je.id,q).catch(()=>X.error(n(`sessions.sidebar.session.subsessions.loadFailed`))).finally(()=>dt(!1))),y(jt)});if(f===Je.id){let e=async()=>{Ue(Ct),v();try{await Rn(Je.id)}catch(e){Ue(null),console.warn(`[session-sidebar] failed to request smart title:`,e)}};return(0,$.jsx)(`div`,{className:`group relative my-0.5 flex items-center rounded-lg py-1.5 pr-2`,style:{paddingLeft:$a(i)},children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0`,children:[(0,$.jsxs)(`form`,{ref:Ke,className:`flex w-full items-center gap-2`,onSubmit:e=>{e.preventDefault(),_(ze)},children:[(0,$.jsx)(`input`,{ref:qe,value:ze,onChange:e=>Be(e.target.value),className:`flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground`,autoFocus:!0,placeholder:n(`sessions.sidebar.session.menu.rename`),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Escape`){v();return}}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},"aria-label":n(`sessions.sidebar.session.rename.smartTitle`),title:n(`sessions.sidebar.session.rename.smartTitle`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`ai-generate-2`,className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`submit`,"aria-label":n(`sessions.sidebar.session.rename.save`),title:n(`sessions.sidebar.session.rename.save`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(Z,{name:`check`,className:`size-3.5`})})]}),le?null:(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight`,style:{fontSize:`calc(var(--text-ui-label) * 0.85)`},children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[kt&&!Pt&&!Nt?(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center flex-shrink-0`,children:Mt?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,(0,$.jsx)(`span`,{className:`flex-shrink-0`,children:Lt}),oe?(0,$.jsx)(`span`,{className:`truncate`,children:ee?.projectLabel}):null,se?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.branchLabel})]}):null]})})]})},Je.id)}let kn=mt,jn=He!==null||Et?.isGenerating===!0,Mn=ht.length,Nn=gt.length>0,Pn=Nn||kn||!Nn&&!kn&&Ft,Fn=!B||G,In=Nn?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.questionRequired`),title:n(`sessions.sidebar.session.status.questionRequired`),children:(0,$.jsx)(Z,{name:`question`,className:`h-3.5 w-3.5 text-primary`})}):kn?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.active`),title:n(`sessions.sidebar.session.status.active`),children:(0,$.jsx)(Vc,{})}):(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":n(`sessions.sidebar.session.status.unread`),title:n(`sessions.sidebar.session.status.unread`),children:(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-[var(--status-info)]`})}),Ln=!Pt&&!Nt&&kt,zn=Ln&&!B&&!ut,Bn=$a(Math.max(0,i-1)),Vn=Ln?(0,$.jsx)(`span`,{role:`button`,tabIndex:0,"aria-expanded":Mt,"aria-busy":ut,onClick:e=>{e.stopPropagation(),e.currentTarget.blur(),On()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),On())},style:{minWidth:14,minHeight:14,left:Bn},className:J(`absolute inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity`,le?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,zn?`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":n(Mt?`sessions.sidebar.session.subsessions.collapse`:`sessions.sidebar.session.subsessions.expand`),children:ut?(0,$.jsx)(Vc,{size:12}):Mt?(0,$.jsx)(Z,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(Z,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,Hn=pt?(0,$.jsx)(Z,{name:`error-warning`,className:`h-4 w-4 text-status-warning`}):null,Un=(0,$.jsx)(pe,{children:(0,$.jsx)(ge,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(me,{"data-slot":`dropdown-menu-content`,finalFocus:()=>!(k||Fe.current),style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:J(co,`min-w-[180px]`),children:(({Item:e,Separator:t,Sub:r,SubTrigger:i,SubContent:a})=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(e,{onClick:()=>{Le.current={id:Je.id,title:Ct}},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`pencil-ai`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.rename`)]}),(0,$.jsxs)(e,{onClick:()=>S(Je.id),className:`[&>svg]:mr-1`,children:[At?(0,$.jsx)(Z,{name:`unpin`,className:`mr-1 h-4 w-4`}):(0,$.jsx)(Z,{name:`pushpin`,className:`mr-1 h-4 w-4`}),n(At?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`)]}),tr()&&!Ye.share?(0,$.jsxs)(e,{onClick:()=>C(Ye),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`share-2`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.share`)]}):tr()&&Ye.share?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onClick:()=>{Ye.share?.url&&T(Ye.share.url,Je.id)},className:`[&>svg]:mr-1`,children:w===Je.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{name:`check`,className:`mr-1 h-4 w-4`,style:{color:`var(--status-success)`}}),n(`sessions.sidebar.session.menu.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{name:`file-copy`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.copyLink`)]})}),(0,$.jsxs)(e,{onClick:()=>E(Je.id),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`link-unlink-m`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.unshare`)]})]}):null,(0,$.jsxs)(e,{onClick:()=>{Qt()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`download`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.exportMarkdown`)]}),(0,$.jsxs)(e,{disabled:!q||ct,onClick:()=>{dn()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`refresh`,className:J(`mr-1 h-4 w-4`,ct&&`animate-spin`)}),n(`sessions.sidebar.session.menu.refreshTranscript`)]}),Ut?(0,$.jsxs)(e,{onClick:()=>Gt(!0),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Pb,{className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.runFusion`)]}):null,q&&!s?(()=>{let o=A(q),s=M(q,Je.id);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(t,{}),(0,$.jsxs)(r,{children:[(0,$.jsxs)(i,{className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`folder`,className:`h-4 w-4`}),n(`sessions.sidebar.folders.moveToFolder`)]}),(0,$.jsxs)(a,{className:`min-w-[180px]`,children:[o.length===0?(0,$.jsx)(e,{disabled:!0,className:`text-muted-foreground`,children:n(`sessions.sidebar.folders.none`)}):o.map(t=>(0,$.jsxs)(e,{onClick:()=>{s===t.id?N(q,Je.id):P(q,t.id,Je.id)},children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),s===t.id?(0,$.jsx)(Z,{name:`check`,className:`ml-2 h-3.5 w-3.5 text-primary flex-shrink-0`}):null]},t.id)),(0,$.jsx)(t,{}),(0,$.jsxs)(e,{onClick:()=>{let e=F(q);e&&P(q,e.id,Je.id)},children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.newFolderEllipsis`)]}),s?(0,$.jsxs)(e,{onClick:()=>{N(q,Je.id)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]})]})})():null,G?null:(0,$.jsxs)(e,{disabled:!q,onClick:()=>{q&&L(q,{mode:`chat`,dedupeKey:`session:${Je.id}`,label:Ct,sessionTitleFallback:Ct})},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`chat-thread`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`sessions.sidebar.session.menu.openInSidePanel`)}),(0,$.jsx)(`span`,{className:`shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10`,children:n(`sessions.sidebar.session.menu.betaBadge`)})]}),ue?(0,$.jsxs)(e,{disabled:!q,onClick:en,className:`[&>svg]:mr-1`,children:[(0,$.jsx)(Z,{name:`window`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:n(`sessions.sidebar.session.menu.openMiniChatWindow`)})]}):null,(0,$.jsx)(t,{}),s?null:(0,$.jsxs)(e,{className:`[&>svg]:mr-1`,onClick:()=>R(Je,{archivedBucket:s}),children:[(0,$.jsx)(Z,{name:`inbox-archive`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.bulkActions.archive`)]}),(0,$.jsxs)(e,{className:`text-destructive focus:text-destructive [&>svg]:mr-1`,onClick:()=>R(Je,{archivedBucket:s,hardDelete:!0}),children:[(0,$.jsx)(Z,{name:`delete-bin`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.bulkActions.delete`)]})]}))({Item:({className:e,...t})=>(0,$.jsx)(he,{className:J(uo,e),...t}),Separator:({className:e,...t})=>(0,$.jsx)(de,{className:J(lo,e),...t}),Sub:Ce,SubTrigger:({className:e,children:t,...n})=>(0,$.jsxs)(fe,{className:J(so,e),...n,children:[t,(0,$.jsx)(Z,{name:`arrow-right-s`,className:`ml-auto size-3.5`})]}),SubContent:({className:e,children:t,...n})=>(0,$.jsx)(pe,{children:(0,$.jsx)(ge,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(me,{"data-slot":`dropdown-menu-sub-content`,style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:J(co,e),...n,children:t})})})})})})});return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(Fc,{sessionId:Je.id,sessionDirectory:q??null,sessionTitle:Ct,children:(0,$.jsxs)(_e,{open:zt,onOpenChange:nn,onOpenChangeComplete:tn,children:[(0,$.jsxs)(xe,{render:(0,$.jsx)(`div`,{ref:xt,"data-session-row":Je.id,"data-session-scope":q??``,"data-session-focus-scope":H,"data-session-focus-key":yt,"data-session-project-id":o??``,"data-session-archived":s?`1`:`0`,"data-session-depth":i,onClick:vn,onMouseLeave:Dn,className:J(`group relative my-0.5 flex cursor-pointer items-center rounded-lg py-1.5 pr-2`,St&&!et&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,et&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,!St&&!et&&`hover:bg-[color-mix(in_srgb,var(--surface-foreground)_3.5%,transparent)] dark:hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`)}),children:[Vn,(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,style:{paddingLeft:$a(i)},children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onPointerDown:bn,onPointerUp:xn,onPointerCancel:xn,onMouseDown:yn,onKeyDown:Sn,onBlur:Tn,onClick:Cn,onDoubleClick:e=>{e.stopPropagation(),x(Je.id,Ct)},className:J(`relative flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none has-[[data-sidebar-shortcut-number]]:!pr-0`,K&&`bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,B?G?Oe:je:Oe),children:(0,$.jsxs)(`div`,{className:`flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden`,children:[(0,$.jsx)(`div`,{className:J(`block min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground`,jn&&`animate-text-shimmer`),"aria-busy":jn||void 0,children:Ta(Ct,d)}),wt?(0,$.jsx)(`span`,{className:`shrink-0 typography-micro tabular-nums text-muted-foreground`,children:wt}):null,Xe?(0,$.jsx)(Z,{name:`ai-agent`,className:`size-3 shrink-0 text-muted-foreground`,"aria-label":`Assistant`}):null,Mn>0?(0,$.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:n(`sessions.sidebar.session.status.permissionRequired`),"aria-label":n(`sessions.sidebar.session.status.permissionRequired`),children:[(0,$.jsx)(Z,{name:`shield`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`leading-none`,children:Mn})]}):null,Pn?(0,$.jsx)(`span`,{className:J(`inline-flex shrink-0 items-center justify-center transition-none`,Fn?J(`group-hover:hidden group-focus-within:hidden`,Vt?`hidden`:``):Vt?`invisible`:``),children:In}):null,W?(0,$.jsx)($b,{number:W}):null]})})}),G?null:(0,$.jsx)(da,{side:`right`,align:`start`,sideOffset:8,className:`w-64 max-w-[min(16rem,calc(100vw-2rem))] px-3 py-2.5 text-left shadow-md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-left`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1 break-words typography-ui-label font-medium text-foreground`,children:Ct}),(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:Rt})]}),oe?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`folder-open`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.projectLabel})]}):null,se?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ee?.branchLabel})]}):null]})})]})})}),Hn&&!z?(0,$.jsx)(`div`,{className:J(`absolute top-1/2 -translate-y-1/2 z-10`,le?`right-0`:`right-[30px]`),children:Hn}):null,(0,$.jsxs)(`div`,{className:J(`absolute right-1 top-1/2 z-10 flex -translate-y-1/2 items-center gap-1 transition-none group-has-[[data-sidebar-shortcut-number]]:hidden`,Vt||B&&!G?`opacity-100`:J(`opacity-0`,ye)),children:[we?(0,$.jsx)(Zb,{pinned:At,pinLabel:n(At?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`),buttonSizeClass:Te,iconSizeClass:Ee,onPointerDown:rn,onMouseDown:an,onPin:on}):null,Se?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`inline-flex items-center justify-center rounded-md text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,Te),"aria-label":n(`sessions.sidebar.session.actions.pinned`),onPointerDown:rn,onMouseDown:an,onClick:un,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(Z,{name:`pushpin-2-fill`,className:Ee})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n(`sessions.sidebar.session.actions.pinned`)})]}):null,be?(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-none`,Te),"aria-label":n(`sessions.sidebar.session.actions.openInEditor`),onPointerDown:mn,onMouseDown:hn,onClick:gn,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(Z,{name:`external-link`,className:Ee})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n(`sessions.sidebar.session.actions.openInEditor`)})]}):null,(0,$.jsx)(Qb,{archiveLabel:n(`sessions.sidebar.bulkActions.archive`),deleteLabel:n(`sessions.sidebar.bulkActions.delete`),deleteOnly:s===!0,buttonSizeClass:Te,iconSizeClass:Ee,revealClassName:le&&!B&&!Vt?J(`opacity-0`,ye):`opacity-100`,onPointerDown:rn,onMouseDown:an,onArchive:cn,onDelete:ln})]})]}),Un]})}),!Pt&&kt&&Mt?r.children.map(e=>{let t=ie?ie(e):{subtreeContainsActive:ne,subtreeContainsEditing:re,menuOpenSessionId:U,nodeStructureKey:``};return V(e,i+1,q??a,o,s,void 0,H,t)}):null,(0,$.jsx)(mr,{open:rt,onOpenChange:it,children:(0,$.jsxs)(dr,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[(0,$.jsxs)(lr,{children:[(0,$.jsx)(fr,{children:n(`sessions.sidebar.session.export.dialog.title`)}),(0,$.jsx)(pr,{children:n(Kt===1?`sessions.sidebar.session.export.dialog.descriptionSingle`:`sessions.sidebar.session.export.dialog.descriptionMany`,{count:Kt})})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:at,onChange:e=>st(e.target.checked),className:`h-4 w-4 rounded border-border accent-primary`}),n(`sessions.sidebar.session.export.dialog.includeSubtasks`)]}),(0,$.jsxs)(ur,{children:[(0,$.jsx)(Y,{type:`button`,onClick:()=>it(!1),variant:`outline`,size:`sm`,children:n(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{type:`button`,onClick:()=>{it(!1),Zt(at)},size:`sm`,children:n(`sessions.sidebar.session.export.dialog.confirm`)})]})]})}),Ut?(0,$.jsx)(Nb,{session:Ye,open:Wt,onOpenChange:Gt}):null]},Je.id)}var tx=e=>I(e.session.directory??null),nx=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null),rx=e=>{if(!e.openSidebarMenuKey)return null;let t=e.archivedBucket?`archived`:`active`,n=`${e.renderContext??`project`}:${t}:`;return e.openSidebarMenuKey.startsWith(n)?e.openSidebarMenuKey.slice(n.length):null},ix=e=>e.menuOpenSessionId??rx(e),ax=(e,t,n)=>t?n.has(e.node.session.id)?!0:Vv(e.node,t):!1,ox=(e,t,n,r,i)=>{if(e.session.id!==t.session.id)return!0;let a=i(e);if(n.has(a)!==r.has(a)||e.children.length!==t.children.length)return!0;for(let a=0;a<e.children.length;a+=1)if(ox(e.children[a],t.children[a],n,r,i))return!0;return!1},sx=(e,t,n,r)=>{if(e.session.id!==t.session.id)return!0;let i=e.session.id,a=n.get(i)??e.session,o=r.get(i)??t.session;if(a!==o&&zv(a)!==zv(o)||e.children.length!==t.children.length)return!0;for(let i=0;i<e.children.length;i+=1)if(sx(e.children[i],t.children[i],n,r))return!0;return!1},cx=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;let n=e.archivedBucket?`archived`:`active`,r=t.archivedBucket?`archived`:`active`;return ox(e.node,t.node,e.expandedParents,t.expandedParents,t=>`${e.renderContext??`project`}:${n}:${t.session.id}`)||ox(e.node,t.node,e.expandedParents,t.expandedParents,e=>`${t.renderContext??`project`}:${r}:${e.session.id}`)},lx=Q.memo(ex,(e,t)=>{if(e.node.session.id!==t.node.session.id||e.depth!==t.depth||e.groupDirectory!==t.groupDirectory||e.projectId!==t.projectId||e.archivedBucket!==t.archivedBucket||(e.renderContext??`project`)!==(t.renderContext??`project`)||e.mobileVariant!==t.mobileVariant||e.alwaysShowActions!==t.alwaysShowActions||e.shortcutNumber!==t.shortcutNumber||e.hasSessionSearchQuery!==t.hasSessionSearchQuery||e.normalizedSessionSearchQuery!==t.normalizedSessionSearchQuery||e.notifyOnSubtasks!==t.notifyOnSubtasks||e.nodeStructureKey!==t.nodeStructureKey||e.node.session.hasChildren!==t.node.session.hasChildren||tx(e.node)!==tx(t.node)||!nx(e.secondaryMeta,t.secondaryMeta)||e.liveSessionById!==t.liveSessionById&&sx(e.node,t.node,e.liveSessionById,t.liveSessionById)||e.pinnedSessionIds!==t.pinnedSessionIds&&ox(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e=>e.session.id)||e.expandedParents!==t.expandedParents&&cx(e,t)||e.currentSessionId!==t.currentSessionId&&(ax(e,e.currentSessionId,e.subtreeContainsActive)||ax(t,t.currentSessionId,t.subtreeContainsActive))||e.editingId!==t.editingId&&(ax(e,e.editingId,e.subtreeContainsEditing)||ax(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(ax(e,e.editingId,e.subtreeContainsEditing)||ax(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(Vv(e.node,e.copiedSessionId)||Vv(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=ix(e),r=ix(t);if(Vv(e.node,n)||Vv(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){let n=ix(e),r=ix(t);if(Vv(e.node,n)||Vv(t.node,r))return!1}return e.setEditingId===t.setEditingId&&e.setEditTitle===t.setEditTitle&&e.handleSaveEdit===t.handleSaveEdit&&e.handleCancelEdit===t.handleCancelEdit&&e.toggleParent===t.toggleParent&&e.handleSessionSelect===t.handleSessionSelect&&e.handleSessionDoubleClick===t.handleSessionDoubleClick&&e.togglePinnedSession===t.togglePinnedSession&&e.handleShareSession===t.handleShareSession&&e.handleCopyShareUrl===t.handleCopyShareUrl&&e.handleUnshareSession===t.handleUnshareSession&&e.setOpenSidebarMenuKey===t.setOpenSidebarMenuKey&&e.getFoldersForScope===t.getFoldersForScope&&e.getSessionFolderId===t.getSessionFolderId&&e.removeSessionFromFolder===t.removeSessionFromFolder&&e.addSessionToFolder===t.addSessionToFolder&&e.createFolderAndStartRename===t.createFolderAndStartRename&&e.openContextPanelTab===t.openContextPanelTab&&e.handleDeleteSession===t.handleDeleteSession&&e.renderSessionNode===t.renderSessionNode});function ux(e){return e.stopPropagation()}function dx(e){return e.stopPropagation()}function fx(e){let t=(0,pl.c)(71),{t:n}=Tt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:s}=e,c,l,u,d,f,p,m,h,g,_;if(t[0]!==i||t[1]!==n||t[2]!==r){let e=n(`sessions.sidebar.session.untitled`);d=mr,g=!!r,t[13]===i?_=t[14]:(_=e=>{e||i(null)},t[13]=i,t[14]=_),u=dr,m=!1,h=`max-w-sm gap-5`,l=lr;let a;t[15]!==n||t[16]!==r?.archivedBucket?(a=r?.archivedBucket?n(`sessions.sidebar.dialogs.deleteSession.title`):n(`sessions.sidebar.dialogs.archiveSession.title`),t[15]=n,t[16]=r?.archivedBucket,t[17]=a):a=t[17],t[18]===a?p=t[19]:(p=(0,$.jsx)(fr,{children:a}),t[18]=a,t[19]=p),c=pr,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n(`sessions.sidebar.dialogs.deleteSession.withOneSubtask`,{sessionTitle:r.session.title||e,count:r.descendantCount}):n(`sessions.sidebar.dialogs.deleteSession.withManySubtasks`,{sessionTitle:r.session.title||e,count:r.descendantCount}):r.descendantCount===1?n(`sessions.sidebar.dialogs.archiveSession.withOneSubtask`,{sessionTitle:r.session.title||e,count:r.descendantCount}):n(`sessions.sidebar.dialogs.archiveSession.withManySubtasks`,{sessionTitle:r.session.title||e,count:r.descendantCount}):r?.archivedBucket?n(`sessions.sidebar.dialogs.deleteSession.single`,{sessionTitle:r?.session.title||e}):n(`sessions.sidebar.dialogs.archiveSession.single`,{sessionTitle:r?.session.title||e}),t[0]=i,t[1]=n,t[2]=r,t[3]=c,t[4]=l,t[5]=u,t[6]=d,t[7]=f,t[8]=p,t[9]=m,t[10]=h,t[11]=g,t[12]=_}else c=t[3],l=t[4],u=t[5],d=t[6],f=t[7],p=t[8],m=t[9],h=t[10],g=t[11],_=t[12];let v;t[20]!==c||t[21]!==f?(v=(0,$.jsx)(c,{children:f}),t[20]=c,t[21]=f,t[22]=v):v=t[22];let y;t[23]!==l||t[24]!==p||t[25]!==v?(y=(0,$.jsxs)(l,{children:[p,v]}),t[23]=l,t[24]=p,t[25]=v,t[26]=y):y=t[26];let b;t[27]!==o||t[28]!==a?(b=()=>o(!a),t[27]=o,t[28]=a,t[29]=b):b=t[29];let x=!a,S;t[30]===a?S=t[31]:(S=a?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`h-4 w-4 text-primary`}),t[30]=a,t[31]=S);let C;t[32]===n?C=t[33]:(C=n(`sessions.sidebar.dialogs.neverAsk`),t[32]=n,t[33]=C);let w;t[34]!==S||t[35]!==C||t[36]!==b||t[37]!==x?(w=(0,$.jsxs)(`button`,{type:`button`,onClick:b,className:`inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,"aria-pressed":x,children:[S,C]}),t[34]=S,t[35]=C,t[36]=b,t[37]=x,t[38]=w):w=t[38];let T;t[39]===i?T=t[40]:(T=()=>i(null),t[39]=i,t[40]=T);let E;t[41]===n?E=t[42]:(E=n(`sessions.sidebar.dialogs.cancel`),t[41]=n,t[42]=E);let D;t[43]!==T||t[44]!==E?(D=(0,$.jsx)(`button`,{type:`button`,onClick:T,className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:E}),t[43]=T,t[44]=E,t[45]=D):D=t[45];let O;t[46]===s?O=t[47]:(O=()=>void s(),t[46]=s,t[47]=O);let k;t[48]!==n||t[49]!==r?.archivedBucket?(k=r?.archivedBucket?n(`sessions.sidebar.bulkActions.delete`):n(`sessions.sidebar.bulkActions.archive`),t[48]=n,t[49]=r?.archivedBucket,t[50]=k):k=t[50];let A;t[51]!==O||t[52]!==k?(A=(0,$.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:k}),t[51]=O,t[52]=k,t[53]=A):A=t[53];let j;t[54]!==D||t[55]!==A?(j=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[D,A]}),t[54]=D,t[55]=A,t[56]=j):j=t[56];let M;t[57]!==w||t[58]!==j?(M=(0,$.jsxs)(ur,{className:`w-full sm:items-center sm:justify-between`,children:[w,j]}),t[57]=w,t[58]=j,t[59]=M):M=t[59];let N;t[60]!==u||t[61]!==m||t[62]!==M||t[63]!==h||t[64]!==y?(N=(0,$.jsxs)(u,{showCloseButton:m,className:h,children:[y,M]}),t[60]=u,t[61]=m,t[62]=M,t[63]=h,t[64]=y,t[65]=N):N=t[65];let P;return t[66]!==d||t[67]!==N||t[68]!==g||t[69]!==_?(P=(0,$.jsx)(d,{open:g,onOpenChange:_,children:N}),t[66]=d,t[67]=N,t[68]=g,t[69]=_,t[70]=P):P=t[70],P}function px(e){let t=(0,pl.c)(57),{t:n}=Tt(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:o,onConfirm:s}=e,c=r?.archivedBucket===!0,l=r?.sessionCount??0,u;t[0]!==c||t[1]!==l||t[2]!==n?(u=n(c?l===1?`sessions.sidebar.dialogs.deleteSession.title`:`sessions.sidebar.dialogs.deleteSessions.title`:l===1?`sessions.sidebar.dialogs.archiveSession.title`:`sessions.sidebar.dialogs.archiveSessions.title`),t[0]=c,t[1]=l,t[2]=n,t[3]=u):u=t[3];let d=u,f;t[4]!==c||t[5]!==l||t[6]!==n?(f=n(c?l===1?`sessions.sidebar.dialogs.deleteSessions.singleDescription`:`sessions.sidebar.dialogs.deleteSessions.pluralDescription`:l===1?`sessions.sidebar.dialogs.archiveSessions.singleDescription`:`sessions.sidebar.dialogs.archiveSessions.pluralDescription`,{count:l}),t[4]=c,t[5]=l,t[6]=n,t[7]=f):f=t[7];let p=f,m=!!r,h;t[8]===i?h=t[9]:(h=e=>{e||i(null)},t[8]=i,t[9]=h);let g;t[10]===d?g=t[11]:(g=(0,$.jsx)(fr,{children:d}),t[10]=d,t[11]=g);let _;t[12]===p?_=t[13]:(_=(0,$.jsx)(pr,{children:p}),t[12]=p,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,$.jsxs)(lr,{children:[g,_]}),t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==o||t[18]!==a?(y=()=>o(!a),t[17]=o,t[18]=a,t[19]=y):y=t[19];let b=!a,x;t[20]===a?x=t[21]:(x=a?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`h-4 w-4 text-primary`}),t[20]=a,t[21]=x);let S;t[22]===n?S=t[23]:(S=n(`sessions.sidebar.dialogs.neverAsk`),t[22]=n,t[23]=S);let C;t[24]!==S||t[25]!==y||t[26]!==b||t[27]!==x?(C=(0,$.jsxs)(`button`,{type:`button`,onClick:y,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":b,children:[x,S]}),t[24]=S,t[25]=y,t[26]=b,t[27]=x,t[28]=C):C=t[28];let w;t[29]===i?w=t[30]:(w=()=>i(null),t[29]=i,t[30]=w);let T;t[31]===n?T=t[32]:(T=n(`sessions.sidebar.dialogs.cancel`),t[31]=n,t[32]=T);let E;t[33]!==w||t[34]!==T?(E=(0,$.jsx)(`button`,{type:`button`,onClick:w,className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:T}),t[33]=w,t[34]=T,t[35]=E):E=t[35];let D;t[36]===s?D=t[37]:(D=()=>void s(),t[36]=s,t[37]=D);let O;t[38]!==c||t[39]!==n?(O=n(c?`sessions.sidebar.bulkActions.delete`:`sessions.sidebar.bulkActions.archive`),t[38]=c,t[39]=n,t[40]=O):O=t[40];let k;t[41]!==D||t[42]!==O?(k=(0,$.jsx)(`button`,{type:`button`,onClick:D,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}),t[41]=D,t[42]=O,t[43]=k):k=t[43];let A;t[44]!==E||t[45]!==k?(A=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[E,k]}),t[44]=E,t[45]=k,t[46]=A):A=t[46];let j;t[47]!==C||t[48]!==A?(j=(0,$.jsxs)(ur,{className:`w-full sm:items-center sm:justify-between`,children:[C,A]}),t[47]=C,t[48]=A,t[49]=j):j=t[49];let M;t[50]!==j||t[51]!==v?(M=(0,$.jsxs)(dr,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[v,j]}),t[50]=j,t[51]=v,t[52]=M):M=t[52];let N;return t[53]!==m||t[54]!==M||t[55]!==h?(N=(0,$.jsx)(mr,{open:m,onOpenChange:h,children:M}),t[53]=m,t[54]=M,t[55]=h,t[56]=N):N=t[56],N}function mx(e){let t=(0,pl.c)(36),{t:n}=Tt(),{value:r,setValue:i,onConfirm:a}=e,o=!!r,s;t[0]===i?s=t[1]:(s=e=>{e||i(null)},t[0]=i,t[1]=s);let c;t[2]===n?c=t[3]:(c=n(`sessions.sidebar.dialogs.deleteFolder.title`),t[2]=n,t[3]=c);let l;t[4]===c?l=t[5]:(l=(0,$.jsx)(fr,{children:c}),t[4]=c,t[5]=l);let u;t[6]!==n||t[7]!==r?(u=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??``}),t[6]=n,t[7]=r,t[8]=u):u=t[8];let d;t[9]===u?d=t[10]:(d=(0,$.jsx)(pr,{children:u}),t[9]=u,t[10]=d);let f;t[11]!==l||t[12]!==d?(f=(0,$.jsxs)(lr,{children:[l,d]}),t[11]=l,t[12]=d,t[13]=f):f=t[13];let p;t[14]===i?p=t[15]:(p=()=>i(null),t[14]=i,t[15]=p);let m;t[16]===n?m=t[17]:(m=n(`sessions.sidebar.dialogs.cancel`),t[16]=n,t[17]=m);let h;t[18]!==p||t[19]!==m?(h=(0,$.jsx)(`button`,{type:`button`,onClick:p,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:m}),t[18]=p,t[19]=m,t[20]=h):h=t[20];let g;t[21]===n?g=t[22]:(g=n(`sessions.sidebar.bulkActions.delete`),t[21]=n,t[22]=g);let _;t[23]!==a||t[24]!==g?(_=(0,$.jsx)(`button`,{type:`button`,onClick:a,className:`inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50`,children:g}),t[23]=a,t[24]=g,t[25]=_):_=t[25];let v;t[26]!==_||t[27]!==h?(v=(0,$.jsxs)(ur,{children:[h,_]}),t[26]=_,t[27]=h,t[28]=v):v=t[28];let y;t[29]!==v||t[30]!==f?(y=(0,$.jsxs)(dr,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[f,v]}),t[29]=v,t[30]=f,t[31]=y):y=t[31];let b;return t[32]!==o||t[33]!==s||t[34]!==y?(b=(0,$.jsx)(mr,{open:o,onOpenChange:s,children:y}),t[32]=o,t[33]=s,t[34]=y,t[35]=b):b=t[35],b}var hx=e=>{let t=(0,pl.c)(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:o,onCreateFolderAndMove:s,onRemoveFromFolder:c,canRemoveFromFolder:l,onDelete:u,onDone:d}=e,{t:f}=Tt(),p=!!r&&!a,m;t[0]!==a||t[1]!==f?(m=f(a?`sessions.sidebar.bulkActions.delete`:`sessions.sidebar.bulkActions.archive`),t[0]=a,t[1]=f,t[2]=m):m=t[2];let h=m,g;t[3]!==n||t[4]!==f?(g=f(`sessions.sidebar.bulkActions.selectedCount`,{count:n}),t[3]=n,t[4]=f,t[5]=g):g=t[5];let _;t[6]===g?_=t[7]:(_=(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground whitespace-nowrap`,children:g}),t[6]=g,t[7]=_);let v;t[8]!==p||t[9]!==l||t[10]!==s||t[11]!==o||t[12]!==c||t[13]!==i||t[14]!==f?(v=p?(0,$.jsxs)(Ga,{children:[(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Ja,{asChild:!0,children:(0,$.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":f(`sessions.sidebar.bulkActions.moveToFolder`),children:(0,$.jsx)(Z,{name:`folder`,className:`h-4 w-4`})})})}),(0,$.jsx)(da,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f(`sessions.sidebar.bulkActions.moveToFolder`)})})]}),(0,$.jsxs)(Ia,{align:`end`,className:`min-w-[180px]`,children:[i.length===0?(0,$.jsx)(ka,{disabled:!0,className:`text-muted-foreground`,children:f(`sessions.sidebar.folders.none`)}):i.map(e=>(0,$.jsx)(ka,{onClick:()=>o(e.id),children:(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})},e.id)),(0,$.jsx)(za,{}),(0,$.jsxs)(ka,{onClick:s,children:[(0,$.jsx)(Z,{name:`add`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.newFolderEllipsis`)]}),l?(0,$.jsxs)(ka,{onClick:c,className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Z,{name:`close`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]}):null,t[8]=p,t[9]=l,t[10]=s,t[11]=o,t[12]=c,t[13]=i,t[14]=f,t[15]=v):v=t[15];let y;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(y=J(`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`),t[16]=y):y=t[16];let b;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Z,{name:`delete-bin`,className:`h-4 w-4`}),t[17]=b):b=t[17];let x;t[18]!==h||t[19]!==u?(x=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:u,className:y,"aria-label":h,children:b})}),t[18]=h,t[19]=u,t[20]=x):x=t[20];let S;t[21]===h?S=t[22]:(S=(0,$.jsx)(da,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:h})}),t[21]=h,t[22]=S);let C;t[23]!==x||t[24]!==S?(C=(0,$.jsxs)(pa,{children:[x,S]}),t[23]=x,t[24]=S,t[25]=C):C=t[25];let w;t[26]===f?w=t[27]:(w=f(`sessions.sidebar.header.actions.exitSelection`),t[26]=f,t[27]=w);let T;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`}),t[28]=T):T=t[28];let E;t[29]!==d||t[30]!==w?(E=(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:d,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":w,children:T})}),t[29]=d,t[30]=w,t[31]=E):E=t[31];let D;t[32]===f?D=t[33]:(D=f(`sessions.sidebar.header.actions.exitSelection`),t[32]=f,t[33]=D);let O;t[34]===D?O=t[35]:(O=(0,$.jsx)(da,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:D})}),t[34]=D,t[35]=O);let k;t[36]!==E||t[37]!==O?(k=(0,$.jsxs)(pa,{children:[E,O]}),t[36]=E,t[37]=O,t[38]=k):k=t[38];let A;t[39]!==k||t[40]!==v||t[41]!==C?(A=(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[v,C,k]}),t[39]=k,t[40]=v,t[41]=C,t[42]=A):A=t[42];let j;return t[43]!==A||t[44]!==_?(j=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5`,children:[_,A]}),t[43]=A,t[44]=_,t[45]=j):j=t[45],j},gx=e=>{let{t}=Tt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,addSessionsToFolder:a,removeSessionsFromFolders:o,createFolderAndStartRename:s,archiveSessions:c,setBulkDeleteConfirm:l}=e,u=$y(e=>e.enabled),d=$y(e=>e.selectedIds.size),f=d>0,p=$y(e=>e.selectedIds),m=$y(e=>e.scopeKey),h=Q.useCallback(()=>{$y.getState().toggleMode()},[]),g=Q.useCallback(()=>{$y.getState().disable()},[]),_=Q.useMemo(()=>{if(!f||typeof document>`u`)return!1;let e=!1,t=!1;for(let n of p){let r=document.querySelectorAll(`[data-session-row="${CSS.escape(n)}"]`);for(let n of r)n.getAttribute(`data-session-archived`)===`1`?t=!0:e=!0}return t&&!e},[f,p]),v=Q.useMemo(()=>{if(m)return m;if(!f||typeof document>`u`)return null;for(let e of p){let t=document.querySelector(`[data-session-row="${CSS.escape(e)}"]`)?.getAttribute(`data-session-scope`);if(t&&t.length>0)return t}return null},[f,p,m]),y=Q.useMemo(()=>v?i[v]??[]:[],[i,v]),b=Q.useMemo(()=>{if(!v||!f)return!1;let e=i[v]??[];for(let t of e)for(let e of t.sessionIds)if(p.has(e))return!0;return!1},[i,v,f,p]),x=Q.useCallback(e=>{!v||!f||a(v,e,Array.from(p))},[a,p,v,f]),S=Q.useCallback(()=>{if(!v||!f)return;let e=s(v);e&&a(v,e.id,Array.from(p))},[a,s,p,v,f]),C=Q.useCallback(()=>{!v||!f||o(v,Array.from(p))},[o,p,v,f]),w=Q.useCallback(async()=>{let e=Array.from(p);if(e.length!==0){if(_)Js({sessionIds:e,message:e.length===1?t(`sessions.sidebar.bulkActions.deletedSingle`,{count:e.length}):t(`sessions.sidebar.bulkActions.deletedPlural`,{count:e.length}),undoLabel:t(`sessions.sidebar.undo`),commitFailedMessage:e.length===1?t(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:e.length}):t(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:e.length})});else{let{archivedIds:n,failedIds:r}=await c(e);n.length>0&&Xs({sessionIds:n,message:n.length===1?t(`sessions.sidebar.bulkActions.archivedSingle`,{count:n.length}):t(`sessions.sidebar.bulkActions.archivedPlural`,{count:n.length}),undoLabel:t(`sessions.sidebar.undo`),settingsLabel:t(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:n.length===1?t(`sessions.sidebar.session.archive.undoFailed`):t(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:n.length})}),r.length>0&&X.error(r.length===1?t(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:r.length}):t(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:r.length}))}$y.getState().clear()}},[c,_,p,t]),T=Q.useCallback(()=>{if(!f)return;let e=p.size;if(!_||!r){w();return}l({sessionCount:e,archivedBucket:_})},[_,w,p,r,l,f]),E=Q.useCallback(async()=>{l(null),await w()},[w]);return Q.useEffect(()=>{if(!u)return;let e=typeof navigator<`u`&&/Macintosh|Mac OS X/.test(navigator.userAgent||``),t=t=>{if(n)return;let r=t.target;if(r&&(r.tagName===`INPUT`||r.tagName===`TEXTAREA`||r.isContentEditable))return;let i=e?t.metaKey:t.ctrlKey;if(t.key===`Escape`){t.preventDefault(),$y.getState().disable();return}if(i&&t.key===`Backspace`){t.preventDefault(),T();return}if(i&&(t.key===`a`||t.key===`A`)){let e=typeof document<`u`?Array.from(document.querySelectorAll(`[data-session-row]`)):[];if(e.length===0)return;t.preventDefault();let n=$y.getState().scopeKey??e[0]?.getAttribute(`data-session-scope`)??null,r=e.filter(e=>!n||e.getAttribute(`data-session-scope`)===n).map(e=>e.getAttribute(`data-session-row`)).filter(e=>typeof e==`string`&&e.length>0);if(r.length===0)return;$y.getState().replaceAll(r,n||null)}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,n,u]),{selectionModeEnabled:u,hasSelection:f,selectedIdsSize:d,bulkScopeIsArchived:_,derivedSelectionScope:v,bulkScopeFolders:y,bulkCanRemoveFromFolder:b,handleToggleSelectionMode:h,handleExitSelectionMode:g,handleBulkMoveToFolder:x,handleBulkCreateFolderAndMove:S,handleBulkRemoveFromFolder:C,handleBulkDelete:T,confirmBulkDelete:E}},_x=(e,t,n)=>{let r=[],i=new Set,a=e=>{let t=I(e??null);!t||i.has(t)||(i.add(t),r.push(t))};if(a(e),a(n?.workspaceRoot),a(n?.currentDirectory),n?.includeWorktrees!==!1)for(let e of t)a(e.path);return r},vx=(e,t,n,r)=>{let i=e.filter(e=>e.sessionId===t);if(i.length===0)return null;if(n){let e=i.find(e=>e.projectId===n);if(e)return e}if(r){let e=i.find(e=>e.projectId===r);if(e)return e}return i[0]??null},yx=({currentSessionId:e,focus:t,pinnedFocuses:n,projectFocuses:r,fallbackProjectId:i})=>{if(!e)return null;let a=t?.sessionId===e,o=a?t.projectId:null,s=vx(r,e,o,i)??{scope:`project`,sessionId:e,projectId:i};return!a||t.scope===`project`?s:vx(n,e,o,i)??s};function bx(e,t,n=null){if(!e||e.scope!==`project`||!e.sessionId)return null;if(e.projectId){let n=t.find(t=>t.sessionId===e.sessionId&&t.projectId===e.projectId);if(n)return n}if(n){let r=t.find(t=>t.sessionId===e.sessionId&&t.projectId===n);if(r)return r}return t.find(t=>t.sessionId===e.sessionId)??null}var xx=`yuri.sessions.projectCollapse`,Sx=`yuri.sessions.groupOrder`,Cx=`yuri.sessions.groupCollapse`,wx=`yuri.sessions.activeSessionByProject`,Tx=`yuri.sessions.expandedParents.v2`,Ex=`yuri.sessions.expandedParents`,Dx=w(Qe()),Ox=e=>{try{let t=Dx.getItem(e);if(!t)return new Set;let n=JSON.parse(t);return new Set(Array.isArray(n)?n.filter(e=>typeof e==`string`):[])}catch{return new Set}},kx=e=>{try{let t=Dx.getItem(e);if(!t)return new Map;let n=JSON.parse(t),r=new Map;return!n||typeof n!=`object`||Array.isArray(n)||Object.entries(n).forEach(([e,t])=>{typeof t==`string`&&t.length>0&&r.set(e,t)}),r}catch{return new Map}},Ax=e=>{try{let t=Dx.getItem(e);if(!t)return new Map;let n=JSON.parse(t),r=new Map;return!n||typeof n!=`object`||Array.isArray(n)||Object.entries(n).forEach(([e,t])=>{Array.isArray(t)&&r.set(e,t.filter(e=>typeof e==`string`))}),r}catch{return new Map}},jx=(e,t,n)=>{let r=new Set;for(let t of e){let e=I(t.path)?.toLowerCase();e&&r.add(e)}if(n?.includeWorktrees===!1)return r;for(let e of t.values())for(let t of e){let e=I(t.path)?.toLowerCase();e&&r.add(e)}return r},Mx=(e,t,n)=>{if(e.time?.archived)return!0;let r=I(In(e))?.toLowerCase();return r?t.size===0?n?.allowEmptyDirectorySet??!0:t.has(r):n?.allowUnknownDirectory??!0},Nx=3e5,Px=new Set,Fx=[],Ix={},Lx=e=>{let t=Q.useRef(e);return t.current=e,Q.useMemo(()=>(...e)=>t.current(...e),[])},Rx=Q.memo(function(e){let t=(0,pl.c)(3),{onOpenChange:n}=e,r=ms(ue(Bx)),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(ps,{open:!0,onOpenChange:n,...r}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}),zx=Q.memo(function({mobileVariant:e=!1,onSessionSelected:t,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1,isVisible:a=!0}){let{t:o}=Tt(),[c,l]=Q.useState(!1),[u,d]=Q.useState(!1),[f,m]=Q.useState(``),h=Q.useRef(null),g=Q.useRef(null),_=Q.useRef(new Set),[v,y]=Q.useState(null),[b,x]=Q.useState(``),[S,C]=Q.useState(null),[w,T]=Q.useState(new Set),E=Q.useMemo(()=>Dx,[]),[D,O]=Q.useState(new Set),[k,A]=Q.useState(new Map),[j,M]=Q.useState(new Map),N=q(e=>e.isNewWorktreeDialogOpen),P=q(e=>e.setNewWorktreeDialogOpen),[L,R]=Q.useState(null),[z,B]=Q.useState(null),[V,ee]=Q.useState(``),[H,ne]=Q.useState(null),[re,U]=Q.useState(null),[ie,ae]=Q.useState(null),W=Kt(),oe=Yt(),[se,ce]=Q.useState(()=>Ox(Cx)),[G,le]=Q.useState(()=>Ax(Sx)),[ue,de]=Q.useState(()=>kx(wx));Q.useEffect(()=>s(e=>{p(e)&&(ce(Ox(Cx)),le(Ax(Sx)),de(kx(wx)),O(Ox(xx)),T(Ox(Tx)))}),[]);let[fe,pe]=Q.useState(new Map),me=Q.useRef(new Map),he=Q.useRef(0),ge=je(e=>e.homeDirectory),_e=je(e=>e.currentDirectory),ve=je(e=>e.setDirectory),ye=jn(e=>e.projects),be=jn(e=>e.activeProjectId),xe=jn(e=>e.removeProject),Se=jn(e=>e.setActiveProjectIdOnly),Ce=jn(e=>e.updateProjectMeta),we=jn(e=>e.reorderProjectsById),Te=q(e=>e.setActiveMainTab),Ee=q(e=>e.activeMainTab),De=It(),Oe=q(e=>e.openContextPanelTab),ke=q(e=>e.setSettingsDialogOpen),Ae=q(e=>e.toggleHelpDialog),Me=q(e=>e.setSessionSwitcherOpen),Ne=q(e=>e.setScheduledTasksDialogOpen),K=q(e=>e.notifyOnSubtasks),Pe=q(e=>e.showDeletionDialog),Fe=q(e=>e.setShowDeletionDialog),Ie=Eo(f,120),Le=Q.useMemo(()=>Ie.trim().toLowerCase(),[Ie]),Re=Le.length>0,ze=ms(e=>e.available&&(e.runtimeType===`desktop`||e.runtimeType===`web`)),Be=rr(e=>e.collapsedFolderIds),Ve=rr(e=>e.foldersMap),He=rr(e=>e.sessionOrderByScope),Ue=rr(e=>e.sessionOrderActivityByScope),We=rr(e=>e.getFoldersForScope),Ge=rr(e=>e.createFolder),Ke=rr(e=>e.renameFolder),qe=rr(e=>e.deleteFolder),Je=rr(e=>e.addSessionToFolder),Ye=rr(e=>e.addSessionsToFolder),Xe=rr(e=>e.removeSessionFromFolder),Ze=rr(e=>e.removeSessionsFromFolders),Qe=rr(e=>e.toggleFolderCollapse),$e=rr(e=>e.getSessionFolderId),et=rr(e=>e.reorderSessions);k_({isSessionSearchOpen:a&&u,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchContainerRef:h});let tt=Q.useMemo(()=>new Map,[]),nt=Vt({enabled:a,includeChildren:!0}),rt=nc({enabled:a}),it=rc({enabled:a}),ot=mn(e=>a?e.index.session.unseenCount:Ix),st=Q.useMemo(()=>te(),[]),ct=tn(e=>e.status),lt=tn(e=>e.activeSessions),ut=tn(e=>e.archivedSessions),dt=tn(e=>e.loadingDirectories.size>0||e.refreshingDirectories.size>0),ft=tn(e=>e.archivedLoadingDirectories),pt=Q.useDeferredValue(lt),mt=Q.useDeferredValue(ut),ht=Sn(e=>e.currentSessionId),gt=Ui(e=>e.focus),_t=Q.useSyncExternalStore(Vn,Un,Un),yt=Sn(e=>!!e.newSessionDraft?.open),bt=Sn(e=>e.setCurrentSession),xt=Sn(e=>e.updateSessionTitle),St=Sn(e=>e.shareSession),Ct=Sn(e=>e.unshareSession),wt=Sn(e=>e.worktreeMetadata),Et=Sn(e=>e.availableWorktreesByProject),Dt=Sn(e=>e.openNewSessionDraft),kt=vt(e=>{Dt(e),st&&window.dispatchEvent(new CustomEvent(`yuri:navigate`,{detail:{view:`chat`}}))}),At=Q.useMemo(()=>jx(ye,Et,{includeWorktrees:!st}),[Et,st,ye]),jt=Q.useMemo(()=>{let e=new Map(nt.map(e=>[e.id,e])),t=pt.map(t=>{let n=e.get(t.id);return n?en(n,t):t}),n=new Set(t.map(e=>e.id));return nt.forEach(e=>{n.has(e.id)||t.push(e)}),t.filter(e=>Mx(e,At,{allowUnknownDirectory:!st,allowEmptyDirectorySet:!st}))},[pt,st,At,nt]),Mt=Q.useMemo(()=>nt.map(e=>{let t=I(e.directory??null)??``;return`${e.id}:${e.title??``}:${+!!e.time?.archived}:${t}`}).join(`|`),[nt]),Nt=Q.useRef(nt);Q.useEffect(()=>{Nt.current=nt},[Mt,nt]);let Pt=Q.useMemo(()=>new Map(nt.map(e=>[e.id,e])),[nt]);Q.useEffect(()=>{let e=null,t=$n(t=>{t.type===`scheduled-task-ran`&&(e&&clearTimeout(e),e=setTimeout(()=>{let e=jn.getState().projects.find(e=>e.id===t.projectId),n=I(e?.path??null);if(!n)return;let r=[n];(Sn.getState().availableWorktreesByProject.get(n)??[]).forEach(e=>{let t=I(e.path);t&&r.push(t)}),Bt(r,Nt.current)},500))});return()=>{e&&clearTimeout(e),t()}},[]);let Ft=Q.useMemo(()=>F(),[]),Lt=xs(e=>e.sidebarBrandName.trim().length>0),{isTablet:Rt}=no(),zt=e||Rt,{buildGroupSearchText:Ht,filterSessionNodesForSearch:Ut,buildGroupedSessions:Gt}=O_({homeDirectory:ge,worktreeMetadata:wt,pinnedSessionIds:W,gitBranches:tt,isVSCode:st}),{scheduleCollapsedProjectsPersist:Jt,hasRestoredProjectCollapse:Xt}=I_({isVSCode:st,safeStorage:E,keys:{sessionExpanded:Tx,sessionExpandedLegacy:Ex,projectCollapse:xx,groupOrder:Sx,projectActiveSession:wx,groupCollapse:Cx},groupOrderByProject:G,activeSessionByProject:ue,collapsedGroups:se,setExpandedParents:T,setCollapsedProjects:O}),Zt=Q.useMemo(()=>[...jt].sort((e,t)=>Na(e,t,W)),[jt,W]),$t=Q.useMemo(()=>{let e=new Map;return Zt.forEach(t=>{let n=t.parentID;if(!n)return;let r=e.get(n)??[];r.push(t),e.set(n,r)}),e.forEach(e=>e.sort((e,t)=>Na(e,t,W))),e},[Zt,W]),nn=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:o(`sessions.sidebar.empty.noSessions.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:o(`sessions.sidebar.empty.noSessions.description`)})]}),rn=Q.useMemo(()=>ye.find(e=>e.id===S)??null,[ye,S]),an=Q.useCallback(e=>{S&&Ce(S,{label:e.label,icon:e.icon,color:e.color,iconBackground:e.iconBackground,defaultModel:e.defaultModel??null})},[S,Ce]),on=Q.useCallback(()=>{P(!0)},[P]),sn=Q.useCallback((t,n)=>{if(Te(`chat`),e&&Me(!1),n?.sessionId){bt(n.sessionId,t);return}Dt({directoryOverride:t,preserveDirectoryOverride:!0})},[e,Dt,Te,bt,Me]),cn=vt(()=>{let e=ms.getState();if(e.available&&e.info){l(!0);return}e.checkForUpdates().then(()=>{let{available:e,error:t}=ms.getState();if(t){X.error(o(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}if(!e){X.success(o(`sessions.sidebar.updateCheck.latestVersion`));return}l(!0)})}),ln=Q.useCallback(()=>{e&&Me(!1),ke(!0)},[e,Me,ke]),un=Q.useCallback(()=>{Te(`chat`),Dt(),e&&Me(!1)},[e,Dt,Te,Me]),dn=Q.useCallback(()=>{if(!e){Te(`schedule`);return}Ne(!0),Me(!1)},[e,Te,Ne,Me]),fn=Q.useCallback(()=>{or(),e&&Me(!1)},[e,Me]),pn=Sn(e=>e.archiveSession),hn=Sn(e=>e.archiveSessions),{copiedSessionId:gn,handleSessionSelect:_n,handleSessionDoubleClick:vn,handleSaveEdit:yn,handleCancelEdit:xn,handleShareSession:Cn,handleCopyShareUrl:wn,handleUnshareSession:Tn,handleDeleteSession:En,confirmDeleteSession:Dn}=A_({activeProjectId:be,currentDirectory:_e,currentSessionId:ht,mobileVariant:e,allowReselect:n,onSessionSelected:t,isSessionSearchOpen:u,sessionSearchQuery:f,setSessionSearchQuery:m,setIsSessionSearchOpen:d,setActiveProjectIdOnly:Se,setDirectory:ve,setActiveMainTab:Te,setSessionSwitcherOpen:Me,setCurrentSession:bt,updateSessionTitle:xt,shareSession:St,unshareSession:Ct,archiveSession:pn,archiveSessions:hn,childrenMap:$t,showDeletionDialog:Pe,setDeleteSessionConfirm:ne,deleteSessionConfirm:H,setEditingId:y,setEditTitle:x,editingId:v,editTitle:b}),kn=Q.useCallback((e,t,n,r=`project`)=>{let i={sessionId:e,scope:r,projectId:n??null};if(e===ht){On(e),Yb(i),_n(e,t,n);return}qb(i,()=>_n(e,t,n))},[_n,ht]);Q.useEffect(()=>()=>{Kb()},[]);let An=Q.useCallback(()=>{if(!re)return;let{scopeKey:e,folderId:t}=re;U(null),qe(e,t)},[re,qe]);Q.useEffect(()=>{if(!ht)return;let e=jt.find(e=>e.id===ht)?.parentID;if(!e)return;let t=[`project:active:${e}`,`project:archived:${e}`,`recent:active:${e}`,`recent:archived:${e}`];T(e=>{if(t.every(t=>e.has(t)))return e;let n=new Set(e);t.forEach(e=>n.add(e));try{E.setItem(Tx,JSON.stringify(Array.from(n)))}catch{}return n})},[ht,jt,E]);let Mn=Q.useCallback(e=>{T(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{E.setItem(Tx,JSON.stringify(Array.from(n)))}catch{}return n})},[E]),Nn=Q.useCallback((e,t)=>{if(!e)return null;t&&Be.has(t)&&Qe(t);let n=Ge(e,o(`sessions.sidebar.folder.newFolderName`),t);return B(n.id),ee(n.name),n},[Be,Qe,Ge,o]),Pn=vt(kn),Fn=vt(vn),Rn=vt(yn),zn=vt(xn),Bn=vt(Cn),Hn=vt(wn),Wn=vt(Tn),Gn=vt(En),Kn=vt(Nn),qn=vt((e,t,n,r)=>{let i=Gs(),a=Math.max(i,n)+7;if(M(e=>{let r=Math.max(i,e.get(t)??i,n),a=new Map(e);return a.set(t,r+7),a}),e.isArchivedBucket||a<r)return;let o=I(e.directory??null);if(!o)return;let s=tn.getState().activePaginationByDirectory.get(o);s?.hasMore&&!s.loadingMore&&Wt(o)}),Jn=vt(e=>{M(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})}),Yn=vt(e=>{M(t=>{let n=!1,r=new Map(t),i=`${e}:`;for(let e of r.keys())e.startsWith(i)&&(r.delete(e),n=!0);return n?r:t})}),Xn=Q.useMemo(()=>e=>{let t=ye.find(t=>t.id===e),n=I(t?.path??null);if(!n)return[];let r=[n];return st||(Et.get(n)??[]).forEach(e=>{let t=I(e.path);t&&r.push(t)}),r},[Et,st,ye]),Zn=vt(e=>{let t=Xn(e);if(t.length===0)return;let n=tn.getState().loadedDirectories,r=t.filter(e=>!n.has(e));r.length!==0&&Bt(r,Nt.current)}),Qn=vt(e=>{let t=ye.find(t=>t.id===e);t&&(async()=>{let e=[];if(!st)try{e=(await sa({id:t.id,path:t.path})).worktrees}catch(n){console.warn(`[SessionSidebar] Worktree refresh before session sync failed:`,n);let r=I(t.path);e=r?Sn.getState().availableWorktreesByProject.get(r)??[]:[]}let n=_x(t.path,e,{currentDirectory:_e,workspaceRoot:t.path,includeWorktrees:!st});n.length!==0&&await Qt(n,Nt.current)})()});Q.useEffect(()=>{if(!Xt)return;let e=tn.getState(),t=ye.flatMap(t=>D.has(t.id)?[]:Xn(t.id).filter(t=>!e.loadedDirectories.has(t)&&!e.loadingDirectories.has(t)&&!e.refreshingDirectories.has(t)));t.length>0&&Bt(t,Nt.current)},[D,Xn,Xt,ye]);let er=vt(()=>{he.current=Date.now()+150,M(new Map),O(()=>{let e=new Set(ye.map(e=>e.id));try{E.setItem(xx,JSON.stringify(Array.from(e)))}catch{}return st||Jt(e),e})}),tr=vt(()=>{he.current=Date.now()+150,M(new Map),O(()=>{let e=new Set;try{E.setItem(xx,JSON.stringify([]))}catch{}return st||Jt(e),e});let e=tn.getState().loadedDirectories,t=ye.flatMap(t=>Xn(t.id).filter(t=>!e.has(t)));t.length>0&&Bt(t,Nt.current)}),nr=vt(e=>{he.current=Date.now()+150,Yn(e),O(t=>{let n=new Set(t);n.has(e)?(n.delete(e),queueMicrotask(()=>Zn(e))):n.add(e);try{E.setItem(xx,JSON.stringify(Array.from(n)))}catch{}return st||Jt(n),n})}),ir=vt(e=>{he.current=Date.now()+150,Zn(e),O(t=>{if(!t.has(e))return t;let n=new Set(t);n.delete(e);try{E.setItem(xx,JSON.stringify(Array.from(n)))}catch{}return st||Jt(n),n})}),ar=Q.useMemo(()=>ye.map(e=>({...e,normalizedPath:I(e.path)})).filter(e=>!!e.normalizedPath),[ye]),sr=Q.useMemo(()=>ar.map(e=>e.normalizedPath),[ar]),cr=Q.useMemo(()=>{let e=new Set(ar.map(e=>e.normalizedPath));if(!st)for(let t of Et.values())for(let n of t){let t=I(n.path);t&&e.add(t)}return[...e].sort()},[Et,st,ar]),lr=Q.useRef(null);Q.useEffect(()=>{let e=new Set(cr),t=lr.current;if(lr.current=e,!t)return;let n=cr.filter(e=>!t.has(e));if(n.length===0)return;let r=tn.getState().loadedDirectories,i=I(_e),a=ar.find(e=>e.id===be)??ar.find(e=>e.normalizedPath===i)??null,o=new Set;i&&o.add(i),a?.normalizedPath&&(o.add(a.normalizedPath),st||(Et.get(a.normalizedPath)??[]).forEach(e=>{let t=I(e.path);t&&o.add(t)}));let s=n.filter(e=>o.has(e)&&!r.has(e));s.length!==0&&Bt(s,Nt.current)},[be,Et,_e,st,ar,cr]);let{github:ur}=at(),dr=ya(),fr=dr.data??null,pr=dr.isFetched,mr=xo(a?sr:Fx),hr=yv(e=>e.ensureEntry),gr=yv(e=>e.setParams),_r=yv(e=>e.refreshTargets);R_({normalizedProjects:ar,activeProjectId:be,gitRepoStatus:mr,setProjectRepoStatus:A,setProjectRootBranches:pe,enabled:a});let vr=Q.useMemo(()=>Ds(jt,ar,Et,st,mt),[mt,Et,st,ar,jt]),{getSessionsForProject:yr,getArchivedSessionsForProject:br}=z_({ownership:vr}),xr=dt||ct===`idle`||ct===`loading`,Sr=Q.useRef(!1);be&&k.has(be)&&(Sr.current=!!k.get(be));let Cr=qt(e=>e.projectSortOrder),wr=Q.useMemo(()=>vc(ar,Cr),[ar,Cr]),{projectSections:Tr,groupSearchDataByGroup:Er,sectionsForRender:Dr,searchMatchCount:Or}=T_({normalizedProjects:wr,getSessionsForProject:yr,getArchivedSessionsForProject:br,availableWorktreesByProject:Et,projectRepoStatus:k,projectRootBranches:fe,lastRepoStatus:Sr.current,buildGroupedSessions:Gt,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,filterSessionNodesForSearch:Ut,buildGroupSearchText:Ht,foldersMap:Ve}),kr=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:o(`sessions.sidebar.empty.noMatches.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:o(`sessions.sidebar.empty.noMatches.description`)})]});E_({projectSections:Tr,activeProjectId:be,activeSessionByProject:ue,setActiveSessionByProject:de,currentSessionId:ht,handleSessionSelect:_n,newSessionDraftOpen:yt,mobileVariant:e,openNewSessionDraft:Dt,setActiveMainTab:Te,setSessionSwitcherOpen:Me});let{getOrderedGroups:Ar}=D_(G),jr=Q.useRef(!1);Q.useEffect(()=>{if(jr.current||Tr.length===0)return;let e=Tr.flatMap(e=>e.groups.filter(e=>e.isArchivedBucket).map(t=>`${e.project.id}:${t.id}`));e.length>0&&ce(t=>new Set([...t,...e])),jr.current=!0},[Tr]);let Mr=Q.useMemo(()=>{let e=new Map,t=new Map;return Tr.forEach(n=>{let r=Ot(n.project.normalizedPath)||n.project.normalizedPath;n.groups.forEach(i=>{let a=i.branch&&i.branch!==`HEAD`&&i.branch!==r?i.branch:null,o={projectLabel:r,branchLabel:a},s=r=>{r.forEach(r=>{let a=n.project.normalizedPath.length;a<(t.get(r.session.id)??-1)||(e.set(r.session.id,{node:r,projectId:n.project.id,groupDirectory:i.directory,secondaryMeta:o}),t.set(r.session.id,a),r.children.length>0&&s(r.children))})};s(i.sessions)})}),e},[Tr]);Q.useLayoutEffect(()=>{if(!ht){Yb(null);return}let e=Ui.getState().focus;if(e?.sessionId===ht){e.scope===`project`&&!e.projectId&&Yb({...e,projectId:Mr.get(ht)?.projectId??null});return}Yb({scope:`project`,sessionId:ht,projectId:Mr.get(ht)?.projectId??null})},[ht,Mr]);let Nr=Q.useMemo(()=>st?[]:Ec(jt,W,He[ac]),[st,W,jt,He]),Fr=vt((e,t)=>{v||et(ac,Nr.map(e=>e.id),e,t,{}).catch(()=>X.error(o(`sessions.order.saveFailed`)))}),Ir=Q.useMemo(()=>Re?[]:Mc(jt,W,it,ot),[Re,W,it,jt,ot]),{pinnedItems:Lr,inProgressItems:Rr}=Q.useMemo(()=>{let e=e=>{let t=Mr.get(e.id),n=I(e.directory??null),r={session:e,children:[],worktree:wt.get(e.id)??null};if(Re&&Ut([r],Le).length===0)return null;let i=vr.bySessionId.get(e.id),a=i?wr.find(e=>e.id===i.projectId):void 0,o=a?Ot(a.normalizedPath)||a.normalizedPath:t?.secondaryMeta?.projectLabel??null,s=cc({projectLabel:o,owner:i,sessionWorktree:wt.get(e.id)??null,worktrees:a?Et.get(a.normalizedPath)??[]:[],projectRootBranch:i?fe.get(i.projectId)??(a?mr.get(a.normalizedPath)?.branch:null)??null:null,isVSCode:st})??t?.secondaryMeta??null;return{node:r,projectId:i?.projectId??t?.projectId??null,groupDirectory:i?.scopeDirectory??t?.groupDirectory??n,secondaryMeta:s}},t=t=>t.map(e).filter(e=>e!==null);return{pinnedItems:st?[]:t(Nr),inProgressItems:t(Ir)}},[Et,Ut,mr,Re,Ir,st,Le,Nr,fe,vr,Mr,wr,wt]),zr=Q.useMemo(()=>Dr.map(e=>({...e,groups:e.groups.filter(e=>!e.isArchivedBucket)})),[Dr]),Br=Q.useMemo(()=>{let e=Re?zr.map(e=>({...e,groups:e.groups.map(e=>({...e,sessions:Er.get(e)?.filteredNodes??[]}))})):zr;if(!i)return e;let t=e.find(e=>e.project.id===be)??e[0];if(!t)return[];let n=t.groups.find(e=>e.isMain&&e.sessions.length>0)??t.groups.find(e=>e.sessions.length>0)??t.groups.find(e=>e.isMain)??t.groups[0];return n?[{...t,groups:[n]}]:[]},[be,Er,Re,zr,i]),Vr=Q.useMemo(()=>Hs({sections:Br,foldersMap:Ve,getOrderedGroups:Ar,pinnedSessionIds:W,sessionOrderByScope:He,sessionOrderActivityByScope:Ue}),[Ve,Ar,Br,W,Ue,He]),Hr=Q.useMemo(()=>ec({targets:Vr,collapsedProjectIds:D,collapsedGroupKeys:se,collapsedFolderIds:Be,visibleSessionCountByGroup:j,defaultVisibleSessionCount:Gs(),hasSessionSearchQuery:Re,alwaysVisibleSessionIds:rt}),[rt,Be,se,D,Re,Vr,j]),Ur=Q.useMemo(()=>Re?[]:[...Lr,...Rr].map((e,t)=>{let n=e.node.session;return{scope:`pinned`,sessionId:n.id,projectId:e.projectId,directory:I(In(n))??e.groupDirectory??null,visibleIndex:t}}),[Re,Rr,Lr]),[Wr,Gr]=Q.useState(null),Kr=Q.useCallback(e=>{Gr(t=>t&&t.length===e.length&&t.every((t,n)=>t===e[n])?t:[...e])},[]),qr=Q.useMemo(()=>{if(!Wr)return Ur;let e=new Set(Wr);return Ur.filter(t=>e.has(t.sessionId))},[Ur,Wr]),Jr=Q.useMemo(()=>e?[]:Ri({pinnedTargets:qr,projectTargets:Hr}),[e,qr,Hr]),Yr=Q.useCallback(e=>{Te(`chat`),Me(!1),e.scope===`project`&&e.projectId&&Se(e.projectId),kn(e.sessionId,e.directory,e.projectId,e.scope)},[kn,Te,Se,Me]);Q.useLayoutEffect(()=>ki({targets:Jr,activate:Yr}),[Yr,Jr]);let Xr=Q.useMemo(()=>{let e=new Map;return Jr.forEach(t=>{let n=yi({scope:t.scope,sessionId:t.sessionId,projectId:t.projectId});n&&e.set(n,mi(Jr,t)??0)}),e},[Jr]),Zr=Q.useMemo(()=>{if(!ht||Re)return[];let e=[],t=(n,r)=>{if(n.session.id===ht){e.push({scope:`pinned`,sessionId:ht,projectId:r});return}n.children.forEach(e=>t(e,r))};return Lr.forEach(e=>t(e.node,e.projectId)),Rr.forEach(e=>t(e.node,e.projectId)),e},[ht,Re,Rr,Lr]),Qr=Q.useMemo(()=>{if(!ht)return[];let e=[],t=(n,r)=>{if(n.session.id===ht){e.push({scope:`project`,sessionId:ht,projectId:r});return}n.children.forEach(e=>t(e,r))};return Tr.forEach(e=>{e.groups.forEach(n=>{n.sessions.forEach(n=>t(n,e.project.id))})}),e},[ht,Tr]);Q.useLayoutEffect(()=>Ai({pinned:qr,project:Hr}),[qr,Hr]),Q.useLayoutEffect(()=>{xr||Yb(yx({currentSessionId:ht,focus:gt,pinnedFocuses:Zr,projectFocuses:Qr,fallbackProjectId:ht?Mr.get(ht)?.projectId??null:null}))},[ht,xr,Qr,Zr,gt,Mr]);let $r=Q.useMemo(()=>{let e=gt?.sessionId?Mr.get(gt.sessionId)?.projectId??null:null;return bx(gt,Vr,e)},[Vr,gt,Mr]),ei=Q.useRef(null),ti=Q.useRef(null);Q.useEffect(()=>{ti.current&&ti.current!==ht&&(ti.current=null)},[ht]),Q.useLayoutEffect(()=>{if(!$r?.projectId)return;let e=$r.sessionId,t=_t.sessionId===e;if(!(!t&&ht!==e)){if(t){if(ei.current===_t.revision)return;ei.current=_t.revision,ti.current=e}else{if(ti.current===e)return;ti.current=e}if(ir($r.projectId),$r.groupKey&&ce(e=>{if(!e.has($r.groupKey))return e;let t=new Set(e);return t.delete($r.groupKey),t}),$r.folderAncestorIds?.forEach(e=>{let t=rr.getState();t.collapsedFolderIds.has(e)&&t.toggleFolderCollapse(e)}),$r.groupKey&&$r.visibleIndex!==void 0){let e=$r.visibleIndex+1;M(t=>{if((t.get($r.groupKey)??0)>=e)return t;let n=new Map(t);return n.set($r.groupKey,e),n})}}},[ht,$r,_t]);let ni=Tv(Q.useMemo(()=>{let e=new Set;return zr.forEach(t=>{D.has(t.project.id)||t.groups.forEach(n=>{if(se.has(`${t.project.id}:${n.id}`))return;let r=I(n.directory??null),i=n.branch?.trim()||tt.get(r||``)?.trim();!r||!i||e.add(ev(r,i))})}),[...e]},[se,D,tt,zr]));Q.useEffect(()=>{if(!a||!pr||!fr?.connected||!ur)return;let e=[],t=Date.now();if(zr.forEach(n=>{D.has(n.project.id)||n.groups.forEach(r=>{if(se.has(`${n.project.id}:${r.id}`))return;let i=I(r.directory??null),a=r.branch?.trim()||tt.get(i||``)?.trim();if(!i||!a)return;let o=ev(i,a),s=yv.getState().entries[o],c=!!s?.status?.pr,l=`${i}::${a}`,u=Math.max(s?.lastRefreshAt??0,s?.lastDiscoveryPollAt??0),d=!!(s?.isInitialStatusResolved&&!c&&(!_.current.has(l)||t-u>=Nx));(!s||!s.isInitialStatusResolved||d)&&(d&&_.current.add(l),e.push({directory:i,branch:a}))})}),e.length===0)return;let n=new Map;e.forEach(e=>{let t=ev(e.directory,e.branch,e.remoteName??null);n.has(t)||n.set(t,e)}),n.forEach((e,t)=>{hr(t),gr(t,{directory:e.directory,branch:e.branch,remoteName:e.remoteName??null,canShow:!0,github:ur,githubAuthChecked:pr,githubConnected:fr.connected})}),_r([...n.values()],{silent:!0,markInitialResolved:!0})},[D,se,hr,ur,pr,fr?.connected,tt,a,_r,zr,gr]);let ri=B_({isDesktopShellRuntime:Ft,projectSections:Tr,projectHeaderSentinelRefs:me,enabled:a}),ii=Lx((t,n=0,r,i,a=!1,o,s=`project`,c)=>(0,$.jsx)(lx,{node:t,depth:n,groupDirectory:r,projectId:i,archivedBucket:a,currentSessionId:ht,pinnedSessionIds:W,expandedParents:w,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,notifyOnSubtasks:K,editingId:v,setEditingId:y,editTitle:b,setEditTitle:x,handleSaveEdit:Rn,handleCancelEdit:zn,toggleParent:Mn,handleSessionSelect:Pn,handleSessionDoubleClick:Fn,togglePinnedSession:oe,handleShareSession:Bn,copiedSessionId:gn,handleCopyShareUrl:Hn,handleUnshareSession:Wn,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,renamingFolderId:z,getFoldersForScope:We,getSessionFolderId:$e,removeSessionFromFolder:Xe,addSessionToFolder:Je,createFolderAndStartRename:Kn,openContextPanelTab:Oe,handleDeleteSession:Gn,mobileVariant:e,alwaysShowActions:zt,renderSessionNode:ii,secondaryMeta:o,renderContext:s,subtreeContainsActive:c?.subtreeContainsActive??Px,subtreeContainsEditing:c?.subtreeContainsEditing??Px,menuOpenSessionId:c?.menuOpenSessionId??null,nodeStructureKey:c?.nodeStructureKey??``,childRenderExtrasFor:c?.childRenderExtrasFor,liveSessionById:Pt,shortcutNumber:Xr.get(yi({scope:s,sessionId:t.session.id,projectId:i??null})??``)??null},`${s}:${i??``}:${t.session.id}`)),ai=Q.useCallback(e=>{Jn(e),ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[Jn]),oi=Q.useCallback(e=>{let t=Xn(e);if(t.length===0)return;let n=tn.getState(),r=t.filter(e=>!n.archivedLoadedDirectories.has(e));r.length>0&&Ln(r)},[Xn]),si=Q.useMemo(()=>{let e=new Map;for(let[t,n]of ni)e.set(t,{visualState:n.visualState,number:n.number,url:n.url,state:n.prState,draft:n.draft,title:n.title,base:n.base,head:n.head,checks:n.checks,canMerge:n.canMerge,mergeableState:n.mergeableState,repo:n.repo});return e},[ni]),ci=vt((e,t,n,r,i)=>{let a=e.folderScopeKey??I(e.directory??null);a&&et(a,t,n,r,i).catch(()=>X.error(o(`sessions.order.saveFailed`)))}),li=vt((e,t,n)=>{e.isArchivedBucket&&se.has(t)&&n&&oi(n),ai(t)}),ui=Q.useMemo(()=>(t,n,r,i,a,o,s)=>(0,$.jsx)(oy,{group:t,groupKey:n,isArchivedLoading:!!(t.isArchivedBucket&&r&&Xn(r).some(e=>ft.has(e))),projectId:r,hideGroupLabel:i,compactBodyPadding:o,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:Le,groupSearchDataByGroup:Er,visibleSessionCount:j.get(n),collapsedGroups:se,collapsedFolderIds:Be,toggleFolderCollapse:Qe,renameFolder:Ke,deleteFolder:qe,showDeletionDialog:Pe,setDeleteFolderConfirm:U,renderSessionNode:ii,projectRepoStatus:k,lastRepoStatus:Sr.current,showMoreGroupSessions:qn,resetGroupSessionLimit:Jn,mobileVariant:e,alwaysShowActions:zt,activeProjectId:be,setActiveProjectIdOnly:Se,setActiveMainTab:Te,setSessionSwitcherOpen:Me,openNewSessionDraft:kt,addSessionToFolder:Je,createFolderAndStartRename:Kn,renamingFolderId:z,renameFolderDraft:V,setRenameFolderDraft:ee,setRenamingFolderId:B,pinnedSessionIds:W,expandedParents:w,sessionOrderByScope:He,sessionOrderActivityByScope:Ue,onReorderSessions:ci,currentSessionId:ht,shortcutTargetSessionId:$r?.groupKey===n?$r.sessionId:null,shortcutTargetVisibleIndex:$r?.groupKey===n?$r.visibleIndex??null:null,editingId:v,editTitle:b,openSidebarMenuKey:L,liveSessionById:Pt,alwaysVisibleSessionIds:rt,prVisualStateByDirectoryBranch:si,onToggleCollapsedGroup:li,dragHandleProps:a,scrollContainerRef:s}),[Re,Le,Er,ft,Xn,j,se,Be,Qe,Ke,qe,Pe,ii,k,qn,Jn,e,zt,be,Se,Te,Me,kt,Je,Kn,z,V,W,w,He,Ue,ci,ht,$r,v,b,L,Pt,rt,si,li]),di=r?null:(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(vy,{collapseAllProjects:er,expandAllProjects:tr}),(0,$.jsx)(Y,{variant:`ghost`,size:`xs`,className:`size-6 p-0 text-muted-foreground`,"aria-label":o(`sessions.sidebar.header.actions.addProject`),title:o(`sessions.sidebar.header.actions.addProject`),onClick:bn.requestDirectoryDialog,children:(0,$.jsx)(Z,{name:`add`,className:`size-4`})})]}),fi=Ft&&Lt&&!st&&!Re?(0,$.jsx)(`div`,{className:`shrink-0 px-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(Ou,{className:`min-w-0 flex-1`}),(0,$.jsx)(bc,{className:`ml-auto shrink-0`})]})}):null,pi=!st&&!Re,hi=!Re&&(Lr.length>0||Rr.length>0),gi=pi||hi?(0,$.jsxs)($.Fragment,{children:[pi?(0,$.jsxs)($.Fragment,{children:[e&&Lt?(0,$.jsx)(Ou,{}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5 py-1`,children:[(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,e&&`h-11`),onClick:un,children:[(0,$.jsx)(Z,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`sessions.sidebar.header.actions.newSession`)})]}),(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,Ee===`schedule`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:dn,children:[(0,$.jsx)(Z,{name:`time`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`sessions.sidebar.header.actions.scheduledTasks`)}),a?(0,$.jsx)(u_,{}):null]}),De.data?.supported&&De.data?.enabled?(0,$.jsxs)(Y,{variant:`ghost`,size:`sm`,className:J(`w-full justify-start font-normal`,Ee===`assistant`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:fn,children:[(0,$.jsx)(Z,{name:`ai-agent`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:o(`assistants.title`)}),(0,$.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,$.jsx)(qc,{}),a?(0,$.jsx)(d_,{}):null]})]}):null]})]}):null,hi?(0,$.jsx)(ly,{items:Lr,reorderEnabled:!0,onSessionsReordered:Fr,inProgressItems:Rr,renderSessionNode:ii,currentSessionId:ht,editingId:v,openSidebarMenuKey:L,onVisibleSessionIdsChange:Kr}):null]}):null,_i=!!(z||v||S),{selectionModeEnabled:vi,hasSelection:bi,selectedIdsSize:xi,bulkScopeIsArchived:Si,derivedSelectionScope:Ci,bulkScopeFolders:wi,bulkCanRemoveFromFolder:Ti,handleExitSelectionMode:Ei,handleBulkMoveToFolder:Di,handleBulkCreateFolderAndMove:Oi,handleBulkRemoveFromFolder:ji,handleBulkDelete:Mi,confirmBulkDelete:Ni}=gx({isInlineEditing:_i,showDeletionDialog:Pe,foldersMap:Ve,addSessionsToFolder:Ye,removeSessionsFromFolders:Ze,createFolderAndStartRename:Nn,archiveSessions:hn,setBulkDeleteConfirm:ae});return(0,$.jsxs)(`div`,{ref:h,className:J(`yuri-session-sidebar relative flex h-full flex-col text-foreground overflow-x-hidden`,e?``:`bg-transparent`),children:[(0,$.jsx)(sy,{hideDirectoryControls:r,isSessionSearchOpen:u,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchQuery:f,setSessionSearchQuery:m,hasSessionSearchQuery:Re,searchMatchCount:Or}),fi,a?(0,$.jsx)(Ny,{topContent:gi,hasLeadingSection:gi!==null&&(Lr.length>0||Rr.length>0),headerAccessory:di,sectionsForRender:zr,projectSections:Tr,activeProjectId:be,showOnlyMainWorkspace:i,hasSessionSearchQuery:Re,emptyState:nn,searchEmptyState:kr,renderGroupSessions:ui,homeDirectory:ge,collapsedProjects:D,hideDirectoryControls:r,projectRepoStatus:k,isDesktopShellRuntime:Ft,stuckProjectHeaders:ri,mobileVariant:e,alwaysShowActions:zt,toggleProject:nr,setActiveProjectIdOnly:Se,setActiveMainTab:Te,setSessionSwitcherOpen:Me,openNewSessionDraft:kt,openNewWorktreeDialog:on,syncProjectSessions:Qn,openProjectEditDialog:C,removeProject:xe,projectHeaderSentinelRefs:me,projectReorderEnabled:Cr===`manual`,reorderProjects:we,projectSortOrder:Cr,getOrderedGroups:Ar,setGroupOrderByProject:le,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,isInlineEditing:_i}):null,vi&&bi?(0,$.jsx)(hx,{selectedCount:xi,scopeKey:Ci,scopeFolders:wi,archivedBucket:Si,onMoveToFolder:Di,onCreateFolderAndMove:Oi,onRemoveFromFolder:ji,canRemoveFromFolder:Ti,onDelete:Mi,onDone:Ei}):null,(0,$.jsx)(g_,{normalizedProjects:ar,ownership:vr,enabled:a}),(0,$.jsx)(wy,{onOpenSettings:ln,onOpenShortcuts:Ae,onOpenUpdate:cn,showRuntimeButtons:!st,showUpdateButton:ze}),c?(0,$.jsx)(Rx,{onOpenChange:l}):null,rn?(0,$.jsx)(Ev,{open:!0,onOpenChange:e=>{e||C(null)},project:rn,onSave:an}):null,N?(0,$.jsx)(Pr,{open:!0,onOpenChange:P,onWorktreeCreated:sn}):null,(0,$.jsx)(Bc,{}),(0,$.jsx)(js,{}),(0,$.jsx)(fx,{value:H,setValue:ne,showDeletionDialog:Pe,setShowDeletionDialog:Fe,onConfirm:Dn}),(0,$.jsx)(mx,{value:re,setValue:U,onConfirm:An}),(0,$.jsx)(px,{value:ie,setValue:ae,showDeletionDialog:Pe,setShowDeletionDialog:Fe,onConfirm:Ni})]})});function Bx(e){return{info:e.info,downloading:e.downloading,downloaded:e.downloaded,progress:e.progress,error:e.error,runtimeType:e.runtimeType,onDownload:e.downloadUpdate,onRestart:e.restartToUpdate}}var Vx=e=>e?(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:e}):void 0,Hx=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Ux=()=>{let{t:e}=Tt(),[t,n]=Q.useState(!1),[r,i]=Q.useState(!1),[a,o]=Q.useState(null),[s,c]=Q.useState([]),[l,u]=Q.useState(!1),[d,f]=Q.useState(!1),[p,m]=Q.useState(!1),[h,g]=Q.useState(!1),[_,v]=Q.useState(new Set),y=Sn(e=>e.getWorktreeMetadata),b=Sn(e=>e.newSessionDraft),x=Sn(e=>e.setNewSessionDraftTarget),S=Sn(e=>e.setDraftBootstrapPendingDirectory),C=qn,w=Sn(e=>e.archiveSessions),T=q(e=>e.showDeletionDialog),E=q(e=>e.setShowDeletionDialog),D=je(e=>e.currentDirectory),O=je(e=>e.homeDirectory),k=je(e=>e.isHomeReady),A=jn(e=>e.projects),j=jn(e=>e.activeProjectId),{isMobile:M,isTablet:N,hasTouchInput:P}=no(),F=M||N||P,I=Q.useMemo(()=>Hx((j?A.find(e=>e.id===j)??null:null)?.path??D),[j,D,A]),L=Q.useCallback(e=>{let t=Hx(e.projectDirectory)||I;return{id:(A.find(e=>Hx(e.path)===t)??null)?.id??`path:${t}`,path:t}},[I,A]),R=h&&_.size>0,z=Q.useMemo(()=>{let e=a?.worktree;return e&&typeof e.branch==`string`&&e.branch.trim().length>0?!0:s.length>0&&s.every(({metadata:e})=>typeof e.branch==`string`&&e.branch.trim().length>0)},[a?.worktree,s]),B=a?.mode===`worktree`,V=B,ee=p||!B||!z,H=p||!B;Q.useEffect(()=>{r||!k||A.length>0||(i(!0),n(!0))},[r,k,A.length]);let te=Q.useCallback(e=>{o({sessions:e.sessions,dateLabel:e.dateLabel,mode:e.mode??`session`,worktree:e.worktree??null})},[]),ne=Q.useCallback(()=>{o(null),c([]),u(!1),f(!1),m(!1),g(!1),v(new Set)},[]),re=Q.useCallback(t=>{if(t.sessions.length===0)return;let n=t.sessions.map(e=>e.id);Js({sessionIds:n,message:n.length===1?e(`sessions.sidebar.session.delete.success`):e(`sessions.sidebar.bulkActions.deletedPlural`,{count:n.length}),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:n.length===1?e(`sessions.sidebar.session.delete.error`):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:n.length})})},[e]);Q.useEffect(()=>bn.onDeleteRequest(e=>{if(!T&&(e.mode??`session`)===`session`){re(e);return}te(e)}),[te,T,re]),Q.useEffect(()=>bn.onDirectoryRequest(()=>{n(!0)}),[]),Q.useEffect(()=>{if(!a){c([]),u(!1),f(!1),g(!1),v(new Set);return}let e=a.sessions.map(e=>{let t=y(e.id);return t?{session:e,metadata:t}:null}).filter(e=>!!e);c(e),u(!1),g(!1),v(new Set);let t=new Map;if(a.worktree?.path&&t.set(Hx(a.worktree.path),a.worktree),e.forEach(({metadata:e})=>{e.path&&t.set(Hx(e.path),e)}),t.size===0){g(!0);return}let n=!1;return(async()=>{let e=new Map,r=new Set;await Promise.all(Array.from(t.entries()).map(async([t,n])=>{try{let i=await oa(n.path);e.set(t,i),i?.isDirty&&r.add(t)}catch{n.status&&(e.set(t,n.status),n.status.isDirty&&r.add(t))}})).catch(e=>{console.warn(`Failed to inspect worktree status before deletion:`,e)}),!n&&(v(r),g(!0),o(t=>{if(!t?.worktree?.path)return t;let n=Hx(t.worktree.path),r=e.get(n);if(!r)return t;let i=t.worktree.status;return i?.isDirty===r.isDirty&&i?.ahead===r.ahead&&i?.behind===r.behind&&i?.upstream===r.upstream?t:{...t,worktree:{...t.worktree,status:r}}}),c(t=>t.map(t=>{let n=Hx(t.metadata.path),r=e.get(n);return r?{session:t.session,metadata:{...t.metadata,status:r}}:t})))})(),()=>{n=!0}},[a,y]),Q.useEffect(()=>{z||u(!1)},[z]);let U=Q.useCallback(async(t,n)=>{let r=l&&z,i=L(t),a=Hx(t.path),o=Hx(i.path);try{await ra(i,t,{deleteRemoteBranch:r,deleteLocalBranch:n});let e=Hx(b?.directoryOverride);return b?.open&&a&&e===a&&o&&(S(null),x({projectId:i.id,directoryOverride:o},{force:!0})),Hx(D)===a&&o&&je.getState().setDirectory(o,{showOverlay:!1}),!0}catch(t){return X.error(e(`sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle`),{description:Vx(t instanceof Error?t.message:e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),!1}},[z,D,l,L,b?.directoryOverride,b?.open,S,x,e]),ie=Q.useCallback((t,n)=>{let r=l&&z;(async()=>{if(!await U(t,n))return;let i=e(r?`sessions.sidebar.sessionDialogs.worktree.removedWithRemote`:`sessions.sidebar.sessionDialogs.worktree.removed`);X.success(e(`sessions.sidebar.sessionDialogs.worktree.removedTitle`),{description:Vx(i)})})()},[z,l,U,e]),ae=Q.useCallback(async()=>{if(a){m(!0);try{let t=V&&d;if(a.sessions.length===0&&B&&a.worktree){ie(a.worktree,t),ne();return}if(a.sessions.length===1){let t=a.sessions[0];if(B){if(!await C(t.id)){X.error(e(`sessions.sidebar.session.archive.error`)),m(!1);return}Xs({sessionIds:[t.id],message:e(`sessions.sidebar.session.archive.success`),undoLabel:e(`sessions.sidebar.undo`),settingsLabel:e(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:e(`sessions.sidebar.session.archive.undoFailed`)})}else Js({sessionIds:[t.id],message:e(`sessions.sidebar.session.delete.success`),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:e(`sessions.sidebar.session.delete.error`)})}else{let n=a.sessions.map(e=>e.id),r=[],i=[];if(B){let e=await w(n);r=e.archivedIds,i=e.failedIds}else Js({sessionIds:n,message:n.length===1?e(`sessions.sidebar.bulkActions.deletedSingle`,{count:n.length}):e(`sessions.sidebar.bulkActions.deletedPlural`,{count:n.length}),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:n.length===1?e(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:n.length}):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:n.length})}),r=n,i=[];if(B&&a.worktree&&i.length===0&&ie(a.worktree,t),B&&r.length>0&&Xs({sessionIds:r,message:r.length===1?e(`sessions.sidebar.bulkActions.archivedSingle`,{count:r.length}):e(`sessions.sidebar.bulkActions.archivedPlural`,{count:r.length}),undoLabel:e(`sessions.sidebar.undo`),settingsLabel:e(`settings.yuri.archivedSessions.actions.view`),undoFailedMessage:r.length===1?e(`sessions.sidebar.session.archive.undoFailed`):e(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:r.length})}),i.length>0&&(X.error(B?i.length===1?e(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:i.length}):e(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:i.length}):i.length===1?e(`sessions.sidebar.bulkActions.failedDeleteSingle`,{count:i.length}):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:i.length}),{description:Vx(e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),r.length===0)){m(!1);return}}B&&a.sessions.length===1&&a.worktree&&ie(a.worktree,t),ne()}finally{m(!1)}}},[a,d,C,w,ne,V,B,ie,e]),W=a?.worktree??s[0]?.metadata??null,oe=a?a.mode===`worktree`?a.sessions.length===0?e(`sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked`):a.sessions.length===1?e(`sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked`,{count:a.sessions.length}):e(`sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked`,{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?e(`sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate`,{dateLabel:a.dateLabel}):e(`sessions.sidebar.dialogs.sessionDelete.descriptionOne`):a.dateLabel?e(`sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate`,{count:a.sessions.length,dateLabel:a.dateLabel}):e(`sessions.sidebar.dialogs.sessionDelete.descriptionMany`,{count:a.sessions.length}):``,se=a?(0,$.jsxs)(`div`,{className:J(B?`space-y-3`:`space-y-2`),children:[a.sessions.length>0&&(0,$.jsxs)(`div`,{className:J(B?`rounded-lg bg-muted/30 p-3`:`space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3`),children:[B&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:a.sessions.length===1?e(`sessions.sidebar.sessionDialogs.linkedSessionSingle`):e(`sessions.sidebar.sessionDialogs.linkedSessionPlural`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground/70`,children:a.sessions.length})]}),(0,$.jsxs)(`ul`,{className:J(B?`mt-2 space-y-1`:`space-y-0.5`),children:[a.sessions.slice(0,5).map(t=>(0,$.jsxs)(`li`,{className:J(B?`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:[(0,$.jsx)(`span`,{className:J(!B&&`hidden`),children:`•`}),(0,$.jsx)(`span`,{className:`truncate`,children:t.title||e(`sessions.sidebar.session.untitled`)})]},t.id)),a.sessions.length>5&&(0,$.jsx)(`li`,{className:J(B?`px-2.5 py-1 text-xs text-muted-foreground/70`:`typography-micro text-muted-foreground/70`),children:e(`sessions.sidebar.dialogs.sessionList.more`,{count:a.sessions.length-5})})]})]}),B?(0,$.jsxs)(`div`,{className:`space-y-2 rounded-lg bg-muted/30 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`typography-meta font-medium text-foreground`,children:e(`sessions.sidebar.sessionDialogs.worktree.label`)}),W?.label?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground/70`,children:W.label}):null]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground/80 break-all`,children:W?St(W.path,O):e(`sessions.sidebar.sessionDialogs.worktree.pathUnavailable`)}),R&&(0,$.jsx)(`p`,{className:`typography-micro text-status-warning`,children:e(`sessions.sidebar.sessionDialogs.worktree.uncommittedWarning`)})]}):(0,$.jsx)(`div`,{className:`rounded-xl border border-border/40 bg-sidebar/60 p-3`,children:(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/80`,children:e(`sessions.sidebar.sessionDialogs.delete.note`)})})]}):null,ce=B?z?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ee||u(e=>!e)},disabled:ee,className:J(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,ee?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[l?(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}),e(`sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch`)]}):(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground/70`,children:e(`sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable`)}):null,G=B?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{H||f(e=>!e)},disabled:H,className:J(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,H?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[d?(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}),e(`sessions.sidebar.sessionDialogs.actions.deleteLocalBranch`)]}):null,le=B?(0,$.jsxs)(`div`,{className:`flex w-full items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[G,ce]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ne,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:ae,disabled:p,children:e(p?`sessions.sidebar.sessionDialogs.actions.deleting`:`sessions.sidebar.sessionDialogs.actions.deleteWorktree`)})]})]}):(0,$.jsxs)(`div`,{className:`flex w-full items-center justify-between gap-3`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>E(!T),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":!T,children:[T?(0,$.jsx)(Z,{name:`checkbox-blank`,className:`size-4`}):(0,$.jsx)(Z,{name:`checkbox`,className:`size-4 text-primary`}),e(`sessions.sidebar.dialogs.neverAsk`)]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Y,{variant:`ghost`,onClick:ne,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Y,{variant:`destructive`,onClick:ae,disabled:p,children:p?e(`sessions.sidebar.sessionDialogs.actions.deleting`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`)})]})]}),ue=B?e(`sessions.sidebar.sessionDialogs.actions.deleteWorktree`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`);return(0,$.jsxs)($.Fragment,{children:[F?(0,$.jsx)(Wa,{open:!!a,onClose:()=>{p||ne()},title:ue,footer:(0,$.jsx)(`div`,{className:`flex justify-end gap-2`,children:le}),children:(0,$.jsxs)(`div`,{className:`space-y-2 pb-2`,children:[oe&&(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/80`,children:oe}),se]})}):(0,$.jsx)(mr,{open:!!a,onOpenChange:e=>{if(!e){if(p)return;ne()}},children:(0,$.jsxs)(dr,{className:J(B?`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:[(0,$.jsxs)(lr,{children:[(0,$.jsxs)(fr,{className:J(B&&`flex items-center gap-2`),children:[B&&(0,$.jsx)(Z,{name:`delete-bin`,className:`h-5 w-5`}),ue]}),oe&&(0,$.jsx)(pr,{children:oe})]}),(0,$.jsx)(`div`,{className:J(B&&`flex-1 min-h-0 overflow-y-auto space-y-2`),children:se}),(0,$.jsx)(ur,{className:`mt-2 gap-2 pt-1 pb-1`,children:le})]})}),(0,$.jsx)(zc,{open:t,onOpenChange:n})]})},Wx=Q.createContext(null),Gx=e=>{let t=(0,pl.c)(3),{children:n,value:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Wx.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Kx=No(()=>dt(()=>import(`./TerminalView-mF-mbAzo.js`).then(e=>({default:e.TerminalView})),__vite__mapDeps([63,1,4,2,3,5,6,7,8,9,10,11,12,13,16,17,18,64,14,15,65,33,34,35,36,44,45,30,31,32,46,47,48,37,38,66,52,67,68,69,70,71,72]))),qx=No(()=>dt(()=>import(`./DiagramView-BRK8rzVX.js`).then(e=>({default:e.DiagramView})),__vite__mapDeps([73,1,3,2,8,11,7,9,10,17,5,16,4,12,18,45,33,6,13,34,35,36,38,52,14,15,44,30,31,32,46,47,48,74,75]))),Jx=No(()=>dt(()=>import(`./SettingsView-DWeiBwOG.js`).then(e=>e.n).then(e=>({default:e.SettingsView})),__vite__mapDeps([76,1,2,3,4,5,6,7,8,9,10,11,12,13,77,78,14,15,16,17,18,79,80,45,30,31,32,33,34,35,36,81,82,44,46,47,48,38,83,49,84,85,54,37,39,50,86,87,88,58,66,89,90,42,68,69,70,91,92,93,43,20,21,22,23,24,25,26,27,28,29,51,52,53,94,55,67,95,96,97,98,99,100,101,102,103,104,105,106,72,107,61,108,109,110]))),Yx=No(()=>dt(()=>import(`./SettingsWindow-1csE2lF6.js`).then(e=>({default:e.SettingsWindow})),__vite__mapDeps([111,1,8,12,33,6,2,3,4,5,7,9,10,11,13,34,18,35,36,76,77,78,14,15,16,17,79,80,45,30,31,32,81,82,44,46,47,48,38,83,49,84,85,54,37,39,50,86,87,88,58,66,89,90,42,68,69,70,91,92,93,43,20,21,22,23,24,25,26,27,28,29,51,52,53,94,55,67,95,96,97,98,99,100,101,102,103,104,105,106,72,107,61,108,109,110]))),Xx=No(()=>dt(()=>import(`./MultiRunWindow-rggd5jvJ.js`).then(e=>({default:e.MultiRunWindow})),__vite__mapDeps([112,1,8,12,33,6,2,3,4,5,7,9,10,11,13,34,18,35,36,38,113,14,15,16,17,30,31,32,44,45,46,47,48,87,86,88,58,66,89,90,42,68,69,70,114,83,49,84,85,54,37,115,116,102]))),Zx=No(()=>dt(()=>import(`./AssistantView-BJyGm9Js.js`).then(e=>e.n).then(e=>({default:e.AssistantView})),__vite__mapDeps([117,1,3,2,6,4,5,7,8,9,10,11,12,13,14,15,16,17,18,45,30,31,32,33,34,35,36,81,82,44,46,47,48,38,83,49,84,85,54,37,39,50,66,40,41,89,90,42,118,93,119,56,120,115,116,51,52,53,121,107,122,123]))),Qx=()=>{let e=1220,t=q(e=>e.isSidebarOpen),n=q(e=>e.isRightSidebarOpen),r=q(e=>e.isBottomTerminalOpen),i=q(e=>e.setRightSidebarOpen),a=q(e=>e.setBottomTerminalOpen),o=q(e=>e.activeMainTab),s=q(e=>e.setIsMobile),c=q(e=>e.isSessionSwitcherOpen),l=q(e=>e.isSettingsDialogOpen),u=q(e=>e.setSettingsDialogOpen),d=q(e=>e.isMultiRunLauncherOpen),f=q(e=>e.setMultiRunLauncherOpen),{isMobile:p,isTablet:m}=no(),h=Q.useRef(!1),g=Q.useRef(!1),_=Q.useRef(!1),[v,y]=Q.useState(!1),[b,x]=Q.useState(!1),[S,C]=Q.useState(!1),[w,T]=Q.useState(!1),E=Q.useCallback(e=>{y(e),q.getState().setSessionSwitcherOpen(e)},[]),D=Q.useRef(!1),O=Q.useRef(typeof window>`u`?0:window.innerWidth),k=vo(-O.current),A=(0,Q.useRef)(0),j=vo(O.current),M=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{p&&(A.current=window.innerWidth,M.current=window.innerWidth)},[p]),(0,Q.useEffect)(()=>{if(!p){C(!1);return}v&&C(!0),yo(k,v?0:-A.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[v,p,k]),(0,Q.useEffect)(()=>{if(!p){T(!1);return}D.current=b,b&&T(!0),yo(j,b?0:M.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[p,b,j]),(0,Q.useEffect)(()=>{if(p)return k.on(`change`,e=>{let t=A.current||O.current,n=v||e>-t+.5;C(e=>e===n?e:n)})},[p,k,v]),(0,Q.useEffect)(()=>{if(p)return j.on(`change`,e=>{let t=M.current||O.current,n=b||e<t-.5;T(e=>e===n?e:n)})},[p,b,j]),(0,Q.useEffect)(()=>{p&&!c&&v&&E(!1)},[c,p,v,E]),(0,Q.useEffect)(()=>{if(!p){_.current=!1;return}_.current||(_.current=!0,E(!1),x(!1),q.getState().isRightSidebarOpen&&i(!1))},[p,E,i]),(0,Q.useEffect)(()=>{if(!p||o!==`chat`||v||b||l)return;let e=!1,t,n=r=>{t=window.setTimeout(()=>{if(e)return;let t=Sn.getState(),r=q.getState();if(!(r.activeMainTab!==`chat`||r.isSettingsDialogOpen||t.currentSessionId||t.newSessionDraft?.open)){if(t.isLoading){n(250);return}t.openNewSessionDraft()}},r)};return n(500),()=>{e=!0,t!==void 0&&window.clearTimeout(t)}},[o,p,l,v,b]),(0,Q.useEffect)(()=>{!p||!l||(E(!1),x(!1),n&&i(!1))},[p,l,n,E,i]),Q.useEffect(()=>{q.getState().isMobile!==p&&s(p)},[p,s]),Q.useEffect(()=>{if(typeof window>`u`)return;let e,t=()=>{e===void 0&&(e=window.requestAnimationFrame(()=>{e=void 0,q.getState().updateProportionalSidebarWidths()}))};return window.addEventListener(`resize`,t),()=>{window.removeEventListener(`resize`,t),e!==void 0&&window.cancelAnimationFrame(e)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let t,n=()=>{let t=q.getState(),n=window.innerWidth,r=window.innerHeight;!p&&!m&&(n<1140?t.isRightSidebarOpen&&(i(!1),h.current=!0):n>=e&&h.current&&(i(!0),h.current=!1),r<640?t.isBottomTerminalOpen&&(a(!1),g.current=!0):r>=700&&g.current&&(a(!0),g.current=!1))},r=()=>{t===void 0&&(t=window.requestAnimationFrame(()=>{t=void 0,n()}))};return n(),window.addEventListener(`resize`,r),()=>{window.removeEventListener(`resize`,r),t!==void 0&&window.cancelAnimationFrame(t)}},[p,m,a,i]),Q.useEffect(()=>{if(typeof window>`u`)return;let t=q.subscribe((t,n)=>{let r=window.innerWidth,i=window.innerHeight,a=r>=e,o=i>=700;t.isRightSidebarOpen!==n.isRightSidebarOpen&&a&&(h.current=!1),t.isBottomTerminalOpen!==n.isBottomTerminalOpen&&o&&(g.current=!1)});return()=>{t()}},[p,m,a,i]);let N=Q.useCallback(()=>{v&&E(!1),x(!b)},[v,b,E]),P=Q.useMemo(()=>{switch(o){case`git`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(cf,{isActive:!b})});case`diff`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Ys,{})});case`terminal`:return r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Kx,{})});case`files`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Ep,{})});case`diagram`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(qx,{})});default:return null}},[o,r,b]),F=o===`schedule`,I=o===`assistant`,L=F||I,R=o===`chat`,z=!L&&!l;return(0,$.jsx)(_c,{children:(0,$.jsxs)(`div`,{"data-page-scroll-lock":`true`,className:J(`main-content-safe-area`,p?`flex h-[100dvh] flex-col`:`relative flex h-[100dvh]`,`bg-background`),children:[(0,$.jsx)(Dc,{}),(0,$.jsx)(n_,{}),(0,$.jsx)(o_,{}),(0,$.jsx)(Ux,{}),p?(0,$.jsxs)(Gx,{value:{leftDrawerOpen:v,rightDrawerOpen:b,toggleLeftDrawer:()=>{let e=!v;b&&x(!1),E(e)},toggleRightDrawer:N,leftDrawerX:k,rightDrawerX:j,leftDrawerWidth:A,rightDrawerWidth:M,setMobileLeftDrawerOpen:E,setRightSidebarOpen:x},children:[!l&&!L&&(0,$.jsx)(pu,{onToggleLeftDrawer:()=>{let e=!v;b&&x(!1),E(e)},onToggleRightDrawer:()=>{N()},leftDrawerOpen:v,rightDrawerOpen:b}),(0,$.jsx)(`div`,{"data-page-scroll-lock":`true`,className:J(`flex flex-1 overflow-hidden relative`,l&&`hidden`),children:(0,$.jsxs)(`main`,{className:`w-full h-full overflow-hidden bg-background relative`,"data-page-scroll-lock":`true`,children:[F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(sc,{})})})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Zx,{})})})}),z&&(0,$.jsx)(`div`,{className:J(`absolute inset-0`,!R&&`invisible`),children:(0,$.jsx)(ha,{children:(0,$.jsx)(oc,{})})}),z&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(ha,{children:P})}),d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(ha,{children:(0,$.jsx)(cl,{onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),(0,$.jsx)(ss.div,{className:J(`absolute inset-0 z-20 bg-sidebar`,!S&&`pointer-events-none invisible`),"data-page-scroll-lock":`true`,style:{x:k},"aria-hidden":!v,children:(0,$.jsx)(ha,{children:(0,$.jsx)(zx,{mobileVariant:!0,isVisible:S})})}),w&&(0,$.jsx)(ss.div,{className:`absolute inset-0 z-20 bg-sidebar`,"data-page-scroll-lock":`true`,style:{x:j},"aria-hidden":!b,children:(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(cf,{isActive:b})})})})]})}),l&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,style:{paddingTop:`var(--yuri-safe-area-top, 0px)`},children:(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Jx,{onClose:()=>u(!1)})})})}),(0,$.jsx)(ha,{children:(0,$.jsx)(Ws,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Nu,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(Eu,{isOpen:t,isMobile:p,className:`border-border/50`,topBar:(0,$.jsx)(Du,{}),children:(0,$.jsx)(zx,{isVisible:t})}),(0,$.jsx)(`div`,{className:`relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:L?(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:I?(0,$.jsx)(Zx,{}):(0,$.jsx)(sc,{})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(pu,{}),(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-h-0 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-w-0 flex-col overflow-hidden yuri-layout-divider-t bg-background`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-h-0 min-w-0 overflow-hidden`,"data-page-scroll-lock":`true`,"data-chat-area":!0,children:[(0,$.jsxs)(`main`,{className:`flex-1 overflow-hidden bg-background relative`,"data-page-scroll-lock":`true`,children:[z&&(0,$.jsx)(`div`,{className:J(`absolute inset-0`,!R&&`invisible`),children:(0,$.jsx)(ha,{children:(0,$.jsx)(oc,{})})}),z&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(ha,{children:P})})]}),(0,$.jsx)(e_,{})]})}),(0,$.jsx)(vu,{isOpen:r,isMobile:p,children:r?(0,$.jsx)(ha,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Kx,{})})}):null})]}),(0,$.jsx)(Hu,{isOpen:n,className:`bg-background yuri-layout-divider-t`,children:(0,$.jsx)(ha,{children:(0,$.jsx)(Hf,{})})})]})]})})]}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Yx,{open:l,onOpenChange:u})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Xx,{open:d,onOpenChange:f})})]})]})})},$x=e=>{if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},eS=e=>{let t=(0,pl.c)(8),{label:n,value:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`div`,{className:`typography-meta text-[var(--surface-muted-foreground)]`,children:n}),t[1]=n,t[2]=a);let o;t[3]===r?o=t[4]:(o=(0,$.jsx)(`div`,{className:`typography-markdown font-semibold text-[var(--surface-foreground)]`,children:r}),t[3]=r,t[4]=o);let s;return t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`rounded-md p-2`,style:i,children:[a,o]}),t[5]=a,t[6]=o,t[7]=s):s=t[7],s},tS=e=>{let t=(0,pl.c)(43),{title:n,snapshot:r,emptyLabel:i}=e,{t:a}=Tt(),o;if(t[0]!==i||t[1]!==r.durationMs||t[2]!==r.entries||t[3]!==r.lastUpdatedAt||t[4]!==r.startedAt||t[5]!==a||t[6]!==n){let e=r.entries.slice(0,12),s;t[8]===r.entries?s=t[9]:(s=r.entries.reduce(rS,0),t[8]=r.entries,t[9]=s);let c=s,l;t[10]===n?l=t[11]:(l=(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:n}),t[10]=n,t[11]=l);let u;t[12]!==r.durationMs||t[13]!==r.startedAt||t[14]!==a?(u=r.startedAt?$x(r.durationMs):a(`memoryDebugPanel.common.idle`),t[12]=r.durationMs,t[13]=r.startedAt,t[14]=a,t[15]=u):u=t[15];let d;t[16]===u?d=t[17]:(d=(0,$.jsx)(`div`,{className:`typography-meta text-[var(--surface-muted-foreground)]`,children:u}),t[16]=u,t[17]=d);let f;t[18]!==l||t[19]!==d?(f=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[l,d]}),t[18]=l,t[19]=d,t[20]=f):f=t[20];let p;t[21]===a?p=t[22]:(p=a(`memoryDebugPanel.metric.metrics`),t[21]=a,t[22]=p);let m;t[23]!==r.entries.length||t[24]!==p?(m=(0,$.jsx)(eS,{label:p,value:r.entries.length}),t[23]=r.entries.length,t[24]=p,t[25]=m):m=t[25];let h;t[26]===a?h=t[27]:(h=a(`memoryDebugPanel.metric.samples`),t[26]=a,t[27]=h);let g;t[28]!==h||t[29]!==c?(g=(0,$.jsx)(eS,{label:h,value:c}),t[28]=h,t[29]=c,t[30]=g):g=t[30];let _;t[31]===a?_=t[32]:(_=a(`memoryDebugPanel.metric.lastUpdate`),t[31]=a,t[32]=_);let v;t[33]!==r.lastUpdatedAt||t[34]!==a?(v=r.lastUpdatedAt?a(`memoryDebugPanel.common.live`):a(`memoryDebugPanel.common.notAvailable`),t[33]=r.lastUpdatedAt,t[34]=a,t[35]=v):v=t[35];let y;t[36]!==_||t[37]!==v?(y=(0,$.jsx)(eS,{label:_,value:v}),t[36]=_,t[37]=v,t[38]=y):y=t[38];let b;t[39]!==g||t[40]!==y||t[41]!==m?(b=(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[m,g,y]}),t[39]=g,t[40]=y,t[41]=m,t[42]=b):b=t[42],o=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0`,children:[f,b,e.length===0?(0,$.jsx)(`div`,{className:`rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]`,style:{backgroundColor:`color-mix(in srgb, var(--surface-muted) 45%, transparent)`},children:i}):(0,$.jsx)(mo,{outerClassName:`max-h-64`,className:`pr-1`,children:(0,$.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-[var(--interactive-border)] p-2`,style:{backgroundColor:`color-mix(in srgb, var(--surface-elevated) 88%, transparent)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)] break-all`,children:e.metric}),(0,$.jsxs)(`div`,{className:`mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]`,children:[(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.countValue`,{value:e.count})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.avgValue`,{value:e.avg})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.maxValue`,{value:e.max})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.totalValue`,{value:e.total})})]})]},e.metric))})})]}),t[0]=i,t[1]=r.durationMs,t[2]=r.entries,t[3]=r.lastUpdatedAt,t[4]=r.startedAt,t[5]=a,t[6]=n,t[7]=o}else o=t[7];return o},nS=e=>{let t=(0,pl.c)(104),{onClose:n}=e,{t:r}=Tt(),[i,a]=Q.useState(`memory`),[o,s]=Q.useState(`idle`),c=Sn(iS),l=Ht(aS),u=Xn(),d=ir(),[f,p]=Q.useState(oS),m,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>Pe(()=>{p(Ge())}),h=[],t[0]=m,t[1]=h):(m=t[0],h=t[1]),Q.useEffect(m,h);let g;if(t[2]!==d||t[3]!==u){bb0:{let e=Ae(),t={};if(!e){g=t;break bb0}let n=e.getCacheBudget?.(),r=n?n.listCanonical().map(sS):u.map(e=>({directory:d,sessionID:e.id}));for(let n of r){if(d&&n.directory!==d)continue;let r=e.getTranscript(Ie(n.directory,n.sessionID));t[n.sessionID]=r.messageOrder.map(e=>r.messagesByID[e]).filter(cS)}g=t}t[2]=d,t[3]=u,t[4]=g}else g=t[4];let _=g,v=yv(lS),[y,b]=Q.useState(uS),[x,S]=Q.useState(dS),C;t[5]===y.entries?C=t[6]:(C=new Map,y.entries.forEach(e=>{C.set(e.metric,e.count)}),t[5]=y.entries,t[6]=C);let w;t[7]===C?w=t[8]:(w=C.get(`ui.message_list.render`)??0,t[7]=C,t[8]=w);let T;t[9]===C?T=t[10]:(T=C.get(`ui.message_list.render.streaming`)??0,t[9]=C,t[10]=T);let E;t[11]===C?E=t[12]:(E=C.get(`ui.chat_message.render`)??0,t[11]=C,t[12]=E);let D;t[13]===C?D=t[14]:(D=C.get(`ui.chat_message.render.streaming`)??0,t[13]=C,t[14]=D);let O;t[15]===C?O=t[16]:(O=C.get(`ui.chat_message.render.static_during_stream`)??0,t[15]=C,t[16]=O);let k;t[17]===C?k=t[18]:(k=C.get(`ui.chat_message.render.static_outside_active_turn_during_stream`)??0,t[17]=C,t[18]=k);let A;t[19]!==w||t[20]!==T||t[21]!==E||t[22]!==D||t[23]!==O||t[24]!==k?(A={messageListRender:w,messageListRenderStreaming:T,chatMessageRender:E,chatMessageRenderStreaming:D,chatMessageRenderStaticDuringStream:O,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},t[19]=w,t[20]=T,t[21]=E,t[22]=D,t[23]=O,t[24]=k,t[25]=A):A=t[25];let j=A,M,N;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>{let e=()=>{b(Ke()),S(ze())};e();let t=window.setInterval(e,500);return()=>window.clearInterval(t)},N=[],t[26]=M,t[27]=N):(M=t[26],N=t[27]),Q.useEffect(M,N);let P,F;t[28]===o?(P=t[29],F=t[30]):(P=()=>{if(o===`idle`)return;let e=window.setTimeout(()=>{s(`idle`)},1500);return()=>window.clearTimeout(e)},F=[o],t[28]=o,t[29]=P,t[30]=F),Q.useEffect(P,F);let I=0,L=0,R=0;for(let e of Object.keys(_)){let t=_[e]??[];L+=t.length;for(let e of t)e.role===`user`?R+=1:e.role===`assistant`&&(I+=1)}let z;t[31]!==I||t[32]!==L||t[33]!==R?(z={assistant:I,total:L,user:R},t[31]=I,t[32]=L,t[33]=R,t[34]=z):z=t[34];let B=z,V;if(t[35]!==c||t[36]!==_||t[37]!==l||t[38]!==u||t[39]!==r){let e;t[41]!==c||t[42]!==_||t[43]!==l||t[44]!==r?(e=e=>{let t=_[e.id]??[],n=0,i=0;for(let e of t)e.role===`user`?i+=1:e.role===`assistant`&&(n+=1);let a=l.get(e.id);return{id:e.id,title:e.title||r(`memoryDebugPanel.common.untitled`),assistantMessageCount:n,messageCount:t.length,userMessageCount:i,isStreaming:a?.isStreaming||!1,isZombie:a?.isZombie||!1,backgroundCount:a?.backgroundMessageCount||0,lastAccessed:a?.lastAccessedAt||0,isCurrent:e.id===c}},t[41]=c,t[42]=_,t[43]=l,t[44]=r,t[45]=e):e=t[45],V=u.map(e).sort(fS),t[35]=c,t[36]=_,t[37]=l,t[38]=u,t[39]=r,t[40]=V}else V=t[40];let ee=V,H;t[46]===_?H=t[47]:(H=Object.keys(_),t[46]=_,t[47]=H);let te=H.length,ne;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(ne=async()=>{try{let e={generatedAt:new Date().toISOString(),ui:Ke(),vscode:ze()};await navigator.clipboard.writeText(JSON.stringify(e,null,2)),s(`copied`)}catch{s(`error`)}},t[48]=ne):ne=t[48];let re=ne,U;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(U={backgroundColor:`color-mix(in srgb, var(--surface-background) 94%, transparent)`},t[49]=U):U=t[49];let ie;t[50]===i?ie=t[51]:(ie=i===`memory`?(0,$.jsx)(Z,{name:`database-2`,className:`h-4 w-4 text-[var(--surface-foreground)]`}):(0,$.jsx)(Z,{name:`bar-chart-box`,className:`h-4 w-4 text-[var(--surface-foreground)]`}),t[50]=i,t[51]=ie);let ae;t[52]===r?ae=t[53]:(ae=r(`memoryDebugPanel.title`),t[52]=r,t[53]=ae);let W;t[54]===ae?W=t[55]:(W=(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:ae}),t[54]=ae,t[55]=W);let oe;t[56]!==ie||t[57]!==W?(oe=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ie,W]}),t[56]=ie,t[57]=W,t[58]=oe):oe=t[58];let se;t[59]===i?se=t[60]:(se=i===`streaming`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{size:`xs`,variant:`ghost`,onClick:re,children:(0,$.jsx)(Z,{name:`file-copy`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Y,{size:`xs`,variant:`ghost`,onClick:()=>{Ne(),b(Ke()),S(ze())},children:(0,$.jsx)(Z,{name:`refresh`,className:`h-3.5 w-3.5`})})]}):null,t[59]=i,t[60]=se);let ce;t[61]===n?ce=t[62]:(ce=n?(0,$.jsx)(Y,{size:`icon`,variant:`ghost`,className:`h-6 w-6`,onClick:n,children:(0,$.jsx)(Z,{name:`close`,className:`h-4 w-4`})}):null,t[61]=n,t[62]=ce);let G;t[63]!==se||t[64]!==ce?(G=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[se,ce]}),t[63]=se,t[64]=ce,t[65]=G):G=t[65];let le;t[66]!==oe||t[67]!==G?(le=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[oe,G]}),t[66]=oe,t[67]=G,t[68]=le):le=t[68];let ue;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(ue={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[69]=ue):ue=t[69];let de=i===`memory`?`secondary`:`ghost`,fe;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(fe=()=>a(`memory`),t[70]=fe):fe=t[70];let pe;t[71]===r?pe=t[72]:(pe=r(`memoryDebugPanel.tabs.memory`),t[71]=r,t[72]=pe);let me;t[73]!==de||t[74]!==pe?(me=(0,$.jsx)(Y,{size:`sm`,variant:de,className:`flex-1`,onClick:fe,children:pe}),t[73]=de,t[74]=pe,t[75]=me):me=t[75];let he=i===`streaming`?`secondary`:`ghost`,ge;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(ge=()=>a(`streaming`),t[76]=ge):ge=t[76];let _e;t[77]===r?_e=t[78]:(_e=r(`memoryDebugPanel.tabs.streaming`),t[77]=r,t[78]=_e);let ve;t[79]!==he||t[80]!==_e?(ve=(0,$.jsx)(Y,{size:`sm`,variant:he,className:`flex-1`,onClick:ge,children:_e}),t[79]=he,t[80]=_e,t[81]=ve):ve=t[81];let ye;t[82]!==me||t[83]!==ve?(ye=(0,$.jsxs)(`div`,{className:`mb-3 flex gap-1 rounded-md p-1`,style:ue,children:[me,ve]}),t[82]=me,t[83]=ve,t[84]=ye):ye=t[84];let be;t[85]!==i||t[86]!==te||t[87]!==o||t[88]!==c||t[89]!==_||t[90]!==B||t[91]!==l||t[92]!==ee||t[93]!==u||t[94]!==j||t[95]!==y||t[96]!==r||t[97]!==v||t[98]!==x?(be=i===`memory`?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 typography-meta`,children:[(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.totalMessages`),value:B.total}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.cachedSessions`),value:`${te} / ${Br.MAX_SESSIONS}`}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.userMessages`),value:B.user}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.assistantMessages`),value:B.assistant})]}),(0,$.jsxs)(`div`,{className:`typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.viewportWindow`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.messagesValue`,{count:$r()})})]}),(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.zombieTimeout`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.minutesValue`,{count:Br.ZOMBIE_TIMEOUT/1e3/60})})]}),(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.githubTotalRequests`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:v})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 typography-meta font-semibold text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.section.sessionsInMemory`)}),(0,$.jsx)(mo,{outerClassName:`max-h-48`,className:`space-y-1 pr-1`,children:ee.map(e=>(0,$.jsxs)(`div`,{className:`typography-meta flex items-center justify-between rounded p-1.5`,style:{backgroundColor:e.isCurrent?`color-mix(in srgb, var(--interactive-selection) 22%, transparent)`:`color-mix(in srgb, var(--surface-muted) 35%, transparent)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[var(--surface-foreground)]`,children:e.title}),e.isStreaming?(0,$.jsx)(Z,{name:`pulse`,className:`h-3 w-3 animate-pulse text-[var(--status-info)]`}):null,e.isZombie?(0,$.jsx)(`span`,{className:`text-[var(--status-warning)]`,children:`!`}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-mono text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.roleMsgsValue`,{assistant:e.assistantMessageCount,user:e.userMessageCount})}),(0,$.jsx)(`span`,{className:`font-mono text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.msgsValue`,{count:e.messageCount})}),e.backgroundCount>0?(0,$.jsxs)(`span`,{className:`text-[var(--status-info)]`,children:[`+`,e.backgroundCount]}):null]})]},e.id))})]}),(0,$.jsx)(`div`,{className:`flex gap-2 border-t border-[var(--interactive-border)] pt-2`,children:(0,$.jsxs)(pa,{children:[(0,$.jsx)(ua,{asChild:!0,children:(0,$.jsx)(Y,{size:`sm`,variant:`outline`,className:`typography-meta`,onClick:()=>{u.map(pS),Object.keys(_),ee.map(mS),Object.fromEntries(l)},children:r(`memoryDebugPanel.actions.logState`)})}),(0,$.jsx)(da,{side:`top`,children:r(`memoryDebugPanel.tooltip.logCurrentState`)})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.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:[(0,$.jsx)(`span`,{children:r(o===`copied`?`memoryDebugPanel.streaming.copy.copied`:o===`error`?`memoryDebugPanel.streaming.copy.failed`:`memoryDebugPanel.streaming.copy.hint`)}),(0,$.jsx)(Y,{size:`xs`,variant:`outline`,onClick:re,children:r(`memoryDebugPanel.actions.copyJson`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.uiMetrics`),value:y.entries.length}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.vscodeMetrics`),value:x.entries.length}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.messageListRenders`),value:j.messageListRender}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.messageListStreamRenders`),value:j.messageListRenderStreaming}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.chatMessageRenders`),value:j.chatMessageRender}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.chatMessageStreamRenders`),value:j.chatMessageRenderStreaming}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.chatMessageStaticDuringStream`),value:j.chatMessageRenderStaticDuringStream}),(0,$.jsx)(eS,{label:r(`memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn`),value:j.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),(0,$.jsx)(tS,{title:r(`memoryDebugPanel.section.uiStreamingMetrics`),snapshot:y,emptyLabel:r(`memoryDebugPanel.section.noUiSamples`)}),x.entries.length>0?(0,$.jsx)(tS,{title:r(`memoryDebugPanel.section.vscodeBridgeMetrics`),snapshot:x,emptyLabel:r(`memoryDebugPanel.section.noVscodeSamples`)}):null]}),t[85]=i,t[86]=te,t[87]=o,t[88]=c,t[89]=_,t[90]=B,t[91]=l,t[92]=ee,t[93]=u,t[94]=j,t[95]=y,t[96]=r,t[97]=v,t[98]=x,t[99]=be):be=t[99];let xe;return t[100]!==le||t[101]!==ye||t[102]!==be?(xe=(0,$.jsxs)(Qa,{className:`fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area`,style:U,children:[le,ye,be]}),t[100]=le,t[101]=ye,t[102]=be,t[103]=xe):xe=t[103],xe};function rS(e,t){return e+t.count}function iS(e){return e.currentSessionId}function aS(e){return e.sessionMemoryState}function oS(){return Ge()}function sS(e){return e.scope}function cS(e){return!!e}function lS(e){return e.totalRequestCount}function uS(){return Ke()}function dS(){return ze()}function fS(e,t){return t.lastAccessed-e.lastAccessed}function pS(e){return{id:e.id,title:e.title}}function mS(e){return{id:e.id,title:e.title,total:e.messageCount,user:e.userMessageCount,assistant:e.assistantMessageCount}}var hS=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=q.getState();if(e)return;let n=ts();n&&t(n)||D()&&j(`desktop_close_current_window`).catch(e=>{console.warn(`[menu-actions] failed to close current window`,e)})},gS=()=>{if(typeof document>`u`)return``;let e=document.activeElement;if(e instanceof HTMLTextAreaElement)return e.value.slice(e.selectionStart??0,e.selectionEnd??0);if(e instanceof HTMLInputElement){let t=e.type?.toLowerCase()??`text`;if([`text`,`search`,`url`,`tel`,`password`].includes(t))return e.value.slice(e.selectionStart??0,e.selectionEnd??0)}return e instanceof HTMLElement&&e.isContentEditable?e.ownerDocument.defaultView?.getSelection?.()?.toString()??``:``},_S=async()=>{let e=gS()||window.getSelection()?.toString()||``;if(!e.trim())return!1;try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}return document.execCommand(`copy`)},vS=`yuri:menu-action`,yS=`yuri:check-for-updates`,bS=e=>typeof e?.listen==`function`?`bridge`:`dom`,xS=e=>{let t=Sn(e=>e.openNewSessionDraft),n=q(e=>e.toggleCommandPalette),r=q(e=>e.setCommandPaletteOpen),i=q(e=>e.toggleHelpDialog),a=q(e=>e.toggleSidebar),o=q(e=>e.setSessionSwitcherOpen),s=q(e=>e.setActiveMainTab),c=q(e=>e.setSettingsDialogOpen),l=q(e=>e.setSettingsPage),u=q(e=>e.setAboutDialogOpen),d=q(e=>e.toggleRightSidebar),f=q(e=>e.setRightSidebarOpen),p=q(e=>e.setRightSidebarTab),m=q(e=>e.toggleBottomTerminal),h=q(e=>e.setBottomTerminalExpanded),g=ms(e=>e.checkForUpdates),{setThemeMode:_}=sr(),{t:v}=Tt(),y=Q.useRef(!1),b=typeof window>`u`?null:window.__YURI_DESKTOP__,x=bS(b),S=Q.useCallback(()=>{y.current||(y.current=!0,g().then(()=>{let{available:e,error:t}=ms.getState();if(t){X.error(v(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}e||X.success(v(`sessions.sidebar.updateCheck.latestVersion`))}).finally(()=>{y.current=!1}))},[g,v]),C=Q.useCallback(()=>{bn.requestDirectoryDialog()},[]),w=Q.useCallback(e=>{Fi(e,Sn.getState().currentSessionId,e=>{s(`chat`),o(!1),Sn.getState().setCurrentSession(e.sessionId,e.directory)})},[s,o]),T=Q.useCallback(e=>{let{activeProjectId:t,projects:n,setActiveProject:r}=jn.getState();if(n.length===0)return;let i=n.findIndex(e=>e.id===t),a=e>0?0:n.length-1;i>=0&&(a=(i+e+n.length)%n.length);let o=n[a];o&&r(o.id)},[]),E=Q.useCallback(g=>{switch(g){case`about`:u(!0);break;case`settings`:c(!0);break;case`switch-instance`:l(`remote-instances`),c(!0);break;case`command-palette`:n();break;case`quick-open`:r(!0);break;case`new-session`:s(`chat`),o(!1),t();break;case`new-worktree-session`:s(`chat`),o(!1),zi();break;case`change-workspace`:C();break;case`close-tab-or-window`:hS();break;case`toggle-right-sidebar`:d();break;case`open-right-sidebar-git`:f(!0),p(`git`);break;case`open-right-sidebar-files`:f(!0),p(`files`);break;case`toggle-terminal`:m();break;case`toggle-terminal-expanded`:h(!q.getState().isBottomTerminalExpanded);break;case`copy`:{let e=new Event(`yuri:copy`,{cancelable:!0});window.dispatchEvent(e)&&_S();break}case`theme-light`:_(`light`);break;case`theme-dark`:_(`dark`);break;case`theme-system`:_(`system`);break;case`toggle-sidebar`:a();break;case`toggle-memory-debug`:e?.();break;case`zoom-in`:hi();break;case`zoom-out`:vi();break;case`zoom-reset`:Hi();break;case`go-back`:je.getState().goBack();break;case`go-forward`:je.getState().goForward();break;case`previous-session`:w(-1);break;case`next-session`:w(1);break;case`previous-project`:T(-1);break;case`next-project`:T(1);break;case`help-dialog`:i();break;case`download-logs`:qi().catch(()=>{X.error(`Failed to collect OpenCode status`)})}},[C,T,w,e,t,u,s,o,r,c,l,h,f,p,_,m,n,i,d,a]);Q.useEffect(()=>{if(x!==`dom`)return;let e=e=>{let t=e.detail;t&&E(t)},t=()=>{S()};return window.addEventListener(vS,e),window.addEventListener(yS,t),()=>{window.removeEventListener(vS,e),window.removeEventListener(yS,t)}},[E,S,x]),Q.useEffect(()=>{if(x!==`bridge`)return;let e=b?.listen;if(typeof e!=`function`)return;let t=null,n=null;return e(`yuri:menu-action`,e=>{let t=e?.payload;typeof t==`string`&&E(t)}).then(e=>{t=e}).catch(()=>{}),e(`yuri:check-for-updates`,S).then(e=>{n=e}).catch(()=>{}),()=>{(async()=>{try{let e=t?.();e instanceof Promise&&await e}catch{}try{let e=n?.();e instanceof Promise&&await e}catch{}})()}},[b,E,S,x])},SS=(e,t)=>e<t?-1:+(e>t),CS=e=>JSON.stringify([...e.entries()].map(([e,t])=>[e,[...new Set(t)].sort(SS)]).sort(([e],[t])=>SS(e,t)));async function wS({targets:e,isReady:t,fetchStatus:n,applySnapshot:r,concurrency:i=2,isDisposed:a=()=>!1}){if(!t()||a())return;let o=[...e.entries()],s=0,c=Math.min(Math.max(1,i),o.length),l=async()=>{for(;s<o.length&&t()&&!a();){let e=o[s];if(s+=1,!e)return;let[t,i]=e,c=await n(t);c===null||a()||r(t,c,i)}};await Promise.all(Array.from({length:c},()=>l()))}var TS=`yuri:tray-action`,ES=3e4,DS=120,OS=20,kS=()=>{if(typeof window>`u`)return!1;let e=window.__YURI_PLATFORM__;return e===`darwin`||e===`win32`},AS=e=>{let t=typeof e.permission==`string`?e.permission:`Permission`,n=Array.isArray(e.patterns)?e.patterns.find(e=>typeof e==`string`&&e.trim()):``;return n?`${t}: ${n}`:t},jS=e=>{let t=Array.isArray(e.questions)?e.questions[0]:void 0;return t?.header||t?.question||`Question`},MS=e=>sn(e),NS=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},PS=(e,t,n,r)=>{if(!e)return``;let i=dn(t,n,e),a=NS(i?i.path:e),o=ar(e),s=o&&r.get(o)||``;if(!s){for(let[e,t]of ko.getState().directories)if(ar(e)===o){s=t.status?.current??``;break}}if(!s)for(let e of n.values()){let t=e.find(e=>ar(e.path)===o);if(t?.branch){s=t.branch;break}}return s?`${a} · ${s}`:a},FS=()=>{let{results:e,dropdownProviderIds:t,displayMode:n}=Ts.getState(),r=n===`remaining`?`remaining`:`usage`;if(!t.length)return{mode:r,groups:[]};let i=new Map(e.map(e=>[e?.providerId,e])),a=[];for(let n of ls(e)){if(!t.includes(n.id))continue;let e=i.get(n.id);if(!e||e.configured!==!0)continue;let o=[];for(let[t,n]of Object.entries(e.usage?.windows??{})){let e=r===`remaining`?n.remainingPercent:n.usedPercent;o.push({label:xa(n.label??t),value:La(n.valueLabel,e)})}let s=!e.ok&&e.error?e.error:o.length===0?`No rate limits reported`:null;a.push({provider:n.name,rows:o,status:s})}return{mode:r,groups:a}},IS=async()=>{try{if(v())return`Local Yuri`;let e=window.__YURI_LOCAL_ORIGIN__||window.location.origin,t=m();if(t&&ae(t,e))return`Local Yuri`;let n=(await se()).hosts.find(e=>t?ae(t,oe(e)):!1);return n?.label?.trim()?W(n.label.trim()):`Instance`}catch{return``}},LS=()=>{let e=new Map,t=new Map,n=[],r=new Map,i;try{i=Je()}catch{return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}}for(let[a,o]of i.children.entries()){let i=o.getState(),s=typeof i.vcs?.branch==`string`?i.vcs.branch:typeof i.vcs?.branch?.current==`string`?i.vcs.branch.current:``;s&&t.set(ar(a)??a,s);for(let e of i.session)!e?.id||!e.title||r.set(e.id,e.title);for(let[t,n]of Object.entries(i.session_status??{})){let r=n?.type,i=r===`busy`?`busy`:r===`retry`?`retry`:`idle`,a=e.get(t);(!a||a===`idle`)&&e.set(t,i)}for(let[e,t]of Object.entries(i.permission??{}))for(let r of t??[]){if(!r?.id)continue;let t=r.sessionID||e;n.push({kind:`permission`,id:r.id,sessionId:t,sessionTitle:``,label:AS(r),directory:a})}for(let[e,t]of Object.entries(i.question??{}))for(let r of t??[]){if(!r?.id)continue;let t=r.sessionID||e;n.push({kind:`question`,id:r.id,sessionId:t,sessionTitle:``,label:jS(r),directory:a})}}return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}},RS=()=>{let e=tn.getState().activeSessions,t=new Set;e.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>MS(t)-MS(e)).slice(0,OS).forEach(e=>{let n=In(e);n&&t.add(n)});let n=new Map;for(let r of e){if(!r?.id)continue;let e=In(r);if(!e||!t.has(e))continue;let i=n.get(e)??[];i.push(r.id),n.set(e,i)}return n},zS=e=>{let t=LS(),n=mn.getState().index.session,r=tn.getState().activeSessions,i=new Map(t.titleById),a=new Map;for(let e of r)if(e?.id&&(e.title&&i.set(e.id,e.title),e.parentID)){let t=a.get(e.parentID)??[];t.push(e.id),a.set(e.parentID,t)}let o=e=>{let t=[],n=[...a.get(e)??[]],r=new Set;for(;n.length;){let e=n.pop();r.has(e)||(r.add(e),t.push(e),n.push(...a.get(e)??[]))}return t},s=rn.getState().statusById,c=e=>{let n=t.statusById.get(e);return n&&n!==`idle`?n:s.get(e)?.status??n??`idle`},l=e=>{let t=e.map(e=>c(e));return t.includes(`busy`)?`busy`:t.includes(`retry`)?`retry`:`idle`},u=jn.getState().projects,d=Sn.getState().availableWorktreesByProject,f=r.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>MS(t)-MS(e)).slice(0,OS).map(e=>{let r=[e.id,...o(e.id)],i=In(e)??``;return{id:e.id,title:e.title||`Untitled session`,status:l(r),branch:i?t.branchByDirectory.get(i)??``:``,unseen:n.unseenCount[e.id]??0,hasError:n.unseenHasError[e.id]??!1,directory:i,subtitle:PS(i,u,d,t.branchByDirectory)}}),p=t.approvals.map(e=>({...e,sessionTitle:i.get(e.sessionId)||``})),m=q.getState(),h=0;if(m.dockBadgeEnabled)for(let e of r)!e?.id||e.parentID||(n.unseenCount[e.id]??0)>0&&(h+=1);return{sessions:f,approvals:p,instanceName:e,usage:FS(),dockBadgeCount:h}},BS=()=>{Q.useEffect(()=>{if(!kS()||!D())return;let e=!1,t=``,n=null,r=``,i=()=>{if(e)return;let n=zS(r),i=JSON.stringify(n);i!==t&&(t=i,j(`desktop_tray_update`,n))};IS().then(t=>{e||(r=t,i())});let a=null,o=``,s=()=>{let e=Qn.getState();return e.isConnected&&e.connectionPhase===`connected`},c=()=>{if(a)return a;let t=RS();return o=CS(t),a=wS({targets:t,isReady:s,concurrency:2,isDisposed:()=>e,fetchStatus:async()=>{try{let e=await Le.getSdkClient().session.active();if(!e||typeof e!=`object`||Array.isArray(e))return null;let t={};for(let[n,r]of Object.entries(e))r?.type===`running`&&(t[n]={type:`busy`});return t}catch{return null}},applySnapshot:(e,t,n)=>{Jt(e,t,[...n])}}).finally(()=>{a=null;let t=RS();!e&&s()&&CS(t)!==o&&c()}),a},l=()=>{e||n!==null||(n=window.setTimeout(()=>{n=null,i()},DS))},u=new Map,d=()=>{if(e)return;let t;try{t=Je()}catch{return}let n=new Set;for(let[e,r]of t.children.entries())n.add(e),u.has(e)||u.set(e,r.subscribe(()=>l()));for(let[e,t]of u)n.has(e)||(t(),u.delete(e))},f=null;try{f=Je().subscribeRegistry(()=>{d(),l()})}catch{}d();let p=mn.subscribe(()=>l()),m=tn.subscribe(()=>{l(),s()&&CS(RS())!==o&&c()}),h=jn.subscribe(()=>l()),g=Sn.subscribe(()=>l()),_=ko.subscribe(()=>l()),v=q.subscribe(()=>l()),y=rn.subscribe(()=>l()),b=s(),x=Qn.subscribe(()=>{let e=s();e&&!b&&c(),b=e});b&&c();let S=Ts.subscribe(()=>l());Ts.getState().loadSettings().then(()=>{if(e)return;let{dropdownProviderIds:t,results:n}=Ts.getState();t.length>0&&t.some(e=>!n.some(t=>t?.providerId===e))&&Ts.getState().fetchAllQuotas()});let C=window.setInterval(()=>{let e=Ts.getState();e.autoRefresh&&e.dropdownProviderIds.length>0&&e.fetchAllQuotas()},Math.max(3e4,Ts.getState().refreshIntervalMs||6e4)),w=window.setInterval(()=>{d(),i()},ES);return i(),()=>{e=!0,n!==null&&window.clearTimeout(n),window.clearInterval(w),window.clearInterval(C),p(),m(),h(),g(),_(),v(),y(),x(),S(),f?.();for(let e of u.values())e();u.clear()}},[]),Q.useEffect(()=>{if(!kS()||typeof window>`u`)return;let e=window.__YURI_DESKTOP__?.listen;if(typeof e!=`function`)return;let t=e=>{e.type===`respond-permission`&&Yn(e.sessionId,e.id,e.response).catch(()=>{X.error(`Failed to respond to permission request`)})},n=null;return e(TS,e=>{let n=e?.payload;!n||typeof n!=`object`||typeof n.type!=`string`||t(n)}).then(e=>{n=e}).catch(()=>{}),()=>{try{let e=n?.();e instanceof Promise&&e.catch(()=>{})}catch{}}},[])},VS=`/api/notifications/stream`,HS=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),US=e=>{if(!e||typeof e!=`object`)return null;let t=e,n=t.properties&&typeof t.properties==`object`?t.properties:null;return t.type!==`yuri: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,requireHidden:n.requireHidden===!0||n.requireHidden!==!1&&void 0}},WS=e=>{let t=(0,pl.c)(3),n=e?.enabled??!0,r,i;t[0]===n?(r=t[1],i=t[2]):(r=()=>{if(!n||F()||!z()||typeof window>`u`||typeof EventSource>`u`)return;let e=new EventSource(c().sse(VS));return e.onmessage=GS,()=>{e.close()}},i=[n],t[0]=n,t[1]=r,t[2]=i),Q.useEffect(r,i)};function GS(e){let t;try{t=JSON.parse(e.data)}catch{return}let n=q.getState();if(!n.nativeNotificationsEnabled)return;let r=US(t);r&&((r.requireHidden??n.notificationMode!==`always`)&&HS()||g()?.notifications?.notifyAgentCompletion(r))}var KS=`pwa-install-toast-shown`,qS=`pwa-install-toast-dismissed`,JS=()=>{let e=(0,pl.c)(6),{browserTab:t}=Ms(),{t:n}=Tt(),r=Q.useRef(n),i,a;e[0]===n?(i=e[1],a=e[2]):(i=()=>{r.current=n},a=[n],e[0]=n,e[1]=i,e[2]=a),Q.useEffect(i,a);let o,s;e[3]===t?(o=e[4],s=e[5]):(o=()=>{if(typeof window>`u`||!z()||!t)return;let e=null,n=null,i=()=>{n!==null&&(X.dismiss(n),n=null)},a=async()=>{if(!e)return;let t=e;e=null,i(),await t.prompt();let{outcome:n}=await t.userChoice;n===`accepted`&&X.success(r.current(`pwa.installPrompt.started`))},o=t=>{let o=t;if(typeof o.prompt!=`function`)return;o.preventDefault(),e=o;let s=Qe(),c=Ye();mc({dismissed:s.getItem(qS),sessionShown:c.getItem(KS),hasActiveToast:n!==null})&&(c.setItem(KS,`true`),n=X.info(r.current(`pwa.installPrompt.description`),{duration:1/0,action:{label:r.current(`pwa.installPrompt.action`),onClick:()=>{a()}},cancel:{label:r.current(`pwa.installPrompt.dismiss`),onClick:()=>{Qe().setItem(qS,`true`),i()}}}))},s=()=>{e=null,i(),X.success(r.current(`pwa.installPrompt.installed`))};return window.addEventListener(`beforeinstallprompt`,o),window.addEventListener(`appinstalled`,s),()=>{i(),window.removeEventListener(`beforeinstallprompt`,o),window.removeEventListener(`appinstalled`,s)}},s=[t],e[3]=t,e[4]=o,e[5]=s),Q.useEffect(o,s)};function YS(e){let t=typeof e?.sessionId==`string`?e.sessionId.trim():``;if(!t)return;let n=typeof e?.directory==`string`&&e.directory.trim().length>0?e.directory.trim():null;q.getState().setActiveMainTab(`chat`),Sn.getState().setCurrentSession(t,n)}var XS=({open:e,onOpenChange:t})=>{let{t:n}=Tt(),[r,i]=Q.useState(null),[a,o]=Q.useState(null);Q.useEffect(()=>{e&&(async()=>{try{let e=await _(`/api/system/info`);if(e.ok){let t=await e.json();if(typeof t.yuriVersion==`string`&&t.yuriVersion.trim()){i(t.yuriVersion);return}}}catch{}i(await Et())})()},[e]),Q.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await _(`/api/opencode/upgrade-status`,{headers:{Accept:`application/json`}});if(!e.ok)return;let n=await e.json().catch(()=>null),r=typeof n?.currentVersion==`string`?n.currentVersion.trim():``;!t&&r&&o(r)}catch{}})(),()=>{t=!0}},[e]);let s=r;return(0,$.jsx)(mr,{open:e,onOpenChange:t,children:(0,$.jsx)(dr,{className:`max-w-xs p-5`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-center`,children:[(0,$.jsx)(Ca,{width:48,height:48}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Yuri`}),(0,$.jsxs)(`div`,{className:`space-y-0.5 typography-meta text-muted-foreground`,children:[s&&(0,$.jsx)(`p`,{children:n(`aboutDialog.yuriVersionLabel`,{version:s})}),a&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openCodeVersionLabel`,{version:a})})]})]}),(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsxs)(`a`,{href:`https://github.com/yee94/yuri`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors`,children:[(0,$.jsx)(Z,{name:`github-fill`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:`GitHub`})]})}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground/60`,children:n(`aboutDialog.footerNote`)})]})})})},ZS=(e,t)=>{let n=e.get(t);return typeof n==`string`&&n.trim()||null},QS=(e,t)=>{let n=e instanceof Error?e.message:t;return/oauth state required/i.test(n)?`Authorization session expired or was cleared during reload. Return to Yuri and click Authorize again.`:n},$S=()=>{let e=hs(e=>e.completeAuth),[t,n]=Q.useState(`working`),[r,i]=Q.useState(`Completing MCP authorization...`);return Q.useEffect(()=>{if(typeof window>`u`){n(`error`),i(`Browser context unavailable.`);return}let t=new URLSearchParams(window.location.search),r=ZS(t,`code`),a=Os(t),o=cs(t),s=ZS(t,`error`),c=ZS(t,`error_description`);if(s){o&&_(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(c??s);return}(async()=>{try{if(!r)throw Error(`Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Yuri manually.`);let t=a;if(!t&&o){let e=await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`);if(e.ok){let n=await e.json().catch(()=>null);n?.name?.trim()&&(t={name:n.name.trim(),directory:typeof n.directory==`string`&&n.directory.trim()?n.directory.trim():null})}}if(!t?.name)throw Error(`Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Yuri manually.`);await e(t.name,r,t.directory),o&&await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`success`),i(`Authorization completed. You can close this tab and return to Yuri.`)}catch(e){o&&await _(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(QS(e,`Failed to complete MCP authorization.`))}})()},[e]),(0,$.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm dark:shadow-none`,children:[(0,$.jsxs)(`div`,{className:`space-y-3 text-center`,children:[(0,$.jsx)(`div`,{className:t===`error`?`text-[var(--status-error)]`:t===`success`?`text-[var(--status-success)]`:`text-[var(--status-info)]`,children:(0,$.jsx)(`h1`,{className:`typography-hero font-semibold`,children:t===`working`?`Completing Authorization`:t===`success`?`Authorization Complete`:`Authorization Failed`})}),(0,$.jsx)(`p`,{className:`typography-body text-muted-foreground`,children:r})]}),t!==`working`&&(0,$.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,$.jsx)(Y,{type:`button`,onClick:()=>{typeof window>`u`||window.location.replace(`/`)},children:`Return to Yuri`})})]})})},eC=()=>{let e=tn(e=>e.startupSyncProgress.active),t=tn(e=>e.startupSyncProgress.phase),n=tn(e=>e.startupSyncProgress.completed),r=tn(e=>e.startupSyncProgress.total),{locale:i,t:a}=Tt(),[o,s]=Q.useState(!0),c=At(i).startingApi;Q.useEffect(()=>{let e=!1,t=async()=>{try{let t=await(await _(`/health`,{signal:AbortSignal.timeout(4e3)})).json().catch(()=>null);if(e)return;let n=t?.openCodeStarting===!0||t?.isOpenCodeReady!==!0&&!t?.lastOpenCodeError;s(n)}catch{e||s(!0)}};t();let n=window.setInterval(()=>{t()},750);return()=>{e=!0,window.clearInterval(n)}},[]);let l=r>0?Math.round(n/r*100):0,u=t===`restoring`?a(`common.loading`):a(`sessions.startupSync.progress`,{completed:n,total:r});return Q.useLayoutEffect(()=>{let t=document.getElementById(`startup-session-progress`),i=document.getElementById(`startup-session-progress-track`),s=document.getElementById(`startup-session-progress-fill`),d=document.getElementById(`startup-session-progress-text`);if(!(!t||!i||!s||!d)){if(e){t.hidden=!1,s.style.width=`${l}%`,i.setAttribute(`aria-label`,a(`sessions.startupSync.title`)),i.setAttribute(`aria-valuemax`,String(Math.max(r,1))),i.setAttribute(`aria-valuenow`,String(n)),i.setAttribute(`aria-valuetext`,u),d.textContent=u;return}if(o){t.hidden=!1,s.style.width=`30%`,i.setAttribute(`aria-label`,c),i.setAttribute(`aria-valuetext`,c),d.textContent=c;return}t.hidden=!0}},[e,n,o,l,u,c,a,r]),null},tC=(e,t,n,r=350)=>n?Math.max(0,r-Math.max(0,t-e)):null;function nC(e){let t=(0,pl.c)(21),{transition:n,ready:r}=e,{t:i}=Tt(),a=Va(),[o,s]=Q.useState(0),c=n.epoch>o,l=a||c,u,d;if(t[0]!==c||t[1]!==a||t[2]!==r||t[3]!==n.epoch||t[4]!==n.startedAt?(u=()=>{if(!c||a)return;let e=tC(n.startedAt,Date.now(),r);if(e===null)return;let t=window.setTimeout(()=>{s(e=>Math.max(e,n.epoch))},e);return()=>window.clearTimeout(t)},d=[c,a,r,n.epoch,n.startedAt],t[0]=c,t[1]=a,t[2]=r,t[3]=n.epoch,t[4]=n.startedAt,t[5]=u,t[6]=d):(u=t[5],d=t[6]),Q.useEffect(u,d),!l)return null;let f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 opacity-70`,"aria-hidden":`true`,children:[(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 size-[28rem] -translate-x-1/2 -translate-y-1/2 rounded-full border border-[var(--interactive-border)]/40`}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 size-72 -translate-x-1/2 -translate-y-1/2 rounded-full bg-[var(--interactive-selection)]/10 blur-3xl`})]}),t[7]=f):f=t[7];let p;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`div`,{className:`mb-7 flex size-28 items-center justify-center rounded-[2rem] border border-[var(--interactive-border)]/60 bg-[var(--surface-elevated)]/75 shadow-2xl shadow-background/40`,children:(0,$.jsx)(Ca,{width:76,height:76,isAnimated:!0})}),t[8]=p):p=t[8];let m;t[9]===i?m=t[10]:(m=i(`desktopHostSwitcher.transition.title`),t[9]=i,t[10]=m);let h;t[11]===m?h=t[12]:(h=(0,$.jsx)(`h1`,{className:`typography-title text-foreground`,children:m}),t[11]=m,t[12]=h);let g;t[13]===i?g=t[14]:(g=i(`desktopHostSwitcher.transition.description`),t[13]=i,t[14]=g);let _;t[15]===g?_=t[16]:(_=(0,$.jsx)(`p`,{className:`mt-2 typography-body text-muted-foreground`,children:g}),t[15]=g,t[16]=_);let v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`div`,{className:`mt-7 h-1 w-28 overflow-hidden rounded-full bg-[var(--surface-muted)]`,"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`h-full w-1/2 animate-pulse rounded-full bg-[var(--status-info)] motion-reduce:animate-none`})}),t[17]=v):v=t[17];let y;return t[18]!==h||t[19]!==_?(y=(0,$.jsxs)(`div`,{className:`fixed inset-0 z-[9998] flex items-center justify-center overflow-hidden bg-background/95 px-6 backdrop-blur-xl`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[f,(0,$.jsxs)(`div`,{className:`relative flex max-w-md animate-in flex-col items-center text-center fade-in zoom-in-95 duration-300 motion-reduce:animate-none`,children:[p,h,_,v]})]}),t[18]=h,t[19]=_,t[20]=y):y=t[20],y}var rC=No(()=>dt(()=>import(`./OnboardingScreen-DTr_WxYY.js`).then(e=>({default:e.OnboardingScreen})),__vite__mapDeps([124,1,4,2,3,5,6,7,8,9,10,11,12,13,77,33,34,18,35,36,38,39,88]))),iC=36e5,aC=12e5,oC=()=>{let e=(0,pl.c)(3),t=q(pC),n=q(mC),r;return e[0]!==t||e[1]!==n?(r=(0,$.jsx)(XS,{open:t,onOpenChange:n}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r},sC=e=>{let t=(0,pl.c)(21),{onRetry:n,isRetrying:r}=e,{t:i}=Tt(),a;t[0]===i?a=t[1]:(a=i(`startup.initRecovery.title`),t[0]=i,t[1]=a);let o;t[2]===a?o=t[3]:(o=(0,$.jsx)(`h1`,{className:`typography-title text-foreground`,children:a}),t[2]=a,t[3]=o);let s;t[4]===i?s=t[5]:(s=i(`startup.initRecovery.description`),t[4]=i,t[5]=s);let c;t[6]===s?c=t[7]:(c=(0,$.jsx)(`p`,{className:`typography-body text-muted-foreground`,children:s}),t[6]=s,t[7]=c);let l;t[8]!==o||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[o,c]}),t[8]=o,t[9]=c,t[10]=l):l=t[10];let u;t[11]!==r||t[12]!==i?(u=i(r?`startup.initRecovery.retrying`:`startup.initRecovery.retry`),t[11]=r,t[12]=i,t[13]=u):u=t[13];let d;t[14]!==r||t[15]!==n||t[16]!==u?(d=(0,$.jsx)(Y,{type:`button`,onClick:n,disabled:r,children:u}),t[14]=r,t[15]=n,t[16]=u,t[17]=d):d=t[17];let f;return t[18]!==l||t[19]!==d?(f=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background px-6 text-foreground`,children:(0,$.jsxs)(`div`,{className:`flex max-w-md flex-col items-center gap-4 text-center`,children:[l,d]})}),t[18]=l,t[19]=d,t[20]=f):f=t[20],f},cC=e=>e?e.replace(/\\/g,`/`).replace(/\/+$/g,``):``,lC=()=>{if(typeof window>`u`||!po())return null;let e=new URLSearchParams(window.location.search),t=e.get(`sessionId`),n=typeof t==`string`?t.trim():``;if(!n)return null;let r=e.get(`directory`);return{sessionId:n,directory:typeof r==`string`&&r.trim().length>0?r.trim():null,readOnly:e.get(`readOnly`)===`1`||e.get(`readOnly`)===`true`}},uC=()=>typeof window>`u`?!1:window.location.pathname===gs,dC=e=>{let t=(0,pl.c)(22),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=e,a=je(hC),o=Sn(gC),s=Sn(_C),c=oi(),l=Q.useRef(null),u;t[0]===n.directory?u=t[1]:(u=cC(n.directory),t[0]=n.directory,t[1]=u);let d=u,f;t[2]===a?f=t[3]:(f=cC(a),t[2]=a,t[3]=f);let p=f,m,h;if(t[4]!==p||t[5]!==o||t[6]!==n.directory||t[7]!==n.sessionId||t[8]!==d||t[9]!==r||t[10]!==s||t[11]!==c?(m=()=>{if(r||d&&p!==d)return;let e=`${d}\n${n.sessionId}`;l.current===e&&o||(l.current=e,s(n.sessionId,n.directory),c.ensureSessionRenderable(n.sessionId,!0))},h=[p,o,n.directory,n.sessionId,d,r,s,c],t[4]=p,t[5]=o,t[6]=n.directory,t[7]=n.sessionId,t[8]=d,t[9]=r,t[10]=s,t[11]=c,t[12]=m,t[13]=h):(m=t[12],h=t[13]),Q.useEffect(m,h),d&&p!==d)return null;let g;t[14]===i?g=t[15]:(g=(0,$.jsx)(Ci,{embeddedBackgroundWorkEnabled:i}),t[14]=i,t[15]=g);let _;t[16]===n.readOnly?_=t[17]:(_=(0,$.jsx)(oc,{readOnly:n.readOnly}),t[16]=n.readOnly,t[17]=_);let v;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(zr,{}),t[18]=v):v=t[18];let y;return t[19]!==g||t[20]!==_?(y=(0,$.jsxs)($.Fragment,{children:[g,_,v]}),t[19]=g,t[20]=_,t[21]=y):y=t[21],y};function fC({apis:e}){Q.useEffect(()=>{We(`App:mounted`),He()},[]),Q.useEffect(()=>ln(),[]);let t=Qn(e=>e.initializeApp),n=Qn(e=>e.isInitialized),r=Qn(e=>e.isConnected),i=Sn(e=>e.error),a=Sn(e=>e.clearError),o=Sn(e=>!(e.newSessionDraft?.open&&e.currentSessionId===null)),c=je(e=>e.currentDirectory),l=je(e=>e.setDirectory),u=je(e=>e.isSwitchingDirectory),[p,m]=Q.useState(!1),g=Ps(e=>e.refreshStatus),[_,b]=Q.useState(()=>e.runtime.isVSCode),[x,w]=Q.useState(!1),[T,D]=Q.useState(!1),[O,k]=Q.useState(0),[A,M]=Q.useState(0),[N,P]=Q.useState({epoch:0,startedAt:0}),[I,R]=Q.useState(!1),z=Q.useRef(!1),V=q(e=>e.wideChatLayoutEnabled),H=q(e=>e.mobileKeyboardMode),te=Q.useMemo(()=>F(),[]),re=tn(e=>e.hasCachedSessionIndex),U=tn(e=>e.hasHydratedSessionIndex),[ie,ae]=Q.useState(()=>S()),[W,oe]=Q.useState(()=>{let e=E();return e===null?null:B({isDesktopShell:!0,bootOutcome:e})}),se=Q.useRef(!1),ce=Q.useMemo(()=>lC(),[]),G=!ce||x,le=Q.useMemo(()=>uC(),[]);Q.useEffect(()=>(Me(p),()=>{Me(!1)}),[p]),Q.useEffect(()=>{Ze(H)},[H]),Q.useEffect(()=>{b(e.runtime.isVSCode)},[e.runtime.isVSCode]),Q.useEffect(()=>{let e=Wr(e=>{d(e)&&(te&&P(e=>({epoch:e.epoch+1,startedAt:Date.now()})),wc(e),M(e=>e+1),D(!1),k(e=>e+1))}),t=s(t=>e.schedule(t));return()=>{t(),e.cancel()}},[te]);let ue=Cn(e=>{let t=f();return Object.values(e.runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t).map(e=>`${e.originalSessionID}:${e.phase}:${e.lastForwardedMessageID??``}:${e.expectedAssistantParentID??``}`).sort().join(`|`)});Q.useEffect(()=>{if(ce)return;let e=!1;return Ut().then(()=>{if(e)return;let t=f(),n=Object.values(Cn.getState().runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t);for(let e of n)hn(e.originalSessionID)}),()=>{e=!0}},[ue,ce,A]),Q.useEffect(()=>(document.documentElement.classList.toggle(`wide-chat-layout`,V),()=>{document.documentElement.classList.remove(`wide-chat-layout`)}),[V]),Q.useEffect(()=>(h(e),()=>h(null)),[e]),Q.useEffect(()=>{if(ce)return;let t=!1;return Ut().then(()=>{t||g(e.github,{force:!0})}),()=>{t=!0}},[e.github,ce,g]),Bi();let de=ie===`valid`,fe=W?.screen===`main`;Q.useEffect(()=>{if(!G||!C({isDesktopShell:te,isInitialized:te&&fe?re||n&&U:n,bootOutcomeKnown:de,bootViewIsMain:fe}))return;let e,t=setTimeout(()=>{let t=document.getElementById(`initial-loading`);t&&(t.classList.add(`fade-out`),e=setTimeout(()=>{t.remove()},300))},150);return()=>{clearTimeout(t),e&&clearTimeout(e)}},[G,te,n,de,fe,re,U]),Q.useEffect(()=>{if(!te||ie!==`malformed`)return;let e=document.getElementById(`initial-loading`);e&&(e.textContent=`Desktop startup failed — please restart the app.`)},[te,ie]),Q.useEffect(()=>{if(!G||te)return;let e,t=setTimeout(()=>{let t=document.getElementById(`initial-loading`);t&&!n&&(t.classList.add(`fade-out`),e=setTimeout(()=>{t.remove()},300))},5e3);return()=>{clearTimeout(t),e&&clearTimeout(e)}},[G,te,n]),Q.useEffect(()=>{if(!G||_)return;let e=!1;return Ut().then(()=>{if(!e)return t()}),()=>{e=!0}},[G,t,_]),Q.useEffect(()=>{if(!G||_||n)return;let e=!0,t,r=0,i=1e3,a=async()=>{if(!e)return;if(r>=10){D(!0);return}let n=Qn.getState();if(n.isInitialized){D(!1);return}if(r+=1,await Ut(),!e)return;await n.initializeApp();let o=Qn.getState();if(!e)return;if(o.isInitialized){D(!1);return}if(r>=10){D(!0);return}let s=Math.min(i*2**(r-1),16e3);t=setTimeout(a,s)};return t=setTimeout(a,i),()=>{e=!1,t&&clearTimeout(t)}},[G,O,n,_]),Q.useEffect(()=>{G&&n&&D(!1)},[G,n]),Q.useEffect(()=>{if(!G||!T)return;let e=document.getElementById(`initial-loading`);if(e){e.classList.add(`fade-out`);let t=setTimeout(()=>{e.remove()},300);return()=>clearTimeout(t)}},[G,T]),ci({enabled:G&&!_,source:`startupRecovery`}),Q.useEffect(()=>{u||_||r&&Le.setDirectory(c)},[c,u,r,_]),Q.useEffect(()=>{if(!ce||typeof window>`u`)return;let e=e=>{let t=e?.visible===!0;w(t)},t=t=>{if(t.origin!==window.location.origin)return;let n=t.data;n?.type===`yuri:embedded-visibility`&&e(n.payload)},n=window;return n.__yuriSetEmbeddedVisibility=e,window.addEventListener(`message`,t),window.parent&&window.parent!==window&&window.parent.postMessage({type:fo},window.location.origin),()=>{window.removeEventListener(`message`,t),n.__yuriSetEmbeddedVisibility===e&&delete n.__yuriSetEmbeddedVisibility}},[ce]),Q.useEffect(()=>{!ce?.directory||_||c!==ce.directory&&l(ce.directory,{showOverlay:!1})},[c,ce,_,l]),Q.useEffect(()=>{if(!ce||typeof window>`u`)return;let e=e=>{e.storageArea===window.localStorage&&e.key===`ui-store`&&q.persist.rehydrate()};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}},[ce]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;YS(t??{})},t=e=>{let t=e.detail?.assistantID;typeof t==`string`&&t.trim()&&or(t.trim())};return window.addEventListener(`yuri:open-session`,e),window.addEventListener(`yuri:open-assistant`,t),()=>{window.removeEventListener(`yuri:open-session`,e),window.removeEventListener(`yuri:open-assistant`,t)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=je.getState().currentDirectory,{activeProjectId:t,projects:n}=jn.getState(),r=n.find(e=>e.id===t)??null;j(`desktop_open_draft_mini_chat_window`,{directory:e||r?.path||``,projectId:r?.id??null})};return window.addEventListener(`yuri:open-mini-chat`,e),()=>window.removeEventListener(`yuri:open-mini-chat`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=Sn.getState().currentSessionId;e&&Gn(e)};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail,n=typeof t?.directory==`string`&&t.directory.trim().length>0?t.directory.trim():null,r=typeof t?.projectId==`string`&&t.projectId.trim().length>0?t.projectId.trim():null,i=typeof t?.initialPrompt==`string`&&t.initialPrompt.trim().length>0?t.initialPrompt.trim():void 0;q.getState().setActiveMainTab(`chat`),q.getState().setSessionSwitcherOpen(!1),Sn.getState().openNewSessionDraft({selectedProjectId:r,directoryOverride:n,preserveDirectoryOverride:!!n,ensureProjectForDirectory:!!n,initialPrompt:i})};return window.addEventListener(`yuri:open-draft-session`,e),()=>window.removeEventListener(`yuri:open-draft-session`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail,n=typeof t?.projectPath==`string`?t.projectPath.trim():``;if(!n)return;let r=jn.getState(),i=r.projects.find(e=>e.path===n);i?r.setActiveProject(i.id):r.addProject(n)};return window.addEventListener(`yuri:open-project`,e),()=>window.removeEventListener(`yuri:open-project`,e)},[]),Q.useEffect(()=>{typeof window>`u`||!G||!n||u||se.current||(se.current=!0,window.__yuriAppReady=!0,window.dispatchEvent(new Event(`yuri:app-ready`)))},[G,n,u]),Rr({enabled:G}),WS({enabled:G}),JS(),ai(),Qs(),xS(vt(()=>{m(e=>!e)})),Q.useEffect(()=>{ee()&&pt().then(async e=>{e&&await ne(e)}).catch(console.warn)},[]),Q.useEffect(()=>{if(!n||!ee()||z.current)return;z.current=!0;let e=!1,t=null,r=null;ms.getState().subscribeDesktopUpdateEvents().then(t=>{if(e){t();return}r=t});let i=()=>{let e=ms.getState();e.checking||e.checkForUpdates()},a=n=>{t=window.setTimeout(()=>{e||(document.visibilityState===`visible`&&i(),a(iC))},n)},o=()=>{if(e||document.visibilityState!==`visible`)return;let t=ms.getState().lastChecked;t!=null&&Date.now()-t<aC||i()};return a(0),window.addEventListener(`focus`,o),()=>{e=!0,t!==null&&window.clearTimeout(t),window.removeEventListener(`focus`,o),r&&r()}},[n]),BS(),Q.useEffect(()=>{if(ce)return;let e=e=>{Ct(e)&&e.shiftKey&&!e.altKey&&(e.code===`KeyD`||e.key.toLowerCase()===`d`)&&(e.preventDefault(),m(e=>!e))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ce]),Q.useEffect(()=>{ce||i&&setTimeout(()=>a(),5e3)},[a,ce,i]),Q.useEffect(()=>{if(!te||ie!==`not-injected`)return;let e=!1,t=0,n=()=>{if(e)return;t++;let r=S();if(r!==`not-injected`){if(e=!0,ae(r),r===`valid`){let e=E();e&&oe(B({isDesktopShell:!0,bootOutcome:e}))}return}let i=Math.min(200*1.1**t,2e3);if(t>=50){let e=document.getElementById(`initial-loading`);e&&!e.textContent?.includes(`taking longer`)&&(e.textContent=`Desktop startup is taking longer than expected...`)}window.setTimeout(n,i)};return window.setTimeout(n,200),()=>{e=!0}},[te,ie]);let pe=vt(async()=>{if(y({isDesktopShell:F(),isDesktopLocalOriginActive:v()})){await L();return}window.location.reload()}),me=vt(async()=>{if(!I){D(!1),R(!0);try{await Ut(),await Qn.getState().initializeApp()}finally{R(!1)}Qn.getState().isInitialized||k(e=>e+1)}}),he=e=>{if(e.screen===`recovery`)return e.variant};if(te&&W&&W.screen!==`main`){if(W.screen===`chooser`)return(0,$.jsx)(ha,{children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-transparent`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-full`}),children:(0,$.jsx)(rC,{mode:`first-launch`,onCliAvailable:pe,onChooseRemote:()=>{}})})})});let e=he(W),t=W.screen===`recovery`&&`url`in W?W.url:void 0;return(0,$.jsx)(ha,{children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-transparent`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-full`}),children:(0,$.jsx)(rC,{mode:`recovery`,recoveryVariant:e,recoveryHostUrl:t,recoveryHostLabel:void 0,onCliAvailable:pe})})})})}if(ce)return cn(),(0,$.jsx)(ha,{children:(0,$.jsx)(Zt,{sdk:Le.getSdkClient(),directory:c||``,bootstrapDirectory:o,children:(0,$.jsx)(Wi,{apis:e,children:(0,$.jsx)(fa,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-background`,children:(0,$.jsx)(dC,{embeddedSessionChat:ce,isVSCodeRuntime:_,embeddedBackgroundWorkEnabled:G})})})})},A)});if(le)return(0,$.jsx)(ha,{children:(0,$.jsx)($S,{})});if(T&&!n&&!_&&!ce)return(0,$.jsx)(ha,{children:(0,$.jsx)(sC,{onRetry:()=>{me()},isRetrying:I})});let ge=!n&&!te;return(0,$.jsx)(ha,{children:(0,$.jsx)(Zt,{sdk:Le.getSdkClient(),directory:c||``,bootstrapDirectory:o,children:(0,$.jsx)(Wi,{apis:e,children:(0,$.jsx)(Qu,{children:(0,$.jsx)(fa,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsxs)(`div`,{className:te?`h-full text-foreground bg-transparent`:`h-full text-foreground bg-background`,children:[(0,$.jsx)(Ci,{embeddedBackgroundWorkEnabled:G}),(0,$.jsx)(Rc,{}),(0,$.jsx)(dc,{}),(0,$.jsx)(Qx,{}),te&&(0,$.jsx)(nC,{transition:N,ready:n&&r}),(0,$.jsx)(eC,{}),(0,$.jsx)(zr,{}),!ge&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ic,{}),(0,$.jsx)(Cc,{}),(0,$.jsx)(oC,{}),p&&(0,$.jsx)(nS,{onClose:()=>m(!1)})]})]})})})})},A)})}function pC(e){return e.isAboutDialogOpen}function mC(e){return e.setAboutDialogOpen}function hC(e){return e.currentDirectory}function gC(e){return e.currentSessionId}function _C(e){return e.setCurrentSession}if(typeof window<`u`&&!window.__YURI_REFRESH_DEBUG_INSTALLED__){window.__YURI_REFRESH_DEBUG_INSTALLED__=!0;let e=performance.getEntriesByType(`navigation`)[0];console.warn(`[refresh-debug] renderer-entry`,{navigationType:e?.type??`unknown`,protocol:window.location.protocol}),window.addEventListener(`beforeunload`,()=>{console.warn(`[refresh-debug] beforeunload`,{visibilityState:document.visibilityState})}),window.addEventListener(`pagehide`,e=>{console.warn(`[refresh-debug] pagehide`,{persisted:e.persisted})})}var vC=typeof window<`u`&&window.__YURI_RUNTIME_APIS__||(()=>{throw Error(`Runtime APIs not provided for legacy UI entrypoint.`)})();Pt(),F()&&nr(),Jr({runtimeKey:f(),initializeAppearance:re,syncSettings:H,applyDirectory:ii,startWatchers:()=>{Oi(),ei(),Vr()},onError:(e,t)=>{console.error(e===`appearance`?`[main] appearance init failed:`:`[main] settings init failed:`,t)}});var yC=document.getElementById(`root`);if(!yC)throw Error(`Root element not found`);(0,fl.createRoot)(yC).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Hr,{children:(0,$.jsx)(Dt,{children:(0,$.jsx)(Ir,{children:(0,$.jsx)(Ei,{children:(0,$.jsx)(Xr,{children:(0,$.jsx)(Qr,{children:(0,$.jsx)(fC,{apis:vC})})})})})})})}));