@openchamber/web 1.18.2 → 1.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/commands-models.js +1 -1
- package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
- package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
- package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
- package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
- package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
- package/dist/assets/FilesView-CzUgIvUm.js +14 -0
- package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
- package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
- package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
- package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
- package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
- package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
- package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
- package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
- package/dist/assets/de-u7gSnqWs.js +9 -0
- package/dist/assets/es-T9O7aAOr.js +15 -0
- package/dist/assets/fr-Oor7ewbE.js +13 -0
- package/dist/assets/index-CVNuER6G.css +1 -0
- package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
- package/dist/assets/index-iFY_N5aO.js +7 -0
- package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
- package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
- package/dist/assets/ja-DHpqbVmr.js +15 -0
- package/dist/assets/ko-CwLkS3nx.js +15 -0
- package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
- package/dist/assets/main-CAxX6DAN.js +915 -0
- package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
- package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
- package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
- package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
- package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
- package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
- package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
- package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
- package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
- package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
- package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
- package/dist/assets/uk-BA2kZR38.js +15 -0
- package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
- package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
- package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
- package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +65 -19
- package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
- package/server/lib/agent-tool/runtime.js +90 -16
- package/server/lib/agent-tool/runtime.test.js +86 -0
- package/server/lib/browser-control/DOCUMENTATION.md +50 -0
- package/server/lib/browser-control/broker.js +154 -0
- package/server/lib/browser-control/broker.test.js +191 -0
- package/server/lib/browser-control/routes.js +48 -0
- package/server/lib/browser-control/routes.test.js +108 -0
- package/server/lib/dev-servers/parse.js +203 -0
- package/server/lib/dev-servers/parse.test.js +174 -0
- package/server/lib/dev-servers/routes.js +135 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
- package/server/lib/dev-tunnel/client.js +174 -0
- package/server/lib/dev-tunnel/runtime.js +189 -0
- package/server/lib/dev-tunnel/tunnel.test.js +282 -0
- package/server/lib/git/credentials.js +0 -33
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
- package/server/lib/openchamber-control/actions.js +33 -1
- package/server/lib/openchamber-control/screenshots.js +83 -0
- package/server/lib/openchamber-control/screenshots.test.js +84 -0
- package/server/lib/openchamber-control/service.js +141 -2
- package/server/lib/openchamber-control/service.test.js +55 -0
- package/server/lib/opencode/core-routes.js +31 -52
- package/server/lib/opencode/core-routes.test.js +37 -9
- package/server/lib/opencode/feature-routes-runtime.js +4 -0
- package/server/lib/opencode/settings-helpers.js +3 -9
- package/server/lib/projects/project-config.js +181 -2
- package/server/lib/projects/project-config.test.js +295 -0
- package/server/lib/quota/DOCUMENTATION.md +4 -2
- package/server/lib/quota/credentials/providers.js +0 -7
- package/server/lib/quota/credentials/store.js +11 -1
- package/server/lib/quota/credentials/store.test.js +9 -1
- package/server/lib/quota/providers/opencode-go.js +35 -35
- package/server/lib/quota/providers/opencode-go.test.js +52 -7
- package/server/lib/quota/routes.js +0 -2
- package/server/lib/relay/DOCUMENTATION.md +2 -0
- package/server/lib/relay/tunnel-host.js +157 -33
- package/server/lib/relay/tunnel-host.test.js +147 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
- package/server/lib/scheduled-tasks/routes.js +6 -0
- package/server/lib/scheduled-tasks/runtime.js +369 -108
- package/server/lib/scheduled-tasks/service.js +7 -1
- package/server/lib/scheduled-tasks/service.test.js +20 -0
- package/server/lib/walkthrough/index.js +0 -2
- package/server/sse-routes.test.js +3 -0
- package/dist/assets/FilesView-WkxsWHBE.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
- package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
- package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
- package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
- package/dist/assets/de-B6t6T54h.js +0 -9
- package/dist/assets/es-DH9NUKge.js +0 -15
- package/dist/assets/fr-Do4t2KmA.js +0 -13
- package/dist/assets/index-B45s9aAX.css +0 -1
- package/dist/assets/index-CNrN5qDs.js +0 -7
- package/dist/assets/ja-DJT9EM80.js +0 -15
- package/dist/assets/ko-CfWRq2p4.js +0 -15
- package/dist/assets/main-B4oBRI9u.js +0 -193
- package/dist/assets/markdownCore-A3_L34oS.js +0 -2
- package/dist/assets/pt-BR-BDEzzltP.js +0 -15
- package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
- package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
- package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
- package/dist/assets/uk-B6Q32nyk.js +0 -15
- package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
- package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
- package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
- package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
- package/server/lib/preview/proxy-runtime.js +0 -1604
- package/server/lib/preview/proxy-runtime.test.js +0 -528
- package/server/lib/quota/opencode-go-credentials.js +0 -11
- package/server/lib/quota/opencode-go-credentials.test.js +0 -32
- package/server/lib/quota/routes.test.js +0 -40
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-HStEYdD2.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-Bbpz77To.js","assets/index-CNrN5qDs.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-B45s9aAX.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-D_V6hAcE.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-5VGWIT_J.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-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-DUOssd4j.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BjbBRsUA.js","assets/vendor-codemirror-lang-json-ryCw7nab.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-VgNqFSH-.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-B3Qe3OpS.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-FGQydhTc.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-Dzt9rWZZ.js","assets/vendor-codemirror-lang-python-N414WYK-.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-ARAOgp1x.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-B5k0KvPW.js","assets/web-components-DGvnI0zx.js","assets/computeVirtualFileMetrics-DQE7R9IY.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-Dcu8Q-5P.js","assets/isDiffPlainText-XyBCe4eD.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-D7zs7-BQ.js","assets/runtimeEndpointReset-D5izT-u5.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-DCIXUHRJ.js","assets/SessionSwitcherDropdown-ig2OT22Z.js","assets/scheduledTasksApi-CTJdfSWc.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-1zd0slLu.js","assets/FilesView-WkxsWHBE.js","assets/shikiHighlight-eU8abJ3T.js","assets/vendor-codemirror-search-8kyQdB3f.js","assets/vendor-replit-codemirror-vim-B0Ecqnlh.js","assets/JsonTreeView-Kgepz4pR.js","assets/Virtualizer-X_7XPoTH.js","assets/isFilePlainText-JbqDfa3n.js","assets/DiagramEditor-C7nUw7p3.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-CxcJ5x9h.js","assets/GitView-OSVIn5V1.js","assets/CommitSection-C9sBBYAJ.js","assets/PlanView-BYgHBHDt.js","assets/DiagramView-cYxZP-HS.js","assets/SettingsView-e7Fmxnz8.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/SettingsWindow-CNHM8ifT.js","assets/OnboardingScreen-BCgYA7J5.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{f as tt,j as s,R as l,r as He,h as Qf}from"./vendor-react-BUCujlKS.js";import{x as _n,y as bi,O as Nl,D as Xf,z as Jf,A as Id,r as hs,n as yi,u as pe,B as Zf,C as er,E as em,F as vt,G as In,H as wi,I as Td,J as Ed,q as Fa,K as Md,L as Jn,M as ri,e as cr,N as tm,a as Tn,P as sm,Q as nm,R as rm,S as Rd,m as On,t as en,T as om,U as im,V as Od,W as vi,X as Br,l as cs,Y as Ba,Z as fa,_ as am,$ as lm,d as Lr,a0 as Vo,a1 as Ho,a2 as cm,a3 as Al,a4 as dm,a5 as um,a6 as fm,a7 as mm,a8 as Dl,a9 as Pl,aa as Il,ab as Tl,ac as hm,o as El,ad as pm,ae as gm,af as xm,v as bm,w as ym}from"./index-CNrN5qDs.js";import{_ as Rs}from"./vendor-vite-runtime-DD1OZmLC.js";import{I as T,f as gt,g as Ce,aO as qt,aP as Bn,t as Ie,aQ as xn,aR as gn,aS as bn,aT as yn,K as Ir,U as tr,aU as fr,o as Gr,aV as Ml,aW as ut,aX as ft,aY as mt,aZ as Fd,a_ as po,a$ as wm,x as Ge,b0 as vm,b1 as Sm,b2 as Bd,b3 as jm,b4 as Ko,b5 as km,b6 as Cm,J as Ld,b7 as Nm,b8 as ma,k as Vt,b9 as Am,z as _d,u as Ms,b as Yt,m as ys,al as Pr,ba as $d,bb as Dm,bc as Pm,bd as Im,be as Tm,n as Em,bf as zd,bg as Mm,bh as Rm,bi as Om,bj as Wd,bk as Fm,bl as Bm,bm as La,bn as Si,bo as ha,am as _a,bp as ji,bq as Ar,ad as Ud,br as qs,bs as Ys,bt as En,bu as wn,bv as vn,bw as mr,B as et,bx as Vd,by as Vi,P as oi,bz as Rl,bA as To,h as pa,i as Lm,bB as Hd,bC as _m,bD as Kd,ab as us,F as $m,bE as zm,bF as Wm,bG as pn,bH as ki,bI as Gd,bJ as go,bK as Um,bL as Vs,bM as Hs,bN as As,bO as Ks,bP as ls,R as Zn,bQ as _r,bR as Ol,bS as zr,M as Ci,$ as Yr,a0 as $a,bT as qd,a3 as dr,bU as Ni,bV as Xn,Y as za,bW as Vm,bX as Hm,aa as Km,bY as Gm,bZ as qm,b_ as Ym,ac as Wa,b$ as Ua,c0 as Yd,c1 as Qm,c2 as Xm,c3 as So,c4 as Jm,c5 as tn,c6 as Zm,c7 as eh,c8 as Hi,c9 as Qd,ca as Va,cb as th,O as Ha,cc as sh,cd as nh,ce as rh,cf as Fl,cg as lo,c as xo,d as Ai,X as Xd,ch as Jd,ci as no,cj as co,ck as oh,r as Gs,cl as ih,V as Ka,cm as ah,cn as lh,co as ch,cp as dh,cq as Zd,cr as Ln,cs as uh,ct as fh,cu as Bl,cv as eu,cw as mh,cx as tu,e as qr,cy as ii,cz as hh,cA as Ll,cB as ur,cC as ga,cD as ph,cE as gh,cF as _l,cG as zs,cH as su,cI as nu,cJ as xh,cK as Go,cL as bh,N as Ga,L as qa,Q as Ya,cM as Qa,cN as xa,cO as ru,cP as yh,cQ as ou,cR as wh,G as vh,cS as $l,cT as Sh,cU as zl,cV as jh,cW as kh,cX as iu,cY as Ch,C as Nh,cZ as Ah,c_ as Dh,c$ as Ph,d0 as Wl,d1 as Ih,d2 as Th,A as Eh,d3 as au,D as Mh,d4 as Ul,d5 as Rh,d6 as Oh,d7 as Fh,d8 as Bh,d9 as Lh,da as _h,db as Di,a as Pi,dc as $h,dd as Ki,E as ai,de as zh,df as Wh,dg as Vl,av as ba,dh as lu,Z as Uh,_ as Vh,ay as Hh,di as Kh,H as Gh,dj as qh,dk as Yh,dl as Qh,dm as cu,dn as du,dp as uu,dq as Xh,dr as Jh,ds as Zh,dt as ep,du as tp,dv as sp,dw as np,dx as rp,dy as op,dz as li,a1 as ip,a2 as ap,dA as lp,dB as Hl,dC as cp,dD as dp,dE as up,dF as fp,dG as Kl,dH as mp,dI as hp,dJ as pp,dK as gp,dL as xp,dM as bp,dN as yp,dO as wp,dP as vp,dQ as qo,dR as Sp,dS as jp,ae as kp,dT as Cp,dU as Np,dV as Ap,dW as Dp,dX as Gl,dY as Pp,ap as Ip,aq as Tp,ar as Ep,at as ql,au as Yl,aw as fu,ax as mu,dZ as Mp,aJ as Rp,aK as Op,aL as Fp,aM as Bp,aN as Lp,aF as _p,aG as $p,aH as zp,aI as Wp}from"./useAppFontEffects-Bbpz77To.js";import{h as Ql,i as Jt,n as Up,j as Xl,t as qn,k as Vp,l as Gi,U as hu,b as Xa,M as Hp,m as Jl,o as Zl,p as ci,q as Ja,s as di,v as pu,w as Kp,x as gu,y as xu,z as bu,P as yu,T as wu,A as Gp,B as qp,E as Yp,S as ec,u as uo,N as Qp,D as Xp,W as Jp,L as tc,F as Zp,d as eg,g as tg,f as ya,G as sg,H as ng,c as rg,e as og,O as vu,C as ig}from"./runtimeEndpointReset-D5izT-u5.js";import{u as Su,S as ag,C as lg,W as ju}from"./SessionSwitcherDropdown-ig2OT22Z.js";import{u as vr,f as cg,a as sc,s as dg,d as ug,b as fg,r as mg}from"./scheduledTasksApi-CTJdfSWc.js";import{c as Qr,u as Qn,d as ku,p as hg}from"./vendor-zustand-BAGL70zf.js";import{g as pg,E as gg,b as xg,i as bg}from"./contextPanelEmbeddedChat-5VGWIT_J.js";import{f as ui,h as Wr,T as yg,M as wg,D as fi,j as mi,P as wa,b as vg,d as Sg,k as va,i as jg}from"./vendor-dnd-kit-core-BZknOX2w.js";import{a as Cu,S as Sa,v as ja,u as Za,s as kg}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as el}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{u as Cg}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{M as nc,a as rc,b as oc,C as Ng,c as Ag,d as Dg,S as Pg,e as Ig,f as Tg}from"./vendor-base-ui-D_V6hAcE.js";import{d as Nu}from"./vendor-cron-parser-CUcP7OfX.js";import{u as ic,a as ac,m as lc}from"./vendor-framer-motion-CRSgBxjL.js";function Au(t){const e=tt.c(5),{className:n}=t,o=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let i,c,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),c=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),a=s.jsx(T,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=i,e[1]=c,e[2]=a):(i=e[0],c=e[1],a=e[2]);let d;return e[3]!==o?(d=s.jsxs("span",{"aria-hidden":"true",className:o,children:[i,c,a]}),e[3]=o,e[4]=d):d=e[4],d}function cc(t){const e=tt.c(14);let n,r,o,i;e[0]!==t?({size:o,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=typeof o=="number"?`${o}px`:o,a=typeof o=="number"?`${o}px`:o;let d;e[5]!==i||e[6]!==c||e[7]!==a?(d={width:c,height:a,...i},e[5]=i,e[6]=c,e[7]=a,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=u):u=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:u}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Eg="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",Mg="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",qi=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?Eg:t.id==="terminal"?Mg:void 0}),dc=t=>{const e=tt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=l.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||o;if(u&&!i){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>c(!0),e[2]=g):g=e[2];let x;return e[3]!==u?(x=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=u,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=Ce("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 f;return e[6]!==d?(f=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=f):f=e[7],f},Rg=t=>{const e=tt.c(75),{directory:n,className:r}=t,{t:o}=gt(),i=vr(Og),c=vr(Fg),a=vr(Bg),d=vr(Lg),u=vr(_g),m=vr($g),f=vr(zg);let g,x;e[0]!==u?(g=()=>{u()},x=[u],e[0]=u,e[1]=g,e[2]=x):(g=e[1],x=e[2]),l.useEffect(g,x);const w=_n()&&bi();let S;e:{let Y;e[3]!==c||e[4]!==i?(Y=c.find(z=>z.id===i)??c.find(Wg)??c[0]??Nl[0],e[3]=c,e[4]=i,e[5]=Y):Y=e[5];const je=Y;if(je){let z;e[6]!==je?(z=qi(je),e[6]=je,e[7]=z):z=e[7],S=z;break e}let me;e[8]===Symbol.for("react.memo_cache_sentinel")?(me=qi(Nl[0]),e[8]=me):me=e[8],S=me}const p=S;if(!w||!n||c.length===0)return null;let h;e[9]!==n?(h=async Y=>{await Jf(n,Y.id,Y.appName)||await Id(n,Y.appName)},e[9]=n,e[10]=h):h=e[10];const y=h;let v;e[11]!==y||e[12]!==f?(v=async Y=>{await f(Y.id),await y(Y)},e[11]=y,e[12]=f,e[13]=v):v=e[13];const j=v;let N;e[14]!==n||e[15]!==o?(N=async()=>{(await Bn(n)).ok&&Ie.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=N):N=e[16];const C=N;let k;e[17]!==r?(k=Ce("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 D;e[19]!==y||e[20]!==p?(D=()=>{y(p)},e[19]=y,e[20]=p,e[21]=D):D=e[21];const M=d&&"animate-pulse";let A;e[22]!==M?(A=Ce("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",M),e[22]=M,e[23]=A):A=e[23];let _;e[24]!==p.label||e[25]!==o?(_=o("openInApp.actions.openInAria",{app:p.label}),e[24]=p.label,e[25]=o,e[26]=_):_=e[26];let L;e[27]!==p.fallbackIconDataUrl||e[28]!==p.iconDataUrl||e[29]!==p.label?(L=s.jsx(dc,{label:p.label,iconDataUrl:p.iconDataUrl,fallbackIconDataUrl:p.fallbackIconDataUrl}),e[27]=p.fallbackIconDataUrl,e[28]=p.iconDataUrl,e[29]=p.label,e[30]=L):L=e[30];let F;e[31]!==A||e[32]!==_||e[33]!==L||e[34]!==D?(F=s.jsx("button",{type:"button",onClick:D,className:A,"aria-label":_,children:L}),e[31]=A,e[32]=_,e[33]=L,e[34]=D,e[35]=F):F=e[35];let $;e[36]===Symbol.for("react.memo_cache_sentinel")?($=Ce("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]=$):$=e[36];let W;e[37]!==o?(W=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=W):W=e[38];let U;e[39]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=U):U=e[39];let K;e[40]!==W?(K=s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:$,"aria-label":W,children:U})}),e[40]=W,e[41]=K):K=e[41];let b;e[42]!==C?(b=()=>{C()},e[42]=C,e[43]=b):b=e[43];let P;e[44]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(T,{name:"file-copy",className:"h-4 w-4"}),e[44]=P):P=e[44];let V;e[45]!==o?(V=o("openInApp.actions.copyPath"),e[45]=o,e[46]=V):V=e[46];let G;e[47]!==V?(G=s.jsx("span",{className:"typography-ui-label text-foreground",children:V}),e[47]=V,e[48]=G):G=e[48];let X;e[49]!==b||e[50]!==G?(X=s.jsxs(qt,{className:"flex items-center gap-2",onClick:b,children:[P,G]}),e[49]=b,e[50]=G,e[51]=X):X=e[51];let J;e[52]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(gn,{}),e[52]=J):J=e[52];let ee;if(e[53]!==c||e[54]!==j||e[55]!==p.id){let Y;e[57]!==j||e[58]!==p.id?(Y=je=>{const me=qi(je);return s.jsxs(qt,{className:"flex items-center gap-2",onClick:()=>{j(je)},children:[s.jsx(dc,{label:je.label,iconDataUrl:je.iconDataUrl,fallbackIconDataUrl:me.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:je.label}),p.id===je.id?s.jsx(T,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},je.id)},e[57]=j,e[58]=p.id,e[59]=Y):Y=e[59],ee=c.map(Y),e[53]=c,e[54]=j,e[55]=p.id,e[56]=ee}else ee=e[56];let le;e[60]!==a||e[61]!==m||e[62]!==o?(le=a?s.jsxs(qt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(T,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=a,e[61]=m,e[62]=o,e[63]=le):le=e[63];let oe;e[64]!==X||e[65]!==ee||e[66]!==le?(oe=s.jsxs(bn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[X,J,ee,le]}),e[64]=X,e[65]=ee,e[66]=le,e[67]=oe):oe=e[67];let Ae;e[68]!==K||e[69]!==oe?(Ae=s.jsxs(yn,{children:[K,oe]}),e[68]=K,e[69]=oe,e[70]=Ae):Ae=e[70];let Se;return e[71]!==F||e[72]!==Ae||e[73]!==k?(Se=s.jsxs("div",{className:k,children:[F,Ae]}),e[71]=F,e[72]=Ae,e[73]=k,e[74]=Se):Se=e[74],Se};function Og(t){return t.selectedAppId}function Fg(t){return t.availableApps}function Bg(t){return t.isCacheStale}function Lg(t){return t.isScanning}function _g(t){return t.initialize}function $g(t){return t.loadInstalledApps}function zg(t){return t.selectApp}function Wg(t){return t.id===Xf}const Ug=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Vg=["dev","start","preview","serve"];async function Hg(t,e,n){if(!t)return null;const r=qg(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Yg(n);if(o){const i=await Qg(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Kg(t)){const o=await Gg(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function Kg(t){const e=`${t}/index.html`,n=await hi(e,t);return typeof n=="string"&&n.trim().length>0}async function Gg(){try{const t=await hs("/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 qg(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Vg.some(o=>n.includes(o)))return e}return null}function Yg(t){for(const{pattern:e}of Ug)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Qg(t){const e=await hi(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const i=await hi(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function hi(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await hs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=yi()?.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 hs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Xg(t){try{const e=await hi(`${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 Jg=(t,e,n)=>new Promise(r=>{let o=!1,i=null,c=null;const a=d=>{o||(o=!0,c&&clearTimeout(c),i?.close(),r(d))};i=t.connect(e,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&a(!0)},onError:(d,u)=>{u&&a(!0)}}),o?i.close():c=setTimeout(()=>a(!1),n)}),Zg="\x1B",ex=new RegExp(`${Zg}\\[[0-9;?]*[ -/]*[@-~]`,"g"),tx=/https?:\/\/[^\s<>'"`]+/gi,Js="__openchamber_auto_discover_preview__",sx=15e3,nx=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},rx=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}},ox=t=>{const n=t.replace(ex,"").match(tx);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const c=new URL(i);c.port&&c.port.length>0&&o.push({raw:i,parsed:c})}catch{}if(o.length>0){const i=c=>{const{parsed:a}=c,d=a.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=a.pathname||"/",f=m.split("/").filter(Boolean).length,g=m==="/"||m==="",x=!!(a.search||a.hash);let w=0;return u&&(w+=50),g&&(w+=30),w-=Math.min(f*5,20),x&&(w-=10),w};return o.sort((c,a)=>i(a)-i(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Du=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=gt(),{currentTheme:c}=Ir(),{terminal:a,runtime:d}=tr(),{isMobile:u}=fr(),m=l.useMemo(()=>_n(),[]),f=Ql(te=>te.instances),g=Ql(te=>te.load),x=pe(te=>te.terminalShell),w=pe(te=>te.terminalLoginShells.includes(te.terminalShell)),S=pe(te=>te.setSettingsPage),p=pe(te=>te.setSettingsDialogOpen),h=pe(te=>te.setSettingsProjectsSelectedId),y=pe(te=>te.openContextPreview),v=Jt(te=>te.ensureDirectory),j=Jt(te=>te.setTabLabel),N=Jt(te=>te.setTabIconKey),C=Jt(te=>te.setActiveTab),k=Jt(te=>te.setConnecting),D=Jt(te=>te.setTabSessionId),M=Jt(te=>te.setTabPreviewUrl),A=Jt(te=>te.projectActionRuns),_=Jt(te=>te.setProjectActionRun),L=Jt(te=>te.updateProjectActionRunStatus),F=Jt(te=>te.removeProjectActionRun),[$,W]=l.useState([]),[U,K]=l.useState(null),[b,P]=l.useState(!1),V=l.useRef({}),G=l.useRef({}),X=l.useRef({}),J=l.useRef({}),ee=l.useRef(new Set),le=l.useRef(0),oe=t?.id??null,Ae=t?.path??"",Se=l.useMemo(()=>oe?{id:oe,path:Ae}:null,[oe,Ae]);l.useEffect(()=>{m&&g().catch(()=>{})},[m,g]);const Y=l.useCallback(async te=>{await Gr(te)},[]),je=l.useCallback(async()=>{if(!Se)return;const te=le.current+1;le.current=te,P(!0);try{const ae=await Ml(Se);if(le.current!==te)return;const ie=ae.actions;W(ie),K(E=>E===Js||E&&ie.some(I=>I.id===E)?E:null)}catch{if(le.current!==te)return}finally{le.current===te&&P(!1)}},[Se]),me=l.useMemo(()=>Up(e||Se?.path||""),[e,Se?.path]),z=l.useMemo(()=>U?$.find(te=>te.id===U)??null:null,[$,U]),Z=l.useMemo(()=>({id:Js,name:i("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[i]),ne=!u,fe=l.useMemo(()=>ne?[Z,...$]:$,[$,Z,ne]);l.useEffect(()=>{je()},[je]),l.useEffect(()=>{if(typeof window>"u")return;const te=ae=>{const ie=ae.detail;oe&&(ie?.projectId&&ie.projectId!==oe||je())};return window.addEventListener(Xl,te),()=>{window.removeEventListener(Xl,te)}},[je,oe]),l.useEffect(()=>{U&&(U===Js&&ne||$.some(te=>te.id===U)||K(null))},[$,ne,U]),l.useEffect(()=>{const te=()=>{const ae=Jt.getState(),ie=ae.sessions,E=ae.projectActionRuns;for(const[I,ue]of Object.entries(E)){const we=ie.get(ue.directory)?.tabs.find(it=>it.id===ue.tabId);if(!we||we.terminalSessionId!==ue.sessionId){F(I);continue}const qe=G.current[I]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};G.current[I]=qe;const Je=fe.find(it=>it.id===ue.actionId),st=ae.getBuffer(ue.directory,ue.tabId).chunks;if(!Je||st.length===0)continue;const rt=st.filter(it=>qe.lastSeenChunkId===null||it.id>qe.lastSeenChunkId);if(rt.length===0)continue;const ot=rt.map(it=>it.data).join(""),lt=`${qe.tail}${ot}`,kt=!qe.openedUrl&&Je.autoOpenUrl===!0?ox(lt):null,nt=rt[rt.length-1]?.id??qe.lastSeenChunkId;if(qe.lastSeenChunkId=nt,qe.tail=lt.slice(-512),kt)if(qe.openedUrl=!0,qe.openInPreview){const it=E[I];it&&(M(it.directory,it.tabId,kt,{locked:!1,autoOpened:!1}),it.status==="waiting-for-preview"&&L(I,"running"),window.clearTimeout(J.current[I]),delete J.current[I],y(it.directory,kt))}else Y(kt),Ie.success(i("projectActions.toast.openedUrlFromOutput"));G.current[I]=qe}for(const I of Object.keys(G.current))E[I]||(delete G.current[I],window.clearTimeout(J.current[I]),delete J.current[I])};return te(),Jt.subscribe((ae,ie)=>{(ae.sessions!==ie.sessions||ae.buffers!==ie.buffers)&&te()})},[fe,y,Y,A,F,M,i,L]);const xe=l.useCallback(async(te,ae={})=>{if(!me)throw new Error(i("projectActions.error.noActiveDirectory"));const ie=qn(me,te.id);v(me);const E=Jt.getState(),I=E.getDirectoryState(me);let ue=V.current[ie]||null;const ke=ue?!!I?.tabs.some(Je=>Je.id===ue):!1;(!ue||!ke)&&(ue=E.createTab(me),V.current[ie]=ue),j(me,ue,`Action: ${te.name}`),N(me,ue,te.icon||"play"),C(me,ue),ae.revealTerminal!==!1&&pe.getState().openContextPanelTab(me,{mode:"terminal"});const qe=Jt.getState().getDirectoryState(me)?.tabs.find(Je=>Je.id===ue);return{key:ie,tabId:ue,sessionId:qe?.terminalSessionId??null}},[v,me,C,N,j,i]),Te=l.useCallback(async te=>{if(d.isVSCode||!o&&u)return;if(!me){Ie.error(i("projectActions.error.noActiveDirectoryForAction"));return}const ae=qn(me,te.id),ie=A[ae];if(!(ie&&ie.status==="running")&&!ee.current.has(ae)){ee.current.add(ae);try{const E=te.id===Js?await(async()=>{const[nt,it]=await Promise.all([Ml({id:Se?.id??"",path:me}),Xg(me)]),St=await Hg(me,nt.actions,it);if(!St)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Js,name:i("projectActions.actions.autoDiscover"),command:St.command,icon:"scan-2",autoOpenUrl:!0,openUrl:St.previewUrlHint||""}})():te,I=E.autoOpenUrl===!0&&(E.openUrl||"").trim().length>0,ue=!I&&te.id!==Js,{key:ke,tabId:we,sessionId:qe}=await xe(E,{revealTerminal:ue});let Je=qe;if(!Je){k(me,we,!0);try{Je=(await a.createSession({cwd:me,sessionId:we,shell:x,loginShell:w,themeMode:c.metadata.variant==="light"?"light":"dark",terminalBackground:c.colors.surface.background,terminalForeground:c.colors.syntax.base.foreground})).sessionId,D(me,we,Je)}finally{k(me,we,!1)}}if(!Je)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));X.current[ke]?.(),k(me,we,!0);const st=a.connect(Je,{onEvent:nt=>{nt.type==="snapshot"&&(Jt.getState().replaceBuffer(me,we,nt.data??"",nt.sequence??0),Jt.getState().setConnecting(me,we,!1)),nt.type==="data"&&typeof nt.data=="string"&&nt.data.length>0&&Jt.getState().appendToBuffer(me,we,nt.data,nt.sequence,nt.replayData),nt.type==="exit"&&(Jt.getState().setTabLifecycle(me,we,"exited"),Jt.getState().setConnecting(me,we,!1),Jt.getState().removeProjectActionRun(ke),delete G.current[ke],X.current[ke]?.(),delete X.current[ke],window.clearTimeout(J.current[ke]),delete J.current[ke])},onError:(nt,it)=>{Jt.getState().setConnecting(me,we,!1),it&&(Jt.getState().setTabLifecycle(me,we,"exited"),Jt.getState().setTabSessionId(me,we,null),Jt.getState().removeProjectActionRun(ke))}});X.current[ke]=st.close;const rt=E.autoOpenUrl===!0&&m&&(E.desktopOpenSshForward||"").trim().length>0,ot=E.autoOpenUrl?rx(E.openUrl):null,lt=E.autoOpenUrl&&m?Vp(E.desktopOpenSshForward,f):null;_({key:ke,directory:me,actionId:E.id,tabId:we,sessionId:Je,status:E.id===Js&&!ot?"waiting-for-preview":"running"}),window.clearTimeout(J.current[ke]),delete J.current[ke],E.id===Js&&!ot&&(J.current[ke]=window.setTimeout(()=>{const nt=Jt.getState(),it=nt.projectActionRuns[ke];nt.updateProjectActionRunStatus(ke,"running"),it&&(nt.setActiveTab(it.directory,it.tabId),pe.getState().openContextPanelTab(it.directory,{mode:"terminal"})),delete J.current[ke]},sx)),G.current[ke]={lastSeenChunkId:null,openedUrl:!!lt||!!ot||I,tail:"",openInPreview:E.id===Js};const kt=nx(E.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await a.sendInput(Je,`${kt}\r`),lt?(M(me,we,null,{locked:!0}),Y(lt),Ie.success(i("projectActions.toast.openedForwardedUrl"))):ot?(M(me,we,ot,{locked:!0,autoOpened:!0}),y(me,ot),Ie.success(i("projectActions.toast.openedActionUrl"))):I?(M(me,we,null,{locked:!0}),Ie.error(i("projectActions.error.invalidCustomUrlFormat"))):rt?(M(me,we,null,{locked:!0}),Ie.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):M(me,we,null,{locked:!1,autoOpened:!1})}catch(E){F(ae),delete G.current[ae],X.current[ae]?.(),delete X.current[ae],window.clearTimeout(J.current[ae]),delete J.current[ae],Ie.error(E instanceof Error?E.message:i("projectActions.error.failedToRunAction"))}finally{ee.current.delete(ae)}}},[c.colors.surface.background,c.colors.syntax.base.foreground,c.metadata.variant,f,xe,o,u,m,me,w,x,Y,y,A,d.isVSCode,F,k,_,M,D,Se?.id,i,a]),be=l.useCallback(async te=>{const ae=qn(me,te.id),ie=A[ae];if(!ie)return;L(ae,"stopping");const E=Jg(a,ie.sessionId,1e3);try{await a.sendInput(ie.sessionId,"")}catch{}const I=await E;if(Jt.getState().getDirectoryState(ie.directory)?.tabs.find(we=>we.id===ie.tabId)?.terminalSessionId===ie.sessionId&&!I){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:ie.sessionId})}catch{}else try{await a.close(ie.sessionId)}catch{}D(ie.directory,ie.tabId,null)}F(ae),delete G.current[ae],X.current[ae]?.(),delete X.current[ae],window.clearTimeout(J.current[ae]),delete J.current[ae]},[me,A,F,D,a,L]),De=l.useCallback(()=>{const te=z??fe[0];if(!te)return;const ae=qn(me,te.id),ie=A[ae];if(ie?.status!=="stopping"){if(ie){be(te);return}Te(te)}},[fe,me,Te,A,z,be]),Ee=l.useCallback((te,ae=!1)=>{if(K(te.id),!ae){Te(te);return}const ie=qn(me,te.id),E=A[ie];if(E?.status!=="stopping"){if(E){be(te);return}Te(te)}},[me,Te,A,be]),Re=l.useCallback(()=>{Se?.id&&(h(Se.id),S("projects"),p(!0))},[p,S,h,Se?.id]),de=z??fe[0]??null,H=de?A[qn(me,de.id)]:null,Ne=Jt(te=>H?te.sessions.get(H.directory)?.tabs.find(ae=>ae.id===H.tabId)?.previewUrl??null:null);if(d.isVSCode||!o&&u||!Se||!me)return null;const he=z??fe[0]??null;if(!he)return null;const ve=he.icon||"play",se=he.id===Js?"scan-2":Gi[ve]||"play",Q=qn(me,he.id),ye=A[Q],re=ye?.status==="stopping",R=ye?.status==="waiting-for-preview",ce=!!(ye&&Ne),Me=()=>{!ye||!Ne||y(ye.directory,Ne)},ge=he.id===Js;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",disabled:b||re,className:Ce("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:De,"aria-label":ye?i("projectActions.actions.stopNamedAria",{name:he.name}):i("projectActions.actions.runNamedAria",{name:he.name}),children:re||R?s.jsx(T,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ye?s.jsx(T,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(T,{name:se,className:"h-5 w-5"})})}),ge?s.jsx(mt,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),ce?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Me,children:s.jsx(T,{name:"global",className:"h-4 w-4"})})}),s.jsx(mt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(yn,{children:[s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(bn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(qt,{className:"flex items-center gap-2",onClick:Re,children:[s.jsx(T,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(gn,{}),fe.map(te=>{const ae=te.icon||"play",ie=te.id===Js?"scan-2":Gi[ae]||"play",E=qn(me,te.id),I=A[E],ue=!!I,ke=I?.status==="stopping";return s.jsxs(qt,{className:"flex items-center gap-2",onClick:()=>{Ee(te,!0)},children:[s.jsx(T,{name:ie,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:te.name}),ke||I?.status==="waiting-for-preview"?s.jsx(T,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ue?s.jsx(T,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},te.id)})]})]})]}):s.jsxs("div",{className:Ce("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(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:De,disabled:b||re,className:Ce("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":ye?i("projectActions.actions.stopNamedAria",{name:he.name}):i("projectActions.actions.runNamedAria",{name:he.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:re||R?s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ye?s.jsx(T,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(T,{name:se,className:"h-4 w-4"})})})}),ge?s.jsx(mt,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),ce?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Me,className:Ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(T,{name:"global",className:"h-4 w-4"})})}),s.jsx(mt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(yn,{children:[s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(bn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(qt,{className:"flex items-center gap-2",onClick:Re,children:[s.jsx(T,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(gn,{}),fe.map(te=>{const ae=te.icon||"play",ie=te.id===Js?"scan-2":Gi[ae]||"play",E=qn(me,te.id),I=A[E],ue=!!I,ke=I?.status==="stopping";return s.jsxs(qt,{className:"flex items-center gap-2",onClick:()=>{Ee(te,!0)},children:[s.jsx(T,{name:ie,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:te.name}),ke||I?.status==="waiting-for-preview"?s.jsx(T,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ue?s.jsx(T,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},te.id)})]})]})]})};function ix(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(po(),{month:"short"}),r=e.getDate(),o=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${c}`}function ax(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 lx(t){const e=t.info.role==="user"?"User":"Assistant",n=ix(t.info.time?.created),r=ax(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
|
|
4
|
-
|
|
5
|
-
*${o}*`:`**${e}**`}function cx(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Pu(t){const e=lx(t),n=cx(t.parts).trim();return n?`${e}
|
|
6
|
-
|
|
7
|
-
${n}`:""}function Iu(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
`,i=t.records.map(Pu).filter(Boolean).join(`
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
`),c=[o+i];for(const a of t.children)c.push(Iu(a,e+1));return c.join(`
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
`)}function Tu(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
20
|
-
|
|
21
|
-
*Exported on ${o}*
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
`,c=t.map(Pu).filter(Boolean).join(`
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
`);let a=i+c;if(n&&n.length>0){const d=n.map(u=>Iu(u,1)).join(`
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
`);a+=`
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
`+d}return a}function Eu(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function Mu(t,e){const n=await Zf(e,t);if(n)return n;if(!er())return null;try{const r=await yi()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function dx(t){const e=yi()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await em(t)?!0:Id(t)}function ux(){return Fd()}function Ru(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const tl=Qr(()=>({pendingSessionIds:new Set})),Ou=t=>{const e=tt.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],tl(n)},uc=(t,e)=>{tl.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{pendingSessionIds:r}})},fx=async(t,e)=>{try{const d=(await Cm(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=vt(t),r=vt(e)??e,o=Ge.getState().availableWorktreesByProject,c=(o.get(r)??o.get(e)??[]).find(a=>vt(a.path)===n)?.branch?.trim();if(c)return c;throw new Error("Unable to determine the current branch")},fc=(t,e)=>{const n=km(e);if(!n)throw new Error("Session status is unavailable");const r=n.session_status;if(t.some(i=>{const c=r[i.id]?.type;return c==="busy"||c==="retry"}))throw new Error("Session is not idle")},mx=async(t,e,n,r,o)=>{const i=[];for(const c of[...t].reverse())try{await Bd(c,r,n,c.id===e),Ge.getState().setWorktreeMetadata(c.id,o.get(c.id)??null)}catch(a){i.push(a)}return i},hx=async(t,e,n)=>{try{await Ld(t,e,{deleteLocalBranch:!0})}catch{const r=n instanceof Error?n.message:String(n);throw new Error(`Session move failed and the new worktree could not be removed: ${r}`)}throw n},px=async t=>{if(tl.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");uc(t.root.id,!0);try{const e=wm(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=[t.root,...t.descendants],r=new Map(n.map(a=>[a.id,Ge.getState().getWorktreeMetadata(a.id)]));fc(n,t.sourceDirectory);const o=await fx(t.sourceDirectory,e.path),i=await vm(e,{startRef:o}),c=[];try{await Sm(i.path),fc(n,t.sourceDirectory);for(const[a,d]of n.entries())await Bd(d,t.sourceDirectory,i.path,a===0),c.push(d),Ge.getState().setWorktreeMetadata(d.id,jm(i))}catch(a){if((await mx(c,t.root.id,t.sourceDirectory,i.path,r)).length>0)throw new Error(`Session move partially failed and could not be fully rolled back: ${a instanceof Error?a.message:String(a)}`);return hx(e,i,a)}try{await Ko([t.sourceDirectory,i.path])}catch(a){console.warn("[session-worktree-move] Failed to refresh moved sessions",a)}return i.path}finally{uc(t.root.id,!1)}},Fu=t=>{px(t).then(()=>Ie.success(t.successMessage)).catch(e=>Ie.error(t.failureMessage,{description:e instanceof Error?e.message:String(e)}))},bo="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",gx="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",xx=l.memo(function(e){const n=tt.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:a,Icon:d,iconClassName:u,pressed:m}=e,f=r===void 0?!0:r,g=m===void 0?!1:m;if(!f)return null;const x=a??bo,w=g&&"bg-interactive-selection text-interactive-selection-foreground";let S;n[0]!==x||n[1]!==w?(S=Ce(x,w),n[0]=x,n[1]=w,n[2]=S):S=n[2];const p=u??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==p?(h=s.jsx(T,{name:d,className:p}),n[3]=d,n[4]=p,n[5]=h):h=n[5];let y;n[6]!==i||n[7]!==c||n[8]!==g||n[9]!==S||n[10]!==h?(y=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":g,className:S,children:h})}),n[6]=i,n[7]=c,n[8]=g,n[9]=S,n[10]=h,n[11]=y):y=n[11];let v;n[12]!==o?(v=s.jsx(mt,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=v):v=n[13];let j;return n[14]!==y||n[15]!==v?(j=s.jsxs(ut,{children:[y,v]}),n[14]=y,n[15]=v,n[16]=j):j=n[16],j}),bx=l.memo(function(e){const n=tt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:a,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:m}=gt();if(!o?.connected||r)return null;if(i.length>1){let w;n[0]===Symbol.for("react.memo_cache_sentinel")?(w=Ce(bo,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=w):w=n[0];let S;n[1]!==a||n[2]!==m?(S=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[1]=a,n[2]=m,n[3]=S):S=n[3];let p;n[4]!==c||n[5]!==a||n[6]!==m?(p=c?s.jsx("img",{src:c,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(T,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=a,n[6]=m,n[7]=p):p=n[7];let h;n[8]!==d||n[9]!==S||n[10]!==p?(h=s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:w,title:S,disabled:d,children:p})}),n[8]=d,n[9]=S,n[10]=p,n[11]=h):h=n[11];let y;n[12]!==m?(y=m("header.github.accountsTitle"),n[12]=m,n[13]=y):y=n[13];let v;n[14]!==y?(v=s.jsx(ma,{className:"typography-ui-header font-semibold text-foreground",children:y}),n[14]=y,n[15]=v):v=n[15];let j;n[16]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(gn,{}),n[16]=j):j=n[16];let N;if(n[17]!==i||n[18]!==u||n[19]!==d||n[20]!==m){let D;n[22]!==u||n[23]!==d||n[24]!==m?(D=M=>{const A=M.user,_=!!M.current,L=M.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(qt,{className:"gap-2",disabled:d,onSelect:()=>{_||u(M.id)},children:[A?.avatarUrl?s.jsx("img",{src:A.avatarUrl,alt:A.login?m("header.github.avatarWithLogin",{login:A.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(T,{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:A?.name?.trim()||A?.login||"GitHub"}),A?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:A.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:L})]}):null]}),_?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},M.id)},n[22]=u,n[23]=d,n[24]=m,n[25]=D):D=n[25],N=i.map(D),n[17]=i,n[18]=u,n[19]=d,n[20]=m,n[21]=N}else N=n[21];let C;n[26]!==v||n[27]!==N?(C=s.jsxs(bn,{align:"end",className:"w-64",children:[v,j,N]}),n[26]=v,n[27]=N,n[28]=C):C=n[28];let k;return n[29]!==h||n[30]!==C?(k=s.jsxs(yn,{children:[h,C]}),n[29]=h,n[30]=C,n[31]=k):k=n[31],k}let f;n[32]!==a||n[33]!==m?(f=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[32]=a,n[33]=m,n[34]=f):f=n[34];let g;n[35]!==c||n[36]!==a||n[37]!==m?(g=c?s.jsx("img",{src:c,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(T,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=a,n[37]=m,n[38]=g):g=n[38];let x;return n[39]!==f||n[40]!==g?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:f,children:g}),n[39]=f,n[40]=g,n[41]=x):x=n[41],x}),yx=l.memo(function(e){const n=tt.c(43),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:a,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,shortcutLabel:m,remoteUpdateInfo:f,remoteUpdateChecking:g,remoteUpdateError:x,onOpenRemoteUpdate:w}=e,{t:S}=gt();let p;n[0]!==u||n[1]!==d?(p=F=>{d(F),F&&u()},n[0]=u,n[1]=d,n[2]=p):p=n[2];let h;n[3]!==o||n[4]!==r||n[5]!==S?(h=r?S("header.services.openWithCurrent",{current:o}):S("header.services.open"),n[3]=o,n[4]=r,n[5]=S,n[6]=h):h=n[6];const y=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let v;n[7]!==y?(v=Ce(bo,y),n[7]=y,n[8]=v):v=n[8];let j;n[9]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(T,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=j):j=n[9];let N;n[10]!==i||n[11]!==r?(N=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[10]=i,n[11]=r,n[12]=N):N=n[12];let C;n[13]!==h||n[14]!==v||n[15]!==N?(C=s.jsx(ft,{asChild:!0,children:s.jsx(xn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,className:v,children:[j,N]})})}),n[13]=h,n[14]=v,n[15]=N,n[16]=C):C=n[16];let k;n[17]!==o||n[18]!==m||n[19]!==S?(k=S("header.services.tooltip.currentInstance",{current:o,toggle:m("toggle_services_menu")}),n[17]=o,n[18]=m,n[19]=S,n[20]=k):k=n[20];let D;n[21]!==k?(D=s.jsx(mt,{children:s.jsx("p",{children:k})}),n[21]=k,n[22]=D):D=n[22];let M;n[23]!==C||n[24]!==D?(M=s.jsxs(ut,{children:[C,D]}),n[23]=C,n[24]=D,n[25]=M):M=n[25];let A;n[26]!==c||n[27]!==r||n[28]!==a||n[29]!==w||n[30]!==g||n[31]!==x||n[32]!==f||n[33]!==d||n[34]!==S?(A=r?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:S("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:f?.available?S("header.services.remoteUpdate.available",{version:f.version||""}):g?S("header.services.remoteUpdate.checking"):x||S("header.services.remoteUpdate.upToDate")})]}),f?.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:w,children:S("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Nm,{embedded:!0,open:a,onOpenChange:jx,onHostSwitched:()=>d(!1)})]}):null,n[26]=c,n[27]=r,n[28]=a,n[29]=w,n[30]=g,n[31]=x,n[32]=f,n[33]=d,n[34]=S,n[35]=A):A=n[35];let _;n[36]!==A?(_=s.jsx(bn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:A}),n[36]=A,n[37]=_):_=n[37];let L;return n[38]!==a||n[39]!==p||n[40]!==M||n[41]!==_?(L=s.jsxs(yn,{open:a,onOpenChange:p,children:[M,_]}),n[38]=a,n[39]=p,n[40]=M,n[41]=_,n[42]=L):L=n[42],L}),wx=(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??""),vx=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Sx=(t,e)=>{if(!t)return"-";try{return Kd(t,e,{fallback:"-"})}catch{return"-"}},Dn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Yi=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,mc=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{In("ui.header.render");const{t:o}=gt(),i=pe(O=>O.setSessionSwitcherOpen),c=pe(O=>O.toggleSidebar),a=pe(O=>O.isSidebarOpen),d=pe(O=>O.openContextOverview),u=pe(O=>O.openContextPlan),m=pe(O=>O.closeContextPanel),f=pe(O=>O.activeMainTab),g=pe(O=>O.setActiveMainTab),x=pe(O=>O.shortcutOverrides),w=pe(O=>O.timeFormatPreference),S=Vt(O=>O.getCurrentModel),p=tr(),h=Ge(O=>O.getContextUsage),y=Ge(O=>!!O.newSessionDraft?.open),v=Ge(O=>O.currentSessionId),j=Am(v??""),N=_d(v??""),C=Ou(v??""),k=Ms(Qn(l.useCallback(O=>{if(!v)return null;const Fe=O.activeSessions.find(bt=>bt.id===v);if(!Fe)return null;const Ye=Fe;return{title:Fe.title??null,directory:Ye.directory??null,created:Fe.time?.created??null,slug:Ye.slug??null,shareUrl:Fe.share?.url??null,parentId:Fe.parentID??null}},[v]))),D=Yt(Qn(O=>{if(!O.activeProjectId)return null;const Fe=O.projects.find(Ye=>Ye.id===O.activeProjectId);return Fe?{id:Fe.id,path:Fe.path,label:Fe.label}:null})),M=l.useMemo(()=>{if(!D)return null;const O=D.label?.trim();if(O)return O;const Fe=D.path.split(/[\\/]/).filter(Boolean);return Fe[Fe.length-1]??null},[D]),A=ys(O=>O.results),_=ys(O=>O.fetchAllQuotas),L=ys(O=>O.isLoading),F=ys(O=>O.lastUpdated),$=ys(O=>O.displayMode),W=ys(O=>O.showPredValues),U=ys(O=>O.dropdownProviderIds),K=ys(O=>O.loadSettings),b=ys(O=>O.setDisplayMode),{isMobile:P}=fr(),V=Pr(O=>O.status),G=Pr(O=>O.setStatus),X=l.useRef(null),[J,ee]=l.useState(()=>typeof window>"u"?!1:_n()),le=l.useMemo(()=>wi(),[]),oe=$d(),[Ae,Se]=l.useState(!1),Y=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:je,side:me}=Su(),z=l.useMemo(()=>{if(typeof window>"u")return null;const O=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof O=="number"&&Number.isFinite(O)&&O>0)return O;if(typeof navigator>"u")return null;const Fe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Fe)return null;const Ye=Number.parseInt(Fe[1],10),bt=Number.parseInt(Fe[2],10);return Number.isNaN(Ye)?null:Ye===10?bt:Ye},[]);He.useEffect(()=>{typeof window>"u"||ee(_n())},[]);const Z=S(),ne=Z&&typeof Z.limit=="object"&&Z.limit!==null?Z.limit:null,fe=ne&&typeof ne.context=="number"?ne.context:0,xe=ne&&typeof ne.output=="number"?ne.output:0,Te=h(fe,xe),[be,De]=l.useState(null),Ee=!v||j;He.useEffect(()=>{if(!v){De(O=>O===null?O:null);return}if(Te&&Te.totalTokens>0){De(O=>wx(O,Te)?O:Te);return}Ee&&De(O=>O===null?O:null)},[Te,v,Ee]);const Re=pe(O=>O.isSessionSwitcherOpen),de=V?.connected?V.user?.avatarUrl??null:null,H=V?.connected?V.user?.login??null:null,Ne=V?.accounts??[],[he,ve]=l.useState(!1),[se,Q]=l.useState(!1),[ye,re]=l.useState(!1),[R,ce]=l.useState(!1),[Me,ge]=l.useState("Local"),[te,ae]=l.useState(!0),[ie,E]=l.useState(!1),[I,ue]=l.useState(null),[ke,we]=l.useState(!1),[qe,Je]=l.useState(null),st=l.useMemo(()=>vx(Me),[Me]),[rt,ot]=l.useState("usage"),lt=l.useMemo(()=>er(),[]),kt=pe(O=>O.workStatusPanelVisible),nt=pe(O=>O.workStatusPanelEnabled),it=pe(O=>O.setWorkStatusPanelEnabled),St=pe(O=>O.workStatusPanelFits),It=pe(O=>O.workStatusOverlayOpen),Ft=pe(O=>O.setWorkStatusOverlayOpen),Ot=nt&&St||It,Ke=l.useCallback(()=>{if(nt&&!St){Ft(!It);return}it(!nt)},[Ft,it,It,nt,St]),$t=!lt&&!kt&&f==="chat"&&!!be&&be.totalTokens>0,Tt=be&&be.contextLimit>0?Math.min(999,be.totalTokens/be.contextLimit*100):0,dt=l.useCallback(async()=>{if(!(typeof window>"u"||!J))try{if(bi()){ge("Local"),ae(!0);return}ae(!1);const O=await Td(),Fe=Dm(),Ye=Pm([Im(Fe),...O.hosts]);if(Ye.id===Tm){ge("Local"),ae(!0);return}ge(Ed(Ye.label.trim()||"Instance"))}catch{ge("Local"),ae(!0)}},[J]);He.useEffect(()=>(dt(),Fa(()=>{dt()})),[dt]);const Ct=l.useCallback(async()=>{if(te){ue(null),Je(null);return}we(!0),Je(null);try{const O=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Fe=await hs(`/api/openchamber/update-check?${O.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Fe.ok)throw new Error(`Server responded with ${Fe.status}`);const Ye=await Fe.json();ue({available:Ye.available??!1,version:Ye.version,currentVersion:Ye.currentVersion??"unknown",body:Ye.body,nextSuggestedCheckInSec:typeof Ye.nextSuggestedCheckInSec=="number"?Ye.nextSuggestedCheckInSec:void 0,packageManager:Ye.packageManager,updateCommand:Ye.updateCommand})}catch(O){ue(null),Je(O instanceof Error?O.message:o("header.services.remoteUpdate.error"))}finally{we(!1)}},[te,o]);l.useEffect(()=>{ue(null),Je(null),E(!1)},[te,Me]),l.useEffect(()=>{if(!J||te)return;const O=3e3,Fe=3600*1e3;let Ye=!1,bt=null;const Wt=ts=>{bt=window.setTimeout(()=>{if(Ye||typeof document<"u"&&document.visibilityState!=="visible"){Wt(Fe);return}Ct().finally(()=>{Ye||Wt(Fe)})},ts)};return Wt(O),()=>{Ye=!0,bt!==null&&window.clearTimeout(bt)}},[Ct,te,Me,J]);const Rt=l.useCallback(()=>{if(I?.available){E(!0);return}Ct()},[Ct,I?.available]);Em();const Qt=ys(O=>O.selectedModels),Qe=ys(O=>O.expandedFamilies),ht=ys(O=>O.toggleFamilyExpanded),Xe=l.useMemo(()=>{const O=[];for(const Fe of zd){if(!U.includes(Fe.id))continue;const Ye=A.find(ms=>ms.providerId===Fe.id),bt=Ye?.usage?.windows??{},Wt=Ye?.usage?.models,ts=Object.entries(bt),Xt={providerId:Fe.id,providerName:Fe.name,entries:ts,error:Ye&&!Ye.ok&&Ye.configured?Ye.error:void 0};if(Wt&&Object.keys(Wt).length>0){const ms=Qt[Fe.id]??[],Ls=ms.length>0,Rr=Mm(Wt,Fe.id),Or=Rm(Fe.id),Do=Om(Or);Xt.modelFamilies=[];for(const _s of Do){const Vn=Rr.get(_s.id)??[];if(Vn.length===0)continue;const Hn=Ls?Vn.filter(br=>ms.includes(br)):Vn;if(Hn.length===0)continue;const Kn=[];for(const br of Hn){const yr=Wt[br];if(yr?.windows){const wr=Object.entries(yr.windows);wr.length>0&&Kn.push([br,wr[0][1]])}}Kn.length>0&&Xt.modelFamilies.push({familyId:_s.id,familyLabel:_s.label,models:Kn})}const Rn=Rr.get(null)??[],to=Ls?Rn.filter(_s=>ms.includes(_s)):Rn;if(to.length>0){const _s=[];for(const Vn of to){const Hn=Wt[Vn];if(Hn?.windows){const Kn=Object.entries(Hn.windows);Kn.length>0&&_s.push([Vn,Kn[0][1]])}}_s.length>0&&Xt.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:_s})}}(ts.length>0||Xt.modelFamilies&&Xt.modelFamilies.length>0||Xt.error)&&O.push(Xt)}return O},[U,A,Qt,o]),_e=Xe.length>0;l.useEffect(()=>{K()},[K]);const yt=l.useCallback(async O=>{b(O);try{await Md({usageDisplayMode:O})}catch(Fe){console.warn("Failed to update usage display mode:",Fe)}},[b]),zt=l.useCallback(()=>{if(R)return;ce(!0);const O=new Promise(Fe=>setTimeout(Fe,500));Promise.all([_(),O]).finally(()=>{ce(!1)})},[_,R]),Bt=v?k??null:null,Lt=l.useRef(null),[_t,Ht]=l.useState(0);l.useEffect(()=>{if(!v){Lt.current&&(Lt.current=null,Ht(bt=>bt+1));return}if(Bt){Lt.current={sessionId:v,session:Bt,expiresAt:Date.now()+2e3};return}const O=Lt.current;if(!O||O.sessionId!==v)return;const Fe=O.expiresAt-Date.now();if(Fe<=0){Lt.current=null,Ht(bt=>bt+1);return}const Ye=window.setTimeout(()=>{Lt.current?.sessionId===v&&(Lt.current=null),Ht(bt=>bt+1)},Fe);return()=>{window.clearTimeout(Ye)}},[v,Bt]);const Dt=(()=>{if(Bt)return Bt;if(!v)return null;const O=Lt.current;return O&&O.sessionId===v&&O.expiresAt>Date.now()?O.session:null})(),fs=Ge(O=>v?O.worktreeMetadata.get(v)?.path??"":""),Kt=Ge(O=>v?O.worktreeMetadata.get(v)?.branch?.trim()??null:null),Nt=Wd(O=>v?O.getAttachment(v):void 0),Zt=l.useMemo(()=>Nt?Fm(Nt,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,Nt]),ss=l.useMemo(()=>Nt?Nt.legacy?"legacy":Nt.degraded?"degraded":Nt.worktreeStatus==="pending"?"pending":Nt.worktreeStatus==="missing"?"missing":Nt.worktreeStatus==="invalid"?"invalid":Nt.attentionReason?"attention":null:null,[Nt]),Oe=l.useMemo(()=>Dn(fs||""),[fs]),Ue=l.useMemo(()=>{const O=typeof Dt?.directory=="string"?Dt.directory:"";return Dn(O||"")},[Dt?.directory]),Ve=Ge(O=>O.newSessionDraft?.open?Dn(O.newSessionDraft.bootstrapPendingDirectory??O.newSessionDraft.directoryOverride??""):""),Be=l.useMemo(()=>Oe||Ue||Ve,[Ve,Ue,Oe]),We=pe(l.useCallback(O=>{const Fe=Dn(Be||"");return Fe?Yi(O.contextPanelByDirectory[Fe]):null},[Be])),wt=Ge(O=>{const Fe=Dn(Oe||Ue||"");if(!Fe)return null;for(const Ye of O.availableWorktreesByProject.values()){const Wt=Ye.find(ts=>Dn(ts.path)===Fe)?.branch?.trim();if(Wt)return Wt}return null}),xt=Bm(Be||null)||Kt||wt,ns=!kt&&!!(M||xt||!y&&ss),ds=l.useMemo(()=>{if(!v)return M??"OpenChamber";const O=Dt?.title?.trim();return O&&O.length>0?O:"Untitled Session"},[M,Dt?.title,v]),es=La(Be||void 0,{bootstrap:!1}),js=Si(),sn=Ge(O=>O.updateSessionTitle),Mn=Ge(O=>O.shareSession),$n=Ge(O=>O.unshareSession),Ds=Ge(O=>O.archiveSessions),nn=Ge(O=>O.deleteSessions),[Sn,Ps]=l.useState(!1),[rn,Qs]=l.useState(!1),on=l.useRef(!1),[an,zn]=l.useState(""),[Os,ln]=l.useState(null),cn=l.useRef(null);l.useEffect(()=>{on.current=!1,Qs(!1),Ps(!1),zn(""),ln(null)},[v]);const q=l.useCallback(()=>{v&&(zn(Dt?.title?.trim()||ds),Ps(!0))},[Dt?.title,v,ds]),$e=l.useCallback(async()=>{if(!v)return;const O=an.trim();O&&O!==Dt?.title?.trim()&&await sn(v,O),Ps(!1)},[Dt?.title,v,an,sn]);l.useEffect(()=>{if(!Sn)return;const O=Fe=>{const Ye=Fe.target;(!Ye||!cn.current?.contains(Ye))&&$e()};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[Sn,$e]);const Ze=l.useCallback(()=>{v&&Bn(v).then(O=>{Ie[O.ok?"success":"error"](o(O.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Ie.error(o("sessions.sidebar.session.copyId.error")))},[v,o]),ct=l.useCallback(async()=>{if(!v)return;const O=await Mn(v);if(O?.share?.url){const Fe=await Bn(O.share.url);Ie[Fe.ok?"success":"warning"](o("sessions.sidebar.session.share.successTitle"),{description:o(Fe.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Ie.error(o("sessions.sidebar.session.share.error"))},[v,Mn,o]),Pt=l.useCallback(()=>{const O=Dt?.shareUrl;O&&Bn(O).then(Fe=>{Ie[Fe.ok?"success":"error"](o(Fe.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Ie.error(o("sessions.sidebar.session.share.copyUrlError")))},[Dt?.shareUrl,o]),jt=l.useCallback(async()=>{if(!v)return;const O=await $n(v);Ie[O?"success":"error"](o(O?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[v,o,$n]),pt=l.useCallback(async()=>{if(!v||!Be){Ie.error(o("sessions.sidebar.session.export.nothingToExport"));return}try{await js.loadCompleteHistory(v,Be)}catch{Ie.error(o("sessions.sidebar.session.export.failedLoadHistory"));return}const O=ha(es.getState(),v).list;if(O.length===0){Ie.error(o("sessions.sidebar.session.export.nothingToExport"));return}const Fe=Tu(O,Dt?.title??null),Ye=Ru(Dt?.title??null);await Mu(Fe,Ye)||Eu(Fe,Ye),Ie.success(o("sessions.sidebar.session.export.success"))},[Dt?.title,v,es,Be,js,o]),is=N?.type==="busy"||N?.type==="retry",vs=l.useCallback(()=>{if(!v||!Ue||is||C)return;const O=Ms.getState().activeSessions,Fe=O.find(Wt=>Wt.id===v);if(!Fe)return;const Ye=[],bt=[v];for(let Wt=0;Wt<bt.length;Wt+=1){const ts=bt[Wt];for(const Xt of O)Xt.parentID===ts&&(Ye.push(Xt),bt.push(Xt.id))}Fu({root:Fe,descendants:Ye,sourceDirectory:Ue,successMessage:o("sessions.sidebar.session.moveToWorktree.success"),failureMessage:o("sessions.sidebar.session.moveToWorktree.failed")})},[v,is,C,Ue,o]),rs=l.useCallback(async()=>{if(!v||!Os)return;const O=Ms.getState().activeSessions,Fe=[v];for(let ts=0;ts<Fe.length;ts+=1){const Xt=Fe[ts];for(const ms of O)ms.parentID===Xt&&!Fe.includes(ms.id)&&Fe.push(ms.id)}const Ye=Os;if(ln(null),(Ye==="archive"?await Ds(Fe):await nn(Fe)).failedIds.length>0){Ie.error(o(Ye==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Ie.success(o(Ye==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[Ds,v,nn,Os,o]),Is=pe(O=>O.isScheduledTasksDialogOpen),Fs=pe(O=>O.isArchivePageOpen),jn=pe(O=>O.worktreesPageProjectId),dn=pe(O=>O.isMultiRunLauncherOpen),Tr=Yt(O=>{if(!jn)return null;const Fe=O.projects.find(Ye=>Ye.id===jn);return Fe?.label?.trim()||Fe?.path?.split("/").pop()||null}),Wn=l.useMemo(()=>Is?{title:o("sessions.scheduledTasks.dialog.title"),subtitle:null}:Fs?{title:o("sessions.archivePage.title"),subtitle:null}:jn?{title:o("sessions.worktreesPage.title",{project:Tr??""}),subtitle:null}:dn?{title:o("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[Fs,dn,Is,o,jn,Tr]),un=l.useMemo(()=>Dn(Be||D?.path||""),[D?.path,Be]),kn=l.useMemo(()=>D?{id:D.id,path:D.path}:null,[D]),Er=l.useRef(null);l.useEffect(()=>{!kn||!un||(Er.current={projectRef:kn,directory:un})},[un,kn]);const hr=l.useMemo(()=>kn&&un?{projectRef:kn,directory:un}:Er.current,[un,kn]),Pe=_a(O=>O.planModeEnabled),At=Ge(O=>O.isSessionPlanAvailable),Ut=Pe&&v?At(v):!1,as=Ut,ps=l.useRef("");l.useEffect(()=>{if(!Pe){pe.getState().activeMainTab==="plan"&&pe.getState().setActiveMainTab("chat");return}if(!v)return;const O=`${v||"none"}:${Ue||"none"}:${Dt?.created||0}:${Dt?.slug||"none"}`;ps.current!==O&&(ps.current=O),!Ut&&pe.getState().activeMainTab==="plan"&&pe.getState().setActiveMainTab("chat")},[Pe,Ut,Dt?.slug,Dt?.created,v,Ue]);const ws=l.useCallback(async O=>{if(!(!O||he)){ve(!0);try{const Fe=p.github?await p.github.authActivate(O):await(async()=>{const Ye=await hs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:O})}),bt=await Ye.json().catch(()=>null);if(!Ye.ok||!bt)throw new Error(bt?.error||Ye.statusText);return bt})();G(Fe)}catch(Fe){console.error("Failed to switch GitHub account:",Fe)}finally{ve(!1)}}},[he,p.github,G]),ks=l.useCallback(()=>{if(typeof document>"u")return;const O=document.activeElement;if(!O)return;const Fe=O.tagName;(Fe==="INPUT"||Fe==="TEXTAREA"||Fe==="SELECT"||O.isContentEditable)&&O.blur()},[]),Ts=l.useCallback(()=>{if(P){ks(),i(!Re);return}c()},[ks,P,Re,i,c]),Bs=l.useCallback(()=>{Jn("desktop_open_draft_mini_chat_window",{directory:Dn(Be||D?.path||""),projectId:D?.id??null,apiBaseUrl:cr(),clientToken:ri()}).catch(O=>{console.warn("[header] failed to open draft mini chat window",O)})},[D?.id,D?.path,Be]),pr=l.useCallback(()=>{if(y){Bs();return}v&&Jn("desktop_open_session_mini_chat_window",{sessionId:v,directory:Dn(Be||D?.path||""),apiBaseUrl:cr(),clientToken:ri()}).catch(O=>{console.warn("[header] failed to open session mini chat window",O)})},[D?.path,v,Bs,y,Be]),xs=l.useCallback(()=>{const O=Dn(Be||"");if(!O)return;const Fe=pe.getState().contextPanelByDirectory[O];if(Yi(Fe)==="context"){m(O);return}d(O)},[m,d,Be]),gs=We==="context",Cn=l.useCallback(()=>{const O=Dn(Be||"");if(!O)return;const Fe=pe.getState().contextPanelByDirectory[O];if(Yi(Fe)==="plan"){m(O);return}u(O)},[m,u,Be]),Jr=bo,gr=gx,Mr=l.useMemo(()=>se?"services":n?"sessions":r?"git":f,[f,se,n,r]),Zr=l.useCallback(()=>{Q(!1),n&&t&&t(),r&&e&&e(),!t&&Re&&i(!1)},[Re,n,t,e,r,i]),Ei=l.useCallback(()=>{n||Q(!1),t?.()},[n,t]),Mi=l.useCallback(()=>{r||Q(!1),e?.()},[e,r]),jo=l.useMemo(()=>J&&Y&&!Ae?"5.5rem":oe?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!J||je)&&!lt?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[J,Ae,Y,oe,lt,je]);He.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",jo)},[jo]);const Ri=a?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Oi=a?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";He.useEffect(()=>{if(!J||!Y){Se(!1);return}let O=!1;const Fe=async()=>{try{const bt=await Jn("desktop_is_window_fullscreen");O||Se(bt===!0)}catch{O||Se(!1)}},Ye=()=>{Fe()};return Fe(),window.addEventListener("openchamber:window-resized",Ye),()=>{O=!0,window.removeEventListener("openchamber:window-resized",Ye)}},[J,Y]);const ko=l.useMemo(()=>!J||!Y||z===null?"":z>=26?"h-12":z<=15?"h-14":"",[J,Y,z]),Fi=l.useMemo(()=>{if(!(J&&!je||lt))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))"}},[J,lt,je]),Un=l.useCallback(()=>{if(typeof document>"u")return;const O=X.current?.getBoundingClientRect().height;O&&document.documentElement.style.setProperty("--oc-header-height",`${O}px`)},[]);He.useEffect(()=>{if(typeof window>"u")return;Un();const O=X.current;if(!O||typeof ResizeObserver>"u")return()=>{};let Fe=0;const Ye=()=>{Fe||(Fe=requestAnimationFrame(()=>{Fe=0,Un()}))},bt=new ResizeObserver(Ye);return bt.observe(O),window.addEventListener("resize",Ye),window.addEventListener("orientationchange",Ye),()=>{Fe&&cancelAnimationFrame(Fe),bt.disconnect(),window.removeEventListener("resize",Ye),window.removeEventListener("orientationchange",Ye)}},[Un]),He.useEffect(()=>{Un()},[Un,P,ko]);const Co=l.useCallback(async O=>{const Fe=O.target;Fe.closest(".app-region-no-drag")||Fe.closest("button, a, input, select, textarea")||O.button===0&&J&&await tm()},[J]),Nn=l.useMemo(()=>{if(P){const O=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return as&&O.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),O.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"},{id:"diagram",label:o("layout.mainTab.diagram"),icon:"file"}),O}return[]},[P,as,o]),No=l.useCallback(O=>ji(Ar(O,x)),[x]);He.useEffect(()=>{!P&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&g("chat")},[f,P,g]);const eo=l.useMemo(()=>{const O=[];return J&&O.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(T,{name:"server",className:"h-3.5 w-3.5"})}),O},[J,o]),Bi=l.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(T,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Ud,{className:"h-3.5 w-3.5"})}],[o]);He.useEffect(()=>{const O=Fe=>{if(Vd(Fe)&&!Fe.shiftKey&&!Fe.altKey){const Ye=parseInt(Fe.key,10);Ye>=1&&Ye<=Nn.length&&(Fe.preventDefault(),P&&(ks(),Zr()),g(Nn[Ye-1].id))}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ks,Zr,P,g,Nn]),He.useEffect(()=>{const O=Fe=>{const Ye=Ar("toggle_services_menu",x);if(Vi(Fe,Ye)){Fe.preventDefault(),ye?re(!1):(re(!0),dt());return}const bt=Ar("cycle_services_tab",x);if(Vi(Fe,bt)){if(Fe.preventDefault(),eo.length===0)return;re(!0),dt();return}const Wt=Ar("toggle_context_plan",x);Vi(Fe,Wt)&&(Fe.preventDefault(),Cn())};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[x,ye,eo,A.length,_,dt,Cn]);const Li=O=>{const Fe=f===O.id,Ye=O.icon==="diff",bt=Ye?null:O.icon,Wt=O.id==="chat",ts=ms=>Ye?s.jsx(cc,{size:ms}):bt?s.jsx(T,{name:bt,className:`h-${ms/4} w-${ms/4}`}):null,Xt=s.jsxs("button",{type:"button",onClick:()=>g(O.id),className:Ce("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Fe?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Wt&&!P&&"min-w-[100px] justify-center"),"aria-label":O.label,"aria-selected":Fe,role:"tab",children:[P?ts(20):s.jsxs(s.Fragment,{children:[ts(16),s.jsx("span",{className:"header-tab-label",children:O.label})]}),O.badge!==void 0&&O.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:O.badge})]});return s.jsx(l.Fragment,{children:Xt},O.id)},_i=s.jsxs(s.Fragment,{children:[s.jsx(Rg,{directory:un,className:"mr-1"}),J?s.jsx(yx,{isDesktopApp:J,currentInstanceLabel:Me,compactCurrentInstanceLabel:st,currentInstanceIsLocal:te,isDesktopServicesOpen:ye,setIsDesktopServicesOpen:re,refreshCurrentInstanceLabel:dt,shortcutLabel:No,remoteUpdateInfo:I,remoteUpdateChecking:ke,remoteUpdateError:qe,onOpenRemoteUpdate:Rt}):null,s.jsx(bx,{isMobile:P,githubAuthStatus:V,githubAccounts:Ne,githubAvatarUrl:de,githubLogin:H,isSwitchingGitHubAccount:he,handleGitHubAccountSwitch:ws})]}),Xs=le&&(y||!!v),$i=()=>s.jsxs("div",{onMouseDown:Co,className:Ce("app-region-drag relative flex h-12 select-none items-center pr-3",ko),style:Fi,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Ri}}),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:Oi}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Wn?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:Wn.title}),Wn.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:Wn.subtitle}):null]}):s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[a?null:s.jsx(ag,{align:"start",children:s.jsx("button",{type:"button",className:Jr,"aria-label":o("sessions.switcher.openAria"),children:s.jsx(T,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[Sn?s.jsxs("form",{ref:cn,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:O=>{O.preventDefault(),$e()},children:[s.jsx("input",{value:an,onChange:O=>zn(O.target.value),autoFocus:!0,onKeyDown:O=>{O.stopPropagation(),O.key==="Escape"&&Ps(!1)},placeholder:o("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":o("sessions.sidebar.session.rename.save"),title:o("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ps(!1),"aria-label":o("sessions.sidebar.session.rename.cancel"),title:o("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{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:y?o("sessions.switcher.draftTitle"):ds}),ns?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:[M?s.jsx("span",{className:"truncate",children:M}):null,xt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:xt})]}):null,!y&&ss?s.jsxs("span",{className:Ce("inline-flex min-w-0 items-center gap-0.5",ss==="attention"||ss==="invalid"||ss==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(T,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Zt})]}):null]}):null]}),s.jsx("div",{className:Ce("flex h-[18px] shrink-0 items-center justify-center",ns?"self-start":"self-center"),children:v&&!y&&!Sn?s.jsxs(yn,{open:rn,onOpenChange:Qs,onOpenChangeComplete:O=>{!O&&on.current&&(on.current=!1,q())},children:[s.jsx(xn,{asChild:!0,children:s.jsx(et,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":o("header.sessionActions.openAria"),children:s.jsx(T,{name:"more",className:"size-4"})})}),s.jsxs(bn,{align:"end",className:"min-w-[190px]",children:[s.jsxs(qt,{onClick:()=>{on.current=!0},children:[s.jsx(T,{name:"pencil-ai",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.rename")]}),s.jsxs(qt,{onClick:Ze,children:[s.jsx(T,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyId")]}),s.jsx(gn,{}),Dt?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(qt,{onClick:Pt,children:[s.jsx(T,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(qt,{onClick:()=>{jt()},children:[s.jsx(T,{name:"link-unlink-m",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(qt,{onClick:()=>{ct()},children:[s.jsx(T,{name:"share-2",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.share")]}),s.jsxs(qt,{onClick:()=>{pt()},children:[s.jsx(T,{name:"download",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.exportMarkdown")]}),!lt&&Dt&&!Dt.parentId?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(qt,{disabled:!Ue||is||C,onClick:vs,className:"w-full",children:[s.jsx(T,{name:"folder-shared",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(mt,{side:"right",className:"max-w-72",children:o(C?"sessions.sidebar.session.moveToWorktree.tooltipMoving":is?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(gn,{}),s.jsxs(qt,{onClick:()=>ln("archive"),children:[s.jsx(T,{name:"inbox-archive",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.archive")]}),s.jsxs(qt,{className:"text-destructive focus:text-destructive",onClick:()=>ln("delete"),children:[s.jsx(T,{name:"delete-bin",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}),Nn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Nn.map(O=>Li(O))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[$t&&be?s.jsx(lg,{totalTokens:be.totalTokens,percentage:Tt,colorPercentage:be.percentage,contextLimit:be.contextLimit,outputLimit:be.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:xs,pressed:gs,className:Xs?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(xx,{visible:Xs,title:o(y?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(y?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:pr,className:Ce(Jr,"mr-1"),Icon:"picture-in-picture-2"}),f==="chat"&&!lt?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":Ot,"aria-label":o("header.workStatusPanel.toggleAria"),onClick:Ke,className:Ce(bo,"mr-1",Ot?"text-foreground":"text-muted-foreground/50"),children:s.jsx(T,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(mt,{side:"bottom",children:o(nt&&!St?It?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":nt?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}):null,_i,s.jsx(ju,{visible:je&&me==="right",position:"right"})]})]})]}),xr=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:Ei,className:Ce(gr,Mr==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(T,{name:"layout-left",className:"h-5 w-5"})}):Re?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.backAria"),children:s.jsx(T,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Ts,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.openSessionsAria"),children:s.jsx(T,{name:"play-list-add",className:"h-5 w-5"})}),!t&&Re&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!Re||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":o("header.navigation.mainAria"),children:Nn.map(O=>{const Fe=f===O.id,Ye=O.icon==="diff",bt=Ye?null:O.icon;return s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{P&&(ks(),Zr()),g(O.id)},"aria-label":O.label,"aria-selected":Fe,role:"tab",className:Ce(gr,"relative rounded-lg",Mr===O.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Ye?s.jsx(cc,{className:"h-5 w-5"}):bt?s.jsx(T,{name:bt,className:"h-5 w-5"}):null,O.badge!==void 0&&O.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:O.badge}),O.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(mt,{children:s.jsx("p",{children:O.label})})]},O.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[hr&&s.jsx(Du,{projectRef:hr.projectRef,directory:hr.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(yn,{open:se,onOpenChange:O=>{O&&(n&&t&&t(),r&&e&&e()),Q(O),O&&A.length===0&&_()},children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:Ce(gr,Mr==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(T,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(mt,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(bn,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Xa,{items:Bi,activeId:rt,onSelect:O=>{const Fe=O;ot(Fe),Fe==="usage"&&A.length===0&&_()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Q(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":o("header.services.closeAria"),children:s.jsx(T,{name:"close",className:"h-5 w-5"})})]})}),rt==="mcp"&&s.jsx(Hp,{active:se&&rt==="mcp"}),rt==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Sx(F,w)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>yt("usage"),className:Ce("typography-ui-label px-1 pb-0.5 transition-colors",$==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>yt("remaining"),className:Ce("typography-ui-label px-1 pb-0.5 transition-colors",$==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:Ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:zt,disabled:L||R,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(T,{name:"refresh",className:Ce("h-4 w-4",R&&"animate-spin")})})]})]})}),!_e&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:Xe.map((O,Fe)=>s.jsxs(l.Fragment,{children:[Fe>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(oi,{providerId:O.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:O.providerName})]}),O.entries.length===0&&(!O.modelFamilies||O.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:O.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[O.entries.map(([Ye,bt])=>{const Wt=$==="remaining"?bt.remainingPercent:bt.usedPercent,ts=Rl(bt.usedPercent,bt.resetAt,bt.windowSeconds,Ye),Xt=ts?.dailyAllocationPercent!=null?$==="remaining"?100-To(ts.elapsedRatio):To(ts.elapsedRatio):null,ms=pa(bt.valueLabel,Wt),Ls=Lm(bt.resetAt,bt.resetAfterFormatted??bt.resetAtFormatted,w);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Hd(Ye)}),Ls?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Ls}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:ms==="-"?"":ms})]}),s.jsx(Jl,{percent:Wt,tonePercent:bt.usedPercent,className:"h-1.5",expectedMarkerPercent:Xt}),ts&&W?s.jsx(Zl,{paceInfo:ts,compact:!0}):null]},`${O.providerId}-${Ye}`)}),O.modelFamilies&&O.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:O.modelFamilies.map(Ye=>{const Wt=(Qe[O.providerId]??[]).includes(Ye.familyId??"other");return s.jsxs(ci,{open:Wt,onOpenChange:()=>ht(O.providerId,Ye.familyId??"other"),children:[s.jsxs(Ja,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ye.familyLabel}),Wt?s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(T,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(di,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ye.models.map(([ts,Xt])=>{const ms=$==="remaining"?Xt.remainingPercent:Xt.usedPercent,Ls=Rl(Xt.usedPercent,Xt.resetAt,Xt.windowSeconds),Rr=Ls?.dailyAllocationPercent!=null?$==="remaining"?100-To(Ls.elapsedRatio):To(Ls.elapsedRatio):null,Or=pa(Xt.valueLabel,ms);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:_m(ts)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Or==="-"?"":Or})]}),s.jsx(Jl,{percent:ms,tonePercent:Xt.usedPercent,className:"h-1.5",expectedMarkerPercent:Rr}),Ls&&W?s.jsx(Zl,{paceInfo:Ls,compact:!0}):null]},`${O.providerId}-${ts}`)})})})]},Ye.familyId??"other")})})]})]},O.providerId))})]})]})})]}),e?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Mi,className:Ce(gr,"relative",Mr==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(T,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(mt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Ao=Ce("header-safe-area relative z-10 bg-background",P&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:X,className:Ao,style:{"--padding-scale":"1"},children:P?xr():$i()}),s.jsx(qs,{open:Os!==null,onOpenChange:O=>{O||ln(null)},children:s.jsxs(Ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(En,{children:[s.jsx(wn,{children:o(Os==="delete"?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(vn,{children:Os==="delete"?o("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:ds}):o("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:ds})})]}),s.jsxs(mr,{children:[s.jsx(et,{variant:"outline",size:"sm",onClick:()=>ln(null),children:o("sessions.sidebar.dialogs.cancel")}),s.jsx(et,{variant:"destructive",size:"sm",onClick:()=>{rs()},children:o(Os==="delete"?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(hu,{open:ie,onOpenChange:E,info:I,downloading:!1,downloaded:!1,progress:null,error:qe,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function jx(){}const hc=280,pc=280,gc=500,kx=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:i}=gt(),c=pe(k=>k.sidebarWidth),a=pe(k=>k.setSidebarWidth),[d,u]=l.useState(!1),m=l.useRef(0),f=l.useRef(c||hc),g=l.useRef(null),x=l.useRef(null),w=l.useRef(null),S=l.useCallback(k=>Math.min(gc,Math.max(pc,k)),[]),p=l.useCallback(k=>{const D=w.current;D&&(D.style.width=`${k}px`,D.style.minWidth=`${k}px`,D.style.maxWidth=`${k}px`,D.style.setProperty("--oc-left-sidebar-width",`${k}px`))},[]);if(l.useEffect(()=>{e&&d&&u(!1)},[e,d]),l.useEffect(()=>{d||(g.current=null,x.current=null)},[d]),e)return null;const h=Math.min(gc,Math.max(pc,c||hc)),y=t?h:0,v=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}x.current=k.pointerId,u(!0),m.current=k.clientX,f.current=y,g.current=y,p(y),k.preventDefault()}},j=k=>{if(e||!d||x.current!==k.pointerId)return;const D=k.clientX-m.current,M=S(f.current+D);g.current!==M&&(g.current=M,p(M))},N=k=>{if(x.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const D=S(g.current??y);x.current=null,g.current=null,u(!1),a(D)},C=d?g.current??y:y;return s.jsxs("aside",{ref:w,className:Ce("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:h}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||y===0,children:[t&&s.jsx("div",{className:"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:Ce("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:v,onPointerMove:j,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Ce("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(us,{children:n})})]})]})},Cx=()=>{const t=tt.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},Eo=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Nx(){const t=Yt(f=>f.activeProjectId?f.projects.find(g=>g.id===f.activeProjectId)??null:null),e=Ge(f=>f.currentSessionId),n=$m(e??null),r=Ge(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=Ge(f=>f.newSessionDraft?.open?Eo(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),i=l.useMemo(()=>Eo(r||""),[r]),c=l.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return Eo(f||"")},[n?.directory]),a=i||c||o,d=l.useMemo(()=>Eo(a||t?.path||""),[t?.path,a]),u=l.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),m=l.useRef(null);return l.useEffect(()=>{u&&d&&(m.current={projectRef:u,directory:d})},[d,u]),l.useMemo(()=>u&&d?{projectRef:u,directory:d}:m.current,[u,d])}const xc="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",Ax=()=>{const t=tt.c(35),{t:e}=gt(),n=pe(Dx),r=pe(Px),o=Nx(),i=l.useRef(null),c=ji(Ar("toggle_sidebar",r)),{usesFramelessChrome:a,side:d}=Su(),u=Tx;let m,f;t[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{if(typeof document>"u")return;const $=i.current;if(!$)return;const W=()=>{const K=Math.max($.getBoundingClientRect().width,$.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(K)}px`)};if(W(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(W);return U.observe($),()=>{U.disconnect()}},f=[],t[0]=m,t[1]=f):(m=t[0],f=t[1]),l.useEffect(m,f);const g="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=x):x=t[2];const w="flex items-center gap-2";let S;t[3]!==a||t[4]!==d?(S=a&&d==="left"?s.jsx(ju,{visible:!0,position:"left"}):null,t[3]=a,t[4]=d,t[5]=S):S=t[5];let p;t[6]!==e||t[7]!==a?(p=a?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:Ce(xc,"shrink-0"),children:s.jsx(T,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(mt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=a,t[8]=p):p=t[8];const h=ut;let y;t[9]!==e?(y=e("header.actions.openSessionsAria"),t[9]=e,t[10]=y):y=t[10];let v,j;t[11]===Symbol.for("react.memo_cache_sentinel")?(v=Ce(xc,"shrink-0"),j=s.jsx(T,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=v,t[12]=j):(v=t[11],j=t[12]);let N;t[13]!==y||t[14]!==n?(N=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":y,className:v,children:j})}),t[13]=y,t[14]=n,t[15]=N):N=t[15];const C=mt,k=e("header.actions.openSessionsWithShortcut",{shortcut:c});let D;t[16]!==k?(D=s.jsx("p",{children:k}),t[16]=k,t[17]=D):D=t[17];let M;t[18]!==C||t[19]!==D?(M=s.jsx(C,{children:D}),t[18]=C,t[19]=D,t[20]=M):M=t[20];let A;t[21]!==h||t[22]!==N||t[23]!==M?(A=s.jsxs(h,{children:[N,M]}),t[21]=h,t[22]=N,t[23]=M,t[24]=A):A=t[24];let _;t[25]!==o?(_=o?s.jsx(Du,{projectRef:o.projectRef,directory:o.directory}):null,t[25]=o,t[26]=_):_=t[26];let L;t[27]!==A||t[28]!==_||t[29]!==S||t[30]!==p?(L=s.jsxs("div",{ref:i,className:w,children:[S,p,A,_]}),t[27]=A,t[28]=_,t[29]=S,t[30]=p,t[31]=L):L=t[31];let F;return t[32]!==L||t[33]!==x?(F=s.jsx("div",{className:g,style:x,children:L}),t[32]=L,t[33]=x,t[34]=F):F=t[34],F};function Dx(t){return t.toggleSidebar}function Px(t){return t.shortcutOverrides}function Ix(t){console.warn("[titlebar] failed to open app menu",t)}function Tx(t){const e=t.currentTarget.getBoundingClientRect();Jn("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Ix)}const bc=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Ex(t,e,n){const r=tt.c(5),[o,i]=l.useState();let c,a;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[u,m]=await Promise.all([zm(t),Wm(t)]).catch(Mx);if(d)return;const f=bc(u),g=bc(m);if(!f||!g||g===f)return;const x=n||"",w=g.split("/").filter(Boolean).pop()||g;i({source:"sdk",path:g,projectDirectory:f,branch:x,label:x||w,name:w,worktreeRoot:g,worktreeStatus:"ready",headState:x?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},a=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=a):(c=r[3],a=r[4]),l.useEffect(c,a),e??o}function Mx(){return["",""]}class Ii 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 Ti="/api/walkthrough",Bu=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),Lu=()=>new Ii("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),Rx=t=>!Bu(t)&&(t.ok||t.status===404),sl=async(t,e)=>{if(Rx(t))throw Lu();const n=await t.json().catch(()=>null);throw new Ii(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})},_u=async t=>{if(!Bu(t))throw Lu();try{return await t.json()}catch{throw new Ii("The server returned a malformed walkthrough response")}};async function Ox(t,e,n={}){const r=await hs(Ti,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?_u(r):sl(r,"Failed to load walkthrough")}async function Fx(t,e,n={}){const r=await hs(`${Ti}/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?_u(r):sl(r,"Failed to generate walkthrough")}async function Bx(t,e){const n=await hs(`${Ti}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await sl(n,"Failed to cancel walkthrough generation")}async function Lx(t,e,n){const r=await hs(`${Ti}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const o=await r.json().catch(()=>null);return typeof o?.stage=="string"?o.stage:null}const ro={status:"idle",stage:null,result:null,readiness:null,error:null},_x=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,or=(t,e)=>`${Tn()}\0${t}\0${_x(e)}`,yc=t=>t instanceof Ii?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},mn=new Map,oo=new Map,$x=1e3,zx=Qr()(ku((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,o)=>{const i=or(n,r);t(c=>{const a={...c.selectedLanguage};return o?a[i]=o:delete a[i],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[or(n,r)],selectModel:(n,r,o)=>{const i=or(n,r);t(c=>{const a={...c.selectedModel};return o?a[i]=o:delete a[i],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[or(n,r)],requestSource:(n,r)=>{t(o=>({requestedSource:{...o.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const o={...r.requestedSource};return delete o[n],{requestedSource:o}})},getEntry:(n,r)=>e().entries[or(n,r)]??ro,load:async(n,r,o={})=>{if(!n)return;const i=or(n,r);if(e().entries[i]?.status==="generating")return;mn.get(i)?.abort();const a=new AbortController;mn.set(i,a),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??ro,status:"loading",error:null}}}));try{const d=await Ox(n,r,{model:e().selectedModel[i],language:o.language,signal:a.signal});if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:d.readiness??null,error:null}}})),d.generating&&e().generate(n,r,{language:o.language})}catch(d){if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??ro,status:"error",stage:null,error:yc(d)}}}))}finally{mn.get(i)===a&&mn.delete(i)}},generate:async(n,r,o={})=>{if(!n)return;const i=or(n,r);mn.get(i)?.abort();const c=new AbortController;mn.set(i,c),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??ro,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const d=oo.get(i);d!==void 0&&(clearInterval(d),oo.delete(i))};a(),oo.set(i,setInterval(()=>{Lx(n,r).then(d=>{!d||c.signal.aborted||t(u=>{const m=u.entries[i];return!m||m.status!=="generating"||m.stage===d?u:{entries:{...u.entries,[i]:{...m,stage:d}}}})}).catch(()=>{})},$x));try{const d=await Fx(n,r,{force:o.force,model:e().selectedModel[i],language:o.language,signal:c.signal});if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:u.entries[i]?.readiness??null,error:null}}}))}catch(d){if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??ro,status:"error",stage:null,error:yc(d)}}}))}finally{a(),mn.get(i)===c&&mn.delete(i)}},cancel:(n,r)=>{const o=or(n,r);Bx(n,r).catch(()=>{}),mn.get(o)?.abort(),mn.delete(o),t(i=>{const c=i.entries[o];return c?{entries:{...i.entries,[o]:{...c,status:c.result?"ready":"idle",stage:null,error:null}}}:i})},reset:()=>{for(const n of mn.values())n.abort();mn.clear();for(const n of oo.values())clearInterval(n);oo.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),Wx="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)]",Ux=3e4,wc=20,$u=(t,e)=>JSON.stringify([Tn(),t,e]),Vx=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,o]=e;return typeof n!="string"||typeof r!="string"||typeof o!="number"?null:{runtimeKey:n,directory:r,number:o}}catch{return null}},vc=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),Mo=new Map,Hx=t=>{const e=Object.entries(t);return e.length<=wc?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,wc))},Sc=Qr()((t,e)=>({entries:{},ensure:async(n,r,o,i)=>{const c=$u(r,o),a=i?.includeCheckDetails??!1,d=e().entries[c],u=d&&d.result&&Date.now()-d.fetchedAt<Ux&&(d.hasCheckDetails||!a);if(!i?.force&&u)return d.result;const m=`${c}::${a?"details":"plain"}`,g=Mo.get(`${c}::details`)??(a?null:Mo.get(m));if(g&&!i?.force)return g;const x=(async()=>{t(w=>({entries:{...w.entries,[c]:{...w.entries[c]??vc(),isLoading:!0,error:null}}}));try{const w=await n.prContext(r,o,{includeDiff:!1,includeCheckDetails:a,sourceRepo:i?.sourceRepo??null});return t(S=>({entries:Hx({...S.entries,[c]:{result:w,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),w}catch(w){const S=w instanceof Error?w.message:"Failed to load pull request context";return t(p=>({entries:{...p.entries,[c]:{...p.entries[c]??vc(),isLoading:!1,error:S}}})),null}finally{Mo.delete(m)}})();return Mo.set(m,x),x},invalidate:(n,r)=>{t(o=>{const i={};for(const[c,a]of Object.entries(o.entries)){const d=Vx(c);d&&d.directory===n&&(r==null||d.number===r)||(i[c]=a)}return{entries:i}})}})),Kx=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const i of t){if(i.status==="in_progress"){e.pending+=1,e.inProgress+=1,i.startedAt&&(!n||i.startedAt<n)&&(n=i.startedAt);continue}if(i.status==="queued"){e.pending+=1,e.queued+=1;continue}const c=typeof i.conclusion=="string"?i.conclusion.toLowerCase():"";if(!c){e.pending+=1;continue}c==="success"||c==="neutral"||c==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},Gx=35e3,Qi=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const o=e?Date.parse(e):n??Date.now();if(!Number.isFinite(o)||o<=r)return null;const i=Math.floor((o-r)/6e4);if(i<1)return"<1m";if(i<60)return`${i}m`;const c=Math.floor(i/60),a=i%60;return a>0?`${c}h ${a}m`:`${c}h`},Xi=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},jc=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"}},qx=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},Yx=[2e3,5e3],kc=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ar=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):""},Qx=(t,e)=>{const n=ar(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},Xx=(t,e)=>`${t}::${e}`,nl=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Ji=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(c=>c.name===n);if(i)return i}const r=nl(e.trackingBranch);if(r){const i=r==="origin"?t.find(a=>a.name==="upstream"):null;if(i)return i;const c=t.find(a=>a.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},Jx=t=>t.startsWith("pr-"),Zx=(t,e)=>{const n=nl(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(a=>a.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!Jx(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},io=new Map,Zi=Gr;function eb(t,e){const[n,r]=l.useState(null),[o,i]=l.useState([]),c=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.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||i(u)}catch{}}catch{}})(),()=>{a=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const tb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:a}=gt(),d=pe(q=>q.timeFormatPreference),{github:u}=tr(),m=Pr(q=>q.status),f=Pr(q=>q.hasChecked),g=pe(q=>q.setSettingsDialogOpen),x=pe(q=>q.setSettingsPage),w=pe(q=>q.setActiveMainTab),S=Ge(q=>q.currentSessionId),p=Ge(q=>!!q.newSessionDraft?.open),{isMobile:h,hasTouchInput:y,screenWidth:v}=fr(),j=pe(q=>q.openContextSurface),N=zx(q=>q.requestSource),C=!h&&v>=768&&!er(),k=l.useCallback(()=>{x("github"),g(!0)},[g,x]),D=l.useMemo(()=>Xx(t,e),[t,e]),M=l.useMemo(()=>io.get(D)??null,[D]),A=pn(q=>q.ensureEntry),_=pn(q=>q.setParams),L=pn(q=>q.startWatching),F=pn(q=>q.stopWatching),$=pn(q=>q.refresh),W=pn(q=>q.updateStatus),[U,K]=l.useState(()=>M?.title??kc(e)),[b,P]=l.useState(()=>M?.body??""),[V,G]=l.useState(()=>M?.draft??!1),[X,J]=l.useState(()=>M?.additionalContext??""),[ee,le]=l.useState(()=>{const q=typeof M?.targetBaseBranch=="string"?ar(M.targetBaseBranch):"";return q||ar(n)}),[oe,Ae]=l.useState("squash"),[Se,Y]=l.useState(!1),[je,me]=l.useState(!1),[z,Z]=l.useState(!1),[ne,fe]=l.useState(!1),[xe,Te]=l.useState(!1),[be,De]=l.useState(!1),[Ee,Re]=l.useState(null),[de,H]=l.useState(""),[Ne,he]=l.useState(""),[ve,se]=l.useState(!1),[Q,ye]=l.useState(!1),[re,R]=l.useState(()=>Ji(o,{selectedRemoteName:M?.selectedRemoteName,trackingBranch:r})),[ce,Me]=l.useState(!1),{detectedUpstream:ge,upstreamBranches:te}=eb(t,u);l.useEffect(()=>{Me(!1)},[t]);const ae=o.some(q=>q.name==="upstream"),E=!!(t&&e&&n&&(e!==n||(ae||ge!==null))),I=l.useMemo(()=>ki(t,e,re?.name??null),[t,e,re?.name]),ue=pn(q=>q.entries[I]),ke=ue?.isLoading??!1,we=ue?.status??null,qe=ue?.error??null,Je=ue?.isInitialStatusResolved??!1,st=l.useMemo(()=>{const q=ce?null:re?.name?.trim()||null,$e=new Set;for(const Pt of i){const jt=Qx(Pt,q);!jt||jt==="HEAD"||$e.add(jt)}if(ce)for(const Pt of te)Pt&&Pt!=="HEAD"&&$e.add(Pt);const Ze=ar(n);Ze&&Ze!=="HEAD"&&$e.add(Ze);const ct=ar(ee);return ct&&ct!=="HEAD"&&$e.add(ct),Array.from($e).sort((Pt,jt)=>Pt.localeCompare(jt))},[n,i,re?.name,ee,te,ce]);l.useEffect(()=>{if(o.length===0){re&&R(null);return}(!re||!o.some(q=>q.name===re.name))&&R(Ji(o,{selectedRemoteName:M?.selectedRemoteName,trackingBranch:r}))},[M?.selectedRemoteName,o,re,r]),l.useEffect(()=>{const q=ar(n);if(!ee&&q){le(q);return}if(st.length!==0&&!st.includes(ee)){const $e=st.includes(q)?q:st[0];$e&&le($e)}},[st,n,ee]);const[rt,ot]=l.useState(()=>M?.activeSegment??"overview"),[lt,kt]=l.useState(new Set),[nt,it]=l.useState(new Set),St=l.useRef(new Set),It=l.useRef(null),Ft=l.useRef(!1),Mt=l.useRef(new Set),Ot=l.useRef([]);l.useEffect(()=>{ge&&!ae&&Me(!0)},[ge,ae]),l.useEffect(()=>{ce&&ge?.defaultBranch&&le(ge.defaultBranch)},[ce,ge?.defaultBranch]);const Ke=we?.pr??null,$t=Ke?$u(t,Ke.number):null,Tt=Sc(q=>$t?q.entries[$t]:void 0),dt=Sc(q=>q.ensure),Ct=Tt?.result??null,Rt=Tt?.isLoading??!1,Qt=l.useCallback(q=>{ot(q);const $e=io.get(D);$e&&io.set(D,{...$e,activeSegment:q})},[D]);l.useEffect(()=>{!Ke||!u?.prContext||rt==="overview"||dt(u,t,Ke.number,{includeCheckDetails:rt==="checks",sourceRepo:we?.repo??null})},[rt,t,dt,u,Ke,we?.repo]);const Qe=we?.checks??null,ht=(Qe?.pending??0)>0,Xe=Ct?.checkRuns??null,_e=Ct?.fetchedAt;l.useEffect(()=>{if(!Xe||Xe.length===0)return;const q=Kx(Xe);W(I,$e=>{if(!$e?.pr||typeof _e=="number"&&typeof $e.fetchedAt=="number"&&_e<$e.fetchedAt)return $e;const Ze=$e.checks;return Ze&&Ze.state===q.state&&Ze.total===q.total&&Ze.success===q.success&&Ze.failure===q.failure&&Ze.pending===q.pending&&Ze.inProgress===q.inProgress&&Ze.queued===q.queued&&Ze.startedAt===q.startedAt?$e:{...$e,checks:q,...typeof _e=="number"?{fetchedAt:_e}:{}}})},[Xe,_e,I,W]),l.useEffect(()=>{if(rt!=="checks"||!ht||!Ke||!u?.prContext)return;const q=window.setInterval(()=>{dt(u,t,Ke.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null,force:!0})},Gx);return()=>window.clearInterval(q)},[rt,ht,t,dt,u,Ke,we?.repo]);const[yt,zt]=l.useState(()=>Date.now());l.useEffect(()=>{if(!ht)return;zt(Date.now());const q=window.setInterval(()=>zt(Date.now()),3e4);return()=>window.clearInterval(q)},[ht]);const Bt=Ke?`${t}#${Ke.number}`:null,Lt=!!(Bt&&Ee===Bt);l.useEffect(()=>{if(!u?.prContext||!Ke||typeof Ke.body=="string"&&Ke.body.length>0)return;const q=`${t}#${Ke.number}`;if(St.current.has(q))return;St.current.add(q),Re(q);let $e=!1;return dt(u,t,Ke.number,{sourceRepo:we?.repo??null}).then(Ze=>{if($e)return;const ct=Ze?.pr;ct&&W(I,Pt=>!Pt?.pr||Pt.pr.number!==Ke.number?Pt:{...Pt,pr:{...Pt.pr,body:ct.body||""}})}).catch(()=>{}).finally(()=>{$e||Re(Ze=>Ze===q?null:Ze)}),()=>{$e=!0}},[t,dt,u,Ke,I,we?.repo,W]),l.useEffect(()=>{if(!Ke){De(!1),H(""),he(""),It.current=null;return}const q=It.current!==null&&It.current!==Ke.number;q&&De(!1),(!be||q)&&(H(Ke.title||""),he(Ke.body||"")),It.current=Ke.number},[be,Ke]);const _t=l.useCallback(q=>{if(!q)return"";const $e=Date.parse(q);return Number.isFinite($e)?Gd($e,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):q},[d]),Ht=l.useMemo(()=>{const q=m?.user?.login;return typeof q=="string"?q.trim():""},[m]),Dt=l.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)]",[]),fs=l.useCallback(q=>{const $e=Ht.toLowerCase(),Ze=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return q.replace(Ze,(ct,Pt,jt)=>{const pt=`@${jt}`,is=jt.toLowerCase();return`${Pt}[${pt}](https://github.com/${is}${$e&&is===$e?"?oc-self-mention=1":""})`})},[Ht]),Kt=l.useMemo(()=>{const q=(Ct?.issueComments??[]).map(ct=>({id:`issue-${ct.id}`,body:ct.body||"",authorName:ct.author?.name||ct.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ct.author?.login||null,avatarUrl:ct.author?.avatarUrl||null,createdAt:ct.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),$e=(Ct?.reviewComments??[]).map(ct=>({id:`review-${ct.id}`,body:ct.body||"",authorName:ct.author?.name||ct.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ct.author?.login||null,avatarUrl:ct.author?.avatarUrl||null,createdAt:ct.createdAt,context:a("gitView.pr.comments.reviewContext"),path:ct.path||null,line:ct.line??null})),Ze=[...q,...$e];return Ze.sort((ct,Pt)=>{const jt=ct.createdAt?Date.parse(ct.createdAt):0,pt=Pt.createdAt?Date.parse(Pt.createdAt):0,is=Number.isFinite(jt)?jt:0,vs=Number.isFinite(pt)?pt:0;return is-vs}),Ze},[Ct,a]),Nt=l.useCallback(()=>{const q=S??(p?"draft":null);return q?{directory:t,sessionKey:q}:(Ie.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[S,t,p,a]),Zt=l.useCallback((q,$e)=>{const Ze=$e.authorLogin?`@${$e.authorLogin}`:$e.authorName,ct=$e.path?` · ${$e.path}${$e.line?`:${$e.line}`:""}`:"";go.getState().addDraft(q,{source:"pr-comment",fileLabel:`PR #${Ke?.number??""} ${Ze}${ct}`,startLine:$e.line??0,endLine:$e.line??0,code:$e.body,language:"markdown",text:""})},[Ke?.number]),ss=l.useCallback((q,$e)=>{const Ze=q.status||"unknown",ct=q.conclusion??void 0,Pt=ct?`${Ze} / ${ct}`:Ze,jt=q.app?.name||q.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:$e?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[$e?.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:jt?`${jt} · ${Pt}`:Pt})]}),q.detailsUrl?s.jsx(et,{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(T,{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((pt,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:[pt.title||pt.level||"Issue",pt.path?` · ${pt.path}`:"",typeof pt.startLine=="number"?`:${pt.startLine}`:"",typeof pt.endLine=="number"&&pt.endLine!==pt.startLine?`-${pt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:pt.message}),pt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:pt.rawDetails}):null]},`${pt.path||"file"}:${pt.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((pt,is)=>{const vs=(pt.conclusion||"").toLowerCase(),rs=vs&&!["success","neutral","skipped"].includes(vs),Is=`${q.id??"run"}:${q.job?.jobId??"job"}:${pt.number??is}:${pt.name}`,Fs=lt.has(Is);return rs?s.jsxs(ci,{open:Fs,children:[s.jsxs("button",{type:"button",onClick:()=>{kt(jn=>{const dn=new Set(jn);return dn.has(Is)?dn.delete(Is):dn.add(Is),dn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(rs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Fs?s.jsx(T,{name:"arrow-down-s",className:"size-4"}):s.jsx(T,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:pt.name}),pt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:pt.conclusion}):null]}),s.jsx(di,{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 pt.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",pt.number]}):null,pt.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",pt.status]}):null,pt.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",pt.conclusion]}):null,pt.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",_t(pt.startedAt)]}):null,pt.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",_t(pt.completedAt)]}):null]})})]},Is):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:pt.name}),pt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:pt.conclusion}):null]},Is)})})]}):null]})},[lt,_t,a]),[Oe,Ue]=l.useState(!1),[Ve,Be]=l.useState(!1),We=l.useCallback(async()=>{if(!u?.prContext){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ke)return;const q=Nt();if(q){Ue(!0);try{const $e=await dt(u,t,Ke.number,{includeCheckDetails:!0,sourceRepo:we?.repo??null});if(!$e){Ie.error(a("gitView.pr.toast.loadChecksFailed"));return}const ct=($e.checkRuns??[]).filter(jt=>Xi(jt.conclusion));if(ct.length===0){Ie.message(a("gitView.pr.toast.noFailedChecks"));return}const Pt=go.getState();for(const jt of ct){const pt=(jt.annotations??[]).map(rs=>[[rs.level,rs.title].filter(Boolean).join(" "),rs.path?`${rs.path}${typeof rs.startLine=="number"?`:${rs.startLine}`:""}`:null,rs.message,rs.rawDetails].filter(Boolean).join(`
|
|
38
|
-
`)),is=(jt.job?.steps??[]).filter(rs=>Xi(rs.conclusion)).map(rs=>`step ${rs.number??"?"}: ${rs.name} → ${rs.conclusion}`),vs=[`check: ${jt.job?.workflowName?`${jt.job.workflowName} / ${jt.name}`:jt.name}`,`status: ${jt.status??"unknown"} / ${jt.conclusion??"unknown"}`,jt.detailsUrl?`url: ${jt.detailsUrl}`:null,jt.output?.title?`title: ${jt.output.title}`:null,jt.output?.summary?`summary:
|
|
39
|
-
${jt.output.summary}`:null,is.length>0?`failed steps:
|
|
40
|
-
${is.join(`
|
|
41
|
-
`)}`:null,pt.length>0?`annotations:
|
|
42
|
-
${pt.join(`
|
|
43
|
-
---
|
|
44
|
-
`)}`:null].filter(Boolean).join(`
|
|
45
|
-
|
|
46
|
-
`);Pt.addDraft(q,{source:"pr-check",fileLabel:`PR #${Ke.number} · ${jt.name}`,startLine:0,endLine:0,code:vs,language:"text",text:""})}w("chat")}catch($e){const Ze=$e instanceof Error?$e.message:String($e);Ie.error(a("gitView.pr.toast.loadChecksFailed"),{description:Ze})}finally{Ue(!1)}}},[t,dt,u,Ke,Nt,w,we?.repo,a]),wt=l.useCallback(async()=>{if(!u?.prContext){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ke)return;const q=Nt();if(q){Be(!0);try{if(!await dt(u,t,Ke.number,{sourceRepo:we?.repo??null})){Ie.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Kt.length===0){Ie.message(a("gitView.pr.toast.noPrComments"));return}for(const Ze of Kt)Zt(q,Ze);w("chat")}catch($e){const Ze=$e instanceof Error?$e.message:String($e);Ie.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:Ze})}finally{Be(!1)}}},[Zt,t,dt,u,Ke,Nt,w,we?.repo,a,Kt]),os=l.useCallback(async q=>{const $e=Nt();$e&&(Zt($e,q),w("chat"))},[Zt,Nt,w]),xt=l.useCallback(async q=>{await $(I,q)},[I,$]),ns=l.useCallback(()=>{Ot.current.forEach(q=>{window.clearTimeout(q)}),Ot.current=Yx.map(q=>window.setTimeout(()=>{xt({force:!0,silent:!0,markInitialResolved:!0})},q))},[xt]);l.useEffect(()=>{if(!u?.prStatus||!E||o.length<=1||Ft.current||we?.pr)return;const q=`${D}::${re?.name??""}`;if(Mt.current.has(q))return;Mt.current.add(q);const $e=Zx(o,r).filter(Pt=>Pt.name!==re?.name);if($e.length===0)return;let Ze=!1;return(async()=>{for(const Pt of $e){if(Ze)return;try{if(!(await u.prStatus(t,e,Pt.name))?.pr)continue;if(Ze)return;R(pt=>pt?.name===Pt.name?pt:Pt);return}catch{}}})(),()=>{Ze=!0}},[e,E,t,u,o,re?.name,D,we?.pr,r]),l.useEffect(()=>{A(I),_(I,{directory:t,branch:e,remoteName:re?.name??null,canShow:E,github:u,githubAuthChecked:f,githubConnected:m?.connected??null})},[e,E,t,A,u,f,m?.connected,I,re?.name,_]),l.useEffect(()=>(L(I),()=>{F(I)}),[I,L,F]),l.useEffect(()=>{const q=io.get(D)??null;K(q?.title??kc(e)),P(q?.body??""),G(q?.draft??!1),le(q?.targetBaseBranch?ar(q.targetBaseBranch):ar(n));const $e=Ji(o,{selectedRemoteName:q?.selectedRemoteName,trackingBranch:r});R(Ze=>Ze?.name===$e?.name?Ze:$e)},[n,e,o,D,r]),l.useEffect(()=>{xt({markInitialResolved:!0})},[I,xt]),l.useEffect(()=>{!E||!re?.name||xt({force:!0,silent:!0,markInitialResolved:!0})},[E,xt,re?.name]),l.useEffect(()=>{const q=we?.resolvedRemoteName?.trim();if(!q||Ft.current)return;const $e=o.find(Ze=>Ze.name===q);$e&&R(Ze=>Ze?.name===$e.name?Ze:$e)},[o,we?.resolvedRemoteName]),l.useEffect(()=>{const q=we?.pr?.state==="closed"||we?.pr?.state==="merged",$e=ue?.lastRefreshAt??0,Ze=Date.now()-$e>6e4,ct=!q&&Ze,Pt=()=>{ct&&xt({force:!0,silent:!0})},jt=()=>{document.visibilityState==="visible"&&ct&&xt({force:!0,silent:!0})};return window.addEventListener("focus",Pt),document.addEventListener("visibilitychange",jt),()=>{window.removeEventListener("focus",Pt),document.removeEventListener("visibilitychange",jt)}},[xt,we?.pr?.state,ue?.lastRefreshAt]),l.useEffect(()=>{f&&m?.connected===!1&&xt({force:!0,silent:!0,markInitialResolved:!0})},[f,m,xt]),l.useEffect(()=>{!t||!e||io.set(D,{title:U,body:b,draft:V,additionalContext:X,targetBaseBranch:ee,selectedRemoteName:re?.name,activeSegment:rt})},[D,U,b,V,X,ee,re?.name,t,e,rt]),l.useEffect(()=>{const q=Ot.current;return()=>{q.forEach($e=>{window.clearTimeout($e)}),Ot.current=[]}},[]);const ds=l.useCallback(async()=>{if(!Se&&t){Y(!0);try{const $e={base:ce&&ge?.defaultBranchSha?ge.defaultBranchSha:ee,head:e};X&&($e.context=X);const Ze=await Um(t,$e);Ze.title?.trim()&&K(Ze.title.trim()),Ze.body?.trim()&&P(Ze.body.trim()),c?.()}catch(q){const $e=q instanceof Error?q.message:String(q);Ie.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:$e})}finally{Y(!1)}}},[X,e,ge?.defaultBranchSha,t,Se,c,ee,a,ce]),es=l.useCallback(async()=>{if(!u?.prCreate){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}const q=U.trim();if(!q){Ie.error(a("gitView.pr.toast.titleRequired"));return}const $e=ee.trim();if(!$e){Ie.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!ce&&$e===e){Ie.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}me(!0);try{const Ze=nl(r),ct=ce&&ge,Pt=await u.prCreate({directory:t,title:q,head:e,base:$e,...b.trim()?{body:b}:{},draft:V,...ct?{targetRepo:{owner:ge.owner,repo:ge.repo},headRemote:"origin"}:{...re?{remote:re.name}:{},...Ze&&Ze!==re?.name?{headRemote:Ze}:{}}});Ie.success(a("gitView.pr.toast.prCreated")),W(I,jt=>jt&&{...jt,pr:Pt}),await xt({force:!0}),ns()}catch(Ze){const ct=Ze instanceof Error?Ze.message:String(Ze);Ie.error(a("gitView.pr.toast.createPrFailed"),{description:ct})}finally{me(!1)}},[b,e,ge,t,V,u,I,xt,ns,re,ee,U,r,W,ce,a]),js=l.useCallback(async q=>{if(!u?.prMerge){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}fe(!0);try{const $e=await u.prMerge({directory:t,number:q.number,method:oe});$e.merged?Ie.success(a("gitView.pr.toast.prMerged")):Ie.message(a("gitView.pr.toast.prNotMerged"),{description:$e.message||a("gitView.pr.notMergeable")}),await xt({force:!0}),ns()}catch($e){const Ze=$e instanceof Error?$e.message:String($e);Ie.error(a("gitView.pr.toast.mergeFailed"),{description:Ze}),q.url&&Zi(q.url)}finally{fe(!1)}},[t,u,oe,xt,ns,a]),sn=l.useCallback(async q=>{if(!u?.prReady){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}Te(!0);try{await u.prReady({directory:t,number:q.number}),Ie.success(a("gitView.pr.toast.markedReady")),await xt({force:!0}),ns()}catch($e){const Ze=$e instanceof Error?$e.message:String($e);Ie.error(a("gitView.pr.toast.markReadyFailed"),{description:Ze}),q.url&&Zi(q.url)}finally{Te(!1)}},[t,u,xt,ns,a]),Mn=l.useCallback(async q=>{if(!u?.prUpdate){Ie.error(a("gitView.pr.toast.githubApiUnavailable"));return}const $e=de.trim();if(!$e){Ie.error(a("gitView.pr.toast.titleRequired"));return}Z(!0);try{const Ze=await u.prUpdate({directory:t,number:q.number,title:$e,body:Ne});W(I,ct=>ct&&{...ct,pr:{...ct.pr??q,...Ze}}),De(!1),Ie.success(a("gitView.pr.toast.prUpdated")),await xt({force:!0}),ns()}catch(Ze){const ct=Ze instanceof Error?Ze.message:String(Ze);Ie.error(a("gitView.pr.toast.updatePrFailed"),{description:ct})}finally{Z(!1)}},[t,Ne,de,u,I,xt,ns,W,a]);if(!E)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 $n=we?.repo?.url||null,Ds=ce&&ge?.url?ge.url:$n,nn=!!we?.canMerge,Sn=!!we?.connected,Ps=f&&we?.connected===!1,rn=qx(we),Qs=rn?`var(--pr-${rn})`:"var(--status-info)",on=rn==="draft"?"git-pr-draft":rn==="merged"?"git-merge":rn==="closed"?"git-close-pull-request":"git-pull-request",an=Ke?[`${Ke.state}${Ke.draft?" (draft)":""}`,Ke.mergeable===!1?a("gitView.pr.notMergeable"):null,Ke.state==="open"&&typeof Ke.mergeableState=="string"&&Ke.mergeableState&&Ke.mergeableState!=="unknown"?Ke.mergeableState:null].filter(Boolean).join(" · "):"",zn=Qe?Qe.total>0?`${Qe.success}/${Qe.total} ${a("gitView.pr.checks.label")}`:`${Qe.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:[Ke?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{Zi(Ke.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(T,{name:on,className:"size-4 shrink-0",style:{color:Qs}})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(T,{name:on,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")}),Ke?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Ke.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[ke?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(ut,{children:[s.jsx(ft,{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:ke,onClick:()=>{xt({force:!0})},"aria-label":a("gitView.pr.actions.refreshAria"),children:s.jsx(T,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]})]})]}),Ke?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:Qs},children:an}),Qe?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${jc(Qe.state)}`}),zn]}):null,r&&re&&r.split("/")[0]!==re.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",re.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[C?s.jsxs(et,{variant:"outline",size:"sm",className:Ce("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",Wx),onClick:()=>{N(t,{kind:"pr",number:Ke.number}),j(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(T,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,nn&&Ke.draft&&Ke.state==="open"?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>sn(Ke),disabled:xe||ne||z||be,"aria-label":a("gitView.pr.actions.markReadyAria"),children:xe?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,nn?s.jsxs(s.Fragment,{children:[s.jsxs(Vs,{value:oe,onValueChange:q=>Ae(q),disabled:ne||Ke.state!=="open",children:[s.jsx(Hs,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(As,{})}),s.jsxs(Ks,{children:[s.jsx(ls,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(ls,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(ls,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>js(Ke),disabled:ne||xe||Ke.state!=="open"||Ke.draft||z||be,"aria-label":a("gitView.pr.actions.mergePrAria"),children:ne?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"git-merge",className:"size-4"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ps?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(et,{variant:"outline",size:"sm",onClick:k,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,qe?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:qe}),Ds?s.jsx(et,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ds,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(T,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Ke&&!Je&&!qe&&!Ps?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):Ke?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(Xa,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:Qe&&Qe.total>0?`${a("gitView.pr.segment.checks")} ${Qe.success}/${Qe.total}`:a("gitView.pr.segment.checks"),icon:Qe?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${jc(Qe.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:rt,onSelect:q=>Qt(q),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),rt==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[nn&&Ke.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,nn?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:be?s.jsx(Zn,{value:de,onChange:q=>H(q.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Ke.title})}),Ke.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:be?s.jsxs(s.Fragment,{children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{De(!1),H(Ke.title||""),he(Ke.body||"")},disabled:z,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(T,{name:"close",className:"size-4"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>Mn(Ke),disabled:z||!de.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:z?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"check",className:"size-4"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>De(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(T,{name:"edit",className:"size-4"})})}),s.jsx(mt,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),be?s.jsx(_r,{value:Ne,onChange:q=>he(q.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):null,be?null:Ke.body?.trim()?s.jsx(Ol,{content:Ke.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(Lt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,rt==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[Qe&&Qe.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:[Qe.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${Qe.success/Qe.total*100}%`}}):null,Qe.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${Qe.failure/Qe.total*100}%`}}):null,Qe.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${Qe.pending/Qe.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Qe.success,"/",Qe.total," ",a("gitView.pr.checks.label")]}),(Qe.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin"}),Qi(Qe.startedAt,void 0,yt)]}):null]}):null,Qe?.failure?s.jsxs(et,{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:We,disabled:Oe,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[Oe?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{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,$e)=>{const Ze=`${q.id??"run"}:${q.name}:${$e}`,ct=q.status==="in_progress",Pt=q.status==="queued",jt=Xi(q.conclusion),pt=nt.has(Ze),is=!!(q.output?.title||q.output?.summary||q.output?.text||(q.annotations?.length??0)>0||(q.job?.steps?.length??0)>0||q.detailsUrl),vs=q.job?.workflowName,rs=ct?Qi(q.startedAt,void 0,yt):Qi(q.startedAt,q.completedAt);return s.jsxs("div",{className:Ce("rounded-md border border-border/40",jt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!is,onClick:()=>{it(Is=>{const Fs=new Set(Is);return Fs.has(Ze)?Fs.delete(Ze):Fs.add(Ze),Fs})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[ct?s.jsx(T,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):Pt?s.jsx(T,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):jt?s.jsx(T,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(T,{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:vs&&vs!==q.name?`${vs} / ${q.name}`:q.name}),rs?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:rs}):null,is?s.jsx(T,{name:"arrow-down-s",className:Ce("size-4 shrink-0 text-muted-foreground transition-transform",pt&&"rotate-180")}):null]}),pt&&is?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:ss(q,{hideHeader:!0})}):null]},Ze)})}):Rt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(T,{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,rt==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Kt.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(et,{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:wt,disabled:Ve,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Ve?s.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(T,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Kt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Kt.map((q,$e)=>{const Ze=(q.authorName||"?").charAt(0).toUpperCase(),ct=$e===Kt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[ct?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:Ze})}),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:_t(q.createdAt)}):null,s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsxs(et,{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:()=>{os(q)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(T,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(mt,{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(Ol,{content:fs(q.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Dt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},q.id)})})}):Rt&&!Ct?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(T,{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:[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)"})," → ",ee," ",s.jsxs("span",{className:"opacity-60",children:["(",ce&&ge?"upstream":"remote",")"]})]})]}),Ds?s.jsx(et,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ds,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(T,{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(Zn,{value:U,onChange:q=>K(q.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.baseBranch")}),st.length>0?s.jsxs(Vs,{value:ee,onValueChange:le,children:[s.jsx(Hs,{size:"lg",children:s.jsx(As,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Ks,{children:st.map(q=>s.jsx(ls,{value:q,children:q},q))})]}):s.jsx(Zn,{value:ee,onChange:q=>le(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(_r,{value:b,onChange:q=>P(q.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":V,onClick:()=>G(q=>!q),onKeyDown:q=>{(q.key===" "||q.key==="Enter")&&(q.preventDefault(),G($e=>!$e))},children:[s.jsx(zr,{size:"sm",checked:V,onChange:q=>G(q),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),h?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(et,{variant:"outline",size:"sm",onClick:()=>ye(!0),children:X.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),X.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:a("gitView.pr.additionalContext.added")})})]}):s.jsxs(ci,{open:ve,onOpenChange:se,children:[s.jsxs(Ja,{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:ve?a("gitView.pr.actions.hide"):X.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(di,{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(_r,{value:X,onChange:q=>J(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(Ci,{open:Q,onClose:()=>ye(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(et,{size:"sm",onClick:()=>ye(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(_r,{value:X,onChange:q=>J(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(et,{variant:"outline",size:"sm",onClick:ds,disabled:Se||je,children:[Se?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(et,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:es,disabled:je||!Sn||!ee.trim()||!ce&&ee.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:je?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},sb=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:o,defaultBranch:i,headBranch:c}=t,a=typeof c=="string"?c.trim():"",d=x=>{if(!x)return"";let w=x.trim();if(!w||w==="HEAD")return"";if(n.includes(w))return w;w.startsWith("refs/heads/")&&(w=w.slice(11)),w.startsWith("heads/")&&(w=w.slice(6)),w.startsWith("remotes/")&&(w=w.slice(8));const S=w.indexOf("/");if(S>0){const p=w.slice(0,S);if(e.has(p)){const h=w.slice(S+1).trim();h&&(w=h)}}return w},u=x=>{const w=d(typeof x=="string"?x:"");return w&&w!==a?w:""},m=u(r);if(m)return m;const f=u(o);if(f)return f;const g=u(i);return g||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},Vk=t=>{const{baseBranch:e,localBranches:n,remoteBranches:r}=t;return n.includes(e)?!0:r.some(o=>{const i=o.indexOf("/");return i>0&&o.slice(i+1)===e})},ea=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Ro=new Map,Oo=new Map,ir=t=>`${Tn()}::${t}`,nb=()=>{const t=tt.c(86),{t:e}=gt(),{git:n}=tr(),r=Yr(),o=$a(r??null),i=qd(r??null),{ensureAll:c}=dr(Qn(rb)),a=Ge(ob),d=Ge(ib),u=Ge(ab),m=Ge(lb);let f;t[0]!==r?(f=ea(r),t[0]=r,t[1]=f):f=t[1];const g=f;let x;if(t[2]!==m||t[3]!==g||t[4]!==u){e:{if(!g){x=void 0;break e}let De;if(t[6]!==m||t[7]!==g){let Re;t[9]!==g?(Re=de=>ea(de.path)===g,t[9]=g,t[10]=Re):Re=t[10],De=m.find(Re),t[6]=m,t[7]=g,t[8]=De}else De=t[8];const Ee=De;if(Ee){x=Ee;break e}for(const Re of u.values())if(ea(Re.path)===g){x=Re;break e}x=void 0}t[2]=m,t[3]=g,t[4]=u,t[5]=x}else x=t[5];const w=x;let S;t[11]!==a||t[12]!==w||t[13]!==d?.open||t[14]!==u?(S=()=>{if(a)return u.get(a)??w;if(d?.open)return w},t[11]=a,t[12]=w,t[13]=d?.open,t[14]=u,t[15]=S):S=t[15],d?.open;let p;t[16]!==S?(p=S(),t[16]=S,t[17]=p):p=t[17];const h=p;let y;t[18]!==a?(y=De=>a?De.getAttachment(a):void 0,t[18]=a,t[19]=y):y=t[19];const v=Wd(y),j=v&&!v.degraded&&!v.legacy?v.worktreeRoot??void 0:void 0,N=Ex(r,h,o?.current??void 0);let C,k;t[20]!==r||t[21]!==c||t[22]!==n?(C=()=>{!r||!n||c(r,n)},k=[r,c,n],t[20]=r,t[21]=c,t[22]=n,t[23]=C,t[24]=k):(C=t[23],k=t[24]),l.useEffect(C,k);const[D,M]=l.useState(null);let A;t[25]!==j||t[26]!==N?.projectDirectory?(A=()=>{const De=j||N?.projectDirectory;if(!De){M(null);return}let Ee=!1;return Ni(De).then(Re=>{if(Ee)return;const de=Re.trim();M(de&&de!=="HEAD"?de:null)}).catch(()=>{Ee||M(null)}),()=>{Ee=!0}},t[25]=j,t[26]=N?.projectDirectory,t[27]=A):A=t[27];const _=N?.projectDirectory;let L;t[28]!==j||t[29]!==_?(L=[j,_],t[28]=j,t[29]=_,t[30]=L):L=t[30],l.useEffect(A,L);let F;t[31]!==r?(F=()=>(r?Ro.get(ir(r)):void 0)??[],t[31]=r,t[32]=F):F=t[32];const[$,W]=l.useState(F);let U;t[33]!==r?(U=()=>(r?Oo.get(ir(r)):void 0)??null,t[33]=r,t[34]=U):U=t[34];const[K,b]=l.useState(U);let P,V;t[35]!==r||t[36]!==n?(P=()=>{if(!r||!n?.getRemotes){W([]);return}W(Ro.get(ir(r))??[]);let De=!1;return n.getRemotes(r).then(Ee=>{De||(Ro.set(ir(r),Ee??[]),W(Ee??[]))}).catch(()=>{De||W(Ro.get(ir(r))??[])}),()=>{De=!0}},V=[r,n],t[35]=r,t[36]=n,t[37]=P,t[38]=V):(P=t[37],V=t[38]),l.useEffect(P,V);let G,X;t[39]!==r||t[40]!==n?(G=()=>{if(!r||!n?.getRemoteUrl){b(null);return}b(Oo.get(ir(r))??null);let De=!1;return n.getRemoteUrl(r).then(Ee=>{De||(Oo.set(ir(r),Ee),b(Ee))}).catch(()=>{De||b(Oo.get(ir(r))??null)}),()=>{De=!0}},X=[r,n],t[39]=r,t[40]=n,t[41]=G,t[42]=X):(G=t[41],X=t[42]),l.useEffect(G,X);let J;e:{if(!i?.all){let Ee;t[43]===Symbol.for("react.memo_cache_sentinel")?(Ee=[],t[43]=Ee):Ee=t[43],J=Ee;break e}let De;t[44]!==i.all?(De=i.all.filter(cb).sort(),t[44]=i.all,t[45]=De):De=t[45],J=De}const ee=J;let le;e:{if(!i?.all){let Ee;t[46]===Symbol.for("react.memo_cache_sentinel")?(Ee=[],t[46]=Ee):Ee=t[46],le=Ee;break e}let De;t[47]!==i.all?(De=i.all.filter(db).map(ub).sort(),t[47]=i.all,t[48]=De):De=t[48],le=De}const oe=le;let Ae;t[49]!==oe||t[50]!==K||t[51]!==$||t[52]!==o?.tracking?(Ae=()=>{if($.length>0)return $;const De=new Set,Ee=o?.tracking?.trim();Ee&&Ee.includes("/")&&De.add(Ee.split("/")[0]);for(const Re of oe){const de=Re.indexOf("/");de>0&&De.add(Re.slice(0,de))}return De.size===0&&K&&De.add("origin"),Array.from(De).map(Re=>({name:Re,fetchUrl:K??"",pushUrl:K??""}))},t[49]=oe,t[50]=K,t[51]=$,t[52]=o?.tracking,t[53]=Ae):Ae=t[53],o?.tracking;let Se;t[54]!==Ae?(Se=Ae(),t[54]=Ae,t[55]=Se):Se=t[55];const Y=Se,je=o?.current??null;o?.tracking;let me;t[56]!==o?.tracking?(me=o?.tracking?.trim().split("/")[0],t[56]=o?.tracking,t[57]=me):me=t[57];const z=me,Z=(z&&i?.defaultBranches?.[z])??i?.defaultBranches?.origin;let ne;t[58]!==je||t[59]!==Z||t[60]!==Y||t[61]!==ee||t[62]!==D||t[63]!==N?.createdFromBranch?(ne=()=>sb({remoteNames:new Set(Y.map(fb)),localBranches:ee,worktreeCreatedFromBranch:N?.createdFromBranch,rootBranchHint:D,defaultBranch:Z,headBranch:je}),t[58]=je,t[59]=Z,t[60]=Y,t[61]=ee,t[62]=D,t[63]=N?.createdFromBranch,t[64]=ne):ne=t[64],N?.createdFromBranch;let fe;t[65]!==ne?(fe=ne(),t[65]=ne,t[66]=fe):fe=t[66];const xe=fe;if(!r||!je){let De;t[67]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(T,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=De):De=t[67];let Ee;t[68]!==e?(Ee=e("gitView.pullRequest.title"),t[68]=e,t[69]=Ee):Ee=t[69];let Re;t[70]!==Ee?(Re=s.jsx("div",{className:"typography-ui-header text-foreground",children:Ee}),t[70]=Ee,t[71]=Re):Re=t[71];let de;t[72]!==e?(de=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=de):de=t[73];let H;t[74]!==de?(H=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:de}),t[74]=de,t[75]=H):H=t[75];let Ne;return t[76]!==Re||t[77]!==H?(Ne=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[De,Re,H]}),t[76]=Re,t[77]=H,t[78]=Ne):Ne=t[78],Ne}const Te=o?.tracking??void 0;let be;return t[79]!==xe||t[80]!==je||t[81]!==r||t[82]!==oe||t[83]!==$||t[84]!==Te?(be=s.jsx(Xn,{as:za,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(tb,{directory:r,branch:je,baseBranch:xe,trackingBranch:Te,remotes:$,remoteBranches:oe})}),t[79]=xe,t[80]=je,t[81]=r,t[82]=oe,t[83]=$,t[84]=Te,t[85]=be):be=t[85],be};function rb(t){return{ensureAll:t.ensureAll}}function ob(t){return t.currentSessionId}function ib(t){return t.newSessionDraft}function ab(t){return t.worktreeMetadata}function lb(t){return t.availableWorktrees}function cb(t){return!t.startsWith("remotes/")}function db(t){return t.startsWith("remotes/")}function ub(t){return t.replace(/^remotes\//,"")}function fb(t){return t.name}const ka=5e3,mb=(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)=>qm(Ym.getState().dictionary,t,e),hb=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"},pb=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const o=await hs(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!o.ok){const i=await o.json().catch(()=>({error:o.statusText}));throw new Error(i.error||"Failed to read file")}return o.text()},zu=async(t,e,n)=>{if(Vm(e)||Hm(e)||Km(e))return{ok:!0};try{const r=await pb(t,e,n);return Gm(r)?{ok:!1,reason:"binary"}:mb(r,ka)>ka?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:hb(r)}}},Wu=t=>{if(t==="too-large"){const e=ka.toLocaleString(po());return Fo("contextFileOpen.failure.tooLarge",{count:e})}return Fo(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},gb=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Ss=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},Uu=(t,e)=>{const n=Ss(e),r=Ss(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},xb=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),bb=new Set(["node_modules"]),yb=t=>bb.has(t),wb=t=>{const e=Ss(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},vb=8,Fn=new Map,rl=t=>JSON.stringify([Tn(),t]),Sb=t=>{const e=rl(t),n=Fn.get(e);return n?(n.touchedAt=Date.now(),Fn.delete(e),Fn.set(e,n),n):null},ta=t=>{const e=rl(t),n=Fn.get(e);if(n)return n.touchedAt=Date.now(),n;if(Fn.size>=vb){const o=Fn.keys().next().value;o!==void 0&&Fn.delete(o)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return Fn.set(e,r),r},jb=t=>{Fn.delete(rl(t))},Vu=(t,e)=>s.jsx(Wa,{filePath:t,extension:e}),kb=t=>{const e=tt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},Cb=t=>{const e=tt.c(66),{node:n,root:r,isExpanded:o,isActive:i,isBrowserClient:c,status:a,badge:d,permissions:u,downloadFile:m,onSelect:f,onToggle:g,onRevealPath:x,onOpenDialog:w}=t,{t:S}=gt(),p=n.type==="directory",{canRename:h,canCreateFile:y,canCreateFolder:v,canDelete:j,canReveal:N}=u,C=!p&&!!m,k=N&&!c,D=h||y||v||j||C||k,[M,A]=l.useState(!1),[_,L]=l.useState(!1);let F;e[0]!==D?(F=fe=>{D&&(fe?.preventDefault(),L(!0))},e[0]=D,e[1]=F):F=e[1];const $=F;let W;e[2]!==p||e[3]!==n||e[4]!==f||e[5]!==g?(W=()=>{p?g(n.path):f(n)},e[2]=p,e[3]=n,e[4]=f,e[5]=g,e[6]=W):W=e[6];const U=W;let K;e[7]===Symbol.for("react.memo_cache_sentinel")?(K=fe=>{fe.stopPropagation(),L(!1),A(!0)},e[7]=K):K=e[7];const b=K;let P;e[8]!==y||e[9]!==v||e[10]!==j||e[11]!==h||e[12]!==k||e[13]!==m||e[14]!==c||e[15]!==p||e[16]!==n||e[17]!==w||e[18]!==x||e[19]!==S?(P=fe=>{const{Item:xe,Separator:Te}=fe;return s.jsxs(s.Fragment,{children:[h&&s.jsxs(xe,{onClick:be=>{be.stopPropagation(),w("rename",n)},children:[s.jsx(T,{name:"edit",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.rename")]}),s.jsxs(xe,{onClick:be=>{be.stopPropagation(),Bn(n.path).then(De=>{if(De.ok){Ie.success(S("sidebarFilesTree.toast.pathCopied"));return}Ie.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(T,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.copyPath")]}),!p&&m&&s.jsxs(xe,{onClick:be=>{be.stopPropagation(),m(n.path).catch(De=>{console.error("Download failed:",De),Ie.error(S("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(T,{name:"download",className:"mr-2 h-4 w-4"})," ",S(c?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),k&&s.jsxs(xe,{onClick:be=>{be.stopPropagation(),x(n.path)},children:[s.jsx(T,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",S(Fd())]}),p&&(y||v)&&s.jsxs(s.Fragment,{children:[s.jsx(Te,{}),y&&s.jsxs(xe,{onClick:be=>{be.stopPropagation(),w("createFile",n)},children:[s.jsx(T,{name:"file-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFile")]}),v&&s.jsxs(xe,{onClick:be=>{be.stopPropagation(),w("createFolder",n)},children:[s.jsx(T,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFolder")]})]}),j&&s.jsxs(s.Fragment,{children:[s.jsx(Te,{}),s.jsxs(xe,{onClick:be=>{be.stopPropagation(),w("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.delete")]})]})]})},e[8]=y,e[9]=v,e[10]=j,e[11]=h,e[12]=k,e[13]=m,e[14]=c,e[15]=p,e[16]=n,e[17]=w,e[18]=x,e[19]=S,e[20]=P):P=e[20];const V=P;let G;e[21]!==n.path||e[22]!==r?(G=fe=>{const xe=Uu(r,n.path);!xe||xe==="."||(fe.dataTransfer.setData("application/x-openchamber-file-path",xe),fe.dataTransfer.effectAllowed="copy")},e[21]=n.path,e[22]=r,e[23]=G):G=e[23];const X=G;let J;e[24]!==$?(J=s.jsx("div",{className:"group relative flex items-center",onContextMenu:$}),e[24]=$,e[25]=J):J=e[25];const ee=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let le;e[26]!==ee?(le=Ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",ee,"cursor-grab active:cursor-grabbing"),e[26]=ee,e[27]=le):le=e[27];let oe;e[28]!==p||e[29]!==o||e[30]!==n.extension||e[31]!==n.path?(oe=p?o?s.jsx(T,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Vu(n.path,n.extension),e[28]=p,e[29]=o,e[30]=n.extension,e[31]=n.path,e[32]=oe):oe=e[32];let Ae;e[33]!==n.name||e[34]!==n.path?(Ae=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[33]=n.name,e[34]=n.path,e[35]=Ae):Ae=e[35];let Se;e[36]!==p||e[37]!==a?(Se=!p&&a&&s.jsx(kb,{status:a}),e[36]=p,e[37]=a,e[38]=Se):Se=e[38];let Y;e[39]!==d||e[40]!==p?(Y=p&&d&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[d.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",d.modified]}),d.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",d.added]})]}),e[39]=d,e[40]=p,e[41]=Y):Y=e[41];let je;e[42]!==$||e[43]!==X||e[44]!==U||e[45]!==Ae||e[46]!==Se||e[47]!==Y||e[48]!==le||e[49]!==oe?(je=s.jsxs("button",{type:"button",onClick:U,onContextMenu:$,draggable:!0,onDragStart:X,className:le,children:[oe,Ae,Se,Y]}),e[42]=$,e[43]=X,e[44]=U,e[45]=Ae,e[46]=Se,e[47]=Y,e[48]=le,e[49]=oe,e[50]=je):je=e[50];let me;e[51]!==M||e[52]!==D||e[53]!==V||e[54]!==S?(me=D&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(yn,{open:M,onOpenChange:A,children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(xn,{asChild:!0,children:s.jsx(et,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:b,title:S("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":S("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(T,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(mt,{side:"bottom",sideOffset:6,children:S("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(bn,{align:"end",side:"bottom",onCloseAutoFocus:()=>A(!1),children:V({Item:qt,Separator:gn})})]})}),e[51]=M,e[52]=D,e[53]=V,e[54]=S,e[55]=me):me=e[55];let z;e[56]!==je||e[57]!==me||e[58]!==J?(z=s.jsxs(xu,{render:J,children:[je,me]}),e[56]=je,e[57]=me,e[58]=J,e[59]=z):z=e[59];let Z;e[60]!==V?(Z=s.jsx(pu,{className:"min-w-[180px]",children:V({Item:gu,Separator:Kp})}),e[60]=V,e[61]=Z):Z=e[61];let ne;return e[62]!==_||e[63]!==z||e[64]!==Z?(ne=s.jsxs(bu,{open:_,onOpenChange:L,children:[z,Z]}),e[62]=_,e[63]=z,e[64]=Z,e[65]=ne):ne=e[65],ne},Nb=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog,Ab=l.memo(Cb,Nb),Db=()=>{const{t}=gt(),{files:e,runtime:n}=tr(),r=sm(n.platform),o=Yr()??"",i=Ss(o.trim()),c=nm(),a=rm(),d=Rd(R=>R.searchFiles),u=pe(R=>R.openContextFile),m=$a(o),[f,g]=l.useState(""),x=Ua(f,200),w=l.useRef(null),[S,p]=l.useState([]),[h,y]=l.useState(!1),[v,j]=l.useState({}),[N,C]=l.useState({}),k=l.useRef(new Set),D=l.useRef(new Set),M=l.useRef(null);l.useEffect(()=>{if(!i){j({}),C({}),k.current=new Set;return}const R=Sb(i);R?(j({...R.childrenByDir}),C({...R.loadErrorsByDir}),k.current=new Set(R.loadedDirs)):(j({}),C({}),k.current=new Set)},[i]),l.useEffect(()=>{if(!i)return;const R=ta(i);R.childrenByDir=v},[i,v]),l.useEffect(()=>{if(!i)return;const R=ta(i);R.loadErrorsByDir=N},[i,N]),l.useEffect(()=>{if(!i)return;const R=ta(i);R.loadedDirs=new Set(k.current)},[i,v,N]),l.useEffect(()=>()=>{if(!i)return;const R=Fn.get(i);R&&R.loadedDirs.size===0&&Object.keys(R.childrenByDir).length===0&&jb(i)},[i]);const A=l.useMemo(()=>[],[]),_=l.useMemo(()=>[],[]),L=On(R=>i?R.byRoot[i]?.expandedPaths??A:A),F=On(R=>i?R.byRoot[i]?.selectedPath??null:null),$=On(R=>R.setSelectedPath),W=On(R=>R.addOpenPath),U=On(R=>R.removeOpenPathsByPrefix),K=On(R=>R.toggleExpandedPath),b=On(R=>R.collapseAllExpandedPaths),P=pe(R=>i?R.contextPanelByDirectory[i]?.tabs??_:_),V=l.useMemo(()=>new Set(P.map(R=>R.mode==="file"?R.targetPath:null).filter(R=>typeof R=="string"&&R.length>0).map(R=>Ss(R))),[P]),[G,X]=l.useState(null),[J,ee]=l.useState(null),[le,oe]=l.useState(""),[Ae,Se]=l.useState(!1),Y=!!e.writeFile,je=!!e.createDirectory,me=!!e.rename,z=!!e.delete,Z=!!e.revealPath,ne=l.useMemo(()=>({canRename:me,canCreateFile:Y,canCreateFolder:je,canDelete:z,canReveal:Z}),[me,Y,je,z,Z]),fe=l.useCallback(R=>{e.revealPath&&e.revealPath(R).catch(()=>{Ie.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),xe=l.useCallback((R,ce)=>{X(R),ee(ce),oe(R==="rename"&&ce.name||""),Se(!1)},[]),Te=l.useCallback((R,ce)=>{const Me=ce.filter(ge=>ge&&typeof ge.name=="string"&&ge.name.length>0).filter(ge=>c||!ge.name.startsWith(".")).filter(ge=>a||!yb(ge.name)).map(ge=>{const te=ge.name,ae=Ss(ge.path||""),ie=ae?xb(ae)?ae:Ss(`${R}/${ae}`):Ss(`${R}/${te}`),E=ge.isDirectory?"directory":"file",I=E==="file"&&te.includes(".")?te.split(".").pop()?.toLowerCase():void 0;return{name:te,path:ie,type:E,extension:I}});return gb(Me)},[a,c]),be=l.useCallback(async(R,ce)=>{const Me=Ss(R.trim());if(!Me||k.current.has(Me)||D.current.has(Me))return;D.current=new Set(D.current),D.current.add(Me);const ge=e.listDirectory?e.listDirectory(Me).then(te=>te.entries.map(ae=>({name:ae.name,path:ae.path,isDirectory:ae.isDirectory}))):en.listLocalDirectory(Me).then(te=>te.map(ae=>({name:ae.name,path:ae.path,isDirectory:ae.isDirectory})));try{const te=await ge;if(ce?.())return;const ae=Te(Me,te);k.current=new Set(k.current),k.current.add(Me),C(ie=>{if(!ie[Me])return ie;const E={...ie};return delete E[Me],E}),j(ie=>({...ie,[Me]:ae}))}catch(te){if(ce?.())return;const ae=te instanceof Error?te.message:String(te??"");console.error("Failed to load sidebar directory:",te),C(ie=>({...ie,[Me]:ae}))}finally{D.current=new Set(D.current),D.current.delete(Me)}},[e,Te]),De=l.useCallback(async()=>{if(!i)return;M.current?.abort();const R=new AbortController;M.current=R;try{const Me=(On.getState().byRoot[i]?.expandedPaths??[]).map(ae=>Ss(ae)).filter(ae=>!!ae&&ae!==i&&ae.startsWith(`${i}/`)),ge=[i,...Me];k.current=new Set(k.current);for(const ae of ge)k.current.delete(ae);C(ae=>{if(Object.keys(ae).length===0)return ae;const ie={...ae};let E=!1;for(const I of ge)I in ie&&(delete ie[I],E=!0);return E?ie:ae});const te=()=>R.signal.aborted;await be(i,te);for(let ae=0;ae<Me.length&&!R.signal.aborted;ae+=3){const ie=Me.slice(ae,ae+3);await Promise.all(ie.map(E=>be(E,te)))}}catch(ce){if(R.signal.aborted)return;console.error("Failed to refresh sidebar tree:",ce)}finally{M.current===R&&(M.current=null)}},[be,i]),Ee=l.useCallback(async R=>{if(!R){await De();return}const ce=Ss(R);k.current=new Set(k.current),k.current.delete(ce),D.current=new Set(D.current),D.current.delete(ce),await be(ce)},[be,De]);l.useEffect(()=>{i&&(M.current?.abort(),k.current=new Set,D.current=new Set,C({}),j(R=>Object.keys(R).length===0?R:{}),be(i))},[be,i,c,a]),l.useEffect(()=>{if(!i||L.length===0)return;const R=L.map(ge=>Ss(ge)).filter(ge=>!!ge&&ge!==i&&ge.startsWith(`${i}/`)&&!k.current.has(ge)&&!D.current.has(ge)).sort((ge,te)=>ge.split("/").length-te.split("/").length);if(R.length===0)return;let ce=!1;const Me=()=>ce;return(async()=>{for(let ge=0;ge<R.length&&!ce;ge+=3){const te=R.slice(ge,ge+3);await Promise.all(te.map(ae=>be(ae,Me)))}})(),()=>{ce=!0}},[L,be,i]),l.useEffect(()=>{if(!o){p([]),y(!1);return}const R=x.trim();if(!R){p([]),y(!1);return}let ce=!1;return y(!0),d(o,R,150,{includeHidden:c,respectGitignore:!a,type:"file"}).then(Me=>{if(ce)return;const te=Me.filter(ae=>a||!wb(ae.path)).map(ae=>({name:ae.name,path:Ss(ae.path),type:"file",extension:ae.extension,relativePath:ae.relativePath}));p(te)}).catch(()=>{ce||p([])}).finally(()=>{ce||y(!1)}),()=>{ce=!0}},[o,x,d,c,a]);const Re=l.useMemo(()=>{const R=new Map;if(!m?.files)return R;for(const ce of m.files)ce.index==="A"||ce.working_dir==="?"?R.set(ce.path,"git-added"):ce.index==="D"?R.set(ce.path,"git-deleted"):(ce.index==="M"||ce.working_dir==="M")&&R.set(ce.path,"git-modified");return R},[m]),de=l.useMemo(()=>{const R=new Map;if(!m?.files||!i)return R;for(const ce of m.files){const Me=ce.index==="M"||ce.working_dir==="M",ge=ce.index==="A"||ce.working_dir==="?";if(!Me&&!ge)continue;const te=ce.path.split("/");if(te.length<=1)continue;let ae=i;for(let ie=0;ie<te.length-1;ie++){ae=`${ae}/${te[ie]}`;let E=R.get(ae);E||(E={modified:0,added:0},R.set(ae,E)),Me&&E.modified++,ge&&E.added++}}return R},[m,i]),H=l.useCallback(R=>{if(V.has(R))return"open";if(Re.size===0)return null;const ce=R.startsWith(i+"/")?R.slice(i.length+1):R;return Re.get(ce)??null},[V,Re,i]),Ne=l.useCallback(R=>{if(de.size===0)return null;const ce=de.get(R);return ce&&ce.modified+ce.added>0?ce:null},[de]),he=l.useCallback(async R=>{if(!i)return;const ce=await zu(e,R.path,{directory:i});if(!ce.ok){Ie.error(Wu(ce.reason));return}$(i,R.path),W(i,R.path),u(i,R.path)},[W,e,u,i,$]),ve=l.useCallback(async R=>{const ce=Ss(R);i&&(K(i,ce),k.current.has(ce)||await be(ce))},[be,i,K]),se=l.useCallback(async R=>{if(R?.preventDefault(),!J||!G)return;Se(!0);const ce=()=>Se(!1),Me=()=>X(null);if(G==="createFile"){if(!le.trim()){Ie.error(t("sidebarFilesTree.toast.filenameRequired")),ce();return}if(!e.writeFile){Ie.error(t("sidebarFilesTree.toast.writeNotSupported")),ce();return}const ge=J.path,te=ge?`${ge}/`:"",ae=Ss(`${te}${le.trim()}`);await e.writeFile(ae,"").then(async ie=>{ie.success&&(Ie.success(t("sidebarFilesTree.toast.fileCreated")),await Ee(ge)),Me()}).catch(()=>Ie.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ce);return}if(G==="createFolder"){if(!le.trim()){Ie.error(t("sidebarFilesTree.toast.folderNameRequired")),ce();return}const ge=J.path,te=ge?`${ge}/`:"",ae=Ss(`${te}${le.trim()}`);await e.createDirectory(ae).then(async ie=>{ie.success&&(Ie.success(t("sidebarFilesTree.toast.folderCreated")),await Ee(ge)),Me()}).catch(()=>Ie.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ce);return}if(G==="rename"){if(!le.trim()){Ie.error(t("sidebarFilesTree.toast.nameRequired")),ce();return}if(!e.rename){Ie.error(t("sidebarFilesTree.toast.renameNotSupported")),ce();return}const ge=J.path,te=ge.split("/").slice(0,-1).join("/"),ae=te?`${te}/`:"",ie=Ss(`${ae}${le.trim()}`);await e.rename(ge,ie).then(async E=>{E.success&&(Ie.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Ee(te),i&&U(i,ge),(F===ge||F&&F.startsWith(`${ge}/`))&&$(i,null)),Me()}).catch(()=>Ie.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ce);return}if(G==="delete"){if(!e.delete){Ie.error(t("sidebarFilesTree.toast.deleteNotSupported")),ce();return}const ge=J.path,te=ge.split("/").slice(0,-1).join("/");await e.delete(ge).then(async ae=>{ae.success&&(Ie.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Ee(te),i&&U(i,ge),(F===ge||F&&F.startsWith(ge+"/"))&&$(i,null)),Me()}).catch(()=>Ie.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ce);return}ce()},[G,J,le,e,Ee,U,i,F,$,t]);function Q(R,ce){const Me=v[R]??[];return Me.map((ge,te)=>{const ae=ge.type==="directory",ie=ae&&L.includes(ge.path),E=F===ge.path,I=te===Me.length-1;return s.jsxs("li",{className:"relative",children:[ce>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),I&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Ab,{node:ge,root:i,isExpanded:ie,isActive:E,isBrowserClient:r,status:ae?void 0:H(ge.path),badge:ae?Ne(ge.path):void 0,permissions:ne,downloadFile:e.downloadFile,onSelect:he,onToggle:ve,onRevealPath:fe,onOpenDialog:xe}),ae&&ie&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[N[ge.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:N[ge.path],children:N[ge.path]}),s.jsxs(et,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ee(ge.path)},children:[s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,Q(ge.path,ce+1)]})]},ge.path)})}const ye=!!(i&&v[i]),re=i?N[i]:null;return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Y&&s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(et,{variant:"ghost",size:"sm",onClick:()=>xe("createFile",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(T,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(mt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),je&&s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(et,{variant:"ghost",size:"sm",onClick:()=>xe("createFolder",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(T,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(mt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(et,{variant:"ghost",size:"sm",onClick:()=>{De()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(T,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(mt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(et,{variant:"ghost",size:"sm",onClick:()=>{i&&b(i)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(T,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(mt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(T,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Zn,{ref:w,value:f,onChange:R=>g(R.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{g(""),w.current?.focus()},children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsx(Xn,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:h?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):S.length>0?S.map(R=>{const ce=F===R.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>he(R),draggable:!0,onDragStart:Me=>{const ge=R.relativePath||Uu(i??"",R.path);!ge||ge==="."||(Me.dataTransfer.setData("application/x-openchamber-file-path",ge),Me.dataTransfer.effectAllowed="copy")},className:Ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",ce?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:R.path,children:[Vu(R.path,R.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:R.relativePath??R.path})]})},R.path)}):re?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:re}),s.jsxs(et,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{De()},children:[s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ye&&i?Q(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),s.jsx(qs,{open:!!G,onOpenChange:R=>!R&&X(null),children:s.jsxs(Ys,{children:[s.jsxs(En,{children:[s.jsxs(wn,{children:[G==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),G==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),G==="rename"&&t("sidebarFilesTree.dialog.rename.title"),G==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(vn,{children:[G==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:J?.path??t("sidebarFilesTree.dialog.rootFallback")}),G==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:J?.path??t("sidebarFilesTree.dialog.rootFallback")}),G==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:J?.name??""}),G==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:J?.name??""})]})]}),G!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Zn,{value:le,onChange:R=>oe(R.target.value),placeholder:t(G==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:R=>{R.key==="Enter"&&se()},autoFocus:!0})}),s.jsxs(mr,{children:[s.jsx(et,{variant:"outline",onClick:()=>X(null),disabled:Ae,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(et,{variant:G==="delete"?"destructive":"default",onClick:()=>{se()},disabled:Ae||G!=="delete"&&!le.trim(),children:Ae?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t(G==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},ol=t=>t,Ca=t=>{const e=ol(t).type;return typeof e=="string"?e:""},Pb=t=>{const e=ol(t).tool;return typeof e=="string"?e:""},Ib=t=>{const e=ol(t).text;return typeof e=="string"?e:""},Tb=t=>{const e=Ca(t);return e==="tool"?Pb(t).trim().toLowerCase()||"tool":e||"unknown"},Eb=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Tb(n);e.includes(r)||e.push(r)}return e.join(" + ")},Mb=t=>t.replace(/\s+/g," ").trim(),Rb=t=>{for(const n of t)if(Ca(n)==="text"){const r=Mb(Ib(n));if(r.length===0)continue;return r}const e=t.filter(n=>Ca(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},Ob=(t,e,n)=>`${n(t)} / ${n(e)}`,Fb=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Bb=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=Fb(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}})},Na={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Yo={user:0,assistant:0,tool:0,other:0},kr=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,sa=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(u=>u.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Na,total:kr(n)};if(!n||typeof n!="object")return Na;const r=n,o=kr(r.input),i=kr(r.output),c=kr(r.reasoning),a=kr(r.cache?.read),d=kr(r.cache?.write);return{input:o,output:i,reasoning:c,cacheRead:a,cacheWrite:d,total:o+i+c+a+d}},Lb=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},Zs=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+Zs(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+Zs(n),0):0,_b=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Yo,assistant:Zs(n.text)+Zs(n.content)};const o=Lb(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:Zs(n.input)+Zs(n.output)+Zs(n.error)+Zs(n.call?.input)+Zs(n.call?.output)+Zs(n.call?.error)+Zs(n.raw)+Math.round(Zs(n.metadata)*.25)+Math.round(Zs(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Cc=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),$b=t=>{const e=So(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},zb=(t,e)=>{if(t.length===0)return{...Yo};const n=t.reduce((r,o)=>{const i=$b(o);let c={...Yo};for(const a of o.parts)c=Cc(c,_b(a,i));return Cc(r,c)},{...Yo});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)}},Cr=t=>t.toLocaleString(po()),Wb=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat(po(),{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(po(),{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),Ub=(t,e)=>!t||!Number.isFinite(t)?"-":Gd(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Vb=(t,e,n)=>{const r=t.find(i=>i.id===e),o=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Hb=()=>{const t=tt.c(203),{t:e}=gt(),n=pe(Kb);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,i]=l.useState(r),[c,a]=l.useState(null),d=l.useRef(null),u=Ge(Gb),m=Ge(qb),f=Yd(m??void 0),g=Qm(u??"",m??void 0),x=Vt(Yb);let w;t[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),i(Qb),a(null)},t[1]=w):w=t[1];let S;t[2]!==m||t[3]!==u?(S=[m,u],t[2]=m,t[3]=u,t[4]=S):S=t[4],l.useEffect(w,S);let p,h;t[5]===Symbol.for("react.memo_cache_sentinel")?(p=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},h=[],t[5]=p,t[6]=h):(p=t[5],h=t[6]),l.useEffect(p,h);let y;t[7]===Symbol.for("react.memo_cache_sentinel")?(y=async(Qe,ht)=>{(await Bn(ht)).ok?(a(Qe),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{a(_e=>_e===Qe?null:_e),d.current=null},2e3)):a(null)},t[7]=y):y=t[7];const v=y;let j;t[8]!==u||t[9]!==f?(j=u?f.find(Qe=>Qe.id===u)??null:null,t[8]=u,t[9]=f,t[10]=j):j=t[10];const N=j;let C,k,D,M,A,_;if(t[11]!==x||t[12]!==g){C=g.filter(Xb);let Qe;t[19]!==g?(Qe=g.filter(Jb),t[19]=g,t[20]=Qe):Qe=t[20],_=Qe;let ht=null;for(let _e=C.length-1;_e>=0;_e=_e-1,_e){const yt=C[_e];if(sa(yt).total>0){ht=yt;break}}M=ht?sa(ht):Na,k=Xm({input:M.input,cache:{read:M.cacheRead,write:M.cacheWrite}}),A=C.reduce(Zb,0);const Xe=ht?.info??null;D=Vb(x,Xe?.providerID||"",Xe?.modelID||""),t[11]=x,t[12]=g,t[13]=C,t[14]=k,t[15]=D,t[16]=M,t[17]=A,t[18]=_}else C=t[13],k=t[14],D=t[15],M=t[16],A=t[17],_=t[18];const L=D,F=L.contextLimit,$=F&&F>0?Math.min(999,M.total/F*100):0;let W;if(t[21]!==g){const Qe=[...g].reverse().find(ey)?.info?.system||"";W=zb(g,Qe),t[21]=g,t[22]=W}else W=t[22];const U=W,K=U.user,b=U.assistant,P=U.tool,V=Math.max(0,M.input-K-b-P),G=K+b+P+V,X=g[0]?.info?.time?.created,J=g.length>0?g[g.length-1]?.info?.time?.created:null;let ee;t[23]!==N?.title||t[24]!==e?(ee=N?.title||e("contextSidebar.session.untitled"),t[23]=N?.title,t[24]=e,t[25]=ee):ee=t[25];const le=N?.time?.created??X??null,oe=J??N?.time?.created??null;let Ae;t[26]!==b||t[27]!==V||t[28]!==P||t[29]!==K?(Ae={user:K,assistant:b,tool:P,other:V},t[26]=b,t[27]=V,t[28]=P,t[29]=K,t[30]=Ae):Ae=t[30];let Se;t[31]!==C.length||t[32]!==G||t[33]!==k||t[34]!==F||t[35]!==L||t[36]!==g.length||t[37]!==le||t[38]!==oe||t[39]!==Ae||t[40]!==ee||t[41]!==M||t[42]!==A||t[43]!==$||t[44]!==_.length?(Se={sessionTitle:ee,messagesCount:g.length,userMessagesCount:_.length,assistantMessagesCount:C.length,createdAt:le,lastActivityAt:oe,providerModel:L,tokenBreakdown:M,usagePercent:$,cacheHitRate:k,totalAssistantCost:A,contextLimit:F,breakdown:Ae,breakdownTotal:G},t[31]=C.length,t[32]=G,t[33]=k,t[34]=F,t[35]=L,t[36]=g.length,t[37]=le,t[38]=oe,t[39]=Ae,t[40]=ee,t[41]=M,t[42]=A,t[43]=$,t[44]=_.length,t[45]=Se):Se=t[45];const Y=Se;if(!u){let Qe;t[46]!==e?(Qe=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=Qe):Qe=t[47];let ht;return t[48]!==Qe?(ht=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:Qe}),t[48]=Qe,t[49]=ht):ht=t[49],ht}let je;t[50]!==e?(je=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=je):je=t[51];let me;t[52]!==je||t[53]!==Y.breakdown.user?(me={key:"user",label:je,value:Y.breakdown.user,color:"var(--status-success)"},t[52]=je,t[53]=Y.breakdown.user,t[54]=me):me=t[54];let z;t[55]!==e?(z=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=z):z=t[56];let Z;t[57]!==z||t[58]!==Y.breakdown.assistant?(Z={key:"assistant",label:z,value:Y.breakdown.assistant,color:"var(--primary-base)"},t[57]=z,t[58]=Y.breakdown.assistant,t[59]=Z):Z=t[59];let ne;t[60]!==e?(ne=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ne):ne=t[61];let fe;t[62]!==ne||t[63]!==Y.breakdown.tool?(fe={key:"tool",label:ne,value:Y.breakdown.tool,color:"var(--status-warning)"},t[62]=ne,t[63]=Y.breakdown.tool,t[64]=fe):fe=t[64];let xe;t[65]!==e?(xe=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=xe):xe=t[66];let Te;t[67]!==xe||t[68]!==Y.breakdown.other?(Te={key:"other",label:xe,value:Y.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=xe,t[68]=Y.breakdown.other,t[69]=Te):Te=t[69];let be;t[70]!==me||t[71]!==Z||t[72]!==fe||t[73]!==Te?(be=[me,Z,fe,Te],t[70]=me,t[71]=Z,t[72]=fe,t[73]=Te,t[74]=be):be=t[74];const De=be;let Ee;t[75]!==Y.sessionTitle?(Ee=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Y.sessionTitle}),t[75]=Y.sessionTitle,t[76]=Ee):Ee=t[76];let Re;t[77]!==Y.providerModel.modelName||t[78]!==Y.providerModel.providerName?(Re=s.jsxs("span",{children:[Y.providerModel.providerName," / ",Y.providerModel.modelName]}),t[77]=Y.providerModel.modelName,t[78]=Y.providerModel.providerName,t[79]=Re):Re=t[79];let de;t[80]!==n||t[81]!==Y.createdAt?(de=Y.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:Ub(Y.createdAt,n)})]}),t[80]=n,t[81]=Y.createdAt,t[82]=de):de=t[82];let H;t[83]!==Re||t[84]!==de?(H=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:[Re,de]}),t[83]=Re,t[84]=de,t[85]=H):H=t[85];let Ne;t[86]!==Ee||t[87]!==H?(Ne=s.jsxs("div",{className:"mb-6",children:[Ee,H]}),t[86]=Ee,t[87]=H,t[88]=Ne):Ne=t[88];let he;t[89]!==e?(he=e("contextSidebar.section.context"),t[89]=e,t[90]=he):he=t[90];let ve;t[91]!==he?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:he}),t[91]=he,t[92]=ve):ve=t[92];let se;t[93]!==Y.tokenBreakdown.total?(se=Cr(Y.tokenBreakdown.total),t[93]=Y.tokenBreakdown.total,t[94]=se):se=t[94];let Q;t[95]!==Y.contextLimit?(Q=Y.contextLimit?` / ${Cr(Y.contextLimit)}`:"",t[95]=Y.contextLimit,t[96]=Q):Q=t[96];let ye;t[97]!==se||t[98]!==Q?(ye=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[se,Q]}),t[97]=se,t[98]=Q,t[99]=ye):ye=t[99];let re;t[100]!==ve||t[101]!==ye?(re=s.jsxs("div",{className:"flex items-baseline justify-between",children:[ve,ye]}),t[100]=ve,t[101]=ye,t[102]=re):re=t[102];let R;t[103]!==Y.usagePercent?(R=Y.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,Y.usagePercent)}%`,backgroundColor:Y.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=Y.usagePercent,t[104]=R):R=t[104];let ce;t[105]!==R?(ce=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:R}),t[105]=R,t[106]=ce):ce=t[106];let Me;t[107]!==e||t[108]!==Y.usagePercent?(Me=e("contextSidebar.context.percentUsed",{percent:Y.usagePercent.toFixed(1)}),t[107]=e,t[108]=Y.usagePercent,t[109]=Me):Me=t[109];let ge;t[110]!==Me?(ge=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Me}),t[110]=Me,t[111]=ge):ge=t[111];let te;t[112]!==re||t[113]!==ce||t[114]!==ge?(te=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[re,ce,ge]}),t[112]=re,t[113]=ce,t[114]=ge,t[115]=te):te=t[115];let ae;t[116]!==e?(ae=e("contextSidebar.stats.messages"),t[116]=e,t[117]=ae):ae=t[117];let ie;t[118]!==Y.messagesCount?(ie=Cr(Y.messagesCount),t[118]=Y.messagesCount,t[119]=ie):ie=t[119];let E;t[120]!==ae||t[121]!==ie?(E={label:ae,value:ie},t[120]=ae,t[121]=ie,t[122]=E):E=t[122];let I;t[123]!==e?(I=e("contextSidebar.stats.user"),t[123]=e,t[124]=I):I=t[124];let ue;t[125]!==Y.userMessagesCount?(ue=Cr(Y.userMessagesCount),t[125]=Y.userMessagesCount,t[126]=ue):ue=t[126];let ke;t[127]!==I||t[128]!==ue?(ke={label:I,value:ue},t[127]=I,t[128]=ue,t[129]=ke):ke=t[129];let we;t[130]!==e?(we=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=we):we=t[131];let qe;t[132]!==Y.assistantMessagesCount?(qe=Cr(Y.assistantMessagesCount),t[132]=Y.assistantMessagesCount,t[133]=qe):qe=t[133];let Je;t[134]!==we||t[135]!==qe?(Je={label:we,value:qe},t[134]=we,t[135]=qe,t[136]=Je):Je=t[136];let st;t[137]!==e?(st=e("contextSidebar.stats.cost"),t[137]=e,t[138]=st):st=t[138];let rt;t[139]!==Y.totalAssistantCost?(rt=Wb(Y.totalAssistantCost),t[139]=Y.totalAssistantCost,t[140]=rt):rt=t[140];let ot;t[141]!==st||t[142]!==rt?(ot={label:st,value:rt},t[141]=st,t[142]=rt,t[143]=ot):ot=t[143];let lt;t[144]!==E||t[145]!==ke||t[146]!==Je||t[147]!==ot?(lt=[E,ke,Je,ot],t[144]=E,t[145]=ke,t[146]=Je,t[147]=ot,t[148]=lt):lt=t[148];const kt=lt;let nt;t[149]!==kt?(nt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:kt.map(ty)}),t[149]=kt,t[150]=nt):nt=t[150];let it;t[151]!==e?(it=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=it):it=t[152];let St;t[153]!==it?(St=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:it}),t[153]=it,t[154]=St):St=t[154];let It;t[155]!==e||t[156]!==Y.cacheHitRate.hasInput||t[157]!==Y.cacheHitRate.percent||t[158]!==Y.tokenBreakdown.cacheRead||t[159]!==Y.tokenBreakdown.cacheWrite||t[160]!==Y.tokenBreakdown.input||t[161]!==Y.tokenBreakdown.output||t[162]!==Y.tokenBreakdown.reasoning?(It=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:Y.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:Y.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:Y.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:Y.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:Y.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:Y.cacheHitRate.hasInput?Y.cacheHitRate.percent:null,format:"percent"}].map(sy)}),t[155]=e,t[156]=Y.cacheHitRate.hasInput,t[157]=Y.cacheHitRate.percent,t[158]=Y.tokenBreakdown.cacheRead,t[159]=Y.tokenBreakdown.cacheWrite,t[160]=Y.tokenBreakdown.input,t[161]=Y.tokenBreakdown.output,t[162]=Y.tokenBreakdown.reasoning,t[163]=It):It=t[163];let Ft;t[164]!==St||t[165]!==It?(Ft=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[St,It]}),t[164]=St,t[165]=It,t[166]=Ft):Ft=t[166];let Mt;t[167]!==De||t[168]!==Y.breakdownTotal?(Mt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:De.map(Qe=>Qe.value<=0||Y.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${Qe.value/Y.breakdownTotal*100}%`,backgroundColor:Qe.color}},Qe.key))}),t[167]=De,t[168]=Y.breakdownTotal,t[169]=Mt):Mt=t[169];let Ot;t[170]!==De||t[171]!==Y.breakdownTotal?(Ot=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:De.map(Qe=>{const ht=Y.breakdownTotal>0?Qe.value/Y.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:Qe.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[Qe.label," ",s.jsxs("span",{className:"tabular-nums",children:[ht.toFixed(0),"%"]})]})]},Qe.key)})}),t[170]=De,t[171]=Y.breakdownTotal,t[172]=Ot):Ot=t[172];let Ke;t[173]!==Mt||t[174]!==Ot?(Ke=s.jsxs("div",{className:"mb-6",children:[Mt,Ot]}),t[173]=Mt,t[174]=Ot,t[175]=Ke):Ke=t[175];let $t;t[176]!==e?($t=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=$t):$t=t[177];let Tt;t[178]!==$t?(Tt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:$t}),t[178]=$t,t[179]=Tt):Tt=t[179];let dt;if(t[180]!==c||t[181]!==o||t[182]!==g||t[183]!==e||t[184]!==n){let Qe;t[186]!==c||t[187]!==o||t[188]!==e||t[189]!==n?(Qe=ht=>{const _e=So(ht.info).role,yt=_e==="assistant",zt=_e==="user",Bt=o[ht.info.id]===!0,Lt=c===ht.info.id,_t=ht.info.time?.created??null,Ht=Eb(ht.parts),Dt=yt?sa({info:ht.info,parts:ht.parts}):null,fs=zt?Rb(ht.parts):"",Kt=Bb(_t,n),Nt=Ht||"—",Zt=Dt?Ob(Dt.input,Dt.output,Cr):"",ss=_e||"unknown",Oe=Ht?`${ss}: ${Ht}`:ss,Ue=Bt?JSON.stringify({info:ht.info,parts:ht.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":Bt,onClick:()=>{i(Ve=>({...Ve,[ht.info.id]:Ve[ht.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:yt?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[zt?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",fs]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:yt?Nt:Oe}),yt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Zt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Kt})]})}),Bt&&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:Ve=>{Ve.stopPropagation(),v(ht.info.id,Ue)},"aria-label":e(Lt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Lt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Lt?s.jsx(T,{name:"check",className:"size-3.5"}):s.jsx(T,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Jm,{language:"json",code:Ue,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},ht.info.id)},t[186]=c,t[187]=o,t[188]=e,t[189]=n,t[190]=Qe):Qe=t[190],dt=[...g].reverse().map(Qe),t[180]=c,t[181]=o,t[182]=g,t[183]=e,t[184]=n,t[185]=dt}else dt=t[185];let Ct;t[191]!==dt?(Ct=s.jsx("div",{className:"mt-2.5 space-y-1",children:dt}),t[191]=dt,t[192]=Ct):Ct=t[192];let Rt;t[193]!==Tt||t[194]!==Ct?(Rt=s.jsxs("div",{children:[Tt,Ct]}),t[193]=Tt,t[194]=Ct,t[195]=Rt):Rt=t[195];let Qt;return t[196]!==Ne||t[197]!==te||t[198]!==nt||t[199]!==Ft||t[200]!==Ke||t[201]!==Rt?(Qt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ne,te,nt,Ft,Ke,Rt]})}),t[196]=Ne,t[197]=te,t[198]=nt,t[199]=Ft,t[200]=Ke,t[201]=Rt,t[202]=Qt):Qt=t[202],Qt};function Kb(t){return t.timeFormatPreference}function Gb(t){return t.currentSessionId}function qb(t){return t.currentSessionDirectory}function Yb(t){return t.providers}function Qb(t){return Object.keys(t).length>0?{}:t}function Xb(t){return So(t.info).role==="assistant"}function Jb(t){return So(t.info).isUser}function Zb(t,e){const n=kr(e.info.cost);return t+n}function ey(t){return So(t.info).isUser&&typeof t.info.system=="string"}function ty(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 sy(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)}%`:Cr(t.value):"—"})]},t.label)}const ny="x-openchamber-preview-target-error",ry=t=>{const e=t.get(ny);return e==="missing"||e==="expired"||e==="invalid-token"?e:null},oy=(t,e)=>ry(t)?e?"stop-retrying":"retry-registration":"none",iy=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},Nc=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),Ur=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&iy(e.center)&&Nc(e.attributes)&&Nc(e.computedStyle)&&Array.isArray(e.ancestry)},il=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:i})=>{const c=r.text.trim(),a=Object.entries(r.attributes).map(([x,w])=>`${x}="${w}"`).join(" "),d=r.computedStyle,u=r.bounds,m=r.center,f=i.replace(/[.:]+$/g,""),g=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,g?`- Ancestry: ${g}`:null,a?`- Attributes: ${a}`:null,`- Bounds: x=${Math.round(u.x)}, y=${Math.round(u.y)}, width=${Math.round(u.width)}, height=${Math.round(u.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(x=>typeof x=="string").join(`
|
|
47
|
-
`)},Hu=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await Jn("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((w,S)=>{o.onload=()=>w(),o.onerror=()=>S(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const i=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),d=Math.min(1,1200/i),u=document.createElement("canvas");u.width=Math.floor(i*d),u.height=Math.floor(c*d);const m=u.getContext("2d");if(!m)return null;m.scale(d,d),m.drawImage(o,0,0,i,c);const f=i/Math.max(1,n.width),g=c/Math.max(1,n.height);m.fillStyle="rgba(37, 99, 235, 0.28)",m.strokeStyle="rgb(37, 99, 235)",m.lineWidth=Math.max(2,2*f),m.fillRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g),m.strokeRect(e.bounds.x*f,e.bounds.y*g,e.bounds.width*f,e.bounds.height*g);const x=await new Promise(w=>u.toBlob(w,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await vy(t,e)},al=async(t,e,n,r,o,i)=>{if(!t)return null;try{const c=new Image;await new Promise((p,h)=>{c.onload=()=>p(),c.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const a=Math.max(1,c.naturalWidth||e),d=Math.max(1,c.naturalHeight||n),m=Math.min(1,1200/a),f=document.createElement("canvas");f.width=Math.floor(a*m),f.height=Math.floor(d*m);const g=f.getContext("2d");if(!g)return null;g.scale(m,m),g.drawImage(c,0,0,a,d);const x=a/Math.max(1,r||a),w=d/Math.max(1,o||d);g.fillStyle="rgba(37, 99, 235, 0.14)",g.strokeStyle="rgb(37, 99, 235)",g.lineWidth=Math.max(2,2*x),g.fillRect(i.bounds.x*x,i.bounds.y*w,i.bounds.width*x,i.bounds.height*w),g.strokeRect(i.bounds.x*x,i.bounds.y*w,i.bounds.width*x,i.bounds.height*w);const S=await new Promise(p=>f.toBlob(p,"image/jpeg",.82));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Vr="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",Us=new Map,na=new Map,ay=3e4,ll=t=>{const e=Us.get(t);return e?e.expiresAt-Date.now()<=ay?(Us.delete(t),null):e:null},ly=t=>{try{return new URL(t).origin}catch{return t}};function Ku(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const Gu=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Vr),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),cy=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await Gu(n)).split(",",2)[1]||""},dy=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Qo=(...t)=>{dy()&&console.info("[preview-capture]",...t)},qu=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const i=o.scrollTop||0,c=o.scrollLeft||0;if(i<=0&&c<=0)continue;const a=o.tagName.toLowerCase(),d=o.id?`#${o.id}`:"",u=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${a}${d}${u}`,scrollTop:i,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},fo="data-oc-fixed-pin",uy=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],i=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const a=c.getBoundingClientRect();if(!(a.width>0&&a.height>0))continue;c.setAttribute(fo,JSON.stringify({top:a.top+n,left:a.left+e,width:a.width,height:a.height})),o.push(c);const d=c.tagName.toLowerCase(),u=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";i.push({selector:`${d}${u}`,top:Math.round(a.top),left:Math.round(a.left),width:Math.round(a.width),height:Math.round(a.height)})}}catch{}return Qo("tagged fixed elements",i),()=>{for(const c of o)try{c.removeAttribute(fo)}catch{}}},fy={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${fo}]`)){let r;try{r=JSON.parse(n.getAttribute(fo)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(fo)}}},$r="data-oc-scroll-pin",my=t=>{const e=[],n=qu(t,64);try{const i=t.documentElement,c=t.body;for(const a of t.querySelectorAll("*")){const d=a.scrollTop||0,u=a.scrollLeft||0;if(d<=0&&u<=0)continue;const m=a!==i&&a!==c;m&&a.setAttribute($r,JSON.stringify({top:d,left:u})),e.push({el:a,top:d,left:u,tagged:m})}}catch{}return{reapply:()=>{for(const i of e)try{i.el.scrollHeight,i.el.scrollTop!==i.top&&(i.el.scrollTop=i.top),i.el.scrollLeft!==i.left&&(i.el.scrollLeft=i.left)}catch{}},cleanup:()=>{for(const i of e)if(i.tagged)try{i.el.removeAttribute($r)}catch{}},snapshot:n}},hy={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${$r}]`)){let o;try{o=JSON.parse(r.getAttribute($r)||"")}catch{r.removeAttribute($r);continue}const i=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=i;else{r.style.overflow="hidden";const a=n.createElement("div");for(a.style.transform=i,a.style.willChange="transform",a.style.display="inline-block",a.style.width="100%";r.firstChild;)a.appendChild(r.firstChild);r.appendChild(a)}r.removeAttribute($r)}}},ra=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await Gu(await n.blob()):null}catch{return null}},py=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=ll(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=na.get(e),o=r??(async()=>{try{const c=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return Us.delete(e),null;const a=await c.json(),d=typeof a.proxyBasePath=="string"?a.proxyBasePath:"",u=typeof a.expiresAt=="number"?a.expiresAt:0;if(!d)return Us.delete(e),null;const m={proxyBasePath:d,expiresAt:u};return Us.set(e,m),m}catch{return Us.delete(e),null}finally{na.delete(e)}})();r||na.set(e,o);const i=await o;return i?`${i.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Yu=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await ra(n.toString(),"include")??Vr;const r=await py(n),o=r?await ra(r,"include"):null;return o||(await ra(n.toString(),"omit")??Vr)}catch{return Vr}},gy=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const i=o[2]||"";if(!i||i.startsWith("data:"))continue;const c=await Yu(i,e);r=r.replace(o[0],`url("${c}")`)}return r},Ac=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),Qu=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},xy=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},by=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const a of c){const d=a.textContent?.replace(/\s+/g," ").trim()??"";if(!d||!d.includes(" "))continue;const u=a.getBoundingClientRect();if(u.width<=0||u.height<=0||u.right<0||u.bottom<0||u.left>e||u.top>n)continue;const m=o.getComputedStyle(a);if(m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)continue;const f=m.getPropertyValue("text-wrap"),g=m.getPropertyValue("text-wrap-mode"),x=m.whiteSpace.includes("nowrap")||f==="nowrap"||g==="nowrap",w=u.height<=xy(m)*1.7;!x&&(!w||u.width>e*.72)||(r.push(Qu(a)),a.style.whiteSpace="nowrap",a.style.overflowWrap="normal",a.style.wordBreak="normal",a.style.setProperty("text-wrap","nowrap"),a.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let a=r.length-1;a>=0;a-=1)r[a]?.()}},yy=(t,e,n,r)=>{const o=[],i=t.defaultView??window,c=i.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,a=i.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,d=Array.from(t.querySelectorAll("*")).filter(u=>{const m=i.getComputedStyle(u);if(m.position!=="fixed"||m.display==="none"||m.visibility==="hidden"||Number(m.opacity)===0)return!1;const f=u.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((u,m,f)=>!f.some((g,x)=>x<m&&g.contains(u)));for(const u of d){const m=u.getBoundingClientRect(),f=i.getComputedStyle(u),g=Math.ceil(m.width)+8,x=Math.ceil(m.height)+2;r?.add(u),o.push(Qu(u)),u.style.position="absolute",u.style.top=`${m.top+a}px`,u.style.left=`${m.left+c}px`,u.style.right="auto",u.style.bottom="auto",u.style.width=`${g}px`,u.style.minWidth=`${g}px`,u.style.height=`${x}px`,u.style.minHeight=`${x}px`,u.style.margin="0",u.style.boxSizing="border-box",u.style.transform="none",f.zIndex!=="auto"&&(u.style.zIndex=f.zIndex)}return()=>{for(let u=o.length-1;u>=0;u-=1)o[u]?.()}},Xu=async(t,e,n,r={})=>{const o=[],i=t.defaultView??window,c=f=>{if(f===t.documentElement||f===t.body)return!0;try{const g=f.getBoundingClientRect();return g.width>0&&g.height>0&&g.right>=0&&g.bottom>=0&&g.left<=e&&g.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const f=new WeakSet;o.push(yy(t,e,n,f)),o.push(by(t,e,n))}const a=new Map;for(const f of Array.from(t.images))a.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const d=Array.from(t.querySelectorAll("picture"));for(const f of d){const g=Array.from(f.querySelectorAll("source"));if(g.length===0)continue;const x=g.map(w=>({source:w,srcset:w.getAttribute("srcset"),sizes:w.getAttribute("sizes")}));o.push(()=>{for(const w of x)w.srcset===null?w.source.removeAttribute("srcset"):w.source.setAttribute("srcset",w.srcset),w.sizes===null?w.source.removeAttribute("sizes"):w.source.setAttribute("sizes",w.sizes)});for(const w of g)w.removeAttribute("srcset"),w.removeAttribute("sizes")}const u=Array.from(t.images).filter(f=>c(f));await Promise.all(u.map(async f=>{const g=a.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!g)return;await Ac(f);const x=await Yu(g,t),w={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{w.src===null?f.removeAttribute("src"):f.setAttribute("src",w.src),w.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",w.srcset),w.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",w.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",x||Vr),await Ac(f)}));const m=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(m.map(async f=>{const g=i.getComputedStyle(f).backgroundImage;if(!g||g==="none"||!g.includes("url("))return;const x=await gy(g,t);if(x===g)return;const w=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=w}),f.style.backgroundImage=x})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function wy(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const i=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||i.width)),a=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||i.height)),d=r.body,u=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,m=n.scrollX||0,f=n.scrollY||0,g=n.pageXOffset||0,x=n.pageYOffset||0,w=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,S=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,p=o.scrollLeft||0,h=o.scrollTop||0,y=d?.scrollLeft||0,v=d?.scrollTop||0,j=u?.scrollLeft||0,N=u?.scrollTop||0,C=Math.max(m,g,w,p,y,j),k=Math.max(f,x,S,h,v,N);Qo("scroll sources",{windowScrollX:m,windowScrollY:f,pageScrollX:g,pageScrollY:x,visualViewportScrollX:w,visualViewportScrollY:S,rootScrollX:p,rootScrollY:h,bodyScrollX:y,bodyScrollY:v,scrollingElementScrollX:j,scrollingElementScrollY:N,scrollingElementTag:u?.tagName?.toLowerCase()??null,resolvedScrollX:C,resolvedScrollY:k,nestedScrolledElements:qu(r)});const D=Math.max(c,o.scrollWidth||0,d?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),M=Math.max(a,o.scrollHeight||0,d?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),A=Math.min(2,Math.max(1,window.devicePixelRatio||1)),_=o.style.scrollBehavior,L=d?.style.scrollBehavior??"";o.style.scrollBehavior="auto",d&&(d.style.scrollBehavior="auto");const F=my(r);Qo("nested scroll snapshot",F.snapshot);let $=()=>{},W=()=>{};try{await r.fonts?.ready.catch(()=>{}),$=await Xu(r,c,a,{applyLayoutWorkarounds:!1}),n.scrollTo(C,k),W=uy(r,C,k),F.reapply();const{snapdom:U}=await Rs(async()=>{const{snapdom:me}=await import("./vendor-zumer-snapdom-Btyu_Xi2.js");return{snapdom:me}},[]),K={backgroundColor:Ku(r),cache:"disabled",dpr:A,embedFonts:!0,fast:!1,height:M,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[fy,hy],quality:.82,width:D},P=await(await U(o,K)).toCanvas();if(!P.width||!P.height)return null;const V=P.width/Math.max(1,D),G=P.height/Math.max(1,M),X=Math.min(P.width,Math.max(1,Math.round(c*V))),J=Math.min(P.height,Math.max(1,Math.round(a*G))),ee=Math.max(0,P.width-X),le=Math.max(0,P.height-J),oe=Math.min(ee,Math.max(0,Math.round(C*V))),Ae=Math.min(le,Math.max(0,Math.round(k*G)));Qo("capture geometry",{viewportWidth:c,viewportHeight:a,captureWidth:D,captureHeight:M,canvasWidth:P.width,canvasHeight:P.height,xScale:V,yScale:G,sourceX:oe,sourceY:Ae,sourceWidth:X,sourceHeight:J});const Se=r.createElement("canvas");Se.width=X,Se.height=J;const Y=Se.getContext("2d");if(!Y)return null;Y.drawImage(P,oe,Ae,X,J,0,0,X,J);const je=await cy(Se,.82);return je?await al(je,c,a,c,a,e):null}finally{W(),F.cleanup(),$(),n.scrollTo(C,k),F.reapply(),o.style.scrollBehavior=_,d&&(d.style.scrollBehavior=L)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function vy(t,e){const n=await wy(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,i=o?.documentElement;if(!r||!o||!i)return null;const c=t.getBoundingClientRect(),a=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),d=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),u=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,m=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,g=Math.max(d,i.scrollHeight||0,f?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),w=i.style.scrollBehavior,S=f?.style.scrollBehavior??"";i.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let p="",h=()=>{};try{await o.fonts?.ready.catch(()=>{}),h=await Xu(o,a,d,{applyLayoutWorkarounds:!0}),r.scrollTo(u,m);const{getFontEmbedCSS:v,toJpeg:j}=await Rs(async()=>{const{getFontEmbedCSS:C,toJpeg:k}=await import("./vendor-html-to-image-BeoRn2gJ.js");return{getFontEmbedCSS:C,toJpeg:k}},[]),N=await v(i).catch(()=>"");p=await j(i,{quality:.82,pixelRatio:x,width:a,height:d,backgroundColor:Ku(o),imagePlaceholder:Vr,fontEmbedCSS:N||void 0,style:{transform:`translate(${-u}px, ${-m}px)`,transformOrigin:"top left",minWidth:`${a}px`,minHeight:`${g}px`},cacheBust:!0})}finally{h(),r.scrollTo(u,m),i.style.scrollBehavior=w,f&&(f.style.scrollBehavior=S)}const y=p.split(",",2)[1]||"";return y?await al(y,a,d,a,d,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const Sy=tn(()=>Rs(()=>import("./WalkthroughView-HStEYdD2.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])).then(t=>({default:t.WalkthroughView}))),jy=tn(()=>Rs(()=>import("./DiffView-1zd0slLu.js"),__vite__mapDeps([121,1,2,4,5,6,7,8,3,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])).then(t=>({default:t.DiffView}))),ky=tn(()=>Rs(()=>import("./FilesView-WkxsWHBE.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,3,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,113,123,124,125,126,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,127,128,114,115,129,130,112,131,118])).then(t=>({default:t.FilesView}))),Cy=tn(()=>Rs(()=>import("./GitView-OSVIn5V1.js"),__vite__mapDeps([132,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,113,133,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,114,115,117,118,119,120])).then(t=>({default:t.GitView}))),Ny=tn(()=>Rs(()=>import("./PlanView-BYgHBHDt.js"),__vite__mapDeps([134,1,2,4,5,6,7,8,123,50,51,52,53,54,55,72,48,49,56,124,125,3,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,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,73,74,75,76,77,78,79,80,112,113,131,114,115,100,101,85,86,87,88,89,90,91,92,93,94,95,96,97,98])).then(t=>({default:t.PlanView}))),Ay=380,Dy=1400,Ju=600,Py=100,Iy=24,pi=new Map,Dc=200,Ty=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",Ey=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},Pc=t=>Number.isFinite(t)?Math.min(Dy,Math.max(Ay,Math.round(t))):Ju,My=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Ry=(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},Zu=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),Oy=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},Fy=(t,e,n)=>{if(t.mode==="chat"){const r=Xo(t.dedupeKey);if(r){const i=e.get(r)?.trim();if(i)return i}const o=t.sessionTitleFallback?.trim();return o||n("contextPanel.mode.chat")}if(t.label)return t.label;if(t.mode==="file")return Oy(t.targetPath)||n("contextPanel.mode.files");if(t.mode==="preview"){const r=t.targetPath;if(r)try{const o=new URL(r);return o.host||o.hostname||n("contextPanel.mode.preview")}catch{}return n("contextPanel.mode.preview")}return t.mode==="diff"?n("contextPanel.mode.diff"):Zu(t.mode,n)},Ic=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Wa,{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(T,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(T,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(T,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(T,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(T,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(T,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(T,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(T,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(T,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(T,{name:"global",className:"h-3.5 w-3.5"})},By=200,Ly=480,_y=({visible:t})=>{const{t:e}=gt(),n=pe(h=>h.contextEditorTreeWidth),r=pe(h=>h.setContextEditorTreeWidth),[o,i]=l.useState(!1),c=l.useRef(0),a=l.useRef(n),d=l.useRef(null),u=l.useRef(null),m=l.useRef(null),f=l.useCallback(h=>Math.min(Ly,Math.max(By,Math.round(h))),[]),g=l.useCallback(h=>{const y=m.current;y&&(y.style.width=`${h}px`,y.style.setProperty("--oc-editor-tree-width",`${h}px`))},[]),x=h=>{if(t){try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}u.current=h.pointerId,i(!0),c.current=h.clientX,a.current=n,d.current=n,h.preventDefault()}},w=h=>{if(!o||u.current!==h.pointerId)return;const y=c.current-h.clientX,v=f(a.current+y);d.current!==v&&(d.current=v,g(v))},S=h=>{if(u.current!==h.pointerId)return;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const y=f(d.current??n);u.current=null,d.current=null,i(!1),r(y)},p=t?n:0;return s.jsxs("div",{ref:m,className:Ce("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${o?d.current??p:p}px`,"--oc-editor-tree-width":`${o?d.current??n:n}px`,overflowX:"clip",transitionProperty:o?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:Ce("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",o&&"bg-[var(--interactive-border)]"),onPointerDown:x,onPointerMove:w,onPointerUp:S,onPointerCancel:S,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:Ce("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",o&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(Db,{})})]})},Xo=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,$y=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},zy=(t,e)=>{if(e.length===0)return pi;const n=new Set(e),r=new Map;for(const o of t){if(!n.has(o.id))continue;const i=o.title?.trim();i&&r.set(o.id,i)}return r.size===0?pi:r},Wy=(t,e)=>{const n=La(t),r=l.useRef(pi),o=l.useRef(e);return o.current=e,l.useSyncExternalStore(n.subscribe,l.useCallback(()=>{const i=zy(n.getState().session,o.current);return $y(r.current,i)?r.current:(r.current=i,i)},[n]),()=>pi)},ef=`new Promise((resolve) => {
|
|
48
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
49
|
-
if (existing) existing.remove();
|
|
50
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
51
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
52
|
-
}
|
|
53
|
-
const overlay = document.createElement('div');
|
|
54
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
55
|
-
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
56
|
-
document.documentElement.appendChild(overlay);
|
|
57
|
-
const cssEscape = (value) => {
|
|
58
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
59
|
-
};
|
|
60
|
-
const selectorPart = (element) => {
|
|
61
|
-
const tag = element.tagName.toLowerCase();
|
|
62
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
63
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
64
|
-
return tag + className;
|
|
65
|
-
};
|
|
66
|
-
const metadata = (element) => {
|
|
67
|
-
const rect = element.getBoundingClientRect();
|
|
68
|
-
const style = getComputedStyle(element);
|
|
69
|
-
const ancestry = [];
|
|
70
|
-
let current = element;
|
|
71
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
72
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
73
|
-
current = current.parentElement;
|
|
74
|
-
}
|
|
75
|
-
const attrs = {};
|
|
76
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
77
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
78
|
-
return {
|
|
79
|
-
frame: 'top',
|
|
80
|
-
tag: element.tagName.toLowerCase(),
|
|
81
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
82
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
83
|
-
path,
|
|
84
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
85
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
86
|
-
attributes: attrs,
|
|
87
|
-
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
88
|
-
ancestry,
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
const move = (event) => {
|
|
92
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
93
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
94
|
-
const rect = element.getBoundingClientRect();
|
|
95
|
-
overlay.style.display = 'block';
|
|
96
|
-
overlay.style.left = rect.left + 'px';
|
|
97
|
-
overlay.style.top = rect.top + 'px';
|
|
98
|
-
overlay.style.width = rect.width + 'px';
|
|
99
|
-
overlay.style.height = rect.height + 'px';
|
|
100
|
-
};
|
|
101
|
-
const cleanup = () => {
|
|
102
|
-
window.removeEventListener('mousemove', move, true);
|
|
103
|
-
window.removeEventListener('click', click, true);
|
|
104
|
-
window.removeEventListener('keydown', keydown, true);
|
|
105
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
106
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const cancel = () => {
|
|
110
|
-
cleanup();
|
|
111
|
-
overlay.remove();
|
|
112
|
-
resolve(null);
|
|
113
|
-
};
|
|
114
|
-
const click = (event) => {
|
|
115
|
-
event.preventDefault();
|
|
116
|
-
event.stopPropagation();
|
|
117
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
118
|
-
const result = element ? metadata(element) : null;
|
|
119
|
-
cleanup();
|
|
120
|
-
overlay.remove();
|
|
121
|
-
resolve(result);
|
|
122
|
-
};
|
|
123
|
-
const keydown = (event) => {
|
|
124
|
-
if (event.key !== 'Escape') return;
|
|
125
|
-
cancel();
|
|
126
|
-
};
|
|
127
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
128
|
-
window.addEventListener('mousemove', move, true);
|
|
129
|
-
window.addEventListener('click', click, true);
|
|
130
|
-
window.addEventListener('keydown', keydown, true);
|
|
131
|
-
});`,Jo=`(() => {
|
|
132
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
133
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
137
|
-
if (overlay) overlay.remove();
|
|
138
|
-
})()`,Uy=`(() => {
|
|
139
|
-
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
140
|
-
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
141
|
-
|
|
142
|
-
const navigate = (rawUrl) => {
|
|
143
|
-
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
144
|
-
try {
|
|
145
|
-
const url = new URL(rawUrl, window.location.href);
|
|
146
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
147
|
-
window.location.assign(url.href);
|
|
148
|
-
return true;
|
|
149
|
-
} catch (_error) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const originalOpen = window.open.bind(window);
|
|
155
|
-
window.open = (url, target, features) => {
|
|
156
|
-
if (navigate(url)) return null;
|
|
157
|
-
return originalOpen(url, target, features);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
document.addEventListener('click', (event) => {
|
|
161
|
-
if (event.defaultPrevented) return;
|
|
162
|
-
const target = event.target;
|
|
163
|
-
if (!(target instanceof Element)) return;
|
|
164
|
-
const anchor = target.closest('a[target="_blank"][href]');
|
|
165
|
-
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
166
|
-
if (!navigate(anchor.href)) return;
|
|
167
|
-
event.preventDefault();
|
|
168
|
-
event.stopPropagation();
|
|
169
|
-
}, true);
|
|
170
|
-
})()`,mo=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},Tc=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},Vy=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,tf=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Ec=(t,e,n)=>{const r=tf(e);t.postMessage(n,r)},Hy=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},Mc=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("ocPreview"),e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},Ky=({rawUrl:t,onNavigate:e})=>{const{t:n}=gt(),{currentTheme:r}=Ir(),[o,i]=l.useReducer(H=>H+1,0),[c,a]=l.useReducer(H=>H+1,0),[d,u]=l.useState({status:"idle"}),[m,f]=l.useState(""),g=l.useRef(null),x=l.useRef(1),[w,S]=l.useState(!1),[p,h]=l.useState(!1),[y,v]=l.useState("all"),[j,N]=l.useState([]),[C,k]=l.useState(!1),[D,M]=l.useState(null),A=Ge(H=>H.currentSessionId),_=Ge(H=>H.newSessionDraft?.open),L=Yr(),F=go(H=>H.addDraft),$=Va(H=>H.addAttachedFile);let W=null;try{W=t?new URL(t):null}catch{W=null}const U=W?W.hostname==="localhost"||W.hostname==="127.0.0.1"||W.hostname==="::1"||W.hostname==="[::1]"||W.hostname==="0.0.0.0":!1,K=W?W.hostname==="0.0.0.0"?new URL(W.toString().replace("0.0.0.0","127.0.0.1")):W:null,b=K?K.toString():"",P=b?`${cr()||"same-origin"}|${b}`:"",V=r.metadata.variant;l.useEffect(()=>{if(!b||!U){u({status:"idle"});return}const H=ll(P);if(H?.previewToken){u({status:"ready",proxyBasePath:H.proxyBasePath,previewToken:H.previewToken,expiresAt:H.expiresAt});return}H&&Us.delete(P);let Ne=!1;return u({status:"loading"}),(async()=>{try{const he=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:b})});if(!he.ok){Us.delete(P);const re=await he.json().catch(()=>({})),R=typeof re?.error=="string"?re.error:`HTTP ${he.status}`;Ne||u({status:"error",message:R});return}const ve=await he.json(),se=typeof ve.proxyBasePath=="string"?ve.proxyBasePath:"",Q=typeof ve.previewToken=="string"?ve.previewToken:"",ye=typeof ve.expiresAt=="number"?ve.expiresAt:0;if(!se||!Q){Us.delete(P),Ne||u({status:"error",message:n("contextPanel.preview.proxyError")});return}Us.set(P,{proxyBasePath:se,previewToken:Q,expiresAt:ye}),Ne||u({status:"ready",proxyBasePath:se,previewToken:Q,expiresAt:ye})}catch(he){if(Us.delete(P),!Ne){const ve=he instanceof Error?he.message:String(he);u({status:"error",message:ve})}}})(),()=>{Ne=!0}},[U,P,c,n,b]);const G=K&&(K.protocol==="http:"||K.protocol==="https:")?K.toString():"",X=U&&d.status==="ready"?`${d.proxyBasePath}|${d.previewToken||""}|${o}`:"";l.useEffect(()=>{if(!X){f("");return}let H=!1;return f(""),Od(cr()).then(Ne=>{!H&&Ne&&f(X)}).catch(()=>{}),()=>{H=!0}},[X]);const J=U&&d.status==="ready"&&K&&m===X?(()=>{const H=K.pathname||"/",Ne=new URLSearchParams(K.search);Ne.delete("oc_url_token"),Ne.delete("oc_client_token"),Ne.set("ocPreview",String(o)),Ne.set("oc_preview_token",d.previewToken||"");const he=Ne.toString(),ve=K.hash||"";return vi().authenticatedAsset(`${d.proxyBasePath}${H}${he?`?${he}`:""}${ve}`)})():"",ee=U?J:G,le=U?Hy(J):G,oe=U&&(d.status==="loading"||d.status==="idle"||m!==X),Ae=U&&d.status==="error",Se=l.useCallback(H=>{const Ne=A??(_?"draft":null);if(!Ne||!L){Ie.error(n("contextPanel.preview.inspect.attachNoSession"));return}const he=t||ee||"",ve=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},se=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let Q=!1;try{const ye=g.current,re=ye?await Hu(ye,H):null;re&&(await $(re),Q=!0)}catch{Q=!1}F({directory:L,sessionKey:Ne},{source:"preview-annotation",fileLabel:he||"preview",startLine:1,endLine:1,code:il({pageUrl:he,viewport:ve,devicePixelRatio:se,target:H,screenshotAttached:Q,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),Ie.success(n("contextPanel.preview.inspect.attached"))})()},[$,F,A,L,ee,_,t,n]);l.useEffect(()=>{S(!1),N([]),h(!1),v("all"),k(!1),M(null),x.current=1},[ee]),l.useEffect(()=>{const H=g.current?.contentWindow;!w||!H||Ec(H,J,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:C})},[w,C,J]),l.useEffect(()=>{const H=g.current?.contentWindow;!w||!H||Ec(H,J,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:V})},[w,V,J]),l.useEffect(()=>{if(!C||typeof window>"u")return;const H=Ne=>{Ne.key==="Escape"&&(Ne.preventDefault(),Ne.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",H,!0),()=>window.removeEventListener("keydown",H,!0)},[C]),l.useEffect(()=>{if(!U||typeof window>"u")return;const H=ve=>{if(typeof ve=="string")return ve;if(ve==null)return"";try{return JSON.stringify(ve)}catch{return String(ve)}},Ne=ve=>{const se=x.current;x.current+=1,N(Q=>{const ye=[...Q,{...ve,id:se}];return ye.length>Dc?ye.slice(ye.length-Dc):ye})},he=ve=>{if(ve.source!==g.current?.contentWindow)return;const se=ve.data;if(!(!se||se.source!=="openchamber-preview-bridge"||se.version!==1)){if(se.type==="ready"){S(!0);return}if(se.type==="console"){const Q=se.level==="error"||se.level==="warn"||se.level==="info"||se.level==="debug"?se.level:"log",ye=Array.isArray(se.args)?se.args.map(H).filter(Boolean):[];Ne({level:Q,message:ye.join(" "),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="runtime-error"){const Q=H(se.filename),ye=typeof se.line=="number"?se.line:null,re=typeof se.column=="number"?se.column:null,R=Q?`${Q}${ye!==null?`:${ye}${re!==null?`:${re}`:""}`:""}`:"",ce=H(se.stack);Ne({level:"runtime",message:H(se.message)||n("contextPanel.preview.console.runtimeError"),details:[R,ce].filter(Boolean).join(`
|
|
171
|
-
`),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="resource-error"){const Q=H(se.tag)||"resource",ye=H(se.url);Ne({level:"resource",message:ye?`${Q}: ${ye}`:Q,details:H(se.outerHTML),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="hover"){M(Ur(se.target)?se.target:null);return}if(se.type==="select"&&Ur(se.target)){M(se.target),k(!1),Se(se.target);return}if(se.type==="navigate-preview"){const Q=typeof se.url=="string"?se.url:"",ye=se.navigation==="external"?"external":"proxy";if(Q&&ye==="external"){Gr(Q);return}Q&&e(Q)}}};return window.addEventListener("message",he),()=>{window.removeEventListener("message",he)}},[Se,U,e,n]);const Y=j.filter(H=>H.level==="error"||H.level==="runtime"||H.level==="resource").length,je=j.filter(H=>Ty(H,y)),me=l.useCallback(()=>{const H=[`Preview URL: ${t||ee||""}`,`Events: ${j.length}`,""].join(`
|
|
172
|
-
`),Ne=j.map(he=>{const ve=new Date(he.ts).toISOString(),se=he.details?`
|
|
173
|
-
${he.details}`:"";return`[${ve}] [${he.level}] ${he.message}${se}`}).join(`
|
|
174
|
-
`);Bn(`${H}${Ne}`).then(he=>{he.ok?Ie.success(n("contextPanel.preview.console.copied")):Ie.error(n("contextPanel.preview.console.copyFailed"))})},[j,ee,t,n]),z=l.useCallback(()=>{const H=A??(_?"draft":null);if(!H||!L){Ie.error(n("contextPanel.preview.console.attachNoSession"));return}const Ne=[`Preview URL: ${t||ee||""}`,`Events: ${j.length}`,""].join(`
|
|
175
|
-
`),he=j.map(ve=>{const se=new Date(ve.ts).toISOString(),Q=ve.details?`
|
|
176
|
-
${ve.details}`:"";return`[${se}] [${ve.level}] ${ve.message}${Q}`}).join(`
|
|
177
|
-
`);F({directory:L,sessionKey:H},{source:"preview-console",fileLabel:t||ee||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${Ne}${he}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),Ie.success(n("contextPanel.preview.console.attached"))},[F,j,A,L,ee,_,t,n]),[Z,ne]=l.useState("unknown"),fe=l.useRef(0),xe=l.useRef(0),Te=l.useRef(""),be=l.useRef(""),De=15e3;l.useEffect(()=>{if(!J){ne("unknown"),Te.current="",fe.current=0,xe.current=0;return}let H=!1,Ne=null;Te.current!==P&&(Te.current=P,fe.current=Date.now(),xe.current=0);const he=ve=>{Ne=setTimeout(()=>{H||i()},ve)};return ne("unknown"),(async()=>{const se=await(async()=>{try{return await hs(J,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(H)return;if(!se){ne("unreachable"),he(5e3);return}const Q=oy(se.headers,be.current===P);if(Q!=="none"){if(Us.delete(P),Q==="retry-registration")be.current=P,u({status:"loading"}),a();else{const R=await se.json().catch(()=>({}));if(H)return;const ce=typeof R?.error=="string"?R.error:`HTTP ${se.status}`;u({status:"error",message:ce})}return}if(se.status!==502){be.current="",ne("reachable");return}const ye=fe.current||Date.now();if(Date.now()-ye<De){ne("starting"),xe.current+=1;const R=xe.current,ce=Math.min(2e3,250*Math.pow(2,Math.min(4,R)));he(ce);return}ne("unreachable"),he(5e3)})(),()=>{H=!0,Ne&&clearTimeout(Ne)}},[P,J,o]);const Ee=U&&d.status==="ready"&&(Z==="unknown"||Z==="starting"),Re=U&&d.status==="ready"&&Z==="unreachable",de=l.useCallback(H=>{if(!U||d.status!=="ready"||typeof window>"u")return;const Ne=H.currentTarget.contentWindow;if(Ne)try{const he=Ne.location,ve=tf(J);if(he.origin!==ve||he.pathname.startsWith(d.proxyBasePath))return;const se=`${d.proxyBasePath}${he.pathname}${he.search}${he.hash}`;Ne.location.replace(se)}catch{}},[U,J,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:le||t,children:le||t||n("contextPanel.preview.empty")}),s.jsx(et,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!ee,children:s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{G&&Gr(G)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!G,children:s.jsx(T,{name:"external-link",className:"h-3.5 w-3.5"})}),U?s.jsx(et,{type:"button",size:"sm",variant:C?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(H=>!H),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!w,children:s.jsx(T,{name:"cursor",className:"h-3.5 w-3.5"})}):null,U?s.jsxs(et,{type:"button",size:"sm",variant:p?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>h(H=>!H),title:n(w?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(w?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!w&&j.length===0,children:[s.jsx(T,{name:"terminal-box",className:"h-3.5 w-3.5"}),Y>0?s.jsx("span",{className:"typography-micro text-status-error",children:Y}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[Ee?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):Re?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(et,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):ee&&(!U||Z==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:g,src:ee,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:V},onLoad:de,sandbox:U?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${ee}:${o}`),C&&D?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[D.tag,D.text?` · ${D.text}`:""]})}):null]}):oe?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):Ae?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),p?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(et,{type:"button",size:"xs",variant:"ghost",onClick:z,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(et,{type:"button",size:"xs",variant:"ghost",onClick:me,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(et,{type:"button",size:"xs",variant:"ghost",onClick:()=>N([]),disabled:j.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(H=>s.jsx(et,{type:"button",size:"xs",variant:y===H?"secondary":"ghost",onClick:()=>v(H),children:n(H==="all"?"contextPanel.preview.console.filter.all":H==="errors"?"contextPanel.preview.console.filter.errors":H==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},H))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:j.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):je.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):je.map(H=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:Ce("shrink-0 uppercase",H.level==="error"||H.level==="runtime"||H.level==="resource"?"text-status-error":H.level==="warn"?"text-status-warning":"text-muted-foreground"),children:H.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:H.message})]})},H.id))})]}):null]})]})},Gy=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,qy=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=gt(),o=l.useRef(null),i=pe(z=>z.setContextPanelTabTargetPath),c=mo(t),a=c!=="about:blank"?c:"",[d,u]=l.useState(a),[m,f]=l.useState(a),[g,x]=l.useState(a),[w,S]=l.useState(()=>a?[a]:[]),[p,h]=l.useState(()=>a?0:-1),[y,v]=l.useReducer(z=>z+1,0),[j,N]=l.useState(!!a),[C,k]=l.useState(!1),[D,M]=l.useState(null),[A,_]=l.useState({status:"idle"}),[L,F]=l.useState(""),$=Ge(z=>z.currentSessionId),W=Ge(z=>z.newSessionDraft?.open),U=go(z=>z.addDraft),K=Va(z=>z.addAttachedFile),b=l.useCallback(z=>{!z||z==="about:blank"||!e||!n||i(e,n,z)},[e,n,i]),P=l.useCallback((z,Z)=>{const ne=mo(z),fe=ne!=="about:blank"?ne:"";f(fe),u(fe),Z?.inFrame?N(!1):(x(fe),N(!!fe)),b(fe),S(xe=>{if(!fe)return h(-1),[];if(Z?.replaceHistory)return xe;const Te=p>=0?xe.slice(0,p+1):[];if(Te[Te.length-1]===fe)return h(Te.length-1),Te;const De=[...Te,fe];return h(De.length-1),De})},[p,b]),V=l.useCallback(z=>{const Z=w[z];Z&&(h(z),f(Z),x(Z),u(Z),N(!0),b(Z))},[w,b]),G=l.useCallback(()=>{if(m){N(!0);try{o.current?.contentWindow?.location.reload()}catch{v()}}},[m]);l.useEffect(()=>{if(!g){_({status:"idle"});return}const z=ly(g),Z=ll(z);if(Z?.previewToken){_({status:"ready",proxyBasePath:Z.proxyBasePath,previewToken:Z.previewToken,expiresAt:Z.expiresAt});return}Z&&Us.delete(z);let ne=!1;return _({status:"loading"}),N(!0),(async()=>{try{const fe=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:g,allowExternal:!0})});if(!fe.ok){const Ee=await fe.json().catch(()=>({})),Re=typeof Ee?.error=="string"?Ee.error:`HTTP ${fe.status}`;ne||_({status:"error",message:Re});return}const xe=await fe.json(),Te=typeof xe.proxyBasePath=="string"?xe.proxyBasePath:"",be=typeof xe.previewToken=="string"?xe.previewToken:"",De=typeof xe.expiresAt=="number"?xe.expiresAt:0;if(!Te||!be){ne||_({status:"error",message:r("contextPanel.preview.proxyError")});return}Us.set(z,{proxyBasePath:Te,previewToken:be,expiresAt:De}),ne||_({status:"ready",proxyBasePath:Te,previewToken:be,expiresAt:De})}catch(fe){if(!ne){const xe=fe instanceof Error?fe.message:String(fe);_({status:"error",message:xe})}}})(),()=>{ne=!0}},[g,r]);const X=g&&A.status==="ready"?`${A.proxyBasePath}|${A.previewToken||""}|${y}`:"";l.useEffect(()=>{if(!X){F("");return}let z=!1;return F(""),Od(cr()).then(Z=>{!z&&Z&&F(X)}).catch(()=>{}),()=>{z=!0}},[X]);const J=l.useMemo(()=>{if(L!==X||!g||A.status!=="ready")return"";try{const z=new URL(g),Z=z.pathname||"/",ne=new URLSearchParams(z.search);ne.delete("oc_url_token"),ne.delete("oc_client_token"),ne.set("ocPreview",String(y)),ne.set("oc_preview_token",A.previewToken||"");const fe=ne.toString();return vi().authenticatedAsset(`${A.proxyBasePath}${Z}${fe?`?${fe}`:""}${z.hash}`)}catch{return""}},[g,A,X,y,L]),ee=J||(A.status==="error"?g:""),le=l.useCallback(z=>{if(!z||!g||A.status!=="ready")return"";try{const Z=new URL(z,window.location.origin),ne=A.proxyBasePath.endsWith("/")?A.proxyBasePath.slice(0,-1):A.proxyBasePath;if(Z.origin!==window.location.origin||!Z.pathname.startsWith(ne))return"";const fe=Z.pathname.slice(ne.length)||"/",xe=new URL(g).origin;return Mc(new URL(`${fe}${Z.search}${Z.hash}`,xe).toString())}catch{return""}},[g,A]),oe=l.useCallback(z=>{if(!z||!g||A.status!=="ready")return"";try{const Z=new URL(z,window.location.origin),ne=new URL(g).origin;if(Z.origin!==window.location.origin||ne===window.location.origin)return"";const fe=A.proxyBasePath.endsWith("/")?A.proxyBasePath.slice(0,-1):A.proxyBasePath;return Z.pathname.startsWith(fe)?"":Mc(new URL(`${Z.pathname}${Z.search}${Z.hash}`,ne).toString())}catch{return""}},[g,A]),Ae=l.useCallback(z=>{const Z=o.current?.contentWindow;Z&&Z.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:z},window.location.origin)},[]),Se=l.useCallback(async z=>{const Z=$??(W?"draft":null);if(!Z){Ie.error(r("contextPanel.preview.inspect.attachNoSession"));return}const ne=o.current,fe=ne?.contentWindow,xe=ne?.getBoundingClientRect(),Te={width:Number.isFinite(fe?.innerWidth)?fe?.innerWidth??xe?.width??0:xe?.width??0,height:Number.isFinite(fe?.innerHeight)?fe?.innerHeight??xe?.height??0:xe?.height??0},be=ne?await Hu(ne,z):null,De=!!be;be&&await K(be),U({directory:e,sessionKey:Z},{source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:il({pageUrl:m,viewport:Te,devicePixelRatio:window.devicePixelRatio||1,target:z,screenshotAttached:De,intro:r(De?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),Ie.success(r("contextPanel.preview.inspect.attached"))},[K,U,$,m,e,W,r]),Y=l.useCallback(()=>{const z=o.current;M(null),Ae(!1),z&&Tc(z,Jo).catch(()=>{})},[Ae]);l.useEffect(()=>{if(!C)return;const z=Z=>{Z.key==="Escape"&&(Z.preventDefault(),Z.stopImmediatePropagation(),k(!1),Y())};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[Y,C]),l.useEffect(()=>()=>Y(),[Y]),l.useEffect(()=>{const z=Z=>{if(Z.source!==o.current?.contentWindow)return;const ne=Z.data;if(!(!ne||ne.source!=="openchamber-preview-bridge"||ne.version!==1)){if(ne.type==="ready"){const fe=typeof ne.url=="string"?ne.url:"",xe=le(fe);xe&&xe!==m&&P(xe,{inFrame:!0});return}if(ne.type==="hover"){M(Ur(ne.target)?ne.target:null);return}if(ne.type==="select"&&Ur(ne.target)){M(null),k(!1),Ae(!1),Se(ne.target);return}if(ne.type==="navigate-preview"){const fe=typeof ne.url=="string"?ne.url:"",xe=oe(fe);if(xe){P(xe);return}fe&&P(fe)}}};return window.addEventListener("message",z),()=>window.removeEventListener("message",z)},[P,Se,m,le,oe,Ae]);const je=l.useCallback(()=>{const z=o.current;if(!(!z||!m)){if(C){k(!1),Y();return}if(J){M(null),k(!0),Ae(!0);return}k(!0),(async()=>{try{const Z=await Tc(z,ef);if(k(!1),!Z||!Ur(Z))return;await Se(Z)}catch{k(!1),Ie.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[Se,Y,m,C,Ae,J,r]),me=l.useCallback(()=>{try{const z=o.current?.contentWindow?.location.href||"",Z=oe(z);if(Z){P(Z,{inFrame:!0});return}}catch{}N(!1),C&&J&&Ae(!0)},[P,oe,C,Ae,J]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<=0,onClick:()=>V(p-1),children:s.jsx(T,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:p<0||p>=w.length-1,onClick:()=>V(p+1),children:s.jsx(T,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:G,children:s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:z=>{z.preventDefault(),P(d)},children:s.jsx("input",{value:d,onChange:z=>u(z.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(et,{type:"button",variant:C?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:je,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(T,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!m,onClick:()=>{Gr(m)},children:s.jsx(T,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[ee?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:ee,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:me},`${n}:${y}`),C&&D?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[D.tag,D.text?` · ${D.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Ha,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),j?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},Yy=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=gt(),o=l.useRef(null),i=pe(A=>A.setContextPanelTabTargetPath),c=mo(t),a=c!=="about:blank"?c:"",d=l.useRef(mo(t)),[u,m]=l.useState(a),[f,g]=l.useState(a),[x,w]=l.useState(!1),[S,p]=l.useState(!0),h=l.useRef(null),y=S,v=l.useCallback(A=>{!A||A==="about:blank"||!e||!n||i(e,n,A)},[e,n,i]),j=Ge(A=>A.currentSessionId),N=Ge(A=>A.newSessionDraft?.open),C=go(A=>A.addDraft),k=Va(A=>A.addAttachedFile);l.useEffect(()=>{const A=o.current;if(!A)return;const _=()=>{try{const K=A.getURL();K&&K!=="about:blank"&&(g(K),m(K),v(K))}catch{}},L=K=>{const b=K.detail;typeof b?.url=="string"&&b.url&&(g(b.url),m(b.url),v(b.url))},F=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>p(!0),200)},$=()=>{h.current&&clearTimeout(h.current),p(!1),_()},W=K=>{const b=K.detail;if(b?.disposition==="new-window"||b?.disposition==="foreground-tab"||b?.disposition==="background-tab"){K.preventDefault();const P=o.current;typeof P?.loadURL=="function"&&b.url&&P.loadURL(b.url)}},U=()=>{try{A.executeJavaScript?.(Uy,!0).catch(()=>{})}catch{}};A.addEventListener("did-navigate",L),A.addEventListener("did-navigate-in-page",L),A.addEventListener("did-start-loading",F),A.addEventListener("did-stop-loading",$),A.addEventListener("new-window",W),A.addEventListener("dom-ready",U);try{A.isLoading()||(p(!1),_())}catch{}return U(),()=>{h.current&&clearTimeout(h.current),A.removeEventListener("did-navigate",L),A.removeEventListener("did-navigate-in-page",L),A.removeEventListener("did-start-loading",F),A.removeEventListener("did-stop-loading",$),A.removeEventListener("new-window",W),A.removeEventListener("dom-ready",U)}},[v]),l.useEffect(()=>{const A=setTimeout(()=>p(!1),3e4);return()=>clearTimeout(A)},[]),l.useEffect(()=>{if(!x)return;const A=_=>{if(_.key!=="Escape")return;_.preventDefault(),_.stopImmediatePropagation(),w(!1);const L=o.current;try{L?.executeJavaScript?.(Jo).catch(()=>{})}catch{}};return window.addEventListener("keydown",A,!0),()=>window.removeEventListener("keydown",A,!0)},[x]),l.useEffect(()=>{const A=o.current;return()=>{try{const _=A?.getURL?.();_&&_!=="about:blank"&&i(e,n,_)}catch{}try{A?.executeJavaScript?.(Jo).catch(()=>{})}catch{}}},[e,n,i]);const D=l.useCallback(A=>{const _=o.current;if(typeof _?.loadURL!="function")return;const L=mo(A);try{_.loadURL(L)}catch{}},[]),M=l.useCallback(()=>{const A=o.current;if(A){if(x){w(!1);try{A.executeJavaScript?.(Jo).catch(()=>{})}catch{}return}w(!0),A.executeJavaScript?.(ef,!0).then(async _=>{if(w(!1),!_||!Ur(_))return;const L=j??(N?"draft":null);if(!L){Ie.error(r("contextPanel.preview.inspect.attachNoSession"));return}const F=typeof A.getWebContentsId=="function"?A.getWebContentsId():null;if(F==null)return;const $=await th("desktop_browser_capture_page",{webContentsId:F}),W=await A.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),U=Number.isFinite(W?.width)?W.width:$.width,K=Number.isFinite(W?.height)?W.height:$.height,b=await al($.base64,$.width,$.height,U,K,_),P=!!b;b&&await k(b),C({directory:e,sessionKey:L},{source:"preview-annotation",fileLabel:f||"browser",startLine:1,endLine:1,code:il({pageUrl:f,viewport:{width:U,height:K},devicePixelRatio:window.devicePixelRatio||1,target:_,screenshotAttached:P,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),Ie.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>w(!1))}},[k,C,j,f,e,x,N,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(T,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(T,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:A=>{A.preventDefault(),D(u)},children:s.jsx("input",{value:u,onChange:A=>m(A.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(et,{type:"button",variant:x?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:M,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(T,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Gr(f)},children:s.jsx(T,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:d.current,partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!f||f==="about:blank")&&!S?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Ha,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,y?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},Qy=()=>{const{t}=gt(),e=Yr()??"",n=l.useMemo(()=>Ey(e),[e]),r=pe(I=>n?I.contextPanelByDirectory[n]:void 0),o=pe(I=>I.closeContextPanel),i=pe(I=>I.closeContextPanelTab),c=pe(I=>I.openContextPanelTab),a=pe(I=>I.toggleContextPanelExpanded),d=pe(I=>I.setContextPanelWidth),u=pe(I=>I.setActiveContextPanelTab),m=pe(I=>I.reorderContextPanelTabs),f=On(I=>I.setSelectedPath),g=pe(I=>I.openContextPreview),x=pe(I=>I.contextEditorTreeVisible),w=pe(I=>I.toggleContextEditorTree),S=pe(I=>I.allowPromptingSubagentSessions),{themeMode:p,setThemeMode:h,lightThemeId:y,darkThemeId:v,currentTheme:j}=Ir(),N=l.useMemo(()=>r?.tabs??[],[r?.tabs]),C=N.find(I=>I.id===r?.activeTabId)??N[N.length-1]??null,k=!!(r?.isOpen&&C),D=!!(k&&r?.expanded),[M,A]=l.useState(null),_=C?.mode??null,L=_?r?.widthByMode?.[_]:void 0,F=_?Zm(_):.5,$=M??(typeof window<"u"?window.innerWidth:Ju*2),W=Pc(L??Math.round(F*$)),U=l.useMemo(()=>{const I=[];for(const ue of N){if(ue.mode!=="chat")continue;const ke=Xo(ue.dedupeKey);ke&&!I.includes(ke)&&I.push(ke)}return I},[N]),K=Wy(n||void 0,U),[b,P]=l.useState(!1),V=l.useRef(0),G=l.useRef(W),X=l.useRef(null),J=l.useRef(null),ee=l.useRef(null),le=l.useRef(new Map),oe=l.useRef(new Map),Ae=l.useRef(!1);l.useLayoutEffect(()=>{const I=ee.current?.parentElement;if(!I||typeof ResizeObserver>"u")return;const ue=new ResizeObserver(()=>{A(I.clientWidth||null)});return ue.observe(I),A(I.clientWidth||null),()=>ue.disconnect()},[]),l.useEffect(()=>{if(!k||Ae.current){Ae.current=k;return}const I=window.requestAnimationFrame(()=>{ee.current?.focus({preventScroll:!0})});return Ae.current=!0,()=>window.cancelAnimationFrame(I)},[k]);const Se=l.useRef(null),Y=l.useRef(null),je=l.useCallback(()=>{Y.current=null;const I=ee.current,ue=X.current;!I||ue===null||I.style.setProperty("--oc-context-panel-width",`${ue}px`)},[]);l.useEffect(()=>()=>{Y.current!==null&&clearTimeout(Y.current)},[]);const me=l.useCallback(I=>{const ue=Pc(I),ke=Se.current;return ke===null?ue:Math.min(ue,Math.max(1,ke))},[]),z=l.useCallback(I=>{!k||D||!n||(J.current=I.pointerId,P(!0),V.current=I.clientX,G.current=W,X.current=W,Se.current=My(ee.current),document.documentElement.style.cursor="col-resize",I.preventDefault())},[n,D,k,W]),Z=l.useCallback(()=>{const I=me(X.current??W);X.current=null,Se.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),document.documentElement.style.cursor="",n&&_&&d(n,_,I),P(!1),J.current=null},[_,me,n,d,W]);l.useEffect(()=>{if(!b)return;const I=we=>{if(J.current!==we.pointerId)return;const qe=V.current-we.clientX,Je=me(G.current+qe);X.current!==Je&&(X.current=Je,Y.current===null&&(Y.current=setTimeout(je,Py)))},ue=we=>{J.current===we.pointerId&&Z()},ke=()=>{Z()};return window.addEventListener("pointermove",I),window.addEventListener("pointerup",ue),window.addEventListener("pointercancel",ue),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",ue),window.removeEventListener("pointercancel",ue),window.removeEventListener("blur",ke)}},[je,me,Z,b]),l.useEffect(()=>{b||(X.current=null,document.documentElement.style.cursor="")},[b]);const ne=l.useCallback(()=>{n&&o(n)},[o,n]),fe=l.useCallback(()=>{n&&a(n)},[n,a]),xe=l.useCallback(I=>{I.key==="Escape"&&(eh(I.target)||(I.preventDefault(),I.stopPropagation(),ne()))},[ne]);l.useEffect(()=>{if(!(!n||!C)&&C.mode==="file"&&C.targetPath){f(n,C.targetPath,{allowOutsideRoot:!0});return}},[C,n,f]);const Te=C?.mode==="chat"?C.id:null,be=C?.mode==="chat"?Xo(C.dedupeKey):null;l.useEffect(()=>{if(!k||!n||!be||typeof window>"u")return;const I=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){Hi(n,be,!1);return}Qd(be),Hi(n,be,!0)};I();const ue=window.setInterval(I,1e4);return window.addEventListener("focus",I),window.addEventListener("blur",I),document.addEventListener("visibilitychange",I),()=>{window.clearInterval(ue),window.removeEventListener("focus",I),window.removeEventListener("blur",I),document.removeEventListener("visibilitychange",I),Hi(n,be,!1)}},[be,n,k]);const De=l.useCallback((I,ue,ke)=>pg(oe.current,I,ue,n||null,ke,{mode:p,lightThemeId:y,darkThemeId:v,currentTheme:j}),[j,v,n,y,p]);l.useEffect(()=>{const I=new Set(N.map(ue=>ue.id));for(const ue of oe.current.keys())I.has(ue)||oe.current.delete(ue)},[N]);const Ee=l.useCallback(I=>{!n||C?.mode!=="diff"||c(n,{mode:"diff",targetPath:C.targetPath,stagedDiff:I==="staged",diffScope:I})},[C,n,c]),Re=l.useCallback(()=>{if(typeof window>"u")return;const I={themeMode:p,lightThemeId:y,darkThemeId:v,currentTheme:j};for(const ue of le.current.values()){const ke=ue.contentWindow;ke&&ke.postMessage({type:"openchamber:theme-sync",payload:I},window.location.origin)}},[j,v,y,p]),de=l.useCallback(()=>{if(typeof window>"u")return;const I={allowPromptingSubagentSessions:S};for(const ue of le.current.values()){const ke=ue.contentWindow;ke&&ke.postMessage({type:"openchamber:chat-settings-sync",payload:I},window.location.origin)}},[S]),H=l.useCallback(()=>{if(!(typeof window>"u"))for(const[I,ue]of le.current.entries()){const ke=ue.contentWindow;if(!ke)continue;const we={visible:Te===I};ke.postMessage({type:"openchamber:embedded-visibility",payload:we},window.location.origin)}},[Te]);l.useEffect(()=>{if(typeof window>"u")return;const I=ue=>{if(ue.origin!==window.location.origin||!Array.from(le.current.values()).some(rt=>rt.contentWindow===ue.source))return;const we=ue.data;if(we?.type===gg){if(typeof we.requestId!="string"||!we.requestId)return;const rt=Tn(),ot={apiBaseUrl:cr(),clientToken:ri(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:im(),relayHostId:rt.startsWith("host:")?rt.slice(5):"",relay:om()??void 0};ue.source?.postMessage({type:xg,requestId:we.requestId,payload:ot},ue.origin);return}if(we?.type==="openchamber:theme-sync-request"){Re();return}if(we?.type==="openchamber:chat-settings-request"){de();return}if(we?.type!=="openchamber:cycle-theme-request")return;const qe=["light","dark","system"],st=(qe.indexOf(p)+1)%qe.length;h(qe[st])};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[de,Re,h,p]),l.useLayoutEffect(()=>{N.some(ue=>ue.mode==="chat")&&(Re(),de(),H())},[v,y,de,H,Re,N,p]);const Ne=C?.mode==="file"||C?.mode==="chat"||C?.mode==="preview",he=l.useMemo(()=>C?N.filter(I=>I.mode===C.mode):[],[C,N]),ve=l.useMemo(()=>he.map(I=>{const ue=Fy(I,K,t),ke=Vy(ue,Iy),we=Ry(I.targetPath,e);return{id:I.id,label:ke,icon:Ic(I),title:we?`${ue}: ${we}`:ue,closeLabel:t("contextPanel.tab.closeTabAria",{label:ke})}}),[he,e,K,t]),se=C?.mode==="context"?s.jsx(Hb,{}):C?.mode==="git"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(Cy,{isActive:k})}):C?.mode==="pr"?s.jsx(nb,{}):C?.mode==="notes"?s.jsx(yu,{}):C?.mode==="plan"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(Ny,{targetPath:C.targetPath})}):C?.mode==="preview"?s.jsx(Ky,{rawUrl:C.targetPath??"",onNavigate:I=>g(e,I)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(T,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),Q=l.useMemo(()=>N.filter(I=>I.mode==="chat"),[N]),ye=l.useMemo(()=>N.filter(I=>I.mode==="browser"),[N]),re=l.useMemo(()=>N.filter(I=>I.mode==="diff"),[N]),R=l.useMemo(()=>N.some(I=>I.mode==="terminal"),[N]),ce=l.useMemo(()=>N.some(I=>I.mode==="walkthrough"),[N]),Me=Gy()?Yy:qy,ge=l.useMemo(()=>N.some(I=>I.mode==="file"),[N]),te=l.useMemo(()=>N.some(I=>I.mode==="file"&&I.targetPath),[N]),ae=C?.mode==="file",ie=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[Ne?s.jsx(Xa,{items:ve,activeId:C?.id??null,onSelect:I=>{n&&u(n,I)},onClose:I=>{n&&i(n,I)},onReorder:(I,ue)=>{n&&m(n,I,ue)},layoutMode:"scrollable",variant:"default"}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[C?Ic(C):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:C?Zu(C.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[ae?s.jsx(et,{type:"button",variant:"ghost",size:"sm",onClick:w,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":x,children:s.jsx(T,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(et,{type:"button",variant:"ghost",size:"sm",onClick:fe,className:"h-7 w-7 p-0",title:t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:D?s.jsx(T,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",onClick:ne,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})})]})]}),E=k?D?{"--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":`${W}px`}:{"--oc-context-panel-width":`${W}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:ee,"data-context-panel":"true",tabIndex:-1,inert:!k||void 0,className:Ce("flex min-h-0 flex-col overflow-hidden bg-background",D?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!k&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:xe,style:E,children:[k&&!D&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),k&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!D&&s.jsx("div",{className:Ce("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",b&&"bg-[var(--interactive-border)]"),onPointerDown:z,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:Ce("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]",!k&&"pointer-events-none select-none opacity-0"),style:{width:D?M!==null?`${M}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!k,children:[ie,s.jsxs("div",{className:Ce("relative min-h-0 flex-1 overflow-hidden",b&&"pointer-events-none"),children:[ge?s.jsxs("div",{className:Ce("absolute inset-0 flex",ae?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:te?s.jsx(l.Suspense,{fallback:null,children:s.jsx(ky,{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(T,{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(_y,{visible:x})]}):null,Q.map(I=>{const ue=Xo(I.dedupeKey);if(!ue)return null;const ke=De(I.id,ue,I.readOnly);return ke?s.jsx("iframe",{ref:we=>{if(!we){le.current.delete(I.id);return}le.current.set(I.id,we)},src:ke,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ue}),className:Ce("absolute inset-0 h-full w-full border-0 bg-background",Te===I.id?"block":"hidden"),onLoad:()=>{Re(),de(),H()}},I.id):null}),ye.map(I=>s.jsx("div",{className:Ce("absolute inset-0",C?.id!==I.id&&"hidden"),children:s.jsx(Me,{initialUrl:I.targetPath??"",directory:n,tabID:I.id})},I.id)),re.map(I=>s.jsx("div",{className:Ce("absolute inset-0",C?.id!==I.id&&"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(jy,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:I.diffScope??(I.stagedDiff?"staged":"working"),onDiffScopeChange:Ee,targetFilePath:I.targetPath,flushContent:!0})})},I.id)),R?s.jsx("div",{className:Ce("absolute inset-0",C?.mode==="terminal"?"block":"hidden"),children:s.jsx(wu,{visible:k&&C?.mode==="terminal"})}):null,ce?s.jsx("div",{className:Ce("absolute inset-0",C?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sy,{directory:e})})}):null,C?.mode!=="chat"&&!ae&&C?.mode!=="browser"&&C?.mode!=="diff"&&C?.mode!=="terminal"&&C?.mode!=="walkthrough"?se:null]})]})]})},Xy=150,Jy=500,Zy=[],ew=t=>t>99?"99+":String(t),tw=t=>{const e=tt.c(51),{surface:n,isActive:r,showActivityDot:o,label:i,description:c,badgeCount:a,badgeAriaLabel:d,badgeDescription:u,orderNumber:m,showOrderNumber:f,onSelect:g}=t;let x;e[0]!==n.id?(x={id:n.id},e[0]=n.id,e[1]=x):x=e[1];const{attributes:w,listeners:S,setNodeRef:p,transform:h,transition:y,isDragging:v}=Za(x);let j;e[2]!==a?(j=a!=null&&a>0?ew(a):null,e[2]=a,e[3]=j):j=e[3];const N=j;let C;e[4]!==h?(C=el.Translate.toString(h),e[4]=h,e[5]=C):C=e[5];let k;e[6]!==C||e[7]!==y?(k={transform:C,transition:y},e[6]=C,e[7]=y,e[8]=k):k=e[8];const D=v&&"z-10 opacity-70";let M;e[9]!==D?(M=Ce("relative",D),e[9]=D,e[10]=M):M=e[10];let A;e[11]!==g||e[12]!==n?(A=()=>g(n),e[11]=g,e[12]=n,e[13]=A):A=e[13];const _=d??i,L=r?"text-primary":"text-muted-foreground hover:text-foreground";let F;e[14]!==L?(F=Ce("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",L),e[14]=L,e[15]=F):F=e[15];let $;e[16]!==n.icon||e[17]!==n.id?($=n.id==="diff"?s.jsx(Au,{}):s.jsx(T,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=$):$=e[18];let W;e[19]!==N||e[20]!==m||e[21]!==o||e[22]!==f?(W=f&&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}):o?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[19]=N,e[20]=m,e[21]=o,e[22]=f,e[23]=W):W=e[23];let U;e[24]!==w||e[25]!==r||e[26]!==S||e[27]!==F||e[28]!==$||e[29]!==W||e[30]!==A||e[31]!==_?(U=s.jsx(ft,{asChild:!0,children:s.jsxs("button",{type:"button",...w,...S,onClick:A,"aria-label":_,"aria-pressed":r,className:F,children:[$,W]})}),e[24]=w,e[25]=r,e[26]=S,e[27]=F,e[28]=$,e[29]=W,e[30]=A,e[31]=_,e[32]=U):U=e[32];let K;e[33]!==i?(K=s.jsx("span",{children:i}),e[33]=i,e[34]=K):K=e[34];let b;e[35]!==c?(b=s.jsx("span",{className:"typography-micro text-muted-foreground",children:c}),e[35]=c,e[36]=b):b=e[36];let P;e[37]!==u?(P=u?s.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null,e[37]=u,e[38]=P):P=e[38];let V;e[39]!==K||e[40]!==b||e[41]!==P?(V=s.jsx(mt,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[K,b,P]})}),e[39]=K,e[40]=b,e[41]=P,e[42]=V):V=e[42];let G;e[43]!==U||e[44]!==V?(G=s.jsxs(ut,{delayDuration:Xy,children:[U,V]}),e[43]=U,e[44]=V,e[45]=G):G=e[45];let X;return e[46]!==p||e[47]!==G||e[48]!==k||e[49]!==M?(X=s.jsx("div",{ref:p,style:k,className:M,children:G}),e[46]=p,e[47]=G,e[48]=k,e[49]=M,e[50]=X):X=e[50],X},sw=()=>{const t=tt.c(52),{t:e}=gt(),n=Yr();let r;t[0]!==n?(r=n?Br(n):"",t[0]=n,t[1]=r):r=t[1];const o=r;let i;t[2]!==o?(i=J=>o?J.contextPanelByDirectory[o]:void 0,t[2]=o,t[3]=i):i=t[3];const c=pe(i),a=pe(nw),d=pe(rw),u=pe(ow),m=pe(iw),f=pe(aw),g=_a(lw),{screenWidth:x}=fr(),w=$a(o||null);let S;t[4]!==f?(S=sh("switch_context_surface",f),t[4]=f,t[5]=S):S=t[5];const p=S,[h,y]=l.useState(!1);let v,j;t[6]!==p?(v=()=>{const J=new Set;let ee=null,le=!1;const oe=cw,Ae=()=>{Fl(p,J)?!le&&ee===null&&(ee=setTimeout(()=>y(!0),Jy)):(le=!1,ee!==null&&(clearTimeout(ee),ee=null),y(!1))},Se=me=>{if(J.add(me.key.toLowerCase()),oe(me.key)&&Fl(p,J)){le=!0,ee!==null&&(clearTimeout(ee),ee=null),y(!1);return}Ae()},Y=me=>{J.delete(me.key.toLowerCase()),Ae()},je=()=>{J.clear(),le=!1,ee!==null&&(clearTimeout(ee),ee=null),y(!1)};return window.addEventListener("keydown",Se,!0),window.addEventListener("keyup",Y,!0),window.addEventListener("blur",je),()=>{window.removeEventListener("keydown",Se,!0),window.removeEventListener("keyup",Y,!0),window.removeEventListener("blur",je),ee!==null&&clearTimeout(ee)}},j=[p],t[6]=p,t[7]=v,t[8]=j):(v=t[7],j=t[8]),l.useEffect(v,j);let N;t[9]===Symbol.for("react.memo_cache_sentinel")?(N={activationConstraint:{distance:8}},t[9]=N):N=t[9];let C;t[10]===Symbol.for("react.memo_cache_sentinel")?(C={activationConstraint:{delay:200,tolerance:6}},t[10]=C):C=t[10];const k=ui(Wr(wg,N),Wr(yg,C)),D=c?.tabs??Zy;let M;t[11]!==c?.activeTabId||t[12]!==D?(M=D.find(J=>J.id===c?.activeTabId)??null,t[11]=c?.activeTabId,t[12]=D,t[13]=M):M=t[13];const A=M,_=c?.isOpen?A?.mode??null:null,L=w?.files.length??0;let F;t[14]!==d||t[15]!==g||t[16]!==x||t[17]!==D?(F=nh({railOrder:d,planModeEnabled:g,isVSCode:er(),screenWidth:x,tabs:D}),t[14]=d,t[15]=g,t[16]=x,t[17]=D,t[18]=F):F=t[18];const $=F;let W;t[19]!==u?(W=J=>{const{active:ee,over:le}=J;if(!le||ee.id===le.id)return;const oe=rh(pe.getState().contextRailOrder).map(dw),Ae=oe.indexOf(ee.id),Se=oe.indexOf(le.id);Ae===-1||Se===-1||u(Cu(oe,Ae,Se))},t[19]=u,t[20]=W):W=t[20];const U=W;if(!o)return null;let K;t[21]!==e?(K=e("contextRail.aria.rail"),t[21]=e,t[22]=K):K=t[22];let b;t[23]!==$?(b=$.map(uw),t[23]=$,t[24]=b):b=t[24];let P;if(t[25]!==_||t[26]!==L||t[27]!==o||t[28]!==m||t[29]!==h||t[30]!==$||t[31]!==e||t[32]!==a){let J;t[34]!==_||t[35]!==L||t[36]!==o||t[37]!==m||t[38]!==h||t[39]!==e||t[40]!==a?(J=(ee,le)=>{const oe=e(ee.labelKey),Ae=ee.id==="git"&&!a?L:0,Se=Ae>0?Ae:null;return s.jsx(tw,{surface:ee,isActive:_===ee.mode,showActivityDot:!1,label:oe,description:e(ee.descriptionKey),badgeCount:Se,badgeAriaLabel:Se!==null?e(Se===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:oe,count:Se}):null,badgeDescription:Se!==null?e(Se===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:Se}):null,orderNumber:le+1,showOrderNumber:h,onSelect:Y=>m(o,Y.mode)},ee.id)},t[34]=_,t[35]=L,t[36]=o,t[37]=m,t[38]=h,t[39]=e,t[40]=a,t[41]=J):J=t[41],P=$.map(J),t[25]=_,t[26]=L,t[27]=o,t[28]=m,t[29]=h,t[30]=$,t[31]=e,t[32]=a,t[33]=P}else P=t[33];let V;t[42]!==b||t[43]!==P?(V=s.jsx(Sa,{items:b,strategy:ja,children:P}),t[42]=b,t[43]=P,t[44]=V):V=t[44];let G;t[45]!==U||t[46]!==k||t[47]!==V?(G=s.jsx(fi,{sensors:k,collisionDetection:mi,onDragEnd:U,children:V}),t[45]=U,t[46]=k,t[47]=V,t[48]=G):G=t[48];let X;return t[49]!==K||t[50]!==G?(X=s.jsx("nav",{"aria-label":K,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:G}),t[49]=K,t[50]=G,t[51]=X):X=t[51],X};function nw(t){return t.workStatusPanelVisible}function rw(t){return t.contextRailOrder}function ow(t){return t.setContextRailOrder}function iw(t){return t.openContextSurface}function aw(t){return t.shortcutOverrides}function lw(t){return t.planModeEnabled}function cw(t){return t.length===1&&t>="0"&&t<="9"}function dw(t){return t.id}function uw(t){return t.id}const fw=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),mw=(t,e,n,r)=>!n||r!==n||t.length===0?[]:lo(t,e,o=>o.name,{limit:10,threshold:.4}),hw=new Set,pw=[],Aa=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},gw=()=>{const t=tt.c(178),{t:e}=gt(),n=pe(xw),r=pe(bw),o=pe(yw),i=pe(ww),c=pe(vw),a=pe(Sw),d=pe(jw),u=pe(kw),m=pe(Cw),f=pe(Nw),g=pe(Aw),x=Ge(Dw),w=Ge(Pw);let S;t[0]!==n?(S=Xe=>n?Xe.activeSessions:pw,t[0]=n,t[1]=S):S=t[1];const p=Ms(S);let h;t[2]!==n?(h=Xe=>n?Xe.ids:hw,t[2]=n,t[3]=h):h=t[3];const y=xo(h);let v;t[4]!==n?(v=Xe=>n?Xe.rankById:Ka,t[4]=n,t[5]=v):v=t[5];const j=Ai(v),N=cs(Iw),C=Yt(Tw),k=Yt(Ew),D=Yr(),M=Rd(Mw),{files:A,git:_}=tr(),L=dr(Rw),{isMobile:F}=fr();let $;t[6]!==D?($=D?Aa(D):null,t[6]=D,t[7]=$):$=t[7];const W=$,[U,K]=l.useState(""),P=Ua(U,200).trim();let V;t[8]!==U?(V=U.trim(),t[8]=U,t[9]=V):V=t[9];const G=V;let X,J;t[10]!==n?(X=()=>{n&&K("")},J=[n],t[10]=n,t[11]=X,t[12]=J):(X=t[11],J=t[12]),l.useEffect(X,J);let ee,le;t[13]!==p||t[14]!==L||t[15]!==_||t[16]!==n?(ee=()=>{if(!n||!_)return;const Xe=setTimeout(()=>{const _e=new Set;for(const yt of p){const zt=Gs(yt);!zt||_e.has(zt)||(_e.add(zt),L(zt,_))}},0);return()=>clearTimeout(Xe)},le=[n,p,_,L],t[13]=p,t[14]=L,t[15]=_,t[16]=n,t[17]=ee,t[18]=le):(ee=t[17],le=t[18]),l.useEffect(ee,le);let oe;t[19]!==r?(oe=()=>r(!1),t[19]=r,t[20]=oe):oe=t[20];const Ae=oe;let Se;t[21]!==Ae?(Se=Xe=>()=>{Ae(),Xe()},t[21]=Ae,t[22]=Se):Se=t[22];const Y=Se;let je;t[23]!==C?.id||t[24]!==C?.path||t[25]!==N||t[26]!==F||t[27]!==u||t[28]!==m||t[29]!==x||t[30]!==Y||t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==e||t[35]!==d?(je=()=>{const Xe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(T,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:Y(()=>{o("chat"),a(!1),x()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(T,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:Y(Ow)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(T,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:Y(Fw)},{id:"toggle-sidebar",title:e(F?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(T,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(F?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:Y(()=>{if(F){const{isSessionSwitcherOpen:_e}=pe.getState();a(!_e)}else d()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(T,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:Y(()=>{N&&m(N,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(T,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:Y(()=>{N&&u(N)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(T,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:Y(()=>i(!0))}];return wi()&&Xe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(T,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:Y(()=>{Jn("desktop_open_draft_mini_chat_window",{directory:Aa(N||C?.path||""),projectId:C?.id??null}).catch(Bw)})}),Xe},t[23]=C?.id,t[24]=C?.path,t[25]=N,t[26]=F,t[27]=u,t[28]=m,t[29]=x,t[30]=Y,t[31]=o,t[32]=a,t[33]=i,t[34]=e,t[35]=d,t[36]=je):je=t[36],C?.id,C?.path;let me;t[37]!==je?(me=je(),t[37]=je,t[38]=me):me=t[38];const z=me;let Z;t[39]===Symbol.for("react.memo_cache_sentinel")?(Z=_n(),t[39]=Z):Z=t[39];const ne=Z;let fe,xe;t[40]===Symbol.for("react.memo_cache_sentinel")?(fe=er(),xe=!ne&&Ba(),t[40]=fe,t[41]=xe):(fe=t[40],xe=t[41]);let Te;t[42]!==F?(Te={isVSCode:fe,isWeb:xe,isDesktop:ne,isMobile:F},t[42]=F,t[43]=Te):Te=t[43];const be=Te;let De;if(t[44]!==Y||t[45]!==i||t[46]!==c||t[47]!==be){let Xe;t[49]!==be?(Xe=yt=>yt.isAvailable?yt.isAvailable(be):!0,t[49]=be,t[50]=Xe):Xe=t[50];let _e;t[51]!==Y||t[52]!==i||t[53]!==c?(_e=yt=>{const zt=qp(yt.slug)??"settings-3",Bt=(yt.keywords??[]).join(" ");return{id:`settings:${yt.slug}`,title:yt.title,icon:yt.slug==="mcp"?s.jsx(Ud,{className:"mr-2 h-4 w-4"}):s.jsx(T,{name:zt,className:"mr-2 h-4 w-4"}),searchText:`${yt.title} ${yt.group} ${Bt}`,onSelect:Y(()=>{c(yt.slug),i(!0)})}},t[51]=Y,t[52]=i,t[53]=c,t[54]=_e):_e=t[54],De=Gp.filter(Lw).filter(Xe).map(_e),t[44]=Y,t[45]=i,t[46]=c,t[47]=be,t[48]=De}else De=t[48];const Ee=De;let Re;t[55]!==p||t[56]!==y||t[57]!==j?(Re=Xd(p,y,j),t[55]=p,t[56]=y,t[57]=j,t[58]=Re):Re=t[58];const de=Re,H=Jd(),Ne=Ge(_w);let he;t[59]!==H||t[60]!==Ne?(he=(Xe,_e)=>{const yt=Ne.get(Xe);return yt?.branch?yt.branch.trim()||null:_e&&H.get(_e)?.trim()||null},t[59]=H,t[60]=Ne,t[61]=he):he=t[61];const ve=he;let se;t[62]===Symbol.for("react.memo_cache_sentinel")?(se=[],t[62]=se):se=t[62];const[Q,ye]=l.useState(se),[re,R]=l.useState(""),ce=fw(W,P);let Me;t[63]!==W||t[64]!==ce||t[65]!==n||t[66]!==M||t[67]!==ye||t[68]!==R||t[69]!==P?(Me=()=>{if(!n){ye([]),R("");return}if(!ce){ye([]),R("");return}if(!W){ye([]),R("");return}let Xe=!1;return M(W,P,10,{type:"file"}).then(_e=>{Xe||(ye(_e.map($w)),R(ce))}).catch(()=>{Xe||(ye([]),R(ce))}),()=>{Xe=!0}},t[63]=W,t[64]=ce,t[65]=n,t[66]=M,t[67]=ye,t[68]=R,t[69]=P,t[70]=Me):Me=t[70];let ge;t[71]!==W||t[72]!==ce||t[73]!==n||t[74]!==M||t[75]!==P?(ge=[n,W,P,ce,M],t[71]=W,t[72]=ce,t[73]=n,t[74]=M,t[75]=P,t[76]=ge):ge=t[76],l.useEffect(Me,ge);const te=G.length>0;let ae;e:{if(!te){let _e;t[77]!==z?(_e=z.map(zw),t[77]=z,t[78]=_e):_e=t[78],ae=_e;break e}let Xe;t[79]!==z||t[80]!==G?(Xe=lo(z,G,Ww,{limit:7,noFuzzy:!0}),t[79]=z,t[80]=G,t[81]=Xe):Xe=t[81],ae=Xe}const ie=ae;let E;e:{if(!te){let _e;t[82]===Symbol.for("react.memo_cache_sentinel")?(_e=[],t[82]=_e):_e=t[82],E=_e;break e}let Xe;t[83]!==G||t[84]!==Ee?(Xe=lo(Ee,G,Uw,{limit:7,noFuzzy:!0}),t[83]=G,t[84]=Ee,t[85]=Xe):Xe=t[85],E=Xe}const I=E;let ue;e:{if(!te){let _e;t[86]!==de?(_e=de.slice(0,5).map(Vw),t[86]=de,t[87]=_e):_e=t[87],ue=_e;break e}let Xe;t[88]!==G||t[89]!==de?(Xe=lo(de,G,Hw,{limit:7,threshold:.2}),t[88]=G,t[89]=de,t[90]=Xe):Xe=t[90],ue=Xe}const ke=ue;let we;e:{if(!n){let _e;t[91]===Symbol.for("react.memo_cache_sentinel")?(_e=[],t[91]=_e):_e=t[91],we=_e;break e}let Xe;t[92]!==Q||t[93]!==re||t[94]!==ce||t[95]!==P?(Xe=mw(Q,P,ce,re),t[92]=Q,t[93]=re,t[94]=ce,t[95]=P,t[96]=Xe):Xe=t[96],we=Xe}const qe=we,Je=n&&ce.length>0&&re!==ce;let st;e:{if(!te){let _e;t[97]===Symbol.for("react.memo_cache_sentinel")?(_e=[],t[97]=_e):_e=t[97],st=_e;break e}let Xe;if(t[98]!==G||t[99]!==k){const _e=k.map(Kw);Xe=lo(_e,G,Gw,{limit:7,threshold:.4}),t[98]=G,t[99]=k,t[100]=Xe}else Xe=t[100];st=Xe}const rt=st;let ot,lt,kt,nt,it,St,It,Ft,Mt,Ot,Ke,$t,Tt,dt;if(t[101]!==ve||t[102]!==Ae||t[103]!==W||t[104]!==A||t[105]!==te||t[106]!==n||t[107]!==f||t[108]!==x||t[109]!==U||t[110]!==ie||t[111]!==qe||t[112]!==rt||t[113]!==ke||t[114]!==I||t[115]!==r||t[116]!==w||t[117]!==g||t[118]!==e){const Xe=ie.map(qw),_e=I.map(Yw),yt=ke.map(Qw),zt=te?qe.map(Xw):[],Bt=te?rt.map(Jw):[];let Lt;e:{if(!te){Lt=["commands","sessions"];break e}const Be=Zw,We=[{key:"commands",score:Be(ie)},{key:"settings",score:Be(I)},{key:"sessions",score:Be(ke)},{key:"files",score:Be(qe)},{key:"projects",score:Be(rt)}];We.sort(ev),Lt=We.map(tv)}const _t=Lt,Ht=Be=>{Ae(),w(Be.id,Gs(Be))},Dt=async Be=>{if(!W)return;const We=await zu(A,Be,{directory:W});if(!We.ok){Ie.error(Wu(We.reason));return}f(W,Be),Ae()},fs=(Be,We)=>{Ae(),x({selectedProjectId:Be,directoryOverride:We})},Kt=Be=>ji(Ar(Be,g));nt=qs,$t=n,Tt=r;let Nt;t[133]!==e?(Nt=e("commandPalette.title"),t[133]=e,t[134]=Nt):Nt=t[134];let Zt;t[135]!==Nt?(Zt=s.jsx(wn,{children:Nt}),t[135]=Nt,t[136]=Zt):Zt=t[136];let ss;t[137]!==e?(ss=e("commandPalette.description"),t[137]=e,t[138]=ss):ss=t[138];let Oe;t[139]!==ss?(Oe=s.jsx(vn,{children:ss}),t[139]=ss,t[140]=Oe):Oe=t[140],t[141]!==Zt||t[142]!==Oe?(dt=s.jsxs(En,{className:"sr-only",children:[Zt,Oe]}),t[141]=Zt,t[142]=Oe,t[143]=dt):dt=t[143],kt=Ys,Ot="overflow-hidden p-0",Ke=!0,lt=ah,It=!1,Ft="[&_[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 Ue;t[144]!==e?(Ue=e("commandPalette.input.placeholder"),t[144]=e,t[145]=Ue):Ue=t[145],t[146]!==U||t[147]!==Ue?(Mt=s.jsx(lh,{value:U,onValueChange:K,placeholder:Ue}),t[146]=U,t[147]=Ue,t[148]=Mt):Mt=t[148],ot=ch;let Ve;t[149]!==e?(Ve=e("commandPalette.empty.noResults"),t[149]=e,t[150]=Ve):Ve=t[150],t[151]!==Ve?(it=s.jsx(dh,{children:Ve}),t[151]=Ve,t[152]=it):it=t[152],St=_t.map(Be=>Be==="commands"&&Xe.length>0?s.jsx(no,{children:Xe.map(We=>s.jsxs(co,{value:We.id,onSelect:We.onSelect,children:[We.icon,s.jsx("span",{children:We.title}),We.shortcutId?s.jsx(oh,{children:Kt(We.shortcutId)}):null]},We.id))},"commands"):Be==="settings"&&_e.length>0?s.jsx(no,{children:_e.map(sv)},"settings"):Be==="sessions"&&yt.length>0?s.jsx(no,{children:yt.map(We=>{const wt=We.title||e("commandPalette.session.untitled"),os=Gs(We),xt=ve(We.id,os);return s.jsxs(co,{value:`session:${We.id}`,onSelect:()=>Ht(We),children:[s.jsx(T,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:wt}),xt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:xt})]}):null]},We.id)})},"sessions"):Be==="files"&&zt.length>0?s.jsx(no,{children:zt.map(We=>{const wt=ih(We.relativePath||We.name,{maxLength:80});return s.jsxs(co,{value:`file:${We.path}`,onSelect:()=>{Dt(We.path)},children:[s.jsx(Wa,{filePath:We.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":We.relativePath,children:wt})]},`file:${We.path}`)})},"files"):Be==="projects"&&Bt.length>0?s.jsx(no,{children:Bt.map(We=>{const wt=We.displayName;return s.jsxs(co,{value:`project:${We.id}`,onSelect:()=>fs(We.id,We.path),children:[s.jsx(T,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:wt}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:We.path})]},`project:${We.id}`)})},"projects"):null),t[101]=ve,t[102]=Ae,t[103]=W,t[104]=A,t[105]=te,t[106]=n,t[107]=f,t[108]=x,t[109]=U,t[110]=ie,t[111]=qe,t[112]=rt,t[113]=ke,t[114]=I,t[115]=r,t[116]=w,t[117]=g,t[118]=e,t[119]=ot,t[120]=lt,t[121]=kt,t[122]=nt,t[123]=it,t[124]=St,t[125]=It,t[126]=Ft,t[127]=Mt,t[128]=Ot,t[129]=Ke,t[130]=$t,t[131]=Tt,t[132]=dt}else ot=t[119],lt=t[120],kt=t[121],nt=t[122],it=t[123],St=t[124],It=t[125],Ft=t[126],Mt=t[127],Ot=t[128],Ke=t[129],$t=t[130],Tt=t[131],dt=t[132];let Ct;t[153]!==Je||t[154]!==e?(Ct=Je?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[153]=Je,t[154]=e,t[155]=Ct):Ct=t[155];let Rt;t[156]!==ot||t[157]!==it||t[158]!==St||t[159]!==Ct?(Rt=s.jsxs(ot,{children:[it,St,Ct]}),t[156]=ot,t[157]=it,t[158]=St,t[159]=Ct,t[160]=Rt):Rt=t[160];let Qt;t[161]!==lt||t[162]!==It||t[163]!==Ft||t[164]!==Mt||t[165]!==Rt?(Qt=s.jsxs(lt,{shouldFilter:It,className:Ft,children:[Mt,Rt]}),t[161]=lt,t[162]=It,t[163]=Ft,t[164]=Mt,t[165]=Rt,t[166]=Qt):Qt=t[166];let Qe;t[167]!==kt||t[168]!==Ot||t[169]!==Ke||t[170]!==Qt?(Qe=s.jsx(kt,{className:Ot,showCloseButton:Ke,children:Qt}),t[167]=kt,t[168]=Ot,t[169]=Ke,t[170]=Qt,t[171]=Qe):Qe=t[171];let ht;return t[172]!==nt||t[173]!==$t||t[174]!==Tt||t[175]!==dt||t[176]!==Qe?(ht=s.jsxs(nt,{open:$t,onOpenChange:Tt,children:[dt,Qe]}),t[172]=nt,t[173]=$t,t[174]=Tt,t[175]=dt,t[176]=Qe,t[177]=ht):ht=t[177],ht};function xw(t){return t.isCommandPaletteOpen}function bw(t){return t.setCommandPaletteOpen}function yw(t){return t.setActiveMainTab}function ww(t){return t.setSettingsDialogOpen}function vw(t){return t.setSettingsPage}function Sw(t){return t.setSessionSwitcherOpen}function jw(t){return t.toggleSidebar}function kw(t){return t.openContextOverview}function Cw(t){return t.openContextSurface}function Nw(t){return t.openContextFile}function Aw(t){return t.shortcutOverrides}function Dw(t){return t.openNewSessionDraft}function Pw(t){return t.setCurrentSession}function Iw(t){return t.currentDirectory}function Tw(t){return t.getActiveProject()}function Ew(t){return t.projects}function Mw(t){return t.searchFiles}function Rw(t){return t.ensureStatus}function Ow(){Zd()}function Fw(){Ln.requestDirectoryDialog()}function Bw(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function Lw(t){return t.slug!=="home"}function _w(t){return t.worktreeMetadata}function $w(t){return{path:Aa(t.path),name:t.name,relativePath:t.relativePath}}function zw(t){return{item:t,score:0}}function Ww(t){return t.searchText}function Uw(t){return t.searchText}function Vw(t){return{item:t,score:0}}function Hw(t){return t.title||""}function Kw(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function Gw(t){return t.searchText}function qw(t){return t.item}function Yw(t){return t.item}function Qw(t){return t.item}function Xw(t){return t.item}function Jw(t){return t.item}function Zw(t){return t.length?t[0].score:1/0}function ev(t,e){return t.score-e.score}function tv(t){return t.key}function sv(t){return s.jsxs(co,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Rc=(t,e,n)=>fh(t)?ji(Ar(t,n)):e,nv=()=>{const t=tt.c(69),{t:e}=gt(),n=pe(rv),r=pe(ov),o=pe(iv);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=uh(),t[0]=i):i=t[0];const c=i;let a;t[1]===Symbol.for("react.memo_cache_sentinel")?(a=er(),t[1]=a):a=t[1];const d=a;let u,m,f,g,x,w,S,p,h;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const K=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""},{keys:[`${c} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",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:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];m=qs,p=n,h=r,u=Ys,w="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let b;t[15]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(T,{name:"command",className:"h-5 w-5"}),t[15]=b):b=t[15];let P;t[16]!==e?(P=e("helpDialog.title"),t[16]=e,t[17]=P):P=t[17];let V;t[18]!==P?(V=s.jsxs(wn,{className:"flex items-center gap-2",children:[b,P]}),t[18]=P,t[19]=V):V=t[19];let G;t[20]!==e?(G=e("helpDialog.description"),t[20]=e,t[21]=G):G=t[21];let X;t[22]!==G?(X=s.jsx(vn,{children:G}),t[22]=G,t[23]=X):X=t[23],t[24]!==V||t[25]!==X?(S=s.jsxs(En,{children:[V,X]}),t[24]=V,t[25]=X,t[26]=S):S=t[26],x="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",g=K.map(J=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(J.categoryKey)}),s.jsx("div",{className:"space-y-1",children:J.items.filter(ee=>!(d&&ee.id==="toggle_prompt_navigator")).map(ee=>{const le=ee.id?Rc(ee.id,Array.isArray(ee.keys)?ee.keys[0]:ee.keys,o):Array.isArray(ee.keys)?ee.keys:ee.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:[ee.icon&&s.jsx(T,{name:ee.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(ee.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(le)?le:[le]).map((oe,Ae)=>s.jsxs(l.Fragment,{children:[Ae>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:oe})]},`${oe}-${Ae}`))})]},ee.id||ee.descriptionKey)})})]},J.categoryKey)),t[2]=n,t[3]=r,t[4]=o,t[5]=e,t[6]=u,t[7]=m,t[8]=f,t[9]=g,t[10]=x,t[11]=w,t[12]=S,t[13]=p,t[14]=h}else u=t[6],m=t[7],f=t[8],g=t[9],x=t[10],w=t[11],S=t[12],p=t[13],h=t[14];let y;t[27]!==f||t[28]!==g?(y=s.jsx("div",{className:f,children:g}),t[27]=f,t[28]=g,t[29]=y):y=t[29];let v;t[30]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(T,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=v):v=t[30];let j;t[31]!==e?(j=e("helpDialog.proTips.title"),t[31]=e,t[32]=j):j=t[32];let N;t[33]!==j?(N=s.jsx("p",{className:"font-medium mb-1",children:j}),t[33]=j,t[34]=N):N=t[34];let C;t[35]!==o||t[36]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:Rc("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=C):C=t[37];let k;t[38]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[38]=C,t[39]=k):k=t[39];let D;t[40]!==e?(D=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=D):D=t[41];let M;t[42]!==D?(M=s.jsxs("li",{children:["• ",D]}),t[42]=D,t[43]=M):M=t[43];let A;t[44]!==e?(A=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=A):A=t[45];let _;t[46]!==A?(_=s.jsxs("li",{children:["• ",A]}),t[46]=A,t[47]=_):_=t[47];let L;t[48]!==k||t[49]!==M||t[50]!==_?(L=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,M,_]}),t[48]=k,t[49]=M,t[50]=_,t[51]=L):L=t[51];let F;t[52]!==N||t[53]!==L?(F=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[v,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[N,L]})]})}),t[52]=N,t[53]=L,t[54]=F):F=t[54];let $;t[55]!==F||t[56]!==x||t[57]!==y?($=s.jsxs("div",{className:x,children:[y,F]}),t[55]=F,t[56]=x,t[57]=y,t[58]=$):$=t[58];let W;t[59]!==u||t[60]!==$||t[61]!==w||t[62]!==S?(W=s.jsxs(u,{className:w,children:[S,$]}),t[59]=u,t[60]=$,t[61]=w,t[62]=S,t[63]=W):W=t[63];let U;return t[64]!==m||t[65]!==W||t[66]!==p||t[67]!==h?(U=s.jsx(m,{open:p,onOpenChange:h,children:W}),t[64]=m,t[65]=W,t[66]=p,t[67]=h,t[68]=U):U=t[68],U};function rv(t){return t.isHelpDialogOpen}function ov(t){return t.setHelpDialogOpen}function iv(t){return t.shortcutOverrides}const av=()=>{const t=tt.c(32),{t:e}=gt(),n=pe(lv),r=pe(cv),o=pe(dv);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await Bn(o)).ok){Ie.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Ie.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;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(wn,{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(vn,{children:u}),t[9]=u,t[10]=m):m=t[10];let f;t[11]!==d||t[12]!==m?(f=s.jsxs(En,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=f):f=t[13];let g;t[14]!==e?(g=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=g):g=t[15];let x;t[16]!==c||t[17]!==g?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:g})}),t[16]=c,t[17]=g,t[18]=x):x=t[18];let w;t[19]!==o||t[20]!==e?(w=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=w):w=t[21];let S;t[22]!==w?(S=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:w}),t[22]=w,t[23]=S):S=t[23];let p;t[24]!==f||t[25]!==x||t[26]!==S?(p=s.jsxs(Ys,{className:"max-w-2xl",children:[f,x,S]}),t[24]=f,t[25]=x,t[26]=S,t[27]=p):p=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==p?(h=s.jsx(qs,{open:n,onOpenChange:r,children:p}),t[28]=n,t[29]=r,t[30]=p,t[31]=h):h=t[31],h};function lv(t){return t.isOpenCodeStatusDialogOpen}function cv(t){return t.setOpenCodeStatusDialogOpen}function dv(t){return t.openCodeStatusText}const uv=180,Oc=600,fv=1,mv=6,hv=t=>{const e=t?.directory;return typeof e=="string"&&e.trim()?e:null},pv=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:o})=>{const i=l.useRef(new Map),c=l.useRef([]),a=l.useRef(new Set),d=l.useRef(0),u=l.useMemo(()=>er(),[]),m=l.useCallback(w=>`${w.directory}
|
|
178
|
-
${w.sessionId}`,[]),f=l.useCallback(()=>{d.current+=1,c.current=[],i.current.forEach(w=>window.clearTimeout(w)),i.current.clear()},[]),g=l.useCallback(()=>{if(!(!t||u||typeof window>"u"))for(;a.current.size<fv&&c.current.length>0;){const w=c.current.shift();if(!w)break;if(w.generation!==d.current||Ge.getState().currentSessionId===w.sessionId||Bl(w.sessionId,w.directory).renderable)continue;const p=m(w);a.current.add(p),o(w.sessionId,w.directory).catch(()=>{}).finally(()=>{a.current.delete(p),g()})}},[t,u,o,m]),x=l.useCallback(w=>{const S=w?.id,p=hv(w);if(!t||u||!S||!p||S===e||typeof window>"u")return;const h={sessionId:S,directory:p,generation:d.current},y=m(h);if(Bl(S,p).renderable||a.current.has(y)||c.current.some(N=>m(N)===y))return;const v=i.current.get(y);v!==void 0&&window.clearTimeout(v);const j=window.setTimeout(()=>{if(i.current.delete(y),h.generation!==d.current)return;const N=c.current;N.length>=mv&&N.shift(),N.push(h),g()},uv);i.current.set(y,j)},[e,t,u,g,m]);l.useEffect(()=>{f()},[f,e,t,u]),l.useEffect(()=>{if(!t||u||!e||n.length===0)return;const w=window.setTimeout(()=>{const S=n.findIndex(p=>p.id===e);S<0||(x(n[S-1]),x(n[S+1]))},Oc);return()=>window.clearTimeout(w)},[e,t,u,x,n]),l.useEffect(()=>{if(!t||u||!e||r.length===0)return;const w=window.setTimeout(()=>{const S=r.findIndex(p=>p.id===e);S<0||(x(r[S-1]),x(r[S+1]))},Oc);return()=>window.clearTimeout(w)},[e,t,u,r,x]),l.useEffect(()=>f,[f])},gv=t=>{const e=tt.c(3),n=Ge(xv);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],pv(r),null};function xv(t){return t.currentSessionId}const bv=t=>{const e=tt.c(12),{normalizedProjects:n,enabled:r,ownership:o,isSessionsLoading:i,hasAuthoritativeGlobalSessions:c,isWorktreeTopologyLoading:a,unresolvedWorktreeProjectPaths:d,foldersMap:u,createFolder:m,addSessionToFolder:f}=t,g=r===void 0?!0:r;let x,w;e[0]!==f||e[1]!==m||e[2]!==g||e[3]!==u||e[4]!==c||e[5]!==i||e[6]!==a||e[7]!==n||e[8]!==o||e[9]!==d?(x=()=>{!g||i||!c||a||n.forEach(S=>{if(d.has(S.normalizedPath))return;const p=eu(S.normalizedPath),h=o.archivedSessionsByProject.get(S.id)??[],y=u[p]??[],v=new Map(y.map(yv));h.forEach(j=>{const N=mh(j,S.normalizedPath),C=N.toLowerCase();let k=v.get(C);k||(k=m(p,N),v.set(C,k)),k.sessionIds.includes(j.id)||f(p,k.id,j.id)})})},w=[n,g,o,i,c,a,d,u,m,f],e[0]=f,e[1]=m,e[2]=g,e[3]=u,e[4]=c,e[5]=i,e[6]=a,e[7]=n,e[8]=o,e[9]=d,e[10]=x,e[11]=w):(x=e[10],w=e[11]),l.useEffect(x,w)};function yv(t){return[t.name.toLowerCase(),t]}const wv=t=>{const e=tt.c(4);let n;e[0]!==t?(n=(i,c)=>{const a=t.get(i);if(!a||a.length===0)return c;const d=new Map(c.map(vv)),u=[];a.forEach(g=>{const x=d.get(g);x&&(u.push(x),d.delete(g))});const m=[],f=[];return c.forEach(g=>{d.has(g.id)&&(g.isArchivedBucket?f.push(g):m.push(g))}),[...m,...u,...f]},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function vv(t){return[t.id,t]}const Sv=[],jv=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:o,projectRepoStatus:i,projectRootBranches:c,lastRepoStatus:a,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,filterSessionNodesForSearch:f,buildGroupSearchText:g,foldersMap:x}=t,w=l.useRef(new Map),S=l.useMemo(()=>{const k=w.current,D=new Map;let M=0,A=0;const _=(F,$)=>F.length===$.length&&F.every((W,U)=>W===$[U]),L=e.map(F=>{const $=n(F.id),W=r(F.id),U=o.get(F.normalizedPath)??Sv,K=i.has(F.id)?!!i.get(F.id):a,b=c.get(F.id)??null,P=k.get(F.id);if(P&&P.project===F&&_(P.activeSessions,$)&&_(P.archivedSessions,W)&&P.availableWorktrees===U&&P.rootBranch===b&&P.isRepo===K&&P.buildGroupedSessions===d)return M+=1,D.set(F.id,P),P.section;A+=1;const V=tu([...$,...W]),G=d(V,F.normalizedPath,U,b,K),X={project:F,groups:G};return D.set(F.id,{project:F,activeSessions:$,archivedSessions:W,availableWorktrees:U,rootBranch:b,isRepo:K,buildGroupedSessions:d,section:X}),X});return w.current=D,M>0&&In("ui.sidebar.project_section.reused",M),A>0&&In("ui.sidebar.project_section.rebuilt",A),L},[e,n,r,o,i,a,d,c]),p=l.useMemo(()=>S,[S]),h=l.useMemo(()=>{const k=new WeakMap;if(!u)return k;const D=M=>M.reduce((A,_)=>A+1+D(_.children),0);return p.forEach(M=>{M.groups.forEach(A=>{const _=f(A.sessions,m),L=D(_),F=g(A).includes(m),$=vt(A.directory??null),U=($?x[$]??[]:[]).filter(K=>K.name.toLowerCase().includes(m)).length;k.set(A,{filteredNodes:_,matchedSessionCount:L,folderNameMatchCount:U,groupMatches:F,hasMatch:F||L>0||U>0})})}),k},[u,p,f,m,g,x]),y=l.useMemo(()=>u?p.map(k=>({...k,groups:k.groups.filter(D=>h.get(D)?.hasMatch===!0)})).filter(k=>k.groups.length>0):p,[u,p,h]),v=u?y:p,j=l.useRef(new WeakMap),N=l.useMemo(()=>{const k=j.current;return v.map(D=>{const M=k.get(D);if(M&&M.query===m)return M.section;const A=D.groups.filter(K=>!K.isArchivedBucket),_=D.groups.filter(K=>K.isArchivedBucket),L=A.flatMap(K=>u?h.get(K)?.filteredNodes??[]:K.sessions),F=A.map(K=>({scopeKey:K.folderScopeKey??vt(K.directory??null),directory:K.directory??null})).filter(K=>!!K.scopeKey),$=A.find(K=>K.isMain)??null,W={id:"flat",label:$?.label??"",branch:$?.branch??null,description:$?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:$?.directory??D.project.normalizedPath,folderScopeKey:$?.folderScopeKey??D.project.normalizedPath,folderScopes:F,sessions:L};if(u){const K=A.map(b=>h.get(b)).filter(b=>!!b);h.set(W,{filteredNodes:L,matchedSessionCount:K.reduce((b,P)=>b+P.matchedSessionCount,0),folderNameMatchCount:K.reduce((b,P)=>b+P.folderNameMatchCount,0),groupMatches:K.some(b=>b.groupMatches),hasMatch:K.some(b=>b.hasMatch)})}const U={project:D.project,groups:[W,..._]};return k.set(D,{query:m,section:U}),U})},[h,u,m,v]),C=l.useMemo(()=>u?v.reduce((k,D)=>k+D.groups.reduce((M,A)=>{const _=h.get(A);if(!_)return M;const L=_.folderNameMatchCount+(_.groupMatches?1:0);return M+_.matchedSessionCount+L},0),0):0,[u,v,h]);return{projectSections:S,visibleProjectSections:p,groupSearchDataByGroup:h,searchableProjectSections:y,sectionsForRender:v,flatSectionsForRender:N,searchMatchCount:C}},kv=t=>{const e=tt.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,handleSessionSelect:a,newSessionDraftOpen:d,mobileVariant:u,openNewSessionDraft:m,setActiveMainTab:f,setSessionSwitcherOpen:g}=t;let x,w;if(e[0]!==n){w=new Map,x=new Map;const C=(k,D,M,A)=>{w.has(k)||w.set(k,new Map);const _=w.get(k);A.forEach(L=>{const F=vt(L.worktree?.path??L.session.directory??M??D);_.set(L.session.id,{directory:F}),x.has(k)||x.set(k,{id:L.session.id,directory:F}),L.children.length>0&&C(k,D,F,L.children)})};n.forEach(k=>{k.groups.forEach(D=>{C(k.project.id,k.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=x,e[2]=w}else x=e[1],w=e[2];let S;e[3]!==x||e[4]!==w?(S={metaByProject:w,firstSessionByProject:x},e[3]=x,e[4]=w,e[5]=S):S=e[5];const p=S,h=l.useRef(null);let y,v;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==a||e[10]!==u||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==p||e[15]!==f||e[16]!==i||e[17]!==g?(y=()=>{if(!r||d||pe.getState().isNewWorktreeDialogOpen||h.current===r)return;const C=n.find(F=>F.project.id===r);if(!C)return;h.current=r;const k=p.metaByProject.get(r);if(c&&k&&k.has(c)){i(F=>{if(F.get(r)===c)return F;const $=new Map(F);return $.set(r,c),$});return}if(c&&k)return;if(!k||k.size===0){f("chat"),u&&g(!1),m({selectedProjectId:C.project.id,directoryOverride:C.project.normalizedPath});return}const D=o.get(r),M=D&&k.has(D)?D:null,A=p.firstSessionByProject.get(r)?.id??null,_=M??A;if(!_||_===c)return;const L=k.get(_)?.directory??null;a(_,L)},v=[r,o,c,a,d,u,m,n,p,f,g,i],e[6]=r,e[7]=o,e[8]=c,e[9]=a,e[10]=u,e[11]=d,e[12]=m,e[13]=n,e[14]=p,e[15]=f,e[16]=i,e[17]=g,e[18]=y,e[19]=v):(y=e[18],v=e[19]),l.useLayoutEffect(y,v);let j,N;e[20]!==r||e[21]!==c||e[22]!==p||e[23]!==i?(j=()=>{if(!r||!c)return;const C=p.metaByProject.get(r);!C||!C.has(c)||i(k=>{if(k.get(r)===c)return k;const D=new Map(k);return D.set(r,c),D})},N=[r,c,p,i],e[20]=r,e[21]=c,e[22]=p,e[23]=i,e[24]=j,e[25]=N):(j=e[24],N=e[25]),l.useEffect(j,N)},Cv=t=>{const e=tt.c(15);let n,r,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);const i=Ge(Nv),c=Ge(Av);let a;e[4]!==r?(a=()=>new Map(r),e[4]=r,e[5]=a):a=e[5];const[d,u]=l.useState(a);let m;e[6]!==d||e[7]!==n||e[8]!==i||e[9]!==c?(m={...n,activeSessionByProject:d,setActiveSessionByProject:u,currentSessionId:i,newSessionDraftOpen:c},e[6]=d,e[7]=n,e[8]=i,e[9]=c,e[10]=m):m=e[10],kv(m);let f,g;return e[11]!==d||e[12]!==o?(f=()=>{o(d)},g=[d,o],e[11]=d,e[12]=o,e[13]=f,e[14]=g):(f=e[13],g=e[14]),l.useEffect(f,g),null};function Nv(t){return t.currentSessionId}function Av(t){return!!t.newSessionDraft?.open}const Da=new Map,Dv=(t,e)=>{for(const n of t){const r=vt(n??null);r&&!Da.has(r)&&Da.set(r,e)}},Fc=t=>{const e=vt(t??null);return e?Da.get(e)??0:0},Bo=t=>!!t.time?.archived,Pv=t=>{const{t:e}=gt(),n=l.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(c=>{const a=vt(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${a}`.toLowerCase()},[e]),o=l.useCallback((c,a)=>a?c.flatMap(d=>{if(r(d.session).includes(a))return[d];const m=o(d.children,a);return m.length===0?[]:[{...d,children:m}]}):c,[r]),i=l.useCallback((c,a,d,u,m)=>{const f=vt(a??null),g=tu(c).sort((L,F)=>qr(L,F,t.pinnedSessionIds,t.sessionOrderRanks)),x=new Map(g.map(L=>[L.id,L])),w=new Map;g.forEach(L=>{const F=L.parentID;if(!F)return;const $=x.get(F);if(!$||Bo($)!==Bo(L))return;const W=w.get(F)??[];W.push(L),w.set(F,W)}),w.forEach(L=>L.sort((F,$)=>qr(F,$,t.pinnedSessionIds,t.sessionOrderRanks)));const S=new Map;d.forEach(L=>{if(L.path){const F=vt(L.path)??L.path;S.set(F,L)}});const p=L=>{const F=vt(L.directory??null),$=t.worktreeMetadata.get(L.id)??null;if($)return $;if(F){const W=S.get(F)??null;if(W&&F!==f)return W}return null},h=L=>{const F=w.get(L.id)??[];return{session:L,children:F.map($=>h($)),worktree:p(L)}},y=g.filter(L=>{const F=L.parentID;if(!F)return!0;const $=x.get(F);return $?Bo($)!==Bo(L):!0}),v=new Map,j="__archived__",N=L=>{if(L.time?.archived)return j;if(t.isVSCode)return f??"__project_root__";const $=vt(t.worktreeMetadata.get(L.id)?.path??null)??Gs(L);return $?$!==f&&S.has($)?$:$===f?f??"__project_root__":j:j};y.forEach(L=>{const F=h(L),$=N(L);v.has($)||v.set($,[]),v.get($)?.push(F)});const C=f??"__project_root__",k=[{id:"root",label:m&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?ii(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:v.get(C)??[]}],D=new Map;d.forEach(L=>{const F=vt(L.path)??L.path,$=v.get(F)??[],W=$.length>0,U=$.reduce((K,b)=>{const P=hh(b.session,t.sessionOrderRanks);return Number.isFinite(P)?Math.max(K,P):K},0);D.set(F,{hasActiveSession:W,lastUpdatedAt:U})});const M=[...d].sort((L,F)=>{const $=vt(L.path)??L.path,W=vt(F.path)??F.path,U=D.get($)??{hasActiveSession:!1,lastUpdatedAt:0},K=D.get(W)??{hasActiveSession:!1,lastUpdatedAt:0};if(U.hasActiveSession!==K.hasActiveSession)return U.hasActiveSession?-1:1;if(U.hasActiveSession&&K.hasActiveSession)return K.lastUpdatedAt-U.lastUpdatedAt;const b=Fc(L.path),P=Fc(F.path);if(b!==P)return P-b;const V=(L.label||L.branch||L.name||L.path||"").toLowerCase(),G=(F.label||F.branch||F.name||F.path||"").toLowerCase();return V.localeCompare(G)});(t.isVSCode?[]:M).forEach(L=>{const F=vt(L.path)??L.path,$=t.gitBranches.get(F)?.trim()||null,W=L.branch?.trim()||null,K=!!($&&W&&L.label&&Ll(L.label)===Ll(W))?$:L.label||L.name||ur(F,t.homeDirectory)||F;k.push({id:`worktree:${F}`,label:K,branch:$||W,description:ii(F,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:L,directory:F,folderScopeKey:F,sessions:v.get(F)??[]})});const _=v.get(j)??[];return _.length>0&&k.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&f?eu(f):null,sessions:_}),k},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},Iv=t=>{const e=tt.c(11),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:o,sessionSearchInputRef:i,sessionSearchContainerRef:c}=t,a=n===void 0?!0:n;let d,u;e[0]!==a||e[1]!==r||e[2]!==i?(d=()=>{if(!a||!r||typeof window>"u")return;const g=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(g)},u=[a,r,i],e[0]=a,e[1]=r,e[2]=i,e[3]=d,e[4]=u):(d=e[3],u=e[4]),l.useEffect(d,u);let m,f;e[5]!==a||e[6]!==r||e[7]!==c||e[8]!==o?(m=()=>{if(!a||!r||typeof document>"u")return;const g=x=>{c.current&&(c.current.contains(x.target)||o(!1))};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},f=[a,r,o,c],e[5]=a,e[6]=r,e[7]=c,e[8]=o,e[9]=m,e[10]=f):(m=e[9],f=e[10]),l.useEffect(m,f)},Tv=t=>{const e=tt.c(50),{t:n}=gt(),[r,o]=l.useState(null),i=l.useRef(null);let c,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},a=[],e[0]=c,e[1]=a):(c=e[0],a=e[1]),l.useEffect(c,a);let d;e[2]!==t?(d=(X,J)=>{fa("navigation.session_select"),pe.getState().closeMainSurfaces();const ee=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),X===Ge.getState().currentSessionId){t.allowReselect&&t.onSessionSelected?.(X),ee();return}fa("navigation.session_state_set"),t.setCurrentSession(X,J??null),t.onSessionSelected?.(X),ee()},e[2]=t,e[3]=d):d=e[3];const u=d;let m;e[4]!==t?(m=(X,J)=>{t.setEditingId(X),t.setEditTitle(J)},e[4]=t,e[5]=m):m=e[5];const f=m;let g;e[6]!==t?(g=async X=>{if(!t.editingId)return;const J=(X??t.editTitle).trim();J&&await t.updateSessionTitle(t.editingId,J),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=g):g=e[7];const x=g;let w;e[8]!==t?(w=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=w):w=e[9];const S=w;let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=async(X,J)=>{try{return(await Bn(X)).ok?(o(J),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{o(null),i.current=null},2e3),!0):!1}catch{return!1}},e[10]=p):p=e[10];const h=p;let y;e[11]!==t||e[12]!==n?(y=async X=>{const J=await t.shareSession(X.id);if(!J?.share?.url){Ie.error(n("sessions.sidebar.session.share.error"));return}const ee=await h(J.share.url,X.id);Ie[ee?"success":"warning"](n("sessions.sidebar.session.share.successTitle"),{description:n(ee?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},e[11]=t,e[12]=n,e[13]=y):y=e[13];const v=y;let j;e[14]!==n?(j=(X,J)=>{h(X,J).then(ee=>{ee||Ie.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[14]=n,e[15]=j):j=e[15];const N=j;let C;e[16]!==n?(C=X=>{Bn(X).then(J=>{if(J.ok){Ie.success(n("sessions.sidebar.session.copyId.success"));return}Ie.error(n("sessions.sidebar.session.copyId.error"))}).catch(()=>Ie.error(n("sessions.sidebar.session.copyId.error")))},e[16]=n,e[17]=C):C=e[17];const k=C;let D;e[18]!==t||e[19]!==n?(D=async X=>{await t.unshareSession(X)?Ie.success(n("sessions.sidebar.session.unshare.success")):Ie.error(n("sessions.sidebar.session.unshare.error"))},e[18]=t,e[19]=n,e[20]=D):D=e[20];const M=D;let A;e[21]!==t.childrenMap?(A=X=>{const J=[],ee=le=>{(t.childrenMap.get(le)??[]).forEach(Ae=>{J.push(Ae),ee(Ae.id)})};return ee(X),J},e[21]=t.childrenMap,e[22]=A):A=e[22];const _=A,L=Mv;let F;e[23]!==t||e[24]!==_||e[25]!==n?(F=async(X,J,ee)=>{const le=J?.archivedBucket===!0||J?.hardDelete===!0,oe=ee?.descendantIds??L(_(X.id),le).map(Rv);if(oe.length===0){(le?await t.deleteSession(X.id):await t.archiveSession(X.id))?Ie.success(n(le?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):Ie.error(n(le?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Ae=[X.id,...oe];if(le){const{deletedIds:je,failedIds:me}=await t.deleteSessions(Ae);if(me.length===0){const z=je.length;Ie.success(z===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:z}):n("sessions.sidebar.bulkActions.deletedPlural",{count:z}))}else Ie.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:Se,failedIds:Y}=await t.archiveSessions(Ae);Se.length>0&&Ie.success(Se.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:Se.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:Se.length})),Y.length>0&&Ie.error(Y.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Y.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Y.length}))},e[23]=t,e[24]=_,e[25]=n,e[26]=F):F=e[26];const $=F;let W;e[27]!==t||e[28]!==_||e[29]!==$?(W=(X,J)=>{const ee=J?.archivedBucket===!0||J?.hardDelete===!0,le=L(_(X.id),ee).map(Ov);if(!t.showDeletionDialog||J?.skipConfirm===!0){$(X,J,{descendantIds:le});return}t.setDeleteSessionConfirm({session:X,descendantCount:le.length,descendantIds:le,archivedBucket:ee})},e[27]=t,e[28]=_,e[29]=$,e[30]=W):W=e[30];const U=W;let K;e[31]!==t||e[32]!==$?(K=async()=>{if(!t.deleteSessionConfirm)return;const{session:X,archivedBucket:J,descendantIds:ee}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await $(X,{archivedBucket:J},{descendantIds:ee})},e[31]=t,e[32]=$,e[33]=K):K=e[33];const b=K;let P;e[34]!==t||e[35]!==n?(P=async X=>{await t.unarchiveSession(X.id)?Ie.success(n("sessions.sidebar.session.restore.success")):Ie.error(n("sessions.sidebar.session.restore.error"))},e[34]=t,e[35]=n,e[36]=P):P=e[36];const V=P;let G;return e[37]!==b||e[38]!==r||e[39]!==S||e[40]!==k||e[41]!==N||e[42]!==U||e[43]!==V||e[44]!==x||e[45]!==f||e[46]!==u||e[47]!==v||e[48]!==M?(G={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:S,handleShareSession:v,handleCopyShareUrl:N,handleCopySessionId:k,handleUnshareSession:M,handleDeleteSession:U,handleRestoreSession:V,confirmDeleteSession:b},e[37]=b,e[38]=r,e[39]=S,e[40]=k,e[41]=N,e[42]=U,e[43]=V,e[44]=x,e[45]=f,e[46]=u,e[47]=v,e[48]=M,e[49]=G):G=e[49],G};function Ev(t){return!t.time?.archived}function Mv(t,e){return e?t:t.filter(Ev)}function Rv(t){return t.id}function Ov(t){return t.id}const Fv=t=>{const e=tt.c(26),{isVSCode:n,safeStorage:r,keys:o,groupOrderByProject:i,collapsedGroups:c,setExpandedParents:a,setCollapsedProjects:d}=t,u=l.useRef(null),m=l.useRef(null);let f;e[0]!==n?(f=()=>{if(n)return;const D=m.current;if(m.current=null,u.current=null,!D)return;const{projects:M}=Yt.getState(),A=M.map(_=>({..._,sidebarCollapsed:D.has(_.id)}));Md({projects:A}).catch(Bv)},e[0]=n,e[1]=f):f=e[1];const g=f;let x;e[2]!==g||e[3]!==n?(x=D=>{typeof window>"u"||n||(m.current=D,u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{g()},700))},e[2]=g,e[3]=n,e[4]=x):x=e[4];const w=x;let S,p;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&u.current!==null&&window.clearTimeout(u.current),u.current=null,m.current=null},p=[],e[5]=S,e[6]=p):(S=e[5],p=e[6]),l.useEffect(S,p);let h,y;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==d||e[11]!==a?(h=()=>{try{const D=r.getItem(o.sessionExpanded);if(D){const A=JSON.parse(D);Array.isArray(A)&&a(new Set(A.filter(Lv)))}const M=r.getItem(o.projectCollapse);if(M){const A=JSON.parse(M);Array.isArray(A)&&d(new Set(A.filter(_v)))}}catch{}},y=[o.projectCollapse,o.sessionExpanded,r,d,a],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=d,e[11]=a,e[12]=h,e[13]=y):(h=e[12],y=e[13]),l.useEffect(h,y);let v,j;e[14]!==i||e[15]!==o.groupOrder||e[16]!==r?(v=()=>{try{const D=Object.fromEntries(i.entries());r.setItem(o.groupOrder,JSON.stringify(D))}catch{}},j=[i,o.groupOrder,r],e[14]=i,e[15]=o.groupOrder,e[16]=r,e[17]=v,e[18]=j):(v=e[17],j=e[18]),l.useEffect(v,j);let N,C;e[19]!==c||e[20]!==o.groupCollapse||e[21]!==r?(N=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(c)))}catch{}},C=[c,o.groupCollapse,r],e[19]=c,e[20]=o.groupCollapse,e[21]=r,e[22]=N,e[23]=C):(N=e[22],C=e[23]),l.useEffect(N,C);let k;return e[24]!==w?(k={scheduleCollapsedProjectsPersist:w},e[24]=w,e[25]=k):k=e[25],k};function Bv(){}function Lv(t){return typeof t=="string"}function _v(t){return typeof t=="string"}const $v=5*6e4,zv=t=>{const e=tt.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:o,setProjectRepoStatus:i,setProjectRootBranches:c}=t,a=r===void 0?!0:r,{git:d}=tr(),u=dr(Wv);let m,f;e[0]!==a||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==i?(m=()=>{if(!a||!d||n.length===0){i(new Map);return}n.forEach(C=>{ga(()=>u(C.normalizedPath,d))})},f=[a,n,d,u,i],e[0]=a,e[1]=u,e[2]=d,e[3]=n,e[4]=i,e[5]=m,e[6]=f):(m=e[5],f=e[6]),l.useEffect(m,f);let g,x;e[7]!==a||e[8]!==o||e[9]!==n||e[10]!==i?(g=()=>{if(!a)return;const C=new Map;n.forEach(k=>{C.set(k.id,o.get(k.normalizedPath)?.isGitRepo??null)}),i(C)},x=[a,n,o,i],e[7]=a,e[8]=o,e[9]=n,e[10]=i,e[11]=g,e[12]=x):(g=e[11],x=e[12]),l.useEffect(g,x);let w;if(e[13]!==o||e[14]!==n){let C;e[16]!==o?(C=k=>{const D=o.get(k.normalizedPath)?.branch??"";return`${k.id}:${D}`},e[16]=o,e[17]=C):C=e[17],w=n.map(C).join("|"),e[13]=o,e[14]=n,e[15]=w}else w=e[15];const S=w;let p;e[18]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[18]=p):p=e[18];const h=l.useRef(p);let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=new Map,e[19]=y):y=e[19];const v=l.useRef(y);let j;e[20]!==a||e[21]!==o||e[22]!==n||e[23]!==c?(j=()=>{if(!a)return;let C=!1;const k=setTimeout(()=>{(async()=>{const M=new Set(n.map(Uv));for(const W of h.current.keys())M.has(W)||(h.current.delete(W),v.current.delete(W));const A=Date.now(),_=n.filter(W=>{const U=o.get(W.normalizedPath);if(U?.isGitRepo===!1)return h.current.delete(W.id),v.current.delete(W.id),!1;if(U?.isGitRepo!==!0||U.branch===null)return!1;const K=U.branch.trim(),b=`${W.normalizedPath}\0${K}`,P=h.current.get(W.id);if(P===b){const V=v.current.get(W.id);return V&&(V.at=A),!1}return!(P!==void 0&&A-(v.current.get(W.id)?.at??0)<$v)});if(_.length===0)return;const L=await ph(_,2,async W=>{const U=o.get(W.normalizedPath)?.branch?.trim()??"",K=`${W.normalizedPath}\0${U}`,b=await ga(()=>Ni(W.normalizedPath,U?{knownBranch:U}:void 0)).catch(Vv);return{id:W.id,inputKey:K,branch:b}});if(C)return;const F=L.filter(Hv);if(F.length===0)return;const $=Date.now();c(W=>{const U=new Map(W);return F.forEach(K=>{const{id:b,branch:P}=K;P&&U.set(b,P)}),U}),F.forEach(W=>{const{id:U,inputKey:K,branch:b}=W;h.current.set(U,K),b&&v.current.set(U,{branch:b,at:$})})})()},150);return()=>{C=!0,clearTimeout(k)}},e[20]=a,e[21]=o,e[22]=n,e[23]=c,e[24]=j):j=e[24];let N;e[25]!==a||e[26]!==o||e[27]!==n||e[28]!==S||e[29]!==c?(N=[a,n,S,o,c],e[25]=a,e[26]=o,e[27]=n,e[28]=S,e[29]=c,e[30]=N):N=e[30],l.useEffect(j,N)};function Wv(t){return t.ensureStatus}function Uv(t){return t.id}function Vv(){return null}function Hv(t){return t.branch}const Kv=t=>{const e=tt.c(7),{ownership:n}=t;let r;e[0]!==n?(r=d=>n.sessionsByProject.get(d)??[],e[0]=n,e[1]=r):r=e[1];const o=r;let i;e[2]!==n?(i=d=>n.archivedSessionsByProject.get(d)??[],e[2]=n,e[3]=i):i=e[3];const c=i;let a;return e[4]!==c||e[5]!==o?(a={getSessionsForProject:o,getArchivedSessionsForProject:c},e[4]=c,e[5]=o,e[6]=a):a=e[6],a},Gv=t=>{const e=new Map;for(const n of t){const r=Gs(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},qv=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,o)=>{e.has(o)||n.push(r)}),n},Yv=t=>{const e=tt.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:o}=t,i=n===void 0?!0:n,c=l.useRef(null);let a,d;e[0]!==i||e[1]!==r||e[2]!==o?(a=()=>{if(!i||!r)return;const u=Tn(),m=Gv(o),f=c.current?.runtimeKey===u?c.current.identities:null;for(const g of qv(f,m))gh({runtimeKey:u,...g});c.current={runtimeKey:u,identities:m}},d=[i,r,o],e[0]=i,e[1]=r,e[2]=o,e[3]=a,e[4]=d):(a=e[3],d=e[4]),l.useEffect(a,d)},Qv=(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,Bc=(t,e,n)=>{Qv(t.get(e),n)&&t.set(e,n)},Xv=t=>{const e=t;return vt(e.directory)??vt(e.project?.worktree)},Jv=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)},Zv=(t,e,n,r,o=[])=>{const i=new Map,c=new Map;for(const w of e){const S=vt(w.normalizedPath);if(!S)continue;const p=c.get(S);(!p||w.id.localeCompare(p.id)<0)&&c.set(S,w),Bc(i,S,{projectId:w.id,projectRoot:S,scopeDirectory:S,kind:"project"})}if(!r)for(const[w,S]of n){const p=vt(w),h=p?c.get(p):void 0;if(!(!h||!p))for(const y of S){const v=vt(y.path);v&&Bc(i,v,{projectId:h.id,projectRoot:p,scopeDirectory:v,kind:"worktree"})}}const a=new Map,d=new Map,u=new Map,m=new Map,f=new Map,g=w=>{if(!w)return null;if(a.has(w))return a.get(w)??null;if(r){const y=i.get(w)??null;return a.set(w,y),y}const S=[];let p=w,h=null;for(;p;){if(a.has(p)){h=a.get(p)??null;break}if(S.push(p),h=i.get(p)??null,h)break;p=Jv(p)}for(const y of S)a.set(y,h);return h},x=(w,S,p)=>{for(const h of w){const y=g(Xv(h));if(!y)continue;d.set(h.id,y);const v=S.get(y.projectId);if(v?v.push(h):S.set(y.projectId,[h]),!p)continue;const j=p.get(y.scopeDirectory);j?j.add(h.id):p.set(y.scopeDirectory,new Set([h.id]))}};return x(t,u,f),x(o,m),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:m,sessionsByScope:f,directoryResolutions:a.size}},e1=t=>{const e=tt.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:o,projectHeaderSentinelRefs:i}=t,c=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]=l.useState(a);let m;e[1]!==c||e[2]!==r||e[3]!==i?(m=()=>{if(!c||!r){u(t1);return}const x=Array.from(i.current.values()).find(s1)?.closest(".oc-sidebar-scroller")??null;if(!x)return;const w=new IntersectionObserver(S=>{u(p=>{const h=new Set(p);let y=!1;for(const v of S){const j=v.target.dataset.projectId;if(!j)continue;const N=v.rootBounds?.top??x.getBoundingClientRect().top,C=!v.isIntersecting&&v.boundingClientRect.top<N;h.has(j)!==C&&(y=!0,C?h.add(j):h.delete(j))}return y?h:p})},{root:x,threshold:0});return i.current.forEach(S=>{S&&w.observe(S)}),()=>w.disconnect()},e[1]=c,e[2]=r,e[3]=i,e[4]=m):m=e[4];let f;return e[5]!==c||e[6]!==r||e[7]!==i||e[8]!==o?(f=[c,r,i,o],e[5]=c,e[6]=r,e[7]=i,e[8]=o,e[9]=f):f=e[9],l.useEffect(m,f),d};function t1(t){return t.size===0?t:new Set}function s1(t){return t!==null}const n1=t=>{const e=tt.c(10),{open:n,onOpenChange:r,project:o,onSave:i}=t;let c;e[0]!==i||e[1]!==n||e[2]!==o?(c=n&&o?s.jsx(Yp,{project:o,onIdentitySave:i,showWorktrees:!1}):null,e[0]=i,e[1]=n,e[2]=o,e[3]=c):c=e[3];let a;e[4]!==c?(a=s.jsx(Ys,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(Xn,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:c})})}),e[4]=c,e[5]=a):a=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==a?(d=s.jsx(qs,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=d):d=e[9],d};function sf(t){const e=tt.c(6),{state:n,activeLabel:r,unreadLabel:o,className:i}=t,c=n==="active"?r:o,a=n==="active"?"bg-primary":"bg-[var(--status-info)]";let d;e[0]!==i||e[1]!==a?(d=Ce("h-1.5 w-1.5 shrink-0 rounded-full",a,i),e[0]=i,e[1]=a,e[2]=d):d=e[2];let u;return e[3]!==c||e[4]!==d?(u=s.jsx("span",{className:d,"aria-label":c,title:c}),e[3]=c,e[4]=d,e[5]=u):u=e[5],u}const r1=t=>{const e=tt.c(86),{folder:n,displayName:r,sessions:o,subFolderItems:i,isCollapsed:c,collapsedActivityState:a,onToggle:d,onRename:u,onDelete:m,renderSessionNode:f,getRenderExtras:g,groupDirectory:x,projectId:w,mobileVariant:S,alwaysShowActions:p,isRenaming:h,renameDraft:y,onRenameDraftChange:v,onRenameSave:j,onRenameCancel:N,droppableRef:C,isDropTarget:k,onNewSession:D,depth:M,hideActions:A,archivedBucket:_}=t,L=a===void 0?null:a,$=p===void 0?S===void 0?!1:S:p,W=h===void 0?!1:h,U=y===void 0?"":y,K=k===void 0?!1:k,b=A===void 0?!1:A,P=_===void 0?!1:_,{t:V}=gt(),[G,X]=l.useState(!1),[J,ee]=l.useState(""),le=l.useRef(null),oe=W||G,Ae=W?U:J;let Se;e[0]!==n.name?(Se=()=>{ee(n.name),X(!0)},e[0]=n.name,e[1]=Se):Se=e[1];const Y=Se;let je;e[2]!==Ae||e[3]!==n.name||e[4]!==W||e[5]!==u||e[6]!==j?(je=()=>{const ie=Ae.trim();ie&&ie!==n.name&&u(ie),W&&j&&j(),X(!1),ee("")},e[2]=Ae,e[3]=n.name,e[4]=W,e[5]=u,e[6]=j,e[7]=je):je=e[7];const me=je;let z;e[8]!==W||e[9]!==N?(z=()=>{W&&N&&N(),X(!1),ee("")},e[8]=W,e[9]=N,e[10]=z):z=e[10];const Z=z;let ne;e[11]!==W||e[12]!==v?(ne=ie=>{W&&v?v(ie):ee(ie)},e[11]=W,e[12]=v,e[13]=ne):ne=e[13];const fe=ne;let xe,Te;e[14]!==W?(xe=()=>{if(!W)return;const ie=()=>{const ue=le.current;ue&&(ue.focus(),ue.select())},E=requestAnimationFrame(ie),I=window.setTimeout(ie,0);return()=>{cancelAnimationFrame(E),window.clearTimeout(I)}},Te=[W],e[14]=W,e[15]=xe,e[16]=Te):(xe=e[15],Te=e[16]),l.useEffect(xe,Te);const be=c?"folder":"folder-open",De=K&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Ee;e[17]!==De?(Ee=Ce("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",De),e[17]=De,e[18]=Ee):Ee=e[18];let Re;e[19]!==d||e[20]!==oe?(Re=oe?void 0:ie=>{ie.currentTarget.blur(),d()},e[19]=d,e[20]=oe,e[21]=Re):Re=e[21];const de=oe?void 0:"button",H=oe?void 0:0;let Ne;e[22]!==d||e[23]!==oe?(Ne=oe?void 0:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),d())},e[22]=d,e[23]=oe,e[24]=Ne):Ne=e[24];let he;e[25]!==n.name||e[26]!==c||e[27]!==V?(he=c?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=c,e[27]=V,e[28]=he):he=e[28];const ve=P?$?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":$?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let se;e[29]!==ve?(se=Ce("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ve),e[29]=ve,e[30]=se):se=e[30];const Q=K?"text-primary":"text-muted-foreground";let ye;e[31]!==Q?(ye=Ce("h-3.5 w-3.5 flex-shrink-0",Q),e[31]=Q,e[32]=ye):ye=e[32];let re;e[33]!==be||e[34]!==ye?(re=s.jsx(T,{name:be,className:ye}),e[33]=be,e[34]=ye,e[35]=re):re=e[35];let R;e[36]!==L||e[37]!==r||e[38]!==Ae||e[39]!==n.name||e[40]!==Z||e[41]!==fe||e[42]!==me||e[43]!==c||e[44]!==K||e[45]!==oe||e[46]!==o||e[47]!==V?(R=oe?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:i1,onMouseDown:a1,onSubmit:ie=>{ie.preventDefault(),me()},children:[s.jsx("input",{ref:le,value:Ae,onChange:ie=>fe(ie.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:V("sessions.sidebar.folderItem.namePlaceholder"),onClick:l1,onPointerDown:c1,onMouseDown:d1,onKeyDown:ie=>{if(ie.key==="Escape"){ie.stopPropagation(),Z();return}(ie.key===" "||ie.key==="Enter")&&ie.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:u1,onPointerDown:f1,onMouseDown:m1,children:s.jsx(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),Z()},onPointerDown:h1,onMouseDown:p1,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:Ce("typography-ui-label font-semibold truncate",K?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(mt,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",o.length]}),L?s.jsx(sf,{state:L,activeLabel:V("sessions.sidebar.session.status.active"),unreadLabel:V("sessions.sidebar.session.status.unread")}):null,c?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=L,e[37]=r,e[38]=Ae,e[39]=n.name,e[40]=Z,e[41]=fe,e[42]=me,e[43]=c,e[44]=K,e[45]=oe,e[46]=o,e[47]=V,e[48]=R):R=e[48];let ce;e[49]!==se||e[50]!==re||e[51]!==R?(ce=s.jsxs("div",{className:se,children:[re,R]}),e[49]=se,e[50]=re,e[51]=R,e[52]=ce):ce=e[52];let Me;e[53]!==$||e[54]!==P||e[55]!==n.name||e[56]!==Y||e[57]!==b||e[58]!==m||e[59]!==D||e[60]!==oe||e[61]!==V?(Me=!oe&&(!b||P)?s.jsx("div",{className:Ce("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",$?"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:[!P&&D?s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),D()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(T,{name:"add",className:"h-3.5 w-3.5"})}):null,P?null:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),Y()},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":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(T,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:ie=>{ie.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":P?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=$,e[54]=P,e[55]=n.name,e[56]=Y,e[57]=b,e[58]=m,e[59]=D,e[60]=oe,e[61]=V,e[62]=Me):Me=e[62];let ge;e[63]!==C||e[64]!==Ee||e[65]!==Re||e[66]!==de||e[67]!==H||e[68]!==Ne||e[69]!==he||e[70]!==ce||e[71]!==Me?(ge=s.jsxs("div",{ref:C,className:Ee,onClick:Re,role:de,tabIndex:H,onKeyDown:Ne,"aria-label":he,children:[ce,Me]}),e[63]=C,e[64]=Ee,e[65]=Re,e[66]=de,e[67]=H,e[68]=Ne,e[69]=he,e[70]=ce,e[71]=Me,e[72]=ge):ge=e[72];let te;e[73]!==P||e[74]!==g||e[75]!==x||e[76]!==c||e[77]!==w||e[78]!==f||e[79]!==o||e[80]!==i||e[81]!==V?(te=c?null:s.jsxs("div",{className:"pb-1",children:[i,o.length>0?o.map(ie=>f(ie,0,x??null,w??null,P,void 0,"project",g?.(ie))):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=P,e[74]=g,e[75]=x,e[76]=c,e[77]=w,e[78]=f,e[79]=o,e[80]=i,e[81]=V,e[82]=te):te=e[82];let ae;return e[83]!==ge||e[84]!==te?(ae=s.jsxs("div",{className:"oc-folder",children:[ge,te]}),e[83]=ge,e[84]=te,e[85]=ae):ae=e[85],ae},o1=l.memo(r1);function i1(t){return t.stopPropagation()}function a1(t){return t.stopPropagation()}function l1(t){return t.stopPropagation()}function c1(t){return t.stopPropagation()}function d1(t){return t.stopPropagation()}function u1(t){return t.stopPropagation()}function f1(t){return t.stopPropagation()}function m1(t){return t.stopPropagation()}function h1(t){return t.stopPropagation()}function p1(t){return t.stopPropagation()}const g1=t=>{const e=tt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let a;e[0]!==r||e[1]!==n||e[2]!==o?(a={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=a):a=e[3];let d;e[4]!==c||e[5]!==a?(d={id:c,data:a},e[4]=c,e[5]=a,e[6]=d):d=e[6];const{attributes:u,listeners:m,setNodeRef:f,isDragging:g}=Sg(d);let x;e[7]!==m?(x=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=x):x=e[8];const w=x,S=g?"opacity-30":void 0;let p;return e[9]!==u||e[10]!==i||e[11]!==w||e[12]!==f||e[13]!==S?(p=s.jsx("div",{ref:f,...u,onPointerDown:w,className:S,children:i}),e[9]=u,e[10]=i,e[11]=w,e[12]=f,e[13]=S,e[14]=p):p=e[14],p},x1=t=>{const e=tt.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let c;e[2]!==o||e[3]!==i?(c={id:o,data:i},e[2]=o,e[3]=i,e[4]=c):c=e[4];const{setNodeRef:a,isOver:d}=vg(c);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},b1=t=>{const e=tt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:i}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const a=ui(Wr(wa,c)),[d,u]=l.useState(null),[m,f]=l.useState("Session"),[g,x]=l.useState(null),[w,S]=l.useState(null);if(!n){let k;return e[1]!==i?(k=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=k):k=e[2],k}let p;e[3]!==o?(p=k=>{u(null),x(null),S(null);const{active:D,over:M}=k;if(!M)return;const A=D.data.current,_=M.data.current;A?.type==="session"&&A.sessionId&&_?.type==="folder"&&_.folderId&&o(A.sessionId,_.folderId)},e[3]=o,e[4]=p):p=e[4];const h=p;let y,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=k=>{const D=k.active.data.current;if(D?.type==="session"&&D.sessionId){u(D.sessionId),f(D.sessionTitle??"Session");const M=k.active.rect.current.initial?.width,A=k.active.rect.current.initial?.height;x(typeof M=="number"?M:null),S(typeof A=="number"?A:null)}},v=()=>{u(null),x(null),S(null)},e[5]=y,e[6]=v):(y=e[5],v=e[6]);let j;e[7]!==w||e[8]!==d||e[9]!==m||e[10]!==g||e[11]!==r?(j=d&&r?s.jsxs("div",{style:{width:g?`${g}px`:"auto",height:w?`${w}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(T,{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]=w,e[8]=d,e[9]=m,e[10]=g,e[11]=r,e[12]=j):j=e[12];let N;e[13]!==j?(N=s.jsx(va,{children:j}),e[13]=j,e[14]=N):N=e[14];let C;return e[15]!==i||e[16]!==h||e[17]!==a||e[18]!==N?(C=s.jsxs(fi,{sensors:a,collisionDetection:mi,onDragStart:y,onDragCancel:v,onDragEnd:h,children:[i,N]}),e[15]=i,e[16]=h,e[17]=a,e[18]=N,e[19]=C):C=e[19],C},Pa=(t,e,n)=>{if(!e)return;const r=o=>{let i=o.session.id===e;for(const c of o.children)i=r(c)||i;return i&&n.add(o.session.id),i};for(const o of t)r(o)},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},y1=(t,e,n)=>{const r=new Map,o=i=>{const c=Gs(i.session)??vt(i.worktree?.path)??n;if(c){const a=r.get(c)??[];a.push(i.session.id),r.set(c,a)}if(!(i===t&&e))for(const a of i.children)o(a)};return o(t),[...r].map(([i,c])=>({directory:i,sessionIDs:c}))},w1=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const o=new Set;let i=r.session.parentID??null;for(;i&&!o.has(i);){if(n.has(i)&&e.has(i))return!1;o.add(i),i=e.get(i)?.session?.parentID??null}return!0})},Lc=new WeakMap;let _c=1;const v1=t=>{const e=Lc.get(t);if(e!==void 0)return e;const n=_c;return _c+=1,Lc.set(t,n),n},gi=t=>t.children.length===0?"":t.children.map(n=>{const r=v1(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${gi(n)}`}).join("|"),nf=(t,e,n,r,o,i)=>{const c=Tn(),a=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const m=d.session.directory??o,f=u.session.directory??i,g=_l(c,m??"",d.session.id),x=_l(c,f??"",u.session.id);return(g?n.has(g):!1)!==(x?r.has(x):!1)?!0:d.children.some((w,S)=>a(w,u.children[S]))};return a(t,e)},yo=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let i=null;const c=a=>{if(`${n}:${o}:${a.session.id}`===e)return i=a.session.id,!0;for(const u of a.children)if(c(u))return!0;return!1};return t.forEach(a=>c(a)),i},cl=(t,e)=>t==="active"||e==="active"?"active":t==="unread"||e==="unread"?"unread":null,rf=(t,e,n,r)=>{if(e.has(t.session.id))return"active";let o=null;const i=!!t.session.parentID;n.has(t.session.id)&&(r||!i)&&(o="unread");for(const c of t.children)if(o=cl(o,rf(c,e,n,r)),o==="active")return o;return o},$c=(t,e,n,r)=>{let o=null;for(const i of t)if(o=cl(o,rf(i,e,n,r)),o==="active")return o;return o},S1=50,j1=28,Lo=(t,e)=>e?t.sessions.some(n=>Yn(n,e)):!1,k1=(t,e,n)=>t.sessions.some(r=>nf(r,r,e,n,t.directory,t.directory)),C1=(t,e,n)=>{const r=o=>{const i=o.session.id;return e.get(i)!==n.get(i)?!0:o.children.some(r)};return t.sessions.some(r)},zc=(t,e,n)=>{const r=o=>e.has(o.session.id)!==n.has(o.session.id)?!0:o.children.some(r);return t.sessions.some(r)},N1=(t,e)=>{const n=r=>e.has(r.session.id)?!0:r.children.some(n);return t.sessions.some(n)},A1=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",o=i=>{const c=`project:${r}:${i.session.id}`;return e.has(c)!==n.has(c)?!0:i.children.some(o)};return t.sessions.some(o)},D1=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&k1(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&A1(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&C1(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.editingId!==e.editingId&&(Lo(t.group,t.editingId)||Lo(e.group,e.editingId))||t.editTitle!==e.editTitle&&(Lo(t.group,t.editingId)||Lo(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=yo(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=yo(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}return t.activeActivitySessionIds!==e.activeActivitySessionIds&&zc(e.group,t.activeActivitySessionIds,e.activeActivitySessionIds)||t.unreadActivitySessionIds!==e.unreadActivitySessionIds&&zc(e.group,t.unreadActivitySessionIds,e.unreadActivitySessionIds)||t.notifyOnSubtasks!==e.notifyOnSubtasks&&N1(e.group,e.unreadActivitySessionIds)?!1:t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.collapsedFolderIds===e.collapsedFolderIds&&t.toggleFolderCollapse===e.toggleFolderCollapse&&t.renameFolder===e.renameFolder&&t.deleteFolder===e.deleteFolder&&t.showDeletionDialog===e.showDeletionDialog&&t.setDeleteFolderConfirm===e.setDeleteFolderConfirm&&t.renderSessionNode===e.renderSessionNode&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.activeProjectId===e.activeProjectId&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setActiveMainTab===e.setActiveMainTab&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.renamingFolderId===e.renamingFolderId&&t.renameFolderDraft===e.renameFolderDraft&&t.setRenameFolderDraft===e.setRenameFolderDraft&&t.setRenamingFolderId===e.setRenamingFolderId&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef};function P1(t){const{t:e}=gt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:a,groupSearchDataByGroup:d,visibleSessionCount:u,collapsedGroups:m,hideDirectoryControls:f,collapsedFolderIds:g,toggleFolderCollapse:x,renameFolder:w,deleteFolder:S,showDeletionDialog:p,setDeleteFolderConfirm:h,renderSessionNode:y,showMoreGroupSessions:v,resetGroupSessionLimit:j,mobileVariant:N,alwaysShowActions:C,activeProjectId:k,setActiveProjectIdOnly:D,setActiveMainTab:M,setSessionSwitcherOpen:A,openNewSessionDraft:_,addSessionToFolder:L,createFolderAndStartRename:F,renamingFolderId:$,renameFolderDraft:W,setRenameFolderDraft:U,setRenamingFolderId:K,pinnedSessionIds:b,expandedParents:P,sessionOrderIndex:V,editingId:G,openSidebarMenuKey:X,activeActivitySessionIds:J,unreadActivitySessionIds:ee,notifyOnSubtasks:le,onToggleCollapsedGroup:oe,dragHandleProps:Ae,compactBodyPadding:Se=!1,scrollContainerRef:Y}=t,je=l.useCallback((Oe,Ue)=>{const Ve=V.get(Oe.session.id),Be=V.get(Ue.session.id);if(Ve!==void 0||Be!==void 0){if(Ve===void 0)return 1;if(Be===void 0)return-1;if(Ve!==Be)return Ve-Be}return qr(Oe.session,Ue.session,b,Ka)},[b,V]),me=c?d.get(n):null,z=zs(Oe=>Oe.foldersMap),Z=c?!1:m.has(r),ne=l.useMemo(()=>{if(n.isMain||n.isArchivedBucket||i)return null;const Oe=vt(n.directory??null),Ue=n.branch?.trim();return Oe&&Ue?ki(Oe,Ue):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,i]),fe=su(ne),xe=fe?`var(--pr-${fe.visualState})`:void 0,Te=nu(),be=l.useMemo(()=>{const Oe=n.folderScopes?.map(Ue=>vt(Ue.directory))??[vt(n.directory??null)];return[...new Set(Oe.filter(Ue=>!!Ue))]},[n.directory,n.folderScopes]);l.useSyncExternalStore(l.useCallback(Oe=>be.length>0?Te.subscribeBootstrap(Oe):()=>{},[be.length,Te]),l.useCallback(()=>be.map(Oe=>`${Oe}\0${Te.getBootstrapState(Oe)??""}\0${Te.getBootstrapFailure(Oe)??""}`).join(""),[be,Te]),l.useCallback(()=>"",[]));const De=be.some(Oe=>{const Ue=Te.getBootstrapState(Oe);return Ue==="queued"||Ue==="running"}),Ee=be.find(Oe=>Te.getBootstrapState(Oe)==="failed")??null,Re=Ee?Te.getBootstrapFailure(Ee):void 0,de=Re==="os-permission"&&am(),[H,Ne]=l.useState(!1),he=l.useCallback(()=>{Ee&&Te.requestBootstrap({directory:Ee,priority:Z?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[Te,Ee,n.isMain,Z]),ve=l.useCallback(async()=>{if(!(!Ee||!de||H)){Ne(!0);try{(await lm(Ee)).success&&he()}finally{Ne(!1)}}},[de,Ee,H,he]),se=f?10:5,Q=Math.max(se,u??se),ye=c?me?.groupMatches===!0:!1,re=c,R=l.useMemo(()=>[...re?me?.filteredNodes??[]:n.sessions].sort(je),[je,n.sessions,me?.filteredNodes,re]),ce=n.folderScopeKey??vt(n.directory??null),Me=l.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:ce?[{scopeKey:ce,directory:n.directory??null}]:[],[ce,n.directory,n.folderScopes]),ge=l.useMemo(()=>Me.flatMap(({scopeKey:Oe,directory:Ue})=>(z[Oe]??[]).map(Ve=>({folder:Ve,scopeKey:Oe,scopeDirectory:Ue}))),[Me,z]),te=l.useMemo(()=>{const Oe=new Map,Ue=Ve=>{Ve.forEach(Be=>{Oe.set(Be.session.id,Be),Be.children.length>0&&Ue(Be.children)})};return Ue(R),Oe},[R]),ae=l.useMemo(()=>ge.map(({folder:Oe,scopeKey:Ue,scopeDirectory:Ve})=>{const Be=w1(Oe.sessionIds,te).sort(je);return{folder:Oe,scopeKey:Ue,scopeDirectory:Ve,nodes:Be}}),[ge,te,je]),ie=l.useMemo(()=>{const Oe=new Map(ae.map(We=>[We.folder.id,We])),Ue=new Map;for(const{folder:We}of ae){if(!We.parentId)continue;const wt=Ue.get(We.parentId);wt?wt.push(We.id):Ue.set(We.parentId,[We.id])}const Ve=new Map,Be=We=>{const wt=Ve.get(We);if(wt!==void 0)return wt;const os=Oe.get(We);if(!os)return Ve.set(We,!1),!1;const xt=Ue.get(We)??[];if(n.isArchivedBucket&&os.nodes.length===0){const es=xt.some(js=>Be(js));return Ve.set(We,es),es}if(!c||os.folder.name.toLowerCase().includes(a)||os.nodes.length>0)return Ve.set(We,!0),!0;const ds=xt.some(es=>Be(es));return Ve.set(We,ds),ds};return ae.filter(({folder:We})=>Be(We.id))},[ae,n.isArchivedBucket,c,a]),E=l.useMemo(()=>new Set(ie.flatMap(Oe=>Oe.folder.sessionIds)),[ie]),I=l.useMemo(()=>R.filter(Oe=>!E.has(Oe.session.id)),[R,E]),ue=l.useMemo(()=>ie.filter(({folder:Oe})=>!Oe.parentId),[ie]),ke=l.useMemo(()=>{const Oe=new Map;return ie.forEach(Ue=>{if(!Ue.folder.parentId)return;const Ve=Oe.get(Ue.folder.parentId)??[];Ve.push(Ue),Oe.set(Ue.folder.parentId,Ve)}),Oe},[ie]),we=l.useMemo(()=>{const Oe=new Map(ie.map(Be=>[Be.folder.id,Be])),Ue=new Map,Ve=(Be,We)=>{const wt=Ue.get(Be);if(wt!==void 0)return wt;if(We.has(Be))return null;We.add(Be);const os=Oe.get(Be);let xt=os?$c(os.nodes,J,ee,le):null;for(const ns of ke.get(Be)??[])if(xt=cl(xt,Ve(ns.folder.id,We)),xt==="active")break;return Ue.set(Be,xt),xt};return ie.forEach(({folder:Be})=>Ve(Be.id,new Set)),Ue},[J,ie,ke,le,ee]),qe="project",Je=l.useMemo(()=>{const Oe=new Set;return Pa(R,G,Oe),ie.forEach(({nodes:Ue})=>{Pa(Ue,G,Oe)}),Oe},[R,ie,G]),st=l.useMemo(()=>{if(!X)return null;const Oe=yo(R,X,qe,!!n.isArchivedBucket);if(Oe)return Oe;for(const{nodes:Ue}of ie){const Ve=yo(Ue,X,qe,!!n.isArchivedBucket);if(Ve)return Ve}return null},[X,R,ie,n.isArchivedBucket]),rt=l.useCallback(Oe=>{const Ue=new WeakMap,Ve=Be=>{Ue.set(Be,gi(Be));for(const We of Be.children)Ve(We)};return Oe.forEach(Ve),Ue},[]),ot=l.useMemo(()=>rt(R),[rt,R]),lt=l.useMemo(()=>{const Oe=new WeakMap;return ie.forEach(({nodes:Ue})=>{Ue.forEach(Ve=>Oe.set(Ve,gi(Ve)))}),Oe},[ie]),kt=l.useCallback(Oe=>ot.get(Oe)??lt.get(Oe)??"",[ot,lt]),nt=l.useCallback(Oe=>({subtreeContainsEditing:Je,menuOpenSessionId:st,nodeStructureKey:kt(Oe)}),[Je,st,kt]),it=I.length,St=n.isArchivedBucket||c?I:I.slice(0,Q),It=it-St.length,Ft=!n.isArchivedBucket&&!c&&it>se&&It===0,Mt=n.isArchivedBucket===!0&&!c&&St.length>=S1,Ot=n.isArchivedBucket?"archived":"active",Ke=Mt&&St.some(Oe=>{if(Oe.children.length===0)return!1;const Ue=`project:${Ot}:${Oe.session.id}`;return P.has(Ue)}),$t=l.useRef(null),[Tt,dt]=l.useState(null),[Ct,Rt]=l.useState(0),[,Qt]=l.useState(0);l.useEffect(()=>{if(!Mt)return;const Oe=$t.current;if(!Oe||typeof ResizeObserver>"u")return;const Ue=new ResizeObserver(()=>Qt(Ve=>Ve+1));return Ue.observe(Oe),()=>Ue.disconnect()},[Mt]),l.useLayoutEffect(()=>{if(!Mt){Tt!==null&&dt(null),Ct!==0&&Rt(0);return}const Oe=$t.current;if(!Oe)return;let Ue=Tt;const Ve=Y?.current??null;if(Ve&&Ve.contains(Oe)){if(Ue=Ve,Ue!==Tt){dt(Ue);return}}else if(!Ue||!Ue.contains(Oe)){let We=Oe.parentElement;for(;We;){const wt=window.getComputedStyle(We);if(wt.overflowY==="auto"||wt.overflowY==="scroll"){Ue=We;break}We=We.parentElement}if(Ue!==Tt){dt(Ue);return}}if(!Ue)return;const Be=Oe.getBoundingClientRect().top-Ue.getBoundingClientRect().top+Ue.scrollTop;Rt(We=>Math.abs(We-Be)<1?We:Be)});const Qe=Mt&&Tt!==null,ht=Cg({count:St.length,enabled:Qe,getScrollElement:()=>Tt,initialOffset:()=>Tt?.scrollTop??0,estimateSize:()=>j1,overscan:Ke?20:8,scrollMargin:Ct,getItemKey:Oe=>St[Oe]?.session.id??Oe}),Xe=l.useCallback(Oe=>{const Ue=[],Ve=Be=>{Be.forEach(We=>{Ue.push(We.session),We.children.length>0&&Ve(We.children)})};return Ve(Oe),Ue},[]),_e=l.useMemo(()=>Xe(R),[Xe,R]),yt=l.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Oe=new Map,Ue=new Map;for(const{folder:Be}of ie){if(!Be.parentId)continue;const We=Ue.get(Be.parentId)??[];We.push(Be.id),Ue.set(Be.parentId,We)}const Ve=(Be,We)=>{if(We.has(Be))return[];We.add(Be);const wt=ie.find(({folder:ns})=>ns.id===Be),os=wt?Xe(wt.nodes):[],xt=Ue.get(Be)??[];for(const ns of xt)os.push(...Ve(ns,We));return os};for(const{folder:Be}of ie)Oe.set(Be.id,Ve(Be.id,new Set));return Oe},[ie,Xe,n.isArchivedBucket]);if(c&&!ye&&ue.length===0&&I.length===0)return null;const zt=!n.isMain&&!!n.branch,Bt=n.branch&&xh(n.branch,n.label)?{label:n.branch}:null,Lt=Z?$c(R,J,ee,le):null,_t=Lt?s.jsx(sf,{state:Lt,activeLabel:e("sessions.sidebar.session.status.active"),unreadLabel:e("sessions.sidebar.session.status.unread")}):null,Ht=(Oe,Ue)=>{const{folder:Ve,scopeKey:Be,scopeDirectory:We,nodes:wt}=Oe,os=yt.get(Ve.id)??[],xt=c?!1:g.has(Ve.id);return s.jsx(x1,{folderId:Ve.id,children:(ns,ds)=>s.jsx(o1,{folder:Ve,displayName:Ue,sessions:wt,isCollapsed:xt,collapsedActivityState:xt?we.get(Ve.id)??null:null,onToggle:()=>x(Ve.id),onRename:es=>{w(Be,Ve.id,es)},onDelete:()=>{if(n.isArchivedBucket){Ln.requestDelete({sessions:os,mode:"session"});return}if(!p){S(Be,Ve.id);return}const es=ie.filter(({folder:sn})=>sn.parentId===Ve.id).length,js=wt.length;h({scopeKey:Be,folderId:Ve.id,folderName:Ve.name,subFolderCount:es,sessionCount:js})},renderSessionNode:y,getRenderExtras:kt?es=>({subtreeContainsEditing:Je,menuOpenSessionId:st,nodeStructureKey:kt(es),childRenderExtrasFor:nt}):void 0,groupDirectory:We??n.directory,projectId:o,mobileVariant:N,alwaysShowActions:C,isRenaming:$===Ve.id,renameDraft:$===Ve.id?W:void 0,onRenameDraftChange:es=>U(es),onRenameSave:()=>{const es=W.trim();es&&w(Be,Ve.id,es),K(null),U("")},onRenameCancel:()=>{K(null),U("")},droppableRef:ns,isDropTarget:ds,depth:0,onNewSession:()=>{o&&o!==k&&D(o),M("chat"),N&&A(!1),_({selectedProjectId:o,directoryOverride:We??n.directory,targetFolderId:Ve.id})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ve.id)},Dt=()=>{const Oe=new Map;for(const Be of ie){const We=Be.folder.parentId;if(!We)continue;const wt=Oe.get(We);wt?wt.push(Be):Oe.set(We,[Be])}const Ue=[],Ve=(Be,We)=>{const wt=We?`${We} / ${Be.folder.name}`:Be.folder.name;Ue.push(Ht(Be,wt)),!(!c&&g.has(Be.folder.id))&&(Oe.get(Be.folder.id)??[]).forEach(xt=>Ve(xt,wt))};return ue.forEach(Be=>Ve(Be,"")),Ue},fs=!!(!n.isMain&&n.worktree),Kt=C?fs?"pr-14":"pr-7":fs?"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",Nt=Ee?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(Re==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),de?s.jsx(et,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:H,onClick:()=>{ve()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(et,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:he,children:e("sessions.sidebar.group.empty.retry")})]}):null,Zt=s.jsxs(b1,{scopeKey:Me[0]?.scopeKey??ce,hasFolders:ie.length>0,onSessionDroppedOnFolder:(Oe,Ue)=>{const Ve=ie.find(({folder:We})=>We.id===Ue);if(!Ve)return;const Be=zs.getState();for(const{scopeKey:We}of Me)We!==Ve.scopeKey&&Be.getSessionFolderId(We,Oe)&&Be.removeSessionFromFolder(We,Oe);L(Ve.scopeKey,Ue,Oe)},children:[Dt(),Mt?s.jsx("div",{ref:$t,children:Qe?s.jsx("div",{style:{height:ht.getTotalSize(),position:"relative"},children:ht.getVirtualItems().map(Oe=>{const Ue=St[Oe.index];return Ue?s.jsx("div",{"data-index":Oe.index,ref:ht.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Oe.start-Ct}px)`},children:y(Ue,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Je,menuOpenSessionId:st,nodeStructureKey:kt(Ue),childRenderExtrasFor:nt})},Ue.session.id):null})}):St.map(Oe=>y(Oe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Je,menuOpenSessionId:st,nodeStructureKey:kt(Oe),childRenderExtrasFor:nt}))}):St.map(Oe=>y(Oe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Je,menuOpenSessionId:st,nodeStructureKey:kt(Oe),childRenderExtrasFor:nt})),it===0&&ie.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"):De?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(T,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Nt||e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,it>0&&Nt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Nt}):null,It>0?s.jsx("button",{type:"button",onClick:()=>v(r,St.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,Ft?s.jsx("button",{type:"button",onClick:()=>j(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),ss="pb-2";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Ce("oc-group-body",ss),children:Zt})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Ce("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>oe(r),role:"button",tabIndex:0,onKeyDown:Oe=>{(Oe.key==="Enter"||Oe.key===" ")&&(Oe.preventDefault(),oe(r))},"aria-label":Z?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Z,children:[s.jsx("div",{ref:Ae?.setActivatorNodeRef,className:Ce("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",Kt),...Ae?.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(T,{name:"archive",className:Ce("h-3.5 w-3.5 shrink-0 text-muted-foreground",C?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Ce("text-muted-foreground h-3.5 w-3.5 items-center justify-center",C?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Z?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Go(n.label,a)}),_t]}):!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(T,{name:"git-branch",className:Ce("h-3.5 w-3.5 shrink-0",!xe&&"text-muted-foreground",C?"hidden":"group-hover/gh:hidden"),style:xe?{color:xe}:void 0}),s.jsx("span",{className:Ce("text-muted-foreground h-3.5 w-3.5 items-center justify-center",C?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Z?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{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:Go(n.label,a)}),_t,fe?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:xe?{color:xe}:void 0,children:["#",fe.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:Go(n.label,a)}),_t]})}),zt&&Bt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(T,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{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:Bt.label})]}):null]})}),n.isArchivedBucket&&_e.length>0?s.jsx("div",{className:Ce("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",C?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),Ln.requestDelete({sessions:_e,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(T,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(mt,{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:Ce("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",C?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),Ln.requestDelete({sessions:_e,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(T,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Ce("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",C?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),o&&o!==k&&D(o),M("chat"),N&&A(!1),_({selectedProjectId:o,directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(T,{name:"add",className:"h-4 w-4"})})}),s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Z?null:s.jsx("div",{className:Ce("oc-group-body",ss),children:Zt})]})}const I1=l.memo(P1,D1),T1=(t,e)=>{const n=t??{};return e<2&&(n.projectSortOrder="manual"),e<3&&n.projectSortOrder==="recent"&&(n.projectSortOrder="manual"),e<4&&delete n.displayMode,n},Ns=Qr()(hg(t=>({sessionGroupingMode:"by-worktree",setSessionGroupingMode:e=>t({sessionGroupingMode:e}),stickyZoneHeaders:!0,toggleStickyZoneHeaders:()=>t(e=>({stickyZoneHeaders:!e.stickyZoneHeaders})),showRecentSection:!0,showArchivedSessions:!1,projectSortOrder:"manual",setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions})),setProjectSortOrder:e=>t({projectSortOrder:e})}),{name:"session-display-mode",version:4,migrate:T1}));function E1(t){const e=tt.c(219),{t:n}=gt(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,onOpenScheduled:c,onOpenMultiRun:a,canOpenMultiRun:d,onOpenArchive:u,headerActionIconClass:m,headerActionButtonClass:f,isSessionSearchOpen:g,setIsSessionSearchOpen:x,sessionSearchInputRef:w,sessionSearchQuery:S,setSessionSearchQuery:p,hasSessionSearchQuery:h,searchMatchCount:y,collapseAllProjects:v,expandAllProjects:j,selectionModeEnabled:N,onToggleSelectionMode:C}=t,k=Ns(z1),D=Ns($1),M=Ns(_1),A=Ns(L1),_=Ns(B1),L=Ns(F1),F=Ns(O1),$=Ns(R1);if(r)return null;let W;e[0]!==f?(W=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=f,e[1]=W):W=e[1];let U;e[2]!==n?(U=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=U):U=e[3];let K;e[4]!==m?(K=s.jsx(T,{name:"folder-add",className:m}),e[4]=m,e[5]=K):K=e[5];let b;e[6]!==i||e[7]!==W||e[8]!==U||e[9]!==K?(b=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:W,"aria-label":U,children:K})}),e[6]=i,e[7]=W,e[8]=U,e[9]=K,e[10]=b):b=e[10];let P;e[11]!==n?(P=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=P):P=e[12];let V;e[13]!==P?(V=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:P})}),e[13]=P,e[14]=V):V=e[14];let G;e[15]!==b||e[16]!==V?(G=s.jsxs(ut,{children:[b,V]}),e[15]=b,e[16]=V,e[17]=G):G=e[17];let X;e[18]!==f?(X=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=f,e[19]=X):X=e[19];let J;e[20]!==n?(J=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=J):J=e[21];let ee;e[22]!==m?(ee=s.jsx(T,{name:"calendar-schedule",className:m}),e[22]=m,e[23]=ee):ee=e[23];let le;e[24]!==c||e[25]!==X||e[26]!==J||e[27]!==ee?(le=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:X,"aria-label":J,children:ee})}),e[24]=c,e[25]=X,e[26]=J,e[27]=ee,e[28]=le):le=e[28];let oe;e[29]!==n?(oe=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=oe):oe=e[30];let Ae;e[31]!==oe?(Ae=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:oe})}),e[31]=oe,e[32]=Ae):Ae=e[32];let Se;e[33]!==le||e[34]!==Ae?(Se=s.jsxs(ut,{children:[le,Ae]}),e[33]=le,e[34]=Ae,e[35]=Se):Se=e[35];let Y;e[36]!==f?(Y=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=f,e[37]=Y):Y=e[37];let je;e[38]!==n?(je=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=je):je=e[39];const me=!d;let z;e[40]!==m?(z=s.jsx(bh,{className:m}),e[40]=m,e[41]=z):z=e[41];let Z;e[42]!==a||e[43]!==Y||e[44]!==je||e[45]!==me||e[46]!==z?(Z=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Y,"aria-label":je,disabled:me,children:z})}),e[42]=a,e[43]=Y,e[44]=je,e[45]=me,e[46]=z,e[47]=Z):Z=e[47];let ne;e[48]!==n?(ne=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=ne):ne=e[49];let fe;e[50]!==ne?(fe=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[50]=ne,e[51]=fe):fe=e[51];let xe;e[52]!==Z||e[53]!==fe?(xe=s.jsxs(ut,{children:[Z,fe]}),e[52]=Z,e[53]=fe,e[54]=xe):xe=e[54];let Te;e[55]!==f?(Te=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=f,e[56]=Te):Te=e[56];let be;e[57]!==n?(be=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=be):be=e[58];let De;e[59]!==m?(De=s.jsx(T,{name:"archive",className:m}),e[59]=m,e[60]=De):De=e[60];let Ee;e[61]!==u||e[62]!==Te||e[63]!==be||e[64]!==De?(Ee=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:Te,"aria-label":be,children:De})}),e[61]=u,e[62]=Te,e[63]=be,e[64]=De,e[65]=Ee):Ee=e[65];let Re;e[66]!==n?(Re=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=Re):Re=e[67];let de;e[68]!==Re?(de=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Re})}),e[68]=Re,e[69]=de):de=e[69];let H;e[70]!==Ee||e[71]!==de?(H=s.jsxs(ut,{children:[Ee,de]}),e[70]=Ee,e[71]=de,e[72]=H):H=e[72];let Ne;e[73]!==Se||e[74]!==xe||e[75]!==H||e[76]!==G?(Ne=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[G,Se,xe,H]}),e[73]=Se,e[74]=xe,e[75]=H,e[76]=G,e[77]=Ne):Ne=e[77];let he;e[78]!==x?(he=()=>x(M1),e[78]=x,e[79]=he):he=e[79];let ve;e[80]!==f?(ve=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=f,e[81]=ve):ve=e[81];let se;e[82]!==n?(se=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=se):se=e[83];let Q;e[84]!==m?(Q=s.jsx(T,{name:"search",className:m}),e[84]=m,e[85]=Q):Q=e[85];let ye;e[86]!==g||e[87]!==he||e[88]!==ve||e[89]!==se||e[90]!==Q?(ye=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he,className:ve,"aria-label":se,"aria-expanded":g,children:Q})}),e[86]=g,e[87]=he,e[88]=ve,e[89]=se,e[90]=Q,e[91]=ye):ye=e[91];let re;e[92]!==n?(re=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=re):re=e[93];let R;e[94]!==re?(R=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:re})}),e[94]=re,e[95]=R):R=e[95];let ce;e[96]!==ye||e[97]!==R?(ce=s.jsxs(ut,{children:[ye,R]}),e[96]=ye,e[97]=R,e[98]=ce):ce=e[98];const Me=N&&"bg-interactive-hover text-primary";let ge;e[99]!==f||e[100]!==Me?(ge=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent",Me),e[99]=f,e[100]=Me,e[101]=ge):ge=e[101];let te;e[102]!==N||e[103]!==n?(te=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=N,e[103]=n,e[104]=te):te=e[104];let ae;e[105]!==m?(ae=s.jsx(T,{name:"checkbox-multiple",className:m}),e[105]=m,e[106]=ae):ae=e[106];let ie;e[107]!==C||e[108]!==N||e[109]!==ge||e[110]!==te||e[111]!==ae?(ie=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:ge,"aria-label":te,"aria-pressed":N,children:ae})}),e[107]=C,e[108]=N,e[109]=ge,e[110]=te,e[111]=ae,e[112]=ie):ie=e[112];let E;e[113]!==N||e[114]!==n?(E=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=N,e[114]=n,e[115]=E):E=e[115];let I;e[116]!==E?(I=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E})}),e[116]=E,e[117]=I):I=e[117];let ue;e[118]!==ie||e[119]!==I?(ue=s.jsxs(ut,{children:[ie,I]}),e[118]=ie,e[119]=I,e[120]=ue):ue=e[120];let ke;e[121]!==f?(ke=Ce(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=f,e[122]=ke):ke=e[122];let we;e[123]!==n?(we=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=we):we=e[124];let qe;e[125]!==m?(qe=s.jsx(T,{name:"equalizer-2",className:m}),e[125]=m,e[126]=qe):qe=e[126];let Je;e[127]!==ke||e[128]!==we||e[129]!==qe?(Je=s.jsx(ft,{asChild:!0,children:s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:ke,"aria-label":we,children:qe})})}),e[127]=ke,e[128]=we,e[129]=qe,e[130]=Je):Je=e[130];let st;e[131]!==n?(st=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=st):st=e[132];let rt;e[133]!==st?(rt=s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:st})}),e[133]=st,e[134]=rt):rt=e[134];let ot;e[135]!==Je||e[136]!==rt?(ot=s.jsxs(ut,{children:[Je,rt]}),e[135]=Je,e[136]=rt,e[137]=ot):ot=e[137];let lt;e[138]!==n?(lt=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=lt):lt=e[139];let kt;e[140]!==lt?(kt=s.jsx(ma,{children:lt}),e[140]=lt,e[141]=kt):kt=e[141];let nt;e[142]!==M||e[143]!==A||e[144]!==n?(nt=[["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(Kt=>{const[Nt,Zt]=Kt;return s.jsxs(qt,{onClick:()=>A(Nt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Zt)}),M===Nt?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},Nt)}),e[142]=M,e[143]=A,e[144]=n,e[145]=nt):nt=e[145];let it;e[146]===Symbol.for("react.memo_cache_sentinel")?(it=s.jsx(gn,{}),e[146]=it):it=e[146];let St;e[147]!==n?(St=n("sessions.sidebar.header.grouping.label"),e[147]=n,e[148]=St):St=e[148];let It;e[149]!==St?(It=s.jsx(ma,{children:St}),e[149]=St,e[150]=It):It=e[150];let Ft;e[151]!==_||e[152]!==L||e[153]!==n?(Ft=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(Kt=>{const[Nt,Zt]=Kt;return s.jsxs(qt,{onClick:()=>L(Nt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Zt)}),_===Nt?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},Nt)}),e[151]=_,e[152]=L,e[153]=n,e[154]=Ft):Ft=e[154];let Mt;e[155]===Symbol.for("react.memo_cache_sentinel")?(Mt=s.jsx(gn,{}),e[155]=Mt):Mt=e[155];let Ot;e[156]!==o||e[157]!==k||e[158]!==n||e[159]!==D?(Ot=o?s.jsxs(qt,{onClick:D,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),k?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[156]=o,e[157]=k,e[158]=n,e[159]=D,e[160]=Ot):Ot=e[160];let Ke;e[161]!==n?(Ke=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[161]=n,e[162]=Ke):Ke=e[162];let $t;e[163]!==Ke?($t=s.jsx("span",{children:Ke}),e[163]=Ke,e[164]=$t):$t=e[164];let Tt;e[165]!==F?(Tt=F?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null,e[165]=F,e[166]=Tt):Tt=e[166];let dt;e[167]!==$t||e[168]!==Tt||e[169]!==$?(dt=s.jsxs(qt,{onClick:$,className:"flex items-center justify-between",children:[$t,Tt]}),e[167]=$t,e[168]=Tt,e[169]=$,e[170]=dt):dt=e[170];let Ct;e[171]===Symbol.for("react.memo_cache_sentinel")?(Ct=s.jsx(gn,{}),e[171]=Ct):Ct=e[171];let Rt;e[172]===Symbol.for("react.memo_cache_sentinel")?(Rt=s.jsx(T,{name:"contract-up-down",className:"h-4 w-4"}),e[172]=Rt):Rt=e[172];let Qt;e[173]!==n?(Qt=n("sessions.sidebar.header.displayMode.collapseAll"),e[173]=n,e[174]=Qt):Qt=e[174];let Qe;e[175]!==Qt?(Qe=s.jsx("span",{children:Qt}),e[175]=Qt,e[176]=Qe):Qe=e[176];let ht;e[177]!==v||e[178]!==Qe?(ht=s.jsxs(qt,{onClick:v,className:"flex items-center gap-2",children:[Rt,Qe]}),e[177]=v,e[178]=Qe,e[179]=ht):ht=e[179];let Xe;e[180]===Symbol.for("react.memo_cache_sentinel")?(Xe=s.jsx(T,{name:"expand-up-down",className:"h-4 w-4"}),e[180]=Xe):Xe=e[180];let _e;e[181]!==n?(_e=n("sessions.sidebar.header.displayMode.expandAll"),e[181]=n,e[182]=_e):_e=e[182];let yt;e[183]!==_e?(yt=s.jsx("span",{children:_e}),e[183]=_e,e[184]=yt):yt=e[184];let zt;e[185]!==j||e[186]!==yt?(zt=s.jsxs(qt,{onClick:j,className:"flex items-center gap-2",children:[Xe,yt]}),e[185]=j,e[186]=yt,e[187]=zt):zt=e[187];let Bt;e[188]!==kt||e[189]!==nt||e[190]!==It||e[191]!==Ft||e[192]!==Ot||e[193]!==dt||e[194]!==ht||e[195]!==zt?(Bt=s.jsxs(bn,{align:"end",className:"min-w-[180px]",children:[kt,nt,it,It,Ft,Mt,Ot,dt,Ct,ht,zt]}),e[188]=kt,e[189]=nt,e[190]=It,e[191]=Ft,e[192]=Ot,e[193]=dt,e[194]=ht,e[195]=zt,e[196]=Bt):Bt=e[196];let Lt;e[197]!==ot||e[198]!==Bt?(Lt=s.jsxs(yn,{children:[ot,Bt]}),e[197]=ot,e[198]=Bt,e[199]=Lt):Lt=e[199];let _t;e[200]!==ce||e[201]!==ue||e[202]!==Lt?(_t=s.jsxs("div",{className:"flex items-center gap-1.5",children:[ce,ue,Lt]}),e[200]=ce,e[201]=ue,e[202]=Lt,e[203]=_t):_t=e[203];let Ht;e[204]!==Ne||e[205]!==_t?(Ht=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[Ne,_t]}),e[204]=Ne,e[205]=_t,e[206]=Ht):Ht=e[206];let Dt;e[207]!==h||e[208]!==g||e[209]!==y||e[210]!==w||e[211]!==S||e[212]!==x||e[213]!==p||e[214]!==n?(Dt=g?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:[h?s.jsx("span",{children:y===1?n("sessions.sidebar.header.search.matchCountSingle",{count:y}):n("sessions.sidebar.header.search.matchCountPlural",{count:y})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(T,{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:w,value:S,onChange:Kt=>p(Kt.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:Kt=>{Kt.key==="Escape"&&(Kt.stopPropagation(),h?p(""):x(!1))}}),S.length>0?s.jsx("button",{type:"button",onClick:()=>p(""),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(T,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[207]=h,e[208]=g,e[209]=y,e[210]=w,e[211]=S,e[212]=x,e[213]=p,e[214]=n,e[215]=Dt):Dt=e[215];let fs;return e[216]!==Ht||e[217]!==Dt?(fs=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:[Ht,Dt]})}),e[216]=Ht,e[217]=Dt,e[218]=fs):fs=e[218],fs}function M1(t){return!t}function R1(t){return t.toggleStickyZoneHeaders}function O1(t){return t.stickyZoneHeaders}function F1(t){return t.setSessionGroupingMode}function B1(t){return t.sessionGroupingMode}function L1(t){return t.setProjectSortOrder}function _1(t){return t.projectSortOrder}function $1(t){return t.toggleRecentSection}function z1(t){return t.showRecentSection}function W1(t){const e=tt.c(8),{t:n}=gt(),r=t.onNewSession;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(T,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=o):o=e[0];let i;e[1]!==n?(i=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("span",{className:"truncate",children:i}),e[3]=i,e[4]=c):c=e[4];let a;return e[5]!==t.onNewSession||e[6]!==c?(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:[o,c]})}),e[5]=t.onNewSession,e[6]=c,e[7]=a):a=e[7],a}const Wc=7;function U1(t){const{sections:e,renderSessionNode:n,editingId:r,openSidebarMenuKey:o,variant:i="section",initialVisibleCount:c=Wc,batchSize:a=Wc}=t,{t:d}=gt(),u=Ns(j=>j.stickyZoneHeaders),[m,f]=l.useState(new Set),[g,x]=l.useState(new Map),w=i==="flat",S=l.useCallback(j=>{x(N=>{if(!N.has(j))return N;const C=new Map(N);return C.delete(j),C})},[]),p=l.useCallback(j=>{S(j),f(N=>{const C=new Set(N);return C.has(j)?C.delete(j):C.add(j),C})},[S]),h=l.useCallback((j,N,C)=>{x(k=>{const D=Math.min(C,N+a),M=new Map(k);return M.set(j,D),M})},[a]),y=l.useCallback(j=>{const N=new Set;Pa(j,r,N);const C=yo(j,o,"recent",!1),k=new WeakMap,D=A=>{k.set(A,gi(A)),A.children.forEach(D)};j.forEach(D);const M=A=>({subtreeContainsEditing:N,menuOpenSessionId:C,nodeStructureKey:k.get(A)??"",childRenderExtrasFor:M});return A=>({subtreeContainsEditing:N,menuOpenSessionId:C,nodeStructureKey:k.get(A)??"",childRenderExtrasFor:M})},[r,o]),v=e.filter(j=>j.items.length>0);return v.length===0?null:s.jsx("div",{className:Ce(w?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:v.map(j=>{const N=m.has(j.key),C=Math.max(c,g.get(j.key)??c),k=j.items.slice(0,C),D=j.items.length-k.length,M=!w&&j.items.length>c&&D===0,A=y(k.map(L=>L.node)),_=L=>n(L.node,0,L.groupDirectory,L.projectId,!1,L.secondaryMeta,"recent",A(L.node));return w?s.jsxs("div",{className:"space-y-0.5",children:[k.map(_),D>0?s.jsx("button",{type:"button",onClick:()=>h(j.key,k.length,j.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null]},j.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsx("div",{className:Ce("-ml-2.5 -mr-2",u&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":u?"true":void 0,children:s.jsxs("button",{type:"button",onClick:()=>p(j.key),className:"group flex w-full items-center gap-1.5 py-1 pl-4 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!N,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(T,{name:"history",className:Ce("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:N?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:j.title})]})}),N?null:s.jsxs("div",{className:Ce("space-y-0.5"),children:[k.map(_),D>0?s.jsx("button",{type:"button",onClick:()=>h(j.key,k.length,j.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null,M?s.jsx("button",{type:"button",onClick:()=>S(j.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showFewer")}):null]})]},j.key)})})}const oa="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 V1(t){const e=tt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:a}=t,d=c===void 0?!0:c,u=a===void 0?!0:a,{t:m}=gt();if(!d&&!u)return null;let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(f=d?s.jsxs(s.Fragment,{children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:oa,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(T,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:oa,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(T,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:oa,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(T,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=f):f=e[5];let g;e[6]!==i||e[7]!==u||e[8]!==m?(g=u?s.jsx(et,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=u,e[8]=m,e[9]=g):g=e[9];let x;return e[10]!==f||e[11]!==g?(x=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,g]}),e[10]=f,e[11]=g,e[12]=x):x=e[12],x}const of=t=>{const e=tt.c(22),{id:n,projectLabel:r,projectIcon:o,projectColor:i,projectIconImage:c,projectIconBackground:a,isCollapsed:d,alwaysShowActions:u}=t,m=u===void 0?!1:u,{currentTheme:f}=Ir(),g=o?Ga[o]:null,x=i?qa[i]??null:null,w=d!==void 0,S=w?m?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let p;e[0]!==m||e[1]!==w||e[2]!==d?(p=w?s.jsx("span",{className:Ce("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(T,{name:d?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=m,e[1]=w,e[2]=d,e[3]=p):p=e[3];let h;e[4]!==m||e[5]!==f||e[6]!==w||e[7]!==x||e[8]!==S||e[9]!==n||e[10]!==a||e[11]!==c||e[12]!==g?(h=c?s.jsx("span",{className:Ce("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",w&&m?"hidden":"inline-flex",S),style:a?{backgroundColor:a}:void 0,children:s.jsx(Ya,{project:{id:n,iconImage:c},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:g?s.jsx(T,{name:g,className:"h-3.5 w-3.5",style:x?{color:x}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:x?{color:x}:void 0})})}):g?s.jsx(T,{name:g,className:Ce("h-3.5 w-3.5",S),style:x?{color:x}:void 0}):s.jsx(T,{name:"folder",className:Ce("h-3.5 w-3.5 text-muted-foreground/80",S),style:x?{color:x}:void 0}),e[4]=m,e[5]=f,e[6]=w,e[7]=x,e[8]=S,e[9]=n,e[10]=a,e[11]=c,e[12]=g,e[13]=h):h=e[13];let y;e[14]!==p||e[15]!==h?(y=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[p,h]}),e[14]=p,e[15]=h,e[16]=y):y=e[16];let v;e[17]!==r?(v=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=v):v=e[18];let j;return e[19]!==y||e[20]!==v?(j=s.jsxs(s.Fragment,{children:[y,v]}),e[19]=y,e[20]=v,e[21]=j):j=e[21],j},H1=t=>{const e=tt.c(59),{id:n,disabled:r,projectLabel:o,projectDescription:i,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,isRepo:f,isDesktopShell:g,hideDirectoryControls:x,alwaysShowActions:w,onToggle:S,onNewSession:p,onNewWorktreeSession:h,onManageWorktrees:y,onRenameStart:v,onClose:j,sentinelRef:N,children:C,showCreateButtons:k,hideHeader:D,openSidebarMenuKey:M,setOpenSidebarMenuKey:A,statusIndicator:_}=t,L=r===void 0?!1:r,F=k===void 0?!0:k,$=D===void 0?!1:D,W=_===void 0?null:_,{t:U}=gt(),K=Ns(q1);let b;e[0]!==L||e[1]!==n?(b={id:n,disabled:L},e[0]=L,e[1]=n,e[2]=b):b=e[2];const{attributes:P,listeners:V,setNodeRef:G,transform:X,transition:J,isDragging:ee}=Za(b),le=l.useRef(!1),oe=`project:${n}`,Ae=M===oe,[Se,Y]=l.useState(!1);let je;e[3]!==oe||e[4]!==A?(je=se=>{se&&Y(!1),A(se?oe:null)},e[3]=oe,e[4]=A,e[5]=je):je=e[5];const me=je;let z;e[6]!==x||e[7]!==f||e[8]!==j||e[9]!==y||e[10]!==p||e[11]!==v||e[12]!==F||e[13]!==U?(z=se=>s.jsxs(s.Fragment,{children:[F&&!f&&!x&&p&&s.jsxs(se,{onClick:p,children:[s.jsx(T,{name:"add",className:"mr-1.5 h-4 w-4"}),U("sessions.sidebar.project.actions.newSession")]}),f&&!x&&y&&s.jsxs(se,{onClick:y,children:[s.jsx(T,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),U("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(se,{onClick:v,children:[s.jsx(T,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),U("sessions.sidebar.project.actions.edit")]}),s.jsxs(se,{onClick:j,className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1.5 h-4 w-4"}),U("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=x,e[7]=f,e[8]=j,e[9]=y,e[10]=p,e[11]=v,e[12]=F,e[13]=U,e[14]=z):z=e[14];const Z=z,ne=Y1,fe=Q1,xe=X1;let Te;e[15]===Symbol.for("react.memo_cache_sentinel")?(Te=se=>{(se.button===2||se.button===0&&se.ctrlKey)&&(le.current=!0)},e[15]=Te):Te=e[15];const be=Te;let De;e[16]!==S?(De=se=>{if(se.currentTarget.blur(),le.current){le.current=!1;return}S()},e[16]=S,e[17]=De):De=e[17];const Ee=De;let Re;e[18]!==X?(Re=el.Transform.toString(X),e[18]=X,e[19]=Re):Re=e[19];let de;e[20]!==Re||e[21]!==J?(de={transform:Re,transition:J},e[20]=Re,e[21]=J,e[22]=de):de=e[22];const H=ee&&"opacity-30";let Ne;e[23]!==H?(Ne=Ce("relative",H),e[23]=H,e[24]=Ne):Ne=e[24];let he;e[25]!==w||e[26]!==P||e[27]!==me||e[28]!==Ee||e[29]!==x||e[30]!==$||e[31]!==n||e[32]!==m||e[33]!==Se||e[34]!==g||e[35]!==Ae||e[36]!==f||e[37]!==V||e[38]!==p||e[39]!==h||e[40]!==a||e[41]!==i||e[42]!==c||e[43]!==u||e[44]!==d||e[45]!==o||e[46]!==Z||e[47]!==N||e[48]!==F||e[49]!==W||e[50]!==K||e[51]!==U?(he=$?null:s.jsxs(s.Fragment,{children:[g&&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(bu,{open:Se,onOpenChange:Y,children:[s.jsx(xu,{render:s.jsx("div",{className:Ce("-ml-2.5 -mr-2 text-left group/project select-none",K&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":K?"true":void 0,onContextMenu:se=>{x||(se.preventDefault(),Y(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...P,children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:be,onClick:Ee,...V,className:Ce("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!x?w?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":w?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(of,{id:n,projectLabel:o,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,alwaysShowActions:w}),W?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:W}):null]})}),s.jsx(mt,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:Ce("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",F?"right-7":"right-0.5"),children:[F&&f&&!x&&h?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),h()},className:Ce("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",w?"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":U("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(T,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:U("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,x?null:s.jsxs(yn,{open:Ae,onOpenChange:me,children:[s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce("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",Ae?"opacity-100 pointer-events-auto":w?"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":U("sessions.sidebar.project.actions.projectMenu"),onPointerDown:fe,onMouseDown:xe,onClick:ne,children:s.jsx(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(bn,{align:"end",className:"min-w-[180px]",children:Z(qt)})]})]}),F&&p?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:se=>{se.stopPropagation(),p()},className:Ce("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",w?"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":U(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(T,{name:"add",className:"h-4 w-4"})})}),s.jsx(mt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:U(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(pu,{className:"min-w-[180px]",children:Z(gu)})]})]}),e[25]=w,e[26]=P,e[27]=me,e[28]=Ee,e[29]=x,e[30]=$,e[31]=n,e[32]=m,e[33]=Se,e[34]=g,e[35]=Ae,e[36]=f,e[37]=V,e[38]=p,e[39]=h,e[40]=a,e[41]=i,e[42]=c,e[43]=u,e[44]=d,e[45]=o,e[46]=Z,e[47]=N,e[48]=F,e[49]=W,e[50]=K,e[51]=U,e[52]=he):he=e[52];let ve;return e[53]!==C||e[54]!==G||e[55]!==de||e[56]!==Ne||e[57]!==he?(ve=s.jsxs("div",{ref:G,style:de,className:Ne,children:[he,C]}),e[53]=C,e[54]=G,e[55]=de,e[56]=Ne,e[57]=he,e[58]=ve):ve=e[58],ve},K1=t=>{const e=tt.c(21),{id:n,disabled:r,children:o}=t,i=r===void 0?!1:r;let c;e[0]!==i||e[1]!==n?(c={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=c):c=e[2];const{listeners:a,setNodeRef:d,setActivatorNodeRef:u,transform:m,transition:f,isDragging:g}=Za(c);let x;e[3]!==a||e[4]!==u?(x={listeners:a,setActivatorNodeRef:u},e[3]=a,e[4]=u,e[5]=x):x=e[5];const w=x;let S;e[6]!==m?(S=el.Transform.toString(m),e[6]=m,e[7]=S):S=e[7];let p;e[8]!==S||e[9]!==f?(p={transform:S,transition:f},e[8]=S,e[9]=f,e[10]=p):p=e[10];const h=g&&"opacity-50";let y;e[11]!==h?(y=Ce("space-y-0.5 rounded-md",h),e[11]=h,e[12]=y):y=e[12];let v;e[13]!==o||e[14]!==w?(v=typeof o=="function"?o(w):o,e[13]=o,e[14]=w,e[15]=v):v=e[15];let j;return e[16]!==d||e[17]!==p||e[18]!==y||e[19]!==v?(j=s.jsx("div",{ref:d,style:p,className:y,children:v}),e[16]=d,e[17]=p,e[18]=y,e[19]=v,e[20]=j):j=e[20],j},G1=l.memo(K1);function q1(t){return t.stickyZoneHeaders}function Y1(t){t.stopPropagation()}function Q1(t){t.stopPropagation()}function X1(t){t.stopPropagation()}const J1=48,Z1=32,eS=24,Uc=(t,e)=>Qa(t.label?.trim()||ur(t.normalizedPath,e)||t.normalizedPath);function tS(t){In("ui.sidebar_projects_list.render");const{t:e}=gt(),n=t.isDesktopShellRuntime&&t.stickyZoneHeaders,r=ui(Wr(wa,{activationConstraint:{distance:8}}),Wr(jg,{coordinateGetter:kg})),o=ui(Wr(wa,{activationConstraint:{distance:8}})),i=l.useRef(new Map),c=l.useRef(t.getOrderedGroups);c.current!==t.getOrderedGroups&&(c.current=t.getOrderedGroups,i.current.clear());const a=(p,h)=>{const y=i.current,v=y.get(p);if(v&&v.groups===h)return v.ordered;const j=t.getOrderedGroups(p,h);if(y.set(p,{groups:h,ordered:j}),y.size>256){const N=y.keys().next().value;N!==void 0&&y.delete(N)}return j},d=l.useRef(null),u=l.useRef(0),m=l.useCallback(p=>{const y=p.scrollTop>1?Math.min(Z1+p.scrollTop,J1):0;u.current=y,p.style.setProperty("--scroll-shadow-top-size",`${y}px`),p.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(y-8,0),eS)}px`)},[]),f=l.useCallback(p=>{p.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||p.clientY-p.currentTarget.getBoundingClientRect().top>=u.current||(p.preventDefault(),p.stopPropagation())},[]),g=t.projectSections.length>0&&t.sectionsForRender.length>0;l.useLayoutEffect(()=>{n&&g&&d.current&&m(d.current)},[n,g,m]);let x=null;for(const p of t.projectSections)t.stuckProjectHeaders.has(p.project.id)&&(x=p.project);const w=x??(t.hasSharedSessions?null:t.sectionsForRender[0]?.project??null),S=w?Uc(w,t.homeDirectory):null;return t.sharedSessionsOnly?s.jsxs(Xn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Ce("space-y-1 pb-1 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.hasSharedSessions?null:t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState]}):t.projectSections.length===0?s.jsxs(Xn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Ce("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx(Xn,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Ce("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs("div",{className:"oc-sticky-fade-root relative flex min-h-0 flex-1",onPointerDownCapture:n?f:void 0,onClickCapture:n?f:void 0,onContextMenuCapture:n?f:void 0,children:[s.jsxs(Xn,{ref:d,useScrollShadow:!0,hideTopScrollShadow:!n,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Ce("oc-sidebar-scroller oc-sticky-fade-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]",(t.mobileVariant,"")),style:n?{"--scroll-shadow-top-size":"0px"}:void 0,onScroll:n?p=>m(p.currentTarget):void 0,children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const p=t.sectionsForRender.find(j=>j.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!p)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const h=p.groups.find(j=>j.isMain&&j.sessions.length>0)??p.groups.find(j=>j.sessions.length>0)??p.groups.find(j=>j.isMain)??p.groups[0];if(!h)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const y=p.groups.find(j=>j.isArchivedBucket);return[h,...y&&y.id!==h.id?[y]:[]].map(j=>{const N=`${p.project.id}:${j.id}`,C=j.id===h.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(j,N,p.project.id,C,null,!0,d)},N)})})()}):s.jsxs(fi,{sensors:r,collisionDetection:mi,onDragEnd:p=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:h,over:y}=p;if(!y||h.id===y.id)return;const v=t.sectionsForRender.findIndex(N=>N.project.id===h.id),j=t.sectionsForRender.findIndex(N=>N.project.id===y.id);v===-1||j===-1||v===j||t.reorderProjects(v,j)},children:[s.jsx(Sa,{items:t.sectionsForRender.map(p=>p.project.id),strategy:ja,children:t.sectionsForRender.map(p=>{const h=p.project,y=h.id,v=Uc(h,t.homeDirectory),j=ii(h.normalizedPath,t.homeDirectory),N=t.collapsedProjects.has(y),C=t.projectRepoStatus.get(y);return s.jsx(H1,{id:y,disabled:t.projectSortOrder!=="manual",projectLabel:v,projectDescription:j,projectIcon:h.icon,projectColor:h.color,projectIconImage:h.iconImage,projectIconBackground:h.iconBackground,isCollapsed:N,isRepo:!!C,isDesktopShell:t.isDesktopShellRuntime,hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,statusIndicator:N?t.renderProjectStatusIndicator?.(y,p.groups):null,onToggle:()=>t.toggleProject(y),onNewSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({selectedProjectId:y,directoryOverride:h.normalizedPath})},onNewWorktreeSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onManageWorktrees:()=>t.openWorktreesPage(y),onRenameStart:()=>t.openProjectEditDialog(y),onClose:()=>t.removeProject(y),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(y,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:N?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const k=a(y,p.groups),D=k.find(A=>A.isMain)??null,M=D?k.filter(A=>A.id!==D.id):k;return s.jsxs(fi,{sensors:o,collisionDetection:mi,onDragEnd:A=>{if(t.isInlineEditing)return;const{active:_,over:L}=A;if(!L||_.id===L.id)return;const F=M.findIndex(K=>K.id===_.id),$=M.findIndex(K=>K.id===L.id);if(F===-1||$===-1||F===$)return;const W=Cu(M,F,$).map(K=>K.id),U=D?[D.id,...W]:W;t.setGroupOrderByProject(K=>{const b=new Map(K);return b.set(y,U),b})},children:[D?t.renderGroupSessions(D,`${y}:${D.id}`,y,!0,null,void 0,d):null,s.jsx(Sa,{items:M.map(A=>A.id),strategy:ja,children:M.map(A=>{const _=`${y}:${A.id}`;return s.jsx(G1,{id:A.id,disabled:t.isInlineEditing,children:L=>t.renderGroupSessions(A,_,y,!1,L,void 0,d)},A.id)})}),s.jsx(va,{dropAnimation:null})]})})()})},y)})}),s.jsx(va,{dropAnimation:null})]})]}),n&&(w||t.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:w&&S?s.jsx(of,{id:w.id,projectLabel:S,projectIcon:w.icon,projectColor:w.color,projectIconImage:w.iconImage,projectIconBackground:w.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(T,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:e("sessions.sidebar.activity.recentTitle")})]})}):null]})}const sS=l.memo(tS),nS=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const i=e.get(o);if(i)for(const c of i)r.has(c)||(r.add(c),n.push(c))}return n},Cs=Qr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const i=e(),c=new Set(i.selectedIds);let a=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),a=r,d=null):a===null&&r!==null&&(a=r);const m=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const g of m)c.delete(g);d===n&&(d=null)}else{for(const g of m)c.add(g);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:a,anchorId:d})},setRange:(n,r,o,i,c)=>{const a=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),m=o.indexOf(r);if(u<0||m<0)return;const[f,g]=u<=m?[u,m]:[m,u],x=o.slice(f,g+1),w=nS(x,c),p=i!==null&&a.scopeKey!==null&&i!==a.scopeKey?new Set:new Set(a.selectedIds);for(const h of w)p.add(h);t({selectedIds:p,scopeKey:i??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 o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}}));let Ia=!1;const Ta=new Set;let Vc=!1;function rS(){for(const t of Ta)t()}function dl(t){Ia!==t&&(Ia=t,rS())}function oS(t){t.key==="Shift"&&dl(!0)}function iS(t){t.key==="Shift"&&dl(!1)}function aS(){dl(!1)}function lS(){Vc||typeof window>"u"||(Vc=!0,window.addEventListener("keydown",oS),window.addEventListener("keyup",iS),window.addEventListener("blur",aS))}function cS(t){return lS(),Ta.add(t),()=>{Ta.delete(t)}}function dS(){return Ia}function uS(){return!1}function fS(){return He.useSyncExternalStore(cS,dS,uS)}const mS=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,af=/^g[1-9]\d*$/,ao=(t,e,n,r,o)=>{if(!mS.test(t)||e!==void 0&&!af.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Zo=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 ao(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,d,u]=e;return af.test(a)?ao(n,a,d,u,void 0):ao(n,void 0,a,d,u)}const[,r,o,i,c]=e;return r===""?ao(n,void 0,o,i,c):ao(n,r,o,i,c)},hS=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("/")},pS=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},lf=t=>{const e=tt.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:a}=t,{t:d}=gt(),u=Vt(gS),m=Vt(xS),f=Vt(bS);let g;e[0]!==u?(g=u(),e[0]=u,e[1]=g):g=e[1];const x=g;let w;e[2]!==x?(w=x.filter(yS),e[2]=x,e[3]=w):w=e[3];const S=w;let p,h;e[4]!==x.length||e[5]!==m?(p=()=>{x.length===0&&m()},h=[x.length,m],e[4]=x.length,e[5]=m,e[6]=p,e[7]=h):(p=e[6],h=e[7]),l.useEffect(p,h);let y,v;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==S||e[12]!==n?(y=()=>{if(i)return;const L=n.trim();if(L.length>0&&S.some(W=>W.name===L))return;const F=typeof f=="string"&&f.trim().length>0?f.trim():null;if(F&&S.some(W=>W.name===F)){r(F);return}const $=S[0]?.name;$&&r($)},v=[f,i,r,S,n],e[8]=f,e[9]=i,e[10]=r,e[11]=S,e[12]=n,e[13]=y,e[14]=v):(y=e[13],v=e[14]),l.useEffect(y,v);const j=n.trim().length>0?n:void 0;let N;e[15]!==o?(N=Ce("max-w-full",o),e[15]=o,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(As,{placeholder:C}),e[19]=C,e[20]=k):k=e[20];let D;e[21]!==c||e[22]!==N||e[23]!==k?(D=s.jsx(Hs,{id:c,size:"lg",className:N,children:k}),e[21]=c,e[22]=N,e[23]=k,e[24]=D):D=e[24];let M;e[25]!==S?(M=S.length>0&&s.jsx(xa,{children:S.map(wS)}),e[25]=S,e[26]=M):M=e[26];let A;e[27]!==a||e[28]!==M?(A=s.jsx(Ks,{fitContent:!0,portalToBody:a,children:M}),e[27]=a,e[28]=M,e[29]=A):A=e[29];let _;return e[30]!==i||e[31]!==r||e[32]!==j||e[33]!==D||e[34]!==A?(_=s.jsxs(Vs,{value:j,onValueChange:r,disabled:i,children:[D,A]}),e[30]=i,e[31]=r,e[32]=j,e[33]=D,e[34]=A,e[35]=_):_=e[35],_};function gS(t){return t.getVisibleAgents}function xS(t){return t.loadAgents}function bS(t){return t.currentAgentName}function yS(t){return ru(t.mode)}function wS(t){return s.jsx(ls,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const vS="h-7",ho=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,SS=t=>{const e=tt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,a=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=Ce("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",vS),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(oi,{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 f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(T,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let g;e[6]!==i?(g=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=g):g=e[7];let x;return e[8]!==u||e[9]!==m||e[10]!==g?(x=s.jsxs("div",{className:d,children:[u,m,g]}),e[8]=u,e[9]=m,e[10]=g,e[11]=x):x=e[11],x},cf=t=>{const e=tt.c(120),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:a,showChips:d,maxModels:u,addButtonClassName:m,dropdownSide:f,dropdownClassName:g,containerClassName:x,triggerIcon:w}=t,S=d===void 0?!0:d,p=f===void 0?"top":f,{t:h}=gt(),y=Vt(jS),v=Vt(kS),j=pe(CS),N=pe(NS),{favoriteModelsList:C,recentModelsList:k}=yh(),D=pe(AS),M=pe(DS),[A,_]=l.useState(!1),[L,F]=l.useState(""),[$,W]=l.useState(null),U=l.useRef(null),K=l.useRef(null),b=u===1,P=u===void 0||n.length<u||b;let V;if(e[0]!==n){V=new Map;for(const ke of n){const we=`${ke.providerID}:${ke.modelID}`;V.set(we,(V.get(we)||0)+1)}e[0]=n,e[1]=V}else V=e[1];const G=V;let X;e[2]!==n?(X=ke=>n.filter(qe=>qe.providerID===ke.providerID&&qe.modelID===ke.modelID).findIndex(qe=>qe.instanceId===ke.instanceId)+1,e[2]=n,e[3]=X):X=e[3];const J=X;let ee,le;e[4]!==p||e[5]!==A?(ee=()=>{if(!A||!K.current)return;const ke=K.current.getBoundingClientRect();if(p==="bottom"){const ot=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-ke.bottom-16-112;W(Math.max(160,Math.min(320,ot)));return}let we=K.current.parentElement;for(;we&&!(we.getAttribute("role")==="dialog"||we.hasAttribute("data-scroll-shadow"));){const st=getComputedStyle(we);if(st.overflow==="auto"||st.overflow==="hidden"||st.overflowY==="auto"||st.overflowY==="hidden")break;we=we.parentElement}const qe=we?we.getBoundingClientRect().top:0,Je=ke.top-qe-16;W(Math.max(150,Math.min(300,Je)))},le=[p,A],e[4]=p,e[5]=A,e[6]=ee,e[7]=le):(ee=e[6],le=e[7]),l.useEffect(ee,le);let oe,Ae;e[8]!==P||e[9]!==A?(oe=()=>{!P&&A&&(_(!1),F(""))},Ae=[P,A],e[8]=P,e[9]=A,e[10]=oe,e[11]=Ae):(oe=e[10],Ae=e[11]),l.useEffect(oe,Ae);let Se,Y;e[12]!==A?(Se=()=>{if(!A)return;const ke=we=>{U.current&&!U.current.contains(we.target)&&(_(!1),F(""))};return document.addEventListener("mousedown",ke),()=>document.removeEventListener("mousedown",ke)},Y=[A],e[12]=A,e[13]=Se,e[14]=Y):(Se=e[13],Y=e[14]),l.useEffect(Se,Y);let je;e[15]!==b||e[16]!==r||e[17]!==i||e[18]!==n.length?(je=ke=>{const we={providerID:ke.providerID,modelID:ke.modelID,displayName:ke.model.name||ke.modelID,instanceId:ho()};b&&n.length>0&&i?i(0,we):r(we),b&&(_(!1),F(""))},e[15]=b,e[16]=r,e[17]=i,e[18]=n.length,e[19]=je):je=e[19];const me=je;let z;e[20]!==h?(z=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=z):z=e[21];let Z;e[22]!==h?(Z=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=Z):Z=e[23];let ne;e[24]!==h?(ne=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=ne):ne=e[25];let fe;e[26]!==h?(fe=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=fe):fe=e[27];let xe;e[28]!==h?(xe=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=xe):xe=e[29];let Te;e[30]!==h?(Te=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=Te):Te=e[31];let be;e[32]!==h?(be=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=be):be=e[33];let De;e[34]!==h?(De=h("chat.modelControls.capabilities"),e[34]=h,e[35]=De):De=e[35];let Ee;e[36]!==h?(Ee=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=Ee):Ee=e[37];let Re;e[38]!==h?(Re=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=Re):Re=e[39];let de;e[40]!==h?(de=h("chat.modelControls.input"),e[40]=h,e[41]=de):de=e[41];let H;e[42]!==h?(H=h("chat.modelControls.output"),e[42]=h,e[43]=H):H=e[43];let Ne;e[44]!==h?(Ne=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Ne):Ne=e[45];let he;e[46]!==z||e[47]!==Z||e[48]!==ne||e[49]!==fe||e[50]!==xe||e[51]!==Te||e[52]!==be||e[53]!==De||e[54]!==Ee||e[55]!==Re||e[56]!==de||e[57]!==H||e[58]!==Ne?(he={searchPlaceholder:z,noResults:Z,favorites:ne,recent:fe,keyboardHint:xe,favorite:Te,unfavorite:be,capabilities:De,capabilityToolCalling:Ee,capabilityReasoning:Re,input:de,output:H,costPerMillion:Ne},e[46]=z,e[47]=Z,e[48]=ne,e[49]=fe,e[50]=xe,e[51]=Te,e[52]=be,e[53]=De,e[54]=Ee,e[55]=Re,e[56]=de,e[57]=H,e[58]=Ne,e[59]=he):he=e[59];const ve=he;let se;e[60]!==x?(se=Ce("relative",x),e[60]=x,e[61]=se):se=e[61];const Q=A?"":void 0;let ye;e[62]!==m?(ye=Ce(ou({size:"default"}),"w-fit",m),e[62]=m,e[63]=ye):ye=e[63];const re=!P;let R;e[64]!==A?(R=()=>{_(!A)},e[64]=A,e[65]=R):R=e[65];let ce;e[66]!==w?(ce=w??s.jsx(T,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=w,e[67]=ce):ce=e[67];let Me;e[68]!==a||e[69]!==h?(Me=a??h("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=h,e[70]=Me):Me=e[70];let ge;e[71]!==Q||e[72]!==ye||e[73]!==re||e[74]!==R||e[75]!==ce||e[76]!==Me?(ge=s.jsxs("button",{ref:K,type:"button","data-popup-open":Q,className:ye,disabled:re,onClick:R,children:[ce,Me]}),e[71]=Q,e[72]=ye,e[73]=re,e[74]=R,e[75]=ce,e[76]=Me,e[77]=ge):ge=e[77];let te;e[78]!==$||e[79]!==P||e[80]!==g||e[81]!==p||e[82]!==C||e[83]!==me||e[84]!==D||e[85]!==N||e[86]!==A||e[87]!==ve||e[88]!==G||e[89]!==v||e[90]!==M||e[91]!==y||e[92]!==k||e[93]!==L||e[94]!==j?(te=A?s.jsx("div",{className:Ce("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",p==="top"?"bottom-full mb-1":"top-full mt-1",g),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(wh,{providers:y,providerOrder:M,favoriteModels:C,recentModels:k,modelsMetadata:v,hiddenModels:D,searchQuery:L,onSearchQueryChange:F,onSelect:me,labels:ve,selectionCount:ke=>G.get(`${ke.providerID}:${ke.modelID}`)||0,disabled:!P,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:$?`${$}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:A,isFavorite:ke=>N(ke.providerID,ke.modelID),onToggleFavorite:ke=>j(ke.providerID,ke.modelID),onEscape:()=>{_(!1),F("")}})}):null,e[78]=$,e[79]=P,e[80]=g,e[81]=p,e[82]=C,e[83]=me,e[84]=D,e[85]=N,e[86]=A,e[87]=ve,e[88]=G,e[89]=v,e[90]=M,e[91]=y,e[92]=k,e[93]=L,e[94]=j,e[95]=te):te=e[95];let ae;e[96]!==se||e[97]!==ge||e[98]!==te?(ae=s.jsxs("div",{className:se,ref:U,children:[ge,te]}),e[96]=se,e[97]=ge,e[98]=te,e[99]=ae):ae=e[99];let ie;e[100]!==J||e[101]!==G||e[102]!==o||e[103]!==i||e[104]!==y||e[105]!==n||e[106]!==S||e[107]!==h?(ie=S&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((ke,we)=>{const qe=`${ke.providerID}:${ke.modelID}`,Je=G.get(qe)||1,st=J(ke),ot=y.find(it=>it.id===ke.providerID)?.models?.find(it=>it.id===ke.modelID),lt=ot?.variants?Object.keys(ot.variants):[],kt=lt.length>0,nt=ke.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(SS,{model:ke,instanceIndex:st,totalSameModel:Je,onRemove:()=>o(we)}),kt&&s.jsxs(Vs,{value:nt,onValueChange:it=>{if(!i)return;i(we,{...ke,variant:it==="__default__"?void 0:it})},children:[s.jsxs(Hs,{size:"sm",className:"gap-1.5",children:[s.jsx(T,{name:"brain-ai-3",className:Ce("h-3.5 w-3.5 flex-shrink-0",nt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(As,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:it=>it==="__default__"?h("multirun.modelMultiSelect.variant.default"):it})]}),s.jsxs(Ks,{fitContent:!0,children:[s.jsx(ls,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),lt.map(PS)]})]})]},ke.instanceId)})}),e[100]=J,e[101]=G,e[102]=o,e[103]=i,e[104]=y,e[105]=n,e[106]=S,e[107]=h,e[108]=ie):ie=e[108];let E;e[109]!==ae||e[110]!==ie?(E=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[ae,ie]}),e[109]=ae,e[110]=ie,e[111]=E):E=e[111];let I;e[112]!==u||e[113]!==c||e[114]!==n.length||e[115]!==h?(I=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:u}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[112]=u,e[113]=c,e[114]=n.length,e[115]=h,e[116]=I):I=e[116];let ue;return e[117]!==E||e[118]!==I?(ue=s.jsxs("div",{className:"space-y-2",children:[E,I]}),e[117]=E,e[118]=I,e[119]=ue):ue=e[119],ue};function jS(t){return t.providers}function kS(t){return t.modelsMetadata}function CS(t){return t.toggleFavoriteModel}function NS(t){return t.isFavoriteModel}function AS(t){return t.hiddenModels}function DS(t){return t.providerOrder}function PS(t){return s.jsx(ls,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const IS=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
179
|
-
|
|
180
|
-
--- RESULT ${n+1}: ${r} ---
|
|
181
|
-
${e.trim()}
|
|
182
|
-
--- END RESULT ${n+1} ---`},Hc=(t,e)=>Ge.getState().getWorktreeMetadata(t)?.projectDirectory??e,TS=async t=>{const e=t.directory??void 0,n=Sh(t.session.id,e);if(n.length===0&&t.directory){const o=(await en.withDirectory(t.directory,()=>en.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=o.length-1;i>=0;i-=1){const c=o[i];if(c.info?.role==="assistant")return zl(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return zl(jh(o.id,e)).trim()}return""};function ES({session:t,open:e,onOpenChange:n}){const{t:r}=gt(),o=vh(),i=Ms(b=>b.activeSessions),c=Ms(b=>b.archivedSessions),a=Vt(b=>b.providers),d=Vt(b=>b.currentProviderId),u=Vt(b=>b.currentModelId),m=Vt(b=>b.currentAgentName),[f,g]=l.useState(d??""),[x,w]=l.useState(u??""),[S,p]=l.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:ho()}]:[]),[h,y]=l.useState(""),[v,j]=l.useState(m??""),[N,C]=l.useState([]),[k,D]=l.useState(!1),M=l.useMemo(()=>Zo(t.title),[t.title]),A=l.useMemo(()=>{const b=new Map;for(const P of o)b.set(P.id,P);for(const P of i)b.set(P.id,P);for(const P of c)b.set(P.id,P);return t.id&&b.set(t.id,t),Array.from(b.values())},[i,c,o,t]);l.useEffect(()=>{if(!e||!M)return;const b=Ge.getState().getDirectoryForSession(t.id),P=Hc(t.id,b),V=A.map(G=>{const X=Zo(G.title);if(!X||X.groupSlug!==M.groupSlug||X.fusion||(X.runGroup??null)!==(M.runGroup??null))return null;const J=Ge.getState().getDirectoryForSession(G.id)??Gs(G),ee=Hc(G.id,J);return P&&ee&&P!==ee?null:{session:G,directory:J,projectDirectory:ee}}).filter(G=>G!==null).sort((G,X)=>(G.session.time?.created??0)-(X.session.time?.created??0));C(V)},[A,e,M,t.id]);const L=a.find(b=>b.id===f)?.models.find(b=>b.id===x),F=L?.variants?Object.keys(L.variants):[],$=!!(M&&f&&x&&N.length>0&&!k),W=l.useCallback(b=>{p([b]),g(b.providerID),w(b.modelID),y("")},[]),U=S[0]?.displayName||S[0]?.modelID||r("multirun.fusion.model.placeholder"),K=async()=>{if(!(!M||!f||!x)){D(!0);try{const b=await Promise.all(N.map(le=>TS(le))),P=N.map((le,oe)=>({source:le,text:b[oe]??""})).filter(le=>le.text.trim().length>0);if(P.length===0){Ie.error(r("multirun.fusion.toast.noOutputs"));return}const V=N[0]?.projectDirectory??N[0]?.directory??null,G=pS(M.groupSlug,f,x,M.runGroup),[X,J]=await Promise.all([$l("session.fusion.visible"),$l("session.fusion.instructions")]),ee=await Ge.getState().createSession(G,V,null);if(!ee)throw new Error("Failed to create fusion session");Ge.getState().setCurrentSession(ee.id,V),n(!1),await en.sendMessage({id:ee.id,providerID:f,modelID:x,variant:h||void 0,agent:v||void 0,text:X,additionalParts:[{text:J,synthetic:!0},...P.map((le,oe)=>({text:IS(le.source,le.text,oe),synthetic:!0})),{text:`
|
|
183
|
-
|
|
184
|
-
--- FUSION INPUTS END ---
|
|
185
|
-
Now write the final fused answer.`,synthetic:!0}],directory:V??en.getDirectory()})}catch(b){console.error("[MultiRunFusion] Failed to start fusion",b),Ie.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(qs,{open:e,onOpenChange:n,children:s.jsxs(Ys,{className:"max-w-xl overflow-visible",children:[s.jsxs(En,{children:[s.jsx(wn,{children:r("multirun.fusion.title")}),s.jsx(vn,{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(cf,{selectedModels:S,onAdd:W,onUpdate:(b,P)=>W(P),onRemove:()=>{p([]),g(""),w(""),y("")},maxModels:1,addButtonLabel:U,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(oi,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),F.length>0?s.jsxs(Vs,{value:h||"__default__",onValueChange:b=>y(b==="__default__"?"":b),children:[s.jsxs(Hs,{size:"lg",className:"w-fit",children:[s.jsx(T,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(As,{children:b=>b==="__default__"?r("multirun.modelMultiSelect.variant.default"):b})]}),s.jsxs(Ks,{fitContent:!0,portalToBody:!0,children:[s.jsx(ls,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),F.map(b=>s.jsx(ls,{value:b,children:b},b))]})]}):null,s.jsx(lf,{value:v,onChange:j,portalToBody:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count: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(b=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(oi,{providerId:Zo(b.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.session.title||b.session.id}),s.jsx("button",{type:"button",onClick:()=>C(P=>P.filter(V=>V.session.id!==b.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"h-4 w-4"})})]},b.session.id))})]}),s.jsxs(mr,{children:[s.jsx(et,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(et,{onClick:K,disabled:!$,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function MS(t){const e=tt.c(7);let n,r,o,i,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=i,e[4]=c):(n=e[0],r=e[1],o=e[2],i=e[3],c=e[4]);let 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,o,i,c]}),e[5]=t,e[6]=a):a=e[6],a}const Ea=6,_o=14,Kc=Ea+14+6,ia=new WeakMap,RS=t=>{if(typeof window>"u")return;const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;ia.get(n)?.();const r=e.getBoundingClientRect().top;let o=3,i=!1,c=null;const a=()=>{i=!0,c!==null&&window.cancelAnimationFrame(c),c=null,ia.delete(n),n.removeEventListener("wheel",a),n.removeEventListener("touchstart",a)},d=()=>{if(i||!e.isConnected||!n.isConnected){a();return}const u=e.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,In("ui.sidebar.selection_scroll_anchor_adjustment")),o-=1,o<=0){a();return}c=window.requestAnimationFrame(d)};n.addEventListener("wheel",a,{passive:!0}),n.addEventListener("touchstart",a,{passive:!0}),ia.set(n,a),c=window.requestAnimationFrame(d)},OS=l.memo(function(e){const n=tt.c(22),{archiveLabel:r,deleteLabel:o,buttonSizeClass:i,iconSizeClass:c,onPointerDown:a,onMouseDown:d,onArchive:u,onDelete:m}=e,f=fS(),g=f?o:r;let x;n[0]!==u||n[1]!==m||n[2]!==f?(x=C=>{if(f||C.shiftKey){m(C);return}u(C)},n[0]=u,n[1]=m,n[2]=f,n[3]=x):x=n[3];const w=x,S=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let p;n[4]!==i||n[5]!==S?(p=Ce("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",S,i),n[4]=i,n[5]=S,n[6]=p):p=n[6];const h=f?"delete-bin":"archive";let y;n[7]!==c||n[8]!==h?(y=s.jsx(T,{name:h,className:c}),n[7]=c,n[8]=h,n[9]=y):y=n[9];let v;n[10]!==w||n[11]!==g||n[12]!==d||n[13]!==a||n[14]!==p||n[15]!==y?(v=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:p,"aria-label":g,onPointerDown:a,onMouseDown:d,onClick:w,onKeyDown:WS,children:y})}),n[10]=w,n[11]=g,n[12]=d,n[13]=a,n[14]=p,n[15]=y,n[16]=v):v=n[16];let j;n[17]!==g?(j=s.jsx(mt,{side:"left",sideOffset:8,children:g}),n[17]=g,n[18]=j):j=n[18];let N;return n[19]!==v||n[20]!==j?(N=s.jsxs(ut,{children:[v,j]}),n[19]=v,n[20]=j,n[21]=N):N=n[21],N});function FS(t){In("ui.sidebar_session_node.render");const{t:e}=gt(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,pinnedSessionIds:a,expandedParents:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,notifyOnSubtasks:f,editingId:g,setEditingId:x,editTitle:w,setEditTitle:S,handleSaveEdit:p,handleCancelEdit:h,toggleParent:y,handleSessionSelect:v,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:C,copiedSessionId:k,handleCopyShareUrl:D,handleCopySessionId:M,handleUnshareSession:A,openSidebarMenuKey:_,setOpenSidebarMenuKey:L,renamingFolderId:F,getFoldersForScope:$,getSessionFolderId:W,removeSessionFromFolder:U,addSessionToFolder:K,createFolderAndStartRename:b,openContextPanelTab:P,handleDeleteSession:V,handleRestoreSession:G,mobileVariant:X,alwaysShowActions:J,renderSessionNode:ee,secondaryMeta:le,renderContext:oe="project",subtreeContainsEditing:Ae,menuOpenSessionId:Se,childRenderExtrasFor:Y}=t,je=l.useMemo(()=>er(),[]),me=l.useMemo(()=>wi(),[]),z=l.useContext(kh),Z=je?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ne=je?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",fe=je,xe=!c&&!X,Te=je?xe&&fe?"group-hover:pr-18":xe||fe?"group-hover:pr-14":"group-hover:pr-8":xe?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",be=xe?"pr-13":"pr-7",De=l.useRef(!1),[Ee,Re]=l.useState(!1),de=l.useRef(g);de.current=g;const H=l.useRef(null),Ne=l.useRef(p);Ne.current=p;const[he,ve]=l.useState(w),se=l.useRef(he);se.current=he;const Q=l.useRef(null),ye=l.useRef(null),re=n.session,R=re,ce=Yt(l.useCallback(Pe=>{if(le?.projectLabel||!i)return null;const At=Pe.projects.find(Ut=>Ut.id===i);return At?At.label?.trim()||ur(vt(At.path)??At.path,null)||At.path:null},[i,le?.projectLabel])),Me=le?.projectLabel??(ce?Qa(ce):null),ge=le?.branchLabel??n.worktree?.branch??null,te=l.useMemo(()=>{if(je)return null;const Pe=n.worktree?.branch?.trim(),At=vt(n.worktree?.path??null);return Pe&&At?ki(At,Pe):null},[je,n.worktree]),ae=su(te),ie=ae?`var(--pr-${ae.visualState})`:void 0,E=Ns(Pe=>Pe.sessionGroupingMode),I=!!ge&&(oe==="recent"||E==="flat"),ue=l.useMemo(()=>{if(!ae)return null;switch(ae.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return ae.canMerge===!0||ae.mergeableState==="clean"||ae.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return ae.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}},[ae,e]),ke=Ge(Pe=>Pe.currentSessionId===re.id),we=vt(re.directory??null)??vt(o??null),qe=i??we??null,Je=La(we??void 0,{bootstrap:!1}),st=Si(),rt=Cs(Pe=>Pe.enabled),ot=Cs(l.useCallback(Pe=>Pe.selectedIds.has(re.id),[re.id])),lt=Cs(Pe=>Pe.toggleSelected),kt=Cs(Pe=>Pe.setRange),nt=l.useCallback(Pe=>{const At=[],Ut=as=>{as.children.forEach(ps=>{At.push(ps.session.id),Ut(ps)})};return Ut(Pe),At},[]),it=l.useCallback(Pe=>{const At=[],Ut=as=>{as.children.forEach(ps=>{At.push(ps.session),Ut(ps)})};return Ut(Pe),At},[]),[St,It]=l.useState(!1),[Ft,Mt]=l.useState(!0),Ot=`${oe}:${c?"archived":"active"}:${re.id}`,Ke=iu(l.useCallback(Pe=>!!Pe.sessionMemoryState.get(Ch(re.id))?.isZombie,[re.id])),Tt=_d(re.id)?.type??"idle",dt=Tt==="busy"||Tt==="retry",Ct=Nh(re.id,dt),Rt=Ou(re.id),Qt=Ah(re.id,we??void 0,{bootstrap:!1}),Qe=Dh(R),ht=Qe?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(Wl[Qe.status]),"aria-label":e(Wl[Qe.status]),children:s.jsx(T,{name:"target",className:"h-3 w-3",style:{color:Ph[Qe.status]}})}):null,Xe=R.title||e("sessions.sidebar.session.untitled"),_e=n.children.length>0,yt=Ih(a,we,re.id),zt=Ot,Bt=u?!0:d.has(zt),Lt=l.useMemo(()=>y1(n,Bt,we),[Bt,n,we]),_t=Th(Lt),Ht=!!R.parentID,fs=Eh(re.id)>0&&(!Ht||f),Kt=R.time?.updated||R.time?.created||Date.now(),Nt=au(Kt),Zt=Mh(Kt),ss=_===Ot,[Oe,Ue]=l.useState(!1),Ve=ss||Oe,Be=l.useMemo(()=>Zo(R.title)!==null,[R.title]),[We,wt]=l.useState(!1),os=l.useMemo(()=>nt(n).length,[nt,n]),xt=l.useCallback(async Pe=>{const At=[];let Ut=0;for(const as of Pe)try{if(!we)throw new Error("Session directory is required for export");await st.loadCompleteHistory(as.session.id,we);const ps=ha(Je.getState(),as.session.id).list,ws=as.session.title||e("sessions.sidebar.session.export.untitledSubagent"),ks=as.session.agent,Ts=await xt(as.children);Ut+=Ts.skipped,At.push({title:ws,agent:ks,records:ps,children:Ts.children})}catch{Ut+=nt(as).length+1}return{children:At,skipped:Ut}},[nt,Je,we,st,e]),ns=l.useCallback(Pe=>{Pe<=0||Ie.warning(Pe===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Pe}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Pe}))},[e]),ds=l.useCallback(async Pe=>{if(!we){Ie.error(e("sessions.sidebar.session.export.nothingToExport"));return}try{await st.loadCompleteHistory(re.id,we)}catch{Ie.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}const At=ha(Je.getState(),re.id).list;if(At.length===0){Ie.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Ut,as=0;if(Pe&&n.children.length>0){const Ts=await xt(n.children);Ut=Ts.children,as=Ts.skipped}const ps=Tu(At,R.title??null,Ut),ws=Ru(R.title??null),ks=await Mu(ps,ws);if(ks){Ie.success(e("sessions.sidebar.session.export.success"),{action:{label:e(ux()),onClick:()=>{dx(ks).then(Ts=>{Ts||Ie.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),ns(as);return}Eu(ps,ws),Ie.success(e("sessions.sidebar.session.export.success")),ns(as)},[xt,Je,n.children,R.title,re.id,we,ns,st,e]),es=l.useCallback(async()=>{if(n.children.length>0){Mt(!0),It(!0);return}await ds(!1)},[ds,n.children.length]),js=l.useCallback(()=>{we&&Jn("desktop_open_session_mini_chat_window",{sessionId:re.id,directory:we,apiBaseUrl:cr(),clientToken:ri()}).catch(Pe=>{console.warn("[session-sidebar] failed to open mini chat window",Pe)})},[re.id,we]);if(l.useEffect(()=>{if(g!==re.id)return;const Pe=At=>{const as=At.target?.closest?.(`[data-session-rename-form="${CSS.escape(re.id)}"]`);ye.current&&!as&&Ne.current(se.current)};return document.addEventListener("mousedown",Pe),()=>document.removeEventListener("mousedown",Pe)},[g,re.id]),l.useLayoutEffect(()=>{if(g!==re.id){Q.current===re.id&&(Q.current=null);return}Q.current!==re.id&&(Q.current=re.id,ve(w))},[g,w,re.id]),g===re.id)return s.jsx("div",{style:{paddingLeft:Kc+r*_o},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:ye,"data-session-rename-form":re.id,className:"flex w-full items-center gap-2",onSubmit:Pe=>{Pe.preventDefault(),p(he)},children:[s.jsx("input",{value:he,onChange:Pe=>ve(Pe.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:Pe=>{if(Pe.stopPropagation(),Pe.key==="Escape"){h();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(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:h,"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(T,{name:"close",className:"size-4"})})]})})},re.id);const sn=Qt.length,Mn=_t===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:_t}),$n=!Rt&&!dt&&fs&&!ke,Ds=dt||$n,nn=e(dt?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),Sn=s.jsx("span",{className:Ce("h-1.5 w-1.5 rounded-full",dt?"bg-primary":"bg-[var(--status-info)]"),"aria-label":nn,title:nn}),Ps=(dt||$n)&&Ct,rn=!J&&_e&&(Rt||Ds||yt),Qs=yt&&!Rt&&!Ds,on=s.jsx(T,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),an=Rt||Ds||Qs?s.jsx("span",{style:{left:Ea+r*_o},className:Ce("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",rn?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Rt?s.jsx(T,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):Ds?Sn:Qs?on:null}):null,zn=_e&&!J&&(Rt||Ds||yt),Os=_e?s.jsx("span",{role:"button",tabIndex:0,onClick:Pe=>{Pe.stopPropagation(),Pe.currentTarget.blur(),y(zt)},onKeyDown:Pe=>{(Pe.key==="Enter"||Pe.key===" ")&&(Pe.preventDefault(),Pe.stopPropagation(),y(zt))},style:{minWidth:14,minHeight:14,left:Ea+r*_o},className:Ce("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",zn?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Bt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Bt?s.jsx(T,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(T,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ln=Ke?s.jsx(T,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,cn=Pe=>{Pe&&Ue(!1),L(Pe?Ot:null)},q=Pe=>{if(!Pe&&H.current){const{id:At,title:Ut}=H.current;H.current=null,x(At),S(Ut)}},$e=Pe=>{Ue(Pe)},Ze=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),L(ss?null:Ot)},ct=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},Pt=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},jt=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},pt=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},is=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),L(null),V(re,{archivedBucket:c})},vs=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),L(null),V(re,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},rs=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},Is=Pe=>{Pe.preventDefault(),Pe.stopPropagation()},Fs=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),z?.vscode?.executeCommand("openchamber.openSessionInEditor",re.id,Xe)},jn=Pe=>{if(De.current){De.current=!1;return}if(rt){if(Pe?.preventDefault(),Pe?.stopPropagation(),Pe?.shiftKey){const Ut=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(ws=>ws.getAttribute("data-session-row")).filter(ws=>typeof ws=="string"&&ws.length>0),as=Cs.getState().anchorId,ps=new Map;ps.set(re.id,nt(n)),kt(as,re.id,Ut,qe,ps);return}lt(re.id,qe,nt(n));return}Pe?.currentTarget&&RS(Pe.currentTarget),v(re.id,we)},dn=Pe=>{Pe.defaultPrevented||Pe.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||jn(Pe)},Tr=Pe=>{(Pe.button===2||Pe.button===0&&Pe.ctrlKey&&!rt)&&(De.current=!0)},Wn=Pe=>{X&&Pe.pointerType==="touch"&&Re(!0)},un=Pe=>{X&&Pe.pointerType==="touch"&&Re(!1)},kn=({Item:Pe,Separator:At,Sub:Ut,SubTrigger:as,SubContent:ps})=>s.jsxs(s.Fragment,{children:[s.jsxs(Pe,{onClick:()=>{H.current={id:re.id,title:Xe}},className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Pe,{onClick:()=>M(re.id),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(Pe,{onClick:()=>we&&N({directory:we,sessionId:re.id}),className:"[&>svg]:mr-1",children:[yt?s.jsx(T,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(T,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(yt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),R.share?s.jsxs(s.Fragment,{children:[s.jsx(Pe,{onClick:()=>{R.share?.url&&D(R.share.url,re.id)},className:"[&>svg]:mr-1",children:k===re.id?s.jsxs(s.Fragment,{children:[s.jsx(T,{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(T,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Pe,{onClick:()=>A(re.id),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Pe,{onClick:()=>C(R),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Pe,{onClick:()=>{es()},className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),!Ht&&!c&&!je?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Pe,{disabled:!we||dt||Rt,onClick:()=>{!we||dt||Rt||Fu({root:R,descendants:it(n),sourceDirectory:we,successMessage:e("sessions.sidebar.session.moveToWorktree.success"),failureMessage:e("sessions.sidebar.session.moveToWorktree.failed")})},className:"w-full [&>svg]:mr-1",children:[s.jsx(T,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(mt,{side:"right",className:"max-w-72",children:e(Rt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":dt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,Be?s.jsxs(Pe,{onClick:()=>wt(!0),className:"[&>svg]:mr-1",children:[s.jsx(MS,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,we&&!c?(()=>{const ws=[],ks=xs=>{const gs=vt(xs??null);gs&&!ws.includes(gs)&&ws.push(gs)};if(i&&!je){const xs=Yt.getState().projects.find(Cn=>Cn.id===i),gs=vt(xs?.path??null);ks(gs),gs&&(Ge.getState().availableWorktreesByProject.get(gs)??[]).forEach(Cn=>ks(Cn.path))}ks(we);const Ts=ws.flatMap(xs=>$(xs).map(gs=>({scope:xs,folder:gs}))),Bs=Ts.find(({scope:xs,folder:gs})=>W(xs,re.id)===gs.id)??null,pr=ws[0]??we;return s.jsxs(s.Fragment,{children:[s.jsx(At,{}),s.jsxs(Ut,{children:[s.jsxs(as,{className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(ps,{className:"min-w-[180px]",children:[Ts.length===0?s.jsx(Pe,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Ts.map(({scope:xs,folder:gs})=>{const Cn=Bs?.folder.id===gs.id;return s.jsxs(Pe,{onClick:()=>{if(Cn){U(xs,re.id);return}Bs&&Bs.scope!==xs&&U(Bs.scope,re.id),K(xs,gs.id,re.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:gs.name}),Cn?s.jsx(T,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},gs.id)}),s.jsx(At,{}),s.jsxs(Pe,{onClick:()=>{const xs=b(pr);xs&&(Bs&&Bs.scope!==pr&&U(Bs.scope,re.id),K(pr,xs.id,re.id))},children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Bs?s.jsxs(Pe,{onClick:()=>{U(Bs.scope,re.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,je?null:s.jsxs(Pe,{disabled:!we,onClick:()=>{we&&P(we,{mode:"chat",dedupeKey:`session:${re.id}`,label:Xe,sessionTitleFallback:Xe})},className:"[&>svg]:mr-1",children:[s.jsx(T,{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")})]}),me?s.jsxs(Pe,{disabled:!we,onClick:js,className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(At,{}),c?null:s.jsxs(Pe,{className:"[&>svg]:mr-1",onClick:()=>V(re,{archivedBucket:c}),children:[s.jsx(T,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),c?s.jsxs(Pe,{className:"[&>svg]:mr-1",onClick:()=>G(re),children:[s.jsx(T,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(Pe,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>V(re,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(T,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Er=s.jsx(bn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(F||de.current),children:kn({Item:qt,Separator:gn,Sub:Bh,SubTrigger:Lh,SubContent:_h})}),hr=s.jsx(nc,{children:s.jsx(rc,{className:"app-region-no-drag z-50",children:s.jsx(oc,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(F||de.current),style:{color:"var(--surface-elevated-foreground)"},className:Ce(Ul,"min-w-[180px]"),children:kn({Item:({className:Pe,...At})=>s.jsx(Dg,{className:Ce(Rh,Pe),...At}),Separator:({className:Pe,...At})=>s.jsx(Pg,{className:Ce(Oh,Pe),...At}),Sub:Ig,SubTrigger:({className:Pe,children:At,...Ut})=>s.jsxs(Tg,{className:Ce(Fh,Pe),...Ut,children:[At,s.jsx(T,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Pe,children:At,...Ut})=>s.jsx(nc,{children:s.jsx(rc,{className:"app-region-no-drag z-50",children:s.jsx(oc,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Ce(Ul,Pe),...Ut,children:At})})})})})})});return s.jsxs(l.Fragment,{children:[s.jsx(g1,{sessionId:re.id,sessionDirectory:we??null,sessionTitle:Xe,children:s.jsxs(Ng,{open:Oe,onOpenChange:$e,onOpenChangeComplete:q,children:[s.jsxs(Ag,{render:s.jsx("div",{"data-session-row":re.id,"data-session-scope":qe??"","data-session-archived":c?"1":"0",onClick:dn,style:{paddingLeft:Kc+r*_o},className:Ce("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",ke&&!ot&&"bg-primary/10",ot&&"bg-interactive-selection")}),children:[an,Os,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:Wn,onPointerUp:un,onPointerCancel:un,onMouseDown:Tr,onClick:Pe=>jn(Pe),onDoubleClick:Pe=>{Pe.stopPropagation(),j(re.id,Xe)},className:Ce("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]",Ee&&"bg-interactive-hover/70",J?je?Te:be:Te),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:Ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",ke?"text-primary":fs?"text-foreground":"text-foreground/80"),children:Go(Xe,m)}),J?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75",children:Ps?s.jsx(ec,{sessionId:re.id,running:dt}):s.jsxs(s.Fragment,{children:[ht,I?s.jsx(T,{name:"git-branch",className:Ce("h-3 w-3",!ie&&"text-muted-foreground/60"),style:ie?{color:ie}:void 0}):null,Zt]})}):Ps||ht||I?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:Ce("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",Ve?"opacity-0":ne),children:Ps?s.jsx(ec,{sessionId:re.id,running:dt,className:"text-[0.72rem]"}):s.jsxs(s.Fragment,{children:[ht,I?s.jsx(T,{name:"git-branch",className:Ce("h-3 w-3",!ie&&"text-muted-foreground/60"),style:ie?{color:ie}:void 0}):null]})})}):null,sn>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(T,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:sn})]}):null,_t>0?s.jsxs("span",{className:"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",title:Mn,"aria-label":Mn,children:[s.jsx(T,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:_t})]}):null]})})}),je?null:s.jsx(mt,{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:Xe}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:Nt,children:Zt})]}),Me?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(T,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:Me})]}):null,ge?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:ie?{color:ie}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:ge})]}):null,ae&&ue?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(T,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:ie?{color:ie}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:ie?{color:ie}:void 0,children:["#",ae.number," · ",ue]})]}):null]})})]})}),ln&&!X?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:ln}):null,s.jsxs("div",{className:Ce("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Ve||J&&!je?"opacity-100":Ce("opacity-0",Z)),children:[xe?s.jsx(OS,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:J?"h-6 w-6":"h-4 w-4",iconSizeClass:J?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:jt,onMouseDown:pt,onArchive:is,onDelete:vs}):null,fe?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce("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",J?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:rs,onMouseDown:Is,onClick:Fs,onKeyDown:Pe=>Pe.stopPropagation(),children:s.jsx(T,{name:"external-link",className:Ce(J?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(mt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(yn,{open:ss,onOpenChange:cn,onOpenChangeComplete:q,children:[s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce("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",J?"h-6 w-6 opacity-100":Ve?"h-4 w-4 opacity-100":Ce("h-4 w-4 opacity-0",Z)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:ct,onMouseDown:Pt,onClick:Ze,onKeyDown:Pe=>Pe.stopPropagation(),children:s.jsx(T,{name:"more-2",className:Ce(J?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Er]})]})]}),hr]})}),_e&&Bt?n.children.map(Pe=>{const At=Y?Y(Pe):{subtreeContainsEditing:Ae,menuOpenSessionId:Se,nodeStructureKey:""};return ee(Pe,r+1,we??o,i,c,void 0,oe,At)}):null,s.jsx(qs,{open:St,onOpenChange:It,children:s.jsxs(Ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(En,{children:[s.jsx(wn,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(vn,{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:Ft,onChange:Pe=>Mt(Pe.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(mr,{children:[s.jsx(et,{type:"button",onClick:()=>It(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(et,{type:"button",onClick:()=>{It(!1),ds(Ft)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Be?s.jsx(ES,{session:R,open:We,onOpenChange:wt}):null]},re.id)}const Gc=t=>vt(t.session.directory??null),BS=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),LS=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},$o=t=>t.menuOpenSessionId??LS(t),zo=(t,e,n)=>e?n.has(t.node.session.id)?!0:Yn(t.node,e):!1,Ma=(t,e,n,r,o)=>{if(t.session.id!==e.session.id)return!0;const i=o(t);if(n.has(i)!==r.has(i)||t.children.length!==e.children.length)return!0;for(let c=0;c<t.children.length;c+=1)if(Ma(t.children[c],e.children[c],n,r,o))return!0;return!1},_S=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return Ma(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||Ma(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},$S=(t,e)=>{if(t.node.session.id!==e.node.session.id||t.node.session!==e.node.session||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||Gc(t.node)!==Gc(e.node)||!BS(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&nf(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&_S(t,e)||t.editingId!==e.editingId&&(zo(t,t.editingId,t.subtreeContainsEditing)||zo(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(zo(t,t.editingId,t.subtreeContainsEditing)||zo(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=$o(t),r=$o(e);if(Yn(t.node,n)||Yn(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=$o(t),r=$o(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.togglePinnedSession===e.togglePinnedSession&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.getFoldersForScope===e.getFoldersForScope&&t.getSessionFolderId===e.getSessionFolderId&&t.removeSessionFromFolder===e.removeSessionFromFolder&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.openContextPanelTab===e.openContextPanelTab&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.renderSessionNode===e.renderSessionNode},zS=l.memo(FS,$S);function WS(t){return t.stopPropagation()}function US(t){const e=tt.c(71),{t:n}=gt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:a}=t;let d,u,m,f,g,x,w,S,p,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const P=n("sessions.sidebar.session.untitled");f=qs,p=!!r,e[13]!==o?(h=G=>{G||o(null)},e[13]=o,e[14]=h):h=e[14],m=Ys,w=!1,S="max-w-sm gap-5",u=En;let V;e[15]!==n||e[16]!==r?.archivedBucket?(V=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=V):V=e[17],e[18]!==V?(x=s.jsx(wn,{children:V}),e[18]=V,e[19]=x):x=e[19],d=vn,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||P,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||P,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||P,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||P,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||P}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||P}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=m,e[6]=f,e[7]=g,e[8]=x,e[9]=w,e[10]=S,e[11]=p,e[12]=h}else d=e[3],u=e[4],m=e[5],f=e[6],g=e[7],x=e[8],w=e[9],S=e[10],p=e[11],h=e[12];let y;e[20]!==d||e[21]!==g?(y=s.jsx(d,{children:g}),e[20]=d,e[21]=g,e[22]=y):y=e[22];let v;e[23]!==u||e[24]!==x||e[25]!==y?(v=s.jsxs(u,{children:[x,y]}),e[23]=u,e[24]=x,e[25]=y,e[26]=v):v=e[26];let j;e[27]!==c||e[28]!==i?(j=()=>c(!i),e[27]=c,e[28]=i,e[29]=j):j=e[29];const N=!i;let C;e[30]!==i?(C=i?s.jsx(T,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(T,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,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 D;e[34]!==C||e[35]!==k||e[36]!==j||e[37]!==N?(D=s.jsxs("button",{type:"button",onClick:j,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":N,children:[C,k]}),e[34]=C,e[35]=k,e[36]=j,e[37]=N,e[38]=D):D=e[38];let M;e[39]!==o?(M=()=>o(null),e[39]=o,e[40]=M):M=e[40];let A;e[41]!==n?(A=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=A):A=e[42];let _;e[43]!==M||e[44]!==A?(_=s.jsx("button",{type:"button",onClick:M,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:A}),e[43]=M,e[44]=A,e[45]=_):_=e[45];let L;e[46]!==a?(L=()=>{a()},e[46]=a,e[47]=L):L=e[47];let F;e[48]!==n||e[49]!==r?.archivedBucket?(F=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=F):F=e[50];let $;e[51]!==L||e[52]!==F?($=s.jsx("button",{type:"button",onClick:L,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:F}),e[51]=L,e[52]=F,e[53]=$):$=e[53];let W;e[54]!==_||e[55]!==$?(W=s.jsxs("div",{className:"flex items-center gap-2",children:[_,$]}),e[54]=_,e[55]=$,e[56]=W):W=e[56];let U;e[57]!==D||e[58]!==W?(U=s.jsxs(mr,{className:"w-full sm:items-center sm:justify-between",children:[D,W]}),e[57]=D,e[58]=W,e[59]=U):U=e[59];let K;e[60]!==m||e[61]!==w||e[62]!==U||e[63]!==S||e[64]!==v?(K=s.jsxs(m,{showCloseButton:w,className:S,children:[v,U]}),e[60]=m,e[61]=w,e[62]=U,e[63]=S,e[64]=v,e[65]=K):K=e[65];let b;return e[66]!==f||e[67]!==K||e[68]!==p||e[69]!==h?(b=s.jsx(f,{open:p,onOpenChange:h,children:K}),e[66]=f,e[67]=K,e[68]=p,e[69]=h,e[70]=b):b=e[70],b}function VS(t){const e=tt.c(57),{t:n}=gt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,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 f=m;let g;e[4]!==d||e[5]!==u||e[6]!==n?(g=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]=g):g=e[7];const x=g,w=!!r;let S;e[8]!==o?(S=b=>{b||o(null)},e[8]=o,e[9]=S):S=e[9];let p;e[10]!==f?(p=s.jsx(wn,{children:f}),e[10]=f,e[11]=p):p=e[11];let h;e[12]!==x?(h=s.jsx(vn,{children:x}),e[12]=x,e[13]=h):h=e[13];let y;e[14]!==p||e[15]!==h?(y=s.jsxs(En,{children:[p,h]}),e[14]=p,e[15]=h,e[16]=y):y=e[16];let v;e[17]!==c||e[18]!==i?(v=()=>c(!i),e[17]=c,e[18]=i,e[19]=v):v=e[19];const j=!i;let N;e[20]!==i?(N=i?s.jsx(T,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(T,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,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]!==v||e[26]!==j||e[27]!==N?(k=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":j,children:[N,C]}),e[24]=C,e[25]=v,e[26]=j,e[27]=N,e[28]=k):k=e[28];let D;e[29]!==o?(D=()=>o(null),e[29]=o,e[30]=D):D=e[30];let M;e[31]!==n?(M=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=M):M=e[32];let A;e[33]!==D||e[34]!==M?(A=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:M}),e[33]=D,e[34]=M,e[35]=A):A=e[35];let _;e[36]!==a?(_=()=>{a()},e[36]=a,e[37]=_):_=e[37];let L;e[38]!==d||e[39]!==n?(L=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=L):L=e[40];let F;e[41]!==_||e[42]!==L?(F=s.jsx("button",{type:"button",onClick:_,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:L}),e[41]=_,e[42]=L,e[43]=F):F=e[43];let $;e[44]!==A||e[45]!==F?($=s.jsxs("div",{className:"flex items-center gap-2",children:[A,F]}),e[44]=A,e[45]=F,e[46]=$):$=e[46];let W;e[47]!==k||e[48]!==$?(W=s.jsxs(mr,{className:"w-full sm:items-center sm:justify-between",children:[k,$]}),e[47]=k,e[48]=$,e[49]=W):W=e[49];let U;e[50]!==W||e[51]!==y?(U=s.jsxs(Ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,W]}),e[50]=W,e[51]=y,e[52]=U):U=e[52];let K;return e[53]!==w||e[54]!==U||e[55]!==S?(K=s.jsx(qs,{open:w,onOpenChange:S,children:U}),e[53]=w,e[54]=U,e[55]=S,e[56]=K):K=e[56],K}function HS(t){const e=tt.c(36),{t:n}=gt(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let a;e[0]!==o?(a=N=>{N||o(null)},e[0]=o,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(wn,{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 f;e[9]!==m?(f=s.jsx(vn,{children:m}),e[9]=m,e[10]=f):f=e[10];let g;e[11]!==u||e[12]!==f?(g=s.jsxs(En,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=g):g=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let w;e[16]!==n?(w=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=w):w=e[17];let S;e[18]!==x||e[19]!==w?(S=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:w}),e[18]=x,e[19]=w,e[20]=S):S=e[20];let p;e[21]!==n?(p=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=p):p=e[22];let h;e[23]!==i||e[24]!==p?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:p}),e[23]=i,e[24]=p,e[25]=h):h=e[25];let y;e[26]!==h||e[27]!==S?(y=s.jsxs(mr,{children:[S,h]}),e[26]=h,e[27]=S,e[28]=y):y=e[28];let v;e[29]!==y||e[30]!==g?(v=s.jsxs(Ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[g,y]}),e[29]=y,e[30]=g,e[31]=v):v=e[31];let j;return e[32]!==c||e[33]!==a||e[34]!==v?(j=s.jsx(qs,{open:c,onOpenChange:a,children:v}),e[32]=c,e[33]=a,e[34]=v,e[35]=j):j=e[35],j}const KS=t=>{const e=tt.c(51),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:a,onRemoveFromFolder:d,canRemoveFromFolder:u,onRestore:m,onDelete:f,onDone:g}=t,{t:x}=gt(),w=!!r&&!i;let S;e[0]!==i||e[1]!==x?(S=x(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=x,e[2]=S):S=e[2];const p=S;let h;e[3]!==n||e[4]!==x?(h=x("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=x,e[5]=h):h=e[5];let y;e[6]!==h?(y=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:h}),e[6]=h,e[7]=y):y=e[7];let v;e[8]!==w||e[9]!==u||e[10]!==a||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==x?(v=w?s.jsxs(yn,{children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(xn,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":x("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(T,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(bn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(qt,{disabled:!0,className:"text-muted-foreground",children:x("sessions.sidebar.folders.none")}):o.map(b=>s.jsx(qt,{onClick:()=>c(b.id),children:s.jsx("span",{className:"flex-1 truncate",children:b.name})},b.id)),s.jsx(gn,{}),s.jsxs(qt,{onClick:a,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(qt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=w,e[9]=u,e[10]=a,e[11]=c,e[12]=d,e[13]=o,e[14]=x,e[15]=v):v=e[15];let j;e[16]!==i||e[17]!==m||e[18]!==x?(j=i?s.jsxs(ut,{children:[s.jsx(ft,{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":x("sessions.sidebar.bulkActions.restore"),children:s.jsx(T,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=i,e[17]=m,e[18]=x,e[19]=j):j=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=Ce("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(T,{name:"delete-bin",className:"h-4 w-4"}),e[21]=C):C=e[21];let k;e[22]!==p||e[23]!==f?(k=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:N,"aria-label":p,children:C})}),e[22]=p,e[23]=f,e[24]=k):k=e[24];let D;e[25]!==p?(D=s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:p})}),e[25]=p,e[26]=D):D=e[26];let M;e[27]!==k||e[28]!==D?(M=s.jsxs(ut,{children:[k,D]}),e[27]=k,e[28]=D,e[29]=M):M=e[29];let A;e[30]!==x?(A=x("sessions.sidebar.header.actions.exitSelection"),e[30]=x,e[31]=A):A=e[31];let _;e[32]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(T,{name:"close",className:"h-4 w-4"}),e[32]=_):_=e[32];let L;e[33]!==g||e[34]!==A?(L=s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:g,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":A,children:_})}),e[33]=g,e[34]=A,e[35]=L):L=e[35];let F;e[36]!==x?(F=x("sessions.sidebar.header.actions.exitSelection"),e[36]=x,e[37]=F):F=e[37];let $;e[38]!==F?($=s.jsx(mt,{side:"top",sideOffset:4,children:s.jsx("p",{children:F})}),e[38]=F,e[39]=$):$=e[39];let W;e[40]!==L||e[41]!==$?(W=s.jsxs(ut,{children:[L,$]}),e[40]=L,e[41]=$,e[42]=W):W=e[42];let U;e[43]!==M||e[44]!==W||e[45]!==v||e[46]!==j?(U=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[v,j,M,W]}),e[43]=M,e[44]=W,e[45]=v,e[46]=j,e[47]=U):U=e[47];let K;return e[48]!==U||e[49]!==y?(K=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[y,U]}),e[48]=U,e[49]=y,e[50]=K):K=e[50],K},GS=t=>{const{t:e}=gt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,folderScopesByProject:i,addSessionsToFolder:c,removeSessionsFromFolders:a,createFolderAndStartRename:d,archiveSessions:u,unarchiveSessions:m,deleteSessions:f,setBulkDeleteConfirm:g}=t,x=Cs(b=>b.enabled),w=Cs(b=>b.selectedIds.size),S=w>0,p=Cs(b=>b.selectedIds),h=Cs(b=>b.scopeKey),y=l.useCallback(()=>{Cs.getState().toggleMode()},[]),v=l.useCallback(()=>{Cs.getState().disable()},[]),j=l.useMemo(()=>{if(!S||typeof document>"u")return!1;let b=!1,P=!1;for(const V of p){const G=document.querySelectorAll(`[data-session-row="${CSS.escape(V)}"]`);for(const X of G)X.getAttribute("data-session-archived")==="1"?P=!0:b=!0}return P&&!b},[S,p]),N=l.useMemo(()=>{if(h)return h;if(!S||typeof document>"u")return null;for(const b of p){const V=document.querySelector(`[data-session-row="${CSS.escape(b)}"]`)?.getAttribute("data-session-scope");if(V&&V.length>0)return V}return null},[S,p,h]),C=l.useMemo(()=>{if(!N)return[];const b=i.get(N);return b&&b.length>0?b.map(P=>P.scopeKey):[N]},[N,i]),k=l.useMemo(()=>C.flatMap(b=>o[b]??[]),[o,C]),D=l.useCallback(b=>{for(const P of C)if((o[P]??[]).some(V=>V.id===b))return P;return null},[o,C]),M=l.useMemo(()=>{if(!S)return!1;for(const b of C)for(const P of o[b]??[])for(const V of P.sessionIds)if(p.has(V))return!0;return!1},[o,C,S,p]),A=l.useCallback((b,P)=>{const V=Array.from(p);for(const G of C)G!==b&&a(G,V);c(b,P,V)},[c,a,p,C]),_=l.useCallback(b=>{if(!S)return;const P=D(b);P&&A(P,b)},[S,A,D]),L=l.useCallback(()=>{const b=C[0];if(!b||!S)return;const P=d(b);P&&A(b,P.id)},[d,S,A,C]),F=l.useCallback(()=>{if(!S)return;const b=Array.from(p);for(const P of C)a(P,b)},[a,p,C,S]),$=l.useCallback(async()=>{const b=Array.from(p);if(b.length!==0){if(j){const{deletedIds:P,failedIds:V}=await f(b);P.length>0&&Ie.success(P.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:P.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:P.length})),V.length>0&&Ie.error(V.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:V.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:V.length}))}else{const{archivedIds:P,failedIds:V}=await u(b);P.length>0&&Ie.success(P.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:P.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:P.length})),V.length>0&&Ie.error(V.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:V.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:V.length}))}Cs.getState().clear()}},[u,j,f,p,e]),W=l.useCallback(()=>{if(!S)return;const b=p.size;if(!r){$();return}g({sessionCount:b,archivedBucket:j})},[j,$,p,r,g,S]),U=l.useCallback(async()=>{if(!S||!j)return;const b=Array.from(p),{restoredIds:P,failedIds:V}=await m(b);P.length>0&&Ie.success(P.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:P.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:P.length})),V.length>0&&Ie.error(V.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:V.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:V.length})),Cs.getState().clear()},[j,S,p,e,m]),K=l.useCallback(async()=>{g(null),await $()},[$]);return l.useEffect(()=>{if(!x)return;const b=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),P=V=>{if(n)return;const G=V.target;if(G&&(G.tagName==="INPUT"||G.tagName==="TEXTAREA"||G.isContentEditable))return;const X=b?V.metaKey:V.ctrlKey;if(V.key==="Escape"){V.preventDefault(),Cs.getState().disable();return}if(X&&V.key==="Backspace"){V.preventDefault(),W();return}if(X&&(V.key==="a"||V.key==="A")){const J=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(J.length===0)return;V.preventDefault();const le=Cs.getState().scopeKey??J[0]?.getAttribute("data-session-scope")??null,oe=Se=>le?Se.getAttribute("data-session-scope")===le:!0,Ae=J.filter(oe).map(Se=>Se.getAttribute("data-session-row")).filter(Se=>typeof Se=="string"&&Se.length>0);if(Ae.length===0)return;Cs.getState().replaceAll(Ae,le||null)}};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[W,n,x]),{selectionModeEnabled:x,hasSelection:S,selectedIdsSize:w,bulkScopeIsArchived:j,derivedSelectionScope:N,bulkScopeFolders:k,bulkCanRemoveFromFolder:M,handleToggleSelectionMode:y,handleExitSelectionMode:v,handleBulkMoveToFolder:_,handleBulkCreateFolderAndMove:L,handleBulkRemoveFromFolder:F,handleBulkDelete:W,handleBulkRestore:U,confirmBulkDelete:K}},qS=2880*60*1e3,YS=t=>!!t.parentID,QS=t=>!!t.time?.archived,XS=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},JS=(t,e,n=Date.now())=>{const r=n-qS;return t.filter(o=>QS(o)||YS(o)?!1:e.has(o.id)||XS(o)>=r)};let Hr=null,Kr=null,ei=null,wo=0,xi=null;const lr=new Set,ZS=3e4,e0=45e3,df=()=>{ei&&(clearTimeout(ei),ei=null)},uf=()=>{if(Kr||lr.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(wo,5)),ZS);Kr=setTimeout(()=>{Kr=null,wo+=1,ul()},t)},vo=()=>{df(),Hr&&Hr.close(),Hr=null},qc=()=>{df(),lr.size!==0&&(ei=setTimeout(()=>{vo(),uf()},e0))},t0=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}},Yc=t=>!t||typeof t!="object"?null:t,s0=t=>{if(t.type==="openchamber:event-stream-ready"){wo=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:session-created"){const d=Yc(t.properties),u=typeof d?.sessionId=="string"?d.sessionId:"",m=typeof d?.directory=="string"?d.directory:"";if(!u||!m)return;const f={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 g of lr)g(f);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=Yc(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,c=i==="running"||i==="error"?i:"success";if(!n||!r)return;const a={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of lr)d(a)},ul=()=>{if(typeof window>"u"||lr.size===0||typeof EventSource!="function"||Hr&&Hr.readyState!==EventSource.CLOSED)return;vo();const t=new EventSource(vi().sse("/api/openchamber/events"));t.onopen=()=>{qc()},t.onmessage=e=>{qc();const n=t0(e.data);n&&s0(n)},t.onerror=()=>{vo(),uf()},Hr=t},n0=()=>{xi||typeof window>"u"||(xi=Fa(()=>{vo(),wo=0,ul()}))},r0=()=>{xi?.(),xi=null},ff=t=>(lr.add(t),n0(),ul(),()=>{lr.delete(t),lr.size===0&&(Kr&&(clearTimeout(Kr),Kr=null),wo=0,vo(),r0())}),Qc={selected:0,"active-project":1,expanded:2,visible:3,background:4};function o0(t){const e=new Map,n=(r,o,i)=>{const c=vt(r??null);if(!c)return;const a=e.get(c);a&&Qc[a.priority]<=Qc[o]||e.set(c,{directory:c,priority:o,reason:i})};for(const r of t.projectSections){const o=!t.collapsedProjects.has(r.project.id);let i="background";r.project.id===t.activeProjectId?i="active-project":o&&(i="expanded"),n(r.project.normalizedPath,i,o?"project-expanded":"known-project");for(const c of r.groups){if(!c.directory||c.isArchivedBucket||c.isMain)continue;const a=o&&!t.collapsedGroups.has(`${r.project.id}:${c.id}`);let d="background";a?d="expanded":o&&(d="visible"),n(c.directory,d,a?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const Wo="oc.sessions.projectCollapse",Xc="oc.sessions.groupOrder",Jc="oc.sessions.groupCollapse",Zc="oc.sessions.activeSessionByProject",ed="oc.sessions.expandedParents.v3",i0=(t,e,n)=>{const r=new Set;for(const o of t){const i=vt(o.path)?.toLowerCase();i&&r.add(i)}if(n?.includeWorktrees===!1)return r;for(const o of e.values())for(const i of o){const c=vt(i.path)?.toLowerCase();c&&r.add(c)}return r},a0=(t,e,n)=>{if(t.time?.archived)return!0;const r=vt(Gs(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},l0=5*6e4,c0=new Set,aa=[],hn=t=>{const e=l.useRef(t);return e.current=t,l.useCallback((...n)=>e.current(...n),[])},d0=t=>{const e=tt.c(14),{owner:n,childStores:r,projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:a,currentDirectory:d}=t,u=Ge(m0);let m,f;e[0]!==i||e[1]!==r||e[2]!==a||e[3]!==c||e[4]!==d||e[5]!==u||e[6]!==n||e[7]!==o?(m=()=>{r.setBootstrapDemand(n,o0({projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:a,currentDirectory:d,currentSessionDirectory:u}))},f=[i,r,a,c,d,u,n,o],e[0]=i,e[1]=r,e[2]=a,e[3]=c,e[4]=d,e[5]=u,e[6]=n,e[7]=o,e[8]=m,e[9]=f):(m=e[8],f=e[9]),l.useEffect(m,f);let g,x;return e[10]!==r||e[11]!==n?(g=()=>()=>r.clearBootstrapDemand(n),x=[r,n],e[10]=r,e[11]=n,e[12]=g,e[13]=x):(g=e[12],x=e[13]),l.useEffect(g,x),null},u0=t=>{const e=tt.c(20),{directories:n}=t,{t:r}=gt();let o;e[0]!==n?(o=new Set,n.forEach(m=>{const f=vt(m)?.toLowerCase();f&&o.add(f)}),e[0]=n,e[1]=o):o=e[1];const i=o;let c;e[2]!==i?(c=m=>{for(const f of m.statusById.values()){if(f.status.type!=="busy"&&f.status.type!=="retry")continue;const g=vt(f.directory)?.toLowerCase();if(g&&i.has(g))return!0}return!1},e[2]=i,e[3]=c):c=e[3];const a=Di(c);let d;e[4]!==i?(d=m=>{for(const[f,g]of Object.entries(m.index.project.unseenCount)){if(!g)continue;const x=vt(f)?.toLowerCase();if(x&&i.has(x))return!0}return!1},e[4]=i,e[5]=d):d=e[5];const u=Pi(d);if(a){let m;e[6]!==r?(m=r("sessions.sidebar.session.status.active"),e[6]=r,e[7]=m):m=e[7];let f;e[8]!==r?(f=r("sessions.sidebar.session.status.active"),e[8]=r,e[9]=f):f=e[9];let g;return e[10]!==m||e[11]!==f?(g=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary","aria-label":m,title:f}),e[10]=m,e[11]=f,e[12]=g):g=e[12],g}if(u){let m;e[13]!==r?(m=r("sessions.sidebar.session.status.unread"),e[13]=r,e[14]=m):m=e[14];let f;e[15]!==r?(f=r("sessions.sidebar.session.status.unread"),e[15]=r,e[16]=f):f=e[16];let g;return e[17]!==m||e[18]!==f?(g=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":m,title:f}),e[17]=m,e[18]=f,e[19]=g):g=e[19],g}return null},f0=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:o=!1,showOnlyMainWorkspace:i=!1})=>{fa("react.session_sidebar_render"),In("ui.session_sidebar.render"),In(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),In(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:c}=gt(),[a,d]=l.useState(!1),[u,m]=l.useState(""),f=l.useRef(null),g=l.useRef(null),[x,w]=l.useState(null),[S,p]=l.useState(""),[h,y]=l.useState(null),[v,j]=l.useState(new Set),N=l.useMemo(()=>Lr(),[]),[C,k]=l.useState(new Set),[D,M]=l.useState(new Map),[A,_]=l.useState(new Map),L=pe(B=>B.isNewWorktreeDialogOpen),F=pe(B=>B.setNewWorktreeDialogOpen),[$,W]=l.useState(!1),[U,K]=l.useState(null),[b,P]=l.useState(null),[V,G]=l.useState(""),[X,J]=l.useState(null),[ee,le]=l.useState(null),[oe,Ae]=l.useState(null),Se=xo(B=>B.ids),Y=Ai(l.useCallback(B=>t?B.rankById:Ka,[t])),je=Di(Qn(B=>t?[...B.statusById.keys()].sort():aa)),me=l.useMemo(()=>new Set(je),[je]),z=Pi(Qn(B=>t?Object.entries(B.index.session.unseenCount).filter(([,ze])=>ze>0).map(([ze])=>ze).sort():aa)),Z=l.useMemo(()=>new Set(z),[z]),ne=xo(B=>B.toggle),[fe,xe]=l.useState(()=>{try{const B=Lr().getItem(Jc);if(!B)return new Set;const ze=JSON.parse(B);return new Set(Array.isArray(ze)?ze.filter(Le=>typeof Le=="string"):[])}catch{return new Set}}),[Te,be]=l.useState(()=>{try{const B=Lr().getItem(Xc);if(!B)return new Map;const ze=JSON.parse(B),Le=new Map;return Object.entries(ze).forEach(([at,Et])=>{Array.isArray(Et)&&Le.set(at,Et.filter(Gt=>typeof Gt=="string"))}),Le}catch{return new Map}}),De=l.useMemo(()=>{try{const B=Lr().getItem(Zc);if(!B)return new Map;const ze=JSON.parse(B),Le=new Map;return Object.entries(ze).forEach(([at,Et])=>{typeof Et=="string"&&Et.length>0&&Le.set(at,Et)}),Le}catch{return new Map}},[]),Ee=l.useCallback(B=>{try{N.setItem(Zc,JSON.stringify(Object.fromEntries(B.entries())))}catch{}},[N]),[Re,de]=l.useState(new Map),H=l.useRef(new Map),Ne=l.useRef(0),he=cs(B=>B.homeDirectory),ve=cs(B=>B.currentDirectory),se=Yt(B=>B.projects),Q=Yt(B=>B.activeProjectId),ye=Yt(B=>B.removeProject),re=Yt(B=>B.setActiveProjectIdOnly),R=Yt(B=>B.updateProjectMeta),ce=Yt(B=>B.reorderProjects),Me=pe(B=>B.setActiveMainTab),ge=pe(B=>B.openContextPanelTab),te=pe(B=>B.setSettingsDialogOpen),ae=pe(B=>B.toggleHelpDialog),ie=pe(B=>B.setAboutDialogOpen),E=pe(B=>B.setSessionSwitcherOpen),I=pe(B=>B.setScheduledTasksDialogOpen),ue=pe(B=>B.setArchivePageOpen),ke=pe(B=>B.setWorktreesPageProjectId),we=pe(B=>B.openMultiRunLauncher),qe=pe(B=>B.notifyOnSubtasks),Je=pe(B=>B.showDeletionDialog),st=pe(B=>B.setShowDeletionDialog),rt=Ua(u,120),ot=l.useMemo(()=>rt.trim().toLowerCase(),[rt]),lt=ot.length>0,kt=zs(B=>B.collapsedFolderIds),nt=zs(B=>B.foldersMap),it=zs(B=>B.getFoldersForScope),St=zs(B=>B.createFolder),It=zs(B=>B.renameFolder),Ft=zs(B=>B.deleteFolder),Mt=zs(B=>B.addSessionToFolder),Ot=zs(B=>B.addSessionsToFolder),Ke=zs(B=>B.removeSessionFromFolder),$t=zs(B=>B.removeSessionsFromFolders),Tt=zs(B=>B.toggleFolderCollapse),dt=zs(B=>B.getSessionFolderId);Iv({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchContainerRef:f});const Ct=Jd(t),Rt=Si(),Qt=nu(),Qe=`session-sidebar:${l.useId()}`,ht=$h(),Xe=l.useMemo(()=>Array.from(ht.values()),[ht]),_e=l.useMemo(()=>er(),[]),yt=Ms(B=>B.status==="ready"),zt=Ms(Qn(B=>B.activeSessions.map(Ki).sort())),Bt=Ms(Qn(B=>B.archivedSessions.map(Ki).sort())),Lt=Ms.getState(),_t=Lt.activeSessions,Ht=Lt.archivedSessions,Dt=l.useRef({signature:"",sessions:[]}),fs=l.useMemo(()=>new Set(_t.map(B=>B.id)),[_t]),Kt=(()=>{const B=Xe.filter(Le=>!fs.has(Le.id)),ze=B.map(Ki).sort().join(`
|
|
186
|
-
`);return Dt.current.signature===ze?Dt.current.sessions:(Dt.current={signature:ze,sessions:B},B)})(),Nt=Ge(B=>B.setCurrentSession),Zt=Ge(B=>B.updateSessionTitle),ss=Ge(B=>B.shareSession),Oe=Ge(B=>B.unshareSession),Ue=Ge(B=>B.worktreeMetadata),Ve=Ge(B=>B.availableWorktreesByProject),Be=Ge(B=>B.openNewSessionDraft),We=l.useCallback(B=>{pe.getState().closeMainSurfaces(),Be(B),_e&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[_e,Be]),wt=uo(Qn(B=>({checkForUpdates:B.checkForUpdates,available:B.available,runtimeType:B.runtimeType,info:B.info,downloading:B.downloading,downloaded:B.downloaded,progress:B.progress,error:B.error,downloadUpdate:B.downloadUpdate,restartToUpdate:B.restartToUpdate}))),os=l.useMemo(()=>i0(se,Ve,{includeWorktrees:!_e}),[Ve,_e,se]),xt=l.useMemo(()=>{const B=[..._t],ze=new Set(B.map(Le=>Le.id));return Kt.forEach(Le=>{ze.has(Le.id)||B.push(Le)}),B.filter(Le=>a0(Le,os,{allowUnknownDirectory:!_e,allowEmptyDirectorySet:!_e}))},[_t,_e,os,Kt]),ns=l.useMemo(()=>[..._t,...Ht],[Ht,_t]),ds=l.useRef(Xe);l.useEffect(()=>{ds.current=Xe},[Xe]);const es=Tn(),js=l.useMemo(()=>`${es}|${se.map(B=>`${B.id}:${vt(B.path)??""}`).join("|")}`,[se,es]),[sn,Mn]=l.useState(_e?js:null),[$n,Ds]=l.useReducer(B=>B+1,0),nn=!_e&&sn!==js,[Sn,Ps]=l.useState(new Set),rn=l.useRef(!1);l.useEffect(()=>{rn.current||(rn.current=!0,ai(ds.current))},[]),l.useEffect(()=>{let B=!1;return(async()=>{const Le=es,at=Yt.getState().projects;if(at.length===0||_e){B||(Ps(new Set),Mn(js));return}const Et=Ge.getState().availableWorktreesByProject,Gt=new Map(Et),$s=new Set,bs=3;let sr=0;const An=Array.from({length:bs},async()=>{for(;;){const Gn=sr;if(sr+=1,Gn>=at.length)return;const Cl=at[Gn],rr=vt(Cl.path);if(rr)try{const Ui=await ga(async()=>dr.getState().directories.get(rr)?.isGitRepo??await lu(rr)?Uh({id:Cl.id,path:rr}):null);if(Ui===null){Gt.delete(rr);continue}if(B)return;Ui.length===0?Gt.delete(rr):Gt.set(rr,Ui)}catch{$s.add(rr)}}});if(await Promise.all(An),B||Tn()!==Le)return;const Fr=new Set(at.map(Gn=>vt(Gn.path)).filter(Boolean));for(const Gn of Gt.keys())Fr.has(Gn)||Gt.delete(Gn);const nr=Vh(at,Gt),kl=[...nr.values()].flat();Dv(kl.map(Gn=>Gn.path),Date.now()),Hh(nr,Et)||Ge.setState({availableWorktrees:kl,availableWorktreesByProject:nr}),Ps($s),Mn(js)})(),()=>{B=!0}},[_e,js,es,$n]),l.useEffect(()=>{let B=null,ze=!1;const Le=new Set,at=ff(Et=>{Et.type==="scheduled-task-ran"?ze=!0:(Le.add(Et.directory),Ds()),B&&clearTimeout(B),B=setTimeout(()=>{if(B=null,ze){ze=!1,Le.clear(),ai(ds.current);return}const Gt=[...Le];Le.clear(),Gt.length>0&&Ko(Gt,ds.current)},500)});return()=>{B&&clearTimeout(B),at()}},[]);const Qs=l.useMemo(()=>_n(),[]),{isTablet:on}=fr(),an=e||on,{buildGroupSearchText:zn,filterSessionNodesForSearch:Os,buildGroupedSessions:ln}=Pv({homeDirectory:he,worktreeMetadata:Ue,pinnedSessionIds:Se,sessionOrderRanks:Y,gitBranches:Ct,isVSCode:_e}),{scheduleCollapsedProjectsPersist:cn}=Fv({isVSCode:_e,safeStorage:N,keys:{sessionExpanded:ed,projectCollapse:Wo,groupOrder:Xc,groupCollapse:Jc},groupOrderByProject:Te,collapsedGroups:fe,setExpandedParents:j,setCollapsedProjects:k}),q=l.useMemo(()=>Xd(xt,Se,Y),[Se,Y,xt]),$e=l.useMemo(()=>q.map(B=>B.id).join("|"),[q]),Ze=l.useRef(null),ct=l.useMemo(()=>{const B=Ze.current;if(B&&B.signature===$e)return B.map;const ze=new Map(q.map((Le,at)=>[Le.id,at]));return Ze.current={signature:$e,map:ze},ze},[q,$e]),Pt=l.useMemo(()=>{const B=new Map;return q.forEach(ze=>{const Le=ze.parentID;if(!Le)return;const at=B.get(Le)??[];at.push(ze),B.set(Le,at)}),B.forEach(ze=>ze.sort((Le,at)=>qr(Le,at,Se,Y))),B},[q,Se,Y]),jt=l.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noSessions.description")})]}),[c]),pt=l.useMemo(()=>se.find(B=>B.id===h)??null,[se,h]),is=l.useCallback(B=>{h&&R(h,{label:B.label,icon:B.icon,color:B.color,iconBackground:B.iconBackground,defaultModel:B.defaultModel??null})},[h,R]),vs=l.useCallback(()=>{F(!0)},[F]),rs=l.useCallback(()=>{const B=uo.getState();if(B.available&&B.info){W(!0);return}wt.checkForUpdates().then(()=>{const{available:ze,error:Le}=uo.getState();if(Le){Ie.error(c("sessions.sidebar.updateCheck.errorTitle"),{description:Le});return}if(!ze){Ie.success(c("sessions.sidebar.updateCheck.latestVersion"));return}W(!0)})},[c,wt]),Is=l.useCallback(()=>{e&&E(!1),te(!0)},[e,E,te]),Fs=wt.available&&(wt.runtimeType==="desktop"||wt.runtimeType==="web"),jn=Ge(B=>B.deleteSession),dn=Ge(B=>B.deleteSessions),Tr=Ge(B=>B.archiveSession),Wn=Ge(B=>B.archiveSessions),un=Ge(B=>B.unarchiveSession),kn=Ge(B=>B.unarchiveSessions),{copiedSessionId:Er,handleSessionSelect:hr,handleSessionDoubleClick:Pe,handleSaveEdit:At,handleCancelEdit:Ut,handleShareSession:as,handleCopyShareUrl:ps,handleCopySessionId:ws,handleUnshareSession:ks,handleDeleteSession:Ts,handleRestoreSession:Bs,confirmDeleteSession:pr}=Tv({mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:d,setActiveMainTab:Me,setSessionSwitcherOpen:E,setCurrentSession:Nt,updateSessionTitle:Zt,shareSession:ss,unshareSession:Oe,deleteSession:jn,deleteSessions:dn,archiveSession:Tr,archiveSessions:Wn,unarchiveSession:un,childrenMap:Pt,showDeletionDialog:Je,setDeleteSessionConfirm:J,deleteSessionConfirm:X,setEditingId:w,setEditTitle:p,editingId:x,editTitle:S}),xs=l.useCallback(()=>{if(!ee)return;const{scopeKey:B,folderId:ze}=ee;le(null),Ft(B,ze)},[ee,Ft]),gs=l.useCallback(()=>{Ln.requestDirectoryDialog()},[]),Cn=l.useCallback(B=>{j(ze=>{const Le=zh(ze,B);try{N.setItem(ed,JSON.stringify(Array.from(Le)))}catch{}return Le})},[N]),Jr=l.useCallback((B,ze)=>{if(!B)return null;ze&&kt.has(ze)&&Tt(ze);const Le=St(B,c("sessions.sidebar.folder.newFolderName"),ze);return P(Le.id),G(Le.name),Le},[kt,Tt,St,c]),gr=hn(hr),Mr=hn(Pe),Zr=hn(At),Ei=hn(Ut),Mi=hn(as),jo=hn(ps),Ri=hn(ws),Oi=hn(ks),ko=hn(Ts),Fi=hn(Bs),Un=hn(Jr),Co=l.useCallback((B,ze)=>{_(Le=>{const at=new Map(Le);return at.set(B,ze+7),at})},[]),Nn=l.useCallback(B=>{_(ze=>{if(!ze.has(B))return ze;const Le=new Map(ze);return Le.delete(B),Le})},[]),No=l.useCallback(B=>{_(ze=>{let Le=!1;const at=new Map(ze),Et=`${B}:`;for(const Gt of at.keys())Gt.startsWith(Et)&&(at.delete(Gt),Le=!0);return Le?at:ze})},[]),eo=l.useRef([]),Bi=l.useCallback(()=>{Ne.current=Date.now()+150,_(new Map),xe(()=>{const B=new Set;return eo.current.forEach(ze=>{ze.groups.forEach(Le=>{Le.isMain||B.add(`${ze.project.id}:${Le.id}`)})}),B}),k(()=>{const B=new Set(se.map(ze=>ze.id));try{N.setItem(Wo,JSON.stringify(Array.from(B)))}catch{}return _e||cn(B),B})},[se,_e,N,cn]),Li=l.useCallback(()=>{Ne.current=Date.now()+150,_(new Map),xe(new Set),k(()=>{const B=new Set;try{N.setItem(Wo,JSON.stringify([]))}catch{}return _e||cn(B),B})},[_e,N,cn]),_i=l.useCallback(B=>{Ne.current=Date.now()+150,No(B),k(ze=>{const Le=new Set(ze);Le.has(B)?Le.delete(B):Le.add(B);try{N.setItem(Wo,JSON.stringify(Array.from(Le)))}catch{}return _e||cn(Le),Le})},[_e,No,N,cn]),Xs=l.useMemo(()=>se.map(B=>({...B,normalizedPath:vt(B.path)})).filter(B=>!!B.normalizedPath),[se]),$i=l.useMemo(()=>Xs.map(B=>B.normalizedPath),[Xs]),xr=l.useMemo(()=>{const B=new Set(Xs.map(ze=>ze.normalizedPath));if(!_e)for(const ze of Ve.values())for(const Le of ze){const at=vt(Le.path);at&&B.add(at)}return[...B].sort()},[Ve,_e,Xs]),Ao=l.useRef(null);l.useEffect(()=>{const B=new Set(xr),ze=Ao.current;if(Ao.current=B,!ze){_e&&xr.length>0&&Ko(xr,ds.current);return}const Le=xr.filter(at=>!ze.has(at));Le.length!==0&&Ko(Le,ds.current)},[_e,xr]);const{github:O}=tr(),Fe=Pr(B=>B.status),Ye=Pr(B=>B.hasChecked),bt=Wh(t?$i:aa),Wt=pn(B=>B.ensureEntry),ts=pn(B=>B.setParams),Xt=pn(B=>B.refreshTargets);zv({enabled:t,normalizedProjects:Xs,gitRepoStatus:bt,setProjectRepoStatus:M,setProjectRootBranches:de});const ms=Ge(B=>B.isLoading),Ls=l.useMemo(()=>Zv(xt,Xs,Ve,_e,Ht),[Ht,Ve,_e,Xs,xt]);Yv({enabled:t,hasAuthoritativeGlobalSessions:yt,sessions:ns});const{getSessionsForProject:Rr,getArchivedSessionsForProject:Or}=Kv({ownership:Ls});bv({enabled:t,normalizedProjects:Xs,ownership:Ls,isSessionsLoading:ms,hasAuthoritativeGlobalSessions:yt,isWorktreeTopologyLoading:nn,unresolvedWorktreeProjectPaths:Sn,foldersMap:nt,createFolder:St,addSessionToFolder:Mt});const Do=l.useRef(!1);Q&&D.has(Q)&&(Do.current=!!D.get(Q));const Rn=Ns(B=>B.showRecentSection),to=Ns(B=>B.showArchivedSessions),_s=Ns(B=>B.projectSortOrder),Vn=Ns(B=>B.stickyZoneHeaders),Hn=Yt(B=>B.manualProjectOrder),Kn=l.useRef(new Set),br=l.useRef(new Set),yr=Vl(Kn.current,v,"project"),wr=Vl(br.current,v,"recent");Kn.current=yr,br.current=wr;const zi={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:o,showOnlyMainWorkspace:i,t:c,isTablet:on,liveSessions:Xe,activeSessionStructure:zt,archivedSessionStructure:Bt,globalActiveSessions:_t,archivedSessions:Ht,projects:se,activeProjectId:Q,manualProjectOrder:Hn,currentDirectory:ve,worktreeMetadata:Ue,availableWorktreesByProject:Ve,pinnedSessionIds:Se,sessionOrderRanks:Y,foldersMap:nt,collapsedFolderIds:kt,gitBranches:Ct,gitRepoStatus:bt,githubAuthStatus:Fe,githubAuthChecked:Ye,updateStore:wt,showRecentSection:Rn,showArchivedSessions:to,projectSortOrder:_s,projectRepoStatus:D,projectRootBranches:Re,resolvedWorktreeTopologyKey:sn,unresolvedWorktreeProjectPaths:Sn,isSessionSearchOpen:a,sessionSearchQuery:u,editingId:x,editTitle:S,editingProjectDialogId:h,expandedParents:v,collapsedProjects:C,visibleSessionCountByGroup:A,updateDialogOpen:$,openSidebarMenuKey:U,renamingFolderId:b,renameFolderDraft:V,deleteSessionConfirm:X,deleteFolderConfirm:ee,bulkDeleteConfirm:oe,collapsedGroups:fe},fl=l.useRef(null),ml=fl.current;if(ml){let B=!1;for(const ze of Object.keys(zi))Object.is(ml[ze],zi[ze])||(In(`ui.session_sidebar.source.${ze}`),B=!0);B||In("ui.session_sidebar.source.parent_or_context")}fl.current=zi;const vf=l.useMemo(()=>{const B=[...Xs];switch(_s){case"a-z":B.sort((ze,Le)=>{const at=(ze.label||ze.path).toLowerCase(),Et=(Le.label||Le.path).toLowerCase();return at.localeCompare(Et)});break;case"z-a":B.sort((ze,Le)=>{const at=(ze.label||ze.path).toLowerCase();return(Le.label||Le.path).toLowerCase().localeCompare(at)});break;case"date-added":B.sort((ze,Le)=>(Le.addedAt??0)-(ze.addedAt??0));break;case"recent":B.sort((ze,Le)=>(Le.lastOpenedAt??0)-(ze.lastOpenedAt??0));break;case"manual":{const ze=new Map(Hn.map((Le,at)=>[Le,at]));B.sort((Le,at)=>{const Et=ze.get(Le.id)??1/0,Gt=ze.get(at.id)??1/0;return Et-Gt});break}}return B},[Xs,_s,Hn]),{projectSections:fn,groupSearchDataByGroup:hl,sectionsForRender:pl,flatSectionsForRender:Po,searchMatchCount:Sf}=jv({normalizedProjects:vf,getSessionsForProject:Rr,getArchivedSessionsForProject:Or,availableWorktreesByProject:Ve,projectRepoStatus:D,projectRootBranches:Re,lastRepoStatus:Do.current,buildGroupedSessions:ln,hasSessionSearchQuery:lt,normalizedSessionSearchQuery:ot,filterSessionNodesForSearch:Os,buildGroupSearchText:zn,foldersMap:nt});eo.current=fn;const jf=l.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noMatches.description")})]}),[c]),{getOrderedGroups:kf}=wv(Te),gl=l.useRef(!1);l.useEffect(()=>{if(gl.current||fn.length===0)return;const B=fn.flatMap(ze=>ze.groups.filter(Le=>Le.isArchivedBucket).map(Le=>`${ze.project.id}:${Le.id}`));B.length>0&&xe(ze=>new Set([...ze,...B])),gl.current=!0},[fn]);const xl=l.useMemo(()=>{const B=new Map,ze=new Map;return fn.forEach(Le=>{const at=Qa(Le.project.label?.trim()||ur(Le.project.normalizedPath,he)||Le.project.normalizedPath);Le.groups.forEach(Et=>{const Gt=Et.branch&&Et.branch!=="HEAD"&&Et.branch!==at?Et.branch:null,$s={projectLabel:at,branchLabel:Gt},bs=sr=>{sr.forEach(An=>{const Fr=Le.project.normalizedPath.length,nr=ze.get(An.session.id)??-1;Fr<nr||(B.set(An.session.id,{node:An,projectId:Le.project.id,groupDirectory:Et.directory,secondaryMeta:$s}),ze.set(An.session.id,Fr),An.children.length>0&&bs(An.children))})};bs(Et.sessions)})}),B},[fn,he]),Wi=l.useMemo(()=>!Rn||_e?[]:JS(xt,me).sort((B,ze)=>qr(B,ze,Se,Y)),[me,_e,Se,Y,xt,Rn]),Io=l.useMemo(()=>{if(_e||!Rn)return[];const B=Le=>{const at=xl.get(Le.id),Et=vt(Le.directory??null),Gt=at?.node??{session:Le,children:[],worktree:null},bs=(lt?Os([Gt],ot):[Gt])[0];if(!bs)return null;const sr=at?.secondaryMeta?{projectLabel:at.secondaryMeta.projectLabel,branchLabel:_e?null:at.secondaryMeta.branchLabel}:null;return{node:bs,projectId:at?.projectId??null,groupDirectory:at?.groupDirectory??Et,secondaryMeta:sr}},ze=Wi.map(B).filter(Le=>Le!==null);return[{key:"active-now",title:c("sessions.sidebar.activity.recentTitle"),items:ze}]},[Os,lt,_e,ot,Wi,xl,Rn,c]),Cf=l.useMemo(()=>Io.some(B=>B.items.length>0),[Io]),bl=_e&&to,yl=Ns(B=>B.sessionGroupingMode)==="by-worktree"&&!_e,Nf=l.useMemo(()=>{const B=yl?pl:Po;return bl?B:B.map(ze=>ze.groups.some(Le=>Le.isArchivedBucket)?{...ze,groups:ze.groups.filter(Le=>!Le.isArchivedBucket)}:ze)},[Po,pl,bl,yl]),wl=l.useRef(new Set);l.useEffect(()=>{if(!t||!Ye||!Fe?.connected||!O)return;const B=new Map,ze=Date.now();fn.forEach(Le=>{C.has(Le.project.id)||Le.groups.forEach(at=>{if(at.isArchivedBucket||at.isMain)return;const Et=vt(at.directory??null),Gt=at.branch?.trim()||Ct.get(Et||"")?.trim();if(!Et||!Gt)return;const $s=ki(Et,Gt),bs=pn.getState().entries[$s],sr=!!bs?.status?.pr,An=`${Et}::${Gt}`,Fr=Math.max(bs?.lastRefreshAt??0,bs?.lastDiscoveryPollAt??0),nr=!!(bs?.isInitialStatusResolved&&!sr&&(!wl.current.has(An)||ze-Fr>=l0));(!bs||!bs.isInitialStatusResolved||nr)&&(nr&&wl.current.add(An),B.has($s)||B.set($s,{directory:Et,branch:Gt}))})}),B.size!==0&&(B.forEach((Le,at)=>{Wt(at),ts(at,{directory:Le.directory,branch:Le.branch,remoteName:null,canShow:!0,github:O,githubAuthChecked:Ye,githubConnected:Fe.connected})}),Xt([...B.values()],{silent:!0,markInitialResolved:!0}))},[C,Wt,O,Ye,Fe?.connected,t,Ct,fn,Xt,ts]);const Af=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",Df="h-4.5 w-4.5",Pf=e1({enabled:t&&Vn,isDesktopShellRuntime:Qs,projectSections:fn,projectHeaderSentinelRefs:H}),so=hn((B,ze=0,Le,at,Et=!1,Gt,$s="project",bs)=>s.jsx(zS,{node:B,depth:ze,groupDirectory:Le,projectId:at,archivedBucket:Et,pinnedSessionIds:Se,expandedParents:$s==="recent"?wr:yr,hasSessionSearchQuery:lt,normalizedSessionSearchQuery:ot,notifyOnSubtasks:qe,editingId:x,setEditingId:w,editTitle:S,setEditTitle:p,handleSaveEdit:Zr,handleCancelEdit:Ei,toggleParent:Cn,handleSessionSelect:gr,handleSessionDoubleClick:Mr,togglePinnedSession:ne,handleShareSession:Mi,copiedSessionId:Er,handleCopyShareUrl:jo,handleCopySessionId:Ri,handleUnshareSession:Oi,openSidebarMenuKey:U,setOpenSidebarMenuKey:K,renamingFolderId:b,getFoldersForScope:it,getSessionFolderId:dt,removeSessionFromFolder:Ke,addSessionToFolder:Mt,createFolderAndStartRename:Un,openContextPanelTab:ge,handleDeleteSession:ko,handleRestoreSession:Fi,mobileVariant:e,alwaysShowActions:an,renderSessionNode:so,secondaryMeta:Gt,renderContext:$s,subtreeContainsEditing:bs?.subtreeContainsEditing??c0,menuOpenSessionId:bs?.menuOpenSessionId??null,nodeStructureKey:bs?.nodeStructureKey??"",childRenderExtrasFor:bs?.childRenderExtrasFor})),If=l.useMemo(()=>{const B=new Map;return Po.forEach(ze=>{const Le=ze.groups.find(at=>!at.isArchivedBucket);Le?.folderScopes&&Le.folderScopes.length>0&&B.set(ze.project.id,Le.folderScopes)}),B},[Po]),Tf=l.useCallback((B,ze)=>{const Le=[];return ze.forEach(at=>{at.isArchivedBucket||(Le.push(at.directory),at.folderScopes?.forEach(Et=>Le.push(Et.directory)))}),s.jsx(u0,{directories:Le})},[]),vl=l.useCallback(B=>{Nn(B),xe(ze=>{const Le=new Set(ze);return Le.has(B)?Le.delete(B):Le.add(B),Le})},[Nn]),Ef=l.useCallback((B,ze,Le,at,Et,Gt,$s)=>s.jsx(I1,{group:B,groupKey:ze,projectId:Le,hideGroupLabel:at,dragHandleProps:Et,compactBodyPadding:Gt,hasSessionSearchQuery:lt,normalizedSessionSearchQuery:ot,groupSearchDataByGroup:hl,visibleSessionCount:A.get(ze),collapsedGroups:fe,hideDirectoryControls:o,collapsedFolderIds:kt,toggleFolderCollapse:Tt,renameFolder:It,deleteFolder:Ft,showDeletionDialog:Je,setDeleteFolderConfirm:le,renderSessionNode:so,showMoreGroupSessions:Co,resetGroupSessionLimit:Nn,mobileVariant:e,alwaysShowActions:an,activeProjectId:Q,setActiveProjectIdOnly:re,setActiveMainTab:Me,setSessionSwitcherOpen:E,openNewSessionDraft:We,addSessionToFolder:Mt,createFolderAndStartRename:Un,renamingFolderId:b,renameFolderDraft:V,setRenameFolderDraft:G,setRenamingFolderId:P,pinnedSessionIds:Se,expandedParents:yr,sessionOrderIndex:ct,editingId:x,editTitle:S,openSidebarMenuKey:U,activeActivitySessionIds:me,unreadActivitySessionIds:Z,notifyOnSubtasks:qe,onToggleCollapsedGroup:vl,scrollContainerRef:$s}),[lt,ot,hl,A,fe,o,kt,Tt,It,Ft,Je,so,Co,Nn,e,an,Q,re,Me,E,We,Mt,Un,b,V,Se,yr,ct,x,S,U,me,Z,qe,vl]),Mf=l.useMemo(()=>!_e&&Rn&&!lt?s.jsx(U1,{sections:Io,renderSessionNode:so,editingId:x,openSidebarMenuKey:U,expansionState:wr,variant:"section",isDesktopShellRuntime:Qs}):null,[Io,x,lt,Qs,_e,U,wr,so,Rn]),Sl=!!(b||x||h),{selectionModeEnabled:jl,hasSelection:Rf,selectedIdsSize:Of,bulkScopeIsArchived:Ff,derivedSelectionScope:Bf,bulkScopeFolders:Lf,bulkCanRemoveFromFolder:_f,handleToggleSelectionMode:$f,handleExitSelectionMode:zf,handleBulkMoveToFolder:Wf,handleBulkCreateFolderAndMove:Uf,handleBulkRemoveFromFolder:Vf,handleBulkDelete:Hf,handleBulkRestore:Kf,confirmBulkDelete:Gf}=GS({isInlineEditing:Sl,showDeletionDialog:Je,foldersMap:nt,folderScopesByProject:If,addSessionsToFolder:Ot,removeSessionsFromFolders:$t,createFolderAndStartRename:Jr,archiveSessions:Wn,unarchiveSessions:kn,deleteSessions:dn,setBulkDeleteConfirm:Ae}),qf=l.useCallback(()=>{Me("chat"),e&&E(!1),we()},[e,we,Me,E]),Yf=l.useCallback(()=>{pe.getState().closeMainSurfaces(),Me("chat"),e&&E(!1),Be()},[e,Be,Me,E]);return s.jsx(ba,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:f,className:Ce("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[s.jsx(d0,{owner:Qe,childStores:Qt,projectSections:fn,activeProjectId:Q,collapsedProjects:C,collapsedGroups:fe,currentDirectory:ve}),s.jsx(Cv,{projectSections:fn,activeProjectId:Q,initialActiveSessionByProject:De,persistActiveSessionByProject:Ee,handleSessionSelect:gr,mobileVariant:e,openNewSessionDraft:Be,setActiveMainTab:Me,setSessionSwitcherOpen:E}),s.jsx(gv,{enabled:t,sortedSessions:q,recentSessions:Wi,prefetchSession:Rt.prefetchSession}),!o&&!_e?s.jsx(W1,{onNewSession:Yf}):null,s.jsx(E1,{hideDirectoryControls:o,showRecentControls:!_e,handleOpenDirectoryDialog:gs,onOpenScheduled:()=>{e&&E(!1),I(!0)},onOpenMultiRun:qf,canOpenMultiRun:se.length>0,onOpenArchive:()=>{e&&E(!1),ue(!0)},headerActionIconClass:Df,headerActionButtonClass:Af,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:lt,searchMatchCount:Sf,collapseAllProjects:Bi,expandAllProjects:Li,selectionModeEnabled:jl,onToggleSelectionMode:$f}),t?s.jsx(sS,{topContent:Mf,hasSharedSessions:Cf,sectionsForRender:Nf,projectSections:fn,activeProjectId:Q,showOnlyMainWorkspace:i,hasSessionSearchQuery:lt,emptyState:jt,searchEmptyState:jf,renderGroupSessions:Ef,homeDirectory:he,collapsedProjects:C,hideDirectoryControls:o,projectRepoStatus:D,isDesktopShellRuntime:Qs,stickyZoneHeaders:Vn,stuckProjectHeaders:Pf,mobileVariant:e,alwaysShowActions:an,toggleProject:_i,setActiveProjectIdOnly:re,setActiveMainTab:Me,setSessionSwitcherOpen:E,openNewSessionDraft:We,openNewWorktreeDialog:vs,openWorktreesPage:B=>{e&&E(!1),ke(B)},openProjectEditDialog:y,removeProject:ye,projectHeaderSentinelRefs:H,reorderProjects:ce,projectSortOrder:_s,getOrderedGroups:kf,setGroupOrderByProject:be,renderProjectStatusIndicator:Tf,openSidebarMenuKey:U,setOpenSidebarMenuKey:K,isInlineEditing:Sl}):null,jl&&Rf?s.jsx(KS,{selectedCount:Of,scopeKey:Bf,scopeFolders:Lf,archivedBucket:Ff,onMoveToFolder:Wf,onCreateFolderAndMove:Uf,onRemoveFromFolder:Vf,canRemoveFromFolder:_f,onRestore:Kf,onDelete:Hf,onDone:zf}):null,s.jsx(V1,{onOpenSettings:Is,onOpenShortcuts:ae,onOpenAbout:()=>ie(!0),onOpenUpdate:rs,showRuntimeButtons:!_e,showUpdateButton:Fs}),s.jsx(hu,{open:$,onOpenChange:W,info:wt.info,downloading:wt.downloading,downloaded:wt.downloaded,progress:wt.progress,error:wt.error,onDownload:wt.downloadUpdate,onRestart:wt.restartToUpdate,runtimeType:wt.runtimeType}),s.jsx(n1,{open:!!pt,onOpenChange:B=>{B||y(null)},project:pt,onSave:is}),s.jsx(Qp,{open:L,onOpenChange:F,onWorktreeCreated:(B,ze)=>{if(Me("chat"),e&&E(!1),ze?.sessionId){Nt(ze.sessionId,B);return}Be({directoryOverride:B,preserveDirectoryOverride:!0})}}),s.jsx(US,{value:X,setValue:J,showDeletionDialog:Je,setShowDeletionDialog:st,onConfirm:pr}),s.jsx(HS,{value:ee,setValue:le,onConfirm:xs}),s.jsx(VS,{value:oe,setValue:Ae,showDeletionDialog:Je,setShowDeletionDialog:st,onConfirm:Gf})]})})},td=l.memo(f0);function m0(t){return t.currentSessionDirectory}const Sr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Pn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},h0=()=>{const{t}=gt(),[e,n]=l.useState(!1),[r,o]=l.useState(!1),[i,c]=l.useState(null),[a,d]=l.useState([]),[u,m]=l.useState(!1),[f,g]=l.useState(!1),[x,w]=l.useState(!1),[S,p]=l.useState(!1),[h,y]=l.useState(new Set),v=Ge(H=>H.getWorktreeMetadata),j=Ge(H=>H.newSessionDraft),N=Ge(H=>H.setNewSessionDraftTarget),C=Ge(H=>H.setDraftBootstrapPendingDirectory),k=Kh,D=qh,M=Ge(H=>H.deleteSessions),A=Ge(H=>H.archiveSessions),_=pe(H=>H.showDeletionDialog),L=pe(H=>H.setShowDeletionDialog),F=cs(H=>H.currentDirectory),$=cs(H=>H.homeDirectory),W=cs(H=>H.isHomeReady),U=Yt(H=>H.projects),K=Yt(H=>H.activeProjectId),{isMobile:b,isTablet:P,hasTouchInput:V}=fr(),G=b||P||V,X=l.useMemo(()=>{const Ne=(K?U.find(he=>he.id===K)??null:null)?.path??F;return Pn(Ne)},[K,F,U]),J=l.useCallback(H=>{const he=Pn(H.projectDirectory)||X;return{id:(U.find(se=>Pn(se.path)===he)??null)?.id??`path:${he}`,path:he}},[X,U]),ee=S&&h.size>0,le=l.useMemo(()=>{const H=i?.worktree;return H&&typeof H.branch=="string"&&H.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[i?.worktree,a]),oe=i?.mode==="worktree",Ae=oe,Se=x||!oe||!le,Y=x||!oe;l.useEffect(()=>{r||!W||U.length>0||(o(!0),n(!0))},[r,W,U.length]);const je=l.useCallback(H=>{c({sessions:H.sessions,dateLabel:H.dateLabel,mode:H.mode??"session",worktree:H.worktree??null})},[]),me=l.useCallback(()=>{c(null),d([]),m(!1),g(!1),w(!1),p(!1),y(new Set)},[]),z=l.useCallback(async H=>{if(H.sessions.length===0)return;if(H.sessions.length===1){const se=H.sessions[0];await k(se.id)?Ie.success(t("sessions.sidebar.session.delete.success")):Ie.error(t("sessions.sidebar.session.delete.error"));return}const Ne=H.sessions.map(se=>se.id),{deletedIds:he,failedIds:ve}=await M(Ne);if(he.length>0){const se=ve.length>0?ve.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ve.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ve.length}):H.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:H.dateLabel}):void 0;Ie.success(he.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:he.length}),{description:Sr(se)})}ve.length>0&&Ie.error(ve.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ve.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ve.length}),{description:Sr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,M,t]);l.useEffect(()=>Ln.onDeleteRequest(H=>{if(!_&&(H.mode??"session")==="session"){z(H);return}je(H)}),[je,_,z]),l.useEffect(()=>Ln.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),g(!1),p(!1),y(new Set);return}const H=i.sessions.map(ve=>{const se=v(ve.id);return se?{session:ve,metadata:se}:null}).filter(ve=>!!ve);d(H),m(!1),p(!1),y(new Set);const Ne=new Map;if(i.worktree?.path&&Ne.set(Pn(i.worktree.path),i.worktree),H.forEach(({metadata:ve})=>{ve.path&&Ne.set(Pn(ve.path),ve)}),Ne.size===0){p(!0);return}let he=!1;return(async()=>{const ve=new Map,se=new Set;await Promise.all(Array.from(Ne.entries()).map(async([Q,ye])=>{try{const re=await Gh(ye.path);ve.set(Q,re),re?.isDirty&&se.add(Q)}catch{ye.status&&(ve.set(Q,ye.status),ye.status.isDirty&&se.add(Q))}})).catch(Q=>{console.warn("Failed to inspect worktree status before deletion:",Q)}),!he&&(y(se),p(!0),c(Q=>{if(!Q?.worktree?.path)return Q;const ye=Pn(Q.worktree.path),re=ve.get(ye);if(!re)return Q;const R=Q.worktree.status;return R?.isDirty===re.isDirty&&R?.ahead===re.ahead&&R?.behind===re.behind&&R?.upstream===re.upstream?Q:{...Q,worktree:{...Q.worktree,status:re}}}),d(Q=>Q.map(ye=>{const re=Pn(ye.metadata.path),R=ve.get(re);return R?{session:ye.session,metadata:{...ye.metadata,status:R}}:ye})))})(),()=>{he=!0}},[i,v]),l.useEffect(()=>{le||m(!1)},[le]);const Z=l.useCallback(async(H,Ne)=>{const he=u&&le,ve=J(H),se=Pn(H.path),Q=Pn(ve.path);try{await Ld(ve,H,{deleteRemoteBranch:he,deleteLocalBranch:Ne});const ye=Pn(j?.directoryOverride);return j?.open&&se&&ye===se&&Q&&(C(null),N({projectId:ve.id,directoryOverride:Q},{force:!0})),Pn(F)===se&&Q&&cs.getState().setDirectory(Q,{showOverlay:!1}),!0}catch(ye){return Ie.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Sr(ye instanceof Error?ye.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[le,F,u,J,j?.directoryOverride,j?.open,C,N,t]),ne=l.useCallback((H,Ne)=>{const he=u&≤(async()=>{if(!await Z(H,Ne))return;const se=t(he?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Ie.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Sr(se)})})()},[le,u,Z,t]),fe=l.useCallback(async()=>{if(i){w(!0);try{const H=Ae,Ne=H&&u,he=H&&f;if(i.sessions.length===0&&oe&&i.worktree){ne(i.worktree,he),me();return}if(i.sessions.length===1){const ve=i.sessions[0];if(!(oe?await D(ve.id):await k(ve.id))){Ie.error(t(oe?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),w(!1);return}const Q=!oe&&H?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Ie.success(t(oe?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Sr(Q),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const ve=i.sessions.map(ye=>ye.id);let se=[],Q=[];if(oe){const ye=await A(ve);se=ye.archivedIds,Q=ye.failedIds}else{const ye=await M(ve);se=ye.deletedIds,Q=ye.failedIds}if(oe&&i.worktree&&Q.length===0&&ne(i.worktree,he),se.length>0){const ye=!oe&&H?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,R=[Q.length>0?oe?Q.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Q.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Q.length}):Q.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Q.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Q.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,ye].filter(Boolean).join(" ");Ie.success(oe?se.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:se.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:se.length}):se.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:se.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:se.length}),{description:Sr(R||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Q.length>0&&(Ie.error(oe?Q.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Q.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Q.length}):Q.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Q.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Q.length}),{description:Sr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),se.length===0)){w(!1);return}}oe&&i.sessions.length===1&&i.worktree&&ne(i.worktree,he),me()}finally{w(!1)}}},[i,u,f,k,M,D,A,me,Ae,oe,ne,t]),xe=i?.worktree??a[0]?.metadata??null,Te=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",be=i?s.jsxs("div",{className:Ce(oe?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:Ce(oe?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[oe&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:Ce(oe?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(H=>s.jsxs("li",{className:Ce(oe?"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:Ce(!oe&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:H.title||t("sessions.sidebar.session.untitled")})]},H.id)),i.sessions.length>5&&s.jsx("li",{className:Ce(oe?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),oe?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(T,{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")}),xe?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:xe.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:xe?ii(xe.path,$):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),ee&&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,De=oe?le?s.jsxs("button",{type:"button",onClick:()=>{Se||m(H=>!H)},disabled:Se,className:Ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Se?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(T,{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,Ee=oe?s.jsxs("button",{type:"button",onClick:()=>{Y||g(H=>!H)},disabled:Y,className:Ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Y?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(T,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Re=oe?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:[Ee,De]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(et,{variant:"ghost",onClick:me,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(et,{variant:"destructive",onClick:fe,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>L(!_),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":!_,children:[_?s.jsx(T,{name:"checkbox-blank",className:"size-4"}):s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(et,{variant:"ghost",onClick:me,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(et,{variant:"destructive",onClick:fe,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),de=oe?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[G?s.jsx(Ci,{open:!!i,onClose:()=>{x||me()},title:de,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Re}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Te&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Te}),be]})}):s.jsx(qs,{open:!!i,onOpenChange:H=>{if(!H){if(x)return;me()}},children:s.jsxs(Ys,{className:Ce(oe?"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(En,{children:[s.jsxs(wn,{className:Ce(oe&&"flex items-center gap-2"),children:[oe&&s.jsx(T,{name:"delete-bin",className:"h-5 w-5"}),de]}),Te&&s.jsx(vn,{children:Te})]}),s.jsx("div",{className:Ce(oe&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:be}),s.jsx(mr,{className:"mt-2 gap-2 pt-1 pb-1",children:Re})]})}),s.jsx(Xp,{open:e,onOpenChange:n})]})};function mf(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return Nu.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function p0(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=Nu.CronExpressionParser.parse(t,r),i=[];for(let c=0;c<n;c+=1){const a=o.next();a&&i.push(a.toDate())}return i}catch{return[]}}const g0=[{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"}],x0={"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"},Dr=t=>x0[t]??t,hf=[0,1,2,3,4,5,6],sd="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",Ra=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(Dr))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],nd=()=>{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}`},ti=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),i=new Date(n,r-1,o);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==o?null:i},rd=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},b0=(t,e,n)=>{const r=ti(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},od=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),y0=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(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 f=m-c+1;if(f<=0){const g=d+f;u.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>a){u.push({date:new Date(n,r+1,f-a),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,f),inCurrentMonth:!0})}return u},w0=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:o}},jr=(t,e,n)=>{const r=Number(t),o=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let a=i%12;return n==="PM"&&(a+=12),`${String(a).padStart(2,"0")}:${String(c).padStart(2,"0")}`},Xr=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(o?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},id=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Xr(t,{min:1,max:12}),Uo=t=>/^[0-5][0-9]$/.test(t)?t:Xr(t,{max:59}),v0=(t,e)=>Xr(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),ad=(t,e)=>Xr(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),S0=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}},j0=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}},k0=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return hf.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},C0=(t,e)=>[...t.slice(e),...t.slice(0,e)],Ws=t=>{const e=tt.c(6),{htmlFor:n,required:r,children:o}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==i?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,i]})}),e[2]=o,e[3]=n,e[4]=i,e[5]=c):c=e[5],c},ld=t=>{const e=tt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:a,amLabel:d,pmLabel:u}=t;let m;e[0]!==n?(m=w0(n),e[0]=n,e[1]=m):m=e[1];const f=m,g=He.useRef(null),x=He.useRef(null),[w,S]=He.useState(null),[p,h]=He.useState(null),y=He.useRef(null),v=He.useRef(null);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j=de=>{y.current=de,S(de)},e[2]=j):j=e[2];const N=j;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=de=>{v.current=de,h(de)},e[3]=C):C=e[3];const k=C,D=E0,M=M0,A=R0;let _;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(_=de=>{const H=de.replace(/\D/g,"").slice(0,2);N(H),H.length===2&&(r(o?A(D(H),f.minute):jr(id(H),f.minute,f.meridiem)),N(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=_):_=e[8];const L=_;let F;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(F=()=>{const de=y.current;if(de!==null&&(N(null),de.length!==0)){if(o){r(A(D(de.padStart(2,"0")),f.minute));return}r(jr(id(de.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=F):F=e[13];const $=F;let W;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(W=de=>{const H=de.replace(/\D/g,"").slice(0,2);k(H),H.length===2&&(r(o?A(f.hour24,Uo(H)):jr(f.hour12,Uo(H),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=W):W=e[19];const U=W;let K;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(K=()=>{const de=v.current;de!==null&&(k(null),de.length!==0&&r(o?A(f.hour24,Uo(de.padStart(2,"0"))):jr(f.hour12,Uo(de.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=o,e[25]=K):K=e[25];const b=K;let P;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(P=de=>r(o?A(M(f.hour24,de),f.minute):jr(v0(f.hour12,de),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=o,e[32]=P):P=e[32];const V=P;let G;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(G=de=>r(o?A(f.hour24,ad(f.minute,de)):jr(f.hour12,ad(f.minute,de),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=G):G=e[39];const X=G;let J;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(J=de=>{de!==f.meridiem&&r(jr(f.hour12,f.minute,de))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=J):J=e[44];const ee=J;let le;e[45]!==$||e[46]!==V?(le=de=>{if(de.key==="ArrowRight"){de.preventDefault(),$(),x.current?.focus();return}(de.key==="ArrowUp"||de.key==="ArrowDown")&&(de.preventDefault(),N(null),V(de.key==="ArrowUp"?1:-1))},e[45]=$,e[46]=V,e[47]=le):le=e[47];const oe=le;let Ae;e[48]!==b||e[49]!==X?(Ae=de=>{if(de.key==="ArrowLeft"&&(de.currentTarget.selectionStart??0)===0){de.preventDefault(),b(),g.current?.focus();return}(de.key==="ArrowUp"||de.key==="ArrowDown")&&(de.preventDefault(),k(null),X(de.key==="ArrowUp"?1:-1))},e[48]=b,e[49]=X,e[50]=Ae):Ae=e[50];const Se=Ae,Y=o?"px-2":"pl-2 pr-1";let je;e[51]!==Y?(je=Ce("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",Y),e[51]=Y,e[52]=je):je=e[52];const me=w??(o?f.hour24:f.hour12);let z;e[53]!==L?(z=de=>L(de.target.value),e[53]=L,e[54]=z):z=e[54];let Z;e[55]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>N(""),e[55]=Z):Z=e[55];let ne;e[56]!==$||e[57]!==i||e[58]!==oe||e[59]!==me||e[60]!==z?(ne=s.jsx("input",{ref:g,inputMode:"numeric",value:me,onChange:z,onKeyDown:oe,onFocus:Z,onBlur:$,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=$,e[57]=i,e[58]=oe,e[59]=me,e[60]=z,e[61]=ne):ne=e[61];let fe;e[62]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=fe):fe=e[62];const xe=p??f.minute;let Te;e[63]!==U?(Te=de=>U(de.target.value),e[63]=U,e[64]=Te):Te=e[64];let be;e[65]===Symbol.for("react.memo_cache_sentinel")?(be=()=>k(""),e[65]=be):be=e[65];let De;e[66]!==b||e[67]!==c||e[68]!==Se||e[69]!==xe||e[70]!==Te?(De=s.jsx("input",{ref:x,inputMode:"numeric",value:xe,onChange:Te,onKeyDown:Se,onFocus:be,onBlur:b,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=b,e[67]=c,e[68]=Se,e[69]=xe,e[70]=Te,e[71]=De):De=e[71];let Ee;e[72]!==d||e[73]!==f.meridiem||e[74]!==a||e[75]!==u||e[76]!==ee||e[77]!==o?(Ee=o?null:s.jsxs(Vs,{value:f.meridiem,onValueChange:de=>ee(de),children:[s.jsx(Hs,{"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(As,{})}),s.jsxs(Ks,{children:[s.jsx(ls,{value:"AM",children:d}),s.jsx(ls,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=a,e[75]=u,e[76]=ee,e[77]=o,e[78]=Ee):Ee=e[78];let Re;return e[79]!==je||e[80]!==ne||e[81]!==De||e[82]!==Ee?(Re=s.jsxs("div",{className:je,children:[ne,fe,De,Ee]}),e[79]=je,e[80]=ne,e[81]=De,e[82]=Ee,e[83]=Re):Re=e[83],Re},cd=t=>new Date(t.getFullYear(),t.getMonth(),1),N0=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},dd=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),A0=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));return r.length>0?r:["09:00"]},ud=(t,e)=>{const n=Dr(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:A0(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:nd(),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:Dr(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:nd(),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}}},D0=(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(!mf(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")},P0=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))},I0=t=>{const e=tt.c(64),{draft:n,setDraft:r,locale:o,t:i}=t,c=n.schedule.cronExpression;let a;e[0]!==c?(a=c.trim()?mf(c):null,e[0]=c,e[1]=a):a=e[1];const d=a;let u;e:{if(!d?.valid||!c.trim()){let P;e[2]===Symbol.for("react.memo_cache_sentinel")?(P=[],e[2]=P):P=e[2],u=P;break e}let b;e[3]!==c||e[4]!==n.schedule.timezone?(b=p0(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=b):b=e[5],u=b}const m=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=b=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(b),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const g=f;let x;e[9]!==i?(x=i("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=i,e[10]=x):x=e[10];let w;e[11]!==x?(w=s.jsx(Ws,{htmlFor:"sched-cron",required:!0,children:x}),e[11]=x,e[12]=w):w=e[12];let S;e[13]!==r?(S=b=>r(P=>({...P,schedule:{...P.schedule,cronExpression:b.target.value}})),e[13]=r,e[14]=S):S=e[14];let p;e[15]!==i?(p=i("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=i,e[16]=p):p=e[16];let h;e[17]!==c||e[18]!==S||e[19]!==p?(h=s.jsx(Zn,{id:"sched-cron",value:c,onChange:S,placeholder:p,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=S,e[19]=p,e[20]=h):h=e[20];let y;e[21]!==c||e[22]!==d||e[23]!==i?(y=d&&!d.valid&&c.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:i("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=c,e[22]=d,e[23]=i,e[24]=y):y=e[24];let v;e[25]!==w||e[26]!==h||e[27]!==y?(v=s.jsxs("div",{className:"flex flex-col gap-1",children:[w,h,y]}),e[25]=w,e[26]=h,e[27]=y,e[28]=v):v=e[28];let j;e[29]!==g||e[30]!==m||e[31]!==i?(j=m.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:m.map(g).join(", ")})]}):null,e[29]=g,e[30]=m,e[31]=i,e[32]=j):j=e[32];let N;e[33]!==i?(N=i("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=i,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]!==i?(k=g0.map(b=>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(P=>({...P,schedule:{...P.schedule,cronExpression:b.expression}})),children:[s.jsx("span",{className:"font-mono",children:b.expression}),s.jsx("span",{className:"text-muted-foreground",children:i(b.labelKey)})]},b.expression)),e[37]=r,e[38]=i,e[39]=k):k=e[39];let D;e[40]!==k?(D=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:k}),e[40]=k,e[41]=D):D=e[41];let M;e[42]!==C||e[43]!==D?(M=s.jsxs("div",{className:"flex flex-col gap-1",children:[C,D]}),e[42]=C,e[43]=D,e[44]=M):M=e[44];let A;e[45]!==i?(A=i("sessions.scheduledTasks.editor.timezone.label"),e[45]=i,e[46]=A):A=e[46];let _;e[47]!==A?(_=s.jsx(Ws,{children:A}),e[47]=A,e[48]=_):_=e[48];let L;e[49]!==r?(L=b=>{r(P=>({...P,schedule:{...P.schedule,timezone:b}}))},e[49]=r,e[50]=L):L=e[50];let F;e[51]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(Hs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(As,{})}),e[51]=F):F=e[51];let $;e[52]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Ks,{children:Ra.map(O0)}),e[52]=$):$=e[52];let W;e[53]!==n.schedule.timezone||e[54]!==L?(W=s.jsxs(Vs,{value:n.schedule.timezone,onValueChange:L,children:[F,$]}),e[53]=n.schedule.timezone,e[54]=L,e[55]=W):W=e[55];let U;e[56]!==_||e[57]!==W?(U=s.jsxs("div",{className:"flex flex-col gap-1",children:[_,W]}),e[56]=_,e[57]=W,e[58]=U):U=e[58];let K;return e[59]!==v||e[60]!==j||e[61]!==M||e[62]!==U?(K=s.jsxs("div",{className:"flex flex-col gap-3",children:[v,j,M,U]}),e[59]=v,e[60]=j,e[61]=M,e[62]=U,e[63]=K):K=e[63],K};function T0(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=gt(),a=Vt(E=>E.loadProviders),d=Vt(E=>E.loadAgents),u=Vt(E=>E.providers),m=Vt(E=>E.currentProviderId),f=Vt(E=>E.currentModelId),g=Vt(E=>E.currentVariant||""),x=Vt(E=>E.currentAgentName||""),w=pe(E=>E.timeFormatPreference),S=pe(E=>E.weekStartPreference),p=pe(E=>E.isMobile),[h,y]=He.useState(()=>ud(n,{providerID:m,modelID:f,variant:g,agent:x})),[v,j]=He.useState(!1),[N,C]=He.useState(!1),[k,D]=He.useState(!1),[M,A]=He.useState(""),[_,L]=He.useState(!1),[F,$]=He.useState(""),[W,U]=He.useState(!1),[K,b]=He.useState(""),[P,V]=He.useState(()=>{const E=ti(n?.schedule?.date||"")||new Date;return new Date(E.getFullYear(),E.getMonth(),1)}),G=He.useRef(null),X=He.useRef(null),J=He.useRef(null),ee=He.useRef(null),le=He.useRef(null),oe=He.useMemo(()=>j0(c),[c]),Ae=He.useMemo(()=>S0(c),[c]),Se=He.useMemo(()=>w==="24h"?!0:w==="12h"?!1:oe,[w,oe]),Y=He.useMemo(()=>S==="sunday"?0:S==="monday"?1:Ae,[S,Ae]),je=He.useMemo(()=>{const E=k0(c);return C0(hf.map(I=>({value:I,label:E[I]||""})),Y)},[c,Y]);He.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,a,d]),He.useEffect(()=>{if(!e)return;y(ud(n,{providerID:m,modelID:f,variant:g,agent:x}));const E=ti(n?.schedule?.date||"")||new Date;V(new Date(E.getFullYear(),E.getMonth(),1)),C(!1),L(!1),D(!1),$(""),A("")},[e,n,m,f,g,x]),He.useEffect(()=>{if(!N)return;const E=I=>{G.current&&!G.current.contains(I.target)&&C(!1)};return document.addEventListener("mousedown",E),()=>{document.removeEventListener("mousedown",E)}},[N]);const me=He.useMemo(()=>{const I=u.find(ue=>ue.id===h.execution.providerID)?.models?.find(ue=>ue.id===h.execution.modelID);return I?.variants?Object.keys(I.variants):[]},[u,h.execution.providerID,h.execution.modelID]),z=me.length>0,Z=He.useMemo(()=>!z||!h.execution.variant?"__default":me.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,z,me]);He.useEffect(()=>{z||!h.execution.variant||y(E=>({...E,execution:{...E.execution,variant:""}}))},[z,h.execution.variant]);const ne=He.useCallback((E,I)=>{y(ue=>{const ke=new Set(ue.schedule.weekdays);return I?ke.add(E):ke.delete(E),{...ue,schedule:{...ue.schedule,weekdays:Array.from(ke).sort((we,qe)=>we-qe)}}})},[]),fe=He.useCallback((E,I)=>{y(ue=>{const ke=ue.schedule.times.slice();return ke[E]=I,{...ue,schedule:{...ue.schedule,times:ke}}})},[]),xe=He.useCallback(E=>{y(I=>{const ue=I.schedule.times.filter((ke,we)=>we!==E);return{...I,schedule:{...I.schedule,times:ue.length>0?ue:["09:00"]}}})},[]),Te=He.useCallback(()=>{y(E=>({...E,schedule:{...E.schedule,times:[...E.schedule.times,"12:00"]}}))},[]),be=He.useMemo(()=>N0(),[]),De=He.useMemo(()=>cd(be),[be]),Ee=He.useMemo(()=>{const E=ti(h.schedule.onceDate);return E?dd(E,be)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(E):null},[h.schedule.onceDate,c,i,be]),Re=He.useMemo(()=>cd(P).getTime()<=De.getTime(),[P,De]),de=He.useMemo(()=>je.map(E=>E.label),[je]),H=He.useCallback(E=>{y(I=>({...I,schedule:{...I.schedule,onceDate:E}}))},[]),Ne=He.useCallback((E,I)=>{if(E.startsWith("/")){const qe=E.indexOf(" "),Je=E.indexOf(`
|
|
187
|
-
`),st=Math.min(qe===-1?E.length:qe,Je===-1?E.length:Je);if(I<=st&&qe===-1){$(E.substring(1,st)),L(!0),D(!1),U(!1);return}}L(!1);const ue=E.substring(0,I),ke=ue.lastIndexOf("#");if(ke!==-1){const qe=ke>0?ue[ke-1]:null,Je=ue.substring(ke+1);if((!qe||/\s/.test(qe))&&!Je.includes(" ")&&!Je.includes(`
|
|
188
|
-
`)){b(Je),U(!0),D(!1);return}}U(!1);const we=ue.lastIndexOf("@");if(we!==-1){const qe=we>0?ue[we-1]:null,Je=ue.substring(we+1);(!qe||/\s/.test(qe))&&!Je.includes(" ")&&!Je.includes(`
|
|
189
|
-
`)?(A(Je),D(!0)):D(!1);return}D(!1)},[]),he=He.useCallback(E=>{y(I=>({...I,execution:{...I.execution,prompt:E}}))},[]),ve=He.useCallback(E=>{const I=h.execution.prompt,ke=X.current?.selectionStart??I.length,qe=I.substring(0,ke).lastIndexOf("@"),Je=E.relativePath&&E.relativePath.trim().length>0?E.relativePath.trim():E.path||E.name,st=qe!==-1?qe:ke,rt=`${I.substring(0,st)}@${Je} ${I.substring(ke)}`,ot=st+Je.length+2;he(rt),D(!1),A(""),requestAnimationFrame(()=>{const lt=X.current;lt&&(lt.selectionStart=ot,lt.selectionEnd=ot,lt.focus()),Ne(rt,ot)})},[h.execution.prompt,he,Ne]),se=He.useCallback(E=>{const I=h.execution.prompt,ke=X.current?.selectionStart??I.length,qe=I.substring(0,ke).lastIndexOf("@"),Je=qe!==-1?qe:ke,st=`${I.substring(0,Je)}@${E} ${I.substring(ke)}`,rt=Je+E.length+2;he(st),D(!1),A(""),requestAnimationFrame(()=>{const ot=X.current;ot&&(ot.selectionStart=rt,ot.selectionEnd=rt,ot.focus()),Ne(st,rt)})},[h.execution.prompt,he,Ne]),Q=He.useCallback(E=>{const I=`/${E.name} `;he(I),L(!1),$(""),U(!1),requestAnimationFrame(()=>{const ue=X.current;ue&&(ue.focus(),ue.selectionStart=ue.value.length,ue.selectionEnd=ue.value.length),Ne(I,I.length)})},[he,Ne]),ye=He.useCallback((E,I)=>{const ue=h.execution.prompt,we=X.current?.selectionStart??ue.length,Je=ue.substring(0,we).lastIndexOf("#"),st=Je!==-1?Je:we,rt=`${ue.substring(0,st)}#${I} ${ue.substring(we)}`,ot=st+I.length+2;he(rt),U(!1),b(""),requestAnimationFrame(()=>{const lt=X.current;lt&&(lt.selectionStart=ot,lt.selectionEnd=ot,lt.focus()),Ne(rt,ot)})},[h.execution.prompt,he,Ne]),re=He.useCallback(E=>{if(_&&ee.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")){E.preventDefault(),ee.current.handleKeyDown(E.key);return}k&&J.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")&&(E.preventDefault(),J.current.handleKeyDown(E.key)),W&&le.current&&(E.key==="Enter"||E.key==="ArrowUp"||E.key==="ArrowDown"||E.key==="Escape"||E.key==="Tab")&&(E.preventDefault(),le.current.handleKeyDown(E.key))},[_,k,W]),R=He.useCallback(async()=>{const E=D0(h,i);if(E){Ie.error(E);return}const I={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="cron"?{cron:h.schedule.cronExpression.trim()}:h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:P0(h.schedule.times),...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{},...h.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...h.execution.goalEnabled?{goalEnabled:!0}:{},...h.execution.goalEnabled&&h.execution.goalTokenBudget?{goalTokenBudget:h.execution.goalTokenBudget}:{}},...h.state?{state:h.state}:{}};j(!0);try{await o(I),r(!1)}catch(ue){Ie.error(ue instanceof Error?ue.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{j(!1)}},[h,r,o,i]),ce=He.useId(),Me=He.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),ge=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),te=i("sessions.scheduledTasks.editor.description"),ae=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(Ws,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Zn,{id:"sched-name",value:h.name,onChange:E=>y(I=>({...I,name:E.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Vs,{value:h.schedule.kind,onValueChange:E=>{y(I=>({...I,schedule:{...I.schedule,kind:E,...E==="cron"&&!I.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Hs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(As,{children:E=>i(E==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":E==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":E==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Ks,{children:[s.jsx(ls,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(ls,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(ls,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(ls,{value:"cron",children:i("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),h.schedule.kind==="cron"?s.jsx(I0,{draft:h,setDraft:y,locale:c,t:i}):h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:G,children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Ce(ou({size:"default"}),"w-fit max-w-full"),onClick:()=>C(E=>!E),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(T,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:b0(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(T,{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:()=>V(E=>od(E,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Re,children:s.jsx(T,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(P)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>V(E=>od(E,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(T,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:de.map((E,I)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:E},`${E}-${I}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:y0(P,Y).map(({date:E,inCurrentMonth:I})=>{const ue=rd(E),ke=ue===h.schedule.onceDate,we=dd(E,be),qe=E.getTime()<be.getTime(),Je=ke?"bg-interactive-selection text-interactive-selection-foreground":qe?"text-muted-foreground/40":I?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{qe||(H(ue),C(!1))},disabled:qe,className:["h-8 rounded-md typography-ui-label",Je,we&&!ke?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",qe?"cursor-not-allowed opacity-45":""].join(" "),children:E.getDate()},ue)})}),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:Ee||""}),s.jsx(et,{type:"button",size:"xs",variant:"ghost",onClick:()=>{H(rd(be)),V(new Date(be.getFullYear(),be.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(ld,{value:h.schedule.onceTime,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:E=>y(I=>({...I,schedule:{...I.schedule,onceTime:E}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Vs,{value:h.schedule.timezone,onValueChange:E=>{y(I=>({...I,schedule:{...I.schedule,timezone:E}}))},children:[s.jsx(Hs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(As,{})}),s.jsx(Ks,{children:Ra.map(E=>s.jsx(ls,{value:E,children:E},E))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:je.map(E=>{const I=h.schedule.weekdays.includes(E.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",I?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(zr,{checked:I,onChange:ue=>ne(E.value,ue),ariaLabel:E.label}),s.jsx("button",{type:"button",onClick:()=>ne(E.value,!I),className:"group-hover:text-foreground",children:E.label})]},E.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((E,I)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ld,{value:E,use24Hour:Se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:ue=>fe(I,ue)}),h.schedule.times.length>1?s.jsx(et,{type:"button",size:"icon",variant:"ghost",onClick:()=>xe(I),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null]},I))}),s.jsx("div",{children:s.jsxs(et,{type:"button",size:"sm",variant:"outline",onClick:Te,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Vs,{value:h.schedule.timezone,onValueChange:E=>{y(I=>({...I,schedule:{...I.schedule,timezone:E}}))},children:[s.jsx(Hs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(As,{})}),s.jsx(Ks,{children:Ra.map(E=>s.jsx(ls,{value:E,children:E},E))})]})]})]}),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(Ws,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Yh,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(E,I)=>{y(ue=>({...ue,execution:{...ue.execution,providerID:E,modelID:I,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Vs,{value:Z,disabled:!z,onValueChange:E=>{y(I=>({...I,execution:{...I.execution,variant:E==="__default"?"":E}}))},children:[s.jsx(Hs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(As,{children:E=>E==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):E})}),s.jsxs(Ks,{children:[s.jsx(ls,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),me.map(E=>s.jsx(ls,{value:E,children:E},E))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ws,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Qh,{agentName:h.execution.agent,filter:E=>ru(E.mode),onChange:E=>y(I=>({...I,execution:{...I.execution,agent:E}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ws,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(_r,{id:"sched-prompt",ref:X,value:h.execution.prompt,onChange:E=>{const I=E.target.value;he(I);const ue=E.target.selectionStart??I.length;Ne(I,ue)},onKeyDown:re,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),_?s.jsx(cu,{ref:ee,searchQuery:F,onCommandSelect:Q,onClose:()=>L(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(du,{ref:J,searchQuery:M,onFileSelect:ve,onAgentSelect:se,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,W?s.jsx(uu,{ref:le,searchQuery:K,onSnippetSelect:ye,onClose:()=>U(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),h.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(zr,{checked:h.execution.goalTokenBudget!==null,onChange:E=>y(I=>({...I,execution:{...I.execution,goalTokenBudget:E?2e5:null}})),ariaLabel:i("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),h.execution.goalTokenBudget!==null?s.jsx(Xh,{value:h.execution.goalTokenBudget,onValueChange:E=>{typeof E=="number"&&Number.isFinite(E)&&E>0&&y(I=>({...I,execution:{...I.execution,goalTokenBudget:Math.floor(E)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),ie=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(zr,{checked:h.enabled,onChange:E=>y(I=>({...I,enabled:E})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce(sd),onClick:()=>y(E=>({...E,execution:{...E.execution,permissionAutoAccept:!E.execution.permissionAutoAccept}})),"aria-pressed":h.execution.permissionAutoAccept,"aria-label":i("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:h.execution.permissionAutoAccept?s.jsx(T,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(T,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(mt,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce(sd,h.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>y(E=>({...E,execution:{...E.execution,goalEnabled:!E.execution.goalEnabled}})),"aria-pressed":h.execution.goalEnabled,"aria-label":i("sessions.scheduledTasks.editor.goal.aria"),children:h.execution.goalEnabled?s.jsx(T,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(T,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(mt,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(et,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(et,{type:"button",size:"sm",onClick:R,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return p?s.jsx(Ci,{open:e,title:ge,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:E=>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:ge}),E]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:te})]}),footer:ie,children:ae}):s.jsx(qs,{open:e,onOpenChange:E=>{!E&&Me()||r(E)},children:s.jsxs(Ys,{"aria-describedby":ce,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(vn,{id:ce,className:"sr-only",children:te}),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(wn,{className:"typography-ui-label font-medium text-foreground",children:ge}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:te})]})}),s.jsx(za,{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:ae})}),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:ie})})]})})}function E0(t){return Xr(t,{min:0,max:23})}function M0(t,e){return Xr(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function R0(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}function O0(t){return s.jsx(ls,{value:t,children:t},t)}const F0=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},B0=(t,e)=>{const n=F0(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:Dr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:Dr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:i,timezone:Dr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:Dr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},L0=(t,e)=>!t||!Number.isFinite(t)?"":Kd(t,e),fd=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,i=60*o,c=24*i,a=n>=0;if(r<o)return e(a?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return a?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<c){const f=Math.floor(r/i),g=Math.round(r%i/o),x=g>0?`${f}h ${g}m`:`${f}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/c),u=Math.round(r%c/i),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})},_0={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"}},$0=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function md(){const{t}=gt(),e=pe(b=>b.isScheduledTasksDialogOpen),n=pe(b=>b.setScheduledTasksDialogOpen),r=pe(b=>b.isMobile),o=pe(b=>b.timeFormatPreference),i=Yt(b=>b.projects),c=Yt(b=>b.getActiveProject()),a=cs(b=>b.homeDirectory),{currentTheme:d}=Ir(),[u,m]=He.useState(""),[f,g]=He.useState([]),[x,w]=He.useState(!0),[S,p]=He.useState(!1),[h,y]=He.useState(null),[v,j]=He.useState(null),N=He.useMemo(()=>i.find(b=>b.id===u)||null,[i,u]),C=He.useCallback(b=>{const P=b.label?.trim()||ur(b.path,a||void 0),V=b.icon?Ga[b.icon]:null,G=b.color?qa[b.color]:void 0,X=V?s.jsx(T,{name:V,className:"h-3.5 w-3.5 shrink-0",style:G?{color:G}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:G?{color:G}: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(Ya,{project:{id:b.id,iconImage:b.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:P})]})},[a,d.metadata.variant,d.colors.surface.foreground]),k=He.useCallback(async(b,P)=>{if(!b){g([]);return}P?.silent||w(!0);try{const V=await cg(b);V.sort((G,X)=>{if(G.enabled!==X.enabled)return G.enabled?-1:1;const J=G.name.localeCompare(X.name);return J!==0?J:(G.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(X.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(V)}catch(V){Ie.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),P?.silent||g([])}finally{P?.silent||w(!1)}},[t]);He.useEffect(()=>{if(!e)return;const b=c?.id||i[0]?.id||"";m(b),b?k(b):(g([]),w(!1))},[e,c,i,k]),He.useEffect(()=>{if(!e)return;let b=null;const P=ff(V=>{V.type==="scheduled-task-ran"&&V.projectId===u&&(b&&clearTimeout(b),b=setTimeout(()=>{k(u,{silent:!0})},400))});return()=>{b&&clearTimeout(b),P()}},[e,u,k]);const D=He.useCallback(async b=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await sc(u,b),await k(u),Ie.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,k,t]),M=He.useCallback(async(b,P)=>{if(u){j(b.id),g(V=>V.map(G=>G.id===b.id?{...G,enabled:P}:G));try{b.loopFile?await dg(u,b.id,P):await sc(u,{...b,enabled:P}),await k(u,{silent:!0})}catch(V){Ie.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(u,{silent:!0})}finally{j(null)}}},[u,k,t]),A=He.useCallback(async b=>{if(!(!u||!window.confirm(b.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:b.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:b.name})))){j(b.id);try{b.loopFile?await ug(u,b.id):await fg(u,b.id),await k(u,{silent:!0}),Ie.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(V){Ie.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{j(null)}}},[u,k,t]),_=He.useCallback(b=>{if(!b.loopFile){y(b),p(!0);return}if(N?.path){if(n(!1),r){On.getState().setSelectedPath(N.path,b.loopFile,{allowOutsideRoot:!0}),pe.getState().setActiveMainTab("files");return}pe.getState().openContextFile(N.path,b.loopFile)}},[r,N?.path,n]),L=He.useCallback(async b=>{if(u){j(b.id);try{const{sessionId:P}=await mg(u,b.id);if(await Promise.all([k(u,{silent:!0}),ai()]),Ie.success(t("sessions.scheduledTasks.dialog.toast.started")),P){const V=i.find(G=>G.id===u);Ge.getState().setCurrentSession(P,V?.path??null),pe.getState().setActiveMainTab("chat")}}catch(P){Ie.error(P instanceof Error?P.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{j(null)}}},[u,i,k,t]),F=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(Vs,{value:u||"__none",onValueChange:b=>{const P=b==="__none"?"":b;m(P),P?k(P):g([])},children:[s.jsx(Hs,{size:"lg",className:r?"w-full":void 0,children:N?s.jsx(As,{children:C(N)}):s.jsx(As,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Ks,{children:[i.length===0?s.jsx(ls,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(b=>s.jsx(ls,{value:b.id,children:C(b)},b.id))]})]})]}),$=()=>{y(null),p(!0)},W=b=>{m(b),b?k(b):g([])},U=s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(u?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(b=>{const P=v===b.id,V=b.state?.lastStatus||"idle",G=_0[V],X=t(V==="success"?"sessions.scheduledTasks.dialog.status.success":V==="error"?"sessions.scheduledTasks.dialog.status.error":V==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),J=b.state?.nextRunAt,ee=b.state?.lastRunAt;return s.jsxs("div",{className:Ce("rounded-lg border border-border p-4 transition-opacity",!b.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:b.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:B0(b,t)}),b.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:b.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:b.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(T,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),J?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:fd(J,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:L0(J,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(T,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),V==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(T,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):ee?s.jsxs(s.Fragment,{children:[G.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${G.tone})`},children:[s.jsx(T,{name:G.Icon,className:"h-3.5 w-3.5"}),X]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:fd(ee,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),b.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:$0("error"),children:[s.jsx(T,{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:b.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Ce("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",b.enabled?"text-foreground":"text-muted-foreground",P&&"cursor-not-allowed opacity-50"),children:[s.jsx(zr,{checked:b.enabled,onChange:le=>{M(b,le)},ariaLabel:b.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:b.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:b.name}),disabled:P}),b.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(et,{variant:"outline",size:"sm",onClick:()=>{L(b)},disabled:P,children:[s.jsx(T,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(et,{variant:"outline",size:"sm",onClick:()=>_(b),disabled:P,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:b.name}),children:[s.jsx(T,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(et,{variant:"destructive",size:"sm",onClick:()=>{A(b)},disabled:P,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:b.name}),children:s.jsx(T,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},b.id)})})}),K=s.jsxs("div",{className:"space-y-4",children:[F,U]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Ci,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:b=>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")}),b]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(et,{className:"w-full",onClick:$,disabled:!u,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:K}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:i.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):i.map(b=>s.jsx("button",{type:"button",onClick:()=>W(b.id),className:Ce("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===b.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:C(b)},b.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(et,{size:"sm",onClick:$,disabled:!u,children:[s.jsx(T,{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:U})})]})]})}):null,s.jsx(T0,{open:S,task:h,onOpenChange:p,onSave:D})]})}const si=100;function hd(){const t=tt.c(105),{t:e}=gt(),n=pe(Y0),r=pe(q0),o=pe(G0),i=Ge(K0),c=Ge(H0),a=cs(V0);let d;t[0]!==n?(d=ee=>n?ee.archivedSessions:[],t[0]=n,t[1]=d):d=t[1];const u=Ms(Qn(d)),[m,f]=l.useState(""),[g,x]=l.useState(null),[w,S]=l.useState(si);let p;t[2]!==m?(p=m.trim().toLowerCase(),t[2]=m,t[3]=p):p=t[3];const h=p;let y;e:{if(!n){let le;t[4]===Symbol.for("react.memo_cache_sentinel")?(le=[],t[4]=le):le=t[4],y=le;break e}let ee;t[5]!==u?(ee=[...u].sort(U0),t[5]=u,t[6]=ee):ee=t[6],y=ee}const v=y;let j;if(t[7]!==a||t[8]!==v||t[9]!==e){const ee=new Map;for(const le of v){const oe=vt(Gs(le))??"",Ae=ee.get(oe);if(Ae){Ae.sessions.push(le);continue}ee.set(oe,{directory:oe,label:oe?ur(oe,a)||oe:e("sessions.archivePage.otherProjects"),sessions:[le]})}j=[...ee.values()].sort(W0),t[7]=a,t[8]=v,t[9]=e,t[10]=j}else j=t[10];const N=j;let C;e:{if(h){let le;if(t[11]!==h||t[12]!==v){let oe;t[14]!==h?(oe=Ae=>(Ae.title??"").toLowerCase().includes(h),t[14]=h,t[15]=oe):oe=t[15],le=v.filter(oe),t[11]=h,t[12]=v,t[13]=le}else le=t[13];C=le;break e}if(g===null){C=v;break e}let ee;t[16]!==N||t[17]!==g?(ee=N.find(le=>le.directory===g)?.sessions??[],t[16]=N,t[17]=g,t[18]=ee):ee=t[18],C=ee}const k=C;let D,M,A,_,L,F,$,W,U,K;if(t[19]!==u.length||t[20]!==N||t[21]!==k||t[22]!==a||t[23]!==h||t[24]!==n||t[25]!==m||t[26]!==g||t[27]!==o||t[28]!==i||t[29]!==r||t[30]!==e||t[31]!==c||t[32]!==w){L=Symbol.for("react.early_return_sentinel");e:{const ee=k.slice(0,w);D=k.length-ee.length;const le=u.length;let oe;t[43]===Symbol.for("react.memo_cache_sentinel")?(oe=de=>{x(de),S(si)},t[43]=oe):oe=t[43];const Ae=oe;let Se;t[44]!==o||t[45]!==i||t[46]!==r?(Se=de=>{const H=vt(Gs(de));i(de.id,H??void 0),o("chat"),r(!1)},t[44]=o,t[45]=i,t[46]=r,t[47]=Se):Se=t[47];const Y=Se;let je;t[48]!==e||t[49]!==c?(je=de=>{c(de.id).then(H=>{H?Ie.success(e("sessions.sidebar.session.restore.success")):Ie.error(e("sessions.sidebar.session.restore.error"))})},t[48]=e,t[49]=c,t[50]=je):je=t[50];const me=je;if(!n){L=null;break e}let z;t[51]!==e?(z=(de,H,Ne,he,ve,se,Q)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:ve,title:se,className:Ce("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",Q?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",he?"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:H}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Ne})]}),Q?s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Ln.requestDelete({sessions:Q,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:H}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(mt,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},de),t[51]=e,t[52]=z):z=t[52];const Z=z;_="absolute inset-0 z-10 flex flex-col bg-background",M="flex min-h-0 flex-1";let ne;if(t[53]!==Z||t[54]!==g||t[55]!==e||t[56]!==le){let de;t[58]===Symbol.for("react.memo_cache_sentinel")?(de=()=>Ae(null),t[58]=de):de=t[58],ne=Z("__all__",e("sessions.archivePage.allDirectories"),le,g===null,de),t[53]=Z,t[54]=g,t[55]=e,t[56]=le,t[57]=ne}else ne=t[57];let fe;if(t[59]!==N||t[60]!==Z||t[61]!==g){let de;t[63]!==Z||t[64]!==g?(de=H=>Z(H.directory||"__none__",H.label,H.sessions.length,g===H.directory,()=>Ae(H.directory),H.directory||void 0,H.sessions),t[63]=Z,t[64]=g,t[65]=de):de=t[65],fe=N.map(de),t[59]=N,t[60]=Z,t[61]=g,t[62]=fe}else fe=t[62];t[66]!==ne||t[67]!==fe?(A=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[ne,fe]})}),t[66]=ne,t[67]=fe,t[68]=A):A=t[68],U="flex min-w-0 flex-1 flex-col";let xe;t[69]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(T,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[69]=xe):xe=t[69];let Te;t[70]===Symbol.for("react.memo_cache_sentinel")?(Te=de=>{f(de.target.value),S(si)},t[70]=Te):Te=t[70];let be;t[71]!==e?(be=e("sessions.archivePage.searchPlaceholder"),t[71]=e,t[72]=be):be=t[72];let De;t[73]!==m||t[74]!==be?(De=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[xe,s.jsx("input",{value:m,onChange:Te,placeholder:be,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[73]=m,t[74]=be,t[75]=De):De=t[75];let Ee;t[76]!==k.length||t[77]!==e?(Ee=k.length===1?e("sessions.archivePage.countSingle",{count:k.length}):e("sessions.archivePage.countPlural",{count:k.length}),t[76]=k.length,t[77]=e,t[78]=Ee):Ee=t[78];let Re;t[79]!==Ee?(Re=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:Ee}),t[79]=Ee,t[80]=Re):Re=t[80],t[81]!==De||t[82]!==Re?(K=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[De,Re]}),t[81]=De,t[82]=Re,t[83]=K):K=t[83],W="min-h-0 flex-1 overflow-y-auto px-6 py-3",F="mx-auto w-full max-w-3xl space-y-0.5",$=ee.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(h?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):ee.map(de=>{const H=vt(Gs(de))??"",Ne=H?ur(H,a)||H: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:()=>Y(de),role:"button",tabIndex:0,onKeyDown:he=>{(he.key==="Enter"||he.key===" ")&&(he.preventDefault(),Y(de))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:de.title||e("sessions.sidebar.session.untitled")}),h&&Ne?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:H,children:Ne}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:au(de.time?.archived??de.time?.updated??de.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),me(de)},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:de.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(T,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),Ln.requestDelete({sessions:[de],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:de.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},de.id)})}t[19]=u.length,t[20]=N,t[21]=k,t[22]=a,t[23]=h,t[24]=n,t[25]=m,t[26]=g,t[27]=o,t[28]=i,t[29]=r,t[30]=e,t[31]=c,t[32]=w,t[33]=D,t[34]=M,t[35]=A,t[36]=_,t[37]=L,t[38]=F,t[39]=$,t[40]=W,t[41]=U,t[42]=K}else D=t[33],M=t[34],A=t[35],_=t[36],L=t[37],F=t[38],$=t[39],W=t[40],U=t[41],K=t[42];if(L!==Symbol.for("react.early_return_sentinel"))return L;let b;t[84]!==D||t[85]!==e?(b=D>0?s.jsx("button",{type:"button",onClick:()=>S(z0),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[84]=D,t[85]=e,t[86]=b):b=t[86];let P;t[87]!==b||t[88]!==F||t[89]!==$?(P=s.jsxs("div",{className:F,children:[$,b]}),t[87]=b,t[88]=F,t[89]=$,t[90]=P):P=t[90];let V;t[91]!==P||t[92]!==W?(V=s.jsx("div",{className:W,children:P}),t[91]=P,t[92]=W,t[93]=V):V=t[93];let G;t[94]!==V||t[95]!==U||t[96]!==K?(G=s.jsxs("div",{className:U,children:[K,V]}),t[94]=V,t[95]=U,t[96]=K,t[97]=G):G=t[97];let X;t[98]!==M||t[99]!==A||t[100]!==G?(X=s.jsxs("div",{className:M,children:[A,G]}),t[98]=M,t[99]=A,t[100]=G,t[101]=X):X=t[101];let J;return t[102]!==_||t[103]!==X?(J=s.jsx("div",{className:_,children:X}),t[102]=_,t[103]=X,t[104]=J):J=t[104],J}function z0(t){return t+si}function W0(t,e){return e.sessions.length-t.sessions.length}function U0(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function V0(t){return t.homeDirectory}function H0(t){return t.unarchiveSession}function K0(t){return t.setCurrentSession}function G0(t){return t.setActiveMainTab}function q0(t){return t.setArchivePageOpen}function Y0(t){return t.isArchivePageOpen}function pd(){const t=tt.c(18),{t:e}=gt(),n=pe(J0),r=pe(X0),o=Yt(Q0);let i;t[0]!==n?(i=x=>x.projects.find(w=>w.id===n)??null,t[0]=n,t[1]=i):i=t[1];const c=Yt(i);if(!n||!c)return null;let a;t[2]!==c.id||t[3]!==o||t[4]!==r?(a=()=>{o(c.id),r(!0)},t[2]=c.id,t[3]=o,t[4]=r,t[5]=a):a=t[5];let d;t[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(T,{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(et,{size:"sm",onClick:a,children:[d,u]})}),t[9]=a,t[10]=u,t[11]=m):m=t[11];let f;t[12]!==c.id||t[13]!==c.path?(f=s.jsx(Jp,{projectRef:{id:c.id,path:c.path},sections:"list-only"}),t[12]=c.id,t[13]=c.path,t[14]=f):f=t[14];let g;return t[15]!==m||t[16]!==f?(g=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,f]})})}),t[15]=m,t[16]=f,t[17]=g):g=t[17],g}function Q0(t){return t.setActiveProjectIdOnly}function X0(t){return t.setNewWorktreeDialogOpen}function J0(t){return t.worktreesPageProjectId}const Oa=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),Z0=(t,e)=>{const n=Oa(t),r=Oa(e);return`${n}-${r}`.substring(0,60)},gd=(t,e)=>`${t}/${e}`,ej=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},xd=(t,e)=>{const n=ej(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};op(t.id,n),Ge.getState().markSessionAsOpenChamberCreated(t.id),Ms.getState().upsertSession(o);try{li().ensureChild(n,{bootstrap:!1}).setState(c=>{const a=c.session.findIndex(u=>u.id===t.id);if(a>=0&&c.session[a]===o)return c;const d=a>=0?c.session.map((u,m)=>m===a?o:u):[...c.session,o].sort((u,m)=>u.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},tj=()=>{const t=Yt.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=cs.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},la=Qr()(ku(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:i,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let 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;if(r[a].models.length>5)return t({error:`Group ${a+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const a=tj();if(!a)return t({error:"Select a project",isLoading:!1}),null;const d=a.path,m=await lu(d)&&e.isolateRuns!==!1,f=Oa(n),g=m?await Ni(d):void 0,x=m?await Jh(d):null,w=[],S=c?.filter(j=>j.trim().length>0)??[];for(let j=0;j<r.length;j++){const N=r[j],C=N.prompt,k=new Map;for(const M of N.models){const A=`${M.providerID}:${M.modelID}`;k.set(A,(k.get(A)||0)+1)}const D=new Map;for(const M of N.models){const A=`${M.providerID}:${M.modelID}`,_=k.get(A)||1,L=(D.get(A)||0)+1;D.set(A,L);const F=Z0(M.providerID,M.modelID),$=r.length>1?`g${j+1}`:void 0,W=_>1?gd(f,`${F}/${L}`):gd(f,F),U=$?`${$}/${W}`:W,K=hS({groupSlug:f,runGroup:$,providerID:M.providerID,modelID:M.modelID,index:_>1?L:void 0});try{if(!m){const G=await en.withDirectory(d,()=>en.createSession({title:K}));xd(G,d),w.push({sessionId:G.id,worktreePath:d,providerID:M.providerID,modelID:M.modelID,variant:M.variant,prompt:C});continue}const b=await Zh(a,{preferredName:U,mode:"new",branchName:U,worktreeName:U,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:S,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:x}),P={...b,createdFromBranch:g,kind:"standard"};await ep(a)&&await tp(b.path);const V=await en.withDirectory(b.path,()=>en.createSession({title:K}));xd(V,b.path),Ge.getState().setWorktreeMetadata(V.id,P),w.push({sessionId:V.id,worktreePath:b.path,providerID:M.providerID,modelID:M.modelID,variant:M.variant,prompt:C})}catch(b){console.warn("[MultiRun] Failed to create session:",b)}}}const p=c?.filter(j=>j.trim().length>0)??[];p.length>0&&sp(a,p).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=w.map(j=>j.sessionId),y=w[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const v=i?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{const j=np.getState().expandText;await Promise.allSettled(w.map(async N=>{try{const C=await j(N.prompt).catch(()=>N.prompt);await rp({sessionId:N.sessionId,directory:N.worktreePath,content:C,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:o,files:v})}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:h,firstSessionId:y}}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 pf(t){const e=tt.c(30),{git:n}=tr(),r=qd(t),o=ip(t),i=ap(t),c=lp(t),a=dr(ij),d=dr(oj);let u,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==o||e[4]!==i?(u=()=>{!t||!n||o!==null||i||d(t,n,{silent:!0})},m=[t,n,d,o,i],e[0]=t,e[1]=d,e[2]=n,e[3]=o,e[4]=i,e[5]=u,e[6]=m):(u=e[5],m=e[6]),l.useEffect(u,m);let f;e[7]!==r?.all||e[8]!==t||e[9]!==a||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||a(t,n))},e[7]=r?.all,e[8]=t,e[9]=a,e[10]=n,e[11]=o,e[12]=f):f=e[12];const g=r?.all;let x;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==o||e[17]!==g?(x=[t,n,o,g,a],e[13]=t,e[14]=a,e[15]=n,e[16]=o,e[17]=g,e[18]=x):x=e[18],l.useEffect(f,x);const w=i||o===!0&&c;let S;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],S=k;break e}let C;e[20]!==r.all?(C=r.all.filter(rj).sort(),e[20]=r.all,e[21]=C):C=e[21],S=C}const p=S;let h;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],h=k;break e}let C;e[23]!==r.all?(C=r.all.filter(nj).map(sj).sort(),e[23]=r.all,e[24]=C):C=e[24],h=C}const y=h;let v;e:{if(!t){v=null;break e}if(o!==null){v=o;break e}if(w){v=null;break e}v=r?.all?!0:null}const j=v;let N;return e[25]!==j||e[26]!==w||e[27]!==p||e[28]!==y?(N={localBranches:p,remoteBranches:y,isLoading:w,isGitRepository:j},e[25]=j,e[26]=w,e[27]=p,e[28]=y,e[29]=N):N=e[29],N}function sj(t){return t.replace(/^remotes\//,"")}function nj(t){return t.startsWith("remotes/")}function rj(t){return!t.startsWith("remotes/")}function oj(t){return t.fetchStatus}function ij(t){return t.fetchBranches}const aj=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=gt(),{localBranches:a,remoteBranches:d,isLoading:u,isGitRepository:m}=pf(t),f=l.useMemo(()=>[...a,...d.map(x=>`remotes/${x}`)],[a,d]);l.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;const x=e;let w=!1;return(async()=>{try{const p=t?await Ni(t).catch(()=>null):null;if(w)return;const h=localStorage.getItem(tc),{sourceBranch:y,shouldClearSavedSourceBranch:v}=Zp({branches:f,savedSourceBranch:h,rootBranch:p});if(v&&localStorage.removeItem(tc),w||x&&f.includes(x))return;y&&n(y)}catch{}})(),()=>{w=!0}},[f,t,o,u,n,e]);const g=o||!m||u;return s.jsxs("div",{children:[s.jsxs(Vs,{value:e,onValueChange:n,disabled:g,children:[s.jsx(Hs,{id:i,size:"lg",className:Ce("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(As,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Ks,{className:"max-h-[280px] max-w-[320px]",children:u?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):a.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[a.length>0&&s.jsxs(xa,{children:[s.jsx(Hl,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),a.map(x=>s.jsx(ls,{value:x,className:"whitespace-normal break-all",children:x},x))]}),a.length>0&&d.length>0&&s.jsx(cp,{}),d.length>0&&s.jsxs(xa,{children:[s.jsx(Hl,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(ls,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},lj=10*1024*1024,ca=5,ni=t=>{const e=tt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(ft,{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(T,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(ut,{children:[r,s.jsx(mt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},Nr=t=>{const e=tt.c(9),{htmlFor:n,required:r,children:o,info:i}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let a;e[2]!==o||e[3]!==n||e[4]!==c?(a=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=a):a=e[5];const d=i&&i;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},bd=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=gt(),[i,c]=l.useState(""),[a,d]=l.useState(()=>[{id:ho(),prompt:"",models:[]}]),[u,m]=l.useState(""),[f,g]=l.useState([]),[x,w]=l.useState(!1),[S,p]=l.useState([]),[h,y]=l.useState(!1),[v,j]=l.useState(!1),[N,C]=l.useState(!0),k=l.useRef(null),D=cs(Q=>Q.currentDirectory??null),M=cs(Q=>Q.homeDirectory??null),A=l.useMemo(()=>{if(typeof window>"u")return null;const Q=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Q=="string"&&Q.trim().length>0?Q.trim():null},[]),_=Yt(Q=>Q.activeProjectId),L=Yt(Q=>Q.setActiveProjectIdOnly),F=Yt(Q=>Q.projects),[$,W]=l.useState(()=>_??null);l.useEffect(()=>{if(_){W(_);return}!$&&F.length>0&&W(F[0].id)},[_,F,$]);const U=l.useMemo(()=>$?F.find(Q=>Q.id===$)??null:null,[F,$]),K=U?.path??D,b=l.useCallback(Q=>{W(Q),Q!==_&&L(Q)},[_,L]),{currentTheme:P}=Ir(),V=l.useCallback(Q=>{const ye=Q.label?.trim()||ur(Q.path,M),re=Q.icon?Ga[Q.icon]:null,R=Q.color?qa[Q.color]:void 0,ce=re?s.jsx(T,{name:re,className:"h-3.5 w-3.5 shrink-0",style:R?{color:R}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:R?{color:R}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[Q.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Q.iconBackground?{backgroundColor:Q.iconBackground}:void 0,children:s.jsx(Ya,{project:{id:Q.id,iconImage:Q.iconImage??null},options:{themeVariant:P.metadata.variant,iconColor:P.colors.surface.foreground},className:"h-full w-full object-contain",fallback:ce})}):ce,s.jsx("span",{className:"truncate",children:ye})]})},[M,P.metadata.variant,P.colors.surface.foreground]),G=l.useMemo(()=>{if(U?.path)return{id:U.id,path:U.path};const Q=D??A;return Q?{id:`path:${Q}`,path:Q}:null},[U,D,A]),[X]=l.useState(()=>typeof window<"u"?_n():!1),J=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ee=$d(),le=l.useMemo(()=>{if(typeof window>"u")return null;const Q=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Q=="number"&&Number.isFinite(Q)&&Q>0)return Q;if(typeof navigator>"u")return null;const ye=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ye)return null;const re=Number.parseInt(ye[1],10),R=Number.parseInt(ye[2],10);return Number.isNaN(re)?null:re===10?R:re},[]),oe=l.useMemo(()=>X&&J||ee?"pl-[5.5rem]":"pl-3",[X,J,ee]),Ae=l.useMemo(()=>!X||!J||le===null?"":le>=26?"h-12":le<=15?"h-14":"",[X,J,le]),Se=l.useCallback(async Q=>{Q.target.closest("button, a, input, select, textarea")||Q.button===0&&X&&await dp()},[X]);l.useEffect(()=>{if(!n)return;const Q=ye=>{ye.key==="Escape"&&(ye.preventDefault(),ye.stopPropagation(),n())};return window.addEventListener("keydown",Q,!0),()=>window.removeEventListener("keydown",Q,!0)},[n]);const[Y,je]=l.useState(""),{isLoading:me,isGitRepository:z}=pf(K),Z=l.useRef(!1),ne=z===!0,fe=ne&&N;l.useEffect(()=>{if(z===!1){Z.current=!0,C(!1);return}z===!0&&Z.current&&(Z.current=!1,C(!0))},[z]);const xe=la(Q=>Q.createMultiRun),Te=la(Q=>Q.error),be=la(Q=>Q.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Q=>{const ye=[...Q];return ye.length>0&&!ye[0].prompt.trim()&&(ye[0]={...ye[0],prompt:t}),ye})},[t]),l.useEffect(()=>{if(!G)return;let Q=!1;return j(!0),(async()=>{try{const ye=await up(G);Q||p(ye)}catch{}finally{Q||j(!1)}})(),()=>{Q=!0}},[G]);const De=l.useCallback((Q,ye)=>{d(re=>re.map(R=>R.id===Q?{...R,...ye}:R))},[]),Ee=l.useCallback(Q=>{d(ye=>ye.filter(re=>re.id!==Q))},[]),Re=l.useCallback(()=>{d(Q=>[...Q,{id:ho(),prompt:"",models:[]}])},[]),de=async Q=>{const ye=Q.target.files;if(!ye)return;let re=0;for(let R=0;R<ye.length;R++){const ce=ye[R];if(ce.size>lj){Ie.error(o("multirun.launcher.toast.fileTooLarge",{fileName:ce.name}));continue}try{const Me=await new Promise((ge,te)=>{const ae=new FileReader;ae.onload=()=>ge(ae.result),ae.onerror=te,ae.readAsDataURL(ce)});g(ge=>[...ge,{id:ho(),filename:ce.name,mimeType:ce.type||"application/octet-stream",size:ce.size,dataUrl:Me}]),re++}catch(Me){console.error("File attach failed",Me),Ie.error(o("multirun.launcher.toast.attachFailed",{fileName:ce.name}))}}re>0&&Ie.success(re===1?o("multirun.launcher.toast.attachedSingle",{count:re}):o("multirun.launcher.toast.attachedPlural",{count:re})),k.current&&(k.current.value="")},H=Q=>{g(ye=>ye.filter(re=>re.id!==Q))},Ne=l.useMemo(()=>a.reduce((Q,ye)=>Q+ye.models.length,0),[a]),he=async Q=>{Q.preventDefault();const ye=a.filter(re=>re.prompt.trim()&&re.models.length>=1);if(ye.length!==0&&!(Ne<1)){w(!0),be();try{$&&$!==_&&L($);const re=f.map(te=>({mime:te.mimeType,filename:te.filename,url:te.dataUrl})),R=S.filter(te=>te.trim().length>0),ce=ye.map(te=>({prompt:te.prompt.trim(),models:te.models.map(ae=>({providerID:ae.providerID,modelID:ae.modelID,displayName:ae.displayName,variant:ae.variant}))})),Me={name:i.trim(),groups:ce,agent:u||void 0,worktreeBaseBranch:fe?Y:void 0,isolateRuns:fe,files:re.length>0?re:void 0,setupCommands:R.length>0?R:void 0},ge=await xe(Me);ge&&(ge.firstSessionId&&Ge.getState().setCurrentSession(ge.firstSessionId),e?.())}finally{w(!1)}}},ve=!!(i.trim()&&a.some(Q=>Q.prompt.trim()&&Q.models.length>=1)&&Ne>=1&&K&&!me&&(z===!1||!fe||Y)),se=S.filter(Q=>Q.trim()).length;return s.jsxs("form",{onSubmit:he,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Se,className:Ce("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",oe,Ae),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(T,{name:"close",className:"h-5 w-5"})})}),s.jsx(mt,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(za,{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(Nr,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),F.length>0?s.jsxs(Vs,{value:$??void 0,onValueChange:b,children:[s.jsx(Hs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:U?s.jsx(As,{children:V(U)}):s.jsx(As,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(Ks,{fitContent:!0,children:F.map(Q=>s.jsx(ls,{value:Q.id,className:"max-w-[24rem]",children:V(Q)},Q.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nr,{htmlFor:"group-name",required:!0,info:s.jsx(ni,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(Zn,{id:"group-name",value:i,onChange:Q=>c(Q.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nr,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(ni,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(aj,{directory:K,value:Y,onChange:je,disabled:!fe,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(zr,{checked:N,onChange:C,disabled:!ne,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nr,{htmlFor:"multirun-agent",info:s.jsx(ni,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(lf,{value:u,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(ci,{open:h,onOpenChange:y,children:[s.jsxs(Ja,{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(T,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:o("multirun.launcher.setupCommands.label")}),se>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:se}),s.jsx(T,{name:"arrow-down-s",className:Ce("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(di,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:v?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[S.map((Q,ye)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Zn,{value:Q,onChange:re=>{const R=[...S];R[ye]=re.target.value,p(R)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>p(S.filter((re,R)=>R!==ye)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})})]},`${Q}-${ye}`)),s.jsxs("button",{type:"button",onClick:()=>p([...S,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(T,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Nr,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:de,accept:"*/*"}),s.jsxs(ut,{children:[s.jsx(ft,{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(T,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(mt,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(Q=>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:[Q.mimeType.startsWith("image/")?s.jsx(T,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(T,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Q.filename,children:Q.filename}),s.jsx("button",{type:"button",onClick:()=>H(Q.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(T,{name:"close",className:"h-3 w-3"})})]},Q.id))]})]}),a.map((Q,ye)=>s.jsx(cj,{group:Q,groupIndex:ye,canRemove:a.length>1,onUpdate:De,onRemove:Ee},Q.id)),s.jsxs("button",{type:"button",onClick:Re,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(T,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),Te&&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:Te})]})})}),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:[!fe&&z!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(et,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}):null,s.jsx(et,{type:"submit",size:"sm",disabled:!ve||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Ne})})})]})})]})},cj=t=>{const e=tt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:a}=gt(),[d,u]=l.useState(!1),[m,f]=l.useState(""),[g,x]=l.useState(!1),[w,S]=l.useState(""),[p,h]=l.useState(!1),[y,v]=l.useState(""),j=l.useRef(null),N=l.useRef(null),C=l.useRef(null),k=l.useRef(null);let D;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(D=R=>{n.models.length>=ca||i(n.id,{models:[...n.models,R]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=D):D=e[3];const M=D;let A;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(A=R=>{i(n.id,{models:n.models.filter((ce,Me)=>Me!==R)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=A):A=e[7];const _=A;let L;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(L=(R,ce)=>{i(n.id,{models:n.models.map((Me,ge)=>ge===R?ce:Me)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=L):L=e[11];const F=L;let $;e[12]===Symbol.for("react.memo_cache_sentinel")?($=(R,ce)=>{if(R.startsWith("/")){const ae=R.indexOf(" "),ie=R.indexOf(`
|
|
190
|
-
`),E=Math.min(ae===-1?R.length:ae,ie===-1?R.length:ie);if(ce<=E&&ae===-1){S(R.substring(1,E)),x(!0),u(!1),h(!1);return}}x(!1);const Me=R.substring(0,ce),ge=Me.lastIndexOf("#");if(ge!==-1){const ae=ge>0?Me[ge-1]:null,ie=Me.substring(ge+1);if((!ae||/\s/.test(ae))&&!ie.includes(" ")&&!ie.includes(`
|
|
191
|
-
`)){v(ie),h(!0),u(!1);return}}h(!1);const te=Me.lastIndexOf("@");if(te!==-1){const ae=te>0?Me[te-1]:null,ie=Me.substring(te+1);(!ae||/\s/.test(ae))&&!ie.includes(" ")&&!ie.includes(`
|
|
192
|
-
`)?(f(ie),u(!0)):u(!1);return}u(!1)},e[12]=$):$=e[12];const W=$;let U;e[13]!==n.id||e[14]!==i?(U=R=>{i(n.id,{prompt:R})},e[13]=n.id,e[14]=i,e[15]=U):U=e[15];const K=U;let b;e[16]!==n.prompt||e[17]!==K?(b=R=>{const ce=n.prompt,ge=j.current?.selectionStart??ce.length,ae=ce.substring(0,ge).lastIndexOf("@"),ie=R.relativePath&&R.relativePath.trim().length>0?R.relativePath.trim():R.path||R.name,E=ae!==-1?ae:ge,I=`${ce.substring(0,E)}@${ie} ${ce.substring(ge)}`,ue=E+ie.length+2;K(I),u(!1),f(""),requestAnimationFrame(()=>{const ke=j.current;ke&&(ke.selectionStart=ue,ke.selectionEnd=ue,ke.focus()),W(I,ue)})},e[16]=n.prompt,e[17]=K,e[18]=b):b=e[18];const P=b;let V;e[19]!==n.prompt||e[20]!==K?(V=R=>{const ce=n.prompt,ge=j.current?.selectionStart??ce.length,ae=ce.substring(0,ge).lastIndexOf("@"),ie=ae!==-1?ae:ge,E=`${ce.substring(0,ie)}@${R} ${ce.substring(ge)}`,I=ie+R.length+2;K(E),u(!1),f(""),requestAnimationFrame(()=>{const ue=j.current;ue&&(ue.selectionStart=I,ue.selectionEnd=I,ue.focus()),W(E,I)})},e[19]=n.prompt,e[20]=K,e[21]=V):V=e[21];const G=V;let X;e[22]!==K?(X=R=>{const ce=`/${R.name} `;K(ce),x(!1),S(""),h(!1),requestAnimationFrame(()=>{const Me=j.current;Me&&(Me.focus(),Me.selectionStart=Me.value.length,Me.selectionEnd=Me.value.length),W(ce,ce.length)})},e[22]=K,e[23]=X):X=e[23];const J=X;let ee;e[24]!==n.prompt||e[25]!==K?(ee=(R,ce)=>{const Me=n.prompt,te=j.current?.selectionStart??Me.length,ie=Me.substring(0,te).lastIndexOf("#"),E=ie!==-1?ie:te,I=`${Me.substring(0,E)}#${ce} ${Me.substring(te)}`,ue=E+ce.length+2;K(I),h(!1),v(""),requestAnimationFrame(()=>{const ke=j.current;ke&&(ke.selectionStart=ue,ke.selectionEnd=ue,ke.focus()),W(I,ue)})},e[24]=n.prompt,e[25]=K,e[26]=ee):ee=e[26];const le=ee;let oe;e[27]!==g||e[28]!==d||e[29]!==p?(oe=R=>{if(g&&C.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")){R.preventDefault(),C.current.handleKeyDown(R.key);return}d&&N.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")&&(R.preventDefault(),N.current.handleKeyDown(R.key)),p&&k.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")&&(R.preventDefault(),k.current.handleKeyDown(R.key))},e[27]=g,e[28]=d,e[29]=p,e[30]=oe):oe=e[30];const Ae=oe,Se=r+1;let Y;e[31]!==a||e[32]!==Se?(Y=a("multirun.launcher.groups.groupLabel",{index:Se}),e[31]=a,e[32]=Se,e[33]=Y):Y=e[33];let je;e[34]!==Y?(je=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:Y}),e[34]=Y,e[35]=je):je=e[35];let me;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==a?(me=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":a("multirun.launcher.groups.removeGroup"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=a,e[40]=me):me=e[40];let z;e[41]!==je||e[42]!==me?(z=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[je,me]}),e[41]=je,e[42]=me,e[43]=z):z=e[43];let Z;e[44]!==a?(Z=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=Z):Z=e[45];let ne;e[46]!==Z?(ne=s.jsx(Nr,{required:!0,children:Z}),e[46]=Z,e[47]=ne):ne=e[47];const fe=n.prompt;let xe;e[48]!==K?(xe=R=>{const ce=R.target.value;K(ce);const Me=R.target.selectionStart??ce.length;W(ce,Me)},e[48]=K,e[49]=xe):xe=e[49];let Te;e[50]!==a?(Te=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=Te):Te=e[51];let be;e[52]!==n.prompt||e[53]!==Ae||e[54]!==xe||e[55]!==Te?(be=s.jsx(_r,{ref:j,value:fe,onChange:xe,onKeyDown:Ae,placeholder:Te,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]=Ae,e[54]=xe,e[55]=Te,e[56]=be):be=e[56];let De;e[57]!==w||e[58]!==J||e[59]!==g?(De=g?s.jsx(cu,{ref:C,searchQuery:w,onCommandSelect:J,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=w,e[58]=J,e[59]=g,e[60]=De):De=e[60];let Ee;e[61]!==G||e[62]!==P||e[63]!==m||e[64]!==d?(Ee=d?s.jsx(du,{ref:N,searchQuery:m,onFileSelect:P,onAgentSelect:G,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=G,e[62]=P,e[63]=m,e[64]=d,e[65]=Ee):Ee=e[65];let Re;e[66]!==le||e[67]!==p||e[68]!==y?(Re=p?s.jsx(uu,{ref:k,searchQuery:y,onSnippetSelect:le,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=le,e[67]=p,e[68]=y,e[69]=Re):Re=e[69];let de;e[70]!==be||e[71]!==De||e[72]!==Ee||e[73]!==Re?(de=s.jsxs("div",{className:"relative",children:[be,De,Ee,Re]}),e[70]=be,e[71]=De,e[72]=Ee,e[73]=Re,e[74]=de):de=e[74];let H;e[75]!==ne||e[76]!==de?(H=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ne,de]}),e[75]=ne,e[76]=de,e[77]=H):H=e[77];let Ne;e[78]!==a?(Ne=a("multirun.launcher.models.info",{max:ca}),e[78]=a,e[79]=Ne):Ne=e[79];let he;e[80]!==Ne?(he=s.jsx(ni,{children:Ne}),e[80]=Ne,e[81]=he):he=e[81];let ve;e[82]!==a?(ve=a("multirun.launcher.models.label"),e[82]=a,e[83]=ve):ve=e[83];let se;e[84]!==he||e[85]!==ve?(se=s.jsx(Nr,{required:!0,info:he,children:ve}),e[84]=he,e[85]=ve,e[86]=se):se=e[86];let Q;e[87]!==n.models||e[88]!==M||e[89]!==_||e[90]!==F?(Q=s.jsx(cf,{selectedModels:n.models,onAdd:M,onRemove:_,onUpdate:F,minModels:1,maxModels:ca}),e[87]=n.models,e[88]=M,e[89]=_,e[90]=F,e[91]=Q):Q=e[91];let ye;e[92]!==se||e[93]!==Q?(ye=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[se,Q]}),e[92]=se,e[93]=Q,e[94]=ye):ye=e[94];let re;return e[95]!==z||e[96]!==H||e[97]!==ye?(re=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[z,H,ye]}),e[95]=z,e[96]=H,e[97]=ye,e[98]=re):re=e[98],re},dj=l.createContext(null),uj=t=>{const e=tt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(dj.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},fj=tn(()=>Rs(()=>import("./PlanView-BYgHBHDt.js"),__vite__mapDeps([134,1,2,4,5,6,7,8,123,50,51,52,53,54,55,72,48,49,56,124,125,3,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,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,73,74,75,76,77,78,79,80,112,113,131,114,115,100,101,85,86,87,88,89,90,91,92,93,94,95,96,97,98])).then(t=>({default:t.PlanView}))),yd=tn(()=>Rs(()=>import("./GitView-OSVIn5V1.js"),__vite__mapDeps([132,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,113,133,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,114,115,117,118,119,120])).then(t=>({default:t.GitView}))),mj=tn(()=>Rs(()=>import("./DiffView-1zd0slLu.js"),__vite__mapDeps([121,1,2,4,5,6,7,8,3,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])).then(t=>({default:t.DiffView}))),hj=tn(()=>Rs(()=>import("./FilesView-WkxsWHBE.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,3,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,113,123,124,125,126,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,127,128,114,115,129,130,112,131,118])).then(t=>({default:t.FilesView}))),pj=tn(()=>Rs(()=>import("./DiagramView-cYxZP-HS.js"),__vite__mapDeps([135,1,2,4,5,6,7,8,3,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,129,130])).then(t=>({default:t.DiagramView}))),gj=tn(()=>Rs(()=>import("./SettingsView-e7Fmxnz8.js").then(t=>t.a),__vite__mapDeps([136,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,113,137,123,124,125,114,115,100,101,85,86,87,88,89,90,91,92,93,94,95,96,97,98,138,139])).then(t=>({default:t.SettingsView}))),xj=tn(()=>Rs(()=>import("./SettingsWindow-CNHM8ifT.js"),__vite__mapDeps([140,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,136,113,137,123,124,125,114,115,100,101,85,86,87,88,89,90,91,92,93,94,95,96,97,98,138,139])).then(t=>({default:t.SettingsWindow}))),bj=()=>{const t=pe(b=>b.isSidebarOpen),e=pe(b=>b.activeMainTab),n=pe(b=>b.setIsMobile),r=pe(b=>b.isSessionSwitcherOpen),o=pe(b=>b.isSettingsDialogOpen),i=pe(b=>b.setSettingsDialogOpen),[c,a]=l.useState(!1);l.useEffect(()=>{o&&a(!0)},[o]);const d=pe(b=>b.isMultiRunLauncherOpen),u=pe(b=>b.setMultiRunLauncherOpen),m=pe(b=>b.multiRunLauncherPrefillPrompt),f=pe(b=>b.isScheduledTasksDialogOpen),g=pe(b=>b.isArchivePageOpen),x=pe(b=>b.worktreesPageProjectId),w=f||g||!!x||d;l.useEffect(()=>{const b=()=>pe.getState().closeMainSurfaces(),P=Ge.subscribe((G,X)=>{const J=!!G.currentSessionId&&G.currentSessionId!==X.currentSessionId,ee=!!G.newSessionDraft?.open&&G.newSessionDraft!==X.newSessionDraft;(J||ee)&&b()}),V=pe.subscribe((G,X)=>{G.activeMainTab!==X.activeMainTab&&b()});return()=>{P(),V()}},[]);const{isMobile:S}=fr(),p=l.useRef(!1),[h,y]=l.useState(!1),[v,j]=l.useState(!1),[N,C]=l.useState(!1),[k,D]=l.useState(!1),M=l.useCallback(b=>{y(b),pe.getState().setSessionSwitcherOpen(b)},[]),A=l.useRef(typeof window>"u"?0:window.innerWidth),_=ic(-A.current),L=He.useRef(0),F=ic(A.current),$=He.useRef(0);He.useEffect(()=>{S&&(L.current=window.innerWidth,$.current=window.innerWidth)},[S]),He.useEffect(()=>{if(!S){C(!1);return}h&&C(!0),ac(_,h?0:-L.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,S,_]),He.useEffect(()=>{if(!S){D(!1);return}v&&D(!0),ac(F,v?0:$.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[S,v,F]),He.useEffect(()=>{if(S)return _.on("change",b=>{const P=L.current||A.current,V=h||b>-P+.5;C(G=>G===V?G:V)})},[S,_,h]),He.useEffect(()=>{if(S)return F.on("change",b=>{const P=$.current||A.current,V=v||b<P-.5;D(G=>G===V?G:V)})},[S,v,F]),He.useEffect(()=>{S&&!r&&h&&M(!1)},[r,S,h,M]),He.useEffect(()=>{if(!S){p.current=!1;return}p.current||(p.current=!0,M(!1),j(!1))},[S,M]),He.useEffect(()=>{if(!S||e!=="chat"||h||v||o)return;let b=!1,P;const V=G=>{P=window.setTimeout(()=>{if(b)return;const X=Ge.getState(),J=pe.getState();if(!(J.activeMainTab!=="chat"||J.isSettingsDialogOpen||X.currentSessionId||X.newSessionDraft?.open)){if(X.isLoading){V(250);return}X.openNewSessionDraft({automatic:!0})}},G)};return V(500),()=>{b=!0,P!==void 0&&window.clearTimeout(P)}},[e,S,o,h,v]),He.useEffect(()=>{!S||!o||(M(!1),j(!1))},[S,o,M]),eg(),l.useEffect(()=>{pe.getState().isMobile!==S&&n(S)},[S,n]);const W=l.useCallback(()=>{h&&M(!1),j(!v)},[h,v,M]),U=l.useMemo(()=>{if(!S&&e!=="terminal"&&e!=="diagram")return null;switch(e){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(fj,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(yd,{isActive:!v})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(mj,{})});case"terminal":return s.jsx(wu,{});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(hj,{})});case"context":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(yu,{})});case"diagram":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(pj,{})});default:return null}},[e,S,v]),K=e==="chat";return s.jsx(tg,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:Ce("main-content-safe-area",S?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(gw,{}),s.jsx(nv,{}),s.jsx(av,{}),s.jsx(h0,{}),S?s.jsxs(uj,{value:{leftDrawerOpen:h,rightDrawerOpen:v,toggleLeftDrawer:()=>{const b=!h;v&&j(!1),M(b)},toggleRightDrawer:W,leftDrawerX:_,rightDrawerX:F,leftDrawerWidth:L,rightDrawerWidth:$,setMobileLeftDrawerOpen:M,setRightSidebarOpen:j},children:[!o&&s.jsx(mc,{onToggleLeftDrawer:()=>{const b=!h;v&&j(!1),M(b)},onToggleRightDrawer:()=>{W()},leftDrawerOpen:h,rightDrawerOpen:v}),s.jsx("div",{"data-page-scroll-lock":"true",className:Ce("flex flex-1 overflow-hidden relative",o&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Ce("absolute inset-0",(!K||w)&&"invisible"),children:s.jsx(us,{children:s.jsx(ya,{active:K&&!o&&!w})})}),U&&s.jsx("div",{className:Ce("absolute inset-0",w&&"invisible"),children:s.jsx(us,{children:U})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(us,{children:s.jsx(bd,{initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(us,{children:s.jsx(md,{})}),s.jsx(us,{children:s.jsx(hd,{})}),s.jsx(us,{children:s.jsx(pd,{})}),s.jsx(lc.div,{className:Ce("absolute inset-0 z-20 bg-sidebar",!N&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:_},"aria-hidden":!h,children:s.jsx(us,{children:s.jsx(td,{mobileVariant:!0,isVisible:N})})}),k&&s.jsx(lc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:F},"aria-hidden":!v,children:s.jsx(us,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(yd,{isActive:v})})})})]})}),o&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(us,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(gj,{onClose:()=>i(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ax,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(kx,{isOpen:t,isMobile:S,className:"border-border",topBar:s.jsx(Cx,{}),children:s.jsx(td,{isVisible:t})}),s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx(mc,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:Ce("absolute inset-0",(!K||w)&&"invisible"),children:s.jsx(us,{children:s.jsx(ya,{active:K&&!o&&!w})})}),U&&s.jsx("div",{className:Ce("absolute inset-0",w&&"invisible"),children:s.jsx(us,{children:U})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(us,{children:s.jsx(bd,{isWindowed:!0,initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(us,{children:s.jsx(md,{})}),s.jsx(us,{children:s.jsx(hd,{})}),s.jsx(us,{children:s.jsx(pd,{})})]}),s.jsx(Qy,{})]})})}),s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(us,{children:s.jsx(sw,{})})})]})]})]}),c?s.jsx(l.Suspense,{fallback:null,children:s.jsx(xj,{open:o,onOpenChange:i})}):null]})]})})},gf=12,yj=[{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"}],wj=t=>{const e=tt.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:a}=t,d=r===void 0?0:r,u=i===void 0?900:i,m=c===void 0?yj:c,f=He.useRef(!1);let g,x;e[0]!==n||e[1]!==a?(g=()=>{!n&&f.current&&a?.(),n&&(f.current=!0)},x=[n,a],e[0]=n,e[1]=a,e[2]=g,e[3]=x):(g=e[2],x=e[3]),He.useEffect(g,x);let w;e[4]===Symbol.for("react.memo_cache_sentinel")?(w=Array.from({length:gf},vj),e[4]=w):w=e[4];const S=w;if(!n)return null;let p;e[5]!==o?(p=Ce("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=p):p=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==u){let v;e[11]!==d||e[12]!==u?(v=j=>{const N={"--burst-delay":`${j.delay}ms`,"--burst-x":`${j.x}%`,"--burst-y":`${j.y}%`,"--firework-color":`var(${j.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:S.map((C,k)=>{const D=C.x*j.radius,M=C.y*j.radius,A={"--translate-x":`${D}px`,"--translate-y":`${M}px`,"--particle-delay":`${C.delay}ms`,color:`var(${j.colorVar})`};return s.jsx("span",{className:"firework-particle",style:A},`${j.id}-${k}-${d}`)})},`${j.id}-${d}`)},e[11]=d,e[12]=u,e[13]=v):v=e[13],h=m.map(v),e[7]=d,e[8]=m,e[9]=u,e[10]=h}else h=e[10];let y;return e[14]!==d||e[15]!==p||e[16]!==h?(y=s.jsx("div",{className:p,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=p,e[16]=h,e[17]=y):y=e[17],y};function vj(t,e){const n=Math.PI*2*e/gf;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Sj=t=>{const e=tt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,o=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[c,a]=He.useState(i),d=He.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 f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{m(),a(jj)},e[4]=f):f=e[4];const g=f;let x;e[5]!==o?(x=()=>{m(),a(kj),d.current=window.setTimeout(()=>{a(Cj),d.current=null},o)},e[5]=o,e[6]=x):x=e[6];const w=x;let S,p;e[7]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>m(),p=[m],e[7]=S,e[8]=p):(S=e[7],p=e[8]),He.useEffect(S,p);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==w?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:w,dismissFireworks:g},e[9]=c.cycle,e[10]=c.isActive,e[11]=w,e[12]=h):h=e[12],h};function jj(t){return t.isActive?{...t,isActive:!1}:t}function kj(t){return{isActive:!0,cycle:t.cycle+1}}function Cj(t){return t.isActive?{...t,isActive:!1}:t}const xf=l.createContext(void 0),Nj=t=>{const e=tt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=Sj();let a;e[0]!==c||e[1]!==i?(a={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=a):a=e[2];const d=a;let u;e[3]!==o||e[4]!==r?(u=s.jsx(wj,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let m;return e[6]!==n||e[7]!==u||e[8]!==d?(m=s.jsxs(xf.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=m):m=e[9],m},Hk=()=>{const t=l.useContext(xf);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Aj=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`},Es=t=>{const e=tt.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let a;return e[5]!==i||e[6]!==c?(a=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=a):a=e[7],a},wd=t=>{const e=tt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=gt();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const a=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(Ij,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 f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?Aj(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let g;e[16]!==f?(g=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=g):g=e[17];let x;e[18]!==m||e[19]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,g]}),e[18]=m,e[19]=g,e[20]=x):x=e[20];let w;e[21]!==i?(w=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=w):w=e[22];let S;e[23]!==r.entries.length||e[24]!==w?(S=s.jsx(Es,{label:w,value:r.entries.length}),e[23]=r.entries.length,e[24]=w,e[25]=S):S=e[25];let p;e[26]!==i?(p=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=p):p=e[27];let h;e[28]!==p||e[29]!==u?(h=s.jsx(Es,{label:p,value:u}),e[28]=p,e[29]=u,e[30]=h):h=e[30];let y;e[31]!==i?(y=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=y):y=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let j;e[36]!==y||e[37]!==v?(j=s.jsx(Es,{label:y,value:v}),e[36]=y,e[37]=v,e[38]=j):j=e[38];let N;e[39]!==h||e[40]!==j||e[41]!==S?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[S,h,j]}),e[39]=h,e[40]=j,e[41]=S,e[42]=N):N=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,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:o}):s.jsx(Xn,{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:i("memoryDebugPanel.metric.countValue",{value:C.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:C.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:C.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:C.total})})]})]},C.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=c}else c=e[7];return c},Dj=t=>{const e=tt.c(99),{onClose:n}=t,{t:r}=gt(),[o,i]=l.useState("memory"),[c,a]=l.useState("idle"),d=Ge(Tj),u=iu(Ej),m=Yd(),f=fp(Mj),g=pn(Rj),[x,w]=l.useState(Oj),[S,p]=l.useState(Fj);let h;e[0]!==x.entries?(h=new Map,x.entries.forEach(ve=>{h.set(ve.metric,ve.count)}),e[0]=x.entries,e[1]=h):h=e[1];let y;e[2]!==h?(y=h.get("ui.message_list.render")??0,e[2]=h,e[3]=y):y=e[3];let v;e[4]!==h?(v=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=v):v=e[5];let j;e[6]!==h?(j=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=j):j=e[7];let N;e[8]!==h?(N=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=N):N=e[9];let C;e[10]!==h?(C=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=C):C=e[11];let k;e[12]!==h?(k=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=k):k=e[13];let D;e[14]!==y||e[15]!==v||e[16]!==j||e[17]!==N||e[18]!==C||e[19]!==k?(D={messageListRender:y,messageListRenderStreaming:v,chatMessageRender:j,chatMessageRenderStreaming:N,chatMessageRenderStaticDuringStream:C,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},e[14]=y,e[15]=v,e[16]=j,e[17]=N,e[18]=C,e[19]=k,e[20]=D):D=e[20];const M=D;let A,_;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{const ve=()=>{w(Vo()),p(Ho())};ve();const se=window.setInterval(ve,500);return()=>window.clearInterval(se)},_=[],e[21]=A,e[22]=_):(A=e[21],_=e[22]),l.useEffect(A,_);let L,F;e[23]!==c?(L=()=>{if(c==="idle")return;const ve=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(ve)},F=[c],e[23]=c,e[24]=L,e[25]=F):(L=e[24],F=e[25]),l.useEffect(L,F);let $=0,W=0,U=0;for(const ve of Object.keys(f)){const se=f[ve]??[];W=W+se.length;for(const Q of se)Q.role==="user"?U=U+1:Q.role==="assistant"&&($=$+1)}let K;e[26]!==$||e[27]!==W||e[28]!==U?(K={assistant:$,total:W,user:U},e[26]=$,e[27]=W,e[28]=U,e[29]=K):K=e[29];const b=K;let P;if(e[30]!==d||e[31]!==f||e[32]!==u||e[33]!==m||e[34]!==r){let ve;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==r?(ve=se=>{const Q=f[se.id]??[];let ye=0,re=0;for(const ce of Q)ce.role==="user"?re=re+1:ce.role==="assistant"&&(ye=ye+1);const R=u.get(se.id);return{id:se.id,title:se.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:ye,messageCount:Q.length,userMessageCount:re,isStreaming:R?.isStreaming||!1,isZombie:R?.isZombie||!1,backgroundCount:R?.backgroundMessageCount||0,lastAccessed:R?.lastAccessedAt||0,isCurrent:se.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=ve):ve=e[40],P=m.map(ve).sort(Bj),e[30]=d,e[31]=f,e[32]=u,e[33]=m,e[34]=r,e[35]=P}else P=e[35];const V=P;let G;e[41]!==f?(G=Object.keys(f),e[41]=f,e[42]=G):G=e[42];const X=G.length;let J;e[43]===Symbol.for("react.memo_cache_sentinel")?(J=async()=>{try{const ve={generatedAt:new Date().toISOString(),ui:Vo(),vscode:Ho()};await navigator.clipboard.writeText(JSON.stringify(ve,null,2)),a("copied")}catch{a("error")}},e[43]=J):J=e[43];const ee=J;let le;e[44]===Symbol.for("react.memo_cache_sentinel")?(le={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=le):le=e[44];let oe;e[45]!==o?(oe=o==="memory"?s.jsx(T,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(T,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[45]=o,e[46]=oe):oe=e[46];let Ae;e[47]!==r?(Ae=r("memoryDebugPanel.title"),e[47]=r,e[48]=Ae):Ae=e[48];let Se;e[49]!==Ae?(Se=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:Ae}),e[49]=Ae,e[50]=Se):Se=e[50];let Y;e[51]!==oe||e[52]!==Se?(Y=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,Se]}),e[51]=oe,e[52]=Se,e[53]=Y):Y=e[53];let je;e[54]!==o?(je=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(et,{size:"xs",variant:"ghost",onClick:ee,children:s.jsx(T,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(et,{size:"xs",variant:"ghost",onClick:()=>{cm(),w(Vo()),p(Ho())},children:s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=je):je=e[55];let me;e[56]!==n?(me=n?s.jsx(et,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=me):me=e[57];let z;e[58]!==je||e[59]!==me?(z=s.jsxs("div",{className:"flex items-center gap-1",children:[je,me]}),e[58]=je,e[59]=me,e[60]=z):z=e[60];let Z;e[61]!==Y||e[62]!==z?(Z=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Y,z]}),e[61]=Y,e[62]=z,e[63]=Z):Z=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=ne):ne=e[64];const fe=o==="memory"?"secondary":"ghost";let xe;e[65]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>i("memory"),e[65]=xe):xe=e[65];let Te;e[66]!==r?(Te=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=Te):Te=e[67];let be;e[68]!==fe||e[69]!==Te?(be=s.jsx(et,{size:"sm",variant:fe,className:"flex-1",onClick:xe,children:Te}),e[68]=fe,e[69]=Te,e[70]=be):be=e[70];const De=o==="streaming"?"secondary":"ghost";let Ee;e[71]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>i("streaming"),e[71]=Ee):Ee=e[71];let Re;e[72]!==r?(Re=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Re):Re=e[73];let de;e[74]!==De||e[75]!==Re?(de=s.jsx(et,{size:"sm",variant:De,className:"flex-1",onClick:Ee,children:Re}),e[74]=De,e[75]=Re,e[76]=de):de=e[76];let H;e[77]!==be||e[78]!==de?(H=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ne,children:[be,de]}),e[77]=be,e[78]=de,e[79]=H):H=e[79];let Ne;e[80]!==o||e[81]!==X||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==b||e[86]!==u||e[87]!==V||e[88]!==m||e[89]!==M||e[90]!==x||e[91]!==r||e[92]!==g||e[93]!==S?(Ne=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Es,{label:r("memoryDebugPanel.metric.totalMessages"),value:b.total}),s.jsx(Es,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${X} / ${Kl.MAX_SESSIONS}`}),s.jsx(Es,{label:r("memoryDebugPanel.metric.userMessages"),value:b.user}),s.jsx(Es,{label:r("memoryDebugPanel.metric.assistantMessages"),value:b.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:mp()})})]}),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:Kl.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:g})]})]}),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(Xn,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(ve=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:ve.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:ve.title}),ve.isStreaming?s.jsx(T,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,ve.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:ve.assistantMessageCount,user:ve.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:ve.messageCount})}),ve.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",ve.backgroundCount]}):null]})]},ve.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(ut,{children:[s.jsx(ft,{asChild:!0,children:s.jsx(et,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(Lj),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:b,sessionMessageRoleCounts:V.map(_j),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(mt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(et,{size:"xs",variant:"outline",onClick:ee,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Es,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(Es,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:S.entries.length}),s.jsx(Es,{label:r("memoryDebugPanel.metric.messageListRenders"),value:M.messageListRender}),s.jsx(Es,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:M.messageListRenderStreaming}),s.jsx(Es,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:M.chatMessageRender}),s.jsx(Es,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:M.chatMessageRenderStreaming}),s.jsx(Es,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:M.chatMessageRenderStaticDuringStream}),s.jsx(Es,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:M.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(wd,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),S.entries.length>0?s.jsx(wd,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:S,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=X,e[82]=c,e[83]=d,e[84]=f,e[85]=b,e[86]=u,e[87]=V,e[88]=m,e[89]=M,e[90]=x,e[91]=r,e[92]=g,e[93]=S,e[94]=Ne):Ne=e[94];let he;return e[95]!==Z||e[96]!==H||e[97]!==Ne?(he=s.jsxs(hp,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:le,children:[Z,H,Ne]}),e[95]=Z,e[96]=H,e[97]=Ne,e[98]=he):he=e[98],he},Pj=Dj;function Ij(t,e){return t+e.count}function Tj(t){return t.currentSessionId}function Ej(t){return t.sessionMemoryState}function Mj(t){return t.message}function Rj(t){return t.totalRequestCount}function Oj(){return Vo()}function Fj(){return Ho()}function Bj(t,e){return e.lastAccessed-t.lastAccessed}function Lj(t){return{id:t.id,title:t.title}}function _j(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const $j=()=>{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()??"":""},zj=async()=>{const t=$j()||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")},vd="openchamber:menu-action",da="openchamber:check-for-updates",Wj=t=>{const e=Ge(y=>y.openNewSessionDraft),n=pe(y=>y.toggleCommandPalette),r=pe(y=>y.setCommandPaletteOpen),o=pe(y=>y.toggleHelpDialog),i=pe(y=>y.toggleSidebar),c=pe(y=>y.setSessionSwitcherOpen),a=pe(y=>y.setActiveMainTab),d=pe(y=>y.setSettingsDialogOpen),u=pe(y=>y.setAboutDialogOpen),m=uo(y=>y.checkForUpdates),{setThemeMode:f}=Ir(),g=l.useRef(!1),x=l.useCallback(()=>{g.current||(g.current=!0,m().then(()=>{const{available:y,error:v}=uo.getState();if(v){Ie.error("Failed to check for updates",{description:v});return}y||Ie.success("You are on the latest version")}).finally(()=>{g.current=!1}))},[m]),w=l.useCallback(()=>{Ln.requestDirectoryDialog()},[]),S=l.useCallback(y=>{const v=pp();if(v.length===0)return;const j=Ge.getState().currentSessionId,N=v.findIndex(D=>D.id===j);let C=y>0?0:v.length-1;N>=0&&(C=(N+y+v.length)%v.length);const k=v[C];k&&(a("chat"),c(!1),Ge.getState().setCurrentSession(k.id))},[a,c]),p=l.useCallback(y=>{const{activeProjectId:v,projects:j,setActiveProject:N}=Yt.getState();if(j.length===0)return;const C=j.findIndex(M=>M.id===v);let k=y>0?0:j.length-1;C>=0&&(k=(C+y+j.length)%j.length);const D=j[k];D&&N(D.id)},[]),h=l.useCallback(y=>{switch(y){case"about":u(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":a("chat"),c(!1),e();break;case"new-worktree-session":a("chat"),c(!1),Zd();break;case"change-workspace":w();break;case"toggle-right-sidebar":{const v=cs.getState().currentDirectory;if(!v)break;const j=pe.getState(),N=Br(v),C=j.contextPanelByDirectory[N];C?.isOpen?j.closeContextPanel(N):C?.activeTabId?j.setActiveContextPanelTab(N,C.activeTabId):j.openContextSurface(N,"git");break}case"open-right-sidebar-git":{const v=cs.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Br(v),"git");break}case"open-right-sidebar-files":{const v=cs.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Br(v),"file");break}case"toggle-terminal":{const v=cs.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Br(v),"terminal");break}case"toggle-terminal-expanded":{const v=cs.getState().currentDirectory;if(!v)break;const j=Br(v),N=pe.getState(),C=N.contextPanelByDirectory[j];(C?.isOpen?C.tabs.find(D=>D.id===C.activeTabId)?.mode:null)!=="terminal"&&N.openContextSurface(j,"terminal"),N.toggleContextPanelExpanded(j);break}case"copy":{const v=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(v)||zj();break}case"theme-light":f("light");break;case"theme-dark":f("dark");break;case"theme-system":f("system");break;case"add-selection-to-chat":xp();break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":cs.getState().goBack();break;case"go-forward":cs.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":p(-1);break;case"next-project":p(1);break;case"help-dialog":o();break;case"download-logs":{gp().catch(()=>{Ie.error("Failed to collect OpenCode status")});break}}},[w,p,S,t,e,u,a,c,r,d,f,n,o,i]);l.useEffect(()=>{const y=j=>{const N=j.detail;N&&h(N)},v=()=>{x()};return window.addEventListener(vd,y),window.addEventListener(da,v),()=>{window.removeEventListener(vd,y),window.removeEventListener(da,v)}},[h,x]),l.useEffect(()=>{if(typeof window>"u")return;const v=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof v!="function")return;let j=null,N=null;return v("openchamber:menu-action",C=>{const k=C?.payload;typeof k=="string"&&h(k)}).then(C=>{j=C}).catch(()=>{}),v("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(da))}).then(C=>{N=C}).catch(()=>{}),()=>{(async()=>{try{const k=j?.();k instanceof Promise&&await k}catch{}try{const k=N?.();k instanceof Promise&&await k}catch{}})()}},[h])},Uj="openchamber:tray-action",Sd=5e3,Vj=500,Hj=45e3,bf=20,jd=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},kd=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,Kj=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},Gj=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},yf=(t,e)=>qr(t,e,xo.getState().ids,Ai.getState().rankById),qj=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},Yj=(t,e,n,r,o)=>{if(!t)return"";const i=Sp(n,r,t),c=e.project?.name,a=i?.label?.trim()||c?.trim()||qj(t),d=qo(t);let u=d&&o.get(d)||"";if(!u){for(const[m,f]of dr.getState().directories)if(qo(m)===d){u=f.status?.current??"";break}}if(!u)for(const m of r.values()){const f=m.find(g=>qo(g.path)===d);if(f?.branch){u=f.branch;break}}return u?`${a} · ${u}`:a},Qj=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=ys.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const o=new Map(t.map(c=>[c.providerId,c])),i=[];for(const c of zd){if(!e.includes(c.id))continue;const a=o.get(c.id);if(!a||a.configured!==!0)continue;const d=[];for(const[m,f]of Object.entries(a.usage?.windows??{})){const g=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:Hd(m),value:pa(f.valueLabel,g)})}const u=!a.ok&&a.error?a.error:d.length===0?"No rate limits reported":null;i.push({provider:c.name,rows:d,status:u})}return{mode:r,groups:i}},Xj=async()=>{try{if(bi())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=cr();if(e&&Al(e,t))return"Local OpenChamber";const r=(await Td()).hosts.find(o=>e?Al(e,dm(o)):!1);return r?.label?.trim()?Ed(r.label.trim()):"Instance"}catch{return""}},Jj=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=li()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[i,c]of o.children.entries()){const a=c.getState();a.vcs?.branch&&e.set(qo(i)??i,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,f=m==="busy"?"busy":m==="retry"?"retry":"idle",g=t.get(d);(!g||g==="idle")&&t.set(d,f)}for(const[d,u]of Object.entries(a.permission??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"permission",id:m.id,sessionId:f,sessionTitle:"",label:Kj(m),directory:i})}for(const[d,u]of Object.entries(a.question??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"question",id:m.id,sessionId:f,sessionTitle:"",label:Gj(m),directory:i})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},Zj=()=>{const t=Ms.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(yf).slice(0,bf).forEach(r=>{const o=Gs(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Gs(r);if(!o||!e.has(o))continue;const i=n.get(o)??[];i.push(r.id),n.set(o,i)}return n},ek=t=>{const e=Jj(),n=Pi.getState().index.session,r=Ms.getState().activeSessions,o=new Map(e.titleById),i=new Map;for(const p of r)if(p?.id&&(p.title&&o.set(p.id,p.title),p.parentID)){const h=i.get(p.parentID)??[];h.push(p.id),i.set(p.parentID,h)}const c=p=>{const h=[],y=[...i.get(p)??[]],v=new Set;for(;y.length;){const j=y.pop();v.has(j)||(v.add(j),h.push(j),y.push(...i.get(j)??[]))}return h},a=Di.getState().statusById,d=p=>{const h=e.statusById.get(p);return h&&h!=="idle"?h:a.get(p)?.status.type??h??"idle"},u=p=>{const h=p.map(y=>d(y));return h.includes("busy")?"busy":h.includes("retry")?"retry":"idle"},m=Yt.getState().projects,f=Ge.getState().availableWorktreesByProject,g=r.filter(p=>p?.id&&!p.parentID).slice().sort(yf).slice(0,bf).map(p=>{const h=[p.id,...c(p.id)],y=Gs(p)??"";return{id:p.id,title:p.title||"Untitled session",status:u(h),branch:y?e.branchByDirectory.get(y)??"":"",unseen:h.reduce((v,j)=>v+(n.unseenCount[j]??0),0),hasError:h.some(v=>n.unseenHasError[v]??!1),directory:y,subtitle:Yj(y,p,m,f,e.branchByDirectory)}}),x=e.approvals.map(p=>({...p,sessionTitle:o.get(p.sessionId)||""})),w=pe.getState();let S=0;if(w.dockBadgeEnabled)for(const p of r){if(!p?.id||p.parentID)continue;let h=n.unseenCount[p.id]??0;h===0&&w.notifyOnSubtasks&&(h=c(p.id).reduce((y,v)=>y+(n.unseenCount[v]??0),0)),h>0&&(S+=1)}return{sessions:g,approvals:x,instanceName:t,usage:Qj(),dockBadgeCount:S}},tk=()=>{l.useEffect(()=>{if(!jd()||!kd()||!wi())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const D=ek(r),M=JSON.stringify(D);M!==e&&(e=M,Jn("desktop_tray_update",D))};Xj().then(D=>{t||(r=D,o())});const i=async()=>{const D=Zj();await Promise.all([...D.entries()].map(async([M,A])=>{const _=await en.getSessionStatusForDirectory(M).catch(()=>null);t||_===null||wp(M,_,A)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},Vj))},a=new Map,d=()=>{if(t)return;let D;try{D=li()}catch{return}const M=new Set;for(const[A,_]of D.children.entries())M.add(A),a.has(A)||a.set(A,_.subscribe(()=>c()));for(const[A,_]of a)M.has(A)||(_(),a.delete(A))};let u=null;try{u=li().subscribeRegistry(()=>{d(),c()})}catch{}d();const m=Pi.subscribe(()=>c()),f=Ms.subscribe(()=>c()),g=Yt.subscribe(()=>c()),x=Ge.subscribe(()=>c()),w=dr.subscribe(()=>c()),S=pe.subscribe(()=>c()),p=Di.subscribe(()=>c()),h=Ai.subscribe(()=>c()),y=xo.subscribe(()=>c());bp(yp());const v=window.setInterval(()=>{ai()},Hj);i();const j=window.setInterval(()=>{i()},Sd),N=ys.subscribe(()=>c());ys.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:D,results:M}=ys.getState();D.length>0&&D.some(_=>!M.some(L=>L.providerId===_))&&ys.getState().fetchAllQuotas()});const C=window.setInterval(()=>{const D=ys.getState();D.autoRefresh&&D.dropdownProviderIds.length>0&&D.fetchAllQuotas()},Math.max(3e4,ys.getState().refreshIntervalMs||6e4)),k=window.setInterval(()=>{d(),o()},Sd);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(k),window.clearInterval(v),window.clearInterval(j),window.clearInterval(C),m(),f(),g(),x(),w(),S(),p(),h(),y(),N(),u?.();for(const D of a.values())D();a.clear()}},[]),l.useEffect(()=>{if(!jd()||!kd()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&vp(o.sessionId,o.id,o.response).catch(()=>{Ie.error("Failed to respond to permission request")})};let r=null;return e(Uj,o=>{const i=o?.payload;!i||typeof i!="object"||typeof i.type!="string"||n(i)}).then(o=>{r=o}).catch(()=>{}),()=>{try{const o=r?.();o instanceof Promise&&o.catch(()=>{})}catch{}}},[])},sk="/api/notifications/stream",nk=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),rk=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}},ok=t=>{const e=tt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||_n()||!Ba()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(vi().sse(sk));return i.onmessage=ik,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),l.useEffect(r,o)};function ik(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=pe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&nk())return;const r=rk(e);if(!r)return;yi()?.notifications?.notifyAgentCompletion(r)}const Cd="pwa-install-toast-shown",Nd="pwa-install-toast-dismissed",ak=()=>{const t=tt.c(6),{browserTab:e}=sg(),{t:n}=gt(),r=l.useRef(n);let o,i;t[0]!==n?(o=()=>{r.current=n},i=[n],t[0]=n,t[1]=o,t[2]=i):(o=t[1],i=t[2]),l.useEffect(o,i);let c,a;t[3]!==e?(c=()=>{if(typeof window>"u"||!Ba()||!e)return;let d=null,u=null;const m=()=>{u!==null&&(Ie.dismiss(u),u=null)},f=async()=>{if(!d)return;const w=d;d=null,m(),await w.prompt();const{outcome:S}=await w.userChoice;S==="accepted"&&Ie.success(r.current("pwa.installPrompt.started"))},g=w=>{const S=w;if(typeof S.prompt!="function")return;S.preventDefault(),d=S;const p=Lr(),h=um();ng({dismissed:p.getItem(Nd),sessionShown:h.getItem(Cd),hasActiveToast:u!==null})&&(h.setItem(Cd,"true"),u=Ie.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Lr().setItem(Nd,"true"),m()}}}))},x=()=>{d=null,m(),Ie.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",x)}},a=[e],t[3]=e,t[4]=c,t[5]=a):(c=t[4],a=t[5]),l.useEffect(c,a)},lk=({open:t,onOpenChange:e})=>{const{t:n}=gt(),r=!1,[o,i]=l.useState(null),[c,a]=l.useState(null),[d,u]=l.useState(!1),[m,f]=l.useState(!1),[g,x]=l.useState(null),[w,S]=l.useState(!1);l.useCallback(async()=>{},[g,d,r,n]),l.useEffect(()=>{if(!t)return;(async()=>{try{const y=await hs("/api/system/info");if(y.ok){const v=await y.json();if(typeof v.openchamberVersion=="string"&&v.openchamberVersion.trim()){i(v.openchamberVersion);return}}}catch{}i(await jp())})()},[t]),l.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const v=await hs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const j=await v.json().catch(()=>null),N=typeof j?.currentVersion=="string"?j.currentVersion.trim():"";!h&&N&&a(N)}catch{}})(),()=>{h=!0}},[t]),l.useEffect(()=>{{x(null),S(!1);return}},[t,r]);const p=o;return s.jsx(qs,{open:t,onOpenChange:e,children:s.jsx(Ys,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Ha,{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:[p&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:p})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(T,{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(T,{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(T,{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")})]})})})},Ad=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},ua=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},ck=(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},dk=()=>{const t=kp(a=>a.completeAuth),[e,n]=l.useState("working"),[r,o]=l.useState(!1),[i,c]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),c("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),d=ua(a,"code"),u=Cp(a),m=Np(a),f=ua(a,"error"),g=ua(a,"error_description");if(f){m&&hs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(g??f);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 x=u,w=!1;if(m){const S=await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`);if(S.ok){const p=await S.json().catch(()=>null);w=p?.origin===Ap,o(w),!x&&p?.name?.trim()&&(x={name:p.name.trim(),directory:typeof p.directory=="string"&&p.directory.trim()?p.directory.trim():null})}}if(!x?.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(x.name,d,x.directory),m&&await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("success"),w&&Ad(!0),c("Authorization completed. You can close this tab and return to OpenChamber.")}catch(x){m&&await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(ck(x,"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:Dp,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:Ce("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:i})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(et,{type:"button",onClick:()=>Ad(r),children:"Return to OpenChamber"})})]})})},Dd=tn(()=>Rs(()=>import("./OnboardingScreen-BCgYA7J5.js"),__vite__mapDeps([141,1,2,4,5,6,7,8,3,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])).then(t=>({default:t.OnboardingScreen}))),uk=()=>{const t=tt.c(3),e=pe(xk),n=pe(bk);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(lk,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},fk=t=>{const e=tt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=gt();let i;e[0]!==o?(i=o("startup.initRecovery.title"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==o?(a=o("startup.initRecovery.description"),e[4]=o,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]!==c||e[9]!==d?(u=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,d]}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let m;e[11]!==r||e[12]!==o?(m=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=m):m=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==m?(f=s.jsx(et,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=f):f=e[17];let g;return e[18]!==u||e[19]!==f?(g=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[u,f]})}),e[18]=u,e[19]=f,e[20]=g):g=e[20],g},Pd=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",mk=()=>{if(typeof window>"u"||!bg())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},hk=()=>typeof window>"u"?!1:window.location.pathname===Mp,pk=t=>{const e=tt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=cs(yk),c=Ge(wk),a=Ge(vk),d=Si(),u=l.useRef(null);let m;e[0]!==n.directory?(m=Pd(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const f=m;let g;e[2]!==i?(g=Pd(i),e[2]=i,e[3]=g):g=e[3];const x=g;let w,S;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==d?(w=()=>{if(r||f&&x!==f)return;const N=`${f}
|
|
193
|
-
${n.sessionId}`;u.current===N&&c||(u.current=N,a(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},S=[x,c,n.directory,n.sessionId,f,r,a,d],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=a,e[11]=d,e[12]=w,e[13]=S):(w=e[12],S=e[13]),l.useEffect(w,S),f&&x!==f)return null;let p;e[14]!==o?(p=s.jsx(fu,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=p):p=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(vu,{}),e[16]=h):h=e[16];let y;e[17]!==n.readOnly?(y=s.jsx(ya,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=y):y=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(mu,{}),e[19]=v):v=e[19];let j;return e[20]!==p||e[21]!==y?(j=s.jsxs(s.Fragment,{children:[p,h,y,v]}),e[20]=p,e[21]=y,e[22]=j):j=e[22],j};function gk({apis:t}){l.useEffect(()=>{fm("App:mounted"),mm()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Vt(z=>z.initializeApp),n=Vt(z=>z.isInitialized),r=Vt(z=>z.isConnected),o=Vt(z=>z.providers.length),i=Vt(z=>z.agents.length),c=Vt(z=>z.loadProviders),a=Vt(z=>z.loadAgents),d=Ge(z=>z.error),u=Ge(z=>z.clearError),m=cs(z=>z.currentDirectory),f=cs(z=>z.setDirectory),g=cs(z=>z.isSwitchingDirectory),[x,w]=l.useState(!1),S=Pr(z=>z.refreshStatus),[p,h]=l.useState(()=>t.runtime.isVSCode),[y,v]=l.useState(!0),[j,N]=l.useState(!1),[C,k]=l.useState(0),[D,M]=l.useState(0),[A,_]=l.useState(!1),L=pe(z=>z.wideChatLayoutEnabled),F=pe(z=>z.mobileKeyboardMode),$=l.useMemo(()=>_n(),[]),W=_a(z=>z.setPlanModeEnabled),[U,K]=l.useState(()=>Dl()),[b,P]=l.useState(()=>{const z=Pl();return z!==null?Il({isDesktopShell:!0,bootOutcome:z}):null}),V=l.useRef(!1),G=l.useMemo(()=>mk(),[]),X=!G||y,J=l.useMemo(()=>hk(),[]);l.useEffect(()=>(Tl(x),()=>{Tl(!1)}),[x]),l.useEffect(()=>{hm(F)},[F]),l.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>Fa(z=>{rg(z),M(Z=>Z+1),N(!1),k(Z=>Z+1)}),[]);const ee=Gl(z=>{const Z=Tn();return Object.values(z.runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===Z).map(ne=>`${ne.originalSessionID}:${ne.phase}:${ne.lastForwardedMessageID??""}:${ne.expectedAssistantParentID??""}`).sort().join("|")});l.useEffect(()=>{if(G)return;const z=Tn(),Z=Object.values(Gl.getState().runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===z);for(const ne of Z)Pp(ne.originalSessionID)},[ee,G,D]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",L),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[L]),l.useEffect(()=>(El(t),()=>El(null)),[t]),l.useEffect(()=>{G||S(t.github,{force:!0})},[t.github,G,S]),Ip();const le=U==="valid",oe=b?.screen==="main";l.useEffect(()=>{if(!pm({isDesktopShell:$,isInitialized:n,bootOutcomeKnown:le,bootViewIsMain:oe}))return;const z=setTimeout(()=>{const Z=document.getElementById("initial-loading");Z&&(Z.classList.add("fade-out"),setTimeout(()=>{Z.remove()},300))},150);return()=>clearTimeout(z)},[$,n,le,oe]),l.useEffect(()=>{if(!$||U!=="malformed")return;const z=document.getElementById("initial-loading");z&&(z.textContent="Desktop startup failed — please restart the app.")},[$,U]),l.useEffect(()=>{if($)return;const z=setTimeout(()=>{const Z=document.getElementById("initial-loading");Z&&!n&&(Z.classList.add("fade-out"),setTimeout(()=>{Z.remove()},300))},5e3);return()=>clearTimeout(z)},[$,n]),l.useEffect(()=>{let z=!1;return(async()=>{const ne=await hs("/health",{method:"GET"}).catch(()=>null);if(!ne||!ne.ok||z)return;const fe=await ne.json().catch(()=>null);if(!fe||z)return;const xe=fe.planModeExperimentalEnabled;W(xe===!0||xe===1||xe==="1"||xe==="true")})(),()=>{z=!0}},[W]),l.useEffect(()=>{p||e()},[e,p]),l.useEffect(()=>{if(p||n)return;let z=!0,Z,ne=0;const fe=10,xe=1e3,Te=async()=>{if(!z)return;if(ne>=fe){N(!0);return}const be=Vt.getState();if(be.isInitialized){N(!1);return}ne+=1,await be.initializeApp();const De=Vt.getState();if(!z)return;if(De.isInitialized){N(!1);return}if(ne>=fe){N(!0);return}const Ee=Math.min(xe*Math.pow(2,ne-1),16e3);Z=setTimeout(Te,Ee)};return Z=setTimeout(Te,xe),()=>{z=!1,Z&&clearTimeout(Z)}},[C,n,p]),l.useEffect(()=>{n&&N(!1)},[n]),l.useEffect(()=>{if(!j)return;const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},[j]),l.useEffect(()=>{if(p||!r||o>0&&i>0)return;let z=!0,Z=0;const ne=15,fe=async()=>{const Te=Vt.getState();if(!(Te.providers.length>0&&Te.agents.length>0))try{Te.providers.length===0&&await c({source:"startupRecovery"}),Vt.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};fe();const xe=setInterval(()=>{if(z){if(++Z>=ne){clearInterval(xe);return}fe()}},2e3);return()=>{z=!1,clearInterval(xe)}},[r,p,a,c,o,i]),l.useEffect(()=>{g||p||r&&en.setDirectory(m)},[m,g,r,p]),l.useEffect(()=>{if(!G||typeof window>"u")return;const z=fe=>{const xe=fe?.visible===!0;v(xe)},Z=fe=>{if(fe.origin!==window.location.origin)return;const xe=fe.data;xe?.type==="openchamber:embedded-visibility"&&z(xe.payload)},ne=window;return ne.__openchamberSetEmbeddedVisibility=z,window.addEventListener("message",Z),()=>{window.removeEventListener("message",Z),ne.__openchamberSetEmbeddedVisibility===z&&delete ne.__openchamberSetEmbeddedVisibility}},[G]),l.useEffect(()=>{!G?.directory||p||m!==G.directory&&f(G.directory,{showOverlay:!1})},[m,G,p,f]),l.useEffect(()=>{if(!G||typeof window>"u")return;const z=Z=>{Z.storageArea===window.localStorage&&Z.key==="ui-store"&&pe.persist.rehydrate()};return window.addEventListener("storage",z),()=>{window.removeEventListener("storage",z)}},[G]),l.useEffect(()=>{if(typeof window>"u")return;const z=Z=>{const ne=Z.detail,fe=typeof ne?.sessionId=="string"?ne.sessionId.trim():"";if(!fe)return;const xe=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null;pe.getState().setActiveMainTab("chat"),Ge.getState().setCurrentSession(fe,xe)};return window.addEventListener("openchamber:open-session",z),()=>window.removeEventListener("openchamber:open-session",z)},[]),l.useEffect(()=>{if(typeof window>"u")return;const z=()=>{const Z=cs.getState().currentDirectory,{activeProjectId:ne,projects:fe}=Yt.getState(),xe=fe.find(Te=>Te.id===ne)??null;Jn("desktop_open_draft_mini_chat_window",{directory:Z||xe?.path||"",projectId:xe?.id??null})};return window.addEventListener("openchamber:open-mini-chat",z),()=>window.removeEventListener("openchamber:open-mini-chat",z)},[]),l.useEffect(()=>{if(typeof window>"u")return;const z=()=>{const Z=Ge.getState().currentSessionId;Z&&Qd(Z)};return window.addEventListener("focus",z),()=>window.removeEventListener("focus",z)},[]),l.useEffect(()=>{if(typeof window>"u")return;const z=Z=>{const ne=Z.detail,fe=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null,xe=typeof ne?.projectId=="string"&&ne.projectId.trim().length>0?ne.projectId.trim():null;pe.getState().setActiveMainTab("chat"),pe.getState().setSessionSwitcherOpen(!1),Ge.getState().openNewSessionDraft({selectedProjectId:xe,directoryOverride:fe,preserveDirectoryOverride:!!fe})};return window.addEventListener("openchamber:open-draft-session",z),()=>window.removeEventListener("openchamber:open-draft-session",z)},[]),l.useEffect(()=>{typeof window>"u"||!n||g||V.current||(V.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,g]),Tp({enabled:X}),ok({enabled:X}),ak(),Ep(),og();const Ae=l.useCallback(()=>{w(z=>!z)},[]);Wj(Ae),tk(),l.useEffect(()=>{if(G)return;const z=Z=>{Vd(Z)&&Z.shiftKey&&!Z.altKey&&(Z.code==="KeyD"||Z.key.toLowerCase()==="d")&&(Z.preventDefault(),w(fe=>!fe))};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)},[G]),l.useEffect(()=>{G||d&&setTimeout(()=>u(),5e3)},[u,G,d]),l.useEffect(()=>{if(!$||U!=="not-injected")return;let z=!1,Z=0;const ne=200,fe=2e3,xe=50,Te=()=>{if(z)return;Z++;const be=Dl();if(be!=="not-injected"){if(z=!0,K(be),be==="valid"){const Ee=Pl();Ee&&P(Il({isDesktopShell:!0,bootOutcome:Ee}))}return}const De=Math.min(ne*Math.pow(1.1,Z),fe);if(Z>=xe){const Ee=document.getElementById("initial-loading");Ee&&!Ee.textContent?.includes("taking longer")&&(Ee.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Te,De)};return window.setTimeout(Te,ne),()=>{z=!0}},[$,U]);const Se=l.useCallback(async()=>{if(gm({isDesktopShell:_n(),isDesktopLocalOriginActive:bi()})){await xm();return}window.location.reload()},[]),Y=l.useCallback(async()=>{if(!A){N(!1),_(!0);try{await Vt.getState().initializeApp()}finally{_(!1)}Vt.getState().isInitialized||k(z=>z+1)}},[A]),je=z=>{if(z.screen==="recovery")return z.variant};if($&&b&&b.screen!=="main"){if(b.screen==="chooser")return s.jsx(us,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Dd,{mode:"first-launch",localAvailable:b.localAvailable!==!1,onCliAvailable:Se,onChooseRemote:()=>{}})})})});const z=je(b),Z=b.screen==="recovery"&&"url"in b?b.url:void 0;return s.jsx(us,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Dd,{mode:"recovery",recoveryVariant:z,recoveryHostUrl:Z,recoveryHostLabel:void 0,localAvailable:b.localAvailable!==!1,onCliAvailable:Se})})})})}if(G)return s.jsx(us,{children:s.jsx(ql,{sdk:en.getSdkClient(),directory:m||"",children:s.jsx(Yl,{apis:t,children:s.jsx(ba,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(pk,{embeddedSessionChat:G,isVSCodeRuntime:p,embeddedBackgroundWorkEnabled:X})})})})},D)});if(J)return s.jsx(us,{children:s.jsx(dk,{})});if(j&&!n&&!p&&!G)return s.jsx(us,{children:s.jsx(fk,{onRetry:()=>{Y()},isRetrying:A})});const me=!n&&!$;return s.jsx(us,{children:s.jsx(ql,{sdk:en.getSdkClient(),directory:m||"",children:s.jsx(Yl,{apis:t,children:s.jsx(Nj,{children:s.jsx(ba,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:$?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(fu,{embeddedBackgroundWorkEnabled:X}),s.jsx(vu,{}),s.jsx(bj,{}),s.jsx(mu,{}),!me&&s.jsxs(s.Fragment,{children:[s.jsx(ig,{}),s.jsx(uk,{}),x&&s.jsx(Pj,{onClose:()=>w(!1)})]})]})})})})},D)})}function xk(t){return t.isAboutDialogOpen}function bk(t){return t.setAboutDialogOpen}function yk(t){return t.currentDirectory}function wk(t){return t.currentSessionId}function vk(t){return t.setCurrentSession}const Sk=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Rp();bm().then(()=>{Promise.all([ym(),Op()]).catch(t=>{console.error("[main] settings init failed:",t)}),Fp(),Bp(),Lp()}).catch(t=>{console.error("[main] appearance init failed:",t)});const wf=document.getElementById("root");if(!wf)throw new Error("Root element not found");Qf.createRoot(wf).render(s.jsx(He.StrictMode,{children:s.jsx(_p,{children:s.jsx($p,{children:s.jsx(zp,{children:s.jsx(Wp,{children:s.jsx(gk,{apis:Sk})})})})})}));const Kk=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Wx as W,Hk as a,zx as b,sb as d,Wu as g,Vk as h,Kk as m,Ex as u,zu as v};
|