@openchambery/web 1.19.13 → 1.19.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-mbvX7YlW.js → AgentAvatar-m1jNq4bX.js} +1 -1
- package/dist/assets/AssistantView-Dncbu_Z2.js +2 -0
- package/dist/assets/{DiagramView-BdI4PT2H.js → DiagramView-CovEl1BY.js} +1 -1
- package/dist/assets/{FadeInOnReveal-moBbL8Ll.js → FadeInOnReveal-UGwClbL_.js} +1 -1
- package/dist/assets/Icon-D1BcR8Tz.js +1 -0
- package/dist/assets/{MarkdownRenderer-CLQ4Z8Z0.js → MarkdownRenderer-CZqok-Cf.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-2ewbRZE2.js → MarkdownRendererImpl-CCfHY-86.js} +3 -3
- package/dist/assets/{MarkstreamRendererImpl-DXewO7S_.js → MarkstreamRendererImpl-y6QgIUZA.js} +2 -2
- package/dist/assets/MobileDetailNavigation-Ca-d5eZ9.js +1 -0
- package/dist/assets/MobileShareBridge-B4S7BaUj.js +4 -0
- package/dist/assets/MobileSurface-xL5Jby4U.js +2 -0
- package/dist/assets/{MultiRunWindow-C8ukIdLA.js → MultiRunWindow-BeHa-CG6.js} +1 -1
- package/dist/assets/{OnboardingScreen-j0iCyH7f.js → OnboardingScreen-bIWeMLVx.js} +1 -1
- package/dist/assets/{OverlayScrollbar-CDC5B3RH.js → OverlayScrollbar-Bahg_P3r.js} +1 -1
- package/dist/assets/SettingsView-Dn7odtQz.js +25 -0
- package/dist/assets/{SettingsWindow-CSePZ_V8.js → SettingsWindow-C0tWPS5f.js} +1 -1
- package/dist/assets/{TerminalView-BmSIrZ81.js → TerminalView-BnJgC7Qo.js} +1 -1
- package/dist/assets/{ToolOutputDialog-2BYaWLo1.js → ToolOutputDialog-D9S-X8hM.js} +1 -1
- package/dist/assets/{appThemeRegistry-Dk4gBaOu.js → appThemeRegistry-DBrvaJnq.js} +1 -1
- package/dist/assets/{button-xx1UOBA5.js → button-9R-WgVMl.js} +1 -1
- package/dist/assets/{clipboard-CUasgPiF.js → clipboard-GUUNlWIv.js} +1 -1
- package/dist/assets/{collapsible-CACHBRYZ.js → collapsible-Bbz9KiJf.js} +1 -1
- package/dist/assets/{context-menu-CYbm4wBZ.js → context-menu-CSyOhRz8.js} +1 -1
- package/dist/assets/{desktopHosts-DILvrAok.js → desktopHosts-B052a4UK.js} +1 -1
- package/dist/assets/{desktopRelayRestore-t8asCr3m.js → desktopRelayRestore-OjKNXr10.js} +1 -1
- package/dist/assets/{diagram-u0BC9uuY.js → diagram-NdsZih8P.js} +1 -1
- package/dist/assets/{dialog-BwQ3rY_x.js → dialog-DhMGbF_B.js} +1 -1
- package/dist/assets/{es-CRjOwvYM.js → es-BQb6I8gl.js} +2 -2
- package/dist/assets/fileMentionTouchSelection-Dc004xOh.js +4 -0
- package/dist/assets/{fileQueries-Bgly-E8f.js → fileQueries-B_s_B-fH.js} +1 -1
- package/dist/assets/{fr-D9taEN9L.js → fr-BjGouC_l.js} +2 -2
- package/dist/assets/{gitApi-DtPf-h-O.js → gitApi-Cm3JLQqh.js} +3 -3
- package/dist/assets/{input-CI730njs.js → input-Cd_1HyQv.js} +1 -1
- package/dist/assets/insertionBoundaries-CTWYFsbH.js +1 -0
- package/dist/assets/{ja-CYQ5aoWp.js → ja-Cw9zliYY.js} +2 -2
- package/dist/assets/{ko-BwASV0Q0.js → ko-Dyz0Dk9b.js} +2 -2
- package/dist/assets/main-CSqu3MB4.js +169 -0
- package/dist/assets/{main-Ci3JmtpW.js → main-DwMprEyr.js} +2 -2
- package/dist/assets/{markdownHeightCache-DEjGKLv8.js → markdownHeightCache-BL8CUQ0M.js} +1 -1
- package/dist/assets/miniChat-C8bzY_Ye.js +2 -0
- package/dist/assets/mobile-Oy-SRKkr.js +2 -0
- package/dist/assets/{multirun-CmaTeZON.js → multirun-ClcuaiKU.js} +1 -1
- package/dist/assets/{persistence-YbQKzHUQ.js → persistence-DwRBC4zl.js} +2 -2
- package/dist/assets/{pl-DUI1vPil.js → pl-C7EY-dTH.js} +1 -1
- package/dist/assets/platform-DQ5_LNKO.js +2 -0
- package/dist/assets/{projectMeta-cw9nrwpr.js → projectMeta-F93wE2Ye.js} +2 -2
- package/dist/assets/{pt-BR-CZQFJllP.js → pt-BR-B1uHpjFW.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-rOOhMVlQ.js +2 -0
- package/dist/assets/renderMobileApp-BP_hGwHP.js +28 -0
- package/dist/assets/{runtimeConfig-DI8l0VyZ.js → runtimeConfig-iJ2mTBVN.js} +1 -1
- package/dist/assets/runtimeEndpointReset-ISnhAS3q.js +147 -0
- package/dist/assets/sessionChangeSummary-BAzU2J1H.js +2 -0
- package/dist/assets/sessionLookup-DQQ9-DuP.js +1 -0
- package/dist/assets/{sortable-tabs-strip-Dom6Sthu.js → sortable-tabs-strip-dYW6SH62.js} +1 -1
- package/dist/assets/src-DYeppLfP.css +2 -0
- package/dist/assets/{store-CSnH_QXM.js → store-ClnJdJSj.js} +3 -3
- package/dist/assets/{terminalApi-noa4Cdbh.js → terminalApi-CfgOfnZk.js} +1 -1
- package/dist/assets/{textarea-BfNtUdJE.js → textarea-B9CmN13Z.js} +1 -1
- package/dist/assets/{tooltip-DPxumadF.js → tooltip-DSjr26A_.js} +1 -1
- package/dist/assets/{uk-C1FYZlmA.js → uk-DgG8v2md.js} +2 -2
- package/dist/assets/{url-CVhsI9kR.js → url-CMQwHq4k.js} +1 -1
- package/dist/assets/{useAppFontEffects-BDFUND4v.js → useAppFontEffects--IcU7jyv.js} +43 -44
- package/dist/assets/useDesktopWindowControlsLayout-BqJ5R_T2.js +1 -0
- package/dist/assets/{useEffectiveDirectory-e9HjIqGz.js → useEffectiveDirectory-ChWXV8xM.js} +1 -1
- package/dist/assets/{useFontPreferences-CB-cGo3I.js → useFontPreferences-DCaY8NbU.js} +1 -1
- package/dist/assets/useMobileNavigationStore-DQkgxuzg.js +413 -0
- package/dist/assets/useSessionAutoCleanup-DWWAvQQ0.js +2 -0
- package/dist/assets/{useWorkerHighlightedLines-DTGE0CDs.js → useWorkerHighlightedLines-D2oQszsk.js} +1 -1
- package/dist/assets/{utils-BHTVlVov.js → utils-2ZK8yboQ.js} +1 -1
- package/dist/assets/{vendor-reactuses-core-DDoDDyM9.js → vendor-reactuses-core-BnW6GxJt.js} +1 -1
- package/dist/assets/{zh-CN-C96qP1ip.js → zh-CN-C6OFKjeT.js} +2 -2
- package/dist/assets/{zh-TW-BsRk1Rbb.js → zh-TW-BVP99aMr.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/mini-chat.html +8 -8
- package/dist/mobile.html +8 -8
- package/package.json +1 -1
- package/server/index.js +1 -0
- package/server/lib/assistants/DOCUMENTATION.md +93 -16
- package/server/lib/assistants/assign.js +117 -12
- package/server/lib/assistants/assign.test.js +79 -0
- package/server/lib/assistants/bubbles.js +1 -1
- package/server/lib/assistants/contact-store.js +496 -11
- package/server/lib/assistants/contact-store.test.js +323 -7
- package/server/lib/assistants/contact-tools.js +303 -52
- package/server/lib/assistants/contact-tools.test.js +239 -7
- package/server/lib/assistants/contracts.js +31 -0
- package/server/lib/assistants/harness.js +178 -50
- package/server/lib/assistants/harness.test.js +428 -3
- package/server/lib/assistants/routes.js +3 -0
- package/server/lib/assistants/service.js +586 -43
- package/server/lib/assistants/service.test.js +696 -7
- package/server/lib/llm/DOCUMENTATION.md +2 -0
- package/server/lib/llm/completions.js +4 -0
- package/server/lib/llm/completions.test.js +3 -0
- package/server/lib/llm/generate.js +12 -5
- package/server/lib/llm/generate.test.js +40 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/dist/assets/AssistantView-CKmIS1cS.js +0 -2
- package/dist/assets/Icon-CkzzhaLr.js +0 -1
- package/dist/assets/MobileDetailNavigation-BGaAyuBH.js +0 -1
- package/dist/assets/MobileShareBridge-BAZoyeIP.js +0 -4
- package/dist/assets/MobileSurface-BVb3xNWt.js +0 -2
- package/dist/assets/SettingsView-CkQ61pbr.js +0 -25
- package/dist/assets/insertionBoundaries-BMhzPFft.js +0 -4
- package/dist/assets/main-BjeOhdcG.js +0 -169
- package/dist/assets/miniChat-BYrjYEXJ.js +0 -2
- package/dist/assets/mobile-BVMNnPK2.js +0 -2
- package/dist/assets/platform-DzsGqlGW.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-COwia8Cs.js +0 -2
- package/dist/assets/renderMobileApp-CXwwpY1t.js +0 -28
- package/dist/assets/runtimeEndpointReset-BkAQXmXJ.js +0 -147
- package/dist/assets/sessionChangeSummary-DQDZ5HW-.js +0 -1
- package/dist/assets/sessionLookup-Imc995rW.js +0 -1
- package/dist/assets/src-AA-5nXsF.css +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-C5hZD1co.js +0 -1
- package/dist/assets/useMobileNavigationStore-CYbDxRTM.js +0 -413
- package/dist/assets/useSessionAutoCleanup-BGy9_AhN.js +0 -2
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-2BYaWLo1.js","assets/rolldown-runtime-C0FnF6B9.js","assets/runtime-fetch-zIalUnbb.js","assets/runtime-auth-D66yq6ie.js","assets/runtime-switch-LvWDU-SL.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-CxOoCv7B.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/vendor-hast-util-to-html-B0p1k5Xa.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-DpDied8H.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-CUasgPiF.js","assets/persistence-YbQKzHUQ.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/store-CSnH_QXM.js","assets/dialog-BwQ3rY_x.js","assets/utils-BHTVlVov.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-CkzzhaLr.js","assets/button-xx1UOBA5.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DOfGg-A7.js","assets/appThemeRegistry-Dk4gBaOu.js","assets/platform-DzsGqlGW.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-CYbDxRTM.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-CLPCNoj_.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/MarkdownRenderer-CLQ4Z8Z0.js","assets/markdownHeightCache-DEjGKLv8.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-CptoICmq.js","assets/useEffectiveDirectory-e9HjIqGz.js","assets/imageSource-BlAJJUEI.js","assets/relay-image-stream-DM7atqJs.js","assets/useWorkerHighlightedLines-DTGE0CDs.js","assets/tooltip-DPxumadF.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js","assets/TerminalView-BmSIrZ81.js","assets/terminalApi-noa4Cdbh.js","assets/vendor-ghostty-web-HohRXr3g.js","assets/OverlayScrollbar-CDC5B3RH.js","assets/useRuntimeAPIs-DSLXJybW.js","assets/sortable-tabs-strip-Dom6Sthu.js","assets/vendor-dnd-kit-core-CvWxUPdb.js","assets/vendor-dnd-kit-accessibility-BY5LhhUB.js","assets/vendor-dnd-kit-sortable-hHdP9lLb.js","assets/useFontPreferences-CB-cGo3I.js","assets/projectActions-CWvNGKfA.js","assets/DiagramView-BdI4PT2H.js","assets/fileQueries-Bgly-E8f.js","assets/diagram-u0BC9uuY.js","assets/vendor-react-drawio-ECtEwvbc.js","assets/SettingsView-CkQ61pbr.js","assets/desktopHosts-DILvrAok.js","assets/desktopRelayRestore-t8asCr3m.js","assets/vendor-codemirror-autocomplete-DHomsvW7.js","assets/MobileShareBridge-BAZoyeIP.js","assets/MobileDetailNavigation-BGaAyuBH.js","assets/AgentAvatar-mbvX7YlW.js","assets/projectMeta-cw9nrwpr.js","assets/gitApi-DtPf-h-O.js","assets/input-CI730njs.js","assets/textarea-BfNtUdJE.js","assets/useSessionAutoCleanup-BGy9_AhN.js","assets/vendor-codemirror-lang-angular-DShkBD6m.js","assets/vendor-codemirror-lang-json-CYJRHck9.js","assets/vendor-codemirror-lang-markdown-WORgx6ZD.js","assets/vendor-codemirror-lang-python-Du6XQ8Zw.js","assets/vendor-codemirror-legacy-modes-DuRAjNvB.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/dropdown-menu.styles-Bzo6L3FH.js","assets/vendor-codemirror-language-data-BfYFhIH1.js","assets/url-CVhsI9kR.js","assets/MobileSurface-BVb3xNWt.js","assets/types-BuiqMmh_.js","assets/collapsible-CACHBRYZ.js","assets/vendor-codemirror-commands-C9DCaJ0C.js","assets/vendor-codemirror-search-D2SOgzph.js","assets/vendor-replit-codemirror-vim-CEibx3EP.js","assets/context-menu-CYbm4wBZ.js","assets/vendor-yaml-DIcAK3EC.js","assets/vendor-qrcode-DAuVxiQR.js","assets/vendor-dijkstrajs-DztKuCwY.js","assets/SettingsWindow-CSePZ_V8.js","assets/MultiRunWindow-C8ukIdLA.js","assets/multirun-CmaTeZON.js","assets/insertionBoundaries-BMhzPFft.js","assets/AssistantView-CKmIS1cS.js","assets/sessionChangeSummary-DQDZ5HW-.js","assets/assistant-attachment-cache-C0aRnFkj.js","assets/sessionLookup-Imc995rW.js","assets/OnboardingScreen-j0iCyH7f.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,p as n,t as r,v as i,w as a}from"./runtime-auth-D66yq6ie.js";import{c as o,f as s,o as c,r as l,s as u,t as d}from"./runtime-switch-LvWDU-SL.js";import{n as f}from"./runtime-fetch-zIalUnbb.js";import{$ as p,$t as m,At as h,Cn as g,D as _,Dn as v,En as y,Ft as b,Gt as x,Qt as S,Rt as C,Sn as w,Tn as T,Xt as E,Yt as D,Zt as O,an as k,en as A,fn as j,in as M,k as N,kt as P,n as F,pn as I,qt as ee,r as L,rn as R,st as z,t as B,un as V,vn as H,wn as te,xn as U}from"./persistence-YbQKzHUQ.js";import{f as ne,h as W,l as re,o as G,r as ie,v as ae}from"./desktopHosts-DILvrAok.js";import{a as oe,i as se,t as ce}from"./vendor-zustand-B4dlGEM2.js";import{E as le,F as ue,I as de,N as fe,O as pe,P as me,T as he,a as ge,i as _e,nt as ve,rt as ye,tt as be}from"./vendor-base-ui-CnHfUmDN.js";import{Ct as xe,Dt as Se,Et as Ce,It as we,Mt as Te,Nt as Ee,Pt as De,Tt as Oe,wt as ke}from"./platform-DzsGqlGW.js";import{b as Ae,n as je,t as K,x as Me,y as Ne}from"./useUIStore-CxOoCv7B.js";import{o as Pe}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as q,t as Fe}from"./vendor-react-DLPElpoQ.js";import{n as Ie}from"./vendor-tanstack-react-query-D7pys_c9.js";import{a as Le,n as Re}from"./terminalApi-noa4Cdbh.js";/* empty css */import{W as ze,ct as Be}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as Ve}from"./vendor-pierre-diffs-DX7XTPG3.js";import{n as He,t as Ue,u as We}from"./vendor-reactuses-core-DDoDDyM9.js";import{a as Ge,i as Ke,n as qe,o as Je,r as Ye,t as Xe}from"./clipboard-CUasgPiF.js";import{n as Ze}from"./store-CSnH_QXM.js";import{An as Qe,Br as $e,Bt as et,Do as tt,Eo as nt,Gn as rt,Gr as it,Gt as at,Jt as ot,Ma as st,Nt as ct,Oo as lt,Pa as ut,Pn as dt,Pt as ft,Ri as pt,Rt as mt,S as ht,To as gt,Tr as _t,Ua as vt,Ui as yt,Un as bt,Ut as xt,Wt as St,Xr as Ct,Yi as wt,Yn as Tt,Zi as Et,_ as Dt,_a as Ot,_n as kt,an as At,ar as jt,ba as Mt,bn as Nt,c as Pt,cn as Ft,cr as It,d as Lt,dr as Rt,ea as zt,ei as Bt,en as Vt,f as Ht,fa as Ut,fr as Wt,ft as Gt,hn as Kt,ho as qt,ir as Jt,jn as Yt,jr as Xt,kn as Zt,l as Qt,la as $t,ln as en,m as tn,mn as nn,mr as J,na as rn,nn as an,nr as on,oa as sn,oi as cn,or as ln,pa as un,pn as dn,pr as fn,rn as pn,sn as mn,sr as hn,ta as gn,ti as _n,tn as vn,tr as yn,u as bn,ua as xn,ur as Sn,v as Cn,wn,wo as Tn,x as En,y as Dn,ya as On,yn as kn,yr as An,zi as jn,zr as Mn,zt as Nn}from"./useMobileNavigationStore-CYbDxRTM.js";import{p as Pn}from"./MobileDetailNavigation-BGaAyuBH.js";import{n as Fn}from"./useAssistantUIStore-CLPCNoj_.js";import{a as In,i as Ln,n as Rn,o as zn,r as Bn,t as Vn}from"./dialog-BwQ3rY_x.js";import{a as Hn,c as Un,i as Wn,n as Gn,o as Kn,r as qn,s as Jn,t as Y}from"./utils-BHTVlVov.js";import{n as X,t as Yn}from"./Icon-CkzzhaLr.js";import{t as Z}from"./button-xx1UOBA5.js";import{A as Xn,C as Zn,D as Qn,O as $n,P as er,T as tr,a as nr,f as rr,h as ir,i as ar,j as or,k as sr,m as cr,o as lr,p as ur,r as dr,t as fr,w as pr,y as mr}from"./gitApi-DtPf-h-O.js";import{$ as hr,A as gr,At as _r,B as vr,C as yr,Ct as br,D as xr,Dt as Sr,E as Cr,Et as wr,F as Tr,Ft as Er,G as Dr,H as Or,Ht as kr,I as Ar,It as jr,J as Mr,K as Nr,L as Pr,Lt as Fr,M as Ir,Mt as Lr,N as Rr,Nt as zr,O as Br,Ot as Vr,Pt as Hr,Q as Ur,Rt as Wr,S as Gr,St as Kr,Tt as qr,U as Jr,V as Yr,Vt as Xr,W as Zr,X as Qr,Z as $r,_ as ei,_t as ti,at as ni,b as ri,c as ii,d as ai,et as oi,f as si,ft as ci,g as li,gt as ui,h as di,ht as fi,i as pi,it as mi,j as hi,k as gi,kt as _i,l as vi,m as yi,mt as bi,n as xi,nt as Si,ot as Ci,p as wi,pt as Ti,q as Ei,rt as Di,t as Oi,tt as ki,u as Ai,ut as ji,v as Mi,w as Ni,wt as Pi,x as Fi,xt as Ii,y as Li,yt as Ri,z as zi,zt as Bi}from"./useAppFontEffects-BDFUND4v.js";import{O as Vi,T as Hi,_ as Ui,a as Wi,b as Gi,f as Ki,h as qi,i as Ji,l as Yi,m as Xi,n as Zi,p as Qi,s as $i,x as ea}from"./projectMeta-cw9nrwpr.js";import{t as ta}from"./input-CI730njs.js";import{i as na,n as ra,r as ia,t as aa}from"./tooltip-DPxumadF.js";import{B as oa,Et as sa,F as ca,G as la,I as ua,It as da,J as fa,L as pa,Lt as ma,P as ha,U as ga,V as _a,X as va,Y as ya,a as ba,b as xa,c as Sa,et as Ca,h as wa,ht as Ta,i as Ea,m as Da,q as Oa,s as ka,tt as Aa,u as ja,w as Ma,y as Na}from"./useSessionAutoCleanup-BGy9_AhN.js";import{n as Pa}from"./useThemeSystem-DMzWVJaW.js";import{i as Fa,o as Ia,t as La}from"./OverlayScrollbar-CDC5B3RH.js";import{s as Ra}from"./markdownTheme-DOfGg-A7.js";import{n as za,r as Ba}from"./useRuntimeAPIs-DSLXJybW.js";import{N as Va,P as Ha,_ as Ua,b as Wa,d as Ga,g as Ka,h as qa,p as Ja,v as Ya,x as Xa,y as Za}from"./insertionBoundaries-BMhzPFft.js";import{n as Qa,t as $a}from"./appThemeRegistry-Dk4gBaOu.js";import{a as eo,n as to,o as no}from"./MarkdownRenderer-CLQ4Z8Z0.js";import{i as ro,n as io,r as ao,t as oo}from"./dropdown-menu.styles-Bzo6L3FH.js";import{n as so,r as co}from"./textarea-BfNtUdJE.js";import{_ as lo,g as uo,i as fo,l as po,n as mo,s as ho,t as go,v as _o,y as vo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{a as yo,n as bo,o as xo,s as So,t as Co}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as wo}from"./url-CVhsI9kR.js";import{c as To,d as Eo,f as Do,l as Oo,s as ko,u as Ao}from"./markdown-worker-CptoICmq.js";import{n as jo,t as Mo}from"./useEffectiveDirectory-e9HjIqGz.js";import{o as No}from"./FadeInOnReveal-moBbL8Ll.js";import{p as Po,u as Fo}from"./imageSource-BlAJJUEI.js";import{g as Io}from"./useWorkerHighlightedLines-DTGE0CDs.js";import{r as Lo,s as Ro,t as zo}from"./sessionChangeSummary-DQDZ5HW-.js";import{t as Bo}from"./sortable-tabs-strip-Dom6Sthu.js";import{t as Vo}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as Ho,r as Uo,t as Wo}from"./vendor-framer-motion-DFy_BSVd.js";import{$ as Go,A as Ko,B as qo,C as Jo,D as Yo,M as Xo,N as Zo,O as Qo,Q as $o,R as es,T as ts,W as ns,_ as rs,b as is,d as as,f as os,h as ss,j as cs,k as ls,m as us,p as ds,s as fs,v as ps,w as ms,x as hs,y as gs,z as _s}from"./MobileSurface-BVb3xNWt.js";import{i as vs,n as ys,r as bs,t as xs}from"./useDesktopWindowControlsLayout-C5hZD1co.js";import{n as Ss}from"./useFontPreferences-CB-cGo3I.js";import{$ as Cs,A as ws,B as Ts,F as Es,G as Ds,I as Os,J as ks,K as As,M as js,N as Ms,P as Ns,Q as Ps,R as Fs,V as Is,W as Ls,X as Rs,Z as zs,_ as Bs,a as Vs,at as Hs,c as Us,d as Ws,et as Gs,f as Ks,g as qs,h as Js,i as Ys,it as Xs,j as Zs,k as Qs,l as $s,m as ec,n as tc,nt as nc,o as rc,ot as ic,p as ac,q as oc,r as sc,rt as cc,s as lc,tt as uc,u as dc,v as fc,y as pc,z as mc}from"./runtimeEndpointReset-BkAQXmXJ.js";import{a as hc,i as gc,n as _c,r as vc,t as yc}from"./context-menu-CYbm4wBZ.js";import{n as bc,r as xc,t as Sc}from"./collapsible-CACHBRYZ.js";import{a as Cc,o as wc,r as Tc,s as Ec,t as Dc}from"./projectActions-CWvNGKfA.js";import{t as Oc}from"./diagram-u0BC9uuY.js";import{a as kc,i as Ac,n as jc,o as Mc,r as Nc,t as Pc}from"./multirun-CmaTeZON.js";import{t as Fc}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as Ic,t as Lc}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(ye(),1),Rc=Fe(),zc=q(),$=ve();function Bc(e){let t=(0,zc.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 Vc=[{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`}],Hc=`finder`,Uc=new Set([`finder`,`terminal`]),Wc=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,Gc=e=>{if(!e)return null;let t=Vc.find(t=>t.id===e)??null;return t?Wc(t):null},Kc=()=>Vc.filter(e=>Uc.has(e.id)).map(e=>({...Wc(e)})),qc=()=>{if(typeof window>`u`)return Hc;let e=window.localStorage.getItem(`openInAppId`);return e&&Gc(e)?e:Hc},Jc=!1,Yc=!1,Xc=!1,Zc=0,Qc=null,$c=()=>{Qc&&=(clearTimeout(Qc),null)},el=oe()((e,t)=>({selectedAppId:qc(),availableApps:Kc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Jc||typeof window>`u`)return;Jc=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:Kc(),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:Vc.filter(e=>r.has(e.appName)||Uc.has(e.id)).map(e=>({...Wc(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!E()||!D()||Yc||t().hasLoadedApps&&!i)return;let a=Vc.map(e=>e.appName);$c(),i&&e({hasLoadedApps:!1}),Yc=!0,Xc=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await C(a,i),l=o&&!s&&t.length===0&&Zc<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][Zc]??3200;Zc+=1,Xc=!0,Qc=setTimeout(()=>{r()},e);return}Zc=0,Xc=!1;return}if(Zc<3){let e=[1e3,3e3,7e3][Zc]??7e3;Zc+=1,Xc=!0,Qc=setTimeout(()=>{r()},e)}}finally{Yc=!1,Xc||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&Gc(n.openInAppId)?n.openInAppId:null;r&&(window.localStorage.setItem(`openInAppId`,r),e({selectedAppId:r}))}),window.addEventListener(`openchamber:app-ready`,()=>{r()}),window.addEventListener(`openchamber:installed-apps-updated`,t=>{let r=t.detail;Array.isArray(r)&&(Zc=3,Xc=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Jc||t().initialize(),!E()||!D()||Yc||t().hasLoadedApps&&!n)return;let r=Vc.map(e=>e.appName);$c(),n&&e({hasLoadedApps:!1}),Yc=!0,Xc=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await C(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=Vc.filter(e=>o.has(e.appName)||Uc.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:Kc(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{Yc=!1,Xc||e({isScanning:!1})}},selectApp:async t=>{Gc(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await L({openInAppId:t}))}})),tl=`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`,rl=e=>({...e,fallbackIconDataUrl:e.id===`finder`&&window.__OPENCHAMBER_PLATFORM__!==`win32`?tl:e.id===`terminal`?nl:void 0}),il=e=>{let t=(0,zc.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=Y(`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},al=e=>{let t=(0,zc.c)(74),{directory:n,className:r}=e,{t:i}=qe(),a=el(ol),o=el(sl),s=el(cl),c=el(ll),l=el(ul),u=el(dl),d=el(fl),f,p;t[0]===l?(f=t[1],p=t[2]):(f=()=>{l()},p=[l],t[0]=l,t[1]=f,t[2]=p),Q.useEffect(f,p);let m=E()&&D(),h;bb0:{let e;t[3]!==o||t[4]!==a?(e=o.find(e=>e.id===a)??o.find(pl)??o[0]??Vc[0],t[3]=o,t[4]=a,t[5]=e):e=t[5];let n=e;if(n){let e;t[6]===n?e=t[7]:(e=rl(n),t[6]=n,t[7]=e),h=e;break bb0}let r;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(r=rl(Vc[0]),t[8]=r):r=t[8],h=r}let g=h;if(!m||!n||o.length===0)return null;let _;t[9]===n?_=t[10]:(_=async e=>{await k(n,e.id,e.appName)||await M(n,e.appName)},t[9]=n,t[10]=_);let v=_,y;t[11]!==v||t[12]!==d?(y=async e=>{await d(e.id),await v(e)},t[11]=v,t[12]=d,t[13]=y):y=t[13];let b=y,x;t[14]===n?x=t[15]:(x=async()=>{await Xe(n)},t[14]=n,t[15]=x);let S=x,C;t[16]===r?C=t[17]:(C=Y(`app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]`,`bg-[var(--surface-elevated)] overflow-hidden`,`border border-border/60`,r),t[16]=r,t[17]=C);let w;t[18]!==v||t[19]!==g?(w=()=>void v(g),t[18]=v,t[19]=g,t[20]=w):w=t[20];let T=c&&`animate-pulse`,O;t[21]===T?O=t[22]:(O=Y(`inline-flex h-full items-center px-2.5 typography-ui-label font-medium`,`text-foreground hover:bg-interactive-hover transition-colors`,T),t[21]=T,t[22]=O);let A;t[23]!==g.label||t[24]!==i?(A=i(`openInApp.actions.openInAria`,{app:g.label}),t[23]=g.label,t[24]=i,t[25]=A):A=t[25];let j;t[26]!==g.fallbackIconDataUrl||t[27]!==g.iconDataUrl||t[28]!==g.label?(j=(0,$.jsx)(il,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),t[26]=g.fallbackIconDataUrl,t[27]=g.iconDataUrl,t[28]=g.label,t[29]=j):j=t[29];let N;t[30]!==O||t[31]!==A||t[32]!==j||t[33]!==w?(N=(0,$.jsx)(`button`,{type:`button`,onClick:w,className:O,"aria-label":A,children:j}),t[30]=O,t[31]=A,t[32]=j,t[33]=w,t[34]=N):N=t[34];let P;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(P=Y(`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`),t[35]=P):P=t[35];let F;t[36]===i?F=t[37]:(F=i(`openInApp.actions.chooseAppAria`),t[36]=i,t[37]=F);let I;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4`}),t[38]=I):I=t[38];let ee;t[39]===F?ee=t[40]:(ee=(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:P,"aria-label":F,children:I})}),t[39]=F,t[40]=ee);let L;t[41]===S?L=t[42]:(L=()=>void S(),t[41]=S,t[42]=L);let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),t[43]=R):R=t[43];let z;t[44]===i?z=t[45]:(z=i(`openInApp.actions.copyPath`),t[44]=i,t[45]=z);let B;t[46]===z?B=t[47]:(B=(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:z}),t[46]=z,t[47]=B);let V;t[48]!==L||t[49]!==B?(V=(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:L,children:[R,B]}),t[48]=L,t[49]=B,t[50]=V):V=t[50];let H;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(oa,{}),t[51]=H):H=t[51];let te;if(t[52]!==o||t[53]!==b||t[54]!==g.id){let e;t[56]!==b||t[57]!==g.id?(e=e=>{let t=rl(e);return(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>void b(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}),g.id===e.id?(0,$.jsx)(X,{name:`check`,className:`ml-auto h-4 w-4 text-primary`}):null]},e.id)},t[56]=b,t[57]=g.id,t[58]=e):e=t[58],te=o.map(e),t[52]=o,t[53]=b,t[54]=g.id,t[55]=te}else te=t[55];let U;t[59]!==s||t[60]!==u||t[61]!==i?(U=s?(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>void u(!0),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:i(`openInApp.actions.refreshApps`)})]}):null,t[59]=s,t[60]=u,t[61]=i,t[62]=U):U=t[62];let ne;t[63]!==V||t[64]!==te||t[65]!==U?(ne=(0,$.jsxs)(ca,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[V,H,te,U]}),t[63]=V,t[64]=te,t[65]=U,t[66]=ne):ne=t[66];let W;t[67]!==ee||t[68]!==ne?(W=(0,$.jsxs)(ha,{children:[ee,ne]}),t[67]=ee,t[68]=ne,t[69]=W):W=t[69];let re;return t[70]!==N||t[71]!==W||t[72]!==C?(re=(0,$.jsxs)(`div`,{className:C,children:[N,W]}),t[70]=N,t[71]=W,t[72]=C,t[73]=re):re=t[73],re};function ol(e){return e.selectedAppId}function sl(e){return e.availableApps}function cl(e){return e.isCacheStale}function ll(e){return e.isScanning}function ul(e){return e.initialize}function dl(e){return e.loadInstalledApps}function fl(e){return e.selectApp}function pl(e){return e.id===Hc}var ml=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],hl=[`dev`,`start`,`preview`,`serve`];async function gl(e,t,n){if(!e)return null;let r=yl(t);if(r)return{command:r.command,label:r.name||`Start Preview`,actionId:r.id};if(n){let t=bl(n);if(t){let n=await xl(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 _l(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 _l(e){let t=await Sl(`${e}/index.html`,e);return typeof t==`string`&&t.trim().length>0}async function vl(){try{let e=await f(`/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 yl(e){for(let t of e){let e=`${t.name} ${t.command}`.toLowerCase();if(hl.some(t=>e.includes(t)))return t}return null}function bl(e){for(let{pattern:t}of ml)for(let n of Object.keys(e))if(t.test(n))return n;return null}async function xl(e){let t=await Sl(`${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 Sl(`${e}/${t}`,e);if(typeof r==`string`&&r.trim().length>0)return n}return`npm`}async function Sl(e,t){if(t?.trim())try{let n=new URLSearchParams({path:e,directory:t,optional:`true`}),r=await f(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(r.ok)return r.text()}catch{}let n=U()?.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 f(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:`no-store`});return t.ok?t.text():null}catch{return null}}async function Cl(e){try{let t=await Sl(`${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 wl=e=>new Promise(t=>{window.setTimeout(t,e)}),Tl=RegExp(`\x1B\\[[0-9;?]*[ -/]*[@-~]`,`g`),El=/https?:\/\/[^\s<>'"`]+/gi,Dl=`__openchamber_auto_discover_preview__`,Ol=15e3,kl=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},Al=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}},jl=e=>{let t=e.replace(Tl,``).match(El);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},Ml=({projectRef:e,directory:t,className:n,compact:r=!1,allowMobile:i=!1})=>{let{t:a}=qe(),{terminal:o,runtime:s}=za(),{isMobile:c}=Fa(),l=Q.useMemo(()=>E(),[]),u=ts(e=>e.instances),d=ts(e=>e.load),f=K(e=>e.setBottomTerminalOpen),p=K(e=>e.setActiveMainTab),m=K(e=>e.setSettingsPage),h=K(e=>e.setSettingsDialogOpen),g=K(e=>e.setSettingsProjectsSelectedId),_=K(e=>e.openContextPreview),v=Ss(e=>e.sessions),y=Ss(e=>e.ensureDirectory),b=Ss(e=>e.setTabLabel),x=Ss(e=>e.setTabIconKey),S=Ss(e=>e.setActiveTab),C=Ss(e=>e.setConnecting),w=Ss(e=>e.setTabSessionId),T=Ss(e=>e.setTabPreviewUrl),D=Ss(e=>e.projectActionRuns),O=Ss(e=>e.setProjectActionRun),k=Ss(e=>e.updateProjectActionRunStatus),A=Ss(e=>e.removeProjectActionRun),[j,M]=Q.useState([]),[N,P]=Q.useState(null),[F,I]=Q.useState(!1),ee=Q.useRef({}),L=Q.useRef({}),R=Q.useRef({}),z=Q.useRef({}),B=Q.useRef(0),V=e?.id??null,H=e?.path??``,te=Q.useMemo(()=>V?{id:V,path:H}:null,[V,H]);Q.useEffect(()=>{l&&d().catch(()=>void 0)},[l,d]);let U=Q.useCallback(async e=>{await wo(e)},[]),ne=Q.useCallback(async()=>{if(!te)return;let e=B.current+1;B.current=e,I(!0);try{let t=await dt(te);if(B.current!==e)return;let n=t.actions;M(n),P(e=>e===Dl||e&&n.some(t=>t.id===e)?e:null)}catch{if(B.current!==e)return}finally{B.current===e&&I(!1)}},[te]),W=Q.useMemo(()=>Cc(t||te?.path||``),[t,te?.path]),re=Q.useMemo(()=>N?j.find(e=>e.id===N)??null:null,[j,N]),G=Q.useMemo(()=>({id:Dl,name:a(`projectActions.actions.autoDiscover`),command:``,icon:`search`,autoOpenUrl:!0}),[a]),ie=!c,ae=Q.useMemo(()=>ie?[G,...j]:j,[j,G,ie]);Q.useEffect(()=>{ne()},[ne]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;V&&(t?.projectId&&t.projectId!==V||ne())};return window.addEventListener(Dc,e),()=>{window.removeEventListener(Dc,e)}},[ne,V]),Q.useEffect(()=>{N&&(N===Dl&&ie||j.some(e=>e.id===N)||P(null))},[j,ie,N]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=v.get(t.directory)?.tabs.find(e=>e.id===t.tabId);(!n||n.terminalSessionId!==t.sessionId)&&A(e)}},[D,A,v]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=L.current[e]??{lastSeenChunkId:null,openedUrl:!1,tail:``,openInPreview:!1};L.current[e]=n;let r=ae.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?jl(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=D[e];t&&(T(t.directory,t.tabId,l,{locked:!1,autoOpened:!1}),t.status===`waiting-for-preview`&&k(e,`running`),window.clearTimeout(z.current[e]),delete z.current[e],_(t.directory,l))}else U(l),J.success(a(`projectActions.toast.openedUrlFromOutput`));L.current[e]=n}for(let e of Object.keys(L.current))D[e]||(delete L.current[e],window.clearTimeout(z.current[e]),delete z.current[e])},[ae,_,U,D,T,a,v,k]);let oe=Q.useCallback(async(e,t={})=>{if(!W)throw Error(a(`projectActions.error.noActiveDirectory`));let n=Ec(W,e.id);y(W);let r=Ss.getState(),i=r.getDirectoryState(W),o=ee.current[n]||null,s=o?!!i?.tabs.some(e=>e.id===o):!1;(!o||!s)&&(o=r.createTab(W),ee.current[n]=o),b(W,o,`Action: ${e.name}`),x(W,o,e.icon||`play`),t.revealTerminal!==!1&&(S(W,o),f(!0),p(`terminal`));let c=Ss.getState().getDirectoryState(W)?.tabs.find(e=>e.id===o);return{key:n,tabId:o,sessionId:c?.terminalSessionId??null}},[y,W,p,S,f,x,b,a]),se=Q.useCallback(async e=>{if(s.isVSCode||!i&&c)return;if(!W){J.error(a(`projectActions.error.noActiveDirectoryForAction`));return}let t=Ec(W,e.id),n=D[t];if(!(n&&n.status===`running`))try{let t=e.id===Dl?await(async()=>{let[e,t]=await Promise.all([dt({id:te?.id??``,path:W}),Cl(W)]),n=await gl(W,e.actions,t);if(!n)throw Error(a(`contextPanel.preview.noDevServer`));return{id:Dl,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 oe(t,{revealTerminal:!n&&e.id!==Dl}),c=s,d=!1;if(!c){C(W,i,!0);try{c=(await o.createSession({cwd:W})).sessionId,d=!0,w(W,i,c)}finally{C(W,i,!1)}}if(!c)throw Error(a(`projectActions.error.failedToCreateTerminalSession`));d&&await wl(350),t.id===Dl&&(R.current[r]?.(),C(W,i,!0),R.current[r]=Re(c,e=>{e.type===`data`&&typeof e.data==`string`&&e.data.length>0&&Ss.getState().appendToBuffer(W,i,e.data),e.type===`exit`&&(Ss.getState().setTabLifecycle(W,i,`exited`),Ss.getState().setConnecting(W,i,!1),Ss.getState().removeProjectActionRun(r),delete L.current[r],R.current[r]?.(),delete R.current[r],window.clearTimeout(z.current[r]),delete z.current[r])},()=>{Ss.getState().setConnecting(W,i,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));let f=t.autoOpenUrl===!0&&l&&(t.desktopOpenSshForward||``).trim().length>0,p=t.autoOpenUrl?Al(t.openUrl):null,m=t.autoOpenUrl&&l?wc(t.desktopOpenSshForward,u):null;O({key:r,directory:W,actionId:t.id,tabId:i,sessionId:c,status:t.id===Dl&&!p?`waiting-for-preview`:`running`}),window.clearTimeout(z.current[r]),delete z.current[r],t.id===Dl&&!p&&(z.current[r]=window.setTimeout(()=>{Ss.getState().updateProjectActionRunStatus(r,`running`),delete z.current[r]},Ol)),m?(T(W,i,null,{locked:!0}),U(m),J.success(a(`projectActions.toast.openedForwardedUrl`))):p?(T(W,i,p,{locked:!0,autoOpened:!0}),_(W,p),J.success(a(`projectActions.toast.openedActionUrl`))):n?(T(W,i,null,{locked:!0}),J.error(a(`projectActions.error.invalidCustomUrlFormat`))):f?(T(W,i,null,{locked:!0}),J.error(a(`projectActions.error.selectedDesktopSshForwardUnavailable`))):T(W,i,null,{locked:!1,autoOpened:!1}),L.current[r]={lastSeenChunkId:null,openedUrl:!!m||!!p||n,tail:``,openInPreview:t.id===Dl};let h=kl(t.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await o.sendInput(c,`${h}\r`)}catch(e){A(t),delete L.current[t],R.current[t]?.(),delete R.current[t],window.clearTimeout(z.current[t]),delete z.current[t],J.error(e instanceof Error?e.message:a(`projectActions.error.failedToRunAction`))}},[u,oe,i,c,l,W,U,_,D,s.isVSCode,A,C,O,T,w,te?.id,a,o]),ce=Q.useCallback(async e=>{let t=Ec(W,e.id),n=D[t];if(n){k(t,`stopping`);try{await o.sendInput(n.sessionId,``)}catch{}if(await new Promise(e=>{window.setTimeout(e,1e3)}),Ss.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)}A(t),delete L.current[t],R.current[t]?.(),delete R.current[t],window.clearTimeout(z.current[t]),delete z.current[t]}},[W,D,A,w,o,k]),le=Q.useCallback(()=>{let e=re??ae[0];if(!e)return;let t=Ec(W,e.id),n=D[t];if(n?.status!==`stopping`){if(n){ce(e);return}se(e)}},[ae,W,se,D,re,ce]),ue=Q.useCallback((e,t=!1)=>{if(P(e.id),!t){se(e);return}let n=Ec(W,e.id),r=D[n];if(r?.status!==`stopping`){if(r){ce(e);return}se(e)}},[W,se,D,ce]),de=Q.useCallback(()=>{te?.id&&(g(te.id),m(`projects`),h(!0))},[h,m,g,te?.id]);if(s.isVSCode||!i&&c||!te||!W)return null;let fe=re??ae[0]??null;if(!fe)return null;let pe=fe.icon||`play`,me=fe.id===Dl?`search`:Tc[pe]||`play`,he=D[Ec(W,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:F||ge,className:Y(`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)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(X,{name:`stop`,className:`h-5 w-5 text-[var(--status-warning)]`}):(0,$.jsx)(X,{name:me,className:`h-5 w-5`})}),ye?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{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)(X,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ha,{children:[(0,$.jsx)(_a,{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)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})}),(0,$.jsxs)(ca,{align:`end`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(oa,{}),ae.map(e=>{let t=e.icon||`play`,n=e.id===Dl?`search`:Tc[t]||`play`,r=Ec(W,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(X,{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)(X,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(X,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]}):(0,$.jsxs)(`div`,{className:Y(`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:F||ge,className:Y(`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)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-[var(--status-warning)]`}):he?(0,$.jsx)(X,{name:`stop`,className:`h-4 w-4 text-[var(--status-warning)]`}):(0,$.jsx)(X,{name:me,className:`h-4 w-4`})})}),ye?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:be,className:Y(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)(X,{name:`global`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ha,{children:[(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(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)(X,{name:`arrow-down-s`,className:`h-4 w-4`})})}),(0,$.jsxs)(ca,{align:`start`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:de,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:a(`projectActions.actions.addNewAction`)})]}),(0,$.jsx)(oa,{}),ae.map(e=>{let t=e.icon||`play`,n=e.id===Dl?`search`:Tc[t]||`play`,r=Ec(W,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>{ue(e,!0)},children:[(0,$.jsx)(X,{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)(X,{name:`loader-4`,className:`ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]`}):a?(0,$.jsx)(X,{name:`stop`,className:`ml-auto h-4 w-4 text-[var(--status-warning)]`}):null]},e.id)})]})]})]})};function Nl(e){return e.isOpen&&e.activeTab===e.targetTab?{open:!1,tab:e.activeTab}:{open:!0,tab:e.targetTab}}var Pl=`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`,Fl=`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`,Il=Q.memo(function(e){let t=(0,zc.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??Pl,p=d&&`bg-interactive-selection text-interactive-selection-foreground`,m;t[0]!==f||t[1]!==p?(m=Y(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)(X,{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)(na,{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)(ra,{children:(0,$.jsx)(`p`,{children:r})}),t[12]=r,t[13]=v);let y;return t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(aa,{children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16],y}),Ll=Q.memo(function(e){let t=(0,zc.c)(42),{isMobile:n,githubAuthStatus:r,githubAccounts:i,githubAvatarUrl:a,githubLogin:o,isSwitchingGitHubAccount:s,handleGitHubAccountSwitch:c}=e,{t:l}=qe();if(!r?.connected||n)return null;if(i.length>1){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(Pl,`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)(X,{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)(_a,{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)(pa,{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)(oa,{}),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)(ua,{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)(X,{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)(X,{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)(ca,{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)(ha,{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)(X,{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}),Rl=Q.memo(function(e){let t=(0,zc.c)(61),{isDesktopApp:n,currentInstanceSupportsUpdate:r,isDesktopServicesOpen:i,setIsDesktopServicesOpen:a,refreshCurrentInstanceLabel:o,desktopServicesTab:s,setDesktopServicesTab:c,quotaResultsLength:l,fetchAllQuotas:u,servicesTabItems:d,quotaLastUpdated:f,quotaDisplayMode:p,quotaDisplayTabItems:m,handleDisplayModeChange:h,handleUsageRefresh:g,isQuotaLoading:_,isUsageRefreshSpinning:v,hasRateLimits:y,rateLimitGroups:b,expandedFamilies:x,toggleFamilyExpanded:S,showDevShutdown:C,isDevShutdownInFlight:w,onDevShutdown:T,remoteUpdateInfo:E,remoteUpdateChecking:D,remoteUpdateError:O,onOpenRemoteUpdate:k,showPredValues:A,timeFormatPreference:j,anchorRef:M}=e,{t:N}=qe(),P;t[0]!==s||t[1]!==u||t[2]!==l||t[3]!==o||t[4]!==a?(P=e=>{a(e),e&&(o(),s===`usage`&&l===0&&u())},t[0]=s,t[1]=u,t[2]=l,t[3]=o,t[4]=a,t[5]=P):P=t[5];let F;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(_a,{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]=F):F=t[6];let I;t[7]!==u||t[8]!==l||t[9]!==c?(I=e=>{let t=e;c(t),t===`usage`&&l===0&&u()},t[7]=u,t[8]=l,t[9]=c,t[10]=I):I=t[10];let ee;t[11]!==s||t[12]!==d||t[13]!==I?(ee=(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)(Bo,{items:d,activeId:s,onSelect:I,layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,activePillButtonClassName:`h-8`,className:`h-full`})})}),t[11]=s,t[12]=d,t[13]=I,t[14]=ee):ee=t[14];let L;t[15]!==r||t[16]!==s||t[17]!==n||t[18]!==i||t[19]!==k||t[20]!==D||t[21]!==O||t[22]!==E||t[23]!==a||t[24]!==N?(L=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:N(`header.services.remoteUpdate.title`)}),(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:E?.available?N(`header.services.remoteUpdate.available`,{version:E.version||``}):D?N(`header.services.remoteUpdate.checking`):O||N(`header.services.remoteUpdate.upToDate`)})]}),E?.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:k,children:N(`header.services.remoteUpdate.actions.open`)}):null]})}):null,(0,$.jsx)(Wr,{embedded:!0,open:i&&s===`instance`,onOpenChange:Wl,onHostSwitched:()=>a(!1)})]}):null,t[15]=r,t[16]=s,t[17]=n,t[18]=i,t[19]=k,t[20]=D,t[21]=O,t[22]=E,t[23]=a,t[24]=N,t[25]=L):L=t[25];let R;t[26]!==s||t[27]!==i?(R=s===`mcp`?(0,$.jsx)(Hs,{active:i&&s===`mcp`}):null,t[26]=s,t[27]=i,t[28]=R):R=t[28];let z;t[29]!==s||t[30]!==x||t[31]!==h||t[32]!==g||t[33]!==y||t[34]!==_||t[35]!==v||t[36]!==p||t[37]!==m||t[38]!==f||t[39]!==b||t[40]!==A||t[41]!==N||t[42]!==j||t[43]!==S?(z=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:N(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:Bl(f,j)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`div`,{className:`h-7 w-[10.5rem]`,children:(0,$.jsx)(Bo,{items:m,activeId:p,onSelect:e=>void h(e),layoutMode:`fit`,variant:`active-pill`,activePillInsetClassName:`gap-0.5 px-px py-0`,className:`h-full`})}),(0,$.jsx)(`button`,{type:`button`,className:Y(`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:g,disabled:_||v,"aria-label":N(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,v&&`animate-spin`)})})]})]}),y?null:(0,$.jsx)(`div`,{className:`px-4 py-5 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:N(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`space-y-2 px-3 py-2.5`,children:b.map(e=>{let t=x[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)(Hi,{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??N(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[e.entries.map(t=>{let[n,r]=t,i=p===`remaining`?r.remainingPercent:r.usedPercent,a=ba(r.usedPercent,r.resetAt,r.windowSeconds,n),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-Ea(a.elapsedRatio):Ea(a.elapsedRatio),s=Sa(r.valueLabel,i),c=ka(r.resetAt,r.resetAfterFormatted??r.resetAtFormatted,j);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 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:ja(n)}),c?(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:c}):null]}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(ss,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(us,{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)(Sc,{open:i,onOpenChange:()=>S(e.providerId,r),children:[(0,$.jsxs)(xc,{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)(X,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(bc,{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=p===`remaining`?r.remainingPercent:r.usedPercent,a=ba(r.usedPercent,r.resetAt,r.windowSeconds),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-Ea(a.elapsedRatio):Ea(a.elapsedRatio),s=Sa(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:is(n)}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(ss,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(us,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)})})})]},r)})}):null]})]},e.providerId)})})]}):null,t[29]=s,t[30]=x,t[31]=h,t[32]=g,t[33]=y,t[34]=_,t[35]=v,t[36]=p,t[37]=m,t[38]=f,t[39]=b,t[40]=A,t[41]=N,t[42]=j,t[43]=S,t[44]=z):z=t[44];let B;t[45]!==w||t[46]!==T||t[47]!==C||t[48]!==N?(B=C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mx-4 my-2 border-t border-[var(--interactive-border)]`}),(0,$.jsx)(`div`,{className:`px-2 pb-2`,children:(0,$.jsx)(ua,{disabled:w,onSelect:()=>{T()},children:N(`header.services.shutdownDev`)})})]}):null,t[45]=w,t[46]=T,t[47]=C,t[48]=N,t[49]=B):B=t[49];let V;t[50]!==M||t[51]!==ee||t[52]!==L||t[53]!==R||t[54]!==z||t[55]!==B?(V=(0,$.jsxs)(ca,{anchor:M,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:[ee,L,R,z,B]}),t[50]=M,t[51]=ee,t[52]=L,t[53]=R,t[54]=z,t[55]=B,t[56]=V):V=t[56];let H;return t[57]!==i||t[58]!==P||t[59]!==V?(H=(0,$.jsxs)(ha,{open:i,onOpenChange:P,children:[F,V]}),t[57]=i,t[58]=P,t[59]=V,t[60]=H):H=t[60],H}),zl=(e,t)=>e===t?!0:!e||!t?!1:e.totalTokens===t.totalTokens&&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??``),Bl=(e,t)=>{if(!e)return`-`;try{return wa(e,t,{fallback:`-`})}catch{return`-`}},Vl=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},Hl=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,Ul=({onToggleLeftDrawer:e,onToggleRightDrawer:n,leftDrawerOpen:r,rightDrawerOpen:i})=>{let{t:a}=qe(),o=K(e=>e.setSessionSwitcherOpen),s=K(e=>e.toggleSidebar),c=K(e=>e.isSidebarOpen),l=K(e=>e.toggleBottomTerminal),u=K(e=>e.toggleRightSidebar),p=K(e=>e.openContextOverview),h=K(e=>e.openContextBrowser),g=K(e=>e.openContextPanelTab),_=K(e=>e.closeContextPanel),v=K(e=>e.contextPanelByDirectory),y=K(e=>e.activeMainTab),S=K(e=>e.setActiveMainTab),C=K(e=>e.shortcutOverrides),w=K(e=>e.timeFormatPreference),T=Et(e=>e.getCurrentModel),O=za(),[k,A]=Q.useState(!1),j=Pt(e=>e.getContextUsage),M=Pt(e=>!!e.newSessionDraft?.open),N=Pt(e=>e.currentSessionId),P=At(N??``),F=xt(N),I=qt(e=>e.activeProjectId?e.projects.find(t=>t.id===e.activeProjectId)??null:null),R=Q.useMemo(()=>{if(!I)return null;let e=I.path.split(/[\\/]/).filter(Boolean);return e[e.length-1]??null},[I]),z=ps(e=>e.results),B=ps(e=>e.fetchAllQuotas),V=ps(e=>e.isLoading),te=ps(e=>e.lastUpdated),U=ps(e=>e.displayMode),G=ps(e=>e.showPredValues),oe=ps(e=>e.dropdownProviderIds),se=ps(e=>e.loadSettings),ce=ps(e=>e.setDisplayMode),{isMobile:le}=Fa(),ue=Ma().data??null,de=ds(e=>e.setStatus),fe=Q.useRef(null),[pe,me]=Q.useState(()=>typeof window>`u`?!1:E()),he=Q.useMemo(()=>b(),[]),ge=pe&&x()===`win32`,_e=Ia(),[ve,ye]=Q.useState(!1),be=Q.useMemo(()=>typeof navigator>`u`?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||``),[]),{usesFramelessChrome:xe,side:Se}=xs(),Ce=Q.useMemo(()=>{if(typeof window>`u`)return null;let e=window.__OPENCHAMBER_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`||me(E())},[]);let we=T(),Te=we&&typeof we.limit==`object`&&we.limit!==null?we.limit:null,Ee=j(Te&&typeof Te.context==`number`?Te.context:0,Te&&typeof Te.output==`number`?Te.output:0),[De,Oe]=Q.useState(null),ke=!N||P;(0,Q.useEffect)(()=>{if(!N){Oe(e=>e===null?e:null);return}if(Ee&&Ee.totalTokens>0){Oe(e=>zl(e,Ee)?e:Ee);return}ke&&Oe(e=>e===null?e:null)},[Ee,N,ke]);let Ae=K(e=>e.isSessionSwitcherOpen),je=ue?.connected?ue.user?.avatarUrl??null:null,Me=ue?.connected?ue.user?.login??null:null,Ne=ue?.accounts??[],[Pe,q]=Q.useState(!1),[Fe,Ie]=Q.useState(!1),[Re,ze]=Q.useState(!1),[Be,Ve]=Q.useState(!1),[Ue,We]=Q.useState(`Local`),[Ge,Ke]=Q.useState(!1),[Je,Ye]=Q.useState(!1),[Xe,Ze]=Q.useState(null),[Qe,$e]=Q.useState(!1),[et,tt]=Q.useState(null),[nt,rt]=Q.useState(pe?`instance`:`usage`),[it,at]=Q.useState(`usage`);(0,Q.useEffect)(()=>{!pe&&nt===`instance`&&rt(`usage`)},[nt,pe]);let ot=Q.useMemo(()=>m(),[]),st=!ot&&y===`chat`&&!!De&&De.totalTokens>0,ct=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,lt=He(async()=>{if(!(typeof window>`u`||!pe))try{if(D()){We(`Local`),Ke(!1);return}let e=await ie(),t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,n=d();if(n&&ne(n,t)){We(`Local`),Ke(!1);return}let r=e.hosts.find(e=>n?ne(n,re(e)):!1);if(r&&!r.relay){let e=await sa();if(d()!==n)return;Ke(ae(r,new Set(e.instances.map(e=>e.id))))}else Ke(!1);if(r?.label?.trim()){We(W(r.label.trim()));return}We(`Instance`)}catch{We(`Local`),Ke(!1)}});(0,Q.useEffect)(()=>{lt()},[pe]);let ut=He(async()=>{if(!Ge){Ze(null),tt(null);return}$e(!0),tt(null);try{let e=new URLSearchParams({appType:`web`,instanceMode:`remote`}),t=await f(`/api/openchamber/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();Ze({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){Ze(null),tt(e instanceof Error?e.message:a(`header.services.remoteUpdate.error`))}finally{$e(!1)}});Q.useEffect(()=>{Ze(null),tt(null),Ye(!1)},[Ge,Ue]),Q.useEffect(()=>{if(!pe||!Ge)return;let e=36e5,t=!1,n=null,r=i=>{n=window.setTimeout(()=>{if(t||typeof document<`u`&&document.visibilityState!==`visible`){r(e);return}ut().finally(()=>{t||r(e)})},i)};return r(3e3),()=>{t=!0,n!==null&&window.clearTimeout(n)}},[Ge,Ue,pe]);let dt=He(()=>{if(Ge){if(Xe?.available){Ye(!0);return}ut()}});rs();let ft=ps(e=>e.selectedModels),pt=ps(e=>e.expandedFamilies),mt=ps(e=>e.toggleFamilyExpanded),ht=Q.useMemo(()=>{let e=[];for(let t of Go){if(!oe.includes(t.id))continue;let n=z.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=ft[t.id]??[],n=e.length>0,r=hs(i,t.id),o=gs(t.id),c=Jo(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},[oe,z,ft,a]),gt=ht.length>0;Q.useEffect(()=>{se()},[se]);let _t=Q.useCallback(async e=>{ce(e);try{await L({usageDisplayMode:e})}catch(e){console.warn(`Failed to update usage display mode:`,e)}},[ce]),vt=Q.useCallback(()=>{if(Be)return;Ve(!0);let e=new Promise(e=>setTimeout(e,500));Promise.all([B(),e]).finally(()=>{Ve(!1)})},[B,Be]),yt=Pt(e=>N?e.worktreeMetadata.get(N)?.path??``:``),bt=Q.useMemo(()=>Vl(yt||``),[yt]),St=Q.useMemo(()=>Vl((typeof F?.directory==`string`?F.directory:``)||``),[F?.directory]),Ct=Pt(e=>e.newSessionDraft?.open?Vl(e.newSessionDraft.bootstrapPendingDirectory??e.newSessionDraft.directoryOverride??``):``),wt=Q.useMemo(()=>bt||St||Ct,[Ct,St,bt]),Tt=jo(),Dt=Q.useMemo(()=>Vl(Tt||wt||I?.path||``),[I?.path,Tt,wt]),Ot=Q.useMemo(()=>{if(!N)return R??`OpenChamber`;let e=F?.title?.trim();return e&&e.length>0?e:`Untitled Session`},[R,F?.title,N]),kt=Q.useMemo(()=>Vl(wt||I?.path||``),[I?.path,wt]),jt=Q.useMemo(()=>I?{id:I.id,path:I.path}:null,[I]),Mt=Q.useRef(null);Q.useEffect(()=>{!jt||!kt||(Mt.current={projectRef:jt,directory:kt})},[kt,jt]);let Nt=Q.useMemo(()=>jt&&kt?{projectRef:jt,directory:kt}:Mt.current,[kt,jt]),Ft=Q.useCallback(async e=>{if(!(!e||Pe)){q(!0);try{let t=O.github?await O.github.authActivate(e):await(async()=>{let t=await f(`/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})();de(t)}catch(e){console.error(`Failed to switch GitHub account:`,e)}finally{q(!1)}}},[Pe,O.github,de]),It=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()},[]),Lt=Q.useCallback(()=>{if(le){It(),o(!Ae);return}s()},[It,le,Ae,o,s]),Rt=Q.useCallback(()=>{ee(`desktop_open_draft_mini_chat_window`,{directory:Vl(wt||I?.path||``),projectId:I?.id??null,apiBaseUrl:d(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open draft mini chat window`,e)})},[I?.id,I?.path,wt]),zt=Q.useCallback(()=>{if(M){Rt();return}N&&ee(`desktop_open_session_mini_chat_window`,{sessionId:N,directory:Vl(wt||I?.path||``),apiBaseUrl:d(),clientToken:t()}).catch(e=>{console.warn(`[header] failed to open session mini chat window`,e)})},[I?.path,N,Rt,M,wt]),Bt=Q.useCallback(()=>{let e=Dt;if(!e)return;let t=v[e];if(Hl(t)===`context`){_(e);return}p(e)},[_,Dt,v,p]),Vt=Q.useMemo(()=>{let e=Dt;if(!e)return!1;let t=v[e];return Hl(t)===`context`},[Dt,v]),Ht=Q.useCallback(()=>{let e=Dt;if(!e)return;let t=v[e];if(Hl(t)===`diff`){_(e);return}g(e,{mode:`diff`,stagedDiff:!1})},[_,Dt,v,g]),Ut=Q.useCallback(()=>{let e=Dt;if(!e)return;let t=v[e];if(Hl(t)===`browser`){_(e);return}h(e)},[_,Dt,v,h]),Wt=Q.useMemo(()=>{let e=Dt;if(!e)return!1;let t=v[e];return Hl(t)===`browser`},[Dt,v]),Gt=Pl,Kt=Fl,Jt=Q.useMemo(()=>Fe?`services`:r?`sessions`:i?`git`:y,[y,Fe,r,i]),Yt=Q.useCallback(()=>{Ie(!1),r&&e&&e(),i&&n&&n(),!e&&Ae&&o(!1)},[Ae,r,e,n,i,o]),Xt=Q.useCallback(()=>{r||Ie(!1),e?.()},[r,e]),Zt=Q.useCallback(()=>{i||Ie(!1),n?.()},[n,i]),Qt=Q.useMemo(()=>pe&&be&&!ve?`5.5rem`:_e?`max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)`:(!pe||xe)&&!ot?`calc(0.75rem + var(--oc-wco-left-inset, 0px))`:`0.75rem`,[pe,ve,be,_e,ot,xe]);(0,Q.useEffect)(()=>{typeof document>`u`||document.documentElement.style.setProperty(`--oc-titlebar-left-inset`,Qt)},[Qt]);let $t=c?`0.75rem`:`var(--oc-titlebar-left-inset, 0.75rem)`,en=c?`0px`:`calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)`;(0,Q.useEffect)(()=>{if(!pe||!be){ye(!1);return}let e=!1,t=async()=>{try{let t=await ee(`desktop_is_window_fullscreen`);e||ye(t===!0)}catch{e||ye(!1)}},n=()=>{t()};return t(),window.addEventListener(`openchamber:window-resized`,n),()=>{e=!0,window.removeEventListener(`openchamber:window-resized`,n)}},[pe,be]);let tn=Q.useMemo(()=>!pe||!be||Ce===null?``:Ce>=26?`h-12`:Ce<=15?`h-14`:``,[pe,be,Ce]),nn=Q.useMemo(()=>{if(!(pe&&!xe||ot))return{paddingRight:`calc(0.75rem + var(--oc-wco-right-inset, 0px))`,minHeight:`max(3rem, var(--oc-wco-titlebar-height, 0px))`,height:`max(3rem, var(--oc-wco-titlebar-height, 0px))`}},[pe,ot,xe]),J=Q.useCallback(()=>{if(typeof document>`u`)return;let e=fe.current?.getBoundingClientRect().height;e&&document.documentElement.style.setProperty(`--oc-header-height`,`${e}px`)},[]);(0,Q.useEffect)(()=>{if(typeof window>`u`)return;J();let e=fe.current;if(!e||typeof ResizeObserver>`u`)return()=>{};let t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,J()})},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)}},[J]),(0,Q.useEffect)(()=>{J()},[J,le,tn]);let rn=Q.useCallback(async e=>{let t=e.target;t.closest(`.app-region-no-drag`)||t.closest(`button, a, input, select, textarea`)||e.button===0&&pe&&await H()},[pe]),an=Q.useMemo(()=>{if(le){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[]},[le,a]),on=Q.useCallback(e=>la(Oa(e,C)),[C]);(0,Q.useEffect)(()=>{!le&&(y===`git`||y===`terminal`||y===`diff`||y===`files`)&&S(`chat`)},[y,le,S]);let sn=Q.useMemo(()=>{let e=[];return pe&&e.push({value:`instance`,label:a(`layout.services.instance`),icon:(0,$.jsx)(X,{name:`server`,className:`h-3.5 w-3.5`})}),e.push({value:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{value:`mcp`,label:`MCP`,icon:(0,$.jsx)($o,{className:`h-3.5 w-3.5`})}),e},[pe,a]),cn=Q.useMemo(()=>sn.map(e=>({id:e.value,label:e.label,icon:e.icon})),[sn]),ln=Q.useMemo(()=>{if(typeof window>`u`||pe||ot)return!1;let e=window.location.hostname;return e===`localhost`||e===`127.0.0.1`||e===`::1`},[pe,ot]),un=Q.useCallback(async()=>{if(k)return;A(!0),ze(!1);let e=[],t=!1;try{try{for(let[,t]of Ss.getState().sessions.entries())for(let n of t.tabs)n.previewUrl&&e.push(n.previewUrl)}catch{}try{await Le({})}catch{}try{t=(await f(`/api/system/dev-shutdown`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({previewUrls:e})})).ok?!0:(await f(`/api/system/shutdown`,{method:`POST`})).ok}catch{}}finally{t||A(!1)}},[k,ze]),dn=Q.useMemo(()=>[{value:`usage`,label:a(`header.services.used`)},{value:`remaining`,label:a(`header.services.remaining`)}],[a]),fn=Q.useMemo(()=>dn.map(e=>({id:e.value,label:e.label})),[dn]),pn=Q.useMemo(()=>[{id:`usage`,label:a(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{id:`mcp`,label:`MCP`,icon:(0,$.jsx)($o,{className:`h-3.5 w-3.5`})}],[a]);(0,Q.useEffect)(()=>{let e=e=>{if(Kn(e)&&!e.shiftKey&&!e.altKey){let t=parseInt(e.key,10);t>=1&&t<=an.length&&(e.preventDefault(),le&&(It(),Yt()),S(an[t-1].id))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[It,Yt,le,S,an]);let mn=Q.useCallback(e=>{rt(e),ze(!0),lt(),e===`usage`&&z.length===0&&B()},[B,z.length,lt]);(0,Q.useEffect)(()=>{let e=e=>{let t=Oa(`toggle_services_menu`,C);if(ga(e,t)){e.preventDefault();let t=Nl({isOpen:Re,activeTab:nt,targetTab:pe?`instance`:`usage`});t.open?mn(t.tab):ze(!1);return}let n=Oa(`cycle_services_tab`,C);if(ga(e,n)){e.preventDefault();let t=sn.map(e=>e.value);if(t.length===0)return;let n=t.indexOf(nt),r=t[n===-1?0:(n+1)%t.length];rt(r),ze(!0),lt(),r===`usage`&&z.length===0&&B();return}let r=Oa(`open_usage`,C);if(ga(e,r)){e.preventDefault();let t=Nl({isOpen:Re,activeTab:nt,targetTab:`usage`});t.open?mn(t.tab):ze(!1);return}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[C,pe,Re,nt,sn,z.length,B,lt,mn]);let hn=e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon,i=e.id===`chat`,a=e=>n?(0,$.jsx)(Bc,{size:e}):r?(0,$.jsx)(X,{name:r,className:`h-${e/4} w-${e/4}`}):null,o=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(e.id),className:Y(`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&&!le&&`min-w-[100px] justify-center`),"aria-label":e.label,"aria-selected":t,role:`tab`,children:[le?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)},gn=he&&(M||!!N),_n=Q.useCallback(e=>{window.setTimeout(e,0)},[]),vn=Q.useCallback(e=>{mn(e)},[mn]),yn=Q.useRef(null),bn=(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,children:[(0,$.jsx)(`div`,{ref:yn,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center`,children:(0,$.jsxs)(ha,{children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.actions.sessionMenuAria`),className:Y(Gt,`text-muted-foreground`),children:(0,$.jsx)(X,{name:`more-2`,className:`h-[18px] w-[18px]`})})})}),(0,$.jsx)(ra,{children:(0,$.jsx)(`p`,{children:a(`header.actions.sessionMenu`)})})]}),(0,$.jsxs)(ca,{align:`start`,className:`min-w-[14rem]`,children:[ot?null:(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(Ht),children:[(0,$.jsx)(X,{name:`layout-column`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`header.actions.toggleChangesPanel`)})]}),gn?(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(zt),children:[(0,$.jsx)(X,{name:`picture-in-picture-2`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(M?`header.actions.newMiniChat`:`header.actions.openSessionMiniChat`)})]}):null,pe?(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(()=>vn(`instance`)),children:[(0,$.jsx)(X,{name:`stack`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a(`header.actions.sessionMenu.servicesWithInstance`,{current:Ue})}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:on(`toggle_services_menu`)})]}):null,(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(()=>vn(`usage`)),children:[(0,$.jsx)(X,{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:on(`open_usage`)})]}),(0,$.jsx)(oa,{}),(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(l),children:[(0,$.jsx)(X,{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:on(`toggle_terminal`)})]}),(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>_n(Ut),children:[(0,$.jsx)(X,{name:`global`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:a(`contextPanel.browser.open`)}),Wt?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-foreground`}):null]})]})]})}),(0,$.jsx)(Rl,{isDesktopApp:pe,currentInstanceSupportsUpdate:Ge,isDesktopServicesOpen:Re,setIsDesktopServicesOpen:ze,refreshCurrentInstanceLabel:lt,desktopServicesTab:nt,setDesktopServicesTab:rt,quotaResultsLength:z.length,fetchAllQuotas:B,servicesTabItems:cn,quotaLastUpdated:te,quotaDisplayMode:U,showPredValues:G,quotaDisplayTabItems:fn,handleDisplayModeChange:_t,handleUsageRefresh:vt,isQuotaLoading:V,isUsageRefreshSpinning:Be,hasRateLimits:gt,rateLimitGroups:ht,expandedFamilies:pt,toggleFamilyExpanded:mt,showDevShutdown:ln,isDevShutdownInFlight:k,onDevShutdown:un,remoteUpdateInfo:Xe,remoteUpdateChecking:Qe,remoteUpdateError:et,onOpenRemoteUpdate:dt,timeFormatPreference:w,anchorRef:yn})]}),xn=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(al,{directory:kt,className:`mr-1`}),(0,$.jsx)(Il,{title:a(`header.actions.rightSidebarWithShortcut`,{shortcut:on(`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)(Ll,{isMobile:le,githubAuthStatus:ue,githubAccounts:Ne,githubAvatarUrl:je,githubLogin:Me,isSwitchingGitHubAccount:Pe,handleGitHubAccountSwitch:Ft})]}),Sn=()=>(0,$.jsxs)(`div`,{onMouseDown:rn,className:Y(`app-region-drag relative flex h-12 select-none items-center pr-3`,tn),style:nn,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:$t}}),(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:en}}),(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)(ys,{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:M?a(`sessions.switcher.draftTitle`):Ot})})}),bn]}),an.length>0&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1`,children:an.map(e=>hn(e))}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[st&&De?(0,$.jsx)(vs,{totalTokens:De.totalTokens,percentage:ct,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:`compact`,appearance:`subtle`,onClick:Bt,pressed:Vt,className:`mr-2`}):null,xn,(0,$.jsx)(bs,{visible:xe&&Se===`right`,position:`right`})]})]})]}),Cn=()=>(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:Xt,className:Y(Kt,Jt===`sessions`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":a(r?`header.actions.closeSessionsAria`:`header.actions.openSessionsAria`),children:(0,$.jsx)(X,{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)(X,{name:`arrow-left-s`,className:`h-5 w-5`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Lt,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)(X,{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:an.map(e=>{let t=y===e.id,n=e.icon===`diff`,r=n?null:e.icon;return(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{le&&(It(),Yt()),S(e.id)},"aria-label":e.label,"aria-selected":t,role:`tab`,className:Y(Kt,`relative rounded-lg`,Jt===e.id&&`bg-interactive-selection text-interactive-selection-foreground`),children:[n?(0,$.jsx)(Bc,{className:`h-5 w-5`}):r?(0,$.jsx)(X,{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)(ra,{children:(0,$.jsx)(`p`,{children:e.label})})]},e.id)})})})})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[Nt&&(0,$.jsx)(Ml,{projectRef:Nt.projectRef,directory:Nt.directory,compact:!0,allowMobile:!0,className:`h-9`}),(0,$.jsxs)(ha,{open:Fe,onOpenChange:t=>{t&&(r&&e&&e(),i&&n&&n()),Ie(t),t&&z.length===0&&B()},children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":a(`header.services.viewAria`),className:Y(Kt,Jt===`services`&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(X,{name:`stack`,className:`h-5 w-5`})})})}),(0,$.jsx)(ra,{children:(0,$.jsx)(`p`,{children:a(`header.services.title`)})})]}),(0,$.jsx)(ca,{align:`end`,sideOffset:0,positionerClassName:`!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none`,className:`h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden`,children:(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)(Bo,{items:pn,activeId:it,onSelect:e=>{let t=e;at(t),t===`usage`&&z.length===0&&B()},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)(X,{name:`close`,className:`h-5 w-5`})})]})}),it===`mcp`&&(0,$.jsx)(Hs,{active:Fe&&it===`mcp`}),it===`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:Bl(te,w)})]}),(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:()=>_t(`usage`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,U===`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:()=>_t(`remaining`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,U===`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:Y(`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:vt,disabled:V||Be,"aria-label":a(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,Be&&`animate-spin`)})})]})]})}),!gt&&(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:ht.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)(Hi,{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=U===`remaining`?n.remainingPercent:n.usedPercent,i=ba(n.usedPercent,n.resetAt,n.windowSeconds,t),a=i?.dailyAllocationPercent==null?null:U===`remaining`?100-Ea(i.elapsedRatio):Ea(i.elapsedRatio),o=Sa(n.valueLabel,r),s=ka(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,w);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 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:ja(t)}),s?(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:s}):null]}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(ss,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&G?(0,$.jsx)(us,{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=(pt[e.providerId]??[]).includes(t.familyId??`other`);return(0,$.jsxs)(Sc,{open:n,onOpenChange:()=>mt(e.providerId,t.familyId??`other`),children:[(0,$.jsxs)(xc,{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)(X,{name:`arrow-down-s`,className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(bc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:t.models.map(([t,n])=>{let r=U===`remaining`?n.remainingPercent:n.usedPercent,i=ba(n.usedPercent,n.resetAt,n.windowSeconds),a=i?.dailyAllocationPercent==null?null:U===`remaining`?100-Ea(i.elapsedRatio):Ea(i.elapsedRatio),o=Sa(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:is(t)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(ss,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&G?(0,$.jsx)(us,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)})})})]},t.familyId??`other`)})})]})]},e.providerId))})]})]})})]}),n?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:Zt,className:Y(Kt,`relative`,Jt===`git`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":i?`Close git sidebar`:`Open git sidebar`,children:(0,$.jsx)(X,{name:`layout-right`,className:`h-5 w-5`})})}),(0,$.jsx)(ra,{children:(0,$.jsx)(`p`,{children:i?`Close git sidebar`:`Open git sidebar`})})]}):null]})]})]}),wn=Y(`header-safe-area relative z-10 bg-background`,ge&&`bg-[var(--surface-background)] backdrop-blur-none`,le&&`oc-layout-divider-b`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`header`,{ref:fe,className:wn,style:{"--padding-scale":`1`},children:le?Cn():Sn()}),(0,$.jsx)(_s,{open:Ge&&Je,onOpenChange:Ye,info:Xe,downloading:!1,downloaded:!1,progress:null,error:et,onDownload:()=>{},onRestart:()=>{},runtimeType:`web`})]})};function Wl(){}var Gl=180,Kl=640,ql=110,Jl=e=>{let t=(0,zc.c)(44),{isOpen:n,isMobile:r,children:i}=e,{t:a}=qe(),o=K(Yl),s=K(Xl),c=K(Zl),l=K(Ql),[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(Kl,Math.max(Gl,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(Kl,Math.max(Gl,g.current+t));c(n)},t=()=>{p(!1),K.getState().bottomTerminalHeight<=ql&&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=Y(`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:Y(`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=Y(`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 ee=!n,L;t[34]!==i||t[35]!==I||t[36]!==ee?(L=(0,$.jsx)(`div`,{className:I,"aria-hidden":ee,children:i}),t[34]=i,t[35]=I,t[36]=ee,t[37]=L):L=t[37];let R;return t[38]!==j||t[39]!==M||t[40]!==N||t[41]!==P||t[42]!==L?(R=(0,$.jsxs)(`section`,{ref:m,className:j,style:M,"aria-hidden":N,children:[P,L]}),t[38]=j,t[39]=M,t[40]=N,t[41]=P,t[42]=L,t[43]=R):R=t[43],R};function Yl(e){return e.bottomTerminalHeight}function Xl(e){return e.isBottomTerminalExpanded}function Zl(e){return e.setBottomTerminalHeight}function Ql(e){return e.setBottomTerminalOpen}var $l=260,eu=260,tu=500,nu=({isOpen:e,isMobile:t,children:n,className:r,topBar:i})=>{let{t:a}=qe(),o=K(e=>e.sidebarWidth),s=K(e=>e.setSidebarWidth),[c,l]=Q.useState(!1),u=Q.useRef(0),d=Q.useRef(o||$l),f=Q.useRef(null),p=Q.useRef(null),m=Q.useRef(null),h=Q.useCallback(e=>Math.min(tu,Math.max(eu,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(`--oc-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(eu,o||$l)),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:Y(`relative flex h-full overflow-hidden oc-layout-divider-r will-change-[width] motion-reduce:transition-none`,`bg-sidebar oc-vibrancy-surface`,!e&&`border-r-0`,r),style:{width:`${S}px`,minWidth:`${S}px`,maxWidth:`${S}px`,"--oc-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:Y(`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:Y(`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(--oc-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)(Ca,{children:n})})]})]})},ru=()=>{let e=(0,zc.c)(3),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={height:`var(--oc-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(--oc-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(--oc-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},iu=e=>{let t=(0,zc.c)(24),{className:n}=e,r=as(au),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0],Q.useEffect(ou,i);let a,o,s,c,l,u,d;if(t[1]!==n||t[2]!==r){d=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.trim().split(/\s+/).filter(Boolean);if(e.length===0){d=null;break bb0}let i=e.slice(0,-1);a=e.at(-1),t[10]===n?u=t[11]:(u=Y(`px-2 pb-2 pt-1`,n),t[10]=n,t[11]=u),o=e.join(` `),s=`inline-flex min-w-0 items-baseline gap-[0.28em] truncate`,t[12]===Symbol.for(`react.memo_cache_sentinel`)?(c={fontFamily:`"Syne", var(--font-sans, system-ui, sans-serif)`,fontSize:`1.0625rem`,fontWeight:700,letterSpacing:`0.08em`,lineHeight:1},t[12]=c):c=t[12],l=i.length>0&&(0,$.jsx)(`span`,{className:`text-foreground`,children:i.join(` `)})}t[1]=n,t[2]=r,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];if(d!==Symbol.for(`react.early_return_sentinel`))return d;let f;t[13]===a?f=t[14]:(f=a&&(0,$.jsx)(`span`,{className:`text-primary`,children:a}),t[13]=a,t[14]=f);let p;t[15]!==o||t[16]!==s||t[17]!==c||t[18]!==l||t[19]!==f?(p=(0,$.jsxs)(`span`,{"aria-label":o,className:s,style:c,children:[l,f]}),t[15]=o,t[16]=s,t[17]=c,t[18]=l,t[19]=f,t[20]=p):p=t[20];let m;return t[21]!==u||t[22]!==p?(m=(0,$.jsx)(`div`,{className:u,children:p}),t[21]=u,t[22]=p,t[23]=m):m=t[23],m};function au(e){return e.sidebarBrandName}function ou(){xi()}var su=e=>{let t=(0,zc.c)(25),{className:n}=e,{t:r}=qe(),i=K(cu),a=K(lu),o;t[0]===a?o=t[1]:(o=la(Oa(`open_command_palette`,a)),t[0]=a,t[1]=o);let s=o,c;t[2]===i?c=t[3]:(c=()=>i(!0),t[2]=i,t[3]=c);let l;t[4]===r?l=t[5]:(l=r(`commandPalette.title`),t[4]=r,t[5]=l);let u;t[6]===n?u=t[7]:(u=Y(`app-region-no-drag size-7 rounded-md text-muted-foreground/75 focus-visible:ring-2 focus-visible:ring-primary`,n),t[6]=n,t[7]=u);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`search`,className:`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),t[8]=d):d=t[8];let f;t[9]!==c||t[10]!==l||t[11]!==u?(f=(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`icon`,onClick:c,"aria-label":l,className:u,children:d})}),t[9]=c,t[10]=l,t[11]=u,t[12]=f):f=t[12];let p;t[13]===r?p=t[14]:(p=r(`commandPalette.title`),t[13]=r,t[14]=p);let m;t[15]===p?m=t[16]:(m=(0,$.jsx)(`span`,{children:p}),t[15]=p,t[16]=m);let h;t[17]===s?h=t[18]:(h=(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:s}),t[17]=s,t[18]=h);let g;t[19]!==m||t[20]!==h?(g=(0,$.jsx)(ra,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[m,h]})}),t[19]=m,t[20]=h,t[21]=g):g=t[21];let _;return t[22]!==g||t[23]!==f?(_=(0,$.jsxs)(aa,{children:[f,g]}),t[22]=g,t[23]=f,t[24]=_):_=t[24],_};function cu(e){return e.setCommandPaletteOpen}function lu(e){return e.shortcutOverrides}var uu=`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`,du=()=>{let e=(0,zc.c)(46),{t}=qe(),n=K(fu),r=K(pu),i=K(mu),a=K(hu),o=as(gu),s=Q.useRef(null),c=la(Oa(`toggle_sidebar`,a)),{usesFramelessChrome:l,side:u}=xs(),d;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=E(),e[0]=d):d=e[0];let f=d,p=!f||!n||!o,h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=A()&&!f&&!m(),e[1]=h):h=e[1];let g=h,_=vu,v,y;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(v=()=>{if(typeof document>`u`)return;let e=s.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect().width;document.documentElement.style.setProperty(`--oc-titlebar-controls-width`,`${Math.round(t)}px`)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},y=[],e[2]=v,e[3]=y):(v=e[2],y=e[3]),Q.useEffect(v,y);let b=g&&n?`${r||260}px`:void 0,x;e[4]===b?x=e[5]:(x={height:`var(--oc-header-height, 3rem)`,paddingLeft:`var(--oc-titlebar-left-inset, 0.75rem)`,width:b},e[4]=b,e[5]=x);let S=g&&n&&`w-full justify-between`,C;e[6]===S?C=e[7]:(C=Y(`flex items-center gap-2`,S),e[6]=S,e[7]=C);let w;e[8]===n?w=e[9]:(w=g&&n?(0,$.jsx)(iu,{className:`flex min-w-0 items-center p-0`}):null,e[8]=n,e[9]=w);let T;e[10]!==l||e[11]!==u?(T=l&&u===`left`?(0,$.jsx)(bs,{visible:!0,position:`left`}):null,e[10]=l,e[11]=u,e[12]=T):T=e[12];let D;e[13]!==t||e[14]!==l?(D=l?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":t(`header.actions.openAppMenuAria`),className:Y(uu,`shrink-0`),children:(0,$.jsx)(X,{name:`menu-2`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(ra,{children:(0,$.jsx)(`p`,{children:t(`header.actions.openAppMenu`)})})]}):null,e[13]=t,e[14]=l,e[15]=D):D=e[15];let O;e[16]===p?O=e[17]:(O=p?(0,$.jsx)(su,{}):null,e[16]=p,e[17]=O);let k=aa,j;e[18]===t?j=e[19]:(j=t(`header.actions.openSessionsAria`),e[18]=t,e[19]=j);let M,N;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(M=Y(uu,`group shrink-0`),N=(0,$.jsx)(X,{name:`layout-left-rounded`,className:`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`}),e[20]=M,e[21]=N):(M=e[20],N=e[21]);let P;e[22]!==j||e[23]!==i?(P=(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,"aria-label":j,className:M,children:N})}),e[22]=j,e[23]=i,e[24]=P):P=e[24];let F=ra,I=t(`header.actions.openSessionsWithShortcut`,{shortcut:c}),ee;e[25]===I?ee=e[26]:(ee=(0,$.jsx)(`p`,{children:I}),e[25]=I,e[26]=ee);let L;e[27]!==F||e[28]!==ee?(L=(0,$.jsx)(F,{children:ee}),e[27]=F,e[28]=ee,e[29]=L):L=e[29];let R;e[30]!==k||e[31]!==P||e[32]!==L?(R=(0,$.jsxs)(k,{children:[P,L]}),e[30]=k,e[31]=P,e[32]=L,e[33]=R):R=e[33];let z;e[34]!==O||e[35]!==R?(z=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[O,R]}),e[34]=O,e[35]=R,e[36]=z):z=e[36];let B;e[37]!==T||e[38]!==D||e[39]!==z||e[40]!==C||e[41]!==w?(B=(0,$.jsxs)(`div`,{ref:s,className:C,children:[w,T,D,z]}),e[37]=T,e[38]=D,e[39]=z,e[40]=C,e[41]=w,e[42]=B):B=e[42];let V;return e[43]!==B||e[44]!==x?(V=(0,$.jsx)(`div`,{className:`app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2`,style:x,children:B}),e[43]=B,e[44]=x,e[45]=V):V=e[45],V};function fu(e){return e.isSidebarOpen}function pu(e){return e.sidebarWidth}function mu(e){return e.toggleSidebar}function hu(e){return e.shortcutOverrides}function gu(e){return e.sidebarBrandName.trim().length>0}function _u(e){console.warn(`[titlebar] failed to open app menu`,e)}function vu(e){let t=e.currentTarget.getBoundingClientRect();ee(`desktop_show_app_menu`,{x:t.left,y:t.bottom}).catch(_u)}var yu=420,bu=({isOpen:e,children:t,className:n})=>{let{t:r}=qe(),i=K(e=>e.rightSidebarWidth),a=K(e=>e.setRightSidebarWidth),[o,s]=Q.useState(!1),c=Q.useRef(0),l=Q.useRef(i||yu),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(`--oc-right-sidebar-width`,`${e}px`))},[]),h=Math.min(860,Math.max(360,i||yu)),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:Y(`relative flex h-full overflow-hidden oc-layout-divider-l will-change-[width] motion-reduce:transition-none`,`bg-sidebar`,!e&&`border-l-0`,n),style:{width:`${b}px`,"--oc-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:Y(`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:Y(`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(--oc-right-sidebar-width)`},"aria-hidden":!e,children:e?t:null})]})},xu=12,Su=[{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`}],Cu=e=>{let t=(0,zc.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?Su: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:xu},wu),t[4]=m):m=t[4];let h=m;if(!n)return null;let g;t[5]===i?g=t[6]:(g=Y(`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/xu;return{x:Math.cos(n),y:Math.sin(n),delay:t*18}}var Tu=e=>{let t=(0,zc.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(Eu)},t[4]=d):d=t[4];let f=d,p;t[5]===i?p=t[6]:(p=()=>{u(),s(Du),c.current=window.setTimeout(()=>{s(Ou),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 Eu(e){return e.isActive?{...e,isActive:!1}:e}function Du(e){return{isActive:!0,cycle:e.cycle+1}}function Ou(e){return e.isActive?{...e,isActive:!1}:e}var ku=Q.createContext(void 0),Au=e=>{let t=(0,zc.c)(10),{children:n}=e,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=Tu(),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)(Cu,{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)(ku.Provider,{value:c,children:[n,l]}),t[6]=n,t[7]=l,t[8]=c,t[9]=u):u=t[9],u},ju=()=>{let e=Q.useContext(ku);if(!e)throw Error(`useFireworksCelebration must be used within FireworksProvider`);return e},Mu=`gitmojiCache`,Nu=6048e5,Pu=`1`,Fu=`https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json`,Iu=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.emoji==`string`&&typeof t.code==`string`&&typeof t.description==`string`},Lu=()=>{if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(Mu);if(!e)return null;let t=JSON.parse(e);return!t||t.version!==Pu||typeof t.fetchedAt!=`number`||!Array.isArray(t.gitmojis)?null:{gitmojis:t.gitmojis.filter(Iu),fetchedAt:t.fetchedAt,version:t.version}}catch{return null}},Ru=e=>{if(!(typeof window>`u`))try{let t={gitmojis:e,fetchedAt:Date.now(),version:Pu};window.localStorage.setItem(Mu,JSON.stringify(t))}catch{return}},zu=e=>Date.now()-e.fetchedAt<Nu,Bu=null,Vu=new Set,Hu=async()=>{if(Bu)return Bu;let e=(async()=>{try{let e=await fetch(Fu);if(!e.ok)throw Error(`Failed to load gitmojis: ${e.statusText}`);let t=await e.json(),n=Array.isArray(t.gitmojis)?t.gitmojis.filter(Iu):[];return Ru(n),Vu.forEach(e=>e(n)),n}catch(e){console.warn(`Failed to load gitmoji list:`,e);let t=[];return Vu.forEach(e=>e(t)),t}finally{Bu=null}})();return Bu=e,e},Uu=e=>{let[t,n]=Q.useState(()=>e?Lu()?.gitmojis??[]:[]),[r,i]=Q.useState(!1),a=Q.useRef(e);return a.current=e,Q.useEffect(()=>{if(!e){Vu.delete(n),n([]),i(!1);return}let t=Lu();if(t&&(n(t.gitmojis),zu(t)))return;Vu.add(n),i(!0);let r=!1;return Hu().finally(()=>{!r&&a.current&&i(!1)}),()=>{r=!0,Vu.delete(n)}},[e]),{gitmojis:t,isLoading:r,ensureLoaded:Q.useCallback(async()=>{if(!a.current)return[];if(t.length>0)return t;let e=Lu();return e&&zu(e)?e.gitmojis:Hu()},[t])}},Wu=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)};function Gu(e,t,n){let r=(0,zc.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([sr(e),Xn(e)]).catch(Ku);if(r)return;let o=Wu(t),s=Wu(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 Ku(){return[``,``]}var qu=({open:e,onOpenChange:t,directory:n,hasUncommittedChanges:r,hasStagedChanges:i=!1,uncommittedFileCount:a,onChanged:o})=>{let{t:s}=qe(),[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 Zn(n);l(e.stashes),y({})}catch(e){J.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 nr(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 er(n,{message:m.trim()||void 0});e.created?(J.success(s(`gitView.stashes.toast.created`)),h(``)):J.info(s(`gitView.stashes.toast.noChanges`)),await S({affectsIndex:!!(e.created&&i)})}catch(e){J.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 fr(n,{ref:e.ref}),t===`pop`&&await tr(n,{ref:e.ref}),t===`drop`&&await rr(n,{ref:e.ref});let r=t===`apply`?`gitView.stashes.toast.applySuccess`:t===`pop`?`gitView.stashes.toast.popSuccess`:`gitView.stashes.toast.dropSuccess`;J.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`;J.error(e instanceof Error?e.message:s(n)),await S({affectsIndex:t!==`drop`})}finally{_(null)}}},T=g!==null;return(0,$.jsx)(Vn,{open:e,onOpenChange:t,children:(0,$.jsxs)(Rn,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(In,{children:[(0,$.jsxs)(zn,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`h-5 w-5`}),s(`gitView.stashes.title`)]}),(0,$.jsx)(Bn,{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)(ta,{value:m,onChange:e=>h(e.target.value),placeholder:s(`gitView.stashes.messagePlaceholder`),disabled:T||!r,className:`flex-1`}),(0,$.jsxs)(Z,{onClick:C,disabled:!r||T||!n,children:[g===`create`?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{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)(X,{name:`search`,className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(ta,{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)(X,{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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{children:t===0&&!f.trim()?s(`gitView.stashes.latestLabel`):s(`gitView.stashes.itemNumber`,{number:t+1})})}),(0,$.jsx)(ra,{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)(Ju,{label:s(`gitView.stashes.actions.apply`),loading:g===`apply:${e.ref}`,onClick:()=>w(e,`apply`),disabled:T,children:(0,$.jsx)(X,{name:`inbox-unarchive`,className:`size-4`})}),(0,$.jsx)(Ju,{label:s(`gitView.stashes.actions.pop`),loading:g===`pop:${e.ref}`,onClick:()=>w(e,`pop`),disabled:T,children:(0,$.jsx)(X,{name:`inbox-unarchive-fill`,className:`size-4`})}),(0,$.jsx)(Ju,{label:s(`gitView.stashes.actions.drop`),loading:g===`drop:${e.ref}`,onClick:()=>w(e,`drop`),disabled:T,destructive:!0,children:(0,$.jsx)(X,{name:`delete-bin`,className:`size-4`})})]})]},e.ref))})]})})},Ju=e=>{let t=(0,zc.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=Y(`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)(X,{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)(na,{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)(ra,{sideOffset:6,children:n}),t[12]=n,t[13]=p);let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(aa,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m},Yu=e=>{let t=(0,zc.c)(16),{onOpenStashes:n}=e,{t:r}=qe(),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(X,{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)(Z,{type:`button`,variant:`outline`,size:`sm`,onClick:n,className:`gap-1.5`,children:[(0,$.jsx)(X,{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},Xu=8,Zu=e=>{let t=(0,zc.c)(18),{laned:n,totalLanes:r,isExpanded:i}=e,{lane:a,color:o,connectors:s}=n,c=Math.max(r,a+1)*Xu+Xu/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*Xu+Xu/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($u);for(let e of g){let t=e.fromLane*Xu+Xu/2,r=e.toLane*Xu+Xu/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 Qu(e){return e===`branch-out`||e===`merge-in`}function $u(e,t){let n=Qu;return!!n(e.type)-+!!n(t.type)}var ed=15e3,td=500,nd=12,rd=8388608,id=e=>typeof e==`string`?0:(e.original?.length??0)+(e.modified?.length??0),ad=e=>{if(e.size<=nd){let t=0;for(let n of e.values())t+=id(n);if(t<=rd)return e}let t=Array.from(e.entries()).reverse(),n=new Map,r=0;for(let[e,i]of t){if(n.size>=nd)continue;let t=id(i);r+t>rd&&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:Da(n,t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function sd(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 cd(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 ld=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}=qe(),p=K(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 dr(l,e.hash),J.success(f(`gitView.history.actions.detachedHead`)),d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},A=async()=>{if(!(!l||!y.trim())){g(`createBranch`);try{await lr(l,y.trim(),e.hash),v(!1),b(``),d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},j=async()=>{if(l){g(`cherryPick`);try{let t=await ar(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`cherry-pick`}):d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},M=async()=>{if(l){g(`revert`);try{let t=await or(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`revert`}):d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},N=async(t,n=!1)=>{if(!(!l||h!==null)){g(`reset`);try{await $n(l,e.hash,t,n),d?.()}catch(e){J.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 pr(l,{branch:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`merge`}):d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},I=async()=>{if(l){g(`rebase`);try{let t=await Qn(l,{onto:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`rebase`}):d?.()}catch(e){J.error(String(e.message))}finally{g(null)}}},ee=Q.useCallback(async t=>{let n=t.path;if(!l){E(e=>new Map(e).set(n,`error`));return}E(e=>ad(new Map(e).set(n,`loading`)));try{let r=cr(l,e.hash,t.path,!1),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${ed}ms`)),ed)}),a=await Promise.race([r,i]);E(e=>ad(new Map(e).set(n,a)))}catch{E(e=>new Map(e).set(n,`error`))}},[l,e.hash]),L=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>td&&!D.has(t)||await ee(e))},[T,D,ee,C]);return(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:a,className:Y(`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)(Zu,{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=cd(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:Y(`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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 px-1 shrink-0`,onClick:t=>{t.stopPropagation(),c(e.hash)},children:(0,$.jsx)(X,{name:`file-copy`,className:`size-3`})})}),(0,$.jsx)(ra,{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)(Z,{variant:`destructive`,size:`xs`,className:`h-6 shrink-0`,disabled:h!==null,onClick:e=>{e.stopPropagation(),P()},children:[h===null?null:(0,$.jsx)(X,{name:`loader-4`,className:`size-3 animate-spin mr-1`}),f(`gitView.history.actions.confirmButton`)]}),(0,$.jsx)(Z,{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)(Z,{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)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:!y.trim()||h!==null,onClick:e=>{e.stopPropagation(),A()},children:[h===`createBranch`?(0,$.jsx)(X,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.createBranchConfirm`)]})]}):(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,onClick:e=>{e.stopPropagation(),v(!0)},children:f(`gitView.history.actions.createBranch`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`cherryPick`)},children:f(`gitView.history.actions.cherryPick`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`revert`)},children:f(`gitView.history.actions.revert`)}),(0,$.jsxs)(ha,{children:[(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>e.stopPropagation(),children:[h===`reset`?(0,$.jsx)(X,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.reset`)]})}),(0,$.jsx)(ca,{align:`start`,className:`min-w-max`,children:[`soft`,`mixed`,`hard`].map(e=>(0,$.jsx)(ua,{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)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:h!==null,onClick:e=>{e.stopPropagation(),S(`merge`)},children:f(`gitView.history.actions.merge`)}),(0,$.jsx)(Z,{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)(X,{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:()=>L(e),className:Y(`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:Y(`font-semibold w-3 text-center shrink-0`,sd(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)(X,{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>td)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)(Z,{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)),ee(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:()=>L(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)(Rs,{original:n.original,modified:n.modified,language:To(e.path)||``,fileName:e.path,renderSideBySide:!1,layout:`inline`,enableComments:!1})})()})]},e.path))})]})]})}),ud=[`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 dd(e){return ud[e%ud.length]}function fd(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=dd(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:dd(e),type:`merge-in`}),t[e]=null;for(let e of d)f.push({fromLane:o,toLane:e,color:dd(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:dd(e),type:`passing`}));n.push({commit:i,lane:o,color:c,connectors:f})}return n}var pd=[{labelKey:`gitView.history.logSize25`,value:25},{labelKey:`gitView.history.logSize50`,value:50},{labelKey:`gitView.history.logSize100`,value:100}],md=e=>{let t=(0,zc.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}=qe(),[C,w]=Q.useState(!0),T=v===`graph`,E;t[0]!==T||t[1]!==r?(E=T&&r?fd(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(hd)),t[3]=D,t[4]=O);let k=O,A;t[5]===D?A=t[6]:(A=new Map(D.map(gd)),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,ee;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)(X,{name:`arrow-down-s`,className:`size-3.5`}):(0,$.jsx)(X,{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)(ld,{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)(Z,{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)(X,{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;ee=(0,$.jsx)(so,{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]=ee}else ee=t[34];let L=ee;if(!y){if(P){let e;return t[56]===L?e=t[57]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0`,children:L}),t[56]=L,t[57]=e),e}let e;return t[58]===L?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:L}),t[58]=L,t[59]=e),e}let R;t[60]===S?R=t[61]:(R=S(`gitView.history.title`),t[60]=S,t[61]=R);let z;t[62]===R?z=t[63]:(z=(0,$.jsx)(`h3`,{className:`typography-ui-header font-semibold text-foreground`,children:R}),t[62]=R,t[63]=z);let B;t[64]!==i||t[65]!==C||t[66]!==a||t[67]!==o||t[68]!==S?(B=C&&(0,$.jsx)(`div`,{onClick:_d,onPointerDown:vd,children:(0,$.jsxs)(Xi,{value:String(a),onValueChange:e=>o(Number(e)),disabled:i,children:[(0,$.jsx)(Gi,{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)(ea,{placeholder:S(`gitView.history.commitsPlaceholder`)})}),(0,$.jsx)(qi,{children:pd.map(e=>(0,$.jsx)(Ui,{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]=B):B=t[69];let V;t[70]===C?V=t[71]:(V=C?(0,$.jsx)(X,{name:`arrow-up-s`,className:`size-4 text-muted-foreground`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-4 text-muted-foreground`}),t[70]=C,t[71]=V);let H;t[72]!==B||t[73]!==V?(H=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B,V]}),t[72]=B,t[73]=V,t[74]=H):H=t[74];let te;t[75]!==z||t[76]!==H?(te=(0,$.jsxs)(xc,{className:`flex w-full items-center justify-between px-3 h-10 hover:bg-transparent`,children:[z,H]}),t[75]=z,t[76]=H,t[77]=te):te=t[77];let U;t[78]===L?U=t[79]:(U=(0,$.jsx)(bc,{children:L}),t[78]=L,t[79]=U);let ne;return t[80]!==C||t[81]!==te||t[82]!==U?(ne=(0,$.jsxs)(Sc,{open:C,onOpenChange:w,className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[te,U]}),t[80]=C,t[81]=te,t[82]=U,t[83]=ne):ne=t[83],ne};function hd(e){return e.lane+1}function gd(e){return[e.commit.hash,e]}function _d(e){return e.stopPropagation()}function vd(e){return e.stopPropagation()}var yd=e=>{let t=(0,zc.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}=qe(),f=Pt(bd),p=Pt(xd),m=Tn(Sd),h=Tn(Cd),g=K(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),ir(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 yt(`git.conflict.resolve.visible`,{operation_label:e,head_ref:t}),instructionsText:await yt(`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){J.error(d(`gitView.conflict.noDetailsAvailable`));return}if(!p){J.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){J.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,ee,L,R,z,B,V,H,te,U,ne,W,re,G,ie,ae,oe,se,ce,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;ee=Vn,le=n,ue=r,I=Rn,ce=`max-w-md w-[calc(100vw-2rem)]`,re=`flex flex-col gap-4 overflow-hidden`;let a;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{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)(zn,{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)(Bn,{children:c}),t[73]=c,t[74]=l),t[75]!==s||t[76]!==l?(G=(0,$.jsxs)(In,{children:[s,l]}),t[75]=s,t[76]=l,t[77]=G):G=t[77],t[78]!==_||t[79]!==d?(ie=_&&(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-4 text-muted-foreground`,children:[(0,$.jsx)(X,{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]=ie):ie=t[80],t[81]!==x||t[82]!==d?(ae=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]=ae):ae=t[83],t[84]!==i||t[85]!==d?(oe=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(Td)})})]}),t[84]=i,t[85]=d,t[86]=oe):oe=t[86],t[87]!==y||t[88]!==d?(se=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]=se):se=t[89],U=`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)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{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?(ne=(0,$.jsxs)(Z,{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]=ne):ne=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)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{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?(W=(0,$.jsxs)(Z,{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]=W):W=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)(Z,{variant:`ghost`,size:`sm`,onClick:A,className:`flex-1`,children:w}),t[114]=A,t[115]=w,t[116]=te):te=t[116],F=Z,L=`destructive`,R=`sm`,z=O,B=`flex-1`,V=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]=ee,t[50]=L,t[51]=R,t[52]=z,t[53]=B,t[54]=V,t[55]=H,t[56]=te,t[57]=U,t[58]=ne,t[59]=W,t[60]=re,t[61]=G,t[62]=ie,t[63]=ae,t[64]=oe,t[65]=se,t[66]=ce,t[67]=le,t[68]=ue}else F=t[47],I=t[48],ee=t[49],L=t[50],R=t[51],z=t[52],B=t[53],V=t[54],H=t[55],te=t[56],U=t[57],ne=t[58],W=t[59],re=t[60],G=t[61],ie=t[62],ae=t[63],oe=t[64],se=t[65],ce=t[66],le=t[67],ue=t[68];let de;t[117]!==F||t[118]!==L||t[119]!==R||t[120]!==z||t[121]!==B||t[122]!==V?(de=(0,$.jsx)(F,{variant:L,size:R,onClick:z,className:B,children:V}),t[117]=F,t[118]=L,t[119]=R,t[120]=z,t[121]=B,t[122]=V,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]!==U||t[129]!==ne||t[130]!==W||t[131]!==fe?(pe=(0,$.jsxs)(`div`,{className:U,children:[ne,W,fe]}),t[128]=U,t[129]=ne,t[130]=W,t[131]=fe,t[132]=pe):pe=t[132];let me;t[133]!==re||t[134]!==G||t[135]!==ie||t[136]!==ae||t[137]!==oe||t[138]!==se||t[139]!==pe?(me=(0,$.jsxs)(`div`,{className:re,children:[G,ie,ae,oe,se,pe]}),t[133]=re,t[134]=G,t[135]=ie,t[136]=ae,t[137]=oe,t[138]=se,t[139]=pe,t[140]=me):me=t[140];let he;t[141]!==I||t[142]!==ce||t[143]!==me?(he=(0,$.jsx)(I,{className:ce,children:me}),t[141]=I,t[142]=ce,t[143]=me,t[144]=he):he=t[144];let ge;return t[145]!==ee||t[146]!==le||t[147]!==ue||t[148]!==he?(ge=(0,$.jsx)(ee,{open:le,onOpenChange:ue,children:he}),t[145]=ee,t[146]=le,t[147]=ue,t[148]=he,t[149]=ge):ge=t[149],ge};function bd(e){return e.openNewSessionDraft}function xd(e){return e.currentSessionId}function Sd(e){return e.setPendingInputText}function Cd(e){return e.setPendingSyntheticParts}function wd(e){return e.setActiveMainTab}function Td(e){return(0,$.jsx)(`li`,{className:`typography-micro text-foreground font-mono truncate block`,title:e,children:e},e)}var Ed=({mergeInProgress:e,rebaseInProgress:t,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{let{t:s}=qe(),[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)(X,{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)(Z,{variant:`outline`,size:`sm`,onClick:i,disabled:h||o,className:`gap-1.5`,children:[(0,$.jsx)(X,{name:`sparkling`,className:`size-4`}),s(`gitView.operation.resolveWithAi`)]}),c!==`continue`&&(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:m,disabled:h||o,className:`gap-1.5`,children:[c===`abort`?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`close`,className:`size-4`}),s(`gitView.operation.abort`)]}),!a&&(0,$.jsxs)(Z,{variant:`default`,size:`sm`,onClick:p,disabled:h||o,className:`gap-1.5`,children:[c===`continue`?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{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`)})]})})},Dd=({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}},Od=15e3,kd=40,Ad=20,jd={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:`},Md=(e,t)=>{let n=e.toLowerCase(),r=n.match(/^([a-z]+)(?:\(.*\))?!?:/);if(r){let e=jd[r[1]];if(e)return t.find(t=>t.code===e)||null}let i=jd[n.split(` `)[0]];return i&&t.find(e=>e.code===i)||null},Nd=20,Pd=new Map,Fd=(e,t)=>{if(Pd.delete(e),Pd.set(e,t),Pd.size>Nd){let e=Pd.keys().next().value;e!==void 0&&Pd.delete(e)}},Id=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),Ld=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},Rd=e=>{let t=e.working_dir?.trim(),n=e.index?.trim();return!!(t||n===`?`)},zd=({isActive:e})=>{let{t}=qe(),{git:n}=za(),r=jo(),[i,a]=Q.useState(null),[o,s]=Q.useState(!1),c=Pt(e=>e.currentSessionId),l=Pt(e=>e.newSessionDraft),u=Pt(e=>e.setDraftBootstrapPendingDirectory),d=Pt(e=>e.worktreeMetadata),f=Pt(e=>e.availableWorktrees),p=Id(r),m=Q.useMemo(()=>{if(!p)return;let e=f.find(e=>Id(e.path)===p);if(e)return e;for(let e of d.values())if(Id(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=Xa(r??null),_=Za(r??null),v=Dn(e=>c?e.getAttachment(c):void 0),y=v?Cn(v):[],b=v&&!v.degraded&&!v.legacy?v.worktreeRoot??void 0:void 0,x=Gu(r,h,_?.current??void 0),S=Ja(r??null),C=Ua(r??null),w=Ka(r??null),T=qa(r??null),{setActiveDirectory:E,fetchAll:D,ensureAll:O,fetchStatus:k,fetchBranches:A,fetchLog:j,setLogMaxCount:M,prefetchDiffs:N,moveStatusPathsOptimistically:P,restoreStatus:F,bumpIndexRevision:I}=Wa(ce(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}))),ee=K(e=>e.isMobile),L=K(e=>e.openContextFileDiff),R=K(e=>e.navigateToDiff),z=K(e=>e.setRightSidebarOpen),B=Q.useRef(null),V=Q.useRef(null),H=Q.useRef(null),te=Q.useRef(null),U=Q.useRef(!0);Q.useEffect(()=>()=>{U.current=!1},[]);let ne=Q.useCallback(()=>{V.current!==null&&(window.clearTimeout(V.current),V.current=null)},[]),W=Q.useCallback(e=>{ne(),V.current=window.setTimeout(()=>{V.current=null,Id(e)===Id(r)&&k(e,n,{silent:!0})},Od)},[ne,r,k,n]);Q.useEffect(()=>ne,[ne]);let re=Q.useCallback(()=>{H.current!==null&&(window.clearTimeout(H.current),H.current=null)},[]),G=Q.useCallback(()=>{H.current===null&&(H.current=window.setTimeout(()=>{H.current=null,te.current?.()},0))},[]),ie=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]),ae=Q.useMemo(()=>Dd({runMutation:({directory:e,direction:t,paths:n})=>ie(e,t,n),onMutationComplete:({directory:e})=>{I(e),W(e)},onMutationError:({directory:e,direction:n,rollback:r},i)=>{r?.(),I(e),W(e);let a=t(n===`stage`?`gitView.toast.stageFileFailed`:`gitView.toast.unstageFileFailed`);J.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:G}),[I,ie,G,W,t]);Q.useEffect(()=>(te.current=ae.flush,()=>{te.current=null}),[ae]),Q.useEffect(()=>()=>ae.clear(),[ae]),Q.useEffect(()=>re,[re]),Q.useEffect(()=>{if(!e)return;if(!r){a(null),s(!1);return}let t=!1,n=rt(r);n&&a(n.status);let i=Tt((e,n)=>{t||Id(e)===Id(r)&&a(n.status)});return mr(r).then(e=>{if(t)return;bt(r,e);let n=rt(r);a(n?.status??e.status)}).catch(()=>{!t&&!rt(r)&&a(null)}),()=>{t=!0,i()}},[e,r]),Q.useEffect(()=>{let e=B.current;B.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 oe=Id(l?.bootstrapPendingDirectory??null),se=!!(r&&oe&&oe===Id(r)),le=!!(r&&(i===`pending`||se))||o,ue=Q.useMemo(()=>r?Pd.get(r)??null:null,[r]),de=Et(e=>e.settingsGitmojiEnabled),[fe,pe]=Q.useState(null),{gitmojis:me}=Uu(de);Q.useEffect(()=>{let e=b||x?.projectDirectory;if(!e){pe(null);return}let t=!1;return Ki(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(ue?.commitMessage??``),[_e,ve]=Q.useState([]),[ye,be]=Q.useState(!1),xe=$s(_)&&!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}=ju(),[Pe,q]=Q.useState(new Set),[Fe,Ie]=Q.useState(new Set),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(ue?.generatedHighlights??[]),Ue=Fe.size>0||ae.size()>0||ae.isRunning(),We=Q.useCallback(()=>{let e=we.current;e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.scrollTo({top:e.scrollHeight,behavior:`smooth`})})})},[]),Ge=Q.useCallback(()=>{He([])},[]),[Ke,Je]=Q.useState(new Set),[Ye,Ze]=Q.useState(new Map),[Qe,$e]=Q.useState(new Set),et=Q.useRef(Ye),tt=Q.useRef(Qe),[nt,it]=Q.useState(null),[at,ot]=Q.useState(null),[st,ct]=Q.useState(``),[lt,ut]=Q.useState(null),[dt,ft]=Q.useState([]),[pt,mt]=Q.useState(!1),[ht,gt]=Q.useState([]),[_t,vt]=Q.useState(`merge`),[yt,xt]=Q.useState(null),[St,wt]=Q.useState(!1),[Ot,kt]=Q.useState(100),At=Q.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),jt=Q.useCallback((e,t,n)=>{if(!At||typeof window>`u`)return;let r={directory:e,conflictFiles:t,operation:n};window.localStorage.setItem(At,JSON.stringify(r))},[At]),Mt=Q.useCallback(()=>{!At||typeof window>`u`||window.localStorage.removeItem(At)},[At]);Q.useEffect(()=>{if(!At||typeof window>`u`||!r)return;let e=window.localStorage.getItem(At);if(e)try{let t=JSON.parse(e);if(t.directory!==r){window.localStorage.removeItem(At);return}gt(t.conflictFiles??[]),vt(t.operation??`merge`),mt(!0)}catch{window.localStorage.removeItem(At)}},[At,r]);let Nt=Q.useCallback(e=>{Xe(e).then(e=>{if(e.ok){J.success(t(`gitView.toast.commitHashCopied`));return}J.error(t(`gitView.toast.copyFailed`))})},[t]),Ft=Q.useCallback(e=>{Je(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);Q.useEffect(()=>{et.current=Ye},[Ye]),Q.useEffect(()=>{tt.current=Qe},[Qe]),Q.useEffect(()=>{if(!r||!n)return;let e=Array.from(Ke).filter(e=>!et.current.has(e)&&!tt.current.has(e));if(e.length===0)return;let t=!1;return $e(t=>{let n=new Set(t);for(let t of e)n.add(t);return tt.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||(Ze(t=>{let n=new Map(t);for(let{hash:t,files:r}of e)n.set(t,r);return et.current=n,n}),$e(t=>{let n=new Set(t);for(let{hash:t}of e)n.delete(t);return tt.current=n,n}))}),()=>{t=!0,$e(t=>{let n=!1,r=new Set(t);for(let t of e)r.delete(t)&&(n=!0);return n?(tt.current=r,r):t})}},[Ke,r,n]),Q.useEffect(()=>{r&&Fd(r,{directory:r,commitMessage:he,generatedHighlights:Ve})},[he,r,Ve]),Q.useEffect(()=>{if(!e)return;if(!r||!n?.getRemoteUrl){ot(null);return}let t=!1;return n.getRemoteUrl(r).then(e=>{t||ot(e)}).catch(()=>{t||ot(null)}),()=>{t=!0}},[e,r,n]);let It=Q.useCallback(async()=>{if(!r||!n?.getRemotes){ft([]);return}try{let e=await n.getRemotes(r);U.current&&ft(e)}catch{U.current&&ft([])}},[r,n]);Q.useEffect(()=>{e&&It()},[e,It]),Q.useEffect(()=>{e&&r&&(E(r),O(r,n))},[e,r,E,O,n]),Q.useEffect(()=>{if(e&&r)return Ct.onGitRefreshHint(e=>{Id(e.directory)===Id(r)&&k(r,n)})},[e,r,k,n]);let Lt=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`);J.error(e)}}},[r,n,k,A,t]),Rt=Q.useCallback(async()=>{r&&await j(r,n,je)},[r,n,j,je]),zt=Q.useMemo(()=>!_||xe?[]:[..._.files??[]].sort((e,t)=>e.path.localeCompare(t.path)),[_,xe]),Bt=Q.useMemo(()=>zt.filter(Ld),[zt]),Vt=Q.useMemo(()=>zt.filter(Rd),[zt]),{deferredStagedCount:Ht,deferredUnstagedCount:Ut}=Q.useMemo(()=>{if(!xe||!_)return{deferredStagedCount:0,deferredUnstagedCount:0};let e=0,t=0;for(let n of _.files??[])Ld(n)&&(e+=1),Rd(n)&&(t+=1);return{deferredStagedCount:e,deferredUnstagedCount:t}},[xe,_]);Q.useEffect(()=>{if(!r||zt.length===0)return;let e=[],t=new Set,i=n=>{!n||t.has(n)||(t.add(n),e.push(n))};if(Bt.forEach(e=>i(e.path)),_e.forEach(i),zt.slice(0,Ad).forEach(e=>i(e.path)),e.length===0)return;let a=window.setTimeout(()=>{N(r,n,e,{maxFiles:kd})},120);return()=>{window.clearTimeout(a)}},[zt,r,n,N,Bt,_e]);let Wt=e=>e?.pushed[0]?.remote||_?.tracking?.split(`/`)[0]||en.find(e=>e.name===`origin`)?.name||en[0]?.name||`origin`,Gt=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}),J.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));J.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);J.success(t(`gitView.toast.pushedToUpstream`,{name:Wt(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){J.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?J.success(t(e===1?`gitView.toast.syncedPulledSingleAndPushed`:`gitView.toast.syncedPulledPluralAndPushed`,{count:e,name:i.name})):e>0?J.success(t(e===1?`gitView.toast.pulledFilesSingle`:`gitView.toast.pulledFilesPlural`,{count:e,name:i.name})):o?J.success(t(`gitView.toast.pushedToUpstream`,{name:i.name})):J.success(t(`gitView.toast.alreadyUpToDate`))}await Lt(!1),await Rt()}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});J.error(r)}finally{Ee(null)}}},Kt=async(e={})=>{if(!r)return;if(!he.trim()){J.error(t(`gitView.toast.enterCommitMessage`));return}let i=Bt.map(e=>e.path).sort();if(i.length===0){J.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),J.success(t(`gitView.toast.commitCreated`)),ge(``),Ge(),await Lt(),e.pushAfter){let e=_?.tracking?.split(`/`)[0],i=en.find(t=>t.name===e)??en[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){J.error(t(`gitView.toast.commitOrStashBeforeSync`)),await Lt(!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)),J.success(t(`gitView.toast.pushedToUpstream`,{name:Wt(l)})),Ne(),await Lt(!1)}else await Lt(!1);await Rt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createCommitFailed`);J.error(n)}finally{Ae(null),e.pushAfter&&Ee(null)}},qt=Q.useCallback(async()=>{if(!r)return;let e=Bt.map(e=>e.path).sort();if(e.length===0){J.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 ur(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=Md(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`);J.error(n)}finally{Be(!1)}},[r,Bt,de,me,We,t]),Jt=e=>e.reason===`attention`?`${e.attentionReason} in progress`:e.reason===`missing`?`worktree is missing`:`worktree is invalid`,Yt=async(e,i)=>{if(!r||!_)return;let a=Dt(v);if(a.length>0){J.error(t(`gitView.toast.cannotCreateBranch`,{reason:Jt(a[0])}));return}let o=_.current??null,s=i?.name??`origin`;try{await n.createBranch(r,e,o??`HEAD`),J.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}.`;J.warning(t(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsxs)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:[`Upstream setup failed: `,n]})})}await Lt(),await Rt(),i&&J.success(t(`gitView.toast.upstreamSet`,{branch:e,remote:s}))}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createBranchFailed`);throw J.error(n),e}},Xt=async(e,i)=>{if(!r)return;let a=Dt(v);if(a.length>0){J.error(t(`gitView.toast.cannotRenameBranch`,{reason:Jt(a[0])}));return}try{await n.renameBranch(r,e,i),J.success(t(`gitView.toast.renamedBranch`,{oldName:e,newName:i})),await Lt(),await Rt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.renameBranchFailed`,{oldName:e,newName:i});J.error(r)}},Zt=async e=>{if(!r)return;let i=Dt(v);if(i.length>0){J.error(t(`gitView.toast.cannotCheckout`,{reason:Jt(i[0])}));return}let a=e.replace(/^remotes\//,``);if(_?.current!==a)try{await n.checkoutBranch(r,a),J.success(t(`gitView.toast.checkedOut`,{name:a})),await Lt(),await Rt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.checkoutFailed`,{name:a});J.error(n)}},Qt=Q.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),$t=Q.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),en=Q.useMemo(()=>{if(dt.length>0)return dt;let e=new Set,t=_?.tracking?.trim();t&&t.includes(`/`)&&e.add(t.split(`/`)[0]);for(let t of $t){let n=t.indexOf(`/`);n>0&&e.add(t.slice(0,n))}return e.size===0&&at&&e.add(`origin`),Array.from(e).map(e=>({name:e,fetchUrl:at??``,pushUrl:at??``}))},[dt,$t,at,_?.tracking]),tn=Q.useMemo(()=>{let e=new Set(en.map(e=>e.name)),t=t=>{if(!t)return``;let n=t.trim();if(!n||n===`HEAD`)return``;if(Qt.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:``)||(Qt.includes(`main`)?`main`:Qt.includes(`master`)?`master`:Qt.includes(`develop`)?`develop`:`main`)},[en,Qt,fe,x?.createdFromBranch]),nn=Bt.length,rn=_?.current??null;Q.useEffect(()=>{if(!r||!n||!C?.all?.length||!rn||!tn||rn===tn){it(null);return}let e=!1;return(async()=>{try{let t=await n.getGitLog(r,{from:tn,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){it(null);return}let a=C.all.findIndex(e=>!i.has(e.hash));if(a===0){it(null);return}if(a===-1){it({insertBeforeIndex:C.all.length,branchName:rn,direction:`up`});return}it({insertBeforeIndex:a,branchName:rn,direction:`up`})}catch{e||it(null)}})(),()=>{e=!0}},[tn,rn,r,n,C,je]),Q.useEffect(()=>{xt(null)},[r]),Q.useEffect(()=>{if(lt!==`graph`||!r){lt!==`graph`&&xt(null);return}let e=!1;return wt(!0),n.getGitLog(r,{maxCount:Ot,all:!0}).then(t=>{e||xt(t)}).catch(e=>{console.error(`Failed to fetch graph log:`,e)}).finally(()=>{e||wt(!1)}),()=>{e=!0}},[lt,r,Ot,n]);let an=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);ae.enqueue({directory:r,direction:t,paths:new Set(n),rollback:()=>F(r,i)}),G()},[r,ae,P,F,G]),on=Q.useCallback(async e=>{if(r){q(t=>{let n=new Set(t);return n.add(e),n});try{await n.revertGitFile(r,e,{scope:`working`}),J.success(t(`gitView.toast.revertedFile`,{path:e})),await Lt(!1)}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.revertFailed`);J.error(n)}finally{q(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,Lt,n,t]),sn=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=>Pe.has(e)))return;let s=new Set(Bt.map(e=>e.path)),c=a===`all`&&o.some(e=>s.has(e));i&&Re(!0),q(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 Lt(!1),l.length===0)J.success(o.length===1?t(`gitView.toast.revertedFilesSingle`,{count:o.length}):t(`gitView.toast.revertedFilesPlural`,{count:o.length}));else if(l.length===o.length)J.error(l[0]?.message||t(`gitView.toast.revertFailed`));else{let e=o.length-l.length;J.warning(t(e===1?`gitView.toast.revertedSomeSingle`:`gitView.toast.revertedSomePlural`,{success:e,failed:l.length}))}}finally{q(e=>{let t=new Set(e);return o.forEach(e=>t.delete(e)),t}),i&&Re(!1)}},[I,r,n,Le,Lt,Pe,Bt,t]),cn=Q.useCallback(async e=>{await sn(e,!0)},[sn]),ln=Q.useCallback(async e=>{await sn(e,!1,`working`)},[sn]),un=Q.useCallback((e,t)=>{if(r&&!ee){L(r,e,t);return}R(e,t),ee&&z(!1)},[r,ee,R,L,z]),dn=Q.useCallback(()=>Oe(!0),[]),fn=Q.useMemo(()=>{let e=[];return Bt.length>0&&e.push({id:`staged`,title:t(`gitView.changes.stagedTitle`),entries:Bt,actionSymbol:`-`,actionAllLabel:t(`gitView.changes.unstageAllAria`),getActionLabel:e=>t(`gitView.changes.unstageFileAria`,{path:e}),onActionFile:e=>void an([e],`unstage`),onActionAll:e=>void an(e,`unstage`),onViewDiff:e=>un(e,!0),onRevertFile:on,showRevertActions:!1,accent:!0}),Vt.length>0&&e.push({id:`unstaged`,title:t(`gitView.changes.title`),entries:Vt,actionSymbol:`+`,actionAllLabel:t(`gitView.changes.stageAllAria`),getActionLabel:e=>t(`gitView.changes.stageFileAria`,{path:e}),onActionFile:e=>void an([e],`stage`),onActionAll:e=>void an(e,`stage`),onViewDiff:e=>un(e,!1),onRevertFile:on}),e},[on,un,an,Bt,t,Vt]),pn=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
|
-
|
|
5
|
-
`:``}${t.join(`
|
|
6
|
-
`)}`.trim()}),Ge()},[Ge]),mn=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()}),ct(``),Ce(!1)},[]),hn=Q.useCallback(async()=>{if(r)try{_t===`merge`?(await n.abortMerge(r),J.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),J.success(t(`gitView.toast.rebaseAborted`))),Mt(),await Lt(),await Rt()}catch(e){let t=e instanceof Error?e.message:`Failed to abort ${_t}`;J.error(t)}},[r,n,_t,Lt,Rt,Mt,t]),gn=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]),_n=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?(gt(e.conflictFiles??[]),vt(`merge`),mt(!0),jt(r,e.conflictFiles??[],`merge`),J.error(t(`gitView.toast.mergeConflictsDetected`))):(Mt(),J.success(t(`gitView.toast.mergeCompleted`)),await Lt(),await Rt())}else if(i){let e=await n.continueRebase(r);e.conflict?(gt(e.conflictFiles??[]),vt(`rebase`),mt(!0),jt(r,e.conflictFiles??[],`rebase`),J.error(t(`gitView.toast.rebaseConflictsDetected`))):(Mt(),J.success(t(`gitView.toast.rebaseStepCompleted`)),await Lt(),await Rt())}}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.continueOperationFailed`);J.error(n)}},[r,n,_,Lt,Rt,jt,Mt,t]),vn=Q.useCallback(async()=>{if(r)try{_?.mergeInProgress?.head?(await n.abortMerge(r),J.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),J.success(t(`gitView.toast.rebaseAborted`))),Mt(),await Lt(),await Rt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.abortOperationFailed`);J.error(n)}},[r,n,_,Lt,Rt,Mt,t]),yn=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&>(t),vt(e),mt(!0)},[r,_]),bn=Q.useCallback(e=>{Me(e),r&&(M(r,e),j(r,n,e))},[r,j,n,M]),xn=Q.useCallback(e=>{kt(e)},[]),Sn=Q.useCallback(()=>{ut(null),r&&(k(r,n),A(r,n,{force:!0}),j(r,n,je))},[r,k,A,j,je,n]),wn=Q.useCallback(e=>{if(e.conflict){if(e.operation===`cherry-pick`||e.operation===`revert`){J.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}gt(e.conflictFiles??[]),vt(e.operation),mt(!0),r&&jt(r,e.conflictFiles??[],e.operation)}},[t,gt,vt,mt,jt,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)(X,{name:`loader-4`,className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{className:`typography-ui-label`,children:t(`gitView.loading.checkingRepository`)})]})});if(g===!1)return le?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-4 text-center`,children:[(0,$.jsx)(X,{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)(X,{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 Tn=_?x?(0,$.jsx)(qs,{currentBranch:_.current,onRename:Xt,iconOnly:!0}):(0,$.jsx)(hr,{currentBranch:_.current,localBranches:Qt,remoteBranches:$t,branchInfo:S?.branches,onCheckout:Zt,onCreate:Yt,remotes:en,iconOnly:!0}):null,En=_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Js,{syncAction:Te,remotes:en,onSync:e=>Gt(`sync`,e),disabled:!_,aheadCount:_.ahead,behindCount:_.behind,trackingRemoteName:_.tracking?.split(`/`)[0],hasUncommittedChanges:(_.files?.length??0)>0}),(0,$.jsxs)(ha,{children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(_a,{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)(X,{name:`git-repository`,className:`size-3.5`})})})}),(0,$.jsx)(ra,{sideOffset:8,children:t(`gitView.header.repositoryViews`)})]}),(0,$.jsxs)(ca,{align:`end`,children:[(0,$.jsxs)(ua,{onSelect:()=>ut(`history`),children:[(0,$.jsx)(X,{name:`history`,className:`size-4`}),t(`gitView.history.title`)]}),(0,$.jsxs)(ua,{onSelect:()=>ut(`graph`),children:[(0,$.jsx)(X,{name:`git-merge`,className:`size-4`}),t(`gitView.graph.title`)]}),(0,$.jsxs)(ua,{onSelect:dn,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`size-4`}),t(`gitView.stashes.title`)]})]})]})]}):null,On=_?(0,$.jsxs)($.Fragment,{children:[Tn,En]}):null;return(0,$.jsxs)(`div`,{className:Y(`flex h-full flex-col overflow-hidden`),children:[r&&(_?.mergeInProgress?.head||_?.rebaseInProgress?.headName||_?.rebaseInProgress?.onto)&&(0,$.jsx)(Ed,{mergeInProgress:_?.mergeInProgress,rebaseInProgress:_?.rebaseInProgress,onContinue:_n,onAbort:vn,onResolveWithAI:yn,hasUnresolvedConflicts:gn,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:Y(`min-w-0 min-h-0 h-full flex flex-col`),children:(0,$.jsx)(so,{as:co,ref:we,outerClassName:`flex-1 min-h-0`,className:Y(`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:On})]}),(0,$.jsx)(dc,{stagedCount:Ht,unstagedCount:Ut,onLoad:()=>be(!0)})]}):(zt?.length??0)>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,$.jsx)(Ws,{groups:fn,diffStats:_?.diffStats,revertingPaths:Pe,isRevertingAll:Le,onVisiblePathsChange:ve,onRevertAll:cn,onRevertDirectory:ln,headerBackgroundClassName:`bg-background`,headerLeadingActions:Tn,headerActions:En})}),(0,$.jsx)(Us,{stagedCount:nn,commitMessage:he,onCommitMessageChange:ge,generatedHighlights:Ve,onInsertHighlights:pn,onGenerateMessage:qt,isGeneratingMessage:ze,onCommit:()=>Kt({pushAfter:!1}),onCommitAndPush:()=>Kt({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:On})]}),(0,$.jsx)(Yu,{onOpenStashes:()=>Oe(!0)})]})})})})})}),(0,$.jsx)(Vn,{open:lt!==null,onOpenChange:e=>{e||ut(null)},children:(0,$.jsxs)(Rn,{className:`max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,$.jsxs)(In,{children:[(0,$.jsx)(zn,{children:t(lt===`graph`?`gitView.graph.title`:`gitView.history.title`)}),(0,$.jsx)(Bn,{children:t(`gitView.history.dialogDescription`)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,$.jsx)(md,{mode:lt===`graph`?`graph`:`history`,log:lt===`graph`?yt??C:C,isLogLoading:lt===`graph`&&St||T,logMaxCount:lt===`graph`?Ot:je,onLogMaxCountChange:lt===`graph`?xn:bn,expandedCommitHashes:Ke,onToggleCommit:Ft,commitFilesMap:Ye,loadingCommitHashes:Qe,onCopyHash:Nt,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:`h-full max-h-none`,branchDivider:lt===`graph`?null:nt,onConflict:lt===`graph`?wn:void 0,onActionSuccess:lt===`graph`?Sn:void 0})})]})}),(0,$.jsx)(qu,{open:De,onOpenChange:Oe,directory:r,hasUncommittedChanges:(_?.files?.length??0)>0,hasStagedChanges:Bt.length>0,uncommittedFileCount:_?.files?.length??0,onChanged:async e=>{r&&e?.affectsIndex&&I(r),await Lt(!1),await Rt()}}),(0,$.jsx)(Vn,{open:Se,onOpenChange:Ce,children:(0,$.jsxs)(Rn,{className:`max-w-md p-0 overflow-hidden`,children:[(0,$.jsx)(In,{className:`px-4 pt-4`,children:(0,$.jsx)(zn,{children:t(`gitView.gitmoji.title`)})}),(0,$.jsxs)(oi,{className:`h-[420px]`,children:[(0,$.jsx)(Di,{placeholder:t(`gitView.gitmoji.searchPlaceholder`),value:st,onValueChange:ct}),(0,$.jsxs)(ni,{children:[(0,$.jsx)(ki,{children:t(`gitView.gitmoji.empty`)}),(0,$.jsx)(Si,{children:(me.length===0?[]:me.filter(e=>{let t=st.trim().toLowerCase();return!t||e.emoji.includes(t)||e.code.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)})).map(e=>(0,$.jsxs)(mi,{onSelect:()=>mn(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)(yd,{open:pt,onOpenChange:mt,conflictFiles:ht,directory:r,operation:_t,onAbort:hn,onClearState:Mt})]})},Bd=(e,t)=>{let n=Fo(t,e);return!n||n===`.`||n===t?0:n.split(`/`).filter(Boolean).length},Vd=(e,t,n=10)=>{let r=Po(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=Po(t.path);if(!e||i.has(e))continue;let o=Bd(r,e);o<1||o>n||(i.add(e),a.push(e))}return a},Hd=e=>e.some(e=>!!Po(e)),Ud=(e,t)=>{let n=new Set(t.map(e=>Po(e)).filter(Boolean));return e.filter(e=>!n.has(e))},Wd=(e,t,n)=>t.length===0?e.length===0:Ud(e,t).length>0?!1:t.every(e=>n.has(Po(e))),Gd=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),Kd=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},qd=(e,t)=>{let n=Kd(t),r=Kd(e).replace(/\/+$/,``);return n===r?`.`:!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Jd=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Yd=new Set([`node_modules`]),Xd=e=>Yd.has(e),Zd=e=>{let t=Kd(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Qd=8,$d=new Map,ef=e=>{let t=$d.get(e);return t?(t.touchedAt=Date.now(),$d.delete(e),$d.set(e,t),t):null},tf=e=>{let t=$d.get(e);if(t)return t.touchedAt=Date.now(),t;if($d.size>=Qd){let e=$d.keys().next().value;e!==void 0&&$d.delete(e)}let n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return $d.set(e,n),n},nf=e=>{$d.delete(e)},rf=(e,t)=>(0,$.jsx)(Ri,{filePath:e,extension:t,className:`size-3.5`}),af=e=>{let t=(0,zc.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},of=Q.memo(e=>{let t=(0,zc.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}=qe(),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)(X,{name:`edit`,className:`mr-2 h-4 w-4`}),` `,m(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),Xe(n.path).then(e=>{e.ok||J.error(m(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(X,{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),J.error(m(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(X,{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)(X,{name:`folder-received`,className:`mr-2 h-4 w-4`}),` `,m(Hn())]}),h&&(_||v)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(r,{}),_&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),p(`createFile`,n)},children:[(0,$.jsx)(X,{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)(X,{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)(X,{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=qd(r,n.path);!t||t===`.`||(e.dataTransfer.setData(`application/x-openchamber-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`,ee;t[29]===I?ee=t[30]:(ee=Y(`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]=ee);let L;t[31]!==h||t[32]!==i||t[33]!==n.extension||t[34]!==n.path?(L=h?i?(0,$.jsx)(X,{name:`folder-open-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(X,{name:`folder-3-fill`,className:`size-3.5 flex-shrink-0 text-muted-foreground`}):rf(n.path,n.extension),t[31]=h,t[32]=i,t[33]=n.extension,t[34]=n.path,t[35]=L):L=t[35];let R;t[36]!==n.name||t[37]!==n.path?(R=(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]=R):R=t[38];let z;t[39]!==h||t[40]!==o?(z=!h&&o&&(0,$.jsx)(af,{status:o}),t[39]=h,t[40]=o,t[41]=z):z=t[41];let B;t[42]!==s||t[43]!==h?(B=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]=B):B=t[44];let V;t[45]!==E||t[46]!==P||t[47]!==O||t[48]!==R||t[49]!==z||t[50]!==B||t[51]!==ee||t[52]!==L?(V=(0,$.jsxs)(`button`,{type:`button`,onClick:O,onContextMenu:E,draggable:!0,onDragStart:P,className:ee,children:[L,R,z,B]}),t[45]=E,t[46]=P,t[47]=O,t[48]=R,t[49]=z,t[50]=B,t[51]=ee,t[52]=L,t[53]=V):V=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)(ha,{open:x,onOpenChange:S,children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(Z,{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)(X,{name:`more-2-fill`,className:`h-4 w-4`})})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:m(`sidebarFilesTree.actions.fileMenuTitle`)})]}),(0,$.jsx)(ca,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>S(!1),children:M({Item:ua,Separator:oa})})]})}),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]!==V||t[64]!==H||t[65]!==F?(te=(0,$.jsxs)(hc,{render:F,children:[V,H]}),t[63]=V,t[64]=H,t[65]=F,t[66]=te):te=t[66];let U;t[67]===M?U=t[68]:(U=(0,$.jsx)(_c,{className:`min-w-[180px]`,children:M({Item:vc,Separator:gc})}),t[67]=M,t[68]=U);let ne;return t[69]!==C||t[70]!==te||t[71]!==U?(ne=(0,$.jsxs)(yc,{open:C,onOpenChange:w,children:[te,U]}),t[69]=C,t[70]=te,t[71]=U,t[72]=ne):ne=t[72],ne},(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),sf=()=>{let{t:e}=qe(),{files:t}=za(),n=jo()??``,r=Kd(n.trim()),i=N(),a=_(),o=Te(e=>e.searchFiles),s=K(e=>e.openContextFile),c=Za(n),[l,u]=Q.useState(``),d=Va(l,200),f=Q.useRef(null),[p,m]=Q.useState([]),[h,g]=Q.useState(!1),[v,y]=Q.useState({}),[b,x]=Q.useState({}),S=Q.useRef(new Set),C=Q.useRef(new Set),w=Q.useRef(null),T=Q.useRef(!1);Q.useEffect(()=>{if(!r){y({}),x({}),S.current=new Set;return}let e=ef(r);e?(y({...e.childrenByDir}),x({...e.loadErrorsByDir}),S.current=new Set(e.loadedDirs)):(y({}),x({}),S.current=new Set)},[r]),Q.useEffect(()=>{if(!r)return;let e=tf(r);e.childrenByDir=v},[r,v]),Q.useEffect(()=>{if(!r)return;let e=tf(r);e.loadErrorsByDir=b},[r,b]),Q.useEffect(()=>{if(!r)return;let e=tf(r);e.loadedDirs=new Set(S.current)},[r,v,b]),Q.useEffect(()=>()=>{if(!r)return;let e=$d.get(r);e&&e.loadedDirs.size===0&&Object.keys(e.childrenByDir).length===0&&nf(r)},[r]);let E=Q.useMemo(()=>[],[]),D=Q.useMemo(()=>[],[]),O=Ha(e=>r?e.byRoot[r]?.expandedPaths??E:E),k=Ha(e=>r?e.byRoot[r]?.selectedPath??null:null),A=Ha(e=>e.setSelectedPath),j=Ha(e=>e.addOpenPath),M=Ha(e=>e.removeOpenPathsByPrefix),P=Ha(e=>e.removeExpandedPathsByPrefix),F=Ha(e=>e.toggleExpandedPath),I=Ha(e=>e.expandPaths),ee=K(e=>r?e.contextPanelByDirectory[r]?.tabs??D:D),L=Q.useMemo(()=>new Set(ee.map(e=>e.mode===`file`?e.targetPath:null).filter(e=>typeof e==`string`&&e.length>0).map(e=>Kd(e))),[ee]),[R,z]=Q.useState(null),[B,V]=Q.useState(null),[H,te]=Q.useState(``),[U,ne]=Q.useState(!1),W=!!t.writeFile,re=!!t.createDirectory,G=!!t.rename,ie=!!t.delete,ae=!!t.revealPath,oe=Q.useMemo(()=>({canRename:G,canCreateFile:W,canCreateFolder:re,canDelete:ie,canReveal:ae}),[G,W,re,ie,ae]),se=Q.useCallback(n=>{t.revealPath&&t.revealPath(n).catch(()=>{J.error(e(`sidebarFilesTree.toast.revealFailed`))})},[t,e]),ce=Q.useCallback((e,t)=>{z(e),V(t),te(e===`rename`&&t.name||``),ne(!1)},[]),le=Q.useCallback((e,t)=>Gd(t.filter(e=>e&&typeof e.name==`string`&&e.name.length>0).filter(e=>i||!e.name.startsWith(`.`)).filter(e=>a||!Xd(e.name)).map(t=>{let n=t.name,r=Kd(t.path||``),i=r?Jd(r)?r:Kd(`${e}/${r}`):Kd(`${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=Kd(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}))):Ee.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),x(e=>{if(!e[r])return e;let t={...e};return delete t[r],t}),y(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),x(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=(Ha.getState().byRoot[r]?.expandedPaths??[]).map(e=>Kd(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);x(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=Kd(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(),T.current=!1,S.current=new Set,C.current=new Set,x({}),y(e=>Object.keys(e).length===0?e:{}),ue(r))},[ue,r,i,a]),Q.useEffect(()=>{if(!r||O.length===0)return;let e=O.map(e=>Kd(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}},[O,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||!Zd(e.path)).map(e=>({name:e.name,path:Kd(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(L.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},[L,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 ks(t,e.path);if(!n.ok){J.error(oc(n.reason));return}A(r,e.path),j(r,e.path),s(r,e.path)},[j,t,s,r,A]),ve=Q.useCallback(async e=>{let t=Kd(e);r&&(F(r,t),S.current.has(t)||await ue(t))},[ue,r,F]),ye=Q.useMemo(()=>r?Vd(r,v):[],[v,r]),be=Q.useMemo(()=>new Set(O.map(e=>Kd(e))),[O]),xe=Hd(O),Se=Q.useCallback(()=>{if(r){if(xe){T.current=!1,P(r,r);return}T.current=!0,I(r,ye)}},[xe,ye,I,P,r]);Q.useEffect(()=>{if(!r||!T.current)return;let e=Ud(ye,O);if(e.length>0){I(r,e);return}let t=new Set([...S.current,...Object.keys(b)]);Wd(ye,O,t)&&(T.current=!1)},[ye,I,O,b,r]);let Ce=Q.useCallback(async n=>{if(n?.preventDefault(),!B||!R)return;ne(!0);let i=()=>ne(!1),a=()=>z(null);if(R===`createFile`){if(!H.trim()){J.error(e(`sidebarFilesTree.toast.filenameRequired`)),i();return}if(!t.writeFile){J.error(e(`sidebarFilesTree.toast.writeNotSupported`)),i();return}let n=B.path,r=Kd(`${n?`${n}/`:``}${H.trim()}`);await t.writeFile(r,``).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.fileCreated`)),await fe(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`createFolder`){if(!H.trim()){J.error(e(`sidebarFilesTree.toast.folderNameRequired`)),i();return}let n=B.path,r=Kd(`${n?`${n}/`:``}${H.trim()}`);await t.createDirectory(r).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.folderCreated`)),await fe(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`rename`){if(!H.trim()){J.error(e(`sidebarFilesTree.toast.nameRequired`)),i();return}if(!t.rename){J.error(e(`sidebarFilesTree.toast.renameNotSupported`)),i();return}let n=B.path,o=n.split(`/`).slice(0,-1).join(`/`),s=Kd(`${o?`${o}/`:``}${H.trim()}`);await t.rename(n,s).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.renamedSuccessfully`)),await fe(o),r&&M(r,n),(k===n||k&&k.startsWith(`${n}/`))&&A(r,null)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`delete`){if(!t.delete){J.error(e(`sidebarFilesTree.toast.deleteNotSupported`)),i();return}let n=B.path,o=n.split(`/`).slice(0,-1).join(`/`);await t.delete(n).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.deletedSuccessfully`)),await fe(o),r&&M(r,n),(k===n||k&&k.startsWith(n+`/`))&&A(r,null)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}i()},[R,B,H,t,fe,M,r,k,A,e]);function we(n,i){return(v[n]??[]).map(n=>{let a=n.type===`directory`,o=a&&be.has(Kd(n.path)),s=k===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)(of,{node:n,root:r,isExpanded:o,isActive:s,status:a?void 0:he(n.path),badge:a?ge(n.path):void 0,permissions:oe,downloadFile:t.downloadFile,onSelect:_e,onToggle:ve,onRevealPath:se,onOpenDialog:ce}),a&&o&&(0,$.jsxs)(`ul`,{className:`relative ml-3 flex flex-col border-l border-border/40 pl-3`,children:[b[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:b[n.path],children:b[n.path]}),(0,$.jsxs)(Z,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void fe(n.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):null,we(n.path,i+1)]})]},n.path)})}let De=!!(r&&v[r]),Oe=r?b[r]:null,ke=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)(X,{name:`search`,className:`pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(ta,{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)(X,{name:`close`,className:`h-4 w-4`})}):null]}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-0.5`,children:[W&&(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>ce(`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)(X,{name:`file-add`,className:`size-3.5`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFileTitle`)})]}),re&&(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>ce(`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)(X,{name:`folder-add`,className:`size-3.5`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFolderTitle`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{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)(X,{name:`refresh`,className:`size-3.5`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.refreshTitle`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:Se,disabled:ye.length===0&&O.length===0,className:`w-6 flex-shrink-0 p-0`,title:ke,"aria-label":ke,children:(0,$.jsx)(X,{name:xe?`contract-up-down`:`expand-up-down`,className:`size-3.5`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:ke})]})]})]}),(0,$.jsx)(so,{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)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),e(`sidebarFilesTree.state.searching`)]}):p.length>0?p.map(e=>{let t=k===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_e(e),draggable:!0,onDragStart:t=>{let n=e.relativePath||qd(r??``,e.path);!n||n===`.`||(t.dataTransfer.setData(`application/x-openchamber-file-path`,n),t.dataTransfer.effectAllowed=`copy`)},className:Y(`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:[rf(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)}):Oe?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:Oe}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void de(),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):De&&r?we(r,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-code text-muted-foreground`,children:e(`sidebarFilesTree.state.loading`)})})}),(0,$.jsx)(Vn,{open:!!R,onOpenChange:e=>!e&&z(null),children:(0,$.jsxs)(Rn,{children:[(0,$.jsxs)(In,{children:[(0,$.jsxs)(zn,{children:[R===`createFile`&&e(`sidebarFilesTree.dialog.createFile.title`),R===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.title`),R===`rename`&&e(`sidebarFilesTree.dialog.rename.title`),R===`delete`&&e(`sidebarFilesTree.dialog.delete.title`)]}),(0,$.jsxs)(Bn,{children:[R===`createFile`&&e(`sidebarFilesTree.dialog.createFile.description`,{path:B?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.description`,{path:B?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`rename`&&e(`sidebarFilesTree.dialog.rename.description`,{name:B?.name??``}),R===`delete`&&e(`sidebarFilesTree.dialog.delete.description`,{name:B?.name??``})]})]}),R!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(ta,{value:H,onChange:e=>te(e.target.value),placeholder:e(R===`rename`?`sidebarFilesTree.dialog.rename.placeholder`:`sidebarFilesTree.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&Ce()},autoFocus:!0})}),(0,$.jsxs)(Ln,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>z(null),disabled:U,children:e(`sidebarFilesTree.dialog.cancel`)}),(0,$.jsx)(Z,{variant:R===`delete`?`destructive`:`default`,onClick:()=>void Ce(),disabled:U||R!==`delete`&&!H.trim(),children:U?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):e(R===`delete`?`sidebarFilesTree.dialog.delete.confirm`:`sidebarFilesTree.dialog.confirm`)})]})]})})]})},cf=e=>e===`git`||e===`files`,lf=`files`,uf=()=>!(typeof document<`u`&&document.hidden||typeof navigator<`u`&&!navigator.onLine);function df(e,t,n,r){let i=(0,zc.c)(6),{git:a}=za(),o=Wa(ff),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(()=>{uf()&&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 ff(e){return e.ensureStatus}var pf=()=>{let e=(0,zc.c)(45),{t}=qe(),n=K(mf),r=K(hf),i=K(gf),a=K(_f);df(jo(),i,n,a);let o=a===`git`?`git`:null,s,c;e[0]!==o||e[1]!==n||e[2]!==r?(s=()=>{o&&n===o&&r(lf)},c=[o,n,r],e[0]=o,e[1]=n,e[2]=r,e[3]=s,e[4]=c):(s=e[3],c=e[4]),Q.useEffect(s,c);let l;e[5]===t?l=e[6]:(l=t(`layout.rightSidebar.git`),e[5]=t,e[6]=l);let u;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`}),e[7]=u):u=e[7];let d;e[8]===l?d=e[9]:(d={id:`git`,label:l,icon:u},e[8]=l,e[9]=d);let f;e[10]===t?f=e[11]:(f=t(`layout.rightSidebar.files`),e[10]=t,e[11]=f);let p;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`folder-3`,className:`h-3.5 w-3.5`}),e[12]=p):p=e[12];let m;e[13]===f?m=e[14]:(m={id:`files`,label:f,icon:p},e[13]=f,e[14]=m);let h;e[15]!==d||e[16]!==m?(h=[d,m],e[15]=d,e[16]=m,e[17]=h):h=e[17];let g=h,_;e[18]!==o||e[19]!==g?(_=o?g.filter(e=>e.id!==o):g,e[18]=o,e[19]=g,e[20]=_):_=e[20];let v=_,y=i&&n===`git`&&o!==`git`,b;e[21]===r?b=e[22]:(b=e=>{cf(e)&&r(e)},e[21]=r,e[22]=b);let x=b,S;e[23]!==x||e[24]!==n||e[25]!==v?(S=(0,$.jsx)(`div`,{className:`h-9 bg-background pt-1 px-2`,children:(0,$.jsx)(Bo,{items:v,activeId:n,onSelect:x,layoutMode:`fit`,variant:`active-pill`,activePillLowercase:!1,className:`h-full`})}),e[23]=x,e[24]=n,e[25]=v,e[26]=S):S=e[26];let C=n!==`git`&&`hidden`,w;e[27]===C?w=e[28]:(w=Y(`h-full`,C),e[27]=C,e[28]=w);let T;e[29]===y?T=e[30]:(T=(0,$.jsx)(zd,{isActive:y}),e[29]=y,e[30]=T);let E;e[31]!==w||e[32]!==T?(E=(0,$.jsx)(`div`,{className:w,children:T}),e[31]=w,e[32]=T,e[33]=E):E=e[33];let D=n!==`files`&&`hidden`,O;e[34]===D?O=e[35]:(O=Y(`h-full`,D),e[34]=D,e[35]=O);let k;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(sf,{}),e[36]=k):k=e[36];let A;e[37]===O?A=e[38]:(A=(0,$.jsx)(`div`,{className:O,children:k}),e[37]=O,e[38]=A);let j;e[39]!==E||e[40]!==A?(j=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[E,A]}),e[39]=E,e[40]=A,e[41]=j):j=e[41];let M;return e[42]!==S||e[43]!==j?(M=(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[S,j]}),e[42]=S,e[43]=j,e[44]=M):M=e[44],M};function mf(e){return e.rightSidebarTab}function hf(e){return e.setRightSidebarTab}function gf(e){return e.isRightSidebarOpen}function _f(e){return e.activeMainTab}var vf=(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)},yf=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},bf=(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:Be.cursor(a),effects:ze.scrollIntoView(a,{y:`center`})})};function xf({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=qe(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>vf(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=yf(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:ze.scrollIntoView(e.main.from,{y:`center`})});return}bf(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:ze.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,bf(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??yf(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)(ta,{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)(Z,{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:Y(`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)(ta,{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 Sf=no(()=>Pe(()=>import(`./ToolOutputDialog-2BYaWLo1.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]))),Cf=e=>{let t=Ef(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},wf=e=>{let t=(0,zc.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=Y(`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},Tf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),Ef=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},Df=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Of=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,kf=(e,t)=>{let n=Ef(t),r=Ef(e);if(!n||!r)return!1;let i=Of(n),a=Of(r);return a===i||a.startsWith(`${i}/`)},Af=(e,t)=>{let n=Ef(t),r=Ef(e);if(!kf(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},jf=(e,t)=>{if(!t)return``;let n=Ef(t);if(!e||!kf(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},Mf=new Set([`node_modules`]),Nf=e=>{let t=(0,zc.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},Pf=e=>{let t=(0,zc.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},Ff=e=>Mf.has(e),If=e=>{let t=Ef(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},Lf=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},Rf=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`)},zf=2e5,Bf=`openchamber:files:auto-save-enabled`,Vf=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
|
-
`:`
|
|
8
|
-
`},Hf=e=>e.replace(/\r\n/g,`
|
|
9
|
-
`).replace(/\r/g,`
|
|
10
|
-
`),Uf=(e,t)=>{let n=Hf(e);return t===`\r
|
|
11
|
-
`?n.replace(/\n/g,`\r
|
|
12
|
-
`):n},Wf=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(Bf)!==`false`}catch{return!0}},Gf=(e,t)=>(0,$.jsx)(Ri,{filePath:e,extension:t}),Kf=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},qf=e=>{let t=(0,zc.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}=qe(),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)(X,{name:`edit`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.rename`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),Xe(n.path).then(e=>{e.ok||J.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(X,{name:`file-copy`,className:`mr-2 size-4`}),` `,b(`sidebarFilesTree.menu.copyPath`)]}),(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation();let t=jf(r,n.path)||n.path;Xe(t).then(e=>{if(e.ok){J.success(b(`filesView.toast.relativePathCopied`));return}J.error(b(`sidebarFilesTree.toast.copyFailed`))})},children:[(0,$.jsx)(X,{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),J.error(b(`sidebarFilesTree.toast.operationFailed`))})},children:[(0,$.jsx)(X,{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)(X,{name:`folder-received`,className:`mr-2 size-4`}),` `,b(Hn())]}),x&&(C||w)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(i,{}),C&&(0,$.jsxs)(t,{onClick:e=>{e.stopPropagation(),y(`createFile`,n)},children:[(0,$.jsx)(X,{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)(X,{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)(X,{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 ee=o?void 0:O,L;t[33]===ee?L=t[34]:(L=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:ee}),t[33]=ee,t[34]=L);let R=o?void 0:O,z=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,B;t[35]===z?B=t[36]:(B=Y(`flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none`,z),t[35]=z,t[36]=B);let V;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(V=x?i?(0,$.jsx)(X,{name:`folder-open-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(X,{name:`folder-3-fill`,className:`size-4 flex-shrink-0 text-muted-foreground`}):Gf(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=V):V=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)(Nf,{status:c}),t[45]=x,t[46]=c,t[47]=te):te=t[47];let U;t[48]!==l||t[49]!==x?(U=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]=U):U=t[50];let ne;t[51]!==A||t[52]!==B||t[53]!==V||t[54]!==H||t[55]!==te||t[56]!==U||t[57]!==R?(ne=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:R,className:B,children:[V,H,te,U]}),t[51]=A,t[52]=B,t[53]=V,t[54]=H,t[55]=te,t[56]=U,t[57]=R,t[58]=ne):ne=t[58];let W;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?(W=(S||C||w||T||E)&&(0,$.jsx)(`div`,{className:Y(`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)(ha,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`icon`,className:`size-6`,onClick:M,children:(0,$.jsx)(X,{name:`more-2-fill`,className:`size-4`})})}),(0,$.jsx)(ca,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:ua,Separator:oa})})]})}),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]=W):W=t[71];let re;t[72]!==ne||t[73]!==W||t[74]!==L?(re=(0,$.jsxs)(hc,{render:L,children:[ne,W]}),t[72]=ne,t[73]=W,t[74]=L,t[75]=re):re=t[75];let G;t[76]===P?G=t[77]:(G=(0,$.jsx)(_c,{className:`min-w-[180px]`,children:P({Item:vc,Separator:gc})}),t[76]=P,t[77]=G);let ie;return t[78]!==re||t[79]!==G||t[80]!==F||t[81]!==I?(ie=(0,$.jsxs)(yc,{open:F,onOpenChange:I,children:[re,G]}),t[78]=re,t[79]=G,t[80]=F,t[81]=I,t[82]=ie):ie=t[82],ie},Jf=e=>{let t=(0,zc.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=qe(),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)(zn,{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)(Bn,{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)(In,{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)(ta,{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)(Z,{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)(X,{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)(Z,{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)(Ln,{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)(Rn,{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)(Vn,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},Yf=(e,t,n)=>e&&!!t&&n===t,Xf=(e,t,a)=>{let o=(0,zc.c)(8),[s,c]=Q.useState(``),[l,u]=Q.useState(0),f,p;o[0]!==e||o[1]!==a||o[2]!==t?(f=()=>{if(!e){c(``);return}let o=!1;c(``);let s=d(),l=r(s);n(s).then(n=>{o||!n||(c(e),t(null))}).catch(n=>{o||(t(n instanceof Error?n.message:a),c(e))});let f=i(()=>{o||(c(e),u(Qf),t(null))});return()=>{o=!0,l(),f()}},p=[e,t,a],o[0]=e,o[1]=a,o[2]=t,o[3]=f,o[4]=p):(f=o[3],p=o[4]),Q.useEffect(f,p);let m;return o[5]!==l||o[6]!==s?(m={readyKey:s,nonce:l},o[5]=l,o[6]=s,o[7]=m):m=o[7],m},Zf=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=qe(),{files:r,runtime:i}=za(),{currentTheme:o,availableThemes:c,lightThemeId:l,darkThemeId:u}=Pa(),{isMobile:d,isTablet:p,screenWidth:m}=Fa(),h=d||p,g=N(),v=_(),y=jo()??``,b=Ef(y.trim()),x=d||e!==`editor-only`,S=e===`editor-only`&&!d,C=Te(e=>e.searchFiles),w=Za(y),[T,E]=Q.useState(``),D=Va(T,200),O=Q.useRef(null),[k,A]=Q.useState(!1),[j,P]=Q.useState(!0),[F,I]=Q.useState(!1),[ee,L]=Q.useState(!1),[B,V]=Q.useState(!1),[H,te]=Q.useState({open:!1,title:``,content:``}),U=Q.useRef(null),ne=Q.useRef(0),W=Q.useCallback(e=>{ne.current=Math.max(0,ne.current+(e?1:-1))},[]),re=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=>{ne.current>0||re(e.target)||U.current&&!U.current.contains(e.target)&&V(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[re,B]);let[G,ie]=Q.useState(`edit`),[ae,oe]=Q.useState(`edit`),[se,ce]=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)??Ra(!1),[c,l]),ve=Q.useMemo(()=>c.find(e=>e.metadata.id===u)??Ra(!0),[c,u]);Q.useEffect(()=>{$a(_e),$a(ve)},[_e,ve]);let ye=Q.useMemo(()=>[],[]),be=Ha(e=>b?e.byRoot[b]?.openPaths??ye:ye),xe=Ha(e=>b?e.byRoot[b]?.selectedPath??null:null),Se=Ha(e=>b?e.byRoot[b]?.expandedPaths??ye:ye),Ce=Ha(e=>e.addOpenPath),we=Ha(e=>e.removeOpenPath),De=Ha(e=>e.removeOpenPathsByPrefix),Oe=Ha(e=>e.removeExpandedPathsByPrefix),ke=Ha(e=>e.setSelectedPath),Ae=Ha(e=>e.toggleExpandedPath),je=Ha(e=>e.expandPaths),Me=Q.useCallback(e=>{let t=Ef(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}},[]),Ne=Q.useMemo(()=>be.map(Me),[be,Me]),Pe=Q.useMemo(()=>{if(xe){let e=Of(xe);if(be.some(t=>Of(t)===e))return xe}return be[0]??null},[be,xe]),q=Q.useMemo(()=>Pe?Me(Pe):null,[Pe,Me]),Fe=q?.path??``;Q.useEffect(()=>{if(!b||!xe)return;let e=Of(xe);be.some(t=>Of(t)===e)||ke(b,be[0]??null)},[be,b,xe,ke]);let Ie=!!(b&&Fe&&!kf(Fe,b)),Le=Ie?No(Fe):void 0,Re=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&Ie,outsideFileGrant:Le,directory:b||void 0}),[e,Ie,Le,b]),Be=Q.useRef(null),[He,Ue]=Q.useState({left:!1,right:!1}),We=Q.useCallback(()=>{let e=Be.current;e&&Ue({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),Ge=Q.useRef(We);Ge.current=We,Q.useEffect(()=>{let e=Be.current;if(!e)return;let t=()=>Ge.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[Ne.length]);let[Ke,Je]=Q.useState({}),[Ye,Ze]=Q.useState({}),Qe=Q.useRef(new Set),$e=Q.useRef(new Set),et=Q.useRef(!1),tt=Q.useRef(new Map),nt=Q.useRef(0),[rt,it]=Q.useState([]),[at,ot]=Q.useState(!1),[st,ct]=Q.useState(``),{isPlaying:lt,play:ut,stop:dt}=Qr(),[ft,pt]=Q.useState(!1),[mt,ht]=Q.useState(null),[gt,_t]=Q.useState(``),vt=Q.useRef(``),[yt,bt]=Q.useState(null),[xt,St]=Q.useState(``),[Ct,wt]=Q.useState(!1),[Tt,Dt]=Q.useState(`
|
|
13
|
-
`),Ot=Q.useRef(null),kt=Q.useRef(null),At=Q.useRef(null),jt=Q.useRef(``),Mt=Q.useRef(``),Nt=Q.useRef(null),Pt=Q.useRef(null),Ft=Q.useRef(null),It=Q.useRef(0),[Lt,Rt]=Q.useState(`idle`),[zt,Bt]=Q.useState(!1),[Vt,Ht]=Q.useState(Wf),[Ut,Wt]=Q.useState(!1),Gt=Q.useRef(null),Kt=Q.useRef(null),qt=Q.useRef(null),Jt=Q.useRef(!1),Yt=Q.useRef(null),Xt=Q.useRef(null),Zt=Q.useRef(null),Qt=Q.useRef(null),[$t,en]=Q.useState(0),tn=Q.useRef(null),nn=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{tn.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame(tn.current),tn.current=null)},[]);let[rn,an]=Q.useState(null),[on,sn]=Q.useState(null),[cn,ln]=Q.useState(``),[un,dn]=Q.useState(!1),[fn,pn]=Q.useState(null),[mn,hn]=Q.useState(null),[gn,_n]=Q.useState(!1),[vn,yn]=Q.useState(!1),[bn,xn]=Q.useState(!1),[Sn,Cn]=Q.useState(!1),[wn,En]=Q.useState(null),Dn=Tn(e=>e.addCodeSelectionAttachment),On=Tn(e=>e.setPendingInputText),kn=!!r.writeFile,An=!!r.createDirectory,jn=!!r.rename,Mn=!!r.delete,Nn=!!r.revealPath,Pn=el(e=>e.availableApps),Fn=el(e=>e.isCacheStale),Hn=el(e=>e.initialize),Un=el(e=>e.loadInstalledApps);Q.useEffect(()=>{Hn()},[Hn]);let Gn=Q.useCallback(e=>{r.revealPath&&r.revealPath(e).catch(()=>{J.error(n(`sidebarFilesTree.toast.revealFailed`))})},[r,n]),qn=Q.useCallback(async e=>{if(!q?.path||await R(q.path,e.id,e.appName)||await M(q.path,e.appName))return;let t=Cf(q.path)||b;t&&await M(t,e.appName)||J.error(n(`filesView.toast.openInAppFailed`,{app:e.appName}))},[b,q?.path,n]),Jn=Q.useCallback((e,t)=>{an(e),sn(t),ln(e===`rename`&&t.name||``),dn(!1)},[]),[Yn,Xn]=Q.useState(null),Zn=Q.useRef(!1),Qn=Q.useRef(null),[$n,er]=Q.useState(!1),tr=K(e=>e.setMainTabGuard),nr=K(e=>e.pendingFileNavigation),rr=K(e=>e.setPendingFileNavigation),ir=K(e=>e.pendingFileFocusPath),ar=K(e=>e.setPendingFileFocusPath),or=K(e=>e.pendingFileViewerMode),sr=K(e=>e.setPendingFileViewerMode),cr=K(e=>e.shortcutOverrides),lr=K(e=>e.fileEditorKeymap),ur=Et(e=>e.settingsDefaultFileViewerPreview),dr=Et(e=>e.showMessageTTSButtons),fr=K(e=>e.expandedEditorToolbar);Q.useEffect(()=>{let e=()=>{Zn.current=!1,Qn.current=null,er(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]),Q.useEffect(()=>()=>{Yt.current!==null&&window.clearTimeout(Yt.current),Xt.current!==null&&window.clearTimeout(Xt.current)},[]);let pr=Q.useCallback((e,t)=>{let n=e.split(`
|
|
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:mr,commentText:hr,setCommentText:gr,editingDraftId:_r,setSelection:vr,saveComment:yr,cancel:br,reset:xr,startEdit:Sr,deleteDraft:Cr}=Gs({source:`file`,fileLabel:q?.path??null,language:q?.path&&To(q.path)||`text`,getCodeForRange:e=>pr(st,Cs(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{Xn(null),xr(),tr(null),St(``),wt(!1)},[q?.path,xr,tr]),Q.useEffect(()=>{vr(Yn)},[Yn,vr]),Q.useEffect(()=>{if(!Yn&&!_r)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]`)||hr.trim()||(Xn(null),br())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[br,hr,_r,Yn]);let wr=Q.useCallback((e,t)=>{let n=t??Yn??void 0;t&&Xn(t),yr(e,n),Xn(null)},[Yn,yr]),Tr=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!g&&r.name.startsWith(`.`)||!v&&Ff(r.name))continue;let t=r.name,i=Ef(r.path||``),a=i?Df(i)?i:Ef(`${e}/${i}`):Ef(`${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 Tf(n)},[v,g]),Er=Q.useCallback(async e=>{let t=Ef(e.trim());if(!t||Qe.current.has(t)||$e.current.has(t))return;$e.current=new Set($e.current),$e.current.add(t);let n=nt.current+1;nt.current=n,tt.current=new Map(tt.current),tt.current.set(t,n);let i=()=>tt.current.get(t)===n;await(r.listDirectory?r.listDirectory(t).then(e=>e.entries.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory}))):Ee.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!i())return;let n=Tr(t,e);Qe.current=new Set(Qe.current),Qe.current.add(t),Ze(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Je(e=>({...e,[t]:n}))}).catch(e=>{if(!i())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&b&&t!==b){Oe(b,t),Ze(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),Ze(e=>({...e,[t]:n}))}).finally(()=>{i()&&(tt.current=new Map(tt.current),tt.current.delete(t),$e.current=new Set($e.current),$e.current.delete(t))})},[r,Tr,Oe,b]),Dr=Q.useCallback(async()=>{b&&(Qe.current=new Set,$e.current=new Set,tt.current=new Map,Ze({}),Je(e=>Object.keys(e).length===0?e:{}),await Er(b))},[Er,b]),Or=Q.useCallback(async e=>{if(!e){await Dr();return}let t=Ef(e);Qe.current=new Set(Qe.current),Qe.current.delete(t),$e.current=new Set($e.current),$e.current.delete(t),await Er(t)},[Er,Dr]),kr=Q.useRef(``),Ar=Q.useRef(``);Q.useEffect(()=>{if(!b)return;let e=`${b}|h${g?`1`:`0`}|g${v?`1`:`0`}`,t=kr.current!==b,n=Ar.current!==e;!t&&!n||(t&&(kr.current=b,ct(``),ht(null),_t(``),bt(null),A(!1)),n&&(Ar.current=e,et.current=!1,Qe.current=new Set,$e.current=new Set,tt.current=new Map,Ze({}),Je(e=>Object.keys(e).length===0?e:{}),Er(b)))},[Er,b,v,g]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&Se.length>0)for(let e of Se)Or(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Se,r.listDirectory,Or]),Q.useEffect(()=>{if(!b||Se.length===0)return;let e=Se.map(e=>Ef(e)).filter(e=>!!e&&e!==b&&e.startsWith(`${b}/`)&&!Qe.current.has(e)&&!$e.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=>Er(e)))}})(),()=>{t=!0}},[Se,Er,b]);let jr=Q.useCallback(async e=>{if(e?.preventDefault(),!on||!rn)return;dn(!0);let t=()=>{an(null)},i=e=>{J.error(e)},a=()=>{dn(!1)};if(rn===`createFile`){if(!cn.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=on.path,o=Ef(`${e?`${e}/`:``}${cn.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.fileCreated`)),await Or(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(rn===`createFolder`){if(!cn.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=on.path,o=Ef(`${e?`${e}/`:``}${cn.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.folderCreated`)),await Or(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(rn===`rename`){if(!cn.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=on.path,o=e.split(`/`).slice(0,-1).join(`/`),s=Ef(`${o?`${o}/`:``}${cn.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await Or(o),b&&De(b,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(b&&ke(b,null),ct(``),ht(null),_t(``),bt(null),d&&A(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(rn===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=on.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await Or(o),b&&De(b,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(b&&ke(b,null),ct(``),ht(null),_t(``),bt(null),d&&A(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[rn,on,cn,r,Or,d,De,b,q?.path,ke,n]);Q.useEffect(()=>{if(!y){it([]),ot(!1);return}let e=D.trim();if(!e){it([]),ot(!1);return}let t=!1;return ot(!0),C(y,e,150,{includeHidden:g,respectGitignore:!v,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>v||!If(e.path)).map(e=>({name:e.name,path:Ef(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));it(n)}).catch(()=>{t||it([])}).finally(()=>{t||ot(!1)}),()=>{t=!0}},[y,D,C,g,v]);let Mr=Q.useCallback(async(e,t)=>{if(r.readFile)return(await r.readFile(e,{...t??{},directory:b||void 0})).content??``;let i=new URLSearchParams({path:e});t?.allowOutsideWorkspace&&i.set(`allowOutsideWorkspace`,`true`),t?.outsideFileGrant&&i.set(`outsideFileGrant`,t.outsideFileGrant),t?.optional&&i.set(`optional`,`true`),b&&i.set(`directory`,b);let a=await f(`/api/fs/read?${i.toString()}`,{cache:t?.optional?`no-store`:`default`});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error||n(`filesView.error.readFileFailed`))}return a.text()},[r,b,n]),Nr=Q.useCallback(async(e,t)=>{if(r.statFile){let n=await r.statFile(e,{...t??{},directory:b||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[r,b]);Q.useEffect(()=>{if(!b||!r.statFile||be.length===0)return;let e=!1,t=[...be];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:b||void 0});!e&&n&&!n.isFile&&De(b,t)}catch(n){!e&&Rf(n)&&De(b,t)}})),()=>{e=!0}},[r,be,De,b]);let Pr=Q.useMemo(()=>st.length>zf?`${st.slice(0,zf)}\n\n… truncated …`:st,[st]),Fr=xt!==Pr,Ir=Q.useCallback(async()=>{if(!q||!r.writeFile)return J.error(n(`filesView.toast.savingNotSupported`)),!1;if(!Fr)return!0;if(xt===``&&st!==``&&yt!==q.path)return console.warn(`[saveDraft] refusing to save empty draft for "${q.path}" (${st.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;wt(!0);try{let e=Uf(xt,Tt);return(await r.writeFile(q.path,e))?.success?(ct(xt),q?.path&&Oo(q.path)&&(jt.current=xt,Mt.current=xt),Nr(q.path).then(e=>{e&&(Ft.current=e)}).catch(()=>{}),!0):(J.error(n(`filesView.toast.writeFileFailed`)),!1)}catch(e){return J.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`)),!1}finally{wt(!1)}},[xt,st,r,Fr,Tt,yt,Nr,q,n]);Q.useEffect(()=>{if(!Fr){tr(null);return}let e=e=>Jt.current?(Jt.current=!1,!0):(Wt(!0),Kt.current=e,!1);return tr(e),()=>{K.getState().mainTabGuard===e&&tr(null)}},[Fr,tr]),Q.useEffect(()=>{try{window.localStorage.setItem(Bf,Vt?`true`:`false`)}catch{}},[Vt]),Q.useEffect(()=>{Vt||(Rt(`idle`),kt.current&&=(clearTimeout(kt.current),null))},[Vt]);let Lr=1500;Q.useEffect(()=>{let e=!!(q&&r.writeFile);if(!(!Vt||!Fr||!e||Ct))return kt.current=setTimeout(()=>{Ir().then(e=>{e&&(Rt(`saved`),setTimeout(()=>Rt(`idle`),2e3))})},Lr),()=>{kt.current&&=(clearTimeout(kt.current),null)}},[Vt,xt,Fr,q,r.writeFile,Ct,Ir]),Q.useEffect(()=>{Rt(`idle`)},[q?.path]),Q.useEffect(()=>{let e=e=>{Kn(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),kt.current&&=(clearTimeout(kt.current),null),Ct||Ir().then(e=>{e&&(Rt(`saved`),setTimeout(()=>Rt(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),L(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ct,Ir]);let Rr=Q.useCallback(async t=>{let r=It.current+1;It.current=r;let a=()=>{if(!b)return!1;let e=Ha.getState().byRoot[b],n=e?.selectedPath??e?.openPaths[0]??null;return It.current===r&&n===t.path};ht(null),_t(``),bt(null);let o=Eo(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Do(t.path);if(d&&A(!0),i.isDesktop&&o&&!s){ct(``),St(``),pt(!0);return}if(!i.isDesktop&&o&&!s){ct(``),St(``),bt(t.path),pt(!1);return}if(c){ct(``),St(``),bt(t.path),pt(!1);return}pt(!0);let l=No(t.path),u={allowOutsideWorkspace:e===`editor-only`&&!!b&&!kf(t.path,b),outsideFileGrant:l};await Mr(t.path,u).then(e=>{if(!a())return;let n=Hf(e);Dt(Vf(e)),ct(n),jt.current=n,Mt.current=n,St(n.length>zf?`${n.slice(0,zf)}\n\n… truncated …`:n),bt(t.path),Nr(t.path,u).then(e=>{e&&a()&&(Ft.current=e)}).catch(()=>{})}).catch(e=>{if(a()){if(Lf(e)){if(pt(!1),b&&ke(b,null),ht(null),ct(``),St(``),bt(null),Ft.current=null,T.trim().length>0&&E(``),d&&A(!1),b){let e=[...Af(t.path,b),t.path];e.length>0&&je(b,e);for(let t of e)Qe.current.has(t)||Er(t)}return}if(Rf(e)){b&&De(b,t.path),ct(``),St(``),ht(null),Ft.current=null,d&&A(!1);return}ct(``),St(``),ht(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),Ft.current=null}}).finally(()=>{a()&&pt(!1)})},[je,d,Er,e,Mr,Nr,De,b,i.isDesktop,T,ke,n]),zr=Q.useCallback(async(e,t)=>{if(!b)return;let n=Af(e,b),r=t?[...n,e]:n;r.length>0&&je(b,r);let i=r.map(e=>{if(!Qe.current.has(e))return Er(e)}).filter(Boolean);await Promise.all(i)},[je,Er,b]),Br=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},[]),Vr=Q.useCallback(async e=>{if(Jt.current)Jt.current=!1;else if(Fr){Wt(!0),Gt.current=e;return}b&&(ke(b,e.path),Ce(b,e.path),zr(e.path,!1)),ht(null),_t(``),ct(``),jt.current=``,Mt.current=``,St(``),bt(null),d&&A(!0)},[Ce,zr,Fr,d,b,ke]);Q.useEffect(()=>{q?.path&&zr(q.path,!1)},[zr,q?.path]),Q.useEffect(()=>{if(!q){It.current+=1,pt(!1);return}yt!==q.path&&Rr(q)},[Rr,yt,q]);let Hr=Q.useRef(Fr);Hr.current=Fr,Q.useEffect(()=>{let e=q?.path??``;if(!Yf(t,e,yt))return;let n=!1,r=window.setInterval(()=>{document.hidden||Nr(e,Re).then(t=>{if(n||!t)return;let r=Ft.current;if(!r||r.path!==e){Ft.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Hr.current||(Ft.current=t,bt(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,yt,Nr,q?.path,Re]);let Ur=Q.useCallback(()=>{let e=Gt.current,t=Kt.current,n=qt.current;if(Gt.current=null,Kt.current=null,qt.current=null,Jt.current=!0,Wt(!1),St(Pr),n){b&&we(b,n),q?.path===n&&(e?Vr(e):(b&&ke(b,null),ct(``),ht(null),_t(``),bt(null),d&&A(!1)));return}if(e){Vr(e);return}t&&(tr(null),K.getState().setActiveMainTab(t))},[Pr,Vr,d,we,b,q?.path,tr,ke]),Wr=Q.useCallback(async()=>{let e=Gt.current,t=Kt.current,n=qt.current;if(!await Ir()){Jt.current=!1;return}if(Gt.current=null,Kt.current=null,qt.current=null,Jt.current=!0,Wt(!1),n){b&&we(b,n),q?.path===n&&(e?await Vr(e):(b&&ke(b,null),ct(``),ht(null),_t(``),bt(null),d&&A(!1)));return}if(e){await Vr(e);return}t&&(tr(null),K.getState().setActiveMainTab(t))},[Vr,d,we,b,Ir,q?.path,tr,ke]),Gr=Q.useCallback(e=>{let t=q?.path===e,n=Br(e,Ne);if(t&&Fr){Wt(!0),Gt.current=n,qt.current=e;return}if(b&&we(b,e),t){if(n){Vr(n);return}b&&ke(b,null),ct(``),ht(null),_t(``),bt(null),d&&A(!1)}},[Br,Vr,Fr,d,Ne,we,b,q?.path,ke]),Kr=Q.useCallback(e=>{if(be.includes(e))return`open`;if(w?.files){let t=e.startsWith(b+`/`)?e.slice(b.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,b]),qr=Q.useCallback(e=>{if(!w?.files)return null;let t=e.startsWith(b+`/`)?e.slice(b.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,b]),Jr=Q.useCallback(async e=>{let t=Ef(e);b&&(Ae(b,t),Qe.current.has(t)||await Er(t))},[Er,b,Ae]),Yr=Q.useMemo(()=>b?Vd(b,Ke):[],[Ke,b]),Xr=Q.useMemo(()=>new Set(Se.map(e=>Ef(e))),[Se]),Zr=Hd(Se),$r=Q.useCallback(()=>{if(b){if(Zr){et.current=!1,Oe(b,b);return}et.current=!0,je(b,Yr)}},[Zr,Yr,je,Oe,b]);Q.useEffect(()=>{if(!b||!et.current)return;let e=Ud(Yr,Se);if(e.length>0){je(b,e);return}let t=new Set([...Qe.current,...Object.keys(Ye)]);Wd(Yr,Se,t)&&(et.current=!1)},[Yr,je,Se,Ye,b]);let ei=Q.useMemo(()=>({canRename:jn,canCreateFile:kn,canCreateFolder:An,canDelete:Mn,canReveal:Nn}),[jn,kn,An,Mn,Nn]);function ni(e,t){let i=Ke[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Xr.has(Ef(e.path)),c=q?.path===e.path,l=a===i.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)(qf,{node:e,root:b,isExpanded:s,isActive:c,isMobile:d,alwaysShowActions:h,status:o?void 0:Kr(e.path),badge:o?qr(e.path):void 0,permissions:ei,downloadFile:r.downloadFile,contextMenuPath:fn,setContextMenuPath:pn,rightClickMenuPath:mn,setRightClickMenuPath:hn,onSelect:Vr,onToggle:Jr,onRevealPath:Gn,onOpenDialog:Jn}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[Ye[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:Ye[e.path],children:Ye[e.path]}),(0,$.jsxs)(Z,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void Or(e.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):null,ni(e.path,t+1)]})]},e.path)})}let ri=!!(q?.path&&Eo(q.path)),ii=!!(q?.path&&q.path.toLowerCase().endsWith(`.svg`)),ai=!!(q?.path&&Do(q.path)),oi=Q.useMemo(()=>Ef(nr?.path??``),[nr?.path]),si=!!(nr&&oi&&Fe&&Fe===oi&&!ft&&!mt&&!ri&&!ai),ci=Q.useMemo(()=>jf(b,Fe),[Fe,b]),li=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(Cn(e=>e===t?e:t),!t){En(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&En({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),ui=Q.useCallback(()=>{let e=Zt.current,t=e?.state.selection.main;if(!e||!t||t.empty||!q)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=`${q.name}:${a}`;Dn(q.path,o,n),On(z(o),`append-inline`),En(null),K.getState().setActiveMainTab(`chat`)},[Dn,q,On]),di=Q.useCallback(e=>{if(!q)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=xt.split(`
|
|
16
|
-
`).slice(t-1,n).join(`
|
|
17
|
-
`);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${q.name}:${i}`;Dn(q.path,a,r),On(z(a),`append-inline`),K.getState().setActiveMainTab(`chat`)},[Dn,xt,q,On]),fi=!!(q&&(!ri||ii)&&!ai&&st.length>0),pi=!!(q&&ci.length>0),mi=!!(q&&!Ie&&!ri&&!ai&&r.writeFile&&st.length<=zf),hi=!!(q?.path&&Kf(q.path)),gi=!!(q?.path&&Ao(q.path)),_i=!!(q?.path&&Oo(q.path)),vi=!!(q&&!ri&&!ai),yi=vi&&!hi&&!_i&&!(gi&&se===`preview`),bi=hi&&ae===`edit`||gi&&se===`edit`||!hi&&!gi&&G===`edit`,xi=Q.useMemo(()=>Fe?Na(Fe):null,[Fe]),[Si,Ci]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=q?.path;if(!t||xi){Ci(null);return}return Ci(null),xa(t).then(t=>{e||Ci(t)}),()=>{e=!0}},[q?.path,xi]),Q.useEffect(()=>{!mi&&G===`edit`&&ie(`view`)},[mi,G]);let wi=`openchamber:files:md-viewer-mode`,Ti=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=q?.path;if(!e)return;ie(pe.current[e]??`edit`);let t=ur?`preview`:`edit`;try{let e=localStorage.getItem(wi);(e===`preview`||e===`edit`)&&(t=e)}catch{}oe(me.current[e]??t);let n=ur?`preview`:`edit`;try{let e=localStorage.getItem(Ti);(e===`preview`||e===`edit`)&&(n=e)}catch{}or&&Ao(e)&&ir===e&&(he.current[e]=or,sr(null)),ce(he.current[e]??n),ue(ge.current[e]??(ur?`preview`:`edit`))},[ir,or,q?.path,sr,ur]);let Ei=Q.useCallback(e=>{let t=q?.path;t&&(pe.current[t]=e),ie(e)},[q?.path]),Di=Q.useCallback(e=>{let t=q?.path;t&&(me.current[t]=e),oe(e);try{localStorage.setItem(wi,e)}catch{}},[q?.path]),Oi=Q.useCallback(()=>ae,[ae]),ki=Q.useCallback(e=>{let t=q?.path;t&&(he.current[t]=e),ce(e);try{localStorage.setItem(Ti,e)}catch{}},[q?.path]),Ai=Q.useCallback(e=>{let t=q?.path;if(t&&(ge.current[t]=e),At.current&&=(clearTimeout(At.current),null),Nt.current!==null&&(cancelAnimationFrame(Nt.current),Nt.current=null),e===`edit`)St(jt.current||st),ue(e);else{jt.current=xt;let e=t;ue(`edit`),Nt.current=requestAnimationFrame(()=>{Nt.current=requestAnimationFrame(()=>{Nt.current=null,!(b&&e&&Ha.getState().byRoot[b]?.selectedPath!==e)&&(fe(e=>e+1),ue(`preview`))})});return}},[xt,st,b,q?.path]),ji=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===Mt.current)return!1;if(!(await r.writeFile(e,t))?.success)return J.error(n(`filesView.toast.writeFileFailed`)),!1;jt.current=t,Mt.current=t,St(t);let i=await Nr(e,Re).catch(()=>null);return i&&(Ft.current=i),!0},[r,Nr,Re,n]);Q.useEffect(()=>()=>{At.current&&=(clearTimeout(At.current),null),Nt.current!==null&&(cancelAnimationFrame(Nt.current),Nt.current=null)},[le,q?.path]);let Mi=Q.useCallback(e=>{if(jt.current=e,!q?.path||le!==`preview`||!r.writeFile)return;At.current&&clearTimeout(At.current);let t=q.path;At.current=setTimeout(()=>{At.current=null,ji(t,e).then(e=>{e&&(Bt(!0),setTimeout(()=>Bt(!1),1500))}).catch(e=>{J.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Lr)},[le,r.writeFile,ji,q?.path,n]),Ni=Q.useMemo(()=>_i&&(jt.current||xt)||st,[xt,st,_i]),Pi=Q.useCallback(()=>se,[se]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of be)pe.current[e]=`edit`,Kf(e)&&(me.current[e]=t),Ao(e)&&(he.current[e]=t),Oo(e)&&(ge.current[e]=t);ie(`edit`),oe(t),ce(t),ue(t);try{localStorage.setItem(wi,t),localStorage.setItem(Ti,t)}catch{}},t=t=>{let n=!!t.detail?.enabled;e(n)};return window.addEventListener(`openchamber:file-viewer-preview-mode-changed`,t),()=>{window.removeEventListener(`openchamber:file-viewer-preview-mode-changed`,t)}},[be]),Q.useEffect(()=>{if(!nr||!b)return;let e=()=>{typeof window>`u`||tn.current===null&&(tn.current=window.requestAnimationFrame(()=>{tn.current=null,en(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=Ef(nr.path);if(!n){rr(null),nn.current={key:``,attempts:0};return}let r=`${n}:${nr.line}:${nr.column??1}`;if(nn.current.key!==r&&(nn.current={key:r,attempts:0}),q?.path!==n){if(Ut)return;Vr(Me(n));return}if(ft||yt!==n)return;if(mt||ri||ai){rr(null),nn.current={key:``,attempts:0};return}if(!mi)return;if(G!==`edit`){ie(`edit`);return}let i=Zt.current;if(!i){e();return}if(!t(i,xt)){e();return}let a=Math.max(1,Math.min(nr.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,nr.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||nn.current.attempts===0){nn.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:ze.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=Zt.current;e&&(e.dispatch({selection:{anchor:u},effects:ze.scrollIntoView(u,{y:`center`})}),e.focus())}),rr(null),nn.current={key:``,attempts:0}},[mi,Ut,xt,$t,mt,ft,ri,ai,yt,Vr,nr,b,q?.path,rr,G,Me]),Q.useEffect(()=>{if(!ir||!b)return;let e=Ef(ir);if(!e){ar(null);return}if(q?.path!==e){if(Ut)return;Vr(Me(e));return}if(!(ft||yt!==e||mt||ri||ai)){if(mi&&G===`edit`){let e=Zt.current;if(!e)return;e.focus()}ar(null)}},[mi,Ut,mt,ft,Vr,ri,ai,yt,ir,b,q?.path,ar,G,Me]);let Fi=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(()=>{Fi(Zt.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,Fi]),Q.useEffect(()=>{if(G!==`edit`||d)return;let e=Oa(`open_go_to_line`,cr),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(ga(t,e)){t.preventDefault(),xn(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=Zt.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),ui())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[ui,d,cr,G]);let Ii=K(e=>e.editorFontSize),Li=Q.useMemo(()=>{if(!q?.path)return[ls(o,{fontSize:Ii})];let e=To(q.path),t=[ls(o,e?{syntaxColors:!1,fontSize:Ii}:{fontSize:Ii})],n=xi??Si;return n&&t.push(n),e&&t.push(Qo({language:e,themeName:o.metadata.id,theme:Qa(o)})),j&&t.push(ze.lineWrapping),t.push(ze.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&li(e.view)})),d&&t.push(ze.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{Fi(e.view)})})),t},[o,q?.path,xi,Si,j,d,Fi,Ii,li]),zi=Q.useMemo(()=>({light:_e.metadata.id,dark:ve.metadata.id}),[_e.metadata.id,ve.metadata.id]),Bi=q?.path&&ri&&!i.isDesktop&&!ii?`${q.path}|${Re.allowOutsideWorkspace?`outside`:`workspace`}|${Re.outsideFileGrant??``}`:``,Vi=q?.path&&ai?`${q.path}|${Re.allowOutsideWorkspace?`outside`:`workspace`}|${Re.outsideFileGrant??``}`:``,Hi=i.isVSCode||a(),Ui=q?.path&&gi&&se===`preview`&&!Hi?q.path:``,Wi=n(`filesView.error.readFileFailed`),{readyKey:Gi,nonce:Ki}=Xf(Bi,ht,Wi),{readyKey:qi,nonce:Ji}=Xf(Ui,ht,Wi),{readyKey:Yi,nonce:Xi}=Xf(Vi,ht,Wi),Zi=!!(Bi&&Gi!==Bi),Qi=!!(Ui&&qi!==Ui),$i=!!(Vi&&Yi!==Vi),ea=q?.path&&ri?i.isDesktop?ii?`data:${ko(q.path)};utf8,${encodeURIComponent(st)}`:gt:ii?`data:${ko(q.path)};utf8,${encodeURIComponent(st)}`:Gi===Bi?s().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Re.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Re.outsideFileGrant,directory:b||void 0}):``:``,ia=Q.useCallback(()=>{if(!q?.path||!ri)return;let e=ii?ea:q.path||ea;if(!e)return;let t=q.name||q.path;te({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:ko(q.path)},image:{url:e,mimeType:ko(q.path),filename:t}})},[ea,ri,ii,q?.name,q?.path]),oa=Q.useCallback(e=>{te(t=>t.open===e?t:{...t,open:e})},[]),sa=Q.useCallback((e,t)=>{let r=e.name||n(`filesView.editor.imageAltFallback`);return(0,$.jsx)(`div`,{className:Y(`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:ia,"aria-label":r,disabled:!ea,children:(0,$.jsx)(`img`,{src:ea,alt:r,className:Y(`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},Ki)})})},[Ki,ea,ia,n]),la=q?.path&&ai&&Yi===Vi?s().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Re.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Re.outsideFileGrant,directory:b||void 0}):``,da=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:la,className:`h-full w-full border-0`,title:e.name},Xi)}),[la,Xi]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!i.isDesktop||!q?.path||!ri||ii){vt.current&&=(URL.revokeObjectURL(vt.current),``),_t(``);return}ht(null),vt.current&&=(URL.revokeObjectURL(vt.current),``),await(r.readFileBinary?r.readFileBinary(q.path,Re).then(e=>e.dataUrl):(async()=>{let t=await f(`/api/fs/raw`,{query:{path:q.path,allowOutsideWorkspace:Re.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Re.outsideFileGrant,directory:b||void 0}});if(!t.ok)throw Error(n(`filesView.error.readFileFailed`));let r=await t.blob(),i=URL.createObjectURL(r);return e?(URL.revokeObjectURL(i),``):(vt.current=i,i)})()).then(t=>{e||(_t(t),bt(q.path))}).catch(t=>{vt.current&&=(URL.revokeObjectURL(vt.current),``),e||(_t(``),ht(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),bt(null))}).finally(()=>{e||pt(!1)})})(),()=>{e=!0}},[r,ri,ii,b,i.isDesktop,q?.path,Re,n]),Q.useEffect(()=>()=>{vt.current&&=(URL.revokeObjectURL(vt.current),``)},[]);let fa=Q.useCallback(()=>an(null),[]),pa=Q.useMemo(()=>Ps({drafts:mr,editingDraftId:_r,commentText:hr,onTextChange:gr,selection:Yn,isDragging:$n,fileLabel:q?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:wr,onCancel:()=>{Xn(null),br()},onEdit:e=>{Sr(e),Xn({start:e.startLine,end:e.endLine})},onDelete:Cr,onAddToChat:di}),[di,br,hr,Cr,_r,mr,wr,$n,Yn,q?.path,gr,Sr]),ma=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(Ve,{file:{name:e.name,contents:t,lang:To(e.path)||void 0},options:{disableFileHeader:!0,overflow:j?`wrap`:`scroll`,theme:zi,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,zi,j]),va=({exitFullscreenOnly:t=!1,layout:i=`floating`}={})=>{if(!q)return null;let a=i===`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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[mi&&bi&&(0,$.jsxs)($.Fragment,{children:[Ct?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-muted-foreground typography-meta`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}),n(`filesView.editor.saving`)]}):Vt&&Lt===`saved`&&!Fr?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta`,children:[(0,$.jsx)(X,{name:`check`,className:`size-3.5`}),n(`filesView.editor.saved`)]}):Fr?o(n(Vt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${Wn()}+S`}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void Ir(),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:n(Vt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${Wn()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${Wn()}+S`}),children:(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})):null,o(n(Vt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Ht(e=>!e),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Vt?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(Vt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":n(Vt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Vt?(0,$.jsx)(X,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(X,{name:`file-check`,className:`size-4`})}))]}),vi&&Sn?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:ui,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:`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,"aria-label":`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{children:n(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(ti,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(ha,{onOpenChange:W,children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.openInDesktopApp`),"aria-label":n(`filesView.editor.openInDesktopApp`),children:(0,$.jsx)(X,{name:`file-transfer`,className:`size-4`})})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(ca,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[Pn.map(e=>(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>void qn(e),children:[(0,$.jsx)(wf,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),Fn?(0,$.jsxs)(ua,{className:`flex items-center gap-2`,onClick:()=>void Un(!0),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:n(`filesView.editor.refreshApps`)})]}):null]})]}),!ri&&!ai&&(0,$.jsxs)($.Fragment,{children:[o(n(j?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>P(!j),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,j?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(j?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(X,{name:`text-wrap`,className:`size-4`})})),G===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:e=>{L(!ee),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:n(`filesView.editor.findInFile`),children:(0,$.jsx)(X,{name:`search`,className:`size-4`})})),o(n(`filesView.editor.goToLine`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:e=>{xn(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:n(`filesView.editor.goToLine`),children:(0,$.jsx)(X,{name:`menu-fold-2`,className:`size-4`})})),(0,$.jsx)(xf,{open:bn,onOpenChange:xn,view:Zt.current,variant:`inline`})]})]}),yi&&mi&&!gi&&(0,$.jsx)(Yo,{currentMode:G===`view`?`preview`:`edit`,onToggle:()=>{Ei(G===`view`?`edit`:`view`)}}),hi&&o(n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Di(Oi()===`preview`?`edit`:`preview`),className:Y(`size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]`,Oi()===`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:n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Oi()===`preview`?`eye`:`eye-off`,className:`size-4`})})),Ao(q?.path??``)&&(0,$.jsx)(Yo,{currentMode:Pi(),onToggle:()=>{ki(Pi()===`preview`?`edit`:`preview`)}}),hi&&Oi()===`preview`&&dr&&(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{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":n(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{lt?dt():st.trim()&&ut(st)},children:lt?(0,$.jsx)(X,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(ra,{sideOffset:8,children:n(lt?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),_i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yo,{currentMode:le,onToggle:()=>Ai(le===`preview`?`edit`:`preview`)}),le===`preview`&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=Pt.current?.getXml();if(At.current&&=(clearTimeout(At.current),null),q?.path&&e){if(!await ji(q.path,e))return;Bt(!0),setTimeout(()=>Bt(!1),1500)}},className:`size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.diagram.saveDiagram`),children:zt?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})]}),fi&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await Xe(st)).ok?(_n(!0),Yt.current!==null&&window.clearTimeout(Yt.current),Yt.current=window.setTimeout(()=>{_n(!1)},1200)):J.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFileContents`),"aria-label":n(`filesView.editor.copyFileContents`),children:gn?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`clipboard`,className:`size-4`})})),pi&&o(n(`filesView.editor.copyFilePathTitle`,{path:ci}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await Xe(ci)).ok?(yn(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{yn(!1)},1200)):J.error(n(`filesView.toast.copyFailed`))},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.copyFilePathTitle`,{path:ci}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:ci}),children:vn?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`file-copy-2`,className:`size-4`})})),r.downloadFile&&o(n(`filesView.editor.saveFile`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>{let e=r.downloadFile;e&&e(q.path).catch(e=>{console.error(`Download failed:`,e),J.error(n(`sidebarFilesTree.toast.operationFailed`))})},className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.saveFile`),"aria-label":n(`filesView.editor.saveFile`),children:(0,$.jsx)(X,{name:`download`,className:`size-4`})})),t?o(n(`filesView.editor.exitFullscreen`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>I(!1),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(`filesView.editor.exitFullscreen`),"aria-label":n(`filesView.editor.exitFullscreen`),children:(0,$.jsx)(X,{name:`fullscreen-exit`,className:`size-4`})})):!d&&e===`full`&&o(n(F?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>I(!F),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(F?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(F?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:F?(0,$.jsx)(X,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(X,{name:`fullscreen`,className:`size-4`})}))]})},ya=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(Vn,{open:Ut,onOpenChange:e=>{e||Wt(!0)},children:(0,$.jsxs)(Rn,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(In,{children:[(0,$.jsx)(zn,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(Bn,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(Ln,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>void Wr(),disabled:Ct,className:`border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]`,children:n(`filesView.unsaved.saveChanges`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:Ur,children:n(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-col flex-shrink-0`,x&&`border-b border-border/40`),children:[x?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[d&&k&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>A(!1),"aria-label":n(`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)(X,{name:`arrow-left-s`,className:`size-5`})}),d?q?(0,$.jsxs)(ha,{children:[(0,$.jsx)(_a,{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":n(`filesView.editor.openFilesAria`),children:[(0,$.jsx)(Ri,{filePath:q.path,extension:q.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(Pf,{name:q.name}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(ca,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:Ne.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(ua,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Vr(e)},className:Y(`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)(Ri,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(Pf,{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(),Gr(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":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(X,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)}):Ne.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[He.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`}),He.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:Ne.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(`div`,{title:jf(b,e.path),className:Y(`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)(Ri,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Vr(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),Gr(e.path)},className:Y(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!h&&`opacity-0 group-hover:opacity-100`),"aria-label":n(`filesView.editor.closeFileAria`,{name:e.name}),children:(0,$.jsx)(X,{name:`close`,className:`size-3.5`})})]},e.path)})})]}):(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:n(`filesView.editor.selectFile`)})]}):null,fr&&!d&&q?(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:[ci?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:ci,children:ci}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:va({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[q&&!ee&&!(fr&&!d)&&(0,$.jsx)(`div`,{ref:U,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{ne.current>0||V(!1)},children:B?va():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[hi?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Di(Oi()===`preview`?`edit`:`preview`),className:Y(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Oi()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Oi()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(Oi()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>V(!0),children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>V(!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":n(`filesView.editor.showControlsAria`),title:n(`filesView.editor.controlsTitle`),children:(0,$.jsx)(X,{name:`more-2-fill`,className:`size-4`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(so,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:q?ft||Zi||$i?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)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.loading`)]}):mt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:mt}):ri&&q?sa(q):ai?da(q):q&&_i&&le===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(Oc,{ref:Pt,xml:Ni,onChange:Mi},`${q.path}:${de}`)}):q&&hi&&Oi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[st.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(st.length/1024)})}),(0,$.jsx)(Ca,{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:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(to,{content:st,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):q&&gi&&se===`preview`?Qi?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground typography-ui-label`,children:n(`common.loading`)}):(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(`iframe`,{src:!Hi&&qi===Ui?(()=>{let e=q.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return s().authenticatedAsset(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`)})():void 0,srcDoc:Hi?(()=>{if(!i.isVSCode)return st;let e=q.path.substring(0,q.path.lastIndexOf(`/`)+1);return e?st.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):st})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},Ji)}):q&&yi&&G===`view`?ma(q,xt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,si&&`overflow-hidden`),ref:Qt,children:[(0,$.jsx)(`div`,{className:Y(`h-full`,si&&`invisible`),children:(0,$.jsx)(Ko,{value:xt,onChange:St,readOnly:!mi,vimMode:lr===`vim`,extensions:Li,className:`h-full`,blockWidgets:pa,onViewReady:e=>{Zt.current=e,li(e),en(e=>e+1),window.requestAnimationFrame(()=>{Fi(e)})},onViewDestroy:()=>{Zt.current&&=null,Cn(!1),En(null),en(e=>e+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:L,highlightLines:Yn?{start:Math.min(Yn.start,Yn.end),end:Math.max(Yn.start,Yn.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(Yn&&!n.shiftKey&&Math.min(Yn.start,Yn.end)===r&&Math.max(Yn.start,Yn.end)===r)return Xn(null),br(),Zn.current=!1,Qn.current=null,er(!1),!0;if(d&&Yn&&!n.shiftKey){let e=Math.min(Yn.start,Yn.end,r),t=Math.max(Yn.start,Yn.end,r);return Xn({start:e,end:t}),Zn.current=!1,Qn.current=null,er(!1),!0}if(Zn.current=!0,Qn.current=r,er(!0),Yn&&n.shiftKey){let e=Math.min(Yn.start,r),t=Math.max(Yn.end,r);Xn({start:e,end:t})}else Xn({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Zn.current||Qn.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Qn.current,r),a=Math.max(Qn.current,r);return Xn({start:i,end:a}),er(!0),!1},mouseup:()=>(Zn.current=!1,Qn.current=null,er(!1),!1)}}})}),si&&(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)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]}):(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:n(`filesView.editor.pickFileFromTree`)})})]})]}),ba=!!(b&&Ke[b]),Sa=b?Ye[b]:null,wa=(0,$.jsxs)(`section`,{className:Y(`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:Y(`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)(X,{name:`search`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground`}),(0,$.jsx)(ta,{ref:O,value:T,onChange:e=>E(e.target.value),placeholder:n(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),T.trim().length>0&&(0,$.jsx)(`button`,{type:`button`,"aria-label":n(`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:()=>{E(``),O.current?.focus()},children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Jn(`createFile`,{path:y,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFileTitle`),"aria-label":n(`filesView.tree.actions.newFileTitle`),children:(0,$.jsx)(X,{name:`file-add`,className:`size-4`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Jn(`createFolder`,{path:y,type:`directory`}),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.newFolderTitle`),"aria-label":n(`filesView.tree.actions.newFolderTitle`),children:(0,$.jsx)(X,{name:`folder-add`,className:`size-4`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void Dr(),className:`size-8 p-0 flex-shrink-0`,title:n(`filesView.tree.actions.refreshTitle`),"aria-label":n(`filesView.tree.actions.refreshTitle`),children:(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:$r,disabled:Yr.length===0&&Se.length===0,className:`size-8 flex-shrink-0 p-0`,title:n(Zr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":n(Zr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(X,{name:Zr?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:6,children:n(Zr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(so,{outerClassName:`flex-1 min-h-0`,className:Y(`py-2`,d?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:at?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):rt.length>0?rt.map(e=>{let t=q?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Vr(e),className:Y(`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:[Gf(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)}):Sa?(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:Sa}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void Dr(),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):ba?ni(b,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),Ta=e===`full`&&F&&q&&(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:va({exitFullscreenOnly:!0})}),(0,$.jsx)(so,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:ft||Zi||$i?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)(X,{name:`loader-4`,className:`size-4 animate-spin`}),`Loading…`]}):mt?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:mt}):ri?sa(q,{fullHeight:!0}):ai?da(q):hi&&Oi()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[st.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:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(st.length/1024)})}),(0,$.jsx)(Ca,{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:n(`filesView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:n(`filesView.error.switchToEditMode`)})]}),children:(0,$.jsx)(to,{content:st,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):yi&&G===`view`?ma(q,xt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,si&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:Y(`h-full`,si&&`invisible`),children:(0,$.jsx)(Ko,{value:xt,onChange:St,readOnly:!mi,vimMode:lr===`vim`,extensions:Li,className:`h-full`,onViewReady:e=>{Zt.current=e,li(e),window.requestAnimationFrame(()=>{Fi(e)})},onViewDestroy:()=>{Zt.current&&=null,Cn(!1),En(null)}})}),si&&(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)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.state.openingFileAtChange`)]})})]})})]})});return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 overflow-hidden bg-background relative`,children:[(0,$.jsx)(Jf,{activeDialog:rn,dialogData:on,dialogInputValue:cn,onDialogInputChange:ln,isDialogSubmitting:un,onDialogSubmit:jr,onClose:fa,inputRef:Ot}),Ta,wn?(0,$.jsx)(zs,{position:wn,onDismiss:()=>En(null),onAddToChat:ui}):null,H.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Sf,{popup:H,onOpenChange:oa,isMobile:d})}):null,d?k?ya:wa: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:ya})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[m>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:wa}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:ya})]})]})};function Qf(e){return e+1}var $f=e=>e,ep=e=>{let t=$f(e).type;return typeof t==`string`?t:``},tp=e=>{let t=$f(e).tool;return typeof t==`string`?t:``},np=e=>{let t=$f(e).text;return typeof t==`string`?t:``},rp=e=>{let t=ep(e);return t===`tool`?tp(e).trim().toLowerCase()||`tool`:t||`unknown`},ip=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=rp(n);t.includes(e)||t.push(e)}return t.join(` + `)},ap=e=>e.replace(/\s+/g,` `).trim(),op=e=>{for(let t of e)if(ep(t)===`text`){let e=ap(np(t));if(e.length===0)continue;return e}let t=e.filter(e=>ep(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},sp=(e,t,n)=>`${n(e)} / ${n(t)}`,cp=(e,t,n,r)=>{let i=sp(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},lp=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},up=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=lp(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}})},dp={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},fp={user:0,assistant:0,tool:0,other:0},pp=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,mp=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{...dp,total:pp(n)};if(!n||typeof n!=`object`)return dp;let r=n,i=pp(r.input),a=pp(r.output),o=pp(r.reasoning),s=pp(r.cache?.read),c=pp(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``},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,_p=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...fp,assistant:gp(n.text)+gp(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: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}},vp=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),yp=e=>{let t=Dr(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},bp=(e,t)=>{if(e.length===0)return{...fp};let n=e.reduce((e,t)=>{let n=yp(t),r={...fp};for(let e of t.parts)r=vp(r,_p(e,n));return vp(e,r)},{...fp});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(Ye()),Sp=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(Ye(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(Ye(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),Cp=(e,t)=>!e||!Number.isFinite(e)?`-`:Da(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),wp=(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}},Tp=()=>{let e=(0,zc.c)(259),{t}=qe(),n=K(Ep),r=K(Dp),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=Pt(Op),d=nn(),f=pn(u??``),p=Et(kp),m;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(Ap),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 Xe(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;if(e[10]!==p||e[11]!==f){S=f.filter(jp);let t;e[20]===f?t=e[21]:(t=f.filter(Mp),e[20]=f,e[21]=t),k=t;let n=null;for(let e=S.length-1;e>=0;--e){let t=S[e];if(mp(t).total>0){n=t;break}}D=n?mp(n):dp,C=bi({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),O=S.reduce(Np,0);let r=0,i=0;for(let e of S){let t=mp(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=Ei(n,a,e.parts);if(o===null)continue;let s=t.output+t.reasoning;s<=0||(r+=s,i+=o)}let a=i>0&&r>0?r/(i/1e3):null,o;e[22]===a?o=e[23]:(o=a===null?null:Mr(a),e[22]=a,e[23]=o),T=o;let s=n?Nr({createdAt:n.info.time?.created??null,completedAt:n.info.time?.completed??null,outputTokens:D.output,reasoningTokens:D.reasoning,parts:n.parts}):null;w=s===null?null:Mr(s);let c=n?.info??null;E=wp(p,c?.providerID||``,c?.modelID||``),e[10]=p,e[11]=f,e[12]=S,e[13]=C,e[14]=w,e[15]=T,e[16]=E,e[17]=D,e[18]=O,e[19]=k}else S=e[12],C=e[13],w=e[14],T=e[15],E=e[16],D=e[17],O=e[18],k=e[19];let A=E,j=A.contextLimit,M=j&&j>0?Math.min(999,D.total/j*100):0,N;e[24]===f?N=e[25]:(N=bp(f,[...f].reverse().find(Pp)?.info?.system||``),e[24]=f,e[25]=N);let P=N,F=P.user,I=P.assistant,ee=P.tool,L=Math.max(0,D.input-F-I-ee),R=F+I+ee+L,z=f[0]?.info?.time?.created,B=f.length>0?f[f.length-1]?.info?.time?.created:null,V;e[26]!==x?.title||e[27]!==t?(V=x?.title||t(`contextSidebar.session.untitled`),e[26]=x?.title,e[27]=t,e[28]=V):V=e[28];let H=x?.time?.created??z??null,te=B??x?.time?.created??null,U=T&&T.length>0?T:null,ne=w&&w.length>0?w:null,W;e[29]!==I||e[30]!==L||e[31]!==ee||e[32]!==F?(W={user:F,assistant:I,tool:ee,other:L},e[29]=I,e[30]=L,e[31]=ee,e[32]=F,e[33]=W):W=e[33];let re;e[34]!==S.length||e[35]!==R||e[36]!==C||e[37]!==j||e[38]!==A||e[39]!==f.length||e[40]!==H||e[41]!==te||e[42]!==U||e[43]!==ne||e[44]!==W||e[45]!==V||e[46]!==D||e[47]!==O||e[48]!==M||e[49]!==k.length?(re={sessionTitle:V,messagesCount:f.length,userMessagesCount:k.length,assistantMessagesCount:S.length,createdAt:H,lastActivityAt:te,providerModel:A,tokenBreakdown:D,usagePercent:M,cacheHitRate:C,totalAssistantCost:O,sessionTpsLabel:U,lastAssistantTpsLabel:ne,contextLimit:j,breakdown:W,breakdownTotal:R},e[34]=S.length,e[35]=R,e[36]=C,e[37]=j,e[38]=A,e[39]=f.length,e[40]=H,e[41]=te,e[42]=U,e[43]=ne,e[44]=W,e[45]=V,e[46]=D,e[47]=O,e[48]=M,e[49]=k.length,e[50]=re):re=e[50];let G=re;if(!u){let n;e[51]===t?n=e[52]:(n=t(`contextSidebar.empty.openSession`),e[51]=t,e[52]=n);let r;return e[53]===n?r=e[54]:(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[53]=n,e[54]=r),r}let ie;e[55]===t?ie=e[56]:(ie=t(`contextSidebar.breakdown.user`),e[55]=t,e[56]=ie);let ae;e[57]!==ie||e[58]!==G.breakdown.user?(ae={key:`user`,label:ie,value:G.breakdown.user,color:`var(--status-success)`},e[57]=ie,e[58]=G.breakdown.user,e[59]=ae):ae=e[59];let oe;e[60]===t?oe=e[61]:(oe=t(`contextSidebar.breakdown.assistant`),e[60]=t,e[61]=oe);let se;e[62]!==oe||e[63]!==G.breakdown.assistant?(se={key:`assistant`,label:oe,value:G.breakdown.assistant,color:`var(--primary-base)`},e[62]=oe,e[63]=G.breakdown.assistant,e[64]=se):se=e[64];let ce;e[65]===t?ce=e[66]:(ce=t(`contextSidebar.breakdown.toolCalls`),e[65]=t,e[66]=ce);let le;e[67]!==ce||e[68]!==G.breakdown.tool?(le={key:`tool`,label:ce,value:G.breakdown.tool,color:`var(--status-warning)`},e[67]=ce,e[68]=G.breakdown.tool,e[69]=le):le=e[69];let ue;e[70]===t?ue=e[71]:(ue=t(`contextSidebar.breakdown.other`),e[70]=t,e[71]=ue);let de;e[72]!==ue||e[73]!==G.breakdown.other?(de={key:`other`,label:ue,value:G.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=ue,e[73]=G.breakdown.other,e[74]=de):de=e[74];let fe;e[75]!==ae||e[76]!==se||e[77]!==le||e[78]!==de?(fe=[ae,se,le,de],e[75]=ae,e[76]=se,e[77]=le,e[78]=de,e[79]=fe):fe=e[79];let pe=fe,me;e[80]===G.sessionTitle?me=e[81]:(me=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:G.sessionTitle}),e[80]=G.sessionTitle,e[81]=me);let he;e[82]!==G.providerModel.modelName||e[83]!==G.providerModel.providerName?(he=(0,$.jsxs)(`span`,{children:[G.providerModel.providerName,` / `,G.providerModel.modelName]}),e[82]=G.providerModel.modelName,e[83]=G.providerModel.providerName,e[84]=he):he=e[84];let ge;e[85]!==n||e[86]!==G.createdAt?(ge=G.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:Cp(G.createdAt,n)})]}),e[85]=n,e[86]=G.createdAt,e[87]=ge):ge=e[87];let _e;e[88]!==he||e[89]!==ge?(_e=(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:[he,ge]}),e[88]=he,e[89]=ge,e[90]=_e):_e=e[90];let ve;e[91]!==me||e[92]!==_e?(ve=(0,$.jsxs)(`div`,{className:`mb-6`,children:[me,_e]}),e[91]=me,e[92]=_e,e[93]=ve):ve=e[93];let ye;e[94]===t?ye=e[95]:(ye=t(`contextSidebar.section.context`),e[94]=t,e[95]=ye);let be;e[96]===ye?be=e[97]:(be=(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ye}),e[96]=ye,e[97]=be);let xe;e[98]===G.tokenBreakdown.total?xe=e[99]:(xe=xp(G.tokenBreakdown.total),e[98]=G.tokenBreakdown.total,e[99]=xe);let Se;e[100]===G.contextLimit?Se=e[101]:(Se=G.contextLimit?` / ${xp(G.contextLimit)}`:``,e[100]=G.contextLimit,e[101]=Se);let Ce;e[102]!==xe||e[103]!==Se?(Ce=(0,$.jsxs)(`span`,{className:`typography-micro tabular-nums text-muted-foreground/70`,children:[xe,Se]}),e[102]=xe,e[103]=Se,e[104]=Ce):Ce=e[104];let we;e[105]!==be||e[106]!==Ce?(we=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[be,Ce]}),e[105]=be,e[106]=Ce,e[107]=we):we=e[107];let Te;e[108]===G.usagePercent?Te=e[109]:(Te=G.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,G.usagePercent)}%`,backgroundColor:G.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=G.usagePercent,e[109]=Te);let Ee;e[110]===Te?Ee=e[111]:(Ee=(0,$.jsx)(`div`,{className:`mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:Te}),e[110]=Te,e[111]=Ee);let De;e[112]!==t||e[113]!==G.usagePercent?(De=t(`contextSidebar.context.percentUsed`,{percent:G.usagePercent.toFixed(1)}),e[112]=t,e[113]=G.usagePercent,e[114]=De):De=e[114];let Oe;e[115]===De?Oe=e[116]:(Oe=(0,$.jsx)(`div`,{className:`mt-1.5 typography-micro font-medium tabular-nums text-foreground/80`,children:De}),e[115]=De,e[116]=Oe);let ke;e[117]!==we||e[118]!==Ee||e[119]!==Oe?(ke=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[we,Ee,Oe]}),e[117]=we,e[118]=Ee,e[119]=Oe,e[120]=ke):ke=e[120];let Ae;e[121]===t?Ae=e[122]:(Ae=t(`contextSidebar.stats.messages`),e[121]=t,e[122]=Ae);let je;e[123]===G.messagesCount?je=e[124]:(je=xp(G.messagesCount),e[123]=G.messagesCount,e[124]=je);let Me;e[125]!==Ae||e[126]!==je?(Me={label:Ae,value:je},e[125]=Ae,e[126]=je,e[127]=Me):Me=e[127];let Ne;e[128]===t?Ne=e[129]:(Ne=t(`contextSidebar.stats.user`),e[128]=t,e[129]=Ne);let Pe;e[130]===G.userMessagesCount?Pe=e[131]:(Pe=xp(G.userMessagesCount),e[130]=G.userMessagesCount,e[131]=Pe);let q;e[132]!==Ne||e[133]!==Pe?(q={label:Ne,value:Pe},e[132]=Ne,e[133]=Pe,e[134]=q):q=e[134];let Fe;e[135]===t?Fe=e[136]:(Fe=t(`contextSidebar.stats.assistant`),e[135]=t,e[136]=Fe);let Ie;e[137]===G.assistantMessagesCount?Ie=e[138]:(Ie=xp(G.assistantMessagesCount),e[137]=G.assistantMessagesCount,e[138]=Ie);let Le;e[139]!==Fe||e[140]!==Ie?(Le={label:Fe,value:Ie},e[139]=Fe,e[140]=Ie,e[141]=Le):Le=e[141];let Re;e[142]!==Me||e[143]!==q||e[144]!==Le?(Re=[Me,q,Le],e[142]=Me,e[143]=q,e[144]=Le,e[145]=Re):Re=e[145];let ze=Re,Be;e[146]===ze?Be=e[147]:(Be=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:ze.map(Fp)}),e[146]=ze,e[147]=Be);let Ve=r?`grid-cols-2`:`grid-cols-1`,He;e[148]===Ve?He=e[149]:(He=Y(`grid gap-2`,Ve),e[148]=Ve,e[149]=He);let Ue;e[150]===t?Ue=e[151]:(Ue=t(`contextSidebar.stats.cost`),e[150]=t,e[151]=Ue);let We;e[152]===Ue?We=e[153]:(We=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:Ue}),e[152]=Ue,e[153]=We);let Ge;e[154]===G.totalAssistantCost?Ge=e[155]:(Ge=Sp(G.totalAssistantCost),e[154]=G.totalAssistantCost,e[155]=Ge);let Ke;e[156]===Ge?Ke=e[157]:(Ke=(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:Ge}),e[156]=Ge,e[157]=Ke);let Je;e[158]!==We||e[159]!==Ke?(Je=(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[We,Ke]}),e[158]=We,e[159]=Ke,e[160]=Je):Je=e[160];let Ye;e[161]!==r||e[162]!==t||e[163]!==G.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:G.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=G.sessionTpsLabel,e[164]=Ye):Ye=e[164];let Ze;e[165]!==He||e[166]!==Je||e[167]!==Ye?(Ze=(0,$.jsxs)(`div`,{className:He,children:[Je,Ye]}),e[165]=He,e[166]=Je,e[167]=Ye,e[168]=Ze):Ze=e[168];let Qe;e[169]!==Be||e[170]!==Ze?(Qe=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Be,Ze]}),e[169]=Be,e[170]=Ze,e[171]=Qe):Qe=e[171];let $e;e[172]===t?$e=e[173]:($e=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=$e);let et;e[174]===$e?et=e[175]:(et=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:$e}),e[174]=$e,e[175]=et);let tt;e[176]===t?tt=e[177]:(tt=t(`contextSidebar.tokens.input`),e[176]=t,e[177]=tt);let nt;e[178]!==tt||e[179]!==G.tokenBreakdown.input?(nt={label:tt,value:G.tokenBreakdown.input,format:`count`},e[178]=tt,e[179]=G.tokenBreakdown.input,e[180]=nt):nt=e[180];let rt;e[181]===t?rt=e[182]:(rt=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=rt);let it;e[183]!==rt||e[184]!==G.tokenBreakdown.output?(it={label:rt,value:G.tokenBreakdown.output,format:`count`},e[183]=rt,e[184]=G.tokenBreakdown.output,e[185]=it):it=e[185];let at;e[186]===t?at=e[187]:(at=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=at);let ot;e[188]!==at||e[189]!==G.tokenBreakdown.reasoning?(ot={label:at,value:G.tokenBreakdown.reasoning,format:`count`},e[188]=at,e[189]=G.tokenBreakdown.reasoning,e[190]=ot):ot=e[190];let st;e[191]===t?st=e[192]:(st=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=st);let ct;e[193]!==st||e[194]!==G.tokenBreakdown.cacheRead?(ct={label:st,value:G.tokenBreakdown.cacheRead,format:`count`},e[193]=st,e[194]=G.tokenBreakdown.cacheRead,e[195]=ct):ct=e[195];let lt;e[196]===t?lt=e[197]:(lt=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=lt);let ut;e[198]!==lt||e[199]!==G.tokenBreakdown.cacheWrite?(ut={label:lt,value:G.tokenBreakdown.cacheWrite,format:`count`},e[198]=lt,e[199]=G.tokenBreakdown.cacheWrite,e[200]=ut):ut=e[200];let dt;e[201]===t?dt=e[202]:(dt=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=dt);let ft=G.cacheHitRate.hasInput?G.cacheHitRate.percent:null,pt;e[203]!==dt||e[204]!==ft?(pt={label:dt,value:ft,format:`percent`},e[203]=dt,e[204]=ft,e[205]=pt):pt=e[205];let mt;e[206]!==r||e[207]!==t||e[208]!==G.lastAssistantTpsLabel?(mt=r?[{label:t(`contextSidebar.tokens.tps`),value:G.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=G.lastAssistantTpsLabel,e[209]=mt):mt=e[209];let ht;e[210]!==nt||e[211]!==it||e[212]!==ot||e[213]!==ct||e[214]!==ut||e[215]!==pt||e[216]!==mt?(ht=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[nt,it,ot,ct,ut,pt,...mt].map(Ip)}),e[210]=nt,e[211]=it,e[212]=ot,e[213]=ct,e[214]=ut,e[215]=pt,e[216]=mt,e[217]=ht):ht=e[217];let gt;e[218]!==et||e[219]!==ht?(gt=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[et,ht]}),e[218]=et,e[219]=ht,e[220]=gt):gt=e[220];let _t;e[221]!==pe||e[222]!==G.breakdownTotal?(_t=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:pe.map(e=>e.value<=0||G.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/G.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=pe,e[222]=G.breakdownTotal,e[223]=_t):_t=e[223];let vt;e[224]!==pe||e[225]!==G.breakdownTotal?(vt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:pe.map(e=>{let t=G.breakdownTotal>0?e.value/G.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[224]=pe,e[225]=G.breakdownTotal,e[226]=vt):vt=e[226];let yt;e[227]!==_t||e[228]!==vt?(yt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[_t,vt]}),e[227]=_t,e[228]=vt,e[229]=yt):yt=e[229];let bt;e[230]===t?bt=e[231]:(bt=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=bt);let xt;e[232]===bt?xt=e[233]:(xt=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:bt}),e[232]=bt,e[233]=xt);let St;if(e[234]!==s||e[235]!==a||e[236]!==f||e[237]!==r||e[238]!==t||e[239]!==n){let i;e[241]!==s||e[242]!==a||e[243]!==r||e[244]!==t||e[245]!==n?(i=e=>{let i=Dr(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=e.info.time?.completed??null,m=ip(e.parts),h=c?mp({info:e.info,parts:e.parts}):null,g=l?op(e.parts):``,_=up(f,n),v=m||`—`,b=(()=>{if(!r||!c||!h)return null;let t=Nr({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=Mr(t);return n.length>0?n:null})(),x=h?cp(h.input,h.output,xp,b):``,S=i||`unknown`,C=m?`${S}: ${m}`:S,w=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:`}),` `,g]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:c?v:C}),c&&(0,$.jsx)(`span`,{className:`text-right text-muted-foreground tabular-nums`,children:x})]}),(0,$.jsx)(`span`,{className:`text-right text-muted-foreground`,children:_})]})}),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,w)},"aria-label":t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copyJson`),title:t(d?`contextSidebar.actions.copied`:`contextSidebar.actions.copy`),children:d?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`})})}),(0,$.jsx)(Io,{language:`json`,code:w,style:{margin:0,padding:`0.75rem`,background:`transparent`,fontSize:`var(--text-micro)`,lineHeight:`1.35`},wrap:!0})]})})]},e.info.id)},e[241]=s,e[242]=a,e[243]=r,e[244]=t,e[245]=n,e[246]=i):i=e[246],St=[...f].reverse().map(i),e[234]=s,e[235]=a,e[236]=f,e[237]=r,e[238]=t,e[239]=n,e[240]=St}else St=e[240];let Ct;e[247]===St?Ct=e[248]:(Ct=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:St}),e[247]=St,e[248]=Ct);let wt;e[249]!==xt||e[250]!==Ct?(wt=(0,$.jsxs)(`div`,{children:[xt,Ct]}),e[249]=xt,e[250]=Ct,e[251]=wt):wt=e[251];let Tt;return e[252]!==ve||e[253]!==ke||e[254]!==Qe||e[255]!==gt||e[256]!==yt||e[257]!==wt?(Tt=(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:[ve,ke,Qe,gt,yt,wt]})}),e[252]=ve,e[253]=ke,e[254]=Qe,e[255]=gt,e[256]=yt,e[257]=wt,e[258]=Tt):Tt=e[258],Tt};function Ep(e){return e.timeFormatPreference}function Dp(e){return e.showAssistantTps}function Op(e){return e.currentSessionId}function kp(e){return e.providers}function Ap(e){return Object.keys(e).length>0?{}:e}function jp(e){return Dr(e.info).role===`assistant`}function Mp(e){return Dr(e.info).isUser}function Np(e,t){return e+pp(t.info.cost)}function Pp(e){return Dr(e.info).isUser&&typeof e.info.system==`string`}function Fp(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 Ip(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 Lp=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(`/`)?`/`:``)},Rp=()=>`react-surface`,zp=(e,t)=>JSON.stringify([Lp(e),t]),Bp=(e,t,n,r)=>JSON.stringify([e,t,Lp(n),r]),Vp=(e,t,n)=>n?t:e===t?e:null,Hp=(e,t)=>e.sessionId===t.sessionId&&Lp(e.directory)===Lp(t.directory),Up=(e,t)=>Lp(e)===Lp(t),Wp=e=>({anchor:e,current:e,stack:[]}),Gp=(e,t)=>e??Wp(t),Kp=(e,t)=>e?.current.sessionId??t,qp=(e,t)=>Hp(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},Jp=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Yp=(e,t,n)=>!Up(e.anchor.directory,t.directory)||!Up(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:qp(e,t)},Xp=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Yp(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Zp=(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},Qp=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`,$p=e=>e===`retry`,em=e=>e.active&&e.visible&&e.messageCount<=0,tm=e=>e?`load-more`:`ensure`,nm=e=>e.kind===`has-more`,rm=(e,t)=>`${e}\n${t}`,im=(e,t,n,r)=>r&&!e.has(rm(t,n)),am=(e,t)=>({scrollHeight:e,scrollTop:t}),om=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),sm=(e,t)=>e&&!t,cm=e=>e,lm=e=>!e,um=e=>!sm(e.hasMore,e.isLoading)||!lm(e.historyVirtualized)?null:am(e.scrollHeight,e.scrollTop),dm=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),fm=33554432,pm=e=>Math.min(fm,262144+Math.max(0,Math.ceil(e))*64*1024),mm=e=>Math.min(fm,Math.max(0,Math.round(Number.isFinite(e)?e:0))),hm=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}},gm=(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 hm({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=mm(t.estimatedBytes);return!n||n.estimatedBytes===r?e:hm({...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:hm({...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??pm(0),lastAccessed:t.now}}})},_m={overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},vm={scrollbar:`chat`,scrollShadow:`true`,orientation:`vertical`},ym=e=>{let t=(0,zc.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=qe();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)(X,{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)(Z,{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},bm=e=>{let t=(0,zc.c)(193),{surfaceId:n,sessionId:r,directory:i,active:a,canNavigateBack:o,onNavigateSession:s,onNavigateBack:c,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=qe(),p=Kr(),m,h,g;t[0]!==i||t[1]!==r||t[2]!==n?(h=l(),m=Lp(i),g=Bp(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,d),E=pn(r,d),D=Et(Sm),O;t[7]===E?O=t[8]:(O=zi(E),t[7]=E,t[8]=O);let k=O,A;bb0:{if(!k.modelId){let e;t[9]===f?e=t[10]:(e=f(`common.unavailable`),t[9]=f,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)&&vt(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=en(r,d),N=Vt(r,d).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=at(P,d),[I,ee]=Q.useState(null),L,R;t[19]!==F||t[20]!==_?(L=()=>{ee(e=>Vp(e,_,F))},R=[F,_],t[19]=F,t[20]=_,t[21]=L,t[22]=R):(L=t[21],R=t[22]),Q.useLayoutEffect(L,R);let z=F||I===_,B=an(r,d),V;t[23]===r?V=t[24]:(V=e=>e.streamingMessageIds.get(r)??null,t[23]=r,t[24]=V);let H=wn(V),te;t[25]===H?te=t[26]:(te=e=>H?e.messageStreamStates.get(H)?.phase??null:null,t[25]=H,t[26]=te);let U=wn(te),ne=M?.type===`busy`||M?.type===`retry`,W=eo(Cm),[re,G]=Q.useState(!1),[ie,ae]=Q.useState(!1),[oe,se]=Q.useState(0),ce=a&&!W,le;t[27]!==r||t[28]!==ne||t[29]!==T||t[30]!==ce||t[31]!==_?(le={enabled:ce,currentSessionId:r,viewportKey:_,sessionMessageCount:T,sessionIsWorking:ne,isMobile:!1},t[27]=r,t[28]=ne,t[29]=T,t[30]=ce,t[31]=_,t[32]=le):le=t[32];let{scrollRef:ue,notifyContentChange:de,getAnimationHandlers:fe,goToBottom:pe,restoreSnapshot:me,showScrollButton:he}=Or(le),ge;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ge=()=>{G(!1),ae(!1)},t[33]=ge):ge=t[33];let _e;t[34]===r?_e=t[35]:(_e=[r],t[34]=r,t[35]=_e),Q.useEffect(ge,_e);let ve;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(e,t)=>{e&&ae(!1),t!==void 0&&G(t)},t[36]=ve):ve=t[36];let ye=He(ve),be;t[37]===pe?be=t[38]:(be=e=>{let t=e===void 0?`instant`:e;ae(!1),v.current?.scrollToBottom(),pe(t)},t[37]=pe,t[38]=be);let xe=He(be),Se;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(Se=()=>{ae(!0)},t[39]=Se):Se=t[39];let Ce=He(Se),we;t[40]!==Ce||t[41]!==W||t[42]!==ue?(we={scrollRef:ue,enabled:W,onUpwardIntent:Ce},t[40]=Ce,t[41]=W,t[42]=ue,t[43]=we):we=t[43],Ro(we);let Te;t[44]!==r||t[45]!==p?(Te=e=>{p.ensureSessionRenderable(r,$p(e))},t[44]=r,t[45]=p,t[46]=Te):Te=t[46];let Ee=He(Te),De,Oe;t[47]!==a||t[48]!==Ee?(De=()=>{a&&Ee(`active`)},Oe=[a,Ee],t[47]=a,t[48]=Ee,t[49]=De,t[50]=Oe):(De=t[49],Oe=t[50]),Q.useEffect(De,Oe);let ke,Ae;t[51]!==a||t[52]!==Ee||t[53]!==T?(ke=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();em({active:a,visible:e,messageCount:T})&&Ee(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},Ae=[a,Ee,T],t[51]=a,t[52]=Ee,t[53]=T,t[54]=ke,t[55]=Ae):(ke=t[54],Ae=t[55]),Q.useEffect(ke,Ae);let je,K;t[56]!==u||t[57]!==T||t[58]!==_?(je=()=>{u?.(_,pm(T))},K=[u,T,_],t[56]=u,t[57]=T,t[58]=_,t[59]=je,t[60]=K):(je=t[59],K=t[60]),Q.useEffect(je,K);let Me,Ne;t[61]!==N||t[62]!==me||t[63]!==r||t[64]!==_?(Me=()=>{if(!im(w.current,r,_,N))return;let e=rm(r,_);w.current.add(e),me()},Ne=[N,me,r,_],t[61]=N,t[62]=me,t[63]=r,t[64]=_,t[65]=Me,t[66]=Ne):(Me=t[65],Ne=t[66]),Q.useEffect(Me,Ne);let Pe;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=()=>{y.current=null,S(null)},t[67]=Pe):Pe=t[67];let q;t[68]===_?q=t[69]:(q=[_],t[68]=_,t[69]=q),Q.useLayoutEffect(Pe,q);let Fe;t[70]!==x||t[71]!==ue||t[72]!==_?(Fe=()=>{let e=y.current,t=ue.current;if(dm(e,x,_)){if(!t||!lm(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=om(e.anchor,t.scrollHeight),y.current=null}},t[70]=x,t[71]=ue,t[72]=_,t[73]=Fe):Fe=t[73];let Le;t[74]!==x||t[75]!==ue||t[76]!==E||t[77]!==_?(Le=[x,ue,E,_],t[74]=x,t[75]=ue,t[76]=E,t[77]=_,t[78]=Le):Le=t[78],Q.useLayoutEffect(Fe,Le);let Re;t[79]===m?Re=t[80]:(Re={directory:m},t[79]=m,t[80]=Re);let ze=Re,Be=dn(r,d).boundary,Ve;t[81]===Be?Ve=t[82]:(Ve=nm(Be),t[81]=Be,t[82]=Ve);let Ue=Ve,We;t[83]!==B?.status||t[84]!==ze||t[85]!==r||t[86]!==p?(We=B?.status===`loading`||p.isLoading(r,ze),t[83]=B?.status,t[84]=ze,t[85]=r,t[86]=p,t[87]=We):We=t[87];let Ge=We,Ke;t[88]!==m||t[89]!==h||t[90]!==r?(Ke=[`context-panel-load-older`,h,m,r],t[88]=m,t[89]=h,t[90]=r,t[91]=Ke):Ke=t[91];let Je;t[92]!==Be||t[93]!==r||t[94]!==d?(Je=async()=>{Be.kind===`unknown`&&await $t(d,r),await xn(d,r)},t[92]=Be,t[93]=r,t[94]=d,t[95]=Je):Je=t[95];let Ye;t[96]!==Ke||t[97]!==Je?(Ye={mutationKey:Ke,mutationFn:Je},t[96]=Ke,t[97]=Je,t[98]=Ye):Ye=t[98];let Xe=Ie(Ye),Ze=Xe.isPending,Qe;t[99]!==Ge||t[100]!==Ue||t[101]!==Ze||t[102]!==W||t[103]!==Xe||t[104]!==ue||t[105]!==f||t[106]!==_?(Qe=()=>{if(!sm(Ue,Ze||Ge)||Xe.isPending)return;W&&se(wm);let e=b.current+1;b.current=e;let t=ue.current,n=t?um({hasMore:Ue,isLoading:Ze,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,Xe.mutateAsync().then(()=>{S(e)},()=>{S(e),J.error(f(`chat.history.loadOlderFailed`))})},t[99]=Ge,t[100]=Ue,t[101]=Ze,t[102]=W,t[103]=Xe,t[104]=ue,t[105]=f,t[106]=_,t[107]=Qe):Qe=t[107];let $e=He(Qe),et=B?.status===`error`?B.error:void 0,tt;t[108]!==a||t[109]!==N||t[110]!==ne||t[111]!==E.length||t[112]!==et?(tt=Qp({directoryMatches:!0,requested:a,renderable:N,messageCount:E.length,working:ne,error:et}),t[108]=a,t[109]=N,t[110]=ne,t[111]=E.length,t[112]=et,t[113]=tt):tt=t[113];let nt=tt,rt;t[114]!==a||t[115]!==m||t[116]!==s||t[117]!==r||t[118]!==n?(rt={kind:`panel`,surfaceId:n,sessionId:r,directory:m,active:a,capabilities:ci,navigateSession:s},t[114]=a,t[115]=m,t[116]=s,t[117]=r,t[118]=n,t[119]=rt):rt=t[119];let it=rt,ot;t[120]!==Ee||t[121]!==Ue||t[122]!==$e?(ot=()=>{if(tm(Ue)===`load-more`){$e();return}Ee(`retry`)},t[120]=Ee,t[121]=Ue,t[122]=$e,t[123]=ot):ot=t[123];let st=He(ot),ct;t[124]!==B?.error||t[125]!==st||t[126]!==f||t[127]!==nt?(ct=nt===`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:B?.error}),(0,$.jsx)(Z,{type:`button`,variant:`secondary`,size:`xs`,onClick:st,children:f(`chat.history.retry`)})]}):null,t[124]=B?.error,t[125]=st,t[126]=f,t[127]=nt,t[128]=ct):ct=t[128];let lt=ct,ut;t[129]!==Ue||t[130]!==Ze||t[131]!==$e||t[132]!==f?(ut=cm(Ue)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,onClick:$e,disabled:Ze,children:[Ze?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,t[129]=Ue,t[130]=Ze,t[131]=$e,t[132]=f,t[133]=ut):ut=t[133];let dt=ut,ft;t[134]===Symbol.for(`react.memo_cache_sentinel`)?(ft=(0,$.jsx)(`div`,{className:`flex-shrink-0`,style:{height:Jr},"aria-hidden":`true`}),t[134]=ft):ft=t[134];let pt=ft,mt;t[135]===xe?mt=t[136]:(mt=()=>xe(`instant`),t[135]=xe,t[136]=mt);let ht=!ie,gt;t[137]!==W||t[138]!==dt||t[139]!==lt?(gt=W?(0,$.jsxs)($.Fragment,{children:[lt,dt]}):void 0,t[137]=W,t[138]=dt,t[139]=lt,t[140]=gt):gt=t[140];let _t=W?pt:void 0,yt;t[141]!==U||t[142]!==fe||t[143]!==ye||t[144]!==Ze||t[145]!==de||t[146]!==ue||t[147]!==r||t[148]!==ne||t[149]!==E||t[150]!==H||t[151]!==d||t[152]!==mt||t[153]!==ht||t[154]!==gt||t[155]!==_t||t[156]!==oe||t[157]!==_?(yt=(0,$.jsx)(Zr,{ref:v,sessionKey:r,virtualizerKey:_,messages:E,sessionIsWorking:ne,activeStreamingMessageId:H,activeStreamingPhase:U,onMessageContentChange:de,getAnimationHandlers:fe,isLoadingOlder:Ze,scrollToBottom:mt,scrollRef:ue,directory:d,enableSendPark:!1,timelineScrollClassName:`absolute inset-0 z-0 chat-scroll overlay-scrollbar-target`,timelineScrollStyle:_m,timelineScrollDataset:vm,timelineFollowEnabled:ht,timelineHistoryAnchorToken:oe,timelineOnIsAtEndChange:ye,headerSlot:gt,footerSlot:_t}),t[141]=U,t[142]=fe,t[143]=ye,t[144]=Ze,t[145]=de,t[146]=ue,t[147]=r,t[148]=ne,t[149]=E,t[150]=H,t[151]=d,t[152]=mt,t[153]=ht,t[154]=gt,t[155]=_t,t[156]=oe,t[157]=_,t[158]=yt):yt=t[158];let bt=yt,xt=W?re:he,St;t[159]===xe?St=t[160]:(St=()=>xe(`smooth`),t[159]=xe,t[160]=St);let Ct;t[161]!==xt||t[162]!==St?(Ct=(0,$.jsx)(ji,{visible:xt,onClick:St}),t[161]=xt,t[162]=St,t[163]=Ct):Ct=t[163];let wt=Ct,Tt;t[164]!==o||t[165]!==c||t[166]!==f?(Tt=o?(0,$.jsxs)(Z,{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":f(`chat.container.returnToParent.aria`),title:f(`chat.container.returnToParent.title`),children:[(0,$.jsx)(X,{name:`arrow-left`,className:`h-4 w-4`}),f(`chat.container.returnToParent.label`)]}):null,t[164]=o,t[165]=c,t[166]=f,t[167]=Tt):Tt=t[167];let Dt;t[168]!==Ee||t[169]!==W||t[170]!==dt||t[171]!==lt||t[172]!==B?.error||t[173]!==ue||t[174]!==wt||t[175]!==bt||t[176]!==nt?(Dt=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:nt===`cold-loading`||nt===`working-empty`||nt===`authoritative-empty`||nt===`fatal-error`?(0,$.jsx)(ym,{state:nt,error:B?.error,onRetry:()=>Ee(`retry`)}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[bt,(0,$.jsx)(La,{containerRef:ue,userIntentOnly:!0,observeMutations:!1})]}),wt]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(co,{ref:ue,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:[lt,dt,bt,pt]})}),wt]})}),t[168]=Ee,t[169]=W,t[170]=dt,t[171]=lt,t[172]=B?.error,t[173]=ue,t[174]=wt,t[175]=bt,t[176]=nt,t[177]=Dt):Dt=t[177];let Ot;t[178]!==k.agentName||t[179]!==k.modelId||t[180]!==k.providerId||t[181]!==j||t[182]!==z?(Ot=z?(0,$.jsx)($r,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[178]=k.agentName,t[179]=k.modelId,t[180]=k.providerId,t[181]=j,t[182]=z,t[183]=Ot):Ot=t[183];let kt;t[184]!==r||t[185]!==n||t[186]!==Tt||t[187]!==Dt||t[188]!==Ot?(kt=(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:[Tt,Dt,Ot]}),t[184]=r,t[185]=n,t[186]=Tt,t[187]=Dt,t[188]=Ot,t[189]=kt):kt=t[189];let At;return t[190]!==it||t[191]!==kt?(At=(0,$.jsx)(Ti.Provider,{value:it,children:kt}),t[190]=it,t[191]=kt,t[192]=At):At=t[192],At},xm=e=>{let t=(0,zc.c)(22),n=Kt(),{t:r}=qe(),i;t[0]===e.directory?i=t[1]:(i=Lp(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===Lp(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:ci,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)(ym,{state:`directory-mismatch`,onRetry:Tm,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)(Ti.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)(bm,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function Sm(e){return e.providers}function Cm(e){return e.legendTimelineEnabled}function wm(e){return e+1}function Tm(){}var Em=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},Dm=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),Om=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`&&Em(t.center)&&Dm(t.attributes)&&Dm(t.computedStyle)&&Array.isArray(t.ancestry)},km=({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
|
-
`)},Am=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await ee(`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 sh(e,t)},jm=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}},Mm=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,Nm=new Map,Pm=new Map,Fm=3e4,Im=e=>{let t=Nm.get(e);return t?t.expiresAt-Date.now()<=Fm?(Nm.delete(e),null):t:null},Lm=e=>{try{return new URL(e).origin}catch{return e}};function Rm(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 zm=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:Mm),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),Bm=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await zm(n)).split(`,`,2)[1]||``},Vm=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Hm=(...e)=>{Vm()&&[...e]},Um=(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},Wm=`data-oc-fixed-pin`,Gm=(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(Wm,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 Hm(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(Wm)}catch{}}},Km={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${Wm}]`)){let t;try{t=JSON.parse(e.getAttribute(Wm)||``)}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(Wm)}}},qm=`data-oc-scroll-pin`,Jm=e=>{let t=[],n=Um(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(qm,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(qm)}catch{}},snapshot:n}},Ym={name:`oc-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(`[${qm}]`)){let t;try{t=JSON.parse(e.getAttribute(qm)||``)}catch{e.removeAttribute(qm);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(qm)}}},Xm=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await zm(await n.blob()):null}catch{return null}},Zm=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=Im(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=Pm.get(t),i=r??(async()=>{try{let n=await f(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return Nm.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 Nm.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return Nm.set(t,o),o}catch{return Nm.delete(t),null}finally{Pm.delete(t)}})();r||Pm.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Qm=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 Xm(n.toString(),`include`)??Mm;let r=await Zm(n);return(r?await Xm(r,`include`):null)||(await Xm(n.toString(),`omit`)??Mm)}catch{return Mm}},$m=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 Qm(n,t);r=r.replace(e[0],`url("${i}")`)}return r},eh=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),th=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},nh=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},rh=(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<=nh(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(th(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]?.()}},ih=(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(th(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]?.()}},ah=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(ih(e,t,n,r)),i.push(rh(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 eh(t);let r=await Qm(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||Mm),await eh(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 $m(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 oh(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);Hm(`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:Um(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=Jm(r);Hm(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await ah(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=Gm(r,S,C),k.reapply();let e={backgroundColor:Rm(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Km,Ym],quality:.82,width:w},a=await(await Fc(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)));Hm(`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 Bm(g,.82);return v?await jm(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 sh(e,t){let n=await oh(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 ah(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await Lc(i).catch(()=>``);h=await Ic(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:Rm(r),imagePlaceholder:Mm,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 jm(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var ch=380,lh=1400,uh=600,dh=24,fh=new Map,ph=200,mh=(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`,hh=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},gh=e=>Number.isFinite(e)?Math.min(lh,Math.max(ch,Math.round(e))):uh,_h=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},vh=(e,t)=>{let n=gh(e),r=_h(t);return r===null?n:Math.min(n,Math.max(1,r))},yh=(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},bh=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`: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`),xh=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},Sh=(e,t,n)=>{if(e.mode===`chat`){let r=wh(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 xh(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`?xh(e.targetPath)||n(`contextPanel.mode.diff`):bh(e.mode,n)},Ch=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Ri,{filePath:e.targetPath,className:`h-3.5 w-3.5`}):void 0;if(e.mode===`diff`||e.mode===`file-diff`)return(0,$.jsx)(X,{name:`arrow-left-right`,className:`h-3.5 w-3.5`});if(e.mode===`context`)return(0,$.jsx)(X,{name:`file-list-2`,className:`h-3.5 w-3.5`});if(e.mode===`chat`)return(0,$.jsx)(X,{name:`chat-thread`,className:`h-3.5 w-3.5`});if(e.mode===`preview`)return(0,$.jsx)(X,{name:`global`,className:`h-3.5 w-3.5 text-[var(--status-info)]`});if(e.mode===`browser`)return(0,$.jsx)(X,{name:`global`,className:`h-3.5 w-3.5`})},wh=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,Th=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},Eh=(e,t)=>{if(t.length===0)return fh;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?fh:r},Dh=(e,t)=>{let n=St(e),r=Q.useRef(fh),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=Eh(n.getState().session,i.current);return Th(r.current,e)?r.current:(r.current=e,e)},[n]),()=>fh)},Oh=`new Promise((resolve) => {
|
|
19
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
20
|
-
if (existing) existing.remove();
|
|
21
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
22
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
23
|
-
}
|
|
24
|
-
const overlay = document.createElement('div');
|
|
25
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
26
|
-
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
27
|
-
document.documentElement.appendChild(overlay);
|
|
28
|
-
const cssEscape = (value) => {
|
|
29
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
30
|
-
};
|
|
31
|
-
const selectorPart = (element) => {
|
|
32
|
-
const tag = element.tagName.toLowerCase();
|
|
33
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
34
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
35
|
-
return tag + className;
|
|
36
|
-
};
|
|
37
|
-
const metadata = (element) => {
|
|
38
|
-
const rect = element.getBoundingClientRect();
|
|
39
|
-
const style = getComputedStyle(element);
|
|
40
|
-
const ancestry = [];
|
|
41
|
-
let current = element;
|
|
42
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
43
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
44
|
-
current = current.parentElement;
|
|
45
|
-
}
|
|
46
|
-
const attrs = {};
|
|
47
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
48
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
49
|
-
return {
|
|
50
|
-
frame: 'top',
|
|
51
|
-
tag: element.tagName.toLowerCase(),
|
|
52
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
53
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
54
|
-
path,
|
|
55
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
56
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
57
|
-
attributes: attrs,
|
|
58
|
-
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
59
|
-
ancestry,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const move = (event) => {
|
|
63
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
64
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
65
|
-
const rect = element.getBoundingClientRect();
|
|
66
|
-
overlay.style.display = 'block';
|
|
67
|
-
overlay.style.left = rect.left + 'px';
|
|
68
|
-
overlay.style.top = rect.top + 'px';
|
|
69
|
-
overlay.style.width = rect.width + 'px';
|
|
70
|
-
overlay.style.height = rect.height + 'px';
|
|
71
|
-
};
|
|
72
|
-
const cleanup = () => {
|
|
73
|
-
window.removeEventListener('mousemove', move, true);
|
|
74
|
-
window.removeEventListener('click', click, true);
|
|
75
|
-
window.removeEventListener('keydown', keydown, true);
|
|
76
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
77
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const cancel = () => {
|
|
81
|
-
cleanup();
|
|
82
|
-
overlay.remove();
|
|
83
|
-
resolve(null);
|
|
84
|
-
};
|
|
85
|
-
const click = (event) => {
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
event.stopPropagation();
|
|
88
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
89
|
-
const result = element ? metadata(element) : null;
|
|
90
|
-
cleanup();
|
|
91
|
-
overlay.remove();
|
|
92
|
-
resolve(result);
|
|
93
|
-
};
|
|
94
|
-
const keydown = (event) => {
|
|
95
|
-
if (event.key !== 'Escape') return;
|
|
96
|
-
cancel();
|
|
97
|
-
};
|
|
98
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
99
|
-
window.addEventListener('mousemove', move, true);
|
|
100
|
-
window.addEventListener('click', click, true);
|
|
101
|
-
window.addEventListener('keydown', keydown, true);
|
|
102
|
-
});`,kh=`(() => {
|
|
103
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
104
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
108
|
-
if (overlay) overlay.remove();
|
|
109
|
-
})()`,Ah=`(() => {
|
|
110
|
-
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
111
|
-
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
112
|
-
|
|
113
|
-
const navigate = (rawUrl) => {
|
|
114
|
-
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
115
|
-
try {
|
|
116
|
-
const url = new URL(rawUrl, window.location.href);
|
|
117
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
118
|
-
window.location.assign(url.href);
|
|
119
|
-
return true;
|
|
120
|
-
} catch (_error) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const originalOpen = window.open.bind(window);
|
|
126
|
-
window.open = (url, target, features) => {
|
|
127
|
-
if (navigate(url)) return null;
|
|
128
|
-
return originalOpen(url, target, features);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
document.addEventListener('click', (event) => {
|
|
132
|
-
if (event.defaultPrevented) return;
|
|
133
|
-
const target = event.target;
|
|
134
|
-
if (!(target instanceof Element)) return;
|
|
135
|
-
const anchor = target.closest('a[target="_blank"][href]');
|
|
136
|
-
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
137
|
-
if (!navigate(anchor.href)) return;
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
event.stopPropagation();
|
|
140
|
-
}, true);
|
|
141
|
-
})()`,jh=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`}},Mh=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)},Nh=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,Ph=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},Fh=(e,t,n)=>{let r=Ph(t);e.postMessage(n,r)},Ih=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`oc_preview_token`),t.searchParams.delete(`oc_client_token`),t.searchParams.delete(`oc_url_token`),t.toString()}catch{return e}},Lh=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`ocPreview`),t.searchParams.delete(`oc_preview_token`),t.searchParams.delete(`oc_client_token`),t.searchParams.delete(`oc_url_token`),t.toString()}catch{return e}},Rh=({rawUrl:e,onNavigate:t})=>{let{t:r}=qe(),{currentTheme:i}=Pa(),[a,o]=Q.useReducer(e=>e+1,0),[c,l]=Q.useReducer(e=>e+1,0),[u,p]=Q.useState({status:`idle`}),[m,h]=Q.useState(``),g=Q.useRef(null),_=Q.useRef(1),[v,y]=Q.useState(!1),[b,x]=Q.useState(!1),[S,C]=Q.useState(`all`),[w,T]=Q.useState([]),[E,D]=Q.useState(!1),[O,k]=Q.useState(null),A=Pt(e=>e.currentSessionId),j=Pt(e=>e.newSessionDraft?.open),M=Ii(e=>e.addDraft),N=Tn(e=>e.addAttachedFile),P=null;try{P=e?new URL(e):null}catch{P=null}let F=P?P.hostname===`localhost`||P.hostname===`127.0.0.1`||P.hostname===`::1`||P.hostname===`[::1]`||P.hostname===`0.0.0.0`:!1,I=P?P.hostname===`0.0.0.0`?new URL(P.toString().replace(`0.0.0.0`,`127.0.0.1`)):P:null,ee=I?I.toString():``,L=ee?`${d()||`same-origin`}|${ee}`:``,R=i.metadata.variant;Q.useEffect(()=>{if(!ee||!F){p({status:`idle`});return}let e=Im(L);if(e?.previewToken){p({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&Nm.delete(L);let t=!1;return p({status:`loading`}),(async()=>{try{let e=await f(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:ee})});if(!e.ok){Nm.delete(L);let n=await e.json().catch(()=>({})),r=typeof n?.error==`string`?n.error:`HTTP ${e.status}`;t||p({status:`error`,message:r});return}let n=await e.json(),i=typeof n.proxyBasePath==`string`?n.proxyBasePath:``,a=typeof n.previewToken==`string`?n.previewToken:``,o=typeof n.expiresAt==`number`?n.expiresAt:0;if(!i||!a){Nm.delete(L),t||p({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}Nm.set(L,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||p({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(Nm.delete(L),!t){let t=e instanceof Error?e.message:String(e);p({status:`error`,message:t})}}})(),()=>{t=!0}},[F,L,c,r,ee]);let z=I&&(I.protocol===`http:`||I.protocol===`https:`)?I.toString():``,B=F&&u.status===`ready`?`${u.proxyBasePath}|${u.previewToken||``}|${a}`:``;Q.useEffect(()=>{if(!B){h(``);return}let e=!1;return h(``),n(d()).then(t=>{!e&&t&&h(B)}).catch(()=>{}),()=>{e=!0}},[B]);let V=F&&u.status===`ready`&&I&&m===B?(()=>{let e=I.pathname||`/`,t=new URLSearchParams(I.search);t.delete(`oc_url_token`),t.delete(`oc_client_token`),t.set(`ocPreview`,String(a)),t.set(`oc_preview_token`,u.previewToken||``);let n=t.toString(),r=I.hash||``;return s().authenticatedAsset(`${u.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,H=F?V:z,te=F?Ih(V):z,U=F&&(u.status===`loading`||u.status===`idle`||m!==B),ne=F&&u.status===`error`,W=Q.useCallback(t=>{let n=A??(j?`draft`:null);if(!n){J.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||H||``,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 Am(n,t):null;r&&(await N(r),e=!0)}catch{e=!1}M({sessionKey:n,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:km({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:r(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),J.success(r(`contextPanel.preview.inspect.attached`))})()},[N,M,A,H,j,e,r]);Q.useEffect(()=>{y(!1),T([]),x(!1),C(`all`),D(!1),k(null),_.current=1},[H]),Q.useEffect(()=>{let e=g.current?.contentWindow;!v||!e||Fh(e,V,{source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:E})},[v,E,V]),Q.useEffect(()=>{let e=g.current?.contentWindow;!v||!e||Fh(e,V,{source:`openchamber-preview-parent`,version:1,type:`set-color-scheme`,scheme:R})},[v,R,V]),Q.useEffect(()=>{if(!E||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[E]),Q.useEffect(()=>{if(!F||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)}},n=e=>{let t=_.current;_.current+=1,T(n=>{let r=[...n,{...e,id:t}];return r.length>ph?r.slice(r.length-ph):r})},i=i=>{if(i.source!==g.current?.contentWindow)return;let a=i.data;if(!(!a||a.source!==`openchamber-preview-bridge`||a.version!==1)){if(a.type===`ready`){y(!0);return}if(a.type===`console`){let t=a.level===`error`||a.level===`warn`||a.level===`info`||a.level===`debug`?a.level:`log`,r=Array.isArray(a.args)?a.args.map(e).filter(Boolean):[];n({level:t,message:r.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);n({level:`runtime`,message:e(a.message)||r(`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`,r=e(a.url);n({level:`resource`,message:r?`${t}: ${r}`:t,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){k(Om(a.target)?a.target:null);return}if(a.type===`select`&&Om(a.target)){k(a.target),D(!1),W(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`){wo(e);return}e&&t(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[W,F,t,r]);let re=w.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,G=w.filter(e=>mh(e,S)),ie=Q.useCallback(()=>{let t=[`Preview URL: ${e||H||``}`,`Events: ${w.length}`,``].join(`
|
|
143
|
-
`),n=w.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
144
|
-
`);Xe(`${t}${n}`).then(e=>{e.ok?J.success(r(`contextPanel.preview.console.copied`)):J.error(r(`contextPanel.preview.console.copyFailed`))})},[w,H,e,r]),ae=Q.useCallback(()=>{let t=A??(j?`draft`:null);if(!t){J.error(r(`contextPanel.preview.console.attachNoSession`));return}let n=[`Preview URL: ${e||H||``}`,`Events: ${w.length}`,``].join(`
|
|
145
|
-
`),i=w.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
146
|
-
`);M({sessionKey:t,source:`preview-console`,fileLabel:e||H||`preview`,startLine:1,endLine:Math.max(1,w.length),code:`${n}${i}`,language:`text`,text:r(`contextPanel.preview.console.attachAnnotation`)}),J.success(r(`contextPanel.preview.console.attached`))},[M,w,A,H,j,e,r]),[oe,se]=Q.useState(`unknown`),ce=Q.useRef(0),le=Q.useRef(0);Q.useEffect(()=>{if(!V){se(`unknown`),ce.current=0,le.current=0;return}let e=!1;return ce.current||(ce.current=Date.now(),le.current=0),se(`unknown`),(async()=>{let t=await(async()=>{try{return await f(V,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){se(`unreachable`);return}if(t.status===403||t.status===404){Nm.delete(L),p({status:`loading`}),l();return}if(t.status!==502){se(`reachable`);return}let n=ce.current||Date.now();if(Date.now()-n<15e3){se(`starting`),le.current+=1;let t=le.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||o()},n).unref?.();return}se(`unreachable`)})(),()=>{e=!0}},[L,V,a]);let ue=F&&u.status===`ready`&&(oe===`unknown`||oe===`starting`),de=F&&u.status===`ready`&&oe===`unreachable`,fe=Q.useCallback(e=>{if(!F||u.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=Ph(V);if(e.origin!==n||e.pathname.startsWith(u.proxyBasePath))return;let r=`${u.proxyBasePath}${e.pathname}${e.search}${e.hash}`;t.location.replace(r)}catch{}},[F,V,u]);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:te||e,children:te||e||r(`contextPanel.preview.empty`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>o(),title:r(`contextPanel.preview.actions.reload`),"aria-label":r(`contextPanel.preview.actions.reload`),disabled:!H,children:(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>{z&&wo(z)},title:r(`contextPanel.preview.actions.openExternal`),"aria-label":r(`contextPanel.preview.actions.openExternal`),disabled:!z,children:(0,$.jsx)(X,{name:`external-link`,className:`h-3.5 w-3.5`})}),F?(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:E?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>D(e=>!e),title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),disabled:!v,children:(0,$.jsx)(X,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,F?(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:b?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>x(e=>!e),title:r(v?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":r(v?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!v&&w.length===0,children:[(0,$.jsx)(X,{name:`terminal-box`,className:`h-3.5 w-3.5`}),re>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:re}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[ue?(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:r(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:r(`contextPanel.preview.startingServerHint`)})]}):de?(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:r(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:r(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>o(),children:r(`contextPanel.preview.actions.retry`)})]}):H&&(!F||oe===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:g,src:H,title:r(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:R},onLoad:fe,sandbox:F?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${H}:${a}`),E&&O?(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:O.bounds.x,top:O.bounds.y,width:O.bounds.width,height:O.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:[O.tag,O.text?` · ${O.text}`:``]})}):null]}):U?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.loading`)}):ne?(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:r(`contextPanel.preview.proxyError`)}),u.status===`error`?(0,$.jsx)(`div`,{className:`text-center text-xs opacity-70`,children:u.message}):null]}):(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:r(`contextPanel.preview.invalidUrl`)}),b?(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:r(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:ae,disabled:w.length===0,children:r(`contextPanel.preview.console.attach`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:ie,disabled:w.length===0,children:r(`contextPanel.preview.console.copy`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>T([]),disabled:w.length===0,children:r(`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)(Z,{type:`button`,size:`xs`,variant:S===e?`secondary`:`ghost`,onClick:()=>C(e),children:r(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:w.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:r(`contextPanel.preview.console.empty`)}):G.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:r(`contextPanel.preview.console.noFilteredEvents`)}):G.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:Y(`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]})]})},zh=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,Bh=({initialUrl:e,directory:t,tabID:r})=>{let{t:i}=qe(),a=Q.useRef(null),o=K(e=>e.setContextPanelTabTargetPath),c=jh(e),l=c===`about:blank`?``:c,[u,p]=Q.useState(l),[m,h]=Q.useState(l),[g,_]=Q.useState(l),[v,y]=Q.useState(()=>l?[l]:[]),[b,x]=Q.useState(()=>l?0:-1),[S,C]=Q.useReducer(e=>e+1,0),[w,T]=Q.useState(!!l),[E,D]=Q.useState(!1),[O,k]=Q.useState(null),[A,j]=Q.useState({status:`idle`}),[M,N]=Q.useState(``),P=Pt(e=>e.currentSessionId),F=Pt(e=>e.newSessionDraft?.open),I=Ii(e=>e.addDraft),ee=Tn(e=>e.addAttachedFile),L=Q.useCallback(e=>{!e||e===`about:blank`||!t||!r||o(t,r,e)},[t,r,o]),R=Q.useCallback((e,t)=>{let n=jh(e),r=n===`about:blank`?``:n;h(r),p(r),t?.inFrame?T(!1):(_(r),T(!!r)),L(r),y(e=>{if(!r)return x(-1),[];if(t?.replaceHistory)return e;let n=b>=0?e.slice(0,b+1):[];if(n[n.length-1]===r)return x(n.length-1),n;let i=[...n,r];return x(i.length-1),i})},[b,L]),z=Q.useCallback(e=>{let t=v[e];t&&(x(e),h(t),_(t),p(t),T(!0),L(t))},[v,L]),B=Q.useCallback(()=>{if(m){T(!0);try{a.current?.contentWindow?.location.reload()}catch{C()}}},[m]);Q.useEffect(()=>{if(!g){j({status:`idle`});return}let e=Lm(g),t=Im(e);if(t?.previewToken){j({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&Nm.delete(e);let n=!1;return j({status:`loading`}),T(!0),(async()=>{try{let t=await f(`/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||j({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||j({status:`error`,message:i(`contextPanel.preview.proxyError`)});return}Nm.set(e,{proxyBasePath:a,previewToken:o,expiresAt:s}),n||j({status:`ready`,proxyBasePath:a,previewToken:o,expiresAt:s})}catch(e){if(!n){let t=e instanceof Error?e.message:String(e);j({status:`error`,message:t})}}})(),()=>{n=!0}},[g,i]);let V=g&&A.status===`ready`?`${A.proxyBasePath}|${A.previewToken||``}|${S}`:``;Q.useEffect(()=>{if(!V){N(``);return}let e=!1;return N(``),n(d()).then(t=>{!e&&t&&N(V)}).catch(()=>{}),()=>{e=!0}},[V]);let H=Q.useMemo(()=>{if(M!==V||!g||A.status!==`ready`)return``;try{let e=new URL(g),t=e.pathname||`/`,n=new URLSearchParams(e.search);n.delete(`oc_url_token`),n.delete(`oc_client_token`),n.set(`ocPreview`,String(S)),n.set(`oc_preview_token`,A.previewToken||``);let r=n.toString();return s().authenticatedAsset(`${A.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,A,V,S,M]),te=H||(A.status===`error`?g:``),U=Q.useCallback(e=>{if(!e||!g||A.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=A.proxyBasePath.endsWith(`/`)?A.proxyBasePath.slice(0,-1):A.proxyBasePath;if(t.origin!==window.location.origin||!t.pathname.startsWith(n))return``;let r=t.pathname.slice(n.length)||`/`,i=new URL(g).origin;return Lh(new URL(`${r}${t.search}${t.hash}`,i).toString())}catch{return``}},[g,A]),ne=Q.useCallback(e=>{if(!e||!g||A.status!==`ready`)return``;try{let t=new URL(e,window.location.origin),n=new URL(g).origin;if(t.origin!==window.location.origin||n===window.location.origin)return``;let r=A.proxyBasePath.endsWith(`/`)?A.proxyBasePath.slice(0,-1):A.proxyBasePath;return t.pathname.startsWith(r)?``:Lh(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,A]),W=Q.useCallback(e=>{let t=a.current?.contentWindow;t&&t.postMessage({source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:e},window.location.origin)},[]),re=Q.useCallback(async e=>{let t=P??(F?`draft`:null);if(!t){J.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 Am(n,e):null,l=!!c;c&&await ee(c),I({sessionKey:t,source:`preview-annotation`,fileLabel:m||`browser`,startLine:1,endLine:1,code:km({pageUrl:m,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:i(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),J.success(i(`contextPanel.preview.inspect.attached`))},[ee,I,P,m,F,i]),G=Q.useCallback(()=>{let e=a.current;k(null),W(!1),e&&Mh(e,kh).catch(()=>{})},[W]);Q.useEffect(()=>{if(!E)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1),G())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[G,E]),Q.useEffect(()=>()=>G(),[G]),Q.useEffect(()=>{let e=e=>{if(e.source!==a.current?.contentWindow)return;let t=e.data;if(!(!t||t.source!==`openchamber-preview-bridge`||t.version!==1)){if(t.type===`ready`){let e=typeof t.url==`string`?t.url:``,n=U(e);n&&n!==m&&R(n,{inFrame:!0});return}if(t.type===`hover`){k(Om(t.target)?t.target:null);return}if(t.type===`select`&&Om(t.target)){k(null),D(!1),W(!1),re(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ne(e);if(n){R(n);return}e&&R(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[R,re,m,U,ne,W]);let ie=Q.useCallback(()=>{let e=a.current;if(!(!e||!m)){if(E){D(!1),G();return}if(H){k(null),D(!0),W(!0);return}D(!0),(async()=>{try{let t=await Mh(e,Oh);if(D(!1),!t||!Om(t))return;await re(t)}catch{D(!1),J.error(i(`contextPanel.browser.inspectUnavailable`))}})()}},[re,G,m,E,W,H,i]),ae=Q.useCallback(()=>{try{let e=a.current?.contentWindow?.location.href||``,t=ne(e);if(t){R(t,{inFrame:!0});return}}catch{}T(!1),E&&H&&W(!0)},[R,ne,E,W,H]);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)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:b<=0,onClick:()=>z(b-1),children:(0,$.jsx)(X,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:b<0||b>=v.length-1,onClick:()=>z(b+1),children:(0,$.jsx)(X,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:B,children:(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`form`,{className:`min-w-0 flex-1`,onSubmit:e=>{e.preventDefault(),R(u)},children:(0,$.jsx)(`input`,{value:u,onChange:e=>p(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)(Z,{type:`button`,variant:E?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:ie,title:i(`contextPanel.preview.inspect.toggle`),"aria-label":i(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(X,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!m,onClick:()=>void wo(m),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[te?(0,$.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,$.jsx)(`iframe`,{ref:a,src:te,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:ae},`${r}:${S}`),E&&O?(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:O.bounds.x,top:O.bounds.y,width:O.bounds.width,height:O.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:[O.tag,O.text?` · ${O.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)(Ta,{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`)})]}),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]})]})},Vh=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=qe(),i=Q.useRef(null),a=K(e=>e.setContextPanelTabTargetPath),o=jh(e),s=o===`about:blank`?``:o,c=Q.useRef(jh(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=Pt(e=>e.currentSessionId),x=Pt(e=>e.newSessionDraft?.open),S=Ii(e=>e.addDraft),C=Tn(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?.(Ah,!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?.(kh).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?.(kh).catch(()=>{})}catch{}}},[t,n,a]);let w=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=jh(e);try{t.loadURL(n)}catch{}},[]),T=Q.useCallback(()=>{let e=i.current;if(e){if(p){m(!1);try{e.executeJavaScript?.(kh).catch(()=>{})}catch{}return}m(!0),e.executeJavaScript?.(Oh,!0).then(async t=>{if(m(!1),!t||!Om(t))return;let n=b??(x?`draft`:null);if(!n){J.error(r(`contextPanel.preview.inspect.attachNoSession`));return}let i=typeof e.getWebContentsId==`function`?e.getWebContentsId():null;if(i==null)return;let a=await Je(`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 jm(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:km({pageUrl:d,viewport:{width:s,height:c},devicePixelRatio:window.devicePixelRatio||1,target:t,screenshotAttached:u,intro:r(`contextPanel.preview.inspect.attachAnnotationWithScreenshot`)}),language:`markdown`,text:``}),J.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)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goBack?.()}catch{}},children:(0,$.jsx)(X,{name:`arrow-left`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.goForward?.()}catch{}},children:(0,$.jsx)(X,{name:`arrow-right`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>{try{i.current?.reload?.()}catch{}},children:(0,$.jsx)(X,{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)(Z,{type:`button`,variant:p?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:T,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(X,{name:`cursor`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:()=>void wo(d),children:(0,$.jsx)(X,{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:openchamber-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)(Ta,{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]})]})},Hh=({directory:e})=>{let{t}=qe(),n=jo()??``,r=e?.trim()||n,i=Q.useMemo(()=>hh(r),[r]),a=K(e=>i?e.contextPanelByDirectory[i]:void 0),o=K(e=>i?e.contextToolDiffByDirectory[i]:void 0),s=K(e=>e.closeContextPanel),c=K(e=>e.closeContextPanelTab),u=K(e=>e.openContextPanelTab),d=K(e=>e.toggleContextPanelExpanded),f=K(e=>e.setContextPanelWidth),p=K(e=>e.setActiveContextPanelTab),m=K(e=>e.reorderContextPanelTabs),h=Ha(e=>e.setSelectedPath),g=K(e=>e.openContextPreview),_=K(e=>e.allowPromptingSubagentSessions),{themeMode:v,setThemeMode:y,lightThemeId:b,darkThemeId:x,currentTheme:S}=Pa(),C=Q.useMemo(()=>a?.tabs??[],[a?.tabs]),w=C.find(e=>e.id===a?.activeTabId)??C[C.length-1]??null,T=!!(a?.isOpen&&w),E=!!(T&&a?.expanded),D=gh(a?.width??uh),O=Q.useMemo(()=>{let e=[];for(let t of C){if(t.mode!==`chat`)continue;let n=wh(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[C]),k=Dh(i||void 0,O),[A,j]=Q.useState(!1),[M,N]=Q.useState(!1),P=Q.useRef(0),F=Q.useRef(D),I=Q.useRef(null),ee=Q.useRef(null),L=Q.useRef(null),R=Q.useRef(new Map),z=Q.useRef(new Map),B=Q.useRef(!1),V=Q.useRef(T),H=Q.useRef(null),[te,U]=Q.useState({}),ne=Q.useRef(te);ne.current=te;let[W,re]=Q.useReducer(gm,{activeViewKey:null,tabs:{},mountedViews:{}}),G=Rp(),ie=l(),ae=Q.useCallback(e=>{let t=ne.current,n=e(t);return n!==t&&(ne.current=n,U(n),!0)},[]),oe=Q.useCallback(e=>{if(!i)return;re({type:`close-tab`,tabId:e});let t=zp(i,e);ae(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),c(i,e)},[c,ae,i]),se=Q.useCallback(()=>{N(!0),H.current!==null&&window.cancelAnimationFrame(H.current),H.current=window.requestAnimationFrame(()=>{H.current=null,N(!1)})},[]);Q.useEffect(()=>()=>{H.current!==null&&window.cancelAnimationFrame(H.current)},[]),Q.useLayoutEffect(()=>{let e=V.current;if(V.current=T,!T){N(!1);return}e||se()},[T,se]),Q.useEffect(()=>{if(!T||B.current){B.current=T;return}let e=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return B.current=!0,()=>window.cancelAnimationFrame(e)},[T]);let ce=Q.useCallback(e=>{let t=L.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${vh(e,t)}px`)},[]),le=Q.useCallback(e=>{if(!(!T||E||!i)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}ee.current=e.pointerId,j(!0),P.current=e.clientX,F.current=D,I.current=D,ce(D),e.preventDefault()}},[ce,i,E,T,D]),ue=Q.useCallback(e=>{if(!A||ee.current!==e.pointerId)return;let t=P.current-e.clientX,n=vh(F.current+t,L.current);I.current!==n&&(I.current=n,ce(n))},[ce,A]),de=Q.useCallback(e=>{if(ee.current!==e.pointerId||!i)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=vh(I.current??D,L.current);se(),ce(t),I.current=t,f(i,t),j(!1),ee.current=null},[ce,i,f,se,D]);Q.useEffect(()=>{A||(I.current=null)},[A]);let fe=Q.useCallback(()=>{i&&s(i)},[s,i]),pe=Q.useCallback(()=>{i&&d(i)},[i,d]),me=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&w&&i){e.preventDefault(),e.stopPropagation(),oe(w.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),fe())},[w,oe,i,fe]);Q.useEffect(()=>{if(!(!i||!w)&&w.mode===`file`&&w.targetPath){h(i,w.targetPath,{allowOutsideRoot:!0});return}},[w,i,h]);let he=w?.mode===`chat`?w.id:null,ge=Kp(he?te[zp(i,he)]:void 0,he?wh(w?.dedupeKey):null);Q.useEffect(()=>{if(!T||!i||!ge){mt(``,null);return}return mt(i,ge),()=>{mt(``,null)}},[ge,i,T]),Q.useEffect(()=>{if(!T||!i||!ge||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){Nn(i,ge,!1);return}Zt(ge),Nn(i,ge,!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),Nn(i,ge,!1)}},[ge,i,T]);let _e=Q.useCallback((e,t,n)=>Hr(z.current,e,t,i||null,n,{mode:v,lightThemeId:b,darkThemeId:x,currentTheme:S}),[S,x,i,b,v]);Q.useEffect(()=>{let e=new Set(C.map(e=>e.id));for(let t of z.current.keys())e.has(t)||z.current.delete(t)},[C]);let ve=Q.useCallback(e=>{!i||w?.mode!==`diff`&&w?.mode!==`file-diff`||u(i,{mode:w.mode,targetPath:w.targetPath,stagedDiff:e===`staged`,diffScope:e})},[w,i,u]),ye=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:v,lightThemeId:b,darkThemeId:x,currentTheme:S};for(let t of R.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyThemeSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:theme-sync`,payload:e},window.location.origin)}},[S,x,b,v]),be=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:_};for(let t of R.current.values()){let n=t.contentWindow;if(!n)continue;let r=n.__openchamberApplyChatSettingsSync;if(typeof r==`function`)try{r(e);continue}catch{}n.postMessage({type:`openchamber:chat-settings-sync`,payload:e},window.location.origin)}},[_]),xe=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of R.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:he===e},i=n.__openchamberSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:Lr,payload:r},window.location.origin)}},[he]);Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{if(e.origin!==window.location.origin||!Array.from(R.current.values()).some(t=>t.contentWindow===e.source))return;let t=e.data;if(t?.type===`openchamber:close-embedded-session-chat`){let t=Array.from(R.current.entries()).find(([,t])=>t.contentWindow===e.source);t&&i&&oe(t[0]);return}if(t?.type===`openchamber:chat-settings-request`){be();return}if(t?.type===`openchamber:embedded-visibility-request`){xe();return}if(t?.type!==`openchamber:cycle-theme-request`)return;let n=[`light`,`dark`,`system`],r=(n.indexOf(v)+1)%n.length;y(n[r])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[oe,i,be,xe,y,v]),Q.useLayoutEffect(()=>{C.some(e=>e.mode===`chat`)&&(ye(),be(),xe())},[x,b,be,xe,ye,C,v]);let Se=Q.useMemo(()=>C.map(e=>{let n=Sh(e,k,t),i=Nh(n,dh),a=yh(e.targetPath,r);return{id:e.id,label:i,icon:Ch(e),title:a?`${n}: ${a}`:n,closeLabel:t(`contextPanel.tab.closeTabAria`,{label:i})}}),[r,k,t,C]),Ce=w?.mode===`context`?(0,$.jsx)(Tp,{}):w?.mode===`preview`?(0,$.jsx)(Rh,{rawUrl:w.targetPath??``,onNavigate:e=>g(r,e)}):(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,$.jsx)(X,{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`)})]}),we=Q.useMemo(()=>C.filter(e=>e.mode===`chat`),[C]),Te=Q.useMemo(()=>C.filter(e=>e.mode===`browser`),[C]),Ee=Q.useMemo(()=>C.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[C]),De=zh()?Vh:Bh,Oe=Q.useMemo(()=>C.some(e=>e.mode===`file`),[C]),ke=w?.mode===`file`,Ae=ke?w?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(we.map(e=>zp(i,e.id)));ae(t=>{let n=!1,r={};for(let e of we){let a=wh(e.dedupeKey);if(!a)continue;let o=zp(i,e.id),s=t[o];r[o]=s??Wp({sessionId:a,directory:i}),n||=!s}let a=Zp(t,e);return n||=a!==t,n?{...a,...r}:t});for(let t of Object.keys(W.tabs))(!e.has(zp(i,t))||W.tabs[t]?.directory!==i)&&re({type:`close-tab`,tabId:t})},[we,ae,i,W.tabs]);let je=he?zp(i,he):null,Me=he?wh(w?.dedupeKey):null,Ne=je&&Me?Gp(te[je],{sessionId:Me,directory:i}):void 0,Pe=Ne&&je?Bp(ie,je,Ne.current.directory,Ne.current.sessionId):null;Q.useLayoutEffect(()=>{if(G!==`react-surface`||!T||!he||!Ne||!je||!Pe){G===`react-surface`&&re({type:`activate`,viewKey:null,now:Date.now()});return}ae(e=>e[je]?e:{...e,[je]:Ne}),re({type:`touch`,tab:{tabId:he,sessionId:Ne.anchor.sessionId,directory:Ne.anchor.directory},view:{tabId:he,surfaceId:je,sessionId:Ne.current.sessionId,directory:Ne.current.directory,viewKey:Pe},now:Date.now()})},[Ne,je,he,Pe,G,ae,T]);let q=Q.useCallback((e,t,n)=>{let r=zp(i,e),a=!1;return ae(e=>{let i=Xp(e,r,{sessionId:t,directory:n});return a=i.accepted,i.navigationBySurfaceId}),a},[ae,i]),Fe=Q.useCallback(e=>{let t=zp(i,e);ae(e=>{let n=e[t];if(!n)return e;let r=Jp(n);return r===n?e:{...e,[t]:r}})},[ae,i]),Ie=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(Bo,{items:Se,activeId:w?.id??null,onSelect:e=>{i&&p(i,e)},onClose:e=>{oe(e)},onReorder:(e,t)=>{i&&m(i,e,t)},layoutMode:`scrollable`,variant:`default`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:pe,className:`h-7 w-7 p-0`,title:t(E?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":t(E?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:E?(0,$.jsx)(X,{name:`fullscreen-exit`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`fullscreen`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:fe,className:`h-7 w-7 p-0`,title:t(`contextPanel.actions.closePanel`),"aria-label":t(`contextPanel.actions.closePanel`),children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),Le=T?E?{"--oc-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--oc-context-panel-width), 100%)`,minWidth:`min(${ch}px, 100%)`,maxWidth:`100%`,"--oc-context-panel-width":`${A?I.current??D:D}px`}:{"--oc-context-panel-width":`${A?I.current??D:D}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:`hidden`,visibility:`hidden`};return(0,$.jsxs)(`aside`,{ref:L,"data-context-panel":`true`,tabIndex:-1,inert:!T||void 0,className:Y(`flex min-h-0 flex-col overflow-hidden bg-background`,!E&&`oc-layout-divider-l`,E?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!T&&`pointer-events-none`,A||!T||M?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:me,style:Le,children:[!E&&(0,$.jsx)(`div`,{className:Y(`absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80`,A&&`bg-[var(--interactive-border)]`),onPointerDown:le,onPointerMove:ue,onPointerUp:de,onPointerCancel:de,role:`separator`,"aria-orientation":`vertical`,"aria-label":t(`contextPanel.actions.resizePanelAria`)}),Ie,Ae===`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:Y(`relative min-h-0 flex-1 overflow-hidden`,A&&`pointer-events-none`),children:[Oe?(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,ke?`block`:`hidden`),children:(0,$.jsx)(Zf,{mode:`editor-only`,isActive:T&&ke})}):null,G===`legacy-iframe`&&we.map(e=>{let n=wh(e.dedupeKey);if(!n)return null;let r=_e(e.id,n,e.readOnly);return r?(0,$.jsx)(`iframe`,{ref:t=>{if(!t){R.current.delete(e.id);return}R.current.set(e.id,t)},src:r,title:t(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:Y(`absolute inset-0 h-full w-full border-0 bg-background`,he===e.id?`block`:`hidden`),onLoad:()=>{ye(),be(),xe()}},e.id):null}),G===`react-surface`?Object.values(W.mountedViews).map(e=>{let t=te[zp(i,e.tabId)],n=T&&he===e.tabId&&Pe===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:n?`visible`:`hidden`,children:(0,$.jsx)(xm,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:n,canNavigateBack:n&&!!t?.stack.length,onNavigateSession:(t,n)=>q(e.tabId,t,n),onNavigateBack:()=>Fe(e.tabId),onEstimateBytes:(e,t)=>re({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,Te.map(e=>(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,w?.id!==e.id&&`hidden`),children:(0,$.jsx)(De,{initialUrl:e.targetPath??``,directory:i,tabID:e.id})},e.id)),Ee.map(e=>{let t=e.mode===`diff`&&o?.targetPath===e.targetPath&&o.turnMessageId===e.diffTurnMessageId?o.patches:null;return(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,w?.id!==e.id&&`hidden`),children:(0,$.jsx)(As,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:i,onDiffScopeChange:ve,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)}),w?.mode!==`chat`&&!ke&&w?.mode!==`browser`&&w?.mode!==`diff`&&w?.mode!==`file-diff`?Ce:null]})]})},Uh=(e,t)=>!e||t.length===0?``:JSON.stringify([e,t]),Wh=(e,t,n,r)=>!n||r!==n||e.length===0?[]:Gt(e,t,e=>e.name,{limit:10,threshold:.4}),Gh=e=>{let t=(0,zc.c)(13),{title:n,description:r,trailing:i}=e,a=r?`min-w-0 max-w-[58%] shrink-0 truncate typography-meta font-medium leading-4 text-foreground`:`min-w-0 flex-1 truncate typography-meta font-medium leading-4 text-foreground`,o;t[0]!==a||t[1]!==n?(o=(0,$.jsx)(`span`,{className:a,children:n}),t[0]=a,t[1]=n,t[2]=o):o=t[2];let s;t[3]===r?s=t[4]:(s=r?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-micro leading-4 text-muted-foreground/65`,children:r}):null,t[3]=r,t[4]=s);let c;t[5]!==o||t[6]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2.5`,children:[o,s]}),t[5]=o,t[6]=s,t[7]=c):c=t[7];let l;t[8]===i?l=t[9]:(l=i?(0,$.jsx)(`div`,{className:`ml-auto flex shrink-0 items-center pl-2 text-muted-foreground/50`,children:i}):null,t[8]=i,t[9]=l);let u;return t[10]!==c||t[11]!==l?(u=(0,$.jsxs)($.Fragment,{children:[c,l]}),t[10]=c,t[11]=l,t[12]=u):u=t[12],u},Kh=`h-8 gap-2 rounded-md px-2.5 py-0 typography-meta`,qh=`py-0 [&_[cmdk-group-heading]]:px-2.5 [&_[cmdk-group-heading]]:pb-0.5 [&_[cmdk-group-heading]]:pt-1.5 [&_[cmdk-group-heading]]:!text-[12px] [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:leading-4 [&_[cmdk-group-heading]]:text-muted-foreground/65`,Jh=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},Yh=()=>{let e=(0,zc.c)(177),{t}=qe(),n=K(Xh),r=K(Zh),i=K(Qh),a=K($h),o=K(eg),s=K(tg),c=K(ng),l=K(rg),u=K(ig),d=K(ag),f=K(og),p=K(sg),h=Pt(cg),g=Pt(lg),_=Rt(ug),v=xe(dg),y=qt(fg),x=qt(pg),S=jo(),C=Te(mg),{files:w,git:T}=za(),D=Wa(hg),{isMobile:O}=Fa(),k;e[0]===S?k=e[1]:(k=S?Jh(S):null,e[0]=S,e[1]=k);let j=k,[M,N]=Q.useState(``),P=Va(M,200).trim(),F;e[2]===M?F=e[3]:(F=M.trim(),e[2]=M,e[3]=F);let I=F,L,R;e[4]===n?(L=e[5],R=e[6]):(L=()=>{n&&N(``)},R=[n],e[4]=n,e[5]=L,e[6]=R),Q.useEffect(L,R);let z,B;e[7]!==_||e[8]!==D||e[9]!==T||e[10]!==n?(z=()=>{if(!n||!T)return;let e=setTimeout(()=>{let e=new Set;for(let t of _){let n=It(t);!n||e.has(n)||(e.add(n),D(n,T))}},0);return()=>clearTimeout(e)},B=[n,_,T,D],e[7]=_,e[8]=D,e[9]=T,e[10]=n,e[11]=z,e[12]=B):(z=e[11],B=e[12]),Q.useEffect(z,B);let V;e[13]===r?V=e[14]:(V=()=>r(!1),e[13]=r,e[14]=V);let H=V,te;e[15]===H?te=e[16]:(te=e=>()=>{H(),e()},e[15]=H,e[16]=te);let U=te,ne;e[17]!==y?.id||e[18]!==y?.path||e[19]!==v||e[20]!==S||e[21]!==O||e[22]!==d||e[23]!==h||e[24]!==U||e[25]!==i||e[26]!==s||e[27]!==a||e[28]!==t||e[29]!==u||e[30]!==l||e[31]!==c?(ne=()=>{let e=[{id:`new-session`,title:t(`commandPalette.item.newSession`),shortcutId:`new_chat`,searchText:t(`commandPalette.item.newSession`),onSelect:U(()=>{i(`chat`),s(!1),h()})},{id:`new-worktree`,title:t(`commandPalette.item.newWorktreeDraft`),shortcutId:`new_chat_worktree`,searchText:t(`commandPalette.item.newWorktreeDraft`),onSelect:U(gg)},{id:`add-project`,title:t(`commandPalette.item.addProject`),searchText:t(`commandPalette.item.addProject`),onSelect:U(_g)},{id:`toggle-sidebar`,title:t(O?`commandPalette.item.showSessionSwitcher`:`commandPalette.item.toggleSidebar`),shortcutId:`toggle_sidebar`,searchText:t(O?`commandPalette.item.showSessionSwitcher`:`commandPalette.item.toggleSidebar`),onSelect:U(()=>{if(O){let{isSessionSwitcherOpen:e}=K.getState();s(!e)}else c()})},{id:`toggle-right-sidebar`,title:t(`commandPalette.item.toggleRightSidebar`),shortcutId:`toggle_right_sidebar`,searchText:t(`commandPalette.item.toggleRightSidebar`),onSelect:U(()=>l())},{id:`toggle-terminal`,title:t(`commandPalette.item.toggleTerminal`),shortcutId:`toggle_terminal`,searchText:t(`commandPalette.item.toggleTerminal`),onSelect:U(()=>u())},{id:`new-terminal-tab`,title:t(`commandPalette.item.newTerminalTab`),shortcutId:`open_new_terminal`,searchText:t(`commandPalette.item.newTerminalTab`),onSelect:U(()=>{S&&ii(S)})},{id:`context-usage`,title:t(`commandPalette.item.showContextUsage`),searchText:t(`commandPalette.item.showContextUsage`),onSelect:U(()=>{v&&d(v)})},{id:`open-settings`,title:t(`commandPalette.item.openSettings`),shortcutId:`open_settings`,searchText:t(`commandPalette.item.openSettings`),onSelect:U(()=>a(!0))}];return b()&&e.splice(1,0,{id:`new-mini-chat`,title:t(`commandPalette.item.newMiniChat`),shortcutId:`new_mini_chat`,searchText:t(`commandPalette.item.newMiniChat`),onSelect:U(()=>{ee(`desktop_open_draft_mini_chat_window`,{directory:Jh(v||y?.path||``),projectId:y?.id??null}).catch(vg)})}),e},e[17]=y?.id,e[18]=y?.path,e[19]=v,e[20]=S,e[21]=O,e[22]=d,e[23]=h,e[24]=U,e[25]=i,e[26]=s,e[27]=a,e[28]=t,e[29]=u,e[30]=l,e[31]=c,e[32]=ne):ne=e[32],y?.id,y?.path;let W;e[33]===ne?W=e[34]:(W=ne(),e[33]=ne,e[34]=W);let re=W,G;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(G=E(),e[35]=G):G=e[35];let ie=G,ae,oe;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(ae=m(),oe=!ie&&A(),e[36]=ae,e[37]=oe):(ae=e[36],oe=e[37]);let se;e[38]===O?se=e[39]:(se={isVSCode:ae,isWeb:oe,isDesktop:ie,isMobile:O},e[38]=O,e[39]=se);let ce=se,le;if(e[40]!==U||e[41]!==a||e[42]!==o||e[43]!==ce){let t;e[45]===ce?t=e[46]:(t=e=>!e.isAvailable||e.isAvailable(ce),e[45]=ce,e[46]=t);let n;e[47]!==U||e[48]!==a||e[49]!==o?(n=e=>{let t=(e.keywords??[]).join(` `);return{id:`settings:${e.slug}`,title:e.title,searchText:`${e.title} ${e.group} ${t}`,onSelect:U(()=>{o(e.slug),a(!0)})}},e[47]=U,e[48]=a,e[49]=o,e[50]=n):n=e[50],le=fs.filter(yg).filter(t).map(n),e[40]=U,e[41]=a,e[42]=o,e[43]=ce,e[44]=le}else le=e[44];let ue=le,de=bg,fe;if(e[51]!==_){let t;e[53]===Symbol.for(`react.memo_cache_sentinel`)?(t=(e,t)=>de(t)-de(e),e[53]=t):t=e[53],fe=[..._].sort(t),e[51]=_,e[52]=fe}else fe=e[52];let pe=fe,me=Ga(),he=Pt(xg),ge;e[54]!==me||e[55]!==he?(ge=(e,t)=>{let n=he.get(e);return n?.branch?n.branch.trim()||null:t&&me.get(t)?.trim()||null},e[54]=me,e[55]=he,e[56]=ge):ge=e[56];let _e=ge,ve;e[57]===Symbol.for(`react.memo_cache_sentinel`)?(ve=[],e[57]=ve):ve=e[57];let[ye,be]=Q.useState(ve),[Se,Ce]=Q.useState(``),we=Uh(j,P),Ee;e[58]!==j||e[59]!==we||e[60]!==n||e[61]!==C||e[62]!==be||e[63]!==Ce||e[64]!==P?(Ee=()=>{if(!n){be([]),Ce(``);return}if(!we){be([]),Ce(``);return}if(!j){be([]),Ce(``);return}let e=!1;return C(j,P,10,{type:`file`}).then(t=>{e||(be(t.map(Sg)),Ce(we))}).catch(()=>{e||(be([]),Ce(we))}),()=>{e=!0}},e[58]=j,e[59]=we,e[60]=n,e[61]=C,e[62]=be,e[63]=Ce,e[64]=P,e[65]=Ee):Ee=e[65];let De;e[66]!==j||e[67]!==we||e[68]!==n||e[69]!==C||e[70]!==P?(De=[n,j,P,we,C],e[66]=j,e[67]=we,e[68]=n,e[69]=C,e[70]=P,e[71]=De):De=e[71],Q.useEffect(Ee,De);let Oe=I.length>0,ke;bb0:{if(!Oe){let t;e[72]===re?t=e[73]:(t=re.map(Cg),e[72]=re,e[73]=t),ke=t;break bb0}let t;e[74]!==re||e[75]!==I?(t=Gt(re,I,wg,{limit:7,noFuzzy:!0}),e[74]=re,e[75]=I,e[76]=t):t=e[76],ke=t}let Ae=ke,je;bb1:{if(!Oe){let t;e[77]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[77]=t):t=e[77],je=t;break bb1}let t;e[78]!==I||e[79]!==ue?(t=Gt(ue,I,Tg,{limit:7,noFuzzy:!0}),e[78]=I,e[79]=ue,e[80]=t):t=e[80],je=t}let Me=je,Ne;bb2:{if(!Oe){let t;e[81]===pe?t=e[82]:(t=pe.slice(0,5).map(Eg),e[81]=pe,e[82]=t),Ne=t;break bb2}let t;e[83]!==I||e[84]!==pe?(t=Gt(pe,I,Dg,{limit:7,threshold:.2}),e[83]=I,e[84]=pe,e[85]=t):t=e[85],Ne=t}let Pe=Ne,q;bb3:{if(!n){let t;e[86]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[86]=t):t=e[86],q=t;break bb3}let t;e[87]!==ye||e[88]!==Se||e[89]!==we||e[90]!==P?(t=Wh(ye,P,we,Se),e[87]=ye,e[88]=Se,e[89]=we,e[90]=P,e[91]=t):t=e[91],q=t}let Fe=q,Ie=n&&we.length>0&&Se!==we,Le;bb4:{if(!Oe){let t;e[92]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[92]=t):t=e[92],Le=t;break bb4}let t;if(e[93]!==I||e[94]!==x){let n=x.map(Og);t=Gt(n,I,kg,{limit:7,threshold:.4}),e[93]=I,e[94]=x,e[95]=t}else t=e[95];Le=t}let Re=Le,ze,Be,Ve,He,Ue,We,Ge,Ke,Je,Ye,Xe,Ze,Qe,$e,et,tt;if(e[96]!==_e||e[97]!==H||e[98]!==j||e[99]!==w||e[100]!==Oe||e[101]!==n||e[102]!==f||e[103]!==h||e[104]!==M||e[105]!==Ae||e[106]!==Fe||e[107]!==Re||e[108]!==Pe||e[109]!==Me||e[110]!==r||e[111]!==g||e[112]!==p||e[113]!==t){let i=Ae.map(Ag),a=Me.map(jg),o=Pe.map(Mg),s=Oe?Fe.map(Ng):[],c=Oe?Re.map(Pg):[],l;bb5:{if(!Oe){l=[`commands`,`sessions`];break bb5}let e=Fg,t=[{key:`commands`,score:e(Ae)},{key:`settings`,score:e(Me)},{key:`sessions`,score:e(Pe)},{key:`files`,score:e(Fe)},{key:`projects`,score:e(Re)}];t.sort(Ig),l=t.map(Lg)}let u=l,d=e=>{H(),g(e.id,It(e))},m=async e=>{if(!j)return;let t=await ks(w,e);if(!t.ok){J.error(oc(t.reason));return}f(j,e),H()},_=(e,t)=>{H(),h({selectedProjectId:e,directoryOverride:t})},v=e=>la(Oa(e,p));He=Vn,$e=n,et=r;let y;e[130]===t?y=e[131]:(y=t(`commandPalette.title`),e[130]=t,e[131]=y);let b;e[132]===y?b=e[133]:(b=(0,$.jsx)(zn,{children:y}),e[132]=y,e[133]=b);let x;e[134]===t?x=e[135]:(x=t(`commandPalette.description`),e[134]=t,e[135]=x);let S;e[136]===x?S=e[137]:(S=(0,$.jsx)(Bn,{children:x}),e[136]=x,e[137]=S),e[138]!==b||e[139]!==S?(tt=(0,$.jsxs)(In,{className:`sr-only`,children:[b,S]}),e[138]=b,e[139]=S,e[140]=tt):tt=e[140],Ve=Rn,Xe=`fixed left-1/2 top-[12vh] z-50 max-h-[min(32rem,calc(100vh-2rem))] w-[min(40rem,calc(100vw-1.5rem))] max-w-none -translate-x-1/2 translate-y-0 gap-0 overflow-hidden rounded-2xl border border-[var(--interactive-border)]/55 bg-[color:color-mix(in_srgb,var(--surface-elevated)_80%,transparent)] p-0 shadow-2xl backdrop-blur-2xl supports-[backdrop-filter]:bg-[color:color-mix(in_srgb,var(--surface-elevated)_72%,transparent)] sm:top-[14vh] sm:max-h-[min(32rem,calc(100vh-4rem))] sm:w-[min(40rem,calc(100vw-3rem))]`,Ze=`block p-0`,Qe=!1,Be=oi,Ke=!1,Je=`max-h-full min-h-0 rounded-[inherit] bg-transparent [&_[cmdk-group]]:px-0 [&_[data-slot=command-input-wrapper]]:px-2.5 [&_[data-slot=command-input-wrapper]]:pt-2.5 [&_[data-slot=command-input-wrapper]]:pb-1.5 [&_[data-slot=command-input-field]]:!bg-transparent`;let C;e[141]===t?C=e[142]:(C=t(`commandPalette.input.placeholder`),e[141]=t,e[142]=C),e[143]!==M||e[144]!==C?(Ye=(0,$.jsx)(Di,{value:M,onValueChange:N,placeholder:C}),e[143]=M,e[144]=C,e[145]=Ye):Ye=e[145],ze=ni,Ue=`px-1.5 pb-2`;let T;e[146]===t?T=e[147]:(T=t(`commandPalette.empty.noResults`),e[146]=t,e[147]=T),e[148]===T?We=e[149]:(We=(0,$.jsx)(ki,{className:`py-10 text-muted-foreground`,children:T}),e[148]=T,e[149]=We),Ge=u.map(e=>e===`commands`&&i.length>0?(0,$.jsx)(Si,{heading:t(`settings.page.commands.title`),className:qh,children:i.map(e=>(0,$.jsx)(mi,{value:e.id,onSelect:e.onSelect,className:Kh,children:(0,$.jsx)(Gh,{title:e.title,trailing:e.shortcutId?(0,$.jsx)(ui,{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`,children:v(e.shortcutId)}):void 0})},e.id))},`commands`):e===`settings`&&a.length>0?(0,$.jsx)(Si,{heading:t(`settings.view.home.title`),className:qh,children:a.map(Rg)},`settings`):e===`sessions`&&o.length>0?(0,$.jsx)(Si,{heading:t(`header.sessions.title`),className:qh,children:o.map(e=>{let n=e.title||t(`commandPalette.session.untitled`),r=It(e),i=_e(e.id,r);return(0,$.jsx)(mi,{value:`session:${e.id}`,onSelect:()=>d(e),className:Kh,children:(0,$.jsx)(Gh,{title:n,trailing:i?(0,$.jsx)(`span`,{className:`max-w-40 truncate typography-micro leading-none opacity-70`,children:i}):void 0})},e.id)})},`sessions`):e===`files`&&s.length>0?(0,$.jsx)(Si,{heading:t(`layout.mainTab.files`),className:qh,children:s.map(e=>{let t=Un(e.relativePath||e.name,{maxLength:80});return(0,$.jsx)(mi,{value:`file:${e.path}`,onSelect:()=>{m(e.path)},className:Kh,children:(0,$.jsx)(Gh,{title:e.name,description:t===e.name?void 0:t})},`file:${e.path}`)})},`files`):e===`projects`&&c.length>0?(0,$.jsx)(Si,{heading:t(`sessions.sidebar.projectsTitle`),className:qh,children:c.map(e=>{let t=e.displayName;return(0,$.jsx)(mi,{value:`project:${e.id}`,onSelect:()=>_(e.id,e.path),className:Kh,children:(0,$.jsx)(Gh,{title:t})},`project:${e.id}`)})},`projects`):null),e[96]=_e,e[97]=H,e[98]=j,e[99]=w,e[100]=Oe,e[101]=n,e[102]=f,e[103]=h,e[104]=M,e[105]=Ae,e[106]=Fe,e[107]=Re,e[108]=Pe,e[109]=Me,e[110]=r,e[111]=g,e[112]=p,e[113]=t,e[114]=ze,e[115]=Be,e[116]=Ve,e[117]=He,e[118]=Ue,e[119]=We,e[120]=Ge,e[121]=Ke,e[122]=Je,e[123]=Ye,e[124]=Xe,e[125]=Ze,e[126]=Qe,e[127]=$e,e[128]=et,e[129]=tt}else ze=e[114],Be=e[115],Ve=e[116],He=e[117],Ue=e[118],We=e[119],Ge=e[120],Ke=e[121],Je=e[122],Ye=e[123],Xe=e[124],Ze=e[125],Qe=e[126],$e=e[127],et=e[128],tt=e[129];let nt;e[150]!==Ie||e[151]!==t?(nt=Ie?(0,$.jsx)(`div`,{className:`px-3 py-2 typography-micro text-muted-foreground/70`,children:t(`commandPalette.empty.searchingFiles`)}):null,e[150]=Ie,e[151]=t,e[152]=nt):nt=e[152];let rt;e[153]!==ze||e[154]!==Ue||e[155]!==We||e[156]!==Ge||e[157]!==nt?(rt=(0,$.jsxs)(ze,{className:Ue,children:[We,Ge,nt]}),e[153]=ze,e[154]=Ue,e[155]=We,e[156]=Ge,e[157]=nt,e[158]=rt):rt=e[158];let it;e[159]!==Be||e[160]!==Ke||e[161]!==Je||e[162]!==Ye||e[163]!==rt?(it=(0,$.jsxs)(Be,{shouldFilter:Ke,className:Je,children:[Ye,rt]}),e[159]=Be,e[160]=Ke,e[161]=Je,e[162]=Ye,e[163]=rt,e[164]=it):it=e[164];let at;e[165]!==Ve||e[166]!==Xe||e[167]!==Ze||e[168]!==Qe||e[169]!==it?(at=(0,$.jsx)(Ve,{className:Xe,containerClassName:Ze,showCloseButton:Qe,children:it}),e[165]=Ve,e[166]=Xe,e[167]=Ze,e[168]=Qe,e[169]=it,e[170]=at):at=e[170];let ot;return e[171]!==He||e[172]!==$e||e[173]!==et||e[174]!==tt||e[175]!==at?(ot=(0,$.jsxs)(He,{open:$e,onOpenChange:et,children:[tt,at]}),e[171]=He,e[172]=$e,e[173]=et,e[174]=tt,e[175]=at,e[176]=ot):ot=e[176],ot};function Xh(e){return e.isCommandPaletteOpen}function Zh(e){return e.setCommandPaletteOpen}function Qh(e){return e.setActiveMainTab}function $h(e){return e.setSettingsDialogOpen}function eg(e){return e.setSettingsPage}function tg(e){return e.setSessionSwitcherOpen}function ng(e){return e.toggleSidebar}function rg(e){return e.toggleRightSidebar}function ig(e){return e.toggleBottomTerminal}function ag(e){return e.openContextOverview}function og(e){return e.openContextFile}function sg(e){return e.shortcutOverrides}function cg(e){return e.openNewSessionDraft}function lg(e){return e.setCurrentSession}function ug(e){return e.activeSessions}function dg(e){return e.currentDirectory}function fg(e){return e.getActiveProject()}function pg(e){return e.projects}function mg(e){return e.searchFiles}function hg(e){return e.ensureStatus}function gg(){Ci()}function _g(){Ct.requestDirectoryDialog()}function vg(e){console.warn(`[command-palette] failed to open draft mini chat window`,e)}function yg(e){return e.slug!==`home`}function bg(e){return(typeof e.time?.updated==`number`?e.time.updated:0)||(typeof e.time?.created==`number`?e.time.created:0)}function xg(e){return e.worktreeMetadata}function Sg(e){return{path:Jh(e.path),name:e.name,relativePath:e.relativePath}}function Cg(e){return{item:e,score:0}}function wg(e){return e.searchText}function Tg(e){return e.searchText}function Eg(e){return{item:e,score:0}}function Dg(e){return e.title||``}function Og(e){return{...e,displayName:e.label||e.path.split(`/`).pop()||e.path,searchText:`${e.label||``} ${e.path}`}}function kg(e){return e.searchText}function Ag(e){return e.item}function jg(e){return e.item}function Mg(e){return e.item}function Ng(e){return e.item}function Pg(e){return e.item}function Fg(e){return e.length?e[0].score:1/0}function Ig(e,t){return e.score-t.score}function Lg(e){return e.key}function Rg(e){return(0,$.jsx)(mi,{value:e.id,onSelect:e.onSelect,className:Kh,children:(0,$.jsx)(Gh,{title:e.title})},e.id)}var zg=(e,t,n)=>va(e)?fa(e,n).map(la):t,Bg=()=>{let e=(0,zc.c)(69),{t}=qe(),n=K(Vg),r=K(Hg),i=K(Ug),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=ya(),e[0]=a):a=e[0];let o=a,s;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=m(),e[1]=s):s=e[1];let c=s,l,u,d,f,p,h,g,_,v;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=Vn,_=n,v=r,l=Rn,h=`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)(X,{name:`settings-3`,className:`h-5 w-5`}),e[15]=s):s=e[15];let m;e[16]===t?m=e[17]:(m=t(`helpDialog.title`),e[16]=t,e[17]=m);let y;e[18]===m?y=e[19]:(y=(0,$.jsxs)(zn,{className:`flex items-center gap-2`,children:[s,m]}),e[18]=m,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)(Bn,{children:b}),e[22]=b,e[23]=x),e[24]!==y||e[25]!==x?(g=(0,$.jsxs)(In,{children:[y,x]}),e[24]=y,e[25]=x,e[26]=g):g=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?zg(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)(X,{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)(ti,{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]=h,e[12]=g,e[13]=_,e[14]=v}else l=e[6],u=e[7],d=e[8],f=e[9],p=e[10],h=e[11],g=e[12],_=e[13],v=e[14];let y;e[27]!==d||e[28]!==f?(y=(0,$.jsx)(`div`,{className:d,children:f}),e[27]=d,e[28]=f,e[29]=y):y=e[29];let b;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-muted-foreground mt-0.5`}),e[30]=b):b=e[30];let x;e[31]===t?x=e[32]:(x=t(`helpDialog.proTips.title`),e[31]=t,e[32]=x);let S;e[33]===x?S=e[34]:(S=(0,$.jsx)(`p`,{className:`font-medium mb-1`,children:x}),e[33]=x,e[34]=S);let C;e[35]!==i||e[36]!==t?(C=t(`helpDialog.proTips.commandPalette`,{shortcut:la(fa(`open_command_palette`,i)[0]??``)}),e[35]=i,e[36]=t,e[37]=C):C=e[37];let w;e[38]===C?w=e[39]:(w=(0,$.jsxs)(`li`,{children:[`• `,C]}),e[38]=C,e[39]=w);let T;e[40]===t?T=e[41]:(T=t(`helpDialog.proTips.recentSessions`),e[40]=t,e[41]=T);let E;e[42]===T?E=e[43]:(E=(0,$.jsxs)(`li`,{children:[`• `,T]}),e[42]=T,e[43]=E);let D;e[44]===t?D=e[45]:(D=t(`helpDialog.proTips.themeCycling`),e[44]=t,e[45]=D);let O;e[46]===D?O=e[47]:(O=(0,$.jsxs)(`li`,{children:[`• `,D]}),e[46]=D,e[47]=O);let k;e[48]!==w||e[49]!==E||e[50]!==O?(k=(0,$.jsxs)(`ul`,{className:`space-y-0.5 typography-meta`,children:[w,E,O]}),e[48]=w,e[49]=E,e[50]=O,e[51]=k):k=e[51];let A;e[52]!==S||e[53]!==k?(A=(0,$.jsx)(`div`,{className:`mt-4 p-2 bg-muted/30 rounded-xl`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[b,(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground`,children:[S,k]})]})}),e[52]=S,e[53]=k,e[54]=A):A=e[54];let j;e[55]!==A||e[56]!==p||e[57]!==y?(j=(0,$.jsxs)(`div`,{className:p,children:[y,A]}),e[55]=A,e[56]=p,e[57]=y,e[58]=j):j=e[58];let M;e[59]!==l||e[60]!==j||e[61]!==h||e[62]!==g?(M=(0,$.jsxs)(l,{className:h,children:[g,j]}),e[59]=l,e[60]=j,e[61]=h,e[62]=g,e[63]=M):M=e[63];let N;return e[64]!==u||e[65]!==M||e[66]!==_||e[67]!==v?(N=(0,$.jsx)(u,{open:_,onOpenChange:v,children:M}),e[64]=u,e[65]=M,e[66]=_,e[67]=v,e[68]=N):N=e[68],N};function Vg(e){return e.isHelpDialogOpen}function Hg(e){return e.setHelpDialogOpen}function Ug(e){return e.shortcutOverrides}var Wg=()=>{let e=(0,zc.c)(32),{t}=qe(),n=K(Gg),r=K(Kg),i=K(qg),a;e[0]!==i||e[1]!==t?(a=async()=>{if(i){if((await Xe(i)).ok){J.success(t(`openCodeStatusDialog.toast.copiedTitle`),{description:t(`openCodeStatusDialog.toast.copiedDescription`)});return}J.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)(zn,{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)(Bn,{children:l}),e[9]=l,e[10]=u);let d;e[11]!==c||e[12]!==u?(d=(0,$.jsxs)(In,{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)(Rn,{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)(Vn,{open:n,onOpenChange:r,children:g}),e[28]=n,e[29]=r,e[30]=g,e[31]=_):_=e[31],_};function Gg(e){return e.isOpenCodeStatusDialogOpen}function Kg(e){return e.setOpenCodeStatusDialogOpen}function qg(e){return e.openCodeStatusText}var Jg=`__other__`;function Yg(e){return e.time?.updated??e.time?.archived??e.time?.created??0}function Xg(){let{t:e}=qe(),{isMobile:t,isTablet:n,hasTouchInput:r}=Fa(),i=t||n||r,a=K(e=>e.isArchivedSessionsDialogOpen),o=K(e=>e.setArchivedSessionsDialogOpen),s=qt(e=>e.projects),c=Rt(e=>e.archivedSessions),l=Pt(e=>e.setCurrentSession),u=K(e=>e.setSettingsDialogOpen),[d,f]=Q.useState(!1),[p,h]=Q.useState(null),[g,_]=Q.useState(null);Q.useEffect(()=>{if(!a){h(null),_(null);return}let t=!1;return f(!0),on().catch(()=>{t||J.error(e(`settings.openchamber.archivedSessions.toast.loadFailed`))}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a,e]);let v=Q.useMemo(()=>{let t=s.map(e=>({id:e.id,normalizedPath:e.path})),n=Ys([],t,new Map,m(),c),r=new Map;for(let[e,t]of n.archivedSessionsByProject)r.set(e,[...t].sort((e,t)=>Yg(t)-Yg(e)));let i=new Set;for(let e of r.values())for(let t of e)i.add(t.id);let a=c.filter(e=>!i.has(e.id)).sort((e,t)=>Yg(t)-Yg(e));a.length>0&&r.set(Jg,a);let o=[];for(let e of s){let t=r.get(e.id)??[];t.length!==0&&o.push({projectId:e.id,label:e.label||e.path,path:e.path,sessions:t})}let l=r.get(Jg);return l&&l.length>0&&o.push({projectId:Jg,label:e(`settings.openchamber.archivedSessions.otherProjects`),path:null,sessions:l}),o.sort((e,t)=>t.sessions.length-e.sessions.length||e.label.localeCompare(t.label)),o},[c,s,e]),y=c.length,b=p?v.find(e=>e.projectId===p)??null:null,x=Q.useCallback(async t=>{_(t.id);try{await it(t.id)?J.success(e(`settings.openchamber.archivedSessions.toast.restored`)):J.error(e(`settings.openchamber.archivedSessions.toast.restoreFailed`))}finally{_(null)}},[e]),S=Q.useCallback(e=>{let t=It(e);l(e.id,t),o(!1),u(!1)},[l,o,u]),C=b?b.label:e(`settings.openchamber.archivedSessions.dialog.title`),w=b?b.sessions.length===1?e(`settings.openchamber.archivedSessions.dialog.sessionCountSingle`,{count:b.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.sessionCountPlural`,{count:b.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.description`),T=(0,$.jsxs)(`div`,{className:`space-y-3`,children:[b?(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`!h-7 !px-2 !font-normal text-muted-foreground`,onClick:()=>h(null),children:[(0,$.jsx)(X,{name:`arrow-left-s`,className:`mr-1 h-4 w-4`}),e(`settings.openchamber.archivedSessions.dialog.backToProjects`)]}):null,d?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 typography-meta text-muted-foreground py-6`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),e(`settings.openchamber.archivedSessions.dialog.loading`)]}):b?b.sessions.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground`,children:e(`settings.openchamber.archivedSessions.dialog.emptyProject`)}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:b.sessions.map(t=>{let n=It(t),r=Yg(t),i=g===t.id;return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-border/60 px-3 py-2.5 sm:flex-row sm:items-center sm:gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground truncate`,children:t.title||e(`sessions.sidebar.session.untitled`)}),(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:[r>0?gi(r):null,r>0&&n?` · `:null,n?qn(n):null]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>S(t),children:e(`settings.openchamber.archivedSessions.actions.preview`)}),(0,$.jsxs)(Z,{type:`button`,variant:`default`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>void x(t),children:[i?(0,$.jsx)(X,{name:`loader-4`,className:`mr-1 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(X,{name:`inbox-unarchive`,className:`mr-1 h-3.5 w-3.5`}),e(`settings.openchamber.archivedSessions.actions.restore`)]})]})]},t.id)})}):v.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground`,children:e(`settings.openchamber.archivedSessions.dialog.empty`)}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:v.map(t=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(t.projectId),className:Y(`flex w-full items-center gap-3 rounded-lg border border-border/60 px-3 py-2.5 text-left`,`hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`),children:[(0,$.jsx)(X,{name:`folder`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium text-foreground truncate`,children:t.label}),t.path?(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:qn(t.path)}):null]}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums text-muted-foreground shrink-0`,children:t.sessions.length===1?e(`settings.openchamber.archivedSessions.dialog.sessionCountSingle`,{count:t.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.sessionCountPlural`,{count:t.sessions.length})}),(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]},t.projectId))}),!b&&!d&&y>0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:e(y===1?`settings.openchamber.archivedSessions.summarySingle`:`settings.openchamber.archivedSessions.summaryPlural`,{count:y})}):null]});return i?(0,$.jsx)(fi,{open:a,title:C,onClose:()=>o(!1),contentMaxHeightClassName:`max-h-[min(80vh,640px)]`,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-border/40 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:C}),e]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground`,children:w})]}),children:T}):(0,$.jsx)(Vn,{open:a,onOpenChange:o,children:(0,$.jsxs)(Rn,{className:`max-h-[85vh] max-w-2xl overflow-y-auto`,children:[(0,$.jsxs)(In,{children:[(0,$.jsx)(zn,{children:C}),(0,$.jsx)(Bn,{children:w})]}),T]})})}var Zg=e=>{let t=(0,zc.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=hi(e.normalizedPath),n=r.archivedSessionsByProject.get(e.id)??[],i=s[t]??[],d=new Map(i.map(Qg));n.forEach(n=>{let r=Pr(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 Qg(e){return[e.name.toLowerCase(),e]}var $g=e=>{let t=(0,zc.c)(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:i,availableWorktreesByProject:a,projectRepoStatus:o,projectRootBranches:s,lastRepoStatus:c,buildGroupedSessions:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:d,filterSessionNodesForSearch:f,buildGroupSearchText:m,foldersMap:h}=e,g;if(t[0]!==a||t[1]!==l||t[2]!==i||t[3]!==r||t[4]!==c||t[5]!==n||t[6]!==o||t[7]!==s){let e;t[9]!==a||t[10]!==l||t[11]!==i||t[12]!==r||t[13]!==c||t[14]!==o||t[15]!==s?(e=e=>{let t=Br([...r(e.id),...i(e.id)]),n=a.get(e.normalizedPath)??[],u=o.has(e.id)?!!o.get(e.id):c;return{project:e,groups:l(t,e.normalizedPath,n,s.get(e.id)??null,u)}},t[9]=a,t[10]=l,t[11]=i,t[12]=r,t[13]=c,t[14]=o,t[15]=s,t[16]=e):e=t[16],g=n.map(e),t[0]=a,t[1]=l,t[2]=i,t[3]=r,t[4]=c,t[5]=n,t[6]=o,t[7]=s,t[8]=g}else g=t[8];let _=g,v=_,y;if(t[17]!==m||t[18]!==f||t[19]!==h||t[20]!==u||t[21]!==d||t[22]!==v){bb0:{let e=new WeakMap;if(!u){y=e;break bb0}let t=e=>e.reduce((e,n)=>e+1+t(n.children),0);v.forEach(n=>{n.groups.forEach(n=>{let r=f(n.sessions,d),i=t(r),a=m(n).includes(d),o=p(n.directory??null),s=(o?h[o]??[]:[]).filter(e=>e.name.toLowerCase().includes(d)).length;e.set(n,{filteredNodes:r,matchedSessionCount:i,folderNameMatchCount:s,groupMatches:a,hasMatch:a||i>0||s>0})})}),y=e}t[17]=m,t[18]=f,t[19]=h,t[20]=u,t[21]=d,t[22]=v,t[23]=y}else y=t[23];let b=y,x;bb1:{if(!u){x=v;break bb1}let e;if(t[24]!==b||t[25]!==v){let n;t[27]===b?n=t[28]:(n=e=>({...e,groups:e.groups.filter(e=>b.get(e)?.hasMatch===!0)}),t[27]=b,t[28]=n),e=v.map(n).filter(e_),t[24]=b,t[25]=v,t[26]=e}else e=t[26];x=e}let S=x,C=u?S:v,w;bb2:{if(!u){w=0;break bb2}let e;if(t[29]!==b||t[30]!==C){let n;t[32]===b?n=t[33]:(n=(e,t)=>e+t.groups.reduce((e,t)=>{let n=b.get(t);if(!n)return e;let r=n.folderNameMatchCount+ +!!n.groupMatches;return e+n.matchedSessionCount+r},0),t[32]=b,t[33]=n),e=C.reduce(n,0),t[29]=b,t[30]=C,t[31]=e}else e=t[31];w=e}let T=w,E;return t[34]!==b||t[35]!==_||t[36]!==T||t[37]!==S||t[38]!==C||t[39]!==v?(E={projectSections:_,visibleProjectSections:v,groupSearchDataByGroup:b,searchableProjectSections:S,sectionsForRender:C,searchMatchCount:T},t[34]=b,t[35]=_,t[36]=T,t[37]=S,t[38]=C,t[39]=v,t[40]=E):E=t[40],E};function e_(e){return e.groups.length>0}var t_=e=>{let t=(0,zc.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,m,h;if(t[0]!==n){h=new Map,m=new Map;let e=(t,n,r,i)=>{h.has(t)||h.set(t,new Map);let a=h.get(t);i.forEach(i=>{let o=p(i.worktree?.path??i.session.directory??r??n);a.set(i.session.id,{directory:o}),m.has(t)||m.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]=m,t[2]=h}else m=t[1],h=t[2];let g;t[3]!==m||t[4]!==h?(g={metaByProject:h,firstSessionByProject:m},t[3]=m,t[4]=h,t[5]=g):g=t[5];let _=g,v=Q.useRef(null),y,b;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]!==_||t[15]!==d||t[16]!==a||t[17]!==f?(y=()=>{if(!r||c||K.getState().isNewWorktreeDialogOpen||v.current===r)return;let e=n.find(e=>e.project.id===r);if(!e)return;v.current=r;let t=_.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=_.firstSessionByProject.get(r)?.id??null,g=m??h;if(!g||g===o)return;let y=t.get(g)?.directory??null;s(g,y,r)},b=[r,i,o,s,c,l,u,n,_,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]=_,t[15]=d,t[16]=a,t[17]=f,t[18]=y,t[19]=b):(y=t[18],b=t[19]),Q.useLayoutEffect(y,b);let x,S;t[20]!==r||t[21]!==o||t[22]!==_||t[23]!==a?(x=()=>{if(!r||!o)return;let e=_.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})},S=[r,o,_,a],t[20]=r,t[21]=o,t[22]=_,t[23]=a,t[24]=x,t[25]=S):(x=t[24],S=t[25]),Q.useEffect(x,S)},n_=e=>{let t=(0,zc.c)(4),n;t[0]===e?n=t[1]:(n=(t,n)=>{let r=e.get(t);if(!r||r.length===0)return n;let i=new Map(n.map(r_)),a=[];return r.forEach(e=>{let t=i.get(e);t&&(a.push(t),i.delete(e))}),n.forEach(e=>{i.has(e.id)&&a.push(e)}),a},t[0]=e,t[1]=n);let r=n,i;return t[2]===r?i=t[3]:(i={getOrderedGroups:r},t[2]=r,t[3]=i),i};function r_(e){return[e.id,e]}var i_=e=>{let{t}=qe(),n=Q.useCallback(e=>[e.label,e.branch??``,e.description??``,e.directory??``].join(` `).toLowerCase(),[]),r=Q.useCallback(e=>{let n=p(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=p(r??null),c=new Map;i.forEach(e=>{if(e.path){let t=p(e.path)??e.path;c.set(t,e)}});let l=sc(n,{pinnedSessionIds:e.pinnedSessionIds,omitPinnedSessions:!0,getWorktree:t=>{let n=p(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=p(e.worktreeMetadata.get(t.id)?.path??null)??It(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 m=s??`__project_root__`,h=[{id:`root`,label:o&&a&&a!==`HEAD`?t(`sessions.sidebar.grouping.projectRootWithBranch`,{branch:a}):t(`sessions.sidebar.grouping.projectRoot`),branch:a??null,description:s?qn(s,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:s,folderScopeKey:s,sessions:u.get(m)??[]}],g=new Map;i.forEach(e=>{let t=p(e.path)??e.path,n=u.get(t)??[],r=n.length>0,i=n.reduce((e,t)=>{let n=wt(t.session);return Number.isFinite(n)?Math.max(e,n):e},0);g.set(t,{hasActiveSession:r,lastUpdatedAt:i})});let _=[...i].sort((e,t)=>{let n=p(e.path)??e.path,r=p(t.path)??t.path,i=g.get(n)??{hasActiveSession:!1,lastUpdatedAt:0},a=g.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?[]:_).forEach(t=>{let n=p(t.path)??t.path,r=e.gitBranches.get(n)?.trim()||null,i=t.branch?.trim()||null,a=r&&i&&t.label&&Tr(t.label)===Tr(i)?r:t.label||t.name||Gn(n,e.homeDirectory)||n;h.push({id:`worktree:${n}`,label:a,branch:r||i,description:qn(n,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:t,directory:n,folderScopeKey:n,sessions:u.get(n)??[]})});let v=u.get(d)??[];return h.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?hi(s):null,sessions:v}),h},[e.homeDirectory,e.worktreeMetadata,e.pinnedSessionIds,e.gitBranches,e.isVSCode,t])}},a_=e=>{let t=(0,zc.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,zc.c)(42),{t:n}=qe(),[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?J.success(n(`sessions.sidebar.session.share.successTitle`),{description:n(`sessions.sidebar.session.share.successDescription`)}):J.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)=>{Xe(e).then(e=>{if(!e.ok){J.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(()=>{J.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)?J.success(n(`sessions.sidebar.session.unshare.success`)):J.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=c_,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(l_);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)?ws({sessionIds:[t.id],message:n(`sessions.sidebar.session.archive.success`),undoLabel:n(`sessions.sidebar.undo`),settingsLabel:n(`settings.openchamber.archivedSessions.actions.view`),undoFailedMessage:n(`sessions.sidebar.session.archive.undoFailed`)}):J.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&&ws({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.openchamber.archivedSessions.actions.view`),undoFailedMessage:c.length===1?n(`sessions.sidebar.session.archive.undoFailed`):n(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:c.length})}),l.length>0&&J.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(u_);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 s_(e){return!e.time?.archived}function c_(e,t){return t?e:e.filter(s_)}function l_(e){return e.id}function u_(e){return e.id}var d_=[`project:active:`,`project:archived:`,`pinned:active:`,`pinned:archived:`],f_=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}=qt.getState(),r=n.map(t=>({...t,sidebarCollapsed:e.has(t.id)}));L({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&&d_.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}},p_=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},m_=e=>{let{normalizedProjects:t,activeProjectId:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a,enabled:o=!0}=e,{git:s}=za(),c=Wa(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(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(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 p_(i,2,async e=>{let t=r.get(e.normalizedPath)?.branch?.trim()??``,n=`${e.normalizedPath}\0${t}`,i=await Ki(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=new Map(e);return s.forEach(({id:e,branch:n})=>{n&&t.set(e,n)}),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])},h_=e=>{let t=(0,zc.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},g_=e=>{let t=(0,zc.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=yn.getState().foldersMap;new Set([...Object.keys(e),...a.map(__)]).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 __(e){return hi(e.normalizedPath)}var v_=e=>{let t=(0,zc.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(y_);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 y_(e){return e.size===0?e:new Set}var b_=9e4,x_=15e3,S_=3e5,C_=[2e3,5e3],w_=6e4,T_=12e4,E_=3e5,D_=4,O_=432e5,k_=`openchamber.github-pr-status`,A_=e=>e===`closed`||e===`merged`,j_=e=>{let t=e?.checks;return t?t.state===`pending`||t.pending>0:!1},M_=(e,t,n)=>`${e}::${t}`,N_=new Map,P_=new Map,F_=new Set,I_=new Map,L_=2,R_=0,z_=[],B_=()=>R_<L_?(R_+=1,Promise.resolve()):new Promise(e=>{z_.push(e)}),V_=()=>{let e=z_.shift();if(e){e();return}R_=Math.max(0,R_-1)},H_=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),U_=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,W_=e=>{let t=U_(e);return!t?.directory||!t.branch?null:`${t.directory}::${t.branch}`},G_=(e,t)=>Object.entries(e).filter(([,e])=>W_(e)===t).map(([e])=>e),K_=(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}}},q_=e=>!e?.params?.canShow||!e.params.github?.prStatus?null:{...e.params,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null},J_=(e,t,n)=>{let r=G_(e,t),i=r.map(t=>q_(e[t])).filter(e=>!!e);if(i.length===0)return null;let a=q_(e[n]);if(a&&W_(e[n])===t)return a;let o=r.map(t=>e[t]).find(e=>!!(e?.resolvedRemoteName&&q_(e)));return o?q_(o):i.find(e=>!!e.remoteName)||(i[0]??null)},Y_=e=>({status:e.status,isInitialStatusResolved:e.isInitialStatusResolved,lastRefreshAt:e.lastRefreshAt,lastDiscoveryPollAt:e.lastDiscoveryPollAt,identity:U_(e),resolvedRemoteName:e.resolvedRemoteName??e.status?.resolvedRemoteName??null}),X_=e=>({...H_(),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}),Z_=oe()(se((e,t)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:t=>{e(e=>e.entries[t]?e:{entries:{...e.entries,[t]:H_()}})},setParams:(t,n)=>{e(e=>{let r=e.entries[t]??H_();return{entries:{...e.entries,[t]:K_(r,n)}}})},startWatching:n=>{if(e(e=>{let t=e.entries[n]??H_();return{entries:{...e.entries,[n]:{...t,watchers:t.watchers+1}}}}),N_.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=P_.get(n)??[];i.push(r),P_.set(n,i)};t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),C_.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<S_)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}A_(r.status?.pr?.state)||Date.now()-r.lastRefreshAt<(j_(r.status)?w_:r.status?.checks&&r.status.checks.state!==`pending`?E_:T_)||t().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})}},x_);N_.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=N_.get(n);typeof i==`number`&&window.clearInterval(i),N_.delete(n);let a=P_.get(n);a&&a.length>0&&a.forEach(e=>{window.clearTimeout(e)}),P_.delete(n)},refresh:async(n,r)=>{let i=t(),a=i.entries[n],o=W_(a);if(!a||!o)return;let s=G_(i.entries,o),c=s.some(e=>!!i.entries[e]?.status?.pr);if(r?.onlyExistingPr&&!c)return;let l=I_.get(o)??0;if(!r?.force&&Date.now()-l<b_||F_.has(o))return;let u=J_(i.entries,o,n);if(u){if(F_.add(o),I_.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}}),F_.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}}),F_.delete(o);return}try{e(e=>({...e,activeRequestCount:e.activeRequestCount+1,totalRequestCount:e.totalRequestCount+1})),await B_();let t;try{t=await u.github.prStatus(u.directory,u.branch,u.remoteName??void 0,{force:r?.force})}finally{V_()}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=U_(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{F_.delete(o),e(e=>({...e,activeRequestCount:Math.max(0,e.activeRequestCount-1)}))}}},refreshTargets:async(e,n)=>{await p_(Array.from(new Set(e.map(e=>{let t=e.directory.trim(),n=e.branch.trim();return!t||!n?null:M_(t,n,e.remoteName??null)}).filter(e=>!!e))),D_,e=>t().refresh(e,n))},updateStatus:(t,n)=>{e(e=>{let r=e.entries[t]??H_();return{entries:{...e.entries,[t]:{...r,status:n(r.status)}}}})}}),{name:k_,storage:Ne(),partialize:e=>({entries:Object.fromEntries(Object.entries(e.entries).filter(([,e])=>{let t=U_(e);if(!t?.directory||!t.branch)return!1;let n=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return n===0||Date.now()-n<O_}).map(([e,t])=>[e,Y_(t)]))}),merge:(e,t)=>{let n=e?.entries??{};return{...t,entries:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,X_(t)]))}}})),Q_=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`},$_=e=>{let t=Q_(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}},ev=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??``}`,tv=new Map,nv=new Map,rv=e=>{let t=(0,zc.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=$_(e);if(!a)continue;let o=ev(a);n.set(i,o),r.set(i,a)}if(n.size===tv.size){let e=!0;for(let[t,r]of n)if(tv.get(t)!==r){e=!1;break}if(e)return nv}return tv=n,nv=r,r},t[0]=e,t[1]=n),Z_(n)},iv=e=>{let t=(0,zc.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)(ms,{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)(Rn,{className:`w-full max-w-2xl gap-0 overflow-hidden p-0`,children:(0,$.jsx)(so,{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)(Vn,{open:n,onOpenChange:r,children:s}),t[6]=r,t[7]=n,t[8]=s,t[9]=c):c=t[9],c},av=Q.memo(e=>{let t=(0,zc.c)(90),{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}=qe(),[ee,L]=Q.useState(!1),[R,z]=Q.useState(``),B=Q.useRef(null),V=k||ee,H=k?A:R,te;t[0]===n.name?te=t[1]:(te=()=>{z(n.name),L(!0)},t[0]=n.name,t[1]=te);let U=te,ne;t[2]!==H||t[3]!==n.name||t[4]!==k||t[5]!==s||t[6]!==v?(ne=()=>{let e=H.trim();e&&e!==n.name&&s(e),k&&v&&v(),L(!1),z(``)},t[2]=H,t[3]=n.name,t[4]=k,t[5]=s,t[6]=v,t[7]=ne):ne=t[7];let W=ne,re;t[8]!==k||t[9]!==y?(re=()=>{k&&y&&y(),L(!1),z(``)},t[8]=k,t[9]=y,t[10]=re):re=t[10];let G=re,ie;t[11]!==k||t[12]!==_?(ie=e=>{if(k&&_){_(e);return}z(e)},t[11]=k,t[12]=_,t[13]=ie):ie=t[13];let ae=ie,oe,se;t[14]===k?(oe=t[15],se=t[16]):(oe=()=>{if(!k)return;let e=()=>{let e=B.current;e&&(e.focus(),e.select())},t=requestAnimationFrame(e),n=window.setTimeout(e,0);return()=>{cancelAnimationFrame(t),window.clearTimeout(n)}},se=[k],t[14]=k,t[15]=oe,t[16]=se),Q.useEffect(oe,se);let ce;t[17]===M?ce=t[18]:(ce=Ir(M),t[17]=M,t[18]=ce);let le=ce,ue;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(ue=Y(`oc-folder`),t[19]=ue):ue=t[19];let de=j&&`bg-primary/10 ring-1 ring-inset ring-primary/30`,fe;t[20]===de?fe=t[21]:(fe=Y(`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`,Cr,de),t[20]=de,t[21]=fe);let pe;t[22]===le?pe=t[23]:(pe={paddingLeft:le},t[22]=le,t[23]=pe);let me=V?void 0:o,he=V?void 0:`button`,ge=V?void 0:0,_e;t[24]!==o||t[25]!==V?(_e=V?void 0:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},t[24]=o,t[25]=V,t[26]=_e):_e=t[26];let ve;t[27]!==n.name||t[28]!==a||t[29]!==I?(ve=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]=ve):ve=t[30];let ye=P?O?`pr-7`:`group-hover/folder:pr-7 group-focus-within/folder:pr-7`:``,be;t[31]===ye?be=t[32]:(be=Y(`min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]`,ye),t[31]=ye,t[32]=be);let xe=j?`text-primary`:`text-muted-foreground`,Se;t[33]===xe?Se=t[34]:(Se=Y(`h-4 w-4 flex-shrink-0`,xe),t[33]=xe,t[34]=Se);let Ce;t[35]===Se?Ce=t[36]:(Ce=(0,$.jsx)(X,{name:`folder-open`,className:Se}),t[35]=Se,t[36]=Ce);let we;t[37]!==H||t[38]!==n.name||t[39]!==G||t[40]!==ae||t[41]!==W||t[42]!==a||t[43]!==j||t[44]!==V||t[45]!==r||t[46]!==I?(we=V?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-1 items-center gap-1`,onPointerDown:ov,onMouseDown:sv,onSubmit:e=>{e.preventDefault(),W()},children:[(0,$.jsx)(`input`,{ref:B,value:H,onChange:e=>ae(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:cv,onPointerDown:lv,onMouseDown:uv,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),G();return}(e.key===` `||e.key===`Enter`)&&e.stopPropagation()}}),(0,$.jsx)(`button`,{type:`submit`,className:`shrink-0 text-muted-foreground hover:text-foreground`,onClick:dv,onPointerDown:fv,onMouseDown:pv,children:(0,$.jsx)(X,{name:`check`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),G()},onPointerDown:mv,onMouseDown:hv,className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(X,{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:Y(`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)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground`}):(0,$.jsx)(X,{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]=G,t[40]=ae,t[41]=W,t[42]=a,t[43]=j,t[44]=V,t[45]=r,t[46]=I,t[47]=we):we=t[47];let Te;t[48]!==be||t[49]!==Ce||t[50]!==we?(Te=(0,$.jsxs)(`div`,{className:be,children:[Ce,we]}),t[48]=be,t[49]=Ce,t[50]=we,t[51]=Te):Te=t[51];let Ee;t[52]!==O||t[53]!==P||t[54]!==M||t[55]!==n.name||t[56]!==U||t[57]!==N||t[58]!==c||t[59]!==S||t[60]!==C||t[61]!==V||t[62]!==I?(Ee=!V&&(!N||P)?(0,$.jsx)(`div`,{className:`flex items-center gap-0.5 px-0.5`,children:(0,$.jsxs)(`div`,{className:Y(`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)(X,{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)(X,{name:`folder-add`,className:`h-3.5 w-3.5`})}):null,P?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),U()},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)(X,{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)(X,{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]=U,t[57]=N,t[58]=c,t[59]=S,t[60]=C,t[61]=V,t[62]=I,t[63]=Ee):Ee=t[63];let De;t[64]!==b||t[65]!==fe||t[66]!==pe||t[67]!==me||t[68]!==he||t[69]!==ge||t[70]!==_e||t[71]!==ve||t[72]!==Te||t[73]!==Ee?(De=(0,$.jsxs)(`div`,{ref:b,className:fe,style:pe,onClick:me,role:he,tabIndex:ge,onKeyDown:_e,"aria-label":ve,children:[Te,Ee]}),t[64]=b,t[65]=fe,t[66]=pe,t[67]=me,t[68]=he,t[69]=ge,t[70]=_e,t[71]=ve,t[72]=Te,t[73]=Ee,t[74]=De):De=t[74];let Oe;t[75]!==P||t[76]!==M||t[77]!==u||t[78]!==d||t[79]!==a||t[80]!==f||t[81]!==l||t[82]!==F||t[83]!==r||t[84]!==i||t[85]!==I?(Oe=a?null:(0,$.jsxs)(`div`,{className:`pb-1`,children:[i,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:Ir(M+1)},children:I(`sessions.sidebar.folderItem.emptyFolder`)})]}),t[75]=P,t[76]=M,t[77]=u,t[78]=d,t[79]=a,t[80]=f,t[81]=l,t[82]=F,t[83]=r,t[84]=i,t[85]=I,t[86]=Oe):Oe=t[86];let ke;return t[87]!==De||t[88]!==Oe?(ke=(0,$.jsxs)(`div`,{className:ue,children:[De,Oe]}),t[87]=De,t[88]=Oe,t[89]=ke):ke=t[89],ke});function ov(e){return e.stopPropagation()}function sv(e){return e.stopPropagation()}function cv(e){return e.stopPropagation()}function lv(e){return e.stopPropagation()}function uv(e){return e.stopPropagation()}function dv(e){return e.stopPropagation()}function fv(e){return e.stopPropagation()}function pv(e){return e.stopPropagation()}function mv(e){return e.stopPropagation()}function hv(e){return e.stopPropagation()}var gv=e=>{let t=(0,zc.c)(21),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:a}=e,o=`session-drag:${n}`,s;t[0]!==r||t[1]!==n||t[2]!==i?(s={type:`session`,sessionId:n,sessionDirectory:r,sessionTitle:i},t[0]=r,t[1]=n,t[2]=i,t[3]=s):s=t[3];let c;t[4]!==o||t[5]!==s?(c={id:o,data:s},t[4]=o,t[5]=s,t[6]=c):c=t[6];let{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:p,isDragging:m}=xo(c),h;t[7]===u?h=t[8]:(h=e=>{e.stopPropagation(),u?.onPointerDown&&u.onPointerDown(e)},t[7]=u,t[8]=h);let g=h,_;t[9]===f?_=t[10]:(_=vo.Translate.toString(f),t[9]=f,t[10]=_);let v;t[11]!==_||t[12]!==p?(v={transform:_,transition:p},t[11]=_,t[12]=p,t[13]=v):v=t[13];let y=m?`opacity-30`:void 0,b;return t[14]!==l||t[15]!==a||t[16]!==g||t[17]!==d||t[18]!==v||t[19]!==y?(b=(0,$.jsx)(`div`,{ref:d,...l,onPointerDown:g,style:v,className:y,children:a}),t[14]=l,t[15]=a,t[16]=g,t[17]=d,t[18]=v,t[19]=y,t[20]=b):b=t[20],b},_v=e=>{let t=(0,zc.c)(11),{folderId:n,children:r}=e,i=`folder-drop:${n}`,a;t[0]===n?a=t[1]:(a={type:`folder`,folderId:n},t[0]=n,t[1]=a);let o;t[2]!==i||t[3]!==a?(o={id:i,data:a},t[2]=i,t[3]=a,t[4]=o):o=t[4];let{setNodeRef:s,isOver:c}=uo(o),l;t[5]!==r||t[6]!==c||t[7]!==s?(l=r(s,c),t[5]=r,t[6]=c,t[7]=s,t[8]=l):l=t[8];let u;return t[9]===l?u=t[10]:(u=(0,$.jsx)($.Fragment,{children:l}),t[9]=l,t[10]=u),u},vv=e=>{let t=(0,zc.c)(26),{scopeKey:n,onSessionDroppedOnFolder:r,sessionIds:i,folderIdBySessionId:a,onSessionsReordered:o,children:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c={activationConstraint:{distance:8}},t[0]=c):c=t[0];let l=_o(lo(ho,c)),[u,d]=Q.useState(null),[f,p]=Q.useState(`Session`),[m,h]=Q.useState(null),[g,_]=Q.useState(null);if(!n){let e;return t[1]===s?e=t[2]:(e=(0,$.jsx)($.Fragment,{children:s}),t[1]=s,t[2]=e),e}let v;t[3]!==a||t[4]!==r||t[5]!==o?(v=e=>{d(null),h(null),_(null);let{active:t,over:n}=e;if(!n)return;let i=t.data.current,s=n.data.current;if(i?.type===`session`&&i.sessionId&&s?.type===`folder`&&s.folderId){r(i.sessionId,s.folderId);return}if(i?.type===`session`&&i.sessionId&&s?.type===`session`&&typeof n.id==`string`){let e=n.id.replace(/^session-drag:/,``);Ts(i.sessionId,e,a)&&o(i.sessionId,e)}},t[3]=a,t[4]=r,t[5]=o,t[6]=v):v=t[6];let y=v,b,x;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=e=>{let t=e.active.data.current;if(t?.type===`session`&&t.sessionId){d(t.sessionId),p(t.sessionTitle??`Session`);let n=e.active.rect.current.initial?.width,r=e.active.rect.current.initial?.height;h(typeof n==`number`?n:null),_(typeof r==`number`?r:null)}},x=()=>{d(null),h(null),_(null)},t[7]=b,t[8]=x):(b=t[7],x=t[8]);let S;t[9]===i?S=t[10]:(S=i.map(yv),t[9]=i,t[10]=S);let C;t[11]!==s||t[12]!==S?(C=(0,$.jsx)(Co,{items:S,strategy:So,children:s}),t[11]=s,t[12]=S,t[13]=C):C=t[13];let w;t[14]!==g||t[15]!==u||t[16]!==f||t[17]!==m?(w=u?(0,$.jsxs)(`div`,{style:{width:m?`${m}px`:`auto`,height:g?`${g}px`:`auto`},className:`flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none`,children:[(0,$.jsx)(X,{name:`sticky-note`,className:`h-4 w-4 text-muted-foreground mr-2 flex-shrink-0`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground`,children:f})]}):null,t[14]=g,t[15]=u,t[16]=f,t[17]=m,t[18]=w):w=t[18];let T;t[19]===w?T=t[20]:(T=(0,$.jsx)(mo,{children:w}),t[19]=w,t[20]=T);let E;return t[21]!==y||t[22]!==l||t[23]!==C||t[24]!==T?(E=(0,$.jsxs)(go,{sensors:l,collisionDetection:po,onDragStart:b,onDragCancel:x,onDragEnd:y,children:[C,T]}),t[21]=y,t[22]=l,t[23]=C,t[24]=T,t[25]=E):E=t[25],E};function yv(e){return`session-drag:${e}`}var bv=3e4,xv=e=>{let t=e,n=t.metadata?.openchamber?.titleRefresh,r=wt(e)||0;return[e.title??``,e.share?e.share.url??`1`:``,t.hasChildren?`1`:``,t.parentID??``,t.metadata?.openchamber?.assistant?`1`:``,n?.isGenerating?`1`:``,String(n?.lastError??``),String(n?.failedAt??``),Math.floor(r/bv)].join(`\0`)},Sv=(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)},Cv=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(let n of e.children)if(Cv(n,t))return!0;return!1},wv=e=>e.children.length===0?``:e.children.map(e=>e.children.length===0?e.session.id:`${e.session.id}:${wv(e)}`).join(`|`),Tv=(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},Ev=oe()(se(e=>({displayMode:`minimal`,projectSortOrder:`manual`,setDisplayMode:t=>e({displayMode:t}),setProjectSortOrder:t=>e({projectSortOrder:t})}),{name:`session-display-mode`,storage:P(),version:4,migrate:(e,t)=>{let n=e??{};return t<1?{...n,displayMode:`minimal`,projectSortOrder:`manual`}:t<2||t<3?{...n,projectSortOrder:`manual`}:t<4?{displayMode:n.displayMode??`minimal`,projectSortOrder:n.projectSortOrder??`manual`}:n}}));typeof window<`u`&&o(e=>{u(e)&&Ev.persist.rehydrate()});var Dv=50,Ov=30,kv=28,Av=(e,t)=>t?e.sessions.some(e=>Cv(e,t)):!1,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)},Mv=(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)},Nv=(e,t,n)=>{let r=i=>{let a=i.session.id,o=e.folderScopeKey??p(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)},Pv=(e,t,n)=>{let r=e.folderScopeKey??p(e.directory??null);return!!(r&&t[r]!==n[r])},Fv=(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)},Iv=(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&&xv(a)!==xv(o)||e.children.some(r)};return e.sessions.some(r)},Lv=e=>{if(e.projectId)return e.projectRepoStatus.has(e.projectId)?e.projectRepoStatus.get(e.projectId):void 0},Rv=e=>{let t=new WeakMap,n=e=>{t.set(e,wv(e));for(let t of e.children)n(t)};return e.forEach(n),t},zv=e=>{let t=[],n=e=>{e.forEach(e=>{t.push(e.session),e.children.length>0&&n(e.children)})};return n(e),t},Bv=(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!==t.groupSearchDataByGroup||e.visibleSessionCount!==t.visibleSessionCount||e.collapsedGroups!==t.collapsedGroups&&e.collapsedGroups.has(e.groupKey)!==t.collapsedGroups.has(t.groupKey)||e.projectRepoStatus!==t.projectRepoStatus&&Lv(e)!==Lv(t)||e.pinnedSessionIds!==t.pinnedSessionIds&&jv(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&Fv(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderByScope!==t.sessionOrderByScope&&Nv(t.group,e.sessionOrderByScope,t.sessionOrderByScope)||e.sessionOrderActivityByScope!==t.sessionOrderActivityByScope&&Pv(t.group,e.sessionOrderActivityByScope,t.sessionOrderActivityByScope)||e.currentSessionId!==t.currentSessionId&&(Av(e.group,e.currentSessionId)||Av(t.group,t.currentSessionId))||e.editingId!==t.editingId&&(Av(e.group,e.editingId)||Av(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Av(e.group,e.editingId)||Av(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Tv(e.group.sessions,e.openSidebarMenuKey,`project`,!!e.group.isArchivedBucket),r=Tv(t.group.sessions,t.openSidebarMenuKey,`project`,!!t.group.isArchivedBucket);if(n||r)return!1}if(e.liveSessionById!==t.liveSessionById&&Iv(t.group,e.liveSessionById,t.liveSessionById)||e.alwaysVisibleSessionIds!==t.alwaysVisibleSessionIds&&Mv(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.dragHandleProps===t.dragHandleProps&&e.scrollContainerRef===t.scrollContainerRef&&e.shortcutTargetSessionId===t.shortcutTargetSessionId&&e.shortcutTargetVisibleIndex===t.shortcutTargetVisibleIndex};function Vv(e){let{t}=qe(),{group:n,groupKey:r,isArchivedLoading:i=!1,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:s,normalizedSessionSearchQuery:c,groupSearchDataByGroup:l,visibleSessionCount:u,collapsedGroups:d,collapsedFolderIds:f,toggleFolderCollapse:h,renameFolder:g,deleteFolder:_,showDeletionDialog:v,setDeleteFolderConfirm:y,renderSessionNode:b,projectRepoStatus:x,lastRepoStatus:S,showMoreGroupSessions:C,resetGroupSessionLimit:w,mobileVariant:T,alwaysShowActions:E,activeProjectId:D,setActiveProjectIdOnly:O,setActiveMainTab:k,setSessionSwitcherOpen:A,openNewSessionDraft:j,addSessionToFolder:M,createFolderAndStartRename:N,renamingFolderId:P,renameFolderDraft:F,setRenameFolderDraft:I,setRenamingFolderId:ee,pinnedSessionIds:L,expandedParents:R,sessionOrderByScope:z,sessionOrderActivityByScope:B,onReorderSessions:V,currentSessionId:H,shortcutTargetSessionId:te=null,shortcutTargetVisibleIndex:U=null,editingId:ne,openSidebarMenuKey:W,prVisualStateByDirectoryBranch:re,onToggleCollapsedGroup:G,dragHandleProps:ie,compactBodyPadding:ae=!1,scrollContainerRef:oe,alwaysVisibleSessionIds:se}=e,ce=n.folderScopeKey??p(n.directory??null),le=Q.useMemo(()=>Is(n.sessions,ce?z[ce]:void 0,ce?B[ce]:void 0,L),[ce,n.sessions,L,B,z]),ue=s?l.get(n):null,de=Ev(e=>e.displayMode),fe=yn(e=>e.foldersMap),pe=de===`minimal`&&!m(),me=n.isArchivedBucket?null:p(n.directory??null),he=Rt(e=>me?e.activePaginationByDirectory.get(me):void 0),ge=!s&&d.has(r),_e=Ns(),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(()=>ce?fe[ce]??[]:[],[ce,fe]),Ce=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]),we=Q.useMemo(()=>Se.map(e=>({folder:e,nodes:e.sessionIds.map(e=>Ce.get(e)).filter(e=>!!e).sort(le)})),[Se,Ce,le]),Te=Q.useMemo(()=>{let e=new Map(we.map(e=>[e.folder.id,e])),t=new Map;for(let{folder:e}of we){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 we.filter(({folder:e})=>i(e.id))},[we,n.isArchivedBucket,s,c]),Ee=Q.useMemo(()=>new Set(Te.flatMap(e=>e.folder.sessionIds)),[Te]),De=Q.useMemo(()=>xe.filter(e=>!Ee.has(e.session.id)),[xe,Ee]),Oe=Q.useMemo(()=>Te.filter(({folder:e})=>!e.parentId),[Te]),ke=`project`,Ae=Q.useMemo(()=>{let e=new Set;return Sv(xe,H,e),Te.forEach(({nodes:t})=>{Sv(t,H,e)}),e},[xe,Te,H]),je=Q.useMemo(()=>{let e=new Set;return Sv(xe,ne,e),Te.forEach(({nodes:t})=>{Sv(t,ne,e)}),e},[xe,Te,ne]),K=Q.useMemo(()=>{if(!W)return null;let e=Tv(xe,W,ke,!!n.isArchivedBucket);if(e)return e;for(let{nodes:e}of Te){let t=Tv(e,W,ke,!!n.isArchivedBucket);if(t)return t}return null},[W,xe,Te,n.isArchivedBucket]),Me=Q.useMemo(()=>Rv(xe),[xe]),Ne=Q.useMemo(()=>{let e=new WeakMap;return Te.forEach(({nodes:t})=>{t.forEach(t=>e.set(t,wv(t)))}),e},[Te]),Pe=Q.useMemo(()=>e=>Me.get(e)??Ne.get(e)??``,[Me,Ne]),q=Q.useMemo(()=>e=>({subtreeContainsActive:Ae,subtreeContainsEditing:je,menuOpenSessionId:K,nodeStructureKey:Pe(e)}),[Ae,je,K,Pe]),Fe=De.length,Ie=n.isArchivedBucket||s?De:De.slice(0,ve),Le=n.isArchivedBucket||s?De:Os(De,ve,se),Re=Fe-Le.length,ze=Q.useMemo(()=>mc({folders:Te,visibleUngroupedNodes:Le,collapsedFolderIds:f,hasSessionSearchQuery:s}),[Te,f,s,Le]),Be=he?.hasMore===!0,Ve=he?.loadingMore===!0,Ue=u===void 0||u<=_e,Ge=!n.isArchivedBucket&&!s&&Fe>_e&&!Ue,Ke=n.isArchivedBucket===!0&&!s&&Le.length>=Dv,Je=n.isArchivedBucket!==!0&&!s&&Le.length>=Ov,Ye=Ke||Je,Xe=n.isArchivedBucket?`archived`:`active`,Ze=Ye&&Le.some(e=>{if(e.children.length===0)return!1;let t=`project:${Xe}:${e.session.id}`;return R.has(t)}),Qe=Q.useRef(null),[$e,et]=Q.useState(null),[,tt]=Q.useState(0);We(Ye?Qe:null,()=>{tt(e=>e+1)}),Q.useLayoutEffect(()=>{if(!Ye){et(e=>e===null?e:null);return}let e=Qe.current;if(!e){et(e=>e===null?e:null);return}let t=null,n=oe?.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){et(e=>e===null?e:null);return}let r=e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop;et(n=>n?.container===e&&n.scrollElement===t&&Math.abs(n.scrollMargin-r)<1?n:{container:e,scrollElement:t,scrollMargin:r})});let nt=Qe.current,rt=oe?.current??null,it=Ye&&$e!==null&&$e.container===nt&&$e.scrollElement.contains(nt)&&(rt===null||$e.scrollElement===rt),at=$e?.scrollElement??null,ot=$e?.scrollMargin??0,st=Vo({count:Le.length,enabled:it,getScrollElement:()=>at,initialOffset:()=>at?.scrollTop??0,estimateSize:()=>kv,overscan:Ze?20:8,scrollMargin:ot,getItemKey:e=>Le[e]?.session.id??e}),ct=Es(Le,te,U);Q.useLayoutEffect(()=>{!it||!te||ct===null||st.getVirtualItems().some(e=>e.index===ct)||st.scrollToIndex(ct,{align:`auto`,behavior:`auto`})},[ot,st,te,ct,it]);let lt=Q.useMemo(()=>zv(xe),[xe]),ut=Q.useMemo(()=>{if(!n.isArchivedBucket)return new Map;let e=new Map,t=new Map;for(let{folder:e}of Te){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=Te.find(({folder:t})=>t.id===e),a=i?zv(i.nodes):[],o=t.get(e)??[];for(let e of o)a.push(...r(e,n));return a};for(let{folder:t}of Te)e.set(t.id,r(t.id,new Set));return e},[Te,n.isArchivedBucket]),dt=Q.useMemo(()=>({projectLabel:n.isMain?null:n.label,branchLabel:n.branch&&n.branch!==`HEAD`?n.branch:null}),[n.branch,n.isMain,n.label]),ft=He(e=>{e.preventDefault(),e.stopPropagation();let t=p(n.directory??null),r=n.branch?.trim()??null,i=t&&r?re.get(`${t}::${r}`)?.url??null:null;i&&wo(i)});if(s&&!ye&&Oe.length===0&&De.length===0)return null;let pt=a&&x.has(a)?!!x.get(a):S,mt=p(n.directory??null),ht=n.branch?.trim()??null,gt=mt&&ht?re.get(`${mt}::${ht}`)??null:null,_t=!!(gt&&n.branch),vt=!gt&&!n.isMain&&!!n.branch,yt=gt&>.state===`open`&>.checks?t(`sessions.sidebar.group.pr.checksPassed`,{success:gt.checks.success,total:gt.checks.total}):null,bt=gt&>.state===`open`&>.checks?[gt.checks.failure>0?t(`sessions.sidebar.group.pr.failingCount`,{count:gt.checks.failure}):null,gt.checks.pending>0?t(`sessions.sidebar.group.pr.pendingCount`,{count:gt.checks.pending}):null].filter(e=>!!e).join(`, `):null,xt=gt&>.state===`open`?gt.mergeableState===`blocked`||gt.mergeableState===`dirty`?t(`sessions.sidebar.group.pr.conflictsOrBlocked`):gt.mergeableState===`clean`||gt.canMerge===!0?t(`sessions.sidebar.group.pr.mergeable`):null:null,St=gt&>.state===`open`&>.mergeableState?t(`sessions.sidebar.group.pr.mergeState`,{state:gt.mergeableState}):null,wt=gt?.base??null,Tt=gt?.head??null,Et=(()=>{if(!gt)return n.branch&&Rr(n.branch,n.label)?{label:n.branch,color:null}:null;switch(gt.visualState){case`merged`:return{label:t(`sessions.sidebar.group.pr.status.merged`),color:`var(--pr-merged)`};case`open`:return gt.canMerge===!0||gt.mergeableState===`clean`||gt.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:gt.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=Te.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=ut.get(e.id)??[];return(0,$.jsx)(_v,{folderId:e.id,children:(i,l)=>(0,$.jsx)(av,{folder:e,sessions:t,subFolderItems:o,isCollapsed:!s&&f.has(e.id),onToggle:()=>h(e.id),onRename:t=>{ce&&g(ce,e.id,t)},onDelete:()=>{if(n.isArchivedBucket){Ct.requestDelete({sessions:c,mode:`session`});return}if(!ce)return;if(!v){_(ce,e.id);return}let r=Te.filter(({folder:t})=>t.parentId===e.id).length,i=t.length;y({scopeKey:ce,folderId:e.id,folderName:e.name,subFolderCount:r,sessionCount:i})},renderSessionNode:b,getRenderExtras:Pe?e=>({subtreeContainsActive:Ae,subtreeContainsEditing:je,menuOpenSessionId:K,nodeStructureKey:Pe(e),childRenderExtrasFor:q}):void 0,groupDirectory:n.directory,projectId:a,mobileVariant:T,alwaysShowActions:E,isRenaming:P===e.id,renameDraft:P===e.id?F:void 0,onRenameDraftChange:e=>I(e),onRenameSave:()=>{let t=F.trim();t&&ce&&g(ce,e.id,t),ee(null),I(``)},onRenameCancel:()=>{ee(null),I(``)},droppableRef:i,isDropTarget:l,depth:r,onNewSession:()=>{a&&a!==D&&O(a),k(`chat`),T&&A(!1),j({directoryOverride:n.directory,targetFolderId:e.id})},onNewSubFolder:r===0?()=>{ce&&N(ce,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=()=>Oe.map(({folder:e,nodes:t})=>Dt(e,t,kt)),jt=!!(!n.isMain&&n.worktree),Mt=E?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)(vv,{scopeKey:ce,sessionIds:ze.sessionIds,folderIdBySessionId:ze.folderIdBySessionId,onSessionDroppedOnFolder:(e,t)=>{ce&&M(ce,t,e)},onSessionsReordered:(e,t)=>{V(ze.sessionIds,e,t,Fs(n.sessions.map(e=>e.session)))},children:[At(),Ye?(0,$.jsx)(`div`,{ref:Qe,children:it?(0,$.jsx)(`div`,{style:{height:st.getTotalSize(),position:`relative`},children:st.getVirtualItems().map(e=>{let t=Le[e.index];return t?(0,$.jsx)(`div`,{"data-index":e.index,ref:st.measureElement,className:`[&_[data-session-row]]:my-px`,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start-ot}px)`},children:b(t,kt,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:Ae,subtreeContainsEditing:je,menuOpenSessionId:K,nodeStructureKey:Pe(t),childRenderExtrasFor:q})},t.session.id):null})}):Le.map(e=>b(e,kt,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:Ae,subtreeContainsEditing:je,menuOpenSessionId:K,nodeStructureKey:Pe(e),childRenderExtrasFor:q}))}):Le.map(e=>b(e,kt,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:Ae,subtreeContainsEditing:je,menuOpenSessionId:K,nodeStructureKey:Pe(e),childRenderExtrasFor:q})),Fe===0&&Te.length===0?(0,$.jsx)(`div`,{className:Ni,style:{paddingLeft:Ir(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||Ge?(0,$.jsxs)(`div`,{className:Y(Ni,`flex w-full items-center gap-3 text-muted-foreground/60`),style:{paddingLeft:Ir(kt)},children:[Re>0||Be?(0,$.jsx)(`button`,{type:`button`,onClick:()=>C(r,Ie.length,Fe),disabled:Ve,className:Y(`text-left transition-colors hover:text-muted-foreground/80 disabled:pointer-events-none`,Ve&&`animate-pulse`),children:t(`sessions.sidebar.group.showMore`)}):null,Ge?(0,$.jsx)(`button`,{type:`button`,onClick:()=>w(r),className:`text-left transition-colors hover:text-muted-foreground/80`,children:t(`sessions.sidebar.group.showFewer`)}):null]}):null]}),Pt=o?ae?`pb-0`:`pb-0.5`:ae?`pb-1`:`pb-1.5`,Ft=Ir(Ot);return o?(0,$.jsx)(`div`,{className:`oc-group`,children:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Pt),children:Nt})}):(0,$.jsxs)(`div`,{className:`oc-group`,children:[(0,$.jsxs)(`div`,{"data-mobile-press-feedback":ie?`none`:void 0,className:Y(`group/gh relative flex min-w-0 cursor-pointer items-start justify-between gap-1.5 rounded-lg py-1.5 pr-2`,Cr),style:{paddingLeft:Ft},onClick:()=>G(r),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G(r))},"aria-label":t(ge?`sessions.sidebar.group.expandAria`:`sessions.sidebar.group.collapseAria`,{label:n.label}),"aria-expanded":!ge,children:[(0,$.jsx)(`div`,{ref:ie?.setActivatorNodeRef,className:Y(`min-w-0 flex flex-1 items-start gap-1.5 overflow-hidden transition-[padding] cursor-grab active:cursor-grabbing`,Mt),...ie?.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:_t&>?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 max-w-full items-center`,children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{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)(X,{name:`git-branch`,className:Y(`h-3.5 w-3.5 shrink-0`,E?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:Y(`h-3.5 w-3.5 items-center justify-center`,E?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),gt.url?(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center leading-none`,onMouseDown:e=>e.stopPropagation(),onClick:ft,children:[`#`,gt.number]}):(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center leading-none`,children:[`#`,gt.number]})]})}),(0,$.jsx)(ra,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[wt||Tt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:wt&&Tt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:wt}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:Tt})]}):(0,$.jsx)(`span`,{children:wt??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)(X,{name:`archive`,className:Y(`h-3.5 w-3.5 shrink-0`,E?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:Y(`h-3.5 w-3.5 items-center justify-center`,E?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ar(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)(X,{name:`git-branch`,className:Y(`h-3.5 w-3.5 shrink-0`,E?`hidden`:`group-hover/gh:hidden`)}),(0,$.jsx)(`span`,{className:Y(`h-3.5 w-3.5 items-center justify-center`,E?`inline-flex`:`hidden group-hover/gh:inline-flex`),children:ge?(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ar(n.label,c)})]}):Ar(n.label,c)}),vt&&Et?(0,$.jsxs)(`span`,{className:Y(`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)(X,{name:`archive`,className:`h-3.5 w-3.5 flex-shrink-0`}):!n.isMain||pt?_t&>?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{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)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(ra,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[wt||Tt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:wt&&Tt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:wt}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:Tt})]}):(0,$.jsx)(`span`,{children:wt??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)(X,{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&<.length>0?(0,$.jsx)(`div`,{className:Y(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,E?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Ct.requestDelete({sessions:lt,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)(X,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{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:Y(`absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity`,E?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Ct.requestDelete({sessions:lt,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)(X,{name:`delete-bin`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.group.actions.deleteWorktree`)})})]})}):null,n.directory?(0,$.jsx)(`div`,{className:Y(`absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity`,E?`opacity-100`:`opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100`),children:(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a&&a!==D&&O(a),k(`chat`),T&&A(!1),j({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)(X,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.project.actions.newDraftSession`)})})]})}):null]}),ge?null:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Pt),children:Nt})]})}var Hv=Q.memo(Vv,Bv);function Uv(e){let t=(0,zc.c)(36),{t:n}=qe(),{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)(X,{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)(X,{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 Wv(e){let t=(0,zc.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=Y(`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)(X,{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:Y(`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 Gv(e){let t=(0,zc.c)(52),{items:n,inProgressItems:r,renderSessionNode:i,currentSessionId:a,editingId:o,openSidebarMenuKey:s,headerAccessory:c,onVisibleSessionIdsChange:l}=e,u;t[0]===r?u=t[1]:(u=r===void 0?[]:r,t[0]=r,t[1]=u);let d=u,{t:f}=qe(),[p,m]=Q.useState(!1),h=ri(Xv),g,_;t[2]!==p||t[3]!==d||t[4]!==n||t[5]!==l?(g=()=>{if(p){l?.([]);return}l?.([...n.map(Yv),...d.map(Jv)])},_=[p,d,n,l],t[2]=p,t[3]=d,t[4]=n,t[5]=l,t[6]=g,t[7]=_):(g=t[6],_=t[7]),Q.useLayoutEffect(g,_);let v,y;t[8]!==d||t[9]!==n||t[10]!==h?(v=()=>{h&&(n.some(e=>e.node.session.id===h)||d.some(e=>e.node.session.id===h))&&m(!1)},y=[d,n,h],t[8]=d,t[9]=n,t[10]=h,t[11]=v,t[12]=y):(v=t[11],y=t[12]),Q.useLayoutEffect(v,y);let b,x,S,C;if(t[13]!==a||t[14]!==o||t[15]!==d||t[16]!==n||t[17]!==s){let e=[...n,...d].map(qv);S=new Set,Sv(e,a,S),C=new Set,Sv(e,o,C),b=Tv(e,s,`pinned`,!1),x=new WeakMap;let r=e=>{x.set(e,wv(e)),e.children.forEach(r)};e.forEach(r),t[13]=a,t[14]=o,t[15]=d,t[16]=n,t[17]=s,t[18]=b,t[19]=x,t[20]=S,t[21]=C}else b=t[18],x=t[19],S=t[20],C=t[21];let w;t[22]!==b||t[23]!==x||t[24]!==S||t[25]!==C?(w=e=>({subtreeContainsActive:S,subtreeContainsEditing:C,menuOpenSessionId:b,nodeStructureKey:x.get(e)??``,childRenderExtrasFor:w}),t[22]=b,t[23]=x,t[24]=S,t[25]=C,t[26]=w):w=t[26];let T;t[27]!==w||t[28]!==b||t[29]!==x||t[30]!==S||t[31]!==C?(T=e=>({subtreeContainsActive:S,subtreeContainsEditing:C,menuOpenSessionId:b,nodeStructureKey:x.get(e)??``,childRenderExtrasFor:w}),t[27]=w,t[28]=b,t[29]=x,t[30]=S,t[31]=C,t[32]=T):T=t[32];let E=T;if(n.length+d.length===0)return null;let D;t[33]!==E||t[34]!==i?(D=e=>e.map(e=>(0,$.jsx)(Q.Fragment,{children:i(e.node,0,e.groupDirectory,e.projectId,!1,e.secondaryMeta,`pinned`,E(e.node))},`${e.projectId??``}:${e.node.session.id}`)),t[33]=E,t[34]=i,t[35]=D):D=t[35];let O=D,k;t[36]!==d.length||t[37]!==f?(k=d.length>0?f(`directoryTree.section.pinnedInProgress`):f(`directoryTree.section.pinned`),t[36]=d.length,t[37]=f,t[38]=k):k=t[38];let A;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>m(Kv),t[39]=A):A=t[39];let j=!p,M;t[40]!==c||t[41]!==j||t[42]!==k?(M=(0,$.jsx)(Wv,{title:k,onToggle:A,expanded:j,accessory:c}),t[40]=c,t[41]=j,t[42]=k,t[43]=M):M=t[43];let N;t[44]!==p||t[45]!==d||t[46]!==n||t[47]!==O?(N=p?null:(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[O(n),O(d)]}),t[44]=p,t[45]=d,t[46]=n,t[47]=O,t[48]=N):N=t[48];let P;return t[49]!==M||t[50]!==N?(P=(0,$.jsx)(ia,{delay:0,closeDelay:150,timeout:600,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[M,N]})}),t[49]=M,t[50]=N,t[51]=P):P=t[51],P}function Kv(e){return!e}function qv(e){return e.node}function Jv(e){return e.node.session.id}function Yv(e){return e.node.session.id}function Xv(e){return e.focus?.scope===`pinned`?e.focus.sessionId:null}function Zv(e){let t=(0,zc.c)(41),{collapseAllProjects:n,expandAllProjects:r,buttonClassName:i,iconClassName:a}=e,{t:o}=qe(),s;t[0]===i?s=t[1]:(s=Y(`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=Y(`h-3.5 w-3.5`,a),t[4]=a,t[5]=l);let u;t[6]===l?u=t[7]:(u=(0,$.jsx)(X,{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)(na,{asChild:!0,children:(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,className:s,"aria-label":c,onClick:Qv,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)(ra,{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)(aa,{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)(X,{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)(ua,{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)(X,{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)(ua,{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)(ca,{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)(ha,{children:[m,C]}),t[38]=C,t[39]=m,t[40]=w):w=t[40],w}function Qv(e){e.stopPropagation()}var $v=`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`,ey=`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`;function ty(e){let t=(0,zc.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}=qe(),u;t[0]!==n||t[1]!==r||t[2]!==s||t[3]!==l?(u=s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:$v,onClick:n,"aria-label":l(`sessions.sidebar.footer.actions.settings`),children:(0,$.jsx)(X,{name:`settings-3`,className:ey})})}),(0,$.jsx)(ra,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.settings`)})]}),(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:$v,onClick:r,"aria-label":l(`sessions.sidebar.footer.actions.shortcuts`),children:(0,$.jsx)(X,{name:`question`,className:ey})})}),(0,$.jsx)(ra,{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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{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)(X,{name:`download`,className:`size-3.5`})})}),(0,$.jsx)(ra,{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 ny=e=>{let t=(0,zc.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}=qe(),I=A||!P,ee;t[0]!==n||t[1]!==I?(ee={id:n,disabled:I},t[0]=n,t[1]=I,t[2]=ee):ee=t[2];let{attributes:L,listeners:R,setNodeRef:z,transform:B,transition:V,isDragging:H}=xo(ee),te=Q.useRef(!1),U=`project:${n}`,ne=D===U,[W,re]=Q.useState(!1),G=o?Ji[o]:null,ie=s?Zi[s]:void 0,ae=G??`folder-open`,oe;t[3]===ie?oe=t[4]:(oe=ie?{color:ie}:void 0,t[3]=ie,t[4]=oe);let se;t[5]!==ae||t[6]!==oe?(se=(0,$.jsx)(X,{name:ae,className:`h-4 w-4`,style:oe}),t[5]=ae,t[6]=oe,t[7]=se):se=t[7];let ce=se,le;t[8]!==U||t[9]!==O?(le=e=>{e&&re(!1),O(e?U:null)},t[8]=U,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)(X,{name:`add`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.newSession`)]}),(0,$.jsxs)(e,{onClick:b,children:[(0,$.jsx)(X,{name:`refresh`,className:`mr-1.5 h-4 w-4`}),F(`sessions.sidebar.project.actions.syncSessions`)]}),(0,$.jsxs)(e,{onClick:x,children:[(0,$.jsx)(X,{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)(X,{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=iy,me=ay,he=oy,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]===B?be=t[24]:(be=vo.Transform.toString(B),t[23]=B,t[24]=be);let xe;t[25]!==be||t[26]!==V?(xe={transform:be,transition:V},t[25]=be,t[26]=V,t[27]=xe):xe=t[27];let Se=H&&`opacity-30`,Ce;t[28]===Se?Ce=t[29]:(Ce=Y(`relative`,Se),t[28]=Se,t[29]=Ce);let we;t[30]!==g||t[31]!==L||t[32]!==ue||t[33]!==ye||t[34]!==h||t[35]!==N||t[36]!==n||t[37]!==u||t[38]!==l||t[39]!==W||t[40]!==p||t[41]!==ne||t[42]!==f||t[43]!==j||t[44]!==m||t[45]!==R||t[46]!==v||t[47]!==y||t[48]!==a||t[49]!==ce||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)(yc,{open:W,onOpenChange:re,children:[(0,$.jsx)(hc,{render:(0,$.jsx)(`div`,{className:Y(`w-full text-left group/project select-none`),style:{backgroundColor:p&&m?`transparent`:void 0},onContextMenu:e=>{h||(e.preventDefault(),re(!0))}}),children:(0,$.jsxs)(`div`,{className:Y(`relative flex items-center gap-1.5 rounded-lg px-2 py-1.5`,Cr),...L,children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onMouseDown:_e,onClick:ye,...P?R:{},className:Y(`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)(X,{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:Y(`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)(X,{name:`arrow-right-s`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(g?`hidden`:`group-hover/project:hidden group-has-[:focus-visible]/project:hidden`),children:c?(0,$.jsx)(Wi,{project:{id:n,iconImage:c},className:`size-full object-contain`,fallback:ce}):ce})]})}),(0,$.jsx)(`span`,{className:Y(`text-[14px] font-normal truncate lowercase`,u?`text-foreground`:`text-foreground group-hover/project:text-foreground`),children:i})]})}),(0,$.jsx)(ra,{side:`right`,sideOffset:8,children:a})]}),(0,$.jsxs)(`div`,{className:Y(`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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y()},className:Y(`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)(X,{name:`node-tree`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(`sessions.sidebar.project.actions.newWorktreeEllipsis`)})})]}):null,h?null:(0,$.jsxs)(ha,{open:ne,onOpenChange:ue,children:[(0,$.jsx)(_a,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`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`,ne?`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)(X,{name:`more-2`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(ca,{align:`end`,className:`min-w-[180px]`,children:fe(ua)})]})]}),M&&v?(0,$.jsx)(`div`,{className:`absolute right-0.5 top-1/2 z-10 -translate-y-1/2`,children:(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},className:Y(`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)(X,{name:`add`,className:`h-4 w-4`})})}),(0,$.jsx)(ra,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`)})})]})}):null]})}),(0,$.jsx)(_c,{className:`min-w-[180px]`,children:fe(vc)})]})]}),t[30]=g,t[31]=L,t[32]=ue,t[33]=ye,t[34]=h,t[35]=N,t[36]=n,t[37]=u,t[38]=l,t[39]=W,t[40]=p,t[41]=ne,t[42]=f,t[43]=j,t[44]=m,t[45]=R,t[46]=v,t[47]=y,t[48]=a,t[49]=ce,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]!==z||t[60]!==xe||t[61]!==Ce||t[62]!==we?(Te=(0,$.jsxs)(`div`,{ref:z,style:xe,className:Ce,children:[we,w]}),t[58]=w,t[59]=z,t[60]=xe,t[61]=Ce,t[62]=we,t[63]=Te):Te=t[63],Te},ry=Q.memo(e=>{let t=(0,zc.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}=xo(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=Y(`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 iy(e){e.stopPropagation()}function ay(e){e.stopPropagation()}function oy(e){e.stopPropagation()}var sy=e=>{let t=(0,zc.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(ia,{delay:0,closeDelay:150,timeout:600,children:n}),t[0]=n,t[1]=r),r};function cy(e){let{t}=qe(),n=_o(lo(ho,{activationConstraint:{distance:8}}),lo(fo,{coordinateGetter:yo})),r=_o(lo(ho,{activationConstraint:{distance:8}})),i=e.hasSessionSearchQuery?null:(0,$.jsx)(Wv,{title:t(`sessions.sidebar.projectsTitle`),isFirst:!e.hasLeadingSection,accessory:e.headerAccessory}),a=Q.useRef(null),o=Q.useRef(new Map),s=Q.useRef(e.getOrderedGroups);s.current!==e.getOrderedGroups&&(s.current=e.getOrderedGroups,o.current.clear());let c=(t,n)=>{let r=o.current,i=r.get(t);if(i&&i.groups===n)return i.ordered;let a=e.getOrderedGroups(t,n);if(r.set(t,{groups:n,ordered:a}),r.size>256){let e=r.keys().next().value;e!==void 0&&r.delete(e)}return a};return e.sharedSessionsOnly?(0,$.jsx)(sy,{children:(0,$.jsxs)(so,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:Y(`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)(sy,{children:(0,$.jsxs)(so,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:Y(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:[e.topContent,i,e.emptyState]})}):e.sectionsForRender.length===0?(0,$.jsx)(sy,{children:(0,$.jsx)(so,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:Y(`space-y-1 px-3 pb-1`,(e.mobileVariant,``)),children:e.searchEmptyState})}):(0,$.jsx)(sy,{children:(0,$.jsxs)(so,{ref:a,useScrollShadow:!0,scrollShadowSize:96,outerClassName:`flex-1 min-h-0`,className:Y(`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:Ni,children:t(`sessions.sidebar.empty.noSessions.title`)});let i=n.groups.find(e=>e.isArchivedBucket);return[r,...i&&i.id!==r.id?[i]:[]].map(t=>{let i=`${n.project.id}:${t.id}`,o=t.id===r.id;return(0,$.jsx)(Q.Fragment,{children:e.renderGroupSessions(t,i,n.project.id,o,null,!0,a)},i)})})()}):(0,$.jsxs)($.Fragment,{children:[i,(0,$.jsxs)(go,{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)(Co,{items:e.sectionsForRender.map(e=>e.project.id),strategy:So,children:e.sectionsForRender.map(n=>{let i=n.project,o=i.id,s=Gn(i.normalizedPath)||i.normalizedPath,l=qn(i.normalizedPath,e.homeDirectory),u=e.collapsedProjects.has(o),d=o===e.activeProjectId,f=e.loadingProjectIds.has(o),p=e.refreshingProjectIds.has(o),m=e.projectRepoStatus.get(o),h=c(o,n.groups),g=h.find(e=>e.isMain)??null,_=g?h.filter(e=>e.id!==g.id):h;return(0,$.jsx)(ny,{id:o,disabled:e.projectSortOrder!==`manual`,projectLabel:s,projectDescription:l,projectIcon:i.icon,projectColor:i.color,projectIconImage:i.iconImage,isCollapsed:u,isActiveProject:d,isSessionsLoading:f||p,isRepo:!!m,isDesktopShell:e.isDesktopShellRuntime,isStuck:e.stuckProjectHeaders.has(o),hideDirectoryControls:e.hideDirectoryControls,mobileVariant:e.mobileVariant,alwaysShowActions:e.alwaysShowActions,onToggle:()=>e.toggleProject(o),onNewSession:()=>{o!==e.activeProjectId&&e.setActiveProjectIdOnly(o),e.setActiveMainTab(`chat`),e.mobileVariant&&e.setSessionSwitcherOpen(!1),e.openNewSessionDraft({directoryOverride:i.normalizedPath})},onNewWorktreeSession:()=>{o!==e.activeProjectId&&e.setActiveProjectIdOnly(o),e.setActiveMainTab(`chat`),e.openNewWorktreeDialog()},onSyncSessions:()=>e.syncProjectSessions(o),onRenameStart:()=>e.openProjectEditDialog(o),onClose:()=>e.removeProject(o),sentinelRef:t=>{e.projectHeaderSentinelRefs.current.set(o,t)},showCreateButtons:!0,openSidebarMenuKey:e.openSidebarMenuKey,setOpenSidebarMenuKey:e.setOpenSidebarMenuKey,reorderEnabled:e.projectReorderEnabled??!1,children:u?null:(0,$.jsx)(`div`,{className:`space-y-0 pt-0 pb-0.5`,children:f&&n.groups.length===0?(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:Ir(1)},role:`status`,"aria-live":`polite`,children:t(`sessions.sidebar.project.loadingSessions`)}):n.groups.length>0?(0,$.jsxs)(go,{sensors:r,collisionDetection:po,onDragEnd:t=>{if(e.isInlineEditing)return;let{active:n,over:r}=t;if(!r||n.id===r.id)return;let i=_.findIndex(e=>e.id===n.id),a=_.findIndex(e=>e.id===r.id);if(i===-1||a===-1||i===a)return;let s=bo(_,i,a).map(e=>e.id),c=g?[g.id,...s]:s;e.setGroupOrderByProject(e=>{let t=new Map(e);return t.set(o,c),t})},children:[g?e.renderGroupSessions(g,`${o}:${g.id}`,o,!0,null,void 0,a):null,(0,$.jsx)(Co,{items:_.map(e=>e.id),strategy:So,children:_.map(t=>{let n=`${o}:${t.id}`;return(0,$.jsx)(ry,{id:t.id,disabled:e.isInlineEditing,children:r=>e.renderGroupSessions(t,n,o,!1,r,void 0,a)},t.id)})}),(0,$.jsx)(mo,{dropAnimation:null})]}):(0,$.jsx)(`div`,{className:Ni,children:t(`sessions.sidebar.empty.noSessions.title`)})})},o)})}),(0,$.jsx)(mo,{dropAnimation:null})]})]})]})})}function ly(e){if(typeof e!=`number`||!Number.isFinite(e))return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toLocaleString(Ye(),{month:`short`})} ${t.getDate()}, ${t.getFullYear()}, ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function uy(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 dy(e){let t=e.info.role===`user`?`User`:`Assistant`,n=ly(e.info.time?.created),r=uy(e),i=n&&r?`${n} (${r})`:n||r;return i?`**${t}**\n\n*${i}*`:`**${t}**`}function fy(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(``)}function py(e){let t=dy(e),n=fy(e.parts).trim();return n?`${t}\n\n${n}`:``}function my(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(py).filter(Boolean).join(`
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
`)];for(let n of e.children)i.push(my(n,t+1));return i.join(`
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
`)}function hy(e,t,n){let r=`# ${t?.trim()||`Session`}\n\n*Exported on ${new Date().toISOString().split(`T`)[0]}*\n\n---\n\n`+e.map(py).filter(Boolean).join(`
|
|
155
|
-
|
|
156
|
-
---
|
|
157
|
-
|
|
158
|
-
`);if(n&&n.length>0){let e=n.map(e=>my(e,1)).join(`
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
`);r+=`
|
|
163
|
-
|
|
164
|
-
---
|
|
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 _y(e,t){let n=await I(t,e);if(n)return n;if(!m())return null;try{let n=await U()?.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 vy(e){let t=U()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await j(e)?!0:M(e)}function yy(){return Hn()}function by(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},Sy=oe()((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}))}})),Cy=!1,wy=new Set,Ty=!1;function Ey(){for(let e of wy)e()}function Dy(e){Cy!==e&&(Cy=e,Ey())}function Oy(e){e.key===`Shift`&&Dy(!0)}function ky(e){e.key===`Shift`&&Dy(!1)}function Ay(){Dy(!1)}function jy(){Ty||typeof window>`u`||(Ty=!0,window.addEventListener(`keydown`,Oy),window.addEventListener(`keyup`,ky),window.addEventListener(`blur`,Ay))}function My(e){return jy(),wy.add(e),()=>{wy.delete(e)}}function Ny(){return Cy}function Py(){return!1}function Fy(){return(0,Q.useSyncExternalStore)(My,Ny,Py)}var Iy=!1,Ly=!1,Ry=new Set;function zy(){Ry.forEach(e=>e())}function By(e){Iy!==e&&(Iy=e,zy())}function Vy(e){return Jn()?e.key===`Meta`:e.key===`Control`}var Hy=(({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:By});function Uy(e){Vy(e)&&Hy.press()}function Wy(){Hy.release()}function Gy(e){Vy(e)&&Wy()}function Ky(){document.visibilityState!==`visible`&&Wy()}function qy(){Ly||typeof window>`u`||(Ly=!0,window.addEventListener(`keydown`,Uy),window.addEventListener(`keyup`,Gy),window.addEventListener(`blur`,Wy),document.addEventListener(`visibilitychange`,Ky))}function Jy(e){return qy(),Ry.add(e),()=>Ry.delete(e)}function Yy(){return Iy}function Xy(){return!1}function Zy(){return(0,Q.useSyncExternalStore)(Jy,Yy,Xy)}var Qy=(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} ---`},$y=(e,t)=>Pt.getState().getWorktreeMetadata(e)?.projectDirectory??t,eb=async e=>{let t=e.directory??void 0,n=gn(e.session.id,t);if(n.length===0&&e.directory){let t=(await Ee.withDirectory(e.directory,()=>Ee.getSdkClient().session.messages({sessionID:e.session.id,directory:e.directory??void 0,limit:50}))).data??[];for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.info?.role===`assistant`)return jn(n.parts??[]).trim()}return``}for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.role===`assistant`)return jn(rn(r.id,t)).trim()}return``};function tb({session:e,open:t,onOpenChange:n}){let{t:r}=qe(),i=et(),a=Rt(e=>e.activeSessions),o=Rt(e=>e.archivedSessions),s=Et(e=>e.providers),c=Et(e=>e.currentProviderId),l=Et(e=>e.currentModelId),u=Et(e=>e.currentAgentName),[d,f]=Q.useState(c??``),[p,m]=Q.useState(l??``),[h,g]=Q.useState(()=>c&&l?[{providerID:c,modelID:l,instanceId:Ac()}]:[]),[_,v]=Q.useState(``),[y,b]=Q.useState(u??``),[x,S]=Q.useState([]),[C,w]=Q.useState(!1),T=Q.useMemo(()=>Mc(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=Pt.getState().getDirectoryForSession(e.id),r=$y(e.id,n),i=E.map(e=>{let t=Mc(e.title);if(!t||t.groupSlug!==T.groupSlug||t.fusion||(t.runGroup??null)!==(T.runGroup??null))return null;let n=Pt.getState().getDirectoryForSession(e.id)??It(e),i=$y(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)(Vn,{open:t,onOpenChange:n,children:(0,$.jsxs)(Rn,{className:`max-w-xl overflow-visible`,children:[(0,$.jsxs)(In,{children:[(0,$.jsx)(zn,{children:r(`multirun.fusion.title`)}),(0,$.jsx)(Bn,{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)(Nc,{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)(Vi,{modelId:p,providerId:d,className:`h-3.5 w-3.5 mr-1`}):void 0})}),O.length>0?(0,$.jsxs)(Xi,{value:_||`__default__`,onValueChange:e=>v(e===`__default__`?``:e),children:[(0,$.jsxs)(Gi,{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)(X,{name:`brain-ai-3`,className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(ea,{children:e=>e===`__default__`?r(`multirun.modelMultiSelect.variant.default`):e})]}),(0,$.jsxs)(qi,{fitContent:!0,portalToBody:!0,children:[(0,$.jsx)(Ui,{value:`__default__`,children:r(`multirun.modelMultiSelect.variant.default`)}),O.map(e=>(0,$.jsx)(Ui,{value:e,children:e},e))]})]}):null,(0,$.jsx)(jc,{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=Mc(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)(Vi,{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)(X,{name:`close`,className:`h-4 w-4`})})]},e.session.id)})})]}),(0,$.jsxs)(Ln,{children:[(0,$.jsx)(Z,{variant:`ghost`,onClick:()=>n(!1),children:r(`multirun.fusion.actions.cancel`)}),(0,$.jsx)(Z,{onClick:async()=>{if(!(!T||!d||!p)){w(!0);try{let e=await Promise.all(x.map(e=>eb(e))),t=x.map((t,n)=>({source:t,text:e[n]??``})).filter(e=>e.text.trim().length>0);if(t.length===0){J.error(r(`multirun.fusion.toast.noOutputs`));return}let i=x[0]?.projectDirectory??x[0]?.directory??null,a=kc(T.groupSlug,d,p,T.runGroup),[o,s]=await Promise.all([yt(`session.fusion.visible`),yt(`session.fusion.instructions`)]),c=await Pt.getState().createSession(a,i,null);if(!c)throw Error(`Failed to create fusion session`);Pt.getState().setCurrentSession(c.id,i),n(!1),await Ee.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:Qy(e.source,e.text,t),synthetic:!0})),{text:`
|
|
167
|
-
|
|
168
|
-
--- FUSION INPUTS END ---
|
|
169
|
-
Now write the final fused answer.`,synthetic:!0}],directory:i??Ee.getDirectory()})}catch(e){console.error(`[MultiRunFusion] Failed to start fusion`,e),J.error(r(`multirun.fusion.toast.failed`))}finally{w(!1)}}},disabled:!k,children:r(C?`multirun.fusion.actions.starting`:`multirun.fusion.actions.start`)})]})]})})}function nb(e){let t=(0,zc.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=[`oc-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:Yn,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 rb=1/3,ib=1,ab=({containerScrollTop:e,containerClientHeight:t,containerScrollHeight:n,rowOffsetFromViewportTop:r})=>{let i=e+(r-t*rb),a=Math.max(0,n-t);return Math.min(a,Math.max(0,i))},ob=()=>typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,sb=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},cb=(e,t)=>{let n=sb(e),r=t?.behavior??ob();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=ab({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})},lb=e(be(),1),ub=null,db=!1,fb=(e,t=ri.getState().focus)=>e===null?null:typeof e==`string`?t?.sessionId===e?t:ei(e):e,pb=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))},mb=()=>{ub&&=(pb(ub),null)},hb=(e,t)=>{mb(),Ht(!0);let n=fb(e);if(!n)return;db=!0;let r;try{r=Qt(n.sessionId)}finally{db=!1}ub={commit:t,commitFrame:null,fallbackTimer:null,focus:n,intent:r,paintFrame:null,scheduled:!1},(0,lb.flushSync)(()=>{ri.getState().setFocus(n)}),typeof window<`u`&&(ub.fallbackTimer=window.setTimeout(()=>{gb(n)},150))},gb=e=>{let t=ub,n=fb(e);if(!t||!Li(t.focus,n)||t.scheduled)return;t.scheduled=!0,typeof window<`u`&&t.fallbackTimer!==null&&(window.clearTimeout(t.fallbackTimer),t.fallbackTimer=null);let r=()=>{ub===t&&bn()===t.intent&&(ub=null,tn(),t.commit())};if(typeof window>`u`){r();return}t.commitFrame=window.requestAnimationFrame(()=>{ub===t&&bn()===t.intent&&(t.paintFrame=window.requestAnimationFrame(r))})},_b=e=>{if(ub)return;let t=ri.getState();t.setFocus(fb(e,t.focus))};Lt(e=>{if(db)return;let t=ub;if(t?.intent===e)return;t&&mb();let n=ri.getState();n.setFocus(fb(e.sessionId,n.focus))});var vb=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,zc.c)(18),{pinLabel:n,buttonSizeClass:r,iconSizeClass:i,onPointerDown:a,onMouseDown:o,onPin:s}=e,c;t[0]===r?c=t[1]:(c=Y(`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`,r),t[0]=r,t[1]=c);let l;t[2]===i?l=t[3]:(l=Y(i,`rotate-45`),t[2]=i,t[3]=l);let u;t[4]===l?u=t[5]:(u=(0,$.jsx)(X,{name:`pushpin-2`,className:l}),t[4]=l,t[5]=u);let d;t[6]!==o||t[7]!==s||t[8]!==a||t[9]!==n||t[10]!==c||t[11]!==u?(d=(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:c,"aria-label":n,onPointerDown:a,onMouseDown:o,onClick:s,onKeyDown:Mb,children:u})}),t[6]=o,t[7]=s,t[8]=a,t[9]=n,t[10]=c,t[11]=u,t[12]=d):d=t[12];let f;t[13]===n?f=t[14]:(f=(0,$.jsx)(ra,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n}),t[13]=n,t[14]=f);let p;return t[15]!==d||t[16]!==f?(p=(0,$.jsxs)(aa,{children:[d,f]}),t[15]=d,t[16]=f,t[17]=p):p=t[17],p}),bb=Q.memo(function(e){let t=(0,zc.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=Fy(),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=Y(`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)(X,{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)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:y,"aria-label":h,onPointerDown:c,onMouseDown:l,onClick:_,onKeyDown:Nb,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)(ra,{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)(aa,{children:[S,C]}),t[21]=S,t[22]=C,t[23]=w):w=t[23],w}),xb=Q.memo(function(e){let t=(0,zc.c)(3),{number:n}=e;if(!Zy())return null;let r=Jn()?`⌘${n}`:`Ctrl+${n}`,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(ui,{"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 Sb(e){let{t:n}=qe(),{node:r,depth:i=0,groupDirectory:a,projectId:o,archivedBucket:s=!1,pinnedSessionIds:c,expandedParents:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,editingId:h,setEditingId:g,editTitle:_,setEditTitle:v,handleSaveEdit:y,handleCancelEdit:x,toggleParent:S,handleSessionSelect:C,handleSessionDoubleClick:w,togglePinnedSession:T,handleShareSession:E,copiedSessionId:D,handleCopyShareUrl:O,handleUnshareSession:k,setOpenSidebarMenuKey:A,renamingFolderId:j,getFoldersForScope:M,getSessionFolderId:N,removeSessionFromFolder:P,addSessionToFolder:F,createFolderAndStartRename:I,openContextPanelTab:L,handleDeleteSession:R,mobileVariant:z,alwaysShowActions:B,renderSessionNode:V,secondaryMeta:H,renderContext:te=`project`,subtreeContainsActive:U,subtreeContainsEditing:ne,menuOpenSessionId:W,childRenderExtrasFor:re,liveSessionById:G,shortcutNumber:ie=null}=e,ae=!!H?.projectLabel,oe=!!H?.branchLabel,se=Ev(e=>e.displayMode),ce=Q.useMemo(()=>m(),[]),ve=se===`minimal`||ce,ye=Q.useMemo(()=>b(),[]),be=Q.useContext(Ba),xe=ce?`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`,Se=ce,Ce=te===`pinned`&&c.has(r.session.id),we=!Ce&&!s&&!z,Te=`h-5 w-5`,Ee=`h-3.5 w-3.5`,De=(we||Ce?1:0)+ +!!Se+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`,ke=De>=2?`pr-12`:`pr-8`,Ae=Q.useRef(!1),je=Q.useRef(!1),[K,Me]=Q.useState(!1),Ne=Q.useRef(h);Ne.current=h;let Pe=Q.useRef(null),q=Q.useRef(y);q.current=y;let[Fe,Ie]=Q.useState(_),[Le,Re]=Q.useState(null),ze=Q.useRef(Fe);ze.current=Fe;let Be=Q.useRef(null),Ve=Q.useRef(null),We=Q.useRef(null),Ge=r.session,Ke=G.get(Ge.id)??Ge,Je=!!Ke.metadata?.openchamber?.assistant,Ye=p(Ge.directory??null)??p(a??null),Xe=St(Ye??void 0,{bootstrap:!1}),Ze=Kr(),Qe=Sy(e=>e.enabled),$e=Sy(Q.useMemo(()=>e=>e.selectedIds.has(Ge.id),[Ge.id])),et=Sy(e=>e.toggleSelected),tt=Sy(e=>e.setRange),[nt,rt]=Q.useState(!1),[it,at]=Q.useState(!0),[st,ct]=Q.useState(!1),lt=`${te}:${s?`archived`:`active`}:${Ge.id}`,ut=En(Q.useMemo(()=>e=>!!e.sessionMemoryState.get(ht(Ge.id))?.isZombie,[Ge.id])),dt=ot(Ge.id),pt=mn(Ge.id,Ye??void 0,{bootstrap:!1}),mt=Ft(Ge.id,Ye??void 0,{bootstrap:!1}),gt=Q.useMemo(()=>({scope:te,sessionId:Ge.id,projectId:o??null}),[o,te,Ge.id]),_t=Q.useMemo(()=>Mi(gt)??``,[gt]),vt=Q.useRef(null),yt=ri(Q.useMemo(()=>e=>Li(e.focus,gt),[gt]));Q.useLayoutEffect(()=>{if(!yt)return;let e=vt.current;e&&(z?e.scrollIntoView({block:`nearest`,inline:`nearest`}):cb(e)),gb(gt)},[yt,z,gt]);let bt=Ke.title||n(`sessions.sidebar.session.untitled`),xt=zo(Lo(Ke)),Ct=Ke.metadata?.openchamber?.titleRefresh,Tt=typeof Ct?.lastError==`string`?Ct.lastError:null,Et=typeof Ct?.failedAt==`number`?Ct.failedAt:null;Q.useEffect(()=>{!Tt||Et===null||(Re(null),console.warn(`[session-title] generation failed for ${Ge.id}: ${Tt}`))},[Ge.id,Tt,Et]),Q.useEffect(()=>{if(Le===null)return;if(bt!==Le){Re(null);return}let e=window.setTimeout(()=>Re(null),3e4);return()=>window.clearTimeout(e)},[Le,bt]);let Dt=r.children.length>0||!!Ke.hasChildren,kt=c.has(Ge.id),At=lt,jt=u?!0:l.has(At),Nt=!!Ke.parentID,Pt=te===`pinned`,It=Yt(Ge.id)>0&&!Nt,Lt=wt(Ke)||Date.now(),Rt=gr(Lt),zt=gi(Lt),[Bt,Vt]=Q.useState(!1),Ht=Bt,Wt=Q.useMemo(()=>Mc(Ke.title)!==null,[Ke.title]),[Gt,Kt]=Q.useState(!1),qt=Q.useMemo(()=>vb(r).length,[r]),Jt=He(e=>{let t=Ye??``,n=(Ut()??Ot(t,Xe)).getTranscript(Mt(t,e)),r=Xe.getState().session.find(t=>t.id===e)?.revert?.messageID;return ft({sessionID:e,messages:sn(n),parts:n.partsByMessageID,revertMessageID:r}).list}),Xt=He(async e=>{let t=[],r=0;for(let i of e)try{await Ze.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 Xt(i.children);r+=s.skipped,t.push({title:a,agent:o,records:e,children:s.children})}catch{r+=vb(i).length+1}return{children:t,skipped:r}}),Zt=He(e=>{e<=0||J.warning(n(e===1?`sessions.sidebar.session.export.skippedSubtaskSingle`:`sessions.sidebar.session.export.skippedSubtaskMany`,{count:e}))}),Qt=He(async e=>{if(!Ye){J.error(n(`sessions.sidebar.session.export.nothingToExport`));return}await Ze.ensureSessionRenderable(Ge.id);let t=Jt(Ge.id);if(t.length===0){J.error(n(`sessions.sidebar.session.export.nothingToExport`));return}let i,a=0;if(e&&r.children.length>0){let e=await Xt(r.children);i=e.children,a=e.skipped}let o=hy(t,Ke.title??null,i),s=by(Ke.title??null),c=await _y(o,s);if(c){J.success(n(`sessions.sidebar.session.export.success`),{action:{label:n(yy()),onClick:()=>{vy(c).then(e=>{e||J.error(n(`sessions.sidebar.session.export.failedRevealPath`))})}}}),Zt(a);return}gy(o,s),J.success(n(`sessions.sidebar.session.export.success`)),Zt(a)}),$t=He(async()=>{if(r.children.length>0){at(!0),rt(!0);return}await Qt(!1)}),en=He(()=>{Ye&&ee(`desktop_open_session_mini_chat_window`,{sessionId:Ge.id,directory:Ye,apiBaseUrl:d(),clientToken:t()}).catch(e=>{console.warn(`[session-sidebar] failed to open mini chat window`,e)})});Ue(Ve,()=>{q.current(ze.current)},h===Ge.id),Q.useLayoutEffect(()=>{if(h!==Ge.id){Be.current===Ge.id&&(Be.current=null);return}Be.current!==Ge.id&&(Be.current=Ge.id,Ie(_),queueMicrotask(()=>We.current?.select()))},[h,_,Ge.id]);let tn=He(e=>{if(!e&&Pe.current){let{id:e,title:t}=Pe.current;Pe.current=null,g(e),v(t)}}),nn=He(e=>{Vt(e)}),rn=He(e=>{e.preventDefault(),e.stopPropagation()}),an=He(e=>{e.preventDefault(),e.stopPropagation()}),on=He(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ge.id)}),cn=He(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ge,{archivedBucket:s})}),ln=He(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ge,{archivedBucket:s,hardDelete:!0,skipConfirm:!0})}),un=He(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ge.id)}),dn=He(()=>{let e=dt?.type??`idle`;!Ye||st||e===`busy`||e===`retry`||(ct(!0),(async()=>{try{await Ze.refreshSessionTranscript(Ge.id,{directory:Ye}),J.success(n(`sessions.sidebar.session.menu.refreshTranscriptSuccess`))}catch{J.error(n(`sessions.sidebar.session.menu.refreshTranscriptFailed`))}finally{ct(!1)}})())}),fn=He(e=>{e.preventDefault(),e.stopPropagation()}),pn=He(e=>{e.preventDefault(),e.stopPropagation()}),hn=He(e=>{e.preventDefault(),e.stopPropagation(),be?.vscode?.executeCommand(`openchamber.openSessionInEditor`,Ge.id,bt)}),gn=He(e=>{if(Ae.current){Ae.current=!1;return}if(Qe){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=Sy.getState().anchorId,n=new Map;n.set(Ge.id,vb(r)),tt(t,Ge.id,e,Ye??null,n);return}et(Ge.id,Ye??null,vb(r));return}C(Ge.id,Ye,o,te)}),_n=He(e=>{e.defaultPrevented||e.target?.closest(`button, a, input, [role="menuitem"], [role="menu"]`)||gn(e)}),vn=He(e=>{(e.button===2||e.button===0&&e.ctrlKey&&!Qe)&&(Ae.current=!0)}),yn=He(e=>{je.current=e.pointerType===`mouse`,z&&e.pointerType===`touch`&&Me(!0)}),bn=He(e=>{z&&e.pointerType===`touch`&&Me(!1)}),xn=He(e=>{e.key!==`Enter`||!je.current||(e.preventDefault(),e.stopPropagation(),w(Ge.id,bt))}),Sn=He(e=>{if(gn(e),!je.current)return;let t=e.currentTarget;window.requestAnimationFrame(()=>{je.current=!0,t.focus({preventScroll:!0})})}),Cn=He(()=>{je.current=!1}),wn=He(e=>{if(!je.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(),je.current=!1)});if(h===Ge.id){let e=async()=>{Re(bt),x();try{await Mn(Ge.id)}catch(e){Re(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:Ir(i)},children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0`,children:[(0,$.jsxs)(`form`,{ref:Ve,className:`flex w-full items-center gap-2`,onSubmit:e=>{e.preventDefault(),y(Fe)},children:[(0,$.jsx)(`input`,{ref:We,value:Fe,onChange:e=>Ie(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`){x();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)(X,{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)(X,{name:`check`,className:`size-3.5`})})]}),ve?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:[Dt&&!Pt&&!Nt?(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center flex-shrink-0`,children:jt?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,(0,$.jsx)(`span`,{className:`flex-shrink-0`,children:Rt}),ae?(0,$.jsx)(`span`,{className:`truncate`,children:H?.projectLabel}):null,oe?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:H?.branchLabel})]}):null]})})]})},Ge.id)}let Tn=dt?.type??`idle`,Dn=Tn===`busy`||Tn===`retry`,On=Le!==null||Ct?.isGenerating===!0,kn=pt.length,An=mt.length>0,jn=An||Dn||!An&&!Dn&&It&&!yt,Nn=!B||ce,Pn=An?(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)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`})}):Dn?(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)(Zs,{})}):(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)]`})}),Fn=!Pt&&!B&&Dt&&kt,Hn=!Pt&&kt,Un=(0,$.jsx)(X,{name:`pushpin-2-fill`,className:`h-3 w-3 flex-shrink-0 text-foreground`,"aria-label":n(`sessions.sidebar.session.status.pinned`)}),Wn=Hn?(0,$.jsx)(`span`,{className:Y(`pointer-events-none absolute inline-flex h-3.5 w-3.5 items-center justify-center transition-opacity`,ve?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,Fn?`opacity-100 group-hover:opacity-0 group-focus-within:opacity-0`:``),style:{left:Ir(Math.max(0,i-1))},children:Un}):null,Gn=!Pt&&!Nt&&Dt,Kn=Gn&&!B,qn=Ir(Math.max(0,i-1)),Jn=()=>{!jt&&r.children.length===0&&Ze.loadChildren(Ge.id,Ye).catch(()=>void 0),S(At)},Yn=Gn?(0,$.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),e.currentTarget.blur(),Jn()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),Jn())},style:{minWidth:14,minHeight:14,left:qn},className:Y(`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`,ve?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,Kn?`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(jt?`sessions.sidebar.session.subsessions.collapse`:`sessions.sidebar.session.subsessions.expand`),children:jt?(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-3 w-3`}):(0,$.jsx)(X,{name:`arrow-right-s`,className:`h-3 w-3`})}):null,Xn=ut?(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4 text-status-warning`}):null,Zn=(0,$.jsx)(me,{children:(0,$.jsx)(fe,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ue,{"data-slot":`dropdown-menu-content`,finalFocus:()=>!(j||Ne.current),style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(io,`min-w-[180px]`),children:(({Item:e,Separator:t,Sub:r,SubTrigger:i,SubContent:a})=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(e,{onClick:()=>{Pe.current={id:Ge.id,title:bt}},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`pencil-ai`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.rename`)]}),(0,$.jsxs)(e,{onClick:()=>T(Ge.id),className:`[&>svg]:mr-1`,children:[kt?(0,$.jsx)(X,{name:`unpin`,className:`mr-1 h-4 w-4`}):(0,$.jsx)(X,{name:`pushpin`,className:`mr-1 h-4 w-4`}),n(kt?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`)]}),Ke.share?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onClick:()=>{Ke.share?.url&&O(Ke.share.url,Ge.id)},className:`[&>svg]:mr-1`,children:D===Ge.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{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)(X,{name:`file-copy`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.copyLink`)]})}),(0,$.jsxs)(e,{onClick:()=>k(Ge.id),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`link-unlink-m`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.unshare`)]})]}):(0,$.jsxs)(e,{onClick:()=>E(Ke),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`share-2`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.share`)]}),(0,$.jsxs)(e,{onClick:()=>{$t()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`download`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.exportMarkdown`)]}),(0,$.jsxs)(e,{disabled:!Ye||Dn||st,onClick:()=>{dn()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`mr-1 h-4 w-4`,st&&`animate-spin`)}),n(`sessions.sidebar.session.menu.refreshTranscript`)]}),Wt?(0,$.jsxs)(e,{onClick:()=>Kt(!0),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(nb,{className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.session.menu.runFusion`)]}):null,Ye&&!s?(()=>{let o=M(Ye),s=N(Ye,Ge.id);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(t,{}),(0,$.jsxs)(r,{children:[(0,$.jsxs)(i,{className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{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?P(Ye,Ge.id):F(Ye,t.id,Ge.id)},children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),s===t.id?(0,$.jsx)(X,{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=I(Ye);e&&F(Ye,e.id,Ge.id)},children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.newFolderEllipsis`)]}),s?(0,$.jsxs)(e,{onClick:()=>{P(Ye,Ge.id)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(X,{name:`close`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]})]})})():null,ce?null:(0,$.jsxs)(e,{disabled:!Ye,onClick:()=>{Ye&&L(Ye,{mode:`chat`,dedupeKey:`session:${Ge.id}`,label:bt,sessionTitleFallback:bt})},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{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`)})]}),ye?(0,$.jsxs)(e,{disabled:!Ye,onClick:en,className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{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(Ge,{archivedBucket:s}),children:[(0,$.jsx)(X,{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(Ge,{archivedBucket:s,hardDelete:!0}),children:[(0,$.jsx)(X,{name:`delete-bin`,className:`mr-1 h-4 w-4`}),n(`sessions.sidebar.bulkActions.delete`)]})]}))({Item:({className:e,...t})=>(0,$.jsx)(de,{className:Y(oo,e),...t}),Separator:({className:e,...t})=>(0,$.jsx)(le,{className:Y(ao,e),...t}),Sub:pe,SubTrigger:({className:e,children:t,...n})=>(0,$.jsxs)(he,{className:Y(ro,e),...n,children:[t,(0,$.jsx)(X,{name:`arrow-right-s`,className:`ml-auto size-3.5`})]}),SubContent:({className:e,children:t,...n})=>(0,$.jsx)(me,{children:(0,$.jsx)(fe,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ue,{"data-slot":`dropdown-menu-sub-content`,style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(io,e),...n,children:t})})})})})})});return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(gv,{sessionId:Ge.id,sessionDirectory:Ye??null,sessionTitle:bt,children:(0,$.jsxs)(ge,{open:Bt,onOpenChange:nn,onOpenChangeComplete:tn,children:[(0,$.jsxs)(_e,{render:(0,$.jsx)(`div`,{ref:vt,"data-session-row":Ge.id,"data-session-scope":Ye??``,"data-session-focus-scope":te,"data-session-focus-key":_t,"data-session-project-id":o??``,"data-session-archived":s?`1`:`0`,"data-session-depth":i,onClick:_n,onMouseLeave:wn,className:Y(`group relative my-0.5 flex cursor-pointer items-center rounded-lg py-1.5 pr-2`,yt&&!$e&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,$e&&`bg-[color-mix(in_srgb,var(--surface-foreground)_6%,transparent)] dark:bg-[color-mix(in_srgb,var(--surface-foreground)_11%,transparent)]`,!yt&&!$e&&`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:[Wn,Yn,(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,style:{paddingLeft:Ir(i)},children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onPointerDown:yn,onPointerUp:bn,onPointerCancel:bn,onMouseDown:vn,onKeyDown:xn,onBlur:Cn,onClick:Sn,onDoubleClick:e=>{e.stopPropagation(),w(Ge.id,bt)},className:Y(`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?ce?Oe:ke: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:Y(`block min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground`,On&&`animate-text-shimmer`),"aria-busy":On||void 0,children:Ar(bt,f)}),xt?(0,$.jsx)(`span`,{className:`shrink-0 typography-micro tabular-nums text-muted-foreground`,children:xt}):null,Je?(0,$.jsx)(X,{name:`ai-agent`,className:`size-3 shrink-0 text-muted-foreground`,"aria-label":`Assistant`}):null,kn>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)(X,{name:`shield`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`leading-none`,children:kn})]}):null,jn?(0,$.jsx)(`span`,{className:Y(`inline-flex shrink-0 items-center justify-center transition-none`,Nn?Y(`group-hover:hidden group-focus-within:hidden`,Ht?`hidden`:``):Ht?`invisible`:``),children:Pn}):null,ie?(0,$.jsx)(xb,{number:ie}):null]})})}),ce?null:(0,$.jsx)(ra,{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:bt}),(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:zt})]}),ae?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`folder-open`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:H?.projectLabel})]}):null,oe?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:H?.branchLabel})]}):null]})})]})})}),Xn&&!z?(0,$.jsx)(`div`,{className:Y(`absolute top-1/2 -translate-y-1/2 z-10`,ve?`right-0`:`right-[30px]`),children:Xn}):null,(0,$.jsxs)(`div`,{className:Y(`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&&!ce?`opacity-100`:Y(`opacity-0`,xe)),children:[we?(0,$.jsx)(yb,{pinLabel:n(`sessions.sidebar.session.menu.pin`),buttonSizeClass:Te,iconSizeClass:Ee,onPointerDown:rn,onMouseDown:an,onPin:on}):null,Ce?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`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.pinned`),onPointerDown:rn,onMouseDown:an,onClick:un,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`pushpin-2-fill`,className:Ee})})}),(0,$.jsx)(ra,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:n(`sessions.sidebar.session.actions.pinned`)})]}):null,Se?(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:Y(`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:fn,onMouseDown:pn,onClick:hn,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:Ee})})}),(0,$.jsx)(ra,{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)(bb,{archiveLabel:n(`sessions.sidebar.bulkActions.archive`),deleteLabel:n(`sessions.sidebar.bulkActions.delete`),deleteOnly:s===!0,buttonSizeClass:Te,iconSizeClass:Ee,revealClassName:ve&&!B&&!Ht?Y(`opacity-0`,xe):`opacity-100`,onPointerDown:rn,onMouseDown:an,onArchive:cn,onDelete:ln})]})]}),Zn]})}),!Pt&&Dt&&jt?r.children.map(e=>{let t=re?re(e):{subtreeContainsActive:U,subtreeContainsEditing:ne,menuOpenSessionId:W,nodeStructureKey:``};return V(e,i+1,Ye??a,o,s,void 0,te,t)}):null,(0,$.jsx)(Vn,{open:nt,onOpenChange:rt,children:(0,$.jsxs)(Rn,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[(0,$.jsxs)(In,{children:[(0,$.jsx)(zn,{children:n(`sessions.sidebar.session.export.dialog.title`)}),(0,$.jsx)(Bn,{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:it,onChange:e=>at(e.target.checked),className:`h-4 w-4 rounded border-border accent-primary`}),n(`sessions.sidebar.session.export.dialog.includeSubtasks`)]}),(0,$.jsxs)(Ln,{children:[(0,$.jsx)(Z,{type:`button`,onClick:()=>rt(!1),variant:`outline`,size:`sm`,children:n(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{type:`button`,onClick:()=>{rt(!1),Qt(it)},size:`sm`,children:n(`sessions.sidebar.session.export.dialog.confirm`)})]})]})}),Wt?(0,$.jsx)(tb,{session:Ke,open:Gt,onOpenChange:Kt}):null]},Ge.id)}var Cb=e=>p(e.session.directory??null),wb=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null),Tb=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},Eb=e=>e.menuOpenSessionId??Tb(e),Db=(e,t,n)=>t?n.has(e.node.session.id)?!0:Cv(e.node,t):!1,Ob=(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(Ob(e.children[a],t.children[a],n,r,i))return!0;return!1},kb=(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&&xv(a)!==xv(o)||e.children.length!==t.children.length)return!0;for(let i=0;i<e.children.length;i+=1)if(kb(e.children[i],t.children[i],n,r))return!0;return!1},Ab=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;let n=e.archivedBucket?`archived`:`active`,r=t.archivedBucket?`archived`:`active`;return Ob(e.node,t.node,e.expandedParents,t.expandedParents,t=>`${e.renderContext??`project`}:${n}:${t.session.id}`)||Ob(e.node,t.node,e.expandedParents,t.expandedParents,e=>`${t.renderContext??`project`}:${r}:${e.session.id}`)},jb=Q.memo(Sb,(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||Cb(e.node)!==Cb(t.node)||!wb(e.secondaryMeta,t.secondaryMeta)||e.liveSessionById!==t.liveSessionById&&kb(e.node,t.node,e.liveSessionById,t.liveSessionById)||e.pinnedSessionIds!==t.pinnedSessionIds&&Ob(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e=>e.session.id)||e.expandedParents!==t.expandedParents&&Ab(e,t)||e.currentSessionId!==t.currentSessionId&&(Db(e,e.currentSessionId,e.subtreeContainsActive)||Db(t,t.currentSessionId,t.subtreeContainsActive))||e.editingId!==t.editingId&&(Db(e,e.editingId,e.subtreeContainsEditing)||Db(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(Db(e,e.editingId,e.subtreeContainsEditing)||Db(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(Cv(e.node,e.copiedSessionId)||Cv(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Eb(e),r=Eb(t);if(Cv(e.node,n)||Cv(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){let n=Eb(e),r=Eb(t);if(Cv(e.node,n)||Cv(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 Mb(e){return e.stopPropagation()}function Nb(e){return e.stopPropagation()}function Pb(e){let t=(0,zc.c)(71),{t:n}=qe(),{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=Vn,g=!!r,t[13]===i?_=t[14]:(_=e=>{e||i(null)},t[13]=i,t[14]=_),u=Rn,m=!1,h=`max-w-sm gap-5`,l=In;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)(zn,{children:a}),t[18]=a,t[19]=p),c=Bn,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)(X,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(X,{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)(Ln,{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 Fb(e){let t=(0,zc.c)(57),{t:n}=qe(),{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)(zn,{children:d}),t[10]=d,t[11]=g);let _;t[12]===p?_=t[13]:(_=(0,$.jsx)(Bn,{children:p}),t[12]=p,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,$.jsxs)(In,{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)(X,{name:`checkbox-blank`,className:`h-4 w-4`}):(0,$.jsx)(X,{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)(Ln,{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)(Rn,{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)(Vn,{open:m,onOpenChange:h,children:M}),t[53]=m,t[54]=M,t[55]=h,t[56]=N):N=t[56],N}function Ib(e){let t=(0,zc.c)(36),{t:n}=qe(),{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)(zn,{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)(Bn,{children:u}),t[9]=u,t[10]=d);let f;t[11]!==l||t[12]!==d?(f=(0,$.jsxs)(In,{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)(Ln,{children:[h,_]}),t[26]=_,t[27]=h,t[28]=v):v=t[28];let y;t[29]!==v||t[30]!==f?(y=(0,$.jsxs)(Rn,{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)(Vn,{open:o,onOpenChange:s,children:y}),t[32]=o,t[33]=s,t[34]=y,t[35]=b):b=t[35],b}var Lb=e=>{let t=(0,zc.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}=qe(),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)(ha,{children:[(0,$.jsxs)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(_a,{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)(X,{name:`folder`,className:`h-4 w-4`})})})}),(0,$.jsx)(ra,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f(`sessions.sidebar.bulkActions.moveToFolder`)})})]}),(0,$.jsxs)(ca,{align:`end`,className:`min-w-[180px]`,children:[i.length===0?(0,$.jsx)(ua,{disabled:!0,className:`text-muted-foreground`,children:f(`sessions.sidebar.folders.none`)}):i.map(e=>(0,$.jsx)(ua,{onClick:()=>o(e.id),children:(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})},e.id)),(0,$.jsx)(oa,{}),(0,$.jsxs)(ua,{onClick:s,children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.newFolderEllipsis`)]}),l?(0,$.jsxs)(ua,{onClick:c,className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(X,{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=Y(`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)(X,{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)(na,{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)(ra,{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)(aa,{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)(X,{name:`close`,className:`h-4 w-4`}),t[28]=T):T=t[28];let E;t[29]!==d||t[30]!==w?(E=(0,$.jsx)(na,{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)(ra,{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)(aa,{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},Rb=e=>{let{t}=qe(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,addSessionsToFolder:a,removeSessionsFromFolders:o,createFolderAndStartRename:s,archiveSessions:c,setBulkDeleteConfirm:l}=e,u=Sy(e=>e.enabled),d=Sy(e=>e.selectedIds.size),f=d>0,p=Sy(e=>e.selectedIds),m=Sy(e=>e.scopeKey),h=Q.useCallback(()=>{Sy.getState().toggleMode()},[]),g=Q.useCallback(()=>{Sy.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&&ws({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.openchamber.archivedSessions.actions.view`),undoFailedMessage:n.length===1?t(`sessions.sidebar.session.archive.undoFailed`):t(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:n.length})}),r.length>0&&J.error(r.length===1?t(`sessions.sidebar.bulkActions.failedArchiveSingle`,{count:r.length}):t(`sessions.sidebar.bulkActions.failedArchivePlural`,{count:r.length}))}Sy.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(),Sy.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=Sy.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;Sy.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}},zb=(e,t,n)=>{let r=[],i=new Set,a=e=>{let t=p(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},Bb=(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},Vb=({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=Bb(r,e,o,i)??{scope:`project`,sessionId:e,projectId:i};return!a||t.scope===`project`?s:Bb(n,e,o,i)??s};function Hb(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 Ub=`oc.sessions.projectCollapse`,Wb=`oc.sessions.groupOrder`,Gb=`oc.sessions.groupCollapse`,Kb=`oc.sessions.activeSessionByProject`,qb=`oc.sessions.expandedParents.v2`,Jb=`oc.sessions.expandedParents`,Yb=h(Ae()),Xb=e=>{try{let t=Yb.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}},Zb=e=>{try{let t=Yb.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}},Qb=e=>{try{let t=Yb.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}},$b=(e,t,n)=>{let r=new Set;for(let t of e){let e=p(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=p(t.path)?.toLowerCase();e&&r.add(e)}return r},ex=(e,t,n)=>{if(e.time?.archived)return!0;let r=p(It(e))?.toLowerCase();return r?t.size===0?n?.allowEmptyDirectorySet??!0:t.has(r):n?.allowUnknownDirectory??!0},tx=3e5,nx=new Set,rx=[],ix={},ax=e=>{let t=Q.useRef(e);return t.current=e,Q.useCallback((...e)=>t.current(...e),[])},ox=({mobileVariant:e=!1,onSessionSelected:t,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1,isVisible:a=!0})=>{let{t:s}=qe(),[c,l]=Q.useState(!1),[d,f]=Q.useState(!1),[h,g]=Q.useState(``),_=Q.useRef(null),v=Q.useRef(null),y=Q.useRef(new Set),[b,x]=Q.useState(null),[S,C]=Q.useState(``),[w,T]=Q.useState(null),[D,O]=Q.useState(new Set),k=Q.useMemo(()=>Yb,[]),[A,j]=Q.useState(new Set),[M,N]=Q.useState(new Map),[P,F]=Q.useState(new Map),I=K(e=>e.isNewWorktreeDialogOpen),ee=K(e=>e.setNewWorktreeDialogOpen),[L,R]=Q.useState(null),[z,B]=Q.useState(null),[V,H]=Q.useState(``),[te,U]=Q.useState(null),[ne,W]=Q.useState(null),[re,G]=Q.useState(null),ie=Wt(),ae=fn(),[oe,se]=Q.useState(()=>Xb(Gb)),[le,ue]=Q.useState(()=>Qb(Wb)),[de,fe]=Q.useState(()=>Zb(Kb));Q.useEffect(()=>o(e=>{u(e)&&(se(Xb(Gb)),ue(Qb(Wb)),fe(Zb(Kb)),j(Xb(Ub)),O(Xb(qb)))}),[]);let[pe,me]=Q.useState(new Map),he=Q.useRef(new Map),ge=Q.useRef(0),_e=xe(e=>e.homeDirectory),ve=xe(e=>e.currentDirectory),ye=xe(e=>e.setDirectory),be=qt(e=>e.projects),Se=qt(e=>e.activeProjectId),Ce=qt(e=>e.removeProject),we=qt(e=>e.setActiveProjectIdOnly),Te=qt(e=>e.updateProjectMeta),Ee=qt(e=>e.reorderProjectsById),De=K(e=>e.setActiveMainTab),Oe=K(e=>e.activeMainTab),ke=Pn(),Ae=K(e=>e.openContextPanelTab),je=K(e=>e.setSettingsDialogOpen),Me=K(e=>e.toggleHelpDialog),Ne=K(e=>e.setSessionSwitcherOpen),Pe=K(e=>e.setScheduledTasksDialogOpen),q=K(e=>e.notifyOnSubtasks),Fe=K(e=>e.showDeletionDialog),Ie=K(e=>e.setShowDeletionDialog),Le=Va(h,120),Re=Q.useMemo(()=>Le.trim().toLowerCase(),[Le]),ze=Re.length>0,Be=qo(ce(e=>({checkForUpdates:e.checkForUpdates,available:e.available,runtimeType:e.runtimeType,info:e.info,downloading:e.downloading,downloaded:e.downloaded,progress:e.progress,error:e.error,downloadUpdate:e.downloadUpdate,restartToUpdate:e.restartToUpdate}))),Ve=yn(e=>e.collapsedFolderIds),He=yn(e=>e.foldersMap),Ue=yn(e=>e.sessionOrderByScope),We=yn(e=>e.sessionOrderActivityByScope),Ge=yn(e=>e.getFoldersForScope),Ke=yn(e=>e.createFolder),Je=yn(e=>e.renameFolder),Ye=yn(e=>e.deleteFolder),Xe=yn(e=>e.addSessionToFolder),Ze=yn(e=>e.addSessionsToFolder),$e=yn(e=>e.removeSessionFromFolder),tt=yn(e=>e.removeSessionsFromFolders),nt=yn(e=>e.toggleFolderCollapse),rt=yn(e=>e.cleanupSessions),it=yn(e=>e.getSessionFolderId),at=yn(e=>e.reorderSessions);a_({isSessionSearchOpen:a&&d,setIsSessionSearchOpen:f,sessionSearchInputRef:v,sessionSearchContainerRef:_});let ot=Q.useMemo(()=>new Map,[]),st=et({enabled:a}),ct=Ls({enabled:a}),ut=Ds({enabled:a}),dt=Qe(e=>a?e.index.session.unseenCount:ix),ft=Q.useMemo(()=>m(),[]),pt=Rt(e=>e.fullCatalogSessionIds),mt=Rt(e=>e.fullCatalogGeneration),ht=Rt(e=>e.status),gt=Rt(e=>e.activeSessions),_t=Rt(e=>e.archivedSessions),vt=Rt(e=>e.loadingDirectories),yt=Rt(e=>e.refreshingDirectories),bt=Rt(e=>e.archivedLoadingDirectories),xt=Q.useDeferredValue(gt),St=Q.useDeferredValue(_t),wt=Pt(e=>e.currentSessionId),Tt=ri(e=>e.focus),Et=Q.useSyncExternalStore(Lt,bn,bn),Dt=Pt(e=>!!e.newSessionDraft?.open),Ot=Pt(e=>e.setCurrentSession),kt=Pt(e=>e.updateSessionTitle),At=Pt(e=>e.shareSession),Mt=Pt(e=>e.unshareSession),Nt=Pt(e=>e.worktreeMetadata),Ft=Pt(e=>e.availableWorktreesByProject),zt=Pt(e=>e.openNewSessionDraft),Bt=Q.useCallback(e=>{zt(e),ft&&window.dispatchEvent(new CustomEvent(`openchamber:navigate`,{detail:{view:`chat`}}))},[ft,zt]),Vt=Q.useMemo(()=>$b(be,Ft,{includeWorktrees:!ft}),[Ft,ft,be]),Ht=Q.useMemo(()=>{let e=new Map(st.map(e=>[e.id,e])),t=xt.map(t=>{let n=e.get(t.id);return n?jt(n,t):t}),n=new Set(t.map(e=>e.id));return st.forEach(e=>{n.has(e.id)||t.push(e)}),t.filter(e=>ex(e,Vt,{allowUnknownDirectory:!ft,allowEmptyDirectorySet:!ft}))},[xt,ft,Vt,st]),Ut=Q.useMemo(()=>st.map(e=>{let t=p(e.directory??null)??``;return`${e.id}:${e.title??``}:${+!!e.time?.archived}:${t}`}).join(`|`),[st]),Gt=Q.useRef(st);Q.useEffect(()=>{Gt.current=st},[Ut,st]);let Kt=Q.useMemo(()=>new Map(st.map(e=>[e.id,e])),[st]);Q.useEffect(()=>{let e=null,t=lt(t=>{t.type===`scheduled-task-ran`&&(e&&clearTimeout(e),e=setTimeout(()=>{let e=qt.getState().projects.find(e=>e.id===t.projectId),n=p(e?.path??null);if(!n)return;let r=[n];(Pt.getState().availableWorktreesByProject.get(n)??[]).forEach(e=>{let t=p(e.path);t&&r.push(t)}),hn(r,Gt.current)},500))});return()=>{e&&clearTimeout(e),t()}},[]);let Yt=Q.useMemo(()=>E(),[]),Xt=as(e=>e.sidebarBrandName.trim().length>0),{isTablet:Zt}=Fa(),$t=e||Zt,{buildGroupSearchText:en,filterSessionNodesForSearch:tn,buildGroupedSessions:nn}=i_({homeDirectory:_e,worktreeMetadata:Nt,pinnedSessionIds:ie,gitBranches:ot,isVSCode:ft}),{scheduleCollapsedProjectsPersist:rn,hasRestoredProjectCollapse:an}=f_({isVSCode:ft,safeStorage:k,keys:{sessionExpanded:qb,sessionExpandedLegacy:Jb,projectCollapse:Ub,groupOrder:Wb,projectActiveSession:Kb,groupCollapse:Gb},groupOrderByProject:le,activeSessionByProject:de,collapsedGroups:oe,setExpandedParents:O,setCollapsedProjects:j}),on=Q.useMemo(()=>[...Ht].sort((e,t)=>xr(e,t,ie)),[Ht,ie]),sn=Q.useMemo(()=>{let e=new Map;return on.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)=>xr(e,t,ie))),e},[on,ie]),cn=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:s(`sessions.sidebar.empty.noSessions.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:s(`sessions.sidebar.empty.noSessions.description`)})]}),un=Q.useMemo(()=>be.find(e=>e.id===w)??null,[be,w]),dn=Q.useCallback(e=>{w&&Te(w,{label:e.label,icon:e.icon,color:e.color,iconBackground:e.iconBackground,defaultModel:e.defaultModel??null})},[w,Te]),pn=Q.useCallback(()=>{ee(!0)},[ee]),mn=Q.useCallback((t,n)=>{if(De(`chat`),e&&Ne(!1),n?.sessionId){Ot(n.sessionId,t);return}zt({directoryOverride:t,preserveDirectoryOverride:!0})},[e,zt,De,Ot,Ne]),gn=Q.useCallback(()=>{let e=qo.getState();if(e.available&&e.info){l(!0);return}Be.checkForUpdates().then(()=>{let{available:e,error:t}=qo.getState();if(t){J.error(s(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}if(!e){J.success(s(`sessions.sidebar.updateCheck.latestVersion`));return}l(!0)})},[s,Be]),_n=Q.useCallback(()=>{e&&Ne(!1),je(!0)},[e,Ne,je]),vn=Q.useCallback(()=>{De(`chat`),zt(),e&&Ne(!1)},[e,zt,De,Ne]),xn=Q.useCallback(()=>{if(!e){De(`schedule`);return}Pe(!0),Ne(!1)},[e,De,Pe,Ne]),Cn=Q.useCallback(()=>{Fn(),e&&Ne(!1)},[e,Ne]),wn=Be.available&&(Be.runtimeType===`desktop`||Be.runtimeType===`web`),Tn=Pt(e=>e.archiveSession),En=Pt(e=>e.archiveSessions),{copiedSessionId:Dn,handleSessionSelect:On,handleSessionDoubleClick:kn,handleSaveEdit:An,handleCancelEdit:jn,handleShareSession:Mn,handleCopyShareUrl:Nn,handleUnshareSession:In,handleDeleteSession:Ln,confirmDeleteSession:Rn}=o_({activeProjectId:Se,currentDirectory:ve,currentSessionId:wt,mobileVariant:e,allowReselect:n,onSessionSelected:t,isSessionSearchOpen:d,sessionSearchQuery:h,setSessionSearchQuery:g,setIsSessionSearchOpen:f,setActiveProjectIdOnly:we,setDirectory:ye,setActiveMainTab:De,setSessionSwitcherOpen:Ne,setCurrentSession:Ot,updateSessionTitle:kt,shareSession:At,unshareSession:Mt,archiveSession:Tn,archiveSessions:En,childrenMap:sn,showDeletionDialog:Fe,setDeleteSessionConfirm:U,deleteSessionConfirm:te,setEditingId:x,setEditTitle:C,editingId:b,editTitle:S}),zn=Q.useCallback((e,t,n,r=`project`)=>{let i={sessionId:e,scope:r,projectId:n??null};if(e===wt){Qt(e),_b(i),On(e,t,n);return}hb(i,()=>On(e,t,n))},[On,wt]);Q.useEffect(()=>()=>{mb()},[]);let Bn=Q.useCallback(()=>{if(!ne)return;let{scopeKey:e,folderId:t}=ne;W(null),Ye(e,t)},[ne,Ye]);Q.useEffect(()=>{if(!wt)return;let e=Ht.find(e=>e.id===wt)?.parentID;if(!e)return;let t=[`project:active:${e}`,`project:archived:${e}`,`recent:active:${e}`,`recent:archived:${e}`];O(e=>{if(t.every(t=>e.has(t)))return e;let n=new Set(e);t.forEach(e=>n.add(e));try{k.setItem(qb,JSON.stringify(Array.from(n)))}catch{}return n})},[wt,Ht,k]);let Vn=Q.useCallback(e=>{O(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{k.setItem(qb,JSON.stringify(Array.from(n)))}catch{}return n})},[k]),Hn=Q.useCallback((e,t)=>{if(!e)return null;t&&Ve.has(t)&&nt(t);let n=Ke(e,s(`sessions.sidebar.folder.newFolderName`),t);return B(n.id),H(n.name),n},[Ve,nt,Ke,s]),Un=ax(zn),Wn=ax(kn),Kn=ax(An),qn=ax(jn),Jn=ax(Mn),Yn=ax(Nn),Xn=ax(In),Zn=ax(Ln),Qn=ax(Hn),$n=Q.useCallback((e,t,n,r)=>{let i=Ns(),a=Math.max(i,n)+7;if(F(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=p(e.directory??null);if(!o)return;let s=Rt.getState().activePaginationByDirectory.get(o);s?.hasMore&&!s.loadingMore&&Jt(o)},[]),er=Q.useCallback(e=>{F(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),tr=Q.useCallback(e=>{F(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})},[]),nr=Q.useCallback(e=>{let t=be.find(t=>t.id===e),n=p(t?.path??null);if(!n)return[];let r=[n];return ft||(Ft.get(n)??[]).forEach(e=>{let t=p(e.path);t&&r.push(t)}),r},[Ft,ft,be]),rr=Q.useCallback(e=>{let t=nr(e);if(t.length===0)return;let n=Rt.getState().loadedDirectories,r=t.filter(e=>!n.has(e));r.length!==0&&hn(r,Gt.current)},[nr]),ir=Q.useCallback(e=>{let t=be.find(t=>t.id===e);t&&(async()=>{let e=[];if(!ft)try{e=(await $i({id:t.id,path:t.path})).worktrees}catch(n){console.warn(`[SessionSidebar] Worktree refresh before session sync failed:`,n);let r=p(t.path);e=r?Pt.getState().availableWorktreesByProject.get(r)??[]:[]}let n=zb(t.path,e,{currentDirectory:ve,workspaceRoot:t.path,includeWorktrees:!ft});n.length!==0&&await Sn(n,Gt.current)})()},[ve,ft,be]);Q.useEffect(()=>{if(!an)return;let e=Rt.getState(),t=be.flatMap(t=>A.has(t.id)?[]:nr(t.id).filter(t=>!e.loadedDirectories.has(t)&&!e.loadingDirectories.has(t)&&!e.refreshingDirectories.has(t)));t.length>0&&hn(t,Gt.current)},[A,nr,an,be]);let ar=Q.useCallback(()=>{ge.current=Date.now()+150,F(new Map),j(()=>{let e=new Set(be.map(e=>e.id));try{k.setItem(Ub,JSON.stringify(Array.from(e)))}catch{}return ft||rn(e),e})},[be,ft,k,rn]),or=Q.useCallback(()=>{ge.current=Date.now()+150,F(new Map),j(()=>{let e=new Set;try{k.setItem(Ub,JSON.stringify([]))}catch{}return ft||rn(e),e});let e=Rt.getState().loadedDirectories,t=be.flatMap(t=>nr(t.id).filter(t=>!e.has(t)));t.length>0&&hn(t,Gt.current)},[nr,ft,be,k,rn]),sr=Q.useCallback(e=>{ge.current=Date.now()+150,tr(e),j(t=>{let n=new Set(t);n.has(e)?(n.delete(e),queueMicrotask(()=>rr(e))):n.add(e);try{k.setItem(Ub,JSON.stringify(Array.from(n)))}catch{}return ft||rn(n),n})},[rr,ft,tr,k,rn]),cr=Q.useCallback(e=>{ge.current=Date.now()+150,rr(e),j(t=>{if(!t.has(e))return t;let n=new Set(t);n.delete(e);try{k.setItem(Ub,JSON.stringify(Array.from(n)))}catch{}return ft||rn(n),n})},[rr,ft,k,rn]),lr=Q.useMemo(()=>be.map(e=>({...e,normalizedPath:p(e.path)})).filter(e=>!!e.normalizedPath),[be]),ur=Q.useMemo(()=>lr.map(e=>e.normalizedPath),[lr]),dr=Q.useMemo(()=>{let e=new Set(lr.map(e=>e.normalizedPath));if(!ft)for(let t of Ft.values())for(let n of t){let t=p(n.path);t&&e.add(t)}return[...e].sort()},[Ft,ft,lr]),fr=Q.useRef(null);Q.useEffect(()=>{let e=new Set(dr),t=fr.current;if(fr.current=e,!t)return;let n=dr.filter(e=>!t.has(e));if(n.length===0)return;let r=Rt.getState().loadedDirectories,i=p(ve),a=lr.find(e=>e.id===Se)??lr.find(e=>e.normalizedPath===i)??null,o=new Set;i&&o.add(i),a?.normalizedPath&&(o.add(a.normalizedPath),ft||(Ft.get(a.normalizedPath)??[]).forEach(e=>{let t=p(e.path);t&&o.add(t)}));let s=n.filter(e=>o.has(e)&&!r.has(e));s.length!==0&&hn(s,Gt.current)},[Se,Ft,ve,ft,lr,dr]);let{github:pr}=za(),mr=Ma(),hr=mr.data??null,gr=mr.isFetched,_r=Ya(a?ur:rx),vr=Z_(e=>e.ensureEntry),yr=Z_(e=>e.setParams),br=Z_(e=>e.refreshTargets);m_({normalizedProjects:lr,activeProjectId:Se,gitRepoStatus:_r,setProjectRepoStatus:N,setProjectRootBranches:me,enabled:a});let Sr=Pt(e=>e.isLoading),Cr=Q.useMemo(()=>Ys(Ht,lr,Ft,ft,St),[St,Ft,ft,lr,Ht]);g_({isSessionsLoading:Sr,fullCatalogSessionIds:pt,fullCatalogGeneration:mt,normalizedProjects:lr,cleanupSessions:rt});let{getSessionsForProject:wr,getArchivedSessionsForProject:Tr}=h_({ownership:Cr}),Er=Q.useMemo(()=>{let e=new Set;if(vt.size===0)return e;for(let t of lr){let n=[t.normalizedPath];ft||(Ft.get(t.normalizedPath)??[]).forEach(e=>{let t=p(e.path);t&&n.push(t)}),n.some(e=>vt.has(e))&&e.add(t.id)}return e},[Ft,ft,vt,lr]),Dr=Q.useMemo(()=>{let e=new Set;if(yt.size===0)return e;for(let t of lr)nr(t.id).some(e=>yt.has(e))&&e.add(t.id);return e},[nr,lr,yt]),Or=vt.size>0||yt.size>0||ht===`idle`||ht===`loading`;Zg({normalizedProjects:lr,ownership:Cr,isSessionsLoading:Sr,fullCatalogSessionIds:pt,fullCatalogGeneration:mt,foldersMap:He,createFolder:Ke,addSessionToFolder:Xe,cleanupSessions:rt,enabled:a});let kr=Q.useRef(!1);Se&&M.has(Se)&&(kr.current=!!M.get(Se));let Ar=Ev(e=>e.projectSortOrder),jr=qt(e=>e.manualProjectOrder),Mr=Q.useMemo(()=>{let e=[...lr];switch(Ar){case`a-z`:e.sort((e,t)=>{let n=(e.label||e.path).toLowerCase(),r=(t.label||t.path).toLowerCase();return n.localeCompare(r)});break;case`z-a`:e.sort((e,t)=>{let n=(e.label||e.path).toLowerCase();return(t.label||t.path).toLowerCase().localeCompare(n)});break;case`date-added`:e.sort((e,t)=>(t.addedAt??0)-(e.addedAt??0));break;case`recent`:e.sort((e,t)=>(t.lastOpenedAt??0)-(e.lastOpenedAt??0));break;case`manual`:{let t=new Map(jr.map((e,t)=>[e,t]));e.sort((e,n)=>(t.get(e.id)??1/0)-(t.get(n.id)??1/0));break}}return e},[lr,Ar,jr]),{projectSections:Nr,groupSearchDataByGroup:Pr,sectionsForRender:Fr,searchMatchCount:Ir}=$g({normalizedProjects:Mr,getSessionsForProject:wr,getArchivedSessionsForProject:Tr,availableWorktreesByProject:Ft,projectRepoStatus:M,projectRootBranches:pe,lastRepoStatus:kr.current,buildGroupedSessions:nn,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,filterSessionNodesForSearch:tn,buildGroupSearchText:en,foldersMap:He}),Lr=(0,$.jsxs)(`div`,{className:`py-6 text-center text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label font-semibold`,children:s(`sessions.sidebar.empty.noMatches.title`)}),(0,$.jsx)(`p`,{className:`typography-meta mt-1`,children:s(`sessions.sidebar.empty.noMatches.description`)})]});t_({projectSections:Nr,activeProjectId:Se,activeSessionByProject:de,setActiveSessionByProject:fe,currentSessionId:wt,handleSessionSelect:On,newSessionDraftOpen:Dt,mobileVariant:e,openNewSessionDraft:zt,setActiveMainTab:De,setSessionSwitcherOpen:Ne});let{getOrderedGroups:Rr}=n_(le),zr=Q.useRef(!1);Q.useEffect(()=>{if(zr.current||Nr.length===0)return;let e=Nr.flatMap(e=>e.groups.filter(e=>e.isArchivedBucket).map(t=>`${e.project.id}:${t.id}`));e.length>0&&se(t=>new Set([...t,...e])),zr.current=!0},[Nr]);let Br=Q.useMemo(()=>{let e=new Map,t=new Map;return Nr.forEach(n=>{let r=Gn(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},[Nr]);Q.useLayoutEffect(()=>{if(!wt){_b(null);return}let e=ri.getState().focus;if(e?.sessionId===wt){e.scope===`project`&&!e.projectId&&_b({...e,projectId:Br.get(wt)?.projectId??null});return}_b({scope:`project`,sessionId:wt,projectId:Br.get(wt)?.projectId??null})},[wt,Br]);let Vr=Q.useMemo(()=>ft?[]:Vs(Ht,ie),[ft,ie,Ht]),Hr=Q.useMemo(()=>ze?[]:rc(Ht,ie,ut,dt),[ze,ie,ut,Ht,dt]),{pinnedItems:Wr,inProgressItems:Gr}=Q.useMemo(()=>{let e=e=>{let t=Br.get(e.id),n=p(e.directory??null),r={session:e,children:[],worktree:Nt.get(e.id)??null};if(ze&&tn([r],Re).length===0)return null;let i=Cr.bySessionId.get(e.id),a=i?Mr.find(e=>e.id===i.projectId):void 0,o=a?Gn(a.normalizedPath)||a.normalizedPath:t?.secondaryMeta?.projectLabel??null,s=lc({projectLabel:o,owner:i,sessionWorktree:Nt.get(e.id)??null,worktrees:a?Ft.get(a.normalizedPath)??[]:[],projectRootBranch:i?pe.get(i.projectId)??(a?_r.get(a.normalizedPath)?.branch:null)??null:null,isVSCode:ft})??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:ft?[]:t(Vr),inProgressItems:t(Hr)}},[Ft,tn,_r,ze,Hr,ft,Re,Vr,pe,Cr,Br,Mr,Nt]),Kr=Q.useMemo(()=>Fr.map(e=>({...e,groups:e.groups.filter(e=>!e.isArchivedBucket)})),[Fr]),qr=Q.useMemo(()=>{let e=ze?Kr.map(e=>({...e,groups:e.groups.map(e=>({...e,sessions:Pr.get(e)?.filteredNodes??[]}))})):Kr;if(!i)return e;let t=e.find(e=>e.project.id===Se)??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]}]:[]},[Se,Pr,ze,Kr,i]),Jr=Q.useMemo(()=>js({sections:qr,foldersMap:He,getOrderedGroups:Rr,pinnedSessionIds:ie,sessionOrderByScope:Ue,sessionOrderActivityByScope:We}),[He,Rr,qr,ie,We,Ue]),Yr=Q.useMemo(()=>Ms({targets:Jr,collapsedProjectIds:A,collapsedGroupKeys:oe,collapsedFolderIds:Ve,visibleSessionCountByGroup:P,defaultVisibleSessionCount:Ns(),hasSessionSearchQuery:ze,alwaysVisibleSessionIds:ct}),[ct,Ve,oe,A,ze,Jr,P]),Xr=Q.useMemo(()=>ze?[]:[...Vr,...Hr].map((e,t)=>{let n=Br.get(e.id);return{scope:`pinned`,sessionId:e.id,projectId:n?.projectId??null,directory:p(It(e))??n?.groupDirectory??null,visibleIndex:t}}),[ze,Hr,Vr,Br]),[Zr,Qr]=Q.useState(null),$r=Q.useCallback(e=>{Qr(t=>t&&t.length===e.length&&t.every((t,n)=>t===e[n])?t:[...e])},[]),ei=Q.useMemo(()=>{if(!Zr)return Xr;let e=new Set(Zr);return Xr.filter(t=>e.has(t.sessionId))},[Xr,Zr]),ti=Q.useMemo(()=>e?[]:vi({pinnedTargets:ei,projectTargets:Yr}),[e,ei,Yr]),ni=Q.useCallback(e=>{De(`chat`),Ne(!1),e.scope===`project`&&e.projectId&&we(e.projectId),zn(e.sessionId,e.directory,e.projectId,e.scope)},[zn,De,we,Ne]);Q.useLayoutEffect(()=>ai({targets:ti,activate:ni}),[ni,ti]);let ii=Q.useMemo(()=>{let e=new Map;return ti.forEach(t=>{let n=Mi({scope:t.scope,sessionId:t.sessionId,projectId:t.projectId});n&&e.set(n,Ai(ti,t)??0)}),e},[ti]),oi=Q.useMemo(()=>{if(!wt||ze)return[];let e=[],t=(n,r)=>{if(n.session.id===wt){e.push({scope:`pinned`,sessionId:wt,projectId:r});return}n.children.forEach(e=>t(e,r))};return Wr.forEach(e=>t(e.node,e.projectId)),Gr.forEach(e=>t(e.node,e.projectId)),e},[wt,ze,Gr,Wr]),si=Q.useMemo(()=>{if(!wt)return[];let e=[],t=(n,r)=>{if(n.session.id===wt){e.push({scope:`project`,sessionId:wt,projectId:r});return}n.children.forEach(e=>t(e,r))};return Nr.forEach(e=>{e.groups.forEach(n=>{n.sessions.forEach(n=>t(n,e.project.id))})}),e},[wt,Nr]);Q.useLayoutEffect(()=>li({pinned:ei,project:Yr}),[ei,Yr]),Q.useLayoutEffect(()=>{Or||_b(Vb({currentSessionId:wt,focus:Tt,pinnedFocuses:oi,projectFocuses:si,fallbackProjectId:wt?Br.get(wt)?.projectId??null:null}))},[wt,Or,si,oi,Tt,Br]);let ci=Q.useMemo(()=>{let e=Tt?.sessionId?Br.get(Tt.sessionId)?.projectId??null:null;return Hb(Tt,Jr,e)},[Jr,Tt,Br]),ui=Q.useRef(null),di=Q.useRef(null);Q.useEffect(()=>{di.current&&di.current!==wt&&(di.current=null)},[wt]),Q.useLayoutEffect(()=>{if(!ci?.projectId)return;let e=ci.sessionId,t=Et.sessionId===e;if(!(!t&&wt!==e)){if(t){if(ui.current===Et.revision)return;ui.current=Et.revision,di.current=e}else{if(di.current===e)return;di.current=e}if(cr(ci.projectId),ci.groupKey&&se(e=>{if(!e.has(ci.groupKey))return e;let t=new Set(e);return t.delete(ci.groupKey),t}),ci.folderAncestorIds?.forEach(e=>{let t=yn.getState();t.collapsedFolderIds.has(e)&&t.toggleFolderCollapse(e)}),ci.groupKey&&ci.visibleIndex!==void 0){let e=ci.visibleIndex+1;F(t=>{if((t.get(ci.groupKey)??0)>=e)return t;let n=new Map(t);return n.set(ci.groupKey,e),n})}}},[wt,cr,ci,Et]);let fi=rv(Q.useMemo(()=>{let e=new Set;return Kr.forEach(t=>{A.has(t.project.id)||t.groups.forEach(n=>{if(oe.has(`${t.project.id}:${n.id}`))return;let r=p(n.directory??null),i=n.branch?.trim()||ot.get(r||``)?.trim();!r||!i||e.add(M_(r,i))})}),[...e]},[oe,A,ot,Kr]));Q.useEffect(()=>{if(!a||!gr||!hr?.connected||!pr)return;let e=[],t=Date.now();if(Kr.forEach(n=>{A.has(n.project.id)||n.groups.forEach(r=>{if(oe.has(`${n.project.id}:${r.id}`))return;let i=p(r.directory??null),a=r.branch?.trim()||ot.get(i||``)?.trim();if(!i||!a)return;let o=M_(i,a),s=Z_.getState().entries[o],c=!!s?.status?.pr,l=`${i}::${a}`,u=Math.max(s?.lastRefreshAt??0,s?.lastDiscoveryPollAt??0),d=!!(s?.isInitialStatusResolved&&!c&&(!y.current.has(l)||t-u>=tx));(!s||!s.isInitialStatusResolved||d)&&(d&&y.current.add(l),e.push({directory:i,branch:a}))})}),e.length===0)return;let n=new Map;e.forEach(e=>{let t=M_(e.directory,e.branch,e.remoteName??null);n.has(t)||n.set(t,e)}),n.forEach((e,t)=>{vr(t),yr(t,{directory:e.directory,branch:e.branch,remoteName:e.remoteName??null,canShow:!0,github:pr,githubAuthChecked:gr,githubConnected:hr.connected})}),br([...n.values()],{silent:!0,markInitialResolved:!0})},[A,oe,vr,pr,gr,hr?.connected,ot,a,br,Kr,yr]);let pi=v_({isDesktopShellRuntime:Yt,projectSections:Nr,projectHeaderSentinelRefs:he,enabled:a}),mi=ax((t,n=0,r,i,a=!1,o,s=`project`,c)=>(0,$.jsx)(jb,{node:t,depth:n,groupDirectory:r,projectId:i,archivedBucket:a,currentSessionId:wt,pinnedSessionIds:ie,expandedParents:D,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,notifyOnSubtasks:q,editingId:b,setEditingId:x,editTitle:S,setEditTitle:C,handleSaveEdit:Kn,handleCancelEdit:qn,toggleParent:Vn,handleSessionSelect:Un,handleSessionDoubleClick:Wn,togglePinnedSession:ae,handleShareSession:Jn,copiedSessionId:Dn,handleCopyShareUrl:Yn,handleUnshareSession:Xn,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,renamingFolderId:z,getFoldersForScope:Ge,getSessionFolderId:it,removeSessionFromFolder:$e,addSessionToFolder:Xe,createFolderAndStartRename:Qn,openContextPanelTab:Ae,handleDeleteSession:Zn,mobileVariant:e,alwaysShowActions:$t,renderSessionNode:mi,secondaryMeta:o,renderContext:s,subtreeContainsActive:c?.subtreeContainsActive??nx,subtreeContainsEditing:c?.subtreeContainsEditing??nx,menuOpenSessionId:c?.menuOpenSessionId??null,nodeStructureKey:c?.nodeStructureKey??``,childRenderExtrasFor:c?.childRenderExtrasFor,liveSessionById:Kt,shortcutNumber:ii.get(Mi({scope:s,sessionId:t.session.id,projectId:i??null})??``)??null},`${s}:${i??``}:${t.session.id}`)),hi=Q.useCallback(e=>{er(e),se(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[er]),gi=Q.useCallback(e=>{let t=nr(e);if(t.length===0)return;let n=Rt.getState(),r=t.filter(e=>!n.archivedLoadedDirectories.has(e));r.length>0&&ln(r)},[nr]),_i=Q.useMemo(()=>{let e=new Map;for(let[t,n]of fi)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},[fi]),yi=Q.useCallback((t,n,r,i,a,o,s)=>(0,$.jsx)(Hv,{group:t,groupKey:n,isArchivedLoading:!!(t.isArchivedBucket&&r&&nr(r).some(e=>bt.has(e))),projectId:r,hideGroupLabel:i,compactBodyPadding:o,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,groupSearchDataByGroup:Pr,visibleSessionCount:P.get(n),collapsedGroups:oe,collapsedFolderIds:Ve,toggleFolderCollapse:nt,renameFolder:Je,deleteFolder:Ye,showDeletionDialog:Fe,setDeleteFolderConfirm:W,renderSessionNode:mi,projectRepoStatus:M,lastRepoStatus:kr.current,showMoreGroupSessions:(e,n,r)=>$n(t,e,n,r),resetGroupSessionLimit:er,mobileVariant:e,alwaysShowActions:$t,activeProjectId:Se,setActiveProjectIdOnly:we,setActiveMainTab:De,setSessionSwitcherOpen:Ne,openNewSessionDraft:Bt,addSessionToFolder:Xe,createFolderAndStartRename:Qn,renamingFolderId:z,renameFolderDraft:V,setRenameFolderDraft:H,setRenamingFolderId:B,pinnedSessionIds:ie,expandedParents:D,sessionOrderByScope:Ue,sessionOrderActivityByScope:We,onReorderSessions:(e,n,r,i)=>{let a=t.folderScopeKey??p(t.directory??null);a&&at(a,e,n,r,i)},currentSessionId:wt,shortcutTargetSessionId:ci?.groupKey===n?ci.sessionId:null,shortcutTargetVisibleIndex:ci?.groupKey===n?ci.visibleIndex??null:null,editingId:b,editTitle:S,openSidebarMenuKey:L,liveSessionById:Kt,alwaysVisibleSessionIds:ct,prVisualStateByDirectoryBranch:_i,onToggleCollapsedGroup:e=>{t.isArchivedBucket&&oe.has(e)&&r&&gi(r),hi(e)},dragHandleProps:a,scrollContainerRef:s}),[ze,Re,Pr,bt,nr,P,oe,Ve,nt,Je,Ye,Fe,mi,M,$n,er,e,$t,Se,we,De,Ne,Bt,Xe,Qn,z,V,ie,D,Ue,We,at,wt,ci,b,S,L,Kt,ct,_i,hi,gi]),bi=r?null:(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Zv,{collapseAllProjects:ar,expandAllProjects:or}),(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,className:`size-6 p-0 text-muted-foreground`,"aria-label":s(`sessions.sidebar.header.actions.addProject`),title:s(`sessions.sidebar.header.actions.addProject`),onClick:Ct.requestDirectoryDialog,children:(0,$.jsx)(X,{name:`add`,className:`size-4`})})]}),xi=Yt&&Xt&&!ft&&!ze?(0,$.jsx)(`div`,{className:`shrink-0 px-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(iu,{className:`min-w-0 flex-1`}),(0,$.jsx)(su,{className:`ml-auto shrink-0`})]})}):null,Si=!ft&&!ze,Ci=!ze&&(Wr.length>0||Gr.length>0),wi=Si||Ci?(0,$.jsxs)($.Fragment,{children:[Si?(0,$.jsxs)($.Fragment,{children:[e&&Xt?(0,$.jsx)(iu,{}):null,(0,$.jsxs)(`div`,{className:`space-y-0.5 py-1`,children:[(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,className:Y(`w-full justify-start font-normal`,e&&`h-11`),onClick:vn,children:[(0,$.jsx)(X,{name:`chat-new`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`sessions.sidebar.header.actions.newSession`)})]}),(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,className:Y(`w-full justify-start font-normal`,Oe===`schedule`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:xn,children:[(0,$.jsx)(X,{name:`time`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`sessions.sidebar.header.actions.scheduledTasks`)})]}),ke.data?.supported&&ke.data?.enabled?(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,className:Y(`w-full justify-start font-normal`,Oe===`assistant`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:Cn,children:[(0,$.jsx)(X,{name:`ai-agent`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`assistants.title`)})]}):null]})]}):null,Ci?(0,$.jsx)(Gv,{items:Wr,inProgressItems:Gr,renderSessionNode:mi,currentSessionId:wt,editingId:b,openSidebarMenuKey:L,onVisibleSessionIdsChange:$r}):null]}):null,Ti=!!(z||b||w),{selectionModeEnabled:Ei,hasSelection:Di,selectedIdsSize:Oi,bulkScopeIsArchived:ki,derivedSelectionScope:ji,bulkScopeFolders:Ni,bulkCanRemoveFromFolder:Pi,handleExitSelectionMode:Fi,handleBulkMoveToFolder:Ii,handleBulkCreateFolderAndMove:Li,handleBulkRemoveFromFolder:Ri,handleBulkDelete:zi,confirmBulkDelete:Bi}=Rb({isInlineEditing:Ti,showDeletionDialog:Fe,foldersMap:He,addSessionsToFolder:Ze,removeSessionsFromFolders:tt,createFolderAndStartRename:Hn,archiveSessions:En,setBulkDeleteConfirm:G});return(0,$.jsxs)(`div`,{ref:_,className:Y(`oc-session-sidebar relative flex h-full flex-col text-foreground overflow-x-hidden`,e?``:`bg-transparent`),children:[(0,$.jsx)(Uv,{hideDirectoryControls:r,isSessionSearchOpen:d,setIsSessionSearchOpen:f,sessionSearchInputRef:v,sessionSearchQuery:h,setSessionSearchQuery:g,hasSessionSearchQuery:ze,searchMatchCount:Ir}),xi,a?(0,$.jsx)(cy,{topContent:wi,hasLeadingSection:wi!==null&&(Wr.length>0||Gr.length>0),headerAccessory:bi,sectionsForRender:Kr,projectSections:Nr,activeProjectId:Se,showOnlyMainWorkspace:i,hasSessionSearchQuery:ze,emptyState:cn,searchEmptyState:Lr,renderGroupSessions:yi,homeDirectory:_e,collapsedProjects:A,hideDirectoryControls:r,projectRepoStatus:M,isDesktopShellRuntime:Yt,stuckProjectHeaders:pi,mobileVariant:e,alwaysShowActions:$t,toggleProject:sr,setActiveProjectIdOnly:we,setActiveMainTab:De,setSessionSwitcherOpen:Ne,openNewSessionDraft:Bt,openNewWorktreeDialog:pn,syncProjectSessions:ir,openProjectEditDialog:T,removeProject:Ce,projectHeaderSentinelRefs:he,projectReorderEnabled:Ar===`manual`,reorderProjects:Ee,projectSortOrder:Ar,getOrderedGroups:Rr,setGroupOrderByProject:ue,openSidebarMenuKey:L,setOpenSidebarMenuKey:R,isInlineEditing:Ti,loadingProjectIds:Er,refreshingProjectIds:Dr,isProjectSessionsSyncing:Or}):null,Ei&&Di?(0,$.jsx)(Lb,{selectedCount:Oi,scopeKey:ji,scopeFolders:Ni,archivedBucket:ki,onMoveToFolder:Ii,onCreateFolderAndMove:Li,onRemoveFromFolder:Ri,canRemoveFromFolder:Pi,onDelete:zi,onDone:Fi}):null,(0,$.jsx)(ty,{onOpenSettings:_n,onOpenShortcuts:Me,onOpenUpdate:gn,showRuntimeButtons:!ft,showUpdateButton:wn}),c?(0,$.jsx)(_s,{open:c,onOpenChange:l,info:Be.info,downloading:Be.downloading,downloaded:Be.downloaded,progress:Be.progress,error:Be.error,onDownload:Be.downloadUpdate,onRestart:Be.restartToUpdate,runtimeType:Be.runtimeType}):null,un?(0,$.jsx)(iv,{open:!0,onOpenChange:e=>{e||T(null)},project:un,onSave:dn}):null,I?(0,$.jsx)(Ur,{open:!0,onOpenChange:ee,onWorktreeCreated:mn}):null,(0,$.jsx)(Ks,{}),(0,$.jsx)(Xg,{}),(0,$.jsx)(Pb,{value:te,setValue:U,showDeletionDialog:Fe,setShowDeletionDialog:Ie,onConfirm:Rn}),(0,$.jsx)(Ib,{value:ne,setValue:W,onConfirm:Bn}),(0,$.jsx)(Fb,{value:re,setValue:G,showDeletionDialog:Fe,setShowDeletionDialog:Ie,onConfirm:Bi})]})},sx=e=>e?(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:e}):void 0,cx=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},lx=()=>{let{t:e}=qe(),[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=Pt(e=>e.getWorktreeMetadata),b=Pt(e=>e.newSessionDraft),x=Pt(e=>e.setNewSessionDraftTarget),S=Pt(e=>e.setDraftBootstrapPendingDirectory),C=Xt,w=Pt(e=>e.archiveSessions),T=K(e=>e.showDeletionDialog),E=K(e=>e.setShowDeletionDialog),D=xe(e=>e.currentDirectory),O=xe(e=>e.homeDirectory),k=xe(e=>e.isHomeReady),A=qt(e=>e.projects),j=qt(e=>e.activeProjectId),{isMobile:M,isTablet:N,hasTouchInput:P}=Fa(),F=M||N||P,I=Q.useMemo(()=>cx((j?A.find(e=>e.id===j)??null:null)?.path??D),[j,D,A]),ee=Q.useCallback(e=>{let t=cx(e.projectDirectory)||I;return{id:(A.find(e=>cx(e.path)===t)??null)?.id??`path:${t}`,path:t}},[I,A]),L=h&&_.size>0,R=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]),z=a?.mode===`worktree`,B=z,V=p||!z||!R,H=p||!z;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})},[]),U=Q.useCallback(()=>{o(null),c([]),u(!1),f(!1),m(!1),g(!1),v(new Set)},[]),ne=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(()=>Ct.onDeleteRequest(e=>{if(!T&&(e.mode??`session`)===`session`){ne(e);return}te(e)}),[te,T,ne]),Q.useEffect(()=>Ct.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(cx(a.worktree.path),a.worktree),e.forEach(({metadata:e})=>{e.path&&t.set(cx(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 Qi(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=cx(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=cx(t.metadata.path),r=e.get(n);return r?{session:t.session,metadata:{...t.metadata,status:r}}:t})))})(),()=>{n=!0}},[a,y]),Q.useEffect(()=>{R||u(!1)},[R]);let W=Q.useCallback(async(t,n)=>{let r=l&&R,i=ee(t),a=cx(t.path),o=cx(i.path);try{await Yi(i,t,{deleteRemoteBranch:r,deleteLocalBranch:n});let e=cx(b?.directoryOverride);return b?.open&&a&&e===a&&o&&(S(null),x({projectId:i.id,directoryOverride:o},{force:!0})),cx(D)===a&&o&&xe.getState().setDirectory(o,{showOverlay:!1}),!0}catch(t){return J.error(e(`sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle`),{description:sx(t instanceof Error?t.message:e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),!1}},[R,D,l,ee,b?.directoryOverride,b?.open,S,x,e]),re=Q.useCallback((t,n)=>{let r=l&&R;(async()=>{if(!await W(t,n))return;let i=e(r?`sessions.sidebar.sessionDialogs.worktree.removedWithRemote`:`sessions.sidebar.sessionDialogs.worktree.removed`);J.success(e(`sessions.sidebar.sessionDialogs.worktree.removedTitle`),{description:sx(i)})})()},[R,l,W,e]),G=Q.useCallback(async()=>{if(a){m(!0);try{let t=B&&d;if(a.sessions.length===0&&z&&a.worktree){re(a.worktree,t),U();return}if(a.sessions.length===1){let t=a.sessions[0];if(z){if(!await C(t.id)){J.error(e(`sessions.sidebar.session.archive.error`)),m(!1);return}ws({sessionIds:[t.id],message:e(`sessions.sidebar.session.archive.success`),undoLabel:e(`sessions.sidebar.undo`),settingsLabel:e(`settings.openchamber.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(z){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(z&&a.worktree&&i.length===0&&re(a.worktree,t),z&&r.length>0&&ws({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.openchamber.archivedSessions.actions.view`),undoFailedMessage:r.length===1?e(`sessions.sidebar.session.archive.undoFailed`):e(`sessions.sidebar.bulkActions.archiveUndoFailed`,{count:r.length})}),i.length>0&&(J.error(z?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:sx(e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),r.length===0)){m(!1);return}}z&&a.sessions.length===1&&a.worktree&&re(a.worktree,t),U()}finally{m(!1)}}},[a,d,C,w,U,B,z,re,e]),ie=a?.worktree??s[0]?.metadata??null,ae=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}):``,oe=a?(0,$.jsxs)(`div`,{className:Y(z?`space-y-3`:`space-y-2`),children:[a.sessions.length>0&&(0,$.jsxs)(`div`,{className:Y(z?`rounded-lg bg-muted/30 p-3`:`space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3`),children:[z&&(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:Y(z?`mt-2 space-y-1`:`space-y-0.5`),children:[a.sessions.slice(0,5).map(t=>(0,$.jsxs)(`li`,{className:Y(z?`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:Y(!z&&`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:Y(z?`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})})]})]}),z?(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)(X,{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`)}),ie?.label?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground/70`,children:ie.label}):null]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground/80 break-all`,children:ie?qn(ie.path,O):e(`sessions.sidebar.sessionDialogs.worktree.pathUnavailable`)}),L&&(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,se=z?R?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{V||u(e=>!e)},disabled:V,className:Y(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,V?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[l?(0,$.jsx)(X,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(X,{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,ce=z?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{H||f(e=>!e)},disabled:H,className:Y(`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)(X,{name:`checkbox`,className:`size-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`size-4`}),e(`sessions.sidebar.sessionDialogs.actions.deleteLocalBranch`)]}):null,le=z?(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:[ce,se]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,onClick:U,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:G,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)(X,{name:`checkbox-blank`,className:`size-4`}):(0,$.jsx)(X,{name:`checkbox`,className:`size-4 text-primary`}),e(`sessions.sidebar.dialogs.neverAsk`)]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Z,{variant:`ghost`,onClick:U,disabled:p,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:G,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=z?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)(fi,{open:!!a,onClose:()=>{p||U()},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:[ae&&(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/80`,children:ae}),oe]})}):(0,$.jsx)(Vn,{open:!!a,onOpenChange:e=>{if(!e){if(p)return;U()}},children:(0,$.jsxs)(Rn,{className:Y(z?`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)(In,{children:[(0,$.jsxs)(zn,{className:Y(z&&`flex items-center gap-2`),children:[z&&(0,$.jsx)(X,{name:`delete-bin`,className:`h-5 w-5`}),ue]}),ae&&(0,$.jsx)(Bn,{children:ae})]}),(0,$.jsx)(`div`,{className:Y(z&&`flex-1 min-h-0 overflow-y-auto space-y-2`),children:oe}),(0,$.jsx)(Ln,{className:`mt-2 gap-2 pt-1 pb-1`,children:le})]})}),(0,$.jsx)(ec,{open:t,onOpenChange:n})]})},ux=Q.createContext(null),dx=e=>{let t=(0,zc.c)(3),{children:n,value:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(ux.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},fx=no(()=>Pe(()=>import(`./TerminalView-BmSIrZ81.js`).then(e=>({default:e.TerminalView})),__vite__mapDeps([54,1,2,3,4,24,7,5,6,25,8,26,55,37,38,10,56,23,27,39,40,41,20,21,22,42,43,29,30,31,32,33,34,57,58,48,59,60,61,62,63,64]))),px=no(()=>Pe(()=>import(`./DiagramView-BdI4PT2H.js`).then(e=>({default:e.DiagramView})),__vite__mapDeps([65,1,4,3,5,6,7,40,26,41,23,24,2,25,8,27,10,32,29,30,31,58,48,37,38,39,20,21,22,42,43,66,67,68]))),mx=no(()=>Pe(()=>import(`./SettingsView-CkQ61pbr.js`).then(e=>e.n).then(e=>({default:e.SettingsView})),__vite__mapDeps([69,1,3,4,2,24,7,5,6,25,8,26,70,71,37,38,10,40,72,41,20,21,22,23,27,73,39,42,43,74,29,30,31,32,33,28,75,76,77,78,52,57,79,60,61,62,80,81,82,83,84,85,86,34,87,88,58,36,9,11,12,13,14,15,16,17,18,19,44,45,46,89,47,59,90,91,92,93,94,95,64,96,97,98,99]))),hx=no(()=>Pe(()=>import(`./SettingsWindow-CSePZ_V8.js`).then(e=>({default:e.SettingsWindow})),__vite__mapDeps([100,1,5,8,23,24,4,3,2,7,6,25,26,27,10,29,30,31,69,70,71,37,38,40,72,41,20,21,22,73,39,42,43,74,32,33,28,75,76,77,78,52,57,79,60,61,62,80,81,82,83,84,85,86,34,87,88,58,36,9,11,12,13,14,15,16,17,18,19,44,45,46,89,47,59,90,91,92,93,94,95,64,96,97,98,99]))),gx=no(()=>Pe(()=>import(`./MultiRunWindow-C8ukIdLA.js`).then(e=>({default:e.MultiRunWindow})),__vite__mapDeps([101,1,5,8,23,24,4,3,2,7,6,25,26,27,10,29,30,31,32,102,37,38,20,21,22,39,40,41,42,43,33,77,76,78,52,57,79,60,61,62,58,103,92]))),_x=no(()=>Pe(()=>import(`./AssistantView-CKmIS1cS.js`).then(e=>e.n).then(e=>({default:e.AssistantView})),__vite__mapDeps([104,1,4,3,24,2,7,5,6,25,8,26,37,38,10,41,20,21,22,23,27,73,39,40,42,43,74,29,30,31,32,33,28,75,57,44,45,46,49,50,105,79,96,87,106,107]))),vx=()=>{let e=1220,t=K(e=>e.isSidebarOpen),n=K(e=>e.isRightSidebarOpen),r=K(e=>e.isBottomTerminalOpen),i=K(e=>e.setRightSidebarOpen),a=K(e=>e.setBottomTerminalOpen),o=K(e=>e.activeMainTab),s=K(e=>e.setIsMobile),c=K(e=>e.isSessionSwitcherOpen),l=K(e=>e.isSettingsDialogOpen),u=K(e=>e.setSettingsDialogOpen),d=K(e=>e.isMultiRunLauncherOpen),f=K(e=>e.setMultiRunLauncherOpen),{isMobile:p,isTablet:m}=Fa(),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),K.getState().setSessionSwitcherOpen(e)},[]),D=Q.useRef(!1),O=Q.useRef(typeof window>`u`?0:window.innerWidth),k=Uo(-O.current),A=(0,Q.useRef)(0),j=Uo(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),Wo(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),Wo(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),K.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=Pt.getState(),r=K.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(()=>{K.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,K.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=K.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=K.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)(zd,{isActive:!b})});case`diff`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(As,{})});case`terminal`:return r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(fx,{})});case`files`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Zf,{})});case`diagram`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(px,{})});default:return null}},[o,r,b]),F=o===`schedule`,I=o===`assistant`,ee=F||I,L=o===`chat`,R=!ee&&!l;return(0,$.jsx)(ic,{children:(0,$.jsxs)(`div`,{"data-page-scroll-lock":`true`,className:Y(`main-content-safe-area`,p?`flex h-[100dvh] flex-col`:`relative flex h-[100dvh]`,`bg-background`),children:[(0,$.jsx)(Yh,{}),(0,$.jsx)(Bg,{}),(0,$.jsx)(Wg,{}),(0,$.jsx)(lx,{}),p?(0,$.jsxs)(dx,{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&&!ee&&(0,$.jsx)(Ul,{onToggleLeftDrawer:()=>{let e=!v;b&&x(!1),E(e)},onToggleRightDrawer:()=>{N()},leftDrawerOpen:v,rightDrawerOpen:b}),(0,$.jsx)(`div`,{"data-page-scroll-lock":`true`,className:Y(`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)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ac,{})})})}),I&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(_x,{})})})}),R&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!L&&`invisible`),children:(0,$.jsx)(Ca,{children:(0,$.jsx)(uc,{})})}),R&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Ca,{children:P})}),d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Pc,{onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),(0,$.jsx)(Ho.div,{className:Y(`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)(Ca,{children:(0,$.jsx)(ox,{mobileVariant:!0,isVisible:S})})}),w&&(0,$.jsx)(Ho.div,{className:`absolute inset-0 z-20 bg-sidebar`,"data-page-scroll-lock":`true`,style:{x:j},"aria-hidden":!b,children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(zd,{isActive:b})})})})]})}),l&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,style:{paddingTop:`var(--oc-safe-area-top, 0px)`},children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(mx,{onClose:()=>u(!1)})})})}),(0,$.jsx)(Ca,{children:(0,$.jsx)(pc,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(du,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(nu,{isOpen:t,isMobile:p,className:`border-border/50`,topBar:(0,$.jsx)(ru,{}),children:(0,$.jsx)(ox,{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:ee?(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:I?(0,$.jsx)(_x,{}):(0,$.jsx)(ac,{})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ul,{}),(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 oc-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`,children:[(0,$.jsxs)(`main`,{className:`flex-1 overflow-hidden bg-background relative`,"data-page-scroll-lock":`true`,children:[R&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!L&&`invisible`),children:(0,$.jsx)(Ca,{children:(0,$.jsx)(uc,{})})}),R&&P&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Ca,{children:P})})]}),(0,$.jsx)(Hh,{})]})}),(0,$.jsx)(Jl,{isOpen:r,isMobile:p,children:r?(0,$.jsx)(Ca,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(fx,{})})}):null})]}),(0,$.jsx)(bu,{isOpen:n,className:`bg-background oc-layout-divider-t`,children:(0,$.jsx)(Ca,{children:(0,$.jsx)(pf,{})})})]})]})})]}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(hx,{open:l,onOpenChange:u})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(gx,{open:d,onOpenChange:f})})]})]})})},yx=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`},bx=e=>{let t=(0,zc.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},xx=e=>{let t=(0,zc.c)(43),{title:n,snapshot:r,emptyLabel:i}=e,{t:a}=qe(),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(Cx,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?yx(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)(bx,{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)(bx,{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)(bx,{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)(so,{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},Sx=e=>{let t=(0,zc.c)(104),{onClose:n}=e,{t:r}=qe(),[i,a]=Q.useState(`memory`),[o,s]=Q.useState(`idle`),c=Pt(wx),l=En(Tx),u=nn(),d=Kt(),[f,p]=Q.useState(Ex),m,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>On(()=>{p(un())}),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=Ut(),t={};if(!e){g=t;break bb0}let n=e.getCacheBudget?.(),r=n?n.listCanonical().map(Dx):u.map(e=>({directory:d,sessionID:e.id}));for(let n of r){if(d&&n.directory!==d)continue;let r=e.getTranscript(Mt(n.directory,n.sessionID));t[n.sessionID]=r.messageOrder.map(e=>r.messagesByID[e]).filter(Ox)}g=t}t[2]=d,t[3]=u,t[4]=g}else g=t[4];let _=g,v=Z_(kx),[y,b]=Q.useState(Ax),[x,S]=Q.useState(jx),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(Oe())};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,ee=0,L=0;for(let e of Object.keys(_)){let t=_[e]??[];ee+=t.length;for(let e of t)e.role===`user`?L+=1:e.role===`assistant`&&(I+=1)}let R;t[31]!==I||t[32]!==ee||t[33]!==L?(R={assistant:I,total:ee,user:L},t[31]=I,t[32]=ee,t[33]=L,t[34]=R):R=t[34];let z=R,B;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],B=u.map(e).sort(Mx),t[35]=c,t[36]=_,t[37]=l,t[38]=u,t[39]=r,t[40]=B}else B=t[40];let V=B,H;t[46]===_?H=t[47]:(H=Object.keys(_),t[46]=_,t[47]=H);let te=H.length,U;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(U=async()=>{try{let e={generatedAt:new Date().toISOString(),ui:ke(),vscode:Oe()};await navigator.clipboard.writeText(JSON.stringify(e,null,2)),s(`copied`)}catch{s(`error`)}},t[48]=U):U=t[48];let ne=U,W;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(W={backgroundColor:`color-mix(in srgb, var(--surface-background) 94%, transparent)`},t[49]=W):W=t[49];let re;t[50]===i?re=t[51]:(re=i===`memory`?(0,$.jsx)(X,{name:`database-2`,className:`h-4 w-4 text-[var(--surface-foreground)]`}):(0,$.jsx)(X,{name:`bar-chart-box`,className:`h-4 w-4 text-[var(--surface-foreground)]`}),t[50]=i,t[51]=re);let G;t[52]===r?G=t[53]:(G=r(`memoryDebugPanel.title`),t[52]=r,t[53]=G);let ie;t[54]===G?ie=t[55]:(ie=(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:G}),t[54]=G,t[55]=ie);let ae;t[56]!==re||t[57]!==ie?(ae=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[re,ie]}),t[56]=re,t[57]=ie,t[58]=ae):ae=t[58];let oe;t[59]===i?oe=t[60]:(oe=i===`streaming`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:ne,children:(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:()=>{Ce(),b(ke()),S(Oe())},children:(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`})})]}):null,t[59]=i,t[60]=oe);let se;t[61]===n?se=t[62]:(se=n?(0,$.jsx)(Z,{size:`icon`,variant:`ghost`,className:`h-6 w-6`,onClick:n,children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4`})}):null,t[61]=n,t[62]=se);let ce;t[63]!==oe||t[64]!==se?(ce=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[oe,se]}),t[63]=oe,t[64]=se,t[65]=ce):ce=t[65];let le;t[66]!==ae||t[67]!==ce?(le=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[ae,ce]}),t[66]=ae,t[67]=ce,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)(Z,{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)(Z,{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]!==z||t[91]!==l||t[92]!==V||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)(bx,{label:r(`memoryDebugPanel.metric.totalMessages`),value:z.total}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.cachedSessions`),value:`${te} / ${vr.MAX_SESSIONS}`}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.userMessages`),value:z.user}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.assistantMessages`),value:z.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:Yr()})})]}),(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:vr.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)(so,{outerClassName:`max-h-48`,className:`space-y-1 pr-1`,children:V.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)(X,{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)(aa,{children:[(0,$.jsx)(na,{asChild:!0,children:(0,$.jsx)(Z,{size:`sm`,variant:`outline`,className:`typography-meta`,onClick:()=>{u.map(Nx),Object.keys(_),V.map(Px),Object.fromEntries(l)},children:r(`memoryDebugPanel.actions.logState`)})}),(0,$.jsx)(ra,{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)(Z,{size:`xs`,variant:`outline`,onClick:ne,children:r(`memoryDebugPanel.actions.copyJson`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.uiMetrics`),value:y.entries.length}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.vscodeMetrics`),value:x.entries.length}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.messageListRenders`),value:j.messageListRender}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.messageListStreamRenders`),value:j.messageListRenderStreaming}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.chatMessageRenders`),value:j.chatMessageRender}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.chatMessageStreamRenders`),value:j.chatMessageRenderStreaming}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.chatMessageStaticDuringStream`),value:j.chatMessageRenderStaticDuringStream}),(0,$.jsx)(bx,{label:r(`memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn`),value:j.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),(0,$.jsx)(xx,{title:r(`memoryDebugPanel.section.uiStreamingMetrics`),snapshot:y,emptyLabel:r(`memoryDebugPanel.section.noUiSamples`)}),x.entries.length>0?(0,$.jsx)(xx,{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]=z,t[91]=l,t[92]=V,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)(Aa,{className:`fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area`,style:W,children:[le,ye,be]}),t[100]=le,t[101]=ye,t[102]=be,t[103]=xe):xe=t[103],xe};function Cx(e,t){return e+t.count}function wx(e){return e.currentSessionId}function Tx(e){return e.sessionMemoryState}function Ex(){return un()}function Dx(e){return e.scope}function Ox(e){return!!e}function kx(e){return e.totalRequestCount}function Ax(){return ke()}function jx(){return Oe()}function Mx(e,t){return t.lastAccessed-e.lastAccessed}function Nx(e){return{id:e.id,title:e.title}}function Px(e){return{id:e.id,title:e.title,total:e.messageCount,user:e.userMessageCount,assistant:e.assistantMessageCount}}var Fx=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=K.getState();if(e)return;let n=Mo();n&&t(n)||b()&&ee(`desktop_close_current_window`).catch(e=>{console.warn(`[menu-actions] failed to close current window`,e)})},Ix=()=>{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()??``:``},Lx=async()=>{let e=Ix()||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`)},Rx=`openchamber:menu-action`,zx=`openchamber:check-for-updates`,Bx=e=>typeof e?.listen==`function`?`bridge`:`dom`,Vx=e=>{let t=Pt(e=>e.openNewSessionDraft),n=K(e=>e.toggleCommandPalette),r=K(e=>e.setCommandPaletteOpen),i=K(e=>e.toggleHelpDialog),a=K(e=>e.toggleSidebar),o=K(e=>e.setSessionSwitcherOpen),s=K(e=>e.setActiveMainTab),c=K(e=>e.setSettingsDialogOpen),l=K(e=>e.setSettingsPage),u=K(e=>e.setAboutDialogOpen),d=K(e=>e.toggleRightSidebar),f=K(e=>e.setRightSidebarOpen),p=K(e=>e.setRightSidebarTab),m=K(e=>e.toggleBottomTerminal),h=K(e=>e.setBottomTerminalExpanded),g=qo(e=>e.checkForUpdates),{setThemeMode:_}=Pa(),{t:v}=qe(),y=Q.useRef(!1),b=typeof window>`u`?null:window.__OPENCHAMBER_DESKTOP__,x=Bx(b),S=Q.useCallback(()=>{y.current||(y.current=!0,g().then(()=>{let{available:e,error:t}=qo.getState();if(t){J.error(v(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}e||J.success(v(`sessions.sidebar.updateCheck.latestVersion`))}).finally(()=>{y.current=!1}))},[g,v]),C=Q.useCallback(()=>{Ct.requestDirectoryDialog()},[]),w=Q.useCallback(e=>{di(e,Pt.getState().currentSessionId,e=>{s(`chat`),o(!1),Pt.getState().setCurrentSession(e.sessionId,e.directory)})},[s,o]),T=Q.useCallback(e=>{let{activeProjectId:t,projects:n,setActiveProject:r}=qt.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),Ci();break;case`change-workspace`:C();break;case`close-tab-or-window`:Fx();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(!K.getState().isBottomTerminalExpanded);break;case`copy`:{let e=new Event(`openchamber:copy`,{cancelable:!0});window.dispatchEvent(e)&&Lx();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`:wi();break;case`zoom-out`:yi();break;case`zoom-reset`:si();break;case`go-back`:xe.getState().goBack();break;case`go-forward`:xe.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`:Fi().catch(()=>{J.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(Rx,e),window.addEventListener(zx,t),()=>{window.removeEventListener(Rx,e),window.removeEventListener(zx,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(`openchamber:menu-action`,e=>{let t=e?.payload;typeof t==`string`&&E(t)}).then(e=>{t=e}).catch(()=>{}),e(`openchamber: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])},Hx=(e,t)=>e<t?-1:+(e>t),Ux=e=>JSON.stringify([...e.entries()].map(([e,t])=>[e,[...new Set(t)].sort(Hx)]).sort(([e],[t])=>Hx(e,t)));async function Wx({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 Gx=`openchamber:tray-action`,Kx=3e4,qx=120,Jx=20,Yx=()=>{if(typeof window>`u`)return!1;let e=window.__OPENCHAMBER_PLATFORM__;return e===`darwin`||e===`win32`},Xx=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},Zx=e=>{let t=Array.isArray(e.questions)?e.questions[0]:void 0;return t?.header||t?.question||`Question`},Qx=e=>wt(e),$x=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},eS=(e,t,n,r)=>{if(!e)return``;let i=ut(t,n,e),a=$x(i?i.path:e),o=st(e),s=o&&r.get(o)||``;if(!s){for(let[e,t]of Wa.getState().directories)if(st(e)===o){s=t.status?.current??``;break}}if(!s)for(let e of n.values()){let t=e.find(e=>st(e.path)===o);if(t?.branch){s=t.branch;break}}return s?`${a} · ${s}`:a},tS=()=>{let{results:e,dropdownProviderIds:t,displayMode:n}=ps.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 e of Go){if(!t.includes(e.id))continue;let n=i.get(e.id);if(!n||n.configured!==!0)continue;let o=[];for(let[e,t]of Object.entries(n.usage?.windows??{})){let n=r===`remaining`?t.remainingPercent:t.usedPercent;o.push({label:ja(e),value:Sa(t.valueLabel,n)})}let s=!n.ok&&n.error?n.error:o.length===0?`No rate limits reported`:null;a.push({provider:e.name,rows:o,status:s})}return{mode:r,groups:a}},nS=async()=>{try{if(D())return`Local OpenChamber`;let e=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,t=d();if(t&&ne(t,e))return`Local OpenChamber`;let n=(await ie()).hosts.find(e=>t?ne(t,re(e)):!1);return n?.label?.trim()?W(n.label.trim()):`Instance`}catch{return``}},rS=()=>{let e=new Map,t=new Map,n=[],r=new Map,i;try{i=zt()}catch{return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}}for(let[a,o]of i.children.entries()){let i=o.getState();i.vcs?.branch&&t.set(st(a)??a,i.vcs.branch);for(let e of i.session)e?.id&&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:Xx(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:Zx(r),directory:a})}}return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}},iS=()=>{let e=Rt.getState().activeSessions,t=new Set;e.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>Qx(t)-Qx(e)).slice(0,Jx).forEach(e=>{let n=It(e);n&&t.add(n)});let n=new Map;for(let r of e){if(!r?.id)continue;let e=It(r);if(!e||!t.has(e))continue;let i=n.get(e)??[];i.push(r.id),n.set(e,i)}return n},aS=e=>{let t=rS(),n=Qe.getState().index.session,r=Rt.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=Nt.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=qt.getState().projects,d=Pt.getState().availableWorktreesByProject,f=r.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>Qx(t)-Qx(e)).slice(0,Jx).map(e=>{let r=[e.id,...o(e.id)],i=It(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:eS(i,u,d,t.branchByDirectory)}}),p=t.approvals.map(e=>({...e,sessionTitle:i.get(e.sessionId)||``})),m=K.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:tS(),dockBadgeCount:h}},oS=()=>{Q.useEffect(()=>{if(!Yx()||!b())return;let e=!1,t=``,n=null,r=``,i=()=>{if(e)return;let n=aS(r),i=JSON.stringify(n);i!==t&&(t=i,ee(`desktop_tray_update`,n))};nS().then(t=>{e||(r=t,i())});let a=null,o=``,s=()=>{let e=Et.getState();return e.isConnected&&e.connectionPhase===`connected`},c=()=>{if(a)return a;let t=iS();return o=Ux(t),a=Wx({targets:t,isReady:s,concurrency:2,isDisposed:()=>e,fetchStatus:e=>Ee.getSessionStatusForDirectory(e).catch(()=>null),applySnapshot:(e,t,n)=>{kn(e,t,[...n])}}).finally(()=>{a=null;let t=iS();!e&&s()&&Ux(t)!==o&&c()}),a},l=()=>{e||n!==null||(n=window.setTimeout(()=>{n=null,i()},qx))},u=new Map,d=()=>{if(e)return;let t;try{t=zt()}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=zt().subscribeRegistry(()=>{d(),l()})}catch{}d();let p=Qe.subscribe(()=>l()),m=Rt.subscribe(()=>{l(),s()&&Ux(iS())!==o&&c()}),h=qt.subscribe(()=>l()),g=Pt.subscribe(()=>l()),_=Wa.subscribe(()=>l()),v=K.subscribe(()=>l()),y=Nt.subscribe(()=>l()),x=s(),S=Et.subscribe(()=>{let e=s();e&&!x&&c(),x=e});x&&c();let C=ps.subscribe(()=>l());ps.getState().loadSettings().then(()=>{if(e)return;let{dropdownProviderIds:t,results:n}=ps.getState();t.length>0&&t.some(e=>!n.some(t=>t.providerId===e))&&ps.getState().fetchAllQuotas()});let w=window.setInterval(()=>{let e=ps.getState();e.autoRefresh&&e.dropdownProviderIds.length>0&&e.fetchAllQuotas()},Math.max(3e4,ps.getState().refreshIntervalMs||6e4)),T=window.setInterval(()=>{d(),i()},Kx);return i(),()=>{e=!0,n!==null&&window.clearTimeout(n),window.clearInterval(T),window.clearInterval(w),p(),m(),h(),g(),_(),v(),y(),S(),C(),f?.();for(let e of u.values())e();u.clear()}},[]),Q.useEffect(()=>{if(!Yx()||typeof window>`u`)return;let e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!=`function`)return;let t=e=>{e.type===`respond-permission`&&$e(e.sessionId,e.id,e.response).catch(()=>{J.error(`Failed to respond to permission request`)})},n=null;return e(Gx,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{}}},[])},sS=`/api/notifications/stream`,cS=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),lS=e=>{if(!e||typeof e!=`object`)return null;let t=e,n=t.properties&&typeof t.properties==`object`?t.properties:null;return t.type!==`openchamber:notification`||!n?null:{title:typeof n.title==`string`?n.title:void 0,body:typeof n.body==`string`?n.body:void 0,tag:typeof n.tag==`string`?n.tag:void 0,requireHidden:n.requireHidden===!0||n.requireHidden!==!1&&void 0}},uS=e=>{let t=(0,zc.c)(3),n=e?.enabled??!0,r,i;t[0]===n?(r=t[1],i=t[2]):(r=()=>{if(!n||E()||!A()||typeof window>`u`||typeof EventSource>`u`)return;let e=new EventSource(s().sse(sS));return e.onmessage=dS,()=>{e.close()}},i=[n],t[0]=n,t[1]=r,t[2]=i),Q.useEffect(r,i)};function dS(e){let t;try{t=JSON.parse(e.data)}catch{return}let n=K.getState();if(!n.nativeNotificationsEnabled)return;let r=lS(t);r&&((r.requireHidden??n.notificationMode!==`always`)&&cS()||U()?.notifications?.notifyAgentCompletion(r))}var fS=`pwa-install-toast-shown`,pS=`pwa-install-toast-dismissed`,mS=()=>{let e=(0,zc.c)(6),{browserTab:t}=os(),{t:n}=qe(),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`||!A()||!t)return;let e=null,n=null,i=()=>{n!==null&&(J.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`&&J.success(r.current(`pwa.installPrompt.started`))},o=t=>{let o=t;if(typeof o.prompt!=`function`)return;o.preventDefault(),e=o;let s=Ae(),c=Me();Xs({dismissed:s.getItem(pS),sessionShown:c.getItem(fS),hasActiveToast:n!==null})&&(c.setItem(fS,`true`),n=J.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:()=>{Ae().setItem(pS,`true`),i()}}}))},s=()=>{e=null,i(),J.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)},hS=()=>typeof window>`u`?``:window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,gS=()=>!O()||l()===`local`,_S=e=>({id:`local`,label:`Local`,url:e}),vS=async()=>{if(!O()||gS())return{ok:!0};let e=hS(),t=await G().catch(()=>``),n=await da({host:_S(e),localApiOrigin:e,localClientToken:t});return n.ok?{ok:!0}:{ok:!1,reason:n.reason}},yS=100,bS=1e4,xS=null,SS=()=>{xS&&=(xS.unsubscribe?.(),xS.openTimer!==null&&clearTimeout(xS.openTimer),xS.timeoutTimer!==null&&clearTimeout(xS.timeoutTimer),null)};function CS(){SS()}var wS=(e,t)=>{K.getState().setActiveMainTab(`chat`),Pt.getState().setCurrentSession(e,t)};function TS(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;if(gS()){wS(t,n);return}SS(),vS().then(e=>{if(!e.ok){kt(t,`missing-directory`);return}if(l()===`local`){wS(t,n);return}let r=!1,i=()=>{r||(r=!0,SS(),wS(t,n))},a=o(e=>{if(e.runtimeKey!==`local`)return;a(),xS&&(xS.unsubscribe=null);let t=setTimeout(()=>{xS&&(xS.openTimer=null),i()},yS);xS&&(xS.openTimer=t)});xS={unsubscribe:a,openTimer:null,timeoutTimer:setTimeout(()=>{r||(SS(),kt(t,`missing-directory`))},bS)}})}var ES=({open:e,onOpenChange:t})=>{let{t:n}=qe(),[r,i]=Q.useState(null),[a,o]=Q.useState(null),[s,c]=Q.useState(!1),[l,u]=Q.useState(!1),[d,p]=Q.useState(null),[m,h]=Q.useState(!1),[g,_]=Q.useState(!1),[v,y]=Q.useState(()=>_n()),b=He(e=>{cn(e),y(e)}),x=He(async()=>{if(!g){_(!0);try{let{outcome:e,eventCount:t}=await Bt();if(e===`cancelled`)return;if(e===`failed`){J.error(n(`settings.openchamber.about.diagnostics.toast.failed`));return}J.success(n(t>0?`settings.openchamber.about.diagnostics.toast.exported`:`settings.openchamber.about.diagnostics.toast.empty`))}catch{J.error(n(`settings.openchamber.about.diagnostics.toast.failed`))}finally{_(!1)}}});Q.useCallback(async()=>{},[d,s,!1,n]),Q.useEffect(()=>{e&&(async()=>{try{let e=await f(`/api/system/info`);if(e.ok){let t=await e.json();if(typeof t.openchamberVersion==`string`&&t.openchamberVersion.trim()){i(t.openchamberVersion);return}}}catch{}i(await Ge())})()},[e]),Q.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await f(`/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]),Q.useEffect(()=>{p(null),h(!1)},[e,!1]);let S=r;return(0,$.jsx)(Vn,{open:e,onOpenChange:t,children:(0,$.jsx)(Rn,{className:`max-w-xs p-6`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,$.jsx)(Ta,{width:64,height:64}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:`OpenChamber`}),(0,$.jsxs)(`div`,{className:`space-y-0.5 typography-meta text-muted-foreground`,children:[S&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openChamberVersionLabel`,{version:S})}),a&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openCodeVersionLabel`,{version:a})})]})]}),(0,$.jsxs)(`div`,{className:`flex w-full flex-col items-stretch gap-3 pt-2`,children:[(0,$.jsx)(es,{itemId:`about.diagnostics`,checked:v,onChange:b,label:n(`settings.openchamber.about.diagnostics.label`),ariaLabel:n(`settings.openchamber.about.diagnostics.label`)}),v&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`sm`,disabled:g,onClick:()=>void x(),children:n(g?`settings.openchamber.about.diagnostics.exporting`:`settings.openchamber.about.diagnostics.export`)})]}),!1,(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-4`,children:[(0,$.jsxs)(`a`,{href:`https://github.com/yee94/openchamber`,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)(X,{name:`github-fill`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:`GitHub`})]}),(0,$.jsxs)(`a`,{href:`https://discord.gg/ZYRSdnwwKA`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors`,children:[(0,$.jsx)(X,{name:`discord-fill`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:`Discord`})]})]}),(0,$.jsxs)(`a`,{href:`https://x.com/openchamber_dev`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors`,children:[(0,$.jsx)(X,{name:`twitter-xfill`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:`@openchamber_dev`})]})]}),(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground/60 pt-2`,children:n(`aboutDialog.footerNote`)})]})})})},DS=(e,t)=>{let n=e.get(t);return typeof n==`string`&&n.trim()||null},OS=(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 OpenChamber and click Authorize again.`:n},kS=()=>{let e=ns(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=DS(t,`code`),a=Xo(t),o=Zo(t),s=DS(t,`error`),c=DS(t,`error_description`);if(s){o&&f(`/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 OpenChamber manually.`);let t=a;if(!t&&o){let e=await f(`/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 OpenChamber manually.`);await e(t.name,r,t.directory),o&&await f(`/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 OpenChamber.`)}catch(e){o&&await f(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(OS(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)(Z,{type:`button`,onClick:()=>{typeof window>`u`||window.location.replace(`/`)},children:`Return to OpenChamber`})})]})})},AS=()=>{let e=(0,zc.c)(16),t=Rt(jS),n=Rt(MS),r=Rt(NS),i=Rt(PS),{t:a}=qe(),o;e[0]!==r||e[1]!==i?(o=i>0?Math.round(r/i*100):0,e[0]=r,e[1]=i,e[2]=o):o=e[2];let s=o,c;e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(c=n===`restoring`?a(`common.loading`):a(`sessions.startupSync.progress`,{completed:r,total:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=c):c=e[7];let l=c,u,d;return e[8]!==t||e[9]!==r||e[10]!==s||e[11]!==l||e[12]!==a||e[13]!==i?(u=()=>{let e=document.getElementById(`startup-session-progress`),n=document.getElementById(`startup-session-progress-track`),o=document.getElementById(`startup-session-progress-fill`),c=document.getElementById(`startup-session-progress-text`);!e||!n||!o||!c||(e.hidden=!t,t&&(o.style.width=`${s}%`,n.setAttribute(`aria-label`,a(`sessions.startupSync.title`)),n.setAttribute(`aria-valuemax`,String(Math.max(i,1))),n.setAttribute(`aria-valuenow`,String(r)),n.setAttribute(`aria-valuetext`,l),c.textContent=l))},d=[t,r,s,l,a,i],e[8]=t,e[9]=r,e[10]=s,e[11]=l,e[12]=a,e[13]=i,e[14]=u,e[15]=d):(u=e[14],d=e[15]),Q.useLayoutEffect(u,d),null};function jS(e){return e.startupSyncProgress.active}function MS(e){return e.startupSyncProgress.phase}function NS(e){return e.startupSyncProgress.completed}function PS(e){return e.startupSyncProgress.total}var FS=(e,t,n,r=350)=>n?Math.max(0,r-Math.max(0,t-e)):null;function IS(e){let t=(0,zc.c)(21),{transition:n,ready:r}=e,{t:i}=qe(),a=ma(),[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=FS(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)(Ta,{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 LS=no(()=>Pe(()=>import(`./OnboardingScreen-j0iCyH7f.js`).then(e=>({default:e.OnboardingScreen})),__vite__mapDeps([108,1,2,3,4,24,7,5,6,25,8,26,70,23,27,10,29,30,31,32,33,78]))),RS=36e5,zS=12e5,BS=()=>{let e=(0,zc.c)(3),t=K(qS),n=K(JS),r;return e[0]!==t||e[1]!==n?(r=(0,$.jsx)(ES,{open:t,onOpenChange:n}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r},VS=e=>{let t=(0,zc.c)(21),{onRetry:n,isRetrying:r}=e,{t:i}=qe(),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)(Z,{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},HS=e=>e?e.replace(/\\/g,`/`).replace(/\/+$/g,``):``,US=()=>{if(typeof window>`u`||!Er())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`}},WS=()=>typeof window>`u`?!1:window.location.pathname===cs,GS=e=>{let t=(0,zc.c)(22),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=e,a=xe(YS),o=Pt(XS),s=Pt(ZS),c=Kr(),l=Q.useRef(null),u;t[0]===n.directory?u=t[1]:(u=HS(n.directory),t[0]=n.directory,t[1]=u);let d=u,f;t[2]===a?f=t[3]:(f=HS(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)(pi,{embeddedBackgroundWorkEnabled:i}),t[14]=i,t[15]=g);let _;t[16]===n.readOnly?_=t[17]:(_=(0,$.jsx)(uc,{readOnly:n.readOnly}),t[16]=n.readOnly,t[17]=_);let v;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(br,{}),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 KS({apis:e}){Q.useEffect(()=>{De(`App:mounted`),we()},[]),Q.useEffect(()=>An(),[]);let t=Et(e=>e.initializeApp),n=Et(e=>e.isInitialized),r=Et(e=>e.isConnected),i=Pt(e=>e.error),a=Pt(e=>e.clearError),s=Pt(e=>e.currentSessionId),u=Pt(e=>!!e.newSessionDraft?.open),d=xe(e=>e.currentDirectory),f=xe(e=>e.setDirectory),p=xe(e=>e.isSwitchingDirectory),[m,h]=Q.useState(!1),_=ds(e=>e.refreshStatus),[b,x]=Q.useState(()=>e.runtime.isVSCode),[C,O]=Q.useState(!1),[k,A]=Q.useState(!1),[j,M]=Q.useState(0),[N,P]=Q.useState(0),[F,I]=Q.useState({epoch:0,startedAt:0}),[L,R]=Q.useState(!1),z=Q.useRef(!1),B=K(e=>e.wideChatLayoutEnabled),H=K(e=>e.mobileKeyboardMode),U=Q.useMemo(()=>E(),[]),ne=Rt(e=>e.hasCachedSessionIndex),W=Rt(e=>e.hasHydratedSessionIndex),[re,G]=Q.useState(()=>te()),[ie,ae]=Q.useState(()=>{let e=T();return e===null?null:y({isDesktopShell:!0,bootOutcome:e})}),oe=Q.useRef(!1),se=Q.useMemo(()=>US(),[]),ce=!se||C,le=Q.useMemo(()=>WS(),[]);Q.useEffect(()=>(Se(m),()=>{Se(!1)}),[m]),Q.useEffect(()=>{je(H)},[H]),Q.useEffect(()=>{x(e.runtime.isVSCode)},[e.runtime.isVSCode]),Q.useEffect(()=>{let e=Bi(e=>{c(e)&&(U&&I(e=>({epoch:e.epoch+1,startedAt:Date.now()})),tc(e),P(e=>e+1),A(!1),M(e=>e+1))}),t=o(t=>e.schedule(t));return()=>{t(),e.cancel()}},[U]);let ue=pt(e=>{let t=l();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(se)return;let e=!1;return tt().then(()=>{if(e)return;let t=l(),n=Object.values(pt.getState().runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t);for(let e of n)_t(e.originalSessionID)}),()=>{e=!0}},[ue,se,N]),Q.useEffect(()=>(document.documentElement.classList.toggle(`wide-chat-layout`,B),()=>{document.documentElement.classList.remove(`wide-chat-layout`)}),[B]),Q.useEffect(()=>(w(e),()=>w(null)),[e]),Q.useEffect(()=>{if(se)return;let t=!1;return tt().then(()=>{t||_(e.github,{force:!0})}),()=>{t=!0}},[e.github,se,_]),Oi();let de=re===`valid`,fe=ie?.screen===`main`;Q.useEffect(()=>{if(!ce||!g({isDesktopShell:U,isInitialized:U&&fe?ne||n&&W: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)}},[ce,U,n,de,fe,ne,W]),Q.useEffect(()=>{if(!U||re!==`malformed`)return;let e=document.getElementById(`initial-loading`);e&&(e.textContent=`Desktop startup failed — please restart the app.`)},[U,re]),Q.useEffect(()=>{if(!ce||U)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)}},[ce,U,n]),Q.useEffect(()=>{if(!ce||b)return;let e=!1;return tt().then(()=>{if(!e)return t()}),()=>{e=!0}},[ce,t,b]),Q.useEffect(()=>{if(!ce||b||n)return;let e=!0,t,r=0,i=1e3,a=async()=>{if(!e)return;if(r>=10){A(!0);return}let n=Et.getState();if(n.isInitialized){A(!1);return}if(r+=1,await tt(),!e)return;await n.initializeApp();let o=Et.getState();if(!e)return;if(o.isInitialized){A(!1);return}if(r>=10){A(!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)}},[ce,j,n,b]),Q.useEffect(()=>{ce&&n&&A(!1)},[ce,n]),Q.useEffect(()=>{if(!ce||!k)return;let e=document.getElementById(`initial-loading`);if(e){e.classList.add(`fade-out`);let t=setTimeout(()=>{e.remove()},300);return()=>clearTimeout(t)}},[ce,k]),qr({enabled:ce&&!b,source:`startupRecovery`}),Q.useEffect(()=>{p||b||r&&Ee.setDirectory(d)},[d,p,r,b]),Q.useEffect(()=>{if(!se||typeof window>`u`)return;let e=e=>{let t=e?.visible===!0;O(t)},t=t=>{if(t.origin!==window.location.origin)return;let n=t.data;n?.type===`openchamber:embedded-visibility`&&e(n.payload)},n=window;return n.__openchamberSetEmbeddedVisibility=e,window.addEventListener(`message`,t),window.parent&&window.parent!==window&&window.parent.postMessage({type:zr},window.location.origin),()=>{window.removeEventListener(`message`,t),n.__openchamberSetEmbeddedVisibility===e&&delete n.__openchamberSetEmbeddedVisibility}},[se]),Q.useEffect(()=>{!se?.directory||b||d!==se.directory&&f(se.directory,{showOverlay:!1})},[d,se,b,f]),Q.useEffect(()=>{if(!se||typeof window>`u`)return;let e=e=>{e.storageArea===window.localStorage&&e.key===`ui-store`&&K.persist.rehydrate()};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}},[se]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;TS(t??{})},t=e=>{let t=e.detail?.assistantID;typeof t==`string`&&t.trim()&&Fn(t.trim())};return window.addEventListener(`openchamber:open-session`,e),window.addEventListener(`openchamber:open-assistant`,t),()=>{CS(),window.removeEventListener(`openchamber:open-session`,e),window.removeEventListener(`openchamber:open-assistant`,t)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=xe.getState().currentDirectory,{activeProjectId:t,projects:n}=qt.getState(),r=n.find(e=>e.id===t)??null;ee(`desktop_open_draft_mini_chat_window`,{directory:e||r?.path||``,projectId:r?.id??null})};return window.addEventListener(`openchamber:open-mini-chat`,e),()=>window.removeEventListener(`openchamber:open-mini-chat`,e)},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=Pt.getState().currentSessionId;e&&Zt(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;K.getState().setActiveMainTab(`chat`),K.getState().setSessionSwitcherOpen(!1),Pt.getState().openNewSessionDraft({selectedProjectId:r,directoryOverride:n,preserveDirectoryOverride:!!n,ensureProjectForDirectory:!!n,initialPrompt:i})};return window.addEventListener(`openchamber:open-draft-session`,e),()=>window.removeEventListener(`openchamber: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=qt.getState(),i=r.projects.find(e=>e.path===n);i?r.setActiveProject(i.id):r.addProject(n)};return window.addEventListener(`openchamber:open-project`,e),()=>window.removeEventListener(`openchamber:open-project`,e)},[]),Q.useEffect(()=>{typeof window>`u`||!ce||!n||p||oe.current||(oe.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event(`openchamber:app-ready`)))},[ce,n,p]),yr({enabled:ce}),uS({enabled:ce}),mS(),Gr(),fc(),Vx(He(()=>{h(e=>!e)})),Q.useEffect(()=>{if(!n||!S()||z.current)return;z.current=!0;let e=!1,t=null,r=null;qo.getState().subscribeDesktopUpdateEvents().then(t=>{if(e){t();return}r=t});let i=()=>{let e=qo.getState();e.checking||e.checkForUpdates()},a=n=>{t=window.setTimeout(()=>{e||(document.visibilityState===`visible`&&i(),a(RS))},n)},o=()=>{if(e||document.visibilityState!==`visible`)return;let t=qo.getState().lastChecked;t!=null&&Date.now()-t<zS||i()};return a(0),window.addEventListener(`focus`,o),()=>{e=!0,t!==null&&window.clearTimeout(t),window.removeEventListener(`focus`,o),r&&r()}},[n]),oS(),Q.useEffect(()=>{if(se)return;let e=e=>{Kn(e)&&e.shiftKey&&!e.altKey&&(e.code===`KeyD`||e.key.toLowerCase()===`d`)&&(e.preventDefault(),h(e=>!e))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[se]),Q.useEffect(()=>{se||i&&setTimeout(()=>a(),5e3)},[a,se,i]),Q.useEffect(()=>{if(!U||re!==`not-injected`)return;let e=!1,t=0,n=()=>{if(e)return;t++;let r=te();if(r!==`not-injected`){if(e=!0,G(r),r===`valid`){let e=T();e&&ae(y({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}},[U,re]);let pe=He(async()=>{if(v({isDesktopShell:E(),isDesktopLocalOriginActive:D()})){await V();return}window.location.reload()}),me=He(async()=>{if(!L){A(!1),R(!0);try{await tt(),await Et.getState().initializeApp()}finally{R(!1)}Et.getState().isInitialized||M(e=>e+1)}}),he=e=>{if(e.screen===`recovery`)return e.variant};if(U&&ie&&ie.screen!==`main`){if(ie.screen===`chooser`)return(0,$.jsx)(Ca,{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)(LS,{mode:`first-launch`,onCliAvailable:pe,onChooseRemote:()=>{}})})})});let e=he(ie),t=ie.screen===`recovery`&&`url`in ie?ie.url:void 0;return(0,$.jsx)(Ca,{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)(LS,{mode:`recovery`,recoveryVariant:e,recoveryHostUrl:t,recoveryHostLabel:void 0,onCliAvailable:pe})})})})}if(se)return nt(),(0,$.jsx)(Ca,{children:(0,$.jsx)(ct,{sdk:Ee.getSdkClient(),directory:d||``,bootstrapDirectory:!(u&&s===null),children:(0,$.jsx)(Pi,{apis:e,children:(0,$.jsx)(ia,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-background`,children:(0,$.jsx)(GS,{embeddedSessionChat:se,isVSCodeRuntime:b,embeddedBackgroundWorkEnabled:ce})})})})},N)});if(le)return(0,$.jsx)(Ca,{children:(0,$.jsx)(kS,{})});if(k&&!n&&!b&&!se)return(0,$.jsx)(Ca,{children:(0,$.jsx)(VS,{onRetry:()=>{me()},isRetrying:L})});let ge=!n&&!U;return(0,$.jsx)(Ca,{children:(0,$.jsx)(ct,{sdk:Ee.getSdkClient(),directory:d||``,bootstrapDirectory:!(u&&s===null),children:(0,$.jsx)(Pi,{apis:e,children:(0,$.jsx)(Au,{children:(0,$.jsx)(ia,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsxs)(`div`,{className:U?`h-full text-foreground bg-transparent`:`h-full text-foreground bg-background`,children:[(0,$.jsx)(pi,{embeddedBackgroundWorkEnabled:ce}),(0,$.jsx)(Bs,{}),(0,$.jsx)(cc,{}),(0,$.jsx)(vx,{}),U&&(0,$.jsx)(IS,{transition:F,ready:n&&r}),(0,$.jsx)(AS,{}),(0,$.jsx)(br,{}),!ge&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nc,{}),(0,$.jsx)(BS,{}),m&&(0,$.jsx)(Sx,{onClose:()=>h(!1)})]})]})})})})},N)})}function qS(e){return e.isAboutDialogOpen}function JS(e){return e.setAboutDialogOpen}function YS(e){return e.currentDirectory}function XS(e){return e.currentSessionId}function ZS(e){return e.setCurrentSession}if(typeof window<`u`&&!window.__OPENCHAMBER_REFRESH_DEBUG_INSTALLED__){window.__OPENCHAMBER_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 QS=typeof window<`u`&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw Error(`Runtime APIs not provided for legacy UI entrypoint.`)})();Ze(),E()&>(),Xr({runtimeKey:l(),initializeAppearance:B,syncSettings:F,applyDirectory:kr,startWatchers:()=>{_i(),Vr(),Sr()},onError:(e,t)=>{console.error(e===`appearance`?`[main] appearance init failed:`:`[main] settings init failed:`,t)}});var $S=document.getElementById(`root`);if(!$S)throw Error(`Root element not found`);(0,Rc.createRoot)($S).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(wr,{children:(0,$.jsx)(Ke,{children:(0,$.jsx)(_r,{children:(0,$.jsx)(jr,{children:(0,$.jsx)(Fr,{children:(0,$.jsx)(KS,{apis:QS})})})})})})}));
|