@pi-chamber/web 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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-LewzHfDH.js +1 -0
- package/dist/assets/DiagramEditor-BOIJVnh3.js +1 -0
- package/dist/assets/DiagramView-CdNHezna.js +1 -0
- package/dist/assets/{DiffView-BHS4m_K7.js → DiffView-Cmw-RHIH.js} +2 -2
- package/dist/assets/{FilesView-DmZcdwl-.js → FilesView-BODbL0Xm.js} +6 -6
- package/dist/assets/GitView-DqYF-n_h.js +6 -0
- package/dist/assets/JsonTreeView-DzEjA1ht.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-B07lHhBl.js → MarkdownRendererImpl-Bfq0bOSM.js} +2 -2
- package/dist/assets/PatchDiff-CtVByTC4.js +1 -0
- package/dist/assets/{PierreDiffViewer-Bo0_BCT7.js → PierreDiffViewer-Cwoewmiu.js} +2 -2
- package/dist/assets/{useAppFontEffects-DXASDavv.js → SessionSwitcherDropdown-DNjCJjzF.js} +97 -97
- package/dist/assets/{SettingsView-CtsS4oDI.js → SettingsView-BtLvHlj4.js} +3 -3
- package/dist/assets/SettingsWindow-CPd7JmJs.js +1 -0
- package/dist/assets/{ToolOutputDialog-iZG2ey4T.js → ToolOutputDialog-CFFC5eI-.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-yFq1DKSA.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-DD5IznIe.js → VirtualizedFileDiff-CC5lTPJS.js} +4 -4
- package/dist/assets/collapsible-D_555Hw_.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-BcVuV0Ic.js +3 -0
- package/dist/assets/contextFileOpenGuard-BygvjHuE.js +1 -0
- package/dist/assets/index-C9CLY-is.js +1 -0
- package/dist/assets/index-DQr8-8RF.js +8 -0
- package/dist/assets/index-DYrJXRkU.css +1 -0
- package/dist/assets/isDiffPlainText-Bher0UxW.js +1 -0
- package/dist/assets/isFilePlainText-EIViqOlI.js +1 -0
- package/dist/assets/main-1bIgjP48.js +2 -0
- package/dist/assets/main-JDtt2bQS.js +133 -0
- package/dist/assets/{markdownCore-BULtt6Xa.js → markdownCore-Bm4FxtK1.js} +2 -2
- package/dist/assets/miniChat-B7kKqKHH.js +2 -0
- package/dist/assets/mobile-DZPRce5z.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-Dq0GdThJ.js +1 -0
- package/dist/assets/renderMobileApp-DlKnjObC.js +23 -0
- package/dist/assets/runtimeSurface-B6sKTjo7.js +1 -0
- package/dist/assets/{useInlineCommentController-KJFe98HG.js → useInlineCommentController-CSR_Ju0a.js} +2 -2
- package/dist/assets/usePanelSlide-BkonU4LS.js +47 -0
- package/dist/assets/{useWindowTitle-BcwmWC0M.js → useWindowTitle-rt_8xbd9.js} +3 -3
- package/dist/assets/{vendor-codemirror-language-data-CFVH0pe8.js → vendor-codemirror-language-data-Be-zDX0u.js} +2 -2
- package/dist/assets/{web-components-CNPQSzpa.js → web-components-DgFD1Jms.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/lib/package-manager.js +44 -65
- package/server/lib/package-manager.test.js +27 -0
- package/server/lib/pi/routes.js +6 -0
- package/server/lib/pi/routes.test.js +32 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
- package/server/lib/pi/session-daemon/session-daemon.js +11 -4
- package/server/lib/pi/session-daemon/session-daemon.test.js +24 -0
- package/dist/assets/CommitSection-DGGArAb2.js +0 -1
- package/dist/assets/DiagramEditor-ig5nYV6t.js +0 -1
- package/dist/assets/DiagramView-8Qr6pwwI.js +0 -1
- package/dist/assets/GitView-gfHxmc66.js +0 -6
- package/dist/assets/JsonTreeView-DbFqka3P.js +0 -1
- package/dist/assets/PatchDiff-DD9pAs47.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-t7WZX24f.js +0 -1
- package/dist/assets/SettingsWindow-DIRGn3eQ.js +0 -1
- package/dist/assets/TerminalView-DUwO1CCY.js +0 -46
- package/dist/assets/ToolPartDiffPreview-FTexlZSz.js +0 -8
- package/dist/assets/collapsible-ODWWxk4f.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DdXkLFAD.js +0 -3
- package/dist/assets/contextFileOpenGuard-uC4OerzL.js +0 -1
- package/dist/assets/index-CRB7i1S2.js +0 -8
- package/dist/assets/index-C_Mo87uS.css +0 -1
- package/dist/assets/index-MSKFS67y.js +0 -1
- package/dist/assets/isDiffPlainText-CeCQwHA2.js +0 -1
- package/dist/assets/isFilePlainText-BcfhE9FH.js +0 -1
- package/dist/assets/main-CPygRDd9.js +0 -134
- package/dist/assets/main-DZg4qzOe.js +0 -2
- package/dist/assets/miniChat-BFotDgpO.js +0 -2
- package/dist/assets/mobile-3LLzhN5Q.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-DGmmT9Wf.js +0 -1
- package/dist/assets/renderMobileApp-Dd8P9hvM.js +0 -23
- package/dist/assets/runtimeSurface-Cnqjhb6Y.js +0 -1
- package/dist/assets/useOpenInAppsStore-DHAeT9zx.js +0 -1
- /package/dist/assets/{TerminalView-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/renderMobileApp-Dd8P9hvM.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CHD9BdDO.js","assets/vendor-katex-Cp579UoJ.css","assets/index-CRB7i1S2.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-C_Mo87uS.css","assets/useWindowTitle-BcwmWC0M.js","assets/useAppFontEffects-DXASDavv.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-Cnqjhb6Y.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-CFVH0pe8.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/TerminalView-DUwO1CCY.js","assets/TerminalView-BV3KOtdA.css","assets/SettingsView-CtsS4oDI.js","assets/vendor-qrcode-COsmt6jn.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-ODWWxk4f.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/CommitSection-DGGArAb2.js","assets/PierreDiffViewer-Bo0_BCT7.js","assets/web-components-CNPQSzpa.js","assets/computeVirtualFileMetrics-DdXkLFAD.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-DD5IznIe.js","assets/isDiffPlainText-CeCQwHA2.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-KJFe98HG.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-remixicon-react-CzPq62YO.js","assets/permissionStore-BRcQ9Jgt.js","assets/main-CPygRDd9.js","assets/SessionSwitcherDropdown-t7WZX24f.js","assets/useOpenInAppsStore-DHAeT9zx.js","assets/contextFileOpenGuard-uC4OerzL.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as a}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as f,g as m}from"./index-CRB7i1S2.js";import{r as w}from"./runtimeSurface-Cnqjhb6Y.js";import"./vendor-katex-CHD9BdDO.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";function _(t={}){const{immediate:r=!1,onNeedRefresh:n,onOfflineReady:o,onRegistered:s,onRegisteredSW:c,onRegisterError:d}=t;let i,u;const l=async(e=!0)=>{await u};async function p(){if("serviceWorker"in navigator){if(i=await a(async()=>{const{Workbox:e}=await import("./vendor-workbox-window-BIl4cyR9.js");return{Workbox:e}},[]).then(({Workbox:e})=>new e("/sw.js",{scope:"/",type:"classic"})).catch(e=>{d?.(e)}),!i)return;i.addEventListener("activated",e=>{(e.isUpdate||e.isExternal)&&window.location.reload()}),i.addEventListener("installed",e=>{e.isUpdate||o?.()}),i.register({immediate:r}).then(e=>{c?c("/sw.js",e):s?.(e)}).catch(e=>{d?.(e)})}}return u=p(),l}const v=w(),g=()=>!(!("serviceWorker"in navigator)||!window.isSecureContext||window.location.protocol!=="http:"&&window.location.protocol!=="https:"||document.prerendering||String(document.visibilityState)==="prerender"),S=t=>{let r=!1;const n=()=>{r||g()&&(r=!0,t())},o=()=>{setTimeout(n,0)};document.readyState==="complete"?o():window.addEventListener("load",o,{once:!0}),(document.prerendering||String(document.visibilityState)==="prerender")&&document.addEventListener("visibilitychange",n,{once:!0})},E=()=>{S(()=>{try{_({onRegisterError(t){console.warn("[PWA] service worker registration skipped:",t)}})}catch(t){console.warn("[PWA] service worker registration skipped:",t)}})},R=async()=>{if(window.__PICHAMBER_RUNTIME_APIS__=f(),v==="mobile"){const{renderMobileApp:t}=await a(async()=>{const{renderMobileApp:r}=await import("./renderMobileApp-Dd8P9hvM.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]));t();return}await m(),await a(()=>import("./main-CPygRDd9.js"),__vite__mapDeps([128,1,2,3,4,5,6,7,11,9,10,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,129,83,84,130,131]))};R();E();
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderElectronMiniChatApp-DGmmT9Wf.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CHD9BdDO.js","assets/vendor-katex-Cp579UoJ.css","assets/index-CRB7i1S2.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-C_Mo87uS.css","assets/useWindowTitle-BcwmWC0M.js","assets/useAppFontEffects-DXASDavv.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-Cnqjhb6Y.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-CFVH0pe8.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-t7WZX24f.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as t}from"./index-CRB7i1S2.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-DGmmT9Wf.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-Dd8P9hvM.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CHD9BdDO.js","assets/vendor-katex-Cp579UoJ.css","assets/index-CRB7i1S2.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-C_Mo87uS.css","assets/useWindowTitle-BcwmWC0M.js","assets/useAppFontEffects-DXASDavv.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-Cnqjhb6Y.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-CFVH0pe8.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/TerminalView-DUwO1CCY.js","assets/TerminalView-BV3KOtdA.css","assets/SettingsView-CtsS4oDI.js","assets/vendor-qrcode-COsmt6jn.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-ODWWxk4f.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/CommitSection-DGGArAb2.js","assets/PierreDiffViewer-Bo0_BCT7.js","assets/web-components-CNPQSzpa.js","assets/computeVirtualFileMetrics-DdXkLFAD.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-DD5IznIe.js","assets/isDiffPlainText-CeCQwHA2.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-KJFe98HG.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-remixicon-react-CzPq62YO.js","assets/permissionStore-BRcQ9Jgt.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as i}from"./index-CRB7i1S2.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-Dd8P9hvM.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{h as T,V as ge,C as U,u as Z,z as xe,o as se,n as ve,q as Se,m as Ie}from"./index-CRB7i1S2.js";import{u as be,a as je,b as De,s as Ce,c as Pe,d as Me}from"./useWindowTitle-BcwmWC0M.js";import{cZ as Ee,m as h,bI as _e,b as X,h as f,b0 as ee,c_ as ke,K as Le,R as Ne,aP as Ae,I as $,B as ie,f as Re,aY as N,c$ as ae,d0 as Oe,i as Be,t as Te,aU as ze,ah as Ue,ai as We,a0 as He,ak as Fe,al as $e,am as Ge,ao as Ve,ap as Ke,d1 as qe,aQ as Je,aw as Qe,ax as Ye,ay as Ze}from"./useAppFontEffects-DXASDavv.js";import{u as Xe,W as ce,S as et,C as tt}from"./SessionSwitcherDropdown-t7WZX24f.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-Cnqjhb6Y.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"./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-CFVH0pe8.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=X(t=>t.projects),c=X(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}=Xe(),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 F=k.find(z=>z.id===l.providerID)?.models.find(z=>z.id===l.modelID);if(F)return F}},[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,H=R&&typeof R.output=="number"?R.output:0,j=a.useMemo(()=>{if(!r||m.length===0)return null;let t,l;for(let Q=m.length-1;Q>=0;Q-=1){const Y=m[Q];if(Y.role!=="assistant")continue;const L=Y.tokens;if(!L)continue;if(L.input+L.output+L.reasoning+(L.cache?.read??0)+(L.cache?.write??0)>0){t=L,l=Y.id;break}}if(!t)return null;const B=t.input+t.output+t.reasoning+(t.cache?.read??0)+(t.cache?.write??0),F=O>0?O:2e5,z=O>0?Math.round(B/O*100):0,he=H>0?Math.round(t.output/H*100):void 0;return{totalTokens:B,percentage:z,contextLimit:O||0,outputLimit:H||void 0,normalizedOutput:he,thresholdLimit:F,lastMessageId:l}},[O,r,m,H]),[P,q]=a.useState(null),ue={WebkitAppRegion:"drag"},J={WebkitAppRegion:"no-drag"};a.useEffect(()=>{if(!r){q(t=>t===null?t:null);return}if(j&&j.totalTokens>0){q(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}q(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:J,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:J,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:J,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=Z(i=>i.shortcutOverrides),r=T(i=>i.currentDirectory),o=X(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}=Z.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}=Z.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=Je();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(He,{children:n.jsx(Fe,{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(qe,{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(Qe,{children:n.jsx(Ye,{children:n.jsx(Ze,{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-BHS4m_K7.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-CRB7i1S2.js","assets/vendor-zustand-CnsBKjP5.js","assets/index-C_Mo87uS.css","assets/useAppFontEffects-DXASDavv.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-Cnqjhb6Y.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-CFVH0pe8.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-Bo0_BCT7.js","assets/web-components-CNPQSzpa.js","assets/computeVirtualFileMetrics-DdXkLFAD.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-DD5IznIe.js","assets/isDiffPlainText-CeCQwHA2.js","assets/vendor-diff-C3JhlQdm.js","assets/TerminalView-DUwO1CCY.js","assets/TerminalView-BV3KOtdA.css","assets/useInlineCommentController-KJFe98HG.js","assets/collapsible-ODWWxk4f.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/contextFileOpenGuard-uC4OerzL.js","assets/FilesView-DmZcdwl-.js","assets/vendor-codemirror-search-BzyfPoRb.js","assets/vendor-replit-codemirror-vim-BUqe2Slv.js","assets/JsonTreeView-DbFqka3P.js","assets/Virtualizer-BxW2CJGB.js","assets/isFilePlainText-BcfhE9FH.js","assets/DiagramEditor-ig5nYV6t.js","assets/vendor-react-drawio-Boqanm0j.js","assets/useOpenInAppsStore-DHAeT9zx.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 Se,j as t,R as o,b as De,e as ds}from"./vendor-react-DYyjh7Q0.js";import"./vendor-katex-CHD9BdDO.js";import{u as ie,a as Ke,b as Dt,d as be,s as Te,i as Be,r as kn,e as us,f as Sn,h as jn,j as Cn,k as Nn,l as fs,m as En,n as gt,o as Mt,p as ms,q as ps}from"./index-CRB7i1S2.js";import{r as Rn,u as hs,a as gs,b as ys,s as bs,c as xs,d as vs}from"./useWindowTitle-BcwmWC0M.js";import{u as Pe,S as ws,a as ks,T as Ss,P as js,b as Cs,c as Ns,d as Es,e as Rs,F as Ts,f as Ps,C as Is,A as As,D as Ds}from"./TerminalView-DUwO1CCY.js";import{u as Tn,a as Ms,b as vt,c as _s,d as Ls,r as wt,e as zs,t as ne,o as Os,I as V,P as xe,B as te,f as H,g as Fs,h as ce,i as $s,j as _t,k as Bs,l as kt,m as de,n as Us,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 St,O as Zs,D as Lt,C as zt,E as Ot,G as Ft,H as $t,J as Bt,K as In,L as jt,M as er,N as tr,Q as nr,R as ge,U as sr,V as rr,W as ar,X as or,Y as ir,Z as lr,_ as cr,$ as dr,a0 as fe,a1 as ur,a2 as An,a3 as yt,a4 as Dn,a5 as fr,a6 as Ut,a7 as mr,a8 as pr,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 Sr,ai as jr,aj as Cr,ak as Nr,al as Er,am as Rr,an as Tr,ao as Pr,ap as Ir,aq as Ar,ar as Dr,as as Mr,at as _r,au as Lr,av as zr,aw as Or,ax as Fr,ay as $r}from"./useAppFontEffects-DXASDavv.js";import{p as Br,a as Ur,S as Hr,A as Kr}from"./SettingsView-CtsS4oDI.js";import{g as Mn,i as re}from"./runtimeSurface-Cnqjhb6Y.js";import{_ as me}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as Vr}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as Wr}from"./vendor-capacitor-core-B4EWRrHz.js";import{u as Gr}from"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import{C as qr}from"./CommitSection-DGGArAb2.js";import{P as Yr}from"./PierreDiffViewer-Bo0_BCT7.js";import{K as Ht,P as Jr,d as Qr,p as Xr,U as Zr,Z as ea,Q as ta,r as na}from"./vendor-remixicon-react-CzPq62YO.js";import{usePermissionStore as sa}from"./permissionStore-BRcQ9Jgt.js";import{c as ra}from"./vendor-zustand-CnsBKjP5.js";import"./vendor-scheduler-7OC5HNn7.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"./vendor-simplewebauthn-browser-VDA66rT_.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-CFVH0pe8.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-ODWWxk4f.js";import"./web-components-CNPQSzpa.js";import"./computeVirtualFileMetrics-DdXkLFAD.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-DD5IznIe.js";import"./isDiffPlainText-CeCQwHA2.js";import"./vendor-diff-C3JhlQdm.js";import"./useInlineCommentController-KJFe98HG.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";let _n=null,Kt=!1;const aa=new Promise(e=>{_n=e});function oa(){Kt||(Kt=!0,_n?.())}const ia=6,la=e=>e.parentID??null,Vt=e=>{const n=e.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},ca=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),da=(e,n)=>{if(!e)return"";let s=null,r=-1;for(const a of n){const i=ca(a.path);(e===i||e.startsWith(`${i}/`))&&i.length>r&&(s=a,r=i.length)}return s?s.label?.trim()||Vt(s.path):Vt(e)},ua=()=>{const e=Tn.getState().activeSessions,n=Ms.getState().index.session.unseenCount,s=ie.getState().notifyOnSubtasks,r=vt.getState().projects,a=_s.getState().ids,i=Ls.getState().rankById;let l=0;const c=[];for(const u of e){const f=la(u)!==null,v=(n[u.id]??0)>0&&(!f||s);v&&(l+=1),f||c.push({session:u,unread:v,project:da(wt(u),r)})}c.sort((u,f)=>zs(u.session,f.session,a,i));const d=c.slice(0,ia).map(({session:u,unread:f,project:x})=>({id:u.id,title:u.title??"",unread:f,project:x}));return{runtimeKey:Ke(),attentionCount:l,recentSessions:d}},fa="__PICHAMBER_WIDGET_SNAPSHOT__",ma=()=>{typeof window>"u"||(window[fa]=()=>{try{return JSON.stringify(ua())}catch{return null}})},ct="mobile-app-update-available",Wt="mobile-app-update-toast-dismissed-version",pa=()=>{const e=Pe(i=>i.available),n=Pe(i=>i.runtimeType),s=Pe(i=>i.info?.version),r=Pe(i=>i.info?.downloadUrl),a=Se.useRef(new Set);return Se.useEffect(()=>{if(Mn()!=="android"||n!=="mobile"||!e||!s||!r){ne.dismiss(ct);return}Dt().getItem(Wt)!==s&&(a.current.has(s)||(a.current.add(s),ne.info("PiChamber update available",{id:ct,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:()=>{Dt().setItem(Wt,s),ne.dismiss(ct)}}})))},[e,r,n,s]),null},ha="Updating OpenCode configuration...",Ln=0,zn=ha,Gt=new Set;function ga(e){return Gt.add(e),e({isUpdating:Ln>0,message:zn}),()=>{Gt.delete(e)}}function ya(){return{isUpdating:Ln>0,message:zn}}const ba=()=>{const[{isUpdating:e},n]=o.useState(()=>ya());return o.useEffect(()=>ga(n),[]),e?t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(xe,{width:80,height:80,isAnimated:!0})}):null},Qe="pichamber.mobile.connections.v1",xa="pichamber.mobile.",qt="pichamber.mobile.deviceId",va=()=>{try{const e=window.localStorage.getItem(qt);if(e&&e.trim())return e.trim();const n=crypto.randomUUID();return window.localStorage.setItem(qt,n),n}catch{return crypto.randomUUID()}},Yt=()=>`mobile:${va()}`,Jt=()=>{try{const e=Wr.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},On=12,wa=8e3,ka=2500,Sa=3e3,Xe=2500,ja=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:n=>n===e}},Le=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(/\/+$/,"")},Ye=e=>{try{return new URL(e).host}catch{return e}},Me=e=>{try{return Le(e)}catch{return e.trim().replace(/\/+$/g,"")}},Fn=(e,n)=>Me(e)===Me(n),$n=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,Ca=e=>`relay://${e.serverId}`,nt=e=>e.candidates.filter(n=>n.kind==="direct"),Ce=e=>{const n=e.candidates.find(s=>s.kind==="relay");return n&&n.kind==="relay"?n.relay:null},ye=e=>{const n=nt(e)[0];if(n)return n.url;const s=Ce(e);return s?Ca(s):""},se=e=>{const n=Ce(e);if(n)return $n(n);const s=nt(e)[0];return s?Me(s.url):""},Ze=(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=>Me(i.url)));return n.some(i=>i.kind==="relay"?r!==null&&i.relay.serverId===r:a.has(Me(i.url)))},Ct=e=>{const n=(()=>{try{return Le(e)}catch{return""}})();return n?[{kind:"direct",url:n}]:[]},Qt=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(...Ct(e.url)),e.relay&&n.push({kind:"relay",relay:e.relay}),n},Nt=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}}},st=e=>{try{return JSON.stringify(e)}catch{return String(e)}},oe=(e,n={})=>{console.info("[mobile-connect]",e,st(n))},_e=(e,n={})=>{console.info("[mobile-storage]",e,st(n))},Na=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},Ea=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},Ra=async(e,n)=>{if(!re())return null;try{const{CapacitorHttp:s}=await me(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:Ea(n?.body)});return{ok:a.status>=200&&a.status<300,status:a.status,source:"native-http",json:async()=>Na(a.data)}}catch(s){return console.warn("[mobile-connect]","native-http failed",st({url:e,error:s instanceof Error?s.message:String(s)})),null}},Ta=async(e,n)=>{const s=await fetch(e,n).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",st({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},we=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)}},Ne=async(e,n,s)=>{const r=s?.totalTimeoutMs??wa,a=Date.now(),i=await we(Math.min(ka,r),Ra(e,n));if(i)return i;const l=new AbortController,c=Math.max(500,r-(Date.now()-a));return we(c,Ta(e,{...n,signal:l.signal}),()=>l.abort())},rt=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}},Ue=15e3,Pa=async(e,n,s,r=Ue,a)=>{const i=Sn({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 we(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 rt(d);return u&&u.disabled!==!0&&u.authenticated===!1?l(n?"auth-failed":"needs-login"):l("ok")}catch(c){throw i.close(),c}},Ia=(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&&us(l,a),Te({apiBaseUrl:i,clientToken:n,runtimeKey:r??$n(e),relay:l})},Aa=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=Nt(n.relay);return s?{kind:"relay",relay:s}:null}return null},Da=e=>{if(e.mode==="relay"){const n=Nt(e.relay);return n?[{kind:"relay",relay:n}]:[]}return typeof e.url=="string"?Ct(e.url):[]},Ee=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(Qe)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const n=re();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(Aa).filter(d=>!!d):Da(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:Ye(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)},bt=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},Et=e=>{if(typeof window>"u")return;const n=re(),s=e.slice(0,On).map(r=>{const a={id:r.id,label:r.label,candidates:r.candidates.map(bt),lastUsedAt:r.lastUsedAt};return n?{...a,hasToken:!!(r.hasToken||r.clientToken)}:{...a,clientToken:r.clientToken}});try{window.localStorage.setItem(Qe,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},Bn=(e,n)=>{const s=e.find(i=>n.id&&i.id===n.id||Ze(i.candidates,n.candidates)),r=re(),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&&!Ze(i.candidates,n.candidates))].slice(0,On)},Rt=Vr,Ma=0,Tt=e=>`${xa}token.${encodeURIComponent(e)}`,_a=async(e,n)=>{let s;const r=new Promise(a=>{s=window.setTimeout(()=>a(n),Sa)});try{return await Promise.race([e.catch(()=>n),r])}finally{s!==void 0&&window.clearTimeout(s)}},Pt=async(e,n,s)=>re()?_a(n().catch(r=>(console.warn(`[mobile-storage] ${e} failed`,r),s)),s):s,He=async e=>{_e("secure:read-start",{key:e});const n=await Pt("secure:read",async()=>(await Rt.internalGetItem({prefixedKey:Tt(e),sync:!1})).data,null),s=typeof n=="string"&&n.trim()?n:void 0;return _e("secure:read",{key:e,hasToken:!!s}),s},ke=async(e,n)=>{_e("secure:write-start",{key:e});const s=await Pt("secure:write",async()=>(await Rt.internalSetItem({prefixedKey:Tt(e),data:n,sync:!1,access:Ma}),!0),!1);return _e("secure:write",{key:e,ok:s}),s},La=async e=>{await Pt("secure:delete",async()=>(await Rt.internalRemoveItem({prefixedKey:Tt(e),sync:!1}),!0),!1)},za=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}},Un=async()=>{if(typeof window>"u"||!re())return;let e;try{e=JSON.parse(window.localStorage.getItem(Qe)||"[]")}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 za(e,async(r,a)=>{const i=Me(r);return await ke(i,a)?await He(i)===a:!1});if(s.migrated>0)try{window.localStorage.setItem(Qe,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})},Oa=async()=>(await Un(),Ee()),et=async e=>{const n=Bn(Ee(),e);return Et(n),re()&&e.clientToken&&await ke(se({candidates:e.candidates}),e.clientToken),n},Fa=async e=>{const n=Ee(),s=n.find(a=>a.id===e)??null,r=n.filter(a=>a.id!==e);return Et(r),s&&re()&&await La(se(s)),r},$a=1500,tt=async(e,n,s)=>{const r=s?.fast?{totalTimeoutMs:Xe}:void 0,a=Ce({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=Le(u.url)||u.url,x=n?{Authorization:`Bearer ${n}`}:void 0,v=await Ne(`${f}/health`,{method:"GET"},r);if(!v?.ok)continue;if(a){const M=await v.json().catch(()=>null),$=M&&typeof M=="object"?M.serverId:null;if(typeof $=="string"&&$&&$!==a){oe("probe:server-id-mismatch",{url:f});continue}}const b=await Ne(`${f}/auth/session`,{method:"GET",credentials:n?"omit":"include",headers:x},r);if(b?.status===401)return{status:"needs-login"};if(!b||!b.ok&&b.status!==404)continue;const S=await rt(b);if(S&&S.disabled!==!0&&S.authenticated===!1)return{status:"needs-login"};const j=S?.disabled===!0;return!n&&re()&&!j&&S?.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 Pa(i.relay,n,void 0,s?.fast?Xe: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,x=!1,v,b=null,S=null;const j=m=>{m?.status==="ok"&&m.transport.kind==="relay"&&m.transport.tunnel?.close()},M=m=>{f||(f=!0,u(m))},$=()=>{x||f||(v!==void 0&&(window.clearTimeout(v),v=void 0),d().then(m=>{if(S=m,f||x){j(m);return}if(m.status==="ok"||m.status==="needs-login"){M(m);return}b&&M(b)}))};c().then(m=>{if(b=m,!f){if(m.status==="ok"||m.status==="needs-login"){x=!0,v!==void 0&&window.clearTimeout(v),j(S),M(m);return}if(S){M(S);return}$()}}),v=window.setTimeout($,$a)}):c()},je=(e,n,s)=>{e.kind==="relay"?Ia(e.relay,n,s?.grant,s?.runtimeKey,e.tunnel):Te({apiBaseUrl:e.url,clientToken:n,runtimeKey:s?.runtimeKey}),Kn()},ze=()=>{const e=Ee()[0];return e?.label?.trim()?e.label:null},dt=async()=>{await Un();const e=Ee()[0];if(!e)return{status:"no-candidate"};let n;if(re()){if(!e.hasToken)return{status:"no-candidate"};if(n=await He(se(e)),!n)return{status:"no-candidate"}}else if(n=e.clientToken,!n)return{status:"no-candidate"};const s=await tt(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 et({id:e.id,label:e.label,candidates:e.candidates}),je(s.transport,n,{runtimeKey:se(e)}),{status:"connected"})},Ba=async(e,n)=>{let s="";try{s=Le(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:Xe};if(!(await Ne(`${s}/health`,{method:"GET",headers:a},i))?.ok)return!1;const c=await Ne(`${s}/auth/session`,{method:"GET",credentials:r?"omit":"include",headers:a},i);if(!c||!c.ok&&c.status!==404)return!1;const d=await rt(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},Ua=e=>[...e].sort((n,s)=>{const r=(n.priority??100)-(s.priority??100);if(r!==0)return r;const a=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return a(n)-a(s)}).flatMap(n=>{if(n.type==="relay"){const s=Nt({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Ct(n.url)}),Xt=async e=>{const n=Ce({candidates:e})?.serverId??null;for(const s of e){if(s.kind==="relay"){const i=Sn(s.relay),l=await we(Ue,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=Le(s.url)||s.url,a=await Ne(`${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},Ha=async(e,n)=>{if(!Be())return Ba(e);const s=await we(Xe,kn("/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 rt(s);return!(r&&r.disabled!==!0&&r.authenticated===!1)},Ka=e=>e.kind==="relay"?Be():!Be()&&Fn(e.url,be()),Hn=()=>{const e=Ke();return e?Ee().find(n=>se(n)===e)??null:null},Zt=e=>{const n=Ke();return!!n&&se(e)===n},Je=async()=>{const e=Hn();if(!e)return"no-connection";let n;if(re()?n=e.hasToken?await He(se(e)):void 0:n=e.clientToken,!n)return"unreachable";const s=e.candidates.findIndex(c=>Ka(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 tt(r,n,{fast:!0});if(a.status==="ok")return await et({id:e.id,label:e.label,candidates:e.candidates}),je(a.transport,n,{runtimeKey:se(e)}),"switched";if(a.status==="needs-login")return"needs-login";if(s>=0&&await Ha({url:be(),clientToken:n}))return Kn(),"unchanged";const i=s>=0?e.candidates.slice(s+1):[],l=await tt(i,n,{fast:!0});return l.status==="ok"?(await et({id:e.id,label:e.label,candidates:e.candidates}),je(l.transport,n,{runtimeKey:se(e)}),"switched"):l.status==="needs-login"?"needs-login":"unreachable"},Va=5e3;let ut=!1;const Wa=async()=>{if(ut)return"skipped";const e=Hn();if(!e)return oe("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const n=Ce(e);if(!n)return oe("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";ut=!0;try{const s=await we(Ue,kn("/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 x=Le(f.url);x&&!i.includes(x)&&i.push(x)}catch{}}if(i.length===0)return oe("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const l=nt(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(bt))===JSON.stringify(c.map(bt))?"unchanged":(oe("candidates:refreshed",{lanCount:i.length}),await et({id:e.id,label:e.label,candidates:c}),"updated")}finally{ut=!1}},Kn=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await Wa().catch(()=>"skipped");oe("candidates:refresh-result",{result:e}),e==="updated"&&Be()&&await Je().catch(()=>null)})()},Va)},Vn=e=>{const[n,s]=o.useState(()=>Ee()),[r,a]=o.useState(null),[i,l]=o.useState(null),[c,d]=o.useState(null),u=o.useRef(n),f=o.useRef(null),x=o.useRef(ja()),v=o.useCallback(w=>{u.current=w,s(w)},[]),b=o.useCallback(w=>{f.current=w,a(w)},[]),S=o.useCallback(w=>{f.current===w&&(f.current=null,a(null))},[]);o.useEffect(()=>{let w=!1;return Oa().then(P=>{w||v(P)}),()=>{w=!0}},[v]);const j=o.useCallback(w=>{const P=Bn(u.current,w);return v(P),Et(P),P},[v]),M=o.useCallback(async w=>{l(null),b("connect");try{const P=Qt(w);if(P.length===0){l("Enter a server URL.");return}const R=w.id?u.current.find(y=>y.id===w.id):u.current.find(y=>Ze(y.candidates,P)),F=w.label?.trim()||R?.label||Ye(ye({candidates:P})),N=w.relayGrant;let D=w.clientToken?.trim()||void 0;const h=!!D;D||(re()?R?.hasToken&&(D=await He(se({candidates:P}))):D=R?.clientToken),oe("connect:start",{candidates:P.map(y=>y.kind),hasToken:!!D});const U=await tt(P,D);if(oe("connect:probe",{status:U.status}),U.status==="unreachable"){l("Could not reach that PiChamber server.");return}if(U.status==="needs-login"){j({id:R?.id,label:F,candidates:P}),d({id:R?.id??crypto.randomUUID(),label:F,candidates:P,relay:Ce({candidates:P})??void 0,relayGrant:N});return}D&&h&&re()&&await ke(se({candidates:P}),D),j({id:R?.id,label:F,candidates:P,clientToken:D}),je(U.transport,D??null,{runtimeKey:se({candidates:P}),grant:N}),e()}catch(P){console.warn("[mobile-connect] connect threw",P),l("That server URL is not valid.")}finally{S("connect")}},[b,S,e,j]),$=o.useCallback(async w=>{if(f.current==="pairing")return;l(null),b("pairing");const P=Ua(w.candidates);let R=null,F=!1;try{if(R=await Xt(P),!R){l("Could not reach that PiChamber server.");return}const N=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:Jt(),dedupeKey:Yt()}),D={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:N},h=R.kind==="relay"?await we(Ue,R.tunnel.fetch("/api/client-auth/pairing/redeem",D).catch(()=>null)):await Ne(`${R.url}/api/client-auth/pairing/redeem`,D);if(!h?.ok){l("This server needs a password or client token.");return}const U=await h.json().catch(()=>null),y=typeof U?.clientToken=="string"?U.clientToken.trim():"";if(!y){l("This server needs a password or client token.");return}const C=typeof U?.server?.label=="string"?U.server.label:"",O=w.label||C||Ye(ye({candidates:P}));if(re()&&!await ke(se({candidates:P}),y)){l("This server needs a password or client token.");return}j({label:O,candidates:P,clientToken:y}),je(R.kind==="relay"?{kind:"relay",relay:R.relay,tunnel:R.tunnel}:{kind:"direct",url:R.url},y,{runtimeKey:se({candidates:P})}),F=R.kind==="relay",e()}catch(N){console.warn("[mobile-connect] pairing threw",N),l("This server needs a password or client token.")}finally{!F&&R?.kind==="relay"&&R.tunnel.close(),S("pairing")}},[b,S,e,j]),m=o.useCallback(async w=>{if(!c||!w.trim()||f.current==="password")return;l(null),b("password");const P=x.current.begin(),R=()=>x.current.isCurrent(P),{id:F,label:N,candidates:D}=c;let h=null,U=!1;try{if(h=await Xt(D),!R())return;if(!h){l("Could not reach that PiChamber server.");return}const y={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:Jt(),dedupeKey:Yt()})};oe("password:start",{transport:h.kind});const C=h.kind==="relay"?await we(Ue,h.tunnel.fetch("/auth/session",y).catch(()=>null)):await Ne(`${h.url}/auth/session`,y);if(!R())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 O=await C.json().catch(()=>null);if(!R())return;const q=typeof O?.clientToken=="string"?O.clientToken.trim():"";if(oe("password:token",{issued:!!q}),!q){if(h.kind==="direct"&&!re()){j({id:F,label:N,candidates:D}),d(null),je({kind:"direct",url:h.url},null,{runtimeKey:se({candidates:D})}),e();return}l("This server needs a password or client token.");return}if(re()&&(!R()||(await ke(se({candidates:D}),q),!R()))||!R()||(j({id:F,label:N,candidates:D,clientToken:q}),d(null),je(h.kind==="relay"?{kind:"relay",relay:h.relay,tunnel:h.tunnel}:{kind:"direct",url:h.url},q,{runtimeKey:se({candidates:D})}),U=h.kind==="relay",!R()))return;e()}catch(y){if(!R())return;console.warn("[mobile-connect] password threw",y),l("Could not unlock that server. Check the password.")}finally{!U&&h?.kind==="relay"&&h.tunnel.close(),R()&&S("password")}},[b,S,e,c,j]),p=o.useCallback(()=>{x.current.cancel(),S("password"),d(null),l(null)},[S]),E=o.useCallback(async w=>{l(null);let P=Qt(w);const R=w.id?u.current.find(h=>h.id===w.id)??null:null;if(R){const h=P.filter(C=>C.kind==="direct"),U=nt(R).filter(C=>C.url.startsWith("https://")&&!h.some(O=>Fn(O.url,C.url))),y=Ce(R);P=[...h,...U,...y?[{kind:"relay",relay:y}]:[]]}if(P.length===0)return l("Enter a server URL."),null;const F=w.clientToken?.trim()||void 0,N=w.label?.trim()||Ye(ye({candidates:P}));if(re()){const h=se({candidates:P});if(F)await ke(h,F);else if(R?.hasToken){const U=se(R);if(U&&h&&U!==h){const y=await He(U);y&&await ke(h,y)}}}return j({id:w.id,label:N,candidates:P,clientToken:F}).find(h=>Ze(h.candidates,P))??null},[j]),z=o.useCallback(async w=>{const P=u.current.find(F=>F.id===w)??null,R=await Fa(w);return v(R),P},[v]);return{connections:n,isBusy:r!==null,isPasswordBusy:r==="password",error:i,pendingConnection:c,connect:M,redeemPairingConnection:$,submitPassword:m,cancelPassword:p,saveConnection:E,removeConnection:z,setError:l}},Wn=()=>{if(typeof window>"u")return null;const n=window.Capacitor?.Plugins?.BarcodeScanner;return n&&(typeof n.scan=="function"||typeof n.startScan=="function")?n:null},Ga=()=>window.Capacitor?.getPlatform?.()==="android",Gn=e=>{const n=e.trim();if(!n)return null;if(/^pichamber:\/\//i.test(n)){const s=Br(n);return s?{pairing:s}:null}return/^https?:\/\//i.test(n)?{url:n}:null},qn=(e,n)=>{const s=Gn(e);if(!s&&n?.pairingStringFallback){const r=Ur(e);if(r)return{status:"pairing",pairing:r}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},qa=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 x=f?.[0],v=(x?.rawValue??x?.displayValue??"").trim();v&&c(qn(v,{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()])}},xt=()=>Wn()!==null,Yn=async e=>{const n=Wn();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(Ga())return qa(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?qn(a):{status:"cancelled"}}catch{return{status:"failed"}}},Ae={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Oe="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",Jn=({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]),De.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)},Qn=()=>De.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(xe,{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),Ya=({onConnected:e,notice:n=null})=>{const s=Vn(e),{connections:r,isBusy:a,isPasswordBusy:i,error:l,pendingConnection:c}=s,[d,u]=o.useState(""),[f,x]=o.useState(""),[v,b]=o.useState(""),[S,j]=o.useState(!1),[M,$]=o.useState(!1),m=o.useRef(null),p=o.useMemo(()=>xt(),[]),[E,z]=o.useState(()=>!xt()),[w,P]=o.useState(null),[R,F]=o.useState(""),N=o.useCallback(C=>{C.preventDefault(),s.connect({url:d,clientToken:v,label:f})},[v,s,f,d]),D=o.useCallback(C=>{if(/^pichamber:\/\//i.test(C.trim())){const O=Gn(C);if(O){if("pairing"in O){s.redeemPairingConnection(O.pairing);return}u(O.url),O.label&&x(O.label),O.clientToken&&b(O.clientToken);return}}u(C)},[s]),h=o.useCallback(async()=>{if(m.current||a)return;s.setError(null),j(!0);const C=new AbortController;m.current=C;try{const O=await Yn({signal:C.signal});switch(m.current===C&&(m.current=null,j(!1)),O.status){case"ok":$(!0),u(O.url),O.label&&x(O.label),O.clientToken&&b(O.clientToken),await s.connect({url:O.url,clientToken:O.clientToken,label:O.label});break;case"pairing":$(!0),await s.redeemPairingConnection(O.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{$(!1),m.current===C&&(m.current=null,j(!1))}},[s,a]);o.useEffect(()=>()=>m.current?.abort(),[]);const U=o.useCallback(C=>{C.preventDefault(),s.submitPassword(R)},[s,R]),y=o.useCallback(()=>{F(""),s.cancelPassword()},[s]);return t.jsxs(t.Fragment,{children:[S?t.jsx(Jn,{onCancel:()=>m.current?.abort()}):null,M?t.jsx(Qn,{}):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(xe,{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:U,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",{...Ae,value:R,onChange:C=>F(C.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Oe}),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||!R.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(te,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:y,children:"Use another server"})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[p?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:S||a,children:[t.jsx(V,{name:"scan-2",className:H("size-[18px]",S&&"animate-pulse")}),a?"Connecting...":"Scan QR code"]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}):null,l&&!E?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved connections"}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(C=>{const O=w===C.id;return t.jsxs("button",{type:"button",disabled:a,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{P(C.id),s.connect({id:C.id,candidates:C.candidates,clientToken:C.clientToken,label:C.label}).finally(()=>P(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:H("block truncate typography-small",O?"text-foreground":"text-muted-foreground"),children:O?"Connecting...":C.candidates.some(q=>q.kind==="direct")?ye(C):"via PiChamber Relay"})]}),O?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:[p?t.jsxs("button",{type:"button",onClick:()=>z(C=>!C),"aria-expanded":E,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:"Connect by address"}),t.jsx(V,{name:"arrow-down-s",className:H("size-4 transition-transform duration-200",E&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:E?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:N,children:[t.jsx("input",{...Ae,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:E?void 0:-1,className:H(Oe,"text-center")}),t.jsx("input",{value:f,onChange:C=>x(C.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:E?void 0:-1,className:H(Oe,"text-center")}),t.jsx("input",{...Ae,value:v,onChange:C=>b(C.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:E?void 0:-1,autoCapitalize:"none",className:H(Oe,"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:p?"outline":"default",size:"lg",className:"h-12 w-full",disabled:a||S||!d.trim(),children:a?"Connecting...":"Connect"})]})})})]})]})]})})]})},en=380,Ja=e=>typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.min(100,Math.round(e))),Qa=e=>e>=90?"critical":e>=75?"warn":"safe",tn=(e,n)=>{if(!e||typeof e!="object")return;const s=e[n];return typeof s=="number"&&Number.isFinite(s)?s:void 0},nn=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),Xn=({percentage:e})=>{const n=Ja(e),s=Qa(e),r=s==="critical"?"var(--status-error)":s==="warn"?"var(--status-warning)":"var(--status-success)",a=18,i=3,l=(a-i)/2,c=2*Math.PI*l;return t.jsxs("svg",{viewBox:`0 0 ${a} ${a}`,className:"size-[18px] -rotate-90",role:"progressbar","aria-valuenow":Math.round(n),"aria-valuemin":0,"aria-valuemax":100,children:[t.jsx("circle",{cx:a/2,cy:a/2,r:l,fill:"none",stroke:"var(--interactive-border)",strokeWidth:i}),t.jsx("circle",{cx:a/2,cy:a/2,r:l,fill:"none",stroke:r,strokeWidth:i,strokeLinecap:"round",strokeDasharray:c,strokeDashoffset:c*(1-n/100),className:"transition-[stroke-dashoffset,stroke] duration-300"})]})},Xa=({icon:e,iconNode:n,label:s,children:r})=>t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:n??(e?t.jsx(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})]}),Za=({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}=kt(),f=o.useRef(null),[x,v]=o.useState(null);o.useLayoutEffect(()=>{if(!e||!u||!i)return;const S=()=>{const $=s.current?.getBoundingClientRect(),m=f.current?.getBoundingClientRect();if(!$||!m){v(null);return}const p=$.left-m.left,E=Math.min(Math.max(p,8),Math.max(8,m.width-en-8));v(E)};S();const j=f.current;if(typeof ResizeObserver>"u"||!j)return;const M=new ResizeObserver(S);return M.observe(j),()=>M.disconnect()},[s,u,e,i]);const b=u&&x!==null;return o.useEffect(()=>{if(e){l(!0),d(!1);return}if(!i)return;d(!0);const S=window.setTimeout(()=>{l(!1),d(!1)},140);return()=>window.clearTimeout(S)},[e,i]),o.useEffect(()=>{if(!e)return;const S=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[n,e]),o.useEffect(()=>{if(!e)return;const S=j=>{const M=j.target;if(!(M instanceof Node)){n();return}a.current?.contains(M)||s.current?.contains(M)||n()};return document.addEventListener("pointerdown",S,!0),document.addEventListener("wheel",S,!0),()=>{document.removeEventListener("pointerdown",S,!0),document.removeEventListener("wheel",S,!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:H("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",b?"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))",...b?{top:8,left:x??8,width:`min(${en}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsx(Xa,{iconNode:t.jsx(Xn,{percentage:r.percentage}),label:"Context",children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:H("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},eo=o.memo(function({open:n,onOpenChange:s,currentSessionId:r,effectiveDirectory:a,isNewSessionDraftOpen:i}){const l=o.useRef(null),c=Fs(r??""),d=ce(h=>h.providers),u=ce(h=>h.currentProviderId),f=ce(h=>h.currentModelId),x=ce(h=>h.getCurrentModel()),v=ce(h=>h.getModelMetadata);ce(h=>h.modelsMetadata.size);const b=$s(o.useCallback(h=>r?h.sessionModelSelections.get(r)??null:null,[r])),S=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const U=c[h]?.info;if(U.role!=="user")continue;const y=U.model,C=y?.providerID??y?.providerId,O=y?.modelID??y?.modelId,q=typeof C=="string"&&C.trim().length>0?C:void 0,Y=typeof O=="string"&&O.trim().length>0?O:void 0;if(q&&Y)return{providerID:q,modelID:Y}}return null},[c]),j=o.useMemo(()=>{for(let h=c.length-1;h>=0;h-=1){const U=c[h];if(U?.info.role==="assistant"&&_t(U).total>0)return U}return null},[c]),M=S??(()=>{const h=j?.info.model,U=h?.providerID??h?.providerId,y=h?.modelID??h?.modelId;return U&&y?{providerID:U,modelID:y}:null})()??(b?{providerID:b.providerId,modelID:b.modelId}:null)??(u&&f?{providerID:u,modelID:f}:null),m=(M?d.find(h=>h.id===M.providerID):void 0)?.models.find(h=>h.id===M?.modelID),p=M?v(M.providerID,M.modelID):void 0,E=tn(m?.limit,"context")??p?.limit?.context??tn(x?.limit,"context")??0,z=j?_t(j):null,w=j?.info?.usage,P=w?Bs(w):z?.total??0,R=!i&&P>0&&E>0?Math.min(P/E*100,999):null,F=R!==null?`${nn(P)}/${nn(E)}`:null,N=R===null?"":R>=90?"text-[var(--status-error)]":R>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",D=R!==null&&F?{percentage:R,tokens:F,colorClass:N}:null;return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:l,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Show context usage for current conversation",title:"Context usage","aria-expanded":n,onClick:()=>s(h=>!h),style:{touchAction:"manipulation"},children:t.jsx(Xn,{percentage:D?.percentage??0})}),t.jsx(Za,{open:n,onClose:()=>s(!1),anchorRef:l,contextDisplay:D})]})}),to=10,sn=380,no=(e,n)=>e.title?.trim()||n,so=({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,x=Ws(e.time?.updated??e.time?.created??0);return t.jsxs("button",{type:"button",className:H("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:H("block truncate typography-ui-label",s?"text-primary":"text-foreground"),children:no(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:x?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:x}):null]})},ro=({open:e,onClose:n,anchorRef:s})=>{const r=o.useRef(null),[a,i]=o.useState(e),[l,c]=o.useState(!1),{enabled:d}=kt(),u=o.useRef(null),[f,x]=o.useState(null);o.useLayoutEffect(()=>{if(!e||!d||!a)return;const m=()=>{const z=s.current?.getBoundingClientRect(),w=u.current?.getBoundingClientRect();if(!z||!w){x(null);return}const P=z.left-w.left;x(Math.min(Math.max(P,8),Math.max(8,w.width-sn-8)))};m();const p=u.current;if(typeof ResizeObserver>"u"||!p)return;const E=new ResizeObserver(m);return E.observe(p),()=>E.disconnect()},[s,d,e,a]);const v=d&&f!==null,b=de(m=>m.currentSessionId),S=de(m=>m.setCurrentSession),j=vt(m=>m.setActiveProjectIdOnly),M=Us(e||a,{maxParents:to});o.useEffect(()=>{if(e){i(!0),c(!1);return}if(!a)return;c(!0);const m=window.setTimeout(()=>{i(!1),c(!1)},140);return()=>window.clearTimeout(m)},[e,a]),o.useEffect(()=>{if(!e)return;const m=p=>{p.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[n,e]),o.useEffect(()=>{if(!e)return;const m=p=>{const E=p.target;if(!(E instanceof Node)){n();return}r.current?.contains(E)||s.current?.contains(E)||n()};return document.addEventListener("pointerdown",m,!0),()=>document.removeEventListener("pointerdown",m,!0)},[s,n,e]);const $=o.useCallback(m=>{S(m.id,wt(m)),n()},[n,S]);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:H("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",v?"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))",...v?{top:8,left:f??8,width:`min(${sn}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(m=>{const p=m.node.session,E=[m.secondaryMeta?.projectLabel,m.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(so,{session:p,meta:E,active:p.id===b,onSelect:()=>{m.projectId&&j(m.projectId),$(p)}},p.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},ao=({onOpenSessions:e,onOpenWorkspace:n,compactTitle:s=!1})=>{const[r,a]=o.useState(!1),[i,l]=o.useState(!1),c=o.useRef(null),d=jn(p=>p.currentDirectory),u=de(p=>p.currentSessionId),x=de(o.useCallback(p=>u?p.getDirectoryForSession(u):null,[u]))||d,v=Ys(u),b=de(p=>!!p.newSessionDraft?.open),j=v?.title?.trim()||(u?"Untitled session":"New session");o.useEffect(()=>{a(!1),l(!1)},[u,x]);const M=o.useCallback(()=>{a(!1),l(!1),e()},[e]),$=o.useCallback(p=>{a(E=>{const z=typeof p=="function"?p(E):p;return z&&l(!1),z})},[]),m=o.useCallback(()=>{l(p=>{const E=!p;return E&&a(!1),E})},[]);return t.jsxs(t.Fragment,{children:[t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open sessions and projects",onClick:M,style:{touchAction:"manipulation"},children:t.jsx(V,{name:"list-unordered",className:"size-5"})}),t.jsx("button",{ref:c,type:"button",className:H("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:m,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:H("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(eo,{open:r,onOpenChange:$,currentSessionId:u,effectiveDirectory:x,isNewSessionDraftOpen:b}),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(ro,{open:i,onClose:()=>l(!1),anchorRef:c})]})},oo=({onActiveConnectionDeleted:e,onConnect:n})=>{const s=Vn(n),{connections:r,isBusy:a,isPasswordBusy:i,error:l,pendingConnection:c,connect:d,submitPassword:u,cancelPassword:f,saveConnection:x,removeConnection:v,setError:b}=s,[S,j]=o.useState(null),M=S?r.find(g=>g.id===S)??null:null,[$,m]=o.useState(null),[p,E]=o.useState(""),[z,w]=o.useState(""),[P,R]=o.useState(""),[F,N]=o.useState(""),[D,h]=o.useState(!1),[U,y]=o.useState(!1),C=o.useRef(null),O=o.useMemo(()=>xt(),[]),[q,Y]=o.useState(!1),[Q,A]=o.useState(null),K=o.useCallback(()=>{j(null),E(""),w(""),R(""),b(null),Y(!1)},[b]),G=o.useCallback(g=>{g.preventDefault(),x({id:S??void 0,url:p,label:z,clientToken:P}).then(J=>{J&&K()})},[P,S,z,K,x,p]),k=o.useCallback(async()=>{if(C.current)return;b(null),h(!0);const g=new AbortController;C.current=g;try{const J=await Yn({signal:g.signal});switch(C.current===g&&(C.current=null,h(!1)),J.status){case"ok":E(J.url),J.label&&w(J.label),J.clientToken&&R(J.clientToken),Y(!0);break;case"pairing":y(!0),await s.redeemPairingConnection(J.pairing);break;case"permission-denied":b("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":b("That QR code is not an PiChamber connection code.");break;case"unsupported":b("QR scanning is only available in the installed mobile app.");break;case"failed":b("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{y(!1),C.current===g&&(C.current=null,h(!1))}},[s,b]);o.useEffect(()=>()=>C.current?.abort(),[]);const T=o.useCallback(g=>{g.preventDefault(),u(F)},[F,u]),_=o.useCallback(()=>{N(""),f()},[f]),B=o.useCallback(g=>{m(J=>J===g?null:g)},[]),Z=o.useCallback(g=>{m(null),S===g&&K();const J=r.length===1;v(g).then(ae=>{ae&&(J||Zt(ae))&&e()})},[r.length,S,e,v,K]),X=Oe;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:T,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(g=>g.kind==="direct")?ye(c):"via PiChamber Relay"})]})]}),t.jsx("input",{...Ae,value:F,onChange:g=>N(g.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:X}),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||!F.trim(),children:i?"Connecting...":"Unlock and connect"}),t.jsx(te,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:_,children:"Use another server"})]})})}):t.jsxs(t.Fragment,{children:[D?t.jsx(Jn,{onCancel:()=>C.current?.abort()}):null,U?t.jsx(Qn,{}):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(g=>{const J=$===g.id,ae=Zt(g),pe=Q===g.id,We=pe?"Connecting...":ae?Be()?"Connected · Private relay":"Connected · Local network":g.candidates.some(he=>he.kind==="direct")?ye(g):"via PiChamber Relay";return t.jsxs("div",{className:H("flex items-center border-b border-border/70 transition-colors last:border-b-0",J&&"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:()=>{ae||(A(g.id),d({id:g.id,candidates:g.candidates,clientToken:g.clientToken,label:g.label}).finally(()=>A(null)))},disabled:a&&!pe||J,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]"}),ae?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:g.label}),t.jsx("span",{className:H("block truncate typography-small",ae&&!pe?"text-[var(--status-success)]":"text-muted-foreground"),children:We})]}),pe?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:[J?t.jsxs("button",{type:"button","aria-label":`Confirm deleting ${g.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:()=>Z(g.id),style:{touchAction:"manipulation"},children:[t.jsx(V,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):g.candidates.some(he=>he.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(g.id),E(ye(g)),w(g.label),R(g.clientToken||""),b(null)},style:{touchAction:"manipulation"},children:t.jsx(V,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":J?`Keep ${g.label}`:`Delete ${g.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:()=>B(g.id),style:{touchAction:"manipulation"},children:t.jsx(V,{name:J?"close":"delete-bin",className:"size-[18px]"})})]})]},g.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."}),!q&&!M?t.jsxs("div",{className:"space-y-2",children:[O?t.jsxs(te,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{k()},disabled:D,children:[t.jsx(V,{name:"scan-2",className:H("size-[18px]",D&&"animate-pulse")}),"Scan QR code"]}):null,t.jsxs(te,{type:"button",variant:O?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{b(null),Y(!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:G,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:K,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",{...Ae,value:p,onChange:g=>E(g.target.value),placeholder:"http://192.168.1.74:2606",type:"url",inputMode:"url",autoCapitalize:"none",className:X})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Name"}),t.jsx("input",{value:z,onChange:g=>w(g.target.value),placeholder:"Optional display name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:X})]}),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",{...Ae,value:P,onChange:g=>R(g.target.value),placeholder:"Paste access token",autoCapitalize:"none",className:X}),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"})]})]})})})]})},io=16,lo=320,rn="cubic-bezier(0.22, 1, 0.36, 1)",an=({open:e,onOpenChange:n,variant:s="drawer"})=>{const r=o.useCallback(()=>n(!1),[n]),a=de(b=>b.openNewSessionDraft),i=ie(b=>b.setActiveMainTab),l=ie(b=>b.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 b=window.setTimeout(()=>d(!0),u?0:io);return()=>window.clearTimeout(b)}d(!1)}},[e,u,s]),o.useEffect(()=>{if(s==="sidebar"||!e)return;const b=document.body.style.overflow;document.body.style.overflow="hidden";const S=j=>{j.key==="Escape"&&r()};return document.addEventListener("keydown",S),()=>{document.body.style.overflow=b,document.removeEventListener("keydown",S)}},[r,e,s]);const f=o.useCallback(()=>{ie.getState().closeMainSurfaces(),i("chat"),l(!1),a(),r()},[r,a,i,l]),x=t.jsx(ws,{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:[x,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 v=u?0:lo;return De.createPortal(t.jsxs("div",{className:"fixed inset-0 z-50","aria-hidden":!e,style:{pointerEvents:e?"auto":"none"},children:[t.jsx("button",{type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:r,tabIndex:e?0:-1,style:{opacity:c?1:0,transition:`opacity ${v}ms ${rn}`}}),t.jsx("div",{className:H("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:c?"none":"translateX(-100%)",transition:v?`transform ${v}ms ${rn}`:"none"},children:x}),t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 z-20 flex w-[28%] items-end justify-center",style:{paddingBottom:"calc(1rem + var(--oc-safe-area-bottom, 0px))"},children:e?t.jsx(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)},on="mobile-surface-root",ft=16,Ge=200,co=()=>{if(typeof document>"u")return null;let e=document.getElementById(on);return e||(e=document.createElement("div"),e.id=on,document.body.appendChild(e)),e},mt=({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:x})=>{const v=o.useRef(null),[b,S]=o.useState(!1),[j,M]=o.useState(!1),$=o.useRef(null),m=o.useRef(null),p=o.useRef(n);if(o.useEffect(()=>{p.current=n},[n]),typeof document<"u"&&!v.current&&(v.current=co()),o.useEffect(()=>{if(!e){S(!1);return}const w=window.setTimeout(()=>S(!0),ft);return()=>window.clearTimeout(w)},[e]),o.useEffect(()=>{if(!e){M(!1);return}const w=window.setTimeout(()=>M(!0),ft+Ge+80);return()=>window.clearTimeout(w)},[e]),o.useEffect(()=>{if(!e)return;const w=document.body.style.overflow;m.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const P=()=>{const N=$.current;if(!N)return;(N.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??N).focus({preventScroll:!0})},R=window.setTimeout(P,ft),F=N=>{if(N.key==="Escape"&&!i){p.current();return}if(N.key!=="Tab")return;const D=$.current;if(!D)return;const h=Array.from(D.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(O=>!O.hasAttribute("disabled")&&O.getAttribute("aria-hidden")!=="true");if(h.length===0){N.preventDefault(),D.focus({preventScroll:!0});return}const U=h[0],y=h[h.length-1],C=document.activeElement;N.shiftKey&&C===U?(N.preventDefault(),y.focus({preventScroll:!0})):!N.shiftKey&&C===y&&(N.preventDefault(),U.focus({preventScroll:!0}))};return document.addEventListener("keydown",F),()=>{window.clearTimeout(R),document.body.style.overflow=w,document.removeEventListener("keydown",F),m.current?.focus?.({preventScroll:!0}),m.current=null}},[i,e]),!e||!v.current)return null;const E=u==="dialog",z=t.jsxs("section",{ref:$,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:H("flex flex-col bg-background text-foreground",E?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface fixed inset-0 z-50"),style:E?{opacity:b?1:0,transform:b?"none":"scale(0.97)",transition:`opacity ${Ge}ms ease-out, transform ${Ge}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:b?"none":"translateX(100%)",transition:`transform ${Ge}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{b&&w.target===w.currentTarget&&w.propertyName==="transform"&&M(!0)},children:[l?null:t.jsxs("header",{className:H("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:x}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return E?De.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:b?1:0,paddingLeft:f==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:f==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:n,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:w=>w.stopPropagation(),children:z})}),v.current):De.createPortal(z,v.current)},Zn={"?":{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"}},uo=Zn.M;function fo(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 mo(e){const n=fo(e);return Zn[n]??uo}const po=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:x=!1,showRevert:v=!0}){const b=Se.useMemo(()=>mo(n),[n]),S=b.description,j=d?.insertions??0,M=d?.deletions??0,$=Se.useCallback(z=>{z.key===" "?(z.preventDefault(),a()):z.key==="Enter"&&(z.preventDefault(),i())},[a,i]),m=Se.useCallback(z=>{z.preventDefault(),z.stopPropagation(),a()},[a]),p=Se.useCallback(z=>{z.preventDefault(),z.stopPropagation(),l()},[l]),E=t.jsx("button",{type:"button",onClick:m,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:$,style:f>0?{paddingLeft:`${f}px`}:void 0,children:[x?E:null,t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:b.color},title:S,"aria-label":S,children:b.code}),t.jsx(Pn,{filePath:n.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const z=n.path.lastIndexOf("/");if(z===-1)return t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:n.path,children:n.path});const w=n.path.slice(0,z),P=n.path.slice(z);return t.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:n.path,children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:w}),t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[t.jsx("span",{className:"text-muted-foreground",children:"/"}),t.jsx("span",{className:"text-foreground",children:P.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]})]}),v?t.jsxs(Js,{children:[t.jsx(Qs,{asChild:!0,children:t.jsx("button",{type:"button",onClick:p,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,x?null:E]})}),ln=14,es=e=>e.replace(/\\/g,"/").replace(/^\/+/,"").trim(),cn=(e,n)=>({id:`dir:${e}`,path:e,name:n,children:new Map,directFiles:[],files:[]}),ho=e=>{const n=cn("","");for(const s of e){const r=es(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=cn(c,d);f.files.push(s),l.children.set(d,f),l=f}}l.directFiles.push(s)}return n},go=(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:${es(d.path)}`,kind:"file",depth:i,file:d})};return r(e,0),s},yo=1e3,dn=34,pt=30,qe="pl-0 pr-2",ht=(e,n)=>`${e} ${n}`,bo=({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=ie(k=>k.gitChangesViewMode)==="tree",x=o.useMemo(()=>e.filter(k=>k.entries.length>0),[e]),[v,b]=o.useState(new Set),[S,j]=o.useState(new Set),[M,$]=o.useState(!1),[m,p]=o.useState(null),E=o.useMemo(()=>x.map(k=>ho(k.entries)),[x]),z=o.useMemo(()=>{const k=[];return x.forEach((T,_)=>{Array.from(E[_]?.children.values()??[]).forEach(B=>{k.push(ht(T.id,B.path))})}),k},[E,x]);o.useEffect(()=>{f&&j(k=>{const T=new Set,_=new Set(z);return k.forEach(B=>{(B.slice(B.indexOf(" ")+1).includes("/")||_.has(B))&&T.add(B)}),z.forEach(B=>T.add(B)),T})},[f,z]);const w=o.useMemo(()=>{const k=[];return x.forEach((T,_)=>{if(k.push({type:"header",key:`header:${T.id}`,groupIndex:_}),!v.has(T.id)){if(f){const B=new Set;S.forEach(X=>{X.startsWith(`${T.id} `)&&B.add(X.slice(T.id.length+1))}),go(E[_],B).forEach(X=>{X.kind==="file"?k.push({type:"file",key:`${T.id}:${X.key}`,groupIndex:_,file:X.file,depth:X.depth}):k.push({type:"directory",key:`${T.id}:${X.key}`,groupIndex:_,directory:X.directory,depth:X.depth})});return}T.entries.forEach(B=>{k.push({type:"file",key:`${T.id}:file:${B.path}`,groupIndex:_,file:B,depth:0})})}}),l&&x.length>0&&k.push({type:"revert-all",key:"revert-all"}),k},[v,S,f,l,E,x]),P=w.length,R=P>=yo,F=Gr({count:P,enabled:R,getScrollElement:()=>d.current,estimateSize:()=>dn,overscan:12,getItemKey:k=>w[k]?.key??k}),N=F.getVirtualItems(),D=o.useMemo(()=>{if(!R)return 0;const k=d.current?.scrollTop??0;return N.find(_=>_.end>k)?.index??0},[R,N,d]);o.useEffect(()=>{if(!i)return;const k=T=>T&&T.type==="file"?T.file.path:null;if(P===0){i([]);return}if(!R){const T=[];for(const _ of w)if(_.type==="file"&&(T.push(_.file.path),T.length>=pt))break;i(T);return}i(w.slice(D,D+Math.ceil((d.current?.clientHeight??0)/dn)+pt).map(T=>k(T)).filter(T=>!!T).slice(0,pt))},[i,P,w,R,D]);const h=o.useCallback(k=>{b(T=>{const _=new Set(T);return _.has(k)?_.delete(k):_.add(k),_})},[]),U=o.useCallback((k,T)=>{j(_=>{const B=new Set(_),Z=ht(k,T);return B.has(Z)?B.delete(Z):B.add(Z),B})},[]),y=o.useMemo(()=>{const k=new Set;return x.forEach(T=>T.entries.forEach(_=>k.add(_.path))),Array.from(k)},[x]),C=y.length,O=m?r||m.paths.some(k=>s.has(k)):!1,q=o.useCallback(async()=>{!l||r||y.length===0||(await l(y),$(!1))},[y,r,l]),Y=o.useCallback(async()=>{!c||!m||O||(await c(m.paths),p(null))},[O,c,m]),Q=o.useCallback((k,T)=>{const _=v.has(k.id),B=k.entries.length;return t.jsxs("div",{className:H("sticky top-0 z-10 flex items-center gap-2 py-2",a,qe,!T&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>k.onActionAll(k.entries.map(Z=>Z.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":k.actionAllLabel,title:k.actionAllLabel,children:k.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>h(k.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!_,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:k.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:B}),t.jsx(V,{name:"arrow-down-s",className:H("size-3.5 shrink-0 text-muted-foreground transition-transform",_&&"-rotate-90")})]})]})},[v,a,h]),A=o.useCallback((k,T,_)=>{const B=S.has(ht(k.id,T.path)),Z=T.files.map(g=>g.path),X=r||Z.some(g=>s.has(g));return t.jsxs("div",{className:H("group flex items-center gap-2 py-1.5",qe),style:{paddingLeft:`${_*ln}px`},children:[t.jsxs("button",{type:"button",onClick:()=>U(k.id,T.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":B?`Collapse directory ${T.path}`:`Expand directory ${T.path}`,children:[B?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:T.path,children:T.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:T.files.length})]}),k.showRevertActions!==!1&&c?t.jsx("button",{type:"button",onClick:()=>p({path:T.path,paths:Z,count:Z.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 ${T.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:()=>k.onActionAll(T.files.map(g=>g.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":k.actionSymbol==="+"?`Stage all changes in ${T.path}`:`Unstage all changes in ${T.path}`,title:k.actionSymbol==="+"?`Stage all changes in ${T.path}`:`Unstage all changes in ${T.path}`,children:k.actionSymbol})]})},[S,r,c,s,U]),K=o.useCallback((k,T)=>{if(k.type==="revert-all")return t.jsx("div",{className:H("flex justify-end py-2",qe),children:t.jsxs(te,{variant:"ghost",size:"sm",onClick:()=>$(!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 _=x[k.groupIndex];if(!_)return null;if(k.type==="header")return Q(_,T);if(k.type==="directory")return A(_,k.directory,k.depth);const B=k.file;return t.jsx(po,{file:B,actionLabel:_.getActionLabel(B.path),actionSymbol:_.actionSymbol,onAction:()=>_.onActionFile(B.path),stats:n?.[B.path],onViewDiff:()=>_.onViewDiff(B.path),onRevert:()=>_.onRevertFile(B.path),isReverting:s.has(B.path)||r,rowPaddingClassName:qe,indentPx:k.depth*ln,actionAtStart:!f,showRevert:_.showRevertActions!==!1})},[n,r,f,A,Q,s,x]),G=o.useCallback(k=>{const T=w[k],_=w[k-1];return!T||!_||T.type!=="file"&&T.type!=="directory"||_.type!=="file"&&_.type!=="directory"?!1:_.groupIndex===T.groupIndex},[w]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[t.jsx(St,{ref:d,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:R?t.jsx("div",{style:{height:F.getTotalSize(),position:"relative"},children:N.map(k=>{const T=w[k.index];return T?t.jsx("div",{"data-index":k.index,ref:F.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${k.start}px)`},className:H(G(k.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(T,k.index===0)},T.key):null})}):t.jsx("div",{role:"list","aria-label":"Changed files",children:w.map((k,T)=>t.jsx("div",{className:H("relative",G(T)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(k,T===0)},k.key))})}),t.jsx(Zs,{containerRef:d,disableHorizontal:!0})]}),t.jsx(Lt,{open:M,onOpenChange:k=>{!r&&!k&&$(!1)},children:t.jsxs(zt,{className:"max-w-md",children:[t.jsxs(Ot,{children:[t.jsx(Ft,{children:"Revert all changes?"}),t.jsx($t,{children:C===1?`Revert ${C} changed file? This cannot be undone.`:`Revert ${C} changed files? This cannot be undone.`})]}),t.jsxs(Bt,{children:[t.jsx(te,{variant:"outline",size:"sm",onClick:()=>$(!1),disabled:r,children:"Cancel"}),t.jsx(te,{variant:"destructive",size:"sm",onClick:()=>{q()},disabled:r,children:r?"Reverting...":"Revert all"})]})]})}),t.jsx(Lt,{open:!!m,onOpenChange:k=>{!O&&!k&&p(null)},children:t.jsxs(zt,{className:"max-w-md",children:[t.jsxs(Ot,{children:[t.jsx(Ft,{children:"Revert folder changes?"}),t.jsx($t,{children:m?m.count===1?`This will discard local changes in ${m.count} file under ${m.path}.`:`This will discard local changes in ${m.count} files under ${m.path}.`:null})]}),t.jsxs(Bt,{children:[t.jsx(te,{variant:"outline",size:"sm",onClick:()=>p(null),disabled:O,children:"Cancel"}),t.jsx(te,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:O||!m,children:O?"Reverting...":"Revert folder"})]})]})})]})},xo=lr(()=>me(()=>import("./DiffView-BHS4m_K7.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])).then(e=>({default:e.DiffView}))),vo=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),wo=e=>{const n=e.index?.trim();return!!(n&&n!=="?")},ko=e=>{const n=e.working_dir?.trim(),s=e.index?.trim();return!!(n||s==="?")},un=(e,n)=>n?`${e}\0staged`:e,So=({onClose:e,initialDiffPath:n,initialDiffStaged:s=!1})=>{const{git:r}=In(),a=vo(jt()??null),i=er(a||null),l=tr(a||null),c=nr(a||null),d=ge(I=>I.setActiveDirectory),u=ge(I=>I.ensureAll),f=ge(I=>I.fetchStatus),x=ge(I=>I.fetchBranches),v=ge(I=>I.prefetchDiffs),b=ge(I=>I.getDiff),S=ge(I=>I.setDiff),[j,M]=o.useState(()=>n?{type:"diff",path:n,staged:s}:{type:"list"});o.useEffect(()=>{n&&M(I=>I.type==="diff"&&I.path===n&&I.staged===s?I:{type:"diff",path:n,staged:s})},[n,s]);const[$,m]=o.useState(null),[p,E]=o.useState(null),[z,w]=o.useState(""),[P,R]=o.useState(new Set),[F,N]=o.useState(!1),[D,h]=o.useState(!1),[U,y]=o.useState([]),[C,O]=o.useState([]),[q,Y]=o.useState([]),[Q,A]=o.useState(null),[K,G]=o.useState(null),[k,T]=o.useState(0),_=o.useMemo(()=>{const I=i?.files??[],L=new Map;for(const W of I)L.set(W.path,W);return Array.from(L.values()).sort((W,ee)=>W.path.localeCompare(ee.path))},[i?.files]),B=o.useMemo(()=>_.filter(wo),[_]),Z=o.useMemo(()=>_.filter(ko),[_]),X=o.useMemo(()=>{if(q.length>0)return q;const I=i?.tracking?.includes("/")?i.tracking.split("/")[0]:null;return I||Q?[{name:I||"origin",fetchUrl:Q??"",pushUrl:Q??""}]:[]},[Q,q,i?.tracking]),g=ge(o.useCallback(I=>!a||j.type!=="diff"?null:I.directories.get(a)?.diffCache.get(un(j.path,j.staged))??null,[a,j])),J=o.useMemo(()=>j.type!=="diff"?null:_.find(I=>I.path===j.path)??null,[_,j]),ae=o.useCallback(async(I=!0)=>{if(a)try{await Promise.all([f(a,r),x(a,r)])}catch(L){I&&ne.error(L instanceof Error?L.message:"Failed to refresh repository")}},[a,x,f,r]),pe=o.useCallback(async()=>{if(!a){Y([]),A(null);return}try{const[I,L]=await Promise.all([r.getRemotes(a).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(a).catch(()=>null):Promise.resolve(null)]);Y(I),A(L)}catch{Y([]),A(null)}},[a,r]);o.useEffect(()=>{a&&(d(a),u(a,r))},[a,u,r,d]),o.useEffect(()=>{pe()},[pe]),o.useEffect(()=>{if(!a||_.length===0)return;const I=Array.from(new Set([...B.map(W=>W.path),...C,..._.slice(0,20).map(W=>W.path)])).filter(Boolean);if(I.length===0)return;const L=window.setTimeout(()=>{v(a,r,I,{maxFiles:40})},120);return()=>window.clearTimeout(L)},[_,a,r,v,B,C]),o.useEffect(()=>{if(j.type!=="diff"){G(null);return}const I=un(j.path,j.staged);if(!a||b(a,I)){G(null);return}let L=!1;const W=Ke();return G(null),r.getGitFileDiff(a,{path:j.path,staged:j.staged||void 0}).then(ee=>{L||S(a,I,{original:ee.original??"",modified:ee.modified??"",isBinary:ee.isBinary},W)}).catch(ee=>{L||G(ee instanceof Error?ee.message:String(ee))}),()=>{L=!0}},[a,k,b,r,j,S]);const We=async(I,L)=>{if(a){m(I);try{const W=ee=>{const Re=`${ee.name}/`,lt=i?.tracking?.startsWith(Re)?i.tracking.slice(Re.length):void 0;return{remote:ee.name,branch:lt,rebase:!0}};if(I==="fetch"){if(!L)throw new Error("No remote available");await r.gitFetch(a,{remote:L.name}),ne.success(`Fetched from ${L.name}`)}else if(I==="sync"){if(!L)throw new Error("No remote available");await r.gitFetch(a,{remote:L.name});const ee=await r.getGitStatus(a);if((ee.behind??0)>0){if((ee.files?.length??0)>0){ne.error("Commit or stash your changes before syncing");return}await r.gitPull(a,W(L))}((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),ne.success("Already up to date")}await ae(!1),await pe()}catch(W){ne.error(W instanceof Error?W.message:"Sync Changes failed")}finally{m(null)}}},he=o.useCallback(async(I,L)=>{if(!(!a||I.length===0))try{L==="stage"?I.length>1?await sr(a,I):await rr(a,I[0]):I.length>1?await ar(a,I):await or(a,I[0]),await ae(!1)}catch(W){ne.error(W instanceof Error?W.message:L==="stage"?"Failed to stage changes":"Failed to unstage changes")}},[a,ae]),at=o.useCallback((I,L=!1)=>{M({type:"diff",path:I,staged:L})},[]),ot=o.useCallback(async I=>{if(a){R(L=>new Set(L).add(I));try{await r.revertGitFile(a,I),ne.success(`Reverted ${I}`),await ae(!1)}catch(L){ne.error(L instanceof Error?L.message:"Failed to revert changes")}finally{R(L=>{const W=new Set(L);return W.delete(I),W})}}},[a,r,ae]),as=o.useCallback(async I=>{if(!a||I.length===0||F)return;const L=Array.from(new Set(I));N(!0),R(new Set(L));try{await Promise.all(L.map(W=>r.revertGitFile(a,W))),await ae(!1),ne.success(L.length===1?`Reverted ${L.length} file`:`Reverted ${L.length} files`)}catch(W){ne.error(W instanceof Error?W.message:"Failed to revert changes")}finally{R(new Set),N(!1)}},[a,r,F,ae]),os=o.useCallback(I=>{const L=I.map(W=>W.trim()).filter(Boolean);if(L.length===0){y([]);return}w(W=>`${W.trim()}${W.trim()?`
|
|
21
|
-
|
|
22
|
-
`:""}${L.join(`
|
|
23
|
-
`)}`.trim()),y([])},[]),is=o.useCallback(async()=>{if(!a)return;const I=B.map(L=>L.path).sort();if(I.length===0){ne.error("Select at least one file to describe");return}h(!0);try{const{message:L}=await ir(a,I);w(L.subject?.trim()??""),y(Array.isArray(L.highlights)?L.highlights:[])}catch(L){ne.error(L instanceof Error?L.message:"Failed to generate commit message")}finally{h(!1)}},[a,B]),At=async(I={})=>{if(!a)return;if(!z.trim()){ne.error("Enter a commit message");return}const L=B.map(W=>W.path).sort();if(L.length===0){ne.error("Select at least one file to commit");return}E(I.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(a,z.trim(),{files:L}),ne.success("Commit created"),w(""),y([]),I.pushAfter){const W=i?.tracking?.split("/")[0],ee=X.find(cs=>cs.name===W)??X[0];if(!ee)throw new Error("No remote available");m("sync");const Re=`${ee.name}/`,lt=i?.tracking?.startsWith(Re)?i.tracking.slice(Re.length):void 0;await r.gitFetch(a,{remote:ee.name}),((await r.getGitStatus(a)).behind??0)>0&&await r.gitPull(a,{remote:ee.name,branch:lt,rebase:!0}),((await r.getGitStatus(a)).ahead??0)>0&&await r.gitPush(a),await ae(!1),await pe()}else await ae(!1)}catch(W){ne.error(W instanceof Error?W.message:"Failed to create commit")}finally{E(null),I.pushAfter&&m(null)}},ls=o.useMemo(()=>{const I=[];return B.length>0&&I.push({id:"staged",title:"Staged",entries:B,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:L=>`Unstage ${L}`,onActionFile:L=>{he([L],"unstage")},onActionAll:L=>{he(L,"unstage")},onViewDiff:L=>at(L,!0),onRevertFile:ot,showRevertActions:!1,accent:!0}),Z.length>0&&I.push({id:"unstaged",title:"Changes",entries:Z,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:L=>`Stage ${L}`,onActionFile:L=>{he([L],"stage")},onActionAll:L=>{he(L,"stage")},onViewDiff:L=>at(L,!1),onRevertFile:ot}),I},[ot,at,he,B,Z]),it=I=>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:I})]});return a?c&&l===null?it(t.jsx(ve,{loading:!0,message:"Checking repository..."})):l===!1?it(t.jsx(o.Suspense,{fallback:t.jsx(ve,{loading:!0,message:"Loading last turn changes..."}),children:t.jsx(xo,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):j.type==="diff"?t.jsx(jo,{path:j.path,diff:g,fileExists:!!J,error:K,onBack:()=>M({type:"list"}),onRetry:()=>T(I=>I+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(ks,{syncAction:$,remotes:X,onFetch:I=>{We("fetch",I)},onSync:I=>{We("sync",I)},disabled:p!==null||c,aheadCount:i?.ahead??0,behindCount:i?.behind??0,trackingRemoteName:i?.tracking?.split("/")[0],hasUncommittedChanges:_.length>0})]}),_.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(bo,{groups:ls,diffStats:i?.diffStats,revertingPaths:P,onRevertAll:as,isRevertingAll:F,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:O})}),t.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:t.jsx(qr,{stagedCount:B.length,commitMessage:z,onCommitMessageChange:w,generatedHighlights:U,onInsertHighlights:os,onGenerateMessage:is,isGeneratingMessage:D,onCommit:()=>{At({pushAfter:!1})},onCommitAndPush:()=>{At({pushAfter:!0})},commitAction:p,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(ve,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):it(t.jsx(ve,{message:"Select a session or directory to view Git status"}))},ve=({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]})}),jo=({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(ve,{icon:!0,message:"Content of this file cannot be viewed."}):dr(e)?t.jsx(ve,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):t.jsx(St,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Yr,{original:n.original,modified:n.modified,language:l,fileName:e,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(ve,{loading:!0,message:"Loading diff..."}):t.jsx(ve,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},le=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ie=e=>{const n=le(e);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},ts=e=>{const n=le(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},fn=(e,n)=>{const s=le(e),r=le(n);return!s||!r?!1:s===r||s.startsWith(`${r}/`)},mn=(e,n)=>{const s=le(e);if(!s)return le(n);if(s.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(s))return s;const r=le(n);return r?`${r}/${s}`:s},Co=(e,n)=>{const s=le(e),r=le(n);if(!s||s===r)return!1;const a=ts(s);return a?r&&fn(s,r)?fn(a,r):!0:!1},No=o.lazy(()=>me(()=>import("./FilesView-DmZcdwl-.js"),__vite__mapDeps([118,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,119,120,121,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,122,123,115,116,124,125,113,114,126])).then(e=>({default:e.FilesView}))),Eo=(e,n)=>{const s=le(e),r=le(n);return!r||s===r?Ie(s):s.startsWith(`${r}/`)?s.slice(r.length+1):s},Ro=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""},To=({onClose:e})=>{const{files:n}=In(),s=Cn(y=>y.setSelectedPath),r=le(jt()??null),[a,i]=o.useState(()=>({type:"browser",directory:r})),[l,c]=o.useState([]),[d,u]=o.useState(!1),[f,x]=o.useState(null),[v,b]=o.useState(""),[S,j]=o.useState([]),[M,$]=o.useState(!1),m=o.useRef(0);o.useEffect(()=>{r&&i(y=>y.type==="browser"&&y.directory?y:{type:"browser",directory:r})},[r]);const p=a.type==="browser"?a.directory:a.returnDirectory,E=o.useCallback(async y=>{if(!y)return;const C=m.current+1;m.current=C,u(!0),x(null);try{const O=await n.listDirectory(y);if(m.current!==C)return;c(O.entries.slice().sort((Y,Q)=>Y.isDirectory!==Q.isDirectory?Y.isDirectory?-1:1:Y.name.localeCompare(Q.name)));const q=le(O.directory);q&&q!==le(y)&&i(Y=>Y.type==="browser"&&Y.directory!==q?{type:"browser",directory:q}:Y)}catch(O){if(m.current!==C)return;c([]),x(O instanceof Error?O.message:"Failed to load files")}finally{m.current===C&&u(!1)}},[n]);o.useEffect(()=>{a.type==="browser"&&E(a.directory)},[E,a]),o.useEffect(()=>{if(a.type!=="browser")return;const y=v.trim();if(!y){j([]),$(!1);return}let C=!1;const O=window.setTimeout(()=>{$(!0),n.search({directory:a.directory,query:y,maxResults:40}).then(q=>{C||j(q)}).catch(()=>{C||j([])}).finally(()=>{C||$(!1)})},250);return()=>{C=!0,window.clearTimeout(O)}},[n,v,a]);const z=y=>{b(""),i({type:"browser",directory:y})},w=y=>{s(r,y),i({type:"file",path:y,returnDirectory:p||r})},P=ie(y=>y.pendingFileFocusPath),R=ie(y=>y.pendingFileNavigation);if(o.useEffect(()=>{const y=le(R?.path??P??"");!y||!r||y!==r&&!y.startsWith(`${r}/`)||(s(r,y),i({type:"file",path:y,returnDirectory:r}),P&&ie.getState().setPendingFileFocusPath(null))},[P,R,r,s]),!r)return t.jsx($e,{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(Ht,{className:"size-4"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:Ie(a.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(fe,{children:t.jsx(o.Suspense,{fallback:t.jsx($e,{loading:!0,message:"Loading..."}),children:t.jsx(No,{mode:"editor-only"})})})})]});const F=a.directory===r?"Project files":Ie(a.directory),N=v.trim()?S:[],D=Co(a.directory,r)?ts(a.directory):null,h=!!D&&!v.trim(),U=D===r?"Project files":Ie(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(Jr,{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 ${Ie(D)}`,onClick:()=>z(D),style:{touchAction:"manipulation"},children:t.jsx(Ht,{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:F})}),t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Refresh files",onClick:()=>{E(a.directory)},style:{touchAction:"manipulation"},children:t.jsx(Qr,{className:H("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(Xr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ur,{value:v,onChange:y=>b(y.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),t.jsx(St,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:f?t.jsx($e,{message:f}):v.trim()?t.jsx(Po,{results:N,isSearching:M,onOpenFile:w}):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 ${U}`,onClick:()=>z(D),style:{touchAction:"manipulation"},children:[t.jsx(V,{name:"arrow-left",className:H(yt(!0),"text-muted-foreground")}),t.jsx("span",{className:H(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(y=>t.jsx(ns,{name:y.name,path:y.path,directory:y.isDirectory,meta:y.isDirectory?void 0:Ro(y.size),onClick:()=>y.isDirectory?z(mn(y.path,a.directory||r)):w(mn(y.path,a.directory||r))},y.path))]})})]})},ns=({name:e,path:n,directory:s,meta:r,onClick:a})=>t.jsxs("button",{type:"button",className:An,onClick:a,style:{touchAction:"manipulation"},children:[s?t.jsx(ta,{className:H(yt(!0),"text-primary/80")}):t.jsx(Pn,{filePath:n,className:yt(!0)}),t.jsx("span",{className:H(Dn(!0),"flex-1 text-foreground"),children:e}),r?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:r}):null,s?t.jsx(na,{className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),Po=({results:e,isSearching:n,onOpenFile:s})=>{const r=le(jt()??null);return n?t.jsx($e,{loading:!0,message:"Loading..."}):e.length===0?t.jsx($e,{message:"No files found."}):t.jsx("div",{className:"flex w-full min-w-0 flex-col",children:e.map(a=>t.jsx(ns,{name:Ie(a.path),path:a.path,directory:!1,meta:Eo(a.path,r),onClick:()=>s(a.path)},a.path))})},$e=({message:e,loading:n=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[n?t.jsx(Zr,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ea,{className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),pn="mobile-surface-root",Io=16,hn=320,gn="cubic-bezier(0.22, 1, 0.36, 1)",Ao=[{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"}],yn=({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),x=o.useRef(n);o.useEffect(()=>{x.current=n},[n]);const v=o.useRef(s);o.useEffect(()=>{v.current=s},[s]);const b=o.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[S,j]=o.useState(()=>new Set);if(o.useEffect(()=>{e&&j(p=>{if(p.has(s))return p;const E=new Set(p);return E.add(s),E})},[e,s]),typeof document<"u"&&!l.current){let p=document.getElementById(pn);p||(p=document.createElement("div"),p.id=pn,document.body.appendChild(p)),l.current=p}if(o.useEffect(()=>{if(e){f(!0);const E=window.setTimeout(()=>d(!0),b?0:Io);return()=>window.clearTimeout(E)}d(!1);const p=window.setTimeout(()=>f(!1),hn+40);return()=>window.clearTimeout(p)},[e,b]),o.useEffect(()=>{if(!e)return;const p=document.body.style.overflow;i==="drawer"&&(document.body.style.overflow="hidden");const E=z=>{z.key==="Escape"&&v.current!=="terminal"&&x.current()};return document.addEventListener("keydown",E),()=>{i==="drawer"&&(document.body.style.overflow=p),document.removeEventListener("keydown",E)}},[e,i]),i==="drawer"&&!l.current)return null;const M=b?0:hn,$=t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",role:"tablist","aria-label":"Workspace",children:Ao.map(p=>{const E=s===p.id;return t.jsxs("button",{type:"button",role:"tab","aria-selected":E,onClick:()=>r(p.id),className:H("flex min-w-0 flex-1 items-center justify-center gap-1 rounded-lg px-1.5 py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",E?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(V,{name:p.icon,className:"size-4 shrink-0"}),t.jsx("span",{className:"truncate",children:p.label})]},p.id)})}),m=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center px-2",children:$}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[S.has("changes")?t.jsx("div",{className:H("h-full",s!=="changes"&&"hidden"),children:t.jsx(fe,{children:t.jsx(So,{initialDiffPath:a?.path??null,initialDiffStaged:a?.staged===!0})})},a?`changes:${a.path}:${a.staged}`:"changes"):null,S.has("files")?t.jsx("div",{className:H("h-full",s!=="files"&&"hidden"),children:t.jsx(fe,{children:t.jsx(To,{})})}):null,S.has("terminal")?t.jsx("div",{className:H("h-full",s!=="terminal"&&"hidden"),children:t.jsx(fe,{children:t.jsx(Ss,{visible:e&&s==="terminal"})})}):null,S.has("notes")?t.jsx("div",{className:H("h-full",s!=="notes"&&"hidden"),children:t.jsx(fe,{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:m}):De.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 ${gn}`:"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 ${gn}`:"none"},children:m})]}),l.current)},Ve=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",Do=()=>{o.useEffect(()=>{if(!Ve())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 me(()=>import("./vendor-capacitor-status-bar-B-N0EOVk.js"),__vite__mapDeps([127,128])).then(async({StatusBar:i,Style:l})=>{if(e)return;const c=window.Capacitor?.getPlatform?.(),d=async()=>{if(c==="android"){const v=document.documentElement.classList.contains("dark"),b=(v?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(v?"#171515":"#fffdf4");await i.setOverlaysWebView({overlay:!1}).catch(()=>{}),await i.setBackgroundColor({color:b}).catch(()=>{}),await i.setStyle({style:v?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 me(async()=>{const{App:v}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:v}},__vite__mapDeps([129,8,128])),x=await f.addListener("appStateChange",({isActive:v})=>{v&&d()});if(e){x.remove();return}n.push(()=>{x.remove()})}).catch(()=>{}),me(()=>import("./vendor-capacitor-keyboard-CYccoJjr.js"),__vite__mapDeps([130,128])).then(async({Keyboard:i})=>{if(e)return;if(window.Capacitor?.getPlatform?.()==="android"){const N=await i.addListener("keyboardWillShow",C=>{Ut(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")}),U=await i.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),y=()=>{N.remove(),D.remove(),h.remove(),U.remove()};if(e){y();return}n.push(y);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,x=null,v=0,b=!1,S=0,j=!1;const M=(N,D)=>{s.style.setProperty(N,`${Math.max(0,Math.round(D))}px`)},$=()=>{f!==null&&(window.clearTimeout(f),f=null)},m=(N,D)=>{window.dispatchEvent(new CustomEvent(N,{detail:D}))},p=()=>{const N=[],D=document.querySelector(".oc-mobile-composer");D&&N.push({el:D,factor:1});const h=document.querySelector(".oc-draft-center");return h&&N.push({el:h,factor:.5}),N},E=()=>{for(const{el:N}of p())N.style.transition="",N.style.transform=""},z=await i.addListener("keyboardWillShow",N=>{if($(),Ut(N.keyboardHeight),j=!0,v=N.keyboardHeight,!b){const h=document.querySelector(".oc-mobile-app-shell");S=h&&parseFloat(getComputedStyle(h).paddingBottom)||0}const D=Math.max(0,v-S);s.classList.remove("oc-kb-hide"),x!==null&&(window.clearTimeout(x),x=null),s.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),a(v);for(const{el:h,factor:U}of p())h.style.transition=`transform ${c}ms ${u}`,h.style.transform=`translateY(${-D*U}px)`;M("--oc-kb-scroll-inset",D),m("oc:keyboard-settled",{open:!0}),m("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",v),b=!0,E(),m("oc:keyboard-settled",{open:!0}),x=window.setTimeout(()=>{x=null,s.classList.remove("oc-kb-caret-hold")},250)},c+20)}),w=()=>{if(!j)return;j=!1,$(),m("oc:keyboard-intent",{open:!1}),x!==null&&(window.clearTimeout(x),x=null),s.classList.remove("oc-kb-caret-hold");const N=Math.max(0,v-S);if(s.classList.remove("oc-keyboard-open"),a(0),M("--oc-kb-scroll-inset",0),b){s.classList.remove("oc-kb-animating"),M("--oc-kb-layout",0),b=!1;for(const{el:D,factor:h}of p())D.style.transition="none",D.style.transform=`translateY(${-N*h}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}m("oc:keyboard-anim",{phase:"hide",slide:N,durationMs:d,easing:u}),s.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:D}of p())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"),E(),m("oc:keyboard-settled",{open:!1})},d+20)},P=await i.addListener("keyboardWillHide",w),R=N=>N instanceof HTMLElement&&(N.tagName==="TEXTAREA"||N.tagName==="INPUT"||N.isContentEditable),F=N=>{j&&R(N.target)&&(R(N.relatedTarget)||window.setTimeout(()=>{j&&(R(document.activeElement)||w())},0))};if(document.addEventListener("focusout",F,!0),e){$(),document.removeEventListener("focusout",F,!0),z.remove(),P.remove();return}n.push($,()=>{x!==null&&(window.clearTimeout(x),x=null)},()=>document.removeEventListener("focusout",F,!0),()=>{z.remove()},()=>{P.remove()})}).catch(()=>{}),()=>{e=!0,n.forEach(i=>i()),mr(),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")}},[])},Mo=e=>{const n=o.useRef(!1);o.useEffect(()=>{if(!Ve())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)),me(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:l})=>{if(s)return;const c=await l.addListener("appStateChange",({isActive:u})=>{if(document.documentElement.classList.toggle("oc-native-app-active",u),!u){n.current=!0;return}a()}),d=await l.addListener("resume",a);if(s){c.remove(),d.remove();return}r.push(()=>{c.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(l=>l())}},[e])},_o=e=>{o.useEffect(()=>{if(!Ve())return;let n=!1,s=null;return me(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:r})=>{if(n)return;const a=await r.addListener("backButton",()=>{e()||r.minimizeApp().catch(()=>{})});if(n){a.remove();return}s=()=>{a.remove()}}).catch(()=>{}),()=>{n=!0,s?.()}},[e])},Lo=ra(()=>({statusById:new Map})),zo=()=>{Nn(),Rn()},Oo=e=>{de.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ie.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),Nn(),Cs.getState().clearAll(),ce.setState({providers:[],agents:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),vt.getState().resetForRuntimeSwitch(),Tn.getState().resetForRuntimeSwitch(),Lo.setState({statusById:new Map}),pr(),hr(),sa.getState().reset(),fs.getState().resetForRuntimeSwitch(),ge.getState().resetForRuntimeSwitch(e.runtimeKey),Ns.getState().resetForRuntimeSwitch(),gr.getState().resetForRuntimeSwitch(e.runtimeKey),Cn.getState().resetForRuntimeSwitch(e.runtimeKey),de.getState().restoreForRuntimeSwitch(e.runtimeKey),ie.getState().restoreForRuntimeSwitch(e.runtimeKey),Rn(),queueMicrotask(()=>{En()})};function Fo(e=2500){const{uiFont:n}=yr(),[s,r]=o.useState(!1);return o.useEffect(()=>{let a=!1;const i=()=>{a||r(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(i))},c=Promise.all([br(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),aa.catch(()=>{})]).then(()=>{}),d=new Promise(u=>{window.setTimeout(u,e)});return Promise.race([c,d]).then(l),()=>{a=!0}},[n,e]),s}const $o="pichamber",Bo=e=>e.replace(/^\/+|\/+$/g,""),Uo=e=>{const n=Bo(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...n]:n};function Ho(e){if(typeof e!="string"||e.length===0)return null;let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`${$o}:`)return null;const s=Uo(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 ue={},ss=!1,Fe=null;const Ko=e=>{switch(e.type){case"session":return de.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const n=de.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 ue.openSessions?(ue.openSessions(e.filter),!0):!1;case"status":return ue.openSessions?(ue.openSessions(),!0):!1;case"view":return ue.openView?(ue.openView(e.target),!0):!1;case"changes":return ue.openChanges?(ue.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return ue.openSettings?(ue.openSettings(e.section),!0):!1}},It=()=>{if(!ss||!Fe)return;const e=Fe;Fe=null,Ko(e)||(Fe=e)},rs=e=>{Fe=e,It()},bn=e=>{const n=Ho(e);n&&rs(n)},Vo=e=>{ss=e,It()},Wo=e=>{o.useEffect(()=>(ue=e,It(),()=>{ue===e&&(ue={})}),[e])},Go=e=>{const{ready:n}=e;o.useEffect(()=>{Vo(n)},[n]),o.useEffect(()=>{if(!re())return;let s=!1;const r=[];return me(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,8,128])).then(async({App:a})=>{if(s)return;const i=await a.addListener("appUrlOpen",l=>{bn(l?.url)});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),me(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,128])).then(async({PushNotifications:a})=>{if(s)return;const i=await a.addListener("pushNotificationActionPerformed",l=>{const c=l?.notification?.data,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){bn(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&rs({type:"session",sessionId:u})});if(s){i.remove();return}r.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(a=>a())}},[])},qo=32,Yo=80,Jo=64,Qo=.7,Xo=(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"?Yo:qo;let l=!1,c=!1,d=0,u=0;const f=v=>{if(v.touches.length!==1){l=!1;return}const b=v.touches[0],S=r.clientWidth,j=b.clientX<=i,M=b.clientX>=S-i;l=j||M,c=j,d=b.clientX,u=b.clientY},x=v=>{if(!l)return;l=!1;const b=v.changedTouches[0];if(!b)return;const S=b.clientX-d,j=b.clientY-u;Math.abs(S)<Jo||Math.abs(j)>Math.abs(S)*Qo||c&&S<=0||!c&&S>=0||(c?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",f,{passive:!0}),r.addEventListener("touchend",x,{passive:!0}),()=>{r.removeEventListener("touchstart",f),r.removeEventListener("touchend",x)}},[e])},Zo=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},ei=()=>{if(typeof window>"u")return!1;const n=window.Capacitor?.getPlatform?.();return n==="ios"||n==="android"},ti=e=>{const{enabled:n}=e,s=ie(a=>a.nativeNotificationsEnabled),r=o.useRef(null);o.useEffect(()=>{if(!n||!s||!ei())return;let a=!1;const i=[];return me(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,128])).then(async({PushNotifications:l})=>{if(a)return;let c=await l.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await l.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const d=await l.addListener("registration",f=>{r.current=f.value,gt()?.push?.registerApnsToken?.({token:f.value,platform:Mn(),environment:Zo()})}),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,gt()?.push?.unregisterApnsToken?.({token:a})},[s])},xn=({side:e,isResizing:n,ariaLabel:s,handleProps:r})=>t.jsx("div",{className:H("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:H("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",n&&"bg-[var(--interactive-border)]")})}),ni=320,si=380,vn=280,ri=560,ai=900;function wn(e,n,s,r=ri){const a=o.useRef(null),[i,l]=o.useState(()=>{if(typeof window>"u")return s;const p=Number.parseInt(window.localStorage.getItem(n)??"",10);return Number.isFinite(p)?Math.min(r,Math.max(vn,p)):s}),[c,d]=o.useState(!1),u=o.useRef(0),f=o.useRef(i),x=o.useRef(null),v=o.useRef(null),b=o.useCallback(p=>Math.min(r,Math.max(vn,Math.round(p))),[r]),S=o.useCallback(p=>{const E=a.current;E&&(E.style.width=`${p}px`,E.style.minWidth=`${p}px`,E.style.maxWidth=`${p}px`,E.style.setProperty("--oc-ipad-sidebar-width",`${p}px`))},[]),j=o.useCallback(p=>{try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}v.current=p.pointerId,u.current=p.clientX,f.current=i,x.current=i,d(!0),p.preventDefault()},[i]),M=o.useCallback(p=>{if(v.current!==p.pointerId)return;const E=p.clientX-u.current,z=b(f.current+(e==="left"?E:-E));x.current!==z&&(x.current=z,S(z))},[S,b,e]),$=o.useCallback(p=>{if(v.current!==p.pointerId)return;try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}const E=b(x.current??f.current);v.current=null,x.current=null,d(!1),l(E);try{window.localStorage.setItem(n,String(E))}catch{}},[b,n]),m=o.useMemo(()=>({onPointerDown:j,onPointerMove:M,onPointerUp:$,onPointerCancel:$}),[j,$,M]);return{asideRef:a,width:i,isResizing:c,handleProps:m}}const oi=1e3,ii=({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"),[x,v]=o.useState(null),b=ie(g=>g.setSettingsPage),S=ie(g=>g.isArchivePageOpen),j=ie(g=>g.setArchivePageOpen),M=ie(g=>g.wideChatLayoutEnabled),$=Pe(g=>g.available),m=Pe(g=>g.runtimeType),p=o.useMemo(()=>Ve(),[]),E=!p&&$&&(m==="desktop"||m==="web"),z=o.useCallback(()=>{a(null)},[]),w=o.useCallback(g=>{a(g)},[]),P=o.useCallback(()=>{l(!1)},[]),R=o.useCallback(g=>{f(g),w("settings")},[w]),{enabled:F,roomyForPanels:N}=kt(),h=Ar()==="portrait",U=Dr(),[y,C]=o.useState(()=>Mr().roomyForPanels),O=o.useCallback(()=>{C(g=>!g)},[]);o.useEffect(()=>{F||C(!1)},[F]);const q=o.useCallback(()=>{v(null),d("files"),l(!0)},[]),Y=o.useCallback((g=null)=>{v(g),d("changes"),l(!0)},[]),Q=wn("left","pichamber.ipad.leftSidebarWidth",ni),A=wn("right","pichamber.ipad.rightSidebarWidth",si,ai),K=N,G=K&&i?A.width:0,k=F&&y?Q.width:0;o.useEffect(()=>{if(typeof document>"u")return;const g=document.documentElement;return g.style.setProperty("--oc-chat-inset-left",`${k}px`),g.style.setProperty("--oc-chat-inset-right",`${G}px`),()=>{g.style.removeProperty("--oc-chat-inset-left"),g.style.removeProperty("--oc-chat-inset-right")}},[k,G]),o.useEffect(()=>{if(typeof document>"u")return;const g=document.documentElement;return g.classList.toggle("wide-chat-layout",M),()=>g.classList.remove("wide-chat-layout")},[M]),o.useEffect(()=>{if(typeof document>"u")return;const g=F&&(h||U),J=document.documentElement;return J.classList.toggle("oc-keep-draft-starters",g),()=>J.classList.remove("oc-keep-draft-starters")},[U,F,h]);const T=o.useMemo(()=>({openChanges:({diffPath:g,staged:J}={})=>{Y(g?{path:g,staged:J===!0}:null)},openFiles:()=>q(),openSettings:()=>R("nav"),openInstances:p?()=>w("instances"):void 0,instanceLabel:p?ze():null,openUpdate:E?()=>w("update"):void 0}),[Y,q,R,w,p,E]),_=o.useMemo(()=>({openSessions:()=>{F?C(!0):s(!0)},openView:g=>{if(g==="files"){q();return}(g==="instances"||g==="update"||g==="mcp")&&w(g)},openChanges:({path:g,staged:J}={})=>{Y(g?{path:g,staged:J===!0}:null)},openSettings:g=>{g&&b(g),R(g?"page-content":"nav")}}),[F,Y,q,R,w,b]);Wo(_);const B=o.useRef(null);Xo(B,{onLeftEdgeSwipe:()=>{F?C(!0):s(!0)},onRightEdgeSwipe:()=>l(!0)});const Z=o.useCallback(()=>S?(j(!1),!0):r?(z(),!0):i?(P(),!0):n?(s(!1),!0):!1,[r,z,P,S,n,j,i]);_o(Z);const X=F?"dialog":"fullscreen";return t.jsx(_r,{actions:T,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:[F?t.jsxs("aside",{ref:Q.asideRef,className:H("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!y&&"border-r-0"),style:{width:y?Q.width:0,minWidth:y?Q.width:0,maxWidth:y?Q.width:0,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Q.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!y,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:H("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Q.isResizing&&"pointer-events-none",!y&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(fe,{children:t.jsx(an,{open:!0,variant:"sidebar",onOpenChange:g=>{!g&&!N&&C(!1)}})})}),y?t.jsx(xn,{side:"left",isResizing:Q.isResizing,ariaLabel:"Resize left panel",handleProps:Q.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(ao,{onOpenSessions:()=>F?O():s(!0),onOpenWorkspace:()=>l(!0),compactTitle:F}),t.jsx("main",{ref:B,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(fe,{children:t.jsx(Is,{})})})})]}),F?null:t.jsx(an,{open:n,onOpenChange:s}),F?t.jsxs("aside",{ref:A.asideRef,className:H("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!G&&"border-l-0"),style:{width:G,minWidth:G,maxWidth:G,"--oc-ipad-sidebar-width":`${A.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:A.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:H("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",A.isResizing&&"pointer-events-none",!G&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(fe,{children:t.jsx(yn,{open:i,onClose:P,tab:c,onTabChange:d,pendingChangesDiff:x,variant:K?"panel":"drawer"})})}),G?t.jsx(xn,{side:"right",isResizing:A.isResizing,ariaLabel:"Resize right panel",handleProps:A.handleProps}):null]}):t.jsx(yn,{open:i,onClose:P,tab:c,onTabChange:d,pendingChangesDiff:x}),r==="instances"&&p?t.jsx(mt,{open:!0,variant:X,dialogAlign:"app",onClose:z,ariaLabel:"Instances",title:"Instances",children:t.jsx(oo,{onConnect:z,onActiveConnectionDeleted:e})}):null,r==="settings"?t.jsx(mt,{open:!0,variant:X,dialogAlign:"app",onClose:z,ariaLabel:"Settings",headerless:!0,children:t.jsx(fe,{children:t.jsx(Hr,{forceMobile:!0,isWindowed:!0,initialMobileStage:u,onClose:z})})}):null,r==="update"?t.jsx(mt,{open:!0,variant:X,dialogAlign:"app",onClose:z,ariaLabel:"Update",title:"Update",children:t.jsx(fe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(Kr,{initialUpdateDialogOpen:!0})})})}):null,t.jsx(fe,{children:t.jsx(As,{})})]})})};function li({apis:e}){const n=ce(A=>A.initializeApp),s=ce(A=>A.isInitialized),r=ce(A=>A.isConnected),a=ce(A=>A.connectionPhase),i=ce(A=>A.providers.length),l=ce(A=>A.agents.length),c=ce(A=>A.loadProviders),d=ce(A=>A.loadAgents),u=jn(A=>A.currentDirectory),f=de(A=>A.error),x=de(A=>A.clearError),v=ie(A=>A.setIsMobile),b=xr(A=>A.refreshStatus),[S,j]=o.useState(0),[M,$]=o.useState(0),[m,p]=o.useState(!1),[E,z]=o.useState("pending"),[w,P]=o.useState(null),R=o.useMemo(()=>ze(),[]),[,F]=o.useReducer(A=>A+1,0),N=o.useMemo(()=>Ve(),[]),D=o.useRef(0),h=o.useRef(0),U=o.useCallback(()=>{const A=be(),K=h.current+1;if(h.current=K,!A){dt();return}const G=()=>{n(),b(e.github,{force:!0}),i===0&&c({source:"mobileApp:nativeResume"}),l===0&&d({source:"mobileApp:nativeResume"})},k=()=>{Te({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(_=>_+1)};Je().then(_=>{if(h.current===K){if(_==="no-connection"){k();return}if(_==="needs-login"){P({kind:"auth-expired",label:ze()??""}),k();return}if(_==="unreachable"){window.setTimeout(()=>{h.current===K&&Je().then(B=>{if(h.current===K&&B!=="switched"){if(B==="unchanged"){G();return}B==="needs-login"&&P({kind:"auth-expired",label:ze()??""}),k()}})},4e3);return}_!=="switched"&&G()}});const T=Date.now();T-D.current>=oi&&(D.current=T,window.dispatchEvent(new Event("pichamber:system-resume")))},[l,e.github,n,d,c,i,b]);Do(),Mo(U),o.useEffect(()=>{if(!N)return;let A;const K=()=>{window.clearTimeout(A),A=window.setTimeout(()=>U(),1500)};return window.addEventListener("online",K),()=>{window.removeEventListener("online",K),window.clearTimeout(A)}},[N,U]),o.useEffect(()=>(Mt(e),()=>Mt(null)),[e]),o.useEffect(()=>ms(A=>{if(!!A.runtimeKey&&A.runtimeKey===A.previousRuntimeKey){zo(),F();return}Oo(A),$(G=>G+1),j(G=>G+1)}),[]),o.useEffect(()=>{if(!N||r||be()){z("done");return}let A=!1;return z("attempting"),dt().catch(()=>({status:"no-candidate"})).then(K=>{A||(K.status==="unreachable"?P({kind:"unreachable",label:K.label}):K.status==="needs-login"&&P({kind:"auth-expired",label:K.label}),z("done"))}),()=>{A=!0}},[]),o.useEffect(()=>{if(!N||!be())return;let A=!1;const K=G=>{G&&P(G),Te({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(k=>k+1)};return Je().then(async G=>{if(A||G==="switched"||G==="unchanged")return;const k=ze();if(G==="needs-login"){K({kind:"auth-expired",label:k??""});return}if(G==="unreachable"){K(k?{kind:"unreachable",label:k}:null);return}const T=await dt().catch(()=>({status:"no-candidate"}));A||T.status==="connected"||(T.status==="needs-login"?K({kind:"auth-expired",label:T.label}):T.status==="unreachable"?K({kind:"unreachable",label:T.label}):K(null))}),()=>{A=!0}},[]),o.useEffect(()=>{v(!0)},[v]),o.useEffect(()=>{N&&!be()||n()},[S,n,N]),o.useEffect(()=>{r&&(i===0&&c({source:"mobileApp:recovery"}),l===0&&d({source:"mobileApp:recovery"}))},[l,r,d,c,i]);const y=o.useRef(!1),[C,O]=o.useState(N);o.useEffect(()=>{if(!N||!r||y.current)return;if(de.getState().currentSessionId){y.current=!0,O(!1);return}const A=Ke(),K=vr(A);if(!K){y.current=!0,O(!1);return}let G=!1;const k=window.setTimeout(()=>O(!1),6e3);return(async()=>{const T=await wr().catch(()=>null);if(G)return;if(!T){O(!1);return}y.current=!0;const _=T.activeSessions.find(Z=>Z.id===K.sessionId);if(!_){kr(A),O(!1);return}const B=de.getState();B.currentSessionId||B.setCurrentSession(_.id,wt(_)??K.directory??void 0),O(!1)})(),()=>{G=!0,window.clearTimeout(k)}},[S,r,N]),o.useEffect(()=>{r&&Sr.setDirectory(u)},[u,r]),o.useEffect(()=>{r&&b(e.github,{force:!0})},[e.github,r,b]),o.useEffect(()=>{if(!f)return;const A=window.setTimeout(()=>x(),5e3);return()=>window.clearTimeout(A)},[x,f]),o.useEffect(()=>{if(!(!r&&(N?!!be():!0))){p(!1);return}const K=window.setTimeout(()=>{p(!0)},N?4e3:8e3);return()=>window.clearTimeout(K)},[r,N,S,M]),jr(),hs({enabled:!0}),Es(),gs(),Rs(),ti({enabled:N&&r}),Go({ready:N&&r&&s});const q=Fo(),Y=!r&&a==="reconnecting";if(!q)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(xe,{width:120,height:120,isAnimated:!0})});const Q=!!be();return N&&(!Q||!r&&!Y)?Q?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(xe,{width:120,height:120,isAnimated:!m}),m?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:()=>{Te({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(A=>A+1)},children:"Use another server"})]}):null]})}):E!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(xe,{width:120,height:120,isAnimated:!0}),R?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:[R,t.jsx(Cr,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Ya,{onConnected:()=>j(A=>A+1),notice:w})}):!r&&!Y?m?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(xe,{width:120,height:120,isAnimated:!0})}):t.jsx(fe,{children:t.jsx(Nr,{children:t.jsx(Er,{apis:e,children:t.jsx(Rr,{delayDuration:300,skipDelayDuration:150,children:t.jsx(Ts,{children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[N&&C?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(xe,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Tr,{embeddedBackgroundWorkEnabled:s}),t.jsx(pa,{}),t.jsx(ii,{onActiveConnectionDeleted:()=>{Te({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(A=>A+1)}}),t.jsx(Ps,{}),t.jsx(Pr,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),t.jsx(Ir,{}),s?t.jsx(ba,{}):null]})})})})},M)})}const ci=()=>{ps().then(()=>{Promise.all([En(),ys()]).catch(e=>{console.error("[mobile-main] settings init failed:",e)}),bs(),xs(),vs()}).catch(e=>{console.error("[mobile-main] appearance init failed:",e)}).finally(()=>{oa()})};function Rc(e){window.__PICHAMBER_SURFACE__="mobile",Lr(),ci(),ma(),zr();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",a=e??gt();if(!a)throw new Error("Runtime APIs not registered");const i=r?{...a,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:a,l=t.jsx(li,{apis:i});ds.createRoot(n).render(t.jsx(Se.StrictMode,{children:t.jsx(Or,{children:t.jsx(Fr,{children:t.jsx(Ds,{children:r?l:t.jsx($r,{children:l})})})})}))}export{Rc as renderMobileApp};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as n}from"./index-CRB7i1S2.js";const r=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",p=()=>{if(typeof window>"u"||!r()||s()!=="ios")return!1;const e=navigator.userAgent||"",t=navigator.maxTouchPoints??0;return/iPad/i.test(e)||/Macintosh|MacIntel/i.test(e)&&t>1},s=()=>{if(typeof window<"u"){const t=window.Capacitor?.getPlatform?.();if(t==="ios"||t==="android")return t}return n()?"desktop":"web"},m=()=>{if(typeof navigator>"u")return!1;const e=navigator.platform||"",t=navigator.userAgent||"";return/Win/i.test(e)&&/ARM|aarch64/i.test(t)},i="pichamber-mobile-layout",c=e=>e==="default"?"default":"new",d=()=>{if(typeof window>"u")return"new";try{return c(window.localStorage.getItem(i))}catch{return"new"}},h=e=>{if(typeof window>"u")return!1;try{return window.localStorage.setItem(i,e),!0}catch{return!1}},u=768,f=()=>{if(typeof window>"u")return!1;const e=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(hover: none)").matches:!1,t=typeof navigator<"u"?navigator.maxTouchPoints??0:0;return e||t>0},a=()=>{if(typeof window>"u")return"desktop";const e=window.__PICHAMBER_SURFACE__;if(e==="mobile"||e==="desktop")return e;const t=new URLSearchParams(window.location.search).get("surface");if(t==="mobile"||t==="desktop")return t;if(r())return"mobile";if(n())return"desktop";const o=Math.min(window.innerWidth||Number.POSITIVE_INFINITY,window.screen?.width||Number.POSITIVE_INFINITY);return Number.isFinite(o)&&o<=u&&f()&&d()==="new"?"mobile":"desktop"},P=()=>{const e=a();return typeof window<"u"&&(window.__PICHAMBER_SURFACE__=e),e},g=()=>a()==="mobile";export{g as a,p as b,d as c,m as d,s as g,r as i,P as r,h as s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{by as v,Y as R,t as _,v as D,O as A,bz as P,bA as L,bB as O,D as E}from"./index-CRB7i1S2.js";import{c as k}from"./vendor-zustand-CnsBKjP5.js";const S=()=>A.filter(e=>L.has(e.id)).map(e=>({...O(e)})),U=()=>{if(typeof window>"u")return E;const e=window.localStorage.getItem("openInAppId");return e&&v(e)?e:E};let g=!1,f=!1,o=!1,d=0,u=null;const C=()=>{u&&(clearTimeout(u),u=null)},B=k()((e,m)=>({selectedAppId:U(),availableApps:S(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(g||typeof window>"u")return;g=!0;const i=(t,n=!0)=>{if(!Array.isArray(t)||t.length===0){e({availableApps:S(),hasLoadedApps:n});return}const l=new Set(t.map(s=>s.name)),p=new Map(t.map(s=>[s.name,s.iconDataUrl??void 0])),I=A.filter(s=>l.has(s.appName)||L.has(s.id)).map(s=>({...O(s),iconDataUrl:p.get(s.appName)}));e({availableApps:I,hasLoadedApps:!0})},r=async t=>{if(!_()||!D()||f||m().hasLoadedApps&&!t)return;const l=A.map(p=>p.appName);C(),f=!0,o=!1,e({isScanning:!0});try{const{apps:p,success:a,hasCache:I,isCacheStale:s}=await P(l,t),b=a&&!I&&p.length===0&&d<3;if(e({isCacheStale:I?s:!1}),i(p,a?!b:!1),a){if(b){const w=[800,1600,3200][d]??3200;d+=1,o=!0,u=setTimeout(()=>{r()},w);return}d=0,o=!1;return}if(d<3){const w=[1e3,3e3,7e3][d]??7e3;d+=1,o=!0,u=setTimeout(()=>{r()},w)}}finally{f=!1,o||e({isScanning:!1})}};r();const h=t=>{const n=t.detail,l=n&&typeof n.openInAppId=="string"&&n.openInAppId.length>0&&v(n.openInAppId)?n.openInAppId:null;l&&(window.localStorage.setItem("openInAppId",l),e({selectedAppId:l}))},c=()=>{r()},y=t=>{const n=t.detail;Array.isArray(n)&&(d=3,o=!1,e({isScanning:!1,isCacheStale:!1}),i(n))};window.addEventListener("pichamber:settings-synced",h),window.addEventListener("pichamber:app-ready",c),window.addEventListener("pichamber:installed-apps-updated",y),window.__pichamberAppReady&&r(),window.setTimeout(()=>{m().hasLoadedApps||r()},5e3)},loadInstalledApps:async i=>{if(g||m().initialize(),!_()||!D()||f||m().hasLoadedApps&&!i)return;const h=A.map(c=>c.appName);C(),i&&e({hasLoadedApps:!1}),f=!0,o=!1,e({isScanning:!0});try{const{apps:c,hasCache:y,isCacheStale:N}=await P(h,i),t=new Set(c.map(a=>a.name)),n=new Map(c.map(a=>[a.name,a.iconDataUrl??void 0])),p=A.filter(a=>t.has(a.appName)||L.has(a.id)).map(a=>({...a,iconDataUrl:n.get(a.appName)}));e({availableApps:p.length>0?p:S(),hasLoadedApps:p.length>0,isCacheStale:y?N:!1})}finally{f=!1,o||e({isScanning:!1})}},selectApp:async i=>{v(i)&&(e({selectedAppId:i}),typeof window<"u"&&window.localStorage.setItem("openInAppId",i),await R({openInAppId:i}))}}));export{B as u};
|
|
File without changes
|