@pi-chamber/web 0.1.9 → 0.2.1
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/README.md +1 -1
- package/bin/cli.test.js +48 -0
- package/bin/lib/DOCUMENTATION.md +2 -2
- package/bin/lib/cli-args.js +38 -11
- package/bin/lib/cli-startup.js +60 -13
- package/bin/lib/commands-startup.js +20 -5
- package/bin/lib/commands-update.js +91 -34
- package/bin/lib/commands-update.test.js +57 -42
- package/dist/assets/CommitSection-BQBmpPVE.js +1 -0
- package/dist/assets/DiagramEditor-Cp22TGpq.js +1 -0
- package/dist/assets/DiagramView-E4HJ4ZPU.js +1 -0
- package/dist/assets/{DiffView-k3lX2PiV.js → DiffView-d23o9CKP.js} +2 -2
- package/dist/assets/{FilesView-C39IOFfs.js → FilesView-DIDB-xK7.js} +6 -6
- package/dist/assets/{GitView-CkztSaT7.js → GitView-CkUONO1-.js} +4 -4
- package/dist/assets/JsonTreeView-By2oGMNK.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-CF12jEtB.js → MarkdownRendererImpl-DUghE55t.js} +2 -2
- package/dist/assets/PatchDiff-BjN6zMtK.js +1 -0
- package/dist/assets/{PierreDiffViewer-DSQwk05R.js → PierreDiffViewer-B38_7NnU.js} +2 -2
- package/dist/assets/{useAppFontEffects-DqOhrZWx.js → SessionSwitcherDropdown-NbVfnqQQ.js} +102 -102
- package/dist/assets/{SettingsView-Bf4vWwVK.js → SettingsView-C2dCv0r7.js} +1 -1
- package/dist/assets/SettingsWindow-DsMhdX5H.js +1 -0
- package/dist/assets/{ToolOutputDialog-Brg2Humk.js → ToolOutputDialog-DVesARmI.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C2N_oIO-.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BELx71mz.js → VirtualizedFileDiff-B7eVR6Pt.js} +1 -1
- package/dist/assets/collapsible-CPkWB1VR.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-BsZulefS.js +3 -0
- package/dist/assets/contextFileOpenGuard-BmmlK5E3.js +1 -0
- package/dist/assets/index-BZXqJcua.css +1 -0
- package/dist/assets/{index-Dnby-sDS.js → index-BhXma4dv.js} +2 -2
- package/dist/assets/index-C84KrQoy.js +1 -0
- package/dist/assets/isDiffPlainText-DsuyxFXo.js +1 -0
- package/dist/assets/isFilePlainText-CCYoe7us.js +1 -0
- package/dist/assets/main-ClYgYVm1.js +2 -0
- package/dist/assets/main-CmrF_CaW.js +133 -0
- package/dist/assets/{markdownCore-BK98alzY.js → markdownCore-D2uqals1.js} +2 -2
- package/dist/assets/miniChat-DmX9SjxM.js +2 -0
- package/dist/assets/mobile-C-PCxN62.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-BhXZtZlU.js +1 -0
- package/dist/assets/renderMobileApp-DUSTAPWw.js +23 -0
- package/dist/assets/{runtimeSurface-DMXukysz.js → runtimeSurface-CouGjZ3A.js} +1 -1
- package/dist/assets/{useInlineCommentController-ruw8wb2Y.js → useInlineCommentController-buNJ3xB4.js} +2 -2
- package/dist/assets/usePanelSlide-BRwyEEzi.js +47 -0
- package/dist/assets/{useWindowTitle-qt23iibv.js → useWindowTitle-CnF4pKz0.js} +3 -3
- package/dist/assets/{vendor-codemirror-language-data-DVYP3hf_.js → vendor-codemirror-language-data-qBLdzwMc.js} +2 -2
- package/dist/assets/{web-components-P2py0R8j.js → web-components-BhO08KaW.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +6 -1
- package/server/lib/package-manager.js +44 -65
- package/server/lib/package-manager.test.js +27 -0
- package/server/lib/pi/routes.js +19 -1
- package/server/lib/pi/routes.test.js +36 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +6 -5
- package/server/lib/pi/session-daemon/daemon-process.js +4 -1
- package/server/lib/pi/session-daemon/session-daemon.js +149 -24
- package/server/lib/pi/session-daemon/session-daemon.test.js +232 -0
- package/server/lib/pi/session-daemon/session-jsonl.js +258 -6
- package/server/lib/pi/session-daemon/session-jsonl.test.js +69 -1
- package/server/lib/pi/session-daemon/supervisor.js +41 -21
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/dist/assets/CommitSection-DSFuOWuL.js +0 -1
- package/dist/assets/DiagramEditor-D6W6zeV7.js +0 -1
- package/dist/assets/DiagramView-r89Qi5ON.js +0 -1
- package/dist/assets/JsonTreeView-C6qt2uIj.js +0 -1
- package/dist/assets/PatchDiff-D6In_lUU.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-CvE7hsxG.js +0 -1
- package/dist/assets/SettingsWindow-B8IV35H4.js +0 -1
- package/dist/assets/ToolPartDiffPreview-rlz2ipa2.js +0 -8
- package/dist/assets/collapsible-QoPrpZP_.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-CInbUZiB.js +0 -3
- package/dist/assets/contextFileOpenGuard-BOtkNMZy.js +0 -1
- package/dist/assets/index-4sRd3SSM.js +0 -1
- package/dist/assets/index-NYG3k04a.css +0 -1
- package/dist/assets/isDiffPlainText-BquUayus.js +0 -1
- package/dist/assets/isFilePlainText-D4iUTBdr.js +0 -1
- package/dist/assets/main-Cp3YZZm1.js +0 -2
- package/dist/assets/main-CyshB9VI.js +0 -134
- package/dist/assets/miniChat-C_A4lnrT.js +0 -2
- package/dist/assets/mobile-2dXx6cUI.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-HL15h5xo.js +0 -1
- package/dist/assets/renderMobileApp-w6YFCJhq.js +0 -23
- package/dist/assets/runtimeEndpointReset-DiVqZFZB.js +0 -46
- package/dist/assets/useOpenInAppsStore-DVr2oGEm.js +0 -1
- /package/dist/assets/{runtimeEndpointReset-BV3KOtdA.css → usePanelSlide-BV3KOtdA.css} +0 -0
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderElectronMiniChatApp-HL15h5xo.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CHD9BdDO.js","assets/vendor-katex-Cp579UoJ.css","assets/index-Dnby-sDS.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-NYG3k04a.css","assets/useWindowTitle-qt23iibv.js","assets/useAppFontEffects-DqOhrZWx.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.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/runtimeSurface-DMXukysz.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-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-DVYP3hf_.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/SessionSwitcherDropdown-CvE7hsxG.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as t}from"./index-Dnby-sDS.js";import"./vendor-katex-CHD9BdDO.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";window.__PICHAMBER_RUNTIME_APIS__=t();o(async()=>{const{renderElectronMiniChatApp:r}=await import("./renderElectronMiniChatApp-HL15h5xo.js");return{renderElectronMiniChatApp:r}},__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])).then(({renderElectronMiniChatApp:r})=>{r()});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderMobileApp-w6YFCJhq.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CHD9BdDO.js","assets/vendor-katex-Cp579UoJ.css","assets/index-Dnby-sDS.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-NYG3k04a.css","assets/useWindowTitle-qt23iibv.js","assets/useAppFontEffects-DqOhrZWx.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.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/runtimeSurface-DMXukysz.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-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-DVYP3hf_.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/runtimeEndpointReset-DiVqZFZB.js","assets/permissionStore-BRcQ9Jgt.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/SettingsView-Bf4vWwVK.js","assets/vendor-qrcode-COsmt6jn.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-QoPrpZP_.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/CommitSection-DSFuOWuL.js","assets/PierreDiffViewer-DSQwk05R.js","assets/web-components-P2py0R8j.js","assets/computeVirtualFileMetrics-CInbUZiB.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-BELx71mz.js","assets/isDiffPlainText-BquUayus.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-ruw8wb2Y.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-remixicon-react-CzPq62YO.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as i}from"./index-Dnby-sDS.js";import"./vendor-katex-CHD9BdDO.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";window.__PICHAMBER_RUNTIME_APIS__=i();o(async()=>{const{renderMobileApp:r}=await import("./renderMobileApp-w6YFCJhq.js");return{renderMobileApp:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127])).then(({renderMobileApp:r})=>{r()});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as n,R as a,e as ye,r as we}from"./vendor-react-DYyjh7Q0.js";import"./vendor-katex-CHD9BdDO.js";import{l as T,Z as ge,G as U,u as X,C as xe,q as se,o as ve,w as Se,v as Ie}from"./index-Dnby-sDS.js";import{u as be,a as je,b as De,s as Ce,c as Pe,d as Me}from"./useWindowTitle-qt23iibv.js";import{c_ as Ee,m as h,bF as _e,b as Y,h as f,aZ as ee,c$ as ke,K as Le,R as Ne,aM as Ae,I as $,B as ie,f as Re,aV as N,d0 as ae,d1 as Oe,i as Be,t as Te,aR as ze,ae as Ue,af as We,a0 as Fe,ah as He,ai as $e,aj as Ge,al as Ve,am as Ke,d2 as Ze,aN as qe,at as Je,au as Qe,av as Xe}from"./useAppFontEffects-DqOhrZWx.js";import{u as Ye,W as ce,S as et,C as tt}from"./SessionSwitcherDropdown-CvE7hsxG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.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"./runtimeSurface-DMXukysz.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"./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-DVYP3hf_.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-tanstack-react-virtual-IrbCBGJ4.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-DJASDzNt.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-dWA7qvjr.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";const rt=({mode:e,children:r})=>n.jsx(Ee.Provider,{value:e,children:r}),nt=e=>{const r=typeof e=="string"?e.trim():"";if(!r)return"";const o=typeof window<"u"?window.__PICHAMBER_HOME__:"";if(o&&r===o)return"~";if(o&&r.startsWith(`${o}/`))return`~/${r.slice(o.length+1)}`;const d=r.split("/").filter(Boolean);return d.length<=3?r:`.../${d.slice(-3).join("/")}`},G=e=>{const r=typeof e=="string"?e.trim():"";if(!r)return"";const o=r.replace(/\\/g,"/");return o==="/"?"/":o.replace(/\/+$/,"")},ot=({mode:e})=>{const r=h(t=>t.currentSessionId),o=h(t=>!!t.newSessionDraft?.open),d=h(t=>t.newSessionDraft?.selectedProjectId??null),i=T(t=>t.currentDirectory),u=Y(t=>t.projects),c=Y(t=>t.getActiveProject()),M=f(t=>t.getCurrentModel),k=f(t=>t.providers),p=ee(),m=ke(r??""),E=Le(),D=Ne(t=>t.ensureStatus),_=h(t=>t.newSessionDraft?.open?G(t.newSessionDraft.directoryOverride??""):""),[w,v]=a.useState(!1),C=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,S=Number.isFinite(C)&&C>0,{usesFramelessChrome:x,side:A}=Ye(),s=S?C>=26?"h-12":C<=15?"h-14":"":"",g=a.useMemo(()=>r?p.find(t=>t.id===r)??null:null,[r,p]);a.useEffect(()=>{ge()&&U("desktop_get_window_pinned").then(t=>{typeof t?.pinned=="boolean"&&v(t.pinned)})},[]);const y=g?.title?.trim()||(o||e==="draft"?"New session":"Session"),I=G(g?.directory??null),V=G(i),b=I||_||V,te=nt(b);a.useEffect(()=>{b&&D(b,E.git).catch(()=>{})},[D,b,E.git]);const re=a.useMemo(()=>{const t=b;return t?u.map(l=>({...l,normalizedPath:G(l.path)})).filter(l=>l.normalizedPath&&(l.normalizedPath===t||t.startsWith(`${l.normalizedPath}/`))).sort((l,B)=>B.path.length-l.path.length)[0]??null:null},[b,u]),de=a.useMemo(()=>{const t=re??c;if(!t)return te||"PiChamber";const l=t.label?.trim();return l||(t.path.split(/[\\/]/).filter(Boolean).at(-1)??t.path)},[c,te,re]),K=Ae(b||null),ne=K&&K!=="HEAD"?K:null,oe=M(),le=a.useMemo(()=>{for(let t=m.length-1;t>=0;t-=1){const l=m[t];if(l.role!=="assistant"||typeof l.providerID!="string"||typeof l.modelID!="string")continue;const H=k.find(z=>z.id===l.providerID)?.models.find(z=>z.id===l.modelID);if(H)return H}},[m,k]),W=oe?.limit?oe:le,R=W&&typeof W.limit=="object"&&W.limit!==null?W.limit:null,O=R&&typeof R.context=="number"?R.context:0,F=R&&typeof R.output=="number"?R.output:0,j=a.useMemo(()=>{if(!r||m.length===0)return null;let t,l;for(let J=m.length-1;J>=0;J-=1){const Q=m[J];if(Q.role!=="assistant")continue;const L=Q.tokens;if(!L)continue;if(L.input+L.output+L.reasoning+(L.cache?.read??0)+(L.cache?.write??0)>0){t=L,l=Q.id;break}}if(!t)return null;const B=t.input+t.output+t.reasoning+(t.cache?.read??0)+(t.cache?.write??0),H=O>0?O:2e5,z=O>0?Math.round(B/O*100):0,he=F>0?Math.round(t.output/F*100):void 0;return{totalTokens:B,percentage:z,contextLimit:O||0,outputLimit:F||void 0,normalizedOutput:he,thresholdLimit:H,lastMessageId:l}},[O,r,m,F]),[P,Z]=a.useState(null),ue={WebkitAppRegion:"drag"},q={WebkitAppRegion:"no-drag"};a.useEffect(()=>{if(!r){Z(t=>t===null?t:null);return}if(j&&j.totalTokens>0){Z(t=>t&&t.totalTokens===j.totalTokens&&t.percentage===j.percentage&&t.contextLimit===j.contextLimit&&(t.outputLimit??0)===(j.outputLimit??0)&&(t.normalizedOutput??0)===(j.normalizedOutput??0)&&t.thresholdLimit===j.thresholdLimit&&t.lastMessageId===j.lastMessageId?t:j);return}Z(t=>t===null?t:null)},[j,r]);const me=P&&P.contextLimit>0?Math.min(999,P.totalTokens/P.contextLimit*100):0,pe=a.useCallback(()=>{const t=!w;v(t),U("desktop_set_window_pinned",{pinned:t}).catch(()=>{v(!t)})},[w]),fe=a.useCallback(()=>{const t=r?{sessionId:r,directory:g?.directory??i??""}:{mode:"draft",directory:b||i||"",projectId:d};U("desktop_focus_main_window",t).then(l=>l?.focused===!0?U("desktop_close_current_window"):null)},[i,r,d,b,g]);return n.jsxs("header",{className:Re("flex items-center gap-3 bg-background pr-3",S?"pl-[5.5rem]":"pl-3",x?"h-12":s||"min-h-14"),style:ue,children:[x&&A==="left"?n.jsx(ce,{visible:!0,position:"left"}):null,n.jsx(et,{children:n.jsxs("button",{type:"button","aria-label":"Open session switcher",style:q,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[n.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),n.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[n.jsx("span",{className:"truncate",children:de}),ne?n.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[n.jsx($,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),n.jsx("span",{className:"truncate",children:ne})]}):null]})]})}),n.jsx("div",{className:"min-w-0 flex-1"}),P&&P.totalTokens>0?n.jsx(tt,{totalTokens:P.totalTokens,percentage:me,colorPercentage:P.percentage,contextLimit:P.contextLimit,outputLimit:P.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,n.jsx(ie,{type:"button",variant:"ghost",size:"icon",onClick:pe,"aria-label":w?"Unpin Mini Chat window":"Pin Mini Chat window",title:w?"Unpin window":"Pin above other windows",style:q,children:w?n.jsx($,{name:"pushpin-2-fill",className:"h-4 w-4"}):n.jsx($,{name:"pushpin-2",className:"h-4 w-4"})}),n.jsx(ie,{type:"button",variant:"ghost",size:"icon",onClick:fe,"aria-label":"Open session in main window",title:"Open in main window",style:q,children:n.jsx($,{name:"external-link",className:"h-4 w-4"})}),n.jsx(ce,{visible:x&&A==="right",position:"right"})]})},st=({mode:e,autoOpenDraft:r=!1,unavailable:o=!1})=>{const d=h(i=>i.currentSessionId);return n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[n.jsx(ot,{mode:e}),n.jsx("main",{className:"min-h-0 flex-1",children:o?n.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:n.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[n.jsx("div",{className:"font-medium text-foreground",children:"Session unavailable"}),n.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:"This session could not be loaded. It may have been deleted, archived, or opened from a different project context."})]})}):n.jsx(rt,{mode:"mini-chat",children:n.jsx(_e,{autoOpenDraft:r},d??"no-session")})})]})},it=()=>{const e=X(i=>i.shortcutOverrides),r=T(i=>i.currentDirectory),o=Y(i=>i.getActiveProject()),d=h(i=>i.openNewSessionDraft);a.useEffect(()=>{const i=c=>ze(c,e),u=c=>{if(N(c,i("focus_input"))){c.preventDefault(),ae();return}if(xe()&&N(c,i("new_mini_chat"))){c.preventDefault(),U("desktop_open_draft_mini_chat_window",{directory:r||o?.path||"",projectId:o?.id??null})?.catch(p=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",p)});return}if(N(c,i("new_chat"))){c.preventDefault(),d({selectedProjectId:o?.id??null,directoryOverride:r||o?.path||null,preserveDirectoryOverride:!!(r||o?.path)}),ae();return}if(N(c,i("open_model_selector"))){c.preventDefault();const{isModelSelectorOpen:p,setModelSelectorOpen:m}=X.getState();m(!p);return}if(N(c,i("cycle_thinking_variant"))){if(f.getState().getCurrentModelVariants().length===0)return;c.preventDefault(),Oe(1).then(E=>{const D=h.getState().currentSessionId,_=f.getState().currentAgentName,w=f.getState().currentProviderId,v=f.getState().currentModelId;D&&_&&w&&v&&Be.getState().saveAgentModelVariantForSession(D,_,w,v,E)}).catch(()=>{Te.error("Couldn't update thinking")});return}const M=N(c,i("cycle_favorite_model_forward")),k=N(c,i("cycle_favorite_model_backward"));if(M||k){const{favoriteModels:p,addRecentModel:m}=X.getState();if(p.length===0)return;c.preventDefault();const{currentProviderId:E,currentModelId:D,setProvider:_,setModel:w}=f.getState(),v=p.findIndex(x=>x.providerID===E&&x.modelID===D),S=p[(v+(M?1:-1)+p.length)%p.length];_(S.providerID),w(S.modelID),m(S.providerID,S.modelID)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[o?.id,o?.path,r,d,e])},at="pichamber:mini-chat-presence",ct=()=>{const e=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,r=e.get("mode")==="session"?"session":"draft",o=e.get("sessionId")?.trim()||null,d=e.get("directory")?.trim()||null,i=e.get("projectId")?.trim()||null;return{mode:r,sessionId:o,directory:d,projectId:i}},dt=({config:e})=>{const r=ee(),o=T(s=>s.currentDirectory),d=T(s=>s.setDirectory),i=h(s=>s.currentSessionId),u=h(s=>!!s.newSessionDraft?.open),c=h(s=>s.newSessionDraft?.open?s.newSessionDraft.bootstrapPendingDirectory??s.newSessionDraft.directoryOverride??"":""),M=h(s=>s.setCurrentSession),k=h(s=>s.openNewSessionDraft),p=f(s=>s.initializeApp),m=f(s=>s.isInitialized),E=f(s=>s.isConnected),D=f(s=>s.loadProviders),_=f(s=>s.loadAgents),w=f(s=>s.providers.length),v=f(s=>s.agents.length),C=qe();a.useEffect(()=>{p()},[p]),a.useEffect(()=>{if(m)return;let s=!0,g=0;const y=window.setInterval(()=>{if(s){if(g+=1,g>10){window.clearInterval(y);return}f.getState().isInitialized||f.getState().initializeApp()}},1e3);return()=>{s=!1,window.clearInterval(y)}},[m]);const S=a.useRef(!1);a.useEffect(()=>{if(!S.current&&e.mode==="session"&&e.directory){if(o===e.directory){S.current=!0;return}d(e.directory,{showOverlay:!1}),S.current=!0}},[e.directory,e.mode,o,d]),a.useEffect(()=>{e.mode!=="draft"||!u||i||!c||o===c||d(c,{showOverlay:!1})},[e.mode,o,i,c,u,d]),a.useEffect(()=>{E&&(w===0&&D({source:"electronMiniChat:recovery"}),v===0&&_({source:"electronMiniChat:recovery"}))},[v,E,_,D,w]);const x=a.useRef(!1);a.useEffect(()=>{if(x.current||e.mode!=="session"||!e.sessionId)return;if(i===e.sessionId){x.current=!0;return}if(i){x.current=!0;return}const s=r.find(y=>y.id===e.sessionId);if(!s){C.ensureSessionRenderable(e.sessionId);return}const g=s.directory??e.directory;M(e.sessionId,g),x.current=!0},[e,i,r,M,C]),a.useEffect(()=>{const s=g=>{const y=g.detail,I=typeof y?.sessionId=="string"?y.sessionId.trim():"";if(!I||h.getState().currentSessionId===I)return;const V=typeof y?.directory=="string"&&y.directory.trim().length>0?y.directory.trim():r.find(b=>b.id===I)?.directory??null;C.ensureSessionRenderable(I),M(I,V),x.current=!0};return window.addEventListener("pichamber:open-session",s),()=>window.removeEventListener("pichamber:open-session",s)},[r,M,C]),a.useEffect(()=>{e.mode!=="draft"||u||i||k({selectedProjectId:e.projectId,directoryOverride:e.directory,preserveDirectoryOverride:!!e.directory})},[e,i,u,k]);const A=a.useRef(!1);return a.useEffect(()=>{if(A.current||!m)return;const s=()=>{if(A.current)return;A.current=!0;const I=typeof document<"u"?document.getElementById("initial-loading"):null;I&&(I.classList.add("fade-out"),window.setTimeout(()=>I.remove(),300))},g=e.mode==="session"?i===e.sessionId:u,y=window.setTimeout(s,g?100:1500);return()=>window.clearTimeout(y)},[m,e.mode,e.sessionId,i,u]),null},lt=()=>{const e=h(o=>o.currentSessionId),r=T(o=>o.currentDirectory);return a.useEffect(()=>{if(!e||!r||typeof BroadcastChannel>"u")return;const o=new BroadcastChannel(at),d=c=>{o.postMessage({type:"mini-chat-session-presence",sessionId:e,directory:r,viewed:c})};d(!0);const i=window.setInterval(()=>d(!0),5e3),u=()=>d(!1);return window.addEventListener("beforeunload",u),()=>{window.clearInterval(i),window.removeEventListener("beforeunload",u),d(!1),o.close()}},[r,e]),null},ut=e=>{const r=ee(),o=h(u=>u.currentSessionId),[d,i]=a.useState(!1);return a.useEffect(()=>{if(e.mode!=="session"||!e.sessionId||o===e.sessionId){i(!1);return}if(r.some(c=>c.id===e.sessionId)){i(!1);return}const u=window.setTimeout(()=>i(!0),5e3);return()=>window.clearTimeout(u)},[e.mode,e.sessionId,o,r]),d};function mt({apis:e}){const r=a.useMemo(()=>ct(),[]),o=T(d=>d.currentDirectory);return a.useEffect(()=>{Ue.setDirectory(o||r.directory||void 0)},[r.directory,o]),a.useEffect(()=>(se(e),()=>se(null)),[e]),We(),it(),be({enabled:!0}),je(),n.jsx(Fe,{children:n.jsx(He,{directory:o||r.directory,children:n.jsx($e,{apis:e,children:n.jsx(Ge,{delayDuration:300,skipDelayDuration:150,children:n.jsxs("div",{className:"h-full text-foreground bg-background",children:[n.jsx(pt,{config:r}),n.jsx(Ve,{}),n.jsx(Ke,{})]})})})})})}const pt=({config:e})=>{const r=ut(e);return n.jsxs(n.Fragment,{children:[n.jsx(dt,{config:e}),n.jsx(lt,{}),n.jsx(Ze,{embeddedBackgroundWorkEnabled:!0}),n.jsx(st,{mode:e.mode,autoOpenDraft:e.mode==="draft",unavailable:r})]})},ft=()=>{Se().then(()=>{Promise.all([Ie(),De()]).catch(e=>{console.error("[mini-chat-main] settings init failed:",e)}),Ce(),Pe(),Me()}).catch(e=>{console.error("[mini-chat-main] appearance init failed:",e)})};function $r(e){const r=e??ve();if(!r)throw new Error("Runtime APIs not registered");ft();const o=document.getElementById("root");if(!o)throw new Error("Root element not found");ye.createRoot(o).render(n.jsx(we.StrictMode,{children:n.jsx(Je,{children:n.jsx(Qe,{children:n.jsx(Xe,{children:n.jsx(mt,{apis:r})})})})}))}export{$r as renderElectronMiniChatApp};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-k3lX2PiV.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-Dnby-sDS.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-NYG3k04a.css","assets/useAppFontEffects-DqOhrZWx.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.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/runtimeSurface-DMXukysz.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-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-DVYP3hf_.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-DSQwk05R.js","assets/web-components-P2py0R8j.js","assets/computeVirtualFileMetrics-CInbUZiB.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-BELx71mz.js","assets/isDiffPlainText-BquUayus.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-DiVqZFZB.js","assets/permissionStore-BRcQ9Jgt.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/useInlineCommentController-ruw8wb2Y.js","assets/collapsible-QoPrpZP_.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/contextFileOpenGuard-BOtkNMZy.js","assets/FilesView-C39IOFfs.js","assets/vendor-codemirror-search-BzyfPoRb.js","assets/vendor-replit-codemirror-vim-BUqe2Slv.js","assets/JsonTreeView-C6qt2uIj.js","assets/Virtualizer-BxW2CJGB.js","assets/isFilePlainText-D4iUTBdr.js","assets/DiagramEditor-D6W6zeV7.js","assets/vendor-react-drawio-Boqanm0j.js","assets/useOpenInAppsStore-DVr2oGEm.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 ce,a as Ye,b as Sn,d as _t,i as ae,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-Dnby-sDS.js";import{u as ms,a as hs,b as gs,s as ys,c as bs,d as xs}from"./useWindowTitle-qt23iibv.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,d as Es,F as Ts,e as Rs,C as Ps,A as Is,D as As}from"./runtimeEndpointReset-DiVqZFZB.js";import{u as Ds,a as Ms,b as Rn,c as _s,d as Ls,r as jt,e as zs,t as se,o as Os,I as V,P as ve,B as te,f as K,g as $s,h as le,i as Us,j as zt,k as Bs,l as St,m as fe,n as Fs,p as Hs,q as Ks,s as Vs,v as Ws,S as Gs,w as qs,x as Ys,F as Pn,T as Js,y as Qs,z as Xs,A as Ct,O as Zs,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 er,N as tr,Q as nr,R as be,U as sr,V as rr,W as ar,X as or,Y as ir,Z as lr,_ as cr,$ as dr,a0 as ue,a1 as ur,a2 as An,a3 as vt,a4 as Dn,a5 as fr,a6 as Kt,a7 as pr,a8 as mr,a9 as hr,aa as gr,ab as yr,ac as br,ad as xr,ae as vr,af as wr,ag as kr,ah as jr,ai as Sr,aj as Cr,ak as Nr,al as Er,am as Tr,an as Rr,ao as Pr,ap as Ir,aq as Ar,ar as Dr,as as Mr,at as _r,au as Lr,av as zr}from"./useAppFontEffects-DqOhrZWx.js";import{p as Or,a as $r,S as Ur,A as Br}from"./SettingsView-Bf4vWwVK.js";import{_ as he}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as Fr}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as Hr}from"./vendor-capacitor-core-B4EWRrHz.js";import{u as Kr}from"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import{C as Vr}from"./CommitSection-DSFuOWuL.js";import{P as Wr}from"./PierreDiffViewer-DSQwk05R.js";import{K as Vt,P as Gr,d as qr,p as Yr,U as Jr,Z as Qr,Q as Xr,r as Zr}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-DMXukysz.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-DVYP3hf_.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-QoPrpZP_.js";import"./web-components-P2py0R8j.js";import"./computeVirtualFileMetrics-CInbUZiB.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-BELx71mz.js";import"./isDiffPlainText-BquUayus.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-ruw8wb2Y.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";let Mn=null,Wt=!1;const ea=new Promise(e=>{Mn=e});function ta(){Wt||(Wt=!0,Mn?.())}const na=6,sa=e=>e.parentID??null,Gt=e=>{const n=e.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},ra=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),aa=(e,n)=>{if(!e)return"";let s=null,r=-1;for(const a of n){const i=ra(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)},oa=()=>{const e=Ds.getState().activeSessions,n=Ms.getState().index.session.unseenCount,s=ce.getState().notifyOnSubtasks,r=Rn.getState().projects,a=_s.getState().ids,i=Ls.getState().rankById;let l=0;const c=[];for(const u of e){const f=sa(u)!==null,x=(n[u.id]??0)>0&&(!f||s);x&&(l+=1),f||c.push({session:u,unread:x,project:aa(jt(u),r)})}c.sort((u,f)=>zs(u.session,f.session,a,i));const d=c.slice(0,na).map(({session:u,unread:f,project:b})=>({id:u.id,title:u.title??"",unread:f,project:b}));return{runtimeKey:Ye(),attentionCount:l,recentSessions:d}},ia="__PICHAMBER_WIDGET_SNAPSHOT__",la=()=>{typeof window>"u"||(window[ia]=()=>{try{return JSON.stringify(oa())}catch{return null}})},ft="mobile-app-update-available",qt="mobile-app-update-toast-dismissed-version",ca=()=>{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(V,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{Os(r)}},cancel:{label:"Dismiss",onClick:()=>{_t().setItem(qt,s),se.dismiss(ft)}}})))},[e,r,n,s]),null},da="Updating OpenCode configuration...",_n=0,Ln=da,Yt=new Set;function ua(e){return Yt.add(e),e({isUpdating:_n>0,message:Ln}),()=>{Yt.delete(e)}}function fa(){return{isUpdating:_n>0,message:Ln}}const pa=()=>{const[{isUpdating:e},n]=o.useState(()=>fa());return o.useEffect(()=>ua(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",ma="pichamber.mobile.",Jt="pichamber.mobile.deviceId",ha=()=>{try{const e=window.localStorage.getItem(Jt);if(e&&e.trim())return e.trim();const n=crypto.randomUUID();return window.localStorage.setItem(Jt,n),n}catch{return crypto.randomUUID()}},Qt=()=>`mobile:${ha()}`,Xt=()=>{try{const e=Hr.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},zn=12,ga=8e3,ya=2500,ba=3e3,nt=2500,xa=()=>{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()}`,va=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?va(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)}},oe=(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))},wa=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},ka=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},ja=async(e,n)=>{if(!ae())return null;try{const{CapacitorHttp:s}=await he(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:ka(n?.body)});return{ok:a.status>=200&&a.status<300,status:a.status,source:"native-http",json:async()=>wa(a.data)}}catch(s){return console.warn("[mobile-connect]","native-http failed",it({url:e,error:s instanceof Error?s.message:String(s)})),null}},Sa=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??ga,a=Date.now(),i=await ke(Math.min(ya,r),ja(e,n));if(i)return i;const l=new AbortController,c=Math.max(500,r-(Date.now()-a));return ke(c,Sa(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,Ca=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(oe("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}},Na=(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})},Ea=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},Ta=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=ae();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(Ea).filter(d=>!!d):Ta(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=ae(),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=ae(),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=Fr,Ra=0,It=e=>`${ma}token.${encodeURIComponent(e)}`,Pa=async(e,n)=>{let s;const r=new Promise(a=>{s=window.setTimeout(()=>a(n),ba)});try{return await Promise.race([e.catch(()=>n),r])}finally{s!==void 0&&window.clearTimeout(s)}},At=async(e,n,s)=>ae()?Pa(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:Ra}),!0),!1);return $e("secure:write",{key:e,ok:s}),s},Ia=async e=>{await At("secure:delete",async()=>(await Pt.internalRemoveItem({prefixedKey:It(e),sync:!1}),!0),!1)},Aa=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"||!ae())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 Aa(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})},Da=async()=>(await Bn(),Re()),rt=async e=>{const n=Un(Re(),e);return Rt(n),ae()&&e.clientToken&&await Se(re({candidates:e.candidates}),e.clientToken),n},Ma=async e=>{const n=Re(),s=n.find(a=>a.id===e)??null,r=n.filter(a=>a.id!==e);return Rt(r),s&&ae()&&await Ia(re(s)),r},_a=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 M=await x.json().catch(()=>null),B=M&&typeof M=="object"?M.serverId:null;if(typeof B=="string"&&B&&B!==a){oe("probe:server-id-mismatch",{url:f});continue}}const y=await Te(`${f}/auth/session`,{method:"GET",credentials:n?"omit":"include",headers:b},r);if(y?.status===401)return{status:"needs-login"};if(!y||!y.ok&&y.status!==404)continue;const k=await lt(y);if(k&&k.disabled!==!0&&k.authenticated===!1)return{status:"needs-login"};const j=k?.disabled===!0;return!n&&ae()&&!j&&k?.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 Ca(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,y=null,k=null;const j=p=>{p?.status==="ok"&&p.transport.kind==="relay"&&p.transport.tunnel?.close()},M=p=>{f||(f=!0,u(p))},B=()=>{b||f||(x!==void 0&&(window.clearTimeout(x),x=void 0),d().then(p=>{if(k=p,f||b){j(p);return}if(p.status==="ok"||p.status==="needs-login"){M(p);return}y&&M(y)}))};c().then(p=>{if(y=p,!f){if(p.status==="ok"||p.status==="needs-login"){b=!0,x!==void 0&&window.clearTimeout(x),j(k),M(p);return}if(k){M(k);return}B()}}),x=window.setTimeout(B,_a)}):c()},Ne=(e,n,s)=>{e.kind==="relay"?Na(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(ae()){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"})},La=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)},za=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(oe("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(oe("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){oe("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},Oa=async(e,n)=>{if(!We())return La(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)},$a=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(ae()?n=e.hasToken?await qe(re(e)):void 0:n=e.clientToken,!n)return"unreachable";const s=e.candidates.findIndex(c=>$a(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 Oa({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"},Ua=5e3;let mt=!1;const Ba=async()=>{if(mt)return"skipped";const e=Fn();if(!e)return oe("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const n=Ee(e);if(!n)return oe("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 oe("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 oe("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 oe("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":(oe("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 Ba().catch(()=>"skipped");oe("candidates:refresh-result",{result:e}),e==="updated"&&We()&&await et().catch(()=>null)})()},Ua)},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(xa()),x=o.useCallback(v=>{u.current=v,s(v)},[]),y=o.useCallback(v=>{f.current=v,a(v)},[]),k=o.useCallback(v=>{f.current===v&&(f.current=null,a(null))},[]);o.useEffect(()=>{let v=!1;return Da().then(R=>{v||x(R)}),()=>{v=!0}},[x]);const j=o.useCallback(v=>{const R=Un(u.current,v);return x(R),Rt(R),R},[x]),M=o.useCallback(async v=>{l(null),y("connect");try{const R=Zt(v);if(R.length===0){l("Enter a server URL.");return}const T=v.id?u.current.find(g=>g.id===v.id):u.current.find(g=>st(g.candidates,R)),O=v.label?.trim()||T?.label||Ze(ye({candidates:R})),S=v.relayGrant;let D=v.clientToken?.trim()||void 0;const h=!!D;D||(ae()?T?.hasToken&&(D=await qe(re({candidates:R}))):D=T?.clientToken),oe("connect:start",{candidates:R.map(g=>g.kind),hasToken:!!D});const H=await at(R,D);if(oe("connect:probe",{status:H.status}),H.status==="unreachable"){l("Could not reach that PiChamber server.");return}if(H.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:S});return}D&&h&&ae()&&await Se(re({candidates:R}),D),j({id:T?.id,label:O,candidates:R,clientToken:D}),Ne(H.transport,D??null,{runtimeKey:re({candidates:R}),grant:S}),e()}catch(R){console.warn("[mobile-connect] connect threw",R),l("That server URL is not valid.")}finally{k("connect")}},[y,k,e,j]),B=o.useCallback(async v=>{if(f.current==="pairing")return;l(null),y("pairing");const R=za(v.candidates);let T=null,O=!1;try{if(T=await en(R),!T){l("Could not reach that PiChamber server.");return}const S=JSON.stringify({pairingId:v.pairingId,secret:v.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:Xt(),dedupeKey:Qt()}),D={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:S},h=T.kind==="relay"?await ke(Ge,T.tunnel.fetch("/api/client-auth/pairing/redeem",D).catch(()=>null)):await Te(`${T.url}/api/client-auth/pairing/redeem`,D);if(!h?.ok){l("This server needs a password or client token.");return}const H=await h.json().catch(()=>null),g=typeof H?.clientToken=="string"?H.clientToken.trim():"";if(!g){l("This server needs a password or client token.");return}const C=typeof H?.server?.label=="string"?H.server.label:"",z=v.label||C||Ze(ye({candidates:R}));if(ae()&&!await Se(re({candidates:R}),g)){l("This server needs a password or client token.");return}j({label:z,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(S){console.warn("[mobile-connect] pairing threw",S),l("This server needs a password or client token.")}finally{!O&&T?.kind==="relay"&&T.tunnel.close(),k("pairing")}},[y,k,e,j]),p=o.useCallback(async v=>{if(!c||!v.trim()||f.current==="password")return;l(null),y("password");const R=b.current.begin(),T=()=>b.current.isCurrent(R),{id:O,label:S,candidates:D}=c;let h=null,H=!1;try{if(h=await en(D),!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:v,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:Xt(),dedupeKey:Qt()})};oe("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(oe("password:done",{ok:C?.ok===!0,status:C?.status??null}),!C?.ok){l("Could not unlock that server. Check the password.");return}const z=await C.json().catch(()=>null);if(!T())return;const Y=typeof z?.clientToken=="string"?z.clientToken.trim():"";if(oe("password:token",{issued:!!Y}),!Y){if(h.kind==="direct"&&!ae()){j({id:O,label:S,candidates:D}),d(null),Ne({kind:"direct",url:h.url},null,{runtimeKey:re({candidates:D})}),e();return}l("This server needs a password or client token.");return}if(ae()&&(!T()||(await Se(re({candidates:D}),Y),!T()))||!T()||(j({id:O,label:S,candidates:D,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:D})}),H=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{!H&&h?.kind==="relay"&&h.tunnel.close(),T()&&k("password")}},[y,k,e,c,j]),m=o.useCallback(()=>{b.current.cancel(),k("password"),d(null),l(null)},[k]),N=o.useCallback(async v=>{l(null);let R=Zt(v);const T=v.id?u.current.find(h=>h.id===v.id)??null:null;if(T){const h=R.filter(C=>C.kind==="direct"),H=ot(T).filter(C=>C.url.startsWith("https://")&&!h.some(z=>On(z.url,C.url))),g=Ee(T);R=[...h,...H,...g?[{kind:"relay",relay:g}]:[]]}if(R.length===0)return l("Enter a server URL."),null;const O=v.clientToken?.trim()||void 0,S=v.label?.trim()||Ze(ye({candidates:R}));if(ae()){const h=re({candidates:R});if(O)await Se(h,O);else if(T?.hasToken){const H=re(T);if(H&&h&&H!==h){const g=await qe(H);g&&await Se(h,g)}}}return j({id:v.id,label:S,candidates:R,clientToken:O}).find(h=>st(h.candidates,R))??null},[j]),L=o.useCallback(async v=>{const R=u.current.find(O=>O.id===v)??null,T=await Ma(v);return x(T),R},[x]);return{connections:n,isBusy:r!==null,isPasswordBusy:r==="password",error:i,pendingConnection:c,connect:M,redeemPairingConnection:B,submitPassword:p,cancelPassword:m,saveConnection:N,removeConnection:L,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},Fa=()=>window.Capacitor?.getPlatform?.()==="android",Wn=e=>{const n=e.trim();if(!n)return null;if(/^pichamber:\/\//i.test(n)){const s=Or(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=$r(e);if(r)return{status:"pairing",pairing:r}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Ha=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(Fa())return Ha(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(te,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[t.jsx(V,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},Jn=()=>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(V,{name:"loader-4",className:"size-[18px] animate-spin"}),t.jsx("span",{children:"Connecting..."})]})]}),document.body),Ka=({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,y]=o.useState(""),[k,j]=o.useState(!1),[M,B]=o.useState(!1),p=o.useRef(null),m=o.useMemo(()=>kt(),[]),[N,L]=o.useState(()=>!kt()),[v,R]=o.useState(null),[T,O]=o.useState(""),S=o.useCallback(C=>{C.preventDefault(),s.connect({url:d,clientToken:x,label:f})},[x,s,f,d]),D=o.useCallback(C=>{if(/^pichamber:\/\//i.test(C.trim())){const z=Wn(C);if(z){if("pairing"in z){s.redeemPairingConnection(z.pairing);return}u(z.url),z.label&&b(z.label),z.clientToken&&y(z.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 z=await qn({signal:C.signal});switch(p.current===C&&(p.current=null,j(!1)),z.status){case"ok":B(!0),u(z.url),z.label&&b(z.label),z.clientToken&&y(z.clientToken),await s.connect({url:z.url,clientToken:z.clientToken,label:z.label});break;case"pairing":B(!0),await s.redeemPairingConnection(z.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{B(!1),p.current===C&&(p.current=null,j(!1))}},[s,a]);o.useEffect(()=>()=>p.current?.abort(),[]);const H=o.useCallback(C=>{C.preventDefault(),s.submitPassword(T)},[s,T]),g=o.useCallback(()=>{O(""),s.cancelPassword()},[s]);return t.jsxs(t.Fragment,{children:[k?t.jsx(Yn,{onCancel:()=>p.current?.abort()}):null,M?t.jsx(Jn,{}):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(V,{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:H,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(V,{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(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!T.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(te,{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(te,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{h()},disabled:k||a,children:[t.jsx(V,{name:"scan-2",className:K("size-[18px]",k&&"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&&!N?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 z=v===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(V,{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",z?"text-foreground":"text-muted-foreground"),children:z?"Connecting...":C.candidates.some(Y=>Y.kind==="direct")?ye(C):"via PiChamber Relay"})]}),z?t.jsx(V,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(V,{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:()=>L(C=>!C),"aria-expanded":N,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(V,{name:"arrow-down-s",className:K("size-4 transition-transform duration-200",N&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:N?"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:S,children:[t.jsx("input",{...Le,value:d,onChange:C=>D(C.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:N?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:N?void 0:-1,className:K(He,"text-center")}),t.jsx("input",{...Le,value:x,onChange:C=>y(C.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:N?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(te,{type:"submit",variant:m?"outline":"default",size:"lg",className:"h-12 w-full",disabled:a||k||!d.trim(),children:a?"Connecting...":"Connect"})]})})})]})]})]})})]})},nn=380,Va=e=>typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.min(100,Math.round(e))),Wa=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),Qn=({percentage:e})=>{const n=Va(e),s=Wa(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"})]})},Ga=({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(V,{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})]}),qa=({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 k=()=>{const B=s.current?.getBoundingClientRect(),p=f.current?.getBoundingClientRect();if(!B||!p){x(null);return}const m=B.left-p.left,N=Math.min(Math.max(m,8),Math.max(8,p.width-nn-8));x(N)};k();const j=f.current;if(typeof ResizeObserver>"u"||!j)return;const M=new ResizeObserver(k);return M.observe(j),()=>M.disconnect()},[s,u,e,i]);const y=u&&b!==null;return o.useEffect(()=>{if(e){l(!0),d(!1);return}if(!i)return;d(!0);const k=window.setTimeout(()=>{l(!1),d(!1)},140);return()=>window.clearTimeout(k)},[e,i]),o.useEffect(()=>{if(!e)return;const k=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[n,e]),o.useEffect(()=>{if(!e)return;const k=j=>{const M=j.target;if(!(M instanceof Node)){n();return}a.current?.contains(M)||s.current?.contains(M)||n()};return document.addEventListener("pointerdown",k,!0),document.addEventListener("wheel",k,!0),()=>{document.removeEventListener("pointerdown",k,!0),document.removeEventListener("wheel",k,!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",y?"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))",...y?{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(Ga,{iconNode:t.jsx(Qn,{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},Ya=o.memo(function({open:n,onOpenChange:s,currentSessionId:r,effectiveDirectory:a,isNewSessionDraftOpen:i}){const l=o.useRef(null),c=$s(r??""),d=le(h=>h.providers),u=le(h=>h.currentProviderId),f=le(h=>h.currentModelId),b=le(h=>h.getCurrentModel()),x=le(h=>h.getModelMetadata);le(h=>h.modelsMetadata.size);const y=Us(o.useCallback(h=>r?h.sessionModelSelections.get(r)??null:null,[r])),k=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const H=c[h]?.info;if(H.role!=="user")continue;const g=H.model,C=g?.providerID??g?.providerId,z=g?.modelID??g?.modelId,Y=typeof C=="string"&&C.trim().length>0?C:void 0,Q=typeof z=="string"&&z.trim().length>0?z:void 0;if(Y&&Q)return{providerID:Y,modelID:Q}}return null},[c]),j=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const H=c[h];if(H?.info.role==="assistant"&&zt(H).total>0)return H}return null},[c]),M=k??(()=>{const h=j?.info.model,H=h?.providerID??h?.providerId,g=h?.modelID??h?.modelId;return H&&g?{providerID:H,modelID:g}:null})()??(y?{providerID:y.providerId,modelID:y.modelId}:null)??(u&&f?{providerID:u,modelID:f}:null),p=(M?d.find(h=>h.id===M.providerID):void 0)?.models.find(h=>h.id===M?.modelID),m=M?x(M.providerID,M.modelID):void 0,N=sn(p?.limit,"context")??m?.limit?.context??sn(b?.limit,"context")??0,L=j?zt(j):null,v=j?.info?.usage,R=v?Bs(v):L?.total??0,T=!i&&R>0&&N>0?Math.min(R/N*100,999):null,O=T!==null?`${rn(R)}/${rn(N)}`:null,S=T===null?"":T>=90?"text-[var(--status-error)]":T>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",D=T!==null&&O?{percentage:T,tokens:O,colorClass:S}: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(Qn,{percentage:D?.percentage??0})}),t.jsx(qa,{open:n,onClose:()=>s(!1),anchorRef:l,contextDisplay:D})]})}),Ja=10,an=380,Qa=(e,n)=>e.title?.trim()||n,Xa=({session:e,meta:n,active:s,onSelect:r})=>{const a=Hs(e.id),i=Ks(e.id),l=a?.type??"idle",c=l==="busy"||l==="retry",d=!c&&i>0&&!s,u=Vs(e.id,c),f=c&&u,b=Ws(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:Qa(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(Gs,{label:"Session complete"}):null,f?t.jsx(qs,{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]})},Za=({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 L=s.current?.getBoundingClientRect(),v=u.current?.getBoundingClientRect();if(!L||!v){b(null);return}const R=L.left-v.left;b(Math.min(Math.max(R,8),Math.max(8,v.width-an-8)))};p();const m=u.current;if(typeof ResizeObserver>"u"||!m)return;const N=new ResizeObserver(p);return N.observe(m),()=>N.disconnect()},[s,d,e,a]);const x=d&&f!==null,y=fe(p=>p.currentSessionId),k=fe(p=>p.setCurrentSession),j=Rn(p=>p.setActiveProjectIdOnly),M=Fs(e||a,{maxParents:Ja});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 N=m.target;if(!(N instanceof Node)){n();return}r.current?.contains(N)||s.current?.contains(N)||n()};return document.addEventListener("pointerdown",p,!0),()=>document.removeEventListener("pointerdown",p,!0)},[s,n,e]);const B=o.useCallback(p=>{k(p.id,jt(p)),n()},[n,k]);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:M.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):M.map(p=>{const m=p.node.session,N=[p.secondaryMeta?.projectLabel,p.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(Xa,{session:m,meta:N,active:m.id===y,onSelect:()=>{p.projectId&&j(p.projectId),B(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},eo=({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=fe(m=>m.currentSessionId),b=fe(o.useCallback(m=>u?m.getDirectoryForSession(u):null,[u]))||d,x=Ys(u),y=fe(m=>!!m.newSessionDraft?.open),j=x?.title?.trim()||(u?"Untitled session":"New session");o.useEffect(()=>{a(!1),l(!1)},[u,b]);const M=o.useCallback(()=>{a(!1),l(!1),e()},[e]),B=o.useCallback(m=>{a(N=>{const L=typeof m=="function"?m(N):m;return L&&l(!1),L})},[]),p=o.useCallback(()=>{l(m=>{const N=!m;return N&&a(!1),N})},[]);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:M,style:{touchAction:"manipulation"},children:t.jsx(V,{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(V,{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(Ya,{open:r,onOpenChange:B,currentSessionId:u,effectiveDirectory:b,isNewSessionDraftOpen:y}),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(V,{name:"layout-right",className:"size-5"})})]})}),t.jsx(Za,{open:i,onClose:()=>l(!1),anchorRef:c})]})},to=({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:y}=s,[k,j]=o.useState(null),M=k?r.find($=>$.id===k)??null:null,[B,p]=o.useState(null),[m,N]=o.useState(""),[L,v]=o.useState(""),[R,T]=o.useState(""),[O,S]=o.useState(""),[D,h]=o.useState(!1),[H,g]=o.useState(!1),[C,z]=o.useState(!1),[Y,Q]=o.useState(null),J=o.useRef(null),I=o.useMemo(()=>kt(),[]),[q,W]=o.useState(!1),[w,E]=o.useState(null),A=o.useCallback(()=>{j(null),N(""),v(""),T(""),y(null),W(!1)},[y]),F=o.useCallback($=>{$.preventDefault(),b({id:k??void 0,url:m,label:L,clientToken:R}).then(Z=>{Z&&A()})},[R,k,L,A,b,m]),ee=o.useCallback(async()=>{if(J.current)return;y(null),h(!0);const $=new AbortController;J.current=$;try{const Z=await qn({signal:$.signal});switch(J.current===$&&(J.current=null,h(!1)),Z.status){case"ok":N(Z.url),Z.label&&v(Z.label),Z.clientToken&&T(Z.clientToken),W(!0);break;case"pairing":g(!0),await s.redeemPairingConnection(Z.pairing);break;case"permission-denied":y("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":y("That QR code is not an PiChamber connection code.");break;case"unsupported":y("QR scanning is only available in the installed mobile app.");break;case"failed":y("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{g(!1),J.current===$&&(J.current=null,h(!1))}},[s,y]);o.useEffect(()=>()=>J.current?.abort(),[]);const X=o.useCallback($=>{$.preventDefault(),u(O)},[O,u]),U=o.useCallback(()=>{S(""),f()},[f]),ge=o.useCallback(async()=>{if(!C){Q(null),z(!0);try{const $=await cs();Q($==="copied"?"Diagnostics copied to the clipboard.":$==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{Q("Diagnostics export was cancelled or unavailable.")}finally{z(!1)}}},[C]),pe=o.useCallback($=>{p(Z=>Z===$?null:$)},[]),Pe=o.useCallback($=>{p(null),k===$&&A();const Z=r.length===1;x($).then(me=>{me&&(Z||tn(me))&&e()})},[r.length,k,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:X,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(V,{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:$=>S($.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(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:i||!O.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(te,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:U,children:"Use another server"})]})})}):t.jsxs(t.Fragment,{children:[D?t.jsx(Yn,{onCancel:()=>J.current?.abort()}):null,H?t.jsx(Jn,{}):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 Z=B===$.id,me=tn($),Ie=w===$.id,ct=Ie?"Connecting...":me?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",Z&&"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:()=>{me||(E($.id),d({id:$.id,candidates:$.candidates,clientToken:$.clientToken,label:$.label}).finally(()=>E(null)))},disabled:a&&!Ie||Z,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(V,{name:"server",className:"size-[18px]"}),me?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",me&&!Ie?"text-[var(--status-success)]":"text-muted-foreground"),children:ct})]}),Ie?t.jsx(V,{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:[Z?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(V,{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),N(ye($)),v($.label),T($.clientToken||""),y(null)},style:{touchAction:"manipulation"},children:t.jsx(V,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":Z?`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:()=>pe($.id),style:{touchAction:"manipulation"},children:t.jsx(V,{name:Z?"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(te,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{ge()},disabled:C,children:[t.jsx(V,{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&&!M?t.jsxs("div",{className:"space-y-2",children:[I?t.jsxs(te,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{ee()},disabled:D,children:[t.jsx(V,{name:"scan-2",className:K("size-[18px]",D&&"animate-pulse")}),"Scan QR code"]}):null,t.jsxs(te,{type:"button",variant:I?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{y(null),W(!0)},children:[t.jsx(V,{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:M?"Edit instance":"Add instance"}),t.jsx(te,{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:$=>N($.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:L,onChange:$=>v($.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(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:M?"Save changes":"Save instance"})]})]})})})]})},no=16,so=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=fe(y=>y.openNewSessionDraft),i=ce(y=>y.setActiveMainTab),l=ce(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:no);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 k=j=>{j.key==="Escape"&&r()};return document.addEventListener("keydown",k),()=>{document.body.style.overflow=y,document.removeEventListener("keydown",k)}},[r,e,s]);const f=o.useCallback(()=>{ce.getState().closeMainSurfaces(),i("chat"),l(!1),a(),r()},[r,a,i,l]),b=t.jsx(vs,{mobileVariant:!0,isVisible:!0,allowReselect:!0,onSessionSelected:r,onNavigateAway:r});if(s==="sidebar")return t.jsxs("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:[b,t.jsx(te,{type:"button",variant:"outline",size:"lg",className:"absolute z-20 size-12 rounded-full p-0 [corner-shape:round] supports-[corner-shape:squircle]:rounded-full",style:{right:"1rem",bottom:"calc(1rem + var(--oc-safe-area-bottom, 0px))"},onClick:f,"aria-label":"New session",children:t.jsx(V,{name:"chat-new",className:"size-5"})})]});if(typeof document>"u")return null;const x=u?0:so;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 ${x}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:x?`transform ${x}ms ${on}`:"none"},children:b}),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(te,{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(V,{name:"chat-new",className:"size-5"})}):null})]}),document.body)},cn="mobile-surface-root",ht=16,Qe=200,ro=()=>{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),[y,k]=o.useState(!1),[j,M]=o.useState(!1),B=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=ro()),o.useEffect(()=>{if(!e){k(!1);return}const v=window.setTimeout(()=>k(!0),ht);return()=>window.clearTimeout(v)},[e]),o.useEffect(()=>{if(!e){M(!1);return}const v=window.setTimeout(()=>M(!0),ht+Qe+80);return()=>window.clearTimeout(v)},[e]),o.useEffect(()=>{if(!e)return;const v=document.body.style.overflow;p.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const R=()=>{const S=B.current;if(!S)return;(S.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??S).focus({preventScroll:!0})},T=window.setTimeout(R,ht),O=S=>{if(S.key==="Escape"&&!i){m.current();return}if(S.key!=="Tab")return;const D=B.current;if(!D)return;const h=Array.from(D.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(z=>!z.hasAttribute("disabled")&&z.getAttribute("aria-hidden")!=="true");if(h.length===0){S.preventDefault(),D.focus({preventScroll:!0});return}const H=h[0],g=h[h.length-1],C=document.activeElement;S.shiftKey&&C===H?(S.preventDefault(),g.focus({preventScroll:!0})):!S.shiftKey&&C===g&&(S.preventDefault(),H.focus({preventScroll:!0}))};return document.addEventListener("keydown",O),()=>{window.clearTimeout(T),document.body.style.overflow=v,document.removeEventListener("keydown",O),p.current?.focus?.({preventScroll:!0}),p.current=null}},[i,e]),!e||!x.current)return null;const N=u==="dialog",L=t.jsxs("section",{ref:B,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:K("flex flex-col bg-background text-foreground",N?"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:N?{opacity:y?1:0,transform:y?"none":"scale(0.97)",transition:`opacity ${Qe}ms ease-out, transform ${Qe}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:y?"none":"translateX(100%)",transition:`transform ${Qe}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:v=>{y&&v.target===v.currentTarget&&v.propertyName==="transform"&&M(!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(V,{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 N?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:y?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:v=>v.stopPropagation(),children:L})}),x.current):ze.createPortal(L,x.current)},Xn={"?":{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"}},ao=Xn.M;function oo(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 io(e){const n=oo(e);return Xn[n]??ao}const lo=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 y=Ce.useMemo(()=>io(n),[n]),k=y.description,j=d?.insertions??0,M=d?.deletions??0,B=Ce.useCallback(L=>{L.key===" "?(L.preventDefault(),a()):L.key==="Enter"&&(L.preventDefault(),i())},[a,i]),p=Ce.useCallback(L=>{L.preventDefault(),L.stopPropagation(),a()},[a]),m=Ce.useCallback(L=>{L.preventDefault(),L.stopPropagation(),l()},[l]),N=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:B,style:f>0?{paddingLeft:`${f}px`}:void 0,children:[b?N:null,t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:y.color},title:k,"aria-label":k,children:y.code}),t.jsx(Pn,{filePath:n.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const L=n.path.lastIndexOf("/");if(L===-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 v=n.path.slice(0,L),R=n.path.slice(L);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:v}),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:["-",M]})]}),x?t.jsxs(Js,{children:[t.jsx(Qs,{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(V,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(V,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(Xs,{sideOffset:8,children:"Revert changes"})]}):null,b?null:N]})}),dn=14,Zn=e=>e.replace(/\\/g,"/").replace(/^\/+/,"").trim(),un=(e,n)=>({id:`dir:${e}`,path:e,name:n,children:new Map,directFiles:[],files:[]}),co=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},uo=(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},fo=1e3,fn=34,yt=30,Xe="pl-0 pr-2",bt=(e,n)=>`${e} ${n}`,po=({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=ce(w=>w.gitChangesViewMode)==="tree",b=o.useMemo(()=>e.filter(w=>w.entries.length>0),[e]),[x,y]=o.useState(new Set),[k,j]=o.useState(new Set),[M,B]=o.useState(!1),[p,m]=o.useState(null),N=o.useMemo(()=>b.map(w=>co(w.entries)),[b]),L=o.useMemo(()=>{const w=[];return b.forEach((E,A)=>{Array.from(N[A]?.children.values()??[]).forEach(F=>{w.push(bt(E.id,F.path))})}),w},[N,b]);o.useEffect(()=>{f&&j(w=>{const E=new Set,A=new Set(L);return w.forEach(F=>{(F.slice(F.indexOf(" ")+1).includes("/")||A.has(F))&&E.add(F)}),L.forEach(F=>E.add(F)),E})},[f,L]);const v=o.useMemo(()=>{const w=[];return b.forEach((E,A)=>{if(w.push({type:"header",key:`header:${E.id}`,groupIndex:A}),!x.has(E.id)){if(f){const F=new Set;k.forEach(X=>{X.startsWith(`${E.id} `)&&F.add(X.slice(E.id.length+1))}),uo(N[A],F).forEach(X=>{X.kind==="file"?w.push({type:"file",key:`${E.id}:${X.key}`,groupIndex:A,file:X.file,depth:X.depth}):w.push({type:"directory",key:`${E.id}:${X.key}`,groupIndex:A,directory:X.directory,depth:X.depth})});return}E.entries.forEach(F=>{w.push({type:"file",key:`${E.id}:file:${F.path}`,groupIndex:A,file:F,depth:0})})}}),l&&b.length>0&&w.push({type:"revert-all",key:"revert-all"}),w},[x,k,f,l,N,b]),R=v.length,T=R>=fo,O=Kr({count:R,enabled:T,getScrollElement:()=>d.current,estimateSize:()=>fn,overscan:12,getItemKey:w=>v[w]?.key??w}),S=O.getVirtualItems(),D=o.useMemo(()=>{if(!T)return 0;const w=d.current?.scrollTop??0;return S.find(A=>A.end>w)?.index??0},[T,S,d]);o.useEffect(()=>{if(!i)return;const w=E=>E&&E.type==="file"?E.file.path:null;if(R===0){i([]);return}if(!T){const E=[];for(const A of v)if(A.type==="file"&&(E.push(A.file.path),E.length>=yt))break;i(E);return}i(v.slice(D,D+Math.ceil((d.current?.clientHeight??0)/fn)+yt).map(E=>w(E)).filter(E=>!!E).slice(0,yt))},[i,R,v,T,D]);const h=o.useCallback(w=>{y(E=>{const A=new Set(E);return A.has(w)?A.delete(w):A.add(w),A})},[]),H=o.useCallback((w,E)=>{j(A=>{const F=new Set(A),ee=bt(w,E);return F.has(ee)?F.delete(ee):F.add(ee),F})},[]),g=o.useMemo(()=>{const w=new Set;return b.forEach(E=>E.entries.forEach(A=>w.add(A.path))),Array.from(w)},[b]),C=g.length,z=p?r||p.paths.some(w=>s.has(w)):!1,Y=o.useCallback(async()=>{!l||r||g.length===0||(await l(g),B(!1))},[g,r,l]),Q=o.useCallback(async()=>{!c||!p||z||(await c(p.paths),m(null))},[z,c,p]),J=o.useCallback((w,E)=>{const A=x.has(w.id),F=w.entries.length;return t.jsxs("div",{className:K("sticky top-0 z-10 flex items-center gap-2 py-2",a,Xe,!E&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>w.onActionAll(w.entries.map(ee=>ee.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":w.actionAllLabel,title:w.actionAllLabel,children:w.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>h(w.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:w.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),t.jsx(V,{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((w,E,A)=>{const F=k.has(bt(w.id,E.path)),ee=E.files.map(U=>U.path),X=r||ee.some(U=>s.has(U));return t.jsxs("div",{className:K("group flex items-center gap-2 py-1.5",Xe),style:{paddingLeft:`${A*dn}px`},children:[t.jsxs("button",{type:"button",onClick:()=>H(w.id,E.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 ${E.path}`:`Expand directory ${E.path}`,children:[F?t.jsx(V,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(V,{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:E.path,children:E.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:E.files.length})]}),w.showRevertActions!==!1&&c?t.jsx("button",{type:"button",onClick:()=>m({path:E.path,paths:ee,count:ee.length}),disabled:X,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 ${E.path}`,title:"Revert folder changes",children:X?t.jsx(V,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(V,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>w.onActionAll(E.files.map(U=>U.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":w.actionSymbol==="+"?`Stage all changes in ${E.path}`:`Unstage all changes in ${E.path}`,title:w.actionSymbol==="+"?`Stage all changes in ${E.path}`:`Unstage all changes in ${E.path}`,children:w.actionSymbol})]})},[k,r,c,s,H]),q=o.useCallback((w,E)=>{if(w.type==="revert-all")return t.jsx("div",{className:K("flex justify-end py-2",Xe),children:t.jsxs(te,{variant:"ghost",size:"sm",onClick:()=>B(!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(V,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const A=b[w.groupIndex];if(!A)return null;if(w.type==="header")return J(A,E);if(w.type==="directory")return I(A,w.directory,w.depth);const F=w.file;return t.jsx(lo,{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:Xe,indentPx:w.depth*dn,actionAtStart:!f,showRevert:A.showRevertActions!==!1})},[n,r,f,I,J,s,b]),W=o.useCallback(w=>{const E=v[w],A=v[w-1];return!E||!A||E.type!=="file"&&E.type!=="directory"||A.type!=="file"&&A.type!=="directory"?!1:A.groupIndex===E.groupIndex},[v]);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:S.map(w=>{const E=v[w.index];return E?t.jsx("div",{"data-index":w.index,ref:O.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${w.start}px)`},className:K(W(w.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(E,w.index===0)},E.key):null})}):t.jsx("div",{role:"list","aria-label":"Changed files",children:v.map((w,E)=>t.jsx("div",{className:K("relative",W(E)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:q(w,E===0)},w.key))})}),t.jsx(Zs,{containerRef:d,disableHorizontal:!0})]}),t.jsx(Ot,{open:M,onOpenChange:w=>{!r&&!w&&B(!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(te,{variant:"outline",size:"sm",onClick:()=>B(!1),disabled:r,children:"Cancel"}),t.jsx(te,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:r,children:r?"Reverting...":"Revert all"})]})]})}),t.jsx(Ot,{open:!!p,onOpenChange:w=>{!z&&!w&&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(te,{variant:"outline",size:"sm",onClick:()=>m(null),disabled:z,children:"Cancel"}),t.jsx(te,{variant:"destructive",size:"sm",onClick:()=>{Q()},disabled:z||!p,children:z?"Reverting...":"Revert folder"})]})]})})]})},mo=lr(()=>he(()=>import("./DiffView-k3lX2PiV.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}))),ho=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),go=e=>{const n=e.index?.trim();return!!(n&&n!=="?")},yo=e=>{const n=e.working_dir?.trim(),s=e.index?.trim();return!!(n||s==="?")},pn=(e,n)=>n?`${e}\0staged`:e,bo=({onClose:e,initialDiffPath:n,initialDiffStaged:s=!1})=>{const{git:r}=In(),a=ho(Nt()??null),i=er(a||null),l=tr(a||null),c=nr(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),y=be(P=>P.getDiff),k=be(P=>P.setDiff),[j,M]=o.useState(()=>n?{type:"diff",path:n,staged:s}:{type:"list"});o.useEffect(()=>{n&&M(P=>P.type==="diff"&&P.path===n&&P.staged===s?P:{type:"diff",path:n,staged:s})},[n,s]);const[B,p]=o.useState(null),[m,N]=o.useState(null),[L,v]=o.useState(""),[R,T]=o.useState(new Set),[O,S]=o.useState(!1),[D,h]=o.useState(!1),[H,g]=o.useState([]),[C,z]=o.useState([]),[Y,Q]=o.useState([]),[J,I]=o.useState(null),[q,W]=o.useState(null),[w,E]=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,ne)=>G.path.localeCompare(ne.path))},[i?.files]),F=o.useMemo(()=>A.filter(go),[A]),ee=o.useMemo(()=>A.filter(yo),[A]),X=o.useMemo(()=>{if(Y.length>0)return Y;const P=i?.tracking?.includes("/")?i.tracking.split("/")[0]:null;return P||J?[{name:P||"origin",fetchUrl:J??"",pushUrl:J??""}]:[]},[J,Y,i?.tracking]),U=be(o.useCallback(P=>!a||j.type!=="diff"?null:P.directories.get(a)?.diffCache.get(pn(j.path,j.staged))??null,[a,j])),ge=o.useMemo(()=>j.type!=="diff"?null:A.find(P=>P.path===j.path)??null,[A,j]),pe=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){Q([]),I(null);return}try{const[P,_]=await Promise.all([r.getRemotes(a).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(a).catch(()=>null):Promise.resolve(null)]);Q(P),I(_)}catch{Q([]),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"){W(null);return}const P=pn(j.path,j.staged);if(!a||y(a,P)){W(null);return}let _=!1;const G=Ye();return W(null),r.getGitFileDiff(a,{path:j.path,staged:j.staged||void 0}).then(ne=>{_||k(a,P,{original:ne.original??"",modified:ne.modified??"",isBinary:ne.isBinary},G)}).catch(ne=>{_||W(ne instanceof Error?ne.message:String(ne))}),()=>{_=!0}},[a,w,y,r,j,k]);const je=async(P,_)=>{if(a){p(P);try{const G=ne=>{const Ae=`${ne.name}/`,ut=i?.tracking?.startsWith(Ae)?i.tracking.slice(Ae.length):void 0;return{remote:ne.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 ne=await r.getGitStatus(a);if((ne.behind??0)>0){if((ne.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 pe(!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 sr(a,P):await rr(a,P[0]):P.length>1?await ar(a,P):await or(a,P[0]),await pe(!1)}catch(G){se.error(G instanceof Error?G.message:_==="stage"?"Failed to stage changes":"Failed to unstage changes")}},[a,pe]),Z=o.useCallback((P,_=!1)=>{M({type:"diff",path:P,staged:_})},[]),me=o.useCallback(async P=>{if(a){T(_=>new Set(_).add(P));try{await r.revertGitFile(a,P),se.success(`Reverted ${P}`),await pe(!1)}catch(_){se.error(_ instanceof Error?_.message:"Failed to revert changes")}finally{T(_=>{const G=new Set(_);return G.delete(P),G})}}},[a,r,pe]),Ie=o.useCallback(async P=>{if(!a||P.length===0||O)return;const _=Array.from(new Set(P));S(!0),T(new Set(_));try{await Promise.all(_.map(G=>r.revertGitFile(a,G))),await pe(!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),S(!1)}},[a,r,O,pe]),ct=o.useCallback(P=>{const _=P.map(G=>G.trim()).filter(Boolean);if(_.length===0){g([]);return}v(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 ir(a,P);v(_.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(!L.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}N(P.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(a,L.trim(),{files:_}),se.success("Commit created"),v(""),g([]),P.pushAfter){const G=i?.tracking?.split("/")[0],ne=X.find(as=>as.name===G)??X[0];if(!ne)throw new Error("No remote available");p("sync");const Ae=`${ne.name}/`,ut=i?.tracking?.startsWith(Ae)?i.tracking.slice(Ae.length):void 0;await r.gitFetch(a,{remote:ne.name}),((await r.getGitStatus(a)).behind??0)>0&&await r.gitPull(a,{remote:ne.name,branch:ut,rebase:!0}),((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),await pe(!1),await Pe()}else await pe(!1)}catch(G){se.error(G instanceof Error?G.message:"Failed to create commit")}finally{N(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:_=>Z(_,!0),onRevertFile:me,showRevertActions:!1,accent:!0}),ee.length>0&&P.push({id:"unstaged",title:"Changes",entries:ee,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:_=>`Stage ${_}`,onActionFile:_=>{$([_],"stage")},onActionAll:_=>{$(_,"stage")},onViewDiff:_=>Z(_,!1),onRevertFile:me}),P},[me,Z,$,F,ee]),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(mo,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):j.type==="diff"?t.jsx(xo,{path:j.path,diff:U,fileExists:!!ge,error:q,onBack:()=>M({type:"list"}),onRetry:()=>E(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(V,{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:B,remotes:X,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(po,{groups:rs,diffStats:i?.diffStats,revertingPaths:R,onRevertAll:Ie,isRevertingAll:O,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:z})}),t.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:t.jsx(Vr,{stagedCount:F.length,commitMessage:L,onCommitMessageChange:v,generatedHighlights:H,onInsertHighlights:ct,onGenerateMessage:Be,isGeneratingMessage:D,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(V,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,r?t.jsx(V,{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]})}),xo=({path:e,diff:n,fileExists:s,error:r,onBack:a,onRetry:i})=>{const l=o.useMemo(()=>cr(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(V,{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(te,{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."}):dr(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(Wr,{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."})})]})},ie=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),_e=e=>{const n=ie(e);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},es=e=>{const n=ie(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=ie(e),r=ie(n);return!s||!r?!1:s===r||s.startsWith(`${r}/`)},hn=(e,n)=>{const s=ie(e);if(!s)return ie(n);if(s.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(s))return s;const r=ie(n);return r?`${r}/${s}`:s},vo=(e,n)=>{const s=ie(e),r=ie(n);if(!s||s===r)return!1;const a=es(s);return a?r&&mn(s,r)?mn(a,r):!0:!1},wo=o.lazy(()=>he(()=>import("./FilesView-C39IOFfs.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,127])).then(e=>({default:e.FilesView}))),ko=(e,n)=>{const s=ie(e),r=ie(n);return!r||s===r?_e(s):s.startsWith(`${r}/`)?s.slice(r.length+1):s},jo=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""},So=({onClose:e})=>{const{files:n}=In(),s=ds(g=>g.setSelectedPath),r=ie(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,y]=o.useState(""),[k,j]=o.useState([]),[M,B]=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,N=o.useCallback(async g=>{if(!g)return;const C=p.current+1;p.current=C,u(!0),b(null);try{const z=await n.listDirectory(g);if(p.current!==C)return;c(z.entries.slice().sort((Q,J)=>Q.isDirectory!==J.isDirectory?Q.isDirectory?-1:1:Q.name.localeCompare(J.name)));const Y=ie(z.directory);Y&&Y!==ie(g)&&i(Q=>Q.type==="browser"&&Q.directory!==Y?{type:"browser",directory:Y}:Q)}catch(z){if(p.current!==C)return;c([]),b(z instanceof Error?z.message:"Failed to load files")}finally{p.current===C&&u(!1)}},[n]);o.useEffect(()=>{a.type==="browser"&&N(a.directory)},[N,a]),o.useEffect(()=>{if(a.type!=="browser")return;const g=x.trim();if(!g){j([]),B(!1);return}let C=!1;const z=window.setTimeout(()=>{B(!0),n.search({directory:a.directory,query:g,maxResults:40}).then(Y=>{C||j(Y)}).catch(()=>{C||j([])}).finally(()=>{C||B(!1)})},250);return()=>{C=!0,window.clearTimeout(z)}},[n,x,a]);const L=g=>{y(""),i({type:"browser",directory:g})},v=g=>{s(r,g),i({type:"file",path:g,returnDirectory:m||r})},R=ce(g=>g.pendingFileFocusPath),T=ce(g=>g.pendingFileNavigation);if(o.useEffect(()=>{const g=ie(T?.path??R??"");!g||!r||g!==r&&!g.startsWith(`${r}/`)||(s(r,g),i({type:"file",path:g,returnDirectory:r}),R&&ce.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(ue,{children:t.jsx(o.Suspense,{fallback:t.jsx(Ve,{loading:!0,message:"Loading..."}),children:t.jsx(wo,{mode:"editor-only"})})})})]});const O=a.directory===r?"Project files":_e(a.directory),S=x.trim()?k:[],D=vo(a.directory,r)?es(a.directory):null,h=!!D&&!x.trim(),H=D===r?"Project files":_e(D??"");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(Gr,{className:"size-4"})}):null,h&&D?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(D)}`,onClick:()=>L(D),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:()=>{N(a.directory)},style:{touchAction:"manipulation"},children:t.jsx(qr,{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(Yr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ur,{value:x,onChange:g=>y(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(Co,{results:S,isSearching:M,onOpenFile:v}):t.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[h&&D?t.jsxs("button",{type:"button",className:An,"aria-label":`Up one level to ${H}`,onClick:()=>L(D),style:{touchAction:"manipulation"},children:[t.jsx(V,{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:jo(g.size),onClick:()=>g.isDirectory?L(hn(g.path,a.directory||r)):v(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(Xr,{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(Zr,{className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),Co=({results:e,isSearching:n,onOpenFile:s})=>{const r=ie(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:ko(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(Jr,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Qr,{className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),gn="mobile-surface-root",No=16,yn=320,bn="cubic-bezier(0.22, 1, 0.36, 1)",Eo=[{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 y=o.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[k,j]=o.useState(()=>new Set);if(o.useEffect(()=>{e&&j(m=>{if(m.has(s))return m;const N=new Set(m);return N.add(s),N})},[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 N=window.setTimeout(()=>d(!0),y?0:No);return()=>window.clearTimeout(N)}d(!1);const m=window.setTimeout(()=>f(!1),yn+40);return()=>window.clearTimeout(m)},[e,y]),o.useEffect(()=>{if(!e)return;const m=document.body.style.overflow;i==="drawer"&&(document.body.style.overflow="hidden");const N=L=>{L.key==="Escape"&&x.current!=="terminal"&&b.current()};return document.addEventListener("keydown",N),()=>{i==="drawer"&&(document.body.style.overflow=m),document.removeEventListener("keydown",N)}},[e,i]),i==="drawer"&&!l.current)return null;const M=y?0:yn,B=t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",role:"tablist","aria-label":"Workspace",children:Eo.map(m=>{const N=s===m.id;return t.jsxs("button",{type:"button",role:"tab","aria-selected":N,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",N?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(V,{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:B}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[k.has("changes")?t.jsx("div",{className:K("h-full",s!=="changes"&&"hidden"),children:t.jsx(ue,{children:t.jsx(bo,{initialDiffPath:a?.path??null,initialDiffStaged:a?.staged===!0})})},a?`changes:${a.path}:${a.staged}`:"changes"):null,k.has("files")?t.jsx("div",{className:K("h-full",s!=="files"&&"hidden"),children:t.jsx(ue,{children:t.jsx(So,{})})}):null,k.has("terminal")?t.jsx("div",{className:K("h-full",s!=="terminal"&&"hidden"),children:t.jsx(ue,{children:t.jsx(ks,{visible:e&&s==="terminal"})})}):null,k.has("notes")?t.jsx("div",{className:K("h-full",s!=="notes"&&"hidden"),children:t.jsx(ue,{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:M?`opacity ${M}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:M?`transform ${M}ms ${bn}`:"none"},children:p})]}),l.current)},Je=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",To=()=>{o.useEffect(()=>{if(!Je())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(fr());const a=i=>{s.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(i))}px`)};return he(()=>import("./vendor-capacitor-status-bar-B-N0EOVk.js"),__vite__mapDeps([128,129])).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"),y=(x?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(x?"#171515":"#fffdf4");await i.setOverlaysWebView({overlay:!1}).catch(()=>{}),await i.setBackgroundColor({color:y}).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 he(async()=>{const{App:x}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:x}},__vite__mapDeps([130,8,129])),b=await f.addListener("appStateChange",({isActive:x})=>{x&&d()});if(e){b.remove();return}n.push(()=>{b.remove()})}).catch(()=>{}),he(()=>import("./vendor-capacitor-keyboard-CYccoJjr.js"),__vite__mapDeps([131,129])).then(async({Keyboard:i})=>{if(e)return;if(window.Capacitor?.getPlatform?.()==="android"){const S=await i.addListener("keyboardWillShow",C=>{Kt(C.keyboardHeight),s.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),D=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")}),H=await i.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),g=()=>{S.remove(),D.remove(),h.remove(),H.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,y=!1,k=0,j=!1;const M=(S,D)=>{s.style.setProperty(S,`${Math.max(0,Math.round(D))}px`)},B=()=>{f!==null&&(window.clearTimeout(f),f=null)},p=(S,D)=>{window.dispatchEvent(new CustomEvent(S,{detail:D}))},m=()=>{const S=[],D=document.querySelector(".oc-mobile-composer");D&&S.push({el:D,factor:1});const h=document.querySelector(".oc-draft-center");return h&&S.push({el:h,factor:.5}),S},N=()=>{for(const{el:S}of m())S.style.transition="",S.style.transform=""},L=await i.addListener("keyboardWillShow",S=>{if(B(),Kt(S.keyboardHeight),j=!0,x=S.keyboardHeight,!y){const h=document.querySelector(".oc-mobile-app-shell");k=h&&parseFloat(getComputedStyle(h).paddingBottom)||0}const D=Math.max(0,x-k);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:H}of m())h.style.transition=`transform ${c}ms ${u}`,h.style.transform=`translateY(${-D*H}px)`;M("--oc-kb-scroll-inset",D),p("oc:keyboard-settled",{open:!0}),p("oc:keyboard-anim",{phase:"show",slide:D,durationMs:c,easing:u}),f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating"),M("--oc-kb-layout",x),y=!0,N(),p("oc:keyboard-settled",{open:!0}),b=window.setTimeout(()=>{b=null,s.classList.remove("oc-kb-caret-hold")},250)},c+20)}),v=()=>{if(!j)return;j=!1,B(),p("oc:keyboard-intent",{open:!1}),b!==null&&(window.clearTimeout(b),b=null),s.classList.remove("oc-kb-caret-hold");const S=Math.max(0,x-k);if(s.classList.remove("oc-keyboard-open"),a(0),M("--oc-kb-scroll-inset",0),y){s.classList.remove("oc-kb-animating"),M("--oc-kb-layout",0),y=!1;for(const{el:D,factor:h}of m())D.style.transition="none",D.style.transform=`translateY(${-S*h}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}p("oc:keyboard-anim",{phase:"hide",slide:S,durationMs:d,easing:u}),s.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:D}of m())D.style.transition=`transform ${d}ms ${u}`,D.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,s.classList.remove("oc-kb-animating","oc-kb-hide"),N(),p("oc:keyboard-settled",{open:!1})},d+20)},R=await i.addListener("keyboardWillHide",v),T=S=>S instanceof HTMLElement&&(S.tagName==="TEXTAREA"||S.tagName==="INPUT"||S.isContentEditable),O=S=>{j&&T(S.target)&&(T(S.relatedTarget)||window.setTimeout(()=>{j&&(T(document.activeElement)||v())},0))};if(document.addEventListener("focusout",O,!0),e){B(),document.removeEventListener("focusout",O,!0),L.remove(),R.remove();return}n.push(B,()=>{b!==null&&(window.clearTimeout(b),b=null)},()=>document.removeEventListener("focusout",O,!0),()=>{L.remove()},()=>{R.remove()})}).catch(()=>{}),()=>{e=!0,n.forEach(i=>i()),pr(),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")}},[])},Ro=e=>{const n=o.useRef(!1);o.useEffect(()=>{if(!Je())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)),he(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([130,8,129])).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])},Po=e=>{o.useEffect(()=>{if(!Je())return;let n=!1,s=null;return he(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([130,8,129])).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 Io(e=2500){const{uiFont:n}=mr(),[s,r]=o.useState(!1);return o.useEffect(()=>{let a=!1;const i=()=>{a||r(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(i))},c=Promise.all([hr(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),ea.catch(()=>{})]).then(()=>{}),d=new Promise(u=>{window.setTimeout(u,e)});return Promise.race([c,d]).then(l),()=>{a=!0}},[n,e]),s}const Ao="pichamber",Do=e=>e.replace(/^\/+|\/+$/g,""),Mo=e=>{const n=Do(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...n]:n};function _o(e){if(typeof e!="string"||e.length===0)return null;let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`${Ao}:`)return null;const s=Mo(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 de={},ns=!1,Ke=null;const Lo=e=>{switch(e.type){case"session":return fe.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const n=fe.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 de.openSessions?(de.openSessions(e.filter),!0):!1;case"status":return de.openSessions?(de.openSessions(),!0):!1;case"view":return de.openView?(de.openView(e.target),!0):!1;case"changes":return de.openChanges?(de.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return de.openSettings?(de.openSettings(e.section),!0):!1}},Dt=()=>{if(!ns||!Ke)return;const e=Ke;Ke=null,Lo(e)||(Ke=e)},ss=e=>{Ke=e,Dt()},vn=e=>{const n=_o(e);n&&ss(n)},zo=e=>{ns=e,Dt()},Oo=e=>{o.useEffect(()=>(de=e,Dt(),()=>{de===e&&(de={})}),[e])},$o=e=>{const{ready:n}=e;o.useEffect(()=>{zo(n)},[n]),o.useEffect(()=>{if(!ae())return;let s=!1;const r=[];return he(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([130,8,129])).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(()=>{}),he(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([132,129])).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())}},[])},Uo=32,Bo=80,Fo=64,Ho=.7,Ko=(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"?Bo:Uo;let l=!1,c=!1,d=0,u=0;const f=x=>{if(x.touches.length!==1){l=!1;return}const y=x.touches[0],k=r.clientWidth,j=y.clientX<=i,M=y.clientX>=k-i;l=j||M,c=j,d=y.clientX,u=y.clientY},b=x=>{if(!l)return;l=!1;const y=x.changedTouches[0];if(!y)return;const k=y.clientX-d,j=y.clientY-u;Math.abs(k)<Fo||Math.abs(j)>Math.abs(k)*Ho||c&&k<=0||!c&&k>=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])},Vo=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},Wo=()=>{if(typeof window>"u")return!1;const n=window.Capacitor?.getPlatform?.();return n==="ios"||n==="android"},Go=e=>{const{enabled:n}=e,s=ce(a=>a.nativeNotificationsEnabled),r=o.useRef(null);o.useEffect(()=>{if(!n||!s||!Wo())return;let a=!1;const i=[];return he(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([132,129])).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:Vo()})}),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)]")})}),qo=320,Yo=380,kn=280,Jo=560,Qo=900;function jn(e,n,s,r=Jo){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),y=o.useCallback(m=>Math.min(r,Math.max(kn,Math.round(m))),[r]),k=o.useCallback(m=>{const N=a.current;N&&(N.style.width=`${m}px`,N.style.minWidth=`${m}px`,N.style.maxWidth=`${m}px`,N.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]),M=o.useCallback(m=>{if(x.current!==m.pointerId)return;const N=m.clientX-u.current,L=y(f.current+(e==="left"?N:-N));b.current!==L&&(b.current=L,k(L))},[k,y,e]),B=o.useCallback(m=>{if(x.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const N=y(b.current??f.current);x.current=null,b.current=null,d(!1),l(N);try{window.localStorage.setItem(n,String(N))}catch{}},[y,n]),p=o.useMemo(()=>({onPointerDown:j,onPointerMove:M,onPointerUp:B,onPointerCancel:B}),[j,B,M]);return{asideRef:a,width:i,isResizing:c,handleProps:p}}const Xo=1e3,Zo=({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),y=ce(U=>U.setSettingsPage),k=ce(U=>U.isArchivePageOpen),j=ce(U=>U.setArchivePageOpen),M=ce(U=>U.wideChatLayoutEnabled),B=Me(U=>U.available),p=Me(U=>U.runtimeType),m=o.useMemo(()=>Je(),[]),N=!m&&B&&(p==="desktop"||p==="web"),L=o.useCallback(()=>{a(null)},[]),v=o.useCallback(U=>{a(U)},[]),R=o.useCallback(()=>{l(!1)},[]),T=o.useCallback(U=>{f(U),v("settings")},[v]),{enabled:O,roomyForPanels:S}=St(),h=Rr()==="portrait",H=Pr(),[g,C]=o.useState(()=>Ir().roomyForPanels),z=o.useCallback(()=>{C(U=>!U)},[]);o.useEffect(()=>{O||C(!1)},[O]);const Y=o.useCallback(()=>{x(null),d("files"),l(!0)},[]),Q=o.useCallback((U=null)=>{x(U),d("changes"),l(!0)},[]),J=jn("left","pichamber.ipad.leftSidebarWidth",qo),I=jn("right","pichamber.ipad.rightSidebarWidth",Yo,Qo),q=S,W=q&&i?I.width:0,w=O&&g?J.width:0;o.useEffect(()=>{if(typeof document>"u")return;const U=document.documentElement;return U.style.setProperty("--oc-chat-inset-left",`${w}px`),U.style.setProperty("--oc-chat-inset-right",`${W}px`),()=>{U.style.removeProperty("--oc-chat-inset-left"),U.style.removeProperty("--oc-chat-inset-right")}},[w,W]),o.useEffect(()=>{if(typeof document>"u")return;const U=document.documentElement;return U.classList.toggle("wide-chat-layout",M),()=>U.classList.remove("wide-chat-layout")},[M]),o.useEffect(()=>{if(typeof document>"u")return;const U=O&&(h||H),ge=document.documentElement;return ge.classList.toggle("oc-keep-draft-starters",U),()=>ge.classList.remove("oc-keep-draft-starters")},[H,O,h]);const E=o.useMemo(()=>({openChanges:({diffPath:U,staged:ge}={})=>{Q(U?{path:U,staged:ge===!0}:null)},openFiles:()=>Y(),openSettings:()=>T("nav"),openInstances:m?()=>v("instances"):void 0,instanceLabel:m?Fe():null,openUpdate:N?()=>v("update"):void 0}),[Q,Y,T,v,m,N]),A=o.useMemo(()=>({openSessions:()=>{O?C(!0):s(!0)},openView:U=>{if(U==="files"){Y();return}(U==="instances"||U==="update"||U==="mcp")&&v(U)},openChanges:({path:U,staged:ge}={})=>{Q(U?{path:U,staged:ge===!0}:null)},openSettings:U=>{U&&y(U),T(U?"page-content":"nav")}}),[O,Q,Y,T,v,y]);Oo(A);const F=o.useRef(null);Ko(F,{onLeftEdgeSwipe:()=>{O?C(!0):s(!0)},onRightEdgeSwipe:()=>l(!0)});const ee=o.useCallback(()=>k?(j(!1),!0):r?(L(),!0):i?(R(),!0):n?(s(!1),!0):!1,[r,L,R,k,n,j,i]);Po(ee);const X=O?"dialog":"fullscreen";return t.jsx(Ar,{actions:E,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:J.asideRef,className:K("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!g&&"border-r-0"),style:{width:g?J.width:0,minWidth:g?J.width:0,maxWidth:g?J.width:0,"--oc-ipad-sidebar-width":`${J.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:J.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!g,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:K("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",J.isResizing&&"pointer-events-none",!g&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(ue,{children:t.jsx(ln,{open:!0,variant:"sidebar",onOpenChange:U=>{!U&&!S&&C(!1)}})})}),g?t.jsx(wn,{side:"left",isResizing:J.isResizing,ariaLabel:"Resize left panel",handleProps:J.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(eo,{onOpenSessions:()=>O?z():s(!0),onOpenWorkspace:()=>l(!0),compactTitle:O}),t.jsx("main",{ref:F,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(ue,{children:t.jsx(Ps,{})})})})]}),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",!W&&"border-l-0"),style:{width:W,minWidth:W,maxWidth:W,"--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":!W,"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",!W&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(ue,{children:t.jsx(xn,{open:i,onClose:R,tab:c,onTabChange:d,pendingChangesDiff:b,variant:q?"panel":"drawer"})})}),W?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:X,dialogAlign:"app",onClose:L,ariaLabel:"Instances",title:"Instances",children:t.jsx(to,{onConnect:L,onActiveConnectionDeleted:e})}):null,r==="settings"?t.jsx(gt,{open:!0,variant:X,dialogAlign:"app",onClose:L,ariaLabel:"Settings",headerless:!0,children:t.jsx(ue,{children:t.jsx(Ur,{forceMobile:!0,isWindowed:!0,initialMobileStage:u,onClose:L})})}):null,r==="update"?t.jsx(gt,{open:!0,variant:X,dialogAlign:"app",onClose:L,ariaLabel:"Update",title:"Update",children:t.jsx(ue,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(Br,{initialUpdateDialogOpen:!0})})})}):null,t.jsx(ue,{children:t.jsx(Is,{})})]})})};function ei({apis:e}){const n=le(I=>I.initializeApp),s=le(I=>I.isInitialized),r=le(I=>I.isConnected),a=le(I=>I.connectionPhase),i=le(I=>I.providers.length),l=le(I=>I.agents.length),c=le(I=>I.loadProviders),d=le(I=>I.loadAgents),u=En(I=>I.currentDirectory),f=fe(I=>I.error),b=fe(I=>I.clearError),x=ce(I=>I.setIsMobile),y=gr(I=>I.refreshStatus),[k,j]=o.useState(0),[M,B]=o.useState(0),[p,m]=o.useState(!1),[N,L]=o.useState("pending"),[v,R]=o.useState(null),T=o.useMemo(()=>Fe(),[]),[,O]=o.useReducer(I=>I+1,0),S=o.useMemo(()=>Je(),[]),D=o.useRef(0),h=o.useRef(0),H=o.useCallback(()=>{const I=xe(),q=h.current+1;if(h.current=q,!I){pt();return}const W=()=>{n(),y(e.github,{force:!0}),i===0&&c({source:"mobileApp:nativeResume"}),l===0&&d({source:"mobileApp:nativeResume"})},w=()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(A=>A+1)};et().then(A=>{if(h.current===q){if(A==="no-connection"){w();return}if(A==="needs-login"){R({kind:"auth-expired",label:Fe()??""}),w();return}if(A==="unreachable"){window.setTimeout(()=>{h.current===q&&et().then(F=>{if(h.current===q&&F!=="switched"){if(F==="unchanged"){W();return}F==="needs-login"&&R({kind:"auth-expired",label:Fe()??""}),w()}})},4e3);return}A!=="switched"&&W()}});const E=Date.now();E-D.current>=Xo&&(D.current=E,window.dispatchEvent(new Event("pichamber:system-resume")))},[l,e.github,n,d,c,i,y]);To(),Ro(H),o.useEffect(()=>us(),[]),o.useEffect(()=>{if(!S)return;let I;const q=()=>{window.clearTimeout(I),I=window.setTimeout(()=>H(),1500)};return window.addEventListener("online",q),()=>{window.removeEventListener("online",q),window.clearTimeout(I)}},[S,H]),o.useEffect(()=>(Lt(e),()=>Lt(null)),[e]),o.useEffect(()=>fs(I=>{if(!!I.runtimeKey&&I.runtimeKey===I.previousRuntimeKey){Ss(),O();return}Cs(I),B(W=>W+1),j(W=>W+1)}),[]),o.useEffect(()=>{Tn()},[M]),o.useEffect(()=>{if(!S||r||xe()){L("done");return}let I=!1;return L("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}),L("done"))}),()=>{I=!0}},[]),o.useEffect(()=>{if(!S||!xe())return;let I=!1;const q=W=>{W&&R(W),De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(w=>w+1)};return et().then(async W=>{if(I||W==="switched"||W==="unchanged")return;const w=Fe();if(W==="needs-login"){q({kind:"auth-expired",label:w??""});return}if(W==="unreachable"){q(w?{kind:"unreachable",label:w}:null);return}const E=await pt().catch(()=>({status:"no-candidate"}));I||E.status==="connected"||(E.status==="needs-login"?q({kind:"auth-expired",label:E.label}):E.status==="unreachable"?q({kind:"unreachable",label:E.label}):q(null))}),()=>{I=!0}},[]),o.useEffect(()=>{x(!0)},[x]),o.useEffect(()=>{S&&!xe()||n()},[k,n,S]),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,z]=o.useState(S);o.useEffect(()=>{if(!S||!r||g.current)return;if(fe.getState().currentSessionId){g.current=!0,z(!1);return}const I=Ye(),q=yr(I);if(!q){g.current=!0,z(!1);return}let W=!1;const w=window.setTimeout(()=>z(!1),6e3);return(async()=>{const E=await br().catch(()=>null);if(W)return;if(!E){z(!1);return}g.current=!0;const A=E.activeSessions.find(ee=>ee.id===q.sessionId);if(!A){xr(I),z(!1);return}const F=fe.getState();F.currentSessionId||F.setCurrentSession(A.id,jt(A)??q.directory??void 0),z(!1)})(),()=>{W=!0,window.clearTimeout(w)}},[k,r,S]),o.useEffect(()=>{r&&vr.setDirectory(u)},[u,r]),o.useEffect(()=>{r&&y(e.github,{force:!0})},[e.github,r,y]),o.useEffect(()=>{if(!f)return;const I=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(I)},[b,f]),o.useEffect(()=>{if(!(!r&&(S?!!xe():!0))){m(!1);return}const q=window.setTimeout(()=>{m(!0)},S?4e3:8e3);return()=>window.clearTimeout(q)},[r,S,k,M]),wr(),ms({enabled:!0}),Ns(),hs(),Es(),Go({enabled:S&&r}),$o({ready:S&&r&&s});const Y=Io(),Q=!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 J=!!xe();return S&&(!J||!r&&!Q)?J?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(te,{type:"button",variant:"outline",onClick:()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(I=>I+1)},children:"Use another server"})]}):null]})}):N!=="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(kr,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Ka,{onConnected:()=>j(I=>I+1),notice:v})}):!r&&!Q?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(ue,{children:t.jsx(jr,{children:t.jsx(Sr,{apis:e,children:t.jsx(Cr,{delayDuration:300,skipDelayDuration:150,children:t.jsx(Ts,{children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[S&&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(Nr,{embeddedBackgroundWorkEnabled:s}),t.jsx(ca,{}),t.jsx(Zo,{onActiveConnectionDeleted:()=>{De({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(I=>I+1)}}),t.jsx(Rs,{}),t.jsx(Er,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),t.jsx(Tr,{}),s?t.jsx(pa,{}):null]})})})})},M)})}const ti=()=>{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(()=>{ta()})};function vc(e){window.__PICHAMBER_SURFACE__="mobile",Dr(),ti(),la(),Mr();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(ei,{apis:i});os.createRoot(n).render(t.jsx(Ce.StrictMode,{children:t.jsx(_r,{children:t.jsx(Lr,{children:t.jsx(As,{children:r?l:t.jsx(zr,{children:l})})})})}))}export{vc as renderMobileApp};
|