@openchamber/web 1.21.1 → 1.22.0
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/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/{CommitSection-DwGiXyjf.js → CommitSection-CC5mFzO2.js} +1 -1
- package/dist/assets/DiffView-6xGdyI0n.js +4 -0
- package/dist/assets/FilesView-Bm3vT63N.js +17 -0
- package/dist/assets/GitView-B6y1Y69c.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-rwHz84MX.js} +1 -1
- package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
- package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
- package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
- package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-Cvz9Z-io.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-BFMsnHk3.js} +4 -4
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-DzQlzMF4.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-C7kBQNAA.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-C3luvSd_.js} +4 -4
- package/dist/assets/{es-DwyXCqaL.js → es-CmU4HLv9.js} +3 -3
- package/dist/assets/{fr-CS7Csln9.js → fr-Bgyni40l.js} +4 -4
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-C1ImKinT.js} +4 -4
- package/dist/assets/{ko-CXuSfZv5.js → ko-CP7OdxYH.js} +4 -4
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-D5RWr6sJ.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/{pl-BJxry0Mi.js → pl-DQYSiGYX.js} +4 -4
- package/dist/assets/{pt-BR-DxLmkhdv.js → pt-BR-DytpsW4M.js} +3 -3
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
- package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
- package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/{uk-ClgQjmlw.js → uk-DwnRxJZd.js} +3 -3
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-DWXGRUPZ.js} +191 -151
- package/dist/assets/useInlineCommentController-Cc0OCXr0.js +2 -0
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/{zh-CN-Ba6y8H-i.js → zh-CN-UDNMxm7r.js} +3 -3
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +4 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/zh-TW-Dv8yyhN1.js +0 -15
|
@@ -1,926 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-MuJodAHD.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-KP8_yiGW.js","assets/index-DIvDEKE-.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-zod-BLfBSgBh.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-CUKcHnUA.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BeMD8X_w.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-C9abMBTb.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-livSKyyV.js","assets/vendor-motion-dom-D_o3BTI3.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-DrTPkHl4.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-gg7YLRW7.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-CY2bx_SB.js","assets/web-components-DOXvU-tB.js","assets/computeVirtualFileMetrics-CZ0xPeaT.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-BP7ebDFF.js","assets/isDiffPlainText-ZBvDxhVB.js","assets/vendor-diff-C3JhlQdm.js","assets/Virtualizer-D_a8gKmg.js","assets/useInlineCommentController-HIjtuhxD.js","assets/runtimeEndpointReset-D6SmNZaP.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-CjRR5ESs.js","assets/useRootScrollLock-BSiQ5F75.js","assets/scheduledTasksApi-mjMDet_H.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-Db6bjVv1.js","assets/FilesView-DQOa7Lgz.js","assets/shikiHighlight-fGmFkxAM.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-CggOsLot.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-DiLRrkJr.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-BGj8TJxW.js","assets/GitView-CHzJxTi0.js","assets/CommitSection-DwGiXyjf.js","assets/PlanView-PkiOY_9H.js","assets/SettingsWindow-oyOm2fHR.js","assets/SettingsView-D-K3ELCM.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/OnboardingScreen-C98d69Fp.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{f as Ye,R as c,j as s,r as it,h as Pm}from"./vendor-react-BUCujlKS.js";import{z as wn,A as Xo,O as Qa,D as Tm,B as Im,C as id,E as Em,F as Dn,o as Jo,G as Rm,H as dt,I as fn,u as Ae,J as Zo,K as ad,L as ld,v as ei,r as rs,m as ss,M as Fn,N as zr,e as Ln,P as Mm,a as Cs,Q as Om,R as Bm,S as Fm,T as cd,n as pn,w as _s,U as _m,V as xa,W as Lm,X as dd,Y as $m,Z as cr,_ as ya,d as Fo,$ as Mr,a0 as us,a1 as Pi,a2 as Wm,a3 as zm,i as Vm,a4 as vo,a5 as jo,a6 as Um,a7 as Ya,a8 as Hm,a9 as Km,aa as Gm,ab as qm,ac as Xa,ad as Ja,ae as Za,af as el,ag as Qm,t as tl,ah as Ym,ai as Xm,aj as Jm,x as Zm,y as ef}from"./index-DIvDEKE-.js";import{_ as sr}from"./vendor-vite-runtime-DD1OZmLC.js";import{f as ht,h as Ie,a_ as Ut,I as R,g as xn,t as Oe,a$ as Js,b0 as Ls,b1 as Zs,b2 as en,b3 as io,y as qe,u as Es,A as wa,C as ud,b4 as Ti,b5 as tf,b6 as md,b7 as fd,r as Us,b8 as hd,b9 as Sa,ba as ti,bb as pd,bc as gd,bd as sf,be as sl,bf as nf,bg as rf,bh as va,bi as Ii,bj as of,bk as af,K as bd,bl as lf,a7 as bt,a8 as xt,a6 as yt,bm as ko,l as Kt,V as Pn,bn as cf,b as Ht,n as dr,bo as zn,as as er,bp as xd,bq as df,br as uf,bs as mf,bt as ff,p as hf,bu as yd,bv as pf,bw as gf,bx as bf,by as wd,bz as Sd,bA as xf,at as ja,bB as Jn,bC as eo,bD as yf,bE as Ns,bF as As,bG as Hs,bH as Rs,bI as Ms,bJ as Sn,B as at,an as Xs,G as wf,L as nr,o as si,bK as nl,bL as Sf,bM as vf,bN as Ys,bO as ni,bP as vd,bQ as Ei,bR as jf,bS as $s,bT as Ws,bU as Is,bV as zs,bW as ns,S as Nn,bX as ur,bY as rl,bZ as hr,M as ri,ab as to,ac as ka,b_ as jd,af as $n,b$ as oi,c0 as An,a1 as Ca,c1 as kf,c2 as Cf,am as Nf,c3 as Af,c4 as Df,c5 as Pf,ao as Na,c6 as Aa,c7 as Fr,c8 as kd,c9 as Tf,ca as If,cb as so,cc as Ef,O as Cd,cd as Rf,ce as rr,cf as Mf,cg as Of,ch as ui,ci as Nd,cj as Ad,ck as Bf,cl as Ri,cm as Ff,cn as ol,co as Dd,cp as Or,c as Vr,d as Da,Z as _f,cq as Pd,cr as Nr,cs as Br,ct as Lf,cu as $f,cv as Wf,W as Td,ap as zf,cw as Vf,cx as Uf,cy as Hf,cz as Kf,cA as Id,cB as yn,cC as Gf,cD as qf,cE as Mi,cF as Qf,cG as Yf,cH as Ed,cI as Xf,cJ as Rd,$ as _o,cK as il,Q as Pa,N as Ta,R as Ia,cL as Ea,a as Ra,_ as Jf,cM as al,cN as Oi,cO as Md,cP as Zf,cQ as Od,cR as eh,P as Bi,H as th,cS as ll,cT as sh,cU as cl,cV as nh,cW as ms,cX as rh,cY as Wn,cZ as Ma,c_ as Bd,c$ as oh,d0 as Fd,d1 as ih,D as ah,d2 as lh,d3 as ch,d4 as dh,d5 as dl,d6 as uh,d7 as mh,d8 as _d,E as fh,d9 as Co,da as Ld,db as hh,dc as ph,dd as gh,de as bh,e as $d,df as Oa,dg as xh,dh as Ur,di as yh,dj as ul,dk as wh,dl as Sh,dm as vh,Y as jh,dn as kh,aF as Fi,a2 as ml,aJ as fl,a3 as hl,dp as Ch,J as Nh,dq as Ah,dr as Dh,ds as Ph,dt as Wd,du as zd,dv as Vd,dw as Th,F as Ba,dx as Ih,a0 as Eh,dy as Rh,dz as Mh,dA as Oh,dB as Bh,dC as Fh,dD as _h,dE as Lh,dF as $h,dG as Lo,ad as Wh,ae as zh,dH as Vh,dI as pl,dJ as Uh,dK as Hh,dL as Kh,dM as Gh,dN as $o,dO as qh,dP as gl,dQ as Qh,dR as Yh,dS as Xh,dT as Jh,dU as Zh,dV as No,dW as ep,dX as tp,i as sp,dY as np,dZ as rp,d_ as op,d$ as ip,a4 as ap,e0 as lp,e1 as cp,e2 as dp,e3 as up,e4 as bl,e5 as mp,az as fp,aA as hp,aB as pp,aD as xl,aE as yl,aH as wl,aG as Ud,aI as Hd,e6 as gp,aV as bp,aW as xp,aX as yp,aY as wp,aZ as Sp,aR as vp,aS as jp,aT as kp,aU as Cp}from"./useAppFontEffects-KP8_yiGW.js";import{u as Kd,S as Sl,C as Np,W as Gd,f as Ap,a as Dp}from"./useRootScrollLock-BSiQ5F75.js";import{U as qd,h as vl,i as Yt,n as Pp,j as jl,t as jn,k as Tp,l as mi,m as Ip,o as Ep,q as _i,s as Li,b as Qd,v as Yd,w as Xd,x as $i,y as qn,z as Jd,A as Zd,P as Rp,T as Mp,B as Op,E as Bp,F as Fp,S as kl,G as _p,H as Lp,I as $p,u as _r,N as Wp,D as zp,W as Vp,L as Cl,J as Up,d as Hp,f as eu,g as Kp,K as Gp,M as qp,Q as Qp,c as Yp,e as Xp,O as tu,C as Jp}from"./runtimeEndpointReset-D6SmNZaP.js";import{u as Un,n as Zp,f as eg,a as Nl,s as tg,d as sg,b as ng,r as rg}from"./scheduledTasksApi-mjMDet_H.js";import{f as Hr,h as _n,T as su,M as nu,D as Kr,j as Gr,d as og,P as Wi,b as ig,k as zi,i as ag}from"./vendor-dnd-kit-core-BZknOX2w.js";import{u as ii,S as Wo,h as lg,a as ru,v as Vi,s as cg}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as ai}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{S as ou,M as iu,C as au,a as Ui,b as Hi,c as Ki,d as lu,e as dg,f as ug}from"./vendor-base-ui-BeMD8X_w.js";import{c as or,u as tr,d as cu,p as mg}from"./vendor-zustand-BAGL70zf.js";import{g as fg,b as hg,E as du,c as pg,d as gg,e as bg,f as xg,i as yg}from"./contextPanelEmbeddedChat-C9abMBTb.js";import{a as Fa,s as vr,r as uu}from"./vendor-zod-BLfBSgBh.js";import{u as wg}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{d as mu}from"./vendor-cron-parser-CUcP7OfX.js";const Sg="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",vg="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",fi=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?Sg:t.id==="terminal"?vg:void 0}),Al=t=>{const e=Ye.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[o,l]=c.useState(!1);let a;e[0]!==n?(a=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=a):a=e[1];const d=a,u=r||i;if(u&&!o){let y;e[2]===Symbol.for("react.memo_cache_sentinel")?(y=()=>l(!0),e[2]=y):y=e[2];let b;return e[3]!==u?(b=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:y}),e[3]=u,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=Ie("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let h;return e[6]!==d?(h=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=h):h=e[7],h},jg=t=>{const e=Ye.c(75),{directory:n,className:r}=t,{t:i}=ht(),o=Un(kg),l=Un(Cg),a=Un(Ng),d=Un(Ag),u=Un(Dg),m=Un(Pg),h=Un(Tg);let y,b;e[0]!==u?(y=()=>{u()},b=[u],e[0]=u,e[1]=y,e[2]=b):(y=e[1],b=e[2]),c.useEffect(y,b);const S=wn()&&Xo();let v;e:{let W;e[3]!==l||e[4]!==o?(W=l.find(F=>F.id===o)??l.find(Ig)??l[0]??Qa[0],e[3]=l,e[4]=o,e[5]=W):W=e[5];const ne=W;if(ne){let F;e[6]!==ne?(F=fi(ne),e[6]=ne,e[7]=F):F=e[7],v=F;break e}let Y;e[8]===Symbol.for("react.memo_cache_sentinel")?(Y=fi(Qa[0]),e[8]=Y):Y=e[8],v=Y}const g=v;if(!S||!n||l.length===0)return null;let f;e[9]!==n?(f=async W=>{await Im(n,W.id,W.appName)||await id(n,W.appName)},e[9]=n,e[10]=f):f=e[10];const x=f;let p;e[11]!==x||e[12]!==h?(p=async W=>{await h(W.id),await x(W)},e[11]=x,e[12]=h,e[13]=p):p=e[13];const w=p;let N;e[14]!==n||e[15]!==i?(N=async()=>{(await xn(n)).ok&&Oe.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=N):N=e[16];const C=N;let k;e[17]!==r?(k=Ie("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=k):k=e[18];let A;e[19]!==x||e[20]!==g?(A=()=>{x(g)},e[19]=x,e[20]=g,e[21]=A):A=e[21];const D=d&&"animate-pulse";let P;e[22]!==D?(P=Ie("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",D),e[22]=D,e[23]=P):P=e[23];let M;e[24]!==g.label||e[25]!==i?(M=i("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=i,e[26]=M):M=e[26];let z;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(z=s.jsx(Al,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=z):z=e[30];let I;e[31]!==P||e[32]!==M||e[33]!==z||e[34]!==A?(I=s.jsx("button",{type:"button",onClick:A,className:P,"aria-label":M,children:z}),e[31]=P,e[32]=M,e[33]=z,e[34]=A,e[35]=I):I=e[35];let V;e[36]===Symbol.for("react.memo_cache_sentinel")?(V=Ie("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=V):V=e[36];let T;e[37]!==i?(T=i("openInApp.actions.chooseAppAria"),e[37]=i,e[38]=T):T=e[38];let _;e[39]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=_):_=e[39];let O;e[40]!==T?(O=s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:V,"aria-label":T,children:_})}),e[40]=T,e[41]=O):O=e[41];let j;e[42]!==C?(j=()=>{C()},e[42]=C,e[43]=j):j=e[43];let E;e[44]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(R,{name:"file-copy",className:"h-4 w-4"}),e[44]=E):E=e[44];let L;e[45]!==i?(L=i("openInApp.actions.copyPath"),e[45]=i,e[46]=L):L=e[46];let U;e[47]!==L?(U=s.jsx("span",{className:"typography-ui-label text-foreground",children:L}),e[47]=L,e[48]=U):U=e[48];let X;e[49]!==j||e[50]!==U?(X=s.jsxs(Ut,{className:"flex items-center gap-2",onClick:j,children:[E,U]}),e[49]=j,e[50]=U,e[51]=X):X=e[51];let Q;e[52]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Ls,{}),e[52]=Q):Q=e[52];let me;if(e[53]!==l||e[54]!==w||e[55]!==g.id){let W;e[57]!==w||e[58]!==g.id?(W=ne=>{const Y=fi(ne);return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{w(ne)},children:[s.jsx(Al,{label:ne.label,iconDataUrl:ne.iconDataUrl,fallbackIconDataUrl:Y.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ne.label}),g.id===ne.id?s.jsx(R,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ne.id)},e[57]=w,e[58]=g.id,e[59]=W):W=e[59],me=l.map(W),e[53]=l,e[54]=w,e[55]=g.id,e[56]=me}else me=e[56];let re;e[60]!==a||e[61]!==m||e[62]!==i?(re=a?s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(R,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[60]=a,e[61]=m,e[62]=i,e[63]=re):re=e[63];let G;e[64]!==X||e[65]!==me||e[66]!==re?(G=s.jsxs(Zs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[X,Q,me,re]}),e[64]=X,e[65]=me,e[66]=re,e[67]=G):G=e[67];let ee;e[68]!==O||e[69]!==G?(ee=s.jsxs(en,{children:[O,G]}),e[68]=O,e[69]=G,e[70]=ee):ee=e[70];let ue;return e[71]!==I||e[72]!==ee||e[73]!==k?(ue=s.jsxs("div",{className:k,children:[I,ee]}),e[71]=I,e[72]=ee,e[73]=k,e[74]=ue):ue=e[74],ue};function kg(t){return t.selectedAppId}function Cg(t){return t.availableApps}function Ng(t){return t.isCacheStale}function Ag(t){return t.isScanning}function Dg(t){return t.initialize}function Pg(t){return t.loadInstalledApps}function Tg(t){return t.selectApp}function Ig(t){return t.id===Tm}const Eg=({transform:t})=>({...t,y:0}),Rg={Item:Ut,Separator:Ls},Mg={Item:({className:t,...e})=>s.jsx(iu,{className:Ie(fd,t),...e}),Separator:({className:t,...e})=>s.jsx(ou,{className:Ie(md,t),...e})},Og=t=>{const e=Ye.c(62),{tab:n,isActive:r,suppressControls:i,onSelect:o,onClose:l,renderMenu:a,closeOtherTabs:d,onMenuOpenChangeComplete:u,children:m}=t,{t:h}=ht(),[y,b]=c.useState(!1),[S,v]=c.useState(!1),[g,f]=c.useState(!1);let x;e[0]!==n.id?(x={id:n.id},e[0]=n.id,e[1]=x):x=e[1];const{attributes:p,listeners:w,setNodeRef:N,transform:C,transition:k,isDragging:A}=ii(x);let D;e[2]!==h||e[3]!==n.session.title?(D=n.session.title?.trim()||h("sessions.sidebar.session.untitled"),e[2]=h,e[3]=n.session.title,e[4]=D):D=e[4];const P=D,M=!i&&(y||S),z=wa(n.id),I=z?.type==="busy"||z?.type==="retry",T=ud(n.id)>0&&!r&&!I,_=I||T;let O;e[5]!==I||e[6]!==h?(O=h(I?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),e[5]=I,e[6]=h,e[7]=O):O=e[7];const j=O;let E;e[8]!==d||e[9]!==r||e[10]!==o||e[11]!==n?(E=xe=>({session:n.session,isActive:r,select:()=>o(n),closeOtherTabs:()=>d(n.id),components:xe}),e[8]=d,e[9]=r,e[10]=o,e[11]=n,e[12]=E):E=e[12];const L=E;let U;e[13]!==C?(U=ai.Translate.toString(C),e[13]=C,e[14]=U):U=e[14];let X;e[15]!==U||e[16]!==k?(X={transform:U,transition:k},e[15]=U,e[16]=k,e[17]=X):X=e[17];const Q=A&&"z-10 opacity-60";let me;e[18]!==Q?(me=Ie("session-tab-slot flex h-7 w-44 shrink-0 touch-none",Q),e[18]=Q,e[19]=me):me=e[19];const re=r?"true":"false";let G;e[20]!==r?(G=r?{"data-active-session-tab":!0}:{},e[20]=r,e[21]=G):G=e[21];let ee;e[22]!==u?(ee=xe=>u?.(xe),e[22]=u,e[23]=ee):ee=e[23];let ue;e[24]!==m||e[25]!==j||e[26]!==r||e[27]!==I||e[28]!==L||e[29]!==y||e[30]!==l||e[31]!==u||e[32]!==o||e[33]!==M||e[34]!==a||e[35]!==_||e[36]!==i||e[37]!==h||e[38]!==n||e[39]!==P?(ue=s.jsx(au,{render:xe=>s.jsxs("div",{...xe,role:"tab","aria-selected":r,tabIndex:r?void 0:0,onClick:r?void 0:()=>o(n),onKeyDown:r?void 0:ge=>{(ge.key==="Enter"||ge.key===" ")&&(ge.preventDefault(),o(n))},onAuxClick:ge=>{ge.button===1&&(ge.preventDefault(),l(n.id))},"data-controls-open":M?"true":"false",className:Ie("session-tab group/session-tab relative flex h-7 w-full min-w-0 select-none items-center rounded-md px-2","transition-colors duration-75",r?"bg-interactive-selection":Ie("cursor-pointer text-muted-foreground hover:bg-interactive-hover hover:text-foreground",M&&"bg-interactive-hover text-foreground")),children:[s.jsxs("div",{className:Ie("flex min-w-0 flex-1 items-center",!i&&"group-hover/session-tab:pr-10",M&&"pr-10"),children:[s.jsx("div",{className:Ie("min-w-0 flex-1 overflow-hidden whitespace-nowrap",!i&&"session-tab-title"),children:r?m:s.jsx("span",{className:"text-[13px] font-medium leading-4",children:P})}),_?s.jsx("span",{className:Ie("ml-1.5 h-1.5 w-1.5 shrink-0 rounded-full",I?"bg-primary":"bg-[var(--status-info)]",!i&&"group-hover/session-tab:opacity-0",M&&"opacity-0"),"aria-label":j}):null]}),i?null:s.jsxs("div",{onClick:Fg,onPointerDown:_g,className:Ie("absolute right-1 top-1/2 hidden -translate-y-1/2 items-center gap-0.5","opacity-0 transition-opacity duration-150","group-hover/session-tab:flex group-hover/session-tab:opacity-100",M&&"flex opacity-100"),children:[s.jsxs(en,{open:y,onOpenChange:ge=>{b(ge),ge&&v(!0)},onOpenChangeComplete:ge=>{ge||v(!1),u?.(ge)},children:[s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":h("header.sessionTabs.tabMenuAria"),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"more",className:"size-4"})})}),s.jsx(Zs,{align:"start",className:"min-w-[190px]",children:a(L(Rg))})]}),s.jsx("button",{type:"button","aria-label":h("header.sessionTabs.closeTab"),onClick:()=>l(n.id),className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]})]})}),e[24]=m,e[25]=j,e[26]=r,e[27]=I,e[28]=L,e[29]=y,e[30]=l,e[31]=u,e[32]=o,e[33]=M,e[34]=a,e[35]=_,e[36]=i,e[37]=h,e[38]=n,e[39]=P,e[40]=ue):ue=e[40];let W,ne;e[41]===Symbol.for("react.memo_cache_sentinel")?(W={color:"var(--surface-elevated-foreground)"},ne=Ie(Ti,"min-w-[190px]"),e[41]=W,e[42]=ne):(W=e[41],ne=e[42]);let Y;e[43]!==L||e[44]!==a?(Y=a(L(Mg)),e[43]=L,e[44]=a,e[45]=Y):Y=e[45];let F;e[46]!==Y?(F=s.jsx(Ui,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Ki,{"data-slot":"dropdown-menu-content",style:W,className:ne,children:Y})})}),e[46]=Y,e[47]=F):F=e[47];let J;e[48]!==g||e[49]!==ee||e[50]!==ue||e[51]!==F?(J=s.jsxs(lu,{open:g,onOpenChange:f,onOpenChangeComplete:ee,children:[ue,F]}),e[48]=g,e[49]=ee,e[50]=ue,e[51]=F,e[52]=J):J=e[52];let ie;return e[53]!==p||e[54]!==w||e[55]!==N||e[56]!==G||e[57]!==J||e[58]!==X||e[59]!==me||e[60]!==re?(ie=s.jsx("div",{ref:N,style:X,className:me,"data-active":re,...G,...p,...w,children:J}),e[53]=p,e[54]=w,e[55]=N,e[56]=G,e[57]=J,e[58]=X,e[59]=me,e[60]=re,e[61]=ie):ie=e[61],ie},Bg=t=>{const e=Ye.c(64),{renderMenu:n,onMenuOpenChangeComplete:r,suppressActiveTabControls:i,children:o}=t,l=i===void 0?!1:i,{t:a}=ht(),d=io(Lg),u=io($g),m=io(Wg),h=io(zg),y=qe(Vg),b=qe(Ug),S=Es(Hg);let v,g;e[0]!==y||e[1]!==u?(v=()=>{y&&u(y)},g=[y,u],e[0]=y,e[1]=u,e[2]=v,e[3]=g):(v=e[2],g=e[3]),c.useEffect(v,g);let f;if(e[4]!==S){f=new Map;for(const ce of S)f.set(ce.id,ce);e[4]=S,e[5]=f}else f=e[5];const x=f;let p;if(e[6]!==x||e[7]!==d){p=[];for(const ce of d){const ye=x.get(ce);ye&&p.push({id:ce,session:ye})}e[6]=x,e[7]=d,e[8]=p}else p=e[8];const w=p;let N;e[9]!==b?(N=ce=>{b(ce.id,Us(ce.session))},e[9]=b,e[10]=N):N=e[10];const C=N,k=Kg;let A;e[11]!==m||e[12]!==y||e[13]!==C||e[14]!==w?(A=ce=>{if(m(ce),y&&y!==ce){const ye=w.find(be=>be.id===ce);ye&&C(ye)}},e[11]=m,e[12]=y,e[13]=C,e[14]=w,e[15]=A):A=e[15];const D=A;let P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P={activationConstraint:{distance:8}},e[16]=P):P=e[16];let M;e[17]===Symbol.for("react.memo_cache_sentinel")?(M={activationConstraint:{delay:200,tolerance:6}},e[17]=M):M=e[17];const z=Hr(_n(nu,P),_n(su,M));let I;e[18]!==h?(I=ce=>{const{active:ye,over:be}=ce;be&&ye.id!==be.id&&h(String(ye.id),String(be.id))},e[18]=h,e[19]=I):I=e[19];const V=I,T=c.useRef(null);let _;e[20]===Symbol.for("react.memo_cache_sentinel")?(_={left:!1,right:!1},e[20]=_):_=e[20];const[O,j]=c.useState(_);let E;e[21]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{const ce=T.current;if(!ce)return;const ye=ce.scrollLeft>2,be=ce.scrollLeft+ce.clientWidth<ce.scrollWidth-2;j(te=>te.left===ye&&te.right===be?te:{left:ye,right:be})},e[21]=E):E=e[21];const L=E;let U;e[22]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{L();const ce=T.current;if(!ce||!globalThis.ResizeObserver)return;const ye=new ResizeObserver(L);return ye.observe(ce),()=>ye.disconnect()},e[22]=U):U=e[22];let X;e[23]!==w.length?(X=[L,w.length],e[23]=w.length,e[24]=X):X=e[24],c.useEffect(U,X);let Q;e[25]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{T.current?.querySelector("[data-active-session-tab]")?.scrollIntoView({block:"nearest",inline:"nearest"})},e[25]=Q):Q=e[25];let me;e[26]!==y?(me=[y],e[26]=y,e[27]=me):me=e[27],c.useEffect(Q,me);const re=O.left&&O.right?"linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent)":O.left?"linear-gradient(to right, transparent, black 24px)":O.right?"linear-gradient(to right, black calc(100% - 24px), transparent)":void 0;let G;e[28]!==w?(G=w.map(Gg),e[28]=w,e[29]=G):G=e[29];const ee=G;let ue;e[30]!==y||e[31]!==w?(ue=!y||!w.some(ce=>ce.id===y),e[30]=y,e[31]=w,e[32]=ue):ue=e[32];const W=ue;let ne;e[33]!==a?(ne=a("header.sessionTabs.stripAria"),e[33]=a,e[34]=ne):ne=e[34];let Y;e[35]!==re?(Y=re?{maskImage:re,WebkitMaskImage:re}:void 0,e[35]=re,e[36]=Y):Y=e[36];let F;e[37]===Symbol.for("react.memo_cache_sentinel")?(F=[Eg],e[37]=F):F=e[37];let J;e[38]!==o||e[39]!==y||e[40]!==D||e[41]!==C||e[42]!==r||e[43]!==n||e[44]!==l||e[45]!==w?(J=w.map(ce=>s.jsx(Og,{tab:ce,isActive:ce.id===y,suppressControls:ce.id===y&&l,onSelect:C,onClose:k,renderMenu:n,closeOtherTabs:D,onMenuOpenChangeComplete:r,children:ce.id===y?o:null},ce.id)),e[38]=o,e[39]=y,e[40]=D,e[41]=C,e[42]=r,e[43]=n,e[44]=l,e[45]=w,e[46]=J):J=e[46];let ie;e[47]!==J||e[48]!==ee?(ie=s.jsx(Wo,{items:ee,strategy:lg,children:J}),e[47]=J,e[48]=ee,e[49]=ie):ie=e[49];let xe;e[50]!==V||e[51]!==z||e[52]!==ie?(xe=s.jsx(Kr,{sensors:z,collisionDetection:Gr,modifiers:F,onDragEnd:V,children:ie}),e[50]=V,e[51]=z,e[52]=ie,e[53]=xe):xe=e[53];let ge;e[54]!==o||e[55]!==W?(ge=W?s.jsx("div",{role:"tab","aria-selected":!0,className:"session-tab-slot flex h-7 w-44 shrink-0 items-center rounded-md bg-interactive-selection px-2","data-active":"true",children:s.jsx("div",{className:"min-w-0 flex-1",children:o})}):null,e[54]=o,e[55]=W,e[56]=ge):ge=e[56];let Ce;e[57]!==Y||e[58]!==xe||e[59]!==ge?(Ce=s.jsxs("div",{ref:T,onScroll:L,className:"session-tabs-scroll flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overscroll-x-contain",style:Y,children:[xe,ge]}),e[57]=Y,e[58]=xe,e[59]=ge,e[60]=Ce):Ce=e[60];let Re;return e[61]!==ne||e[62]!==Ce?(Re=s.jsx("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center",role:"tablist","aria-label":ne,children:Ce}),e[61]=ne,e[62]=Ce,e[63]=Re):Re=e[63],Re};function Fg(t){return t.stopPropagation()}function _g(t){return t.stopPropagation()}function Lg(t){return t.tabIds}function $g(t){return t.ensureTab}function Wg(t){return t.closeOtherTabs}function zg(t){return t.reorderTabs}function Vg(t){return t.currentSessionId}function Ug(t){return t.setCurrentSession}function Hg(t){return t.activeSessions}function Kg(t){tf(t)}function Gg(t){return t.id}function qg(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(Sa(),{month:"short"}),r=e.getDate(),i=e.getFullYear(),o=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${i}, ${o}:${l}`}function Qg(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function Yg(t){const e=t.info.role==="user"?"User":"Assistant",n=qg(t.info.time?.created),r=Qg(t),i=n&&r?`${n} (${r})`:n||r;return i?`**${e}**
|
|
3
|
-
|
|
4
|
-
*${i}*`:`**${e}**`}function Xg(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function fu(t){const e=Yg(t),n=Xg(t.parts).trim();return n?`${e}
|
|
5
|
-
|
|
6
|
-
${n}`:""}function hu(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",i=`${n} Sub-agent: ${t.title}${r}
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
`,o=t.records.map(fu).filter(Boolean).join(`
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
`),l=[i+o];for(const a of t.children)l.push(hu(a,e+1));return l.join(`
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
`)}function pu(t,e,n){const r=e?.trim()||"Session",i=new Date().toISOString().split("T")[0],o=`# ${r}
|
|
19
|
-
|
|
20
|
-
*Exported on ${i}*
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
`,l=t.map(fu).filter(Boolean).join(`
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
`);let a=o+l;if(n&&n.length>0){const d=n.map(u=>hu(u,1)).join(`
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
`);a+=`
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
`+d}return a}function gu(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}async function bu(t,e){const n=await Em(e,t);if(n)return n;if(!Dn())return null;try{const r=await Jo()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const i=typeof r.path=="string"?r.path.trim():"";return i.length>0?i:null}catch{return null}}async function Jg(t){const e=Jo()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Rm(t)?!0:id(t)}function Zg(){return hd()}function xu(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",i=new Date().toISOString().split("T")[0];return`${r}-${i}.md`}const Gi=(t,e)=>({success:t(e.success),failure:t(e.failure),sourceVerificationFailed:t("sessions.sidebar.session.moveToWorktree.sourceVerificationFailed"),applyChangesFailed:t("sessions.sidebar.session.moveToWorktree.applyChangesFailed"),changesMayBeInDestination:t("sessions.sidebar.session.moveToWorktree.changesMayBeInDestination")}),Vn=or(()=>({pendingSessionIds:new Set,requestingSessionIds:new Set,confirmation:null})),yu=t=>{const e=Ye.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t)||r.requestingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],Vn(n)},eb=()=>Vn(db),wu=()=>Vn.getState().confirmation,_a=t=>{Vn.setState(e=>e.confirmation===t?e:{...e,confirmation:t})},Dl=(t,e)=>{Vn.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{...n,pendingSessionIds:r}})},mr=(t,e)=>{Vn.setState(n=>{if(n.requestingSessionIds.has(t)===e)return n;const r=new Set(n.requestingSessionIds);return e?r.add(t):r.delete(t),{...n,requestingSessionIds:r}})},tb="Unable to apply your changes in the destination directory",sb=t=>t.status===400&&t.message.includes(tb),nb=async(t,e)=>{try{const d=(await pd(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=dt(t),r=dt(e)??e,i=qe.getState().availableWorktreesByProject,l=(i.get(r)??i.get(e)??[]).find(a=>dt(a.path)===n)?.branch?.trim();if(l)return l;throw new Error("Unable to determine the current branch")},Pl=t=>{for(const e of t){const n=nf(e.id);if(n==="unknown")throw new Error("Session status is unavailable");if(n==="active")throw new Error("Session is not idle")}};class Su extends Error{changesMayBeInDestination;constructor(e,n,r){super(e,{cause:n}),this.name="IncompleteRollbackError",this.changesMayBeInDestination=r}}const rb=(t,e,n)=>{const r=e.map(({sessionId:i,error:o})=>`${i}: ${o.message}`).join(", ");return new Su(`Session move partially failed and could not be fully rolled back: ${t.message}. Rollback failures: ${r}`,{moveError:t,rollbackFailures:e},n)},ob=async(t,e,n,r)=>{const i=[];for(const o of[...t].reverse()){if(rf(o.id)){i.push({sessionId:o.id,error:new Error("Session is not idle")});continue}try{await gd(o,n,e,!1),qe.getState().setWorktreeMetadata(o.id,r.get(o.id)??null)}catch(l){i.push({sessionId:o.id,error:l instanceof Error?l:new Error(String(l))})}}return i};class vu extends Error{constructor(e){super(e.message,{cause:e}),this.name="ChangesMayBeInDestinationError"}}const Tl=async(t,e,n)=>{try{await bd(t,e,{deleteLocalBranch:!0})}catch{throw new Error(`Session move failed and the new worktree could not be removed: ${n.message}`)}throw n},Il=async(t,e)=>{const n=e?[t,e]:[t];try{await va(n)}catch(r){console.warn("[session-worktree-move] Failed to refresh moved sessions",r)}},ju=async(t,e)=>{if(Vn.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");Dl(t.root.id,!0);try{const n=[...t.descendants,t.root],r=new Map(n.map(a=>[a.id,qe.getState().getWorktreeMetadata(a.id)]));Pl(n);let i=null;const o=[];let l=!1;try{i=await e();for(const[a,d]of n.entries()){Pl(n.slice(a));const u=d.id===t.root.id&&t.moveChanges;try{await gd(d,t.sourceDirectory,i.directory,u)}catch(m){throw u&&sf(m)&&(l=!0),m}o.push(d),d.id!==t.root.id&&qe.getState().setWorktreeMetadata(d.id,sl(i.metadata))}}catch(a){const d=a instanceof Error?a:new Error(String(a)),u=await ob(o,t.sourceDirectory,i?.directory??t.sourceDirectory,r);if(l&&await Il(t.sourceDirectory,i?.directory),u.length>0)throw rb(d,u,l);if(l)throw new vu(d);if(i?.onMoveFailure)return i.onMoveFailure(d);throw d}return qe.getState().setWorktreeMetadata(t.root.id,sl(i.metadata)),await Il(t.sourceDirectory,i.directory),i.directory}finally{Dl(t.root.id,!1)}},ib=async t=>{const e=dt(t.sourceDirectory)??t.sourceDirectory,n=dt(t.destination.path)??t.destination.path;if(e===n)throw new Error("Source and destination are the same");if(t.destination.worktreeStatus!=="ready")throw new Error("Destination worktree is not ready");return ju(t,async()=>({directory:t.destination.path,metadata:t.destination}))},ab=async t=>ju(t,async()=>{const e=Ii(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=await ti(t.sourceDirectory)?await nb(t.sourceDirectory,e.path):null,r=await of(e,n?{startRef:n}:{});try{await af(r.path)}catch(i){const o=i instanceof Error?i:new Error(String(i));return Tl(e,r,o)}return{directory:r.path,metadata:r,onMoveFailure:async i=>Tl(e,r,i)}}),lb=(t,e,n)=>e instanceof vu?t.changesMayBeInDestination:e instanceof Su&&e.changesMayBeInDestination?`${e.message} ${t.changesMayBeInDestination}`:n&&sb(e)?t.applyChangesFailed:e.message,qi=(t,e)=>{(t.kind==="existing"?ib({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,destination:t.destination,moveChanges:e}):ab({root:t.root,descendants:t.descendants,sourceDirectory:t.sourceDirectory,moveChanges:e})).then(()=>Oe.success(t.messages.success)).catch(r=>{const i=r instanceof Error?r:new Error(String(r));Oe.error(t.messages.failure,{description:lb(t.messages,i,e)})})},cb=()=>{const t=wu();t&&(mr(t.intent.root.id,!1),_a(null))},ku=t=>{const e=wu();if(!e)return;const{intent:n}=e;_a(null),mr(n.root.id,!1),qi(n,t)},Qi=t=>{const e=Vn.getState();e.confirmation||e.pendingSessionIds.has(t.root.id)||e.requestingSessionIds.has(t.root.id)||(mr(t.root.id,!0),(async()=>{try{if(!await ti(t.sourceDirectory)){mr(t.root.id,!1),qi(t,!1);return}const r=await pd(t.sourceDirectory);if(r.isClean){mr(t.root.id,!1),qi(t,!1);return}const i=r.files.filter(o=>{const l=o.index.trim();return l!==""&&l!=="?"}).length;_a({intent:t,dirtyFileCount:r.files.length,stagedFileCount:i})}catch{Oe.error(t.messages.failure,{description:t.messages.sourceVerificationFailed}),mr(t.root.id,!1)}})())};function db(t){return t.confirmation}const qr="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",ub=c.memo(function(e){const n=Ye.c(17),{visible:r,title:i,ariaLabel:o,onClick:l,className:a,Icon:d,iconClassName:u,pressed:m}=e,h=r===void 0?!0:r,y=m===void 0?!1:m;if(!h)return null;const b=a??qr,S=y&&"bg-interactive-selection text-interactive-selection-foreground";let v;n[0]!==b||n[1]!==S?(v=Ie(b,S),n[0]=b,n[1]=S,n[2]=v):v=n[2];const g=u??"h-[18px] w-[18px]";let f;n[3]!==d||n[4]!==g?(f=s.jsx(R,{name:d,className:g}),n[3]=d,n[4]=g,n[5]=f):f=n[5];let x;n[6]!==o||n[7]!==l||n[8]!==y||n[9]!==v||n[10]!==f?(x=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":o,"aria-pressed":y,className:v,children:f})}),n[6]=o,n[7]=l,n[8]=y,n[9]=v,n[10]=f,n[11]=x):x=n[11];let p;n[12]!==i?(p=s.jsx(xt,{children:s.jsx("p",{children:i})}),n[12]=i,n[13]=p):p=n[13];let w;return n[14]!==x||n[15]!==p?(w=s.jsxs(yt,{children:[x,p]}),n[14]=x,n[15]=p,n[16]=w):w=n[16],w}),mb=c.memo(function(e){const n=Ye.c(42),{isMobile:r,githubAuthStatus:i,githubAccounts:o,githubAvatarUrl:l,githubLogin:a,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:m}=ht();if(!i?.connected||r)return null;if(o.length>1){let S;n[0]===Symbol.for("react.memo_cache_sentinel")?(S=Ie(qr,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=S):S=n[0];let v;n[1]!==a||n[2]!==m?(v=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[1]=a,n[2]=m,n[3]=v):v=n[3];let g;n[4]!==l||n[5]!==a||n[6]!==m?(g=l?s.jsx("img",{src:l,alt:a?m("header.github.avatarWithLogin",{login:a}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=a,n[6]=m,n[7]=g):g=n[7];let f;n[8]!==d||n[9]!==v||n[10]!==g?(f=s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:S,title:v,disabled:d,children:g})}),n[8]=d,n[9]=v,n[10]=g,n[11]=f):f=n[11];let x;n[12]!==m?(x=m("header.github.accountsTitle"),n[12]=m,n[13]=x):x=n[13];let p;n[14]!==x?(p=s.jsx(ko,{className:"typography-ui-header font-semibold text-foreground",children:x}),n[14]=x,n[15]=p):p=n[15];let w;n[16]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Ls,{}),n[16]=w):w=n[16];let N;if(n[17]!==o||n[18]!==u||n[19]!==d||n[20]!==m){let A;n[22]!==u||n[23]!==d||n[24]!==m?(A=D=>{const P=D.user,M=!!D.current,z=D.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(Ut,{className:"gap-2",disabled:d,onSelect:()=>{M||u(D.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(R,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:P.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:z})]}):null]}),M?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},D.id)},n[22]=u,n[23]=d,n[24]=m,n[25]=A):A=n[25],N=o.map(A),n[17]=o,n[18]=u,n[19]=d,n[20]=m,n[21]=N}else N=n[21];let C;n[26]!==p||n[27]!==N?(C=s.jsxs(Zs,{align:"end",className:"w-64",children:[p,w,N]}),n[26]=p,n[27]=N,n[28]=C):C=n[28];let k;return n[29]!==f||n[30]!==C?(k=s.jsxs(en,{children:[f,C]}),n[29]=f,n[30]=C,n[31]=k):k=n[31],k}let h;n[32]!==a||n[33]!==m?(h=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[32]=a,n[33]=m,n[34]=h):h=n[34];let y;n[35]!==l||n[36]!==a||n[37]!==m?(y=l?s.jsx("img",{src:l,alt:a?m("header.github.avatarWithLogin",{login:a}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,n[36]=a,n[37]=m,n[38]=y):y=n[38];let b;return n[39]!==h||n[40]!==y?(b=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:h,children:y}),n[39]=h,n[40]=y,n[41]=b):b=n[41],b}),fb=c.memo(function(e){const n=Ye.c(43),{isDesktopApp:r,currentInstanceLabel:i,compactCurrentInstanceLabel:o,currentInstanceIsLocal:l,isDesktopServicesOpen:a,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,shortcutLabel:m,remoteUpdateInfo:h,remoteUpdateChecking:y,remoteUpdateError:b,onOpenRemoteUpdate:S}=e,{t:v}=ht();let g;n[0]!==u||n[1]!==d?(g=I=>{d(I),I&&u()},n[0]=u,n[1]=d,n[2]=g):g=n[2];let f;n[3]!==i||n[4]!==r||n[5]!==v?(f=r?v("header.services.openWithCurrent",{current:i}):v("header.services.open"),n[3]=i,n[4]=r,n[5]=v,n[6]=f):f=n[6];const x=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let p;n[7]!==x?(p=Ie(qr,x),n[7]=x,n[8]=p):p=n[8];let w;n[9]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(R,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=w):w=n[9];let N;n[10]!==o||n[11]!==r?(N=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:o}):null,n[10]=o,n[11]=r,n[12]=N):N=n[12];let C;n[13]!==f||n[14]!==p||n[15]!==N?(C=s.jsx(bt,{asChild:!0,children:s.jsx(Js,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":f,className:p,children:[w,N]})})}),n[13]=f,n[14]=p,n[15]=N,n[16]=C):C=n[16];let k;n[17]!==i||n[18]!==m||n[19]!==v?(k=v("header.services.tooltip.currentInstance",{current:i,toggle:m("toggle_services_menu")}),n[17]=i,n[18]=m,n[19]=v,n[20]=k):k=n[20];let A;n[21]!==k?(A=s.jsx(xt,{children:s.jsx("p",{children:k})}),n[21]=k,n[22]=A):A=n[22];let D;n[23]!==C||n[24]!==A?(D=s.jsxs(yt,{children:[C,A]}),n[23]=C,n[24]=A,n[25]=D):D=n[25];let P;n[26]!==l||n[27]!==r||n[28]!==a||n[29]!==S||n[30]!==y||n[31]!==b||n[32]!==h||n[33]!==d||n[34]!==v?(P=r?s.jsxs("div",{children:[l?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:v("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:h?.available?v("header.services.remoteUpdate.available",{version:h.version||""}):y?v("header.services.remoteUpdate.checking"):b||v("header.services.remoteUpdate.upToDate")})]}),h?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:S,children:v("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(lf,{embedded:!0,open:a,onOpenChange:bb,onHostSwitched:()=>d(!1)})]}):null,n[26]=l,n[27]=r,n[28]=a,n[29]=S,n[30]=y,n[31]=b,n[32]=h,n[33]=d,n[34]=v,n[35]=P):P=n[35];let M;n[36]!==P?(M=s.jsx(Zs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:P}),n[36]=P,n[37]=M):M=n[37];let z;return n[38]!==a||n[39]!==g||n[40]!==D||n[41]!==M?(z=s.jsxs(en,{open:a,onOpenChange:g,children:[D,M]}),n[38]=a,n[39]=g,n[40]=D,n[41]=M,n[42]=z):z=n[42],z}),hb=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),pb=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],i=n[1].slice(0,3),o=`${r} ${i}`.trim();return n.length>2||o.length<e.length?`${o}...`:o}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},El=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,gb=()=>{fn("ui.header.render");const{t}=ht(),e=Ae(oe=>oe.isSidebarOpen),n=Ae(oe=>oe.openContextOverview),r=Ae(oe=>oe.closeContextPanel),i=Ae(oe=>oe.shortcutOverrides),o=Ae(oe=>oe.sessionTabsEnabled),l=Kt(oe=>oe.getCurrentModel),a=Pn(),d=qe(oe=>oe.getContextUsage),u=qe(oe=>!!oe.newSessionDraft?.open),m=qe(oe=>oe.currentSessionId),h=cf(m??""),y=wa(m??""),b=yu(m??""),S=Es(tr(c.useCallback(oe=>{if(!m)return null;const tt=[...oe.activeSessions,...oe.archivedSessions].find(Vt=>Vt.id===m);if(!tt)return null;const pt=tt;return{title:tt.title??null,directory:pt.directory??null,created:tt.time?.created??null,slug:pt.slug??null,shareUrl:tt.share?.url??null,parentId:tt.parentID??null}},[m]))),v=Ht(tr(oe=>{if(!oe.activeProjectId)return null;const tt=oe.projects.find(pt=>pt.id===oe.activeProjectId);return tt?{id:tt.id,path:tt.path,label:tt.label}:null})),g=c.useMemo(()=>{if(!v)return null;const oe=v.label?.trim();if(oe)return oe;const tt=v.path.split(/[\\/]/).filter(Boolean);return tt[tt.length-1]??null},[v]),f=dr(oe=>oe.loadSettings),{isMobile:x}=zn(),p=er(oe=>oe.status),w=er(oe=>oe.setStatus),N=c.useRef(null),[C,k]=c.useState(()=>typeof window>"u"?!1:wn()),A=c.useMemo(()=>Zo(),[]),D=xd(),[P,M]=c.useState(!1),z=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:I,side:V}=Kd(),T=c.useMemo(()=>{if(typeof window>"u")return null;const oe=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof oe=="number"&&Number.isFinite(oe)&&oe>0)return oe;if(typeof navigator>"u")return null;const tt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!tt)return null;const pt=Number.parseInt(tt[1],10),Vt=Number.parseInt(tt[2],10);return Number.isNaN(pt)?null:pt===10?Vt:pt},[]);it.useEffect(()=>{typeof window>"u"||k(wn())},[]);const _=l(),O=_&&typeof _.limit=="object"&&_.limit!==null?_.limit:null,j=O&&typeof O.context=="number"?O.context:0,E=O&&typeof O.output=="number"?O.output:0,L=d(j,E),[U,X]=c.useState(null),Q=!m||h;it.useEffect(()=>{if(!m){X(oe=>oe===null?oe:null);return}if(L&&L.totalTokens>0){X(oe=>hb(oe,L)?oe:L);return}Q&&X(oe=>oe===null?oe:null)},[L,m,Q]);const me=p?.connected?p.user?.avatarUrl??null:null,re=p?.connected?p.user?.login??null:null,G=p?.accounts??[],[ee,ue]=c.useState(!1),[W,ne]=c.useState(!1),[Y,F]=c.useState("Local"),[J,ie]=c.useState(!0),[xe,ge]=c.useState(!1),[Ce,Re]=c.useState(null),[ce,ye]=c.useState(!1),[be,te]=c.useState(null),pe=c.useMemo(()=>pb(Y),[Y]),Pe=c.useMemo(()=>Dn(),[]),de=Ae(oe=>oe.workStatusPanelVisible),he=Ae(oe=>oe.workStatusPanelEnabled),fe=Ae(oe=>oe.setWorkStatusPanelEnabled),B=Ae(oe=>oe.workStatusPanelFits),H=Ae(oe=>oe.workStatusOverlayOpen),ke=Ae(oe=>oe.setWorkStatusOverlayOpen),Be=he&&B||H,_e=c.useCallback(()=>{if(he&&!B){ke(!H);return}fe(!he)},[ke,fe,H,he,B]),Te=!Pe&&!de&&!!U&&U.totalTokens>0,Z=U&&U.contextLimit>0?Math.min(999,U.totalTokens/U.contextLimit*100):0,Ne=c.useCallback(async()=>{if(!(typeof window>"u"||!C))try{if(Xo()){F("Local"),ie(!0);return}ie(!1);const oe=await ad(),tt=df(),pt=uf([mf(tt),...oe.hosts]);if(pt.id===ff){F("Local"),ie(!0);return}F(ld(pt.label.trim()||"Instance"))}catch{F("Local"),ie(!0)}},[C]);it.useEffect(()=>(Ne(),ei(()=>{Ne()})),[Ne]);const Me=c.useCallback(async()=>{if(J){Re(null),te(null);return}ye(!0),te(null);try{const oe=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),tt=await rs(`/api/openchamber/update-check?${oe.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!tt.ok)throw new Error(`Server responded with ${tt.status}`);const pt=await tt.json();Re({available:pt.available??!1,version:pt.version,currentVersion:pt.currentVersion??"unknown",body:pt.body,nextSuggestedCheckInSec:typeof pt.nextSuggestedCheckInSec=="number"?pt.nextSuggestedCheckInSec:void 0,packageManager:pt.packageManager,updateCommand:pt.updateCommand})}catch(oe){Re(null),te(oe instanceof Error?oe.message:t("header.services.remoteUpdate.error"))}finally{ye(!1)}},[J,t]);c.useEffect(()=>{Re(null),te(null),ge(!1)},[J,Y]),c.useEffect(()=>{if(!C||J)return;const oe=3e3,tt=3600*1e3;let pt=!1,Vt=null;const vs=as=>{Vt=window.setTimeout(()=>{if(pt||typeof document<"u"&&document.visibilityState!=="visible"){vs(tt);return}Me().finally(()=>{pt||vs(tt)})},as)};return vs(oe),()=>{pt=!0,Vt!==null&&window.clearTimeout(Vt)}},[Me,J,Y,C]);const $=c.useCallback(()=>{if(Ce?.available){ge(!0);return}Me()},[Me,Ce?.available]);hf(),c.useEffect(()=>{f()},[f]);const ae=m?S??null:null,se=c.useRef(null),[we,Ke]=c.useState(0);c.useEffect(()=>{if(!m){se.current&&(se.current=null,Ke(Vt=>Vt+1));return}if(ae){se.current={sessionId:m,session:ae,expiresAt:Date.now()+2e3};return}const oe=se.current;if(!oe||oe.sessionId!==m)return;const tt=oe.expiresAt-Date.now();if(tt<=0){se.current=null,Ke(Vt=>Vt+1);return}const pt=window.setTimeout(()=>{se.current?.sessionId===m&&(se.current=null),Ke(Vt=>Vt+1)},tt);return()=>{window.clearTimeout(pt)}},[m,ae]);const Qe=(()=>{if(ae)return ae;if(!m)return null;const oe=se.current;return oe&&oe.sessionId===m&&oe.expiresAt>Date.now()?oe.session:null})(),He=qe(oe=>m?oe.worktreeMetadata.get(m)?.path??"":""),le=qe(oe=>m?oe.worktreeMetadata.get(m)?.branch?.trim()??null:null),K=yd(oe=>m?oe.getAttachment(m):void 0),ve=c.useMemo(()=>K?pf(K,{pending:t("gitView.empty.worktreeSetupInProgress")}):null,[t,K]),$e=c.useMemo(()=>K?K.legacy?"legacy":K.degraded?"degraded":K.worktreeStatus==="pending"?"pending":K.worktreeStatus==="missing"?"missing":K.worktreeStatus==="invalid"?"invalid":K.attentionReason?"attention":null:null,[K]),We=c.useMemo(()=>kn(He||""),[He]),Le=c.useMemo(()=>{const oe=typeof Qe?.directory=="string"?Qe.directory:"";return kn(oe||"")},[Qe?.directory]),Fe=qe(oe=>oe.newSessionDraft?.open?kn(oe.newSessionDraft.bootstrapPendingDirectory??oe.newSessionDraft.directoryOverride??""):""),Ge=qe(oe=>oe.newSessionDraft.target),rt=qe(oe=>oe.newSessionDraft.selectedProjectId),St=qe(oe=>oe.currentSessionDirectory),Rt=ss(oe=>oe.homeDirectory),ze=c.useMemo(()=>We||Le||Fe,[Fe,Le,We]),Pt=Ae(c.useCallback(oe=>{const tt=kn(ze||"");return tt?El(oe.contextPanelByDirectory[tt]):null},[ze])),Nt=qe(oe=>{const tt=kn(We||Le||"");if(!tt)return null;for(const pt of oe.availableWorktreesByProject.values()){const vs=pt.find(as=>kn(as.path)===tt)?.branch?.trim();if(vs)return vs}return null}),Et=gf(ze||null)||le||Nt,vt=u?Ge==="chat":bf(Le||St,Rt),Ct=!vt&&!de&&!!(g||Et||!u&&$e),It=c.useMemo(()=>{if(!m)return g??"OpenChamber";const oe=Qe?.title?.trim();return oe&&oe.length>0?oe:"Untitled Session"},[g,Qe?.title,m]),mt=wd(ze||void 0,{bootstrap:!1}),Ze=Sd(),je=qe(oe=>oe.updateSessionTitle),ot=qe(oe=>oe.shareSession),ct=qe(oe=>oe.unshareSession),Mt=qe(oe=>oe.archiveSessions),Je=qe(oe=>oe.deleteSessions),[nt,jt]=c.useState(!1),[At,Ot]=c.useState(!1),$t=c.useRef(null),[Zt,Gt]=c.useState(""),[Ft,qt]=c.useState(null),Xt=c.useRef(null),zt=c.useCallback(()=>{m&&(Gt(Qe?.title?.trim()||It),jt(!0))},[Qe?.title,m,It]),Ee=c.useRef(zt);Ee.current=zt,c.useEffect(()=>{if(Ot(!1),qt(null),m&&$t.current===m){$t.current=null,Ee.current();return}jt(!1),Gt("")},[m]);const Ue=c.useCallback(async()=>{if(!m)return;const oe=Zt.trim();oe&&oe!==Qe?.title?.trim()&&await je(m,oe),jt(!1)},[Qe?.title,m,Zt,je]);c.useEffect(()=>{if(!nt)return;const oe=tt=>{const pt=tt.target;(!pt||!Xt.current?.contains(pt))&&Ue()};return document.addEventListener("mousedown",oe),()=>document.removeEventListener("mousedown",oe)},[nt,Ue]);const et=c.useCallback(oe=>{oe&&xn(oe).then(tt=>{Oe[tt.ok?"success":"error"](t(tt.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Oe.error(t("sessions.sidebar.session.copyId.error")))},[t]),lt=c.useCallback(async oe=>{if(!oe)return;const tt=await ot(oe);if(tt?.share?.url){const pt=await xn(tt.share.url);Oe[pt.ok?"success":"warning"](t("sessions.sidebar.session.share.successTitle"),{description:t(pt.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Oe.error(t("sessions.sidebar.session.share.error"))},[ot,t]),ut=c.useCallback(oe=>{oe&&xn(oe).then(tt=>{Oe[tt.ok?"success":"error"](t(tt.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Oe.error(t("sessions.sidebar.session.share.copyUrlError")))},[t]),kt=c.useCallback(async oe=>{if(!oe)return;const tt=await ct(oe);Oe[tt?"success":"error"](t(tt?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[t,ct]),st=c.useCallback(async()=>{if(!m||!ze){Oe.error(t("sessions.sidebar.session.export.nothingToExport"));return}try{await Ze.loadCompleteHistory(m,ze)}catch{Oe.error(t("sessions.sidebar.session.export.failedLoadHistory"));return}const oe=xf(mt.getState(),m).list;if(oe.length===0){Oe.error(t("sessions.sidebar.session.export.nothingToExport"));return}const tt=pu(oe,Qe?.title??null),pt=xu(Qe?.title??null);await bu(tt,pt)||gu(tt,pt),Oe.success(t("sessions.sidebar.session.export.success"))},[Qe?.title,m,mt,ze,Ze,t]),_t=y?.type==="busy"||y?.type==="retry",es=c.useCallback(()=>{if(!m||!Le||_t||b)return;const oe=Es.getState().activeSessions,tt=oe.find(vs=>vs.id===m);if(!tt)return;const pt=[],Vt=[m];for(let vs=0;vs<Vt.length;vs+=1){const as=Vt[vs];for(const sn of oe)sn.parentID===as&&(pt.push(sn),Vt.push(sn.id))}Qi({kind:"quick",root:tt,descendants:pt,sourceDirectory:Le,messages:Gi(t,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},[m,_t,b,Le,t]),Ds=c.useCallback(async()=>{if(!Ft)return;const oe=Es.getState().activeSessions,tt=[Ft.sessionId];for(let as=0;as<tt.length;as+=1){const sn=tt[as];for(const In of oe)In.parentID===sn&&!tt.includes(In.id)&&tt.push(In.id)}const pt=Ft.action;if(qt(null),(pt==="archive"?await Mt(tt):await Je(tt)).failedIds.length>0){Oe.error(t(pt==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Oe.success(t(pt==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[Mt,Je,Ft,t]),Os=Ae(oe=>oe.isScheduledTasksDialogOpen),bs=Ae(oe=>oe.isArchivePageOpen),xs=Ae(oe=>oe.worktreesPageProjectId),os=Ae(oe=>oe.isMultiRunLauncherOpen),Ps=Ht(oe=>{if(!xs)return null;const tt=oe.projects.find(pt=>pt.id===xs);return tt?.label?.trim()||tt?.path?.split("/").pop()||null}),fs=c.useMemo(()=>Os?{title:t("sessions.scheduledTasks.dialog.title"),subtitle:null}:bs?{title:t("sessions.archivePage.title"),subtitle:null}:xs?{title:t("sessions.worktreesPage.title",{project:Ps??""}),subtitle:null}:os?{title:t("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[bs,os,Os,t,xs,Ps]),Bs=c.useMemo(()=>kn(ze||v?.path||""),[v?.path,ze]),Ks=c.useMemo(()=>v?{id:v.id,path:v.path}:null,[v]),ys=c.useRef(null);c.useEffect(()=>{!Ks||!Bs||(ys.current={projectRef:Ks,directory:Bs})},[Bs,Ks]);const ws=ja(oe=>oe.planModeEnabled),Ss=qe(oe=>oe.isSessionPlanAvailable),hn=ws&&m?Ss(m):!1,Gs=c.useRef("");c.useEffect(()=>{if(!ws||!m)return;const oe=`${m||"none"}:${Le||"none"}:${Qe?.created||0}:${Qe?.slug||"none"}`;Gs.current!==oe&&(Gs.current=oe)},[ws,hn,Qe?.slug,Qe?.created,m,Le]);const dn=c.useCallback(async oe=>{if(!(!oe||ee)){ue(!0);try{const tt=a.github?await a.github.authActivate(oe):await(async()=>{const pt=await rs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:oe})}),Vt=await pt.json().catch(()=>null);if(!pt.ok||!Vt)throw new Error(Vt?.error||pt.statusText);return Vt})();w(tt)}catch(tt){console.error("Failed to switch GitHub account:",tt)}finally{ue(!1)}}},[ee,a.github,w]),Lt=c.useCallback(()=>{Fn("desktop_open_draft_mini_chat_window",{directory:vt?"":Fe,projectId:vt?null:rt,apiBaseUrl:Ln(),clientToken:zr()}).catch(oe=>{console.warn("[header] failed to open draft mini chat window",oe)})},[Fe,rt,vt]),Wt=c.useCallback(()=>{if(u){Lt();return}m&&Fn("desktop_open_session_mini_chat_window",{sessionId:m,directory:Le||kn(St||"")||We,apiBaseUrl:Ln(),clientToken:zr()}).catch(oe=>{console.warn("[header] failed to open session mini chat window",oe)})},[m,Lt,u,St,Le,We]),q=c.useCallback(()=>{const oe=kn(ze||"");if(!oe)return;const tt=Ae.getState().contextPanelByDirectory[oe];if(El(tt)==="context"){r(oe);return}n(oe)},[r,n,ze]),Ve=Pt==="context",Xe=qr,ft=c.useMemo(()=>C&&z&&!P?"5.5rem":D?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!C||I)&&!Pe?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[C,P,z,D,Pe,I]);it.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",ft)},[ft]);const Dt=e?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",gt=e?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";it.useEffect(()=>{if(!C||!z){M(!1);return}let oe=!1;const tt=async()=>{try{const Vt=await Fn("desktop_is_window_fullscreen");oe||M(Vt===!0)}catch{oe||M(!1)}},pt=()=>{tt()};return tt(),window.addEventListener("openchamber:window-resized",pt),()=>{oe=!0,window.removeEventListener("openchamber:window-resized",pt)}},[C,z]);const wt=c.useMemo(()=>!C||!z||T===null?"":T>=26?"h-12":T<=15?"h-14":"",[C,z,T]),is=c.useMemo(()=>{if(!(C&&!I||Pe))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))"}},[C,Pe,I]),cs=c.useCallback(()=>{if(typeof document>"u")return;const oe=N.current?.getBoundingClientRect().height;oe&&document.documentElement.style.setProperty("--oc-header-height",`${oe}px`)},[]);it.useEffect(()=>{if(typeof window>"u")return;cs();const oe=N.current;if(!oe||typeof ResizeObserver>"u")return()=>{};let tt=0;const pt=()=>{tt||(tt=requestAnimationFrame(()=>{tt=0,cs()}))},Vt=new ResizeObserver(pt);return Vt.observe(oe),window.addEventListener("resize",pt),window.addEventListener("orientationchange",pt),()=>{tt&&cancelAnimationFrame(tt),Vt.disconnect(),window.removeEventListener("resize",pt),window.removeEventListener("orientationchange",pt)}},[cs]),it.useEffect(()=>{cs()},[cs,x,wt]);const Jt=c.useCallback(async oe=>{const tt=oe.target;tt.closest(".app-region-no-drag")||tt.closest("button, a, input, select, textarea")||oe.button===0&&C&&await Mm()},[C]),tn=c.useCallback(oe=>Jn(eo(oe,i)),[i]);yf({rename_current_session:()=>{if(!m||x)return!1;zt()},toggle_services_menu:()=>{if(W){ne(!1);return}ne(!0),Ne()}});const un=s.jsxs(s.Fragment,{children:[s.jsx(jg,{directory:Bs,className:"mr-1"}),C?s.jsx(fb,{isDesktopApp:C,currentInstanceLabel:Y,compactCurrentInstanceLabel:pe,currentInstanceIsLocal:J,isDesktopServicesOpen:W,setIsDesktopServicesOpen:ne,refreshCurrentInstanceLabel:Ne,shortcutLabel:tn,remoteUpdateInfo:Ce,remoteUpdateChecking:ce,remoteUpdateError:be,onOpenRemoteUpdate:$}):null,s.jsx(mb,{isMobile:x,githubAuthStatus:p,githubAccounts:G,githubAvatarUrl:me,githubLogin:re,isSwitchingGitHubAccount:ee,handleGitHubAccountSwitch:dn})]}),ir=A&&(u||!!m),Tn=c.useCallback(({session:oe,isActive:tt,select:pt,closeOtherTabs:Vt,components:vs})=>{const{Item:as,Separator:sn}=vs,In=oe.share?.url??null,oo=tt&&!Pe&&!vt&&Qe&&!Qe.parentId;return s.jsxs(s.Fragment,{children:[s.jsxs(as,{onClick:()=>{tt||pt(),$t.current=oe.id},children:[s.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs(as,{onClick:()=>et(oe.id),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(sn,{}),In?s.jsxs(s.Fragment,{children:[s.jsxs(as,{onClick:()=>ut(In),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(as,{onClick:()=>{kt(oe.id)},children:[s.jsx(R,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(as,{onClick:()=>{lt(oe.id)},children:[s.jsx(R,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),tt?s.jsxs(as,{onClick:()=>{st()},children:[s.jsx(R,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}):null,oo?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(as,{disabled:!Le||_t||b,onClick:es,className:"w-full",children:[s.jsx(R,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(xt,{side:"right",className:"max-w-72",children:t(b?"sessions.sidebar.session.moveToWorktree.tooltipMoving":_t?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(sn,{}),s.jsxs(as,{onClick:Vt,children:[s.jsx(R,{name:"close-circle",className:"mr-2 size-4"}),t("header.sessionTabs.closeOtherTabs")]}),s.jsx(sn,{}),s.jsxs(as,{onClick:()=>qt({action:"archive",sessionId:oe.id}),children:[s.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(as,{className:"text-destructive focus:text-destructive",onClick:()=>qt({action:"delete",sessionId:oe.id}),children:[s.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})},[et,ut,Qe,st,vt,_t,b,Pe,es,Le,lt,t,kt]),di=()=>s.jsxs("div",{onMouseDown:Jt,className:Ie("app-region-drag relative flex h-12 select-none items-center",I&&V==="right"?"pr-0":"pr-3",wt),style:is,role:"tablist","aria-label":t("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Dt}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:gt}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[fs?s.jsxs("div",{className:"mr-3 flex min-w-0 flex-col items-start px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:fs.title}),fs.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:fs.subtitle}):null]}):Pe||!o?s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[e?null:s.jsx(Sl,{align:"start",children:s.jsx("button",{type:"button",className:Xe,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[nt?s.jsxs("form",{ref:Xt,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:oe=>oe.stopPropagation(),onSubmit:oe=>{oe.preventDefault(),Ue()},children:[s.jsx("input",{value:Zt,onChange:oe=>Gt(oe.target.value),autoFocus:!0,onKeyDown:oe=>{oe.stopPropagation(),oe.key==="Escape"&&jt(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":t("sessions.sidebar.session.rename.save"),title:t("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>jt(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):It}),Ct?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[g?s.jsx("span",{className:"truncate",children:g}):null,Et?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Et})]}):null,!u&&$e?s.jsxs("span",{className:Ie("inline-flex min-w-0 items-center gap-0.5",$e==="attention"||$e==="invalid"||$e==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(R,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ve})]}):null]}):null]}),s.jsx("div",{className:Ie("flex h-[18px] shrink-0 items-center justify-center",Ct?"self-start":"self-center"),children:m&&!u&&!nt?s.jsxs(en,{open:At,onOpenChange:Ot,onOpenChangeComplete:oe=>{!oe&&$t.current&&$t.current===m&&($t.current=null,zt())},children:[s.jsx(Js,{asChild:!0,children:s.jsx(at,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":t("header.sessionActions.openAria"),children:s.jsx(R,{name:"more",className:"size-4"})})}),s.jsxs(Zs,{align:"end",className:"min-w-[190px]",children:[s.jsxs(Ut,{onClick:()=>{$t.current=m},children:[s.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ut,{onClick:()=>m&&et(m),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyId")]}),s.jsx(Ls,{}),Qe?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(Ut,{onClick:()=>ut(Qe?.shareUrl),children:[s.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Ut,{onClick:()=>{m&&kt(m)},children:[s.jsx(R,{name:"link-unlink-m",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ut,{onClick:()=>{m&<(m)},children:[s.jsx(R,{name:"share-2",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.share")]}),s.jsxs(Ut,{onClick:()=>{st()},children:[s.jsx(R,{name:"download",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.exportMarkdown")]}),!Pe&&!vt&&Qe&&!Qe.parentId?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Ut,{disabled:!Le||_t||b,onClick:es,className:"w-full",children:[s.jsx(R,{name:"folder-shared",className:"mr-2 size-4"}),t("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(xt,{side:"right",className:"max-w-72",children:t(b?"sessions.sidebar.session.moveToWorktree.tooltipMoving":_t?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(Ls,{}),s.jsxs(Ut,{onClick:()=>{m&&qt({action:"archive",sessionId:m})},children:[s.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Ut,{className:"text-destructive focus:text-destructive",onClick:()=>{m&&qt({action:"delete",sessionId:m})},children:[s.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),t("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}):s.jsxs("div",{className:"app-region-no-drag flex h-full min-w-0 flex-1 items-center gap-0.5 text-left",children:[e?null:s.jsx(Sl,{align:"start",children:s.jsx("button",{type:"button",className:Xe,"aria-label":t("sessions.switcher.openAria"),children:s.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsx(Bg,{renderMenu:Tn,suppressActiveTabControls:nt,onMenuOpenChangeComplete:oe=>{!oe&&$t.current&&$t.current===m&&($t.current=null,zt())},children:s.jsx("div",{className:"flex min-w-0 flex-col justify-center",children:nt?s.jsxs("form",{ref:Xt,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onPointerDown:oe=>oe.stopPropagation(),onSubmit:oe=>{oe.preventDefault(),Ue()},children:[s.jsx("input",{value:Zt,onChange:oe=>Gt(oe.target.value),autoFocus:!0,onKeyDown:oe=>{oe.stopPropagation(),oe.key==="Escape"&&jt(!1)},placeholder:t("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent text-[13px] font-medium leading-4 outline-none placeholder:text-muted-foreground"}),s.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:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>jt(!1),"aria-label":t("sessions.sidebar.session.rename.cancel"),title:t("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"block overflow-hidden whitespace-nowrap text-[13px] font-medium leading-4 text-foreground max-w-full",children:u?t("sessions.switcher.draftTitle"):It})})})]}),fs||Pe||!o?s.jsx("div",{className:"flex-1"}):null,s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Te&&U?s.jsx(Np,{totalTokens:U.totalTokens,percentage:Z,colorPercentage:U.percentage,contextLimit:U.contextLimit,outputLimit:U.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:q,pressed:Ve,className:ir?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(ub,{visible:ir,title:t(u?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:t(u?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Wt,className:Ie(Xe,"mr-1"),Icon:"picture-in-picture-2"}),Pe?null:s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":Be,"aria-label":t("header.workStatusPanel.toggleAria"),onClick:_e,className:Ie(qr,"mr-1",Be?"text-foreground":"text-muted-foreground/50"),children:s.jsx(R,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(xt,{side:"bottom",children:t(he&&!B?H?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":he?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}),un,s.jsx(Gd,{visible:I&&V==="right",position:"right"})]})]})]});return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:N,className:"header-safe-area relative z-10 bg-background",style:{"--padding-scale":"1"},children:di()}),s.jsx(Ns,{open:Ft!==null,onOpenChange:oe=>{oe||qt(null)},children:s.jsxs(As,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Hs,{children:[s.jsx(Rs,{children:Ft?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.title"):t("sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Ms,{children:Ft?.action==="delete"?t("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:It}):t("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:It})})]}),s.jsxs(Sn,{children:[s.jsx(at,{variant:"outline",size:"sm",onClick:()=>qt(null),children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",size:"sm",onClick:()=>{Ds()},children:Ft?.action==="delete"?t("sessions.sidebar.bulkActions.delete"):t("sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(qd,{open:xe,onOpenChange:ge,info:Ce,downloading:!1,downloaded:!1,progress:null,error:be,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function bb(){}const Rl=280,Ml=280,Ol=500,xb=({isOpen:t,isMobile:e,children:n,className:r,topBar:i})=>{const{t:o}=ht(),l=Ae(k=>k.sidebarWidth),a=Ae(k=>k.setSidebarWidth),[d,u]=c.useState(!1),m=c.useRef(0),h=c.useRef(l||Rl),y=c.useRef(null),b=c.useRef(null),S=c.useRef(null),v=c.useCallback(k=>Math.min(Ol,Math.max(Ml,k)),[]),g=c.useCallback(k=>{const A=S.current;A&&(A.style.width=`${k}px`,A.style.minWidth=`${k}px`,A.style.maxWidth=`${k}px`,A.style.setProperty("--oc-left-sidebar-width",`${k}px`))},[]);if(c.useEffect(()=>{e&&d&&u(!1)},[e,d]),c.useEffect(()=>{d||(y.current=null,b.current=null)},[d]),e)return null;const f=Math.min(Ol,Math.max(Ml,l||Rl)),x=t?f:0,p=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}b.current=k.pointerId,u(!0),m.current=k.clientX,h.current=x,y.current=x,g(x),k.preventDefault()}},w=k=>{if(e||!d||b.current!==k.pointerId)return;const A=k.clientX-m.current,D=v(h.current+A);y.current!==D&&(y.current=D,g(D))},N=k=>{if(b.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const A=v(y.current??x);b.current=null,y.current=null,u(!1),a(A)},C=d?y.current??x:x;return s.jsxs("aside",{ref:S,className:Ie("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-left-sidebar-width":`${d?C:f}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&s.jsx("div",{className:Ie("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",d&&"bg-[var(--interactive-border)]"),onPointerDown:p,onPointerMove:w,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":o("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Ie("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[i,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(Xs,{children:n})})]})]})},yb=()=>{const t=Ye.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},ao=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function wb(){const t=Ht(h=>h.activeProjectId?h.projects.find(y=>y.id===h.activeProjectId)??null:null),e=qe(h=>h.currentSessionId),n=wf(e??null),r=qe(h=>e?h.worktreeMetadata.get(e)?.path??"":""),i=qe(h=>h.newSessionDraft?.open?ao(h.newSessionDraft.bootstrapPendingDirectory??h.newSessionDraft.directoryOverride??""):""),o=c.useMemo(()=>ao(r||""),[r]),l=c.useMemo(()=>{const h=typeof n?.directory=="string"?n.directory:"";return ao(h||"")},[n?.directory]),a=o||l||i,d=c.useMemo(()=>ao(a||t?.path||""),[t?.path,a]),u=c.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),m=c.useRef(null);return c.useEffect(()=>{u&&d&&(m.current={projectRef:u,directory:d})},[d,u]),c.useMemo(()=>u&&d?{projectRef:u,directory:d}:m.current,[u,d])}const zo=new Map,Yi=new Set,Cu=()=>{for(const t of Yi)t()},hi=(t,e)=>{const n=t.trim();n&&(e.length===0?zo.delete(n):zo.set(n,[...e]),Cu())},Sb=t=>{zo.delete(t.trim())&&Cu()},Nu=[],vb=t=>zo.get(t.trim())??Nu,jb=t=>(Yi.add(t),()=>{Yi.delete(t)}),kb=t=>{const e=Ye.c(2);let n;return e[0]!==t?(n=()=>vb(t),e[0]=t,e[1]=n):n=e[1],c.useSyncExternalStore(jb,n,Cb)};function Cb(){return Nu}const Nb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Ab=["dev","start","preview","serve"];async function Db(t,e,n){if(!t)return null;const r=Ib(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const i=Eb(n);if(i){const o=await Rb(t);return{command:`${o==="npm"?"npm run":o==="yarn"?"yarn":o==="pnpm"?"pnpm":o==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await Pb(t)){const i=await Tb(),o=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${o}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${o}/`}}return null}async function Pb(t){const e=`${t}/index.html`,n=await Vo(e,t);return typeof n=="string"&&n.trim().length>0}async function Tb(){try{const t=await rs("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Ib(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Ab.some(i=>n.includes(i)))return e}return null}function Eb(t){for(const{pattern:e}of Nb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Rb(t){const e=await Vo(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,i]of n){const o=await Vo(`${t}/${r}`,t);if(typeof o=="string"&&o.trim().length>0)return i}return"npm"}async function Vo(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),i=await rs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(i.ok)return i.text()}catch{}const n=Jo()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await rs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Mb(t){try{const e=await Vo(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Ob=(t,e,n)=>new Promise(r=>{let i=!1,o=null,l=null;const a=d=>{i||(i=!0,l&&clearTimeout(l),o?.close(),r(d))};o=t.connect(e,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&a(!0)},onError:(d,u)=>{u&&a(!0)}}),i?o.close():l=setTimeout(()=>a(!1),n)}),qs="__openchamber_auto_discover_preview__",Bb=15e3,Fb=3e3,_b=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},Lb=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},$b=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:o}=ht(),{currentTheme:l}=nr(),{terminal:a,runtime:d}=Pn(),{isMobile:u}=zn(),m=c.useMemo(()=>wn(),[]),h=vl(Z=>Z.instances),y=vl(Z=>Z.load),b=Ae(Z=>Z.terminalShell),S=Ae(Z=>Z.terminalLoginShells.includes(Z.terminalShell)),v=Ae(Z=>Z.setSettingsPage),g=Ae(Z=>Z.setSettingsDialogOpen),f=Ae(Z=>Z.setSettingsProjectsSelectedId),x=Ae(Z=>Z.openContextPreview),p=Yt(Z=>Z.ensureDirectory),w=Yt(Z=>Z.setTabLabel),N=Yt(Z=>Z.setTabIconKey),C=Yt(Z=>Z.setActiveTab),k=Yt(Z=>Z.setConnecting),A=Yt(Z=>Z.setTabSessionId),D=Yt(Z=>Z.setTabPreviewUrl),P=Yt(Z=>Z.projectActionRuns),M=Yt(Z=>Z.setProjectActionRun),z=Yt(Z=>Z.updateProjectActionRunStatus),I=Yt(Z=>Z.removeProjectActionRun),[V,T]=c.useState([]),[_,O]=c.useState(null),[j,E]=c.useState(!1),L=c.useRef({}),U=c.useRef({}),X=c.useRef({}),Q=c.useRef({}),me=c.useRef(new Set),re=c.useRef(0),G=t?.id??null,ee=t?.path??"",ue=c.useMemo(()=>G?{id:G,path:ee}:null,[G,ee]);c.useEffect(()=>{m&&y().catch(()=>{})},[m,y]);const W=c.useCallback(async Z=>{await si(Z)},[]),ne=c.useCallback(async()=>{if(!ue)return;const Z=re.current+1;re.current=Z,E(!0);try{const Ne=await nl(ue);if(re.current!==Z)return;const Me=Ne.actions;T(Me),O($=>$===qs||$&&Me.some(ae=>ae.id===$)?$:null)}catch{if(re.current!==Z)return}finally{re.current===Z&&E(!1)}},[ue]),Y=c.useMemo(()=>Pp(e||ue?.path||""),[e,ue?.path]),F=c.useMemo(()=>_?V.find(Z=>Z.id===_)??null:null,[V,_]),J=c.useMemo(()=>({id:qs,name:o("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[o]),ie=!u,xe=c.useMemo(()=>ie?[J,...V]:V,[V,J,ie]);c.useEffect(()=>{ne()},[ne]),c.useEffect(()=>{if(typeof window>"u")return;const Z=Ne=>{const Me=Ne.detail;G&&(Me?.projectId&&Me.projectId!==G||ne())};return window.addEventListener(jl,Z),()=>{window.removeEventListener(jl,Z)}},[ne,G]),c.useEffect(()=>{_&&(_===qs&&ie||V.some(Z=>Z.id===_)||O(null))},[V,ie,_]),c.useEffect(()=>{const Z=Me=>{delete Q.current[Me];const $=U.current[Me];if(!$||$.openedUrl)return;const ae=Yt.getState(),se=ae.projectActionRuns[Me];if(!se)return;const we=$.announced;if(we.length!==0){if($.openedUrl=!0,ae.updateProjectActionRunStatus(Me,"running"),we.length===1){hi(se.directory,[]),D(se.directory,se.tabId,we[0],{locked:!1,autoOpened:!0}),x(se.directory,we[0]);return}$.offering=!0,hi(se.directory,we),Ae.getState().openContextSurface(se.directory,"browser"),Oe.info(o("projectActions.toast.multipleServers"))}},Ne=()=>{const Me=Yt.getState(),$=Me.sessions,ae=Me.projectActionRuns;for(const[se,we]of Object.entries(ae)){const Qe=$.get(we.directory)?.tabs.find(Ge=>Ge.id===we.tabId);if(!Qe||Qe.terminalSessionId!==we.sessionId){I(se);continue}const He=U.current[se]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1,announced:[],offering:!1};U.current[se]=He;const le=xe.find(Ge=>Ge.id===we.actionId),K=Me.getBuffer(we.directory,we.tabId).chunks;if(!le||K.length===0)continue;const ve=K.filter(Ge=>He.lastSeenChunkId===null||Ge.id>He.lastSeenChunkId);if(ve.length===0)continue;const $e=ve.map(Ge=>Ge.data).join(""),We=`${He.tail}${$e}`;if(He.openInPreview&&(!He.openedUrl||He.offering)){const Ge=Ip(We),rt=He.announced.length;for(const Rt of Ge)He.announced.includes(Rt)||He.announced.push(Rt);const St=He.announced.length-rt;He.offering&&St>0?hi(we.directory,He.announced):!He.openedUrl&&rt===0&&He.announced.length>0&&(window.clearTimeout(Q.current[se]),Q.current[se]=window.setTimeout(()=>Z(se),Fb))}const Le=!He.openedUrl&&le.autoOpenUrl===!0&&!He.openInPreview?Ep(We):null,Fe=ve[ve.length-1]?.id??He.lastSeenChunkId;if(He.lastSeenChunkId=Fe,He.tail=We.slice(-512),Le)if(He.openedUrl=!0,He.openInPreview){const Ge=ae[se];Ge&&(D(Ge.directory,Ge.tabId,Le,{locked:!1,autoOpened:!1}),Ge.status==="waiting-for-preview"&&z(se,"running"),window.clearTimeout(Q.current[se]),delete Q.current[se],x(Ge.directory,Le))}else W(Le),Oe.success(o("projectActions.toast.openedUrlFromOutput"));U.current[se]=He}for(const se of Object.keys(U.current))ae[se]||(delete U.current[se],window.clearTimeout(Q.current[se]),delete Q.current[se])};return Ne(),Yt.subscribe((Me,$)=>{(Me.sessions!==$.sessions||Me.buffers!==$.buffers)&&Ne()})},[xe,x,W,P,I,D,o,z]);const ge=c.useCallback(async(Z,Ne={})=>{if(!Y)throw new Error(o("projectActions.error.noActiveDirectory"));const Me=jn(Y,Z.id);p(Y);const $=Yt.getState(),ae=$.getDirectoryState(Y);let se=L.current[Me]||null;const we=se?!!ae?.tabs.some(He=>He.id===se):!1;(!se||!we)&&(se=$.createTab(Y),L.current[Me]=se),w(Y,se,`Action: ${Z.name}`),N(Y,se,Z.icon||"play"),C(Y,se),Ne.revealTerminal!==!1&&Ae.getState().openContextPanelTab(Y,{mode:"terminal"});const Qe=Yt.getState().getDirectoryState(Y)?.tabs.find(He=>He.id===se);return{key:Me,tabId:se,sessionId:Qe?.terminalSessionId??null}},[p,Y,C,N,w,o]),Ce=c.useCallback(async Z=>{if(d.isVSCode||!i&&u)return;if(!Y){Oe.error(o("projectActions.error.noActiveDirectoryForAction"));return}const Ne=jn(Y,Z.id),Me=P[Ne];if(!(Me&&Me.status==="running")&&!me.current.has(Ne)){me.current.add(Ne);try{const $=Z.id===qs?await(async()=>{const[Le,Fe]=await Promise.all([nl({id:ue?.id??"",path:Y}),Mb(Y)]),Ge=await Db(Y,Le.actions,Fe);if(!Ge)throw new Error(o("contextPanel.preview.noDevServer"));return{id:qs,name:o("projectActions.actions.autoDiscover"),command:Ge.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Ge.previewUrlHint||""}})():Z,ae=$.autoOpenUrl===!0&&($.openUrl||"").trim().length>0,se=!ae&&Z.id!==qs,{key:we,tabId:Ke,sessionId:Qe}=await ge($,{revealTerminal:se});let He=Qe;if(!He){k(Y,Ke,!0);try{He=(await a.createSession({cwd:Y,sessionId:Ke,shell:b,loginShell:S,themeMode:l.metadata.variant==="light"?"light":"dark",terminalBackground:l.colors.surface.background,terminalForeground:l.colors.syntax.base.foreground})).sessionId,A(Y,Ke,He)}finally{k(Y,Ke,!1)}}if(!He)throw new Error(o("projectActions.error.failedToCreateTerminalSession"));X.current[we]?.(),k(Y,Ke,!0);const le=a.connect(He,{onEvent:Le=>{Le.type==="snapshot"&&(Yt.getState().replaceBuffer(Y,Ke,Le.data??"",Le.sequence??0),Yt.getState().setConnecting(Y,Ke,!1)),Le.type==="data"&&typeof Le.data=="string"&&Le.data.length>0&&Yt.getState().appendToBuffer(Y,Ke,Le.data,Le.sequence,Le.replayData),Le.type==="exit"&&(Yt.getState().setTabLifecycle(Y,Ke,"exited"),Yt.getState().setConnecting(Y,Ke,!1),Yt.getState().removeProjectActionRun(we),delete U.current[we],X.current[we]?.(),delete X.current[we],window.clearTimeout(Q.current[we]),delete Q.current[we])},onError:(Le,Fe)=>{Yt.getState().setConnecting(Y,Ke,!1),Fe&&(Yt.getState().setTabLifecycle(Y,Ke,"exited"),Yt.getState().setTabSessionId(Y,Ke,null),Yt.getState().removeProjectActionRun(we))}});X.current[we]=le.close;const K=$.autoOpenUrl===!0&&m&&($.desktopOpenSshForward||"").trim().length>0,ve=$.autoOpenUrl?Lb($.openUrl):null,$e=$.autoOpenUrl&&m?Tp($.desktopOpenSshForward,h):null;M({key:we,directory:Y,actionId:$.id,tabId:Ke,sessionId:He,status:$.id===qs&&!ve?"waiting-for-preview":"running"}),window.clearTimeout(Q.current[we]),delete Q.current[we],$.id===qs&&!ve&&(Q.current[we]=window.setTimeout(()=>{const Le=Yt.getState(),Fe=Le.projectActionRuns[we];Le.updateProjectActionRunStatus(we,"running"),Fe&&(Le.setActiveTab(Fe.directory,Fe.tabId),Ae.getState().openContextPanelTab(Fe.directory,{mode:"terminal"})),delete Q.current[we]},Bb)),U.current[we]={lastSeenChunkId:null,openedUrl:!!$e||!!ve||ae,tail:"",openInPreview:$.id===qs,announced:[],offering:!1};const We=_b($.command.trim().replace(/\r\n|\r/g,`
|
|
37
|
-
`));await a.sendInput(He,`${We}\r`),$e?(D(Y,Ke,null,{locked:!0}),W($e),Oe.success(o("projectActions.toast.openedForwardedUrl"))):ve?(D(Y,Ke,ve,{locked:!0,autoOpened:!0}),x(Y,ve),Oe.success(o("projectActions.toast.openedActionUrl"))):ae?(D(Y,Ke,null,{locked:!0}),Oe.error(o("projectActions.error.invalidCustomUrlFormat"))):K?(D(Y,Ke,null,{locked:!0}),Oe.error(o("projectActions.error.selectedDesktopSshForwardUnavailable"))):D(Y,Ke,null,{locked:!1,autoOpened:!1})}catch($){I(Ne),delete U.current[Ne],X.current[Ne]?.(),delete X.current[Ne],window.clearTimeout(Q.current[Ne]),delete Q.current[Ne],Oe.error($ instanceof Error?$.message:o("projectActions.error.failedToRunAction"))}finally{me.current.delete(Ne)}}},[l.colors.surface.background,l.colors.syntax.base.foreground,l.metadata.variant,h,ge,i,u,m,Y,S,b,W,x,P,d.isVSCode,I,k,M,D,A,ue?.id,o,a]),Re=c.useCallback(async Z=>{const Ne=jn(Y,Z.id),Me=P[Ne];if(!Me)return;z(Ne,"stopping");const $=Ob(a,Me.sessionId,1e3);try{await a.sendInput(Me.sessionId,"")}catch{}const ae=await $;if(Yt.getState().getDirectoryState(Me.directory)?.tabs.find(Ke=>Ke.id===Me.tabId)?.terminalSessionId===Me.sessionId&&!ae){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:Me.sessionId})}catch{}else try{await a.close(Me.sessionId)}catch{}A(Me.directory,Me.tabId,null)}I(Ne),delete U.current[Ne],X.current[Ne]?.(),delete X.current[Ne],window.clearTimeout(Q.current[Ne]),delete Q.current[Ne]},[Y,P,I,A,a,z]),ce=c.useCallback(()=>{const Z=F??xe[0];if(!Z)return;const Ne=jn(Y,Z.id),Me=P[Ne];if(Me?.status!=="stopping"){if(Me){Re(Z);return}Ce(Z)}},[xe,Y,Ce,P,F,Re]),ye=c.useCallback((Z,Ne=!1)=>{if(O(Z.id),!Ne){Ce(Z);return}const Me=jn(Y,Z.id),$=P[Me];if($?.status!=="stopping"){if($){Re(Z);return}Ce(Z)}},[Y,Ce,P,Re]),be=c.useCallback(()=>{ue?.id&&(f(ue.id),v("projects"),g(!0))},[g,v,f,ue?.id]),te=F??xe[0]??null,pe=te?P[jn(Y,te.id)]:null,Pe=Yt(Z=>pe?Z.sessions.get(pe.directory)?.tabs.find(Ne=>Ne.id===pe.tabId)?.previewUrl??null:null);if(d.isVSCode||!i&&u||!ue||!Y)return null;const de=F??xe[0]??null;if(!de)return null;const he=de.icon||"play",fe=de.id===qs?"scan-2":mi[he]||"play",B=jn(Y,de.id),H=P[B],ke=H?.status==="stopping",Se=H?.status==="waiting-for-preview",Be=!!(H&&Pe),_e=()=>{!H||!Pe||x(H.directory,Pe)},Te=de.id===qs;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:j||ke,className:Ie("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:ce,"aria-label":H?o("projectActions.actions.stopNamedAria",{name:de.name}):o("projectActions.actions.runNamedAria",{name:de.name}),children:ke||Se?s.jsx(R,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):H?s.jsx(R,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(R,{name:fe,className:"h-5 w-5"})})}),Te?s.jsx(xt,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),Be?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("projectActions.actions.openPreview"),onClick:_e,children:s.jsx(R,{name:"global",className:"h-4 w-4"})})}),s.jsx(xt,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(en,{children:[s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("projectActions.actions.chooseActionAria"),children:s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Zs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ut,{className:"flex items-center gap-2",onClick:be,children:[s.jsx(R,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Ls,{}),xe.map(Z=>{const Ne=Z.icon||"play",Me=Z.id===qs?"scan-2":mi[Ne]||"play",$=jn(Y,Z.id),ae=P[$],se=!!ae,we=ae?.status==="stopping";return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{ye(Z,!0)},children:[s.jsx(R,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z.name}),we||ae?.status==="waiting-for-preview"?s.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Z.id)})]})]})]}):s.jsxs("div",{className:Ie("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ce,disabled:j||ke,className:Ie("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":H?o("projectActions.actions.stopNamedAria",{name:de.name}):o("projectActions.actions.runNamedAria",{name:de.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||Se?s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):H?s.jsx(R,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(R,{name:fe,className:"h-4 w-4"})})})}),Te?s.jsx(xt,{sideOffset:6,children:o("projectActions.actions.autoDiscoverTooltip")}):null]}),Be?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:_e,className:Ie(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":o("projectActions.actions.openPreview"),children:s.jsx(R,{name:"global",className:"h-4 w-4"})})}),s.jsx(xt,{sideOffset:6,children:o("projectActions.actions.openPreview")})]}):null,s.jsxs(en,{children:[s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(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":o("projectActions.actions.chooseActionAria"),children:s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Zs,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ut,{className:"flex items-center gap-2",onClick:be,children:[s.jsx(R,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("projectActions.actions.addNewAction")})]}),s.jsx(Ls,{}),xe.map(Z=>{const Ne=Z.icon||"play",Me=Z.id===qs?"scan-2":mi[Ne]||"play",$=jn(Y,Z.id),ae=P[$],se=!!ae,we=ae?.status==="stopping";return s.jsxs(Ut,{className:"flex items-center gap-2",onClick:()=>{ye(Z,!0)},children:[s.jsx(R,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z.name}),we||ae?.status==="waiting-for-preview"?s.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):se?s.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},Z.id)})]})]})]})},Bl="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",Wb=()=>{const t=Ye.c(35),{t:e}=ht(),n=Ae(zb),r=Ae(Vb),i=wb(),o=c.useRef(null),l=Jn(eo("toggle_sidebar",r)),{usesFramelessChrome:a,side:d}=Kd(),u=Hb;let m,h;t[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{if(typeof document>"u")return;const V=o.current;if(!V)return;const T=()=>{const O=Math.max(V.getBoundingClientRect().width,V.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(O)}px`)};if(T(),typeof ResizeObserver>"u")return;const _=new ResizeObserver(T);return _.observe(V),()=>{_.disconnect()}},h=[],t[0]=m,t[1]=h):(m=t[0],h=t[1]),c.useEffect(m,h);const y="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let b;t[2]===Symbol.for("react.memo_cache_sentinel")?(b={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=b):b=t[2];const S="flex items-center gap-2";let v;t[3]!==a||t[4]!==d?(v=a&&d==="left"?s.jsx(Gd,{visible:!0,position:"left"}):null,t[3]=a,t[4]=d,t[5]=v):v=t[5];let g;t[6]!==e||t[7]!==a?(g=a?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:Ie(Bl,"shrink-0"),children:s.jsx(R,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(xt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=a,t[8]=g):g=t[8];const f=yt;let x;t[9]!==e?(x=e("header.actions.openSessionsAria"),t[9]=e,t[10]=x):x=t[10];let p,w;t[11]===Symbol.for("react.memo_cache_sentinel")?(p=Ie(Bl,"shrink-0"),w=s.jsx(R,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=p,t[12]=w):(p=t[11],w=t[12]);let N;t[13]!==x||t[14]!==n?(N=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":x,className:p,children:w})}),t[13]=x,t[14]=n,t[15]=N):N=t[15];const C=xt,k=e("header.actions.openSessionsWithShortcut",{shortcut:l});let A;t[16]!==k?(A=s.jsx("p",{children:k}),t[16]=k,t[17]=A):A=t[17];let D;t[18]!==C||t[19]!==A?(D=s.jsx(C,{children:A}),t[18]=C,t[19]=A,t[20]=D):D=t[20];let P;t[21]!==f||t[22]!==N||t[23]!==D?(P=s.jsxs(f,{children:[N,D]}),t[21]=f,t[22]=N,t[23]=D,t[24]=P):P=t[24];let M;t[25]!==i?(M=i?s.jsx($b,{projectRef:i.projectRef,directory:i.directory}):null,t[25]=i,t[26]=M):M=t[26];let z;t[27]!==P||t[28]!==M||t[29]!==v||t[30]!==g?(z=s.jsxs("div",{ref:o,className:S,children:[v,g,P,M]}),t[27]=P,t[28]=M,t[29]=v,t[30]=g,t[31]=z):z=t[31];let I;return t[32]!==z||t[33]!==b?(I=s.jsx("div",{className:y,style:b,children:z}),t[32]=z,t[33]=b,t[34]=I):I=t[34],I};function zb(t){return t.toggleSidebar}function Vb(t){return t.shortcutOverrides}function Ub(t){console.warn("[titlebar] failed to open app menu",t)}function Hb(t){const e=t.currentTarget.getBoundingClientRect();Fn("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Ub)}function Au(t){const e=Ye.c(5),{className:n}=t,i=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let o,l,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),l=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),a=s.jsx(R,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=o,e[1]=l,e[2]=a):(o=e[0],l=e[1],a=e[2]);let d;return e[3]!==i?(d=s.jsxs("span",{"aria-hidden":"true",className:i,children:[o,l,a]}),e[3]=i,e[4]=d):d=e[4],d}const Fl=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Kb(t,e,n){const r=Ye.c(5),[i,o]=c.useState();let l,a;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){o(void 0);return}if(!t){o(void 0);return}o(void 0);let d=!1;return(async()=>{const[u,m]=await Promise.all([Sf(t),vf(t)]).catch(Gb);if(d)return;const h=Fl(u),y=Fl(m);if(!h||!y||y===h)return;const b=n||"",S=y.split("/").filter(Boolean).pop()||y;o({source:"sdk",path:y,projectDirectory:h,branch:b,label:b||S,name:S,worktreeRoot:y,worktreeStatus:"ready",headState:b?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},a=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=a):(l=r[3],a=r[4]),c.useEffect(l,a),e??i}function Gb(){return["",""]}class li extends Error{code;model;requiredChars;availableChars;constructor(e,n={}){super(e),this.name="WalkthroughError",this.code=n.code,this.model=n.model,this.requiredChars=n.requiredChars,this.availableChars=n.availableChars}}const ci="/api/walkthrough",Du=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),Pu=()=>new li("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),qb=t=>!Du(t)&&(t.ok||t.status===404),La=async(t,e)=>{if(qb(t))throw Pu();const n=await t.json().catch(()=>null);throw new li(typeof n?.error=="string"?n.error:e,{code:typeof n?.code=="string"?n.code:void 0,model:n?.model??void 0,requiredChars:typeof n?.requiredChars=="number"?n.requiredChars:void 0,availableChars:typeof n?.availableChars=="number"?n.availableChars:void 0})},Tu=async t=>{if(!Du(t))throw Pu();try{return await t.json()}catch{throw new li("The server returned a malformed walkthrough response")}};async function Qb(t,e,n={}){const r=await rs(ci,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?Tu(r):La(r,"Failed to load walkthrough")}async function Yb(t,e,n={}){const r=await rs(`${ci}/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e,force:n.force===!0,...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}}),signal:n.signal});return r.ok?Tu(r):La(r,"Failed to generate walkthrough")}async function Xb(t,e){const n=await rs(`${ci}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await La(n,"Failed to cancel walkthrough generation")}async function Jb(t,e,n){const r=await rs(`${ci}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const i=await r.json().catch(()=>null);return typeof i?.stage=="string"?i.stage:null}const Ar={status:"idle",stage:null,result:null,readiness:null,error:null},Zb=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,En=(t,e)=>`${Cs()}\0${t}\0${Zb(e)}`,_l=t=>t instanceof li?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},on=new Map,Dr=new Map,ex=1e3,tx=or()(cu((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,i)=>{const o=En(n,r);t(l=>{const a={...l.selectedLanguage};return i?a[o]=i:delete a[o],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[En(n,r)],selectModel:(n,r,i)=>{const o=En(n,r);t(l=>{const a={...l.selectedModel};return i?a[o]=i:delete a[o],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[En(n,r)],requestSource:(n,r)=>{t(i=>({requestedSource:{...i.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const i={...r.requestedSource};return delete i[n],{requestedSource:i}})},getEntry:(n,r)=>e().entries[En(n,r)]??Ar,load:async(n,r,i={})=>{if(!n)return;const o=En(n,r);if(e().entries[o]?.status==="generating")return;on.get(o)?.abort();const a=new AbortController;on.set(o,a),t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Ar,status:"loading",error:null}}}));try{const d=await Qb(n,r,{model:e().selectedModel[o],language:i.language,signal:a.signal});if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[o]:{status:"ready",stage:null,result:d,readiness:d.readiness??null,error:null}}})),d.generating&&e().generate(n,r,{language:i.language})}catch(d){if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Ar,status:"error",stage:null,error:_l(d)}}}))}finally{on.get(o)===a&&on.delete(o)}},generate:async(n,r,i={})=>{if(!n)return;const o=En(n,r);on.get(o)?.abort();const l=new AbortController;on.set(o,l),t(d=>({entries:{...d.entries,[o]:{...d.entries[o]??Ar,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const d=Dr.get(o);d!==void 0&&(clearInterval(d),Dr.delete(o))};a(),Dr.set(o,setInterval(()=>{Jb(n,r).then(d=>{!d||l.signal.aborted||t(u=>{const m=u.entries[o];return!m||m.status!=="generating"||m.stage===d?u:{entries:{...u.entries,[o]:{...m,stage:d}}}})}).catch(()=>{})},ex));try{const d=await Yb(n,r,{force:i.force,model:e().selectedModel[o],language:i.language,signal:l.signal});if(l.signal.aborted)return;t(u=>({entries:{...u.entries,[o]:{status:"ready",stage:null,result:d,readiness:u.entries[o]?.readiness??null,error:null}}}))}catch(d){if(l.signal.aborted)return;t(u=>({entries:{...u.entries,[o]:{...u.entries[o]??Ar,status:"error",stage:null,error:_l(d)}}}))}finally{a(),on.get(o)===l&&on.delete(o)}},cancel:(n,r)=>{const i=En(n,r);Xb(n,r).catch(()=>{}),on.get(i)?.abort(),on.delete(i),t(o=>{const l=o.entries[i];return l?{entries:{...o.entries,[i]:{...l,status:l.result?"ready":"idle",stage:null,error:null}}}:o})},reset:()=>{for(const n of on.values())n.abort();on.clear();for(const n of Dr.values())clearInterval(n);Dr.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),sx="border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)] hover:text-[var(--status-info)]",nx=3e4,Ll=20,Iu=(t,e)=>JSON.stringify([Cs(),t,e]),rx=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,i]=e;return typeof n!="string"||typeof r!="string"||typeof i!="number"?null:{runtimeKey:n,directory:r,number:i}}catch{return null}},$l=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),lo=new Map,ox=t=>{const e=Object.entries(t);return e.length<=Ll?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Ll))},Wl=or()((t,e)=>({entries:{},ensure:async(n,r,i,o)=>{const l=Iu(r,i),a=o?.includeCheckDetails??!1,d=e().entries[l],u=d&&d.result&&Date.now()-d.fetchedAt<nx&&(d.hasCheckDetails||!a);if(!o?.force&&u)return d.result;const m=`${l}::${a?"details":"plain"}`,y=lo.get(`${l}::details`)??(a?null:lo.get(m));if(y&&!o?.force)return y;const b=(async()=>{t(S=>({entries:{...S.entries,[l]:{...S.entries[l]??$l(),isLoading:!0,error:null}}}));try{const S=await n.prContext(r,i,{includeDiff:!1,includeCheckDetails:a,sourceRepo:o?.sourceRepo??null});return t(v=>({entries:ox({...v.entries,[l]:{result:S,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),S}catch(S){const v=S instanceof Error?S.message:"Failed to load pull request context";return t(g=>({entries:{...g.entries,[l]:{...g.entries[l]??$l(),isLoading:!1,error:v}}})),null}finally{lo.delete(m)}})();return lo.set(m,b),b},invalidate:(n,r)=>{t(i=>{const o={};for(const[l,a]of Object.entries(i.entries)){const d=rx(l);d&&d.directory===n&&(r==null||d.number===r)||(o[l]=a)}return{entries:o}})}})),ix=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const o of t){if(o.status==="in_progress"){e.pending+=1,e.inProgress+=1,o.startedAt&&(!n||o.startedAt<n)&&(n=o.startedAt);continue}if(o.status==="queued"){e.pending+=1,e.queued+=1;continue}const l=typeof o.conclusion=="string"?o.conclusion.toLowerCase():"";if(!l){e.pending+=1;continue}l==="success"||l==="neutral"||l==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},ax=35e3,pi=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const i=e?Date.parse(e):n??Date.now();if(!Number.isFinite(i)||i<=r)return null;const o=Math.floor((i-r)/6e4);if(o<1)return"<1m";if(o<60)return`${o}m`;const l=Math.floor(o/60),a=o%60;return a>0?`${l}h ${a}m`:`${l}h`},gi=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},zl=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},lx=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",i=e.mergeable===!1||r==="blocked"||r==="dirty";return n||i?"blocked":"open"},cx=[2e3,5e3],Vl=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),On=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},dx=(t,e)=>{const n=On(t);if(!n||n.includes("->"))return"";if(e){const i=`${e}/`;return n.startsWith(i)?n.slice(i.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},ux=(t,e)=>`${t}::${e}`,$a=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},bi=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const o=t.find(l=>l.name===n);if(o)return o}const r=$a(e.trackingBranch);if(r){const o=r==="origin"?t.find(a=>a.name==="upstream"):null;if(o)return o;const l=t.find(a=>a.name===r);if(l)return l}const i=t.find(o=>o.name==="origin");return i||(t[0]??null)},mx=t=>t.startsWith("pr-"),fx=(t,e)=>{const n=$a(e),r=new Map(t.map(l=>[l.name,l])),i=[],o=l=>{l&&(i.some(a=>a.name===l.name)||i.push(l))};return n&&o(r.get(n)),o(r.get("upstream")),o(r.get("origin")),t.filter(l=>!mx(l.name)).forEach(l=>o(l)),t.forEach(l=>o(l)),i},Pr=new Map,co=si;function hx(t,e){const[n,r]=c.useState(null),[i,o]=c.useState([]),l=c.useRef(null);return c.useEffect(()=>{r(null),o([])},[t]),c.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.current=t;let a=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(a||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const u=await e.repoBranches(d.upstream.owner,d.upstream.repo);a||o(u)}catch{}}catch{}})(),()=>{a=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:i}}const px=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:i=[],remoteBranches:o=[],onGeneratedDescription:l})=>{const{t:a}=ht(),d=Ae(q=>q.timeFormatPreference),{github:u}=Pn(),m=er(q=>q.status),h=er(q=>q.hasChecked),y=Ae(q=>q.setSettingsDialogOpen),b=Ae(q=>q.setSettingsPage),S=qe(q=>q.currentSessionId),v=qe(q=>!!q.newSessionDraft?.open),{isMobile:g,hasTouchInput:f,screenWidth:x}=zn(),p=Ae(q=>q.openContextSurface),w=tx(q=>q.requestSource),N=!g&&x>=768&&!Dn(),C=c.useCallback(()=>{b("github"),y(!0)},[y,b]),k=c.useMemo(()=>ux(t,e),[t,e]),A=c.useMemo(()=>Pr.get(k)??null,[k]),D=Ys(q=>q.ensureEntry),P=Ys(q=>q.setParams),M=Ys(q=>q.startWatching),z=Ys(q=>q.stopWatching),I=Ys(q=>q.refresh),V=Ys(q=>q.updateStatus),[T,_]=c.useState(()=>A?.title??Vl(e)),[O,j]=c.useState(()=>A?.body??""),[E,L]=c.useState(()=>A?.draft??!1),[U,X]=c.useState(()=>A?.additionalContext??""),[Q,me]=c.useState(()=>{const q=typeof A?.targetBaseBranch=="string"?On(A.targetBaseBranch):"";return q||On(n)}),[re,G]=c.useState("squash"),[ee,ue]=c.useState(!1),[W,ne]=c.useState(!1),[Y,F]=c.useState(!1),[J,ie]=c.useState(!1),[xe,ge]=c.useState(!1),[Ce,Re]=c.useState(!1),[ce,ye]=c.useState(null),[be,te]=c.useState(""),[pe,Pe]=c.useState(""),[de,he]=c.useState(!1),[fe,B]=c.useState(!1),[H,ke]=c.useState(()=>bi(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r})),[Se,Be]=c.useState(!1),{detectedUpstream:_e,upstreamBranches:Te}=hx(t,u);c.useEffect(()=>{Be(!1)},[t]);const Z=i.some(q=>q.name==="upstream"),Me=!!(t&&e&&n&&(e!==n||(Z||_e!==null))),$=c.useMemo(()=>ni(t,e,H?.name??null),[t,e,H?.name]),ae=Ys(q=>q.entries[$]),se=ae?.isLoading??!1,we=ae?.status??null,Ke=ae?.error??null,Qe=ae?.isInitialStatusResolved??!1,He=c.useMemo(()=>{const q=Se?null:H?.name?.trim()||null,Ve=new Set;for(const Dt of o){const gt=dx(Dt,q);!gt||gt==="HEAD"||Ve.add(gt)}if(Se)for(const Dt of Te)Dt&&Dt!=="HEAD"&&Ve.add(Dt);const Xe=On(n);Xe&&Xe!=="HEAD"&&Ve.add(Xe);const ft=On(Q);return ft&&ft!=="HEAD"&&Ve.add(ft),Array.from(Ve).sort((Dt,gt)=>Dt.localeCompare(gt))},[n,o,H?.name,Q,Te,Se]);c.useEffect(()=>{if(i.length===0){H&&ke(null);return}(!H||!i.some(q=>q.name===H.name))&&ke(bi(i,{selectedRemoteName:A?.selectedRemoteName,trackingBranch:r}))},[A?.selectedRemoteName,i,H,r]),c.useEffect(()=>{const q=On(n);if(!Q&&q){me(q);return}if(He.length!==0&&!He.includes(Q)){const Ve=He.includes(q)?q:He[0];Ve&&me(Ve)}},[He,n,Q]);const[le,K]=c.useState(()=>A?.activeSegment??"overview"),[ve,$e]=c.useState(new Set),[We,Le]=c.useState(new Set),Fe=c.useRef(new Set),Ge=c.useRef(null),rt=c.useRef(!1),St=c.useRef(new Set),Rt=c.useRef([]);c.useEffect(()=>{_e&&!Z&&Be(!0)},[_e,Z]),c.useEffect(()=>{Se&&_e?.defaultBranch&&me(_e.defaultBranch)},[Se,_e?.defaultBranch]);const ze=we?.pr??null,Pt=ze?.state==="merged"||ze?.state==="closed",Nt=Pt?null:ze,Tt=Nt?Iu(t,Nt.number):null,Et=Wl(q=>Tt?q.entries[Tt]:void 0),vt=Wl(q=>q.ensure),Ct=Et?.result??null,It=Et?.isLoading??!1,mt=c.useCallback(q=>{K(q);const Ve=Pr.get(k);Ve&&Pr.set(k,{...Ve,activeSegment:q})},[k]);c.useEffect(()=>{!Nt||!u?.prContext||le==="overview"||vt(u,t,Nt.number,{includeCheckDetails:le==="checks",sourceRepo:we?.repo??null})},[le,t,vt,u,Nt,we?.repo]);const Ze=we?.checks??null,je=(Ze?.pending??0)>0,ot=Ct?.checkRuns??null,ct=Ct?.fetchedAt;c.useEffect(()=>{if(!ot||ot.length===0)return;const q=ix(ot);V($,Ve=>{if(!Ve?.pr||typeof ct=="number"&&typeof Ve.fetchedAt=="number"&&ct<Ve.fetchedAt)return Ve;const Xe=Ve.checks;return Xe&&Xe.state===q.state&&Xe.total===q.total&&Xe.success===q.success&&Xe.failure===q.failure&&Xe.pending===q.pending&&Xe.inProgress===q.inProgress&&Xe.queued===q.queued&&Xe.startedAt===q.startedAt?Ve:{...Ve,checks:q,...typeof ct=="number"?{fetchedAt:ct}:{}}})},[ot,ct,$,V]),c.useEffect(()=>{if(le!=="checks"||!je||!ze||!u?.prContext)return;const q=window.setInterval(()=>{vt(u,t,ze.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null,force:!0})},ax);return()=>window.clearInterval(q)},[le,je,t,vt,u,ze,we?.repo]);const[Mt,Je]=c.useState(()=>Date.now());c.useEffect(()=>{if(!je)return;Je(Date.now());const q=window.setInterval(()=>Je(Date.now()),3e4);return()=>window.clearInterval(q)},[je]);const nt=ze?`${t}#${ze.number}`:null,jt=!!(nt&&ce===nt);c.useEffect(()=>{if(!u?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const q=`${t}#${ze.number}`;if(Fe.current.has(q))return;Fe.current.add(q),ye(q);let Ve=!1;return vt(u,t,ze.number,{sourceRepo:we?.repo??null}).then(Xe=>{if(Ve)return;const ft=Xe?.pr;ft&&V($,Dt=>!Dt?.pr||Dt.pr.number!==ze.number?Dt:{...Dt,pr:{...Dt.pr,body:ft.body||""}})}).catch(()=>{}).finally(()=>{Ve||ye(Xe=>Xe===q?null:Xe)}),()=>{Ve=!0}},[t,vt,u,ze,$,we?.repo,V]),c.useEffect(()=>{if(!ze){Re(!1),te(""),Pe(""),Ge.current=null;return}const q=Ge.current!==null&&Ge.current!==ze.number;q&&Re(!1),(!Ce||q)&&(te(ze.title||""),Pe(ze.body||"")),Ge.current=ze.number},[Ce,ze]);const At=c.useCallback(q=>{if(!q)return"";const Ve=Date.parse(q);return Number.isFinite(Ve)?vd(Ve,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):q},[d]),Ot=c.useMemo(()=>{const q=m?.user?.login;return typeof q=="string"?q.trim():""},[m]),$t=c.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Zt=c.useCallback(q=>{const Ve=Ot.toLowerCase(),Xe=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return q.replace(Xe,(ft,Dt,gt)=>{const wt=`@${gt}`,is=gt.toLowerCase();return`${Dt}[${wt}](https://github.com/${is}${Ve&&is===Ve?"?oc-self-mention=1":""})`})},[Ot]),Gt=c.useMemo(()=>{const q=(Ct?.issueComments??[]).map(ft=>({id:`issue-${ft.id}`,body:ft.body||"",authorName:ft.author?.name||ft.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ft.author?.login||null,avatarUrl:ft.author?.avatarUrl||null,createdAt:ft.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),Ve=(Ct?.reviewComments??[]).map(ft=>({id:`review-${ft.id}`,body:ft.body||"",authorName:ft.author?.name||ft.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ft.author?.login||null,avatarUrl:ft.author?.avatarUrl||null,createdAt:ft.createdAt,context:a("gitView.pr.comments.reviewContext"),path:ft.path||null,line:ft.line??null})),Xe=[...q,...Ve];return Xe.sort((ft,Dt)=>{const gt=ft.createdAt?Date.parse(ft.createdAt):0,wt=Dt.createdAt?Date.parse(Dt.createdAt):0,is=Number.isFinite(gt)?gt:0,cs=Number.isFinite(wt)?wt:0;return is-cs}),Xe},[Ct,a]),Ft=c.useCallback(()=>{const q=S??(v?"draft":null);return q?{directory:t,sessionKey:q}:(Oe.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[S,t,v,a]),qt=c.useCallback((q,Ve)=>{const Xe=Ve.authorLogin?`@${Ve.authorLogin}`:Ve.authorName,ft=Ve.path?` · ${Ve.path}${Ve.line?`:${Ve.line}`:""}`:"";Ei.getState().addDraft(q,{source:"pr-comment",fileLabel:`PR #${ze?.number??""} ${Xe}${ft}`,startLine:Ve.line??0,endLine:Ve.line??0,code:Ve.body,language:"markdown",text:""})},[ze?.number]),Xt=c.useCallback((q,Ve)=>{const Xe=q.status||"unknown",ft=q.conclusion??void 0,Dt=ft?`${Xe} / ${ft}`:Xe,gt=q.app?.name||q.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:Ve?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[Ve?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:q.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:gt?`${gt} · ${Dt}`:Dt})]}),q.detailsUrl?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:q.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),q.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:q.output.title}):null,q.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:q.output.summary}):null,q.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap break-words max-h-48 overflow-y-auto",children:q.output.text}):null,Array.isArray(q.annotations)&&q.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",q.annotations.length>20?` (showing 20/${q.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:q.annotations.slice(0,20).map((wt,is)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro break-words text-[var(--status-error)]",children:[wt.title||wt.level||"Issue",wt.path?` · ${wt.path}`:"",typeof wt.startLine=="number"?`:${wt.startLine}`:"",typeof wt.endLine=="number"&&wt.endLine!==wt.startLine?`-${wt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:wt.message}),wt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:wt.rawDetails}):null]},`${wt.path||"file"}:${wt.startLine||is}:${is}`))})]}):null,q.job?.steps&&q.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:q.job.steps.map((wt,is)=>{const cs=(wt.conclusion||"").toLowerCase(),Jt=cs&&!["success","neutral","skipped"].includes(cs),tn=`${q.id??"run"}:${q.job?.jobId??"job"}:${wt.number??is}:${wt.name}`,un=ve.has(tn);return Jt?s.jsxs(_i,{open:un,children:[s.jsxs("button",{type:"button",onClick:()=>{$e(ir=>{const Tn=new Set(ir);return Tn.has(tn)?Tn.delete(tn):Tn.add(tn),Tn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Jt?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[un?s.jsx(R,{name:"arrow-down-s",className:"size-4"}):s.jsx(R,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:wt.name}),wt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:wt.conclusion}):null]}),s.jsx(Li,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof wt.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",wt.number]}):null,wt.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",wt.status]}):null,wt.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",wt.conclusion]}):null,wt.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",At(wt.startedAt)]}):null,wt.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",At(wt.completedAt)]}):null]})})]},tn):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:wt.name}),wt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:wt.conclusion}):null]},tn)})})]}):null]})},[ve,At,a]),[zt,Ee]=c.useState(!1),[Ue,et]=c.useState(!1),lt=c.useCallback(async()=>{if(!u?.prContext){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const q=Ft();if(q){Ee(!0);try{const Ve=await vt(u,t,ze.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null});if(!Ve){Oe.error(a("gitView.pr.toast.loadChecksFailed"));return}const ft=(Ve.checkRuns??[]).filter(gt=>gi(gt.conclusion));if(ft.length===0){Oe.message(a("gitView.pr.toast.noFailedChecks"));return}const Dt=Ei.getState();for(const gt of ft){const wt=(gt.annotations??[]).map(Jt=>[[Jt.level,Jt.title].filter(Boolean).join(" "),Jt.path?`${Jt.path}${typeof Jt.startLine=="number"?`:${Jt.startLine}`:""}`:null,Jt.message,Jt.rawDetails].filter(Boolean).join(`
|
|
38
|
-
`)),is=(gt.job?.steps??[]).filter(Jt=>gi(Jt.conclusion)).map(Jt=>`step ${Jt.number??"?"}: ${Jt.name} → ${Jt.conclusion}`),cs=[`check: ${gt.job?.workflowName?`${gt.job.workflowName} / ${gt.name}`:gt.name}`,`status: ${gt.status??"unknown"} / ${gt.conclusion??"unknown"}`,gt.detailsUrl?`url: ${gt.detailsUrl}`:null,gt.output?.title?`title: ${gt.output.title}`:null,gt.output?.summary?`summary:
|
|
39
|
-
${gt.output.summary}`:null,is.length>0?`failed steps:
|
|
40
|
-
${is.join(`
|
|
41
|
-
`)}`:null,wt.length>0?`annotations:
|
|
42
|
-
${wt.join(`
|
|
43
|
-
---
|
|
44
|
-
`)}`:null].filter(Boolean).join(`
|
|
45
|
-
|
|
46
|
-
`);Dt.addDraft(q,{source:"pr-check",fileLabel:`PR #${ze.number} · ${gt.name}`,startLine:0,endLine:0,code:cs,language:"text",text:""})}}catch(Ve){const Xe=Ve instanceof Error?Ve.message:String(Ve);Oe.error(a("gitView.pr.toast.loadChecksFailed"),{description:Xe})}finally{Ee(!1)}}},[t,vt,u,ze,Ft,we?.repo,a]),ut=c.useCallback(async()=>{if(!u?.prContext){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const q=Ft();if(q){et(!0);try{if(!await vt(u,t,ze.number,{sourceRepo:we?.repo??null})){Oe.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Gt.length===0){Oe.message(a("gitView.pr.toast.noPrComments"));return}for(const Xe of Gt)qt(q,Xe)}catch(Ve){const Xe=Ve instanceof Error?Ve.message:String(Ve);Oe.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:Xe})}finally{et(!1)}}},[qt,t,vt,u,ze,Ft,we?.repo,a,Gt]),kt=c.useCallback(async q=>{const Ve=Ft();Ve&&qt(Ve,q)},[qt,Ft]),st=c.useCallback(async q=>{await I($,q)},[$,I]),_t=c.useCallback(()=>{Rt.current.forEach(q=>{window.clearTimeout(q)}),Rt.current=cx.map(q=>window.setTimeout(()=>{st({force:!0,silent:!0,markInitialResolved:!0})},q))},[st]);c.useEffect(()=>{if(!u?.prStatus||!Me||i.length<=1||rt.current||we?.pr)return;const q=`${k}::${H?.name??""}`;if(St.current.has(q))return;St.current.add(q);const Ve=fx(i,r).filter(Dt=>Dt.name!==H?.name);if(Ve.length===0)return;let Xe=!1;return(async()=>{for(const Dt of Ve){if(Xe)return;try{if(!(await u.prStatus(t,e,Dt.name))?.pr)continue;if(Xe)return;ke(wt=>wt?.name===Dt.name?wt:Dt);return}catch{}}})(),()=>{Xe=!0}},[e,Me,t,u,i,H?.name,k,we?.pr,r]),c.useEffect(()=>{D($),P($,{directory:t,branch:e,remoteName:H?.name??null,canShow:Me,github:u,githubAuthChecked:h,githubConnected:m?.connected??null})},[e,Me,t,D,u,h,m?.connected,$,H?.name,P]),c.useEffect(()=>(M($),()=>{z($)}),[$,M,z]),c.useEffect(()=>{const q=Pr.get(k)??null;_(q?.title??Vl(e)),j(q?.body??""),L(q?.draft??!1),me(q?.targetBaseBranch?On(q.targetBaseBranch):On(n));const Ve=bi(i,{selectedRemoteName:q?.selectedRemoteName,trackingBranch:r});ke(Xe=>Xe?.name===Ve?.name?Xe:Ve)},[n,e,i,k,r]),c.useEffect(()=>{st({markInitialResolved:!0})},[$,st]),c.useEffect(()=>{!Me||!H?.name||st({force:!0,silent:!0,markInitialResolved:!0})},[Me,st,H?.name]),c.useEffect(()=>{const q=we?.resolvedRemoteName?.trim();if(!q||rt.current)return;const Ve=i.find(Xe=>Xe.name===q);Ve&&ke(Xe=>Xe?.name===Ve.name?Xe:Ve)},[i,we?.resolvedRemoteName]),c.useEffect(()=>{const q=()=>{const Xe=Ys.getState().entries[$]?.lastRefreshAt??0;Date.now()-Xe>6e4&&st({force:!0,silent:!0})},Ve=()=>{document.visibilityState==="visible"&&q()};return window.addEventListener("focus",q),document.addEventListener("visibilitychange",Ve),()=>{window.removeEventListener("focus",q),document.removeEventListener("visibilitychange",Ve)}},[$,st]),c.useEffect(()=>{h&&m?.connected===!1&&st({force:!0,silent:!0,markInitialResolved:!0})},[h,m,st]),c.useEffect(()=>{!t||!e||Pr.set(k,{title:T,body:O,draft:E,additionalContext:U,targetBaseBranch:Q,selectedRemoteName:H?.name,activeSegment:le})},[k,T,O,E,U,Q,H?.name,t,e,le]),c.useEffect(()=>{const q=Rt.current;return()=>{q.forEach(Ve=>{window.clearTimeout(Ve)}),Rt.current=[]}},[]);const es=c.useCallback(async()=>{if(!ee&&t){ue(!0);try{const Ve={base:Se&&_e?.defaultBranchSha?_e.defaultBranchSha:Q,head:e};U&&(Ve.context=U);const Xe=await jf(t,Ve);Xe.title?.trim()&&_(Xe.title.trim()),Xe.body?.trim()&&j(Xe.body.trim()),l?.()}catch(q){const Ve=q instanceof Error?q.message:String(q);Oe.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:Ve})}finally{ue(!1)}}},[U,e,_e?.defaultBranchSha,t,ee,l,Q,a,Se]),Ds=c.useCallback(async()=>{if(!u?.prCreate){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const q=T.trim();if(!q){Oe.error(a("gitView.pr.toast.titleRequired"));return}const Ve=Q.trim();if(!Ve){Oe.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!Se&&Ve===e){Oe.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}ne(!0);try{const Xe=$a(r),ft=Se&&_e,Dt=await u.prCreate({directory:t,title:q,head:e,base:Ve,...O.trim()?{body:O}:{},draft:E,...ft?{targetRepo:{owner:_e.owner,repo:_e.repo},headRemote:"origin"}:{...H?{remote:H.name}:{},...Xe&&Xe!==H?.name?{headRemote:Xe}:{}}});Oe.success(a("gitView.pr.toast.prCreated")),V($,gt=>gt&&{...gt,pr:Dt}),await st({force:!0}),_t()}catch(Xe){const ft=Xe instanceof Error?Xe.message:String(Xe);Oe.error(a("gitView.pr.toast.createPrFailed"),{description:ft})}finally{ne(!1)}},[O,e,_e,t,E,u,$,st,_t,H,Q,T,r,V,Se,a]),Os=c.useCallback(async q=>{if(!u?.prMerge){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}ie(!0);try{const Ve=await u.prMerge({directory:t,number:q.number,method:re});Ve.merged?Oe.success(a("gitView.pr.toast.prMerged")):Oe.message(a("gitView.pr.toast.prNotMerged"),{description:Ve.message||a("gitView.pr.notMergeable")}),await st({force:!0}),_t()}catch(Ve){const Xe=Ve instanceof Error?Ve.message:String(Ve);Oe.error(a("gitView.pr.toast.mergeFailed"),{description:Xe}),q.url&&co(q.url)}finally{ie(!1)}},[t,u,re,st,_t,a]),bs=c.useCallback(async q=>{if(!u?.prReady){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}ge(!0);try{await u.prReady({directory:t,number:q.number}),Oe.success(a("gitView.pr.toast.markedReady")),await st({force:!0}),_t()}catch(Ve){const Xe=Ve instanceof Error?Ve.message:String(Ve);Oe.error(a("gitView.pr.toast.markReadyFailed"),{description:Xe}),q.url&&co(q.url)}finally{ge(!1)}},[t,u,st,_t,a]),xs=c.useCallback(async q=>{if(!u?.prUpdate){Oe.error(a("gitView.pr.toast.githubApiUnavailable"));return}const Ve=be.trim();if(!Ve){Oe.error(a("gitView.pr.toast.titleRequired"));return}F(!0);try{const Xe=await u.prUpdate({directory:t,number:q.number,title:Ve,body:pe});V($,ft=>ft&&{...ft,pr:{...ft.pr??q,...Xe}}),Re(!1),Oe.success(a("gitView.pr.toast.prUpdated")),await st({force:!0}),_t()}catch(Xe){const ft=Xe instanceof Error?Xe.message:String(Xe);Oe.error(a("gitView.pr.toast.updatePrFailed"),{description:ft})}finally{F(!1)}},[t,pe,be,u,$,st,_t,V,a]);if(!Me)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pullRequest.availableOnFeatureBranches")})]})});const os=we?.repo?.url||null,Ps=Se&&_e?.url?_e.url:os,fs=!!we?.canMerge,Bs=!!we?.connected,Ks=h&&we?.connected===!1,ys=lx(we),ws=ys?`var(--pr-${ys})`:"var(--status-info)",Ss=ys==="draft"?"git-pr-draft":ys==="merged"?"git-merge":ys==="closed"?"git-close-pull-request":"git-pull-request",hn=ze?[`${ze.state}${ze.draft?" (draft)":""}`,ze.mergeable===!1?a("gitView.pr.notMergeable"):null,ze.state==="open"&&typeof ze.mergeableState=="string"&&ze.mergeableState&&ze.mergeableState!=="unknown"?ze.mergeableState:null].filter(Boolean).join(" · "):"",Gs=Ze?Ze.total>0?`${Ze.success}/${Ze.total} ${a("gitView.pr.checks.label")}`:`${Ze.state} ${a("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[ze?s.jsxs(at,{type:"button",variant:"outline",size:"xs",className:"shrink-0",onClick:()=>{co(ze.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(R,{name:Ss,className:"size-4 shrink-0",style:{color:ws}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(R,{name:Ss,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:a("gitView.pullRequest.title")}),ze?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",ze.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[se?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:se,onClick:()=>{st({force:!0})},"aria-label":a("gitView.pr.actions.refreshAria"),children:s.jsx(R,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]})]})]}),ze?s.jsxs("div",{className:"@container/pr-actions flex min-w-0 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:ws},children:hn}),Ze?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${zl(Ze.state)}`}),Gs]}):null,r&&H&&r.split("/")[0]!==H.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",H.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[N?s.jsxs(at,{variant:"outline",size:"sm",className:Ie("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",sx),onClick:()=>{w(t,{kind:"pr",number:ze.number}),p(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(R,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,fs&&ze.draft&&ze.state==="open"?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>bs(ze),disabled:xe||J||Y||Ce,"aria-label":a("gitView.pr.actions.markReadyAria"),children:xe?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,fs?s.jsxs(s.Fragment,{children:[s.jsxs($s,{value:re,onValueChange:q=>G(q),disabled:J||ze.state!=="open",children:[s.jsx(Ws,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Is,{})}),s.jsxs(zs,{children:[s.jsx(ns,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(ns,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(ns,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Os(ze),disabled:J||xe||ze.state!=="open"||ze.draft||Y||Ce,"aria-label":a("gitView.pr.actions.mergePrAria"),children:J?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"git-merge",className:"size-4"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ks?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(at,{variant:"outline",size:"sm",onClick:C,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,Ke?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:Ke}),Ps?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ps,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!Qe&&!Ke&&!Ks?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):ze&&!Pt?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(Qd,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:Ze&&Ze.total>0?`${a("gitView.pr.segment.checks")} ${Ze.success}/${Ze.total}`:a("gitView.pr.segment.checks"),icon:Ze?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${zl(Ze.state)}`}):void 0},{id:"comments",label:Ct?`${a("gitView.pr.segment.comments")} ${(Ct.issueComments?.length??0)+(Ct.reviewComments?.length??0)}`:a("gitView.pr.segment.comments")}],activeId:le,onSelect:q=>mt(q),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),le==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[fs&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,fs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.noMergePermission")}),s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:Ce?s.jsx(Nn,{value:be,onChange:q=>te(q.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:f?"on":"off",autoCapitalize:f?"sentences":"off",spellCheck:f}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:ze.title})}),ze.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:Ce?s.jsxs(s.Fragment,{children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{Re(!1),te(ze.title||""),Pe(ze.body||"")},disabled:Y,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(R,{name:"close",className:"size-4"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>xs(ze),disabled:Y||!be.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:Y?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"check",className:"size-4"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Re(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(R,{name:"edit",className:"size-4"})})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),Ce?s.jsx(ur,{value:pe,onChange:q=>Pe(q.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:f?"on":"off",autoCapitalize:f?"sentences":"off",spellCheck:f}):null,Ce?null:ze.body?.trim()?s.jsx(rl,{content:ze.body,className:"typography-markdown-body min-w-0 text-muted-foreground break-words",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:a(jt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,le==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[Ze&&Ze.total>0?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-muted/40",children:[Ze.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${Ze.success/Ze.total*100}%`}}):null,Ze.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${Ze.failure/Ze.total*100}%`}}):null,Ze.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${Ze.pending/Ze.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Ze.success,"/",Ze.total," ",a("gitView.pr.checks.label")]}),(Ze.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}),pi(Ze.startedAt,void 0,Mt)]}):null]}):null,Ze?.failure?s.jsxs(at,{variant:"outline",size:"sm",className:"w-fit gap-1.5 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:lt,disabled:zt,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[zt?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-4"}),a("gitView.pr.actions.resolveFailedChecks")]}):null,(Ct?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(Ct?.checkRuns??[]).map((q,Ve)=>{const Xe=`${q.id??"run"}:${q.name}:${Ve}`,ft=q.status==="in_progress",Dt=q.status==="queued",gt=gi(q.conclusion),wt=We.has(Xe),is=!!(q.output?.title||q.output?.summary||q.output?.text||(q.annotations?.length??0)>0||(q.job?.steps?.length??0)>0||q.detailsUrl),cs=q.job?.workflowName,Jt=ft?pi(q.startedAt,void 0,Mt):pi(q.startedAt,q.completedAt);return s.jsxs("div",{className:Ie("rounded-md border border-border/40",gt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!is,onClick:()=>{Le(tn=>{const un=new Set(tn);return un.has(Xe)?un.delete(Xe):un.add(Xe),un})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[ft?s.jsx(R,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):Dt?s.jsx(R,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):gt?s.jsx(R,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(R,{name:"checkbox-circle",className:"size-4 shrink-0 text-[var(--status-success)]"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:cs&&cs!==q.name?`${cs} / ${q.name}`:q.name}),Jt?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Jt}):null,is?s.jsx(R,{name:"arrow-down-s",className:Ie("size-4 shrink-0 text-muted-foreground transition-transform",wt&&"rotate-180")}):null]}),wt&&is?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:Xt(q,{hideHeader:!0})}):null]},Xe)})}):It?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.checkDetails.empty")})]}):null,le==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Gt.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(at,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)]",onClick:ut,disabled:Ue,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Ue?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Gt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Gt.map((q,Ve)=>{const Xe=(q.authorName||"?").charAt(0).toUpperCase(),ft=Ve===Gt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[ft?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:q.avatarUrl?s.jsx("img",{src:q.avatarUrl,alt:q.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Xe})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[q.authorName,q.authorLogin&&q.authorLogin!==q.authorName?` · @${q.authorLogin}`:""]}),q.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:At(q.createdAt)}):null,s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsxs(at,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{kt(q)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(R,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(xt,{children:s.jsx("p",{children:a("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[q.context,q.path?` · ${q.path}`:"",q.line?`:${q.line}`:""]}),s.jsx(rl,{content:Zt(q.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",$t].filter(Boolean).join(" "),enableFileReferences:!1})]})]},q.id)})})}):It&&!Ct?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[ze&&Pt?s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md border border-border/60 bg-surface-muted/40 px-2.5 py-2",children:[s.jsx(R,{name:ze.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:ws}}),s.jsx("div",{className:"min-w-0 flex-1 typography-micro text-muted-foreground",children:ze.state==="merged"?a("gitView.pr.history.merged",{number:ze.number,base:ze.base||Q}):a("gitView.pr.history.closed",{number:ze.number})}),s.jsx(at,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{co(ze.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(R,{name:"external-link",className:"size-3.5"})})]}):null,s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",Q," ",s.jsxs("span",{className:"opacity-60",children:["(",Se&&_e?"upstream":"remote",")"]})]})]}),Ps?s.jsx(at,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ps,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(R,{name:"external-link",className:"size-4"}),a("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.title")}),s.jsx(Nn,{value:T,onChange:q=>_(q.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:f?"on":"off",autoCapitalize:f?"sentences":"off",spellCheck:f})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.baseBranch")}),He.length>0?s.jsxs($s,{value:Q,onValueChange:me,children:[s.jsx(Ws,{size:"lg",children:s.jsx(Is,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(zs,{children:He.map(q=>s.jsx(ns,{value:q,children:q},q))})]}):s.jsx(Nn,{value:Q,onChange:q=>me(q.target.value),placeholder:a("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.description")}),s.jsx(ur,{value:O,onChange:q=>j(q.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:f?"on":"off",autoCapitalize:f?"sentences":"off",spellCheck:f})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>L(q=>!q),onKeyDown:q=>{(q.key===" "||q.key==="Enter")&&(q.preventDefault(),L(Ve=>!Ve))},children:[s.jsx(hr,{size:"sm",checked:E,onChange:q=>L(q),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),g?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx(at,{variant:"outline",size:"sm",onClick:()=>B(!0),children:U.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),U.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:a("gitView.pr.additionalContext.added")})})]}):s.jsxs(_i,{open:de,onOpenChange:he,children:[s.jsxs(Yd,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:de?a("gitView.pr.actions.hide"):U.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(Li,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(ur,{value:U,onChange:q=>X(q.target.value),className:"min-h-[100px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(ri,{open:fe,onClose:()=>B(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(at,{size:"sm",onClick:()=>B(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(ur,{value:U,onChange:q=>X(q.target.value),className:"min-h-[200px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(at,{variant:"outline",size:"sm",onClick:es,disabled:ee||W,children:[ee?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(at,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Ds,disabled:W||!Bs||!Q.trim()||!Se&&Q.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:W?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},gx=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:i,defaultBranch:o,headBranch:l}=t,a=typeof l=="string"?l.trim():"",d=b=>{if(!b)return"";let S=b.trim();if(!S||S==="HEAD")return"";if(n.includes(S))return S;S.startsWith("refs/heads/")&&(S=S.slice(11)),S.startsWith("heads/")&&(S=S.slice(6)),S.startsWith("remotes/")&&(S=S.slice(8));const v=S.indexOf("/");if(v>0){const g=S.slice(0,v);if(e.has(g)){const f=S.slice(v+1).trim();f&&(S=f)}}return S},u=b=>{const S=d(typeof b=="string"?b:"");return S&&S!==a?S:""},m=u(r);if(m)return m;const h=u(i);if(h)return h;const y=u(o);return y||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},BC=t=>{const{baseBranch:e,localBranches:n,remoteBranches:r}=t;return n.includes(e)?!0:r.some(i=>{const o=i.indexOf("/");return o>0&&i.slice(o+1)===e})},xi=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),uo=new Map,mo=new Map,Rn=t=>`${Cs()}::${t}`,bx=()=>{const t=Ye.c(86),{t:e}=ht(),{git:n}=Pn(),r=to(),i=ka(r??null),o=jd(r??null),{ensureAll:l}=$n(tr(xx)),a=qe(yx),d=qe(wx),u=qe(Sx),m=qe(vx);let h;t[0]!==r?(h=xi(r),t[0]=r,t[1]=h):h=t[1];const y=h;let b;if(t[2]!==m||t[3]!==y||t[4]!==u){e:{if(!y){b=void 0;break e}let ce;if(t[6]!==m||t[7]!==y){let be;t[9]!==y?(be=te=>xi(te.path)===y,t[9]=y,t[10]=be):be=t[10],ce=m.find(be),t[6]=m,t[7]=y,t[8]=ce}else ce=t[8];const ye=ce;if(ye){b=ye;break e}for(const be of u.values())if(xi(be.path)===y){b=be;break e}b=void 0}t[2]=m,t[3]=y,t[4]=u,t[5]=b}else b=t[5];const S=b;let v;t[11]!==a||t[12]!==S||t[13]!==d?.open||t[14]!==u?(v=()=>{if(a)return u.get(a)??S;if(d?.open)return S},t[11]=a,t[12]=S,t[13]=d?.open,t[14]=u,t[15]=v):v=t[15],d?.open;let g;t[16]!==v?(g=v(),t[16]=v,t[17]=g):g=t[17];const f=g;let x;t[18]!==a?(x=ce=>a?ce.getAttachment(a):void 0,t[18]=a,t[19]=x):x=t[19];const p=yd(x),w=p&&!p.degraded&&!p.legacy?p.worktreeRoot??void 0:void 0,N=Kb(r,f,i?.current??void 0);let C,k;t[20]!==r||t[21]!==l||t[22]!==n?(C=()=>{!r||!n||l(r,n)},k=[r,l,n],t[20]=r,t[21]=l,t[22]=n,t[23]=C,t[24]=k):(C=t[23],k=t[24]),c.useEffect(C,k);const[A,D]=c.useState(null);let P;t[25]!==w||t[26]!==N?.projectDirectory?(P=()=>{const ce=w||N?.projectDirectory;if(!ce){D(null);return}let ye=!1;return oi(ce).then(be=>{if(ye)return;const te=be.trim();D(te&&te!=="HEAD"?te:null)}).catch(()=>{ye||D(null)}),()=>{ye=!0}},t[25]=w,t[26]=N?.projectDirectory,t[27]=P):P=t[27];const M=N?.projectDirectory;let z;t[28]!==w||t[29]!==M?(z=[w,M],t[28]=w,t[29]=M,t[30]=z):z=t[30],c.useEffect(P,z);let I;t[31]!==r?(I=()=>(r?uo.get(Rn(r)):void 0)??[],t[31]=r,t[32]=I):I=t[32];const[V,T]=c.useState(I);let _;t[33]!==r?(_=()=>(r?mo.get(Rn(r)):void 0)??null,t[33]=r,t[34]=_):_=t[34];const[O,j]=c.useState(_);let E,L;t[35]!==r||t[36]!==n?(E=()=>{if(!r||!n?.getRemotes){T([]);return}T(uo.get(Rn(r))??[]);let ce=!1;return n.getRemotes(r).then(ye=>{ce||(uo.set(Rn(r),ye??[]),T(ye??[]))}).catch(()=>{ce||T(uo.get(Rn(r))??[])}),()=>{ce=!0}},L=[r,n],t[35]=r,t[36]=n,t[37]=E,t[38]=L):(E=t[37],L=t[38]),c.useEffect(E,L);let U,X;t[39]!==r||t[40]!==n?(U=()=>{if(!r||!n?.getRemoteUrl){j(null);return}j(mo.get(Rn(r))??null);let ce=!1;return n.getRemoteUrl(r).then(ye=>{ce||(mo.set(Rn(r),ye),j(ye))}).catch(()=>{ce||j(mo.get(Rn(r))??null)}),()=>{ce=!0}},X=[r,n],t[39]=r,t[40]=n,t[41]=U,t[42]=X):(U=t[41],X=t[42]),c.useEffect(U,X);let Q;e:{if(!o?.all){let ye;t[43]===Symbol.for("react.memo_cache_sentinel")?(ye=[],t[43]=ye):ye=t[43],Q=ye;break e}let ce;t[44]!==o.all?(ce=o.all.filter(jx).sort(),t[44]=o.all,t[45]=ce):ce=t[45],Q=ce}const me=Q;let re;e:{if(!o?.all){let ye;t[46]===Symbol.for("react.memo_cache_sentinel")?(ye=[],t[46]=ye):ye=t[46],re=ye;break e}let ce;t[47]!==o.all?(ce=o.all.filter(kx).map(Cx).sort(),t[47]=o.all,t[48]=ce):ce=t[48],re=ce}const G=re;let ee;t[49]!==G||t[50]!==O||t[51]!==V||t[52]!==i?.tracking?(ee=()=>{if(V.length>0)return V;const ce=new Set,ye=i?.tracking?.trim();ye&&ye.includes("/")&&ce.add(ye.split("/")[0]);for(const be of G){const te=be.indexOf("/");te>0&&ce.add(be.slice(0,te))}return ce.size===0&&O&&ce.add("origin"),Array.from(ce).map(be=>({name:be,fetchUrl:O??"",pushUrl:O??""}))},t[49]=G,t[50]=O,t[51]=V,t[52]=i?.tracking,t[53]=ee):ee=t[53],i?.tracking;let ue;t[54]!==ee?(ue=ee(),t[54]=ee,t[55]=ue):ue=t[55];const W=ue,ne=i?.current??null;i?.tracking;let Y;t[56]!==i?.tracking?(Y=i?.tracking?.trim().split("/")[0],t[56]=i?.tracking,t[57]=Y):Y=t[57];const F=Y,J=(F&&o?.defaultBranches?.[F])??o?.defaultBranches?.origin;let ie;t[58]!==ne||t[59]!==J||t[60]!==W||t[61]!==me||t[62]!==A||t[63]!==N?.createdFromBranch?(ie=()=>gx({remoteNames:new Set(W.map(Nx)),localBranches:me,worktreeCreatedFromBranch:N?.createdFromBranch,rootBranchHint:A,defaultBranch:J,headBranch:ne}),t[58]=ne,t[59]=J,t[60]=W,t[61]=me,t[62]=A,t[63]=N?.createdFromBranch,t[64]=ie):ie=t[64],N?.createdFromBranch;let xe;t[65]!==ie?(xe=ie(),t[65]=ie,t[66]=xe):xe=t[66];const ge=xe;if(!r||!ne){let ce;t[67]===Symbol.for("react.memo_cache_sentinel")?(ce=s.jsx(R,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=ce):ce=t[67];let ye;t[68]!==e?(ye=e("gitView.pullRequest.title"),t[68]=e,t[69]=ye):ye=t[69];let be;t[70]!==ye?(be=s.jsx("div",{className:"typography-ui-header text-foreground",children:ye}),t[70]=ye,t[71]=be):be=t[71];let te;t[72]!==e?(te=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=te):te=t[73];let pe;t[74]!==te?(pe=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:te}),t[74]=te,t[75]=pe):pe=t[75];let Pe;return t[76]!==be||t[77]!==pe?(Pe=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[ce,be,pe]}),t[76]=be,t[77]=pe,t[78]=Pe):Pe=t[78],Pe}const Ce=i?.tracking??void 0;let Re;return t[79]!==ge||t[80]!==ne||t[81]!==r||t[82]!==G||t[83]!==V||t[84]!==Ce?(Re=s.jsx(An,{as:Ca,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(px,{directory:r,branch:ne,baseBranch:ge,trackingBranch:Ce,remotes:V,remoteBranches:G})}),t[79]=ge,t[80]=ne,t[81]=r,t[82]=G,t[83]=V,t[84]=Ce,t[85]=Re):Re=t[85],Re};function xx(t){return{ensureAll:t.ensureAll}}function yx(t){return t.currentSessionId}function wx(t){return t.newSessionDraft}function Sx(t){return t.worktreeMetadata}function vx(t){return t.availableWorktrees}function jx(t){return!t.startsWith("remotes/")}function kx(t){return t.startsWith("remotes/")}function Cx(t){return t.replace(/^remotes\//,"")}function Nx(t){return t.name}const Xi=2e4,Ax=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},fo=(t,e)=>Df(Pf.getState().dictionary,t,e),Dx=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},Px=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const i=await rs(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!i.ok){const o=await i.json().catch(()=>({error:i.statusText}));throw new Error(o.error||"Failed to read file")}return i.text()},Eu=async(t,e,n)=>{if(kf(e)||Cf(e)||Nf(e))return{ok:!0};try{const r=await Px(t,e,n);return Af(r)?{ok:!1,reason:"binary"}:Ax(r,Xi)>Xi?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:Dx(r)}}},Ru=t=>{if(t==="too-large"){const e=Xi.toLocaleString(Sa());return fo("contextFileOpen.failure.tooLarge",{count:e})}return fo(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},Ul=8;let Ji=null;const Mu=t=>{Ji={x:t.clientX,y:t.clientY}},Ou=t=>{const e=Ji;return Ji=null,!e||t.dataTransfer&&t.dataTransfer.dropEffect!=="none"?!1:Math.abs(t.clientX-e.x)<=Ul&&Math.abs(t.clientY-e.y)<=Ul},Hl=3,pr=t=>Array.from(t.types).includes("Files"),Tx=t=>{const e=Array.from(t.items);return e.length===0?Array.from(t.files):e.flatMap(n=>{if(n.kind!=="file"||n.webkitGetAsEntry()?.isDirectory)return[];const r=n.getAsFile();return r?[r]:[]})},Kl=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},Ix=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),ds=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Wa=(t,e)=>{const n=ds(e),r=ds(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Ex=(t,e)=>{const n=Wa(t,e);if(n!==".")return n;const r=ds(t);return r.split("/").filter(Boolean).pop()??r},Rx=t=>{const e=ds(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},Mx=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ox=new Set(["node_modules"]),Bx=t=>Ox.has(t),Fx=t=>{const e=ds(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},_x=8,gn=new Map,za=t=>JSON.stringify([Cs(),t]),Lx=t=>{const e=za(t),n=gn.get(e);return n?(n.touchedAt=Date.now(),gn.delete(e),gn.set(e,n),n):null},yi=t=>{const e=za(t),n=gn.get(e);if(n)return n.touchedAt=Date.now(),n;if(gn.size>=_x){const i=gn.keys().next().value;i!==void 0&&gn.delete(i)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return gn.set(e,r),r},$x=t=>{gn.delete(za(t))},Bu=(t,e)=>s.jsx(Na,{filePath:t,extension:e}),Wx=t=>{const e=Ye.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const i=r[n];let o;return e[1]!==i?(o=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:i}}),e[1]=i,e[2]=o):o=e[2],o},zx=t=>{const e=Ye.c(87),{node:n,root:r,isExpanded:i,isActive:o,isBrowserClient:l,status:a,badge:d,isDropTarget:u,canUpload:m,permissions:h,downloadFile:y,onSelect:b,onToggle:S,onRevealPath:v,onOpenDialog:g,onSetDropTarget:f,onDropFiles:x}=t,{t:p}=ht(),w=n.type==="directory";let N;e[0]!==w||e[1]!==n.path?(N=w?n.path:Rx(n.path),e[0]=w,e[1]=n.path,e[2]=N):N=e[2];const C=N,{canRename:k,canCreateFile:A,canCreateFolder:D,canDelete:P,canReveal:M}=h,z=!w&&!!y,I=M&&!l,V=k||A||D||P||z||I,[T,_]=c.useState(!1),[O,j]=c.useState(!1);let E;e[3]!==V?(E=H=>{V&&(H?.preventDefault(),j(!0))},e[3]=V,e[4]=E):E=e[4];const L=E;let U;e[5]!==w||e[6]!==n||e[7]!==b||e[8]!==S?(U=()=>{w?S(n.path):b(n)},e[5]=w,e[6]=n,e[7]=b,e[8]=S,e[9]=U):U=e[9];const X=U;let Q;e[10]===Symbol.for("react.memo_cache_sentinel")?(Q=H=>{H.stopPropagation(),j(!1),_(!0)},e[10]=Q):Q=e[10];const me=Q;let re;e[11]!==A||e[12]!==D||e[13]!==P||e[14]!==k||e[15]!==I||e[16]!==y||e[17]!==l||e[18]!==w||e[19]!==n||e[20]!==g||e[21]!==v||e[22]!==p?(re=H=>{const{Item:ke,Separator:Se}=H;return s.jsxs(s.Fragment,{children:[k&&s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),g("rename",n)},children:[s.jsx(R,{name:"edit",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.rename")]}),s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),xn(n.path).then(_e=>{if(_e.ok){Oe.success(p("sidebarFilesTree.toast.pathCopied"));return}Oe.error(p("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(R,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.copyPath")]}),!w&&y&&s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),y(n.path).catch(_e=>{console.error("Download failed:",_e),Oe.error(p("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(R,{name:"download",className:"mr-2 h-4 w-4"})," ",p(l?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),I&&s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),v(n.path)},children:[s.jsx(R,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",p(hd())]}),w&&(A||D)&&s.jsxs(s.Fragment,{children:[s.jsx(Se,{}),A&&s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),g("createFile",n)},children:[s.jsx(R,{name:"file-add",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.newFile")]}),D&&s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),g("createFolder",n)},children:[s.jsx(R,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(Se,{}),s.jsxs(ke,{onClick:Be=>{Be.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",p("sidebarFilesTree.menu.delete")]})]})]})},e[11]=A,e[12]=D,e[13]=P,e[14]=k,e[15]=I,e[16]=y,e[17]=l,e[18]=w,e[19]=n,e[20]=g,e[21]=v,e[22]=p,e[23]=re):re=e[23];const G=re;let ee;e[24]!==n.path||e[25]!==r?(ee=H=>{Mu(H);const ke=Wa(r,n.path);!ke||ke==="."||(H.dataTransfer.setData("application/x-openchamber-file-path",ke),H.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=ee):ee=e[26];const ue=ee;let W;e[27]!==X?(W=H=>{Ou(H)&&X()},e[27]=X,e[28]=W):W=e[28];const ne=W;let Y;e[29]!==m||e[30]!==f||e[31]!==C?(Y=H=>{!m||!C||!pr(H.dataTransfer)||(H.preventDefault(),H.stopPropagation(),H.dataTransfer.dropEffect="copy",f(C))},e[29]=m,e[30]=f,e[31]=C,e[32]=Y):Y=e[32];const F=Y;let J;e[33]!==m||e[34]!==f||e[35]!==C?(J=H=>{!m||!C||!pr(H.dataTransfer)||H.relatedTarget instanceof Node&&H.currentTarget.contains(H.relatedTarget)||(H.stopPropagation(),f(null))},e[33]=m,e[34]=f,e[35]=C,e[36]=J):J=e[36];const ie=J;let xe;e[37]!==m||e[38]!==x||e[39]!==C?(xe=H=>{!m||!C||!pr(H.dataTransfer)||(H.preventDefault(),H.stopPropagation(),x(C,H.dataTransfer))},e[37]=m,e[38]=x,e[39]=C,e[40]=xe):xe=e[40];const ge=xe;let Ce;e[41]!==L||e[42]!==ie||e[43]!==F||e[44]!==ge?(Ce=s.jsx("div",{className:"group relative flex items-center",onContextMenu:L,onDragEnter:F,onDragOver:F,onDragLeave:ie,onDrop:ge}),e[41]=L,e[42]=ie,e[43]=F,e[44]=ge,e[45]=Ce):Ce=e[45];const Re=u?"bg-interactive-selection ring-2 ring-inset ring-primary":o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let ce;e[46]!==Re?(ce=Ie("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",Re),e[46]=Re,e[47]=ce):ce=e[47];let ye;e[48]!==w||e[49]!==i||e[50]!==n.extension||e[51]!==n.path?(ye=w?i?s.jsx(R,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Bu(n.path,n.extension),e[48]=w,e[49]=i,e[50]=n.extension,e[51]=n.path,e[52]=ye):ye=e[52];let be;e[53]!==n.name||e[54]!==n.path?(be=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[53]=n.name,e[54]=n.path,e[55]=be):be=e[55];let te;e[56]!==w||e[57]!==a?(te=!w&&a&&s.jsx(Wx,{status:a}),e[56]=w,e[57]=a,e[58]=te):te=e[58];let pe;e[59]!==d||e[60]!==w?(pe=w&&d&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[d.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",d.modified]}),d.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",d.added]})]}),e[59]=d,e[60]=w,e[61]=pe):pe=e[61];let Pe;e[62]!==L||e[63]!==ne||e[64]!==ue||e[65]!==X||e[66]!==ce||e[67]!==ye||e[68]!==be||e[69]!==te||e[70]!==pe?(Pe=s.jsxs("button",{type:"button",onClick:X,onContextMenu:L,draggable:!0,onDragStart:ue,onDragEnd:ne,className:ce,children:[ye,be,te,pe]}),e[62]=L,e[63]=ne,e[64]=ue,e[65]=X,e[66]=ce,e[67]=ye,e[68]=be,e[69]=te,e[70]=pe,e[71]=Pe):Pe=e[71];let de;e[72]!==T||e[73]!==V||e[74]!==G||e[75]!==p?(de=V&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(en,{open:T,onOpenChange:_,children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Js,{asChild:!0,children:s.jsx(at,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:me,title:p("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":p("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(R,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:p("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Zs,{align:"end",side:"bottom",onCloseAutoFocus:()=>_(!1),children:G({Item:Ut,Separator:Ls})})]})}),e[72]=T,e[73]=V,e[74]=G,e[75]=p,e[76]=de):de=e[76];let he;e[77]!==Ce||e[78]!==Pe||e[79]!==de?(he=s.jsxs(Jd,{render:Ce,children:[Pe,de]}),e[77]=Ce,e[78]=Pe,e[79]=de,e[80]=he):he=e[80];let fe;e[81]!==G?(fe=s.jsx(Xd,{className:"min-w-[180px]",children:G({Item:qn,Separator:$i})}),e[81]=G,e[82]=fe):fe=e[82];let B;return e[83]!==O||e[84]!==he||e[85]!==fe?(B=s.jsxs(Zd,{open:O,onOpenChange:j,children:[he,fe]}),e[83]=O,e[84]=he,e[85]=fe,e[86]=B):B=e[86],B},Vx=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.isDropTarget===e.isDropTarget&&t.canUpload===e.canUpload&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog&&t.onSetDropTarget===e.onSetDropTarget&&t.onDropFiles===e.onDropFiles,Ux=c.memo(zx,Vx),Hx=()=>{const{t}=ht(),{files:e,runtime:n}=Pn(),r=Om(n.platform),i=to()??"",o=ds(i.trim()),l=Bm(),a=Fm(),d=cd(K=>K.searchFiles),u=Ae(K=>K.openContextFile),m=ka(i),[h,y]=c.useState(""),b=Aa(h,200),S=c.useRef(null),[v,g]=c.useState([]),[f,x]=c.useState(!1),[p,w]=c.useState(null),[N,C]=c.useState(!1),[k,A]=c.useState(null),D=c.useRef(!1),P=c.useRef(o);P.current=o;const[M,z]=c.useState({}),[I,V]=c.useState({}),T=c.useRef(new Set),_=c.useRef(new Set),O=c.useRef(null);c.useEffect(()=>{if(w(null),A(null),!o){z({}),V({}),T.current=new Set;return}const K=Lx(o);K?(z({...K.childrenByDir}),V({...K.loadErrorsByDir}),T.current=new Set(K.loadedDirs)):(z({}),V({}),T.current=new Set)},[o]),c.useEffect(()=>{if(!o)return;const K=yi(o);K.childrenByDir=M},[o,M]),c.useEffect(()=>{if(!o)return;const K=yi(o);K.loadErrorsByDir=I},[o,I]),c.useEffect(()=>{if(!o)return;const K=yi(o);K.loadedDirs=new Set(T.current)},[o,M,I]),c.useEffect(()=>()=>{if(!o)return;const K=gn.get(o);K&&K.loadedDirs.size===0&&Object.keys(K.childrenByDir).length===0&&$x(o)},[o]);const j=c.useMemo(()=>[],[]),E=c.useMemo(()=>[],[]),L=pn(K=>o?K.byRoot[o]?.expandedPaths??j:j),U=pn(K=>o?K.byRoot[o]?.selectedPath??null:null),X=pn(K=>K.setSelectedPath),Q=pn(K=>K.addOpenPath),me=pn(K=>K.removeOpenPathsByPrefix),re=pn(K=>K.toggleExpandedPath),G=pn(K=>K.collapseAllExpandedPaths),ee=Ae(K=>o?K.contextPanelByDirectory[o]?.tabs??E:E),ue=c.useMemo(()=>new Set(ee.map(K=>K.mode==="file"?K.targetPath:null).filter(K=>typeof K=="string"&&K.length>0).map(K=>ds(K))),[ee]),[W,ne]=c.useState(null),[Y,F]=c.useState(null),[J,ie]=c.useState(""),[xe,ge]=c.useState(!1),Ce=!!e.writeFile,Re=!!e.createDirectory,ce=!!e.rename,ye=!!e.delete,be=!!e.revealPath,te=!!e.uploadFile,pe=c.useMemo(()=>({canRename:ce,canCreateFile:Ce,canCreateFolder:Re,canDelete:ye,canReveal:be}),[ce,Ce,Re,ye,be]),Pe=c.useCallback(K=>{e.revealPath&&e.revealPath(K).catch(()=>{Oe.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),de=c.useCallback((K,ve)=>{ne(K),F(ve),ie(K==="rename"&&ve.name||""),ge(!1)},[]),he=c.useCallback((K,ve)=>{const $e=ve.filter(We=>We&&typeof We.name=="string"&&We.name.length>0).filter(We=>l||!We.name.startsWith(".")).filter(We=>a||!Bx(We.name)).map(We=>{const Le=We.name,Fe=ds(We.path||""),Ge=Fe?Mx(Fe)?Fe:ds(`${K}/${Fe}`):ds(`${K}/${Le}`),rt=We.isDirectory?"directory":"file",St=rt==="file"&&Le.includes(".")?Le.split(".").pop()?.toLowerCase():void 0;return{name:Le,path:Ge,type:rt,extension:St}});return Ix($e)},[a,l]),fe=c.useCallback(async(K,ve)=>{const $e=ds(K.trim());if(!$e||T.current.has($e)||_.current.has($e))return;_.current=new Set(_.current),_.current.add($e);const We=e.listDirectory?e.listDirectory($e).then(Le=>Le.entries.map(Fe=>({name:Fe.name,path:Fe.path,isDirectory:Fe.isDirectory}))):_s.listLocalDirectory($e).then(Le=>Le.map(Fe=>({name:Fe.name,path:Fe.path,isDirectory:Fe.isDirectory})));try{const Le=await We;if(ve?.())return;const Fe=he($e,Le);T.current=new Set(T.current),T.current.add($e),V(Ge=>{if(!Ge[$e])return Ge;const rt={...Ge};return delete rt[$e],rt}),z(Ge=>({...Ge,[$e]:Fe}))}catch(Le){if(ve?.())return;const Fe=Le instanceof Error?Le.message:String(Le??"");console.error("Failed to load sidebar directory:",Le),V(Ge=>({...Ge,[$e]:Fe}))}finally{_.current=new Set(_.current),_.current.delete($e)}},[e,he]),B=c.useCallback(async()=>{if(!o)return;O.current?.abort();const K=new AbortController;O.current=K;try{const $e=(pn.getState().byRoot[o]?.expandedPaths??[]).map(Fe=>ds(Fe)).filter(Fe=>!!Fe&&Fe!==o&&Fe.startsWith(`${o}/`)),We=[o,...$e];T.current=new Set(T.current);for(const Fe of We)T.current.delete(Fe);V(Fe=>{if(Object.keys(Fe).length===0)return Fe;const Ge={...Fe};let rt=!1;for(const St of We)St in Ge&&(delete Ge[St],rt=!0);return rt?Ge:Fe});const Le=()=>K.signal.aborted;await fe(o,Le);for(let Fe=0;Fe<$e.length&&!K.signal.aborted;Fe+=3){const Ge=$e.slice(Fe,Fe+3);await Promise.all(Ge.map(rt=>fe(rt,Le)))}}catch(ve){if(K.signal.aborted)return;console.error("Failed to refresh sidebar tree:",ve)}finally{O.current===K&&(O.current=null)}},[fe,o]),H=c.useCallback(async K=>{if(!K){await B();return}const ve=ds(K);T.current=new Set(T.current),T.current.delete(ve),_.current=new Set(_.current),_.current.delete(ve),await fe(ve)},[fe,B]);c.useEffect(()=>{o&&(O.current?.abort(),T.current=new Set,_.current=new Set,V({}),z(K=>Object.keys(K).length===0?K:{}),fe(o))},[fe,o,l,a]),c.useEffect(()=>{if(!o||L.length===0)return;const K=L.map(We=>ds(We)).filter(We=>!!We&&We!==o&&We.startsWith(`${o}/`)&&!T.current.has(We)&&!_.current.has(We)).sort((We,Le)=>We.split("/").length-Le.split("/").length);if(K.length===0)return;let ve=!1;const $e=()=>ve;return(async()=>{for(let We=0;We<K.length&&!ve;We+=3){const Le=K.slice(We,We+3);await Promise.all(Le.map(Fe=>fe(Fe,$e)))}})(),()=>{ve=!0}},[L,fe,o]),c.useEffect(()=>{if(!i){g([]),x(!1);return}const K=b.trim();if(!K){g([]),x(!1);return}let ve=!1;return x(!0),d(i,K,150,{includeHidden:l,respectGitignore:!a,type:"file"}).then($e=>{if(ve)return;const Le=$e.filter(Fe=>a||!Fx(Fe.path)).map(Fe=>({name:Fe.name,path:ds(Fe.path),type:"file",extension:Fe.extension,relativePath:Fe.relativePath}));g(Le)}).catch(()=>{ve||g([])}).finally(()=>{ve||x(!1)}),()=>{ve=!0}},[i,b,d,l,a]);const ke=c.useMemo(()=>{const K=new Map;if(!m?.files)return K;for(const ve of m.files)ve.index==="A"||ve.working_dir==="?"?K.set(ve.path,"git-added"):ve.index==="D"?K.set(ve.path,"git-deleted"):(ve.index==="M"||ve.working_dir==="M")&&K.set(ve.path,"git-modified");return K},[m]),Se=c.useMemo(()=>{const K=new Map;if(!m?.files||!o)return K;for(const ve of m.files){const $e=ve.index==="M"||ve.working_dir==="M",We=ve.index==="A"||ve.working_dir==="?";if(!$e&&!We)continue;const Le=ve.path.split("/");if(Le.length<=1)continue;let Fe=o;for(let Ge=0;Ge<Le.length-1;Ge++){Fe=`${Fe}/${Le[Ge]}`;let rt=K.get(Fe);rt||(rt={modified:0,added:0},K.set(Fe,rt)),$e&&rt.modified++,We&&rt.added++}}return K},[m,o]),Be=c.useCallback(K=>{if(ue.has(K))return"open";if(ke.size===0)return null;const ve=K.startsWith(o+"/")?K.slice(o.length+1):K;return ke.get(ve)??null},[ue,ke,o]),_e=c.useCallback(K=>{if(Se.size===0)return null;const ve=Se.get(K);return ve&&ve.modified+ve.added>0?ve:null},[Se]),Te=c.useCallback(async K=>{if(!o)return;const ve=await Eu(e,K.path,{directory:o});if(!ve.ok){Oe.error(Ru(ve.reason));return}X(o,K.path),Q(o,K.path),u(o,K.path)},[Q,e,u,o,X]),Z=c.useCallback(async K=>{const ve=ds(K);o&&(re(o,ve),T.current.has(ve)||await fe(ve))},[fe,o,re]),Ne=c.useCallback(async(K,ve,$e=!1)=>{const We=e.uploadFile;if(!We||ve.length===0||D.current||!o)return;const Le=o,Fe=Cs();D.current=!0,C(!0),w(K),$e&&A(null);const Ge=[];for(let Nt=0;Nt<ve.length;Nt+=Hl){const Tt=ve.slice(Nt,Nt+Hl),Et=await Promise.all(Tt.map(async vt=>{const Ct=Kl(vt);if(!Ct||Cs()!==Fe)return"failed";try{return(await We(ds(`${K}/${Ct}`),vt,{directory:Le,overwrite:$e})).success?"uploaded":"failed"}catch(It){return!$e&&_m(It)&&It.reason==="already-exists"?"conflict":"failed"}}));Ge.push(...Et)}const rt=Ge.filter(Nt=>Nt==="uploaded").length,St=Ge.filter(Nt=>Nt==="failed").length,Rt=ve.filter((Nt,Tt)=>Ge[Tt]==="conflict"),ze=ve.flatMap((Nt,Tt)=>{const Et=Kl(Nt);return Ge[Tt]==="uploaded"&&Et?[ds(`${K}/${Et}`)]:[]}),Pt=P.current===Le&&Cs()===Fe;try{ze.length>0&&Zp({runtimeKey:Fe,paths:ze}),rt>0&&Pt&&await H(K),rt>0&&Oe.success(t(Rt.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),St>0&&Oe.error(t("sidebarFilesTree.toast.uploadFailed")),Rt.length>0&&Pt&&A({directory:K,files:Rt,runtimeKey:Fe,workspaceRoot:Le})}finally{D.current=!1,C(!1),w(null)}},[e.uploadFile,H,o,t]),Me=c.useCallback((K,ve)=>{const $e=Tx(ve);$e.length!==0&&Ne(K,$e)},[Ne]),$=c.useCallback(K=>{!te||D.current||!o||!pr(K.dataTransfer)||(K.preventDefault(),K.dataTransfer.dropEffect="copy",w(o))},[te,o]),ae=c.useCallback(K=>{pr(K.dataTransfer)&&(K.relatedTarget instanceof Node&&K.currentTarget.contains(K.relatedTarget)||w(null))},[]),se=c.useCallback(K=>{!te||D.current||!o||!pr(K.dataTransfer)||(K.preventDefault(),Me(o,K.dataTransfer))},[te,Me,o]),we=c.useCallback(async K=>{if(K?.preventDefault(),!Y||!W)return;ge(!0);const ve=()=>ge(!1),$e=()=>ne(null);if(W==="createFile"){if(!J.trim()){Oe.error(t("sidebarFilesTree.toast.filenameRequired")),ve();return}if(!e.writeFile){Oe.error(t("sidebarFilesTree.toast.writeNotSupported")),ve();return}const We=Y.path,Le=We?`${We}/`:"",Fe=ds(`${Le}${J.trim()}`);await e.writeFile(Fe,"").then(async Ge=>{Ge.success&&(Oe.success(t("sidebarFilesTree.toast.fileCreated")),await H(We)),$e()}).catch(()=>Oe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(W==="createFolder"){if(!J.trim()){Oe.error(t("sidebarFilesTree.toast.folderNameRequired")),ve();return}const We=Y.path,Le=We?`${We}/`:"",Fe=ds(`${Le}${J.trim()}`);await e.createDirectory(Fe).then(async Ge=>{Ge.success&&(Oe.success(t("sidebarFilesTree.toast.folderCreated")),await H(We)),$e()}).catch(()=>Oe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(W==="rename"){if(!J.trim()){Oe.error(t("sidebarFilesTree.toast.nameRequired")),ve();return}if(!e.rename){Oe.error(t("sidebarFilesTree.toast.renameNotSupported")),ve();return}const We=Y.path,Le=We.split("/").slice(0,-1).join("/"),Fe=Le?`${Le}/`:"",Ge=ds(`${Fe}${J.trim()}`);await e.rename(We,Ge).then(async rt=>{rt.success&&(Oe.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await H(Le),o&&me(o,We),(U===We||U&&U.startsWith(`${We}/`))&&X(o,null)),$e()}).catch(()=>Oe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}if(W==="delete"){if(!e.delete){Oe.error(t("sidebarFilesTree.toast.deleteNotSupported")),ve();return}const We=Y.path,Le=We.split("/").slice(0,-1).join("/");await e.delete(We).then(async Fe=>{Fe.success&&(Oe.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await H(Le),o&&me(o,We),(U===We||U&&U.startsWith(We+"/"))&&X(o,null)),$e()}).catch(()=>Oe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ve);return}ve()},[W,Y,J,e,H,me,o,U,X,t]);function Ke(K,ve){const $e=M[K]??[];return $e.map((We,Le)=>{const Fe=We.type==="directory",Ge=Fe&&L.includes(We.path),rt=U===We.path,St=Le===$e.length-1;return s.jsxs("li",{className:"relative",children:[ve>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),St&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Ux,{node:We,root:o,isExpanded:Ge,isActive:rt,isBrowserClient:r,status:Fe?void 0:Be(We.path),badge:Fe?_e(We.path):void 0,isDropTarget:Fe&&p===We.path,canUpload:te&&!N,permissions:pe,downloadFile:e.downloadFile,onSelect:Te,onToggle:Z,onRevealPath:Pe,onOpenDialog:de,onSetDropTarget:w,onDropFiles:Me}),Fe&&Ge&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[I[We.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:I[We.path],children:I[We.path]}),s.jsxs(at,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{H(We.path)},children:[s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,Ke(We.path,ve+1)]})]},We.path)})}const Qe=!!(o&&M[o]),He=o?I[o]:null,le=p?Ex(o,p):"";return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Ce&&s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>de("createFile",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(R,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Re&&s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>de("createFolder",{path:i,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(R,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>{B()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(R,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(at,{variant:"ghost",size:"sm",onClick:()=>{o&&G(o)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(R,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(xt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Nn,{ref:S,value:h,onChange:K=>y(K.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),h.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{y(""),S.current?.focus()},children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsxs("div",{className:"relative flex-1 min-h-0",children:[s.jsx(An,{outerClassName:"h-full min-h-0",className:Ie("p-2",p===o&&"bg-interactive-selection/10"),onDragEnter:$,onDragOver:$,onDragLeave:ae,onDrop:se,children:s.jsx("ul",{className:"flex flex-col",children:f?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):v.length>0?v.map(K=>{const ve=U===K.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Te(K),draggable:!0,onDragStart:$e=>{Mu($e);const We=K.relativePath||Wa(o??"",K.path);!We||We==="."||($e.dataTransfer.setData("application/x-openchamber-file-path",We),$e.dataTransfer.effectAllowed="copy")},onDragEnd:$e=>{Ou($e)&&Te(K)},className:Ie("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",ve?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:K.path,children:[Bu(K.path,K.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:K.relativePath??K.path})]})},K.path)}):He?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:He}),s.jsxs(at,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{B()},children:[s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):Qe&&o?Ke(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),p?s.jsxs("div",{className:"pointer-events-none absolute left-2 right-2 top-2 z-50 flex items-center gap-2 rounded-md border border-primary bg-background/95 px-2 py-1.5 shadow-sm",children:[s.jsx(R,{name:N?"loader-4":"folder-received",className:Ie("size-4 flex-shrink-0",N&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:le,children:t(N?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:le})})]}):null]}),s.jsx(Ns,{open:!!k,onOpenChange:K=>!K&&A(null),children:s.jsxs(As,{children:[s.jsxs(Hs,{children:[s.jsx(Rs,{children:t("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(Ms,{children:t("sidebarFilesTree.dialog.uploadConflicts.description",{path:k?.directory??""})})]}),s.jsx(An,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:k?.files.map((K,ve)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:K.name,children:K.name},`${K.name}-${K.size}-${ve}`))}),s.jsxs(Sn,{children:[s.jsx(at,{variant:"outline",onClick:()=>A(null),disabled:N,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(at,{onClick:()=>{if(k){if(k.runtimeKey!==Cs()||k.workspaceRoot!==o){A(null);return}Ne(k.directory,k.files,!0)}},disabled:N,children:t("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx(Ns,{open:!!W,onOpenChange:K=>!K&&ne(null),children:s.jsxs(As,{children:[s.jsxs(Hs,{children:[s.jsxs(Rs,{children:[W==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),W==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),W==="rename"&&t("sidebarFilesTree.dialog.rename.title"),W==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Ms,{children:[W==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:Y?.path??t("sidebarFilesTree.dialog.rootFallback")}),W==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:Y?.path??t("sidebarFilesTree.dialog.rootFallback")}),W==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:Y?.name??""}),W==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:Y?.name??""})]})]}),W!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Nn,{value:J,onChange:K=>ie(K.target.value),placeholder:t(W==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:K=>{K.key==="Enter"&&we()},autoFocus:!0})}),s.jsxs(Sn,{children:[s.jsx(at,{variant:"outline",onClick:()=>ne(null),disabled:xe,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(at,{variant:W==="delete"?"destructive":"default",onClick:()=>{we()},disabled:xe||W!=="delete"&&!J.trim(),children:xe?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):t(W==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},Gl=60,Kx=t=>{try{return new URL(t).origin}catch{return""}},wi=new Set,Fu=or()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const i=Kx(n);!i||!r||e().byOrigin[i]||wi.has(i)||(wi.add(i),Fr("desktop_browser_fetch_favicon",{url:r}).then(o=>{const l=typeof o?.dataUrl=="string"?o.dataUrl:"";l&&t(a=>{const d={...a.byOrigin,[i]:l},u=Object.keys(d);if(u.length<=Gl)return{byOrigin:d};for(const m of u.slice(0,u.length-Gl))delete d[m];return{byOrigin:d}})}).catch(()=>{}).finally(()=>{wi.delete(i)}))}})),Va=t=>t,Zi=t=>{const e=Va(t).type;return typeof e=="string"?e:""},Gx=t=>{const e=Va(t).tool;return typeof e=="string"?e:""},qx=t=>{const e=Va(t).text;return typeof e=="string"?e:""},Qx=t=>{const e=Zi(t);return e==="tool"?Gx(t).trim().toLowerCase()||"tool":e||"unknown"},Yx=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Qx(n);e.includes(r)||e.push(r)}return e.join(" + ")},Xx=t=>t.replace(/\s+/g," ").trim(),Jx=t=>{for(const n of t)if(Zi(n)==="text"){const r=Xx(qx(n));if(r.length===0)continue;return r}const e=t.filter(n=>Zi(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},Zx=(t,e,n)=>`${n(t)} / ${n(e)}`,ey=t=>{if(t==="12h")return!0;if(t==="24h")return!1},ty=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=ey(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},ea={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Ao={user:0,assistant:0,tool:0,other:0},Bn=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Si=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(m=>m.tokens!==void 0)?.tokens;if(typeof n=="number")return{...ea,total:Bn(n)};if(!n||typeof n!="object")return ea;const r=n,i=Bn(r.input),o=Bn(r.output),l=Bn(r.reasoning),a=Bn(r.cache?.read),d=Bn(r.cache?.write),u=Bn(r.total);return{input:i,output:o,reasoning:l,cacheRead:a,cacheWrite:d,total:u>0?u:i+o+l+a+d}},sy=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Qs=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Qs(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Qs(n),0):0,ny=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Ao,assistant:Qs(n.text)+Qs(n.content)};const i=sy(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Qs(n.input)+Qs(n.output)+Qs(n.error)+Qs(n.call?.input)+Qs(n.call?.output)+Qs(n.call?.error)+Qs(n.raw)+Math.round(Qs(n.metadata)*.25)+Math.round(Qs(n.state)*.1),other:0}:e==="user"?{user:i.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:i.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:i.length}},ql=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),ry=t=>{const e=so(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},oy=(t,e)=>{if(t.length===0)return{...Ao};const n=t.reduce((r,i)=>{const o=ry(i);let l={...Ao};for(const a of i.parts)l=ql(l,ny(a,o));return ql(r,l)},{...Ao});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Gn=t=>t.toLocaleString(Sa()),iy=(t,e)=>!t||!Number.isFinite(t)?"-":vd(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),ay=(t,e,n)=>{const r=t.find(o=>o.id===e),i=r?.models?.find(o=>o.id===n);return{providerName:r?.name||e||"-",modelName:i?.name||n||"-",contextLimit:typeof i?.limit?.context=="number"?i.limit.context:null}},ly=()=>{const t=Ye.c(203),{t:e}=ht(),n=Ae(cy);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[i,o]=c.useState(r),[l,a]=c.useState(null),d=c.useRef(null),u=qe(dy),m=qe(uy),h=kd(m??void 0),y=Tf(u??"",m??void 0),b=Kt(my);let S;t[1]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),o(fy),a(null)},t[1]=S):S=t[1];let v;t[2]!==m||t[3]!==u?(v=[m,u],t[2]=m,t[3]=u,t[4]=v):v=t[4],c.useEffect(S,v);let g,f;t[5]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},f=[],t[5]=g,t[6]=f):(g=t[5],f=t[6]),c.useEffect(g,f);let x;t[7]===Symbol.for("react.memo_cache_sentinel")?(x=async(mt,Ze)=>{(await xn(Ze)).ok?(a(mt),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{a(ot=>ot===mt?null:ot),d.current=null},2e3)):a(null)},t[7]=x):x=t[7];const p=x;let w;t[8]!==u||t[9]!==h?(w=u?h.find(mt=>mt.id===u)??null:null,t[8]=u,t[9]=h,t[10]=w):w=t[10];const N=w;let C,k,A,D,P,M;if(t[11]!==b||t[12]!==y){C=y.filter(hy);let mt;t[19]!==y?(mt=y.filter(py),t[19]=y,t[20]=mt):mt=t[20],M=mt;let Ze=null;for(let ot=C.length-1;ot>=0;ot=ot-1,ot){const ct=C[ot];if(Si(ct).total>0){Ze=ct;break}}D=Ze?Si(Ze):ea,k=If({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),P=C.reduce(gy,0);const je=Ze?.info??null;A=ay(b,je?.providerID||"",je?.modelID||""),t[11]=b,t[12]=y,t[13]=C,t[14]=k,t[15]=A,t[16]=D,t[17]=P,t[18]=M}else C=t[13],k=t[14],A=t[15],D=t[16],P=t[17],M=t[18];const z=A,I=z.contextLimit,V=I&&I>0?Math.min(999,D.total/I*100):0;let T;if(t[21]!==y){const mt=[...y].reverse().find(by)?.info?.system||"";T=oy(y,mt),t[21]=y,t[22]=T}else T=t[22];const _=T,O=_.user,j=_.assistant,E=_.tool,L=Math.max(0,D.input-O-j-E),U=O+j+E+L,X=y[0]?.info?.time?.created,Q=y.length>0?y[y.length-1]?.info?.time?.created:null;let me;t[23]!==N?.title||t[24]!==e?(me=N?.title||e("contextSidebar.session.untitled"),t[23]=N?.title,t[24]=e,t[25]=me):me=t[25];const re=N?.time?.created??X??null,G=Q??N?.time?.created??null;let ee;t[26]!==j||t[27]!==L||t[28]!==E||t[29]!==O?(ee={user:O,assistant:j,tool:E,other:L},t[26]=j,t[27]=L,t[28]=E,t[29]=O,t[30]=ee):ee=t[30];let ue;t[31]!==C.length||t[32]!==U||t[33]!==k||t[34]!==I||t[35]!==z||t[36]!==y.length||t[37]!==re||t[38]!==G||t[39]!==ee||t[40]!==me||t[41]!==D||t[42]!==P||t[43]!==V||t[44]!==M.length?(ue={sessionTitle:me,messagesCount:y.length,userMessagesCount:M.length,assistantMessagesCount:C.length,createdAt:re,lastActivityAt:G,providerModel:z,tokenBreakdown:D,usagePercent:V,cacheHitRate:k,totalAssistantCost:P,contextLimit:I,breakdown:ee,breakdownTotal:U},t[31]=C.length,t[32]=U,t[33]=k,t[34]=I,t[35]=z,t[36]=y.length,t[37]=re,t[38]=G,t[39]=ee,t[40]=me,t[41]=D,t[42]=P,t[43]=V,t[44]=M.length,t[45]=ue):ue=t[45];const W=ue;if(!u){let mt;t[46]!==e?(mt=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=mt):mt=t[47];let Ze;return t[48]!==mt?(Ze=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:mt}),t[48]=mt,t[49]=Ze):Ze=t[49],Ze}let ne;t[50]!==e?(ne=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=ne):ne=t[51];let Y;t[52]!==ne||t[53]!==W.breakdown.user?(Y={key:"user",label:ne,value:W.breakdown.user,color:"var(--status-success)"},t[52]=ne,t[53]=W.breakdown.user,t[54]=Y):Y=t[54];let F;t[55]!==e?(F=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=F):F=t[56];let J;t[57]!==F||t[58]!==W.breakdown.assistant?(J={key:"assistant",label:F,value:W.breakdown.assistant,color:"var(--primary-base)"},t[57]=F,t[58]=W.breakdown.assistant,t[59]=J):J=t[59];let ie;t[60]!==e?(ie=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ie):ie=t[61];let xe;t[62]!==ie||t[63]!==W.breakdown.tool?(xe={key:"tool",label:ie,value:W.breakdown.tool,color:"var(--status-warning)"},t[62]=ie,t[63]=W.breakdown.tool,t[64]=xe):xe=t[64];let ge;t[65]!==e?(ge=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=ge):ge=t[66];let Ce;t[67]!==ge||t[68]!==W.breakdown.other?(Ce={key:"other",label:ge,value:W.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=ge,t[68]=W.breakdown.other,t[69]=Ce):Ce=t[69];let Re;t[70]!==Y||t[71]!==J||t[72]!==xe||t[73]!==Ce?(Re=[Y,J,xe,Ce],t[70]=Y,t[71]=J,t[72]=xe,t[73]=Ce,t[74]=Re):Re=t[74];const ce=Re;let ye;t[75]!==W.sessionTitle?(ye=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:W.sessionTitle}),t[75]=W.sessionTitle,t[76]=ye):ye=t[76];let be;t[77]!==W.providerModel.modelName||t[78]!==W.providerModel.providerName?(be=s.jsxs("span",{children:[W.providerModel.providerName," / ",W.providerModel.modelName]}),t[77]=W.providerModel.modelName,t[78]=W.providerModel.providerName,t[79]=be):be=t[79];let te;t[80]!==n||t[81]!==W.createdAt?(te=W.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:iy(W.createdAt,n)})]}),t[80]=n,t[81]=W.createdAt,t[82]=te):te=t[82];let pe;t[83]!==be||t[84]!==te?(pe=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[be,te]}),t[83]=be,t[84]=te,t[85]=pe):pe=t[85];let Pe;t[86]!==ye||t[87]!==pe?(Pe=s.jsxs("div",{className:"mb-6",children:[ye,pe]}),t[86]=ye,t[87]=pe,t[88]=Pe):Pe=t[88];let de;t[89]!==e?(de=e("contextSidebar.section.context"),t[89]=e,t[90]=de):de=t[90];let he;t[91]!==de?(he=s.jsx("span",{className:"typography-micro text-muted-foreground",children:de}),t[91]=de,t[92]=he):he=t[92];let fe;t[93]!==W.tokenBreakdown.total?(fe=Gn(W.tokenBreakdown.total),t[93]=W.tokenBreakdown.total,t[94]=fe):fe=t[94];let B;t[95]!==W.contextLimit?(B=W.contextLimit?` / ${Gn(W.contextLimit)}`:"",t[95]=W.contextLimit,t[96]=B):B=t[96];let H;t[97]!==fe||t[98]!==B?(H=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[fe,B]}),t[97]=fe,t[98]=B,t[99]=H):H=t[99];let ke;t[100]!==he||t[101]!==H?(ke=s.jsxs("div",{className:"flex items-baseline justify-between",children:[he,H]}),t[100]=he,t[101]=H,t[102]=ke):ke=t[102];let Se;t[103]!==W.usagePercent?(Se=W.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=W.usagePercent,t[104]=Se):Se=t[104];let Be;t[105]!==Se?(Be=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Se}),t[105]=Se,t[106]=Be):Be=t[106];let _e;t[107]!==e||t[108]!==W.usagePercent?(_e=e("contextSidebar.context.percentUsed",{percent:W.usagePercent.toFixed(1)}),t[107]=e,t[108]=W.usagePercent,t[109]=_e):_e=t[109];let Te;t[110]!==_e?(Te=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:_e}),t[110]=_e,t[111]=Te):Te=t[111];let Z;t[112]!==ke||t[113]!==Be||t[114]!==Te?(Z=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ke,Be,Te]}),t[112]=ke,t[113]=Be,t[114]=Te,t[115]=Z):Z=t[115];let Ne;t[116]!==e?(Ne=e("contextSidebar.stats.messages"),t[116]=e,t[117]=Ne):Ne=t[117];let Me;t[118]!==W.messagesCount?(Me=Gn(W.messagesCount),t[118]=W.messagesCount,t[119]=Me):Me=t[119];let $;t[120]!==Ne||t[121]!==Me?($={label:Ne,value:Me},t[120]=Ne,t[121]=Me,t[122]=$):$=t[122];let ae;t[123]!==e?(ae=e("contextSidebar.stats.user"),t[123]=e,t[124]=ae):ae=t[124];let se;t[125]!==W.userMessagesCount?(se=Gn(W.userMessagesCount),t[125]=W.userMessagesCount,t[126]=se):se=t[126];let we;t[127]!==ae||t[128]!==se?(we={label:ae,value:se},t[127]=ae,t[128]=se,t[129]=we):we=t[129];let Ke;t[130]!==e?(Ke=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Ke):Ke=t[131];let Qe;t[132]!==W.assistantMessagesCount?(Qe=Gn(W.assistantMessagesCount),t[132]=W.assistantMessagesCount,t[133]=Qe):Qe=t[133];let He;t[134]!==Ke||t[135]!==Qe?(He={label:Ke,value:Qe},t[134]=Ke,t[135]=Qe,t[136]=He):He=t[136];let le;t[137]!==e?(le=e("contextSidebar.stats.cost"),t[137]=e,t[138]=le):le=t[138];let K;t[139]!==W.totalAssistantCost?(K=Ap(W.totalAssistantCost),t[139]=W.totalAssistantCost,t[140]=K):K=t[140];let ve;t[141]!==le||t[142]!==K?(ve={label:le,value:K},t[141]=le,t[142]=K,t[143]=ve):ve=t[143];let $e;t[144]!==$||t[145]!==we||t[146]!==He||t[147]!==ve?($e=[$,we,He,ve],t[144]=$,t[145]=we,t[146]=He,t[147]=ve,t[148]=$e):$e=t[148];const We=$e;let Le;t[149]!==We?(Le=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:We.map(xy)}),t[149]=We,t[150]=Le):Le=t[150];let Fe;t[151]!==e?(Fe=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=Fe):Fe=t[152];let Ge;t[153]!==Fe?(Ge=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:Fe}),t[153]=Fe,t[154]=Ge):Ge=t[154];let rt;t[155]!==e||t[156]!==W.cacheHitRate.hasInput||t[157]!==W.cacheHitRate.percent||t[158]!==W.tokenBreakdown.cacheRead||t[159]!==W.tokenBreakdown.cacheWrite||t[160]!==W.tokenBreakdown.input||t[161]!==W.tokenBreakdown.output||t[162]!==W.tokenBreakdown.reasoning?(rt=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:W.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:W.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:W.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:W.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:W.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:W.cacheHitRate.hasInput?W.cacheHitRate.percent:null,format:"percent"}].map(yy)}),t[155]=e,t[156]=W.cacheHitRate.hasInput,t[157]=W.cacheHitRate.percent,t[158]=W.tokenBreakdown.cacheRead,t[159]=W.tokenBreakdown.cacheWrite,t[160]=W.tokenBreakdown.input,t[161]=W.tokenBreakdown.output,t[162]=W.tokenBreakdown.reasoning,t[163]=rt):rt=t[163];let St;t[164]!==Ge||t[165]!==rt?(St=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ge,rt]}),t[164]=Ge,t[165]=rt,t[166]=St):St=t[166];let Rt;t[167]!==ce||t[168]!==W.breakdownTotal?(Rt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ce.map(mt=>mt.value<=0||W.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${mt.value/W.breakdownTotal*100}%`,backgroundColor:mt.color}},mt.key))}),t[167]=ce,t[168]=W.breakdownTotal,t[169]=Rt):Rt=t[169];let ze;t[170]!==ce||t[171]!==W.breakdownTotal?(ze=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ce.map(mt=>{const Ze=W.breakdownTotal>0?mt.value/W.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:mt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[mt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Ze.toFixed(0),"%"]})]})]},mt.key)})}),t[170]=ce,t[171]=W.breakdownTotal,t[172]=ze):ze=t[172];let Pt;t[173]!==Rt||t[174]!==ze?(Pt=s.jsxs("div",{className:"mb-6",children:[Rt,ze]}),t[173]=Rt,t[174]=ze,t[175]=Pt):Pt=t[175];let Nt;t[176]!==e?(Nt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=Nt):Nt=t[177];let Tt;t[178]!==Nt?(Tt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Nt}),t[178]=Nt,t[179]=Tt):Tt=t[179];let Et;if(t[180]!==l||t[181]!==i||t[182]!==y||t[183]!==e||t[184]!==n){let mt;t[186]!==l||t[187]!==i||t[188]!==e||t[189]!==n?(mt=Ze=>{const ot=so(Ze.info).role,ct=ot==="assistant",Mt=ot==="user",Je=i[Ze.info.id]===!0,nt=l===Ze.info.id,jt=Ze.info.time?.created??null,At=Yx(Ze.parts),Ot=ct?Si({info:Ze.info,parts:Ze.parts}):null,$t=Mt?Jx(Ze.parts):"",Zt=ty(jt,n),Gt=At||"—",Ft=Ot?Zx(Ot.input,Ot.output,Gn):"",qt=ot||"unknown",Xt=At?`${qt}: ${At}`:qt,zt=Je?JSON.stringify({info:Ze.info,parts:Ze.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Je,onClick:()=>{o(Ee=>({...Ee,[Ze.info.id]:Ee[Ze.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:ct?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[Mt?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",$t]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:ct?Gt:Xt}),ct&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Ft})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Zt})]})}),Je&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Ee=>{Ee.stopPropagation(),p(Ze.info.id,zt)},"aria-label":e(nt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(nt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:nt?s.jsx(R,{name:"check",className:"size-3.5"}):s.jsx(R,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Ef,{language:"json",code:zt,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},Ze.info.id)},t[186]=l,t[187]=i,t[188]=e,t[189]=n,t[190]=mt):mt=t[190],Et=[...y].reverse().map(mt),t[180]=l,t[181]=i,t[182]=y,t[183]=e,t[184]=n,t[185]=Et}else Et=t[185];let vt;t[191]!==Et?(vt=s.jsx("div",{className:"mt-2.5 space-y-1",children:Et}),t[191]=Et,t[192]=vt):vt=t[192];let Ct;t[193]!==Tt||t[194]!==vt?(Ct=s.jsxs("div",{children:[Tt,vt]}),t[193]=Tt,t[194]=vt,t[195]=Ct):Ct=t[195];let It;return t[196]!==Pe||t[197]!==Z||t[198]!==Le||t[199]!==St||t[200]!==Pt||t[201]!==Ct?(It=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Pe,Z,Le,St,Pt,Ct]})}),t[196]=Pe,t[197]=Z,t[198]=Le,t[199]=St,t[200]=Pt,t[201]=Ct,t[202]=It):It=t[202],It};function cy(t){return t.timeFormatPreference}function dy(t){return t.currentSessionId}function uy(t){return t.currentSessionDirectory}function my(t){return t.providers}function fy(t){return Object.keys(t).length>0?{}:t}function hy(t){return so(t.info).role==="assistant"}function py(t){return so(t.info).isUser}function gy(t,e){const n=Bn(e.info.cost);return t+n}function by(t){return so(t.info).isUser&&typeof t.info.system=="string"}function xy(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function yy(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Gn(t.value):"—"})]},t.label)}const _u=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),wy=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return _u.has(n.toLowerCase())},cn="about:blank",gr=t=>{const e=t.trim();if(!e)return cn;const n=e.includes("://")?e:`${wy(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?cn:r.toString()}catch{return cn}},jr=t=>{try{return _u.has(new URL(t).hostname.toLowerCase())}catch{return!1}},Ua=t=>{if(!t||t===cn)return"";try{return new URL(t).host||t}catch{return t}},Sy=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),vy=(t,e)=>Sy.has(t)&&jr(e),jy=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.port=="number"&&Number.isFinite(e.port)&&typeof e.url=="string"&&e.url.length>0&&typeof e.command=="string"},ky=async t=>{try{const e=await rs("/api/dev-servers",{signal:t});if(!e.ok)return{kind:"unavailable"};const n=await e.json();if(!n||typeof n!="object")return{kind:"unavailable"};const r=n.servers;return Array.isArray(r)?{kind:"ready",servers:r.filter(jy)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},Cy=async t=>{try{const e=await rs("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})});if(!e.ok)return null;const n=await e.json();if(!n||typeof n!="object")return null;const r=n.status;return typeof r=="number"&&Number.isFinite(r)?r:null}catch{return null}},Ny=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:null}catch{return null}},Ay=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const i=Ny(r);i!==null&&!n.has(i)&&n.set(i,r)}return e?e.map(r=>{const i=n.get(r.port);return{url:i??r.url,port:r.port,announced:i!==void 0}}).sort((r,i)=>r.announced!==i.announced?r.announced?-1:1:r.port-i.port):[...n.entries()].map(([r,i])=>({url:i,port:r,announced:!0})).sort((r,i)=>r.port-i.port)},ta="__openchamberBrowserAnnotationActive",Dy=`(() => {
|
|
47
|
-
try {
|
|
48
|
-
var host = document.querySelector('[data-openchamber-annotation]');
|
|
49
|
-
if (host && host.parentNode) host.parentNode.removeChild(host);
|
|
50
|
-
} catch (error) { /* page navigated away */ }
|
|
51
|
-
try {
|
|
52
|
-
var cursor = document.getElementById('openchamber-annotation-cursor');
|
|
53
|
-
if (cursor && cursor.parentNode) cursor.parentNode.removeChild(cursor);
|
|
54
|
-
} catch (error) { /* page navigated away */ }
|
|
55
|
-
try { delete window['${ta}']; } catch (error) { /* non-configurable */ }
|
|
56
|
-
})();`,Py=(t,e)=>{const n=JSON.stringify({theme:t,labels:e});return String.raw`new Promise((resolve) => {
|
|
57
|
-
var CONFIG = ${n};
|
|
58
|
-
var THEME = CONFIG.theme;
|
|
59
|
-
var LABELS = CONFIG.labels;
|
|
60
|
-
var OVERLAY_ATTR = 'data-openchamber-annotation';
|
|
61
|
-
var Z_OVERLAY = 2147483646;
|
|
62
|
-
var MAX_TEXT = 400;
|
|
63
|
-
var MIN_RECT = 3;
|
|
64
|
-
var EDITOR_GAP = 10;
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
var stale = document.querySelector('[' + OVERLAY_ATTR + ']');
|
|
68
|
-
if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
|
|
69
|
-
} catch (error) { /* nothing to clean */ }
|
|
70
|
-
|
|
71
|
-
window['${ta}'] = true;
|
|
72
|
-
|
|
73
|
-
var counter = 0;
|
|
74
|
-
var nextId = function (prefix) { counter += 1; return prefix + '-' + counter; };
|
|
75
|
-
|
|
76
|
-
var selected = null;
|
|
77
|
-
var regions = [];
|
|
78
|
-
var strokes = [];
|
|
79
|
-
var tool = 'select';
|
|
80
|
-
var settled = false;
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------- geometry
|
|
83
|
-
|
|
84
|
-
var rectFrom = function (domRect) {
|
|
85
|
-
return { x: domRect.left, y: domRect.top, width: domRect.width, height: domRect.height };
|
|
86
|
-
};
|
|
87
|
-
var normalizeRect = function (ax, ay, bx, by) {
|
|
88
|
-
return { x: Math.min(ax, bx), y: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
|
|
89
|
-
};
|
|
90
|
-
var usableRect = function (rect) { return rect.width >= MIN_RECT && rect.height >= MIN_RECT; };
|
|
91
|
-
|
|
92
|
-
// ------------------------------------------------------------- description
|
|
93
|
-
|
|
94
|
-
var isOverlayNode = function (element) {
|
|
95
|
-
var node = element;
|
|
96
|
-
while (node) {
|
|
97
|
-
if (node.nodeType === 1 && node.hasAttribute && node.hasAttribute(OVERLAY_ATTR)) return true;
|
|
98
|
-
node = node.parentNode || (node.host || null);
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
var elementFromPoint = function (x, y) {
|
|
104
|
-
var found = document.elementFromPoint(x, y);
|
|
105
|
-
if (!found || isOverlayNode(found)) return null;
|
|
106
|
-
return found;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var selectorPart = function (element) {
|
|
110
|
-
var part = element.tagName.toLowerCase();
|
|
111
|
-
if (element.id) return part + '#' + element.id;
|
|
112
|
-
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
113
|
-
if (className) {
|
|
114
|
-
var first = className.split(/\s+/).filter(Boolean).slice(0, 2).join('.');
|
|
115
|
-
if (first) part += '.' + first;
|
|
116
|
-
}
|
|
117
|
-
return part;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
var buildSelector = function (element) {
|
|
121
|
-
if (element.id) return '#' + element.id;
|
|
122
|
-
var parts = [];
|
|
123
|
-
var node = element;
|
|
124
|
-
var depth = 0;
|
|
125
|
-
while (node && node.nodeType === 1 && depth < 5) {
|
|
126
|
-
var part = selectorPart(node);
|
|
127
|
-
var parent = node.parentElement;
|
|
128
|
-
if (parent) {
|
|
129
|
-
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
130
|
-
return child.tagName === node.tagName;
|
|
131
|
-
});
|
|
132
|
-
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
133
|
-
}
|
|
134
|
-
parts.unshift(part);
|
|
135
|
-
if (node.id) break;
|
|
136
|
-
node = parent;
|
|
137
|
-
depth += 1;
|
|
138
|
-
}
|
|
139
|
-
return parts.join(' > ');
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
var INTERESTING_ATTRS = ['id', 'class', 'name', 'type', 'href', 'src', 'alt', 'title', 'role', 'placeholder', 'aria-label', 'data-testid'];
|
|
143
|
-
var STYLE_PROPS = [
|
|
144
|
-
'display', 'position', 'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontFamily',
|
|
145
|
-
'lineHeight', 'padding', 'margin', 'border', 'borderRadius', 'width', 'height', 'opacity',
|
|
146
|
-
'zIndex', 'flexDirection', 'justifyContent', 'alignItems', 'gap', 'textAlign'
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
var describe = function (element) {
|
|
150
|
-
var computed = window.getComputedStyle(element);
|
|
151
|
-
var attributes = {};
|
|
152
|
-
for (var i = 0; i < INTERESTING_ATTRS.length; i += 1) {
|
|
153
|
-
var name = INTERESTING_ATTRS[i];
|
|
154
|
-
var value = element.getAttribute(name);
|
|
155
|
-
if (value) attributes[name] = String(value).slice(0, 200);
|
|
156
|
-
}
|
|
157
|
-
var computedStyle = {};
|
|
158
|
-
for (var j = 0; j < STYLE_PROPS.length; j += 1) {
|
|
159
|
-
var prop = STYLE_PROPS[j];
|
|
160
|
-
computedStyle[prop] = String(computed[prop] == null ? '' : computed[prop]);
|
|
161
|
-
}
|
|
162
|
-
var ancestry = [];
|
|
163
|
-
var node = element.parentElement;
|
|
164
|
-
var depth = 0;
|
|
165
|
-
while (node && node.nodeType === 1 && depth < 4) {
|
|
166
|
-
var entry = { tag: node.tagName.toLowerCase(), selectorPart: selectorPart(node) };
|
|
167
|
-
if (node.id) entry.id = node.id;
|
|
168
|
-
var cls = typeof node.className === 'string' ? node.className.trim() : '';
|
|
169
|
-
if (cls) entry.className = cls.slice(0, 200);
|
|
170
|
-
ancestry.unshift(entry);
|
|
171
|
-
node = node.parentElement;
|
|
172
|
-
depth += 1;
|
|
173
|
-
}
|
|
174
|
-
var box = element.getBoundingClientRect();
|
|
175
|
-
var text = (element.textContent == null ? '' : String(element.textContent)).replace(/\s+/g, ' ').trim();
|
|
176
|
-
return {
|
|
177
|
-
tag: element.tagName.toLowerCase(),
|
|
178
|
-
text: text.slice(0, MAX_TEXT),
|
|
179
|
-
selector: buildSelector(element),
|
|
180
|
-
path: ancestry.map(function (e) { return e.selectorPart; }).concat([selectorPart(element)]).join(' > '),
|
|
181
|
-
bounds: rectFrom(box),
|
|
182
|
-
center: { x: box.left + box.width / 2, y: box.top + box.height / 2 },
|
|
183
|
-
attributes: attributes,
|
|
184
|
-
computedStyle: computedStyle,
|
|
185
|
-
ancestry: ancestry
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// ------------------------------------------------------------------ chrome
|
|
190
|
-
|
|
191
|
-
var host = document.createElement('div');
|
|
192
|
-
host.setAttribute(OVERLAY_ATTR, '');
|
|
193
|
-
host.style.cssText = 'position:fixed;inset:0;z-index:' + Z_OVERLAY + ';pointer-events:none';
|
|
194
|
-
var shadow = host.attachShadow({ mode: 'closed' });
|
|
195
|
-
|
|
196
|
-
var style = document.createElement('style');
|
|
197
|
-
style.textContent = [
|
|
198
|
-
':host{all:initial}',
|
|
199
|
-
'*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}',
|
|
200
|
-
'.layer{position:fixed;inset:0;pointer-events:none}',
|
|
201
|
-
'.box{position:fixed;left:0;top:0;display:none;pointer-events:none;border:1.5px solid ' + THEME.primary + ';background:' + THEME.primarySoft + ';border-radius:2px}',
|
|
202
|
-
'.label{position:fixed;left:0;top:0;display:none;pointer-events:none;padding:1px 6px;border-radius:4px;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';font-size:11px;line-height:17px;white-space:nowrap;font-weight:600}',
|
|
203
|
-
'.tools{position:fixed;top:14px;left:50%;transform:translateX(-50%);display:flex;gap:2px;padding:4px;border-radius:999px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 6px 20px rgba(0,0,0,.24);pointer-events:auto}',
|
|
204
|
-
'.tools button{appearance:none;border:none;background:transparent;color:' + THEME.mutedText + ';border-radius:999px;padding:5px 14px;font-size:12px;line-height:18px;font-weight:500;cursor:pointer;white-space:nowrap}',
|
|
205
|
-
'.tools button:hover{background:' + THEME.primaryFaint + '}',
|
|
206
|
-
'.tools button[aria-pressed="true"]{background:' + THEME.primarySoft + ';color:' + THEME.primary + ';font-weight:600}',
|
|
207
|
-
'.editor{position:fixed;left:0;top:0;display:none;align-items:center;gap:8px;width:min(420px,calc(100vw - 24px));padding:6px;padding-left:16px;border-radius:22px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 8px 28px rgba(0,0,0,.3);pointer-events:auto}',
|
|
208
|
-
'.editor textarea{flex:1;min-width:0;resize:none;border:none;background:transparent;color:' + THEME.text + ';font-size:13px;line-height:20px;outline:none;padding:6px 0;min-height:32px;max-height:104px;display:block}',
|
|
209
|
-
'.editor textarea::placeholder{color:' + THEME.mutedText + '}',
|
|
210
|
-
'.editor button{appearance:none;border:none;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';border-radius:999px;width:32px;height:32px;padding:0;display:flex;align-items:center;justify-content:center;flex-shrink:0;cursor:pointer}',
|
|
211
|
-
'.editor button svg{width:16px;height:16px;display:block}',
|
|
212
|
-
'.editor button[disabled]{opacity:.5;cursor:default}'
|
|
213
|
-
].join('');
|
|
214
|
-
shadow.appendChild(style);
|
|
215
|
-
|
|
216
|
-
var cursorStyle = document.createElement('style');
|
|
217
|
-
cursorStyle.id = 'openchamber-annotation-cursor';
|
|
218
|
-
document.head.appendChild(cursorStyle);
|
|
219
|
-
var setCursor = function (value) {
|
|
220
|
-
cursorStyle.textContent = value ? '*{cursor:' + value + ' !important}' : '';
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
var svgNS = 'http://www.w3.org/2000/svg';
|
|
224
|
-
var svg = document.createElementNS(svgNS, 'svg');
|
|
225
|
-
svg.setAttribute('class', 'layer');
|
|
226
|
-
svg.style.overflow = 'visible';
|
|
227
|
-
shadow.appendChild(svg);
|
|
228
|
-
|
|
229
|
-
var hoverBox = document.createElement('div');
|
|
230
|
-
hoverBox.className = 'box';
|
|
231
|
-
var hoverLabel = document.createElement('div');
|
|
232
|
-
hoverLabel.className = 'label';
|
|
233
|
-
var marqueeBox = document.createElement('div');
|
|
234
|
-
marqueeBox.className = 'box';
|
|
235
|
-
shadow.append(hoverBox, hoverLabel, marqueeBox);
|
|
236
|
-
|
|
237
|
-
var positionBox = function (node, rect) {
|
|
238
|
-
node.style.display = 'block';
|
|
239
|
-
node.style.transform = 'translate(' + rect.x + 'px,' + rect.y + 'px)';
|
|
240
|
-
node.style.width = rect.width + 'px';
|
|
241
|
-
node.style.height = rect.height + 'px';
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
var tools = document.createElement('div');
|
|
245
|
-
tools.className = 'tools';
|
|
246
|
-
shadow.appendChild(tools);
|
|
247
|
-
|
|
248
|
-
var toolButtons = {};
|
|
249
|
-
[['select', LABELS.select], ['marquee', LABELS.marquee], ['draw', LABELS.draw]].forEach(function (entry) {
|
|
250
|
-
var button = document.createElement('button');
|
|
251
|
-
button.type = 'button';
|
|
252
|
-
button.textContent = entry[1];
|
|
253
|
-
button.addEventListener('click', function () { setTool(entry[0]); });
|
|
254
|
-
toolButtons[entry[0]] = button;
|
|
255
|
-
tools.appendChild(button);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
var editor = document.createElement('div');
|
|
259
|
-
editor.className = 'editor';
|
|
260
|
-
shadow.appendChild(editor);
|
|
261
|
-
|
|
262
|
-
var comment = document.createElement('textarea');
|
|
263
|
-
comment.rows = 1;
|
|
264
|
-
comment.placeholder = LABELS.commentPlaceholder;
|
|
265
|
-
var submit = document.createElement('button');
|
|
266
|
-
submit.type = 'button';
|
|
267
|
-
// Icon-only attach button (Remix attachment-2), matching the chat comment
|
|
268
|
-
// input; the localized label stays available to assistive tech.
|
|
269
|
-
submit.setAttribute('aria-label', LABELS.submit);
|
|
270
|
-
submit.title = LABELS.submit;
|
|
271
|
-
submit.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.8287 7.75737L9.1718 13.4142C8.78127 13.8047 8.78127 14.4379 9.1718 14.8284C9.56232 15.219 10.1955 15.219 10.586 14.8284L16.2429 9.17158C17.4144 8.00001 17.4144 6.10052 16.2429 4.92894C15.0713 3.75737 13.1718 3.75737 12.0002 4.92894L6.34337 10.5858C4.39075 12.5384 4.39075 15.7042 6.34337 17.6569C8.29599 19.6095 11.4618 19.6095 13.4144 17.6569L19.0713 12L20.4855 13.4142L14.8287 19.0711C12.095 21.8047 7.66283 21.8047 4.92916 19.0711C2.19549 16.3374 2.19549 11.9053 4.92916 9.17158L10.586 3.51473C12.5386 1.56211 15.7045 1.56211 17.6571 3.51473C19.6097 5.46735 19.6097 8.63317 17.6571 10.5858L12.0002 16.2427C10.8287 17.4142 8.92916 17.4142 7.75759 16.2427C6.58601 15.0711 6.58601 13.1716 7.75759 12L13.4144 6.34316L14.8287 7.75737Z" fill="currentColor"/></svg>';
|
|
272
|
-
editor.append(comment, submit);
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Grows the box with its content.
|
|
276
|
-
*
|
|
277
|
-
* A hidden element reports scrollHeight 0, so measuring one collapses the
|
|
278
|
-
* field to nothing — which is what left a sliver of a click target and an
|
|
279
|
-
* invisible caret. Measuring only while visible, and never below the CSS
|
|
280
|
-
* min-height, keeps it usable.
|
|
281
|
-
*/
|
|
282
|
-
var resizeComment = function () {
|
|
283
|
-
if (editor.style.display === 'none') return;
|
|
284
|
-
comment.style.height = 'auto';
|
|
285
|
-
comment.style.height = Math.max(32, Math.min(comment.scrollHeight, 104)) + 'px';
|
|
286
|
-
};
|
|
287
|
-
comment.addEventListener('input', resizeComment);
|
|
288
|
-
|
|
289
|
-
// -------------------------------------------------------------- selection
|
|
290
|
-
|
|
291
|
-
var lastTargetRect = null;
|
|
292
|
-
|
|
293
|
-
/** Places the comment box under whatever was just marked, kept on screen. */
|
|
294
|
-
var positionEditor = function () {
|
|
295
|
-
if (!lastTargetRect) {
|
|
296
|
-
editor.style.display = 'none';
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
var wasHidden = editor.style.display === 'none';
|
|
300
|
-
editor.style.display = 'flex';
|
|
301
|
-
// Measured now that it is laid out, not while it was still hidden.
|
|
302
|
-
if (wasHidden) resizeComment();
|
|
303
|
-
var box = editor.getBoundingClientRect();
|
|
304
|
-
var left = lastTargetRect.x + lastTargetRect.width / 2 - box.width / 2;
|
|
305
|
-
var top = lastTargetRect.y + lastTargetRect.height + EDITOR_GAP;
|
|
306
|
-
// Above the target when there is no room below, so the box is never left
|
|
307
|
-
// half off the bottom of the page.
|
|
308
|
-
if (top + box.height > window.innerHeight - 8) {
|
|
309
|
-
top = Math.max(8, lastTargetRect.y - box.height - EDITOR_GAP);
|
|
310
|
-
}
|
|
311
|
-
left = Math.max(8, Math.min(left, window.innerWidth - box.width - 8));
|
|
312
|
-
editor.style.transform = 'translate(' + Math.round(left) + 'px,' + Math.round(top) + 'px)';
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
/** Focus after layout: focusing a zero-height field puts the caret nowhere. */
|
|
316
|
-
var focusComment = function () {
|
|
317
|
-
requestAnimationFrame(function () {
|
|
318
|
-
try {
|
|
319
|
-
comment.focus({ preventScroll: true });
|
|
320
|
-
comment.setSelectionRange(comment.value.length, comment.value.length);
|
|
321
|
-
} catch (error) { /* field went away */ }
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
var hasTargets = function () {
|
|
326
|
-
return Boolean(selected) || regions.length > 0 || strokes.length > 0;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
var syncChrome = function () {
|
|
330
|
-
submit.disabled = !hasTargets();
|
|
331
|
-
if (!hasTargets()) {
|
|
332
|
-
lastTargetRect = null;
|
|
333
|
-
editor.style.display = 'none';
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
positionEditor();
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
var syncSelectionVisuals = function () {
|
|
340
|
-
if (!selected) return;
|
|
341
|
-
var rect = rectFrom(selected.element.getBoundingClientRect());
|
|
342
|
-
if (!usableRect(rect)) {
|
|
343
|
-
selected.outline.style.display = 'none';
|
|
344
|
-
selected.badge.style.display = 'none';
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
positionBox(selected.outline, rect);
|
|
348
|
-
selected.badge.style.display = 'block';
|
|
349
|
-
selected.badge.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
350
|
-
lastTargetRect = rect;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
var dropSelection = function () {
|
|
354
|
-
if (!selected) return;
|
|
355
|
-
selected.outline.remove();
|
|
356
|
-
selected.badge.remove();
|
|
357
|
-
selected = null;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
var selectElement = function (element) {
|
|
361
|
-
var wasSelected = selected && selected.element === element;
|
|
362
|
-
dropSelection();
|
|
363
|
-
if (wasSelected) {
|
|
364
|
-
// Clicking the chosen element again clears it, so a misclick costs one
|
|
365
|
-
// click rather than starting over.
|
|
366
|
-
lastTargetRect = null;
|
|
367
|
-
syncChrome();
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
var outline = document.createElement('div');
|
|
371
|
-
outline.className = 'box';
|
|
372
|
-
var badge = document.createElement('div');
|
|
373
|
-
badge.className = 'label';
|
|
374
|
-
badge.textContent = selectorPart(element);
|
|
375
|
-
shadow.append(outline, badge);
|
|
376
|
-
selected = { id: nextId('element'), element: element, outline: outline, badge: badge };
|
|
377
|
-
syncSelectionVisuals();
|
|
378
|
-
syncChrome();
|
|
379
|
-
focusComment();
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
var setTool = function (next) {
|
|
383
|
-
tool = next;
|
|
384
|
-
hoverBox.style.display = 'none';
|
|
385
|
-
hoverLabel.style.display = 'none';
|
|
386
|
-
marqueeBox.style.display = 'none';
|
|
387
|
-
setCursor(next === 'select' ? '' : 'crosshair');
|
|
388
|
-
for (var key in toolButtons) {
|
|
389
|
-
if (Object.prototype.hasOwnProperty.call(toolButtons, key)) {
|
|
390
|
-
toolButtons[key].setAttribute('aria-pressed', key === next ? 'true' : 'false');
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// ------------------------------------------------------------- interaction
|
|
396
|
-
|
|
397
|
-
var drag = null;
|
|
398
|
-
|
|
399
|
-
var onPointerMove = function (event) {
|
|
400
|
-
if (drag) {
|
|
401
|
-
if (drag.kind === 'marquee') {
|
|
402
|
-
drag.rect = normalizeRect(drag.startX, drag.startY, event.clientX, event.clientY);
|
|
403
|
-
positionBox(marqueeBox, drag.rect);
|
|
404
|
-
} else if (drag.kind === 'draw') {
|
|
405
|
-
drag.points.push({ x: event.clientX, y: event.clientY });
|
|
406
|
-
drag.path.setAttribute('d', drag.points.map(function (point, index) {
|
|
407
|
-
return (index === 0 ? 'M' : 'L') + point.x + ' ' + point.y;
|
|
408
|
-
}).join(' '));
|
|
409
|
-
}
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (tool !== 'select') return;
|
|
414
|
-
var element = elementFromPoint(event.clientX, event.clientY);
|
|
415
|
-
if (!element) {
|
|
416
|
-
hoverBox.style.display = 'none';
|
|
417
|
-
hoverLabel.style.display = 'none';
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
var rect = rectFrom(element.getBoundingClientRect());
|
|
421
|
-
positionBox(hoverBox, rect);
|
|
422
|
-
hoverLabel.textContent = selectorPart(element);
|
|
423
|
-
hoverLabel.style.display = 'block';
|
|
424
|
-
hoverLabel.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
var onPointerDown = function (event) {
|
|
428
|
-
if (event.button !== 0) return;
|
|
429
|
-
if (isOverlayNode(event.target)) return;
|
|
430
|
-
event.preventDefault();
|
|
431
|
-
event.stopPropagation();
|
|
432
|
-
|
|
433
|
-
if (tool === 'select') {
|
|
434
|
-
var element = elementFromPoint(event.clientX, event.clientY);
|
|
435
|
-
if (element) selectElement(element);
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (tool === 'marquee') {
|
|
440
|
-
drag = { kind: 'marquee', startX: event.clientX, startY: event.clientY, rect: null };
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
var path = document.createElementNS(svgNS, 'path');
|
|
445
|
-
path.setAttribute('fill', 'none');
|
|
446
|
-
path.setAttribute('stroke', THEME.primary);
|
|
447
|
-
path.setAttribute('stroke-width', '2.5');
|
|
448
|
-
path.setAttribute('stroke-linecap', 'round');
|
|
449
|
-
path.setAttribute('stroke-linejoin', 'round');
|
|
450
|
-
svg.appendChild(path);
|
|
451
|
-
drag = { kind: 'draw', path: path, points: [{ x: event.clientX, y: event.clientY }] };
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
var onPointerUp = function () {
|
|
455
|
-
if (!drag) return;
|
|
456
|
-
var finished = drag;
|
|
457
|
-
drag = null;
|
|
458
|
-
|
|
459
|
-
if (finished.kind === 'marquee') {
|
|
460
|
-
marqueeBox.style.display = 'none';
|
|
461
|
-
var rect = finished.rect;
|
|
462
|
-
if (!rect || !usableRect(rect)) return;
|
|
463
|
-
// A region marks an area, not the elements inside it: expanding it into a
|
|
464
|
-
// selection made the result depend on the page's markup rather than on
|
|
465
|
-
// what was drawn.
|
|
466
|
-
regions.push({ id: nextId('region'), rect: rect });
|
|
467
|
-
var outline = document.createElementNS(svgNS, 'rect');
|
|
468
|
-
outline.setAttribute('x', String(rect.x));
|
|
469
|
-
outline.setAttribute('y', String(rect.y));
|
|
470
|
-
outline.setAttribute('width', String(rect.width));
|
|
471
|
-
outline.setAttribute('height', String(rect.height));
|
|
472
|
-
outline.style.fill = THEME.primarySoft;
|
|
473
|
-
outline.setAttribute('stroke', THEME.primary);
|
|
474
|
-
outline.setAttribute('stroke-width', '1.5');
|
|
475
|
-
outline.setAttribute('rx', '2');
|
|
476
|
-
svg.appendChild(outline);
|
|
477
|
-
lastTargetRect = rect;
|
|
478
|
-
syncChrome();
|
|
479
|
-
focusComment();
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
var points = finished.points;
|
|
484
|
-
if (points.length < 2) {
|
|
485
|
-
if (finished.path.parentNode) finished.path.parentNode.removeChild(finished.path);
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
var minX = points[0].x, minY = points[0].y, maxX = points[0].x, maxY = points[0].y;
|
|
489
|
-
for (var p = 1; p < points.length; p += 1) {
|
|
490
|
-
minX = Math.min(minX, points[p].x);
|
|
491
|
-
minY = Math.min(minY, points[p].y);
|
|
492
|
-
maxX = Math.max(maxX, points[p].x);
|
|
493
|
-
maxY = Math.max(maxY, points[p].y);
|
|
494
|
-
}
|
|
495
|
-
var bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
496
|
-
strokes.push({ id: nextId('stroke'), points: points, bounds: bounds });
|
|
497
|
-
lastTargetRect = bounds;
|
|
498
|
-
syncChrome();
|
|
499
|
-
focusComment();
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Swallows the page's own mouse handling while annotating.
|
|
504
|
-
*
|
|
505
|
-
* Blocking pointerdown is not enough: a click still follows it, so marking a
|
|
506
|
-
* button pressed that button and marking a link navigated away from the page
|
|
507
|
-
* being annotated. These are the events that reach page code, so these are
|
|
508
|
-
* the ones that have to stop.
|
|
509
|
-
*/
|
|
510
|
-
var blockPageInteraction = function (event) {
|
|
511
|
-
if (isOverlayNode(event.target)) return;
|
|
512
|
-
event.preventDefault();
|
|
513
|
-
event.stopPropagation();
|
|
514
|
-
};
|
|
515
|
-
var BLOCKED_EVENTS = ['click', 'auxclick', 'dblclick', 'mousedown', 'mouseup', 'contextmenu'];
|
|
516
|
-
|
|
517
|
-
var onScrollOrResize = function () {
|
|
518
|
-
syncSelectionVisuals();
|
|
519
|
-
positionEditor();
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
var onKeyDown = function (event) {
|
|
523
|
-
if (event.key === 'Escape') {
|
|
524
|
-
event.preventDefault();
|
|
525
|
-
event.stopImmediatePropagation();
|
|
526
|
-
finish(null);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
var onCommentKeyDown = function (event) {
|
|
531
|
-
// Do not let the annotated page treat typed letters as its own shortcuts.
|
|
532
|
-
event.stopPropagation();
|
|
533
|
-
if (event.key === 'Enter' && !event.shiftKey) {
|
|
534
|
-
event.preventDefault();
|
|
535
|
-
attach();
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
document.addEventListener('pointermove', onPointerMove, true);
|
|
540
|
-
document.addEventListener('pointerdown', onPointerDown, true);
|
|
541
|
-
document.addEventListener('pointerup', onPointerUp, true);
|
|
542
|
-
BLOCKED_EVENTS.forEach(function (name) {
|
|
543
|
-
window.addEventListener(name, blockPageInteraction, { capture: true, passive: false });
|
|
544
|
-
});
|
|
545
|
-
window.addEventListener('scroll', onScrollOrResize, true);
|
|
546
|
-
window.addEventListener('resize', onScrollOrResize, true);
|
|
547
|
-
window.addEventListener('keydown', onKeyDown, true);
|
|
548
|
-
comment.addEventListener('keydown', onCommentKeyDown);
|
|
549
|
-
|
|
550
|
-
// ------------------------------------------------------------------ finish
|
|
551
|
-
|
|
552
|
-
var teardown = function () {
|
|
553
|
-
document.removeEventListener('pointermove', onPointerMove, true);
|
|
554
|
-
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
555
|
-
document.removeEventListener('pointerup', onPointerUp, true);
|
|
556
|
-
BLOCKED_EVENTS.forEach(function (name) {
|
|
557
|
-
window.removeEventListener(name, blockPageInteraction, true);
|
|
558
|
-
});
|
|
559
|
-
window.removeEventListener('scroll', onScrollOrResize, true);
|
|
560
|
-
window.removeEventListener('resize', onScrollOrResize, true);
|
|
561
|
-
window.removeEventListener('keydown', onKeyDown, true);
|
|
562
|
-
comment.removeEventListener('keydown', onCommentKeyDown);
|
|
563
|
-
setCursor('');
|
|
564
|
-
if (cursorStyle.parentNode) cursorStyle.parentNode.removeChild(cursorStyle);
|
|
565
|
-
if (host.parentNode) host.parentNode.removeChild(host);
|
|
566
|
-
try { delete window['${ta}']; } catch (error) { /* non-configurable */ }
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
var finish = function (payload) {
|
|
570
|
-
if (settled) return;
|
|
571
|
-
settled = true;
|
|
572
|
-
teardown();
|
|
573
|
-
// Removing the chrome is not enough: the host screenshots this page right
|
|
574
|
-
// after we resolve, and the compositor can still hold a frame containing
|
|
575
|
-
// our outlines. Yield two frames so the page has actually repainted.
|
|
576
|
-
requestAnimationFrame(function () {
|
|
577
|
-
requestAnimationFrame(function () { resolve(payload); });
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
var attach = function () {
|
|
582
|
-
if (!hasTargets()) return;
|
|
583
|
-
finish({
|
|
584
|
-
id: 'annotation-' + Date.now(),
|
|
585
|
-
pageUrl: String(location.href),
|
|
586
|
-
pageTitle: String(document.title || ''),
|
|
587
|
-
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
588
|
-
devicePixelRatio: window.devicePixelRatio || 1,
|
|
589
|
-
comment: comment.value,
|
|
590
|
-
// Zero or one element, never more. Kept as a list so elements, regions
|
|
591
|
-
// and strokes stay one uniform shape for everything downstream.
|
|
592
|
-
elements: selected ? [{ id: selected.id, element: describe(selected.element) }] : [],
|
|
593
|
-
regions: regions.map(function (entry) { return { id: entry.id, rect: entry.rect }; }),
|
|
594
|
-
strokes: strokes.map(function (entry) {
|
|
595
|
-
return { id: entry.id, points: entry.points, bounds: entry.bounds };
|
|
596
|
-
})
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
submit.addEventListener('click', attach);
|
|
601
|
-
|
|
602
|
-
(document.body || document.documentElement).appendChild(host);
|
|
603
|
-
setTool('select');
|
|
604
|
-
syncChrome();
|
|
605
|
-
});`},Ty={kind:"idle"},vn=t=>typeof t=="object"&&t!==null,Cn=t=>typeof t=="number"&&Number.isFinite(t),Ql=t=>vn(t)&&Object.values(t).every(e=>typeof e=="string"),Ha=t=>vn(t)&&Cn(t.x)&&Cn(t.y)&&Cn(t.width)&&Cn(t.height),Lu=t=>vn(t)&&Cn(t.x)&&Cn(t.y),Iy=t=>vn(t)&&typeof t.tag=="string"&&typeof t.selectorPart=="string"&&(t.id===void 0||typeof t.id=="string")&&(t.className===void 0||typeof t.className=="string"),Ey=t=>vn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&Ha(t.bounds)&&Lu(t.center)&&Ql(t.attributes)&&Ql(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every(Iy),Ry=t=>vn(t)&&typeof t.id=="string"&&Ey(t.element),My=t=>vn(t)&&typeof t.id=="string"&&Ha(t.rect),Oy=t=>vn(t)&&typeof t.id=="string"&&Ha(t.bounds)&&Array.isArray(t.points)&&t.points.every(Lu),By=t=>vn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&vn(t.viewport)&&Cn(t.viewport.width)&&Cn(t.viewport.height)&&Cn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(Ry)&&Array.isArray(t.regions)&&t.regions.every(My)&&Array.isArray(t.strokes)&&t.strokes.every(Oy),Fy=1600,_y=t=>new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to decode browser page capture")),r.src=t}),Ly=async({base64:t,mime:e,captureWidth:n,captureHeight:r,cssWidth:i,cssHeight:o,payload:l,accentColor:a,accentFill:d})=>{if(!t)return null;try{const u=await _y(`data:${e};base64,${t}`),m=Math.max(1,u.naturalWidth||n),h=Math.max(1,u.naturalHeight||r),y=m/Math.max(1,i||m),b=h/Math.max(1,o||h),S=Math.min(1,Fy/m),v=document.createElement("canvas");v.width=Math.max(1,Math.floor(m*S)),v.height=Math.max(1,Math.floor(h*S));const g=v.getContext("2d");if(!g)return null;g.scale(S,S),g.drawImage(u,0,0,m,h);const f=N=>({x:N.x*y,y:N.y*b,width:N.width*y,height:N.height*b}),x=Math.max(2,2.5*y/Math.max(S,.2));g.strokeStyle=a,g.fillStyle=d;const p=N=>{const C=f(N);g.lineWidth=x,g.fillRect(C.x,C.y,C.width,C.height),g.strokeRect(C.x,C.y,C.width,C.height)};for(const N of l.elements)p(N.element.bounds);for(const N of l.regions)p(N.rect);for(const N of l.strokes)N.points.length<2||(g.beginPath(),N.points.forEach((C,k)=>{const A=C.x*y,D=C.y*b;k===0?g.moveTo(A,D):g.lineTo(A,D)}),g.lineCap="round",g.lineJoin="round",g.lineWidth=x*1.4,g.stroke());const w=await new Promise(N=>v.toBlob(N,"image/jpeg",.85));return w?new File([w],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},$y="({ width: window.innerWidth, height: window.innerHeight })",Wy=async t=>{try{const e=await t.executeJavaScript($y,!0);if(!e||typeof e!="object")return null;const n=e;return typeof n.width!="number"||typeof n.height!="number"||!Number.isFinite(n.width)||!Number.isFinite(n.height)?null:{width:n.width,height:n.height}}catch{return null}},Do=async t=>{try{await t.executeJavaScript(Dy,!1)}catch{}},zy=async({host:t,theme:e,labels:n})=>{const r=Py(e,n),i=await t.executeJavaScript(r,!0);if(i==null)return null;if(!By(i))return await Do(t),null;const o=i;try{const l=await Wy(t)??o.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:o,screenshot:null};const d=await Ly({base64:a.base64,mime:a.mime||"image/jpeg",captureWidth:a.width,captureHeight:a.height,cssWidth:l.width,cssHeight:l.height,payload:o,accentColor:e.primary,accentFill:e.primarySoft});return{payload:o,screenshot:d}}catch{return{payload:o,screenshot:null}}},an={colorScheme:"dark",primary:"rgb(59, 130, 246)",primarySoft:"rgba(59, 130, 246, 0.16)",primaryFaint:"rgba(59, 130, 246, 0.10)",primaryContrast:"rgb(255, 255, 255)",surface:"rgb(24, 24, 27)",surfaceElevated:"rgb(32, 32, 36)",glassSurface:"rgba(32, 32, 36, 0.64)",glassFilter:"blur(26px) saturate(1.16)",border:"rgba(255, 255, 255, 0.14)",text:"rgb(244, 244, 245)",mutedText:"rgba(244, 244, 245, 0.62)"},Vy=()=>{if(typeof document>"u"||!document.body)return null;const t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;pointer-events:none",document.body.appendChild(t),{read:e=>{t.style.backgroundColor="",t.style.backgroundColor=e;const n=window.getComputedStyle(t).backgroundColor;return n&&n!=="rgba(0, 0, 0, 0)"?n:""},readVariable:e=>window.getComputedStyle(document.documentElement).getPropertyValue(e).trim(),dispose:()=>t.remove()}},Uy=t=>{const e=Vy();if(!e)return{...an,colorScheme:t};try{const n=(a,d)=>e.read(`var(${a})`)||d,r=(a,d,u)=>e.read(`color-mix(in srgb, var(${a}) ${d}%, transparent)`)||u,i=e.readVariable("--oc-glass-tooltip-opacity")||"62%",o=e.readVariable("--oc-glass-blur")||"26px",l=e.readVariable("--oc-glass-saturation")||"1.16";return{colorScheme:t,glassSurface:e.read(`color-mix(in srgb, var(--surface-elevated) ${i}, transparent)`)||an.glassSurface,glassFilter:`blur(${o}) saturate(${l})`,primary:n("--primary",an.primary),primarySoft:r("--primary",16,an.primarySoft),primaryFaint:r("--primary",10,an.primaryFaint),primaryContrast:n("--primary-foreground",an.primaryContrast),surface:n("--surface-background",an.surface),surfaceElevated:n("--surface-elevated",an.surfaceElevated),border:n("--border",an.border),text:n("--foreground",an.text),mutedText:n("--muted-foreground",an.mutedText)}}catch{return{...an,colorScheme:t}}finally{e.dispose()}};let br=null,xr=null,Po=null,Qr=0,Uo=null;const bn=new Set,Hy=3e4,Ky=45e3,$u=()=>{Po&&(clearTimeout(Po),Po=null)},Wu=()=>{if(xr||bn.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Qr,5)),Hy);xr=setTimeout(()=>{xr=null,Qr+=1,Ka()},t)},Yr=()=>{$u(),br&&br.close(),br=null},Yl=()=>{$u(),bn.size!==0&&(Po=setTimeout(()=>{Yr(),Wu()},Ky))},Gy=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},ho=t=>!t||typeof t!="object"?null:t,qy=t=>{if(t.type==="openchamber:event-stream-ready"){Qr=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:agent-memory-changed"){const d=ho(t.properties),m={type:"agent-memory-changed",scope:d?.scope==="project"?"project":"global",...typeof d?.projectId=="string"&&d.projectId.length>0?{projectId:d.projectId}:{}};for(const h of bn)h(m);return}if(t.type==="openchamber:session-created"){const d=ho(t.properties),u=typeof d?.sessionId=="string"?d.sessionId:"",m=typeof d?.directory=="string"?d.directory:"";if(!u||!m)return;const h={type:"session-created",sessionId:u,directory:m,createdAt:typeof d?.createdAt=="number"?d.createdAt:Date.now(),promptDispatched:d?.promptDispatched===!0,dispatchedAsCommand:d?.dispatchedAsCommand===!0,...typeof d?.projectId=="string"&&d.projectId.length>0?{projectId:d.projectId}:{}};for(const y of bn)y(h);return}if(t.type==="openchamber:browser-control-request"){const d=ho(t.properties),u=typeof d?.requestId=="string"?d.requestId:"",m=typeof d?.action=="string"?d.action:"";if(!u||!m)return;const h=d?.parameters,y={type:"browser-control-request",requestId:u,action:m,parameters:h&&typeof h=="object"&&!Array.isArray(h)?h:{}};for(const b of bn)b(y);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=ho(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",i=typeof e?.ranAt=="number"?e.ranAt:Date.now(),o=e?.status,l=o==="running"||o==="error"?o:"success";if(!n||!r)return;const a={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:i,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of bn)d(a)},Ka=()=>{if(typeof window>"u"||bn.size===0||typeof EventSource!="function"||br&&br.readyState!==EventSource.CLOSED)return;Yr();const t=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,e=new EventSource(xa().sse("/api/openchamber/events",t?{browser:"1"}:void 0));e.onopen=()=>{Yl()},e.onmessage=n=>{Yl();const r=Gy(n.data);r&&qy(r)},e.onerror=()=>{Yr(),Wu()},br=e},Qy=()=>{Uo||typeof window>"u"||(Uo=ei(()=>{Yr(),Qr=0,Ka()}))},Yy=()=>{Uo?.(),Uo=null},no=t=>(bn.add(t),Qy(),Ka(),()=>{bn.delete(t),bn.size===0&&(xr&&(clearTimeout(xr),xr=null),Qr=0,Yr(),Yy())}),Xy=2e3,Jy=50;let Zn=null,yr=null,Lr=null;const Zy=async t=>{try{const e=await rs("/api/browser-control/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t})});return e.ok?(await e.json())?.granted===!0:!1}catch{return!1}},lr=async(t,e)=>{try{const n=await rs("/api/browser-control/result",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t,...e})});n.ok||console.warn(`[browser-control] the server rejected the result for ${t} (HTTP ${n.status}); the agent will see this action time out`)}catch(n){console.warn(`[browser-control] could not deliver the result for ${t}:`,n)}},e1=async(t=Xy)=>{const e=Date.now()+t;for(;!Zn&&Date.now()<e;)await new Promise(n=>setTimeout(n,Jy));return Zn},t1=async t=>{const e=t.action==="browser.open",n=Zn;if(!(!n&&!(e&&yr))&&await Zy(t.requestId))try{if(e&&!n){const i=typeof t.parameters.url=="string"?t.parameters.url:"";if(!i){await lr(t.requestId,{ok:!1,error:"url is required"});return}yr?.(i);const o=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!o||o==="fill"){await lr(t.requestId,{ok:!0,data:{url:i,opened:!0}});return}const l=await e1();if(!l){await lr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!1,note:"The panel had no browser view yet, so the viewport was not applied. Call browser.resize now that one exists."}});return}const a=await l.run("browser.resize",{viewport:o}),d=a&&typeof a=="object"?a.viewport??null:null;await lr(t.requestId,{ok:!0,data:{url:i,opened:!0,viewportApplied:!0,viewport:d}});return}const r=await n.run(t.action,t.parameters);await lr(t.requestId,{ok:!0,data:r})}catch(r){await lr(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},zu=()=>{Lr||(Lr=no(t=>{t.type==="browser-control-request"&&t1({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},Vu=()=>{Zn||yr||!Lr||(Lr(),Lr=null)},s1=t=>(Zn=t,zu(),()=>{Zn===t&&(Zn=null),Vu()}),n1=t=>(yr=t,zu(),()=>{yr===t&&(yr=null),Vu()}),r1=50,o1=6,i1=2048,a1=200,Uu=t=>{const e=gr(String(t??"").trim());if(!e||e.length>i1)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},l1=(t,e)=>{const n=Uu(e.url);if(!n)return t;const r=t.find(l=>l.url===n),i=String(e.title??"").trim().slice(0,a1)||r?.title||"";return[{url:n,title:i,lastVisitedAt:e.at},...t.filter(l=>l.url!==n)].slice(0,r1)},c1=(t,e)=>{const n=Uu(e);return t.filter(r=>r.url!==n)},d1=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),Hu=(t,e,n=o1)=>{const r=String(e??"").trim().toLowerCase(),i=[...t].sort((l,a)=>a.lastVisitedAt-l.lastVisitedAt);if(!r)return i.slice(0,n);const o=r.replace(/^https?:\/\//,"");return i.filter(l=>{const a=d1(l);return l.url===r||a===o?!1:a.includes(o)}).slice(0,n)},Xl=20,To=t=>{const e=dt((t||"").trim());return e?JSON.stringify([Cs(),e]):""},u1=t=>{const e=Object.keys(t);if(e.length<=Xl)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,i)=>i[1]-r[1]).slice(0,Xl);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},wr=or()(mg(t=>({byProject:{},recordVisit:(e,n)=>{const r=To(e);r&&t(i=>{const o=i.byProject[r]??[],l=l1(o,{...n,at:Date.now()});return l===o?i:{byProject:u1({...i.byProject,[r]:l})}})},forget:(e,n)=>{const r=To(e);r&&t(i=>{const o=i.byProject[r];return o?{byProject:{...i.byProject,[r]:c1(o,n)}}:i})},clear:e=>{const n=To(e);n&&t(r=>{if(!(n in r.byProject))return r;const i={...r.byProject};return delete i[n],{byProject:i}})}}),{name:"openchamber-browser-history",version:1,storage:Lm(),partialize:t=>({byProject:t.byProject})})),m1=[],Ku=t=>e=>{const n=To(t);return(n?e.byProject[n]:void 0)??m1},sa=new Map,Xr=new Map,Gu=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,qu=t=>{if(!t)return!1;try{const e=new URL(t,typeof window<"u"?window.location.href:void 0),n=typeof window<"u"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"";return n&&e.origin===n?!1:!jr(e.toString())}catch{return!1}},Qu=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:0}catch{return 0}},Jl=(t,e)=>{try{const n=new URL(t);return n.protocol="http:",n.hostname="127.0.0.1",n.port=String(e),n.toString()}catch{return t}};class $r extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const Zl=async t=>{if(!t||!Gu()||!jr(t))return t;const e=Ln();if(!qu(e))return t;const n=Qu(t);if(!n)return t;const r=`${e}|${n}`,i=sa.get(r);if(i){try{Xr.set(i,new URL(t).origin)}catch{}return Jl(t,i)}try{const o=await Fr("desktop_dev_tunnel_open",{baseUrl:e,port:n,clientToken:zr(),requestHeaders:dd()});if(!o||!Number.isInteger(o.localPort)||o.localPort<=0)throw new $r(t);sa.set(r,o.localPort);try{Xr.set(o.localPort,new URL(t).origin)}catch{}return Jl(t,o.localPort)}catch(o){throw o instanceof $r?o:new $r(t)}},ec=t=>{if(!t||!Gu()||!jr(t)||!qu(Ln()))return!1;const e=Qu(t);return e>0&&!Xr.has(e)},Tr=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=Xr.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},f1=()=>{sa.clear(),Xr.clear()};typeof window<"u"&&ei(f1);const tc=6e3,h1=120,p1=80,g1=`
|
|
606
|
-
var MAX_ELEMENTS = ${h1};
|
|
607
|
-
var MAX_LABEL_CHARS = ${p1};
|
|
608
|
-
var visible = function (element) {
|
|
609
|
-
var rect = element.getBoundingClientRect();
|
|
610
|
-
if (rect.width < 1 || rect.height < 1) return false;
|
|
611
|
-
var style = window.getComputedStyle(element);
|
|
612
|
-
return style.visibility !== 'hidden' && style.display !== 'none' && Number(style.opacity) !== 0;
|
|
613
|
-
};
|
|
614
|
-
var label = function (element) {
|
|
615
|
-
var aria = element.getAttribute('aria-label');
|
|
616
|
-
if (aria) return aria.trim();
|
|
617
|
-
var value = element.getAttribute('value');
|
|
618
|
-
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
619
|
-
if (text) return text.slice(0, MAX_LABEL_CHARS);
|
|
620
|
-
if (value) return String(value).slice(0, MAX_LABEL_CHARS);
|
|
621
|
-
var placeholder = element.getAttribute('placeholder');
|
|
622
|
-
return placeholder ? placeholder.trim().slice(0, MAX_LABEL_CHARS) : '';
|
|
623
|
-
};
|
|
624
|
-
var isUnique = function (selector) {
|
|
625
|
-
try {
|
|
626
|
-
return document.querySelectorAll(selector).length === 1;
|
|
627
|
-
} catch (error) {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Names an element by what it is, falling back to where it sits.
|
|
634
|
-
*
|
|
635
|
-
* A positional chain like 'main > section:nth-of-type(3) > div > a' survives
|
|
636
|
-
* only until the markup shifts, and says nothing about what it points at.
|
|
637
|
-
* Anything the page states about identity — an id, a test id, an accessible
|
|
638
|
-
* name — outlives edits and reads as the thing it selects. The chain remains
|
|
639
|
-
* as the last resort, because something always has to work.
|
|
640
|
-
*/
|
|
641
|
-
var cssPath = function (element) {
|
|
642
|
-
var tag = element.tagName.toLowerCase();
|
|
643
|
-
|
|
644
|
-
if (element.id) {
|
|
645
|
-
var byId = '#' + CSS.escape(element.id);
|
|
646
|
-
if (isUnique(byId)) return byId;
|
|
647
|
-
}
|
|
648
|
-
var stableAttrs = ['data-testid', 'data-test-id', 'data-test', 'name', 'aria-label'];
|
|
649
|
-
for (var a = 0; a < stableAttrs.length; a += 1) {
|
|
650
|
-
var value = element.getAttribute(stableAttrs[a]);
|
|
651
|
-
if (!value) continue;
|
|
652
|
-
var raw = String(value);
|
|
653
|
-
// A value containing a quote would need escaping for no real gain: such
|
|
654
|
-
// attributes are rare, and the positional chain still covers them.
|
|
655
|
-
if (raw.indexOf('"') !== -1) continue;
|
|
656
|
-
var byAttr = tag + '[' + stableAttrs[a] + '="' + raw + '"]';
|
|
657
|
-
if (isUnique(byAttr)) return byAttr;
|
|
658
|
-
}
|
|
659
|
-
var className = typeof element.className === 'string' ? element.className.trim() : '';
|
|
660
|
-
if (className) {
|
|
661
|
-
var classes = className.split(/\\s+/).filter(Boolean);
|
|
662
|
-
for (var c = 0; c < classes.length; c += 1) {
|
|
663
|
-
var byClass = tag + '.' + CSS.escape(classes[c]);
|
|
664
|
-
if (isUnique(byClass)) return byClass;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
var parts = [];
|
|
669
|
-
var node = element;
|
|
670
|
-
var depth = 0;
|
|
671
|
-
while (node && node.nodeType === 1 && depth < 6) {
|
|
672
|
-
var part = node.tagName.toLowerCase();
|
|
673
|
-
var parent = node.parentElement;
|
|
674
|
-
if (!parent) { parts.unshift(part); break; }
|
|
675
|
-
var siblings = Array.prototype.filter.call(parent.children, function (child) {
|
|
676
|
-
return child.tagName === node.tagName;
|
|
677
|
-
});
|
|
678
|
-
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
679
|
-
parts.unshift(part);
|
|
680
|
-
if (node.id) { parts[0] = '#' + CSS.escape(node.id); break; }
|
|
681
|
-
node = parent;
|
|
682
|
-
depth += 1;
|
|
683
|
-
}
|
|
684
|
-
return parts.join(' > ');
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
/** What a screen reader would announce, or '' when there is nothing to say. */
|
|
688
|
-
var accessibleName = function (element) {
|
|
689
|
-
var aria = element.getAttribute('aria-label');
|
|
690
|
-
if (aria && aria.trim()) return aria.trim();
|
|
691
|
-
var labelled = element.getAttribute('aria-labelledby');
|
|
692
|
-
if (labelled) {
|
|
693
|
-
var source = document.getElementById(labelled.split(/\\s+/)[0]);
|
|
694
|
-
if (source && (source.innerText || '').trim()) return source.innerText.trim();
|
|
695
|
-
}
|
|
696
|
-
var title = element.getAttribute('title');
|
|
697
|
-
if (title && title.trim()) return title.trim();
|
|
698
|
-
var alt = element.getAttribute('alt');
|
|
699
|
-
if (alt && alt.trim()) return alt.trim();
|
|
700
|
-
var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
|
|
701
|
-
if (text) return text;
|
|
702
|
-
var value = element.getAttribute('value');
|
|
703
|
-
return value && String(value).trim() ? String(value).trim() : '';
|
|
704
|
-
};
|
|
705
|
-
var findByText = function (needle) {
|
|
706
|
-
var wanted = String(needle).replace(/\\s+/g, ' ').trim().toLowerCase();
|
|
707
|
-
var candidates = document.querySelectorAll('a, button, [role="button"], [role="link"], input[type="submit"], input[type="button"], summary, label');
|
|
708
|
-
var exact = null;
|
|
709
|
-
var partial = null;
|
|
710
|
-
for (var i = 0; i < candidates.length; i += 1) {
|
|
711
|
-
var element = candidates[i];
|
|
712
|
-
if (!visible(element)) continue;
|
|
713
|
-
var text = label(element).toLowerCase();
|
|
714
|
-
if (!text) continue;
|
|
715
|
-
if (text === wanted) { exact = element; break; }
|
|
716
|
-
if (!partial && text.indexOf(wanted) !== -1) partial = element;
|
|
717
|
-
}
|
|
718
|
-
return exact || partial;
|
|
719
|
-
};
|
|
720
|
-
`,ro=t=>`(() => {
|
|
721
|
-
${g1}
|
|
722
|
-
${t}
|
|
723
|
-
})()`,b1=({selector:t}={})=>ro(`
|
|
724
|
-
var scopeSelector = ${JSON.stringify(t??"")};
|
|
725
|
-
var root = document;
|
|
726
|
-
if (scopeSelector) {
|
|
727
|
-
try { root = document.querySelector(scopeSelector); }
|
|
728
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + scopeSelector }; }
|
|
729
|
-
if (!root) return { ok: false, error: 'No element matches ' + scopeSelector };
|
|
730
|
-
}
|
|
731
|
-
var interactive = root.querySelectorAll('a[href], button, input, select, textarea, [role="button"], [role="link"], [role="tab"], [contenteditable="true"]');
|
|
732
|
-
var elements = [];
|
|
733
|
-
var visibleTotal = 0;
|
|
734
|
-
for (var i = 0; i < interactive.length; i += 1) {
|
|
735
|
-
var element = interactive[i];
|
|
736
|
-
if (!visible(element)) continue;
|
|
737
|
-
visibleTotal += 1;
|
|
738
|
-
if (elements.length >= MAX_ELEMENTS) continue;
|
|
739
|
-
|
|
740
|
-
var rect = element.getBoundingClientRect();
|
|
741
|
-
// Empty and default-valued fields are left out rather than serialized as
|
|
742
|
-
// "" and false. Repeated across a hundred entries that overhead dwarfed
|
|
743
|
-
// the information it carried.
|
|
744
|
-
var entry = {
|
|
745
|
-
selector: cssPath(element),
|
|
746
|
-
tag: element.tagName.toLowerCase(),
|
|
747
|
-
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
748
|
-
};
|
|
749
|
-
// The list covers the whole document so anything can be clicked without
|
|
750
|
-
// scrolling to it first, which means bounds alone do not say what is on
|
|
751
|
-
// screen — a negative y reads as a bug otherwise.
|
|
752
|
-
if (rect.bottom > 0 && rect.top < window.innerHeight) entry.inViewport = true;
|
|
753
|
-
var type = element.getAttribute('type');
|
|
754
|
-
if (type) entry.type = type;
|
|
755
|
-
var role = element.getAttribute('role');
|
|
756
|
-
if (role) entry.role = role;
|
|
757
|
-
var labelText = label(element);
|
|
758
|
-
if (labelText) entry.label = labelText;
|
|
759
|
-
if (element.disabled === true) entry.disabled = true;
|
|
760
|
-
// Flagged rather than described: reporting the accessible name of every
|
|
761
|
-
// element would cost more than it tells, while its absence on something
|
|
762
|
-
// clickable is a defect worth naming.
|
|
763
|
-
if (!accessibleName(element)) entry.missingAccessibleName = true;
|
|
764
|
-
elements.push(entry);
|
|
765
|
-
}
|
|
766
|
-
var body = document.body ? (document.body.innerText || '') : '';
|
|
767
|
-
var text = body.replace(/\\n{3,}/g, '\\n\\n').trim();
|
|
768
|
-
var docEl = document.documentElement;
|
|
769
|
-
var result = {
|
|
770
|
-
ok: true,
|
|
771
|
-
url: String(location.href),
|
|
772
|
-
title: String(document.title || ''),
|
|
773
|
-
scope: scopeSelector || 'document',
|
|
774
|
-
scrollY: Math.round(window.scrollY),
|
|
775
|
-
maxScrollY: Math.max(0, Math.round(docEl.scrollHeight - window.innerHeight)),
|
|
776
|
-
text: text.slice(0, ${tc}),
|
|
777
|
-
elements: elements
|
|
778
|
-
};
|
|
779
|
-
// State what was dropped. A capped list that reports only its own length
|
|
780
|
-
// reads as the whole page, and the agent acts as if it had seen everything.
|
|
781
|
-
if (text.length > ${tc}) {
|
|
782
|
-
result.textTruncated = true;
|
|
783
|
-
result.textTotalChars = text.length;
|
|
784
|
-
}
|
|
785
|
-
if (visibleTotal > elements.length) {
|
|
786
|
-
result.elementsTruncated = true;
|
|
787
|
-
result.interactiveElementsOnPage = visibleTotal;
|
|
788
|
-
}
|
|
789
|
-
return result;
|
|
790
|
-
`),x1=({selector:t,text:e})=>ro(`
|
|
791
|
-
var selector = ${JSON.stringify(t??"")};
|
|
792
|
-
var text = ${JSON.stringify(e??"")};
|
|
793
|
-
var target = null;
|
|
794
|
-
if (selector) {
|
|
795
|
-
try { target = document.querySelector(selector); }
|
|
796
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
797
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
798
|
-
} else {
|
|
799
|
-
target = findByText(text);
|
|
800
|
-
if (!target) return { ok: false, error: 'No clickable element has the label ' + text };
|
|
801
|
-
}
|
|
802
|
-
if (target.disabled === true) return { ok: false, error: 'Element is disabled' };
|
|
803
|
-
target.scrollIntoView({ block: 'center', inline: 'center' });
|
|
804
|
-
target.click();
|
|
805
|
-
return { ok: true, clicked: cssPath(target), label: label(target), url: String(location.href) };
|
|
806
|
-
`),y1=({selector:t,value:e,submit:n})=>ro(`
|
|
807
|
-
var selector = ${JSON.stringify(t)};
|
|
808
|
-
var value = ${JSON.stringify(e)};
|
|
809
|
-
var target = null;
|
|
810
|
-
try { target = document.querySelector(selector); }
|
|
811
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
812
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
813
|
-
|
|
814
|
-
var editable = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
815
|
-
if (!editable) return { ok: false, error: selector + ' is not a text field' };
|
|
816
|
-
if (target.disabled === true || target.readOnly === true) return { ok: false, error: 'Field is not editable' };
|
|
817
|
-
|
|
818
|
-
target.scrollIntoView({ block: 'center' });
|
|
819
|
-
target.focus();
|
|
820
|
-
if (target.isContentEditable) {
|
|
821
|
-
target.textContent = value;
|
|
822
|
-
} else {
|
|
823
|
-
// Frameworks track the value through the native setter; assigning the
|
|
824
|
-
// property directly leaves React and friends unaware of the change.
|
|
825
|
-
var prototype = target.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
826
|
-
var setter = Object.getOwnPropertyDescriptor(prototype, 'value');
|
|
827
|
-
if (setter && setter.set) setter.set.call(target, value);
|
|
828
|
-
else target.value = value;
|
|
829
|
-
}
|
|
830
|
-
target.dispatchEvent(new Event('input', { bubbles: true }));
|
|
831
|
-
target.dispatchEvent(new Event('change', { bubbles: true }));
|
|
832
|
-
|
|
833
|
-
if (${n?"true":"false"}) {
|
|
834
|
-
var enter = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true };
|
|
835
|
-
target.dispatchEvent(new KeyboardEvent('keydown', enter));
|
|
836
|
-
target.dispatchEvent(new KeyboardEvent('keyup', enter));
|
|
837
|
-
var form = target.form;
|
|
838
|
-
if (form && typeof form.requestSubmit === 'function') form.requestSubmit();
|
|
839
|
-
}
|
|
840
|
-
return { ok: true, selector: cssPath(target), url: String(location.href) };
|
|
841
|
-
`),w1=({selector:t,direction:e})=>ro(`
|
|
842
|
-
var selector = ${JSON.stringify(t??"")};
|
|
843
|
-
var direction = ${JSON.stringify(e??"")};
|
|
844
|
-
|
|
845
|
-
var settle = function (extra) {
|
|
846
|
-
return new Promise(function (resolve) {
|
|
847
|
-
requestAnimationFrame(function () {
|
|
848
|
-
requestAnimationFrame(function () {
|
|
849
|
-
var doc = document.documentElement;
|
|
850
|
-
var maxScrollY = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
851
|
-
var scrollY = Math.round(window.scrollY);
|
|
852
|
-
var result = { ok: true, scrollY: scrollY, maxScrollY: Math.round(maxScrollY) };
|
|
853
|
-
result.atTop = scrollY <= 1;
|
|
854
|
-
result.atBottom = scrollY >= maxScrollY - 1;
|
|
855
|
-
for (var key in extra) {
|
|
856
|
-
if (Object.prototype.hasOwnProperty.call(extra, key)) result[key] = extra[key];
|
|
857
|
-
}
|
|
858
|
-
resolve(result);
|
|
859
|
-
});
|
|
860
|
-
});
|
|
861
|
-
});
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
if (selector) {
|
|
865
|
-
var target = null;
|
|
866
|
-
try { target = document.querySelector(selector); }
|
|
867
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
868
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
869
|
-
// Instant on purpose: the page's own smooth scrolling would still be
|
|
870
|
-
// animating when the next action runs against it.
|
|
871
|
-
target.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
872
|
-
return settle({ scrolledTo: cssPath(target) });
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
var doc = document.documentElement;
|
|
876
|
-
var page = Math.round(window.innerHeight * 0.85);
|
|
877
|
-
var bottom = Math.max(0, doc.scrollHeight - window.innerHeight);
|
|
878
|
-
if (direction === 'down') window.scrollTo({ top: window.scrollY + page, behavior: 'instant' });
|
|
879
|
-
else if (direction === 'up') window.scrollTo({ top: window.scrollY - page, behavior: 'instant' });
|
|
880
|
-
else if (direction === 'top') window.scrollTo({ top: 0, behavior: 'instant' });
|
|
881
|
-
else if (direction === 'bottom') window.scrollTo({ top: bottom, behavior: 'instant' });
|
|
882
|
-
else return { ok: false, error: 'Unknown scroll direction: ' + direction };
|
|
883
|
-
return settle({ direction: direction });
|
|
884
|
-
`),S1=["color","background-color","background-image","opacity","font-family","font-size","font-weight","line-height","letter-spacing","text-align","border-radius","border-width","border-style","border-color","box-shadow","display","position","width","height","padding","margin","gap","flex-direction","justify-content","align-items","z-index","overflow","visibility"],v1=({selector:t})=>ro(`
|
|
885
|
-
var selector = ${JSON.stringify(t)};
|
|
886
|
-
var target = null;
|
|
887
|
-
try { target = document.querySelector(selector); }
|
|
888
|
-
catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
|
|
889
|
-
if (!target) return { ok: false, error: 'No element matches ' + selector };
|
|
890
|
-
|
|
891
|
-
var computed = window.getComputedStyle(target);
|
|
892
|
-
var styles = {};
|
|
893
|
-
var props = ${JSON.stringify(S1)};
|
|
894
|
-
for (var i = 0; i < props.length; i += 1) {
|
|
895
|
-
var value = computed.getPropertyValue(props[i]);
|
|
896
|
-
if (value) styles[props[i]] = String(value).trim();
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
var rect = target.getBoundingClientRect();
|
|
900
|
-
return {
|
|
901
|
-
ok: true,
|
|
902
|
-
selector: cssPath(target),
|
|
903
|
-
tag: target.tagName.toLowerCase(),
|
|
904
|
-
label: label(target),
|
|
905
|
-
bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
|
|
906
|
-
inViewport: rect.bottom > 0 && rect.top < window.innerHeight,
|
|
907
|
-
styles: styles
|
|
908
|
-
};
|
|
909
|
-
`),j1=t=>{const e=Ye.c(18),{entries:n,activeIndex:r,onSelect:i,onForget:o,onHighlight:l}=t,{t:a}=ht();if(n.length===0)return null;let d;e[0]!==a?(d=a("contextPanel.browser.history.label"),e[0]=a,e[1]=d):d=e[1];let u;if(e[2]!==r||e[3]!==n||e[4]!==o||e[5]!==l||e[6]!==i||e[7]!==a){let h;e[9]!==r||e[10]!==o||e[11]!==l||e[12]!==i||e[13]!==a?(h=(y,b)=>s.jsxs("div",{role:"option","aria-selected":b===r,className:Ie("group flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1",b===r?"bg-interactive-hover":"hover:bg-interactive-hover"),onPointerDown:S=>{S.preventDefault(),i(y.url)},onPointerEnter:()=>l(b),children:[s.jsx(R,{name:"global",className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate typography-micro text-foreground",children:y.title||Ua(y.url)}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:y.url})]}),s.jsx("button",{type:"button",className:Ie("shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity","hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"),"aria-label":a("contextPanel.browser.history.forget"),title:a("contextPanel.browser.history.forget"),onPointerDown:S=>{S.preventDefault(),S.stopPropagation(),o(y.url)},children:s.jsx(R,{name:"close",className:"size-3","aria-hidden":"true"})})]},y.url),e[9]=r,e[10]=o,e[11]=l,e[12]=i,e[13]=a,e[14]=h):h=e[14],u=n.map(h),e[2]=r,e[3]=n,e[4]=o,e[5]=l,e[6]=i,e[7]=a,e[8]=u}else u=e[8];let m;return e[15]!==d||e[16]!==u?(m=s.jsx("div",{className:"oc-glass-popover oc-glass-floating absolute inset-x-0 top-full z-50 mt-1 overflow-hidden rounded-xl p-1",role:"listbox","aria-label":d,children:u}),e[15]=d,e[16]=u,e[17]=m):m=e[17],m},ln=t=>{const e=Ye.c(17),{icon:n,label:r,onClick:i,disabled:o,pressed:l}=t,a=l?"secondary":"ghost",d=l&&"text-foreground";let u;e[0]!==d?(u=Ie("w-6 shrink-0 rounded-full px-0 text-muted-foreground","hover:text-foreground",d),e[0]=d,e[1]=u):u=e[1];let m;e[2]!==n?(m=s.jsx(R,{name:n,className:"size-3.5","aria-hidden":"true"}),e[2]=n,e[3]=m):m=e[3];let h;e[4]!==o||e[5]!==r||e[6]!==i||e[7]!==l||e[8]!==a||e[9]!==u||e[10]!==m?(h=s.jsx(bt,{asChild:!0,children:s.jsx(at,{type:"button",variant:a,size:"xs",className:u,onClick:i,disabled:o,"aria-label":r,"aria-pressed":l,children:m})}),e[4]=o,e[5]=r,e[6]=i,e[7]=l,e[8]=a,e[9]=u,e[10]=m,e[11]=h):h=e[11];let y;e[12]!==r?(y=s.jsx(xt,{sideOffset:6,children:r}),e[12]=r,e[13]=y):y=e[13];let b;return e[14]!==h||e[15]!==y?(b=s.jsxs(yt,{children:[h,y]}),e[14]=h,e[15]=y,e[16]=b):b=e[16],b},Yu=t=>{const e=Ye.c(104),{address:n,suggestions:r,onForgetSuggestion:i,onAddressChange:o,onSubmit:l,onBack:a,onForward:d,onReload:u,onOpenExternal:m,canGoBack:h,canGoForward:y,isLoading:b,onAnnotate:S,onOpenDevTools:v,isAnnotating:g,onHardReload:f,onZoomIn:x,onZoomOut:p,onZoomReset:w,zoomPercent:N,onClearCookies:C,onClearCache:k,onToggleDeviceBar:A,isDeviceBarOpen:D}=t;let P;e[0]!==r?(P=r===void 0?[]:r,e[0]=r,e[1]=P):P=e[1];const M=P,z=N===void 0?100:N,{t:I}=ht(),[V,T]=c.useState(!1),[_,O]=c.useState(-1);let j;e[2]!==V||e[3]!==M?(j=V?M:[],e[2]=V,e[3]=M,e[4]=j):j=e[4];const E=j;let L;e[5]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{O(-1)},e[5]=L):L=e[5];let U;e[6]!==n||e[7]!==V?(U=[n,V],e[6]=n,e[7]=V,e[8]=U):U=e[8],c.useEffect(L,U);let X;e[9]!==l?(X=Z=>{T(!1),O(-1),l(Z)},e[9]=l,e[10]=X):X=e[10];const Q=X;let me;e[11]!==_||e[12]!==Q||e[13]!==E?(me=Z=>{if(E.length!==0){if(Z.key==="ArrowDown"||Z.key==="ArrowUp"){Z.preventDefault();const Ne=Z.key==="ArrowDown"?1:-1,Me=E.length;O($=>{const ae=$+Ne;return ae<-1?Me-1:ae>=Me?-1:ae});return}if(Z.key==="Escape"&&_>=0){Z.preventDefault(),O(-1);return}if(Z.key==="Enter"&&_>=0){Z.preventDefault();const Ne=E[_];Ne&&Q(Ne.url)}}},e[11]=_,e[12]=Q,e[13]=E,e[14]=me):me=e[14];const re=me;let G;e[15]!==I?(G=I("contextPanel.browser.back"),e[15]=I,e[16]=G):G=e[16];const ee=!h;let ue;e[17]!==a||e[18]!==ee||e[19]!==G?(ue=s.jsx(ln,{icon:"arrow-left",label:G,onClick:a,disabled:ee}),e[17]=a,e[18]=ee,e[19]=G,e[20]=ue):ue=e[20];let W;e[21]!==I?(W=I("contextPanel.browser.forward"),e[21]=I,e[22]=W):W=e[22];const ne=!y;let Y;e[23]!==d||e[24]!==W||e[25]!==ne?(Y=s.jsx(ln,{icon:"arrow-right",label:W,onClick:d,disabled:ne}),e[23]=d,e[24]=W,e[25]=ne,e[26]=Y):Y=e[26];let F;e[27]!==b||e[28]!==I?(F=I(b?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=b,e[28]=I,e[29]=F):F=e[29];let J;e[30]!==u||e[31]!==F?(J=s.jsx(ln,{icon:"refresh",label:F,onClick:u}),e[30]=u,e[31]=F,e[32]=J):J=e[32];let ie;e[33]!==f||e[34]!==I?(ie=f?s.jsx(ln,{icon:"restart",label:I("contextPanel.browser.hardReload"),onClick:f}):null,e[33]=f,e[34]=I,e[35]=ie):ie=e[35];let xe;e[36]!==n||e[37]!==Q?(xe=Z=>{Z.preventDefault(),Q(n)},e[36]=n,e[37]=Q,e[38]=xe):xe=e[38];let ge;e[39]!==o?(ge=Z=>o(Z.target.value),e[39]=o,e[40]=ge):ge=e[40];let Ce,Re;e[41]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>T(!0),Re=()=>T(!1),e[41]=Ce,e[42]=Re):(Ce=e[41],Re=e[42]);const ce=E.length>0;let ye;e[43]===Symbol.for("react.memo_cache_sentinel")?(ye=Ie("h-6 w-full rounded-full border border-border/50 bg-[var(--surface-elevated)] px-3","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[43]=ye):ye=e[43];let be;e[44]!==I?(be=I("contextPanel.browser.addressAria"),e[44]=I,e[45]=be):be=e[45];let te;e[46]!==n||e[47]!==re||e[48]!==ge||e[49]!==ce||e[50]!==be?(te=s.jsx("input",{value:n,onChange:ge,onFocus:Ce,onBlur:Re,onKeyDown:re,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":ce,"aria-controls":"openchamber-browser-address-suggestions",className:ye,"aria-label":be}),e[46]=n,e[47]=re,e[48]=ge,e[49]=ce,e[50]=be,e[51]=te):te=e[51];let pe;e[52]!==i?(pe=Z=>i?.(Z),e[52]=i,e[53]=pe):pe=e[53];let Pe;e[54]!==_||e[55]!==Q||e[56]!==pe||e[57]!==E?(Pe=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(j1,{entries:E,activeIndex:_,onSelect:Q,onForget:pe,onHighlight:O})}),e[54]=_,e[55]=Q,e[56]=pe,e[57]=E,e[58]=Pe):Pe=e[58];let de;e[59]!==xe||e[60]!==te||e[61]!==Pe?(de=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:xe,children:[te,Pe]}),e[59]=xe,e[60]=te,e[61]=Pe,e[62]=de):de=e[62];let he;e[63]!==x||e[64]!==p||e[65]!==w||e[66]!==I||e[67]!==z?(he=p&&x?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(ln,{icon:"subtract",label:I("contextPanel.browser.zoomOut"),onClick:p}),z!==100&&w?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsxs(at,{type:"button",variant:"ghost",size:"xs",className:"shrink-0 rounded-full px-1.5 typography-micro tabular-nums text-muted-foreground",onClick:w,"aria-label":I("contextPanel.browser.zoomReset"),children:[z,"%"]})}),s.jsx(xt,{sideOffset:6,children:I("contextPanel.browser.zoomReset")})]}):null,s.jsx(ln,{icon:"add",label:I("contextPanel.browser.zoomIn"),onClick:x})]}):null,e[63]=x,e[64]=p,e[65]=w,e[66]=I,e[67]=z,e[68]=he):he=e[68];let fe;e[69]!==C||e[70]!==I?(fe=C?s.jsx(ln,{icon:"delete-bin",label:I("contextPanel.browser.clearCookies"),onClick:C}):null,e[69]=C,e[70]=I,e[71]=fe):fe=e[71];let B;e[72]!==k||e[73]!==I?(B=k?s.jsx(ln,{icon:"database-2",label:I("contextPanel.browser.clearCache"),onClick:k}):null,e[72]=k,e[73]=I,e[74]=B):B=e[74];let H;e[75]!==D||e[76]!==A||e[77]!==I?(H=A?s.jsx(ln,{icon:"smartphone",label:I("contextPanel.browser.deviceToolbar"),onClick:A,pressed:D}):null,e[75]=D,e[76]=A,e[77]=I,e[78]=H):H=e[78];let ke;e[79]!==g||e[80]!==S||e[81]!==I?(ke=S?s.jsx(ln,{icon:"markup",label:I("contextPanel.browser.annotate.toggle"),onClick:S,pressed:g}):null,e[79]=g,e[80]=S,e[81]=I,e[82]=ke):ke=e[82];let Se;e[83]!==v||e[84]!==I?(Se=v?s.jsx(ln,{icon:"terminal-box",label:I("contextPanel.browser.devTools"),onClick:v}):null,e[83]=v,e[84]=I,e[85]=Se):Se=e[85];let Be;e[86]!==I?(Be=I("contextPanel.browser.openExternal"),e[86]=I,e[87]=Be):Be=e[87];let _e;e[88]!==m||e[89]!==Be?(_e=s.jsx(ln,{icon:"external-link",label:Be,onClick:m}),e[88]=m,e[89]=Be,e[90]=_e):_e=e[90];let Te;return e[91]!==ue||e[92]!==Y||e[93]!==J||e[94]!==ie||e[95]!==de||e[96]!==he||e[97]!==fe||e[98]!==B||e[99]!==H||e[100]!==ke||e[101]!==Se||e[102]!==_e?(Te=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[ue,Y,J,ie,de,he,fe,B,H,ke,Se,_e]}),e[91]=ue,e[92]=Y,e[93]=J,e[94]=ie,e[95]=de,e[96]=he,e[97]=fe,e[98]=B,e[99]=H,e[100]=ke,e[101]=Se,e[102]=_e,e[103]=Te):Te=e[103],Te},Ho={kind:"fill"},sc=240,k1=3840,Xu=[{id:"iphone-se",label:"iPhone SE",width:375,height:667},{id:"iphone-14",label:"iPhone 14",width:390,height:844},{id:"iphone-14-pro-max",label:"iPhone 14 Pro Max",width:430,height:932},{id:"pixel-7",label:"Pixel 7",width:412,height:915},{id:"ipad-mini",label:"iPad mini",width:768,height:1024},{id:"ipad-pro",label:"iPad Pro",width:1024,height:1366},{id:"laptop",label:"Laptop",width:1280,height:800},{id:"desktop",label:"Desktop",width:1440,height:900}],nc=t=>Number.isFinite(t)?Math.round(Math.min(k1,Math.max(sc,t))):sc,Ko=t=>t.kind==="fill"?null:{width:t.width,height:t.height},Ju=t=>{const e=Xu.find(n=>n.id===t);return e?{kind:"preset",id:e.id,width:e.width,height:e.height}:null},C1=t=>t.kind==="fill"?t:{kind:"custom",width:t.height,height:t.width},N1=(t,e)=>{const n=Ko(t);if(!n)return null;const r=Math.max(1,e.width),i=Math.max(1,e.height),o=Math.min(1,r/n.width,i/n.height);return{width:n.width,height:n.height,scale:o}},A1=["mobile","tablet","desktop","fill"],D1={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},rc=t=>typeof t=="string"&&A1.includes(t),na=t=>t==="fill"?Ho:Ju(D1[t])??Ho,po=t=>{const e=Ko(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=na(n),i=Ko(r);if(i&&i.width===e.width&&i.height===e.height)return{mode:n,width:e.width,height:e.height}}return{mode:"custom",width:e.width,height:e.height}},P1=t=>{const e=Ye.c(70),{viewport:n,onViewportChange:r,colorScheme:i,onColorSchemeChange:o,scale:l}=t,{t:a}=ht();let d;e[0]!==n?(d=Ko(n),e[0]=n,e[1]=d):d=e[1];const u=d,m=n.kind==="preset"?n.id:"";let h;e[2]!==r||e[3]!==u?(h=(ee,ue)=>{const W=Number.parseInt(ue,10);if(!Number.isFinite(W))return;const ne=u??{width:1280,height:800};r({kind:"custom",width:nc(ee==="width"?W:ne.width),height:nc(ee==="height"?W:ne.height)})},e[2]=r,e[3]=u,e[4]=h):h=e[4];const y=h;let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=Ie("h-6 w-14 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2 text-center","typography-micro tabular-nums text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[5]=b):b=e[5];const S=b;let v;e[6]!==r?(v=ee=>{const ue=Ju(ee.target.value);r(ue??Ho)},e[6]=r,e[7]=v):v=e[7];let g;e[8]!==a?(g=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=g):g=e[9];let f;e[10]===Symbol.for("react.memo_cache_sentinel")?(f=Ie("h-6 shrink-0 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[10]=f):f=e[10];let x;e[11]!==a?(x=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=x):x=e[12];let p;e[13]!==x?(p=s.jsx("option",{value:"",children:x}),e[13]=x,e[14]=p):p=e[14];let w;e[15]===Symbol.for("react.memo_cache_sentinel")?(w=Xu.map(T1),e[15]=w):w=e[15];let N;e[16]!==m||e[17]!==v||e[18]!==g||e[19]!==p?(N=s.jsxs("select",{value:m,onChange:v,"aria-label":g,className:f,children:[p,w]}),e[16]=m,e[17]=v,e[18]=g,e[19]=p,e[20]=N):N=e[20];const C=u?String(u.width):"";let k;e[21]!==y?(k=ee=>y("width",ee.target.value),e[21]=y,e[22]=k):k=e[22];let A;e[23]!==a?(A=a("contextPanel.browser.device.width"),e[23]=a,e[24]=A):A=e[24];let D;e[25]!==C||e[26]!==k||e[27]!==A?(D=s.jsx("input",{value:C,onChange:k,placeholder:"—",inputMode:"numeric","aria-label":A,className:S}),e[25]=C,e[26]=k,e[27]=A,e[28]=D):D=e[28];let P;e[29]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=P):P=e[29];const M=u?String(u.height):"";let z;e[30]!==y?(z=ee=>y("height",ee.target.value),e[30]=y,e[31]=z):z=e[31];let I;e[32]!==a?(I=a("contextPanel.browser.device.height"),e[32]=a,e[33]=I):I=e[33];let V;e[34]!==M||e[35]!==z||e[36]!==I?(V=s.jsx("input",{value:M,onChange:z,placeholder:"—",inputMode:"numeric","aria-label":I,className:S}),e[34]=M,e[35]=z,e[36]=I,e[37]=V):V=e[37];let T;e[38]!==r||e[39]!==n?(T=()=>r(C1(n)),e[38]=r,e[39]=n,e[40]=T):T=e[40];const _=!u;let O;e[41]!==a?(O=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=O):O=e[42];let j;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(R,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=j):j=e[43];let E;e[44]!==T||e[45]!==_||e[46]!==O?(E=s.jsx(bt,{asChild:!0,children:s.jsx(at,{type:"button",variant:"ghost",size:"xs",className:"w-6 shrink-0 rounded-full px-0 text-muted-foreground hover:text-foreground",onClick:T,disabled:_,"aria-label":O,children:j})}),e[44]=T,e[45]=_,e[46]=O,e[47]=E):E=e[47];let L;e[48]!==a?(L=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=L):L=e[49];let U;e[50]!==L?(U=s.jsx(xt,{sideOffset:6,children:L}),e[50]=L,e[51]=U):U=e[51];let X;e[52]!==E||e[53]!==U?(X=s.jsxs(yt,{children:[E,U]}),e[52]=E,e[53]=U,e[54]=X):X=e[54];let Q;e[55]!==l||e[56]!==u?(Q=u&&l<1?s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Math.round(l*100),"%"]}):null,e[55]=l,e[56]=u,e[57]=Q):Q=e[57];let me;e[58]===Symbol.for("react.memo_cache_sentinel")?(me=["system","light","dark"],e[58]=me):me=e[58];let re;e[59]!==i||e[60]!==o||e[61]!==a?(re=s.jsx("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:me.map(ee=>s.jsx(at,{type:"button",variant:i===ee?"secondary":"ghost",size:"xs",className:Ie("shrink-0 rounded-full px-2.5 typography-micro",i===ee?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>o(ee),"aria-pressed":i===ee,children:a(ee==="system"?"contextPanel.browser.device.schemeSystem":ee==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},ee))}),e[59]=i,e[60]=o,e[61]=a,e[62]=re):re=e[62];let G;return e[63]!==N||e[64]!==D||e[65]!==V||e[66]!==X||e[67]!==Q||e[68]!==re?(G=s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[N,D,P,V,X,Q,re]}),e[63]=N,e[64]=D,e[65]=V,e[66]=X,e[67]=Q,e[68]=re,e[69]=G):G=e[69],G};function T1(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const I1=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},E1=2e3,R1=()=>{if(typeof window>"u"||window.__OPENCHAMBER_ELECTRON__)return!1;const t=Ln();if(!t)return!1;try{return!jr(new URL(t,window.location.href).toString())}catch{return!1}},Zu=t=>{const e=Ye.c(33),{onOpen:n,directory:r}=t,i=r===void 0?"":r,{t:o}=ht();let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={kind:"loading"},e[0]=l):l=e[0];const[a,d]=c.useState(l),u=kb(i),[m]=c.useState(R1);let h,y;e[1]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{let D=!0,P=null;const M=new AbortController,z=()=>{ky(M.signal).then(I=>{D&&(d(I),P=setTimeout(z,E1))})};return z(),()=>{D=!1,P&&clearTimeout(P),M.abort()}},y=[],e[1]=h,e[2]=y):(h=e[1],y=e[2]),c.useEffect(h,y);const b=a.kind==="ready"?a.servers:null;let S;e[3]!==u||e[4]!==b?(S=Ay({announced:u,discovered:b}),e[3]=u,e[4]=b,e[5]=S):S=e[5];const v=S;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Cd,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=g):g=e[6];let f;e[7]!==o?(f=o("contextPanel.browser.empty"),e[7]=o,e[8]=f):f=e[8];let x;e[9]!==f?(x=s.jsx("span",{className:"typography-ui-header text-foreground",children:f}),e[9]=f,e[10]=x):x=e[10];let p;e[11]!==o?(p=o("contextPanel.browser.emptyHint"),e[11]=o,e[12]=p):p=e[12];let w;e[13]!==p?(w=s.jsx("span",{className:"typography-micro text-muted-foreground",children:p}),e[13]=p,e[14]=w):w=e[14];let N;e[15]!==w||e[16]!==x?(N=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[x,w]}),e[15]=w,e[16]=x,e[17]=N):N=e[17];let C;e[18]!==u||e[19]!==v||e[20]!==i||e[21]!==n||e[22]!==m||e[23]!==o?(C=v.length>0?s.jsxs("div",{className:"flex min-h-0 w-full max-w-sm flex-col gap-1",children:[s.jsx("span",{className:"shrink-0 typography-micro text-left text-muted-foreground",children:u.length>0?o("contextPanel.browser.devServers.justStarted"):o("contextPanel.browser.devServers.title")}),m?s.jsx("span",{className:"shrink-0 pb-1 text-left typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.remoteOnly")}):null,s.jsx("div",{className:"flex min-h-0 flex-col gap-1 overflow-y-auto pr-0.5",children:v.map(D=>s.jsxs(at,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{Sb(i),n(D.url)},children:[s.jsx(R,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:Ua(D.url)||D.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:I1(D.url)})]},D.port))})]}):null,e[18]=u,e[19]=v,e[20]=i,e[21]=n,e[22]=m,e[23]=o,e[24]=C):C=e[24];let k;e[25]!==v.length||e[26]!==a.kind||e[27]!==o?(k=v.length===0&&a.kind==="unavailable"?s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("contextPanel.browser.devServers.unavailable")}):null,e[25]=v.length,e[26]=a.kind,e[27]=o,e[28]=k):k=e[28];let A;return e[29]!==N||e[30]!==C||e[31]!==k?(A=s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-5 overflow-hidden bg-background p-6 text-center",children:[g,N,C,k]}),e[29]=N,e[30]=C,e[31]=k,e[32]=A):A=e[32],A},Vs=t=>Math.round(t),M1=(t,e)=>{const n=t.text.trim(),r=Object.entries(t.attributes).map(([a,d])=>`${a}="${d}"`).join(" "),i=t.ancestry.map(a=>a.selectorPart).join(" > "),o=t.computedStyle,l=t.bounds;return[`Element ${e+1}: ${t.tag}`,n?`- Text: ${n}`:null,`- Selector: ${t.selector}`,`- Path: ${t.path}`,i?`- Ancestry: ${i}`:null,r?`- Attributes: ${r}`:null,`- Bounds: x=${Vs(l.x)}, y=${Vs(l.y)}, width=${Vs(l.width)}, height=${Vs(l.height)}`,`- Styles: display=${o.display??""}; position=${o.position??""}; font=${o.fontWeight??""} ${o.fontSize??""} / ${o.lineHeight??""} ${o.fontFamily??""}; color=${o.color??""}; background=${o.backgroundColor??""}`].filter(a=>typeof a=="string")},O1=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Vs(n.x)}, y=${Vs(n.y)}, width=${Vs(n.width)}, height=${Vs(n.height)}`},B1=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Vs(n.x)}, y=${Vs(n.y)}, width=${Vs(n.width)}, height=${Vs(n.height)}`},F1=({payload:t,screenshotAttached:e,intro:n})=>{const r=n.replace(/[.:]+$/g,""),i=t.comment.trim(),o=[`${r}:`,`Page: ${t.pageTitle.trim()||t.pageUrl||"browser"}`,t.pageTitle.trim()&&t.pageUrl?`URL: ${t.pageUrl}`:null,`Viewport: ${Vs(t.viewport.width)}x${Vs(t.viewport.height)}, DPR ${t.devicePixelRatio}`,`Screenshot: ${e?"attached":"not attached"}`,i?`Comment: ${i}`:null];for(const[l,a]of t.elements.entries())o.push("",...M1(a.element,l));return t.regions.length>0&&(o.push(""),t.regions.forEach((l,a)=>o.push(O1(l,a)))),t.strokes.length>0&&(o.push(""),t.strokes.forEach((l,a)=>o.push(B1(l,a)))),o.filter(l=>typeof l=="string").join(`
|
|
910
|
-
`)},_1=t=>{const e=Ye.c(7),{t:n}=ht(),r=qe($1),i=qe(W1),o=Ei(z1),l=Rf(V1);let a;return e[0]!==l||e[1]!==o||e[2]!==r||e[3]!==t||e[4]!==i||e[5]!==n?(a=async d=>{const u=r??(i?"draft":null);if(!u){Oe.error(n("contextPanel.browser.annotate.noSession"));return}let m=!1;if(d.screenshot)try{await l(d.screenshot),m=!0}catch{m=!1}o({directory:t,sessionKey:u},{source:"preview-annotation",fileLabel:d.payload.pageUrl||"browser",startLine:1,endLine:1,code:F1({payload:d.payload,screenshotAttached:m,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),Oe.success(n("contextPanel.browser.annotate.attached"))},e[0]=l,e[1]=o,e[2]=r,e[3]=t,e[4]=i,e[5]=n,e[6]=a):a=e[6],a},L1=()=>{const t=Ye.c(16),{t:e}=ht();let n;t[0]!==e?(n=e("contextPanel.browser.annotate.tool.element"),t[0]=e,t[1]=n):n=t[1];let r;t[2]!==e?(r=e("contextPanel.browser.annotate.tool.region"),t[2]=e,t[3]=r):r=t[3];let i;t[4]!==e?(i=e("contextPanel.browser.annotate.tool.draw"),t[4]=e,t[5]=i):i=t[5];let o;t[6]!==e?(o=e("contextPanel.browser.annotate.commentPlaceholder"),t[6]=e,t[7]=o):o=t[7];let l;t[8]!==e?(l=e("contextPanel.browser.annotate.submit"),t[8]=e,t[9]=l):l=t[9];let a;return t[10]!==n||t[11]!==r||t[12]!==i||t[13]!==o||t[14]!==l?(a={select:n,marquee:r,draw:i,commentPlaceholder:o,submit:l},t[10]=n,t[11]=r,t[12]=i,t[13]=o,t[14]=l,t[15]=a):a=t[15],a};function $1(t){return t.currentSessionId}function W1(t){return t.newSessionDraft?.open}function z1(t){return t.addDraft}function V1(t){return t.addAttachedFile}const U1=3e4,H1=3,K1=250,G1={attempts:0,windowStartedAt:null},q1=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=U1,r=n?0:t.attempts;return r>=H1?null:{delayMs:K1*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},Q1=-3,go=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",fr=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},Y1=(t,{initialUrl:e,onUrlChange:n})=>{const[r,i]=c.useState(e?{kind:"loading",url:e}:Ty),[o,l]=c.useState(e),[a,d]=c.useState(""),[u,m]=c.useState(!1),[h,y]=c.useState(!1),b=c.useRef(n);b.current=n;const S=c.useRef(G1);return c.useEffect(()=>{if(!t)return;const v=()=>{try{const P=t.getURL();return go(P)?P:""}catch{return""}},g=()=>{try{m(t.canGoBack()),y(t.canGoForward())}catch{}},f=P=>{go(P)&&(l(P),b.current(P))},x=()=>{const P=v();i({kind:"loading",url:P})},p=()=>{const P=v();let M="";try{M=t.getTitle()||""}catch{M=""}d(M),f(P),g(),i(z=>z.kind==="failed"&&z.url===P?z:{kind:"ready",url:P,title:M})},w=P=>{const M=fr(P);go(M.url)&&(f(M.url),g())},N=P=>{const M=fr(P),z=Array.isArray(M.favicons)?M.favicons.find(Boolean):"",I=v();z&&I&&Fu.getState().resolve(I,z)},C=P=>{const M=fr(P);typeof M.title=="string"&&d(M.title)},k=P=>{const M=fr(P);if(M.isMainFrame===!1)return;const z=typeof M.errorCode=="number"?M.errorCode:0;z!==Q1&&i({kind:"failed",url:go(M.validatedURL)?M.validatedURL:v(),code:z,description:typeof M.errorDescription=="string"?M.errorDescription:""})};let A=null;const D=()=>{const P=v(),M=q1(S.current,Date.now());if(!M){i({kind:"failed",url:P,code:0,description:"",crashed:!0});return}S.current=M.state,i({kind:"loading",url:P}),A=setTimeout(()=>{A=null;try{t.reload()}catch{i({kind:"failed",url:P,code:0,description:"",crashed:!0})}},M.delayMs)};t.addEventListener("did-start-loading",x),t.addEventListener("did-stop-loading",p),t.addEventListener("did-navigate",w),t.addEventListener("did-navigate-in-page",w),t.addEventListener("page-title-updated",C),t.addEventListener("page-favicon-updated",N),t.addEventListener("did-fail-load",k),t.addEventListener("render-process-gone",D),t.addEventListener("crashed",D);try{!t.isLoading()&&v()&&p()}catch{}return()=>{A!==null&&clearTimeout(A),t.removeEventListener("render-process-gone",D),t.removeEventListener("crashed",D),t.removeEventListener("did-start-loading",x),t.removeEventListener("did-stop-loading",p),t.removeEventListener("did-navigate",w),t.removeEventListener("did-navigate-in-page",w),t.removeEventListener("page-title-updated",C),t.removeEventListener("page-favicon-updated",N),t.removeEventListener("did-fail-load",k)}},[t]),{status:r,url:o,title:a,canGoBack:u,canGoForward:h}},X1=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,J1=4e4,oc=.5,Z1=-3,ew=4,tw="persist:openchamber-browser",ic=20,sw=600,nw=2e4,rw=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ht(),{currentTheme:i}=nr(),o=c.useRef(null),[l,a]=c.useState(null),d=c.useCallback(de=>{o.current=de,a(de)},[]),u=Ae(de=>de.setContextPanelTabTargetPath),m=c.useRef(gr(t)),h=m.current!==cn?m.current:"",[y,b]=c.useState(h?null:cn),[S,v]=c.useState(h),[g,f]=c.useState(!1),[x,p]=c.useState(!1),[w,N]=c.useState(0),[C,k]=c.useState(!1),[A,D]=c.useState(Ho),P=c.useRef(A);P.current=A;const M=c.useRef([]),[z,I]=c.useState("system"),[V,T]=c.useState({width:0,height:0}),_=c.useRef(null),O=c.useRef(null),j=c.useRef(!1),E=c.useRef(Date.now()),L=c.useCallback(de=>{!de||de===cn||!e||!n||u(e,n,de)},[e,n,u]),U=Y1(l,{initialUrl:h,onUrlChange:c.useCallback(de=>{const he=Tr(de);v(he),L(he)},[L])}),[X,Q]=c.useState(null),me=_1(e),re=L1(),G=U.status.kind==="loading",ee=wr(Ku(e)),ue=wr(de=>de.recordVisit),W=wr(de=>de.forget);c.useEffect(()=>{U.status.kind==="ready"&&ue(e,{url:Tr(U.status.url),title:U.status.title})},[e,U.status,ue]);const ne=c.useMemo(()=>Hu(ee,S),[ee,S]),Y=c.useCallback(de=>{const he=gr(de);he!==cn&&(v(he),Q(null),Zl(he).then(fe=>{const B=o.current;if(!B){b(fe);return}try{B.loadURL(fe)}catch{b(fe)}}).catch(fe=>{fe instanceof $r&&Q(he)}))},[]);c.useEffect(()=>{if(!h)return;let de=!0;return Zl(h).then(he=>{de&&b(he)}).catch(he=>{if(de){if(he instanceof $r){Q(h),b(cn);return}b(h)}}),()=>{de=!1}},[]);const F=c.useMemo(()=>({executeJavaScript:async(de,he)=>{const fe=o.current;if(!fe)throw new Error("Browser view is not available");return fe.executeJavaScript(de,he)},capturePage:async()=>{const de=o.current;if(!de)return null;const he=de.getWebContentsId();return Number.isFinite(he)?await Fr("desktop_browser_capture_page",{webContentsId:he}):null}}),[]),J=c.useCallback(()=>{if(g){f(!1),Do(F);return}if(!U.url){Oe.error(r("contextPanel.browser.annotate.noPage"));return}const de=Uy(i.metadata.variant==="light"?"light":"dark");f(!0),zy({host:F,theme:de,labels:re}).then(async he=>{f(!1),he&&await me(he)}).catch(()=>{f(!1),Oe.error(r("contextPanel.browser.annotate.failed"))})},[F,me,i,g,U.url,re,r]);c.useEffect(()=>{if(!g)return;const de=he=>{he.key==="Escape"&&(he.preventDefault(),he.stopImmediatePropagation(),f(!1),Do(F))};return window.addEventListener("keydown",de,!0),()=>window.removeEventListener("keydown",de,!0)},[F,g]);const ie=c.useCallback(async(de=8e3)=>{const he=Date.now();for(;;){const fe=o.current;if(!fe)return!1;let B=!1;try{B=fe.isLoading()}catch{return!1}if(!B)return!0;if(Date.now()-he>de)return!1;await new Promise(H=>setTimeout(H,120))}},[]),xe=c.useCallback(async(de,he)=>{const fe=o.current;if(!fe)throw new Error("The browser panel is not ready");const B=()=>{rc(he.viewport)&&(D(na(he.viewport)),k(!0))};if(de==="browser.back"||de==="browser.forward"){const Te=de==="browser.back";if(!(Te?fe.canGoBack():fe.canGoForward()))throw new Error(Te?"There is nothing to go back to in this tab":"There is nothing to go forward to in this tab");Te?fe.goBack():fe.goForward(),await new Promise(Me=>setTimeout(Me,150)),await ie();let Ne="";try{Ne=fe.getTitle()||""}catch{Ne=""}return{url:Tr(fe.getURL()),title:Ne}}if(de==="browser.capture"){Ae.getState().openContextBrowser(e,fe.getURL());const Te=Date.now()+1200;let Z=0,Ne=0;for(;Ne<2&&Date.now()<Te;){const ae=fe.getBoundingClientRect().width;Ne=ae>=2&&Math.abs(ae-Z)<.5?Ne+1:0,Z=ae,await new Promise(se=>setTimeout(se,50))}await new Promise(ae=>{requestAnimationFrame(()=>requestAnimationFrame(()=>ae()))}),await ie();const Me=await F.capturePage();if(!Me)throw new Error("The page could not be captured");let $="";try{$=fe.getTitle()||""}catch{$=""}return{...Me,url:Tr(fe.getURL()),title:$,viewport:po(P.current)}}if(de==="browser.resize"){if(!rc(he.viewport))throw new Error("viewport is required");return B(),await new Promise(Te=>setTimeout(Te,200)),await ie(),{viewport:po(na(he.viewport))}}if(de==="browser.open"){const Te=typeof he.url=="string"?he.url:"";if(!Te)throw new Error("url is required");B(),Y(Te),await new Promise(Me=>setTimeout(Me,150));const Z=await ie(25e3);let Ne="";try{Ne=fe.getTitle()||""}catch{Ne=""}return{url:gr(Te),title:Ne,opened:!0,settled:Z,viewport:po(P.current)}}await ie();const H=Te=>typeof Te=="string"&&Te?Te:void 0,Se=(()=>{switch(de){case"browser.snapshot":return b1({selector:H(he.selector)});case"browser.click":return x1({selector:H(he.selector),text:H(he.text)});case"browser.type":return y1({selector:String(he.selector??""),value:String(he.value??""),submit:he.submit===!0});case"browser.inspect":return v1({selector:String(he.selector??"")});case"browser.scroll":return w1({selector:H(he.selector),direction:H(he.direction)});default:return null}})();if(!Se)throw new Error(`Unsupported browser action: ${de}`);const Be=await fe.executeJavaScript(Se,!0);if(!Be||typeof Be!="object")throw new Error("The page returned no result");const _e=Be;if(_e.ok!==!0)throw new Error(typeof _e.error=="string"&&_e.error?_e.error:"Browser action failed");if(de==="browser.snapshot"){const Te=M.current;return{..._e,viewport:po(P.current),...Te.length>0?{consoleProblems:[...Te]}:{}}}return(de==="browser.click"||de==="browser.type"&&he.submit===!0)&&(await new Promise(Te=>setTimeout(Te,150)),await ie()),Be},[F,e,Y,ie]);c.useEffect(()=>s1({run:xe}),[xe]),c.useEffect(()=>{const de=F;return()=>{Do(de)}},[F]),c.useEffect(()=>{if(!l)return;const de=fe=>{const B=fe;if(typeof B.level!="number"||B.level<2)return;const H=B.sourceId?`${B.sourceId}${B.line?`:${B.line}`:""}`:"";M.current.push({level:B.level>=3?"error":"warning",message:String(B.message??"").slice(0,400),source:H}),M.current.length>ic&&M.current.splice(0,M.current.length-ic)},he=()=>{M.current=[]};return l.addEventListener("console-message",de),l.addEventListener("did-start-loading",he),()=>{l.removeEventListener("console-message",de),l.removeEventListener("did-start-loading",he)}},[l]);const ge=c.useRef(new Set),Ce=c.useCallback(de=>{ge.current.clear(),Y(de)},[Y]);c.useEffect(()=>{if(!l)return;const de=fe=>{const B=fr(fe),H=typeof B.url=="string"?B.url:"";!H||!ec(H)||(fe.preventDefault(),Y(H))},he=fe=>{const B=fr(fe);if(B.isMainFrame===!1||B.errorCode===-3)return;const H=typeof B.validatedURL=="string"?B.validatedURL:"";!H||!ec(H)||ge.current.has(H)||(ge.current.add(H),Y(H))};return l.addEventListener("will-navigate",de),l.addEventListener("did-fail-load",he),()=>{l.removeEventListener("will-navigate",de),l.removeEventListener("did-fail-load",he)}},[Y,l]),c.useEffect(()=>{if(!l)return;const de=he=>{const fe=he.detail;he.preventDefault(),fe?.url&&Y(fe.url)};return l.addEventListener("new-window",de),()=>l.removeEventListener("new-window",de)},[Y,l]);const Re=c.useCallback(de=>{const he=Math.min(ew,Math.max(Z1,de));N(he);try{o.current?.setZoomLevel(he)}catch{}},[]),ce=c.useCallback(de=>{Fr("desktop_browser_clear_data",{partition:tw,cookies:de==="cookies",cache:de==="cache"}).then(()=>{Oe.success(r(de==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{o.current?.reloadIgnoringCache()}catch{}}).catch(()=>Oe.error(r("contextPanel.browser.clearFailed")))},[r]);c.useEffect(()=>{const de=_.current;if(!de||typeof ResizeObserver>"u")return;const he=new ResizeObserver(fe=>{const B=fe[0]?.contentRect;B&&T({width:B.width,height:B.height})});return he.observe(de),()=>he.disconnect()},[]);const ye=c.useCallback(de=>{I(de);const he=o.current;if(!he)return;let fe=-1;try{fe=he.getWebContentsId()}catch{return}Fr("desktop_browser_set_color_scheme",{webContentsId:fe,scheme:de}).catch(B=>{I("system"),Oe.error(B instanceof Error?B.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),be=c.useCallback(()=>{try{G?o.current?.stop():o.current?.reload()}catch{}},[G]),te=U.status;c.useEffect(()=>{const de=()=>{p(!0);const B=setTimeout(()=>{try{o.current?.reload()}catch{}},sw);return()=>clearTimeout(B)};if(te.kind==="failed"){if(!vy(te.code,te.url)){p(!1);return}const B=Date.now(),H=O.current?.url===te.url?O.current:{url:te.url,startedAt:B};if(O.current=H,B-H.startedAt>J1){p(!1);return}return de()}if(te.kind==="loading")return;if(O.current=null,te.kind!=="ready"||!te.url||!jr(te.url)){j.current=!0,p(!1);return}if(j.current||Date.now()-E.current>nw){j.current=!0,p(!1);return}let he=!1,fe=null;return Cy(Tr(te.url)).then(B=>{if(!he){if(B===null||B<500){j.current=!0,p(!1);return}fe=de()}}),()=>{he=!0,fe?.()}},[te]);const pe=U.status.kind==="failed"&&!x?U.status:null,Pe=N1(A,V);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(Yu,{address:S,onAddressChange:v,onSubmit:Ce,suggestions:ne,onForgetSuggestion:de=>W(e,de),onBack:()=>{try{o.current?.goBack()}catch{}},onForward:()=>{try{o.current?.goForward()}catch{}},onReload:be,onOpenExternal:()=>{si(U.url||S)},canGoBack:U.canGoBack,canGoForward:U.canGoForward,isLoading:G,onAnnotate:J,isAnnotating:g,onOpenDevTools:()=>{try{o.current?.openDevTools()}catch{}},onHardReload:()=>{try{o.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>Re(w+oc),onZoomOut:()=>Re(w-oc),onZoomReset:()=>Re(0),zoomPercent:Math.round(Math.pow(1.2,w)*100),onClearCookies:()=>ce("cookies"),onClearCache:()=>ce("cache"),onToggleDeviceBar:()=>k(de=>!de),isDeviceBarOpen:C}),C?s.jsx(P1,{viewport:A,onViewportChange:D,colorScheme:z,onColorSchemeChange:ye,scale:Pe?.scale??1}):null,s.jsxs("div",{ref:_,className:Ie("relative min-h-0 flex-1 bg-background",Pe&&"flex items-center justify-center overflow-hidden bg-[var(--surface-muted)]"),children:[y!==null?s.jsx("webview",{ref:d,src:y,partition:"persist:openchamber-browser",allowpopups:!0,style:Pe?{width:`${Pe.width}px`,height:`${Pe.height}px`,transform:`scale(${Pe.scale})`,border:"none",flex:"none",boxShadow:"0 2px 18px rgba(0,0,0,.28)"}:{width:"100%",height:"100%",border:"none"}}):null,y!==null&&!h&&!U.url&&!G?s.jsx(Zu,{onOpen:Ce,directory:e}):null,x?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.waitingForServer")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.waitingForServerHint")})]}):null,X?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.tunnelFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.tunnelFailedHint",{url:X})})]}):null,pe&&!X?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:pe.crashed?r("contextPanel.browser.crashed"):r("contextPanel.browser.loadFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:pe.crashed?r("contextPanel.browser.crashedHint"):pe.description||r("contextPanel.browser.loadFailedUnknown")})]}):null,G?s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-0.5 overflow-hidden",children:s.jsx("div",{className:"h-full w-1/3 animate-[browser-progress_1.1s_ease-in-out_infinite] bg-[var(--primary)]"})}):null]})]})},ow=t=>{const e=Ye.c(49),{initialUrl:n,directory:r,tabID:i}=t,{t:o}=ht(),l=Ae(aw);let a;e[0]!==n?(a=gr(n),e[0]=n,e[1]=a):a=e[1];const d=a,u=d!==cn?d:"",[m,h]=c.useState(u),[y,b]=c.useState(u);let S;e[2]!==u?(S=u?[u]:[],e[2]=u,e[3]=S):S=e[3];const[v,g]=c.useState(S),[f,x]=c.useState(u?0:-1),[p,w]=c.useReducer(lw,0);let N;e[4]!==r||e[5]!==l||e[6]!==i?(N=G=>{!G||G===cn||!r||!i||l(r,i,G)},e[4]=r,e[5]=l,e[6]=i,e[7]=N):N=e[7];const C=N;let k;e[8]!==r?(k=Ku(r),e[8]=r,e[9]=k):k=e[9];const A=wr(k),D=wr(cw),P=wr(dw);let M;e[10]!==m||e[11]!==A?(M=Hu(A,m),e[10]=m,e[11]=A,e[12]=M):M=e[12];const z=M;let I;e[13]!==r||e[14]!==f||e[15]!==C||e[16]!==D?(I=G=>{const ee=gr(G);ee!==cn&&(h(ee),b(ee),C(ee),D(r,{url:ee}),g(ue=>{const W=f>=0?ue.slice(0,f+1):[];return W[W.length-1]===ee?(x(W.length-1),W):(x(W.length),[...W,ee])}))},e[13]=r,e[14]=f,e[15]=C,e[16]=D,e[17]=I):I=e[17];const V=I;let T;e[18]!==v||e[19]!==C?(T=G=>{const ee=v[G];ee&&(x(G),h(ee),b(ee),C(ee))},e[18]=v,e[19]=C,e[20]=T):T=e[20];const _=T;let O;e[21]!==r||e[22]!==P?(O=G=>P(r,G),e[21]=r,e[22]=P,e[23]=O):O=e[23];let j,E;e[24]!==_||e[25]!==f?(E=()=>_(f-1),j=()=>_(f+1),e[24]=_,e[25]=f,e[26]=j,e[27]=E):(j=e[26],E=e[27]);let L;e[28]!==m||e[29]!==y?(L=()=>{si(y||m)},e[28]=m,e[29]=y,e[30]=L):L=e[30];const U=f>0,X=f>=0&&f<v.length-1;let Q;e[31]!==m||e[32]!==V||e[33]!==z||e[34]!==j||e[35]!==L||e[36]!==U||e[37]!==X||e[38]!==O||e[39]!==E?(Q=s.jsx(Yu,{address:m,onAddressChange:h,onSubmit:V,suggestions:z,onForgetSuggestion:O,onBack:E,onForward:j,onReload:w,onOpenExternal:L,canGoBack:U,canGoForward:X,isLoading:!1}),e[31]=m,e[32]=V,e[33]=z,e[34]=j,e[35]=L,e[36]=U,e[37]=X,e[38]=O,e[39]=E,e[40]=Q):Q=e[40];let me;e[41]!==y||e[42]!==V||e[43]!==p||e[44]!==o?(me=s.jsx("div",{className:"relative min-h-0 flex-1 bg-background",children:y?s.jsx("iframe",{src:y,title:o("contextPanel.browser.frameTitle"),className:"h-full w-full border-none bg-white",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups"},`${y}|${p}`):s.jsx(Zu,{onOpen:V})}),e[41]=y,e[42]=V,e[43]=p,e[44]=o,e[45]=me):me=e[45];let re;return e[46]!==Q||e[47]!==me?(re=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Q,me]}),e[46]=Q,e[47]=me,e[48]=re):re=e[48],re},iw=t=>{const e=Ye.c(3),[n]=c.useState(X1);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(rw,{...t}):s.jsx(ow,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function aw(t){return t.setContextPanelTabTargetPath}function lw(t){return t+1}function cw(t){return t.recordVisit}function dw(t){return t.forget}const uw=rr(()=>sr(()=>import("./WalkthroughView-MuJodAHD.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123])).then(t=>({default:t.WalkthroughView}))),mw=rr(()=>sr(()=>import("./DiffView-Db6bjVv1.js"),__vite__mapDeps([124,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123])).then(t=>({default:t.DiffView}))),fw=rr(()=>sr(()=>import("./FilesView-DQOa7Lgz.js"),__vite__mapDeps([125,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,126,127,128,129,130,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,131,132,117,118,114,121,133,115,134])).then(t=>({default:t.FilesView}))),hw=rr(()=>sr(()=>import("./GitView-CHzJxTi0.js"),__vite__mapDeps([135,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,116,136,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,117,118,120,121,122,123])).then(t=>({default:t.GitView}))),pw=rr(()=>sr(()=>import("./PlanView-PkiOY_9H.js"),__vite__mapDeps([137,1,2,4,5,6,7,8,9,126,57,58,59,60,61,62,79,55,56,63,127,128,129,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,80,81,82,115,116,134,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100])).then(t=>({default:t.PlanView}))),gw=380,bw=1400,em=600,xw=100,yw=24,Go=new Map,ww=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},ac=t=>Number.isFinite(t)?Math.min(bw,Math.max(gw,Math.round(t))):em,Sw=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},vw=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},tm=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),jw=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},kw=(t,e,n)=>{if(t.mode==="chat"){const r=ra(t.dedupeKey);if(r){const o=e.get(r)?.trim();if(o)return o}const i=t.sessionTitleFallback?.trim();return i||n("contextPanel.mode.chat")}return t.mode==="browser"?Ua(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?jw(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):tm(t.mode,n)},lc=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(Na,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(Au,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(R,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(R,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(R,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(R,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(R,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(R,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(R,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(R,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="browser"){const n=Cw(t.targetPath??"",e);return n?s.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"h-3.5 w-3.5 rounded-[3px] object-contain"}):s.jsx(R,{name:"global",className:"h-3.5 w-3.5"})}},Cw=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},Nw=200,Aw=480,Dw=({visible:t})=>{const{t:e}=ht(),n=Ae(f=>f.contextEditorTreeWidth),r=Ae(f=>f.setContextEditorTreeWidth),[i,o]=c.useState(!1),l=c.useRef(0),a=c.useRef(n),d=c.useRef(null),u=c.useRef(null),m=c.useRef(null),h=c.useCallback(f=>Math.min(Aw,Math.max(Nw,Math.round(f))),[]),y=c.useCallback(f=>{const x=m.current;x&&(x.style.width=`${f}px`,x.style.setProperty("--oc-editor-tree-width",`${f}px`))},[]),b=f=>{if(t){try{f.currentTarget.setPointerCapture(f.pointerId)}catch{}u.current=f.pointerId,o(!0),l.current=f.clientX,a.current=n,d.current=n,f.preventDefault()}},S=f=>{if(!i||u.current!==f.pointerId)return;const x=l.current-f.clientX,p=h(a.current+x);d.current!==p&&(d.current=p,y(p))},v=f=>{if(u.current!==f.pointerId)return;try{f.currentTarget.releasePointerCapture(f.pointerId)}catch{}const x=h(d.current??n);u.current=null,d.current=null,o(!1),r(x)},g=t?n:0;return s.jsxs("div",{ref:m,className:Ie("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${i?d.current??g:g}px`,"--oc-editor-tree-width":`${i?d.current??n:n}px`,overflowX:"clip",transitionProperty:i?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:Ie("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",i&&"bg-[var(--interactive-border)]"),onPointerDown:b,onPointerMove:S,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:Ie("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",i&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(Hx,{})})]})},ra=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Pw=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},Tw=(t,e)=>{if(e.length===0)return Go;const n=new Set(e),r=new Map;for(const i of t){if(!n.has(i.id))continue;const o=i.title?.trim();o&&r.set(i.id,o)}return r.size===0?Go:r},Iw=(t,e)=>{const n=wd(t),r=c.useRef(Go),i=c.useRef(e);return i.current=e,c.useSyncExternalStore(n.subscribe,c.useCallback(()=>{const o=Tw(n.getState().session,i.current);return Pw(r.current,o)?r.current:(r.current=o,o)},[n]),()=>Go)},Ew=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Rw=()=>{const{t}=ht(),e=to()??"",n=c.useMemo(()=>ww(e),[e]),r=Ae(le=>n?le.contextPanelByDirectory[n]:void 0),i=Ae(le=>le.closeContextPanel),o=Ae(le=>le.closeContextPanelTab),l=Ae(le=>le.openContextPanelTab),a=Ae(le=>le.toggleContextPanelExpanded),d=Ae(le=>le.setContextPanelWidth),u=Ae(le=>le.setActiveContextPanelTab),m=Ae(le=>le.openContextBrowser);c.useEffect(()=>{if(e)return n1(le=>m(e,le))},[e,m]);const h=Ae(le=>le.reorderContextPanelTabs),y=pn(le=>le.setSelectedPath),b=Ae(le=>le.contextEditorTreeVisible),S=Ae(le=>le.toggleContextEditorTree),v=Ae(le=>le.openNewContextBrowserTab),g=Fu(le=>le.byOrigin),f=Ae(le=>le.allowPromptingSubagentSessions),{themeMode:x,setThemeMode:p,lightThemeId:w,darkThemeId:N,currentTheme:C}=nr(),k=c.useMemo(()=>r?.tabs??[],[r?.tabs]),A=k.find(le=>le.id===r?.activeTabId)??k[k.length-1]??null,D=!!(r?.isOpen&&A),P=!!(D&&r?.expanded),[M,z]=c.useState(null),I=A?.mode??null,V=I?r?.widthByMode?.[I]:void 0,T=I?Mf(I):.5,_=M??(typeof window<"u"?window.innerWidth:em*2),O=ac(V??Math.round(T*_)),j=c.useMemo(()=>{const le=[];for(const K of k){if(K.mode!=="chat")continue;const ve=ra(K.dedupeKey);ve&&!le.includes(ve)&&le.push(ve)}return le},[k]),E=Iw(n||void 0,j),[L,U]=c.useState(!1),X=c.useRef(0),Q=c.useRef(O),me=c.useRef(null),re=c.useRef(null),G=c.useRef(null),ee=c.useRef(new Map),ue=c.useRef(new Map),W=c.useRef(!1);c.useLayoutEffect(()=>{const le=G.current?.parentElement;if(!le||typeof ResizeObserver>"u")return;const K=new ResizeObserver(()=>{z(le.clientWidth||null)});return K.observe(le),z(le.clientWidth||null),()=>K.disconnect()},[]),c.useEffect(()=>{if(!D||W.current){W.current=D;return}const le=window.requestAnimationFrame(()=>{G.current?.focus({preventScroll:!0})});return W.current=!0,()=>window.cancelAnimationFrame(le)},[D]);const ne=c.useRef(null),Y=c.useRef(null),F=c.useCallback(()=>{Y.current=null;const le=G.current,K=me.current;!le||K===null||le.style.setProperty("--oc-context-panel-width",`${K}px`)},[]);c.useEffect(()=>()=>{Y.current!==null&&clearTimeout(Y.current)},[]);const J=c.useCallback(le=>{const K=ac(le),ve=ne.current;return ve===null?K:Math.min(K,Math.max(1,ve))},[]),ie=c.useCallback(le=>{!D||P||!n||(re.current=le.pointerId,U(!0),X.current=le.clientX,Q.current=O,me.current=O,ne.current=Sw(G.current),document.documentElement.style.cursor="col-resize",le.preventDefault())},[n,P,D,O]),xe=c.useCallback(()=>{const le=J(me.current??O);me.current=null,ne.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),document.documentElement.style.cursor="",n&&I&&d(n,I,le),U(!1),re.current=null},[I,J,n,d,O]);c.useEffect(()=>{if(!L)return;const le=$e=>{if(re.current!==$e.pointerId)return;const We=X.current-$e.clientX,Le=J(Q.current+We);me.current!==Le&&(me.current=Le,Y.current===null&&(Y.current=setTimeout(F,xw)))},K=$e=>{re.current===$e.pointerId&&xe()},ve=()=>{xe()};return window.addEventListener("pointermove",le),window.addEventListener("pointerup",K),window.addEventListener("pointercancel",K),window.addEventListener("blur",ve),()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",K),window.removeEventListener("pointercancel",K),window.removeEventListener("blur",ve)}},[F,J,xe,L]),c.useEffect(()=>{L||(me.current=null,document.documentElement.style.cursor="")},[L]);const ge=c.useCallback(()=>{n&&i(n)},[i,n]),Ce=c.useCallback(()=>{n&&a(n)},[n,a]),Re=c.useCallback(le=>{le.key==="Escape"&&(Of(le.target)||(le.preventDefault(),le.stopPropagation(),ge()))},[ge]);c.useEffect(()=>{if(!(!n||!A)&&A.mode==="file"&&A.targetPath){y(n,A.targetPath,{allowOutsideRoot:!0});return}},[A,n,y]);const ce=c.useMemo(()=>k.filter(le=>le.mode==="chat"),[k]),ye=D&&A?.mode==="chat"?A.id:null,be=D&&A?.mode==="chat"?ra(A.dedupeKey):null,te=fg(ce,ye);c.useEffect(()=>{if(!D||!n||!be||typeof window>"u")return;const le=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){ui(n,be,!1);return}Nd(be),ui(n,be,!0)};le();const K=window.setInterval(le,1e4);return window.addEventListener("focus",le),window.addEventListener("blur",le),document.addEventListener("visibilitychange",le),()=>{window.clearInterval(K),window.removeEventListener("focus",le),window.removeEventListener("blur",le),document.removeEventListener("visibilitychange",le),ui(n,be,!1)}},[be,n,D]);const pe=c.useCallback((le,K,ve)=>hg(ue.current,le,K,n||null,ve,{mode:x,lightThemeId:w,darkThemeId:N,currentTheme:C},{allowPromptingSubagentSessions:f}),[f,C,N,n,w,x]),Pe=te&&be?pe(te.id,be,te.readOnly):null;c.useEffect(()=>{const le=new Set(k.map(K=>K.id));for(const K of ue.current.keys())le.has(K)||ue.current.delete(K)},[k]);const de=c.useCallback(le=>{!n||A?.mode!=="diff"||l(n,{mode:"diff",targetPath:A.targetPath,stagedDiff:le==="staged",diffScope:le})},[A,n,l]),he=c.useCallback(()=>{if(typeof window>"u")return;const le={themeMode:x,lightThemeId:w,darkThemeId:N,currentTheme:C};for(const K of ee.current.values()){const ve=K.contentWindow;ve&&ve.postMessage({type:"openchamber:theme-sync",payload:le},window.location.origin)}},[C,N,w,x]),fe=c.useCallback(()=>{if(typeof window>"u")return;const le={allowPromptingSubagentSessions:f};for(const K of ee.current.values()){const ve=K.contentWindow;ve&&ve.postMessage({type:"openchamber:chat-settings-sync",payload:le},window.location.origin)}},[f]),B=c.useCallback((le,K,ve)=>{const $e=K.contentWindow;$e&&$e.postMessage({type:du,payload:{visible:ye===le}},ve)},[ye]),H=c.useCallback(()=>{if(!(typeof window>"u"))for(const[le,K]of ee.current.entries())B(le,K,window.location.origin)},[B]);c.useEffect(()=>{if(typeof window>"u")return;const le=K=>{if(K.origin!==window.location.origin)return;const ve=Array.from(ee.current.entries()).find(([,Ge])=>Ge.contentWindow===K.source);if(!ve)return;const $e=K.data;if($e?.type===pg){const[Ge,rt]=ve;B(Ge,rt,K.origin);return}if($e?.type===gg){if(typeof $e.requestId!="string"||!$e.requestId)return;const Ge=Cs(),rt={apiBaseUrl:Ln(),clientToken:zr(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:dd(),relayHostId:Ge.startsWith("host:")?Ge.slice(5):"",relay:$m()??void 0};K.source?.postMessage({type:bg,requestId:$e.requestId,payload:rt},K.origin);return}if($e?.type==="openchamber:theme-sync-request"){he();return}if($e?.type==="openchamber:chat-settings-request"){fe();return}if($e?.type!=="openchamber:cycle-theme-request")return;const We=["light","dark","system"],Fe=(We.indexOf(x)+1)%We.length;p(We[Fe])};return window.addEventListener("message",le),()=>window.removeEventListener("message",le)},[fe,B,he,p,x]),c.useLayoutEffect(()=>{k.some(K=>K.mode==="chat")&&(he(),fe(),H())},[N,w,fe,H,he,k,x]);const ke=A?.mode==="file"||A?.mode==="chat"||A?.mode==="browser",Se=c.useMemo(()=>A?k.filter(le=>le.mode===A.mode):[],[A,k]),Be=c.useMemo(()=>Se.map(le=>{const K=kw(le,E,t),ve=Ew(K,yw),$e=vw(le.targetPath,e);return{id:le.id,label:ve,icon:lc(le,g),title:$e?`${K}: ${$e}`:K,closeLabel:t("contextPanel.tab.closeTabAria",{label:ve})}}),[Se,e,g,E,t]),_e=A?.mode==="context"?s.jsx(ly,{}):A?.mode==="git"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(hw,{isActive:D})}):A?.mode==="pr"?s.jsx(bx,{}):A?.mode==="notes"?s.jsx(Rp,{}):A?.mode==="plan"?s.jsx(c.Suspense,{fallback:null,children:s.jsx(pw,{targetPath:A.targetPath,savedProjectPlan:A.projectPlanId&&A.projectPlanRef?{projectRef:A.projectPlanRef,planId:A.projectPlanId}:null})}):null,Te=c.useMemo(()=>k.filter(le=>le.mode==="browser"),[k]),Z=c.useMemo(()=>k.filter(le=>le.mode==="diff"),[k]),Ne=c.useMemo(()=>k.some(le=>le.mode==="terminal"),[k]),Me=c.useMemo(()=>k.some(le=>le.mode==="walkthrough"),[k]),$=c.useMemo(()=>k.some(le=>le.mode==="file"),[k]),ae=c.useMemo(()=>k.some(le=>le.mode==="file"&&le.targetPath),[k]),se=A?.mode==="file",we=Ae(le=>le.closeContextPanelTabs),Ke=c.useCallback(le=>{if(!n)return null;const{id:K,index:ve,allIds:$e,close:We}=le,Le=()=>we(n,$e.filter(Pt=>Pt!==K)),Fe=()=>we(n,$e.slice(0,ve)),Ge=()=>we(n,$e.slice(ve+1)),rt=()=>we(n,$e),St=$e.length>1,Rt=ve===0,ze=ve===$e.length-1;return s.jsxs(s.Fragment,{children:[s.jsxs(qn,{onClick:We,children:[s.jsx(R,{name:"close",className:"mr-2 size-4"}),t("contextPanel.tab.menu.close")]}),s.jsx($i,{}),s.jsxs(qn,{onClick:Le,disabled:!St,children:[s.jsx(R,{name:"expand-horizontal",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeOthers")]}),s.jsxs(qn,{onClick:Fe,disabled:Rt,children:[s.jsx(R,{name:"expand-left",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToLeft")]}),s.jsxs(qn,{onClick:Ge,disabled:ze,children:[s.jsx(R,{name:"expand-right",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeToRight")]}),s.jsx($i,{}),s.jsxs(qn,{onClick:rt,disabled:!St,children:[s.jsx(R,{name:"close-circle",className:"mr-2 size-4"}),t("contextPanel.tab.menu.closeAll")]})]})},[we,n,t]),Qe=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[ke?s.jsx(Qd,{items:Be,activeId:A?.id??null,onSelect:le=>{n&&u(n,le)},onClose:le=>{n&&o(n,le)},onReorder:(le,K)=>{n&&h(n,le,K)},layoutMode:"scrollable",variant:"default",tabContextMenu:Ke}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[A?lc(A,g):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:A?tm(A.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[A?.mode==="browser"?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&v(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})}):null,se?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:S,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":b,children:s.jsx(R,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:Ce,className:"h-7 w-7 p-0",title:t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:P?s.jsx(R,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:ge,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})]}),He=D?P?{"--oc-context-panel-width":M!==null?`${M}px`:"100%",width:M!==null?`${M}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${O}px`}:{"--oc-context-panel-width":`${O}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:G,"data-context-panel":"true",tabIndex:-1,inert:!D||void 0,className:Ie("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!D&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:Re,style:He,children:[D&&!P&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),D&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&s.jsx("div",{className:Ie("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",L&&"bg-[var(--interactive-border)]"),onPointerDown:ie,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:Ie("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!D&&"pointer-events-none select-none opacity-0"),style:{width:P?M!==null?`${M}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!D,children:[Qe,s.jsxs("div",{className:Ie("relative min-h-0 flex-1 overflow-hidden",L&&"pointer-events-none"),children:[$?s.jsxs("div",{className:Ie("absolute inset-0 flex",se?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:ae?s.jsx(c.Suspense,{fallback:null,children:s.jsx(fw,{mode:"editor-only"})}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(R,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.editorEmpty.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.editorEmpty.description")})]})}),s.jsx(Dw,{visible:b})]}):null,te&&be&&Pe?s.jsx("iframe",{ref:le=>{if(!le){ee.current.delete(te.id);return}ee.current.set(te.id,le)},src:Pe,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:be}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{he(),fe(),H()}},te.id):null,Te.map(le=>s.jsx("div",{className:Ie("absolute inset-0",A?.id!==le.id&&"hidden"),children:s.jsx(iw,{initialUrl:le.targetPath??"",directory:n,tabID:le.id})},le.id)),Z.map(le=>s.jsx("div",{className:Ie("absolute inset-0",A?.id!==le.id&&"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(mw,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:le.diffScope??(le.stagedDiff?"staged":"working"),onDiffScopeChange:de,targetFilePath:le.targetPath,flushContent:!0})})},le.id)),Ne?s.jsx("div",{className:Ie("absolute inset-0",A?.mode==="terminal"?"block":"hidden"),children:s.jsx(Mp,{visible:D&&A?.mode==="terminal"})}):null,Me?s.jsx("div",{className:Ie("absolute inset-0",A?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(c.Suspense,{fallback:null,children:s.jsx(uw,{directory:e})})}):null,A?.mode!=="chat"&&!se&&A?.mode!=="browser"&&A?.mode!=="diff"&&A?.mode!=="terminal"&&A?.mode!=="walkthrough"?_e:null]})]})]})},Mw=t=>{const e=Ye.c(42),{open:n,onOpenChange:r}=t,{t:i}=ht(),o=Ae(Ow),l=Ae(Bw),a=Ae(Fw),d=Ae(_w);let u;e[0]!==o?(u=Ad(o),e[0]=o,e[1]=u):u=e[1];const m=u,h=l.length===0;let y;if(e[2]!==l||e[3]!==m){let A;e[5]!==l?(A=D=>l.includes(D.id),e[5]=l,e[6]=A):A=e[6],y=m.every(A),e[2]=l,e[3]=m,e[4]=y}else y=e[4];const b=y;let S;e[7]!==i?(S=i("contextRail.configure.dialogTitle"),e[7]=i,e[8]=S):S=e[8];let v;e[9]!==S?(v=s.jsx(Rs,{children:S}),e[9]=S,e[10]=v):v=e[10];let g;e[11]!==i?(g=i("contextRail.configure.dialogDescription"),e[11]=i,e[12]=g):g=e[12];let f;e[13]!==g?(f=s.jsx(Ms,{children:g}),e[13]=g,e[14]=f):f=e[14];let x;e[15]!==v||e[16]!==f?(x=s.jsxs(Hs,{children:[v,f]}),e[15]=v,e[16]=f,e[17]=x):x=e[17];let p;if(e[18]!==l||e[19]!==a||e[20]!==m||e[21]!==i){let A;e[23]!==l||e[24]!==a||e[25]!==i?(A=D=>s.jsx(Bf,{settingsItem:`layout.context-rail.surface.${D.id}`,checked:!l.includes(D.id),onChange:P=>a(D.id,P),label:i(D.labelKey),ariaLabel:i(D.labelKey)},D.id),e[23]=l,e[24]=a,e[25]=i,e[26]=A):A=e[26],p=m.map(A),e[18]=l,e[19]=a,e[20]=m,e[21]=i,e[22]=p}else p=e[22];let w;e[27]!==p?(w=s.jsx("div",{className:"flex flex-col",children:p}),e[27]=p,e[28]=w):w=e[28];let N;e[29]!==h||e[30]!==b||e[31]!==d||e[32]!==i?(N=h?null:s.jsxs("div",{className:"flex items-center justify-between border-t pt-3",children:[b?s.jsx("span",{className:"text-xs text-destructive",children:i("contextRail.configure.noneWarning")}):s.jsx("span",{}),s.jsx(at,{variant:"link",size:"xs",onClick:()=>d([]),className:"normal-case text-muted-foreground hover:text-foreground",children:i("contextRail.configure.showAll")})]}),e[29]=h,e[30]=b,e[31]=d,e[32]=i,e[33]=N):N=e[33];let C;e[34]!==N||e[35]!==x||e[36]!==w?(C=s.jsxs(As,{className:"max-w-md",children:[x,w,N]}),e[34]=N,e[35]=x,e[36]=w,e[37]=C):C=e[37];let k;return e[38]!==r||e[39]!==n||e[40]!==C?(k=s.jsx(Ns,{open:n,onOpenChange:r,children:C}),e[38]=r,e[39]=n,e[40]=C,e[41]=k):k=e[41],k};function Ow(t){return t.contextRailOrder}function Bw(t){return t.contextRailHiddenSurfaces}function Fw(t){return t.setContextRailSurfaceVisible}function _w(t){return t.setContextRailHiddenSurfaces}const sm=150,Lw=500,$w=[],Ww=t=>t>99?"99+":String(t),zw=t=>{const e=Ye.c(51),{surface:n,isActive:r,showActivityDot:i,label:o,description:l,badgeCount:a,badgeAriaLabel:d,badgeDescription:u,orderNumber:m,showOrderNumber:h,onSelect:y}=t;let b;e[0]!==n.id?(b={id:n.id},e[0]=n.id,e[1]=b):b=e[1];const{attributes:S,listeners:v,setNodeRef:g,transform:f,transition:x,isDragging:p}=ii(b);let w;e[2]!==a?(w=a!=null&&a>0?Ww(a):null,e[2]=a,e[3]=w):w=e[3];const N=w;let C;e[4]!==f?(C=ai.Translate.toString(f),e[4]=f,e[5]=C):C=e[5];let k;e[6]!==C||e[7]!==x?(k={transform:C,transition:x},e[6]=C,e[7]=x,e[8]=k):k=e[8];const A=p&&"z-10 opacity-70";let D;e[9]!==A?(D=Ie("relative",A),e[9]=A,e[10]=D):D=e[10];let P;e[11]!==y||e[12]!==n?(P=()=>y(n),e[11]=y,e[12]=n,e[13]=P):P=e[13];const M=d??o,z=r?"text-primary":"text-muted-foreground hover:text-foreground";let I;e[14]!==z?(I=Ie("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",z),e[14]=z,e[15]=I):I=e[15];let V;e[16]!==n.icon||e[17]!==n.id?(V=n.id==="diff"?s.jsx(Au,{}):s.jsx(R,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=V):V=e[18];let T;e[19]!==N||e[20]!==m||e[21]!==i||e[22]!==h?(T=h&&m!=null?s.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:m===10?"0":m}):N?s.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:N}):i?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[19]=N,e[20]=m,e[21]=i,e[22]=h,e[23]=T):T=e[23];let _;e[24]!==S||e[25]!==r||e[26]!==v||e[27]!==I||e[28]!==V||e[29]!==T||e[30]!==P||e[31]!==M?(_=s.jsx(bt,{asChild:!0,children:s.jsxs("button",{type:"button",...S,...v,onClick:P,"aria-label":M,"aria-pressed":r,className:I,children:[V,T]})}),e[24]=S,e[25]=r,e[26]=v,e[27]=I,e[28]=V,e[29]=T,e[30]=P,e[31]=M,e[32]=_):_=e[32];let O;e[33]!==o?(O=s.jsx("span",{children:o}),e[33]=o,e[34]=O):O=e[34];let j;e[35]!==l?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:l}),e[35]=l,e[36]=j):j=e[36];let E;e[37]!==u?(E=u?s.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null,e[37]=u,e[38]=E):E=e[38];let L;e[39]!==O||e[40]!==j||e[41]!==E?(L=s.jsx(xt,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[O,j,E]})}),e[39]=O,e[40]=j,e[41]=E,e[42]=L):L=e[42];let U;e[43]!==_||e[44]!==L?(U=s.jsxs(yt,{delayDuration:sm,children:[_,L]}),e[43]=_,e[44]=L,e[45]=U):U=e[45];let X;return e[46]!==g||e[47]!==U||e[48]!==k||e[49]!==D?(X=s.jsx("div",{ref:g,style:k,className:D,children:U}),e[46]=g,e[47]=U,e[48]=k,e[49]=D,e[50]=X):X=e[50],X},Vw=()=>{const t=Ye.c(70),{t:e}=ht(),n=to();let r;t[0]!==n?(r=n?cr(n):"",t[0]=n,t[1]=r):r=t[1];const i=r;let o;t[2]!==i?(o=ie=>i?ie.contextPanelByDirectory[i]:void 0,t[2]=i,t[3]=o):o=t[3];const l=Ae(o),a=Ae(Uw),d=Ae(Hw),u=Ae(Kw),m=Ae(Gw),h=Ae(qw),y=Ae(Qw),b=ja(Yw),{screenWidth:S}=zn(),v=ka(i||null);let g;t[4]!==y?(g=Ri("switch_context_surface",y),t[4]=y,t[5]=g):g=t[5];const f=g,[x,p]=c.useState(!1);let w,N;t[6]!==f?(w=()=>{const ie=new Set;let xe=null,ge=!1;const Ce=Xw,Re=()=>{ol(f,ie)?!ge&&xe===null&&(xe=setTimeout(()=>p(!0),Lw)):(ge=!1,xe!==null&&(clearTimeout(xe),xe=null),p(!1))},ce=te=>{if(ie.add(te.key.toLowerCase()),Ce(te.key)&&ol(f,ie)){ge=!0,xe!==null&&(clearTimeout(xe),xe=null),p(!1);return}Re()},ye=te=>{ie.delete(te.key.toLowerCase()),Re()},be=()=>{ie.clear(),ge=!1,xe!==null&&(clearTimeout(xe),xe=null),p(!1)};return window.addEventListener("keydown",ce,!0),window.addEventListener("keyup",ye,!0),window.addEventListener("blur",be),()=>{window.removeEventListener("keydown",ce,!0),window.removeEventListener("keyup",ye,!0),window.removeEventListener("blur",be),xe!==null&&clearTimeout(xe)}},N=[f],t[6]=f,t[7]=w,t[8]=N):(w=t[7],N=t[8]),c.useEffect(w,N);let C;t[9]===Symbol.for("react.memo_cache_sentinel")?(C={activationConstraint:{distance:8}},t[9]=C):C=t[9];let k;t[10]===Symbol.for("react.memo_cache_sentinel")?(k={activationConstraint:{delay:200,tolerance:6}},t[10]=k):k=t[10];const A=Hr(_n(nu,C),_n(su,k)),D=l?.tabs??$w;let P;t[11]!==l?.activeTabId||t[12]!==D?(P=D.find(ie=>ie.id===l?.activeTabId)??null,t[11]=l?.activeTabId,t[12]=D,t[13]=P):P=t[13];const M=P,z=l?.isOpen?M?.mode??null:null,I=v?.files.length??0;let V;t[14]!==u||t[15]!==d||t[16]!==b||t[17]!==S||t[18]!==D?(V=Ff({railOrder:d,hiddenSurfaces:u,planModeEnabled:b,isVSCode:Dn(),screenWidth:S,tabs:D}),t[14]=u,t[15]=d,t[16]=b,t[17]=S,t[18]=D,t[19]=V):V=t[19];const T=V,[_,O]=c.useState(!1);let j;t[20]!==m?(j=ie=>{const{active:xe,over:ge}=ie;if(!ge||xe.id===ge.id)return;const Ce=Ad(Ae.getState().contextRailOrder).map(Jw),Re=Ce.indexOf(xe.id),ce=Ce.indexOf(ge.id);Re===-1||ce===-1||m(ru(Ce,Re,ce))},t[20]=m,t[21]=j):j=t[21];const E=j;if(!i)return null;let L;t[22]!==e?(L=e("contextRail.aria.rail"),t[22]=e,t[23]=L):L=t[23];let U;t[24]!==T?(U=T.map(Zw),t[24]=T,t[25]=U):U=t[25];let X;if(t[26]!==z||t[27]!==I||t[28]!==i||t[29]!==h||t[30]!==x||t[31]!==T||t[32]!==e||t[33]!==a){let ie;t[35]!==z||t[36]!==I||t[37]!==i||t[38]!==h||t[39]!==x||t[40]!==e||t[41]!==a?(ie=(xe,ge)=>{const Ce=e(xe.labelKey),Re=xe.id==="git"&&!a?I:0,ce=Re>0?Re:null;return s.jsx(zw,{surface:xe,isActive:z===xe.mode,showActivityDot:!1,label:Ce,description:e(xe.descriptionKey),badgeCount:ce,badgeAriaLabel:ce!==null?e(ce===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:Ce,count:ce}):null,badgeDescription:ce!==null?e(ce===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:ce}):null,orderNumber:ge+1,showOrderNumber:x,onSelect:ye=>h(i,ye.mode)},xe.id)},t[35]=z,t[36]=I,t[37]=i,t[38]=h,t[39]=x,t[40]=e,t[41]=a,t[42]=ie):ie=t[42],X=T.map(ie),t[26]=z,t[27]=I,t[28]=i,t[29]=h,t[30]=x,t[31]=T,t[32]=e,t[33]=a,t[34]=X}else X=t[34];let Q;t[43]!==U||t[44]!==X?(Q=s.jsx(Wo,{items:U,strategy:Vi,children:X}),t[43]=U,t[44]=X,t[45]=Q):Q=t[45];let me;t[46]!==E||t[47]!==A||t[48]!==Q?(me=s.jsx(Kr,{sensors:A,collisionDetection:Gr,onDragEnd:E,children:Q}),t[46]=E,t[47]=A,t[48]=Q,t[49]=me):me=t[49];let re;t[50]!==e?(re=e("contextRail.configure.open"),t[50]=e,t[51]=re):re=t[51];let G;t[52]===Symbol.for("react.memo_cache_sentinel")?(G=()=>O(!0),t[52]=G):G=t[52];let ee;t[53]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(R,{name:"equalizer-2",className:"h-[18px] w-[18px]"}),t[53]=ee):ee=t[53];let ue;t[54]!==re?(ue=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":re,onClick:G,className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground",children:ee})}),t[54]=re,t[55]=ue):ue=t[55];let W;t[56]!==e?(W=e("contextRail.configure.open"),t[56]=e,t[57]=W):W=t[57];let ne;t[58]!==W?(ne=s.jsx(xt,{side:"left",sideOffset:8,children:W}),t[58]=W,t[59]=ne):ne=t[59];let Y;t[60]!==ue||t[61]!==ne?(Y=s.jsxs(yt,{delayDuration:sm,children:[ue,ne]}),t[60]=ue,t[61]=ne,t[62]=Y):Y=t[62];let F;t[63]!==_?(F=s.jsx(Mw,{open:_,onOpenChange:O}),t[63]=_,t[64]=F):F=t[64];let J;return t[65]!==L||t[66]!==me||t[67]!==Y||t[68]!==F?(J=s.jsxs("nav",{"aria-label":L,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:[me,Y,F]}),t[65]=L,t[66]=me,t[67]=Y,t[68]=F,t[69]=J):J=t[69],J};function Uw(t){return t.workStatusPanelVisible}function Hw(t){return t.contextRailOrder}function Kw(t){return t.contextRailHiddenSurfaces}function Gw(t){return t.setContextRailOrder}function qw(t){return t.openContextSurface}function Qw(t){return t.shortcutOverrides}function Yw(t){return t.planModeEnabled}function Xw(t){return t.length===1&&t>="0"&&t<="9"}function Jw(t){return t.id}function Zw(t){return t.id}const eS=()=>{const e=qe.getState().currentSessionId;if(!e)return"";const r=Dd().find(i=>i.id===e);return typeof r?.directory=="string"?r.directory:""},tS=async(t,e=6e3)=>{const n=new AbortController,r=setTimeout(()=>n.abort(),e),i=Date.now();try{const o=await rs(t,{method:"GET",headers:{Accept:"application/json"},signal:n.signal}),l=Date.now()-i,a=o.headers.get("content-type")||"",d=a.toLowerCase(),u=d.includes("json")&&!d.includes("text/html");let m="";if(u){const h=await o.json().catch(()=>null);if(Array.isArray(h))m=`json[array] len=${h.length}`;else if(h&&typeof h=="object"){const y=Object.keys(h).slice(0,8);m=`json[object] keys=${y.join(",")}${Object.keys(h).length>y.length?",…":""}`}else m=`json[${typeof h}]`}else m=a?`content-type=${a}`:"no content-type";return{ok:o.ok&&u,status:o.status,elapsedMs:l,summary:m}}catch(o){const l=Date.now()-i,d=n.signal.aborted||o instanceof Error&&(o.name==="AbortError"||o.message.toLowerCase().includes("aborted"))?`timeout after ${e}ms`:o instanceof Error?o.message:String(o);return{ok:!1,status:0,elapsedMs:l,summary:`error=${d}`}}finally{clearTimeout(r)}},sS=t=>{if(!t||!Number.isFinite(t))return"(n/a)";try{return new Date(t).toISOString()}catch{return"(invalid)"}},nS=t=>{if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.trunc(t);if(typeof t=="string"){const e=Number.parseInt(t,10);if(Number.isFinite(e)&&e>0)return e}return null},rS=t=>!!t&&typeof t=="object"&&!Array.isArray(t),Mn=(t,e="(n/a)")=>typeof t=="string"?t.trim()||e:typeof t=="number"&&Number.isFinite(t)?String(t):typeof t=="boolean"?t?"true":"false":e,cc=(t,e,n)=>t==="node-shebang"||t==="node-launcher"?e?`node (${e})`:"node":t==="bun-shebang"?n?`bun (${n})`:"bun":t||"direct executable",oS=async()=>{const t=new Date,e="1.21.1",n=typeof navigator<"u"?navigator.userAgent:"(no navigator)",r=eS(),i=Ae.getState().eventStreamStatus,o=typeof window<"u"?window.location.origin:"",l=xa(),a=l.health(),d=l.api("/api/"),u=await(async()=>{if(!a)return null;const f=new AbortController,x=setTimeout(()=>f.abort(),5e3);try{const p=await rs(a,{method:"GET",headers:{Accept:"application/json"},signal:f.signal});if(!p.ok)return null;const w=await p.json().catch(()=>null);return!w||typeof w!="object"||Array.isArray(w)?null:w}catch{return null}finally{clearTimeout(x)}})(),m=await(async()=>{if(!d)return null;const f=new AbortController,x=setTimeout(()=>f.abort(),7e3);try{const p=await rs(l.api("/api/config/opencode-resolution"),{method:"GET",headers:{Accept:"application/json"},signal:f.signal}),w=p.headers.get("content-type")||"(none)";if(!p.ok)return{data:null,status:p.status,error:`http ${p.status} content-type=${w}`};const N=await p.text();let C=null;try{C=JSON.parse(N)}catch{const k=N.replace(/\s+/g," ").slice(0,120);return{data:null,status:p.status,error:`invalid json content-type=${w} body=${k||"(empty)"}`}}return!C||typeof C!="object"||Array.isArray(C)?{data:null,status:p.status,error:`invalid json-shape content-type=${w}`}:{data:C,status:p.status,error:null}}catch(p){return{data:null,status:null,error:p instanceof Error?p.message:String(p)}}finally{clearTimeout(x)}})()||{data:null,error:null},h=(f,x=!0)=>{if(!d)return null;const p=new URL(f.replace(/^\/+/,""),d);return x&&r&&p.searchParams.set("directory",r),p.toString()},y=[{label:"health",path:"/health",includeDirectory:!1},{label:"config",path:"/config",includeDirectory:!0},{label:"providers",path:"/config/providers",includeDirectory:!0},{label:"agents",path:"/agent",includeDirectory:!0,timeoutMs:12e3},{label:"commands",path:"/command",includeDirectory:!0,timeoutMs:1e4},{label:"project",path:"/project/current",includeDirectory:!0},{label:"path",path:"/path",includeDirectory:!0},{label:"sessions",path:"/session",includeDirectory:!0,timeoutMs:12e3},{label:"sessionStatus",path:"/session/status",includeDirectory:!0}],b=d?await Promise.all(y.map(async f=>{const x=h(f.path,f.includeDirectory!==!1);if(!x)return{label:f.label,url:"(none)",result:null};const p=await tS(x,typeof f.timeoutMs=="number"?f.timeoutMs:void 0);return{label:f.label,url:x,result:p}})):[],S=[];S.push(`Time: ${t.toISOString()}`),S.push(`OpenChamber version: ${e}`),S.push(`Runtime: ${o||"(unknown)"} (api=${d||"(unknown)"})`),S.push(`OpenCode SDK base: ${_s.getBaseUrl()}`),S.push(`Event stream: ${i}`),S.push(`Directory: ${r||"(none)"}`),S.push(`Platform: ${n}`);const v=nS(u?.openCodePort);if(S.push(`OpenCode runtime port: ${v??"(unknown)"}`),typeof u?.openCodeRunning=="boolean"&&S.push(`OpenCode runtime running: ${u.openCodeRunning?"yes":"no"}`),typeof u?.openCodeSecureConnection=="boolean"&&S.push(`Secure OpenCode connection: ${u.openCodeSecureConnection?"true":"false"}`),typeof u?.openCodeAuthSource=="string"&&u.openCodeAuthSource.trim()&&S.push(`OpenCode auth source: ${u.openCodeAuthSource}`),typeof window<"u"){const f=window.__OPENCHAMBER_MACOS_MAJOR__;typeof f=="number"&&Number.isFinite(f)&&f>0&&S.push(`macOS major: ${f}`)}if(/Mac OS X|Macintosh/.test(n)){S.push(""),S.push("OpenCode CLI resolution:");const f=rS(u?.lastOpenCodeLaunchDiagnostics)?u.lastOpenCodeLaunchDiagnostics:null,x=f&&Array.isArray(f.args)?f.args.filter(T=>typeof T=="string"):[],p=m.data,w=p&&typeof p.configured=="string"?p.configured:null,N=p&&typeof p.resolved=="string"?p.resolved:u&&typeof u.opencodeBinaryResolved=="string"?u.opencodeBinaryResolved:"",C=p&&typeof p.resolvedDir=="string"?p.resolvedDir:"",k=p&&typeof p.source=="string"?p.source:u&&typeof u.opencodeBinarySource=="string"?u.opencodeBinarySource:"",A=p&&typeof p.launchBinary=="string"?p.launchBinary:u&&typeof u.opencodeLaunchBinary=="string"?u.opencodeLaunchBinary:"",D=p&&typeof p.launchWrapperType=="string"?p.launchWrapperType:u&&typeof u.opencodeLaunchWrapperType=="string"?u.opencodeLaunchWrapperType:"",P=p&&Array.isArray(p.launchArgs)?p.launchArgs.filter(T=>typeof T=="string"):u&&Array.isArray(u.opencodeLaunchArgs)?u.opencodeLaunchArgs.filter(T=>typeof T=="string"):[],M=p&&typeof p.node=="string"?p.node:u&&typeof u.nodeBinaryResolved=="string"?u.nodeBinaryResolved:"",z=p&&typeof p.bun=="string"?p.bun:u&&typeof u.bunBinaryResolved=="string"?u.bunBinaryResolved:"",I=p&&typeof p.detectedNow=="string"?p.detectedNow:"",V=p&&typeof p.detectedSourceNow=="string"?p.detectedSourceNow:"";if(w!==null&&S.push(`- configured: ${w.trim().length===0?"(cleared)":w}`),N){const T=C||(N.includes("/")?N.split("/").slice(0,-1).join("/")||"/":"");S.push(`- opencode: ${N}${T?` (dir=${T})`:""}`)}else S.push("- opencode: (n/a)");S.push(`- source: ${k||"(n/a)"}`),I&&(S.push(`- detected-now: ${I}`),S.push(`- detected-source: ${V||"(n/a)"}`)),f?(S.push(`- launched-at: ${Mn(f.launchedAt)}`),S.push(`- launch: ${Mn(f.binary)} ${x.join(" ")}`.trim()),S.push(`- cwd: ${Mn(f.cwd)}`),S.push(`- wrapper: ${Mn(f.wrapperType)}`),S.push(`- runtime: ${cc(Mn(f.wrapperType,""),M,z)}`),S.push(`- PATH entries: ${Mn(f.pathEntryCount,"(unknown)")}`),S.push(`- shell env: ${Mn(f.hasShellEnv,"(unknown)")} (${Mn(f.shellEnvKeysCount,"?")} keys)`)):(S.push(`- launch-binary: ${A||"(n/a)"}`),S.push(`- launch-wrapper: ${D||"(n/a)"}`),S.push(`- launch-args: ${P.length?P.join(" "):"(none)"}`),S.push(`- runtime: ${cc(D||"",M,z)}`)),!p&&m.error&&S.push(`- resolution-endpoint: ${m.error}`)}if(S.push(""),b.length){S.push("OpenCode API probes:");for(const f of b){if(!f.result){S.push(`- ${f.label}: (no url)`);continue}const{ok:x,status:p,elapsedMs:w,summary:N}=f.result,C=x?"":` url=${f.url}`;S.push(`- ${f.label}: ${x?"ok":"fail"} status=${p} time=${w}ms ${N}${C}`)}}else S.push("OpenCode API probes: (skipped)");return S.push(""),S.push(`Generated: ${sS(Date.now())}`),S.join(`
|
|
911
|
-
`)},nm=async()=>{const t=await oS(),e=Ae.getState();e.setOpenCodeStatusText(t),e.setOpenCodeStatusDialogOpen(!0)},iS=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),aS=(t,e,n,r)=>!n||r!==n||t.length===0?[]:Or(t,e,i=>i.relativePath||i.name,{limit:10,threshold:.4}),lS=new Set,cS=[],oa=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const i=r==="/",o=/^[A-Za-z]:\/$/.test(r);return!i&&!o&&(r=r.replace(/\/+$/,"")),r},dS=()=>{const t=Ye.c(182),{t:e}=ht(),n=Ae(uS),r=Ae(mS),i=Ae(fS),o=Ae(hS),l=Ae(pS),a=Ae(gS),d=Ae(bS),u=Ae(xS),m=Ae(yS),h=Ae(wS),y=Ae(SS),b=Ae(vS),S=Ae(jS),v=qe(kS),g=qe(CS),f=qe(NS),x=Vr(AS);let p;t[0]!==n?(p=Je=>n?Je.activeSessions:cS,t[0]=n,t[1]=p):p=t[1];const w=Es(p);let N;t[2]!==n?(N=Je=>n?Je.ids:lS,t[2]=n,t[3]=N):N=t[3];const C=Vr(N);let k;t[4]!==n?(k=Je=>n?Je.rankById:Td,t[4]=n,t[5]=k):k=t[5];const A=Da(k),D=ss(DS),P=Ht(PS),M=Ht(TS),z=to(),I=cd(IS),{files:V,git:T}=Pn(),_=$n(ES),{isMobile:O}=zn();let j;t[6]!==z?(j=z?oa(z):null,t[6]=z,t[7]=j):j=t[7];const E=j,[L,U]=c.useState(""),Q=Aa(L,200).trim();let me;t[8]!==L?(me=L.trim(),t[8]=L,t[9]=me):me=t[9];const re=me;let G,ee;t[10]!==n?(G=()=>{n&&U("")},ee=[n],t[10]=n,t[11]=G,t[12]=ee):(G=t[11],ee=t[12]),c.useEffect(G,ee);let ue,W;t[13]!==w||t[14]!==_||t[15]!==T||t[16]!==n?(ue=()=>{if(!n||!T)return;const Je=setTimeout(()=>{const nt=new Set;for(const jt of w){const At=Us(jt);!At||nt.has(At)||(nt.add(At),_(At,T))}},0);return()=>clearTimeout(Je)},W=[n,w,T,_],t[13]=w,t[14]=_,t[15]=T,t[16]=n,t[17]=ue,t[18]=W):(ue=t[17],W=t[18]),c.useEffect(ue,W);let ne;t[19]!==r?(ne=()=>r(!1),t[19]=r,t[20]=ne):ne=t[20];const Y=ne;let F;t[21]!==Y?(F=Je=>()=>{Y(),Je()},t[21]=Y,t[22]=F):F=t[22];const J=F;let ie;t[23]!==P?.id||t[24]!==P?.path||t[25]!==D||t[26]!==f||t[27]!==O||t[28]!==d||t[29]!==u||t[30]!==y||t[31]!==v||t[32]!==J||t[33]!==b||t[34]!==S||t[35]!==l||t[36]!==i||t[37]!==e||t[38]!==x||t[39]!==a?(ie=()=>{const Je=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(R,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:J(()=>{l(!1),v()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(R,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:J(RS)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(R,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:J(MS)},{id:"toggle-sidebar",title:e(O?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(R,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(O?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:J(()=>{if(O){const{isSessionSwitcherOpen:nt}=Ae.getState();l(!nt)}else a()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(R,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:J(()=>{D&&u(D,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(R,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:J(()=>{D&&d(D)})},{id:"cycle-theme",secondary:!0,title:e("commandPalette.item.cycleTheme"),icon:s.jsx(R,{name:"palette",className:"mr-2 h-4 w-4"}),shortcutId:"cycle_theme",searchText:e("commandPalette.item.cycleTheme"),onSelect:J(OS)},{id:"open-status",secondary:!0,title:e("commandPalette.item.showOpenCodeStatus"),icon:s.jsx(R,{name:"pulse",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showOpenCodeStatus"),onSelect:J(BS)},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(R,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:J(()=>i(!0))}];return Je.push({id:"pin-session",secondary:!0,title:e("commandPalette.item.pinSession"),icon:s.jsx(R,{name:"pushpin",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.pinSession"),onSelect:J(()=>{f&&D&&x({directory:D,sessionId:f})})},{id:"copy-session-id",secondary:!0,title:e("commandPalette.item.copySessionId"),icon:s.jsx(R,{name:"file-copy",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.copySessionId"),onSelect:J(()=>{f&&xn(f).then(nt=>{if(nt.ok){Oe.success(e("sessions.sidebar.session.copyId.success"));return}Oe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Oe.error(e("sessions.sidebar.session.copyId.error")))})},{id:"open-multi-run",secondary:!0,title:e("commandPalette.item.openMultiRun"),icon:s.jsx(R,{name:"checkbox-multiple",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openMultiRun"),onSelect:J(()=>{l(!1),y()})},{id:"open-archive",secondary:!0,title:e("commandPalette.item.openArchive"),icon:s.jsx(R,{name:"archive",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openArchive"),onSelect:J(()=>{l(!1),b(!0)})},{id:"open-notes",secondary:!0,title:e("commandPalette.item.openNotes"),icon:s.jsx(R,{name:"sticky-note",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openNotes"),onSelect:J(()=>{D&&(S("notes"),u(D,"notes"))})},{id:"open-todos",secondary:!0,title:e("commandPalette.item.openTodos"),icon:s.jsx(R,{name:"checkbox-circle",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.openTodos"),onSelect:J(()=>{D&&(S("todos"),u(D,"notes"))})}),Je.push({id:"toggle-memory-debug",secondary:!0,title:e("commandPalette.item.toggleMemoryDebug"),icon:s.jsx(R,{name:"bug",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.toggleMemoryDebug"),onSelect:J(FS)}),Zo()&&Je.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(R,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:J(()=>{Fn("desktop_open_draft_mini_chat_window",{directory:oa(D||P?.path||""),projectId:P?.id??null}).catch(_S)})}),Je},t[23]=P?.id,t[24]=P?.path,t[25]=D,t[26]=f,t[27]=O,t[28]=d,t[29]=u,t[30]=y,t[31]=v,t[32]=J,t[33]=b,t[34]=S,t[35]=l,t[36]=i,t[37]=e,t[38]=x,t[39]=a,t[40]=ie):ie=t[40],P?.id,P?.path;let xe;t[41]!==ie?(xe=ie(),t[41]=ie,t[42]=xe):xe=t[42];const ge=xe;let Ce;t[43]===Symbol.for("react.memo_cache_sentinel")?(Ce=wn(),t[43]=Ce):Ce=t[43];const Re=Ce;let ce,ye;t[44]===Symbol.for("react.memo_cache_sentinel")?(ce=Dn(),ye=!Re&&ya(),t[44]=ce,t[45]=ye):(ce=t[44],ye=t[45]);let be;t[46]!==O?(be={isVSCode:ce,isWeb:ye,isDesktop:Re,isMobile:O},t[46]=O,t[47]=be):be=t[47];const te=be;let pe;if(t[48]!==J||t[49]!==i||t[50]!==o||t[51]!==te){let Je;t[53]!==te?(Je=jt=>jt.isAvailable?jt.isAvailable(te):!0,t[53]=te,t[54]=Je):Je=t[54];let nt;t[55]!==J||t[56]!==i||t[57]!==o?(nt=jt=>{const At=Bp(jt.slug)??"settings-3",Ot=(jt.keywords??[]).join(" ");return{id:`settings:${jt.slug}`,title:jt.title,icon:jt.slug==="mcp"?s.jsx(zf,{className:"mr-2 h-4 w-4"}):s.jsx(R,{name:At,className:"mr-2 h-4 w-4"}),searchText:`${jt.title} ${jt.group} ${Ot}`,onSelect:J(()=>{o(jt.slug),i(!0)})}},t[55]=J,t[56]=i,t[57]=o,t[58]=nt):nt=t[58],pe=Op.filter(LS).filter(Je).map(nt),t[48]=J,t[49]=i,t[50]=o,t[51]=te,t[52]=pe}else pe=t[52];const Pe=pe;let de;if(t[59]!==w||t[60]!==C||t[61]!==A){const Je=w.filter($S);de=_f(Je,C,A),t[59]=w,t[60]=C,t[61]=A,t[62]=de}else de=t[62];const he=de,fe=Pd(),B=qe(WS);let H;t[63]!==fe||t[64]!==B?(H=(Je,nt)=>{const jt=B.get(Je);return jt?.branch?jt.branch.trim()||null:nt&&fe.get(nt)?.trim()||null},t[63]=fe,t[64]=B,t[65]=H):H=t[65];const ke=H;let Se;t[66]===Symbol.for("react.memo_cache_sentinel")?(Se=[],t[66]=Se):Se=t[66];const[Be,_e]=c.useState(Se),[Te,Z]=c.useState(""),Ne=iS(E,Q);let Me;t[67]!==E||t[68]!==Ne||t[69]!==n||t[70]!==I||t[71]!==_e||t[72]!==Z||t[73]!==Q?(Me=()=>{if(!n){_e([]),Z("");return}if(!Ne){_e([]),Z("");return}if(!E){_e([]),Z("");return}let Je=!1;return I(E,Q,40,{type:"file"}).then(nt=>{Je||(_e(nt.map(zS)),Z(Ne))}).catch(()=>{Je||(_e([]),Z(Ne))}),()=>{Je=!0}},t[67]=E,t[68]=Ne,t[69]=n,t[70]=I,t[71]=_e,t[72]=Z,t[73]=Q,t[74]=Me):Me=t[74];let $;t[75]!==E||t[76]!==Ne||t[77]!==n||t[78]!==I||t[79]!==Q?($=[n,E,Q,Ne,I],t[75]=E,t[76]=Ne,t[77]=n,t[78]=I,t[79]=Q,t[80]=$):$=t[80],c.useEffect(Me,$);const ae=re.length>0;let se;e:{if(!ae){let nt;t[81]!==ge?(nt=ge.filter(VS).map(US),t[81]=ge,t[82]=nt):nt=t[82],se=nt;break e}let Je;t[83]!==ge||t[84]!==re?(Je=Or(ge,re,HS,{limit:7,noFuzzy:!0}),t[83]=ge,t[84]=re,t[85]=Je):Je=t[85],se=Je}const we=se;let Ke;e:{if(!ae){let nt;t[86]===Symbol.for("react.memo_cache_sentinel")?(nt=[],t[86]=nt):nt=t[86],Ke=nt;break e}let Je;t[87]!==re||t[88]!==Pe?(Je=Or(Pe,re,KS,{limit:7,noFuzzy:!0}),t[87]=re,t[88]=Pe,t[89]=Je):Je=t[89],Ke=Je}const Qe=Ke;let He;e:{if(!ae){let nt;t[90]!==he?(nt=he.slice(0,5).map(GS),t[90]=he,t[91]=nt):nt=t[91],He=nt;break e}let Je;t[92]!==re||t[93]!==he?(Je=Or(he,re,qS,{limit:7,threshold:.2}),t[92]=re,t[93]=he,t[94]=Je):Je=t[94],He=Je}const le=He;let K;e:{if(!n){let nt;t[95]===Symbol.for("react.memo_cache_sentinel")?(nt=[],t[95]=nt):nt=t[95],K=nt;break e}let Je;t[96]!==Be||t[97]!==Te||t[98]!==Ne||t[99]!==Q?(Je=aS(Be,Q,Ne,Te),t[96]=Be,t[97]=Te,t[98]=Ne,t[99]=Q,t[100]=Je):Je=t[100],K=Je}const ve=K,$e=n&&Ne.length>0&&Te!==Ne;let We;e:{if(!ae){let nt;t[101]===Symbol.for("react.memo_cache_sentinel")?(nt=[],t[101]=nt):nt=t[101],We=nt;break e}let Je;if(t[102]!==re||t[103]!==M){const nt=M.map(QS);Je=Or(nt,re,YS,{limit:7,threshold:.4}),t[102]=re,t[103]=M,t[104]=Je}else Je=t[104];We=Je}const Le=We;let Fe,Ge,rt,St,Rt,ze,Pt,Nt,Tt,Et,vt,Ct,It,mt;if(t[105]!==ke||t[106]!==Y||t[107]!==E||t[108]!==V||t[109]!==ae||t[110]!==n||t[111]!==m||t[112]!==v||t[113]!==L||t[114]!==we||t[115]!==ve||t[116]!==Le||t[117]!==le||t[118]!==Qe||t[119]!==r||t[120]!==g||t[121]!==h||t[122]!==e){const Je=we.map(XS),nt=Qe.map(JS),jt=le.map(ZS),At=ae?ve.map(ev):[],Ot=ae?Le.map(tv):[];let $t;e:{if(!ae){$t=["commands","sessions"];break e}const kt=sv,st=[{key:"commands",score:kt(we)},{key:"settings",score:kt(Qe)},{key:"sessions",score:kt(le)},{key:"files",score:kt(ve)},{key:"projects",score:kt(Le)}];st.sort(nv),$t=st.map(rv)}const Zt=$t,Gt=kt=>{Y(),g(kt.id,Us(kt))},Ft=async kt=>{if(!E)return;const st=await Eu(V,kt,{directory:E});if(!st.ok){Oe.error(Ru(st.reason));return}m(E,kt),Y()},qt=(kt,st)=>{Y(),v({selectedProjectId:kt,directoryOverride:st})},Xt=kt=>Jn(eo(kt,h));St=Ns,Ct=n,It=r;let zt;t[137]!==e?(zt=e("commandPalette.title"),t[137]=e,t[138]=zt):zt=t[138];let Ee;t[139]!==zt?(Ee=s.jsx(Rs,{children:zt}),t[139]=zt,t[140]=Ee):Ee=t[140];let Ue;t[141]!==e?(Ue=e("commandPalette.description"),t[141]=e,t[142]=Ue):Ue=t[142];let et;t[143]!==Ue?(et=s.jsx(Ms,{children:Ue}),t[143]=Ue,t[144]=et):et=t[144],t[145]!==Ee||t[146]!==et?(mt=s.jsxs(Hs,{className:"sr-only",children:[Ee,et]}),t[145]=Ee,t[146]=et,t[147]=mt):mt=t[147],rt=As,Et="overflow-hidden p-0",vt=!0,Ge=Vf,Pt=!1,Nt="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let lt;t[148]!==e?(lt=e("commandPalette.input.placeholder"),t[148]=e,t[149]=lt):lt=t[149],t[150]!==L||t[151]!==lt?(Tt=s.jsx(Uf,{value:L,onValueChange:U,placeholder:lt}),t[150]=L,t[151]=lt,t[152]=Tt):Tt=t[152],Fe=Hf;let ut;t[153]!==e?(ut=e("commandPalette.empty.noResults"),t[153]=e,t[154]=ut):ut=t[154],t[155]!==ut?(Rt=s.jsx(Kf,{children:ut}),t[155]=ut,t[156]=Rt):Rt=t[156],ze=Zt.map(kt=>kt==="commands"&&Je.length>0?s.jsx(Nr,{children:Je.map(st=>s.jsxs(Br,{value:st.id,onSelect:st.onSelect,children:[st.icon,s.jsx("span",{children:st.title}),st.shortcutId?s.jsx(Lf,{children:Xt(st.shortcutId)}):null]},st.id))},"commands"):kt==="settings"&&nt.length>0?s.jsx(Nr,{children:nt.map(ov)},"settings"):kt==="sessions"&&jt.length>0?s.jsx(Nr,{children:jt.map(st=>{const _t=st.title||e("commandPalette.session.untitled"),es=Us(st),Ds=ke(st.id,es);return s.jsxs(Br,{value:`session:${st.id}`,onSelect:()=>Gt(st),children:[s.jsx(R,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:_t}),Ds?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Ds})]}):null]},st.id)})},"sessions"):kt==="files"&&At.length>0?s.jsx(Nr,{children:At.map(st=>{const _t=$f(st.relativePath||st.name,{maxLength:80});return s.jsxs(Br,{value:`file:${st.path}`,onSelect:()=>{Ft(st.path)},children:[s.jsx(Na,{filePath:st.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":st.relativePath,children:_t})]},`file:${st.path}`)})},"files"):kt==="projects"&&Ot.length>0?s.jsx(Nr,{children:Ot.map(st=>{const _t=st.displayName;return s.jsxs(Br,{value:`project:${st.id}`,onSelect:()=>qt(st.id,st.path),children:[s.jsx(R,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:_t}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:st.path})]},`project:${st.id}`)})},"projects"):null),t[105]=ke,t[106]=Y,t[107]=E,t[108]=V,t[109]=ae,t[110]=n,t[111]=m,t[112]=v,t[113]=L,t[114]=we,t[115]=ve,t[116]=Le,t[117]=le,t[118]=Qe,t[119]=r,t[120]=g,t[121]=h,t[122]=e,t[123]=Fe,t[124]=Ge,t[125]=rt,t[126]=St,t[127]=Rt,t[128]=ze,t[129]=Pt,t[130]=Nt,t[131]=Tt,t[132]=Et,t[133]=vt,t[134]=Ct,t[135]=It,t[136]=mt}else Fe=t[123],Ge=t[124],rt=t[125],St=t[126],Rt=t[127],ze=t[128],Pt=t[129],Nt=t[130],Tt=t[131],Et=t[132],vt=t[133],Ct=t[134],It=t[135],mt=t[136];let Ze;t[157]!==$e||t[158]!==e?(Ze=$e?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[157]=$e,t[158]=e,t[159]=Ze):Ze=t[159];let je;t[160]!==Fe||t[161]!==Rt||t[162]!==ze||t[163]!==Ze?(je=s.jsxs(Fe,{children:[Rt,ze,Ze]}),t[160]=Fe,t[161]=Rt,t[162]=ze,t[163]=Ze,t[164]=je):je=t[164];let ot;t[165]!==Ge||t[166]!==Pt||t[167]!==Nt||t[168]!==Tt||t[169]!==je?(ot=s.jsxs(Ge,{shouldFilter:Pt,className:Nt,children:[Tt,je]}),t[165]=Ge,t[166]=Pt,t[167]=Nt,t[168]=Tt,t[169]=je,t[170]=ot):ot=t[170];let ct;t[171]!==rt||t[172]!==Et||t[173]!==vt||t[174]!==ot?(ct=s.jsx(rt,{className:Et,showCloseButton:vt,children:ot}),t[171]=rt,t[172]=Et,t[173]=vt,t[174]=ot,t[175]=ct):ct=t[175];let Mt;return t[176]!==St||t[177]!==Ct||t[178]!==It||t[179]!==mt||t[180]!==ct?(Mt=s.jsxs(St,{open:Ct,onOpenChange:It,children:[mt,ct]}),t[176]=St,t[177]=Ct,t[178]=It,t[179]=mt,t[180]=ct,t[181]=Mt):Mt=t[181],Mt};function uS(t){return t.isCommandPaletteOpen}function mS(t){return t.setCommandPaletteOpen}function fS(t){return t.setSettingsDialogOpen}function hS(t){return t.setSettingsPage}function pS(t){return t.setSessionSwitcherOpen}function gS(t){return t.toggleSidebar}function bS(t){return t.openContextOverview}function xS(t){return t.openContextSurface}function yS(t){return t.openContextFile}function wS(t){return t.shortcutOverrides}function SS(t){return t.openMultiRunLauncher}function vS(t){return t.setArchivePageOpen}function jS(t){return t.setProjectContextTab}function kS(t){return t.openNewSessionDraft}function CS(t){return t.setCurrentSession}function NS(t){return t.currentSessionId}function AS(t){return t.toggle}function DS(t){return t.currentDirectory}function PS(t){return t.getActiveProject()}function TS(t){return t.projects}function IS(t){return t.searchFiles}function ES(t){return t.ensureStatus}function RS(){Id()}function MS(){yn.requestDirectoryDialog()}function OS(){Gf.invoke("cycle_theme")}function BS(){nm()}function FS(){window.dispatchEvent(new CustomEvent("openchamber:memory-debug-toggle"))}function _S(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function LS(t){return t.slug!=="home"}function $S(t){return!Wf(t)}function WS(t){return t.worktreeMetadata}function zS(t){return{path:oa(t.path),name:t.name,relativePath:t.relativePath}}function VS(t){return!t.secondary}function US(t){return{item:t,score:0}}function HS(t){return t.searchText}function KS(t){return t.searchText}function GS(t){return{item:t,score:0}}function qS(t){return t.title||""}function QS(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function YS(t){return t.searchText}function XS(t){return t.item}function JS(t){return t.item}function ZS(t){return t.item}function ev(t){return t.item}function tv(t){return t.item}function sv(t){return t.length?t[0].score:1/0}function nv(t,e){return t.score-e.score}function rv(t){return t.key}function ov(t){return s.jsxs(Br,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const dc=(t,e,n)=>Jn(eo(t,e),n),iv=()=>{const t=Ye.c(68),{t:e}=ht(),n=Ae(av),r=Ae(lv),i=Ae(cv);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=Dn(),t[0]=o):o=t[0];const l=o;let a,d,u,m,h,y,b,S,v;if(t[1]!==n||t[2]!==r||t[3]!==i||t[4]!==e){const T=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[Jn("mod+shift+alt+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:"open_draft_project_picker",icon:"folder",keys:""},{id:"open_draft_worktree_picker",icon:"git-branch",keys:""},{id:"open_session_list",icon:"list-unordered",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{keys:[`${Jn(Ri("switch_context_surface",i))} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"},{keys:[`${Jn(Ri("switch_session_tab",i))} + 1...9`],descriptionKey:"helpDialog.item.switchSessionTab",icon:"layout-right"}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=Ns,S=n,v=r,a=As,y="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let _;t[14]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(R,{name:"command",className:"h-5 w-5"}),t[14]=_):_=t[14];let O;t[15]!==e?(O=e("helpDialog.title"),t[15]=e,t[16]=O):O=t[16];let j;t[17]!==O?(j=s.jsxs(Rs,{className:"flex items-center gap-2",children:[_,O]}),t[17]=O,t[18]=j):j=t[18];let E;t[19]!==e?(E=e("helpDialog.description"),t[19]=e,t[20]=E):E=t[20];let L;t[21]!==E?(L=s.jsx(Ms,{children:E}),t[21]=E,t[22]=L):L=t[22],t[23]!==j||t[24]!==L?(b=s.jsxs(Hs,{children:[j,L]}),t[23]=j,t[24]=L,t[25]=b):b=t[25],h="flex-1 overflow-y-auto mt-3 pr-1",u="space-y-4",m=T.map(U=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(U.categoryKey)}),s.jsx("div",{className:"space-y-1",children:U.items.filter(X=>!(l&&X.id==="toggle_prompt_navigator")).map(X=>{const Q=X.id?qf(X.id):void 0,me=X.descriptionKey??(Q?.customizable?Q.settingsLabelKey:void 0);if(!me||X.id&&!eo(X.id,i))return null;const re=X.id?dc(X.id,i,e("settings.openchamber.keyboardShortcuts.unassigned")):Array.isArray(X.keys)?X.keys:X.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[X.icon&&s.jsx(R,{name:X.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(me)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(re)?re:[re]).map((G,ee)=>s.jsxs(c.Fragment,{children:[ee>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:G})]},`${G}-${ee}`))})]},X.id||me)})})]},U.categoryKey)),t[1]=n,t[2]=r,t[3]=i,t[4]=e,t[5]=a,t[6]=d,t[7]=u,t[8]=m,t[9]=h,t[10]=y,t[11]=b,t[12]=S,t[13]=v}else a=t[5],d=t[6],u=t[7],m=t[8],h=t[9],y=t[10],b=t[11],S=t[12],v=t[13];let g;t[26]!==u||t[27]!==m?(g=s.jsx("div",{className:u,children:m}),t[26]=u,t[27]=m,t[28]=g):g=t[28];let f;t[29]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(R,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=f):f=t[29];let x;t[30]!==e?(x=e("helpDialog.proTips.title"),t[30]=e,t[31]=x):x=t[31];let p;t[32]!==x?(p=s.jsx("p",{className:"font-medium mb-1",children:x}),t[32]=x,t[33]=p):p=t[33];let w;t[34]!==i||t[35]!==e?(w=e("helpDialog.proTips.commandPalette",{shortcut:dc("open_command_palette",i,e("settings.openchamber.keyboardShortcuts.unassigned"))}),t[34]=i,t[35]=e,t[36]=w):w=t[36];let N;t[37]!==w?(N=s.jsxs("li",{children:["• ",w]}),t[37]=w,t[38]=N):N=t[38];let C;t[39]!==e?(C=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=C):C=t[40];let k;t[41]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[41]=C,t[42]=k):k=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.leaderSequences"),t[43]=e,t[44]=A):A=t[44];let D;t[45]!==A?(D=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=D):D=t[46];let P;t[47]!==N||t[48]!==k||t[49]!==D?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[N,k,D]}),t[47]=N,t[48]=k,t[49]=D,t[50]=P):P=t[50];let M;t[51]!==p||t[52]!==P?(M=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[f,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[p,P]})]})}),t[51]=p,t[52]=P,t[53]=M):M=t[53];let z;t[54]!==M||t[55]!==h||t[56]!==g?(z=s.jsxs("div",{className:h,children:[g,M]}),t[54]=M,t[55]=h,t[56]=g,t[57]=z):z=t[57];let I;t[58]!==a||t[59]!==z||t[60]!==y||t[61]!==b?(I=s.jsxs(a,{className:y,children:[b,z]}),t[58]=a,t[59]=z,t[60]=y,t[61]=b,t[62]=I):I=t[62];let V;return t[63]!==d||t[64]!==I||t[65]!==S||t[66]!==v?(V=s.jsx(d,{open:S,onOpenChange:v,children:I}),t[63]=d,t[64]=I,t[65]=S,t[66]=v,t[67]=V):V=t[67],V};function av(t){return t.isHelpDialogOpen}function lv(t){return t.setHelpDialogOpen}function cv(t){return t.shortcutOverrides}const dv=()=>{const t=Ye.c(32),{t:e}=ht(),n=Ae(uv),r=Ae(mv),i=Ae(fv);let o;t[0]!==i||t[1]!==e?(o=async()=>{if(!i)return;if((await xn(i)).ok){Oe.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Oe.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=i,t[1]=e,t[2]=o):o=t[2];const l=o;let a;t[3]!==e?(a=e("openCodeStatusDialog.title"),t[3]=e,t[4]=a):a=t[4];let d;t[5]!==a?(d=s.jsx(Rs,{children:a}),t[5]=a,t[6]=d):d=t[6];let u;t[7]!==e?(u=e("openCodeStatusDialog.description"),t[7]=e,t[8]=u):u=t[8];let m;t[9]!==u?(m=s.jsx(Ms,{children:u}),t[9]=u,t[10]=m):m=t[10];let h;t[11]!==d||t[12]!==m?(h=s.jsxs(Hs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=h):h=t[13];let y;t[14]!==e?(y=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=y):y=t[15];let b;t[16]!==l||t[17]!==y?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,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:y})}),t[16]=l,t[17]=y,t[18]=b):b=t[18];let S;t[19]!==i||t[20]!==e?(S=i||e("openCodeStatusDialog.empty.noData"),t[19]=i,t[20]=e,t[21]=S):S=t[21];let v;t[22]!==S?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:S}),t[22]=S,t[23]=v):v=t[23];let g;t[24]!==h||t[25]!==b||t[26]!==v?(g=s.jsxs(As,{className:"max-w-2xl",children:[h,b,v]}),t[24]=h,t[25]=b,t[26]=v,t[27]=g):g=t[27];let f;return t[28]!==n||t[29]!==r||t[30]!==g?(f=s.jsx(Ns,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=f):f=t[31],f};function uv(t){return t.isOpenCodeStatusDialogOpen}function mv(t){return t.setOpenCodeStatusDialogOpen}function fv(t){return t.openCodeStatusText}const hv=t=>{const e=Ye.c(16),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:i,sessionSearchInputRef:o,sessionSearchContainerRef:l}=t,a=n===void 0?!0:n;let d,u;e[0]!==a||e[1]!==r||e[2]!==o?(d=()=>{if(!a||!r||typeof window>"u")return;const S=window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.select()});return()=>window.cancelAnimationFrame(S)},u=[a,r,o],e[0]=a,e[1]=r,e[2]=o,e[3]=d,e[4]=u):(d=e[3],u=e[4]),c.useEffect(d,u);let m,h;e[5]!==a||e[6]!==o||e[7]!==i?(m=()=>{if(!a||typeof window>"u")return;const S=()=>{i(!0),o.current?.focus(),o.current?.select()};return window.addEventListener("openchamber:sidebar-session-search",S),()=>window.removeEventListener("openchamber:sidebar-session-search",S)},h=[a,i,o],e[5]=a,e[6]=o,e[7]=i,e[8]=m,e[9]=h):(m=e[8],h=e[9]),c.useEffect(m,h);let y,b;e[10]!==a||e[11]!==r||e[12]!==l||e[13]!==i?(y=()=>{if(!a||!r||typeof document>"u")return;const S=v=>{l.current&&(l.current.contains(v.target)||i(!1))};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},b=[a,r,i,l],e[10]=a,e[11]=r,e[12]=l,e[13]=i,e[14]=y,e[15]=b):(y=e[14],b=e[15]),c.useEffect(y,b)},pv=t=>{const e=Ye.c(4);let n;e[0]!==t?(n=(o,l)=>{const a=t.get(o);if(!a||a.length===0)return l;const d=new Map(l.map(gv)),u=[];a.forEach(y=>{const b=d.get(y);b&&(u.push(b),d.delete(y))});const m=[],h=[];return l.forEach(y=>{d.has(y.id)&&(y.isArchivedBucket?h.push(y):m.push(y))}),[...m,...u,...h]},e[0]=t,e[1]=n):n=e[1];const r=n;let i;return e[2]!==r?(i={getOrderedGroups:r},e[2]=r,e[3]=i):i=e[3],i};function gv(t){return[t.id,t]}const bo="oc.sessions.projectCollapse",uc="oc.sessions.groupOrder",mc="oc.sessions.groupCollapse",fc=t=>{if(!t)return new Set;try{const e=Fa(vr()).safeParse(JSON.parse(t));return new Set(e.success?e.data:[])}catch{return new Set}},bv=t=>{if(!t)return new Map;try{const e=uu(vr(),Fa(vr())).safeParse(JSON.parse(t));if(!e.success)return new Map;const n=new Map;for(const[r,i]of Object.entries(e.data))n.set(r,i);return n}catch{return new Map}},xv=t=>{const e=Ye.c(39),{isVSCode:n,projects:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Fo(),e[0]=i):i=e[0];const o=i;let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=()=>fc(o.getItem(bo)),e[1]=l):l=e[1];const[a,d]=c.useState(l);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=()=>fc(o.getItem(mc)),e[2]=u):u=e[2];const[m,h]=c.useState(u);let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>bv(o.getItem(uc)),e[3]=y):y=e[3];const[b,S]=c.useState(y),v=c.useRef(0),g=c.useRef(!1),f=c.useRef(!1),x=c.useRef(null),p=c.useRef(null);let w;e[4]!==n?(w=()=>{if(n)return;const ne=p.current;if(p.current=null,x.current=null,!ne)return;const{projects:Y}=Ht.getState(),F=Y.map(J=>({...J,sidebarCollapsed:ne.has(J.id)}));Mr({projects:F}).catch(yv)},e[4]=n,e[5]=w):w=e[5];const N=w;let C;e[6]!==N||e[7]!==n?(C=ne=>{!globalThis.window||n||(p.current=ne,x.current!==null&&window.clearTimeout(x.current),x.current=window.setTimeout(()=>{N()},700))},e[6]=N,e[7]=n,e[8]=C):C=e[8];const k=C;let A,D;e[9]===Symbol.for("react.memo_cache_sentinel")?(A=()=>()=>{globalThis.window&&x.current!==null&&window.clearTimeout(x.current),x.current=null,p.current=null},D=[],e[9]=A,e[10]=D):(A=e[9],D=e[10]),c.useEffect(A,D);let P,M;e[11]!==b?(M=()=>{if(f.current)try{o.setItem(uc,JSON.stringify(Object.fromEntries(b.entries())))}catch{}},P=[b,o],e[11]=b,e[12]=P,e[13]=M):(P=e[12],M=e[13]),c.useEffect(M,P);let z,I;e[14]!==m?(z=()=>{if(g.current)try{o.setItem(mc,JSON.stringify(Array.from(m)))}catch{}},I=[m,o],e[14]=m,e[15]=z,e[16]=I):(z=e[15],I=e[16]),c.useEffect(z,I);let V;e[17]!==r||e[18]!==k?(V=()=>{v.current=Date.now()+150,g.current=!0,h(new Set),d(()=>{const ne=new Set(r.map(wv));try{o.setItem(bo,JSON.stringify(Array.from(ne)))}catch{}return k(ne),ne})},e[17]=r,e[18]=k,e[19]=V):V=e[19];const T=V;let _;e[20]!==k?(_=()=>{v.current=Date.now()+150,g.current=!0,h(new Set),d(()=>{const ne=new Set;try{o.setItem(bo,JSON.stringify([]))}catch{}return k(ne),ne})},e[20]=k,e[21]=_):_=e[21];const O=_;let j;e[22]!==k?(j=ne=>{v.current=Date.now()+150,d(Y=>{const F=new Set(Y);F.has(ne)?F.delete(ne):F.add(ne);try{o.setItem(bo,JSON.stringify(Array.from(F)))}catch{}return k(F),F})},e[22]=k,e[23]=j):j=e[23];const E=j;let L;e[24]===Symbol.for("react.memo_cache_sentinel")?(L=ne=>{g.current=!0,h(Y=>{const F=new Set(Y);return F.has(ne)?F.delete(ne):F.add(ne),F})},e[24]=L):L=e[24];const U=L;let X;e[25]===Symbol.for("react.memo_cache_sentinel")?(X=ne=>{f.current=!0,S(ne)},e[25]=X):X=e[25];const Q=X,{getOrderedGroups:me}=pv(b);let re;e[26]!==m||e[27]!==a||e[28]!==b?(re={collapsedProjects:a,collapsedGroups:m,groupOrderByProject:b},e[26]=m,e[27]=a,e[28]=b,e[29]=re):re=e[29];const G=re;let ee;e[30]!==T||e[31]!==O||e[32]!==me||e[33]!==k||e[34]!==E?(ee={setCollapsedProjects:d,toggleProject:E,collapseAllProjects:T,expandAllProjects:O,scheduleCollapsedProjectsPersist:k,setCollapsedGroups:h,toggleGroup:U,setGroupOrderByProject:Q,getOrderedGroups:me},e[30]=T,e[31]=O,e[32]=me,e[33]=k,e[34]=E,e[35]=ee):ee=e[35];const ue=ee;let W;return e[36]!==ue||e[37]!==G?(W={state:G,actions:ue},e[36]=ue,e[37]=G,e[38]=W):W=e[38],W};function yv(){}function wv(t){return t.id}const Sv=5*6e4,vv=t=>{const e=Ye.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:i,setProjectRepoStatus:o,setProjectRootBranches:l}=t,a=r===void 0?!0:r,{git:d}=Pn(),u=$n(jv);let m,h;e[0]!==a||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==o?(m=()=>{if(!a||!d||n.length===0){o(new Map);return}n.forEach(C=>{Mi(()=>u(C.normalizedPath,d))})},h=[a,n,d,u,o],e[0]=a,e[1]=u,e[2]=d,e[3]=n,e[4]=o,e[5]=m,e[6]=h):(m=e[5],h=e[6]),c.useEffect(m,h);let y,b;e[7]!==a||e[8]!==i||e[9]!==n||e[10]!==o?(y=()=>{if(!a)return;const C=new Map;n.forEach(k=>{C.set(k.id,i.get(k.normalizedPath)?.isGitRepo??null)}),o(C)},b=[a,n,i,o],e[7]=a,e[8]=i,e[9]=n,e[10]=o,e[11]=y,e[12]=b):(y=e[11],b=e[12]),c.useEffect(y,b);let S;if(e[13]!==i||e[14]!==n){let C;e[16]!==i?(C=k=>{const A=i.get(k.normalizedPath)?.branch??"";return`${k.id}:${A}`},e[16]=i,e[17]=C):C=e[17],S=n.map(C).join("|"),e[13]=i,e[14]=n,e[15]=S}else S=e[15];const v=S;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[18]=g):g=e[18];const f=c.useRef(g);let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[19]=x):x=e[19];const p=c.useRef(x);let w;e[20]!==a||e[21]!==i||e[22]!==n||e[23]!==l?(w=()=>{if(!a)return;let C=!1;const k=setTimeout(()=>{(async()=>{const D=new Set(n.map(kv));for(const T of f.current.keys())D.has(T)||(f.current.delete(T),p.current.delete(T));const P=Date.now(),M=n.filter(T=>{const _=i.get(T.normalizedPath);if(_?.isGitRepo===!1)return f.current.delete(T.id),p.current.delete(T.id),!1;if(_?.isGitRepo!==!0||_.branch===null)return!1;const O=_.branch.trim(),j=`${T.normalizedPath}\0${O}`,E=f.current.get(T.id);if(E===j){const L=p.current.get(T.id);return L&&(L.at=P),!1}return!(E!==void 0&&P-(p.current.get(T.id)?.at??0)<Sv)});if(M.length===0)return;const z=await Qf(M,2,async T=>{const _=i.get(T.normalizedPath)?.branch?.trim()??"",O=`${T.normalizedPath}\0${_}`,j=await Mi(()=>oi(T.normalizedPath,_?{knownBranch:_}:void 0)).catch(Cv);return{id:T.id,inputKey:O,branch:j}});if(C)return;const I=z.filter(Nv);if(I.length===0)return;const V=Date.now();l(T=>{const _=new Map(T);return I.forEach(O=>{const{id:j,branch:E}=O;E&&_.set(j,E)}),_}),I.forEach(T=>{const{id:_,inputKey:O,branch:j}=T;f.current.set(_,O),j&&p.current.set(_,{branch:j,at:V})})})()},150);return()=>{C=!0,clearTimeout(k)}},e[20]=a,e[21]=i,e[22]=n,e[23]=l,e[24]=w):w=e[24];let N;e[25]!==a||e[26]!==i||e[27]!==n||e[28]!==v||e[29]!==l?(N=[a,n,v,i,l],e[25]=a,e[26]=i,e[27]=n,e[28]=v,e[29]=l,e[30]=N):N=e[30],c.useEffect(w,N)};function jv(t){return t.ensureStatus}function kv(t){return t.id}function Cv(){return null}function Nv(t){return t.branch}const Av=t=>{const e=Ye.c(10),{open:n,onOpenChange:r,project:i,onSave:o}=t;let l;e[0]!==o||e[1]!==n||e[2]!==i?(l=n&&i?s.jsx(Fp,{project:i,onIdentitySave:o,showWorktrees:!1}):null,e[0]=o,e[1]=n,e[2]=i,e[3]=l):l=e[3];let a;e[4]!==l?(a=s.jsx(As,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(An,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:l})})}),e[4]=l,e[5]=a):a=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==a?(d=s.jsx(Ns,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=d):d=e[9],d},Dv=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const i of t){r.has(i)||(r.add(i),n.push(i));const o=e.get(i);if(o)for(const l of o)r.has(l)||(r.add(l),n.push(l))}return n},gs=or()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,i)=>{const o=e(),l=new Set(o.selectedIds);let a=o.scopeKey,d=o.anchorId;r!==null&&o.scopeKey!==null&&r!==o.scopeKey?(l.clear(),a=r,d=null):a===null&&r!==null&&(a=r);const m=i&&i.length>0?[n,...i]:[n];if(l.has(n)){for(const y of m)l.delete(y);d===n&&(d=null)}else{for(const y of m)l.add(y);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:a,anchorId:d})},setRange:(n,r,i,o,l)=>{const a=e();if(i.length===0)return;const d=n&&i.includes(n)?n:i[0],u=i.indexOf(d),m=i.indexOf(r);if(u<0||m<0)return;const[h,y]=u<=m?[u,m]:[m,u],b=i.slice(h,y+1),S=Dv(b,l),g=o!==null&&a.scopeKey!==null&&o!==a.scopeKey?new Set:new Set(a.selectedIds);for(const f of S)g.add(f);t({selectedIds:g,scopeKey:o??a.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const i=new Set(r.selectedIds);for(const o of n)i.delete(o);i.size!==r.selectedIds.size&&(i.size===0?t({selectedIds:i,scopeKey:null,anchorId:null}):t({selectedIds:i}))}}));function Pv(t){const e=Ye.c(213),{t:n}=ht(),{hideDirectoryControls:r,showProjectDisplayControls:i,showRecentControls:o,handleOpenDirectoryDialog:l,onOpenScheduled:a,onOpenMultiRun:d,canOpenMultiRun:u,onOpenArchive:m,headerActionIconClass:h,headerActionButtonClass:y,isSessionSearchOpen:b,setIsSessionSearchOpen:S,sessionSearchInputRef:v,sessionSearchQuery:g,setSessionSearchQuery:f,hasSessionSearchQuery:x,searchMatchCount:p,collapseAllProjects:w,expandAllProjects:N}=t,C=gs(zv),k=gs(Wv),A=us($v),D=us(Lv),P=us(_v),M=us(Fv),z=us(Bv),I=us(Ov),V=us(Mv),T=us(Rv),_=us(Ev),O=us(Iv),j=i&&_==="single";if(r)return null;let E;e[0]!==y?(E=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=y,e[1]=E):E=e[1];let L;e[2]!==n?(L=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=L):L=e[3];let U;e[4]!==h?(U=s.jsx(R,{name:"folder-add",className:h}),e[4]=h,e[5]=U):U=e[5];let X;e[6]!==l||e[7]!==E||e[8]!==L||e[9]!==U?(X=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:E,"aria-label":L,children:U})}),e[6]=l,e[7]=E,e[8]=L,e[9]=U,e[10]=X):X=e[10];let Q;e[11]!==n?(Q=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=Q):Q=e[12];let me;e[13]!==Q?(me=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Q})}),e[13]=Q,e[14]=me):me=e[14];let re;e[15]!==X||e[16]!==me?(re=s.jsxs(yt,{delayDuration:500,children:[X,me]}),e[15]=X,e[16]=me,e[17]=re):re=e[17];let G;e[18]!==y?(G=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=y,e[19]=G):G=e[19];let ee;e[20]!==n?(ee=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=ee):ee=e[21];let ue;e[22]!==h?(ue=s.jsx(R,{name:"calendar-schedule",className:h}),e[22]=h,e[23]=ue):ue=e[23];let W;e[24]!==a||e[25]!==G||e[26]!==ee||e[27]!==ue?(W=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:G,"aria-label":ee,children:ue})}),e[24]=a,e[25]=G,e[26]=ee,e[27]=ue,e[28]=W):W=e[28];let ne;e[29]!==n?(ne=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=ne):ne=e[30];let Y;e[31]!==ne?(Y=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[31]=ne,e[32]=Y):Y=e[32];let F;e[33]!==W||e[34]!==Y?(F=s.jsxs(yt,{delayDuration:500,children:[W,Y]}),e[33]=W,e[34]=Y,e[35]=F):F=e[35];let J;e[36]!==y?(J=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=y,e[37]=J):J=e[37];let ie;e[38]!==n?(ie=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=ie):ie=e[39];const xe=!u;let ge;e[40]!==h?(ge=s.jsx(Yf,{className:h}),e[40]=h,e[41]=ge):ge=e[41];let Ce;e[42]!==d||e[43]!==J||e[44]!==ie||e[45]!==xe||e[46]!==ge?(Ce=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:J,"aria-label":ie,disabled:xe,children:ge})}),e[42]=d,e[43]=J,e[44]=ie,e[45]=xe,e[46]=ge,e[47]=Ce):Ce=e[47];let Re;e[48]!==n?(Re=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=Re):Re=e[49];let ce;e[50]!==Re?(ce=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Re})}),e[50]=Re,e[51]=ce):ce=e[51];let ye;e[52]!==Ce||e[53]!==ce?(ye=s.jsxs(yt,{delayDuration:500,children:[Ce,ce]}),e[52]=Ce,e[53]=ce,e[54]=ye):ye=e[54];let be;e[55]!==y?(be=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=y,e[56]=be):be=e[56];let te;e[57]!==n?(te=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=te):te=e[58];let pe;e[59]!==h?(pe=s.jsx(R,{name:"archive",className:h}),e[59]=h,e[60]=pe):pe=e[60];let Pe;e[61]!==m||e[62]!==be||e[63]!==te||e[64]!==pe?(Pe=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:be,"aria-label":te,children:pe})}),e[61]=m,e[62]=be,e[63]=te,e[64]=pe,e[65]=Pe):Pe=e[65];let de;e[66]!==n?(de=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=de):de=e[67];let he;e[68]!==de?(he=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:de})}),e[68]=de,e[69]=he):he=e[69];let fe;e[70]!==Pe||e[71]!==he?(fe=s.jsxs(yt,{delayDuration:500,children:[Pe,he]}),e[70]=Pe,e[71]=he,e[72]=fe):fe=e[72];let B;e[73]!==F||e[74]!==ye||e[75]!==fe||e[76]!==re?(B=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[re,F,ye,fe]}),e[73]=F,e[74]=ye,e[75]=fe,e[76]=re,e[77]=B):B=e[77];let H;e[78]!==S?(H=()=>S(Tv),e[78]=S,e[79]=H):H=e[79];let ke;e[80]!==y?(ke=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=y,e[81]=ke):ke=e[81];let Se;e[82]!==n?(Se=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=Se):Se=e[83];let Be;e[84]!==h?(Be=s.jsx(R,{name:"search",className:h}),e[84]=h,e[85]=Be):Be=e[85];let _e;e[86]!==b||e[87]!==H||e[88]!==ke||e[89]!==Se||e[90]!==Be?(_e=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:H,className:ke,"aria-label":Se,"aria-expanded":b,children:Be})}),e[86]=b,e[87]=H,e[88]=ke,e[89]=Se,e[90]=Be,e[91]=_e):_e=e[91];let Te;e[92]!==n?(Te=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=Te):Te=e[93];let Z;e[94]!==Te?(Z=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Te})}),e[94]=Te,e[95]=Z):Z=e[95];let Ne;e[96]!==_e||e[97]!==Z?(Ne=s.jsxs(yt,{delayDuration:500,children:[_e,Z]}),e[96]=_e,e[97]=Z,e[98]=Ne):Ne=e[98];const Me=C&&"bg-interactive-hover text-primary";let $;e[99]!==y||e[100]!==Me?($=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent",Me),e[99]=y,e[100]=Me,e[101]=$):$=e[101];let ae;e[102]!==C||e[103]!==n?(ae=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=C,e[103]=n,e[104]=ae):ae=e[104];let se;e[105]!==h?(se=s.jsx(R,{name:"checkbox-multiple",className:h}),e[105]=h,e[106]=se):se=e[106];let we;e[107]!==C||e[108]!==$||e[109]!==ae||e[110]!==se||e[111]!==k?(we=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:$,"aria-label":ae,"aria-pressed":C,children:se})}),e[107]=C,e[108]=$,e[109]=ae,e[110]=se,e[111]=k,e[112]=we):we=e[112];let Ke;e[113]!==C||e[114]!==n?(Ke=n(C?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=C,e[114]=n,e[115]=Ke):Ke=e[115];let Qe;e[116]!==Ke?(Qe=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ke})}),e[116]=Ke,e[117]=Qe):Qe=e[117];let He;e[118]!==we||e[119]!==Qe?(He=s.jsxs(yt,{delayDuration:500,children:[we,Qe]}),e[118]=we,e[119]=Qe,e[120]=He):He=e[120];let le;e[121]!==y?(le=Ie(y,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=y,e[122]=le):le=e[122];let K;e[123]!==n?(K=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=K):K=e[124];let ve;e[125]!==h?(ve=s.jsx(R,{name:"equalizer-2",className:h}),e[125]=h,e[126]=ve):ve=e[126];let $e;e[127]!==le||e[128]!==K||e[129]!==ve?($e=s.jsx(bt,{asChild:!0,children:s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:le,"aria-label":K,children:ve})})}),e[127]=le,e[128]=K,e[129]=ve,e[130]=$e):$e=e[130];let We;e[131]!==n?(We=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=We):We=e[132];let Le;e[133]!==We?(Le=s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:We})}),e[133]=We,e[134]=Le):Le=e[134];let Fe;e[135]!==$e||e[136]!==Le?(Fe=s.jsxs(yt,{delayDuration:500,children:[$e,Le]}),e[135]=$e,e[136]=Le,e[137]=Fe):Fe=e[137];let Ge;e[138]!==n?(Ge=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=Ge):Ge=e[139];let rt;e[140]!==Ge?(rt=s.jsx(ko,{children:Ge}),e[140]=Ge,e[141]=rt):rt=e[141];let St;e[142]!==P||e[143]!==M||e[144]!==n?(St=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]].map(At=>{const[Ot,$t]=At;return s.jsxs(Ut,{onClick:()=>{M(Ot),Mr({sidebarProjectSortOrder:Ot})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n($t)}),P===Ot?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},Ot)}),e[142]=P,e[143]=M,e[144]=n,e[145]=St):St=e[145];let Rt;e[146]===Symbol.for("react.memo_cache_sentinel")?(Rt=s.jsx(Ls,{}),e[146]=Rt):Rt=e[146];let ze;e[147]!==_||e[148]!==O||e[149]!==i||e[150]!==n?(ze=i?s.jsxs(s.Fragment,{children:[s.jsx(ko,{children:n("sessions.sidebar.header.projectDisplay.label")}),[["all","sessions.sidebar.header.projectDisplay.all"],["single","sessions.sidebar.header.projectDisplay.single"]].map(At=>{const[Ot,$t]=At;return s.jsxs(Ut,{onClick:()=>{O(Ot),Mr({sidebarProjectDisplayMode:Ot})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n($t)}),_===Ot?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},Ot)}),s.jsx(Ls,{})]}):null,e[147]=_,e[148]=O,e[149]=i,e[150]=n,e[151]=ze):ze=e[151];let Pt;e[152]!==n?(Pt=n("sessions.sidebar.header.grouping.label"),e[152]=n,e[153]=Pt):Pt=e[153];let Nt;e[154]!==Pt?(Nt=s.jsx(ko,{children:Pt}),e[154]=Pt,e[155]=Nt):Nt=e[155];let Tt;e[156]!==z||e[157]!==I||e[158]!==n?(Tt=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(At=>{const[Ot,$t]=At;return s.jsxs(Ut,{onClick:()=>{I(Ot),Mr({sidebarSessionGroupingMode:Ot})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n($t)}),z===Ot?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},Ot)}),e[156]=z,e[157]=I,e[158]=n,e[159]=Tt):Tt=e[159];let Et;e[160]===Symbol.for("react.memo_cache_sentinel")?(Et=s.jsx(Ls,{}),e[160]=Et):Et=e[160];let vt;e[161]!==j||e[162]!==o||e[163]!==A||e[164]!==n||e[165]!==D?(vt=o&&!j?s.jsxs(Ut,{onClick:()=>{D(),Mr({sidebarShowRecentSection:!A})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),A?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[161]=j,e[162]=o,e[163]=A,e[164]=n,e[165]=D,e[166]=vt):vt=e[166];let Ct;e[167]!==n?(Ct=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[167]=n,e[168]=Ct):Ct=e[168];let It;e[169]!==Ct?(It=s.jsx("span",{children:Ct}),e[169]=Ct,e[170]=It):It=e[170];let mt;e[171]!==V?(mt=V?s.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null,e[171]=V,e[172]=mt):mt=e[172];let Ze;e[173]!==It||e[174]!==mt||e[175]!==T?(Ze=s.jsxs(Ut,{onClick:T,className:"flex items-center justify-between",children:[It,mt]}),e[173]=It,e[174]=mt,e[175]=T,e[176]=Ze):Ze=e[176];let je;e[177]!==w||e[178]!==N||e[179]!==j||e[180]!==n?(je=j?null:s.jsxs(s.Fragment,{children:[s.jsx(Ls,{}),s.jsxs(Ut,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(R,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(Ut,{onClick:N,className:"flex items-center gap-2",children:[s.jsx(R,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]}),e[177]=w,e[178]=N,e[179]=j,e[180]=n,e[181]=je):je=e[181];let ot;e[182]!==rt||e[183]!==St||e[184]!==ze||e[185]!==Nt||e[186]!==Tt||e[187]!==vt||e[188]!==Ze||e[189]!==je?(ot=s.jsxs(Zs,{align:"end",className:"min-w-[180px]",children:[rt,St,Rt,ze,Nt,Tt,Et,vt,Ze,je]}),e[182]=rt,e[183]=St,e[184]=ze,e[185]=Nt,e[186]=Tt,e[187]=vt,e[188]=Ze,e[189]=je,e[190]=ot):ot=e[190];let ct;e[191]!==Fe||e[192]!==ot?(ct=s.jsxs(en,{children:[Fe,ot]}),e[191]=Fe,e[192]=ot,e[193]=ct):ct=e[193];let Mt;e[194]!==Ne||e[195]!==He||e[196]!==ct?(Mt=s.jsxs("div",{className:"flex items-center gap-1.5",children:[Ne,He,ct]}),e[194]=Ne,e[195]=He,e[196]=ct,e[197]=Mt):Mt=e[197];let Je;e[198]!==B||e[199]!==Mt?(Je=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[B,Mt]}),e[198]=B,e[199]=Mt,e[200]=Je):Je=e[200];let nt;e[201]!==x||e[202]!==b||e[203]!==p||e[204]!==v||e[205]!==g||e[206]!==S||e[207]!==f||e[208]!==n?(nt=b?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[x?s.jsx("span",{children:p===1?n("sessions.sidebar.header.search.matchCountSingle",{count:p}):n("sessions.sidebar.header.search.matchCountPlural",{count:p})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:v,value:g,onChange:At=>f(At.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:At=>{At.key==="Escape"&&(At.stopPropagation(),x?f(""):S(!1))}}),g.length>0?s.jsx("button",{type:"button",onClick:()=>f(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[201]=x,e[202]=b,e[203]=p,e[204]=v,e[205]=g,e[206]=S,e[207]=f,e[208]=n,e[209]=nt):nt=e[209];let jt;return e[210]!==Je||e[211]!==nt?(jt=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[Je,nt]})}),e[210]=Je,e[211]=nt,e[212]=jt):jt=e[212],jt}function Tv(t){return!t}function Iv(t){return t.setProjectDisplayMode}function Ev(t){return t.projectDisplayMode}function Rv(t){return t.toggleStickyZoneHeaders}function Mv(t){return t.stickyZoneHeaders}function Ov(t){return t.setSessionGroupingMode}function Bv(t){return t.sessionGroupingMode}function Fv(t){return t.setProjectSortOrder}function _v(t){return t.projectSortOrder}function Lv(t){return t.toggleRecentSection}function $v(t){return t.showRecentSection}function Wv(t){return t.toggleMode}function zv(t){return t.enabled}function Vv(t){const e=Ye.c(8),{t:n}=ht(),r=t.onNewSession;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(R,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=i):i=e[0];let o;e[1]!==n?(o=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==o?(l=s.jsx("span",{className:"truncate",children:o}),e[3]=o,e[4]=l):l=e[4];let a;return e[5]!==t.onNewSession||e[6]!==l?(a=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 pt-1.5",children:s.jsxs("button",{type:"button",onClick:r,className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left typography-ui-label font-normal text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[i,l]})}),e[5]=t.onNewSession,e[6]=l,e[7]=a):a=e[7],a}const vi="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function Uv(t){const e=Ye.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:i,onOpenUpdate:o,showRuntimeButtons:l,showUpdateButton:a}=t,d=l===void 0?!0:l,u=a===void 0?!0:a,{t:m}=ht();if(!d&&!u)return null;let h;e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(h=d?s.jsxs(s.Fragment,{children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:vi,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(R,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:vi,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(R,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:vi,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(R,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=h):h=e[5];let y;e[6]!==o||e[7]!==u||e[8]!==m?(y=u?s.jsx(at,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:o,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=o,e[7]=u,e[8]=m,e[9]=y):y=e[9];let b;return e[10]!==h||e[11]!==y?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[h,y]}),e[10]=h,e[11]=y,e[12]=b):b=e[12],b}const Hv=t=>{const e=Ye.c(12),{normalizedProjects:n,enabled:r,ownership:i,isSessionsLoading:o,hasAuthoritativeGlobalSessions:l,isWorktreeTopologyLoading:a,unresolvedWorktreeProjectPaths:d,foldersMap:u,createFolder:m,addSessionToFolder:h}=t,y=r===void 0?!0:r;let b,S;e[0]!==h||e[1]!==m||e[2]!==y||e[3]!==u||e[4]!==l||e[5]!==o||e[6]!==a||e[7]!==n||e[8]!==i||e[9]!==d?(b=()=>{!y||o||!l||a||n.forEach(v=>{if(d.has(v.normalizedPath))return;const g=Ed(v.normalizedPath),f=i.archivedSessionsByProject.get(v.id)??[],x=u[g]??[],p=new Map(x.map(Kv));f.forEach(w=>{const N=Xf(w,v.normalizedPath),C=N.toLowerCase();let k=p.get(C);k||(k=m(g,N),p.set(C,k)),k.sessionIds.includes(w.id)||h(g,k.id,w.id)})})},S=[n,y,i,o,l,a,d,u,m,h],e[0]=h,e[1]=m,e[2]=y,e[3]=u,e[4]=l,e[5]=o,e[6]=a,e[7]=n,e[8]=i,e[9]=d,e[10]=b,e[11]=S):(b=e[10],S=e[11]),c.useEffect(b,S)};function Kv(t){return[t.name.toLowerCase(),t]}function Gv({activeProjectId:t,currentSessionId:e,currentSessionOwnerProjectId:n,projectMap:r,metaByProject:i,rememberedSessionId:o,fallbackSessionId:l}){if(e&&n===t)return{kind:"preserve-current"};if(n==null){const u=!!(e&&Array.from(i.entries()).some(([m,h])=>m!==t&&h.has(e)));if(e&&r&&!u)return{kind:"preserve-current"}}if(!r||r.size===0)return{kind:"open-draft"};const d=(o&&r.has(o)?o:null)??l;return!d||d===e?{kind:"none"}:{kind:"select-session",sessionId:d}}const qv=t=>{const e=Ye.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:i,setActiveSessionByProject:o,currentSessionId:l,currentSessionOwnerProjectId:a,handleSessionSelect:d,newSessionDraftOpen:u,mobileVariant:m,openNewSessionDraft:h,setSessionSwitcherOpen:y}=t;let b,S;if(e[0]!==n){S=new Map,b=new Map;const C=(k,A,D,P)=>{S.has(k)||S.set(k,new Map);const M=S.get(k);P.forEach(z=>{const I=dt(z.worktree?.path??z.session.directory??D??A);M.set(z.session.id,{directory:I}),b.has(k)||b.set(k,{id:z.session.id,directory:I}),z.children.length>0&&C(k,A,I,z.children)})};n.forEach(k=>{k.groups.forEach(A=>{C(k.project.id,k.project.normalizedPath,A.directory,A.sessions)})}),e[0]=n,e[1]=b,e[2]=S}else b=e[1],S=e[2];let v;e[3]!==b||e[4]!==S?(v={metaByProject:S,firstSessionByProject:b},e[3]=b,e[4]=S,e[5]=v):v=e[5];const g=v,f=c.useRef(null);let x,p;e[6]!==r||e[7]!==i||e[8]!==l||e[9]!==a||e[10]!==d||e[11]!==m||e[12]!==u||e[13]!==h||e[14]!==n||e[15]!==g||e[16]!==o||e[17]!==y?(x=()=>{if(!r||u||Ae.getState().isNewWorktreeDialogOpen||f.current===r)return;const C=n.find(P=>P.project.id===r);if(!C)return;const k=g.metaByProject.get(r);if(l&&k&&k.has(l)){f.current=r,o(P=>{if(P.get(r)===l)return P;const M=new Map(P);return M.set(r,l),M});return}const A=Gv({activeProjectId:r,currentSessionId:l,currentSessionOwnerProjectId:a,projectMap:k,metaByProject:g.metaByProject,rememberedSessionId:i.get(r),fallbackSessionId:g.firstSessionByProject.get(r)?.id??null});if(A.kind==="preserve-current"){a===r&&(f.current=r);return}if(f.current=r,A.kind==="open-draft"){m&&y(!1),h({selectedProjectId:C.project.id,directoryOverride:C.project.normalizedPath});return}if(A.kind!=="select-session")return;const D=k?.get(A.sessionId)?.directory??null;d(A.sessionId,D)},p=[r,i,l,a,d,u,m,h,n,g,y,o],e[6]=r,e[7]=i,e[8]=l,e[9]=a,e[10]=d,e[11]=m,e[12]=u,e[13]=h,e[14]=n,e[15]=g,e[16]=o,e[17]=y,e[18]=x,e[19]=p):(x=e[18],p=e[19]),c.useLayoutEffect(x,p);let w,N;e[20]!==r||e[21]!==l||e[22]!==g||e[23]!==o?(w=()=>{if(!r||!l)return;const C=g.metaByProject.get(r);!C||!C.has(l)||o(k=>{if(k.get(r)===l)return k;const A=new Map(k);return A.set(r,l),A})},N=[r,l,g,o],e[20]=r,e[21]=l,e[22]=g,e[23]=o,e[24]=w,e[25]=N):(w=e[24],N=e[25]),c.useEffect(w,N)},Qv=t=>{const e=Ye.c(20);let n,r,i,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:i,sessionOwnerBySessionId:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=o):(n=e[1],r=e[2],i=e[3],o=e[4]);const l=qe(Yv),a=qe(Xv);let d;e[5]!==l||e[6]!==o?(d=l?o?.get(l)?.projectId??null:null,e[5]=l,e[6]=o,e[7]=d):d=e[7];const u=d;let m;e[8]!==r?(m=()=>new Map(r),e[8]=r,e[9]=m):m=e[9];const[h,y]=c.useState(m);let b;e[10]!==h||e[11]!==n||e[12]!==l||e[13]!==u||e[14]!==a?(b={...n,activeSessionByProject:h,setActiveSessionByProject:y,currentSessionId:l,currentSessionOwnerProjectId:u,newSessionDraftOpen:a},e[10]=h,e[11]=n,e[12]=l,e[13]=u,e[14]=a,e[15]=b):b=e[15],qv(b);let S,v;return e[16]!==h||e[17]!==i?(S=()=>{i(h)},v=[h,i],e[16]=h,e[17]=i,e[18]=S,e[19]=v):(S=e[18],v=e[19]),c.useEffect(S,v),null};function Yv(t){return t.currentSessionId}function Xv(t){return!!t.newSessionDraft?.open}const hc={selected:0,"active-project":1,expanded:2,visible:3,background:4};function rm(t){const e=new Map,n=(r,i,o)=>{const l=dt(r??null);if(!l)return;const a=e.get(l);a&&hc[a.priority]<=hc[i]||e.set(l,{directory:l,priority:i,reason:o})};for(const r of t.knownDirectories??[])n(r,"background","known-project");n(t.activeProjectDirectory,"active-project","project-expanded");for(const r of t.projectSections??[]){const i=!t.collapsedProjects.has(r.project.id);let o="background";r.project.id===t.activeProjectId?o="active-project":i&&(o="expanded"),n(r.project.normalizedPath,o,i?"project-expanded":"known-project");for(const l of r.groups){if(!l.directory||l.isArchivedBucket||l.isMain)continue;const a=i&&!t.collapsedGroups.has(`${r.project.id}:${l.id}`);let d="background";a?d="expanded":i&&(d="visible"),n(l.directory,d,a?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const Jv=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,pc=(t,e,n)=>{Jv(t.get(e),n)&&t.set(e,n)},Zv=t=>{const e=t;return dt(e.directory)??dt(e.project?.worktree)},e0=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},t0=(t,e,n,r,i=[])=>{const o=new Map,l=new Map;for(const S of e){const v=dt(S.normalizedPath);if(!v)continue;const g=l.get(v);(!g||S.id.localeCompare(g.id)<0)&&l.set(v,S),pc(o,v,{projectId:S.id,projectRoot:v,scopeDirectory:v,kind:"project"})}if(!r)for(const[S,v]of n){const g=dt(S),f=g?l.get(g):void 0;if(!(!f||!g))for(const x of v){const p=dt(x.path);p&&pc(o,p,{projectId:f.id,projectRoot:g,scopeDirectory:p,kind:"worktree"})}}const a=new Map,d=new Map,u=new Map,m=new Map,h=new Map,y=S=>{if(!S)return null;if(a.has(S))return a.get(S)??null;if(r){const x=o.get(S)??null;return a.set(S,x),x}const v=[];let g=S,f=null;for(;g;){if(a.has(g)){f=a.get(g)??null;break}if(v.push(g),f=o.get(g)??null,f)break;g=e0(g)}for(const x of v)a.set(x,f);return f},b=(S,v,g)=>{for(const f of S){const x=y(Zv(f));if(!x)continue;d.set(f.id,x);const p=v.get(x.projectId);if(p?p.push(f):v.set(x.projectId,[f]),!g)continue;const w=g.get(x.scopeDirectory);w?w.add(f.id):g.set(x.scopeDirectory,new Set([f.id]))}};return b(t,u,h),b(i,m),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:m,sessionsByScope:h,directoryResolutions:a.size}},s0=t=>{const e=Ye.c(7),{ownership:n}=t;let r;e[0]!==n?(r=d=>n.sessionsByProject.get(d)??[],e[0]=n,e[1]=r):r=e[1];const i=r;let o;e[2]!==n?(o=d=>n.archivedSessionsByProject.get(d)??[],e[2]=n,e[3]=o):o=e[3];const l=o;let a;return e[4]!==l||e[5]!==i?(a={getSessionsForProject:i,getArchivedSessionsForProject:l},e[4]=l,e[5]=i,e[6]=a):a=e[6],a},n0=[],r0=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:l,lastRepoStatus:a,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,filterSessionNodesForSearch:h,buildGroupSearchText:y,foldersMap:b,standaloneGroups:S}=t,v=c.useRef(new Map),g=c.useMemo(()=>{const A=v.current,D=new Map;let P=0,M=0;const z=(V,T)=>V.length===T.length&&V.every((_,O)=>_===T[O]),I=e.map(V=>{const T=n(V.id),_=r(V.id),O=i.get(V.normalizedPath)??n0,j=o.has(V.id)?!!o.get(V.id):a,E=l.get(V.id)??null,L=A.get(V.id);if(L&&L.project===V&&z(L.activeSessions,T)&&z(L.archivedSessions,_)&&L.availableWorktrees===O&&L.rootBranch===E&&L.isRepo===j&&L.buildGroupedSessions===d)return P+=1,D.set(V.id,L),L.section;M+=1;const U=Rd([...T,..._]),X=d(U,V.normalizedPath,O,E,j),Q={project:V,groups:X};return D.set(V.id,{project:V,activeSessions:T,archivedSessions:_,availableWorktrees:O,rootBranch:E,isRepo:j,buildGroupedSessions:d,section:Q}),Q});return v.current=D,P>0&&fn("ui.sidebar.project_section.reused",P),M>0&&fn("ui.sidebar.project_section.rebuilt",M),I},[e,n,r,i,o,a,d,l]),f=c.useMemo(()=>g,[g]),x=c.useMemo(()=>{const A=new WeakMap;if(!u)return A;const D=M=>M.reduce((z,I)=>z+1+D(I.children),0),P=M=>{const z=h(M.sessions,m),I=D(z),V=_o([y(M)],m),T=dt(M.directory??null),O=(T?b[T]??[]:[]).filter(j=>_o([j.name],m)).length;A.set(M,{filteredNodes:z,matchedSessionCount:I,folderNameMatchCount:O,groupMatches:V,hasMatch:V||I>0||O>0})};return f.forEach(M=>{M.groups.forEach(P)}),S.forEach(P),A},[u,f,S,h,m,y,b]),p=c.useMemo(()=>u?f.map(A=>({...A,groups:A.groups.filter(D=>x.get(D)?.hasMatch===!0)})).filter(A=>A.groups.length>0):f,[u,f,x]),w=u?p:f,N=c.useRef(new WeakMap),C=c.useMemo(()=>{const A=N.current;return w.map(D=>{const P=A.get(D);if(P&&P.query===m)return P.section;const M=D.groups.filter(j=>!j.isArchivedBucket),z=D.groups.filter(j=>j.isArchivedBucket),I=M.flatMap(j=>u?x.get(j)?.filteredNodes??[]:j.sessions),V=M.map(j=>({scopeKey:j.folderScopeKey??dt(j.directory??null),directory:j.directory??null})).filter(j=>!!j.scopeKey),T=M.find(j=>j.isMain)??null,_={id:"flat",label:T?.label??"",branch:T?.branch??null,description:T?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:T?.directory??D.project.normalizedPath,folderScopeKey:T?.folderScopeKey??D.project.normalizedPath,folderScopes:V,sessions:I};if(u){const j=M.map(E=>x.get(E)).filter(E=>!!E);x.set(_,{filteredNodes:I,matchedSessionCount:j.reduce((E,L)=>E+L.matchedSessionCount,0),folderNameMatchCount:j.reduce((E,L)=>E+L.folderNameMatchCount,0),groupMatches:j.some(E=>E.groupMatches),hasMatch:j.some(E=>E.hasMatch)})}const O={project:D.project,groups:[_,...z]};return A.set(D,{query:m,section:O}),O})},[x,u,m,w]),k=c.useMemo(()=>{if(!u)return 0;const A=(P,M)=>{const z=x.get(M);if(!z)return P;const I=z.folderNameMatchCount+(z.groupMatches?1:0);return P+z.matchedSessionCount+I},D=w.reduce((P,M)=>M.groups.reduce(A,P),0);return S.reduce(A,D)},[u,w,S,x]);return{projectSections:g,visibleProjectSections:f,groupSearchDataByGroup:x,searchableProjectSections:p,sectionsForRender:w,flatSectionsForRender:C,searchMatchCount:k}},o0=180,gc=600,i0=1,a0=6,ji=t=>`${t.directory}
|
|
912
|
-
${t.sessionId}`,l0=t=>t?.directory?.trim()||null,c0=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:i})=>{const o=c.useRef(new Map),l=c.useRef([]),a=c.useRef(new Set),d=c.useRef(0),u=c.useMemo(()=>Dn(),[]),m=c.useCallback(()=>{d.current+=1,l.current=[],o.current.forEach(b=>window.clearTimeout(b)),o.current.clear()},[]),h=c.useCallback(()=>{if(!(!t||u))for(;a.current.size<i0&&l.current.length>0;){const b=l.current.shift();if(!b)break;if(b.generation!==d.current||qe.getState().currentSessionId===b.sessionId||il(b.sessionId,b.directory).renderable)continue;const v=ji(b);a.current.add(v),i({directory:b.directory,sessionID:b.sessionId}).catch(()=>{}).finally(()=>{a.current.delete(v),h()})}},[t,u,i]),y=c.useCallback(b=>{const S=b?.id,v=l0(b);if(!t||u||!S||!v||S===e)return;const g={sessionId:S,directory:v,generation:d.current},f=ji(g);if(il(S,v).renderable||a.current.has(f)||l.current.some(w=>ji(w)===f))return;const x=o.current.get(f);x!==void 0&&window.clearTimeout(x);const p=window.setTimeout(()=>{if(o.current.delete(f),g.generation!==d.current)return;const w=l.current;w.length>=a0&&w.shift(),w.push(g),h()},o0);o.current.set(f,p)},[e,t,u,h]);c.useEffect(()=>{m()},[m,e,t,u]),c.useEffect(()=>{if(!t||u||!e||n.length===0)return;const b=window.setTimeout(()=>{const S=n.findIndex(v=>v.id===e);S<0||(y(n[S-1]),y(n[S+1]))},gc);return()=>window.clearTimeout(b)},[e,t,u,y,n]),c.useEffect(()=>{if(!t||u||!e||r.length===0)return;const b=window.setTimeout(()=>{const S=r.findIndex(v=>v.id===e);S<0||(y(r[S-1]),y(r[S+1]))},gc);return()=>window.clearTimeout(b)},[e,t,u,r,y]),c.useEffect(()=>m,[m])},d0=t=>{const e=Ye.c(3),n=qe(u0);let r;return e[0]!==t||e[1]!==n?(r={...t,currentSessionId:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],c0(r),null};function u0(t){return t.currentSessionId}const Io=t=>{const e=Ye.c(22),{id:n,projectLabel:r,projectIcon:i,projectColor:o,projectIconImage:l,projectIconBackground:a,isCollapsed:d,alwaysShowActions:u}=t,m=u===void 0?!1:u,{currentTheme:h}=nr(),y=i?Pa[i]:null,b=o?Ta[o]??null:null,S=d!==void 0,v=S?m?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let g;e[0]!==m||e[1]!==S||e[2]!==d?(g=S?s.jsx("span",{className:Ie("h-3.5 w-3.5 items-center justify-center text-muted-foreground",m?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:s.jsx(R,{name:d?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=m,e[1]=S,e[2]=d,e[3]=g):g=e[3];let f;e[4]!==m||e[5]!==h||e[6]!==S||e[7]!==b||e[8]!==v||e[9]!==n||e[10]!==a||e[11]!==l||e[12]!==y?(f=l?s.jsx("span",{className:Ie("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",S&&m?"hidden":"inline-flex",v),style:a?{backgroundColor:a}:void 0,children:s.jsx(Ia,{project:{id:n,iconImage:l},options:{themeVariant:h.metadata.variant,iconColor:h.colors.surface.foreground},className:"h-full w-full object-contain",fallback:y?s.jsx(R,{name:y,className:"h-3.5 w-3.5",style:b?{color:b}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:b?{color:b}:void 0})})}):y?s.jsx(R,{name:y,className:Ie("h-3.5 w-3.5",v),style:b?{color:b}:void 0}):s.jsx(R,{name:"folder",className:Ie("h-3.5 w-3.5 text-muted-foreground/80",v),style:b?{color:b}:void 0}),e[4]=m,e[5]=h,e[6]=S,e[7]=b,e[8]=v,e[9]=n,e[10]=a,e[11]=l,e[12]=y,e[13]=f):f=e[13];let x;e[14]!==g||e[15]!==f?(x=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[g,f]}),e[14]=g,e[15]=f,e[16]=x):x=e[16];let p;e[17]!==r?(p=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=p):p=e[18];let w;return e[19]!==x||e[20]!==p?(w=s.jsxs(s.Fragment,{children:[x,p]}),e[19]=x,e[20]=p,e[21]=w):w=e[21],w},m0=t=>{const e=Ye.c(62),{id:n,disabled:r,projectLabel:i,projectDescription:o,projectIcon:l,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,isRepo:h,isDesktopShell:y,hideDirectoryControls:b,alwaysShowActions:S,onToggle:v,onNewSession:g,onNewWorktreeSession:f,onManageWorktrees:x,onRenameStart:p,onClose:w,sentinelRef:N,children:C,showCreateButtons:k,hideHeader:A,statusIndicator:D,openSidebarMenuKey:P,setOpenSidebarMenuKey:M,projectPickerOptions:z,onProjectSelect:I}=t,V=r===void 0?!1:r,T=k===void 0?!0:k,_=A===void 0?!1:A,O=D===void 0?null:D,{t:j}=ht(),E=us(p0);let L;e[0]!==V||e[1]!==n?(L={id:n,disabled:V},e[0]=V,e[1]=n,e[2]=L):L=e[2];const{attributes:U,listeners:X,setNodeRef:Q,transform:me,transition:re,isDragging:G}=ii(L),ee=c.useRef(!1),ue=`project:${n}`,W=P===ue,[ne,Y]=c.useState(!1),F=!!(z&&I);let J;e[3]!==ue||e[4]!==M?(J=ke=>{ke&&Y(!1),M(ke?ue:null)},e[3]=ue,e[4]=M,e[5]=J):J=e[5];const ie=J;let xe;e[6]!==b||e[7]!==h||e[8]!==w||e[9]!==x||e[10]!==g||e[11]!==p||e[12]!==T||e[13]!==j?(xe=ke=>s.jsxs(s.Fragment,{children:[T&&!h&&!b&&g&&s.jsxs(ke,{onClick:g,children:[s.jsx(R,{name:"add",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.newSession")]}),h&&!b&&x&&s.jsxs(ke,{onClick:x,children:[s.jsx(R,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(ke,{onClick:p,children:[s.jsx(R,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.edit")]}),s.jsxs(ke,{onClick:w,className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1.5 h-4 w-4"}),j("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=b,e[7]=h,e[8]=w,e[9]=x,e[10]=g,e[11]=p,e[12]=T,e[13]=j,e[14]=xe):xe=e[14];const ge=xe,Ce=g0,Re=b0,ce=x0;let ye;e[15]===Symbol.for("react.memo_cache_sentinel")?(ye=ke=>{(ke.button===2||ke.button===0&&ke.ctrlKey)&&(ee.current=!0)},e[15]=ye):ye=e[15];const be=ye;let te;e[16]!==v?(te=ke=>{if(ke.currentTarget.blur(),ee.current){ee.current=!1;return}v()},e[16]=v,e[17]=te):te=e[17];const pe=te;let Pe;e[18]!==me?(Pe=ai.Transform.toString(me),e[18]=me,e[19]=Pe):Pe=e[19];let de;e[20]!==Pe||e[21]!==re?(de={transform:Pe,transition:re},e[20]=Pe,e[21]=re,e[22]=de):de=e[22];const he=G&&"opacity-30";let fe;e[23]!==he?(fe=Ie("relative",he),e[23]=he,e[24]=fe):fe=e[24];let B;e[25]!==S||e[26]!==U||e[27]!==ie||e[28]!==pe||e[29]!==b||e[30]!==_||e[31]!==n||e[32]!==m||e[33]!==ne||e[34]!==y||e[35]!==W||e[36]!==F||e[37]!==h||e[38]!==X||e[39]!==g||e[40]!==f||e[41]!==I||e[42]!==a||e[43]!==o||e[44]!==l||e[45]!==u||e[46]!==d||e[47]!==i||e[48]!==z||e[49]!==ge||e[50]!==N||e[51]!==T||e[52]!==O||e[53]!==E||e[54]!==j?(B=_?null:s.jsxs(s.Fragment,{children:[y&&s.jsx("div",{ref:N,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Zd,{open:ne,onOpenChange:Y,children:[s.jsx(Jd,{render:s.jsx("div",{className:Ie("-ml-2.5 -mr-2 text-left group/project select-none",E&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":E?"true":void 0,onContextMenu:ke=>{b||(ke.preventDefault(),Y(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...U,children:[F?s.jsxs(en,{children:[s.jsx(Js,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":j("sessions.sidebar.project.selectAria",{project:i}),children:[s.jsx(Io,{id:n,projectLabel:i,projectIcon:l,projectColor:a,projectIconImage:d,projectIconBackground:u}),s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Zs,{align:"start",className:"max-h-[70vh] min-w-[220px] overflow-y-auto",children:z?.map(ke=>s.jsxs(Ut,{onClick:()=>I?.(ke.id),className:"flex items-center justify-between gap-3",title:ke.projectDescription,children:[s.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:s.jsx(Io,{...ke})}),ke.id===n?s.jsx(R,{name:"check",className:"h-4 w-4 flex-shrink-0 text-primary"}):null]},ke.id))})]}):s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:be,onClick:pe,...X,className:Ie("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",h&&!b?S?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":S?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(Io,{id:n,projectLabel:i,projectIcon:l,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,alwaysShowActions:S}),O?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:O}):null]})}),s.jsx(xt,{side:"right",sideOffset:8,children:o})]}),s.jsxs("div",{className:Ie("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",T?"right-7":"right-0.5"),children:[T&&h&&!b&&f?s.jsxs(yt,{delayDuration:500,children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ke=>{ke.stopPropagation(),f()},className:Ie("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",S?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(R,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:j("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,b?null:s.jsxs(en,{open:W,onOpenChange:ie,children:[s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("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":S?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j("sessions.sidebar.project.actions.projectMenu"),onPointerDown:Re,onMouseDown:ce,onClick:Ce,children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Zs,{align:"end",className:"min-w-[180px]",children:ge(Ut)})]})]}),T&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(yt,{delayDuration:500,children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ke=>{ke.stopPropagation(),g()},className:Ie("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",S?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":j(h?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-4 w-4"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:j(h?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Xd,{className:"min-w-[180px]",children:ge(qn)})]})]}),e[25]=S,e[26]=U,e[27]=ie,e[28]=pe,e[29]=b,e[30]=_,e[31]=n,e[32]=m,e[33]=ne,e[34]=y,e[35]=W,e[36]=F,e[37]=h,e[38]=X,e[39]=g,e[40]=f,e[41]=I,e[42]=a,e[43]=o,e[44]=l,e[45]=u,e[46]=d,e[47]=i,e[48]=z,e[49]=ge,e[50]=N,e[51]=T,e[52]=O,e[53]=E,e[54]=j,e[55]=B):B=e[55];let H;return e[56]!==C||e[57]!==Q||e[58]!==de||e[59]!==fe||e[60]!==B?(H=s.jsxs("div",{ref:Q,style:de,className:fe,children:[B,C]}),e[56]=C,e[57]=Q,e[58]=de,e[59]=fe,e[60]=B,e[61]=H):H=e[61],H},f0=t=>{const e=Ye.c(21),{id:n,disabled:r,children:i}=t,o=r===void 0?!1:r;let l;e[0]!==o||e[1]!==n?(l={id:n,disabled:o},e[0]=o,e[1]=n,e[2]=l):l=e[2];const{listeners:a,setNodeRef:d,setActivatorNodeRef:u,transform:m,transition:h,isDragging:y}=ii(l);let b;e[3]!==a||e[4]!==u?(b={listeners:a,setActivatorNodeRef:u},e[3]=a,e[4]=u,e[5]=b):b=e[5];const S=b;let v;e[6]!==m?(v=ai.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let g;e[8]!==v||e[9]!==h?(g={transform:v,transition:h},e[8]=v,e[9]=h,e[10]=g):g=e[10];const f=y&&"opacity-50";let x;e[11]!==f?(x=Ie("space-y-0.5 rounded-md",f),e[11]=f,e[12]=x):x=e[12];let p;e[13]!==i||e[14]!==S?(p=i(S),e[13]=i,e[14]=S,e[15]=p):p=e[15];let w;return e[16]!==d||e[17]!==g||e[18]!==x||e[19]!==p?(w=s.jsx("div",{ref:d,style:g,className:x,children:p}),e[16]=d,e[17]=g,e[18]=x,e[19]=p,e[20]=w):w=e[20],w},h0=c.memo(f0);function p0(t){return t.stickyZoneHeaders}function g0(t){t.stopPropagation()}function b0(t){t.stopPropagation()}function x0(t){t.stopPropagation()}const y0=(t,e)=>{const n=new Set,r=new Set,i=(o,l)=>{n.add(o.session.id),(!l||e)&&r.add(o.session.id),o.children.forEach(a=>i(a,!0))};return t.forEach(o=>i(o,!1)),{active:n,unread:r}},om=t=>{const e=Ye.c(9),{nodes:n,includeUnreadSubtasks:r,enabled:i}=t,o=i===void 0?!0:i;let l;e[0]!==r||e[1]!==n?(l=y0(n,r),e[0]=r,e[1]=n,e[2]=l):l=e[2];const a=l;let d;e[3]!==o||e[4]!==a.active?(d=y=>{if(!o)return null;for(const b of a.active){const S=y.statusById.get(b)?.status.type;if(S==="busy"||S==="retry")return"active"}return null},e[3]=o,e[4]=a.active,e[5]=d):d=e[5];const u=Ea(d);let m;e[6]!==o||e[7]!==a.unread?(m=y=>{if(!o)return null;for(const b of a.unread)if((y.index.session.unseenCount[b]??0)>0)return"unread";return null},e[6]=o,e[7]=a.unread,e[8]=m):m=e[8];const h=Ra(m);return u??h};function im(t){const e=Ye.c(6),{state:n,activeLabel:r,unreadLabel:i,className:o}=t,l=n==="active"?r:i,a=n==="active"?"bg-primary":"bg-[var(--status-info)]";let d;e[0]!==o||e[1]!==a?(d=Ie("h-1.5 w-1.5 shrink-0 rounded-full",a,o),e[0]=o,e[1]=a,e[2]=d):d=e[2];let u;return e[3]!==l||e[4]!==d?(u=s.jsx("span",{className:d,"aria-label":l,title:l}),e[3]=l,e[4]=d,e[5]=u):u=e[5],u}const w0=t=>{const e=Ye.c(11),{nodes:n,includeUnreadSubtasks:r}=t,{t:i}=ht();let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=om(o);if(!l)return null;let a;e[3]!==i?(a=i("sessions.sidebar.session.status.active"),e[3]=i,e[4]=a):a=e[4];let d;e[5]!==i?(d=i("sessions.sidebar.session.status.unread"),e[5]=i,e[6]=d):d=e[6];let u;return e[7]!==l||e[8]!==a||e[9]!==d?(u=s.jsx(im,{state:l,activeLabel:a,unreadLabel:d}),e[7]=l,e[8]=a,e[9]=d,e[10]=u):u=e[10],u},S0=t=>{const e=Ye.c(82),{folder:n,displayName:r,sessions:i,subFolderItems:o,isCollapsed:l,collapsedActivityState:a,onToggle:d,onRename:u,onDelete:m,children:h,mobileVariant:y,alwaysShowActions:b,isRenaming:S,renameDraft:v,onRenameDraftChange:g,onRenameSave:f,onRenameCancel:x,droppableRef:p,isDropTarget:w,onNewSession:N,depth:C,hideActions:k,archivedBucket:A}=t,D=a===void 0?null:a,M=b===void 0?y===void 0?!1:y:b,z=S===void 0?!1:S,I=v===void 0?"":v,V=w===void 0?!1:w,T=k===void 0?!1:k,_=A===void 0?!1:A,{t:O}=ht(),[j,E]=c.useState(!1),[L,U]=c.useState(""),X=c.useRef(null),Q=z||j,me=z?I:L;let re;e[0]!==n.name?(re=()=>{U(n.name),E(!0)},e[0]=n.name,e[1]=re):re=e[1];const G=re;let ee;e[2]!==me||e[3]!==n.name||e[4]!==z||e[5]!==u||e[6]!==f?(ee=()=>{const Te=me.trim();Te&&Te!==n.name&&u(Te),z&&f&&f(),E(!1),U("")},e[2]=me,e[3]=n.name,e[4]=z,e[5]=u,e[6]=f,e[7]=ee):ee=e[7];const ue=ee;let W;e[8]!==z||e[9]!==x?(W=()=>{z&&x&&x(),E(!1),U("")},e[8]=z,e[9]=x,e[10]=W):W=e[10];const ne=W;let Y;e[11]!==z||e[12]!==g?(Y=Te=>{z&&g?g(Te):U(Te)},e[11]=z,e[12]=g,e[13]=Y):Y=e[13];const F=Y;let J,ie;e[14]!==z?(J=()=>{if(!z)return;const Te=()=>{const Me=X.current;Me&&(Me.focus(),Me.select())},Z=requestAnimationFrame(Te),Ne=window.setTimeout(Te,0);return()=>{cancelAnimationFrame(Z),window.clearTimeout(Ne)}},ie=[z],e[14]=z,e[15]=J,e[16]=ie):(J=e[15],ie=e[16]),c.useEffect(J,ie);const xe=l?"folder":"folder-open",ge=V&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Ce;e[17]!==ge?(Ce=Ie("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ge),e[17]=ge,e[18]=Ce):Ce=e[18];let Re;e[19]!==d||e[20]!==Q?(Re=Q?void 0:Te=>{Te.currentTarget.blur(),d()},e[19]=d,e[20]=Q,e[21]=Re):Re=e[21];const ce=Q?void 0:"button",ye=Q?void 0:0;let be;e[22]!==d||e[23]!==Q?(be=Q?void 0:Te=>{(Te.key==="Enter"||Te.key===" ")&&(Te.preventDefault(),d())},e[22]=d,e[23]=Q,e[24]=be):be=e[24];let te;e[25]!==n.name||e[26]!==l||e[27]!==O?(te=l?O("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):O("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=l,e[27]=O,e[28]=te):te=e[28];const pe=_?M?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":M?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let Pe;e[29]!==pe?(Pe=Ie("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",pe),e[29]=pe,e[30]=Pe):Pe=e[30];const de=V?"text-primary":"text-muted-foreground";let he;e[31]!==de?(he=Ie("h-3.5 w-3.5 flex-shrink-0",de),e[31]=de,e[32]=he):he=e[32];let fe;e[33]!==xe||e[34]!==he?(fe=s.jsx(R,{name:xe,className:he}),e[33]=xe,e[34]=he,e[35]=fe):fe=e[35];let B;e[36]!==D||e[37]!==r||e[38]!==me||e[39]!==n.name||e[40]!==ne||e[41]!==F||e[42]!==ue||e[43]!==l||e[44]!==V||e[45]!==Q||e[46]!==i||e[47]!==O?(B=Q?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:j0,onMouseDown:k0,onSubmit:Te=>{Te.preventDefault(),ue()},children:[s.jsx("input",{ref:X,value:me,onChange:Te=>F(Te.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:O("sessions.sidebar.folderItem.namePlaceholder"),onClick:C0,onPointerDown:N0,onMouseDown:A0,onKeyDown:Te=>{if(Te.key==="Escape"){Te.stopPropagation(),ne();return}(Te.key===" "||Te.key==="Enter")&&Te.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:D0,onPointerDown:P0,onMouseDown:T0,children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),ne()},onPointerDown:I0,onMouseDown:E0,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("span",{className:Ie("typography-ui-label font-semibold truncate",V?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(xt,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",i.length]}),D?s.jsx(im,{state:D,activeLabel:O("sessions.sidebar.session.status.active"),unreadLabel:O("sessions.sidebar.session.status.unread")}):null,l?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=D,e[37]=r,e[38]=me,e[39]=n.name,e[40]=ne,e[41]=F,e[42]=ue,e[43]=l,e[44]=V,e[45]=Q,e[46]=i,e[47]=O,e[48]=B):B=e[48];let H;e[49]!==Pe||e[50]!==fe||e[51]!==B?(H=s.jsxs("div",{className:Pe,children:[fe,B]}),e[49]=Pe,e[50]=fe,e[51]=B,e[52]=H):H=e[52];let ke;e[53]!==M||e[54]!==_||e[55]!==n.name||e[56]!==G||e[57]!==T||e[58]!==m||e[59]!==N||e[60]!==Q||e[61]!==O?(ke=!Q&&(!T||_)?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",M?"opacity-100":"opacity-0 pointer-events-none group-hover/folder:opacity-100 group-hover/folder:pointer-events-auto group-focus-within/folder:opacity-100 group-focus-within/folder:pointer-events-auto"),children:s.jsxs("div",{className:"flex items-center gap-0.5",children:[!_&&N?s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),N()},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":O("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:O("sessions.sidebar.project.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})}):null,_?null:s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),G()},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":O("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(R,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Te=>{Te.stopPropagation(),m()},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":_?O("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):O("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=M,e[54]=_,e[55]=n.name,e[56]=G,e[57]=T,e[58]=m,e[59]=N,e[60]=Q,e[61]=O,e[62]=ke):ke=e[62];let Se;e[63]!==p||e[64]!==Ce||e[65]!==Re||e[66]!==ce||e[67]!==ye||e[68]!==be||e[69]!==te||e[70]!==H||e[71]!==ke?(Se=s.jsxs("div",{ref:p,className:Ce,onClick:Re,role:ce,tabIndex:ye,onKeyDown:be,"aria-label":te,children:[H,ke]}),e[63]=p,e[64]=Ce,e[65]=Re,e[66]=ce,e[67]=ye,e[68]=be,e[69]=te,e[70]=H,e[71]=ke,e[72]=Se):Se=e[72];let Be;e[73]!==h||e[74]!==l||e[75]!==i||e[76]!==o||e[77]!==O?(Be=l?null:s.jsxs("div",{className:"pb-1",children:[o,i.length>0?h:o?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:O("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=h,e[74]=l,e[75]=i,e[76]=o,e[77]=O,e[78]=Be):Be=e[78];let _e;return e[79]!==Se||e[80]!==Be?(_e=s.jsxs("div",{className:"oc-folder",children:[Se,Be]}),e[79]=Se,e[80]=Be,e[81]=_e):_e=e[81],_e},v0=c.memo(S0);function j0(t){return t.stopPropagation()}function k0(t){return t.stopPropagation()}function C0(t){return t.stopPropagation()}function N0(t){return t.stopPropagation()}function A0(t){return t.stopPropagation()}function D0(t){return t.stopPropagation()}function P0(t){return t.stopPropagation()}function T0(t){return t.stopPropagation()}function I0(t){return t.stopPropagation()}function E0(t){return t.stopPropagation()}const R0=t=>{const e=Ye.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:i,children:o}=t,l=`session-drag:${n}`;let a;e[0]!==r||e[1]!==n||e[2]!==i?(a={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:i},e[0]=r,e[1]=n,e[2]=i,e[3]=a):a=e[3];let d;e[4]!==l||e[5]!==a?(d={id:l,data:a},e[4]=l,e[5]=a,e[6]=d):d=e[6];const{attributes:u,listeners:m,setNodeRef:h,isDragging:y}=og(d);let b;e[7]!==m?(b=f=>{f.stopPropagation(),m?.onPointerDown&&m.onPointerDown(f)},e[7]=m,e[8]=b):b=e[8];const S=b,v=y?"opacity-30":void 0;let g;return e[9]!==u||e[10]!==o||e[11]!==S||e[12]!==h||e[13]!==v?(g=s.jsx("div",{ref:h,...u,onPointerDown:S,className:v,children:o}),e[9]=u,e[10]=o,e[11]=S,e[12]=h,e[13]=v,e[14]=g):g=e[14],g},M0=t=>{const e=Ye.c(11),{folderId:n,children:r}=t,i=`folder-drop:${n}`;let o;e[0]!==n?(o={type:"folder",folderId:n},e[0]=n,e[1]=o):o=e[1];let l;e[2]!==i||e[3]!==o?(l={id:i,data:o},e[2]=i,e[3]=o,e[4]=l):l=e[4];const{setNodeRef:a,isOver:d}=ig(l);let u;e[5]!==r||e[6]!==d||e[7]!==a?(u=r(a,d),e[5]=r,e[6]=d,e[7]=a,e[8]=u):u=e[8];let m;return e[9]!==u?(m=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=m):m=e[10],m},O0=t=>{const e=Ye.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:i,children:o}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const a=Hr(_n(Wi,l)),[d,u]=c.useState(null),[m,h]=c.useState("Session"),[y,b]=c.useState(null),[S,v]=c.useState(null);if(!n){let k;return e[1]!==o?(k=s.jsx(s.Fragment,{children:o}),e[1]=o,e[2]=k):k=e[2],k}let g;e[3]!==i?(g=k=>{u(null),b(null),v(null);const{active:A,over:D}=k;if(!D)return;const P=A.data.current,M=D.data.current;P?.type==="session"&&P.sessionId&&M?.type==="folder"&&M.folderId&&i(P.sessionId,M.folderId)},e[3]=i,e[4]=g):g=e[4];const f=g;let x,p;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=k=>{const A=k.active.data.current;if(A?.type==="session"&&A.sessionId){u(A.sessionId),h(A.sessionTitle??"Session");const D=k.active.rect.current.initial?.width,P=k.active.rect.current.initial?.height;b(typeof D=="number"?D:null),v(typeof P=="number"?P:null)}},p=()=>{u(null),b(null),v(null)},e[5]=x,e[6]=p):(x=e[5],p=e[6]);let w;e[7]!==S||e[8]!==d||e[9]!==m||e[10]!==y||e[11]!==r?(w=d&&r?s.jsxs("div",{style:{width:y?`${y}px`:"auto",height:S?`${S}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(R,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=S,e[8]=d,e[9]=m,e[10]=y,e[11]=r,e[12]=w):w=e[12];let N;e[13]!==w?(N=s.jsx(zi,{children:w}),e[13]=w,e[14]=N):N=e[14];let C;return e[15]!==o||e[16]!==f||e[17]!==a||e[18]!==N?(C=s.jsxs(Kr,{sensors:a,collisionDetection:Gr,onDragStart:x,onDragCancel:p,onDragEnd:f,children:[o,N]}),e[15]=o,e[16]=f,e[17]=a,e[18]=N,e[19]=C):C=e[19],C},ia=(t,e,n)=>{if(!e)return;const r=i=>{let o=i.session.id===e;for(const l of i.children)o=r(l)||o;return o&&n.add(i.session.id),o};for(const i of t)r(i)},Yn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Yn(n,e))return!0;return!1},B0=({isSubtaskSession:t,archivedBucket:e,isVSCode:n,sessionDirectory:r})=>!t&&!e&&!n&&!Jf(r),F0=({sessionDirectory:t,isStreaming:e,isMovingToWorktree:n})=>!t||e||n,_0=(t,e,n)=>{const r=new Map,i=o=>{const l=Us(o.session)??dt(o.worktree?.path)??n;if(l){const a=r.get(l)??[];a.push(o.session.id),r.set(l,a)}if(!(o===t&&e))for(const a of o.children)i(a)};return i(t),[...r].map(([o,l])=>({directory:o,sessionIDs:l}))},L0=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const i=new Set;let o=r.session.parentID??null;for(;o&&!i.has(o);){if(n.has(o)&&e.has(o))return!1;i.add(o),o=e.get(o)?.session?.parentID??null}return!0})},$0=t=>{const e=new Map(t.map(l=>[l.id,l])),n=new Map;for(const l of t){if(!l.parentId||!e.has(l.parentId))continue;const a=n.get(l.parentId)??[];a.push(l),n.set(l.parentId,a)}const r=new Set,i=[],o=l=>{if(r.has(l.id))return;i.push(l);const a=[l.id];for(;a.length>0;){const d=a.pop();if(!(!d||r.has(d))){r.add(d);for(const u of n.get(d)??[])a.push(u.id)}}};return t.forEach(l=>{(!l.parentId||!e.has(l.parentId))&&o(l)}),t.forEach(o),i},W0=(t,e)=>{const n=new Map(t.map(d=>[d.id,d])),r=new Map,i=new Set;for(const d of t){if(d.parentId&&!n.has(d.parentId)){i.add(d.id);continue}if(d.parentId){const h=r.get(d.parentId)??[];h.push(d.id),r.set(d.parentId,h)}const u=new Set;let m=d.id;for(;m;){if(u.has(m)){i.add(d.id);break}u.add(m),m=n.get(m)?.parentId}}const o=new Set,l=new Set,a=d=>{if(o.has(d))return!0;if(l.has(d))return!1;const u=n.get(d);if(!u)return!1;l.add(d);let m=i.has(d);return!m&&e.archivedBucket&&u.nodeCount===0?m=(r.get(d)??[]).some(a):(!m&&!e.searchQuery&&(m=!0),!m&&(u.nodeCount>0||_o([u.name],e.searchQuery))&&(m=!0),m||(m=(r.get(d)??[]).some(a))),l.delete(d),m&&o.add(d),m};return t.forEach(d=>a(d.id)),new Set(t.filter(d=>o.has(d.id)).map(d=>d.id))},bc=new WeakMap;let xc=1;const z0=t=>{const e=bc.get(t);if(e!==void 0)return e;const n=xc;return xc+=1,bc.set(t,n),n},qo=t=>t.children.length===0?"":t.children.map(n=>{const r=z0(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${qo(n)}`}).join("|"),am=(t,e,n,r,i,o)=>{const l=Cs(),a=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const m=d.session.directory??i,h=u.session.directory??o,y=al(l,m??"",d.session.id),b=al(l,h??"",u.session.id);return(y?n.has(y):!1)!==(b?r.has(b):!1)?!0:d.children.some((S,v)=>a(S,u.children[v]))};return a(t,e)},V0=t=>t.actionsAlwaysVisible?"":`transition-opacity duration-150 ${t.menuOpen?"opacity-0":t.hideOnHoverClass}`,Jr=(t,e,n,r)=>{if(!e)return null;const i=r?"archived":"active";let o=null;const l=a=>{if(`${n}:${i}:${a.session.id}`===e)return o=a.session.id,!0;for(const u of a.children)if(l(u))return!0;return!1};return t.forEach(a=>l(a)),o};let aa=!1;const la=new Set;let yc=!1;function U0(){for(const t of la)t()}function Ga(t){aa!==t&&(aa=t,U0())}function H0(t){t.key==="Shift"&&Ga(!0)}function K0(t){t.key==="Shift"&&Ga(!1)}function G0(){Ga(!1)}function q0(){yc||typeof window>"u"||(yc=!0,window.addEventListener("keydown",H0),window.addEventListener("keyup",K0),window.addEventListener("blur",G0))}function Q0(t){return q0(),la.add(t),()=>{la.delete(t)}}function Y0(){return aa}function X0(){return!1}function J0(){return it.useSyncExternalStore(Q0,Y0,X0)}const Z0=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,lm=/^g[1-9]\d*$/,Ir=(t,e,n,r,i)=>{if(!Z0.test(t)||e!==void 0&&!lm.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(i===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(i==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:o,fusion:!1}},Eo=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Ir(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,d,u]=e;return lm.test(a)?Ir(n,a,d,u,void 0):Ir(n,void 0,a,d,u)}const[,r,i,o,l]=e;return r===""?Ir(n,void 0,i,o,l):Ir(n,r,i,o,l)},ej=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},tj=(t,e,n,r)=>{const i=[t];return r&&i.push(r),i.push(e,n,"fusion"),i.join("/")},cm=t=>{const e=Ye.c(36),{value:n,onChange:r,className:i,disabled:o,id:l,portalToBody:a}=t,{t:d}=ht(),u=Kt(sj),m=Kt(nj),h=Kt(rj);let y;e[0]!==u?(y=u(),e[0]=u,e[1]=y):y=e[1];const b=y;let S;e[2]!==b?(S=b.filter(oj),e[2]=b,e[3]=S):S=e[3];const v=S;let g,f;e[4]!==b.length||e[5]!==m?(g=()=>{b.length===0&&m()},f=[b.length,m],e[4]=b.length,e[5]=m,e[6]=g,e[7]=f):(g=e[6],f=e[7]),c.useEffect(g,f);let x,p;e[8]!==h||e[9]!==o||e[10]!==r||e[11]!==v||e[12]!==n?(x=()=>{if(o)return;const z=n.trim();if(z.length>0&&v.some(T=>T.name===z))return;const I=typeof h=="string"&&h.trim().length>0?h.trim():null;if(I&&v.some(T=>T.name===I)){r(I);return}const V=v[0]?.name;V&&r(V)},p=[h,o,r,v,n],e[8]=h,e[9]=o,e[10]=r,e[11]=v,e[12]=n,e[13]=x,e[14]=p):(x=e[13],p=e[14]),c.useEffect(x,p);const w=n.trim().length>0?n:void 0;let N;e[15]!==i?(N=Ie("max-w-full",i),e[15]=i,e[16]=N):N=e[16];let C;e[17]!==d?(C=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=C):C=e[18];let k;e[19]!==C?(k=s.jsx(Is,{placeholder:C}),e[19]=C,e[20]=k):k=e[20];let A;e[21]!==l||e[22]!==N||e[23]!==k?(A=s.jsx(Ws,{id:l,size:"lg",className:N,children:k}),e[21]=l,e[22]=N,e[23]=k,e[24]=A):A=e[24];let D;e[25]!==v?(D=v.length>0&&s.jsx(Oi,{children:v.map(ij)}),e[25]=v,e[26]=D):D=e[26];let P;e[27]!==a||e[28]!==D?(P=s.jsx(zs,{fitContent:!0,portalToBody:a,children:D}),e[27]=a,e[28]=D,e[29]=P):P=e[29];let M;return e[30]!==o||e[31]!==r||e[32]!==w||e[33]!==A||e[34]!==P?(M=s.jsxs($s,{value:w,onValueChange:r,disabled:o,children:[A,P]}),e[30]=o,e[31]=r,e[32]=w,e[33]=A,e[34]=P,e[35]=M):M=e[35],M};function sj(t){return t.getVisibleAgents}function nj(t){return t.loadAgents}function rj(t){return t.currentAgentName}function oj(t){return Md(t.mode)}function ij(t){return s.jsx(ns,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const aj="h-7",Wr=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,lj=t=>{const e=Ye.c(12),{model:n,instanceIndex:r,totalSameModel:i,onRemove:o}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,a=i>1?`${l} (${r})`:l;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=Ie("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",aj),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(Bi,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=u):u=e[2];let m;e[3]!==a?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:a}),e[3]=a,e[4]=m):m=e[4];let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(R,{name:"close",className:"h-3.5 w-3.5"}),e[5]=h):h=e[5];let y;e[6]!==o?(y=s.jsx("button",{type:"button",onClick:o,className:"text-muted-foreground hover:text-foreground ml-0.5",children:h}),e[6]=o,e[7]=y):y=e[7];let b;return e[8]!==u||e[9]!==m||e[10]!==y?(b=s.jsxs("div",{className:d,children:[u,m,y]}),e[8]=u,e[9]=m,e[10]=y,e[11]=b):b=e[11],b},dm=t=>{const e=Ye.c(120),{selectedModels:n,onAdd:r,onRemove:i,onUpdate:o,minModels:l,addButtonLabel:a,showChips:d,maxModels:u,addButtonClassName:m,dropdownSide:h,dropdownClassName:y,containerClassName:b,triggerIcon:S}=t,v=d===void 0?!0:d,g=h===void 0?"top":h,{t:f}=ht(),x=Kt(cj),p=Kt(dj),w=Ae(uj),N=Ae(mj),{favoriteModelsList:C,recentModelsList:k}=Zf(),A=Ae(fj),D=Ae(hj),[P,M]=c.useState(!1),[z,I]=c.useState(""),[V,T]=c.useState(null),_=c.useRef(null),O=c.useRef(null),j=u===1,E=u===void 0||n.length<u||j;let L;if(e[0]!==n){L=new Map;for(const we of n){const Ke=`${we.providerID}:${we.modelID}`;L.set(Ke,(L.get(Ke)||0)+1)}e[0]=n,e[1]=L}else L=e[1];const U=L;let X;e[2]!==n?(X=we=>n.filter(Qe=>Qe.providerID===we.providerID&&Qe.modelID===we.modelID).findIndex(Qe=>Qe.instanceId===we.instanceId)+1,e[2]=n,e[3]=X):X=e[3];const Q=X;let me,re;e[4]!==g||e[5]!==P?(me=()=>{if(!P||!O.current)return;const we=O.current.getBoundingClientRect();if(g==="bottom"){const ve=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-we.bottom-16-112;T(Math.max(160,Math.min(320,ve)));return}let Ke=O.current.parentElement;for(;Ke&&!Ke.matches('[role="dialog"], [data-scroll-shadow-scroller]');){const le=getComputedStyle(Ke);if(le.overflow==="auto"||le.overflow==="hidden"||le.overflowY==="auto"||le.overflowY==="hidden")break;Ke=Ke.parentElement}const Qe=Ke?Ke.getBoundingClientRect().top:0,He=we.top-Qe-16;T(Math.max(150,Math.min(300,He)))},re=[g,P],e[4]=g,e[5]=P,e[6]=me,e[7]=re):(me=e[6],re=e[7]),c.useEffect(me,re);let G,ee;e[8]!==E||e[9]!==P?(G=()=>{!E&&P&&(M(!1),I(""))},ee=[E,P],e[8]=E,e[9]=P,e[10]=G,e[11]=ee):(G=e[10],ee=e[11]),c.useEffect(G,ee);let ue,W;e[12]!==P?(ue=()=>{if(!P)return;const we=Ke=>{_.current&&!_.current.contains(Ke.target)&&(M(!1),I(""))};return document.addEventListener("mousedown",we),()=>document.removeEventListener("mousedown",we)},W=[P],e[12]=P,e[13]=ue,e[14]=W):(ue=e[13],W=e[14]),c.useEffect(ue,W);let ne;e[15]!==j||e[16]!==r||e[17]!==o||e[18]!==n.length?(ne=we=>{const Ke={providerID:we.providerID,modelID:we.modelID,displayName:we.model.name||we.modelID,instanceId:Wr()};j&&n.length>0&&o?o(0,Ke):r(Ke),j&&(M(!1),I(""))},e[15]=j,e[16]=r,e[17]=o,e[18]=n.length,e[19]=ne):ne=e[19];const Y=ne;let F;e[20]!==f?(F=f("multirun.modelMultiSelect.search.placeholder"),e[20]=f,e[21]=F):F=e[21];let J;e[22]!==f?(J=f("multirun.modelMultiSelect.search.noResults"),e[22]=f,e[23]=J):J=e[23];let ie;e[24]!==f?(ie=f("multirun.modelMultiSelect.sections.favorites"),e[24]=f,e[25]=ie):ie=e[25];let xe;e[26]!==f?(xe=f("multirun.modelMultiSelect.sections.recent"),e[26]=f,e[27]=xe):xe=e[27];let ge;e[28]!==f?(ge=f("multirun.modelMultiSelect.keyboard.hint"),e[28]=f,e[29]=ge):ge=e[29];let Ce;e[30]!==f?(Ce=f("settings.agents.modelSelector.actions.favorite"),e[30]=f,e[31]=Ce):Ce=e[31];let Re;e[32]!==f?(Re=f("settings.agents.modelSelector.actions.unfavorite"),e[32]=f,e[33]=Re):Re=e[33];let ce;e[34]!==f?(ce=f("chat.modelControls.capabilities"),e[34]=f,e[35]=ce):ce=e[35];let ye;e[36]!==f?(ye=f("chat.modelControls.capability.toolCalling"),e[36]=f,e[37]=ye):ye=e[37];let be;e[38]!==f?(be=f("chat.modelControls.capability.reasoning"),e[38]=f,e[39]=be):be=e[39];let te;e[40]!==f?(te=f("chat.modelControls.input"),e[40]=f,e[41]=te):te=e[41];let pe;e[42]!==f?(pe=f("chat.modelControls.output"),e[42]=f,e[43]=pe):pe=e[43];let Pe;e[44]!==f?(Pe=f("chat.modelControls.costPerMillion"),e[44]=f,e[45]=Pe):Pe=e[45];let de;e[46]!==F||e[47]!==J||e[48]!==ie||e[49]!==xe||e[50]!==ge||e[51]!==Ce||e[52]!==Re||e[53]!==ce||e[54]!==ye||e[55]!==be||e[56]!==te||e[57]!==pe||e[58]!==Pe?(de={searchPlaceholder:F,noResults:J,favorites:ie,recent:xe,keyboardHint:ge,favorite:Ce,unfavorite:Re,capabilities:ce,capabilityToolCalling:ye,capabilityReasoning:be,input:te,output:pe,costPerMillion:Pe},e[46]=F,e[47]=J,e[48]=ie,e[49]=xe,e[50]=ge,e[51]=Ce,e[52]=Re,e[53]=ce,e[54]=ye,e[55]=be,e[56]=te,e[57]=pe,e[58]=Pe,e[59]=de):de=e[59];const he=de;let fe;e[60]!==b?(fe=Ie("relative",b),e[60]=b,e[61]=fe):fe=e[61];const B=P?"":void 0;let H;e[62]!==m?(H=Ie(Od({size:"default"}),"w-fit",m),e[62]=m,e[63]=H):H=e[63];const ke=!E;let Se;e[64]!==P?(Se=()=>{M(!P)},e[64]=P,e[65]=Se):Se=e[65];let Be;e[66]!==S?(Be=S??s.jsx(R,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=S,e[67]=Be):Be=e[67];let _e;e[68]!==a||e[69]!==f?(_e=a??f("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=f,e[70]=_e):_e=e[70];let Te;e[71]!==B||e[72]!==H||e[73]!==ke||e[74]!==Se||e[75]!==Be||e[76]!==_e?(Te=s.jsxs("button",{ref:O,type:"button","data-popup-open":B,className:H,disabled:ke,onClick:Se,children:[Be,_e]}),e[71]=B,e[72]=H,e[73]=ke,e[74]=Se,e[75]=Be,e[76]=_e,e[77]=Te):Te=e[77];let Z;e[78]!==V||e[79]!==E||e[80]!==y||e[81]!==g||e[82]!==C||e[83]!==Y||e[84]!==A||e[85]!==N||e[86]!==P||e[87]!==he||e[88]!==U||e[89]!==p||e[90]!==D||e[91]!==x||e[92]!==k||e[93]!==z||e[94]!==w?(Z=P?s.jsx("div",{className:Ie("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",g==="top"?"bottom-full mb-1":"top-full mt-1",y),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(eh,{providers:x,providerOrder:D,favoriteModels:C,recentModels:k,modelsMetadata:p,hiddenModels:A,searchQuery:z,onSearchQueryChange:I,onSelect:Y,labels:he,selectionCount:we=>U.get(`${we.providerID}:${we.modelID}`)||0,disabled:!E,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:V?`${V}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:P,isFavorite:we=>N(we.providerID,we.modelID),onToggleFavorite:we=>w(we.providerID,we.modelID),onEscape:()=>{M(!1),I("")}})}):null,e[78]=V,e[79]=E,e[80]=y,e[81]=g,e[82]=C,e[83]=Y,e[84]=A,e[85]=N,e[86]=P,e[87]=he,e[88]=U,e[89]=p,e[90]=D,e[91]=x,e[92]=k,e[93]=z,e[94]=w,e[95]=Z):Z=e[95];let Ne;e[96]!==fe||e[97]!==Te||e[98]!==Z?(Ne=s.jsxs("div",{className:fe,ref:_,children:[Te,Z]}),e[96]=fe,e[97]=Te,e[98]=Z,e[99]=Ne):Ne=e[99];let Me;e[100]!==Q||e[101]!==U||e[102]!==i||e[103]!==o||e[104]!==x||e[105]!==n||e[106]!==v||e[107]!==f?(Me=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((we,Ke)=>{const Qe=`${we.providerID}:${we.modelID}`,He=U.get(Qe)||1,le=Q(we),ve=x.find(Fe=>Fe.id===we.providerID)?.models?.find(Fe=>Fe.id===we.modelID),$e=ve?.variants?Object.keys(ve.variants):[],We=$e.length>0,Le=we.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(lj,{model:we,instanceIndex:le,totalSameModel:He,onRemove:()=>i(Ke)}),We&&s.jsxs($s,{value:Le,onValueChange:Fe=>{if(!o)return;o(Ke,{...we,variant:Fe==="__default__"?void 0:Fe})},children:[s.jsxs(Ws,{size:"sm",className:"gap-1.5",children:[s.jsx(R,{name:"brain-ai-3",className:Ie("h-3.5 w-3.5 flex-shrink-0",Le==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Is,{placeholder:f("multirun.modelMultiSelect.variant.placeholder"),children:Fe=>Fe==="__default__"?f("multirun.modelMultiSelect.variant.default"):Fe})]}),s.jsxs(zs,{fitContent:!0,children:[s.jsx(ns,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:f("multirun.modelMultiSelect.variant.default")}),$e.map(pj)]})]})]},we.instanceId)})}),e[100]=Q,e[101]=U,e[102]=i,e[103]=o,e[104]=x,e[105]=n,e[106]=v,e[107]=f,e[108]=Me):Me=e[108];let $;e[109]!==Ne||e[110]!==Me?($=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Ne,Me]}),e[109]=Ne,e[110]=Me,e[111]=$):$=e[111];let ae;e[112]!==u||e[113]!==l||e[114]!==n.length||e[115]!==f?(ae=l!==void 0&&n.length<l&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?f("multirun.modelMultiSelect.validation.minToMax",{min:l,max:u}):f("multirun.modelMultiSelect.validation.minOnly",{min:l})}),e[112]=u,e[113]=l,e[114]=n.length,e[115]=f,e[116]=ae):ae=e[116];let se;return e[117]!==$||e[118]!==ae?(se=s.jsxs("div",{className:"space-y-2",children:[$,ae]}),e[117]=$,e[118]=ae,e[119]=se):se=e[119],se};function cj(t){return t.providers}function dj(t){return t.modelsMetadata}function uj(t){return t.toggleFavoriteModel}function mj(t){return t.isFavoriteModel}function fj(t){return t.hiddenModels}function hj(t){return t.providerOrder}function pj(t){return s.jsx(ns,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const gj=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
913
|
-
|
|
914
|
-
--- RESULT ${n+1}: ${r} ---
|
|
915
|
-
${e.trim()}
|
|
916
|
-
--- END RESULT ${n+1} ---`},wc=(t,e)=>qe.getState().getWorktreeMetadata(t)?.projectDirectory??e,bj=async t=>{const e=t.directory??void 0,n=sh(t.session.id,e);if(n.length===0&&t.directory){const i=(await _s.withDirectory(t.directory,()=>_s.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let o=i.length-1;o>=0;o-=1){const l=i[o];if(l.info?.role==="assistant")return cl(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return cl(nh(i.id,e)).trim()}return""};function xj({session:t,open:e,onOpenChange:n}){const{t:r}=ht(),i=th(),o=Es(j=>j.activeSessions),l=Es(j=>j.archivedSessions),a=Kt(j=>j.providers),d=Kt(j=>j.currentProviderId),u=Kt(j=>j.currentModelId),m=Kt(j=>j.currentAgentName),[h,y]=c.useState(d??""),[b,S]=c.useState(u??""),[v,g]=c.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:Wr()}]:[]),[f,x]=c.useState(""),[p,w]=c.useState(m??""),[N,C]=c.useState([]),[k,A]=c.useState(!1),D=c.useMemo(()=>Eo(t.title),[t.title]),P=c.useMemo(()=>{const j=new Map;for(const E of i)j.set(E.id,E);for(const E of o)j.set(E.id,E);for(const E of l)j.set(E.id,E);return t.id&&j.set(t.id,t),Array.from(j.values())},[o,l,i,t]);c.useEffect(()=>{if(!e||!D)return;const j=qe.getState().getDirectoryForSession(t.id),E=wc(t.id,j),L=P.map(U=>{const X=Eo(U.title);if(!X||X.groupSlug!==D.groupSlug||X.fusion||(X.runGroup??null)!==(D.runGroup??null))return null;const Q=qe.getState().getDirectoryForSession(U.id)??Us(U),me=wc(U.id,Q);return E&&me&&E!==me?null:{session:U,directory:Q,projectDirectory:me}}).filter(U=>U!==null).sort((U,X)=>(U.session.time?.created??0)-(X.session.time?.created??0));C(L)},[P,e,D,t.id]);const z=a.find(j=>j.id===h)?.models.find(j=>j.id===b),I=z?.variants?Object.keys(z.variants):[],V=!!(D&&h&&b&&N.length>0&&!k),T=c.useCallback(j=>{g([j]),y(j.providerID),S(j.modelID),x("")},[]),_=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),O=async()=>{if(!(!D||!h||!b)){A(!0);try{const j=await Promise.all(N.map(re=>bj(re))),E=N.map((re,G)=>({source:re,text:j[G]??""})).filter(re=>re.text.trim().length>0);if(E.length===0){Oe.error(r("multirun.fusion.toast.noOutputs"));return}const L=N[0]?.projectDirectory??N[0]?.directory??null,U=tj(D.groupSlug,h,b,D.runGroup),[X,Q]=await Promise.all([ll("session.fusion.visible"),ll("session.fusion.instructions")]),me=await qe.getState().createSession(U,L,null);if(!me)throw new Error("Failed to create fusion session");qe.getState().setCurrentSession(me.id,L),n(!1),await _s.sendMessage({id:me.id,providerID:h,modelID:b,variant:f||void 0,agent:p||void 0,text:X,additionalParts:[{text:Q,synthetic:!0},...E.map((re,G)=>({text:gj(re.source,re.text,G),synthetic:!0})),{text:`
|
|
917
|
-
|
|
918
|
-
--- FUSION INPUTS END ---
|
|
919
|
-
Now write the final fused answer.`,synthetic:!0}],directory:L??_s.getDirectory()})}catch(j){console.error("[MultiRunFusion] Failed to start fusion",j),Oe.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(Ns,{open:e,onOpenChange:n,children:s.jsxs(As,{className:"max-w-xl overflow-visible",children:[s.jsxs(Hs,{children:[s.jsx(Rs,{children:r("multirun.fusion.title")}),s.jsx(Ms,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(dm,{selectedModels:v,onAdd:T,onUpdate:(j,E)=>T(E),onRemove:()=>{g([]),y(""),S(""),x("")},maxModels:1,addButtonLabel:_,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:h?s.jsx(Bi,{providerId:h,className:"h-3.5 w-3.5 mr-1"}):void 0})}),I.length>0?s.jsxs($s,{value:f||"__default__",onValueChange:j=>x(j==="__default__"?"":j),children:[s.jsxs(Ws,{size:"lg",className:"w-fit",children:[s.jsx(R,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Is,{children:j=>j==="__default__"?r("multirun.modelMultiSelect.variant.default"):j})]}),s.jsxs(zs,{fitContent:!0,portalToBody:!0,children:[s.jsx(ns,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),I.map(j=>s.jsx(ns,{value:j,children:j},j))]})]}):null,s.jsx(cm,{value:p,onChange:w,portalToBody:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:N.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:N.map(j=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Bi,{providerId:Eo(j.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:j.session.title||j.session.id}),s.jsx("button",{type:"button",onClick:()=>C(E=>E.filter(L=>L.session.id!==j.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},j.session.id))})]}),s.jsxs(Sn,{children:[s.jsx(at,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(at,{onClick:O,disabled:!V,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function yj(t){const e=Ye.c(7);let n,r,i,o,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=o,e[4]=l):(n=e[0],r=e[1],i=e[2],o=e[3],l=e[4]);let a;return e[5]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,o,l]}),e[5]=t,e[6]=a):a=e[6],a}const wj=(t,e)=>(t.current.runtimeKey!==e||(t.current={...t.current,revision:t.current.revision+1}),t.current.revision),um=t=>new Map([...t.entries()].map(([e,n])=>[e,n.map(r=>Zr(r))])),ca=t=>((t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey||t.rawWorktreesByProjectRef.current.worktreesByProject.size===0&&t.publishedWorktreesByProject.size>0)&&(t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.rawWorktreesByProjectRef.current.runtimeKey===t.runtimeKey?t.rawWorktreesByProjectRef.current.revision:0,worktreesByProject:um(t.publishedWorktreesByProject)}),t.rawWorktreesByProjectRef.current),mm=(t,e)=>{const n=t.metadata.branch||t.metadata.name||t.metadata.label||t.metadata.path,r=e.metadata.branch||e.metadata.name||e.metadata.label||e.metadata.path,i=n.localeCompare(r,void 0,{sensitivity:"base"});return i!==0?i:t.metadata.path.localeCompare(e.metadata.path,void 0,{sensitivity:"base"})},Sc=t=>{const e=t.split("/").filter(Boolean);return e[e.length-1]??t},Zr=t=>({...t,path:dt(t.path)??t.path,projectDirectory:dt(t.projectDirectory)??t.projectDirectory,worktreeRoot:dt(t.worktreeRoot??t.path)??t.worktreeRoot}),vc=t=>{const{currentWorktree:e,path:n,projectDirectory:r,projectRootBranch:i}=t,l=dt(e?.path??null)===n,a=l?e?.branch??"":i??"",d={path:n,projectDirectory:r,branch:a,label:l?e?.label||e?.branch||e?.name||Sc(n):i||Sc(n),name:l?e?.name:void 0,worktreeRoot:l?dt(e?.worktreeRoot??n)??n:n,worktreeStatus:l?e?.worktreeStatus??"ready":"ready",worktreeSource:l?e?.worktreeSource??"existing":"existing",headState:l?e?.headState:i?"branch":void 0};return l&&e?{...e,...d}:d},jc=t=>{const e=dt(t.projectPath??null),n=dt(t.sourceDirectory??null)??dt(t.currentWorktree?.path??null),r=dt(t.discoveredWorktrees.find(m=>dt(m.projectDirectory??null))?.projectDirectory??null),i=dt(t.currentWorktree?.projectDirectory??null),o=r??i??e,l=new Map,a=m=>{const h=dt(m.metadata.path??null);!h||l.has(h)||l.set(h,{...m,metadata:Zr({...m.metadata,path:h})})};for(const m of t.discoveredWorktrees){const h=dt(m.path??null);h&&a({metadata:Zr({...m,path:h,projectDirectory:dt(m.projectDirectory??null)??o??e??h}),isPrimary:o===h,isCurrent:n===h})}o&&!l.has(o)&&a({metadata:vc({path:o,projectDirectory:o,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:!0,isCurrent:n===o}),n&&!l.has(n)&&a({metadata:vc({path:n,projectDirectory:o??e??n,currentWorktree:t.currentWorktree,projectRootBranch:t.projectRootBranch}),isPrimary:o===n,isCurrent:!0});const d=[],u=[];for(const m of l.values()){if(m.isPrimary){d.push(m);continue}u.push(m)}return d.sort((m,h)=>m.metadata.path.localeCompare(h.metadata.path,void 0,{sensitivity:"base"})),u.sort(mm),[...d,...u]},Sj=(t,e)=>{const n=e.getRuntimeKey(),r=e.getPublishedWorktreesByProject(),i=ca({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:r,runtimeKey:n}),l=(t.projectId?e.projects.find(u=>u.id===t.projectId)??null:null)??(t.sourceDirectory?e.resolveProject(t.sourceDirectory):null),a=dt(l?.path??null);return{cachedTargets:jc({projectPath:a,discoveredWorktrees:a?i.worktreesByProject.get(a)??[]:[],sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch}),refreshTargets:(async()=>{if(!l||!a)throw new Error("Unable to resolve worktree project");const u=await e.listProjectWorktrees(l,{force:!0});if(e.getRuntimeKey()!==n)throw new Error("Runtime changed during worktree refresh");const m=e.getCurrentProjects(),h=m.find(w=>w.id===l.id)??null;if(!h||dt(h.path??null)!==a)throw new Error("Project removed during worktree refresh");const y=ca({rawWorktreesByProjectRef:e.rawWorktreesByProjectRef,publishedWorktreesByProject:e.getPublishedWorktreesByProject(),runtimeKey:n}),b=um(y.worktreesByProject),S=[...u].map(w=>Zr(w)).sort((w,N)=>mm({metadata:w},{metadata:N})),v=dt(S.find(w=>dt(w.projectDirectory??null))?.projectDirectory??t.currentWorktree?.projectDirectory??l.path),g=new Set([a]);for(const[w,N]of b.entries()){const C=dt(N.find(k=>dt(k.projectDirectory??null))?.projectDirectory??w);C&&C===v&&g.add(w)}for(const w of g){if(S.length===0){b.delete(w);continue}b.set(w,S.map(N=>Zr(N)))}wj(e.rawWorktreesByProjectRef,n),e.rawWorktreesByProjectRef.current={runtimeKey:n,revision:e.rawWorktreesByProjectRef.current.revision,worktreesByProject:b};const f=e.partitionWorktreesByRegisteredProject(m,b),x=[...f.values()].flat();e.recordWorktreesSeen(x.map(w=>w.path),e.now());const p=e.getPublishedWorktreesByProject();return e.worktreeMapsEqual(f,p)||e.publishTopology({availableWorktrees:x,availableWorktreesByProject:f}),jc({projectPath:a,discoveredWorktrees:S,sourceDirectory:t.sourceDirectory,currentWorktree:t.currentWorktree,projectRootBranch:e.projectRootBranch})})()}},vj=t=>{if(t.rawWorktreesByProjectRef.current.runtimeKey!==t.runtimeKey)return!1;if(t.rawWorktreesByProjectRef.current.revision!==t.capturedRevision)return t.requestRediscovery(),!1;const e=t.partitionWorktreesByRegisteredProject(t.projects,t.nextRawWorktreesByProject),n=[...e.values()].flat();return t.recordWorktreesSeen(n.map(r=>r.path),t.now()),t.rawWorktreesByProjectRef.current={runtimeKey:t.runtimeKey,revision:t.capturedRevision,worktreesByProject:new Map(t.nextRawWorktreesByProject)},t.worktreeMapsEqual(e,t.publishedWorktreesByProject)||t.publishTopology({availableWorktrees:n,availableWorktreesByProject:e}),!0},jj=t=>({refreshState:t.isRefreshing?"loading":t.loadFailed&&t.targets.length===0?"error":null,showNewWorktreeAction:!0}),kj=(t,e)=>dt(t.worktree?.path??null)===dt(e.worktree?.path??null)&&t.worktree?.branch===e.worktree?.branch,da=6,xo=14,kc=da+14+6,ki=new WeakMap,Cj=t=>{const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;ki.get(n)?.();const r=e.getBoundingClientRect().top;let i=3,o=!1,l=null;const a=()=>{o=!0,l!==null&&window.cancelAnimationFrame(l),l=null,ki.delete(n),n.removeEventListener("wheel",a),n.removeEventListener("touchstart",a)},d=()=>{if(o||!e.isConnected||!n.isConnected){a();return}const u=e.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,fn("ui.sidebar.selection_scroll_anchor_adjustment")),i-=1,i<=0){a();return}l=window.requestAnimationFrame(d)};n.addEventListener("wheel",a,{passive:!0}),n.addEventListener("touchstart",a,{passive:!0}),ki.set(n,a),l=window.requestAnimationFrame(d)},Nj=c.memo(function(e){const n=Ye.c(22),{archiveLabel:r,deleteLabel:i,buttonSizeClass:o,iconSizeClass:l,onPointerDown:a,onMouseDown:d,onArchive:u,onDelete:m}=e,h=J0(),y=h?i:r;let b;n[0]!==u||n[1]!==m||n[2]!==h?(b=C=>{if(h||C.shiftKey){m(C);return}u(C)},n[0]=u,n[1]=m,n[2]=h,n[3]=b):b=n[3];const S=b,v=h?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let g;n[4]!==o||n[5]!==v?(g=Ie("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v,o),n[4]=o,n[5]=v,n[6]=g):g=n[6];const f=h?"delete-bin":"archive";let x;n[7]!==l||n[8]!==f?(x=s.jsx(R,{name:f,className:l}),n[7]=l,n[8]=f,n[9]=x):x=n[9];let p;n[10]!==S||n[11]!==y||n[12]!==d||n[13]!==a||n[14]!==g||n[15]!==x?(p=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:g,"aria-label":y,onPointerDown:a,onMouseDown:d,onClick:S,onKeyDown:Mj,children:x})}),n[10]=S,n[11]=y,n[12]=d,n[13]=a,n[14]=g,n[15]=x,n[16]=p):p=n[16];let w;n[17]!==y?(w=s.jsx(xt,{side:"left",sideOffset:8,children:y}),n[17]=y,n[18]=w):w=n[18];let N;return n[19]!==p||n[20]!==w?(N=s.jsxs(yt,{delayDuration:500,children:[p,w]}),n[19]=p,n[20]=w,n[21]=N):N=n[21],N});function Aj(t){fn("ui.sidebar_session_node.render");const{t:e}=ht(),{node:n,depth:r=0,groupDirectory:i,projectId:o,archivedBucket:l=!1,pinnedSessionIds:a,expandedParents:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,notifyOnSubtasks:h,editingId:y,setEditingId:b,editTitle:S,setEditTitle:v,handleSaveEdit:g,handleCancelEdit:f,toggleParent:x,handleSessionSelect:p,handleSessionDoubleClick:w,handleShareSession:N,copiedSessionId:C,handleCopyShareUrl:k,handleCopySessionId:A,handleUnshareSession:D,openSidebarMenuKey:P,setOpenSidebarMenuKey:M,createFolderAndStartRename:z,handleDeleteSession:I,handleRestoreSession:V,startSessionWorktreeMenuLoad:T,mobileVariant:_,alwaysShowActions:O,secondaryMeta:j,renderContext:E="project",children:L}=t,U=Vr(De=>De.toggle),X=ms(De=>De.getFoldersForScope),Q=ms(De=>De.getSessionFolderId),me=ms(De=>De.removeSessionFromFolder),re=ms(De=>De.addSessionToFolder),G=Ae(De=>De.openContextPanelTab),ee=c.useMemo(()=>Dn(),[]),ue=c.useMemo(()=>Zo(),[]),W=c.useContext(rh),ne=ee?"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",Y=ee?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",F=ee,J=!l&&!_,ie=ee?J&&F?"group-hover:pr-18":J||F?"group-hover:pr-14":"group-hover:pr-8":J?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",xe=J?"pr-13":"pr-7",ge=c.useRef(!1),[Ce,Re]=c.useState(!1),ce=c.useRef(y);ce.current=y;const ye=c.useRef(null),be=c.useRef(!1),te=c.useRef(g);te.current=g;const[pe,Pe]=c.useState(S),de=c.useRef(pe);de.current=pe;const he=c.useRef(null),fe=c.useRef(null),B=n.session,H=B,ke=Ht(c.useCallback(De=>{if(j?.projectLabel||!o)return null;const Bt=De.projects.find(Qt=>Qt.id===o);return Bt?Bt.label?.trim()||Wn(dt(Bt.path)??Bt.path,null)||Bt.path:null},[o,j?.projectLabel])),Se=j?.projectLabel??(ke?Ma(ke):null),Be=j?.branchLabel??n.worktree?.branch??null,_e=c.useMemo(()=>{if(ee)return null;const De=n.worktree?.branch?.trim(),Bt=dt(n.worktree?.path??null);return De&&Bt?ni(Bt,De):null},[ee,n.worktree]),Te=Bd(_e),Z=Te?`var(--pr-${Te.visualState})`:void 0,Ne=us(De=>De.sessionGroupingMode),Me=!!Be&&(E==="recent"||Ne==="flat"),$=c.useMemo(()=>{if(!Te)return null;switch(Te.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return Te.canMerge===!0||Te.mergeableState==="clean"||Te.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return Te.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked");case"draft":return e("sessions.sidebar.group.pr.status.draft");case"closed":return e("sessions.sidebar.group.pr.status.closed");default:return null}},[Te,e]),ae=qe(De=>De.currentSessionId===B.id),se=dt(B.directory??null)??dt(i??null),we=o??se??null,Ke=oh(),Qe=gs(De=>De.enabled),He=gs(c.useCallback(De=>De.selectedIds.has(B.id),[B.id])),le=gs(De=>De.toggleSelected),K=gs(De=>De.setRange),ve=c.useCallback(De=>{const Bt=[],Qt=ls=>{ls.children.forEach(js=>{Bt.push(js.session.id),Qt(js)})};return Qt(De),Bt},[]),$e=c.useCallback(De=>{const Bt=[],Qt=ls=>{ls.children.forEach(js=>{Bt.push(js.session),Qt(js)})};return Qt(De),Bt},[]),[We,Le]=c.useState(!1),[Fe,Ge]=c.useState(!0),rt=`${E}:${l?"archived":"active"}:${B.id}`,St=Fd(c.useCallback(De=>!!De.sessionMemoryState.get(ih(B.id))?.isZombie,[B.id])),ze=wa(B.id)?.type??"idle",Pt=ze==="busy"||ze==="retry",Nt=ah(B.id,Pt),Tt=yu(B.id),Et=n.worktree??qe.getState().getWorktreeMetadata(B.id)??null,[vt,Ct]=c.useState([]),[It,mt]=c.useState(!1),[Ze,je]=c.useState(!1),ot=c.useRef(!1),ct=c.useRef(0),Mt=lh(B.id,se??void 0,{bootstrap:!1}),Je=ch(H),nt=Je?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(dl[Je.status]),"aria-label":e(dl[Je.status]),children:s.jsx(R,{name:"target",className:"h-3 w-3",style:{color:dh[Je.status]}})}):null,jt=H.title||e("sessions.sidebar.session.untitled"),At=n.children.length>0,Ot=uh(a,se,B.id),$t=rt,Zt=u?!0:d.has($t),Gt=c.useMemo(()=>_0(n,Zt,se),[Zt,n,se]),Ft=mh(Gt),qt=!!H.parentID,zt=ud(B.id)>0&&(!qt||h),Ee=H.time?.updated||H.time?.created||Date.now(),Ue=_d(Ee),et=fh(Ee),lt=P===rt,[ut,kt]=c.useState(!1),st=lt||ut,_t=c.useMemo(()=>Eo(H.title)!==null,[H.title]),[es,Ds]=c.useState(!1),Os=c.useMemo(()=>ve(n).length,[ve,n]),bs=c.useCallback(async De=>{const Bt=[];let Qt=0;for(const ls of De)try{if(!se)throw new Error("Session directory is required for export");const js=await Ke({directory:se,sessionID:ls.session.id});if(!js)throw new Error("Session runtime changed during export");const hs=ls.session.title||e("sessions.sidebar.session.export.untitledSubagent"),nn=ls.session.agent,ts=await bs(ls.children);Qt+=ts.skipped,Bt.push({title:hs,agent:nn,records:js,children:ts.children})}catch{Qt+=ve(ls).length+1}return{children:Bt,skipped:Qt}},[ve,Ke,se,e]),xs=c.useCallback(De=>{De<=0||Oe.warning(De===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:De}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:De}))},[e]),os=c.useCallback(async De=>{if(!se){Oe.error(e("sessions.sidebar.session.export.nothingToExport"));return}const Bt=await Ke({directory:se,sessionID:B.id}).catch(()=>null);if(!Bt){Oe.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}if(Bt.length===0){Oe.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Qt,ls=0;if(De&&n.children.length>0){const ts=await bs(n.children);Qt=ts.children,ls=ts.skipped}const js=pu(Bt,H.title??null,Qt),hs=xu(H.title??null),nn=await bu(js,hs);if(nn){Oe.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Zg()),onClick:()=>{Jg(nn).then(ts=>{ts||Oe.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),xs(ls);return}gu(js,hs),Oe.success(e("sessions.sidebar.session.export.success")),xs(ls)},[bs,Ke,n.children,H.title,B.id,se,xs,e]),Ps=c.useCallback(async()=>{if(n.children.length>0){Ge(!0),Le(!0);return}await os(!1)},[os,n.children.length]),fs=c.useCallback(()=>{se&&Fn("desktop_open_session_mini_chat_window",{sessionId:B.id,directory:se,apiBaseUrl:Ln(),clientToken:zr()}).catch(De=>{console.warn("[session-sidebar] failed to open mini chat window",De)})},[B.id,se]);if(c.useEffect(()=>{if(y!==B.id)return;const De=Bt=>{const ls=(Bt.target instanceof HTMLElement?Bt.target:null)?.closest?.(`[data-session-rename-form="${CSS.escape(B.id)}"]`);fe.current&&!ls&&te.current(de.current)};return document.addEventListener("mousedown",De),()=>document.removeEventListener("mousedown",De)},[y,B.id]),c.useLayoutEffect(()=>{if(y!==B.id){he.current===B.id&&(he.current=null);return}he.current!==B.id&&(he.current=B.id,Pe(S))},[y,S,B.id]),y===B.id)return s.jsx("div",{style:{paddingLeft:kc+r*xo},className:"group relative my-0.5 flex items-center rounded-sm py-1 pr-1.5",children:s.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:s.jsxs("form",{ref:fe,"data-session-rename-form":B.id,className:"flex w-full items-center gap-2",onSubmit:De=>{De.preventDefault(),g(pe)},children:[s.jsx("input",{value:pe,onChange:De=>Pe(De.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:De=>{if(De.stopPropagation(),De.key==="Escape"){f();return}}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:f,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"size-4"})})]})})},B.id);const Bs=Mt.length,Ks=Ft===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:Ft}),ys=V0({actionsAlwaysVisible:O&&!ee,menuOpen:st,hideOnHoverClass:Y}),ws=!Tt&&!Pt&&zt&&!ae,Ss=Pt||ws,hn=e(Pt?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),Gs=s.jsx("span",{className:Ie("h-1.5 w-1.5 rounded-full",Pt?"bg-primary":"bg-[var(--status-info)]"),"aria-label":hn,title:hn}),dn=(Pt||ws)&&Nt,Lt=!O&&At&&(Tt||Ss||Ot),Wt=Ot&&!Tt&&!Ss,q=s.jsx(R,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),Ve=Tt||Ss||Wt?s.jsx("span",{style:{left:da+r*xo},className:Ie("pointer-events-none absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",Lt?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Tt?s.jsx(R,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):Ss?Gs:Wt?q:null}):null,Xe=At&&!O&&(Tt||Ss||Ot),ft=At?s.jsx("span",{role:"button",tabIndex:0,onClick:De=>{De.stopPropagation(),De.currentTarget.blur(),x($t)},onKeyDown:De=>{(De.key==="Enter"||De.key===" ")&&(De.preventDefault(),De.stopPropagation(),x($t))},style:{minWidth:14,minHeight:14,left:da+r*xo},className:Ie("absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",Xe?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Zt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Zt?s.jsx(R,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(R,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Dt=St?s.jsx(R,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,gt=De=>{De&&kt(!1),M(De?rt:null)},wt=De=>{if(!De&&ye.current){const{id:Bt,title:Qt}=ye.current;ye.current=null,b(Bt),v(Qt)}},is=De=>{kt(De)},cs=De=>{De.preventDefault(),De.stopPropagation(),M(lt?null:rt)},Jt=De=>{De.preventDefault(),De.stopPropagation()},tn=De=>{De.preventDefault(),De.stopPropagation()},un=De=>{De.preventDefault(),De.stopPropagation()},ir=De=>{De.preventDefault(),De.stopPropagation()},Tn=De=>{De.preventDefault(),De.stopPropagation(),M(null),I(B,{archivedBucket:l})},di=De=>{De.preventDefault(),De.stopPropagation(),M(null),I(B,{archivedBucket:l,hardDelete:!0,skipConfirm:!0})},qa=De=>{De.preventDefault(),De.stopPropagation()},oe=De=>{De.preventDefault(),De.stopPropagation()},tt=De=>{De.preventDefault(),De.stopPropagation(),W?.vscode?.executeCommand("openchamber.openSessionInEditor",B.id,jt)},pt=De=>{if(ge.current){ge.current=!1;return}if(Qe){if(De?.preventDefault(),De?.stopPropagation(),De?.shiftKey){const Qt=Array.from(document.querySelectorAll("[data-session-row]")).map(hs=>hs.getAttribute("data-session-row")).filter(hs=>hs!==null&&hs.length>0),ls=gs.getState().anchorId,js=new Map;js.set(B.id,ve(n)),K(ls,B.id,Qt,we,js);return}le(B.id,we,ve(n));return}De?.currentTarget&&Cj(De.currentTarget),p(B.id,se)},Vt=De=>{De.defaultPrevented||(De.target instanceof HTMLElement?De.target:null)?.closest('button, a, input, [role="menuitem"], [role="menu"]')||pt(De)},vs=De=>{(De.button===2||De.button===0&&De.ctrlKey&&!Qe)&&(ge.current=!0)},as=De=>{_&&De.pointerType==="touch"&&Re(!0)},sn=De=>{_&&De.pointerType==="touch"&&Re(!1)},In=De=>{ot.current=De,ct.current+=1;const Bt=ct.current;if(!De){mt(!1),je(!1);return}const Qt=T({projectId:o??null,sourceDirectory:se,currentWorktree:Et});Ct(Qt.cachedTargets),mt(!0),je(!1),Qt.refreshTargets.then(ls=>{!ot.current||ct.current!==Bt||(Ct(ls),mt(!1),je(!1))}).catch(()=>{!ot.current||ct.current!==Bt||(mt(!1),je(!0))})},oo=({Item:De,Separator:Bt,Sub:Qt,SubTrigger:ls,SubContent:js})=>s.jsxs(s.Fragment,{children:[s.jsxs(De,{onClick:()=>{ye.current={id:B.id,title:jt}},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(De,{onClick:()=>A(B.id),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(De,{onClick:()=>se&&U({directory:se,sessionId:B.id}),className:"[&>svg]:mr-1",children:[Ot?s.jsx(R,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(R,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Ot?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),H.share?s.jsxs(s.Fragment,{children:[s.jsx(De,{onClick:()=>{H.share?.url&&k(H.share.url,B.id)},className:"[&>svg]:mr-1",children:C===B.id?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(De,{onClick:()=>D(B.id),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(De,{onClick:()=>N(H),className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(De,{onClick:()=>{Ps()},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),B0({isSubtaskSession:qt,archivedBucket:!!l,isVSCode:ee,sessionDirectory:se})?(()=>{const hs=F0({sessionDirectory:se,isStreaming:Pt,isMovingToWorktree:Tt}),nn=jj({targets:vt,isRefreshing:It,loadFailed:Ze});return s.jsxs(Qt,{onOpenChange:In,children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsxs(ls,{disabled:hs,className:"w-full [&>svg]:mr-1","data-session-worktree-submenu-trigger":B.id,children:[s.jsx(R,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktreeTargets")]})}),s.jsx(xt,{side:"right",className:"max-w-72",children:e(Tt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":Pt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltipTargets")})]}),s.jsxs(js,{className:"min-w-[220px]","data-session-worktree-submenu":B.id,children:[vt.map(ts=>{const rn=dt(ts.metadata.path??null)??ts.metadata.path,Cr=ts.isPrimary?e("sessions.sidebar.session.moveToWorktree.main"):ts.metadata.label||ts.metadata.branch||ts.metadata.name||ts.metadata.path,ps=ts.isCurrent||ts.metadata.worktreeStatus!=="ready";return s.jsxs(De,{disabled:ps,title:ts.metadata.path,"data-session-worktree-target":rn,onClick:()=>{ps||!se||Qi({kind:"existing",root:H,descendants:$e(n),sourceDirectory:se,destination:ts.metadata,messages:Gi(e,{success:"sessions.sidebar.session.moveToWorktree.existingSuccess",failure:"sessions.sidebar.session.moveToWorktree.existingFailed"})})},children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1 truncate",children:[s.jsx("span",{className:"truncate",children:Cr}),ts.isCurrent?s.jsx("span",{className:"sr-only",children:e("sessions.sidebar.session.moveToWorktree.current")}):null]}),ts.isCurrent?s.jsx(R,{name:"check",className:"ml-2 h-3.5 w-3.5 flex-shrink-0 text-primary","aria-hidden":"true"}):null]},rn)}),nn.refreshState==="loading"?s.jsx(De,{disabled:!0,"data-session-worktree-refresh-state":"loading",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.refreshing")}):null,nn.refreshState==="error"?s.jsx(De,{disabled:!0,"data-session-worktree-refresh-state":"error",className:"py-0.5 text-muted-foreground typography-micro",children:e("sessions.sidebar.session.moveToWorktree.loadFailed")}):null,s.jsx(Bt,{}),s.jsxs(De,{disabled:hs,"data-session-worktree-new-action":"true",onClick:()=>{hs||!se||Qi({kind:"quick",root:H,descendants:$e(n),sourceDirectory:se,messages:Gi(e,{success:"sessions.sidebar.session.moveToWorktree.success",failure:"sessions.sidebar.session.moveToWorktree.failed"})})},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.newWorktree")]})]})]})})():null,_t?s.jsxs(De,{onClick:()=>Ds(!0),className:"[&>svg]:mr-1",children:[s.jsx(yj,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,se&&!l?(()=>{const hs=[],nn=ps=>{const Ts=dt(ps??null);Ts&&!hs.includes(Ts)&&hs.push(Ts)};if(o&&!ee){const ps=Ht.getState().projects.find(ar=>ar.id===o),Ts=dt(ps?.path??null);nn(Ts),Ts&&(qe.getState().availableWorktreesByProject.get(Ts)??[]).forEach(ar=>nn(ar.path))}nn(Ld(se)),nn(se);const ts=hs.flatMap(ps=>X(ps).map(Ts=>({scope:ps,folder:Ts}))),rn=ts.find(({scope:ps,folder:Ts})=>Q(ps,B.id)===Ts.id)??null,Cr=hs[0]??se;return s.jsxs(s.Fragment,{children:[s.jsx(Bt,{}),s.jsxs(Qt,{children:[s.jsxs(ls,{className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(js,{className:"min-w-[180px]",children:[ts.length===0?s.jsx(De,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ts.map(({scope:ps,folder:Ts})=>{const ar=rn?.folder.id===Ts.id;return s.jsxs(De,{onClick:()=>{if(ar){me(ps,B.id);return}rn&&rn.scope!==ps&&me(rn.scope,B.id),re(ps,Ts.id,B.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Ts.name}),ar?s.jsx(R,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Ts.id)}),s.jsx(Bt,{}),s.jsxs(De,{onClick:()=>{const ps=z(Cr);ps&&(be.current=!0,rn&&rn.scope!==Cr&&me(rn.scope,B.id),re(Cr,ps.id,B.id))},children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),rn?s.jsxs(De,{onClick:()=>{me(rn.scope,B.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,ee?null:s.jsxs(De,{disabled:!se,onClick:()=>{se&&G(se,{mode:"chat",dedupeKey:`session:${B.id}`,label:jt,sessionTitleFallback:jt})},className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),ue?s.jsxs(De,{disabled:!se,onClick:fs,className:"[&>svg]:mr-1",children:[s.jsx(R,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Bt,{}),l?null:s.jsxs(De,{className:"[&>svg]:mr-1",onClick:()=>I(B,{archivedBucket:l}),children:[s.jsx(R,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),l?s.jsxs(De,{className:"[&>svg]:mr-1",onClick:()=>V(B),children:[s.jsx(R,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(De,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>I(B,{archivedBucket:l,hardDelete:!0}),children:[s.jsx(R,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Am=s.jsx(Zs,{align:"end",className:"min-w-[180px]",finalFocus:()=>be.current?(be.current=!1,!1):!ce.current,children:oo({Item:Ut,Separator:Ls,Sub:ph,SubTrigger:gh,SubContent:bh})}),Dm=s.jsx(Ui,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Ki,{"data-slot":"dropdown-menu-content",finalFocus:()=>be.current?(be.current=!1,!1):!ce.current,style:{color:"var(--surface-elevated-foreground)"},className:Ie(Ti,"min-w-[180px]"),children:oo({Item:({className:De,...Bt})=>s.jsx(iu,{className:Ie(fd,De),...Bt}),Separator:({className:De,...Bt})=>s.jsx(ou,{className:Ie(md,De),...Bt}),Sub:dg,SubTrigger:({className:De,children:Bt,...Qt})=>s.jsxs(ug,{className:Ie(hh,De),...Qt,children:[Bt,s.jsx(R,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:De,children:Bt,...Qt})=>s.jsx(Ui,{children:s.jsx(Hi,{className:"app-region-no-drag z-50",children:s.jsx(Ki,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Ie(Ti,De),...Qt,children:Bt})})})})})})});return s.jsxs(c.Fragment,{children:[s.jsx(R0,{sessionId:B.id,sessionDirectory:se??null,sessionTitle:jt,children:s.jsxs(lu,{open:ut,onOpenChange:is,onOpenChangeComplete:wt,children:[s.jsxs(au,{render:s.jsx("div",{"data-session-row":B.id,"data-session-scope":we??"","data-session-archived":l?"1":"0",onClick:Vt,style:{paddingLeft:kc+r*xo},className:Ie("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",ae&&!He&&"bg-primary/10",He&&"bg-interactive-selection")}),children:[Ve,ft,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:as,onPointerUp:sn,onPointerCancel:sn,onMouseDown:vs,onClick:De=>pt(De),onDoubleClick:De=>{De.stopPropagation(),w(B.id,jt)},className:Ie("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",Ce&&"bg-interactive-hover/70",O?ee?ie:xe:ie),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:Ie("block min-w-0 flex-1 truncate typography-ui-label font-normal",ae?"text-primary":zt?"text-foreground":"text-foreground/80"),children:Co(jt,m)}),O?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 typography-micro text-muted-foreground/75",children:dn?s.jsx(kl,{sessionId:B.id,running:Pt}):s.jsxs(s.Fragment,{children:[nt,Me?s.jsx(R,{name:"git-branch",className:Ie("h-3 w-3",!Z&&"text-muted-foreground/60"),style:Z?{color:Z}:void 0}):null,et]})}):dn||nt||Me||E==="recent"?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:Ie("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",st?"opacity-0":Y),children:dn?s.jsx(kl,{sessionId:B.id,running:Pt,className:"typography-micro"}):s.jsxs(s.Fragment,{children:[nt,Me?s.jsx(R,{name:"git-branch",className:Ie("h-3 w-3",!Z&&"text-muted-foreground/60"),style:Z?{color:Z}:void 0}):null,E==="recent"?s.jsx("span",{className:"flex-shrink-0 typography-micro leading-none text-muted-foreground/75 tabular-nums",children:et}):null]})})}):null,Bs>0?s.jsxs("span",{className:Ie("inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",ys),title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(R,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Bs})]}):null,Ft>0?s.jsxs("span",{className:Ie("inline-flex items-center gap-1 rounded bg-status-info/10 px-1 py-0.5 text-[0.7rem] text-status-info flex-shrink-0",ys),title:Ks,"aria-label":Ks,children:[s.jsx(R,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Ft})]}):null]})})}),ee?null:s.jsx(xt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:jt}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:Ue,children:et})]}),Se?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(R,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:Se})]}):null,Be?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:Z?{color:Z}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:Be})]}):null,Te&&$?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(R,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:Z?{color:Z}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:Z?{color:Z}:void 0,children:["#",Te.number," · ",$]})]}):null]})})]})}),Dt&&!_?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:Dt}):null,s.jsxs("div",{className:Ie("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",st||O&&!ee?"opacity-100":Ie("opacity-0",ne)),children:[J?s.jsx(Nj,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:O?"h-6 w-6":"h-4 w-4",iconSizeClass:O?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:un,onMouseDown:ir,onArchive:Tn,onDelete:di}):null,F?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",O?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:qa,onMouseDown:oe,onClick:tt,onKeyDown:De=>De.stopPropagation(),children:s.jsx(R,{name:"external-link",className:Ie(O?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(xt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(en,{open:lt,onOpenChange:gt,onOpenChangeComplete:wt,children:[s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",O?"h-6 w-6 opacity-100":st?"h-4 w-4 opacity-100":Ie("h-4 w-4 opacity-0",ne)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Jt,onMouseDown:tn,onClick:cs,onKeyDown:De=>De.stopPropagation(),children:s.jsx(R,{name:"more-2",className:Ie(O?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Am]})]})]}),Dm]})}),At&&Zt?L:null,s.jsx(Ns,{open:We,onOpenChange:Le,children:s.jsxs(As,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Hs,{children:[s.jsx(Rs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ms,{children:Os===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Os}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Os})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Fe,onChange:De=>Ge(De.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Sn,{children:[s.jsx(at,{type:"button",onClick:()=>Le(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{type:"button",onClick:()=>{Le(!1),os(Fe)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),_t?s.jsx(xj,{session:H,open:es,onOpenChange:Ds}):null]},B.id)}const Cc=t=>dt(t.session.directory??null),Dj=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),Pj=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},Nc=t=>t.menuOpenSessionId??Pj(t),yo=(t,e,n)=>e?n.has(t.node.session.id)?!0:Yn(t.node,e):!1,ua=(t,e,n,r,i)=>{if(t.session.id!==e.session.id)return!0;const o=i(t);if(n.has(o)!==r.has(o)||t.children.length!==e.children.length)return!0;for(let l=0;l<t.children.length;l+=1)if(ua(t.children[l],e.children[l],n,r,i))return!0;return!1},Tj=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return ua(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${t.renderContext??"project"}:${n}:${i.session.id}`)||ua(t.node,e.node,t.expandedParents,e.expandedParents,i=>`${e.renderContext??"project"}:${r}:${i.session.id}`)},Ij=(t,e)=>t.id===e.id&&t.title===e.title&&t.directory===e.directory&&t.parentID===e.parentID&&t.share?.url===e.share?.url&&t.time?.created===e.time?.created&&t.time?.updated===e.time?.updated&&t.time?.archived===e.time?.archived,Ej=(t,e)=>{if(t.node.session.id!==e.node.session.id||!Ij(t.node.session,e.node.session)||!kj(t.node,e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||t.relativeTimeTick!==e.relativeTimeTick||Cc(t.node)!==Cc(e.node)||!Dj(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&am(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&Tj(t,e)||t.editingId!==e.editingId&&(yo(t,t.editingId,t.subtreeContainsEditing)||yo(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(yo(t,t.editingId,t.subtreeContainsEditing)||yo(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(Yn(t.node,t.copiedSessionId)||Yn(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=Nc(t),r=Nc(e);if(Yn(t.node,n)||Yn(e.node,r))return!1}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.children===e.children},Rj=c.memo(Aj,Ej);function Mj(t){return t.stopPropagation()}const Oj=t=>{const{t:e}=ht(),n=c.useRef(null),r=c.useRef(t.editingId),i=c.useRef(t.editTitle),o=c.useRef(t.deleteSessionConfirm);r.current=t.editingId,i.current=t.editTitle,o.current=t.deleteSessionConfirm;const l=Ae(G=>G.setSessionSwitcherOpen),a=qe(G=>G.setCurrentSession),d=qe(G=>G.updateSessionTitle),u=qe(G=>G.shareSession),m=qe(G=>G.unshareSession),h=qe(G=>G.deleteSession),y=qe(G=>G.deleteSessions),b=qe(G=>G.archiveSession),S=qe(G=>G.archiveSessions),v=qe(G=>G.unarchiveSession),{mobileVariant:g,allowReselect:f,onSessionSelected:x,isSessionSearchOpen:p,sessionSearchQuery:w,setSessionSearchQuery:N,setIsSessionSearchOpen:C,descendantIds:k,showDeletionDialog:A,setDeleteSessionConfirm:D,setEditingId:P,setEditTitle:M,setCopiedSessionId:z}=t;c.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const I=c.useCallback((G,ee)=>{Pi("navigation.session_select"),Ae.getState().closeMainSurfaces();const ue=()=>{!p&&w.length===0||(N(""),C(!1))};if(g&&l(!1),G===qe.getState().currentSessionId){f&&x?.(G),ue();return}Pi("navigation.session_state_set"),a(G,ee??null),x?.(G),ue()},[f,p,g,x,w,a,C,N,l]),V=c.useCallback((G,ee)=>{P(G),M(ee)},[M,P]),T=c.useCallback(async G=>{const ee=r.current;if(!ee)return;const ue=(G??i.current).trim();ue&&await d(ee,ue),P(null),M("")},[M,P,d]),_=c.useCallback(()=>{P(null),M("")},[M,P]),O=c.useCallback(async(G,ee)=>{try{return(await xn(G)).ok?(z(ee),n.current&&clearTimeout(n.current),n.current=window.setTimeout(()=>{z(null),n.current=null},2e3),!0):!1}catch{return!1}},[z]),j=c.useCallback(async G=>{const ee=await u(G.id);if(!ee?.share?.url){Oe.error(e("sessions.sidebar.session.share.error"));return}const ue=await O(ee.share.url,G.id);Oe[ue?"success":"warning"](e("sessions.sidebar.session.share.successTitle"),{description:e(ue?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},[O,u,e]),E=c.useCallback((G,ee)=>{O(G,ee).then(ue=>{ue||Oe.error(e("sessions.sidebar.session.share.copyUrlError"))})},[O,e]),L=c.useCallback(G=>{xn(G).then(ee=>{if(ee.ok){Oe.success(e("sessions.sidebar.session.copyId.success"));return}Oe.error(e("sessions.sidebar.session.copyId.error"))}).catch(()=>Oe.error(e("sessions.sidebar.session.copyId.error")))},[e]),U=c.useCallback(async G=>{await m(G)?Oe.success(e("sessions.sidebar.session.unshare.success")):Oe.error(e("sessions.sidebar.session.unshare.error"))},[e,m]),X=c.useCallback(async(G,ee,ue)=>{const W=ee?.archivedBucket===!0||ee?.hardDelete===!0,ne=ue?.descendantIds??k;if(ne.length===0){(W?await h(G.id):await b(G.id))?Oe.success(e(W?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):Oe.error(e(W?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Y=[G.id,...ne];if(W){const{deletedIds:ie,failedIds:xe}=await y(Y);if(xe.length===0){const ge=ie.length;Oe.success(ge===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:ge}):e("sessions.sidebar.bulkActions.deletedPlural",{count:ge}))}else Oe.error(e("sessions.sidebar.session.delete.error"));return}const{archivedIds:F,failedIds:J}=await S(Y);F.length>0&&Oe.success(F.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:F.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:F.length})),J.length>0&&Oe.error(J.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:J.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:J.length}))},[b,S,h,y,k,e]),Q=c.useCallback((G,ee)=>{const ue=ee?.archivedBucket===!0||ee?.hardDelete===!0,W=[...k];if(!A||ee?.skipConfirm===!0){X(G,ee,{descendantIds:W});return}D({session:G,descendantCount:W.length,descendantIds:W,archivedBucket:ue})},[k,X,D,A]),me=c.useCallback(async()=>{const G=o.current;if(!G)return;const{session:ee,archivedBucket:ue,descendantIds:W}=G;D(null),await X(ee,{archivedBucket:ue},{descendantIds:W})},[X,D]),re=c.useCallback(async G=>{await v(G.id)?Oe.success(e("sessions.sidebar.session.restore.success")):Oe.error(e("sessions.sidebar.session.restore.error"))},[e,v]);return c.useMemo(()=>({handleSessionSelect:I,handleSessionDoubleClick:V,handleSaveEdit:T,handleCancelEdit:_,handleShareSession:j,handleCopyShareUrl:E,handleCopySessionId:L,handleUnshareSession:U,handleDeleteSession:Q,handleRestoreSession:re,confirmDeleteSession:me}),[_,L,E,Q,re,T,V,I,j,U,me])};function Bj(t){const e=Ye.c(71),{t:n}=ht(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t;let d,u,m,h,y,b,S,v,g,f;if(e[0]!==i||e[1]!==n||e[2]!==r){const E=n("sessions.sidebar.session.untitled");h=Ns,g=!!r,e[13]!==i?(f=U=>{U||i(null)},e[13]=i,e[14]=f):f=e[14],m=As,S=!1,v="max-w-sm gap-5",u=Hs;let L;e[15]!==n||e[16]!==r?.archivedBucket?(L=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=L):L=e[17],e[18]!==L?(b=s.jsx(Rs,{children:L}),e[18]=L,e[19]=b):b=e[19],d=Ms,y=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}),e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=m,e[6]=h,e[7]=y,e[8]=b,e[9]=S,e[10]=v,e[11]=g,e[12]=f}else d=e[3],u=e[4],m=e[5],h=e[6],y=e[7],b=e[8],S=e[9],v=e[10],g=e[11],f=e[12];let x;e[20]!==d||e[21]!==y?(x=s.jsx(d,{children:y}),e[20]=d,e[21]=y,e[22]=x):x=e[22];let p;e[23]!==u||e[24]!==b||e[25]!==x?(p=s.jsxs(u,{children:[b,x]}),e[23]=u,e[24]=b,e[25]=x,e[26]=p):p=e[26];let w;e[27]!==l||e[28]!==o?(w=()=>l(!o),e[27]=l,e[28]=o,e[29]=w):w=e[29];const N=!o;let C;e[30]!==o?(C=o?s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=o,e[31]=C):C=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let A;e[34]!==C||e[35]!==k||e[36]!==w||e[37]!==N?(A=s.jsxs("button",{type:"button",onClick:w,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":N,children:[C,k]}),e[34]=C,e[35]=k,e[36]=w,e[37]=N,e[38]=A):A=e[38];let D;e[39]!==i?(D=()=>i(null),e[39]=i,e[40]=D):D=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let M;e[43]!==D||e[44]!==P?(M=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=D,e[44]=P,e[45]=M):M=e[45];let z;e[46]!==a?(z=()=>{a()},e[46]=a,e[47]=z):z=e[47];let I;e[48]!==n||e[49]!==r?.archivedBucket?(I=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=I):I=e[50];let V;e[51]!==z||e[52]!==I?(V=s.jsx("button",{type:"button",onClick:z,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:I}),e[51]=z,e[52]=I,e[53]=V):V=e[53];let T;e[54]!==M||e[55]!==V?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[M,V]}),e[54]=M,e[55]=V,e[56]=T):T=e[56];let _;e[57]!==A||e[58]!==T?(_=s.jsxs(Sn,{className:"w-full sm:items-center sm:justify-between",children:[A,T]}),e[57]=A,e[58]=T,e[59]=_):_=e[59];let O;e[60]!==m||e[61]!==S||e[62]!==_||e[63]!==v||e[64]!==p?(O=s.jsxs(m,{showCloseButton:S,className:v,children:[p,_]}),e[60]=m,e[61]=S,e[62]=_,e[63]=v,e[64]=p,e[65]=O):O=e[65];let j;return e[66]!==h||e[67]!==O||e[68]!==g||e[69]!==f?(j=s.jsx(h,{open:g,onOpenChange:f,children:O}),e[66]=h,e[67]=O,e[68]=g,e[69]=f,e[70]=j):j=e[70],j}function Fj(t){const e=Ye.c(57),{t:n}=ht(),{value:r,setValue:i,showDeletionDialog:o,setShowDeletionDialog:l,onConfirm:a}=t,d=r?.archivedBucket===!0,u=r?.sessionCount??0;let m;e[0]!==d||e[1]!==u||e[2]!==n?(m=n(d?u===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":u===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=u,e[2]=n,e[3]=m):m=e[3];const h=m;let y;e[4]!==d||e[5]!==u||e[6]!==n?(y=d?u===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:u}):u===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:u}),e[4]=d,e[5]=u,e[6]=n,e[7]=y):y=e[7];const b=y,S=!!r;let v;e[8]!==i?(v=j=>{j||i(null)},e[8]=i,e[9]=v):v=e[9];let g;e[10]!==h?(g=s.jsx(Rs,{children:h}),e[10]=h,e[11]=g):g=e[11];let f;e[12]!==b?(f=s.jsx(Ms,{children:b}),e[12]=b,e[13]=f):f=e[13];let x;e[14]!==g||e[15]!==f?(x=s.jsxs(Hs,{children:[g,f]}),e[14]=g,e[15]=f,e[16]=x):x=e[16];let p;e[17]!==l||e[18]!==o?(p=()=>l(!o),e[17]=l,e[18]=o,e[19]=p):p=e[19];const w=!o;let N;e[20]!==o?(N=o?s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=o,e[21]=N):N=e[21];let C;e[22]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=C):C=e[23];let k;e[24]!==C||e[25]!==p||e[26]!==w||e[27]!==N?(k=s.jsxs("button",{type:"button",onClick:p,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":w,children:[N,C]}),e[24]=C,e[25]=p,e[26]=w,e[27]=N,e[28]=k):k=e[28];let A;e[29]!==i?(A=()=>i(null),e[29]=i,e[30]=A):A=e[30];let D;e[31]!==n?(D=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=D):D=e[32];let P;e[33]!==A||e[34]!==D?(P=s.jsx("button",{type:"button",onClick:A,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:D}),e[33]=A,e[34]=D,e[35]=P):P=e[35];let M;e[36]!==a?(M=()=>{a()},e[36]=a,e[37]=M):M=e[37];let z;e[38]!==d||e[39]!==n?(z=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=z):z=e[40];let I;e[41]!==M||e[42]!==z?(I=s.jsx("button",{type:"button",onClick:M,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:z}),e[41]=M,e[42]=z,e[43]=I):I=e[43];let V;e[44]!==P||e[45]!==I?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[P,I]}),e[44]=P,e[45]=I,e[46]=V):V=e[46];let T;e[47]!==k||e[48]!==V?(T=s.jsxs(Sn,{className:"w-full sm:items-center sm:justify-between",children:[k,V]}),e[47]=k,e[48]=V,e[49]=T):T=e[49];let _;e[50]!==T||e[51]!==x?(_=s.jsxs(As,{showCloseButton:!1,className:"max-w-sm gap-5",children:[x,T]}),e[50]=T,e[51]=x,e[52]=_):_=e[52];let O;return e[53]!==S||e[54]!==_||e[55]!==v?(O=s.jsx(Ns,{open:S,onOpenChange:v,children:_}),e[53]=S,e[54]=_,e[55]=v,e[56]=O):O=e[56],O}function _j(t){const e=Ye.c(36),{t:n}=ht(),{value:r,setValue:i,onConfirm:o}=t,l=!!r;let a;e[0]!==i?(a=N=>{N||i(null)},e[0]=i,e[1]=a):a=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let u;e[4]!==d?(u=s.jsx(Rs,{children:d}),e[4]=d,e[5]=u):u=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let h;e[9]!==m?(h=s.jsx(Ms,{children:m}),e[9]=m,e[10]=h):h=e[10];let y;e[11]!==u||e[12]!==h?(y=s.jsxs(Hs,{children:[u,h]}),e[11]=u,e[12]=h,e[13]=y):y=e[13];let b;e[14]!==i?(b=()=>i(null),e[14]=i,e[15]=b):b=e[15];let S;e[16]!==n?(S=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=S):S=e[17];let v;e[18]!==b||e[19]!==S?(v=s.jsx("button",{type:"button",onClick:b,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:S}),e[18]=b,e[19]=S,e[20]=v):v=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let f;e[23]!==o||e[24]!==g?(f=s.jsx("button",{type:"button",onClick:o,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:g}),e[23]=o,e[24]=g,e[25]=f):f=e[25];let x;e[26]!==f||e[27]!==v?(x=s.jsxs(Sn,{children:[v,f]}),e[26]=f,e[27]=v,e[28]=x):x=e[28];let p;e[29]!==x||e[30]!==y?(p=s.jsxs(As,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,x]}),e[29]=x,e[30]=y,e[31]=p):p=e[31];let w;return e[32]!==l||e[33]!==a||e[34]!==p?(w=s.jsx(Ns,{open:l,onOpenChange:a,children:p}),e[32]=l,e[33]=a,e[34]=p,e[35]=w):w=e[35],w}const Lj=new Set;function Qo(t){const e=Ye.c(140),{node:n,depth:r,groupDirectory:i,projectId:o,archivedBucket:l,secondaryMeta:a,renderContext:d,renderExtras:u,pinnedSessionIds:m,expandedParents:h,hasSessionSearchQuery:y,normalizedSessionSearchQuery:b,notifyOnSubtasks:S,editingId:v,setEditingId:g,editTitle:f,setEditTitle:x,toggleParent:p,openSidebarMenuKey:w,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:M,deleteSessionConfirm:z,setDeleteSessionConfirm:I,startFolderRename:V,copiedSessionId:T,setCopiedSessionId:_,startSessionWorktreeMenuLoad:O,mobileVariant:j,alwaysShowActions:E}=t,L=r===void 0?0:r,U=l===void 0?!1:l,X=d===void 0?"project":d,Q=ms(Vj),me=ms(zj),re=Ae(Wj),G=Ae($j);let ee;if(e[0]!==n){ee=[];const Z=Ne=>Ne.children.forEach(Me=>{ee.push(Me.session.id),Z(Me)});Z(n),e[0]=n,e[1]=ee}else ee=e[1];const ue=ee;let W;e[2]!==Q||e[3]!==V||e[4]!==me?(W=(Z,Ne)=>{if(!Z)return null;Ne&&ms.getState().collapsedFolderIds.has(Ne)&&me(Ne);const Me=Q(Z,"New folder",Ne);return V(Z,Me),Me},e[2]=Q,e[3]=V,e[4]=me,e[5]=W):W=e[5];const ne=W;let Y;e[6]!==C||e[7]!==T||e[8]!==z||e[9]!==ue||e[10]!==f||e[11]!==v||e[12]!==A||e[13]!==j||e[14]!==k||e[15]!==D||e[16]!==_||e[17]!==I||e[18]!==x||e[19]!==g||e[20]!==M||e[21]!==P||e[22]!==re?(Y={mobileVariant:j,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:M,descendantIds:ue,showDeletionDialog:re,setDeleteSessionConfirm:I,deleteSessionConfirm:z,editingId:v,setEditingId:g,editTitle:f,setEditTitle:x,copiedSessionId:T,setCopiedSessionId:_},e[6]=C,e[7]=T,e[8]=z,e[9]=ue,e[10]=f,e[11]=v,e[12]=A,e[13]=j,e[14]=k,e[15]=D,e[16]=_,e[17]=I,e[18]=x,e[19]=g,e[20]=M,e[21]=P,e[22]=re,e[23]=Y):Y=e[23];const F=Oj(Y),J=u?.childRenderExtrasFor,ie=n.session.directory??i;let xe;e[24]!==U||e[25]!==o||e[26]!==X||e[27]!==ie?(xe={groupDirectory:ie,projectId:o,archivedBucket:U,renderContext:X},e[24]=U,e[25]=o,e[26]=X,e[27]=ie,e[28]=xe):xe=e[28];const ge=xe,Ce=F.handleSaveEdit,Re=F.handleCancelEdit,ce=F.handleSessionSelect,ye=F.handleSessionDoubleClick,be=F.handleShareSession,te=F.handleCopyShareUrl,pe=F.handleCopySessionId,Pe=F.handleUnshareSession,de=F.handleDeleteSession,he=F.handleRestoreSession,fe=u?.subtreeContainsEditing??Lj,B=u?.menuOpenSessionId??null,H=u?.nodeStructureKey??"",ke=u?.relativeTimeTick;let Se;if(e[29]!==C||e[30]!==E||e[31]!==ge||e[32]!==J||e[33]!==T||e[34]!==z||e[35]!==L||e[36]!==f||e[37]!==v||e[38]!==h||e[39]!==y||e[40]!==A||e[41]!==j||e[42]!==n.children||e[43]!==b||e[44]!==S||e[45]!==k||e[46]!==w||e[47]!==m||e[48]!==D||e[49]!==_||e[50]!==I||e[51]!==x||e[52]!==g||e[53]!==M||e[54]!==N||e[55]!==P||e[56]!==V||e[57]!==O||e[58]!==p){let Z;e[60]!==C||e[61]!==E||e[62]!==ge||e[63]!==J||e[64]!==T||e[65]!==z||e[66]!==L||e[67]!==f||e[68]!==v||e[69]!==h||e[70]!==y||e[71]!==A||e[72]!==j||e[73]!==b||e[74]!==S||e[75]!==k||e[76]!==w||e[77]!==m||e[78]!==D||e[79]!==_||e[80]!==I||e[81]!==x||e[82]!==g||e[83]!==M||e[84]!==N||e[85]!==P||e[86]!==V||e[87]!==O||e[88]!==p?(Z=Ne=>s.jsx(Qo,{node:Ne,pinnedSessionIds:m,expandedParents:h,hasSessionSearchQuery:y,normalizedSessionSearchQuery:b,notifyOnSubtasks:S,editingId:v,setEditingId:g,editTitle:f,copiedSessionId:T,setEditTitle:x,toggleParent:p,openSidebarMenuKey:w,setOpenSidebarMenuKey:N,allowReselect:C,onSessionSelected:k,isSessionSearchOpen:A,sessionSearchQuery:D,setSessionSearchQuery:P,setIsSessionSearchOpen:M,deleteSessionConfirm:z,setDeleteSessionConfirm:I,startFolderRename:V,setCopiedSessionId:_,startSessionWorktreeMenuLoad:O,mobileVariant:j,alwaysShowActions:E,depth:L+1,...ge,renderExtras:J?.(Ne)},Ne.session.id),e[60]=C,e[61]=E,e[62]=ge,e[63]=J,e[64]=T,e[65]=z,e[66]=L,e[67]=f,e[68]=v,e[69]=h,e[70]=y,e[71]=A,e[72]=j,e[73]=b,e[74]=S,e[75]=k,e[76]=w,e[77]=m,e[78]=D,e[79]=_,e[80]=I,e[81]=x,e[82]=g,e[83]=M,e[84]=N,e[85]=P,e[86]=V,e[87]=O,e[88]=p,e[89]=Z):Z=e[89],Se=n.children.map(Z),e[29]=C,e[30]=E,e[31]=ge,e[32]=J,e[33]=T,e[34]=z,e[35]=L,e[36]=f,e[37]=v,e[38]=h,e[39]=y,e[40]=A,e[41]=j,e[42]=n.children,e[43]=b,e[44]=S,e[45]=k,e[46]=w,e[47]=m,e[48]=D,e[49]=_,e[50]=I,e[51]=x,e[52]=g,e[53]=M,e[54]=N,e[55]=P,e[56]=V,e[57]=O,e[58]=p,e[59]=Se}else Se=e[59];let Be;e[90]!==E||e[91]!==U||e[92]!==T||e[93]!==ne||e[94]!==L||e[95]!==f||e[96]!==v||e[97]!==h||e[98]!==i||e[99]!==y||e[100]!==j||e[101]!==n||e[102]!==b||e[103]!==S||e[104]!==w||e[105]!==m||e[106]!==o||e[107]!==X||e[108]!==a||e[109]!==F.handleCancelEdit||e[110]!==F.handleCopySessionId||e[111]!==F.handleCopyShareUrl||e[112]!==F.handleDeleteSession||e[113]!==F.handleRestoreSession||e[114]!==F.handleSaveEdit||e[115]!==F.handleSessionDoubleClick||e[116]!==F.handleSessionSelect||e[117]!==F.handleShareSession||e[118]!==F.handleUnshareSession||e[119]!==x||e[120]!==g||e[121]!==N||e[122]!==O||e[123]!==fe||e[124]!==B||e[125]!==H||e[126]!==ke||e[127]!==Se||e[128]!==p?(Be=s.jsx(Rj,{expandedParents:h,hasSessionSearchQuery:y,normalizedSessionSearchQuery:b,notifyOnSubtasks:S,editingId:v,setEditingId:g,editTitle:f,setEditTitle:x,handleSaveEdit:Ce,handleCancelEdit:Re,toggleParent:p,handleSessionSelect:ce,handleSessionDoubleClick:ye,handleShareSession:be,copiedSessionId:T,handleCopyShareUrl:te,handleCopySessionId:pe,handleUnshareSession:Pe,openSidebarMenuKey:w,setOpenSidebarMenuKey:N,createFolderAndStartRename:ne,handleDeleteSession:de,handleRestoreSession:he,startSessionWorktreeMenuLoad:O,mobileVariant:j,alwaysShowActions:E,pinnedSessionIds:m,node:n,depth:L,groupDirectory:i,projectId:o,archivedBucket:U,secondaryMeta:a,renderContext:X,subtreeContainsEditing:fe,menuOpenSessionId:B,nodeStructureKey:H,relativeTimeTick:ke,children:Se}),e[90]=E,e[91]=U,e[92]=T,e[93]=ne,e[94]=L,e[95]=f,e[96]=v,e[97]=h,e[98]=i,e[99]=y,e[100]=j,e[101]=n,e[102]=b,e[103]=S,e[104]=w,e[105]=m,e[106]=o,e[107]=X,e[108]=a,e[109]=F.handleCancelEdit,e[110]=F.handleCopySessionId,e[111]=F.handleCopyShareUrl,e[112]=F.handleDeleteSession,e[113]=F.handleRestoreSession,e[114]=F.handleSaveEdit,e[115]=F.handleSessionDoubleClick,e[116]=F.handleSessionSelect,e[117]=F.handleShareSession,e[118]=F.handleUnshareSession,e[119]=x,e[120]=g,e[121]=N,e[122]=O,e[123]=fe,e[124]=B,e[125]=H,e[126]=ke,e[127]=Se,e[128]=p,e[129]=Be):Be=e[129];let _e;e[130]!==z||e[131]!==n.session.id||e[132]!==F.confirmDeleteSession||e[133]!==I||e[134]!==G||e[135]!==re?(_e=z?.session.id===n.session.id?s.jsx(Bj,{value:z,setValue:I,showDeletionDialog:re,setShowDeletionDialog:G,onConfirm:F.confirmDeleteSession}):null,e[130]=z,e[131]=n.session.id,e[132]=F.confirmDeleteSession,e[133]=I,e[134]=G,e[135]=re,e[136]=_e):_e=e[136];let Te;return e[137]!==Be||e[138]!==_e?(Te=s.jsxs(s.Fragment,{children:[Be,_e]}),e[137]=Be,e[138]=_e,e[139]=Te):Te=e[139],Te}function $j(t){return t.setShowDeletionDialog}function Wj(t){return t.showDeletionDialog}function zj(t){return t.toggleFolderCollapse}function Vj(t){return t.createFolder}const Uj=50,Hj=28,Ac=[],Kj=t=>{const e=Ye.c(6),{nodes:n,includeUnreadSubtasks:r,children:i}=t;let o;e[0]!==r||e[1]!==n?(o={nodes:n,includeUnreadSubtasks:r},e[0]=r,e[1]=n,e[2]=o):o=e[2];const l=om(o);let a;return e[3]!==i||e[4]!==l?(a=i(l),e[3]=i,e[4]=l,e[5]=a):a=e[5],a},Er=(t,e)=>e?t.sessions.some(n=>Yn(n,e)):!1,Gj=(t,e,n)=>t.sessions.some(r=>am(r,r,e,n,t.directory,t.directory)),qj=(t,e,n)=>{const r=i=>{const o=i.session.id;return e.get(o)!==n.get(o)?!0:i.children.some(r)};return t.sessions.some(r)},Qj=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",i=o=>{const l=`project:${r}:${o.session.id}`;return e.has(l)!==n.has(l)?!0:o.children.some(i)};return t.sessions.some(i)},Yj=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.sessionBatchSize!==e.sessionBatchSize||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&Gj(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.sessionOrderIndex!==e.sessionOrderIndex&&qj(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.expandedParents!==e.expandedParents&&Qj(e.group,t.expandedParents,e.expandedParents)||t.editingId!==e.editingId&&(Er(e.group,t.editingId)||Er(e.group,e.editingId))||t.editTitle!==e.editTitle&&Er(e.group,e.editingId)||t.copiedSessionId!==e.copiedSessionId&&(Er(e.group,t.copiedSessionId)||Er(e.group,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=e.group.isArchivedBucket===!0,r=Jr(e.group.sessions,t.openSidebarMenuKey,"project",n),i=Jr(e.group.sessions,e.openSidebarMenuKey,"project",n);if(r||i)return!1}if(t.folderRename!==e.folderRename){const n=e.group.folderScopes?.map(r=>r.scopeKey)??[e.group.folderScopeKey??dt(e.group.directory??null)];if(n.includes(t.folderRename?.scopeKey??null)||n.includes(e.folderRename?.scopeKey??null))return!1}return t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef&&t.notifyOnSubtasks===e.notifyOnSubtasks&&t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.toggleParent===e.toggleParent&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.allowReselect===e.allowReselect&&t.onSessionSelected===e.onSessionSelected&&t.isSessionSearchOpen===e.isSessionSearchOpen&&t.sessionSearchQuery===e.sessionSearchQuery&&t.setSessionSearchQuery===e.setSessionSearchQuery&&t.setIsSessionSearchOpen===e.setIsSessionSearchOpen&&t.deleteSessionConfirm===e.deleteSessionConfirm&&t.setDeleteSessionConfirm===e.setDeleteSessionConfirm&&t.startFolderRename===e.startFolderRename&&t.setCopiedSessionId===e.setCopiedSessionId&&t.startSessionWorktreeMenuLoad===e.startSessionWorktreeMenuLoad&&t.setFolderRenameDraft===e.setFolderRenameDraft&&t.clearFolderRename===e.clearFolderRename};function Xj(t){const{t:e}=ht(),{group:n,groupKey:r,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,groupSearchDataByGroup:d,visibleSessionCount:u,sessionBatchSize:m,collapsedGroups:h,hideDirectoryControls:y,showMoreGroupSessions:b,resetGroupSessionLimit:S,mobileVariant:v,alwaysShowActions:g,activeProjectId:f,setActiveProjectIdOnly:x,setSessionSwitcherOpen:p,openNewSessionDraft:w,pinnedSessionIds:N,sessionOrderIndex:C,notifyOnSubtasks:k,onToggleCollapsedGroup:A,dragHandleProps:D,compactBodyPadding:P=!1,scrollContainerRef:M,expandedParents:z,editingId:I,openSidebarMenuKey:V,editTitle:T,copiedSessionId:_,folderRename:O,setFolderRenameDraft:j,clearFolderRename:E}=t,L=ms(Ee=>Ee.toggleFolderCollapse),U=ms(Ee=>Ee.renameFolder),X=ms(Ee=>Ee.deleteFolder),Q=ms(Ee=>Ee.addSessionToFolder),me=Ae(Ee=>Ee.showDeletionDialog),[re,G]=c.useState(null),ee=c.useCallback((Ee,Ue)=>{const et=C.get(Ee.session.id),lt=C.get(Ue.session.id);if(et!==void 0||lt!==void 0){if(et===void 0)return 1;if(lt===void 0)return-1;if(et!==lt)return et-lt}return $d(Ee.session,Ue.session,N,Td)},[N,C]),ue=l?d.get(n):null,W=l?!1:h.has(r),ne=c.useMemo(()=>{if(n.isMain||n.isArchivedBucket||o)return null;const Ee=dt(n.directory??null),Ue=n.branch?.trim();return Ee&&Ue?ni(Ee,Ue):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,o]),Y=Bd(ne),F=Y?`var(--pr-${Y.visualState})`:void 0,J=Oa(),ie=c.useMemo(()=>{const Ee=n.folderScopes?.map(Ue=>dt(Ue.directory))??[dt(n.directory??null)];return[...new Set(Ee.filter(Ue=>!!Ue))]},[n.directory,n.folderScopes]);c.useSyncExternalStore(c.useCallback(Ee=>ie.length>0?J.subscribeBootstrap(Ee):()=>{},[ie.length,J]),c.useCallback(()=>ie.map(Ee=>`${Ee}\0${J.getBootstrapState(Ee)??""}\0${J.getBootstrapFailure(Ee)??""}`).join(""),[ie,J]),c.useCallback(()=>"",[]));const xe=ie.some(Ee=>{const Ue=J.getBootstrapState(Ee);return Ue==="queued"||Ue==="running"}),ge=ie.find(Ee=>J.getBootstrapState(Ee)==="failed")??null,Ce=ge?J.getBootstrapFailure(ge):void 0,Re=Ce==="os-permission"&&Wm(),[ce,ye]=c.useState(!1),be=c.useCallback(()=>{ge&&J.requestBootstrap({directory:ge,priority:W?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[J,ge,n.isMain,W]),te=c.useCallback(async()=>{if(!(!ge||!Re||ce)){ye(!0);try{(await zm(ge)).success&&be()}finally{ye(!1)}}},[Re,ge,ce,be]),pe=m??(y?10:5),Pe=Math.max(pe,u??pe),de=l?ue?.groupMatches===!0:!1,he=l,fe=c.useMemo(()=>[...he?ue?.filteredNodes??[]:n.sessions].sort(ee),[ee,n.sessions,ue?.filteredNodes,he]),B=n.folderScopeKey??dt(n.directory??null),H=c.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:B?[{scopeKey:B,directory:n.directory??null}]:[],[B,n.directory,n.folderScopes]),ke=ms(tr(c.useCallback(Ee=>H.map(({scopeKey:Ue})=>Ee.foldersMap[Ue]??Ac),[H]))),Se=c.useMemo(()=>H.flatMap(({scopeKey:Ee,directory:Ue},et)=>(ke[et]??Ac).map(ut=>({folder:ut,scopeKey:Ee,scopeDirectory:Ue}))),[ke,H]),Be=ms(tr(c.useCallback(Ee=>new Set(ke.flatMap(Ue=>Ue.filter(et=>Ee.collapsedFolderIds.has(et.id)).map(et=>et.id))),[ke]))),_e=c.useMemo(()=>{const Ee=new Map,Ue=et=>{et.forEach(lt=>{Ee.set(lt.session.id,lt),lt.children.length>0&&Ue(lt.children)})};return Ue(fe),Ee},[fe]),Te=c.useMemo(()=>Se.map(({folder:Ee,scopeKey:Ue,scopeDirectory:et})=>{const lt=L0(Ee.sessionIds,_e).sort(ee);return{folder:Ee,scopeKey:Ue,scopeDirectory:et,nodes:lt}}),[Se,_e,ee]),Z=c.useMemo(()=>{const Ee=W0(Te.map(({folder:Ue,nodes:et})=>({id:Ue.id,name:Ue.name,parentId:Ue.parentId,nodeCount:et.length})),{archivedBucket:n.isArchivedBucket===!0,searchQuery:l?a:""});return Te.filter(({folder:Ue})=>Ee.has(Ue.id))},[Te,n.isArchivedBucket,l,a]),Ne=I,Me=V,$=z,ae=c.useMemo(()=>new Set(Z.flatMap(Ee=>Ee.folder.sessionIds)),[Z]),se=c.useMemo(()=>fe.filter(Ee=>!ae.has(Ee.session.id)),[fe,ae]),we=c.useMemo(()=>{const Ee=new Map(Z.map(Ue=>[Ue.folder.id,Ue]));return $0(Z.map(Ue=>Ue.folder)).map(Ue=>Ee.get(Ue.id)).filter(Ue=>!!Ue)},[Z]),Ke=c.useMemo(()=>{const Ee=new Map;return Z.forEach(Ue=>{if(!Ue.folder.parentId)return;const et=Ee.get(Ue.folder.parentId)??[];et.push(Ue),Ee.set(Ue.folder.parentId,et)}),Ee},[Z]),Qe=c.useMemo(()=>{const Ee=new Map(Z.map(lt=>[lt.folder.id,lt])),Ue=new Map,et=(lt,ut)=>{const kt=Ue.get(lt);if(kt!==void 0)return kt;if(ut.has(lt))return[];ut.add(lt);const st=Ee.get(lt),_t=st?[...st.nodes]:[];for(const es of Ke.get(lt)??[])_t.push(...et(es.folder.id,ut));return Ue.set(lt,_t),_t};return Z.forEach(({folder:lt})=>et(lt.id,new Set)),Ue},[Z,Ke]),He="project",le=c.useMemo(()=>{const Ee=new Set;return ia(fe,Ne,Ee),Z.forEach(({nodes:Ue})=>{ia(Ue,Ne,Ee)}),Ee},[fe,Z,Ne]),K=c.useMemo(()=>{if(!Me)return null;const Ee=Jr(fe,Me,He,!!n.isArchivedBucket);if(Ee)return Ee;for(const{nodes:Ue}of Z){const et=Jr(Ue,Me,He,!!n.isArchivedBucket);if(et)return et}return null},[Me,fe,Z,n.isArchivedBucket]),ve=c.useCallback(Ee=>{const Ue=new WeakMap,et=lt=>{Ue.set(lt,qo(lt));for(const ut of lt.children)et(ut)};return Ee.forEach(et),Ue},[]),$e=c.useMemo(()=>ve(fe),[ve,fe]),We=c.useMemo(()=>{const Ee=new WeakMap;return Z.forEach(({nodes:Ue})=>{Ue.forEach(et=>Ee.set(et,qo(et)))}),Ee},[Z]),Le=c.useCallback(Ee=>$e.get(Ee)??We.get(Ee)??"",[$e,We]),Fe=c.useCallback(Ee=>({subtreeContainsEditing:le,menuOpenSessionId:K,nodeStructureKey:Le(Ee)}),[le,K,Le]),Ge=se.length,rt=n.isArchivedBucket||l?se:se.slice(0,Pe),St=Ge-rt.length,Rt=!n.isArchivedBucket&&!l&&Ge>pe&&St===0,ze=n.isArchivedBucket===!0&&!l&&rt.length>=Uj,Pt=n.isArchivedBucket?"archived":"active",Nt=ze&&rt.some(Ee=>{if(Ee.children.length===0)return!1;const Ue=`project:${Pt}:${Ee.session.id}`;return $.has(Ue)}),Tt=c.useRef(null),[Et,vt]=c.useState(null),[Ct,It]=c.useState(0),[,mt]=c.useState(0);c.useEffect(()=>{if(!ze)return;const Ee=Tt.current;if(!Ee||!globalThis.ResizeObserver)return;const Ue=new ResizeObserver(()=>mt(et=>et+1));return Ue.observe(Ee),()=>Ue.disconnect()},[ze]),c.useLayoutEffect(()=>{if(!ze){Et!==null&&vt(null),Ct!==0&&It(0);return}const Ee=Tt.current;if(!Ee)return;let Ue=Et;const et=M?.current??null;if(et&&et.contains(Ee)){if(Ue=et,Ue!==Et){vt(Ue);return}}else if(!Ue||!Ue.contains(Ee)){let ut=Ee.parentElement;for(;ut;){const kt=window.getComputedStyle(ut);if(kt.overflowY==="auto"||kt.overflowY==="scroll"){Ue=ut;break}ut=ut.parentElement}if(Ue!==Et){vt(Ue);return}}if(!Ue)return;const lt=Ee.getBoundingClientRect().top-Ue.getBoundingClientRect().top+Ue.scrollTop;It(ut=>Math.abs(ut-lt)<1?ut:lt)});const Ze=ze&&Et!==null,je=wg({count:rt.length,enabled:Ze,getScrollElement:()=>Et,initialOffset:()=>Et?.scrollTop??0,estimateSize:()=>Hj,overscan:Nt?20:8,scrollMargin:Ct,getItemKey:Ee=>rt[Ee]?.session.id??Ee}),ot=c.useCallback(Ee=>{const Ue=[],et=lt=>{lt.forEach(ut=>{Ue.push(ut.session),ut.children.length>0&&et(ut.children)})};return et(Ee),Ue},[]),ct=c.useMemo(()=>ot(fe),[ot,fe]),Mt=c.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Ee=new Map,Ue=new Map;for(const{folder:lt}of Z){if(!lt.parentId)continue;const ut=Ue.get(lt.parentId)??[];ut.push(lt.id),Ue.set(lt.parentId,ut)}const et=(lt,ut)=>{if(ut.has(lt))return[];ut.add(lt);const kt=Z.find(({folder:es})=>es.id===lt),st=kt?ot(kt.nodes):[],_t=Ue.get(lt)??[];for(const es of _t)st.push(...et(es,ut));return st};for(const{folder:lt}of Z)Ee.set(lt.id,et(lt.id,new Set));return Ee},[Z,ot,n.isArchivedBucket]);if(l&&!de&&we.length===0&&se.length===0)return null;const Je=!n.isMain&&!!n.branch,nt=n.branch&&xh(n.branch,n.label)?{label:n.branch}:null,jt=W?s.jsx(w0,{nodes:fe,includeUnreadSubtasks:k}):null,At=(Ee,Ue)=>{const{folder:et,scopeKey:lt,scopeDirectory:ut,nodes:kt}=Ee,st=Mt.get(et.id)??[],_t=O?.folderId===et.id&&O?.scopeKey===lt,es=l?!1:Be.has(et.id),Ds=Os=>s.jsx(M0,{folderId:et.id,children:(bs,xs)=>s.jsx(v0,{folder:et,displayName:Ue,sessions:kt,isCollapsed:es,collapsedActivityState:Os,onToggle:()=>L(et.id),onRename:os=>{U(lt,et.id,os)},onDelete:()=>{if(n.isArchivedBucket){yn.requestDelete({sessions:st,mode:"session"});return}if(!me){X(lt,et.id);return}const os=Z.filter(({folder:fs})=>fs.parentId===et.id).length,Ps=kt.length;G({scopeKey:lt,folderId:et.id,folderName:et.name,subFolderCount:os,sessionCount:Ps})},groupDirectory:ut??n.directory,projectId:i,mobileVariant:v,alwaysShowActions:g,isRenaming:_t,renameDraft:_t?O?.draft:void 0,onRenameDraftChange:j,onRenameSave:()=>{const os=O?.draft.trim()??"";os&&U(lt,et.id,os),E()},onRenameCancel:E,droppableRef:bs,isDropTarget:xs,depth:0,onNewSession:()=>{i&&i!==f&&x(i),v&&p(!1),w({selectedProjectId:i,directoryOverride:ut??n.directory,targetFolderId:et.id,target:n.draftTarget})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0,children:kt.map(os=>s.jsx(Qo,{node:os,pinnedSessionIds:N,expandedParents:z,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:I,editTitle:T,copiedSessionId:_,openSidebarMenuKey:V,mobileVariant:v,alwaysShowActions:g,groupDirectory:ut??n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:le,menuOpenSessionId:K,nodeStructureKey:Le(os),childRenderExtrasFor:Fe},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},os.session.id))})},et.id);return es?s.jsx(Kj,{nodes:Qe.get(et.id)??kt,includeUnreadSubtasks:k,children:Ds},et.id):Ds(null)},Ot=()=>{const Ee=new Map;for(const ut of Z){const kt=ut.folder.parentId;if(!kt)continue;const st=Ee.get(kt);st?st.push(ut):Ee.set(kt,[ut])}const Ue=[],et=new Set,lt=(ut,kt)=>{if(et.has(ut.folder.id))return;et.add(ut.folder.id);const st=kt?`${kt} / ${ut.folder.name}`:ut.folder.name;Ue.push(At(ut,st)),!(!l&&Be.has(ut.folder.id))&&(Ee.get(ut.folder.id)??[]).forEach(es=>lt(es,st))};return we.forEach(ut=>lt(ut,"")),Ue},$t=!!(!n.isMain&&n.worktree),Zt=g?$t?"pr-14":"pr-7":$t?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",Gt=ge?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(Ce==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),Re?s.jsx(at,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:ce,onClick:()=>{te()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(at,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:be,children:e("sessions.sidebar.group.empty.retry")})]}):null,Ft=Ee=>s.jsx(Qo,{node:Ee,pinnedSessionIds:N,expandedParents:z,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,notifyOnSubtasks:k,editingId:I,editTitle:T,copiedSessionId:_,openSidebarMenuKey:V,mobileVariant:v,alwaysShowActions:g,groupDirectory:n.directory,projectId:i,archivedBucket:n.isArchivedBucket===!0,renderExtras:{subtreeContainsEditing:le,menuOpenSessionId:K,nodeStructureKey:Le(Ee),childRenderExtrasFor:Fe},setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},Ee.session.id),qt=s.jsxs(O0,{scopeKey:H[0]?.scopeKey??B,hasFolders:Z.length>0,onSessionDroppedOnFolder:(Ee,Ue)=>{const et=Z.find(({folder:ut})=>ut.id===Ue);if(!et)return;const lt=ms.getState();for(const{scopeKey:ut}of H)ut!==et.scopeKey&<.getSessionFolderId(ut,Ee)&<.removeSessionFromFolder(ut,Ee);Q(et.scopeKey,Ue,Ee)},children:[Ot(),ze?s.jsx("div",{ref:Tt,children:Ze?s.jsx("div",{style:{height:je.getTotalSize(),position:"relative"},children:je.getVirtualItems().map(Ee=>{const Ue=rt[Ee.index];return Ue?s.jsx("div",{"data-index":Ee.index,ref:je.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Ee.start-Ct}px)`},children:Ft(Ue)},Ue.session.id):null})}):rt.map(Ft)}):rt.map(Ft),Ge===0&&Z.length===0?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):xe?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Gt||(n.emptyMessage??e("sessions.sidebar.group.empty.noSessionsInWorkspace"))}):null,Ge>0&&Gt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Gt}):null,St>0?s.jsx("button",{type:"button",onClick:()=>b(r,rt.length,m??7),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,Rt?s.jsx("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Xt="pb-2",zt=s.jsx(_j,{value:re,setValue:G,onConfirm:()=>{const Ee=re;Ee&&(X(Ee.scopeKey,Ee.folderId),G(null))}});return o?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Ie("oc-group-body",Xt),children:qt})}),zt]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Ie("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>A(r),role:"button",tabIndex:0,onKeyDown:Ee=>{(Ee.key==="Enter"||Ee.key===" ")&&(Ee.preventDefault(),A(r))},"aria-label":W?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!W,children:[s.jsx("div",{ref:D?.setActivatorNodeRef,className:Ie("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",Zt),...D?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(R,{name:"archive",className:Ie("h-3.5 w-3.5 shrink-0 text-muted-foreground",g?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",g?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Co(n.label,a)}),jt]}):!n.isMain||n.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(R,{name:"git-branch",className:Ie("h-3.5 w-3.5 shrink-0",!F&&"text-muted-foreground",g?"hidden":"group-hover/gh:hidden"),style:F?{color:F}:void 0}),s.jsx("span",{className:Ie("text-muted-foreground h-3.5 w-3.5 items-center justify-center",g?"inline-flex":"hidden group-hover/gh:inline-flex"),children:W?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-semibold text-muted-foreground",children:Co(n.label,a)}),jt,Y?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:F?{color:F}:void 0,children:["#",Y.number]}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:Co(n.label,a)}),jt]})}),Je&&nt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(R,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(R,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:nt.label})]}):null]})}),n.isArchivedBucket&&ct.length>0?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",g?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(yt,{delayDuration:500,children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ee=>{Ee.stopPropagation(),yn.requestDelete({sessions:ct,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Ie("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",g?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(yt,{delayDuration:500,children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ee=>{Ee.stopPropagation(),yn.requestDelete({sessions:ct,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Ie("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",g?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(yt,{delayDuration:500,children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ee=>{Ee.stopPropagation(),i&&i!==f&&x(i),v&&p(!1),w({selectedProjectId:i,directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(R,{name:"add",className:"h-4 w-4"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),W?null:s.jsx("div",{className:Ie("oc-group-body",Xt),children:qt})]}),zt]})}const Ro=c.memo(Xj,Yj),Jj=(t,e,n)=>e?t.filter(r=>r.project.id===n):t,Zj=t=>t?"top-content":"empty-state",e2=(t,e)=>{const n=t.groups.find(o=>o.isMain&&o.sessions.length>0)??t.groups.find(o=>o.sessions.length>0)??t.groups.find(o=>o.isMain)??t.groups[0];if(!n)return[];const r=t.groups.find(o=>o.isArchivedBucket&&o.id!==n.id);return[n,...r?[r]:[]].map(o=>({group:o,groupKey:`${t.project.id}:${o.id}`,projectId:t.project.id,hideGroupLabel:o.id===n.id}))},t2=48,s2=32,n2=24,Ci=(t,e)=>Ma(t.label?.trim()||Wn(t.normalizedPath,e)||t.normalizedPath);function r2(t){const e=Ye.c(42);fn("ui.sidebar_projects_list.render");const{t:n}=ht(),{model:r,view:i,actions:o}=t,l=r.state.editingId!==null,a=i.isDesktopShellRuntime&&i.stickyZoneHeaders&&!r.singleProjectMode;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={activationConstraint:{distance:8}},e[0]=d):d=e[0];let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={coordinateGetter:cg},e[1]=u):u=e[1];const m=Hr(_n(Wi,d),_n(ag,u));let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h={activationConstraint:{distance:8}},e[2]=h):h=e[2];const y=Hr(_n(Wi,h)),b=c.useRef(null),S=c.useRef(0);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=ue=>{const ne=ue.scrollTop>1?Math.min(s2+ue.scrollTop,t2):0;S.current=ne;const Y=ue.closest(".oc-sticky-fade-root");Y?.style.setProperty("--scroll-shadow-top-size",`${ne}px`),Y?.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(ne-8,0),n2)}px`)},e[3]=v):v=e[3];const g=v;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=ue=>{ue.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||ue.clientY-ue.currentTarget.getBoundingClientRect().top>=S.current||(ue.preventDefault(),ue.stopPropagation())},e[4]=f):f=e[4];const x=f,p=Jj(r.sectionsForRender,r.singleProjectMode,r.singleProjectId),w=r.projectSections.length>0&&p.length>0;let N,C;e[5]!==a||e[6]!==w?(N=()=>{a&&w&&b.current&&g(b.current)},C=[a,w,g],e[5]=a,e[6]=w,e[7]=N,e[8]=C):(N=e[7],C=e[8]),c.useLayoutEffect(N,C);let k=null;for(const ue of r.projectSections)r.stuckProjectHeaders.has(ue.project.id)&&(k=ue.project);const A=k??(r.hasSharedSessions?null:p[0]?.project??null),D=A?Ci(A,i.homeDirectory):null;let P;if(e[9]!==r.projectSections||e[10]!==i.homeDirectory){let ue;e[12]!==i.homeDirectory?(ue=W=>({id:W.project.id,projectLabel:Ci(W.project,i.homeDirectory),projectDescription:Ur(W.project.normalizedPath,i.homeDirectory),projectIcon:W.project.icon,projectColor:W.project.color,projectIconImage:W.project.iconImage,projectIconBackground:W.project.iconBackground}),e[12]=i.homeDirectory,e[13]=ue):ue=e[13],P=r.projectSections.map(ue),e[9]=r.projectSections,e[10]=i.homeDirectory,e[11]=P}else P=e[11];const M=P;if(r.projectSections.length===0){let ue;return e[14]!==r.emptyState||e[15]!==r.topContent?(ue=s.jsxs(An,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:[r.topContent,r.emptyState]}),e[14]=r.emptyState,e[15]=r.topContent,e[16]=ue):ue=e[16],ue}if(r.sectionsForRender.length===0){const W=Zj(r.topContentHasSearchMatches===!0)==="top-content"?r.topContent:r.searchEmptyState;let ne;return e[17]!==W?(ne=s.jsx(An,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:"space-y-1 pb-1 pl-2.5 pr-2",children:W}),e[17]=W,e[18]=ne):ne=e[18],ne}const z="oc-sticky-fade-root relative flex min-h-0 flex-1";let I;e[19]!==a?(I=a?{"--scroll-shadow-top-size":"0px"}:void 0,e[19]=a,e[20]=I):I=e[20];const V=a?x:void 0,T=a?x:void 0,_=a?x:void 0,O=An,j=!0,E=!a,L=96,U="flex-1 min-h-0",X="oc-sidebar-scroller oc-sticky-fade-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]";let Q;e[21]!==a?(Q=a?ue=>g(ue.currentTarget):void 0,e[21]=a,e[22]=Q):Q=e[22];const me=i.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const ue=p.find(ne=>ne.project.id===r.activeProjectId)??p[0];if(!ue)return i.hasSessionSearchQuery?r.searchEmptyState:r.emptyState;const W=e2(ue);return W.length?W.map(ne=>{const{group:Y,groupKey:F,projectId:J,hideGroupLabel:ie}=ne;return s.jsx(c.Fragment,{children:s.jsx(Ro,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:Y,groupKey:F,projectId:J,hideGroupLabel:ie,visibleSessionCount:r.state.visibleSessionCountByGroup.get(F),compactBodyPadding:!0,scrollContainerRef:b})},F)}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})()}):s.jsxs(Kr,{sensors:m,collisionDetection:Gr,onDragEnd:ue=>{if(l||i.projectSortOrder!=="manual")return;const{active:W,over:ne}=ue;if(!ne||W.id===ne.id)return;const Y=r.sectionsForRender.findIndex(J=>J.project.id===W.id),F=r.sectionsForRender.findIndex(J=>J.project.id===ne.id);Y===-1||F===-1||Y===F||o.reorderProjects(Y,F)},children:[s.jsx(Wo,{items:p.map(l2),strategy:Vi,children:p.map(ue=>{const W=ue.project,ne=W.id,Y=Ci(W,i.homeDirectory),F=Ur(W.normalizedPath,i.homeDirectory),J=r.singleProjectMode?!1:i.collapsedProjects.has(ne),ie=r.projectRepoStatus.get(ne);return s.jsx(m0,{id:ne,disabled:r.singleProjectMode||i.projectSortOrder!=="manual",projectLabel:Y,projectDescription:F,projectIcon:W.icon,projectColor:W.color,projectIconImage:W.iconImage,projectIconBackground:W.iconBackground,isCollapsed:J,isRepo:!!ie,isDesktopShell:i.isDesktopShellRuntime,hideDirectoryControls:i.hideDirectoryControls,mobileVariant:i.mobileVariant,alwaysShowActions:i.alwaysShowActions,statusIndicator:J?o.renderProjectStatusIndicator?.(ne,ue.groups):null,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,projectPickerOptions:r.singleProjectMode?M:void 0,onProjectSelect:r.singleProjectMode?o.setSingleProjectId:void 0,onToggle:()=>{r.singleProjectMode||o.toggleProject(ne)},onNewSession:()=>{ne!==r.activeProjectId&&o.setActiveProjectIdOnly(ne),i.mobileVariant&&o.setSessionSwitcherOpen(!1),o.openNewSessionDraft({selectedProjectId:ne,directoryOverride:W.normalizedPath})},onNewWorktreeSession:()=>{ne!==r.activeProjectId&&o.setActiveProjectIdOnly(ne),o.openNewWorktreeDialog()},onManageWorktrees:()=>o.openWorktreesPage(ne),onRenameStart:()=>o.openProjectEditDialog(ne),onClose:()=>o.removeProject(ne),sentinelRef:xe=>{r.projectHeaderSentinelRefs.current.set(ne,xe)},showCreateButtons:!0,children:J?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const xe=ue.groups,ge=xe.find(a2)??null,Ce=ge?xe.filter(Re=>Re.id!==ge.id):xe;return s.jsxs(Kr,{sensors:y,collisionDetection:Gr,onDragEnd:Re=>{if(l)return;const{active:ce,over:ye}=Re;if(!ye||ce.id===ye.id)return;const be=Ce.findIndex(de=>de.id===ce.id),te=Ce.findIndex(de=>de.id===ye.id);if(be===-1||te===-1||be===te)return;const pe=ru(Ce,be,te).map(i2),Pe=ge?[ge.id,...pe]:pe;o.setGroupOrderByProject(de=>{const he=new Map(de);return he.set(ne,Pe),he})},children:[ge?s.jsx(Ro,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:ge,groupKey:`${ne}:${ge.id}`,projectId:ne,hideGroupLabel:!0,visibleSessionCount:r.state.visibleSessionCountByGroup.get(`${ne}:${ge.id}`),scrollContainerRef:b}):null,s.jsx(Wo,{items:Ce.map(o2),strategy:Vi,children:Ce.map(Re=>{const ce=`${ne}:${Re.id}`;return s.jsx(h0,{id:Re.id,disabled:l,children:ye=>s.jsx(Ro,{...r.groupProps,...o.group,editingId:r.state.editingId,openSidebarMenuKey:r.state.openSidebarMenuKey,setOpenSidebarMenuKey:r.state.setOpenSidebarMenuKey,group:Re,groupKey:ce,projectId:ne,visibleSessionCount:r.state.visibleSessionCountByGroup.get(ce),dragHandleProps:ye,scrollContainerRef:b})},Re.id)})}),s.jsx(zi,{dropAnimation:null})]})})()})},ne)})}),s.jsx(zi,{dropAnimation:null})]});let re;e[23]!==O||e[24]!==r.topContent||e[25]!==E||e[26]!==Q||e[27]!==me?(re=s.jsxs(O,{ref:b,useScrollShadow:j,hideTopScrollShadow:E,scrollShadowSize:L,outerClassName:U,className:X,onScroll:Q,children:[r.topContent,me]}),e[23]=O,e[24]=r.topContent,e[25]=E,e[26]=Q,e[27]=me,e[28]=re):re=e[28];let G;e[29]!==a||e[30]!==A||e[31]!==D||e[32]!==r.hasSharedSessions||e[33]!==n?(G=a&&(A||r.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:A&&D?s.jsx(Io,{id:A.id,projectLabel:D,projectIcon:A.icon,projectColor:A.color,projectIconImage:A.iconImage,projectIconBackground:A.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:n("sessions.sidebar.activity.recentTitle")})]})}):null,e[29]=a,e[30]=A,e[31]=D,e[32]=r.hasSharedSessions,e[33]=n,e[34]=G):G=e[34];let ee;return e[35]!==V||e[36]!==T||e[37]!==_||e[38]!==re||e[39]!==G||e[40]!==I?(ee=s.jsxs("div",{className:z,style:I,onPointerDownCapture:V,onClickCapture:T,onContextMenuCapture:_,children:[re,G]}),e[35]=V,e[36]=T,e[37]=_,e[38]=re,e[39]=G,e[40]=I,e[41]=ee):ee=e[41],ee}function o2(t){return t.id}function i2(t){return t.id}function a2(t){return t.isMain}function l2(t){return t.project.id}const c2=c.memo(r2),ma=new Map,Dc=(t,e)=>{for(const n of t){const r=dt(n??null);r&&!ma.has(r)&&ma.set(r,e)}},Pc=t=>{const e=dt(t??null);return e?ma.get(e)??0:0},wo=t=>!!t.time?.archived,d2=t=>{const{t:e}=ht(),n=c.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=c.useCallback(l=>{const a=dt(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${a}`.toLowerCase()},[e]),i=c.useCallback((l,a)=>a?l.flatMap(d=>{if(_o([r(d.session)],a))return[d];const m=i(d.children,a);return m.length===0?[]:[{...d,children:m}]}):l,[r]),o=c.useCallback((l,a,d,u,m)=>{const h=dt(a??null),y=Rd(l),b=new Map(y.map(T=>[T.id,T])),S=new Map;y.forEach(T=>{const _=T.parentID;if(!_)return;const O=b.get(_);if(!O||wo(O)!==wo(T))return;const j=S.get(_)??[];j.push(T),S.set(_,j)});const v=new Map;d.forEach(T=>{if(T.path){const _=dt(T.path)??T.path;v.set(_,T)}});const g=T=>{const _=dt(T.directory??null),O=t.worktreeMetadata.get(T.id)??null;if(O)return O;if(_){const j=v.get(_)??null;if(j&&_!==h)return j}return null},f=new Set,x=T=>{f.add(T.id);const _=S.get(T.id)??[],O=[];for(const j of _)f.has(j.id)||O.push(x(j));return{session:T,children:O,worktree:g(T)}},p=y.filter(T=>{const _=T.parentID;if(!_)return!0;const O=b.get(_);return O?wo(O)!==wo(T):!0}),w=[],N=T=>{f.has(T.id)||w.push(x(T))};p.forEach(N),y.forEach(N);const C=new Map,k="__archived__",A=T=>{if(T.time?.archived)return k;if(t.isVSCode)return h??"__project_root__";const O=dt(t.worktreeMetadata.get(T.id)?.path??null)??Us(T);return O?O!==h&&v.has(O)?O:O===h?h??"__project_root__":k:k};w.forEach(T=>{const _=A(T.session);C.has(_)||C.set(_,[]),C.get(_)?.push(T)});const D=h??"__project_root__",P=[{id:"root",label:m&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:h?Ur(h,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:h,folderScopeKey:h,sessions:C.get(D)??[]}],M=new Map;d.forEach(T=>{const _=dt(T.path)??T.path,O=C.get(_)??[],j=O.length>0,E=O.reduce((L,U)=>{const X=yh(U.session,t.sessionOrderRanks);return Number.isFinite(X)?Math.max(L,X):L},0);M.set(_,{hasActiveSession:j,lastUpdatedAt:E})});const z=[...d].sort((T,_)=>{const O=dt(T.path)??T.path,j=dt(_.path)??_.path,E=M.get(O)??{hasActiveSession:!1,lastUpdatedAt:0},L=M.get(j)??{hasActiveSession:!1,lastUpdatedAt:0};if(E.hasActiveSession!==L.hasActiveSession)return E.hasActiveSession?-1:1;if(E.hasActiveSession&&L.hasActiveSession)return L.lastUpdatedAt-E.lastUpdatedAt;const U=Pc(T.path),X=Pc(_.path);if(U!==X)return X-U;const Q=(T.label||T.branch||T.name||T.path||"").toLowerCase(),me=(_.label||_.branch||_.name||_.path||"").toLowerCase();return Q.localeCompare(me)});(t.isVSCode?[]:z).forEach(T=>{const _=dt(T.path)??T.path,O=t.gitBranches.get(_)?.trim()||null,j=T.branch?.trim()||null,L=!!(O&&j&&T.label&&ul(T.label)===ul(j))?O:T.label||T.name||Wn(_,t.homeDirectory)||_;P.push({id:`worktree:${_}`,label:L,branch:O||j,description:Ur(_,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:T,directory:_,folderScopeKey:_,sessions:C.get(_)??[]})});const V=C.get(k)??[];return V.length>0&&P.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&h?Ed(h):null,sessions:V}),P},[t.homeDirectory,t.worktreeMetadata,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:i,buildGroupedSessions:o}},u2=t=>{const e=Ye.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:i,projectHeaderSentinelRefs:o}=t,l=n===void 0?!0:n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[d,u]=c.useState(a);let m;e[1]!==l||e[2]!==r||e[3]!==o?(m=()=>{if(!l||!r){u(m2);return}const b=Array.from(o.current.values()).find(f2)?.closest(".oc-sidebar-scroller")??null;if(!b)return;const S=new IntersectionObserver(v=>{u(g=>{const f=new Set(g);let x=!1;for(const p of v){const w=p.target.dataset.projectId;if(!w)continue;const N=p.rootBounds?.top??b.getBoundingClientRect().top,C=!p.isIntersecting&&p.boundingClientRect.top<N;f.has(w)!==C&&(x=!0,C?f.add(w):f.delete(w))}return x?f:g})},{root:b,threshold:0});return o.current.forEach(v=>{v&&S.observe(v)}),()=>S.disconnect()},e[1]=l,e[2]=r,e[3]=o,e[4]=m):m=e[4];let h;return e[5]!==l||e[6]!==r||e[7]!==o||e[8]!==i?(h=[l,r,o,i],e[5]=l,e[6]=r,e[7]=o,e[8]=i,e[9]=h):h=e[9],c.useEffect(m,h),d};function m2(t){return t.size===0?t:new Set}function f2(t){return t!==null}const h2=t=>{const e=Ye.c(51),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:o,onMoveToFolder:l,onCreateFolderAndMove:a,onRemoveFromFolder:d,canRemoveFromFolder:u,onRestore:m,onDelete:h,onDone:y}=t,{t:b}=ht(),S=!!r&&!o;let v;e[0]!==o||e[1]!==b?(v=b(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=o,e[1]=b,e[2]=v):v=e[2];const g=v;let f;e[3]!==n||e[4]!==b?(f=b("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=b,e[5]=f):f=e[5];let x;e[6]!==f?(x=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:f}),e[6]=f,e[7]=x):x=e[7];let p;e[8]!==S||e[9]!==u||e[10]!==a||e[11]!==l||e[12]!==d||e[13]!==i||e[14]!==b?(p=S?s.jsxs(en,{children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(Js,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":b("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(R,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:b("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Zs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx(Ut,{disabled:!0,className:"text-muted-foreground",children:b("sessions.sidebar.folders.none")}):i.map(j=>s.jsx(Ut,{onClick:()=>l(j.id),children:s.jsx("span",{className:"flex-1 truncate",children:j.name})},j.id)),s.jsx(Ls,{}),s.jsxs(Ut,{onClick:a,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"}),b("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(Ut,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"close",className:"mr-1 h-4 w-4"}),b("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=S,e[9]=u,e[10]=a,e[11]=l,e[12]=d,e[13]=i,e[14]=b,e[15]=p):p=e[15];let w;e[16]!==o||e[17]!==m||e[18]!==b?(w=o?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,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":b("sessions.sidebar.bulkActions.restore"),children:s.jsx(R,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:b("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=o,e[17]=m,e[18]=b,e[19]=w):w=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=Ie("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[20]=N):N=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(R,{name:"delete-bin",className:"h-4 w-4"}),e[21]=C):C=e[21];let k;e[22]!==g||e[23]!==h?(k=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:N,"aria-label":g,children:C})}),e[22]=g,e[23]=h,e[24]=k):k=e[24];let A;e[25]!==g?(A=s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:g})}),e[25]=g,e[26]=A):A=e[26];let D;e[27]!==k||e[28]!==A?(D=s.jsxs(yt,{children:[k,A]}),e[27]=k,e[28]=A,e[29]=D):D=e[29];let P;e[30]!==b?(P=b("sessions.sidebar.header.actions.exitSelection"),e[30]=b,e[31]=P):P=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(R,{name:"close",className:"h-4 w-4"}),e[32]=M):M=e[32];let z;e[33]!==y||e[34]!==P?(z=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:y,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":P,children:M})}),e[33]=y,e[34]=P,e[35]=z):z=e[35];let I;e[36]!==b?(I=b("sessions.sidebar.header.actions.exitSelection"),e[36]=b,e[37]=I):I=e[37];let V;e[38]!==I?(V=s.jsx(xt,{side:"top",sideOffset:4,children:s.jsx("p",{children:I})}),e[38]=I,e[39]=V):V=e[39];let T;e[40]!==z||e[41]!==V?(T=s.jsxs(yt,{children:[z,V]}),e[40]=z,e[41]=V,e[42]=T):T=e[42];let _;e[43]!==D||e[44]!==T||e[45]!==p||e[46]!==w?(_=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[p,w,D,T]}),e[43]=D,e[44]=T,e[45]=p,e[46]=w,e[47]=_):_=e[47];let O;return e[48]!==_||e[49]!==x?(O=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[x,_]}),e[48]=_,e[49]=x,e[50]=O):O=e[50],O},p2=(t,e)=>{if(!t)return[];const n=e(t);return n.length>0?n.map(r=>r.scopeKey):[t]},g2=t=>{const{t:e}=ht(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:i,getFolderScopesForProject:o,addSessionsToFolder:l,removeSessionsFromFolders:a,createFolderAndStartRename:d,archiveSessions:u,unarchiveSessions:m,deleteSessions:h,setBulkDeleteConfirm:y}=t,b=gs(j=>j.enabled),S=gs(j=>j.selectedIds.size),v=S>0,g=gs(j=>j.selectedIds),f=gs(j=>j.scopeKey),x=c.useCallback(()=>{gs.getState().toggleMode()},[]),p=c.useCallback(()=>{gs.getState().disable()},[]),w=c.useMemo(()=>{if(!v||typeof document>"u")return!1;let j=!1,E=!1;for(const L of g){const U=document.querySelectorAll(`[data-session-row="${CSS.escape(L)}"]`);for(const X of U)X.getAttribute("data-session-archived")==="1"?E=!0:j=!0}return E&&!j},[v,g]),N=c.useMemo(()=>{if(f)return f;if(!v||typeof document>"u")return null;for(const j of g){const L=document.querySelector(`[data-session-row="${CSS.escape(j)}"]`)?.getAttribute("data-session-scope");if(L&&L.length>0)return L}return null},[v,g,f]),C=c.useMemo(()=>p2(N,o),[N,o]),k=c.useMemo(()=>C.flatMap(j=>i[j]??[]),[i,C]),A=c.useCallback(j=>{for(const E of C)if((i[E]??[]).some(L=>L.id===j))return E;return null},[i,C]),D=c.useMemo(()=>{if(!v)return!1;for(const j of C)for(const E of i[j]??[])for(const L of E.sessionIds)if(g.has(L))return!0;return!1},[i,C,v,g]),P=c.useCallback((j,E)=>{const L=Array.from(g);for(const U of C)U!==j&&a(U,L);l(j,E,L)},[l,a,g,C]),M=c.useCallback(j=>{if(!v)return;const E=A(j);E&&P(E,j)},[v,P,A]),z=c.useCallback(()=>{const j=C[0];if(!j||!v)return;const E=d(j);E&&P(j,E.id)},[d,v,P,C]),I=c.useCallback(()=>{if(!v)return;const j=Array.from(g);for(const E of C)a(E,j)},[a,g,C,v]),V=c.useCallback(async()=>{const j=Array.from(g);if(j.length!==0){if(w){const{deletedIds:E,failedIds:L}=await h(j);E.length>0&&Oe.success(E.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:E.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:E.length})),L.length>0&&Oe.error(L.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:L.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:L.length}))}else{const{archivedIds:E,failedIds:L}=await u(j);E.length>0&&Oe.success(E.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:E.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:E.length})),L.length>0&&Oe.error(L.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:L.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:L.length}))}gs.getState().clear()}},[u,w,h,g,e]),T=c.useCallback(()=>{if(!v)return;const j=g.size;if(!r){V();return}y({sessionCount:j,archivedBucket:w})},[w,V,g,r,y,v]),_=c.useCallback(async()=>{if(!v||!w)return;const j=Array.from(g),{restoredIds:E,failedIds:L}=await m(j);E.length>0&&Oe.success(E.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:E.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:E.length})),L.length>0&&Oe.error(L.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:L.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:L.length})),gs.getState().clear()},[w,v,g,e,m]),O=c.useCallback(async()=>{y(null),await V()},[V]);return c.useEffect(()=>{if(!b)return;const j=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),E=L=>{if(n)return;const U=L.target;if(U&&(U.tagName==="INPUT"||U.tagName==="TEXTAREA"||U.isContentEditable))return;const X=j?L.metaKey:L.ctrlKey;if(L.key==="Escape"){L.preventDefault(),gs.getState().disable();return}if(X&&L.key==="Backspace"){L.preventDefault(),T();return}if(X&&(L.key==="a"||L.key==="A")){const Q=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Q.length===0)return;L.preventDefault();const re=gs.getState().scopeKey??Q[0]?.getAttribute("data-session-scope")??null,G=ue=>re?ue.getAttribute("data-session-scope")===re:!0,ee=Q.filter(G).map(ue=>ue.getAttribute("data-session-row")).filter(ue=>typeof ue=="string"&&ue.length>0);if(ee.length===0)return;gs.getState().replaceAll(ee,re||null)}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[T,n,b]),{selectionModeEnabled:b,hasSelection:v,selectedIdsSize:S,bulkScopeIsArchived:w,derivedSelectionScope:N,bulkScopeFolders:k,bulkCanRemoveFromFolder:D,handleToggleSelectionMode:x,handleExitSelectionMode:p,handleBulkMoveToFolder:M,handleBulkCreateFolderAndMove:z,handleBulkRemoveFromFolder:I,handleBulkDelete:T,handleBulkRestore:_,confirmBulkDelete:O}};function b2(t){const e=Ye.c(36),{getFolderScopesForProject:n,isInlineEditing:r,startFolderRename:i}=t,[o,l]=c.useState(null),a=Ae(N2),d=Ae(C2),u=ms(k2),m=ms(j2),h=ms(v2),y=ms(S2),b=qe(w2),S=qe(y2),v=qe(x2);let g;e[0]!==m||e[1]!==i?(g=C=>{const k=m(C,"New folder");return i(C,k),k},e[0]=m,e[1]=i,e[2]=g):g=e[2];let f;e[3]!==h||e[4]!==b||e[5]!==v||e[6]!==u||e[7]!==n||e[8]!==r||e[9]!==y||e[10]!==a||e[11]!==g||e[12]!==S?(f={isInlineEditing:r,showDeletionDialog:a,foldersMap:u,getFolderScopesForProject:n,addSessionsToFolder:h,removeSessionsFromFolders:y,createFolderAndStartRename:g,archiveSessions:b,unarchiveSessions:S,deleteSessions:v,setBulkDeleteConfirm:l},e[3]=h,e[4]=b,e[5]=v,e[6]=u,e[7]=n,e[8]=r,e[9]=y,e[10]=a,e[11]=g,e[12]=S,e[13]=f):f=e[13];const x=g2(f);let p;e[14]!==x.bulkCanRemoveFromFolder||e[15]!==x.bulkScopeFolders||e[16]!==x.bulkScopeIsArchived||e[17]!==x.derivedSelectionScope||e[18]!==x.handleBulkCreateFolderAndMove||e[19]!==x.handleBulkDelete||e[20]!==x.handleBulkMoveToFolder||e[21]!==x.handleBulkRemoveFromFolder||e[22]!==x.handleBulkRestore||e[23]!==x.handleExitSelectionMode||e[24]!==x.hasSelection||e[25]!==x.selectedIdsSize||e[26]!==x.selectionModeEnabled?(p=x.selectionModeEnabled&&x.hasSelection?s.jsx(h2,{selectedCount:x.selectedIdsSize,scopeKey:x.derivedSelectionScope,scopeFolders:x.bulkScopeFolders,archivedBucket:x.bulkScopeIsArchived,onMoveToFolder:x.handleBulkMoveToFolder,onCreateFolderAndMove:x.handleBulkCreateFolderAndMove,onRemoveFromFolder:x.handleBulkRemoveFromFolder,canRemoveFromFolder:x.bulkCanRemoveFromFolder,onRestore:x.handleBulkRestore,onDelete:x.handleBulkDelete,onDone:x.handleExitSelectionMode}):null,e[14]=x.bulkCanRemoveFromFolder,e[15]=x.bulkScopeFolders,e[16]=x.bulkScopeIsArchived,e[17]=x.derivedSelectionScope,e[18]=x.handleBulkCreateFolderAndMove,e[19]=x.handleBulkDelete,e[20]=x.handleBulkMoveToFolder,e[21]=x.handleBulkRemoveFromFolder,e[22]=x.handleBulkRestore,e[23]=x.handleExitSelectionMode,e[24]=x.hasSelection,e[25]=x.selectedIdsSize,e[26]=x.selectionModeEnabled,e[27]=p):p=e[27];let w;e[28]!==x.confirmBulkDelete||e[29]!==o||e[30]!==d||e[31]!==a?(w=s.jsx(Fj,{value:o,setValue:l,showDeletionDialog:a,setShowDeletionDialog:d,onConfirm:x.confirmBulkDelete}),e[28]=x.confirmBulkDelete,e[29]=o,e[30]=d,e[31]=a,e[32]=w):w=e[32];let N;return e[33]!==p||e[34]!==w?(N=s.jsxs(s.Fragment,{children:[p,w]}),e[33]=p,e[34]=w,e[35]=N):N=e[35],N}function x2(t){return t.deleteSessions}function y2(t){return t.unarchiveSessions}function w2(t){return t.archiveSessions}function S2(t){return t.removeSessionsFromFolders}function v2(t){return t.addSessionsToFolder}function j2(t){return t.createFolder}function k2(t){return t.foldersMap}function C2(t){return t.setShowDeletionDialog}function N2(t){return t.showDeletionDialog}const Tc=7,A2=6e4,D2=()=>{const t=Ye.c(2),[e,n]=c.useState(0);let r,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{const o=setInterval(()=>{n(T2)},A2);return()=>clearInterval(o)},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),c.useEffect(r,i),e};function P2(t){const{sections:e,variant:n="section",initialVisibleCount:r=Tc,batchSize:i=Tc}=t,{t:o}=ht(),{pinnedSessionIds:l}=t,a=us(p=>p.stickyZoneHeaders),[d,u]=c.useState(new Set),[m,h]=c.useState(new Map),y=n==="flat",b=c.useCallback(p=>{h(w=>{if(!w.has(p))return w;const N=new Map(w);return N.delete(p),N})},[]),S=c.useCallback(p=>{b(p),u(w=>{const N=new Set(w);return N.has(p)?N.delete(p):N.add(p),N})},[b]),v=c.useCallback((p,w,N)=>{h(C=>{const k=Math.min(N,w+i),A=new Map(C);return A.set(p,k),A})},[i]),g=D2(),f=c.useCallback(p=>{const w=new Set;ia(p,t.editingId,w);const N=Jr(p,t.openSidebarMenuKey,"recent",!1),C=new WeakMap,k=D=>{C.set(D,qo(D)),D.children.forEach(k)};p.forEach(k);const A=D=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:g,childRenderExtrasFor:A});return D=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:C.get(D)??"",relativeTimeTick:g,childRenderExtrasFor:A})},[t.editingId,t.openSidebarMenuKey,g]),x=e.filter(p=>p.items.length>0||p.key==="chats");return x.length===0?null:s.jsx("div",{className:Ie(y?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:x.map(p=>{const w=d.has(p.key),N=Math.max(r,m.get(p.key)??r),C=p.items.slice(0,N),k=p.items.length-C.length,A=p.key==="chats"&&!!t.renderChatsSection,D=!A&&!y&&p.items.length>r&&k===0,P=f(C.map(z=>z.node)),M=z=>s.jsx(Qo,{node:z.node,pinnedSessionIds:l,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,groupDirectory:z.groupDirectory,projectId:z.projectId,secondaryMeta:z.secondaryMeta,renderContext:"recent",renderExtras:P(z.node),setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad},z.node.session.id);return y?s.jsxs("div",{className:"space-y-0.5",children:[C.map(M),k>0?s.jsx("button",{type:"button",onClick:()=>v(p.key,C.length,p.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null]},p.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsxs("div",{className:Ie("relative group/chats","-ml-2.5 -mr-2",a&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":a?"true":void 0,children:[s.jsxs("button",{type:"button",onClick:()=>S(p.key),className:Ie("group flex w-full items-center gap-1.5 py-1 pl-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",p.key==="chats"?"pr-10":"pr-3.5"),"aria-expanded":!w,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(R,{name:p.key==="chats"?"chat-4":"history",className:Ie("h-3.5 w-3.5 text-muted-foreground/80","group-hover:hidden")}),s.jsx("span",{className:"hidden h-3.5 w-3.5 items-center justify-center text-muted-foreground group-hover:inline-flex",children:w?s.jsx(R,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:p.title})]}),p.key==="chats"&&t.onNewChat?s.jsx("button",{type:"button",onClick:z=>{z.stopPropagation(),t.onNewChat?.()},className:Ie("absolute right-0.5 top-1/2 z-10 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",t.alwaysShowActions?"opacity-100":"opacity-0 pointer-events-none group-hover/chats:opacity-100 group-hover/chats:pointer-events-auto group-focus-within/chats:opacity-100 group-focus-within/chats:pointer-events-auto"),"aria-label":o("sessions.sidebar.header.actions.newSession"),children:s.jsx(R,{name:"add",className:"h-4 w-4"})}):null]}),w?null:s.jsxs("div",{className:Ie("space-y-0.5"),children:[A?t.renderChatsSection?.(p.items):C.map(M),!A&&k>0?s.jsx("button",{type:"button",onClick:()=>v(p.key,C.length,p.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showMore")}):null,D?s.jsx("button",{type:"button",onClick:()=>b(p.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:o("sessions.sidebar.group.showFewer")}):null]})]},p.key)})})}function T2(t){return t+1}const I2=t=>{const e=Ye.c(61),{projects:n,availableWorktreesByProject:r,gitBranches:i,homeDirectory:o,hasSessionSearchQuery:l,normalizedSessionSearchQuery:a,isDesktopShellRuntime:d,sessions:u,childrenMap:m,pinnedSessionIds:h,recentSessions:y,chatSessions:b,showRecentSection:S}=t,{t:v}=ht();let g;if(e[0]!==r||e[1]!==i||e[2]!==o||e[3]!==n||e[4]!==u){g=new Map;for(const T of u){const _=dt(T.directory??null);if(!_)continue;let O=null,j=-1;for(const X of n){const Q=dt(X.normalizedPath);Q&&(_===Q||_.startsWith(`${Q}/`))&&Q.length>j&&(O=X,j=Q.length)}if(!O)continue;const E=r.get(O.normalizedPath)?.find(X=>dt(X.path)===_),L=Ma(O.label?.trim()||Wn(O.normalizedPath,o)||O.normalizedPath),U=E?.branch?.trim()||i.get(_)?.trim()||null;g.set(T.id,{projectId:O.id,groupDirectory:_,projectLabel:L,branchLabel:U&&U!=="HEAD"&&U!==L?U:null})}e[0]=r,e[1]=i,e[2]=o,e[3]=n,e[4]=u,e[5]=g}else g=e[5];const f=g;let x;e[6]!==f?(x=T=>f.get(T)??null,e[6]=f,e[7]=x):x=e[7];const p=x;let w;e[8]!==m?(w=T=>({session:T,children:(m.get(T.id)??[]).filter(E2).map(R2),worktree:null}),e[8]=m,e[9]=w):w=e[9];const N=w,C=l?a:"";let k;e[10]!==p||e[11]!==N||e[12]!==y||e[13]!==C?(k=_p({sessions:y,getSessionLocation:p,getSessionNode:N,query:C}),e[10]=p,e[11]=N,e[12]=y,e[13]=C,e[14]=k):k=e[14];const A=k;let D;e[15]!==v?(D=v("sessions.sidebar.activity.chatsTitle"),e[15]=v,e[16]=D):D=e[16];let P;if(e[17]!==b||e[18]!==N){let T;e[20]!==N?(T=_=>({node:N(_),projectId:null,groupDirectory:_.directory??null,secondaryMeta:null}),e[20]=N,e[21]=T):T=e[21],P=b.map(T),e[17]=b,e[18]=N,e[19]=P}else P=e[19];let M;e[22]!==D||e[23]!==P?(M={key:"chats",title:D,items:P},e[22]=D,e[23]=P,e[24]=M):M=e[24];let z;e[25]!==A||e[26]!==S||e[27]!==v||e[28]!==M?(z=[M,...S?A.map(T=>({...T,title:v("sessions.sidebar.activity.recentTitle")})):[]],e[25]=A,e[26]=S,e[27]=v,e[28]=M,e[29]=z):z=e[29];const I=z;let V;return e[30]!==d||e[31]!==h||e[32]!==t.allowReselect||e[33]!==t.alwaysShowActions||e[34]!==t.copiedSessionId||e[35]!==t.deleteSessionConfirm||e[36]!==t.editTitle||e[37]!==t.editingId||e[38]!==t.expandedParents||e[39]!==t.hasSessionSearchQuery||e[40]!==t.isSessionSearchOpen||e[41]!==t.mobileVariant||e[42]!==t.normalizedSessionSearchQuery||e[43]!==t.notifyOnSubtasks||e[44]!==t.onNewChat||e[45]!==t.onSessionSelected||e[46]!==t.openSidebarMenuKey||e[47]!==t.renderChatsSection||e[48]!==t.sessionSearchQuery||e[49]!==t.setCopiedSessionId||e[50]!==t.setDeleteSessionConfirm||e[51]!==t.setEditTitle||e[52]!==t.setEditingId||e[53]!==t.setIsSessionSearchOpen||e[54]!==t.setOpenSidebarMenuKey||e[55]!==t.setSessionSearchQuery||e[56]!==t.startFolderRename||e[57]!==t.startSessionWorktreeMenuLoad||e[58]!==t.toggleParent||e[59]!==I?(V=s.jsx(P2,{sections:I,variant:"section",isDesktopShellRuntime:d,pinnedSessionIds:h,expandedParents:t.expandedParents,hasSessionSearchQuery:t.hasSessionSearchQuery,normalizedSessionSearchQuery:t.normalizedSessionSearchQuery,notifyOnSubtasks:t.notifyOnSubtasks,editingId:t.editingId,editTitle:t.editTitle,copiedSessionId:t.copiedSessionId,openSidebarMenuKey:t.openSidebarMenuKey,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onNewChat:t.onNewChat,renderChatsSection:t.renderChatsSection,setEditingId:t.setEditingId,setEditTitle:t.setEditTitle,toggleParent:t.toggleParent,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,allowReselect:t.allowReselect,onSessionSelected:t.onSessionSelected,isSessionSearchOpen:t.isSessionSearchOpen,sessionSearchQuery:t.sessionSearchQuery,setSessionSearchQuery:t.setSessionSearchQuery,setIsSessionSearchOpen:t.setIsSessionSearchOpen,deleteSessionConfirm:t.deleteSessionConfirm,setDeleteSessionConfirm:t.setDeleteSessionConfirm,startFolderRename:t.startFolderRename,setCopiedSessionId:t.setCopiedSessionId,startSessionWorktreeMenuLoad:t.startSessionWorktreeMenuLoad}),e[30]=d,e[31]=h,e[32]=t.allowReselect,e[33]=t.alwaysShowActions,e[34]=t.copiedSessionId,e[35]=t.deleteSessionConfirm,e[36]=t.editTitle,e[37]=t.editingId,e[38]=t.expandedParents,e[39]=t.hasSessionSearchQuery,e[40]=t.isSessionSearchOpen,e[41]=t.mobileVariant,e[42]=t.normalizedSessionSearchQuery,e[43]=t.notifyOnSubtasks,e[44]=t.onNewChat,e[45]=t.onSessionSelected,e[46]=t.openSidebarMenuKey,e[47]=t.renderChatsSection,e[48]=t.sessionSearchQuery,e[49]=t.setCopiedSessionId,e[50]=t.setDeleteSessionConfirm,e[51]=t.setEditTitle,e[52]=t.setEditingId,e[53]=t.setIsSessionSearchOpen,e[54]=t.setOpenSidebarMenuKey,e[55]=t.setSessionSearchQuery,e[56]=t.startFolderRename,e[57]=t.startSessionWorktreeMenuLoad,e[58]=t.toggleParent,e[59]=I,e[60]=V):V=e[60],V};function E2(t){return!t.time?.archived}function R2(t){return{session:t,children:[],worktree:null}}const fm="oc.sessions.expandedParents.v3",M2=Fa(vr()),O2=()=>{try{const t=globalThis.localStorage.getItem(fm);if(t===null)return new Set;const e=M2.safeParse(JSON.parse(t));return e.success?new Set(e.data):new Set}catch{return new Set}},B2=()=>{const[t,e]=c.useState(O2),n=c.useRef(t);n.current=t;const r=c.useCallback(i=>{const o=wh(n.current,i);n.current=o,e(o);try{globalThis.localStorage.setItem(fm,JSON.stringify([...o]))}catch{}},[]);return{expandedParents:t,toggleParent:r}},F2=5*6e4,_2=[],L2=t=>!t.parentID,$2=t=>{const e=Ye.c(291),{topology:n,view:r,actions:i}=t;let o,l,a,d,u;e[0]!==i?({alwaysShowActions:o,notifyOnSubtasks:l,projectViewActions:a,rowActions:d,...u}=i,e[0]=i,e[1]=o,e[2]=l,e[3]=a,e[4]=d,e[5]=u):(o=e[1],l=e[2],a=e[3],d=e[4],u=e[5]);const m=ms(z2),h=ms(V2),y=ms(U2),b=r.projectView,{getOrderedGroups:S,setGroupOrderByProject:v,toggleGroup:g,toggleProject:f}=a;let x;e[6]!==n.isVSCode||e[7]!==n.knownDirectories?(x={knownDirectories:n.knownDirectories,isVSCode:n.isVSCode,isVisible:!0},e[6]=n.isVSCode,e[7]=n.knownDirectories,e[8]=x):x=e[8];const p=Lp(x);let w;e[9]===Symbol.for("react.memo_cache_sentinel")?(w=new Map,e[9]=w):w=e[9];const[N,C]=c.useState(w);let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=(Lt,Wt)=>{C(q=>new Map(q).set(Lt,Wt+7))},e[10]=k):k=e[10];const A=k;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=Lt=>{C(Wt=>{if(!Wt.has(Lt))return Wt;const q=new Map(Wt);return q.delete(Lt),q})},e[11]=D):D=e[11];const P=D,M=us(H2),z=us(K2),I=us(G2),V=us(q2);let T;e[12]!==n.isVSCode?(T=!n.isVSCode&&!Vm(),e[12]=n.isVSCode,e[13]=T):T=e[13];const O=T&&z==="single",j=M&&!O;let E;e[14]!==p.pinnedSessionIds||e[15]!==p.rootSessions||e[16]!==p.sessionOrderRanks||e[17]!==j||e[18]!==n.isVSCode?(E={enabled:j,isVSCode:n.isVSCode,pinnedSessionIds:p.pinnedSessionIds,sessionOrderRanks:p.sessionOrderRanks,sessions:p.rootSessions},e[14]=p.pinnedSessionIds,e[15]=p.rootSessions,e[16]=p.sessionOrderRanks,e[17]=j,e[18]=n.isVSCode,e[19]=E):E=e[19];const L=$p(E),[U,X]=c.useState(null),[Q,me]=c.useState(""),[re,G]=c.useState(null),[ee,ue]=c.useState(null),[W,ne]=c.useState(null),[Y,F]=c.useState(null);let J;e[20]===Symbol.for("react.memo_cache_sentinel")?(J=(Lt,Wt)=>{F({scopeKey:Lt,folderId:Wt.id,draft:Wt.name})},e[20]=J):J=e[20];const ie=J;let xe;e[21]===Symbol.for("react.memo_cache_sentinel")?(xe=Lt=>{F(Wt=>Wt?{...Wt,draft:Lt}:null)},e[21]=xe):xe=e[21];const ge=xe;let Ce;e[22]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>F(null),e[22]=Ce):Ce=e[22];const Re=Ce,{expandedParents:ce,toggleParent:ye}=B2(),be=qe(Q2);let te;e[23]!==be?(te=(Lt,Wt)=>{Lt!==qe.getState().currentSessionId&&be(Lt,Wt)},e[23]=be,e[24]=te):te=e[24];const pe=te,Pe=Sh();let de;e[25]!==p.pinnedSessionIds||e[26]!==p.sessionOrderRanks||e[27]!==n.gitBranches||e[28]!==n.isVSCode||e[29]!==n.worktreeMetadata||e[30]!==r.homeDirectory?(de={homeDirectory:r.homeDirectory,worktreeMetadata:n.worktreeMetadata,pinnedSessionIds:p.pinnedSessionIds,sessionOrderRanks:p.sessionOrderRanks,gitBranches:n.gitBranches,isVSCode:n.isVSCode},e[25]=p.pinnedSessionIds,e[26]=p.sessionOrderRanks,e[27]=n.gitBranches,e[28]=n.isVSCode,e[29]=n.worktreeMetadata,e[30]=r.homeDirectory,e[31]=de):de=e[31];const{buildGroupedSessions:he,filterSessionNodesForSearch:fe,buildGroupSearchText:B}=d2(de);let H;e[32]!==p.archivedSessions||e[33]!==p.sessions||e[34]!==n.availableWorktreesByProject||e[35]!==n.isVSCode||e[36]!==n.projects?(H=t0(p.sessions,n.projects,n.availableWorktreesByProject,n.isVSCode,p.archivedSessions),e[32]=p.archivedSessions,e[33]=p.sessions,e[34]=n.availableWorktreesByProject,e[35]=n.isVSCode,e[36]=n.projects,e[37]=H):H=e[37];const ke=H;let Se;e[38]!==ke?(Se={ownership:ke},e[38]=ke,e[39]=Se):Se=e[39];const{getSessionsForProject:Be,getArchivedSessionsForProject:_e}=s0(Se);let Te;e:{if(n.isVSCode){Te=null;break e}let Lt;e[40]!==p.chatSessions||e[41]!==r.homeDirectory?(Lt=vh(r.homeDirectory)??p.chatSessions.map(Y2).find(Boolean)??null,e[40]=p.chatSessions,e[41]=r.homeDirectory,e[42]=Lt):Lt=e[42];const Wt=Lt;if(!Wt){Te=null;break e}let q;if(e[43]!==Wt||e[44]!==p.chatSessions){const Dt=[Wt,...p.chatSessions.map(X2).filter(Boolean)];let gt;e[46]!==Dt?(gt=new Set(Dt),e[46]=Dt,e[47]=gt):gt=e[47],q=Array.from(gt).filter(J2).map(Z2),e[43]=Wt,e[44]=p.chatSessions,e[45]=q}else q=e[45];const Ve=q;let Xe;if(e[48]!==p.chatSessions||e[49]!==p.childrenMap){let Dt;e[51]!==p.childrenMap?(Dt=gt=>({session:gt,children:(p.childrenMap.get(gt.id)??[]).filter(tk).map(sk),worktree:null}),e[51]=p.childrenMap,e[52]=Dt):Dt=e[52],Xe=p.chatSessions.filter(ek).map(Dt),e[48]=p.chatSessions,e[49]=p.childrenMap,e[50]=Xe}else Xe=e[50];let ft;e[53]!==Wt||e[54]!==Ve||e[55]!==Xe?(ft={id:"managed-chats",label:"",branch:null,description:null,isMain:!0,worktree:null,directory:Wt,folderScopeKey:Wt,folderScopes:Ve,draftTarget:"chat",sessions:Xe},e[53]=Wt,e[54]=Ve,e[55]=Xe,e[56]=ft):ft=e[56],Te=ft}const Z=Te;let Ne;e[57]!==Z?(Ne=Z?[Z]:_2,e[57]=Z,e[58]=Ne):Ne=e[58];const Me=Ne;let $;e[59]!==B||e[60]!==he||e[61]!==fe||e[62]!==m||e[63]!==_e||e[64]!==Be||e[65]!==Me||e[66]!==n.availableWorktreesByProject||e[67]!==n.lastRepoStatus||e[68]!==n.projectRepoStatus||e[69]!==n.projectRootBranches||e[70]!==n.projects||e[71]!==r.hasSessionSearchQuery||e[72]!==r.normalizedSessionSearchQuery?($={normalizedProjects:n.projects,getSessionsForProject:Be,getArchivedSessionsForProject:_e,availableWorktreesByProject:n.availableWorktreesByProject,projectRepoStatus:n.projectRepoStatus,projectRootBranches:n.projectRootBranches,lastRepoStatus:n.lastRepoStatus,buildGroupedSessions:he,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,filterSessionNodesForSearch:fe,buildGroupSearchText:B,foldersMap:m,standaloneGroups:Me},e[59]=B,e[60]=he,e[61]=fe,e[62]=m,e[63]=_e,e[64]=Be,e[65]=Me,e[66]=n.availableWorktreesByProject,e[67]=n.lastRepoStatus,e[68]=n.projectRepoStatus,e[69]=n.projectRootBranches,e[70]=n.projects,e[71]=r.hasSessionSearchQuery,e[72]=r.normalizedSessionSearchQuery,e[73]=$):$=e[73];const{projectSections:ae,groupSearchDataByGroup:se,sectionsForRender:we,flatSectionsForRender:Ke,searchMatchCount:Qe}=r0($),He=r.onSearchMatchCountChange;let le,K;e[74]!==He||e[75]!==Qe?(le=()=>{He(Qe)},K=[He,Qe],e[74]=He,e[75]=Qe,e[76]=le,e[77]=K):(le=e[76],K=e[77]),c.useEffect(le,K);let ve,$e;e[78]!==He?(ve=()=>()=>He(0),$e=[He],e[78]=He,e[79]=ve,e[80]=$e):(ve=e[79],$e=e[80]),c.useEffect(ve,$e);const We=Oa(),Le=`session-collection-expansion:${c.useId()}`;let Fe,Ge;e[81]!==We||e[82]!==Le||e[83]!==ae||e[84]!==b.collapsedGroups||e[85]!==b.collapsedProjects||e[86]!==r.activeProjectId?(Fe=()=>(We.setBootstrapDemand(Le,rm({projectSections:ae,activeProjectId:r.activeProjectId,collapsedProjects:b.collapsedProjects,collapsedGroups:b.collapsedGroups,currentDirectory:null,currentSessionDirectory:null})),()=>We.clearBootstrapDemand(Le)),Ge=[We,Le,ae,b.collapsedProjects,b.collapsedGroups,r.activeProjectId],e[81]=We,e[82]=Le,e[83]=ae,e[84]=b.collapsedGroups,e[85]=b.collapsedProjects,e[86]=r.activeProjectId,e[87]=Fe,e[88]=Ge):(Fe=e[87],Ge=e[88]),c.useEffect(Fe,Ge);const rt=r.useGroupedSections?we:Ke;let St;e[89]!==rt||e[90]!==r.showInlineArchived?(St=r.showInlineArchived?rt:rt.map(ok),e[89]=rt,e[90]=r.showInlineArchived,e[91]=St):St=e[91];const Rt=St;let ze;e[92]!==Ke?(ze=Lt=>Ke.find(q=>q.project.id===Lt)?.groups.find(ik)?.folderScopes??[],e[92]=Ke,e[93]=ze):ze=e[93];const Pt=ze;let Nt;e[94]===Symbol.for("react.memo_cache_sentinel")?(Nt=new Map,e[94]=Nt):Nt=e[94];const Tt=c.useRef(Nt);let Et;e[95]!==ae||e[96]!==r.isDesktopShellRuntime||e[97]!==r.stickyZoneHeaders?(Et={enabled:r.stickyZoneHeaders,isDesktopShellRuntime:r.isDesktopShellRuntime,projectSections:ae,projectHeaderSentinelRefs:Tt},e[95]=ae,e[96]=r.isDesktopShellRuntime,e[97]=r.stickyZoneHeaders,e[98]=Et):Et=e[98];const vt=u2(Et);let Ct;e[99]!==y||e[100]!==p.hasAuthoritativeGlobalSessions||e[101]!==h||e[102]!==m||e[103]!==ke||e[104]!==n.projects||e[105]!==r.isSessionsLoading||e[106]!==r.isWorktreeTopologyLoading||e[107]!==r.unresolvedWorktreeProjectPaths?(Ct={enabled:!0,normalizedProjects:n.projects,ownership:ke,isSessionsLoading:r.isSessionsLoading,hasAuthoritativeGlobalSessions:p.hasAuthoritativeGlobalSessions,isWorktreeTopologyLoading:r.isWorktreeTopologyLoading,unresolvedWorktreeProjectPaths:r.unresolvedWorktreeProjectPaths,foldersMap:m,createFolder:h,addSessionToFolder:y},e[99]=y,e[100]=p.hasAuthoritativeGlobalSessions,e[101]=h,e[102]=m,e[103]=ke,e[104]=n.projects,e[105]=r.isSessionsLoading,e[106]=r.isWorktreeTopologyLoading,e[107]=r.unresolvedWorktreeProjectPaths,e[108]=Ct):Ct=e[108],Hv(Ct);const{github:It}=Pn(),mt=er(ak),Ze=er(lk),je=Ys(ck),ot=Ys(dk),ct=Ys(uk);let Mt;e[109]===Symbol.for("react.memo_cache_sentinel")?(Mt=new Set,e[109]=Mt):Mt=e[109];const Je=c.useRef(Mt);let nt;e[110]!==je||e[111]!==It||e[112]!==Ze||e[113]!==mt||e[114]!==ae||e[115]!==b.collapsedProjects||e[116]!==ct||e[117]!==ot||e[118]!==n.gitBranches?(nt=()=>{if(!It||!Ze||!mt?.connected)return;const Lt=new Map,Wt=Date.now();ae.forEach(q=>{b.collapsedProjects.has(q.project.id)||q.groups.forEach(Ve=>{if(Ve.isArchivedBucket||Ve.isMain)return;const Xe=dt(Ve.directory??null),ft=Ve.branch?.trim()||n.gitBranches.get(Xe||"")?.trim();if(!Xe||!ft)return;const Dt=ni(Xe,ft),gt=Ys.getState().entries[Dt],wt=gt?.status?.pr?.state==="closed"||gt?.status?.pr?.state==="merged",is=`${Xe}::${ft}`,cs=Math.max(gt?.lastRefreshAt??0,gt?.lastDiscoveryPollAt??0),Jt=!!(gt?.isInitialStatusResolved&&(!gt.status?.pr||wt)&&(!Je.current.has(is)||Wt-cs>=F2));(!gt||!gt.isInitialStatusResolved||Jt)&&(Jt&&Je.current.add(is),Lt.set(Dt,{directory:Xe,branch:ft}))})}),Lt.forEach((q,Ve)=>{je(Ve),ot(Ve,{...q,remoteName:null,canShow:!0,github:It,githubAuthChecked:Ze,githubConnected:mt.connected})}),Lt.size&&ct([...Lt.values()],{silent:!0,markInitialResolved:!0})},e[110]=je,e[111]=It,e[112]=Ze,e[113]=mt,e[114]=ae,e[115]=b.collapsedProjects,e[116]=ct,e[117]=ot,e[118]=n.gitBranches,e[119]=nt):nt=e[119];const jt=mt?.connected;let At;e[120]!==je||e[121]!==It||e[122]!==Ze||e[123]!==ae||e[124]!==b.collapsedProjects||e[125]!==ct||e[126]!==ot||e[127]!==jt||e[128]!==n.gitBranches?(At=[je,It,Ze,jt,ae,b.collapsedProjects,ct,ot,n.gitBranches],e[120]=je,e[121]=It,e[122]=Ze,e[123]=ae,e[124]=b.collapsedProjects,e[125]=ct,e[126]=ot,e[127]=jt,e[128]=n.gitBranches,e[129]=At):At=e[129],c.useEffect(nt,At);let Ot;e[130]!==p.orderedSessions?(Ot=new Map(p.orderedSessions.map(mk)),e[130]=p.orderedSessions,e[131]=Ot):Ot=e[131];const $t=Ot;let Zt;if(e[132]!==S||e[133]!==Rt){let Lt;e[135]!==S?(Lt=Wt=>{const q=S(Wt.project.id,Wt.groups);return q===Wt.groups?Wt:{...Wt,groups:q}},e[135]=S,e[136]=Lt):Lt=e[136],Zt=Rt.map(Lt),e[132]=S,e[133]=Rt,e[134]=Zt}else Zt=e[134];const Gt=Zt;let Ft;e[137]!==ae||e[138]!==I||e[139]!==O||e[140]!==r.activeProjectId?(Ft=null,O&&(ae.some(Lt=>Lt.project.id===I)?Ft=I:ae.some(Lt=>Lt.project.id===r.activeProjectId)?Ft=r.activeProjectId:Ft=ae[0]?.project.id??null),e[137]=ae,e[138]=I,e[139]=O,e[140]=r.activeProjectId,e[141]=Ft):Ft=e[141];const qt=O&&!r.useGroupedSections?20:void 0;let Xt;e[142]!==i.startSessionWorktreeMenuLoad||e[143]!==o||e[144]!==p.pinnedSessionIds||e[145]!==W||e[146]!==ee||e[147]!==Q||e[148]!==U||e[149]!==ce||e[150]!==Y||e[151]!==se||e[152]!==l||e[153]!==b.collapsedGroups||e[154]!==d.allowReselect||e[155]!==d.isSessionSearchOpen||e[156]!==d.onSessionSelected||e[157]!==d.sessionSearchQuery||e[158]!==d.setIsSessionSearchOpen||e[159]!==d.setSessionSearchQuery||e[160]!==$t||e[161]!==qt||e[162]!==ye||e[163]!==r.activeProjectId||e[164]!==r.hasSessionSearchQuery||e[165]!==r.hideDirectoryControls||e[166]!==r.mobileVariant||e[167]!==r.normalizedSessionSearchQuery?(Xt={hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,groupSearchDataByGroup:se,collapsedGroups:b.collapsedGroups,hideDirectoryControls:r.hideDirectoryControls,mobileVariant:r.mobileVariant,alwaysShowActions:o,activeProjectId:r.activeProjectId,notifyOnSubtasks:l,pinnedSessionIds:p.pinnedSessionIds,sessionOrderIndex:$t,expandedParents:ce,editingId:U,editTitle:Q,copiedSessionId:W,sessionBatchSize:qt,setEditingId:X,setEditTitle:me,toggleParent:ye,allowReselect:d.allowReselect,onSessionSelected:d.onSessionSelected,isSessionSearchOpen:d.isSessionSearchOpen,sessionSearchQuery:d.sessionSearchQuery,setSessionSearchQuery:d.setSessionSearchQuery,setIsSessionSearchOpen:d.setIsSessionSearchOpen,deleteSessionConfirm:ee,setDeleteSessionConfirm:ue,startFolderRename:ie,setCopiedSessionId:ne,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,folderRename:Y,setFolderRenameDraft:ge,clearFolderRename:Re},e[142]=i.startSessionWorktreeMenuLoad,e[143]=o,e[144]=p.pinnedSessionIds,e[145]=W,e[146]=ee,e[147]=Q,e[148]=U,e[149]=ce,e[150]=Y,e[151]=se,e[152]=l,e[153]=b.collapsedGroups,e[154]=d.allowReselect,e[155]=d.isSessionSearchOpen,e[156]=d.onSessionSelected,e[157]=d.sessionSearchQuery,e[158]=d.setIsSessionSearchOpen,e[159]=d.setSessionSearchQuery,e[160]=$t,e[161]=qt,e[162]=ye,e[163]=r.activeProjectId,e[164]=r.hasSessionSearchQuery,e[165]=r.hideDirectoryControls,e[166]=r.mobileVariant,e[167]=r.normalizedSessionSearchQuery,e[168]=Xt):Xt=e[168];const zt=Xt;let Ee;e[169]!==u.openNewSessionDraft||e[170]!==u.setActiveProjectIdOnly||e[171]!==u.setSessionSwitcherOpen||e[172]!==g?(Ee={showMoreGroupSessions:A,resetGroupSessionLimit:P,setActiveProjectIdOnly:u.setActiveProjectIdOnly,setSessionSwitcherOpen:u.setSessionSwitcherOpen,openNewSessionDraft:u.openNewSessionDraft,onToggleCollapsedGroup:g},e[169]=u.openNewSessionDraft,e[170]=u.setActiveProjectIdOnly,e[171]=u.setSessionSwitcherOpen,e[172]=g,e[173]=Ee):Ee=e[173];const Ue=Ee;let et;e[174]!==Z||e[175]!==Ue||e[176]!==zt||e[177]!==re?(et=()=>Z?s.jsx(Ro,{...zt,...Ue,group:Z,groupKey:"managed-chats",projectId:null,hideGroupLabel:!0,sessionBatchSize:20,scrollContainerRef:void 0,openSidebarMenuKey:re,setOpenSidebarMenuKey:G}):null,e[174]=Z,e[175]=Ue,e[176]=zt,e[177]=re,e[178]=et):et=e[178];const lt=et;let ut;e[179]!==u||e[180]!==r.mobileVariant?(ut=()=>{Ae.getState().closeMainSurfaces(),r.mobileVariant&&u.setSessionSwitcherOpen(!1),u.openNewSessionDraft({selectedProjectId:jh,directoryOverride:null})},e[179]=u,e[180]=r.mobileVariant,e[181]=ut):ut=e[181];const kt=ut;let st;e[182]!==i.startSessionWorktreeMenuLoad||e[183]!==o||e[184]!==p.chatSessions||e[185]!==p.childrenMap||e[186]!==p.pinnedSessionIds||e[187]!==W||e[188]!==ee||e[189]!==Q||e[190]!==U||e[191]!==ce||e[192]!==kt||e[193]!==l||e[194]!==re||e[195]!==L||e[196]!==lt||e[197]!==d.allowReselect||e[198]!==d.isSessionSearchOpen||e[199]!==d.onSessionSelected||e[200]!==d.sessionSearchQuery||e[201]!==d.setIsSessionSearchOpen||e[202]!==d.setSessionSearchQuery||e[203]!==M||e[204]!==O||e[205]!==ye||e[206]!==n.availableWorktreesByProject||e[207]!==n.gitBranches||e[208]!==n.isVSCode||e[209]!==n.projects||e[210]!==r.hasSessionSearchQuery||e[211]!==r.homeDirectory||e[212]!==r.isDesktopShellRuntime||e[213]!==r.mobileVariant||e[214]!==r.normalizedSessionSearchQuery?(st=n.isVSCode?null:s.jsx(I2,{projects:n.projects,availableWorktreesByProject:n.availableWorktreesByProject,gitBranches:n.gitBranches,homeDirectory:r.homeDirectory,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,isDesktopShellRuntime:r.isDesktopShellRuntime,sessions:L,childrenMap:p.childrenMap,pinnedSessionIds:p.pinnedSessionIds,recentSessions:L,expandedParents:ce,notifyOnSubtasks:l,editingId:U,editTitle:Q,copiedSessionId:W,openSidebarMenuKey:re,mobileVariant:r.mobileVariant,alwaysShowActions:o,setEditingId:X,setEditTitle:me,toggleParent:ye,setOpenSidebarMenuKey:G,allowReselect:d.allowReselect,onSessionSelected:d.onSessionSelected,isSessionSearchOpen:d.isSessionSearchOpen,sessionSearchQuery:d.sessionSearchQuery,setSessionSearchQuery:d.setSessionSearchQuery,setIsSessionSearchOpen:d.setIsSessionSearchOpen,deleteSessionConfirm:ee,setDeleteSessionConfirm:ue,startFolderRename:ie,setCopiedSessionId:ne,startSessionWorktreeMenuLoad:i.startSessionWorktreeMenuLoad,chatSessions:p.chatSessions,renderChatsSection:lt,onNewChat:kt,showRecentSection:M&&!O}),e[182]=i.startSessionWorktreeMenuLoad,e[183]=o,e[184]=p.chatSessions,e[185]=p.childrenMap,e[186]=p.pinnedSessionIds,e[187]=W,e[188]=ee,e[189]=Q,e[190]=U,e[191]=ce,e[192]=kt,e[193]=l,e[194]=re,e[195]=L,e[196]=lt,e[197]=d.allowReselect,e[198]=d.isSessionSearchOpen,e[199]=d.onSessionSelected,e[200]=d.sessionSearchQuery,e[201]=d.setIsSessionSearchOpen,e[202]=d.setSessionSearchQuery,e[203]=M,e[204]=O,e[205]=ye,e[206]=n.availableWorktreesByProject,e[207]=n.gitBranches,e[208]=n.isVSCode,e[209]=n.projects,e[210]=r.hasSessionSearchQuery,e[211]=r.homeDirectory,e[212]=r.isDesktopShellRuntime,e[213]=r.mobileVariant,e[214]=r.normalizedSessionSearchQuery,e[215]=st):st=e[215];const _t=st;let es;e[216]!==se||e[217]!==Me||e[218]!==r.hasSessionSearchQuery?(es=r.hasSessionSearchQuery&&Me.some(Lt=>se.get(Lt)?.hasMatch===!0),e[216]=se,e[217]=Me,e[218]=r.hasSessionSearchQuery,e[219]=es):es=e[219];const Ds=es,Os=!!_t;let bs;e[220]!==U||e[221]!==re||e[222]!==N?(bs={editingId:U,openSidebarMenuKey:re,setOpenSidebarMenuKey:G,visibleSessionCountByGroup:N},e[220]=U,e[221]=re,e[222]=N,e[223]=bs):bs=e[223];let xs;e[224]!==zt||e[225]!==Gt||e[226]!==ae||e[227]!==_t||e[228]!==Ft||e[229]!==O||e[230]!==vt||e[231]!==Os||e[232]!==bs||e[233]!==Ds||e[234]!==n.projectRepoStatus||e[235]!==r.activeProjectId||e[236]!==r.emptyState||e[237]!==r.searchEmptyState?(xs={topContent:_t,topContentHasSearchMatches:Ds,hasSharedSessions:Os,sectionsForRender:Gt,projectSections:ae,activeProjectId:r.activeProjectId,singleProjectMode:O,singleProjectId:Ft,emptyState:r.emptyState,searchEmptyState:r.searchEmptyState,projectRepoStatus:n.projectRepoStatus,stuckProjectHeaders:vt,projectHeaderSentinelRefs:Tt,state:bs,groupProps:zt},e[224]=zt,e[225]=Gt,e[226]=ae,e[227]=_t,e[228]=Ft,e[229]=O,e[230]=vt,e[231]=Os,e[232]=bs,e[233]=Ds,e[234]=n.projectRepoStatus,e[235]=r.activeProjectId,e[236]=r.emptyState,e[237]=r.searchEmptyState,e[238]=xs):xs=e[238];const os=xs;let Ps;e[239]!==o||e[240]!==b.collapsedProjects||e[241]!==r.hasSessionSearchQuery||e[242]!==r.hideDirectoryControls||e[243]!==r.homeDirectory||e[244]!==r.isDesktopShellRuntime||e[245]!==r.mobileVariant||e[246]!==r.normalizedSessionSearchQuery||e[247]!==r.projectSortOrder||e[248]!==r.showOnlyMainWorkspace||e[249]!==r.stickyZoneHeaders?(Ps={homeDirectory:r.homeDirectory,collapsedProjects:b.collapsedProjects,showOnlyMainWorkspace:r.showOnlyMainWorkspace,hasSessionSearchQuery:r.hasSessionSearchQuery,normalizedSessionSearchQuery:r.normalizedSessionSearchQuery,hideDirectoryControls:r.hideDirectoryControls,isDesktopShellRuntime:r.isDesktopShellRuntime,stickyZoneHeaders:r.stickyZoneHeaders,mobileVariant:r.mobileVariant,alwaysShowActions:o,projectSortOrder:r.projectSortOrder},e[239]=o,e[240]=b.collapsedProjects,e[241]=r.hasSessionSearchQuery,e[242]=r.hideDirectoryControls,e[243]=r.homeDirectory,e[244]=r.isDesktopShellRuntime,e[245]=r.mobileVariant,e[246]=r.normalizedSessionSearchQuery,e[247]=r.projectSortOrder,e[248]=r.showOnlyMainWorkspace,e[249]=r.stickyZoneHeaders,e[250]=Ps):Ps=e[250];const fs=Ps;let Bs;e[251]!==Ue||e[252]!==u.openNewSessionDraft||e[253]!==u.openNewWorktreeDialog||e[254]!==u.openProjectEditDialog||e[255]!==u.openWorktreesPage||e[256]!==u.removeProject||e[257]!==u.renderProjectStatusIndicator||e[258]!==u.reorderProjects||e[259]!==u.setActiveProjectIdOnly||e[260]!==u.setSessionSwitcherOpen||e[261]!==v||e[262]!==V||e[263]!==f?(Bs={group:Ue,toggleProject:f,setActiveProjectIdOnly:u.setActiveProjectIdOnly,setSessionSwitcherOpen:u.setSessionSwitcherOpen,openNewSessionDraft:u.openNewSessionDraft,openNewWorktreeDialog:u.openNewWorktreeDialog,openWorktreesPage:u.openWorktreesPage,openProjectEditDialog:u.openProjectEditDialog,removeProject:u.removeProject,reorderProjects:u.reorderProjects,setGroupOrderByProject:v,renderProjectStatusIndicator:u.renderProjectStatusIndicator,setSingleProjectId:V},e[251]=Ue,e[252]=u.openNewSessionDraft,e[253]=u.openNewWorktreeDialog,e[254]=u.openProjectEditDialog,e[255]=u.openWorktreesPage,e[256]=u.removeProject,e[257]=u.renderProjectStatusIndicator,e[258]=u.reorderProjects,e[259]=u.setActiveProjectIdOnly,e[260]=u.setSessionSwitcherOpen,e[261]=v,e[262]=V,e[263]=f,e[264]=Bs):Bs=e[264];const Ks=Bs;let ys;e[265]!==i.initialActiveSessionByProject||e[266]!==i.openNewSessionDraft||e[267]!==i.persistActiveSessionByProject||e[268]!==i.setSessionSwitcherOpen||e[269]!==ke.bySessionId||e[270]!==ae||e[271]!==pe||e[272]!==r.activeProjectId||e[273]!==r.mobileVariant?(ys=s.jsx(Qv,{projectSections:ae,activeProjectId:r.activeProjectId,initialActiveSessionByProject:i.initialActiveSessionByProject,persistActiveSessionByProject:i.persistActiveSessionByProject,mobileVariant:r.mobileVariant,openNewSessionDraft:i.openNewSessionDraft,setSessionSwitcherOpen:i.setSessionSwitcherOpen,sessionOwnerBySessionId:ke.bySessionId,handleSessionSelect:pe}),e[265]=i.initialActiveSessionByProject,e[266]=i.openNewSessionDraft,e[267]=i.persistActiveSessionByProject,e[268]=i.setSessionSwitcherOpen,e[269]=ke.bySessionId,e[270]=ae,e[271]=pe,e[272]=r.activeProjectId,e[273]=r.mobileVariant,e[274]=ys):ys=e[274];let ws;e[275]!==p.orderedSessions||e[276]!==Pe||e[277]!==L?(ws=s.jsx(d0,{sortedSessions:p.orderedSessions,recentSessions:L,prefetchSession:Pe}),e[275]=p.orderedSessions,e[276]=Pe,e[277]=L,e[278]=ws):ws=e[278];let Ss;e[279]!==Ks||e[280]!==os||e[281]!==fs?(Ss=s.jsx(c2,{model:os,view:fs,actions:Ks}),e[279]=Ks,e[280]=os,e[281]=fs,e[282]=Ss):Ss=e[282];const hn=U!==null;let Gs;e[283]!==Pt||e[284]!==hn?(Gs=s.jsx(b2,{getFolderScopesForProject:Pt,isInlineEditing:hn,startFolderRename:ie}),e[283]=Pt,e[284]=hn,e[285]=Gs):Gs=e[285];let dn;return e[286]!==ys||e[287]!==ws||e[288]!==Ss||e[289]!==Gs?(dn=s.jsxs(s.Fragment,{children:[ys,ws,Ss,Gs]}),e[286]=ys,e[287]=ws,e[288]=Ss,e[289]=Gs,e[290]=dn):dn=e[290],dn},W2=t=>{const e=Ye.c(2);let n;return e[0]!==t?(n=t.view.isVisible?s.jsx($2,{...t}):null,e[0]=t,e[1]=n):n=e[1],n};function z2(t){return t.foldersMap}function V2(t){return t.createFolder}function U2(t){return t.addSessionToFolder}function H2(t){return t.showRecentSection}function K2(t){return t.projectDisplayMode}function G2(t){return t.singleProjectId}function q2(t){return t.setSingleProjectId}function Q2(t){return t.setCurrentSession}function Y2(t){return Ld(t.directory)}function X2(t){return dt(t.directory??null)}function J2(t){return!!t}function Z2(t){return{scopeKey:t,directory:t}}function ek(t){return!t.time?.archived&&L2(t)}function tk(t){return!t.time?.archived}function sk(t){return{session:t,children:[],worktree:null}}function nk(t){return t.isArchivedBucket}function rk(t){return!t.isArchivedBucket}function ok(t){return t.groups.some(nk)?{...t,groups:t.groups.filter(rk)}:t}function ik(t){return!t.isArchivedBucket}function ak(t){return t.status}function lk(t){return t.hasChecked}function ck(t){return t.ensureEntry}function dk(t){return t.setParams}function uk(t){return t.refreshTargets}function mk(t,e){return[t.id,e]}const hm=(t,e,n)=>{const r=new Set;for(const i of t){const o=dt(i.path)?.toLowerCase();o&&r.add(o)}if(n?.includeWorktrees===!1)return r;for(const i of e.values())for(const o of i){const l=dt(o.path)?.toLowerCase();l&&r.add(l)}return r},Ic="oc.sessions.activeSessionByProject",fk=[],hk=uu(vr(),vr().min(1).catch("")),pk=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:i=!1,showOnlyMainWorkspace:o=!1})=>{Pi("react.session_sidebar_render"),fn("ui.session_sidebar.render"),fn(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),fn(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:l}=ht(),[a,d]=c.useState(!1),[u,m]=c.useState(""),[h,y]=c.useState(0),b=c.useRef(null),S=c.useRef(null),[v,g]=c.useState(null),f=c.useMemo(()=>Fo(),[]),[x,p]=c.useState(new Map),w=Ae(je=>je.isNewWorktreeDialogOpen),N=Ae(je=>je.setNewWorktreeDialogOpen),[C,k]=c.useState(!1),A=c.useMemo(()=>{try{const je=f.getItem(Ic);if(!je)return new Map;const ot=hk.safeParse(JSON.parse(je));if(!ot.success)return new Map;const ct=new Map;return Object.entries(ot.data).forEach(([Mt,Je])=>{Je&&ct.set(Mt,Je)}),ct}catch{return new Map}},[f]),D=c.useCallback(je=>{try{f.setItem(Ic,JSON.stringify(Object.fromEntries(je.entries())))}catch{}},[f]),[P,M]=c.useState(new Map),z=ss(je=>je.homeDirectory),I=Ht(je=>je.projects),V=Ht(je=>je.activeProjectId),T=Ht(je=>je.removeProject),_=Ht(je=>je.setActiveProjectIdOnly),O=Ht(je=>je.updateProjectMeta),j=Ht(je=>je.reorderProjects),E=Ae(je=>je.setSettingsDialogOpen),L=Ae(je=>je.toggleHelpDialog),U=Ae(je=>je.setAboutDialogOpen),X=Ae(je=>je.setSessionSwitcherOpen),Q=Ae(je=>je.setScheduledTasksDialogOpen),me=Ae(je=>je.setArchivePageOpen),re=Ae(je=>je.setWorktreesPageProjectId),G=Ae(je=>je.openMultiRunLauncher),ee=Ae(je=>je.notifyOnSubtasks),ue=Aa(u,120),W=c.useMemo(()=>ue.trim().toLowerCase(),[ue]),ne=W.length>0;hv({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:S,sessionSearchContainerRef:b});const Y=Pd(t),F=c.useMemo(()=>Dn(),[]),J=qe(je=>je.setCurrentSession),ie=qe(je=>je.worktreeMetadata),xe=qe(je=>je.availableWorktreesByProject),ge=qe(je=>je.openNewSessionDraft),Ce=c.useMemo(()=>hm(I,xe,{includeWorktrees:!F}),[xe,F,I]),Re=c.useCallback(je=>{Ae.getState().closeMainSurfaces(),ge(je),F&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[F,ge]),ce=_r(tr(je=>({checkForUpdates:je.checkForUpdates,available:je.available,runtimeType:je.runtimeType,info:je.info,downloading:je.downloading,downloaded:je.downloaded,progress:je.progress,error:je.error,downloadUpdate:je.downloadUpdate,restartToUpdate:je.restartToUpdate}))),ye=Cs(),be=c.useMemo(()=>`${ye}|${I.map(je=>`${je.id}:${dt(je.path)??""}`).join("|")}`,[I,ye]),[te,pe]=c.useState(F?be:null),[Pe,de]=c.useReducer(je=>je+1,0),he=!F&&te!==be,[fe,B]=c.useState(new Set),H=c.useRef({runtimeKey:null,revision:0,worktreesByProject:new Map});c.useEffect(()=>{let je=!1;return(async()=>{const ct=ye,Mt=Ht.getState().projects;if(Mt.length===0||F){je||(H.current={runtimeKey:null,revision:0,worktreesByProject:new Map},B(new Set),pe(be));return}const Je=qe.getState().availableWorktreesByProject,nt=ca({rawWorktreesByProjectRef:H,publishedWorktreesByProject:Je,runtimeKey:ct}),jt=nt.revision,At=new Map(nt.worktreesByProject),Ot=new Set,$t=3;let Zt=0;const Gt=Array.from({length:$t},async()=>{for(;;){const Xt=Zt;if(Zt+=1,Xt>=Mt.length)return;const zt=Mt[Xt],Ee=dt(zt.path);if(Ee)try{const Ue=await Mi(async()=>$n.getState().directories.get(Ee)?.isGitRepo??await ti(Ee)?ml({id:zt.id,path:Ee}):null);if(Ue===null){At.delete(Ee);continue}if(je)return;Ue.length===0?At.delete(Ee):At.set(Ee,Ue)}catch{Ot.add(Ee)}}});if(await Promise.all(Gt),je||Cs()!==ct)return;const Ft=new Set(Mt.map(Xt=>dt(Xt.path)).filter(Boolean));for(const Xt of At.keys())Ft.has(Xt)||At.delete(Xt);vj({rawWorktreesByProjectRef:H,runtimeKey:ct,capturedRevision:jt,nextRawWorktreesByProject:At,publishedWorktreesByProject:Je,partitionWorktreesByRegisteredProject:hl,projects:Mt,worktreeMapsEqual:fl,recordWorktreesSeen:Dc,publishTopology:Xt=>{qe.setState(Xt)},requestRediscovery:()=>{de()},now:()=>Date.now()})&&(B(Ot),pe(be))})(),()=>{je=!0}},[F,be,ye,Pe]),c.useEffect(()=>{if(!F)return no(je=>{je.type==="session-created"&&de()})},[F]);const ke=c.useMemo(()=>wn(),[]),{isTablet:Se}=zn(),Be=e||Se,_e=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noSessions.description")})]}),[l]),Te=c.useMemo(()=>I.find(je=>je.id===v)??null,[I,v]),Z=c.useCallback(je=>{v&&O(v,{label:je.label,icon:je.icon,color:je.color,iconBackground:je.iconBackground,defaultModel:je.defaultModel??null})},[v,O]),Ne=c.useCallback(()=>{N(!0)},[N]),Me=c.useCallback(()=>{const je=_r.getState();if(je.available&&je.info){k(!0);return}ce.checkForUpdates().then(()=>{const{available:ot,error:ct}=_r.getState();if(ct){Oe.error(l("sessions.sidebar.updateCheck.errorTitle"),{description:ct});return}if(!ot){Oe.success(l("sessions.sidebar.updateCheck.latestVersion"));return}k(!0)})},[l,ce]),$=c.useCallback(()=>{e&&X(!1),E(!0)},[e,X,E]),ae=ce.available&&(ce.runtimeType==="desktop"||ce.runtimeType==="web"),se=c.useCallback(()=>{yn.requestDirectoryDialog()},[]),we=c.useMemo(()=>I.flatMap(je=>{const ot=dt(je.path);return ot?[{id:je.id,path:je.path,label:je.label,normalizedPath:ot,icon:je.icon??void 0,color:je.color??void 0,iconImage:je.iconImage??void 0,iconBackground:je.iconBackground??void 0,addedAt:je.addedAt,lastOpenedAt:je.lastOpenedAt,sidebarCollapsed:je.sidebarCollapsed}]:[]}),[I]),Ke=c.useMemo(()=>we.map(je=>je.normalizedPath),[we]),Qe=kh(t?Ke:fk);vv({enabled:t,normalizedProjects:we,gitRepoStatus:Qe,setProjectRepoStatus:p,setProjectRootBranches:M});const He=qe(je=>je.isLoading),le=c.useRef(!1);V&&x.has(V)&&(le.current=!!x.get(V));const K=us(je=>je.showArchivedSessions),ve=us(je=>je.projectSortOrder),$e=us(je=>je.stickyZoneHeaders),We=Ht(je=>je.manualProjectOrder),Le={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:i,showOnlyMainWorkspace:o,t:l,isTablet:Se,projects:I,activeProjectId:V,manualProjectOrder:We,worktreeMetadata:ie,availableWorktreesByProject:xe,gitBranches:Y,gitRepoStatus:Qe,updateStore:ce,showArchivedSessions:K,projectSortOrder:ve,projectRepoStatus:x,projectRootBranches:P,resolvedWorktreeTopologyKey:te,unresolvedWorktreeProjectPaths:fe,isSessionSearchOpen:a,sessionSearchQuery:u,editingProjectDialogId:v,updateDialogOpen:C},Fe=c.useRef(null),Ge=Fe.current;if(Ge){let je=!1;for(const ot of Object.keys(Le))Object.is(Ge[ot],Le[ot])||(fn(`ui.session_sidebar.source.${ot}`),je=!0);je||fn("ui.session_sidebar.source.parent_or_context")}Fe.current=Le;const rt=c.useMemo(()=>{const je=[...we];switch(ve){case"a-z":je.sort((ot,ct)=>{const Mt=(ot.label||ot.path).toLowerCase(),Je=(ct.label||ct.path).toLowerCase();return Mt.localeCompare(Je)});break;case"z-a":je.sort((ot,ct)=>{const Mt=(ot.label||ot.path).toLowerCase();return(ct.label||ct.path).toLowerCase().localeCompare(Mt)});break;case"date-added":je.sort((ot,ct)=>(ct.addedAt??0)-(ot.addedAt??0));break;case"recent":je.sort((ot,ct)=>(ct.lastOpenedAt??0)-(ot.lastOpenedAt??0));break;case"manual":{const ot=new Map(We.map((ct,Mt)=>[ct,Mt]));je.sort((ct,Mt)=>{const Je=ot.get(ct.id)??1/0,nt=ot.get(Mt.id)??1/0;return Je-nt});break}}return je},[we,ve,We]),St=xv({isVSCode:F,projects:rt}),Rt=c.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:l("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:l("sessions.sidebar.empty.noMatches.description")})]}),[l]),ze=F&&K,Nt=us(je=>je.sessionGroupingMode)==="by-worktree"&&!F,vt=e?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",Ct="h-4.5 w-4.5",It=c.useCallback(()=>{e&&X(!1),G()},[e,G,X]),mt=c.useCallback(je=>{const ot=je.projectId?I.find(ct=>ct.id===je.projectId)??null:je.sourceDirectory?Ii(je.sourceDirectory):null;return Sj(je,{projects:I,getCurrentProjects:()=>Ht.getState().projects,rawWorktreesByProjectRef:H,getPublishedWorktreesByProject:()=>qe.getState().availableWorktreesByProject,resolveProject:ct=>Ii(ct),listProjectWorktrees:ml,partitionWorktreesByRegisteredProject:hl,worktreeMapsEqual:fl,recordWorktreesSeen:Dc,publishTopology:ct=>{qe.setState(ct)},getRuntimeKey:Cs,now:()=>Date.now(),projectRootBranch:ot?P.get(ot.id)??null:null})},[P,I]),Ze=c.useCallback(()=>{Ae.getState().closeMainSurfaces(),e&&X(!1),ge()},[e,ge,X]);return s.jsx(Fi,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:b,className:Ie("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[!i&&!F?s.jsx(Vv,{onNewSession:Ze}):null,s.jsx(Pv,{hideDirectoryControls:i,showProjectDisplayControls:!F,showRecentControls:!F,handleOpenDirectoryDialog:se,onOpenScheduled:()=>{e&&X(!1),Q(!0)},onOpenMultiRun:It,canOpenMultiRun:I.length>0,onOpenArchive:()=>{e&&X(!1),me(!0)},headerActionIconClass:Ct,headerActionButtonClass:vt,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:S,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:ne,searchMatchCount:h,collapseAllProjects:St.actions.collapseAllProjects,expandAllProjects:St.actions.expandAllProjects}),s.jsx(W2,{topology:{projects:rt,availableWorktreesByProject:xe,knownDirectories:Ce,isVSCode:F,worktreeMetadata:ie,gitBranches:Y,projectRepoStatus:x,projectRootBranches:P,lastRepoStatus:le.current},view:{isVisible:t,hasSessionSearchQuery:ne,normalizedSessionSearchQuery:W,activeProjectId:V,showInlineArchived:ze,useGroupedSections:Nt,homeDirectory:z,mobileVariant:e,hideDirectoryControls:i,showOnlyMainWorkspace:o,isDesktopShellRuntime:ke,stickyZoneHeaders:$e,projectSortOrder:ve,emptyState:_e,searchEmptyState:Rt,isSessionsLoading:He,isWorktreeTopologyLoading:he,unresolvedWorktreeProjectPaths:fe,projectView:St.state,onSearchMatchCountChange:y},actions:{rowActions:{allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:d},alwaysShowActions:Be,notifyOnSubtasks:ee,setActiveProjectIdOnly:_,setSessionSwitcherOpen:X,openNewSessionDraft:Re,openNewWorktreeDialog:Ne,openWorktreesPage:je=>{e&&X(!1),re(je)},openProjectEditDialog:g,removeProject:T,reorderProjects:j,startSessionWorktreeMenuLoad:mt,initialActiveSessionByProject:A,persistActiveSessionByProject:D,projectViewActions:St.actions}}),s.jsx(Uv,{onOpenSettings:$,onOpenShortcuts:L,onOpenAbout:()=>U(!0),onOpenUpdate:Me,showRuntimeButtons:!F,showUpdateButton:ae}),s.jsx(qd,{open:C,onOpenChange:k,info:ce.info,downloading:ce.downloading,downloaded:ce.downloaded,progress:ce.progress,error:ce.error,onDownload:ce.downloadUpdate,onRestart:ce.restartToUpdate,runtimeType:ce.runtimeType}),s.jsx(Av,{open:!!Te,onOpenChange:je=>{je||g(null)},project:Te,onSave:Z}),s.jsx(Wp,{open:w,onOpenChange:N,onWorktreeCreated:(je,ot)=>{if(Ae.getState().closeMainSurfaces(),e&&X(!1),ot?.sessionId){J(ot.sessionId,je);return}ge({directoryOverride:je,preserveDirectoryOverride:!0})}})]})})},gk=c.memo(pk),Hn=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,mn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},bk=()=>{const{t}=ht(),[e,n]=c.useState(!1),[r,i]=c.useState(!1),[o,l]=c.useState(null),[a,d]=c.useState([]),[u,m]=c.useState(!1),[h,y]=c.useState(!1),[b,S]=c.useState(!1),[v,g]=c.useState(!1),[f,x]=c.useState(new Set),p=qe(pe=>pe.getWorktreeMetadata),w=qe(pe=>pe.newSessionDraft),N=qe(pe=>pe.setNewSessionDraftTarget),C=qe(pe=>pe.setDraftBootstrapPendingDirectory),k=Ch,A=Ah,D=qe(pe=>pe.deleteSessions),P=qe(pe=>pe.archiveSessions),M=Ae(pe=>pe.showDeletionDialog),z=Ae(pe=>pe.setShowDeletionDialog),I=ss(pe=>pe.currentDirectory),V=ss(pe=>pe.homeDirectory),T=ss(pe=>pe.isHomeReady),_=Ht(pe=>pe.projects),O=Ht(pe=>pe.activeProjectId),{isMobile:j,isTablet:E,hasTouchInput:L}=zn(),U=j||E||L,X=c.useMemo(()=>{const Pe=(O?_.find(de=>de.id===O)??null:null)?.path??I;return mn(Pe)},[O,I,_]),Q=c.useCallback(pe=>{const de=mn(pe.projectDirectory)||X;return{id:(_.find(fe=>mn(fe.path)===de)??null)?.id??`path:${de}`,path:de}},[X,_]),me=v&&f.size>0,re=c.useMemo(()=>{const pe=o?.worktree;return pe&&typeof pe.branch=="string"&&pe.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:Pe})=>typeof Pe.branch=="string"&&Pe.branch.trim().length>0)},[o?.worktree,a]),G=o?.mode==="worktree",ee=G,ue=b||!G||!re,W=b||!G;c.useEffect(()=>{r||!T||_.length>0||(i(!0),n(!0))},[r,T,_.length]);const ne=c.useCallback(pe=>{l({sessions:pe.sessions,dateLabel:pe.dateLabel,mode:pe.mode??"session",worktree:pe.worktree??null})},[]),Y=c.useCallback(()=>{l(null),d([]),m(!1),y(!1),S(!1),g(!1),x(new Set)},[]),F=c.useCallback(async pe=>{if(pe.sessions.length===0)return;if(pe.sessions.length===1){const fe=pe.sessions[0];await k(fe.id)?Oe.success(t("sessions.sidebar.session.delete.success")):Oe.error(t("sessions.sidebar.session.delete.error"));return}const Pe=pe.sessions.map(fe=>fe.id),{deletedIds:de,failedIds:he}=await D(Pe);if(de.length>0){const fe=he.length>0?he.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:he.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:he.length}):pe.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:pe.dateLabel}):void 0;Oe.success(de.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:de.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:de.length}),{description:Hn(fe)})}he.length>0&&Oe.error(he.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:he.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:he.length}),{description:Hn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,D,t]);c.useEffect(()=>yn.onDeleteRequest(pe=>{if(!M&&(pe.mode??"session")==="session"){F(pe);return}ne(pe)}),[ne,M,F]),c.useEffect(()=>yn.onDirectoryRequest(()=>{n(!0)}),[]),c.useEffect(()=>{if(!o){d([]),m(!1),y(!1),g(!1),x(new Set);return}const pe=o.sessions.map(he=>{const fe=p(he.id);return fe?{session:he,metadata:fe}:null}).filter(he=>!!he);d(pe),m(!1),g(!1),x(new Set);const Pe=new Map;if(o.worktree?.path&&Pe.set(mn(o.worktree.path),o.worktree),pe.forEach(({metadata:he})=>{he.path&&Pe.set(mn(he.path),he)}),Pe.size===0){g(!0);return}let de=!1;return(async()=>{const he=new Map,fe=new Set;await Promise.all(Array.from(Pe.entries()).map(async([B,H])=>{try{const ke=await Nh(H.path);he.set(B,ke),ke?.isDirty&&fe.add(B)}catch{H.status&&(he.set(B,H.status),H.status.isDirty&&fe.add(B))}})).catch(B=>{console.warn("Failed to inspect worktree status before deletion:",B)}),!de&&(x(fe),g(!0),l(B=>{if(!B?.worktree?.path)return B;const H=mn(B.worktree.path),ke=he.get(H);if(!ke)return B;const Se=B.worktree.status;return Se?.isDirty===ke.isDirty&&Se?.ahead===ke.ahead&&Se?.behind===ke.behind&&Se?.upstream===ke.upstream?B:{...B,worktree:{...B.worktree,status:ke}}}),d(B=>B.map(H=>{const ke=mn(H.metadata.path),Se=he.get(ke);return Se?{session:H.session,metadata:{...H.metadata,status:Se}}:H})))})(),()=>{de=!0}},[o,p]),c.useEffect(()=>{re||m(!1)},[re]);const J=c.useCallback(async(pe,Pe)=>{const de=u&&re,he=Q(pe),fe=mn(pe.path),B=mn(he.path);try{await bd(he,pe,{deleteRemoteBranch:de,deleteLocalBranch:Pe});const H=mn(w?.directoryOverride);return w?.open&&fe&&H===fe&&B&&(C(null),N({projectId:he.id,directoryOverride:B},{force:!0})),mn(I)===fe&&B&&ss.getState().setDirectory(B,{showOverlay:!1}),!0}catch(H){return Oe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Hn(H instanceof Error?H.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[re,I,u,Q,w?.directoryOverride,w?.open,C,N,t]),ie=c.useCallback((pe,Pe)=>{const de=u&&re;(async()=>{if(!await J(pe,Pe))return;const fe=t(de?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Oe.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Hn(fe)})})()},[re,u,J,t]),xe=c.useCallback(async()=>{if(o){S(!0);try{const pe=ee,Pe=pe&&u,de=pe&&h;if(o.sessions.length===0&&G&&o.worktree){ie(o.worktree,de),Y();return}if(o.sessions.length===1){const he=o.sessions[0];if(!(G?await A(he.id):await k(he.id))){Oe.error(t(G?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),S(!1);return}const B=!G&&pe?t(Pe?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Oe.success(t(G?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Hn(B),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const he=o.sessions.map(H=>H.id);let fe=[],B=[];if(G){const H=await P(he);fe=H.archivedIds,B=H.failedIds}else{const H=await D(he);fe=H.deletedIds,B=H.failedIds}if(G&&o.worktree&&B.length===0&&ie(o.worktree,de),fe.length>0){const H=!G&&pe?t(Pe?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Se=[B.length>0?G?B.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:B.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:B.length}):B.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:B.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:B.length}):o.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:o.dateLabel}):void 0,H].filter(Boolean).join(" ");Oe.success(G?fe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:fe.length}):fe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:fe.length}),{description:Hn(Se||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(B.length>0&&(Oe.error(G?B.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:B.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:B.length}):B.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:B.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:B.length}),{description:Hn(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),fe.length===0)){S(!1);return}}G&&o.sessions.length===1&&o.worktree&&ie(o.worktree,de),Y()}finally{S(!1)}}},[o,u,h,k,D,A,P,Y,ee,G,ie,t]),ge=o?.worktree??a[0]?.metadata??null,Ce=o?o.mode==="worktree"?o.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):o.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:o.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:o.sessions.length}):o.sessions.length===1?o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):o.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:o.sessions.length,dateLabel:o.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:o.sessions.length}):"",Re=o?s.jsxs("div",{className:Ie(G?"space-y-3":"space-y-2"),children:[o.sessions.length>0&&s.jsxs("div",{className:Ie(G?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[G&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:o.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:o.sessions.length})]}),s.jsxs("ul",{className:Ie(G?"mt-2 space-y-1":"space-y-0.5"),children:[o.sessions.slice(0,5).map(pe=>s.jsxs("li",{className:Ie(G?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:Ie(!G&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:pe.title||t("sessions.sidebar.session.untitled")})]},pe.id)),o.sessions.length>5&&s.jsx("li",{className:Ie(G?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:o.sessions.length-5})})]})]}),G?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ge?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ge.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ge?Ur(ge.path,V):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),me&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,ce=G?re?s.jsxs("button",{type:"button",onClick:()=>{ue||m(pe=>!pe)},disabled:ue,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ue?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ye=G?s.jsxs("button",{type:"button",onClick:()=>{W||y(pe=>!pe)},disabled:W,className:Ie("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",W?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[h?s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,be=G?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ye,ce]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{variant:"ghost",onClick:Y,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",onClick:xe,disabled:b,children:t(b?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>z(!M),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":!M,children:[M?s.jsx(R,{name:"checkbox-blank",className:"size-4"}):s.jsx(R,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{variant:"ghost",onClick:Y,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(at,{variant:"destructive",onClick:xe,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),te=G?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):o?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[U?s.jsx(ri,{open:!!o,onClose:()=>{b||Y()},title:te,footer:s.jsx("div",{className:"flex justify-end gap-2",children:be}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Ce&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Ce}),Re]})}):s.jsx(Ns,{open:!!o,onOpenChange:pe=>{if(!pe){if(b)return;Y()}},children:s.jsxs(As,{className:Ie(G?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Hs,{children:[s.jsxs(Rs,{className:Ie(G&&"flex items-center gap-2"),children:[G&&s.jsx(R,{name:"delete-bin",className:"h-5 w-5"}),te]}),Ce&&s.jsx(Ms,{children:Ce})]}),s.jsx("div",{className:Ie(G&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:Re}),s.jsx(Sn,{className:"mt-2 gap-2 pt-1 pb-1",children:be})]})}),s.jsx(zp,{open:e,onOpenChange:n})]})};function xk(t){const e=Ye.c(64),{t:n}=ht(),{value:r,onMoveSessionOnly:i,onMoveAllChanges:o,onCancel:l}=t,a=!!r;let d;e[0]!==l?(d=O=>{O||l()},e[0]=l,e[1]=d):d=e[1];let u;e[2]!==n?(u=n("sessions.sidebar.session.moveToWorktree.confirm.title"),e[2]=n,e[3]=u):u=e[3];let m;e[4]!==u?(m=s.jsx(Rs,{children:u}),e[4]=u,e[5]=m):m=e[5];const h=r?.dirtyFileCount??0;let y;e[6]!==n||e[7]!==h?(y=n("sessions.sidebar.session.moveToWorktree.confirm.changedFiles",{count:h}),e[6]=n,e[7]=h,e[8]=y):y=e[8];let b;e[9]!==n?(b=n("sessions.sidebar.session.moveToWorktree.confirm.ownership"),e[9]=n,e[10]=b):b=e[10];let S;e[11]!==y||e[12]!==b?(S=s.jsxs(Ms,{children:[y," ",b]}),e[11]=y,e[12]=b,e[13]=S):S=e[13];let v;e[14]!==m||e[15]!==S?(v=s.jsxs(Hs,{children:[m,S]}),e[14]=m,e[15]=S,e[16]=v):v=e[16];let g;e[17]!==n?(g=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnlyHelp"),e[17]=n,e[18]=g):g=e[18];let f;e[19]!==g?(f=s.jsx("p",{children:g}),e[19]=g,e[20]=f):f=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.session.moveToWorktree.confirm.allChangesHelp"),e[21]=n,e[22]=x):x=e[22];let p;e[23]!==x?(p=s.jsx("p",{children:x}),e[23]=x,e[24]=p):p=e[24];let w;e[25]!==n||e[26]!==r?(w=r&&r.stagedFileCount>0?s.jsx("p",{"data-session-worktree-move-staged-warning":"true",children:n("sessions.sidebar.session.moveToWorktree.confirm.stagedWarning")}):null,e[25]=n,e[26]=r,e[27]=w):w=e[27];let N;e[28]!==n?(N=n("sessions.sidebar.session.moveToWorktree.confirm.baseWarning"),e[28]=n,e[29]=N):N=e[29];let C;e[30]!==N?(C=s.jsx("p",{children:N}),e[30]=N,e[31]=C):C=e[31];let k;e[32]!==f||e[33]!==p||e[34]!==w||e[35]!==C?(k=s.jsxs("div",{className:"space-y-2 typography-ui-label text-muted-foreground",children:[f,p,w,C]}),e[32]=f,e[33]=p,e[34]=w,e[35]=C,e[36]=k):k=e[36];let A;e[37]!==n?(A=n("sessions.sidebar.session.moveToWorktree.confirm.cancel"),e[37]=n,e[38]=A):A=e[38];let D;e[39]!==l||e[40]!==A?(D=s.jsx(at,{type:"button",variant:"neutral","data-session-worktree-move-action":"cancel",onClick:l,children:A}),e[39]=l,e[40]=A,e[41]=D):D=e[41];let P;e[42]!==n?(P=n("sessions.sidebar.session.moveToWorktree.confirm.allChanges"),e[42]=n,e[43]=P):P=e[43];let M;e[44]!==o||e[45]!==P?(M=s.jsx(at,{type:"button",variant:"outline","data-session-worktree-move-action":"all-changes",onClick:o,children:P}),e[44]=o,e[45]=P,e[46]=M):M=e[46];let z;e[47]!==n?(z=n("sessions.sidebar.session.moveToWorktree.confirm.sessionOnly"),e[47]=n,e[48]=z):z=e[48];let I;e[49]!==i||e[50]!==z?(I=s.jsx(at,{type:"button",autoFocus:!0,"data-session-worktree-move-action":"session-only",onClick:i,children:z}),e[49]=i,e[50]=z,e[51]=I):I=e[51];let V;e[52]!==D||e[53]!==M||e[54]!==I?(V=s.jsxs(Sn,{className:"gap-2 sm:justify-end",children:[D,M,I]}),e[52]=D,e[53]=M,e[54]=I,e[55]=V):V=e[55];let T;e[56]!==k||e[57]!==V||e[58]!==v?(T=s.jsxs(As,{id:"session-worktree-move-confirm-dialog",showCloseButton:!1,className:"max-w-md gap-5",children:[v,k,V]}),e[56]=k,e[57]=V,e[58]=v,e[59]=T):T=e[59];let _;return e[60]!==a||e[61]!==d||e[62]!==T?(_=s.jsx(Ns,{open:a,onOpenChange:d,children:T}),e[60]=a,e[61]=d,e[62]=T,e[63]=_):_=e[63],_}function pm(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return mu.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function yk(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},i=mu.CronExpressionParser.parse(t,r),o=[];for(let l=0;l<n;l+=1){const a=i.next();a&&o.push(a.toDate())}return o}catch{return[]}}const wk=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],Sk={"Europe/Kiev":"Europe/Kyiv","Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Rangoon":"Asia/Yangon","Asia/Katmandu":"Asia/Kathmandu","America/Godthab":"America/Nuuk","Atlantic/Faeroe":"Atlantic/Faroe","Pacific/Enderbury":"Pacific/Kanton"},Xn=t=>Sk[t]??t,gm=[0,1,2,3,4,5,6],Ec="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",fa=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(Xn))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],Rc=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Mo=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),i=Number(e[3]),o=new Date(n,r-1,i);return Number.isNaN(o.getTime())||o.getFullYear()!==n||o.getMonth()!==r-1||o.getDate()!==i?null:o},Mc=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},vk=(t,e,n)=>{const r=Mo(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Oc=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),jk=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,a=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),u=[];for(let m=0;m<42;m+=1){const h=m-l+1;if(h<=0){const y=d+h;u.push({date:new Date(n,r-1,y),inCurrentMonth:!1});continue}if(h>a){u.push({date:new Date(n,r+1,h-a),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,h),inCurrentMonth:!0})}return u},kk=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],i=n>=12?"PM":"AM",o=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(o).padStart(2,"0"),minute:r,meridiem:i}},Kn=(t,e,n)=>{const r=Number(t),i=Number(e),o=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(i)?Math.min(59,Math.max(0,i)):0;let a=o%12;return n==="PM"&&(a+=12),`${String(a).padStart(2,"0")}:${String(l).padStart(2,"0")}`},kr=(t,e)=>{const{max:n,min:r=0,loop:i=!1}=e;let o=Number.parseInt(t,10);return Number.isFinite(o)?(i?(o>n&&(o=r),o<r&&(o=n)):(o>n&&(o=n),o<r&&(o=r)),String(o).padStart(2,"0")):"00"},Bc=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:kr(t,{min:1,max:12}),So=t=>/^[0-5][0-9]$/.test(t)?t:kr(t,{max:59}),Ck=(t,e)=>kr(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Fc=(t,e)=>kr(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),Nk=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},Ak=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},Dk=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return gm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},Pk=(t,e)=>[...t.slice(e),...t.slice(0,e)],Fs=t=>{const e=Ye.c(6),{htmlFor:n,required:r,children:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=o):o=e[1];let l;return e[2]!==i||e[3]!==n||e[4]!==o?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,o]})}),e[2]=i,e[3]=n,e[4]=o,e[5]=l):l=e[5],l},_c=t=>{const e=Ye.c(84),{value:n,onChange:r,use24Hour:i,hourAriaLabel:o,minuteAriaLabel:l,periodAriaLabel:a,amLabel:d,pmLabel:u}=t;let m;e[0]!==n?(m=kk(n),e[0]=n,e[1]=m):m=e[1];const h=m,y=it.useRef(null),b=it.useRef(null),[S,v]=it.useState(null),[g,f]=it.useState(null),x=it.useRef(null),p=it.useRef(null);let w;e[2]===Symbol.for("react.memo_cache_sentinel")?(w=te=>{x.current=te,v(te)},e[2]=w):w=e[2];const N=w;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=te=>{p.current=te,f(te)},e[3]=C):C=e[3];const k=C,A=Bk,D=Fk,P=_k;let M;e[4]!==r||e[5]!==h.meridiem||e[6]!==h.minute||e[7]!==i?(M=te=>{const pe=te.replace(/\D/g,"").slice(0,2);N(pe),pe.length===2&&(r(i?P(A(pe),h.minute):Kn(Bc(pe),h.minute,h.meridiem)),N(null),b.current?.focus())},e[4]=r,e[5]=h.meridiem,e[6]=h.minute,e[7]=i,e[8]=M):M=e[8];const z=M;let I;e[9]!==r||e[10]!==h.meridiem||e[11]!==h.minute||e[12]!==i?(I=()=>{const te=x.current;if(te!==null&&(N(null),te.length!==0)){if(i){r(P(A(te.padStart(2,"0")),h.minute));return}r(Kn(Bc(te.padStart(2,"0")),h.minute,h.meridiem))}},e[9]=r,e[10]=h.meridiem,e[11]=h.minute,e[12]=i,e[13]=I):I=e[13];const V=I;let T;e[14]!==r||e[15]!==h.hour12||e[16]!==h.hour24||e[17]!==h.meridiem||e[18]!==i?(T=te=>{const pe=te.replace(/\D/g,"").slice(0,2);k(pe),pe.length===2&&(r(i?P(h.hour24,So(pe)):Kn(h.hour12,So(pe),h.meridiem)),k(null))},e[14]=r,e[15]=h.hour12,e[16]=h.hour24,e[17]=h.meridiem,e[18]=i,e[19]=T):T=e[19];const _=T;let O;e[20]!==r||e[21]!==h.hour12||e[22]!==h.hour24||e[23]!==h.meridiem||e[24]!==i?(O=()=>{const te=p.current;te!==null&&(k(null),te.length!==0&&r(i?P(h.hour24,So(te.padStart(2,"0"))):Kn(h.hour12,So(te.padStart(2,"0")),h.meridiem)))},e[20]=r,e[21]=h.hour12,e[22]=h.hour24,e[23]=h.meridiem,e[24]=i,e[25]=O):O=e[25];const j=O;let E;e[26]!==r||e[27]!==h.hour12||e[28]!==h.hour24||e[29]!==h.meridiem||e[30]!==h.minute||e[31]!==i?(E=te=>r(i?P(D(h.hour24,te),h.minute):Kn(Ck(h.hour12,te),h.minute,h.meridiem)),e[26]=r,e[27]=h.hour12,e[28]=h.hour24,e[29]=h.meridiem,e[30]=h.minute,e[31]=i,e[32]=E):E=e[32];const L=E;let U;e[33]!==r||e[34]!==h.hour12||e[35]!==h.hour24||e[36]!==h.meridiem||e[37]!==h.minute||e[38]!==i?(U=te=>r(i?P(h.hour24,Fc(h.minute,te)):Kn(h.hour12,Fc(h.minute,te),h.meridiem)),e[33]=r,e[34]=h.hour12,e[35]=h.hour24,e[36]=h.meridiem,e[37]=h.minute,e[38]=i,e[39]=U):U=e[39];const X=U;let Q;e[40]!==r||e[41]!==h.hour12||e[42]!==h.meridiem||e[43]!==h.minute?(Q=te=>{te!==h.meridiem&&r(Kn(h.hour12,h.minute,te))},e[40]=r,e[41]=h.hour12,e[42]=h.meridiem,e[43]=h.minute,e[44]=Q):Q=e[44];const me=Q;let re;e[45]!==V||e[46]!==L?(re=te=>{if(te.key==="ArrowRight"){te.preventDefault(),V(),b.current?.focus();return}(te.key==="ArrowUp"||te.key==="ArrowDown")&&(te.preventDefault(),N(null),L(te.key==="ArrowUp"?1:-1))},e[45]=V,e[46]=L,e[47]=re):re=e[47];const G=re;let ee;e[48]!==j||e[49]!==X?(ee=te=>{if(te.key==="ArrowLeft"&&(te.currentTarget.selectionStart??0)===0){te.preventDefault(),j(),y.current?.focus();return}(te.key==="ArrowUp"||te.key==="ArrowDown")&&(te.preventDefault(),k(null),X(te.key==="ArrowUp"?1:-1))},e[48]=j,e[49]=X,e[50]=ee):ee=e[50];const ue=ee,W=i?"px-2":"pl-2 pr-1";let ne;e[51]!==W?(ne=Ie("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",W),e[51]=W,e[52]=ne):ne=e[52];const Y=S??(i?h.hour24:h.hour12);let F;e[53]!==z?(F=te=>z(te.target.value),e[53]=z,e[54]=F):F=e[54];let J;e[55]===Symbol.for("react.memo_cache_sentinel")?(J=()=>N(""),e[55]=J):J=e[55];let ie;e[56]!==V||e[57]!==o||e[58]!==G||e[59]!==Y||e[60]!==F?(ie=s.jsx("input",{ref:y,inputMode:"numeric",value:Y,onChange:F,onKeyDown:G,onFocus:J,onBlur:V,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=V,e[57]=o,e[58]=G,e[59]=Y,e[60]=F,e[61]=ie):ie=e[61];let xe;e[62]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=xe):xe=e[62];const ge=g??h.minute;let Ce;e[63]!==_?(Ce=te=>_(te.target.value),e[63]=_,e[64]=Ce):Ce=e[64];let Re;e[65]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>k(""),e[65]=Re):Re=e[65];let ce;e[66]!==j||e[67]!==l||e[68]!==ue||e[69]!==ge||e[70]!==Ce?(ce=s.jsx("input",{ref:b,inputMode:"numeric",value:ge,onChange:Ce,onKeyDown:ue,onFocus:Re,onBlur:j,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=j,e[67]=l,e[68]=ue,e[69]=ge,e[70]=Ce,e[71]=ce):ce=e[71];let ye;e[72]!==d||e[73]!==h.meridiem||e[74]!==a||e[75]!==u||e[76]!==me||e[77]!==i?(ye=i?null:s.jsxs($s,{value:h.meridiem,onValueChange:te=>me(te),children:[s.jsx(Ws,{"aria-label":a,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Is,{})}),s.jsxs(zs,{children:[s.jsx(ns,{value:"AM",children:d}),s.jsx(ns,{value:"PM",children:u})]})]}),e[72]=d,e[73]=h.meridiem,e[74]=a,e[75]=u,e[76]=me,e[77]=i,e[78]=ye):ye=e[78];let be;return e[79]!==ne||e[80]!==ie||e[81]!==ce||e[82]!==ye?(be=s.jsxs("div",{className:ne,children:[ie,xe,ce,ye]}),e[79]=ne,e[80]=ie,e[81]=ce,e[82]=ye,e[83]=be):be=e[83],be},Lc=t=>new Date(t.getFullYear(),t.getMonth(),1),Tk=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},$c=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),Ik=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(i=>typeof i=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(i)).map(i=>i.trim()),r=Array.from(new Set(n)).sort((i,o)=>i.localeCompare(o));return r.length>0?r:["09:00"]},Wc=(t,e)=>{const n=Xn(Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC");return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:Ik(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Rc(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:Xn(t.schedule.timezone||n),cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null,permissionAutoAccept:t.execution.permissionAutoAccept===!0},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:Rc(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null,permissionAutoAccept:!1}}},Ek=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!pm(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},Rk=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},Mk=t=>{const e=Ye.c(64),{draft:n,setDraft:r,locale:i,t:o}=t,l=n.schedule.cronExpression;let a;e[0]!==l?(a=l.trim()?pm(l):null,e[0]=l,e[1]=a):a=e[1];const d=a;let u;e:{if(!d?.valid||!l.trim()){let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=[],e[2]=E):E=e[2],u=E;break e}let j;e[3]!==l||e[4]!==n.schedule.timezone?(j=yk(l,n.schedule.timezone),e[3]=l,e[4]=n.schedule.timezone,e[5]=j):j=e[5],u=j}const m=u;let h;e[6]!==n.schedule.timezone||e[7]!==i?(h=j=>new Intl.DateTimeFormat(i,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(j),e[6]=n.schedule.timezone,e[7]=i,e[8]=h):h=e[8];const y=h;let b;e[9]!==o?(b=o("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=o,e[10]=b):b=e[10];let S;e[11]!==b?(S=s.jsx(Fs,{htmlFor:"sched-cron",required:!0,children:b}),e[11]=b,e[12]=S):S=e[12];let v;e[13]!==r?(v=j=>r(E=>({...E,schedule:{...E.schedule,cronExpression:j.target.value}})),e[13]=r,e[14]=v):v=e[14];let g;e[15]!==o?(g=o("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=o,e[16]=g):g=e[16];let f;e[17]!==l||e[18]!==v||e[19]!==g?(f=s.jsx(Nn,{id:"sched-cron",value:l,onChange:v,placeholder:g,className:"w-full max-w-xs font-mono"}),e[17]=l,e[18]=v,e[19]=g,e[20]=f):f=e[20];let x;e[21]!==l||e[22]!==d||e[23]!==o?(x=d&&!d.valid&&l.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:o("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=l,e[22]=d,e[23]=o,e[24]=x):x=e[24];let p;e[25]!==S||e[26]!==f||e[27]!==x?(p=s.jsxs("div",{className:"flex flex-col gap-1",children:[S,f,x]}),e[25]=S,e[26]=f,e[27]=x,e[28]=p):p=e[28];let w;e[29]!==y||e[30]!==m||e[31]!==o?(w=m.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:m.map(y).join(", ")})]}):null,e[29]=y,e[30]=m,e[31]=o,e[32]=w):w=e[32];let N;e[33]!==o?(N=o("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=o,e[34]=N):N=e[34];let C;e[35]!==N?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[35]=N,e[36]=C):C=e[36];let k;e[37]!==r||e[38]!==o?(k=wk.map(j=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(E=>({...E,schedule:{...E.schedule,cronExpression:j.expression}})),children:[s.jsx("span",{className:"font-mono",children:j.expression}),s.jsx("span",{className:"text-muted-foreground",children:o(j.labelKey)})]},j.expression)),e[37]=r,e[38]=o,e[39]=k):k=e[39];let A;e[40]!==k?(A=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:k}),e[40]=k,e[41]=A):A=e[41];let D;e[42]!==C||e[43]!==A?(D=s.jsxs("div",{className:"flex flex-col gap-1",children:[C,A]}),e[42]=C,e[43]=A,e[44]=D):D=e[44];let P;e[45]!==o?(P=o("sessions.scheduledTasks.editor.timezone.label"),e[45]=o,e[46]=P):P=e[46];let M;e[47]!==P?(M=s.jsx(Fs,{children:P}),e[47]=P,e[48]=M):M=e[48];let z;e[49]!==r?(z=j=>{r(E=>({...E,schedule:{...E.schedule,timezone:j}}))},e[49]=r,e[50]=z):z=e[50];let I;e[51]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Ws,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Is,{})}),e[51]=I):I=e[51];let V;e[52]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(zs,{children:fa.map(Lk)}),e[52]=V):V=e[52];let T;e[53]!==n.schedule.timezone||e[54]!==z?(T=s.jsxs($s,{value:n.schedule.timezone,onValueChange:z,children:[I,V]}),e[53]=n.schedule.timezone,e[54]=z,e[55]=T):T=e[55];let _;e[56]!==M||e[57]!==T?(_=s.jsxs("div",{className:"flex flex-col gap-1",children:[M,T]}),e[56]=M,e[57]=T,e[58]=_):_=e[58];let O;return e[59]!==p||e[60]!==w||e[61]!==D||e[62]!==_?(O=s.jsxs("div",{className:"flex flex-col gap-3",children:[p,w,D,_]}),e[59]=p,e[60]=w,e[61]=D,e[62]=_,e[63]=O):O=e[63],O};function Ok(t){const{open:e,task:n,onOpenChange:r,onSave:i}=t,{t:o,locale:l}=ht(),a=Kt($=>$.loadProviders),d=Kt($=>$.loadAgents),u=Kt($=>$.providers),m=Kt($=>$.currentProviderId),h=Kt($=>$.currentModelId),y=Kt($=>$.currentVariant||""),b=Kt($=>$.currentAgentName||""),S=Ae($=>$.timeFormatPreference),v=Ae($=>$.weekStartPreference),g=Ae($=>$.isMobile),[f,x]=it.useState(()=>Wc(n,{providerID:m,modelID:h,variant:y,agent:b})),[p,w]=it.useState(!1),[N,C]=it.useState(!1),[k,A]=it.useState(!1),[D,P]=it.useState(""),[M,z]=it.useState(!1),[I,V]=it.useState(""),[T,_]=it.useState(!1),[O,j]=it.useState(""),[E,L]=it.useState(()=>{const $=Mo(n?.schedule?.date||"")||new Date;return new Date($.getFullYear(),$.getMonth(),1)}),U=it.useRef(null),X=it.useRef(null),Q=it.useRef(null),me=it.useRef(null),re=it.useRef(null),G=it.useMemo(()=>Ak(l),[l]),ee=it.useMemo(()=>Nk(l),[l]),ue=it.useMemo(()=>S==="24h"?!0:S==="12h"?!1:G,[S,G]),W=it.useMemo(()=>v==="sunday"?0:v==="monday"?1:ee,[v,ee]),ne=it.useMemo(()=>{const $=Dk(l);return Pk(gm.map(ae=>({value:ae,label:$[ae]||""})),W)},[l,W]);it.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,a,d]),it.useEffect(()=>{if(!e)return;x(Wc(n,{providerID:m,modelID:h,variant:y,agent:b}));const $=Mo(n?.schedule?.date||"")||new Date;L(new Date($.getFullYear(),$.getMonth(),1)),C(!1),z(!1),A(!1),V(""),P("")},[e,n,m,h,y,b]),it.useEffect(()=>{if(!N)return;const $=ae=>{U.current&&!U.current.contains(ae.target)&&C(!1)};return document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[N]);const Y=it.useMemo(()=>{const ae=u.find(se=>se.id===f.execution.providerID)?.models?.find(se=>se.id===f.execution.modelID);return ae?.variants?Object.keys(ae.variants):[]},[u,f.execution.providerID,f.execution.modelID]),F=Y.length>0,J=it.useMemo(()=>!F||!f.execution.variant?"__default":Y.includes(f.execution.variant)?f.execution.variant:"__default",[f.execution.variant,F,Y]);it.useEffect(()=>{F||!f.execution.variant||x($=>({...$,execution:{...$.execution,variant:""}}))},[F,f.execution.variant]);const ie=it.useCallback(($,ae)=>{x(se=>{const we=new Set(se.schedule.weekdays);return ae?we.add($):we.delete($),{...se,schedule:{...se.schedule,weekdays:Array.from(we).sort((Ke,Qe)=>Ke-Qe)}}})},[]),xe=it.useCallback(($,ae)=>{x(se=>{const we=se.schedule.times.slice();return we[$]=ae,{...se,schedule:{...se.schedule,times:we}}})},[]),ge=it.useCallback($=>{x(ae=>{const se=ae.schedule.times.filter((we,Ke)=>Ke!==$);return{...ae,schedule:{...ae.schedule,times:se.length>0?se:["09:00"]}}})},[]),Ce=it.useCallback(()=>{x($=>({...$,schedule:{...$.schedule,times:[...$.schedule.times,"12:00"]}}))},[]),Re=it.useMemo(()=>Tk(),[]),ce=it.useMemo(()=>Lc(Re),[Re]),ye=it.useMemo(()=>{const $=Mo(f.schedule.onceDate);return $?$c($,Re)?o("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format($):null},[f.schedule.onceDate,l,o,Re]),be=it.useMemo(()=>Lc(E).getTime()<=ce.getTime(),[E,ce]),te=it.useMemo(()=>ne.map($=>$.label),[ne]),pe=it.useCallback($=>{x(ae=>({...ae,schedule:{...ae.schedule,onceDate:$}}))},[]),Pe=it.useCallback(($,ae)=>{if($.startsWith("/")){const Qe=$.indexOf(" "),He=$.indexOf(`
|
|
920
|
-
`),le=Math.min(Qe===-1?$.length:Qe,He===-1?$.length:He);if(ae<=le&&Qe===-1){V($.substring(1,le)),z(!0),A(!1),_(!1);return}}z(!1);const se=$.substring(0,ae),we=se.lastIndexOf("#");if(we!==-1){const Qe=we>0?se[we-1]:null,He=se.substring(we+1);if((!Qe||/\s/.test(Qe))&&!He.includes(" ")&&!He.includes(`
|
|
921
|
-
`)){j(He),_(!0),A(!1);return}}_(!1);const Ke=se.lastIndexOf("@");if(Ke!==-1){const Qe=Ke>0?se[Ke-1]:null,He=se.substring(Ke+1);(!Qe||/\s/.test(Qe))&&!He.includes(" ")&&!He.includes(`
|
|
922
|
-
`)?(P(He),A(!0)):A(!1);return}A(!1)},[]),de=it.useCallback($=>{x(ae=>({...ae,execution:{...ae.execution,prompt:$}}))},[]),he=it.useCallback($=>{const ae=f.execution.prompt,we=X.current?.selectionStart??ae.length,Qe=ae.substring(0,we).lastIndexOf("@"),He=$.relativePath&&$.relativePath.trim().length>0?$.relativePath.trim():$.path||$.name,le=Qe!==-1?Qe:we,K=`${ae.substring(0,le)}@${He} ${ae.substring(we)}`,ve=le+He.length+2;de(K),A(!1),P(""),requestAnimationFrame(()=>{const $e=X.current;$e&&($e.selectionStart=ve,$e.selectionEnd=ve,$e.focus()),Pe(K,ve)})},[f.execution.prompt,de,Pe]),fe=it.useCallback($=>{const ae=f.execution.prompt,we=X.current?.selectionStart??ae.length,Qe=ae.substring(0,we).lastIndexOf("@"),He=Qe!==-1?Qe:we,le=`${ae.substring(0,He)}@${$} ${ae.substring(we)}`,K=He+$.length+2;de(le),A(!1),P(""),requestAnimationFrame(()=>{const ve=X.current;ve&&(ve.selectionStart=K,ve.selectionEnd=K,ve.focus()),Pe(le,K)})},[f.execution.prompt,de,Pe]),B=it.useCallback($=>{const ae=`/${$.name} `;de(ae),z(!1),V(""),_(!1),requestAnimationFrame(()=>{const se=X.current;se&&(se.focus(),se.selectionStart=se.value.length,se.selectionEnd=se.value.length),Pe(ae,ae.length)})},[de,Pe]),H=it.useCallback(($,ae)=>{const se=f.execution.prompt,Ke=X.current?.selectionStart??se.length,He=se.substring(0,Ke).lastIndexOf("#"),le=He!==-1?He:Ke,K=`${se.substring(0,le)}#${ae} ${se.substring(Ke)}`,ve=le+ae.length+2;de(K),_(!1),j(""),requestAnimationFrame(()=>{const $e=X.current;$e&&($e.selectionStart=ve,$e.selectionEnd=ve,$e.focus()),Pe(K,ve)})},[f.execution.prompt,de,Pe]),ke=it.useCallback($=>{if(M&&me.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")){$.preventDefault(),me.current.handleKeyDown($.key);return}k&&Q.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),Q.current.handleKeyDown($.key)),T&&re.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),re.current.handleKeyDown($.key))},[M,k,T]),Se=it.useCallback(async()=>{const $=Ek(f,o);if($){Oe.error($);return}const ae={...f.id?{id:f.id}:{},name:f.name.trim(),enabled:f.enabled,schedule:{kind:f.schedule.kind,timezone:f.schedule.timezone.trim(),...f.schedule.kind==="cron"?{cron:f.schedule.cronExpression.trim()}:f.schedule.kind==="once"?{date:f.schedule.onceDate,time:f.schedule.onceTime}:{times:Rk(f.schedule.times),...f.schedule.kind==="weekly"?{weekdays:f.schedule.weekdays}:{}}},execution:{prompt:f.execution.prompt,providerID:f.execution.providerID,modelID:f.execution.modelID,...f.execution.variant.trim()?{variant:f.execution.variant.trim()}:{},...f.execution.agent.trim()?{agent:f.execution.agent.trim()}:{},...f.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...f.execution.goalEnabled?{goalEnabled:!0}:{},...f.execution.goalEnabled&&f.execution.goalTokenBudget?{goalTokenBudget:f.execution.goalTokenBudget}:{}},...f.state?{state:f.state}:{}};w(!0);try{await i(ae),r(!1)}catch(se){Oe.error(se instanceof Error?se.message:o("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{w(!1)}},[f,r,i,o]),Be=it.useId(),_e=it.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),Te=o(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),Z=o("sessions.scheduledTasks.editor.description"),Ne=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fs,{htmlFor:"sched-name",required:!0,children:o("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Nn,{id:"sched-name",value:f.name,onChange:$=>x(ae=>({...ae,name:$.target.value})),placeholder:o("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs($s,{value:f.schedule.kind,onValueChange:$=>{x(ae=>({...ae,schedule:{...ae.schedule,kind:$,...$==="cron"&&!ae.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Ws,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Is,{children:$=>o($==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":$==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":$==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(zs,{children:[s.jsx(ns,{value:"daily",children:o("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(ns,{value:"weekly",children:o("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(ns,{value:"once",children:o("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(ns,{value:"cron",children:o("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),f.schedule.kind==="cron"?s.jsx(Mk,{draft:f,setDraft:x,locale:l,t:o}):f.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:U,children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Ie(Od({size:"default"}),"w-fit max-w-full"),onClick:()=>C($=>!$),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(R,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:vk(f.schedule.onceDate,o("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),N?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>L($=>Oc($,-1)),"aria-label":o("sessions.scheduledTasks.editor.date.previousMonth"),disabled:be,children:s.jsx(R,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(E)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>L($=>Oc($,1)),"aria-label":o("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:te.map(($,ae)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:$},`${$}-${ae}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:jk(E,W).map(({date:$,inCurrentMonth:ae})=>{const se=Mc($),we=se===f.schedule.onceDate,Ke=$c($,Re),Qe=$.getTime()<Re.getTime(),He=we?"bg-interactive-selection text-interactive-selection-foreground":Qe?"text-muted-foreground/40":ae?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Qe||(pe(se),C(!1))},disabled:Qe,className:["h-8 rounded-md typography-ui-label",He,Ke&&!we?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Qe?"cursor-not-allowed opacity-45":""].join(" "),children:$.getDate()},se)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ye||""}),s.jsx(at,{type:"button",size:"xs",variant:"ghost",onClick:()=>{pe(Mc(Re)),L(new Date(Re.getFullYear(),Re.getMonth(),1))},children:o("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.time.label")}),s.jsx(_c,{value:f.schedule.onceTime,use24Hour:ue,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:$=>x(ae=>({...ae,schedule:{...ae.schedule,onceTime:$}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs($s,{value:f.schedule.timezone,onValueChange:$=>{x(ae=>({...ae,schedule:{...ae.schedule,timezone:$}}))},children:[s.jsx(Ws,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Is,{})}),s.jsx(zs,{children:fa.map($=>s.jsx(ns,{value:$,children:$},$))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[f.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ne.map($=>{const ae=f.schedule.weekdays.includes($.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",ae?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(hr,{checked:ae,onChange:se=>ie($.value,se),ariaLabel:$.label}),s.jsx("button",{type:"button",onClick:()=>ie($.value,!ae),className:"group-hover:text-foreground",children:$.label})]},$.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:f.schedule.times.map(($,ae)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_c,{value:$,use24Hour:ue,hourAriaLabel:o("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:o("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:o("sessions.scheduledTasks.editor.time.periodAria"),amLabel:o("sessions.scheduledTasks.editor.time.period.am"),pmLabel:o("sessions.scheduledTasks.editor.time.period.pm"),onChange:se=>xe(ae,se)}),f.schedule.times.length>1?s.jsx(at,{type:"button",size:"icon",variant:"ghost",onClick:()=>ge(ae),"aria-label":o("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null]},ae))}),s.jsx("div",{children:s.jsxs(at,{type:"button",size:"sm",variant:"outline",onClick:Ce,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",o("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs($s,{value:f.schedule.timezone,onValueChange:$=>{x(ae=>({...ae,schedule:{...ae.schedule,timezone:$}}))},children:[s.jsx(Ws,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Is,{})}),s.jsx(zs,{children:fa.map($=>s.jsx(ns,{value:$,children:$},$))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Fs,{required:!0,children:o("sessions.scheduledTasks.editor.model.label")}),s.jsx(Dh,{providerId:f.execution.providerID,modelId:f.execution.modelID,onChange:($,ae)=>{x(se=>({...se,execution:{...se.execution,providerID:$,modelID:ae,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs($s,{value:J,disabled:!F,onValueChange:$=>{x(ae=>({...ae,execution:{...ae.execution,variant:$==="__default"?"":$}}))},children:[s.jsx(Ws,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Is,{children:$=>$==="__default"?o("sessions.scheduledTasks.editor.thinkingLevel.default"):$})}),s.jsxs(zs,{children:[s.jsx(ns,{value:"__default",children:o("sessions.scheduledTasks.editor.thinkingLevel.default")}),Y.map($=>s.jsx(ns,{value:$,children:$},$))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Fs,{children:o("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Ph,{agentName:f.execution.agent,filter:$=>Md($.mode),onChange:$=>x(ae=>({...ae,execution:{...ae.execution,agent:$}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Fs,{htmlFor:"sched-prompt",required:!0,children:o("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(ur,{id:"sched-prompt",ref:X,value:f.execution.prompt,onChange:$=>{const ae=$.target.value;de(ae);const se=$.target.selectionStart??ae.length;Pe(ae,se)},onKeyDown:ke,rows:8,placeholder:o("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),M?s.jsx(Wd,{ref:me,searchQuery:I,onCommandSelect:B,onClose:()=>z(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(zd,{ref:Q,searchQuery:D,onFileSelect:he,onAgentSelect:fe,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,T?s.jsx(Vd,{ref:re,searchQuery:O,onSnippetSelect:H,onClose:()=>_(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),f.execution.goalEnabled?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(hr,{checked:f.execution.goalTokenBudget!==null,onChange:$=>x(ae=>({...ae,execution:{...ae.execution,goalTokenBudget:$?2e5:null}})),ariaLabel:o("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),f.execution.goalTokenBudget!==null?s.jsx(Th,{value:f.execution.goalTokenBudget,onValueChange:$=>{typeof $=="number"&&Number.isFinite($)&&$>0&&x(ae=>({...ae,execution:{...ae.execution,goalTokenBudget:Math.floor($)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),Me=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(hr,{checked:f.enabled,onChange:$=>x(ae=>({...ae,enabled:$})),ariaLabel:o("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:o("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Ec),onClick:()=>x($=>({...$,execution:{...$.execution,permissionAutoAccept:!$.execution.permissionAutoAccept}})),"aria-pressed":f.execution.permissionAutoAccept,"aria-label":o("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:f.execution.permissionAutoAccept?s.jsx(R,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(R,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(xt,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie(Ec,f.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>x($=>({...$,execution:{...$.execution,goalEnabled:!$.execution.goalEnabled}})),"aria-pressed":f.execution.goalEnabled,"aria-label":o("sessions.scheduledTasks.editor.goal.aria"),children:f.execution.goalEnabled?s.jsx(R,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(R,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(xt,{side:"top",sideOffset:6,children:o("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:p,children:o("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(at,{type:"button",size:"sm",onClick:Se,disabled:p,children:o(p?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(ri,{open:e,title:Te,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:$=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:Te}),$]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:Z})]}),footer:Me,children:Ne}):s.jsx(Ns,{open:e,onOpenChange:$=>{!$&&_e()||r($)},children:s.jsxs(As,{"aria-describedby":Be,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ms,{id:Be,className:"sr-only",children:Z}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Rs,{className:"typography-ui-label font-medium text-foreground",children:Te}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:Z})]})}),s.jsx(Ca,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ne})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Me})})]})})}function Bk(t){return kr(t,{min:0,max:23})}function Fk(t,e){return kr(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function _k(t,e){const n=Number(t),r=Number(e),i=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,o=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(i).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function Lk(t){return s.jsx(ns,{value:t,children:t},t)}const $k=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,i)=>r.localeCompare(i))},Wk=(t,e)=>{const n=$k(t).join(", ")||"--:--",r=i=>e(i===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":i===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":i===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":i===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":i===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":i===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":i===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:Xn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const i=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(o=>r(o)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:i,time:n,timezone:Xn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:i,time:n})}if(t.schedule.kind==="once"){const i=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),o=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:i,time:o,timezone:Xn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:i,time:o})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:Xn(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},zk=(t,e)=>!t||!Number.isFinite(t)?"":Ih(t,e),zc=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),i=6e4,o=60*i,l=24*o,a=n>=0;if(r<i)return e(a?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<o){const h=Math.round(r/i);return a?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:h}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:h})}if(r<l){const h=Math.floor(r/o),y=Math.round(r%o/i),b=y>0?`${h}h ${y}m`:`${h}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/l),u=Math.round(r%l/o),m=u>0?`${d}d ${u}h`:`${d}d`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},Vk={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},Uk=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function Hk(){const{t}=ht(),e=Ae(j=>j.isScheduledTasksDialogOpen),n=Ae(j=>j.setScheduledTasksDialogOpen),r=Ae(j=>j.isMobile),i=Ae(j=>j.timeFormatPreference),o=Ht(j=>j.projects),l=Ht(j=>j.getActiveProject()),a=ss(j=>j.homeDirectory),{currentTheme:d}=nr(),[u,m]=it.useState(""),[h,y]=it.useState([]),[b,S]=it.useState(!0),[v,g]=it.useState(!1),[f,x]=it.useState(null),[p,w]=it.useState(null),N=it.useMemo(()=>o.find(j=>j.id===u)||null,[o,u]),C=it.useCallback(j=>{const E=j.label?.trim()||Wn(j.path,a||void 0),L=j.icon?Pa[j.icon]:null,U=j.color?Ta[j.color]:void 0,X=L?s.jsx(R,{name:L,className:"h-3.5 w-3.5 shrink-0",style:U?{color:U}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:U?{color:U}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[j.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Ia,{project:{id:j.id,iconImage:j.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:X})}):X,s.jsx("span",{className:"truncate",children:E})]})},[a,d.metadata.variant,d.colors.surface.foreground]),k=it.useCallback(async(j,E)=>{if(!j){y([]);return}E?.silent||S(!0);try{const L=await eg(j);L.sort((U,X)=>{if(U.enabled!==X.enabled)return U.enabled?-1:1;const Q=U.name.localeCompare(X.name);return Q!==0?Q:(U.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(X.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),y(L)}catch(L){Oe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),E?.silent||y([])}finally{E?.silent||S(!1)}},[t]);it.useEffect(()=>{if(!e)return;const j=l?.id||o[0]?.id||"";m(j),j?k(j):(y([]),S(!1))},[e,l,o,k]),it.useEffect(()=>{if(!e)return;let j=null;const E=no(L=>{L.type==="scheduled-task-ran"&&L.projectId===u&&(j&&clearTimeout(j),j=setTimeout(()=>{k(u,{silent:!0})},400))});return()=>{j&&clearTimeout(j),E()}},[e,u,k]);const A=it.useCallback(async j=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Nl(u,j),await k(u),Oe.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,k,t]),D=it.useCallback(async(j,E)=>{if(u){w(j.id),y(L=>L.map(U=>U.id===j.id?{...U,enabled:E}:U));try{j.loopFile?await tg(u,j.id,E):await Nl(u,{...j,enabled:E}),await k(u,{silent:!0})}catch(L){Oe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(u,{silent:!0})}finally{w(null)}}},[u,k,t]),P=it.useCallback(async j=>{if(!(!u||!window.confirm(j.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:j.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:j.name})))){w(j.id);try{j.loopFile?await sg(u,j.id):await ng(u,j.id),await k(u,{silent:!0}),Oe.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(L){Oe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{w(null)}}},[u,k,t]),M=it.useCallback(j=>{if(!j.loopFile){x(j),g(!0);return}N?.path&&(n(!1),pn.getState().setSelectedPath(N.path,j.loopFile,{allowOutsideRoot:!0}),Ae.getState().openContextFile(N.path,j.loopFile))},[N?.path,n]),z=it.useCallback(async j=>{if(u){w(j.id);try{const{sessionId:E,persistError:L}=await rg(u,j.id);if(await Promise.all([k(u,{silent:!0}),Ba()]),L?Oe.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):Oe.success(t("sessions.scheduledTasks.dialog.toast.started")),E){const U=o.find(X=>X.id===u);qe.getState().setCurrentSession(E,U?.path??null)}}catch(E){Oe.error(E instanceof Error?E.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{w(null)}}},[u,o,k,t]),I=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs($s,{value:u||"__none",onValueChange:j=>{const E=j==="__none"?"":j;m(E),E?k(E):y([])},children:[s.jsx(Ws,{size:"lg",className:r?"w-full":void 0,children:N?s.jsx(Is,{children:C(N)}):s.jsx(Is,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(zs,{children:[o.length===0?s.jsx(ns,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,o.map(j=>s.jsx(ns,{value:j.id,children:C(j)},j.id))]})]})]}),V=()=>{x(null),g(!0)},T=j=>{m(j),j?k(j):y([])},_=s.jsx("div",{className:"min-h-[280px]",children:b?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):h.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(u?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:h.map(j=>{const E=p===j.id,L=j.state?.lastStatus||"idle",U=Vk[L],X=t(L==="success"?"sessions.scheduledTasks.dialog.status.success":L==="error"?"sessions.scheduledTasks.dialog.status.error":L==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Q=j.state?.nextRunAt,me=j.state?.lastRunAt;return s.jsxs("div",{className:Ie("rounded-lg border border-border p-4 transition-opacity",!j.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:j.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:Wk(j,t)}),j.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:j.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:j.loopFile})}):null]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),Q?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:zc(Q,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:zk(Q,i)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(R,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),L==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):me?s.jsxs(s.Fragment,{children:[U.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${U.tone})`},children:[s.jsx(R,{name:U.Icon,className:"h-3.5 w-3.5"}),X]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:zc(me,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),j.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:Uk("error"),children:[s.jsx(R,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:j.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Ie("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",j.enabled?"text-foreground":"text-muted-foreground",E&&"cursor-not-allowed opacity-50"),children:[s.jsx(hr,{checked:j.enabled,onChange:re=>{D(j,re)},ariaLabel:j.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:j.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:j.name}),disabled:E}),j.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(at,{variant:"outline",size:"sm",onClick:()=>{z(j)},disabled:E,children:[s.jsx(R,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(at,{variant:"outline",size:"sm",onClick:()=>M(j),disabled:E,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:j.name}),children:[s.jsx(R,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(at,{variant:"destructive",size:"sm",onClick:()=>{P(j)},disabled:E,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:j.name}),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},j.id)})})}),O=s.jsxs("div",{className:"space-y-4",children:[I,_]});return s.jsxs(s.Fragment,{children:[r?s.jsx(ri,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:j=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),j]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(at,{className:"w-full",onClick:V,disabled:!u,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:O}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:o.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):o.map(j=>s.jsx("button",{type:"button",onClick:()=>T(j.id),className:Ie("flex w-full min-w-0 items-center rounded-md px-2 py-1.5 text-left typography-ui-label focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",u===j.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:C(j)},j.id))})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("div",{className:"flex items-center px-6 pt-3",children:s.jsxs(at,{size:"sm",onClick:V,disabled:!u,children:[s.jsx(R,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-4",children:s.jsx("div",{className:"mx-auto w-full max-w-3xl",children:_})})]})]})}):null,s.jsx(Ok,{open:v,task:f,onOpenChange:g,onSave:A})]})}const Oo=100;function Kk(){const t=Ye.c(101),{t:e}=ht(),n=Ae(t3),r=Ae(e3),i=qe(Zk),o=qe(Jk),l=ss(Xk);let a;t[0]!==n?(a=Q=>n?Q.archivedSessions:[],t[0]=n,t[1]=a):a=t[1];const d=Es(tr(a)),[u,m]=c.useState(""),[h,y]=c.useState(null),[b,S]=c.useState(Oo);let v;t[2]!==u?(v=u.trim().toLowerCase(),t[2]=u,t[3]=v):v=t[3];const g=v;let f;e:{if(!n){let me;t[4]===Symbol.for("react.memo_cache_sentinel")?(me=[],t[4]=me):me=t[4],f=me;break e}let Q;t[5]!==d?(Q=[...d].sort(Yk),t[5]=d,t[6]=Q):Q=t[6],f=Q}const x=f;let p;if(t[7]!==l||t[8]!==x||t[9]!==e){const Q=new Map;for(const me of x){const re=dt(Us(me))??"",G=Q.get(re);if(G){G.sessions.push(me);continue}Q.set(re,{directory:re,label:re?Wn(re,l)||re:e("sessions.archivePage.otherProjects"),sessions:[me]})}p=[...Q.values()].sort(Qk),t[7]=l,t[8]=x,t[9]=e,t[10]=p}else p=t[10];const w=p;let N;e:{if(g){let me;t[11]!==g||t[12]!==x?(me=Eh(x,g,qk),t[11]=g,t[12]=x,t[13]=me):me=t[13],N=me;break e}if(h===null){N=x;break e}let Q;t[14]!==w||t[15]!==h?(Q=w.find(me=>me.directory===h)?.sessions??[],t[14]=w,t[15]=h,t[16]=Q):Q=t[16],N=Q}const C=N;let k,A,D,P,M,z,I,V,T,_;if(t[17]!==d.length||t[18]!==w||t[19]!==C||t[20]!==l||t[21]!==g||t[22]!==n||t[23]!==u||t[24]!==h||t[25]!==i||t[26]!==r||t[27]!==e||t[28]!==o||t[29]!==b){M=Symbol.for("react.early_return_sentinel");e:{const Q=C.slice(0,b);k=C.length-Q.length;const me=d.length;let re;t[40]===Symbol.for("react.memo_cache_sentinel")?(re=be=>{y(be),S(Oo)},t[40]=re):re=t[40];const G=re;let ee;t[41]!==i||t[42]!==r?(ee=be=>{const te=dt(Us(be));i(be.id,te??void 0),r(!1)},t[41]=i,t[42]=r,t[43]=ee):ee=t[43];const ue=ee;let W;t[44]!==e||t[45]!==o?(W=be=>{o(be.id).then(te=>{te?Oe.success(e("sessions.sidebar.session.restore.success")):Oe.error(e("sessions.sidebar.session.restore.error"))})},t[44]=e,t[45]=o,t[46]=W):W=t[46];const ne=W;if(!n){M=null;break e}let Y;t[47]!==e?(Y=(be,te,pe,Pe,de,he,fe)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:de,title:he,className:Ie("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",fe?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",Pe?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:te}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:pe})]}),fe?s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>yn.requestDelete({sessions:fe,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteProjectAria",{label:te}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(xt,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},be),t[47]=e,t[48]=Y):Y=t[48];const F=Y;P="absolute inset-0 z-10 flex flex-col bg-background",A="flex min-h-0 flex-1";let J;if(t[49]!==F||t[50]!==h||t[51]!==e||t[52]!==me){let be;t[54]===Symbol.for("react.memo_cache_sentinel")?(be=()=>G(null),t[54]=be):be=t[54],J=F("__all__",e("sessions.archivePage.allDirectories"),me,h===null,be),t[49]=F,t[50]=h,t[51]=e,t[52]=me,t[53]=J}else J=t[53];let ie;if(t[55]!==w||t[56]!==F||t[57]!==h){let be;t[59]!==F||t[60]!==h?(be=te=>F(te.directory||"__none__",te.label,te.sessions.length,h===te.directory,()=>G(te.directory),te.directory||void 0,te.sessions),t[59]=F,t[60]=h,t[61]=be):be=t[61],ie=w.map(be),t[55]=w,t[56]=F,t[57]=h,t[58]=ie}else ie=t[58];t[62]!==J||t[63]!==ie?(D=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[J,ie]})}),t[62]=J,t[63]=ie,t[64]=D):D=t[64],T="flex min-w-0 flex-1 flex-col";let xe;t[65]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(R,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[65]=xe):xe=t[65];let ge;t[66]===Symbol.for("react.memo_cache_sentinel")?(ge=be=>{m(be.target.value),S(Oo)},t[66]=ge):ge=t[66];let Ce;t[67]!==e?(Ce=e("sessions.archivePage.searchPlaceholder"),t[67]=e,t[68]=Ce):Ce=t[68];let Re;t[69]!==u||t[70]!==Ce?(Re=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[xe,s.jsx("input",{value:u,onChange:ge,placeholder:Ce,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[69]=u,t[70]=Ce,t[71]=Re):Re=t[71];let ce;t[72]!==C.length||t[73]!==e?(ce=C.length===1?e("sessions.archivePage.countSingle",{count:C.length}):e("sessions.archivePage.countPlural",{count:C.length}),t[72]=C.length,t[73]=e,t[74]=ce):ce=t[74];let ye;t[75]!==ce?(ye=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:ce}),t[75]=ce,t[76]=ye):ye=t[76],t[77]!==Re||t[78]!==ye?(_=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[Re,ye]}),t[77]=Re,t[78]=ye,t[79]=_):_=t[79],V="min-h-0 flex-1 overflow-y-auto px-6 py-3",z="mx-auto w-full max-w-3xl space-y-0.5",I=Q.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:e(g?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):Q.map(be=>{const te=dt(Us(be))??"",pe=te?Wn(te,l)||te:null;return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>ue(be),role:"button",tabIndex:0,onKeyDown:Pe=>{(Pe.key==="Enter"||Pe.key===" ")&&(Pe.preventDefault(),ue(be))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:be.title||e("sessions.sidebar.session.untitled")}),g&&pe?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:te,children:pe}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:_d(be.time?.archived??be.time?.updated??be.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:Pe=>{Pe.stopPropagation(),ne(be)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.restoreSessionAria",{title:be.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(R,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:Pe=>{Pe.stopPropagation(),yn.requestDelete({sessions:[be],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteSessionAria",{title:be.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},be.id)})}t[17]=d.length,t[18]=w,t[19]=C,t[20]=l,t[21]=g,t[22]=n,t[23]=u,t[24]=h,t[25]=i,t[26]=r,t[27]=e,t[28]=o,t[29]=b,t[30]=k,t[31]=A,t[32]=D,t[33]=P,t[34]=M,t[35]=z,t[36]=I,t[37]=V,t[38]=T,t[39]=_}else k=t[30],A=t[31],D=t[32],P=t[33],M=t[34],z=t[35],I=t[36],V=t[37],T=t[38],_=t[39];if(M!==Symbol.for("react.early_return_sentinel"))return M;let O;t[80]!==k||t[81]!==e?(O=k>0?s.jsx("button",{type:"button",onClick:()=>S(Gk),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[80]=k,t[81]=e,t[82]=O):O=t[82];let j;t[83]!==O||t[84]!==z||t[85]!==I?(j=s.jsxs("div",{className:z,children:[I,O]}),t[83]=O,t[84]=z,t[85]=I,t[86]=j):j=t[86];let E;t[87]!==j||t[88]!==V?(E=s.jsx("div",{className:V,children:j}),t[87]=j,t[88]=V,t[89]=E):E=t[89];let L;t[90]!==E||t[91]!==T||t[92]!==_?(L=s.jsxs("div",{className:T,children:[_,E]}),t[90]=E,t[91]=T,t[92]=_,t[93]=L):L=t[93];let U;t[94]!==A||t[95]!==D||t[96]!==L?(U=s.jsxs("div",{className:A,children:[D,L]}),t[94]=A,t[95]=D,t[96]=L,t[97]=U):U=t[97];let X;return t[98]!==P||t[99]!==U?(X=s.jsx("div",{className:P,children:U}),t[98]=P,t[99]=U,t[100]=X):X=t[100],X}function Gk(t){return t+Oo}function qk(t){return[t.title]}function Qk(t,e){return e.sessions.length-t.sessions.length}function Yk(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function Xk(t){return t.homeDirectory}function Jk(t){return t.unarchiveSession}function Zk(t){return t.setCurrentSession}function e3(t){return t.setArchivePageOpen}function t3(t){return t.isArchivePageOpen}function s3(){const t=Ye.c(18),{t:e}=ht(),n=Ae(o3),r=Ae(r3),i=Ht(n3);let o;t[0]!==n?(o=b=>b.projects.find(S=>S.id===n)??null,t[0]=n,t[1]=o):o=t[1];const l=Ht(o);if(!n||!l)return null;let a;t[2]!==l.id||t[3]!==i||t[4]!==r?(a=()=>{i(l.id),r(!0)},t[2]=l.id,t[3]=i,t[4]=r,t[5]=a):a=t[5];let d;t[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(R,{name:"node-tree",className:"mr-1 h-3.5 w-3.5"}),t[6]=d):d=t[6];let u;t[7]!==e?(u=e("sessions.sidebar.project.actions.newWorktree"),t[7]=e,t[8]=u):u=t[8];let m;t[9]!==a||t[10]!==u?(m=s.jsx("div",{className:"flex items-center",children:s.jsxs(at,{size:"sm",onClick:a,children:[d,u]})}),t[9]=a,t[10]=u,t[11]=m):m=t[11];let h;t[12]!==l.id||t[13]!==l.path?(h=s.jsx(Vp,{projectRef:{id:l.id,path:l.path},sections:"list-only"}),t[12]=l.id,t[13]=l.path,t[14]=h):h=t[14];let y;return t[15]!==m||t[16]!==h?(y=s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-4",children:[m,h]})})}),t[15]=m,t[16]=h,t[17]=y):y=t[17],y}function n3(t){return t.setActiveProjectIdOnly}function r3(t){return t.setNewWorktreeDialogOpen}function o3(t){return t.worktreesPageProjectId}const ha=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),i3=(t,e)=>{const n=ha(t),r=ha(e);return`${n}-${r}`.substring(0,60)},Vc=(t,e)=>`${t}/${e}`,a3=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Uc=(t,e)=>{const n=a3(e),r=t.directory,i=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};$h(t.id,n),qe.getState().markSessionAsOpenChamberCreated(t.id),Es.getState().upsertSession(i);try{Lo().ensureChild(n,{bootstrap:!1}).setState(l=>{const a=l.session.findIndex(u=>u.id===t.id);if(a>=0&&l.session[a]===i)return l;const d=a>=0?l.session.map((u,m)=>m===a?i:u):[...l.session,i].sort((u,m)=>u.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(l.sessionTotal,d.length),limit:Math.max(l.limit,d.length)}})}catch{}return i},l3=()=>{const t=Ht.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=ss.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Ni=or()(cu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:i,files:o,setupCommands:l}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let a=0;a<r.length;a++){if(!r[a].prompt.trim())return t({error:`Group ${a+1}: prompt is required`}),null;if(r[a].models.length<1)return t({error:`Group ${a+1}: select at least 1 model`}),null}t({isLoading:!0,error:null});try{const a=l3();if(!a)return t({error:"Select a project",isLoading:!1}),null;const d=a.path,m=await ti(d)&&e.isolateRuns!==!1,h=ha(n),y=m?await oi(d):void 0,b=m?await Rh(d):null,S=[],v=l?.filter(w=>w.trim().length>0)??[];for(let w=0;w<r.length;w++){const N=r[w],C=N.prompt,k=new Map;for(const D of N.models){const P=`${D.providerID}:${D.modelID}`;k.set(P,(k.get(P)||0)+1)}const A=new Map;for(const D of N.models){const P=`${D.providerID}:${D.modelID}`,M=k.get(P)||1,z=(A.get(P)||0)+1;A.set(P,z);const I=i3(D.providerID,D.modelID),V=r.length>1?`g${w+1}`:void 0,T=M>1?Vc(h,`${I}/${z}`):Vc(h,I),_=V?`${V}/${T}`:T,O=ej({groupSlug:h,runGroup:V,providerID:D.providerID,modelID:D.modelID,index:M>1?z:void 0});try{if(!m){const U=await _s.withDirectory(d,()=>_s.createSession({title:O}));Uc(U,d),S.push({sessionId:U.id,worktreePath:d,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C});continue}const j=await Mh(a,{preferredName:_,mode:"new",branchName:_,worktreeName:_,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:b}),E={...j,createdFromBranch:y,kind:"standard"};await Oh(a)&&await Bh(j.path);const L=await _s.withDirectory(j.path,()=>_s.createSession({title:O}));Uc(L,j.path),qe.getState().setWorktreeMetadata(L.id,E),S.push({sessionId:L.id,worktreePath:j.path,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:C})}catch(j){console.warn("[MultiRun] Failed to create session:",j)}}}const g=l?.filter(w=>w.trim().length>0)??[];g.length>0&&Fh(a,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const f=S.map(w=>w.sessionId),x=S[0]?.sessionId??null;if(f.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const p=o?.map(w=>({type:"file",mime:w.mime,filename:w.filename,url:w.url}));return(async()=>{try{const w=_h.getState().expandText;await Promise.allSettled(S.map(async N=>{try{const C=await w(N.prompt).catch(()=>N.prompt);await Lh({sessionId:N.sessionId,directory:N.worktreePath,content:C,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:i,files:p})}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(w){console.warn("[MultiRun] Failed to start runs:",w)}})(),t({isLoading:!1}),{groupSlug:h,sessionIds:f,firstSessionId:x}}catch(a){return t({error:a instanceof Error?a.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function bm(t){const e=Ye.c(30),{git:n}=Pn(),r=jd(t),i=Wh(t),o=zh(t),l=Vh(t),a=$n(f3),d=$n(m3);let u,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==i||e[4]!==o?(u=()=>{!t||!n||i!==null||o||d(t,n,{silent:!0})},m=[t,n,d,i,o],e[0]=t,e[1]=d,e[2]=n,e[3]=i,e[4]=o,e[5]=u,e[6]=m):(u=e[5],m=e[6]),c.useEffect(u,m);let h;e[7]!==r?.all||e[8]!==t||e[9]!==a||e[10]!==n||e[11]!==i?(h=()=>{!t||!n||i===!0&&(r?.all||a(t,n))},e[7]=r?.all,e[8]=t,e[9]=a,e[10]=n,e[11]=i,e[12]=h):h=e[12];const y=r?.all;let b;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==i||e[17]!==y?(b=[t,n,i,y,a],e[13]=t,e[14]=a,e[15]=n,e[16]=i,e[17]=y,e[18]=b):b=e[18],c.useEffect(h,b);const S=o||i===!0&&l;let v;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],v=k;break e}let C;e[20]!==r.all?(C=r.all.filter(u3).sort(),e[20]=r.all,e[21]=C):C=e[21],v=C}const g=v;let f;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],f=k;break e}let C;e[23]!==r.all?(C=r.all.filter(d3).map(c3).sort(),e[23]=r.all,e[24]=C):C=e[24],f=C}const x=f;let p;e:{if(!t){p=null;break e}if(i!==null){p=i;break e}if(S){p=null;break e}p=r?.all?!0:null}const w=p;let N;return e[25]!==w||e[26]!==S||e[27]!==g||e[28]!==x?(N={localBranches:g,remoteBranches:x,isLoading:S,isGitRepository:w},e[25]=w,e[26]=S,e[27]=g,e[28]=x,e[29]=N):N=e[29],N}function c3(t){return t.replace(/^remotes\//,"")}function d3(t){return t.startsWith("remotes/")}function u3(t){return!t.startsWith("remotes/")}function m3(t){return t.fetchStatus}function f3(t){return t.fetchBranches}const h3=({directory:t,value:e,onChange:n,className:r,disabled:i,id:o})=>{const{t:l}=ht(),{localBranches:a,remoteBranches:d,isLoading:u,isGitRepository:m}=bm(t),h=c.useMemo(()=>[...a,...d.map(b=>`remotes/${b}`)],[a,d]);c.useEffect(()=>{if(i||u||h.length===0||e&&h.includes(e))return;const b=e;let S=!1;return(async()=>{try{const g=t?await oi(t).catch(()=>null):null;if(S)return;const f=localStorage.getItem(Cl),{sourceBranch:x,shouldClearSavedSourceBranch:p}=Up({branches:h,savedSourceBranch:f,rootBranch:g});if(p&&localStorage.removeItem(Cl),S||b&&h.includes(b))return;x&&n(x)}catch{}})(),()=>{S=!0}},[h,t,i,u,n,e]);const y=i||!m||u;return s.jsxs("div",{children:[s.jsxs($s,{value:e,onValueChange:n,disabled:y,children:[s.jsx(Ws,{id:o,size:"lg",className:Ie("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Is,{placeholder:l(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(zs,{className:"max-h-[280px] max-w-[320px]",children:u?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):a.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[a.length>0&&s.jsxs(Oi,{children:[s.jsx(pl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),a.map(b=>s.jsx(ns,{value:b,className:"whitespace-normal break-all",children:b},b))]}),a.length>0&&d.length>0&&s.jsx(Uh,{}),d.length>0&&s.jsxs(Oi,{children:[s.jsx(pl,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(ns,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},p3=10*1024*1024,Bo=t=>{const e=Ye.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(R,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(yt,{children:[r,s.jsx(xt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},Qn=t=>{const e=Ye.c(9),{htmlFor:n,required:r,children:i,info:o}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let a;e[2]!==i||e[3]!==n||e[4]!==l?(a=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=a):a=e[5];const d=o&&o;let u;return e[6]!==a||e[7]!==d?(u=s.jsxs("div",{className:"flex items-center gap-1.5",children:[a,d]}),e[6]=a,e[7]=d,e[8]=u):u=e[8],u},g3=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=ht(),[o,l]=c.useState(""),[a,d]=c.useState(()=>[{id:Wr(),prompt:"",models:[]}]),[u,m]=c.useState(""),[h,y]=c.useState([]),[b,S]=c.useState(!1),[v,g]=c.useState([]),[f,x]=c.useState(!1),[p,w]=c.useState(!1),[N,C]=c.useState(!0),k=c.useRef(null),A=ss(B=>B.currentDirectory??null),D=ss(B=>B.homeDirectory??null),P=c.useMemo(()=>{if(typeof window>"u")return null;const B=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof B=="string"&&B.trim().length>0?B.trim():null},[]),M=Ht(B=>B.activeProjectId),z=Ht(B=>B.setActiveProjectIdOnly),I=Ht(B=>B.projects),[V,T]=c.useState(()=>M??null);c.useEffect(()=>{if(M){T(M);return}!V&&I.length>0&&T(I[0].id)},[M,I,V]);const _=c.useMemo(()=>V?I.find(B=>B.id===V)??null:null,[I,V]),O=_?.path??A,j=c.useCallback(B=>{T(B),B!==M&&z(B)},[M,z]),{currentTheme:E}=nr(),L=c.useCallback(B=>{const H=B.label?.trim()||Wn(B.path,D),ke=B.icon?Pa[B.icon]:null,Se=B.color?Ta[B.color]:void 0,Be=ke?s.jsx(R,{name:ke,className:"h-3.5 w-3.5 shrink-0",style:Se?{color:Se}:void 0}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Se?{color:Se}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[B.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:B.iconBackground?{backgroundColor:B.iconBackground}:void 0,children:s.jsx(Ia,{project:{id:B.id,iconImage:B.iconImage??null},options:{themeVariant:E.metadata.variant,iconColor:E.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Be})}):Be,s.jsx("span",{className:"truncate",children:H})]})},[D,E.metadata.variant,E.colors.surface.foreground]),U=c.useMemo(()=>{if(_?.path)return{id:_.id,path:_.path};const B=A??P;return B?{id:`path:${B}`,path:B}:null},[_,A,P]),[X]=c.useState(()=>typeof window<"u"?wn():!1),Q=c.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),me=xd(),re=c.useMemo(()=>{if(typeof window>"u")return null;const B=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof B=="number"&&Number.isFinite(B)&&B>0)return B;if(typeof navigator>"u")return null;const H=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!H)return null;const ke=Number.parseInt(H[1],10),Se=Number.parseInt(H[2],10);return Number.isNaN(ke)?null:ke===10?Se:ke},[]),G=c.useMemo(()=>X&&Q||me?"pl-[5.5rem]":"pl-3",[X,Q,me]),ee=c.useMemo(()=>!X||!Q||re===null?"":re>=26?"h-12":re<=15?"h-14":"",[X,Q,re]),ue=c.useCallback(async B=>{B.target.closest("button, a, input, select, textarea")||B.button===0&&X&&await Hh()},[X]);c.useEffect(()=>{if(!n)return;const B=H=>{H.key==="Escape"&&(H.preventDefault(),H.stopPropagation(),n())};return window.addEventListener("keydown",B,!0),()=>window.removeEventListener("keydown",B,!0)},[n]);const[W,ne]=c.useState(""),{isLoading:Y,isGitRepository:F}=bm(O),J=c.useRef(!1),ie=F===!0,xe=ie&&N;c.useEffect(()=>{if(F===!1){J.current=!0,C(!1);return}F===!0&&J.current&&(J.current=!1,C(!0))},[F]);const ge=Ni(B=>B.createMultiRun),Ce=Ni(B=>B.error),Re=Ni(B=>B.clearError);c.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(B=>{const H=[...B];return H.length>0&&!H[0].prompt.trim()&&(H[0]={...H[0],prompt:t}),H})},[t]),c.useEffect(()=>{if(!U)return;let B=!1;return w(!0),(async()=>{try{const H=await Kh(U);B||g(H)}catch{}finally{B||w(!1)}})(),()=>{B=!0}},[U]);const ce=c.useCallback((B,H)=>{d(ke=>ke.map(Se=>Se.id===B?{...Se,...H}:Se))},[]),ye=c.useCallback(B=>{d(H=>H.filter(ke=>ke.id!==B))},[]),be=c.useCallback(()=>{d(B=>[...B,{id:Wr(),prompt:"",models:[]}])},[]),te=async B=>{const H=B.target.files;if(!H)return;let ke=0;for(let Se=0;Se<H.length;Se++){const Be=H[Se];if(Be.size>p3){Oe.error(i("multirun.launcher.toast.fileTooLarge",{fileName:Be.name}));continue}try{const _e=await new Promise((Te,Z)=>{const Ne=new FileReader;Ne.onload=()=>Te(Ne.result),Ne.onerror=Z,Ne.readAsDataURL(Be)});y(Te=>[...Te,{id:Wr(),filename:Be.name,mimeType:Be.type||"application/octet-stream",size:Be.size,dataUrl:_e}]),ke++}catch(_e){console.error("File attach failed",_e),Oe.error(i("multirun.launcher.toast.attachFailed",{fileName:Be.name}))}}ke>0&&Oe.success(ke===1?i("multirun.launcher.toast.attachedSingle",{count:ke}):i("multirun.launcher.toast.attachedPlural",{count:ke})),k.current&&(k.current.value="")},pe=B=>{y(H=>H.filter(ke=>ke.id!==B))},Pe=c.useMemo(()=>a.reduce((B,H)=>B+H.models.length,0),[a]),de=async B=>{B.preventDefault();const H=a.filter(ke=>ke.prompt.trim()&&ke.models.length>=1);if(H.length!==0&&!(Pe<1)){S(!0),Re();try{V&&V!==M&&z(V);const ke=h.map(Z=>({mime:Z.mimeType,filename:Z.filename,url:Z.dataUrl})),Se=v.filter(Z=>Z.trim().length>0),Be=H.map(Z=>({prompt:Z.prompt.trim(),models:Z.models.map(Ne=>({providerID:Ne.providerID,modelID:Ne.modelID,displayName:Ne.displayName,variant:Ne.variant}))})),_e={name:o.trim(),groups:Be,agent:u||void 0,worktreeBaseBranch:xe?W:void 0,isolateRuns:xe,files:ke.length>0?ke:void 0,setupCommands:Se.length>0?Se:void 0},Te=await ge(_e);Te&&(Te.firstSessionId&&qe.getState().setCurrentSession(Te.firstSessionId),e?.())}finally{S(!1)}}},he=!!(o.trim()&&a.some(B=>B.prompt.trim()&&B.models.length>=1)&&Pe>=1&&O&&!Y&&(F===!1||!xe||W)),fe=v.filter(B=>B.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:ue,className:Ie("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",G,ee),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(R,{name:"close",className:"h-5 w-5"})})}),s.jsx(xt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Ca,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Qn,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),I.length>0?s.jsxs($s,{value:V??void 0,onValueChange:j,children:[s.jsx(Ws,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:_?s.jsx(Is,{children:L(_)}):s.jsx(Is,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(zs,{fitContent:!0,children:I.map(B=>s.jsx(ns,{value:B.id,className:"max-w-[24rem]",children:L(B)},B.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Qn,{htmlFor:"group-name",required:!0,info:s.jsx(Bo,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Nn,{id:"group-name",value:o,onChange:B=>l(B.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Qn,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Bo,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(h3,{directory:O,value:W,onChange:ne,disabled:!xe,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(hr,{checked:N,onChange:C,disabled:!ie,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Qn,{htmlFor:"multirun-agent",info:s.jsx(Bo,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(cm,{value:u,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(_i,{open:f,onOpenChange:x,children:[s.jsxs(Yd,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(R,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),fe>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:fe}),s.jsx(R,{name:"arrow-down-s",className:Ie("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",f&&"rotate-180")})]}),s.jsx(Li,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:p?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[v.map((B,H)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Nn,{value:B,onChange:ke=>{const Se=[...v];Se[H]=ke.target.value,g(Se)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(v.filter((ke,Se)=>Se!==H)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]},`${B}-${H}`)),s.jsxs("button",{type:"button",onClick:()=>g([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(R,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Qn,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:te,accept:"*/*"}),s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(R,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(xt,{children:i("multirun.launcher.attachments.tooltip")})]}),h.map(B=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[B.mimeType.startsWith("image/")?s.jsx(R,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(R,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:B.filename,children:B.filename}),s.jsx("button",{type:"button",onClick:()=>pe(B.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(R,{name:"close",className:"h-3 w-3"})})]},B.id))]})]}),a.map((B,H)=>s.jsx(b3,{group:B,groupIndex:H,canRemove:a.length>1,onUpdate:ce,onRemove:ye},B.id)),s.jsxs("button",{type:"button",onClick:be,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),i("multirun.launcher.groups.addGroup")]}),Ce&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Ce})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!xe&&F!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(R,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(at,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}):null,s.jsx(at,{type:"submit",size:"sm",disabled:!he||b,children:b?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithRunCount",{count:Pe})})})]})})]})},b3=t=>{const e=Ye.c(99),{group:n,groupIndex:r,canRemove:i,onUpdate:o,onRemove:l}=t,{t:a}=ht(),[d,u]=c.useState(!1),[m,h]=c.useState(""),[y,b]=c.useState(!1),[S,v]=c.useState(""),[g,f]=c.useState(!1),[x,p]=c.useState(""),w=c.useRef(null),N=c.useRef(null),C=c.useRef(null),k=c.useRef(null);let A;e[0]!==n.id||e[1]!==n.models||e[2]!==o?(A=Se=>{o(n.id,{models:[...n.models,Se]})},e[0]=n.id,e[1]=n.models,e[2]=o,e[3]=A):A=e[3];const D=A;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==o?(P=Se=>{o(n.id,{models:n.models.filter((Be,_e)=>_e!==Se)})},e[4]=n.id,e[5]=n.models,e[6]=o,e[7]=P):P=e[7];const M=P;let z;e[8]!==n.id||e[9]!==n.models||e[10]!==o?(z=(Se,Be)=>{o(n.id,{models:n.models.map((_e,Te)=>Te===Se?Be:_e)})},e[8]=n.id,e[9]=n.models,e[10]=o,e[11]=z):z=e[11];const I=z;let V;e[12]===Symbol.for("react.memo_cache_sentinel")?(V=(Se,Be)=>{if(Se.startsWith("/")){const Ne=Se.indexOf(" "),Me=Se.indexOf(`
|
|
923
|
-
`),$=Math.min(Ne===-1?Se.length:Ne,Me===-1?Se.length:Me);if(Be<=$&&Ne===-1){v(Se.substring(1,$)),b(!0),u(!1),f(!1);return}}b(!1);const _e=Se.substring(0,Be),Te=_e.lastIndexOf("#");if(Te!==-1){const Ne=Te>0?_e[Te-1]:null,Me=_e.substring(Te+1);if((!Ne||/\s/.test(Ne))&&!Me.includes(" ")&&!Me.includes(`
|
|
924
|
-
`)){p(Me),f(!0),u(!1);return}}f(!1);const Z=_e.lastIndexOf("@");if(Z!==-1){const Ne=Z>0?_e[Z-1]:null,Me=_e.substring(Z+1);(!Ne||/\s/.test(Ne))&&!Me.includes(" ")&&!Me.includes(`
|
|
925
|
-
`)?(h(Me),u(!0)):u(!1);return}u(!1)},e[12]=V):V=e[12];const T=V;let _;e[13]!==n.id||e[14]!==o?(_=Se=>{o(n.id,{prompt:Se})},e[13]=n.id,e[14]=o,e[15]=_):_=e[15];const O=_;let j;e[16]!==n.prompt||e[17]!==O?(j=Se=>{const Be=n.prompt,Te=w.current?.selectionStart??Be.length,Ne=Be.substring(0,Te).lastIndexOf("@"),Me=Se.relativePath&&Se.relativePath.trim().length>0?Se.relativePath.trim():Se.path||Se.name,$=Ne!==-1?Ne:Te,ae=`${Be.substring(0,$)}@${Me} ${Be.substring(Te)}`,se=$+Me.length+2;O(ae),u(!1),h(""),requestAnimationFrame(()=>{const we=w.current;we&&(we.selectionStart=se,we.selectionEnd=se,we.focus()),T(ae,se)})},e[16]=n.prompt,e[17]=O,e[18]=j):j=e[18];const E=j;let L;e[19]!==n.prompt||e[20]!==O?(L=Se=>{const Be=n.prompt,Te=w.current?.selectionStart??Be.length,Ne=Be.substring(0,Te).lastIndexOf("@"),Me=Ne!==-1?Ne:Te,$=`${Be.substring(0,Me)}@${Se} ${Be.substring(Te)}`,ae=Me+Se.length+2;O($),u(!1),h(""),requestAnimationFrame(()=>{const se=w.current;se&&(se.selectionStart=ae,se.selectionEnd=ae,se.focus()),T($,ae)})},e[19]=n.prompt,e[20]=O,e[21]=L):L=e[21];const U=L;let X;e[22]!==O?(X=Se=>{const Be=`/${Se.name} `;O(Be),b(!1),v(""),f(!1),requestAnimationFrame(()=>{const _e=w.current;_e&&(_e.focus(),_e.selectionStart=_e.value.length,_e.selectionEnd=_e.value.length),T(Be,Be.length)})},e[22]=O,e[23]=X):X=e[23];const Q=X;let me;e[24]!==n.prompt||e[25]!==O?(me=(Se,Be)=>{const _e=n.prompt,Z=w.current?.selectionStart??_e.length,Me=_e.substring(0,Z).lastIndexOf("#"),$=Me!==-1?Me:Z,ae=`${_e.substring(0,$)}#${Be} ${_e.substring(Z)}`,se=$+Be.length+2;O(ae),f(!1),p(""),requestAnimationFrame(()=>{const we=w.current;we&&(we.selectionStart=se,we.selectionEnd=se,we.focus()),T(ae,se)})},e[24]=n.prompt,e[25]=O,e[26]=me):me=e[26];const re=me;let G;e[27]!==y||e[28]!==d||e[29]!==g?(G=Se=>{if(y&&C.current&&(Se.key==="Enter"||Se.key==="ArrowUp"||Se.key==="ArrowDown"||Se.key==="Escape"||Se.key==="Tab")){Se.preventDefault(),C.current.handleKeyDown(Se.key);return}d&&N.current&&(Se.key==="Enter"||Se.key==="ArrowUp"||Se.key==="ArrowDown"||Se.key==="Escape"||Se.key==="Tab")&&(Se.preventDefault(),N.current.handleKeyDown(Se.key)),g&&k.current&&(Se.key==="Enter"||Se.key==="ArrowUp"||Se.key==="ArrowDown"||Se.key==="Escape"||Se.key==="Tab")&&(Se.preventDefault(),k.current.handleKeyDown(Se.key))},e[27]=y,e[28]=d,e[29]=g,e[30]=G):G=e[30];const ee=G,ue=r+1;let W;e[31]!==a||e[32]!==ue?(W=a("multirun.launcher.groups.groupLabel",{index:ue}),e[31]=a,e[32]=ue,e[33]=W):W=e[33];let ne;e[34]!==W?(ne=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:W}),e[34]=W,e[35]=ne):ne=e[35];let Y;e[36]!==i||e[37]!==n.id||e[38]!==l||e[39]!==a?(Y=i&&s.jsx("button",{type:"button",onClick:()=>l(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":a("multirun.launcher.groups.removeGroup"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=i,e[37]=n.id,e[38]=l,e[39]=a,e[40]=Y):Y=e[40];let F;e[41]!==ne||e[42]!==Y?(F=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ne,Y]}),e[41]=ne,e[42]=Y,e[43]=F):F=e[43];let J;e[44]!==a?(J=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=J):J=e[45];let ie;e[46]!==J?(ie=s.jsx(Qn,{required:!0,children:J}),e[46]=J,e[47]=ie):ie=e[47];const xe=n.prompt;let ge;e[48]!==O?(ge=Se=>{const Be=Se.target.value;O(Be);const _e=Se.target.selectionStart??Be.length;T(Be,_e)},e[48]=O,e[49]=ge):ge=e[49];let Ce;e[50]!==a?(Ce=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=Ce):Ce=e[51];let Re;e[52]!==n.prompt||e[53]!==ee||e[54]!==ge||e[55]!==Ce?(Re=s.jsx(ur,{ref:w,value:xe,onChange:ge,onKeyDown:ee,placeholder:Ce,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=ee,e[54]=ge,e[55]=Ce,e[56]=Re):Re=e[56];let ce;e[57]!==S||e[58]!==Q||e[59]!==y?(ce=y?s.jsx(Wd,{ref:C,searchQuery:S,onCommandSelect:Q,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=S,e[58]=Q,e[59]=y,e[60]=ce):ce=e[60];let ye;e[61]!==U||e[62]!==E||e[63]!==m||e[64]!==d?(ye=d?s.jsx(zd,{ref:N,searchQuery:m,onFileSelect:E,onAgentSelect:U,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=U,e[62]=E,e[63]=m,e[64]=d,e[65]=ye):ye=e[65];let be;e[66]!==re||e[67]!==g||e[68]!==x?(be=g?s.jsx(Vd,{ref:k,searchQuery:x,onSnippetSelect:re,onClose:()=>f(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=re,e[67]=g,e[68]=x,e[69]=be):be=e[69];let te;e[70]!==Re||e[71]!==ce||e[72]!==ye||e[73]!==be?(te=s.jsxs("div",{className:"relative",children:[Re,ce,ye,be]}),e[70]=Re,e[71]=ce,e[72]=ye,e[73]=be,e[74]=te):te=e[74];let pe;e[75]!==ie||e[76]!==te?(pe=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ie,te]}),e[75]=ie,e[76]=te,e[77]=pe):pe=e[77];let Pe;e[78]!==a?(Pe=a("multirun.launcher.models.info"),e[78]=a,e[79]=Pe):Pe=e[79];let de;e[80]!==Pe?(de=s.jsx(Bo,{children:Pe}),e[80]=Pe,e[81]=de):de=e[81];let he;e[82]!==a?(he=a("multirun.launcher.models.label"),e[82]=a,e[83]=he):he=e[83];let fe;e[84]!==de||e[85]!==he?(fe=s.jsx(Qn,{required:!0,info:de,children:he}),e[84]=de,e[85]=he,e[86]=fe):fe=e[86];let B;e[87]!==n.models||e[88]!==D||e[89]!==M||e[90]!==I?(B=s.jsx(dm,{selectedModels:n.models,onAdd:D,onRemove:M,onUpdate:I,minModels:1}),e[87]=n.models,e[88]=D,e[89]=M,e[90]=I,e[91]=B):B=e[91];let H;e[92]!==fe||e[93]!==B?(H=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[fe,B]}),e[92]=fe,e[93]=B,e[94]=H):H=e[94];let ke;return e[95]!==F||e[96]!==pe||e[97]!==H?(ke=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[F,pe,H]}),e[95]=F,e[96]=pe,e[97]=H,e[98]=ke):ke=e[98],ke},x3=t=>{const e=new Map;for(const n of t){const r=Us(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},y3=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,i)=>{e.has(i)||n.push(r)}),n},w3=t=>{const e=Ye.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:i}=t,o=n===void 0?!0:n,l=c.useRef(null);let a,d;e[0]!==o||e[1]!==r||e[2]!==i?(a=()=>{if(!o||!r)return;const u=Cs(),m=x3(i),h=l.current?.runtimeKey===u?l.current.identities:null;for(const y of y3(h,m))Gh({runtimeKey:u,...y});l.current={runtimeKey:u,identities:m}},d=[o,r,i],e[0]=o,e[1]=r,e[2]=i,e[3]=a,e[4]=d):(a=e[3],d=e[4]),c.useEffect(a,d)},S3=new Map,v3=t=>{const e=Ye.c(26),{isVSCode:n}=t,r=Oa(),i=Ht(j3),o=Ht(k3),l=ss(C3),a=qe(N3);let d;e[0]!==n?(d=P=>n?S3:P.availableWorktreesByProject,e[0]=n,e[1]=d):d=e[1];const u=qe(d),m=!n;let h;e[2]!==u||e[3]!==i||e[4]!==m?(h=hm(i,u,{includeWorktrees:m}),e[2]=u,e[3]=i,e[4]=m,e[5]=h):h=e[5];const y=h,b=Es(A3),S=Es(D3),v=Es(P3),g=`session-list-sync:${c.useId()}`;let f,x;e[6]!==o||e[7]!==g||e[8]!==r||e[9]!==l||e[10]!==a||e[11]!==y||e[12]!==i?(f=()=>(r.setBootstrapDemand(g,rm({knownDirectories:y,activeProjectDirectory:dt(i.find(P=>P.id===o)?.path??null),activeProjectId:o,collapsedProjects:new Set,collapsedGroups:new Set,currentDirectory:l,currentSessionDirectory:a})),()=>r.clearBootstrapDemand(g)),x=[o,g,r,l,a,y,i],e[6]=o,e[7]=g,e[8]=r,e[9]=l,e[10]=a,e[11]=y,e[12]=i,e[13]=f,e[14]=x):(f=e[13],x=e[14]),c.useEffect(f,x);const p=c.useRef(null);let w,N;e[15]!==n||e[16]!==y?(w=()=>{const P=new Set(y),M=p.current;p.current=P;const z=M?[...P].filter(I=>!M.has(I)):n?[...P]:[];z.length&&va(z,$o())},N=[n,y],e[15]=n,e[16]=y,e[17]=w,e[18]=N):(w=e[17],N=e[18]),c.useEffect(w,N);let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[19]=C):C=e[19],c.useEffect(T3,C);let k;e[20]!==S||e[21]!==b?(k=[...b,...S],e[20]=S,e[21]=b,e[22]=k):k=e[22];const A=k;let D;e[23]!==A||e[24]!==v?(D={enabled:!0,hasAuthoritativeGlobalSessions:v,sessions:A},e[23]=A,e[24]=v,e[25]=D):D=e[25],w3(D)};function j3(t){return t.projects}function k3(t){return t.activeProjectId}function C3(t){return t.currentDirectory}function N3(t){return t.currentSessionDirectory}function A3(t){return t.activeSessions}function D3(t){return t.archivedSessions}function P3(t){return t.status==="ready"}function T3(){let t=null,e=!1;const n=new Set,r=no(i=>{if(i.type==="scheduled-task-ran")e=!0;else if(i.type==="session-created")n.add(i.directory);else return;t&&clearTimeout(t),t=setTimeout(()=>{if(t=null,e){e=!1,n.clear(),Ba($o());return}const o=[...n];n.clear(),o.length&&va(o,$o())},500)});return()=>{t&&clearTimeout(t),r()}}const I3=rr(()=>sr(()=>import("./SettingsWindow-oyOm2fHR.js"),__vite__mapDeps([138,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,139,116,140,126,127,128,129,117,118,102,103,87,88,89,90,91,92,93,94,95,96,97,98,99,100,141,142])).then(t=>({default:t.SettingsWindow}))),E3=()=>{const t=Ye.c(58);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={isVSCode:!1},t[0]=e):e=t[0],v3(e);const n=Ae(R3),r=Ae(M3),i=Ae(O3),o=Ae(B3),[l,a]=c.useState(!1);let d,u;t[1]!==i?(d=()=>{i&&a(!0)},u=[i],t[1]=i,t[2]=d,t[3]=u):(d=t[2],u=t[3]),c.useEffect(d,u);const m=Ae(F3),h=Ae(_3),y=Ae(L3),b=Ae($3),S=Ae(W3),v=Ae(z3),g=b||S||!!v||m;let f;t[4]===Symbol.for("react.memo_cache_sentinel")?(f=[],t[4]=f):f=t[4],c.useEffect(U3,f);const{isMobile:x}=zn();Hp();const p=eb();let w,N;t[5]!==x||t[6]!==r?(w=()=>{Ae.getState().isMobile!==x&&r(x)},N=[x,r],t[5]=x,t[6]=r,t[7]=w,t[8]=N):(w=t[7],N=t[8]),c.useEffect(w,N);let C,k,A,D;t[9]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(dS,{}),k=s.jsx(iv,{}),A=s.jsx(dv,{}),D=s.jsx(bk,{}),t[9]=C,t[10]=k,t[11]=A,t[12]=D):(C=t[9],k=t[10],A=t[11],D=t[12]);let P;t[13]!==p?(P=s.jsx(xk,{value:p,onMoveSessionOnly:H3,onMoveAllChanges:K3,onCancel:cb}),t[13]=p,t[14]=P):P=t[14];let M;t[15]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(Wb,{}),t[15]=M):M=t[15];let z;t[16]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(yb,{}),t[16]=z):z=t[16];let I;t[17]!==n?(I=s.jsx(gk,{isVisible:n}),t[17]=n,t[18]=I):I=t[18];let V;t[19]!==x||t[20]!==n||t[21]!==I?(V=s.jsx(xb,{isOpen:n,isMobile:x,className:"border-border",topBar:z,children:I}),t[19]=x,t[20]=n,t[21]=I,t[22]=V):V=t[22];let T;t[23]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(gb,{}),t[23]=T):T=t[23];const _=g&&"invisible";let O;t[24]!==_?(O=Ie("absolute inset-0",_),t[24]=_,t[25]=O):O=t[25];const j=!i&&!g;let E;t[26]!==j?(E=s.jsx(Xs,{children:s.jsx(eu,{active:j})}),t[26]=j,t[27]=E):E=t[27];let L;t[28]!==O||t[29]!==E?(L=s.jsx("div",{className:O,children:E}),t[28]=O,t[29]=E,t[30]=L):L=t[30];let U;t[31]!==m||t[32]!==y||t[33]!==h?(U=m&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(g3,{isWindowed:!0,initialPrompt:y,onCreated:()=>h(!1),onCancel:()=>h(!1)})})}),t[31]=m,t[32]=y,t[33]=h,t[34]=U):U=t[34];let X;t[35]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(Xs,{children:s.jsx(Hk,{})}),t[35]=X):X=t[35];let Q;t[36]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Xs,{children:s.jsx(Kk,{})}),t[36]=Q):Q=t[36];let me;t[37]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(Xs,{children:s.jsx(s3,{})}),t[37]=me):me=t[37];let re;t[38]!==L||t[39]!==U?(re=s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[L,U,X,Q,me]}),t[38]=L,t[39]=U,t[40]=re):re=t[40];let G;t[41]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Rw,{}),t[41]=G):G=t[41];let ee;t[42]!==re?(ee=s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[re,G]})})}),t[42]=re,t[43]=ee):ee=t[43];let ue;t[44]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(Vw,{})})}),t[44]=ue):ue=t[44];let W;t[45]!==ee?(W=s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[T,s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[ee,ue]})]}),t[45]=ee,t[46]=W):W=t[46];let ne;t[47]!==V||t[48]!==W?(ne=s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[V,W]}),t[47]=V,t[48]=W,t[49]=ne):ne=t[49];let Y;t[50]!==i||t[51]!==o||t[52]!==l?(Y=l?s.jsx(c.Suspense,{fallback:null,children:s.jsx(I3,{open:i,onOpenChange:o})}):null,t[50]=i,t[51]=o,t[52]=l,t[53]=Y):Y=t[53];let F;return t[54]!==P||t[55]!==ne||t[56]!==Y?(F=s.jsx(Kp,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:"main-content-safe-area relative flex h-[100dvh] bg-background",children:[C,k,A,D,P,M,ne,Y]})}),t[54]=P,t[55]=ne,t[56]=Y,t[57]=F):F=t[57],F};function R3(t){return t.isSidebarOpen}function M3(t){return t.setIsMobile}function O3(t){return t.isSettingsDialogOpen}function B3(t){return t.setSettingsDialogOpen}function F3(t){return t.isMultiRunLauncherOpen}function _3(t){return t.setMultiRunLauncherOpen}function L3(t){return t.multiRunLauncherPrefillPrompt}function $3(t){return t.isScheduledTasksDialogOpen}function W3(t){return t.isArchivePageOpen}function z3(t){return t.worktreesPageProjectId}function V3(){return Ae.getState().closeMainSurfaces()}function U3(){const t=V3,e=qe.subscribe((n,r)=>{const i=!!n.currentSessionId&&n.currentSessionId!==r.currentSessionId,o=!!n.newSessionDraft?.open&&n.newSessionDraft!==r.newSessionDraft;(i||o)&&t()});return()=>{e()}}function H3(){return ku(!1)}function K3(){return ku(!0)}const xm=12,G3=[{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"}],q3=t=>{const e=Ye.c(18),{isActive:n,burstKey:r,className:i,durationMs:o,bursts:l,onComplete:a}=t,d=r===void 0?0:r,u=o===void 0?900:o,m=l===void 0?G3:l,h=it.useRef(!1);let y,b;e[0]!==n||e[1]!==a?(y=()=>{!n&&h.current&&a?.(),n&&(h.current=!0)},b=[n,a],e[0]=n,e[1]=a,e[2]=y,e[3]=b):(y=e[2],b=e[3]),it.useEffect(y,b);let S;e[4]===Symbol.for("react.memo_cache_sentinel")?(S=Array.from({length:xm},Q3),e[4]=S):S=e[4];const v=S;if(!n)return null;let g;e[5]!==i?(g=Ie("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=g):g=e[6];let f;if(e[7]!==d||e[8]!==m||e[9]!==u){let p;e[11]!==d||e[12]!==u?(p=w=>{const N={"--burst-delay":`${w.delay}ms`,"--burst-x":`${w.x}%`,"--burst-y":`${w.y}%`,"--firework-color":`var(${w.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:v.map((C,k)=>{const A=C.x*w.radius,D=C.y*w.radius,P={"--translate-x":`${A}px`,"--translate-y":`${D}px`,"--particle-delay":`${C.delay}ms`,color:`var(${w.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${w.id}-${k}-${d}`)})},`${w.id}-${d}`)},e[11]=d,e[12]=u,e[13]=p):p=e[13],f=m.map(p),e[7]=d,e[8]=m,e[9]=u,e[10]=f}else f=e[10];let x;return e[14]!==d||e[15]!==g||e[16]!==f?(x=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:f}),e[14]=d,e[15]=g,e[16]=f,e[17]=x):x=e[17],x};function Q3(t,e){const n=Math.PI*2*e/xm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Y3=t=>{const e=Ye.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={isActive:!1,cycle:0},e[2]=o):o=e[2];const[l,a]=it.useState(o),d=it.useRef(null);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=u):u=e[3];const m=u;let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{m(),a(X3)},e[4]=h):h=e[4];const y=h;let b;e[5]!==i?(b=()=>{m(),a(J3),d.current=window.setTimeout(()=>{a(Z3),d.current=null},i)},e[5]=i,e[6]=b):b=e[6];const S=b;let v,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),g=[m],e[7]=v,e[8]=g):(v=e[7],g=e[8]),it.useEffect(v,g);let f;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==S?(f={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:S,dismissFireworks:y},e[9]=l.cycle,e[10]=l.isActive,e[11]=S,e[12]=f):f=e[12],f};function X3(t){return t.isActive?{...t,isActive:!1}:t}function J3(t){return{isActive:!0,cycle:t.cycle+1}}function Z3(t){return t.isActive?{...t,isActive:!1}:t}const ym=c.createContext(void 0),e4=t=>{const e=Ye.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:o,dismissFireworks:l}=Y3();let a;e[0]!==l||e[1]!==o?(a={triggerFireworks:o,dismissFireworks:l},e[0]=l,e[1]=o,e[2]=a):a=e[2];const d=a;let u;e[3]!==i||e[4]!==r?(u=s.jsx(q3,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=u):u=e[5];let m;return e[6]!==n||e[7]!==u||e[8]!==d?(m=s.jsxs(ym.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=m):m=e[9],m},FC=()=>{const t=c.useContext(ym);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},pa="openchamber_requests_in_flight",wm=1e3,t4=300*1e3,Yo=Math.ceil(t4/wm),s4=()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(pa)==="1"}catch{return!1}},Sm=()=>({enabled:!0,startedAt:Date.now(),inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],peakAgeMs:0,inFlightStarts:new Map,sampleCount:0,lastSampleAt:null,fetchWrapped:!1,originalFetch:null,sampleTimer:null});let n4=1;const r4=(t,e)=>{const n=window.__openchamberRequestsInFlight__;!n||!n.enabled||(n.inFlight+=1,n.totalStarted+=1,n.inFlight>n.peak&&(n.peak=n.inFlight),n.inFlightStarts.set(t,e))},o4=t=>{const e=window.__openchamberRequestsInFlight__;!e||!e.enabled||(e.inFlight=Math.max(0,e.inFlight-1),e.totalSettled+=1,e.inFlightStarts.delete(t))},vm=t=>{if(t.inFlightStarts.size===0)return[];const e=Date.now(),n=[];for(const r of t.inFlightStarts.values())n.push(Math.max(0,e-r));return n.sort((r,i)=>r-i),n},Sr=(t,e)=>{const n=t.length;if(n===0)return 0;if(n===1)return t[0];const r=e/100*(n-1),i=Math.floor(r),o=Math.ceil(r);return i===o?t[i]:t[i]+(t[o]-t[i])*(r-i)},i4=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;if(!t||t.fetchWrapped)return;const e=window.fetch.bind(window);t.originalFetch=e,t.fetchWrapped=!0;const n=async(r,i)=>{const o=n4++;r4(o,Date.now());try{return await e(r,i)}finally{o4(o)}};window.fetch=n},Hc=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||!t.fetchWrapped||!t.originalFetch||(window.fetch=t.originalFetch,t.fetchWrapped=!1,t.originalFetch=null)},Rr=t=>{t.length>Yo&&t.splice(0,t.length-Yo)},a4=()=>{const t=window.__openchamberRequestsInFlight__;if(!t||!t.enabled)return;t.samples.push(t.inFlight);const e=vm(t),n=e.length>0?e[e.length-1]:0;t.p50Samples.push(Sr(e,50)),t.p90Samples.push(Sr(e,90)),t.p99Samples.push(Sr(e,99)),t.maxSamples.push(n),n>t.peakAgeMs&&(t.peakAgeMs=n),t.sampleCount+=1,Rr(t.samples),Rr(t.p50Samples),Rr(t.p90Samples),Rr(t.p99Samples),Rr(t.maxSamples),t.lastSampleAt=Date.now()},l4=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer!=null||(t.sampleTimer=window.setInterval(a4,wm))},Kc=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;!t||t.sampleTimer==null||(window.clearInterval(t.sampleTimer),t.sampleTimer=null)},Gc=t=>{if(!(typeof window>"u"))try{if(t){Kc(),Hc(),window.localStorage.setItem(pa,"1"),window.__openchamberRequestsInFlight__=Sm(),i4(),l4();return}window.localStorage.removeItem(pa),Kc(),Hc(),delete window.__openchamberRequestsInFlight__}catch{}},c4=()=>{if(typeof window>"u")return;const t=window.__openchamberRequestsInFlight__;if(!t)return;const e=Sm();t.startedAt=e.startedAt,t.inFlight=e.inFlight,t.peak=e.peak,t.totalStarted=e.totalStarted,t.totalSettled=e.totalSettled,t.samples=e.samples,t.p50Samples=e.p50Samples,t.p90Samples=e.p90Samples,t.p99Samples=e.p99Samples,t.maxSamples=e.maxSamples,t.peakAgeMs=e.peakAgeMs,t.inFlightStarts=e.inFlightStarts,t.sampleCount=e.sampleCount,t.lastSampleAt=e.lastSampleAt},ga=()=>{if(typeof window>"u")return qc();const t=window.__openchamberRequestsInFlight__;if(!s4()||!t)return qc();const e=vm(t);return{enabled:!0,startedAt:t.startedAt,durationMs:Math.max(0,Date.now()-t.startedAt),inFlight:t.inFlight,peak:t.peak,totalStarted:t.totalStarted,totalSettled:t.totalSettled,samples:t.samples.slice(),ageP50:Sr(e,50),ageP90:Sr(e,90),ageP99:Sr(e,99),ageMax:e.length>0?e[e.length-1]:0,peakAgeMs:t.peakAgeMs,p50Samples:t.p50Samples.slice(),p90Samples:t.p90Samples.slice(),p99Samples:t.p99Samples.slice(),maxSamples:t.maxSamples.slice(),sampleCount:t.sampleCount,lastSampleAt:t.lastSampleAt,windowSeconds:Yo}},qc=()=>({enabled:!1,startedAt:null,durationMs:0,inFlight:0,peak:0,totalStarted:0,totalSettled:0,samples:[],ageP50:0,ageP90:0,ageP99:0,ageMax:0,peakAgeMs:0,p50Samples:[],p90Samples:[],p99Samples:[],maxSamples:[],sampleCount:0,lastSampleAt:null,windowSeconds:Yo});function d4(t){switch(t){case"memory":return"database-2";case"streaming":return"bar-chart-box";case"requests":return"pulse"}}const jm=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},ba=t=>`${(t/1e3).toFixed(2)} s`,ks=t=>{const e=Ye.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let o;e[1]!==n?(o=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=o):o=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let a;return e[5]!==o||e[6]!==l?(a=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[o,l]}),e[5]=o,e[6]=l,e[7]=a):a=e[7],a},Qc=t=>{const e=Ye.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:o}=ht();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==o||e[6]!==n){const a=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(f4,0),e[8]=r.entries,e[9]=d):d=e[9];const u=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let h;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==o?(h=r.startedAt?jm(r.durationMs):o("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=o,e[15]=h):h=e[15];let y;e[16]!==h?(y=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:h}),e[16]=h,e[17]=y):y=e[17];let b;e[18]!==m||e[19]!==y?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,y]}),e[18]=m,e[19]=y,e[20]=b):b=e[20];let S;e[21]!==o?(S=o("memoryDebugPanel.metric.metrics"),e[21]=o,e[22]=S):S=e[22];let v;e[23]!==r.entries.length||e[24]!==S?(v=s.jsx(ks,{label:S,value:r.entries.length}),e[23]=r.entries.length,e[24]=S,e[25]=v):v=e[25];let g;e[26]!==o?(g=o("memoryDebugPanel.metric.samples"),e[26]=o,e[27]=g):g=e[27];let f;e[28]!==g||e[29]!==u?(f=s.jsx(ks,{label:g,value:u}),e[28]=g,e[29]=u,e[30]=f):f=e[30];let x;e[31]!==o?(x=o("memoryDebugPanel.metric.lastUpdate"),e[31]=o,e[32]=x):x=e[32];let p;e[33]!==r.lastUpdatedAt||e[34]!==o?(p=r.lastUpdatedAt?o("memoryDebugPanel.common.live"):o("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=o,e[35]=p):p=e[35];let w;e[36]!==x||e[37]!==p?(w=s.jsx(ks,{label:x,value:p}),e[36]=x,e[37]=p,e[38]=w):w=e[38];let N;e[39]!==f||e[40]!==w||e[41]!==v?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,f,w]}),e[39]=f,e[40]=w,e[41]=v,e[42]=N):N=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,N,a.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(An,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:a.map(C=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:C.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:o("memoryDebugPanel.metric.countValue",{value:C.count})}),s.jsx("span",{children:o("memoryDebugPanel.metric.avgValue",{value:C.avg})}),s.jsx("span",{children:o("memoryDebugPanel.metric.maxValue",{value:C.max})}),s.jsx("span",{children:o("memoryDebugPanel.metric.totalValue",{value:C.total})})]})]},C.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=o,e[6]=n,e[7]=l}else l=e[7];return l},Yc=t=>{const e=Ye.c(24),{series:n,peak:r,windowSeconds:i,ariaLabel:o,maxLabel:l}=t,a=i,d=n.reduce(h4,0),u=r>0?52/r:0;let m;e[0]!==d||e[1]!==a?(m=w=>a-d+w,e[0]=d,e[1]=a,e[2]=m):m=e[2];const h=m;let y;e[3]!==u?(y=w=>56-w*u,e[3]=u,e[4]=y):y=e[4];const b=y;let S;e[5]!==l?(S=s.jsx("span",{className:"pointer-events-none absolute left-0 top-0 typography-meta text-[var(--surface-muted-foreground)]",children:l}),e[5]=l,e[6]=S):S=e[6];const v=`0 0 ${a} 56`;let g;e[7]!==a?(g=s.jsx("line",{x1:0,y1:56,x2:a,y2:56,stroke:"var(--interactive-border)",strokeWidth:1,vectorEffect:"non-scaling-stroke"}),e[7]=a,e[8]=g):g=e[8];let f;if(e[9]!==n||e[10]!==h||e[11]!==b){let w;e[13]!==h||e[14]!==b?(w=(N,C)=>{const k=N.samples.length;if(k===0)return null;const A=N.samples.map((P,M)=>`${h(M)},${b(P).toFixed(2)}`),D=`M ${A.join(" L ")}`;return s.jsxs(c.Fragment,{children:[N.filled?s.jsx("path",{d:`M ${h(0)},56 L ${A.join(" L ")} L ${h(k-1)},56 Z`,fill:`color-mix(in srgb, ${N.color} 18%, transparent)`,stroke:"none"}):null,s.jsx("path",{d:D,fill:"none",stroke:N.color,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke"})]},C)},e[13]=h,e[14]=b,e[15]=w):w=e[15],f=n.map(w),e[9]=n,e[10]=h,e[11]=b,e[12]=f}else f=e[12];let x;e[16]!==o||e[17]!==v||e[18]!==g||e[19]!==f?(x=s.jsxs("svg",{viewBox:v,preserveAspectRatio:"none",className:"h-14 w-full",role:"img","aria-label":o,children:[g,f]}),e[16]=o,e[17]=v,e[18]=g,e[19]=f,e[20]=x):x=e[20];let p;return e[21]!==S||e[22]!==x?(p=s.jsxs("div",{className:"relative w-full",children:[S,x]}),e[21]=S,e[22]=x,e[23]=p):p=e[23],p},u4=t=>{const e=Ye.c(100),{onClose:n}=t,{t:r}=ht(),[i,o]=c.useState("memory"),[l,a]=c.useState("idle"),d=qe(p4),u=Fd(g4),m=kd(),h=qh(b4),y=Ys(x4),[b,S]=c.useState(y4),[v,g]=c.useState(w4),[f,x]=c.useState(S4),p=[{label:"p50",current:f.ageP50,samples:f.p50Samples,color:"var(--status-success)"},{label:"p90",current:f.ageP90,samples:f.p90Samples,color:"var(--status-info)"},{label:"p99",current:f.ageP99,samples:f.p99Samples,color:"var(--status-warning)"},{label:"max",current:f.ageMax,samples:f.maxSamples,color:"var(--status-error)"}];let w;e[0]!==f.samples?(w=f.samples.reduce(v4,0),e[0]=f.samples,e[1]=w):w=e[1];const N=w,C=p.reduce(k4,0);let k;e[2]!==b.entries?(k=new Map,b.entries.forEach(se=>{k.set(se.metric,se.count)}),e[2]=b.entries,e[3]=k):k=e[3];let A;e[4]!==k?(A=k.get("ui.message_list.render")??0,e[4]=k,e[5]=A):A=e[5];let D;e[6]!==k?(D=k.get("ui.message_list.render.streaming")??0,e[6]=k,e[7]=D):D=e[7];let P;e[8]!==k?(P=k.get("ui.chat_message.render")??0,e[8]=k,e[9]=P):P=e[9];let M;e[10]!==k?(M=k.get("ui.chat_message.render.streaming")??0,e[10]=k,e[11]=M):M=e[11];let z;e[12]!==k?(z=k.get("ui.chat_message.render.static_during_stream")??0,e[12]=k,e[13]=z):z=e[13];let I;e[14]!==k?(I=k.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[14]=k,e[15]=I):I=e[15];let V;e[16]!==A||e[17]!==D||e[18]!==P||e[19]!==M||e[20]!==z||e[21]!==I?(V={messageListRender:A,messageListRenderStreaming:D,chatMessageRender:P,chatMessageRenderStreaming:M,chatMessageRenderStaticDuringStream:z,chatMessageRenderStaticOutsideActiveTurnDuringStream:I},e[16]=A,e[17]=D,e[18]=P,e[19]=M,e[20]=z,e[21]=I,e[22]=V):V=e[22];const T=V;let _,O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{const se=()=>{S(vo()),g(jo()),x(ga())};se();const we=window.setInterval(se,500);return()=>window.clearInterval(we)},_=[],e[23]=_,e[24]=O):(_=e[23],O=e[24]),c.useEffect(O,_);let j,E;e[25]!==l?(j=()=>{if(l==="idle")return;const se=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(se)},E=[l],e[25]=l,e[26]=j,e[27]=E):(j=e[26],E=e[27]),c.useEffect(j,E);let L=0,U=0,X=0;for(const se of Object.keys(h)){const we=h[se]??[];U=U+we.length;for(const Ke of we)Ke.role==="user"?X=X+1:Ke.role==="assistant"&&(L=L+1)}let Q;e[28]!==L||e[29]!==U||e[30]!==X?(Q={assistant:L,total:U,user:X},e[28]=L,e[29]=U,e[30]=X,e[31]=Q):Q=e[31];const me=Q;let re;if(e[32]!==d||e[33]!==h||e[34]!==u||e[35]!==m||e[36]!==r){let se;e[38]!==d||e[39]!==h||e[40]!==u||e[41]!==r?(se=we=>{const Ke=h[we.id]??[];let Qe=0,He=0;for(const K of Ke)K.role==="user"?He=He+1:K.role==="assistant"&&(Qe=Qe+1);const le=u.get(we.id);return{id:we.id,title:we.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:Qe,messageCount:Ke.length,userMessageCount:He,isStreaming:le?.isStreaming||!1,isZombie:le?.isZombie||!1,backgroundCount:le?.backgroundMessageCount||0,lastAccessed:le?.lastAccessedAt||0,isCurrent:we.id===d}},e[38]=d,e[39]=h,e[40]=u,e[41]=r,e[42]=se):se=e[42],re=m.map(se).sort(C4),e[32]=d,e[33]=h,e[34]=u,e[35]=m,e[36]=r,e[37]=re}else re=e[37];const G=re;let ee;e[43]!==h?(ee=Object.keys(h),e[43]=h,e[44]=ee):ee=e[44];const ue=ee.length;let W;e[45]===Symbol.for("react.memo_cache_sentinel")?(W=async()=>{try{const se={generatedAt:new Date().toISOString(),ui:vo(),vscode:jo()};await navigator.clipboard.writeText(JSON.stringify(se,null,2)),a("copied")}catch{a("error")}},e[45]=W):W=e[45];const ne=W,Y=Yh,F="fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area";let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let ie;e[47]!==i?(ie=d4(i),e[47]=i,e[48]=ie):ie=e[48];let xe;e[49]!==ie?(xe=s.jsx(R,{name:ie,className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[49]=ie,e[50]=xe):xe=e[50];let ge;e[51]!==r?(ge=r("memoryDebugPanel.title"),e[51]=r,e[52]=ge):ge=e[52];let Ce;e[53]!==ge?(Ce=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ge}),e[53]=ge,e[54]=Ce):Ce=e[54];let Re;e[55]!==xe||e[56]!==Ce?(Re=s.jsxs("div",{className:"flex items-center gap-2",children:[xe,Ce]}),e[55]=xe,e[56]=Ce,e[57]=Re):Re=e[57];let ce;e[58]!==i?(ce=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(at,{size:"xs",variant:"ghost",onClick:ne,children:s.jsx(R,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(at,{size:"xs",variant:"ghost",onClick:()=>{Um(),S(vo()),g(jo())},children:s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[58]=i,e[59]=ce):ce=e[59];let ye;e[60]!==i?(ye=i==="requests"?s.jsx(at,{size:"xs",variant:"ghost",onClick:()=>{c4(),x(ga())},children:s.jsx(R,{name:"refresh",className:"h-3.5 w-3.5"})}):null,e[60]=i,e[61]=ye):ye=e[61];let be;e[62]!==n?(be=n?s.jsx(at,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(R,{name:"close",className:"h-4 w-4"})}):null,e[62]=n,e[63]=be):be=e[63];let te;e[64]!==ce||e[65]!==ye||e[66]!==be?(te=s.jsxs("div",{className:"flex items-center gap-1",children:[ce,ye,be]}),e[64]=ce,e[65]=ye,e[66]=be,e[67]=te):te=e[67];let pe;e[68]!==Re||e[69]!==te?(pe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Re,te]}),e[68]=Re,e[69]=te,e[70]=pe):pe=e[70];let Pe;e[71]===Symbol.for("react.memo_cache_sentinel")?(Pe={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[71]=Pe):Pe=e[71];const de=i==="memory"?"secondary":"ghost";let he;e[72]===Symbol.for("react.memo_cache_sentinel")?(he=()=>o("memory"),e[72]=he):he=e[72];let fe;e[73]!==r?(fe=r("memoryDebugPanel.tabs.memory"),e[73]=r,e[74]=fe):fe=e[74];let B;e[75]!==de||e[76]!==fe?(B=s.jsx(at,{size:"sm",variant:de,className:"flex-1",onClick:he,children:fe}),e[75]=de,e[76]=fe,e[77]=B):B=e[77];const H=i==="streaming"?"secondary":"ghost";let ke;e[78]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>o("streaming"),e[78]=ke):ke=e[78];let Se;e[79]!==r?(Se=r("memoryDebugPanel.tabs.streaming"),e[79]=r,e[80]=Se):Se=e[80];let Be;e[81]!==H||e[82]!==Se?(Be=s.jsx(at,{size:"sm",variant:H,className:"flex-1",onClick:ke,children:Se}),e[81]=H,e[82]=Se,e[83]=Be):Be=e[83];const _e=i==="requests"?"secondary":"ghost";let Te;e[84]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>o("requests"),e[84]=Te):Te=e[84];let Z;e[85]!==r?(Z=r("memoryDebugPanel.tabs.requests"),e[85]=r,e[86]=Z):Z=e[86];let Ne;e[87]!==_e||e[88]!==Z?(Ne=s.jsx(at,{size:"sm",variant:_e,className:"flex-1",onClick:Te,children:Z}),e[87]=_e,e[88]=Z,e[89]=Ne):Ne=e[89];let Me;e[90]!==B||e[91]!==Be||e[92]!==Ne?(Me=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:Pe,children:[B,Be,Ne]}),e[90]=B,e[91]=Be,e[92]=Ne,e[93]=Me):Me=e[93];const $=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ks,{label:r("memoryDebugPanel.metric.totalMessages"),value:me.total}),s.jsx(ks,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${ue} / ${gl.MAX_SESSIONS}`}),s.jsx(ks,{label:r("memoryDebugPanel.metric.userMessages"),value:me.user}),s.jsx(ks,{label:r("memoryDebugPanel.metric.assistantMessages"),value:me.assistant})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:Qh()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:gl.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:y})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(An,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:G.map(se=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:se.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:se.title}),se.isStreaming?s.jsx(R,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,se.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:se.assistantMessageCount,user:se.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:se.messageCount})}),se.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",se.backgroundCount]}):null]})]},se.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(yt,{children:[s.jsx(bt,{asChild:!0,children:s.jsx(at,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(N4),currentSessionId:d,cachedSessions:Object.keys(h),messageRoleCounts:me,sessionMessageRoleCounts:G.map(A4),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(xt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):i==="streaming"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(at,{size:"xs",variant:"outline",onClick:ne,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(ks,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(ks,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(ks,{label:r("memoryDebugPanel.metric.messageListRenders"),value:T.messageListRender}),s.jsx(ks,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:T.messageListRenderStreaming}),s.jsx(ks,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:T.chatMessageRender}),s.jsx(ks,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:T.chatMessageRenderStreaming}),s.jsx(ks,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:T.chatMessageRenderStaticDuringStream}),s.jsx(ks,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:T.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Qc,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Qc,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(ks,{label:r("memoryDebugPanel.requests.totalRequests"),value:`${f.totalSettled} / ${f.totalStarted}`}),s.jsx(ks,{label:r("memoryDebugPanel.requests.tracking"),value:f.startedAt?jm(f.durationMs):r("memoryDebugPanel.common.idle")})]}),f.samples.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:r("memoryDebugPanel.requests.noSamples")}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.inFlight")}),s.jsxs("span",{children:[s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:f.inFlight}),s.jsxs("span",{className:"text-[var(--surface-muted-foreground)]",children:[" · ",r("memoryDebugPanel.requests.peak")," "]}),s.jsx("span",{className:"font-medium text-[var(--surface-foreground)]",children:f.peak})]})]}),s.jsx(Yc,{series:[{samples:f.samples,color:"var(--status-info)",filled:!0}],peak:N,windowSeconds:f.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.chartLabel",{peak:f.peak}),maxLabel:`${N}`}),s.jsxs("div",{className:"flex items-center justify-between typography-meta",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.requests.duration")}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ba(f.peakAgeMs)})]}),s.jsx(Yc,{series:p.map(D4),peak:C,windowSeconds:f.windowSeconds,ariaLabel:r("memoryDebugPanel.requests.percentileChartLabel"),maxLabel:ba(C)}),s.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-meta",children:p.map(P4)}),s.jsxs("div",{className:"flex items-center justify-between typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r("memoryDebugPanel.requests.windowHint",{seconds:f.windowSeconds})}),s.jsx("span",{children:r("memoryDebugPanel.requests.now")})]})]})]});let ae;return e[94]!==Y||e[95]!==J||e[96]!==pe||e[97]!==Me||e[98]!==$?(ae=s.jsxs(Y,{className:F,style:J,children:[pe,Me,$]}),e[94]=Y,e[95]=J,e[96]=pe,e[97]=Me,e[98]=$,e[99]=ae):ae=e[99],ae},m4=u4;function f4(t,e){return t+e.count}function h4(t,e){return Math.max(t,e.samples.length)}function p4(t){return t.currentSessionId}function g4(t){return t.sessionMemoryState}function b4(t){return t.message}function x4(t){return t.totalRequestCount}function y4(){return vo()}function w4(){return jo()}function S4(){return ga()}function v4(t,e){return Math.max(t,e)}function j4(t,e){return Math.max(t,e)}function k4(t,e){return e.samples.reduce(j4,t)}function C4(t,e){return e.lastAccessed-t.lastAccessed}function N4(t){return{id:t.id,title:t.title}}function A4(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}function D4(t){return{samples:t.samples,color:t.color}}function P4(t){return s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:t.color}}),s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:t.label}),s.jsx("span",{className:"font-medium tabular-nums text-[var(--surface-foreground)]",children:ba(t.current)})]},t.label)}const T4=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},I4=async()=>{const t=T4()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},Xc="openchamber:menu-action",Ai="openchamber:check-for-updates",E4=t=>{const e=qe(f=>f.openNewSessionDraft),n=Ae(f=>f.toggleCommandPalette),r=Ae(f=>f.setCommandPaletteOpen),i=Ae(f=>f.toggleHelpDialog),o=Ae(f=>f.toggleSidebar),l=Ae(f=>f.setSessionSwitcherOpen),a=Ae(f=>f.setSettingsDialogOpen),d=Ae(f=>f.setAboutDialogOpen),u=_r(f=>f.checkForUpdates),{setThemeMode:m}=nr(),h=c.useRef(!1),y=c.useCallback(()=>{h.current||(h.current=!0,u().then(()=>{const{available:f,error:x}=_r.getState();if(x){Oe.error("Failed to check for updates",{description:x});return}f||Oe.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[u]),b=c.useCallback(()=>{yn.requestDirectoryDialog()},[]),S=c.useCallback(f=>{const x=Dd();if(x.length===0)return;const p=qe.getState().currentSessionId,w=x.findIndex(k=>k.id===p);let N=f>0?0:x.length-1;w>=0&&(N=(w+f+x.length)%x.length);const C=x[N];C&&(l(!1),qe.getState().setCurrentSession(C.id))},[l]),v=c.useCallback(f=>{const{activeProjectId:x,projects:p,setActiveProject:w}=Ht.getState();if(p.length===0)return;const N=p.findIndex(A=>A.id===x);let C=f>0?0:p.length-1;N>=0&&(C=(N+f+p.length)%p.length);const k=p[C];k&&w(k.id)},[]),g=c.useCallback(f=>{switch(f){case"about":d(!0);break;case"settings":a(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l(!1);{const x=qe.getState(),p=ss.getState().currentDirectory;e(x.currentSessionId&&p?{directoryOverride:p}:void 0)}break;case"new-worktree-session":l(!1),Id();break;case"change-workspace":b();break;case"toggle-right-sidebar":{const x=ss.getState().currentDirectory;if(!x)break;const p=Ae.getState(),w=cr(x),N=p.contextPanelByDirectory[w];N?.isOpen?p.closeContextPanel(w):N?.activeTabId?p.setActiveContextPanelTab(w,N.activeTabId):p.openContextSurface(w,"git");break}case"open-right-sidebar-git":{const x=ss.getState().currentDirectory;if(!x)break;Ae.getState().openContextSurface(cr(x),"git");break}case"open-right-sidebar-files":{const x=ss.getState().currentDirectory;if(!x)break;Ae.getState().openContextSurface(cr(x),"file");break}case"toggle-terminal":{const x=ss.getState().currentDirectory;if(!x)break;Ae.getState().openContextSurface(cr(x),"terminal");break}case"toggle-terminal-expanded":{const x=ss.getState().currentDirectory;if(!x)break;const p=cr(x),w=Ae.getState(),N=w.contextPanelByDirectory[p];(N?.isOpen?N.tabs.find(k=>k.id===N.activeTabId)?.mode:null)!=="terminal"&&w.openContextSurface(p,"terminal"),w.toggleContextPanelExpanded(p);break}case"copy":{const x=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(x)||I4();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"add-selection-to-chat":Xh();break;case"toggle-sidebar":o();break;case"toggle-memory-debug":t?.();break;case"go-back":ss.getState().goBack();break;case"go-forward":ss.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":v(-1);break;case"next-project":v(1);break;case"help-dialog":i();break;case"download-logs":{nm().catch(()=>{Oe.error("Failed to collect OpenCode status")});break}}},[b,v,S,t,e,d,l,r,a,m,n,i,o]);c.useEffect(()=>{const f=p=>{const w=p.detail;w&&g(w)},x=()=>{y()};return window.addEventListener(Xc,f),window.addEventListener(Ai,x),()=>{window.removeEventListener(Xc,f),window.removeEventListener(Ai,x)}},[g,y]),c.useEffect(()=>{if(typeof window>"u")return;const x=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof x!="function")return;let p=null,w=null;return x("openchamber:menu-action",N=>{const C=N?.payload;typeof C=="string"&&g(C)}).then(N=>{p=N}).catch(()=>{}),x("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Ai))}).then(N=>{w=N}).catch(()=>{}),()=>{(async()=>{try{const C=p?.();C instanceof Promise&&await C}catch{}try{const C=w?.();C instanceof Promise&&await C}catch{}})()}},[g])},R4="openchamber:tray-action",Jc=5e3,M4=500,km=20,Zc=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},ed=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,O4=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},B4=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Cm=(t,e)=>$d(t,e,Vr.getState().ids,Da.getState().rankById),F4=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},_4=(t,e,n,r,i)=>{if(!t)return"";const o=ep(n,r,t),l=e.project?.name,a=o?.label?.trim()||l?.trim()||F4(t),d=No(t);let u=d&&i.get(d)||"";if(!u){for(const[m,h]of $n.getState().directories)if(No(m)===d){u=h.status?.current??"";break}}if(!u)for(const m of r.values()){const h=m.find(y=>No(y.path)===d);if(h?.branch){u=h.branch;break}}return u?`${a} · ${u}`:a},L4=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=dr.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const i=new Map(t.map(l=>[l.providerId,l])),o=[];for(const l of tp){if(!e.includes(l.id))continue;const a=i.get(l.id);if(!a||a.configured!==!0)continue;const d=[];for(const[m,h]of Object.entries(a.usage?.windows??{})){const y=r==="remaining"?h.remainingPercent:h.usedPercent;d.push({label:np(m),value:sp(h.valueLabel,y)})}const u=!a.ok&&a.error?a.error:d.length===0?"No rate limits reported":null;o.push({provider:l.name,rows:d,status:u})}return{mode:r,groups:o}},$4=async()=>{try{if(Xo())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=Ln();if(e&&Ya(e,t))return"Local OpenChamber";const r=(await ad()).hosts.find(i=>e?Ya(e,Hm(i)):!1);return r?.label?.trim()?ld(r.label.trim()):"Instance"}catch{return""}},W4=()=>{const t=new Map,e=new Map,n=[],r=new Map;let i;try{i=Lo()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[o,l]of i.children.entries()){const a=l.getState();a.vcs?.branch&&e.set(No(o)??o,a.vcs.branch);for(const d of a.session)d?.id&&r.set(d.id,d.title);for(const[d,u]of Object.entries(a.session_status??{})){const m=u?.type,h=m==="busy"?"busy":m==="retry"?"retry":"idle",y=t.get(d);(!y||y==="idle")&&t.set(d,h)}for(const[d,u]of Object.entries(a.permission??{}))for(const m of u??[]){if(!m?.id)continue;const h=m.sessionID||d;n.push({kind:"permission",id:m.id,sessionId:h,sessionTitle:"",label:O4(m),directory:o})}for(const[d,u]of Object.entries(a.question??{}))for(const m of u??[]){if(!m?.id)continue;const h=m.sessionID||d;n.push({kind:"question",id:m.id,sessionId:h,sessionTitle:"",label:B4(m),directory:o})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},z4=()=>{const t=Es.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(Cm).slice(0,km).forEach(r=>{const i=Us(r);i&&e.add(i)});const n=new Map;for(const r of t){if(!r?.id)continue;const i=Us(r);if(!i||!e.has(i))continue;const o=n.get(i)??[];o.push(r.id),n.set(i,o)}return n},V4=t=>{const e=W4(),n=Ra.getState().index.session,r=Es.getState().activeSessions,i=new Map(e.titleById),o=new Map;for(const g of r)if(g?.id&&(g.title&&i.set(g.id,g.title),g.parentID)){const f=o.get(g.parentID)??[];f.push(g.id),o.set(g.parentID,f)}const l=g=>{const f=[],x=[...o.get(g)??[]],p=new Set;for(;x.length;){const w=x.pop();p.has(w)||(p.add(w),f.push(w),x.push(...o.get(w)??[]))}return f},a=Ea.getState().statusById,d=g=>{const f=e.statusById.get(g);return f&&f!=="idle"?f:a.get(g)?.status.type??f??"idle"},u=g=>{const f=g.map(x=>d(x));return f.includes("busy")?"busy":f.includes("retry")?"retry":"idle"},m=Ht.getState().projects,h=qe.getState().availableWorktreesByProject,y=r.filter(g=>g?.id&&!g.parentID).slice().sort(Cm).slice(0,km).map(g=>{const f=[g.id,...l(g.id)],x=Us(g)??"";return{id:g.id,title:g.title||"Untitled session",status:u(f),branch:x?e.branchByDirectory.get(x)??"":"",unseen:f.reduce((p,w)=>p+(n.unseenCount[w]??0),0),hasError:f.some(p=>n.unseenHasError[p]??!1),directory:x,subtitle:_4(x,g,m,h,e.branchByDirectory)}}),b=e.approvals.map(g=>({...g,sessionTitle:i.get(g.sessionId)||""})),S=Ae.getState();let v=0;if(S.dockBadgeEnabled)for(const g of r){if(!g?.id||g.parentID)continue;let f=n.unseenCount[g.id]??0;f===0&&S.notifyOnSubtasks&&(f=l(g.id).reduce((x,p)=>x+(n.unseenCount[p]??0),0)),f>0&&(v+=1)}return{sessions:y,approvals:b,instanceName:t,usage:L4(),dockBadgeCount:v}},U4=()=>{c.useEffect(()=>{if(!Zc()||!ed()||!Zo())return;let t=!1,e="",n=null,r="";const i=()=>{if(t)return;const C=V4(r),k=JSON.stringify(C);k!==e&&(e=k,Fn("desktop_tray_update",C))};$4().then(C=>{t||(r=C,i())});const o=async()=>{const C=z4();await Promise.all([...C.entries()].map(async([k,A])=>{const D=await _s.getSessionStatusForDirectory(k).catch(()=>null);t||D===null||Jh(k,D,A)}))},l=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,i()},M4))},a=new Map,d=()=>{if(t)return;let C;try{C=Lo()}catch{return}const k=new Set;for(const[A,D]of C.children.entries())k.add(A),a.has(A)||a.set(A,D.subscribe(()=>l()));for(const[A,D]of a)k.has(A)||(D(),a.delete(A))};let u=null;try{u=Lo().subscribeRegistry(()=>{d(),l()})}catch{}d();const m=Ra.subscribe(()=>l()),h=Es.subscribe(()=>l()),y=Ht.subscribe(()=>l()),b=qe.subscribe(()=>l()),S=$n.subscribe(()=>l()),v=Ae.subscribe(()=>l()),g=Ea.subscribe(()=>l()),f=Da.subscribe(()=>l()),x=Vr.subscribe(()=>l());o();const p=window.setInterval(()=>{o()},Jc),w=dr.subscribe(()=>l());dr.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:C,results:k}=dr.getState();C.length>0&&C.some(D=>!k.some(P=>P.providerId===D))&&dr.getState().fetchQuotas(C)});const N=window.setInterval(()=>{d(),i()},Jc);return i(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(N),window.clearInterval(p),m(),h(),y(),b(),S(),v(),g(),f(),x(),w(),u?.();for(const C of a.values())C();a.clear()}},[]),c.useEffect(()=>{if(!Zc()||!ed()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=i=>{i.type==="respond-permission"&&Zh(i.sessionId,i.id,i.response).catch(()=>{Oe.error("Failed to respond to permission request")})};let r=null;return e(R4,i=>{const o=i?.payload;!o||typeof o!="object"||typeof o.type!="string"||n(o)}).then(i=>{r=i}).catch(()=>{}),()=>{try{const i=r?.();i instanceof Promise&&i.catch(()=>{})}catch{}}},[])},H4=45e3,K4=(t,e,n=window.setInterval.bind(window),r=window.clearInterval.bind(window))=>{t();const i=n(e,H4);return()=>r(i)},G4=t=>{const e=Ye.c(3);let n,r;e[0]!==t?(n=()=>{if(t)return K4(q4,Q4)},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),c.useEffect(n,r)};function q4(){rp($o())}function Q4(){Ba()}const Y4="/api/notifications/stream",X4=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),J4=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},Z4=t=>{const e=Ye.c(3),n=t?.enabled??!0;let r,i;e[0]!==n?(r=()=>{if(!n||wn()||!ya()||typeof window>"u"||typeof EventSource>"u")return;const o=new EventSource(xa().sse(Y4));return o.onmessage=eC,()=>{o.close()}},i=[n],e[0]=n,e[1]=r,e[2]=i):(r=e[1],i=e[2]),c.useEffect(r,i)};function eC(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Ae.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&X4())return;const r=J4(e);if(!r)return;Jo()?.notifications?.notifyAgentCompletion(r)}const tC=t=>{const e=Ye.c(10),n=Ae(sC),r=op(nC),o=Gp(t)?.path??null;let l,a;e[0]!==n||e[1]!==r||e[2]!==o?(l=()=>{n&&r(o)},a=[n,r,o],e[0]=n,e[1]=r,e[2]=o,e[3]=l,e[4]=a):(l=e[3],a=e[4]),c.useEffect(l,a);let d,u;e[5]!==n||e[6]!==r||e[7]!==o?(d=()=>{if(n)return no(m=>{m.type==="agent-memory-changed"&&r(o)})},u=[n,r,o],e[5]=n,e[6]=r,e[7]=o,e[8]=d,e[9]=u):(d=e[8],u=e[9]),c.useEffect(d,u)};function sC(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function nC(t){return t.load}const td="pwa-install-toast-shown",sd="pwa-install-toast-dismissed",rC=()=>{const t=Ye.c(6),{browserTab:e}=qp(),{t:n}=ht(),r=c.useRef(n);let i,o;t[0]!==n?(i=()=>{r.current=n},o=[n],t[0]=n,t[1]=i,t[2]=o):(i=t[1],o=t[2]),c.useEffect(i,o);let l,a;t[3]!==e?(l=()=>{if(typeof window>"u"||!ya()||!e)return;let d=null,u=null;const m=()=>{u!==null&&(Oe.dismiss(u),u=null)},h=async()=>{if(!d)return;const S=d;d=null,m(),await S.prompt();const{outcome:v}=await S.userChoice;v==="accepted"&&Oe.success(r.current("pwa.installPrompt.started"))},y=S=>{const v=S;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const g=Fo(),f=Km();Qp({dismissed:g.getItem(sd),sessionShown:f.getItem(td),hasActiveToast:u!==null})&&(f.setItem(td,"true"),u=Oe.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{h()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Fo().setItem(sd,"true"),m()}}}))},b=()=>{d=null,m(),Oe.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",y),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",y),window.removeEventListener("appinstalled",b)}},a=[e],t[3]=e,t[4]=l,t[5]=a):(l=t[4],a=t[5]),c.useEffect(l,a)},oC=({open:t,onOpenChange:e})=>{const{t:n}=ht(),r=!1,[i,o]=c.useState(null),[l,a]=c.useState(null),[d,u]=c.useState(!1),[m,h]=c.useState(!1),[y,b]=c.useState(null),[S,v]=c.useState(!1);c.useCallback(async()=>{},[y,d,r,n]),c.useEffect(()=>{if(!t)return;(async()=>{try{const x=await rs("/api/system/info");if(x.ok){const p=await x.json();if(typeof p.openchamberVersion=="string"&&p.openchamberVersion.trim()){o(p.openchamberVersion);return}}}catch{}o(await ip())})()},[t]),c.useEffect(()=>{if(!t)return;let f=!1;return(async()=>{try{const p=await rs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!p.ok)return;const w=await p.json().catch(()=>null),N=typeof w?.currentVersion=="string"?w.currentVersion.trim():"";!f&&N&&a(N)}catch{}})(),()=>{f=!0}},[t]),c.useEffect(()=>{{b(null),v(!1);return}},[t,r]);const g=i;return s.jsx(Ns,{open:t,onOpenChange:e,children:s.jsx(As,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Cd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[g&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:g})}),l&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:l})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(R,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},nd=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},Di=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},iC=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},aC=()=>{const t=ap(a=>a.completeAuth),[e,n]=c.useState("working"),[r,i]=c.useState(!1),[o,l]=c.useState("Completing MCP authorization...");return c.useEffect(()=>{if(typeof window>"u"){n("error"),l("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),d=Di(a,"code"),u=lp(a),m=cp(a),h=Di(a,"error"),y=Di(a,"error_description");if(h){m&&rs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(y??h);return}(async()=>{try{if(!d)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let b=u,S=!1;if(m){const v=await rs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`);if(v.ok){const g=await v.json().catch(()=>null);S=g?.origin===dp,i(S),!b&&g?.name?.trim()&&(b={name:g.name.trim(),directory:typeof g.directory=="string"&&g.directory.trim()?g.directory.trim():null})}}if(!b?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(b.name,d,b.directory),m&&await rs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("success"),S&&nd(!0),l("Authorization completed. You can close this tab and return to OpenChamber.")}catch(b){m&&await rs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),l(iC(b,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("h1",{className:up,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:Ie("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:o})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(at,{type:"button",onClick:()=>nd(r),children:"Return to OpenChamber"})})]})})},rd=rr(()=>sr(()=>import("./OnboardingScreen-C98d69Fp.js"),__vite__mapDeps([143,1,2,4,5,6,7,8,9,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(t=>({default:t.OnboardingScreen}))),lC=()=>{const t=Ye.c(3),e=Ae(hC),n=Ae(pC);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(oC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},cC=t=>{const e=Ye.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=ht();let o;e[0]!==i?(o=i("startup.initRecovery.title"),e[0]=i,e[1]=o):o=e[1];let l;e[2]!==o?(l=s.jsx("h1",{className:"typography-title text-foreground",children:o}),e[2]=o,e[3]=l):l=e[3];let a;e[4]!==i?(a=i("startup.initRecovery.description"),e[4]=i,e[5]=a):a=e[5];let d;e[6]!==a?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:a}),e[6]=a,e[7]=d):d=e[7];let u;e[8]!==l||e[9]!==d?(u=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=u):u=e[10];let m;e[11]!==r||e[12]!==i?(m=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=m):m=e[13];let h;e[14]!==r||e[15]!==n||e[16]!==m?(h=s.jsx(at,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=h):h=e[17];let y;return e[18]!==u||e[19]!==h?(y=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[u,h]})}),e[18]=u,e[19]=h,e[20]=y):y=e[20],y},od=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",dC=()=>{if(typeof window>"u"||!yg())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true",allowPromptingSubagentSessions:t.has("allowPromptingSubagentSessions")?t.get("allowPromptingSubagentSessions")==="1":void 0}},uC=()=>typeof window>"u"?!1:window.location.pathname===gp,mC=t=>{const e=Ye.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,o=ss(gC),l=qe(bC),a=qe(xC),d=Sd(),u=c.useRef(null);let m;e[0]!==n.directory?(m=od(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const h=m;let y;e[2]!==o?(y=od(o),e[2]=o,e[3]=y):y=e[3];const b=y;let S,v;if(e[4]!==b||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==h||e[9]!==r||e[10]!==a||e[11]!==d?(S=()=>{if(r||h&&b!==h)return;const N=`${h}
|
|
926
|
-
${n.sessionId}`;u.current===N&&l||(u.current=N,a(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,l,n.directory,n.sessionId,h,r,a,d],e[4]=b,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=h,e[9]=r,e[10]=a,e[11]=d,e[12]=S,e[13]=v):(S=e[12],v=e[13]),c.useEffect(S,v),h&&b!==h)return null;let g;e[14]!==i?(g=s.jsx(Ud,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=g):g=e[15];let f;e[16]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(tu,{}),e[16]=f):f=e[16];let x;e[17]!==i||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(x=s.jsx(eu,{active:i,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=i,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=x):x=e[20];let p;e[21]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(Hd,{}),e[21]=p):p=e[21];let w;return e[22]!==g||e[23]!==x?(w=s.jsxs(s.Fragment,{children:[g,f,x,p]}),e[22]=g,e[23]=x,e[24]=w):w=e[24],w};function fC({apis:t}){c.useEffect(()=>{Gm("App:mounted"),qm()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Kt(F=>F.initializeApp),n=Kt(F=>F.isInitialized),r=Kt(F=>F.isConnected),i=Kt(F=>F.providers.length),o=Kt(F=>F.agents.length),l=Kt(F=>F.loadProviders),a=Kt(F=>F.loadAgents),d=qe(F=>F.error),u=qe(F=>F.clearError),m=ss(F=>F.currentDirectory),h=ss(F=>F.setDirectory),y=ss(F=>F.isSwitchingDirectory),[b,S]=c.useState(!1),v=er(F=>F.refreshStatus),[g,f]=c.useState(()=>t.runtime.isVSCode),[x,p]=c.useState(!1),[w,N]=c.useState(!1),[C,k]=c.useState(0),[A,D]=c.useState(0),[P,M]=c.useState(!1),z=Ae(F=>F.wideChatLayoutEnabled),I=Ae(F=>F.mobileKeyboardMode),V=c.useMemo(()=>wn(),[]),T=ja(F=>F.setPlanModeEnabled),[_,O]=c.useState(()=>Xa()),[j,E]=c.useState(()=>{const F=Ja();return F!==null?Za({isDesktopShell:!0,bootOutcome:F}):null}),L=c.useRef(!1),U=c.useMemo(()=>dC(),[]),X=!U||x,Q=c.useMemo(()=>uC(),[]);c.useEffect(()=>(el(b),()=>{el(!1)}),[b]),c.useEffect(()=>(Gc(b),()=>{Gc(!1)}),[b]),c.useEffect(()=>{Qm(I)},[I]),c.useEffect(()=>{f(t.runtime.isVSCode)},[t.runtime.isVSCode]),c.useEffect(()=>ei(F=>{Yp(F),D(J=>J+1),N(!1),k(J=>J+1)}),[]);const me=bl(F=>{const J=Cs();return Object.values(F.runsByOriginalSessionID).filter(ie=>ie.status==="running"&&ie.runtimeKey===J).map(ie=>`${ie.originalSessionID}:${ie.phase}:${ie.lastForwardedMessageID??""}:${ie.expectedAssistantParentID??""}`).sort().join("|")});c.useEffect(()=>{if(U)return;const F=Cs(),J=Object.values(bl.getState().runsByOriginalSessionID).filter(ie=>ie.status==="running"&&ie.runtimeKey===F);for(const ie of J)mp(ie.originalSessionID)},[me,U,A]),c.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",z),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[z]),c.useEffect(()=>(tl(t),()=>tl(null)),[t]),c.useEffect(()=>{U||v(t.github,{force:!0})},[t.github,U,v]),fp();const re=_==="valid",G=j?.screen==="main";c.useEffect(()=>{if(!Ym({isDesktopShell:V,isInitialized:n,bootOutcomeKnown:re,bootViewIsMain:G}))return;const F=setTimeout(()=>{const J=document.getElementById("initial-loading");J&&(J.classList.add("fade-out"),setTimeout(()=>{J.remove()},300))},150);return()=>clearTimeout(F)},[V,n,re,G]),c.useEffect(()=>{if(!V||_!=="malformed")return;const F=document.getElementById("initial-loading");F&&(F.textContent="Desktop startup failed — please restart the app.")},[V,_]),c.useEffect(()=>{if(V)return;const F=setTimeout(()=>{const J=document.getElementById("initial-loading");J&&!n&&(J.classList.add("fade-out"),setTimeout(()=>{J.remove()},300))},5e3);return()=>clearTimeout(F)},[V,n]),c.useEffect(()=>{let F=!1;return(async()=>{const ie=await rs("/health",{method:"GET"}).catch(()=>null);if(!ie||!ie.ok||F)return;const xe=await ie.json().catch(()=>null);if(!xe||F)return;const ge=xe.planModeExperimentalEnabled;T(ge===!0||ge===1||ge==="1"||ge==="true")})(),()=>{F=!0}},[T]),c.useEffect(()=>{g||e()},[e,g]),c.useEffect(()=>{if(g||n)return;let F=!0,J,ie=0;const xe=10,ge=1e3,Ce=async()=>{if(!F)return;if(ie>=xe){N(!0);return}const Re=Kt.getState();if(Re.isInitialized){N(!1);return}ie+=1,await Re.initializeApp();const ce=Kt.getState();if(!F)return;if(ce.isInitialized){N(!1);return}if(ie>=xe){N(!0);return}const ye=Math.min(ge*Math.pow(2,ie-1),16e3);J=setTimeout(Ce,ye)};return J=setTimeout(Ce,ge),()=>{F=!1,J&&clearTimeout(J)}},[C,n,g]),c.useEffect(()=>{n&&N(!1)},[n]),c.useEffect(()=>{if(!w)return;const F=document.getElementById("initial-loading");F&&(F.classList.add("fade-out"),setTimeout(()=>{F.remove()},300))},[w]),c.useEffect(()=>{if(g||!r||i>0&&o>0)return;let F=!0,J=0;const ie=15,xe=async()=>{const Ce=Kt.getState();if(!(Ce.providers.length>0&&Ce.agents.length>0))try{Ce.providers.length===0&&await l({source:"startupRecovery"}),Kt.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};xe();const ge=setInterval(()=>{if(F){if(++J>=ie){clearInterval(ge);return}xe()}},2e3);return()=>{F=!1,clearInterval(ge)}},[r,g,a,l,i,o]),c.useEffect(()=>{y||g||r&&_s.setDirectory(m)},[m,y,r,g]),c.useEffect(()=>{if(!U||typeof window>"u")return;const F=xe=>{p(xe?.visible===!0)},J=xe=>{if(xe.origin!==window.location.origin||xe.source!==window.parent)return;const ge=xe.data;ge?.type===du&&F(ge.payload)},ie=window;return ie.__openchamberSetEmbeddedVisibility=F,window.addEventListener("message",J),xg(),()=>{window.removeEventListener("message",J),ie.__openchamberSetEmbeddedVisibility===F&&delete ie.__openchamberSetEmbeddedVisibility}},[U]),c.useEffect(()=>{!U?.directory||g||m!==U.directory&&h(U.directory,{showOverlay:!1})},[m,U,g,h]),c.useEffect(()=>{if(!U||typeof window>"u")return;const F=J=>{J.storageArea===window.localStorage&&J.key==="ui-store"&&Ae.persist.rehydrate()};return window.addEventListener("storage",F),()=>{window.removeEventListener("storage",F)}},[U]),c.useEffect(()=>{if(typeof window>"u")return;const F=J=>{const ie=J.detail,xe=typeof ie?.sessionId=="string"?ie.sessionId.trim():"";if(!xe)return;const ge=typeof ie?.directory=="string"&&ie.directory.trim().length>0?ie.directory.trim():null;qe.getState().setCurrentSession(xe,ge)};return window.addEventListener("openchamber:open-session",F),()=>window.removeEventListener("openchamber:open-session",F)},[]),c.useEffect(()=>{if(typeof window>"u")return;const F=()=>{Fn("desktop_open_draft_mini_chat_window",{directory:"",projectId:null})};return window.addEventListener("openchamber:open-mini-chat",F),()=>window.removeEventListener("openchamber:open-mini-chat",F)},[]),c.useEffect(()=>{if(typeof window>"u")return;const F=()=>{const J=qe.getState().currentSessionId;J&&Nd(J)};return window.addEventListener("focus",F),()=>window.removeEventListener("focus",F)},[]),c.useEffect(()=>{if(typeof window>"u")return;const F=J=>{const ie=J.detail,xe=typeof ie?.directory=="string"&&ie.directory.trim().length>0?ie.directory.trim():null,ge=typeof ie?.projectId=="string"&&ie.projectId.trim().length>0?ie.projectId.trim():null,Ce=!!(xe||ge);Ae.getState().setSessionSwitcherOpen(!1),qe.getState().openNewSessionDraft({target:Ce?"project":"chat",selectedProjectId:Ce?ge:null,directoryOverride:Ce?xe:null,preserveDirectoryOverride:!!xe})};return window.addEventListener("openchamber:open-draft-session",F),()=>window.removeEventListener("openchamber:open-draft-session",F)},[]),c.useEffect(()=>{typeof window>"u"||!n||y||L.current||(L.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,y]),hp({enabled:X}),Z4({enabled:X}),tC(m||null),rC(),pp(),Dp(),Xp();const ee=c.useCallback(()=>{S(F=>!F)},[]);E4(ee),U4(),G4(!U),c.useEffect(()=>{if(U)return;const F=()=>S(J=>!J);return window.addEventListener("openchamber:memory-debug-toggle",F),()=>window.removeEventListener("openchamber:memory-debug-toggle",F)},[U]),c.useEffect(()=>{U||d&&setTimeout(()=>u(),5e3)},[u,U,d]),c.useEffect(()=>{if(!V||_!=="not-injected")return;let F=!1,J=0;const ie=200,xe=2e3,ge=50,Ce=()=>{if(F)return;J++;const Re=Xa();if(Re!=="not-injected"){if(F=!0,O(Re),Re==="valid"){const ye=Ja();ye&&E(Za({isDesktopShell:!0,bootOutcome:ye}))}return}const ce=Math.min(ie*Math.pow(1.1,J),xe);if(J>=ge){const ye=document.getElementById("initial-loading");ye&&!ye.textContent?.includes("taking longer")&&(ye.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Ce,ce)};return window.setTimeout(Ce,ie),()=>{F=!0}},[V,_]);const ue=c.useCallback(async()=>{if(Xm({isDesktopShell:wn(),isDesktopLocalOriginActive:Xo()})){await Jm();return}window.location.reload()},[]),W=c.useCallback(async()=>{if(!P){N(!1),M(!0);try{await Kt.getState().initializeApp()}finally{M(!1)}Kt.getState().isInitialized||k(F=>F+1)}},[P]),ne=F=>{if(F.screen==="recovery")return F.variant};if(V&&j&&j.screen!=="main"){if(j.screen==="chooser")return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(rd,{mode:"first-launch",localAvailable:j.localAvailable!==!1,onCliAvailable:ue,onChooseRemote:()=>{}})})})});const F=ne(j),J=j.screen==="recovery"&&"url"in j?j.url:void 0;return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(c.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(rd,{mode:"recovery",recoveryVariant:F,recoveryHostUrl:J,recoveryHostLabel:void 0,localAvailable:j.localAvailable!==!1,onCliAvailable:ue})})})})}if(U)return s.jsx(Xs,{children:s.jsx(xl,{sdk:_s.getSdkClient(),directory:m||"",children:s.jsx(yl,{apis:t,children:s.jsx(Fi,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(mC,{embeddedSessionChat:U,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:X}),s.jsx(wl,{})]})})})},A)});if(Q)return s.jsx(Xs,{children:s.jsx(aC,{})});if(w&&!n&&!g&&!U)return s.jsx(Xs,{children:s.jsx(cC,{onRetry:()=>{W()},isRetrying:P})});const Y=!n&&!V;return s.jsx(Xs,{children:s.jsx(xl,{sdk:_s.getSdkClient(),directory:m||"",children:s.jsx(yl,{apis:t,children:s.jsx(e4,{children:s.jsx(Fi,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:V?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Ud,{embeddedBackgroundWorkEnabled:X}),s.jsx(tu,{}),s.jsx(E3,{}),s.jsx(Hd,{}),s.jsx(wl,{}),!Y&&s.jsxs(s.Fragment,{children:[s.jsx(Jp,{}),s.jsx(lC,{}),b&&s.jsx(m4,{onClose:()=>S(!1)})]})]})})})})},A)})}function hC(t){return t.isAboutDialogOpen}function pC(t){return t.setAboutDialogOpen}function gC(t){return t.currentDirectory}function bC(t){return t.currentSessionId}function xC(t){return t.setCurrentSession}const yC=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();bp();Zm().then(()=>{Promise.all([ef(),xp()]).catch(t=>{console.error("[main] settings init failed:",t)}),yp(),wp(),Sp()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Nm=document.getElementById("root");if(!Nm)throw new Error("Root element not found");Pm.createRoot(Nm).render(s.jsx(it.StrictMode,{children:s.jsx(vp,{children:s.jsx(jp,{children:s.jsx(kp,{children:s.jsx(Cp,{children:s.jsx(fC,{apis:yC})})})})})}));const _C=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{sx as W,Kb as a,FC as b,gx as d,Ru as g,BC as h,_C as m,tx as u,Eu as v};
|