@openchambery/web 1.18.2-beta.2 → 1.18.2-beta.21
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-B2kZjgaf.js → AgentAvatar-B4fj9PIe.js} +1 -1
- package/dist/assets/{AssistantView-DvoyOGkx.js → AssistantView-C00aiEHK.js} +1 -1
- package/dist/assets/{ChatContainer-D6yfuigV.js → ChatContainer-BDFeDKu-.js} +39 -39
- package/dist/assets/{DiagramView-MGGo9iME.js → DiagramView-CUfSFI3e.js} +1 -1
- package/dist/assets/{FadeInOnReveal-aeWlaqVB.js → FadeInOnReveal-CKKU6fKI.js} +1 -1
- package/dist/assets/{Icon-AXqa-fYB.js → Icon-DiIuWOuC.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-jVOkZkyX.js → MarkdownRendererImpl-Cen6E9Lj.js} +2 -2
- package/dist/assets/{MobileDetailNavigation-Q2IzHqGA.js → MobileDetailNavigation-DILi0tN7.js} +1 -1
- package/dist/assets/{MobileShareBridge-apXM34Lb.js → MobileShareBridge-PZMRiieI.js} +1 -1
- package/dist/assets/MobileSurface-BLYcR0tO.js +2 -0
- package/dist/assets/{MultiRunWindow-B-l_O-bd.js → MultiRunWindow-D_2mWZyv.js} +1 -1
- package/dist/assets/{OnboardingScreen-CUsgwt4y.js → OnboardingScreen-CYeRZznl.js} +1 -1
- package/dist/assets/{OverlayScrollbar-D6NySAxi.js → OverlayScrollbar-BgMLtMIq.js} +1 -1
- package/dist/assets/SettingsView-CbDBfQp1.js +25 -0
- package/dist/assets/{SettingsWindow-DfVgTQ4I.js → SettingsWindow-Br7XLcSd.js} +1 -1
- package/dist/assets/{TerminalView-DNyjfkvT.js → TerminalView-CM5jRKlj.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DLG1iThm.js → ToolOutputDialog-D3U6aTZ4.js} +1 -1
- package/dist/assets/appThemeRegistry-CDxBJNNB.js +2 -0
- package/dist/assets/assistant-guide-hero-BeUHQcxE.jpg +0 -0
- package/dist/assets/{button-CDvMVaiO.js → button-DaAoVF4X.js} +1 -1
- package/dist/assets/{clipboard-BW7nk_Cx.js → clipboard-BnElHSnO.js} +1 -1
- package/dist/assets/{collapsible-C2aamDvD.js → collapsible-BmuQu0dq.js} +1 -1
- package/dist/assets/{context-menu-BaxmodD8.js → context-menu-DBOMervd.js} +1 -1
- package/dist/assets/{desktopHosts-CBoBpJ1Z.js → desktopHosts-ZK_vkdzL.js} +1 -1
- package/dist/assets/{desktopRelayRestore-l2R9muux.js → desktopRelayRestore-CewM6-g5.js} +1 -1
- package/dist/assets/{diagram-CEon0BQs.js → diagram-DAE4CZy2.js} +1 -1
- package/dist/assets/{dialog-DjYfj1Sn.js → dialog-COrLBm9O.js} +1 -1
- package/dist/assets/{es-5Lhudh0n.js → es-DIVYdoxi.js} +1 -1
- package/dist/assets/{fileQueries-CE_DaZWQ.js → fileQueries-CmWYnRVz.js} +1 -1
- package/dist/assets/{fr-Q_UhFmKT.js → fr-CNTlVypq.js} +2 -2
- package/dist/assets/{gitApi-BYxg_qGJ.js → gitApi-BQT3QXD2.js} +1 -1
- package/dist/assets/gitApiHttp-BxGAFLTf.js +2 -0
- package/dist/assets/{input-k9DGGyZ6.js → input-XiL2-2gG.js} +1 -1
- package/dist/assets/insertionBoundaries-9a0RuIDc.js +1 -0
- package/dist/assets/{ja-CzMPz7bT.js → ja-C_eW5ZM8.js} +1 -1
- package/dist/assets/{ko-B-EslUsR.js → ko-CE3cOv7v.js} +1 -1
- package/dist/assets/{main-LDphyc-v.js → main-BGfX81Y9.js} +20 -20
- package/dist/assets/{main-CO6z5yRB.js → main-CEqSDnE2.js} +2 -2
- package/dist/assets/{markdown-worker-DkeWiER6.js → markdown-worker-BDyY0vt6.js} +1 -1
- package/dist/assets/{markdownTheme-DNT93i5L.js → markdownTheme-D-aLQZaM.js} +1 -1
- package/dist/assets/{miniChat-BZQwTZpx.js → miniChat-CKucSAhg.js} +2 -2
- package/dist/assets/mobile-C4bTWKry.js +2 -0
- package/dist/assets/{multirun-ZlwlkIy5.js → multirun-DeNtSkgb.js} +1 -1
- package/dist/assets/{persistence-DPNMIbF5.js → persistence-D1lIuyqO.js} +1 -1
- package/dist/assets/{pl-Dnea6Ppc.js → pl-BZKZOE99.js} +1 -1
- package/dist/assets/projectMeta-BunN9pH5.js +3 -0
- package/dist/assets/{pt-BR-Ca6QTem7.js → pt-BR-DHDgp8S3.js} +1 -1
- package/dist/assets/{radio-CJuhbQ5a.js → radio-Bziafaje.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-D8-FDgWE.js +2 -0
- package/dist/assets/renderMobileApp-CdU0aJ-e.js +23 -0
- package/dist/assets/{runtimeConfig-BtWi74Pm.js → runtimeConfig-BXCt7ZsQ.js} +1 -1
- package/dist/assets/runtimeEndpointReset-CK1GhIsm.js +145 -0
- package/dist/assets/{sortable-tabs-strip-D8JHUI0z.js → sortable-tabs-strip-pWlBorwQ.js} +1 -1
- package/dist/assets/src-8kQFmtjw.css +2 -0
- package/dist/assets/{store-wa1ersRf.js → store-CUWqzRt7.js} +2 -2
- package/dist/assets/{terminalApi-tB3qLcfa.js → terminalApi-DpiAJlil.js} +1 -1
- package/dist/assets/{tooltip-DMNR5rN0.js → tooltip-BLugzWq-.js} +1 -1
- package/dist/assets/{uk-xGc9Pzge.js → uk-CfQK6cz1.js} +1 -1
- package/dist/assets/{url-7MqoLs9X.js → url-DMs_PgIC.js} +1 -1
- package/dist/assets/useAppFontEffects-IEUQDvE8.js +7 -0
- package/dist/assets/useDesktopWindowControlsLayout-MlqJX89k.js +1 -0
- package/dist/assets/{useEffectiveDirectory-aUC3zzl_.js → useEffectiveDirectory-GbhkdO6m.js} +1 -1
- package/dist/assets/{useFontPreferences-CIurCeNv.js → useFontPreferences-92Qg-98H.js} +1 -1
- package/dist/assets/useMobileNavigationStore-DQHF_ETu.js +476 -0
- package/dist/assets/useSessionAutoCleanup-BuU_S_Sh.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-CiYQjBe6.js → useWorkerHighlightedLines-Ca6OgNHF.js} +1 -1
- package/dist/assets/{utils-Co19EJEL.js → utils-BxJEIWv5.js} +1 -1
- package/dist/assets/{zh-CN-sL4ktGB3.js → zh-CN-DvY2fKWp.js} +1 -1
- package/dist/assets/{zh-TW-Cfxps4gq.js → zh-TW-eWe0lm3-.js} +1 -1
- 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.d.ts +6 -0
- package/server/index.js +13 -0
- package/server/lib/config-sync/DOCUMENTATION.md +70 -0
- package/server/lib/config-sync/config-sync.test.js +197 -0
- package/server/lib/config-sync/constants.js +39 -0
- package/server/lib/config-sync/contract.js +130 -0
- package/server/lib/config-sync/credential-auth.js +39 -0
- package/server/lib/config-sync/engine.js +108 -0
- package/server/lib/config-sync/index.js +67 -0
- package/server/lib/config-sync/local-backup.js +171 -0
- package/server/lib/config-sync/plan.js +318 -0
- package/server/lib/config-sync/receiver.js +330 -0
- package/server/lib/config-sync/routes.js +141 -0
- package/server/lib/config-sync/routes.test.js +154 -0
- package/server/lib/config-sync/scripts.js +264 -0
- package/server/lib/config-sync/selections.js +112 -0
- package/server/lib/config-sync/tar.js +35 -0
- package/server/lib/config-sync/target-id.js +24 -0
- package/server/lib/event-stream/DOCUMENTATION.md +2 -2
- package/server/lib/event-stream/diff-summary.js +39 -11
- package/server/lib/event-stream/diff-summary.test.js +73 -6
- package/server/lib/event-stream/protocol.test.js +70 -7
- package/server/lib/notifications/DOCUMENTATION.md +2 -2
- package/server/lib/notifications/runtime.js +68 -27
- package/server/lib/notifications/runtime.test.js +176 -0
- package/server/lib/opencode/DOCUMENTATION.md +4 -1
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.test.js +10 -1
- package/server/lib/opencode/openchamber-routes.js +7 -0
- package/server/lib/opencode/settings-runtime.js +82 -51
- package/server/lib/opencode/settings-runtime.test.js +42 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/session-index/DOCUMENTATION.md +12 -6
- package/server/lib/session-index/routes.js +34 -0
- package/server/lib/session-index/routes.test.js +76 -0
- package/server/lib/session-index/service.js +53 -4
- package/server/lib/session-index/service.test.js +72 -2
- package/server/lib/session-title/DOCUMENTATION.md +19 -14
- package/server/lib/session-title/runtime.js +8 -8
- package/server/lib/session-title/runtime.test.js +231 -0
- package/server/lib/session-turn-pages/DOCUMENTATION.md +26 -6
- package/server/lib/session-turn-pages/changes.service.js +156 -0
- package/server/lib/session-turn-pages/changes.service.test.js +188 -0
- package/server/lib/session-turn-pages/reconcile.routes.test.js +52 -0
- package/server/lib/session-turn-pages/reconcile.service.js +3 -1
- package/server/lib/session-turn-pages/reconcile.service.test.js +44 -0
- package/server/lib/session-turn-pages/routes.js +273 -12
- package/server/lib/session-turn-pages/routes.test.js +387 -0
- package/server/lib/session-turn-pages/service.js +31 -7
- package/server/lib/session-turn-pages/service.test.js +40 -0
- package/server/lib/small-model/DOCUMENTATION.md +93 -38
- package/server/lib/small-model/catalog.js +10 -2
- package/server/lib/small-model/catalog.test.js +3 -1
- package/server/lib/small-model/index.js +52 -28
- package/server/lib/small-model/opencode-session.js +339 -0
- package/server/lib/small-model/opencode-session.test.js +177 -0
- package/server/lib/small-model/resolve.js +116 -5
- package/server/lib/small-model/resolve.test.js +76 -10
- package/server/lib/small-model/summary-settings.test.js +60 -3
- package/dist/assets/MobileSurface-htGkf7Ua.js +0 -2
- package/dist/assets/SettingsView-DxMpVLlt.js +0 -25
- package/dist/assets/appThemeRegistry-CgfOR_0L.js +0 -2
- package/dist/assets/gitApiHttp-D8j1qRH4.js +0 -2
- package/dist/assets/insertionBoundaries-DzXMTleb.js +0 -1
- package/dist/assets/mobile-BktO3_4R.js +0 -2
- package/dist/assets/projectMeta-v-LP2mzz.js +0 -3
- package/dist/assets/renderElectronMiniChatApp-Db8uO-6q.js +0 -2
- package/dist/assets/renderMobileApp-BCV81Ryl.js +0 -23
- package/dist/assets/runtimeEndpointReset-Dg3DMy9v.js +0 -145
- package/dist/assets/src-oHrYIqHF.css +0 -2
- package/dist/assets/useAppFontEffects-CM0VKsdo.js +0 -7
- package/dist/assets/useDesktopWindowControlsLayout-Cq-r4Hcb.js +0 -1
- package/dist/assets/useMobileNavigationStore-DnzT4jO2.js +0 -475
- package/dist/assets/useSessionAutoCleanup-DxZeceKO.js +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F as i,L as a,V as o,W as s,b as c,j as l,k as u,n as d,q as f,t as p,w as m,x as h,y as g}from"./useUIStore-5agS8bsW.js";import{$ as _,$t as v,At as y,Cn as b,D as x,Dn as S,En as C,Ft as w,Gt as T,Qt as E,Rt as D,Sn as O,Tn as k,Xt as A,Yt as j,Zt as M,an as N,cn as P,d as F,en as I,et as L,fn as R,in as z,k as B,kn as V,kt as H,n as U,pn as ee,qt as te,r as W,rn as ne,st as G,t as re,un as K,vn as ie,wn as ae,xn as oe}from"./persistence-DPNMIbF5.js";import{f as se,h as ce,l as le,o as ue,r as de}from"./desktopHosts-CBoBpJ1Z.js";import{a as fe,i as pe,t as me}from"./vendor-zustand-B4dlGEM2.js";import{E as he,F as ge,I as _e,N as ve,O as ye,P as be,T as xe,a as Se,i as Ce,nt as we,rt as Te,tt as Ee}from"./vendor-base-ui-CnHfUmDN.js";import{At as De,Ct as Oe,Mt as ke,Ot as Ae,St as je,bt as Me,kt as Ne,xt as q,yt as Pe}from"./gitApiHttp-D8j1qRH4.js";import{o as Fe}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as Ie,t as Le}from"./vendor-react-DLPElpoQ.js";import{l as Re,n as ze,s as Be}from"./vendor-tanstack-react-query-D7pys_c9.js";import{a as Ve,n as He}from"./terminalApi-tB3qLcfa.js";/* empty css */import{W as Ue,ct as We}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{n as Ge,t as Ke,u as qe}from"./vendor-reactuses-core-DDoDDyM9.js";import{a as Je,i as Ye,n as Xe,o as Ze,r as Qe,t as $e}from"./clipboard-BW7nk_Cx.js";import{n as et}from"./store-wa1ersRf.js";import{$i as tt,$n as nt,$t as rt,Aa as it,An as at,At as ot,Bi as st,Bn as ct,Bt as lt,C as ut,Co as dt,Cr as ft,Ct as pt,Dn as mt,Do as ht,En as gt,Eo as _t,Er as vt,Fi as yt,Ft as bt,Hr as xt,Ii as St,It as Ct,Ji as wt,Ki as Tt,Lt as Et,Ma as Dt,Mn as Ot,Na as kt,Nn as At,Pr as jt,Pt as Mt,Qi as Nt,Qt as Pt,Ra as Ft,Rn as It,S as Lt,Tn as Rt,To as zt,Un as Bt,Ur as Vt,Va as Ht,Vt as Ut,Wt,Xr as Gt,Xt as Kt,Yn as qt,Zi as Jt,Zt as Yt,_a as Xt,_r as Zt,ai as Qt,an as $t,b as en,bn as tn,br as nn,ca as rn,ct as an,d as on,da as sn,di as cn,dn as ln,f as un,gn as dn,h as fn,ha as pn,hn as mn,hr as hn,in as gn,jn as _n,kt as vn,l as yn,ln as bn,mo as xn,mr as Sn,ni as Cn,oi as wn,p as Tn,pn as En,pr as Dn,qa as On,qn as kn,ra as An,rn as jn,sa as Mn,tn as Nn,tr as J,u as Pn,ua as Fn,un as In,v as Ln,va as Rn,vr as zn,wo as Bn,wr as Vn,xr as Hn,y as Un,yr as Wn,zn as Gn,zt as Kn}from"./useMobileNavigationStore-DnzT4jO2.js";import{_ as qn}from"./MobileDetailNavigation-Q2IzHqGA.js";import{n as Jn}from"./useAssistantUIStore-Bq3cPj2x.js";import{a as Yn,c as Xn,i as Zn,n as Qn,o as $n,r as er,s as tr,t as Y}from"./utils-Co19EJEL.js";import{n as X,t as nr}from"./Icon-AXqa-fYB.js";import{a as rr,i as ir,n as ar,o as or,r as sr,t as cr}from"./dialog-DjYfj1Sn.js";import{t as Z}from"./button-CDvMVaiO.js";import{A as lr,C as ur,D as dr,O as fr,P as pr,T as mr,a as hr,f as gr,h as _r,i as vr,j as yr,k as br,m as xr,o as Sr,p as Cr,r as wr,t as Tr,w as Er,y as Dr}from"./gitApi-BYxg_qGJ.js";import{$ as Or,A as kr,B as Ar,C as jr,D as Mr,E as Nr,F as Pr,G as Fr,H as Ir,I as Lr,J as Rr,K as zr,L as Br,M as Vr,N as Hr,O as Ur,Q as Wr,R as Gr,S as Kr,U as qr,V as Jr,W as Yr,X as Xr,Y as Zr,_ as Qr,b as $r,c as ei,d as ti,f as ni,g as ri,h as ii,i as ai,j as oi,k as si,l as ci,m as li,n as ui,p as di,q as fi,t as pi,u as mi,v as hi,w as gi,x as _i,y as vi,z as yi}from"./useAppFontEffects-CM0VKsdo.js";import{A as bi,E as xi,N as Si,S as Ci,a as wi,c as Ti,g as Ei,h as Di,i as Oi,j as ki,k as Ai,m as ji,n as Mi,o as Ni,p as Pi,u as Fi,v as Ii,x as Li}from"./projectMeta-v-LP2mzz.js";import{t as Ri}from"./input-k9DGGyZ6.js";import{i as zi,n as Bi,r as Vi,t as Hi}from"./tooltip-DMNR5rN0.js";import{H as Ui,V as Wi,a as Gi,c as Ki,i as qi,m as Ji,p as Yi,s as Xi,u as Zi}from"./useSessionAutoCleanup-DxZeceKO.js";import{n as Qi}from"./useThemeSystem-DMzWVJaW.js";import{D as $i,E as ea,F as ta,G as na,I as ra,K as ia,L as aa,M as oa,N as sa,O as ca,P as la,Q as ua,U as da,V as fa,W as pa,c as ma,f as ha,h as ga,k as _a,n as va,p as ya,r as ba,s as xa,z as Sa}from"./radio-CJuhbQ5a.js";import{i as Ca,o as wa}from"./OverlayScrollbar-D6NySAxi.js";import{x as Ta}from"./markdownTheme-DNT93i5L.js";import{$ as Ea,B as Da,C as Oa,D as ka,E as Aa,F as ja,G as Ma,K as Na,O as Pa,P as Fa,Q as Ia,R as La,S as Ra,T as za,U as Ba,V as Va,Z as Ha,a as Ua,b as Wa,c as Ga,d as Ka,et as qa,f as Ja,h as Ya,i as Xa,k as Za,l as Qa,m as $a,n as eo,o as to,p as no,q as ro,r as io,u as ao,w as oo,x as so,y as co,z as lo}from"./ChatContainer-D6yfuigV.js";import{n as uo,r as fo}from"./useRuntimeAPIs-DSLXJybW.js";import{i as po,n as mo,t as ho,u as go}from"./appThemeRegistry-CgfOR_0L.js";import{_ as _o,g as vo,i as yo,l as bo,n as xo,s as So,t as Co,v as wo,y as To}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{a as Eo,n as Do,o as Oo,s as ko,t as Ao}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as jo}from"./url-7MqoLs9X.js";import{f as Mo,g as No,h as Po,m as Fo,p as Io}from"./markdown-worker-DkeWiER6.js";import{n as Lo,t as Ro}from"./useEffectiveDirectory-aUC3zzl_.js";import{o as zo}from"./FadeInOnReveal-aeWlaqVB.js";import{M as Bo,N as Vo,_ as Ho,b as Uo,d as Wo,g as Go,h as Ko,p as qo,v as Jo,x as Yo,y as Xo}from"./insertionBoundaries-DzXMTleb.js";import{g as Zo}from"./useWorkerHighlightedLines-CiYQjBe6.js";import{t as Qo}from"./sortable-tabs-strip-D8JHUI0z.js";import{t as $o}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{a as es}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as ts,r as ns,t as rs}from"./vendor-framer-motion-DFy_BSVd.js";import{A as is,B as as,C as os,D as ss,H as cs,M as ls,N as us,O as ds,R as fs,T as ps,X as ms,Z as hs,_ as gs,b as _s,d as vs,f as ys,h as bs,j as xs,k as Ss,m as Cs,p as ws,s as Ts,v as Es,w as Ds,x as Os,y as ks,z as As}from"./MobileSurface-htGkf7Ua.js";import{i as js,n as Ms,r as Ns,t as Ps}from"./useDesktopWindowControlsLayout-Cq-r4Hcb.js";import{n as Fs}from"./useFontPreferences-CIurCeNv.js";import{B as Is,D as Ls,E as Rs,F as zs,I as Bs,L as Vs,M as Hs,N as Us,O as Ws,P as Gs,R as Ks,T as qs,V as Js,a as Ys,c as Xs,d as Zs,f as Qs,i as $s,j as ec,k as tc,l as nc,m as rc,n as ic,o as ac,p as oc,r as sc,s as cc,u as lc,w as uc,z as dc}from"./runtimeEndpointReset-Dg3DMy9v.js";import{a as fc,i as pc,n as mc,r as hc,t as gc}from"./context-menu-BaxmodD8.js";import{n as _c,r as vc,t as yc}from"./collapsible-C2aamDvD.js";import{a as bc,o as xc,r as Sc,s as Cc,t as wc}from"./projectActions-CWvNGKfA.js";import{n as Tc,t as Ec}from"./fileQueries-CE_DaZWQ.js";import{t as Dc}from"./diagram-CEon0BQs.js";import{a as Oc,i as kc,n as Ac,o as jc,r as Mc,t as Nc}from"./multirun-ZlwlkIy5.js";import{t as Pc}from"./vendor-zumer-snapdom-yq9vlCKr.js";import{n as Fc,t as Ic}from"./vendor-html-to-image-BDMm2v6d.js";var Q=e(Te(),1),Lc=Le(),Rc=Ie(),$=we();function zc(e){let t=(0,Rc.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 Bc=[{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`}],Vc=`finder`,Hc=new Set([`finder`,`terminal`]),Uc=e=>typeof window<`u`&&window.__OPENCHAMBER_PLATFORM__===`win32`&&e.id===`finder`?{...e,label:`Explorer`,appName:`File Explorer`}:e,Wc=e=>{if(!e)return null;let t=Bc.find(t=>t.id===e)??null;return t?Uc(t):null},Gc=()=>Bc.filter(e=>Hc.has(e.id)).map(e=>({...Uc(e)})),Kc=()=>{if(typeof window>`u`)return Vc;let e=window.localStorage.getItem(`openInAppId`);return e&&Wc(e)?e:Vc},qc=!1,Jc=!1,Yc=!1,Xc=0,Zc=null,Qc=()=>{Zc&&=(clearTimeout(Zc),null)},$c=fe()((e,t)=>({selectedAppId:Kc(),availableApps:Gc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(qc||typeof window>`u`)return;qc=!0;let n=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:Gc(),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:Bc.filter(e=>r.has(e.appName)||Hc.has(e.id)).map(e=>({...Uc(e),iconDataUrl:i.get(e.appName)})),hasLoadedApps:!0})},r=async i=>{if(!A()||!j()||Jc||t().hasLoadedApps&&!i)return;let a=Bc.map(e=>e.appName);Qc(),i&&e({hasLoadedApps:!1}),Jc=!0,Yc=!1,e({isScanning:!0});try{let{apps:t,success:o,hasCache:s,isCacheStale:c}=await D(a,i),l=o&&!s&&t.length===0&&Xc<3;if(e({isCacheStale:s?c:!1}),n(t,o?!l:!1),o){if(l){let e=[800,1600,3200][Xc]??3200;Xc+=1,Yc=!0,Zc=setTimeout(()=>{r()},e);return}Xc=0,Yc=!1;return}if(Xc<3){let e=[1e3,3e3,7e3][Xc]??7e3;Xc+=1,Yc=!0,Zc=setTimeout(()=>{r()},e)}}finally{Jc=!1,Yc||e({isScanning:!1})}};r(),window.addEventListener(`openchamber:settings-synced`,t=>{let n=t.detail,r=n&&typeof n.openInAppId==`string`&&n.openInAppId.length>0&&Wc(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)&&(Xc=3,Yc=!1,e({isScanning:!1,isCacheStale:!1}),n(r))}),window.__openchamberAppReady&&r(),window.setTimeout(()=>{t().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(qc||t().initialize(),!A()||!j()||Jc||t().hasLoadedApps&&!n)return;let r=Bc.map(e=>e.appName);Qc(),n&&e({hasLoadedApps:!1}),Jc=!0,Yc=!1,e({isScanning:!0});try{let{apps:t,hasCache:i,isCacheStale:a}=await D(r,n),o=new Set(t.map(e=>e.name)),s=new Map(t.map(e=>[e.name,e.iconDataUrl??void 0])),c=Bc.filter(e=>o.has(e.appName)||Hc.has(e.id)).map(e=>({...e,iconDataUrl:s.get(e.appName)}));e({availableApps:c.length>0?c:Gc(),hasLoadedApps:c.length>0,isCacheStale:i?a:!1})}finally{Jc=!1,Yc||e({isScanning:!1})}},selectApp:async t=>{Wc(t)&&(e({selectedAppId:t}),typeof window<`u`&&window.localStorage.setItem(`openInAppId`,t),await W({openInAppId:t}))}})),el=`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`,tl=`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`,nl=e=>({...e,fallbackIconDataUrl:e.id===`finder`&&window.__OPENCHAMBER_PLATFORM__!==`win32`?el:e.id===`terminal`?tl:void 0}),rl=e=>{let t=(0,Rc.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},il=e=>{let t=(0,Rc.c)(74),{directory:n,className:r}=e,{t:i}=Xe(),a=$c(al),o=$c(ol),s=$c(sl),c=$c(cl),l=$c(ll),u=$c(ul),d=$c(dl),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=A()&&j(),h;bb0:{let e;t[3]!==o||t[4]!==a?(e=o.find(e=>e.id===a)??o.find(fl)??o[0]??Bc[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=nl(n),t[6]=n,t[7]=e),h=e;break bb0}let r;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(r=nl(Bc[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 N(n,e.id,e.appName)||await z(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 $e(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`,E;t[21]===T?E=t[22]:(E=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]=E);let D;t[23]!==g.label||t[24]!==i?(D=i(`openInApp.actions.openInAria`,{app:g.label}),t[23]=g.label,t[24]=i,t[25]=D):D=t[25];let O;t[26]!==g.fallbackIconDataUrl||t[27]!==g.iconDataUrl||t[28]!==g.label?(O=(0,$.jsx)(rl,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),t[26]=g.fallbackIconDataUrl,t[27]=g.iconDataUrl,t[28]=g.label,t[29]=O):O=t[29];let k;t[30]!==E||t[31]!==D||t[32]!==O||t[33]!==w?(k=(0,$.jsx)(`button`,{type:`button`,onClick:w,className:E,"aria-label":D,children:O}),t[30]=E,t[31]=D,t[32]=O,t[33]=w,t[34]=k):k=t[34];let M;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(M=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]=M):M=t[35];let P;t[36]===i?P=t[37]:(P=i(`openInApp.actions.chooseAppAria`),t[36]=i,t[37]=P);let F;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4`}),t[38]=F):F=t[38];let I;t[39]===P?I=t[40]:(I=(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:M,"aria-label":P,children:F})}),t[39]=P,t[40]=I);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 B;t[44]===i?B=t[45]:(B=i(`openInApp.actions.copyPath`),t[44]=i,t[45]=B);let V;t[46]===B?V=t[47]:(V=(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:B}),t[46]=B,t[47]=V);let H;t[48]!==L||t[49]!==V?(H=(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:L,children:[R,V]}),t[48]=L,t[49]=V,t[50]=H):H=t[50];let U;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(oa,{}),t[51]=U):U=t[51];let ee;if(t[52]!==o||t[53]!==b||t[54]!==g.id){let e;t[56]!==b||t[57]!==g.id?(e=e=>{let t=nl(e);return(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>void b(e),children:[(0,$.jsx)(rl,{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],ee=o.map(e),t[52]=o,t[53]=b,t[54]=g.id,t[55]=ee}else ee=t[55];let te;t[59]!==s||t[60]!==u||t[61]!==i?(te=s?(0,$.jsxs)(ca,{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]=te):te=t[62];let W;t[63]!==H||t[64]!==ee||t[65]!==te?(W=(0,$.jsxs)($i,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[H,U,ee,te]}),t[63]=H,t[64]=ee,t[65]=te,t[66]=W):W=t[66];let ne;t[67]!==I||t[68]!==W?(ne=(0,$.jsxs)(ea,{children:[I,W]}),t[67]=I,t[68]=W,t[69]=ne):ne=t[69];let G;return t[70]!==k||t[71]!==ne||t[72]!==C?(G=(0,$.jsxs)(`div`,{className:C,children:[k,ne]}),t[70]=k,t[71]=ne,t[72]=C,t[73]=G):G=t[73],G};function al(e){return e.selectedAppId}function ol(e){return e.availableApps}function sl(e){return e.isCacheStale}function cl(e){return e.isScanning}function ll(e){return e.initialize}function ul(e){return e.loadInstalledApps}function dl(e){return e.selectApp}function fl(e){return e.id===Vc}var pl=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],ml=[`dev`,`start`,`preview`,`serve`];async function hl(e,t,n){if(!e)return null;let r=vl(t);if(r)return{command:r.command,label:r.name||`Start Preview`,actionId:r.id};if(n){let t=yl(n);if(t){let n=await bl(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 gl(e)){let e=await _l(),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 gl(e){let t=await xl(`${e}/index.html`,e);return typeof t==`string`&&t.trim().length>0}async function _l(){try{let e=await V(`/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 vl(e){for(let t of e){let e=`${t.name} ${t.command}`.toLowerCase();if(ml.some(t=>e.includes(t)))return t}return null}function yl(e){for(let{pattern:t}of pl)for(let n of Object.keys(e))if(t.test(n))return n;return null}async function bl(e){let t=await xl(`${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 xl(`${e}/${t}`,e);if(typeof r==`string`&&r.trim().length>0)return n}return`npm`}async function xl(e,t){if(t?.trim())try{let n=new URLSearchParams({path:e,directory:t,optional:`true`}),r=await V(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(r.ok)return r.text()}catch{}let n=oe()?.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 V(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:`no-store`});return t.ok?t.text():null}catch{return null}}async function Sl(e){try{let t=await xl(`${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 Cl=e=>new Promise(t=>{window.setTimeout(t,e)}),wl=RegExp(`\x1B\\[[0-9;?]*[ -/]*[@-~]`,`g`),Tl=/https?:\/\/[^\s<>'"`]+/gi,El=`__openchamber_auto_discover_preview__`,Dl=15e3,Ol=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},kl=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}},Al=e=>{let t=e.replace(wl,``).match(Tl);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},jl=({projectRef:e,directory:t,className:n,compact:r=!1,allowMobile:i=!1})=>{let{t:a}=Xe(),{terminal:o,runtime:s}=uo(),{isMobile:c}=Ca(),l=Q.useMemo(()=>A(),[]),u=ps(e=>e.instances),d=ps(e=>e.load),f=p(e=>e.setBottomTerminalOpen),m=p(e=>e.setActiveMainTab),h=p(e=>e.setSettingsPage),g=p(e=>e.setSettingsDialogOpen),_=p(e=>e.setSettingsProjectsSelectedId),v=p(e=>e.openContextPreview),y=Fs(e=>e.sessions),b=Fs(e=>e.ensureDirectory),x=Fs(e=>e.setTabLabel),S=Fs(e=>e.setTabIconKey),C=Fs(e=>e.setActiveTab),w=Fs(e=>e.setConnecting),T=Fs(e=>e.setTabSessionId),E=Fs(e=>e.setTabPreviewUrl),D=Fs(e=>e.projectActionRuns),O=Fs(e=>e.setProjectActionRun),k=Fs(e=>e.updateProjectActionRunStatus),j=Fs(e=>e.removeProjectActionRun),[M,N]=Q.useState([]),[P,F]=Q.useState(null),[I,L]=Q.useState(!1),R=Q.useRef({}),z=Q.useRef({}),B=Q.useRef({}),V=Q.useRef({}),H=Q.useRef(0),U=e?.id??null,ee=e?.path??``,te=Q.useMemo(()=>U?{id:U,path:ee}:null,[U,ee]);Q.useEffect(()=>{l&&d().catch(()=>void 0)},[l,d]);let W=Q.useCallback(async e=>{await jo(e)},[]),ne=Q.useCallback(async()=>{if(!te)return;let e=H.current+1;H.current=e,L(!0);try{let t=await Ot(te);if(H.current!==e)return;let n=t.actions;N(n),F(e=>e===El||e&&n.some(t=>t.id===e)?e:null)}catch{if(H.current!==e)return}finally{H.current===e&&L(!1)}},[te]),G=Q.useMemo(()=>bc(t||te?.path||``),[t,te?.path]),re=Q.useMemo(()=>P?M.find(e=>e.id===P)??null:null,[M,P]),K=Q.useMemo(()=>({id:El,name:a(`projectActions.actions.autoDiscover`),command:``,icon:`search`,autoOpenUrl:!0}),[a]),ie=!c,ae=Q.useMemo(()=>ie?[K,...M]:M,[M,K,ie]);Q.useEffect(()=>{ne()},[ne]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;U&&(t?.projectId&&t.projectId!==U||ne())};return window.addEventListener(wc,e),()=>{window.removeEventListener(wc,e)}},[ne,U]),Q.useEffect(()=>{P&&(P===El&&ie||M.some(e=>e.id===P)||F(null))},[M,ie,P]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=y.get(t.directory)?.tabs.find(e=>e.id===t.tabId);(!n||n.terminalSessionId!==t.sessionId)&&j(e)}},[D,j,y]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=z.current[e]??{lastSeenChunkId:null,openedUrl:!1,tail:``,openInPreview:!1};z.current[e]=n;let r=ae.find(e=>e.id===t.actionId);if(!r)continue;let i=y.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?Al(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&&(E(t.directory,t.tabId,l,{locked:!1,autoOpened:!1}),t.status===`waiting-for-preview`&&k(e,`running`),window.clearTimeout(V.current[e]),delete V.current[e],v(t.directory,l))}else W(l),J.success(a(`projectActions.toast.openedUrlFromOutput`));z.current[e]=n}for(let e of Object.keys(z.current))D[e]||(delete z.current[e],window.clearTimeout(V.current[e]),delete V.current[e])},[ae,v,W,D,E,a,y,k]);let oe=Q.useCallback(async(e,t={})=>{if(!G)throw Error(a(`projectActions.error.noActiveDirectory`));let n=Cc(G,e.id);b(G);let r=Fs.getState(),i=r.getDirectoryState(G),o=R.current[n]||null,s=o?!!i?.tabs.some(e=>e.id===o):!1;(!o||!s)&&(o=r.createTab(G),R.current[n]=o),x(G,o,`Action: ${e.name}`),S(G,o,e.icon||`play`),t.revealTerminal!==!1&&(C(G,o),f(!0),m(`terminal`));let c=Fs.getState().getDirectoryState(G)?.tabs.find(e=>e.id===o);return{key:n,tabId:o,sessionId:c?.terminalSessionId??null}},[b,G,m,C,f,S,x,a]),se=Q.useCallback(async e=>{if(s.isVSCode||!i&&c)return;if(!G){J.error(a(`projectActions.error.noActiveDirectoryForAction`));return}let t=Cc(G,e.id),n=D[t];if(!(n&&n.status===`running`))try{let t=e.id===El?await(async()=>{let[e,t]=await Promise.all([Ot({id:te?.id??``,path:G}),Sl(G)]),n=await hl(G,e.actions,t);if(!n)throw Error(a(`contextPanel.preview.noDevServer`));return{id:El,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!==El}),c=s,d=!1;if(!c){w(G,i,!0);try{c=(await o.createSession({cwd:G})).sessionId,d=!0,T(G,i,c)}finally{w(G,i,!1)}}if(!c)throw Error(a(`projectActions.error.failedToCreateTerminalSession`));d&&await Cl(350),t.id===El&&(B.current[r]?.(),w(G,i,!0),B.current[r]=He(c,e=>{e.type===`data`&&typeof e.data==`string`&&e.data.length>0&&Fs.getState().appendToBuffer(G,i,e.data),e.type===`exit`&&(Fs.getState().setTabLifecycle(G,i,`exited`),Fs.getState().setConnecting(G,i,!1),Fs.getState().removeProjectActionRun(r),delete z.current[r],B.current[r]?.(),delete B.current[r],window.clearTimeout(V.current[r]),delete V.current[r])},()=>{Fs.getState().setConnecting(G,i,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));let f=t.autoOpenUrl===!0&&l&&(t.desktopOpenSshForward||``).trim().length>0,p=t.autoOpenUrl?kl(t.openUrl):null,m=t.autoOpenUrl&&l?xc(t.desktopOpenSshForward,u):null;O({key:r,directory:G,actionId:t.id,tabId:i,sessionId:c,status:t.id===El&&!p?`waiting-for-preview`:`running`}),window.clearTimeout(V.current[r]),delete V.current[r],t.id===El&&!p&&(V.current[r]=window.setTimeout(()=>{Fs.getState().updateProjectActionRunStatus(r,`running`),delete V.current[r]},Dl)),m?(E(G,i,null,{locked:!0}),W(m),J.success(a(`projectActions.toast.openedForwardedUrl`))):p?(E(G,i,p,{locked:!0,autoOpened:!0}),v(G,p),J.success(a(`projectActions.toast.openedActionUrl`))):n?(E(G,i,null,{locked:!0}),J.error(a(`projectActions.error.invalidCustomUrlFormat`))):f?(E(G,i,null,{locked:!0}),J.error(a(`projectActions.error.selectedDesktopSshForwardUnavailable`))):E(G,i,null,{locked:!1,autoOpened:!1}),z.current[r]={lastSeenChunkId:null,openedUrl:!!m||!!p||n,tail:``,openInPreview:t.id===El};let h=Ol(t.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await o.sendInput(c,`${h}\r`)}catch(e){j(t),delete z.current[t],B.current[t]?.(),delete B.current[t],window.clearTimeout(V.current[t]),delete V.current[t],J.error(e instanceof Error?e.message:a(`projectActions.error.failedToRunAction`))}},[u,oe,i,c,l,G,W,v,D,s.isVSCode,j,w,O,E,T,te?.id,a,o]),ce=Q.useCallback(async e=>{let t=Cc(G,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)}),Fs.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{}T(n.directory,n.tabId,null)}j(t),delete z.current[t],B.current[t]?.(),delete B.current[t],window.clearTimeout(V.current[t]),delete V.current[t]}},[G,D,j,T,o,k]),le=Q.useCallback(()=>{let e=re??ae[0];if(!e)return;let t=Cc(G,e.id),n=D[t];if(n?.status!==`stopping`){if(n){ce(e);return}se(e)}},[ae,G,se,D,re,ce]),ue=Q.useCallback((e,t=!1)=>{if(F(e.id),!t){se(e);return}let n=Cc(G,e.id),r=D[n];if(r?.status!==`stopping`){if(r){ce(e);return}se(e)}},[G,se,D,ce]),de=Q.useCallback(()=>{te?.id&&(_(te.id),h(`projects`),g(!0))},[g,h,_,te?.id]);if(s.isVSCode||!i&&c||!te||!G)return null;let fe=re??ae[0]??null;if(!fe)return null;let pe=fe.icon||`play`,me=fe.id===El?`search`:Sc[pe]||`play`,he=D[Cc(G,fe.id)],ge=he?.status===`stopping`,_e=he?.status===`waiting-for-preview`,ve=he?y.get(he.directory)?.tabs.find(e=>e.id===he.tabId)?.previewUrl??null:null,ye=!!(he&&ve),be=()=>{!he||!ve||v(he.directory,ve)};return r?(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:I||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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ea,{children:[(0,$.jsx)(sa,{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)($i,{align:`end`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ca,{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===El?`search`:Sc[t]||`play`,r=Cc(G,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ca,{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:I||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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ea,{children:[(0,$.jsx)(sa,{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)($i,{align:`start`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(ca,{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===El?`search`:Sc[t]||`play`,r=Cc(G,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(ca,{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)})]})]})]})},Ml=`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`,Nl=`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`,Pl=Q.memo(function(e){let t=(0,Rc.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??Ml,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)(zi,{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)(Bi,{children:(0,$.jsx)(`p`,{children:r})}),t[12]=r,t[13]=v);let y;return t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(Hi,{children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16],y}),Fl=Q.memo(function(e){let t=(0,Rc.c)(42),{isMobile:n,githubAuthStatus:r,githubAccounts:i,githubAvatarUrl:a,githubLogin:o,isSwitchingGitHubAccount:s,handleGitHubAccountSwitch:c}=e,{t:l}=Xe();if(!r?.connected||n)return null;if(i.length>1){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(Ml,`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)(sa,{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)(_a,{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)(ca,{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)($i,{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)(ea,{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}),Il=Q.memo(function(e){let t=(0,Rc.c)(61),{isDesktopApp:n,currentInstanceIsLocal: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}=Xe(),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)(sa,{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 L;t[11]!==s||t[12]!==d||t[13]!==I?(L=(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)(Qo,{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]=L):L=t[14];let R;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?(R=n&&s===`instance`?(0,$.jsxs)(`div`,{children:[r?null:(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]})}),(0,$.jsx)(Zr,{embedded:!0,open:i&&s===`instance`,onOpenChange:Hl,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]=R):R=t[25];let z;t[26]!==s||t[27]!==i?(z=s===`mcp`?(0,$.jsx)(Is,{active:i&&s===`mcp`}):null,t[26]=s,t[27]=i,t[28]=z):z=t[28];let B;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?(B=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:Rl(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)(Qo,{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)(xi,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??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=Gi(r.usedPercent,r.resetAt,r.windowSeconds,n),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-qi(a.elapsedRatio):qi(a.elapsedRatio),s=Ki(r.valueLabel,i),c=Xi(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:Zi(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)(bs,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(Cs,{paceInfo:a,compact:!0}):null]},`${e.providerId}-${n}`)}),e.modelFamilies&&e.modelFamilies.length>0?(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(n=>{let r=n.familyId??`other`,i=t.includes(r);return(0,$.jsxs)(yc,{open:i,onOpenChange:()=>S(e.providerId,r),children:[(0,$.jsxs)(vc,{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)(_c,{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=Gi(r.usedPercent,r.resetAt,r.windowSeconds),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-qi(a.elapsedRatio):qi(a.elapsedRatio),s=Ki(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:_s(n)}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(bs,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(Cs,{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]=B):B=t[44];let V;t[45]!==w||t[46]!==T||t[47]!==C||t[48]!==N?(V=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)(ca,{disabled:w,onSelect:()=>{T()},children:N(`header.services.shutdownDev`)})})]}):null,t[45]=w,t[46]=T,t[47]=C,t[48]=N,t[49]=V):V=t[49];let H;t[50]!==M||t[51]!==L||t[52]!==R||t[53]!==z||t[54]!==B||t[55]!==V?(H=(0,$.jsxs)($i,{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:[L,R,z,B,V]}),t[50]=M,t[51]=L,t[52]=R,t[53]=z,t[54]=B,t[55]=V,t[56]=H):H=t[56];let U;return t[57]!==i||t[58]!==P||t[59]!==H?(U=(0,$.jsxs)(ea,{open:i,onOpenChange:P,children:[F,H]}),t[57]=i,t[58]=P,t[59]=H,t[60]=U):U=t[60],U}),Ll=(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??``),Rl=(e,t)=>{if(!e)return`-`;try{return ba(e,t,{fallback:`-`})}catch{return`-`}},zl=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},Bl=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,Vl=({onToggleLeftDrawer:e,onToggleRightDrawer:t,leftDrawerOpen:n,rightDrawerOpen:r})=>{let{t:i}=Xe(),a=p(e=>e.setSessionSwitcherOpen),s=p(e=>e.toggleSidebar),c=p(e=>e.isSidebarOpen),l=p(e=>e.toggleBottomTerminal),u=p(e=>e.toggleRightSidebar),d=p(e=>e.openContextOverview),f=p(e=>e.openContextPlan),h=p(e=>e.openContextBrowser),g=p(e=>e.openContextPanelTab),_=p(e=>e.closeContextPanel),y=p(e=>e.contextPanelByDirectory),b=p(e=>e.activeMainTab),x=p(e=>e.setActiveMainTab),S=p(e=>e.shortcutOverrides),C=p(e=>e.timeFormatPreference),E=wt(e=>e.getCurrentModel),D=uo(),[O,k]=Q.useState(!1),M=yn(e=>e.getContextUsage),N=yn(e=>!!e.newSessionDraft?.open),P=yn(e=>e.currentSessionId),F=Nn(P??``),I=Kn(P),L=xn(e=>e.activeProjectId?e.projects.find(t=>t.id===e.activeProjectId)??null:null),R=Q.useMemo(()=>{if(!L)return null;let e=L.path.split(/[\\/]/).filter(Boolean);return e[e.length-1]??null},[L]),z=Es(e=>e.results),B=Es(e=>e.fetchAllQuotas),H=Es(e=>e.isLoading),U=Es(e=>e.lastUpdated),ee=Es(e=>e.displayMode),ne=Es(e=>e.showPredValues),G=Es(e=>e.dropdownProviderIds),re=Es(e=>e.loadSettings),K=Es(e=>e.setDisplayMode),{isMobile:ae}=Ca(),oe=ha().data??null,ue=ws(e=>e.setStatus),fe=Q.useRef(null),[pe,me]=Q.useState(()=>typeof window>`u`?!1:A()),he=Q.useMemo(()=>w(),[]),ge=pe&&T()===`win32`,_e=wa(),[ve,ye]=Q.useState(!1),be=Q.useMemo(()=>typeof navigator>`u`?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||``),[]),{usesFramelessChrome:xe,side:Se}=Ps(),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(A())},[]);let we=E(),Te=we&&typeof we.limit==`object`&&we.limit!==null?we.limit:null,Ee=M(Te&&typeof Te.context==`number`?Te.context:0,Te&&typeof Te.output==`number`?Te.output:0),[De,Oe]=Q.useState(null),ke=!P||F;(0,Q.useEffect)(()=>{if(!P){Oe(e=>e===null?e:null);return}if(Ee&&Ee.totalTokens>0){Oe(e=>Ll(e,Ee)?e:Ee);return}ke&&Oe(e=>e===null?e:null)},[Ee,P,ke]);let Ae=p(e=>e.isSessionSwitcherOpen),je=oe?.connected?oe.user?.avatarUrl??null:null,Me=oe?.connected?oe.user?.login??null:null,Ne=oe?.accounts??[],[q,Pe]=Q.useState(!1),[Fe,Ie]=Q.useState(!1),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[He,Ue]=Q.useState(`Local`),[We,Ge]=Q.useState(!0),[Ke,qe]=Q.useState(!1),[Je,Ye]=Q.useState(null),[Ze,Qe]=Q.useState(!1),[$e,et]=Q.useState(null),[tt,nt]=Q.useState(pe?`instance`:`usage`),[rt,it]=Q.useState(`usage`);(0,Q.useEffect)(()=>{!pe&&tt===`instance`&&nt(`usage`)},[tt,pe]);let at=Q.useMemo(()=>v(),[]),ot=!at&&b===`chat`&&!!De&&De.totalTokens>0,st=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,ct=Q.useCallback(async()=>{if(!(typeof window>`u`||!pe))try{if(j()){Ue(`Local`),Ge(!0);return}Ge(!1);let e=await de(),t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,n=m();if(n&&se(n,t)){Ue(`Local`),Ge(!0);return}let r=e.hosts.find(e=>n?se(n,le(e)):!1);if(r?.label?.trim()){Ue(ce(r.label.trim()));return}Ue(`Instance`)}catch{Ue(`Local`),Ge(!0)}},[pe]);(0,Q.useEffect)(()=>{ct()},[ct]);let lt=Q.useCallback(async()=>{if(We){Ye(null),et(null);return}Qe(!0),et(null);try{let e=new URLSearchParams({appType:`web`,instanceMode:`remote`}),t=await V(`/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();Ye({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){Ye(null),et(e instanceof Error?e.message:i(`header.services.remoteUpdate.error`))}finally{Qe(!1)}},[We,i]);Q.useEffect(()=>{Ye(null),et(null),qe(!1)},[We,He]),Q.useEffect(()=>{if(!pe||We)return;let e=36e5,t=!1,n=null,r=i=>{n=window.setTimeout(()=>{if(t||typeof document<`u`&&document.visibilityState!==`visible`){r(e);return}lt().finally(()=>{t||r(e)})},i)};return r(3e3),()=>{t=!0,n!==null&&window.clearTimeout(n)}},[lt,We,He,pe]);let ut=Q.useCallback(()=>{if(Je?.available){qe(!0);return}lt()},[lt,Je?.available]);gs();let dt=Es(e=>e.selectedModels),ft=Es(e=>e.expandedFamilies),pt=Es(e=>e.toggleFamilyExpanded),mt=Q.useMemo(()=>{let e=[];for(let t of hs){if(!G.includes(t.id))continue;let n=z.find(e=>e.providerId===t.id),r=n?.usage?.windows??{},a=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(a&&Object.keys(a).length>0){let e=dt[t.id]??[],n=e.length>0,r=Os(a,t.id),o=ks(t.id),c=os(o);s.modelFamilies=[];for(let t of c){let i=r.get(t.id)??[];if(i.length===0)continue;let o=n?i.filter(t=>e.includes(t)):i;if(o.length===0)continue;let c=[];for(let e of o){let t=a[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=a[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:i(`header.services.modelFamily.other`),models:e})}}(o.length>0||s.modelFamilies&&s.modelFamilies.length>0||s.error)&&e.push(s)}return e},[G,z,dt,i]),ht=mt.length>0;Q.useEffect(()=>{re()},[re]);let gt=Q.useCallback(async e=>{K(e);try{await W({usageDisplayMode:e})}catch(e){console.warn(`Failed to update usage display mode:`,e)}},[K]),_t=Q.useCallback(()=>{if(ze)return;Be(!0);let e=new Promise(e=>setTimeout(e,500));Promise.all([B(),e]).finally(()=>{Be(!1)})},[B,ze]),vt=yn(e=>P?e.worktreeMetadata.get(P)?.path??``:``),yt=Q.useMemo(()=>zl(vt||``),[vt]),bt=Q.useMemo(()=>zl((typeof I?.directory==`string`?I.directory:``)||``),[I?.directory]),xt=yn(e=>e.newSessionDraft?.open?zl(e.newSessionDraft.bootstrapPendingDirectory??e.newSessionDraft.directoryOverride??``):``),St=Q.useMemo(()=>yt||bt||xt,[xt,bt,yt]),Ct=Lo(),Tt=Q.useMemo(()=>zl(Ct||St||L?.path||``),[L?.path,Ct,St]),Et=Q.useMemo(()=>{if(!P)return R??`OpenChamber`;let e=I?.title?.trim();return e&&e.length>0?e:`Untitled Session`},[R,I?.title,P]),Dt=Q.useMemo(()=>zl(St||L?.path||``),[L?.path,St]),Ot=Q.useMemo(()=>L?{id:L.id,path:L.path}:null,[L]),kt=Q.useRef(null);Q.useEffect(()=>{!Ot||!Dt||(kt.current={projectRef:Ot,directory:Dt})},[Dt,Ot]);let At=Q.useMemo(()=>Ot&&Dt?{projectRef:Ot,directory:Dt}:kt.current,[Dt,Ot]),jt=$a(e=>e.planModeEnabled),Mt=yn(e=>e.isSessionPlanAvailable),Nt=jt&&P?Mt(P):!1,Pt=Nt,Ft=Q.useRef(``);Q.useEffect(()=>{if(!jt){p.getState().activeMainTab===`plan`&&p.getState().setActiveMainTab(`chat`);return}if(!P)return;let e=`${P||`none`}:${bt||`none`}:${I?.time?.created||0}:${I?.slug||`none`}`;Ft.current!==e&&(Ft.current=e),!Nt&&p.getState().activeMainTab===`plan`&&p.getState().setActiveMainTab(`chat`)},[jt,Nt,I?.slug,I?.time?.created,P,bt]);let It=Q.useCallback(async e=>{if(!(!e||q)){Pe(!0);try{let t=D.github?await D.github.authActivate(e):await(async()=>{let t=await V(`/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})();ue(t)}catch(e){console.error(`Failed to switch GitHub account:`,e)}finally{Pe(!1)}}},[q,D.github,ue]),Lt=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()},[]),Rt=Q.useCallback(()=>{if(ae){Lt(),a(!Ae);return}s()},[Lt,ae,Ae,a,s]),zt=Q.useCallback(()=>{te(`desktop_open_draft_mini_chat_window`,{directory:zl(St||L?.path||``),projectId:L?.id??null,apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[header] failed to open draft mini chat window`,e)})},[L?.id,L?.path,St]),Bt=Q.useCallback(()=>{if(N){zt();return}P&&te(`desktop_open_session_mini_chat_window`,{sessionId:P,directory:zl(St||L?.path||``),apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[header] failed to open session mini chat window`,e)})},[L?.path,P,zt,N,St]),Vt=Q.useCallback(()=>{let e=Tt;if(!e)return;let t=y[e];if(Bl(t)===`context`){_(e);return}d(e)},[_,Tt,y,d]),Ht=Q.useMemo(()=>{let e=Tt;if(!e)return!1;let t=y[e];return Bl(t)===`context`},[Tt,y]),Ut=Q.useCallback(()=>{let e=Tt;if(!e)return;let t=y[e];if(Bl(t)===`plan`){_(e);return}f(e)},[_,Tt,y,f]),Wt=Q.useCallback(()=>{let e=Tt;if(!e)return;let t=y[e];if(Bl(t)===`diff`){_(e);return}g(e,{mode:`diff`,stagedDiff:!1})},[_,Tt,y,g]),Gt=Q.useCallback(()=>{let e=Tt;if(!e)return;let t=y[e];if(Bl(t)===`browser`){_(e);return}h(e)},[_,Tt,y,h]),Kt=Q.useMemo(()=>{let e=Tt;if(!e)return!1;let t=y[e];return Bl(t)===`plan`},[Tt,y]),qt=Q.useMemo(()=>{let e=Tt;if(!e)return!1;let t=y[e];return Bl(t)===`browser`},[Tt,y]),Jt=Ml,Yt=Nl,Xt=Q.useMemo(()=>Fe?`services`:n?`sessions`:r?`git`:b,[b,Fe,n,r]),Zt=Q.useCallback(()=>{Ie(!1),n&&e&&e(),r&&t&&t(),!e&&Ae&&a(!1)},[Ae,n,e,t,r,a]),Qt=Q.useCallback(()=>{n||Ie(!1),e?.()},[n,e]),$t=Q.useCallback(()=>{r||Ie(!1),t?.()},[t,r]),en=Q.useMemo(()=>pe&&be&&!ve?`5.5rem`:_e?`max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)`:(!pe||xe)&&!at?`calc(0.75rem + var(--oc-wco-left-inset, 0px))`:`0.75rem`,[pe,ve,be,_e,at,xe]);(0,Q.useEffect)(()=>{typeof document>`u`||document.documentElement.style.setProperty(`--oc-titlebar-left-inset`,en)},[en]);let tn=c?`0.75rem`:`var(--oc-titlebar-left-inset, 0.75rem)`,nn=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 te(`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 rn=Q.useMemo(()=>!pe||!be||Ce===null?``:Ce>=26?`h-12`:Ce<=15?`h-14`:``,[pe,be,Ce]),an=Q.useMemo(()=>{if(!(pe&&!xe||at))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,at,xe]),on=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;on();let e=fe.current;if(!e||typeof ResizeObserver>`u`)return()=>{};let t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,on()})},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)}},[on]),(0,Q.useEffect)(()=>{on()},[on,ae,rn]);let sn=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 ie()},[pe]),cn=Q.useMemo(()=>{if(ae){let e=[{id:`chat`,label:i(`layout.mainTab.chat`),icon:`chat-thread`}];return Pt&&e.push({id:`plan`,label:i(`layout.mainTab.plan`),icon:`file-text`}),e.push({id:`diff`,label:i(`layout.mainTab.diff`),icon:`diff`},{id:`files`,label:i(`layout.mainTab.files`),icon:`folder-6`},{id:`terminal`,label:i(`layout.mainTab.terminal`),icon:`terminal-box`},{id:`context`,label:i(`layout.mainTab.context`),icon:`file-list-2`},{id:`diagram`,label:i(`layout.mainTab.diagram`),icon:`file`}),e}return[]},[ae,Pt,i]),ln=Q.useCallback(e=>fa(da(e,S)),[S]);(0,Q.useEffect)(()=>{!ae&&(b===`git`||b===`terminal`||b===`diff`||b===`files`||b===`context`)&&x(`chat`)},[b,ae,x]);let un=Q.useMemo(()=>{let e=[];return pe&&e.push({value:`instance`,label:i(`layout.services.instance`),icon:(0,$.jsx)(X,{name:`server`,className:`h-3.5 w-3.5`})}),e.push({value:`usage`,label:i(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{value:`mcp`,label:`MCP`,icon:(0,$.jsx)(ms,{className:`h-3.5 w-3.5`})}),e},[pe,i]),dn=Q.useMemo(()=>un.map(e=>({id:e.value,label:e.label,icon:e.icon})),[un]),fn=Q.useMemo(()=>{if(typeof window>`u`||pe||at)return!1;let e=window.location.hostname;return e===`localhost`||e===`127.0.0.1`||e===`::1`},[pe,at]),pn=Q.useCallback(async()=>{if(O)return;k(!0),Re(!1);let e=[],t=!1;try{try{for(let[,t]of Fs.getState().sessions.entries())for(let n of t.tabs)n.previewUrl&&e.push(n.previewUrl)}catch{}try{await Ve({})}catch{}try{t=(await V(`/api/system/dev-shutdown`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({previewUrls:e})})).ok?!0:(await V(`/api/system/shutdown`,{method:`POST`})).ok}catch{}}finally{t||k(!1)}},[O,Re]),mn=Q.useMemo(()=>[{value:`usage`,label:i(`header.services.used`)},{value:`remaining`,label:i(`header.services.remaining`)}],[i]),hn=Q.useMemo(()=>mn.map(e=>({id:e.value,label:e.label})),[mn]),gn=Q.useMemo(()=>[{id:`usage`,label:i(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{id:`mcp`,label:`MCP`,icon:(0,$.jsx)(ms,{className:`h-3.5 w-3.5`})}],[i]);(0,Q.useEffect)(()=>{let e=e=>{if($n(e)&&!e.shiftKey&&!e.altKey){let t=parseInt(e.key,10);t>=1&&t<=cn.length&&(e.preventDefault(),ae&&(Lt(),Zt()),x(cn[t-1].id))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Lt,Zt,ae,x,cn]),(0,Q.useEffect)(()=>{let e=e=>{let t=da(`toggle_services_menu`,S);if(Sa(e,t)){e.preventDefault(),Le?Re(!1):(Re(!0),ct(),tt===`usage`&&z.length===0&&B());return}let n=da(`cycle_services_tab`,S);if(Sa(e,n)){e.preventDefault();let t=un.map(e=>e.value);if(t.length===0)return;let n=t.indexOf(tt),r=t[n===-1?0:(n+1)%t.length];nt(r),Re(!0),ct(),r===`usage`&&z.length===0&&B();return}let r=da(`open_usage`,S);if(Sa(e,r)){e.preventDefault(),nt(`usage`),Re(!0),ct(),z.length===0&&B();return}let i=da(`toggle_context_plan`,S);Sa(e,i)&&(e.preventDefault(),Ut())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,Le,tt,un,z.length,B,ct,Ut]);let _n=e=>{let t=b===e.id,n=e.icon===`diff`,r=n?null:e.icon,i=e.id===`chat`,a=e=>n?(0,$.jsx)(zc,{size:e}):r?(0,$.jsx)(X,{name:r,className:`h-${e/4} w-${e/4}`}):null,o=(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(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&&!ae&&`min-w-[100px] justify-center`),"aria-label":e.label,"aria-selected":t,role:`tab`,children:[ae?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)},vn=he&&(N||!!P),bn=Q.useCallback(e=>{window.setTimeout(e,0)},[]),Sn=Q.useCallback(e=>{nt(e),Re(!0),ct(),e===`usage`&&z.length===0&&B()},[B,z.length,ct]),Cn=Q.useRef(null),wn=(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,children:[(0,$.jsx)(`div`,{ref:Cn,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center`,children:(0,$.jsxs)(ea,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.actions.sessionMenuAria`),className:Y(Jt,`text-muted-foreground`),children:(0,$.jsx)(X,{name:`more-2`,className:`h-[18px] w-[18px]`})})})}),(0,$.jsx)(Bi,{children:(0,$.jsx)(`p`,{children:i(`header.actions.sessionMenu`)})})]}),(0,$.jsxs)($i,{align:`start`,className:`min-w-[14rem]`,children:[at?null:(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(Wt),children:[(0,$.jsx)(X,{name:`layout-column`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.toggleChangesPanel`)})]}),vn?(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(Bt),children:[(0,$.jsx)(X,{name:`picture-in-picture-2`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(N?`header.actions.newMiniChat`:`header.actions.openSessionMiniChat`)})]}):null,pe?(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(()=>Sn(`instance`)),children:[(0,$.jsx)(X,{name:`stack`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:i(`header.actions.sessionMenu.servicesWithInstance`,{current:He})}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`toggle_services_menu`)})]}):null,(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(()=>Sn(`usage`)),children:[(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.sessionMenu.viewUsage`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`open_usage`)})]}),(0,$.jsx)(oa,{}),(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(l),children:[(0,$.jsx)(X,{name:`terminal-box`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.toggleTerminalPanel`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`toggle_terminal`)})]}),(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>bn(Gt),children:[(0,$.jsx)(X,{name:`global`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`contextPanel.browser.open`)}),qt?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-foreground`}):null]})]})]})}),(0,$.jsx)(Il,{isDesktopApp:pe,currentInstanceIsLocal:We,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Re,refreshCurrentInstanceLabel:ct,desktopServicesTab:tt,setDesktopServicesTab:nt,quotaResultsLength:z.length,fetchAllQuotas:B,servicesTabItems:dn,quotaLastUpdated:U,quotaDisplayMode:ee,showPredValues:ne,quotaDisplayTabItems:hn,handleDisplayModeChange:gt,handleUsageRefresh:_t,isQuotaLoading:H,isUsageRefreshSpinning:ze,hasRateLimits:ht,rateLimitGroups:mt,expandedFamilies:ft,toggleFamilyExpanded:pt,showDevShutdown:fn,isDevShutdownInFlight:O,onDevShutdown:pn,remoteUpdateInfo:Je,remoteUpdateChecking:Ze,remoteUpdateError:$e,onOpenRemoteUpdate:ut,timeFormatPreference:C,anchorRef:Cn})]}),Tn=(0,$.jsxs)($.Fragment,{children:[Pt&&(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.actions.openPlanAria`),onClick:Ut,className:Y(Jt,Kt&&`bg-[var(--interactive-hover)]`),children:(0,$.jsx)(X,{name:`file-text`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(Bi,{children:(0,$.jsx)(`p`,{children:i(`header.actions.planWithShortcut`,{shortcut:ln(`toggle_context_plan`)})})})]}),(0,$.jsx)(il,{directory:Dt,className:`mr-1`}),(0,$.jsx)(Pl,{title:i(`header.actions.rightSidebarWithShortcut`,{shortcut:ln(`toggle_right_sidebar`)}),ariaLabel:i(`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)(Fl,{isMobile:ae,githubAuthStatus:oe,githubAccounts:Ne,githubAvatarUrl:je,githubLogin:Me,isSwitchingGitHubAccount:q,handleGitHubAccountSwitch:It})]}),En=()=>(0,$.jsxs)(`div`,{onMouseDown:sn,className:Y(`app-region-drag relative flex h-12 select-none items-center pr-3`,rn),style:an,role:`tablist`,"aria-label":i(`header.navigation.mainAria`),children:[(0,$.jsx)(`div`,{"aria-hidden":!0,className:`shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,style:{width:tn}}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,style:{width:nn}}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,$.jsxs)(`div`,{className:`app-region-no-drag mr-3 flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Ms,{children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`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:N?i(`sessions.switcher.draftTitle`):Et})})}),wn]}),cn.length>0&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1`,children:cn.map(e=>_n(e))}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[ot&&De?(0,$.jsx)(js,{totalTokens:De.totalTokens,percentage:st,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:`compact`,appearance:`subtle`,onClick:Vt,pressed:Ht,className:`mr-2`}):null,Tn,(0,$.jsx)(Ns,{visible:xe&&Se===`right`,position:`right`})]})]})]}),Dn=()=>(0,$.jsxs)(`div`,{className:`app-region-drag relative flex items-center gap-2 px-3 py-2 select-none`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e?(0,$.jsx)(`button`,{type:`button`,onClick:Qt,className:Y(Yt,Xt===`sessions`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":i(n?`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:()=>a(!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":i(`header.actions.backAria`),children:(0,$.jsx)(X,{name:`arrow-left-s`,className:`h-5 w-5`})}):(0,$.jsx)(`button`,{type:`button`,onClick:Rt,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":i(`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:i(`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":i(`header.navigation.mainAria`),children:cn.map(e=>{let t=b===e.id,n=e.icon===`diff`,r=n?null:e.icon;return(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ae&&(Lt(),Zt()),x(e.id)},"aria-label":e.label,"aria-selected":t,role:`tab`,className:Y(Yt,`relative rounded-lg`,Xt===e.id&&`bg-interactive-selection text-interactive-selection-foreground`),children:[n?(0,$.jsx)(zc,{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":i(`header.changes.availableAria`)})]})}),(0,$.jsx)(Bi,{children:(0,$.jsx)(`p`,{children:e.label})})]},e.id)})})})})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[At&&(0,$.jsx)(jl,{projectRef:At.projectRef,directory:At.directory,compact:!0,allowMobile:!0,className:`h-9`}),(0,$.jsxs)(ea,{open:Fe,onOpenChange:i=>{i&&(n&&e&&e(),r&&t&&t()),Ie(i),i&&z.length===0&&B()},children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.services.viewAria`),className:Y(Yt,Xt===`services`&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(X,{name:`stack`,className:`h-5 w-5`})})})}),(0,$.jsx)(Bi,{children:(0,$.jsx)(`p`,{children:i(`header.services.title`)})})]}),(0,$.jsx)($i,{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)(Qo,{items:gn,activeId:rt,onSelect:e=>{let t=e;it(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":i(`header.services.closeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-5 w-5`})})]})}),rt===`mcp`&&(0,$.jsx)(Is,{active:Fe&&rt===`mcp`}),rt===`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:i(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:Rl(U,C)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center h-6`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>gt(`usage`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,ee===`usage`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:i(`header.services.used`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground typography-ui-label px-0.5`,children:`·`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>gt(`remaining`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,ee===`remaining`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:i(`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:_t,disabled:H||ze,"aria-label":i(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,ze&&`animate-spin`)})})]})]})}),!ht&&(0,$.jsx)(`div`,{className:`px-4 py-6 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:i(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`py-1`,children:mt.map((e,t)=>(0,$.jsxs)(Q.Fragment,{children:[t>0?(0,$.jsx)(`div`,{className:`mx-4 my-1 border-t border-[var(--interactive-border)]`}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2`,children:[(0,$.jsx)(xi,{providerId:e.providerId,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:e.providerName})]}),e.entries.length===0&&(!e.modelFamilies||e.modelFamilies.length===0)?(0,$.jsx)(`div`,{className:`px-4 pb-2`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:e.error??i(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3 px-4 pb-2`,children:[e.entries.map(([t,n])=>{let r=ee===`remaining`?n.remainingPercent:n.usedPercent,i=Gi(n.usedPercent,n.resetAt,n.windowSeconds,t),a=i?.dailyAllocationPercent==null?null:ee===`remaining`?100-qi(i.elapsedRatio):qi(i.elapsedRatio),o=Ki(n.valueLabel,r),s=Xi(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,C);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:Zi(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)(bs,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ne?(0,$.jsx)(Cs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)}),e.modelFamilies&&e.modelFamilies.length>0&&(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.modelFamilies.map(t=>{let n=(ft[e.providerId]??[]).includes(t.familyId??`other`);return(0,$.jsxs)(yc,{open:n,onOpenChange:()=>pt(e.providerId,t.familyId??`other`),children:[(0,$.jsxs)(vc,{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)(_c,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:t.models.map(([t,n])=>{let r=ee===`remaining`?n.remainingPercent:n.usedPercent,i=Gi(n.usedPercent,n.resetAt,n.windowSeconds),a=i?.dailyAllocationPercent==null?null:ee===`remaining`?100-qi(i.elapsedRatio):qi(i.elapsedRatio),o=Ki(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:_s(t)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(bs,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ne?(0,$.jsx)(Cs,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)})})})]},t.familyId??`other`)})})]})]},e.providerId))})]})]})})]}),t?(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:$t,className:Y(Yt,`relative`,Xt===`git`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":r?`Close git sidebar`:`Open git sidebar`,children:(0,$.jsx)(X,{name:`layout-right`,className:`h-5 w-5`})})}),(0,$.jsx)(Bi,{children:(0,$.jsx)(`p`,{children:r?`Close git sidebar`:`Open git sidebar`})})]}):null]})]})]}),On=Y(`header-safe-area relative z-10 bg-background`,ge&&`bg-[var(--surface-background)] backdrop-blur-none`,ae&&`border-b border-border/50`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`header`,{ref:fe,className:On,style:{"--padding-scale":`1`},children:ae?Dn():En()}),(0,$.jsx)(As,{open:Ke,onOpenChange:qe,info:Je,downloading:!1,downloaded:!1,progress:null,error:$e,onDownload:()=>{},onRestart:()=>{},runtimeType:`web`})]})};function Hl(){}var Ul=180,Wl=640,Gl=110,Kl=e=>{let t=(0,Rc.c)(44),{isOpen:n,isMobile:r,children:i}=e,{t:a}=Xe(),o=p(ql),s=p(Jl),c=p(Yl),l=p(Xl),[u,d]=Q.useState(null),[f,m]=Q.useState(!1),h=Q.useRef(null),g=Q.useRef(0),_=Q.useRef(o||300),v=Math.min(Wl,Math.max(Ul,o||300)),y,b;t[0]===n?(y=t[1],b=t[2]):(y=()=>{n||(d(null),m(!1))},b=[n],t[0]=n,t[1]=y,t[2]=b),Q.useEffect(y,b);let x,S;t[3]!==s||t[4]!==r||t[5]!==n?(x=()=>{if(r||!n||!s)return;let e=()=>{let e=h.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=h.current?.parentElement;if(!t)return;let i=new ResizeObserver(e);return i.observe(t),()=>{i.disconnect()}},S=[s,r,n],t[3]=s,t[4]=r,t[5]=n,t[6]=x,t[7]=S):(x=t[6],S=t[7]),Q.useEffect(x,S);let C,w;if(t[8]!==s||t[9]!==r||t[10]!==f||t[11]!==c||t[12]!==l?(C=()=>{if(r||!f||s)return;let e=e=>{let t=g.current-e.clientY,n=Math.min(Wl,Math.max(Ul,_.current+t));c(n)},t=()=>{m(!1),p.getState().bottomTerminalHeight<=Gl&&l(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},w=[s,r,f,c,l],t[8]=s,t[9]=r,t[10]=f,t[11]=c,t[12]=l,t[13]=C,t[14]=w):(C=t[13],w=t[14]),Q.useEffect(C,w),r)return null;let T=n?s?Math.max(0,u??v):v:0,E=n&&s,D;t[15]!==T||t[16]!==s||t[17]!==n?(D=e=>{!n||s||(m(!0),g.current=e.clientY,_.current=T,e.preventDefault())},t[15]=T,t[16]=s,t[17]=n,t[18]=D):D=t[18];let O=D,k=E?`absolute inset-x-0 bottom-0 z-40`:`relative`,A=f?`transition-none`:`transition-[height] duration-300 ease-in-out`,j=(!n||E)&&`border-t-0`,M;t[19]!==j||t[20]!==k||t[21]!==A?(M=Y(`flex overflow-hidden border-t border-border bg-sidebar`,k,A,j),t[19]=j,t[20]=k,t[21]=A,t[22]=M):M=t[22];let N;t[23]!==T||t[24]!==E?(N=E?{top:0}:{height:`${T}px`,minHeight:`${T}px`,maxHeight:`${T}px`},t[23]=T,t[24]=E,t[25]=N):N=t[25];let P=!n||!s&&T===0,F;t[26]!==O||t[27]!==s||t[28]!==n||t[29]!==f||t[30]!==a?(F=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:O,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`terminalView.bottomDock.resizeAria`)}),t[26]=O,t[27]=s,t[28]=n,t[29]=f,t[30]=a,t[31]=F):F=t[31];let I=!n&&`pointer-events-none select-none opacity-0`,L;t[32]===I?L=t[33]:(L=Y(`relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out`,I),t[32]=I,t[33]=L);let R=!n,z;t[34]!==i||t[35]!==L||t[36]!==R?(z=(0,$.jsx)(`div`,{className:L,"aria-hidden":R,children:i}),t[34]=i,t[35]=L,t[36]=R,t[37]=z):z=t[37];let B;return t[38]!==M||t[39]!==N||t[40]!==P||t[41]!==F||t[42]!==z?(B=(0,$.jsxs)(`section`,{ref:h,className:M,style:N,"aria-hidden":P,children:[F,z]}),t[38]=M,t[39]=N,t[40]=P,t[41]=F,t[42]=z,t[43]=B):B=t[43],B};function ql(e){return e.bottomTerminalHeight}function Jl(e){return e.isBottomTerminalExpanded}function Yl(e){return e.setBottomTerminalHeight}function Xl(e){return e.setBottomTerminalOpen}var Zl=260,Ql=260,$l=500,eu=({isOpen:e,isMobile:t,children:n,className:r,topBar:i})=>{let{t:a}=Xe(),o=p(e=>e.sidebarWidth),s=p(e=>e.setSidebarWidth),[c,l]=Q.useState(!1),u=Q.useRef(0),d=Q.useRef(o||Zl),f=Q.useRef(null),m=Q.useRef(null),h=Q.useRef(null),g=Q.useCallback(e=>Math.min($l,Math.max(Ql,e)),[]),_=Q.useCallback(e=>{let t=h.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,m.current=null)},[c]),t)return null;let v=Math.min($l,Math.max(Ql,o||Zl)),y=e?v:0,b=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}m.current=t.pointerId,l(!0),u.current=t.clientX,d.current=y,f.current=y,_(y),t.preventDefault()}},x=e=>{if(t||!c||m.current!==e.pointerId)return;let n=e.clientX-u.current,r=g(d.current+n);f.current!==r&&(f.current=r,_(r))},S=e=>{if(m.current!==e.pointerId||t)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let n=g(f.current??y);m.current=null,f.current=null,l(!1),s(n)},C=c?f.current??y:y;return(0,$.jsxs)(`aside`,{ref:h,className:Y(`relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none`,`bg-sidebar oc-vibrancy-surface`,!e&&`border-r-0`,r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${c?C:v}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||y===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:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S,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)(Yi,{children:n})})]})]})},tu=()=>{let e=(0,Rc.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},nu=e=>{let t=(0,Rc.c)(24),{className:n}=e,r=vs(ru),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0],Q.useEffect(iu,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 ru(e){return e.sidebarBrandName}function iu(){ui()}var au=e=>{let t=(0,Rc.c)(25),{className:n}=e,{t:r}=Xe(),i=p(ou),a=p(su),o;t[0]===a?o=t[1]:(o=fa(da(`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)(zi,{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 m;t[13]===r?m=t[14]:(m=r(`commandPalette.title`),t[13]=r,t[14]=m);let h;t[15]===m?h=t[16]:(h=(0,$.jsx)(`span`,{children:m}),t[15]=m,t[16]=h);let g;t[17]===s?g=t[18]:(g=(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:s}),t[17]=s,t[18]=g);let _;t[19]!==h||t[20]!==g?(_=(0,$.jsx)(Bi,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[h,g]})}),t[19]=h,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==_||t[23]!==f?(v=(0,$.jsxs)(Hi,{children:[f,_]}),t[22]=_,t[23]=f,t[24]=v):v=t[24],v};function ou(e){return e.setCommandPaletteOpen}function su(e){return e.shortcutOverrides}var cu=`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`,lu=()=>{let e=(0,Rc.c)(46),{t}=Xe(),n=p(uu),r=p(du),i=p(fu),a=p(pu),o=vs(mu),s=Q.useRef(null),c=fa(da(`toggle_sidebar`,a)),{usesFramelessChrome:l,side:u}=Ps(),d;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=A(),e[0]=d):d=e[0];let f=d,m=!f||!n||!o,h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=I()&&!f&&!v(),e[1]=h):h=e[1];let g=h,_=gu,y,b;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{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()}},b=[],e[2]=y,e[3]=b):(y=e[2],b=e[3]),Q.useEffect(y,b);let x=g&&n?`${r||260}px`:void 0,S;e[4]===x?S=e[5]:(S={height:`var(--oc-header-height, 3rem)`,paddingLeft:`var(--oc-titlebar-left-inset, 0.75rem)`,width:x},e[4]=x,e[5]=S);let C=g&&n&&`w-full justify-between`,w;e[6]===C?w=e[7]:(w=Y(`flex items-center gap-2`,C),e[6]=C,e[7]=w);let T;e[8]===n?T=e[9]:(T=g&&n?(0,$.jsx)(nu,{className:`flex min-w-0 items-center p-0`}):null,e[8]=n,e[9]=T);let E;e[10]!==l||e[11]!==u?(E=l&&u===`left`?(0,$.jsx)(Ns,{visible:!0,position:`left`}):null,e[10]=l,e[11]=u,e[12]=E):E=e[12];let D;e[13]!==t||e[14]!==l?(D=l?(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":t(`header.actions.openAppMenuAria`),className:Y(cu,`shrink-0`),children:(0,$.jsx)(X,{name:`menu-2`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(Bi,{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]===m?O=e[17]:(O=m?(0,$.jsx)(au,{}):null,e[16]=m,e[17]=O);let k=Hi,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(cu,`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)(zi,{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=Bi,L=t(`header.actions.openSessionsWithShortcut`,{shortcut:c}),R;e[25]===L?R=e[26]:(R=(0,$.jsx)(`p`,{children:L}),e[25]=L,e[26]=R);let z;e[27]!==F||e[28]!==R?(z=(0,$.jsx)(F,{children:R}),e[27]=F,e[28]=R,e[29]=z):z=e[29];let B;e[30]!==k||e[31]!==P||e[32]!==z?(B=(0,$.jsxs)(k,{children:[P,z]}),e[30]=k,e[31]=P,e[32]=z,e[33]=B):B=e[33];let V;e[34]!==O||e[35]!==B?(V=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[O,B]}),e[34]=O,e[35]=B,e[36]=V):V=e[36];let H;e[37]!==E||e[38]!==D||e[39]!==V||e[40]!==w||e[41]!==T?(H=(0,$.jsxs)(`div`,{ref:s,className:w,children:[T,E,D,V]}),e[37]=E,e[38]=D,e[39]=V,e[40]=w,e[41]=T,e[42]=H):H=e[42];let U;return e[43]!==H||e[44]!==S?(U=(0,$.jsx)(`div`,{className:`app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2`,style:S,children:H}),e[43]=H,e[44]=S,e[45]=U):U=e[45],U};function uu(e){return e.isSidebarOpen}function du(e){return e.sidebarWidth}function fu(e){return e.toggleSidebar}function pu(e){return e.shortcutOverrides}function mu(e){return e.sidebarBrandName.trim().length>0}function hu(e){console.warn(`[titlebar] failed to open app menu`,e)}function gu(e){let t=e.currentTarget.getBoundingClientRect();te(`desktop_show_app_menu`,{x:t.left,y:t.bottom}).catch(hu)}var _u=420,vu=({isOpen:e,children:t,className:n})=>{let{t:r}=Xe(),i=p(e=>e.rightSidebarWidth),a=p(e=>e.setRightSidebarWidth),[o,s]=Q.useState(!1),c=Q.useRef(0),l=Q.useRef(i||_u),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),m=Q.useCallback(e=>Math.min(860,Math.max(360,e)),[]),h=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`))},[]),g=Math.min(860,Math.max(360,i||_u)),_=e?g:0;Q.useLayoutEffect(()=>{if(o)return;let e=f.current;e&&(e.style.minWidth=``,e.style.maxWidth=``)},[e,o,g]);let v=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}d.current=t.pointerId,s(!0),c.current=t.clientX,l.current=_,u.current=_,h(_),t.preventDefault()}},y=e=>{if(!o||d.current!==e.pointerId)return;let t=c.current-e.clientX,n=m(l.current+t);u.current!==n&&(u.current=n,h(n))},b=e=>{if(d.current!==e.pointerId)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=m(u.current??_);d.current=null,u.current=null,s(!1),a(t)},x=o?u.current??_:_;return(0,$.jsxs)(`aside`,{ref:f,className:Y(`relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none`,`bg-sidebar`,!e&&`border-l-0`,n),style:{width:`${x}px`,"--oc-right-sidebar-width":`${o?x:g}px`,overflowX:`clip`,transitionProperty:o?`none`:`width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||_===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:v,onPointerMove:y,onPointerUp:b,onPointerCancel:b,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})]})},yu=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent});function bu(e){let t=(0,Rc.c)(131),{t:n}=Xe(),{open:r,onOpenChange:i,target:a,projectDirectory:o,submitting:s,allowRunAsGoal:c,onConfirm:l}=e,u=s!==void 0&&s,d=c!==void 0&&c,f;t[0]===d?f=t[1]:(f=d&&!v(),t[0]=d,t[1]=f);let p=f,m=wt(ju),h=wt(Au),g=On(ku),_=wt(Ou),y=wt(Du),b=wt(Eu),x=wt(Tu),S=wt(wu),C;t[2]!==S||t[3]!==b||t[4]!==y||t[5]!==x?(C=()=>yu({providerID:y,modelID:b,variant:x,agent:S}),t[2]=S,t[3]=b,t[4]=y,t[5]=x,t[6]=C):C=t[6];let[w,T]=Q.useState(C),E,D;t[7]!==g||t[8]!==h||t[9]!==m||t[10]!==r||t[11]!==o?(E=()=>{r&&(m({directory:o,source:`todoSendDialog`}),h({directory:o}),g())},D=[r,m,h,g,o],t[7]=g,t[8]=h,t[9]=m,t[10]=r,t[11]=o,t[12]=E,t[13]=D):(E=t[12],D=t[13]),Q.useEffect(E,D);let O,k;t[14]!==S||t[15]!==b||t[16]!==y||t[17]!==x||t[18]!==r?(O=()=>{r&&T(yu({providerID:y,modelID:b,variant:x,agent:S}))},k=[r,y,b,x,S],t[14]=S,t[15]=b,t[16]=y,t[17]=x,t[18]=r,t[19]=O,t[20]=k):(O=t[19],k=t[20]),Q.useEffect(O,k);let A,j;t[21]!==w.modelID||t[22]!==w.providerID||t[23]!==r||t[24]!==_?(A=()=>{if(!r||_.length===0)return;let e=_.find(e=>e.id===w.providerID)??_[0],t=Array.isArray(e?.models)?e.models:[],n=t.some(e=>e.id===w.modelID),i=t[0]?.id??``;e?.id===w.providerID&&n||T(t=>({...t,providerID:e?.id??``,modelID:n?t.modelID:i,variant:``}))},j=[r,_,w.providerID,w.modelID],t[21]=w.modelID,t[22]=w.providerID,t[23]=r,t[24]=_,t[25]=A,t[26]=j):(A=t[25],j=t[26]),Q.useEffect(A,j);let M=Cu,N;if(t[27]!==w.modelID||t[28]!==w.providerID||t[29]!==_){let e;t[31]===w.providerID?e=t[32]:(e=e=>e.id===w.providerID,t[31]=w.providerID,t[32]=e),N=_.find(e)?.models?.find(e=>e.id===w.modelID),t[27]=w.modelID,t[28]=w.providerID,t[29]=_,t[30]=N}else N=t[30];let P=N,F;t[33]===P?F=t[34]:(F=P?.variants?Object.keys(P.variants):[],t[33]=P,t[34]=F);let I=F,L=I.length>0,R,z;t[35]!==w.variant||t[36]!==L?(R=()=>{L||!w.variant||T(Su)},z=[L,w.variant],t[35]=w.variant,t[36]=L,t[37]=R,t[38]=z):(R=t[37],z=t[38]),Q.useEffect(R,z);let B;t[39]!==w.modelID||t[40]!==w.providerID?(B=w.providerID.trim().length>0&&w.modelID.trim().length>0,t[39]=w.modelID,t[40]=w.providerID,t[41]=B):B=t[41];let V=B,H;t[42]!==V||t[43]!==w||t[44]!==l||t[45]!==u?(H=()=>{!V||u||l(w)},t[42]=V,t[43]=w,t[44]=l,t[45]=u,t[46]=H):H=t[46];let U=H,ee,te;t[47]!==U||t[48]!==r?(ee=()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),U())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},te=[r,U],t[47]=U,t[48]=r,t[49]=ee,t[50]=te):(ee=t[49],te=t[50]),Q.useEffect(ee,te);let W;t[51]!==n||t[52]!==a?(W=n(a===`worktree`?`rightSidebar.contextNotesTodo.sendDialog.title.newWorktree`:`rightSidebar.contextNotesTodo.sendDialog.title.newSession`),t[51]=n,t[52]=a,t[53]=W):W=t[53];let ne=W,G;t[54]!==i||t[55]!==u?(G=e=>{u||i(e)},t[54]=i,t[55]=u,t[56]=G):G=t[56];let re;t[57]===ne?re=t[58]:(re=(0,$.jsx)(rr,{children:(0,$.jsx)(or,{children:ne})}),t[57]=ne,t[58]=re);let K;t[59]===n?K=t[60]:(K=n(`chat.modelControls.model`),t[59]=n,t[60]=K);let ie;t[61]===K?ie=t[62]:(ie=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:K}),t[61]=K,t[62]=ie);let ae;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(e,t)=>{T(n=>({...n,providerID:e,modelID:t,variant:``}))},t[63]=ae):ae=t[63];let oe;t[64]!==w.modelID||t[65]!==w.providerID?(oe=(0,$.jsx)(ya,{providerId:w.providerID,modelId:w.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:ae}),t[64]=w.modelID,t[65]=w.providerID,t[66]=oe):oe=t[66];let se;t[67]!==ie||t[68]!==oe?(se=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[ie,oe]}),t[67]=ie,t[68]=oe,t[69]=se):se=t[69];let ce;t[70]===n?ce=t[71]:(ce=n(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[70]=n,t[71]=ce);let le;t[72]===ce?le=t[73]:(le=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:ce}),t[72]=ce,t[73]=le);let ue=!L,de;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(de=e=>T(t=>({...t,variant:e})),t[74]=de):de=t[74];let fe;t[75]!==w.variant||t[76]!==ue||t[77]!==I?(fe=(0,$.jsx)(Ma,{value:w.variant,options:I,disabled:ue,onChange:de}),t[75]=w.variant,t[76]=ue,t[77]=I,t[78]=fe):fe=t[78];let pe;t[79]!==le||t[80]!==fe?(pe=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[le,fe]}),t[79]=le,t[80]=fe,t[81]=pe):pe=t[81];let me;t[82]===n?me=t[83]:(me=n(`sessions.scheduledTasks.editor.agent.label`),t[82]=n,t[83]=me);let he;t[84]===me?he=t[85]:(he=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:me}),t[84]=me,t[85]=he);let ge;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>T(t=>({...t,agent:e})),t[86]=ge):ge=t[86];let _e;t[87]===w.agent?_e=t[88]:(_e=(0,$.jsx)(ga,{agentName:w.agent,filter:M,dropdownPortalToBody:!0,onChange:ge}),t[87]=w.agent,t[88]=_e);let ve;t[89]!==he||t[90]!==_e?(ve=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[he,_e]}),t[89]=he,t[90]=_e,t[91]=ve):ve=t[91];let ye;t[92]!==se||t[93]!==pe||t[94]!==ve?(ye=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[se,pe,ve]}),t[92]=se,t[93]=pe,t[94]=ve,t[95]=ye):ye=t[95];let be=`flex items-center gap-3 ${p?`justify-between`:`justify-end`}`,xe;t[96]!==w.runAsGoal||t[97]!==p||t[98]!==u||t[99]!==n?(xe=p?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Si,{checked:w.runAsGoal===!0,onChange:e=>T(t=>({...t,runAsGoal:e})),disabled:u,ariaLabel:n(`sessions.scheduledTasks.editor.goal.aria`)}),(0,$.jsx)(`button`,{type:`button`,className:`truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,disabled:u,onClick:()=>T(xu),children:n(`sessions.scheduledTasks.editor.goal.label`)})]}):null,t[96]=w.runAsGoal,t[97]=p,t[98]=u,t[99]=n,t[100]=xe):xe=t[100];let Se;t[101]===i?Se=t[102]:(Se=()=>i(!1),t[101]=i,t[102]=Se);let Ce;t[103]===n?Ce=t[104]:(Ce=n(`rightSidebar.contextNotesTodo.sendDialog.actions.cancel`),t[103]=n,t[104]=Ce);let we;t[105]!==u||t[106]!==Se||t[107]!==Ce?(we=(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:Se,disabled:u,children:Ce}),t[105]=u,t[106]=Se,t[107]=Ce,t[108]=we):we=t[108];let Te=!V||u,Ee;t[109]!==u||t[110]!==n?(Ee=n(u?`rightSidebar.contextNotesTodo.sendDialog.actions.sending`:`rightSidebar.contextNotesTodo.sendDialog.actions.send`),t[109]=u,t[110]=n,t[111]=Ee):Ee=t[111];let De;t[112]!==U||t[113]!==Te||t[114]!==Ee?(De=(0,$.jsx)(Z,{size:`sm`,onClick:U,disabled:Te,children:Ee}),t[112]=U,t[113]=Te,t[114]=Ee,t[115]=De):De=t[115];let Oe;t[116]!==we||t[117]!==De?(Oe=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[we,De]}),t[116]=we,t[117]=De,t[118]=Oe):Oe=t[118];let ke;t[119]!==be||t[120]!==xe||t[121]!==Oe?(ke=(0,$.jsxs)(`div`,{className:be,children:[xe,Oe]}),t[119]=be,t[120]=xe,t[121]=Oe,t[122]=ke):ke=t[122];let Ae;t[123]!==re||t[124]!==ye||t[125]!==ke?(Ae=(0,$.jsxs)(ar,{className:`max-w-md overflow-visible`,children:[re,ye,ke]}),t[123]=re,t[124]=ye,t[125]=ke,t[126]=Ae):Ae=t[126];let je;return t[127]!==r||t[128]!==G||t[129]!==Ae?(je=(0,$.jsx)(cr,{open:r,onOpenChange:G,children:Ae}),t[127]=r,t[128]=G,t[129]=Ae,t[130]=je):je=t[130],je}function xu(e){return{...e,runAsGoal:e.runAsGoal!==!0}}function Su(e){return{...e,variant:``}}function Cu(e){return Ft(e.mode)}function wu(e){return e.currentAgentName||``}function Tu(e){return e.currentVariant||``}function Eu(e){return e.currentModelId}function Du(e){return e.currentProviderId}function Ou(e){return e.providers}function ku(e){return e.loadAgents}function Au(e){return e.loadAgents}function ju(e){return e.loadProviders}var Mu=5,Nu=15,Pu=new Map,Fu=e=>{let t=Math.sqrt(e/100),n=12*t,r=24*t;return Math.ceil(n+r+1)},Iu=(e,t)=>{let n=Fu(t);return Math.max(n*Mu,Math.min(n*Nu,n*e))},Lu=async(e,t)=>{let n=await ct(e.path);return{...e,title:n?.title||e.path.split(`/`).pop()||t}},Ru=()=>L(),zu=e=>[...e.filter(e=>!e.completed),...e.filter(e=>e.completed)],Bu=(e,t)=>{let n=e.findIndex(e=>e.completed);return n===-1?[...e,t]:[...e.slice(0,n),t,...e.slice(n)]},Vu=e=>{let t=(0,Rc.c)(20),{id:n,children:r}=e,i;t[0]===n?i=t[1]:(i={id:n},t[0]=n,t[1]=i);let{attributes:a,listeners:o,setNodeRef:s,setActivatorNodeRef:c,transform:l,transition:u,isDragging:d}=Oo(i),f;t[2]===l?f=t[3]:(f=To.Transform.toString(l),t[2]=l,t[3]=f);let p;t[4]!==f||t[5]!==u?(p={transform:f,transition:u},t[4]=f,t[5]=u,t[6]=p):p=t[6];let m=d&&`opacity-60`,h;t[7]===m?h=t[8]:(h=Y(m),t[7]=m,t[8]=h);let g;t[9]!==a||t[10]!==r||t[11]!==d||t[12]!==o||t[13]!==c?(g=r({attributes:a,listeners:o,setActivatorNodeRef:c,isDragging:d}),t[9]=a,t[10]=r,t[11]=d,t[12]=o,t[13]=c,t[14]=g):g=t[14];let _;return t[15]!==s||t[16]!==p||t[17]!==h||t[18]!==g?(_=(0,$.jsx)(`li`,{ref:s,style:p,className:h,children:g}),t[15]=s,t[16]=p,t[17]=h,t[18]=g,t[19]=_):_=t[19],_},Hu=({projectRef:e,projectLabel:t,canCreateWorktree:n=!1,onActionComplete:r,className:i})=>{let{t:a}=Xe(),[o,s]=Q.useState(!1),[c,l]=Q.useState(``),[u,d]=Q.useState([]),[f,m]=Q.useState(``),[h,g]=Q.useState(null),[_,v]=Q.useState(()=>new Set),[y,b]=Q.useState([]),[x,S]=Q.useState(null),[C,w]=Q.useState(!1),[T,E]=Q.useState(0),D=Q.useRef(!1),O=Q.useRef(``),k=Q.useRef(null),A=p(e=>e.todoPanelHeight),j=p(e=>e.setTodoPanelHeight),M=p(e=>e.notesPanelHeight),N=p(e=>e.setNotesPanelHeight),[F,I]=Q.useState(!1),L=Q.useRef(0),R=Q.useRef(A),z=yn(e=>e.currentSessionId),B=yn(e=>e.createSession),H=yn(e=>e.initializeNewOpenChamberSession),U=yn(e=>e.sendMessage),ee=yn(e=>e.setCurrentSession),te=dt(e=>e.setPendingInputText),W=Pe(e=>e.currentDirectory),ne=p(e=>e.openContextPanelTab),G=p(e=>e.setActiveMainTab),re=p(e=>e.setSessionSwitcherOpen),K=p(e=>e.padding),ie=Q.useCallback(async(t,n)=>{if(!e)return!1;let r=e.id,i=(Pu.get(r)??Promise.resolve()).catch(()=>void 0).then(()=>Bt(e,{notes:t,todos:n}));Pu.set(r,i);try{let e=await i;return e||J.error(a(`rightSidebar.contextNotesTodo.toast.saveNotesFailed`)),e}finally{Pu.get(r)===i&&Pu.delete(r)}},[e,a]);Q.useEffect(()=>{if(!e){l(``),d([]),b([]),m(``),v(new Set);return}let t=!1;return s(!0),(async()=>{try{let n=await At(e),r=await Promise.all(n.plans.map(e=>Lu(e,a(`rightSidebar.contextNotesTodo.plan.defaultTitle`))));if(t)return;l(n.notes),d(zu(n.todos)),b(r),O.current=n.notes,D.current=!0,m(``),v(new Set)}catch{t||(J.error(a(`rightSidebar.contextNotesTodo.toast.loadNotesFailed`)),l(``),d([]),b([]),O.current=``,D.current=!0)}finally{t||s(!1)}})(),()=>{t=!0}},[T,e,a]),Q.useEffect(()=>{if(!e)return;let t=t=>{let n=t.detail;n?.projectId&&n.projectId!==e.id||E(e=>e+1)};return window.addEventListener(`openchamber:project-plan-saved`,t),window.addEventListener(`openchamber:project-notes-updated`,t),()=>{window.removeEventListener(`openchamber:project-plan-saved`,t),window.removeEventListener(`openchamber:project-notes-updated`,t)}},[e]),Q.useEffect(()=>{if(u.length<7)return;let e=Iu(u.length,K),t=Fu(K)*Mu;A!==e&&(A<t||A>e)&&j(e)},[u.length,K,A,j]),Q.useEffect(()=>{if(!F)return;let e=e=>{let t=e.clientY-L.current,n=Math.min(Fu(K)*Nu,Math.max(Fu(K)*Mu,R.current+t));j(n)},t=()=>{I(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),window.addEventListener(`pointercancel`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,t)}},[F,K,j]);let ae=Q.useCallback(e=>{I(!0),L.current=e.clientY,R.current=A,e.preventDefault()},[A]),oe=Q.useCallback(()=>{k.current!==null&&(window.clearTimeout(k.current),k.current=null)},[]),se=Q.useCallback(()=>{oe(),O.current=c,ie(c,u)},[oe,c,ie,u]);Q.useEffect(()=>{if(!(!e||!D.current)&&c!==O.current)return k.current=window.setTimeout(()=>{k.current=null,O.current=c,ie(c,u)},400),()=>{oe()}},[oe,c,ie,e,u]),Q.useEffect(()=>()=>oe(),[oe]);let ce=Q.useCallback(()=>{let e=f.trim();if(!e)return;let t=Bu(u,{id:Ru(),text:e.slice(0,120),completed:!1,createdAt:Date.now()});d(t),m(``),ie(c,t)},[f,c,ie,u]),le=Q.useCallback(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=Q.useCallback((e,t)=>{let n=u.find(t=>t.id===e);if(!n||n.completed===t)return;let r=u.filter(t=>t.id!==e),i={...n,completed:t},a=t?[...r,i]:Bu(r,i);d(a),ie(c,a)},[c,ie,u]),de=Q.useCallback(e=>{let t=u.filter(t=>t.id!==e);d(t),ie(c,t)},[c,ie,u]),fe=Q.useCallback(()=>{let e=u.filter(e=>!e.completed);e.length!==u.length&&(d(e),ie(c,e))},[c,ie,u]),pe=Q.useCallback(e=>{let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=u.findIndex(e=>e.id===t.id),i=u.findIndex(e=>e.id===n.id);if(r===-1||i===-1)return;let a=zu(Do(u,r,i));d(a),ie(c,a)},[c,ie,u]),me=wo(_o(So,{activationConstraint:{distance:8}})),he=f.slice(0,120),ge=u.reduce((e,t)=>e+ +!!t.completed,0),_e=Q.useCallback(()=>{G(`chat`),re(!1)},[G,re]),ve=Q.useCallback((t,n)=>{!e||h||S({kind:`session`,todoId:t,todoText:n})},[e,h]),ye=Q.useCallback(e=>{if(!z){J.error(a(`rightSidebar.contextNotesTodo.toast.noActiveSession`));return}_e();let t=`\`\`\`md\n${e}\n\`\`\``;te(t,`append`),J.success(a(`rightSidebar.contextNotesTodo.toast.sentToCurrentSession`)),r?.()},[z,r,_e,te,a]),be=Q.useCallback((t,r)=>{if(!(!e||h)){if(!n){J.error(a(`rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo`));return}S({kind:`worktree`,todoId:t,todoText:r})}},[n,e,h,a]),xe=Q.useCallback(async t=>{if(!e||!x)return;let i=await st(`plan.todo.visible`,{todo_text:x.todoText}),o=[{synthetic:!0,text:await st(`plan.todo.instructions`,{todo_text:x.todoText})}];w(!0),g(x.todoId);try{_e();let s=null,c=e.path;if(x.kind===`worktree`){if(!n){J.error(a(`rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo`));return}let t=await Pa(e.path,Za());if(!t?.id)return;s=t.id,c=t.path}else{let t=await B(void 0,e.path,null);if(!t?.id){J.error(a(`rightSidebar.contextNotesTodo.toast.createSessionFailed`));return}s=t.id,c=t.directory??e.path,H(t.id,wt.getState().agents??[])}if(!s)return;let l=kt.getState();l.saveSessionModelSelection(s,t.providerID,t.modelID),t.agent.trim()&&(l.saveSessionAgentSelection(s,t.agent),l.saveAgentModelForSession(s,t.agent,t.providerID,t.modelID),l.saveAgentModelVariantForSession(s,t.agent,t.providerID,t.modelID,t.variant||void 0)),ee(s,c),await U(i,t.providerID,t.modelID,t.agent.trim()||void 0,void 0,void 0,o,t.variant||void 0),J.success(x.kind===`worktree`?a(`rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession`):a(`rightSidebar.contextNotesTodo.toast.sentToNewSession`)),S(null),r?.()}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.sendTodoFailed`),t?{description:t}:void 0)}finally{w(!1),g(null)}},[n,B,H,r,x,e,_e,U,ee,a]),Se=Q.useRef(null),[Ce,we]=Q.useState(!1),[Te,Ee]=Q.useState(null),De=Q.useCallback(async t=>{if(!(!e||Te)){Ee(t);try{if(!await _n(e,t)){J.error(a(`rightSidebar.contextNotesTodo.toast.deletePlanFailed`));return}b(e=>e.filter(e=>e.id!==t)),window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}}))}finally{Ee(null)}}},[Te,e,a]),Oe=Q.useCallback(async()=>{if(!e||Ce)return;let t=await P({defaultPath:e.path,filters:[{name:`Plan files`,extensions:[`md`,`markdown`,`txt`]},{name:`All files`,extensions:[`*`]}]});if(t.success&&t.path){we(!0);try{let n=new URLSearchParams({path:t.path,allowOutsideWorkspace:`true`});t.outsideFileGrant&&n.set(`outsideFileGrant`,t.outsideFileGrant);let r=await V(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(!r.ok){J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`));return}let i=await r.text();if(!i.trim()){J.error(a(`rightSidebar.contextNotesTodo.toast.planFileEmpty`));return}let o=t.path.split(`/`).pop()?.replace(/\.(md|markdown|txt)$/i,``).trim()||``;if(!await It(e,i,o)){J.error(a(`rightSidebar.contextNotesTodo.toast.importPlanFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}})),J.success(a(`rightSidebar.contextNotesTodo.toast.planImported`))}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`),t?{description:t}:void 0)}finally{we(!1)}}else t.error===`Native file picker not available`&&Se.current?.click()},[Ce,e,a]),ke=Q.useCallback(async t=>{if(!(!e||!t)){we(!0);try{let n=await t.text();if(!n.trim()){J.error(a(`rightSidebar.contextNotesTodo.toast.planFileEmpty`));return}let r=t.name.replace(/\.(md|markdown|txt)$/i,``).trim();if(!await It(e,n,r)){J.error(a(`rightSidebar.contextNotesTodo.toast.importPlanFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}})),J.success(a(`rightSidebar.contextNotesTodo.toast.planImported`))}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`),t?{description:t}:void 0)}finally{we(!1)}}},[e,a]),Ae=Q.useCallback(t=>{let n=e?.path?.trim(),r=W?.trim()||n;r&&ne(r,{mode:`plan`,targetPath:t.path,dedupeKey:t.path,label:t.title})},[W,ne,e]);return e?(0,$.jsxs)(`div`,{className:Y(`w-full min-w-0 space-y-3 p-3`,i),children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-semibold text-foreground`,title:e.path,children:a(`rightSidebar.contextNotesTodo.notes.title`,{project:t?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[c.length,`/`,at]})]}),(0,$.jsx)(Ni,{value:c,onChange:e=>l(e.target.value.slice(0,at)),onBlur:se,placeholder:a(`rightSidebar.contextNotesTodo.notes.placeholder`),resizedHeight:M,onResizeHeightChange:N,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`rightSidebar.contextNotesTodo.todo.title`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:u.length===1?a(`rightSidebar.contextNotesTodo.todo.itemsSingle`,{count:u.length}):a(`rightSidebar.contextNotesTodo.todo.itemsPlural`,{count:u.length})}),(0,$.jsx)(`button`,{type:`button`,onClick:fe,disabled:o||ge===0,className:`typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,children:a(`rightSidebar.contextNotesTodo.todo.clearCompleted`)})]}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[he.length,`/`,120]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Ri,{value:he,onChange:e=>m(e.target.value.slice(0,120)),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ce())},placeholder:a(`rightSidebar.contextNotesTodo.todo.inputPlaceholder`),disabled:o,className:`h-8`}),(0,$.jsx)(`button`,{type:`button`,onClick:ce,disabled:o||he.trim().length===0,className:`inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.addAria`),title:a(`rightSidebar.contextNotesTodo.todo.addAria`),children:(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:Y(`overflow-y-auto rounded-lg border border-border/60 bg-background/40`,F&&`transition-none`),style:u.length<7?void 0:{height:`${A}px`,maxHeight:`${A}px`},children:u.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.todo.empty`)}):(0,$.jsx)(Co,{sensors:me,collisionDetection:bo,onDragEnd:pe,children:(0,$.jsx)(Ao,{items:u.map(e=>e.id),strategy:ko,children:(0,$.jsx)(`ul`,{className:`divide-y divide-border/50`,children:u.map(e=>{let t=_.has(e.id);return(0,$.jsx)(Vu,{id:e.id,children:r=>(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5 px-2.5 py-1.5`,t?`items-start`:`items-center`),children:[(0,$.jsx)(`button`,{type:`button`,ref:r.setActivatorNodeRef,...r.attributes,...r.listeners,onClick:e=>{e.preventDefault(),e.stopPropagation()},className:`flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.reorder`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.reorder`,{text:e.text}),children:(0,$.jsx)(X,{name:`draggable`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:`flex h-6 items-center`,children:(0,$.jsx)(Si,{checked:e.completed,onChange:t=>ue(e.id,t),ariaLabel:a(`rightSidebar.contextNotesTodo.todo.actions.markComplete`,{text:e.text})})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>le(e.id),className:Y(`block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground`,t?`whitespace-normal break-words`:`overflow-hidden text-ellipsis whitespace-nowrap`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,e.completed&&`text-muted-foreground line-through`),title:t?void 0:e.text,"aria-label":a(t?`rightSidebar.contextNotesTodo.todo.actions.collapse`:`rightSidebar.contextNotesTodo.todo.actions.expand`,{text:e.text}),children:e.text}),(0,$.jsxs)(`div`,{className:`flex h-6 items-center gap-0.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>de(e.id),className:`inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.delete`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.delete`,{text:e.text}),children:(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`})}),(0,$.jsxs)(ea,{children:[(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:h===e.id,className:`inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.send`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.send`,{text:e.text}),children:(0,$.jsx)(X,{name:`send-plane`,className:`h-3.5 w-3.5`})})}),(0,$.jsxs)($i,{align:`end`,className:`w-56`,children:[(0,$.jsx)(ca,{onClick:()=>ye(e.text),children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.currentSession`)}),(0,$.jsx)(ca,{onClick:()=>ve(e.id,e.text),children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.newSession`)}),(0,$.jsx)(ca,{onClick:()=>void be(e.id,e.text),disabled:!n,children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession`)})]})]})]})]})},e.id)})})})})}),u.length>=7&&(0,$.jsx)(`div`,{className:Y(`h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,F&&`bg-[var(--interactive-border)]`),onPointerDown:ae,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.resizeAria`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`rightSidebar.contextNotesTodo.plans.title`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:y.length===1?a(`rightSidebar.contextNotesTodo.plans.filesSingle`,{count:y.length}):a(`rightSidebar.contextNotesTodo.plans.filesPlural`,{count:y.length})})]}),(0,$.jsx)(`input`,{ref:Se,type:`file`,accept:`.md,.markdown,.txt,text/markdown,text/plain`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;ke(t),e.currentTarget.value=``}}),(0,$.jsx)(`button`,{type:`button`,onClick:Oe,disabled:!e||Ce,className:`inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.plans.importFromFile`),title:a(`rightSidebar.contextNotesTodo.plans.importFromFile`),children:(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40`,children:y.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.plans.empty`)}):(0,$.jsx)(`ul`,{className:`divide-y divide-border/50`,children:y.map(e=>(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2.5 py-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Ae(e),className:`flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label text-foreground`,children:e.title}),(0,$.jsx)(`span`,{className:`flex-shrink-0 typography-micro text-muted-foreground`,children:new Date(e.createdAt).toLocaleDateString(Qe())})]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void De(e.id),disabled:Te===e.id,className:`inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,title:a(`rightSidebar.contextNotesTodo.plans.deletePlan`),"aria-label":a(`rightSidebar.contextNotesTodo.plans.deletePlanWithTitle`,{title:e.title}),children:(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`})})]},e.id))})})]}),(0,$.jsx)(bu,{open:x!==null,onOpenChange:e=>{!e&&!C&&S(null)},target:x?.kind??`session`,projectDirectory:e?.path??null,submitting:C,onConfirm:xe})]}):(0,$.jsx)(`div`,{className:Y(`w-full min-w-0 p-3`,i),children:(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.empty.selectProject`)})})},Uu=12,Wu=[{id:`left`,x:22,y:58,delay:0,radius:120,colorVar:`--status-success`},{id:`center`,x:50,y:42,delay:120,radius:150,colorVar:`--primary-base`},{id:`right`,x:78,y:55,delay:200,radius:130,colorVar:`--status-info`}],Gu=e=>{let t=(0,Rc.c)(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:o,onComplete:s}=e,c=r===void 0?0:r,l=a===void 0?900:a,u=o===void 0?Wu:o,d=Q.useRef(!1),f,p;t[0]!==n||t[1]!==s?(f=()=>{!n&&d.current&&s?.(),n&&(d.current=!0)},p=[n,s],t[0]=n,t[1]=s,t[2]=f,t[3]=p):(f=t[2],p=t[3]),Q.useEffect(f,p);let m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m=Array.from({length:Uu},Ku),t[4]=m):m=t[4];let h=m;if(!n)return null;let g;t[5]===i?g=t[6]:(g=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 Ku(e,t){let n=Math.PI*2*t/Uu;return{x:Math.cos(n),y:Math.sin(n),delay:t*18}}var qu=e=>{let t=(0,Rc.c)(13),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{durationMs:r}=n,i=r===void 0?3400:r,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a={isActive:!1,cycle:0},t[2]=a):a=t[2];let[o,s]=Q.useState(a),c=Q.useRef(null),l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{c.current&&=(window.clearTimeout(c.current),null)},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{u(),s(Ju)},t[4]=d):d=t[4];let f=d,p;t[5]===i?p=t[6]:(p=()=>{u(),s(Yu),c.current=window.setTimeout(()=>{s(Xu),c.current=null},i)},t[5]=i,t[6]=p);let m=p,h,g;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>()=>u(),g=[u],t[7]=h,t[8]=g):(h=t[7],g=t[8]),Q.useEffect(h,g);let _;return t[9]!==o.cycle||t[10]!==o.isActive||t[11]!==m?(_={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:m,dismissFireworks:f},t[9]=o.cycle,t[10]=o.isActive,t[11]=m,t[12]=_):_=t[12],_};function Ju(e){return e.isActive?{...e,isActive:!1}:e}function Yu(e){return{isActive:!0,cycle:e.cycle+1}}function Xu(e){return e.isActive?{...e,isActive:!1}:e}var Zu=Q.createContext(void 0),Qu=e=>{let t=(0,Rc.c)(10),{children:n}=e,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=qu(),s;t[0]!==o||t[1]!==a?(s={triggerFireworks:a,dismissFireworks:o},t[0]=o,t[1]=a,t[2]=s):s=t[2];let c=s,l;t[3]!==i||t[4]!==r?(l=(0,$.jsx)(Gu,{isActive:r,burstKey:i}),t[3]=i,t[4]=r,t[5]=l):l=t[5];let u;return t[6]!==n||t[7]!==l||t[8]!==c?(u=(0,$.jsxs)(Zu.Provider,{value:c,children:[n,l]}),t[6]=n,t[7]=l,t[8]=c,t[9]=u):u=t[9],u},$u=()=>{let e=Q.useContext(Zu);if(!e)throw Error(`useFireworksCelebration must be used within FireworksProvider`);return e},ed=`gitmojiCache`,td=6048e5,nd=`1`,rd=`https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json`,id=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.emoji==`string`&&typeof t.code==`string`&&typeof t.description==`string`},ad=()=>{if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(ed);if(!e)return null;let t=JSON.parse(e);return!t||t.version!==nd||typeof t.fetchedAt!=`number`||!Array.isArray(t.gitmojis)?null:{gitmojis:t.gitmojis.filter(id),fetchedAt:t.fetchedAt,version:t.version}}catch{return null}},od=e=>{if(!(typeof window>`u`))try{let t={gitmojis:e,fetchedAt:Date.now(),version:nd};window.localStorage.setItem(ed,JSON.stringify(t))}catch{return}},sd=e=>Date.now()-e.fetchedAt<td,cd=null,ld=new Set,ud=async()=>{if(cd)return cd;let e=(async()=>{try{let e=await fetch(rd);if(!e.ok)throw Error(`Failed to load gitmojis: ${e.statusText}`);let t=await e.json(),n=Array.isArray(t.gitmojis)?t.gitmojis.filter(id):[];return od(n),ld.forEach(e=>e(n)),n}catch(e){console.warn(`Failed to load gitmoji list:`,e);let t=[];return ld.forEach(e=>e(t)),t}finally{cd=null}})();return cd=e,e},dd=e=>{let[t,n]=Q.useState(()=>e?ad()?.gitmojis??[]:[]),[r,i]=Q.useState(!1),a=Q.useRef(e);return a.current=e,Q.useEffect(()=>{if(!e){ld.delete(n),n([]),i(!1);return}let t=ad();if(t&&(n(t.gitmojis),sd(t)))return;ld.add(n),i(!0);let r=!1;return ud().finally(()=>{!r&&a.current&&i(!1)}),()=>{r=!0,ld.delete(n)}},[e]),{gitmojis:t,isLoading:r,ensureLoaded:Q.useCallback(async()=>{if(!a.current)return[];if(t.length>0)return t;let e=ad();return e&&sd(e)?e.gitmojis:ud()},[t])}},fd=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)};function pd(e,t,n){let r=(0,Rc.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([br(e),lr(e)]).catch(md);if(r)return;let o=fd(t),s=fd(i);if(!o||!s||s===o)return;let c=n||``,l=s.split(`/`).filter(Boolean).pop()||s;a({source:`sdk`,path:s,projectDirectory:o,branch:c,label:c||l,name:l,worktreeRoot:s,worktreeStatus:`ready`,headState:c?`branch`:`unborn`,worktreeSource:`existing`})})(),()=>{r=!0}},s=[e,t,n],r[0]=n,r[1]=e,r[2]=t,r[3]=o,r[4]=s):(o=r[3],s=r[4]),Q.useEffect(o,s),t??i}function md(){return[``,``]}var hd=({open:e,onOpenChange:t,directory:n,hasUncommittedChanges:r,hasStagedChanges:i=!1,uncommittedFileCount:a,onChanged:o})=>{let{t:s}=Xe(),[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 ur(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 hr(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 pr(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 Tr(n,{ref:e.ref}),t===`pop`&&await mr(n,{ref:e.ref}),t===`drop`&&await gr(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)(cr,{open:e,onOpenChange:t,children:(0,$.jsxs)(ar,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(or,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`h-5 w-5`}),s(`gitView.stashes.title`)]}),(0,$.jsx)(sr,{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)(Ri,{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)(Ri,{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)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{children:t===0&&!f.trim()?s(`gitView.stashes.latestLabel`):s(`gitView.stashes.itemNumber`,{number:t+1})})}),(0,$.jsx)(Bi,{sideOffset:6,children:e.ref})]}),` · `,e.relativeTime,` · `,typeof v[e.ref]==`number`?s(`gitView.stashes.fileCount`,{count:v[e.ref]}):s(`gitView.stashes.fileCountLoading`)]})]}),(0,$.jsxs)(`div`,{className:`mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100`,children:[(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.apply`),loading:g===`apply:${e.ref}`,onClick:()=>w(e,`apply`),disabled:T,children:(0,$.jsx)(X,{name:`inbox-unarchive`,className:`size-4`})}),(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.pop`),loading:g===`pop:${e.ref}`,onClick:()=>w(e,`pop`),disabled:T,children:(0,$.jsx)(X,{name:`inbox-unarchive-fill`,className:`size-4`})}),(0,$.jsx)(gd,{label:s(`gitView.stashes.actions.drop`),loading:g===`drop:${e.ref}`,onClick:()=>w(e,`drop`),disabled:T,destructive:!0,children:(0,$.jsx)(X,{name:`delete-bin`,className:`size-4`})})]})]},e.ref))})]})})},gd=e=>{let t=(0,Rc.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)(zi,{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)(Bi,{sideOffset:6,children:n}),t[12]=n,t[13]=p);let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(Hi,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m},_d=e=>{let t=(0,Rc.c)(16),{onOpenStashes:n}=e,{t:r}=Xe(),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},vd=8,yd=e=>{let t=(0,Rc.c)(18),{laned:n,totalLanes:r,isExpanded:i}=e,{lane:a,color:o,connectors:s}=n,c=Math.max(r,a+1)*vd+vd/2,l=Q.useRef(null),u=Q.useRef(null),d;t[0]!==o||t[1]!==s||t[2]!==a||t[3]!==c?(d=()=>{let e=l.current,t=u.current;if(!e||!t)return;let n=e.offsetHeight;if(n===0)return;let r=window.devicePixelRatio||1;t.width=c*r,t.height=n*r;let i=t.getContext(`2d`);if(!i)return;i.scale(r,r),i.clearRect(0,0,c,n);let d=n/2,f=a*vd+vd/2,p=getComputedStyle(t),m=p.getPropertyValue(`--surface-muted-foreground`).trim()||p.color,h=e=>{if(!e.startsWith(`var(`))return e;let t=e.slice(4,-1).trim();return p.getPropertyValue(t).trim()||m},g=[...s].sort(xd);for(let e of g){let t=e.fromLane*vd+vd/2,r=e.toLane*vd+vd/2,a=e.type===`passing`?.72:e.type===`branch-out`||e.type===`merge-in`?.95:1;i.beginPath(),i.strokeStyle=h(e.color),i.globalAlpha=a,i.lineWidth=1.25,i.lineCap=`round`;bb64:switch(e.type){case`passing`:case`commit-lane`:i.moveTo(t,0),i.lineTo(t,n);break bb64;case`top-stub`:i.moveTo(t,0),i.lineTo(t,d);break bb64;case`bottom-stub`:i.moveTo(t,d),i.lineTo(t,n);break bb64;case`branch-out`:{let e=(d+n)/2;i.moveTo(f,d),i.bezierCurveTo(f,e,r,e,r,n);break bb64}case`merge-in`:{let e=d/2;i.moveTo(t,0),i.bezierCurveTo(t,e,f,e,f,d);break bb64}default:continue}i.stroke(),i.globalAlpha=1}let _=p.getPropertyValue(`--background`).trim()||p.getPropertyValue(`--surface-background`).trim();i.beginPath(),i.arc(f,d,4,0,Math.PI*2),i.fillStyle=h(o),i.fill(),i.beginPath(),i.arc(f,d,5,0,Math.PI*2),i.strokeStyle=_||m,i.lineWidth=2,i.stroke()},t[0]=o,t[1]=s,t[2]=a,t[3]=c,t[4]=d):d=t[4];let f;t[5]!==o||t[6]!==s||t[7]!==i||t[8]!==a||t[9]!==n||t[10]!==r||t[11]!==c?(f=[n,a,o,s,r,i,c],t[5]=o,t[6]=s,t[7]=i,t[8]=a,t[9]=n,t[10]=r,t[11]=c,t[12]=f):f=t[12],Q.useLayoutEffect(d,f);let p;t[13]===c?p=t[14]:(p={width:c,height:`100%`,position:`relative`,flexShrink:0,overflow:`hidden`},t[13]=c,t[14]=p);let m;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`canvas`,{ref:u,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,display:`block`}}),t[15]=m):m=t[15];let h;return t[16]===p?h=t[17]:(h=(0,$.jsx)(`div`,{ref:l,style:p,children:m}),t[16]=p,t[17]=h),h};function bd(e){return e===`branch-out`||e===`merge-in`}function xd(e,t){let n=bd;return!!n(e.type)-+!!n(t.type)}var Sd=15e3,Cd=500,wd=12,Td=8388608,Ed=e=>typeof e==`string`?0:(e.original?.length??0)+(e.modified?.length??0),Dd=e=>{if(e.size<=wd){let t=0;for(let n of e.values())t+=Ed(n);if(t<=Td)return e}let t=Array.from(e.entries()).reverse(),n=new Map,r=0;for(let[e,i]of t){if(n.size>=wd)continue;let t=Ed(i);r+t>Td&&n.size>0||(n.set(e,i),r+=t)}return new Map(Array.from(n.entries()).reverse())};function Od(e,t){let n=new Date(e);return Number.isNaN(n.getTime())?e:va(n,t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function kd(e){switch(e){case`A`:return`text-[var(--status-success)]`;case`D`:return`text-[var(--status-error)]`;case`M`:return`text-[var(--status-warning)]`;case`R`:return`text-[var(--status-info)]`;default:return`text-muted-foreground`}}function Ad(e){return e?e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.startsWith(`HEAD ->`);return{label:t?e.replace(`HEAD -> `,``):e.replace(`tag: `,``),isHead:t,isTag:e.startsWith(`tag: `)}}):[]}var jd=Q.memo(({entry:e,mode:t=`history`,laned:n,totalLanes:r,isExpanded:i,onToggle:a,files:o,isLoadingFiles:s,onCopyHash:c,directory:l,onConflict:u,onActionSuccess:d})=>{let{t:f}=Xe(),m=p(e=>e.timeFormatPreference),h=t===`graph`,[g,_]=Q.useState(null),[v,y]=Q.useState(!1),[b,x]=Q.useState(``),[S,C]=Q.useState(null),[w,T]=Q.useState(new Set),[E,D]=Q.useState(new Map),[O,k]=Q.useState(new Set),A=async()=>{if(l){_(`checkout`);try{await wr(l,e.hash),J.success(f(`gitView.history.actions.detachedHead`)),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},j=async()=>{if(!(!l||!b.trim())){_(`createBranch`);try{await Sr(l,b.trim(),e.hash),y(!1),x(``),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},M=async()=>{if(l){_(`cherryPick`);try{let t=await vr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`cherry-pick`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},N=async()=>{if(l){_(`revert`);try{let t=await yr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`revert`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},P=async(t,n=!1)=>{if(!(!l||g!==null)){_(`reset`);try{await fr(l,e.hash,t,n),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},F=async()=>{if(!S)return;let e=S;switch(C(null),e){case`checkout`:return A();case`cherryPick`:return M();case`revert`:return N();case`merge`:return I();case`rebase`:return L();case`resetSoft`:return P(`soft`);case`resetMixed`:return P(`mixed`);case`resetHard`:return P(`hard`,!0)}},I=async()=>{if(l){_(`merge`);try{let t=await Er(l,{branch:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`merge`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},L=async()=>{if(l){_(`rebase`);try{let t=await dr(l,{onto:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`rebase`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},R=Q.useCallback(async t=>{let n=t.path;if(!l){D(e=>new Map(e).set(n,`error`));return}D(e=>Dd(new Map(e).set(n,`loading`)));try{let r=xr(l,e.hash,t.path,!1),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${Sd}ms`)),Sd)}),a=await Promise.race([r,i]);D(e=>Dd(new Map(e).set(n,a)))}catch{D(e=>new Map(e).set(n,`error`))}},[l,e.hash]),z=Q.useCallback(async e=>{let t=e.path;if(e.changeType===`R`||e.isBinary){T(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n});return}let n=E.get(t);if(w.has(t)&&n&&n!==`error`){T(e=>{let n=new Set(e);return n.delete(t),n});return}T(e=>{let n=new Set(e);return n.add(t),n}),!(n&&n!==`error`)&&(e.insertions+e.deletions>Cd&&!O.has(t)||await R(e))},[E,O,R,w]);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`,h?`hover:bg-[var(--interactive-hover)]/40`:i?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[h&&n&&r!==void 0?(0,$.jsx)(`div`,{className:`-my-2 shrink-0 self-stretch`,children:(0,$.jsx)(yd,{laned:n,totalLanes:r,isExpanded:i})}):(0,$.jsx)(`div`,{className:`h-2 w-2 translate-y-2 rounded-full shrink-0`,style:{backgroundColor:`var(--status-success)`},"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[h?(()=>{let t=Ad(e.refs);return t.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-0.5`,children:t.map(e=>(0,$.jsx)(`span`,{className: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,m),children:Od(e.date,m)})]}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`code`,{className:`shrink-0 font-mono`,children:e.hash.slice(0,8)}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{sideOffset:8,children:f(`gitView.history.copySha`)})]})]})]})]}),i&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 pl-8 border-t border-border/40`,children:[h&&S?(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.${S}Confirm`)}),(0,$.jsxs)(Z,{variant:`destructive`,size:`xs`,className:`h-6 shrink-0`,disabled:g!==null,onClick:e=>{e.stopPropagation(),F()},children:[g===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:g!==null,onClick:e=>{e.stopPropagation(),C(null)},children:f(`gitView.history.actions.cancelButton`)})]}):h?(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:g!==null,onClick:e=>{e.stopPropagation(),C(`checkout`)},children:f(`gitView.history.actions.checkout`)}),v?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&(y(!1),x(``))},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:!b.trim()||g!==null,onClick:e=>{e.stopPropagation(),j()},children:[g===`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(),y(!0)},children:f(`gitView.history.actions.createBranch`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`cherryPick`)},children:f(`gitView.history.actions.cherryPick`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`revert`)},children:f(`gitView.history.actions.revert`)}),(0,$.jsxs)(ea,{children:[(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>e.stopPropagation(),children:[g===`reset`?(0,$.jsx)(X,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.reset`)]})}),(0,$.jsx)($i,{align:`start`,className:`min-w-max`,children:[`soft`,`mixed`,`hard`].map(e=>(0,$.jsx)(ca,{disabled:g!==null,onSelect:t=>{t.stopPropagation(),C(`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:g!==null,onClick:e=>{e.stopPropagation(),C(`merge`)},children:f(`gitView.history.actions.merge`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`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:()=>z(e),className:Y(`w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1`,w.has(e.path)?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[(0,$.jsx)(`span`,{className:Y(`font-semibold w-3 text-center shrink-0`,kd(e.changeType)),children:e.changeType}),(0,$.jsx)(`span`,{className:`truncate text-foreground min-w-0`,title:e.path,children:e.path}),!e.isBinary&&(0,$.jsxs)(`span`,{className:`shrink-0`,children:[(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,e.insertions]}),(0,$.jsx)(`span`,{className:`text-muted-foreground mx-0.5`,children:`/`}),(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,e.deletions]})]}),e.isBinary&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:f(`gitView.history.binary`)}),(0,$.jsx)(X,{name:w.has(e.path)?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),w.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(!O.has(e.path)&&t>Cd)return(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-semibold text-foreground`,children:f(`gitView.history.largeDiffTitle`,{count:t})}),(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground`,children:f(`gitView.history.largeDiffDescription`)}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`xs`,className:`h-6 px-0 text-primary hover:bg-transparent hover:underline`,onClick:()=>{k(t=>new Set(t).add(e.path)),R(e)},children:f(`gitView.history.renderDiffAnyway`)})]});let n=E.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:()=>z(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)(ec,{original:n.original,modified:n.modified,language:Io(e.path)||``,fileName:e.path,renderSideBySide:!1,layout:`inline`,enableComments:!1})})()})]},e.path))})]})]})}),Md=[`var(--chart-1)`,`var(--chart-2)`,`var(--chart-3)`,`var(--chart-4)`,`var(--chart-5)`,`var(--syntax-keyword)`,`var(--syntax-string)`,`var(--status-info)`];function Nd(e){return Md[e%Md.length]}function Pd(e){if(e.length===0)return[];let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r],a=[];for(let e=0;e<t.length;e++)t[e]===i.hash&&a.push(e);let o=a.length>0?a[0]:-1;if(o===-1){let e=t.indexOf(null);e===-1?(o=t.length,t.push(null)):o=e}let s=a.slice(1),c=Nd(o),l=t[o]===i.hash,u=i.parents.length>0;u?t[o]=i.parents[0]:t[o]=null;let d=[];for(let e=1;e<i.parents.length;e++){let n=i.parents[e],r=t.indexOf(n);if(r!==-1)d.push(r);else{let e=t.indexOf(null),r=e===-1?t.length:e;t[r]=n,r===t.length&&t.push(n),d.push(r)}}let f=[];l&&u?f.push({fromLane:o,toLane:o,color:c,type:`commit-lane`}):l&&!u?f.push({fromLane:o,toLane:o,color:c,type:`top-stub`}):!l&&u&&f.push({fromLane:o,toLane:o,color:c,type:`bottom-stub`});for(let e of s)f.push({fromLane:e,toLane:o,color:Nd(e),type:`merge-in`}),t[e]=null;for(let e of d)f.push({fromLane:o,toLane:e,color:Nd(e),type:`branch-out`});for(let e=0;e<t.length;e++)t[e]!==null&&e!==o&&(d.includes(e)||f.push({fromLane:e,toLane:e,color:Nd(e),type:`passing`}));n.push({commit:i,lane:o,color:c,connectors:f})}return n}var Fd=[{labelKey:`gitView.history.logSize25`,value:25},{labelKey:`gitView.history.logSize50`,value:50},{labelKey:`gitView.history.logSize100`,value:100}],Id=e=>{let t=(0,Rc.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}=Xe(),[C,w]=Q.useState(!0),T=v===`graph`,E;t[0]!==T||t[1]!==r?(E=T&&r?Pd(r.all):[],t[0]=T,t[1]=r,t[2]=E):E=t[2];let D=E,O;t[3]===D?O=t[4]:(O=Math.max(1,...D.map(Ld)),t[3]=D,t[4]=O);let k=O,A;t[5]===D?A=t[6]:(A=new Map(D.map(Rd)),t[5]=D,t[6]=A);let j=A;if(!r)return null;let M=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<r.all.length,N=x!==null&&x.insertBeforeIndex===r.all.length,P=M||N,F;t[7]!==x||t[8]!==M||t[9]!==N||t[10]!==r.all?(F=M?r.all.slice(0,x.insertBeforeIndex):N?r.all:[],t[7]=x,t[8]=M,t[9]=N,t[10]=r.all,t[11]=F):F=t[11];let I=F,L;if(t[12]!==x||t[13]!==l||t[14]!==b||t[15]!==f||t[16]!==s||t[17]!==M||t[18]!==P||t[19]!==T||t[20]!==i||t[21]!==j||t[22]!==u||t[23]!==r.all||t[24]!==a||t[25]!==k||t[26]!==v||t[27]!==_||t[28]!==g||t[29]!==d||t[30]!==o||t[31]!==c||t[32]!==S||t[33]!==I){let e=M?r.all.slice(x.insertBeforeIndex):[],n;t[35]===x?.direction?n=t[36]:(n=x?.direction===`down`?(0,$.jsx)(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)(jd,{entry:e,mode:v,laned:T?j.get(e.hash):void 0,totalLanes:T?k:void 0,isExpanded:s.has(e.hash),onToggle:()=>c(e.hash),files:l.get(e.hash)??[],isLoadingFiles:u.has(e.hash),onCopyHash:d,directory:f,onConflict:g,onActionSuccess:_},e.hash))}),t[37]=l,t[38]=f,t[39]=s,t[40]=T,t[41]=j,t[42]=u,t[43]=k,t[44]=v,t[45]=_,t[46]=g,t[47]=d,t[48]=c,t[49]=m):m=t[49];let h=m,y;t[50]!==i||t[51]!==r.all.length||t[52]!==a||t[53]!==o||t[54]!==S?(y=r.all.length>=a?(0,$.jsx)(`div`,{className:`flex justify-center py-2 border-t border-border/40`,children:(0,$.jsx)(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;L=(0,$.jsx)(bi,{outerClassName:`min-h-0 ${b}`,className:`h-full w-full`,children:r.all.length===0?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:S(`gitView.history.noCommits`)})}):P&&x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0`,children:[I.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(I)}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsxs)(`span`,{className:`inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate`,title:x.branchName,children:x.branchName}),p]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`})]}),e.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(e)}):null]}),C]}):(0,$.jsxs)($.Fragment,{children:[h(r.all),C]})}),t[12]=x,t[13]=l,t[14]=b,t[15]=f,t[16]=s,t[17]=M,t[18]=P,t[19]=T,t[20]=i,t[21]=j,t[22]=u,t[23]=r.all,t[24]=a,t[25]=k,t[26]=v,t[27]=_,t[28]=g,t[29]=d,t[30]=o,t[31]=c,t[32]=S,t[33]=I,t[34]=L}else L=t[34];let R=L;if(!y){if(P){let e;return t[56]===R?e=t[57]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0`,children:R}),t[56]=R,t[57]=e),e}let e;return t[58]===R?e=t[59]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:R}),t[58]=R,t[59]=e),e}let z;t[60]===S?z=t[61]:(z=S(`gitView.history.title`),t[60]=S,t[61]=z);let B;t[62]===z?B=t[63]:(B=(0,$.jsx)(`h3`,{className:`typography-ui-header font-semibold text-foreground`,children:z}),t[62]=z,t[63]=B);let V;t[64]!==i||t[65]!==C||t[66]!==a||t[67]!==o||t[68]!==S?(V=C&&(0,$.jsx)(`div`,{onClick:zd,onPointerDown:Bd,children:(0,$.jsxs)(Di,{value:String(a),onValueChange:e=>o(Number(e)),disabled:i,children:[(0,$.jsx)(Li,{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)(Ci,{placeholder:S(`gitView.history.commitsPlaceholder`)})}),(0,$.jsx)(Ei,{children:Fd.map(e=>(0,$.jsx)(Ii,{value:String(e.value),children:S(e.labelKey)},e.value))})]})}),t[64]=i,t[65]=C,t[66]=a,t[67]=o,t[68]=S,t[69]=V):V=t[69];let H;t[70]===C?H=t[71]:(H=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]=H);let U;t[72]!==V||t[73]!==H?(U=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V,H]}),t[72]=V,t[73]=H,t[74]=U):U=t[74];let ee;t[75]!==B||t[76]!==U?(ee=(0,$.jsxs)(vc,{className:`flex w-full items-center justify-between px-3 h-10 hover:bg-transparent`,children:[B,U]}),t[75]=B,t[76]=U,t[77]=ee):ee=t[77];let te;t[78]===R?te=t[79]:(te=(0,$.jsx)(_c,{children:R}),t[78]=R,t[79]=te);let W;return t[80]!==C||t[81]!==ee||t[82]!==te?(W=(0,$.jsxs)(yc,{open:C,onOpenChange:w,className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[ee,te]}),t[80]=C,t[81]=ee,t[82]=te,t[83]=W):W=t[83],W};function Ld(e){return e.lane+1}function Rd(e){return[e.commit.hash,e]}function zd(e){return e.stopPropagation()}function Bd(e){return e.stopPropagation()}var Vd=e=>{let t=(0,Rc.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}=Xe(),f=yn(Hd),m=yn(Ud),h=dt(Wd),g=dt(Gd),_=p(Kd),[v,y]=Q.useState(!1),[b,x]=Q.useState(null),[S,C]=Q.useState(null),w,T;t[2]!==a||t[3]!==n||t[4]!==d?(w=()=>{!n||!a||(y(!0),C(null),x(null),_r(a).then(e=>{x(e)}).catch(e=>{let t=e instanceof Error?e.message:d(`gitView.conflict.loadFailed`);C(t)}).finally(()=>{y(!1)}))},T=[n,a,d],t[2]=a,t[3]=n,t[4]=d,t[5]=w,t[6]=T):(w=t[5],T=t[6]),Q.useEffect(w,T);let E;t[7]!==b||t[8]!==a||t[9]!==o?(E=async()=>{if(!b)return null;let e=o===`merge`?`merge`:`rebase`,t=b.headInfo||(o===`merge`?`MERGE_HEAD`:`REBASE_HEAD`),n=o===`merge`?`git commit --no-edit`:`git rebase --continue`;return{visibleText:await st(`git.conflict.resolve.visible`,{operation_label:e,head_ref:t}),instructionsText:await st(`git.conflict.resolve.instructions`,{operation_label:e,directory:a,operation:o,head_info:b.headInfo||`N/A`,continue_cmd:n}),payloadText:`${e} conflict context (JSON)\n${JSON.stringify({directory:a,operation:b.operation,headInfo:b.headInfo,statusPorcelain:b.statusPorcelain,unmergedFiles:b.unmergedFiles,diff:b.diff},null,2)}`}},t[7]=b,t[8]=a,t[9]=o,t[10]=E):E=t[10];let D=E,O;t[11]!==s||t[12]!==r?(O=()=>{s(),r(!1)},t[11]=s,t[12]=r,t[13]=O):O=t[13];let k=O,A;t[14]!==c||t[15]!==r?(A=()=>{c?.(),r(!1)},t[14]=c,t[15]=r,t[16]=A):A=t[16];let j=A,M;t[17]!==D||t[18]!==m||t[19]!==c||t[20]!==r||t[21]!==_||t[22]!==h||t[23]!==g||t[24]!==d?(M=async()=>{let e=await D();if(!e){J.error(d(`gitView.conflict.noDetailsAvailable`));return}if(!m){J.error(d(`gitView.conflict.noActiveSession`),{description:d(`gitView.conflict.noActiveSessionDescription`)});return}h(e.visibleText,`replace`),g([{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]),_(`chat`),c?.(),r(!1)},t[17]=D,t[18]=m,t[19]=c,t[20]=r,t[21]=_,t[22]=h,t[23]=g,t[24]=d,t[25]=M):M=t[25];let N=M,P;t[26]!==D||t[27]!==a||t[28]!==c||t[29]!==r||t[30]!==f||t[31]!==_||t[32]!==d?(P=async()=>{let e=await D();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}]}),_(`chat`),c?.(),r(!1)},t[26]=D,t[27]=a,t[28]=c,t[29]=r,t[30]=f,t[31]=_,t[32]=d,t[33]=P):P=t[33];let F=P,I,L,R,z,B,V,H,U,ee,te,W,ne,G,re,K,ie,ae,oe,se,ce,le,ue;if(t[34]!==b||t[35]!==u||t[36]!==m||t[37]!==k||t[38]!==j||t[39]!==N||t[40]!==F||t[41]!==v||t[42]!==S||t[43]!==r||t[44]!==n||t[45]!==o||t[46]!==d){let e=d(o===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),i=b?.unmergedFiles||u;R=cr,le=n,ue=r,L=ar,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)(or,{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)(sr,{children:c}),t[73]=c,t[74]=l),t[75]!==s||t[76]!==l?(K=(0,$.jsxs)(rr,{children:[s,l]}),t[75]=s,t[76]=l,t[77]=K):K=t[77],t[78]!==v||t[79]!==d?(ie=v&&(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]=v,t[79]=d,t[80]=ie):ie=t[80],t[81]!==S||t[82]!==d?(ae=S&&(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:S})}),t[81]=S,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(qd)})})]}),t[84]=i,t[85]=d,t[86]=oe):oe=t[86],t[87]!==b||t[88]!==d?(se=b?.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:b.headInfo})]}),t[87]=b,t[88]=d,t[89]=se):se=t[89],W=`flex flex-col gap-2 pt-2`;let f;t[90]===F?f=t[91]:(f=()=>{F()},t[90]=F,t[91]=f);let p=v||!b,h;t[92]===v?h=t[93]:(h=v?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`}),t[92]=v,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]!==p||t[98]!==h||t[99]!==g?(ne=(0,$.jsxs)(Z,{variant:`default`,onClick:f,disabled:p,className:`w-full gap-2`,children:[h,g]}),t[96]=f,t[97]=p,t[98]=h,t[99]=g,t[100]=ne):ne=t[100];let _;t[101]===N?_=t[102]:(_=()=>void N(),t[101]=N,t[102]=_);let y=v||!b||!m,x;t[103]===v?x=t[104]:(x=v?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`chat-1`,className:`size-4`}),t[103]=v,t[104]=x);let C;t[105]===d?C=t[106]:(C=d(`gitView.conflict.resolveCurrentSession`),t[105]=d,t[106]=C),t[107]!==_||t[108]!==y||t[109]!==x||t[110]!==C?(G=(0,$.jsxs)(Z,{variant:`outline`,onClick:_,disabled:y,className:`w-full gap-2`,children:[x,C]}),t[107]=_,t[108]=y,t[109]=x,t[110]=C,t[111]=G):G=t[111],ee=`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]!==j||t[115]!==w?(te=(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:j,className:`flex-1`,children:w}),t[114]=j,t[115]=w,t[116]=te):te=t[116],I=Z,z=`destructive`,B=`sm`,V=k,H=`flex-1`,U=d(`gitView.conflict.abortOperation`,{operation:e}),t[34]=b,t[35]=u,t[36]=m,t[37]=k,t[38]=j,t[39]=N,t[40]=F,t[41]=v,t[42]=S,t[43]=r,t[44]=n,t[45]=o,t[46]=d,t[47]=I,t[48]=L,t[49]=R,t[50]=z,t[51]=B,t[52]=V,t[53]=H,t[54]=U,t[55]=ee,t[56]=te,t[57]=W,t[58]=ne,t[59]=G,t[60]=re,t[61]=K,t[62]=ie,t[63]=ae,t[64]=oe,t[65]=se,t[66]=ce,t[67]=le,t[68]=ue}else I=t[47],L=t[48],R=t[49],z=t[50],B=t[51],V=t[52],H=t[53],U=t[54],ee=t[55],te=t[56],W=t[57],ne=t[58],G=t[59],re=t[60],K=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]!==I||t[118]!==z||t[119]!==B||t[120]!==V||t[121]!==H||t[122]!==U?(de=(0,$.jsx)(I,{variant:z,size:B,onClick:V,className:H,children:U}),t[117]=I,t[118]=z,t[119]=B,t[120]=V,t[121]=H,t[122]=U,t[123]=de):de=t[123];let fe;t[124]!==ee||t[125]!==te||t[126]!==de?(fe=(0,$.jsxs)(`div`,{className:ee,children:[te,de]}),t[124]=ee,t[125]=te,t[126]=de,t[127]=fe):fe=t[127];let pe;t[128]!==W||t[129]!==ne||t[130]!==G||t[131]!==fe?(pe=(0,$.jsxs)(`div`,{className:W,children:[ne,G,fe]}),t[128]=W,t[129]=ne,t[130]=G,t[131]=fe,t[132]=pe):pe=t[132];let me;t[133]!==re||t[134]!==K||t[135]!==ie||t[136]!==ae||t[137]!==oe||t[138]!==se||t[139]!==pe?(me=(0,$.jsxs)(`div`,{className:re,children:[K,ie,ae,oe,se,pe]}),t[133]=re,t[134]=K,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]!==L||t[142]!==ce||t[143]!==me?(he=(0,$.jsx)(L,{className:ce,children:me}),t[141]=L,t[142]=ce,t[143]=me,t[144]=he):he=t[144];let ge;return t[145]!==R||t[146]!==le||t[147]!==ue||t[148]!==he?(ge=(0,$.jsx)(R,{open:le,onOpenChange:ue,children:he}),t[145]=R,t[146]=le,t[147]=ue,t[148]=he,t[149]=ge):ge=t[149],ge};function Hd(e){return e.openNewSessionDraft}function Ud(e){return e.currentSessionId}function Wd(e){return e.setPendingInputText}function Gd(e){return e.setPendingSyntheticParts}function Kd(e){return e.setActiveMainTab}function qd(e){return(0,$.jsx)(`li`,{className:`typography-micro text-foreground font-mono truncate block`,title:e,children:e},e)}var Jd=({mergeInProgress:e,rebaseInProgress:t,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{let{t:s}=Xe(),[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`)})]})})},Yd=({runMutation:e,onMutationComplete:t,onMutationError:n,onPathsComplete:r,scheduleFlush:i})=>{let a=[],o=!1;return{enqueue:e=>{let t=a[a.length-1];if(t?.directory===e.directory&&t.direction===e.direction){e.paths.forEach(e=>t.paths.add(e));return}a.push(e)},flush:()=>{if(o)return;let s=a.shift();if(!s)return;o=!0;let c={directory:s.directory,direction:s.direction,paths:Array.from(s.paths),rollback:s.rollback};(async()=>{try{await e(c),t(c)}catch(e){n(c,e)}finally{r(c.paths),o=!1,a.length>0&&i()}})()},clear:()=>{a.length=0},size:()=>a.length,isRunning:()=>o}},Xd=15e3,Zd=40,Qd=20,$d={feat:`:sparkles:`,feature:`:sparkles:`,fix:`:bug:`,bug:`:bug:`,hotfix:`:ambulance:`,docs:`:memo:`,documentation:`:memo:`,style:`:lipstick:`,refactor:`:recycle:`,perf:`:zap:`,performance:`:zap:`,test:`:white_check_mark:`,tests:`:white_check_mark:`,build:`:construction_worker:`,ci:`:green_heart:`,chore:`:wrench:`,revert:`:rewind:`,wip:`:construction:`,security:`:lock:`,release:`:bookmark:`,merge:`:twisted_rightwards_arrows:`,mv:`:truck:`,move:`:truck:`,rename:`:truck:`,remove:`:fire:`,delete:`:fire:`,add:`:sparkles:`,create:`:sparkles:`,implement:`:sparkles:`,update:`:recycle:`,improve:`:zap:`,optimize:`:zap:`,upgrade:`:arrow_up:`,downgrade:`:arrow_down:`,deploy:`:rocket:`,init:`:tada:`,initial:`:tada:`},ef=(e,t)=>{let n=e.toLowerCase(),r=n.match(/^([a-z]+)(?:\(.*\))?!?:/);if(r){let e=$d[r[1]];if(e)return t.find(t=>t.code===e)||null}let i=$d[n.split(` `)[0]];return i&&t.find(e=>e.code===i)||null},tf=20,nf=new Map,rf=(e,t)=>{if(nf.delete(e),nf.set(e,t),nf.size>tf){let e=nf.keys().next().value;e!==void 0&&nf.delete(e)}},af=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),of=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},sf=e=>{let t=e.working_dir?.trim(),n=e.index?.trim();return!!(t||n===`?`)},cf=({isActive:e})=>{let{t}=Xe(),{git:n}=uo(),r=Lo(),[i,a]=Q.useState(null),[o,s]=Q.useState(!1),c=yn(e=>e.currentSessionId),l=yn(e=>e.newSessionDraft),u=yn(e=>e.setDraftBootstrapPendingDirectory),d=yn(e=>e.worktreeMetadata),f=yn(e=>e.availableWorktrees),m=af(r),h=Q.useMemo(()=>{if(!m)return;let e=f.find(e=>af(e.path)===m);if(e)return e;for(let e of d.values())if(af(e.path)===m)return e},[f,m,d]),g=Q.useMemo(()=>{if(c)return d.get(c)??h;if(l?.open)return h},[c,h,l?.open,d]),_=Yo(r??null),v=Xo(r??null),y=en(e=>c?e.getAttachment(c):void 0),b=y?Un(y):[],x=y&&!y.degraded&&!y.legacy?y.worktreeRoot??void 0:void 0,S=pd(r,g,v?.current??void 0),C=qo(r??null),w=Ho(r??null),T=Go(r??null),E=Ko(r??null),{setActiveDirectory:D,fetchAll:O,ensureAll:k,fetchStatus:A,fetchBranches:j,fetchLog:M,setLogMaxCount:N,prefetchDiffs:P,moveStatusPathsOptimistically:F,restoreStatus:I,bumpIndexRevision:L}=Uo(me(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}))),R=p(e=>e.isMobile),z=p(e=>e.openContextFileDiff),B=p(e=>e.navigateToDiff),V=p(e=>e.setRightSidebarOpen),H=Q.useRef(null),U=Q.useRef(null),ee=Q.useRef(null),te=Q.useRef(null),W=Q.useRef(!0);Q.useEffect(()=>()=>{W.current=!1},[]);let ne=Q.useCallback(()=>{U.current!==null&&(window.clearTimeout(U.current),U.current=null)},[]),G=Q.useCallback(e=>{ne(),U.current=window.setTimeout(()=>{U.current=null,af(e)===af(r)&&A(e,n,{silent:!0})},Xd)},[ne,r,A,n]);Q.useEffect(()=>ne,[ne]);let re=Q.useCallback(()=>{ee.current!==null&&(window.clearTimeout(ee.current),ee.current=null)},[]),K=Q.useCallback(()=>{ee.current===null&&(ee.current=window.setTimeout(()=>{ee.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(()=>Yd({runMutation:({directory:e,direction:t,paths:n})=>ie(e,t,n),onMutationComplete:({directory:e})=>{L(e),G(e)},onMutationError:({directory:e,direction:n,rollback:r},i)=>{r?.(),L(e),G(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:K}),[L,ie,K,G,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=qt(r);n&&a(n.status);let i=nt((e,n)=>{t||af(e)===af(r)&&a(n.status)});return Dr(r).then(e=>{if(t)return;kn(r,e);let n=qt(r);a(n?.status??e.status)}).catch(()=>{!t&&!qt(r)&&a(null)}),()=>{t=!0,i()}},[e,r]),Q.useEffect(()=>{let e=H.current;H.current=i,!(!r||!n)&&(e===`pending`&&i===`ready`&&(s(!0),O(r,n).finally(()=>{window.setTimeout(()=>{s(!1)},1200)})),i===`failed`&&(u(null),s(!1)))},[r,O,n,u,i]);let oe=af(l?.bootstrapPendingDirectory??null),se=!!(r&&oe&&oe===af(r)),ce=!!(r&&(i===`pending`||se))||o,le=Q.useMemo(()=>r?nf.get(r)??null:null,[r]),ue=wt(e=>e.settingsGitmojiEnabled),[de,fe]=Q.useState(null),{gitmojis:pe}=dd(ue);Q.useEffect(()=>{let e=x||S?.projectDirectory;if(!e){fe(null);return}let t=!1;return Pi(e).then(e=>{if(t)return;let n=e.trim();fe(n&&n!==`HEAD`?n:null)}).catch(()=>{t||fe(null)}),()=>{t=!0}},[x,S?.projectDirectory]);let[he,ge]=Q.useState(le?.commitMessage??``),[_e,ve]=Q.useState([]),[ye,be]=Q.useState(!1),xe=$s(v)&&!ye,[Se,Ce]=Q.useState(!1),we=Q.useRef(null),[Te,Ee]=Q.useState(null),[De,Oe]=Q.useState(!1),[ke,Ae]=Q.useState(null),[je,Me]=Q.useState(25),{triggerFireworks:Ne}=$u(),[q,Pe]=Q.useState(new Set),[Fe,Ie]=Q.useState(new Set),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(le?.generatedHighlights??[]),Ue=Fe.size>0||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,qe]=Q.useState(new Set),[Je,Ye]=Q.useState(new Map),[Ze,Qe]=Q.useState(new Set),et=Q.useRef(Je),tt=Q.useRef(Ze),[rt,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,bt]=Q.useState(null),[xt,St]=Q.useState(!1),[Ct,Tt]=Q.useState(100),Et=Q.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Dt=Q.useCallback((e,t,n)=>{if(!Et||typeof window>`u`)return;let r={directory:e,conflictFiles:t,operation:n};window.localStorage.setItem(Et,JSON.stringify(r))},[Et]),Ot=Q.useCallback(()=>{!Et||typeof window>`u`||window.localStorage.removeItem(Et)},[Et]);Q.useEffect(()=>{if(!Et||typeof window>`u`||!r)return;let e=window.localStorage.getItem(Et);if(e)try{let t=JSON.parse(e);if(t.directory!==r){window.localStorage.removeItem(Et);return}gt(t.conflictFiles??[]),vt(t.operation??`merge`),mt(!0)}catch{window.localStorage.removeItem(Et)}},[Et,r]);let kt=Q.useCallback(e=>{$e(e).then(e=>{if(e.ok){J.success(t(`gitView.toast.commitHashCopied`));return}J.error(t(`gitView.toast.copyFailed`))})},[t]),At=Q.useCallback(e=>{qe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);Q.useEffect(()=>{et.current=Je},[Je]),Q.useEffect(()=>{tt.current=Ze},[Ze]),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 Qe(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||(Ye(t=>{let n=new Map(t);for(let{hash:t,files:r}of e)n.set(t,r);return et.current=n,n}),Qe(t=>{let n=new Set(t);for(let{hash:t}of e)n.delete(t);return tt.current=n,n}))}),()=>{t=!0,Qe(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&&rf(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 jt=Q.useCallback(async()=>{if(!r||!n?.getRemotes){ft([]);return}try{let e=await n.getRemotes(r);W.current&&ft(e)}catch{W.current&&ft([])}},[r,n]);Q.useEffect(()=>{e&&jt()},[e,jt]),Q.useEffect(()=>{e&&r&&(D(r),k(r,n))},[e,r,D,k,n]),Q.useEffect(()=>{if(e&&r)return Cn.onGitRefreshHint(e=>{af(e.directory)===af(r)&&A(r,n)})},[e,r,A,n]);let Mt=Q.useCallback(async(e=!0)=>{if(r)try{await Promise.all([A(r,n),j(r,n,{force:!0})])}catch(n){if(e){let e=n instanceof Error?n.message:t(`gitView.toast.refreshRepositoryFailed`);J.error(e)}}},[r,n,A,j,t]),Nt=Q.useCallback(async()=>{r&&await M(r,n,je)},[r,n,M,je]),Pt=Q.useMemo(()=>!v||xe?[]:[...v.files??[]].sort((e,t)=>e.path.localeCompare(t.path)),[v,xe]),Ft=Q.useMemo(()=>Pt.filter(of),[Pt]),It=Q.useMemo(()=>Pt.filter(sf),[Pt]),{deferredStagedCount:Lt,deferredUnstagedCount:Rt}=Q.useMemo(()=>{if(!xe||!v)return{deferredStagedCount:0,deferredUnstagedCount:0};let e=0,t=0;for(let n of v.files??[])of(n)&&(e+=1),sf(n)&&(t+=1);return{deferredStagedCount:e,deferredUnstagedCount:t}},[xe,v]);Q.useEffect(()=>{if(!r||Pt.length===0)return;let e=[],t=new Set,i=n=>{!n||t.has(n)||(t.add(n),e.push(n))};if(Ft.forEach(e=>i(e.path)),_e.forEach(i),Pt.slice(0,Qd).forEach(e=>i(e.path)),e.length===0)return;let a=window.setTimeout(()=>{P(r,n,e,{maxFiles:Zd})},120);return()=>{window.clearTimeout(a)}},[Pt,r,n,P,Ft,_e]);let zt=e=>e?.pushed[0]?.remote||v?.tracking?.split(`/`)[0]||Xt.find(e=>e.name===`origin`)?.name||Xt[0]?.name||`origin`,Bt=async(e,i)=>{if(r){Ee(e);try{let a=e=>{let t=`${e.name}/`,n=v?.tracking?.startsWith(t)?v.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:zt(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 Mt(!1),await Nt()}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)}}},Vt=async(e={})=>{if(!r)return;if(!he.trim()){J.error(t(`gitView.toast.enterCommitMessage`));return}let i=Ft.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:[]}),L(r),J.success(t(`gitView.toast.commitCreated`)),ge(``),Ge(),await Mt(),e.pushAfter){let e=v?.tracking?.split(`/`)[0],i=Xt.find(t=>t.name===e)??Xt[0];if(!i)throw Error(t(`mobile.changes.noRemote`));Ee(`sync`);let a=`${i.name}/`,o=v?.tracking?.startsWith(a)?v.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 Mt(!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:zt(l)})),Ne(),await Mt(!1)}else await Mt(!1);await Nt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createCommitFailed`);J.error(n)}finally{Ae(null),e.pushAfter&&Ee(null)}},Ht=Q.useCallback(async()=>{if(!r)return;let e=Ft.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 Cr(r,e),n=t.subject?.trim()??``,i=Array.isArray(t.highlights)?t.highlights:[];if(n){let e=n;if(ue&&pe.length>0){let t=ef(n,pe);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,Ft,ue,pe,We,t]),Ut=e=>e.reason===`attention`?`${e.attentionReason} in progress`:e.reason===`missing`?`worktree is missing`:`worktree is invalid`,Wt=async(e,i)=>{if(!r||!v)return;let a=Ln(y);if(a.length>0){J.error(t(`gitView.toast.cannotCreateBranch`,{reason:Ut(a[0])}));return}let o=v.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 Mt(),await Nt(),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}},Gt=async(e,i)=>{if(!r)return;let a=Ln(y);if(a.length>0){J.error(t(`gitView.toast.cannotRenameBranch`,{reason:Ut(a[0])}));return}try{await n.renameBranch(r,e,i),J.success(t(`gitView.toast.renamedBranch`,{oldName:e,newName:i})),await Mt(),await Nt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.renameBranchFailed`,{oldName:e,newName:i});J.error(r)}},Kt=async e=>{if(!r)return;let i=Ln(y);if(i.length>0){J.error(t(`gitView.toast.cannotCheckout`,{reason:Ut(i[0])}));return}let a=e.replace(/^remotes\//,``);if(v?.current!==a)try{await n.checkoutBranch(r,a),J.success(t(`gitView.toast.checkedOut`,{name:a})),await Mt(),await Nt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.checkoutFailed`,{name:a});J.error(n)}},Jt=Q.useMemo(()=>C?.all?C.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[C]),Yt=Q.useMemo(()=>C?.all?C.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[C]),Xt=Q.useMemo(()=>{if(dt.length>0)return dt;let e=new Set,t=v?.tracking?.trim();t&&t.includes(`/`)&&e.add(t.split(`/`)[0]);for(let t of Yt){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,Yt,at,v?.tracking]),Zt=Q.useMemo(()=>{let e=new Set(Xt.map(e=>e.name)),t=t=>{if(!t)return``;let n=t.trim();if(!n||n===`HEAD`)return``;if(Jt.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 S?.createdFromBranch==`string`?S.createdFromBranch:``)||t(typeof de==`string`?de:``)||(Jt.includes(`main`)?`main`:Jt.includes(`master`)?`master`:Jt.includes(`develop`)?`develop`:`main`)},[Xt,Jt,de,S?.createdFromBranch]),Qt=Ft.length,$t=v?.current??null;Q.useEffect(()=>{if(!r||!n||!w?.all?.length||!$t||!Zt||$t===Zt){it(null);return}let e=!1;return(async()=>{try{let t=await n.getGitLog(r,{from:Zt,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=w.all.findIndex(e=>!i.has(e.hash));if(a===0){it(null);return}if(a===-1){it({insertBeforeIndex:w.all.length,branchName:$t,direction:`up`});return}it({insertBeforeIndex:a,branchName:$t,direction:`up`})}catch{e||it(null)}})(),()=>{e=!0}},[Zt,$t,r,n,w,je]),Q.useEffect(()=>{bt(null)},[r]),Q.useEffect(()=>{if(lt!==`graph`||!r){lt!==`graph`&&bt(null);return}let e=!1;return St(!0),n.getGitLog(r,{maxCount:Ct,all:!0}).then(t=>{e||bt(t)}).catch(e=>{console.error(`Failed to fetch graph log:`,e)}).finally(()=>{e||St(!1)}),()=>{e=!0}},[lt,r,Ct,n]);let tn=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=F(r,n,t);ae.enqueue({directory:r,direction:t,paths:new Set(n),rollback:()=>I(r,i)}),K()},[r,ae,F,I,K]),nn=Q.useCallback(async e=>{if(r){Pe(t=>{let n=new Set(t);return n.add(e),n});try{await n.revertGitFile(r,e,{scope:`working`}),J.success(t(`gitView.toast.revertedFile`,{path:e})),await Mt(!1)}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.revertFailed`);J.error(n)}finally{Pe(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,Mt,n,t]),rn=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=>q.has(e)))return;let s=new Set(Ft.map(e=>e.path)),c=a===`all`&&o.some(e=>s.has(e));i&&Re(!0),Pe(e=>{let t=new Set(e);return o.forEach(e=>t.add(e)),t});let l=[];try{if(await Promise.all(o.map(async e=>{try{await n.revertGitFile(r,e,{scope:a})}catch(n){l.push({path:e,message:n instanceof Error?n.message:t(`gitView.toast.revertFailed`)})}})),c&&l.length<o.length&&L(r),await Mt(!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{Pe(e=>{let t=new Set(e);return o.forEach(e=>t.delete(e)),t}),i&&Re(!1)}},[L,r,n,Le,Mt,q,Ft,t]),an=Q.useCallback(async e=>{await rn(e,!0)},[rn]),on=Q.useCallback(async e=>{await rn(e,!1,`working`)},[rn]),sn=Q.useCallback((e,t)=>{if(r&&!R){z(r,e,t);return}B(e,t),R&&V(!1)},[r,R,B,z,V]),cn=Q.useCallback(()=>Oe(!0),[]),ln=Q.useMemo(()=>{let e=[];return Ft.length>0&&e.push({id:`staged`,title:t(`gitView.changes.stagedTitle`),entries:Ft,actionSymbol:`-`,actionAllLabel:t(`gitView.changes.unstageAllAria`),getActionLabel:e=>t(`gitView.changes.unstageFileAria`,{path:e}),onActionFile:e=>void tn([e],`unstage`),onActionAll:e=>void tn(e,`unstage`),onViewDiff:e=>sn(e,!0),onRevertFile:nn,showRevertActions:!1,accent:!0}),It.length>0&&e.push({id:`unstaged`,title:t(`gitView.changes.title`),entries:It,actionSymbol:`+`,actionAllLabel:t(`gitView.changes.stageAllAria`),getActionLabel:e=>t(`gitView.changes.stageFileAria`,{path:e}),onActionFile:e=>void tn([e],`stage`),onActionAll:e=>void tn(e,`stage`),onViewDiff:e=>sn(e,!1),onRevertFile:nn}),e},[nn,sn,tn,Ft,t,It]),un=Q.useCallback(e=>{if(e.length===0)return;let t=e.map(e=>e.trim()).filter(Boolean);if(t.length===0){Ge();return}ge(e=>{let n=e.trim();return`${n}${n.length>0?`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-D3U6aTZ4.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-5agS8bsW.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-D1lIuyqO.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-BnElHSnO.js","assets/store-CUWqzRt7.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-BxJEIWv5.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-DiIuWOuC.js","assets/dialog-COrLBm9O.js","assets/button-DaAoVF4X.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-D-aLQZaM.js","assets/vendor-pierre-diffs-BenIz2TM.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/appThemeRegistry-CDxBJNNB.js","assets/useMobileNavigationStore-DQHF_ETu.js","assets/gitApiHttp-BxGAFLTf.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-Bq3cPj2x.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-BDyY0vt6.js","assets/useEffectiveDirectory-GbhkdO6m.js","assets/useWorkerHighlightedLines-Ca6OgNHF.js","assets/tooltip-BLugzWq-.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js","assets/TerminalView-CM5jRKlj.js","assets/terminalApi-DpiAJlil.js","assets/vendor-ghostty-web-HohRXr3g.js","assets/OverlayScrollbar-BgMLtMIq.js","assets/useRuntimeAPIs-DSLXJybW.js","assets/sortable-tabs-strip-pWlBorwQ.js","assets/vendor-dnd-kit-core-CvWxUPdb.js","assets/vendor-dnd-kit-accessibility-BY5LhhUB.js","assets/vendor-dnd-kit-sortable-hHdP9lLb.js","assets/useFontPreferences-92Qg-98H.js","assets/projectActions-CWvNGKfA.js","assets/DiagramView-CUfSFI3e.js","assets/fileQueries-CmWYnRVz.js","assets/diagram-DAE4CZy2.js","assets/vendor-react-drawio-ECtEwvbc.js","assets/SettingsView-CbDBfQp1.js","assets/desktopHosts-ZK_vkdzL.js","assets/desktopRelayRestore-CewM6-g5.js","assets/vendor-codemirror-autocomplete-DHomsvW7.js","assets/MobileShareBridge-PZMRiieI.js","assets/MobileDetailNavigation-DILi0tN7.js","assets/AgentAvatar-B4fj9PIe.js","assets/projectMeta-BunN9pH5.js","assets/gitApi-BQT3QXD2.js","assets/input-XiL2-2gG.js","assets/useSessionAutoCleanup-BuU_S_Sh.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/radio-Bziafaje.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-codemirror-language-data-BfYFhIH1.js","assets/url-DMs_PgIC.js","assets/MobileSurface-BLYcR0tO.js","assets/collapsible-BmuQu0dq.js","assets/vendor-codemirror-commands-C9DCaJ0C.js","assets/vendor-codemirror-search-D2SOgzph.js","assets/vendor-replit-codemirror-vim-CEibx3EP.js","assets/context-menu-DBOMervd.js","assets/vendor-yaml-DIcAK3EC.js","assets/vendor-qrcode-DAuVxiQR.js","assets/vendor-dijkstrajs-DztKuCwY.js","assets/SettingsWindow-Br7XLcSd.js","assets/MultiRunWindow-D_2mWZyv.js","assets/multirun-DeNtSkgb.js","assets/insertionBoundaries-9a0RuIDc.js","assets/AssistantView-C00aiEHK.js","assets/ChatContainer-BDFeDKu-.js","assets/FadeInOnReveal-CKKU6fKI.js","assets/vendor-cmdk-CeAGfrLo.js","assets/vendor-aria-hidden-BbL3cEyI.js","assets/vendor-framer-motion-DFy_BSVd.js","assets/OnboardingScreen-CYeRZznl.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F as i,L as a,V as o,W as s,b as c,j as l,k as u,n as d,q as f,t as p,w as m,x as h,y as g}from"./useUIStore-5agS8bsW.js";import{$ as _,$t as v,At as y,Cn as b,D as x,Dn as S,En as C,Ft as w,Gt as T,Qt as E,Rt as D,Sn as O,Tn as k,Xt as A,Yt as j,Zt as M,an as N,cn as P,d as F,en as I,et as L,fn as R,in as z,k as B,kn as V,kt as H,n as U,pn as ee,qt as te,r as W,rn as ne,st as G,t as re,un as K,vn as ie,wn as ae,xn as oe}from"./persistence-D1lIuyqO.js";import{f as se,h as ce,l as le,o as ue,r as de}from"./desktopHosts-ZK_vkdzL.js";import{a as fe,i as pe,t as me}from"./vendor-zustand-B4dlGEM2.js";import{E as he,F as ge,I as _e,N as ve,O as ye,P as be,T as xe,a as Se,i as Ce,nt as we,rt as Te,tt as Ee}from"./vendor-base-ui-CnHfUmDN.js";import{At as De,Ct as Oe,Mt as ke,Ot as Ae,St as je,bt as Me,kt as Ne,xt as q,yt as Pe}from"./gitApiHttp-BxGAFLTf.js";import{o as Fe}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as Ie,t as Le}from"./vendor-react-DLPElpoQ.js";import{l as Re,n as ze,s as Be}from"./vendor-tanstack-react-query-D7pys_c9.js";import{a as Ve,n as He}from"./terminalApi-DpiAJlil.js";/* empty css */import{W as Ue,ct as We}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{n as Ge,t as Ke,u as qe}from"./vendor-reactuses-core-DDoDDyM9.js";import{a as Je,i as Ye,n as Xe,o as Ze,r as Qe,t as $e}from"./clipboard-BnElHSnO.js";import{n as et}from"./store-CUWqzRt7.js";import{$i as tt,$n as nt,$t as rt,An as it,At as at,Ba as ot,Bn as st,Bt as ct,C as lt,Ct as ut,Dn as dt,Do as ft,En as pt,Eo as mt,Fa as ht,Ft as gt,Gr as _t,Hi as vt,Ir as yt,It as bt,Ji as xt,Li as St,Lt as Ct,Ma as wt,Mn as Tt,Nn as Et,Oo as Dt,Or as Ot,Pa as kt,Pt as At,Qr as jt,Qt as Mt,Ri as Nt,Rn as Pt,S as Ft,Tn as It,To as Lt,Ua as Rt,Un as zt,Vt as Bt,Wr as Vt,Wt as Ht,Xi as Ut,Xt as Wt,Ya as Gt,Yn as Kt,Zt as qt,_a as Jt,_r as Yt,aa as Xt,an as Zt,ar as Qt,b as $t,ba as en,bn as tn,ci as nn,cr as rn,ct as an,d as on,dn as sn,dr as cn,ea as ln,f as un,fa as dn,fr as fn,gn as pn,go as mn,gr as hn,h as gn,hn as _n,hr as vn,ii as yn,in as bn,ir as xn,jn as Sn,ko as Cn,kt as wn,l as Tn,la as En,ln as Dn,lr as On,mr as kn,or as An,p as jn,pa as Mn,pi as Nn,pn as Pn,qn as Fn,rn as In,si as Ln,ta as Rn,tn as zn,u as Bn,ua as Vn,un as Hn,ur as Un,v as Wn,vr as J,y as Gn,ya as Kn,zn as qn,zt as Jn}from"./useMobileNavigationStore-DQHF_ETu.js";import{_ as Yn}from"./MobileDetailNavigation-DILi0tN7.js";import{n as Xn}from"./useAssistantUIStore-Bq3cPj2x.js";import{a as Zn,c as Qn,i as $n,n as er,o as tr,r as nr,s as rr,t as Y}from"./utils-BxJEIWv5.js";import{n as X,t as ir}from"./Icon-DiIuWOuC.js";import{a as ar,i as or,n as sr,o as cr,r as lr,t as ur}from"./dialog-COrLBm9O.js";import{t as Z}from"./button-DaAoVF4X.js";import{A as dr,C as fr,D as pr,O as mr,P as hr,T as gr,a as _r,f as vr,h as yr,i as br,j as xr,k as Sr,m as Cr,o as wr,p as Tr,r as Er,t as Dr,w as Or,y as kr}from"./gitApi-BQT3QXD2.js";import{A as Ar,B as jr,C as Mr,D as Nr,E as Pr,F as Fr,G as Ir,H as Lr,I as Rr,J as zr,K as Br,L as Vr,M as Hr,N as Ur,O as Wr,Q as Gr,R as Kr,S as qr,U as Jr,V as Yr,W as Xr,Y as Zr,Z as Qr,_ as $r,b as ei,c as ti,d as ni,f as ri,g as ii,h as ai,i as oi,j as si,k as ci,l as li,m as ui,n as di,p as fi,q as pi,t as mi,u as hi,v as gi,w as _i,x as vi,y as yi,z as bi}from"./useAppFontEffects-IEUQDvE8.js";import{A as xi,E as Si,N as Ci,S as wi,a as Ti,c as Ei,g as Di,h as Oi,i as ki,j as Ai,k as ji,m as Mi,n as Ni,o as Pi,p as Fi,u as Ii,v as Li,x as Ri}from"./projectMeta-BunN9pH5.js";import{t as zi}from"./input-XiL2-2gG.js";import{i as Bi,n as Vi,r as Hi,t as Ui}from"./tooltip-BLugzWq-.js";import{K as Wi,a as Gi,c as Ki,i as qi,m as Ji,p as Yi,q as Xi,s as Zi,u as Qi}from"./useSessionAutoCleanup-BuU_S_Sh.js";import{n as $i}from"./useThemeSystem-DMzWVJaW.js";import{D as ea,E as ta,F as na,G as ra,I as ia,K as aa,L as oa,M as sa,N as ca,O as la,P as ua,Q as da,U as fa,V as pa,W as ma,c as ha,f as ga,h as _a,k as va,n as ya,p as ba,r as xa,s as Sa,z as Ca}from"./radio-Bziafaje.js";import{i as wa,o as Ta}from"./OverlayScrollbar-BgMLtMIq.js";import{x as Ea}from"./markdownTheme-D-aLQZaM.js";import{$ as Da,B as Oa,C as ka,D as Aa,E as ja,F as Ma,G as Na,K as Pa,O as Fa,P as Ia,Q as La,R as Ra,S as za,T as Ba,U as Va,V as Ha,Z as Ua,a as Wa,b as Ga,c as Ka,d as qa,et as Ja,f as Ya,h as Xa,i as Za,k as Qa,l as $a,m as eo,n as to,o as no,p as ro,q as io,r as ao,u as oo,w as so,x as co,y as lo,z as uo}from"./ChatContainer-BDFeDKu-.js";import{n as fo,r as po}from"./useRuntimeAPIs-DSLXJybW.js";import{i as mo,n as ho,t as go,u as _o}from"./appThemeRegistry-CDxBJNNB.js";import{_ as vo,g as yo,i as bo,l as xo,n as So,s as Co,t as wo,v as To,y as Eo}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{a as Do,n as Oo,o as ko,s as Ao,t as jo}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as Mo}from"./url-DMs_PgIC.js";import{f as No,g as Po,h as Fo,m as Io,p as Lo}from"./markdown-worker-BDyY0vt6.js";import{n as Ro,t as zo}from"./useEffectiveDirectory-GbhkdO6m.js";import{o as Bo}from"./FadeInOnReveal-CKKU6fKI.js";import{M as Vo,N as Ho,_ as Uo,b as Wo,d as Go,g as Ko,h as qo,p as Jo,v as Yo,x as Xo,y as Zo}from"./insertionBoundaries-9a0RuIDc.js";import{g as Qo}from"./useWorkerHighlightedLines-Ca6OgNHF.js";import{t as $o}from"./sortable-tabs-strip-pWlBorwQ.js";import{t as es}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{a as ts}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as ns,r as rs,t as is}from"./vendor-framer-motion-DFy_BSVd.js";import{A as as,B as os,C as ss,D as cs,H as ls,M as us,N as ds,O as fs,R as ps,T as ms,X as hs,Z as gs,_ as _s,b as vs,d as ys,f as bs,h as xs,j as Ss,k as Cs,m as ws,p as Ts,s as Es,v as Ds,w as Os,x as ks,y as As,z as js}from"./MobileSurface-BLYcR0tO.js";import{i as Ms,n as Ns,r as Ps,t as Fs}from"./useDesktopWindowControlsLayout-MlqJX89k.js";import{n as Is}from"./useFontPreferences-92Qg-98H.js";import{B as Ls,D as Rs,E as zs,F as Bs,I as Vs,L as Hs,M as Us,N as Ws,O as Gs,P as Ks,R as qs,T as Js,V as Ys,a as Xs,c as Zs,d as Qs,f as $s,i as ec,j as tc,k as nc,l as rc,m as ic,n as ac,o as oc,p as sc,r as cc,s as lc,u as uc,w as dc,z as fc}from"./runtimeEndpointReset-CK1GhIsm.js";import{a as pc,i as mc,n as hc,r as gc,t as _c}from"./context-menu-DBOMervd.js";import{n as vc,r as yc,t as bc}from"./collapsible-BmuQu0dq.js";import{a as xc,o as Sc,r as Cc,s as wc,t as Tc}from"./projectActions-CWvNGKfA.js";import{n as Ec,t as Dc}from"./fileQueries-CmWYnRVz.js";import{t as Oc}from"./diagram-DAE4CZy2.js";import{a as kc,i as Ac,n as jc,o as Mc,r as Nc,t as Pc}from"./multirun-DeNtSkgb.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(Te(),1),Rc=Le(),zc=Ie(),$=we();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=fe()((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(!A()||!j()||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 D(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(),!A()||!j()||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 D(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 W({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}=Xe(),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=A()&&j(),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 N(n,e.id,e.appName)||await z(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 $e(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`,E;t[21]===T?E=t[22]:(E=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]=E);let D;t[23]!==g.label||t[24]!==i?(D=i(`openInApp.actions.openInAria`,{app:g.label}),t[23]=g.label,t[24]=i,t[25]=D):D=t[25];let O;t[26]!==g.fallbackIconDataUrl||t[27]!==g.iconDataUrl||t[28]!==g.label?(O=(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]=O):O=t[29];let k;t[30]!==E||t[31]!==D||t[32]!==O||t[33]!==w?(k=(0,$.jsx)(`button`,{type:`button`,onClick:w,className:E,"aria-label":D,children:O}),t[30]=E,t[31]=D,t[32]=O,t[33]=w,t[34]=k):k=t[34];let M;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(M=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]=M):M=t[35];let P;t[36]===i?P=t[37]:(P=i(`openInApp.actions.chooseAppAria`),t[36]=i,t[37]=P);let F;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4`}),t[38]=F):F=t[38];let I;t[39]===P?I=t[40]:(I=(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:M,"aria-label":P,children:F})}),t[39]=P,t[40]=I);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 B;t[44]===i?B=t[45]:(B=i(`openInApp.actions.copyPath`),t[44]=i,t[45]=B);let V;t[46]===B?V=t[47]:(V=(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:B}),t[46]=B,t[47]=V);let H;t[48]!==L||t[49]!==V?(H=(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:L,children:[R,V]}),t[48]=L,t[49]=V,t[50]=H):H=t[50];let U;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(sa,{}),t[51]=U):U=t[51];let ee;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)(la,{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],ee=o.map(e),t[52]=o,t[53]=b,t[54]=g.id,t[55]=ee}else ee=t[55];let te;t[59]!==s||t[60]!==u||t[61]!==i?(te=s?(0,$.jsxs)(la,{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]=te):te=t[62];let W;t[63]!==H||t[64]!==ee||t[65]!==te?(W=(0,$.jsxs)(ea,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[H,U,ee,te]}),t[63]=H,t[64]=ee,t[65]=te,t[66]=W):W=t[66];let ne;t[67]!==I||t[68]!==W?(ne=(0,$.jsxs)(ta,{children:[I,W]}),t[67]=I,t[68]=W,t[69]=ne):ne=t[69];let G;return t[70]!==k||t[71]!==ne||t[72]!==C?(G=(0,$.jsxs)(`div`,{className:C,children:[k,ne]}),t[70]=k,t[71]=ne,t[72]=C,t[73]=G):G=t[73],G};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 V(`/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 V(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(r.ok)return r.text()}catch{}let n=oe()?.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 V(`/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}=Xe(),{terminal:o,runtime:s}=fo(),{isMobile:c}=wa(),l=Q.useMemo(()=>A(),[]),u=ms(e=>e.instances),d=ms(e=>e.load),f=p(e=>e.setBottomTerminalOpen),m=p(e=>e.setActiveMainTab),h=p(e=>e.setSettingsPage),g=p(e=>e.setSettingsDialogOpen),_=p(e=>e.setSettingsProjectsSelectedId),v=p(e=>e.openContextPreview),y=Is(e=>e.sessions),b=Is(e=>e.ensureDirectory),x=Is(e=>e.setTabLabel),S=Is(e=>e.setTabIconKey),C=Is(e=>e.setActiveTab),w=Is(e=>e.setConnecting),T=Is(e=>e.setTabSessionId),E=Is(e=>e.setTabPreviewUrl),D=Is(e=>e.projectActionRuns),O=Is(e=>e.setProjectActionRun),k=Is(e=>e.updateProjectActionRunStatus),j=Is(e=>e.removeProjectActionRun),[M,N]=Q.useState([]),[P,F]=Q.useState(null),[I,L]=Q.useState(!1),R=Q.useRef({}),z=Q.useRef({}),B=Q.useRef({}),V=Q.useRef({}),H=Q.useRef(0),U=e?.id??null,ee=e?.path??``,te=Q.useMemo(()=>U?{id:U,path:ee}:null,[U,ee]);Q.useEffect(()=>{l&&d().catch(()=>void 0)},[l,d]);let W=Q.useCallback(async e=>{await Mo(e)},[]),ne=Q.useCallback(async()=>{if(!te)return;let e=H.current+1;H.current=e,L(!0);try{let t=await Tt(te);if(H.current!==e)return;let n=t.actions;N(n),F(e=>e===Dl||e&&n.some(t=>t.id===e)?e:null)}catch{if(H.current!==e)return}finally{H.current===e&&L(!1)}},[te]),G=Q.useMemo(()=>xc(t||te?.path||``),[t,te?.path]),re=Q.useMemo(()=>P?M.find(e=>e.id===P)??null:null,[M,P]),K=Q.useMemo(()=>({id:Dl,name:a(`projectActions.actions.autoDiscover`),command:``,icon:`search`,autoOpenUrl:!0}),[a]),ie=!c,ae=Q.useMemo(()=>ie?[K,...M]:M,[M,K,ie]);Q.useEffect(()=>{ne()},[ne]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;U&&(t?.projectId&&t.projectId!==U||ne())};return window.addEventListener(Tc,e),()=>{window.removeEventListener(Tc,e)}},[ne,U]),Q.useEffect(()=>{P&&(P===Dl&&ie||M.some(e=>e.id===P)||F(null))},[M,ie,P]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=y.get(t.directory)?.tabs.find(e=>e.id===t.tabId);(!n||n.terminalSessionId!==t.sessionId)&&j(e)}},[D,j,y]),Q.useEffect(()=>{for(let[e,t]of Object.entries(D)){let n=z.current[e]??{lastSeenChunkId:null,openedUrl:!1,tail:``,openInPreview:!1};z.current[e]=n;let r=ae.find(e=>e.id===t.actionId);if(!r)continue;let i=y.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&&(E(t.directory,t.tabId,l,{locked:!1,autoOpened:!1}),t.status===`waiting-for-preview`&&k(e,`running`),window.clearTimeout(V.current[e]),delete V.current[e],v(t.directory,l))}else W(l),J.success(a(`projectActions.toast.openedUrlFromOutput`));z.current[e]=n}for(let e of Object.keys(z.current))D[e]||(delete z.current[e],window.clearTimeout(V.current[e]),delete V.current[e])},[ae,v,W,D,E,a,y,k]);let oe=Q.useCallback(async(e,t={})=>{if(!G)throw Error(a(`projectActions.error.noActiveDirectory`));let n=wc(G,e.id);b(G);let r=Is.getState(),i=r.getDirectoryState(G),o=R.current[n]||null,s=o?!!i?.tabs.some(e=>e.id===o):!1;(!o||!s)&&(o=r.createTab(G),R.current[n]=o),x(G,o,`Action: ${e.name}`),S(G,o,e.icon||`play`),t.revealTerminal!==!1&&(C(G,o),f(!0),m(`terminal`));let c=Is.getState().getDirectoryState(G)?.tabs.find(e=>e.id===o);return{key:n,tabId:o,sessionId:c?.terminalSessionId??null}},[b,G,m,C,f,S,x,a]),se=Q.useCallback(async e=>{if(s.isVSCode||!i&&c)return;if(!G){J.error(a(`projectActions.error.noActiveDirectoryForAction`));return}let t=wc(G,e.id),n=D[t];if(!(n&&n.status===`running`))try{let t=e.id===Dl?await(async()=>{let[e,t]=await Promise.all([Tt({id:te?.id??``,path:G}),Cl(G)]),n=await gl(G,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){w(G,i,!0);try{c=(await o.createSession({cwd:G})).sessionId,d=!0,T(G,i,c)}finally{w(G,i,!1)}}if(!c)throw Error(a(`projectActions.error.failedToCreateTerminalSession`));d&&await wl(350),t.id===Dl&&(B.current[r]?.(),w(G,i,!0),B.current[r]=He(c,e=>{e.type===`data`&&typeof e.data==`string`&&e.data.length>0&&Is.getState().appendToBuffer(G,i,e.data),e.type===`exit`&&(Is.getState().setTabLifecycle(G,i,`exited`),Is.getState().setConnecting(G,i,!1),Is.getState().removeProjectActionRun(r),delete z.current[r],B.current[r]?.(),delete B.current[r],window.clearTimeout(V.current[r]),delete V.current[r])},()=>{Is.getState().setConnecting(G,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?Sc(t.desktopOpenSshForward,u):null;O({key:r,directory:G,actionId:t.id,tabId:i,sessionId:c,status:t.id===Dl&&!p?`waiting-for-preview`:`running`}),window.clearTimeout(V.current[r]),delete V.current[r],t.id===Dl&&!p&&(V.current[r]=window.setTimeout(()=>{Is.getState().updateProjectActionRunStatus(r,`running`),delete V.current[r]},Ol)),m?(E(G,i,null,{locked:!0}),W(m),J.success(a(`projectActions.toast.openedForwardedUrl`))):p?(E(G,i,p,{locked:!0,autoOpened:!0}),v(G,p),J.success(a(`projectActions.toast.openedActionUrl`))):n?(E(G,i,null,{locked:!0}),J.error(a(`projectActions.error.invalidCustomUrlFormat`))):f?(E(G,i,null,{locked:!0}),J.error(a(`projectActions.error.selectedDesktopSshForwardUnavailable`))):E(G,i,null,{locked:!1,autoOpened:!1}),z.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){j(t),delete z.current[t],B.current[t]?.(),delete B.current[t],window.clearTimeout(V.current[t]),delete V.current[t],J.error(e instanceof Error?e.message:a(`projectActions.error.failedToRunAction`))}},[u,oe,i,c,l,G,W,v,D,s.isVSCode,j,w,O,E,T,te?.id,a,o]),ce=Q.useCallback(async e=>{let t=wc(G,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)}),Is.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{}T(n.directory,n.tabId,null)}j(t),delete z.current[t],B.current[t]?.(),delete B.current[t],window.clearTimeout(V.current[t]),delete V.current[t]}},[G,D,j,T,o,k]),le=Q.useCallback(()=>{let e=re??ae[0];if(!e)return;let t=wc(G,e.id),n=D[t];if(n?.status!==`stopping`){if(n){ce(e);return}se(e)}},[ae,G,se,D,re,ce]),ue=Q.useCallback((e,t=!1)=>{if(F(e.id),!t){se(e);return}let n=wc(G,e.id),r=D[n];if(r?.status!==`stopping`){if(r){ce(e);return}se(e)}},[G,se,D,ce]),de=Q.useCallback(()=>{te?.id&&(_(te.id),h(`projects`),g(!0))},[g,h,_,te?.id]);if(s.isVSCode||!i&&c||!te||!G)return null;let fe=re??ae[0]??null;if(!fe)return null;let pe=fe.icon||`play`,me=fe.id===Dl?`search`:Cc[pe]||`play`,he=D[wc(G,fe.id)],ge=he?.status===`stopping`,_e=he?.status===`waiting-for-preview`,ve=he?y.get(he.directory)?.tabs.find(e=>e.id===he.tabId)?.previewUrl??null:null,ye=!!(he&&ve),be=()=>{!he||!ve||v(he.directory,ve)};return r?(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:I||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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ta,{children:[(0,$.jsx)(ca,{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)(ea,{align:`end`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(la,{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)(sa,{}),ae.map(e=>{let t=e.icon||`play`,n=e.id===Dl?`search`:Cc[t]||`play`,r=wc(G,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(la,{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:I||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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{sideOffset:6,children:a(`projectActions.actions.openPreview`)})]}):null,(0,$.jsxs)(ta,{children:[(0,$.jsx)(ca,{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)(ea,{align:`start`,className:`w-52 max-h-[70vh] overflow-y-auto`,children:[(0,$.jsxs)(la,{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)(sa,{}),ae.map(e=>{let t=e.icon||`play`,n=e.id===Dl?`search`:Cc[t]||`play`,r=wc(G,e.id),i=D[r],a=!!i,o=i?.status===`stopping`;return(0,$.jsxs)(la,{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)})]})]})]})},Nl=`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`,Pl=`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`,Fl=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??Nl,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)(Bi,{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)(Vi,{children:(0,$.jsx)(`p`,{children:r})}),t[12]=r,t[13]=v);let y;return t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(Ui,{children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16],y}),Il=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}=Xe();if(!r?.connected||n)return null;if(i.length>1){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=Y(Nl,`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)(ca,{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)(va,{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)(sa,{}),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)(la,{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)(ea,{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)(ta,{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}),Ll=Q.memo(function(e){let t=(0,zc.c)(61),{isDesktopApp:n,currentInstanceIsLocal: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}=Xe(),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)(ca,{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 L;t[11]!==s||t[12]!==d||t[13]!==I?(L=(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)($o,{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]=L):L=t[14];let R;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?(R=n&&s===`instance`?(0,$.jsxs)(`div`,{children:[r?null:(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]})}),(0,$.jsx)(zr,{embedded:!0,open:i&&s===`instance`,onOpenChange:Ul,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]=R):R=t[25];let z;t[26]!==s||t[27]!==i?(z=s===`mcp`?(0,$.jsx)(Ls,{active:i&&s===`mcp`}):null,t[26]=s,t[27]=i,t[28]=z):z=t[28];let B;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?(B=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:zl(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)($o,{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)(Si,{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=Gi(r.usedPercent,r.resetAt,r.windowSeconds,n),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-qi(a.elapsedRatio):qi(a.elapsedRatio),s=Ki(r.valueLabel,i),c=Zi(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:Qi(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)(xs,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(ws,{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)(bc,{open:i,onOpenChange:()=>S(e.providerId,r),children:[(0,$.jsxs)(yc,{className:`flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:n.familyLabel}),i?(0,$.jsx)(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)(vc,{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=Gi(r.usedPercent,r.resetAt,r.windowSeconds),o=a?.dailyAllocationPercent==null?null:p===`remaining`?100-qi(a.elapsedRatio):qi(a.elapsedRatio),s=Ki(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:vs(n)}),(0,$.jsx)(`span`,{className:`typography-ui-label tabular-nums text-foreground`,children:s===`-`?``:s})]}),(0,$.jsx)(xs,{percent:i,tonePercent:r.usedPercent,className:`h-1.5`,expectedMarkerPercent:o}),a&&A?(0,$.jsx)(ws,{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]=B):B=t[44];let V;t[45]!==w||t[46]!==T||t[47]!==C||t[48]!==N?(V=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)(la,{disabled:w,onSelect:()=>{T()},children:N(`header.services.shutdownDev`)})})]}):null,t[45]=w,t[46]=T,t[47]=C,t[48]=N,t[49]=V):V=t[49];let H;t[50]!==M||t[51]!==L||t[52]!==R||t[53]!==z||t[54]!==B||t[55]!==V?(H=(0,$.jsxs)(ea,{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:[L,R,z,B,V]}),t[50]=M,t[51]=L,t[52]=R,t[53]=z,t[54]=B,t[55]=V,t[56]=H):H=t[56];let U;return t[57]!==i||t[58]!==P||t[59]!==H?(U=(0,$.jsxs)(ta,{open:i,onOpenChange:P,children:[F,H]}),t[57]=i,t[58]=P,t[59]=H,t[60]=U):U=t[60],U}),Rl=(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??``),zl=(e,t)=>{if(!e)return`-`;try{return xa(e,t,{fallback:`-`})}catch{return`-`}},Bl=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},Vl=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,Hl=({onToggleLeftDrawer:e,onToggleRightDrawer:t,leftDrawerOpen:n,rightDrawerOpen:r})=>{let{t:i}=Xe(),a=p(e=>e.setSessionSwitcherOpen),s=p(e=>e.toggleSidebar),c=p(e=>e.isSidebarOpen),l=p(e=>e.toggleBottomTerminal),u=p(e=>e.toggleRightSidebar),d=p(e=>e.openContextOverview),f=p(e=>e.openContextPlan),h=p(e=>e.openContextBrowser),g=p(e=>e.openContextPanelTab),_=p(e=>e.closeContextPanel),y=p(e=>e.contextPanelByDirectory),b=p(e=>e.activeMainTab),x=p(e=>e.setActiveMainTab),S=p(e=>e.shortcutOverrides),C=p(e=>e.timeFormatPreference),E=Ut(e=>e.getCurrentModel),D=fo(),[O,k]=Q.useState(!1),M=Tn(e=>e.getContextUsage),N=Tn(e=>!!e.newSessionDraft?.open),P=Tn(e=>e.currentSessionId),F=zn(P??``),I=Jn(P),L=mn(e=>e.activeProjectId?e.projects.find(t=>t.id===e.activeProjectId)??null:null),R=Q.useMemo(()=>{if(!L)return null;let e=L.path.split(/[\\/]/).filter(Boolean);return e[e.length-1]??null},[L]),z=Ds(e=>e.results),B=Ds(e=>e.fetchAllQuotas),H=Ds(e=>e.isLoading),U=Ds(e=>e.lastUpdated),ee=Ds(e=>e.displayMode),ne=Ds(e=>e.showPredValues),G=Ds(e=>e.dropdownProviderIds),re=Ds(e=>e.loadSettings),K=Ds(e=>e.setDisplayMode),{isMobile:ae}=wa(),oe=ga().data??null,ue=Ts(e=>e.setStatus),fe=Q.useRef(null),[pe,me]=Q.useState(()=>typeof window>`u`?!1:A()),he=Q.useMemo(()=>w(),[]),ge=pe&&T()===`win32`,_e=Ta(),[ve,ye]=Q.useState(!1),be=Q.useMemo(()=>typeof navigator>`u`?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||``),[]),{usesFramelessChrome:xe,side:Se}=Fs(),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(A())},[]);let we=E(),Te=we&&typeof we.limit==`object`&&we.limit!==null?we.limit:null,Ee=M(Te&&typeof Te.context==`number`?Te.context:0,Te&&typeof Te.output==`number`?Te.output:0),[De,Oe]=Q.useState(null),ke=!P||F;(0,Q.useEffect)(()=>{if(!P){Oe(e=>e===null?e:null);return}if(Ee&&Ee.totalTokens>0){Oe(e=>Rl(e,Ee)?e:Ee);return}ke&&Oe(e=>e===null?e:null)},[Ee,P,ke]);let Ae=p(e=>e.isSessionSwitcherOpen),je=oe?.connected?oe.user?.avatarUrl??null:null,Me=oe?.connected?oe.user?.login??null:null,Ne=oe?.accounts??[],[q,Pe]=Q.useState(!1),[Fe,Ie]=Q.useState(!1),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[He,Ue]=Q.useState(`Local`),[We,Ge]=Q.useState(!0),[Ke,qe]=Q.useState(!1),[Je,Ye]=Q.useState(null),[Ze,Qe]=Q.useState(!1),[$e,et]=Q.useState(null),[tt,nt]=Q.useState(pe?`instance`:`usage`),[rt,it]=Q.useState(`usage`);(0,Q.useEffect)(()=>{!pe&&tt===`instance`&&nt(`usage`)},[tt,pe]);let at=Q.useMemo(()=>v(),[]),ot=!at&&b===`chat`&&!!De&&De.totalTokens>0,st=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,ct=Q.useCallback(async()=>{if(!(typeof window>`u`||!pe))try{if(j()){Ue(`Local`),Ge(!0);return}Ge(!1);let e=await de(),t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,n=m();if(n&&se(n,t)){Ue(`Local`),Ge(!0);return}let r=e.hosts.find(e=>n?se(n,le(e)):!1);if(r?.label?.trim()){Ue(ce(r.label.trim()));return}Ue(`Instance`)}catch{Ue(`Local`),Ge(!0)}},[pe]);(0,Q.useEffect)(()=>{ct()},[ct]);let lt=Q.useCallback(async()=>{if(We){Ye(null),et(null);return}Qe(!0),et(null);try{let e=new URLSearchParams({appType:`web`,instanceMode:`remote`}),t=await V(`/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();Ye({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){Ye(null),et(e instanceof Error?e.message:i(`header.services.remoteUpdate.error`))}finally{Qe(!1)}},[We,i]);Q.useEffect(()=>{Ye(null),et(null),qe(!1)},[We,He]),Q.useEffect(()=>{if(!pe||We)return;let e=36e5,t=!1,n=null,r=i=>{n=window.setTimeout(()=>{if(t||typeof document<`u`&&document.visibilityState!==`visible`){r(e);return}lt().finally(()=>{t||r(e)})},i)};return r(3e3),()=>{t=!0,n!==null&&window.clearTimeout(n)}},[lt,We,He,pe]);let ut=Q.useCallback(()=>{if(Je?.available){qe(!0);return}lt()},[lt,Je?.available]);_s();let dt=Ds(e=>e.selectedModels),ft=Ds(e=>e.expandedFamilies),pt=Ds(e=>e.toggleFamilyExpanded),mt=Q.useMemo(()=>{let e=[];for(let t of gs){if(!G.includes(t.id))continue;let n=z.find(e=>e.providerId===t.id),r=n?.usage?.windows??{},a=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(a&&Object.keys(a).length>0){let e=dt[t.id]??[],n=e.length>0,r=ks(a,t.id),o=As(t.id),c=ss(o);s.modelFamilies=[];for(let t of c){let i=r.get(t.id)??[];if(i.length===0)continue;let o=n?i.filter(t=>e.includes(t)):i;if(o.length===0)continue;let c=[];for(let e of o){let t=a[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=a[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:i(`header.services.modelFamily.other`),models:e})}}(o.length>0||s.modelFamilies&&s.modelFamilies.length>0||s.error)&&e.push(s)}return e},[G,z,dt,i]),ht=mt.length>0;Q.useEffect(()=>{re()},[re]);let gt=Q.useCallback(async e=>{K(e);try{await W({usageDisplayMode:e})}catch(e){console.warn(`Failed to update usage display mode:`,e)}},[K]),_t=Q.useCallback(()=>{if(ze)return;Be(!0);let e=new Promise(e=>setTimeout(e,500));Promise.all([B(),e]).finally(()=>{Be(!1)})},[B,ze]),vt=Tn(e=>P?e.worktreeMetadata.get(P)?.path??``:``),yt=Q.useMemo(()=>Bl(vt||``),[vt]),bt=Q.useMemo(()=>Bl((typeof I?.directory==`string`?I.directory:``)||``),[I?.directory]),xt=Tn(e=>e.newSessionDraft?.open?Bl(e.newSessionDraft.bootstrapPendingDirectory??e.newSessionDraft.directoryOverride??``):``),St=Q.useMemo(()=>yt||bt||xt,[xt,bt,yt]),Ct=Ro(),wt=Q.useMemo(()=>Bl(Ct||St||L?.path||``),[L?.path,Ct,St]),Tt=Q.useMemo(()=>{if(!P)return R??`OpenChamber`;let e=I?.title?.trim();return e&&e.length>0?e:`Untitled Session`},[R,I?.title,P]),Et=Q.useMemo(()=>Bl(St||L?.path||``),[L?.path,St]),Dt=Q.useMemo(()=>L?{id:L.id,path:L.path}:null,[L]),Ot=Q.useRef(null);Q.useEffect(()=>{!Dt||!Et||(Ot.current={projectRef:Dt,directory:Et})},[Et,Dt]);let kt=Q.useMemo(()=>Dt&&Et?{projectRef:Dt,directory:Et}:Ot.current,[Et,Dt]),At=eo(e=>e.planModeEnabled),jt=Tn(e=>e.isSessionPlanAvailable),Mt=At&&P?jt(P):!1,Nt=Mt,Pt=Q.useRef(``);Q.useEffect(()=>{if(!At){p.getState().activeMainTab===`plan`&&p.getState().setActiveMainTab(`chat`);return}if(!P)return;let e=`${P||`none`}:${bt||`none`}:${I?.time?.created||0}:${I?.slug||`none`}`;Pt.current!==e&&(Pt.current=e),!Mt&&p.getState().activeMainTab===`plan`&&p.getState().setActiveMainTab(`chat`)},[At,Mt,I?.slug,I?.time?.created,P,bt]);let Ft=Q.useCallback(async e=>{if(!(!e||q)){Pe(!0);try{let t=D.github?await D.github.authActivate(e):await(async()=>{let t=await V(`/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})();ue(t)}catch(e){console.error(`Failed to switch GitHub account:`,e)}finally{Pe(!1)}}},[q,D.github,ue]),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(ae){It(),a(!Ae);return}s()},[It,ae,Ae,a,s]),Rt=Q.useCallback(()=>{te(`desktop_open_draft_mini_chat_window`,{directory:Bl(St||L?.path||``),projectId:L?.id??null,apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[header] failed to open draft mini chat window`,e)})},[L?.id,L?.path,St]),zt=Q.useCallback(()=>{if(N){Rt();return}P&&te(`desktop_open_session_mini_chat_window`,{sessionId:P,directory:Bl(St||L?.path||``),apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[header] failed to open session mini chat window`,e)})},[L?.path,P,Rt,N,St]),Bt=Q.useCallback(()=>{let e=wt;if(!e)return;let t=y[e];if(Vl(t)===`context`){_(e);return}d(e)},[_,wt,y,d]),Vt=Q.useMemo(()=>{let e=wt;if(!e)return!1;let t=y[e];return Vl(t)===`context`},[wt,y]),Ht=Q.useCallback(()=>{let e=wt;if(!e)return;let t=y[e];if(Vl(t)===`plan`){_(e);return}f(e)},[_,wt,y,f]),Wt=Q.useCallback(()=>{let e=wt;if(!e)return;let t=y[e];if(Vl(t)===`diff`){_(e);return}g(e,{mode:`diff`,stagedDiff:!1})},[_,wt,y,g]),Gt=Q.useCallback(()=>{let e=wt;if(!e)return;let t=y[e];if(Vl(t)===`browser`){_(e);return}h(e)},[_,wt,y,h]),Kt=Q.useMemo(()=>{let e=wt;if(!e)return!1;let t=y[e];return Vl(t)===`plan`},[wt,y]),qt=Q.useMemo(()=>{let e=wt;if(!e)return!1;let t=y[e];return Vl(t)===`browser`},[wt,y]),Jt=Nl,Yt=Pl,Xt=Q.useMemo(()=>Fe?`services`:n?`sessions`:r?`git`:b,[b,Fe,n,r]),Zt=Q.useCallback(()=>{Ie(!1),n&&e&&e(),r&&t&&t(),!e&&Ae&&a(!1)},[Ae,n,e,t,r,a]),Qt=Q.useCallback(()=>{n||Ie(!1),e?.()},[n,e]),$t=Q.useCallback(()=>{r||Ie(!1),t?.()},[t,r]),en=Q.useMemo(()=>pe&&be&&!ve?`5.5rem`:_e?`max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)`:(!pe||xe)&&!at?`calc(0.75rem + var(--oc-wco-left-inset, 0px))`:`0.75rem`,[pe,ve,be,_e,at,xe]);(0,Q.useEffect)(()=>{typeof document>`u`||document.documentElement.style.setProperty(`--oc-titlebar-left-inset`,en)},[en]);let tn=c?`0.75rem`:`var(--oc-titlebar-left-inset, 0.75rem)`,nn=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 te(`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 rn=Q.useMemo(()=>!pe||!be||Ce===null?``:Ce>=26?`h-12`:Ce<=15?`h-14`:``,[pe,be,Ce]),an=Q.useMemo(()=>{if(!(pe&&!xe||at))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,at,xe]),on=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;on();let e=fe.current;if(!e||typeof ResizeObserver>`u`)return()=>{};let t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,on()})},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)}},[on]),(0,Q.useEffect)(()=>{on()},[on,ae,rn]);let sn=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 ie()},[pe]),cn=Q.useMemo(()=>{if(ae){let e=[{id:`chat`,label:i(`layout.mainTab.chat`),icon:`chat-thread`}];return Nt&&e.push({id:`plan`,label:i(`layout.mainTab.plan`),icon:`file-text`}),e.push({id:`diff`,label:i(`layout.mainTab.diff`),icon:`diff`},{id:`files`,label:i(`layout.mainTab.files`),icon:`folder-6`},{id:`terminal`,label:i(`layout.mainTab.terminal`),icon:`terminal-box`},{id:`context`,label:i(`layout.mainTab.context`),icon:`file-list-2`},{id:`diagram`,label:i(`layout.mainTab.diagram`),icon:`file`}),e}return[]},[ae,Nt,i]),ln=Q.useCallback(e=>pa(fa(e,S)),[S]);(0,Q.useEffect)(()=>{!ae&&(b===`git`||b===`terminal`||b===`diff`||b===`files`||b===`context`)&&x(`chat`)},[b,ae,x]);let un=Q.useMemo(()=>{let e=[];return pe&&e.push({value:`instance`,label:i(`layout.services.instance`),icon:(0,$.jsx)(X,{name:`server`,className:`h-3.5 w-3.5`})}),e.push({value:`usage`,label:i(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{value:`mcp`,label:`MCP`,icon:(0,$.jsx)(hs,{className:`h-3.5 w-3.5`})}),e},[pe,i]),dn=Q.useMemo(()=>un.map(e=>({id:e.value,label:e.label,icon:e.icon})),[un]),fn=Q.useMemo(()=>{if(typeof window>`u`||pe||at)return!1;let e=window.location.hostname;return e===`localhost`||e===`127.0.0.1`||e===`::1`},[pe,at]),pn=Q.useCallback(async()=>{if(O)return;k(!0),Re(!1);let e=[],t=!1;try{try{for(let[,t]of Is.getState().sessions.entries())for(let n of t.tabs)n.previewUrl&&e.push(n.previewUrl)}catch{}try{await Ve({})}catch{}try{t=(await V(`/api/system/dev-shutdown`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({previewUrls:e})})).ok?!0:(await V(`/api/system/shutdown`,{method:`POST`})).ok}catch{}}finally{t||k(!1)}},[O,Re]),hn=Q.useMemo(()=>[{value:`usage`,label:i(`header.services.used`)},{value:`remaining`,label:i(`header.services.remaining`)}],[i]),gn=Q.useMemo(()=>hn.map(e=>({id:e.value,label:e.label})),[hn]),_n=Q.useMemo(()=>[{id:`usage`,label:i(`layout.services.usage`),icon:(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`})},{id:`mcp`,label:`MCP`,icon:(0,$.jsx)(hs,{className:`h-3.5 w-3.5`})}],[i]);(0,Q.useEffect)(()=>{let e=e=>{if(tr(e)&&!e.shiftKey&&!e.altKey){let t=parseInt(e.key,10);t>=1&&t<=cn.length&&(e.preventDefault(),ae&&(It(),Zt()),x(cn[t-1].id))}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[It,Zt,ae,x,cn]),(0,Q.useEffect)(()=>{let e=e=>{let t=fa(`toggle_services_menu`,S);if(Ca(e,t)){e.preventDefault(),Le?Re(!1):(Re(!0),ct(),tt===`usage`&&z.length===0&&B());return}let n=fa(`cycle_services_tab`,S);if(Ca(e,n)){e.preventDefault();let t=un.map(e=>e.value);if(t.length===0)return;let n=t.indexOf(tt),r=t[n===-1?0:(n+1)%t.length];nt(r),Re(!0),ct(),r===`usage`&&z.length===0&&B();return}let r=fa(`open_usage`,S);if(Ca(e,r)){e.preventDefault(),nt(`usage`),Re(!0),ct(),z.length===0&&B();return}let i=fa(`toggle_context_plan`,S);Ca(e,i)&&(e.preventDefault(),Ht())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,Le,tt,un,z.length,B,ct,Ht]);let vn=e=>{let t=b===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:()=>x(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&&!ae&&`min-w-[100px] justify-center`),"aria-label":e.label,"aria-selected":t,role:`tab`,children:[ae?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)},yn=he&&(N||!!P),bn=Q.useCallback(e=>{window.setTimeout(e,0)},[]),xn=Q.useCallback(e=>{nt(e),Re(!0),ct(),e===`usage`&&z.length===0&&B()},[B,z.length,ct]),Sn=Q.useRef(null),Cn=(0,$.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,children:[(0,$.jsx)(`div`,{ref:Sn,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center`,children:(0,$.jsxs)(ta,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.actions.sessionMenuAria`),className:Y(Jt,`text-muted-foreground`),children:(0,$.jsx)(X,{name:`more-2`,className:`h-[18px] w-[18px]`})})})}),(0,$.jsx)(Vi,{children:(0,$.jsx)(`p`,{children:i(`header.actions.sessionMenu`)})})]}),(0,$.jsxs)(ea,{align:`start`,className:`min-w-[14rem]`,children:[at?null:(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(Wt),children:[(0,$.jsx)(X,{name:`layout-column`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.toggleChangesPanel`)})]}),yn?(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(zt),children:[(0,$.jsx)(X,{name:`picture-in-picture-2`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(N?`header.actions.newMiniChat`:`header.actions.openSessionMiniChat`)})]}):null,pe?(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(()=>xn(`instance`)),children:[(0,$.jsx)(X,{name:`stack`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:i(`header.actions.sessionMenu.servicesWithInstance`,{current:He})}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`toggle_services_menu`)})]}):null,(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(()=>xn(`usage`)),children:[(0,$.jsx)(X,{name:`timer`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.sessionMenu.viewUsage`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`open_usage`)})]}),(0,$.jsx)(sa,{}),(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(l),children:[(0,$.jsx)(X,{name:`terminal-box`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`header.actions.toggleTerminalPanel`)}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:ln(`toggle_terminal`)})]}),(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>bn(Gt),children:[(0,$.jsx)(X,{name:`global`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`flex-1`,children:i(`contextPanel.browser.open`)}),qt?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-foreground`}):null]})]})]})}),(0,$.jsx)(Ll,{isDesktopApp:pe,currentInstanceIsLocal:We,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Re,refreshCurrentInstanceLabel:ct,desktopServicesTab:tt,setDesktopServicesTab:nt,quotaResultsLength:z.length,fetchAllQuotas:B,servicesTabItems:dn,quotaLastUpdated:U,quotaDisplayMode:ee,showPredValues:ne,quotaDisplayTabItems:gn,handleDisplayModeChange:gt,handleUsageRefresh:_t,isQuotaLoading:H,isUsageRefreshSpinning:ze,hasRateLimits:ht,rateLimitGroups:mt,expandedFamilies:ft,toggleFamilyExpanded:pt,showDevShutdown:fn,isDevShutdownInFlight:O,onDevShutdown:pn,remoteUpdateInfo:Je,remoteUpdateChecking:Ze,remoteUpdateError:$e,onOpenRemoteUpdate:ut,timeFormatPreference:C,anchorRef:Sn})]}),wn=(0,$.jsxs)($.Fragment,{children:[Nt&&(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.actions.openPlanAria`),onClick:Ht,className:Y(Jt,Kt&&`bg-[var(--interactive-hover)]`),children:(0,$.jsx)(X,{name:`file-text`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(Vi,{children:(0,$.jsx)(`p`,{children:i(`header.actions.planWithShortcut`,{shortcut:ln(`toggle_context_plan`)})})})]}),(0,$.jsx)(al,{directory:Et,className:`mr-1`}),(0,$.jsx)(Fl,{title:i(`header.actions.rightSidebarWithShortcut`,{shortcut:ln(`toggle_right_sidebar`)}),ariaLabel:i(`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)(Il,{isMobile:ae,githubAuthStatus:oe,githubAccounts:Ne,githubAvatarUrl:je,githubLogin:Me,isSwitchingGitHubAccount:q,handleGitHubAccountSwitch:Ft})]}),En=()=>(0,$.jsxs)(`div`,{onMouseDown:sn,className:Y(`app-region-drag relative flex h-12 select-none items-center pr-3`,rn),style:an,role:`tablist`,"aria-label":i(`header.navigation.mainAria`),children:[(0,$.jsx)(`div`,{"aria-hidden":!0,className:`shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,style:{width:tn}}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:`app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none`,style:{width:nn}}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,$.jsxs)(`div`,{className:`app-region-no-drag mr-3 flex min-w-0 items-center gap-0.5`,children:[(0,$.jsx)(Ns,{children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`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:N?i(`sessions.switcher.draftTitle`):Tt})})}),Cn]}),cn.length>0&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1`,children:cn.map(e=>vn(e))}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[ot&&De?(0,$.jsx)(Ms,{totalTokens:De.totalTokens,percentage:st,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:`compact`,appearance:`subtle`,onClick:Bt,pressed:Vt,className:`mr-2`}):null,wn,(0,$.jsx)(Ps,{visible:xe&&Se===`right`,position:`right`})]})]})]}),Dn=()=>(0,$.jsxs)(`div`,{className:`app-region-drag relative flex items-center gap-2 px-3 py-2 select-none`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e?(0,$.jsx)(`button`,{type:`button`,onClick:Qt,className:Y(Yt,Xt===`sessions`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":i(n?`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:()=>a(!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":i(`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":i(`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:i(`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":i(`header.navigation.mainAria`),children:cn.map(e=>{let t=b===e.id,n=e.icon===`diff`,r=n?null:e.icon;return(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ae&&(It(),Zt()),x(e.id)},"aria-label":e.label,"aria-selected":t,role:`tab`,className:Y(Yt,`relative rounded-lg`,Xt===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":i(`header.changes.availableAria`)})]})}),(0,$.jsx)(Vi,{children:(0,$.jsx)(`p`,{children:e.label})})]},e.id)})})})})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[kt&&(0,$.jsx)(Ml,{projectRef:kt.projectRef,directory:kt.directory,compact:!0,allowMobile:!0,className:`h-9`}),(0,$.jsxs)(ta,{open:Fe,onOpenChange:i=>{i&&(n&&e&&e(),r&&t&&t()),Ie(i),i&&z.length===0&&B()},children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":i(`header.services.viewAria`),className:Y(Yt,Xt===`services`&&`bg-interactive-selection text-interactive-selection-foreground`),children:(0,$.jsx)(X,{name:`stack`,className:`h-5 w-5`})})})}),(0,$.jsx)(Vi,{children:(0,$.jsx)(`p`,{children:i(`header.services.title`)})})]}),(0,$.jsx)(ea,{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)($o,{items:_n,activeId:rt,onSelect:e=>{let t=e;it(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":i(`header.services.closeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-5 w-5`})})]})}),rt===`mcp`&&(0,$.jsx)(Ls,{active:Fe&&rt===`mcp`}),rt===`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:i(`header.services.rateLimits`)}),(0,$.jsx)(`span`,{className:`truncate typography-micro text-muted-foreground`,children:zl(U,C)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center h-6`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>gt(`usage`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,ee===`usage`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:i(`header.services.used`)}),(0,$.jsx)(`span`,{className:`text-muted-foreground typography-ui-label px-0.5`,children:`·`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>gt(`remaining`),className:Y(`typography-ui-label px-1 pb-0.5 transition-colors`,ee===`remaining`?`text-foreground border-b-2 border-[var(--primary-base)]`:`text-muted-foreground hover:text-foreground`),children:i(`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:_t,disabled:H||ze,"aria-label":i(`header.services.refreshRateLimitsAria`),children:(0,$.jsx)(X,{name:`refresh`,className:Y(`h-4 w-4`,ze&&`animate-spin`)})})]})]})}),!ht&&(0,$.jsx)(`div`,{className:`px-4 py-6 text-center`,children:(0,$.jsx)(`span`,{className:`typography-ui-label text-muted-foreground`,children:i(`header.services.noRateLimits`)})}),(0,$.jsx)(`div`,{className:`py-1`,children:mt.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)(Si,{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??i(`header.services.noRateLimitsReported`)})}):(0,$.jsxs)(`div`,{className:`space-y-3 px-4 pb-2`,children:[e.entries.map(([t,n])=>{let r=ee===`remaining`?n.remainingPercent:n.usedPercent,i=Gi(n.usedPercent,n.resetAt,n.windowSeconds,t),a=i?.dailyAllocationPercent==null?null:ee===`remaining`?100-qi(i.elapsedRatio):qi(i.elapsedRatio),o=Ki(n.valueLabel,r),s=Zi(n.resetAt,n.resetAfterFormatted??n.resetAtFormatted,C);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:Qi(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)(xs,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ne?(0,$.jsx)(ws,{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=(ft[e.providerId]??[]).includes(t.familyId??`other`);return(0,$.jsxs)(bc,{open:n,onOpenChange:()=>pt(e.providerId,t.familyId??`other`),children:[(0,$.jsxs)(yc,{className:`flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label font-medium text-foreground`,children:t.familyLabel}),n?(0,$.jsx)(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)(vc,{children:(0,$.jsx)(`div`,{className:`space-y-2.5 pb-1 pl-1 pt-1`,children:t.models.map(([t,n])=>{let r=ee===`remaining`?n.remainingPercent:n.usedPercent,i=Gi(n.usedPercent,n.resetAt,n.windowSeconds),a=i?.dailyAllocationPercent==null?null:ee===`remaining`?100-qi(i.elapsedRatio):qi(i.elapsedRatio),o=Ki(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:vs(t)}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground tabular-nums`,children:o===`-`?``:o})]}),(0,$.jsx)(xs,{percent:r,tonePercent:n.usedPercent,className:`h-1.5`,expectedMarkerPercent:a}),i&&ne?(0,$.jsx)(ws,{paceInfo:i,compact:!0}):null]},`${e.providerId}-${t}`)})})})]},t.familyId??`other`)})})]})]},e.providerId))})]})]})})]}),t?(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:$t,className:Y(Yt,`relative`,Xt===`git`&&`bg-interactive-selection text-interactive-selection-foreground`),"aria-label":r?`Close git sidebar`:`Open git sidebar`,children:(0,$.jsx)(X,{name:`layout-right`,className:`h-5 w-5`})})}),(0,$.jsx)(Vi,{children:(0,$.jsx)(`p`,{children:r?`Close git sidebar`:`Open git sidebar`})})]}):null]})]})]}),On=Y(`header-safe-area relative z-10 bg-background`,ge&&`bg-[var(--surface-background)] backdrop-blur-none`,ae&&`border-b border-border/50`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`header`,{ref:fe,className:On,style:{"--padding-scale":`1`},children:ae?Dn():En()}),(0,$.jsx)(js,{open:Ke,onOpenChange:qe,info:Je,downloading:!1,downloaded:!1,progress:null,error:$e,onDownload:()=>{},onRestart:()=>{},runtimeType:`web`})]})};function Ul(){}var Wl=180,Gl=640,Kl=110,ql=e=>{let t=(0,zc.c)(44),{isOpen:n,isMobile:r,children:i}=e,{t:a}=Xe(),o=p(Jl),s=p(Yl),c=p(Xl),l=p(Zl),[u,d]=Q.useState(null),[f,m]=Q.useState(!1),h=Q.useRef(null),g=Q.useRef(0),_=Q.useRef(o||300),v=Math.min(Gl,Math.max(Wl,o||300)),y,b;t[0]===n?(y=t[1],b=t[2]):(y=()=>{n||(d(null),m(!1))},b=[n],t[0]=n,t[1]=y,t[2]=b),Q.useEffect(y,b);let x,S;t[3]!==s||t[4]!==r||t[5]!==n?(x=()=>{if(r||!n||!s)return;let e=()=>{let e=h.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=h.current?.parentElement;if(!t)return;let i=new ResizeObserver(e);return i.observe(t),()=>{i.disconnect()}},S=[s,r,n],t[3]=s,t[4]=r,t[5]=n,t[6]=x,t[7]=S):(x=t[6],S=t[7]),Q.useEffect(x,S);let C,w;if(t[8]!==s||t[9]!==r||t[10]!==f||t[11]!==c||t[12]!==l?(C=()=>{if(r||!f||s)return;let e=e=>{let t=g.current-e.clientY,n=Math.min(Gl,Math.max(Wl,_.current+t));c(n)},t=()=>{m(!1),p.getState().bottomTerminalHeight<=Kl&&l(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},w=[s,r,f,c,l],t[8]=s,t[9]=r,t[10]=f,t[11]=c,t[12]=l,t[13]=C,t[14]=w):(C=t[13],w=t[14]),Q.useEffect(C,w),r)return null;let T=n?s?Math.max(0,u??v):v:0,E=n&&s,D;t[15]!==T||t[16]!==s||t[17]!==n?(D=e=>{!n||s||(m(!0),g.current=e.clientY,_.current=T,e.preventDefault())},t[15]=T,t[16]=s,t[17]=n,t[18]=D):D=t[18];let O=D,k=E?`absolute inset-x-0 bottom-0 z-40`:`relative`,A=f?`transition-none`:`transition-[height] duration-300 ease-in-out`,j=(!n||E)&&`border-t-0`,M;t[19]!==j||t[20]!==k||t[21]!==A?(M=Y(`flex overflow-hidden border-t border-border bg-sidebar`,k,A,j),t[19]=j,t[20]=k,t[21]=A,t[22]=M):M=t[22];let N;t[23]!==T||t[24]!==E?(N=E?{top:0}:{height:`${T}px`,minHeight:`${T}px`,maxHeight:`${T}px`},t[23]=T,t[24]=E,t[25]=N):N=t[25];let P=!n||!s&&T===0,F;t[26]!==O||t[27]!==s||t[28]!==n||t[29]!==f||t[30]!==a?(F=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:O,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`terminalView.bottomDock.resizeAria`)}),t[26]=O,t[27]=s,t[28]=n,t[29]=f,t[30]=a,t[31]=F):F=t[31];let I=!n&&`pointer-events-none select-none opacity-0`,L;t[32]===I?L=t[33]:(L=Y(`relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out`,I),t[32]=I,t[33]=L);let R=!n,z;t[34]!==i||t[35]!==L||t[36]!==R?(z=(0,$.jsx)(`div`,{className:L,"aria-hidden":R,children:i}),t[34]=i,t[35]=L,t[36]=R,t[37]=z):z=t[37];let B;return t[38]!==M||t[39]!==N||t[40]!==P||t[41]!==F||t[42]!==z?(B=(0,$.jsxs)(`section`,{ref:h,className:M,style:N,"aria-hidden":P,children:[F,z]}),t[38]=M,t[39]=N,t[40]=P,t[41]=F,t[42]=z,t[43]=B):B=t[43],B};function Jl(e){return e.bottomTerminalHeight}function Yl(e){return e.isBottomTerminalExpanded}function Xl(e){return e.setBottomTerminalHeight}function Zl(e){return e.setBottomTerminalOpen}var Ql=260,$l=260,eu=500,tu=({isOpen:e,isMobile:t,children:n,className:r,topBar:i})=>{let{t:a}=Xe(),o=p(e=>e.sidebarWidth),s=p(e=>e.setSidebarWidth),[c,l]=Q.useState(!1),u=Q.useRef(0),d=Q.useRef(o||Ql),f=Q.useRef(null),m=Q.useRef(null),h=Q.useRef(null),g=Q.useCallback(e=>Math.min(eu,Math.max($l,e)),[]),_=Q.useCallback(e=>{let t=h.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,m.current=null)},[c]),t)return null;let v=Math.min(eu,Math.max($l,o||Ql)),y=e?v:0,b=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}m.current=t.pointerId,l(!0),u.current=t.clientX,d.current=y,f.current=y,_(y),t.preventDefault()}},x=e=>{if(t||!c||m.current!==e.pointerId)return;let n=e.clientX-u.current,r=g(d.current+n);f.current!==r&&(f.current=r,_(r))},S=e=>{if(m.current!==e.pointerId||t)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let n=g(f.current??y);m.current=null,f.current=null,l(!1),s(n)},C=c?f.current??y:y;return(0,$.jsxs)(`aside`,{ref:h,className:Y(`relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none`,`bg-sidebar oc-vibrancy-surface`,!e&&`border-r-0`,r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${c?C:v}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||y===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:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S,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)(Yi,{children:n})})]})]})},nu=()=>{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},ru=e=>{let t=(0,zc.c)(24),{className:n}=e,r=ys(iu),i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0],Q.useEffect(au,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 iu(e){return e.sidebarBrandName}function au(){di()}var ou=e=>{let t=(0,zc.c)(25),{className:n}=e,{t:r}=Xe(),i=p(su),a=p(cu),o;t[0]===a?o=t[1]:(o=pa(fa(`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)(Bi,{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 m;t[13]===r?m=t[14]:(m=r(`commandPalette.title`),t[13]=r,t[14]=m);let h;t[15]===m?h=t[16]:(h=(0,$.jsx)(`span`,{children:m}),t[15]=m,t[16]=h);let g;t[17]===s?g=t[18]:(g=(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:s}),t[17]=s,t[18]=g);let _;t[19]!==h||t[20]!==g?(_=(0,$.jsx)(Vi,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[h,g]})}),t[19]=h,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==_||t[23]!==f?(v=(0,$.jsxs)(Ui,{children:[f,_]}),t[22]=_,t[23]=f,t[24]=v):v=t[24],v};function su(e){return e.setCommandPaletteOpen}function cu(e){return e.shortcutOverrides}var lu=`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`,uu=()=>{let e=(0,zc.c)(46),{t}=Xe(),n=p(du),r=p(fu),i=p(pu),a=p(mu),o=ys(hu),s=Q.useRef(null),c=pa(fa(`toggle_sidebar`,a)),{usesFramelessChrome:l,side:u}=Fs(),d;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=A(),e[0]=d):d=e[0];let f=d,m=!f||!n||!o,h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=I()&&!f&&!v(),e[1]=h):h=e[1];let g=h,_=_u,y,b;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{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()}},b=[],e[2]=y,e[3]=b):(y=e[2],b=e[3]),Q.useEffect(y,b);let x=g&&n?`${r||260}px`:void 0,S;e[4]===x?S=e[5]:(S={height:`var(--oc-header-height, 3rem)`,paddingLeft:`var(--oc-titlebar-left-inset, 0.75rem)`,width:x},e[4]=x,e[5]=S);let C=g&&n&&`w-full justify-between`,w;e[6]===C?w=e[7]:(w=Y(`flex items-center gap-2`,C),e[6]=C,e[7]=w);let T;e[8]===n?T=e[9]:(T=g&&n?(0,$.jsx)(ru,{className:`flex min-w-0 items-center p-0`}):null,e[8]=n,e[9]=T);let E;e[10]!==l||e[11]!==u?(E=l&&u===`left`?(0,$.jsx)(Ps,{visible:!0,position:`left`}):null,e[10]=l,e[11]=u,e[12]=E):E=e[12];let D;e[13]!==t||e[14]!==l?(D=l?(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":t(`header.actions.openAppMenuAria`),className:Y(lu,`shrink-0`),children:(0,$.jsx)(X,{name:`menu-2`,className:`h-[18px] w-[18px]`})})}),(0,$.jsx)(Vi,{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]===m?O=e[17]:(O=m?(0,$.jsx)(ou,{}):null,e[16]=m,e[17]=O);let k=Ui,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(lu,`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)(Bi,{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=Vi,L=t(`header.actions.openSessionsWithShortcut`,{shortcut:c}),R;e[25]===L?R=e[26]:(R=(0,$.jsx)(`p`,{children:L}),e[25]=L,e[26]=R);let z;e[27]!==F||e[28]!==R?(z=(0,$.jsx)(F,{children:R}),e[27]=F,e[28]=R,e[29]=z):z=e[29];let B;e[30]!==k||e[31]!==P||e[32]!==z?(B=(0,$.jsxs)(k,{children:[P,z]}),e[30]=k,e[31]=P,e[32]=z,e[33]=B):B=e[33];let V;e[34]!==O||e[35]!==B?(V=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[O,B]}),e[34]=O,e[35]=B,e[36]=V):V=e[36];let H;e[37]!==E||e[38]!==D||e[39]!==V||e[40]!==w||e[41]!==T?(H=(0,$.jsxs)(`div`,{ref:s,className:w,children:[T,E,D,V]}),e[37]=E,e[38]=D,e[39]=V,e[40]=w,e[41]=T,e[42]=H):H=e[42];let U;return e[43]!==H||e[44]!==S?(U=(0,$.jsx)(`div`,{className:`app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2`,style:S,children:H}),e[43]=H,e[44]=S,e[45]=U):U=e[45],U};function du(e){return e.isSidebarOpen}function fu(e){return e.sidebarWidth}function pu(e){return e.toggleSidebar}function mu(e){return e.shortcutOverrides}function hu(e){return e.sidebarBrandName.trim().length>0}function gu(e){console.warn(`[titlebar] failed to open app menu`,e)}function _u(e){let t=e.currentTarget.getBoundingClientRect();te(`desktop_show_app_menu`,{x:t.left,y:t.bottom}).catch(gu)}var vu=420,yu=({isOpen:e,children:t,className:n})=>{let{t:r}=Xe(),i=p(e=>e.rightSidebarWidth),a=p(e=>e.setRightSidebarWidth),[o,s]=Q.useState(!1),c=Q.useRef(0),l=Q.useRef(i||vu),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),m=Q.useCallback(e=>Math.min(860,Math.max(360,e)),[]),h=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`))},[]),g=Math.min(860,Math.max(360,i||vu)),_=e?g:0;Q.useLayoutEffect(()=>{if(o)return;let e=f.current;e&&(e.style.minWidth=``,e.style.maxWidth=``)},[e,o,g]);let v=t=>{if(e){try{t.currentTarget.setPointerCapture(t.pointerId)}catch{}d.current=t.pointerId,s(!0),c.current=t.clientX,l.current=_,u.current=_,h(_),t.preventDefault()}},y=e=>{if(!o||d.current!==e.pointerId)return;let t=c.current-e.clientX,n=m(l.current+t);u.current!==n&&(u.current=n,h(n))},b=e=>{if(d.current!==e.pointerId)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=m(u.current??_);d.current=null,u.current=null,s(!1),a(t)},x=o?u.current??_:_;return(0,$.jsxs)(`aside`,{ref:f,className:Y(`relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none`,`bg-sidebar`,!e&&`border-l-0`,n),style:{width:`${x}px`,"--oc-right-sidebar-width":`${o?x:g}px`,overflowX:`clip`,transitionProperty:o?`none`:`width`,transitionDuration:`200ms`,transitionTimingFunction:`cubic-bezier(0.22, 1, 0.36, 1)`},"aria-hidden":!e||_===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:v,onPointerMove:y,onPointerUp:b,onPointerCancel:b,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})]})},bu=e=>({providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent});function xu(e){let t=(0,zc.c)(131),{t:n}=Xe(),{open:r,onOpenChange:i,target:a,projectDirectory:o,submitting:s,allowRunAsGoal:c,onConfirm:l}=e,u=s!==void 0&&s,d=c!==void 0&&c,f;t[0]===d?f=t[1]:(f=d&&!v(),t[0]=d,t[1]=f);let p=f,m=Ut(Mu),h=Ut(ju),g=Gt(Au),_=Ut(ku),y=Ut(Ou),b=Ut(Du),x=Ut(Eu),S=Ut(Tu),C;t[2]!==S||t[3]!==b||t[4]!==y||t[5]!==x?(C=()=>bu({providerID:y,modelID:b,variant:x,agent:S}),t[2]=S,t[3]=b,t[4]=y,t[5]=x,t[6]=C):C=t[6];let[w,T]=Q.useState(C),E,D;t[7]!==g||t[8]!==h||t[9]!==m||t[10]!==r||t[11]!==o?(E=()=>{r&&(m({directory:o,source:`todoSendDialog`}),h({directory:o}),g())},D=[r,m,h,g,o],t[7]=g,t[8]=h,t[9]=m,t[10]=r,t[11]=o,t[12]=E,t[13]=D):(E=t[12],D=t[13]),Q.useEffect(E,D);let O,k;t[14]!==S||t[15]!==b||t[16]!==y||t[17]!==x||t[18]!==r?(O=()=>{r&&T(bu({providerID:y,modelID:b,variant:x,agent:S}))},k=[r,y,b,x,S],t[14]=S,t[15]=b,t[16]=y,t[17]=x,t[18]=r,t[19]=O,t[20]=k):(O=t[19],k=t[20]),Q.useEffect(O,k);let A,j;t[21]!==w.modelID||t[22]!==w.providerID||t[23]!==r||t[24]!==_?(A=()=>{if(!r||_.length===0)return;let e=_.find(e=>e.id===w.providerID)??_[0],t=Array.isArray(e?.models)?e.models:[],n=t.some(e=>e.id===w.modelID),i=t[0]?.id??``;e?.id===w.providerID&&n||T(t=>({...t,providerID:e?.id??``,modelID:n?t.modelID:i,variant:``}))},j=[r,_,w.providerID,w.modelID],t[21]=w.modelID,t[22]=w.providerID,t[23]=r,t[24]=_,t[25]=A,t[26]=j):(A=t[25],j=t[26]),Q.useEffect(A,j);let M=wu,N;if(t[27]!==w.modelID||t[28]!==w.providerID||t[29]!==_){let e;t[31]===w.providerID?e=t[32]:(e=e=>e.id===w.providerID,t[31]=w.providerID,t[32]=e),N=_.find(e)?.models?.find(e=>e.id===w.modelID),t[27]=w.modelID,t[28]=w.providerID,t[29]=_,t[30]=N}else N=t[30];let P=N,F;t[33]===P?F=t[34]:(F=P?.variants?Object.keys(P.variants):[],t[33]=P,t[34]=F);let I=F,L=I.length>0,R,z;t[35]!==w.variant||t[36]!==L?(R=()=>{L||!w.variant||T(Cu)},z=[L,w.variant],t[35]=w.variant,t[36]=L,t[37]=R,t[38]=z):(R=t[37],z=t[38]),Q.useEffect(R,z);let B;t[39]!==w.modelID||t[40]!==w.providerID?(B=w.providerID.trim().length>0&&w.modelID.trim().length>0,t[39]=w.modelID,t[40]=w.providerID,t[41]=B):B=t[41];let V=B,H;t[42]!==V||t[43]!==w||t[44]!==l||t[45]!==u?(H=()=>{!V||u||l(w)},t[42]=V,t[43]=w,t[44]=l,t[45]=u,t[46]=H):H=t[46];let U=H,ee,te;t[47]!==U||t[48]!==r?(ee=()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),U())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},te=[r,U],t[47]=U,t[48]=r,t[49]=ee,t[50]=te):(ee=t[49],te=t[50]),Q.useEffect(ee,te);let W;t[51]!==n||t[52]!==a?(W=n(a===`worktree`?`rightSidebar.contextNotesTodo.sendDialog.title.newWorktree`:`rightSidebar.contextNotesTodo.sendDialog.title.newSession`),t[51]=n,t[52]=a,t[53]=W):W=t[53];let ne=W,G;t[54]!==i||t[55]!==u?(G=e=>{u||i(e)},t[54]=i,t[55]=u,t[56]=G):G=t[56];let re;t[57]===ne?re=t[58]:(re=(0,$.jsx)(ar,{children:(0,$.jsx)(cr,{children:ne})}),t[57]=ne,t[58]=re);let K;t[59]===n?K=t[60]:(K=n(`chat.modelControls.model`),t[59]=n,t[60]=K);let ie;t[61]===K?ie=t[62]:(ie=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:K}),t[61]=K,t[62]=ie);let ae;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(e,t)=>{T(n=>({...n,providerID:e,modelID:t,variant:``}))},t[63]=ae):ae=t[63];let oe;t[64]!==w.modelID||t[65]!==w.providerID?(oe=(0,$.jsx)(ba,{providerId:w.providerID,modelId:w.modelID,className:`max-w-[320px] justify-between`,dropdownPortalToBody:!0,onChange:ae}),t[64]=w.modelID,t[65]=w.providerID,t[66]=oe):oe=t[66];let se;t[67]!==ie||t[68]!==oe?(se=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[ie,oe]}),t[67]=ie,t[68]=oe,t[69]=se):se=t[69];let ce;t[70]===n?ce=t[71]:(ce=n(`sessions.scheduledTasks.editor.thinkingLevel.label`),t[70]=n,t[71]=ce);let le;t[72]===ce?le=t[73]:(le=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:ce}),t[72]=ce,t[73]=le);let ue=!L,de;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(de=e=>T(t=>({...t,variant:e})),t[74]=de):de=t[74];let fe;t[75]!==w.variant||t[76]!==ue||t[77]!==I?(fe=(0,$.jsx)(Na,{value:w.variant,options:I,disabled:ue,onChange:de}),t[75]=w.variant,t[76]=ue,t[77]=I,t[78]=fe):fe=t[78];let pe;t[79]!==le||t[80]!==fe?(pe=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[le,fe]}),t[79]=le,t[80]=fe,t[81]=pe):pe=t[81];let me;t[82]===n?me=t[83]:(me=n(`sessions.scheduledTasks.editor.agent.label`),t[82]=n,t[83]=me);let he;t[84]===me?he=t[85]:(he=(0,$.jsx)(`span`,{className:`typography-meta font-medium text-muted-foreground`,children:me}),t[84]=me,t[85]=he);let ge;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>T(t=>({...t,agent:e})),t[86]=ge):ge=t[86];let _e;t[87]===w.agent?_e=t[88]:(_e=(0,$.jsx)(_a,{agentName:w.agent,filter:M,dropdownPortalToBody:!0,onChange:ge}),t[87]=w.agent,t[88]=_e);let ve;t[89]!==he||t[90]!==_e?(ve=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[he,_e]}),t[89]=he,t[90]=_e,t[91]=ve):ve=t[91];let ye;t[92]!==se||t[93]!==pe||t[94]!==ve?(ye=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[se,pe,ve]}),t[92]=se,t[93]=pe,t[94]=ve,t[95]=ye):ye=t[95];let be=`flex items-center gap-3 ${p?`justify-between`:`justify-end`}`,xe;t[96]!==w.runAsGoal||t[97]!==p||t[98]!==u||t[99]!==n?(xe=p?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Ci,{checked:w.runAsGoal===!0,onChange:e=>T(t=>({...t,runAsGoal:e})),disabled:u,ariaLabel:n(`sessions.scheduledTasks.editor.goal.aria`)}),(0,$.jsx)(`button`,{type:`button`,className:`truncate typography-ui-label text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50`,disabled:u,onClick:()=>T(Su),children:n(`sessions.scheduledTasks.editor.goal.label`)})]}):null,t[96]=w.runAsGoal,t[97]=p,t[98]=u,t[99]=n,t[100]=xe):xe=t[100];let Se;t[101]===i?Se=t[102]:(Se=()=>i(!1),t[101]=i,t[102]=Se);let Ce;t[103]===n?Ce=t[104]:(Ce=n(`rightSidebar.contextNotesTodo.sendDialog.actions.cancel`),t[103]=n,t[104]=Ce);let we;t[105]!==u||t[106]!==Se||t[107]!==Ce?(we=(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:Se,disabled:u,children:Ce}),t[105]=u,t[106]=Se,t[107]=Ce,t[108]=we):we=t[108];let Te=!V||u,Ee;t[109]!==u||t[110]!==n?(Ee=n(u?`rightSidebar.contextNotesTodo.sendDialog.actions.sending`:`rightSidebar.contextNotesTodo.sendDialog.actions.send`),t[109]=u,t[110]=n,t[111]=Ee):Ee=t[111];let De;t[112]!==U||t[113]!==Te||t[114]!==Ee?(De=(0,$.jsx)(Z,{size:`sm`,onClick:U,disabled:Te,children:Ee}),t[112]=U,t[113]=Te,t[114]=Ee,t[115]=De):De=t[115];let Oe;t[116]!==we||t[117]!==De?(Oe=(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[we,De]}),t[116]=we,t[117]=De,t[118]=Oe):Oe=t[118];let ke;t[119]!==be||t[120]!==xe||t[121]!==Oe?(ke=(0,$.jsxs)(`div`,{className:be,children:[xe,Oe]}),t[119]=be,t[120]=xe,t[121]=Oe,t[122]=ke):ke=t[122];let Ae;t[123]!==re||t[124]!==ye||t[125]!==ke?(Ae=(0,$.jsxs)(sr,{className:`max-w-md overflow-visible`,children:[re,ye,ke]}),t[123]=re,t[124]=ye,t[125]=ke,t[126]=Ae):Ae=t[126];let je;return t[127]!==r||t[128]!==G||t[129]!==Ae?(je=(0,$.jsx)(ur,{open:r,onOpenChange:G,children:Ae}),t[127]=r,t[128]=G,t[129]=Ae,t[130]=je):je=t[130],je}function Su(e){return{...e,runAsGoal:e.runAsGoal!==!0}}function Cu(e){return{...e,variant:``}}function wu(e){return ot(e.mode)}function Tu(e){return e.currentAgentName||``}function Eu(e){return e.currentVariant||``}function Du(e){return e.currentModelId}function Ou(e){return e.currentProviderId}function ku(e){return e.providers}function Au(e){return e.loadAgents}function ju(e){return e.loadAgents}function Mu(e){return e.loadProviders}var Nu=5,Pu=15,Fu=new Map,Iu=e=>{let t=Math.sqrt(e/100),n=12*t,r=24*t;return Math.ceil(n+r+1)},Lu=(e,t)=>{let n=Iu(t);return Math.max(n*Nu,Math.min(n*Pu,n*e))},Ru=async(e,t)=>{let n=await st(e.path);return{...e,title:n?.title||e.path.split(`/`).pop()||t}},zu=()=>L(),Bu=e=>[...e.filter(e=>!e.completed),...e.filter(e=>e.completed)],Vu=(e,t)=>{let n=e.findIndex(e=>e.completed);return n===-1?[...e,t]:[...e.slice(0,n),t,...e.slice(n)]},Hu=e=>{let t=(0,zc.c)(20),{id:n,children:r}=e,i;t[0]===n?i=t[1]:(i={id:n},t[0]=n,t[1]=i);let{attributes:a,listeners:o,setNodeRef:s,setActivatorNodeRef:c,transform:l,transition:u,isDragging:d}=ko(i),f;t[2]===l?f=t[3]:(f=Eo.Transform.toString(l),t[2]=l,t[3]=f);let p;t[4]!==f||t[5]!==u?(p={transform:f,transition:u},t[4]=f,t[5]=u,t[6]=p):p=t[6];let m=d&&`opacity-60`,h;t[7]===m?h=t[8]:(h=Y(m),t[7]=m,t[8]=h);let g;t[9]!==a||t[10]!==r||t[11]!==d||t[12]!==o||t[13]!==c?(g=r({attributes:a,listeners:o,setActivatorNodeRef:c,isDragging:d}),t[9]=a,t[10]=r,t[11]=d,t[12]=o,t[13]=c,t[14]=g):g=t[14];let _;return t[15]!==s||t[16]!==p||t[17]!==h||t[18]!==g?(_=(0,$.jsx)(`li`,{ref:s,style:p,className:h,children:g}),t[15]=s,t[16]=p,t[17]=h,t[18]=g,t[19]=_):_=t[19],_},Uu=({projectRef:e,projectLabel:t,canCreateWorktree:n=!1,onActionComplete:r,className:i})=>{let{t:a}=Xe(),[o,s]=Q.useState(!1),[c,l]=Q.useState(``),[u,d]=Q.useState([]),[f,m]=Q.useState(``),[h,g]=Q.useState(null),[_,v]=Q.useState(()=>new Set),[y,b]=Q.useState([]),[x,S]=Q.useState(null),[C,w]=Q.useState(!1),[T,E]=Q.useState(0),D=Q.useRef(!1),O=Q.useRef(``),k=Q.useRef(null),A=p(e=>e.todoPanelHeight),j=p(e=>e.setTodoPanelHeight),M=p(e=>e.notesPanelHeight),N=p(e=>e.setNotesPanelHeight),[F,I]=Q.useState(!1),L=Q.useRef(0),R=Q.useRef(A),z=Tn(e=>e.currentSessionId),B=Tn(e=>e.createSession),H=Tn(e=>e.initializeNewOpenChamberSession),U=Tn(e=>e.sendMessage),ee=Tn(e=>e.setCurrentSession),te=Lt(e=>e.setPendingInputText),W=Pe(e=>e.currentDirectory),ne=p(e=>e.openContextPanelTab),G=p(e=>e.setActiveMainTab),re=p(e=>e.setSessionSwitcherOpen),K=p(e=>e.padding),ie=Q.useCallback(async(t,n)=>{if(!e)return!1;let r=e.id,i=(Fu.get(r)??Promise.resolve()).catch(()=>void 0).then(()=>zt(e,{notes:t,todos:n}));Fu.set(r,i);try{let e=await i;return e||J.error(a(`rightSidebar.contextNotesTodo.toast.saveNotesFailed`)),e}finally{Fu.get(r)===i&&Fu.delete(r)}},[e,a]);Q.useEffect(()=>{if(!e){l(``),d([]),b([]),m(``),v(new Set);return}let t=!1;return s(!0),(async()=>{try{let n=await Et(e),r=await Promise.all(n.plans.map(e=>Ru(e,a(`rightSidebar.contextNotesTodo.plan.defaultTitle`))));if(t)return;l(n.notes),d(Bu(n.todos)),b(r),O.current=n.notes,D.current=!0,m(``),v(new Set)}catch{t||(J.error(a(`rightSidebar.contextNotesTodo.toast.loadNotesFailed`)),l(``),d([]),b([]),O.current=``,D.current=!0)}finally{t||s(!1)}})(),()=>{t=!0}},[T,e,a]),Q.useEffect(()=>{if(!e)return;let t=t=>{let n=t.detail;n?.projectId&&n.projectId!==e.id||E(e=>e+1)};return window.addEventListener(`openchamber:project-plan-saved`,t),window.addEventListener(`openchamber:project-notes-updated`,t),()=>{window.removeEventListener(`openchamber:project-plan-saved`,t),window.removeEventListener(`openchamber:project-notes-updated`,t)}},[e]),Q.useEffect(()=>{if(u.length<7)return;let e=Lu(u.length,K),t=Iu(K)*Nu;A!==e&&(A<t||A>e)&&j(e)},[u.length,K,A,j]),Q.useEffect(()=>{if(!F)return;let e=e=>{let t=e.clientY-L.current,n=Math.min(Iu(K)*Pu,Math.max(Iu(K)*Nu,R.current+t));j(n)},t=()=>{I(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t,{once:!0}),window.addEventListener(`pointercancel`,t,{once:!0}),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,t)}},[F,K,j]);let ae=Q.useCallback(e=>{I(!0),L.current=e.clientY,R.current=A,e.preventDefault()},[A]),oe=Q.useCallback(()=>{k.current!==null&&(window.clearTimeout(k.current),k.current=null)},[]),se=Q.useCallback(()=>{oe(),O.current=c,ie(c,u)},[oe,c,ie,u]);Q.useEffect(()=>{if(!(!e||!D.current)&&c!==O.current)return k.current=window.setTimeout(()=>{k.current=null,O.current=c,ie(c,u)},400),()=>{oe()}},[oe,c,ie,e,u]),Q.useEffect(()=>()=>oe(),[oe]);let ce=Q.useCallback(()=>{let e=f.trim();if(!e)return;let t=Vu(u,{id:zu(),text:e.slice(0,120),completed:!1,createdAt:Date.now()});d(t),m(``),ie(c,t)},[f,c,ie,u]),le=Q.useCallback(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=Q.useCallback((e,t)=>{let n=u.find(t=>t.id===e);if(!n||n.completed===t)return;let r=u.filter(t=>t.id!==e),i={...n,completed:t},a=t?[...r,i]:Vu(r,i);d(a),ie(c,a)},[c,ie,u]),de=Q.useCallback(e=>{let t=u.filter(t=>t.id!==e);d(t),ie(c,t)},[c,ie,u]),fe=Q.useCallback(()=>{let e=u.filter(e=>!e.completed);e.length!==u.length&&(d(e),ie(c,e))},[c,ie,u]),pe=Q.useCallback(e=>{let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=u.findIndex(e=>e.id===t.id),i=u.findIndex(e=>e.id===n.id);if(r===-1||i===-1)return;let a=Bu(Oo(u,r,i));d(a),ie(c,a)},[c,ie,u]),me=To(vo(Co,{activationConstraint:{distance:8}})),he=f.slice(0,120),ge=u.reduce((e,t)=>e+ +!!t.completed,0),_e=Q.useCallback(()=>{G(`chat`),re(!1)},[G,re]),ve=Q.useCallback((t,n)=>{!e||h||S({kind:`session`,todoId:t,todoText:n})},[e,h]),ye=Q.useCallback(e=>{if(!z){J.error(a(`rightSidebar.contextNotesTodo.toast.noActiveSession`));return}_e();let t=`\`\`\`md\n${e}\n\`\`\``;te(t,`append`),J.success(a(`rightSidebar.contextNotesTodo.toast.sentToCurrentSession`)),r?.()},[z,r,_e,te,a]),be=Q.useCallback((t,r)=>{if(!(!e||h)){if(!n){J.error(a(`rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo`));return}S({kind:`worktree`,todoId:t,todoText:r})}},[n,e,h,a]),xe=Q.useCallback(async t=>{if(!e||!x)return;let i=await vt(`plan.todo.visible`,{todo_text:x.todoText}),o=[{synthetic:!0,text:await vt(`plan.todo.instructions`,{todo_text:x.todoText})}];w(!0),g(x.todoId);try{_e();let s=null,c=e.path;if(x.kind===`worktree`){if(!n){J.error(a(`rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo`));return}let t=await Fa(e.path,Qa());if(!t?.id)return;s=t.id,c=t.path}else{let t=await B(void 0,e.path,null);if(!t?.id){J.error(a(`rightSidebar.contextNotesTodo.toast.createSessionFailed`));return}s=t.id,c=t.directory??e.path,H(t.id,Ut.getState().agents??[])}if(!s)return;let l=ht.getState();l.saveSessionModelSelection(s,t.providerID,t.modelID),t.agent.trim()&&(l.saveSessionAgentSelection(s,t.agent),l.saveAgentModelForSession(s,t.agent,t.providerID,t.modelID),l.saveAgentModelVariantForSession(s,t.agent,t.providerID,t.modelID,t.variant||void 0)),ee(s,c),await U(i,t.providerID,t.modelID,t.agent.trim()||void 0,void 0,void 0,o,t.variant||void 0),J.success(x.kind===`worktree`?a(`rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession`):a(`rightSidebar.contextNotesTodo.toast.sentToNewSession`)),S(null),r?.()}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.sendTodoFailed`),t?{description:t}:void 0)}finally{w(!1),g(null)}},[n,B,H,r,x,e,_e,U,ee,a]),Se=Q.useRef(null),[Ce,we]=Q.useState(!1),[Te,Ee]=Q.useState(null),De=Q.useCallback(async t=>{if(!(!e||Te)){Ee(t);try{if(!await Sn(e,t)){J.error(a(`rightSidebar.contextNotesTodo.toast.deletePlanFailed`));return}b(e=>e.filter(e=>e.id!==t)),window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}}))}finally{Ee(null)}}},[Te,e,a]),Oe=Q.useCallback(async()=>{if(!e||Ce)return;let t=await P({defaultPath:e.path,filters:[{name:`Plan files`,extensions:[`md`,`markdown`,`txt`]},{name:`All files`,extensions:[`*`]}]});if(t.success&&t.path){we(!0);try{let n=new URLSearchParams({path:t.path,allowOutsideWorkspace:`true`});t.outsideFileGrant&&n.set(`outsideFileGrant`,t.outsideFileGrant);let r=await V(`/api/fs/read?${n.toString()}`,{cache:`no-store`});if(!r.ok){J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`));return}let i=await r.text();if(!i.trim()){J.error(a(`rightSidebar.contextNotesTodo.toast.planFileEmpty`));return}let o=t.path.split(`/`).pop()?.replace(/\.(md|markdown|txt)$/i,``).trim()||``;if(!await Pt(e,i,o)){J.error(a(`rightSidebar.contextNotesTodo.toast.importPlanFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}})),J.success(a(`rightSidebar.contextNotesTodo.toast.planImported`))}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`),t?{description:t}:void 0)}finally{we(!1)}}else t.error===`Native file picker not available`&&Se.current?.click()},[Ce,e,a]),ke=Q.useCallback(async t=>{if(!(!e||!t)){we(!0);try{let n=await t.text();if(!n.trim()){J.error(a(`rightSidebar.contextNotesTodo.toast.planFileEmpty`));return}let r=t.name.replace(/\.(md|markdown|txt)$/i,``).trim();if(!await Pt(e,n,r)){J.error(a(`rightSidebar.contextNotesTodo.toast.importPlanFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-plan-saved`,{detail:{projectId:e.id}})),J.success(a(`rightSidebar.contextNotesTodo.toast.planImported`))}catch(e){let t=e instanceof Error?e.message:void 0;J.error(a(`rightSidebar.contextNotesTodo.toast.readPlanFileFailed`),t?{description:t}:void 0)}finally{we(!1)}}},[e,a]),Ae=Q.useCallback(t=>{let n=e?.path?.trim(),r=W?.trim()||n;r&&ne(r,{mode:`plan`,targetPath:t.path,dedupeKey:t.path,label:t.title})},[W,ne,e]);return e?(0,$.jsxs)(`div`,{className:Y(`w-full min-w-0 space-y-3 p-3`,i),children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-semibold text-foreground`,title:e.path,children:a(`rightSidebar.contextNotesTodo.notes.title`,{project:t?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[c.length,`/`,it]})]}),(0,$.jsx)(Pi,{value:c,onChange:e=>l(e.target.value.slice(0,it)),onBlur:se,placeholder:a(`rightSidebar.contextNotesTodo.notes.placeholder`),resizedHeight:M,onResizeHeightChange:N,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`rightSidebar.contextNotesTodo.todo.title`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:u.length===1?a(`rightSidebar.contextNotesTodo.todo.itemsSingle`,{count:u.length}):a(`rightSidebar.contextNotesTodo.todo.itemsPlural`,{count:u.length})}),(0,$.jsx)(`button`,{type:`button`,onClick:fe,disabled:o||ge===0,className:`typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,children:a(`rightSidebar.contextNotesTodo.todo.clearCompleted`)})]}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[he.length,`/`,120]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(zi,{value:he,onChange:e=>m(e.target.value.slice(0,120)),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ce())},placeholder:a(`rightSidebar.contextNotesTodo.todo.inputPlaceholder`),disabled:o,className:`h-8`}),(0,$.jsx)(`button`,{type:`button`,onClick:ce,disabled:o||he.trim().length===0,className:`inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.addAria`),title:a(`rightSidebar.contextNotesTodo.todo.addAria`),children:(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:Y(`overflow-y-auto rounded-lg border border-border/60 bg-background/40`,F&&`transition-none`),style:u.length<7?void 0:{height:`${A}px`,maxHeight:`${A}px`},children:u.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.todo.empty`)}):(0,$.jsx)(wo,{sensors:me,collisionDetection:xo,onDragEnd:pe,children:(0,$.jsx)(jo,{items:u.map(e=>e.id),strategy:Ao,children:(0,$.jsx)(`ul`,{className:`divide-y divide-border/50`,children:u.map(e=>{let t=_.has(e.id);return(0,$.jsx)(Hu,{id:e.id,children:r=>(0,$.jsxs)(`div`,{className:Y(`flex gap-1.5 px-2.5 py-1.5`,t?`items-start`:`items-center`),children:[(0,$.jsx)(`button`,{type:`button`,ref:r.setActivatorNodeRef,...r.attributes,...r.listeners,onClick:e=>{e.preventDefault(),e.stopPropagation()},className:`flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.reorder`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.reorder`,{text:e.text}),children:(0,$.jsx)(X,{name:`draggable`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:`flex h-6 items-center`,children:(0,$.jsx)(Ci,{checked:e.completed,onChange:t=>ue(e.id,t),ariaLabel:a(`rightSidebar.contextNotesTodo.todo.actions.markComplete`,{text:e.text})})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>le(e.id),className:Y(`block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground`,t?`whitespace-normal break-words`:`overflow-hidden text-ellipsis whitespace-nowrap`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,e.completed&&`text-muted-foreground line-through`),title:t?void 0:e.text,"aria-label":a(t?`rightSidebar.contextNotesTodo.todo.actions.collapse`:`rightSidebar.contextNotesTodo.todo.actions.expand`,{text:e.text}),children:e.text}),(0,$.jsxs)(`div`,{className:`flex h-6 items-center gap-0.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>de(e.id),className:`inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.delete`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.delete`,{text:e.text}),children:(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`})}),(0,$.jsxs)(ta,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:h===e.id,className:`inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.actions.send`,{text:e.text}),title:a(`rightSidebar.contextNotesTodo.todo.actions.send`,{text:e.text}),children:(0,$.jsx)(X,{name:`send-plane`,className:`h-3.5 w-3.5`})})}),(0,$.jsxs)(ea,{align:`end`,className:`w-56`,children:[(0,$.jsx)(la,{onClick:()=>ye(e.text),children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.currentSession`)}),(0,$.jsx)(la,{onClick:()=>ve(e.id,e.text),children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.newSession`)}),(0,$.jsx)(la,{onClick:()=>void be(e.id,e.text),disabled:!n,children:a(`rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession`)})]})]})]})]})},e.id)})})})})}),u.length>=7&&(0,$.jsx)(`div`,{className:Y(`h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors`,F&&`bg-[var(--interactive-border)]`),onPointerDown:ae,role:`separator`,"aria-orientation":`horizontal`,"aria-label":a(`rightSidebar.contextNotesTodo.todo.resizeAria`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-foreground`,children:a(`rightSidebar.contextNotesTodo.plans.title`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:y.length===1?a(`rightSidebar.contextNotesTodo.plans.filesSingle`,{count:y.length}):a(`rightSidebar.contextNotesTodo.plans.filesPlural`,{count:y.length})})]}),(0,$.jsx)(`input`,{ref:Se,type:`file`,accept:`.md,.markdown,.txt,text/markdown,text/plain`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;ke(t),e.currentTarget.value=``}}),(0,$.jsx)(`button`,{type:`button`,onClick:Oe,disabled:!e||Ce,className:`inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":a(`rightSidebar.contextNotesTodo.plans.importFromFile`),title:a(`rightSidebar.contextNotesTodo.plans.importFromFile`),children:(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40`,children:y.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.plans.empty`)}):(0,$.jsx)(`ul`,{className:`divide-y divide-border/50`,children:y.map(e=>(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2.5 py-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Ae(e),className:`flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label text-foreground`,children:e.title}),(0,$.jsx)(`span`,{className:`flex-shrink-0 typography-micro text-muted-foreground`,children:new Date(e.createdAt).toLocaleDateString(Qe())})]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void De(e.id),disabled:Te===e.id,className:`inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50`,title:a(`rightSidebar.contextNotesTodo.plans.deletePlan`),"aria-label":a(`rightSidebar.contextNotesTodo.plans.deletePlanWithTitle`,{title:e.title}),children:(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`})})]},e.id))})})]}),(0,$.jsx)(xu,{open:x!==null,onOpenChange:e=>{!e&&!C&&S(null)},target:x?.kind??`session`,projectDirectory:e?.path??null,submitting:C,onConfirm:xe})]}):(0,$.jsx)(`div`,{className:Y(`w-full min-w-0 p-3`,i),children:(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:a(`rightSidebar.contextNotesTodo.empty.selectProject`)})})},Wu=12,Gu=[{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`}],Ku=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?Gu: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:Wu},qu),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 qu(e,t){let n=Math.PI*2*t/Wu;return{x:Math.cos(n),y:Math.sin(n),delay:t*18}}var Ju=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(Yu)},t[4]=d):d=t[4];let f=d,p;t[5]===i?p=t[6]:(p=()=>{u(),s(Xu),c.current=window.setTimeout(()=>{s(Zu),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 Yu(e){return e.isActive?{...e,isActive:!1}:e}function Xu(e){return{isActive:!0,cycle:e.cycle+1}}function Zu(e){return e.isActive?{...e,isActive:!1}:e}var Qu=Q.createContext(void 0),$u=e=>{let t=(0,zc.c)(10),{children:n}=e,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:o}=Ju(),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)(Ku,{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)(Qu.Provider,{value:c,children:[n,l]}),t[6]=n,t[7]=l,t[8]=c,t[9]=u):u=t[9],u},ed=()=>{let e=Q.useContext(Qu);if(!e)throw Error(`useFireworksCelebration must be used within FireworksProvider`);return e},td=`gitmojiCache`,nd=6048e5,rd=`1`,id=`https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json`,ad=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.emoji==`string`&&typeof t.code==`string`&&typeof t.description==`string`},od=()=>{if(typeof window>`u`)return null;try{let e=window.localStorage.getItem(td);if(!e)return null;let t=JSON.parse(e);return!t||t.version!==rd||typeof t.fetchedAt!=`number`||!Array.isArray(t.gitmojis)?null:{gitmojis:t.gitmojis.filter(ad),fetchedAt:t.fetchedAt,version:t.version}}catch{return null}},sd=e=>{if(!(typeof window>`u`))try{let t={gitmojis:e,fetchedAt:Date.now(),version:rd};window.localStorage.setItem(td,JSON.stringify(t))}catch{return}},cd=e=>Date.now()-e.fetchedAt<nd,ld=null,ud=new Set,dd=async()=>{if(ld)return ld;let e=(async()=>{try{let e=await fetch(id);if(!e.ok)throw Error(`Failed to load gitmojis: ${e.statusText}`);let t=await e.json(),n=Array.isArray(t.gitmojis)?t.gitmojis.filter(ad):[];return sd(n),ud.forEach(e=>e(n)),n}catch(e){console.warn(`Failed to load gitmoji list:`,e);let t=[];return ud.forEach(e=>e(t)),t}finally{ld=null}})();return ld=e,e},fd=e=>{let[t,n]=Q.useState(()=>e?od()?.gitmojis??[]:[]),[r,i]=Q.useState(!1),a=Q.useRef(e);return a.current=e,Q.useEffect(()=>{if(!e){ud.delete(n),n([]),i(!1);return}let t=od();if(t&&(n(t.gitmojis),cd(t)))return;ud.add(n),i(!0);let r=!1;return dd().finally(()=>{!r&&a.current&&i(!1)}),()=>{r=!0,ud.delete(n)}},[e]),{gitmojis:t,isLoading:r,ensureLoaded:Q.useCallback(async()=>{if(!a.current)return[];if(t.length>0)return t;let e=od();return e&&cd(e)?e.gitmojis:dd()},[t])}},pd=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)};function md(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),dr(e)]).catch(hd);if(r)return;let o=pd(t),s=pd(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 hd(){return[``,``]}var gd=({open:e,onOpenChange:t,directory:n,hasUncommittedChanges:r,hasStagedChanges:i=!1,uncommittedFileCount:a,onChanged:o})=>{let{t:s}=Xe(),[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 fr(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 _r(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 hr(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 Dr(n,{ref:e.ref}),t===`pop`&&await gr(n,{ref:e.ref}),t===`drop`&&await vr(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)(ur,{open:e,onOpenChange:t,children:(0,$.jsxs)(sr,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsxs)(cr,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`h-5 w-5`}),s(`gitView.stashes.title`)]}),(0,$.jsx)(lr,{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)(zi,{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)(zi,{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)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{children:t===0&&!f.trim()?s(`gitView.stashes.latestLabel`):s(`gitView.stashes.itemNumber`,{number:t+1})})}),(0,$.jsx)(Vi,{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)(_d,{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)(_d,{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)(_d,{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))})]})})},_d=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)(Bi,{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)(Vi,{sideOffset:6,children:n}),t[12]=n,t[13]=p);let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(Ui,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m},vd=e=>{let t=(0,zc.c)(16),{onOpenStashes:n}=e,{t:r}=Xe(),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},yd=8,bd=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)*yd+yd/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*yd+yd/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(Sd);for(let e of g){let t=e.fromLane*yd+yd/2,r=e.toLane*yd+yd/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 xd(e){return e===`branch-out`||e===`merge-in`}function Sd(e,t){let n=xd;return!!n(e.type)-+!!n(t.type)}var Cd=15e3,wd=500,Td=12,Ed=8388608,Dd=e=>typeof e==`string`?0:(e.original?.length??0)+(e.modified?.length??0),Od=e=>{if(e.size<=Td){let t=0;for(let n of e.values())t+=Dd(n);if(t<=Ed)return e}let t=Array.from(e.entries()).reverse(),n=new Map,r=0;for(let[e,i]of t){if(n.size>=Td)continue;let t=Dd(i);r+t>Ed&&n.size>0||(n.set(e,i),r+=t)}return new Map(Array.from(n.entries()).reverse())};function kd(e,t){let n=new Date(e);return Number.isNaN(n.getTime())?e:ya(n,t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function Ad(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 jd(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 Md=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}=Xe(),m=p(e=>e.timeFormatPreference),h=t===`graph`,[g,_]=Q.useState(null),[v,y]=Q.useState(!1),[b,x]=Q.useState(``),[S,C]=Q.useState(null),[w,T]=Q.useState(new Set),[E,D]=Q.useState(new Map),[O,k]=Q.useState(new Set),A=async()=>{if(l){_(`checkout`);try{await Er(l,e.hash),J.success(f(`gitView.history.actions.detachedHead`)),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},j=async()=>{if(!(!l||!b.trim())){_(`createBranch`);try{await wr(l,b.trim(),e.hash),y(!1),x(``),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},M=async()=>{if(l){_(`cherryPick`);try{let t=await br(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`cherry-pick`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},N=async()=>{if(l){_(`revert`);try{let t=await xr(l,e.hash);t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`revert`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},P=async(t,n=!1)=>{if(!(!l||g!==null)){_(`reset`);try{await mr(l,e.hash,t,n),d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},F=async()=>{if(!S)return;let e=S;switch(C(null),e){case`checkout`:return A();case`cherryPick`:return M();case`revert`:return N();case`merge`:return I();case`rebase`:return L();case`resetSoft`:return P(`soft`);case`resetMixed`:return P(`mixed`);case`resetHard`:return P(`hard`,!0)}},I=async()=>{if(l){_(`merge`);try{let t=await Or(l,{branch:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`merge`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},L=async()=>{if(l){_(`rebase`);try{let t=await pr(l,{onto:e.hash});t.conflict?u?.({conflict:!0,conflictFiles:t.conflictFiles,operation:`rebase`}):d?.()}catch(e){J.error(String(e.message))}finally{_(null)}}},R=Q.useCallback(async t=>{let n=t.path;if(!l){D(e=>new Map(e).set(n,`error`));return}D(e=>Od(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 ${Cd}ms`)),Cd)}),a=await Promise.race([r,i]);D(e=>Od(new Map(e).set(n,a)))}catch{D(e=>new Map(e).set(n,`error`))}},[l,e.hash]),z=Q.useCallback(async e=>{let t=e.path;if(e.changeType===`R`||e.isBinary){T(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n});return}let n=E.get(t);if(w.has(t)&&n&&n!==`error`){T(e=>{let n=new Set(e);return n.delete(t),n});return}T(e=>{let n=new Set(e);return n.add(t),n}),!(n&&n!==`error`)&&(e.insertions+e.deletions>wd&&!O.has(t)||await R(e))},[E,O,R,w]);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`,h?`hover:bg-[var(--interactive-hover)]/40`:i?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[h&&n&&r!==void 0?(0,$.jsx)(`div`,{className:`-my-2 shrink-0 self-stretch`,children:(0,$.jsx)(bd,{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:[h?(()=>{let t=jd(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:kd(e.date,m),children:kd(e.date,m)})]}),(0,$.jsx)(`span`,{className:`shrink-0`,children:`·`}),(0,$.jsx)(`code`,{className:`shrink-0 font-mono`,children:e.hash.slice(0,8)}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{sideOffset:8,children:f(`gitView.history.copySha`)})]})]})]})]}),i&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 pl-8 border-t border-border/40`,children:[h&&S?(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.${S}Confirm`)}),(0,$.jsxs)(Z,{variant:`destructive`,size:`xs`,className:`h-6 shrink-0`,disabled:g!==null,onClick:e=>{e.stopPropagation(),F()},children:[g===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:g!==null,onClick:e=>{e.stopPropagation(),C(null)},children:f(`gitView.history.actions.cancelButton`)})]}):h?(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:g!==null,onClick:e=>{e.stopPropagation(),C(`checkout`)},children:f(`gitView.history.actions.checkout`)}),v?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&(y(!1),x(``))},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:!b.trim()||g!==null,onClick:e=>{e.stopPropagation(),j()},children:[g===`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(),y(!0)},children:f(`gitView.history.actions.createBranch`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`cherryPick`)},children:f(`gitView.history.actions.cherryPick`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`revert`)},children:f(`gitView.history.actions.revert`)}),(0,$.jsxs)(ta,{children:[(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>e.stopPropagation(),children:[g===`reset`?(0,$.jsx)(X,{name:`loader-4`,className:`size-3 animate-spin mr-1`}):null,f(`gitView.history.actions.reset`)]})}),(0,$.jsx)(ea,{align:`start`,className:`min-w-max`,children:[`soft`,`mixed`,`hard`].map(e=>(0,$.jsx)(la,{disabled:g!==null,onSelect:t=>{t.stopPropagation(),C(`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:g!==null,onClick:e=>{e.stopPropagation(),C(`merge`)},children:f(`gitView.history.actions.merge`)}),(0,$.jsx)(Z,{variant:`outline`,size:`xs`,className:`h-6`,disabled:g!==null,onClick:e=>{e.stopPropagation(),C(`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:()=>z(e),className:Y(`w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1`,w.has(e.path)?`bg-sidebar/90`:`hover:bg-sidebar/40`),children:[(0,$.jsx)(`span`,{className:Y(`font-semibold w-3 text-center shrink-0`,Ad(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:w.has(e.path)?`arrow-down-s`:`arrow-right-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),w.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(!O.has(e.path)&&t>wd)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:()=>{k(t=>new Set(t).add(e.path)),R(e)},children:f(`gitView.history.renderDiffAnyway`)})]});let n=E.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:()=>z(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)(tc,{original:n.original,modified:n.modified,language:Lo(e.path)||``,fileName:e.path,renderSideBySide:!1,layout:`inline`,enableComments:!1})})()})]},e.path))})]})]})}),Nd=[`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 Pd(e){return Nd[e%Nd.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=Pd(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:Pd(e),type:`merge-in`}),t[e]=null;for(let e of d)f.push({fromLane:o,toLane:e,color:Pd(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:Pd(e),type:`passing`}));n.push({commit:i,lane:o,color:c,connectors:f})}return n}var Id=[{labelKey:`gitView.history.logSize25`,value:25},{labelKey:`gitView.history.logSize50`,value:50},{labelKey:`gitView.history.logSize100`,value:100}],Ld=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}=Xe(),[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(Rd)),t[3]=D,t[4]=O);let k=O,A;t[5]===D?A=t[6]:(A=new Map(D.map(zd)),t[5]=D,t[6]=A);let j=A;if(!r)return null;let M=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<r.all.length,N=x!==null&&x.insertBeforeIndex===r.all.length,P=M||N,F;t[7]!==x||t[8]!==M||t[9]!==N||t[10]!==r.all?(F=M?r.all.slice(0,x.insertBeforeIndex):N?r.all:[],t[7]=x,t[8]=M,t[9]=N,t[10]=r.all,t[11]=F):F=t[11];let I=F,L;if(t[12]!==x||t[13]!==l||t[14]!==b||t[15]!==f||t[16]!==s||t[17]!==M||t[18]!==P||t[19]!==T||t[20]!==i||t[21]!==j||t[22]!==u||t[23]!==r.all||t[24]!==a||t[25]!==k||t[26]!==v||t[27]!==_||t[28]!==g||t[29]!==d||t[30]!==o||t[31]!==c||t[32]!==S||t[33]!==I){let e=M?r.all.slice(x.insertBeforeIndex):[],n;t[35]===x?.direction?n=t[36]:(n=x?.direction===`down`?(0,$.jsx)(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)(Md,{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;L=(0,$.jsx)(xi,{outerClassName:`min-h-0 ${b}`,className:`h-full w-full`,children:r.all.length===0?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,$.jsx)(`p`,{className:`typography-ui-label text-muted-foreground`,children:S(`gitView.history.noCommits`)})}):P&&x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0`,children:[I.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(I)}):null,(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`}),(0,$.jsxs)(`span`,{className:`inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`truncate`,title:x.branchName,children:x.branchName}),p]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border/60`})]}),e.length>0?(0,$.jsx)(`div`,{className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:h(e)}):null]}),C]}):(0,$.jsxs)($.Fragment,{children:[h(r.all),C]})}),t[12]=x,t[13]=l,t[14]=b,t[15]=f,t[16]=s,t[17]=M,t[18]=P,t[19]=T,t[20]=i,t[21]=j,t[22]=u,t[23]=r.all,t[24]=a,t[25]=k,t[26]=v,t[27]=_,t[28]=g,t[29]=d,t[30]=o,t[31]=c,t[32]=S,t[33]=I,t[34]=L}else L=t[34];let R=L;if(!y){if(P){let e;return t[56]===R?e=t[57]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0`,children:R}),t[56]=R,t[57]=e),e}let e;return t[58]===R?e=t[59]:(e=(0,$.jsx)(`section`,{className:`h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:R}),t[58]=R,t[59]=e),e}let z;t[60]===S?z=t[61]:(z=S(`gitView.history.title`),t[60]=S,t[61]=z);let B;t[62]===z?B=t[63]:(B=(0,$.jsx)(`h3`,{className:`typography-ui-header font-semibold text-foreground`,children:z}),t[62]=z,t[63]=B);let V;t[64]!==i||t[65]!==C||t[66]!==a||t[67]!==o||t[68]!==S?(V=C&&(0,$.jsx)(`div`,{onClick:Bd,onPointerDown:Vd,children:(0,$.jsxs)(Oi,{value:String(a),onValueChange:e=>o(Number(e)),disabled:i,children:[(0,$.jsx)(Ri,{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)(wi,{placeholder:S(`gitView.history.commitsPlaceholder`)})}),(0,$.jsx)(Di,{children:Id.map(e=>(0,$.jsx)(Li,{value:String(e.value),children:S(e.labelKey)},e.value))})]})}),t[64]=i,t[65]=C,t[66]=a,t[67]=o,t[68]=S,t[69]=V):V=t[69];let H;t[70]===C?H=t[71]:(H=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]=H);let U;t[72]!==V||t[73]!==H?(U=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V,H]}),t[72]=V,t[73]=H,t[74]=U):U=t[74];let ee;t[75]!==B||t[76]!==U?(ee=(0,$.jsxs)(yc,{className:`flex w-full items-center justify-between px-3 h-10 hover:bg-transparent`,children:[B,U]}),t[75]=B,t[76]=U,t[77]=ee):ee=t[77];let te;t[78]===R?te=t[79]:(te=(0,$.jsx)(vc,{children:R}),t[78]=R,t[79]=te);let W;return t[80]!==C||t[81]!==ee||t[82]!==te?(W=(0,$.jsxs)(bc,{open:C,onOpenChange:w,className:`rounded-xl border border-border/60 bg-background/70 overflow-hidden`,children:[ee,te]}),t[80]=C,t[81]=ee,t[82]=te,t[83]=W):W=t[83],W};function Rd(e){return e.lane+1}function zd(e){return[e.commit.hash,e]}function Bd(e){return e.stopPropagation()}function Vd(e){return e.stopPropagation()}var Hd=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}=Xe(),f=Tn(Ud),m=Tn(Wd),h=Lt(Gd),g=Lt(Kd),_=p(qd),[v,y]=Q.useState(!1),[b,x]=Q.useState(null),[S,C]=Q.useState(null),w,T;t[2]!==a||t[3]!==n||t[4]!==d?(w=()=>{!n||!a||(y(!0),C(null),x(null),yr(a).then(e=>{x(e)}).catch(e=>{let t=e instanceof Error?e.message:d(`gitView.conflict.loadFailed`);C(t)}).finally(()=>{y(!1)}))},T=[n,a,d],t[2]=a,t[3]=n,t[4]=d,t[5]=w,t[6]=T):(w=t[5],T=t[6]),Q.useEffect(w,T);let E;t[7]!==b||t[8]!==a||t[9]!==o?(E=async()=>{if(!b)return null;let e=o===`merge`?`merge`:`rebase`,t=b.headInfo||(o===`merge`?`MERGE_HEAD`:`REBASE_HEAD`),n=o===`merge`?`git commit --no-edit`:`git rebase --continue`;return{visibleText:await vt(`git.conflict.resolve.visible`,{operation_label:e,head_ref:t}),instructionsText:await vt(`git.conflict.resolve.instructions`,{operation_label:e,directory:a,operation:o,head_info:b.headInfo||`N/A`,continue_cmd:n}),payloadText:`${e} conflict context (JSON)\n${JSON.stringify({directory:a,operation:b.operation,headInfo:b.headInfo,statusPorcelain:b.statusPorcelain,unmergedFiles:b.unmergedFiles,diff:b.diff},null,2)}`}},t[7]=b,t[8]=a,t[9]=o,t[10]=E):E=t[10];let D=E,O;t[11]!==s||t[12]!==r?(O=()=>{s(),r(!1)},t[11]=s,t[12]=r,t[13]=O):O=t[13];let k=O,A;t[14]!==c||t[15]!==r?(A=()=>{c?.(),r(!1)},t[14]=c,t[15]=r,t[16]=A):A=t[16];let j=A,M;t[17]!==D||t[18]!==m||t[19]!==c||t[20]!==r||t[21]!==_||t[22]!==h||t[23]!==g||t[24]!==d?(M=async()=>{let e=await D();if(!e){J.error(d(`gitView.conflict.noDetailsAvailable`));return}if(!m){J.error(d(`gitView.conflict.noActiveSession`),{description:d(`gitView.conflict.noActiveSessionDescription`)});return}h(e.visibleText,`replace`),g([{text:e.instructionsText,synthetic:!0},{text:e.payloadText,synthetic:!0}]),_(`chat`),c?.(),r(!1)},t[17]=D,t[18]=m,t[19]=c,t[20]=r,t[21]=_,t[22]=h,t[23]=g,t[24]=d,t[25]=M):M=t[25];let N=M,P;t[26]!==D||t[27]!==a||t[28]!==c||t[29]!==r||t[30]!==f||t[31]!==_||t[32]!==d?(P=async()=>{let e=await D();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}]}),_(`chat`),c?.(),r(!1)},t[26]=D,t[27]=a,t[28]=c,t[29]=r,t[30]=f,t[31]=_,t[32]=d,t[33]=P):P=t[33];let F=P,I,L,R,z,B,V,H,U,ee,te,W,ne,G,re,K,ie,ae,oe,se,ce,le,ue;if(t[34]!==b||t[35]!==u||t[36]!==m||t[37]!==k||t[38]!==j||t[39]!==N||t[40]!==F||t[41]!==v||t[42]!==S||t[43]!==r||t[44]!==n||t[45]!==o||t[46]!==d){let e=d(o===`merge`?`gitView.operation.merge`:`gitView.operation.rebase`),i=b?.unmergedFiles||u;R=ur,le=n,ue=r,L=sr,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)(cr,{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)(lr,{children:c}),t[73]=c,t[74]=l),t[75]!==s||t[76]!==l?(K=(0,$.jsxs)(ar,{children:[s,l]}),t[75]=s,t[76]=l,t[77]=K):K=t[77],t[78]!==v||t[79]!==d?(ie=v&&(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]=v,t[79]=d,t[80]=ie):ie=t[80],t[81]!==S||t[82]!==d?(ae=S&&(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:S})}),t[81]=S,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(Jd)})})]}),t[84]=i,t[85]=d,t[86]=oe):oe=t[86],t[87]!==b||t[88]!==d?(se=b?.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:b.headInfo})]}),t[87]=b,t[88]=d,t[89]=se):se=t[89],W=`flex flex-col gap-2 pt-2`;let f;t[90]===F?f=t[91]:(f=()=>{F()},t[90]=F,t[91]=f);let p=v||!b,h;t[92]===v?h=t[93]:(h=v?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`}),t[92]=v,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]!==p||t[98]!==h||t[99]!==g?(ne=(0,$.jsxs)(Z,{variant:`default`,onClick:f,disabled:p,className:`w-full gap-2`,children:[h,g]}),t[96]=f,t[97]=p,t[98]=h,t[99]=g,t[100]=ne):ne=t[100];let _;t[101]===N?_=t[102]:(_=()=>void N(),t[101]=N,t[102]=_);let y=v||!b||!m,x;t[103]===v?x=t[104]:(x=v?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`chat-1`,className:`size-4`}),t[103]=v,t[104]=x);let C;t[105]===d?C=t[106]:(C=d(`gitView.conflict.resolveCurrentSession`),t[105]=d,t[106]=C),t[107]!==_||t[108]!==y||t[109]!==x||t[110]!==C?(G=(0,$.jsxs)(Z,{variant:`outline`,onClick:_,disabled:y,className:`w-full gap-2`,children:[x,C]}),t[107]=_,t[108]=y,t[109]=x,t[110]=C,t[111]=G):G=t[111],ee=`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]!==j||t[115]!==w?(te=(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:j,className:`flex-1`,children:w}),t[114]=j,t[115]=w,t[116]=te):te=t[116],I=Z,z=`destructive`,B=`sm`,V=k,H=`flex-1`,U=d(`gitView.conflict.abortOperation`,{operation:e}),t[34]=b,t[35]=u,t[36]=m,t[37]=k,t[38]=j,t[39]=N,t[40]=F,t[41]=v,t[42]=S,t[43]=r,t[44]=n,t[45]=o,t[46]=d,t[47]=I,t[48]=L,t[49]=R,t[50]=z,t[51]=B,t[52]=V,t[53]=H,t[54]=U,t[55]=ee,t[56]=te,t[57]=W,t[58]=ne,t[59]=G,t[60]=re,t[61]=K,t[62]=ie,t[63]=ae,t[64]=oe,t[65]=se,t[66]=ce,t[67]=le,t[68]=ue}else I=t[47],L=t[48],R=t[49],z=t[50],B=t[51],V=t[52],H=t[53],U=t[54],ee=t[55],te=t[56],W=t[57],ne=t[58],G=t[59],re=t[60],K=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]!==I||t[118]!==z||t[119]!==B||t[120]!==V||t[121]!==H||t[122]!==U?(de=(0,$.jsx)(I,{variant:z,size:B,onClick:V,className:H,children:U}),t[117]=I,t[118]=z,t[119]=B,t[120]=V,t[121]=H,t[122]=U,t[123]=de):de=t[123];let fe;t[124]!==ee||t[125]!==te||t[126]!==de?(fe=(0,$.jsxs)(`div`,{className:ee,children:[te,de]}),t[124]=ee,t[125]=te,t[126]=de,t[127]=fe):fe=t[127];let pe;t[128]!==W||t[129]!==ne||t[130]!==G||t[131]!==fe?(pe=(0,$.jsxs)(`div`,{className:W,children:[ne,G,fe]}),t[128]=W,t[129]=ne,t[130]=G,t[131]=fe,t[132]=pe):pe=t[132];let me;t[133]!==re||t[134]!==K||t[135]!==ie||t[136]!==ae||t[137]!==oe||t[138]!==se||t[139]!==pe?(me=(0,$.jsxs)(`div`,{className:re,children:[K,ie,ae,oe,se,pe]}),t[133]=re,t[134]=K,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]!==L||t[142]!==ce||t[143]!==me?(he=(0,$.jsx)(L,{className:ce,children:me}),t[141]=L,t[142]=ce,t[143]=me,t[144]=he):he=t[144];let ge;return t[145]!==R||t[146]!==le||t[147]!==ue||t[148]!==he?(ge=(0,$.jsx)(R,{open:le,onOpenChange:ue,children:he}),t[145]=R,t[146]=le,t[147]=ue,t[148]=he,t[149]=ge):ge=t[149],ge};function Ud(e){return e.openNewSessionDraft}function Wd(e){return e.currentSessionId}function Gd(e){return e.setPendingInputText}function Kd(e){return e.setPendingSyntheticParts}function qd(e){return e.setActiveMainTab}function Jd(e){return(0,$.jsx)(`li`,{className:`typography-micro text-foreground font-mono truncate block`,title:e,children:e},e)}var Yd=({mergeInProgress:e,rebaseInProgress:t,onContinue:n,onAbort:r,onResolveWithAI:i,hasUnresolvedConflicts:a=!1,isLoading:o=!1})=>{let{t:s}=Xe(),[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`)})]})})},Xd=({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}},Zd=15e3,Qd=40,$d=20,ef={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:`},tf=(e,t)=>{let n=e.toLowerCase(),r=n.match(/^([a-z]+)(?:\(.*\))?!?:/);if(r){let e=ef[r[1]];if(e)return t.find(t=>t.code===e)||null}let i=ef[n.split(` `)[0]];return i&&t.find(e=>e.code===i)||null},nf=20,rf=new Map,af=(e,t)=>{if(rf.delete(e),rf.set(e,t),rf.size>nf){let e=rf.keys().next().value;e!==void 0&&rf.delete(e)}},of=e=>(e||``).replace(/\\/g,`/`).replace(/\/+$/,``),sf=e=>{let t=e.index?.trim();return!!(t&&t!==`?`)},cf=e=>{let t=e.working_dir?.trim(),n=e.index?.trim();return!!(t||n===`?`)},lf=({isActive:e})=>{let{t}=Xe(),{git:n}=fo(),r=Ro(),[i,a]=Q.useState(null),[o,s]=Q.useState(!1),c=Tn(e=>e.currentSessionId),l=Tn(e=>e.newSessionDraft),u=Tn(e=>e.setDraftBootstrapPendingDirectory),d=Tn(e=>e.worktreeMetadata),f=Tn(e=>e.availableWorktrees),m=of(r),h=Q.useMemo(()=>{if(!m)return;let e=f.find(e=>of(e.path)===m);if(e)return e;for(let e of d.values())if(of(e.path)===m)return e},[f,m,d]),g=Q.useMemo(()=>{if(c)return d.get(c)??h;if(l?.open)return h},[c,h,l?.open,d]),_=Xo(r??null),v=Zo(r??null),y=$t(e=>c?e.getAttachment(c):void 0),b=y?Gn(y):[],x=y&&!y.degraded&&!y.legacy?y.worktreeRoot??void 0:void 0,S=md(r,g,v?.current??void 0),C=Jo(r??null),w=Uo(r??null),T=Ko(r??null),E=qo(r??null),{setActiveDirectory:D,fetchAll:O,ensureAll:k,fetchStatus:A,fetchBranches:j,fetchLog:M,setLogMaxCount:N,prefetchDiffs:P,moveStatusPathsOptimistically:F,restoreStatus:I,bumpIndexRevision:L}=Wo(me(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}))),R=p(e=>e.isMobile),z=p(e=>e.openContextFileDiff),B=p(e=>e.navigateToDiff),V=p(e=>e.setRightSidebarOpen),H=Q.useRef(null),U=Q.useRef(null),ee=Q.useRef(null),te=Q.useRef(null),W=Q.useRef(!0);Q.useEffect(()=>()=>{W.current=!1},[]);let ne=Q.useCallback(()=>{U.current!==null&&(window.clearTimeout(U.current),U.current=null)},[]),G=Q.useCallback(e=>{ne(),U.current=window.setTimeout(()=>{U.current=null,of(e)===of(r)&&A(e,n,{silent:!0})},Zd)},[ne,r,A,n]);Q.useEffect(()=>ne,[ne]);let re=Q.useCallback(()=>{ee.current!==null&&(window.clearTimeout(ee.current),ee.current=null)},[]),K=Q.useCallback(()=>{ee.current===null&&(ee.current=window.setTimeout(()=>{ee.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(()=>Xd({runMutation:({directory:e,direction:t,paths:n})=>ie(e,t,n),onMutationComplete:({directory:e})=>{L(e),G(e)},onMutationError:({directory:e,direction:n,rollback:r},i)=>{r?.(),L(e),G(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:K}),[L,ie,K,G,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=Kt(r);n&&a(n.status);let i=nt((e,n)=>{t||of(e)===of(r)&&a(n.status)});return kr(r).then(e=>{if(t)return;Fn(r,e);let n=Kt(r);a(n?.status??e.status)}).catch(()=>{!t&&!Kt(r)&&a(null)}),()=>{t=!0,i()}},[e,r]),Q.useEffect(()=>{let e=H.current;H.current=i,!(!r||!n)&&(e===`pending`&&i===`ready`&&(s(!0),O(r,n).finally(()=>{window.setTimeout(()=>{s(!1)},1200)})),i===`failed`&&(u(null),s(!1)))},[r,O,n,u,i]);let oe=of(l?.bootstrapPendingDirectory??null),se=!!(r&&oe&&oe===of(r)),ce=!!(r&&(i===`pending`||se))||o,le=Q.useMemo(()=>r?rf.get(r)??null:null,[r]),ue=Ut(e=>e.settingsGitmojiEnabled),[de,fe]=Q.useState(null),{gitmojis:pe}=fd(ue);Q.useEffect(()=>{let e=x||S?.projectDirectory;if(!e){fe(null);return}let t=!1;return Fi(e).then(e=>{if(t)return;let n=e.trim();fe(n&&n!==`HEAD`?n:null)}).catch(()=>{t||fe(null)}),()=>{t=!0}},[x,S?.projectDirectory]);let[he,ge]=Q.useState(le?.commitMessage??``),[_e,ve]=Q.useState([]),[ye,be]=Q.useState(!1),xe=ec(v)&&!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}=ed(),[q,Pe]=Q.useState(new Set),[Fe,Ie]=Q.useState(new Set),[Le,Re]=Q.useState(!1),[ze,Be]=Q.useState(!1),[Ve,He]=Q.useState(le?.generatedHighlights??[]),Ue=Fe.size>0||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,qe]=Q.useState(new Set),[Je,Ye]=Q.useState(new Map),[Ze,Qe]=Q.useState(new Set),et=Q.useRef(Je),tt=Q.useRef(Ze),[rt,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,bt]=Q.useState(null),[xt,St]=Q.useState(!1),[Ct,wt]=Q.useState(100),Tt=Q.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Et=Q.useCallback((e,t,n)=>{if(!Tt||typeof window>`u`)return;let r={directory:e,conflictFiles:t,operation:n};window.localStorage.setItem(Tt,JSON.stringify(r))},[Tt]),Dt=Q.useCallback(()=>{!Tt||typeof window>`u`||window.localStorage.removeItem(Tt)},[Tt]);Q.useEffect(()=>{if(!Tt||typeof window>`u`||!r)return;let e=window.localStorage.getItem(Tt);if(e)try{let t=JSON.parse(e);if(t.directory!==r){window.localStorage.removeItem(Tt);return}gt(t.conflictFiles??[]),vt(t.operation??`merge`),mt(!0)}catch{window.localStorage.removeItem(Tt)}},[Tt,r]);let Ot=Q.useCallback(e=>{$e(e).then(e=>{if(e.ok){J.success(t(`gitView.toast.commitHashCopied`));return}J.error(t(`gitView.toast.copyFailed`))})},[t]),kt=Q.useCallback(e=>{qe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);Q.useEffect(()=>{et.current=Je},[Je]),Q.useEffect(()=>{tt.current=Ze},[Ze]),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 Qe(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||(Ye(t=>{let n=new Map(t);for(let{hash:t,files:r}of e)n.set(t,r);return et.current=n,n}),Qe(t=>{let n=new Set(t);for(let{hash:t}of e)n.delete(t);return tt.current=n,n}))}),()=>{t=!0,Qe(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&&af(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 At=Q.useCallback(async()=>{if(!r||!n?.getRemotes){ft([]);return}try{let e=await n.getRemotes(r);W.current&&ft(e)}catch{W.current&&ft([])}},[r,n]);Q.useEffect(()=>{e&&At()},[e,At]),Q.useEffect(()=>{e&&r&&(D(r),k(r,n))},[e,r,D,k,n]),Q.useEffect(()=>{if(e&&r)return yn.onGitRefreshHint(e=>{of(e.directory)===of(r)&&A(r,n)})},[e,r,A,n]);let jt=Q.useCallback(async(e=!0)=>{if(r)try{await Promise.all([A(r,n),j(r,n,{force:!0})])}catch(n){if(e){let e=n instanceof Error?n.message:t(`gitView.toast.refreshRepositoryFailed`);J.error(e)}}},[r,n,A,j,t]),Mt=Q.useCallback(async()=>{r&&await M(r,n,je)},[r,n,M,je]),Nt=Q.useMemo(()=>!v||xe?[]:[...v.files??[]].sort((e,t)=>e.path.localeCompare(t.path)),[v,xe]),Pt=Q.useMemo(()=>Nt.filter(sf),[Nt]),Ft=Q.useMemo(()=>Nt.filter(cf),[Nt]),{deferredStagedCount:It,deferredUnstagedCount:Lt}=Q.useMemo(()=>{if(!xe||!v)return{deferredStagedCount:0,deferredUnstagedCount:0};let e=0,t=0;for(let n of v.files??[])sf(n)&&(e+=1),cf(n)&&(t+=1);return{deferredStagedCount:e,deferredUnstagedCount:t}},[xe,v]);Q.useEffect(()=>{if(!r||Nt.length===0)return;let e=[],t=new Set,i=n=>{!n||t.has(n)||(t.add(n),e.push(n))};if(Pt.forEach(e=>i(e.path)),_e.forEach(i),Nt.slice(0,$d).forEach(e=>i(e.path)),e.length===0)return;let a=window.setTimeout(()=>{P(r,n,e,{maxFiles:Qd})},120);return()=>{window.clearTimeout(a)}},[Nt,r,n,P,Pt,_e]);let Rt=e=>e?.pushed[0]?.remote||v?.tracking?.split(`/`)[0]||Xt.find(e=>e.name===`origin`)?.name||Xt[0]?.name||`origin`,zt=async(e,i)=>{if(r){Ee(e);try{let a=e=>{let t=`${e.name}/`,n=v?.tracking?.startsWith(t)?v.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:Rt(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 jt(!1),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.syncActionFailed`,{action:e===`sync`?t(`gitView.sync.syncChanges`):e===`pull`?t(`gitView.sync.pull`):e});J.error(r)}finally{Ee(null)}}},Bt=async(e={})=>{if(!r)return;if(!he.trim()){J.error(t(`gitView.toast.enterCommitMessage`));return}let i=Pt.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:[]}),L(r),J.success(t(`gitView.toast.commitCreated`)),ge(``),Ge(),await jt(),e.pushAfter){let e=v?.tracking?.split(`/`)[0],i=Xt.find(t=>t.name===e)??Xt[0];if(!i)throw Error(t(`mobile.changes.noRemote`));Ee(`sync`);let a=`${i.name}/`,o=v?.tracking?.startsWith(a)?v.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 jt(!1);return}await n.gitPull(r,{remote:i.name,branch:o,rebase:!0})}let c=await n.getGitStatus(r),l;(c.ahead??0)>0&&(l=await n.gitPush(r)),J.success(t(`gitView.toast.pushedToUpstream`,{name:Rt(l)})),Ne(),await jt(!1)}else await jt(!1);await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.createCommitFailed`);J.error(n)}finally{Ae(null),e.pushAfter&&Ee(null)}},Vt=Q.useCallback(async()=>{if(!r)return;let e=Pt.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 Tr(r,e),n=t.subject?.trim()??``,i=Array.isArray(t.highlights)?t.highlights:[];if(n){let e=n;if(ue&&pe.length>0){let t=tf(n,pe);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,Pt,ue,pe,We,t]),Ht=e=>e.reason===`attention`?`${e.attentionReason} in progress`:e.reason===`missing`?`worktree is missing`:`worktree is invalid`,Wt=async(e,i)=>{if(!r||!v)return;let a=Wn(y);if(a.length>0){J.error(t(`gitView.toast.cannotCreateBranch`,{reason:Ht(a[0])}));return}let o=v.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 jt(),await Mt(),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}},Gt=async(e,i)=>{if(!r)return;let a=Wn(y);if(a.length>0){J.error(t(`gitView.toast.cannotRenameBranch`,{reason:Ht(a[0])}));return}try{await n.renameBranch(r,e,i),J.success(t(`gitView.toast.renamedBranch`,{oldName:e,newName:i})),await jt(),await Mt()}catch(n){let r=n instanceof Error?n.message:t(`gitView.toast.renameBranchFailed`,{oldName:e,newName:i});J.error(r)}},qt=async e=>{if(!r)return;let i=Wn(y);if(i.length>0){J.error(t(`gitView.toast.cannotCheckout`,{reason:Ht(i[0])}));return}let a=e.replace(/^remotes\//,``);if(v?.current!==a)try{await n.checkoutBranch(r,a),J.success(t(`gitView.toast.checkedOut`,{name:a})),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.checkoutFailed`,{name:a});J.error(n)}},Jt=Q.useMemo(()=>C?.all?C.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[C]),Yt=Q.useMemo(()=>C?.all?C.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[C]),Xt=Q.useMemo(()=>{if(dt.length>0)return dt;let e=new Set,t=v?.tracking?.trim();t&&t.includes(`/`)&&e.add(t.split(`/`)[0]);for(let t of Yt){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,Yt,at,v?.tracking]),Zt=Q.useMemo(()=>{let e=new Set(Xt.map(e=>e.name)),t=t=>{if(!t)return``;let n=t.trim();if(!n||n===`HEAD`)return``;if(Jt.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 S?.createdFromBranch==`string`?S.createdFromBranch:``)||t(typeof de==`string`?de:``)||(Jt.includes(`main`)?`main`:Jt.includes(`master`)?`master`:Jt.includes(`develop`)?`develop`:`main`)},[Xt,Jt,de,S?.createdFromBranch]),Qt=Pt.length,en=v?.current??null;Q.useEffect(()=>{if(!r||!n||!w?.all?.length||!en||!Zt||en===Zt){it(null);return}let e=!1;return(async()=>{try{let t=await n.getGitLog(r,{from:Zt,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=w.all.findIndex(e=>!i.has(e.hash));if(a===0){it(null);return}if(a===-1){it({insertBeforeIndex:w.all.length,branchName:en,direction:`up`});return}it({insertBeforeIndex:a,branchName:en,direction:`up`})}catch{e||it(null)}})(),()=>{e=!0}},[Zt,en,r,n,w,je]),Q.useEffect(()=>{bt(null)},[r]),Q.useEffect(()=>{if(lt!==`graph`||!r){lt!==`graph`&&bt(null);return}let e=!1;return St(!0),n.getGitLog(r,{maxCount:Ct,all:!0}).then(t=>{e||bt(t)}).catch(e=>{console.error(`Failed to fetch graph log:`,e)}).finally(()=>{e||St(!1)}),()=>{e=!0}},[lt,r,Ct,n]);let tn=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=F(r,n,t);ae.enqueue({directory:r,direction:t,paths:new Set(n),rollback:()=>I(r,i)}),K()},[r,ae,F,I,K]),nn=Q.useCallback(async e=>{if(r){Pe(t=>{let n=new Set(t);return n.add(e),n});try{await n.revertGitFile(r,e,{scope:`working`}),J.success(t(`gitView.toast.revertedFile`,{path:e})),await jt(!1)}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.revertFailed`);J.error(n)}finally{Pe(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,jt,n,t]),rn=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=>q.has(e)))return;let s=new Set(Pt.map(e=>e.path)),c=a===`all`&&o.some(e=>s.has(e));i&&Re(!0),Pe(e=>{let t=new Set(e);return o.forEach(e=>t.add(e)),t});let l=[];try{if(await Promise.all(o.map(async e=>{try{await n.revertGitFile(r,e,{scope:a})}catch(n){l.push({path:e,message:n instanceof Error?n.message:t(`gitView.toast.revertFailed`)})}})),c&&l.length<o.length&&L(r),await jt(!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{Pe(e=>{let t=new Set(e);return o.forEach(e=>t.delete(e)),t}),i&&Re(!1)}},[L,r,n,Le,jt,q,Pt,t]),an=Q.useCallback(async e=>{await rn(e,!0)},[rn]),on=Q.useCallback(async e=>{await rn(e,!1,`working`)},[rn]),sn=Q.useCallback((e,t)=>{if(r&&!R){z(r,e,t);return}B(e,t),R&&V(!1)},[r,R,B,z,V]),cn=Q.useCallback(()=>Oe(!0),[]),ln=Q.useMemo(()=>{let e=[];return Pt.length>0&&e.push({id:`staged`,title:t(`gitView.changes.stagedTitle`),entries:Pt,actionSymbol:`-`,actionAllLabel:t(`gitView.changes.unstageAllAria`),getActionLabel:e=>t(`gitView.changes.unstageFileAria`,{path:e}),onActionFile:e=>void tn([e],`unstage`),onActionAll:e=>void tn(e,`unstage`),onViewDiff:e=>sn(e,!0),onRevertFile:nn,showRevertActions:!1,accent:!0}),Ft.length>0&&e.push({id:`unstaged`,title:t(`gitView.changes.title`),entries:Ft,actionSymbol:`+`,actionAllLabel:t(`gitView.changes.stageAllAria`),getActionLabel:e=>t(`gitView.changes.stageFileAria`,{path:e}),onActionFile:e=>void tn([e],`stage`),onActionAll:e=>void tn(e,`stage`),onViewDiff:e=>sn(e,!1),onRevertFile:nn}),e},[nn,sn,tn,Pt,t,Ft]),un=Q.useCallback(e=>{if(e.length===0)return;let t=e.map(e=>e.trim()).filter(Boolean);if(t.length===0){Ge();return}ge(e=>{let n=e.trim();return`${n}${n.length>0?`
|
|
4
4
|
|
|
5
5
|
`:``}${t.join(`
|
|
6
|
-
`)}`.trim()}),Ge()},[Ge]),dn=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)},[]),fn=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`))),Ot(),await Mt(),await Nt()}catch(e){let t=e instanceof Error?e.message:`Failed to abort ${_t}`;J.error(t)}},[r,n,_t,Mt,Nt,Ot,t]),pn=Q.useMemo(()=>v?.files?v.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,[v?.files]),mn=Q.useCallback(async()=>{if(r)try{let e=!!v?.mergeInProgress?.head,i=!!(v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto);if(e){let e=await n.continueMerge(r);e.conflict?(gt(e.conflictFiles??[]),vt(`merge`),mt(!0),Dt(r,e.conflictFiles??[],`merge`),J.error(t(`gitView.toast.mergeConflictsDetected`))):(Ot(),J.success(t(`gitView.toast.mergeCompleted`)),await Mt(),await Nt())}else if(i){let e=await n.continueRebase(r);e.conflict?(gt(e.conflictFiles??[]),vt(`rebase`),mt(!0),Dt(r,e.conflictFiles??[],`rebase`),J.error(t(`gitView.toast.rebaseConflictsDetected`))):(Ot(),J.success(t(`gitView.toast.rebaseStepCompleted`)),await Mt(),await Nt())}}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.continueOperationFailed`);J.error(n)}},[r,n,v,Mt,Nt,Dt,Ot,t]),hn=Q.useCallback(async()=>{if(r)try{v?.mergeInProgress?.head?(await n.abortMerge(r),J.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),J.success(t(`gitView.toast.rebaseAborted`))),Ot(),await Mt(),await Nt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.abortOperationFailed`);J.error(n)}},[r,n,v,Mt,Nt,Ot,t]),gn=Q.useCallback(()=>{if(!r)return;let e=v?.mergeInProgress?.head?`merge`:`rebase`,t=v?.files?.filter(e=>e.index===`U`||e.working_dir===`U`).map(e=>e.path)??[];t.length>0&>(t),vt(e),mt(!0)},[r,v]),_n=Q.useCallback(e=>{Me(e),r&&(N(r,e),M(r,n,e))},[r,M,n,N]),vn=Q.useCallback(e=>{Tt(e)},[]),bn=Q.useCallback(()=>{ut(null),r&&(A(r,n),j(r,n,{force:!0}),M(r,n,je))},[r,A,j,M,je,n]),xn=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&&(A(r,n),j(r,n,{force:!0}),M(r,n,je));return}gt(e.conflictFiles??[]),vt(e.operation),mt(!0),r&&Dt(r,e.conflictFiles??[],e.operation)}},[t,gt,vt,mt,Dt,r,A,j,M,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(_===null||_===!0&&!v)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(_===!1)return ce?(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`)}),b.includes(`open-without-worktree-features`)?(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:t(`gitView.empty.worktreeFeaturesUnavailable`)}):null]});let Sn=v?(0,$.jsxs)($.Fragment,{children:[S?(0,$.jsx)(Zs,{currentBranch:v.current,onRename:Gt,iconOnly:!0}):(0,$.jsx)(Wa,{currentBranch:v.current,localBranches:Jt,remoteBranches:Yt,branchInfo:C?.branches,onCheckout:Kt,onCreate:Wt,remotes:Xt,iconOnly:!0}),(0,$.jsx)(lc,{syncAction:Te,remotes:Xt,onSync:e=>Bt(`sync`,e),disabled:!v,aheadCount:v.ahead,behindCount:v.behind,trackingRemoteName:v.tracking?.split(`/`)[0],hasUncommittedChanges:(v.files?.length??0)>0}),(0,$.jsxs)(ea,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{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)(Bi,{sideOffset:8,children:t(`gitView.header.repositoryViews`)})]}),(0,$.jsxs)($i,{align:`end`,children:[(0,$.jsxs)(ca,{onSelect:()=>ut(`history`),children:[(0,$.jsx)(X,{name:`history`,className:`size-4`}),t(`gitView.history.title`)]}),(0,$.jsxs)(ca,{onSelect:()=>ut(`graph`),children:[(0,$.jsx)(X,{name:`git-merge`,className:`size-4`}),t(`gitView.graph.title`)]}),(0,$.jsxs)(ca,{onSelect:cn,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`size-4`}),t(`gitView.stashes.title`)]})]})]})]}):null;return(0,$.jsxs)(`div`,{className:Y(`flex h-full flex-col overflow-hidden`),children:[r&&(v?.mergeInProgress?.head||v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto)&&(0,$.jsx)(Jd,{mergeInProgress:v?.mergeInProgress,rebaseInProgress:v?.rebaseInProgress,onContinue:mn,onAbort:hn,onResolveWithAI:gn,hasUnresolvedConflicts:pn,isLoading:T}),(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)(bi,{as:ki,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:v?.files?.length??0})}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Sn})]}),(0,$.jsx)(Ys,{stagedCount:Lt,unstagedCount:Rt,onLoad:()=>be(!0)})]}):(Pt?.length??0)>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,$.jsx)(ac,{groups:ln,diffStats:v?.diffStats,revertingPaths:q,isRevertingAll:Le,onVisiblePathsChange:ve,onRevertAll:an,onRevertDirectory:on,headerBackgroundClassName:`bg-background`,headerActions:Sn})}),(0,$.jsx)(sc,{stagedCount:Qt,commitMessage:he,onCommitMessageChange:ge,generatedHighlights:Ve,onInsertHighlights:un,onGenerateMessage:Ht,isGeneratingMessage:ze,onCommit:()=>Vt({pushAfter:!1}),onCommitAndPush:()=>Vt({pushAfter:!0}),commitAction:ke,hasPendingIndexMutation:Ue,gitmojiEnabled:ue,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:Sn})]}),(0,$.jsx)(_d,{onOpenStashes:()=>Oe(!0)})]})})})})})}),(0,$.jsx)(cr,{open:lt!==null,onOpenChange:e=>{e||ut(null)},children:(0,$.jsxs)(ar,{className:`max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(or,{children:t(lt===`graph`?`gitView.graph.title`:`gitView.history.title`)}),(0,$.jsx)(sr,{children:t(`gitView.history.dialogDescription`)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,$.jsx)(Id,{mode:lt===`graph`?`graph`:`history`,log:lt===`graph`?yt??w:w,isLogLoading:lt===`graph`&&xt||E,logMaxCount:lt===`graph`?Ct:je,onLogMaxCountChange:lt===`graph`?vn:_n,expandedCommitHashes:Ke,onToggleCommit:At,commitFilesMap:Je,loadingCommitHashes:Ze,onCopyHash:kt,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:`h-full max-h-none`,branchDivider:lt===`graph`?null:rt,onConflict:lt===`graph`?xn:void 0,onActionSuccess:lt===`graph`?bn:void 0})})]})}),(0,$.jsx)(hd,{open:De,onOpenChange:Oe,directory:r,hasUncommittedChanges:(v?.files?.length??0)>0,hasStagedChanges:Ft.length>0,uncommittedFileCount:v?.files?.length??0,onChanged:async e=>{r&&e?.affectsIndex&&L(r),await Mt(!1),await Nt()}}),(0,$.jsx)(cr,{open:Se,onOpenChange:Ce,children:(0,$.jsxs)(ar,{className:`max-w-md p-0 overflow-hidden`,children:[(0,$.jsx)(rr,{className:`px-4 pt-4`,children:(0,$.jsx)(or,{children:t(`gitView.gitmoji.title`)})}),(0,$.jsxs)(so,{className:`h-[420px]`,children:[(0,$.jsx)(oo,{placeholder:t(`gitView.gitmoji.searchPlaceholder`),value:st,onValueChange:ct}),(0,$.jsxs)(Aa,{children:[(0,$.jsx)(Ra,{children:t(`gitView.gitmoji.empty`)}),(0,$.jsx)(Oa,{children:(pe.length===0?[]:pe.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)(za,{onSelect:()=>dn(e.emoji,e.code),children:[(0,$.jsx)(`span`,{className:`text-lg`,children:e.emoji}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.code}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:e.description})]},e.code))})]})]})]})}),r&&(0,$.jsx)(Vd,{open:pt,onOpenChange:mt,conflictFiles:ht,directory:r,operation:_t,onAbort:fn,onClearState:Ot})]})},lf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),uf=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},df=(e,t)=>{let n=uf(t),r=uf(e).replace(/\/+$/,``);return n===r?`.`:!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},ff=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),pf=new Set([`node_modules`]),mf=e=>pf.has(e),hf=e=>{let t=uf(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},gf=8,_f=new Map,vf=e=>{let t=_f.get(e);return t?(t.touchedAt=Date.now(),_f.delete(e),_f.set(e,t),t):null},yf=e=>{let t=_f.get(e);if(t)return t.touchedAt=Date.now(),t;if(_f.size>=gf){let e=_f.keys().next().value;e!==void 0&&_f.delete(e)}let n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return _f.set(e,n),n},bf=e=>{_f.delete(e)},xf=(e,t)=>(0,$.jsx)(Ba,{filePath:e,extension:t,className:`size-3.5`}),Sf=e=>{let t=(0,Rc.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},Cf=Q.memo(e=>{let t=(0,Rc.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}=Xe(),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(),$e(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(Yn())]}),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=df(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`,L;t[29]===I?L=t[30]:(L=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]=L);let R;t[31]!==h||t[32]!==i||t[33]!==n.extension||t[34]!==n.path?(R=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`}):xf(n.path,n.extension),t[31]=h,t[32]=i,t[33]=n.extension,t[34]=n.path,t[35]=R):R=t[35];let z;t[36]!==n.name||t[37]!==n.path?(z=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,title:n.path,children:n.name}),t[36]=n.name,t[37]=n.path,t[38]=z):z=t[38];let B;t[39]!==h||t[40]!==o?(B=!h&&o&&(0,$.jsx)(Sf,{status:o}),t[39]=h,t[40]=o,t[41]=B):B=t[41];let V;t[42]!==s||t[43]!==h?(V=h&&s&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[s.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,s.modified]}),s.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,s.added]})]}),t[42]=s,t[43]=h,t[44]=V):V=t[44];let H;t[45]!==E||t[46]!==P||t[47]!==O||t[48]!==z||t[49]!==B||t[50]!==V||t[51]!==L||t[52]!==R?(H=(0,$.jsxs)(`button`,{type:`button`,onClick:O,onContextMenu:E,draggable:!0,onDragStart:P,className:L,children:[R,z,B,V]}),t[45]=E,t[46]=P,t[47]=O,t[48]=z,t[49]=B,t[50]=V,t[51]=L,t[52]=R,t[53]=H):H=t[53];let U;t[54]!==_||t[55]!==v||t[56]!==y||t[57]!==g||t[58]!==b||t[59]!==x||t[60]!==M||t[61]!==m?(U=(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)(ea,{open:x,onOpenChange:S,children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(sa,{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)(Bi,{side:`bottom`,sideOffset:6,children:m(`sidebarFilesTree.actions.fileMenuTitle`)})]}),(0,$.jsx)($i,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>S(!1),children:M({Item:ca,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]=U):U=t[62];let ee;t[63]!==H||t[64]!==U||t[65]!==F?(ee=(0,$.jsxs)(fc,{render:F,children:[H,U]}),t[63]=H,t[64]=U,t[65]=F,t[66]=ee):ee=t[66];let te;t[67]===M?te=t[68]:(te=(0,$.jsx)(mc,{className:`min-w-[180px]`,children:M({Item:hc,Separator:pc})}),t[67]=M,t[68]=te);let W;return t[69]!==C||t[70]!==ee||t[71]!==te?(W=(0,$.jsxs)(gc,{open:C,onOpenChange:w,children:[ee,te]}),t[69]=C,t[70]=ee,t[71]=te,t[72]=W):W=t[72],W},(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),wf=()=>{let{t:e}=Xe(),{files:t}=uo(),n=Lo()??``,r=uf(n.trim()),i=B(),a=x(),o=Ae(e=>e.searchFiles),s=p(e=>e.openContextFile),c=Xo(n),[l,u]=Q.useState(``),d=Bo(l,200),f=Q.useRef(null),[m,h]=Q.useState([]),[g,_]=Q.useState(!1),[v,y]=Q.useState({}),[b,S]=Q.useState({}),C=Q.useRef(new Set),w=Q.useRef(new Set),T=Q.useRef(null);Q.useEffect(()=>{if(!r){y({}),S({}),C.current=new Set;return}let e=vf(r);e?(y({...e.childrenByDir}),S({...e.loadErrorsByDir}),C.current=new Set(e.loadedDirs)):(y({}),S({}),C.current=new Set)},[r]),Q.useEffect(()=>{if(!r)return;let e=yf(r);e.childrenByDir=v},[r,v]),Q.useEffect(()=>{if(!r)return;let e=yf(r);e.loadErrorsByDir=b},[r,b]),Q.useEffect(()=>{if(!r)return;let e=yf(r);e.loadedDirs=new Set(C.current)},[r,v,b]),Q.useEffect(()=>()=>{if(!r)return;let e=_f.get(r);e&&e.loadedDirs.size===0&&Object.keys(e.childrenByDir).length===0&&bf(r)},[r]);let E=Q.useMemo(()=>[],[]),D=Q.useMemo(()=>[],[]),O=Vo(e=>r?e.byRoot[r]?.expandedPaths??E:E),k=Vo(e=>r?e.byRoot[r]?.selectedPath??null:null),A=Vo(e=>e.setSelectedPath),j=Vo(e=>e.addOpenPath),M=Vo(e=>e.removeOpenPathsByPrefix),N=Vo(e=>e.removeExpandedPathsByPrefix),P=Vo(e=>e.toggleExpandedPath),F=Vo(e=>e.expandPaths),I=p(e=>r?e.contextPanelByDirectory[r]?.tabs??D:D),L=Q.useMemo(()=>new Set(I.map(e=>e.mode===`file`?e.targetPath:null).filter(e=>typeof e==`string`&&e.length>0).map(e=>uf(e))),[I]),[R,z]=Q.useState(null),[V,H]=Q.useState(null),[U,ee]=Q.useState(``),[te,W]=Q.useState(!1),ne=!!t.writeFile,G=!!t.createDirectory,re=!!t.rename,K=!!t.delete,ie=!!t.revealPath,ae=Q.useMemo(()=>({canRename:re,canCreateFile:ne,canCreateFolder:G,canDelete:K,canReveal:ie}),[re,ne,G,K,ie]),oe=Q.useCallback(n=>{t.revealPath&&t.revealPath(n).catch(()=>{J.error(e(`sidebarFilesTree.toast.revealFailed`))})},[t,e]),se=Q.useCallback((e,t)=>{z(e),H(t),ee(e===`rename`&&t.name||``),W(!1)},[]),ce=Q.useCallback((e,t)=>lf(t.filter(e=>e&&typeof e.name==`string`&&e.name.length>0).filter(e=>i||!e.name.startsWith(`.`)).filter(e=>a||!mf(e.name)).map(t=>{let n=t.name,r=uf(t.path||``),i=r?ff(r)?r:uf(`${e}/${r}`):uf(`${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]),le=Q.useCallback(async(e,n)=>{let r=uf(e.trim());if(!r||C.current.has(r)||w.current.has(r))return;w.current=new Set(w.current),w.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}))):Ne.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=ce(r,e);C.current=new Set(C.current),C.current.add(r),S(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),S(e=>({...e,[r]:t}))}finally{w.current=new Set(w.current),w.current.delete(r)}},[t,ce]),ue=Q.useCallback(async()=>{if(!r)return;T.current?.abort();let e=new AbortController;T.current=e;try{let t=(Vo.getState().byRoot[r]?.expandedPaths??[]).map(e=>uf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)),n=[r,...t];C.current=new Set(C.current);for(let e of n)C.current.delete(e);S(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 le(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=>le(e,i)))}}catch(t){if(e.signal.aborted)return;console.error(`Failed to refresh sidebar tree:`,t)}finally{T.current===e&&(T.current=null)}},[le,r]),de=Q.useCallback(async e=>{if(!e){await ue();return}let t=uf(e);C.current=new Set(C.current),C.current.delete(t),w.current=new Set(w.current),w.current.delete(t),await le(t)},[le,ue]);Q.useEffect(()=>{r&&(T.current?.abort(),C.current=new Set,w.current=new Set,S({}),y(e=>Object.keys(e).length===0?e:{}),le(r))},[le,r,i,a]),Q.useEffect(()=>{if(!r||O.length===0)return;let e=O.map(e=>uf(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)&&!C.current.has(e)&&!w.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=>le(e,n)))}})(),()=>{t=!0}},[O,le,r]),Q.useEffect(()=>{if(!n){h([]),_(!1);return}let e=d.trim();if(!e){h([]),_(!1);return}let t=!1;return _(!0),o(n,e,150,{includeHidden:i,respectGitignore:!a,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>a||!hf(e.path)).map(e=>({name:e.name,path:uf(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));h(n)}).catch(()=>{t||h([])}).finally(()=>{t||_(!1)}),()=>{t=!0}},[n,d,o,i,a]);let fe=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]),pe=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]),me=Q.useCallback(e=>{if(L.has(e))return`open`;if(fe.size===0)return null;let t=e.startsWith(r+`/`)?e.slice(r.length+1):e;return fe.get(t)??null},[L,fe,r]),he=Q.useCallback(e=>{if(pe.size===0)return null;let t=pe.get(e);return t&&t.modified+t.added>0?t:null},[pe]),ge=Q.useCallback(async e=>{if(!r)return;let n=await tc(t,e.path);if(!n.ok){J.error(Ws(n.reason));return}A(r,e.path),j(r,e.path),s(r,e.path)},[j,t,s,r,A]),_e=Q.useCallback(async e=>{let t=uf(e);r&&(P(r,t),C.current.has(t)||await le(t))},[le,r,P]),ve=Q.useMemo(()=>Array.from(new Set(Object.values(v).flatMap(e=>e.filter(e=>e.type===`directory`).map(e=>e.path)))),[v]),ye=Q.useMemo(()=>new Set(O.map(e=>uf(e))),[O]),be=ve.length>0&&ve.every(e=>ye.has(uf(e))),xe=Q.useCallback(()=>{if(r){if(be){N(r,r);return}F(r,ve)}},[be,ve,F,N,r]),Se=Q.useCallback(async n=>{if(n?.preventDefault(),!V||!R)return;W(!0);let i=()=>W(!1),a=()=>z(null);if(R===`createFile`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.filenameRequired`)),i();return}if(!t.writeFile){J.error(e(`sidebarFilesTree.toast.writeNotSupported`)),i();return}let n=V.path,r=uf(`${n?`${n}/`:``}${U.trim()}`);await t.writeFile(r,``).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.fileCreated`)),await de(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`createFolder`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.folderNameRequired`)),i();return}let n=V.path,r=uf(`${n?`${n}/`:``}${U.trim()}`);await t.createDirectory(r).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.folderCreated`)),await de(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`rename`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.nameRequired`)),i();return}if(!t.rename){J.error(e(`sidebarFilesTree.toast.renameNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`),s=uf(`${o?`${o}/`:``}${U.trim()}`);await t.rename(n,s).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.renamedSuccessfully`)),await de(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=V.path,o=n.split(`/`).slice(0,-1).join(`/`);await t.delete(n).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.deletedSuccessfully`)),await de(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,V,U,t,de,M,r,k,A,e]);function Ce(n,i){return(v[n]??[]).map(n=>{let a=n.type===`directory`,o=a&&ye.has(uf(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)(Cf,{node:n,root:r,isExpanded:o,isActive:s,status:a?void 0:me(n.path),badge:a?he(n.path):void 0,permissions:ae,downloadFile:t.downloadFile,onSelect:ge,onToggle:_e,onRevealPath:oe,onOpenDialog:se}),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 de(n.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):null,Ce(n.path,i+1)]})]},n.path)})}let we=!!(r&&v[r]),Te=r?b[r]:null,Ee=e(be?`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)(Ri,{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:[ne&&(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>se(`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)(Bi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFileTitle`)})]}),G&&(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>se(`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)(Bi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>void ue(),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)(Bi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.refreshTitle`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:xe,disabled:ve.length===0&&O.length===0,className:`w-6 flex-shrink-0 p-0`,title:Ee,"aria-label":Ee,children:(0,$.jsx)(X,{name:be?`contract-up-down`:`expand-up-down`,className:`size-3.5`})})}),(0,$.jsx)(Bi,{side:`bottom`,sideOffset:6,children:Ee})]})]})]}),(0,$.jsx)(bi,{outerClassName:`flex-1 min-h-0`,className:`p-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:g?(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`)]}):m.length>0?m.map(e=>{let t=k===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ge(e),draggable:!0,onDragStart:t=>{let n=e.relativePath||df(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:[xf(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)}):Te?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:Te}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void ue(),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):we&&r?Ce(r,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-code text-muted-foreground`,children:e(`sidebarFilesTree.state.loading`)})})}),(0,$.jsx)(cr,{open:!!R,onOpenChange:e=>!e&&z(null),children:(0,$.jsxs)(ar,{children:[(0,$.jsxs)(rr,{children:[(0,$.jsxs)(or,{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)(sr,{children:[R===`createFile`&&e(`sidebarFilesTree.dialog.createFile.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`rename`&&e(`sidebarFilesTree.dialog.rename.description`,{name:V?.name??``}),R===`delete`&&e(`sidebarFilesTree.dialog.delete.description`,{name:V?.name??``})]})]}),R!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Ri,{value:U,onChange:e=>ee(e.target.value),placeholder:e(R===`rename`?`sidebarFilesTree.dialog.rename.placeholder`:`sidebarFilesTree.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&Se()},autoFocus:!0})}),(0,$.jsxs)(ir,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>z(null),disabled:te,children:e(`sidebarFilesTree.dialog.cancel`)}),(0,$.jsx)(Z,{variant:R===`delete`?`destructive`:`default`,onClick:()=>void Se(),disabled:te||R!==`delete`&&!U.trim(),children:te?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):e(R===`delete`?`sidebarFilesTree.dialog.delete.confirm`:`sidebarFilesTree.dialog.confirm`)})]})]})})]})},Tf=e=>e===`git`||e===`files`||e===`context`,Ef=`files`,Df=()=>!(typeof document<`u`&&document.hidden||typeof navigator<`u`&&!navigator.onLine);function Of(e,t,n,r){let i=(0,Rc.c)(6),{git:a}=uo(),o=Uo(kf),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(()=>{Df()&&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 kf(e){return e.ensureStatus}var Af=()=>{let e=(0,Rc.c)(15),t=xn(Mf),n=xn(Nf),r=Uo(Pf),i;bb0:{if(t){let r;e[0]!==t||e[1]!==n?(r=n.find(e=>e.id===t)??n[0]??null,e[0]=t,e[1]=n,e[2]=r):r=e[2],i=r;break bb0}i=n[0]??null}let a=i,o;bb1:{if(!a){o=null;break bb1}let t;e[3]!==a.id||e[4]!==a.path?(t={id:a.id,path:a.path},e[3]=a.id,e[4]=a.path,e[5]=t):t=e[5],o=t}let s=o,c;bb2:{if(!a){c=null;break bb2}let t;e[6]===a.path?t=e[7]:(t=Qn(a.path)||a.path,e[6]=a.path,e[7]=t),c=t}let l=c,u;bb3:{if(!a){u=!1;break bb3}let t;e[8]!==a.path||e[9]!==r?(t=r.get(a.path)?.isGitRepo,e[8]=a.path,e[9]=r,e[10]=t):t=e[10],u=t===!0}let d=u,f;return e[11]!==d||e[12]!==l||e[13]!==s?(f=(0,$.jsx)(`div`,{className:`h-full min-h-0 overflow-auto bg-background`,children:(0,$.jsx)(Hu,{projectRef:s,projectLabel:l,canCreateWorktree:d})}),e[11]=d,e[12]=l,e[13]=s,e[14]=f):f=e[14],f},jf=()=>{let e=(0,Rc.c)(57),{t}=Xe(),n=p(Ff),r=p(If),i=p(Lf),a=p(Rf);Of(Lo(),i,n,a);let o=a===`git`?`git`:a===`context`?`context`:null,s,c;e[0]!==o||e[1]!==n||e[2]!==r?(s=()=>{o&&n===o&&r(Ef)},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 m;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(X,{name:`folder-3`,className:`h-3.5 w-3.5`}),e[12]=m):m=e[12];let h;e[13]===f?h=e[14]:(h={id:`files`,label:f,icon:m},e[13]=f,e[14]=h);let g;e[15]===t?g=e[16]:(g=t(`layout.rightSidebar.context`),e[15]=t,e[16]=g);let _;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(X,{name:`file-list-2`,className:`h-3.5 w-3.5`}),e[17]=_):_=e[17];let v;e[18]===g?v=e[19]:(v={id:`context`,label:g,icon:_},e[18]=g,e[19]=v);let y;e[20]!==v||e[21]!==d||e[22]!==h?(y=[d,h,v],e[20]=v,e[21]=d,e[22]=h,e[23]=y):y=e[23];let b=y,x;e[24]!==o||e[25]!==b?(x=o?b.filter(e=>e.id!==o):b,e[24]=o,e[25]=b,e[26]=x):x=e[26];let S=x,C=i&&n===`git`&&o!==`git`,w;e[27]===r?w=e[28]:(w=e=>{Tf(e)&&r(e)},e[27]=r,e[28]=w);let T=w,E;e[29]!==T||e[30]!==n||e[31]!==S?(E=(0,$.jsx)(`div`,{className:`h-9 bg-background pt-1 px-2`,children:(0,$.jsx)(Qo,{items:S,activeId:n,onSelect:T,layoutMode:`fit`,variant:`active-pill`,activePillLowercase:!1,className:`h-full`})}),e[29]=T,e[30]=n,e[31]=S,e[32]=E):E=e[32];let D=n!==`git`&&`hidden`,O;e[33]===D?O=e[34]:(O=Y(`h-full`,D),e[33]=D,e[34]=O);let k;e[35]===C?k=e[36]:(k=(0,$.jsx)(cf,{isActive:C}),e[35]=C,e[36]=k);let A;e[37]!==O||e[38]!==k?(A=(0,$.jsx)(`div`,{className:O,children:k}),e[37]=O,e[38]=k,e[39]=A):A=e[39];let j=n!==`files`&&`hidden`,M;e[40]===j?M=e[41]:(M=Y(`h-full`,j),e[40]=j,e[41]=M);let N;e[42]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(wf,{}),e[42]=N):N=e[42];let P;e[43]===M?P=e[44]:(P=(0,$.jsx)(`div`,{className:M,children:N}),e[43]=M,e[44]=P);let F=n!==`context`&&`hidden`,I;e[45]===F?I=e[46]:(I=Y(`h-full`,F),e[45]=F,e[46]=I);let L;e[47]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(Af,{}),e[47]=L):L=e[47];let R;e[48]===I?R=e[49]:(R=(0,$.jsx)(`div`,{className:I,children:L}),e[48]=I,e[49]=R);let z;e[50]!==A||e[51]!==P||e[52]!==R?(z=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[A,P,R]}),e[50]=A,e[51]=P,e[52]=R,e[53]=z):z=e[53];let B;return e[54]!==E||e[55]!==z?(B=(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[E,z]}),e[54]=E,e[55]=z,e[56]=B):B=e[56],B};function Mf(e){return e.activeProjectId}function Nf(e){return e.projects}function Pf(e){return e.directories}function Ff(e){return e.rightSidebarTab}function If(e){return e.setRightSidebarTab}function Lf(e){return e.isRightSidebarOpen}function Rf(e){return e.activeMainTab}var zf=(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)},Bf=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Vf=(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:We.cursor(a),effects:Ue.scrollIntoView(a,{y:`center`})})};function Hf({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=Xe(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>zf(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Bf(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:Ue.scrollIntoView(e.main.from,{y:`center`})});return}Vf(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:Ue.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,Vf(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??Bf(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)(Ri,{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)(Ri,{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 Uf=go(()=>Fe(()=>import(`./ToolOutputDialog-DLG1iThm.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]))),Wf=e=>{let t=qf(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},Gf=e=>{let t=(0,Rc.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},Kf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),qf=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},Jf=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Yf=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,Xf=(e,t)=>{let n=qf(t),r=qf(e);if(!n||!r)return!1;let i=Yf(n),a=Yf(r);return a===i||a.startsWith(`${i}/`)},Zf=(e,t)=>{let n=qf(t),r=qf(e);if(!Xf(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},Qf=(e,t)=>{if(!t)return``;let n=qf(t);if(!e||!Xf(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},$f=new Set([`node_modules`]),ep=e=>{let t=(0,Rc.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},tp=e=>{let t=(0,Rc.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},np=e=>$f.has(e),rp=e=>{let t=qf(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},ip=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},ap=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`)},op=2e5,sp=`openchamber:files:auto-save-enabled`,cp=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
|
|
6
|
+
`)}`.trim()}),Ge()},[Ge]),dn=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)},[]),fn=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`))),Dt(),await jt(),await Mt()}catch(e){let t=e instanceof Error?e.message:`Failed to abort ${_t}`;J.error(t)}},[r,n,_t,jt,Mt,Dt,t]),pn=Q.useMemo(()=>v?.files?v.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,[v?.files]),mn=Q.useCallback(async()=>{if(r)try{let e=!!v?.mergeInProgress?.head,i=!!(v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto);if(e){let e=await n.continueMerge(r);e.conflict?(gt(e.conflictFiles??[]),vt(`merge`),mt(!0),Et(r,e.conflictFiles??[],`merge`),J.error(t(`gitView.toast.mergeConflictsDetected`))):(Dt(),J.success(t(`gitView.toast.mergeCompleted`)),await jt(),await Mt())}else if(i){let e=await n.continueRebase(r);e.conflict?(gt(e.conflictFiles??[]),vt(`rebase`),mt(!0),Et(r,e.conflictFiles??[],`rebase`),J.error(t(`gitView.toast.rebaseConflictsDetected`))):(Dt(),J.success(t(`gitView.toast.rebaseStepCompleted`)),await jt(),await Mt())}}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.continueOperationFailed`);J.error(n)}},[r,n,v,jt,Mt,Et,Dt,t]),hn=Q.useCallback(async()=>{if(r)try{v?.mergeInProgress?.head?(await n.abortMerge(r),J.success(t(`gitView.toast.mergeAborted`))):(await n.abortRebase(r),J.success(t(`gitView.toast.rebaseAborted`))),Dt(),await jt(),await Mt()}catch(e){let n=e instanceof Error?e.message:t(`gitView.toast.abortOperationFailed`);J.error(n)}},[r,n,v,jt,Mt,Dt,t]),gn=Q.useCallback(()=>{if(!r)return;let e=v?.mergeInProgress?.head?`merge`:`rebase`,t=v?.files?.filter(e=>e.index===`U`||e.working_dir===`U`).map(e=>e.path)??[];t.length>0&>(t),vt(e),mt(!0)},[r,v]),_n=Q.useCallback(e=>{Me(e),r&&(N(r,e),M(r,n,e))},[r,M,n,N]),vn=Q.useCallback(e=>{wt(e)},[]),bn=Q.useCallback(()=>{ut(null),r&&(A(r,n),j(r,n,{force:!0}),M(r,n,je))},[r,A,j,M,je,n]),xn=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&&(A(r,n),j(r,n,{force:!0}),M(r,n,je));return}gt(e.conflictFiles??[]),vt(e.operation),mt(!0),r&&Et(r,e.conflictFiles??[],e.operation)}},[t,gt,vt,mt,Et,r,A,j,M,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(_===null||_===!0&&!v)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(_===!1)return ce?(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`)}),b.includes(`open-without-worktree-features`)?(0,$.jsx)(`p`,{className:`typography-meta mt-2 text-muted-foreground`,children:t(`gitView.empty.worktreeFeaturesUnavailable`)}):null]});let Sn=v?(0,$.jsxs)($.Fragment,{children:[S?(0,$.jsx)(Qs,{currentBranch:v.current,onRename:Gt,iconOnly:!0}):(0,$.jsx)(Ga,{currentBranch:v.current,localBranches:Jt,remoteBranches:Yt,branchInfo:C?.branches,onCheckout:qt,onCreate:Wt,remotes:Xt,iconOnly:!0}),(0,$.jsx)(uc,{syncAction:Te,remotes:Xt,onSync:e=>zt(`sync`,e),disabled:!v,aheadCount:v.ahead,behindCount:v.behind,trackingRemoteName:v.tracking?.split(`/`)[0],hasUncommittedChanges:(v.files?.length??0)>0}),(0,$.jsxs)(ta,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{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)(Vi,{sideOffset:8,children:t(`gitView.header.repositoryViews`)})]}),(0,$.jsxs)(ea,{align:`end`,children:[(0,$.jsxs)(la,{onSelect:()=>ut(`history`),children:[(0,$.jsx)(X,{name:`history`,className:`size-4`}),t(`gitView.history.title`)]}),(0,$.jsxs)(la,{onSelect:()=>ut(`graph`),children:[(0,$.jsx)(X,{name:`git-merge`,className:`size-4`}),t(`gitView.graph.title`)]}),(0,$.jsxs)(la,{onSelect:cn,children:[(0,$.jsx)(X,{name:`archive-stack`,className:`size-4`}),t(`gitView.stashes.title`)]})]})]})]}):null;return(0,$.jsxs)(`div`,{className:Y(`flex h-full flex-col overflow-hidden`),children:[r&&(v?.mergeInProgress?.head||v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto)&&(0,$.jsx)(Yd,{mergeInProgress:v?.mergeInProgress,rebaseInProgress:v?.rebaseInProgress,onContinue:mn,onAbort:hn,onResolveWithAI:gn,hasUnresolvedConflicts:pn,isLoading:T}),(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)(xi,{as:Ai,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:v?.files?.length??0})}),(0,$.jsx)(`div`,{className:`ml-auto grid shrink-0 grid-flow-col auto-cols-[1.5rem] items-center justify-end`,children:Sn})]}),(0,$.jsx)(Xs,{stagedCount:It,unstagedCount:Lt,onLoad:()=>be(!0)})]}):(Nt?.length??0)>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,$.jsx)(oc,{groups:ln,diffStats:v?.diffStats,revertingPaths:q,isRevertingAll:Le,onVisiblePathsChange:ve,onRevertAll:an,onRevertDirectory:on,headerBackgroundClassName:`bg-background`,headerActions:Sn})}),(0,$.jsx)(cc,{stagedCount:Qt,commitMessage:he,onCommitMessageChange:ge,generatedHighlights:Ve,onInsertHighlights:un,onGenerateMessage:Vt,isGeneratingMessage:ze,onCommit:()=>Bt({pushAfter:!1}),onCommitAndPush:()=>Bt({pushAfter:!0}),commitAction:ke,hasPendingIndexMutation:Ue,gitmojiEnabled:ue,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:Sn})]}),(0,$.jsx)(vd,{onOpenStashes:()=>Oe(!0)})]})})})})})}),(0,$.jsx)(ur,{open:lt!==null,onOpenChange:e=>{e||ut(null)},children:(0,$.jsxs)(sr,{className:`max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsx)(cr,{children:t(lt===`graph`?`gitView.graph.title`:`gitView.history.title`)}),(0,$.jsx)(lr,{children:t(`gitView.history.dialogDescription`)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,$.jsx)(Ld,{mode:lt===`graph`?`graph`:`history`,log:lt===`graph`?yt??w:w,isLogLoading:lt===`graph`&&xt||E,logMaxCount:lt===`graph`?Ct:je,onLogMaxCountChange:lt===`graph`?vn:_n,expandedCommitHashes:Ke,onToggleCommit:kt,commitFilesMap:Je,loadingCommitHashes:Ze,onCopyHash:Ot,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:`h-full max-h-none`,branchDivider:lt===`graph`?null:rt,onConflict:lt===`graph`?xn:void 0,onActionSuccess:lt===`graph`?bn:void 0})})]})}),(0,$.jsx)(gd,{open:De,onOpenChange:Oe,directory:r,hasUncommittedChanges:(v?.files?.length??0)>0,hasStagedChanges:Pt.length>0,uncommittedFileCount:v?.files?.length??0,onChanged:async e=>{r&&e?.affectsIndex&&L(r),await jt(!1),await Mt()}}),(0,$.jsx)(ur,{open:Se,onOpenChange:Ce,children:(0,$.jsxs)(sr,{className:`max-w-md p-0 overflow-hidden`,children:[(0,$.jsx)(ar,{className:`px-4 pt-4`,children:(0,$.jsx)(cr,{children:t(`gitView.gitmoji.title`)})}),(0,$.jsxs)(co,{className:`h-[420px]`,children:[(0,$.jsx)(so,{placeholder:t(`gitView.gitmoji.searchPlaceholder`),value:st,onValueChange:ct}),(0,$.jsxs)(ja,{children:[(0,$.jsx)(za,{children:t(`gitView.gitmoji.empty`)}),(0,$.jsx)(ka,{children:(pe.length===0?[]:pe.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)(Ba,{onSelect:()=>dn(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)(Hd,{open:pt,onOpenChange:mt,conflictFiles:ht,directory:r,operation:_t,onAbort:fn,onClearState:Dt})]})},uf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),df=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},ff=(e,t)=>{let n=df(t),r=df(e).replace(/\/+$/,``);return n===r?`.`:!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},pf=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),mf=new Set([`node_modules`]),hf=e=>mf.has(e),gf=e=>{let t=df(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},_f=8,vf=new Map,yf=e=>{let t=vf.get(e);return t?(t.touchedAt=Date.now(),vf.delete(e),vf.set(e,t),t):null},bf=e=>{let t=vf.get(e);if(t)return t.touchedAt=Date.now(),t;if(vf.size>=_f){let e=vf.keys().next().value;e!==void 0&&vf.delete(e)}let n={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return vf.set(e,n),n},xf=e=>{vf.delete(e)},Sf=(e,t)=>(0,$.jsx)(Va,{filePath:e,extension:t,className:`size-3.5`}),Cf=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},wf=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}=Xe(),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(),$e(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(Zn())]}),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=ff(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`,L;t[29]===I?L=t[30]:(L=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]=L);let R;t[31]!==h||t[32]!==i||t[33]!==n.extension||t[34]!==n.path?(R=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`}):Sf(n.path,n.extension),t[31]=h,t[32]=i,t[33]=n.extension,t[34]=n.path,t[35]=R):R=t[35];let z;t[36]!==n.name||t[37]!==n.path?(z=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-code`,title:n.path,children:n.name}),t[36]=n.name,t[37]=n.path,t[38]=z):z=t[38];let B;t[39]!==h||t[40]!==o?(B=!h&&o&&(0,$.jsx)(Cf,{status:o}),t[39]=h,t[40]=o,t[41]=B):B=t[41];let V;t[42]!==s||t[43]!==h?(V=h&&s&&(0,$.jsxs)(`span`,{className:`text-xs flex items-center gap-1 ml-auto mr-1`,children:[s.modified>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-warning)]`,children:[`M`,s.modified]}),s.added>0&&(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,s.added]})]}),t[42]=s,t[43]=h,t[44]=V):V=t[44];let H;t[45]!==E||t[46]!==P||t[47]!==O||t[48]!==z||t[49]!==B||t[50]!==V||t[51]!==L||t[52]!==R?(H=(0,$.jsxs)(`button`,{type:`button`,onClick:O,onContextMenu:E,draggable:!0,onDragStart:P,className:L,children:[R,z,B,V]}),t[45]=E,t[46]=P,t[47]=O,t[48]=z,t[49]=B,t[50]=V,t[51]=L,t[52]=R,t[53]=H):H=t[53];let U;t[54]!==_||t[55]!==v||t[56]!==y||t[57]!==g||t[58]!==b||t[59]!==x||t[60]!==M||t[61]!==m?(U=(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)(ta,{open:x,onOpenChange:S,children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(ca,{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)(Vi,{side:`bottom`,sideOffset:6,children:m(`sidebarFilesTree.actions.fileMenuTitle`)})]}),(0,$.jsx)(ea,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>S(!1),children:M({Item:la,Separator:sa})})]})}),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]=U):U=t[62];let ee;t[63]!==H||t[64]!==U||t[65]!==F?(ee=(0,$.jsxs)(pc,{render:F,children:[H,U]}),t[63]=H,t[64]=U,t[65]=F,t[66]=ee):ee=t[66];let te;t[67]===M?te=t[68]:(te=(0,$.jsx)(hc,{className:`min-w-[180px]`,children:M({Item:gc,Separator:mc})}),t[67]=M,t[68]=te);let W;return t[69]!==C||t[70]!==ee||t[71]!==te?(W=(0,$.jsxs)(_c,{open:C,onOpenChange:w,children:[ee,te]}),t[69]=C,t[70]=ee,t[71]=te,t[72]=W):W=t[72],W},(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),Tf=()=>{let{t:e}=Xe(),{files:t}=fo(),n=Ro()??``,r=df(n.trim()),i=B(),a=x(),o=Ae(e=>e.searchFiles),s=p(e=>e.openContextFile),c=Zo(n),[l,u]=Q.useState(``),d=Vo(l,200),f=Q.useRef(null),[m,h]=Q.useState([]),[g,_]=Q.useState(!1),[v,y]=Q.useState({}),[b,S]=Q.useState({}),C=Q.useRef(new Set),w=Q.useRef(new Set),T=Q.useRef(null);Q.useEffect(()=>{if(!r){y({}),S({}),C.current=new Set;return}let e=yf(r);e?(y({...e.childrenByDir}),S({...e.loadErrorsByDir}),C.current=new Set(e.loadedDirs)):(y({}),S({}),C.current=new Set)},[r]),Q.useEffect(()=>{if(!r)return;let e=bf(r);e.childrenByDir=v},[r,v]),Q.useEffect(()=>{if(!r)return;let e=bf(r);e.loadErrorsByDir=b},[r,b]),Q.useEffect(()=>{if(!r)return;let e=bf(r);e.loadedDirs=new Set(C.current)},[r,v,b]),Q.useEffect(()=>()=>{if(!r)return;let e=vf.get(r);e&&e.loadedDirs.size===0&&Object.keys(e.childrenByDir).length===0&&xf(r)},[r]);let E=Q.useMemo(()=>[],[]),D=Q.useMemo(()=>[],[]),O=Ho(e=>r?e.byRoot[r]?.expandedPaths??E:E),k=Ho(e=>r?e.byRoot[r]?.selectedPath??null:null),A=Ho(e=>e.setSelectedPath),j=Ho(e=>e.addOpenPath),M=Ho(e=>e.removeOpenPathsByPrefix),N=Ho(e=>e.removeExpandedPathsByPrefix),P=Ho(e=>e.toggleExpandedPath),F=Ho(e=>e.expandPaths),I=p(e=>r?e.contextPanelByDirectory[r]?.tabs??D:D),L=Q.useMemo(()=>new Set(I.map(e=>e.mode===`file`?e.targetPath:null).filter(e=>typeof e==`string`&&e.length>0).map(e=>df(e))),[I]),[R,z]=Q.useState(null),[V,H]=Q.useState(null),[U,ee]=Q.useState(``),[te,W]=Q.useState(!1),ne=!!t.writeFile,G=!!t.createDirectory,re=!!t.rename,K=!!t.delete,ie=!!t.revealPath,ae=Q.useMemo(()=>({canRename:re,canCreateFile:ne,canCreateFolder:G,canDelete:K,canReveal:ie}),[re,ne,G,K,ie]),oe=Q.useCallback(n=>{t.revealPath&&t.revealPath(n).catch(()=>{J.error(e(`sidebarFilesTree.toast.revealFailed`))})},[t,e]),se=Q.useCallback((e,t)=>{z(e),H(t),ee(e===`rename`&&t.name||``),W(!1)},[]),ce=Q.useCallback((e,t)=>uf(t.filter(e=>e&&typeof e.name==`string`&&e.name.length>0).filter(e=>i||!e.name.startsWith(`.`)).filter(e=>a||!hf(e.name)).map(t=>{let n=t.name,r=df(t.path||``),i=r?pf(r)?r:df(`${e}/${r}`):df(`${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]),le=Q.useCallback(async(e,n)=>{let r=df(e.trim());if(!r||C.current.has(r)||w.current.has(r))return;w.current=new Set(w.current),w.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}))):Ne.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=ce(r,e);C.current=new Set(C.current),C.current.add(r),S(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),S(e=>({...e,[r]:t}))}finally{w.current=new Set(w.current),w.current.delete(r)}},[t,ce]),ue=Q.useCallback(async()=>{if(!r)return;T.current?.abort();let e=new AbortController;T.current=e;try{let t=(Ho.getState().byRoot[r]?.expandedPaths??[]).map(e=>df(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)),n=[r,...t];C.current=new Set(C.current);for(let e of n)C.current.delete(e);S(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 le(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=>le(e,i)))}}catch(t){if(e.signal.aborted)return;console.error(`Failed to refresh sidebar tree:`,t)}finally{T.current===e&&(T.current=null)}},[le,r]),de=Q.useCallback(async e=>{if(!e){await ue();return}let t=df(e);C.current=new Set(C.current),C.current.delete(t),w.current=new Set(w.current),w.current.delete(t),await le(t)},[le,ue]);Q.useEffect(()=>{r&&(T.current?.abort(),C.current=new Set,w.current=new Set,S({}),y(e=>Object.keys(e).length===0?e:{}),le(r))},[le,r,i,a]),Q.useEffect(()=>{if(!r||O.length===0)return;let e=O.map(e=>df(e)).filter(e=>!!e&&e!==r&&e.startsWith(`${r}/`)&&!C.current.has(e)&&!w.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=>le(e,n)))}})(),()=>{t=!0}},[O,le,r]),Q.useEffect(()=>{if(!n){h([]),_(!1);return}let e=d.trim();if(!e){h([]),_(!1);return}let t=!1;return _(!0),o(n,e,150,{includeHidden:i,respectGitignore:!a,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>a||!gf(e.path)).map(e=>({name:e.name,path:df(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));h(n)}).catch(()=>{t||h([])}).finally(()=>{t||_(!1)}),()=>{t=!0}},[n,d,o,i,a]);let fe=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]),pe=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]),me=Q.useCallback(e=>{if(L.has(e))return`open`;if(fe.size===0)return null;let t=e.startsWith(r+`/`)?e.slice(r.length+1):e;return fe.get(t)??null},[L,fe,r]),he=Q.useCallback(e=>{if(pe.size===0)return null;let t=pe.get(e);return t&&t.modified+t.added>0?t:null},[pe]),ge=Q.useCallback(async e=>{if(!r)return;let n=await nc(t,e.path);if(!n.ok){J.error(Gs(n.reason));return}A(r,e.path),j(r,e.path),s(r,e.path)},[j,t,s,r,A]),_e=Q.useCallback(async e=>{let t=df(e);r&&(P(r,t),C.current.has(t)||await le(t))},[le,r,P]),ve=Q.useMemo(()=>Array.from(new Set(Object.values(v).flatMap(e=>e.filter(e=>e.type===`directory`).map(e=>e.path)))),[v]),ye=Q.useMemo(()=>new Set(O.map(e=>df(e))),[O]),be=ve.length>0&&ve.every(e=>ye.has(df(e))),xe=Q.useCallback(()=>{if(r){if(be){N(r,r);return}F(r,ve)}},[be,ve,F,N,r]),Se=Q.useCallback(async n=>{if(n?.preventDefault(),!V||!R)return;W(!0);let i=()=>W(!1),a=()=>z(null);if(R===`createFile`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.filenameRequired`)),i();return}if(!t.writeFile){J.error(e(`sidebarFilesTree.toast.writeNotSupported`)),i();return}let n=V.path,r=df(`${n?`${n}/`:``}${U.trim()}`);await t.writeFile(r,``).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.fileCreated`)),await de(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`createFolder`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.folderNameRequired`)),i();return}let n=V.path,r=df(`${n?`${n}/`:``}${U.trim()}`);await t.createDirectory(r).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.folderCreated`)),await de(n)),a()}).catch(()=>J.error(e(`sidebarFilesTree.toast.operationFailed`))).finally(i);return}if(R===`rename`){if(!U.trim()){J.error(e(`sidebarFilesTree.toast.nameRequired`)),i();return}if(!t.rename){J.error(e(`sidebarFilesTree.toast.renameNotSupported`)),i();return}let n=V.path,o=n.split(`/`).slice(0,-1).join(`/`),s=df(`${o?`${o}/`:``}${U.trim()}`);await t.rename(n,s).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.renamedSuccessfully`)),await de(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=V.path,o=n.split(`/`).slice(0,-1).join(`/`);await t.delete(n).then(async t=>{t.success&&(J.success(e(`sidebarFilesTree.toast.deletedSuccessfully`)),await de(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,V,U,t,de,M,r,k,A,e]);function Ce(n,i){return(v[n]??[]).map(n=>{let a=n.type===`directory`,o=a&&ye.has(df(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)(wf,{node:n,root:r,isExpanded:o,isActive:s,status:a?void 0:me(n.path),badge:a?he(n.path):void 0,permissions:ae,downloadFile:t.downloadFile,onSelect:ge,onToggle:_e,onRevealPath:oe,onOpenDialog:se}),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 de(n.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):null,Ce(n.path,i+1)]})]},n.path)})}let we=!!(r&&v[r]),Te=r?b[r]:null,Ee=e(be?`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)(zi,{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:[ne&&(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>se(`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)(Vi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFileTitle`)})]}),G&&(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>se(`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)(Vi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:()=>void ue(),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)(Vi,{side:`bottom`,sideOffset:6,children:e(`sidebarFilesTree.actions.refreshTitle`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,onClick:xe,disabled:ve.length===0&&O.length===0,className:`w-6 flex-shrink-0 p-0`,title:Ee,"aria-label":Ee,children:(0,$.jsx)(X,{name:be?`contract-up-down`:`expand-up-down`,className:`size-3.5`})})}),(0,$.jsx)(Vi,{side:`bottom`,sideOffset:6,children:Ee})]})]})]}),(0,$.jsx)(xi,{outerClassName:`flex-1 min-h-0`,className:`p-2`,children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:g?(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`)]}):m.length>0?m.map(e=>{let t=k===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ge(e),draggable:!0,onDragStart:t=>{let n=e.relativePath||ff(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:[Sf(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)}):Te?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 px-2 py-1 typography-code text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:Te}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void ue(),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`}),e(`sidebarFilesTree.actions.refreshTitle`)]})]}):we&&r?Ce(r,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-code text-muted-foreground`,children:e(`sidebarFilesTree.state.loading`)})})}),(0,$.jsx)(ur,{open:!!R,onOpenChange:e=>!e&&z(null),children:(0,$.jsxs)(sr,{children:[(0,$.jsxs)(ar,{children:[(0,$.jsxs)(cr,{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)(lr,{children:[R===`createFile`&&e(`sidebarFilesTree.dialog.createFile.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`createFolder`&&e(`sidebarFilesTree.dialog.createFolder.description`,{path:V?.path??e(`sidebarFilesTree.dialog.rootFallback`)}),R===`rename`&&e(`sidebarFilesTree.dialog.rename.description`,{name:V?.name??``}),R===`delete`&&e(`sidebarFilesTree.dialog.delete.description`,{name:V?.name??``})]})]}),R!==`delete`&&(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(zi,{value:U,onChange:e=>ee(e.target.value),placeholder:e(R===`rename`?`sidebarFilesTree.dialog.rename.placeholder`:`sidebarFilesTree.dialog.namePlaceholder`),onKeyDown:e=>{e.key===`Enter`&&Se()},autoFocus:!0})}),(0,$.jsxs)(or,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>z(null),disabled:te,children:e(`sidebarFilesTree.dialog.cancel`)}),(0,$.jsx)(Z,{variant:R===`delete`?`destructive`:`default`,onClick:()=>void Se(),disabled:te||R!==`delete`&&!U.trim(),children:te?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):e(R===`delete`?`sidebarFilesTree.dialog.delete.confirm`:`sidebarFilesTree.dialog.confirm`)})]})]})})]})},Ef=e=>e===`git`||e===`files`||e===`context`,Df=`files`,Of=()=>!(typeof document<`u`&&document.hidden||typeof navigator<`u`&&!navigator.onLine);function kf(e,t,n,r){let i=(0,zc.c)(6),{git:a}=fo(),o=Wo(Af),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(()=>{Of()&&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 Af(e){return e.ensureStatus}var jf=()=>{let e=(0,zc.c)(15),t=mn(Nf),n=mn(Pf),r=Wo(Ff),i;bb0:{if(t){let r;e[0]!==t||e[1]!==n?(r=n.find(e=>e.id===t)??n[0]??null,e[0]=t,e[1]=n,e[2]=r):r=e[2],i=r;break bb0}i=n[0]??null}let a=i,o;bb1:{if(!a){o=null;break bb1}let t;e[3]!==a.id||e[4]!==a.path?(t={id:a.id,path:a.path},e[3]=a.id,e[4]=a.path,e[5]=t):t=e[5],o=t}let s=o,c;bb2:{if(!a){c=null;break bb2}let t;e[6]===a.path?t=e[7]:(t=er(a.path)||a.path,e[6]=a.path,e[7]=t),c=t}let l=c,u;bb3:{if(!a){u=!1;break bb3}let t;e[8]!==a.path||e[9]!==r?(t=r.get(a.path)?.isGitRepo,e[8]=a.path,e[9]=r,e[10]=t):t=e[10],u=t===!0}let d=u,f;return e[11]!==d||e[12]!==l||e[13]!==s?(f=(0,$.jsx)(`div`,{className:`h-full min-h-0 overflow-auto bg-background`,children:(0,$.jsx)(Uu,{projectRef:s,projectLabel:l,canCreateWorktree:d})}),e[11]=d,e[12]=l,e[13]=s,e[14]=f):f=e[14],f},Mf=()=>{let e=(0,zc.c)(57),{t}=Xe(),n=p(If),r=p(Lf),i=p(Rf),a=p(zf);kf(Ro(),i,n,a);let o=a===`git`?`git`:a===`context`?`context`:null,s,c;e[0]!==o||e[1]!==n||e[2]!==r?(s=()=>{o&&n===o&&r(Df)},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 m;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(X,{name:`folder-3`,className:`h-3.5 w-3.5`}),e[12]=m):m=e[12];let h;e[13]===f?h=e[14]:(h={id:`files`,label:f,icon:m},e[13]=f,e[14]=h);let g;e[15]===t?g=e[16]:(g=t(`layout.rightSidebar.context`),e[15]=t,e[16]=g);let _;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(X,{name:`file-list-2`,className:`h-3.5 w-3.5`}),e[17]=_):_=e[17];let v;e[18]===g?v=e[19]:(v={id:`context`,label:g,icon:_},e[18]=g,e[19]=v);let y;e[20]!==v||e[21]!==d||e[22]!==h?(y=[d,h,v],e[20]=v,e[21]=d,e[22]=h,e[23]=y):y=e[23];let b=y,x;e[24]!==o||e[25]!==b?(x=o?b.filter(e=>e.id!==o):b,e[24]=o,e[25]=b,e[26]=x):x=e[26];let S=x,C=i&&n===`git`&&o!==`git`,w;e[27]===r?w=e[28]:(w=e=>{Ef(e)&&r(e)},e[27]=r,e[28]=w);let T=w,E;e[29]!==T||e[30]!==n||e[31]!==S?(E=(0,$.jsx)(`div`,{className:`h-9 bg-background pt-1 px-2`,children:(0,$.jsx)($o,{items:S,activeId:n,onSelect:T,layoutMode:`fit`,variant:`active-pill`,activePillLowercase:!1,className:`h-full`})}),e[29]=T,e[30]=n,e[31]=S,e[32]=E):E=e[32];let D=n!==`git`&&`hidden`,O;e[33]===D?O=e[34]:(O=Y(`h-full`,D),e[33]=D,e[34]=O);let k;e[35]===C?k=e[36]:(k=(0,$.jsx)(lf,{isActive:C}),e[35]=C,e[36]=k);let A;e[37]!==O||e[38]!==k?(A=(0,$.jsx)(`div`,{className:O,children:k}),e[37]=O,e[38]=k,e[39]=A):A=e[39];let j=n!==`files`&&`hidden`,M;e[40]===j?M=e[41]:(M=Y(`h-full`,j),e[40]=j,e[41]=M);let N;e[42]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Tf,{}),e[42]=N):N=e[42];let P;e[43]===M?P=e[44]:(P=(0,$.jsx)(`div`,{className:M,children:N}),e[43]=M,e[44]=P);let F=n!==`context`&&`hidden`,I;e[45]===F?I=e[46]:(I=Y(`h-full`,F),e[45]=F,e[46]=I);let L;e[47]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(jf,{}),e[47]=L):L=e[47];let R;e[48]===I?R=e[49]:(R=(0,$.jsx)(`div`,{className:I,children:L}),e[48]=I,e[49]=R);let z;e[50]!==A||e[51]!==P||e[52]!==R?(z=(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:[A,P,R]}),e[50]=A,e[51]=P,e[52]=R,e[53]=z):z=e[53];let B;return e[54]!==E||e[55]!==z?(B=(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[E,z]}),e[54]=E,e[55]=z,e[56]=B):B=e[56],B};function Nf(e){return e.activeProjectId}function Pf(e){return e.projects}function Ff(e){return e.directories}function If(e){return e.rightSidebarTab}function Lf(e){return e.setRightSidebarTab}function Rf(e){return e.isRightSidebarOpen}function zf(e){return e.activeMainTab}var Bf=(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)},Vf=(e,t)=>{let n=e.state.doc.lineAt(t.main.head);return{lineNumber:n.number,character:t.main.head-n.from+1,selection:t}},Hf=(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:We.cursor(a),effects:Ue.scrollIntoView(a,{y:`center`})})};function Uf({open:e,onOpenChange:t,view:n,variant:r=`overlay`}){let{t:i}=Xe(),[a,o]=Q.useState(``),s=Q.useRef(null),c=Q.useRef(!1),l=Q.useRef(null),u=Q.useRef(null),d=Q.useMemo(()=>Bf(a,n),[a,n]);Q.useEffect(()=>{!e||!n||(c.current=!1,s.current=Vf(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:Ue.scrollIntoView(e.main.from,{y:`center`})});return}Hf(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:Ue.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,Hf(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??Vf(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)(zi,{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)(zi,{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 Wf=_o(()=>Fe(()=>import(`./ToolOutputDialog-D3U6aTZ4.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]))),Gf=e=>{let t=Jf(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},Kf=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},qf=e=>e.slice().sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1),Jf=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},Yf=e=>e.startsWith(`/`)||e.startsWith(`//`)||/^[A-Za-z]:\//.test(e),Xf=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,Zf=(e,t)=>{let n=Jf(t),r=Jf(e);if(!n||!r)return!1;let i=Xf(n),a=Xf(r);return a===i||a.startsWith(`${i}/`)},Qf=(e,t)=>{let n=Jf(t),r=Jf(e);if(!Zf(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},$f=(e,t)=>{if(!t)return``;let n=Jf(t);if(!e||!Zf(n,e))return n;let r=n.slice(e.length);return r.startsWith(`/`)?r.slice(1):r},ep=new Set([`node_modules`]),tp=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},np=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},rp=e=>ep.has(e),ip=e=>{let t=Jf(e);return t===`node_modules`||t.endsWith(`/node_modules`)||t.includes(`/node_modules/`)},ap=e=>{let t=(e instanceof Error?e.message:String(e??``)).toLowerCase();return t.includes(`is a directory`)||t.includes(`eisdir`)},op=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`)},sp=2e5,cp=`openchamber:files:auto-save-enabled`,lp=e=>{let t=0,n=0;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(r>0&&e.charCodeAt(r-1)===13?t+=1:n+=1);return t>n?`\r
|
|
7
7
|
`:`
|
|
8
|
-
`},
|
|
8
|
+
`},up=e=>e.replace(/\r\n/g,`
|
|
9
9
|
`).replace(/\r/g,`
|
|
10
|
-
`),
|
|
10
|
+
`),dp=(e,t)=>{let n=up(e);return t===`\r
|
|
11
11
|
`?n.replace(/\n/g,`\r
|
|
12
|
-
`):n},dp=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(sp)!==`false`}catch{return!0}},fp=(e,t)=>(0,$.jsx)(Ba,{filePath:e,extension:t}),pp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},mp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`html`||t===`htm`},hp=e=>{let t=(0,Rc.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}=Xe(),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(),$e(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=Qf(r,n.path)||n.path;$e(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(Yn())]}),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 L=o?void 0:O,R;t[33]===L?R=t[34]:(R=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:L}),t[33]=L,t[34]=R);let z=o?void 0:O,B=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,V;t[35]===B?V=t[36]:(V=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`,B),t[35]=B,t[36]=V);let H;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(H=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`}):fp(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=H):H=t[41];let U;t[42]!==n.name||t[43]!==n.path?(U=(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]=U):U=t[44];let ee;t[45]!==x||t[46]!==c?(ee=!x&&c&&(0,$.jsx)(ep,{status:c}),t[45]=x,t[46]=c,t[47]=ee):ee=t[47];let te;t[48]!==l||t[49]!==x?(te=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]=te):te=t[50];let W;t[51]!==A||t[52]!==V||t[53]!==H||t[54]!==U||t[55]!==ee||t[56]!==te||t[57]!==z?(W=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:z,className:V,children:[H,U,ee,te]}),t[51]=A,t[52]=V,t[53]=H,t[54]=U,t[55]=ee,t[56]=te,t[57]=z,t[58]=W):W=t[58];let ne;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?(ne=(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)(ea,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(sa,{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)($i,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:ca,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]=ne):ne=t[71];let G;t[72]!==W||t[73]!==ne||t[74]!==R?(G=(0,$.jsxs)(fc,{render:R,children:[W,ne]}),t[72]=W,t[73]=ne,t[74]=R,t[75]=G):G=t[75];let re;t[76]===P?re=t[77]:(re=(0,$.jsx)(mc,{className:`min-w-[180px]`,children:P({Item:hc,Separator:pc})}),t[76]=P,t[77]=re);let K;return t[78]!==G||t[79]!==re||t[80]!==F||t[81]!==I?(K=(0,$.jsxs)(gc,{open:F,onOpenChange:I,children:[G,re]}),t[78]=G,t[79]=re,t[80]=F,t[81]=I,t[82]=K):K=t[82],K},gp=e=>{let t=(0,Rc.c)(83),{activeDialog:n,dialogData:r,dialogInputValue:i,onDialogInputChange:a,isDialogSubmitting:o,onDialogSubmit:s,onClose:c,inputRef:l}=e,{t:u}=Xe(),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)(or,{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)(sr,{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)(rr,{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)(Ri,{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)(ir,{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)(ar,{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)(cr,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},_p=(e,t,n)=>e&&!!t&&n===t,vp=(e,t,n)=>{let r=(0,Rc.c)(8),[i,o]=Q.useState(``),[c,l]=Q.useState(0),u,d;r[0]!==e||r[1]!==n||r[2]!==t?(u=()=>{if(!e){o(``);return}let r=!1;o(``);let i=m(),c=a(i);s(i).then(n=>{r||!n||(o(e),t(null))}).catch(i=>{r||(t(i instanceof Error?i.message:n),o(e))});let u=f(()=>{r||(o(e),l(bp),t(null))});return()=>{r=!0,c(),u()}},d=[e,t,n],r[0]=e,r[1]=n,r[2]=t,r[3]=u,r[4]=d):(u=r[3],d=r[4]),Q.useEffect(u,d);let p;return r[5]!==c||r[6]!==i?(p={readyKey:i,nonce:c},r[5]=c,r[6]=i,r[7]=p):p=r[7],p},yp=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=Xe(),{files:r,runtime:a}=uo(),{currentTheme:o,availableThemes:s,lightThemeId:c,darkThemeId:l}=Qi(),{isMobile:u,isTablet:d,screenWidth:f}=Ca(),m=u||d,h=B(),g=x(),_=Lo()??``,v=qf(_.trim()),y=u||e!==`editor-only`,b=e===`editor-only`&&!u,S=Ae(e=>e.searchFiles),C=Xo(_),[w,T]=Q.useState(``),E=Bo(w,200),D=Q.useRef(null),[O,k]=Q.useState(!1),[A,j]=Q.useState(!0),[M,N]=Q.useState(!1),[P,F]=Q.useState(!1),[I,L]=Q.useState(!1),[R,H]=Q.useState({open:!1,title:``,content:``}),U=Q.useRef(null),ee=Q.useRef(0),te=Q.useCallback(e=>{ee.current=Math.max(0,ee.current+(e?1:-1))},[]),W=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!I)return;let e=e=>{ee.current>0||W(e.target)||U.current&&!U.current.contains(e.target)&&L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[W,I]);let[re,K]=Q.useState(`edit`),[ie,ae]=Q.useState(`edit`),[oe,se]=Q.useState(`edit`),[ce,le]=Q.useState(`preview`),[ue,de]=Q.useState(0),fe=Q.useRef({}),pe=Q.useRef({}),me=Q.useRef({}),he=Q.useRef({}),ge=Q.useMemo(()=>s.find(e=>e.metadata.id===c)??Ta(!1),[s,c]),_e=Q.useMemo(()=>s.find(e=>e.metadata.id===l)??Ta(!0),[s,l]);Q.useEffect(()=>{ho(ge),ho(_e)},[ge,_e]);let ve=Q.useMemo(()=>[],[]),ye=Vo(e=>v?e.byRoot[v]?.openPaths??ve:ve),be=Vo(e=>v?e.byRoot[v]?.selectedPath??null:null),xe=Vo(e=>v?e.byRoot[v]?.expandedPaths??ve:ve),Se=Vo(e=>e.addOpenPath),Ce=Vo(e=>e.removeOpenPath),we=Vo(e=>e.removeOpenPathsByPrefix),Te=Vo(e=>e.removeExpandedPathsByPrefix),Ee=Vo(e=>e.setSelectedPath),De=Vo(e=>e.toggleExpandedPath),Oe=Vo(e=>e.expandPaths),ke=Q.useCallback(e=>{let t=qf(e),n=t.split(`/`),r=n[n.length-1]||t;return{name:r,path:t,type:`file`,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0}},[]),je=Q.useMemo(()=>ye.map(ke),[ye,ke]),Me=Q.useMemo(()=>{if(be){let e=Yf(be);if(ye.some(t=>Yf(t)===e))return be}return ye[0]??null},[ye,be]),q=Q.useMemo(()=>Me?ke(Me):null,[Me,ke]),Pe=q?.path??``;Q.useEffect(()=>{if(!v||!be)return;let e=Yf(be);ye.some(t=>Yf(t)===e)||Ee(v,ye[0]??null)},[ye,v,be,Ee]);let Fe=!!(v&&Pe&&!Xf(Pe,v)),Ie=Fe?zo(Pe):void 0,Le=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&Fe,outsideFileGrant:Ie,directory:v||void 0}),[e,Fe,Ie,v]),Re=Q.useRef(null),[ze,Be]=Q.useState({left:!1,right:!1}),Ve=Q.useCallback(()=>{let e=Re.current;e&&Be({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),He=Q.useRef(Ve);He.current=Ve,Q.useEffect(()=>{let e=Re.current;if(!e)return;let t=()=>He.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[je.length]);let[We,Ge]=Q.useState({}),[Ke,qe]=Q.useState({}),Je=Q.useRef(new Set),Ye=Q.useRef(new Set),Ze=Q.useRef(new Map),Qe=Q.useRef(0),[et,tt]=Q.useState([]),[nt,rt]=Q.useState(!1),[it,at]=Q.useState(``),{isPlaying:ot,play:st,stop:ct}=no(),[lt,ut]=Q.useState(!1),[ft,pt]=Q.useState(null),[mt,ht]=Q.useState(``),gt=Q.useRef(``),[_t,vt]=Q.useState(null),[yt,bt]=Q.useState(``),[xt,St]=Q.useState(!1),[Ct,Tt]=Q.useState(`
|
|
13
|
-
`),
|
|
12
|
+
`):n},fp=()=>{if(typeof window>`u`)return!0;try{return window.localStorage.getItem(cp)!==`false`}catch{return!0}},pp=(e,t)=>(0,$.jsx)(Va,{filePath:e,extension:t}),mp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`md`||t===`markdown`},hp=e=>{if(!e)return!1;let t=e.toLowerCase().split(`.`).pop();return t===`html`||t===`htm`},gp=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}=Xe(),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(),$e(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=$f(r,n.path)||n.path;$e(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(Zn())]}),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 L=o?void 0:O,R;t[33]===L?R=t[34]:(R=(0,$.jsx)(`div`,{className:`group relative flex items-center`,onContextMenu:L}),t[33]=L,t[34]=R);let z=o?void 0:O,B=a?`bg-interactive-selection/70`:`hover:bg-interactive-hover/40`,V;t[35]===B?V=t[36]:(V=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`,B),t[35]=B,t[36]=V);let H;t[37]!==x||t[38]!==i||t[39]!==n.extension||t[40]!==n.path?(H=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`}):pp(n.path,n.extension),t[37]=x,t[38]=i,t[39]=n.extension,t[40]=n.path,t[41]=H):H=t[41];let U;t[42]!==n.name||t[43]!==n.path?(U=(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]=U):U=t[44];let ee;t[45]!==x||t[46]!==c?(ee=!x&&c&&(0,$.jsx)(tp,{status:c}),t[45]=x,t[46]=c,t[47]=ee):ee=t[47];let te;t[48]!==l||t[49]!==x?(te=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]=te):te=t[50];let W;t[51]!==A||t[52]!==V||t[53]!==H||t[54]!==U||t[55]!==ee||t[56]!==te||t[57]!==z?(W=(0,$.jsxs)(`button`,{type:`button`,onClick:A,onContextMenu:z,className:V,children:[H,U,ee,te]}),t[51]=A,t[52]=V,t[53]=H,t[54]=U,t[55]=ee,t[56]=te,t[57]=z,t[58]=W):W=t[58];let ne;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?(ne=(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)(ta,{open:f===n.path,onOpenChange:e=>p(e?n.path:null),children:[(0,$.jsx)(ca,{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)(ea,{align:`end`,side:`bottom`,onCloseAutoFocus:()=>p(null),children:P({Item:la,Separator:sa})})]})}),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]=ne):ne=t[71];let G;t[72]!==W||t[73]!==ne||t[74]!==R?(G=(0,$.jsxs)(pc,{render:R,children:[W,ne]}),t[72]=W,t[73]=ne,t[74]=R,t[75]=G):G=t[75];let re;t[76]===P?re=t[77]:(re=(0,$.jsx)(hc,{className:`min-w-[180px]`,children:P({Item:gc,Separator:mc})}),t[76]=P,t[77]=re);let K;return t[78]!==G||t[79]!==re||t[80]!==F||t[81]!==I?(K=(0,$.jsxs)(_c,{open:F,onOpenChange:I,children:[G,re]}),t[78]=G,t[79]=re,t[80]=F,t[81]=I,t[82]=K):K=t[82],K},_p=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}=Xe(),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)(cr,{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)(lr,{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)(ar,{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)(zi,{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)(or,{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)(sr,{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)(ur,{open:d,onOpenChange:f,children:N}),t[79]=d,t[80]=f,t[81]=N,t[82]=P):P=t[82],P},vp=(e,t,n)=>e&&!!t&&n===t,yp=(e,t,n)=>{let r=(0,zc.c)(8),[i,o]=Q.useState(``),[c,l]=Q.useState(0),u,d;r[0]!==e||r[1]!==n||r[2]!==t?(u=()=>{if(!e){o(``);return}let r=!1;o(``);let i=m(),c=a(i);s(i).then(n=>{r||!n||(o(e),t(null))}).catch(i=>{r||(t(i instanceof Error?i.message:n),o(e))});let u=f(()=>{r||(o(e),l(xp),t(null))});return()=>{r=!0,c(),u()}},d=[e,t,n],r[0]=e,r[1]=n,r[2]=t,r[3]=u,r[4]=d):(u=r[3],d=r[4]),Q.useEffect(u,d);let p;return r[5]!==c||r[6]!==i?(p={readyKey:i,nonce:c},r[5]=c,r[6]=i,r[7]=p):p=r[7],p},bp=({mode:e=`full`,isActive:t=!0})=>{let{t:n}=Xe(),{files:r,runtime:a}=fo(),{currentTheme:o,availableThemes:s,lightThemeId:c,darkThemeId:l}=$i(),{isMobile:u,isTablet:d,screenWidth:f}=wa(),m=u||d,h=B(),g=x(),_=Ro()??``,v=Jf(_.trim()),y=u||e!==`editor-only`,b=e===`editor-only`&&!u,S=Ae(e=>e.searchFiles),C=Zo(_),[w,T]=Q.useState(``),E=Vo(w,200),D=Q.useRef(null),[O,k]=Q.useState(!1),[A,j]=Q.useState(!0),[M,N]=Q.useState(!1),[P,F]=Q.useState(!1),[I,L]=Q.useState(!1),[R,H]=Q.useState({open:!1,title:``,content:``}),U=Q.useRef(null),ee=Q.useRef(0),te=Q.useCallback(e=>{ee.current=Math.max(0,ee.current+(e?1:-1))},[]),W=Q.useCallback(e=>e instanceof Element&&e.closest(`[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]`)!==null,[]);Q.useEffect(()=>{if(!I)return;let e=e=>{ee.current>0||W(e.target)||U.current&&!U.current.contains(e.target)&&L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[W,I]);let[re,K]=Q.useState(`edit`),[ie,ae]=Q.useState(`edit`),[oe,se]=Q.useState(`edit`),[ce,le]=Q.useState(`preview`),[ue,de]=Q.useState(0),fe=Q.useRef({}),pe=Q.useRef({}),me=Q.useRef({}),he=Q.useRef({}),ge=Q.useMemo(()=>s.find(e=>e.metadata.id===c)??Ea(!1),[s,c]),_e=Q.useMemo(()=>s.find(e=>e.metadata.id===l)??Ea(!0),[s,l]);Q.useEffect(()=>{go(ge),go(_e)},[ge,_e]);let ve=Q.useMemo(()=>[],[]),ye=Ho(e=>v?e.byRoot[v]?.openPaths??ve:ve),be=Ho(e=>v?e.byRoot[v]?.selectedPath??null:null),xe=Ho(e=>v?e.byRoot[v]?.expandedPaths??ve:ve),Se=Ho(e=>e.addOpenPath),Ce=Ho(e=>e.removeOpenPath),we=Ho(e=>e.removeOpenPathsByPrefix),Te=Ho(e=>e.removeExpandedPathsByPrefix),Ee=Ho(e=>e.setSelectedPath),De=Ho(e=>e.toggleExpandedPath),Oe=Ho(e=>e.expandPaths),ke=Q.useCallback(e=>{let t=Jf(e),n=t.split(`/`),r=n[n.length-1]||t;return{name:r,path:t,type:`file`,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0}},[]),je=Q.useMemo(()=>ye.map(ke),[ye,ke]),Me=Q.useMemo(()=>{if(be){let e=Xf(be);if(ye.some(t=>Xf(t)===e))return be}return ye[0]??null},[ye,be]),q=Q.useMemo(()=>Me?ke(Me):null,[Me,ke]),Pe=q?.path??``;Q.useEffect(()=>{if(!v||!be)return;let e=Xf(be);ye.some(t=>Xf(t)===e)||Ee(v,ye[0]??null)},[ye,v,be,Ee]);let Fe=!!(v&&Pe&&!Zf(Pe,v)),Ie=Fe?Bo(Pe):void 0,Le=Q.useMemo(()=>({allowOutsideWorkspace:e===`editor-only`&&Fe,outsideFileGrant:Ie,directory:v||void 0}),[e,Fe,Ie,v]),Re=Q.useRef(null),[ze,Be]=Q.useState({left:!1,right:!1}),Ve=Q.useCallback(()=>{let e=Re.current;e&&Be({left:e.scrollLeft>2,right:e.scrollLeft+e.clientWidth<e.scrollWidth-2})},[]),He=Q.useRef(Ve);He.current=Ve,Q.useEffect(()=>{let e=Re.current;if(!e)return;let t=()=>He.current();t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[je.length]);let[We,Ge]=Q.useState({}),[Ke,qe]=Q.useState({}),Je=Q.useRef(new Set),Ye=Q.useRef(new Set),Ze=Q.useRef(new Map),Qe=Q.useRef(0),[et,tt]=Q.useState([]),[nt,rt]=Q.useState(!1),[it,at]=Q.useState(``),{isPlaying:ot,play:st,stop:ct}=ro(),[lt,ut]=Q.useState(!1),[dt,ft]=Q.useState(null),[pt,mt]=Q.useState(``),ht=Q.useRef(``),[gt,_t]=Q.useState(null),[vt,yt]=Q.useState(``),[bt,xt]=Q.useState(!1),[St,Ct]=Q.useState(`
|
|
13
|
+
`),wt=Q.useRef(null),Tt=Q.useRef(null),Et=Q.useRef(null),Dt=Q.useRef(``),Ot=Q.useRef(``),kt=Q.useRef(null),At=Q.useRef(null),jt=Q.useRef(null),Mt=Q.useRef(0),[Nt,Pt]=Q.useState(`idle`),[Ft,It]=Q.useState(!1),[Rt,zt]=Q.useState(fp),[Bt,Vt]=Q.useState(!1),Ht=Q.useRef(null),Wt=Q.useRef(null),Gt=Q.useRef(null),Kt=Q.useRef(!1),qt=Q.useRef(null),Jt=Q.useRef(null),Yt=Q.useRef(null),Xt=Q.useRef(null),[Zt,Qt]=Q.useState(0),$t=Q.useRef(null),en=Q.useRef({key:``,attempts:0});Q.useEffect(()=>()=>{$t.current!==null&&typeof window<`u`&&(window.cancelAnimationFrame($t.current),$t.current=null)},[]);let[tn,nn]=Q.useState(null),[rn,an]=Q.useState(null),[on,sn]=Q.useState(``),[cn,ln]=Q.useState(!1),[un,dn]=Q.useState(null),[fn,pn]=Q.useState(null),[mn,hn]=Q.useState(!1),[gn,_n]=Q.useState(!1),[vn,yn]=Q.useState(!1),[bn,xn]=Q.useState(!1),[Sn,Cn]=Q.useState(null),wn=Lt(e=>e.addCodeSelectionAttachment),Tn=Lt(e=>e.setPendingInputText),En=!!r.writeFile,Dn=!!r.createDirectory,On=!!r.rename,kn=!!r.delete,An=!!r.revealPath,jn=el(e=>e.availableApps),Mn=el(e=>e.isCacheStale),Nn=el(e=>e.initialize),Pn=el(e=>e.loadInstalledApps);Q.useEffect(()=>{Nn()},[Nn]);let Fn=Q.useCallback(e=>{r.revealPath&&r.revealPath(e).catch(()=>{J.error(n(`sidebarFilesTree.toast.revealFailed`))})},[r,n]),In=Q.useCallback(async e=>{if(!q?.path||await ne(q.path,e.id,e.appName)||await z(q.path,e.appName))return;let t=Gf(q.path)||v;t&&await z(t,e.appName)||J.error(n(`filesView.toast.openInAppFailed`,{app:e.appName}))},[v,q?.path,n]),Ln=Q.useCallback((e,t)=>{nn(e),an(t),sn(e===`rename`&&t.name||``),ln(!1)},[]),[Rn,zn]=Q.useState(null),Bn=Q.useRef(!1),Vn=Q.useRef(null),[Hn,Un]=Q.useState(!1),Wn=p(e=>e.setMainTabGuard),Gn=p(e=>e.pendingFileNavigation),Kn=p(e=>e.setPendingFileNavigation),qn=p(e=>e.pendingFileFocusPath),Jn=p(e=>e.setPendingFileFocusPath),Yn=p(e=>e.shortcutOverrides),Xn=p(e=>e.fileEditorKeymap),Zn=Ut(e=>e.settingsDefaultFileViewerPreview),Qn=Ut(e=>e.showMessageTTSButtons),er=p(e=>e.expandedEditorToolbar);Q.useEffect(()=>{let e=()=>{Bn.current=!1,Vn.current=null,Un(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]),Q.useEffect(()=>()=>{qt.current!==null&&window.clearTimeout(qt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);let nr=Q.useCallback((e,t)=>{let n=e.split(`
|
|
14
14
|
`),r=Math.max(1,t.start),i=Math.min(n.length,t.end);return r>i?``:n.slice(r-1,i).join(`
|
|
15
|
-
`)},[]),{drafts:lr,commentText:ur,setCommentText:dr,editingDraftId:fr,setSelection:pr,saveComment:mr,cancel:hr,reset:gr,startEdit:_r,deleteDraft:vr}=zs({source:`file`,fileLabel:q?.path??null,language:q?.path&&Io(q.path)||`text`,getCodeForRange:e=>nr(it,Gs(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{zn(null),gr(),Wn(null),bt(``),St(!1)},[q?.path,gr,Wn]),Q.useEffect(()=>{pr(Rn)},[Rn,pr]),Q.useEffect(()=>{if(!Rn&&!fr)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]`)||ur.trim()||(zn(null),hr())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[hr,ur,fr,Rn]);let yr=Q.useCallback((e,t)=>{let n=t??Rn??void 0;t&&zn(t),mr(e,n),zn(null)},[Rn,mr]),br=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!h&&r.name.startsWith(`.`)||!g&&np(r.name))continue;let t=r.name,i=qf(r.path||``),a=i?Jf(i)?i:qf(`${e}/${i}`):qf(`${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 Kf(n)},[g,h]),xr=Q.useCallback(async e=>{let t=qf(e.trim());if(!t||Je.current.has(t)||Ye.current.has(t))return;Ye.current=new Set(Ye.current),Ye.current.add(t);let n=Qe.current+1;Qe.current=n,Ze.current=new Map(Ze.current),Ze.current.set(t,n);let i=()=>Ze.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}))):Ne.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!i())return;let n=br(t,e);Je.current=new Set(Je.current),Je.current.add(t),qe(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ge(e=>({...e,[t]:n}))}).catch(e=>{if(!i())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&v&&t!==v){Te(v,t),qe(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),qe(e=>({...e,[t]:n}))}).finally(()=>{i()&&(Ze.current=new Map(Ze.current),Ze.current.delete(t),Ye.current=new Set(Ye.current),Ye.current.delete(t))})},[r,br,Te,v]),Sr=Q.useCallback(async()=>{v&&(Je.current=new Set,Ye.current=new Set,Ze.current=new Map,qe({}),Ge(e=>Object.keys(e).length===0?e:{}),await xr(v))},[xr,v]),Cr=Q.useCallback(async e=>{if(!e){await Sr();return}let t=qf(e);Je.current=new Set(Je.current),Je.current.delete(t),Ye.current=new Set(Ye.current),Ye.current.delete(t),await xr(t)},[xr,Sr]),wr=Q.useRef(``),Tr=Q.useRef(``);Q.useEffect(()=>{if(!v)return;let e=`${v}|h${h?`1`:`0`}|g${g?`1`:`0`}`,t=wr.current!==v,n=Tr.current!==e;!t&&!n||(t&&(wr.current=v,at(``),pt(null),ht(``),vt(null),k(!1)),n&&(Tr.current=e,Je.current=new Set,Ye.current=new Set,Ze.current=new Map,qe({}),Ge(e=>Object.keys(e).length===0?e:{}),xr(v)))},[xr,v,g,h]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&xe.length>0)for(let e of xe)Cr(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[xe,r.listDirectory,Cr]);let Er=Q.useCallback(async e=>{if(e?.preventDefault(),!rn||!tn)return;ln(!0);let t=()=>{nn(null)},i=e=>{J.error(e)},a=()=>{ln(!1)};if(tn===`createFile`){if(!on.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=rn.path,o=qf(`${e?`${e}/`:``}${on.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.fileCreated`)),await Cr(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`createFolder`){if(!on.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=rn.path,o=qf(`${e?`${e}/`:``}${on.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.folderCreated`)),await Cr(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`rename`){if(!on.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=rn.path,o=e.split(`/`).slice(0,-1).join(`/`),s=qf(`${o?`${o}/`:``}${on.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await Cr(o),v&&we(v,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(v&&Ee(v,null),at(``),pt(null),ht(``),vt(null),u&&k(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=rn.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await Cr(o),v&&we(v,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(v&&Ee(v,null),at(``),pt(null),ht(``),vt(null),u&&k(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[tn,rn,on,r,Cr,u,we,v,q?.path,Ee,n]);Q.useEffect(()=>{if(!_){tt([]),rt(!1);return}let e=E.trim();if(!e){tt([]),rt(!1);return}let t=!1;return rt(!0),S(_,e,150,{includeHidden:h,respectGitignore:!g,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>g||!rp(e.path)).map(e=>({name:e.name,path:qf(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));tt(n)}).catch(()=>{t||tt([])}).finally(()=>{t||rt(!1)}),()=>{t=!0}},[_,E,S,h,g]);let Dr=Q.useCallback(async(e,t)=>{if(r.readFile)return(await r.readFile(e,{...t??{},directory:v||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`),v&&i.set(`directory`,v);let a=await V(`/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,v,n]),Or=Q.useCallback(async(e,t)=>{if(r.statFile){let n=await r.statFile(e,{...t??{},directory:v||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[r,v]);Q.useEffect(()=>{if(!v||!r.statFile||ye.length===0)return;let e=!1,t=[...ye];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:v||void 0});!e&&n&&!n.isFile&&we(v,t)}catch(n){!e&&ap(n)&&we(v,t)}})),()=>{e=!0}},[r,ye,we,v]);let kr=Q.useMemo(()=>it.length>op?`${it.slice(0,op)}\n\n… truncated …`:it,[it]),Ar=yt!==kr,jr=Q.useCallback(async()=>{if(!q||!r.writeFile)return J.error(n(`filesView.toast.savingNotSupported`)),!1;if(!Ar)return!0;if(yt===``&&it!==``&&_t!==q.path)return console.warn(`[saveDraft] refusing to save empty draft for "${q.path}" (${it.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;St(!0);try{let e=up(yt,Ct);return(await r.writeFile(q.path,e))?.success?(at(yt),q?.path&&Fo(q.path)&&(kt.current=yt,At.current=yt),Or(q.path).then(e=>{e&&(Nt.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{St(!1)}},[yt,it,r,Ar,Ct,_t,Or,q,n]);Q.useEffect(()=>{if(!Ar){Wn(null);return}let e=e=>Kt.current?(Kt.current=!1,!0):(Ht(!0),Wt.current=e,!1);return Wn(e),()=>{p.getState().mainTabGuard===e&&Wn(null)}},[Ar,Wn]),Q.useEffect(()=>{try{window.localStorage.setItem(sp,zt?`true`:`false`)}catch{}},[zt]),Q.useEffect(()=>{zt||(It(`idle`),Dt.current&&=(clearTimeout(Dt.current),null))},[zt]);let Mr=1500;Q.useEffect(()=>{let e=!!(q&&r.writeFile);if(!(!zt||!Ar||!e||xt))return Dt.current=setTimeout(()=>{jr().then(e=>{e&&(It(`saved`),setTimeout(()=>It(`idle`),2e3))})},Mr),()=>{Dt.current&&=(clearTimeout(Dt.current),null)}},[zt,yt,Ar,q,r.writeFile,xt,jr]),Q.useEffect(()=>{It(`idle`)},[q?.path]),Q.useEffect(()=>{let e=e=>{$n(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Dt.current&&=(clearTimeout(Dt.current),null),xt||jr().then(e=>{e&&(It(`saved`),setTimeout(()=>It(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),F(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[xt,jr]);let Nr=Q.useCallback(async t=>{let r=Pt.current+1;Pt.current=r;let i=()=>{if(!v)return!1;let e=Vo.getState().byRoot[v],n=e?.selectedPath??e?.openPaths[0]??null;return Pt.current===r&&n===t.path};pt(null),ht(``),vt(null);let o=Po(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=No(t.path);if(u&&k(!0),a.isDesktop&&o&&!s){at(``),bt(``),ut(!0);return}if(!a.isDesktop&&o&&!s){at(``),bt(``),vt(t.path),ut(!1);return}if(c){at(``),bt(``),vt(t.path),ut(!1);return}ut(!0);let l=zo(t.path),d={allowOutsideWorkspace:e===`editor-only`&&!!v&&!Xf(t.path,v),outsideFileGrant:l};await Dr(t.path,d).then(e=>{if(!i())return;let n=lp(e);Tt(cp(e)),at(n),kt.current=n,At.current=n,bt(n.length>op?`${n.slice(0,op)}\n\n… truncated …`:n),vt(t.path),Or(t.path,d).then(e=>{e&&i()&&(Nt.current=e)}).catch(()=>{})}).catch(e=>{if(i()){if(ip(e)){if(ut(!1),v&&Ee(v,null),pt(null),at(``),bt(``),vt(null),Nt.current=null,w.trim().length>0&&T(``),u&&k(!1),v){let e=[...Zf(t.path,v),t.path];e.length>0&&Oe(v,e);for(let t of e)Je.current.has(t)||xr(t)}return}if(ap(e)){v&&we(v,t.path),at(``),bt(``),pt(null),Nt.current=null,u&&k(!1);return}at(``),bt(``),pt(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),Nt.current=null}}).finally(()=>{i()&&ut(!1)})},[Oe,u,xr,e,Dr,Or,we,v,a.isDesktop,w,Ee,n]),Pr=Q.useCallback(async(e,t)=>{if(!v)return;let n=Zf(e,v),r=t?[...n,e]:n;r.length>0&&Oe(v,r);let i=r.map(e=>{if(!Je.current.has(e))return xr(e)}).filter(Boolean);await Promise.all(i)},[Oe,xr,v]),Fr=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},[]),Ir=Q.useCallback(async e=>{if(Kt.current)Kt.current=!1;else if(Ar){Ht(!0),Ut.current=e;return}v&&(Ee(v,e.path),Se(v,e.path),Pr(e.path,!1)),pt(null),ht(``),at(``),kt.current=``,At.current=``,bt(``),vt(null),u&&k(!0)},[Se,Pr,Ar,u,v,Ee]);Q.useEffect(()=>{q?.path&&Pr(q.path,!1)},[Pr,q?.path]),Q.useEffect(()=>{if(!q){Pt.current+=1,ut(!1);return}_t!==q.path&&Nr(q)},[Nr,_t,q]);let Lr=Q.useRef(Ar);Lr.current=Ar,Q.useEffect(()=>{let e=q?.path??``;if(!_p(t,e,_t))return;let n=!1,r=window.setInterval(()=>{document.hidden||Or(e,Le).then(t=>{if(n||!t)return;let r=Nt.current;if(!r||r.path!==e){Nt.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Lr.current||(Nt.current=t,vt(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,_t,Or,q?.path,Le]);let Rr=Q.useCallback(()=>{let e=Ut.current,t=Wt.current,n=Gt.current;if(Ut.current=null,Wt.current=null,Gt.current=null,Kt.current=!0,Ht(!1),bt(kr),n){v&&Ce(v,n),q?.path===n&&(e?Ir(e):(v&&Ee(v,null),at(``),pt(null),ht(``),vt(null),u&&k(!1)));return}if(e){Ir(e);return}t&&(Wn(null),p.getState().setActiveMainTab(t))},[kr,Ir,u,Ce,v,q?.path,Wn,Ee]),zr=Q.useCallback(async()=>{let e=Ut.current,t=Wt.current,n=Gt.current;if(!await jr()){Kt.current=!1;return}if(Ut.current=null,Wt.current=null,Gt.current=null,Kt.current=!0,Ht(!1),n){v&&Ce(v,n),q?.path===n&&(e?await Ir(e):(v&&Ee(v,null),at(``),pt(null),ht(``),vt(null),u&&k(!1)));return}if(e){await Ir(e);return}t&&(Wn(null),p.getState().setActiveMainTab(t))},[Ir,u,Ce,v,jr,q?.path,Wn,Ee]),Br=Q.useCallback(e=>{let t=q?.path===e,n=Fr(e,je);if(t&&Ar){Ht(!0),Ut.current=n,Gt.current=e;return}if(v&&Ce(v,e),t){if(n){Ir(n);return}v&&Ee(v,null),at(``),pt(null),ht(``),vt(null),u&&k(!1)}},[Fr,Ir,Ar,u,je,Ce,v,q?.path,Ee]),Vr=Q.useCallback(e=>{if(ye.includes(e))return`open`;if(C?.files){let t=e.startsWith(v+`/`)?e.slice(v.length+1):e,n=C.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},[ye,C,v]),Hr=Q.useCallback(e=>{if(!C?.files)return null;let t=e.startsWith(v+`/`)?e.slice(v.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of C.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},[C,v]),Ur=Q.useCallback(async e=>{let t=qf(e);v&&(De(v,t),Je.current.has(t)||await xr(t))},[xr,v,De]),Wr=Q.useMemo(()=>Array.from(new Set(Object.values(We).flatMap(e=>e.filter(e=>e.type===`directory`).map(e=>e.path)))),[We]),Gr=Q.useMemo(()=>new Set(xe.map(e=>qf(e))),[xe]),Kr=Wr.length>0&&Wr.every(e=>Gr.has(qf(e))),qr=Q.useCallback(()=>{if(v){if(Kr){Te(v,v);return}Oe(v,Wr.map(e=>qf(e)))}},[Kr,Wr,Oe,Te,v]),Jr=Q.useMemo(()=>({canRename:On,canCreateFile:En,canCreateFolder:Dn,canDelete:kn,canReveal:An}),[On,En,Dn,kn,An]);function Yr(e,t){let i=We[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Gr.has(qf(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)(hp,{node:e,root:v,isExpanded:s,isActive:c,isMobile:u,alwaysShowActions:m,status:o?void 0:Vr(e.path),badge:o?Hr(e.path):void 0,permissions:Jr,downloadFile:r.downloadFile,contextMenuPath:un,setContextMenuPath:dn,rightClickMenuPath:fn,setRightClickMenuPath:pn,onSelect:Ir,onToggle:Ur,onRevealPath:Fn,onOpenDialog:Ln}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[Ke[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:Ke[e.path],children:Ke[e.path]}),(0,$.jsxs)(Z,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void Cr(e.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):null,Yr(e.path,t+1)]})]},e.path)})}let Xr=!!(q?.path&&Po(q.path)),Zr=!!(q?.path&&q.path.toLowerCase().endsWith(`.svg`)),Qr=!!(q?.path&&No(q.path)),$r=Q.useMemo(()=>qf(Gn?.path??``),[Gn?.path]),ei=!!(Gn&&$r&&Pe&&Pe===$r&&!lt&&!ft&&!Xr&&!Qr),ti=Q.useMemo(()=>Qf(v,Pe),[Pe,v]),ni=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(xn(e=>e===t?e:t),!t){Cn(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Cn({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),ri=Q.useCallback(()=>{let e=Yt.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}`;wn(q.path,o,n),Tn(G(o),`append-inline`),Cn(null),p.getState().setActiveMainTab(`chat`)},[wn,q,Tn]),ii=Q.useCallback(e=>{if(!q)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=yt.split(`
|
|
15
|
+
`)},[]),{drafts:rr,commentText:ir,setCommentText:dr,editingDraftId:fr,setSelection:pr,saveComment:mr,cancel:hr,reset:gr,startEdit:_r,deleteDraft:vr}=Bs({source:`file`,fileLabel:q?.path??null,language:q?.path&&Lo(q.path)||`text`,getCodeForRange:e=>nr(it,Ks(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{zn(null),gr(),Wn(null),yt(``),xt(!1)},[q?.path,gr,Wn]),Q.useEffect(()=>{pr(Rn)},[Rn,pr]),Q.useEffect(()=>{if(!Rn&&!fr)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]`)||ir.trim()||(zn(null),hr())},t=setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{clearTimeout(t),document.removeEventListener(`click`,e)}},[hr,ir,fr,Rn]);let yr=Q.useCallback((e,t)=>{let n=t??Rn??void 0;t&&zn(t),mr(e,n),zn(null)},[Rn,mr]),br=Q.useCallback((e,t)=>{let n=[];for(let r of t){if(!(r&&typeof r.name==`string`&&r.name.length>0)||!h&&r.name.startsWith(`.`)||!g&&rp(r.name))continue;let t=r.name,i=Jf(r.path||``),a=i?Yf(i)?i:Jf(`${e}/${i}`):Jf(`${e}/${t}`),o=r.isDirectory?`directory`:`file`,s=o===`file`&&t.includes(`.`)?t.split(`.`).pop()?.toLowerCase():void 0;n.push({name:t,path:a,type:o,extension:s})}return qf(n)},[g,h]),xr=Q.useCallback(async e=>{let t=Jf(e.trim());if(!t||Je.current.has(t)||Ye.current.has(t))return;Ye.current=new Set(Ye.current),Ye.current.add(t);let n=Qe.current+1;Qe.current=n,Ze.current=new Map(Ze.current),Ze.current.set(t,n);let i=()=>Ze.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}))):Ne.listLocalDirectory(t).then(e=>e.map(e=>({name:e.name,path:e.path,isDirectory:e.isDirectory})))).then(e=>{if(!i())return;let n=br(t,e);Je.current=new Set(Je.current),Je.current.add(t),qe(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),Ge(e=>({...e,[t]:n}))}).catch(e=>{if(!i())return;let n=e instanceof Error?e.message:String(e??``);if(n===`Directory not found`&&v&&t!==v){Te(v,t),qe(e=>{if(!e[t])return e;let n={...e};return delete n[t],n});return}console.error(`Failed to load files directory:`,e),qe(e=>({...e,[t]:n}))}).finally(()=>{i()&&(Ze.current=new Map(Ze.current),Ze.current.delete(t),Ye.current=new Set(Ye.current),Ye.current.delete(t))})},[r,br,Te,v]),Sr=Q.useCallback(async()=>{v&&(Je.current=new Set,Ye.current=new Set,Ze.current=new Map,qe({}),Ge(e=>Object.keys(e).length===0?e:{}),await xr(v))},[xr,v]),Cr=Q.useCallback(async e=>{if(!e){await Sr();return}let t=Jf(e);Je.current=new Set(Je.current),Je.current.delete(t),Ye.current=new Set(Ye.current),Ye.current.delete(t),await xr(t)},[xr,Sr]),wr=Q.useRef(``),Tr=Q.useRef(``);Q.useEffect(()=>{if(!v)return;let e=`${v}|h${h?`1`:`0`}|g${g?`1`:`0`}`,t=wr.current!==v,n=Tr.current!==e;!t&&!n||(t&&(wr.current=v,at(``),ft(null),mt(``),_t(null),k(!1)),n&&(Tr.current=e,Je.current=new Set,Ye.current=new Set,Ze.current=new Map,qe({}),Ge(e=>Object.keys(e).length===0?e:{}),xr(v)))},[xr,v,g,h]),Q.useEffect(()=>{if(!r.listDirectory)return;let e=()=>{if(!document.hidden&&xe.length>0)for(let e of xe)Cr(e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[xe,r.listDirectory,Cr]);let Er=Q.useCallback(async e=>{if(e?.preventDefault(),!rn||!tn)return;ln(!0);let t=()=>{nn(null)},i=e=>{J.error(e)},a=()=>{ln(!1)};if(tn===`createFile`){if(!on.trim()){i(n(`sidebarFilesTree.toast.filenameRequired`)),a();return}if(!r.writeFile){i(n(`sidebarFilesTree.toast.writeNotSupported`)),a();return}let e=rn.path,o=Jf(`${e?`${e}/`:``}${on.trim()}`);await r.writeFile(o,``).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.fileCreated`)),await Cr(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`createFolder`){if(!on.trim()){i(n(`sidebarFilesTree.toast.folderNameRequired`)),a();return}let e=rn.path,o=Jf(`${e?`${e}/`:``}${on.trim()}`);await r.createDirectory(o).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.folderCreated`)),await Cr(e)),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`rename`){if(!on.trim()){i(n(`sidebarFilesTree.toast.nameRequired`)),a();return}if(!r.rename){i(n(`sidebarFilesTree.toast.renameNotSupported`)),a();return}let e=rn.path,o=e.split(`/`).slice(0,-1).join(`/`),s=Jf(`${o?`${o}/`:``}${on.trim()}`);await r.rename(e,s).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.renamedSuccessfully`)),await Cr(o),v&&we(v,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(v&&Ee(v,null),at(``),ft(null),mt(``),_t(null),u&&k(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}if(tn===`delete`){if(!r.delete){i(n(`sidebarFilesTree.toast.deleteNotSupported`)),a();return}let e=rn.path,o=e.split(`/`).slice(0,-1).join(`/`);await r.delete(e).then(async r=>{r.success&&(J.success(n(`sidebarFilesTree.toast.deletedSuccessfully`)),await Cr(o),v&&we(v,e),(q?.path===e||q?.path.startsWith(`${e}/`))&&(v&&Ee(v,null),at(``),ft(null),mt(``),_t(null),u&&k(!1))),t()}).catch(()=>i(n(`sidebarFilesTree.toast.operationFailed`))).finally(a);return}a()},[tn,rn,on,r,Cr,u,we,v,q?.path,Ee,n]);Q.useEffect(()=>{if(!_){tt([]),rt(!1);return}let e=E.trim();if(!e){tt([]),rt(!1);return}let t=!1;return rt(!0),S(_,e,150,{includeHidden:h,respectGitignore:!g,type:`file`}).then(e=>{if(t)return;let n=e.filter(e=>g||!ip(e.path)).map(e=>({name:e.name,path:Jf(e.path),type:`file`,extension:e.extension,relativePath:e.relativePath}));tt(n)}).catch(()=>{t||tt([])}).finally(()=>{t||rt(!1)}),()=>{t=!0}},[_,E,S,h,g]);let Dr=Q.useCallback(async(e,t)=>{if(r.readFile)return(await r.readFile(e,{...t??{},directory:v||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`),v&&i.set(`directory`,v);let a=await V(`/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,v,n]),Or=Q.useCallback(async(e,t)=>{if(r.statFile){let n=await r.statFile(e,{...t??{},directory:v||void 0});return{path:n.path,size:n.size,mtimeMs:n.mtimeMs}}return null},[r,v]);Q.useEffect(()=>{if(!v||!r.statFile||ye.length===0)return;let e=!1,t=[...ye];return Promise.all(t.map(async t=>{try{let n=await r.statFile?.(t,{directory:v||void 0});!e&&n&&!n.isFile&&we(v,t)}catch(n){!e&&op(n)&&we(v,t)}})),()=>{e=!0}},[r,ye,we,v]);let kr=Q.useMemo(()=>it.length>sp?`${it.slice(0,sp)}\n\n… truncated …`:it,[it]),Ar=vt!==kr,jr=Q.useCallback(async()=>{if(!q||!r.writeFile)return J.error(n(`filesView.toast.savingNotSupported`)),!1;if(!Ar)return!0;if(vt===``&&it!==``&>!==q.path)return console.warn(`[saveDraft] refusing to save empty draft for "${q.path}" (${it.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;xt(!0);try{let e=dp(vt,St);return(await r.writeFile(q.path,e))?.success?(at(vt),q?.path&&Io(q.path)&&(Dt.current=vt,Ot.current=vt),Or(q.path).then(e=>{e&&(jt.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{xt(!1)}},[vt,it,r,Ar,St,gt,Or,q,n]);Q.useEffect(()=>{if(!Ar){Wn(null);return}let e=e=>Kt.current?(Kt.current=!1,!0):(Vt(!0),Wt.current=e,!1);return Wn(e),()=>{p.getState().mainTabGuard===e&&Wn(null)}},[Ar,Wn]),Q.useEffect(()=>{try{window.localStorage.setItem(cp,Rt?`true`:`false`)}catch{}},[Rt]),Q.useEffect(()=>{Rt||(Pt(`idle`),Tt.current&&=(clearTimeout(Tt.current),null))},[Rt]);let Mr=1500;Q.useEffect(()=>{let e=!!(q&&r.writeFile);if(!(!Rt||!Ar||!e||bt))return Tt.current=setTimeout(()=>{jr().then(e=>{e&&(Pt(`saved`),setTimeout(()=>Pt(`idle`),2e3))})},Mr),()=>{Tt.current&&=(clearTimeout(Tt.current),null)}},[Rt,vt,Ar,q,r.writeFile,bt,jr]),Q.useEffect(()=>{Pt(`idle`)},[q?.path]),Q.useEffect(()=>{let e=e=>{tr(e)&&(e.key.toLowerCase()===`s`?(e.preventDefault(),Tt.current&&=(clearTimeout(Tt.current),null),bt||jr().then(e=>{e&&(Pt(`saved`),setTimeout(()=>Pt(`idle`),2e3))})):e.key.toLowerCase()===`f`&&(e.preventDefault(),F(!0)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[bt,jr]);let Nr=Q.useCallback(async t=>{let r=Mt.current+1;Mt.current=r;let i=()=>{if(!v)return!1;let e=Ho.getState().byRoot[v],n=e?.selectedPath??e?.openPaths[0]??null;return Mt.current===r&&n===t.path};ft(null),mt(``),_t(null);let o=Fo(t.path),s=t.path.toLowerCase().endsWith(`.svg`),c=Po(t.path);if(u&&k(!0),a.isDesktop&&o&&!s){at(``),yt(``),ut(!0);return}if(!a.isDesktop&&o&&!s){at(``),yt(``),_t(t.path),ut(!1);return}if(c){at(``),yt(``),_t(t.path),ut(!1);return}ut(!0);let l=Bo(t.path),d={allowOutsideWorkspace:e===`editor-only`&&!!v&&!Zf(t.path,v),outsideFileGrant:l};await Dr(t.path,d).then(e=>{if(!i())return;let n=up(e);Ct(lp(e)),at(n),Dt.current=n,Ot.current=n,yt(n.length>sp?`${n.slice(0,sp)}\n\n… truncated …`:n),_t(t.path),Or(t.path,d).then(e=>{e&&i()&&(jt.current=e)}).catch(()=>{})}).catch(e=>{if(i()){if(ap(e)){if(ut(!1),v&&Ee(v,null),ft(null),at(``),yt(``),_t(null),jt.current=null,w.trim().length>0&&T(``),u&&k(!1),v){let e=[...Qf(t.path,v),t.path];e.length>0&&Oe(v,e);for(let t of e)Je.current.has(t)||xr(t)}return}if(op(e)){v&&we(v,t.path),at(``),yt(``),ft(null),jt.current=null,u&&k(!1);return}at(``),yt(``),ft(e instanceof Error?e.message:n(`filesView.error.readFileFailed`)),jt.current=null}}).finally(()=>{i()&&ut(!1)})},[Oe,u,xr,e,Dr,Or,we,v,a.isDesktop,w,Ee,n]),Pr=Q.useCallback(async(e,t)=>{if(!v)return;let n=Qf(e,v),r=t?[...n,e]:n;r.length>0&&Oe(v,r);let i=r.map(e=>{if(!Je.current.has(e))return xr(e)}).filter(Boolean);await Promise.all(i)},[Oe,xr,v]),Fr=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},[]),Ir=Q.useCallback(async e=>{if(Kt.current)Kt.current=!1;else if(Ar){Vt(!0),Ht.current=e;return}v&&(Ee(v,e.path),Se(v,e.path),Pr(e.path,!1)),ft(null),mt(``),at(``),Dt.current=``,Ot.current=``,yt(``),_t(null),u&&k(!0)},[Se,Pr,Ar,u,v,Ee]);Q.useEffect(()=>{q?.path&&Pr(q.path,!1)},[Pr,q?.path]),Q.useEffect(()=>{if(!q){Mt.current+=1,ut(!1);return}gt!==q.path&&Nr(q)},[Nr,gt,q]);let Lr=Q.useRef(Ar);Lr.current=Ar,Q.useEffect(()=>{let e=q?.path??``;if(!vp(t,e,gt))return;let n=!1,r=window.setInterval(()=>{document.hidden||Or(e,Le).then(t=>{if(n||!t)return;let r=jt.current;if(!r||r.path!==e){jt.current=t;return}let i=t.mtimeMs!==void 0&&r.mtimeMs!==void 0&&t.mtimeMs!==r.mtimeMs,a=t.size!==r.size;!i&&!a||Lr.current||(jt.current=t,_t(null))}).catch(()=>{})},2e3);return()=>{n=!0,window.clearInterval(r)}},[t,gt,Or,q?.path,Le]);let Rr=Q.useCallback(()=>{let e=Ht.current,t=Wt.current,n=Gt.current;if(Ht.current=null,Wt.current=null,Gt.current=null,Kt.current=!0,Vt(!1),yt(kr),n){v&&Ce(v,n),q?.path===n&&(e?Ir(e):(v&&Ee(v,null),at(``),ft(null),mt(``),_t(null),u&&k(!1)));return}if(e){Ir(e);return}t&&(Wn(null),p.getState().setActiveMainTab(t))},[kr,Ir,u,Ce,v,q?.path,Wn,Ee]),zr=Q.useCallback(async()=>{let e=Ht.current,t=Wt.current,n=Gt.current;if(!await jr()){Kt.current=!1;return}if(Ht.current=null,Wt.current=null,Gt.current=null,Kt.current=!0,Vt(!1),n){v&&Ce(v,n),q?.path===n&&(e?await Ir(e):(v&&Ee(v,null),at(``),ft(null),mt(``),_t(null),u&&k(!1)));return}if(e){await Ir(e);return}t&&(Wn(null),p.getState().setActiveMainTab(t))},[Ir,u,Ce,v,jr,q?.path,Wn,Ee]),Br=Q.useCallback(e=>{let t=q?.path===e,n=Fr(e,je);if(t&&Ar){Vt(!0),Ht.current=n,Gt.current=e;return}if(v&&Ce(v,e),t){if(n){Ir(n);return}v&&Ee(v,null),at(``),ft(null),mt(``),_t(null),u&&k(!1)}},[Fr,Ir,Ar,u,je,Ce,v,q?.path,Ee]),Vr=Q.useCallback(e=>{if(ye.includes(e))return`open`;if(C?.files){let t=e.startsWith(v+`/`)?e.slice(v.length+1):e,n=C.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},[ye,C,v]),Hr=Q.useCallback(e=>{if(!C?.files)return null;let t=e.startsWith(v+`/`)?e.slice(v.length+1):e,n=t?`${t}/`:``,r=0,i=0;for(let e of C.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},[C,v]),Ur=Q.useCallback(async e=>{let t=Jf(e);v&&(De(v,t),Je.current.has(t)||await xr(t))},[xr,v,De]),Wr=Q.useMemo(()=>Array.from(new Set(Object.values(We).flatMap(e=>e.filter(e=>e.type===`directory`).map(e=>e.path)))),[We]),Gr=Q.useMemo(()=>new Set(xe.map(e=>Jf(e))),[xe]),Kr=Wr.length>0&&Wr.every(e=>Gr.has(Jf(e))),qr=Q.useCallback(()=>{if(v){if(Kr){Te(v,v);return}Oe(v,Wr.map(e=>Jf(e)))}},[Kr,Wr,Oe,Te,v]),Jr=Q.useMemo(()=>({canRename:On,canCreateFile:En,canCreateFolder:Dn,canDelete:kn,canReveal:An}),[On,En,Dn,kn,An]);function Yr(e,t){let i=We[e]??[];return i.map((e,a)=>{let o=e.type===`directory`,s=o&&Gr.has(Jf(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)(gp,{node:e,root:v,isExpanded:s,isActive:c,isMobile:u,alwaysShowActions:m,status:o?void 0:Vr(e.path),badge:o?Hr(e.path):void 0,permissions:Jr,downloadFile:r.downloadFile,contextMenuPath:un,setContextMenuPath:dn,rightClickMenuPath:fn,setRightClickMenuPath:pn,onSelect:Ir,onToggle:Ur,onRevealPath:Fn,onOpenDialog:Ln}),o&&s&&(0,$.jsxs)(`ul`,{className:`flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative`,children:[Ke[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:Ke[e.path],children:Ke[e.path]}),(0,$.jsxs)(Z,{variant:`ghost`,size:`xs`,className:`h-6 gap-1`,onClick:()=>void Cr(e.path),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):null,Yr(e.path,t+1)]})]},e.path)})}let Xr=!!(q?.path&&Fo(q.path)),Zr=!!(q?.path&&q.path.toLowerCase().endsWith(`.svg`)),Qr=!!(q?.path&&Po(q.path)),$r=Q.useMemo(()=>Jf(Gn?.path??``),[Gn?.path]),ei=!!(Gn&&$r&&Pe&&Pe===$r&&!lt&&!dt&&!Xr&&!Qr),ti=Q.useMemo(()=>$f(v,Pe),[Pe,v]),ni=Q.useCallback(e=>{let t=!e.state.selection.main.empty;if(xn(e=>e===t?e:t),!t){Cn(null);return}let n=e.state.selection.main,r=e.state.doc.lineAt(n.from).from,i=e.coordsAtPos(r);i&&Cn({x:Math.min(window.innerWidth-240,Math.max(8,i.left)),y:Math.max(8,i.top-8)})},[]),ri=Q.useCallback(()=>{let e=Yt.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}`;wn(q.path,o,n),Tn(G(o),`append-inline`),Cn(null),p.getState().setActiveMainTab(`chat`)},[wn,q,Tn]),ii=Q.useCallback(e=>{if(!q)return;let t=Math.min(e.start,e.end),n=Math.max(e.start,e.end),r=vt.split(`
|
|
16
16
|
`).slice(t-1,n).join(`
|
|
17
|
-
`);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${q.name}:${i}`;wn(q.path,a,r),Tn(G(a),`append-inline`),p.getState().setActiveMainTab(`chat`)},[wn,yt,q,Tn]),ai=!!(q&&(!Xr||Zr)&&!Qr&&it.length>0),oi=!!(q&&ti.length>0),si=!!(q&&!Fe&&!Xr&&!Qr&&r.writeFile&&it.length<=op),ci=!!(q?.path&&pp(q.path)),li=!!(q?.path&&mp(q.path)),ui=!!(q?.path&&Fo(q.path)),di=!!(q&&!Xr&&!Qr),fi=di&&!ci&&!ui&&!(li&&oe===`preview`),pi=ci&&ie===`edit`||li&&oe===`edit`||!ci&&!li&&re===`edit`,mi=Q.useMemo(()=>Pe?xa(Pe):null,[Pe]),[hi,gi]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=q?.path;if(!t||mi){gi(null);return}return gi(null),ma(t).then(t=>{e||gi(t)}),()=>{e=!0}},[q?.path,mi]),Q.useEffect(()=>{!si&&re===`edit`&&K(`view`)},[si,re]);let _i=`openchamber:files:md-viewer-mode`,vi=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=q?.path;if(!e)return;K(fe.current[e]??`edit`);let t=Qn?`preview`:`edit`;try{let e=localStorage.getItem(_i);(e===`preview`||e===`edit`)&&(t=e)}catch{}ae(pe.current[e]??t);let n=Qn?`preview`:`edit`;try{let e=localStorage.getItem(vi);(e===`preview`||e===`edit`)&&(n=e)}catch{}se(me.current[e]??n),le(he.current[e]??(Qn?`preview`:`edit`))},[q?.path,Qn]);let yi=Q.useCallback(e=>{let t=q?.path;t&&(fe.current[t]=e),K(e)},[q?.path]),xi=Q.useCallback(e=>{let t=q?.path;t&&(pe.current[t]=e),ae(e);try{localStorage.setItem(_i,e)}catch{}},[q?.path]),Si=Q.useCallback(()=>ie,[ie]),Ci=Q.useCallback(e=>{let t=q?.path;t&&(me.current[t]=e),se(e);try{localStorage.setItem(vi,e)}catch{}},[q?.path]),wi=Q.useCallback(e=>{let t=q?.path;if(t&&(he.current[t]=e),Ot.current&&=(clearTimeout(Ot.current),null),jt.current!==null&&(cancelAnimationFrame(jt.current),jt.current=null),e===`edit`)bt(kt.current||it),le(e);else{kt.current=yt;let e=t;le(`edit`),jt.current=requestAnimationFrame(()=>{jt.current=requestAnimationFrame(()=>{jt.current=null,!(v&&e&&Vo.getState().byRoot[v]?.selectedPath!==e)&&(de(e=>e+1),le(`preview`))})});return}},[yt,it,v,q?.path]),Ti=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===At.current)return!1;if(!(await r.writeFile(e,t))?.success)return J.error(n(`filesView.toast.writeFileFailed`)),!1;kt.current=t,At.current=t,bt(t);let i=await Or(e,Le).catch(()=>null);return i&&(Nt.current=i),!0},[r,Or,Le,n]);Q.useEffect(()=>()=>{Ot.current&&=(clearTimeout(Ot.current),null),jt.current!==null&&(cancelAnimationFrame(jt.current),jt.current=null)},[ce,q?.path]);let Ei=Q.useCallback(e=>{if(kt.current=e,!q?.path||ce!==`preview`||!r.writeFile)return;Ot.current&&clearTimeout(Ot.current);let t=q.path;Ot.current=setTimeout(()=>{Ot.current=null,Ti(t,e).then(e=>{e&&(Rt(!0),setTimeout(()=>Rt(!1),1500))}).catch(e=>{J.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Mr)},[ce,r.writeFile,Ti,q?.path,n]),Di=Q.useMemo(()=>ui&&(kt.current||yt)||it,[yt,it,ui]),Oi=Q.useCallback(()=>oe,[oe]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of ye)fe.current[e]=`edit`,pp(e)&&(pe.current[e]=t),mp(e)&&(me.current[e]=t),Fo(e)&&(he.current[e]=t);K(`edit`),ae(t),se(t),le(t);try{localStorage.setItem(_i,t),localStorage.setItem(vi,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)}},[ye]),Q.useEffect(()=>{if(!Gn||!v)return;let e=()=>{typeof window>`u`||$t.current===null&&($t.current=window.requestAnimationFrame(()=>{$t.current=null,Qt(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=qf(Gn.path);if(!n){Kn(null),en.current={key:``,attempts:0};return}let r=`${n}:${Gn.line}:${Gn.column??1}`;if(en.current.key!==r&&(en.current={key:r,attempts:0}),q?.path!==n){if(Vt)return;Ir(ke(n));return}if(lt||_t!==n)return;if(ft||Xr||Qr){Kn(null),en.current={key:``,attempts:0};return}if(!si)return;if(re!==`edit`){K(`edit`);return}let i=Yt.current;if(!i){e();return}if(!t(i,yt)){e();return}let a=Math.max(1,Math.min(Gn.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,Gn.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||en.current.attempts===0){en.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:Ue.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=Yt.current;e&&(e.dispatch({selection:{anchor:u},effects:Ue.scrollIntoView(u,{y:`center`})}),e.focus())}),Kn(null),en.current={key:``,attempts:0}},[si,Vt,yt,Zt,ft,lt,Xr,Qr,_t,Ir,Gn,v,q?.path,Kn,re,ke]),Q.useEffect(()=>{if(!qn||!v)return;let e=qf(qn);if(!e){Jn(null);return}if(q?.path!==e){if(Vt)return;Ir(ke(e));return}if(!(lt||_t!==e||ft||Xr||Qr)){if(si&&re===`edit`){let e=Yt.current;if(!e)return;e.focus()}Jn(null)}},[si,Vt,ft,lt,Ir,Xr,Qr,_t,qn,v,q?.path,Jn,re,ke]);let ki=Q.useCallback(e=>{if(!u||!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)},[u]);Q.useEffect(()=>{if(!u||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{ki(Yt.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)}},[u,ki]),Q.useEffect(()=>{if(re!==`edit`||u)return;let e=da(`open_go_to_line`,Yn),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(Sa(t,e)){t.preventDefault(),yn(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=Yt.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),ri())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[ri,u,Yn,re]);let Ai=p(e=>e.editorFontSize),ji=Q.useMemo(()=>{if(!q?.path)return[Ss(o,{fontSize:Ai})];let e=Io(q.path),t=[Ss(o,e?{syntaxColors:!1,fontSize:Ai}:{fontSize:Ai})],n=mi??hi;return n&&t.push(n),e&&t.push(ds({language:e,themeName:o.metadata.id,theme:mo(o)})),A&&t.push(Ue.lineWrapping),t.push(Ue.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&ni(e.view)})),u&&t.push(Ue.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{ki(e.view)})})),t},[o,q?.path,mi,hi,A,u,ki,Ai,ni]),Mi=Q.useMemo(()=>({light:ge.metadata.id,dark:_e.metadata.id}),[ge.metadata.id,_e.metadata.id]),Ni=q?.path&&Xr&&!a.isDesktop&&!Zr?`${q.path}|${Le.allowOutsideWorkspace?`outside`:`workspace`}|${Le.outsideFileGrant??``}`:``,Pi=q?.path&&Qr?`${q.path}|${Le.allowOutsideWorkspace?`outside`:`workspace`}|${Le.outsideFileGrant??``}`:``,Fi=q?.path&&li&&oe===`preview`&&!a.isVSCode?q.path:``,Ii=n(`filesView.error.readFileFailed`),{readyKey:Li,nonce:Vi}=vp(Ni,pt,Ii),{readyKey:Ui,nonce:Wi}=vp(Fi,pt,Ii),{readyKey:Gi,nonce:Ki}=vp(Pi,pt,Ii),qi=!!(Ni&&Li!==Ni),Ji=!!(Fi&&Ui!==Fi),Xi=!!(Pi&&Gi!==Pi),Zi=q?.path&&Xr?a.isDesktop?Zr?`data:${Mo(q.path)};utf8,${encodeURIComponent(it)}`:mt:Zr?`data:${Mo(q.path)};utf8,${encodeURIComponent(it)}`:Li===Ni?i().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||void 0}):``:``,ta=Q.useCallback(()=>{if(!q?.path||!Xr)return;let e=Zr?Zi:q.path||Zi;if(!e)return;let t=q.name||q.path;H({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:Mo(q.path)},image:{url:e,mimeType:Mo(q.path),filename:t}})},[Zi,Xr,Zr,q?.name,q?.path]),na=Q.useCallback(e=>{H(t=>t.open===e?t:{...t,open:e})},[]),ra=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:ta,"aria-label":r,disabled:!Zi,children:(0,$.jsx)(`img`,{src:Zi,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},Vi)})})},[Vi,Zi,ta,n]),ia=q?.path&&Qr&&Gi===Pi?i().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||void 0}):``,aa=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:ia,className:`h-full w-full border-0`,title:e.name},Ki)}),[ia,Ki]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!a.isDesktop||!q?.path||!Xr||Zr){gt.current&&=(URL.revokeObjectURL(gt.current),``),ht(``);return}pt(null),gt.current&&=(URL.revokeObjectURL(gt.current),``),await(r.readFileBinary?r.readFileBinary(q.path,Le).then(e=>e.dataUrl):(async()=>{let t=await V(`/api/fs/raw`,{query:{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||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),``):(gt.current=i,i)})()).then(t=>{e||(ht(t),vt(q.path))}).catch(t=>{gt.current&&=(URL.revokeObjectURL(gt.current),``),e||(ht(``),pt(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),vt(null))}).finally(()=>{e||ut(!1)})})(),()=>{e=!0}},[r,Xr,Zr,v,a.isDesktop,q?.path,Le,n]),Q.useEffect(()=>()=>{gt.current&&=(URL.revokeObjectURL(gt.current),``)},[]);let oa=Q.useCallback(()=>nn(null),[]),la=Q.useMemo(()=>Us({drafts:lr,editingDraftId:fr,commentText:ur,onTextChange:dr,selection:Rn,isDragging:Hn,fileLabel:q?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:yr,onCancel:()=>{zn(null),hr()},onEdit:e=>{_r(e),zn({start:e.startLine,end:e.endLine})},onDelete:vr,onAddToChat:ii}),[ii,hr,ur,vr,fr,lr,yr,Hn,Rn,q?.path,dr,_r]),ua=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(es,{file:{name:e.name,contents:t,lang:Io(e.path)||void 0},options:{disableFileHeader:!0,overflow:A?`wrap`:`scroll`,theme:Mi,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,Mi,A]),fa=({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)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(Bi,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[si&&pi&&(0,$.jsxs)($.Fragment,{children:[xt?(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`)]}):zt&&Ft===`saved`&&!Ar?(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`)]}):Ar?o(n(zt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${Zn()}+S`}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void jr(),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(zt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${Zn()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${Zn()}+S`}),children:(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})):null,o(n(zt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Bt(e=>!e),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,zt?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(zt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":n(zt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:zt?(0,$.jsx)(X,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(X,{name:`file-check`,className:`size-4`})}))]}),di&&bn?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:ri,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)(Va,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(ea,{onOpenChange:te,children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(sa,{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)(Bi,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)($i,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[jn.map(e=>(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>void In(e),children:[(0,$.jsx)(Gf,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),Mn?(0,$.jsxs)(ca,{className:`flex items-center gap-2`,onClick:()=>void Pn(!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]})]}),!Xr&&!Qr&&(0,$.jsxs)($.Fragment,{children:[o(n(A?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>j(!A),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,A?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(A?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(X,{name:`text-wrap`,className:`size-4`})})),re===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:e=>{F(!P),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=>{yn(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)(Hf,{open:vn,onOpenChange:yn,view:Yt.current,variant:`inline`})]})]}),fi&&si&&!li&&(0,$.jsx)(ss,{currentMode:re===`view`?`preview`:`edit`,onToggle:()=>{yi(re===`view`?`edit`:`view`)}}),ci&&o(n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>xi(Si()===`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)]`,Si()===`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(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Si()===`preview`?`eye`:`eye-off`,className:`size-4`})})),mp(q?.path??``)&&(0,$.jsx)(ss,{currentMode:Oi(),onToggle:()=>{Ci(Oi()===`preview`?`edit`:`preview`)}}),ci&&Si()===`preview`&&er&&(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{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(ot?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{ot?ct():it.trim()&&st(it)},children:ot?(0,$.jsx)(X,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(Bi,{sideOffset:8,children:n(ot?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),ui&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ss,{currentMode:ce,onToggle:()=>wi(ce===`preview`?`edit`:`preview`)}),ce===`preview`&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=Mt.current?.getXml();if(Ot.current&&=(clearTimeout(Ot.current),null),q?.path&&e){if(!await Ti(q.path,e))return;Rt(!0),setTimeout(()=>Rt(!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:Lt?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})]}),ai&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(it)).ok?(hn(!0),qt.current!==null&&window.clearTimeout(qt.current),qt.current=window.setTimeout(()=>{hn(!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:mn?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`clipboard`,className:`size-4`})})),oi&&o(n(`filesView.editor.copyFilePathTitle`,{path:ti}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(ti)).ok?(_n(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.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.copyFilePathTitle`,{path:ti}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:ti}),children:gn?(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:()=>N(!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`})})):!u&&e===`full`&&o(n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>N(!M),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:M?(0,$.jsx)(X,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(X,{name:`fullscreen`,className:`size-4`})}))]})},pa=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(cr,{open:Vt,onOpenChange:e=>{e||Ht(!0)},children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(or,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(sr,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(ir,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>void zr(),disabled:xt,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:Rr,children:n(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-col flex-shrink-0`,y&&`border-b border-border/40`),children:[y?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[u&&O&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>k(!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`})}),u?q?(0,$.jsxs)(ea,{children:[(0,$.jsx)(sa,{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)(Ba,{filePath:q.path,extension:q.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(tp,{name:q.name}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)($i,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:je.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(ca,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Ir(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)(Ba,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(tp,{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(),Br(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`)}):je.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[ze.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`}),ze.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:Re,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:je.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(`div`,{title:Qf(v,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)(Ba,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Ir(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),Br(e.path)},className:Y(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!m&&`opacity-0 group-hover:opacity-100`),"aria-label":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,tr&&!u&&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:[ti?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:ti,children:ti}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:fa({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[q&&!P&&!(tr&&!u)&&(0,$.jsx)(`div`,{ref:U,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{ee.current>0||L(!1)},children:I?fa():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ci?(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>xi(Si()===`preview`?`edit`:`preview`),className:Y(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Si()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Si()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(Bi,{side:`bottom`,sideOffset:6,children:n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>L(!0),children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>L(!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)(Bi,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(bi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:q?lt||qi||Xi?b?(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`)]}):ft?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:ft}):Xr&&q?ra(q):Qr?aa(q):q&&ui&&ce===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(Dc,{ref:Mt,xml:Di,onChange:Ei},`${q.path}:${ue}`)}):q&&ci&&Si()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(Yi,{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)(po,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):q&&li&&oe===`preview`?Ji?(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:!a.isVSCode&&Ui===Fi?(()=>{let e=q.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return i().authenticatedAsset(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`)})():void 0,srcDoc:a.isVSCode?(()=>{let e=q.path.substring(0,q.path.lastIndexOf(`/`)+1);return e?it.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):it})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},Wi)}):q&&fi&&re===`view`?ua(q,yt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,ei&&`overflow-hidden`),ref:Xt,children:[(0,$.jsx)(`div`,{className:Y(`h-full`,ei&&`invisible`),children:(0,$.jsx)(is,{value:yt,onChange:bt,readOnly:!si,vimMode:Xn===`vim`,extensions:ji,className:`h-full`,blockWidgets:la,onViewReady:e=>{Yt.current=e,ni(e),Qt(e=>e+1),window.requestAnimationFrame(()=>{ki(e)})},onViewDestroy:()=>{Yt.current&&=null,xn(!1),Cn(null),Qt(e=>e+1)},enableSearch:!0,searchOpen:P,onSearchOpenChange:F,highlightLines:Rn?{start:Math.min(Rn.start,Rn.end),end:Math.max(Rn.start,Rn.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(Rn&&!n.shiftKey&&Math.min(Rn.start,Rn.end)===r&&Math.max(Rn.start,Rn.end)===r)return zn(null),hr(),Bn.current=!1,Vn.current=null,Un(!1),!0;if(u&&Rn&&!n.shiftKey){let e=Math.min(Rn.start,Rn.end,r),t=Math.max(Rn.start,Rn.end,r);return zn({start:e,end:t}),Bn.current=!1,Vn.current=null,Un(!1),!0}if(Bn.current=!0,Vn.current=r,Un(!0),Rn&&n.shiftKey){let e=Math.min(Rn.start,r),t=Math.max(Rn.end,r);zn({start:e,end:t})}else zn({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Bn.current||Vn.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Vn.current,r),a=Math.max(Vn.current,r);return zn({start:i,end:a}),Un(!0),!1},mouseup:()=>(Bn.current=!1,Vn.current=null,Un(!1),!1)}}})}),ei&&(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`)})})]})]}),ha=!!(v&&We[v]),ga=v?Ke[v]:null,_a=(0,$.jsxs)(`section`,{className:Y(`flex min-h-0 flex-col overflow-hidden`,u?`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`,u?`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)(Ri,{ref:D,value:w,onChange:e=>T(e.target.value),placeholder:n(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),w.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:()=>{T(``),D.current?.focus()},children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Ln(`createFile`,{path:_,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)(Bi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Ln(`createFolder`,{path:_,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)(Bi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void Sr(),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)(Bi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:qr,disabled:Wr.length===0&&xe.length===0,className:`size-8 flex-shrink-0 p-0`,title:n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(X,{name:Kr?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(Bi,{side:`bottom`,sideOffset:6,children:n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(bi,{outerClassName:`flex-1 min-h-0`,className:Y(`py-2`,u?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:nt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):et.length>0?et.map(e=>{let t=q?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Ir(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:[fp(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)}):ga?(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:ga}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void Sr(),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):ha?Yr(v,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),va=e===`full`&&M&&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:fa({exitFullscreenOnly:!0})}),(0,$.jsx)(bi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:lt||qi||Xi?b?(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…`]}):ft?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:ft}):Xr?ra(q,{fullHeight:!0}):Qr?aa(q):ci&&Si()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(Yi,{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)(po,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):fi&&re===`view`?ua(q,yt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,ei&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:Y(`h-full`,ei&&`invisible`),children:(0,$.jsx)(is,{value:yt,onChange:bt,readOnly:!si,vimMode:Xn===`vim`,extensions:ji,className:`h-full`,onViewReady:e=>{Yt.current=e,ni(e),window.requestAnimationFrame(()=>{ki(e)})},onViewDestroy:()=>{Yt.current&&=null,xn(!1),Cn(null)}})}),ei&&(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)(gp,{activeDialog:tn,dialogData:rn,dialogInputValue:on,onDialogInputChange:sn,isDialogSubmitting:cn,onDialogSubmit:Er,onClose:oa,inputRef:Et}),va,Sn?(0,$.jsx)(Hs,{position:Sn,onAddToChat:ri}):null,R.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Uf,{popup:R,onOpenChange:na,isMobile:u})}):null,u?O?pa:_a: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:pa})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[f>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:_a}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:pa})]})]})};function bp(e){return e+1}var xp=(e,t)=>e.mode===`target`?`target`:t===e.repoPath?`repo`:`home`,Sp=e=>({optional:!0,...e?{directory:e}:{}}),Cp=async(e,t,n)=>{if(e?.readFile){let r=await e.readFile(t,Sp(n));if(typeof r.exists!=`boolean`)throw Error(`Plan file read returned an invalid exists contract`);return r.exists?r.content:null}let r=await V(`/api/fs/read`,{query:{path:t,optional:!0},cache:`no-store`,headers:n?{"x-opencode-directory":n}:void 0});if(!r.ok)throw Error(`Failed to read plan file (${r.status})`);let i=r.headers.get(`x-openchamber-file-exists`);if(i===`true`)return r.text();if(i===`false`)return null;throw Error(`Plan file read returned an invalid exists contract`)},wp=(e,t,r=n())=>{let i=e?.readFile?e:oe()?.files;return{queryKey:F.plans.resolved(t.mode,t.sessionId,t.scopeDirectory,t.targetPath,t.repoPath,t.homePath,r),queryFn:async()=>{if(t.mode===`target`){if(!t.targetPath)throw Error(`A target plan path is required`);let e=await Cp(i,t.targetPath,t.scopeDirectory);return e===null?{kind:`missing`,candidates:[t.targetPath]}:{kind:`resolved`,source:`target`,path:t.targetPath,content:e}}if(!t.repoPath||!t.homePath)throw Error(`Session plan candidates are required`);let e=await Cp(i,t.repoPath,t.scopeDirectory);if(e!==null)return{kind:`resolved`,source:`repo`,path:t.repoPath,content:e};let n=await Cp(i,t.homePath,t.scopeDirectory);return n===null?{kind:`missing`,candidates:[t.repoPath,t.homePath]}:{kind:`resolved`,source:`home`,path:t.homePath,content:n}}}},Tp=(e,t)=>{let r=(0,Rc.c)(9),i;r[0]===t?i=r[1]:(i=t===void 0?{}:t,r[0]=t,r[1]=i);let a=i,{files:o}=uo(),s,c;if(r[2]!==o||r[3]!==e){let t=n();c=Be,s=wp(o,e,t),r[2]=o,r[3]=e,r[4]=s,r[5]=c}else s=r[4],c=r[5];let l;return r[6]!==a||r[7]!==s?(l={...s,...a},r[6]=a,r[7]=s,r[8]=l):l=r[8],c(l)},Ep=(e,t,n,r)=>e.identity===t?e.content===e.baseContent&&!r?{...e,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``}:e:{identity:t,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``},Dp=e=>({persisted:e,desired:e,desiredRevision:0,nextAttemptToken:1,inFlight:null,failed:null}),Op=(e,t)=>e.desired===t?e:{...e,desired:t,desiredRevision:e.desiredRevision+1,failed:null},kp=e=>e.desired===e.persisted&&e.inFlight===null&&e.failed===null,Ap=(e,t,n)=>({identity:e,path:t,content:n.desired,baseContent:n.persisted}),jp=e=>{if(e.inFlight||e.desired===e.persisted||e.failed?.revision===e.desiredRevision)return[e,null];let t={content:e.desired,revision:e.desiredRevision,token:e.nextAttemptToken};return[{...e,inFlight:t,nextAttemptToken:t.token+1},t]},Mp=(e,t)=>e.inFlight?.token===t.token?{...e,persisted:t.content,inFlight:null,failed:e.failed&&e.failed.revision>t.revision?e.failed:null}:e,Np=(e,t,n)=>e.inFlight?.token===t.token?{...e,inFlight:null,failed:{revision:t.revision,error:n}}:e,Pp=e=>({...e,failed:null}),Fp=(e,t)=>e===t,Ip=(e,t,n)=>Fp(t,n)?jp(e):[e,null],Lp=e=>e.desired!==e.persisted||e.inFlight!==null,Rp=(e,t,n=32)=>{let r=[];for(let[i,a]of e){if(e.size<=n)return r;i!==t&&kp(a)&&(e.delete(i),r.push(i))}return r},zp=(e,t,n)=>{let r=e.get(t);r&&e.set(t,Mp(r,n))},Bp=(e,t,n,r)=>{let i=e.get(t);i&&e.set(t,Np(i,n,r))},Vp=(e,t)=>e&&t.path===null&&t.content===t.baseContent,Hp=(e,t)=>e&&t!==null,Up=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Wp=(e,t)=>{let n=Up(e),r=t.replace(/\\/g,`/`).replace(/^\/+/,``).replace(/\/+$/,``);return!n||n===`/`?`/${r}`:`${n}/${r}`},Gp=(e,t,n)=>Wp(Wp(Wp(e,`.opencode`),`plans`),`${t}-${n}.md`),Kp=(e,t)=>`~/.opencode/plans/${e}-${t}.md`,qp=(e,t)=>{let n=e.trim();return n.startsWith(`~`)?n===`~`?t||n:(n.startsWith(`~/`)||n.startsWith(`~\\`))&&t?`${t}${n.slice(1)}`:n:n},Jp=(e,t)=>{let n=Up(t.currentDirectory),r=Up(t.homeDirectory),i=Up(e);return n&&i.startsWith(n+`/`)?i.slice(n.length+1):r&&i===r?`~`:r&&i.startsWith(r+`/`)?`~${i.slice(r.length)}`:i},Yp=(e,t,n)=>{let r=Up(e.trim());if(!r)return null;let i=n?t.find(e=>e.id===n)??null:null;if(i?.path){let e=Up(i.path);if(r===e||r.startsWith(`${e}/`))return{id:i.id,path:i.path}}let a=t.filter(e=>{let t=Up(e.path);return r===t||r.startsWith(`${t}/`)}).sort((e,t)=>Up(t.path).length-Up(e.path).length)[0];return a?{id:a.id,path:a.path}:null},Xp=({targetPath:e=null})=>{let{t}=Xe(),r=yn(e=>e.currentSessionId),i=yn(e=>e.createSession),a=yn(e=>e.initializeNewOpenChamberSession),o=yn(e=>e.sendMessage),s=yn(e=>e.setCurrentSession),c=In(),l=Pe(e=>e.homeDirectory),u=$a(e=>e.planModeEnabled),d=xn(e=>e.projects),f=xn(e=>e.activeProjectId),m=Uo(e=>e.directories),h=Lo()??``,g=p(e=>e.setActiveMainTab),_=p(e=>e.setSessionSwitcherOpen),v=uo(),y=Re(),{isMobile:b}=Ca(),{currentTheme:x}=Qi(),S=Q.useMemo(()=>r?c.find(e=>e.id===r)??null:null,[r,c]),C=Q.useMemo(()=>Up((typeof S?.directory==`string`?S.directory:``)||``),[S?.directory]),w=Q.useMemo(()=>Up(h||C),[h,C]),T=Q.useMemo(()=>Yp(w,d,f),[f,w,d]),E=Q.useMemo(()=>T?m.get(T.path)?.isGitRepo===!0:!1,[T,m]),[D,O]=Q.useState(null),[k,A]=Q.useState(!1),[j,M]=Q.useState(null),N=Q.useMemo(()=>!j||!C||!l?j:Jp(j,{currentDirectory:C,homeDirectory:l}),[j,C,l]),[P,I]=Q.useState(``),[L,R]=Q.useState(``),{isPlaying:z,play:B,stop:H}=no(),U=wt(e=>e.showMessageTTSButtons),[ee,te]=Q.useState(null),[W,ne]=Q.useState(0),G=Q.useMemo(()=>N&&N.split(`/`).pop()||t(`planView.file.defaultName`),[N,t]),re=Q.useMemo(()=>P.trim()&&Gn(P).title||t(`planView.title.default`),[P,t]),K=Q.useMemo(()=>re.trim()||t(`planView.title.default`),[re,t]),[ie,ae]=Q.useState(!1),[oe,se]=Q.useState(`edit`),ce=Q.useRef(null),le=Q.useRef(!0),ue=Q.useRef(new Map),de=Q.useRef(new Map),fe=Q.useRef(new Map),pe=Q.useRef(new Map),me=Q.useRef(()=>{}),he=Q.useRef(null),[ge,_e]=Q.useState(null),ve=Q.useRef(null),ye=Q.useRef(null);Q.useEffect(()=>{le.current=!0;let e=de.current,t=pe.current,n=ue.current;return()=>{le.current=!1;for(let t of e.values())window.clearTimeout(t);e.clear();for(let[e,r]of t){let t=n.get(e);t&&Lp(t)&&me.current(r)}}},[]);let be=`openchamber:plan:md-viewer-mode`;Q.useEffect(()=>{try{let e=localStorage.getItem(be);if(!e)return;let t=JSON.parse(e);(t===`preview`||t===`edit`)&&se(t)}catch{}},[]);let xe=Q.useCallback(e=>{se(e);try{localStorage.setItem(be,JSON.stringify(e))}catch{}},[]),Se=Q.useRef(!1),Ce=Q.useRef(null),[we,Te]=Q.useState(!1);Q.useEffect(()=>{let e=()=>{Se.current=!1,Ce.current=null,Te(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]);let Ee=Q.useCallback((e,t)=>{let n=e.split(`
|
|
17
|
+
`);if(!r)return;let i=t===n?`${t}`:`${t}-${n}`,a=`${q.name}:${i}`;wn(q.path,a,r),Tn(G(a),`append-inline`),p.getState().setActiveMainTab(`chat`)},[wn,vt,q,Tn]),ai=!!(q&&(!Xr||Zr)&&!Qr&&it.length>0),oi=!!(q&&ti.length>0),si=!!(q&&!Fe&&!Xr&&!Qr&&r.writeFile&&it.length<=sp),ci=!!(q?.path&&mp(q.path)),li=!!(q?.path&&hp(q.path)),ui=!!(q?.path&&Io(q.path)),di=!!(q&&!Xr&&!Qr),fi=di&&!ci&&!ui&&!(li&&oe===`preview`),pi=ci&&ie===`edit`||li&&oe===`edit`||!ci&&!li&&re===`edit`,mi=Q.useMemo(()=>Pe?Sa(Pe):null,[Pe]),[hi,gi]=Q.useState(null);Q.useEffect(()=>{let e=!1,t=q?.path;if(!t||mi){gi(null);return}return gi(null),ha(t).then(t=>{e||gi(t)}),()=>{e=!0}},[q?.path,mi]),Q.useEffect(()=>{!si&&re===`edit`&&K(`view`)},[si,re]);let _i=`openchamber:files:md-viewer-mode`,vi=`openchamber:files:html-viewer-mode`;Q.useEffect(()=>{let e=q?.path;if(!e)return;K(fe.current[e]??`edit`);let t=Zn?`preview`:`edit`;try{let e=localStorage.getItem(_i);(e===`preview`||e===`edit`)&&(t=e)}catch{}ae(pe.current[e]??t);let n=Zn?`preview`:`edit`;try{let e=localStorage.getItem(vi);(e===`preview`||e===`edit`)&&(n=e)}catch{}se(me.current[e]??n),le(he.current[e]??(Zn?`preview`:`edit`))},[q?.path,Zn]);let yi=Q.useCallback(e=>{let t=q?.path;t&&(fe.current[t]=e),K(e)},[q?.path]),bi=Q.useCallback(e=>{let t=q?.path;t&&(pe.current[t]=e),ae(e);try{localStorage.setItem(_i,e)}catch{}},[q?.path]),Si=Q.useCallback(()=>ie,[ie]),Ci=Q.useCallback(e=>{let t=q?.path;t&&(me.current[t]=e),se(e);try{localStorage.setItem(vi,e)}catch{}},[q?.path]),wi=Q.useCallback(e=>{let t=q?.path;if(t&&(he.current[t]=e),Et.current&&=(clearTimeout(Et.current),null),kt.current!==null&&(cancelAnimationFrame(kt.current),kt.current=null),e===`edit`)yt(Dt.current||it),le(e);else{Dt.current=vt;let e=t;le(`edit`),kt.current=requestAnimationFrame(()=>{kt.current=requestAnimationFrame(()=>{kt.current=null,!(v&&e&&Ho.getState().byRoot[v]?.selectedPath!==e)&&(de(e=>e+1),le(`preview`))})});return}},[vt,it,v,q?.path]),Ti=Q.useCallback(async(e,t)=>{if(!r.writeFile||t===Ot.current)return!1;if(!(await r.writeFile(e,t))?.success)return J.error(n(`filesView.toast.writeFileFailed`)),!1;Dt.current=t,Ot.current=t,yt(t);let i=await Or(e,Le).catch(()=>null);return i&&(jt.current=i),!0},[r,Or,Le,n]);Q.useEffect(()=>()=>{Et.current&&=(clearTimeout(Et.current),null),kt.current!==null&&(cancelAnimationFrame(kt.current),kt.current=null)},[ce,q?.path]);let Ei=Q.useCallback(e=>{if(Dt.current=e,!q?.path||ce!==`preview`||!r.writeFile)return;Et.current&&clearTimeout(Et.current);let t=q.path;Et.current=setTimeout(()=>{Et.current=null,Ti(t,e).then(e=>{e&&(It(!0),setTimeout(()=>It(!1),1500))}).catch(e=>{J.error(e instanceof Error?e.message:n(`filesView.toast.saveFailed`))})},Mr)},[ce,r.writeFile,Ti,q?.path,n]),Di=Q.useMemo(()=>ui&&(Dt.current||vt)||it,[vt,it,ui]),Oi=Q.useCallback(()=>oe,[oe]);Q.useEffect(()=>{let e=e=>{let t=e?`preview`:`edit`;for(let e of ye)fe.current[e]=`edit`,mp(e)&&(pe.current[e]=t),hp(e)&&(me.current[e]=t),Io(e)&&(he.current[e]=t);K(`edit`),ae(t),se(t),le(t);try{localStorage.setItem(_i,t),localStorage.setItem(vi,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)}},[ye]),Q.useEffect(()=>{if(!Gn||!v)return;let e=()=>{typeof window>`u`||$t.current===null&&($t.current=window.requestAnimationFrame(()=>{$t.current=null,Qt(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=Jf(Gn.path);if(!n){Kn(null),en.current={key:``,attempts:0};return}let r=`${n}:${Gn.line}:${Gn.column??1}`;if(en.current.key!==r&&(en.current={key:r,attempts:0}),q?.path!==n){if(Bt)return;Ir(ke(n));return}if(lt||gt!==n)return;if(dt||Xr||Qr){Kn(null),en.current={key:``,attempts:0};return}if(!si)return;if(re!==`edit`){K(`edit`);return}let i=Yt.current;if(!i){e();return}if(!t(i,vt)){e();return}let a=Math.max(1,Math.min(Gn.line,i.state.doc.lines)),o=i.state.doc.line(a),s=Math.max(1,Gn.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||en.current.attempts===0){en.current.attempts+=1,i.dispatch({selection:{anchor:u},effects:Ue.scrollIntoView(u,{y:`center`})}),i.focus(),e();return}typeof window<`u`&&window.requestAnimationFrame(()=>{let e=Yt.current;e&&(e.dispatch({selection:{anchor:u},effects:Ue.scrollIntoView(u,{y:`center`})}),e.focus())}),Kn(null),en.current={key:``,attempts:0}},[si,Bt,vt,Zt,dt,lt,Xr,Qr,gt,Ir,Gn,v,q?.path,Kn,re,ke]),Q.useEffect(()=>{if(!qn||!v)return;let e=Jf(qn);if(!e){Jn(null);return}if(q?.path!==e){if(Bt)return;Ir(ke(e));return}if(!(lt||gt!==e||dt||Xr||Qr)){if(si&&re===`edit`){let e=Yt.current;if(!e)return;e.focus()}Jn(null)}},[si,Bt,dt,lt,Ir,Xr,Qr,gt,qn,v,q?.path,Jn,re,ke]);let ki=Q.useCallback(e=>{if(!u||!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)},[u]);Q.useEffect(()=>{if(!u||typeof window>`u`)return;let e=()=>{window.requestAnimationFrame(()=>{ki(Yt.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)}},[u,ki]),Q.useEffect(()=>{if(re!==`edit`||u)return;let e=fa(`open_go_to_line`,Yn),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(Ca(t,e)){t.preventDefault(),yn(!0);return}if(t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&t.key.toLowerCase()===`i`){let e=Yt.current?.state.selection.main;e&&!e.empty&&(t.preventDefault(),ri())}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[ri,u,Yn,re]);let Ai=p(e=>e.editorFontSize),ji=Q.useMemo(()=>{if(!q?.path)return[Cs(o,{fontSize:Ai})];let e=Lo(q.path),t=[Cs(o,e?{syntaxColors:!1,fontSize:Ai}:{fontSize:Ai})],n=mi??hi;return n&&t.push(n),e&&t.push(fs({language:e,themeName:o.metadata.id,theme:ho(o)})),A&&t.push(Ue.lineWrapping),t.push(Ue.updateListener.of(e=>{(e.selectionSet||e.docChanged)&&ni(e.view)})),u&&t.push(Ue.updateListener.of(e=>{e.view.hasFocus&&(e.selectionSet||e.focusChanged||e.viewportChanged||e.geometryChanged)&&window.requestAnimationFrame(()=>{ki(e.view)})})),t},[o,q?.path,mi,hi,A,u,ki,Ai,ni]),Mi=Q.useMemo(()=>({light:ge.metadata.id,dark:_e.metadata.id}),[ge.metadata.id,_e.metadata.id]),Ni=q?.path&&Xr&&!a.isDesktop&&!Zr?`${q.path}|${Le.allowOutsideWorkspace?`outside`:`workspace`}|${Le.outsideFileGrant??``}`:``,Pi=q?.path&&Qr?`${q.path}|${Le.allowOutsideWorkspace?`outside`:`workspace`}|${Le.outsideFileGrant??``}`:``,Fi=q?.path&&li&&oe===`preview`&&!a.isVSCode?q.path:``,Ii=n(`filesView.error.readFileFailed`),{readyKey:Li,nonce:Ri}=yp(Ni,ft,Ii),{readyKey:Hi,nonce:Wi}=yp(Fi,ft,Ii),{readyKey:Gi,nonce:Ki}=yp(Pi,ft,Ii),qi=!!(Ni&&Li!==Ni),Ji=!!(Fi&&Hi!==Fi),Xi=!!(Pi&&Gi!==Pi),Zi=q?.path&&Xr?a.isDesktop?Zr?`data:${No(q.path)};utf8,${encodeURIComponent(it)}`:pt:Zr?`data:${No(q.path)};utf8,${encodeURIComponent(it)}`:Li===Ni?i().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||void 0}):``:``,Qi=Q.useCallback(()=>{if(!q?.path||!Xr)return;let e=Zr?Zi:q.path||Zi;if(!e)return;let t=q.name||q.path;H({open:!0,title:t,content:``,metadata:{tool:`image-preview`,filename:t,mime:No(q.path)},image:{url:e,mimeType:No(q.path),filename:t}})},[Zi,Xr,Zr,q?.name,q?.path]),na=Q.useCallback(e=>{H(t=>t.open===e?t:{...t,open:e})},[]),ra=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:Qi,"aria-label":r,disabled:!Zi,children:(0,$.jsx)(`img`,{src:Zi,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},Ri)})})},[Ri,Zi,Qi,n]),ia=q?.path&&Qr&&Gi===Pi?i().authenticatedAsset(`/api/fs/raw`,{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||void 0}):``,aa=Q.useCallback(e=>(0,$.jsx)(`div`,{className:`h-full overflow-hidden bg-[var(--surface-background)]`,children:(0,$.jsx)(`iframe`,{src:ia,className:`h-full w-full border-0`,title:e.name},Ki)}),[ia,Ki]);Q.useEffect(()=>{let e=!1;return(async()=>{if(!a.isDesktop||!q?.path||!Xr||Zr){ht.current&&=(URL.revokeObjectURL(ht.current),``),mt(``);return}ft(null),ht.current&&=(URL.revokeObjectURL(ht.current),``),await(r.readFileBinary?r.readFileBinary(q.path,Le).then(e=>e.dataUrl):(async()=>{let t=await V(`/api/fs/raw`,{query:{path:q.path,allowOutsideWorkspace:Le.allowOutsideWorkspace?`true`:void 0,outsideFileGrant:Le.outsideFileGrant,directory:v||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),``):(ht.current=i,i)})()).then(t=>{e||(mt(t),_t(q.path))}).catch(t=>{ht.current&&=(URL.revokeObjectURL(ht.current),``),e||(mt(``),ft(t instanceof Error?t.message:n(`filesView.error.readFileFailed`)),_t(null))}).finally(()=>{e||ut(!1)})})(),()=>{e=!0}},[r,Xr,Zr,v,a.isDesktop,q?.path,Le,n]),Q.useEffect(()=>()=>{ht.current&&=(URL.revokeObjectURL(ht.current),``)},[]);let oa=Q.useCallback(()=>nn(null),[]),sa=Q.useMemo(()=>Ws({drafts:rr,editingDraftId:fr,commentText:ir,onTextChange:dr,selection:Rn,isDragging:Hn,fileLabel:q?.path??``,newWidgetId:`files-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:yr,onCancel:()=>{zn(null),hr()},onEdit:e=>{_r(e),zn({start:e.startLine,end:e.endLine})},onDelete:vr,onAddToChat:ii}),[ii,hr,ir,vr,fr,rr,yr,Hn,Rn,q?.path,dr,_r]),ua=Q.useCallback((e,t)=>(0,$.jsx)(`div`,{className:`h-full`,children:(0,$.jsx)(ts,{file:{name:e.name,contents:t,lang:Lo(e.path)||void 0},options:{disableFileHeader:!0,overflow:A?`wrap`:`scroll`,theme:Mi,themeType:o.metadata.variant===`dark`?`dark`:`light`},className:`block h-full w-full`,style:{height:`100%`}})}),[o.metadata.variant,Mi,A]),da=({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)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:t})}),(0,$.jsx)(Vi,{side:`bottom`,sideOffset:6,children:e})]});return(0,$.jsxs)(`div`,{className:a,children:[si&&pi&&(0,$.jsxs)($.Fragment,{children:[bt?(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`)]}):Rt&&Nt===`saved`&&!Ar?(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`)]}):Ar?o(n(Rt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${$n()}+S`}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void jr(),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(Rt?`filesView.editor.saveNowTitle`:`filesView.editor.saveNowManualTitle`,{shortcut:`${$n()}+S`}),"aria-label":n(`filesView.editor.saveAria`,{shortcut:`${$n()}+S`}),children:(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})):null,o(n(Rt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>zt(e=>!e),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,Rt?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(Rt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),"aria-label":n(Rt?`filesView.editor.autoSaveOn`:`filesView.editor.manualSave`),children:Rt?(0,$.jsx)(X,{name:`file-check-fill`,className:`size-4`}):(0,$.jsx)(X,{name:`file-check`,className:`size-4`})}))]}),di&&bn?o(`${n(`chat.textSelection.title.addToCurrentChat`)} (⌘I)`,(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:ri,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)(Ha,{shortcut:`⌘+I`})]})):null,(0,$.jsxs)(ta,{onOpenChange:te,children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(ca,{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)(Vi,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.openInDesktopApp`)})]}),(0,$.jsxs)(ea,{align:`end`,className:`w-56 max-h-[70vh] overflow-y-auto`,children:[jn.map(e=>(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>void In(e),children:[(0,$.jsx)(Kf,{label:e.label,iconDataUrl:e.iconDataUrl}),(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e.label})]},e.id)),Mn?(0,$.jsxs)(la,{className:`flex items-center gap-2`,onClick:()=>void Pn(!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]})]}),!Xr&&!Qr&&(0,$.jsxs)($.Fragment,{children:[o(n(A?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>j(!A),className:Y(`size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,A?`text-foreground opacity-100`:`text-muted-foreground opacity-65 hover:opacity-100`),title:n(A?`filesView.editor.disableLineWrap`:`filesView.editor.enableLineWrap`),children:(0,$.jsx)(X,{name:`text-wrap`,className:`size-4`})})),re===`edit`&&(0,$.jsxs)($.Fragment,{children:[o(n(`filesView.editor.findInFile`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:e=>{F(!P),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=>{yn(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)(Uf,{open:vn,onOpenChange:yn,view:Yt.current,variant:`inline`})]})]}),fi&&si&&!li&&(0,$.jsx)(cs,{currentMode:re===`view`?`preview`:`edit`,onToggle:()=>{yi(re===`view`?`edit`:`view`)}}),ci&&o(n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>bi(Si()===`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)]`,Si()===`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(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),"aria-label":n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Si()===`preview`?`eye`:`eye-off`,className:`size-4`})})),hp(q?.path??``)&&(0,$.jsx)(cs,{currentMode:Oi(),onToggle:()=>{Ci(Oi()===`preview`?`edit`:`preview`)}}),ci&&Si()===`preview`&&Qn&&(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{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(ot?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`),onClick:()=>{ot?ct():it.trim()&&st(it)},children:ot?(0,$.jsx)(X,{name:`stop`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`volume-up`,className:`size-4`})})}),(0,$.jsx)(Vi,{sideOffset:8,children:n(ot?`filesView.tts.stopSpeaking`:`filesView.tts.readAloud`)})]}),ui&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cs,{currentMode:ce,onToggle:()=>wi(ce===`preview`?`edit`:`preview`)}),ce===`preview`&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{let e=At.current?.getXml();if(Et.current&&=(clearTimeout(Et.current),null),q?.path&&e){if(!await Ti(q.path,e))return;It(!0),setTimeout(()=>It(!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:Ft?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`save-3`,className:`size-4`})})]}),ai&&o(n(`filesView.editor.copyFileContents`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(it)).ok?(hn(!0),qt.current!==null&&window.clearTimeout(qt.current),qt.current=window.setTimeout(()=>{hn(!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:mn?(0,$.jsx)(X,{name:`check`,className:`size-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`clipboard`,className:`size-4`})})),oi&&o(n(`filesView.editor.copyFilePathTitle`,{path:ti}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(ti)).ok?(_n(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.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.copyFilePathTitle`,{path:ti}),"aria-label":n(`filesView.editor.copyFilePathTitle`,{path:ti}),children:gn?(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:()=>N(!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`})})):!u&&e===`full`&&o(n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>N(!M),className:`size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent`,title:n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),"aria-label":n(M?`filesView.editor.exitFullscreen`:`filesView.editor.fullscreen`),children:M?(0,$.jsx)(X,{name:`fullscreen-exit`,className:`size-4`}):(0,$.jsx)(X,{name:`fullscreen`,className:`size-4`})}))]})},pa=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden`,children:[(0,$.jsx)(ur,{open:Bt,onOpenChange:e=>{e||Vt(!0)},children:(0,$.jsxs)(sr,{showCloseButton:!1,className:`max-w-md`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsx)(cr,{children:n(`filesView.unsaved.title`)}),(0,$.jsx)(lr,{children:n(`filesView.unsaved.description`)})]}),(0,$.jsxs)(or,{children:[(0,$.jsx)(Z,{variant:`outline`,onClick:()=>void zr(),disabled:bt,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:Rr,children:n(`filesView.unsaved.discard`)})]})]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-col flex-shrink-0`,y&&`border-b border-border/40`),children:[y?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center px-3 py-1.5`,children:[u&&O&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>k(!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`})}),u?q?(0,$.jsxs)(ta,{children:[(0,$.jsx)(ca,{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)(Va,{filePath:q.path,extension:q.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(np,{name:q.name}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-4 flex-shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(ea,{align:`start`,className:`w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]`,children:je.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(la,{onSelect:n=>{if(n.target.closest(`[data-close-open-file]`)){n.preventDefault();return}t||Ir(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)(Va,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(np,{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(),Br(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`)}):je.length>0?(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[ze.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`}),ze.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:Re,className:`flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:je.map(e=>{let t=q?.path===e.path;return(0,$.jsxs)(`div`,{title:$f(v,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)(Va,{filePath:e.path,extension:e.extension,className:`size-3.5 flex-shrink-0`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{t||Ir(e)},className:`max-w-[12rem] truncate text-left`,children:e.name}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),Br(e.path)},className:Y(`rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]`,!t&&!m&&`opacity-0 group-hover:opacity-100`),"aria-label":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,er&&!u&&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:[ti?(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-meta text-muted-foreground`,title:ti,children:ti}):null,(0,$.jsx)(`div`,{className:`ml-auto min-w-0 shrink-0 overflow-x-auto`,children:da({layout:`docked`})})]}):null]}),(0,$.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:[q&&!P&&!(er&&!u)&&(0,$.jsx)(`div`,{ref:U,className:`absolute right-3 top-3 z-30`,onMouseLeave:()=>{ee.current>0||L(!1)},children:I?da():(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ci?(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>bi(Si()===`preview`?`edit`:`preview`),className:Y(`size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors`,Si()===`preview`?`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]`:`text-muted-foreground hover:text-foreground`),"aria-label":n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),title:n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`),children:(0,$.jsx)(X,{name:Si()===`preview`?`eye`:`eye-off`,className:`size-4`})})})}),(0,$.jsx)(Vi,{side:`bottom`,sideOffset:6,children:n(Si()===`preview`?`filesView.editor.switchToEditMode`:`filesView.editor.switchToPreviewMode`)})]}):null,(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,onMouseEnter:()=>L(!0),children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>L(!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)(Vi,{side:`bottom`,sideOffset:6,children:n(`filesView.editor.controlsTitle`)})]})]})}),(0,$.jsx)(xi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:q?lt||qi||Xi?b?(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`)]}):dt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-[color:var(--status-error)]`,children:dt}):Xr&&q?ra(q):Qr?aa(q):q&&ui&&ce===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,style:{minHeight:`400px`},children:(0,$.jsx)(Oc,{ref:At,xml:Di,onChange:Ei},`${q.path}:${ue}`)}):q&&ci&&Si()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-3`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(Yi,{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)(mo,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):q&&li&&oe===`preview`?Ji?(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:!a.isVSCode&&Hi===Fi?(()=>{let e=q.path.split(`/`).map(e=>encodeURIComponent(e)).join(`/`);return i().authenticatedAsset(`/api/fs/serve${e.startsWith(`/`)?e:`/${e}`}`)})():void 0,srcDoc:a.isVSCode?(()=>{let e=q.path.substring(0,q.path.lastIndexOf(`/`)+1);return e?it.replace(/<head([^>]*)>/i,`<head$1><base href="${e}">`):it})():void 0,className:`w-full h-full border-none`,sandbox:`allow-scripts allow-same-origin allow-forms`,title:n(`filesView.editor.htmlPreviewTitle`)},Wi)}):q&&fi&&re===`view`?ua(q,vt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,ei&&`overflow-hidden`),ref:Xt,children:[(0,$.jsx)(`div`,{className:Y(`h-full`,ei&&`invisible`),children:(0,$.jsx)(as,{value:vt,onChange:yt,readOnly:!si,vimMode:Xn===`vim`,extensions:ji,className:`h-full`,blockWidgets:sa,onViewReady:e=>{Yt.current=e,ni(e),Qt(e=>e+1),window.requestAnimationFrame(()=>{ki(e)})},onViewDestroy:()=>{Yt.current&&=null,xn(!1),Cn(null),Qt(e=>e+1)},enableSearch:!0,searchOpen:P,onSearchOpenChange:F,highlightLines:Rn?{start:Math.min(Rn.start,Rn.end),end:Math.max(Rn.start,Rn.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(Rn&&!n.shiftKey&&Math.min(Rn.start,Rn.end)===r&&Math.max(Rn.start,Rn.end)===r)return zn(null),hr(),Bn.current=!1,Vn.current=null,Un(!1),!0;if(u&&Rn&&!n.shiftKey){let e=Math.min(Rn.start,Rn.end,r),t=Math.max(Rn.start,Rn.end,r);return zn({start:e,end:t}),Bn.current=!1,Vn.current=null,Un(!1),!0}if(Bn.current=!0,Vn.current=r,Un(!0),Rn&&n.shiftKey){let e=Math.min(Rn.start,r),t=Math.max(Rn.end,r);zn({start:e,end:t})}else zn({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Bn.current||Vn.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Vn.current,r),a=Math.max(Vn.current,r);return zn({start:i,end:a}),Un(!0),!1},mouseup:()=>(Bn.current=!1,Vn.current=null,Un(!1),!1)}}})}),ei&&(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`)})})]})]}),ma=!!(v&&We[v]),ga=v?Ke[v]:null,_a=(0,$.jsxs)(`section`,{className:Y(`flex min-h-0 flex-col overflow-hidden`,u?`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`,u?`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)(zi,{ref:D,value:w,onChange:e=>T(e.target.value),placeholder:n(`filesView.tree.search.placeholder`),className:`h-8 pl-8 pr-8 typography-meta`}),w.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:()=>{T(``),D.current?.focus()},children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Ln(`createFile`,{path:_,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)(Vi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFileTitle`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>Ln(`createFolder`,{path:_,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)(Vi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.newFolderTitle`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex flex-shrink-0`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>void Sr(),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)(Vi,{side:`bottom`,sideOffset:6,children:n(`filesView.tree.actions.refreshTitle`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:qr,disabled:Wr.length===0&&xe.length===0,className:`size-8 flex-shrink-0 p-0`,title:n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),"aria-label":n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`),children:(0,$.jsx)(X,{name:Kr?`contract-up-down`:`expand-up-down`,className:`size-4`})})}),(0,$.jsx)(Vi,{side:`bottom`,sideOffset:6,children:n(Kr?`sidebarFilesTree.actions.collapseAllTitle`:`sidebarFilesTree.actions.expandAllTitle`)})]})]})}),(0,$.jsx)(xi,{outerClassName:`flex-1 min-h-0`,className:Y(`py-2`,u?`px-3`:`px-2`),children:(0,$.jsx)(`ul`,{className:`flex flex-col`,children:nt?(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}),n(`filesView.tree.search.searching`)]}):et.length>0?et.map(e=>{let t=q?.path===e.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void Ir(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:[pp(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)}):ga?(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:ga}),(0,$.jsxs)(Z,{variant:`outline`,size:`xs`,className:`w-fit gap-1.5`,onClick:()=>void Sr(),children:[(0,$.jsx)(X,{name:`refresh`,className:`size-3.5`}),n(`filesView.tree.actions.refreshTitle`)]})]}):ma?Yr(v,0):(0,$.jsx)(`li`,{className:`px-2 py-1 typography-meta text-muted-foreground`,children:n(`filesView.state.loading`)})})})]}),va=e===`full`&&M&&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:da({exitFullscreenOnly:!0})}),(0,$.jsx)(xi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:lt||qi||Xi?b?(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…`]}):dt?(0,$.jsx)(`div`,{className:`p-4 typography-ui text-[color:var(--status-error)]`,children:dt}):Xr?ra(q,{fullHeight:!0}):Qr?aa(q):ci&&Si()===`preview`?(0,$.jsxs)(`div`,{className:`h-full overflow-auto p-4`,children:[it.length>512e3&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning`,children:n(`filesView.warning.largeFilePreviewLimited`,{sizeKb:Math.round(it.length/1024)})}),(0,$.jsx)(Yi,{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)(mo,{content:it,className:`typography-markdown-body`,stripFrontmatter:!0,enableFileReferences:!1})})]}):fi&&re===`view`?ua(q,vt):(0,$.jsxs)(`div`,{className:Y(`relative h-full`,ei&&`overflow-hidden`),children:[(0,$.jsx)(`div`,{className:Y(`h-full`,ei&&`invisible`),children:(0,$.jsx)(as,{value:vt,onChange:yt,readOnly:!si,vimMode:Xn===`vim`,extensions:ji,className:`h-full`,onViewReady:e=>{Yt.current=e,ni(e),window.requestAnimationFrame(()=>{ki(e)})},onViewDestroy:()=>{Yt.current&&=null,xn(!1),Cn(null)}})}),ei&&(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)(_p,{activeDialog:tn,dialogData:rn,dialogInputValue:on,onDialogInputChange:sn,isDialogSubmitting:cn,onDialogSubmit:Er,onClose:oa,inputRef:wt}),va,Sn?(0,$.jsx)(Us,{position:Sn,onAddToChat:ri}):null,R.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Wf,{popup:R,onOpenChange:na,isMobile:u})}):null,u?O?pa:_a: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:pa})}):(0,$.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2`,children:[f>=700&&(0,$.jsx)(`div`,{className:`w-72 flex-shrink-0 min-h-0 overflow-hidden`,children:_a}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background`,children:pa})]})]})};function xp(e){return e+1}var Sp=(e,t)=>e.mode===`target`?`target`:t===e.repoPath?`repo`:`home`,Cp=e=>({optional:!0,...e?{directory:e}:{}}),wp=async(e,t,n)=>{if(e?.readFile){let r=await e.readFile(t,Cp(n));if(typeof r.exists!=`boolean`)throw Error(`Plan file read returned an invalid exists contract`);return r.exists?r.content:null}let r=await V(`/api/fs/read`,{query:{path:t,optional:!0},cache:`no-store`,headers:n?{"x-opencode-directory":n}:void 0});if(!r.ok)throw Error(`Failed to read plan file (${r.status})`);let i=r.headers.get(`x-openchamber-file-exists`);if(i===`true`)return r.text();if(i===`false`)return null;throw Error(`Plan file read returned an invalid exists contract`)},Tp=(e,t,r=n())=>{let i=e?.readFile?e:oe()?.files;return{queryKey:F.plans.resolved(t.mode,t.sessionId,t.scopeDirectory,t.targetPath,t.repoPath,t.homePath,r),queryFn:async()=>{if(t.mode===`target`){if(!t.targetPath)throw Error(`A target plan path is required`);let e=await wp(i,t.targetPath,t.scopeDirectory);return e===null?{kind:`missing`,candidates:[t.targetPath]}:{kind:`resolved`,source:`target`,path:t.targetPath,content:e}}if(!t.repoPath||!t.homePath)throw Error(`Session plan candidates are required`);let e=await wp(i,t.repoPath,t.scopeDirectory);if(e!==null)return{kind:`resolved`,source:`repo`,path:t.repoPath,content:e};let n=await wp(i,t.homePath,t.scopeDirectory);return n===null?{kind:`missing`,candidates:[t.repoPath,t.homePath]}:{kind:`resolved`,source:`home`,path:t.homePath,content:n}}}},Ep=(e,t)=>{let r=(0,zc.c)(9),i;r[0]===t?i=r[1]:(i=t===void 0?{}:t,r[0]=t,r[1]=i);let a=i,{files:o}=fo(),s,c;if(r[2]!==o||r[3]!==e){let t=n();c=Be,s=Tp(o,e,t),r[2]=o,r[3]=e,r[4]=s,r[5]=c}else s=r[4],c=r[5];let l;return r[6]!==a||r[7]!==s?(l={...s,...a},r[6]=a,r[7]=s,r[8]=l):l=r[8],c(l)},Dp=(e,t,n,r)=>e.identity===t?e.content===e.baseContent&&!r?{...e,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``}:e:{identity:t,path:n?.path??null,content:n?.content??``,baseContent:n?.content??``},Op=e=>({persisted:e,desired:e,desiredRevision:0,nextAttemptToken:1,inFlight:null,failed:null}),kp=(e,t)=>e.desired===t?e:{...e,desired:t,desiredRevision:e.desiredRevision+1,failed:null},Ap=e=>e.desired===e.persisted&&e.inFlight===null&&e.failed===null,jp=(e,t,n)=>({identity:e,path:t,content:n.desired,baseContent:n.persisted}),Mp=e=>{if(e.inFlight||e.desired===e.persisted||e.failed?.revision===e.desiredRevision)return[e,null];let t={content:e.desired,revision:e.desiredRevision,token:e.nextAttemptToken};return[{...e,inFlight:t,nextAttemptToken:t.token+1},t]},Np=(e,t)=>e.inFlight?.token===t.token?{...e,persisted:t.content,inFlight:null,failed:e.failed&&e.failed.revision>t.revision?e.failed:null}:e,Pp=(e,t,n)=>e.inFlight?.token===t.token?{...e,inFlight:null,failed:{revision:t.revision,error:n}}:e,Fp=e=>({...e,failed:null}),Ip=(e,t)=>e===t,Lp=(e,t,n)=>Ip(t,n)?Mp(e):[e,null],Rp=e=>e.desired!==e.persisted||e.inFlight!==null,zp=(e,t,n=32)=>{let r=[];for(let[i,a]of e){if(e.size<=n)return r;i!==t&&Ap(a)&&(e.delete(i),r.push(i))}return r},Bp=(e,t,n)=>{let r=e.get(t);r&&e.set(t,Np(r,n))},Vp=(e,t,n,r)=>{let i=e.get(t);i&&e.set(t,Pp(i,n,r))},Hp=(e,t)=>e&&t.path===null&&t.content===t.baseContent,Up=(e,t)=>e&&t!==null,Wp=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},Gp=(e,t)=>{let n=Wp(e),r=t.replace(/\\/g,`/`).replace(/^\/+/,``).replace(/\/+$/,``);return!n||n===`/`?`/${r}`:`${n}/${r}`},Kp=(e,t,n)=>Gp(Gp(Gp(e,`.opencode`),`plans`),`${t}-${n}.md`),qp=(e,t)=>`~/.opencode/plans/${e}-${t}.md`,Jp=(e,t)=>{let n=e.trim();return n.startsWith(`~`)?n===`~`?t||n:(n.startsWith(`~/`)||n.startsWith(`~\\`))&&t?`${t}${n.slice(1)}`:n:n},Yp=(e,t)=>{let n=Wp(t.currentDirectory),r=Wp(t.homeDirectory),i=Wp(e);return n&&i.startsWith(n+`/`)?i.slice(n.length+1):r&&i===r?`~`:r&&i.startsWith(r+`/`)?`~${i.slice(r.length)}`:i},Xp=(e,t,n)=>{let r=Wp(e.trim());if(!r)return null;let i=n?t.find(e=>e.id===n)??null:null;if(i?.path){let e=Wp(i.path);if(r===e||r.startsWith(`${e}/`))return{id:i.id,path:i.path}}let a=t.filter(e=>{let t=Wp(e.path);return r===t||r.startsWith(`${t}/`)}).sort((e,t)=>Wp(t.path).length-Wp(e.path).length)[0];return a?{id:a.id,path:a.path}:null},Zp=({targetPath:e=null})=>{let{t}=Xe(),r=Tn(e=>e.currentSessionId),i=Tn(e=>e.createSession),a=Tn(e=>e.initializeNewOpenChamberSession),o=Tn(e=>e.sendMessage),s=Tn(e=>e.setCurrentSession),c=Hn(),l=Pe(e=>e.homeDirectory),u=eo(e=>e.planModeEnabled),d=mn(e=>e.projects),f=mn(e=>e.activeProjectId),m=Wo(e=>e.directories),h=Ro()??``,g=p(e=>e.setActiveMainTab),_=p(e=>e.setSessionSwitcherOpen),v=fo(),y=Re(),{isMobile:b}=wa(),{currentTheme:x}=$i(),S=Q.useMemo(()=>r?c.find(e=>e.id===r)??null:null,[r,c]),C=Q.useMemo(()=>Wp((typeof S?.directory==`string`?S.directory:``)||``),[S?.directory]),w=Q.useMemo(()=>Wp(h||C),[h,C]),T=Q.useMemo(()=>Xp(w,d,f),[f,w,d]),E=Q.useMemo(()=>T?m.get(T.path)?.isGitRepo===!0:!1,[T,m]),[D,O]=Q.useState(null),[k,A]=Q.useState(!1),[j,M]=Q.useState(null),N=Q.useMemo(()=>!j||!C||!l?j:Yp(j,{currentDirectory:C,homeDirectory:l}),[j,C,l]),[P,I]=Q.useState(``),[L,R]=Q.useState(``),{isPlaying:z,play:B,stop:H}=ro(),U=Ut(e=>e.showMessageTTSButtons),[ee,te]=Q.useState(null),[W,ne]=Q.useState(0),G=Q.useMemo(()=>N&&N.split(`/`).pop()||t(`planView.file.defaultName`),[N,t]),re=Q.useMemo(()=>P.trim()&&qn(P).title||t(`planView.title.default`),[P,t]),K=Q.useMemo(()=>re.trim()||t(`planView.title.default`),[re,t]),[ie,ae]=Q.useState(!1),[oe,se]=Q.useState(`edit`),ce=Q.useRef(null),le=Q.useRef(!0),ue=Q.useRef(new Map),de=Q.useRef(new Map),fe=Q.useRef(new Map),pe=Q.useRef(new Map),me=Q.useRef(()=>{}),he=Q.useRef(null),[ge,_e]=Q.useState(null),ve=Q.useRef(null),ye=Q.useRef(null);Q.useEffect(()=>{le.current=!0;let e=de.current,t=pe.current,n=ue.current;return()=>{le.current=!1;for(let t of e.values())window.clearTimeout(t);e.clear();for(let[e,r]of t){let t=n.get(e);t&&Rp(t)&&me.current(r)}}},[]);let be=`openchamber:plan:md-viewer-mode`;Q.useEffect(()=>{try{let e=localStorage.getItem(be);if(!e)return;let t=JSON.parse(e);(t===`preview`||t===`edit`)&&se(t)}catch{}},[]);let xe=Q.useCallback(e=>{se(e);try{localStorage.setItem(be,JSON.stringify(e))}catch{}},[]),Se=Q.useRef(!1),Ce=Q.useRef(null),[we,Te]=Q.useState(!1);Q.useEffect(()=>{let e=()=>{Se.current=!1,Ce.current=null,Te(!1)};return document.addEventListener(`mouseup`,e),()=>document.removeEventListener(`mouseup`,e)},[]);let Ee=Q.useCallback((e,t)=>{let n=e.split(`
|
|
18
18
|
`),r=Math.max(1,t.start),i=Math.min(n.length,t.end);return r>i?``:n.slice(r-1,i).join(`
|
|
19
|
-
`)},[]),{drafts:De,commentText:Oe,setCommentText:ke,editingDraftId:Ae,setSelection:je,saveComment:Me,cancel:Ne,reset:q,startEdit:Fe,deleteDraft:Ie}=
|
|
20
|
-
`):null;pt.getState().setArmed(e.runAsGoal===!0,u),await o(t,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,n,e.variant||void 0),O(null)}finally{A(!1)}},[E,P,i,T,a,D,j,rt,o,K,s]),at=Q.useMemo(()=>Us({drafts:De,editingDraftId:Ae,commentText:Oe,onTextChange:ke,selection:ge,isDragging:we,fileLabel:G,newWidgetId:`plan-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:ze,onCancel:Le,onEdit:e=>{Fe(e),_e({start:e.startLine,end:e.endLine})},onDelete:Ie}),[Oe,Ie,Ae,Le,ze,we,ge,De,G,ke,Fe]);return(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:re}),ee?(0,$.jsx)(Z,{variant:`link`,size:`xs`,className:`h-auto p-0 typography-micro text-[color:var(--status-error)]`,title:ee,onClick:()=>{let e=ue.current.get(Ye);e&&(ue.current.set(Ye,Pp(e)),te(null),ne(e=>e+1))},children:t(`planView.error.saveFailed`)}):null]}),j?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.improvePlanAria`),disabled:!P.trim(),children:(0,$.jsx)(X,{name:`loop-right-ai`,className:`size-4`})})})}),(0,$.jsx)(Bi,{sideOffset:8,children:t(`planView.actions.improve`)})]}),(0,$.jsxs)($i,{align:`end`,children:[(0,$.jsx)(ca,{onClick:()=>O({action:`improve`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(ca,{onClick:()=>O({action:`improve`,target:`worktree`}),disabled:!E,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsxs)(ea,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.implementPlanAria`),disabled:!P.trim(),children:(0,$.jsx)(X,{name:`code-ai`,className:`size-4`})})})}),(0,$.jsx)(Bi,{sideOffset:8,children:t(`planView.actions.implement`)})]}),(0,$.jsxs)($i,{align:`end`,children:[(0,$.jsx)(ca,{onClick:()=>O({action:`implement`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(ca,{onClick:()=>O({action:`implement`,target:`worktree`}),disabled:!E,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsx)(ss,{currentMode:oe,onToggle:()=>xe(oe===`preview`?`edit`:`preview`)}),oe===`preview`&&U&&(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(z?`planView.tts.stopSpeaking`:`planView.tts.readAloud`),onClick:()=>{z?H():P.trim()&&B(P)},children:z?(0,$.jsx)(X,{name:`stop`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`volume-up`,className:`h-4 w-4`})})}),(0,$.jsx)(Bi,{sideOffset:8,children:t(z?`planView.tts.stopSpeaking`:`planView.tts.readAloud`)})]}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(P)).ok&&(ae(!0),ce.current!==null&&window.clearTimeout(ce.current),ce.current=window.setTimeout(()=>{ae(!1)},1200))},className:`h-5 w-5 p-0`,title:t(`planView.actions.copyPlanContents`),"aria-label":t(`planView.actions.copyPlanContents`),children:ie?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`clipboard`,className:`h-4 w-4`})})]}):null]}),(0,$.jsx)(bu,{open:D!==null,onOpenChange:e=>{!e&&!k&&O(null)},target:D?.target??`session`,projectDirectory:T?.path??null,submitting:k,allowRunAsGoal:!0,onConfirm:it}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:(0,$.jsx)(bi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Ze?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:t(`planView.state.loading`)}):Qe?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-destructive`,children:Ge.error instanceof Error?Ge.error.message:t(`planView.error.saveFailed`)}):et&&tt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:tt.join(`, `)}):(0,$.jsx)(`div`,{className:`relative h-full`,children:(0,$.jsx)(`div`,{className:`h-full`,children:oe===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,$.jsx)(Yi,{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:t(`planView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:t(`planView.error.switchToEditMode`)})]}),children:(0,$.jsx)(po,{content:P,className:`typography-markdown-body`,enableFileReferences:!1})})}):(0,$.jsx)(`div`,{className:`relative h-full`,ref:ye,children:(0,$.jsx)(is,{value:P,onChange:I,readOnly:!1,className:`h-full`,extensions:Ve,onViewReady:e=>{ve.current=e},onViewDestroy:()=>{ve.current=null},blockWidgets:at,highlightLines:ge?{start:Math.min(ge.start,ge.end),end:Math.max(ge.start,ge.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(ge&&!n.shiftKey&&Math.min(ge.start,ge.end)===r&&Math.max(ge.start,ge.end)===r)return _e(null),Ne(),Se.current=!1,Ce.current=null,Te(!1),!0;if(b&&ge&&!n.shiftKey){let e=Math.min(ge.start,ge.end,r),t=Math.max(ge.start,ge.end,r);return _e({start:e,end:t}),Se.current=!1,Ce.current=null,Te(!1),!0}if(Se.current=!0,Ce.current=r,Te(!0),ge&&n.shiftKey){let e=Math.min(ge.start,r),t=Math.max(ge.end,r);_e({start:e,end:t})}else _e({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Se.current||Ce.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Ce.current,r),a=Math.max(Ce.current,r);return _e({start:i,end:a}),Te(!0),!1},mouseup:()=>(Se.current=!1,Ce.current=null,Te(!1),!1)}}})})})})})})]})},Zp=e=>e,Qp=e=>{let t=Zp(e).type;return typeof t==`string`?t:``},$p=e=>{let t=Zp(e).tool;return typeof t==`string`?t:``},em=e=>{let t=Zp(e).text;return typeof t==`string`?t:``},tm=e=>{let t=Qp(e);return t===`tool`?$p(e).trim().toLowerCase()||`tool`:t||`unknown`},nm=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=tm(n);t.includes(e)||t.push(e)}return t.join(` + `)},rm=e=>e.replace(/\s+/g,` `).trim(),im=e=>{for(let t of e)if(Qp(t)===`text`){let e=rm(em(t));if(e.length===0)continue;return e}let t=e.filter(e=>Qp(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},am=(e,t,n)=>`${n(e)} / ${n(t)}`,om=(e,t,n,r)=>{let i=am(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},sm=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},cm=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=sm(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}})},lm={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},um={user:0,assistant:0,tool:0,other:0},dm=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,fm=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{...lm,total:dm(n)};if(!n||typeof n!=`object`)return lm;let r=n,i=dm(r.input),a=dm(r.output),o=dm(r.reasoning),s=dm(r.cache?.read),c=dm(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},pm=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},mm=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+mm(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+mm(t),0):0,hm=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...um,assistant:mm(n.text)+mm(n.content)};let i=pm(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:mm(n.input)+mm(n.output)+mm(n.error)+mm(n.call?.input)+mm(n.call?.output)+mm(n.call?.error)+mm(n.raw)+Math.round(mm(n.metadata)*.25)+Math.round(mm(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}},gm=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),_m=e=>{let t=Qa(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},vm=(e,t)=>{if(e.length===0)return{...um};let n=e.reduce((e,t)=>{let n=_m(t),r={...um};for(let e of t.parts)r=gm(r,hm(e,n));return gm(e,r)},{...um});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)}},ym=e=>e.toLocaleString(Qe()),bm=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(Qe(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(Qe(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),xm=(e,t)=>!e||!Number.isFinite(e)?`-`:va(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),Sm=(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}},Cm=()=>{let e=(0,Rc.c)(259),{t}=Xe(),n=p(wm),r=p(Tm),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=yn(Em),d=In(),f=rt(u??``),m=wt(Dm),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(Om),c(null)},e[1]=h):h=e[1];let g;e[2]===u?g=e[3]:(g=[u],e[2]=u,e[3]=g),Q.useEffect(h,g);let _,v;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},v=[],e[4]=_,e[5]=v):(_=e[4],v=e[5]),Q.useEffect(_,v);let y;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=async(e,t)=>{(await $e(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]=y):y=e[6];let b=y,x;e[7]!==u||e[8]!==d?(x=u?d.find(e=>e.id===u)??null:null,e[7]=u,e[8]=d,e[9]=x):x=e[9];let S=x,C,w,T,E,D,O,k,A;if(e[10]!==m||e[11]!==f){C=f.filter(km);let t;e[20]===f?t=e[21]:(t=f.filter(Am),e[20]=f,e[21]=t),A=t;let n=null;for(let e=C.length-1;e>=0;--e){let t=C[e];if(fm(t).total>0){n=t;break}}O=n?fm(n):lm,w=La({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(jm,0);let r=0,i=0;for(let e of C){let t=fm(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=Ka(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:Ja(a),e[22]=a,e[23]=o),E=o;let s=n?ao({createdAt:n.info.time?.created??null,completedAt:n.info.time?.completed??null,outputTokens:O.output,reasoningTokens:O.reasoning,parts:n.parts}):null;T=s===null?null:Ja(s);let c=n?.info??null;D=Sm(m,c?.providerID||``,c?.modelID||``),e[10]=m,e[11]=f,e[12]=C,e[13]=w,e[14]=T,e[15]=E,e[16]=D,e[17]=O,e[18]=k,e[19]=A}else C=e[12],w=e[13],T=e[14],E=e[15],D=e[16],O=e[17],k=e[18],A=e[19];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===f?P=e[25]:(P=vm(f,[...f].reverse().find(Mm)?.info?.system||``),e[24]=f,e[25]=P);let F=P,I=F.user,L=F.assistant,R=F.tool,z=Math.max(0,O.input-I-L-R),B=I+L+R+z,V=f[0]?.info?.time?.created,H=f.length>0?f[f.length-1]?.info?.time?.created:null,U;e[26]!==S?.title||e[27]!==t?(U=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=U):U=e[28];let ee=S?.time?.created??V??null,te=H??S?.time?.created??null,W=E&&E.length>0?E:null,ne=T&&T.length>0?T:null,G;e[29]!==L||e[30]!==z||e[31]!==R||e[32]!==I?(G={user:I,assistant:L,tool:R,other:z},e[29]=L,e[30]=z,e[31]=R,e[32]=I,e[33]=G):G=e[33];let re;e[34]!==C.length||e[35]!==B||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==f.length||e[40]!==ee||e[41]!==te||e[42]!==W||e[43]!==ne||e[44]!==G||e[45]!==U||e[46]!==O||e[47]!==k||e[48]!==N||e[49]!==A.length?(re={sessionTitle:U,messagesCount:f.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:ee,lastActivityAt:te,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:W,lastAssistantTpsLabel:ne,contextLimit:M,breakdown:G,breakdownTotal:B},e[34]=C.length,e[35]=B,e[36]=w,e[37]=M,e[38]=j,e[39]=f.length,e[40]=ee,e[41]=te,e[42]=W,e[43]=ne,e[44]=G,e[45]=U,e[46]=O,e[47]=k,e[48]=N,e[49]=A.length,e[50]=re):re=e[50];let K=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]!==K.breakdown.user?(ae={key:`user`,label:ie,value:K.breakdown.user,color:`var(--status-success)`},e[57]=ie,e[58]=K.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]!==K.breakdown.assistant?(se={key:`assistant`,label:oe,value:K.breakdown.assistant,color:`var(--primary-base)`},e[62]=oe,e[63]=K.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]!==K.breakdown.tool?(le={key:`tool`,label:ce,value:K.breakdown.tool,color:`var(--status-warning)`},e[67]=ce,e[68]=K.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]!==K.breakdown.other?(de={key:`other`,label:ue,value:K.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=ue,e[73]=K.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]===K.sessionTitle?me=e[81]:(me=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:K.sessionTitle}),e[80]=K.sessionTitle,e[81]=me);let he;e[82]!==K.providerModel.modelName||e[83]!==K.providerModel.providerName?(he=(0,$.jsxs)(`span`,{children:[K.providerModel.providerName,` / `,K.providerModel.modelName]}),e[82]=K.providerModel.modelName,e[83]=K.providerModel.providerName,e[84]=he):he=e[84];let ge;e[85]!==n||e[86]!==K.createdAt?(ge=K.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:xm(K.createdAt,n)})]}),e[85]=n,e[86]=K.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]===K.tokenBreakdown.total?xe=e[99]:(xe=ym(K.tokenBreakdown.total),e[98]=K.tokenBreakdown.total,e[99]=xe);let Se;e[100]===K.contextLimit?Se=e[101]:(Se=K.contextLimit?` / ${ym(K.contextLimit)}`:``,e[100]=K.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]===K.usagePercent?Te=e[109]:(Te=K.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,K.usagePercent)}%`,backgroundColor:K.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=K.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]!==K.usagePercent?(De=t(`contextSidebar.context.percentUsed`,{percent:K.usagePercent.toFixed(1)}),e[112]=t,e[113]=K.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]===K.messagesCount?je=e[124]:(je=ym(K.messagesCount),e[123]=K.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 q;e[130]===K.userMessagesCount?q=e[131]:(q=ym(K.userMessagesCount),e[130]=K.userMessagesCount,e[131]=q);let Pe;e[132]!==Ne||e[133]!==q?(Pe={label:Ne,value:q},e[132]=Ne,e[133]=q,e[134]=Pe):Pe=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]===K.assistantMessagesCount?Ie=e[138]:(Ie=ym(K.assistantMessagesCount),e[137]=K.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]!==Pe||e[144]!==Le?(Re=[Me,Pe,Le],e[142]=Me,e[143]=Pe,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(Nm)}),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]===K.totalAssistantCost?Ge=e[155]:(Ge=bm(K.totalAssistantCost),e[154]=K.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 qe;e[158]!==We||e[159]!==Ke?(qe=(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]=qe):qe=e[160];let Je;e[161]!==r||e[162]!==t||e[163]!==K.sessionTpsLabel?(Je=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:K.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=K.sessionTpsLabel,e[164]=Je):Je=e[164];let Ye;e[165]!==He||e[166]!==qe||e[167]!==Je?(Ye=(0,$.jsxs)(`div`,{className:He,children:[qe,Je]}),e[165]=He,e[166]=qe,e[167]=Je,e[168]=Ye):Ye=e[168];let Ze;e[169]!==Be||e[170]!==Ye?(Ze=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Be,Ye]}),e[169]=Be,e[170]=Ye,e[171]=Ze):Ze=e[171];let Qe;e[172]===t?Qe=e[173]:(Qe=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=Qe);let et;e[174]===Qe?et=e[175]:(et=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:Qe}),e[174]=Qe,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]!==K.tokenBreakdown.input?(nt={label:tt,value:K.tokenBreakdown.input,format:`count`},e[178]=tt,e[179]=K.tokenBreakdown.input,e[180]=nt):nt=e[180];let it;e[181]===t?it=e[182]:(it=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=it);let at;e[183]!==it||e[184]!==K.tokenBreakdown.output?(at={label:it,value:K.tokenBreakdown.output,format:`count`},e[183]=it,e[184]=K.tokenBreakdown.output,e[185]=at):at=e[185];let ot;e[186]===t?ot=e[187]:(ot=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=ot);let st;e[188]!==ot||e[189]!==K.tokenBreakdown.reasoning?(st={label:ot,value:K.tokenBreakdown.reasoning,format:`count`},e[188]=ot,e[189]=K.tokenBreakdown.reasoning,e[190]=st):st=e[190];let ct;e[191]===t?ct=e[192]:(ct=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=ct);let lt;e[193]!==ct||e[194]!==K.tokenBreakdown.cacheRead?(lt={label:ct,value:K.tokenBreakdown.cacheRead,format:`count`},e[193]=ct,e[194]=K.tokenBreakdown.cacheRead,e[195]=lt):lt=e[195];let ut;e[196]===t?ut=e[197]:(ut=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=ut);let dt;e[198]!==ut||e[199]!==K.tokenBreakdown.cacheWrite?(dt={label:ut,value:K.tokenBreakdown.cacheWrite,format:`count`},e[198]=ut,e[199]=K.tokenBreakdown.cacheWrite,e[200]=dt):dt=e[200];let ft;e[201]===t?ft=e[202]:(ft=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=ft);let pt=K.cacheHitRate.hasInput?K.cacheHitRate.percent:null,mt;e[203]!==ft||e[204]!==pt?(mt={label:ft,value:pt,format:`percent`},e[203]=ft,e[204]=pt,e[205]=mt):mt=e[205];let ht;e[206]!==r||e[207]!==t||e[208]!==K.lastAssistantTpsLabel?(ht=r?[{label:t(`contextSidebar.tokens.tps`),value:K.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=K.lastAssistantTpsLabel,e[209]=ht):ht=e[209];let gt;e[210]!==nt||e[211]!==at||e[212]!==st||e[213]!==lt||e[214]!==dt||e[215]!==mt||e[216]!==ht?(gt=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[nt,at,st,lt,dt,mt,...ht].map(Pm)}),e[210]=nt,e[211]=at,e[212]=st,e[213]=lt,e[214]=dt,e[215]=mt,e[216]=ht,e[217]=gt):gt=e[217];let _t;e[218]!==et||e[219]!==gt?(_t=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[et,gt]}),e[218]=et,e[219]=gt,e[220]=_t):_t=e[220];let vt;e[221]!==pe||e[222]!==K.breakdownTotal?(vt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:pe.map(e=>e.value<=0||K.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/K.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=pe,e[222]=K.breakdownTotal,e[223]=vt):vt=e[223];let yt;e[224]!==pe||e[225]!==K.breakdownTotal?(yt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:pe.map(e=>{let t=K.breakdownTotal>0?e.value/K.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]=K.breakdownTotal,e[226]=yt):yt=e[226];let bt;e[227]!==vt||e[228]!==yt?(bt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[vt,yt]}),e[227]=vt,e[228]=yt,e[229]=bt):bt=e[229];let xt;e[230]===t?xt=e[231]:(xt=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=xt);let St;e[232]===xt?St=e[233]:(St=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:xt}),e[232]=xt,e[233]=St);let Ct;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=Qa(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=nm(e.parts),h=c?fm({info:e.info,parts:e.parts}):null,g=l?im(e.parts):``,_=cm(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=ao({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=Ja(t);return n.length>0?n:null})(),x=h?om(h.input,h.output,ym,y):``,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(),b(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)(Zo,{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],Ct=[...f].reverse().map(i),e[234]=s,e[235]=a,e[236]=f,e[237]=r,e[238]=t,e[239]=n,e[240]=Ct}else Ct=e[240];let Tt;e[247]===Ct?Tt=e[248]:(Tt=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:Ct}),e[247]=Ct,e[248]=Tt);let Et;e[249]!==St||e[250]!==Tt?(Et=(0,$.jsxs)(`div`,{children:[St,Tt]}),e[249]=St,e[250]=Tt,e[251]=Et):Et=e[251];let Dt;return e[252]!==ve||e[253]!==ke||e[254]!==Ze||e[255]!==_t||e[256]!==bt||e[257]!==Et?(Dt=(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,Ze,_t,bt,Et]})}),e[252]=ve,e[253]=ke,e[254]=Ze,e[255]=_t,e[256]=bt,e[257]=Et,e[258]=Dt):Dt=e[258],Dt};function wm(e){return e.timeFormatPreference}function Tm(e){return e.showAssistantTps}function Em(e){return e.currentSessionId}function Dm(e){return e.providers}function Om(e){return Object.keys(e).length>0?{}:e}function km(e){return Qa(e.info).role===`assistant`}function Am(e){return Qa(e.info).isUser}function jm(e,t){return e+dm(t.info.cost)}function Mm(e){return Qa(e.info).isUser&&typeof e.info.system==`string`}function Nm(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 Pm(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)}%`:ym(Number(e.value)):`—`})]},e.label)}var Fm=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(`/`)?`/`:``)},Im=()=>`react-surface`,Lm=(e,t)=>JSON.stringify([Fm(e),t]),Rm=(e,t,n,r)=>JSON.stringify([e,t,Fm(n),r]),zm=(e,t,n)=>n?t:e===t?e:null,Bm=(e,t)=>e.sessionId===t.sessionId&&Fm(e.directory)===Fm(t.directory),Vm=(e,t)=>Fm(e)===Fm(t),Hm=e=>({anchor:e,current:e,stack:[]}),Um=(e,t)=>e??Hm(t),Wm=(e,t)=>e?.current.sessionId??t,Gm=(e,t)=>Bm(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},Km=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},qm=(e,t,n)=>!Vm(e.anchor.directory,t.directory)||!Vm(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Gm(e,t)},Jm=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=qm(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Ym=(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},Xm=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`,Zm=e=>e===`retry`,Qm=e=>e.active&&e.visible&&e.messageCount<=0,$m=e=>e?`load-more`:`ensure`,eh=e=>e.kind===`has-more`,th=(e,t)=>`${e}\n${t}`,nh=(e,t,n,r)=>r&&!e.has(th(t,n)),rh=(e,t)=>({scrollHeight:e,scrollTop:t}),ih=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),ah=(e,t)=>e&&!t,oh=e=>e,sh=e=>!e,ch=e=>!ah(e.hasMore,e.isLoading)||!sh(e.historyVirtualized)?null:rh(e.scrollHeight,e.scrollTop),lh=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),uh=33554432,dh=e=>Math.min(uh,262144+Math.max(0,Math.ceil(e))*64*1024),fh=e=>Math.min(uh,Math.max(0,Math.round(Number.isFinite(e)?e:0))),ph=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}},mh=(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 ph({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=fh(t.estimatedBytes);return!n||n.estimatedBytes===r?e:ph({...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:ph({...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??dh(0),lastAccessed:t.now}}})},hh=e=>{let t=(0,Rc.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=Xe();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},gh=e=>{let t=(0,Rc.c)(151),{surfaceId:n,sessionId:i,directory:a,active:o,canNavigateBack:s,onNavigateSession:c,onNavigateBack:l,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=Xe(),p=ro(),m,h,g;t[0]!==a||t[1]!==i||t[2]!==n?(h=r(),m=Fm(a),g=Rm(h,n,m,i),t[0]=a,t[1]=i,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=Yt(i,d),E=rt(i,d),D=wt(vh),O;t[7]===E?O=t[8]:(O=eo(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)&&Ht(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=$t(i,d),N=Kt(i,d).renderable,P;t[17]===i?P=t[18]:(P=e=>!!e.session.find(e=>e.id===i)?.parentID,t[17]=i,t[18]=P);let F=Ut(P,d),[I,L]=Q.useState(null),R,z;t[19]!==F||t[20]!==_?(R=()=>{L(e=>zm(e,_,F))},z=[F,_],t[19]=F,t[20]=_,t[21]=R,t[22]=z):(R=t[21],z=t[22]),Q.useLayoutEffect(R,z);let B=F||I===_,V=Pt(i,d),H;t[23]===i?H=t[24]:(H=e=>e.streamingMessageIds.get(i)??null,t[23]=i,t[24]=H);let U=tn(H),ee;t[25]===U?ee=t[26]:(ee=e=>U?e.messageStreamStates.get(U)?.phase??null:null,t[25]=U,t[26]=ee);let te=tn(ee),W=M?.type===`busy`||M?.type===`retry`,ne;t[27]!==i||t[28]!==W||t[29]!==T||t[30]!==_?(ne={currentSessionId:i,viewportKey:_,sessionMessageCount:T,sessionIsWorking:W,isMobile:!1},t[27]=i,t[28]=W,t[29]=T,t[30]=_,t[31]=ne):ne=t[31];let{scrollRef:G,notifyContentChange:re,getAnimationHandlers:K,goToBottom:ie,restoreSnapshot:ae,showScrollButton:oe}=Ua(ne),se;t[32]!==i||t[33]!==p?(se=e=>{p.ensureSessionRenderable(i,Zm(e))},t[32]=i,t[33]=p,t[34]=se):se=t[34];let ce=Ge(se),le,ue;t[35]!==o||t[36]!==ce?(le=()=>{o&&ce(`active`)},ue=[o,ce],t[35]=o,t[36]=ce,t[37]=le,t[38]=ue):(le=t[37],ue=t[38]),Q.useEffect(le,ue);let de,fe;t[39]!==o||t[40]!==ce||t[41]!==T?(de=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();Qm({active:o,visible:e,messageCount:T})&&ce(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},fe=[o,ce,T],t[39]=o,t[40]=ce,t[41]=T,t[42]=de,t[43]=fe):(de=t[42],fe=t[43]),Q.useEffect(de,fe);let pe,me;t[44]!==u||t[45]!==T||t[46]!==_?(pe=()=>{u?.(_,dh(T))},me=[u,T,_],t[44]=u,t[45]=T,t[46]=_,t[47]=pe,t[48]=me):(pe=t[47],me=t[48]),Q.useEffect(pe,me);let he,ge;t[49]!==N||t[50]!==ae||t[51]!==i||t[52]!==_?(he=()=>{if(!nh(w.current,i,_,N))return;let e=th(i,_);w.current.add(e),ae()},ge=[N,ae,i,_],t[49]=N,t[50]=ae,t[51]=i,t[52]=_,t[53]=he,t[54]=ge):(he=t[53],ge=t[54]),Q.useEffect(he,ge);let _e;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>{y.current=null,S(null)},t[55]=_e):_e=t[55];let ve;t[56]===_?ve=t[57]:(ve=[_],t[56]=_,t[57]=ve),Q.useLayoutEffect(_e,ve);let ye;t[58]!==x||t[59]!==G||t[60]!==_?(ye=()=>{let e=y.current,t=G.current;if(lh(e,x,_)){if(!t||!sh(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=ih(e.anchor,t.scrollHeight),y.current=null}},t[58]=x,t[59]=G,t[60]=_,t[61]=ye):ye=t[61];let be;t[62]!==x||t[63]!==G||t[64]!==E||t[65]!==_?(be=[x,G,E,_],t[62]=x,t[63]=G,t[64]=E,t[65]=_,t[66]=be):be=t[66],Q.useLayoutEffect(ye,be);let xe;t[67]===m?xe=t[68]:(xe={directory:m},t[67]=m,t[68]=xe);let Se=xe,Ce=bn(i,d).boundary,we;t[69]===Ce?we=t[70]:(we=eh(Ce),t[69]=Ce,t[70]=we);let Te=we,Ee;t[71]!==V?.status||t[72]!==Se||t[73]!==i||t[74]!==p?(Ee=V?.status===`loading`||p.isLoading(i,Se),t[71]=V?.status,t[72]=Se,t[73]=i,t[74]=p,t[75]=Ee):Ee=t[75];let De=Ee,Oe;t[76]!==m||t[77]!==h||t[78]!==i?(Oe=[`context-panel-load-older`,h,m,i],t[76]=m,t[77]=h,t[78]=i,t[79]=Oe):Oe=t[79];let ke;t[80]!==Ce||t[81]!==i||t[82]!==d?(ke=async()=>{Ce.kind===`unknown`&&await Mn(d,i),await rn(d,i)},t[80]=Ce,t[81]=i,t[82]=d,t[83]=ke):ke=t[83];let Ae;t[84]!==Oe||t[85]!==ke?(Ae={mutationKey:Oe,mutationFn:ke},t[84]=Oe,t[85]=ke,t[86]=Ae):Ae=t[86];let je=ze(Ae),Me=je.isPending,Ne;t[87]!==De||t[88]!==Te||t[89]!==Me||t[90]!==je||t[91]!==G||t[92]!==f||t[93]!==_?(Ne=()=>{if(!ah(Te,Me||De)||je.isPending)return;let e=b.current+1;b.current=e;let t=G.current,n=t?ch({hasMore:Te,isLoading:Me,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,je.mutateAsync().then(()=>{S(e)},()=>{S(e),J.error(f(`chat.history.loadOlderFailed`))})},t[87]=De,t[88]=Te,t[89]=Me,t[90]=je,t[91]=G,t[92]=f,t[93]=_,t[94]=Ne):Ne=t[94];let q=Ge(Ne),Pe=V?.status===`error`?V.error:void 0,Fe;t[95]!==o||t[96]!==N||t[97]!==W||t[98]!==E.length||t[99]!==Pe?(Fe=Xm({directoryMatches:!0,requested:o,renderable:N,messageCount:E.length,working:W,error:Pe}),t[95]=o,t[96]=N,t[97]=W,t[98]=E.length,t[99]=Pe,t[100]=Fe):Fe=t[100];let Ie=Fe,Le;t[101]!==o||t[102]!==m||t[103]!==c||t[104]!==i||t[105]!==n?(Le={kind:`panel`,surfaceId:n,sessionId:i,directory:m,active:o,capabilities:Fa,navigateSession:c},t[101]=o,t[102]=m,t[103]=c,t[104]=i,t[105]=n,t[106]=Le):Le=t[106];let Re=Le,Be;t[107]!==ce||t[108]!==Te||t[109]!==q?(Be=()=>{if($m(Te)===`load-more`){q();return}ce(`retry`)},t[107]=ce,t[108]=Te,t[109]=q,t[110]=Be):Be=t[110];let Ve=Ge(Be),He;t[111]!==s||t[112]!==l||t[113]!==f?(He=s?(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`xs`,onClick:l,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[111]=s,t[112]=l,t[113]=f,t[114]=He):He=t[114];let Ue;t[115]!==te||t[116]!==ce||t[117]!==K||t[118]!==ie||t[119]!==Te||t[120]!==Me||t[121]!==q||t[122]!==re||t[123]!==V?.error||t[124]!==Ve||t[125]!==G||t[126]!==i||t[127]!==W||t[128]!==E||t[129]!==oe||t[130]!==U||t[131]!==d||t[132]!==f||t[133]!==Ie||t[134]!==_?(Ue=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:Ie===`cold-loading`||Ie===`working-empty`||Ie===`authoritative-empty`||Ie===`fatal-error`?(0,$.jsx)(hh,{state:Ie,error:V?.error,onRetry:()=>ce(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ki,{ref:G,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:[Ie===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:V?.error}),(0,$.jsx)(Z,{type:`button`,variant:`secondary`,size:`xs`,onClick:Ve,children:f(`chat.history.retry`)})]}):null,oh(Te)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,onClick:q,disabled:Me,children:[Me?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,(0,$.jsx)(Ga,{ref:v,sessionKey:i,virtualizerKey:_,messages:E,sessionIsWorking:W,activeStreamingMessageId:U,activeStreamingPhase:te,onMessageContentChange:re,getAnimationHandlers:K,isLoadingOlder:Me,scrollToBottom:()=>ie(`instant`),scrollRef:G,directory:d}),(0,$.jsx)(`div`,{className:`h-12`,"aria-hidden":`true`})]})}),(0,$.jsx)(to,{visible:oe,onClick:()=>ie(`smooth`)})]})}),t[115]=te,t[116]=ce,t[117]=K,t[118]=ie,t[119]=Te,t[120]=Me,t[121]=q,t[122]=re,t[123]=V?.error,t[124]=Ve,t[125]=G,t[126]=i,t[127]=W,t[128]=E,t[129]=oe,t[130]=U,t[131]=d,t[132]=f,t[133]=Ie,t[134]=_,t[135]=Ue):Ue=t[135];let We;t[136]!==k.agentName||t[137]!==k.modelId||t[138]!==k.providerId||t[139]!==j||t[140]!==B?(We=B?(0,$.jsx)(Ya,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[136]=k.agentName,t[137]=k.modelId,t[138]=k.providerId,t[139]=j,t[140]=B,t[141]=We):We=t[141];let Ke;t[142]!==i||t[143]!==n||t[144]!==He||t[145]!==Ue||t[146]!==We?(Ke=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":i,"data-surface-id":n,children:[He,Ue,We]}),t[142]=i,t[143]=n,t[144]=He,t[145]=Ue,t[146]=We,t[147]=Ke):Ke=t[147];let qe;return t[148]!==Re||t[149]!==Ke?(qe=(0,$.jsx)(ja.Provider,{value:Re,children:Ke}),t[148]=Re,t[149]=Ke,t[150]=qe):qe=t[150],qe},_h=e=>{let t=(0,Rc.c)(22),n=ln(),{t:r}=Xe(),i;t[0]===e.directory?i=t[1]:(i=Fm(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===Fm(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:Fa,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)(hh,{state:`directory-mismatch`,onRetry:yh,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)(ja.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)(gh,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function vh(e){return e.providers}function yh(){}var bh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},xh=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),Sh=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`&&bh(t.center)&&xh(t.attributes)&&xh(t.computedStyle)&&Array.isArray(t.ancestry)},Ch=({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(`
|
|
21
|
-
`)},wh=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await te(`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 tg(e,t)},Th=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}},Eh=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,Dh=new Map,Oh=new Map,kh=3e4,Ah=e=>{let t=Dh.get(e);return t?t.expiresAt-Date.now()<=kh?(Dh.delete(e),null):t:null},jh=e=>{try{return new URL(e).origin}catch{return e}};function Mh(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 Nh=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:Eh),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),Ph=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await Nh(n)).split(`,`,2)[1]||``},Fh=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Ih=(...e)=>{Fh()&&[...e]},Lh=(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},Rh=`data-oc-fixed-pin`,zh=(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(Rh,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 Ih(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(Rh)}catch{}}},Bh={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${Rh}]`)){let t;try{t=JSON.parse(e.getAttribute(Rh)||``)}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(Rh)}}},Vh=`data-oc-scroll-pin`,Hh=e=>{let t=[],n=Lh(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(Vh,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(Vh)}catch{}},snapshot:n}},Uh={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(`[${Vh}]`)){let t;try{t=JSON.parse(e.getAttribute(Vh)||``)}catch{e.removeAttribute(Vh);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(Vh)}}},Wh=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await Nh(await n.blob()):null}catch{return null}},Gh=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=Ah(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=Oh.get(t),i=r??(async()=>{try{let n=await V(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return Dh.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 Dh.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return Dh.set(t,o),o}catch{return Dh.delete(t),null}finally{Oh.delete(t)}})();r||Oh.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},Kh=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 Wh(n.toString(),`include`)??Eh;let r=await Gh(n);return(r?await Wh(r,`include`):null)||(await Wh(n.toString(),`omit`)??Eh)}catch{return Eh}},qh=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 Kh(n,t);r=r.replace(e[0],`url("${i}")`)}return r},Jh=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Yh=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},Xh=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},Zh=(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<=Xh(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Yh(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]?.()}},Qh=(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(Yh(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]?.()}},$h=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(Qh(e,t,n,r)),i.push(Zh(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 Jh(t);let r=await Kh(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||Eh),await Jh(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 qh(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 eg(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);Ih(`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:Lh(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=Hh(r);Ih(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await $h(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=zh(r,S,C),k.reapply();let e={backgroundColor:Mh(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Bh,Uh],quality:.82,width:w},a=await(await Pc(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)));Ih(`capture geometry`,{viewportWidth:o,viewportHeight:s,captureWidth:w,captureHeight:T,canvasWidth:a.width,canvasHeight:a.height,xScale:c,yScale:l,sourceX:m,sourceY:h,sourceWidth:u,sourceHeight:d});let g=r.createElement(`canvas`);g.width=u,g.height=d;let _=g.getContext(`2d`);if(!_)return null;_.drawImage(a,m,h,u,d,0,0,u,d);let v=await Ph(g,.82);return v?await Th(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 tg(e,t){let n=await eg(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 $h(r,o,s,{applyLayoutWorkarounds:!0}),n.scrollTo(c,l);let e=await Ic(i).catch(()=>``);h=await Fc(i,{quality:.82,pixelRatio:f,width:o,height:s,backgroundColor:Mh(r),imagePlaceholder:Eh,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 Th(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var ng=380,rg=1400,ig=600,ag=24,og=new Map,sg=200,cg=(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`,lg=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},ug=e=>Number.isFinite(e)?Math.min(rg,Math.max(ng,Math.round(e))):ig,dg=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},fg=(e,t)=>{let n=ug(e),r=dg(t);return r===null?n:Math.min(n,Math.max(1,r))},pg=(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},mg=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`plan`?`contextPanel.mode.plan`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),hg=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},gg=(e,t,n)=>{if(e.mode===`chat`){let r=vg(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 hg(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`?hg(e.targetPath)||n(`contextPanel.mode.diff`):mg(e.mode,n)},_g=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Ba,{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===`plan`)return(0,$.jsx)(X,{name:`file-text`,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`})},vg=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,yg=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},bg=(e,t)=>{if(t.length===0)return og;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?og:r},xg=(e,t)=>{let n=lt(e),r=Q.useRef(og),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=bg(n.getState().session,i.current);return yg(r.current,e)?r.current:(r.current=e,e)},[n]),()=>og)},Sg=`new Promise((resolve) => {
|
|
19
|
+
`)},[]),{drafts:De,commentText:Oe,setCommentText:ke,editingDraftId:Ae,setSelection:je,saveComment:Me,cancel:Ne,reset:q,startEdit:Fe,deleteDraft:Ie}=Bs({source:`plan`,fileLabel:G,language:j&&Lo(j)||`markdown`,getCodeForRange:e=>Ee(P,Ks(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})});Q.useEffect(()=>{_e(null),q()},[P,q]),Q.useEffect(()=>{je(ge)},[ge,je]);let Le=Q.useCallback(()=>{_e(null),Ne()},[Ne]),ze=Q.useCallback((e,t)=>{t&&_e(t),Me(e,t??ge??void 0),_e(null)},[ge,Me]);Q.useEffect(()=>{if(!ge)return;let e=e=>{let t=e.target;t.closest(`[data-comment-card="true"]`)||t.closest(`[data-comment-input="true"]`)||t.closest(`.oc-block-widget`)||t.closest(`.cm-gutterElement`)||t.closest(`[data-sonner-toast]`)||t.closest(`[data-sonner-toaster]`)||Oe.trim()||(_e(null),Ne())},t=window.setTimeout(()=>{document.addEventListener(`click`,e)},100);return()=>{window.clearTimeout(t),document.removeEventListener(`click`,e)}},[Ne,Oe,Ae,b,ge]);let Be=p(e=>e.editorFontSize),Ve=Q.useMemo(()=>{let e=j?Lo(j):null,t=!!e&&e!==`markdown`,n=[Cs(x,t?{syntaxColors:!1,fontSize:Be}:{fontSize:Be})],r=Sa(j||`plan.md`);return r&&n.push(r),t&&e&&n.push(fs({language:e,themeName:x.metadata.id,theme:ho(x)})),n.push(Ue.lineWrapping),n},[x,j,Be]),He=Q.useMemo(()=>({mode:e?`target`:`session`,sessionId:r,scopeDirectory:C||null,targetPath:e||null,repoPath:!e&&S?.slug&&S?.time?.created&&C?Kp(C,S.time.created,S.slug):null,homePath:!e&&S?.slug&&S?.time?.created?Jp(qp(S.time.created,S.slug),l||null):null}),[r,l,S?.slug,S?.time?.created,C,e]),We=!!(e||u&&He.repoPath&&He.homePath),Ge=Ep(He,{enabled:We}),Ke=n(),qe=Q.useRef(Ke);qe.current=Ke;let Je=Q.useMemo(()=>F.plans.resolved(He.mode,He.sessionId,He.scopeDirectory,He.targetPath,He.repoPath,He.homePath,Ke),[He.homePath,He.mode,He.repoPath,He.scopeDirectory,He.sessionId,He.targetPath,Ke]),Ye=Q.useMemo(()=>JSON.stringify(Je),[Je]),Ze=We&&Ge.isPending,Qe=We&&Ge.isError&&Ge.data===void 0,et=Hp(We&&Ge.data?.kind===`missing`,{path:j,content:P,baseContent:L}),tt=Ge.data?.kind===`missing`?Ge.data.candidates:null;Q.useEffect(()=>{if(!We){he.current=null,M(null),I(``),R(``),te(null);return}let e=We&&Ge.data?.kind===`resolved`?{path:Ge.data.path,content:Ge.data.content}:null,t=he.current,n=ue.current.get(Ye),r=Dp({identity:he.current,path:j,content:P,baseContent:L},Ye,e,(n?.inFlight??null)!==null),i=he.current!==Ye;if(i&&n&&!Ap(n)){let t=pe.current.get(Ye)?.path??null;r=jp(Ye,e?.path??t,n)}if(i&&t){let e=de.current.get(t);e!==void 0&&(window.clearTimeout(e),de.current.delete(t));let n=ue.current.get(t),r=pe.current.get(t);n&&r&&Rp(n)&&me.current(r)}he.current=Ye,(i||r.path!==j||r.content!==P||r.baseContent!==L)&&(M(r.path),I(r.content),R(r.baseContent),i&&te(ue.current.get(Ye)?.failed?.error??null)),(!n||Ap(n))&&ue.current.set(Ye,Op(r.baseContent));for(let e of zp(ue.current,Ye))pe.current.delete(e)},[L,P,Ye,We,Ge.data,j]);let nt=Q.useCallback(e=>{if(fe.current.has(e.identity))return;let n=(async()=>{for(;;){let n=ue.current.get(e.identity);if(!n)return;let[r,i]=Lp(n,e.transport,qe.current);if(ue.current.set(e.identity,r),!i)return;try{await e.write(i.content),await e.commit(i.content),Bp(ue.current,e.identity,i);for(let e of zp(ue.current,he.current))pe.current.delete(e);le.current&&he.current===e.identity&&(R(i.content),te(null))}catch(n){let r=n instanceof Error?n.message:t(`planView.error.saveFailed`);Vp(ue.current,e.identity,i,r);let a=ue.current.get(e.identity),o=a?.failed?.revision;le.current&&he.current===e.identity&&a&&o!==void 0&&o===a.desiredRevision&&te(r)}}})().finally(()=>{fe.current.delete(e.identity)});fe.current.set(e.identity,n)},[t]);me.current=nt,Q.useEffect(()=>{let e=de.current,n=ue.current.get(Ye)??Op(P);ue.current.set(Ye,kp(n,P));for(let e of zp(ue.current,Ye))pe.current.delete(e);if(!Up(We,j)||!j){le.current&&he.current===Ye&&te(null);return}let r=e.get(Ye);r!==void 0&&window.clearTimeout(r);let i=v.files?.writeFile,a={identity:Ye,transport:Ke,path:j,scopeDirectory:He.scopeDirectory,planKey:Je,planInput:He,write:async e=>{if(i){if(!(await i(j,e))?.success)throw Error(t(`planView.error.writeFailed`));return}let n=await V(`/api/fs/write`,{method:`POST`,headers:{"Content-Type":`application/json`,...He.scopeDirectory?{"x-opencode-directory":He.scopeDirectory}:{}},body:JSON.stringify({path:j,content:e})});if(!n.ok)throw Error(t(`planView.error.writePlanFileFailed`,{status:n.status}))},commit:async e=>{let t={scopeDirectory:He.scopeDirectory,path:j,options:{optional:!0,...He.scopeDirectory?{directory:He.scopeDirectory}:{}}};await y.cancelQueries({queryKey:Dc(t,Ke),exact:!0}),await y.cancelQueries({queryKey:Je,exact:!0}),Ec(y,t,Ke,e),y.setQueryData(Je,()=>({kind:`resolved`,source:Sp(He,j),path:j,content:e}))}};pe.current.set(Ye,a);let o=window.setTimeout(()=>{e.delete(Ye),nt(a)},350);return e.set(Ye,o),()=>{window.clearTimeout(o),e.get(Ye)===o&&e.delete(Ye)}},[P,Ye,nt,We,He,Je,Ge.data?.kind,y,j,v.files,W,t,Ke]),Q.useEffect(()=>()=>{ce.current!==null&&window.clearTimeout(ce.current)},[]);let rt=Q.useCallback(()=>{g(`chat`),_(!1)},[g,_]),it=Q.useCallback(async e=>{if(!T||!D)return;let t=await vt(D.action===`improve`?`plan.improve.visible`:`plan.implement.visible`,{plan_title:K}),n=[{synthetic:!0,text:await vt(D.action===`improve`?`plan.improve.instructions`:`plan.implement.instructions`,{plan_title:K,plan_path:j??``})}];A(!0);try{rt();let r=null,c=T.path;if(D.target===`worktree`){if(!E)return;let e=await Fa(T.path,Qa());if(!e?.id)return;r=e.id,c=e.path}else{let e=await i(void 0,T.path,null);if(!e?.id)return;r=e.id,c=e.directory??T.path,a(e.id,Ut.getState().agents??[])}if(!r)return;let l=ht.getState();l.saveSessionModelSelection(r,e.providerID,e.modelID),e.agent.trim()&&(l.saveSessionAgentSelection(r,e.agent),l.saveAgentModelForSession(r,e.agent,e.providerID,e.modelID),l.saveAgentModelVariantForSession(r,e.agent,e.providerID,e.modelID,e.variant||void 0)),s(r,c);let u=e.runAsGoal===!0?[`Implement the plan "${K}" end-to-end${j?` (plan file: ${j})`:``}.`,`Re-read that file for full details — it is the source of truth.`,``,P].join(`
|
|
20
|
+
`):null;ut.getState().setArmed(e.runAsGoal===!0,u),await o(t,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,n,e.variant||void 0),O(null)}finally{A(!1)}},[E,P,i,T,a,D,j,rt,o,K,s]),at=Q.useMemo(()=>Ws({drafts:De,editingDraftId:Ae,commentText:Oe,onTextChange:ke,selection:ge,isDragging:we,fileLabel:G,newWidgetId:`plan-new-comment-input`,mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:ze,onCancel:Le,onEdit:e=>{Fe(e),_e({start:e.startLine,end:e.endLine})},onDelete:Ie}),[Oe,Ie,Ae,Le,ze,we,ge,De,G,ke,Fe]);return(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label font-medium truncate`,children:re}),ee?(0,$.jsx)(Z,{variant:`link`,size:`xs`,className:`h-auto p-0 typography-micro text-[color:var(--status-error)]`,title:ee,onClick:()=>{let e=ue.current.get(Ye);e&&(ue.current.set(Ye,Fp(e)),te(null),ne(e=>e+1))},children:t(`planView.error.saveFailed`)}):null]}),j?(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(ta,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.improvePlanAria`),disabled:!P.trim(),children:(0,$.jsx)(X,{name:`loop-right-ai`,className:`size-4`})})})}),(0,$.jsx)(Vi,{sideOffset:8,children:t(`planView.actions.improve`)})]}),(0,$.jsxs)(ea,{align:`end`,children:[(0,$.jsx)(la,{onClick:()=>O({action:`improve`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(la,{onClick:()=>O({action:`improve`,target:`worktree`}),disabled:!E,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsxs)(ta,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(`planView.actions.implementPlanAria`),disabled:!P.trim(),children:(0,$.jsx)(X,{name:`code-ai`,className:`size-4`})})})}),(0,$.jsx)(Vi,{sideOffset:8,children:t(`planView.actions.implement`)})]}),(0,$.jsxs)(ea,{align:`end`,children:[(0,$.jsx)(la,{onClick:()=>O({action:`implement`,target:`session`}),children:t(`planView.actions.sendToNewSession`)}),(0,$.jsx)(la,{onClick:()=>O({action:`implement`,target:`worktree`}),disabled:!E,children:t(`planView.actions.sendToNewWorktreeSession`)})]})]}),(0,$.jsx)(cs,{currentMode:oe,onToggle:()=>xe(oe===`preview`?`edit`:`preview`)}),oe===`preview`&&U&&(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,className:`h-5 w-5 p-0`,"aria-label":t(z?`planView.tts.stopSpeaking`:`planView.tts.readAloud`),onClick:()=>{z?H():P.trim()&&B(P)},children:z?(0,$.jsx)(X,{name:`stop`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`volume-up`,className:`h-4 w-4`})})}),(0,$.jsx)(Vi,{sideOffset:8,children:t(z?`planView.tts.stopSpeaking`:`planView.tts.readAloud`)})]}),(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:async()=>{(await $e(P)).ok&&(ae(!0),ce.current!==null&&window.clearTimeout(ce.current),ce.current=window.setTimeout(()=>{ae(!1)},1200))},className:`h-5 w-5 p-0`,title:t(`planView.actions.copyPlanContents`),"aria-label":t(`planView.actions.copyPlanContents`),children:ie?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 text-[color:var(--status-success)]`}):(0,$.jsx)(X,{name:`clipboard`,className:`h-4 w-4`})})]}):null]}),(0,$.jsx)(xu,{open:D!==null,onOpenChange:e=>{!e&&!k&&O(null)},target:D?.target??`session`,projectDirectory:T?.path??null,submitting:k,allowRunAsGoal:!0,onConfirm:it}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 relative`,children:(0,$.jsx)(xi,{outerClassName:`h-full min-w-0`,className:`h-full min-w-0`,children:Ze?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:t(`planView.state.loading`)}):Qe?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-destructive`,children:Ge.error instanceof Error?Ge.error.message:t(`planView.error.saveFailed`)}):et&&tt?(0,$.jsx)(`div`,{className:`p-3 typography-ui text-muted-foreground`,children:tt.join(`, `)}):(0,$.jsx)(`div`,{className:`relative h-full`,children:(0,$.jsx)(`div`,{className:`h-full`,children:oe===`preview`?(0,$.jsx)(`div`,{className:`h-full overflow-auto p-3`,children:(0,$.jsx)(Yi,{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:t(`planView.error.previewUnavailable`)}),(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:t(`planView.error.switchToEditMode`)})]}),children:(0,$.jsx)(mo,{content:P,className:`typography-markdown-body`,enableFileReferences:!1})})}):(0,$.jsx)(`div`,{className:`relative h-full`,ref:ye,children:(0,$.jsx)(as,{value:P,onChange:I,readOnly:!1,className:`h-full`,extensions:Ve,onViewReady:e=>{ve.current=e},onViewDestroy:()=>{ve.current=null},blockWidgets:at,highlightLines:ge?{start:Math.min(ge.start,ge.end),end:Math.max(ge.start,ge.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(ge&&!n.shiftKey&&Math.min(ge.start,ge.end)===r&&Math.max(ge.start,ge.end)===r)return _e(null),Ne(),Se.current=!1,Ce.current=null,Te(!1),!0;if(b&&ge&&!n.shiftKey){let e=Math.min(ge.start,ge.end,r),t=Math.max(ge.start,ge.end,r);return _e({start:e,end:t}),Se.current=!1,Ce.current=null,Te(!1),!0}if(Se.current=!0,Ce.current=r,Te(!0),ge&&n.shiftKey){let e=Math.min(ge.start,r),t=Math.max(ge.end,r);_e({start:e,end:t})}else _e({start:r,end:r});return!0},mouseover:(e,t,n)=>{if(!(n instanceof MouseEvent)||n.buttons!==1||!Se.current||Ce.current===null)return!1;let r=e.state.doc.lineAt(t.from).number,i=Math.min(Ce.current,r),a=Math.max(Ce.current,r);return _e({start:i,end:a}),Te(!0),!1},mouseup:()=>(Se.current=!1,Ce.current=null,Te(!1),!1)}}})})})})})})]})},Qp=e=>e,$p=e=>{let t=Qp(e).type;return typeof t==`string`?t:``},em=e=>{let t=Qp(e).tool;return typeof t==`string`?t:``},tm=e=>{let t=Qp(e).text;return typeof t==`string`?t:``},nm=e=>{let t=$p(e);return t===`tool`?em(e).trim().toLowerCase()||`tool`:t||`unknown`},rm=e=>{if(e.length===0)return``;let t=[];for(let n of e){let e=nm(n);t.includes(e)||t.push(e)}return t.join(` + `)},im=e=>e.replace(/\s+/g,` `).trim(),am=e=>{for(let t of e)if($p(t)===`text`){let e=im(tm(t));if(e.length===0)continue;return e}let t=e.filter(e=>$p(e)!==`text`).length;return t===0?``:`${t} attachment${t===1?``:`s`}`},om=(e,t,n)=>`${n(e)} / ${n(t)}`,sm=(e,t,n,r)=>{let i=om(e,t,n);return typeof r==`string`&&r.trim().length>0?`${i} · ${r.trim()}`:i},cm=e=>{if(e===`12h`)return!0;if(e===`24h`)return!1},lm=(e,t)=>{if(!e||!Number.isFinite(e))return`-`;let n=cm(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}})},um={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},dm={user:0,assistant:0,tool:0,other:0},fm=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,pm=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{...um,total:fm(n)};if(!n||typeof n!=`object`)return um;let r=n,i=fm(r.input),a=fm(r.output),o=fm(r.reasoning),s=fm(r.cache?.read),c=fm(r.cache?.write);return{input:i,output:a,reasoning:o,cacheRead:s,cacheWrite:c,total:i+a+o+s+c}},mm=(...e)=>{for(let t of e)if(typeof t==`string`&&t.trim().length>0)return t;return``},hm=e=>typeof e==`string`?e.length:typeof e==`number`||typeof e==`boolean`?String(e).length:Array.isArray(e)?e.reduce((e,t)=>e+hm(t),0):e&&typeof e==`object`?Object.values(e).reduce((e,t)=>e+hm(t),0):0,gm=(e,t)=>{let n=e,r=typeof n.type==`string`?n.type:``;if(r===`reasoning`)return{...dm,assistant:hm(n.text)+hm(n.content)};let i=mm(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r===`tool`||t===`tool`?{user:0,assistant:0,tool:hm(n.input)+hm(n.output)+hm(n.error)+hm(n.call?.input)+hm(n.call?.output)+hm(n.call?.error)+hm(n.raw)+Math.round(hm(n.metadata)*.25)+Math.round(hm(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}},_m=(e,t)=>({user:e.user+t.user,assistant:e.assistant+t.assistant,tool:e.tool+t.tool,other:e.other+t.other}),vm=e=>{let t=$a(e.info);return t.isUser?`user`:t.role===`assistant`?`assistant`:t.role===`tool`?`tool`:`other`},ym=(e,t)=>{if(e.length===0)return{...dm};let n=e.reduce((e,t)=>{let n=vm(t),r={...dm};for(let e of t.parts)r=_m(r,gm(e,n));return _m(e,r)},{...dm});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)}},bm=e=>e.toLocaleString(Qe()),xm=e=>!Number.isFinite(e)||e<=0?new Intl.NumberFormat(Qe(),{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(Qe(),{style:`currency`,currency:`USD`,minimumFractionDigits:e<.01?4:2,maximumFractionDigits:e<.01?4:2}).format(e),Sm=(e,t)=>!e||!Number.isFinite(e)?`-`:ya(e,t,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`}),Cm=(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}},wm=()=>{let e=(0,zc.c)(259),{t}=Xe(),n=p(Tm),r=p(Em),i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={},e[0]=i):i=e[0];let[a,o]=Q.useState(i),[s,c]=Q.useState(null),l=Q.useRef(null),u=Tn(Dm),d=Hn(),f=rt(u??``),m=Ut(Om),h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(km),c(null)},e[1]=h):h=e[1];let g;e[2]===u?g=e[3]:(g=[u],e[2]=u,e[3]=g),Q.useEffect(h,g);let _,v;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},v=[],e[4]=_,e[5]=v):(_=e[4],v=e[5]),Q.useEffect(_,v);let y;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=async(e,t)=>{(await $e(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]=y):y=e[6];let b=y,x;e[7]!==u||e[8]!==d?(x=u?d.find(e=>e.id===u)??null:null,e[7]=u,e[8]=d,e[9]=x):x=e[9];let S=x,C,w,T,E,D,O,k,A;if(e[10]!==m||e[11]!==f){C=f.filter(Am);let t;e[20]===f?t=e[21]:(t=f.filter(jm),e[20]=f,e[21]=t),A=t;let n=null;for(let e=C.length-1;e>=0;--e){let t=C[e];if(pm(t).total>0){n=t;break}}O=n?pm(n):um,w=Ra({input:O.input,cache:{read:O.cacheRead,write:O.cacheWrite}}),k=C.reduce(Mm,0);let r=0,i=0;for(let e of C){let t=pm(e),n=e.info.time?.created??null,a=e.info.time?.completed??null,o=qa(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:Ya(a),e[22]=a,e[23]=o),E=o;let s=n?oo({createdAt:n.info.time?.created??null,completedAt:n.info.time?.completed??null,outputTokens:O.output,reasoningTokens:O.reasoning,parts:n.parts}):null;T=s===null?null:Ya(s);let c=n?.info??null;D=Cm(m,c?.providerID||``,c?.modelID||``),e[10]=m,e[11]=f,e[12]=C,e[13]=w,e[14]=T,e[15]=E,e[16]=D,e[17]=O,e[18]=k,e[19]=A}else C=e[12],w=e[13],T=e[14],E=e[15],D=e[16],O=e[17],k=e[18],A=e[19];let j=D,M=j.contextLimit,N=M&&M>0?Math.min(999,O.total/M*100):0,P;e[24]===f?P=e[25]:(P=ym(f,[...f].reverse().find(Nm)?.info?.system||``),e[24]=f,e[25]=P);let F=P,I=F.user,L=F.assistant,R=F.tool,z=Math.max(0,O.input-I-L-R),B=I+L+R+z,V=f[0]?.info?.time?.created,H=f.length>0?f[f.length-1]?.info?.time?.created:null,U;e[26]!==S?.title||e[27]!==t?(U=S?.title||t(`contextSidebar.session.untitled`),e[26]=S?.title,e[27]=t,e[28]=U):U=e[28];let ee=S?.time?.created??V??null,te=H??S?.time?.created??null,W=E&&E.length>0?E:null,ne=T&&T.length>0?T:null,G;e[29]!==L||e[30]!==z||e[31]!==R||e[32]!==I?(G={user:I,assistant:L,tool:R,other:z},e[29]=L,e[30]=z,e[31]=R,e[32]=I,e[33]=G):G=e[33];let re;e[34]!==C.length||e[35]!==B||e[36]!==w||e[37]!==M||e[38]!==j||e[39]!==f.length||e[40]!==ee||e[41]!==te||e[42]!==W||e[43]!==ne||e[44]!==G||e[45]!==U||e[46]!==O||e[47]!==k||e[48]!==N||e[49]!==A.length?(re={sessionTitle:U,messagesCount:f.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:ee,lastActivityAt:te,providerModel:j,tokenBreakdown:O,usagePercent:N,cacheHitRate:w,totalAssistantCost:k,sessionTpsLabel:W,lastAssistantTpsLabel:ne,contextLimit:M,breakdown:G,breakdownTotal:B},e[34]=C.length,e[35]=B,e[36]=w,e[37]=M,e[38]=j,e[39]=f.length,e[40]=ee,e[41]=te,e[42]=W,e[43]=ne,e[44]=G,e[45]=U,e[46]=O,e[47]=k,e[48]=N,e[49]=A.length,e[50]=re):re=e[50];let K=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]!==K.breakdown.user?(ae={key:`user`,label:ie,value:K.breakdown.user,color:`var(--status-success)`},e[57]=ie,e[58]=K.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]!==K.breakdown.assistant?(se={key:`assistant`,label:oe,value:K.breakdown.assistant,color:`var(--primary-base)`},e[62]=oe,e[63]=K.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]!==K.breakdown.tool?(le={key:`tool`,label:ce,value:K.breakdown.tool,color:`var(--status-warning)`},e[67]=ce,e[68]=K.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]!==K.breakdown.other?(de={key:`other`,label:ue,value:K.breakdown.other,color:`var(--surface-muted-foreground)`},e[72]=ue,e[73]=K.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]===K.sessionTitle?me=e[81]:(me=(0,$.jsx)(`h2`,{className:`typography-ui-header font-semibold text-foreground truncate`,children:K.sessionTitle}),e[80]=K.sessionTitle,e[81]=me);let he;e[82]!==K.providerModel.modelName||e[83]!==K.providerModel.providerName?(he=(0,$.jsxs)(`span`,{children:[K.providerModel.providerName,` / `,K.providerModel.modelName]}),e[82]=K.providerModel.modelName,e[83]=K.providerModel.providerName,e[84]=he):he=e[84];let ge;e[85]!==n||e[86]!==K.createdAt?(ge=K.createdAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`·`}),(0,$.jsx)(`span`,{children:Sm(K.createdAt,n)})]}),e[85]=n,e[86]=K.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]===K.tokenBreakdown.total?xe=e[99]:(xe=bm(K.tokenBreakdown.total),e[98]=K.tokenBreakdown.total,e[99]=xe);let Se;e[100]===K.contextLimit?Se=e[101]:(Se=K.contextLimit?` / ${bm(K.contextLimit)}`:``,e[100]=K.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]===K.usagePercent?Te=e[109]:(Te=K.usagePercent>0&&(0,$.jsx)(`div`,{className:`rounded-full transition-all duration-300`,style:{width:`${Math.max(.5,K.usagePercent)}%`,backgroundColor:K.usagePercent>80?`var(--status-warning)`:`var(--primary-base)`}}),e[108]=K.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]!==K.usagePercent?(De=t(`contextSidebar.context.percentUsed`,{percent:K.usagePercent.toFixed(1)}),e[112]=t,e[113]=K.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]===K.messagesCount?je=e[124]:(je=bm(K.messagesCount),e[123]=K.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 q;e[130]===K.userMessagesCount?q=e[131]:(q=bm(K.userMessagesCount),e[130]=K.userMessagesCount,e[131]=q);let Pe;e[132]!==Ne||e[133]!==q?(Pe={label:Ne,value:q},e[132]=Ne,e[133]=q,e[134]=Pe):Pe=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]===K.assistantMessagesCount?Ie=e[138]:(Ie=bm(K.assistantMessagesCount),e[137]=K.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]!==Pe||e[144]!==Le?(Re=[Me,Pe,Le],e[142]=Me,e[143]=Pe,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(Pm)}),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]===K.totalAssistantCost?Ge=e[155]:(Ge=xm(K.totalAssistantCost),e[154]=K.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 qe;e[158]!==We||e[159]!==Ke?(qe=(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]=qe):qe=e[160];let Je;e[161]!==r||e[162]!==t||e[163]!==K.sessionTpsLabel?(Je=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:K.sessionTpsLabel??`—`})]}):null,e[161]=r,e[162]=t,e[163]=K.sessionTpsLabel,e[164]=Je):Je=e[164];let Ye;e[165]!==He||e[166]!==qe||e[167]!==Je?(Ye=(0,$.jsxs)(`div`,{className:He,children:[qe,Je]}),e[165]=He,e[166]=qe,e[167]=Je,e[168]=Ye):Ye=e[168];let Ze;e[169]!==Be||e[170]!==Ye?(Ze=(0,$.jsxs)(`div`,{className:`mb-5 space-y-2`,children:[Be,Ye]}),e[169]=Be,e[170]=Ye,e[171]=Ze):Ze=e[171];let Qe;e[172]===t?Qe=e[173]:(Qe=t(`contextSidebar.section.lastAssistantMessage`),e[172]=t,e[173]=Qe);let et;e[174]===Qe?et=e[175]:(et=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground mb-2.5`,children:Qe}),e[174]=Qe,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]!==K.tokenBreakdown.input?(nt={label:tt,value:K.tokenBreakdown.input,format:`count`},e[178]=tt,e[179]=K.tokenBreakdown.input,e[180]=nt):nt=e[180];let it;e[181]===t?it=e[182]:(it=t(`contextSidebar.tokens.output`),e[181]=t,e[182]=it);let at;e[183]!==it||e[184]!==K.tokenBreakdown.output?(at={label:it,value:K.tokenBreakdown.output,format:`count`},e[183]=it,e[184]=K.tokenBreakdown.output,e[185]=at):at=e[185];let ot;e[186]===t?ot=e[187]:(ot=t(`contextSidebar.tokens.reasoning`),e[186]=t,e[187]=ot);let st;e[188]!==ot||e[189]!==K.tokenBreakdown.reasoning?(st={label:ot,value:K.tokenBreakdown.reasoning,format:`count`},e[188]=ot,e[189]=K.tokenBreakdown.reasoning,e[190]=st):st=e[190];let ct;e[191]===t?ct=e[192]:(ct=t(`contextSidebar.tokens.cacheRead`),e[191]=t,e[192]=ct);let lt;e[193]!==ct||e[194]!==K.tokenBreakdown.cacheRead?(lt={label:ct,value:K.tokenBreakdown.cacheRead,format:`count`},e[193]=ct,e[194]=K.tokenBreakdown.cacheRead,e[195]=lt):lt=e[195];let ut;e[196]===t?ut=e[197]:(ut=t(`contextSidebar.tokens.cacheWrite`),e[196]=t,e[197]=ut);let dt;e[198]!==ut||e[199]!==K.tokenBreakdown.cacheWrite?(dt={label:ut,value:K.tokenBreakdown.cacheWrite,format:`count`},e[198]=ut,e[199]=K.tokenBreakdown.cacheWrite,e[200]=dt):dt=e[200];let ft;e[201]===t?ft=e[202]:(ft=t(`contextSidebar.tokens.cacheHit`),e[201]=t,e[202]=ft);let pt=K.cacheHitRate.hasInput?K.cacheHitRate.percent:null,mt;e[203]!==ft||e[204]!==pt?(mt={label:ft,value:pt,format:`percent`},e[203]=ft,e[204]=pt,e[205]=mt):mt=e[205];let ht;e[206]!==r||e[207]!==t||e[208]!==K.lastAssistantTpsLabel?(ht=r?[{label:t(`contextSidebar.tokens.tps`),value:K.lastAssistantTpsLabel,format:`text`}]:[],e[206]=r,e[207]=t,e[208]=K.lastAssistantTpsLabel,e[209]=ht):ht=e[209];let gt;e[210]!==nt||e[211]!==at||e[212]!==st||e[213]!==lt||e[214]!==dt||e[215]!==mt||e[216]!==ht?(gt=(0,$.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-2.5`,children:[nt,at,st,lt,dt,mt,...ht].map(Fm)}),e[210]=nt,e[211]=at,e[212]=st,e[213]=lt,e[214]=dt,e[215]=mt,e[216]=ht,e[217]=gt):gt=e[217];let _t;e[218]!==et||e[219]!==gt?(_t=(0,$.jsxs)(`div`,{className:`mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5`,children:[et,gt]}),e[218]=et,e[219]=gt,e[220]=_t):_t=e[220];let vt;e[221]!==pe||e[222]!==K.breakdownTotal?(vt=(0,$.jsx)(`div`,{className:`flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]`,children:pe.map(e=>e.value<=0||K.breakdownTotal<=0?null:(0,$.jsx)(`div`,{style:{width:`${e.value/K.breakdownTotal*100}%`,backgroundColor:e.color}},e.key))}),e[221]=pe,e[222]=K.breakdownTotal,e[223]=vt):vt=e[223];let yt;e[224]!==pe||e[225]!==K.breakdownTotal?(yt=(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:pe.map(e=>{let t=K.breakdownTotal>0?e.value/K.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]=K.breakdownTotal,e[226]=yt):yt=e[226];let bt;e[227]!==vt||e[228]!==yt?(bt=(0,$.jsxs)(`div`,{className:`mb-6`,children:[vt,yt]}),e[227]=vt,e[228]=yt,e[229]=bt):bt=e[229];let xt;e[230]===t?xt=e[231]:(xt=t(`contextSidebar.section.rawMessages`),e[230]=t,e[231]=xt);let St;e[232]===xt?St=e[233]:(St=(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:xt}),e[232]=xt,e[233]=St);let Ct;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=$a(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=rm(e.parts),h=c?pm({info:e.info,parts:e.parts}):null,g=l?am(e.parts):``,_=lm(f,n),v=m||`—`,y=(()=>{if(!r||!c||!h)return null;let t=oo({createdAt:f,completedAt:p,outputTokens:h.output,reasoningTokens:h.reasoning,parts:e.parts});if(t===null)return null;let n=Ya(t);return n.length>0?n:null})(),x=h?sm(h.input,h.output,bm,y):``,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(),b(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)(Qo,{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],Ct=[...f].reverse().map(i),e[234]=s,e[235]=a,e[236]=f,e[237]=r,e[238]=t,e[239]=n,e[240]=Ct}else Ct=e[240];let wt;e[247]===Ct?wt=e[248]:(wt=(0,$.jsx)(`div`,{className:`mt-2.5 space-y-1`,children:Ct}),e[247]=Ct,e[248]=wt);let Tt;e[249]!==St||e[250]!==wt?(Tt=(0,$.jsxs)(`div`,{children:[St,wt]}),e[249]=St,e[250]=wt,e[251]=Tt):Tt=e[251];let Et;return e[252]!==ve||e[253]!==ke||e[254]!==Ze||e[255]!==_t||e[256]!==bt||e[257]!==Tt?(Et=(0,$.jsx)(`div`,{className:`h-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-[52rem] px-5 py-6`,children:[ve,ke,Ze,_t,bt,Tt]})}),e[252]=ve,e[253]=ke,e[254]=Ze,e[255]=_t,e[256]=bt,e[257]=Tt,e[258]=Et):Et=e[258],Et};function Tm(e){return e.timeFormatPreference}function Em(e){return e.showAssistantTps}function Dm(e){return e.currentSessionId}function Om(e){return e.providers}function km(e){return Object.keys(e).length>0?{}:e}function Am(e){return $a(e.info).role===`assistant`}function jm(e){return $a(e.info).isUser}function Mm(e,t){return e+fm(t.info.cost)}function Nm(e){return $a(e.info).isUser&&typeof e.info.system==`string`}function Pm(e){return(0,$.jsxs)(`div`,{className:`rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.value})]},e.label)}function Fm(e){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground/70`,children:e.label}),(0,$.jsx)(`div`,{className:`mt-0.5 typography-ui-label tabular-nums text-foreground`,children:e.format===`text`?typeof e.value==`string`&&e.value.length>0?e.value:`—`:e.value!==null&&e.value!==void 0?e.format===`percent`?`${Number(e.value).toFixed(1)}%`:bm(Number(e.value)):`—`})]},e.label)}var Im=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(`/`)?`/`:``)},Lm=()=>`react-surface`,Rm=(e,t)=>JSON.stringify([Im(e),t]),zm=(e,t,n,r)=>JSON.stringify([e,t,Im(n),r]),Bm=(e,t,n)=>n?t:e===t?e:null,Vm=(e,t)=>e.sessionId===t.sessionId&&Im(e.directory)===Im(t.directory),Hm=(e,t)=>Im(e)===Im(t),Um=e=>({anchor:e,current:e,stack:[]}),Wm=(e,t)=>e??Um(t),Gm=(e,t)=>e?.current.sessionId??t,Km=(e,t)=>Vm(e.current,t)?e:{...e,current:t,stack:[...e.stack,e.current]},qm=e=>{let t=e.stack[e.stack.length-1];return t?{...e,current:t,stack:e.stack.slice(0,-1)}:e},Jm=(e,t,n)=>!Hm(e.anchor.directory,t.directory)||!Hm(e.current.directory,t.directory)||n(t.sessionId,t.directory)===!1?{status:`rejected-cross-directory`,state:e}:{status:`navigated`,state:Km(e,t)},Ym=(e,t,n)=>{let r=e[t];if(!r)return{accepted:!1,navigationBySurfaceId:e};let i=Jm(r,n,()=>!0);return i.status===`navigated`?{accepted:!0,navigationBySurfaceId:i.state===r?e:{...e,[t]:i.state}}:{accepted:!1,navigationBySurfaceId:e}},Xm=(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},Zm=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`,Qm=e=>e===`retry`,$m=e=>e.active&&e.visible&&e.messageCount<=0,eh=e=>e?`load-more`:`ensure`,th=e=>e.kind===`has-more`,nh=(e,t)=>`${e}\n${t}`,rh=(e,t,n,r)=>r&&!e.has(nh(t,n)),ih=(e,t)=>({scrollHeight:e,scrollTop:t}),ah=(e,t)=>Math.max(0,e.scrollTop+Math.max(0,t-e.scrollHeight)),oh=(e,t)=>e&&!t,sh=e=>e,ch=e=>!e,lh=e=>!oh(e.hasMore,e.isLoading)||!ch(e.historyVirtualized)?null:ih(e.scrollHeight,e.scrollTop),uh=(e,t,n)=>!!(e&&e.token===t&&e.viewportKey===n),dh=33554432,fh=e=>Math.min(dh,262144+Math.max(0,Math.ceil(e))*64*1024),ph=e=>Math.min(dh,Math.max(0,Math.round(Number.isFinite(e)?e:0))),mh=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}},hh=(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 mh({...e,activeViewKey:t.viewKey,mountedViews:r})}if(t.type===`estimate`){let n=e.mountedViews[t.viewKey],r=ph(t.estimatedBytes);return!n||n.estimatedBytes===r?e:mh({...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:mh({...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??fh(0),lastAccessed:t.now}}})},gh=e=>{let t=(0,zc.c)(17),{state:n,error:r,onRetry:i}=e,{t:a}=Xe();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},_h=e=>{let t=(0,zc.c)(151),{surfaceId:n,sessionId:i,directory:a,active:o,canNavigateBack:s,onNavigateSession:c,onNavigateBack:l,onEstimateBytes:u,syncDirectory:d}=e,{t:f}=Xe(),p=io(),m,h,g;t[0]!==a||t[1]!==i||t[2]!==n?(h=r(),m=Im(a),g=zm(h,n,m,i),t[0]=a,t[1]=i,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=qt(i,d),E=rt(i,d),D=Ut(yh),O;t[7]===E?O=t[8]:(O=to(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)&&Rt(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=Zt(i,d),N=Wt(i,d).renderable,P;t[17]===i?P=t[18]:(P=e=>!!e.session.find(e=>e.id===i)?.parentID,t[17]=i,t[18]=P);let F=Bt(P,d),[I,L]=Q.useState(null),R,z;t[19]!==F||t[20]!==_?(R=()=>{L(e=>Bm(e,_,F))},z=[F,_],t[19]=F,t[20]=_,t[21]=R,t[22]=z):(R=t[21],z=t[22]),Q.useLayoutEffect(R,z);let B=F||I===_,V=Mt(i,d),H;t[23]===i?H=t[24]:(H=e=>e.streamingMessageIds.get(i)??null,t[23]=i,t[24]=H);let U=tn(H),ee;t[25]===U?ee=t[26]:(ee=e=>U?e.messageStreamStates.get(U)?.phase??null:null,t[25]=U,t[26]=ee);let te=tn(ee),W=M?.type===`busy`||M?.type===`retry`,ne;t[27]!==i||t[28]!==W||t[29]!==T||t[30]!==_?(ne={currentSessionId:i,viewportKey:_,sessionMessageCount:T,sessionIsWorking:W,isMobile:!1},t[27]=i,t[28]=W,t[29]=T,t[30]=_,t[31]=ne):ne=t[31];let{scrollRef:G,notifyContentChange:re,getAnimationHandlers:K,goToBottom:ie,restoreSnapshot:ae,showScrollButton:oe}=Wa(ne),se;t[32]!==i||t[33]!==p?(se=e=>{p.ensureSessionRenderable(i,Qm(e))},t[32]=i,t[33]=p,t[34]=se):se=t[34];let ce=Ge(se),le,ue;t[35]!==o||t[36]!==ce?(le=()=>{o&&ce(`active`)},ue=[o,ce],t[35]=o,t[36]=ce,t[37]=le,t[38]=ue):(le=t[37],ue=t[38]),Q.useEffect(le,ue);let de,fe;t[39]!==o||t[40]!==ce||t[41]!==T?(de=()=>{if(typeof window>`u`)return;let e=()=>{let e=document.visibilityState!==`hidden`&&document.hasFocus();$m({active:o,visible:e,messageCount:T})&&ce(`retry`)};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},fe=[o,ce,T],t[39]=o,t[40]=ce,t[41]=T,t[42]=de,t[43]=fe):(de=t[42],fe=t[43]),Q.useEffect(de,fe);let pe,me;t[44]!==u||t[45]!==T||t[46]!==_?(pe=()=>{u?.(_,fh(T))},me=[u,T,_],t[44]=u,t[45]=T,t[46]=_,t[47]=pe,t[48]=me):(pe=t[47],me=t[48]),Q.useEffect(pe,me);let he,ge;t[49]!==N||t[50]!==ae||t[51]!==i||t[52]!==_?(he=()=>{if(!rh(w.current,i,_,N))return;let e=nh(i,_);w.current.add(e),ae()},ge=[N,ae,i,_],t[49]=N,t[50]=ae,t[51]=i,t[52]=_,t[53]=he,t[54]=ge):(he=t[53],ge=t[54]),Q.useEffect(he,ge);let _e;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>{y.current=null,S(null)},t[55]=_e):_e=t[55];let ve;t[56]===_?ve=t[57]:(ve=[_],t[56]=_,t[57]=ve),Q.useLayoutEffect(_e,ve);let ye;t[58]!==x||t[59]!==G||t[60]!==_?(ye=()=>{let e=y.current,t=G.current;if(uh(e,x,_)){if(!t||!ch(!!v.current?.isHistoryVirtualized())){y.current=null;return}t.scrollTop=ah(e.anchor,t.scrollHeight),y.current=null}},t[58]=x,t[59]=G,t[60]=_,t[61]=ye):ye=t[61];let be;t[62]!==x||t[63]!==G||t[64]!==E||t[65]!==_?(be=[x,G,E,_],t[62]=x,t[63]=G,t[64]=E,t[65]=_,t[66]=be):be=t[66],Q.useLayoutEffect(ye,be);let xe;t[67]===m?xe=t[68]:(xe={directory:m},t[67]=m,t[68]=xe);let Se=xe,Ce=Dn(i,d).boundary,we;t[69]===Ce?we=t[70]:(we=th(Ce),t[69]=Ce,t[70]=we);let Te=we,Ee;t[71]!==V?.status||t[72]!==Se||t[73]!==i||t[74]!==p?(Ee=V?.status===`loading`||p.isLoading(i,Se),t[71]=V?.status,t[72]=Se,t[73]=i,t[74]=p,t[75]=Ee):Ee=t[75];let De=Ee,Oe;t[76]!==m||t[77]!==h||t[78]!==i?(Oe=[`context-panel-load-older`,h,m,i],t[76]=m,t[77]=h,t[78]=i,t[79]=Oe):Oe=t[79];let ke;t[80]!==Ce||t[81]!==i||t[82]!==d?(ke=async()=>{Ce.kind===`unknown`&&await En(d,i),await Vn(d,i)},t[80]=Ce,t[81]=i,t[82]=d,t[83]=ke):ke=t[83];let Ae;t[84]!==Oe||t[85]!==ke?(Ae={mutationKey:Oe,mutationFn:ke},t[84]=Oe,t[85]=ke,t[86]=Ae):Ae=t[86];let je=ze(Ae),Me=je.isPending,Ne;t[87]!==De||t[88]!==Te||t[89]!==Me||t[90]!==je||t[91]!==G||t[92]!==f||t[93]!==_?(Ne=()=>{if(!oh(Te,Me||De)||je.isPending)return;let e=b.current+1;b.current=e;let t=G.current,n=t?lh({hasMore:Te,isLoading:Me,historyVirtualized:!!v.current?.isHistoryVirtualized(),scrollHeight:t.scrollHeight,scrollTop:t.scrollTop}):null;y.current=n?{token:e,viewportKey:_,anchor:n}:null,je.mutateAsync().then(()=>{S(e)},()=>{S(e),J.error(f(`chat.history.loadOlderFailed`))})},t[87]=De,t[88]=Te,t[89]=Me,t[90]=je,t[91]=G,t[92]=f,t[93]=_,t[94]=Ne):Ne=t[94];let q=Ge(Ne),Pe=V?.status===`error`?V.error:void 0,Fe;t[95]!==o||t[96]!==N||t[97]!==W||t[98]!==E.length||t[99]!==Pe?(Fe=Zm({directoryMatches:!0,requested:o,renderable:N,messageCount:E.length,working:W,error:Pe}),t[95]=o,t[96]=N,t[97]=W,t[98]=E.length,t[99]=Pe,t[100]=Fe):Fe=t[100];let Ie=Fe,Le;t[101]!==o||t[102]!==m||t[103]!==c||t[104]!==i||t[105]!==n?(Le={kind:`panel`,surfaceId:n,sessionId:i,directory:m,active:o,capabilities:Ia,navigateSession:c},t[101]=o,t[102]=m,t[103]=c,t[104]=i,t[105]=n,t[106]=Le):Le=t[106];let Re=Le,Be;t[107]!==ce||t[108]!==Te||t[109]!==q?(Be=()=>{if(eh(Te)===`load-more`){q();return}ce(`retry`)},t[107]=ce,t[108]=Te,t[109]=q,t[110]=Be):Be=t[110];let Ve=Ge(Be),He;t[111]!==s||t[112]!==l||t[113]!==f?(He=s?(0,$.jsxs)(Z,{type:`button`,variant:`outline`,size:`xs`,onClick:l,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[111]=s,t[112]=l,t[113]=f,t[114]=He):He=t[114];let Ue;t[115]!==te||t[116]!==ce||t[117]!==K||t[118]!==ie||t[119]!==Te||t[120]!==Me||t[121]!==q||t[122]!==re||t[123]!==V?.error||t[124]!==Ve||t[125]!==G||t[126]!==i||t[127]!==W||t[128]!==E||t[129]!==oe||t[130]!==U||t[131]!==d||t[132]!==f||t[133]!==Ie||t[134]!==_?(Ue=(0,$.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:Ie===`cold-loading`||Ie===`working-empty`||Ie===`authoritative-empty`||Ie===`fatal-error`?(0,$.jsx)(gh,{state:Ie,error:V?.error,onRetry:()=>ce(`retry`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ai,{ref:G,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:[Ie===`partial-error`?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--status-error-foreground)]`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:V?.error}),(0,$.jsx)(Z,{type:`button`,variant:`secondary`,size:`xs`,onClick:Ve,children:f(`chat.history.retry`)})]}):null,sh(Te)?(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsxs)(Z,{type:`button`,variant:`secondary`,size:`sm`,onClick:q,disabled:Me,children:[Me?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):null,f(`chat.history.loadOlder`)]})}):null,(0,$.jsx)(Ka,{ref:v,sessionKey:i,virtualizerKey:_,messages:E,sessionIsWorking:W,activeStreamingMessageId:U,activeStreamingPhase:te,onMessageContentChange:re,getAnimationHandlers:K,isLoadingOlder:Me,scrollToBottom:()=>ie(`instant`),scrollRef:G,directory:d}),(0,$.jsx)(`div`,{className:`h-12`,"aria-hidden":`true`})]})}),(0,$.jsx)(no,{visible:oe,onClick:()=>ie(`smooth`)})]})}),t[115]=te,t[116]=ce,t[117]=K,t[118]=ie,t[119]=Te,t[120]=Me,t[121]=q,t[122]=re,t[123]=V?.error,t[124]=Ve,t[125]=G,t[126]=i,t[127]=W,t[128]=E,t[129]=oe,t[130]=U,t[131]=d,t[132]=f,t[133]=Ie,t[134]=_,t[135]=Ue):Ue=t[135];let We;t[136]!==k.agentName||t[137]!==k.modelId||t[138]!==k.providerId||t[139]!==j||t[140]!==B?(We=B?(0,$.jsx)(Xa,{agentName:k.agentName,providerId:k.providerId,modelId:k.modelId,modelName:j}):null,t[136]=k.agentName,t[137]=k.modelId,t[138]=k.providerId,t[139]=j,t[140]=B,t[141]=We):We=t[141];let Ke;t[142]!==i||t[143]!==n||t[144]!==He||t[145]!==Ue||t[146]!==We?(Ke=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-background`,"data-context-session-surface":`true`,"data-session-id":i,"data-surface-id":n,children:[He,Ue,We]}),t[142]=i,t[143]=n,t[144]=He,t[145]=Ue,t[146]=We,t[147]=Ke):Ke=t[147];let qe;return t[148]!==Re||t[149]!==Ke?(qe=(0,$.jsx)(Ma.Provider,{value:Re,children:Ke}),t[148]=Re,t[149]=Ke,t[150]=qe):qe=t[150],qe},vh=e=>{let t=(0,zc.c)(22),n=sn(),{t:r}=Xe(),i;t[0]===e.directory?i=t[1]:(i=Im(e.directory),t[0]=e.directory,t[1]=i);let a=i,o=a===Im(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:Ia,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)(gh,{state:`directory-mismatch`,onRetry:bh,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)(Ma.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)(_h,{...e,syncDirectory:n}),t[19]=e,t[20]=n,t[21]=l):l=t[21],l};function yh(e){return e.providers}function bh(){}var xh=e=>{if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.x==`number`&&typeof t.y==`number`},Sh=e=>!e||typeof e!=`object`?!1:Object.values(e).every(e=>typeof e==`string`),Ch=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`&&xh(t.center)&&Sh(t.attributes)&&Sh(t.computedStyle)&&Array.isArray(t.ancestry)},wh=({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(`
|
|
21
|
+
`)},Th=async(e,t)=>{if(typeof window<`u`)try{let n=e.getBoundingClientRect(),r=await te(`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 ng(e,t)},Eh=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}},Dh=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=`,Oh=new Map,kh=new Map,Ah=3e4,jh=e=>{let t=Oh.get(e);return t?t.expiresAt-Date.now()<=Ah?(Oh.delete(e),null):t:null},Mh=e=>{try{return new URL(e).origin}catch{return e}};function Nh(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 Ph=e=>new Promise((t,n)=>{let r=new FileReader;r.onloadend=()=>t(typeof r.result==`string`?r.result:Dh),r.onerror=()=>n(r.error??Error(`Failed to read image blob`)),r.readAsDataURL(e)}),Fh=async(e,t=.82)=>{let n=await new Promise(n=>e.toBlob(n,`image/jpeg`,t));return n&&(await Ph(n)).split(`,`,2)[1]||``},Ih=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Lh=(...e)=>{Ih()&&[...e]},Rh=(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},zh=`data-oc-fixed-pin`,Bh=(e,t,n)=>{if(t<=0&&n<=0)return()=>{};let r=e.defaultView;if(!r)return()=>{};let i=[],a=[];try{for(let o of e.querySelectorAll(`*`)){if(r.getComputedStyle(o).position!==`fixed`)continue;let e=o.getBoundingClientRect();if(!(e.width>0&&e.height>0))continue;o.setAttribute(zh,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 Lh(`tagged fixed elements`,a),()=>{for(let e of i)try{e.removeAttribute(zh)}catch{}}},Vh={name:`oc-fixed-pin`,afterClone(e){let t=e?.clone;if(!(!t||typeof t.querySelectorAll!=`function`))for(let e of t.querySelectorAll(`[${zh}]`)){let t;try{t=JSON.parse(e.getAttribute(zh)||``)}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(zh)}}},Hh=`data-oc-scroll-pin`,Uh=e=>{let t=[],n=Rh(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(Hh,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(Hh)}catch{}},snapshot:n}},Wh={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(`[${Hh}]`)){let t;try{t=JSON.parse(e.getAttribute(Hh)||``)}catch{e.removeAttribute(Hh);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(Hh)}}},Gh=async(e,t)=>{try{let n=await fetch(e,{credentials:t});return n.ok?await Ph(await n.blob()):null}catch{return null}},Kh=async e=>{if(e.protocol!==`http:`&&e.protocol!==`https:`)return``;let t=e.origin,n=jh(t);if(n)return`${n.proxyBasePath}${e.pathname}${e.search}${e.hash}`;let r=kh.get(t),i=r??(async()=>{try{let n=await V(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:e.toString(),allowExternal:!0})});if(!n.ok)return Oh.delete(t),null;let r=await n.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i)return Oh.delete(t),null;let o={proxyBasePath:i,expiresAt:a};return Oh.set(t,o),o}catch{return Oh.delete(t),null}finally{kh.delete(t)}})();r||kh.set(t,i);let a=await i;return a?`${a.proxyBasePath}${e.pathname}${e.search}${e.hash}`:``},qh=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 Gh(n.toString(),`include`)??Dh;let r=await Kh(n);return(r?await Gh(r,`include`):null)||(await Gh(n.toString(),`omit`)??Dh)}catch{return Dh}},Jh=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 qh(n,t);r=r.replace(e[0],`url("${i}")`)}return r},Yh=e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}),Xh=e=>{let t=e.style.cssText;return()=>{e.style.cssText=t}},Zh=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},Qh=(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<=Zh(s)*1.7;!u&&(!d||o.width>t*.72)||(r.push(Xh(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]?.()}},$h=(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(Xh(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]?.()}},eg=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($h(e,t,n,r)),i.push(Qh(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 Yh(t);let r=await qh(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||Dh),await Yh(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 Jh(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 tg(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);Lh(`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:Rh(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=Uh(r);Lh(`nested scroll snapshot`,k.snapshot);let A=()=>{},j=()=>{};try{await r.fonts?.ready.catch(()=>void 0),A=await eg(r,o,s,{applyLayoutWorkarounds:!1}),n.scrollTo(S,C),j=Bh(r,S,C),k.reapply();let e={backgroundColor:Nh(r),cache:`disabled`,dpr:E,embedFonts:!0,fast:!1,height:T,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Vh,Wh],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)));Lh(`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 Fh(g,.82);return v?await Eh(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 ng(e,t){let n=await tg(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 eg(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:Nh(r),imagePlaceholder:Dh,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 Eh(_,o,s,o,s,t):null}catch(e){return console.warn(`[preview] failed to capture iframe DOM screenshot:`,e),null}}var rg=380,ig=1400,ag=600,og=24,sg=new Map,cg=200,lg=(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`,ug=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+$/g,``);return r=r.replace(/\/+/g,`/`),n&&!r.startsWith(`//`)&&(r=`/${r}`),r===``?t.startsWith(`/`)?`/`:``:r},dg=e=>Number.isFinite(e)?Math.min(ig,Math.max(rg,Math.round(e))):ag,fg=e=>{let t=e?.parentElement?.clientWidth;return!t||t<=0?null:t},pg=(e,t)=>{let n=dg(e),r=fg(t);return r===null?n:Math.min(n,Math.max(1,r))},mg=(e,t)=>{if(!e)return``;let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`).replace(/\/+$/,``);return r&&n.startsWith(r+`/`)?n.slice(r.length+1):n},hg=(e,t)=>t(e===`chat`?`contextPanel.mode.chat`:e===`file`?`contextPanel.mode.files`:e===`diff`||e===`file-diff`?`contextPanel.mode.diff`:e===`plan`?`contextPanel.mode.plan`:e===`preview`?`contextPanel.mode.preview`:e===`browser`?`contextPanel.mode.browser`:`contextPanel.mode.context`),gg=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},_g=(e,t,n)=>{if(e.mode===`chat`){let r=yg(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 gg(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`?gg(e.targetPath)||n(`contextPanel.mode.diff`):hg(e.mode,n)},vg=e=>{if(e.mode===`file`)return e.targetPath?(0,$.jsx)(Va,{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===`plan`)return(0,$.jsx)(X,{name:`file-text`,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`})},yg=e=>!e||!e.startsWith(`session:`)?null:e.slice(8).trim()||null,bg=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0},xg=(e,t)=>{if(t.length===0)return sg;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?sg:r},Sg=(e,t)=>{let n=ct(e),r=Q.useRef(sg),i=Q.useRef(t);return i.current=t,Q.useSyncExternalStore(n.subscribe,Q.useCallback(()=>{let e=xg(n.getState().session,i.current);return bg(r.current,e)?r.current:(r.current=e,e)},[n]),()=>sg)},Cg=`new Promise((resolve) => {
|
|
22
22
|
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
23
23
|
if (existing) existing.remove();
|
|
24
24
|
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
@@ -102,14 +102,14 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F
|
|
|
102
102
|
window.addEventListener('mousemove', move, true);
|
|
103
103
|
window.addEventListener('click', click, true);
|
|
104
104
|
window.addEventListener('keydown', keydown, true);
|
|
105
|
-
});`,
|
|
105
|
+
});`,wg=`(() => {
|
|
106
106
|
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
107
107
|
window.__openchamberDesktopBrowserCancelInspect();
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
111
111
|
if (overlay) overlay.remove();
|
|
112
|
-
})()`,
|
|
112
|
+
})()`,Tg=`(() => {
|
|
113
113
|
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
114
114
|
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
115
115
|
|
|
@@ -141,12 +141,12 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F
|
|
|
141
141
|
event.preventDefault();
|
|
142
142
|
event.stopPropagation();
|
|
143
143
|
}, true);
|
|
144
|
-
})()`,
|
|
145
|
-
`),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`resource-error`){let t=e(a.tag)||`resource`,n=e(a.url);r({level:`resource`,message:n?`${t}: ${n}`:t,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){O(
|
|
144
|
+
})()`,Eg=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`}},Dg=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)},Og=(e,t)=>e.length<=t?e:`${e.slice(0,t-3)}...`,kg=e=>{if(typeof window>`u`)return``;try{return new URL(e||window.location.href,window.location.href).origin}catch{return window.location.origin}},Ag=(e,t,n)=>{let r=kg(t);e.postMessage(n,r)},jg=e=>{if(!e)return e;try{let t=new URL(e);return t.searchParams.delete(`oc_preview_token`),t.searchParams.delete(`oc_client_token`),t.searchParams.delete(`oc_url_token`),t.toString()}catch{return e}},Mg=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}},Ng=({rawUrl:e,onNavigate:t})=>{let{t:n}=Xe(),{currentTheme:r}=$i(),[a,o]=Q.useReducer(e=>e+1,0),[c,l]=Q.useReducer(e=>e+1,0),[u,d]=Q.useState({status:`idle`}),[f,p]=Q.useState(``),h=Q.useRef(null),g=Q.useRef(1),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(`all`),[C,w]=Q.useState([]),[T,E]=Q.useState(!1),[D,O]=Q.useState(null),k=Tn(e=>e.currentSessionId),A=Tn(e=>e.newSessionDraft?.open),j=Pa(e=>e.addDraft),M=Lt(e=>e.addAttachedFile),N=null;try{N=e?new URL(e):null}catch{N=null}let P=N?N.hostname===`localhost`||N.hostname===`127.0.0.1`||N.hostname===`::1`||N.hostname===`[::1]`||N.hostname===`0.0.0.0`:!1,F=N?N.hostname===`0.0.0.0`?new URL(N.toString().replace(`0.0.0.0`,`127.0.0.1`)):N:null,I=F?F.toString():``,L=I?`${m()||`same-origin`}|${I}`:``,R=r.metadata.variant;Q.useEffect(()=>{if(!I||!P){d({status:`idle`});return}let e=jh(L);if(e?.previewToken){d({status:`ready`,proxyBasePath:e.proxyBasePath,previewToken:e.previewToken,expiresAt:e.expiresAt});return}e&&Oh.delete(L);let t=!1;return d({status:`loading`}),(async()=>{try{let e=await V(`/api/preview/targets`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({url:I})});if(!e.ok){Oh.delete(L);let n=await e.json().catch(()=>({})),r=typeof n?.error==`string`?n.error:`HTTP ${e.status}`;t||d({status:`error`,message:r});return}let r=await e.json(),i=typeof r.proxyBasePath==`string`?r.proxyBasePath:``,a=typeof r.previewToken==`string`?r.previewToken:``,o=typeof r.expiresAt==`number`?r.expiresAt:0;if(!i||!a){Oh.delete(L),t||d({status:`error`,message:n(`contextPanel.preview.proxyError`)});return}Oh.set(L,{proxyBasePath:i,previewToken:a,expiresAt:o}),t||d({status:`ready`,proxyBasePath:i,previewToken:a,expiresAt:o})}catch(e){if(Oh.delete(L),!t){let t=e instanceof Error?e.message:String(e);d({status:`error`,message:t})}}})(),()=>{t=!0}},[P,L,c,n,I]);let z=F&&(F.protocol===`http:`||F.protocol===`https:`)?F.toString():``,B=P&&u.status===`ready`?`${u.proxyBasePath}|${u.previewToken||``}|${a}`:``;Q.useEffect(()=>{if(!B){p(``);return}let e=!1;return p(``),s(m()).then(t=>{!e&&t&&p(B)}).catch(()=>{}),()=>{e=!0}},[B]);let H=P&&u.status===`ready`&&F&&f===B?(()=>{let e=F.pathname||`/`,t=new URLSearchParams(F.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=F.hash||``;return i().authenticatedAsset(`${u.proxyBasePath}${e}${n?`?${n}`:``}${r}`)})():``,U=P?H:z,ee=P?jg(H):z,te=P&&(u.status===`loading`||u.status===`idle`||f!==B),W=P&&u.status===`error`,ne=Q.useCallback(t=>{let r=k??(A?`draft`:null);if(!r){J.error(n(`contextPanel.preview.inspect.attachNoSession`));return}let i=e||U||``,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=h.current,r=n?await Th(n,t):null;r&&(await M(r),e=!0)}catch{e=!1}j({sessionKey:r,source:`preview-annotation`,fileLabel:i||`preview`,startLine:1,endLine:1,code:wh({pageUrl:i,viewport:a,devicePixelRatio:o,target:t,screenshotAttached:e,intro:n(`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),J.success(n(`contextPanel.preview.inspect.attached`))})()},[M,j,k,U,A,e,n]);Q.useEffect(()=>{v(!1),w([]),b(!1),S(`all`),E(!1),O(null),g.current=1},[U]),Q.useEffect(()=>{let e=h.current?.contentWindow;!_||!e||Ag(e,H,{source:`openchamber-preview-parent`,version:1,type:`set-inspect-mode`,enabled:T})},[_,T,H]),Q.useEffect(()=>{let e=h.current?.contentWindow;!_||!e||Ag(e,H,{source:`openchamber-preview-parent`,version:1,type:`set-color-scheme`,scheme:R})},[_,R,H]),Q.useEffect(()=>{if(!T||typeof window>`u`)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),E(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[T]),Q.useEffect(()=>{if(!P||typeof window>`u`)return;let e=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},r=e=>{let t=g.current;g.current+=1,w(n=>{let r=[...n,{...e,id:t}];return r.length>cg?r.slice(r.length-cg):r})},i=i=>{if(i.source!==h.current?.contentWindow)return;let a=i.data;if(!(!a||a.source!==`openchamber-preview-bridge`||a.version!==1)){if(a.type===`ready`){v(!0);return}if(a.type===`console`){let t=a.level===`error`||a.level===`warn`||a.level===`info`||a.level===`debug`?a.level:`log`,n=Array.isArray(a.args)?a.args.map(e).filter(Boolean):[];r({level:t,message:n.join(` `),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`runtime-error`){let t=e(a.filename),i=typeof a.line==`number`?a.line:null,o=typeof a.column==`number`?a.column:null,s=t?`${t}${i===null?``:`:${i}${o===null?``:`:${o}`}`}`:``,c=e(a.stack);r({level:`runtime`,message:e(a.message)||n(`contextPanel.preview.console.runtimeError`),details:[s,c].filter(Boolean).join(`
|
|
145
|
+
`),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`resource-error`){let t=e(a.tag)||`resource`,n=e(a.url);r({level:`resource`,message:n?`${t}: ${n}`:t,details:e(a.outerHTML),ts:typeof a.ts==`number`?a.ts:Date.now()});return}if(a.type===`hover`){O(Ch(a.target)?a.target:null);return}if(a.type===`select`&&Ch(a.target)){O(a.target),E(!1),ne(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`){Mo(e);return}e&&t(e)}}};return window.addEventListener(`message`,i),()=>{window.removeEventListener(`message`,i)}},[ne,P,t,n]);let G=C.filter(e=>e.level===`error`||e.level===`runtime`||e.level===`resource`).length,re=C.filter(e=>lg(e,x)),K=Q.useCallback(()=>{let t=[`Preview URL: ${e||U||``}`,`Events: ${C.length}`,``].join(`
|
|
146
146
|
`),r=C.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
147
147
|
`);$e(`${t}${r}`).then(e=>{e.ok?J.success(n(`contextPanel.preview.console.copied`)):J.error(n(`contextPanel.preview.console.copyFailed`))})},[C,U,e,n]),ie=Q.useCallback(()=>{let t=k??(A?`draft`:null);if(!t){J.error(n(`contextPanel.preview.console.attachNoSession`));return}let r=[`Preview URL: ${e||U||``}`,`Events: ${C.length}`,``].join(`
|
|
148
148
|
`),i=C.map(e=>{let t=new Date(e.ts).toISOString(),n=e.details?`\n${e.details}`:``;return`[${t}] [${e.level}] ${e.message}${n}`}).join(`
|
|
149
|
-
`);j({sessionKey:t,source:`preview-console`,fileLabel:e||U||`preview`,startLine:1,endLine:Math.max(1,C.length),code:`${r}${i}`,language:`text`,text:n(`contextPanel.preview.console.attachAnnotation`)}),J.success(n(`contextPanel.preview.console.attached`))},[j,C,k,U,A,e,n]),[ae,oe]=Q.useState(`unknown`),se=Q.useRef(0),ce=Q.useRef(0);Q.useEffect(()=>{if(!H){oe(`unknown`),se.current=0,ce.current=0;return}let e=!1;return se.current||(se.current=Date.now(),ce.current=0),oe(`unknown`),(async()=>{let t=await(async()=>{try{return await V(H,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){oe(`unreachable`);return}if(t.status===403||t.status===404){Dh.delete(L),d({status:`loading`}),l();return}if(t.status!==502){oe(`reachable`);return}let n=se.current||Date.now();if(Date.now()-n<15e3){oe(`starting`),ce.current+=1;let t=ce.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||o()},n).unref?.();return}oe(`unreachable`)})(),()=>{e=!0}},[L,H,a]);let le=P&&u.status===`ready`&&(ae===`unknown`||ae===`starting`),ue=P&&u.status===`ready`&&ae===`unreachable`,de=Q.useCallback(e=>{if(!P||u.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=Og(H);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{}},[P,H,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:ee||e,children:ee||e||n(`contextPanel.preview.empty`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>o(),title:n(`contextPanel.preview.actions.reload`),"aria-label":n(`contextPanel.preview.actions.reload`),disabled:!U,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&&jo(z)},title:n(`contextPanel.preview.actions.openExternal`),"aria-label":n(`contextPanel.preview.actions.openExternal`),disabled:!z,children:(0,$.jsx)(X,{name:`external-link`,className:`h-3.5 w-3.5`})}),P?(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:T?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>E(e=>!e),title:n(`contextPanel.preview.inspect.toggle`),"aria-label":n(`contextPanel.preview.inspect.toggle`),disabled:!_,children:(0,$.jsx)(X,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,P?(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:y?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>b(e=>!e),title:n(_?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":n(_?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!_&&C.length===0,children:[(0,$.jsx)(X,{name:`terminal-box`,className:`h-3.5 w-3.5`}),G>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:G}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[le?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.startingServerHint`)})]}):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:n(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>o(),children:n(`contextPanel.preview.actions.retry`)})]}):U&&(!P||ae===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:h,src:U,title:n(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:R},onLoad:de,sandbox:P?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${U}:${a}`),T&&D?(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:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.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:[D.tag,D.text?` · ${D.text}`:``]})}):null]}):te?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.loading`)}):W?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.proxyError`)}),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:n(`contextPanel.preview.invalidUrl`)}),y?(0,$.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:ie,disabled:C.length===0,children:n(`contextPanel.preview.console.attach`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:K,disabled:C.length===0,children:n(`contextPanel.preview.console.copy`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>w([]),disabled:C.length===0,children:n(`contextPanel.preview.console.clear`)})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/30 px-3 py-1.5`,children:[`all`,`errors`,`warnings`,`logs`].map(e=>(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:x===e?`secondary`:`ghost`,onClick:()=>S(e),children:n(e===`all`?`contextPanel.preview.console.filter.all`:e===`errors`?`contextPanel.preview.console.filter.errors`:e===`warnings`?`contextPanel.preview.console.filter.warnings`:`contextPanel.preview.console.filter.logs`)},e))}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-auto p-2 typography-code text-xs`,children:C.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.empty`)}):re.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.noFilteredEvents`)}):re.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]})]})},Ng=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,Pg=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=Xe(),a=Q.useRef(null),o=p(e=>e.setContextPanelTabTargetPath),c=Tg(e),l=c===`about:blank`?``:c,[u,d]=Q.useState(l),[f,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=yn(e=>e.currentSessionId),F=yn(e=>e.newSessionDraft?.open),I=Na(e=>e.addDraft),L=dt(e=>e.addAttachedFile),R=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||o(t,n,e)},[t,n,o]),z=Q.useCallback((e,t)=>{let n=Tg(e),r=n===`about:blank`?``:n;h(r),d(r),t?.inFrame?T(!1):(_(r),T(!!r)),R(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,R]),B=Q.useCallback(e=>{let t=v[e];t&&(x(e),h(t),_(t),d(t),T(!0),R(t))},[v,R]),H=Q.useCallback(()=>{if(f){T(!0);try{a.current?.contentWindow?.location.reload()}catch{C()}}},[f]);Q.useEffect(()=>{if(!g){j({status:`idle`});return}let e=jh(g),t=Ah(e);if(t?.previewToken){j({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&Dh.delete(e);let n=!1;return j({status:`loading`}),T(!0),(async()=>{try{let t=await V(`/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 i=await t.json(),a=typeof i.proxyBasePath==`string`?i.proxyBasePath:``,o=typeof i.previewToken==`string`?i.previewToken:``,s=typeof i.expiresAt==`number`?i.expiresAt:0;if(!a||!o){n||j({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}Dh.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,r]);let U=g&&A.status===`ready`?`${A.proxyBasePath}|${A.previewToken||``}|${S}`:``;Q.useEffect(()=>{if(!U){N(``);return}let e=!1;return N(``),s(m()).then(t=>{!e&&t&&N(U)}).catch(()=>{}),()=>{e=!0}},[U]);let ee=Q.useMemo(()=>{if(M!==U||!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 i().authenticatedAsset(`${A.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,A,U,S,M]),te=ee||(A.status===`error`?g:``),W=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 jg(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)?``:jg(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,A]),G=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(r(`contextPanel.preview.inspect.attachNoSession`));return}let n=a.current,i=n?.contentWindow,o=n?.getBoundingClientRect(),s={width:Number.isFinite(i?.innerWidth)?i?.innerWidth??o?.width??0:o?.width??0,height:Number.isFinite(i?.innerHeight)?i?.innerHeight??o?.height??0:o?.height??0},c=n?await wh(n,e):null,l=!!c;c&&await L(c),I({sessionKey:t,source:`preview-annotation`,fileLabel:f||`browser`,startLine:1,endLine:1,code:Ch({pageUrl:f,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:r(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),J.success(r(`contextPanel.preview.inspect.attached`))},[L,I,P,f,F,r]),K=Q.useCallback(()=>{let e=a.current;k(null),G(!1),e&&Eg(e,Cg).catch(()=>{})},[G]);Q.useEffect(()=>{if(!E)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1),K())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[K,E]),Q.useEffect(()=>()=>K(),[K]),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=W(e);n&&n!==f&&z(n,{inFrame:!0});return}if(t.type===`hover`){k(Sh(t.target)?t.target:null);return}if(t.type===`select`&&Sh(t.target)){k(null),D(!1),G(!1),re(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ne(e);if(n){z(n);return}e&&z(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[z,re,f,W,ne,G]);let ie=Q.useCallback(()=>{let e=a.current;if(!(!e||!f)){if(E){D(!1),K();return}if(ee){k(null),D(!0),G(!0);return}D(!0),(async()=>{try{let t=await Eg(e,Sg);if(D(!1),!t||!Sh(t))return;await re(t)}catch{D(!1),J.error(r(`contextPanel.browser.inspectUnavailable`))}})()}},[re,K,f,E,G,ee,r]),ae=Q.useCallback(()=>{try{let e=a.current?.contentWindow?.location.href||``,t=ne(e);if(t){z(t,{inFrame:!0});return}}catch{}T(!1),E&&ee&&G(!0)},[z,ne,E,G,ee]);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:()=>B(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:()=>B(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:!f,onClick:H,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(),z(u)},children:(0,$.jsx)(`input`,{value:u,onChange:e=>d(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:E?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!f,onClick:ie,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`,disabled:!f,onClick:()=>void jo(f),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:r(`contextPanel.browser.empty`),className:`absolute inset-0 h-full w-full border-0 bg-background`,allow:`clipboard-read; clipboard-write; fullscreen`,allowFullScreen:!0,onLoad:ae},`${n}:${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)(ua,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)}),(0,$.jsx)(`span`,{className:`max-w-sm typography-micro text-muted-foreground`,children:r(`contextPanel.browser.emptyHint`)}),(0,$.jsx)(`span`,{className:`max-w-md typography-micro leading-relaxed text-status-warning/70`,children:r(`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:r(`common.loading`)}):null]})]})},Fg=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=Xe(),i=Q.useRef(null),a=p(e=>e.setContextPanelTabTargetPath),o=Tg(e),s=o===`about:blank`?``:o,c=Q.useRef(Tg(e)),[l,u]=Q.useState(s),[d,f]=Q.useState(s),[m,h]=Q.useState(!1),[g,_]=Q.useState(!0),v=Q.useRef(null),y=g,b=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||a(t,n,e)},[t,n,a]),x=yn(e=>e.currentSessionId),S=yn(e=>e.newSessionDraft?.open),C=Na(e=>e.addDraft),w=dt(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),b(t))}catch{}},n=e=>{let t=e.detail;typeof t?.url==`string`&&t.url&&(f(t.url),u(t.url),b(t.url))},r=()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>_(!0),200)},a=()=>{v.current&&clearTimeout(v.current),_(!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?.(wg,!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()||(_(!1),t())}catch{}return s(),()=>{v.current&&clearTimeout(v.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)}},[b]),Q.useEffect(()=>{let e=setTimeout(()=>_(!1),3e4);return()=>clearTimeout(e)},[]),Q.useEffect(()=>{if(!m)return;let e=e=>{if(e.key!==`Escape`)return;e.preventDefault(),e.stopImmediatePropagation(),h(!1);let t=i.current;try{t?.executeJavaScript?.(Cg).catch(()=>{})}catch{}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[m]),Q.useEffect(()=>{let e=i.current;return()=>{try{let r=e?.getURL?.();r&&r!==`about:blank`&&a(t,n,r)}catch{}try{e?.executeJavaScript?.(Cg).catch(()=>{})}catch{}}},[t,n,a]);let T=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=Tg(e);try{t.loadURL(n)}catch{}},[]),E=Q.useCallback(()=>{let e=i.current;if(e){if(m){h(!1);try{e.executeJavaScript?.(Cg).catch(()=>{})}catch{}return}h(!0),e.executeJavaScript?.(Sg,!0).then(async t=>{if(h(!1),!t||!Sh(t))return;let n=x??(S?`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 Ze(`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 Th(a.base64,a.width,a.height,s,c,t),u=!!l;l&&await w(l),C({sessionKey:n,source:`preview-annotation`,fileLabel:d||`browser`,startLine:1,endLine:1,code:Ch({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(()=>h(!1))}},[w,C,x,d,m,S,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(),T(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:m?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:E,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(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 jo(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`)&&!g?(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)(ua,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)})]}):null,y?(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]})]})},Ig=()=>{let{t:e}=Xe(),t=Lo()??``,n=Q.useMemo(()=>lg(t),[t]),i=p(e=>n?e.contextPanelByDirectory[n]:void 0),a=p(e=>n?e.contextToolDiffByDirectory[n]:void 0),o=p(e=>e.closeContextPanel),s=p(e=>e.closeContextPanelTab),c=p(e=>e.openContextPanelTab),l=p(e=>e.toggleContextPanelExpanded),u=p(e=>e.setContextPanelWidth),d=p(e=>e.setActiveContextPanelTab),f=p(e=>e.reorderContextPanelTabs),m=Vo(e=>e.setSelectedPath),h=p(e=>e.openContextPreview),g=p(e=>e.allowPromptingSubagentSessions),{themeMode:_,setThemeMode:v,lightThemeId:y,darkThemeId:b,currentTheme:x}=Qi(),S=Q.useMemo(()=>i?.tabs??[],[i?.tabs]),C=S.find(e=>e.id===i?.activeTabId)??S[S.length-1]??null,w=!!(i?.isOpen&&C),T=!!(w&&i?.expanded),E=ug(i?.width??ig),D=Q.useMemo(()=>{let e=[];for(let t of S){if(t.mode!==`chat`)continue;let n=vg(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[S]),O=xg(n||void 0,D),[k,A]=Q.useState(!1),[j,M]=Q.useState(!1),N=Q.useRef(0),P=Q.useRef(E),F=Q.useRef(null),I=Q.useRef(null),L=Q.useRef(null),R=Q.useRef(new Map),z=Q.useRef(new Map),B=Q.useRef(!1),V=Q.useRef(w),H=Q.useRef(null),[U,ee]=Q.useState({}),te=Q.useRef(U);te.current=U;let[W,ne]=Q.useReducer(mh,{activeViewKey:null,tabs:{},mountedViews:{}}),G=Im(),re=r(),K=Q.useCallback(e=>{let t=te.current,n=e(t);return n!==t&&(te.current=n,ee(n),!0)},[]),ie=Q.useCallback(e=>{if(!n)return;ne({type:`close-tab`,tabId:e});let t=Lm(n,e);K(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),s(n,e)},[s,K,n]),ae=Q.useCallback(()=>{M(!0),H.current!==null&&window.cancelAnimationFrame(H.current),H.current=window.requestAnimationFrame(()=>{H.current=null,M(!1)})},[]);Q.useEffect(()=>()=>{H.current!==null&&window.cancelAnimationFrame(H.current)},[]),Q.useLayoutEffect(()=>{let e=V.current;if(V.current=w,!w){M(!1);return}e||ae()},[w,ae]),Q.useEffect(()=>{if(!w||B.current){B.current=w;return}let e=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return B.current=!0,()=>window.cancelAnimationFrame(e)},[w]);let oe=Q.useCallback(e=>{let t=L.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${fg(e,t)}px`)},[]),se=Q.useCallback(e=>{if(!(!w||T||!n)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}I.current=e.pointerId,A(!0),N.current=e.clientX,P.current=E,F.current=E,oe(E),e.preventDefault()}},[oe,n,T,w,E]),ce=Q.useCallback(e=>{if(!k||I.current!==e.pointerId)return;let t=N.current-e.clientX,n=fg(P.current+t,L.current);F.current!==n&&(F.current=n,oe(n))},[oe,k]),le=Q.useCallback(e=>{if(I.current!==e.pointerId||!n)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=fg(F.current??E,L.current);ae(),oe(t),F.current=t,u(n,t),A(!1),I.current=null},[oe,n,u,ae,E]);Q.useEffect(()=>{k||(F.current=null)},[k]);let ue=Q.useCallback(()=>{n&&o(n)},[o,n]),de=Q.useCallback(()=>{n&&l(n)},[n,l]),fe=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&C&&n){e.preventDefault(),e.stopPropagation(),ie(C.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),ue())},[C,ie,n,ue]);Q.useEffect(()=>{if(!(!n||!C)&&C.mode===`file`&&C.targetPath){m(n,C.targetPath,{allowOutsideRoot:!0});return}},[C,n,m]);let pe=C?.mode===`chat`?C.id:null,me=Wm(pe?U[Lm(n,pe)]:void 0,pe?vg(C?.dedupeKey):null);Q.useEffect(()=>{if(!w||!n||!me){Mt(``,null);return}return Mt(n,me),()=>{Mt(``,null)}},[me,n,w]),Q.useEffect(()=>{if(!w||!n||!me||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){bt(n,me,!1);return}Rt(me),bt(n,me,!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),bt(n,me,!1)}},[me,n,w]);let he=Q.useCallback((e,t,r)=>Ea(z.current,e,t,n||null,r,{mode:_,lightThemeId:y,darkThemeId:b,currentTheme:x}),[x,b,n,y,_]);Q.useEffect(()=>{let e=new Set(S.map(e=>e.id));for(let t of z.current.keys())e.has(t)||z.current.delete(t)},[S]);let ge=Q.useCallback(e=>{!n||C?.mode!==`diff`&&C?.mode!==`file-diff`||c(n,{mode:C.mode,targetPath:C.targetPath,stagedDiff:e===`staged`,diffScope:e})},[C,n,c]),_e=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:_,lightThemeId:y,darkThemeId:b,currentTheme:x};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)}},[x,b,y,_]),ve=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:g};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)}},[g]),ye=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of R.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:pe===e},i=n.__openchamberSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:Ha,payload:r},window.location.origin)}},[pe]);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&&n&&ie(t[0]);return}if(t?.type===`openchamber:chat-settings-request`){ve();return}if(t?.type===`openchamber:embedded-visibility-request`){ye();return}if(t?.type!==`openchamber:cycle-theme-request`)return;let r=[`light`,`dark`,`system`],i=(r.indexOf(_)+1)%r.length;v(r[i])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ie,n,ve,ye,v,_]),Q.useLayoutEffect(()=>{S.some(e=>e.mode===`chat`)&&(_e(),ve(),ye())},[b,y,ve,ye,_e,S,_]);let be=Q.useMemo(()=>S.map(n=>{let r=gg(n,O,e),i=Dg(r,ag),a=pg(n.targetPath,t);return{id:n.id,label:i,icon:_g(n),title:a?`${r}: ${a}`:r,closeLabel:e(`contextPanel.tab.closeTabAria`,{label:i})}}),[t,O,e,S]),xe=C?.mode===`context`?(0,$.jsx)(Cm,{}):C?.mode===`plan`?(0,$.jsx)(Xp,{targetPath:C.targetPath}):C?.mode===`preview`?(0,$.jsx)(Mg,{rawUrl:C.targetPath??``,onNavigate:e=>h(t,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:e(`contextPanel.preview.title`)}),(0,$.jsx)(`div`,{className:`max-w-sm typography-micro text-muted-foreground`,children:e(`contextPanel.preview.description`)})]}),Se=Q.useMemo(()=>S.filter(e=>e.mode===`chat`),[S]),Ce=Q.useMemo(()=>S.filter(e=>e.mode===`browser`),[S]),we=Q.useMemo(()=>S.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[S]),Te=Ng()?Fg:Pg,Ee=Q.useMemo(()=>S.some(e=>e.mode===`file`),[S]),De=C?.mode===`file`,Oe=De?C?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(Se.map(e=>Lm(n,e.id)));K(t=>{let r=!1,i={};for(let e of Se){let a=vg(e.dedupeKey);if(!a)continue;let o=Lm(n,e.id),s=t[o];i[o]=s??Hm({sessionId:a,directory:n}),r||=!s}let a=Ym(t,e);return r||=a!==t,r?{...a,...i}:t});for(let t of Object.keys(W.tabs))(!e.has(Lm(n,t))||W.tabs[t]?.directory!==n)&&ne({type:`close-tab`,tabId:t})},[Se,K,n,W.tabs]);let ke=pe?Lm(n,pe):null,Ae=pe?vg(C?.dedupeKey):null,je=ke&&Ae?Um(U[ke],{sessionId:Ae,directory:n}):void 0,Me=je&&ke?Rm(re,ke,je.current.directory,je.current.sessionId):null;Q.useLayoutEffect(()=>{if(G!==`react-surface`||!w||!pe||!je||!ke||!Me){G===`react-surface`&&ne({type:`activate`,viewKey:null,now:Date.now()});return}K(e=>e[ke]?e:{...e,[ke]:je}),ne({type:`touch`,tab:{tabId:pe,sessionId:je.anchor.sessionId,directory:je.anchor.directory},view:{tabId:pe,surfaceId:ke,sessionId:je.current.sessionId,directory:je.current.directory,viewKey:Me},now:Date.now()})},[je,ke,pe,Me,G,K,w]);let Ne=Q.useCallback((e,t,r)=>{let i=Lm(n,e),a=!1;return K(e=>{let n=Jm(e,i,{sessionId:t,directory:r});return a=n.accepted,n.navigationBySurfaceId}),a},[K,n]),q=Q.useCallback(e=>{let t=Lm(n,e);K(e=>{let n=e[t];if(!n)return e;let r=Km(n);return r===n?e:{...e,[t]:r}})},[K,n]),Pe=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)(Qo,{items:be,activeId:C?.id??null,onSelect:e=>{n&&d(n,e)},onClose:e=>{ie(e)},onReorder:(e,t)=>{n&&f(n,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:de,className:`h-7 w-7 p-0`,title:e(T?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":e(T?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:T?(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:ue,className:`h-7 w-7 p-0`,title:e(`contextPanel.actions.closePanel`),"aria-label":e(`contextPanel.actions.closePanel`),children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),Fe=w?T?{"--oc-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--oc-context-panel-width), 100%)`,minWidth:`min(${ng}px, 100%)`,maxWidth:`100%`,"--oc-context-panel-width":`${k?F.current??E:E}px`}:{"--oc-context-panel-width":`${k?F.current??E:E}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:!w||void 0,className:Y(`flex min-h-0 flex-col overflow-hidden bg-background`,!T&&`border-l border-border/40`,T?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!w&&`pointer-events-none`,k||!w||j?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:fe,style:Fe,children:[!T&&(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`,k&&`bg-[var(--interactive-border)]`),onPointerDown:se,onPointerMove:ce,onPointerUp:le,onPointerCancel:le,role:`separator`,"aria-orientation":`vertical`,"aria-label":e(`contextPanel.actions.resizePanelAria`)}),Pe,Oe===`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:e(`contextPanel.file.notice.turnDiffOutsideWorkspace`)}):null,(0,$.jsxs)(`div`,{className:Y(`relative min-h-0 flex-1 overflow-hidden`,k&&`pointer-events-none`),children:[Ee?(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,De?`block`:`hidden`),children:(0,$.jsx)(yp,{mode:`editor-only`,isActive:w&&De})}):null,G===`legacy-iframe`&&Se.map(t=>{let n=vg(t.dedupeKey);if(!n)return null;let r=he(t.id,n,t.readOnly);return r?(0,$.jsx)(`iframe`,{ref:e=>{if(!e){R.current.delete(t.id);return}R.current.set(t.id,e)},src:r,title:e(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:Y(`absolute inset-0 h-full w-full border-0 bg-background`,pe===t.id?`block`:`hidden`),onLoad:()=>{_e(),ve(),ye()}},t.id):null}),G===`react-surface`?Object.values(W.mountedViews).map(e=>{let t=U[Lm(n,e.tabId)],r=w&&pe===e.tabId&&Me===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:r?`visible`:`hidden`,children:(0,$.jsx)(_h,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:r,canNavigateBack:r&&!!t?.stack.length,onNavigateSession:(t,n)=>Ne(e.tabId,t,n),onNavigateBack:()=>q(e.tabId),onEstimateBytes:(e,t)=>ne({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,Ce.map(e=>(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,C?.id!==e.id&&`hidden`),children:(0,$.jsx)(Te,{initialUrl:e.targetPath??``,directory:n,tabID:e.id})},e.id)),we.map(e=>{let t=e.mode===`diff`&&a?.targetPath===e.targetPath&&a.turnMessageId===e.diffTurnMessageId?a.patches:null;return(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,C?.id!==e.id&&`hidden`),children:(0,$.jsx)(Ls,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:n,onDiffScopeChange:ge,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)}),C?.mode!==`chat`&&!De&&C?.mode!==`browser`&&C?.mode!==`diff`&&C?.mode!==`file-diff`?xe:null]})]})},Lg=(e,t)=>!e||t.length===0?``:JSON.stringify([e,t]),Rg=(e,t,n,r)=>!n||r!==n||e.length===0?[]:an(e,t,e=>e.name,{limit:10,threshold:.4}),zg=e=>{let t=(0,Rc.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},Bg=`h-8 gap-2 rounded-md px-2.5 py-0 typography-meta`,Vg=`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`,Hg=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},Ug=()=>{let e=(0,Rc.c)(177),{t}=Xe(),n=p(Wg),r=p(Gg),i=p(Kg),a=p(qg),o=p(Jg),s=p(Yg),c=p(Xg),l=p(Zg),u=p(Qg),d=p($g),f=p(e_),m=p(t_),h=yn(n_),g=yn(r_),_=Vn(i_),y=Pe(a_),b=xn(o_),x=xn(s_),S=Lo(),C=Ae(c_),{files:T,git:E}=uo(),D=Uo(l_),{isMobile:O}=Ca(),k;e[0]===S?k=e[1]:(k=S?Hg(S):null,e[0]=S,e[1]=k);let j=k,[M,N]=Q.useState(``),P=Bo(M,200).trim(),F;e[2]===M?F=e[3]:(F=M.trim(),e[2]=M,e[3]=F);let L=F,R,z;e[4]===n?(R=e[5],z=e[6]):(R=()=>{n&&N(``)},z=[n],e[4]=n,e[5]=R,e[6]=z),Q.useEffect(R,z);let B,V;e[7]!==_||e[8]!==D||e[9]!==E||e[10]!==n?(B=()=>{if(!n||!E)return;let e=setTimeout(()=>{let e=new Set;for(let t of _){let n=Hn(t);!n||e.has(n)||(e.add(n),D(n,E))}},0);return()=>clearTimeout(e)},V=[n,_,E,D],e[7]=_,e[8]=D,e[9]=E,e[10]=n,e[11]=B,e[12]=V):(B=e[11],V=e[12]),Q.useEffect(B,V);let H;e[13]===r?H=e[14]:(H=()=>r(!1),e[13]=r,e[14]=H);let U=H,ee;e[15]===U?ee=e[16]:(ee=e=>()=>{U(),e()},e[15]=U,e[16]=ee);let W=ee,ne;e[17]!==b?.id||e[18]!==b?.path||e[19]!==y||e[20]!==S||e[21]!==O||e[22]!==d||e[23]!==h||e[24]!==W||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:W(()=>{i(`chat`),s(!1),h()})},{id:`new-worktree`,title:t(`commandPalette.item.newWorktreeDraft`),shortcutId:`new_chat_worktree`,searchText:t(`commandPalette.item.newWorktreeDraft`),onSelect:W(u_)},{id:`add-project`,title:t(`commandPalette.item.addProject`),searchText:t(`commandPalette.item.addProject`),onSelect:W(d_)},{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:W(()=>{if(O){let{isSessionSwitcherOpen:e}=p.getState();s(!e)}else c()})},{id:`toggle-right-sidebar`,title:t(`commandPalette.item.toggleRightSidebar`),shortcutId:`toggle_right_sidebar`,searchText:t(`commandPalette.item.toggleRightSidebar`),onSelect:W(()=>l())},{id:`toggle-terminal`,title:t(`commandPalette.item.toggleTerminal`),shortcutId:`toggle_terminal`,searchText:t(`commandPalette.item.toggleTerminal`),onSelect:W(()=>u())},{id:`new-terminal-tab`,title:t(`commandPalette.item.newTerminalTab`),shortcutId:`open_new_terminal`,searchText:t(`commandPalette.item.newTerminalTab`),onSelect:W(()=>{S&&ei(S)})},{id:`context-usage`,title:t(`commandPalette.item.showContextUsage`),searchText:t(`commandPalette.item.showContextUsage`),onSelect:W(()=>{y&&d(y)})},{id:`open-settings`,title:t(`commandPalette.item.openSettings`),shortcutId:`open_settings`,searchText:t(`commandPalette.item.openSettings`),onSelect:W(()=>a(!0))}];return w()&&e.splice(1,0,{id:`new-mini-chat`,title:t(`commandPalette.item.newMiniChat`),shortcutId:`new_mini_chat`,searchText:t(`commandPalette.item.newMiniChat`),onSelect:W(()=>{te(`desktop_open_draft_mini_chat_window`,{directory:Hg(y||b?.path||``),projectId:b?.id??null}).catch(f_)})}),e},e[17]=b?.id,e[18]=b?.path,e[19]=y,e[20]=S,e[21]=O,e[22]=d,e[23]=h,e[24]=W,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],b?.id,b?.path;let G;e[33]===ne?G=e[34]:(G=ne(),e[33]=ne,e[34]=G);let re=G,K;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(K=A(),e[35]=K):K=e[35];let ie=K,ae,oe;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(ae=v(),oe=!ie&&I(),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]!==W||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]!==W||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:W(()=>{o(e.slug),a(!0)})}},e[47]=W,e[48]=a,e[49]=o,e[50]=n):n=e[50],le=Ts.filter(p_).filter(t).map(n),e[40]=W,e[41]=a,e[42]=o,e[43]=ce,e[44]=le}else le=e[44];let ue=le,de=m_,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=Wo(),he=yn(h_),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),[xe,Se]=Q.useState(``),Ce=Lg(j,P),we;e[58]!==j||e[59]!==Ce||e[60]!==n||e[61]!==C||e[62]!==be||e[63]!==Se||e[64]!==P?(we=()=>{if(!n){be([]),Se(``);return}if(!Ce){be([]),Se(``);return}if(!j){be([]),Se(``);return}let e=!1;return C(j,P,10,{type:`file`}).then(t=>{e||(be(t.map(g_)),Se(Ce))}).catch(()=>{e||(be([]),Se(Ce))}),()=>{e=!0}},e[58]=j,e[59]=Ce,e[60]=n,e[61]=C,e[62]=be,e[63]=Se,e[64]=P,e[65]=we):we=e[65];let Te;e[66]!==j||e[67]!==Ce||e[68]!==n||e[69]!==C||e[70]!==P?(Te=[n,j,P,Ce,C],e[66]=j,e[67]=Ce,e[68]=n,e[69]=C,e[70]=P,e[71]=Te):Te=e[71],Q.useEffect(we,Te);let Ee=L.length>0,De;bb0:{if(!Ee){let t;e[72]===re?t=e[73]:(t=re.map(__),e[72]=re,e[73]=t),De=t;break bb0}let t;e[74]!==re||e[75]!==L?(t=an(re,L,v_,{limit:7,noFuzzy:!0}),e[74]=re,e[75]=L,e[76]=t):t=e[76],De=t}let Oe=De,ke;bb1:{if(!Ee){let t;e[77]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[77]=t):t=e[77],ke=t;break bb1}let t;e[78]!==L||e[79]!==ue?(t=an(ue,L,y_,{limit:7,noFuzzy:!0}),e[78]=L,e[79]=ue,e[80]=t):t=e[80],ke=t}let je=ke,Me;bb2:{if(!Ee){let t;e[81]===pe?t=e[82]:(t=pe.slice(0,5).map(b_),e[81]=pe,e[82]=t),Me=t;break bb2}let t;e[83]!==L||e[84]!==pe?(t=an(pe,L,x_,{limit:7,threshold:.2}),e[83]=L,e[84]=pe,e[85]=t):t=e[85],Me=t}let Ne=Me,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]!==xe||e[89]!==Ce||e[90]!==P?(t=Rg(ye,P,Ce,xe),e[87]=ye,e[88]=xe,e[89]=Ce,e[90]=P,e[91]=t):t=e[91],q=t}let Fe=q,Ie=n&&Ce.length>0&&xe!==Ce,Le;bb4:{if(!Ee){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]!==L||e[94]!==x){let n=x.map(S_);t=an(n,L,C_,{limit:7,threshold:.4}),e[93]=L,e[94]=x,e[95]=t}else t=e[95];Le=t}let Re=Le,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Ze,Qe,$e,et,tt;if(e[96]!==_e||e[97]!==U||e[98]!==j||e[99]!==T||e[100]!==Ee||e[101]!==n||e[102]!==f||e[103]!==h||e[104]!==M||e[105]!==Oe||e[106]!==Fe||e[107]!==Re||e[108]!==Ne||e[109]!==je||e[110]!==r||e[111]!==g||e[112]!==m||e[113]!==t){let i=Oe.map(w_),a=je.map(T_),o=Ne.map(E_),s=Ee?Fe.map(D_):[],c=Ee?Re.map(O_):[],l;bb5:{if(!Ee){l=[`commands`,`sessions`];break bb5}let e=k_,t=[{key:`commands`,score:e(Oe)},{key:`settings`,score:e(je)},{key:`sessions`,score:e(Ne)},{key:`files`,score:e(Fe)},{key:`projects`,score:e(Re)}];t.sort(A_),l=t.map(j_)}let u=l,d=e=>{U(),g(e.id,Hn(e))},p=async e=>{if(!j)return;let t=await tc(T,e);if(!t.ok){J.error(Ws(t.reason));return}f(j,e),U()},_=(e,t)=>{U(),h({selectedProjectId:e,directoryOverride:t})},v=e=>fa(da(e,m));He=cr,$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)(or,{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)(sr,{children:x}),e[136]=x,e[137]=S),e[138]!==b||e[139]!==S?(tt=(0,$.jsxs)(rr,{className:`sr-only`,children:[b,S]}),e[138]=b,e[139]=S,e[140]=tt):tt=e[140],Ve=ar,Ye=`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=so,Ke=!1,qe=`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?(Je=(0,$.jsx)(oo,{value:M,onValueChange:N,placeholder:C}),e[143]=M,e[144]=C,e[145]=Je):Je=e[145],ze=Aa,Ue=`px-1.5 pb-2`;let w;e[146]===t?w=e[147]:(w=t(`commandPalette.empty.noResults`),e[146]=t,e[147]=w),e[148]===w?We=e[149]:(We=(0,$.jsx)(Ra,{className:`py-10 text-muted-foreground`,children:w}),e[148]=w,e[149]=We),Ge=u.map(e=>e===`commands`&&i.length>0?(0,$.jsx)(Oa,{heading:t(`settings.page.commands.title`),className:Vg,children:i.map(e=>(0,$.jsx)(za,{value:e.id,onSelect:e.onSelect,className:Bg,children:(0,$.jsx)(zg,{title:e.title,trailing:e.shortcutId?(0,$.jsx)(Da,{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)(Oa,{heading:t(`settings.view.home.title`),className:Vg,children:a.map(M_)},`settings`):e===`sessions`&&o.length>0?(0,$.jsx)(Oa,{heading:t(`header.sessions.title`),className:Vg,children:o.map(e=>{let n=e.title||t(`commandPalette.session.untitled`),r=Hn(e),i=_e(e.id,r);return(0,$.jsx)(za,{value:`session:${e.id}`,onSelect:()=>d(e),className:Bg,children:(0,$.jsx)(zg,{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)(Oa,{heading:t(`layout.mainTab.files`),className:Vg,children:s.map(e=>{let t=Xn(e.relativePath||e.name,{maxLength:80});return(0,$.jsx)(za,{value:`file:${e.path}`,onSelect:()=>{p(e.path)},className:Bg,children:(0,$.jsx)(zg,{title:e.name,description:t===e.name?void 0:t})},`file:${e.path}`)})},`files`):e===`projects`&&c.length>0?(0,$.jsx)(Oa,{heading:t(`sessions.sidebar.projectsTitle`),className:Vg,children:c.map(e=>{let t=e.displayName;return(0,$.jsx)(za,{value:`project:${e.id}`,onSelect:()=>_(e.id,e.path),className:Bg,children:(0,$.jsx)(zg,{title:t})},`project:${e.id}`)})},`projects`):null),e[96]=_e,e[97]=U,e[98]=j,e[99]=T,e[100]=Ee,e[101]=n,e[102]=f,e[103]=h,e[104]=M,e[105]=Oe,e[106]=Fe,e[107]=Re,e[108]=Ne,e[109]=je,e[110]=r,e[111]=g,e[112]=m,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]=qe,e[123]=Je,e[124]=Ye,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],qe=e[122],Je=e[123],Ye=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]!==qe||e[162]!==Je||e[163]!==rt?(it=(0,$.jsxs)(Be,{shouldFilter:Ke,className:qe,children:[Je,rt]}),e[159]=Be,e[160]=Ke,e[161]=qe,e[162]=Je,e[163]=rt,e[164]=it):it=e[164];let at;e[165]!==Ve||e[166]!==Ye||e[167]!==Ze||e[168]!==Qe||e[169]!==it?(at=(0,$.jsx)(Ve,{className:Ye,containerClassName:Ze,showCloseButton:Qe,children:it}),e[165]=Ve,e[166]=Ye,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 Wg(e){return e.isCommandPaletteOpen}function Gg(e){return e.setCommandPaletteOpen}function Kg(e){return e.setActiveMainTab}function qg(e){return e.setSettingsDialogOpen}function Jg(e){return e.setSettingsPage}function Yg(e){return e.setSessionSwitcherOpen}function Xg(e){return e.toggleSidebar}function Zg(e){return e.toggleRightSidebar}function Qg(e){return e.toggleBottomTerminal}function $g(e){return e.openContextOverview}function e_(e){return e.openContextFile}function t_(e){return e.shortcutOverrides}function n_(e){return e.openNewSessionDraft}function r_(e){return e.setCurrentSession}function i_(e){return e.activeSessions}function a_(e){return e.currentDirectory}function o_(e){return e.getActiveProject()}function s_(e){return e.projects}function c_(e){return e.searchFiles}function l_(e){return e.ensureStatus}function u_(){ka()}function d_(){Cn.requestDirectoryDialog()}function f_(e){console.warn(`[command-palette] failed to open draft mini chat window`,e)}function p_(e){return e.slug!==`home`}function m_(e){return(typeof e.time?.updated==`number`?e.time.updated:0)||(typeof e.time?.created==`number`?e.time.created:0)}function h_(e){return e.worktreeMetadata}function g_(e){return{path:Hg(e.path),name:e.name,relativePath:e.relativePath}}function __(e){return{item:e,score:0}}function v_(e){return e.searchText}function y_(e){return e.searchText}function b_(e){return{item:e,score:0}}function x_(e){return e.title||``}function S_(e){return{...e,displayName:e.label||e.path.split(`/`).pop()||e.path,searchText:`${e.label||``} ${e.path}`}}function C_(e){return e.searchText}function w_(e){return e.item}function T_(e){return e.item}function E_(e){return e.item}function D_(e){return e.item}function O_(e){return e.item}function k_(e){return e.length?e[0].score:1/0}function A_(e,t){return e.score-t.score}function j_(e){return e.key}function M_(e){return(0,$.jsx)(za,{value:e.id,onSelect:e.onSelect,className:Bg,children:(0,$.jsx)(zg,{title:e.title})},e.id)}var N_=(e,t,n)=>ia(e)?pa(e,n).map(fa):t,P_=()=>{let e=(0,Rc.c)(69),{t}=Xe(),n=p(F_),r=p(I_),i=p(L_),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=na(),e[0]=a):a=e[0];let o=a,s;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=v(),e[1]=s):s=e[1];let c=s,l,u,d,f,m,h,g,_,y;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:``},{id:`toggle_context_plan`,descriptionKey:`helpDialog.item.togglePlanContextPanel`,icon:`time`,keys:``}]},{categoryKey:`helpDialog.section.interface`,items:[{id:`cycle_theme`,descriptionKey:`helpDialog.item.cycleTheme`,icon:`palette`,keys:``},{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=cr,_=n,y=r,l=ar,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 p;e[16]===t?p=e[17]:(p=t(`helpDialog.title`),e[16]=t,e[17]=p);let v;e[18]===p?v=e[19]:(v=(0,$.jsxs)(or,{className:`flex items-center gap-2`,children:[s,p]}),e[18]=p,e[19]=v);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)(sr,{children:b}),e[22]=b,e[23]=x),e[24]!==v||e[25]!==x?(g=(0,$.jsxs)(rr,{children:[v,x]}),e[24]=v,e[25]=x,e[26]=g):g=e[26],m=`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?N_(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)(Va,{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]=m,e[11]=h,e[12]=g,e[13]=_,e[14]=y}else l=e[6],u=e[7],d=e[8],f=e[9],m=e[10],h=e[11],g=e[12],_=e[13],y=e[14];let b;e[27]!==d||e[28]!==f?(b=(0,$.jsx)(`div`,{className:d,children:f}),e[27]=d,e[28]=f,e[29]=b):b=e[29];let x;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-muted-foreground mt-0.5`}),e[30]=x):x=e[30];let S;e[31]===t?S=e[32]:(S=t(`helpDialog.proTips.title`),e[31]=t,e[32]=S);let C;e[33]===S?C=e[34]:(C=(0,$.jsx)(`p`,{className:`font-medium mb-1`,children:S}),e[33]=S,e[34]=C);let w;e[35]!==i||e[36]!==t?(w=t(`helpDialog.proTips.commandPalette`,{shortcut:fa(pa(`open_command_palette`,i)[0]??``)}),e[35]=i,e[36]=t,e[37]=w):w=e[37];let T;e[38]===w?T=e[39]:(T=(0,$.jsxs)(`li`,{children:[`• `,w]}),e[38]=w,e[39]=T);let E;e[40]===t?E=e[41]:(E=t(`helpDialog.proTips.recentSessions`),e[40]=t,e[41]=E);let D;e[42]===E?D=e[43]:(D=(0,$.jsxs)(`li`,{children:[`• `,E]}),e[42]=E,e[43]=D);let O;e[44]===t?O=e[45]:(O=t(`helpDialog.proTips.themeCycling`),e[44]=t,e[45]=O);let k;e[46]===O?k=e[47]:(k=(0,$.jsxs)(`li`,{children:[`• `,O]}),e[46]=O,e[47]=k);let A;e[48]!==T||e[49]!==D||e[50]!==k?(A=(0,$.jsxs)(`ul`,{className:`space-y-0.5 typography-meta`,children:[T,D,k]}),e[48]=T,e[49]=D,e[50]=k,e[51]=A):A=e[51];let j;e[52]!==C||e[53]!==A?(j=(0,$.jsx)(`div`,{className:`mt-4 p-2 bg-muted/30 rounded-xl`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[x,(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground`,children:[C,A]})]})}),e[52]=C,e[53]=A,e[54]=j):j=e[54];let M;e[55]!==j||e[56]!==m||e[57]!==b?(M=(0,$.jsxs)(`div`,{className:m,children:[b,j]}),e[55]=j,e[56]=m,e[57]=b,e[58]=M):M=e[58];let N;e[59]!==l||e[60]!==M||e[61]!==h||e[62]!==g?(N=(0,$.jsxs)(l,{className:h,children:[g,M]}),e[59]=l,e[60]=M,e[61]=h,e[62]=g,e[63]=N):N=e[63];let P;return e[64]!==u||e[65]!==N||e[66]!==_||e[67]!==y?(P=(0,$.jsx)(u,{open:_,onOpenChange:y,children:N}),e[64]=u,e[65]=N,e[66]=_,e[67]=y,e[68]=P):P=e[68],P};function F_(e){return e.isHelpDialogOpen}function I_(e){return e.setHelpDialogOpen}function L_(e){return e.shortcutOverrides}var R_=()=>{let e=(0,Rc.c)(32),{t}=Xe(),n=p(z_),r=p(B_),i=p(V_),a;e[0]!==i||e[1]!==t?(a=async()=>{if(i){if((await $e(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)(or,{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)(sr,{children:l}),e[9]=l,e[10]=u);let d;e[11]!==c||e[12]!==u?(d=(0,$.jsxs)(rr,{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 m;e[16]!==o||e[17]!==f?(m=(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]=m):m=e[18];let h;e[19]!==i||e[20]!==t?(h=i||t(`openCodeStatusDialog.empty.noData`),e[19]=i,e[20]=t,e[21]=h):h=e[21];let g;e[22]===h?g=e[23]:(g=(0,$.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap`,children:h}),e[22]=h,e[23]=g);let _;e[24]!==d||e[25]!==m||e[26]!==g?(_=(0,$.jsxs)(ar,{className:`max-w-2xl`,children:[d,m,g]}),e[24]=d,e[25]=m,e[26]=g,e[27]=_):_=e[27];let v;return e[28]!==n||e[29]!==r||e[30]!==_?(v=(0,$.jsx)(cr,{open:n,onOpenChange:r,children:_}),e[28]=n,e[29]=r,e[30]=_,e[31]=v):v=e[31],v};function z_(e){return e.isOpenCodeStatusDialogOpen}function B_(e){return e.setOpenCodeStatusDialogOpen}function V_(e){return e.openCodeStatusText}var H_=(e,t)=>e?t.kind===e.kind?t.projectRoot.length===e.projectRoot.length?t.projectId.localeCompare(e.projectId)<0:t.projectRoot.length>e.projectRoot.length:t.kind===`project`:!0,U_=(e,t,n)=>{H_(e.get(t),n)&&e.set(t,n)},W_=e=>{let t=e;return _(t.directory)??_(t.project?.worktree)},G_=e=>{if(e===`/`||/^[A-Z]:$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:t===0?`/`:t===2&&/^[A-Z]:\//.test(e)?e.slice(0,2):e.slice(0,t)},K_=(e,t,n,r,i=[])=>{let a=new Map,o=new Map;for(let e of t){let t=_(e.normalizedPath);if(!t)continue;let n=o.get(t);(!n||e.id.localeCompare(n.id)<0)&&o.set(t,e),U_(a,t,{projectId:e.id,projectRoot:t,scopeDirectory:t,kind:`project`})}if(!r)for(let[e,t]of n){let n=_(e),r=n?o.get(n):void 0;if(!(!r||!n))for(let e of t){let t=_(e.path);t&&U_(a,t,{projectId:r.id,projectRoot:n,scopeDirectory:t,kind:`worktree`})}}let s=new Map,c=new Map,l=new Map,u=new Map,d=new Map,f=e=>{if(!e)return null;if(s.has(e))return s.get(e)??null;if(r){let t=a.get(e)??null;return s.set(e,t),t}let t=[],n=e,i=null;for(;n;){if(s.has(n)){i=s.get(n)??null;break}if(t.push(n),i=a.get(n)??null,i)break;n=G_(n)}for(let e of t)s.set(e,i);return i},p=(e,t,n)=>{for(let r of e){let e=f(W_(r));if(!e)continue;c.set(r.id,e);let i=t.get(e.projectId);if(i?i.push(r):t.set(e.projectId,[r]),!n)continue;let a=n.get(e.scopeDirectory);a?a.add(r.id):n.set(e.scopeDirectory,new Set([r.id]))}};return p(e,l,d),p(i,u),{bySessionId:c,sessionsByProject:l,archivedSessionsByProject:u,sessionsByScope:d,directoryResolutions:s.size}},q_=`__other__`;function J_(e){return e.time?.updated??e.time?.archived??e.time?.created??0}function Y_(){let{t:e}=Xe(),{isMobile:t,isTablet:n,hasTouchInput:r}=Ca(),i=t||n||r,a=p(e=>e.isArchivedSessionsDialogOpen),o=p(e=>e.setArchivedSessionsDialogOpen),s=xn(e=>e.projects),c=Vn(e=>e.archivedSessions),l=yn(e=>e.setCurrentSession),u=p(e=>e.setSettingsDialogOpen),[d,f]=Q.useState(!1),[m,h]=Q.useState(null),[g,_]=Q.useState(null);Q.useEffect(()=>{if(!a){h(null),_(null);return}let t=!1;return f(!0),hn().catch(()=>{t||J.error(e(`settings.openchamber.archivedSessions.toast.loadFailed`))}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a,e]);let y=Q.useMemo(()=>{let t=K_([],s.map(e=>({id:e.id,normalizedPath:e.path})),new Map,v(),c),n=new Map;for(let[e,r]of t.archivedSessionsByProject)n.set(e,[...r].sort((e,t)=>J_(t)-J_(e)));let r=new Set;for(let e of n.values())for(let t of e)r.add(t.id);let i=c.filter(e=>!r.has(e.id)).sort((e,t)=>J_(t)-J_(e));i.length>0&&n.set(q_,i);let a=[];for(let e of s){let t=n.get(e.id)??[];t.length!==0&&a.push({projectId:e.id,label:e.label||e.path,path:e.path,sessions:t})}let o=n.get(q_);return o&&o.length>0&&a.push({projectId:q_,label:e(`settings.openchamber.archivedSessions.otherProjects`),path:null,sessions:o}),a.sort((e,t)=>t.sessions.length-e.sessions.length||e.label.localeCompare(t.label)),a},[c,s,e]),b=c.length,x=m?y.find(e=>e.projectId===m)??null:null,S=Q.useCallback(async t=>{_(t.id);try{await Gt(t.id)?J.success(e(`settings.openchamber.archivedSessions.toast.restored`)):J.error(e(`settings.openchamber.archivedSessions.toast.restoreFailed`))}finally{_(null)}},[e]),C=Q.useCallback(e=>{let t=Hn(e);l(e.id,t),o(!1),u(!1)},[l,o,u]),w=x?x.label:e(`settings.openchamber.archivedSessions.dialog.title`),T=x?x.sessions.length===1?e(`settings.openchamber.archivedSessions.dialog.sessionCountSingle`,{count:x.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.sessionCountPlural`,{count:x.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.description`),E=(0,$.jsxs)(`div`,{className:`space-y-3`,children:[x?(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`)]}):x?x.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:x.sessions.map(t=>{let n=Hn(t),r=J_(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?si(r):null,r>0&&n?` · `:null,n?er(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:()=>C(t),children:e(`settings.openchamber.archivedSessions.actions.preview`)}),(0,$.jsxs)(Z,{type:`button`,variant:`default`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>void S(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)})}):y.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:y.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:er(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))}),!x&&!d&&b>0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:e(b===1?`settings.openchamber.archivedSessions.summarySingle`:`settings.openchamber.archivedSessions.summaryPlural`,{count:b})}):null]});return i?(0,$.jsx)(lo,{open:a,title:w,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:w}),e]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground`,children:T})]}),children:E}):(0,$.jsx)(cr,{open:a,onOpenChange:o,children:(0,$.jsxs)(ar,{className:`max-h-[85vh] max-w-2xl overflow-y-auto`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(or,{children:w}),(0,$.jsx)(sr,{children:T})]}),E]})})}var X_=e=>{let t=(0,Rc.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=oi(e.normalizedPath),n=r.archivedSessionsByProject.get(e.id)??[],i=s[t]??[],d=new Map(i.map(Z_));n.forEach(n=>{let r=Br(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 Z_(e){return[e.name.toLowerCase(),e]}var Q_=e=>{let t=(0,Rc.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:p,foldersMap:m}=e,h;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=Ur([...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],h=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]=h}else h=t[8];let g=h,v=g,y;if(t[17]!==p||t[18]!==f||t[19]!==m||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=p(n).includes(d),o=_(n.directory??null),s=(o?m[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]=p,t[18]=f,t[19]=m,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($_),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]!==g||t[36]!==T||t[37]!==S||t[38]!==C||t[39]!==v?(E={projectSections:g,visibleProjectSections:v,groupSearchDataByGroup:b,searchableProjectSections:S,sectionsForRender:C,searchMatchCount:T},t[34]=b,t[35]=g,t[36]=T,t[37]=S,t[38]=C,t[39]=v,t[40]=E):E=t[40],E};function $_(e){return e.groups.length>0}var ev=e=>{let t=(0,Rc.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=_(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 v=g,y=Q.useRef(null),b,x;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]!==v||t[15]!==d||t[16]!==a||t[17]!==f?(b=()=>{if(!r||c||p.getState().isNewWorktreeDialogOpen||y.current===r)return;let e=n.find(e=>e.project.id===r);if(!e)return;y.current=r;let t=v.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 m=i.get(r),h=m&&t.has(m)?m:null,g=v.firstSessionByProject.get(r)?.id??null,_=h??g;if(!_||_===o)return;let b=t.get(_)?.directory??null;s(_,b,r)},x=[r,i,o,s,c,l,u,n,v,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]=v,t[15]=d,t[16]=a,t[17]=f,t[18]=b,t[19]=x):(b=t[18],x=t[19]),Q.useLayoutEffect(b,x);let S,C;t[20]!==r||t[21]!==o||t[22]!==v||t[23]!==a?(S=()=>{if(!r||!o)return;let e=v.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})},C=[r,o,v,a],t[20]=r,t[21]=o,t[22]=v,t[23]=a,t[24]=S,t[25]=C):(S=t[24],C=t[25]),Q.useEffect(S,C)},tv=e=>{let t=(0,Rc.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(nv)),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 nv(e){return[e.id,e]}var rv=e=>!!e.time?.archived,iv=e=>{let t=e.parentID;return typeof t==`string`&&t.trim()?t:null},av=(e,t={})=>{let n=t.pinnedSessionIds??new Set,r=t.omitPinnedSessions===!0,i=t.getWorktree??(()=>null),a=Ur(e).sort((e,t)=>Mr(e,t,n)),o=new Map(a.map(e=>[e.id,e])),s=new Map;a.forEach(e=>{let t=iv(e);if(!t)return;let i=o.get(t);if(!i||rv(i)!==rv(e)||r&&n.has(t))return;let a=s.get(t)??[];a.push(e),s.set(t,a)}),s.forEach(e=>e.sort((e,t)=>Mr(e,t,n)));let c=e=>({session:e,children:(s.get(e.id)??[]).filter(e=>!(r&&n.has(e.id))).map(e=>c(e)),worktree:i(e)});return a.filter(e=>!(r&&n.has(e.id)||iv(e))).map(e=>c(e))},ov=e=>{let{t}=Xe(),n=Q.useCallback(e=>[e.label,e.branch??``,e.description??``,e.directory??``].join(` `).toLowerCase(),[]),r=Q.useCallback(e=>{let n=_(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=_(r??null),c=new Map;i.forEach(e=>{if(e.path){let t=_(e.path)??e.path;c.set(t,e)}});let l=av(n,{pinnedSessionIds:e.pinnedSessionIds,omitPinnedSessions:!0,getWorktree:t=>{let n=_(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=_(e.worktreeMetadata.get(t.id)?.path??null)??Hn(t);return n?n!==s&&c.has(n)?n:n===s?s??`__project_root__`:d:d};l.forEach(e=>{let t=f(e.session);u.has(t)||u.set(t,[]),u.get(t)?.push(e)});let p=s??`__project_root__`,m=[{id:`root`,label:o&&a&&a!==`HEAD`?t(`sessions.sidebar.grouping.projectRootWithBranch`,{branch:a}):t(`sessions.sidebar.grouping.projectRoot`),branch:a??null,description:s?er(s,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:s,folderScopeKey:s,sessions:u.get(p)??[]}],h=new Map;i.forEach(e=>{let t=_(e.path)??e.path,n=u.get(t)??[],r=n.length>0,i=n.reduce((e,t)=>{let n=Tt(t.session);return Number.isFinite(n)?Math.max(e,n):e},0);h.set(t,{hasActiveSession:r,lastUpdatedAt:i})});let g=[...i].sort((e,t)=>{let n=_(e.path)??e.path,r=_(t.path)??t.path,i=h.get(n)??{hasActiveSession:!1,lastUpdatedAt:0},a=h.get(r)??{hasActiveSession:!1,lastUpdatedAt:0};if(i.hasActiveSession!==a.hasActiveSession)return i.hasActiveSession?-1:1;if(i.hasActiveSession&&a.hasActiveSession)return a.lastUpdatedAt-i.lastUpdatedAt;let o=(e.label||e.branch||e.name||e.path||``).toLowerCase(),s=(t.label||t.branch||t.name||t.path||``).toLowerCase();return o.localeCompare(s)});(e.isVSCode?[]:g).forEach(t=>{let n=_(t.path)??t.path,r=e.gitBranches.get(n)?.trim()||null,i=t.branch?.trim()||null,a=r&&i&&t.label&&Pr(t.label)===Pr(i)?r:t.label||t.name||Qn(n,e.homeDirectory)||n;m.push({id:`worktree:${n}`,label:a,branch:r||i,description:er(n,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:t,directory:n,folderScopeKey:n,sessions:u.get(n)??[]})});let v=u.get(d)??[];return m.push({id:`archived`,label:t(`sessions.sidebar.grouping.archived`),branch:null,description:t(`sessions.sidebar.grouping.archivedDescription`),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!e.isVSCode&&s?oi(s):null,sessions:v}),m},[e.homeDirectory,e.worktreeMetadata,e.pinnedSessionIds,e.gitBranches,e.isVSCode,t])}},sv=e=>{let t=(0,Rc.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)},cv=e=>{let t=(0,Rc.c)(42),{t:n}=Xe(),[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)=>{$e(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=uv,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(dv);if(o.length===0){if(a){uc({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)?qs({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){uc({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&&qs({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(fv);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 lv(e){return!e.time?.archived}function uv(e,t){return t?e:e.filter(lv)}function dv(e){return e.id}function fv(e){return e.id}var pv=(e,t)=>{let n=!1,r=new Set;return t.forEach(t=>{if(e.has(t)){r.add(t);return}n=!0}),n?r:t},mv=[`project:active:`,`project:archived:`,`pinned:active:`,`pinned:archived:`],hv=e=>{let{isVSCode:t,fullCatalogSessionIds:n,fullCatalogGeneration:r,safeStorage:i,keys:a,setPinnedSessionIds:o,groupOrderByProject:s,activeSessionByProject:c,collapsedGroups:l,setExpandedParents:u,setCollapsedProjects:d}=e,f=Q.useRef(null),p=Q.useRef(null),[m,h]=Q.useState(!1),g=Q.useCallback(()=>{if(t)return;let e=p.current;if(p.current=null,f.current=null,!e)return;let{projects:n}=xn.getState(),r=n.map(t=>({...t,sidebarCollapsed:e.has(t.id)}));W({projects:r}).catch(()=>{})},[t]),_=Q.useCallback(e=>{typeof window>`u`||t||(p.current=e,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{g()},700))},[t,g]);return Q.useEffect(()=>()=>{typeof window<`u`&&f.current!==null&&window.clearTimeout(f.current),f.current=null,p.current=null},[]),Q.useEffect(()=>{try{let e=i.getItem(a.sessionExpanded);if(e){let t=JSON.parse(e);Array.isArray(t)&&u(new Set(t.filter(e=>typeof e==`string`)))}else{let e=i.getItem(a.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&&mv.forEach(n=>e.add(`${n}${t}`))}),e.size>0){u(e);try{i.setItem(a.sessionExpanded,JSON.stringify(Array.from(e)))}catch{}}}}catch{}try{i.removeItem?.(a.sessionExpandedLegacy)}catch{}}}let t=i.getItem(a.projectCollapse);if(t){let e=JSON.parse(t);Array.isArray(e)&&d(new Set(e.filter(e=>typeof e==`string`)))}}catch{}finally{h(!0)}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,i,d,u]),Q.useEffect(()=>{r!==0&&o(e=>pv(n,e))},[r,n,o]),Q.useEffect(()=>{try{let e=Object.fromEntries(s.entries());i.setItem(a.groupOrder,JSON.stringify(e))}catch{}},[s,a.groupOrder,i]),Q.useEffect(()=>{try{let e=Object.fromEntries(c.entries());i.setItem(a.projectActiveSession,JSON.stringify(e))}catch{}},[c,a.projectActiveSession,i]),Q.useEffect(()=>{try{i.setItem(a.groupCollapse,JSON.stringify(Array.from(l)))}catch{}},[l,a.groupCollapse,i]),{scheduleCollapsedProjectsPersist:_,hasRestoredProjectCollapse:m}},gv=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},_v=e=>{let{normalizedProjects:t,activeProjectId:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a,enabled:o=!0}=e,{git:s}=uo(),c=Uo(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 gv(i,2,async e=>{let t=r.get(e.normalizedPath)?.branch?.trim()??``,n=`${e.normalizedPath}\0${t}`,i=await Pi(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])},vv=e=>{let t=(0,Rc.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},yv=e=>{let t=(0,Rc.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=Sn.getState().foldersMap;new Set([...Object.keys(e),...a.map(bv)]).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 bv(e){return oi(e.normalizedPath)}var xv=e=>{let t=(0,Rc.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(Sv);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 Sv(e){return e.size===0?e:new Set}var Cv=9e4,wv=15e3,Tv=3e5,Ev=[2e3,5e3],Dv=6e4,Ov=12e4,kv=3e5,Av=4,jv=432e5,Mv=`openchamber.github-pr-status`,Nv=e=>e===`closed`||e===`merged`,Pv=e=>{let t=e?.checks;return t?t.state===`pending`||t.pending>0:!1},Fv=(e,t,n)=>`${e}::${t}`,Iv=new Map,Lv=new Map,Rv=new Set,zv=new Map,Bv=2,Vv=0,Hv=[],Uv=()=>Vv<Bv?(Vv+=1,Promise.resolve()):new Promise(e=>{Hv.push(e)}),Wv=()=>{let e=Hv.shift();if(e){e();return}Vv=Math.max(0,Vv-1)},Gv=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Kv=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,qv=e=>{let t=Kv(e);return!t?.directory||!t.branch?null:`${t.directory}::${t.branch}`},Jv=(e,t)=>Object.entries(e).filter(([,e])=>qv(e)===t).map(([e])=>e),Yv=(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}}},Xv=e=>!e?.params?.canShow||!e.params.github?.prStatus?null:{...e.params,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null},Zv=(e,t,n)=>{let r=Jv(e,t),i=r.map(t=>Xv(e[t])).filter(e=>!!e);if(i.length===0)return null;let a=Xv(e[n]);if(a&&qv(e[n])===t)return a;let o=r.map(t=>e[t]).find(e=>!!(e?.resolvedRemoteName&&Xv(e)));return o?Xv(o):i.find(e=>!!e.remoteName)||(i[0]??null)},Qv=e=>({status:e.status,isInitialStatusResolved:e.isInitialStatusResolved,lastRefreshAt:e.lastRefreshAt,lastDiscoveryPollAt:e.lastDiscoveryPollAt,identity:Kv(e),resolvedRemoteName:e.resolvedRemoteName??e.status?.resolvedRemoteName??null}),$v=e=>({...Gv(),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}),ey=fe()(pe((e,t)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:t=>{e(e=>e.entries[t]?e:{entries:{...e.entries,[t]:Gv()}})},setParams:(t,n)=>{e(e=>{let r=e.entries[t]??Gv();return{entries:{...e.entries,[t]:Yv(r,n)}}})},startWatching:n=>{if(e(e=>{let t=e.entries[n]??Gv();return{entries:{...e.entries,[n]:{...t,watchers:t.watchers+1}}}}),Iv.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=Lv.get(n)??[];i.push(r),Lv.set(n,i)};t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),Ev.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<Tv)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}Nv(r.status?.pr?.state)||Date.now()-r.lastRefreshAt<(Pv(r.status)?Dv:r.status?.checks&&r.status.checks.state!==`pending`?kv:Ov)||t().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})}},wv);Iv.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=Iv.get(n);typeof i==`number`&&window.clearInterval(i),Iv.delete(n);let a=Lv.get(n);a&&a.length>0&&a.forEach(e=>{window.clearTimeout(e)}),Lv.delete(n)},refresh:async(n,r)=>{let i=t(),a=i.entries[n],o=qv(a);if(!a||!o)return;let s=Jv(i.entries,o),c=s.some(e=>!!i.entries[e]?.status?.pr);if(r?.onlyExistingPr&&!c)return;let l=zv.get(o)??0;if(!r?.force&&Date.now()-l<Cv||Rv.has(o))return;let u=Zv(i.entries,o,n);if(u){if(Rv.add(o),zv.set(o,Date.now()),e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,lastRefreshAt:Date.now(),isLoading:!r?.silent||n.isLoading,error:null})}),{entries:t}}),u.githubAuthChecked&&u.githubConnected===!1){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:{connected:!1},error:null,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),Rv.delete(o);return}if(!u.github?.prStatus){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:null,error:`GitHub runtime API unavailable`,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),Rv.delete(o);return}try{e(e=>({...e,activeRequestCount:e.activeRequestCount+1,totalRequestCount:e.totalRequestCount+1})),await Uv();let t;try{t=await u.github.prStatus(u.directory,u.branch,u.remoteName??void 0,{force:r?.force})}finally{Wv()}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=Kv(i)??{directory:u.directory,branch:u.branch,remoteName:u.remoteName??null};n[e]={...i,status:s,error:null,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved,resolvedRemoteName:c,identity:{...l,remoteName:c??l.remoteName??null}}}),{entries:n}})}catch(t){let n=t instanceof Error?t.message:String(t);e(e=>{let t={...e.entries};return s.forEach(e=>{let i=t[e];i&&(t[e]={...i,error:n||`Failed to load PR status`,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved})}),{entries:t}})}finally{Rv.delete(o),e(e=>({...e,activeRequestCount:Math.max(0,e.activeRequestCount-1)}))}}},refreshTargets:async(e,n)=>{await gv(Array.from(new Set(e.map(e=>{let t=e.directory.trim(),n=e.branch.trim();return!t||!n?null:Fv(t,n,e.remoteName??null)}).filter(e=>!!e))),Av,e=>t().refresh(e,n))},updateStatus:(t,n)=>{e(e=>{let r=e.entries[t]??Gv();return{entries:{...e.entries,[t]:{...r,status:n(r.status)}}}})}}),{name:Mv,storage:g(),partialize:e=>({entries:Object.fromEntries(Object.entries(e.entries).filter(([,e])=>{let t=Kv(e);if(!t?.directory||!t.branch)return!1;let n=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return n===0||Date.now()-n<jv}).map(([e,t])=>[e,Qv(t)]))}),merge:(e,t)=>{let n=e?.entries??{};return{...t,entries:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,$v(t)]))}}})),ty=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`},ny=e=>{let t=ty(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}},ry=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??``}`,iy=new Map,ay=new Map,oy=e=>{let t=(0,Rc.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=ny(e);if(!a)continue;let o=ry(a);n.set(i,o),r.set(i,a)}if(n.size===iy.size){let e=!0;for(let[t,r]of n)if(iy.get(t)!==r){e=!1;break}if(e)return ay}return iy=n,ay=r,r},t[0]=e,t[1]=n),ey(n)},sy=e=>{let t=(0,Rc.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)(Ds,{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)(ar,{className:`w-full max-w-2xl gap-0 overflow-hidden p-0`,children:(0,$.jsx)(bi,{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)(cr,{open:n,onOpenChange:r,children:s}),t[6]=r,t[7]=n,t[8]=s,t[9]=c):c=t[9],c},cy=Q.memo(e=>{let t=(0,Rc.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}=Xe(),[L,R]=Q.useState(!1),[z,B]=Q.useState(``),V=Q.useRef(null),H=k||L,U=k?A:z,ee;t[0]===n.name?ee=t[1]:(ee=()=>{B(n.name),R(!0)},t[0]=n.name,t[1]=ee);let te=ee,W;t[2]!==U||t[3]!==n.name||t[4]!==k||t[5]!==s||t[6]!==v?(W=()=>{let e=U.trim();e&&e!==n.name&&s(e),k&&v&&v(),R(!1),B(``)},t[2]=U,t[3]=n.name,t[4]=k,t[5]=s,t[6]=v,t[7]=W):W=t[7];let ne=W,G;t[8]!==k||t[9]!==y?(G=()=>{k&&y&&y(),R(!1),B(``)},t[8]=k,t[9]=y,t[10]=G):G=t[10];let re=G,K;t[11]!==k||t[12]!==_?(K=e=>{if(k&&_){_(e);return}B(e)},t[11]=k,t[12]=_,t[13]=K):K=t[13];let ie=K,ae,oe;t[14]===k?(ae=t[15],oe=t[16]):(ae=()=>{if(!k)return;let e=()=>{let e=V.current;e&&(e.focus(),e.select())},t=requestAnimationFrame(e),n=window.setTimeout(e,0);return()=>{cancelAnimationFrame(t),window.clearTimeout(n)}},oe=[k],t[14]=k,t[15]=ae,t[16]=oe),Q.useEffect(ae,oe);let se;t[17]===M?se=t[18]:(se=Vr(M),t[17]=M,t[18]=se);let ce=se,le;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(le=Y(`oc-folder`),t[19]=le):le=t[19];let ue=j&&`bg-primary/10 ring-1 ring-inset ring-primary/30`,de;t[20]===ue?de=t[21]:(de=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`,Nr,ue),t[20]=ue,t[21]=de);let fe;t[22]===ce?fe=t[23]:(fe={paddingLeft:ce},t[22]=ce,t[23]=fe);let pe=H?void 0:o,me=H?void 0:`button`,he=H?void 0:0,ge;t[24]!==o||t[25]!==H?(ge=H?void 0:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},t[24]=o,t[25]=H,t[26]=ge):ge=t[26];let _e;t[27]!==n.name||t[28]!==a||t[29]!==I?(_e=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]=_e):_e=t[30];let ve=P?O?`pr-7`:`group-hover/folder:pr-7 group-focus-within/folder:pr-7`:``,ye;t[31]===ve?ye=t[32]:(ye=Y(`min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]`,ve),t[31]=ve,t[32]=ye);let be=j?`text-primary`:`text-muted-foreground`,xe;t[33]===be?xe=t[34]:(xe=Y(`h-4 w-4 flex-shrink-0`,be),t[33]=be,t[34]=xe);let Se;t[35]===xe?Se=t[36]:(Se=(0,$.jsx)(X,{name:`folder-open`,className:xe}),t[35]=xe,t[36]=Se);let Ce;t[37]!==U||t[38]!==n.name||t[39]!==re||t[40]!==ie||t[41]!==ne||t[42]!==a||t[43]!==j||t[44]!==H||t[45]!==r||t[46]!==I?(Ce=H?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-1 items-center gap-1`,onPointerDown:ly,onMouseDown:uy,onSubmit:e=>{e.preventDefault(),ne()},children:[(0,$.jsx)(`input`,{ref:V,value:U,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:I(`sessions.sidebar.folderItem.namePlaceholder`),onClick:dy,onPointerDown:fy,onMouseDown:py,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),re();return}(e.key===` `||e.key===`Enter`)&&e.stopPropagation()}}),(0,$.jsx)(`button`,{type:`submit`,className:`shrink-0 text-muted-foreground hover:text-foreground`,onClick:my,onPointerDown:hy,onMouseDown:gy,children:(0,$.jsx)(X,{name:`check`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re()},onPointerDown:_y,onMouseDown:vy,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]=U,t[38]=n.name,t[39]=re,t[40]=ie,t[41]=ne,t[42]=a,t[43]=j,t[44]=H,t[45]=r,t[46]=I,t[47]=Ce):Ce=t[47];let we;t[48]!==ye||t[49]!==Se||t[50]!==Ce?(we=(0,$.jsxs)(`div`,{className:ye,children:[Se,Ce]}),t[48]=ye,t[49]=Se,t[50]=Ce,t[51]=we):we=t[51];let Te;t[52]!==O||t[53]!==P||t[54]!==M||t[55]!==n.name||t[56]!==te||t[57]!==N||t[58]!==c||t[59]!==S||t[60]!==C||t[61]!==H||t[62]!==I?(Te=!H&&(!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(),te()},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]=te,t[57]=N,t[58]=c,t[59]=S,t[60]=C,t[61]=H,t[62]=I,t[63]=Te):Te=t[63];let Ee;t[64]!==b||t[65]!==de||t[66]!==fe||t[67]!==pe||t[68]!==me||t[69]!==he||t[70]!==ge||t[71]!==_e||t[72]!==we||t[73]!==Te?(Ee=(0,$.jsxs)(`div`,{ref:b,className:de,style:fe,onClick:pe,role:me,tabIndex:he,onKeyDown:ge,"aria-label":_e,children:[we,Te]}),t[64]=b,t[65]=de,t[66]=fe,t[67]=pe,t[68]=me,t[69]=he,t[70]=ge,t[71]=_e,t[72]=we,t[73]=Te,t[74]=Ee):Ee=t[74];let De;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?(De=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:Vr(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]=De):De=t[86];let Oe;return t[87]!==Ee||t[88]!==De?(Oe=(0,$.jsxs)(`div`,{className:le,children:[Ee,De]}),t[87]=Ee,t[88]=De,t[89]=Oe):Oe=t[89],Oe});function ly(e){return e.stopPropagation()}function uy(e){return e.stopPropagation()}function dy(e){return e.stopPropagation()}function fy(e){return e.stopPropagation()}function py(e){return e.stopPropagation()}function my(e){return e.stopPropagation()}function hy(e){return e.stopPropagation()}function gy(e){return e.stopPropagation()}function _y(e){return e.stopPropagation()}function vy(e){return e.stopPropagation()}var yy=e=>Object.fromEntries(e.map(e=>[e.id,Tt(e)])),by=(e,t,n)=>{let r=yy(e.map(e=>e.session));return Dn(r,n)?new Map((t??[]).map((e,t)=>[e,t])):new Map},xy=(e,t,n,r)=>{let i=by(e,t,n);return(e,t)=>{let n=i.get(e.session.id),a=i.get(t.session.id);if(n!==void 0||a!==void 0){if(n===void 0)return 1;if(a===void 0)return-1;if(n!==a)return n-a}return Mr(e.session,t.session,r)}},Sy=({folders:e,visibleUngroupedNodes:t,collapsedFolderIds:n,hasSessionSearchQuery:r})=>{let i=new Map(e.map(e=>[e.folder.id,e])),a=new Map;e.forEach(({folder:e})=>{let t=e.parentId??null,n=a.get(t)??[];n.push(e.id),a.set(t,n)});let o=[],s=new Map,c=e=>{let t=i.get(e);t&&(!r&&n.has(e)||((a.get(e)??[]).forEach(c),t.nodes.forEach(t=>{o.push(t.session.id),s.set(t.session.id,e)})))};return(a.get(null)??[]).forEach(c),t.forEach(e=>{o.push(e.session.id),s.set(e.session.id,null)}),{sessionIds:o,folderIdBySessionId:s}},Cy=(e,t,n)=>n.get(e)===n.get(t),wy=e=>{let t=(0,Rc.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}=Oo(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]:(_=To.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},Ty=e=>{let t=(0,Rc.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}=vo(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},Ey=e=>{let t=(0,Rc.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=wo(_o(So,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:/,``);Cy(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(Dy),t[9]=i,t[10]=S);let C;t[11]!==s||t[12]!==S?(C=(0,$.jsx)(Ao,{items:S,strategy:ko,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)(xo,{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)(Co,{sensors:l,collisionDetection:bo,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 Dy(e){return`session-drag:${e}`}var Oy=3e4,ky=e=>{let t=e,n=t.metadata?.openchamber?.titleRefresh,r=Tt(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/Oy)].join(`\0`)},Ay=(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)},jy=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(let n of e.children)if(jy(n,t))return!0;return!1},My=e=>e.children.length===0?``:e.children.map(e=>e.children.length===0?e.session.id:`${e.session.id}:${My(e)}`).join(`|`),Ny=(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},Py=fe()(pe(e=>({displayMode:`minimal`,projectSortOrder:`manual`,setDisplayMode:t=>e({displayMode:t}),setProjectSortOrder:t=>e({projectSortOrder:t})}),{name:`session-display-mode`,storage:H(),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`&&l(e=>{t(e)&&Py.persist.rehydrate()});var Fy=e=>!!e.parentID,Iy=(e,t)=>_(Hn(e.session))??_(t.directory??null),Ly=()=>3,Ry=(e,t,n)=>{let r=Math.min(e.length,Math.max(0,t)),i=e.slice(0,r);for(let t=r;t<e.length;t+=1){let r=e[t];r&&n.has(r.session.id)&&i.push(r)}return i},zy=({targets:e,collapsedProjectIds:t,collapsedGroupKeys:n,collapsedFolderIds:r,visibleSessionCountByGroup:i,defaultVisibleSessionCount:a,hasSessionSearchQuery:o,alwaysVisibleSessionIds:s})=>e.filter(e=>{if(!e.projectId||t.has(e.projectId))return!1;if(o)return!0;if(e.groupKey&&n.has(e.groupKey)||e.folderAncestorIds?.some(e=>r.has(e)))return!1;if(e.groupKey&&e.visibleIndex!==void 0){let t=Math.max(a,i.get(e.groupKey)??a);if(e.visibleIndex>=t&&!s?.has(e.sessionId))return!1}return!0}),By=(e,t,n)=>{if(!t||n==null||!Number.isInteger(n)||n<0)return null;if(e[n]?.session.id===t)return n;let r=e.findIndex(e=>e.session.id===t);return r>=0?r:null},Vy=({sections:e,foldersMap:t,getOrderedGroups:n,pinnedSessionIds:r,sessionOrderByScope:i,sessionOrderActivityByScope:a})=>{let o=[];return e.forEach(e=>{let s=n(e.project.id,e.groups),c=s.find(e=>e.isMain)??null;(c?[c,...s.filter(e=>e.id!==c.id)]:s).forEach(n=>{if(n.isArchivedBucket)return;let s=`${e.project.id}:${n.id}`,c=n.folderScopeKey??_(n.directory??null),l=xy(n.sessions,c?i[c]:void 0,c?a[c]:void 0,r),u=[...n.sessions].filter(e=>!e.session.time?.archived&&!Fy(e.session)).sort(l),d=new Map(u.map(e=>[e.session.id,e])),f=c?t[c]??[]:[],p=new Map;f.forEach(e=>{let t=e.parentId??null,n=p.get(t)??[];n.push(e),p.set(t,n)});let m=new Set(f.flatMap(e=>e.sessionIds)),h=(t,r,i)=>{o.push({scope:`project`,sessionId:t.session.id,projectId:e.project.id,directory:Iy(t,n),groupKey:s,folderAncestorIds:r,visibleIndex:i})},g=(e,t)=>{let n=f.find(t=>t.id===e);if(!n)return;let r=[...t,n.id];(p.get(n.id)??[]).forEach(e=>{g(e.id,r)}),n.sessionIds.map(e=>d.get(e)).filter(e=>!!e).sort(l).forEach(e=>h(e,r))};(p.get(null)??[]).forEach(e=>g(e.id,[])),u.filter(e=>!m.has(e.session.id)).forEach((e,t)=>h(e,void 0,t))})}),o},Hy=50,Uy=30,Wy=28,Gy=(e,t)=>t?e.sessions.some(e=>jy(e,t)):!1,Ky=(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)},qy=(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)},Jy=(e,t,n)=>{let r=i=>{let a=i.session.id,o=e.folderScopeKey??_(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)},Yy=(e,t,n)=>{let r=e.folderScopeKey??_(e.directory??null);return!!(r&&t[r]!==n[r])},Xy=(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)},Zy=(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&&ky(a)!==ky(o)||e.children.some(r)};return e.sessions.some(r)},Qy=e=>{if(e.projectId)return e.projectRepoStatus.has(e.projectId)?e.projectRepoStatus.get(e.projectId):void 0},$y=e=>{let t=new WeakMap,n=e=>{t.set(e,My(e));for(let t of e.children)n(t)};return e.forEach(n),t},eb=e=>{let t=[],n=e=>{e.forEach(e=>{t.push(e.session),e.children.length>0&&n(e.children)})};return n(e),t},tb=(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&&Qy(e)!==Qy(t)||e.pinnedSessionIds!==t.pinnedSessionIds&&Ky(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&Xy(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderByScope!==t.sessionOrderByScope&&Jy(t.group,e.sessionOrderByScope,t.sessionOrderByScope)||e.sessionOrderActivityByScope!==t.sessionOrderActivityByScope&&Yy(t.group,e.sessionOrderActivityByScope,t.sessionOrderActivityByScope)||e.currentSessionId!==t.currentSessionId&&(Gy(e.group,e.currentSessionId)||Gy(t.group,t.currentSessionId))||e.editingId!==t.editingId&&(Gy(e.group,e.editingId)||Gy(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Gy(e.group,e.editingId)||Gy(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Ny(e.group.sessions,e.openSidebarMenuKey,`project`,!!e.group.isArchivedBucket),r=Ny(t.group.sessions,t.openSidebarMenuKey,`project`,!!t.group.isArchivedBucket);if(n||r)return!1}if(e.liveSessionById!==t.liveSessionById&&Zy(t.group,e.liveSessionById,t.liveSessionById)||e.runningSessionIds!==t.runningSessionIds&&qy(t.group,e.runningSessionIds,t.runningSessionIds))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 nb(e){let{t}=Xe(),{group:n,groupKey:r,isArchivedLoading:i=!1,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:s,normalizedSessionSearchQuery:c,groupSearchDataByGroup:l,visibleSessionCount:u,collapsedGroups:d,collapsedFolderIds:f,toggleFolderCollapse:p,renameFolder:m,deleteFolder:h,showDeletionDialog:g,setDeleteFolderConfirm: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:L,pinnedSessionIds:R,expandedParents:z,sessionOrderByScope:B,sessionOrderActivityByScope:V,onReorderSessions:H,currentSessionId:U,shortcutTargetSessionId:ee=null,shortcutTargetVisibleIndex:te=null,editingId:W,openSidebarMenuKey:ne,prVisualStateByDirectoryBranch:G,onToggleCollapsedGroup:re,dragHandleProps:K,compactBodyPadding:ie=!1,scrollContainerRef:ae,runningSessionIds:oe}=e,se=n.folderScopeKey??_(n.directory??null),ce=Q.useMemo(()=>xy(n.sessions,se?B[se]:void 0,se?V[se]:void 0,R),[se,n.sessions,R,V,B]),le=s?l.get(n):null,ue=Py(e=>e.displayMode),de=Sn(e=>e.foldersMap),fe=ue===`minimal`&&!v(),pe=n.isArchivedBucket?null:_(n.directory??null),me=Vn(e=>pe?e.activePaginationByDirectory.get(pe):void 0),he=!s&&d.has(r),ge=Ly(),_e=Math.max(ge,u??ge),ve=s?le?.groupMatches===!0:!1,ye=s,be=Q.useMemo(()=>[...ye?le?.filteredNodes??[]:n.sessions].sort(ce),[ce,n.sessions,le?.filteredNodes,ye]),xe=Q.useMemo(()=>se?de[se]??[]:[],[se,de]),Se=Q.useMemo(()=>{let e=new Map,t=n=>{n.forEach(n=>{e.set(n.session.id,n),n.children.length>0&&t(n.children)})};return t(be),e},[be]),Ce=Q.useMemo(()=>xe.map(e=>({folder:e,nodes:e.sessionIds.map(e=>Se.get(e)).filter(e=>!!e).sort(ce)})),[xe,Se,ce]),we=Q.useMemo(()=>{let e=new Map(Ce.map(e=>[e.folder.id,e])),t=new Map;for(let{folder:e}of Ce){if(!e.parentId)continue;let n=t.get(e.parentId);n?n.push(e.id):t.set(e.parentId,[e.id])}let r=new Map,i=a=>{let o=r.get(a);if(o!==void 0)return o;let l=e.get(a);if(!l)return r.set(a,!1),!1;let u=t.get(a)??[];if(n.isArchivedBucket&&l.nodes.length===0){let e=u.some(e=>i(e));return r.set(a,e),e}if(!s||l.folder.name.toLowerCase().includes(c)||l.nodes.length>0)return r.set(a,!0),!0;let d=u.some(e=>i(e));return r.set(a,d),d};return Ce.filter(({folder:e})=>i(e.id))},[Ce,n.isArchivedBucket,s,c]),Te=Q.useMemo(()=>new Set(we.flatMap(e=>e.folder.sessionIds)),[we]),Ee=Q.useMemo(()=>be.filter(e=>!Te.has(e.session.id)),[be,Te]),De=Q.useMemo(()=>we.filter(({folder:e})=>!e.parentId),[we]),Oe=`project`,ke=Q.useMemo(()=>{let e=new Set;return Ay(be,U,e),we.forEach(({nodes:t})=>{Ay(t,U,e)}),e},[be,we,U]),Ae=Q.useMemo(()=>{let e=new Set;return Ay(be,W,e),we.forEach(({nodes:t})=>{Ay(t,W,e)}),e},[be,we,W]),je=Q.useMemo(()=>{if(!ne)return null;let e=Ny(be,ne,Oe,!!n.isArchivedBucket);if(e)return e;for(let{nodes:e}of we){let t=Ny(e,ne,Oe,!!n.isArchivedBucket);if(t)return t}return null},[ne,be,we,n.isArchivedBucket]),Me=Q.useMemo(()=>$y(be),[be]),Ne=Q.useMemo(()=>{let e=new WeakMap;return we.forEach(({nodes:t})=>{t.forEach(t=>e.set(t,My(t)))}),e},[we]),q=Q.useMemo(()=>e=>Me.get(e)??Ne.get(e)??``,[Me,Ne]),Pe=Q.useMemo(()=>e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e)}),[ke,Ae,je,q]),Fe=Ee.length,Ie=n.isArchivedBucket||s?Ee:Ee.slice(0,_e),Le=n.isArchivedBucket||s?Ee:Ry(Ee,_e,oe),Re=Fe-Le.length,ze=Q.useMemo(()=>Sy({folders:we,visibleUngroupedNodes:Le,collapsedFolderIds:f,hasSessionSearchQuery:s}),[we,f,s,Le]),Be=me?.hasMore===!0,Ve=me?.loadingMore===!0,He=u===void 0||u<=ge,Ue=!n.isArchivedBucket&&!s&&Fe>ge&&!He,We=n.isArchivedBucket===!0&&!s&&Le.length>=Hy,Ke=n.isArchivedBucket!==!0&&!s&&Le.length>=Uy,Je=We||Ke,Ye=n.isArchivedBucket?`archived`:`active`,Ze=Je&&Le.some(e=>{if(e.children.length===0)return!1;let t=`project:${Ye}:${e.session.id}`;return z.has(t)}),Qe=Q.useRef(null),[$e,et]=Q.useState(null),[,tt]=Q.useState(0);qe(Je?Qe:null,()=>{tt(e=>e+1)}),Q.useLayoutEffect(()=>{if(!Je){et(e=>e===null?e:null);return}let e=Qe.current;if(!e){et(e=>e===null?e:null);return}let t=null,n=ae?.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=ae?.current??null,it=Je&&$e!==null&&$e.container===nt&&$e.scrollElement.contains(nt)&&(rt===null||$e.scrollElement===rt),at=$e?.scrollElement??null,ot=$e?.scrollMargin??0,st=$o({count:Le.length,enabled:it,getScrollElement:()=>at,initialOffset:()=>at?.scrollTop??0,estimateSize:()=>Wy,overscan:Ze?20:8,scrollMargin:ot,getItemKey:e=>Le[e]?.session.id??e}),ct=By(Le,ee,te);Q.useLayoutEffect(()=>{!it||!ee||ct===null||st.getVirtualItems().some(e=>e.index===ct)||st.scrollToIndex(ct,{align:`auto`,behavior:`auto`})},[ot,st,ee,ct,it]);let lt=Q.useMemo(()=>eb(be),[be]),ut=Q.useMemo(()=>{if(!n.isArchivedBucket)return new Map;let e=new Map,t=new Map;for(let{folder:e}of we){if(!e.parentId)continue;let n=t.get(e.parentId)??[];n.push(e.id),t.set(e.parentId,n)}let r=(e,n)=>{if(n.has(e))return[];n.add(e);let i=we.find(({folder:t})=>t.id===e),a=i?eb(i.nodes):[],o=t.get(e)??[];for(let e of o)a.push(...r(e,n));return a};for(let{folder:t}of we)e.set(t.id,r(t.id,new Set));return e},[we,n.isArchivedBucket]),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=Ge(e=>{e.preventDefault(),e.stopPropagation();let t=_(n.directory??null),r=n.branch?.trim()??null,i=t&&r?G.get(`${t}::${r}`)?.url??null:null;i&&jo(i)});if(s&&!ve&&De.length===0&&Ee.length===0)return null;let pt=a&&x.has(a)?!!x.get(a):S,mt=_(n.directory??null),ht=n.branch?.trim()??null,gt=mt&&ht?G.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,Ct=gt?.base??null,wt=gt?.head??null,Tt=(()=>{if(!gt)return n.branch&&Hr(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}})(),Et=(e,t,r)=>{let i=we.filter(({folder:t})=>t.parentId===e.id),o=i.length>0?(0,$.jsx)($.Fragment,{children:i.map(({folder:e,nodes:t})=>Et(e,t,r+1))}):void 0,c=ut.get(e.id)??[];return(0,$.jsx)(Ty,{folderId:e.id,children:(i,l)=>(0,$.jsx)(cy,{folder:e,sessions:t,subFolderItems:o,isCollapsed:!s&&f.has(e.id),onToggle:()=>p(e.id),onRename:t=>{se&&m(se,e.id,t)},onDelete:()=>{if(n.isArchivedBucket){Cn.requestDelete({sessions:c,mode:`session`});return}if(!se)return;if(!g){h(se,e.id);return}let r=we.filter(({folder:t})=>t.parentId===e.id).length,i=t.length;y({scopeKey:se,folderId:e.id,folderName:e.name,subFolderCount:r,sessionCount:i})},renderSessionNode:b,getRenderExtras:q?e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe}):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&&se&&m(se,e.id,t),L(null),I(``)},onRenameCancel:()=>{L(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?()=>{se&&N(se,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)},Dt=+!o,Ot=o?1:Dt,kt=()=>De.map(({folder:e,nodes:t})=>Et(e,t,Ot)),At=!!(!n.isMain&&n.worktree),jt=E?At?`pr-14`:`pr-7`:fe?At?`pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-2`:At?`pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-5`,Mt=(0,$.jsxs)(Ey,{scopeKey:se,sessionIds:ze.sessionIds,folderIdBySessionId:ze.folderIdBySessionId,onSessionDroppedOnFolder:(e,t)=>{se&&M(se,t,e)},onSessionsReordered:(e,t)=>{H(ze.sessionIds,e,t,yy(n.sessions.map(e=>e.session)))},children:[kt(),Je?(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,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(t),childRenderExtrasFor:Pe})},t.session.id):null})}):Le.map(e=>b(e,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe}))}):Le.map(e=>b(e,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe})),Fe===0&&we.length===0?(0,$.jsx)(`div`,{className:gi,style:{paddingLeft:Vr(Ot)},children:i?t(`sessions.sidebar.project.loadingSessions`):n.isArchivedBucket?t(`sessions.sidebar.group.empty.noArchivedSessions`):t(`sessions.sidebar.group.empty.noSessionsInWorkspace`)}):null,Re>0||Be||Ue?(0,$.jsxs)(`div`,{className:Y(gi,`flex w-full items-center gap-3 text-muted-foreground/60`),style:{paddingLeft:Vr(Ot)},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,Ue?(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]}),Nt=o?ie?`pb-0`:`pb-0.5`:ie?`pb-1`:`pb-1.5`,Pt=Vr(Dt);return o?(0,$.jsx)(`div`,{className:`oc-group`,children:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Nt),children:Mt})}):(0,$.jsxs)(`div`,{className:`oc-group`,children:[(0,$.jsxs)(`div`,{"data-mobile-press-feedback":K?`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`,Nr),style:{paddingLeft:Pt},onClick:()=>re(r),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),re(r))},"aria-label":t(he?`sessions.sidebar.group.expandAria`:`sessions.sidebar.group.collapseAria`,{label:n.label}),"aria-expanded":!he,children:[(0,$.jsx)(`div`,{ref:K?.setActivatorNodeRef,className:Y(`min-w-0 flex flex-1 items-start gap-1.5 overflow-hidden transition-[padding] cursor-grab active:cursor-grabbing`,jt),...K?.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)(Hi,{children:[(0,$.jsx)(zi,{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:he?(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)(Bi,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||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:he?(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:Lr(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:he?(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:Lr(n.label,c)})]}):Lr(n.label,c)}),vt&&Tt?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1.5 leading-tight`,!Tt.color&&`text-muted-foreground`),style:Tt.color?{color:Tt.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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||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:Tt.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)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Cn.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)(Bi,{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)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Cn.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)(Bi,{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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.project.actions.newDraftSession`)})})]})}):null]}),he?null:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Nt),children:Mt})]})}var rb=Q.memo(nb,tb);function ib(e){let t=(0,Rc.c)(36),{t:n}=Xe(),{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 ab(e){let t=(0,Rc.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 ob(e){let t=(0,Rc.c)(43),{items:n,renderSessionNode:r,currentSessionId:i,editingId:a,openSidebarMenuKey:o,headerAccessory:s,onVisibleSessionIdsChange:c}=e,{t:l}=Xe(),[u,d]=Q.useState(!1),f=$r(ub),p,m;t[0]!==u||t[1]!==n||t[2]!==c?(p=()=>{c?.(u?[]:n.map(lb))},m=[u,n,c],t[0]=u,t[1]=n,t[2]=c,t[3]=p,t[4]=m):(p=t[3],m=t[4]),Q.useLayoutEffect(p,m);let h,g;t[5]!==n||t[6]!==f?(h=()=>{f&&n.some(e=>e.node.session.id===f)&&d(!1)},g=[n,f],t[5]=n,t[6]=f,t[7]=h,t[8]=g):(h=t[7],g=t[8]),Q.useLayoutEffect(h,g);let _,v,y,b;if(t[9]!==i||t[10]!==a||t[11]!==n||t[12]!==o){let e=n.map(cb);y=new Set,Ay(e,i,y),b=new Set,Ay(e,a,b),_=Ny(e,o,`pinned`,!1),v=new WeakMap;let r=e=>{v.set(e,My(e)),e.children.forEach(r)};e.forEach(r),t[9]=i,t[10]=a,t[11]=n,t[12]=o,t[13]=_,t[14]=v,t[15]=y,t[16]=b}else _=t[13],v=t[14],y=t[15],b=t[16];let x;t[17]!==_||t[18]!==v||t[19]!==y||t[20]!==b?(x=e=>({subtreeContainsActive:y,subtreeContainsEditing:b,menuOpenSessionId:_,nodeStructureKey:v.get(e)??``,childRenderExtrasFor:x}),t[17]=_,t[18]=v,t[19]=y,t[20]=b,t[21]=x):x=t[21];let S;t[22]!==x||t[23]!==_||t[24]!==v||t[25]!==y||t[26]!==b?(S=e=>({subtreeContainsActive:y,subtreeContainsEditing:b,menuOpenSessionId:_,nodeStructureKey:v.get(e)??``,childRenderExtrasFor:x}),t[22]=x,t[23]=_,t[24]=v,t[25]=y,t[26]=b,t[27]=S):S=t[27];let C=S;if(n.length===0)return null;let w;t[28]===l?w=t[29]:(w=l(`directoryTree.section.pinned`),t[28]=l,t[29]=w);let T;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>d(sb),t[30]=T):T=t[30];let E=!u,D;t[31]!==s||t[32]!==w||t[33]!==E?(D=(0,$.jsx)(ab,{title:w,onToggle:T,expanded:E,accessory:s}),t[31]=s,t[32]=w,t[33]=E,t[34]=D):D=t[34];let O;t[35]!==u||t[36]!==C||t[37]!==n||t[38]!==r?(O=u?null:(0,$.jsx)(`div`,{className:`space-y-0.5`,children:n.map(e=>(0,$.jsx)(Q.Fragment,{children:r(e.node,0,e.groupDirectory,e.projectId,!1,e.secondaryMeta,`pinned`,C(e.node))},`${e.projectId??``}:${e.node.session.id}`))}),t[35]=u,t[36]=C,t[37]=n,t[38]=r,t[39]=O):O=t[39];let k;return t[40]!==O||t[41]!==D?(k=(0,$.jsx)(Vi,{delay:0,closeDelay:150,timeout:600,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[D,O]})}),t[40]=O,t[41]=D,t[42]=k):k=t[42],k}function sb(e){return!e}function cb(e){return e.node}function lb(e){return e.node.session.id}function ub(e){return e.focus?.scope===`pinned`?e.focus.sessionId:null}function db(e){let t=(0,Rc.c)(41),{collapseAllProjects:n,expandAllProjects:r,buttonClassName:i,iconClassName:a}=e,{t:o}=Xe(),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)(zi,{asChild:!0,children:(0,$.jsx)(sa,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,className:s,"aria-label":c,onClick:fb,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)(Bi,{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)(Hi,{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)(ca,{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)(ca,{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)($i,{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)(ea,{children:[m,C]}),t[38]=C,t[39]=m,t[40]=w):w=t[40],w}function fb(e){e.stopPropagation()}var pb=`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`,mb=`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`;function hb(e){let t=(0,Rc.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}=Xe(),u;t[0]!==n||t[1]!==r||t[2]!==s||t[3]!==l?(u=s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:pb,onClick:n,"aria-label":l(`sessions.sidebar.footer.actions.settings`),children:(0,$.jsx)(X,{name:`settings-3`,className:mb})})}),(0,$.jsx)(Bi,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.settings`)})]}),(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:pb,onClick:r,"aria-label":l(`sessions.sidebar.footer.actions.shortcuts`),children:(0,$.jsx)(X,{name:`question`,className:mb})})}),(0,$.jsx)(Bi,{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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{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 gb=e=>{let t=(0,Rc.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}=Xe(),I=A||!P,L;t[0]!==n||t[1]!==I?(L={id:n,disabled:I},t[0]=n,t[1]=I,t[2]=L):L=t[2];let{attributes:R,listeners:z,setNodeRef:B,transform:V,transition:H,isDragging:U}=Oo(L),ee=Q.useRef(!1),te=`project:${n}`,W=D===te,[ne,G]=Q.useState(!1),re=o?Oi[o]:null,K=s?Mi[s]:void 0,ie=re??`folder-open`,ae;t[3]===K?ae=t[4]:(ae=K?{color:K}:void 0,t[3]=K,t[4]=ae);let oe;t[5]!==ie||t[6]!==ae?(oe=(0,$.jsx)(X,{name:ie,className:`h-4 w-4`,style:ae}),t[5]=ie,t[6]=ae,t[7]=oe):oe=t[7];let se=oe,ce;t[8]!==te||t[9]!==O?(ce=e=>{e&&G(!1),O(e?te:null)},t[8]=te,t[9]=O,t[10]=ce):ce=t[10];let le=ce,ue;t[11]!==h||t[12]!==f||t[13]!==S||t[14]!==v||t[15]!==x||t[16]!==b||t[17]!==M||t[18]!==F?(ue=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]=ue):ue=t[19];let de=ue,fe=vb,pe=yb,me=bb,he;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(he=e=>{(e.button===2||e.button===0&&e.ctrlKey)&&(ee.current=!0)},t[20]=he):he=t[20];let ge=he,_e;t[21]===_?_e=t[22]:(_e=()=>{if(ee.current){ee.current=!1;return}_()},t[21]=_,t[22]=_e);let ve=_e,ye;t[23]===V?ye=t[24]:(ye=To.Transform.toString(V),t[23]=V,t[24]=ye);let be;t[25]!==ye||t[26]!==H?(be={transform:ye,transition:H},t[25]=ye,t[26]=H,t[27]=be):be=t[27];let xe=U&&`opacity-30`,Se;t[28]===xe?Se=t[29]:(Se=Y(`relative`,xe),t[28]=xe,t[29]=Se);let Ce;t[30]!==g||t[31]!==R||t[32]!==le||t[33]!==ve||t[34]!==h||t[35]!==N||t[36]!==n||t[37]!==u||t[38]!==l||t[39]!==ne||t[40]!==p||t[41]!==W||t[42]!==f||t[43]!==j||t[44]!==m||t[45]!==z||t[46]!==v||t[47]!==y||t[48]!==a||t[49]!==se||t[50]!==c||t[51]!==i||t[52]!==de||t[53]!==P||t[54]!==C||t[55]!==M||t[56]!==F?(Ce=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)(gc,{open:ne,onOpenChange:G,children:[(0,$.jsx)(fc,{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(),G(!0))}}),children:(0,$.jsxs)(`div`,{className:Y(`relative flex items-center gap-1.5 rounded-lg px-2 py-1.5`,Nr),...R,children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onMouseDown:ge,onClick:ve,...P?z:{},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:se}):se})]})}),(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)(Bi,{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)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(`sessions.sidebar.project.actions.newWorktreeEllipsis`)})})]}):null,h?null:(0,$.jsxs)(ea,{open:W,onOpenChange:le,children:[(0,$.jsx)(sa,{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`,W?`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:pe,onMouseDown:me,onClick:fe,children:(0,$.jsx)(X,{name:`more-2`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)($i,{align:`end`,className:`min-w-[180px]`,children:de(ca)})]})]}),M&&v?(0,$.jsx)(`div`,{className:`absolute right-0.5 top-1/2 z-10 -translate-y-1/2`,children:(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{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)(Bi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`)})})]})}):null]})}),(0,$.jsx)(mc,{className:`min-w-[180px]`,children:de(hc)})]})]}),t[30]=g,t[31]=R,t[32]=le,t[33]=ve,t[34]=h,t[35]=N,t[36]=n,t[37]=u,t[38]=l,t[39]=ne,t[40]=p,t[41]=W,t[42]=f,t[43]=j,t[44]=m,t[45]=z,t[46]=v,t[47]=y,t[48]=a,t[49]=se,t[50]=c,t[51]=i,t[52]=de,t[53]=P,t[54]=C,t[55]=M,t[56]=F,t[57]=Ce):Ce=t[57];let we;return t[58]!==w||t[59]!==B||t[60]!==be||t[61]!==Se||t[62]!==Ce?(we=(0,$.jsxs)(`div`,{ref:B,style:be,className:Se,children:[Ce,w]}),t[58]=w,t[59]=B,t[60]=be,t[61]=Se,t[62]=Ce,t[63]=we):we=t[63],we},_b=Q.memo(e=>{let t=(0,Rc.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}=Oo(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=To.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 vb(e){e.stopPropagation()}function yb(e){e.stopPropagation()}function bb(e){e.stopPropagation()}var xb=e=>{let t=(0,Rc.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(Vi,{delay:0,closeDelay:150,timeout:600,children:n}),t[0]=n,t[1]=r),r};function Sb(e){let{t}=Xe(),n=wo(_o(So,{activationConstraint:{distance:8}}),_o(yo,{coordinateGetter:Eo})),r=wo(_o(So,{activationConstraint:{distance:8}})),i=e.hasSessionSearchQuery?null:(0,$.jsx)(ab,{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)(xb,{children:(0,$.jsxs)(bi,{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)(xb,{children:(0,$.jsxs)(bi,{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)(xb,{children:(0,$.jsx)(bi,{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)(xb,{children:(0,$.jsxs)(bi,{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:gi,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)(Co,{sensors:n,collisionDetection:bo,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)(Ao,{items:e.sectionsForRender.map(e=>e.project.id),strategy:ko,children:e.sectionsForRender.map(n=>{let i=n.project,o=i.id,s=Qn(i.normalizedPath)||i.normalizedPath,l=er(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)(gb,{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:Vr(1)},role:`status`,"aria-live":`polite`,children:t(`sessions.sidebar.project.loadingSessions`)}):n.groups.length>0?(0,$.jsxs)(Co,{sensors:r,collisionDetection:bo,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=Do(_,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)(Ao,{items:_.map(e=>e.id),strategy:ko,children:_.map(t=>{let n=`${o}:${t.id}`;return(0,$.jsx)(_b,{id:t.id,disabled:e.isInlineEditing,children:r=>e.renderGroupSessions(t,n,o,!1,r,void 0,a)},t.id)})}),(0,$.jsx)(xo,{dropAnimation:null})]}):(0,$.jsx)(`div`,{className:gi,children:t(`sessions.sidebar.empty.noSessions.title`)})})},o)})}),(0,$.jsx)(xo,{dropAnimation:null})]})]})]})})}function Cb(e){if(typeof e!=`number`||!Number.isFinite(e))return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toLocaleString(Qe(),{month:`short`})} ${t.getDate()}, ${t.getFullYear()}, ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function wb(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 Tb(e){let t=e.info.role===`user`?`User`:`Assistant`,n=Cb(e.info.time?.created),r=wb(e),i=n&&r?`${n} (${r})`:n||r;return i?`**${t}**\n\n*${i}*`:`**${t}**`}function Eb(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(``)}function Db(e){let t=Tb(e),n=Eb(e.parts).trim();return n?`${t}\n\n${n}`:``}function Ob(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(Db).filter(Boolean).join(`
|
|
149
|
+
`);j({sessionKey:t,source:`preview-console`,fileLabel:e||U||`preview`,startLine:1,endLine:Math.max(1,C.length),code:`${r}${i}`,language:`text`,text:n(`contextPanel.preview.console.attachAnnotation`)}),J.success(n(`contextPanel.preview.console.attached`))},[j,C,k,U,A,e,n]),[ae,oe]=Q.useState(`unknown`),se=Q.useRef(0),ce=Q.useRef(0);Q.useEffect(()=>{if(!H){oe(`unknown`),se.current=0,ce.current=0;return}let e=!1;return se.current||(se.current=Date.now(),ce.current=0),oe(`unknown`),(async()=>{let t=await(async()=>{try{return await V(H,{method:`GET`,credentials:`include`,cache:`no-store`,redirect:`manual`})}catch{return null}})();if(e)return;if(!t){oe(`unreachable`);return}if(t.status===403||t.status===404){Oh.delete(L),d({status:`loading`}),l();return}if(t.status!==502){oe(`reachable`);return}let n=se.current||Date.now();if(Date.now()-n<15e3){oe(`starting`),ce.current+=1;let t=ce.current,n=Math.min(2e3,250*2**Math.min(4,t));setTimeout(()=>{e||o()},n).unref?.();return}oe(`unreachable`)})(),()=>{e=!0}},[L,H,a]);let le=P&&u.status===`ready`&&(ae===`unknown`||ae===`starting`),ue=P&&u.status===`ready`&&ae===`unreachable`,de=Q.useCallback(e=>{if(!P||u.status!==`ready`||typeof window>`u`)return;let t=e.currentTarget.contentWindow;if(t)try{let e=t.location,n=kg(H);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{}},[P,H,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:ee||e,children:ee||e||n(`contextPanel.preview.empty`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>o(),title:n(`contextPanel.preview.actions.reload`),"aria-label":n(`contextPanel.preview.actions.reload`),disabled:!U,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&&Mo(z)},title:n(`contextPanel.preview.actions.openExternal`),"aria-label":n(`contextPanel.preview.actions.openExternal`),disabled:!z,children:(0,$.jsx)(X,{name:`external-link`,className:`h-3.5 w-3.5`})}),P?(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:T?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>E(e=>!e),title:n(`contextPanel.preview.inspect.toggle`),"aria-label":n(`contextPanel.preview.inspect.toggle`),disabled:!_,children:(0,$.jsx)(X,{name:`cursor`,className:`h-3.5 w-3.5`})}):null,P?(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:y?`secondary`:`ghost`,className:`h-7 gap-1 px-2`,onClick:()=>b(e=>!e),title:n(_?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),"aria-label":n(_?`contextPanel.preview.console.open`:`contextPanel.preview.console.waiting`),disabled:!_&&C.length===0,children:[(0,$.jsx)(X,{name:`terminal-box`,className:`h-3.5 w-3.5`}),G>0?(0,$.jsx)(`span`,{className:`typography-micro text-status-error`,children:G}):null]}):null]}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 bg-background`,children:[le?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.startingServer`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.startingServerHint`)})]}):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:n(`contextPanel.preview.upstreamUnreachable`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:n(`contextPanel.preview.upstreamUnreachableHint`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>o(),children:n(`contextPanel.preview.actions.retry`)})]}):U&&(!P||ae===`reachable`)?(0,$.jsxs)(`div`,{className:`relative h-full w-full`,children:[(0,$.jsx)(`iframe`,{ref:h,src:U,title:n(`contextPanel.preview.iframeTitle`),className:`h-full w-full border-0`,style:{colorScheme:R},onLoad:de,sandbox:P?`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads`:`allow-scripts allow-forms`},`${U}:${a}`),T&&D?(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:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.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:[D.tag,D.text?` · ${D.text}`:``]})}):null]}):te?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-sm text-muted-foreground`,children:n(`contextPanel.preview.loading`)}):W?(0,$.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{children:n(`contextPanel.preview.proxyError`)}),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:n(`contextPanel.preview.invalidUrl`)}),y?(0,$.jsxs)(`div`,{className:`absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/50 px-3 py-2`,children:[(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground`,children:n(`contextPanel.preview.console.title`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:ie,disabled:C.length===0,children:n(`contextPanel.preview.console.attach`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:K,disabled:C.length===0,children:n(`contextPanel.preview.console.copy`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>w([]),disabled:C.length===0,children:n(`contextPanel.preview.console.clear`)})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/30 px-3 py-1.5`,children:[`all`,`errors`,`warnings`,`logs`].map(e=>(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:x===e?`secondary`:`ghost`,onClick:()=>S(e),children:n(e===`all`?`contextPanel.preview.console.filter.all`:e===`errors`?`contextPanel.preview.console.filter.errors`:e===`warnings`?`contextPanel.preview.console.filter.warnings`:`contextPanel.preview.console.filter.logs`)},e))}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-auto p-2 typography-code text-xs`,children:C.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.empty`)}):re.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-muted-foreground`,children:n(`contextPanel.preview.console.noFilteredEvents`)}):re.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]})]})},Pg=()=>typeof window<`u`&&!!window.__OPENCHAMBER_ELECTRON__,Fg=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=Xe(),a=Q.useRef(null),o=p(e=>e.setContextPanelTabTargetPath),c=Eg(e),l=c===`about:blank`?``:c,[u,d]=Q.useState(l),[f,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=Tn(e=>e.currentSessionId),F=Tn(e=>e.newSessionDraft?.open),I=Pa(e=>e.addDraft),L=Lt(e=>e.addAttachedFile),R=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||o(t,n,e)},[t,n,o]),z=Q.useCallback((e,t)=>{let n=Eg(e),r=n===`about:blank`?``:n;h(r),d(r),t?.inFrame?T(!1):(_(r),T(!!r)),R(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,R]),B=Q.useCallback(e=>{let t=v[e];t&&(x(e),h(t),_(t),d(t),T(!0),R(t))},[v,R]),H=Q.useCallback(()=>{if(f){T(!0);try{a.current?.contentWindow?.location.reload()}catch{C()}}},[f]);Q.useEffect(()=>{if(!g){j({status:`idle`});return}let e=Mh(g),t=jh(e);if(t?.previewToken){j({status:`ready`,proxyBasePath:t.proxyBasePath,previewToken:t.previewToken,expiresAt:t.expiresAt});return}t&&Oh.delete(e);let n=!1;return j({status:`loading`}),T(!0),(async()=>{try{let t=await V(`/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 i=await t.json(),a=typeof i.proxyBasePath==`string`?i.proxyBasePath:``,o=typeof i.previewToken==`string`?i.previewToken:``,s=typeof i.expiresAt==`number`?i.expiresAt:0;if(!a||!o){n||j({status:`error`,message:r(`contextPanel.preview.proxyError`)});return}Oh.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,r]);let U=g&&A.status===`ready`?`${A.proxyBasePath}|${A.previewToken||``}|${S}`:``;Q.useEffect(()=>{if(!U){N(``);return}let e=!1;return N(``),s(m()).then(t=>{!e&&t&&N(U)}).catch(()=>{}),()=>{e=!0}},[U]);let ee=Q.useMemo(()=>{if(M!==U||!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 i().authenticatedAsset(`${A.proxyBasePath}${t}${r?`?${r}`:``}${e.hash}`)}catch{return``}},[g,A,U,S,M]),te=ee||(A.status===`error`?g:``),W=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 Mg(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)?``:Mg(new URL(`${t.pathname}${t.search}${t.hash}`,n).toString())}catch{return``}},[g,A]),G=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(r(`contextPanel.preview.inspect.attachNoSession`));return}let n=a.current,i=n?.contentWindow,o=n?.getBoundingClientRect(),s={width:Number.isFinite(i?.innerWidth)?i?.innerWidth??o?.width??0:o?.width??0,height:Number.isFinite(i?.innerHeight)?i?.innerHeight??o?.height??0:o?.height??0},c=n?await Th(n,e):null,l=!!c;c&&await L(c),I({sessionKey:t,source:`preview-annotation`,fileLabel:f||`browser`,startLine:1,endLine:1,code:wh({pageUrl:f,viewport:s,devicePixelRatio:window.devicePixelRatio||1,target:e,screenshotAttached:l,intro:r(l?`contextPanel.preview.inspect.attachAnnotationWithScreenshot`:`contextPanel.preview.inspect.attachAnnotation`)}),language:`markdown`,text:``}),J.success(r(`contextPanel.preview.inspect.attached`))},[L,I,P,f,F,r]),K=Q.useCallback(()=>{let e=a.current;k(null),G(!1),e&&Dg(e,wg).catch(()=>{})},[G]);Q.useEffect(()=>{if(!E)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),D(!1),K())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[K,E]),Q.useEffect(()=>()=>K(),[K]),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=W(e);n&&n!==f&&z(n,{inFrame:!0});return}if(t.type===`hover`){k(Ch(t.target)?t.target:null);return}if(t.type===`select`&&Ch(t.target)){k(null),D(!1),G(!1),re(t.target);return}if(t.type===`navigate-preview`){let e=typeof t.url==`string`?t.url:``,n=ne(e);if(n){z(n);return}e&&z(e)}}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[z,re,f,W,ne,G]);let ie=Q.useCallback(()=>{let e=a.current;if(!(!e||!f)){if(E){D(!1),K();return}if(ee){k(null),D(!0),G(!0);return}D(!0),(async()=>{try{let t=await Dg(e,Cg);if(D(!1),!t||!Ch(t))return;await re(t)}catch{D(!1),J.error(r(`contextPanel.browser.inspectUnavailable`))}})()}},[re,K,f,E,G,ee,r]),ae=Q.useCallback(()=>{try{let e=a.current?.contentWindow?.location.href||``,t=ne(e);if(t){z(t,{inFrame:!0});return}}catch{}T(!1),E&&ee&&G(!0)},[z,ne,E,G,ee]);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:()=>B(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:()=>B(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:!f,onClick:H,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(),z(u)},children:(0,$.jsx)(`input`,{value:u,onChange:e=>d(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:E?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,disabled:!f,onClick:ie,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`,disabled:!f,onClick:()=>void Mo(f),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:r(`contextPanel.browser.empty`),className:`absolute inset-0 h-full w-full border-0 bg-background`,allow:`clipboard-read; clipboard-write; fullscreen`,allowFullScreen:!0,onLoad:ae},`${n}:${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)(da,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)}),(0,$.jsx)(`span`,{className:`max-w-sm typography-micro text-muted-foreground`,children:r(`contextPanel.browser.emptyHint`)}),(0,$.jsx)(`span`,{className:`max-w-md typography-micro leading-relaxed text-status-warning/70`,children:r(`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:r(`common.loading`)}):null]})]})},Ig=({initialUrl:e,directory:t,tabID:n})=>{let{t:r}=Xe(),i=Q.useRef(null),a=p(e=>e.setContextPanelTabTargetPath),o=Eg(e),s=o===`about:blank`?``:o,c=Q.useRef(Eg(e)),[l,u]=Q.useState(s),[d,f]=Q.useState(s),[m,h]=Q.useState(!1),[g,_]=Q.useState(!0),v=Q.useRef(null),y=g,b=Q.useCallback(e=>{!e||e===`about:blank`||!t||!n||a(t,n,e)},[t,n,a]),x=Tn(e=>e.currentSessionId),S=Tn(e=>e.newSessionDraft?.open),C=Pa(e=>e.addDraft),w=Lt(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),b(t))}catch{}},n=e=>{let t=e.detail;typeof t?.url==`string`&&t.url&&(f(t.url),u(t.url),b(t.url))},r=()=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>_(!0),200)},a=()=>{v.current&&clearTimeout(v.current),_(!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?.(Tg,!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()||(_(!1),t())}catch{}return s(),()=>{v.current&&clearTimeout(v.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)}},[b]),Q.useEffect(()=>{let e=setTimeout(()=>_(!1),3e4);return()=>clearTimeout(e)},[]),Q.useEffect(()=>{if(!m)return;let e=e=>{if(e.key!==`Escape`)return;e.preventDefault(),e.stopImmediatePropagation(),h(!1);let t=i.current;try{t?.executeJavaScript?.(wg).catch(()=>{})}catch{}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[m]),Q.useEffect(()=>{let e=i.current;return()=>{try{let r=e?.getURL?.();r&&r!==`about:blank`&&a(t,n,r)}catch{}try{e?.executeJavaScript?.(wg).catch(()=>{})}catch{}}},[t,n,a]);let T=Q.useCallback(e=>{let t=i.current;if(typeof t?.loadURL!=`function`)return;let n=Eg(e);try{t.loadURL(n)}catch{}},[]),E=Q.useCallback(()=>{let e=i.current;if(e){if(m){h(!1);try{e.executeJavaScript?.(wg).catch(()=>{})}catch{}return}h(!0),e.executeJavaScript?.(Cg,!0).then(async t=>{if(h(!1),!t||!Ch(t))return;let n=x??(S?`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 Ze(`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 Eh(a.base64,a.width,a.height,s,c,t),u=!!l;l&&await w(l),C({sessionKey:n,source:`preview-annotation`,fileLabel:d||`browser`,startLine:1,endLine:1,code:wh({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(()=>h(!1))}},[w,C,x,d,m,S,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(),T(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:m?`secondary`:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:E,title:r(`contextPanel.preview.inspect.toggle`),"aria-label":r(`contextPanel.preview.inspect.toggle`),children:(0,$.jsx)(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 Mo(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`)&&!g?(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)(da,{width:140,height:140,className:`opacity-20`}),(0,$.jsx)(`span`,{className:`typography-ui-header text-muted-foreground`,children:r(`contextPanel.browser.empty`)})]}):null,y?(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]})]})},Lg=()=>{let{t:e}=Xe(),t=Ro()??``,n=Q.useMemo(()=>ug(t),[t]),i=p(e=>n?e.contextPanelByDirectory[n]:void 0),a=p(e=>n?e.contextToolDiffByDirectory[n]:void 0),o=p(e=>e.closeContextPanel),s=p(e=>e.closeContextPanelTab),c=p(e=>e.openContextPanelTab),l=p(e=>e.toggleContextPanelExpanded),u=p(e=>e.setContextPanelWidth),d=p(e=>e.setActiveContextPanelTab),f=p(e=>e.reorderContextPanelTabs),m=Ho(e=>e.setSelectedPath),h=p(e=>e.openContextPreview),g=p(e=>e.allowPromptingSubagentSessions),{themeMode:_,setThemeMode:v,lightThemeId:y,darkThemeId:b,currentTheme:x}=$i(),S=Q.useMemo(()=>i?.tabs??[],[i?.tabs]),C=S.find(e=>e.id===i?.activeTabId)??S[S.length-1]??null,w=!!(i?.isOpen&&C),T=!!(w&&i?.expanded),E=dg(i?.width??ag),D=Q.useMemo(()=>{let e=[];for(let t of S){if(t.mode!==`chat`)continue;let n=yg(t.dedupeKey);n&&!e.includes(n)&&e.push(n)}return e},[S]),O=Sg(n||void 0,D),[k,A]=Q.useState(!1),[j,M]=Q.useState(!1),N=Q.useRef(0),P=Q.useRef(E),F=Q.useRef(null),I=Q.useRef(null),L=Q.useRef(null),R=Q.useRef(new Map),z=Q.useRef(new Map),B=Q.useRef(!1),V=Q.useRef(w),H=Q.useRef(null),[U,ee]=Q.useState({}),te=Q.useRef(U);te.current=U;let[W,ne]=Q.useReducer(hh,{activeViewKey:null,tabs:{},mountedViews:{}}),G=Lm(),re=r(),K=Q.useCallback(e=>{let t=te.current,n=e(t);return n!==t&&(te.current=n,ee(n),!0)},[]),ie=Q.useCallback(e=>{if(!n)return;ne({type:`close-tab`,tabId:e});let t=Rm(n,e);K(e=>{if(!e[t])return e;let n={...e};return delete n[t],n}),s(n,e)},[s,K,n]),ae=Q.useCallback(()=>{M(!0),H.current!==null&&window.cancelAnimationFrame(H.current),H.current=window.requestAnimationFrame(()=>{H.current=null,M(!1)})},[]);Q.useEffect(()=>()=>{H.current!==null&&window.cancelAnimationFrame(H.current)},[]),Q.useLayoutEffect(()=>{let e=V.current;if(V.current=w,!w){M(!1);return}e||ae()},[w,ae]),Q.useEffect(()=>{if(!w||B.current){B.current=w;return}let e=window.requestAnimationFrame(()=>{L.current?.focus({preventScroll:!0})});return B.current=!0,()=>window.cancelAnimationFrame(e)},[w]);let oe=Q.useCallback(e=>{let t=L.current;t&&t.style.setProperty(`--oc-context-panel-width`,`${pg(e,t)}px`)},[]),se=Q.useCallback(e=>{if(!(!w||T||!n)){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}I.current=e.pointerId,A(!0),N.current=e.clientX,P.current=E,F.current=E,oe(E),e.preventDefault()}},[oe,n,T,w,E]),ce=Q.useCallback(e=>{if(!k||I.current!==e.pointerId)return;let t=N.current-e.clientX,n=pg(P.current+t,L.current);F.current!==n&&(F.current=n,oe(n))},[oe,k]),le=Q.useCallback(e=>{if(I.current!==e.pointerId||!n)return;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}let t=pg(F.current??E,L.current);ae(),oe(t),F.current=t,u(n,t),A(!1),I.current=null},[oe,n,u,ae,E]);Q.useEffect(()=>{k||(F.current=null)},[k]);let ue=Q.useCallback(()=>{n&&o(n)},[o,n]),de=Q.useCallback(()=>{n&&l(n)},[n,l]),fe=Q.useCallback(e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`w`&&C&&n){e.preventDefault(),e.stopPropagation(),ie(C.id);return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),ue())},[C,ie,n,ue]);Q.useEffect(()=>{if(!(!n||!C)&&C.mode===`file`&&C.targetPath){m(n,C.targetPath,{allowOutsideRoot:!0});return}},[C,n,m]);let pe=C?.mode===`chat`?C.id:null,me=Gm(pe?U[Rm(n,pe)]:void 0,pe?yg(C?.dedupeKey):null);Q.useEffect(()=>{if(!w||!n||!me){At(``,null);return}return At(n,me),()=>{At(``,null)}},[me,n,w]),Q.useEffect(()=>{if(!w||!n||!me||typeof window>`u`)return;let e=()=>{if(document.visibilityState===`hidden`||!document.hasFocus()){gt(n,me,!1);return}It(me),gt(n,me,!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),gt(n,me,!1)}},[me,n,w]);let he=Q.useCallback((e,t,r)=>Da(z.current,e,t,n||null,r,{mode:_,lightThemeId:y,darkThemeId:b,currentTheme:x}),[x,b,n,y,_]);Q.useEffect(()=>{let e=new Set(S.map(e=>e.id));for(let t of z.current.keys())e.has(t)||z.current.delete(t)},[S]);let ge=Q.useCallback(e=>{!n||C?.mode!==`diff`&&C?.mode!==`file-diff`||c(n,{mode:C.mode,targetPath:C.targetPath,stagedDiff:e===`staged`,diffScope:e})},[C,n,c]),_e=Q.useCallback(()=>{if(typeof window>`u`)return;let e={themeMode:_,lightThemeId:y,darkThemeId:b,currentTheme:x};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)}},[x,b,y,_]),ve=Q.useCallback(()=>{if(typeof window>`u`)return;let e={allowPromptingSubagentSessions:g};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)}},[g]),ye=Q.useCallback(()=>{if(!(typeof window>`u`))for(let[e,t]of R.current.entries()){let n=t.contentWindow;if(!n)continue;let r={visible:pe===e},i=n.__openchamberSetEmbeddedVisibility;if(typeof i==`function`)try{i(r);continue}catch{}n.postMessage({type:Ua,payload:r},window.location.origin)}},[pe]);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&&n&&ie(t[0]);return}if(t?.type===`openchamber:chat-settings-request`){ve();return}if(t?.type===`openchamber:embedded-visibility-request`){ye();return}if(t?.type!==`openchamber:cycle-theme-request`)return;let r=[`light`,`dark`,`system`],i=(r.indexOf(_)+1)%r.length;v(r[i])};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[ie,n,ve,ye,v,_]),Q.useLayoutEffect(()=>{S.some(e=>e.mode===`chat`)&&(_e(),ve(),ye())},[b,y,ve,ye,_e,S,_]);let be=Q.useMemo(()=>S.map(n=>{let r=_g(n,O,e),i=Og(r,og),a=mg(n.targetPath,t);return{id:n.id,label:i,icon:vg(n),title:a?`${r}: ${a}`:r,closeLabel:e(`contextPanel.tab.closeTabAria`,{label:i})}}),[t,O,e,S]),xe=C?.mode===`context`?(0,$.jsx)(wm,{}):C?.mode===`plan`?(0,$.jsx)(Zp,{targetPath:C.targetPath}):C?.mode===`preview`?(0,$.jsx)(Ng,{rawUrl:C.targetPath??``,onNavigate:e=>h(t,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:e(`contextPanel.preview.title`)}),(0,$.jsx)(`div`,{className:`max-w-sm typography-micro text-muted-foreground`,children:e(`contextPanel.preview.description`)})]}),Se=Q.useMemo(()=>S.filter(e=>e.mode===`chat`),[S]),Ce=Q.useMemo(()=>S.filter(e=>e.mode===`browser`),[S]),we=Q.useMemo(()=>S.filter(e=>e.mode===`diff`||e.mode===`file-diff`),[S]),Te=Pg()?Ig:Fg,Ee=Q.useMemo(()=>S.some(e=>e.mode===`file`),[S]),De=C?.mode===`file`,Oe=De?C?.fileNotice??null:null;Q.useEffect(()=>{let e=new Set(Se.map(e=>Rm(n,e.id)));K(t=>{let r=!1,i={};for(let e of Se){let a=yg(e.dedupeKey);if(!a)continue;let o=Rm(n,e.id),s=t[o];i[o]=s??Um({sessionId:a,directory:n}),r||=!s}let a=Xm(t,e);return r||=a!==t,r?{...a,...i}:t});for(let t of Object.keys(W.tabs))(!e.has(Rm(n,t))||W.tabs[t]?.directory!==n)&&ne({type:`close-tab`,tabId:t})},[Se,K,n,W.tabs]);let ke=pe?Rm(n,pe):null,Ae=pe?yg(C?.dedupeKey):null,je=ke&&Ae?Wm(U[ke],{sessionId:Ae,directory:n}):void 0,Me=je&&ke?zm(re,ke,je.current.directory,je.current.sessionId):null;Q.useLayoutEffect(()=>{if(G!==`react-surface`||!w||!pe||!je||!ke||!Me){G===`react-surface`&&ne({type:`activate`,viewKey:null,now:Date.now()});return}K(e=>e[ke]?e:{...e,[ke]:je}),ne({type:`touch`,tab:{tabId:pe,sessionId:je.anchor.sessionId,directory:je.anchor.directory},view:{tabId:pe,surfaceId:ke,sessionId:je.current.sessionId,directory:je.current.directory,viewKey:Me},now:Date.now()})},[je,ke,pe,Me,G,K,w]);let Ne=Q.useCallback((e,t,r)=>{let i=Rm(n,e),a=!1;return K(e=>{let n=Ym(e,i,{sessionId:t,directory:r});return a=n.accepted,n.navigationBySurfaceId}),a},[K,n]),q=Q.useCallback(e=>{let t=Rm(n,e);K(e=>{let n=e[t];if(!n)return e;let r=qm(n);return r===n?e:{...e,[t]:r}})},[K,n]),Pe=(0,$.jsxs)(`header`,{className:`flex h-10 items-stretch border-b border-transparent`,children:[(0,$.jsx)($o,{items:be,activeId:C?.id??null,onSelect:e=>{n&&d(n,e)},onClose:e=>{ie(e)},onReorder:(e,t)=>{n&&f(n,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:de,className:`h-7 w-7 p-0`,title:e(T?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),"aria-label":e(T?`contextPanel.actions.collapsePanel`:`contextPanel.actions.expandPanel`),children:T?(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:ue,className:`h-7 w-7 p-0`,title:e(`contextPanel.actions.closePanel`),"aria-label":e(`contextPanel.actions.closePanel`),children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),Fe=w?T?{"--oc-context-panel-width":`100%`,width:`100%`,minWidth:`100%`,maxWidth:`100%`}:{width:`min(var(--oc-context-panel-width), 100%)`,minWidth:`min(${rg}px, 100%)`,maxWidth:`100%`,"--oc-context-panel-width":`${k?F.current??E:E}px`}:{"--oc-context-panel-width":`${k?F.current??E:E}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:!w||void 0,className:Y(`flex min-h-0 flex-col overflow-hidden bg-background`,!T&&`border-l border-border/40`,T?`absolute inset-0 z-20 min-w-0`:`relative h-full flex-shrink-0`,!w&&`pointer-events-none`,k||!w||j?`transition-none`:`transition-[width] duration-200 ease-in-out`),onKeyDownCapture:fe,style:Fe,children:[!T&&(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`,k&&`bg-[var(--interactive-border)]`),onPointerDown:se,onPointerMove:ce,onPointerUp:le,onPointerCancel:le,role:`separator`,"aria-orientation":`vertical`,"aria-label":e(`contextPanel.actions.resizePanelAria`)}),Pe,Oe===`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:e(`contextPanel.file.notice.turnDiffOutsideWorkspace`)}):null,(0,$.jsxs)(`div`,{className:Y(`relative min-h-0 flex-1 overflow-hidden`,k&&`pointer-events-none`),children:[Ee?(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,De?`block`:`hidden`),children:(0,$.jsx)(bp,{mode:`editor-only`,isActive:w&&De})}):null,G===`legacy-iframe`&&Se.map(t=>{let n=yg(t.dedupeKey);if(!n)return null;let r=he(t.id,n,t.readOnly);return r?(0,$.jsx)(`iframe`,{ref:e=>{if(!e){R.current.delete(t.id);return}R.current.set(t.id,e)},src:r,title:e(`contextPanel.iframe.sessionChatTitle`,{sessionID:n}),className:Y(`absolute inset-0 h-full w-full border-0 bg-background`,pe===t.id?`block`:`hidden`),onLoad:()=>{_e(),ve(),ye()}},t.id):null}),G===`react-surface`?Object.values(W.mountedViews).map(e=>{let t=U[Rm(n,e.tabId)],r=w&&pe===e.tabId&&Me===e.viewKey;return(0,$.jsx)(Q.Activity,{name:`context-panel-session-${e.sessionId}`,mode:r?`visible`:`hidden`,children:(0,$.jsx)(vh,{surfaceId:e.surfaceId,sessionId:e.sessionId,directory:e.directory,active:r,canNavigateBack:r&&!!t?.stack.length,onNavigateSession:(t,n)=>Ne(e.tabId,t,n),onNavigateBack:()=>q(e.tabId),onEstimateBytes:(e,t)=>ne({type:`estimate`,viewKey:e,estimatedBytes:t})})},e.viewKey)}):null,Ce.map(e=>(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,C?.id!==e.id&&`hidden`),children:(0,$.jsx)(Te,{initialUrl:e.targetPath??``,directory:n,tabID:e.id})},e.id)),we.map(e=>{let t=e.mode===`diff`&&a?.targetPath===e.targetPath&&a.turnMessageId===e.diffTurnMessageId?a.patches:null;return(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,C?.id!==e.id&&`hidden`),children:(0,$.jsx)(Rs,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!t,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:e.diffScope??(e.stagedDiff?`staged`:`working`),turnMessageId:e.diffTurnMessageId,sessionId:e.diffSessionId,directory:n,onDiffScopeChange:ge,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)}),C?.mode!==`chat`&&!De&&C?.mode!==`browser`&&C?.mode!==`diff`&&C?.mode!==`file-diff`?xe:null]})]})},Rg=(e,t)=>!e||t.length===0?``:JSON.stringify([e,t]),zg=(e,t,n,r)=>!n||r!==n||e.length===0?[]:an(e,t,e=>e.name,{limit:10,threshold:.4}),Bg=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},Vg=`h-8 gap-2 rounded-md px-2.5 py-0 typography-meta`,Hg=`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`,Ug=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},Wg=()=>{let e=(0,zc.c)(177),{t}=Xe(),n=p(Gg),r=p(Kg),i=p(qg),a=p(Jg),o=p(Yg),s=p(Xg),c=p(Zg),l=p(Qg),u=p($g),d=p(e_),f=p(t_),m=p(n_),h=Tn(r_),g=Tn(i_),_=vn(a_),y=Pe(o_),b=mn(s_),x=mn(c_),S=Ro(),C=Ae(l_),{files:T,git:E}=fo(),D=Wo(u_),{isMobile:O}=wa(),k;e[0]===S?k=e[1]:(k=S?Ug(S):null,e[0]=S,e[1]=k);let j=k,[M,N]=Q.useState(``),P=Vo(M,200).trim(),F;e[2]===M?F=e[3]:(F=M.trim(),e[2]=M,e[3]=F);let L=F,R,z;e[4]===n?(R=e[5],z=e[6]):(R=()=>{n&&N(``)},z=[n],e[4]=n,e[5]=R,e[6]=z),Q.useEffect(R,z);let B,V;e[7]!==_||e[8]!==D||e[9]!==E||e[10]!==n?(B=()=>{if(!n||!E)return;let e=setTimeout(()=>{let e=new Set;for(let t of _){let n=fn(t);!n||e.has(n)||(e.add(n),D(n,E))}},0);return()=>clearTimeout(e)},V=[n,_,E,D],e[7]=_,e[8]=D,e[9]=E,e[10]=n,e[11]=B,e[12]=V):(B=e[11],V=e[12]),Q.useEffect(B,V);let H;e[13]===r?H=e[14]:(H=()=>r(!1),e[13]=r,e[14]=H);let U=H,ee;e[15]===U?ee=e[16]:(ee=e=>()=>{U(),e()},e[15]=U,e[16]=ee);let W=ee,ne;e[17]!==b?.id||e[18]!==b?.path||e[19]!==y||e[20]!==S||e[21]!==O||e[22]!==d||e[23]!==h||e[24]!==W||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:W(()=>{i(`chat`),s(!1),h()})},{id:`new-worktree`,title:t(`commandPalette.item.newWorktreeDraft`),shortcutId:`new_chat_worktree`,searchText:t(`commandPalette.item.newWorktreeDraft`),onSelect:W(d_)},{id:`add-project`,title:t(`commandPalette.item.addProject`),searchText:t(`commandPalette.item.addProject`),onSelect:W(f_)},{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:W(()=>{if(O){let{isSessionSwitcherOpen:e}=p.getState();s(!e)}else c()})},{id:`toggle-right-sidebar`,title:t(`commandPalette.item.toggleRightSidebar`),shortcutId:`toggle_right_sidebar`,searchText:t(`commandPalette.item.toggleRightSidebar`),onSelect:W(()=>l())},{id:`toggle-terminal`,title:t(`commandPalette.item.toggleTerminal`),shortcutId:`toggle_terminal`,searchText:t(`commandPalette.item.toggleTerminal`),onSelect:W(()=>u())},{id:`new-terminal-tab`,title:t(`commandPalette.item.newTerminalTab`),shortcutId:`open_new_terminal`,searchText:t(`commandPalette.item.newTerminalTab`),onSelect:W(()=>{S&&ti(S)})},{id:`context-usage`,title:t(`commandPalette.item.showContextUsage`),searchText:t(`commandPalette.item.showContextUsage`),onSelect:W(()=>{y&&d(y)})},{id:`open-settings`,title:t(`commandPalette.item.openSettings`),shortcutId:`open_settings`,searchText:t(`commandPalette.item.openSettings`),onSelect:W(()=>a(!0))}];return w()&&e.splice(1,0,{id:`new-mini-chat`,title:t(`commandPalette.item.newMiniChat`),shortcutId:`new_mini_chat`,searchText:t(`commandPalette.item.newMiniChat`),onSelect:W(()=>{te(`desktop_open_draft_mini_chat_window`,{directory:Ug(y||b?.path||``),projectId:b?.id??null}).catch(p_)})}),e},e[17]=b?.id,e[18]=b?.path,e[19]=y,e[20]=S,e[21]=O,e[22]=d,e[23]=h,e[24]=W,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],b?.id,b?.path;let G;e[33]===ne?G=e[34]:(G=ne(),e[33]=ne,e[34]=G);let re=G,K;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(K=A(),e[35]=K):K=e[35];let ie=K,ae,oe;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(ae=v(),oe=!ie&&I(),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]!==W||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]!==W||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:W(()=>{o(e.slug),a(!0)})}},e[47]=W,e[48]=a,e[49]=o,e[50]=n):n=e[50],le=Es.filter(m_).filter(t).map(n),e[40]=W,e[41]=a,e[42]=o,e[43]=ce,e[44]=le}else le=e[44];let ue=le,de=h_,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=Go(),he=Tn(g_),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),[xe,Se]=Q.useState(``),Ce=Rg(j,P),we;e[58]!==j||e[59]!==Ce||e[60]!==n||e[61]!==C||e[62]!==be||e[63]!==Se||e[64]!==P?(we=()=>{if(!n){be([]),Se(``);return}if(!Ce){be([]),Se(``);return}if(!j){be([]),Se(``);return}let e=!1;return C(j,P,10,{type:`file`}).then(t=>{e||(be(t.map(__)),Se(Ce))}).catch(()=>{e||(be([]),Se(Ce))}),()=>{e=!0}},e[58]=j,e[59]=Ce,e[60]=n,e[61]=C,e[62]=be,e[63]=Se,e[64]=P,e[65]=we):we=e[65];let Te;e[66]!==j||e[67]!==Ce||e[68]!==n||e[69]!==C||e[70]!==P?(Te=[n,j,P,Ce,C],e[66]=j,e[67]=Ce,e[68]=n,e[69]=C,e[70]=P,e[71]=Te):Te=e[71],Q.useEffect(we,Te);let Ee=L.length>0,De;bb0:{if(!Ee){let t;e[72]===re?t=e[73]:(t=re.map(v_),e[72]=re,e[73]=t),De=t;break bb0}let t;e[74]!==re||e[75]!==L?(t=an(re,L,y_,{limit:7,noFuzzy:!0}),e[74]=re,e[75]=L,e[76]=t):t=e[76],De=t}let Oe=De,ke;bb1:{if(!Ee){let t;e[77]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[77]=t):t=e[77],ke=t;break bb1}let t;e[78]!==L||e[79]!==ue?(t=an(ue,L,b_,{limit:7,noFuzzy:!0}),e[78]=L,e[79]=ue,e[80]=t):t=e[80],ke=t}let je=ke,Me;bb2:{if(!Ee){let t;e[81]===pe?t=e[82]:(t=pe.slice(0,5).map(x_),e[81]=pe,e[82]=t),Me=t;break bb2}let t;e[83]!==L||e[84]!==pe?(t=an(pe,L,S_,{limit:7,threshold:.2}),e[83]=L,e[84]=pe,e[85]=t):t=e[85],Me=t}let Ne=Me,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]!==xe||e[89]!==Ce||e[90]!==P?(t=zg(ye,P,Ce,xe),e[87]=ye,e[88]=xe,e[89]=Ce,e[90]=P,e[91]=t):t=e[91],q=t}let Fe=q,Ie=n&&Ce.length>0&&xe!==Ce,Le;bb4:{if(!Ee){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]!==L||e[94]!==x){let n=x.map(C_);t=an(n,L,w_,{limit:7,threshold:.4}),e[93]=L,e[94]=x,e[95]=t}else t=e[95];Le=t}let Re=Le,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Ze,Qe,$e,et,tt;if(e[96]!==_e||e[97]!==U||e[98]!==j||e[99]!==T||e[100]!==Ee||e[101]!==n||e[102]!==f||e[103]!==h||e[104]!==M||e[105]!==Oe||e[106]!==Fe||e[107]!==Re||e[108]!==Ne||e[109]!==je||e[110]!==r||e[111]!==g||e[112]!==m||e[113]!==t){let i=Oe.map(T_),a=je.map(E_),o=Ne.map(D_),s=Ee?Fe.map(O_):[],c=Ee?Re.map(k_):[],l;bb5:{if(!Ee){l=[`commands`,`sessions`];break bb5}let e=A_,t=[{key:`commands`,score:e(Oe)},{key:`settings`,score:e(je)},{key:`sessions`,score:e(Ne)},{key:`files`,score:e(Fe)},{key:`projects`,score:e(Re)}];t.sort(j_),l=t.map(M_)}let u=l,d=e=>{U(),g(e.id,fn(e))},p=async e=>{if(!j)return;let t=await nc(T,e);if(!t.ok){J.error(Gs(t.reason));return}f(j,e),U()},_=(e,t)=>{U(),h({selectedProjectId:e,directoryOverride:t})},v=e=>pa(fa(e,m));He=ur,$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)(cr,{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)(lr,{children:x}),e[136]=x,e[137]=S),e[138]!==b||e[139]!==S?(tt=(0,$.jsxs)(ar,{className:`sr-only`,children:[b,S]}),e[138]=b,e[139]=S,e[140]=tt):tt=e[140],Ve=sr,Ye=`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=co,Ke=!1,qe=`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?(Je=(0,$.jsx)(so,{value:M,onValueChange:N,placeholder:C}),e[143]=M,e[144]=C,e[145]=Je):Je=e[145],ze=ja,Ue=`px-1.5 pb-2`;let w;e[146]===t?w=e[147]:(w=t(`commandPalette.empty.noResults`),e[146]=t,e[147]=w),e[148]===w?We=e[149]:(We=(0,$.jsx)(za,{className:`py-10 text-muted-foreground`,children:w}),e[148]=w,e[149]=We),Ge=u.map(e=>e===`commands`&&i.length>0?(0,$.jsx)(ka,{heading:t(`settings.page.commands.title`),className:Hg,children:i.map(e=>(0,$.jsx)(Ba,{value:e.id,onSelect:e.onSelect,className:Vg,children:(0,$.jsx)(Bg,{title:e.title,trailing:e.shortcutId?(0,$.jsx)(Oa,{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)(ka,{heading:t(`settings.view.home.title`),className:Hg,children:a.map(N_)},`settings`):e===`sessions`&&o.length>0?(0,$.jsx)(ka,{heading:t(`header.sessions.title`),className:Hg,children:o.map(e=>{let n=e.title||t(`commandPalette.session.untitled`),r=fn(e),i=_e(e.id,r);return(0,$.jsx)(Ba,{value:`session:${e.id}`,onSelect:()=>d(e),className:Vg,children:(0,$.jsx)(Bg,{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)(ka,{heading:t(`layout.mainTab.files`),className:Hg,children:s.map(e=>{let t=Qn(e.relativePath||e.name,{maxLength:80});return(0,$.jsx)(Ba,{value:`file:${e.path}`,onSelect:()=>{p(e.path)},className:Vg,children:(0,$.jsx)(Bg,{title:e.name,description:t===e.name?void 0:t})},`file:${e.path}`)})},`files`):e===`projects`&&c.length>0?(0,$.jsx)(ka,{heading:t(`sessions.sidebar.projectsTitle`),className:Hg,children:c.map(e=>{let t=e.displayName;return(0,$.jsx)(Ba,{value:`project:${e.id}`,onSelect:()=>_(e.id,e.path),className:Vg,children:(0,$.jsx)(Bg,{title:t})},`project:${e.id}`)})},`projects`):null),e[96]=_e,e[97]=U,e[98]=j,e[99]=T,e[100]=Ee,e[101]=n,e[102]=f,e[103]=h,e[104]=M,e[105]=Oe,e[106]=Fe,e[107]=Re,e[108]=Ne,e[109]=je,e[110]=r,e[111]=g,e[112]=m,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]=qe,e[123]=Je,e[124]=Ye,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],qe=e[122],Je=e[123],Ye=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]!==qe||e[162]!==Je||e[163]!==rt?(it=(0,$.jsxs)(Be,{shouldFilter:Ke,className:qe,children:[Je,rt]}),e[159]=Be,e[160]=Ke,e[161]=qe,e[162]=Je,e[163]=rt,e[164]=it):it=e[164];let at;e[165]!==Ve||e[166]!==Ye||e[167]!==Ze||e[168]!==Qe||e[169]!==it?(at=(0,$.jsx)(Ve,{className:Ye,containerClassName:Ze,showCloseButton:Qe,children:it}),e[165]=Ve,e[166]=Ye,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 Gg(e){return e.isCommandPaletteOpen}function Kg(e){return e.setCommandPaletteOpen}function qg(e){return e.setActiveMainTab}function Jg(e){return e.setSettingsDialogOpen}function Yg(e){return e.setSettingsPage}function Xg(e){return e.setSessionSwitcherOpen}function Zg(e){return e.toggleSidebar}function Qg(e){return e.toggleRightSidebar}function $g(e){return e.toggleBottomTerminal}function e_(e){return e.openContextOverview}function t_(e){return e.openContextFile}function n_(e){return e.shortcutOverrides}function r_(e){return e.openNewSessionDraft}function i_(e){return e.setCurrentSession}function a_(e){return e.activeSessions}function o_(e){return e.currentDirectory}function s_(e){return e.getActiveProject()}function c_(e){return e.projects}function l_(e){return e.searchFiles}function u_(e){return e.ensureStatus}function d_(){Aa()}function f_(){yn.requestDirectoryDialog()}function p_(e){console.warn(`[command-palette] failed to open draft mini chat window`,e)}function m_(e){return e.slug!==`home`}function h_(e){return(typeof e.time?.updated==`number`?e.time.updated:0)||(typeof e.time?.created==`number`?e.time.created:0)}function g_(e){return e.worktreeMetadata}function __(e){return{path:Ug(e.path),name:e.name,relativePath:e.relativePath}}function v_(e){return{item:e,score:0}}function y_(e){return e.searchText}function b_(e){return e.searchText}function x_(e){return{item:e,score:0}}function S_(e){return e.title||``}function C_(e){return{...e,displayName:e.label||e.path.split(`/`).pop()||e.path,searchText:`${e.label||``} ${e.path}`}}function w_(e){return e.searchText}function T_(e){return e.item}function E_(e){return e.item}function D_(e){return e.item}function O_(e){return e.item}function k_(e){return e.item}function A_(e){return e.length?e[0].score:1/0}function j_(e,t){return e.score-t.score}function M_(e){return e.key}function N_(e){return(0,$.jsx)(Ba,{value:e.id,onSelect:e.onSelect,className:Vg,children:(0,$.jsx)(Bg,{title:e.title})},e.id)}var P_=(e,t,n)=>aa(e)?ma(e,n).map(pa):t,F_=()=>{let e=(0,zc.c)(69),{t}=Xe(),n=p(I_),r=p(L_),i=p(R_),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=ra(),e[0]=a):a=e[0];let o=a,s;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=v(),e[1]=s):s=e[1];let c=s,l,u,d,f,m,h,g,_,y;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:``},{id:`toggle_context_plan`,descriptionKey:`helpDialog.item.togglePlanContextPanel`,icon:`time`,keys:``}]},{categoryKey:`helpDialog.section.interface`,items:[{id:`cycle_theme`,descriptionKey:`helpDialog.item.cycleTheme`,icon:`palette`,keys:``},{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=ur,_=n,y=r,l=sr,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 p;e[16]===t?p=e[17]:(p=t(`helpDialog.title`),e[16]=t,e[17]=p);let v;e[18]===p?v=e[19]:(v=(0,$.jsxs)(cr,{className:`flex items-center gap-2`,children:[s,p]}),e[18]=p,e[19]=v);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)(lr,{children:b}),e[22]=b,e[23]=x),e[24]!==v||e[25]!==x?(g=(0,$.jsxs)(ar,{children:[v,x]}),e[24]=v,e[25]=x,e[26]=g):g=e[26],m=`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?P_(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)(Ha,{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]=m,e[11]=h,e[12]=g,e[13]=_,e[14]=y}else l=e[6],u=e[7],d=e[8],f=e[9],m=e[10],h=e[11],g=e[12],_=e[13],y=e[14];let b;e[27]!==d||e[28]!==f?(b=(0,$.jsx)(`div`,{className:d,children:f}),e[27]=d,e[28]=f,e[29]=b):b=e[29];let x;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-muted-foreground mt-0.5`}),e[30]=x):x=e[30];let S;e[31]===t?S=e[32]:(S=t(`helpDialog.proTips.title`),e[31]=t,e[32]=S);let C;e[33]===S?C=e[34]:(C=(0,$.jsx)(`p`,{className:`font-medium mb-1`,children:S}),e[33]=S,e[34]=C);let w;e[35]!==i||e[36]!==t?(w=t(`helpDialog.proTips.commandPalette`,{shortcut:pa(ma(`open_command_palette`,i)[0]??``)}),e[35]=i,e[36]=t,e[37]=w):w=e[37];let T;e[38]===w?T=e[39]:(T=(0,$.jsxs)(`li`,{children:[`• `,w]}),e[38]=w,e[39]=T);let E;e[40]===t?E=e[41]:(E=t(`helpDialog.proTips.recentSessions`),e[40]=t,e[41]=E);let D;e[42]===E?D=e[43]:(D=(0,$.jsxs)(`li`,{children:[`• `,E]}),e[42]=E,e[43]=D);let O;e[44]===t?O=e[45]:(O=t(`helpDialog.proTips.themeCycling`),e[44]=t,e[45]=O);let k;e[46]===O?k=e[47]:(k=(0,$.jsxs)(`li`,{children:[`• `,O]}),e[46]=O,e[47]=k);let A;e[48]!==T||e[49]!==D||e[50]!==k?(A=(0,$.jsxs)(`ul`,{className:`space-y-0.5 typography-meta`,children:[T,D,k]}),e[48]=T,e[49]=D,e[50]=k,e[51]=A):A=e[51];let j;e[52]!==C||e[53]!==A?(j=(0,$.jsx)(`div`,{className:`mt-4 p-2 bg-muted/30 rounded-xl`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[x,(0,$.jsxs)(`div`,{className:`typography-meta text-muted-foreground`,children:[C,A]})]})}),e[52]=C,e[53]=A,e[54]=j):j=e[54];let M;e[55]!==j||e[56]!==m||e[57]!==b?(M=(0,$.jsxs)(`div`,{className:m,children:[b,j]}),e[55]=j,e[56]=m,e[57]=b,e[58]=M):M=e[58];let N;e[59]!==l||e[60]!==M||e[61]!==h||e[62]!==g?(N=(0,$.jsxs)(l,{className:h,children:[g,M]}),e[59]=l,e[60]=M,e[61]=h,e[62]=g,e[63]=N):N=e[63];let P;return e[64]!==u||e[65]!==N||e[66]!==_||e[67]!==y?(P=(0,$.jsx)(u,{open:_,onOpenChange:y,children:N}),e[64]=u,e[65]=N,e[66]=_,e[67]=y,e[68]=P):P=e[68],P};function I_(e){return e.isHelpDialogOpen}function L_(e){return e.setHelpDialogOpen}function R_(e){return e.shortcutOverrides}var z_=()=>{let e=(0,zc.c)(32),{t}=Xe(),n=p(B_),r=p(V_),i=p(H_),a;e[0]!==i||e[1]!==t?(a=async()=>{if(i){if((await $e(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)(cr,{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)(lr,{children:l}),e[9]=l,e[10]=u);let d;e[11]!==c||e[12]!==u?(d=(0,$.jsxs)(ar,{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 m;e[16]!==o||e[17]!==f?(m=(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]=m):m=e[18];let h;e[19]!==i||e[20]!==t?(h=i||t(`openCodeStatusDialog.empty.noData`),e[19]=i,e[20]=t,e[21]=h):h=e[21];let g;e[22]===h?g=e[23]:(g=(0,$.jsx)(`pre`,{className:`max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap`,children:h}),e[22]=h,e[23]=g);let _;e[24]!==d||e[25]!==m||e[26]!==g?(_=(0,$.jsxs)(sr,{className:`max-w-2xl`,children:[d,m,g]}),e[24]=d,e[25]=m,e[26]=g,e[27]=_):_=e[27];let v;return e[28]!==n||e[29]!==r||e[30]!==_?(v=(0,$.jsx)(ur,{open:n,onOpenChange:r,children:_}),e[28]=n,e[29]=r,e[30]=_,e[31]=v):v=e[31],v};function B_(e){return e.isOpenCodeStatusDialogOpen}function V_(e){return e.setOpenCodeStatusDialogOpen}function H_(e){return e.openCodeStatusText}var U_=(e,t)=>e?t.kind===e.kind?t.projectRoot.length===e.projectRoot.length?t.projectId.localeCompare(e.projectId)<0:t.projectRoot.length>e.projectRoot.length:t.kind===`project`:!0,W_=(e,t,n)=>{U_(e.get(t),n)&&e.set(t,n)},G_=e=>{let t=e;return _(t.directory)??_(t.project?.worktree)},K_=e=>{if(e===`/`||/^[A-Z]:$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:t===0?`/`:t===2&&/^[A-Z]:\//.test(e)?e.slice(0,2):e.slice(0,t)},q_=(e,t,n,r,i=[])=>{let a=new Map,o=new Map;for(let e of t){let t=_(e.normalizedPath);if(!t)continue;let n=o.get(t);(!n||e.id.localeCompare(n.id)<0)&&o.set(t,e),W_(a,t,{projectId:e.id,projectRoot:t,scopeDirectory:t,kind:`project`})}if(!r)for(let[e,t]of n){let n=_(e),r=n?o.get(n):void 0;if(!(!r||!n))for(let e of t){let t=_(e.path);t&&W_(a,t,{projectId:r.id,projectRoot:n,scopeDirectory:t,kind:`worktree`})}}let s=new Map,c=new Map,l=new Map,u=new Map,d=new Map,f=e=>{if(!e)return null;if(s.has(e))return s.get(e)??null;if(r){let t=a.get(e)??null;return s.set(e,t),t}let t=[],n=e,i=null;for(;n;){if(s.has(n)){i=s.get(n)??null;break}if(t.push(n),i=a.get(n)??null,i)break;n=K_(n)}for(let e of t)s.set(e,i);return i},p=(e,t,n)=>{for(let r of e){let e=f(G_(r));if(!e)continue;c.set(r.id,e);let i=t.get(e.projectId);if(i?i.push(r):t.set(e.projectId,[r]),!n)continue;let a=n.get(e.scopeDirectory);a?a.add(r.id):n.set(e.scopeDirectory,new Set([r.id]))}};return p(e,l,d),p(i,u),{bySessionId:c,sessionsByProject:l,archivedSessionsByProject:u,sessionsByScope:d,directoryResolutions:s.size}},J_=`__other__`;function Y_(e){return e.time?.updated??e.time?.archived??e.time?.created??0}function X_(){let{t:e}=Xe(),{isMobile:t,isTablet:n,hasTouchInput:r}=wa(),i=t||n||r,a=p(e=>e.isArchivedSessionsDialogOpen),o=p(e=>e.setArchivedSessionsDialogOpen),s=mn(e=>e.projects),c=vn(e=>e.archivedSessions),l=Tn(e=>e.setCurrentSession),u=p(e=>e.setSettingsDialogOpen),[d,f]=Q.useState(!1),[m,h]=Q.useState(null),[g,_]=Q.useState(null);Q.useEffect(()=>{if(!a){h(null),_(null);return}let t=!1;return f(!0),An().catch(()=>{t||J.error(e(`settings.openchamber.archivedSessions.toast.loadFailed`))}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a,e]);let y=Q.useMemo(()=>{let t=q_([],s.map(e=>({id:e.id,normalizedPath:e.path})),new Map,v(),c),n=new Map;for(let[e,r]of t.archivedSessionsByProject)n.set(e,[...r].sort((e,t)=>Y_(t)-Y_(e)));let r=new Set;for(let e of n.values())for(let t of e)r.add(t.id);let i=c.filter(e=>!r.has(e.id)).sort((e,t)=>Y_(t)-Y_(e));i.length>0&&n.set(J_,i);let a=[];for(let e of s){let t=n.get(e.id)??[];t.length!==0&&a.push({projectId:e.id,label:e.label||e.path,path:e.path,sessions:t})}let o=n.get(J_);return o&&o.length>0&&a.push({projectId:J_,label:e(`settings.openchamber.archivedSessions.otherProjects`),path:null,sessions:o}),a.sort((e,t)=>t.sessions.length-e.sessions.length||e.label.localeCompare(t.label)),a},[c,s,e]),b=c.length,x=m?y.find(e=>e.projectId===m)??null:null,S=Q.useCallback(async t=>{_(t.id);try{await jt(t.id)?J.success(e(`settings.openchamber.archivedSessions.toast.restored`)):J.error(e(`settings.openchamber.archivedSessions.toast.restoreFailed`))}finally{_(null)}},[e]),C=Q.useCallback(e=>{let t=fn(e);l(e.id,t),o(!1),u(!1)},[l,o,u]),w=x?x.label:e(`settings.openchamber.archivedSessions.dialog.title`),T=x?x.sessions.length===1?e(`settings.openchamber.archivedSessions.dialog.sessionCountSingle`,{count:x.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.sessionCountPlural`,{count:x.sessions.length}):e(`settings.openchamber.archivedSessions.dialog.description`),E=(0,$.jsxs)(`div`,{className:`space-y-3`,children:[x?(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`)]}):x?x.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:x.sessions.map(t=>{let n=fn(t),r=Y_(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?ci(r):null,r>0&&n?` · `:null,n?nr(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:()=>C(t),children:e(`settings.openchamber.archivedSessions.actions.preview`)}),(0,$.jsxs)(Z,{type:`button`,variant:`default`,size:`xs`,className:`!font-normal`,disabled:i,onClick:()=>void S(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)})}):y.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:y.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:nr(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))}),!x&&!d&&b>0?(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:e(b===1?`settings.openchamber.archivedSessions.summarySingle`:`settings.openchamber.archivedSessions.summaryPlural`,{count:b})}):null]});return i?(0,$.jsx)(uo,{open:a,title:w,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:w}),e]}),(0,$.jsx)(`p`,{className:`typography-micro text-muted-foreground`,children:T})]}),children:E}):(0,$.jsx)(ur,{open:a,onOpenChange:o,children:(0,$.jsxs)(sr,{className:`max-h-[85vh] max-w-2xl overflow-y-auto`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsx)(cr,{children:w}),(0,$.jsx)(lr,{children:T})]}),E]})})}var Z_=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=si(e.normalizedPath),n=r.archivedSessionsByProject.get(e.id)??[],i=s[t]??[],d=new Map(i.map(Q_));n.forEach(n=>{let r=Vr(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 Q_(e){return[e.name.toLowerCase(),e]}var $_=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:p,foldersMap:m}=e,h;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=Wr([...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],h=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]=h}else h=t[8];let g=h,v=g,y;if(t[17]!==p||t[18]!==f||t[19]!==m||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=p(n).includes(d),o=_(n.directory??null),s=(o?m[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]=p,t[18]=f,t[19]=m,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(ev),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]!==g||t[36]!==T||t[37]!==S||t[38]!==C||t[39]!==v?(E={projectSections:g,visibleProjectSections:v,groupSearchDataByGroup:b,searchableProjectSections:S,sectionsForRender:C,searchMatchCount:T},t[34]=b,t[35]=g,t[36]=T,t[37]=S,t[38]=C,t[39]=v,t[40]=E):E=t[40],E};function ev(e){return e.groups.length>0}var tv=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=_(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 v=g,y=Q.useRef(null),b,x;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]!==v||t[15]!==d||t[16]!==a||t[17]!==f?(b=()=>{if(!r||c||p.getState().isNewWorktreeDialogOpen||y.current===r)return;let e=n.find(e=>e.project.id===r);if(!e)return;y.current=r;let t=v.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 m=i.get(r),h=m&&t.has(m)?m:null,g=v.firstSessionByProject.get(r)?.id??null,_=h??g;if(!_||_===o)return;let b=t.get(_)?.directory??null;s(_,b,r)},x=[r,i,o,s,c,l,u,n,v,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]=v,t[15]=d,t[16]=a,t[17]=f,t[18]=b,t[19]=x):(b=t[18],x=t[19]),Q.useLayoutEffect(b,x);let S,C;t[20]!==r||t[21]!==o||t[22]!==v||t[23]!==a?(S=()=>{if(!r||!o)return;let e=v.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})},C=[r,o,v,a],t[20]=r,t[21]=o,t[22]=v,t[23]=a,t[24]=S,t[25]=C):(S=t[24],C=t[25]),Q.useEffect(S,C)},nv=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(rv)),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 rv(e){return[e.id,e]}var iv=e=>!!e.time?.archived,av=e=>{let t=e.parentID;return typeof t==`string`&&t.trim()?t:null},ov=(e,t={})=>{let n=t.pinnedSessionIds??new Set,r=t.omitPinnedSessions===!0,i=t.getWorktree??(()=>null),a=Wr(e).sort((e,t)=>Nr(e,t,n)),o=new Map(a.map(e=>[e.id,e])),s=new Map;a.forEach(e=>{let t=av(e);if(!t)return;let i=o.get(t);if(!i||iv(i)!==iv(e)||r&&n.has(t))return;let a=s.get(t)??[];a.push(e),s.set(t,a)}),s.forEach(e=>e.sort((e,t)=>Nr(e,t,n)));let c=e=>({session:e,children:(s.get(e.id)??[]).filter(e=>!(r&&n.has(e.id))).map(e=>c(e)),worktree:i(e)});return a.filter(e=>!(r&&n.has(e.id)||av(e))).map(e=>c(e))},sv=e=>{let{t}=Xe(),n=Q.useCallback(e=>[e.label,e.branch??``,e.description??``,e.directory??``].join(` `).toLowerCase(),[]),r=Q.useCallback(e=>{let n=_(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=_(r??null),c=new Map;i.forEach(e=>{if(e.path){let t=_(e.path)??e.path;c.set(t,e)}});let l=ov(n,{pinnedSessionIds:e.pinnedSessionIds,omitPinnedSessions:!0,getWorktree:t=>{let n=_(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=_(e.worktreeMetadata.get(t.id)?.path??null)??fn(t);return n?n!==s&&c.has(n)?n:n===s?s??`__project_root__`:d:d};l.forEach(e=>{let t=f(e.session);u.has(t)||u.set(t,[]),u.get(t)?.push(e)});let p=s??`__project_root__`,m=[{id:`root`,label:o&&a&&a!==`HEAD`?t(`sessions.sidebar.grouping.projectRootWithBranch`,{branch:a}):t(`sessions.sidebar.grouping.projectRoot`),branch:a??null,description:s?nr(s,e.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:s,folderScopeKey:s,sessions:u.get(p)??[]}],h=new Map;i.forEach(e=>{let t=_(e.path)??e.path,n=u.get(t)??[],r=n.length>0,i=n.reduce((e,t)=>{let n=xt(t.session);return Number.isFinite(n)?Math.max(e,n):e},0);h.set(t,{hasActiveSession:r,lastUpdatedAt:i})});let g=[...i].sort((e,t)=>{let n=_(e.path)??e.path,r=_(t.path)??t.path,i=h.get(n)??{hasActiveSession:!1,lastUpdatedAt:0},a=h.get(r)??{hasActiveSession:!1,lastUpdatedAt:0};if(i.hasActiveSession!==a.hasActiveSession)return i.hasActiveSession?-1:1;if(i.hasActiveSession&&a.hasActiveSession)return a.lastUpdatedAt-i.lastUpdatedAt;let o=(e.label||e.branch||e.name||e.path||``).toLowerCase(),s=(t.label||t.branch||t.name||t.path||``).toLowerCase();return o.localeCompare(s)});(e.isVSCode?[]:g).forEach(t=>{let n=_(t.path)??t.path,r=e.gitBranches.get(n)?.trim()||null,i=t.branch?.trim()||null,a=r&&i&&t.label&&Fr(t.label)===Fr(i)?r:t.label||t.name||er(n,e.homeDirectory)||n;m.push({id:`worktree:${n}`,label:a,branch:r||i,description:nr(n,e.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:t,directory:n,folderScopeKey:n,sessions:u.get(n)??[]})});let v=u.get(d)??[];return m.push({id:`archived`,label:t(`sessions.sidebar.grouping.archived`),branch:null,description:t(`sessions.sidebar.grouping.archivedDescription`),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!e.isVSCode&&s?si(s):null,sessions:v}),m},[e.homeDirectory,e.worktreeMetadata,e.pinnedSessionIds,e.gitBranches,e.isVSCode,t])}},cv=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)},lv=e=>{let t=(0,zc.c)(42),{t:n}=Xe(),[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)=>{$e(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=dv,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(fv);if(o.length===0){if(a){dc({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)?Js({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){dc({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&&Js({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(pv);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 uv(e){return!e.time?.archived}function dv(e,t){return t?e:e.filter(uv)}function fv(e){return e.id}function pv(e){return e.id}var mv=[`project:active:`,`project:archived:`,`pinned:active:`,`pinned:archived:`],hv=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}=mn.getState(),r=n.map(t=>({...t,sidebarCollapsed:e.has(t.id)}));W({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&&mv.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}},gv=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},_v=e=>{let{normalizedProjects:t,activeProjectId:n,gitRepoStatus:r,setProjectRepoStatus:i,setProjectRootBranches:a,enabled:o=!0}=e,{git:s}=fo(),c=Wo(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 gv(i,2,async e=>{let t=r.get(e.normalizedPath)?.branch?.trim()??``,n=`${e.normalizedPath}\0${t}`,i=await Fi(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])},vv=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},yv=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=Qt.getState().foldersMap;new Set([...Object.keys(e),...a.map(bv)]).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 bv(e){return si(e.normalizedPath)}var xv=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(Sv);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 Sv(e){return e.size===0?e:new Set}var Cv=9e4,wv=15e3,Tv=3e5,Ev=[2e3,5e3],Dv=6e4,Ov=12e4,kv=3e5,Av=4,jv=432e5,Mv=`openchamber.github-pr-status`,Nv=e=>e===`closed`||e===`merged`,Pv=e=>{let t=e?.checks;return t?t.state===`pending`||t.pending>0:!1},Fv=(e,t,n)=>`${e}::${t}`,Iv=new Map,Lv=new Map,Rv=new Set,zv=new Map,Bv=2,Vv=0,Hv=[],Uv=()=>Vv<Bv?(Vv+=1,Promise.resolve()):new Promise(e=>{Hv.push(e)}),Wv=()=>{let e=Hv.shift();if(e){e();return}Vv=Math.max(0,Vv-1)},Gv=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Kv=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,qv=e=>{let t=Kv(e);return!t?.directory||!t.branch?null:`${t.directory}::${t.branch}`},Jv=(e,t)=>Object.entries(e).filter(([,e])=>qv(e)===t).map(([e])=>e),Yv=(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}}},Xv=e=>!e?.params?.canShow||!e.params.github?.prStatus?null:{...e.params,remoteName:e.params.remoteName??e.resolvedRemoteName??e.identity?.remoteName??null},Zv=(e,t,n)=>{let r=Jv(e,t),i=r.map(t=>Xv(e[t])).filter(e=>!!e);if(i.length===0)return null;let a=Xv(e[n]);if(a&&qv(e[n])===t)return a;let o=r.map(t=>e[t]).find(e=>!!(e?.resolvedRemoteName&&Xv(e)));return o?Xv(o):i.find(e=>!!e.remoteName)||(i[0]??null)},Qv=e=>({status:e.status,isInitialStatusResolved:e.isInitialStatusResolved,lastRefreshAt:e.lastRefreshAt,lastDiscoveryPollAt:e.lastDiscoveryPollAt,identity:Kv(e),resolvedRemoteName:e.resolvedRemoteName??e.status?.resolvedRemoteName??null}),$v=e=>({...Gv(),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}),ey=fe()(pe((e,t)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:t=>{e(e=>e.entries[t]?e:{entries:{...e.entries,[t]:Gv()}})},setParams:(t,n)=>{e(e=>{let r=e.entries[t]??Gv();return{entries:{...e.entries,[t]:Yv(r,n)}}})},startWatching:n=>{if(e(e=>{let t=e.entries[n]??Gv();return{entries:{...e.entries,[n]:{...t,watchers:t.watchers+1}}}}),Iv.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=Lv.get(n)??[];i.push(r),Lv.set(n,i)};t().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),Ev.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<Tv)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}Nv(r.status?.pr?.state)||Date.now()-r.lastRefreshAt<(Pv(r.status)?Dv:r.status?.checks&&r.status.checks.state!==`pending`?kv:Ov)||t().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})}},wv);Iv.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=Iv.get(n);typeof i==`number`&&window.clearInterval(i),Iv.delete(n);let a=Lv.get(n);a&&a.length>0&&a.forEach(e=>{window.clearTimeout(e)}),Lv.delete(n)},refresh:async(n,r)=>{let i=t(),a=i.entries[n],o=qv(a);if(!a||!o)return;let s=Jv(i.entries,o),c=s.some(e=>!!i.entries[e]?.status?.pr);if(r?.onlyExistingPr&&!c)return;let l=zv.get(o)??0;if(!r?.force&&Date.now()-l<Cv||Rv.has(o))return;let u=Zv(i.entries,o,n);if(u){if(Rv.add(o),zv.set(o,Date.now()),e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,lastRefreshAt:Date.now(),isLoading:!r?.silent||n.isLoading,error:null})}),{entries:t}}),u.githubAuthChecked&&u.githubConnected===!1){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:{connected:!1},error:null,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),Rv.delete(o);return}if(!u.github?.prStatus){e(e=>{let t={...e.entries};return s.forEach(e=>{let n=t[e];n&&(t[e]={...n,status:null,error:`GitHub runtime API unavailable`,isLoading:r?.silent?n.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||n.isInitialStatusResolved})}),{entries:t}}),Rv.delete(o);return}try{e(e=>({...e,activeRequestCount:e.activeRequestCount+1,totalRequestCount:e.totalRequestCount+1})),await Uv();let t;try{t=await u.github.prStatus(u.directory,u.branch,u.remoteName??void 0,{force:r?.force})}finally{Wv()}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=Kv(i)??{directory:u.directory,branch:u.branch,remoteName:u.remoteName??null};n[e]={...i,status:s,error:null,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved,resolvedRemoteName:c,identity:{...l,remoteName:c??l.remoteName??null}}}),{entries:n}})}catch(t){let n=t instanceof Error?t.message:String(t);e(e=>{let t={...e.entries};return s.forEach(e=>{let i=t[e];i&&(t[e]={...i,error:n||`Failed to load PR status`,isLoading:r?.silent?i.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved!==!1||i.isInitialStatusResolved})}),{entries:t}})}finally{Rv.delete(o),e(e=>({...e,activeRequestCount:Math.max(0,e.activeRequestCount-1)}))}}},refreshTargets:async(e,n)=>{await gv(Array.from(new Set(e.map(e=>{let t=e.directory.trim(),n=e.branch.trim();return!t||!n?null:Fv(t,n,e.remoteName??null)}).filter(e=>!!e))),Av,e=>t().refresh(e,n))},updateStatus:(t,n)=>{e(e=>{let r=e.entries[t]??Gv();return{entries:{...e.entries,[t]:{...r,status:n(r.status)}}}})}}),{name:Mv,storage:g(),partialize:e=>({entries:Object.fromEntries(Object.entries(e.entries).filter(([,e])=>{let t=Kv(e);if(!t?.directory||!t.branch)return!1;let n=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return n===0||Date.now()-n<jv}).map(([e,t])=>[e,Qv(t)]))}),merge:(e,t)=>{let n=e?.entries??{};return{...t,entries:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,$v(t)]))}}})),ty=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`},ny=e=>{let t=ty(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}},ry=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??``}`,iy=new Map,ay=new Map,oy=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=ny(e);if(!a)continue;let o=ry(a);n.set(i,o),r.set(i,a)}if(n.size===iy.size){let e=!0;for(let[t,r]of n)if(iy.get(t)!==r){e=!1;break}if(e)return ay}return iy=n,ay=r,r},t[0]=e,t[1]=n),ey(n)},sy=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)(Os,{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)(sr,{className:`w-full max-w-2xl gap-0 overflow-hidden p-0`,children:(0,$.jsx)(xi,{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)(ur,{open:n,onOpenChange:r,children:s}),t[6]=r,t[7]=n,t[8]=s,t[9]=c):c=t[9],c},cy=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}=Xe(),[L,R]=Q.useState(!1),[z,B]=Q.useState(``),V=Q.useRef(null),H=k||L,U=k?A:z,ee;t[0]===n.name?ee=t[1]:(ee=()=>{B(n.name),R(!0)},t[0]=n.name,t[1]=ee);let te=ee,W;t[2]!==U||t[3]!==n.name||t[4]!==k||t[5]!==s||t[6]!==v?(W=()=>{let e=U.trim();e&&e!==n.name&&s(e),k&&v&&v(),R(!1),B(``)},t[2]=U,t[3]=n.name,t[4]=k,t[5]=s,t[6]=v,t[7]=W):W=t[7];let ne=W,G;t[8]!==k||t[9]!==y?(G=()=>{k&&y&&y(),R(!1),B(``)},t[8]=k,t[9]=y,t[10]=G):G=t[10];let re=G,K;t[11]!==k||t[12]!==_?(K=e=>{if(k&&_){_(e);return}B(e)},t[11]=k,t[12]=_,t[13]=K):K=t[13];let ie=K,ae,oe;t[14]===k?(ae=t[15],oe=t[16]):(ae=()=>{if(!k)return;let e=()=>{let e=V.current;e&&(e.focus(),e.select())},t=requestAnimationFrame(e),n=window.setTimeout(e,0);return()=>{cancelAnimationFrame(t),window.clearTimeout(n)}},oe=[k],t[14]=k,t[15]=ae,t[16]=oe),Q.useEffect(ae,oe);let se;t[17]===M?se=t[18]:(se=Hr(M),t[17]=M,t[18]=se);let ce=se,le;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(le=Y(`oc-folder`),t[19]=le):le=t[19];let ue=j&&`bg-primary/10 ring-1 ring-inset ring-primary/30`,de;t[20]===ue?de=t[21]:(de=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`,Pr,ue),t[20]=ue,t[21]=de);let fe;t[22]===ce?fe=t[23]:(fe={paddingLeft:ce},t[22]=ce,t[23]=fe);let pe=H?void 0:o,me=H?void 0:`button`,he=H?void 0:0,ge;t[24]!==o||t[25]!==H?(ge=H?void 0:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},t[24]=o,t[25]=H,t[26]=ge):ge=t[26];let _e;t[27]!==n.name||t[28]!==a||t[29]!==I?(_e=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]=_e):_e=t[30];let ve=P?O?`pr-7`:`group-hover/folder:pr-7 group-focus-within/folder:pr-7`:``,ye;t[31]===ve?ye=t[32]:(ye=Y(`min-w-0 flex items-center gap-1.5 flex-1 transition-[padding]`,ve),t[31]=ve,t[32]=ye);let be=j?`text-primary`:`text-muted-foreground`,xe;t[33]===be?xe=t[34]:(xe=Y(`h-4 w-4 flex-shrink-0`,be),t[33]=be,t[34]=xe);let Se;t[35]===xe?Se=t[36]:(Se=(0,$.jsx)(X,{name:`folder-open`,className:xe}),t[35]=xe,t[36]=Se);let Ce;t[37]!==U||t[38]!==n.name||t[39]!==re||t[40]!==ie||t[41]!==ne||t[42]!==a||t[43]!==j||t[44]!==H||t[45]!==r||t[46]!==I?(Ce=H?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-1 items-center gap-1`,onPointerDown:ly,onMouseDown:uy,onSubmit:e=>{e.preventDefault(),ne()},children:[(0,$.jsx)(`input`,{ref:V,value:U,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:I(`sessions.sidebar.folderItem.namePlaceholder`),onClick:dy,onPointerDown:fy,onMouseDown:py,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),re();return}(e.key===` `||e.key===`Enter`)&&e.stopPropagation()}}),(0,$.jsx)(`button`,{type:`submit`,className:`shrink-0 text-muted-foreground hover:text-foreground`,onClick:my,onPointerDown:hy,onMouseDown:gy,children:(0,$.jsx)(X,{name:`check`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re()},onPointerDown:_y,onMouseDown:vy,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]=U,t[38]=n.name,t[39]=re,t[40]=ie,t[41]=ne,t[42]=a,t[43]=j,t[44]=H,t[45]=r,t[46]=I,t[47]=Ce):Ce=t[47];let we;t[48]!==ye||t[49]!==Se||t[50]!==Ce?(we=(0,$.jsxs)(`div`,{className:ye,children:[Se,Ce]}),t[48]=ye,t[49]=Se,t[50]=Ce,t[51]=we):we=t[51];let Te;t[52]!==O||t[53]!==P||t[54]!==M||t[55]!==n.name||t[56]!==te||t[57]!==N||t[58]!==c||t[59]!==S||t[60]!==C||t[61]!==H||t[62]!==I?(Te=!H&&(!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(),te()},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]=te,t[57]=N,t[58]=c,t[59]=S,t[60]=C,t[61]=H,t[62]=I,t[63]=Te):Te=t[63];let Ee;t[64]!==b||t[65]!==de||t[66]!==fe||t[67]!==pe||t[68]!==me||t[69]!==he||t[70]!==ge||t[71]!==_e||t[72]!==we||t[73]!==Te?(Ee=(0,$.jsxs)(`div`,{ref:b,className:de,style:fe,onClick:pe,role:me,tabIndex:he,onKeyDown:ge,"aria-label":_e,children:[we,Te]}),t[64]=b,t[65]=de,t[66]=fe,t[67]=pe,t[68]=me,t[69]=he,t[70]=ge,t[71]=_e,t[72]=we,t[73]=Te,t[74]=Ee):Ee=t[74];let De;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?(De=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:Hr(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]=De):De=t[86];let Oe;return t[87]!==Ee||t[88]!==De?(Oe=(0,$.jsxs)(`div`,{className:le,children:[Ee,De]}),t[87]=Ee,t[88]=De,t[89]=Oe):Oe=t[89],Oe});function ly(e){return e.stopPropagation()}function uy(e){return e.stopPropagation()}function dy(e){return e.stopPropagation()}function fy(e){return e.stopPropagation()}function py(e){return e.stopPropagation()}function my(e){return e.stopPropagation()}function hy(e){return e.stopPropagation()}function gy(e){return e.stopPropagation()}function _y(e){return e.stopPropagation()}function vy(e){return e.stopPropagation()}var yy=e=>Object.fromEntries(e.map(e=>[e.id,xt(e)])),by=(e,t,n)=>{let r=yy(e.map(e=>e.session));return xn(r,n)?new Map((t??[]).map((e,t)=>[e,t])):new Map},xy=(e,t,n,r)=>{let i=by(e,t,n);return(e,t)=>{let n=i.get(e.session.id),a=i.get(t.session.id);if(n!==void 0||a!==void 0){if(n===void 0)return 1;if(a===void 0)return-1;if(n!==a)return n-a}return Nr(e.session,t.session,r)}},Sy=({folders:e,visibleUngroupedNodes:t,collapsedFolderIds:n,hasSessionSearchQuery:r})=>{let i=new Map(e.map(e=>[e.folder.id,e])),a=new Map;e.forEach(({folder:e})=>{let t=e.parentId??null,n=a.get(t)??[];n.push(e.id),a.set(t,n)});let o=[],s=new Map,c=e=>{let t=i.get(e);t&&(!r&&n.has(e)||((a.get(e)??[]).forEach(c),t.nodes.forEach(t=>{o.push(t.session.id),s.set(t.session.id,e)})))};return(a.get(null)??[]).forEach(c),t.forEach(e=>{o.push(e.session.id),s.set(e.session.id,null)}),{sessionIds:o,folderIdBySessionId:s}},Cy=(e,t,n)=>n.get(e)===n.get(t),wy=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}=ko(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]:(_=Eo.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},Ty=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}=yo(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},Ey=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=To(vo(Co,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:/,``);Cy(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(Dy),t[9]=i,t[10]=S);let C;t[11]!==s||t[12]!==S?(C=(0,$.jsx)(jo,{items:S,strategy:Ao,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)(So,{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)(wo,{sensors:l,collisionDetection:xo,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 Dy(e){return`session-drag:${e}`}var Oy=3e4,ky=e=>{let t=e,n=t.metadata?.openchamber?.titleRefresh,r=xt(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/Oy)].join(`\0`)},Ay=(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)},jy=(e,t)=>{if(!t)return!1;if(e.session.id===t)return!0;for(let n of e.children)if(jy(n,t))return!0;return!1},My=e=>e.children.length===0?``:e.children.map(e=>e.children.length===0?e.session.id:`${e.session.id}:${My(e)}`).join(`|`),Ny=(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},Py=fe()(pe(e=>({displayMode:`minimal`,projectSortOrder:`manual`,setDisplayMode:t=>e({displayMode:t}),setProjectSortOrder:t=>e({projectSortOrder:t})}),{name:`session-display-mode`,storage:H(),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`&&l(e=>{t(e)&&Py.persist.rehydrate()});var Fy=e=>!!e.parentID,Iy=(e,t)=>_(fn(e.session))??_(t.directory??null),Ly=()=>3,Ry=(e,t,n)=>{let r=Math.min(e.length,Math.max(0,t)),i=e.slice(0,r);for(let t=r;t<e.length;t+=1){let r=e[t];r&&n.has(r.session.id)&&i.push(r)}return i},zy=({targets:e,collapsedProjectIds:t,collapsedGroupKeys:n,collapsedFolderIds:r,visibleSessionCountByGroup:i,defaultVisibleSessionCount:a,hasSessionSearchQuery:o,alwaysVisibleSessionIds:s})=>e.filter(e=>{if(!e.projectId||t.has(e.projectId))return!1;if(o)return!0;if(e.groupKey&&n.has(e.groupKey)||e.folderAncestorIds?.some(e=>r.has(e)))return!1;if(e.groupKey&&e.visibleIndex!==void 0){let t=Math.max(a,i.get(e.groupKey)??a);if(e.visibleIndex>=t&&!s?.has(e.sessionId))return!1}return!0}),By=(e,t,n)=>{if(!t||n==null||!Number.isInteger(n)||n<0)return null;if(e[n]?.session.id===t)return n;let r=e.findIndex(e=>e.session.id===t);return r>=0?r:null},Vy=({sections:e,foldersMap:t,getOrderedGroups:n,pinnedSessionIds:r,sessionOrderByScope:i,sessionOrderActivityByScope:a})=>{let o=[];return e.forEach(e=>{let s=n(e.project.id,e.groups),c=s.find(e=>e.isMain)??null;(c?[c,...s.filter(e=>e.id!==c.id)]:s).forEach(n=>{if(n.isArchivedBucket)return;let s=`${e.project.id}:${n.id}`,c=n.folderScopeKey??_(n.directory??null),l=xy(n.sessions,c?i[c]:void 0,c?a[c]:void 0,r),u=[...n.sessions].filter(e=>!e.session.time?.archived&&!Fy(e.session)).sort(l),d=new Map(u.map(e=>[e.session.id,e])),f=c?t[c]??[]:[],p=new Map;f.forEach(e=>{let t=e.parentId??null,n=p.get(t)??[];n.push(e),p.set(t,n)});let m=new Set(f.flatMap(e=>e.sessionIds)),h=(t,r,i)=>{o.push({scope:`project`,sessionId:t.session.id,projectId:e.project.id,directory:Iy(t,n),groupKey:s,folderAncestorIds:r,visibleIndex:i})},g=(e,t)=>{let n=f.find(t=>t.id===e);if(!n)return;let r=[...t,n.id];(p.get(n.id)??[]).forEach(e=>{g(e.id,r)}),n.sessionIds.map(e=>d.get(e)).filter(e=>!!e).sort(l).forEach(e=>h(e,r))};(p.get(null)??[]).forEach(e=>g(e.id,[])),u.filter(e=>!m.has(e.session.id)).forEach((e,t)=>h(e,void 0,t))})}),o},Hy=50,Uy=30,Wy=28,Gy=(e,t)=>t?e.sessions.some(e=>jy(e,t)):!1,Ky=(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)},qy=(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)},Jy=(e,t,n)=>{let r=i=>{let a=i.session.id,o=e.folderScopeKey??_(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)},Yy=(e,t,n)=>{let r=e.folderScopeKey??_(e.directory??null);return!!(r&&t[r]!==n[r])},Xy=(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)},Zy=(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&&ky(a)!==ky(o)||e.children.some(r)};return e.sessions.some(r)},Qy=e=>{if(e.projectId)return e.projectRepoStatus.has(e.projectId)?e.projectRepoStatus.get(e.projectId):void 0},$y=e=>{let t=new WeakMap,n=e=>{t.set(e,My(e));for(let t of e.children)n(t)};return e.forEach(n),t},eb=e=>{let t=[],n=e=>{e.forEach(e=>{t.push(e.session),e.children.length>0&&n(e.children)})};return n(e),t},tb=(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&&Qy(e)!==Qy(t)||e.pinnedSessionIds!==t.pinnedSessionIds&&Ky(t.group,e.pinnedSessionIds,t.pinnedSessionIds)||e.expandedParents!==t.expandedParents&&Xy(t.group,e.expandedParents,t.expandedParents)||e.sessionOrderByScope!==t.sessionOrderByScope&&Jy(t.group,e.sessionOrderByScope,t.sessionOrderByScope)||e.sessionOrderActivityByScope!==t.sessionOrderActivityByScope&&Yy(t.group,e.sessionOrderActivityByScope,t.sessionOrderActivityByScope)||e.currentSessionId!==t.currentSessionId&&(Gy(e.group,e.currentSessionId)||Gy(t.group,t.currentSessionId))||e.editingId!==t.editingId&&(Gy(e.group,e.editingId)||Gy(t.group,t.editingId))||e.editTitle!==t.editTitle&&(Gy(e.group,e.editingId)||Gy(t.group,t.editingId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Ny(e.group.sessions,e.openSidebarMenuKey,`project`,!!e.group.isArchivedBucket),r=Ny(t.group.sessions,t.openSidebarMenuKey,`project`,!!t.group.isArchivedBucket);if(n||r)return!1}if(e.liveSessionById!==t.liveSessionById&&Zy(t.group,e.liveSessionById,t.liveSessionById)||e.runningSessionIds!==t.runningSessionIds&&qy(t.group,e.runningSessionIds,t.runningSessionIds))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 nb(e){let{t}=Xe(),{group:n,groupKey:r,isArchivedLoading:i=!1,projectId:a,hideGroupLabel:o,hasSessionSearchQuery:s,normalizedSessionSearchQuery:c,groupSearchDataByGroup:l,visibleSessionCount:u,collapsedGroups:d,collapsedFolderIds:f,toggleFolderCollapse:p,renameFolder:m,deleteFolder:h,showDeletionDialog:g,setDeleteFolderConfirm: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:L,pinnedSessionIds:R,expandedParents:z,sessionOrderByScope:B,sessionOrderActivityByScope:V,onReorderSessions:H,currentSessionId:U,shortcutTargetSessionId:ee=null,shortcutTargetVisibleIndex:te=null,editingId:W,openSidebarMenuKey:ne,prVisualStateByDirectoryBranch:G,onToggleCollapsedGroup:re,dragHandleProps:K,compactBodyPadding:ie=!1,scrollContainerRef:ae,runningSessionIds:oe}=e,se=n.folderScopeKey??_(n.directory??null),ce=Q.useMemo(()=>xy(n.sessions,se?B[se]:void 0,se?V[se]:void 0,R),[se,n.sessions,R,V,B]),le=s?l.get(n):null,ue=Py(e=>e.displayMode),de=Qt(e=>e.foldersMap),fe=ue===`minimal`&&!v(),pe=n.isArchivedBucket?null:_(n.directory??null),me=vn(e=>pe?e.activePaginationByDirectory.get(pe):void 0),he=!s&&d.has(r),ge=Ly(),_e=Math.max(ge,u??ge),ve=s?le?.groupMatches===!0:!1,ye=s,be=Q.useMemo(()=>[...ye?le?.filteredNodes??[]:n.sessions].sort(ce),[ce,n.sessions,le?.filteredNodes,ye]),xe=Q.useMemo(()=>se?de[se]??[]:[],[se,de]),Se=Q.useMemo(()=>{let e=new Map,t=n=>{n.forEach(n=>{e.set(n.session.id,n),n.children.length>0&&t(n.children)})};return t(be),e},[be]),Ce=Q.useMemo(()=>xe.map(e=>({folder:e,nodes:e.sessionIds.map(e=>Se.get(e)).filter(e=>!!e).sort(ce)})),[xe,Se,ce]),we=Q.useMemo(()=>{let e=new Map(Ce.map(e=>[e.folder.id,e])),t=new Map;for(let{folder:e}of Ce){if(!e.parentId)continue;let n=t.get(e.parentId);n?n.push(e.id):t.set(e.parentId,[e.id])}let r=new Map,i=a=>{let o=r.get(a);if(o!==void 0)return o;let l=e.get(a);if(!l)return r.set(a,!1),!1;let u=t.get(a)??[];if(n.isArchivedBucket&&l.nodes.length===0){let e=u.some(e=>i(e));return r.set(a,e),e}if(!s||l.folder.name.toLowerCase().includes(c)||l.nodes.length>0)return r.set(a,!0),!0;let d=u.some(e=>i(e));return r.set(a,d),d};return Ce.filter(({folder:e})=>i(e.id))},[Ce,n.isArchivedBucket,s,c]),Te=Q.useMemo(()=>new Set(we.flatMap(e=>e.folder.sessionIds)),[we]),Ee=Q.useMemo(()=>be.filter(e=>!Te.has(e.session.id)),[be,Te]),De=Q.useMemo(()=>we.filter(({folder:e})=>!e.parentId),[we]),Oe=`project`,ke=Q.useMemo(()=>{let e=new Set;return Ay(be,U,e),we.forEach(({nodes:t})=>{Ay(t,U,e)}),e},[be,we,U]),Ae=Q.useMemo(()=>{let e=new Set;return Ay(be,W,e),we.forEach(({nodes:t})=>{Ay(t,W,e)}),e},[be,we,W]),je=Q.useMemo(()=>{if(!ne)return null;let e=Ny(be,ne,Oe,!!n.isArchivedBucket);if(e)return e;for(let{nodes:e}of we){let t=Ny(e,ne,Oe,!!n.isArchivedBucket);if(t)return t}return null},[ne,be,we,n.isArchivedBucket]),Me=Q.useMemo(()=>$y(be),[be]),Ne=Q.useMemo(()=>{let e=new WeakMap;return we.forEach(({nodes:t})=>{t.forEach(t=>e.set(t,My(t)))}),e},[we]),q=Q.useMemo(()=>e=>Me.get(e)??Ne.get(e)??``,[Me,Ne]),Pe=Q.useMemo(()=>e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e)}),[ke,Ae,je,q]),Fe=Ee.length,Ie=n.isArchivedBucket||s?Ee:Ee.slice(0,_e),Le=n.isArchivedBucket||s?Ee:Ry(Ee,_e,oe),Re=Fe-Le.length,ze=Q.useMemo(()=>Sy({folders:we,visibleUngroupedNodes:Le,collapsedFolderIds:f,hasSessionSearchQuery:s}),[we,f,s,Le]),Be=me?.hasMore===!0,Ve=me?.loadingMore===!0,He=u===void 0||u<=ge,Ue=!n.isArchivedBucket&&!s&&Fe>ge&&!He,We=n.isArchivedBucket===!0&&!s&&Le.length>=Hy,Ke=n.isArchivedBucket!==!0&&!s&&Le.length>=Uy,Je=We||Ke,Ye=n.isArchivedBucket?`archived`:`active`,Ze=Je&&Le.some(e=>{if(e.children.length===0)return!1;let t=`project:${Ye}:${e.session.id}`;return z.has(t)}),Qe=Q.useRef(null),[$e,et]=Q.useState(null),[,tt]=Q.useState(0);qe(Je?Qe:null,()=>{tt(e=>e+1)}),Q.useLayoutEffect(()=>{if(!Je){et(e=>e===null?e:null);return}let e=Qe.current;if(!e){et(e=>e===null?e:null);return}let t=null,n=ae?.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=ae?.current??null,it=Je&&$e!==null&&$e.container===nt&&$e.scrollElement.contains(nt)&&(rt===null||$e.scrollElement===rt),at=$e?.scrollElement??null,ot=$e?.scrollMargin??0,st=es({count:Le.length,enabled:it,getScrollElement:()=>at,initialOffset:()=>at?.scrollTop??0,estimateSize:()=>Wy,overscan:Ze?20:8,scrollMargin:ot,getItemKey:e=>Le[e]?.session.id??e}),ct=By(Le,ee,te);Q.useLayoutEffect(()=>{!it||!ee||ct===null||st.getVirtualItems().some(e=>e.index===ct)||st.scrollToIndex(ct,{align:`auto`,behavior:`auto`})},[ot,st,ee,ct,it]);let lt=Q.useMemo(()=>eb(be),[be]),ut=Q.useMemo(()=>{if(!n.isArchivedBucket)return new Map;let e=new Map,t=new Map;for(let{folder:e}of we){if(!e.parentId)continue;let n=t.get(e.parentId)??[];n.push(e.id),t.set(e.parentId,n)}let r=(e,n)=>{if(n.has(e))return[];n.add(e);let i=we.find(({folder:t})=>t.id===e),a=i?eb(i.nodes):[],o=t.get(e)??[];for(let e of o)a.push(...r(e,n));return a};for(let{folder:t}of we)e.set(t.id,r(t.id,new Set));return e},[we,n.isArchivedBucket]),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=Ge(e=>{e.preventDefault(),e.stopPropagation();let t=_(n.directory??null),r=n.branch?.trim()??null,i=t&&r?G.get(`${t}::${r}`)?.url??null:null;i&&Mo(i)});if(s&&!ve&&De.length===0&&Ee.length===0)return null;let pt=a&&x.has(a)?!!x.get(a):S,mt=_(n.directory??null),ht=n.branch?.trim()??null,gt=mt&&ht?G.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,Ct=gt?.base??null,wt=gt?.head??null,Tt=(()=>{if(!gt)return n.branch&&Ur(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}})(),Et=(e,t,r)=>{let i=we.filter(({folder:t})=>t.parentId===e.id),o=i.length>0?(0,$.jsx)($.Fragment,{children:i.map(({folder:e,nodes:t})=>Et(e,t,r+1))}):void 0,c=ut.get(e.id)??[];return(0,$.jsx)(Ty,{folderId:e.id,children:(i,l)=>(0,$.jsx)(cy,{folder:e,sessions:t,subFolderItems:o,isCollapsed:!s&&f.has(e.id),onToggle:()=>p(e.id),onRename:t=>{se&&m(se,e.id,t)},onDelete:()=>{if(n.isArchivedBucket){yn.requestDelete({sessions:c,mode:`session`});return}if(!se)return;if(!g){h(se,e.id);return}let r=we.filter(({folder:t})=>t.parentId===e.id).length,i=t.length;y({scopeKey:se,folderId:e.id,folderName:e.name,subFolderCount:r,sessionCount:i})},renderSessionNode:b,getRenderExtras:q?e=>({subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe}):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&&se&&m(se,e.id,t),L(null),I(``)},onRenameCancel:()=>{L(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?()=>{se&&N(se,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)},Dt=+!o,Ot=o?1:Dt,kt=()=>De.map(({folder:e,nodes:t})=>Et(e,t,Ot)),At=!!(!n.isMain&&n.worktree),jt=E?At?`pr-14`:`pr-7`:fe?At?`pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-2`:At?`pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14`:`pr-5`,Mt=(0,$.jsxs)(Ey,{scopeKey:se,sessionIds:ze.sessionIds,folderIdBySessionId:ze.folderIdBySessionId,onSessionDroppedOnFolder:(e,t)=>{se&&M(se,t,e)},onSessionsReordered:(e,t)=>{H(ze.sessionIds,e,t,yy(n.sessions.map(e=>e.session)))},children:[kt(),Je?(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,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(t),childRenderExtrasFor:Pe})},t.session.id):null})}):Le.map(e=>b(e,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe}))}):Le.map(e=>b(e,Ot,n.directory,a,n.isArchivedBucket===!0,dt,`project`,{subtreeContainsActive:ke,subtreeContainsEditing:Ae,menuOpenSessionId:je,nodeStructureKey:q(e),childRenderExtrasFor:Pe})),Fe===0&&we.length===0?(0,$.jsx)(`div`,{className:_i,style:{paddingLeft:Hr(Ot)},children:i?t(`sessions.sidebar.project.loadingSessions`):n.isArchivedBucket?t(`sessions.sidebar.group.empty.noArchivedSessions`):t(`sessions.sidebar.group.empty.noSessionsInWorkspace`)}):null,Re>0||Be||Ue?(0,$.jsxs)(`div`,{className:Y(_i,`flex w-full items-center gap-3 text-muted-foreground/60`),style:{paddingLeft:Hr(Ot)},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,Ue?(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]}),Nt=o?ie?`pb-0`:`pb-0.5`:ie?`pb-1`:`pb-1.5`,Pt=Hr(Dt);return o?(0,$.jsx)(`div`,{className:`oc-group`,children:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Nt),children:Mt})}):(0,$.jsxs)(`div`,{className:`oc-group`,children:[(0,$.jsxs)(`div`,{"data-mobile-press-feedback":K?`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`,Pr),style:{paddingLeft:Pt},onClick:()=>re(r),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),re(r))},"aria-label":t(he?`sessions.sidebar.group.expandAria`:`sessions.sidebar.group.collapseAria`,{label:n.label}),"aria-expanded":!he,children:[(0,$.jsx)(`div`,{ref:K?.setActivatorNodeRef,className:Y(`min-w-0 flex flex-1 items-start gap-1.5 overflow-hidden transition-[padding] cursor-grab active:cursor-grabbing`,jt),...K?.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)(Ui,{children:[(0,$.jsx)(Bi,{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:he?(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)(Vi,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||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:he?(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:Rr(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:he?(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:Rr(n.label,c)})]}):Rr(n.label,c)}),vt&&Tt?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center gap-1.5 leading-tight`,!Tt.color&&`text-muted-foreground`),style:Tt.color?{color:Tt.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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{side:`top`,sideOffset:6,align:`start`,className:`max-w-sm`,children:(0,$.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[Ct||wt?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:Ct&&wt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:Ct}),(0,$.jsx)(X,{name:`arrow-left-long`,className:`mx-0.5 inline h-3 w-3 align-[-2px]`}),(0,$.jsx)(`span`,{children:wt})]}):(0,$.jsx)(`span`,{children:Ct??wt??``})}):null,St?(0,$.jsx)(`div`,{className:`text-muted-foreground truncate`,children:St}):null,xt||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:Tt.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)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),yn.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)(Vi,{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)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),yn.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)(Vi,{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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:t(`sessions.sidebar.project.actions.newDraftSession`)})})]})}):null]}),he?null:(0,$.jsx)(`div`,{className:Y(`oc-group-body`,Nt),children:Mt})]})}var rb=Q.memo(nb,tb);function ib(e){let t=(0,zc.c)(36),{t:n}=Xe(),{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 ab(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 ob(e){let t=(0,zc.c)(43),{items:n,renderSessionNode:r,currentSessionId:i,editingId:a,openSidebarMenuKey:o,headerAccessory:s,onVisibleSessionIdsChange:c}=e,{t:l}=Xe(),[u,d]=Q.useState(!1),f=ei(ub),p,m;t[0]!==u||t[1]!==n||t[2]!==c?(p=()=>{c?.(u?[]:n.map(lb))},m=[u,n,c],t[0]=u,t[1]=n,t[2]=c,t[3]=p,t[4]=m):(p=t[3],m=t[4]),Q.useLayoutEffect(p,m);let h,g;t[5]!==n||t[6]!==f?(h=()=>{f&&n.some(e=>e.node.session.id===f)&&d(!1)},g=[n,f],t[5]=n,t[6]=f,t[7]=h,t[8]=g):(h=t[7],g=t[8]),Q.useLayoutEffect(h,g);let _,v,y,b;if(t[9]!==i||t[10]!==a||t[11]!==n||t[12]!==o){let e=n.map(cb);y=new Set,Ay(e,i,y),b=new Set,Ay(e,a,b),_=Ny(e,o,`pinned`,!1),v=new WeakMap;let r=e=>{v.set(e,My(e)),e.children.forEach(r)};e.forEach(r),t[9]=i,t[10]=a,t[11]=n,t[12]=o,t[13]=_,t[14]=v,t[15]=y,t[16]=b}else _=t[13],v=t[14],y=t[15],b=t[16];let x;t[17]!==_||t[18]!==v||t[19]!==y||t[20]!==b?(x=e=>({subtreeContainsActive:y,subtreeContainsEditing:b,menuOpenSessionId:_,nodeStructureKey:v.get(e)??``,childRenderExtrasFor:x}),t[17]=_,t[18]=v,t[19]=y,t[20]=b,t[21]=x):x=t[21];let S;t[22]!==x||t[23]!==_||t[24]!==v||t[25]!==y||t[26]!==b?(S=e=>({subtreeContainsActive:y,subtreeContainsEditing:b,menuOpenSessionId:_,nodeStructureKey:v.get(e)??``,childRenderExtrasFor:x}),t[22]=x,t[23]=_,t[24]=v,t[25]=y,t[26]=b,t[27]=S):S=t[27];let C=S;if(n.length===0)return null;let w;t[28]===l?w=t[29]:(w=l(`directoryTree.section.pinned`),t[28]=l,t[29]=w);let T;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>d(sb),t[30]=T):T=t[30];let E=!u,D;t[31]!==s||t[32]!==w||t[33]!==E?(D=(0,$.jsx)(ab,{title:w,onToggle:T,expanded:E,accessory:s}),t[31]=s,t[32]=w,t[33]=E,t[34]=D):D=t[34];let O;t[35]!==u||t[36]!==C||t[37]!==n||t[38]!==r?(O=u?null:(0,$.jsx)(`div`,{className:`space-y-0.5`,children:n.map(e=>(0,$.jsx)(Q.Fragment,{children:r(e.node,0,e.groupDirectory,e.projectId,!1,e.secondaryMeta,`pinned`,C(e.node))},`${e.projectId??``}:${e.node.session.id}`))}),t[35]=u,t[36]=C,t[37]=n,t[38]=r,t[39]=O):O=t[39];let k;return t[40]!==O||t[41]!==D?(k=(0,$.jsx)(Hi,{delay:0,closeDelay:150,timeout:600,children:(0,$.jsxs)(`div`,{className:`pb-1`,children:[D,O]})}),t[40]=O,t[41]=D,t[42]=k):k=t[42],k}function sb(e){return!e}function cb(e){return e.node}function lb(e){return e.node.session.id}function ub(e){return e.focus?.scope===`pinned`?e.focus.sessionId:null}function db(e){let t=(0,zc.c)(41),{collapseAllProjects:n,expandAllProjects:r,buttonClassName:i,iconClassName:a}=e,{t:o}=Xe(),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)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{asChild:!0,children:(0,$.jsx)(Z,{variant:`ghost`,size:`xs`,className:s,"aria-label":c,onClick:fb,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)(Vi,{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)(Ui,{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)(la,{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)(la,{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)(ea,{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)(ta,{children:[m,C]}),t[38]=C,t[39]=m,t[40]=w):w=t[40],w}function fb(e){e.stopPropagation()}var pb=`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`,mb=`size-4 text-foreground/55 transition-colors group-hover:text-foreground group-focus-visible:text-foreground`;function hb(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}=Xe(),u;t[0]!==n||t[1]!==r||t[2]!==s||t[3]!==l?(u=s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:pb,onClick:n,"aria-label":l(`sessions.sidebar.footer.actions.settings`),children:(0,$.jsx)(X,{name:`settings-3`,className:mb})})}),(0,$.jsx)(Vi,{side:`top`,sideOffset:4,children:l(`sessions.sidebar.footer.actions.settings`)})]}),(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:pb,onClick:r,"aria-label":l(`sessions.sidebar.footer.actions.shortcuts`),children:(0,$.jsx)(X,{name:`question`,className:mb})})}),(0,$.jsx)(Vi,{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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{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 gb=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}=Xe(),I=A||!P,L;t[0]!==n||t[1]!==I?(L={id:n,disabled:I},t[0]=n,t[1]=I,t[2]=L):L=t[2];let{attributes:R,listeners:z,setNodeRef:B,transform:V,transition:H,isDragging:U}=ko(L),ee=Q.useRef(!1),te=`project:${n}`,W=D===te,[ne,G]=Q.useState(!1),re=o?ki[o]:null,K=s?Ni[s]:void 0,ie=re??`folder-open`,ae;t[3]===K?ae=t[4]:(ae=K?{color:K}:void 0,t[3]=K,t[4]=ae);let oe;t[5]!==ie||t[6]!==ae?(oe=(0,$.jsx)(X,{name:ie,className:`h-4 w-4`,style:ae}),t[5]=ie,t[6]=ae,t[7]=oe):oe=t[7];let se=oe,ce;t[8]!==te||t[9]!==O?(ce=e=>{e&&G(!1),O(e?te:null)},t[8]=te,t[9]=O,t[10]=ce):ce=t[10];let le=ce,ue;t[11]!==h||t[12]!==f||t[13]!==S||t[14]!==v||t[15]!==x||t[16]!==b||t[17]!==M||t[18]!==F?(ue=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]=ue):ue=t[19];let de=ue,fe=vb,pe=yb,me=bb,he;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(he=e=>{(e.button===2||e.button===0&&e.ctrlKey)&&(ee.current=!0)},t[20]=he):he=t[20];let ge=he,_e;t[21]===_?_e=t[22]:(_e=()=>{if(ee.current){ee.current=!1;return}_()},t[21]=_,t[22]=_e);let ve=_e,ye;t[23]===V?ye=t[24]:(ye=Eo.Transform.toString(V),t[23]=V,t[24]=ye);let be;t[25]!==ye||t[26]!==H?(be={transform:ye,transition:H},t[25]=ye,t[26]=H,t[27]=be):be=t[27];let xe=U&&`opacity-30`,Se;t[28]===xe?Se=t[29]:(Se=Y(`relative`,xe),t[28]=xe,t[29]=Se);let Ce;t[30]!==g||t[31]!==R||t[32]!==le||t[33]!==ve||t[34]!==h||t[35]!==N||t[36]!==n||t[37]!==u||t[38]!==l||t[39]!==ne||t[40]!==p||t[41]!==W||t[42]!==f||t[43]!==j||t[44]!==m||t[45]!==z||t[46]!==v||t[47]!==y||t[48]!==a||t[49]!==se||t[50]!==c||t[51]!==i||t[52]!==de||t[53]!==P||t[54]!==C||t[55]!==M||t[56]!==F?(Ce=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)(_c,{open:ne,onOpenChange:G,children:[(0,$.jsx)(pc,{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(),G(!0))}}),children:(0,$.jsxs)(`div`,{className:Y(`relative flex items-center gap-1.5 rounded-lg px-2 py-1.5`,Pr),...R,children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onMouseDown:ge,onClick:ve,...P?z:{},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)(Ti,{project:{id:n,iconImage:c},className:`size-full object-contain`,fallback:se}):se})]})}),(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)(Vi,{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)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(`sessions.sidebar.project.actions.newWorktreeEllipsis`)})})]}):null,h?null:(0,$.jsxs)(ta,{open:W,onOpenChange:le,children:[(0,$.jsx)(ca,{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`,W?`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:pe,onMouseDown:me,onClick:fe,children:(0,$.jsx)(X,{name:`more-2`,className:`h-3.5 w-3.5`})})}),(0,$.jsx)(ea,{align:`end`,className:`min-w-[180px]`,children:de(la)})]})]}),M&&v?(0,$.jsx)(`div`,{className:`absolute right-0.5 top-1/2 z-10 -translate-y-1/2`,children:(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{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)(Vi,{side:`bottom`,sideOffset:4,children:(0,$.jsx)(`p`,{children:F(f?`sessions.sidebar.project.actions.newDraftSession`:`sessions.sidebar.project.actions.newSession`)})})]})}):null]})}),(0,$.jsx)(hc,{className:`min-w-[180px]`,children:de(gc)})]})]}),t[30]=g,t[31]=R,t[32]=le,t[33]=ve,t[34]=h,t[35]=N,t[36]=n,t[37]=u,t[38]=l,t[39]=ne,t[40]=p,t[41]=W,t[42]=f,t[43]=j,t[44]=m,t[45]=z,t[46]=v,t[47]=y,t[48]=a,t[49]=se,t[50]=c,t[51]=i,t[52]=de,t[53]=P,t[54]=C,t[55]=M,t[56]=F,t[57]=Ce):Ce=t[57];let we;return t[58]!==w||t[59]!==B||t[60]!==be||t[61]!==Se||t[62]!==Ce?(we=(0,$.jsxs)(`div`,{ref:B,style:be,className:Se,children:[Ce,w]}),t[58]=w,t[59]=B,t[60]=be,t[61]=Se,t[62]=Ce,t[63]=we):we=t[63],we},_b=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}=ko(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=Eo.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 vb(e){e.stopPropagation()}function yb(e){e.stopPropagation()}function bb(e){e.stopPropagation()}var xb=e=>{let t=(0,zc.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(Hi,{delay:0,closeDelay:150,timeout:600,children:n}),t[0]=n,t[1]=r),r};function Sb(e){let{t}=Xe(),n=To(vo(Co,{activationConstraint:{distance:8}}),vo(bo,{coordinateGetter:Do})),r=To(vo(Co,{activationConstraint:{distance:8}})),i=e.hasSessionSearchQuery?null:(0,$.jsx)(ab,{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)(xb,{children:(0,$.jsxs)(xi,{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)(xb,{children:(0,$.jsxs)(xi,{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)(xb,{children:(0,$.jsx)(xi,{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)(xb,{children:(0,$.jsxs)(xi,{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:_i,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)(wo,{sensors:n,collisionDetection:xo,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)(jo,{items:e.sectionsForRender.map(e=>e.project.id),strategy:Ao,children:e.sectionsForRender.map(n=>{let i=n.project,o=i.id,s=er(i.normalizedPath)||i.normalizedPath,l=nr(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)(gb,{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:Hr(1)},role:`status`,"aria-live":`polite`,children:t(`sessions.sidebar.project.loadingSessions`)}):n.groups.length>0?(0,$.jsxs)(wo,{sensors:r,collisionDetection:xo,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=Oo(_,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)(jo,{items:_.map(e=>e.id),strategy:Ao,children:_.map(t=>{let n=`${o}:${t.id}`;return(0,$.jsx)(_b,{id:t.id,disabled:e.isInlineEditing,children:r=>e.renderGroupSessions(t,n,o,!1,r,void 0,a)},t.id)})}),(0,$.jsx)(So,{dropAnimation:null})]}):(0,$.jsx)(`div`,{className:_i,children:t(`sessions.sidebar.empty.noSessions.title`)})})},o)})}),(0,$.jsx)(So,{dropAnimation:null})]})]})]})})}function Cb(e){if(typeof e!=`number`||!Number.isFinite(e))return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${t.toLocaleString(Qe(),{month:`short`})} ${t.getDate()}, ${t.getFullYear()}, ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function wb(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 Tb(e){let t=e.info.role===`user`?`User`:`Assistant`,n=Cb(e.info.time?.created),r=wb(e),i=n&&r?`${n} (${r})`:n||r;return i?`**${t}**\n\n*${i}*`:`**${t}**`}function Eb(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(``)}function Db(e){let t=Tb(e),n=Eb(e.parts).trim();return n?`${t}\n\n${n}`:``}function Ob(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(Db).filter(Boolean).join(`
|
|
150
150
|
|
|
151
151
|
---
|
|
152
152
|
|
|
@@ -166,7 +166,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,D as n,E as r,F
|
|
|
166
166
|
|
|
167
167
|
---
|
|
168
168
|
|
|
169
|
-
`+e}return r}function Ab(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 jb(e,t){let n=await ee(t,e);if(n)return n;if(!v())return null;try{let n=await oe()?.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 Mb(e){let t=oe()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await R(e)?!0:z(e)}function Nb(){return
|
|
169
|
+
`+e}return r}function Ab(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 jb(e,t){let n=await ee(t,e);if(n)return n;if(!v())return null;try{let n=await oe()?.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 Mb(e){let t=oe()?.files;if(t?.revealPath)try{return!!(await t.revealPath(e))?.success}catch{return!1}return await R(e)?!0:z(e)}function Nb(){return Zn()}function Pb(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 Fb=(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},Ib=fe()((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=Fb(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}))}})),Lb=!1,Rb=new Set,zb=!1;function Bb(){for(let e of Rb)e()}function Vb(e){Lb!==e&&(Lb=e,Bb())}function Hb(e){e.key===`Shift`&&Vb(!0)}function Ub(e){e.key===`Shift`&&Vb(!1)}function Wb(){Vb(!1)}function Gb(){zb||typeof window>`u`||(zb=!0,window.addEventListener(`keydown`,Hb),window.addEventListener(`keyup`,Ub),window.addEventListener(`blur`,Wb))}function Kb(e){return Gb(),Rb.add(e),()=>{Rb.delete(e)}}function qb(){return Lb}function Jb(){return!1}function Yb(){return(0,Q.useSyncExternalStore)(Kb,qb,Jb)}var Xb=!1,Zb=!1,Qb=new Set;function $b(){Qb.forEach(e=>e())}function ex(e){Xb!==e&&(Xb=e,$b())}function tx(e){return rr()?e.key===`Meta`:e.key===`Control`}var nx=(({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:ex});function rx(e){tx(e)&&nx.press()}function ix(){nx.release()}function ax(e){tx(e)&&ix()}function ox(){document.visibilityState!==`visible`&&ix()}function sx(){Zb||typeof window>`u`||(Zb=!0,window.addEventListener(`keydown`,rx),window.addEventListener(`keyup`,ax),window.addEventListener(`blur`,ix),document.addEventListener(`visibilitychange`,ox))}function cx(e){return sx(),Qb.add(e),()=>Qb.delete(e)}function lx(){return Xb}function ux(){return!1}function dx(){return(0,Q.useSyncExternalStore)(cx,lx,ux)}var fx=(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} ---`},px=(e,t)=>Tn.getState().getWorktreeMetadata(e)?.projectDirectory??t,mx=async e=>{let t=e.directory??void 0,n=ln(e.session.id,t);if(n.length===0&&e.directory){let t=(await Ne.withDirectory(e.directory,()=>Ne.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 Nt(n.parts??[]).trim()}return``}for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.role===`assistant`)return Nt(Rn(r.id,t)).trim()}return``};function hx({session:e,open:t,onOpenChange:n}){let{t:r}=Xe(),i=bt(),a=vn(e=>e.activeSessions),o=vn(e=>e.archivedSessions),s=Ut(e=>e.providers),c=Ut(e=>e.currentProviderId),l=Ut(e=>e.currentModelId),u=Ut(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=Tn.getState().getDirectoryForSession(e.id),r=px(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=Tn.getState().getDirectoryForSession(e.id)??fn(e),i=px(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)(ur,{open:t,onOpenChange:n,children:(0,$.jsxs)(sr,{className:`max-w-xl overflow-visible`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsx)(cr,{children:r(`multirun.fusion.title`)}),(0,$.jsx)(lr,{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)(ji,{modelId:p,providerId:d,className:`h-3.5 w-3.5 mr-1`}):void 0})}),O.length>0?(0,$.jsxs)(Oi,{value:_||`__default__`,onValueChange:e=>v(e===`__default__`?``:e),children:[(0,$.jsxs)(Ri,{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)(wi,{children:e=>e===`__default__`?r(`multirun.modelMultiSelect.variant.default`):e})]}),(0,$.jsxs)(Di,{fitContent:!0,portalToBody:!0,children:[(0,$.jsx)(Li,{value:`__default__`,children:r(`multirun.modelMultiSelect.variant.default`)}),O.map(e=>(0,$.jsx)(Li,{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)(ji,{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)(or,{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=>mx(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([vt(`session.fusion.visible`),vt(`session.fusion.instructions`)]),c=await Tn.getState().createSession(a,i,null);if(!c)throw Error(`Failed to create fusion session`);Tn.getState().setCurrentSession(c.id,i),n(!1),await Ne.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:fx(e.source,e.text,t),synthetic:!0})),{text:`
|
|
170
170
|
|
|
171
171
|
--- FUSION INPUTS END ---
|
|
172
|
-
Now write the final fused answer.`,synthetic:!0}],directory:i??Ne.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 gx(e){let t=(0,Rc.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:nr,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 _x=e(Ee(),1),vx=null,yx=!1,bx=(e,t=$r.getState().focus)=>e===null?null:typeof e==`string`?t?.sessionId===e?t:Qr(e):e,xx=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))},Sx=()=>{vx&&=(xx(vx),null)},Cx=(e,t)=>{Sx(),Tn(!0);let n=bx(e);if(!n)return;yx=!0;let r;try{r=Pn(n.sessionId)}finally{yx=!1}vx={commit:t,commitFrame:null,fallbackTimer:null,focus:n,intent:r,paintFrame:null,scheduled:!1},(0,_x.flushSync)(()=>{$r.getState().setFocus(n)}),typeof window<`u`&&(vx.fallbackTimer=window.setTimeout(()=>{wx(n)},150))},wx=e=>{let t=vx,n=bx(e);if(!t||!vi(t.focus,n)||t.scheduled)return;t.scheduled=!0,typeof window<`u`&&t.fallbackTimer!==null&&(window.clearTimeout(t.fallbackTimer),t.fallbackTimer=null);let r=()=>{vx===t&&on()===t.intent&&(vx=null,fn(),t.commit())};if(typeof window>`u`){r();return}t.commitFrame=window.requestAnimationFrame(()=>{vx===t&&on()===t.intent&&(t.paintFrame=window.requestAnimationFrame(r))})},Tx=e=>{if(vx)return;let t=$r.getState();t.setFocus(bx(e,t.focus))};un(e=>{if(yx)return;let t=vx;if(t?.intent===e)return;t&&Sx();let n=$r.getState();n.setFocus(bx(e.sessionId,n.focus))});var Ex=e=>{let t=[],n=e=>{e.children.forEach(e=>{t.push(e.session.id),n(e)})};return n(e),t},Dx=Q.memo(function(e){let t=(0,Rc.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)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:c,"aria-label":n,onPointerDown:a,onMouseDown:o,onClick:s,onKeyDown:Bx,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)(Bi,{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)(Hi,{children:[d,f]}),t[15]=d,t[16]=f,t[17]=p):p=t[17],p}),Ox=Q.memo(function(e){let t=(0,Rc.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=Yb(),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)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:y,"aria-label":h,onPointerDown:c,onMouseDown:l,onClick:_,onKeyDown:Vx,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)(Bi,{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)(Hi,{children:[S,C]}),t[21]=S,t[22]=C,t[23]=w):w=t[23],w}),kx=Q.memo(function(e){let t=(0,Rc.c)(3),{number:n}=e;if(!dx())return null;let r=tr()?`⌘${n}`:`Ctrl+${n}`,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Da,{"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 Ax(e){let{t}=Xe(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:s=!1,pinnedSessionIds:c,expandedParents:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:d,editingId:f,setEditingId:p,editTitle:h,setEditTitle:g,handleSaveEdit:y,handleCancelEdit:b,toggleParent:x,handleSessionSelect:S,handleSessionDoubleClick:C,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:U=`project`,subtreeContainsActive:ee,subtreeContainsEditing:W,menuOpenSessionId:ne,childRenderExtrasFor:G,liveSessionById:re,shortcutNumber:K=null}=e,ie=!!H?.projectLabel,ae=!!H?.branchLabel,oe=Py(e=>e.displayMode),se=Q.useMemo(()=>v(),[]),ce=oe===`minimal`||se,le=Q.useMemo(()=>w(),[]),ue=Q.useContext(fo),de=se?`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`,fe=se,pe=U===`pinned`,me=!pe&&!s&&!z,we=`h-5 w-5`,Te=`h-3.5 w-3.5`,Ee=(me||pe?1:0)+ +!!fe+1,De=Ee>=3?`group-hover:pr-18 group-focus-within:pr-18`:Ee>=2?`group-hover:pr-12 group-focus-within:pr-12`:`group-hover:pr-7 group-focus-within:pr-7`,Oe=Ee>=2?`pr-12`:`pr-8`,ke=Q.useRef(!1),Ae=Q.useRef(!1),[je,Me]=Q.useState(!1),Ne=Q.useRef(f);Ne.current=f;let q=Q.useRef(null),Pe=Q.useRef(y);Pe.current=y;let[Fe,Ie]=Q.useState(h),[Le,Re]=Q.useState(null),ze=Q.useRef(Fe);ze.current=Fe;let Be=Q.useRef(null),Ve=Q.useRef(null),He=Q.useRef(null),Ue=n.session,We=re.get(Ue.id)??Ue,qe=!!We.metadata?.openchamber?.assistant,Je=_(Ue.directory??null)??_(i??null),Ye=lt(Je??void 0,{bootstrap:!1}),Ze=ro(),Qe=Ib(e=>e.enabled),$e=Ib(Q.useMemo(()=>e=>e.selectedIds.has(Ue.id),[Ue.id])),et=Ib(e=>e.toggleSelected),tt=Ib(e=>e.setRange),[nt,rt]=Q.useState(!1),[it,at]=Q.useState(!0),[st,ct]=Q.useState(!1),dt=`${U}:${s?`archived`:`active`}:${Ue.id}`,ft=Lt(Q.useMemo(()=>e=>!!e.sessionMemoryState.get(ut(Ue.id))?.isZombie,[Ue.id])),pt=Wt(Ue.id),ht=jn(Ue.id,Je??void 0,{bootstrap:!1}),gt=gn(Ue.id,Je??void 0,{bootstrap:!1}),_t=Q.useMemo(()=>({scope:U,sessionId:Ue.id,projectId:a??null}),[a,U,Ue.id]),vt=Q.useMemo(()=>hi(_t)??``,[_t]),yt=Q.useRef(null),bt=$r(Q.useMemo(()=>e=>vi(e.focus,_t),[_t]));Q.useLayoutEffect(()=>{bt&&(yt.current?.scrollIntoView({block:`nearest`,inline:`nearest`}),wx(_t))},[bt,_t]);let St=We.title||t(`sessions.sidebar.session.untitled`),Ct=We.metadata?.openchamber?.titleRefresh,wt=typeof Ct?.lastError==`string`?Ct.lastError:null,Et=typeof Ct?.failedAt==`number`?Ct.failedAt:null;Q.useEffect(()=>{!wt||Et===null||(Re(null),console.warn(`[session-title] generation failed for ${Ue.id}: ${wt}`))},[Ue.id,wt,Et]),Q.useEffect(()=>{if(Le===null)return;if(St!==Le){Re(null);return}let e=window.setTimeout(()=>Re(null),3e4);return()=>window.clearTimeout(e)},[Le,St]);let Dt=n.children.length>0||!!We.hasChildren,Ot=c.has(Ue.id),kt=dt,At=u?!0:l.has(kt),jt=!!We.parentID,Mt=U===`pinned`,Nt=mt(Ue.id)>0&&!jt,Pt=Tt(We)||Date.now(),Ft=kr(Pt),It=si(Pt),[Rt,zt]=Q.useState(!1),Bt=Rt,Vt=Q.useMemo(()=>jc(We.title)!==null,[We.title]),[Ht,Ut]=Q.useState(!1),Gt=Q.useMemo(()=>Ex(n).length,[n]),Kt=Ge(e=>{let t=Je??``,n=(Fn()??pn(t,Ye)).getTranscript(Rn(t,e)),r=Ye.getState().session.find(t=>t.id===e)?.revert?.messageID;return ot({sessionID:e,messages:An(n),parts:n.partsByMessageID,revertMessageID:r}).list}),qt=Ge(async e=>{let n=[],r=0;for(let i of e)try{await Ze.ensureSessionRenderable(i.session.id);let e=Kt(i.session.id),a=i.session.title||t(`sessions.sidebar.session.export.untitledSubagent`),o=i.session.agent,s=await qt(i.children);r+=s.skipped,n.push({title:a,agent:o,records:e,children:s.children})}catch{r+=Ex(i).length+1}return{children:n,skipped:r}}),Jt=Ge(e=>{e<=0||J.warning(t(e===1?`sessions.sidebar.session.export.skippedSubtaskSingle`:`sessions.sidebar.session.export.skippedSubtaskMany`,{count:e}))}),Yt=Ge(async e=>{if(!Je){J.error(t(`sessions.sidebar.session.export.nothingToExport`));return}await Ze.ensureSessionRenderable(Ue.id);let r=Kt(Ue.id);if(r.length===0){J.error(t(`sessions.sidebar.session.export.nothingToExport`));return}let i,a=0;if(e&&n.children.length>0){let e=await qt(n.children);i=e.children,a=e.skipped}let o=kb(r,We.title??null,i),s=Pb(We.title??null),c=await jb(o,s);if(c){J.success(t(`sessions.sidebar.session.export.success`),{action:{label:t(Nb()),onClick:()=>{Mb(c).then(e=>{e||J.error(t(`sessions.sidebar.session.export.failedRevealPath`))})}}}),Jt(a);return}Ab(o,s),J.success(t(`sessions.sidebar.session.export.success`)),Jt(a)}),Xt=Ge(async()=>{if(n.children.length>0){at(!0),rt(!0);return}await Yt(!1)}),Zt=Ge(()=>{Je&&te(`desktop_open_session_mini_chat_window`,{sessionId:Ue.id,directory:Je,apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[session-sidebar] failed to open mini chat window`,e)})});Ke(Ve,()=>{Pe.current(ze.current)},f===Ue.id),Q.useLayoutEffect(()=>{if(f!==Ue.id){Be.current===Ue.id&&(Be.current=null);return}Be.current!==Ue.id&&(Be.current=Ue.id,Ie(h),queueMicrotask(()=>He.current?.select()))},[f,h,Ue.id]);let Qt=Ge(e=>{if(!e&&q.current){let{id:e,title:t}=q.current;q.current=null,p(e),g(t)}}),$t=Ge(e=>{zt(e)}),en=Ge(e=>{e.preventDefault(),e.stopPropagation()}),tn=Ge(e=>{e.preventDefault(),e.stopPropagation()}),nn=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ue.id)}),rn=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ue,{archivedBucket:s})}),an=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ue,{archivedBucket:s,hardDelete:!0,skipConfirm:!0})}),on=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ue.id)}),sn=Ge(()=>{let e=pt?.type??`idle`;!Je||st||e===`busy`||e===`retry`||(ct(!0),(async()=>{try{await Ze.refreshSessionTranscript(Ue.id,{directory:Je}),J.success(t(`sessions.sidebar.session.menu.refreshTranscriptSuccess`))}catch{J.error(t(`sessions.sidebar.session.menu.refreshTranscriptFailed`))}finally{ct(!1)}})())}),cn=Ge(e=>{e.preventDefault(),e.stopPropagation()}),ln=Ge(e=>{e.preventDefault(),e.stopPropagation()}),un=Ge(e=>{e.preventDefault(),e.stopPropagation(),ue?.vscode?.executeCommand(`openchamber.openSessionInEditor`,Ue.id,St)}),dn=Ge(e=>{if(ke.current){ke.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=Ib.getState().anchorId,r=new Map;r.set(Ue.id,Ex(n)),tt(t,Ue.id,e,Je??null,r);return}et(Ue.id,Je??null,Ex(n));return}S(Ue.id,Je,a,U)}),fn=Ge(e=>{e.defaultPrevented||e.target?.closest(`button, a, input, [role="menuitem"], [role="menu"]`)||dn(e)}),mn=Ge(e=>{(e.button===2||e.button===0&&e.ctrlKey&&!Qe)&&(ke.current=!0)}),hn=Ge(e=>{Ae.current=e.pointerType===`mouse`,z&&e.pointerType===`touch`&&Me(!0)}),_n=Ge(e=>{z&&e.pointerType===`touch`&&Me(!1)}),vn=Ge(e=>{e.key!==`Enter`||!Ae.current||(e.preventDefault(),e.stopPropagation(),C(Ue.id,St))}),yn=Ge(e=>{if(dn(e),!Ae.current)return;let t=e.currentTarget;window.requestAnimationFrame(()=>{Ae.current=!0,t.focus({preventScroll:!0})})}),bn=Ge(()=>{Ae.current=!1}),xn=Ge(e=>{if(!Ae.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(),Ae.current=!1)});if(f===Ue.id){let e=async()=>{Re(St),b();try{await xt(Ue.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:Vr(r)},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:He,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:t(`sessions.sidebar.session.menu.rename`),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Escape`){b();return}}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},"aria-label":t(`sessions.sidebar.session.rename.smartTitle`),title:t(`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":t(`sessions.sidebar.session.rename.save`),title:t(`sessions.sidebar.session.rename.save`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(X,{name:`check`,className:`size-3.5`})})]}),ce?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&&!Mt&&!jt?(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center flex-shrink-0`,children:At?(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:Ft}),ie?(0,$.jsx)(`span`,{className:`truncate`,children:H?.projectLabel}):null,ae?(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]})})]})},Ue.id)}let Sn=pt?.type??`idle`,Cn=Sn===`busy`||Sn===`retry`,wn=Le!==null||Ct?.isGenerating===!0,Tn=ht.length,En=gt.length>0,Dn=En||Cn||!En&&!Cn&&Nt&&!bt,On=!B||se,kn=En?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":t(`sessions.sidebar.session.status.questionRequired`),title:t(`sessions.sidebar.session.status.questionRequired`),children:(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`})}):Cn?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":t(`sessions.sidebar.session.status.active`),title:t(`sessions.sidebar.session.status.active`),children:(0,$.jsx)(Rs,{})}):(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":t(`sessions.sidebar.session.status.unread`),title:t(`sessions.sidebar.session.status.unread`),children:(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-[var(--status-info)]`})}),Mn=!Mt&&!B&&Dt&&Ot,Nn=!Mt&&Ot,Pn=(0,$.jsx)(X,{name:`pushpin-2-fill`,className:`h-3 w-3 flex-shrink-0 text-foreground`,"aria-label":t(`sessions.sidebar.session.status.pinned`)}),In=Nn?(0,$.jsx)(`span`,{className:Y(`pointer-events-none absolute inline-flex h-3.5 w-3.5 items-center justify-center transition-opacity`,ce?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,Mn?`opacity-100 group-hover:opacity-0 group-focus-within:opacity-0`:``),style:{left:Vr(Math.max(0,r-1))},children:Pn}):null,Ln=!Mt&&!jt&&Dt,zn=Ln&&!B,Bn=Vr(Math.max(0,r-1)),Vn=()=>{!At&&n.children.length===0&&Ze.loadChildren(Ue.id,Je).catch(()=>void 0),x(kt)},Hn=Ln?(0,$.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),e.currentTarget.blur(),Vn()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),Vn())},style:{minWidth:14,minHeight:14,left:Bn},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`,ce?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,zn?`opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto`:``),"aria-label":t(At?`sessions.sidebar.session.subsessions.collapse`:`sessions.sidebar.session.subsessions.expand`),children:At?(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,Un=ft?(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4 text-status-warning`}):null,Wn=(0,$.jsx)(be,{children:(0,$.jsx)(ve,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ge,{"data-slot":`dropdown-menu-content`,finalFocus:()=>!(j||Ne.current),style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(ta,`min-w-[180px]`),children:(({Item:e,Separator:n,Sub:r,SubTrigger:i,SubContent:a})=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(e,{onClick:()=>{q.current={id:Ue.id,title:St}},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`pencil-ai`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.rename`)]}),(0,$.jsxs)(e,{onClick:()=>T(Ue.id),className:`[&>svg]:mr-1`,children:[Ot?(0,$.jsx)(X,{name:`unpin`,className:`mr-1 h-4 w-4`}):(0,$.jsx)(X,{name:`pushpin`,className:`mr-1 h-4 w-4`}),t(Ot?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`)]}),We.share?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onClick:()=>{We.share?.url&&O(We.share.url,Ue.id)},className:`[&>svg]:mr-1`,children:D===Ue.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`check`,className:`mr-1 h-4 w-4`,style:{color:`var(--status-success)`}}),t(`sessions.sidebar.session.menu.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`file-copy`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.copyLink`)]})}),(0,$.jsxs)(e,{onClick:()=>k(Ue.id),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`link-unlink-m`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.unshare`)]})]}):(0,$.jsxs)(e,{onClick:()=>E(We),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`share-2`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.share`)]}),(0,$.jsxs)(e,{onClick:()=>{Xt()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`download`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.exportMarkdown`)]}),(0,$.jsxs)(e,{disabled:!Je||Cn||st,onClick:()=>{sn()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`mr-1 h-4 w-4`,st&&`animate-spin`)}),t(`sessions.sidebar.session.menu.refreshTranscript`)]}),Vt?(0,$.jsxs)(e,{onClick:()=>Ut(!0),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(gx,{className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.runFusion`)]}):null,Je&&!s?(()=>{let o=M(Je),s=N(Je,Ue.id);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(n,{}),(0,$.jsxs)(r,{children:[(0,$.jsxs)(i,{className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`folder`,className:`h-4 w-4`}),t(`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:t(`sessions.sidebar.folders.none`)}):o.map(t=>(0,$.jsxs)(e,{onClick:()=>{s===t.id?P(Je,Ue.id):F(Je,t.id,Ue.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)(n,{}),(0,$.jsxs)(e,{onClick:()=>{let e=I(Je);e&&F(Je,e.id,Ue.id)},children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.folders.newFolderEllipsis`)]}),s?(0,$.jsxs)(e,{onClick:()=>{P(Je,Ue.id)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(X,{name:`close`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]})]})})():null,se?null:(0,$.jsxs)(e,{disabled:!Je,onClick:()=>{Je&&L(Je,{mode:`chat`,dedupeKey:`session:${Ue.id}`,label:St,sessionTitleFallback:St})},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`chat-thread`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:t(`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:t(`sessions.sidebar.session.menu.betaBadge`)})]}),le?(0,$.jsxs)(e,{disabled:!Je,onClick:Zt,className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`window`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:t(`sessions.sidebar.session.menu.openMiniChatWindow`)})]}):null,(0,$.jsx)(n,{}),s?null:(0,$.jsxs)(e,{className:`[&>svg]:mr-1`,onClick:()=>R(Ue,{archivedBucket:s}),children:[(0,$.jsx)(X,{name:`inbox-archive`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.bulkActions.archive`)]}),(0,$.jsxs)(e,{className:`text-destructive focus:text-destructive [&>svg]:mr-1`,onClick:()=>R(Ue,{archivedBucket:s,hardDelete:!0}),children:[(0,$.jsx)(X,{name:`delete-bin`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.bulkActions.delete`)]})]}))({Item:({className:e,...t})=>(0,$.jsx)(_e,{className:Y(la,e),...t}),Separator:({className:e,...t})=>(0,$.jsx)(he,{className:Y(ra,e),...t}),Sub:ye,SubTrigger:({className:e,children:t,...n})=>(0,$.jsxs)(xe,{className:Y(aa,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)(be,{children:(0,$.jsx)(ve,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ge,{"data-slot":`dropdown-menu-sub-content`,style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(ta,e),...n,children:t})})})})})})});return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(wy,{sessionId:Ue.id,sessionDirectory:Je??null,sessionTitle:St,children:(0,$.jsxs)(Se,{open:Rt,onOpenChange:$t,onOpenChangeComplete:Qt,children:[(0,$.jsxs)(Ce,{render:(0,$.jsx)(`div`,{ref:yt,"data-session-row":Ue.id,"data-session-scope":Je??``,"data-session-focus-scope":U,"data-session-focus-key":vt,"data-session-project-id":a??``,"data-session-archived":s?`1`:`0`,"data-session-depth":r,onClick:fn,onMouseLeave:xn,className:Y(`group relative my-0.5 flex cursor-pointer items-center rounded-lg py-1.5 pr-2`,bt&&!$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)]`,!bt&&!$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:[In,Hn,(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,style:{paddingLeft:Vr(r)},children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onPointerDown:hn,onPointerUp:_n,onPointerCancel:_n,onMouseDown:mn,onKeyDown:vn,onBlur:bn,onClick:yn,onDoubleClick:e=>{e.stopPropagation(),C(Ue.id,St)},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`,je&&`bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,B?se?De:Oe:De),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`,wn&&`animate-text-shimmer`),"aria-busy":wn||void 0,children:Lr(St,d)}),qe?(0,$.jsx)(X,{name:`ai-agent`,className:`size-3 shrink-0 text-muted-foreground`,"aria-label":`Assistant`}):null,Tn>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:t(`sessions.sidebar.session.status.permissionRequired`),"aria-label":t(`sessions.sidebar.session.status.permissionRequired`),children:[(0,$.jsx)(X,{name:`shield`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`leading-none`,children:Tn})]}):null,Dn?(0,$.jsx)(`span`,{className:Y(`inline-flex shrink-0 items-center justify-center transition-none`,On?Y(`group-hover:hidden group-focus-within:hidden`,Bt?`hidden`:``):Bt?`invisible`:``),children:kn}):null,K?(0,$.jsx)(kx,{number:K}):null]})})}),se?null:(0,$.jsx)(Bi,{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:St}),(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:It})]}),ie?(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,ae?(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]})})]})})}),Un&&!z?(0,$.jsx)(`div`,{className:Y(`absolute top-1/2 -translate-y-1/2 z-10`,ce?`right-0`:`right-[30px]`),children:Un}):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`,Bt||B&&!se?`opacity-100`:Y(`opacity-0`,de)),children:[me?(0,$.jsx)(Dx,{pinLabel:t(`sessions.sidebar.session.menu.pin`),buttonSizeClass:we,iconSizeClass:Te,onPointerDown:en,onMouseDown:tn,onPin:nn}):null,pe?(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{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`,we),"aria-label":t(`sessions.sidebar.session.actions.pinned`),onPointerDown:en,onMouseDown:tn,onClick:on,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`pushpin-2-fill`,className:Te})})}),(0,$.jsx)(Bi,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:t(`sessions.sidebar.session.actions.pinned`)})]}):null,fe?(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{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`,we),"aria-label":t(`sessions.sidebar.session.actions.openInEditor`),onPointerDown:cn,onMouseDown:ln,onClick:un,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:Te})})}),(0,$.jsx)(Bi,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:t(`sessions.sidebar.session.actions.openInEditor`)})]}):null,(0,$.jsx)(Ox,{archiveLabel:t(`sessions.sidebar.bulkActions.archive`),deleteLabel:t(`sessions.sidebar.bulkActions.delete`),deleteOnly:s===!0,buttonSizeClass:we,iconSizeClass:Te,revealClassName:ce&&!B&&!Bt?Y(`opacity-0`,de):`opacity-100`,onPointerDown:en,onMouseDown:tn,onArchive:rn,onDelete:an})]})]}),Wn]})}),!Mt&&Dt&&At?n.children.map(e=>{let t=G?G(e):{subtreeContainsActive:ee,subtreeContainsEditing:W,menuOpenSessionId:ne,nodeStructureKey:``};return V(e,r+1,Je??i,a,s,void 0,U,t)}):null,(0,$.jsx)(cr,{open:nt,onOpenChange:rt,children:(0,$.jsxs)(ar,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[(0,$.jsxs)(rr,{children:[(0,$.jsx)(or,{children:t(`sessions.sidebar.session.export.dialog.title`)}),(0,$.jsx)(sr,{children:t(Gt===1?`sessions.sidebar.session.export.dialog.descriptionSingle`:`sessions.sidebar.session.export.dialog.descriptionMany`,{count:Gt})})]}),(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`}),t(`sessions.sidebar.session.export.dialog.includeSubtasks`)]}),(0,$.jsxs)(ir,{children:[(0,$.jsx)(Z,{type:`button`,onClick:()=>rt(!1),variant:`outline`,size:`sm`,children:t(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{type:`button`,onClick:()=>{rt(!1),Yt(it)},size:`sm`,children:t(`sessions.sidebar.session.export.dialog.confirm`)})]})]})}),Vt?(0,$.jsx)(hx,{session:We,open:Ht,onOpenChange:Ut}):null]},Ue.id)}var jx=e=>_(e.session.directory??null),Mx=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null),Nx=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},Px=e=>e.menuOpenSessionId??Nx(e),Fx=(e,t,n)=>t?n.has(e.node.session.id)?!0:jy(e.node,t):!1,Ix=(e,t,n,r,i)=>{if(e.session.id!==t.session.id)return!0;let a=i(e);if(n.has(a)!==r.has(a)||e.children.length!==t.children.length)return!0;for(let a=0;a<e.children.length;a+=1)if(Ix(e.children[a],t.children[a],n,r,i))return!0;return!1},Lx=(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&&ky(a)!==ky(o)||e.children.length!==t.children.length)return!0;for(let i=0;i<e.children.length;i+=1)if(Lx(e.children[i],t.children[i],n,r))return!0;return!1},Rx=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;let n=e.archivedBucket?`archived`:`active`,r=t.archivedBucket?`archived`:`active`;return Ix(e.node,t.node,e.expandedParents,t.expandedParents,t=>`${e.renderContext??`project`}:${n}:${t.session.id}`)||Ix(e.node,t.node,e.expandedParents,t.expandedParents,e=>`${t.renderContext??`project`}:${r}:${e.session.id}`)},zx=Q.memo(Ax,(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||jx(e.node)!==jx(t.node)||!Mx(e.secondaryMeta,t.secondaryMeta)||e.liveSessionById!==t.liveSessionById&&Lx(e.node,t.node,e.liveSessionById,t.liveSessionById)||e.pinnedSessionIds!==t.pinnedSessionIds&&Ix(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e=>e.session.id)||e.expandedParents!==t.expandedParents&&Rx(e,t)||e.currentSessionId!==t.currentSessionId&&(Fx(e,e.currentSessionId,e.subtreeContainsActive)||Fx(t,t.currentSessionId,t.subtreeContainsActive))||e.editingId!==t.editingId&&(Fx(e,e.editingId,e.subtreeContainsEditing)||Fx(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(Fx(e,e.editingId,e.subtreeContainsEditing)||Fx(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(jy(e.node,e.copiedSessionId)||jy(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Px(e),r=Px(t);if(jy(e.node,n)||jy(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){let n=Px(e),r=Px(t);if(jy(e.node,n)||jy(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 Bx(e){return e.stopPropagation()}function Vx(e){return e.stopPropagation()}function Hx(e){let t=(0,Rc.c)(71),{t:n}=Xe(),{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=cr,g=!!r,t[13]===i?_=t[14]:(_=e=>{e||i(null)},t[13]=i,t[14]=_),u=ar,m=!1,h=`max-w-sm gap-5`,l=rr;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)(or,{children:a}),t[18]=a,t[19]=p),c=sr,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)(ir,{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 Ux(e){let t=(0,Rc.c)(57),{t:n}=Xe(),{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)(or,{children:d}),t[10]=d,t[11]=g);let _;t[12]===p?_=t[13]:(_=(0,$.jsx)(sr,{children:p}),t[12]=p,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,$.jsxs)(rr,{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)(ir,{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)(ar,{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)(cr,{open:m,onOpenChange:h,children:M}),t[53]=m,t[54]=M,t[55]=h,t[56]=N):N=t[56],N}function Wx(e){let t=(0,Rc.c)(36),{t:n}=Xe(),{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)(or,{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)(sr,{children:u}),t[9]=u,t[10]=d);let f;t[11]!==l||t[12]!==d?(f=(0,$.jsxs)(rr,{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)(ir,{children:[h,_]}),t[26]=_,t[27]=h,t[28]=v):v=t[28];let y;t[29]!==v||t[30]!==f?(y=(0,$.jsxs)(ar,{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)(cr,{open:o,onOpenChange:s,children:y}),t[32]=o,t[33]=s,t[34]=y,t[35]=b):b=t[35],b}var Gx=e=>{let t=(0,Rc.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}=Xe(),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)(ea,{children:[(0,$.jsxs)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(sa,{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)(Bi,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f(`sessions.sidebar.bulkActions.moveToFolder`)})})]}),(0,$.jsxs)($i,{align:`end`,className:`min-w-[180px]`,children:[i.length===0?(0,$.jsx)(ca,{disabled:!0,className:`text-muted-foreground`,children:f(`sessions.sidebar.folders.none`)}):i.map(e=>(0,$.jsx)(ca,{onClick:()=>o(e.id),children:(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})},e.id)),(0,$.jsx)(oa,{}),(0,$.jsxs)(ca,{onClick:s,children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.newFolderEllipsis`)]}),l?(0,$.jsxs)(ca,{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)(zi,{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)(Bi,{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)(Hi,{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)(zi,{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)(Bi,{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)(Hi,{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},Kx=e=>{let{t}=Xe(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,addSessionsToFolder:a,removeSessionsFromFolders:o,createFolderAndStartRename:s,archiveSessions:c,setBulkDeleteConfirm:l}=e,u=Ib(e=>e.enabled),d=Ib(e=>e.selectedIds.size),f=d>0,p=Ib(e=>e.selectedIds),m=Ib(e=>e.scopeKey),h=Q.useCallback(()=>{Ib.getState().toggleMode()},[]),g=Q.useCallback(()=>{Ib.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(_)uc({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&&qs({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}))}Ib.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(),Ib.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=Ib.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;Ib.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}},qx=e=>{let t=e.time?.created;return typeof t==`number`&&Number.isFinite(t)?t:0},Jx=(e,t)=>e.filter(e=>t.has(e.id)).sort((e,t)=>qx(t)-qx(e)),Yx=(e,t,n)=>{let r=[],i=new Set,a=e=>{let t=_(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},Xx=(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},Zx=({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=Xx(r,e,o,i)??{scope:`project`,sessionId:e,projectId:i};return!a||t.scope===`project`?s:Xx(n,e,o,i)??s};function Qx(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 $x=`oc.sessions.projectCollapse`,eS=`oc.sessions.groupOrder`,tS=`oc.sessions.groupCollapse`,nS=`oc.sessions.activeSessionByProject`,rS=`oc.sessions.expandedParents.v2`,iS=`oc.sessions.expandedParents`,aS=`oc.sessions.pinned`,oS=y(c()),sS=e=>{try{let t=oS.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}},cS=e=>{try{let t=oS.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}},lS=e=>{try{let t=oS.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}},uS=(e,t,n)=>{let r=new Set;for(let t of e){let e=_(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=_(t.path)?.toLowerCase();e&&r.add(e)}return r},dS=(e,t,n)=>{if(e.time?.archived)return!0;let r=_(Hn(e))?.toLowerCase();return r?t.size===0?n?.allowEmptyDirectorySet??!0:t.has(r):n?.allowUnknownDirectory??!0},fS=3e5,pS=new Set,mS=new Set,hS=[],gS=new Map,_S=e=>{let t=Q.useRef(e);return t.current=e,Q.useCallback((...e)=>t.current(...e),[])},vS=({mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:a=!1,isVisible:o=!0})=>{let{t:s}=Xe(),[c,u]=Q.useState(!1),[d,f]=Q.useState(!1),[m,h]=Q.useState(``),g=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(new Set),[x,S]=Q.useState(null),[C,w]=Q.useState(``),[T,E]=Q.useState(null),[D,O]=Q.useState(new Set),k=Q.useMemo(()=>oS,[]),[j,M]=Q.useState(new Set),[N,P]=Q.useState(new Map),[F,I]=Q.useState(new Map),L=p(e=>e.isNewWorktreeDialogOpen),R=p(e=>e.setNewWorktreeDialogOpen),[z,B]=Q.useState(null),[V,H]=Q.useState(null),[U,ee]=Q.useState(``),[te,W]=Q.useState(null),[ne,G]=Q.useState(null),[re,K]=Q.useState(null),ie=Gr(e=>e.ids),ae=Gr(e=>e.setIds),oe=Gr(e=>e.toggle),[se,ce]=Q.useState(()=>sS(tS)),[le,ue]=Q.useState(()=>lS(eS)),[de,fe]=Q.useState(()=>cS(nS));Q.useEffect(()=>l(e=>{t(e)&&(ce(sS(tS)),ue(lS(eS)),fe(cS(nS)),M(sS($x)),O(sS(rS)))}),[]);let[pe,he]=Q.useState(new Map),ge=Q.useRef(new Map),_e=Q.useRef(0),ve=Pe(e=>e.homeDirectory),ye=Pe(e=>e.currentDirectory),be=Pe(e=>e.setDirectory),xe=xn(e=>e.projects),Se=xn(e=>e.activeProjectId),Ce=xn(e=>e.removeProject),we=xn(e=>e.setActiveProjectIdOnly),Te=xn(e=>e.updateProjectMeta),Ee=xn(e=>e.reorderProjectsById),De=p(e=>e.setActiveMainTab),Oe=p(e=>e.activeMainTab),ke=qn(),Ae=p(e=>e.openContextPanelTab),je=p(e=>e.setSettingsDialogOpen),Me=p(e=>e.toggleHelpDialog),Ne=p(e=>e.setSessionSwitcherOpen),q=p(e=>e.setScheduledTasksDialogOpen),Fe=p(e=>e.notifyOnSubtasks),Ie=p(e=>e.showDeletionDialog),Le=p(e=>e.setShowDeletionDialog),Re=Bo(m,120),ze=Q.useMemo(()=>Re.trim().toLowerCase(),[Re]),Be=ze.length>0,Ve=as(me(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}))),He=Sn(e=>e.collapsedFolderIds),Ue=Sn(e=>e.foldersMap),We=Sn(e=>e.sessionOrderByScope),Ge=Sn(e=>e.sessionOrderActivityByScope),Ke=Sn(e=>e.getFoldersForScope),qe=Sn(e=>e.createFolder),Je=Sn(e=>e.renameFolder),Ye=Sn(e=>e.deleteFolder),Ze=Sn(e=>e.addSessionToFolder),Qe=Sn(e=>e.addSessionsToFolder),$e=Sn(e=>e.removeSessionFromFolder),et=Sn(e=>e.removeSessionsFromFolders),tt=Sn(e=>e.toggleFolderCollapse),nt=Sn(e=>e.cleanupSessions),rt=Sn(e=>e.getSessionFolderId),it=Sn(e=>e.reorderSessions);sv({isSessionSearchOpen:o&&d,setIsSessionSearchOpen:f,sessionSearchInputRef:y,sessionSearchContainerRef:g});let at=Q.useMemo(()=>new Map,[]),ot=Ct({enabled:o}),st=Et({enabled:o}),ct=dn(e=>o?e.statusById:gS),lt=Q.useMemo(()=>{if(!o)return mS;let e=new Set;for(let[t,n]of Object.entries(st))(n.type===`busy`||n.type===`retry`)&&e.add(t);for(let t of ct.keys())st[t]===void 0&&e.add(t);return e},[ct,o,st]),ut=Q.useMemo(()=>v(),[]),dt=Vn(e=>e.fullCatalogSessionIds),pt=Vn(e=>e.fullCatalogGeneration),mt=Vn(e=>e.status),gt=Vn(e=>e.activeSessions),_t=Vn(e=>e.archivedSessions),vt=Vn(e=>e.loadingDirectories),yt=Vn(e=>e.refreshingDirectories),bt=Vn(e=>e.archivedLoadingDirectories),xt=Q.useDeferredValue(gt),St=Q.useDeferredValue(_t),wt=yn(e=>e.currentSessionId),Tt=Q.useMemo(()=>{if(!wt||lt.has(wt))return lt;let e=new Set(lt);return e.add(wt),e},[wt,lt]),Dt=$r(e=>e.focus),Ot=Q.useSyncExternalStore(un,on,on),kt=yn(e=>!!e.newSessionDraft?.open),At=yn(e=>e.setCurrentSession),jt=yn(e=>e.updateSessionTitle),Mt=yn(e=>e.shareSession),Nt=yn(e=>e.unshareSession),Pt=yn(e=>e.worktreeMetadata),Ft=yn(e=>e.availableWorktreesByProject),It=yn(e=>e.openNewSessionDraft),Lt=Q.useCallback(e=>{It(e),ut&&window.dispatchEvent(new CustomEvent(`openchamber:navigate`,{detail:{view:`chat`}}))},[ut,It]),Rt=Q.useMemo(()=>uS(xe,Ft,{includeWorktrees:!ut}),[Ft,ut,xe]),zt=Q.useMemo(()=>{let e=new Map(ot.map(e=>[e.id,e])),t=xt.map(t=>{let n=e.get(t.id);return n?zn(n,t):t}),n=new Set(t.map(e=>e.id));return ot.forEach(e=>{n.has(e.id)||t.push(e)}),t.filter(e=>dS(e,Rt,{allowUnknownDirectory:!ut,allowEmptyDirectorySet:!ut}))},[xt,ut,Rt,ot]),Bt=Q.useMemo(()=>ot.map(e=>{let t=_(e.directory??null)??``;return`${e.id}:${e.title??``}:${+!!e.time?.archived}:${t}`}).join(`|`),[ot]),Vt=Q.useRef(ot);Q.useEffect(()=>{Vt.current=ot},[Bt,ot]);let Ht=Q.useMemo(()=>new Map(ot.map(e=>[e.id,e])),[ot]);Q.useEffect(()=>{let e=null,t=ht(t=>{t.type===`scheduled-task-ran`&&(e&&clearTimeout(e),e=setTimeout(()=>{let e=xn.getState().projects.find(e=>e.id===t.projectId),n=_(e?.path??null);if(!n)return;let r=[n];(yn.getState().availableWorktreesByProject.get(n)??[]).forEach(e=>{let t=_(e.path);t&&r.push(t)}),nn(r,Vt.current)},500))});return()=>{e&&clearTimeout(e),t()}},[]);let Ut=Q.useMemo(()=>A(),[]),Wt=vs(e=>e.sidebarBrandName.trim().length>0),{isTablet:Gt}=Ca(),Kt=e||Gt,{buildGroupSearchText:qt,filterSessionNodesForSearch:Jt,buildGroupedSessions:Yt}=ov({homeDirectory:ve,worktreeMetadata:Pt,pinnedSessionIds:ie,gitBranches:at,isVSCode:ut}),{scheduleCollapsedProjectsPersist:Xt,hasRestoredProjectCollapse:Qt}=hv({isVSCode:ut,fullCatalogSessionIds:dt,fullCatalogGeneration:pt,safeStorage:k,keys:{sessionExpanded:rS,sessionExpandedLegacy:iS,projectCollapse:$x,sessionPinned:aS,groupOrder:eS,projectActiveSession:nS,groupCollapse:tS},pinnedSessionIds:ie,setPinnedSessionIds:ae,groupOrderByProject:le,activeSessionByProject:de,collapsedGroups:se,setExpandedParents:O,setCollapsedProjects:M}),$t=Q.useMemo(()=>[...zt].sort((e,t)=>Mr(e,t,ie)),[zt,ie]),en=Q.useMemo(()=>{let e=new Map;return $t.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)=>Mr(e,t,ie))),e},[$t,ie]),tn=(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`)})]}),rn=Q.useMemo(()=>xe.find(e=>e.id===T)??null,[xe,T]),an=Q.useCallback(e=>{T&&Te(T,{label:e.label,icon:e.icon,color:e.color,iconBackground:e.iconBackground,defaultModel:e.defaultModel??null})},[T,Te]),sn=Q.useCallback(()=>{R(!0)},[R]),cn=Q.useCallback((t,n)=>{if(De(`chat`),e&&Ne(!1),n?.sessionId){At(n.sessionId,t);return}It({directoryOverride:t,preserveDirectoryOverride:!0})},[e,It,De,At,Ne]),ln=Q.useCallback(()=>{let e=as.getState();if(e.available&&e.info){u(!0);return}Ve.checkForUpdates().then(()=>{let{available:e,error:t}=as.getState();if(t){J.error(s(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}if(!e){J.success(s(`sessions.sidebar.updateCheck.latestVersion`));return}u(!0)})},[s,Ve]),fn=Q.useCallback(()=>{e&&Ne(!1),je(!0)},[e,Ne,je]),pn=Q.useCallback(()=>{De(`chat`),It(),e&&Ne(!1)},[e,It,De,Ne]),mn=Q.useCallback(()=>{if(!e){De(`schedule`);return}q(!0),Ne(!1)},[e,De,q,Ne]),hn=Q.useCallback(()=>{Jn(),e&&Ne(!1)},[e,Ne]),gn=Ve.available&&(Ve.runtimeType===`desktop`||Ve.runtimeType===`web`),_n=yn(e=>e.archiveSession),vn=yn(e=>e.archiveSessions),{copiedSessionId:bn,handleSessionSelect:wn,handleSessionDoubleClick:Tn,handleSaveEdit:En,handleCancelEdit:Dn,handleShareSession:On,handleCopyShareUrl:kn,handleUnshareSession:An,handleDeleteSession:jn,confirmDeleteSession:Mn}=cv({activeProjectId:Se,currentDirectory:ye,currentSessionId:wt,mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:d,sessionSearchQuery:m,setSessionSearchQuery:h,setIsSessionSearchOpen:f,setActiveProjectIdOnly:we,setDirectory:be,setActiveMainTab:De,setSessionSwitcherOpen:Ne,setCurrentSession:At,updateSessionTitle:jt,shareSession:Mt,unshareSession:Nt,archiveSession:_n,archiveSessions:vn,childrenMap:en,showDeletionDialog:Ie,setDeleteSessionConfirm:W,deleteSessionConfirm:te,setEditingId:S,setEditTitle:w,editingId:x,editTitle:C}),Nn=Q.useCallback((e,t,n,r=`project`)=>{let i={sessionId:e,scope:r,projectId:n??null};if(e===wt){Pn(e),Tx(i),wn(e,t,n);return}Cx(i,()=>wn(e,t,n))},[wn,wt]);Q.useEffect(()=>()=>{Sx()},[]);let Fn=Q.useCallback(()=>{if(!ne)return;let{scopeKey:e,folderId:t}=ne;G(null),Ye(e,t)},[ne,Ye]);Q.useEffect(()=>{if(!wt)return;let e=zt.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(rS,JSON.stringify(Array.from(n)))}catch{}return n})},[wt,zt,k]);let In=Q.useCallback(e=>{O(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{k.setItem(rS,JSON.stringify(Array.from(n)))}catch{}return n})},[k]),Ln=Q.useCallback((e,t)=>{if(!e)return null;t&&He.has(t)&&tt(t);let n=qe(e,s(`sessions.sidebar.folder.newFolderName`),t);return H(n.id),ee(n.name),n},[He,tt,qe,s]),Rn=_S(Nn),Bn=_S(Tn),Un=_S(En),Gn=_S(Dn),Kn=_S(On),Yn=_S(kn),Xn=_S(An),Zn=_S(jn),$n=_S(Ln),er=Q.useCallback((e,t,n,r)=>{let i=Ly(),a=Math.max(i,n)+7;if(I(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=_(e.directory??null);if(!o)return;let s=Vn.getState().activePaginationByDirectory.get(o);s?.hasMore&&!s.loadingMore&&Zt(o)},[]),tr=Q.useCallback(e=>{I(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),nr=Q.useCallback(e=>{I(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})},[]),rr=Q.useCallback(e=>{let t=xe.find(t=>t.id===e),n=_(t?.path??null);if(!n)return[];let r=[n];return ut||(Ft.get(n)??[]).forEach(e=>{let t=_(e.path);t&&r.push(t)}),r},[Ft,ut,xe]),ir=Q.useCallback(e=>{let t=rr(e);if(t.length===0)return;let n=Vn.getState().loadedDirectories,r=t.filter(e=>!n.has(e));r.length!==0&&nn(r,Vt.current)},[rr]),ar=Q.useCallback(e=>{let t=xe.find(t=>t.id===e);t&&(async()=>{let e=[];if(!ut)try{e=(await Ti({id:t.id,path:t.path})).worktrees}catch(n){console.warn(`[SessionSidebar] Worktree refresh before session sync failed:`,n);let r=_(t.path);e=r?yn.getState().availableWorktreesByProject.get(r)??[]:[]}let n=Yx(t.path,e,{currentDirectory:ye,workspaceRoot:t.path,includeWorktrees:!ut});n.length!==0&&await ft(n,Vt.current)})()},[ye,ut,xe]);Q.useEffect(()=>{if(!Qt)return;let e=Vn.getState(),t=xe.flatMap(t=>j.has(t.id)?[]:rr(t.id).filter(t=>!e.loadedDirectories.has(t)&&!e.loadingDirectories.has(t)&&!e.refreshingDirectories.has(t)));t.length>0&&nn(t,Vt.current)},[j,rr,Qt,xe]);let or=Q.useCallback(()=>{_e.current=Date.now()+150,I(new Map),M(()=>{let e=new Set(xe.map(e=>e.id));try{k.setItem($x,JSON.stringify(Array.from(e)))}catch{}return ut||Xt(e),e})},[xe,ut,k,Xt]),sr=Q.useCallback(()=>{_e.current=Date.now()+150,I(new Map),M(()=>{let e=new Set;try{k.setItem($x,JSON.stringify([]))}catch{}return ut||Xt(e),e});let e=Vn.getState().loadedDirectories,t=xe.flatMap(t=>rr(t.id).filter(t=>!e.has(t)));t.length>0&&nn(t,Vt.current)},[rr,ut,xe,k,Xt]),cr=Q.useCallback(e=>{_e.current=Date.now()+150,nr(e),M(t=>{let n=new Set(t);n.has(e)?(n.delete(e),queueMicrotask(()=>ir(e))):n.add(e);try{k.setItem($x,JSON.stringify(Array.from(n)))}catch{}return ut||Xt(n),n})},[ir,ut,nr,k,Xt]),lr=Q.useCallback(e=>{_e.current=Date.now()+150,ir(e),M(t=>{if(!t.has(e))return t;let n=new Set(t);n.delete(e);try{k.setItem($x,JSON.stringify(Array.from(n)))}catch{}return ut||Xt(n),n})},[ir,ut,k,Xt]),ur=Q.useMemo(()=>xe.map(e=>({...e,normalizedPath:_(e.path)})).filter(e=>!!e.normalizedPath),[xe]),dr=Q.useMemo(()=>ur.map(e=>e.normalizedPath),[ur]),fr=Q.useMemo(()=>{let e=new Set(ur.map(e=>e.normalizedPath));if(!ut)for(let t of Ft.values())for(let n of t){let t=_(n.path);t&&e.add(t)}return[...e].sort()},[Ft,ut,ur]),pr=Q.useRef(null);Q.useEffect(()=>{let e=new Set(fr),t=pr.current;if(pr.current=e,!t)return;let n=fr.filter(e=>!t.has(e));if(n.length===0)return;let r=Vn.getState().loadedDirectories,i=_(ye),a=ur.find(e=>e.id===Se)??ur.find(e=>e.normalizedPath===i)??null,o=new Set;i&&o.add(i),a?.normalizedPath&&(o.add(a.normalizedPath),ut||(Ft.get(a.normalizedPath)??[]).forEach(e=>{let t=_(e.path);t&&o.add(t)}));let s=n.filter(e=>o.has(e)&&!r.has(e));s.length!==0&&nn(s,Vt.current)},[Se,Ft,ye,ut,ur,fr]);let{github:mr}=uo(),hr=ha(),gr=hr.data??null,_r=hr.isFetched,vr=Jo(o?dr:hS),yr=ey(e=>e.ensureEntry),br=ey(e=>e.setParams),xr=ey(e=>e.refreshTargets);_v({normalizedProjects:ur,activeProjectId:Se,gitRepoStatus:vr,setProjectRepoStatus:P,setProjectRootBranches:he,enabled:o});let Sr=yn(e=>e.isLoading),Cr=Q.useMemo(()=>K_(zt,ur,Ft,ut,St),[St,Ft,ut,ur,zt]);yv({isSessionsLoading:Sr,fullCatalogSessionIds:dt,fullCatalogGeneration:pt,normalizedProjects:ur,cleanupSessions:nt});let{getSessionsForProject:wr,getArchivedSessionsForProject:Tr}=vv({ownership:Cr}),Er=Q.useMemo(()=>{let e=new Set;if(vt.size===0)return e;for(let t of ur){let n=[t.normalizedPath];ut||(Ft.get(t.normalizedPath)??[]).forEach(e=>{let t=_(e.path);t&&n.push(t)}),n.some(e=>vt.has(e))&&e.add(t.id)}return e},[Ft,ut,vt,ur]),Dr=Q.useMemo(()=>{let e=new Set;if(yt.size===0)return e;for(let t of ur)rr(t.id).some(e=>yt.has(e))&&e.add(t.id);return e},[rr,ur,yt]),Or=vt.size>0||yt.size>0||mt===`idle`||mt===`loading`;X_({normalizedProjects:ur,ownership:Cr,isSessionsLoading:Sr,fullCatalogSessionIds:dt,fullCatalogGeneration:pt,foldersMap:Ue,createFolder:qe,addSessionToFolder:Ze,cleanupSessions:nt,enabled:o});let kr=Q.useRef(!1);Se&&N.has(Se)&&(kr.current=!!N.get(Se));let Ar=Py(e=>e.projectSortOrder),jr=xn(e=>e.manualProjectOrder),{projectSections:Nr,groupSearchDataByGroup:Pr,sectionsForRender:Fr,searchMatchCount:Ir}=Q_({normalizedProjects:Q.useMemo(()=>{let e=[...ur];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},[ur,Ar,jr]),getSessionsForProject:wr,getArchivedSessionsForProject:Tr,availableWorktreesByProject:Ft,projectRepoStatus:N,projectRootBranches:pe,lastRepoStatus:kr.current,buildGroupedSessions:Yt,hasSessionSearchQuery:Be,normalizedSessionSearchQuery:ze,filterSessionNodesForSearch:Jt,buildGroupSearchText:qt,foldersMap:Ue}),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`)})]});ev({projectSections:Nr,activeProjectId:Se,activeSessionByProject:de,setActiveSessionByProject:fe,currentSessionId:wt,handleSessionSelect:wn,newSessionDraftOpen:kt,mobileVariant:e,openNewSessionDraft:It,setActiveMainTab:De,setSessionSwitcherOpen:Ne});let{getOrderedGroups:Rr}=tv(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&&ce(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=Qn(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){Tx(null);return}let e=$r.getState().focus;if(e?.sessionId===wt){e.scope===`project`&&!e.projectId&&Tx({...e,projectId:Br.get(wt)?.projectId??null});return}Tx({scope:`project`,sessionId:wt,projectId:Br.get(wt)?.projectId??null})},[wt,Br]);let Vr=Q.useMemo(()=>ut?[]:Jx(zt,ie),[ut,ie,zt]),Hr=Q.useMemo(()=>ut?[]:Vr.map(e=>{let t=Br.get(e.id),n=_(e.directory??null),r={session:e,children:[],worktree:Pt.get(e.id)??null};if(Be&&Jt([r],ze).length===0)return null;let i=t?.secondaryMeta?{projectLabel:t.secondaryMeta.projectLabel,branchLabel:ut?null:t.secondaryMeta.branchLabel}:null;return{node:r,projectId:t?.projectId??null,groupDirectory:t?.groupDirectory??n,secondaryMeta:i}}).filter(e=>e!==null),[Jt,Be,ut,ze,Vr,Br,Pt]),Ur=Q.useMemo(()=>Fr.map(e=>({...e,groups:e.groups.filter(e=>!e.isArchivedBucket)})),[Fr]),Wr=Q.useMemo(()=>{let e=Be?Ur.map(e=>({...e,groups:e.groups.map(e=>({...e,sessions:Pr.get(e)?.filteredNodes??[]}))})):Ur;if(!a)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,Be,Ur,a]),Kr=Q.useMemo(()=>Vy({sections:Wr,foldersMap:Ue,getOrderedGroups:Rr,pinnedSessionIds:ie,sessionOrderByScope:We,sessionOrderActivityByScope:Ge}),[Ue,Rr,Wr,ie,Ge,We]),qr=Q.useMemo(()=>zy({targets:Kr,collapsedProjectIds:j,collapsedGroupKeys:se,collapsedFolderIds:He,visibleSessionCountByGroup:F,defaultVisibleSessionCount:Ly(),hasSessionSearchQuery:Be,alwaysVisibleSessionIds:Tt}),[Tt,He,se,j,Be,Kr,F]),Jr=Q.useMemo(()=>Be||ut?[]:Vr.map((e,t)=>{let n=Br.get(e.id);return{scope:`pinned`,sessionId:e.id,projectId:n?.projectId??null,directory:_(Hn(e))??n?.groupDirectory??null,visibleIndex:t}}),[Be,ut,Vr,Br]),[Yr,Xr]=Q.useState(null),Zr=Q.useCallback(e=>{Xr(t=>t&&t.length===e.length&&t.every((t,n)=>t===e[n])?t:[...e])},[]),Qr=Q.useMemo(()=>{if(!Yr)return Jr;let e=new Set(Yr);return Jr.filter(t=>e.has(t.sessionId))},[Jr,Yr]),ei=Q.useMemo(()=>e?[]:ci({pinnedTargets:Qr,projectTargets:qr}),[e,Qr,qr]),ni=Q.useCallback(e=>{De(`chat`),Ne(!1),e.scope===`project`&&e.projectId&&we(e.projectId),Nn(e.sessionId,e.directory,e.projectId,e.scope)},[Nn,De,we,Ne]);Q.useLayoutEffect(()=>ti({targets:ei,activate:ni}),[ni,ei]);let ii=Q.useMemo(()=>{let e=new Map;return ei.forEach(t=>{let n=hi({scope:t.scope,sessionId:t.sessionId,projectId:t.projectId});n&&e.set(n,mi(ei,t)??0)}),e},[ei]),ai=Q.useMemo(()=>{if(!wt||Be||ut)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 Hr.forEach(e=>t(e.node,e.projectId)),e},[wt,Be,ut,Hr]),oi=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(()=>ri({pinned:Jr,project:qr}),[Jr,qr]),Q.useLayoutEffect(()=>{Or||Tx(Zx({currentSessionId:wt,focus:Dt,pinnedFocuses:ai,projectFocuses:oi,fallbackProjectId:wt?Br.get(wt)?.projectId??null:null}))},[wt,Or,oi,ai,Dt,Br]);let si=Q.useMemo(()=>{let e=Dt?.sessionId?Br.get(Dt.sessionId)?.projectId??null:null;return Qx(Dt,Kr,e)},[Kr,Dt,Br]),li=Q.useRef(null),ui=Q.useRef(null);Q.useEffect(()=>{ui.current&&ui.current!==wt&&(ui.current=null)},[wt]),Q.useLayoutEffect(()=>{if(!si?.projectId)return;let e=si.sessionId,t=Ot.sessionId===e;if(!(!t&&wt!==e)){if(t){if(li.current===Ot.revision)return;li.current=Ot.revision,ui.current=e}else{if(ui.current===e)return;ui.current=e}if(lr(si.projectId),si.groupKey&&ce(e=>{if(!e.has(si.groupKey))return e;let t=new Set(e);return t.delete(si.groupKey),t}),si.folderAncestorIds?.forEach(e=>{let t=Sn.getState();t.collapsedFolderIds.has(e)&&t.toggleFolderCollapse(e)}),si.groupKey&&si.visibleIndex!==void 0){let e=si.visibleIndex+1;I(t=>{if((t.get(si.groupKey)??0)>=e)return t;let n=new Map(t);return n.set(si.groupKey,e),n})}}},[wt,lr,si,Ot]);let di=oy(Q.useMemo(()=>{let e=new Set;return Ur.forEach(t=>{j.has(t.project.id)||t.groups.forEach(n=>{if(se.has(`${t.project.id}:${n.id}`))return;let r=_(n.directory??null),i=n.branch?.trim()||at.get(r||``)?.trim();!r||!i||e.add(Fv(r,i))})}),[...e]},[se,j,at,Ur]));Q.useEffect(()=>{if(!o||!_r||!gr?.connected||!mr)return;let e=[],t=Date.now();if(Ur.forEach(n=>{j.has(n.project.id)||n.groups.forEach(r=>{if(se.has(`${n.project.id}:${r.id}`))return;let i=_(r.directory??null),a=r.branch?.trim()||at.get(i||``)?.trim();if(!i||!a)return;let o=Fv(i,a),s=ey.getState().entries[o],c=!!s?.status?.pr,l=`${i}::${a}`,u=Math.max(s?.lastRefreshAt??0,s?.lastDiscoveryPollAt??0),d=!!(s?.isInitialStatusResolved&&!c&&(!b.current.has(l)||t-u>=fS));(!s||!s.isInitialStatusResolved||d)&&(d&&b.current.add(l),e.push({directory:i,branch:a}))})}),e.length===0)return;let n=new Map;e.forEach(e=>{let t=Fv(e.directory,e.branch,e.remoteName??null);n.has(t)||n.set(t,e)}),n.forEach((e,t)=>{yr(t),br(t,{directory:e.directory,branch:e.branch,remoteName:e.remoteName??null,canShow:!0,github:mr,githubAuthChecked:_r,githubConnected:gr.connected})}),xr([...n.values()],{silent:!0,markInitialResolved:!0})},[j,se,yr,mr,_r,gr?.connected,at,o,xr,Ur,br]);let fi=xv({isDesktopShellRuntime:Ut,projectSections:Nr,projectHeaderSentinelRefs:ge,enabled:o}),pi=_S((t,n=0,r,i,a=!1,o,s=`project`,c)=>(0,$.jsx)(zx,{node:t,depth:n,groupDirectory:r,projectId:i,archivedBucket:a,currentSessionId:wt,pinnedSessionIds:ie,expandedParents:D,hasSessionSearchQuery:Be,normalizedSessionSearchQuery:ze,notifyOnSubtasks:Fe,editingId:x,setEditingId:S,editTitle:C,setEditTitle:w,handleSaveEdit:Un,handleCancelEdit:Gn,toggleParent:In,handleSessionSelect:Rn,handleSessionDoubleClick:Bn,togglePinnedSession:oe,handleShareSession:Kn,copiedSessionId:bn,handleCopyShareUrl:Yn,handleUnshareSession:Xn,openSidebarMenuKey:z,setOpenSidebarMenuKey:B,renamingFolderId:V,getFoldersForScope:Ke,getSessionFolderId:rt,removeSessionFromFolder:$e,addSessionToFolder:Ze,createFolderAndStartRename:$n,openContextPanelTab:Ae,handleDeleteSession:Zn,mobileVariant:e,alwaysShowActions:Kt,renderSessionNode:pi,secondaryMeta:o,renderContext:s,subtreeContainsActive:c?.subtreeContainsActive??pS,subtreeContainsEditing:c?.subtreeContainsEditing??pS,menuOpenSessionId:c?.menuOpenSessionId??null,nodeStructureKey:c?.nodeStructureKey??``,childRenderExtrasFor:c?.childRenderExtrasFor,liveSessionById:Ht,shortcutNumber:ii.get(hi({scope:s,sessionId:t.session.id,projectId:i??null})??``)??null},`${s}:${i??``}:${t.session.id}`)),gi=Q.useCallback(e=>{tr(e),ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[tr]),_i=Q.useCallback(e=>{let t=rr(e);if(t.length===0)return;let n=Vn.getState(),r=t.filter(e=>!n.archivedLoadedDirectories.has(e));r.length>0&&Wn(r)},[rr]),vi=Q.useMemo(()=>{let e=new Map;for(let[t,n]of di)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},[di]),yi=Q.useCallback((t,n,r,i,a,o,s)=>(0,$.jsx)(rb,{group:t,groupKey:n,isArchivedLoading:!!(t.isArchivedBucket&&r&&rr(r).some(e=>bt.has(e))),projectId:r,hideGroupLabel:i,compactBodyPadding:o,hasSessionSearchQuery:Be,normalizedSessionSearchQuery:ze,groupSearchDataByGroup:Pr,visibleSessionCount:F.get(n),collapsedGroups:se,collapsedFolderIds:He,toggleFolderCollapse:tt,renameFolder:Je,deleteFolder:Ye,showDeletionDialog:Ie,setDeleteFolderConfirm:G,renderSessionNode:pi,projectRepoStatus:N,lastRepoStatus:kr.current,showMoreGroupSessions:(e,n,r)=>er(t,e,n,r),resetGroupSessionLimit:tr,mobileVariant:e,alwaysShowActions:Kt,activeProjectId:Se,setActiveProjectIdOnly:we,setActiveMainTab:De,setSessionSwitcherOpen:Ne,openNewSessionDraft:Lt,addSessionToFolder:Ze,createFolderAndStartRename:$n,renamingFolderId:V,renameFolderDraft:U,setRenameFolderDraft:ee,setRenamingFolderId:H,pinnedSessionIds:ie,expandedParents:D,sessionOrderByScope:We,sessionOrderActivityByScope:Ge,onReorderSessions:(e,n,r,i)=>{let a=t.folderScopeKey??_(t.directory??null);a&&it(a,e,n,r,i)},currentSessionId:wt,shortcutTargetSessionId:si?.groupKey===n?si.sessionId:null,shortcutTargetVisibleIndex:si?.groupKey===n?si.visibleIndex??null:null,editingId:x,editTitle:C,openSidebarMenuKey:z,liveSessionById:Ht,runningSessionIds:lt,prVisualStateByDirectoryBranch:vi,onToggleCollapsedGroup:e=>{t.isArchivedBucket&&se.has(e)&&r&&_i(r),gi(e)},dragHandleProps:a,scrollContainerRef:s}),[Be,ze,Pr,bt,rr,F,se,He,tt,Je,Ye,Ie,pi,N,er,tr,e,Kt,Se,we,De,Ne,Lt,Ze,$n,V,U,ie,D,We,Ge,it,wt,si,x,C,z,Ht,lt,vi,gi,_i]),bi=i?null:(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(db,{collapseAllProjects:or,expandAllProjects:sr}),(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:Cn.requestDirectoryDialog,children:(0,$.jsx)(X,{name:`add`,className:`size-4`})})]}),xi=Ut&&Wt&&!ut&&!Be?(0,$.jsx)(`div`,{className:`shrink-0 px-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(nu,{className:`min-w-0 flex-1`}),(0,$.jsx)(au,{className:`ml-auto shrink-0`})]})}):null,Si=!ut&&!Be?(0,$.jsxs)($.Fragment,{children:[e&&Wt?(0,$.jsx)(nu,{}):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:pn,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:mn,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:hn,children:[(0,$.jsx)(X,{name:`ai-agent`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`assistants.title`)})]}):null]}),Hr.length>0?(0,$.jsx)(ob,{items:Hr,renderSessionNode:pi,currentSessionId:wt,editingId:x,openSidebarMenuKey:z,onVisibleSessionIdsChange:Zr}):null]}):null,Ci=!!(V||x||T),{selectionModeEnabled:wi,hasSelection:Ei,selectedIdsSize:Di,bulkScopeIsArchived:Oi,derivedSelectionScope:ki,bulkScopeFolders:Ai,bulkCanRemoveFromFolder:ji,handleExitSelectionMode:Mi,handleBulkMoveToFolder:Ni,handleBulkCreateFolderAndMove:Pi,handleBulkRemoveFromFolder:Fi,handleBulkDelete:Ii,confirmBulkDelete:Li}=Kx({isInlineEditing:Ci,showDeletionDialog:Ie,foldersMap:Ue,addSessionsToFolder:Qe,removeSessionsFromFolders:et,createFolderAndStartRename:Ln,archiveSessions:vn,setBulkDeleteConfirm:K});return(0,$.jsxs)(`div`,{ref:g,className:Y(`oc-session-sidebar relative flex h-full flex-col text-foreground overflow-x-hidden`,e?``:`bg-transparent`),children:[(0,$.jsx)(ib,{hideDirectoryControls:i,isSessionSearchOpen:d,setIsSessionSearchOpen:f,sessionSearchInputRef:y,sessionSearchQuery:m,setSessionSearchQuery:h,hasSessionSearchQuery:Be,searchMatchCount:Ir}),xi,o?(0,$.jsx)(Sb,{topContent:Si,hasLeadingSection:Si!==null&&Hr.length>0,headerAccessory:bi,sectionsForRender:Ur,projectSections:Nr,activeProjectId:Se,showOnlyMainWorkspace:a,hasSessionSearchQuery:Be,emptyState:tn,searchEmptyState:Lr,renderGroupSessions:yi,homeDirectory:ve,collapsedProjects:j,hideDirectoryControls:i,projectRepoStatus:N,isDesktopShellRuntime:Ut,stuckProjectHeaders:fi,mobileVariant:e,alwaysShowActions:Kt,toggleProject:cr,setActiveProjectIdOnly:we,setActiveMainTab:De,setSessionSwitcherOpen:Ne,openNewSessionDraft:Lt,openNewWorktreeDialog:sn,syncProjectSessions:ar,openProjectEditDialog:E,removeProject:Ce,projectHeaderSentinelRefs:ge,projectReorderEnabled:Ar===`manual`,reorderProjects:Ee,projectSortOrder:Ar,getOrderedGroups:Rr,setGroupOrderByProject:ue,openSidebarMenuKey:z,setOpenSidebarMenuKey:B,isInlineEditing:Ci,loadingProjectIds:Er,refreshingProjectIds:Dr,isProjectSessionsSyncing:Or}):null,wi&&Ei?(0,$.jsx)(Gx,{selectedCount:Di,scopeKey:ki,scopeFolders:Ai,archivedBucket:Oi,onMoveToFolder:Ni,onCreateFolderAndMove:Pi,onRemoveFromFolder:Fi,canRemoveFromFolder:ji,onDelete:Ii,onDone:Mi}):null,(0,$.jsx)(hb,{onOpenSettings:fn,onOpenShortcuts:Me,onOpenUpdate:ln,showRuntimeButtons:!ut,showUpdateButton:gn}),c?(0,$.jsx)(As,{open:c,onOpenChange:u,info:Ve.info,downloading:Ve.downloading,downloaded:Ve.downloaded,progress:Ve.progress,error:Ve.error,onDownload:Ve.downloadUpdate,onRestart:Ve.restartToUpdate,runtimeType:Ve.runtimeType}):null,rn?(0,$.jsx)(sy,{open:!0,onOpenChange:e=>{e||E(null)},project:rn,onSave:an}):null,L?(0,$.jsx)(co,{open:!0,onOpenChange:R,onWorktreeCreated:cn}):null,(0,$.jsx)(cc,{}),(0,$.jsx)(Y_,{}),(0,$.jsx)(Hx,{value:te,setValue:W,showDeletionDialog:Ie,setShowDeletionDialog:Le,onConfirm:Mn}),(0,$.jsx)(Wx,{value:ne,setValue:G,onConfirm:Fn}),(0,$.jsx)(Ux,{value:re,setValue:K,showDeletionDialog:Ie,setShowDeletionDialog:Le,onConfirm:Li})]})},yS=e=>e?(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:e}):void 0,bS=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},xS=()=>{let{t:e}=Xe(),[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),[m,h]=Q.useState(!1),[g,_]=Q.useState(!1),[v,y]=Q.useState(new Set),b=yn(e=>e.getWorktreeMetadata),x=yn(e=>e.newSessionDraft),S=yn(e=>e.setNewSessionDraftTarget),C=yn(e=>e.setDraftBootstrapPendingDirectory),w=jt,T=yn(e=>e.archiveSessions),E=p(e=>e.showDeletionDialog),D=p(e=>e.setShowDeletionDialog),O=Pe(e=>e.currentDirectory),k=Pe(e=>e.homeDirectory),A=Pe(e=>e.isHomeReady),j=xn(e=>e.projects),M=xn(e=>e.activeProjectId),{isMobile:N,isTablet:P,hasTouchInput:F}=Ca(),I=N||P||F,L=Q.useMemo(()=>bS((M?j.find(e=>e.id===M)??null:null)?.path??O),[M,O,j]),R=Q.useCallback(e=>{let t=bS(e.projectDirectory)||L;return{id:(j.find(e=>bS(e.path)===t)??null)?.id??`path:${t}`,path:t}},[L,j]),z=g&&v.size>0,B=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]),V=a?.mode===`worktree`,H=V,U=m||!V||!B,ee=m||!V;Q.useEffect(()=>{r||!A||j.length>0||(i(!0),n(!0))},[r,A,j.length]);let te=Q.useCallback(e=>{o({sessions:e.sessions,dateLabel:e.dateLabel,mode:e.mode??`session`,worktree:e.worktree??null})},[]),W=Q.useCallback(()=>{o(null),c([]),u(!1),f(!1),h(!1),_(!1),y(new Set)},[]),ne=Q.useCallback(t=>{if(t.sessions.length===0)return;let n=t.sessions.map(e=>e.id);uc({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(()=>Cn.onDeleteRequest(e=>{if(!E&&(e.mode??`session`)===`session`){ne(e);return}te(e)}),[te,E,ne]),Q.useEffect(()=>Cn.onDirectoryRequest(()=>{n(!0)}),[]),Q.useEffect(()=>{if(!a){c([]),u(!1),f(!1),_(!1),y(new Set);return}let e=a.sessions.map(e=>{let t=b(e.id);return t?{session:e,metadata:t}:null}).filter(e=>!!e);c(e),u(!1),_(!1),y(new Set);let t=new Map;if(a.worktree?.path&&t.set(bS(a.worktree.path),a.worktree),e.forEach(({metadata:e})=>{e.path&&t.set(bS(e.path),e)}),t.size===0){_(!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 ji(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&&(y(r),_(!0),o(t=>{if(!t?.worktree?.path)return t;let n=bS(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=bS(t.metadata.path),r=e.get(n);return r?{session:t.session,metadata:{...t.metadata,status:r}}:t})))})(),()=>{n=!0}},[a,b]),Q.useEffect(()=>{B||u(!1)},[B]);let G=Q.useCallback(async(t,n)=>{let r=l&&B,i=R(t),a=bS(t.path),o=bS(i.path);try{await Fi(i,t,{deleteRemoteBranch:r,deleteLocalBranch:n});let e=bS(x?.directoryOverride);return x?.open&&a&&e===a&&o&&(C(null),S({projectId:i.id,directoryOverride:o},{force:!0})),bS(O)===a&&o&&Pe.getState().setDirectory(o,{showOverlay:!1}),!0}catch(t){return J.error(e(`sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle`),{description:yS(t instanceof Error?t.message:e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),!1}},[B,O,l,R,x?.directoryOverride,x?.open,C,S,e]),re=Q.useCallback((t,n)=>{let r=l&&B;(async()=>{if(!await G(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:yS(i)})})()},[B,l,G,e]),K=Q.useCallback(async()=>{if(a){h(!0);try{let t=H&&d;if(a.sessions.length===0&&V&&a.worktree){re(a.worktree,t),W();return}if(a.sessions.length===1){let t=a.sessions[0];if(V){if(!await w(t.id)){J.error(e(`sessions.sidebar.session.archive.error`)),h(!1);return}qs({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 uc({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(V){let e=await T(n);r=e.archivedIds,i=e.failedIds}else uc({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(V&&a.worktree&&i.length===0&&re(a.worktree,t),V&&r.length>0&&qs({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(V?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:yS(e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),r.length===0)){h(!1);return}}V&&a.sessions.length===1&&a.worktree&&re(a.worktree,t),W()}finally{h(!1)}}},[a,d,w,T,W,H,V,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(V?`space-y-3`:`space-y-2`),children:[a.sessions.length>0&&(0,$.jsxs)(`div`,{className:Y(V?`rounded-lg bg-muted/30 p-3`:`space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3`),children:[V&&(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(V?`mt-2 space-y-1`:`space-y-0.5`),children:[a.sessions.slice(0,5).map(t=>(0,$.jsxs)(`li`,{className:Y(V?`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(!V&&`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(V?`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})})]})]}),V?(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?er(ie.path,k):e(`sessions.sidebar.sessionDialogs.worktree.pathUnavailable`)}),z&&(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=V?B?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U||u(e=>!e)},disabled:U,className:Y(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,U?`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=V?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ee||f(e=>!e)},disabled:ee,className:Y(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,ee?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[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=V?(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:W,disabled:m,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:K,disabled:m,children:e(m?`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:()=>D(!E),className:`inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,"aria-pressed":!E,children:[E?(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:W,disabled:m,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:K,disabled:m,children:m?e(`sessions.sidebar.sessionDialogs.actions.deleting`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`)})]})]}),ue=V?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:[I?(0,$.jsx)(lo,{open:!!a,onClose:()=>{m||W()},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)(cr,{open:!!a,onOpenChange:e=>{if(!e){if(m)return;W()}},children:(0,$.jsxs)(ar,{className:Y(V?`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)(rr,{children:[(0,$.jsxs)(or,{className:Y(V&&`flex items-center gap-2`),children:[V&&(0,$.jsx)(X,{name:`delete-bin`,className:`h-5 w-5`}),ue]}),ae&&(0,$.jsx)(sr,{children:ae})]}),(0,$.jsx)(`div`,{className:Y(V&&`flex-1 min-h-0 overflow-y-auto space-y-2`),children:oe}),(0,$.jsx)(ir,{className:`mt-2 gap-2 pt-1 pb-1`,children:le})]})}),(0,$.jsx)(nc,{open:t,onOpenChange:n})]})},SS=Q.createContext(null),CS=e=>{let t=(0,Rc.c)(3),{children:n,value:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(SS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},wS=go(()=>Fe(()=>import(`./TerminalView-DNyjfkvT.js`).then(e=>({default:e.TerminalView})),__vite__mapDeps([46,1,2,3,4,5,6,7,8,47,35,36,14,48,12,13,34,37,38,39,40,15,16,17,18,20,21,49,50,42,51,52,53,54,55,56]))),TS=go(()=>Fe(()=>import(`./DiagramView-MGGo9iME.js`).then(e=>({default:e.DiagramView})),__vite__mapDeps([57,1,2,3,4,37,8,38,12,5,6,7,13,14,18,15,16,17,50,42,35,36,34,39,40,58,59,60]))),ES=go(()=>Fe(()=>import(`./SettingsView-DxMpVLlt.js`).then(e=>e.n).then(e=>({default:e.SettingsView})),__vite__mapDeps([61,1,2,3,4,5,6,7,8,62,63,35,36,14,37,64,38,9,10,11,12,13,34,39,40,65,66,15,16,17,18,20,67,19,68,69,70,44,49,52,53,54,71,72,73,74,75,76,77,78,21,79,50,33,41,23,24,25,26,27,28,29,30,31,32,80,51,81,82,83,84,85,56,86,87,88,89]))),DS=go(()=>Fe(()=>import(`./SettingsWindow-DfVgTQ4I.js`).then(e=>({default:e.SettingsWindow})),__vite__mapDeps([90,1,4,7,12,5,2,3,6,8,13,14,15,16,17,61,62,63,35,36,37,64,38,9,10,11,34,39,40,65,66,18,20,67,19,68,69,70,44,49,52,53,54,71,72,73,74,75,76,77,78,21,79,50,33,41,23,24,25,26,27,28,29,30,31,32,80,51,81,82,83,84,85,56,86,87,88,89]))),OS=go(()=>Fe(()=>import(`./MultiRunWindow-B-l_O-bd.js`).then(e=>({default:e.MultiRunWindow})),__vite__mapDeps([91,1,4,7,12,5,2,3,6,8,13,14,15,16,17,18,92,35,36,9,10,11,34,37,38,39,40,20,69,68,70,44,49,52,53,54,50,93,82]))),kS=go(()=>Fe(()=>import(`./AssistantView-DvoyOGkx.js`).then(e=>e.n).then(e=>({default:e.AssistantView})),__vite__mapDeps([94,1,2,3,4,5,6,7,8,38,9,10,11,12,13,14,34,35,36,37,39,40,65,62,63,66,15,16,17,18,20,67,19,49,95,64,69,68,70,44,52,53,54,21,73,74,75,76,77,78,79,22,23,24,25,26,27,28,29,30,31,32,50,33,41,80,42,96,93,43,45,97,98,51,99,86]))),AS=()=>{let e=1220,t=p(e=>e.isSidebarOpen),n=p(e=>e.isRightSidebarOpen),r=p(e=>e.isBottomTerminalOpen),i=p(e=>e.setRightSidebarOpen),a=p(e=>e.setBottomTerminalOpen),o=p(e=>e.activeMainTab),s=p(e=>e.setIsMobile),c=p(e=>e.isSessionSwitcherOpen),l=p(e=>e.isSettingsDialogOpen),u=p(e=>e.setSettingsDialogOpen),d=p(e=>e.isMultiRunLauncherOpen),f=p(e=>e.setMultiRunLauncherOpen),{isMobile:m,isTablet:h}=Ca(),g=Q.useRef(!1),_=Q.useRef(!1),v=Q.useRef(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(!1),D=Q.useCallback(e=>{b(e),p.getState().setSessionSwitcherOpen(e)},[]),O=Q.useRef(!1),k=Q.useRef(typeof window>`u`?0:window.innerWidth),A=ns(-k.current),j=(0,Q.useRef)(0),M=ns(k.current),N=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{m&&(j.current=window.innerWidth,N.current=window.innerWidth)},[m]),(0,Q.useEffect)(()=>{if(!m){w(!1);return}y&&w(!0),rs(A,y?0:-j.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[y,m,A]),(0,Q.useEffect)(()=>{if(!m){E(!1);return}O.current=x,x&&E(!0),rs(M,x?0:N.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[m,x,M]),(0,Q.useEffect)(()=>{if(m)return A.on(`change`,e=>{let t=j.current||k.current,n=y||e>-t+.5;w(e=>e===n?e:n)})},[m,A,y]),(0,Q.useEffect)(()=>{if(m)return M.on(`change`,e=>{let t=N.current||k.current,n=x||e<t-.5;E(e=>e===n?e:n)})},[m,x,M]),(0,Q.useEffect)(()=>{m&&!c&&y&&D(!1)},[c,m,y,D]),(0,Q.useEffect)(()=>{if(!m){v.current=!1;return}v.current||(v.current=!0,D(!1),S(!1),p.getState().isRightSidebarOpen&&i(!1))},[m,D,i]),(0,Q.useEffect)(()=>{if(!m||o!==`chat`||y||x||l)return;let e=!1,t,n=r=>{t=window.setTimeout(()=>{if(e)return;let t=yn.getState(),r=p.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,m,l,y,x]),(0,Q.useEffect)(()=>{!m||!l||(D(!1),S(!1),n&&i(!1))},[m,l,n,D,i]),Q.useEffect(()=>{p.getState().isMobile!==m&&s(m)},[m,s]),Q.useEffect(()=>{if(typeof window>`u`)return;let e,t=()=>{e===void 0&&(e=window.requestAnimationFrame(()=>{e=void 0,p.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=p.getState(),n=window.innerWidth,r=window.innerHeight;!m&&!h&&(n<1140?t.isRightSidebarOpen&&(i(!1),g.current=!0):n>=e&&g.current&&(i(!0),g.current=!1),r<640?t.isBottomTerminalOpen&&(a(!1),_.current=!0):r>=700&&_.current&&(a(!0),_.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)}},[m,h,a,i]),Q.useEffect(()=>{if(typeof window>`u`)return;let t=p.subscribe((t,n)=>{let r=window.innerWidth,i=window.innerHeight,a=r>=e,o=i>=700;t.isRightSidebarOpen!==n.isRightSidebarOpen&&a&&(g.current=!1),t.isBottomTerminalOpen!==n.isBottomTerminalOpen&&o&&(_.current=!1)});return()=>{t()}},[m,h,a,i]);let P=Q.useCallback(()=>{y&&D(!1),S(!x)},[y,x,D]),F=Q.useMemo(()=>{switch(o){case`git`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(cf,{isActive:!x})});case`diff`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Ls,{})});case`terminal`:return r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wS,{})});case`files`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(yp,{})});case`context`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Af,{})});case`diagram`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(TS,{})});default:return null}},[o,r,x]),I=o===`schedule`,L=o===`assistant`,R=o===`plan`,z=I||L||R,B=o===`chat`,V=!z&&!l;return(0,$.jsx)(Js,{children:(0,$.jsxs)(`div`,{"data-page-scroll-lock":`true`,className:Y(`main-content-safe-area`,m?`flex h-[100dvh] flex-col`:`relative flex h-[100dvh]`,`bg-background`),children:[(0,$.jsx)(Ug,{}),(0,$.jsx)(P_,{}),(0,$.jsx)(R_,{}),(0,$.jsx)(xS,{}),m?(0,$.jsxs)(CS,{value:{leftDrawerOpen:y,rightDrawerOpen:x,toggleLeftDrawer:()=>{let e=!y;x&&S(!1),D(e)},toggleRightDrawer:P,leftDrawerX:A,rightDrawerX:M,leftDrawerWidth:j,rightDrawerWidth:N,setMobileLeftDrawerOpen:D,setRightSidebarOpen:S},children:[!l&&!z&&(0,$.jsx)(Vl,{onToggleLeftDrawer:()=>{let e=!y;x&&S(!1),D(e)},onToggleRightDrawer:()=>{P()},leftDrawerOpen:y,rightDrawerOpen:x}),(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:[I&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Xs,{})})})}),L&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(kS,{})})})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Xp,{})})})}),V&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!B&&`invisible`),children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Bs,{})})}),V&&F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:F})}),d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Nc,{onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),(0,$.jsx)(ts.div,{className:Y(`absolute inset-0 z-20 bg-sidebar`,!C&&`pointer-events-none invisible`),"data-page-scroll-lock":`true`,style:{x:A},"aria-hidden":!y,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(vS,{mobileVariant:!0,isVisible:C})})}),T&&(0,$.jsx)(ts.div,{className:`absolute inset-0 z-20 bg-sidebar`,"data-page-scroll-lock":`true`,style:{x:M},"aria-hidden":!x,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(cf,{isActive:x})})})})]})}),l&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,style:{paddingTop:`var(--oc-safe-area-top, 0px)`},children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ES,{onClose:()=>u(!1)})})})}),(0,$.jsx)(Yi,{children:(0,$.jsx)(rc,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(lu,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(eu,{isOpen:t,isMobile:m,className:`border-border/50`,topBar:(0,$.jsx)(tu,{}),children:(0,$.jsx)(vS,{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:z?(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:L?(0,$.jsx)(kS,{}):R?(0,$.jsx)(Xp,{}):(0,$.jsx)(Xs,{})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Vl,{}),(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 border-t border-border/50 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:[V&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!B&&`invisible`),children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Bs,{})})}),V&&F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:F})})]}),(0,$.jsx)(Ig,{})]})}),(0,$.jsx)(Kl,{isOpen:r,isMobile:m,children:r?(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wS,{})})}):null})]}),(0,$.jsx)(vu,{isOpen:n,className:`bg-background border-t border-border/50`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(jf,{})})})]})]})})]}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(DS,{open:l,onOpenChange:u})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(OS,{open:d,onOpenChange:f})})]})]})})},jS=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`},MS=e=>{let t=(0,Rc.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},NS=e=>{let t=(0,Rc.c)(43),{title:n,snapshot:r,emptyLabel:i}=e,{t:a}=Xe(),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(FS,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?jS(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)(MS,{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)(MS,{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)(MS,{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)(bi,{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},PS=e=>{let t=(0,Rc.c)(104),{onClose:n}=e,{t:r}=Xe(),[i,a]=Q.useState(`memory`),[o,s]=Q.useState(`idle`),c=yn(IS),l=Lt(LS),u=In(),d=ln(),[f,p]=Q.useState(RS),m,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>Xt(()=>{p(sn())}),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=Fn(),t={};if(!e){g=t;break bb0}let n=e.getCacheBudget?.(),r=n?n.listCanonical().map(zS):u.map(e=>({directory:d,sessionID:e.id}));for(let n of r){if(d&&n.directory!==d)continue;let r=e.getTranscript(Rn(n.directory,n.sessionID));t[n.sessionID]=r.messageOrder.map(e=>r.messagesByID[e]).filter(BS)}g=t}t[2]=d,t[3]=u,t[4]=g}else g=t[4];let _=g,v=ey(VS),[y,b]=Q.useState(HS),[x,S]=Q.useState(US),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(Me()),S(q())};e();let t=window.setInterval(e,500);return()=>window.clearInterval(t)},N=[],t[26]=M,t[27]=N):(M=t[26],N=t[27]),Q.useEffect(M,N);let P,F;t[28]===o?(P=t[29],F=t[30]):(P=()=>{if(o===`idle`)return;let e=window.setTimeout(()=>{s(`idle`)},1500);return()=>window.clearTimeout(e)},F=[o],t[28]=o,t[29]=P,t[30]=F),Q.useEffect(P,F);let I=0,L=0,R=0;for(let e of Object.keys(_)){let t=_[e]??[];L+=t.length;for(let e of t)e.role===`user`?R+=1:e.role===`assistant`&&(I+=1)}let z;t[31]!==I||t[32]!==L||t[33]!==R?(z={assistant:I,total:L,user:R},t[31]=I,t[32]=L,t[33]=R,t[34]=z):z=t[34];let B=z,V;if(t[35]!==c||t[36]!==_||t[37]!==l||t[38]!==u||t[39]!==r){let e;t[41]!==c||t[42]!==_||t[43]!==l||t[44]!==r?(e=e=>{let t=_[e.id]??[],n=0,i=0;for(let e of t)e.role===`user`?i+=1:e.role===`assistant`&&(n+=1);let a=l.get(e.id);return{id:e.id,title:e.title||r(`memoryDebugPanel.common.untitled`),assistantMessageCount:n,messageCount:t.length,userMessageCount:i,isStreaming:a?.isStreaming||!1,isZombie:a?.isZombie||!1,backgroundCount:a?.backgroundMessageCount||0,lastAccessed:a?.lastAccessedAt||0,isCurrent:e.id===c}},t[41]=c,t[42]=_,t[43]=l,t[44]=r,t[45]=e):e=t[45],V=u.map(e).sort(WS),t[35]=c,t[36]=_,t[37]=l,t[38]=u,t[39]=r,t[40]=V}else V=t[40];let H=V,U;t[46]===_?U=t[47]:(U=Object.keys(_),t[46]=_,t[47]=U);let ee=U.length,te;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(te=async()=>{try{let e={generatedAt:new Date().toISOString(),ui:Me(),vscode:q()};await navigator.clipboard.writeText(JSON.stringify(e,null,2)),s(`copied`)}catch{s(`error`)}},t[48]=te):te=t[48];let W=te,ne;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ne={backgroundColor:`color-mix(in srgb, var(--surface-background) 94%, transparent)`},t[49]=ne):ne=t[49];let G;t[50]===i?G=t[51]:(G=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]=G);let re;t[52]===r?re=t[53]:(re=r(`memoryDebugPanel.title`),t[52]=r,t[53]=re);let K;t[54]===re?K=t[55]:(K=(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:re}),t[54]=re,t[55]=K);let ie;t[56]!==G||t[57]!==K?(ie=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[G,K]}),t[56]=G,t[57]=K,t[58]=ie):ie=t[58];let ae;t[59]===i?ae=t[60]:(ae=i===`streaming`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:W,children:(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:()=>{je(),b(Me()),S(q())},children:(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`})})]}):null,t[59]=i,t[60]=ae);let oe;t[61]===n?oe=t[62]:(oe=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]=oe);let se;t[63]!==ae||t[64]!==oe?(se=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ae,oe]}),t[63]=ae,t[64]=oe,t[65]=se):se=t[65];let ce;t[66]!==ie||t[67]!==se?(ce=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[ie,se]}),t[66]=ie,t[67]=se,t[68]=ce):ce=t[68];let le;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(le={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[69]=le):le=t[69];let ue=i===`memory`?`secondary`:`ghost`,de;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>a(`memory`),t[70]=de):de=t[70];let fe;t[71]===r?fe=t[72]:(fe=r(`memoryDebugPanel.tabs.memory`),t[71]=r,t[72]=fe);let pe;t[73]!==ue||t[74]!==fe?(pe=(0,$.jsx)(Z,{size:`sm`,variant:ue,className:`flex-1`,onClick:de,children:fe}),t[73]=ue,t[74]=fe,t[75]=pe):pe=t[75];let me=i===`streaming`?`secondary`:`ghost`,he;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(he=()=>a(`streaming`),t[76]=he):he=t[76];let ge;t[77]===r?ge=t[78]:(ge=r(`memoryDebugPanel.tabs.streaming`),t[77]=r,t[78]=ge);let _e;t[79]!==me||t[80]!==ge?(_e=(0,$.jsx)(Z,{size:`sm`,variant:me,className:`flex-1`,onClick:he,children:ge}),t[79]=me,t[80]=ge,t[81]=_e):_e=t[81];let ve;t[82]!==pe||t[83]!==_e?(ve=(0,$.jsxs)(`div`,{className:`mb-3 flex gap-1 rounded-md p-1`,style:le,children:[pe,_e]}),t[82]=pe,t[83]=_e,t[84]=ve):ve=t[84];let ye;t[85]!==i||t[86]!==ee||t[87]!==o||t[88]!==c||t[89]!==_||t[90]!==B||t[91]!==l||t[92]!==H||t[93]!==u||t[94]!==j||t[95]!==y||t[96]!==r||t[97]!==v||t[98]!==x?(ye=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)(MS,{label:r(`memoryDebugPanel.metric.totalMessages`),value:B.total}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.cachedSessions`),value:`${ee} / ${io.MAX_SESSIONS}`}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.userMessages`),value:B.user}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.assistantMessages`),value:B.assistant})]}),(0,$.jsxs)(`div`,{className:`typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.viewportWindow`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.messagesValue`,{count:Xa()})})]}),(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:io.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)(bi,{outerClassName:`max-h-48`,className:`space-y-1 pr-1`,children:H.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)(Hi,{children:[(0,$.jsx)(zi,{asChild:!0,children:(0,$.jsx)(Z,{size:`sm`,variant:`outline`,className:`typography-meta`,onClick:()=>{u.map(GS),Object.keys(_),H.map(KS),Object.fromEntries(l)},children:r(`memoryDebugPanel.actions.logState`)})}),(0,$.jsx)(Bi,{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:W,children:r(`memoryDebugPanel.actions.copyJson`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.uiMetrics`),value:y.entries.length}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.vscodeMetrics`),value:x.entries.length}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.messageListRenders`),value:j.messageListRender}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.messageListStreamRenders`),value:j.messageListRenderStreaming}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.chatMessageRenders`),value:j.chatMessageRender}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.chatMessageStreamRenders`),value:j.chatMessageRenderStreaming}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.chatMessageStaticDuringStream`),value:j.chatMessageRenderStaticDuringStream}),(0,$.jsx)(MS,{label:r(`memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn`),value:j.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),(0,$.jsx)(NS,{title:r(`memoryDebugPanel.section.uiStreamingMetrics`),snapshot:y,emptyLabel:r(`memoryDebugPanel.section.noUiSamples`)}),x.entries.length>0?(0,$.jsx)(NS,{title:r(`memoryDebugPanel.section.vscodeBridgeMetrics`),snapshot:x,emptyLabel:r(`memoryDebugPanel.section.noVscodeSamples`)}):null]}),t[85]=i,t[86]=ee,t[87]=o,t[88]=c,t[89]=_,t[90]=B,t[91]=l,t[92]=H,t[93]=u,t[94]=j,t[95]=y,t[96]=r,t[97]=v,t[98]=x,t[99]=ye):ye=t[99];let be;return t[100]!==ce||t[101]!==ve||t[102]!==ye?(be=(0,$.jsxs)(Ji,{className:`fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area`,style:ne,children:[ce,ve,ye]}),t[100]=ce,t[101]=ve,t[102]=ye,t[103]=be):be=t[103],be};function FS(e,t){return e+t.count}function IS(e){return e.currentSessionId}function LS(e){return e.sessionMemoryState}function RS(){return sn()}function zS(e){return e.scope}function BS(e){return!!e}function VS(e){return e.totalRequestCount}function HS(){return Me()}function US(){return q()}function WS(e,t){return t.lastAccessed-e.lastAccessed}function GS(e){return{id:e.id,title:e.title}}function KS(e){return{id:e.id,title:e.title,total:e.messageCount,user:e.userMessageCount,assistant:e.assistantMessageCount}}var qS=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=p.getState();if(e)return;let n=Ro();n&&t(n)||w()&&te(`desktop_close_current_window`).catch(e=>{console.warn(`[menu-actions] failed to close current window`,e)})},JS=()=>{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()??``:``},YS=async()=>{let e=JS()||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`)},XS=`openchamber:menu-action`,ZS=`openchamber:check-for-updates`,QS=e=>typeof e?.listen==`function`?`bridge`:`dom`,$S=e=>{let t=yn(e=>e.openNewSessionDraft),n=p(e=>e.toggleCommandPalette),r=p(e=>e.setCommandPaletteOpen),i=p(e=>e.toggleHelpDialog),a=p(e=>e.toggleSidebar),o=p(e=>e.setSessionSwitcherOpen),s=p(e=>e.setActiveMainTab),c=p(e=>e.setSettingsDialogOpen),l=p(e=>e.setSettingsPage),u=p(e=>e.setAboutDialogOpen),d=p(e=>e.toggleRightSidebar),f=p(e=>e.setRightSidebarOpen),m=p(e=>e.setRightSidebarTab),h=p(e=>e.toggleBottomTerminal),g=p(e=>e.setBottomTerminalExpanded),_=as(e=>e.checkForUpdates),{setThemeMode:v}=Qi(),{t:y}=Xe(),b=Q.useRef(!1),x=typeof window>`u`?null:window.__OPENCHAMBER_DESKTOP__,S=QS(x),C=Q.useCallback(()=>{b.current||(b.current=!0,_().then(()=>{let{available:e,error:t}=as.getState();if(t){J.error(y(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}e||J.success(y(`sessions.sidebar.updateCheck.latestVersion`))}).finally(()=>{b.current=!1}))},[_,y]),w=Q.useCallback(()=>{Cn.requestDirectoryDialog()},[]),T=Q.useCallback(e=>{ii(e,yn.getState().currentSessionId,e=>{s(`chat`),o(!1),yn.getState().setCurrentSession(e.sessionId,e.directory)})},[s,o]),E=Q.useCallback(e=>{let{activeProjectId:t,projects:n,setActiveProject:r}=xn.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)},[]),D=Q.useCallback(_=>{switch(_){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),ka();break;case`change-workspace`:w();break;case`close-tab-or-window`:qS();break;case`toggle-right-sidebar`:d();break;case`open-right-sidebar-git`:f(!0),m(`git`);break;case`open-right-sidebar-files`:f(!0),m(`files`);break;case`toggle-terminal`:h();break;case`toggle-terminal-expanded`:g(!p.getState().isBottomTerminalExpanded);break;case`copy`:{let e=new Event(`openchamber:copy`,{cancelable:!0});window.dispatchEvent(e)&&YS();break}case`theme-light`:v(`light`);break;case`theme-dark`:v(`dark`);break;case`theme-system`:v(`system`);break;case`toggle-sidebar`:a();break;case`toggle-memory-debug`:e?.();break;case`zoom-in`:di();break;case`zoom-out`:li();break;case`zoom-reset`:ni();break;case`go-back`:Pe.getState().goBack();break;case`go-forward`:Pe.getState().goForward();break;case`previous-session`:T(-1);break;case`next-session`:T(1);break;case`previous-project`:E(-1);break;case`next-project`:E(1);break;case`help-dialog`:i();break;case`download-logs`:_i().catch(()=>{J.error(`Failed to collect OpenCode status`)})}},[w,E,T,e,t,u,s,o,r,c,l,g,f,m,v,h,n,i,d,a]);Q.useEffect(()=>{if(S!==`dom`)return;let e=e=>{let t=e.detail;t&&D(t)},t=()=>{C()};return window.addEventListener(XS,e),window.addEventListener(ZS,t),()=>{window.removeEventListener(XS,e),window.removeEventListener(ZS,t)}},[D,C,S]),Q.useEffect(()=>{if(S!==`bridge`)return;let e=x?.listen;if(typeof e!=`function`)return;let t=null,n=null;return e(`openchamber:menu-action`,e=>{let t=e?.payload;typeof t==`string`&&D(t)}).then(e=>{t=e}).catch(()=>{}),e(`openchamber:check-for-updates`,C).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{}})()}},[x,D,C,S])},eC=(e,t)=>e<t?-1:+(e>t),tC=e=>JSON.stringify([...e.entries()].map(([e,t])=>[e,[...new Set(t)].sort(eC)]).sort(([e],[t])=>eC(e,t)));async function nC({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 rC=`openchamber:tray-action`,iC=3e4,aC=120,oC=20,sC=()=>{if(typeof window>`u`)return!1;let e=window.__OPENCHAMBER_PLATFORM__;return e===`darwin`||e===`win32`},cC=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},lC=e=>{let t=Array.isArray(e.questions)?e.questions[0]:void 0;return t?.header||t?.question||`Question`},uC=e=>Tt(e),dC=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},fC=(e,t,n,r)=>{if(!e)return``;let i=Dt(t,n,e),a=dC(i?i.path:e),o=it(e),s=o&&r.get(o)||``;if(!s){for(let[e,t]of Uo.getState().directories)if(it(e)===o){s=t.status?.current??``;break}}if(!s)for(let e of n.values()){let t=e.find(e=>it(e.path)===o);if(t?.branch){s=t.branch;break}}return s?`${a} · ${s}`:a},pC=()=>{let{results:e,dropdownProviderIds:t,displayMode:n}=Es.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 hs){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:Zi(e),value:Ki(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}},mC=async()=>{try{if(j())return`Local OpenChamber`;let e=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,t=m();if(t&&se(t,e))return`Local OpenChamber`;let n=(await de()).hosts.find(e=>t?se(t,le(e)):!1);return n?.label?.trim()?ce(n.label.trim()):`Instance`}catch{return``}},hC=()=>{let e=new Map,t=new Map,n=[],r=new Map,i;try{i=Jt()}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(it(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:cC(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:lC(r),directory:a})}}return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}},gC=()=>{let e=Vn.getState().activeSessions,t=new Set;e.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>uC(t)-uC(e)).slice(0,oC).forEach(e=>{let n=Hn(e);n&&t.add(n)});let n=new Map;for(let r of e){if(!r?.id)continue;let e=Hn(r);if(!e||!t.has(e))continue;let i=n.get(e)??[];i.push(r.id),n.set(e,i)}return n},_C=e=>{let t=hC(),n=gt.getState().index.session,r=Vn.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=dn.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=xn.getState().projects,d=yn.getState().availableWorktreesByProject,f=r.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>uC(t)-uC(e)).slice(0,oC).map(e=>{let r=[e.id,...o(e.id)],i=Hn(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:fC(i,u,d,t.branchByDirectory)}}),m=t.approvals.map(e=>({...e,sessionTitle:i.get(e.sessionId)||``})),h=p.getState(),g=0;if(h.dockBadgeEnabled)for(let e of r)!e?.id||e.parentID||(n.unseenCount[e.id]??0)>0&&(g+=1);return{sessions:f,approvals:m,instanceName:e,usage:pC(),dockBadgeCount:g}},vC=()=>{Q.useEffect(()=>{if(!sC()||!w())return;let e=!1,t=``,n=null,r=``,i=()=>{if(e)return;let n=_C(r),i=JSON.stringify(n);i!==t&&(t=i,te(`desktop_tray_update`,n))};mC().then(t=>{e||(r=t,i())});let a=null,o=``,s=()=>{let e=wt.getState();return e.isConnected&&e.connectionPhase===`connected`},c=()=>{if(a)return a;let t=gC();return o=tC(t),a=nC({targets:t,isReady:s,concurrency:2,isDisposed:()=>e,fetchStatus:e=>Ne.getSessionStatusForDirectory(e).catch(()=>null),applySnapshot:(e,t,n)=>{mn(e,t,[...n])}}).finally(()=>{a=null;let t=gC();!e&&s()&&tC(t)!==o&&c()}),a},l=()=>{e||n!==null||(n=window.setTimeout(()=>{n=null,i()},aC))},u=new Map,d=()=>{if(e)return;let t;try{t=Jt()}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=Jt().subscribeRegistry(()=>{d(),l()})}catch{}d();let m=gt.subscribe(()=>l()),h=Vn.subscribe(()=>{l(),s()&&tC(gC())!==o&&c()}),g=xn.subscribe(()=>l()),_=yn.subscribe(()=>l()),v=Uo.subscribe(()=>l()),y=p.subscribe(()=>l()),b=dn.subscribe(()=>l()),x=s(),S=wt.subscribe(()=>{let e=s();e&&!x&&c(),x=e});x&&c();let C=Es.subscribe(()=>l());Es.getState().loadSettings().then(()=>{if(e)return;let{dropdownProviderIds:t,results:n}=Es.getState();t.length>0&&t.some(e=>!n.some(t=>t.providerId===e))&&Es.getState().fetchAllQuotas()});let T=window.setInterval(()=>{let e=Es.getState();e.autoRefresh&&e.dropdownProviderIds.length>0&&e.fetchAllQuotas()},Math.max(3e4,Es.getState().refreshIntervalMs||6e4)),E=window.setInterval(()=>{d(),i()},iC);return i(),()=>{e=!0,n!==null&&window.clearTimeout(n),window.clearInterval(E),window.clearInterval(T),m(),h(),g(),_(),v(),y(),b(),S(),C(),f?.();for(let e of u.values())e();u.clear()}},[]),Q.useEffect(()=>{if(!sC()||typeof window>`u`)return;let e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!=`function`)return;let t=e=>{e.type===`respond-permission`&&Vt(e.sessionId,e.id,e.response).catch(()=>{J.error(`Failed to respond to permission request`)})},n=null;return e(rC,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{}}},[])},yC=`/api/notifications/stream`,bC=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),xC=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}},SC=e=>{let t=(0,Rc.c)(3),n=e?.enabled??!0,r,a;t[0]===n?(r=t[1],a=t[2]):(r=()=>{if(!n||A()||!I()||typeof window>`u`||typeof EventSource>`u`)return;let e=new EventSource(i().sse(yC));return e.onmessage=CC,()=>{e.close()}},a=[n],t[0]=n,t[1]=r,t[2]=a),Q.useEffect(r,a)};function CC(e){let t;try{t=JSON.parse(e.data)}catch{return}let n=p.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!==`always`&&bC())return;let r=xC(t);r&&oe()?.notifications?.notifyAgentCompletion(r)}var wC=`pwa-install-toast-shown`,TC=`pwa-install-toast-dismissed`,EC=()=>{let e=(0,Rc.c)(6),{browserTab:t}=ys(),{t:n}=Xe(),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`||!I()||!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=c(),l=h();dc({dismissed:s.getItem(TC),sessionShown:l.getItem(wC),hasActiveToast:n!==null})&&(l.setItem(wC,`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:()=>{c().setItem(TC,`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)},DC=()=>typeof window>`u`?``:window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,OC=()=>!M()||r()===`local`,kC=e=>({id:`local`,label:`Local`,url:e}),AC=async()=>{if(!M()||OC())return{ok:!0};let e=DC(),t=await ue().catch(()=>``),n=await Wi({host:kC(e),localApiOrigin:e,localClientToken:t});return n.ok?{ok:!0}:{ok:!1,reason:n.reason}},jC=100,MC=1e4,NC=null,PC=()=>{NC&&=(NC.unsubscribe?.(),NC.openTimer!==null&&clearTimeout(NC.openTimer),NC.timeoutTimer!==null&&clearTimeout(NC.timeoutTimer),null)};function FC(){PC()}var IC=(e,t)=>{p.getState().setActiveMainTab(`chat`),yn.getState().setCurrentSession(e,t)};function LC(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(OC()){IC(t,n);return}PC(),AC().then(e=>{if(!e.ok){En(t,`missing-directory`);return}if(r()===`local`){IC(t,n);return}let i=!1,a=()=>{i||(i=!0,PC(),IC(t,n))},o=l(e=>{if(e.runtimeKey!==`local`)return;o(),NC&&(NC.unsubscribe=null);let t=setTimeout(()=>{NC&&(NC.openTimer=null),a()},jC);NC&&(NC.openTimer=t)});NC={unsubscribe:o,openTimer:null,timeoutTimer:setTimeout(()=>{i||(PC(),En(t,`missing-directory`))},MC)}})}var RC=({open:e,onOpenChange:t})=>{let{t:n}=Xe(),[r,i]=Q.useState(null),[a,o]=Q.useState(null),[s,c]=Q.useState(!1),[l,u]=Q.useState(!1),[d,f]=Q.useState(null),[p,m]=Q.useState(!1),[h,g]=Q.useState(!1),[_,v]=Q.useState(()=>wn()),y=Ge(e=>{cn(e),v(e)}),b=Ge(async()=>{if(!h){g(!0);try{let{outcome:e,eventCount:t}=await Qt();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{g(!1)}}});Q.useCallback(async()=>{},[d,s,!1,n]),Q.useEffect(()=>{e&&(async()=>{try{let e=await V(`/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 Je())})()},[e]),Q.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await V(`/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(()=>{f(null),m(!1)},[e,!1]);let x=r;return(0,$.jsx)(cr,{open:e,onOpenChange:t,children:(0,$.jsx)(ar,{className:`max-w-xs p-6`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,$.jsx)(ua,{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:[x&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openChamberVersionLabel`,{version:x})}),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)(fs,{itemId:`about.diagnostics`,checked:_,onChange:y,label:n(`settings.openchamber.about.diagnostics.label`),ariaLabel:n(`settings.openchamber.about.diagnostics.label`)}),_&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void b(),children:n(h?`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`)})]})})})},zC=(e,t)=>{let n=e.get(t);return typeof n==`string`&&n.trim()||null},BC=(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},VC=()=>{let e=cs(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=zC(t,`code`),a=ls(t),o=us(t),s=zC(t,`error`),c=zC(t,`error_description`);if(s){o&&V(`/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 V(`/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 V(`/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 V(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(BC(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`})})]})})},HC=()=>{let e=(0,Rc.c)(16),t=Vn(UC),n=Vn(WC),r=Vn(GC),i=Vn(KC),{t:a}=Xe(),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 UC(e){return e.startupSyncProgress.active}function WC(e){return e.startupSyncProgress.phase}function GC(e){return e.startupSyncProgress.completed}function KC(e){return e.startupSyncProgress.total}var qC=(e,t,n,r=350)=>n?Math.max(0,r-Math.max(0,t-e)):null;function JC(e){let t=(0,Rc.c)(21),{transition:n,ready:r}=e,{t:i}=Xe(),a=Ui(),[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=qC(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)(ua,{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 YC=go(()=>Fe(()=>import(`./OnboardingScreen-CUsgwt4y.js`).then(e=>({default:e.OnboardingScreen})),__vite__mapDeps([100,1,5,2,3,4,6,7,8,62,12,13,14,15,16,17,18,20,70]))),XC=36e5,ZC=12e5,QC=()=>{let e=(0,Rc.c)(3),t=p(aw),n=p(ow),r;return e[0]!==t||e[1]!==n?(r=(0,$.jsx)(RC,{open:t,onOpenChange:n}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r},$C=e=>{let t=(0,Rc.c)(21),{onRetry:n,isRetrying:r}=e,{t:i}=Xe(),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},ew=e=>e?e.replace(/\\/g,`/`).replace(/\/+$/g,``):``,tw=()=>{if(typeof window>`u`||!qa())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`}},nw=()=>typeof window>`u`?!1:window.location.pathname===xs,rw=e=>{let t=(0,Rc.c)(22),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=e,a=Pe(sw),o=yn(cw),s=yn(lw),c=ro(),l=Q.useRef(null),u;t[0]===n.directory?u=t[1]:(u=ew(n.directory),t[0]=n.directory,t[1]=u);let d=u,f;t[2]===a?f=t[3]:(f=ew(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)(ai,{embeddedBackgroundWorkEnabled:i}),t[14]=i,t[15]=g);let _;t[16]===n.readOnly?_=t[17]:(_=(0,$.jsx)(Bs,{readOnly:n.readOnly}),t[16]=n.readOnly,t[17]=_);let v;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(yi,{}),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 iw({apis:e}){Q.useEffect(()=>{De(`App:mounted`),ke()},[]);let t=wt(e=>e.initializeApp),n=wt(e=>e.isInitialized),i=wt(e=>e.isConnected),a=yn(e=>e.error),o=yn(e=>e.clearError),s=yn(e=>e.currentSessionId),c=yn(e=>!!e.newSessionDraft?.open),f=Pe(e=>e.currentDirectory),m=Pe(e=>e.setDirectory),h=Pe(e=>e.isSwitchingDirectory),[g,_]=Q.useState(!1),v=ws(e=>e.refreshStatus),[y,x]=Q.useState(()=>e.runtime.isVSCode),[w,T]=Q.useState(!1),[D,M]=Q.useState(!1),[N,P]=Q.useState(0),[F,I]=Q.useState(0),[L,R]=Q.useState({epoch:0,startedAt:0}),[z,B]=Q.useState(!1),H=Q.useRef(!1),U=p(e=>e.wideChatLayoutEnabled),ee=p(e=>e.mobileKeyboardMode),W=Q.useMemo(()=>A(),[]),ne=Vn(e=>e.hasCachedSessionIndex),G=Vn(e=>e.hasHydratedSessionIndex),re=$a(e=>e.setPlanModeEnabled),[ie,oe]=Q.useState(()=>ae()),[se,ce]=Q.useState(()=>{let e=k();return e===null?null:C({isDesktopShell:!0,bootOutcome:e})}),le=Q.useRef(!1),ue=Q.useMemo(()=>tw(),[]),de=!ue||w,fe=Q.useMemo(()=>nw(),[]);Q.useEffect(()=>(Oe(g),()=>{Oe(!1)}),[g]),Q.useEffect(()=>{d(ee)},[ee]),Q.useEffect(()=>{x(e.runtime.isVSCode)},[e.runtime.isVSCode]),Q.useEffect(()=>{let e=Xr(e=>{u(e)&&(W&&R(e=>({epoch:e.epoch+1,startedAt:Date.now()})),ic(e),I(e=>e+1),M(!1),P(e=>e+1))}),t=l(t=>e.schedule(t));return()=>{t(),e.cancel()}},[W]);let pe=yt(e=>{let t=r();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(ue)return;let e=!1;return _t().then(()=>{if(e)return;let t=r(),n=Object.values(yt.getState().runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t);for(let e of n)vt(e.originalSessionID)}),()=>{e=!0}},[pe,ue,F]),Q.useEffect(()=>(document.documentElement.classList.toggle(`wide-chat-layout`,U),()=>{document.documentElement.classList.remove(`wide-chat-layout`)}),[U]),Q.useEffect(()=>(O(e),()=>O(null)),[e]),Q.useEffect(()=>{if(ue)return;let t=!1;return _t().then(()=>{t||v(e.github,{force:!0})}),()=>{t=!0}},[e.github,ue,v]),pi();let me=ie===`valid`,he=se?.screen===`main`;Q.useEffect(()=>{if(!de||!b({isDesktopShell:W,isInitialized:W&&he?ne||n&&G:n,bootOutcomeKnown:me,bootViewIsMain:he}))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)}},[de,W,n,me,he,ne,G]),Q.useEffect(()=>{if(!W||ie!==`malformed`)return;let e=document.getElementById(`initial-loading`);e&&(e.textContent=`Desktop startup failed — please restart the app.`)},[W,ie]),Q.useEffect(()=>{if(!de||W)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)}},[de,W,n]),Q.useEffect(()=>{if(!de)return;let e=!1;return(async()=>{if(await _t(),e)return;let t=await V(`/health`,{method:`GET`}).catch(()=>null);if(!t||!t.ok||e)return;let n=await t.json().catch(()=>null);if(!n||e)return;let r=n.planModeExperimentalEnabled;re(r===!0||r===1||r===`1`||r===`true`)})(),()=>{e=!0}},[de,re]),Q.useEffect(()=>{if(!de||y)return;let e=!1;return _t().then(()=>{if(!e)return t()}),()=>{e=!0}},[de,t,y]),Q.useEffect(()=>{if(!de||y||n)return;let e=!0,t,r=0,i=1e3,a=async()=>{if(!e)return;if(r>=10){M(!0);return}let n=wt.getState();if(n.isInitialized){M(!1);return}if(r+=1,await _t(),!e)return;await n.initializeApp();let o=wt.getState();if(!e)return;if(o.isInitialized){M(!1);return}if(r>=10){M(!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)}},[de,N,n,y]),Q.useEffect(()=>{de&&n&&M(!1)},[de,n]),Q.useEffect(()=>{if(!de||!D)return;let e=document.getElementById(`initial-loading`);if(e){e.classList.add(`fade-out`);let t=setTimeout(()=>{e.remove()},300);return()=>clearTimeout(t)}},[de,D]),Jr({enabled:de&&!y,source:`startupRecovery`}),Q.useEffect(()=>{h||y||i&&Ne.setDirectory(f)},[f,h,i,y]),Q.useEffect(()=>{if(!ue||typeof window>`u`)return;let e=e=>{let t=e?.visible===!0;T(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:Ia},window.location.origin),()=>{window.removeEventListener(`message`,t),n.__openchamberSetEmbeddedVisibility===e&&delete n.__openchamberSetEmbeddedVisibility}},[ue]),Q.useEffect(()=>{!ue?.directory||y||f!==ue.directory&&m(ue.directory,{showOverlay:!1})},[f,ue,y,m]),Q.useEffect(()=>{if(!ue||typeof window>`u`)return;let e=e=>{e.storageArea===window.localStorage&&e.key===`ui-store`&&p.persist.rehydrate()};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}},[ue]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;LC(t??{})};return window.addEventListener(`openchamber:open-session`,e),()=>{FC(),window.removeEventListener(`openchamber:open-session`,e)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=Pe.getState().currentDirectory,{activeProjectId:t,projects:n}=xn.getState(),r=n.find(e=>e.id===t)??null;te(`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=yn.getState().currentSessionId;e&&Rt(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;p.getState().setActiveMainTab(`chat`),p.getState().setSessionSwitcherOpen(!1),yn.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=xn.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`||!de||!n||h||le.current||(le.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event(`openchamber:app-ready`)))},[de,n,h]),jr({enabled:de}),SC({enabled:de}),EC(),Kr(),oc(),$S(Ge(()=>{_(e=>!e)})),Q.useEffect(()=>{if(!n||!E()||H.current)return;H.current=!0;let e=!1,t=null,r=null;as.getState().subscribeDesktopUpdateEvents().then(t=>{if(e){t();return}r=t});let i=()=>{let e=as.getState();e.checking||e.checkForUpdates()},a=n=>{t=window.setTimeout(()=>{e||(document.visibilityState===`visible`&&i(),a(XC))},n)},o=()=>{if(e||document.visibilityState!==`visible`)return;let t=as.getState().lastChecked;t!=null&&Date.now()-t<ZC||i()};return a(0),window.addEventListener(`focus`,o),()=>{e=!0,t!==null&&window.clearTimeout(t),window.removeEventListener(`focus`,o),r&&r()}},[n]),vC(),Q.useEffect(()=>{if(ue)return;let e=e=>{$n(e)&&e.shiftKey&&!e.altKey&&(e.code===`KeyD`||e.key.toLowerCase()===`d`)&&(e.preventDefault(),_(e=>!e))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ue]),Q.useEffect(()=>{ue||a&&setTimeout(()=>o(),5e3)},[o,ue,a]),Q.useEffect(()=>{if(!W||ie!==`not-injected`)return;let e=!1,t=0,n=()=>{if(e)return;t++;let r=ae();if(r!==`not-injected`){if(e=!0,oe(r),r===`valid`){let e=k();e&&ce(C({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}},[W,ie]);let ge=Ge(async()=>{if(S({isDesktopShell:A(),isDesktopLocalOriginActive:j()})){await K();return}window.location.reload()}),_e=Ge(async()=>{if(!z){M(!1),B(!0);try{await _t(),await wt.getState().initializeApp()}finally{B(!1)}wt.getState().isInitialized||P(e=>e+1)}}),ve=e=>{if(e.screen===`recovery`)return e.variant};if(W&&se&&se.screen!==`main`){if(se.screen===`chooser`)return(0,$.jsx)(Yi,{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)(YC,{mode:`first-launch`,onCliAvailable:ge,onChooseRemote:()=>{}})})})});let e=ve(se),t=se.screen===`recovery`&&`url`in se?se.url:void 0;return(0,$.jsx)(Yi,{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)(YC,{mode:`recovery`,recoveryVariant:e,recoveryHostUrl:t,recoveryHostLabel:void 0,onCliAvailable:ge})})})})}if(ue)return zt(),(0,$.jsx)(Yi,{children:(0,$.jsx)(vn,{sdk:Ne.getSdkClient(),directory:f||``,bootstrapDirectory:!(c&&s===null),children:(0,$.jsx)(Ar,{apis:e,children:(0,$.jsx)(Vi,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-background`,children:(0,$.jsx)(rw,{embeddedSessionChat:ue,isVSCodeRuntime:y,embeddedBackgroundWorkEnabled:de})})})})},F)});if(fe)return(0,$.jsx)(Yi,{children:(0,$.jsx)(VC,{})});if(D&&!n&&!y&&!ue)return(0,$.jsx)(Yi,{children:(0,$.jsx)($C,{onRetry:()=>{_e()},isRetrying:z})});let ye=!n&&!W;return(0,$.jsx)(Yi,{children:(0,$.jsx)(vn,{sdk:Ne.getSdkClient(),directory:f||``,bootstrapDirectory:!(c&&s===null),children:(0,$.jsx)(Ar,{apis:e,children:(0,$.jsx)(Qu,{children:(0,$.jsx)(Vi,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsxs)(`div`,{className:W?`h-full text-foreground bg-transparent`:`h-full text-foreground bg-background`,children:[(0,$.jsx)(ai,{embeddedBackgroundWorkEnabled:de}),(0,$.jsx)(Qs,{}),(0,$.jsx)(Ks,{}),(0,$.jsx)(AS,{}),W&&(0,$.jsx)(JC,{transition:L,ready:n&&i}),(0,$.jsx)(HC,{}),(0,$.jsx)(yi,{}),!ye&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Vs,{}),(0,$.jsx)(QC,{}),g&&(0,$.jsx)(PS,{onClose:()=>_(!1)})]})]})})})})},F)})}function aw(e){return e.isAboutDialogOpen}function ow(e){return e.setAboutDialogOpen}function sw(e){return e.currentDirectory}function cw(e){return e.currentSessionId}function lw(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 uw=typeof window<`u`&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw Error(`Runtime APIs not provided for legacy UI entrypoint.`)})();et(),A()&&Bn(),Wr({runtimeKey:r(),initializeAppearance:re,syncSettings:U,applyDirectory:Or,startWatchers:()=>{Fr(),Yr(),qr()},onError:(e,t)=>{console.error(e===`appearance`?`[main] appearance init failed:`:`[main] settings init failed:`,t)}});var dw=document.getElementById(`root`);if(!dw)throw Error(`Root element not found`);(0,Lc.createRoot)(dw).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Ir,{children:(0,$.jsx)(Ye,{children:(0,$.jsx)(zr,{children:(0,$.jsx)(fi,{children:(0,$.jsx)(Rr,{children:(0,$.jsx)(iw,{apis:uw})})})})})})}));
|
|
172
|
+
Now write the final fused answer.`,synthetic:!0}],directory:i??Ne.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 gx(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:ir,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 _x=e(Ee(),1),vx=null,yx=!1,bx=(e,t=ei.getState().focus)=>e===null?null:typeof e==`string`?t?.sessionId===e?t:$r(e):e,xx=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))},Sx=()=>{vx&&=(xx(vx),null)},Cx=(e,t)=>{Sx(),jn(!0);let n=bx(e);if(!n)return;yx=!0;let r;try{r=Bn(n.sessionId)}finally{yx=!1}vx={commit:t,commitFrame:null,fallbackTimer:null,focus:n,intent:r,paintFrame:null,scheduled:!1},(0,_x.flushSync)(()=>{ei.getState().setFocus(n)}),typeof window<`u`&&(vx.fallbackTimer=window.setTimeout(()=>{wx(n)},150))},wx=e=>{let t=vx,n=bx(e);if(!t||!yi(t.focus,n)||t.scheduled)return;t.scheduled=!0,typeof window<`u`&&t.fallbackTimer!==null&&(window.clearTimeout(t.fallbackTimer),t.fallbackTimer=null);let r=()=>{vx===t&&on()===t.intent&&(vx=null,gn(),t.commit())};if(typeof window>`u`){r();return}t.commitFrame=window.requestAnimationFrame(()=>{vx===t&&on()===t.intent&&(t.paintFrame=window.requestAnimationFrame(r))})},Tx=e=>{if(vx)return;let t=ei.getState();t.setFocus(bx(e,t.focus))};un(e=>{if(yx)return;let t=vx;if(t?.intent===e)return;t&&Sx();let n=ei.getState();n.setFocus(bx(e.sessionId,n.focus))});var Ex=e=>{let t=[],n=e=>{e.children.forEach(e=>{t.push(e.session.id),n(e)})};return n(e),t},Dx=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)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:c,"aria-label":n,onPointerDown:a,onMouseDown:o,onClick:s,onKeyDown:Bx,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)(Vi,{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)(Ui,{children:[d,f]}),t[15]=d,t[16]=f,t[17]=p):p=t[17],p}),Ox=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=Yb(),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)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:y,"aria-label":h,onPointerDown:c,onMouseDown:l,onClick:_,onKeyDown:Vx,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)(Vi,{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)(Ui,{children:[S,C]}),t[21]=S,t[22]=C,t[23]=w):w=t[23],w}),kx=Q.memo(function(e){let t=(0,zc.c)(3),{number:n}=e;if(!dx())return null;let r=rr()?`⌘${n}`:`Ctrl+${n}`,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Oa,{"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 Ax(e){let{t}=Xe(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:s=!1,pinnedSessionIds:c,expandedParents:l,hasSessionSearchQuery:u,normalizedSessionSearchQuery:d,editingId:f,setEditingId:p,editTitle:h,setEditTitle:g,handleSaveEdit:y,handleCancelEdit:b,toggleParent:x,handleSessionSelect:S,handleSessionDoubleClick:C,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:U=`project`,subtreeContainsActive:ee,subtreeContainsEditing:W,menuOpenSessionId:ne,childRenderExtrasFor:G,liveSessionById:re,shortcutNumber:K=null}=e,ie=!!H?.projectLabel,ae=!!H?.branchLabel,oe=Py(e=>e.displayMode),se=Q.useMemo(()=>v(),[]),ce=oe===`minimal`||se,le=Q.useMemo(()=>w(),[]),ue=Q.useContext(po),de=se?`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`,fe=se,pe=U===`pinned`,me=!pe&&!s&&!z,we=`h-5 w-5`,Te=`h-3.5 w-3.5`,Ee=(me||pe?1:0)+ +!!fe+1,De=Ee>=3?`group-hover:pr-18 group-focus-within:pr-18`:Ee>=2?`group-hover:pr-12 group-focus-within:pr-12`:`group-hover:pr-7 group-focus-within:pr-7`,Oe=Ee>=2?`pr-12`:`pr-8`,ke=Q.useRef(!1),Ae=Q.useRef(!1),[je,Me]=Q.useState(!1),Ne=Q.useRef(f);Ne.current=f;let q=Q.useRef(null),Pe=Q.useRef(y);Pe.current=y;let[Fe,Ie]=Q.useState(h),[Le,Re]=Q.useState(null),ze=Q.useRef(Fe);ze.current=Fe;let Be=Q.useRef(null),Ve=Q.useRef(null),He=Q.useRef(null),Ue=n.session,We=re.get(Ue.id)??Ue,qe=!!We.metadata?.openchamber?.assistant,Je=_(Ue.directory??null)??_(i??null),Ye=ct(Je??void 0,{bootstrap:!1}),Ze=io(),Qe=Ib(e=>e.enabled),$e=Ib(Q.useMemo(()=>e=>e.selectedIds.has(Ue.id),[Ue.id])),et=Ib(e=>e.toggleSelected),tt=Ib(e=>e.setRange),[nt,rt]=Q.useState(!1),[it,ot]=Q.useState(!0),[st,ut]=Q.useState(!1),ft=`${U}:${s?`archived`:`active`}:${Ue.id}`,pt=Ft(Q.useMemo(()=>e=>!!e.sessionMemoryState.get(lt(Ue.id))?.isZombie,[Ue.id])),mt=Ht(Ue.id),ht=In(Ue.id,Je??void 0,{bootstrap:!1}),gt=bn(Ue.id,Je??void 0,{bootstrap:!1}),_t=Q.useMemo(()=>({scope:U,sessionId:Ue.id,projectId:a??null}),[a,U,Ue.id]),vt=Q.useMemo(()=>gi(_t)??``,[_t]),yt=Q.useRef(null),bt=ei(Q.useMemo(()=>e=>yi(e.focus,_t),[_t]));Q.useLayoutEffect(()=>{bt&&(yt.current?.scrollIntoView({block:`nearest`,inline:`nearest`}),wx(_t))},[bt,_t]);let St=We.title||t(`sessions.sidebar.session.untitled`),Ct=We.metadata?.openchamber?.titleRefresh,wt=typeof Ct?.lastError==`string`?Ct.lastError:null,Tt=typeof Ct?.failedAt==`number`?Ct.failedAt:null;Q.useEffect(()=>{!wt||Tt===null||(Re(null),console.warn(`[session-title] generation failed for ${Ue.id}: ${wt}`))},[Ue.id,wt,Tt]),Q.useEffect(()=>{if(Le===null)return;if(St!==Le){Re(null);return}let e=window.setTimeout(()=>Re(null),3e4);return()=>window.clearTimeout(e)},[Le,St]);let Et=n.children.length>0||!!We.hasChildren,Dt=c.has(Ue.id),Ot=ft,kt=u?!0:l.has(Ot),At=!!We.parentID,jt=U===`pinned`,Mt=dt(Ue.id)>0&&!At,Nt=xt(We)||Date.now(),Pt=Ar(Nt),It=ci(Nt),[Lt,Rt]=Q.useState(!1),zt=Lt,Bt=Q.useMemo(()=>Mc(We.title)!==null,[We.title]),[Ut,Wt]=Q.useState(!1),Gt=Q.useMemo(()=>Ex(n).length,[n]),Kt=Ge(e=>{let t=Je??``,n=(dn()??Jt(t,Ye)).getTranscript(en(t,e)),r=Ye.getState().session.find(t=>t.id===e)?.revert?.messageID;return at({sessionID:e,messages:Xt(n),parts:n.partsByMessageID,revertMessageID:r}).list}),qt=Ge(async e=>{let n=[],r=0;for(let i of e)try{await Ze.ensureSessionRenderable(i.session.id);let e=Kt(i.session.id),a=i.session.title||t(`sessions.sidebar.session.export.untitledSubagent`),o=i.session.agent,s=await qt(i.children);r+=s.skipped,n.push({title:a,agent:o,records:e,children:s.children})}catch{r+=Ex(i).length+1}return{children:n,skipped:r}}),Yt=Ge(e=>{e<=0||J.warning(t(e===1?`sessions.sidebar.session.export.skippedSubtaskSingle`:`sessions.sidebar.session.export.skippedSubtaskMany`,{count:e}))}),Zt=Ge(async e=>{if(!Je){J.error(t(`sessions.sidebar.session.export.nothingToExport`));return}await Ze.ensureSessionRenderable(Ue.id);let r=Kt(Ue.id);if(r.length===0){J.error(t(`sessions.sidebar.session.export.nothingToExport`));return}let i,a=0;if(e&&n.children.length>0){let e=await qt(n.children);i=e.children,a=e.skipped}let o=kb(r,We.title??null,i),s=Pb(We.title??null),c=await jb(o,s);if(c){J.success(t(`sessions.sidebar.session.export.success`),{action:{label:t(Nb()),onClick:()=>{Mb(c).then(e=>{e||J.error(t(`sessions.sidebar.session.export.failedRevealPath`))})}}}),Yt(a);return}Ab(o,s),J.success(t(`sessions.sidebar.session.export.success`)),Yt(a)}),Qt=Ge(async()=>{if(n.children.length>0){ot(!0),rt(!0);return}await Zt(!1)}),$t=Ge(()=>{Je&&te(`desktop_open_session_mini_chat_window`,{sessionId:Ue.id,directory:Je,apiBaseUrl:m(),clientToken:o()}).catch(e=>{console.warn(`[session-sidebar] failed to open mini chat window`,e)})});Ke(Ve,()=>{Pe.current(ze.current)},f===Ue.id),Q.useLayoutEffect(()=>{if(f!==Ue.id){Be.current===Ue.id&&(Be.current=null);return}Be.current!==Ue.id&&(Be.current=Ue.id,Ie(h),queueMicrotask(()=>He.current?.select()))},[f,h,Ue.id]);let tn=Ge(e=>{if(!e&&q.current){let{id:e,title:t}=q.current;q.current=null,p(e),g(t)}}),nn=Ge(e=>{Rt(e)}),rn=Ge(e=>{e.preventDefault(),e.stopPropagation()}),an=Ge(e=>{e.preventDefault(),e.stopPropagation()}),on=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ue.id)}),sn=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ue,{archivedBucket:s})}),cn=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),R(Ue,{archivedBucket:s,hardDelete:!0,skipConfirm:!0})}),ln=Ge(e=>{e.preventDefault(),e.stopPropagation(),A(null),T(Ue.id)}),un=Ge(()=>{let e=mt?.type??`idle`;!Je||st||e===`busy`||e===`retry`||(ut(!0),(async()=>{try{await Ze.refreshSessionTranscript(Ue.id,{directory:Je}),J.success(t(`sessions.sidebar.session.menu.refreshTranscriptSuccess`))}catch{J.error(t(`sessions.sidebar.session.menu.refreshTranscriptFailed`))}finally{ut(!1)}})())}),fn=Ge(e=>{e.preventDefault(),e.stopPropagation()}),pn=Ge(e=>{e.preventDefault(),e.stopPropagation()}),mn=Ge(e=>{e.preventDefault(),e.stopPropagation(),ue?.vscode?.executeCommand(`openchamber.openSessionInEditor`,Ue.id,St)}),hn=Ge(e=>{if(ke.current){ke.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=Ib.getState().anchorId,r=new Map;r.set(Ue.id,Ex(n)),tt(t,Ue.id,e,Je??null,r);return}et(Ue.id,Je??null,Ex(n));return}S(Ue.id,Je,a,U)}),gn=Ge(e=>{e.defaultPrevented||e.target?.closest(`button, a, input, [role="menuitem"], [role="menu"]`)||hn(e)}),_n=Ge(e=>{(e.button===2||e.button===0&&e.ctrlKey&&!Qe)&&(ke.current=!0)}),vn=Ge(e=>{Ae.current=e.pointerType===`mouse`,z&&e.pointerType===`touch`&&Me(!0)}),yn=Ge(e=>{z&&e.pointerType===`touch`&&Me(!1)}),xn=Ge(e=>{e.key!==`Enter`||!Ae.current||(e.preventDefault(),e.stopPropagation(),C(Ue.id,St))}),Sn=Ge(e=>{if(hn(e),!Ae.current)return;let t=e.currentTarget;window.requestAnimationFrame(()=>{Ae.current=!0,t.focus({preventScroll:!0})})}),Cn=Ge(()=>{Ae.current=!1}),wn=Ge(e=>{if(!Ae.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(),Ae.current=!1)});if(f===Ue.id){let e=async()=>{Re(St),b();try{await Vt(Ue.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:Hr(r)},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:He,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:t(`sessions.sidebar.session.menu.rename`),onKeyDown:e=>{if(e.stopPropagation(),e.key===`Escape`){b();return}}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},"aria-label":t(`sessions.sidebar.session.rename.smartTitle`),title:t(`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":t(`sessions.sidebar.session.rename.save`),title:t(`sessions.sidebar.session.rename.save`),className:`shrink-0 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(X,{name:`check`,className:`size-3.5`})})]}),ce?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:[Et&&!jt&&!At?(0,$.jsx)(`span`,{className:`inline-flex items-center justify-center flex-shrink-0`,children:kt?(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:Pt}),ie?(0,$.jsx)(`span`,{className:`truncate`,children:H?.projectLabel}):null,ae?(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]})})]})},Ue.id)}let Tn=mt?.type??`idle`,En=Tn===`busy`||Tn===`retry`,Dn=Le!==null||Ct?.isGenerating===!0,On=ht.length,kn=gt.length>0,An=kn||En||!kn&&!En&&Mt&&!bt,jn=!B||se,Mn=kn?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":t(`sessions.sidebar.session.status.questionRequired`),title:t(`sessions.sidebar.session.status.questionRequired`),children:(0,$.jsx)(X,{name:`question`,className:`h-3.5 w-3.5 text-primary`})}):En?(0,$.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center`,"aria-label":t(`sessions.sidebar.session.status.active`),title:t(`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":t(`sessions.sidebar.session.status.unread`),title:t(`sessions.sidebar.session.status.unread`),children:(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-[var(--status-info)]`})}),Nn=!jt&&!B&&Et&&Dt,Pn=!jt&&Dt,Fn=(0,$.jsx)(X,{name:`pushpin-2-fill`,className:`h-3 w-3 flex-shrink-0 text-foreground`,"aria-label":t(`sessions.sidebar.session.status.pinned`)}),Ln=Pn?(0,$.jsx)(`span`,{className:Y(`pointer-events-none absolute inline-flex h-3.5 w-3.5 items-center justify-center transition-opacity`,ce?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,Nn?`opacity-100 group-hover:opacity-0 group-focus-within:opacity-0`:``),style:{left:Hr(Math.max(0,r-1))},children:Fn}):null,Rn=!jt&&!At&&Et,zn=Rn&&!B,Bn=Hr(Math.max(0,r-1)),Vn=()=>{!kt&&n.children.length===0&&Ze.loadChildren(Ue.id,Je).catch(()=>void 0),x(Ot)},Hn=Rn?(0,$.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),e.currentTarget.blur(),Vn()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),Vn())},style:{minWidth:14,minHeight:14,left:Bn},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`,ce?`top-1/2 -translate-y-1/2`:`top-[14.5px] -translate-y-1/2`,zn?`opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto`:``),"aria-label":t(kt?`sessions.sidebar.session.subsessions.collapse`:`sessions.sidebar.session.subsessions.expand`),children:kt?(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,Un=pt?(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4 text-status-warning`}):null,Wn=(0,$.jsx)(be,{children:(0,$.jsx)(ve,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ge,{"data-slot":`dropdown-menu-content`,finalFocus:()=>!(j||Ne.current),style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(na,`min-w-[180px]`),children:(({Item:e,Separator:n,Sub:r,SubTrigger:i,SubContent:a})=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(e,{onClick:()=>{q.current={id:Ue.id,title:St}},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`pencil-ai`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.rename`)]}),(0,$.jsxs)(e,{onClick:()=>T(Ue.id),className:`[&>svg]:mr-1`,children:[Dt?(0,$.jsx)(X,{name:`unpin`,className:`mr-1 h-4 w-4`}):(0,$.jsx)(X,{name:`pushpin`,className:`mr-1 h-4 w-4`}),t(Dt?`sessions.sidebar.session.menu.unpin`:`sessions.sidebar.session.menu.pin`)]}),We.share?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onClick:()=>{We.share?.url&&O(We.share.url,Ue.id)},className:`[&>svg]:mr-1`,children:D===Ue.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`check`,className:`mr-1 h-4 w-4`,style:{color:`var(--status-success)`}}),t(`sessions.sidebar.session.menu.copied`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`file-copy`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.copyLink`)]})}),(0,$.jsxs)(e,{onClick:()=>k(Ue.id),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`link-unlink-m`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.unshare`)]})]}):(0,$.jsxs)(e,{onClick:()=>E(We),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`share-2`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.share`)]}),(0,$.jsxs)(e,{onClick:()=>{Qt()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`download`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.exportMarkdown`)]}),(0,$.jsxs)(e,{disabled:!Je||En||st,onClick:()=>{un()},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`refresh`,className:Y(`mr-1 h-4 w-4`,st&&`animate-spin`)}),t(`sessions.sidebar.session.menu.refreshTranscript`)]}),Bt?(0,$.jsxs)(e,{onClick:()=>Wt(!0),className:`[&>svg]:mr-1`,children:[(0,$.jsx)(gx,{className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.session.menu.runFusion`)]}):null,Je&&!s?(()=>{let o=M(Je),s=N(Je,Ue.id);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(n,{}),(0,$.jsxs)(r,{children:[(0,$.jsxs)(i,{className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`folder`,className:`h-4 w-4`}),t(`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:t(`sessions.sidebar.folders.none`)}):o.map(t=>(0,$.jsxs)(e,{onClick:()=>{s===t.id?P(Je,Ue.id):F(Je,t.id,Ue.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)(n,{}),(0,$.jsxs)(e,{onClick:()=>{let e=I(Je);e&&F(Je,e.id,Ue.id)},children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.folders.newFolderEllipsis`)]}),s?(0,$.jsxs)(e,{onClick:()=>{P(Je,Ue.id)},className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(X,{name:`close`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.folders.removeFromFolder`)]}):null]})]})]})})():null,se?null:(0,$.jsxs)(e,{disabled:!Je,onClick:()=>{Je&&L(Je,{mode:`chat`,dedupeKey:`session:${Ue.id}`,label:St,sessionTitleFallback:St})},className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`chat-thread`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:t(`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:t(`sessions.sidebar.session.menu.betaBadge`)})]}),le?(0,$.jsxs)(e,{disabled:!Je,onClick:$t,className:`[&>svg]:mr-1`,children:[(0,$.jsx)(X,{name:`window`,className:`mr-1 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:t(`sessions.sidebar.session.menu.openMiniChatWindow`)})]}):null,(0,$.jsx)(n,{}),s?null:(0,$.jsxs)(e,{className:`[&>svg]:mr-1`,onClick:()=>R(Ue,{archivedBucket:s}),children:[(0,$.jsx)(X,{name:`inbox-archive`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.bulkActions.archive`)]}),(0,$.jsxs)(e,{className:`text-destructive focus:text-destructive [&>svg]:mr-1`,onClick:()=>R(Ue,{archivedBucket:s,hardDelete:!0}),children:[(0,$.jsx)(X,{name:`delete-bin`,className:`mr-1 h-4 w-4`}),t(`sessions.sidebar.bulkActions.delete`)]})]}))({Item:({className:e,...t})=>(0,$.jsx)(_e,{className:Y(ua,e),...t}),Separator:({className:e,...t})=>(0,$.jsx)(he,{className:Y(ia,e),...t}),Sub:ye,SubTrigger:({className:e,children:t,...n})=>(0,$.jsxs)(xe,{className:Y(oa,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)(be,{children:(0,$.jsx)(ve,{className:`app-region-no-drag z-50`,children:(0,$.jsx)(ge,{"data-slot":`dropdown-menu-sub-content`,style:{backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},className:Y(na,e),...n,children:t})})})})})})});return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(wy,{sessionId:Ue.id,sessionDirectory:Je??null,sessionTitle:St,children:(0,$.jsxs)(Se,{open:Lt,onOpenChange:nn,onOpenChangeComplete:tn,children:[(0,$.jsxs)(Ce,{render:(0,$.jsx)(`div`,{ref:yt,"data-session-row":Ue.id,"data-session-scope":Je??``,"data-session-focus-scope":U,"data-session-focus-key":vt,"data-session-project-id":a??``,"data-session-archived":s?`1`:`0`,"data-session-depth":r,onClick:gn,onMouseLeave:wn,className:Y(`group relative my-0.5 flex cursor-pointer items-center rounded-lg py-1.5 pr-2`,bt&&!$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)]`,!bt&&!$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:[Ln,Hn,(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,style:{paddingLeft:Hr(r)},children:(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onPointerDown:vn,onPointerUp:yn,onPointerCancel:yn,onMouseDown:_n,onKeyDown:xn,onBlur:Cn,onClick:Sn,onDoubleClick:e=>{e.stopPropagation(),C(Ue.id,St)},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`,je&&`bg-[color-mix(in_srgb,var(--surface-foreground)_8%,transparent)]`,B?se?De:Oe:De),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`,Dn&&`animate-text-shimmer`),"aria-busy":Dn||void 0,children:Rr(St,d)}),qe?(0,$.jsx)(X,{name:`ai-agent`,className:`size-3 shrink-0 text-muted-foreground`,"aria-label":`Assistant`}):null,On>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:t(`sessions.sidebar.session.status.permissionRequired`),"aria-label":t(`sessions.sidebar.session.status.permissionRequired`),children:[(0,$.jsx)(X,{name:`shield`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`leading-none`,children:On})]}):null,An?(0,$.jsx)(`span`,{className:Y(`inline-flex shrink-0 items-center justify-center transition-none`,jn?Y(`group-hover:hidden group-focus-within:hidden`,zt?`hidden`:``):zt?`invisible`:``),children:Mn}):null,K?(0,$.jsx)(kx,{number:K}):null]})})}),se?null:(0,$.jsx)(Vi,{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:St}),(0,$.jsx)(`div`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:It})]}),ie?(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,ae?(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]})})]})})}),Un&&!z?(0,$.jsx)(`div`,{className:Y(`absolute top-1/2 -translate-y-1/2 z-10`,ce?`right-0`:`right-[30px]`),children:Un}):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`,zt||B&&!se?`opacity-100`:Y(`opacity-0`,de)),children:[me?(0,$.jsx)(Dx,{pinLabel:t(`sessions.sidebar.session.menu.pin`),buttonSizeClass:we,iconSizeClass:Te,onPointerDown:rn,onMouseDown:an,onPin:on}):null,pe?(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{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`,we),"aria-label":t(`sessions.sidebar.session.actions.pinned`),onPointerDown:rn,onMouseDown:an,onClick:ln,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`pushpin-2-fill`,className:Te})})}),(0,$.jsx)(Vi,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:t(`sessions.sidebar.session.actions.pinned`)})]}):null,fe?(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{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`,we),"aria-label":t(`sessions.sidebar.session.actions.openInEditor`),onPointerDown:fn,onMouseDown:pn,onClick:mn,onKeyDown:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:Te})})}),(0,$.jsx)(Vi,{side:`top`,sideOffset:4,className:`rounded-md px-1.5 py-0.5 typography-micro`,children:t(`sessions.sidebar.session.actions.openInEditor`)})]}):null,(0,$.jsx)(Ox,{archiveLabel:t(`sessions.sidebar.bulkActions.archive`),deleteLabel:t(`sessions.sidebar.bulkActions.delete`),deleteOnly:s===!0,buttonSizeClass:we,iconSizeClass:Te,revealClassName:ce&&!B&&!zt?Y(`opacity-0`,de):`opacity-100`,onPointerDown:rn,onMouseDown:an,onArchive:sn,onDelete:cn})]})]}),Wn]})}),!jt&&Et&&kt?n.children.map(e=>{let t=G?G(e):{subtreeContainsActive:ee,subtreeContainsEditing:W,menuOpenSessionId:ne,nodeStructureKey:``};return V(e,r+1,Je??i,a,s,void 0,U,t)}):null,(0,$.jsx)(ur,{open:nt,onOpenChange:rt,children:(0,$.jsxs)(sr,{showCloseButton:!1,className:`max-w-sm gap-5`,children:[(0,$.jsxs)(ar,{children:[(0,$.jsx)(cr,{children:t(`sessions.sidebar.session.export.dialog.title`)}),(0,$.jsx)(lr,{children:t(Gt===1?`sessions.sidebar.session.export.dialog.descriptionSingle`:`sessions.sidebar.session.export.dialog.descriptionMany`,{count:Gt})})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 typography-ui-label cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:it,onChange:e=>ot(e.target.checked),className:`h-4 w-4 rounded border-border accent-primary`}),t(`sessions.sidebar.session.export.dialog.includeSubtasks`)]}),(0,$.jsxs)(or,{children:[(0,$.jsx)(Z,{type:`button`,onClick:()=>rt(!1),variant:`outline`,size:`sm`,children:t(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{type:`button`,onClick:()=>{rt(!1),Zt(it)},size:`sm`,children:t(`sessions.sidebar.session.export.dialog.confirm`)})]})]})}),Bt?(0,$.jsx)(hx,{session:We,open:Ut,onOpenChange:Wt}):null]},Ue.id)}var jx=e=>_(e.session.directory??null),Mx=(e,t)=>(e?.projectLabel??null)===(t?.projectLabel??null)&&(e?.branchLabel??null)===(t?.branchLabel??null),Nx=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},Px=e=>e.menuOpenSessionId??Nx(e),Fx=(e,t,n)=>t?n.has(e.node.session.id)?!0:jy(e.node,t):!1,Ix=(e,t,n,r,i)=>{if(e.session.id!==t.session.id)return!0;let a=i(e);if(n.has(a)!==r.has(a)||e.children.length!==t.children.length)return!0;for(let a=0;a<e.children.length;a+=1)if(Ix(e.children[a],t.children[a],n,r,i))return!0;return!1},Lx=(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&&ky(a)!==ky(o)||e.children.length!==t.children.length)return!0;for(let i=0;i<e.children.length;i+=1)if(Lx(e.children[i],t.children[i],n,r))return!0;return!1},Rx=(e,t)=>{if(e.hasSessionSearchQuery||t.hasSessionSearchQuery)return!1;let n=e.archivedBucket?`archived`:`active`,r=t.archivedBucket?`archived`:`active`;return Ix(e.node,t.node,e.expandedParents,t.expandedParents,t=>`${e.renderContext??`project`}:${n}:${t.session.id}`)||Ix(e.node,t.node,e.expandedParents,t.expandedParents,e=>`${t.renderContext??`project`}:${r}:${e.session.id}`)},zx=Q.memo(Ax,(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||jx(e.node)!==jx(t.node)||!Mx(e.secondaryMeta,t.secondaryMeta)||e.liveSessionById!==t.liveSessionById&&Lx(e.node,t.node,e.liveSessionById,t.liveSessionById)||e.pinnedSessionIds!==t.pinnedSessionIds&&Ix(e.node,t.node,e.pinnedSessionIds,t.pinnedSessionIds,e=>e.session.id)||e.expandedParents!==t.expandedParents&&Rx(e,t)||e.currentSessionId!==t.currentSessionId&&(Fx(e,e.currentSessionId,e.subtreeContainsActive)||Fx(t,t.currentSessionId,t.subtreeContainsActive))||e.editingId!==t.editingId&&(Fx(e,e.editingId,e.subtreeContainsEditing)||Fx(t,t.editingId,t.subtreeContainsEditing))||e.editTitle!==t.editTitle&&(Fx(e,e.editingId,e.subtreeContainsEditing)||Fx(t,t.editingId,t.subtreeContainsEditing))||e.copiedSessionId!==t.copiedSessionId&&(jy(e.node,e.copiedSessionId)||jy(t.node,t.copiedSessionId)))return!1;if(e.openSidebarMenuKey!==t.openSidebarMenuKey){let n=Px(e),r=Px(t);if(jy(e.node,n)||jy(t.node,r))return!1}if(e.renamingFolderId!==t.renamingFolderId){let n=Px(e),r=Px(t);if(jy(e.node,n)||jy(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 Bx(e){return e.stopPropagation()}function Vx(e){return e.stopPropagation()}function Hx(e){let t=(0,zc.c)(71),{t:n}=Xe(),{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=ur,g=!!r,t[13]===i?_=t[14]:(_=e=>{e||i(null)},t[13]=i,t[14]=_),u=sr,m=!1,h=`max-w-sm gap-5`,l=ar;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)(cr,{children:a}),t[18]=a,t[19]=p),c=lr,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)(or,{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 Ux(e){let t=(0,zc.c)(57),{t:n}=Xe(),{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)(cr,{children:d}),t[10]=d,t[11]=g);let _;t[12]===p?_=t[13]:(_=(0,$.jsx)(lr,{children:p}),t[12]=p,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,$.jsxs)(ar,{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)(or,{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)(sr,{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)(ur,{open:m,onOpenChange:h,children:M}),t[53]=m,t[54]=M,t[55]=h,t[56]=N):N=t[56],N}function Wx(e){let t=(0,zc.c)(36),{t:n}=Xe(),{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)(cr,{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)(lr,{children:u}),t[9]=u,t[10]=d);let f;t[11]!==l||t[12]!==d?(f=(0,$.jsxs)(ar,{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)(or,{children:[h,_]}),t[26]=_,t[27]=h,t[28]=v):v=t[28];let y;t[29]!==v||t[30]!==f?(y=(0,$.jsxs)(sr,{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)(ur,{open:o,onOpenChange:s,children:y}),t[32]=o,t[33]=s,t[34]=y,t[35]=b):b=t[35],b}var Gx=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}=Xe(),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)(ta,{children:[(0,$.jsxs)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(ca,{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)(Vi,{side:`top`,sideOffset:4,children:(0,$.jsx)(`p`,{children:f(`sessions.sidebar.bulkActions.moveToFolder`)})})]}),(0,$.jsxs)(ea,{align:`end`,className:`min-w-[180px]`,children:[i.length===0?(0,$.jsx)(la,{disabled:!0,className:`text-muted-foreground`,children:f(`sessions.sidebar.folders.none`)}):i.map(e=>(0,$.jsx)(la,{onClick:()=>o(e.id),children:(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})},e.id)),(0,$.jsx)(sa,{}),(0,$.jsxs)(la,{onClick:s,children:[(0,$.jsx)(X,{name:`add`,className:`mr-1 h-4 w-4`}),f(`sessions.sidebar.folders.newFolderEllipsis`)]}),l?(0,$.jsxs)(la,{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)(Bi,{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)(Vi,{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)(Ui,{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)(Bi,{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)(Vi,{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)(Ui,{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},Kx=e=>{let{t}=Xe(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,addSessionsToFolder:a,removeSessionsFromFolders:o,createFolderAndStartRename:s,archiveSessions:c,setBulkDeleteConfirm:l}=e,u=Ib(e=>e.enabled),d=Ib(e=>e.selectedIds.size),f=d>0,p=Ib(e=>e.selectedIds),m=Ib(e=>e.scopeKey),h=Q.useCallback(()=>{Ib.getState().toggleMode()},[]),g=Q.useCallback(()=>{Ib.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(_)dc({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&&Js({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}))}Ib.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(),Ib.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=Ib.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;Ib.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}},qx=e=>{let t=e.time?.created;return typeof t==`number`&&Number.isFinite(t)?t:0},Jx=(e,t)=>e.filter(e=>t.has(e.id)).sort((e,t)=>qx(t)-qx(e)),Yx=(e,t,n)=>{let r=[],i=new Set,a=e=>{let t=_(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},Xx=(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},Zx=({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=Xx(r,e,o,i)??{scope:`project`,sessionId:e,projectId:i};return!a||t.scope===`project`?s:Xx(n,e,o,i)??s};function Qx(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 $x=`oc.sessions.projectCollapse`,eS=`oc.sessions.groupOrder`,tS=`oc.sessions.groupCollapse`,nS=`oc.sessions.activeSessionByProject`,rS=`oc.sessions.expandedParents.v2`,iS=`oc.sessions.expandedParents`,aS=y(c()),oS=e=>{try{let t=aS.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}},sS=e=>{try{let t=aS.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}},cS=e=>{try{let t=aS.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}},lS=(e,t,n)=>{let r=new Set;for(let t of e){let e=_(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=_(t.path)?.toLowerCase();e&&r.add(e)}return r},uS=(e,t,n)=>{if(e.time?.archived)return!0;let r=_(fn(e))?.toLowerCase();return r?t.size===0?n?.allowEmptyDirectorySet??!0:t.has(r):n?.allowUnknownDirectory??!0},dS=3e5,fS=new Set,pS=new Set,mS=[],hS=new Map,gS=e=>{let t=Q.useRef(e);return t.current=e,Q.useCallback((...e)=>t.current(...e),[])},_S=({mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:a=!1,isVisible:o=!0})=>{let{t:s}=Xe(),[c,u]=Q.useState(!1),[d,f]=Q.useState(!1),[m,h]=Q.useState(``),g=Q.useRef(null),y=Q.useRef(null),b=Q.useRef(new Set),[x,S]=Q.useState(null),[C,w]=Q.useState(``),[T,E]=Q.useState(null),[D,O]=Q.useState(new Set),k=Q.useMemo(()=>aS,[]),[j,M]=Q.useState(new Set),[N,P]=Q.useState(new Map),[F,I]=Q.useState(new Map),L=p(e=>e.isNewWorktreeDialogOpen),R=p(e=>e.setNewWorktreeDialogOpen),[z,B]=Q.useState(null),[V,H]=Q.useState(null),[U,ee]=Q.useState(``),[te,W]=Q.useState(null),[ne,G]=Q.useState(null),[re,K]=Q.useState(null),ie=hn(),ae=Yt(),[oe,se]=Q.useState(()=>oS(tS)),[ce,le]=Q.useState(()=>cS(eS)),[ue,de]=Q.useState(()=>sS(nS));Q.useEffect(()=>l(e=>{t(e)&&(se(oS(tS)),le(cS(eS)),de(sS(nS)),M(oS($x)),O(oS(rS)))}),[]);let[fe,pe]=Q.useState(new Map),he=Q.useRef(new Map),ge=Q.useRef(0),_e=Pe(e=>e.homeDirectory),ve=Pe(e=>e.currentDirectory),ye=Pe(e=>e.setDirectory),be=mn(e=>e.projects),xe=mn(e=>e.activeProjectId),Se=mn(e=>e.removeProject),Ce=mn(e=>e.setActiveProjectIdOnly),we=mn(e=>e.updateProjectMeta),Te=mn(e=>e.reorderProjectsById),Ee=p(e=>e.setActiveMainTab),De=p(e=>e.activeMainTab),Oe=Yn(),ke=p(e=>e.openContextPanelTab),Ae=p(e=>e.setSettingsDialogOpen),je=p(e=>e.toggleHelpDialog),Me=p(e=>e.setSessionSwitcherOpen),Ne=p(e=>e.setScheduledTasksDialogOpen),q=p(e=>e.notifyOnSubtasks),Fe=p(e=>e.showDeletionDialog),Ie=p(e=>e.setShowDeletionDialog),Le=Vo(m,120),Re=Q.useMemo(()=>Le.trim().toLowerCase(),[Le]),ze=Re.length>0,Be=os(me(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=Qt(e=>e.collapsedFolderIds),He=Qt(e=>e.foldersMap),Ue=Qt(e=>e.sessionOrderByScope),We=Qt(e=>e.sessionOrderActivityByScope),Ge=Qt(e=>e.getFoldersForScope),Ke=Qt(e=>e.createFolder),qe=Qt(e=>e.renameFolder),Je=Qt(e=>e.deleteFolder),Ye=Qt(e=>e.addSessionToFolder),Ze=Qt(e=>e.addSessionsToFolder),Qe=Qt(e=>e.removeSessionFromFolder),$e=Qt(e=>e.removeSessionsFromFolders),et=Qt(e=>e.toggleFolderCollapse),tt=Qt(e=>e.cleanupSessions),nt=Qt(e=>e.getSessionFolderId),rt=Qt(e=>e.reorderSessions);cv({isSessionSearchOpen:o&&d,setIsSessionSearchOpen:f,sessionSearchInputRef:y,sessionSearchContainerRef:g});let it=Q.useMemo(()=>new Map,[]),at=bt({enabled:o}),ot=Ct({enabled:o}),st=pn(e=>o?e.statusById:hS),ct=Q.useMemo(()=>{if(!o)return pS;let e=new Set;for(let[t,n]of Object.entries(ot))(n.type===`busy`||n.type===`retry`)&&e.add(t);for(let t of st.keys())ot[t]===void 0&&e.add(t);return e},[st,o,ot]),lt=Q.useMemo(()=>v(),[]),ut=vn(e=>e.fullCatalogSessionIds),dt=vn(e=>e.fullCatalogGeneration),ft=vn(e=>e.status),pt=vn(e=>e.activeSessions),mt=vn(e=>e.archivedSessions),ht=vn(e=>e.loadingDirectories),gt=vn(e=>e.refreshingDirectories),_t=vn(e=>e.archivedLoadingDirectories),vt=Q.useDeferredValue(pt),yt=Q.useDeferredValue(mt),xt=Tn(e=>e.currentSessionId),St=Q.useMemo(()=>{if(!xt||ct.has(xt))return ct;let e=new Set(ct);return e.add(xt),e},[xt,ct]),wt=ei(e=>e.focus),Tt=Q.useSyncExternalStore(un,on,on),Et=Tn(e=>!!e.newSessionDraft?.open),Dt=Tn(e=>e.setCurrentSession),Ot=Tn(e=>e.updateSessionTitle),kt=Tn(e=>e.shareSession),At=Tn(e=>e.unshareSession),jt=Tn(e=>e.worktreeMetadata),Mt=Tn(e=>e.availableWorktreesByProject),Nt=Tn(e=>e.openNewSessionDraft),Pt=Q.useCallback(e=>{Nt(e),lt&&window.dispatchEvent(new CustomEvent(`openchamber:navigate`,{detail:{view:`chat`}}))},[lt,Nt]),Ft=Q.useMemo(()=>lS(be,Mt,{includeWorktrees:!lt}),[Mt,lt,be]),It=Q.useMemo(()=>{let e=new Map(at.map(e=>[e.id,e])),t=vt.map(t=>{let n=e.get(t.id);return n?On(n,t):t}),n=new Set(t.map(e=>e.id));return at.forEach(e=>{n.has(e.id)||t.push(e)}),t.filter(e=>uS(e,Ft,{allowUnknownDirectory:!lt,allowEmptyDirectorySet:!lt}))},[vt,lt,Ft,at]),Lt=Q.useMemo(()=>at.map(e=>{let t=_(e.directory??null)??``;return`${e.id}:${e.title??``}:${+!!e.time?.archived}:${t}`}).join(`|`),[at]),Rt=Q.useRef(at);Q.useEffect(()=>{Rt.current=at},[Lt,at]);let zt=Q.useMemo(()=>new Map(at.map(e=>[e.id,e])),[at]);Q.useEffect(()=>{let e=null,t=Cn(t=>{t.type===`scheduled-task-ran`&&(e&&clearTimeout(e),e=setTimeout(()=>{let e=mn.getState().projects.find(e=>e.id===t.projectId),n=_(e?.path??null);if(!n)return;let r=[n];(Tn.getState().availableWorktreesByProject.get(n)??[]).forEach(e=>{let t=_(e.path);t&&r.push(t)}),cn(r,Rt.current)},500))});return()=>{e&&clearTimeout(e),t()}},[]);let Bt=Q.useMemo(()=>A(),[]),Vt=ys(e=>e.sidebarBrandName.trim().length>0),{isTablet:Ht}=wa(),Ut=e||Ht,{buildGroupSearchText:Wt,filterSessionNodesForSearch:Gt,buildGroupedSessions:Kt}=sv({homeDirectory:_e,worktreeMetadata:jt,pinnedSessionIds:ie,gitBranches:it,isVSCode:lt}),{scheduleCollapsedProjectsPersist:qt,hasRestoredProjectCollapse:Jt}=hv({isVSCode:lt,safeStorage:k,keys:{sessionExpanded:rS,sessionExpandedLegacy:iS,projectCollapse:$x,groupOrder:eS,projectActiveSession:nS,groupCollapse:tS},groupOrderByProject:ce,activeSessionByProject:ue,collapsedGroups:oe,setExpandedParents:O,setCollapsedProjects:M}),Xt=Q.useMemo(()=>[...It].sort((e,t)=>Nr(e,t,ie)),[It,ie]),Zt=Q.useMemo(()=>{let e=new Map;return Xt.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)=>Nr(e,t,ie))),e},[Xt,ie]),$t=(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`)})]}),en=Q.useMemo(()=>be.find(e=>e.id===T)??null,[be,T]),tn=Q.useCallback(e=>{T&&we(T,{label:e.label,icon:e.icon,color:e.color,iconBackground:e.iconBackground,defaultModel:e.defaultModel??null})},[T,we]),nn=Q.useCallback(()=>{R(!0)},[R]),an=Q.useCallback((t,n)=>{if(Ee(`chat`),e&&Me(!1),n?.sessionId){Dt(n.sessionId,t);return}Nt({directoryOverride:t,preserveDirectoryOverride:!0})},[e,Nt,Ee,Dt,Me]),sn=Q.useCallback(()=>{let e=os.getState();if(e.available&&e.info){u(!0);return}Be.checkForUpdates().then(()=>{let{available:e,error:t}=os.getState();if(t){J.error(s(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}if(!e){J.success(s(`sessions.sidebar.updateCheck.latestVersion`));return}u(!0)})},[s,Be]),ln=Q.useCallback(()=>{e&&Me(!1),Ae(!0)},[e,Me,Ae]),dn=Q.useCallback(()=>{Ee(`chat`),Nt(),e&&Me(!1)},[e,Nt,Ee,Me]),gn=Q.useCallback(()=>{if(!e){Ee(`schedule`);return}Ne(!0),Me(!1)},[e,Ee,Ne,Me]),_n=Q.useCallback(()=>{Xn(),e&&Me(!1)},[e,Me]),bn=Be.available&&(Be.runtimeType===`desktop`||Be.runtimeType===`web`),xn=Tn(e=>e.archiveSession),Sn=Tn(e=>e.archiveSessions),{copiedSessionId:wn,handleSessionSelect:En,handleSessionDoubleClick:Dn,handleSaveEdit:An,handleCancelEdit:jn,handleShareSession:Mn,handleCopyShareUrl:Nn,handleUnshareSession:Pn,handleDeleteSession:Fn,confirmDeleteSession:In}=lv({activeProjectId:xe,currentDirectory:ve,currentSessionId:xt,mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:d,sessionSearchQuery:m,setSessionSearchQuery:h,setIsSessionSearchOpen:f,setActiveProjectIdOnly:Ce,setDirectory:ye,setActiveMainTab:Ee,setSessionSwitcherOpen:Me,setCurrentSession:Dt,updateSessionTitle:Ot,shareSession:kt,unshareSession:At,archiveSession:xn,archiveSessions:Sn,childrenMap:Zt,showDeletionDialog:Fe,setDeleteSessionConfirm:W,deleteSessionConfirm:te,setEditingId:S,setEditTitle:w,editingId:x,editTitle:C}),Ln=Q.useCallback((e,t,n,r=`project`)=>{let i={sessionId:e,scope:r,projectId:n??null};if(e===xt){Bn(e),Tx(i),En(e,t,n);return}Cx(i,()=>En(e,t,n))},[En,xt]);Q.useEffect(()=>()=>{Sx()},[]);let Rn=Q.useCallback(()=>{if(!ne)return;let{scopeKey:e,folderId:t}=ne;G(null),Je(e,t)},[ne,Je]);Q.useEffect(()=>{if(!xt)return;let e=It.find(e=>e.id===xt)?.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(rS,JSON.stringify(Array.from(n)))}catch{}return n})},[xt,It,k]);let zn=Q.useCallback(e=>{O(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{k.setItem(rS,JSON.stringify(Array.from(n)))}catch{}return n})},[k]),Vn=Q.useCallback((e,t)=>{if(!e)return null;t&&Ve.has(t)&&et(t);let n=Ke(e,s(`sessions.sidebar.folder.newFolderName`),t);return H(n.id),ee(n.name),n},[Ve,et,Ke,s]),Hn=gS(Ln),Wn=gS(Dn),Gn=gS(An),Kn=gS(jn),qn=gS(Mn),Jn=gS(Nn),Zn=gS(Pn),Qn=gS(Fn),$n=gS(Vn),tr=Q.useCallback((e,t,n,r)=>{let i=Ly(),a=Math.max(i,n)+7;if(I(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=_(e.directory??null);if(!o)return;let s=vn.getState().activePaginationByDirectory.get(o);s?.hasMore&&!s.loadingMore&&rn(o)},[]),nr=Q.useCallback(e=>{I(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),rr=Q.useCallback(e=>{I(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})},[]),ir=Q.useCallback(e=>{let t=be.find(t=>t.id===e),n=_(t?.path??null);if(!n)return[];let r=[n];return lt||(Mt.get(n)??[]).forEach(e=>{let t=_(e.path);t&&r.push(t)}),r},[Mt,lt,be]),ar=Q.useCallback(e=>{let t=ir(e);if(t.length===0)return;let n=vn.getState().loadedDirectories,r=t.filter(e=>!n.has(e));r.length!==0&&cn(r,Rt.current)},[ir]),or=Q.useCallback(e=>{let t=be.find(t=>t.id===e);t&&(async()=>{let e=[];if(!lt)try{e=(await Ei({id:t.id,path:t.path})).worktrees}catch(n){console.warn(`[SessionSidebar] Worktree refresh before session sync failed:`,n);let r=_(t.path);e=r?Tn.getState().availableWorktreesByProject.get(r)??[]:[]}let n=Yx(t.path,e,{currentDirectory:ve,workspaceRoot:t.path,includeWorktrees:!lt});n.length!==0&&await kn(n,Rt.current)})()},[ve,lt,be]);Q.useEffect(()=>{if(!Jt)return;let e=vn.getState(),t=be.flatMap(t=>j.has(t.id)?[]:ir(t.id).filter(t=>!e.loadedDirectories.has(t)&&!e.loadingDirectories.has(t)&&!e.refreshingDirectories.has(t)));t.length>0&&cn(t,Rt.current)},[j,ir,Jt,be]);let sr=Q.useCallback(()=>{ge.current=Date.now()+150,I(new Map),M(()=>{let e=new Set(be.map(e=>e.id));try{k.setItem($x,JSON.stringify(Array.from(e)))}catch{}return lt||qt(e),e})},[be,lt,k,qt]),cr=Q.useCallback(()=>{ge.current=Date.now()+150,I(new Map),M(()=>{let e=new Set;try{k.setItem($x,JSON.stringify([]))}catch{}return lt||qt(e),e});let e=vn.getState().loadedDirectories,t=be.flatMap(t=>ir(t.id).filter(t=>!e.has(t)));t.length>0&&cn(t,Rt.current)},[ir,lt,be,k,qt]),lr=Q.useCallback(e=>{ge.current=Date.now()+150,rr(e),M(t=>{let n=new Set(t);n.has(e)?(n.delete(e),queueMicrotask(()=>ar(e))):n.add(e);try{k.setItem($x,JSON.stringify(Array.from(n)))}catch{}return lt||qt(n),n})},[ar,lt,rr,k,qt]),ur=Q.useCallback(e=>{ge.current=Date.now()+150,ar(e),M(t=>{if(!t.has(e))return t;let n=new Set(t);n.delete(e);try{k.setItem($x,JSON.stringify(Array.from(n)))}catch{}return lt||qt(n),n})},[ar,lt,k,qt]),dr=Q.useMemo(()=>be.map(e=>({...e,normalizedPath:_(e.path)})).filter(e=>!!e.normalizedPath),[be]),fr=Q.useMemo(()=>dr.map(e=>e.normalizedPath),[dr]),pr=Q.useMemo(()=>{let e=new Set(dr.map(e=>e.normalizedPath));if(!lt)for(let t of Mt.values())for(let n of t){let t=_(n.path);t&&e.add(t)}return[...e].sort()},[Mt,lt,dr]),mr=Q.useRef(null);Q.useEffect(()=>{let e=new Set(pr),t=mr.current;if(mr.current=e,!t)return;let n=pr.filter(e=>!t.has(e));if(n.length===0)return;let r=vn.getState().loadedDirectories,i=_(ve),a=dr.find(e=>e.id===xe)??dr.find(e=>e.normalizedPath===i)??null,o=new Set;i&&o.add(i),a?.normalizedPath&&(o.add(a.normalizedPath),lt||(Mt.get(a.normalizedPath)??[]).forEach(e=>{let t=_(e.path);t&&o.add(t)}));let s=n.filter(e=>o.has(e)&&!r.has(e));s.length!==0&&cn(s,Rt.current)},[xe,Mt,ve,lt,dr,pr]);let{github:hr}=fo(),gr=ga(),_r=gr.data??null,vr=gr.isFetched,yr=Yo(o?fr:mS),br=ey(e=>e.ensureEntry),xr=ey(e=>e.setParams),Sr=ey(e=>e.refreshTargets);_v({normalizedProjects:dr,activeProjectId:xe,gitRepoStatus:yr,setProjectRepoStatus:P,setProjectRootBranches:pe,enabled:o});let Cr=Tn(e=>e.isLoading),wr=Q.useMemo(()=>q_(It,dr,Mt,lt,yt),[yt,Mt,lt,dr,It]);yv({isSessionsLoading:Cr,fullCatalogSessionIds:ut,fullCatalogGeneration:dt,normalizedProjects:dr,cleanupSessions:tt});let{getSessionsForProject:Tr,getArchivedSessionsForProject:Er}=vv({ownership:wr}),Dr=Q.useMemo(()=>{let e=new Set;if(ht.size===0)return e;for(let t of dr){let n=[t.normalizedPath];lt||(Mt.get(t.normalizedPath)??[]).forEach(e=>{let t=_(e.path);t&&n.push(t)}),n.some(e=>ht.has(e))&&e.add(t.id)}return e},[Mt,lt,ht,dr]),Or=Q.useMemo(()=>{let e=new Set;if(gt.size===0)return e;for(let t of dr)ir(t.id).some(e=>gt.has(e))&&e.add(t.id);return e},[ir,dr,gt]),kr=ht.size>0||gt.size>0||ft===`idle`||ft===`loading`;Z_({normalizedProjects:dr,ownership:wr,isSessionsLoading:Cr,fullCatalogSessionIds:ut,fullCatalogGeneration:dt,foldersMap:He,createFolder:Ke,addSessionToFolder:Ye,cleanupSessions:tt,enabled:o});let Ar=Q.useRef(!1);xe&&N.has(xe)&&(Ar.current=!!N.get(xe));let jr=Py(e=>e.projectSortOrder),Mr=mn(e=>e.manualProjectOrder),{projectSections:Pr,groupSearchDataByGroup:Fr,sectionsForRender:Ir,searchMatchCount:Lr}=$_({normalizedProjects:Q.useMemo(()=>{let e=[...dr];switch(jr){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(Mr.map((e,t)=>[e,t]));e.sort((e,n)=>(t.get(e.id)??1/0)-(t.get(n.id)??1/0));break}}return e},[dr,jr,Mr]),getSessionsForProject:Tr,getArchivedSessionsForProject:Er,availableWorktreesByProject:Mt,projectRepoStatus:N,projectRootBranches:fe,lastRepoStatus:Ar.current,buildGroupedSessions:Kt,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,filterSessionNodesForSearch:Gt,buildGroupSearchText:Wt,foldersMap:He}),Rr=(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`)})]});tv({projectSections:Pr,activeProjectId:xe,activeSessionByProject:ue,setActiveSessionByProject:de,currentSessionId:xt,handleSessionSelect:En,newSessionDraftOpen:Et,mobileVariant:e,openNewSessionDraft:Nt,setActiveMainTab:Ee,setSessionSwitcherOpen:Me});let{getOrderedGroups:zr}=nv(ce),Br=Q.useRef(!1);Q.useEffect(()=>{if(Br.current||Pr.length===0)return;let e=Pr.flatMap(e=>e.groups.filter(e=>e.isArchivedBucket).map(t=>`${e.project.id}:${t.id}`));e.length>0&&se(t=>new Set([...t,...e])),Br.current=!0},[Pr]);let Vr=Q.useMemo(()=>{let e=new Map,t=new Map;return Pr.forEach(n=>{let r=er(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},[Pr]);Q.useLayoutEffect(()=>{if(!xt){Tx(null);return}let e=ei.getState().focus;if(e?.sessionId===xt){e.scope===`project`&&!e.projectId&&Tx({...e,projectId:Vr.get(xt)?.projectId??null});return}Tx({scope:`project`,sessionId:xt,projectId:Vr.get(xt)?.projectId??null})},[xt,Vr]);let Hr=Q.useMemo(()=>lt?[]:Jx(It,ie),[lt,ie,It]),Ur=Q.useMemo(()=>lt?[]:Hr.map(e=>{let t=Vr.get(e.id),n=_(e.directory??null),r={session:e,children:[],worktree:jt.get(e.id)??null};if(ze&&Gt([r],Re).length===0)return null;let i=t?.secondaryMeta?{projectLabel:t.secondaryMeta.projectLabel,branchLabel:lt?null:t.secondaryMeta.branchLabel}:null;return{node:r,projectId:t?.projectId??null,groupDirectory:t?.groupDirectory??n,secondaryMeta:i}}).filter(e=>e!==null),[Gt,ze,lt,Re,Hr,Vr,jt]),Wr=Q.useMemo(()=>Ir.map(e=>({...e,groups:e.groups.filter(e=>!e.isArchivedBucket)})),[Ir]),Gr=Q.useMemo(()=>{let e=ze?Wr.map(e=>({...e,groups:e.groups.map(e=>({...e,sessions:Fr.get(e)?.filteredNodes??[]}))})):Wr;if(!a)return e;let t=e.find(e=>e.project.id===xe)??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]}]:[]},[xe,Fr,ze,Wr,a]),Kr=Q.useMemo(()=>Vy({sections:Gr,foldersMap:He,getOrderedGroups:zr,pinnedSessionIds:ie,sessionOrderByScope:Ue,sessionOrderActivityByScope:We}),[He,zr,Gr,ie,We,Ue]),qr=Q.useMemo(()=>zy({targets:Kr,collapsedProjectIds:j,collapsedGroupKeys:oe,collapsedFolderIds:Ve,visibleSessionCountByGroup:F,defaultVisibleSessionCount:Ly(),hasSessionSearchQuery:ze,alwaysVisibleSessionIds:St}),[St,Ve,oe,j,ze,Kr,F]),Jr=Q.useMemo(()=>ze||lt?[]:Hr.map((e,t)=>{let n=Vr.get(e.id);return{scope:`pinned`,sessionId:e.id,projectId:n?.projectId??null,directory:_(fn(e))??n?.groupDirectory??null,visibleIndex:t}}),[ze,lt,Hr,Vr]),[Yr,Xr]=Q.useState(null),Zr=Q.useCallback(e=>{Xr(t=>t&&t.length===e.length&&t.every((t,n)=>t===e[n])?t:[...e])},[]),Qr=Q.useMemo(()=>{if(!Yr)return Jr;let e=new Set(Yr);return Jr.filter(t=>e.has(t.sessionId))},[Jr,Yr]),$r=Q.useMemo(()=>e?[]:li({pinnedTargets:Qr,projectTargets:qr}),[e,Qr,qr]),ti=Q.useCallback(e=>{Ee(`chat`),Me(!1),e.scope===`project`&&e.projectId&&Ce(e.projectId),Ln(e.sessionId,e.directory,e.projectId,e.scope)},[Ln,Ee,Ce,Me]);Q.useLayoutEffect(()=>ni({targets:$r,activate:ti}),[ti,$r]);let ri=Q.useMemo(()=>{let e=new Map;return $r.forEach(t=>{let n=gi({scope:t.scope,sessionId:t.sessionId,projectId:t.projectId});n&&e.set(n,hi($r,t)??0)}),e},[$r]),ai=Q.useMemo(()=>{if(!xt||ze||lt)return[];let e=[],t=(n,r)=>{if(n.session.id===xt){e.push({scope:`pinned`,sessionId:xt,projectId:r});return}n.children.forEach(e=>t(e,r))};return Ur.forEach(e=>t(e.node,e.projectId)),e},[xt,ze,lt,Ur]),oi=Q.useMemo(()=>{if(!xt)return[];let e=[],t=(n,r)=>{if(n.session.id===xt){e.push({scope:`project`,sessionId:xt,projectId:r});return}n.children.forEach(e=>t(e,r))};return Pr.forEach(e=>{e.groups.forEach(n=>{n.sessions.forEach(n=>t(n,e.project.id))})}),e},[xt,Pr]);Q.useLayoutEffect(()=>ii({pinned:Jr,project:qr}),[Jr,qr]),Q.useLayoutEffect(()=>{kr||Tx(Zx({currentSessionId:xt,focus:wt,pinnedFocuses:ai,projectFocuses:oi,fallbackProjectId:xt?Vr.get(xt)?.projectId??null:null}))},[xt,kr,oi,ai,wt,Vr]);let si=Q.useMemo(()=>{let e=wt?.sessionId?Vr.get(wt.sessionId)?.projectId??null:null;return Qx(wt,Kr,e)},[Kr,wt,Vr]),ci=Q.useRef(null),ui=Q.useRef(null);Q.useEffect(()=>{ui.current&&ui.current!==xt&&(ui.current=null)},[xt]),Q.useLayoutEffect(()=>{if(!si?.projectId)return;let e=si.sessionId,t=Tt.sessionId===e;if(!(!t&&xt!==e)){if(t){if(ci.current===Tt.revision)return;ci.current=Tt.revision,ui.current=e}else{if(ui.current===e)return;ui.current=e}if(ur(si.projectId),si.groupKey&&se(e=>{if(!e.has(si.groupKey))return e;let t=new Set(e);return t.delete(si.groupKey),t}),si.folderAncestorIds?.forEach(e=>{let t=Qt.getState();t.collapsedFolderIds.has(e)&&t.toggleFolderCollapse(e)}),si.groupKey&&si.visibleIndex!==void 0){let e=si.visibleIndex+1;I(t=>{if((t.get(si.groupKey)??0)>=e)return t;let n=new Map(t);return n.set(si.groupKey,e),n})}}},[xt,ur,si,Tt]);let di=oy(Q.useMemo(()=>{let e=new Set;return Wr.forEach(t=>{j.has(t.project.id)||t.groups.forEach(n=>{if(oe.has(`${t.project.id}:${n.id}`))return;let r=_(n.directory??null),i=n.branch?.trim()||it.get(r||``)?.trim();!r||!i||e.add(Fv(r,i))})}),[...e]},[oe,j,it,Wr]));Q.useEffect(()=>{if(!o||!vr||!_r?.connected||!hr)return;let e=[],t=Date.now();if(Wr.forEach(n=>{j.has(n.project.id)||n.groups.forEach(r=>{if(oe.has(`${n.project.id}:${r.id}`))return;let i=_(r.directory??null),a=r.branch?.trim()||it.get(i||``)?.trim();if(!i||!a)return;let o=Fv(i,a),s=ey.getState().entries[o],c=!!s?.status?.pr,l=`${i}::${a}`,u=Math.max(s?.lastRefreshAt??0,s?.lastDiscoveryPollAt??0),d=!!(s?.isInitialStatusResolved&&!c&&(!b.current.has(l)||t-u>=dS));(!s||!s.isInitialStatusResolved||d)&&(d&&b.current.add(l),e.push({directory:i,branch:a}))})}),e.length===0)return;let n=new Map;e.forEach(e=>{let t=Fv(e.directory,e.branch,e.remoteName??null);n.has(t)||n.set(t,e)}),n.forEach((e,t)=>{br(t),xr(t,{directory:e.directory,branch:e.branch,remoteName:e.remoteName??null,canShow:!0,github:hr,githubAuthChecked:vr,githubConnected:_r.connected})}),Sr([...n.values()],{silent:!0,markInitialResolved:!0})},[j,oe,br,hr,vr,_r?.connected,it,o,Sr,Wr,xr]);let fi=xv({isDesktopShellRuntime:Bt,projectSections:Pr,projectHeaderSentinelRefs:he,enabled:o}),pi=gS((t,n=0,r,i,a=!1,o,s=`project`,c)=>(0,$.jsx)(zx,{node:t,depth:n,groupDirectory:r,projectId:i,archivedBucket:a,currentSessionId:xt,pinnedSessionIds:ie,expandedParents:D,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,notifyOnSubtasks:q,editingId:x,setEditingId:S,editTitle:C,setEditTitle:w,handleSaveEdit:Gn,handleCancelEdit:Kn,toggleParent:zn,handleSessionSelect:Hn,handleSessionDoubleClick:Wn,togglePinnedSession:ae,handleShareSession:qn,copiedSessionId:wn,handleCopyShareUrl:Jn,handleUnshareSession:Zn,openSidebarMenuKey:z,setOpenSidebarMenuKey:B,renamingFolderId:V,getFoldersForScope:Ge,getSessionFolderId:nt,removeSessionFromFolder:Qe,addSessionToFolder:Ye,createFolderAndStartRename:$n,openContextPanelTab:ke,handleDeleteSession:Qn,mobileVariant:e,alwaysShowActions:Ut,renderSessionNode:pi,secondaryMeta:o,renderContext:s,subtreeContainsActive:c?.subtreeContainsActive??fS,subtreeContainsEditing:c?.subtreeContainsEditing??fS,menuOpenSessionId:c?.menuOpenSessionId??null,nodeStructureKey:c?.nodeStructureKey??``,childRenderExtrasFor:c?.childRenderExtrasFor,liveSessionById:zt,shortcutNumber:ri.get(gi({scope:s,sessionId:t.session.id,projectId:i??null})??``)??null},`${s}:${i??``}:${t.session.id}`)),mi=Q.useCallback(e=>{nr(e),se(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[nr]),_i=Q.useCallback(e=>{let t=ir(e);if(t.length===0)return;let n=vn.getState(),r=t.filter(e=>!n.archivedLoadedDirectories.has(e));r.length>0&&Un(r)},[ir]),vi=Q.useMemo(()=>{let e=new Map;for(let[t,n]of di)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},[di]),yi=Q.useCallback((t,n,r,i,a,o,s)=>(0,$.jsx)(rb,{group:t,groupKey:n,isArchivedLoading:!!(t.isArchivedBucket&&r&&ir(r).some(e=>_t.has(e))),projectId:r,hideGroupLabel:i,compactBodyPadding:o,hasSessionSearchQuery:ze,normalizedSessionSearchQuery:Re,groupSearchDataByGroup:Fr,visibleSessionCount:F.get(n),collapsedGroups:oe,collapsedFolderIds:Ve,toggleFolderCollapse:et,renameFolder:qe,deleteFolder:Je,showDeletionDialog:Fe,setDeleteFolderConfirm:G,renderSessionNode:pi,projectRepoStatus:N,lastRepoStatus:Ar.current,showMoreGroupSessions:(e,n,r)=>tr(t,e,n,r),resetGroupSessionLimit:nr,mobileVariant:e,alwaysShowActions:Ut,activeProjectId:xe,setActiveProjectIdOnly:Ce,setActiveMainTab:Ee,setSessionSwitcherOpen:Me,openNewSessionDraft:Pt,addSessionToFolder:Ye,createFolderAndStartRename:$n,renamingFolderId:V,renameFolderDraft:U,setRenameFolderDraft:ee,setRenamingFolderId:H,pinnedSessionIds:ie,expandedParents:D,sessionOrderByScope:Ue,sessionOrderActivityByScope:We,onReorderSessions:(e,n,r,i)=>{let a=t.folderScopeKey??_(t.directory??null);a&&rt(a,e,n,r,i)},currentSessionId:xt,shortcutTargetSessionId:si?.groupKey===n?si.sessionId:null,shortcutTargetVisibleIndex:si?.groupKey===n?si.visibleIndex??null:null,editingId:x,editTitle:C,openSidebarMenuKey:z,liveSessionById:zt,runningSessionIds:ct,prVisualStateByDirectoryBranch:vi,onToggleCollapsedGroup:e=>{t.isArchivedBucket&&oe.has(e)&&r&&_i(r),mi(e)},dragHandleProps:a,scrollContainerRef:s}),[ze,Re,Fr,_t,ir,F,oe,Ve,et,qe,Je,Fe,pi,N,tr,nr,e,Ut,xe,Ce,Ee,Me,Pt,Ye,$n,V,U,ie,D,Ue,We,rt,xt,si,x,C,z,zt,ct,vi,mi,_i]),bi=i?null:(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(db,{collapseAllProjects:sr,expandAllProjects:cr}),(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:yn.requestDirectoryDialog,children:(0,$.jsx)(X,{name:`add`,className:`size-4`})})]}),xi=Bt&&Vt&&!lt&&!ze?(0,$.jsx)(`div`,{className:`shrink-0 px-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(ru,{className:`min-w-0 flex-1`}),(0,$.jsx)(ou,{className:`ml-auto shrink-0`})]})}):null,Si=!lt&&!ze?(0,$.jsxs)($.Fragment,{children:[e&&Vt?(0,$.jsx)(ru,{}):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:dn,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`,De===`schedule`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:gn,children:[(0,$.jsx)(X,{name:`time`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`sessions.sidebar.header.actions.scheduledTasks`)})]}),Oe.data?.supported&&Oe.data?.enabled?(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,className:Y(`w-full justify-start font-normal`,De===`assistant`&&`bg-interactive-selection text-interactive-selection-foreground`,e&&`h-11`),onClick:_n,children:[(0,$.jsx)(X,{name:`ai-agent`,className:`size-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:s(`assistants.title`)})]}):null]}),Ur.length>0?(0,$.jsx)(ob,{items:Ur,renderSessionNode:pi,currentSessionId:xt,editingId:x,openSidebarMenuKey:z,onVisibleSessionIdsChange:Zr}):null]}):null,Ci=!!(V||x||T),{selectionModeEnabled:wi,hasSelection:Ti,selectedIdsSize:Di,bulkScopeIsArchived:Oi,derivedSelectionScope:ki,bulkScopeFolders:Ai,bulkCanRemoveFromFolder:ji,handleExitSelectionMode:Mi,handleBulkMoveToFolder:Ni,handleBulkCreateFolderAndMove:Pi,handleBulkRemoveFromFolder:Fi,handleBulkDelete:Ii,confirmBulkDelete:Li}=Kx({isInlineEditing:Ci,showDeletionDialog:Fe,foldersMap:He,addSessionsToFolder:Ze,removeSessionsFromFolders:$e,createFolderAndStartRename:Vn,archiveSessions:Sn,setBulkDeleteConfirm:K});return(0,$.jsxs)(`div`,{ref:g,className:Y(`oc-session-sidebar relative flex h-full flex-col text-foreground overflow-x-hidden`,e?``:`bg-transparent`),children:[(0,$.jsx)(ib,{hideDirectoryControls:i,isSessionSearchOpen:d,setIsSessionSearchOpen:f,sessionSearchInputRef:y,sessionSearchQuery:m,setSessionSearchQuery:h,hasSessionSearchQuery:ze,searchMatchCount:Lr}),xi,o?(0,$.jsx)(Sb,{topContent:Si,hasLeadingSection:Si!==null&&Ur.length>0,headerAccessory:bi,sectionsForRender:Wr,projectSections:Pr,activeProjectId:xe,showOnlyMainWorkspace:a,hasSessionSearchQuery:ze,emptyState:$t,searchEmptyState:Rr,renderGroupSessions:yi,homeDirectory:_e,collapsedProjects:j,hideDirectoryControls:i,projectRepoStatus:N,isDesktopShellRuntime:Bt,stuckProjectHeaders:fi,mobileVariant:e,alwaysShowActions:Ut,toggleProject:lr,setActiveProjectIdOnly:Ce,setActiveMainTab:Ee,setSessionSwitcherOpen:Me,openNewSessionDraft:Pt,openNewWorktreeDialog:nn,syncProjectSessions:or,openProjectEditDialog:E,removeProject:Se,projectHeaderSentinelRefs:he,projectReorderEnabled:jr===`manual`,reorderProjects:Te,projectSortOrder:jr,getOrderedGroups:zr,setGroupOrderByProject:le,openSidebarMenuKey:z,setOpenSidebarMenuKey:B,isInlineEditing:Ci,loadingProjectIds:Dr,refreshingProjectIds:Or,isProjectSessionsSyncing:kr}):null,wi&&Ti?(0,$.jsx)(Gx,{selectedCount:Di,scopeKey:ki,scopeFolders:Ai,archivedBucket:Oi,onMoveToFolder:Ni,onCreateFolderAndMove:Pi,onRemoveFromFolder:Fi,canRemoveFromFolder:ji,onDelete:Ii,onDone:Mi}):null,(0,$.jsx)(hb,{onOpenSettings:ln,onOpenShortcuts:je,onOpenUpdate:sn,showRuntimeButtons:!lt,showUpdateButton:bn}),c?(0,$.jsx)(js,{open:c,onOpenChange:u,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,en?(0,$.jsx)(sy,{open:!0,onOpenChange:e=>{e||E(null)},project:en,onSave:tn}):null,L?(0,$.jsx)(lo,{open:!0,onOpenChange:R,onWorktreeCreated:an}):null,(0,$.jsx)(lc,{}),(0,$.jsx)(X_,{}),(0,$.jsx)(Hx,{value:te,setValue:W,showDeletionDialog:Fe,setShowDeletionDialog:Ie,onConfirm:In}),(0,$.jsx)(Wx,{value:ne,setValue:G,onConfirm:Rn}),(0,$.jsx)(Ux,{value:re,setValue:K,showDeletionDialog:Fe,setShowDeletionDialog:Ie,onConfirm:Li})]})},vS=e=>e?(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:e}):void 0,yS=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`);return t===`/`?`/`:t.replace(/\/+$/,``)},bS=()=>{let{t:e}=Xe(),[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),[m,h]=Q.useState(!1),[g,_]=Q.useState(!1),[v,y]=Q.useState(new Set),b=Tn(e=>e.getWorktreeMetadata),x=Tn(e=>e.newSessionDraft),S=Tn(e=>e.setNewSessionDraftTarget),C=Tn(e=>e.setDraftBootstrapPendingDirectory),w=yt,T=Tn(e=>e.archiveSessions),E=p(e=>e.showDeletionDialog),D=p(e=>e.setShowDeletionDialog),O=Pe(e=>e.currentDirectory),k=Pe(e=>e.homeDirectory),A=Pe(e=>e.isHomeReady),j=mn(e=>e.projects),M=mn(e=>e.activeProjectId),{isMobile:N,isTablet:P,hasTouchInput:F}=wa(),I=N||P||F,L=Q.useMemo(()=>yS((M?j.find(e=>e.id===M)??null:null)?.path??O),[M,O,j]),R=Q.useCallback(e=>{let t=yS(e.projectDirectory)||L;return{id:(j.find(e=>yS(e.path)===t)??null)?.id??`path:${t}`,path:t}},[L,j]),z=g&&v.size>0,B=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]),V=a?.mode===`worktree`,H=V,U=m||!V||!B,ee=m||!V;Q.useEffect(()=>{r||!A||j.length>0||(i(!0),n(!0))},[r,A,j.length]);let te=Q.useCallback(e=>{o({sessions:e.sessions,dateLabel:e.dateLabel,mode:e.mode??`session`,worktree:e.worktree??null})},[]),W=Q.useCallback(()=>{o(null),c([]),u(!1),f(!1),h(!1),_(!1),y(new Set)},[]),ne=Q.useCallback(t=>{if(t.sessions.length===0)return;let n=t.sessions.map(e=>e.id);dc({sessionIds:n,message:n.length===1?e(`sessions.sidebar.session.delete.success`):e(`sessions.sidebar.bulkActions.deletedPlural`,{count:n.length}),undoLabel:e(`sessions.sidebar.undo`),commitFailedMessage:n.length===1?e(`sessions.sidebar.session.delete.error`):e(`sessions.sidebar.bulkActions.failedDeletePlural`,{count:n.length})})},[e]);Q.useEffect(()=>yn.onDeleteRequest(e=>{if(!E&&(e.mode??`session`)===`session`){ne(e);return}te(e)}),[te,E,ne]),Q.useEffect(()=>yn.onDirectoryRequest(()=>{n(!0)}),[]),Q.useEffect(()=>{if(!a){c([]),u(!1),f(!1),_(!1),y(new Set);return}let e=a.sessions.map(e=>{let t=b(e.id);return t?{session:e,metadata:t}:null}).filter(e=>!!e);c(e),u(!1),_(!1),y(new Set);let t=new Map;if(a.worktree?.path&&t.set(yS(a.worktree.path),a.worktree),e.forEach(({metadata:e})=>{e.path&&t.set(yS(e.path),e)}),t.size===0){_(!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 Mi(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&&(y(r),_(!0),o(t=>{if(!t?.worktree?.path)return t;let n=yS(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=yS(t.metadata.path),r=e.get(n);return r?{session:t.session,metadata:{...t.metadata,status:r}}:t})))})(),()=>{n=!0}},[a,b]),Q.useEffect(()=>{B||u(!1)},[B]);let G=Q.useCallback(async(t,n)=>{let r=l&&B,i=R(t),a=yS(t.path),o=yS(i.path);try{await Ii(i,t,{deleteRemoteBranch:r,deleteLocalBranch:n});let e=yS(x?.directoryOverride);return x?.open&&a&&e===a&&o&&(C(null),S({projectId:i.id,directoryOverride:o},{force:!0})),yS(O)===a&&o&&Pe.getState().setDirectory(o,{showOverlay:!1}),!0}catch(t){return J.error(e(`sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle`),{description:vS(t instanceof Error?t.message:e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),!1}},[B,O,l,R,x?.directoryOverride,x?.open,C,S,e]),re=Q.useCallback((t,n)=>{let r=l&&B;(async()=>{if(!await G(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:vS(i)})})()},[B,l,G,e]),K=Q.useCallback(async()=>{if(a){h(!0);try{let t=H&&d;if(a.sessions.length===0&&V&&a.worktree){re(a.worktree,t),W();return}if(a.sessions.length===1){let t=a.sessions[0];if(V){if(!await w(t.id)){J.error(e(`sessions.sidebar.session.archive.error`)),h(!1);return}Js({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 dc({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(V){let e=await T(n);r=e.archivedIds,i=e.failedIds}else dc({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(V&&a.worktree&&i.length===0&&re(a.worktree,t),V&&r.length>0&&Js({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(V?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:vS(e(`sessions.sidebar.dialogs.deleteResult.tryAgain`))}),r.length===0)){h(!1);return}}V&&a.sessions.length===1&&a.worktree&&re(a.worktree,t),W()}finally{h(!1)}}},[a,d,w,T,W,H,V,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(V?`space-y-3`:`space-y-2`),children:[a.sessions.length>0&&(0,$.jsxs)(`div`,{className:Y(V?`rounded-lg bg-muted/30 p-3`:`space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3`),children:[V&&(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(V?`mt-2 space-y-1`:`space-y-0.5`),children:[a.sessions.slice(0,5).map(t=>(0,$.jsxs)(`li`,{className:Y(V?`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(!V&&`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(V?`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})})]})]}),V?(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?nr(ie.path,k):e(`sessions.sidebar.sessionDialogs.worktree.pathUnavailable`)}),z&&(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=V?B?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{U||u(e=>!e)},disabled:U,className:Y(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,U?`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=V?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ee||f(e=>!e)},disabled:ee,className:Y(`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors`,ee?`cursor-not-allowed opacity-60`:`hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`),children:[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=V?(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:W,disabled:m,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:K,disabled:m,children:e(m?`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:()=>D(!E),className:`inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,"aria-pressed":!E,children:[E?(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:W,disabled:m,children:e(`sessions.sidebar.dialogs.cancel`)}),(0,$.jsx)(Z,{variant:`destructive`,onClick:K,disabled:m,children:m?e(`sessions.sidebar.sessionDialogs.actions.deleting`):a?.sessions.length===1?e(`sessions.sidebar.dialogs.deleteSession.titleAction`):e(`sessions.sidebar.dialogs.deleteSessions.titleAction`)})]})]}),ue=V?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:[I?(0,$.jsx)(uo,{open:!!a,onClose:()=>{m||W()},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)(ur,{open:!!a,onOpenChange:e=>{if(!e){if(m)return;W()}},children:(0,$.jsxs)(sr,{className:Y(V?`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)(ar,{children:[(0,$.jsxs)(cr,{className:Y(V&&`flex items-center gap-2`),children:[V&&(0,$.jsx)(X,{name:`delete-bin`,className:`h-5 w-5`}),ue]}),ae&&(0,$.jsx)(lr,{children:ae})]}),(0,$.jsx)(`div`,{className:Y(V&&`flex-1 min-h-0 overflow-y-auto space-y-2`),children:oe}),(0,$.jsx)(or,{className:`mt-2 gap-2 pt-1 pb-1`,children:le})]})}),(0,$.jsx)(rc,{open:t,onOpenChange:n})]})},xS=Q.createContext(null),SS=e=>{let t=(0,zc.c)(3),{children:n,value:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(xS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},CS=_o(()=>Fe(()=>import(`./TerminalView-CM5jRKlj.js`).then(e=>({default:e.TerminalView})),__vite__mapDeps([46,1,2,3,4,5,6,7,8,47,35,36,14,48,12,13,34,37,38,9,10,11,39,40,15,16,17,18,20,21,49,50,42,51,52,53,54,55,56]))),wS=_o(()=>Fe(()=>import(`./DiagramView-CUfSFI3e.js`).then(e=>({default:e.DiagramView})),__vite__mapDeps([57,1,2,3,4,37,8,38,12,5,6,7,13,14,18,15,16,17,50,42,35,36,34,9,10,11,39,40,58,59,60]))),TS=_o(()=>Fe(()=>import(`./SettingsView-CbDBfQp1.js`).then(e=>e.n).then(e=>({default:e.SettingsView})),__vite__mapDeps([61,1,2,3,4,5,6,7,8,62,63,35,36,14,37,64,38,9,10,11,12,13,34,39,40,65,66,15,16,17,18,20,67,19,68,69,70,44,49,52,53,54,71,72,73,74,75,76,77,78,21,79,50,33,41,23,24,25,26,27,28,29,30,31,32,80,51,81,82,83,84,85,56,86,87,88,89]))),ES=_o(()=>Fe(()=>import(`./SettingsWindow-Br7XLcSd.js`).then(e=>({default:e.SettingsWindow})),__vite__mapDeps([90,1,4,7,12,5,2,3,6,8,13,14,15,16,17,61,62,63,35,36,37,64,38,9,10,11,34,39,40,65,66,18,20,67,19,68,69,70,44,49,52,53,54,71,72,73,74,75,76,77,78,21,79,50,33,41,23,24,25,26,27,28,29,30,31,32,80,51,81,82,83,84,85,56,86,87,88,89]))),DS=_o(()=>Fe(()=>import(`./MultiRunWindow-D_2mWZyv.js`).then(e=>({default:e.MultiRunWindow})),__vite__mapDeps([91,1,4,7,12,5,2,3,6,8,13,14,15,16,17,18,92,35,36,9,10,11,34,37,38,39,40,20,69,68,70,44,49,52,53,54,50,93,82]))),OS=_o(()=>Fe(()=>import(`./AssistantView-C00aiEHK.js`).then(e=>e.n).then(e=>({default:e.AssistantView})),__vite__mapDeps([94,1,2,3,4,5,6,7,8,38,9,10,11,12,13,14,34,35,36,37,39,40,65,62,63,66,15,16,17,18,20,67,19,49,95,64,69,68,70,44,52,53,54,21,73,74,75,76,77,78,79,22,23,24,25,26,27,28,29,30,31,32,50,33,41,80,42,96,93,43,45,97,98,51,99,86]))),kS=()=>{let e=1220,t=p(e=>e.isSidebarOpen),n=p(e=>e.isRightSidebarOpen),r=p(e=>e.isBottomTerminalOpen),i=p(e=>e.setRightSidebarOpen),a=p(e=>e.setBottomTerminalOpen),o=p(e=>e.activeMainTab),s=p(e=>e.setIsMobile),c=p(e=>e.isSessionSwitcherOpen),l=p(e=>e.isSettingsDialogOpen),u=p(e=>e.setSettingsDialogOpen),d=p(e=>e.isMultiRunLauncherOpen),f=p(e=>e.setMultiRunLauncherOpen),{isMobile:m,isTablet:h}=wa(),g=Q.useRef(!1),_=Q.useRef(!1),v=Q.useRef(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(!1),D=Q.useCallback(e=>{b(e),p.getState().setSessionSwitcherOpen(e)},[]),O=Q.useRef(!1),k=Q.useRef(typeof window>`u`?0:window.innerWidth),A=rs(-k.current),j=(0,Q.useRef)(0),M=rs(k.current),N=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{m&&(j.current=window.innerWidth,N.current=window.innerWidth)},[m]),(0,Q.useEffect)(()=>{if(!m){w(!1);return}y&&w(!0),is(A,y?0:-j.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[y,m,A]),(0,Q.useEffect)(()=>{if(!m){E(!1);return}O.current=x,x&&E(!0),is(M,x?0:N.current,{type:`spring`,stiffness:400,damping:35,mass:.8})},[m,x,M]),(0,Q.useEffect)(()=>{if(m)return A.on(`change`,e=>{let t=j.current||k.current,n=y||e>-t+.5;w(e=>e===n?e:n)})},[m,A,y]),(0,Q.useEffect)(()=>{if(m)return M.on(`change`,e=>{let t=N.current||k.current,n=x||e<t-.5;E(e=>e===n?e:n)})},[m,x,M]),(0,Q.useEffect)(()=>{m&&!c&&y&&D(!1)},[c,m,y,D]),(0,Q.useEffect)(()=>{if(!m){v.current=!1;return}v.current||(v.current=!0,D(!1),S(!1),p.getState().isRightSidebarOpen&&i(!1))},[m,D,i]),(0,Q.useEffect)(()=>{if(!m||o!==`chat`||y||x||l)return;let e=!1,t,n=r=>{t=window.setTimeout(()=>{if(e)return;let t=Tn.getState(),r=p.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,m,l,y,x]),(0,Q.useEffect)(()=>{!m||!l||(D(!1),S(!1),n&&i(!1))},[m,l,n,D,i]),Q.useEffect(()=>{p.getState().isMobile!==m&&s(m)},[m,s]),Q.useEffect(()=>{if(typeof window>`u`)return;let e,t=()=>{e===void 0&&(e=window.requestAnimationFrame(()=>{e=void 0,p.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=p.getState(),n=window.innerWidth,r=window.innerHeight;!m&&!h&&(n<1140?t.isRightSidebarOpen&&(i(!1),g.current=!0):n>=e&&g.current&&(i(!0),g.current=!1),r<640?t.isBottomTerminalOpen&&(a(!1),_.current=!0):r>=700&&_.current&&(a(!0),_.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)}},[m,h,a,i]),Q.useEffect(()=>{if(typeof window>`u`)return;let t=p.subscribe((t,n)=>{let r=window.innerWidth,i=window.innerHeight,a=r>=e,o=i>=700;t.isRightSidebarOpen!==n.isRightSidebarOpen&&a&&(g.current=!1),t.isBottomTerminalOpen!==n.isBottomTerminalOpen&&o&&(_.current=!1)});return()=>{t()}},[m,h,a,i]);let P=Q.useCallback(()=>{y&&D(!1),S(!x)},[y,x,D]),F=Q.useMemo(()=>{switch(o){case`git`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(lf,{isActive:!x})});case`diff`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Rs,{})});case`terminal`:return r?null:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(CS,{})});case`files`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(bp,{})});case`context`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(jf,{})});case`diagram`:return(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wS,{})});default:return null}},[o,r,x]),I=o===`schedule`,L=o===`assistant`,R=o===`plan`,z=I||L||R,B=o===`chat`,V=!z&&!l;return(0,$.jsx)(Ys,{children:(0,$.jsxs)(`div`,{"data-page-scroll-lock":`true`,className:Y(`main-content-safe-area`,m?`flex h-[100dvh] flex-col`:`relative flex h-[100dvh]`,`bg-background`),children:[(0,$.jsx)(Wg,{}),(0,$.jsx)(F_,{}),(0,$.jsx)(z_,{}),(0,$.jsx)(bS,{}),m?(0,$.jsxs)(SS,{value:{leftDrawerOpen:y,rightDrawerOpen:x,toggleLeftDrawer:()=>{let e=!y;x&&S(!1),D(e)},toggleRightDrawer:P,leftDrawerX:A,rightDrawerX:M,leftDrawerWidth:j,rightDrawerWidth:N,setMobileLeftDrawerOpen:D,setRightSidebarOpen:S},children:[!l&&!z&&(0,$.jsx)(Hl,{onToggleLeftDrawer:()=>{let e=!y;x&&S(!1),D(e)},onToggleRightDrawer:()=>{P()},leftDrawerOpen:y,rightDrawerOpen:x}),(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:[I&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Zs,{})})})}),L&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(OS,{})})})}),R&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(Zp,{})})})}),V&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!B&&`invisible`),children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Vs,{})})}),V&&F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:F})}),d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Pc,{onCreated:()=>f(!1),onCancel:()=>f(!1)})})}),(0,$.jsx)(ns.div,{className:Y(`absolute inset-0 z-20 bg-sidebar`,!C&&`pointer-events-none invisible`),"data-page-scroll-lock":`true`,style:{x:A},"aria-hidden":!y,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(_S,{mobileVariant:!0,isVisible:C})})}),T&&(0,$.jsx)(ns.div,{className:`absolute inset-0 z-20 bg-sidebar`,"data-page-scroll-lock":`true`,style:{x:M},"aria-hidden":!x,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(lf,{isActive:x})})})})]})}),l&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,style:{paddingTop:`var(--oc-safe-area-top, 0px)`},children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(TS,{onClose:()=>u(!1)})})})}),(0,$.jsx)(Yi,{children:(0,$.jsx)(ic,{})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(uu,{}),(0,$.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,"data-page-scroll-lock":`true`,children:[(0,$.jsx)(tu,{isOpen:t,isMobile:m,className:`border-border/50`,topBar:(0,$.jsx)(nu,{}),children:(0,$.jsx)(_S,{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:z?(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden bg-background`,"data-page-scroll-lock":`true`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:L?(0,$.jsx)(OS,{}):R?(0,$.jsx)(Zp,{}):(0,$.jsx)(Zs,{})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hl,{}),(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 border-t border-border/50 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:[V&&(0,$.jsx)(`div`,{className:Y(`absolute inset-0`,!B&&`invisible`),children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Vs,{})})}),V&&F&&(0,$.jsx)(`div`,{className:`absolute inset-0`,children:(0,$.jsx)(Yi,{children:F})})]}),(0,$.jsx)(Lg,{})]})}),(0,$.jsx)(ql,{isOpen:r,isMobile:m,children:r?(0,$.jsx)(Yi,{children:(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(CS,{})})}):null})]}),(0,$.jsx)(yu,{isOpen:n,className:`bg-background border-t border-border/50`,children:(0,$.jsx)(Yi,{children:(0,$.jsx)(Mf,{})})})]})]})})]}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ES,{open:l,onOpenChange:u})}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(DS,{open:d,onOpenChange:f})})]})]})})},AS=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`},jS=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},MS=e=>{let t=(0,zc.c)(43),{title:n,snapshot:r,emptyLabel:i}=e,{t:a}=Xe(),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(PS,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?AS(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)(jS,{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)(jS,{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)(jS,{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)(xi,{outerClassName:`max-h-64`,className:`pr-1`,children:(0,$.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`rounded-md border border-[var(--interactive-border)] p-2`,style:{backgroundColor:`color-mix(in srgb, var(--surface-elevated) 88%, transparent)`},children:[(0,$.jsx)(`div`,{className:`typography-meta font-medium text-[var(--surface-foreground)] break-all`,children:e.metric}),(0,$.jsxs)(`div`,{className:`mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]`,children:[(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.countValue`,{value:e.count})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.avgValue`,{value:e.avg})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.maxValue`,{value:e.max})}),(0,$.jsx)(`span`,{children:a(`memoryDebugPanel.metric.totalValue`,{value:e.total})})]})]},e.metric))})})]}),t[0]=i,t[1]=r.durationMs,t[2]=r.entries,t[3]=r.lastUpdatedAt,t[4]=r.startedAt,t[5]=a,t[6]=n,t[7]=o}else o=t[7];return o},NS=e=>{let t=(0,zc.c)(104),{onClose:n}=e,{t:r}=Xe(),[i,a]=Q.useState(`memory`),[o,s]=Q.useState(`idle`),c=Tn(FS),l=Ft(IS),u=Hn(),d=sn(),[f,p]=Q.useState(LS),m,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>Kn(()=>{p(Mn())}),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=dn(),t={};if(!e){g=t;break bb0}let n=e.getCacheBudget?.(),r=n?n.listCanonical().map(RS):u.map(e=>({directory:d,sessionID:e.id}));for(let n of r){if(d&&n.directory!==d)continue;let r=e.getTranscript(en(n.directory,n.sessionID));t[n.sessionID]=r.messageOrder.map(e=>r.messagesByID[e]).filter(zS)}g=t}t[2]=d,t[3]=u,t[4]=g}else g=t[4];let _=g,v=ey(BS),[y,b]=Q.useState(VS),[x,S]=Q.useState(HS),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(Me()),S(q())};e();let t=window.setInterval(e,500);return()=>window.clearInterval(t)},N=[],t[26]=M,t[27]=N):(M=t[26],N=t[27]),Q.useEffect(M,N);let P,F;t[28]===o?(P=t[29],F=t[30]):(P=()=>{if(o===`idle`)return;let e=window.setTimeout(()=>{s(`idle`)},1500);return()=>window.clearTimeout(e)},F=[o],t[28]=o,t[29]=P,t[30]=F),Q.useEffect(P,F);let I=0,L=0,R=0;for(let e of Object.keys(_)){let t=_[e]??[];L+=t.length;for(let e of t)e.role===`user`?R+=1:e.role===`assistant`&&(I+=1)}let z;t[31]!==I||t[32]!==L||t[33]!==R?(z={assistant:I,total:L,user:R},t[31]=I,t[32]=L,t[33]=R,t[34]=z):z=t[34];let B=z,V;if(t[35]!==c||t[36]!==_||t[37]!==l||t[38]!==u||t[39]!==r){let e;t[41]!==c||t[42]!==_||t[43]!==l||t[44]!==r?(e=e=>{let t=_[e.id]??[],n=0,i=0;for(let e of t)e.role===`user`?i+=1:e.role===`assistant`&&(n+=1);let a=l.get(e.id);return{id:e.id,title:e.title||r(`memoryDebugPanel.common.untitled`),assistantMessageCount:n,messageCount:t.length,userMessageCount:i,isStreaming:a?.isStreaming||!1,isZombie:a?.isZombie||!1,backgroundCount:a?.backgroundMessageCount||0,lastAccessed:a?.lastAccessedAt||0,isCurrent:e.id===c}},t[41]=c,t[42]=_,t[43]=l,t[44]=r,t[45]=e):e=t[45],V=u.map(e).sort(US),t[35]=c,t[36]=_,t[37]=l,t[38]=u,t[39]=r,t[40]=V}else V=t[40];let H=V,U;t[46]===_?U=t[47]:(U=Object.keys(_),t[46]=_,t[47]=U);let ee=U.length,te;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(te=async()=>{try{let e={generatedAt:new Date().toISOString(),ui:Me(),vscode:q()};await navigator.clipboard.writeText(JSON.stringify(e,null,2)),s(`copied`)}catch{s(`error`)}},t[48]=te):te=t[48];let W=te,ne;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ne={backgroundColor:`color-mix(in srgb, var(--surface-background) 94%, transparent)`},t[49]=ne):ne=t[49];let G;t[50]===i?G=t[51]:(G=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]=G);let re;t[52]===r?re=t[53]:(re=r(`memoryDebugPanel.title`),t[52]=r,t[53]=re);let K;t[54]===re?K=t[55]:(K=(0,$.jsx)(`h3`,{className:`typography-ui-label font-semibold text-[var(--surface-foreground)]`,children:re}),t[54]=re,t[55]=K);let ie;t[56]!==G||t[57]!==K?(ie=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[G,K]}),t[56]=G,t[57]=K,t[58]=ie):ie=t[58];let ae;t[59]===i?ae=t[60]:(ae=i===`streaming`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:W,children:(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(Z,{size:`xs`,variant:`ghost`,onClick:()=>{je(),b(Me()),S(q())},children:(0,$.jsx)(X,{name:`refresh`,className:`h-3.5 w-3.5`})})]}):null,t[59]=i,t[60]=ae);let oe;t[61]===n?oe=t[62]:(oe=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]=oe);let se;t[63]!==ae||t[64]!==oe?(se=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ae,oe]}),t[63]=ae,t[64]=oe,t[65]=se):se=t[65];let ce;t[66]!==ie||t[67]!==se?(ce=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[ie,se]}),t[66]=ie,t[67]=se,t[68]=ce):ce=t[68];let le;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(le={backgroundColor:`color-mix(in srgb, var(--surface-muted) 55%, transparent)`},t[69]=le):le=t[69];let ue=i===`memory`?`secondary`:`ghost`,de;t[70]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>a(`memory`),t[70]=de):de=t[70];let fe;t[71]===r?fe=t[72]:(fe=r(`memoryDebugPanel.tabs.memory`),t[71]=r,t[72]=fe);let pe;t[73]!==ue||t[74]!==fe?(pe=(0,$.jsx)(Z,{size:`sm`,variant:ue,className:`flex-1`,onClick:de,children:fe}),t[73]=ue,t[74]=fe,t[75]=pe):pe=t[75];let me=i===`streaming`?`secondary`:`ghost`,he;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(he=()=>a(`streaming`),t[76]=he):he=t[76];let ge;t[77]===r?ge=t[78]:(ge=r(`memoryDebugPanel.tabs.streaming`),t[77]=r,t[78]=ge);let _e;t[79]!==me||t[80]!==ge?(_e=(0,$.jsx)(Z,{size:`sm`,variant:me,className:`flex-1`,onClick:he,children:ge}),t[79]=me,t[80]=ge,t[81]=_e):_e=t[81];let ve;t[82]!==pe||t[83]!==_e?(ve=(0,$.jsxs)(`div`,{className:`mb-3 flex gap-1 rounded-md p-1`,style:le,children:[pe,_e]}),t[82]=pe,t[83]=_e,t[84]=ve):ve=t[84];let ye;t[85]!==i||t[86]!==ee||t[87]!==o||t[88]!==c||t[89]!==_||t[90]!==B||t[91]!==l||t[92]!==H||t[93]!==u||t[94]!==j||t[95]!==y||t[96]!==r||t[97]!==v||t[98]!==x?(ye=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)(jS,{label:r(`memoryDebugPanel.metric.totalMessages`),value:B.total}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.cachedSessions`),value:`${ee} / ${ao.MAX_SESSIONS}`}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.userMessages`),value:B.user}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.assistantMessages`),value:B.assistant})]}),(0,$.jsxs)(`div`,{className:`typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[var(--surface-muted-foreground)]`,children:r(`memoryDebugPanel.metric.viewportWindow`)}),(0,$.jsx)(`span`,{className:`text-[var(--surface-foreground)]`,children:r(`memoryDebugPanel.metric.messagesValue`,{count:Za()})})]}),(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:ao.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)(xi,{outerClassName:`max-h-48`,className:`space-y-1 pr-1`,children:H.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)(Ui,{children:[(0,$.jsx)(Bi,{asChild:!0,children:(0,$.jsx)(Z,{size:`sm`,variant:`outline`,className:`typography-meta`,onClick:()=>{u.map(WS),Object.keys(_),H.map(GS),Object.fromEntries(l)},children:r(`memoryDebugPanel.actions.logState`)})}),(0,$.jsx)(Vi,{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:W,children:r(`memoryDebugPanel.actions.copyJson`)})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.uiMetrics`),value:y.entries.length}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.vscodeMetrics`),value:x.entries.length}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.messageListRenders`),value:j.messageListRender}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.messageListStreamRenders`),value:j.messageListRenderStreaming}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.chatMessageRenders`),value:j.chatMessageRender}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.chatMessageStreamRenders`),value:j.chatMessageRenderStreaming}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.chatMessageStaticDuringStream`),value:j.chatMessageRenderStaticDuringStream}),(0,$.jsx)(jS,{label:r(`memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn`),value:j.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),(0,$.jsx)(MS,{title:r(`memoryDebugPanel.section.uiStreamingMetrics`),snapshot:y,emptyLabel:r(`memoryDebugPanel.section.noUiSamples`)}),x.entries.length>0?(0,$.jsx)(MS,{title:r(`memoryDebugPanel.section.vscodeBridgeMetrics`),snapshot:x,emptyLabel:r(`memoryDebugPanel.section.noVscodeSamples`)}):null]}),t[85]=i,t[86]=ee,t[87]=o,t[88]=c,t[89]=_,t[90]=B,t[91]=l,t[92]=H,t[93]=u,t[94]=j,t[95]=y,t[96]=r,t[97]=v,t[98]=x,t[99]=ye):ye=t[99];let be;return t[100]!==ce||t[101]!==ve||t[102]!==ye?(be=(0,$.jsxs)(Ji,{className:`fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area`,style:ne,children:[ce,ve,ye]}),t[100]=ce,t[101]=ve,t[102]=ye,t[103]=be):be=t[103],be};function PS(e,t){return e+t.count}function FS(e){return e.currentSessionId}function IS(e){return e.sessionMemoryState}function LS(){return Mn()}function RS(e){return e.scope}function zS(e){return!!e}function BS(e){return e.totalRequestCount}function VS(){return Me()}function HS(){return q()}function US(e,t){return t.lastAccessed-e.lastAccessed}function WS(e){return{id:e.id,title:e.title}}function GS(e){return{id:e.id,title:e.title,total:e.messageCount,user:e.userMessageCount,assistant:e.assistantMessageCount}}var KS=()=>{let{isMobile:e,closeActiveContextPanelTab:t}=p.getState();if(e)return;let n=zo();n&&t(n)||w()&&te(`desktop_close_current_window`).catch(e=>{console.warn(`[menu-actions] failed to close current window`,e)})},qS=()=>{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()??``:``},JS=async()=>{let e=qS()||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`)},YS=`openchamber:menu-action`,XS=`openchamber:check-for-updates`,ZS=e=>typeof e?.listen==`function`?`bridge`:`dom`,QS=e=>{let t=Tn(e=>e.openNewSessionDraft),n=p(e=>e.toggleCommandPalette),r=p(e=>e.setCommandPaletteOpen),i=p(e=>e.toggleHelpDialog),a=p(e=>e.toggleSidebar),o=p(e=>e.setSessionSwitcherOpen),s=p(e=>e.setActiveMainTab),c=p(e=>e.setSettingsDialogOpen),l=p(e=>e.setSettingsPage),u=p(e=>e.setAboutDialogOpen),d=p(e=>e.toggleRightSidebar),f=p(e=>e.setRightSidebarOpen),m=p(e=>e.setRightSidebarTab),h=p(e=>e.toggleBottomTerminal),g=p(e=>e.setBottomTerminalExpanded),_=os(e=>e.checkForUpdates),{setThemeMode:v}=$i(),{t:y}=Xe(),b=Q.useRef(!1),x=typeof window>`u`?null:window.__OPENCHAMBER_DESKTOP__,S=ZS(x),C=Q.useCallback(()=>{b.current||(b.current=!0,_().then(()=>{let{available:e,error:t}=os.getState();if(t){J.error(y(`sessions.sidebar.updateCheck.errorTitle`),{description:t});return}e||J.success(y(`sessions.sidebar.updateCheck.latestVersion`))}).finally(()=>{b.current=!1}))},[_,y]),w=Q.useCallback(()=>{yn.requestDirectoryDialog()},[]),T=Q.useCallback(e=>{ai(e,Tn.getState().currentSessionId,e=>{s(`chat`),o(!1),Tn.getState().setCurrentSession(e.sessionId,e.directory)})},[s,o]),E=Q.useCallback(e=>{let{activeProjectId:t,projects:n,setActiveProject:r}=mn.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)},[]),D=Q.useCallback(_=>{switch(_){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),Aa();break;case`change-workspace`:w();break;case`close-tab-or-window`:KS();break;case`toggle-right-sidebar`:d();break;case`open-right-sidebar-git`:f(!0),m(`git`);break;case`open-right-sidebar-files`:f(!0),m(`files`);break;case`toggle-terminal`:h();break;case`toggle-terminal-expanded`:g(!p.getState().isBottomTerminalExpanded);break;case`copy`:{let e=new Event(`openchamber:copy`,{cancelable:!0});window.dispatchEvent(e)&&JS();break}case`theme-light`:v(`light`);break;case`theme-dark`:v(`dark`);break;case`theme-system`:v(`system`);break;case`toggle-sidebar`:a();break;case`toggle-memory-debug`:e?.();break;case`zoom-in`:fi();break;case`zoom-out`:ui();break;case`zoom-reset`:ri();break;case`go-back`:Pe.getState().goBack();break;case`go-forward`:Pe.getState().goForward();break;case`previous-session`:T(-1);break;case`next-session`:T(1);break;case`previous-project`:E(-1);break;case`next-project`:E(1);break;case`help-dialog`:i();break;case`download-logs`:vi().catch(()=>{J.error(`Failed to collect OpenCode status`)})}},[w,E,T,e,t,u,s,o,r,c,l,g,f,m,v,h,n,i,d,a]);Q.useEffect(()=>{if(S!==`dom`)return;let e=e=>{let t=e.detail;t&&D(t)},t=()=>{C()};return window.addEventListener(YS,e),window.addEventListener(XS,t),()=>{window.removeEventListener(YS,e),window.removeEventListener(XS,t)}},[D,C,S]),Q.useEffect(()=>{if(S!==`bridge`)return;let e=x?.listen;if(typeof e!=`function`)return;let t=null,n=null;return e(`openchamber:menu-action`,e=>{let t=e?.payload;typeof t==`string`&&D(t)}).then(e=>{t=e}).catch(()=>{}),e(`openchamber:check-for-updates`,C).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{}})()}},[x,D,C,S])},$S=(e,t)=>e<t?-1:+(e>t),eC=e=>JSON.stringify([...e.entries()].map(([e,t])=>[e,[...new Set(t)].sort($S)]).sort(([e],[t])=>$S(e,t)));async function tC({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 nC=`openchamber:tray-action`,rC=3e4,iC=120,aC=20,oC=()=>{if(typeof window>`u`)return!1;let e=window.__OPENCHAMBER_PLATFORM__;return e===`darwin`||e===`win32`},sC=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},cC=e=>{let t=Array.isArray(e.questions)?e.questions[0]:void 0;return t?.header||t?.question||`Question`},lC=e=>xt(e),uC=e=>{let t=e.replace(/\\/g,`/`).replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},dC=(e,t,n,r)=>{if(!e)return``;let i=kt(t,n,e),a=uC(i?i.path:e),o=wt(e),s=o&&r.get(o)||``;if(!s){for(let[e,t]of Wo.getState().directories)if(wt(e)===o){s=t.status?.current??``;break}}if(!s)for(let e of n.values()){let t=e.find(e=>wt(e.path)===o);if(t?.branch){s=t.branch;break}}return s?`${a} · ${s}`:a},fC=()=>{let{results:e,dropdownProviderIds:t,displayMode:n}=Ds.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 gs){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:Qi(e),value:Ki(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}},pC=async()=>{try{if(j())return`Local OpenChamber`;let e=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,t=m();if(t&&se(t,e))return`Local OpenChamber`;let n=(await de()).hosts.find(e=>t?se(t,le(e)):!1);return n?.label?.trim()?ce(n.label.trim()):`Instance`}catch{return``}},mC=()=>{let e=new Map,t=new Map,n=[],r=new Map,i;try{i=tt()}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(wt(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:sC(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:cC(r),directory:a})}}return{statusById:e,branchByDirectory:t,approvals:n,titleById:r}},hC=()=>{let e=vn.getState().activeSessions,t=new Set;e.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>lC(t)-lC(e)).slice(0,aC).forEach(e=>{let n=fn(e);n&&t.add(n)});let n=new Map;for(let r of e){if(!r?.id)continue;let e=fn(r);if(!e||!t.has(e))continue;let i=n.get(e)??[];i.push(r.id),n.set(e,i)}return n},gC=e=>{let t=mC(),n=pt.getState().index.session,r=vn.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=pn.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=mn.getState().projects,d=Tn.getState().availableWorktreesByProject,f=r.filter(e=>e?.id&&!e.parentID).slice().sort((e,t)=>lC(t)-lC(e)).slice(0,aC).map(e=>{let r=[e.id,...o(e.id)],i=fn(e)??``;return{id:e.id,title:e.title||`Untitled session`,status:l(r),branch:i?t.branchByDirectory.get(i)??``:``,unseen:n.unseenCount[e.id]??0,hasError:n.unseenHasError[e.id]??!1,directory:i,subtitle:dC(i,u,d,t.branchByDirectory)}}),m=t.approvals.map(e=>({...e,sessionTitle:i.get(e.sessionId)||``})),h=p.getState(),g=0;if(h.dockBadgeEnabled)for(let e of r)!e?.id||e.parentID||(n.unseenCount[e.id]??0)>0&&(g+=1);return{sessions:f,approvals:m,instanceName:e,usage:fC(),dockBadgeCount:g}},_C=()=>{Q.useEffect(()=>{if(!oC()||!w())return;let e=!1,t=``,n=null,r=``,i=()=>{if(e)return;let n=gC(r),i=JSON.stringify(n);i!==t&&(t=i,te(`desktop_tray_update`,n))};pC().then(t=>{e||(r=t,i())});let a=null,o=``,s=()=>{let e=Ut.getState();return e.isConnected&&e.connectionPhase===`connected`},c=()=>{if(a)return a;let t=hC();return o=eC(t),a=tC({targets:t,isReady:s,concurrency:2,isDisposed:()=>e,fetchStatus:e=>Ne.getSessionStatusForDirectory(e).catch(()=>null),applySnapshot:(e,t,n)=>{_n(e,t,[...n])}}).finally(()=>{a=null;let t=hC();!e&&s()&&eC(t)!==o&&c()}),a},l=()=>{e||n!==null||(n=window.setTimeout(()=>{n=null,i()},iC))},u=new Map,d=()=>{if(e)return;let t;try{t=tt()}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=tt().subscribeRegistry(()=>{d(),l()})}catch{}d();let m=pt.subscribe(()=>l()),h=vn.subscribe(()=>{l(),s()&&eC(hC())!==o&&c()}),g=mn.subscribe(()=>l()),_=Tn.subscribe(()=>l()),v=Wo.subscribe(()=>l()),y=p.subscribe(()=>l()),b=pn.subscribe(()=>l()),x=s(),S=Ut.subscribe(()=>{let e=s();e&&!x&&c(),x=e});x&&c();let C=Ds.subscribe(()=>l());Ds.getState().loadSettings().then(()=>{if(e)return;let{dropdownProviderIds:t,results:n}=Ds.getState();t.length>0&&t.some(e=>!n.some(t=>t.providerId===e))&&Ds.getState().fetchAllQuotas()});let T=window.setInterval(()=>{let e=Ds.getState();e.autoRefresh&&e.dropdownProviderIds.length>0&&e.fetchAllQuotas()},Math.max(3e4,Ds.getState().refreshIntervalMs||6e4)),E=window.setInterval(()=>{d(),i()},rC);return i(),()=>{e=!0,n!==null&&window.clearTimeout(n),window.clearInterval(E),window.clearInterval(T),m(),h(),g(),_(),v(),y(),b(),S(),C(),f?.();for(let e of u.values())e();u.clear()}},[]),Q.useEffect(()=>{if(!oC()||typeof window>`u`)return;let e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!=`function`)return;let t=e=>{e.type===`respond-permission`&&_t(e.sessionId,e.id,e.response).catch(()=>{J.error(`Failed to respond to permission request`)})},n=null;return e(nC,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{}}},[])},vC=`/api/notifications/stream`,yC=()=>typeof document>`u`||document.visibilityState===`visible`&&document.hasFocus(),bC=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}},xC=e=>{let t=(0,zc.c)(3),n=e?.enabled??!0,r,a;t[0]===n?(r=t[1],a=t[2]):(r=()=>{if(!n||A()||!I()||typeof window>`u`||typeof EventSource>`u`)return;let e=new EventSource(i().sse(vC));return e.onmessage=SC,()=>{e.close()}},a=[n],t[0]=n,t[1]=r,t[2]=a),Q.useEffect(r,a)};function SC(e){let t;try{t=JSON.parse(e.data)}catch{return}let n=p.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!==`always`&&yC())return;let r=bC(t);r&&oe()?.notifications?.notifyAgentCompletion(r)}var CC=`pwa-install-toast-shown`,wC=`pwa-install-toast-dismissed`,TC=()=>{let e=(0,zc.c)(6),{browserTab:t}=bs(),{t:n}=Xe(),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`||!I()||!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=c(),l=h();fc({dismissed:s.getItem(wC),sessionShown:l.getItem(CC),hasActiveToast:n!==null})&&(l.setItem(CC,`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:()=>{c().setItem(wC,`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)},EC=()=>typeof window>`u`?``:window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,DC=()=>!M()||r()===`local`,OC=e=>({id:`local`,label:`Local`,url:e}),kC=async()=>{if(!M()||DC())return{ok:!0};let e=EC(),t=await ue().catch(()=>``),n=await Wi({host:OC(e),localApiOrigin:e,localClientToken:t});return n.ok?{ok:!0}:{ok:!1,reason:n.reason}},AC=100,jC=1e4,MC=null,NC=()=>{MC&&=(MC.unsubscribe?.(),MC.openTimer!==null&&clearTimeout(MC.openTimer),MC.timeoutTimer!==null&&clearTimeout(MC.timeoutTimer),null)};function PC(){NC()}var FC=(e,t)=>{p.getState().setActiveMainTab(`chat`),Tn.getState().setCurrentSession(e,t)};function IC(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(DC()){FC(t,n);return}NC(),kC().then(e=>{if(!e.ok){Pn(t,`missing-directory`);return}if(r()===`local`){FC(t,n);return}let i=!1,a=()=>{i||(i=!0,NC(),FC(t,n))},o=l(e=>{if(e.runtimeKey!==`local`)return;o(),MC&&(MC.unsubscribe=null);let t=setTimeout(()=>{MC&&(MC.openTimer=null),a()},AC);MC&&(MC.openTimer=t)});MC={unsubscribe:o,openTimer:null,timeoutTimer:setTimeout(()=>{i||(NC(),Pn(t,`missing-directory`))},jC)}})}var LC=({open:e,onOpenChange:t})=>{let{t:n}=Xe(),[r,i]=Q.useState(null),[a,o]=Q.useState(null),[s,c]=Q.useState(!1),[l,u]=Q.useState(!1),[d,f]=Q.useState(null),[p,m]=Q.useState(!1),[h,g]=Q.useState(!1),[_,v]=Q.useState(()=>nn()),y=Ge(e=>{Nn(e),v(e)}),b=Ge(async()=>{if(!h){g(!0);try{let{outcome:e,eventCount:t}=await Ln();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{g(!1)}}});Q.useCallback(async()=>{},[d,s,!1,n]),Q.useEffect(()=>{e&&(async()=>{try{let e=await V(`/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 Je())})()},[e]),Q.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await V(`/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(()=>{f(null),m(!1)},[e,!1]);let x=r;return(0,$.jsx)(ur,{open:e,onOpenChange:t,children:(0,$.jsx)(sr,{className:`max-w-xs p-6`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,$.jsx)(da,{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:[x&&(0,$.jsx)(`p`,{children:n(`aboutDialog.openChamberVersionLabel`,{version:x})}),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)(ps,{itemId:`about.diagnostics`,checked:_,onChange:y,label:n(`settings.openchamber.about.diagnostics.label`),ariaLabel:n(`settings.openchamber.about.diagnostics.label`)}),_&&(0,$.jsx)(Z,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void b(),children:n(h?`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`)})]})})})},RC=(e,t)=>{let n=e.get(t);return typeof n==`string`&&n.trim()||null},zC=(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},BC=()=>{let e=ls(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=RC(t,`code`),a=us(t),o=ds(t),s=RC(t,`error`),c=RC(t,`error_description`);if(s){o&&V(`/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 V(`/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 V(`/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 V(`/api/mcp/auth/pending?state=${encodeURIComponent(o)}`,{method:`DELETE`}).catch(()=>void 0),n(`error`),i(zC(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`})})]})})},VC=()=>{let e=(0,zc.c)(16),t=vn(HC),n=vn(UC),r=vn(WC),i=vn(GC),{t:a}=Xe(),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 HC(e){return e.startupSyncProgress.active}function UC(e){return e.startupSyncProgress.phase}function WC(e){return e.startupSyncProgress.completed}function GC(e){return e.startupSyncProgress.total}var KC=(e,t,n,r=350)=>n?Math.max(0,r-Math.max(0,t-e)):null;function qC(e){let t=(0,zc.c)(21),{transition:n,ready:r}=e,{t:i}=Xe(),a=Xi(),[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=KC(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)(da,{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 JC=_o(()=>Fe(()=>import(`./OnboardingScreen-CYeRZznl.js`).then(e=>({default:e.OnboardingScreen})),__vite__mapDeps([100,1,5,2,3,4,6,7,8,62,12,13,14,15,16,17,18,20,70]))),YC=36e5,XC=12e5,ZC=()=>{let e=(0,zc.c)(3),t=p(iw),n=p(aw),r;return e[0]!==t||e[1]!==n?(r=(0,$.jsx)(LC,{open:t,onOpenChange:n}),e[0]=t,e[1]=n,e[2]=r):r=e[2],r},QC=e=>{let t=(0,zc.c)(21),{onRetry:n,isRetrying:r}=e,{t:i}=Xe(),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},$C=e=>e?e.replace(/\\/g,`/`).replace(/\/+$/g,``):``,ew=()=>{if(typeof window>`u`||!Ja())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`}},tw=()=>typeof window>`u`?!1:window.location.pathname===Ss,nw=e=>{let t=(0,zc.c)(22),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=e,a=Pe(ow),o=Tn(sw),s=Tn(cw),c=io(),l=Q.useRef(null),u;t[0]===n.directory?u=t[1]:(u=$C(n.directory),t[0]=n.directory,t[1]=u);let d=u,f;t[2]===a?f=t[3]:(f=$C(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)(oi,{embeddedBackgroundWorkEnabled:i}),t[14]=i,t[15]=g);let _;t[16]===n.readOnly?_=t[17]:(_=(0,$.jsx)(Vs,{readOnly:n.readOnly}),t[16]=n.readOnly,t[17]=_);let v;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Kr,{}),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 rw({apis:e}){Q.useEffect(()=>{De(`App:mounted`),ke()},[]);let t=Ut(e=>e.initializeApp),n=Ut(e=>e.isInitialized),i=Ut(e=>e.isConnected),a=Tn(e=>e.error),o=Tn(e=>e.clearError),s=Tn(e=>e.currentSessionId),c=Tn(e=>!!e.newSessionDraft?.open),f=Pe(e=>e.currentDirectory),m=Pe(e=>e.setDirectory),h=Pe(e=>e.isSwitchingDirectory),[g,_]=Q.useState(!1),v=Ts(e=>e.refreshStatus),[y,x]=Q.useState(()=>e.runtime.isVSCode),[w,T]=Q.useState(!1),[D,M]=Q.useState(!1),[N,P]=Q.useState(0),[F,I]=Q.useState(0),[L,R]=Q.useState({epoch:0,startedAt:0}),[z,B]=Q.useState(!1),H=Q.useRef(!1),U=p(e=>e.wideChatLayoutEnabled),ee=p(e=>e.mobileKeyboardMode),W=Q.useMemo(()=>A(),[]),ne=vn(e=>e.hasCachedSessionIndex),G=vn(e=>e.hasHydratedSessionIndex),re=eo(e=>e.setPlanModeEnabled),[ie,oe]=Q.useState(()=>ae()),[se,ce]=Q.useState(()=>{let e=k();return e===null?null:C({isDesktopShell:!0,bootOutcome:e})}),le=Q.useRef(!1),ue=Q.useMemo(()=>ew(),[]),de=!ue||w,fe=Q.useMemo(()=>tw(),[]);Q.useEffect(()=>(Oe(g),()=>{Oe(!1)}),[g]),Q.useEffect(()=>{d(ee)},[ee]),Q.useEffect(()=>{x(e.runtime.isVSCode)},[e.runtime.isVSCode]),Q.useEffect(()=>{let e=Zr(e=>{u(e)&&(W&&R(e=>({epoch:e.epoch+1,startedAt:Date.now()})),ac(e),I(e=>e+1),M(!1),P(e=>e+1))}),t=l(t=>e.schedule(t));return()=>{t(),e.cancel()}},[W]);let pe=St(e=>{let t=r();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(ue)return;let e=!1;return Dt().then(()=>{if(e)return;let t=r(),n=Object.values(St.getState().runsByOriginalSessionID).filter(e=>e.status===`running`&&e.runtimeKey===t);for(let e of n)Ot(e.originalSessionID)}),()=>{e=!0}},[pe,ue,F]),Q.useEffect(()=>(document.documentElement.classList.toggle(`wide-chat-layout`,U),()=>{document.documentElement.classList.remove(`wide-chat-layout`)}),[U]),Q.useEffect(()=>(O(e),()=>O(null)),[e]),Q.useEffect(()=>{if(ue)return;let t=!1;return Dt().then(()=>{t||v(e.github,{force:!0})}),()=>{t=!0}},[e.github,ue,v]),mi();let me=ie===`valid`,he=se?.screen===`main`;Q.useEffect(()=>{if(!de||!b({isDesktopShell:W,isInitialized:W&&he?ne||n&&G:n,bootOutcomeKnown:me,bootViewIsMain:he}))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)}},[de,W,n,me,he,ne,G]),Q.useEffect(()=>{if(!W||ie!==`malformed`)return;let e=document.getElementById(`initial-loading`);e&&(e.textContent=`Desktop startup failed — please restart the app.`)},[W,ie]),Q.useEffect(()=>{if(!de||W)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)}},[de,W,n]),Q.useEffect(()=>{if(!de)return;let e=!1;return(async()=>{if(await Dt(),e)return;let t=await V(`/health`,{method:`GET`}).catch(()=>null);if(!t||!t.ok||e)return;let n=await t.json().catch(()=>null);if(!n||e)return;let r=n.planModeExperimentalEnabled;re(r===!0||r===1||r===`1`||r===`true`)})(),()=>{e=!0}},[de,re]),Q.useEffect(()=>{if(!de||y)return;let e=!1;return Dt().then(()=>{if(!e)return t()}),()=>{e=!0}},[de,t,y]),Q.useEffect(()=>{if(!de||y||n)return;let e=!0,t,r=0,i=1e3,a=async()=>{if(!e)return;if(r>=10){M(!0);return}let n=Ut.getState();if(n.isInitialized){M(!1);return}if(r+=1,await Dt(),!e)return;await n.initializeApp();let o=Ut.getState();if(!e)return;if(o.isInitialized){M(!1);return}if(r>=10){M(!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)}},[de,N,n,y]),Q.useEffect(()=>{de&&n&&M(!1)},[de,n]),Q.useEffect(()=>{if(!de||!D)return;let e=document.getElementById(`initial-loading`);if(e){e.classList.add(`fade-out`);let t=setTimeout(()=>{e.remove()},300);return()=>clearTimeout(t)}},[de,D]),jr({enabled:de&&!y,source:`startupRecovery`}),Q.useEffect(()=>{h||y||i&&Ne.setDirectory(f)},[f,h,i,y]),Q.useEffect(()=>{if(!ue||typeof window>`u`)return;let e=e=>{let t=e?.visible===!0;T(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:La},window.location.origin),()=>{window.removeEventListener(`message`,t),n.__openchamberSetEmbeddedVisibility===e&&delete n.__openchamberSetEmbeddedVisibility}},[ue]),Q.useEffect(()=>{!ue?.directory||y||f!==ue.directory&&m(ue.directory,{showOverlay:!1})},[f,ue,y,m]),Q.useEffect(()=>{if(!ue||typeof window>`u`)return;let e=e=>{e.storageArea===window.localStorage&&e.key===`ui-store`&&p.persist.rehydrate()};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}},[ue]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;IC(t??{})};return window.addEventListener(`openchamber:open-session`,e),()=>{PC(),window.removeEventListener(`openchamber:open-session`,e)}},[]),Q.useEffect(()=>{if(typeof window>`u`)return;let e=()=>{let e=Pe.getState().currentDirectory,{activeProjectId:t,projects:n}=mn.getState(),r=n.find(e=>e.id===t)??null;te(`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=Tn.getState().currentSessionId;e&&It(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;p.getState().setActiveMainTab(`chat`),p.getState().setSessionSwitcherOpen(!1),Tn.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=mn.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`||!de||!n||h||le.current||(le.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event(`openchamber:app-ready`)))},[de,n,h]),Mr({enabled:de}),xC({enabled:de}),TC(),qr(),sc(),QS(Ge(()=>{_(e=>!e)})),Q.useEffect(()=>{if(!n||!E()||H.current)return;H.current=!0;let e=!1,t=null,r=null;os.getState().subscribeDesktopUpdateEvents().then(t=>{if(e){t();return}r=t});let i=()=>{let e=os.getState();e.checking||e.checkForUpdates()},a=n=>{t=window.setTimeout(()=>{e||(document.visibilityState===`visible`&&i(),a(YC))},n)},o=()=>{if(e||document.visibilityState!==`visible`)return;let t=os.getState().lastChecked;t!=null&&Date.now()-t<XC||i()};return a(0),window.addEventListener(`focus`,o),()=>{e=!0,t!==null&&window.clearTimeout(t),window.removeEventListener(`focus`,o),r&&r()}},[n]),_C(),Q.useEffect(()=>{if(ue)return;let e=e=>{tr(e)&&e.shiftKey&&!e.altKey&&(e.code===`KeyD`||e.key.toLowerCase()===`d`)&&(e.preventDefault(),_(e=>!e))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[ue]),Q.useEffect(()=>{ue||a&&setTimeout(()=>o(),5e3)},[o,ue,a]),Q.useEffect(()=>{if(!W||ie!==`not-injected`)return;let e=!1,t=0,n=()=>{if(e)return;t++;let r=ae();if(r!==`not-injected`){if(e=!0,oe(r),r===`valid`){let e=k();e&&ce(C({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}},[W,ie]);let ge=Ge(async()=>{if(S({isDesktopShell:A(),isDesktopLocalOriginActive:j()})){await K();return}window.location.reload()}),_e=Ge(async()=>{if(!z){M(!1),B(!0);try{await Dt(),await Ut.getState().initializeApp()}finally{B(!1)}Ut.getState().isInitialized||P(e=>e+1)}}),ve=e=>{if(e.screen===`recovery`)return e.variant};if(W&&se&&se.screen!==`main`){if(se.screen===`chooser`)return(0,$.jsx)(Yi,{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)(JC,{mode:`first-launch`,onCliAvailable:ge,onChooseRemote:()=>{}})})})});let e=ve(se),t=se.screen===`recovery`&&`url`in se?se.url:void 0;return(0,$.jsx)(Yi,{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)(JC,{mode:`recovery`,recoveryVariant:e,recoveryHostUrl:t,recoveryHostLabel:void 0,onCliAvailable:ge})})})})}if(ue)return ft(),(0,$.jsx)(Yi,{children:(0,$.jsx)(wn,{sdk:Ne.getSdkClient(),directory:f||``,bootstrapDirectory:!(c&&s===null),children:(0,$.jsx)(bi,{apis:e,children:(0,$.jsx)(Hi,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsx)(`div`,{className:`h-full text-foreground bg-background`,children:(0,$.jsx)(nw,{embeddedSessionChat:ue,isVSCodeRuntime:y,embeddedBackgroundWorkEnabled:de})})})})},F)});if(fe)return(0,$.jsx)(Yi,{children:(0,$.jsx)(BC,{})});if(D&&!n&&!y&&!ue)return(0,$.jsx)(Yi,{children:(0,$.jsx)(QC,{onRetry:()=>{_e()},isRetrying:z})});let ye=!n&&!W;return(0,$.jsx)(Yi,{children:(0,$.jsx)(wn,{sdk:Ne.getSdkClient(),directory:f||``,bootstrapDirectory:!(c&&s===null),children:(0,$.jsx)(bi,{apis:e,children:(0,$.jsx)($u,{children:(0,$.jsx)(Hi,{delayDuration:300,skipDelayDuration:150,children:(0,$.jsxs)(`div`,{className:W?`h-full text-foreground bg-transparent`:`h-full text-foreground bg-background`,children:[(0,$.jsx)(oi,{embeddedBackgroundWorkEnabled:de}),(0,$.jsx)($s,{}),(0,$.jsx)(qs,{}),(0,$.jsx)(kS,{}),W&&(0,$.jsx)(qC,{transition:L,ready:n&&i}),(0,$.jsx)(VC,{}),(0,$.jsx)(Kr,{}),!ye&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hs,{}),(0,$.jsx)(ZC,{}),g&&(0,$.jsx)(NS,{onClose:()=>_(!1)})]})]})})})})},F)})}function iw(e){return e.isAboutDialogOpen}function aw(e){return e.setAboutDialogOpen}function ow(e){return e.currentDirectory}function sw(e){return e.currentSessionId}function cw(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 lw=typeof window<`u`&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw Error(`Runtime APIs not provided for legacy UI entrypoint.`)})();et(),A()&&mt(),Qr({runtimeKey:r(),initializeAppearance:re,syncSettings:U,applyDirectory:Gr,startWatchers:()=>{Xr(),Jr(),Lr()},onError:(e,t)=>{console.error(e===`appearance`?`[main] appearance init failed:`:`[main] settings init failed:`,t)}});var uw=document.getElementById(`root`);if(!uw)throw Error(`Root element not found`);(0,Rc.createRoot)(uw).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Yr,{children:(0,$.jsx)(Ye,{children:(0,$.jsx)(Ir,{children:(0,$.jsx)(Br,{children:(0,$.jsx)(pi,{children:(0,$.jsx)(rw,{apis:lw})})})})})})}));
|