@pi-chamber/web 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CommitSection-BQBmpPVE.js → CommitSection-DPjTv8fA.js} +1 -1
- package/dist/assets/{DiagramEditor-Cp22TGpq.js → DiagramEditor-ChOor9l9.js} +1 -1
- package/dist/assets/{DiagramView-E4HJ4ZPU.js → DiagramView-3hAT86v_.js} +1 -1
- package/dist/assets/{DiffView-d23o9CKP.js → DiffView-D1dyOiw2.js} +2 -2
- package/dist/assets/FilesView-BCzghrc7.js +14 -0
- package/dist/assets/{GitView-CkUONO1-.js → GitView-CYF1E1p4.js} +4 -4
- package/dist/assets/{JsonTreeView-By2oGMNK.js → JsonTreeView-CrJO6LNu.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DUghE55t.js → MarkdownRendererImpl-BmKjrkGD.js} +2 -2
- package/dist/assets/{PatchDiff-BjN6zMtK.js → PatchDiff-DgvPLx6x.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B38_7NnU.js → PierreDiffViewer-InnT0JVA.js} +2 -2
- package/dist/assets/{SessionSwitcherDropdown-NbVfnqQQ.js → SessionSwitcherDropdown-C0OdvirK.js} +102 -102
- package/dist/assets/{SettingsView-C2dCv0r7.js → SettingsView-JAfC_cBL.js} +1 -1
- package/dist/assets/{SettingsWindow-DsMhdX5H.js → SettingsWindow-BBEsjcJE.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DVesARmI.js → ToolOutputDialog-gzwcb8nI.js} +4 -4
- package/dist/assets/{ToolPartDiffPreview-C2N_oIO-.js → ToolPartDiffPreview-C45V5bhy.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-B7eVR6Pt.js → VirtualizedFileDiff-uKfnkQWb.js} +1 -1
- package/dist/assets/{collapsible-CPkWB1VR.js → collapsible-Bq8sDiKS.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BsZulefS.js → computeVirtualFileMetrics-BPgZ_RSe.js} +2 -2
- package/dist/assets/{contextFileOpenGuard-BmmlK5E3.js → contextFileOpenGuard-CydO7PkI.js} +1 -1
- package/dist/assets/{index-C84KrQoy.js → index-BSuNNtBh.js} +1 -1
- package/dist/assets/{index-BhXma4dv.js → index-CH7o4-_q.js} +1 -1
- package/dist/assets/index-o4Eea60G.css +1 -0
- package/dist/assets/{isDiffPlainText-DsuyxFXo.js → isDiffPlainText-f9b4cKNo.js} +1 -1
- package/dist/assets/{isFilePlainText-CCYoe7us.js → isFilePlainText-BjESb-gU.js} +1 -1
- package/dist/assets/{main-ClYgYVm1.js → main-B508FBXr.js} +2 -2
- package/dist/assets/main-nG4uFyAy.js +133 -0
- package/dist/assets/{markdownCore-D2uqals1.js → markdownCore-BFmf8a-O.js} +2 -2
- package/dist/assets/{miniChat-DmX9SjxM.js → miniChat-BTlz8IPL.js} +2 -2
- package/dist/assets/{mobile-C-PCxN62.js → mobile-DBkrRt80.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-DW3fSR5w.js +1 -0
- package/dist/assets/renderMobileApp-9qkroKty.js +14 -0
- package/dist/assets/{runtimeSurface-CouGjZ3A.js → runtimeSurface-Bec4O8FD.js} +1 -1
- package/dist/assets/{useInlineCommentController-buNJ3xB4.js → useInlineCommentController-CHmIm0Rr.js} +2 -2
- package/dist/assets/usePanelSlide-DCX8qQ4K.js +56 -0
- package/dist/assets/{useWindowTitle-CnF4pKz0.js → useWindowTitle-CE5N_NeU.js} +3 -3
- package/dist/assets/{vendor-codemirror-autocomplete-3xMyV7a2.js → vendor-codemirror-autocomplete-BS2SpSAZ.js} +1 -1
- package/dist/assets/{vendor-codemirror-commands-Bzf12ODH.js → vendor-codemirror-commands-RrgJ8H_6.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-0K6s6cvb.js → vendor-codemirror-lang-angular-ADhO_TUK.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B0aL03z-.js → vendor-codemirror-lang-cpp-BGCWj7Om.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-C4jEScp7.js → vendor-codemirror-lang-css-Ba8JZ6fp.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-CgrfVBPr.js → vendor-codemirror-lang-go-DyTiHXo4.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-C1Svvdey.js → vendor-codemirror-lang-html-DK27qQri.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-DNPz7_Bx.js → vendor-codemirror-lang-java-CvFfnhPQ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-CrbeaEAU.js → vendor-codemirror-lang-javascript-BUlYhQ3o.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-DL8BR_RG.js → vendor-codemirror-lang-jinja-wBMtAEvT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-BTvAjwkJ.js → vendor-codemirror-lang-json-CqayksDf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-CPABt6NZ.js → vendor-codemirror-lang-less-Ct3-H1PB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-BLOLOBMg.js → vendor-codemirror-lang-liquid-XspREksq.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BloD9GN-.js → vendor-codemirror-lang-markdown-CvO36Y1p.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-FIZMTuWM.js → vendor-codemirror-lang-php-BlUF9cCe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-CR2g6ukK.js → vendor-codemirror-lang-python-_2bIYTiJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-lsPqn4k4.js → vendor-codemirror-lang-rust-BdTYih_U.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-CtECMwzH.js → vendor-codemirror-lang-sass-E6MhfOFk.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BtmZrrZH.js → vendor-codemirror-lang-sql-B1BRhQSF.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-Br6DrntY.js → vendor-codemirror-lang-vue-BYQJRa1Q.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-DT7IlCnb.js → vendor-codemirror-lang-wast-D706yuyC.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-wNr-LZOf.js → vendor-codemirror-lang-xml--MfWU6Dj.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-BTKFwfc2.js → vendor-codemirror-lang-yaml-CRUFIbRX.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-BuDklWi8.js → vendor-codemirror-language-E2vgV9K3.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-qBLdzwMc.js → vendor-codemirror-language-data-q1yHU1R9.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-BzyfPoRb.js → vendor-codemirror-search-8kyQdB3f.js} +1 -1
- package/dist/assets/{vendor-codemirror-state-Wdz6Qsow.js → vendor-codemirror-state-CNWM3Q8V.js} +1 -1
- package/dist/assets/{vendor-codemirror-view-pXtfpqbT.js → vendor-codemirror-view-DSzLbZiS.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-BUqe2Slv.js → vendor-replit-codemirror-vim-BJY5fGLS.js} +1 -1
- package/dist/assets/{web-components-BhO08KaW.js → web-components-CLirSfwt.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/dist/assets/FilesView-DIDB-xK7.js +0 -14
- package/dist/assets/index-BZXqJcua.css +0 -1
- package/dist/assets/main-CmrF_CaW.js +0 -133
- package/dist/assets/renderElectronMiniChatApp-BhXZtZlU.js +0 -1
- package/dist/assets/renderMobileApp-DUSTAPWw.js +0 -23
- package/dist/assets/usePanelSlide-BRwyEEzi.js +0 -47
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-d23o9CKP.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-BhXma4dv.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-BZXqJcua.css","assets/SessionSwitcherDropdown-NbVfnqQQ.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/runtimeSurface-CouGjZ3A.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-base-ui-DwfTg5wD.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BuDklWi8.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-Wdz6Qsow.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-pXtfpqbT.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-CrbeaEAU.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-3xMyV7a2.js","assets/vendor-codemirror-lang-json-BTvAjwkJ.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-C4jEScp7.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-C1Svvdey.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BloD9GN-.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-qBLdzwMc.js","assets/vendor-codemirror-lang-python-CR2g6ukK.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-Bzf12ODH.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-dWA7qvjr.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-B38_7NnU.js","assets/web-components-BhO08KaW.js","assets/computeVirtualFileMetrics-BsZulefS.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-B7eVR6Pt.js","assets/isDiffPlainText-DsuyxFXo.js","assets/vendor-diff-C3JhlQdm.js","assets/usePanelSlide-BRwyEEzi.js","assets/permissionStore-BRcQ9Jgt.js","assets/usePanelSlide-BV3KOtdA.css","assets/useInlineCommentController-buNJ3xB4.js","assets/collapsible-CPkWB1VR.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/contextFileOpenGuard-BmmlK5E3.js","assets/FilesView-DIDB-xK7.js","assets/vendor-codemirror-search-BzyfPoRb.js","assets/vendor-replit-codemirror-vim-BUqe2Slv.js","assets/JsonTreeView-By2oGMNK.js","assets/Virtualizer-BxW2CJGB.js","assets/isFilePlainText-CCYoe7us.js","assets/DiagramEditor-Cp22TGpq.js","assets/vendor-react-drawio-Boqanm0j.js","assets/vendor-capacitor-status-bar-B-N0EOVk.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-keyboard-CYccoJjr.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as Ce,j as t,R as o,b as ze,e as os}from"./vendor-react-DYyjh7Q0.js";import"./vendor-katex-CHD9BdDO.js";import{u as le,a as Ye,b as Sn,d as _t,i as oe,e as xe,s as De,f as We,r as Cn,h as is,j as ls,k as Nn,l as En,m as cs,n as ds,o as xt,p as us,q as Lt,t as fs,v as Tn,w as ps}from"./index-BhXma4dv.js";import{u as ms,a as hs,b as gs,s as ys,c as bs,d as xs}from"./useWindowTitle-CnF4pKz0.js";import{u as Me,S as vs,a as ws,T as ks,P as js,r as Ss,b as Cs,c as Ns,F as Es,D as Ts,d as Rs,e as Ps,f as Is,H as As,C as Ds,A as Ms,g as _s}from"./usePanelSlide-BRwyEEzi.js";import{u as Ls,a as zs,b as Rn,c as Os,d as $s,r as jt,e as Us,t as se,o as Bs,I as W,P as ve,B as ne,f as K,g as Fs,h as de,i as Hs,j as zt,k as Ks,l as St,m as me,n as Vs,p as Ws,q as Gs,s as qs,v as Ys,S as Xs,w as Js,x as Qs,F as Pn,T as Zs,y as er,z as tr,A as Ct,O as nr,D as Ot,C as $t,E as Ut,G as Bt,H as Ft,J as Ht,K as In,L as Nt,M as sr,N as rr,Q as ar,R as be,U as or,V as ir,W as lr,X as cr,Y as dr,Z as ur,_ as fr,$ as pr,a0 as pe,a1 as mr,a2 as An,a3 as vt,a4 as Dn,a5 as hr,a6 as Kt,a7 as gr,a8 as yr,a9 as br,aa as xr,ab as vr,ac as wr,ad as kr,ae as jr,af as Sr,ag as Cr,ah as Nr,ai as Er,aj as Tr,ak as Rr,al as Pr,am as Ir,an as Ar,ao as Dr,ap as Mr,aq as _r,ar as Lr,as as zr,at as Or,au as $r,av as Ur}from"./SessionSwitcherDropdown-NbVfnqQQ.js";import{p as Br,a as Fr,S as Hr,A as Kr}from"./SettingsView-C2dCv0r7.js";import{_ as ge}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as Vr}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as Wr}from"./vendor-capacitor-core-B4EWRrHz.js";import{u as Gr}from"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import{C as qr}from"./CommitSection-BQBmpPVE.js";import{P as Yr}from"./PierreDiffViewer-B38_7NnU.js";import{K as Vt,P as Xr,d as Jr,p as Qr,U as Zr,Z as ea,Q as ta,r as na}from"./vendor-remixicon-react-CzPq62YO.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-base-ui-DwfTg5wD.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-sVFnuruh.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-B7OScDIw.js";import"./vendor-dnd-kit-core-GipZW2tY.js";import"./vendor-dnd-kit-utilities-CrOcp0Bp.js";import"./vendor-dnd-kit-accessibility-Cv52zwWT.js";import"./vendor-dnd-kit-sortable-Ct2QxIHb.js";import"./permissionStore-BRcQ9Jgt.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./runtimeSurface-CouGjZ3A.js";import"./vendor-cmdk-BCEUzcHE.js";import"./vendor-radix-ui-react-dialog-jX3Dld8c.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-D1GnwnP9.js";import"./vendor-radix-ui-react-context-CM4yFQ2I.js";import"./vendor-radix-ui-react-id-BcxRjnbX.js";import"./vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js";import"./vendor-radix-ui-react-use-controllable-state-C_ecoh35.js";import"./vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js";import"./vendor-radix-ui-react-primitive-CfpW6_IT.js";import"./vendor-radix-ui-react-slot-BxUc3Pvz.js";import"./vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js";import"./vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js";import"./vendor-radix-ui-react-focus-scope-C2K7lNPv.js";import"./vendor-radix-ui-react-portal-xlJWBfDg.js";import"./vendor-radix-ui-react-presence-Btn-Dp7L.js";import"./vendor-radix-ui-react-focus-guards-D5MZ0nQs.js";import"./vendor-react-remove-scroll-CfeMe0DL.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-C9YRs2nU.js";import"./vendor-react-style-singleton-B1H4bWSG.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-C-AuTczP.js";import"./vendor-use-callback-ref-CJB0R85I.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BuDklWi8.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-Wdz6Qsow.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-pXtfpqbT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-CrbeaEAU.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-3xMyV7a2.js";import"./vendor-codemirror-lang-json-BTvAjwkJ.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-C4jEScp7.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-C1Svvdey.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BloD9GN-.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-qBLdzwMc.js";import"./vendor-codemirror-lang-python-CR2g6ukK.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-Bzf12ODH.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-DJASDzNt.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-dWA7qvjr.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-qrcode-COsmt6jn.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./collapsible-CPkWB1VR.js";import"./web-components-BhO08KaW.js";import"./computeVirtualFileMetrics-BsZulefS.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-B7eVR6Pt.js";import"./isDiffPlainText-DsuyxFXo.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-buNJ3xB4.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";let Mn=null,Wt=!1;const sa=new Promise(e=>{Mn=e});function ra(){Wt||(Wt=!0,Mn?.())}const aa=6,oa=e=>e.parentID??null,Gt=e=>{const n=e.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},ia=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),la=(e,n)=>{if(!e)return"";let s=null,r=-1;for(const a of n){const i=ia(a.path);(e===i||e.startsWith(`${i}/`))&&i.length>r&&(s=a,r=i.length)}return s?s.label?.trim()||Gt(s.path):Gt(e)},ca=()=>{const e=Ls.getState().activeSessions,n=zs.getState().index.session.unseenCount,s=le.getState().notifyOnSubtasks,r=Rn.getState().projects,a=Os.getState().ids,i=$s.getState().rankById;let l=0;const c=[];for(const u of e){const f=oa(u)!==null,x=(n[u.id]??0)>0&&(!f||s);x&&(l+=1),f||c.push({session:u,unread:x,project:la(jt(u),r)})}c.sort((u,f)=>Us(u.session,f.session,a,i));const d=c.slice(0,aa).map(({session:u,unread:f,project:b})=>({id:u.id,title:u.title??"",unread:f,project:b}));return{runtimeKey:Ye(),attentionCount:l,recentSessions:d}},da="__PICHAMBER_WIDGET_SNAPSHOT__",ua=()=>{typeof window>"u"||(window[da]=()=>{try{return JSON.stringify(ca())}catch{return null}})},ft="mobile-app-update-available",qt="mobile-app-update-toast-dismissed-version",fa=()=>{const e=Me(i=>i.available),n=Me(i=>i.runtimeType),s=Me(i=>i.info?.version),r=Me(i=>i.info?.downloadUrl),a=Ce.useRef(new Set);return Ce.useEffect(()=>{if(Sn()!=="android"||n!=="mobile"||!e||!s||!r){se.dismiss(ft);return}_t().getItem(qt)!==s&&(a.current.has(s)||(a.current.add(s),se.info("PiChamber update available",{id:ft,description:`Version ${s} is ready for Android.`,duration:1/0,icon:t.jsx(W,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{Bs(r)}},cancel:{label:"Dismiss",onClick:()=>{_t().setItem(qt,s),se.dismiss(ft)}}})))},[e,r,n,s]),null},pa="Updating OpenCode configuration...",_n=0,Ln=pa,Yt=new Set;function ma(e){return Yt.add(e),e({isUpdating:_n>0,message:Ln}),()=>{Yt.delete(e)}}function ha(){return{isUpdating:_n>0,message:Ln}}const ga=()=>{const[{isUpdating:e},n]=o.useState(()=>ha());return o.useEffect(()=>ma(n),[]),e?t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(ve,{width:80,height:80,isAnimated:!0})}):null},tt="pichamber.mobile.connections.v1",ya="pichamber.mobile.",Xt="pichamber.mobile.deviceId",ba=()=>{try{const e=window.localStorage.getItem(Xt);if(e&&e.trim())return e.trim();const n=crypto.randomUUID();return window.localStorage.setItem(Xt,n),n}catch{return crypto.randomUUID()}},Jt=()=>`mobile:${ba()}`,Qt=()=>{try{const e=Wr.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},zn=12,xa=8e3,va=2500,wa=3e3,nt=2500,ka=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:n=>n===e}},Ue=e=>{const n=e.trim();if(!n)return"";const s=/^https?:\/\//i.test(n)?n:`http://${n}`,r=new URL(s);return r.hash="",r.search="",r.pathname=r.pathname.replace(/\/+$/,""),r.toString().replace(/\/+$/,"")},Ze=e=>{try{return new URL(e).host}catch{return e}},Oe=e=>{try{return Ue(e)}catch{return e.trim().replace(/\/+$/g,"")}},On=(e,n)=>Oe(e)===Oe(n),$n=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,ja=e=>`relay://${e.serverId}`,ot=e=>e.candidates.filter(n=>n.kind==="direct"),Ee=e=>{const n=e.candidates.find(s=>s.kind==="relay");return n&&n.kind==="relay"?n.relay:null},ye=e=>{const n=ot(e)[0];if(n)return n.url;const s=Ee(e);return s?ja(s):""},re=e=>{const n=Ee(e);if(n)return $n(n);const s=ot(e)[0];return s?Oe(s.url):""},st=(e,n)=>{const s=e.find(i=>i.kind==="relay"),r=s&&s.kind==="relay"?s.relay.serverId:null,a=new Set(e.filter(i=>i.kind==="direct").map(i=>Oe(i.url)));return n.some(i=>i.kind==="relay"?r!==null&&i.relay.serverId===r:a.has(Oe(i.url)))},Et=e=>{const n=(()=>{try{return Ue(e)}catch{return""}})();return n?[{kind:"direct",url:n}]:[]},Zt=e=>{if(e.candidates&&e.candidates.length>0)return e.candidates;const n=[];return typeof e.url=="string"&&e.url.trim()&&!/^relay:\/\//i.test(e.url.trim())&&n.push(...Et(e.url)),e.relay&&n.push({kind:"relay",relay:e.relay}),n},Tt=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;const n=e;if(typeof n.relayUrl!="string"||!n.relayUrl.trim()||typeof n.serverId!="string"||!n.serverId.trim())return null;const s=n.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const r=s;return r.kty!=="EC"||r.crv!=="P-256"||typeof r.x!="string"||!r.x||typeof r.y!="string"||!r.y?null:{relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:r.x,y:r.y}}},it=e=>{try{return JSON.stringify(e)}catch{return String(e)}},ie=(e,n={})=>{console.info("[mobile-connect]",e,it(n)),ls("connect",{code:e,status:typeof n.status=="number"?n.status:void 0,detail:typeof n.reason=="string"?n.reason:typeof n.result=="string"?n.result:void 0})},$e=(e,n={})=>{console.info("[mobile-storage]",e,it(n))},Sa=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},Ca=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},Na=async(e,n)=>{if(!oe())return null;try{const{CapacitorHttp:s}=await ge(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),r=Object.fromEntries(new Headers(n?.headers).entries()),a=await s.request({url:e,method:n?.method||"GET",headers:r,data:Ca(n?.body)});return{ok:a.status>=200&&a.status<300,status:a.status,source:"native-http",json:async()=>Sa(a.data)}}catch(s){return console.warn("[mobile-connect]","native-http failed",it({url:e,error:s instanceof Error?s.message:String(s)})),null}},Ea=async(e,n)=>{const s=await fetch(e,n).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",it({url:e,error:r instanceof Error?r.message:String(r)})),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},ke=async(e,n,s)=>{let r;const a=new Promise(i=>{r=window.setTimeout(()=>{s?.(),i(null)},e)});try{return await Promise.race([n,a])}catch{return null}finally{r!==void 0&&window.clearTimeout(r)}},Te=async(e,n,s)=>{const r=s?.totalTimeoutMs??xa,a=Date.now(),i=await ke(Math.min(va,r),Na(e,n));if(i)return i;const l=new AbortController,c=Math.max(500,r-(Date.now()-a));return ke(c,Ea(e,{...n,signal:l.signal}),()=>l.abort())},lt=async e=>{if(!e)return null;const n=await e.json().catch(()=>null);if(!n||typeof n!="object")return null;const s=n;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},Ge=15e3,Ta=async(e,n,s,r=Ge,a)=>{const i=Nn({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk}),l=c=>c==="ok"&&a?.keepTunnel?{outcome:c,tunnel:i}:(i.close(),{outcome:c});try{const c=n?{Authorization:`Bearer ${n}`}:void 0,d=await ke(r,i.fetch("/auth/session",{headers:c}).catch(()=>null));if(ie("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!n}),!d)return l("unreachable");if(d.status===401)return l(n?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return l("auth-failed");const u=await lt(d);return u&&u.disabled!==!0&&u.authenticated===!1?l(n?"auth-failed":"needs-login"):l("ok")}catch(c){throw i.close(),c}},Ra=(e,n,s,r,a)=>{const i=typeof window<"u"?window.location.origin:"",l={relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk,...s?{grant:s}:{}};a&&is(l,a),De({apiBaseUrl:i,clientToken:n,runtimeKey:r??$n(e),relay:l})},Pa=e=>{if(!e||typeof e!="object")return null;const n=e;if(n.kind==="direct")return typeof n.url=="string"&&n.url.trim()?{kind:"direct",url:n.url}:null;if(n.kind==="relay"){const s=Tt(n.relay);return s?{kind:"relay",relay:s}:null}return null},Ia=e=>{if(e.mode==="relay"){const n=Tt(e.relay);return n?[{kind:"relay",relay:n}]:[]}return typeof e.url=="string"?Et(e.url):[]},Re=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(tt)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const n=oe();return e.flatMap(s=>{if(!s||typeof s!="object")return[];const r=s;if(typeof r.id!="string")return[];const a=Array.isArray(r.candidates)?r.candidates.map(Pa).filter(d=>!!d):Ia(r);if(a.length===0)return[];const i=typeof r.clientToken=="string"&&r.clientToken.trim()?r.clientToken:void 0,l=typeof r.label=="string"&&r.label.trim()?r.label:Ze(ye({candidates:a})),c={id:r.id,label:l,candidates:a,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return n?[{...c,hasToken:!!r.hasToken||!!i}]:[{...c,clientToken:i,hasToken:!!i}]}).sort((s,r)=>r.lastUsedAt-s.lastUsedAt)},wt=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},Rt=e=>{if(typeof window>"u")return;const n=oe(),s=e.slice(0,zn).map(r=>{const a={id:r.id,label:r.label,candidates:r.candidates.map(wt),lastUsedAt:r.lastUsedAt};return n?{...a,hasToken:!!(r.hasToken||r.clientToken)}:{...a,clientToken:r.clientToken}});try{window.localStorage.setItem(tt,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},Un=(e,n)=>{const s=e.find(i=>n.id&&i.id===n.id||st(i.candidates,n.candidates)),r=oe(),a={id:n.id||s?.id||crypto.randomUUID(),label:n.label,candidates:n.candidates,lastUsedAt:Date.now(),...r?{hasToken:n.hasToken??(!!n.clientToken||s?.hasToken||!1)}:{clientToken:n.clientToken??s?.clientToken,hasToken:!!(n.clientToken??s?.clientToken)}};return[a,...e.filter(i=>i.id!==a.id&&!st(i.candidates,n.candidates))].slice(0,zn)},Pt=Vr,Aa=0,It=e=>`${ya}token.${encodeURIComponent(e)}`,Da=async(e,n)=>{let s;const r=new Promise(a=>{s=window.setTimeout(()=>a(n),wa)});try{return await Promise.race([e.catch(()=>n),r])}finally{s!==void 0&&window.clearTimeout(s)}},At=async(e,n,s)=>oe()?Da(n().catch(r=>(console.warn(`[mobile-storage] ${e} failed`,r),s)),s):s,qe=async e=>{$e("secure:read-start",{key:e});const n=await At("secure:read",async()=>(await Pt.internalGetItem({prefixedKey:It(e),sync:!1})).data,null),s=typeof n=="string"&&n.trim()?n:void 0;return $e("secure:read",{key:e,hasToken:!!s}),s},Se=async(e,n)=>{$e("secure:write-start",{key:e});const s=await At("secure:write",async()=>(await Pt.internalSetItem({prefixedKey:It(e),data:n,sync:!1,access:Aa}),!0),!1);return $e("secure:write",{key:e,ok:s}),s},Ma=async e=>{await At("secure:delete",async()=>(await Pt.internalRemoveItem({prefixedKey:It(e),sync:!1}),!0),!1)},_a=async(e,n)=>{let s=0,r=0;return{records:await Promise.all(e.map(async i=>{if(!i||typeof i!="object")return i;const l=i,c=typeof l.url=="string"?l.url:null,d=typeof l.clientToken=="string"?l.clientToken.trim():"";if(!c||!d)return i;if(!await n(c,d))return r+=1,i;s+=1;const{clientToken:u,...f}=l;return{...f,hasToken:!0}})),migrated:s,failed:r}},Bn=async()=>{if(typeof window>"u"||!oe())return;let e;try{e=JSON.parse(window.localStorage.getItem(tt)||"[]")}catch{return}if(!Array.isArray(e))return;const n=e.filter(r=>!!r&&typeof r=="object"&&typeof r.url=="string"&&typeof r.clientToken=="string"&&!!r.clientToken.trim());if(n.length===0)return;$e("secure:migrate-start",{count:n.length});const s=await _a(e,async(r,a)=>{const i=Oe(r);return await Se(i,a)?await qe(i)===a:!1});if(s.migrated>0)try{window.localStorage.setItem(tt,JSON.stringify(s.records))}catch(r){console.warn("[mobile-storage] failed to finalize secure token migration",r);return}$e("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},La=async()=>(await Bn(),Re()),rt=async e=>{const n=Un(Re(),e);return Rt(n),oe()&&e.clientToken&&await Se(re({candidates:e.candidates}),e.clientToken),n},za=async e=>{const n=Re(),s=n.find(a=>a.id===e)??null,r=n.filter(a=>a.id!==e);return Rt(r),s&&oe()&&await Ma(re(s)),r},Oa=1500,at=async(e,n,s)=>{const r=s?.fast?{totalTimeoutMs:nt}:void 0,a=Ee({candidates:e})?.serverId??null,i=e.find(u=>u.kind==="relay")??null,l=e.filter(u=>u.kind==="direct"),c=async()=>{for(const u of l){const f=Ue(u.url)||u.url,b=n?{Authorization:`Bearer ${n}`}:void 0,x=await Te(`${f}/health`,{method:"GET"},r);if(!x?.ok)continue;if(a){const D=await x.json().catch(()=>null),U=D&&typeof D=="object"?D.serverId:null;if(typeof U=="string"&&U&&U!==a){ie("probe:server-id-mismatch",{url:f});continue}}const v=await Te(`${f}/auth/session`,{method:"GET",credentials:n?"omit":"include",headers:b},r);if(v?.status===401)return{status:"needs-login"};if(!v||!v.ok&&v.status!==404)continue;const y=await lt(v);if(y&&y.disabled!==!0&&y.authenticated===!1)return{status:"needs-login"};const j=y?.disabled===!0;return!n&&oe()&&!j&&y?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},d=async()=>{if(!i)return{status:"unreachable"};const{outcome:u,tunnel:f}=await Ta(i.relay,n,void 0,s?.fast?nt:void 0,{keepTunnel:!0});return u==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:f}}:u==="needs-login"||u==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?l.length===0?d():new Promise(u=>{let f=!1,b=!1,x,v=null,y=null;const j=p=>{p?.status==="ok"&&p.transport.kind==="relay"&&p.transport.tunnel?.close()},D=p=>{f||(f=!0,u(p))},U=()=>{b||f||(x!==void 0&&(window.clearTimeout(x),x=void 0),d().then(p=>{if(y=p,f||b){j(p);return}if(p.status==="ok"||p.status==="needs-login"){D(p);return}v&&D(v)}))};c().then(p=>{if(v=p,!f){if(p.status==="ok"||p.status==="needs-login"){b=!0,x!==void 0&&window.clearTimeout(x),j(y),D(p);return}if(y){D(y);return}U()}}),x=window.setTimeout(U,Oa)}):c()},Ne=(e,n,s)=>{e.kind==="relay"?Ra(e.relay,n,s?.grant,s?.runtimeKey,e.tunnel):De({apiBaseUrl:e.url,clientToken:n,runtimeKey:s?.runtimeKey}),Hn()},Fe=()=>{const e=Re()[0];return e?.label?.trim()?e.label:null},pt=async()=>{await Bn();const e=Re()[0];if(!e)return{status:"no-candidate"};let n;if(oe()){if(!e.hasToken)return{status:"no-candidate"};if(n=await qe(re(e)),!n)return{status:"no-candidate"}}else if(n=e.clientToken,!n)return{status:"no-candidate"};const s=await at(e.candidates,n,{fast:!0});return s.status==="needs-login"?{status:"needs-login",label:e.label}:s.status!=="ok"?{status:"unreachable",label:e.label}:(await rt({id:e.id,label:e.label,candidates:e.candidates}),Ne(s.transport,n,{runtimeKey:re(e)}),{status:"connected"})},$a=async(e,n)=>{let s="";try{s=Ue(e.url)}catch{return!1}if(!s)return!1;const r=e.clientToken?.trim()||void 0,a=r?{Authorization:`Bearer ${r}`}:void 0,i={totalTimeoutMs:nt};if(!(await Te(`${s}/health`,{method:"GET",headers:a},i))?.ok)return!1;const c=await Te(`${s}/auth/session`,{method:"GET",credentials:r?"omit":"include",headers:a},i);if(!c||!c.ok&&c.status!==404)return!1;const d=await lt(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},Ua=e=>[...e].sort((n,s)=>{const r=(n.priority??100)-(s.priority??100);if(r!==0)return r;const a=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return a(n)-a(s)}).flatMap(n=>{if(n.type==="relay"){const s=Tt({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Et(n.url)}),en=async e=>{const n=Ee({candidates:e})?.serverId??null;for(const s of e){if(s.kind==="relay"){const i=Nn(s.relay),l=await ke(Ge,i.fetch("/health").catch(()=>null));if(ie("establish:relay:health",{ok:l?.ok===!0,status:l?.status??null}),l?.ok)return{kind:"relay",relay:s.relay,tunnel:i};i.close();continue}const r=Ue(s.url)||s.url,a=await Te(`${r}/health`,{method:"GET"});if(ie("establish:direct:health",{ok:a?.ok===!0,status:a?.status??null}),!!a?.ok){if(n){const i=await a.json().catch(()=>null),l=i&&typeof i=="object"?i.serverId:null;if(typeof l=="string"&&l&&l!==n){ie("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},Ba=async(e,n)=>{if(!We())return $a(e);const s=await ke(nt,Cn("/auth/session").then(a=>a).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const r=await lt(s);return!(r&&r.disabled!==!0&&r.authenticated===!1)},Fa=e=>e.kind==="relay"?We():!We()&&On(e.url,xe()),Fn=()=>{const e=Ye();return e?Re().find(n=>re(n)===e)??null:null},tn=e=>{const n=Ye();return!!n&&re(e)===n},et=async()=>{const e=Fn();if(!e)return"no-connection";let n;if(oe()?n=e.hasToken?await qe(re(e)):void 0:n=e.clientToken,!n)return"unreachable";const s=e.candidates.findIndex(c=>Fa(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),r=s>=0?e.candidates.slice(0,s):e.candidates,a=await at(r,n,{fast:!0});if(a.status==="ok")return await rt({id:e.id,label:e.label,candidates:e.candidates}),Ne(a.transport,n,{runtimeKey:re(e)}),"switched";if(a.status==="needs-login")return"needs-login";if(s>=0&&await Ba({url:xe(),clientToken:n}))return Hn(),"unchanged";const i=s>=0?e.candidates.slice(s+1):[],l=await at(i,n,{fast:!0});return l.status==="ok"?(await rt({id:e.id,label:e.label,candidates:e.candidates}),Ne(l.transport,n,{runtimeKey:re(e)}),"switched"):l.status==="needs-login"?"needs-login":"unreachable"},Ha=5e3;let mt=!1;const Ka=async()=>{if(mt)return"skipped";const e=Fn();if(!e)return ie("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const n=Ee(e);if(!n)return ie("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";mt=!0;try{const s=await ke(Ge,Cn("/api/client-auth/connection/candidates").then(u=>u).catch(()=>null));if(!s?.ok)return ie("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const r=await s.json().catch(()=>null);if(!r||r.serverId!==n.serverId)return ie("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const a=Array.isArray(r.candidates)?r.candidates:[],i=[];for(const u of a){if(!u||typeof u!="object")continue;const f=u;if(!(f.type!=="lan"||typeof f.url!="string"))try{const b=Ue(f.url);b&&!i.includes(b)&&i.push(b)}catch{}}if(i.length===0)return ie("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const l=ot(e).filter(u=>u.url.startsWith("https://")),c=[...i.map(u=>({kind:"direct",url:u})),...l,{kind:"relay",relay:n}];return JSON.stringify(e.candidates.map(wt))===JSON.stringify(c.map(wt))?"unchanged":(ie("candidates:refreshed",{lanCount:i.length}),await rt({id:e.id,label:e.label,candidates:c}),"updated")}finally{mt=!1}},Hn=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await Ka().catch(()=>"skipped");ie("candidates:refresh-result",{result:e}),e==="updated"&&We()&&await et().catch(()=>null)})()},Ha)},Kn=e=>{const[n,s]=o.useState(()=>Re()),[r,a]=o.useState(null),[i,l]=o.useState(null),[c,d]=o.useState(null),u=o.useRef(n),f=o.useRef(null),b=o.useRef(ka()),x=o.useCallback(w=>{u.current=w,s(w)},[]),v=o.useCallback(w=>{f.current=w,a(w)},[]),y=o.useCallback(w=>{f.current===w&&(f.current=null,a(null))},[]);o.useEffect(()=>{let w=!1;return La().then(R=>{w||x(R)}),()=>{w=!0}},[x]);const j=o.useCallback(w=>{const R=Un(u.current,w);return x(R),Rt(R),R},[x]),D=o.useCallback(async w=>{l(null),v("connect");try{const R=Zt(w);if(R.length===0){l("Enter a server URL.");return}const T=w.id?u.current.find(g=>g.id===w.id):u.current.find(g=>st(g.candidates,R)),O=w.label?.trim()||T?.label||Ze(ye({candidates:R})),N=w.relayGrant;let M=w.clientToken?.trim()||void 0;const h=!!M;M||(oe()?T?.hasToken&&(M=await qe(re({candidates:R}))):M=T?.clientToken),ie("connect:start",{candidates:R.map(g=>g.kind),hasToken:!!M});const B=await at(R,M);if(ie("connect:probe",{status:B.status}),B.status==="unreachable"){l("Could not reach that PiChamber server.");return}if(B.status==="needs-login"){j({id:T?.id,label:O,candidates:R}),d({id:T?.id??crypto.randomUUID(),label:O,candidates:R,relay:Ee({candidates:R})??void 0,relayGrant:N});return}M&&h&&oe()&&await Se(re({candidates:R}),M),j({id:T?.id,label:O,candidates:R,clientToken:M}),Ne(B.transport,M??null,{runtimeKey:re({candidates:R}),grant:N}),e()}catch(R){console.warn("[mobile-connect] connect threw",R),l("That server URL is not valid.")}finally{y("connect")}},[v,y,e,j]),U=o.useCallback(async w=>{if(f.current==="pairing")return;l(null),v("pairing");const R=Ua(w.candidates);let T=null,O=!1;try{if(T=await en(R),!T){l("Could not reach that PiChamber server.");return}const N=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:Qt(),dedupeKey:Jt()}),M={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:N},h=T.kind==="relay"?await ke(Ge,T.tunnel.fetch("/api/client-auth/pairing/redeem",M).catch(()=>null)):await Te(`${T.url}/api/client-auth/pairing/redeem`,M);if(!h?.ok){l("This server needs a password or client token.");return}const B=await h.json().catch(()=>null),g=typeof B?.clientToken=="string"?B.clientToken.trim():"";if(!g){l("This server needs a password or client token.");return}const C=typeof B?.server?.label=="string"?B.server.label:"",L=w.label||C||Ze(ye({candidates:R}));if(oe()&&!await Se(re({candidates:R}),g)){l("This server needs a password or client token.");return}j({label:L,candidates:R,clientToken:g}),Ne(T.kind==="relay"?{kind:"relay",relay:T.relay,tunnel:T.tunnel}:{kind:"direct",url:T.url},g,{runtimeKey:re({candidates:R})}),O=T.kind==="relay",e()}catch(N){console.warn("[mobile-connect] pairing threw",N),l("This server needs a password or client token.")}finally{!O&&T?.kind==="relay"&&T.tunnel.close(),y("pairing")}},[v,y,e,j]),p=o.useCallback(async w=>{if(!c||!w.trim()||f.current==="password")return;l(null),v("password");const R=b.current.begin(),T=()=>b.current.isCurrent(R),{id:O,label:N,candidates:M}=c;let h=null,B=!1;try{if(h=await en(M),!T())return;if(!h){l("Could not reach that PiChamber server.");return}const g={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:Qt(),dedupeKey:Jt()})};ie("password:start",{transport:h.kind});const C=h.kind==="relay"?await ke(Ge,h.tunnel.fetch("/auth/session",g).catch(()=>null)):await Te(`${h.url}/auth/session`,g);if(!T())return;if(ie("password:done",{ok:C?.ok===!0,status:C?.status??null}),!C?.ok){l("Could not unlock that server. Check the password.");return}const L=await C.json().catch(()=>null);if(!T())return;const Y=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(ie("password:token",{issued:!!Y}),!Y){if(h.kind==="direct"&&!oe()){j({id:O,label:N,candidates:M}),d(null),Ne({kind:"direct",url:h.url},null,{runtimeKey:re({candidates:M})}),e();return}l("This server needs a password or client token.");return}if(oe()&&(!T()||(await Se(re({candidates:M}),Y),!T()))||!T()||(j({id:O,label:N,candidates:M,clientToken:Y}),d(null),Ne(h.kind==="relay"?{kind:"relay",relay:h.relay,tunnel:h.tunnel}:{kind:"direct",url:h.url},Y,{runtimeKey:re({candidates:M})}),B=h.kind==="relay",!T()))return;e()}catch(g){if(!T())return;console.warn("[mobile-connect] password threw",g),l("Could not unlock that server. Check the password.")}finally{!B&&h?.kind==="relay"&&h.tunnel.close(),T()&&y("password")}},[v,y,e,c,j]),m=o.useCallback(()=>{b.current.cancel(),y("password"),d(null),l(null)},[y]),E=o.useCallback(async w=>{l(null);let R=Zt(w);const T=w.id?u.current.find(h=>h.id===w.id)??null:null;if(T){const h=R.filter(C=>C.kind==="direct"),B=ot(T).filter(C=>C.url.startsWith("https://")&&!h.some(L=>On(L.url,C.url))),g=Ee(T);R=[...h,...B,...g?[{kind:"relay",relay:g}]:[]]}if(R.length===0)return l("Enter a server URL."),null;const O=w.clientToken?.trim()||void 0,N=w.label?.trim()||Ze(ye({candidates:R}));if(oe()){const h=re({candidates:R});if(O)await Se(h,O);else if(T?.hasToken){const B=re(T);if(B&&h&&B!==h){const g=await qe(B);g&&await Se(h,g)}}}return j({id:w.id,label:N,candidates:R,clientToken:O}).find(h=>st(h.candidates,R))??null},[j]),z=o.useCallback(async w=>{const R=u.current.find(O=>O.id===w)??null,T=await za(w);return x(T),R},[x]);return{connections:n,isBusy:r!==null,isPasswordBusy:r==="password",error:i,pendingConnection:c,connect:D,redeemPairingConnection:U,submitPassword:p,cancelPassword:m,saveConnection:E,removeConnection:z,setError:l}},Vn=()=>{if(typeof window>"u")return null;const n=window.Capacitor?.Plugins?.BarcodeScanner;return n&&(typeof n.scan=="function"||typeof n.startScan=="function")?n:null},Va=()=>window.Capacitor?.getPlatform?.()==="android",Wn=e=>{const n=e.trim();if(!n)return null;if(/^pichamber:\/\//i.test(n)){const s=Br(n);return s?{pairing:s}:null}return/^https?:\/\//i.test(n)?{url:n}:null},Gn=(e,n)=>{const s=Wn(e);if(!s&&n?.pairingStringFallback){const r=Fr(e);if(r)return{status:"pairing",pairing:r}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Wa=async(e,n)=>{if(!e.startScan||!e.stopScan||!e.addListener)return{status:"unsupported"};if(n?.aborted)return{status:"cancelled"};let s,r,a=!1,i=()=>{};const l=new Promise(u=>{i=u}),c=u=>{a||(a=!0,i(u))},d=()=>c({status:"cancelled"});n?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(e.addListener("barcodesScanned",({barcodes:f})=>{const b=f?.[0],x=(b?.rawValue??b?.displayValue??"").trim();x&&c(Gn(x,{pairingStringFallback:!0}))})).then(f=>{s=f}),Promise.resolve(e.addListener("scanError",()=>c({status:"failed"}))).then(f=>{r=f})])).some(({status:f})=>f==="rejected")?c({status:"failed"}):a||e.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await l}finally{n?.removeEventListener("abort",d),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(r?.remove()),e.stopScan()])}},kt=()=>Vn()!==null,qn=async e=>{const n=Vn();if(!n)return{status:"unsupported"};try{if(n.requestPermissions){const l=(await n.requestPermissions())?.camera;if(l&&l!=="granted"&&l!=="limited")return{status:"permission-denied"}}if(e?.signal?.aborted)return{status:"cancelled"};if(Va())return Wa(n,e?.signal);if(!n.scan)return{status:"unsupported"};const r=(await n.scan({formats:["QR_CODE"]}))?.barcodes?.[0],a=(r?.rawValue??r?.displayValue??"").trim();return a?Gn(a):{status:"cancelled"}}catch{return{status:"failed"}}},Le={autoComplete:"off",autoCorrect:"off",spellCheck:!1},He="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",Yn=({onCancel:e})=>{const n=o.useRef(null);return o.useLayoutEffect(()=>{const s={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},r={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const a=new Map,i=c=>{!(c instanceof HTMLElement)||c===n.current||a.has(c)||(a.set(c,{opacity:c.style.opacity,pointerEvents:c.style.pointerEvents}),c.style.setProperty("opacity","0"),c.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(i);const l=new MutationObserver(c=>{c.forEach(d=>d.addedNodes.forEach(i))});return l.observe(document.body,{childList:!0}),()=>{l.disconnect(),a.forEach((c,d)=>{d.style.opacity=c.opacity,d.style.pointerEvents=c.pointerEvents}),s.value?document.documentElement.style.setProperty("background-color",s.value,s.priority):document.documentElement.style.removeProperty("background-color"),r.value?document.body.style.setProperty("background-color",r.value,r.priority):document.body.style.removeProperty("background-color")}},[]),o.useEffect(()=>{const s=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[e]),ze.createPortal(t.jsxs("div",{ref:n,role:"dialog","aria-modal":"true","aria-label":"Scan QR code",className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}),t.jsxs(ne,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[t.jsx(W,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},Xn=()=>ze.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[t.jsx(ve,{width:96,height:96,isAnimated:!0}),t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[t.jsx(W,{name:"loader-4",className:"size-[18px] animate-spin"}),t.jsx("span",{children:"Connecting..."})]})]}),document.body),Ga=({onConnected:e,notice:n=null})=>{const s=Kn(e),{connections:r,isBusy:a,isPasswordBusy:i,error:l,pendingConnection:c}=s,[d,u]=o.useState(""),[f,b]=o.useState(""),[x,v]=o.useState(""),[y,j]=o.useState(!1),[D,U]=o.useState(!1),p=o.useRef(null),m=o.useMemo(()=>kt(),[]),[E,z]=o.useState(()=>!kt()),[w,R]=o.useState(null),[T,O]=o.useState(""),N=o.useCallback(C=>{C.preventDefault(),s.connect({url:d,clientToken:x,label:f})},[x,s,f,d]),M=o.useCallback(C=>{if(/^pichamber:\/\//i.test(C.trim())){const L=Wn(C);if(L){if("pairing"in L){s.redeemPairingConnection(L.pairing);return}u(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken);return}}u(C)},[s]),h=o.useCallback(async()=>{if(p.current||a)return;s.setError(null),j(!0);const C=new AbortController;p.current=C;try{const L=await qn({signal:C.signal});switch(p.current===C&&(p.current=null,j(!1)),L.status){case"ok":U(!0),u(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken),await s.connect({url:L.url,clientToken:L.clientToken,label:L.label});break;case"pairing":U(!0),await s.redeemPairingConnection(L.pairing);break;case"permission-denied":s.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":s.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":s.setError("QR scanning is only available in the installed mobile app.");break;case"failed":s.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{U(!1),p.current===C&&(p.current=null,j(!1))}},[s,a]);o.useEffect(()=>()=>p.current?.abort(),[]);const B=o.useCallback(C=>{C.preventDefault(),s.submitPassword(T)},[s,T]),g=o.useCallback(()=>{O(""),s.cancelPassword()},[s]);return t.jsxs(t.Fragment,{children:[y?t.jsx(Yn,{onCancel:()=>p.current?.abort()}):null,D?t.jsx(Xn,{}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(ve,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),n?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(W,{name:n.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:n.kind==="auth-expired"?`Access to ${n.label} has expired or was revoked. Sign in again.`:`Couldn't reach ${n.label}. Check that the server is running.`})]}):null,c?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:B,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(W,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(C=>C.kind==="direct")?ye(c):"via PiChamber Relay"})]})]}),t.jsx("input",{...Le,value:T,onChange:C=>O(C.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:He}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(ne,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!T.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:g,children:"Use another server"})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[m?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ne,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{h()},disabled:y||a,children:[t.jsx(W,{name:"scan-2",className:K("size-[18px]",y&&"animate-pulse")}),a?"Connecting...":"Scan QR code"]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}):null,l&&!E?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved connections"}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(C=>{const L=w===C.id;return t.jsxs("button",{type:"button",disabled:a,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{R(C.id),s.connect({id:C.id,candidates:C.candidates,clientToken:C.clientToken,label:C.label}).finally(()=>R(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(W,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:C.label}),t.jsx("span",{className:K("block truncate typography-small",L?"text-foreground":"text-muted-foreground"),children:L?"Connecting...":C.candidates.some(Y=>Y.kind==="direct")?ye(C):"via PiChamber Relay"})]}),L?t.jsx(W,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(W,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},C.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[m?t.jsxs("button",{type:"button",onClick:()=>z(C=>!C),"aria-expanded":E,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:"Connect by address"}),t.jsx(W,{name:"arrow-down-s",className:K("size-4 transition-transform duration-200",E&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:E?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:N,children:[t.jsx("input",{...Le,value:d,onChange:C=>M(C.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:E?void 0:-1,className:K(He,"text-center")}),t.jsx("input",{value:f,onChange:C=>b(C.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:E?void 0:-1,className:K(He,"text-center")}),t.jsx("input",{...Le,value:x,onChange:C=>v(C.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:E?void 0:-1,autoCapitalize:"none",className:K(He,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(ne,{type:"submit",variant:m?"outline":"default",size:"lg",className:"h-12 w-full",disabled:a||y||!d.trim(),children:a?"Connecting...":"Connect"})]})})})]})]})]})})]})},nn=380,qa=e=>typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.min(100,Math.round(e))),Ya=e=>e>=90?"critical":e>=75?"warn":"safe",sn=(e,n)=>{if(!e||typeof e!="object")return;const s=e[n];return typeof s=="number"&&Number.isFinite(s)?s:void 0},rn=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),Jn=({percentage:e})=>{const n=qa(e),s=Ya(e),r=s==="critical"?"var(--status-error)":s==="warn"?"var(--status-warning)":"var(--status-success)",a=18,i=3,l=(a-i)/2,c=2*Math.PI*l;return t.jsxs("svg",{viewBox:`0 0 ${a} ${a}`,className:"size-[18px] -rotate-90",role:"progressbar","aria-valuenow":Math.round(n),"aria-valuemin":0,"aria-valuemax":100,children:[t.jsx("circle",{cx:a/2,cy:a/2,r:l,fill:"none",stroke:"var(--interactive-border)",strokeWidth:i}),t.jsx("circle",{cx:a/2,cy:a/2,r:l,fill:"none",stroke:r,strokeWidth:i,strokeLinecap:"round",strokeDasharray:c,strokeDashoffset:c*(1-n/100),className:"transition-[stroke-dashoffset,stroke] duration-300"})]})},Xa=({icon:e,iconNode:n,label:s,children:r})=>t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:n??(e?t.jsx(W,{name:e,className:"size-[18px]"}):null)}),t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:s}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:r})]}),Ja=({open:e,onClose:n,anchorRef:s,contextDisplay:r})=>{const a=o.useRef(null),[i,l]=o.useState(e),[c,d]=o.useState(!1),{enabled:u}=St(),f=o.useRef(null),[b,x]=o.useState(null);o.useLayoutEffect(()=>{if(!e||!u||!i)return;const y=()=>{const U=s.current?.getBoundingClientRect(),p=f.current?.getBoundingClientRect();if(!U||!p){x(null);return}const m=U.left-p.left,E=Math.min(Math.max(m,8),Math.max(8,p.width-nn-8));x(E)};y();const j=f.current;if(typeof ResizeObserver>"u"||!j)return;const D=new ResizeObserver(y);return D.observe(j),()=>D.disconnect()},[s,u,e,i]);const v=u&&b!==null;return o.useEffect(()=>{if(e){l(!0),d(!1);return}if(!i)return;d(!0);const y=window.setTimeout(()=>{l(!1),d(!1)},140);return()=>window.clearTimeout(y)},[e,i]),o.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[n,e]),o.useEffect(()=>{if(!e)return;const y=j=>{const D=j.target;if(!(D instanceof Node)){n();return}a.current?.contains(D)||s.current?.contains(D)||n()};return document.addEventListener("pointerdown",y,!0),document.addEventListener("wheel",y,!0),()=>{document.removeEventListener("pointerdown",y,!0),document.removeEventListener("wheel",y,!0)}},[s,n,e]),i?t.jsxs("div",{ref:f,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[t.jsx("div",{ref:a,role:"tooltip","aria-label":"Context usage for current conversation",className:K("overflow-y-auto overscroll-contain rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)] will-change-transform",v?"absolute origin-top-left":"mx-3 mt-2",c?"pointer-events-none":"pointer-events-auto"),style:{animation:`${c?"session-metadata-out":"session-metadata-in"} ${c?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...v?{top:8,left:b??8,width:`min(${nn}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsx(Xa,{iconNode:t.jsx(Jn,{percentage:r.percentage}),label:"Context",children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:K("font-semibold",r.colorClass),children:[r.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:r.tokens})]})}):t.jsx("div",{className:"px-2.5 py-2 typography-meta text-muted-foreground",children:"Context usage is not available for this conversation yet."})})}),t.jsx("style",{children:`
|
|
3
|
-
@keyframes session-metadata-in {
|
|
4
|
-
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
5
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
6
|
-
}
|
|
7
|
-
@keyframes session-metadata-out {
|
|
8
|
-
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
9
|
-
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
10
|
-
}
|
|
11
|
-
`})]}):null},Qa=o.memo(function({open:n,onOpenChange:s,currentSessionId:r,effectiveDirectory:a,isNewSessionDraftOpen:i}){const l=o.useRef(null),c=Fs(r??""),d=de(h=>h.providers),u=de(h=>h.currentProviderId),f=de(h=>h.currentModelId),b=de(h=>h.getCurrentModel()),x=de(h=>h.getModelMetadata);de(h=>h.modelsMetadata.size);const v=Hs(o.useCallback(h=>r?h.sessionModelSelections.get(r)??null:null,[r])),y=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const B=c[h]?.info;if(B.role!=="user")continue;const g=B.model,C=g?.providerID??g?.providerId,L=g?.modelID??g?.modelId,Y=typeof C=="string"&&C.trim().length>0?C:void 0,J=typeof L=="string"&&L.trim().length>0?L:void 0;if(Y&&J)return{providerID:Y,modelID:J}}return null},[c]),j=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const B=c[h];if(B?.info.role==="assistant"&&zt(B).total>0)return B}return null},[c]),D=y??(()=>{const h=j?.info.model,B=h?.providerID??h?.providerId,g=h?.modelID??h?.modelId;return B&&g?{providerID:B,modelID:g}:null})()??(v?{providerID:v.providerId,modelID:v.modelId}:null)??(u&&f?{providerID:u,modelID:f}:null),p=(D?d.find(h=>h.id===D.providerID):void 0)?.models.find(h=>h.id===D?.modelID),m=D?x(D.providerID,D.modelID):void 0,E=sn(p?.limit,"context")??m?.limit?.context??sn(b?.limit,"context")??0,z=j?zt(j):null,w=j?.info?.usage,R=w?Ks(w):z?.total??0,T=!i&&R>0&&E>0?Math.min(R/E*100,999):null,O=T!==null?`${rn(R)}/${rn(E)}`:null,N=T===null?"":T>=90?"text-[var(--status-error)]":T>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",M=T!==null&&O?{percentage:T,tokens:O,colorClass:N}:null;return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:l,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Show context usage for current conversation",title:"Context usage","aria-expanded":n,onClick:()=>s(h=>!h),style:{touchAction:"manipulation"},children:t.jsx(Jn,{percentage:M?.percentage??0})}),t.jsx(Ja,{open:n,onClose:()=>s(!1),anchorRef:l,contextDisplay:M})]})}),Za=10,an=380,eo=(e,n)=>e.title?.trim()||n,to=({session:e,meta:n,active:s,onSelect:r})=>{const a=Ws(e.id),i=Gs(e.id),l=a?.type??"idle",c=l==="busy"||l==="retry",d=!c&&i>0&&!s,u=qs(e.id,c),f=c&&u,b=Ys(e.time?.updated??e.time?.created??0);return t.jsxs("button",{type:"button",className:K("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",s&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:r,style:{touchAction:"manipulation"},children:[t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:K("block truncate typography-ui-label",s?"text-primary":"text-foreground"),children:eo(e,"Untitled Session")}),n?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:n}):null]}),c?t.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):d?t.jsx(Xs,{label:"Session complete"}):null,f?t.jsx(Js,{sessionId:e.id,running:c,className:"typography-micro"}):d?null:b?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:b}):null]})},no=({open:e,onClose:n,anchorRef:s})=>{const r=o.useRef(null),[a,i]=o.useState(e),[l,c]=o.useState(!1),{enabled:d}=St(),u=o.useRef(null),[f,b]=o.useState(null);o.useLayoutEffect(()=>{if(!e||!d||!a)return;const p=()=>{const z=s.current?.getBoundingClientRect(),w=u.current?.getBoundingClientRect();if(!z||!w){b(null);return}const R=z.left-w.left;b(Math.min(Math.max(R,8),Math.max(8,w.width-an-8)))};p();const m=u.current;if(typeof ResizeObserver>"u"||!m)return;const E=new ResizeObserver(p);return E.observe(m),()=>E.disconnect()},[s,d,e,a]);const x=d&&f!==null,v=me(p=>p.currentSessionId),y=me(p=>p.setCurrentSession),j=Rn(p=>p.setActiveProjectIdOnly),D=Vs(e||a,{maxParents:Za});o.useEffect(()=>{if(e){i(!0),c(!1);return}if(!a)return;c(!0);const p=window.setTimeout(()=>{i(!1),c(!1)},140);return()=>window.clearTimeout(p)},[e,a]),o.useEffect(()=>{if(!e)return;const p=m=>{m.key==="Escape"&&n()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n,e]),o.useEffect(()=>{if(!e)return;const p=m=>{const E=m.target;if(!(E instanceof Node)){n();return}r.current?.contains(E)||s.current?.contains(E)||n()};return document.addEventListener("pointerdown",p,!0),()=>document.removeEventListener("pointerdown",p,!0)},[s,n,e]);const U=o.useCallback(p=>{y(p.id,jt(p)),n()},[n,y]);return a?t.jsxs("div",{ref:u,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[t.jsx("div",{ref:r,role:"dialog","aria-label":"Open session switcher",className:K("flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",x?"absolute origin-top-left":"mx-3 mt-2",l?"pointer-events-none":"pointer-events-auto"),style:{animation:`${l?"session-switcher-out":"session-switcher-in"} ${l?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...x?{top:8,left:f??8,width:`min(${an}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:D.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):D.map(p=>{const m=p.node.session,E=[p.secondaryMeta?.projectLabel,p.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(to,{session:m,meta:E,active:m.id===v,onSelect:()=>{p.projectId&&j(p.projectId),U(m)}},m.id)})})}),t.jsx("style",{children:`
|
|
12
|
-
@keyframes session-switcher-in {
|
|
13
|
-
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
14
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
15
|
-
}
|
|
16
|
-
@keyframes session-switcher-out {
|
|
17
|
-
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
18
|
-
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
19
|
-
}
|
|
20
|
-
`})]}):null},so=({onOpenSessions:e,onOpenWorkspace:n,compactTitle:s=!1})=>{const[r,a]=o.useState(!1),[i,l]=o.useState(!1),c=o.useRef(null),d=En(m=>m.currentDirectory),u=me(m=>m.currentSessionId),b=me(o.useCallback(m=>u?m.getDirectoryForSession(u):null,[u]))||d,x=Qs(u),v=me(m=>!!m.newSessionDraft?.open),j=x?.title?.trim()||(u?"Untitled session":"New session");o.useEffect(()=>{a(!1),l(!1)},[u,b]);const D=o.useCallback(()=>{a(!1),l(!1),e()},[e]),U=o.useCallback(m=>{a(E=>{const z=typeof m=="function"?m(E):m;return z&&l(!1),z})},[]),p=o.useCallback(()=>{l(m=>{const E=!m;return E&&a(!1),E})},[]);return t.jsxs(t.Fragment,{children:[t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open sessions and projects",onClick:D,style:{touchAction:"manipulation"},children:t.jsx(W,{name:"list-unordered",className:"size-5"})}),t.jsx("button",{ref:c,type:"button",className:K("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",s?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":i,onClick:p,style:{touchAction:"manipulation"},children:t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:j}),t.jsx(W,{name:"arrow-down-s",className:K("size-4 shrink-0 text-muted-foreground transition-transform duration-150",i&&"rotate-180")})]})}),s?t.jsx("div",{className:"min-w-0 flex-1"}):null,t.jsx(Qa,{open:r,onOpenChange:U,currentSessionId:u,effectiveDirectory:b,isNewSessionDraftOpen:v}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open workspace panel",onClick:()=>{a(!1),l(!1),n()},style:{touchAction:"manipulation"},children:t.jsx(W,{name:"layout-right",className:"size-5"})})]})}),t.jsx(no,{open:i,onClose:()=>l(!1),anchorRef:c})]})},ro=({onActiveConnectionDeleted:e,onConnect:n})=>{const s=Kn(n),{connections:r,isBusy:a,isPasswordBusy:i,error:l,pendingConnection:c,connect:d,submitPassword:u,cancelPassword:f,saveConnection:b,removeConnection:x,setError:v}=s,[y,j]=o.useState(null),D=y?r.find($=>$.id===y)??null:null,[U,p]=o.useState(null),[m,E]=o.useState(""),[z,w]=o.useState(""),[R,T]=o.useState(""),[O,N]=o.useState(""),[M,h]=o.useState(!1),[B,g]=o.useState(!1),[C,L]=o.useState(!1),[Y,J]=o.useState(null),X=o.useRef(null),I=o.useMemo(()=>kt(),[]),[q,V]=o.useState(!1),[k,S]=o.useState(null),A=o.useCallback(()=>{j(null),E(""),w(""),T(""),v(null),V(!1)},[v]),F=o.useCallback($=>{$.preventDefault(),b({id:y??void 0,url:m,label:z,clientToken:R}).then(Q=>{Q&&A()})},[R,y,z,A,b,m]),Z=o.useCallback(async()=>{if(X.current)return;v(null),h(!0);const $=new AbortController;X.current=$;try{const Q=await qn({signal:$.signal});switch(X.current===$&&(X.current=null,h(!1)),Q.status){case"ok":E(Q.url),Q.label&&w(Q.label),Q.clientToken&&T(Q.clientToken),V(!0);break;case"pairing":g(!0),await s.redeemPairingConnection(Q.pairing);break;case"permission-denied":v("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":v("That QR code is not an PiChamber connection code.");break;case"unsupported":v("QR scanning is only available in the installed mobile app.");break;case"failed":v("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{g(!1),X.current===$&&(X.current=null,h(!1))}},[s,v]);o.useEffect(()=>()=>X.current?.abort(),[]);const ee=o.useCallback($=>{$.preventDefault(),u(O)},[O,u]),ue=o.useCallback(()=>{N(""),f()},[f]),H=o.useCallback(async()=>{if(!C){J(null),L(!0);try{const $=await cs();J($==="copied"?"Diagnostics copied to the clipboard.":$==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{J("Diagnostics export was cancelled or unavailable.")}finally{L(!1)}}},[C]),ae=o.useCallback($=>{p(Q=>Q===$?null:$)},[]),Pe=o.useCallback($=>{p(null),y===$&&A();const Q=r.length===1;x($).then(he=>{he&&(Q||tn(he))&&e()})},[r.length,y,e,x,A]),je=He;return c?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:ee,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(W,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some($=>$.kind==="direct")?ye(c):"via PiChamber Relay"})]})]}),t.jsx("input",{...Le,value:O,onChange:$=>N($.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:je}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(ne,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!O.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:ue,children:"Use another server"})]})})}):t.jsxs(t.Fragment,{children:[M?t.jsx(Yn,{onCancel:()=>X.current?.abort()}):null,B?t.jsx(Xn,{}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map($=>{const Q=U===$.id,he=tn($),Ie=k===$.id,ct=Ie?"Connecting...":he?We()?"Connected · Private relay":"Connected · Local network":$.candidates.some(Be=>Be.kind==="direct")?ye($):"via PiChamber Relay";return t.jsxs("div",{className:K("flex items-center border-b border-border/70 transition-colors last:border-b-0",Q&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{he||(S($.id),d({id:$.id,candidates:$.candidates,clientToken:$.clientToken,label:$.label}).finally(()=>S(null)))},disabled:a&&!Ie||Q,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(W,{name:"server",className:"size-[18px]"}),he?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:$.label}),t.jsx("span",{className:K("block truncate typography-small",he&&!Ie?"text-[var(--status-success)]":"text-muted-foreground"),children:ct})]}),Ie?t.jsx(W,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[Q?t.jsxs("button",{type:"button","aria-label":`Confirm deleting ${$.label}`,className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>Pe($.id),style:{touchAction:"manipulation"},children:[t.jsx(W,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):$.candidates.some(Be=>Be.kind==="direct")?t.jsx("button",{type:"button","aria-label":"Edit",className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{j($.id),E(ye($)),w($.label),T($.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:t.jsx(W,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":Q?`Keep ${$.label}`:`Delete ${$.label}`,className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>ae($.id),style:{touchAction:"manipulation"},children:t.jsx(W,{name:Q?"close":"delete-bin",className:"size-[18px]"})})]})]},$.id)})}):t.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:"No saved connections yet."}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs(ne,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{H()},disabled:C,children:[t.jsx(W,{name:"download",className:"size-[18px]"}),C?"Preparing diagnostics…":"Export diagnostics"]}),Y?t.jsx("p",{className:"px-1 text-center typography-small text-muted-foreground",children:Y}):null]}),!q&&!D?t.jsxs("div",{className:"space-y-2",children:[I?t.jsxs(ne,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{Z()},disabled:M,children:[t.jsx(W,{name:"scan-2",className:K("size-[18px]",M&&"animate-pulse")}),"Scan QR code"]}):null,t.jsxs(ne,{type:"button",variant:I?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),V(!0)},children:[t.jsx(W,{name:"add",className:"size-[18px]"}),"Add by address"]}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:F,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:D?"Edit instance":"Add instance"}),t.jsx(ne,{type:"button",variant:"ghost",size:"xs",onClick:A,children:"Cancel"})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Server URL"}),t.jsx("input",{...Le,value:m,onChange:$=>E($.target.value),placeholder:"http://192.168.1.74:2606",type:"url",inputMode:"url",autoCapitalize:"none",className:je})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Name"}),t.jsx("input",{value:z,onChange:$=>w($.target.value),placeholder:"Optional display name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:je})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Client token"}),t.jsx("input",{...Le,value:R,onChange:$=>T($.target.value),placeholder:"Paste access token",autoCapitalize:"none",className:je}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."})]}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(ne,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:D?"Save changes":"Save instance"})]})]})})})]})},ao=16,oo=320,on="cubic-bezier(0.22, 1, 0.36, 1)",ln=({open:e,onOpenChange:n,variant:s="drawer"})=>{const r=o.useCallback(()=>n(!1),[n]),a=me(y=>y.openNewSessionDraft),i=le(y=>y.setActiveMainTab),l=le(y=>y.setSessionSwitcherOpen),[c,d]=o.useState(!1),u=o.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);o.useEffect(()=>{if(s!=="sidebar"){if(e){const y=window.setTimeout(()=>d(!0),u?0:ao);return()=>window.clearTimeout(y)}d(!1)}},[e,u,s]),o.useEffect(()=>{if(s==="sidebar"||!e)return;const y=document.body.style.overflow;document.body.style.overflow="hidden";const j=D=>{D.key==="Escape"&&r()};return document.addEventListener("keydown",j),()=>{document.body.style.overflow=y,document.removeEventListener("keydown",j)}},[r,e,s]);const f=o.useCallback(()=>{le.getState().closeMainSurfaces(),i("chat"),l(!1),a(),r()},[r,a,i,l]),b=s==="sidebar",x=t.jsx(vs,{mobileVariant:!b,isVisible:!0,allowReselect:!0,onSessionSelected:b?void 0:r,onNavigateAway:b?void 0:r});if(s==="sidebar")return t.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:x});if(typeof document>"u")return null;const v=u?0:oo;return ze.createPortal(t.jsxs("div",{className:"fixed inset-0 z-50","aria-hidden":!e,style:{pointerEvents:e?"auto":"none"},children:[t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:r,tabIndex:e?0:-1,style:{opacity:c?1:0,transition:`opacity ${v}ms ${on}`}}),t.jsx("div",{className:K("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:c?"none":"translateX(-100%)",transition:v?`transform ${v}ms ${on}`:"none"},children:x}),t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 z-20 flex w-[28%] items-end justify-center",style:{paddingBottom:"calc(1rem + var(--oc-safe-area-bottom, 0px))"},children:e?t.jsx(ne,{type:"button",variant:"outline",size:"lg",className:"pointer-events-auto size-12 rounded-full p-0 [corner-shape:round] supports-[corner-shape:squircle]:rounded-full",onClick:f,"aria-label":"New session",children:t.jsx(W,{name:"chat-new",className:"size-5"})}):null})]}),document.body)},cn="mobile-surface-root",ht=16,Je=200,io=()=>{if(typeof document>"u")return null;let e=document.getElementById(cn);return e||(e=document.createElement("div"),e.id=cn,document.body.appendChild(e)),e},gt=({open:e,onClose:n,title:s,subtitle:r,trailing:a,disableEscapeDismiss:i=!1,headerless:l=!1,noHeaderBorder:c=!1,ariaLabel:d,variant:u="fullscreen",dialogAlign:f="chat",children:b})=>{const x=o.useRef(null),[v,y]=o.useState(!1),[j,D]=o.useState(!1),U=o.useRef(null),p=o.useRef(null),m=o.useRef(n);if(o.useEffect(()=>{m.current=n},[n]),typeof document<"u"&&!x.current&&(x.current=io()),o.useEffect(()=>{if(!e){y(!1);return}const w=window.setTimeout(()=>y(!0),ht);return()=>window.clearTimeout(w)},[e]),o.useEffect(()=>{if(!e){D(!1);return}const w=window.setTimeout(()=>D(!0),ht+Je+80);return()=>window.clearTimeout(w)},[e]),o.useEffect(()=>{if(!e)return;const w=document.body.style.overflow;p.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const R=()=>{const N=U.current;if(!N)return;(N.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??N).focus({preventScroll:!0})},T=window.setTimeout(R,ht),O=N=>{if(N.key==="Escape"&&!i){m.current();return}if(N.key!=="Tab")return;const M=U.current;if(!M)return;const h=Array.from(M.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(L=>!L.hasAttribute("disabled")&&L.getAttribute("aria-hidden")!=="true");if(h.length===0){N.preventDefault(),M.focus({preventScroll:!0});return}const B=h[0],g=h[h.length-1],C=document.activeElement;N.shiftKey&&C===B?(N.preventDefault(),g.focus({preventScroll:!0})):!N.shiftKey&&C===g&&(N.preventDefault(),B.focus({preventScroll:!0}))};return document.addEventListener("keydown",O),()=>{window.clearTimeout(T),document.body.style.overflow=w,document.removeEventListener("keydown",O),p.current?.focus?.({preventScroll:!0}),p.current=null}},[i,e]),!e||!x.current)return null;const E=u==="dialog",z=t.jsxs("section",{ref:U,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:K("flex flex-col bg-background text-foreground",E?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface fixed inset-0 z-50"),style:E?{opacity:v?1:0,transform:v?"none":"scale(0.97)",transition:`opacity ${Je}ms ease-out, transform ${Je}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:`transform ${Je}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{v&&w.target===w.currentTarget&&w.propertyName==="transform"&&D(!0)},children:[l?null:t.jsxs("header",{className:K("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:n,style:{touchAction:"manipulation"},children:t.jsx(W,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,r?typeof r=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:r}):r:null]}),a?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:a}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:b}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return E?ze.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:v?1:0,paddingLeft:f==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:f==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:n,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:w=>w.stopPropagation(),children:z})}),x.current):ze.createPortal(z,x.current)},Qn={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},lo=Qn.M;function co(e){const n=e.index?.trim(),s=e.working_dir?.trim();return n&&n!=="?"?n.charAt(0):s?s.charAt(0):n?.charAt(0)||s?.charAt(0)||"M"}function uo(e){const n=co(e);return Qn[n]??lo}const fo=o.memo(function({file:n,actionLabel:s,actionSymbol:r,onAction:a,onViewDiff:i,onRevert:l,isReverting:c,stats:d,rowPaddingClassName:u,indentPx:f=0,actionAtStart:b=!1,showRevert:x=!0}){const v=Ce.useMemo(()=>uo(n),[n]),y=v.description,j=d?.insertions??0,D=d?.deletions??0,U=Ce.useCallback(z=>{z.key===" "?(z.preventDefault(),a()):z.key==="Enter"&&(z.preventDefault(),i())},[a,i]),p=Ce.useCallback(z=>{z.preventDefault(),z.stopPropagation(),a()},[a]),m=Ce.useCallback(z=>{z.preventDefault(),z.stopPropagation(),l()},[l]),E=t.jsx("button",{type:"button",onClick:p,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":s,title:s,children:r});return t.jsxs("div",{className:`group flex items-center gap-2 py-1.5 cursor-pointer ${u??"px-3"}`,role:"button",tabIndex:0,onClick:i,onKeyDown:U,style:f>0?{paddingLeft:`${f}px`}:void 0,children:[b?E:null,t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:v.color},title:y,"aria-label":y,children:v.code}),t.jsx(Pn,{filePath:n.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const z=n.path.lastIndexOf("/");if(z===-1)return t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:n.path,children:n.path});const w=n.path.slice(0,z),R=n.path.slice(z);return t.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:n.path,children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:w}),t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[t.jsx("span",{className:"text-muted-foreground",children:"/"}),t.jsx("span",{className:"text-foreground",children:R.slice(1)})]})]})})(),t.jsxs("span",{className:"shrink-0 typography-micro",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",j]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",D]})]}),x?t.jsxs(Zs,{children:[t.jsx(er,{asChild:!0,children:t.jsx("button",{type:"button",onClick:m,disabled:c,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${n.path}`,children:c?t.jsx(W,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(W,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(tr,{sideOffset:8,children:"Revert changes"})]}):null,b?null:E]})}),dn=14,Zn=e=>e.replace(/\\/g,"/").replace(/^\/+/,"").trim(),un=(e,n)=>({id:`dir:${e}`,path:e,name:n,children:new Map,directFiles:[],files:[]}),po=e=>{const n=un("","");for(const s of e){const r=Zn(s.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let l=n;if(l.files.push(s),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const u=l.children.get(d);if(u){u.files.push(s),l=u;continue}const f=un(c,d);f.files.push(s),l.children.set(d,f),l=f}}l.directFiles.push(s)}return n},mo=(e,n)=>{const s=[],r=(a,i)=>{const l=Array.from(a.children.values()).sort((d,u)=>d.path.localeCompare(u.path));for(const d of l)s.push({key:d.id,kind:"directory",depth:i,directory:d}),n.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,u)=>d.path.localeCompare(u.path));for(const d of c)s.push({key:`file:${Zn(d.path)}`,kind:"file",depth:i,file:d})};return r(e,0),s},ho=1e3,fn=34,yt=30,Qe="pl-0 pr-2",bt=(e,n)=>`${e} ${n}`,go=({groups:e,diffStats:n,revertingPaths:s,isRevertingAll:r=!1,headerBackgroundClassName:a="bg-sidebar",onVisiblePathsChange:i,onRevertAll:l,onRevertDirectory:c})=>{const d=o.useRef(null),f=le(k=>k.gitChangesViewMode)==="tree",b=o.useMemo(()=>e.filter(k=>k.entries.length>0),[e]),[x,v]=o.useState(new Set),[y,j]=o.useState(new Set),[D,U]=o.useState(!1),[p,m]=o.useState(null),E=o.useMemo(()=>b.map(k=>po(k.entries)),[b]),z=o.useMemo(()=>{const k=[];return b.forEach((S,A)=>{Array.from(E[A]?.children.values()??[]).forEach(F=>{k.push(bt(S.id,F.path))})}),k},[E,b]);o.useEffect(()=>{f&&j(k=>{const S=new Set,A=new Set(z);return k.forEach(F=>{(F.slice(F.indexOf(" ")+1).includes("/")||A.has(F))&&S.add(F)}),z.forEach(F=>S.add(F)),S})},[f,z]);const w=o.useMemo(()=>{const k=[];return b.forEach((S,A)=>{if(k.push({type:"header",key:`header:${S.id}`,groupIndex:A}),!x.has(S.id)){if(f){const F=new Set;y.forEach(ee=>{ee.startsWith(`${S.id} `)&&F.add(ee.slice(S.id.length+1))}),mo(E[A],F).forEach(ee=>{ee.kind==="file"?k.push({type:"file",key:`${S.id}:${ee.key}`,groupIndex:A,file:ee.file,depth:ee.depth}):k.push({type:"directory",key:`${S.id}:${ee.key}`,groupIndex:A,directory:ee.directory,depth:ee.depth})});return}S.entries.forEach(F=>{k.push({type:"file",key:`${S.id}:file:${F.path}`,groupIndex:A,file:F,depth:0})})}}),l&&b.length>0&&k.push({type:"revert-all",key:"revert-all"}),k},[x,y,f,l,E,b]),R=w.length,T=R>=ho,O=Gr({count:R,enabled:T,getScrollElement:()=>d.current,estimateSize:()=>fn,overscan:12,getItemKey:k=>w[k]?.key??k}),N=O.getVirtualItems(),M=o.useMemo(()=>{if(!T)return 0;const k=d.current?.scrollTop??0;return N.find(A=>A.end>k)?.index??0},[T,N,d]);o.useEffect(()=>{if(!i)return;const k=S=>S&&S.type==="file"?S.file.path:null;if(R===0){i([]);return}if(!T){const S=[];for(const A of w)if(A.type==="file"&&(S.push(A.file.path),S.length>=yt))break;i(S);return}i(w.slice(M,M+Math.ceil((d.current?.clientHeight??0)/fn)+yt).map(S=>k(S)).filter(S=>!!S).slice(0,yt))},[i,R,w,T,M]);const h=o.useCallback(k=>{v(S=>{const A=new Set(S);return A.has(k)?A.delete(k):A.add(k),A})},[]),B=o.useCallback((k,S)=>{j(A=>{const F=new Set(A),Z=bt(k,S);return F.has(Z)?F.delete(Z):F.add(Z),F})},[]),g=o.useMemo(()=>{const k=new Set;return b.forEach(S=>S.entries.forEach(A=>k.add(A.path))),Array.from(k)},[b]),C=g.length,L=p?r||p.paths.some(k=>s.has(k)):!1,Y=o.useCallback(async()=>{!l||r||g.length===0||(await l(g),U(!1))},[g,r,l]),J=o.useCallback(async()=>{!c||!p||L||(await c(p.paths),m(null))},[L,c,p]),X=o.useCallback((k,S)=>{const A=x.has(k.id),F=k.entries.length;return t.jsxs("div",{className:K("sticky top-0 z-10 flex items-center gap-2 py-2",a,Qe,!S&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>k.onActionAll(k.entries.map(Z=>Z.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":k.actionAllLabel,title:k.actionAllLabel,children:k.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>h(k.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!A,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:k.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),t.jsx(W,{name:"arrow-down-s",className:K("size-3.5 shrink-0 text-muted-foreground transition-transform",A&&"-rotate-90")})]})]})},[x,a,h]),I=o.useCallback((k,S,A)=>{const F=y.has(bt(k.id,S.path)),Z=S.files.map(ue=>ue.path),ee=r||Z.some(ue=>s.has(ue));return t.jsxs("div",{className:K("group flex items-center gap-2 py-1.5",Qe),style:{paddingLeft:`${A*dn}px`},children:[t.jsxs("button",{type:"button",onClick:()=>B(k.id,S.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":F?`Collapse directory ${S.path}`:`Expand directory ${S.path}`,children:[F?t.jsx(W,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(W,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:S.path,children:S.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:S.files.length})]}),k.showRevertActions!==!1&&c?t.jsx("button",{type:"button",onClick:()=>m({path:S.path,paths:Z,count:Z.length}),disabled:ee,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${S.path}`,title:"Revert folder changes",children:ee?t.jsx(W,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(W,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>k.onActionAll(S.files.map(ue=>ue.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":k.actionSymbol==="+"?`Stage all changes in ${S.path}`:`Unstage all changes in ${S.path}`,title:k.actionSymbol==="+"?`Stage all changes in ${S.path}`:`Unstage all changes in ${S.path}`,children:k.actionSymbol})]})},[y,r,c,s,B]),q=o.useCallback((k,S)=>{if(k.type==="revert-all")return t.jsx("div",{className:K("flex justify-end py-2",Qe),children:t.jsxs(ne,{variant:"ghost",size:"sm",onClick:()=>U(!0),disabled:r,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(W,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const A=b[k.groupIndex];if(!A)return null;if(k.type==="header")return X(A,S);if(k.type==="directory")return I(A,k.directory,k.depth);const F=k.file;return t.jsx(fo,{file:F,actionLabel:A.getActionLabel(F.path),actionSymbol:A.actionSymbol,onAction:()=>A.onActionFile(F.path),stats:n?.[F.path],onViewDiff:()=>A.onViewDiff(F.path),onRevert:()=>A.onRevertFile(F.path),isReverting:s.has(F.path)||r,rowPaddingClassName:Qe,indentPx:k.depth*dn,actionAtStart:!f,showRevert:A.showRevertActions!==!1})},[n,r,f,I,X,s,b]),V=o.useCallback(k=>{const S=w[k],A=w[k-1];return!S||!A||S.type!=="file"&&S.type!=="directory"||A.type!=="file"&&A.type!=="directory"?!1:A.groupIndex===S.groupIndex},[w]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[t.jsx(Ct,{ref:d,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:T?t.jsx("div",{style:{height:O.getTotalSize(),position:"relative"},children:N.map(k=>{const S=w[k.index];return S?t.jsx("div",{"data-index":k.index,ref:O.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${k.start}px)`},className:K(V(k.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:q(S,k.index===0)},S.key):null})}):t.jsx("div",{role:"list","aria-label":"Changed files",children:w.map((k,S)=>t.jsx("div",{className:K("relative",V(S)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:q(k,S===0)},k.key))})}),t.jsx(nr,{containerRef:d,disableHorizontal:!0})]}),t.jsx(Ot,{open:D,onOpenChange:k=>{!r&&!k&&U(!1)},children:t.jsxs($t,{className:"max-w-md",children:[t.jsxs(Ut,{children:[t.jsx(Bt,{children:"Revert all changes?"}),t.jsx(Ft,{children:C===1?`Revert ${C} changed file? This cannot be undone.`:`Revert ${C} changed files? This cannot be undone.`})]}),t.jsxs(Ht,{children:[t.jsx(ne,{variant:"outline",size:"sm",onClick:()=>U(!1),disabled:r,children:"Cancel"}),t.jsx(ne,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:r,children:r?"Reverting...":"Revert all"})]})]})}),t.jsx(Ot,{open:!!p,onOpenChange:k=>{!L&&!k&&m(null)},children:t.jsxs($t,{className:"max-w-md",children:[t.jsxs(Ut,{children:[t.jsx(Bt,{children:"Revert folder changes?"}),t.jsx(Ft,{children:p?p.count===1?`This will discard local changes in ${p.count} file under ${p.path}.`:`This will discard local changes in ${p.count} files under ${p.path}.`:null})]}),t.jsxs(Ht,{children:[t.jsx(ne,{variant:"outline",size:"sm",onClick:()=>m(null),disabled:L,children:"Cancel"}),t.jsx(ne,{variant:"destructive",size:"sm",onClick:()=>{J()},disabled:L||!p,children:L?"Reverting...":"Revert folder"})]})]})})]})},yo=ur(()=>ge(()=>import("./DiffView-d23o9CKP.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])).then(e=>({default:e.DiffView}))),bo=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),xo=e=>{const n=e.index?.trim();return!!(n&&n!=="?")},vo=e=>{const n=e.working_dir?.trim(),s=e.index?.trim();return!!(n||s==="?")},pn=(e,n)=>n?`${e}\0staged`:e,wo=({onClose:e,initialDiffPath:n,initialDiffStaged:s=!1})=>{const{git:r}=In(),a=bo(Nt()??null),i=sr(a||null),l=rr(a||null),c=ar(a||null),d=be(P=>P.setActiveDirectory),u=be(P=>P.ensureAll),f=be(P=>P.fetchStatus),b=be(P=>P.fetchBranches),x=be(P=>P.prefetchDiffs),v=be(P=>P.getDiff),y=be(P=>P.setDiff),[j,D]=o.useState(()=>n?{type:"diff",path:n,staged:s}:{type:"list"});o.useEffect(()=>{n&&D(P=>P.type==="diff"&&P.path===n&&P.staged===s?P:{type:"diff",path:n,staged:s})},[n,s]);const[U,p]=o.useState(null),[m,E]=o.useState(null),[z,w]=o.useState(""),[R,T]=o.useState(new Set),[O,N]=o.useState(!1),[M,h]=o.useState(!1),[B,g]=o.useState([]),[C,L]=o.useState([]),[Y,J]=o.useState([]),[X,I]=o.useState(null),[q,V]=o.useState(null),[k,S]=o.useState(0),A=o.useMemo(()=>{const P=i?.files??[],_=new Map;for(const G of P)_.set(G.path,G);return Array.from(_.values()).sort((G,te)=>G.path.localeCompare(te.path))},[i?.files]),F=o.useMemo(()=>A.filter(xo),[A]),Z=o.useMemo(()=>A.filter(vo),[A]),ee=o.useMemo(()=>{if(Y.length>0)return Y;const P=i?.tracking?.includes("/")?i.tracking.split("/")[0]:null;return P||X?[{name:P||"origin",fetchUrl:X??"",pushUrl:X??""}]:[]},[X,Y,i?.tracking]),ue=be(o.useCallback(P=>!a||j.type!=="diff"?null:P.directories.get(a)?.diffCache.get(pn(j.path,j.staged))??null,[a,j])),H=o.useMemo(()=>j.type!=="diff"?null:A.find(P=>P.path===j.path)??null,[A,j]),ae=o.useCallback(async(P=!0)=>{if(a)try{await Promise.all([f(a,r),b(a,r)])}catch(_){P&&se.error(_ instanceof Error?_.message:"Failed to refresh repository")}},[a,b,f,r]),Pe=o.useCallback(async()=>{if(!a){J([]),I(null);return}try{const[P,_]=await Promise.all([r.getRemotes(a).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(a).catch(()=>null):Promise.resolve(null)]);J(P),I(_)}catch{J([]),I(null)}},[a,r]);o.useEffect(()=>{a&&(d(a),u(a,r))},[a,u,r,d]),o.useEffect(()=>{Pe()},[Pe]),o.useEffect(()=>{if(!a||A.length===0)return;const P=Array.from(new Set([...F.map(G=>G.path),...C,...A.slice(0,20).map(G=>G.path)])).filter(Boolean);if(P.length===0)return;const _=window.setTimeout(()=>{x(a,r,P,{maxFiles:40})},120);return()=>window.clearTimeout(_)},[A,a,r,x,F,C]),o.useEffect(()=>{if(j.type!=="diff"){V(null);return}const P=pn(j.path,j.staged);if(!a||v(a,P)){V(null);return}let _=!1;const G=Ye();return V(null),r.getGitFileDiff(a,{path:j.path,staged:j.staged||void 0}).then(te=>{_||y(a,P,{original:te.original??"",modified:te.modified??"",isBinary:te.isBinary},G)}).catch(te=>{_||V(te instanceof Error?te.message:String(te))}),()=>{_=!0}},[a,k,v,r,j,y]);const je=async(P,_)=>{if(a){p(P);try{const G=te=>{const Ae=`${te.name}/`,ut=i?.tracking?.startsWith(Ae)?i.tracking.slice(Ae.length):void 0;return{remote:te.name,branch:ut,rebase:!0}};if(P==="fetch"){if(!_)throw new Error("No remote available");await r.gitFetch(a,{remote:_.name}),se.success(`Fetched from ${_.name}`)}else if(P==="sync"){if(!_)throw new Error("No remote available");await r.gitFetch(a,{remote:_.name});const te=await r.getGitStatus(a);if((te.behind??0)>0){if((te.files?.length??0)>0){se.error("Commit or stash your changes before syncing");return}await r.gitPull(a,G(_))}((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),se.success("Already up to date")}await ae(!1),await Pe()}catch(G){se.error(G instanceof Error?G.message:"Sync Changes failed")}finally{p(null)}}},$=o.useCallback(async(P,_)=>{if(!(!a||P.length===0))try{_==="stage"?P.length>1?await or(a,P):await ir(a,P[0]):P.length>1?await lr(a,P):await cr(a,P[0]),await ae(!1)}catch(G){se.error(G instanceof Error?G.message:_==="stage"?"Failed to stage changes":"Failed to unstage changes")}},[a,ae]),Q=o.useCallback((P,_=!1)=>{D({type:"diff",path:P,staged:_})},[]),he=o.useCallback(async P=>{if(a){T(_=>new Set(_).add(P));try{await r.revertGitFile(a,P),se.success(`Reverted ${P}`),await ae(!1)}catch(_){se.error(_ instanceof Error?_.message:"Failed to revert changes")}finally{T(_=>{const G=new Set(_);return G.delete(P),G})}}},[a,r,ae]),Ie=o.useCallback(async P=>{if(!a||P.length===0||O)return;const _=Array.from(new Set(P));N(!0),T(new Set(_));try{await Promise.all(_.map(G=>r.revertGitFile(a,G))),await ae(!1),se.success(_.length===1?`Reverted ${_.length} file`:`Reverted ${_.length} files`)}catch(G){se.error(G instanceof Error?G.message:"Failed to revert changes")}finally{T(new Set),N(!1)}},[a,r,O,ae]),ct=o.useCallback(P=>{const _=P.map(G=>G.trim()).filter(Boolean);if(_.length===0){g([]);return}w(G=>`${G.trim()}${G.trim()?`
|
|
21
|
-
|
|
22
|
-
`:""}${_.join(`
|
|
23
|
-
`)}`.trim()),g([])},[]),Be=o.useCallback(async()=>{if(!a)return;const P=F.map(_=>_.path).sort();if(P.length===0){se.error("Select at least one file to describe");return}h(!0);try{const{message:_}=await dr(a,P);w(_.subject?.trim()??""),g(Array.isArray(_.highlights)?_.highlights:[])}catch(_){se.error(_ instanceof Error?_.message:"Failed to generate commit message")}finally{h(!1)}},[a,F]),Mt=async(P={})=>{if(!a)return;if(!z.trim()){se.error("Enter a commit message");return}const _=F.map(G=>G.path).sort();if(_.length===0){se.error("Select at least one file to commit");return}E(P.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(a,z.trim(),{files:_}),se.success("Commit created"),w(""),g([]),P.pushAfter){const G=i?.tracking?.split("/")[0],te=ee.find(as=>as.name===G)??ee[0];if(!te)throw new Error("No remote available");p("sync");const Ae=`${te.name}/`,ut=i?.tracking?.startsWith(Ae)?i.tracking.slice(Ae.length):void 0;await r.gitFetch(a,{remote:te.name}),((await r.getGitStatus(a)).behind??0)>0&&await r.gitPull(a,{remote:te.name,branch:ut,rebase:!0}),((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),await ae(!1),await Pe()}else await ae(!1)}catch(G){se.error(G instanceof Error?G.message:"Failed to create commit")}finally{E(null),P.pushAfter&&p(null)}},rs=o.useMemo(()=>{const P=[];return F.length>0&&P.push({id:"staged",title:"Staged",entries:F,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:_=>`Unstage ${_}`,onActionFile:_=>{$([_],"unstage")},onActionAll:_=>{$(_,"unstage")},onViewDiff:_=>Q(_,!0),onRevertFile:he,showRevertActions:!1,accent:!0}),Z.length>0&&P.push({id:"unstaged",title:"Changes",entries:Z,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:_=>`Stage ${_}`,onActionFile:_=>{$([_],"stage")},onActionAll:_=>{$(_,"stage")},onViewDiff:_=>Q(_,!1),onRevertFile:he}),P},[he,Q,$,F,Z]),dt=P=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsx("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:t.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:i?.current||a||""})}),t.jsx("div",{className:"min-h-0 flex-1",children:P})]});return a?c&&l===null?dt(t.jsx(we,{loading:!0,message:"Checking repository..."})):l===!1?dt(t.jsx(o.Suspense,{fallback:t.jsx(we,{loading:!0,message:"Loading last turn changes..."}),children:t.jsx(yo,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):j.type==="diff"?t.jsx(ko,{path:j.path,diff:ue,fileExists:!!H,error:q,onBack:()=>D({type:"list"}),onRetry:()=>S(P=>P+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:e,style:{touchAction:"manipulation"},children:t.jsx(W,{name:"close",className:"size-4"})}):null,t.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:i?.current||a}),t.jsx(ws,{syncAction:U,remotes:ee,onFetch:P=>{je("fetch",P)},onSync:P=>{je("sync",P)},disabled:m!==null||c,aheadCount:i?.ahead??0,behindCount:i?.behind??0,trackingRemoteName:i?.tracking?.split("/")[0],hasUncommittedChanges:A.length>0})]}),A.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-3 pt-2",children:t.jsx(go,{groups:rs,diffStats:i?.diffStats,revertingPaths:R,onRevertAll:Ie,isRevertingAll:O,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:L})}),t.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:t.jsx(qr,{stagedCount:F.length,commitMessage:z,onCommitMessageChange:w,generatedHighlights:B,onInsertHighlights:ct,onGenerateMessage:Be,isGeneratingMessage:M,onCommit:()=>{Mt({pushAfter:!1})},onCommitAndPush:()=>{Mt({pushAfter:!0})},commitAction:m,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(we,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):dt(t.jsx(we,{message:"Select a session or directory to view Git status"}))},we=({message:e,description:n,loading:s=!1,icon:r=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[s?t.jsx(W,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,r?t.jsx(W,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e}),n?t.jsx("p",{className:"typography-meta text-muted-foreground",children:n}):null]})}),ko=({path:e,diff:n,fileExists:s,error:r,onBack:a,onRetry:i})=>{const l=o.useMemo(()=>fr(e)||"text",[e]);return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:a,children:t.jsx(W,{name:"arrow-left",className:"size-4"})}),t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:e})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s?r?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:r}),t.jsx(ne,{type:"button",size:"sm",variant:"outline",onClick:i,children:"Retry"})]})}):n?n.isBinary?t.jsx(we,{icon:!0,message:"Content of this file cannot be viewed."}):pr(e)?t.jsx(we,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):t.jsx(Ct,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Yr,{original:n.original,modified:n.modified,language:l,fileName:e,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(we,{loading:!0,message:"Loading diff..."}):t.jsx(we,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},ce=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),_e=e=>{const n=ce(e);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},es=e=>{const n=ce(e);if(!n||n==="/")return null;const s=n.lastIndexOf("/");if(s<0)return null;if(s===0)return"/";const r=n.slice(0,s);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},mn=(e,n)=>{const s=ce(e),r=ce(n);return!s||!r?!1:s===r||s.startsWith(`${r}/`)},hn=(e,n)=>{const s=ce(e);if(!s)return ce(n);if(s.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(s))return s;const r=ce(n);return r?`${r}/${s}`:s},jo=(e,n)=>{const s=ce(e),r=ce(n);if(!s||s===r)return!1;const a=es(s);return a?r&&mn(s,r)?mn(a,r):!0:!1},So=o.lazy(()=>ge(()=>import("./FilesView-DIDB-xK7.js"),__vite__mapDeps([119,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,111,112,113,120,121,122,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,123,124,116,117,125,126,114,115])).then(e=>({default:e.FilesView}))),Co=(e,n)=>{const s=ce(e),r=ce(n);return!r||s===r?_e(s):s.startsWith(`${r}/`)?s.slice(r.length+1):s},No=e=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)return"";if(e<1024)return`${e} B`;const n=["KB","MB","GB"];let s=e/1024;for(const r of n){if(s<1024||r===n[n.length-1])return`${s.toFixed(s>=10?0:1)} ${r}`;s/=1024}return""},Eo=({onClose:e})=>{const{files:n}=In(),s=ds(g=>g.setSelectedPath),r=ce(Nt()??null),[a,i]=o.useState(()=>({type:"browser",directory:r})),[l,c]=o.useState([]),[d,u]=o.useState(!1),[f,b]=o.useState(null),[x,v]=o.useState(""),[y,j]=o.useState([]),[D,U]=o.useState(!1),p=o.useRef(0);o.useEffect(()=>{r&&i(g=>g.type==="browser"&&g.directory?g:{type:"browser",directory:r})},[r]);const m=a.type==="browser"?a.directory:a.returnDirectory,E=o.useCallback(async g=>{if(!g)return;const C=p.current+1;p.current=C,u(!0),b(null);try{const L=await n.listDirectory(g);if(p.current!==C)return;c(L.entries.slice().sort((J,X)=>J.isDirectory!==X.isDirectory?J.isDirectory?-1:1:J.name.localeCompare(X.name)));const Y=ce(L.directory);Y&&Y!==ce(g)&&i(J=>J.type==="browser"&&J.directory!==Y?{type:"browser",directory:Y}:J)}catch(L){if(p.current!==C)return;c([]),b(L instanceof Error?L.message:"Failed to load files")}finally{p.current===C&&u(!1)}},[n]);o.useEffect(()=>{a.type==="browser"&&E(a.directory)},[E,a]),o.useEffect(()=>{if(a.type!=="browser")return;const g=x.trim();if(!g){j([]),U(!1);return}let C=!1;const L=window.setTimeout(()=>{U(!0),n.search({directory:a.directory,query:g,maxResults:40}).then(Y=>{C||j(Y)}).catch(()=>{C||j([])}).finally(()=>{C||U(!1)})},250);return()=>{C=!0,window.clearTimeout(L)}},[n,x,a]);const z=g=>{v(""),i({type:"browser",directory:g})},w=g=>{s(r,g),i({type:"file",path:g,returnDirectory:m||r})},R=le(g=>g.pendingFileFocusPath),T=le(g=>g.pendingFileNavigation);if(o.useEffect(()=>{const g=ce(T?.path??R??"");!g||!r||g!==r&&!g.startsWith(`${r}/`)||(s(r,g),i({type:"file",path:g,returnDirectory:r}),R&&le.getState().setPendingFileFocusPath(null))},[R,T,r,s]),!r)return t.jsx(Ve,{message:"Select a project to browse files."});if(a.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:()=>i({type:"browser",directory:a.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(Vt,{className:"size-4"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:_e(a.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(pe,{children:t.jsx(o.Suspense,{fallback:t.jsx(Ve,{loading:!0,message:"Loading..."}),children:t.jsx(So,{mode:"editor-only"})})})})]});const O=a.directory===r?"Project files":_e(a.directory),N=x.trim()?y:[],M=jo(a.directory,r)?es(a.directory):null,h=!!M&&!x.trim(),B=M===r?"Project files":_e(M??"");return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Xr,{className:"size-4"})}):null,h&&M?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":`Back to ${_e(M)}`,onClick:()=>z(M),style:{touchAction:"manipulation"},children:t.jsx(Vt,{className:"size-4"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:O})}),t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Refresh files",onClick:()=>{E(a.directory)},style:{touchAction:"manipulation"},children:t.jsx(Jr,{className:K("size-4",d&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-3 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(Qr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(mr,{value:x,onChange:g=>v(g.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),t.jsx(Ct,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:f?t.jsx(Ve,{message:f}):x.trim()?t.jsx(To,{results:N,isSearching:D,onOpenFile:w}):t.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[h&&M?t.jsxs("button",{type:"button",className:An,"aria-label":`Up one level to ${B}`,onClick:()=>z(M),style:{touchAction:"manipulation"},children:[t.jsx(W,{name:"arrow-left",className:K(vt(!0),"text-muted-foreground")}),t.jsx("span",{className:K(Dn(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,l.length===0&&!d?t.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,l.map(g=>t.jsx(ts,{name:g.name,path:g.path,directory:g.isDirectory,meta:g.isDirectory?void 0:No(g.size),onClick:()=>g.isDirectory?z(hn(g.path,a.directory||r)):w(hn(g.path,a.directory||r))},g.path))]})})]})},ts=({name:e,path:n,directory:s,meta:r,onClick:a})=>t.jsxs("button",{type:"button",className:An,onClick:a,style:{touchAction:"manipulation"},children:[s?t.jsx(ta,{className:K(vt(!0),"text-primary/80")}):t.jsx(Pn,{filePath:n,className:vt(!0)}),t.jsx("span",{className:K(Dn(!0),"flex-1 text-foreground"),children:e}),r?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:r}):null,s?t.jsx(na,{className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),To=({results:e,isSearching:n,onOpenFile:s})=>{const r=ce(Nt()??null);return n?t.jsx(Ve,{loading:!0,message:"Loading..."}):e.length===0?t.jsx(Ve,{message:"No files found."}):t.jsx("div",{className:"flex w-full min-w-0 flex-col",children:e.map(a=>t.jsx(ts,{name:_e(a.path),path:a.path,directory:!1,meta:Co(a.path,r),onClick:()=>s(a.path)},a.path))})},Ve=({message:e,loading:n=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[n?t.jsx(Zr,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ea,{className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),gn="mobile-surface-root",Ro=16,yn=320,bn="cubic-bezier(0.22, 1, 0.36, 1)",Po=[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal"},{id:"notes",label:"Notes",icon:"sticky-note"}],xn=({open:e,onClose:n,tab:s,onTabChange:r,pendingChangesDiff:a,variant:i="drawer"})=>{const l=o.useRef(null),[c,d]=o.useState(!1),[u,f]=o.useState(e),b=o.useRef(n);o.useEffect(()=>{b.current=n},[n]);const x=o.useRef(s);o.useEffect(()=>{x.current=s},[s]);const v=o.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[y,j]=o.useState(()=>new Set);if(o.useEffect(()=>{e&&j(m=>{if(m.has(s))return m;const E=new Set(m);return E.add(s),E})},[e,s]),typeof document<"u"&&!l.current){let m=document.getElementById(gn);m||(m=document.createElement("div"),m.id=gn,document.body.appendChild(m)),l.current=m}if(o.useEffect(()=>{if(e){f(!0);const E=window.setTimeout(()=>d(!0),v?0:Ro);return()=>window.clearTimeout(E)}d(!1);const m=window.setTimeout(()=>f(!1),yn+40);return()=>window.clearTimeout(m)},[e,v]),o.useEffect(()=>{if(!e)return;const m=document.body.style.overflow;i==="drawer"&&(document.body.style.overflow="hidden");const E=z=>{z.key==="Escape"&&x.current!=="terminal"&&b.current()};return document.addEventListener("keydown",E),()=>{i==="drawer"&&(document.body.style.overflow=m),document.removeEventListener("keydown",E)}},[e,i]),i==="drawer"&&!l.current)return null;const D=v?0:yn,U=t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",role:"tablist","aria-label":"Workspace",children:Po.map(m=>{const E=s===m.id;return t.jsxs("button",{type:"button",role:"tab","aria-selected":E,onClick:()=>r(m.id),className:K("flex min-w-0 flex-1 items-center justify-center gap-1 rounded-lg px-1.5 py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",E?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(W,{name:m.icon,className:"size-4 shrink-0"}),t.jsx("span",{className:"truncate",children:m.label})]},m.id)})}),p=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center px-2",children:U}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y.has("changes")?t.jsx("div",{className:K("h-full",s!=="changes"&&"hidden"),children:t.jsx(pe,{children:t.jsx(wo,{initialDiffPath:a?.path??null,initialDiffStaged:a?.staged===!0})})},a?`changes:${a.path}:${a.staged}`:"changes"):null,y.has("files")?t.jsx("div",{className:K("h-full",s!=="files"&&"hidden"),children:t.jsx(pe,{children:t.jsx(Eo,{})})}):null,y.has("terminal")?t.jsx("div",{className:K("h-full",s!=="terminal"&&"hidden"),children:t.jsx(pe,{children:t.jsx(ks,{visible:e&&s==="terminal"})})}):null,y.has("notes")?t.jsx("div",{className:K("h-full",s!=="notes"&&"hidden"),children:t.jsx(pe,{children:t.jsx(js,{onActionComplete:n})})}):null]})]});return i==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:p}):ze.createPortal(t.jsxs("div",{className:"fixed inset-0 z-50","aria-hidden":!e,style:{pointerEvents:e?"auto":"none",visibility:u?"visible":"hidden"},children:[t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:n,tabIndex:e?0:-1,style:{opacity:c?1:0,transition:D?`opacity ${D}ms ${bn}`:"none"}}),t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":"Open workspace panel",className:"oc-keyboard-inset-surface absolute inset-y-0 right-0 z-10 flex h-full w-[80%] max-w-[80%] flex-col bg-sidebar",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:c?"none":"translateX(100%)",transition:D?`transform ${D}ms ${bn}`:"none"},children:p})]}),l.current)},Xe=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",Io=()=>{o.useEffect(()=>{if(!Xe())return;let e=!1;const n=[],s=document.documentElement;s.classList.add("oc-capacitor-app"),window.Capacitor?.getPlatform?.()==="android"&&s.classList.add("oc-platform-android"),n.push(hr());const a=i=>{s.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(i))}px`)};return ge(()=>import("./vendor-capacitor-status-bar-B-N0EOVk.js"),__vite__mapDeps([127,128])).then(async({StatusBar:i,Style:l})=>{if(e)return;const c=window.Capacitor?.getPlatform?.(),d=async()=>{if(c==="android"){const x=document.documentElement.classList.contains("dark"),v=(x?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(x?"#171515":"#fffdf4");await i.setOverlaysWebView({overlay:!1}).catch(()=>{}),await i.setBackgroundColor({color:v}).catch(()=>{}),await i.setStyle({style:x?l.Dark:l.Light}).catch(()=>{}),await i.show().catch(()=>{});return}await i.setStyle({style:l.Default}).catch(()=>{}),await i.setOverlaysWebView({overlay:!0}).catch(()=>{}),await i.show().catch(()=>{})};await d();const u=window.setTimeout(()=>{d()},400);n.push(()=>window.clearTimeout(u));const{App:f}=await ge(async()=>{const{App:x}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:x}},__vite__mapDeps([129,8,128])),b=await f.addListener("appStateChange",({isActive:x})=>{x&&d()});if(e){b.remove();return}n.push(()=>{b.remove()})}).catch(()=>{}),ge(()=>import("./vendor-capacitor-keyboard-CYccoJjr.js"),__vite__mapDeps([130,128])).then(async({Keyboard:i})=>{if(e)return;if(window.Capacitor?.getPlatform?.()==="android"){const N=await i.addListener("keyboardWillShow",C=>{Kt(C.keyboardHeight),s.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),M=await i.addListener("keyboardDidShow",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),h=await i.addListener("keyboardWillHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-intent",{detail:{open:!1}})),s.classList.remove("oc-keyboard-open")}),B=await i.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),g=()=>{N.remove(),M.remove(),h.remove(),B.remove()};if(e){g();return}n.push(g);return}await i.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const c=250,d=200,u="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,b=null,x=0,v=!1,y=0,j=!1;const D=(N,M)=>{s.style.setProperty(N,`${Math.max(0,Math.round(M))}px`)},U=()=>{f!==null&&(window.clearTimeout(f),f=null)},p=(N,M)=>{window.dispatchEvent(new CustomEvent(N,{detail:M}))},m=()=>{const N=[],M=document.querySelector(".oc-mobile-composer");M&&N.push({el:M,factor:1});const h=document.querySelector(".oc-draft-center");return h&&N.push({el:h,factor:.5}),N},E=()=>{for(const{el:N}of m())N.style.transition="",N.style.transform=""},z=await i.addListener("keyboardWillShow",N=>{if(U(),Kt(N.keyboardHeight),j=!0,x=N.keyboardHeight,!v){const h=document.querySelector(".oc-mobile-app-shell");y=h&&parseFloat(getComputedStyle(h).paddingBottom)||0}const M=Math.max(0,x-y);s.classList.remove("oc-kb-hide"),b!==null&&(window.clearTimeout(b),b=null),s.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),a(x);for(const{el:h,factor:B}of m())h.style.transition=`transform ${c}ms ${u}`,h.style.transform=`translateY(${-M*B}px)`;D("--oc-kb-scroll-inset",M),p("oc:keyboard-settled",{open:!0}),p("oc:keyboard-anim",{phase:"show",slide:M,durationMs:c,easing:u}),f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating"),D("--oc-kb-layout",x),v=!0,E(),p("oc:keyboard-settled",{open:!0}),b=window.setTimeout(()=>{b=null,s.classList.remove("oc-kb-caret-hold")},250)},c+20)}),w=()=>{if(!j)return;j=!1,U(),p("oc:keyboard-intent",{open:!1}),b!==null&&(window.clearTimeout(b),b=null),s.classList.remove("oc-kb-caret-hold");const N=Math.max(0,x-y);if(s.classList.remove("oc-keyboard-open"),a(0),D("--oc-kb-scroll-inset",0),v){s.classList.remove("oc-kb-animating"),D("--oc-kb-layout",0),v=!1;for(const{el:M,factor:h}of m())M.style.transition="none",M.style.transform=`translateY(${-N*h}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}p("oc:keyboard-anim",{phase:"hide",slide:N,durationMs:d,easing:u}),s.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:M}of m())M.style.transition=`transform ${d}ms ${u}`,M.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating","oc-kb-hide"),E(),p("oc:keyboard-settled",{open:!1})},d+20)},R=await i.addListener("keyboardWillHide",w),T=N=>N instanceof HTMLElement&&(N.tagName==="TEXTAREA"||N.tagName==="INPUT"||N.isContentEditable),O=N=>{j&&T(N.target)&&(T(N.relatedTarget)||window.setTimeout(()=>{j&&(T(document.activeElement)||w())},0))};if(document.addEventListener("focusout",O,!0),e){U(),document.removeEventListener("focusout",O,!0),z.remove(),R.remove();return}n.push(U,()=>{b!==null&&(window.clearTimeout(b),b=null)},()=>document.removeEventListener("focusout",O,!0),()=>{z.remove()},()=>{R.remove()})}).catch(()=>{}),()=>{e=!0,n.forEach(i=>i()),gr(),s.classList.remove("oc-capacitor-app","oc-keyboard-open","oc-kb-animating","oc-kb-hide","oc-kb-caret-hold","oc-platform-android"),s.style.removeProperty("--oc-keyboard-inset"),s.style.removeProperty("--oc-kb-shift"),s.style.removeProperty("--oc-kb-layout"),s.style.removeProperty("--oc-kb-scroll-inset")}},[])},Ao=e=>{const n=o.useRef(!1);o.useEffect(()=>{if(!Xe())return;let s=!1;const r=[],a=()=>{n.current&&(n.current=!1,e())},i=()=>{if(document.visibilityState==="hidden"){n.current=!0;return}a()};return document.addEventListener("visibilitychange",i),r.push(()=>document.removeEventListener("visibilitychange",i)),ge(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:l})=>{if(s)return;const c=await l.addListener("appStateChange",({isActive:u})=>{if(document.documentElement.classList.toggle("oc-native-app-active",u),!u){n.current=!0;return}a()}),d=await l.addListener("resume",a);if(s){c.remove(),d.remove();return}r.push(()=>{c.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(l=>l())}},[e])},Do=e=>{o.useEffect(()=>{if(!Xe())return;let n=!1,s=null;return ge(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:r})=>{if(n)return;const a=await r.addListener("backButton",()=>{e()||r.minimizeApp().catch(()=>{})});if(n){a.remove();return}s=()=>{a.remove()}}).catch(()=>{}),()=>{n=!0,s?.()}},[e])};function Mo(e=2500){const{uiFont:n}=yr(),[s,r]=o.useState(!1);return o.useEffect(()=>{let a=!1;const i=()=>{a||r(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(i))},c=Promise.all([br(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),sa.catch(()=>{})]).then(()=>{}),d=new Promise(u=>{window.setTimeout(u,e)});return Promise.race([c,d]).then(l),()=>{a=!0}},[n,e]),s}const _o="pichamber",Lo=e=>e.replace(/^\/+|\/+$/g,""),zo=e=>{const n=Lo(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...n]:n};function Oo(e){if(typeof e!="string"||e.length===0)return null;let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`${_o}:`)return null;const s=zo(n),r=(s[0]??"").toLowerCase(),a=s.slice(1),i=n.searchParams;switch(r){case"session":{const l=a[0]||i.get("id")||"";return l?{type:"session",sessionId:l,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const l=i.get("filter");return{type:"sessions",filter:l==="attention"||l==="recent"||l==="all"?l:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:a[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:a.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const l=(a[0]||"").toLowerCase();return l==="changes"?{type:"changes"}:l==="files"||l==="mcp"||l==="instances"||l==="update"?{type:"view",target:l}:null}default:return null}}let fe={},ns=!1,Ke=null;const $o=e=>{switch(e.type){case"session":return me.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const n=me.getState();return n.openNewSessionDraft(),(e.directory||e.projectId)&&n.setNewSessionDraftTarget({directoryOverride:e.directory??null,projectId:e.projectId??null,selectedProjectId:e.projectId??null}),!0}case"sessions":return fe.openSessions?(fe.openSessions(e.filter),!0):!1;case"status":return fe.openSessions?(fe.openSessions(),!0):!1;case"view":return fe.openView?(fe.openView(e.target),!0):!1;case"changes":return fe.openChanges?(fe.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return fe.openSettings?(fe.openSettings(e.section),!0):!1}},Dt=()=>{if(!ns||!Ke)return;const e=Ke;Ke=null,$o(e)||(Ke=e)},ss=e=>{Ke=e,Dt()},vn=e=>{const n=Oo(e);n&&ss(n)},Uo=e=>{ns=e,Dt()},Bo=e=>{o.useEffect(()=>(fe=e,Dt(),()=>{fe===e&&(fe={})}),[e])},Fo=e=>{const{ready:n}=e;o.useEffect(()=>{Uo(n)},[n]),o.useEffect(()=>{if(!oe())return;let s=!1;const r=[];return ge(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:a})=>{if(s)return;const i=await a.addListener("appUrlOpen",l=>{vn(l?.url)});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),ge(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,128])).then(async({PushNotifications:a})=>{if(s)return;const i=await a.addListener("pushNotificationActionPerformed",l=>{const c=l?.notification?.data,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){vn(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&ss({type:"session",sessionId:u})});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(a=>a())}},[])},Ho=32,Ko=80,Vo=64,Wo=.7,Go=(e,n)=>{const s=o.useRef(n);s.current=n,o.useEffect(()=>{const r=e.current;if(!r)return;const i=window.Capacitor?.getPlatform?.()==="android"?Ko:Ho;let l=!1,c=!1,d=0,u=0;const f=x=>{if(x.touches.length!==1){l=!1;return}const v=x.touches[0],y=r.clientWidth,j=v.clientX<=i,D=v.clientX>=y-i;l=j||D,c=j,d=v.clientX,u=v.clientY},b=x=>{if(!l)return;l=!1;const v=x.changedTouches[0];if(!v)return;const y=v.clientX-d,j=v.clientY-u;Math.abs(y)<Vo||Math.abs(j)>Math.abs(y)*Wo||c&&y<=0||!c&&y>=0||(c?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",f,{passive:!0}),r.addEventListener("touchend",b,{passive:!0}),()=>{r.removeEventListener("touchstart",f),r.removeEventListener("touchend",b)}},[e])},qo=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},Yo=()=>{if(typeof window>"u")return!1;const n=window.Capacitor?.getPlatform?.();return n==="ios"||n==="android"},Xo=e=>{const{enabled:n}=e,s=le(a=>a.nativeNotificationsEnabled),r=o.useRef(null);o.useEffect(()=>{if(!n||!s||!Yo())return;let a=!1;const i=[];return ge(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,128])).then(async({PushNotifications:l})=>{if(a)return;let c=await l.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await l.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const d=await l.addListener("registration",f=>{r.current=f.value,xt()?.push?.registerApnsToken?.({token:f.value,platform:Sn(),environment:qo()})}),u=await l.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await l.register().catch(()=>{}),a){d.remove(),u.remove();return}i.push(()=>{d.remove()},()=>{u.remove()})}).catch(()=>{}),()=>{a=!0,i.forEach(l=>l())}},[n,s]),o.useEffect(()=>{if(s)return;const a=r.current;if(!a)return;r.current=null,xt()?.push?.unregisterApnsToken?.({token:a})},[s])},wn=({side:e,isResizing:n,ariaLabel:s,handleProps:r})=>t.jsx("div",{className:K("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",e==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":s,...r,children:t.jsx("div",{className:K("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",n&&"bg-[var(--interactive-border)]")})}),Jo=320,Qo=380,kn=280,Zo=560,ei=900;function jn(e,n,s,r=Zo){const a=o.useRef(null),[i,l]=o.useState(()=>{if(typeof window>"u")return s;const m=Number.parseInt(window.localStorage.getItem(n)??"",10);return Number.isFinite(m)?Math.min(r,Math.max(kn,m)):s}),[c,d]=o.useState(!1),u=o.useRef(0),f=o.useRef(i),b=o.useRef(null),x=o.useRef(null),v=o.useCallback(m=>Math.min(r,Math.max(kn,Math.round(m))),[r]),y=o.useCallback(m=>{const E=a.current;E&&(E.style.width=`${m}px`,E.style.minWidth=`${m}px`,E.style.maxWidth=`${m}px`,E.style.setProperty("--oc-ipad-sidebar-width",`${m}px`))},[]),j=o.useCallback(m=>{try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}x.current=m.pointerId,u.current=m.clientX,f.current=i,b.current=i,d(!0),m.preventDefault()},[i]),D=o.useCallback(m=>{if(x.current!==m.pointerId)return;const E=m.clientX-u.current,z=v(f.current+(e==="left"?E:-E));b.current!==z&&(b.current=z,y(z))},[y,v,e]),U=o.useCallback(m=>{if(x.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const E=v(b.current??f.current);x.current=null,b.current=null,d(!1),l(E);try{window.localStorage.setItem(n,String(E))}catch{}},[v,n]),p=o.useMemo(()=>({onPointerDown:j,onPointerMove:D,onPointerUp:U,onPointerCancel:U}),[j,U,D]);return{asideRef:a,width:i,isResizing:c,handleProps:p}}const ti=1e3,ni=({onActiveConnectionDeleted:e})=>{const[n,s]=o.useState(!1),[r,a]=o.useState(null),[i,l]=o.useState(!1),[c,d]=o.useState("changes"),[u,f]=o.useState("nav"),[b,x]=o.useState(null),v=le(H=>H.setSettingsPage),y=le(H=>H.isArchivePageOpen),j=le(H=>H.setArchivePageOpen),D=le(H=>H.wideChatLayoutEnabled),U=Me(H=>H.available),p=Me(H=>H.runtimeType),m=o.useMemo(()=>Xe(),[]),E=!m&&U&&(p==="desktop"||p==="web"),z=o.useCallback(()=>{a(null)},[]),w=o.useCallback(H=>{a(H)},[]),R=o.useCallback(()=>{l(!1)},[]),T=o.useCallback(H=>{f(H),w("settings")},[w]),{enabled:O,roomyForPanels:N}=St(),h=Ar()==="portrait",B=Dr(),g=le(H=>H.setSidebarOpen),C=le(H=>H.isSidebarOpen),L=o.useRef(!1);o.useLayoutEffect(()=>{O&&!L.current&&g(Mr().roomyForPanels),!O&&L.current&&g(!1),L.current=O},[O,g]);const Y=o.useCallback(()=>{x(null),d("files"),l(!0)},[]),J=o.useCallback((H=null)=>{x(H),d("changes"),l(!0)},[]),X=jn("left","pichamber.ipad.leftSidebarWidth",Jo),I=jn("right","pichamber.ipad.rightSidebarWidth",Qo,ei),q=N,V=q&&i?I.width:0,k=Ps(O&&C),S=O&&C?X.width:0;o.useEffect(()=>{if(typeof document>"u")return;const H=document.documentElement;return H.style.setProperty("--oc-chat-inset-left",`${S}px`),H.style.setProperty("--oc-chat-inset-right",`${V}px`),()=>{H.style.removeProperty("--oc-chat-inset-left"),H.style.removeProperty("--oc-chat-inset-right")}},[S,V]),o.useEffect(()=>{if(typeof document>"u")return;const H=document.documentElement;return H.classList.toggle("wide-chat-layout",D),()=>H.classList.remove("wide-chat-layout")},[D]),o.useEffect(()=>{if(typeof document>"u")return;const H=O&&(h||B),ae=document.documentElement;return ae.classList.toggle("oc-keep-draft-starters",H),()=>ae.classList.remove("oc-keep-draft-starters")},[B,O,h]);const A=o.useMemo(()=>({openChanges:({diffPath:H,staged:ae}={})=>{J(H?{path:H,staged:ae===!0}:null)},openFiles:()=>Y(),openSettings:()=>T("nav"),openInstances:m?()=>w("instances"):void 0,instanceLabel:m?Fe():null,openUpdate:E?()=>w("update"):void 0}),[J,Y,T,w,m,E]),F=o.useMemo(()=>({openSessions:()=>{O?g(!0):s(!0)},openView:H=>{if(H==="files"){Y();return}(H==="instances"||H==="update"||H==="mcp")&&w(H)},openChanges:({path:H,staged:ae}={})=>{J(H?{path:H,staged:ae===!0}:null)},openSettings:H=>{H&&v(H),T(H?"page-content":"nav")}}),[O,J,Y,T,w,v,g]);Bo(F);const Z=o.useRef(null);Go(Z,{onLeftEdgeSwipe:()=>{O?g(!0):s(!0)},onRightEdgeSwipe:()=>l(!0)});const ee=o.useCallback(()=>y?(j(!1),!0):r?(z(),!0):i?(R(),!0):n?(s(!1),!0):!1,[r,z,R,y,n,j,i]);Do(ee);const ue=O?"dialog":"fullscreen";return t.jsx(_r,{actions:A,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area relative flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[O?t.jsxs("aside",{ref:X.asideRef,className:K("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!C&&"border-r-0"),style:{width:S,minWidth:S,maxWidth:S,"--oc-ipad-sidebar-width":`${X.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transform:X.isResizing||k.slidIn?"translateX(0)":"translateX(-100%)",transition:X.isResizing?"none":k.transition},"aria-hidden":!C,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:K("flex h-full shrink-0 flex-col",X.isResizing&&"pointer-events-none",!C&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(pe,{children:t.jsx(ln,{open:!0,variant:"sidebar",onOpenChange:H=>{!H&&!N&&g(!1)}})})}),C?t.jsx(wn,{side:"left",isResizing:X.isResizing,ariaLabel:"Resize left panel",handleProps:X.handleProps}):null]}):null,t.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[O?t.jsxs(t.Fragment,{children:[t.jsx(Is,{}),t.jsx(As,{onToggleRightDrawer:()=>l(!0),rightDrawerOpen:i})]}):t.jsx(so,{onOpenSessions:()=>s(!0),onOpenWorkspace:()=>l(!0)}),t.jsx("main",{ref:Z,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(pe,{children:t.jsx(Ds,{})})})})]}),O?null:t.jsx(ln,{open:n,onOpenChange:s}),O?t.jsxs("aside",{ref:I.asideRef,className:K("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!V&&"border-l-0"),style:{width:V,minWidth:V,maxWidth:V,"--oc-ipad-sidebar-width":`${I.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:I.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!V,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:K("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",I.isResizing&&"pointer-events-none",!V&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(pe,{children:t.jsx(xn,{open:i,onClose:R,tab:c,onTabChange:d,pendingChangesDiff:b,variant:q?"panel":"drawer"})})}),V?t.jsx(wn,{side:"right",isResizing:I.isResizing,ariaLabel:"Resize right panel",handleProps:I.handleProps}):null]}):t.jsx(xn,{open:i,onClose:R,tab:c,onTabChange:d,pendingChangesDiff:b}),r==="instances"&&m?t.jsx(gt,{open:!0,variant:ue,dialogAlign:"app",onClose:z,ariaLabel:"Instances",title:"Instances",children:t.jsx(ro,{onConnect:z,onActiveConnectionDeleted:e})}):null,r==="settings"?t.jsx(gt,{open:!0,variant:ue,dialogAlign:"app",onClose:z,ariaLabel:"Settings",headerless:!0,children:t.jsx(pe,{children:t.jsx(Hr,{forceMobile:!O,isWindowed:!0,initialMobileStage:u,onClose:z})})}):null,r==="update"?t.jsx(gt,{open:!0,variant:ue,dialogAlign:"app",onClose:z,ariaLabel:"Update",title:"Update",children:t.jsx(pe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(Kr,{initialUpdateDialogOpen:!0})})})}):null,t.jsx(pe,{children:t.jsx(Ms,{})})]})})};function si({apis:e}){const n=de(I=>I.initializeApp),s=de(I=>I.isInitialized),r=de(I=>I.isConnected),a=de(I=>I.connectionPhase),i=de(I=>I.providers.length),l=de(I=>I.agents.length),c=de(I=>I.loadProviders),d=de(I=>I.loadAgents),u=En(I=>I.currentDirectory),f=me(I=>I.error),b=me(I=>I.clearError),x=le(I=>I.setIsMobile),v=xr(I=>I.refreshStatus),[y,j]=o.useState(0),[D,U]=o.useState(0),[p,m]=o.useState(!1),[E,z]=o.useState("pending"),[w,R]=o.useState(null),T=o.useMemo(()=>Fe(),[]),[,O]=o.useReducer(I=>I+1,0),N=o.useMemo(()=>Xe(),[]),M=o.useRef(0),h=o.useRef(0),B=o.useCallback(()=>{const I=xe(),q=h.current+1;if(h.current=q,!I){pt();return}const V=()=>{n(),v(e.github,{force:!0}),i===0&&c({source:"mobileApp:nativeResume"}),l===0&&d({source:"mobileApp:nativeResume"})},k=()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(A=>A+1)};et().then(A=>{if(h.current===q){if(A==="no-connection"){k();return}if(A==="needs-login"){R({kind:"auth-expired",label:Fe()??""}),k();return}if(A==="unreachable"){window.setTimeout(()=>{h.current===q&&et().then(F=>{if(h.current===q&&F!=="switched"){if(F==="unchanged"){V();return}F==="needs-login"&&R({kind:"auth-expired",label:Fe()??""}),k()}})},4e3);return}A!=="switched"&&V()}});const S=Date.now();S-M.current>=ti&&(M.current=S,window.dispatchEvent(new Event("pichamber:system-resume")))},[l,e.github,n,d,c,i,v]);Io(),Ao(B),o.useEffect(()=>us(),[]),o.useEffect(()=>{if(!N)return;let I;const q=()=>{window.clearTimeout(I),I=window.setTimeout(()=>B(),1500)};return window.addEventListener("online",q),()=>{window.removeEventListener("online",q),window.clearTimeout(I)}},[N,B]),o.useEffect(()=>(Lt(e),()=>Lt(null)),[e]),o.useEffect(()=>fs(I=>{if(!!I.runtimeKey&&I.runtimeKey===I.previousRuntimeKey){Ss(),O();return}Cs(I),U(V=>V+1),j(V=>V+1)}),[]),o.useEffect(()=>{Tn()},[D]),o.useEffect(()=>{if(!N||r||xe()){z("done");return}let I=!1;return z("attempting"),pt().catch(()=>({status:"no-candidate"})).then(q=>{I||(q.status==="unreachable"?R({kind:"unreachable",label:q.label}):q.status==="needs-login"&&R({kind:"auth-expired",label:q.label}),z("done"))}),()=>{I=!0}},[]),o.useEffect(()=>{if(!N||!xe())return;let I=!1;const q=V=>{V&&R(V),De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(k=>k+1)};return et().then(async V=>{if(I||V==="switched"||V==="unchanged")return;const k=Fe();if(V==="needs-login"){q({kind:"auth-expired",label:k??""});return}if(V==="unreachable"){q(k?{kind:"unreachable",label:k}:null);return}const S=await pt().catch(()=>({status:"no-candidate"}));I||S.status==="connected"||(S.status==="needs-login"?q({kind:"auth-expired",label:S.label}):S.status==="unreachable"?q({kind:"unreachable",label:S.label}):q(null))}),()=>{I=!0}},[]),o.useEffect(()=>{x(!0)},[x]),o.useEffect(()=>{N&&!xe()||n()},[y,n,N]),o.useEffect(()=>{r&&(i===0&&c({source:"mobileApp:recovery"}),l===0&&d({source:"mobileApp:recovery"}))},[l,r,d,c,i]);const g=o.useRef(!1),[C,L]=o.useState(N);o.useEffect(()=>{if(!N||!r||g.current)return;if(me.getState().currentSessionId){g.current=!0,L(!1);return}const I=Ye(),q=vr(I);if(!q){g.current=!0,L(!1);return}let V=!1;const k=window.setTimeout(()=>L(!1),6e3);return(async()=>{const S=await wr().catch(()=>null);if(V)return;if(!S){L(!1);return}g.current=!0;const A=S.activeSessions.find(Z=>Z.id===q.sessionId);if(!A){kr(I),L(!1);return}const F=me.getState();F.currentSessionId||F.setCurrentSession(A.id,jt(A)??q.directory??void 0),L(!1)})(),()=>{V=!0,window.clearTimeout(k)}},[y,r,N]),o.useEffect(()=>{r&&jr.setDirectory(u)},[u,r]),o.useEffect(()=>{r&&v(e.github,{force:!0})},[e.github,r,v]),o.useEffect(()=>{if(!f)return;const I=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(I)},[b,f]),o.useEffect(()=>{if(!(!r&&(N?!!xe():!0))){m(!1);return}const q=window.setTimeout(()=>{m(!0)},N?4e3:8e3);return()=>window.clearTimeout(q)},[r,N,y,D]),Sr(),ms({enabled:!0}),hs(),Ns(),Xo({enabled:N&&r}),Fo({ready:N&&r&&s});const Y=Mo(),J=!r&&a==="reconnecting";if(!Y)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(ve,{width:120,height:120,isAnimated:!0})});const X=!!xe();return N&&(!X||!r&&!J)?X?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(ve,{width:120,height:120,isAnimated:!p}),p?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),t.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another instance."})]}),t.jsx(ne,{type:"button",variant:"outline",onClick:()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(I=>I+1)},children:"Use another server"})]}):null]})}):E!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(ve,{width:120,height:120,isAnimated:!0}),T?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),t.jsxs("p",{className:"typography-small text-foreground",children:[T,t.jsx(Cr,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Ga,{onConnected:()=>j(I=>I+1),notice:w})}):!r&&!J?p?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),t.jsx("p",{className:"typography-body text-muted-foreground",children:"We could not verify the UI session. If you're opening PiChamber from another device on your local network, make sure Desktop Network Access is enabled on the desktop app and use the LAN address shown in Settings."})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(ve,{width:120,height:120,isAnimated:!0})}):t.jsx(pe,{children:t.jsx(Nr,{children:t.jsx(Er,{apis:e,children:t.jsx(Tr,{delayDuration:300,skipDelayDuration:150,children:t.jsxs(Es,{children:[t.jsx(Ts,{}),t.jsxs("div",{className:"h-full bg-background text-foreground",children:[N&&C?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(ve,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Rr,{embeddedBackgroundWorkEnabled:s}),t.jsx(fa,{}),t.jsx(ni,{onActiveConnectionDeleted:()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(I=>I+1)}}),t.jsx(Rs,{}),t.jsx(Pr,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),t.jsx(Ir,{}),s?t.jsx(ga,{}):null]})]})})})},D)})}const ri=()=>{ps().then(()=>{Promise.all([Tn(),gs()]).catch(e=>{console.error("[mobile-main] settings init failed:",e)}),ys(),bs(),xs()}).catch(e=>{console.error("[mobile-main] appearance init failed:",e)}).finally(()=>{ra()})};function jc(e){window.__PICHAMBER_SURFACE__="mobile",Lr(),ri(),ua(),zr();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",a=e??xt();if(!a)throw new Error("Runtime APIs not registered");const i=r?{...a,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:a,l=t.jsx(si,{apis:i});os.createRoot(n).render(t.jsx(Ce.StrictMode,{children:t.jsx(Or,{children:t.jsx($r,{children:t.jsx(_s,{children:r?l:t.jsx(Ur,{children:l})})})})}))}export{jc as renderMobileApp};
|