@pi-chamber/web 1.0.6-rc.4 → 1.0.6-rc.5

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.
Files changed (119) hide show
  1. package/dist/assets/{DiagramView-BZ--w7Lh.js → DiagramView--XO16VPB.js} +1 -1
  2. package/dist/assets/{DiffView-Dtn6otnT.js → DiffView-Duy2_7Gp.js} +6 -6
  3. package/dist/assets/{FileSaveConflictDialog-p1ik30al.js → FileSaveConflictDialog-B1DvL9zy.js} +1 -1
  4. package/dist/assets/{FilesView-D0Z0VmQm.js → FilesView-CjjPpE4c.js} +4 -4
  5. package/dist/assets/{GitHubDetailScaffold-a27RksFo.js → GitHubDetailScaffold-DqxAKqCT.js} +2 -2
  6. package/dist/assets/{GitHubLinkPicker-B0CfzNfk.js → GitHubLinkPicker-ELF_chia.js} +1 -1
  7. package/dist/assets/GitHubListPrimitives-C2nGTntk.js +1 -0
  8. package/dist/assets/{GitView-BNkoaVYl.js → GitView-5fIq2nzM.js} +4 -4
  9. package/dist/assets/IssuesSurface-Dq5A_bWq.js +7 -0
  10. package/dist/assets/{JsonTreeView-CEiJsFnP.js → JsonTreeView-BjFFSUwi.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-418ChlsN.js → MarkdownRendererImpl-B9Cu4TCh.js} +2 -2
  12. package/dist/assets/{PatchDiff-BtOv_oLB.js → PatchDiff-CTqTTcg7.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-CkuyY9ne.js → PierreDiffViewer-H2f4pJ1k.js} +1 -1
  14. package/dist/assets/PullRequestsSurface-DPpb2RW_.js +2 -0
  15. package/dist/assets/{SessionSwitcherContent-DkfjRgwv.js → SessionSwitcherContent-B5DaBWZU.js} +1 -1
  16. package/dist/assets/{SessionSwitcherDropdown-CEw8BEs6.js → SessionSwitcherDropdown-D86FaZg_.js} +2 -2
  17. package/dist/assets/SessionUnreadDot-CY9-1iV2.js +1 -0
  18. package/dist/assets/SettingsView-CiIuOi_E.js +6 -0
  19. package/dist/assets/{SettingsWindow-D03Z9QyW.js → SettingsWindow-Bw1dUoJ1.js} +1 -1
  20. package/dist/assets/{StickyHorizontalScrollbar-CONTbZgX.js → StickyHorizontalScrollbar-DNsbTLS7.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-DibddNlz.js → ToolOutputDialog-aR4kcgKL.js} +5 -5
  22. package/dist/assets/{ToolPartDiffPreview-Bx7T1M2f.js → ToolPartDiffPreview-B_wWmhtE.js} +1 -1
  23. package/dist/assets/{VirtualizedFileDiff-BY-mDMT8.js → VirtualizedFileDiff-BYby097w.js} +4 -4
  24. package/dist/assets/{Virtualizer-cIf8dSOQ.js → Virtualizer-okhy9Aq3.js} +1 -1
  25. package/dist/assets/{collapsible-BhQdnj8G.js → collapsible-Dz0bPrJ_.js} +1 -1
  26. package/dist/assets/{computeVirtualFileMetrics-CzkFqhaU.js → computeVirtualFileMetrics-8MuwxSC6.js} +1 -1
  27. package/dist/assets/{contextFileOpenGuard-CjCOK8EB.js → contextFileOpenGuard-fZ2NIQMQ.js} +1 -1
  28. package/dist/assets/{fileTreeStatus-CPTpyKOV.js → fileTreeStatus-BzhMMLA9.js} +2 -2
  29. package/dist/assets/{gitStatusPredicates-_GNbGCCb.js → gitStatusPredicates-Cyh9UhYX.js} +1 -1
  30. package/dist/assets/{githubLink-CwIFogWd.js → githubLink-D2PznPcI.js} +2 -2
  31. package/dist/assets/{index-DjOKW10B.js → index-BX5pAOQX.js} +1 -1
  32. package/dist/assets/index-Cs2nBW_t.js +11 -0
  33. package/dist/assets/{index-D7k62S9M.css → index-tmO0fZa4.css} +1 -1
  34. package/dist/assets/{main-1wmEZ4Is.js → main-7vBNPBMb.js} +4 -4
  35. package/dist/assets/{main-C51a3z3b.js → main-BI6qe8pz.js} +2 -2
  36. package/dist/assets/{markdownCore-Dsr6dY5C.js → markdownCore-D5jiabKe.js} +1 -1
  37. package/dist/assets/{miniChat-DCxCx1fF.js → miniChat-B3up4Bnz.js} +2 -2
  38. package/dist/assets/{mobile-D6Ac2Mu3.js → mobile-B4vLFgBc.js} +2 -2
  39. package/dist/assets/{nativeFileSave-P_Eg5Dgb.js → nativeFileSave-DpBH1Sa3.js} +1 -1
  40. package/dist/assets/{pi-session-focus-preference-DjDyjZ1C.js → pi-session-focus-preference-BrB72skF.js} +3 -3
  41. package/dist/assets/{renderDiffWithHighlighter-CK_inhQE.js → renderDiffWithHighlighter-B6T04JGG.js} +1 -1
  42. package/dist/assets/{renderElectronMiniChatApp-wBNgFl0U.js → renderElectronMiniChatApp-CX10w321.js} +2 -2
  43. package/dist/assets/{renderFileWithHighlighter-B_PFeRW5.js → renderFileWithHighlighter-DtAcGyJr.js} +1 -1
  44. package/dist/assets/{renderMobileApp-B3mhxGnb.js → renderMobileApp-C9n-BhPZ.js} +3 -3
  45. package/dist/assets/runtimeEndpointReset-aGyXPXPs.js +62 -0
  46. package/dist/assets/{runtimeSurface-C3YPOBlg.js → runtimeSurface-DiP2a57a.js} +1 -1
  47. package/dist/assets/{useAppFontEffects-CoFst31H.js → useAppFontEffects-Oyin3dgQ.js} +92 -92
  48. package/dist/assets/useGitHubRemoteSearch-CZ9Hauw0.js +1 -0
  49. package/dist/assets/{useSwitcherItems-DHCCg4GF.js → useSwitcherItems-BSqDA1IF.js} +1 -1
  50. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-B9_YeZyx.js → vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-CKSCJw-4.js → vendor-base-ui-BCqPBzDj.js} +1 -1
  52. package/dist/assets/{vendor-boot-Ciu-Edvy.js → vendor-boot-3SaHYVb1.js} +1 -1
  53. package/dist/assets/{vendor-capacitor-app-Bpy_aPMq.js → vendor-capacitor-app-NbQ-WiPS.js} +1 -1
  54. package/dist/assets/{vendor-capacitor-keyboard-DO8AIjrZ.js → vendor-capacitor-keyboard-CgrHt8iN.js} +1 -1
  55. package/dist/assets/{vendor-capacitor-status-bar-SQkytwUW.js → vendor-capacitor-status-bar-CWt0OF5t.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-autocomplete-CInQsE8a.js → vendor-codemirror-autocomplete-WThuuUAz.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-QbsN3LGE.js → vendor-codemirror-lang-angular-BbLGCxF6.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-cpp-BT5U7lxV.js → vendor-codemirror-lang-cpp-Cceks-9O.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-css-dF-Dxbty.js → vendor-codemirror-lang-css-D1wpUg3Z.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-lang-go-e4dp1bar.js → vendor-codemirror-lang-go-Cv0zXHHM.js} +1 -1
  61. package/dist/assets/{vendor-codemirror-lang-html-DKcbBVQ4.js → vendor-codemirror-lang-html-DbL8oT9H.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-lang-java-CB2-FWv6.js → vendor-codemirror-lang-java-CNugenuC.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-javascript-B1zJk7xE.js → vendor-codemirror-lang-javascript-Bx_FIyZF.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-jinja-BsERjdSd.js → vendor-codemirror-lang-jinja-DDGjB3Zq.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-json-C0pZ0NhY.js → vendor-codemirror-lang-json-DIvqf9Pb.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-less-_N9HmR4h.js → vendor-codemirror-lang-less-D8r9dGG1.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-liquid-D02xJRCD.js → vendor-codemirror-lang-liquid-B24mguYi.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-markdown-_6ojeUuZ.js → vendor-codemirror-lang-markdown-v3yG2sbf.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-php-DguCnbJA.js → vendor-codemirror-lang-php-BcZGalqy.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-python-Byr5gw5f.js → vendor-codemirror-lang-python-b-JqEwQy.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-rust-DN6Wh0eK.js → vendor-codemirror-lang-rust-B1uZxDW-.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sass-DOlEW7q1.js → vendor-codemirror-lang-sass-DqPrngKp.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-sql-BJzE9Dby.js → vendor-codemirror-lang-sql-UyCnpt-k.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-vue-DR8E-2nr.js → vendor-codemirror-lang-vue-xDwYkovV.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-wast-n6lcDH5S.js → vendor-codemirror-lang-wast-CF3169p_.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-xml-Cf2lmlmY.js → vendor-codemirror-lang-xml-FCtVhuOb.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-yaml-DSR_E0yh.js → vendor-codemirror-lang-yaml-g0sPmAnv.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-language-data-CSid5JuX.js → vendor-codemirror-language-data-B03xgzP2.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-search-8lY3lt6q.js → vendor-codemirror-search-Dw3Wpu15.js} +1 -1
  80. package/dist/assets/{vendor-lezer-cpp-DZYTDKiD.js → vendor-lezer-cpp-Cu3E-KUI.js} +1 -1
  81. package/dist/assets/{vendor-lezer-css-6qV4fYNQ.js → vendor-lezer-css-Cb8vp67u.js} +1 -1
  82. package/dist/assets/{vendor-lezer-go-BDi_Iblq.js → vendor-lezer-go-BTsIaOm7.js} +1 -1
  83. package/dist/assets/{vendor-lezer-html-BjqcY-oJ.js → vendor-lezer-html-UQMsUwj-.js} +1 -1
  84. package/dist/assets/{vendor-lezer-java-J2BXqz1h.js → vendor-lezer-java-BIWrFrAx.js} +1 -1
  85. package/dist/assets/{vendor-lezer-javascript-CiQ9F8yX.js → vendor-lezer-javascript-BH2Etgoy.js} +1 -1
  86. package/dist/assets/{vendor-lezer-json-BxN83KKR.js → vendor-lezer-json-CE-QUCwM.js} +1 -1
  87. package/dist/assets/{vendor-lezer-lr-BVsDua_K.js → vendor-lezer-lr-HY6Yc0Vr.js} +1 -1
  88. package/dist/assets/{vendor-lezer-markdown-BkMtRQ3X.js → vendor-lezer-markdown-xFL3Evwf.js} +1 -1
  89. package/dist/assets/{vendor-lezer-php-B3XqnXdP.js → vendor-lezer-php-Cr_mQGrG.js} +1 -1
  90. package/dist/assets/{vendor-lezer-python-D342CidI.js → vendor-lezer-python-BNRFWCb0.js} +1 -1
  91. package/dist/assets/{vendor-lezer-rust-Dbfg_4LA.js → vendor-lezer-rust-BvfOK5cU.js} +1 -1
  92. package/dist/assets/{vendor-lezer-sass-ClxPaFt1.js → vendor-lezer-sass-qoxiLisk.js} +1 -1
  93. package/dist/assets/{vendor-lezer-xml-I_S6FQ1u.js → vendor-lezer-xml--x8SSpqU.js} +1 -1
  94. package/dist/assets/{vendor-lezer-yaml-COA6HWLP.js → vendor-lezer-yaml-BDo1JaEr.js} +1 -1
  95. package/dist/assets/{vendor-replit-codemirror-vim-7IE2zVmx.js → vendor-replit-codemirror-vim-D1Fe7FiY.js} +1 -1
  96. package/dist/assets/{web-components-CzkvK_V5.js → web-components-CkTNGkJ2.js} +4 -4
  97. package/dist/index.html +4 -4
  98. package/dist/mini-chat.html +3 -3
  99. package/dist/mobile.html +3 -3
  100. package/package.json +1 -1
  101. package/server/lib/pi/archive-store.js +38 -10
  102. package/server/lib/pi/archive-store.test.js +10 -0
  103. package/server/lib/pi/routes.js +60 -17
  104. package/server/lib/pi/routes.test.js +186 -8
  105. package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -1
  106. package/server/lib/pi/session-daemon/session-daemon-engines.test.js +18 -0
  107. package/server/lib/pi/session-daemon/session-daemon.js +24 -1
  108. package/server/lib/pi/session-shelf-store.js +155 -84
  109. package/server/lib/pi/session-shelf-store.test.js +134 -33
  110. package/server/lib/pi/ui-settings-store.js +59 -0
  111. package/server/lib/pi/ui-settings-store.test.js +105 -6
  112. package/dist/assets/GitHubListPrimitives-LFdR70l6.js +0 -1
  113. package/dist/assets/IssuesSurface-D4kD7_VW.js +0 -7
  114. package/dist/assets/PullRequestsSurface-PML07zr-.js +0 -2
  115. package/dist/assets/SessionUnreadDot-DXUn8-ss.js +0 -1
  116. package/dist/assets/SettingsView-BvUeFUqw.js +0 -6
  117. package/dist/assets/index-Cfrwo5uQ.js +0 -11
  118. package/dist/assets/runtimeEndpointReset-D8lAOCUB.js +0 -62
  119. package/dist/assets/useGitHubRemoteSearch-C0-6hhMJ.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-D0Z0VmQm.js","assets/vendor-boot-Ciu-Edvy.js","assets/vendor-react-Bz1tRBxM.js","assets/vendor-clsx-B-dksMZM.js","assets/index-Cfrwo5uQ.js","assets/vendor-zustand-CXhN0IMY.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-tailwind-merge-BKkUfl9q.js","assets/vendor-fuse.js-t_7AcMTv.js","assets/index-D7k62S9M.css","assets/useAppFontEffects-CoFst31H.js","assets/runtimeSurface-C3YPOBlg.js","assets/nativeFileSave-P_Eg5Dgb.js","assets/vendor-codemirror-lang-javascript-B1zJk7xE.js","assets/vendor-lezer-javascript-CiQ9F8yX.js","assets/vendor-lezer-lr-BVsDua_K.js","assets/vendor-codemirror-autocomplete-CInQsE8a.js","assets/vendor-codemirror-lang-json-C0pZ0NhY.js","assets/vendor-lezer-json-BxN83KKR.js","assets/vendor-codemirror-lang-css-dF-Dxbty.js","assets/vendor-lezer-css-6qV4fYNQ.js","assets/vendor-codemirror-lang-html-DKcbBVQ4.js","assets/vendor-lezer-html-BjqcY-oJ.js","assets/vendor-codemirror-lang-markdown-_6ojeUuZ.js","assets/vendor-lezer-markdown-BkMtRQ3X.js","assets/vendor-codemirror-language-data-CSid5JuX.js","assets/vendor-codemirror-lang-python-Byr5gw5f.js","assets/vendor-lezer-python-D342CidI.js","assets/shell-CjFT_Tl9.js","assets/appThemeRegistry-Ca8eGRB9.js","assets/registerCustomTheme-C-h6lsYW.js","assets/themeResolver-DrfmQi8i.js","assets/vendor-pierre-theming-BO6EPniU.js","assets/vendor-shikijs-core-Ck_OPM_T.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-DPFxvYtK.js","assets/vendor-hast-util-to-html-O3stl53j.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-C40bX6nM.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/FileSaveConflictDialog-p1ik30al.js","assets/vendor-react-drawio-IYnLUY5N.js","assets/runtimeEndpointReset-D8lAOCUB.js","assets/SessionUnreadDot-DXUn8-ss.js","assets/permissionStore-zIpxq9Pq.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/vendor-xterm-xterm-css-DDGTF8rc.css","assets/fileTreeStatus-CPTpyKOV.js","assets/JsonTreeView-CEiJsFnP.js","assets/web-components-CzkvK_V5.js","assets/computeVirtualFileMetrics-CzkFqhaU.js","assets/vendor-shiki-BEwTOAFg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-DL394yyj.js","assets/vendor-oniguruma-to-es-DgwFOwdE.js","assets/vendor-oniguruma-parser-BrbMHgHx.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/Virtualizer-cIf8dSOQ.js","assets/renderFileWithHighlighter-B_PFeRW5.js","assets/vendor-codemirror-search-8lY3lt6q.js","assets/vendor-replit-codemirror-vim-7IE2zVmx.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/StickyHorizontalScrollbar-CONTbZgX.js","assets/GitView-BNkoaVYl.js","assets/gitStatusPredicates-_GNbGCCb.js","assets/GitHubDetailScaffold-a27RksFo.js","assets/vendor-dompurify-BGCr_sdL.js","assets/collapsible-BhQdnj8G.js","assets/vendor-base-ui-CKSCJw-4.js","assets/PierreDiffViewer-CkuyY9ne.js","assets/VirtualizedFileDiff-BY-mDMT8.js","assets/renderDiffWithHighlighter-CK_inhQE.js","assets/vendor-diff-C3JhlQdm.js","assets/PullRequestsSurface-PML07zr-.js","assets/useGitHubRemoteSearch-C0-6hhMJ.js","assets/GitHubListPrimitives-LFdR70l6.js","assets/IssuesSurface-D4kD7_VW.js","assets/githubLink-CwIFogWd.js","assets/vendor-capacitor-app-Bpy_aPMq.js"])))=>i.map(i=>d[i]);
2
- import{j as e,aP as We,aQ as He,aR as Vt}from"./vendor-boot-Ciu-Edvy.js";import{a as qe,R as t}from"./vendor-react-Bz1tRBxM.js";/* empty css */import{b as Ae,d as Gt,e as tt,f as W,u as Ct,i as Xt,h as Ee,n as Kt,r as he,j as de,s as Pe,k as Yt,l as qt,m as nt,o as Qt,p as Nt,q as Jt,t as Zt,v as en}from"./index-Cfrwo5uQ.js";import{f as tn,a as nn,s as sn}from"./pi-session-focus-preference-DjDyjZ1C.js";import{u as rn,M as an,a as on,i as ln,D as st,b as rt,c as it,g as cn,d as at,e as un,s as dn,S as fn,f as hn,T as pn,h as ot,j as lt,k as mn,r as bn,l as xn,m as gn,n as yn,H as vn,A as wn,C as Sn,o as jn,p as Rn,q as kn,O as En,F as Cn,t as Nn,v as Tn,W as In,w as Pn}from"./runtimeEndpointReset-D8lAOCUB.js";import{g as De,l as An,u as Dn,a as Tt,b as _n,c as Mn,r as It,d as Ln,e as Ce,t as $e,o as On,I as ce,s as zn,f as Pt,P as we,B as Se,S as Wn,h as ue,i as Un,j as Bn,k as Hn,m as $n,n as Fn,p as Vn,q as Gn,v as At,w as Xn,E as re,C as Le,x as Dt,y as Kn,z as Yn,A as ct,D as qn,F as Qn,G as Jn,H as Zn,J as es,K as ts,L as ns,M as ss,N as rs,O as pe,Q as is,R as me,T as as,U as os,V as ls,W as cs,X as us,Y as ds,Z as fs,_ as hs,$ as ps,a0 as ms,a1 as bs,a2 as xs,a3 as gs,a4 as ys,a5 as vs,a6 as ws,a7 as Ss,a8 as js,a9 as Rs,aa as ks,ab as Es,ac as Cs,ad as Ns,ae as Ts}from"./useAppFontEffects-CoFst31H.js";import{u as Is,i as ut,p as Ps,s as As,m as Ds,M as _s,a as Ms,c as Ls,b as Oe,d as Fe,e as Os,g as ve,S as zs,A as Ws,f as Ve,r as Us}from"./SettingsView-BvUeFUqw.js";import{f as Bs,S as Hs,a as $s}from"./SessionUnreadDot-DXUn8-ss.js";import{u as Fs}from"./useSwitcherItems-DHCCg4GF.js";import{_ as Me}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-aparajita-capacitor-secure-storage-B9_YeZyx.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";/* empty css */import"./nativeFileSave-P_Eg5Dgb.js";import"./permissionStore-zIpxq9Pq.js";import"./runtimeSurface-C3YPOBlg.js";import"./vendor-qrcode-gzL9QFkg.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./collapsible-BhQdnj8G.js";import"./vendor-base-ui-CKSCJw-4.js";let _t=null,dt=!1;const Vs=new Promise(s=>{_t=s});function Gs(){dt||(dt=!0,_t?.())}const Xs=6,Ks=s=>s.parentID??null,ft=s=>{const n=s.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},Ys=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),qs=(s,n)=>{if(!s)return"";let r=null,i=-1;for(const l of n){const a=Ys(l.path);(s===a||s.startsWith(`${a}/`))&&a.length>i&&(r=l,i=a.length)}return r?r.label?.trim()||ft(r.path):ft(s)},Qs=()=>{const s=De().getState().catalog,n=[];for(const d of s.byId.values())d.archived||n.push(An(d));const r=Dn.getState().index.session.unseenCount,i=Tt.getState().projects,l=_n.getState().ids,a=Mn.getState().rankById;let o=0;const v=[];for(const d of n){const b=Ks(d)!==null,w=(r[d.id]??0)>0;w&&(o+=1),b||v.push({session:d,unread:w,project:qs(It(d),i)})}v.sort(Ln(l,a,d=>d.session));const p=v.slice(0,Xs).map(({session:d,unread:b,project:R})=>({id:d.id,title:d.title??"",unread:b,project:R}));return{runtimeKey:Ae(),attentionCount:o,recentSessions:p}},Js="__PICHAMBER_WIDGET_SNAPSHOT__",Zs=()=>{typeof window>"u"||(window[Js]=()=>{try{return JSON.stringify(Qs())}catch{return null}})},Ge="mobile-app-update-available",ht="mobile-app-update-toast-dismissed-version",er=()=>{const s=Ce(a=>a.available),n=Ce(a=>a.runtimeType),r=Ce(a=>a.info?.version),i=Ce(a=>a.info?.downloadUrl),l=qe.useRef(new Set);return qe.useEffect(()=>{if(Gt()!=="android"||n!=="mobile"||!s||!r||!i){$e.dismiss(Ge);return}tt().getItem(ht)!==r&&(l.current.has(r)||(l.current.add(r),$e.info("PiChamber update available",{id:Ge,description:`Version ${r} is ready for Android.`,duration:1/0,icon:e.jsx(ce,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{On(i)}},cancel:{label:"Dismiss",onClick:()=>{tt().setItem(ht,r),$e.dismiss(Ge)}}})))},[s,i,n,r]),null},tr=s=>{const{persisted:n,persistedDirectory:r,stale:i,ready:l,catalog:a,runtimeKey:o,capturedRuntimeKey:v,storeIdentityMatches:p,generationMatches:d}=s;if(!n||!r)return{action:"wait"};if(i||o!==v||!p||!d)return{action:"wait"};if(!l||!a)return{action:"wait"};const b=a.byId.get(n.sessionId);return!b||b.archived?{action:"clear"}:{action:"select",sessionId:b.id,directory:b.directory??r}},nr=({onConnected:s,notice:n=null})=>{const r=Is(s),{connections:i,isBusy:l,isPasswordBusy:a,error:o,pendingConnection:v}=r,[p,d]=t.useState(""),[b,R]=t.useState(""),[w,T]=t.useState(""),[y,P]=t.useState(!1),[E,N]=t.useState(!1),C=t.useRef(null),h=t.useMemo(()=>ut(),[]),[f,A]=t.useState(()=>!ut()),[S,$]=t.useState(null),[G,B]=t.useState(""),_=t.useCallback(x=>{x.preventDefault(),r.connect({url:p,clientToken:w,label:b})},[w,r,b,p]),M=t.useCallback(x=>{if(/^pichamber:\/\//i.test(x.trim())){const k=Ps(x);if(k){if("pairing"in k){r.redeemPairingConnection(k.pairing);return}d(k.url),k.label&&R(k.label),k.clientToken&&T(k.clientToken);return}}d(x)},[r]),g=t.useCallback(async()=>{if(C.current||l)return;r.setError(null),P(!0);const x=new AbortController;C.current=x;try{const k=await As({signal:x.signal});switch(C.current===x&&(C.current=null,P(!1)),k.status){case"ok":N(!0),d(k.url),k.label&&R(k.label),k.clientToken&&T(k.clientToken),await r.connect({url:k.url,clientToken:k.clientToken,label:k.label});break;case"pairing":N(!0),await r.redeemPairingConnection(k.pairing);break;case"permission-denied":r.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":r.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":r.setError("QR scanning is only available in the installed mobile app.");break;case"failed":r.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{N(!1),C.current===x&&(C.current=null,P(!1))}},[r,l]);t.useEffect(()=>()=>C.current?.abort(),[]);const L=t.useCallback(x=>{x.preventDefault(),r.submitPassword(G)},[r,G]),j=t.useMemo(()=>zn(i.map(x=>Ds(x,{isCurrent:!1,status:S===x.id?{kind:"connecting"}:{kind:"unknown"},probing:S===x.id}))),[i,S]),F=t.useCallback(x=>{const k=i.find(K=>K.id===x)??null;k&&($(x),r.connect({id:k.id,candidates:k.candidates,clientToken:k.clientToken,label:k.label}).finally(()=>$(null)))},[r,i]),U=t.useCallback(()=>{B(""),r.cancelPassword()},[r]),te=t.useCallback(()=>y?(C.current?.abort(),P(!1),!0):v?(U(),!0):f&&h?(A(!1),!0):!1,[U,y,f,v,h]);return Pt(te),e.jsxs(e.Fragment,{children:[y?e.jsx(_s,{onCancel:()=>C.current?.abort()}):null,E?e.jsx(Ms,{}):null,e.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:e.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[e.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[e.jsx(we,{width:72,height:72,className:"size-[72px]"}),e.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),n?e.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:[e.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:e.jsx(ce,{name:n.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),e.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,v?e.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:L,children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:e.jsx(ce,{name:"lock",className:"size-[18px]"})}),e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsx("p",{className:"truncate typography-ui-label text-foreground",children:v.label}),e.jsx("p",{className:"truncate typography-small text-muted-foreground",children:v.candidates.some(x=>x.kind==="direct")?Ls(v):"via PiChamber Relay"})]})]}),e.jsx("input",{...Fe,value:G,onChange:x=>B(x.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Oe}),o?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,e.jsx(Se,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!G.trim(),children:a?"Connecting...":"Unlock and connect"}),e.jsx(Se,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:U,children:"Use another server"})]}):e.jsxs("div",{className:"flex w-full flex-col gap-6",children:[h?e.jsxs("div",{className:"flex w-full flex-col gap-2",children:[e.jsxs(Se,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{g()},disabled:y||l,children:[e.jsx(ce,{name:"scan-2",className:W("size-[18px]",y&&"animate-pulse")}),l?"Connecting...":"Scan QR code"]}),e.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,o&&!f?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,i.length>0?e.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[e.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved servers"}),e.jsx(Wn,{items:j,layout:"touch",switchLabel:"Connect",pendingId:S,actionsDisabled:l,onSwitch:x=>F(x.id),emptyMessage:"No saved servers yet."})]}):null,e.jsxs("div",{className:"flex w-full flex-col",children:[h?e.jsxs("button",{type:"button",onClick:()=>A(x=>!x),"aria-expanded":f,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:[e.jsx("span",{children:"Connect by address"}),e.jsx(ce,{name:"arrow-down-s",className:W("size-4 transition-transform duration-200",f&&"rotate-180")})]}):null,e.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:f?"1fr":"0fr"},children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:_,children:[e.jsx("input",{...Fe,value:p,onChange:x=>M(x.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:f?void 0:-1,className:W(Oe,"text-center")}),e.jsx("input",{value:b,onChange:x=>R(x.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:f?void 0:-1,className:W(Oe,"text-center")}),e.jsx("input",{...Fe,value:w,onChange:x=>T(x.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:f?void 0:-1,autoCapitalize:"none",className:W(Oe,"text-center")}),e.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."}),o?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,e.jsx(Se,{type:"submit",variant:h?"outline":"default",size:"lg",className:"h-12 w-full",disabled:l||y||!p.trim(),children:l?"Connecting...":"Connect"})]})})})]})]})]})})]})},sr=10,rr=(s,n)=>At(s,n),ir=({session:s,meta:n,active:r,onSelect:i})=>{const l=Un(s.id),a=Bn(s.id),o=Hn(s.id),v=l?.type??"idle",p=v==="busy"||v==="retry",d=$n({pendingInput:o,isStreaming:p,unseenCount:a,isActive:r}),b=d==="needs-input",R=b&&o?Fn(o.kind,o.count):null,w=d==="unread",T=Vn(s.id,p),y=p&&T,P=Bs(s.time?.updated??s.time?.created??0);return e.jsxs("button",{type:"button",className:W("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",r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:i,style:{touchAction:"manipulation"},children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:W("block truncate typography-ui-label",r?"text-primary":"text-foreground"),children:rr(s,"Untitled session")}),n?e.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:n}):null]}),b?e.jsx(Gn,{label:R??"Needs input"}):p?e.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):w?e.jsx(Hs,{label:"Session complete"}):null,y?e.jsx($s,{sessionId:s.id,running:p,className:"typography-micro"}):w||b?null:P?e.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:P}):null]})},ar=({open:s,onClose:n,anchorRef:r})=>{const{panelRef:i,wrapperRef:l,shouldRender:a,isExiting:o,anchorLeft:v,isPopover:p}=rn({open:s,onClose:n,anchorRef:r}),d=ue(y=>y.currentSessionId),b=ue(y=>y.setCurrentSession),R=Tt(y=>y.setActiveProjectIdOnly),w=Fs(s||a,{maxParents:sr}),T=t.useCallback(y=>{b(y.id,It(y)),n()},[n,b]);return a?e.jsxs("div",{ref:l,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:[e.jsx("div",{ref:i,role:"dialog","aria-label":"Open session switcher",className:W("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",p?"absolute origin-top-left":"mx-3 mt-2",o?"pointer-events-none":"pointer-events-auto"),style:{animation:`${o?"session-switcher-out":"session-switcher-in"} ${o?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))",...p?{top:8,left:v??8,width:`min(${an}px, calc(100% - 16px))`}:null},children:e.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:w.length===0?e.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):w.map(y=>{const P=y.node.session,E=[y.secondaryMeta?.projectLabel,y.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return e.jsx(ir,{session:P,meta:E,active:P.id===d,onSelect:()=>{y.projectId&&R(y.projectId),T(P)}},P.id)})})}),e.jsx("style",{children:`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-CjjPpE4c.js","assets/vendor-boot-3SaHYVb1.js","assets/vendor-react-Bz1tRBxM.js","assets/vendor-clsx-B-dksMZM.js","assets/index-Cs2nBW_t.js","assets/vendor-zustand-CXhN0IMY.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-tailwind-merge-BKkUfl9q.js","assets/vendor-fuse.js-t_7AcMTv.js","assets/index-tmO0fZa4.css","assets/useAppFontEffects-Oyin3dgQ.js","assets/runtimeSurface-DiP2a57a.js","assets/nativeFileSave-DpBH1Sa3.js","assets/vendor-codemirror-lang-javascript-Bx_FIyZF.js","assets/vendor-lezer-javascript-BH2Etgoy.js","assets/vendor-lezer-lr-HY6Yc0Vr.js","assets/vendor-codemirror-autocomplete-WThuuUAz.js","assets/vendor-codemirror-lang-json-DIvqf9Pb.js","assets/vendor-lezer-json-CE-QUCwM.js","assets/vendor-codemirror-lang-css-D1wpUg3Z.js","assets/vendor-lezer-css-Cb8vp67u.js","assets/vendor-codemirror-lang-html-DbL8oT9H.js","assets/vendor-lezer-html-UQMsUwj-.js","assets/vendor-codemirror-lang-markdown-v3yG2sbf.js","assets/vendor-lezer-markdown-xFL3Evwf.js","assets/vendor-codemirror-language-data-B03xgzP2.js","assets/vendor-codemirror-lang-python-b-JqEwQy.js","assets/vendor-lezer-python-BNRFWCb0.js","assets/shell-CjFT_Tl9.js","assets/appThemeRegistry-Ca8eGRB9.js","assets/registerCustomTheme-C-h6lsYW.js","assets/themeResolver-DrfmQi8i.js","assets/vendor-pierre-theming-BO6EPniU.js","assets/vendor-shikijs-core-Ck_OPM_T.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-DPFxvYtK.js","assets/vendor-hast-util-to-html-O3stl53j.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-C40bX6nM.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/FileSaveConflictDialog-B1DvL9zy.js","assets/vendor-react-drawio-IYnLUY5N.js","assets/runtimeEndpointReset-aGyXPXPs.js","assets/SessionUnreadDot-CY9-1iV2.js","assets/permissionStore-zIpxq9Pq.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/vendor-xterm-xterm-css-DDGTF8rc.css","assets/fileTreeStatus-BzhMMLA9.js","assets/JsonTreeView-BjFFSUwi.js","assets/web-components-CkTNGkJ2.js","assets/computeVirtualFileMetrics-8MuwxSC6.js","assets/vendor-shiki-BEwTOAFg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-DL394yyj.js","assets/vendor-oniguruma-to-es-DgwFOwdE.js","assets/vendor-oniguruma-parser-BrbMHgHx.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/Virtualizer-okhy9Aq3.js","assets/renderFileWithHighlighter-DtAcGyJr.js","assets/vendor-codemirror-search-Dw3Wpu15.js","assets/vendor-replit-codemirror-vim-D1Fe7FiY.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/StickyHorizontalScrollbar-DNsbTLS7.js","assets/GitView-5fIq2nzM.js","assets/gitStatusPredicates-Cyh9UhYX.js","assets/GitHubDetailScaffold-DqxAKqCT.js","assets/vendor-dompurify-BGCr_sdL.js","assets/collapsible-Dz0bPrJ_.js","assets/vendor-base-ui-BCqPBzDj.js","assets/PierreDiffViewer-H2f4pJ1k.js","assets/VirtualizedFileDiff-BYby097w.js","assets/renderDiffWithHighlighter-B6T04JGG.js","assets/vendor-diff-C3JhlQdm.js","assets/PullRequestsSurface-DPpb2RW_.js","assets/useGitHubRemoteSearch-CZ9Hauw0.js","assets/GitHubListPrimitives-C2nGTntk.js","assets/IssuesSurface-Dq5A_bWq.js","assets/githubLink-D2PznPcI.js","assets/vendor-capacitor-app-NbQ-WiPS.js"])))=>i.map(i=>d[i]);
2
+ import{j as e,aP as We,aQ as He,aR as Gt}from"./vendor-boot-3SaHYVb1.js";import{a as qe,R as t}from"./vendor-react-Bz1tRBxM.js";/* empty css */import{b as Ae,d as Xt,e as st,n as Qe,u as Je,f as W,i as Kt,h as Ee,j as Yt,r as he,k as de,s as Pe,l as qt,m as Qt,o as rt,p as Jt,q as Tt,t as Zt,v as en}from"./index-Cs2nBW_t.js";import{f as tn,a as nn,s as sn}from"./pi-session-focus-preference-BrB72skF.js";import{u as rn,M as an,a as on,i as ln,D as it,b as at,c as ot,g as cn,d as lt,e as un,s as dn,S as fn,f as hn,T as pn,h as ct,j as ut,k as mn,r as bn,l as xn,m as gn,n as yn,H as vn,A as wn,C as Sn,o as jn,p as Rn,q as kn,O as En,F as Cn,t as Nn,v as Tn,W as In,w as Pn}from"./runtimeEndpointReset-aGyXPXPs.js";import{g as _e,l as An,u as Dn,a as It,b as _n,c as Mn,r as Pt,d as Ln,e as Ce,t as $e,o as On,I as ce,s as zn,f as At,P as we,B as Se,S as Wn,h as ue,i as Un,j as Bn,k as Hn,m as $n,n as Fn,p as Vn,q as Gn,v as Dt,w as Xn,E as re,C as Le,x as _t,y as Kn,z as Yn,A as dt,D as qn,F as Qn,G as Jn,H as Zn,J as es,K as ts,L as ns,M as ss,N as rs,O as pe,Q as is,R as me,T as as,U as os,V as ls,W as cs,X as us,Y as ds,Z as fs,_ as hs,$ as ps,a0 as ms,a1 as bs,a2 as xs,a3 as gs,a4 as ys,a5 as vs,a6 as ws,a7 as Ss,a8 as js,a9 as Rs,aa as ks,ab as Es,ac as Cs,ad as Ns,ae as Ts}from"./useAppFontEffects-Oyin3dgQ.js";import{u as Is,i as ft,p as Ps,s as As,m as Ds,M as _s,a as Ms,c as Ls,b as Oe,d as Fe,e as Os,g as ve,S as zs,A as Ws,f as Ve,r as Us}from"./SettingsView-CiIuOi_E.js";import{f as Bs,S as Hs,a as $s}from"./SessionUnreadDot-CY9-1iV2.js";import{u as Fs}from"./useSwitcherItems-BSqDA1IF.js";import{_ as Me}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";/* empty css */import"./nativeFileSave-DpBH1Sa3.js";import"./permissionStore-zIpxq9Pq.js";import"./runtimeSurface-DiP2a57a.js";import"./vendor-qrcode-gzL9QFkg.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./collapsible-Dz0bPrJ_.js";import"./vendor-base-ui-BCqPBzDj.js";let Mt=null,ht=!1;const Vs=new Promise(s=>{Mt=s});function Gs(){ht||(ht=!0,Mt?.())}const Xs=6,Ks=s=>s.parentID??null,pt=s=>{const n=s.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},Ys=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),qs=(s,n)=>{if(!s)return"";let r=null,i=-1;for(const l of n){const a=Ys(l.path);(s===a||s.startsWith(`${a}/`))&&a.length>i&&(r=l,i=a.length)}return r?r.label?.trim()||pt(r.path):pt(s)},Qs=()=>{const s=_e().getState().catalog,n=[];for(const d of s.byId.values())d.archived||n.push(An(d));const r=Dn.getState().index.session.unseenCount,i=It.getState().projects,l=_n.getState().ids,a=Mn.getState().rankById;let o=0;const j=[];for(const d of n){const b=Ks(d)!==null,v=(r[d.id]??0)>0;v&&(o+=1),b||j.push({session:d,unread:v,project:qs(Pt(d),i)})}j.sort(Ln(l,a,d=>d.session));const p=j.slice(0,Xs).map(({session:d,unread:b,project:R})=>({id:d.id,title:d.title??"",unread:b,project:R}));return{runtimeKey:Ae(),attentionCount:o,recentSessions:p}},Js="__PICHAMBER_WIDGET_SNAPSHOT__",Zs=()=>{typeof window>"u"||(window[Js]=()=>{try{return JSON.stringify(Qs())}catch{return null}})},Ge="mobile-app-update-available",mt="mobile-app-update-toast-dismissed-version",er=()=>{const s=Ce(a=>a.available),n=Ce(a=>a.runtimeType),r=Ce(a=>a.info?.version),i=Ce(a=>a.info?.downloadUrl),l=qe.useRef(new Set);return qe.useEffect(()=>{if(Xt()!=="android"||n!=="mobile"||!s||!r||!i){$e.dismiss(Ge);return}st().getItem(mt)!==r&&(l.current.has(r)||(l.current.add(r),$e.info("PiChamber update available",{id:Ge,description:`Version ${r} is ready for Android.`,duration:1/0,icon:e.jsx(ce,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{On(i)}},cancel:{label:"Dismiss",onClick:()=>{st().setItem(mt,r),$e.dismiss(Ge)}}})))},[s,i,n,r]),null},tr=s=>{const{persisted:n,persistedDirectory:r,stale:i,ready:l,catalog:a,runtimeKey:o,capturedRuntimeKey:j,storeIdentityMatches:p,generationMatches:d}=s;if(!n||!r)return{action:"wait"};if(i||o!==j||!p||!d)return{action:"wait"};if(!l||!a)return{action:"wait"};const b=a.byId.get(n.sessionId);return!b||b.archived?{action:"clear"}:{action:"select",sessionId:b.id,directory:b.directory??r}};function nr(s,n){t.useEffect(()=>{n&&Qe(Je.getState().currentDirectory)===Qe(s)&&_e().focusProject(s,tn(s))},[s,n])}const sr=({onConnected:s,notice:n=null})=>{const r=Is(s),{connections:i,isBusy:l,isPasswordBusy:a,error:o,pendingConnection:j}=r,[p,d]=t.useState(""),[b,R]=t.useState(""),[v,T]=t.useState(""),[y,P]=t.useState(!1),[E,N]=t.useState(!1),C=t.useRef(null),h=t.useMemo(()=>ft(),[]),[f,A]=t.useState(()=>!ft()),[w,$]=t.useState(null),[G,B]=t.useState(""),_=t.useCallback(x=>{x.preventDefault(),r.connect({url:p,clientToken:v,label:b})},[v,r,b,p]),M=t.useCallback(x=>{if(/^pichamber:\/\//i.test(x.trim())){const k=Ps(x);if(k){if("pairing"in k){r.redeemPairingConnection(k.pairing);return}d(k.url),k.label&&R(k.label),k.clientToken&&T(k.clientToken);return}}d(x)},[r]),g=t.useCallback(async()=>{if(C.current||l)return;r.setError(null),P(!0);const x=new AbortController;C.current=x;try{const k=await As({signal:x.signal});switch(C.current===x&&(C.current=null,P(!1)),k.status){case"ok":N(!0),d(k.url),k.label&&R(k.label),k.clientToken&&T(k.clientToken),await r.connect({url:k.url,clientToken:k.clientToken,label:k.label});break;case"pairing":N(!0),await r.redeemPairingConnection(k.pairing);break;case"permission-denied":r.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":r.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":r.setError("QR scanning is only available in the installed mobile app.");break;case"failed":r.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{N(!1),C.current===x&&(C.current=null,P(!1))}},[r,l]);t.useEffect(()=>()=>C.current?.abort(),[]);const L=t.useCallback(x=>{x.preventDefault(),r.submitPassword(G)},[r,G]),S=t.useMemo(()=>zn(i.map(x=>Ds(x,{isCurrent:!1,status:w===x.id?{kind:"connecting"}:{kind:"unknown"},probing:w===x.id}))),[i,w]),F=t.useCallback(x=>{const k=i.find(K=>K.id===x)??null;k&&($(x),r.connect({id:k.id,candidates:k.candidates,clientToken:k.clientToken,label:k.label}).finally(()=>$(null)))},[r,i]),U=t.useCallback(()=>{B(""),r.cancelPassword()},[r]),te=t.useCallback(()=>y?(C.current?.abort(),P(!1),!0):j?(U(),!0):f&&h?(A(!1),!0):!1,[U,y,f,j,h]);return At(te),e.jsxs(e.Fragment,{children:[y?e.jsx(_s,{onCancel:()=>C.current?.abort()}):null,E?e.jsx(Ms,{}):null,e.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:e.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[e.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[e.jsx(we,{width:72,height:72,className:"size-[72px]"}),e.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),n?e.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:[e.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:e.jsx(ce,{name:n.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),e.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,j?e.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:L,children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:e.jsx(ce,{name:"lock",className:"size-[18px]"})}),e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsx("p",{className:"truncate typography-ui-label text-foreground",children:j.label}),e.jsx("p",{className:"truncate typography-small text-muted-foreground",children:j.candidates.some(x=>x.kind==="direct")?Ls(j):"via PiChamber Relay"})]})]}),e.jsx("input",{...Fe,value:G,onChange:x=>B(x.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Oe}),o?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,e.jsx(Se,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!G.trim(),children:a?"Connecting...":"Unlock and connect"}),e.jsx(Se,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:U,children:"Use another server"})]}):e.jsxs("div",{className:"flex w-full flex-col gap-6",children:[h?e.jsxs("div",{className:"flex w-full flex-col gap-2",children:[e.jsxs(Se,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{g()},disabled:y||l,children:[e.jsx(ce,{name:"scan-2",className:W("size-[18px]",y&&"animate-pulse")}),l?"Connecting...":"Scan QR code"]}),e.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,o&&!f?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,i.length>0?e.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[e.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved servers"}),e.jsx(Wn,{items:S,layout:"touch",switchLabel:"Connect",pendingId:w,actionsDisabled:l,onSwitch:x=>F(x.id),emptyMessage:"No saved servers yet."})]}):null,e.jsxs("div",{className:"flex w-full flex-col",children:[h?e.jsxs("button",{type:"button",onClick:()=>A(x=>!x),"aria-expanded":f,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:[e.jsx("span",{children:"Connect by address"}),e.jsx(ce,{name:"arrow-down-s",className:W("size-4 transition-transform duration-200",f&&"rotate-180")})]}):null,e.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:f?"1fr":"0fr"},children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:_,children:[e.jsx("input",{...Fe,value:p,onChange:x=>M(x.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:f?void 0:-1,className:W(Oe,"text-center")}),e.jsx("input",{value:b,onChange:x=>R(x.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:f?void 0:-1,className:W(Oe,"text-center")}),e.jsx("input",{...Fe,value:v,onChange:x=>T(x.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:f?void 0:-1,autoCapitalize:"none",className:W(Oe,"text-center")}),e.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."}),o?e.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:o}):null,e.jsx(Se,{type:"submit",variant:h?"outline":"default",size:"lg",className:"h-12 w-full",disabled:l||y||!p.trim(),children:l?"Connecting...":"Connect"})]})})})]})]})]})})]})},rr=10,ir=(s,n)=>Dt(s,n),ar=({session:s,meta:n,active:r,onSelect:i})=>{const l=Un(s.id),a=Bn(s.id),o=Hn(s.id),j=l?.type??"idle",p=j==="busy"||j==="retry",d=$n({pendingInput:o,isStreaming:p,unseenCount:a,isActive:r}),b=d==="needs-input",R=b&&o?Fn(o.kind,o.count):null,v=d==="unread",T=Vn(s.id,p),y=p&&T,P=Bs(s.time?.updated??s.time?.created??0);return e.jsxs("button",{type:"button",className:W("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",r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:i,style:{touchAction:"manipulation"},children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:W("block truncate typography-ui-label",r?"text-primary":"text-foreground"),children:ir(s,"Untitled session")}),n?e.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:n}):null]}),b?e.jsx(Gn,{label:R??"Needs input"}):p?e.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):v?e.jsx(Hs,{label:"Session complete"}):null,y?e.jsx($s,{sessionId:s.id,running:p,className:"typography-micro"}):v||b?null:P?e.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:P}):null]})},or=({open:s,onClose:n,anchorRef:r})=>{const{panelRef:i,wrapperRef:l,shouldRender:a,isExiting:o,anchorLeft:j,isPopover:p}=rn({open:s,onClose:n,anchorRef:r}),d=ue(y=>y.currentSessionId),b=ue(y=>y.setCurrentSession),R=It(y=>y.setActiveProjectIdOnly),v=Fs(s||a,{maxParents:rr}),T=t.useCallback(y=>{b(y.id,Pt(y)),n()},[n,b]);return a?e.jsxs("div",{ref:l,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:[e.jsx("div",{ref:i,role:"dialog","aria-label":"Open session switcher",className:W("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",p?"absolute origin-top-left":"mx-3 mt-2",o?"pointer-events-none":"pointer-events-auto"),style:{animation:`${o?"session-switcher-out":"session-switcher-in"} ${o?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))",...p?{top:8,left:j??8,width:`min(${an}px, calc(100% - 16px))`}:null},children:e.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:v.length===0?e.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):v.map(y=>{const P=y.node.session,E=[y.secondaryMeta?.projectLabel,y.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return e.jsx(ar,{session:P,meta:E,active:P.id===d,onSelect:()=>{y.projectId&&R(y.projectId),T(P)}},P.id)})})}),e.jsx("style",{children:`
3
3
  @keyframes session-switcher-in {
4
4
  from { opacity: 0; transform: translateY(-8px) scale(0.985); }
5
5
  to { opacity: 1; transform: translateY(0) scale(1); }
@@ -8,4 +8,4 @@ import{j as e,aP as We,aQ as He,aR as Vt}from"./vendor-boot-Ciu-Edvy.js";import{
8
8
  from { opacity: 1; transform: translateY(0) scale(1); }
9
9
  to { opacity: 0; transform: translateY(-6px) scale(0.985); }
10
10
  }
11
- `})]}):null},or=({onOpenSessions:s,onOpenWorkspace:n,compactTitle:r=!1})=>{const[i,l]=t.useState(!1),[a,o]=t.useState(!1),v=t.useRef(null),p=Ct(h=>h.currentDirectory),d=ue(h=>h.currentSessionId),R=ue(t.useCallback(h=>d?h.getDirectoryForSession(d):null,[d]))||p,w=Xn(d),T=ue(h=>!!h.newSessionDraft?.open),P=w?.title?.trim()||(d?At(w,"Untitled session"):"New session");t.useEffect(()=>{l(!1),o(!1)},[d,R]);const E=t.useCallback(()=>{l(!1),o(!1),s()},[s]),N=t.useCallback(h=>{l(f=>{const A=typeof h=="function"?h(f):h;return A&&o(!1),A})},[]),C=t.useCallback(()=>{o(h=>{const f=!h;return f&&l(!1),f})},[]);return e.jsxs(e.Fragment,{children:[e.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:e.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[e.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:E,style:{touchAction:"manipulation"},children:e.jsx(ce,{name:"list-unordered",className:"size-5"})}),e.jsx("button",{ref:v,type:"button",className:W("flex h-10 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",r?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":a,onClick:C,style:{touchAction:"manipulation"},children:e.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:P}),e.jsx(ce,{name:"arrow-down-s",className:W("size-4 shrink-0 text-muted-foreground transition-transform duration-150",a&&"rotate-180")})]})}),r?e.jsx("div",{className:"min-w-0 flex-1"}):null,e.jsx(on,{open:i,onOpenChange:N,currentSessionId:d,effectiveDirectory:R,isNewSessionDraftOpen:T}),e.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:()=>{l(!1),o(!1),n()},style:{touchAction:"manipulation"},children:e.jsx(ce,{name:"layout-right",className:"size-5"})})]})}),e.jsx(ar,{open:a,onClose:()=>o(!1),anchorRef:v})]})},lr=({onActiveConnectionDeleted:s,onConnect:n})=>e.jsx(Os,{onConnect:n,onActiveConnectionDeleted:s,showDiagnostics:!0}),Ne=320,be="cubic-bezier(0.22, 1, 0.36, 1)",Mt=({side:s,enabled:n,open:r,drawerRef:i,scrimRef:l,onClose:a,widthRatio:o,prefersReducedMotion:v})=>{t.useEffect(()=>{if(!n||!r)return;const p=i.current,d=l.current;if(!p||!d)return;let b=!1,R=!1,w=!1,T=0,y=0,P=0,E=0;const N=v?0:Ne,C=s==="left"?"translateX(-100%)":"translateX(100%)",h=()=>({drawer:N?`transform ${N}ms ${be}`:"none",scrim:N?`opacity ${N}ms ${be}`:"none"}),f=()=>{const g=h();p.style.transition=g.drawer,d.style.transition=g.scrim,p.style.transform="none",d.style.opacity="1",d.style.pointerEvents="auto"},A=()=>{b=!1,R=!1,w=!1},S=()=>{if(!(b||R)){A();return}f(),A()},$=g=>{if(g.touches.length!==1){(b||R)&&S();return}if(ln(g.target,p,{excludeInteractive:!1}))return;p.style.transition&&p.style.transition!=="none"&&(p.style.transition="none",d.style.transition="none");const L=g.touches[0];T=L.clientX,y=L.clientY,P=Date.now(),E=p.offsetWidth||window.innerWidth*o,E<10&&(E=window.innerWidth*o),b=!0,R=!1,w=!1},G=g=>{if(!b)return;if(g.touches.length!==1){S();return}const L=g.touches[0],j=L.clientX-T,F=L.clientY-y;if(!w){if(Math.abs(j)<st&&Math.abs(F)<st)return;if(Math.abs(F)>Math.abs(j)*rt||!it(s,j)){b=!1;return}w=!0,R=!0,p.style.transition="none",d.style.transition="none"}if(!R)return;g.cancelable&&g.preventDefault();const U=at(s,j,E);p.style.transform=cn(s,U),d.style.opacity=String(U)},B=(g,L,j)=>{if(!b)return;const F=g-T,U=L-y,te=Math.max(1,Date.now()-P),x=at(s,F,E),k=dn({side:s,dx:F,dy:U,dt:te,progress:x,isDragging:R}),K=h();p.style.transition=K.drawer,d.style.transition=K.scrim,p.style.transform=k?C:"none",d.style.opacity=k?"0":"1",d.style.pointerEvents=k?"none":"auto",A(),k&&a()},_=g=>{const L=g.changedTouches[0];if(!L){S();return}const j=L.clientX-T,F=L.clientY-y,U=Math.abs(j)>=un&&Math.abs(F)<=Math.abs(j)*rt&&it(s,j);b&&(R||U)&&g.cancelable&&g.preventDefault(),B(L.clientX,L.clientY)},M=()=>{S()};return p.addEventListener("touchstart",$,{passive:!0}),p.addEventListener("touchmove",G,{passive:!1}),p.addEventListener("touchend",_,{passive:!1}),p.addEventListener("touchcancel",M,{passive:!0}),()=>{try{S()}catch{}p.removeEventListener("touchstart",$),p.removeEventListener("touchmove",G),p.removeEventListener("touchend",_),p.removeEventListener("touchcancel",M)}},[i,n,a,r,v,l,s,o])},cr=16,pt=t.memo(function({open:n,onOpenChange:r,variant:i="drawer",drawerRefExternal:l,scrimRefExternal:a,rootRefExternal:o}){const v=t.useRef(null),p=t.useCallback(()=>{const f=typeof document<"u"?document.activeElement:null;f instanceof HTMLElement&&v.current?.contains(f)&&f.blur(),r(!1)},[r]),[d,b]=t.useState(!1),R=t.useRef(null),w=t.useRef(null),T=l??R,y=a??w,P=t.useCallback(f=>{v.current=f,o&&(o.current=f)},[o]),E=t.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);t.useEffect(()=>{const f=v.current;if(!f||n)return;const A=document.activeElement;A&&f.contains(A)&&A.blur()},[n]),t.useEffect(()=>{if(i!=="sidebar"){if(n){const f=window.setTimeout(()=>b(!0),E?0:cr);return()=>window.clearTimeout(f)}b(!1)}},[n,E,i]),t.useEffect(()=>{if(i==="sidebar"||!n)return;const f=document.body.style.overflow;document.body.style.overflow="hidden";const A=S=>{S.key==="Escape"&&p()};return document.addEventListener("keydown",A),()=>{document.body.style.overflow=f,document.removeEventListener("keydown",A)}},[p,n,i]);const N=i==="sidebar",C=e.jsx(fn,{mobileVariant:!N,isVisible:n,allowReselect:!0,onSessionSelected:N?void 0:p,onNavigateAway:N?void 0:p});if(Mt({side:"left",enabled:i==="drawer",open:n,drawerRef:T,scrimRef:y,onClose:p,widthRatio:.72,prefersReducedMotion:E}),i==="sidebar")return e.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:C});if(typeof document>"u")return null;const h=E?0:Ne;return We.createPortal(e.jsxs("div",{ref:P,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none"},"data-mobile-sessions-root":"true",children:[e.jsx("button",{ref:y,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:p,tabIndex:n?0:-1,style:{opacity:d?1:0,transition:`opacity ${h}ms ${be}`},"data-mobile-sessions-scrim":"true"}),e.jsx("div",{ref:T,className:W("relative z-10 flex h-full w-[72%] max-w-[360px] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:d?"none":"translateX(-100%)",transition:h?`transform ${h}ms ${be}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:C})]}),document.body)}),mt="mobile-surface-root",Xe=16,ze=200,ur=()=>{if(typeof document>"u")return null;let s=document.getElementById(mt);return s||(s=document.createElement("div"),s.id=mt,document.body.appendChild(s)),s},Ke=({open:s,onClose:n,title:r,subtitle:i,trailing:l,disableEscapeDismiss:a=!1,headerless:o=!1,noHeaderBorder:v=!1,ariaLabel:p,variant:d="fullscreen",dialogAlign:b="chat",children:R})=>{const w=t.useRef(null),[T,y]=t.useState(!1),[P,E]=t.useState(!1),N=t.useRef(null),C=t.useRef(null),h=t.useRef(n);if(t.useEffect(()=>{h.current=n},[n]),typeof document<"u"&&!w.current&&(w.current=ur()),t.useEffect(()=>{if(!s){y(!1);return}const S=window.setTimeout(()=>y(!0),Xe);return()=>window.clearTimeout(S)},[s]),t.useEffect(()=>{if(!s){E(!1);return}const S=window.setTimeout(()=>E(!0),Xe+ze+80);return()=>window.clearTimeout(S)},[s]),t.useEffect(()=>{if(!s)return;const S=document.body.style.overflow;C.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const $=()=>{const _=N.current;if(!_)return;(_.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??_).focus({preventScroll:!0})},G=window.setTimeout($,Xe),B=_=>{if(_.key==="Escape"&&!a){h.current();return}if(_.key!=="Tab")return;const M=N.current;if(!M)return;const g=Array.from(M.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(U=>!U.hasAttribute("disabled")&&U.getAttribute("aria-hidden")!=="true");if(g.length===0){_.preventDefault(),M.focus({preventScroll:!0});return}const L=g[0],j=g[g.length-1],F=document.activeElement;_.shiftKey&&F===L?(_.preventDefault(),j.focus({preventScroll:!0})):!_.shiftKey&&F===j&&(_.preventDefault(),L.focus({preventScroll:!0}))};return document.addEventListener("keydown",B),()=>{window.clearTimeout(G),document.body.style.overflow=S,document.removeEventListener("keydown",B),C.current?.focus?.({preventScroll:!0}),C.current=null}},[a,s]),!s||!w.current)return null;const f=d==="dialog",A=e.jsxs("section",{ref:N,role:"dialog","aria-modal":"true","aria-label":p,tabIndex:-1,className:W("flex flex-col bg-background text-foreground",f?"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:f?{opacity:T?1:0,transform:T?"none":"scale(0.97)",transition:`opacity ${ze}ms ease-out, transform ${ze}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:T?"none":"translateX(100%)",transition:`transform ${ze}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:S=>{T&&S.target===S.currentTarget&&S.propertyName==="transform"&&E(!0)},children:[o?null:e.jsxs("header",{className:W("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!v&&"border-b border-border/70"),children:[e.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:e.jsx(ce,{name:"close",className:"size-5"})}),e.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[r?typeof r=="string"?e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:r}):r:null,i?typeof i=="string"?e.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:i}):i:null]}),l?e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:l}):null]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:P?e.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:R}):null}),e.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return f?We.createPortal(e.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:T?1:0,paddingLeft:b==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:b==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:n,children:e.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:S=>S.stopPropagation(),children:A})}),w.current):We.createPortal(A,w.current)},dr=t.lazy(()=>Me(()=>import("./FilesView-D0Z0VmQm.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])).then(s=>({default:s.FilesView}))),fr=t.lazy(()=>Me(()=>import("./GitView-BNkoaVYl.js"),__vite__mapDeps([73,6,1,2,3,10,4,5,7,8,9,11,12,49,50,51,52,53,74,75,76,77,78,79,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,80,81,82,72,29,30])).then(s=>({default:s.GitView}))),hr=t.lazy(()=>Me(()=>import("./PullRequestsSurface-PML07zr-.js"),__vite__mapDeps([83,6,1,2,3,84,4,5,7,8,9,10,11,12,49,50,51,52,53,85,75,76,79,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,80,81,82,72,29,30])).then(s=>({default:s.PullRequestsSurface}))),pr=t.lazy(()=>Me(()=>import("./IssuesSurface-D4kD7_VW.js"),__vite__mapDeps([86,1,2,3,84,4,5,6,7,8,9,10,11,12,49,50,51,52,53,85,75,76,87])).then(s=>({default:s.IssuesSurface}))),bt="mobile-surface-root",mr=16,xt=t.memo(function({open:n,onClose:r,tab:i,onTabChange:l,pendingChangesDiff:a,variant:o="drawer",drawerRefExternal:v,scrimRefExternal:p,rootRefExternal:d,githubTabsAvailable:b=!1}){const R=t.useRef(null),w=t.useRef(null),T=t.useRef(null),y=t.useRef(null),P=v??w,E=p??T,N=d??y,C=t.useCallback(m=>{y.current=m,d&&(d.current=m)},[d]),h=t.useCallback(()=>{const m=typeof document<"u"?document.activeElement:null;m instanceof HTMLElement&&N.current?.contains(m)&&m.blur(),r()},[r]),[f,A]=t.useState(!1),[S,$]=t.useState(n),G=`mobile-workspace-tab-${t.useId()}`,B=t.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[_,M]=t.useState(()=>new Set),[g,L]=t.useState(null),[j,F]=t.useState(null);if(t.useEffect(()=>{n&&M(m=>{if(m.has(i))return m;const H=new Set(m);return H.add(i),H})},[n,i]),typeof document<"u"&&!R.current){let m=document.getElementById(bt);m||(m=document.createElement("div"),m.id=bt,document.body.appendChild(m)),R.current=m}if(t.useEffect(()=>{if(n){$(!0);const H=window.setTimeout(()=>A(!0),B?0:mr);return()=>window.clearTimeout(H)}A(!1);const m=window.setTimeout(()=>$(!1),Ne+40);return()=>window.clearTimeout(m)},[n,B]),t.useEffect(()=>{if(!n)return;const m=document.body.style.overflow;o==="drawer"&&(document.body.style.overflow="hidden");const H=ne=>{ne.key==="Escape"&&i!=="terminal"&&h()};return document.addEventListener("keydown",H),()=>{o==="drawer"&&(document.body.style.overflow=m),document.removeEventListener("keydown",H)}},[h,n,i,o]),t.useEffect(()=>{const m=N.current;if(!m||n||o!=="drawer")return;const H=document.activeElement;H&&m.contains(H)&&H.blur()},[n,o]),Mt({side:"right",enabled:o==="drawer",open:n,drawerRef:P,scrimRef:E,onClose:h,widthRatio:1,prefersReducedMotion:B}),o==="drawer"&&!R.current)return null;const U=B?0:Ne,te=hn(b),x=B?{duration:0}:{type:"spring",stiffness:520,damping:40,mass:.8},k=e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 py-1 overflow-x-auto overflow-y-hidden scrollbar-none",role:"tablist","aria-label":"Workspace","data-no-drawer-swipe":"true",children:te.map(m=>{const H=i===m.id;return e.jsxs(He.button,{layout:"position",transition:x,type:"button",role:"tab","aria-selected":H,"aria-label":m.label,onClick:()=>l(m.id),className:W("relative flex min-h-[44px] items-center justify-center gap-1 rounded-lg py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",H?"min-w-0 shrink px-2.5 text-foreground":"size-11 shrink-0 text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[H?e.jsx(He.span,{layoutId:G,transition:x,className:"absolute inset-0 bg-interactive-selection",style:{borderRadius:8},"aria-hidden":"true"}):null,e.jsx(ce,{name:m.icon,className:"relative size-5 shrink-0"}),H?e.jsx(He.span,{initial:B?!1:{opacity:0,x:-4},animate:{opacity:1,x:0},transition:x,className:"relative truncate",children:m.label},m.id):null]},m.id)})}),K=e.jsxs(e.Fragment,{children:[o==="panel"?null:e.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2",children:[k,e.jsx("button",{type:"button",onClick:h,"aria-label":"Close workspace panel",className:"flex size-11 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/50",children:e.jsx(ce,{name:"close",className:"size-5"})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[_.has("changes")?e.jsx("div",{className:W("h-full",i!=="changes"&&"hidden"),children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(fr,{isActive:n&&i==="changes",chrome:"mobile",initialDiffPath:a?.path??null,initialDiffStaged:a?.staged===!0})})})},a?`changes:${a.path}:${a.staged}`:"changes"):null,_.has("files")?e.jsx("div",{className:W("h-full",i!=="files"&&"hidden"),children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(dr,{chrome:"mobile",mode:"editor-only",isVisible:n&&i==="files"})})})}):null,_.has("terminal")?e.jsx("div",{className:W("h-full",i!=="terminal"&&"hidden"),children:e.jsx(re,{children:e.jsx(pn,{visible:n&&i==="terminal"})})}):null,_.has("pull-requests")?e.jsx("div",{className:W("h-full",i!=="pull-requests"&&"hidden"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[e.jsx(ot,{icon:Le.find(m=>m.id==="pull-requests")?.icon,title:Le.find(m=>m.id==="pull-requests")?.label??"Pull requests",actions:e.jsx("div",{ref:m=>{L(m)},className:"flex items-center gap-1"})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(hr,{hideFilesTab:!0,headerActionsSlot:n&&i==="pull-requests"?g:null,headerActionsPresentation:"drawer"})})})})]})}):null,_.has("issues")?e.jsx("div",{className:W("h-full",i!=="issues"&&"hidden"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[e.jsx(ot,{icon:Le.find(m=>m.id==="issues")?.icon,title:Le.find(m=>m.id==="issues")?.label??"Issues",actions:e.jsx("div",{ref:m=>{F(m)},className:"flex items-center gap-1"})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(pr,{headerActionsSlot:n&&i==="issues"?j:null,headerActionsPresentation:"drawer"})})})})]})}):null]})]});return o==="panel"?e.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:K}):We.createPortal(e.jsxs("div",{ref:C,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none",visibility:S?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[e.jsx("button",{ref:E,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:h,tabIndex:n?0:-1,style:{opacity:f?1:0,transition:U?`opacity ${U}ms ${be}`:"none"},"data-mobile-workspace-scrim":"true"}),e.jsx("section",{ref:P,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-full flex-col bg-sidebar",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:f?"none":"translateX(100%)",transition:U?`transform ${U}ms ${be}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:K})]}),R.current)}),br="pichamber",xr=s=>s.replace(/^\/+|\/+$/g,""),gr=s=>{const n=xr(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...n]:n};function yr(s){if(typeof s!="string"||s.length===0)return null;let n;try{n=new URL(s)}catch{return null}if(n.protocol!==`${br}:`)return null;const r=gr(n),i=(r[0]??"").toLowerCase(),l=r.slice(1),a=n.searchParams;switch(i){case"session":{const o=l[0]||a.get("id")||"";return o?{type:"session",sessionId:o,directory:a.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:a.get("dir")??void 0,projectId:a.get("project")??void 0,agent:a.get("agent")??void 0,model:a.get("model")??void 0};case"sessions":{const o=a.get("filter");return{type:"sessions",filter:o==="attention"||o==="recent"||o==="all"?o:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:l[0]||a.get("section")||void 0};case"changes":return{type:"changes",path:l.join("/")||a.get("path")||void 0,staged:a.get("staged")==="true"};case"view":{const o=(l[0]||"").toLowerCase();return o==="changes"?{type:"changes"}:o==="files"||o==="mcp"||o==="instances"||o==="update"?{type:"view",target:o}:null}default:return null}}let ee={},Lt=!1,_e=null;const vr=s=>{switch(s.type){case"session":return ue.getState().setCurrentSession(s.sessionId,s.directory??null),!0;case"new-session":{const n=ue.getState();return n.openNewSessionDraft(),(s.directory||s.projectId)&&n.setNewSessionDraftTarget({directoryOverride:s.directory??null,projectId:s.projectId??null,selectedProjectId:s.projectId??null}),!0}case"sessions":return ee.openSessions?(ee.openSessions(s.filter),!0):!1;case"status":return ee.openSessions?(ee.openSessions(),!0):!1;case"view":return ee.openView?(ee.openView(s.target),!0):!1;case"changes":return ee.openChanges?(ee.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return ee.openSettings?(ee.openSettings(s.section),!0):!1}},Qe=()=>{if(!Lt||!_e)return;const s=_e;_e=null,vr(s)||(_e=s)},wr=s=>{_e=s,Qe()},Sr=s=>{const n=yr(s);n&&wr(n)},jr=s=>{Lt=s,Qe()},Rr=s=>{t.useEffect(()=>(ee=s,Qe(),()=>{ee===s&&(ee={})}),[s])},kr=s=>{const{ready:n}=s;t.useEffect(()=>{jr(n)},[n]),t.useEffect(()=>{if(!Xt())return;let r=!1;const i=[];return Me(()=>import("./vendor-capacitor-app-Bpy_aPMq.js"),__vite__mapDeps([88,6,1,2,3])).then(async({App:l})=>{if(r)return;const a=await l.addListener("appUrlOpen",o=>{Sr(o?.url)});if(r){a.remove();return}i.push(()=>{a.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(l=>l())}},[])},gt=s=>{const n=s.drawer.current,r=s.scrim.current,i=s.root.current;i&&(i.style.pointerEvents="auto",i.style.visibility="visible"),n&&(n.style.transition="none"),r&&(r.style.transition="none")},yt=(s,n,r)=>{const i=s.drawer.current,l=s.scrim.current;if(i&&(i.style.transform=r>=.999?"none":`translateX(${(n==="left"?r-1:1-r)*100}%)`),l){l.style.opacity=String(r);const a=r>.01?"auto":"none";l.style.pointerEvents!==a&&(l.style.pointerEvents=a)}},vt=(s,n,r)=>{const i=r.drawer.current,l=r.scrim.current,a=r.root.current;i&&(i.style.transition=`transform ${Ne}ms ${be}`,i.style.transform=n?"none":s==="left"?"translateX(-100%)":"translateX(100%)"),l&&(l.style.transition=`opacity ${Ne}ms ${be}`,l.style.opacity=n?"1":"0",l.style.pointerEvents=n?"auto":"none"),a&&(a.style.pointerEvents=n?"auto":"none",a.style.visibility=n?"visible":"")},wt=s=>{const n=s.shell.current,r=s.inner.current;n&&(n.style.overflow="visible"),r&&(r.style.transition="none")},St=(s,n,r,i)=>{const l=s.inner.current;if(!l)return;const a=i==="left"?(n-1)*r:(1-n)*r;l.style.transform=n>=.999?"translateX(0)":`translateX(${a}px)`},jt=(s,n,r,i,l)=>{const a=s.shell.current,o=s.inner.current;return!a||!o?void 0:(o.style.transition="transform 200ms cubic-bezier(0.22, 1, 0.36, 1)",o.style.transform=n?"translateX(0)":`translateX(${i==="left"?-r:r}px)`,window.setTimeout(()=>{o.style.transition="",o.style.transform="",a.style.overflow=""},220))},Rt=({side:s,isResizing:n,ariaLabel:r,handleProps:i})=>e.jsx("div",{className:W("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",s==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:e.jsx("div",{className:W("absolute inset-y-0 w-[3px] transition-colors",s==="left"?"right-0":"left-0",n&&"bg-[var(--interactive-border)]")})}),Er=320,Cr=380,kt=280,Nr=560,Tr=900;function Et(s,n,r,i=Nr){const l=t.useRef(null),[a,o]=t.useState(()=>{if(typeof window>"u")return r;const h=Number.parseInt(window.localStorage.getItem(n)??"",10);return Number.isFinite(h)?Math.min(i,Math.max(kt,h)):r}),[v,p]=t.useState(!1),d=t.useRef(0),b=t.useRef(a),R=t.useRef(null),w=t.useRef(null),T=t.useCallback(h=>Math.min(i,Math.max(kt,Math.round(h))),[i]),y=t.useCallback(h=>{const f=l.current;f&&(f.style.width=`${h}px`,f.style.minWidth=`${h}px`,f.style.maxWidth=`${h}px`,f.style.setProperty("--oc-ipad-sidebar-width",`${h}px`))},[]),P=t.useCallback(h=>{try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}w.current=h.pointerId,d.current=h.clientX,b.current=a,R.current=a,p(!0),h.preventDefault()},[a]),E=t.useCallback(h=>{if(w.current!==h.pointerId)return;const f=h.clientX-d.current,A=T(b.current+(s==="left"?f:-f));R.current!==A&&(R.current=A,y(A))},[y,T,s]),N=t.useCallback(h=>{if(w.current!==h.pointerId)return;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const f=T(R.current??b.current);w.current=null,R.current=null,p(!1),o(f);try{window.localStorage.setItem(n,String(f))}catch{}},[T,n]),C=t.useMemo(()=>({onPointerDown:P,onPointerMove:E,onPointerUp:N,onPointerCancel:N}),[P,N,E]);return{asideRef:l,width:a,isResizing:v,handleProps:C}}const Ir=t.memo(Sn),Pr=({onActiveConnectionDeleted:s})=>{const[n,r]=t.useState(!1),[i,l]=t.useState(null),[a,o]=t.useState(!1),[v,p]=t.useState("changes"),d=t.useCallback(c=>{p(lt(c))},[]),b=v,[R,w]=t.useState("nav"),[T,y]=t.useState(null),P=t.useRef([]),E=t.useCallback(()=>{P.current.forEach(c=>window.clearTimeout(c)),P.current=[]},[]);t.useEffect(()=>()=>E(),[E]);const N=t.useRef(null),C=t.useRef(null),h=t.useRef(null),f=t.useRef(null),A=t.useRef(null),S=t.useRef(null),$=t.useRef(null),G=t.useRef(null),B=t.useRef(0),_=t.useRef(0),M=t.useCallback(c=>{E(),r(c)},[E]),g=t.useCallback(c=>{E(),o(c)},[E]),L=Ee(c=>c.setSettingsPage),j=Ee(c=>c.isArchivePageOpen),F=Ee(c=>c.setArchivePageOpen),U=Ce(c=>c.available),te=Ce(c=>c.runtimeType),x=t.useMemo(()=>Dt(),[]),k=!x&&U&&(te==="desktop"||te==="web"),K=Kn()??"",m=K?Kt(K):"",H=Yn().github??null,ne=ct(c=>c.ensureScope);t.useEffect(()=>{!m||!H||ne(m,H)},[m,H,ne]);const xe=ct(c=>m?c.entriesByDirectory[m]??null:null),Te=t.useMemo(()=>qn(xe),[xe]),ie=Qn(Te);t.useEffect(()=>{!ie&&mn(v)&&p(bn(v))},[ie,v]);const fe=t.useCallback(()=>{l(null)},[]),X=t.useCallback(c=>{l(c)},[]),je=t.useCallback(()=>{g(!1)},[g]),ge=t.useCallback(c=>{w(c),X("settings")},[X]),{enabled:D,roomyForPanels:se}=Jn(),I=Zn()==="portrait",V=es(),O=Ee(c=>c.setSidebarOpen),z=Ee(c=>c.isSidebarOpen),J=t.useRef(!1);t.useLayoutEffect(()=>{D&&!J.current&&O(ts().roomyForPanels),!D&&J.current&&O(!1),J.current=D},[D,O]);const Re=t.useCallback(()=>{y(null),d("files"),g(!0)},[d,g]),ae=t.useCallback((c=null)=>{y(c),d("changes"),g(!0)},[d,g]),Y=Et("left","pichamber.ipad.leftSidebarWidth",Er),q=Et("right","pichamber.ipad.rightSidebarWidth",Cr,Tr),ye=se,Z=ye&&a?q.width:0,zt=xn(D&&z),Ie=D&&z?Y.width:0,Wt=t.useCallback(c=>{const Q=lt(c);a&&b===Q?g(!1):(d(Q),g(!0))},[a,b,d,g]),Ut=t.useCallback(()=>{g(!a)},[a,g]),Bt=t.useCallback(c=>{!c&&!se&&O(!1)},[se,O]);t.useEffect(()=>{if(typeof document>"u")return;const c=document.documentElement;return c.style.setProperty("--oc-chat-inset-left",`${Ie}px`),c.style.setProperty("--oc-chat-inset-right",`${Z}px`),()=>{c.style.removeProperty("--oc-chat-inset-left"),c.style.removeProperty("--oc-chat-inset-right")}},[Ie,Z]),t.useEffect(()=>{if(typeof document>"u")return;const c=D&&(I||V),Q=document.documentElement;return Q.classList.toggle("oc-keep-draft-starters",c),()=>Q.classList.remove("oc-keep-draft-starters")},[V,D,I]);const Je=t.useCallback(()=>{M(!1),g(!1)},[M,g]),Ht=t.useMemo(()=>({openChanges:({diffPath:c,staged:Q}={})=>{ae(c?{path:c,staged:Q===!0}:null)},openFiles:()=>Re(),openSettings:c=>{c&&L(c),ge(c?"page-content":"nav")},openInstances:x?()=>X("instances"):void 0,instanceLabel:x?ve():null,openUpdate:k?()=>X("update"):void 0,closeDrawers:Je}),[Je,ae,Re,ge,X,L,x,k]),$t=t.useMemo(()=>({openSessions:()=>{D?O(!0):M(!0)},openView:c=>{if(c==="files"){Re();return}(c==="instances"||c==="update"||c==="mcp")&&X(c)},openChanges:({path:c,staged:Q}={})=>{ae(c?{path:c,staged:Q===!0}:null)},openSettings:c=>{c&&L(c),ge(c?"page-content":"nav")}}),[D,ae,Re,ge,X,L,M,O]);Rr($t);const Ze=t.useRef(null);gn(Ze,{leftOpen:D?z:n,rightOpen:a,leftWidth:()=>D?Y.width:N.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>D?q.width:f.current?.offsetWidth||window.innerWidth,onLeftProgress:c=>{if(B.current=c,D){St({inner:$},c,Y.width,"left");return}yt({drawer:N,scrim:C},"left",c)},onRightProgress:c=>{if(_.current=c,D&&se){St({inner:G},c,q.width,"right");return}yt({drawer:f,scrim:A},"right",c)},onLeftOpen:()=>{D?O(!0):M(!0)},onLeftClose:()=>{D?O(!1):M(!1)},onRightOpen:()=>g(!0),onRightClose:()=>g(!1),onDragStart:c=>{if(E(),c==="left"){B.current=D?z?1:0:n?1:0,D?wt({shell:Y.asideRef,inner:$}):gt({drawer:N,scrim:C,root:h});return}_.current=a?1:0,D&&se?wt({shell:q.asideRef,inner:G}):gt({drawer:f,scrim:A,root:S})},onDragEnd:(c,Q)=>{if(c==="left"){const ke=typeof Q=="boolean"?Q:B.current>.5;if(B.current=ke?1:0,D){const et=jt({shell:Y.asideRef,inner:$},ke,Y.width,"left");et!==void 0&&P.current.push(et)}else vt("left",ke,{drawer:N,scrim:C,root:h});return}const Be=typeof Q=="boolean"?Q:_.current>.5;if(_.current=Be?1:0,D&&se){const ke=jt({shell:q.asideRef,inner:G},Be,q.width,"right");ke!==void 0&&P.current.push(ke)}else vt("right",Be,{drawer:f,scrim:A,root:S})}});const Ft=t.useCallback(()=>j?(F(!1),!0):i?(fe(),!0):a?(je(),!0):n?(M(!1),!0):!1,[i,fe,je,j,n,F,M,a]);Pt(Ft);const Ue=D?"dialog":"fullscreen";return e.jsx(ns,{actions:Ht,children:e.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:[D?e.jsxs("aside",{ref:Y.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!z&&"border-r-0"),style:{width:Ie,minWidth:Ie,maxWidth:Ie,"--oc-ipad-sidebar-width":`${Y.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!z,"data-page-scroll-lock":"true",children:[e.jsx("div",{ref:$,className:W("flex h-full shrink-0 flex-col",Y.isResizing&&"pointer-events-none",!z&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:Y.isResizing||zt.slidIn?"translateX(0)":"translateX(-100%)",transition:Y.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:e.jsx(re,{children:e.jsx(pt,{open:z,variant:"sidebar",onOpenChange:Bt})})}),z?e.jsx(Rt,{side:"left",isResizing:Y.isResizing,ariaLabel:"Resize left panel",handleProps:Y.handleProps}):null]}):null,e.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[D?e.jsxs(e.Fragment,{children:[e.jsx(yn,{}),e.jsx(vn,{onToggleRightDrawer:Ut,rightDrawerOpen:a,tabletWorkspaceTab:b,onSelectTabletWorkspaceTab:Wt,tabletGitHubTabsAvailable:ie})]}):e.jsx(or,{onOpenSessions:()=>M(!0),onOpenWorkspace:()=>g(!0)}),e.jsx("main",{ref:Ze,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:e.jsx("div",{className:"h-full w-full",children:e.jsx(re,{children:e.jsx(Ir,{})})})})]}),D?null:e.jsx(pt,{open:n,onOpenChange:M,drawerRefExternal:N,scrimRefExternal:C,rootRefExternal:h}),D?e.jsxs("aside",{ref:q.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!Z&&"border-l-0"),style:{width:Z,minWidth:Z,maxWidth:Z,"--oc-ipad-sidebar-width":`${q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!Z,"data-page-scroll-lock":"true",children:[e.jsx("div",{ref:G,className:W("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",q.isResizing&&"pointer-events-none",!Z&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:Z?"translateX(0)":"translateX(100%)",transition:q.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:e.jsx(re,{children:e.jsx(xt,{open:a,onClose:je,tab:b,onTabChange:d,pendingChangesDiff:T,variant:ye?"panel":"drawer",githubTabsAvailable:ie,drawerRefExternal:f,scrimRefExternal:A,rootRefExternal:S})})}),Z?e.jsx(Rt,{side:"right",isResizing:q.isResizing,ariaLabel:"Resize right panel",handleProps:q.handleProps}):null]}):e.jsx(xt,{open:a,onClose:je,tab:b,onTabChange:d,pendingChangesDiff:T,githubTabsAvailable:ie,drawerRefExternal:f,scrimRefExternal:A,rootRefExternal:S}),i==="instances"&&x?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Servers",title:"Servers",children:e.jsx(lr,{onConnect:fe,onActiveConnectionDeleted:s})}):null,i==="settings"?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Settings",headerless:!0,children:e.jsx(re,{children:e.jsx(zs,{forceMobile:!D,isWindowed:!0,initialMobileStage:R,onClose:fe,onActiveConnectionDeleted:s})})}):null,i==="update"?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Update",title:"Update",children:e.jsx(re,{children:e.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:e.jsx(Ws,{initialUpdateDialogOpen:!0})})})}):null,e.jsx(re,{children:e.jsx(wn,{})})]})})},Ar=8,Ot=6e4,Dr=6e4,Ye=[1e3,2e3,4e3,8e3,15e3,3e4,3e4,3e4],_r=(s,n)=>{if(n?.offline||n?.hidden)return Ot;if(s<=0)return Ye[0];const r=Math.min(s-1,Ye.length-1);return Ye[r]??3e4},oe=()=>typeof navigator<"u"&&typeof navigator.onLine=="boolean"?!navigator.onLine:!1,le=()=>typeof document<"u"&&typeof document.visibilityState=="string"?document.visibilityState==="hidden":!1;class Mr{constructor(n,r,i=()=>""){this.probe=n,this.callbacks=r,this.getRuntimeIdentity=i}probe;callbacks;getRuntimeIdentity;generation=0;attempt=0;timer=null;wakeCleanup=null;running=!1;exhausted=!1;probingGeneration=null;get currentGeneration(){return this.generation}get currentAttempt(){return this.attempt}get isRunning(){return this.running&&!this.exhausted}start(){he("recovery",{code:"start"}),this.startCycle(!1)}startCycle(n){this.clearTimer(),this.generation+=1,this.attempt=0,this.exhausted=!1,this.running=!0,n?this.runAttempt(this.generation):this.scheduleNext(this.generation)}retryNow(){if(this.exhausted){if(oe()||le())return;this.startCycle(!0);return}this.running&&(this.clearTimer(),this.runAttempt(this.generation))}cancel(){he("recovery",{code:"cancel"}),this.generation+=1,this.running=!1,this.exhausted=!1,this.attempt=0,this.probingGeneration=null,this.clearTimer()}async probeOnce(){return this.running||this.exhausted||this.probingGeneration!==null||oe()||le()?null:this.runGuardedProbe(this.generation)}async runGuardedProbe(n){this.probingGeneration=n;const r=this.getRuntimeIdentity();let i;try{i=await this.probe()}catch{i="unreachable"}finally{this.probingGeneration===n&&(this.probingGeneration=null)}return n!==this.generation||this.getRuntimeIdentity()!==r?null:i}settleTerminalOutcome(n){return n==="unreachable"?!1:(this.running=!1,this.exhausted=!1,this.clearTimer(),n==="needs-login"?this.callbacks.onAuthExpired():n==="no-connection"?this.callbacks.onNoConnection():this.callbacks.onHealthy(n),!0)}clearTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.wakeCleanup&&(this.wakeCleanup(),this.wakeCleanup=null)}scheduleNext(n){if(n!==this.generation||!this.running||this.exhausted)return;if(this.attempt>=Ar){this.exhausted=!0,this.running=!1,this.callbacks.onExhausted(),this.scheduleExhaustedPoll(n);return}const r=this.attempt+1,i=_r(r,{offline:oe(),hidden:le()});this.callbacks.onAttempt?.(r,i);const l=()=>{oe()||le()||n===this.generation&&(this.clearTimer(),this.runAttempt(n))},a=()=>l(),o=()=>{typeof document<"u"&&document.visibilityState==="visible"&&l()};typeof window<"u"&&window.addEventListener("online",a),typeof document<"u"&&document.addEventListener("visibilitychange",o),this.wakeCleanup=()=>{typeof window<"u"&&window.removeEventListener("online",a),typeof document<"u"&&document.removeEventListener("visibilitychange",o)},this.timer=setTimeout(()=>{if(this.timer=null,this.wakeCleanup?.(),this.wakeCleanup=null,!(n!==this.generation||!this.running||this.exhausted)){if(oe()||le()){this.scheduleNext(n);return}this.runAttempt(n)}},i)}async runAttempt(n){if(n!==this.generation||!this.running||this.exhausted||this.probingGeneration===n)return;if(oe()||le()){this.scheduleNext(n);return}const r=await this.runGuardedProbe(n);r===null||this.settleTerminalOutcome(r)||(this.attempt+=1,this.scheduleNext(n))}scheduleExhaustedPoll(n){if(n!==this.generation||!this.exhausted)return;this.clearTimer();const r=oe()||le()?Ot:Dr;this.timer=setTimeout(()=>{this.timer=null,this.runExhaustedPoll(n)},r)}async runExhaustedPoll(n){if(n!==this.generation||!this.exhausted)return;if(this.probingGeneration!==null||oe()||le()){this.scheduleExhaustedPoll(n);return}const r=await this.runGuardedProbe(n);r===null||!this.exhausted||this.settleTerminalOutcome(r)||this.scheduleExhaustedPoll(n)}}function Lr({state:s,label:n,onRetry:r,onUseAnotherServer:i}){const l=n.trim()||"the server";return e.jsx("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px)+10px)] z-40 flex justify-center px-4",children:s==="reconnecting"?e.jsxs("span",{className:"flex max-w-full items-center gap-2 rounded-full border border-border/70 bg-[var(--surface-elevated)] py-1.5 pl-2 pr-3 text-[var(--surface-elevated-foreground)] shadow-sm",children:[e.jsx(we,{width:20,height:20,isAnimated:!0}),e.jsx("span",{className:"truncate typography-ui-label",children:`Reconnecting to ${l}…`})]}):e.jsxs("div",{className:"pointer-events-auto flex w-full max-w-sm flex-col gap-3 rounded-xl border border-border/70 bg-[var(--surface-elevated)] p-3 text-[var(--surface-elevated-foreground)] shadow-sm",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"truncate typography-ui-label font-medium",children:`Can't reach ${l}`}),e.jsx("p",{className:"typography-meta text-muted-foreground [text-wrap:pretty]",children:"Its address may only work on another network. Still retrying in the background."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Se,{type:"button",variant:"ghost",size:"sm",onClick:i,children:"Use another server"}),e.jsx(Se,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Retry"})]})]})})}function Or(s=2500){const{uiFont:n}=ss(),[r,i]=t.useState(!1);return t.useEffect(()=>{let l=!1;const a=()=>{l||i(!0)},o=()=>{requestAnimationFrame(()=>requestAnimationFrame(a))},v=Promise.all([rs(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),Vs.catch(()=>{})]).then(()=>{}),p=new Promise(d=>{window.setTimeout(d,s)});return Promise.race([v,p]).then(o),()=>{l=!0}},[n,s]),r}const zr=1e3,Wr=2;function Ur({apis:s}){const n=pe(u=>u.initializeApp),r=pe(u=>u.isInitialized),i=pe(u=>u.isConnected),l=pe(u=>u.connectionPhase),a=pe(u=>u.providers.length),o=pe(u=>u.loadProviders),v=Ct(u=>u.currentDirectory),p=ue(u=>u.error),d=ue(u=>u.clearError),b=Ee(u=>u.setIsMobile),[R,w]=t.useState(0),[T,y]=t.useState(0),[P,E]=t.useState(!1),[N,C]=t.useState("idle"),[h,f]=t.useState(0),A=is(),S=t.useRef(null),$=t.useRef(N);$.current=N;const[G,B]=t.useState("pending"),[_,M]=t.useState(null),g=t.useMemo(()=>ve(),[]),[,L]=t.useReducer(u=>u+1,0),j=t.useMemo(()=>Dt(),[]),F=t.useRef(0),U=t.useRef(0),te=t.useRef(!1),[x,k]=t.useState(()=>j&&!!de());t.useEffect(()=>{const u=new Mr(()=>Us(),{onHealthy:I=>{if(he("recovery",{code:"success"}),C("idle"),f(0),me(!1),I==="unchanged"){Zt(),pe.getState().initializeApp();const V=pe.getState();V.providers.length===0&&V.loadProviders({source:"mobileApp:recovery"})}},onAuthExpired:()=>{he("recovery",{code:"auth-expired"}),C("idle"),f(0),me(!1),M({kind:"auth-expired",label:ve()??""}),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),w(I=>I+1)},onNoConnection:()=>{he("recovery",{code:"no-connection"}),C("idle"),f(0),me(!1),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),w(I=>I+1)},onExhausted:()=>{he("recovery",{code:"exhausted"}),C("exhausted")},onAttempt:I=>{he("recovery",{code:"attempt",detail:String(I)}),f(I)}},()=>`${Ae()}|${de()}`);return S.current=u,()=>{u.cancel(),S.current=null}},[]);const K=t.useCallback(()=>{if(!j||!de())return;const u=S.current;if(u){if(u.isRunning){u.retryNow();return}C("recovering"),f(0),me(!0),u.start()}},[j]),m=t.useCallback(()=>{S.current?.cancel(),C("idle"),f(0),me(!1),k(!1)},[]),H=t.useCallback(()=>{const u=S.current;if(u){if(u.isRunning){f(0),u.retryNow();return}$.current!=="exhausted"||oe()||(C("recovering"),f(0),me(!0),u.retryNow())}},[]),ne=t.useCallback(u=>{m(),u&&M(u),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),w(I=>I+1)},[m]),xe=t.useCallback(()=>{const u=Date.now();u-F.current>=zr&&(F.current=u,window.dispatchEvent(new Event("pichamber:system-resume")))},[]),Te=t.useCallback(()=>{const u=de(),I=U.current+1;if(U.current=I,!u){if(te.current)return;te.current=!0,Ve().catch(()=>{}).finally(()=>{te.current=!1});return}if(S.current?.isRunning){S.current.retryNow(),xe();return}if($.current==="exhausted"){if(oe()||le())return;C("recovering"),f(0),me(!0),S.current?.start(),xe();return}if(oe()||le()){K();return}const V=()=>{n(),a===0&&o({source:"mobileApp:nativeResume"})},O=S.current;O&&(O.probeOnce().then(z=>{if(z!==null&&U.current===I){if(z==="no-connection"){ne(null);return}if(z==="needs-login"){ne({kind:"auth-expired",label:ve()??""});return}if(z==="unreachable"){K();return}z!=="switched"&&V()}}),xe())},[ne,xe,n,o,a,K]);as(),os(Te),t.useEffect(()=>Yt(),[]),t.useEffect(()=>{if(!j)return;let u;const I=()=>{if(S.current?.isRunning){S.current.retryNow();return}if($.current==="exhausted"){if(le())return;C("recovering"),f(0),me(!0),S.current?.start();return}window.clearTimeout(u),u=window.setTimeout(()=>Te(),1500)};return window.addEventListener("online",I),()=>{window.removeEventListener("online",I),window.clearTimeout(u)}},[j,Te]),t.useEffect(()=>{if(j)return qt(()=>{de()&&ne({kind:"auth-expired",label:ve()??""})})},[ne,j]),t.useEffect(()=>(nt(s),()=>nt(null)),[s]),t.useEffect(()=>Qt(u=>{if(!!u.runtimeKey&&u.runtimeKey===u.previousRuntimeKey){jn(),L();return}m(),Rn(u),y(V=>V+1),w(V=>V+1)}),[m]),t.useEffect(()=>{Nt()},[T]),t.useEffect(()=>{if(!j||i||de()){B("done");return}let u=!1;return B("attempting"),Ve().catch(()=>({status:"no-candidate"})).then(I=>{u||(he("auto-connect",{code:I.status}),I.status==="unreachable"?M({kind:"unreachable",label:I.label}):I.status==="needs-login"&&M({kind:"auth-expired",label:I.label}),B("done"))}),()=>{u=!0}},[]),t.useEffect(()=>{if(!j||!de()){k(!1);return}let u=!1;const I=O=>{O&&M(O),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),w(z=>z+1)},V=S.current;if(!V){k(!1);return}return(async()=>{try{const O=await V.probeOnce();if(u||O===null||O==="switched"||O==="unchanged")return;const z=ve();if(O==="needs-login"){I({kind:"auth-expired",label:z??""});return}if(O==="unreachable"){K();return}const J=await Ve().catch(()=>({status:"no-candidate"}));if(u||(he("auto-connect",{code:J.status}),J.status==="connected"))return;J.status==="needs-login"?I({kind:"auth-expired",label:J.label}):J.status==="unreachable"?I({kind:"unreachable",label:J.label}):I(null)}finally{u||k(!1)}})(),()=>{u=!0,k(!1)}},[K]),t.useEffect(()=>{b(!0)},[b]),t.useEffect(()=>{j&&!de()||n()},[R,n,j]),t.useEffect(()=>{i&&a===0&&o({source:"mobileApp:recovery"})},[i,o,a]);const ie=t.useRef(!1),[fe,X]=t.useState(j);t.useEffect(()=>{if(!j||!i||ie.current)return;if(ue.getState().currentSessionId){ie.current=!0,X(!1);return}const u=Ae(),I=ls(u);if(!I){ie.current=!0,X(!1);return}const V=Jt(I.directory??null);if(!V){ie.current=!0,X(!1);return}const O=De();let z=0;try{z=O.getRuntimeGeneration()}catch{z=0}let J=!1;const Re=window.setTimeout(()=>X(!1),6e3);return(async()=>{let ae=null;try{ae=await cs([V])}catch{ae=null}if(J)return;if(!ae){X(!1);return}const Y=De();let q=z;try{q=Y.getRuntimeGeneration()}catch{q=z}const ye=tr({persisted:I,persistedDirectory:V,stale:ae.stale,ready:ae.readyDirectories.has(V),catalog:ae.catalog,runtimeKey:Ae(),capturedRuntimeKey:u,storeIdentityMatches:Y===O,generationMatches:q===z});if(ye.action==="wait"){X(!1);return}if(ie.current=!0,ye.action==="clear"){us(u),X(!1);return}const Z=ue.getState();if(Ae()!==u||De()!==O){X(!1);return}Z.currentSessionId||Z.setCurrentSession(ye.sessionId,ye.directory),X(!1)})(),()=>{J=!0,window.clearTimeout(Re)}},[R,i,j]),t.useEffect(()=>{i&&De().focusProject(v,tn(v))},[v,i]),t.useEffect(()=>{if(!p)return;const u=window.setTimeout(()=>d(),5e3);return()=>window.clearTimeout(u)},[d,p]),t.useEffect(()=>{if(j&&N!=="idle"){E(!1);return}if(j&&x){E(!1);return}if(!(!i&&(j?!!de():!0))){E(!1);return}const I=window.setTimeout(()=>{E(!0)},j?4e3:8e3);return()=>window.clearTimeout(I)},[i,j,R,N,T,x]),ds(),kn(),kr({ready:j&&i&&r});const je=Or(),ge=!i&&l==="reconnecting",D=!!de(),se=j&&D&&N!=="idle";return t.useEffect(()=>{se&&X(!1)},[se]),je?j&&!se&&(!D||!i&&!ge)?D?e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[e.jsx(we,{width:120,height:120,isAnimated:!P}),P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),e.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another server."})]}),e.jsx(Se,{type:"button",variant:"outline",onClick:()=>{ne(null)},children:"Use another server"})]}):null]})}):G!=="done"?e.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[e.jsx(we,{width:120,height:120,isAnimated:!0}),g?e.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[e.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),e.jsx("div",{className:"flex justify-center",children:e.jsx(fs,{text:g,showElapsed:!1})})]}):null]}):e.jsx(e.Fragment,{children:e.jsx(nr,{onConnected:()=>w(u=>u+1),notice:_})}):!j&&!i&&!ge?P?e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:e.jsxs("div",{className:"max-w-sm space-y-3",children:[e.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),e.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."})]})}):e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:e.jsx(we,{width:120,height:120,isAnimated:!0})}):e.jsx(re,{children:e.jsx(hs,{children:e.jsxs(ps,{apis:s,children:[e.jsx(ms,{}),e.jsx(bs,{}),e.jsx(En,{}),e.jsx(xs,{}),e.jsx(gs,{}),e.jsx(ys,{delayDuration:300,skipDelayDuration:150,children:e.jsxs(Cn,{children:[e.jsx(Nn,{}),e.jsxs("div",{className:"h-full bg-background text-foreground",children:[j&&fe&&i&&!se?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:e.jsx(we,{width:120,height:120,isAnimated:!0})}):null,e.jsx(vs,{embeddedBackgroundWorkEnabled:r&&!A}),se?e.jsx(Lr,{state:N==="exhausted"||h>=Wr?"unreachable":"reconnecting",label:ve()??"",onRetry:H,onUseAnotherServer:()=>ne(null)}):null,e.jsx(er,{}),e.jsx(Pr,{onActiveConnectionDeleted:()=>{m(),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),w(u=>u+1)}}),e.jsx(Tn,{}),e.jsx(In,{}),e.jsx(ws,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),e.jsx(Ss,{})]})]})})]})},T)}):e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:e.jsx(we,{width:120,height:120,isAnimated:!0})})}const Br=()=>{(async()=>{try{await Promise.all([Nt(),nn()])}catch(s){console.error("[mobile-main] settings init failed:",s)}Cs(),Ns(),Ts(),sn()})().finally(()=>{Gs()})};function fi(s){window.__PICHAMBER_SURFACE__="mobile",js(),Br(),Zs(),Rs();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");const i=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",l=s??en();if(!l)throw new Error("Runtime APIs not registered");const a=i?{...l,notifications:{notify:async()=>!1,canNotify:()=>!1}}:l,o=e.jsx(Ur,{apis:a});Vt.createRoot(n).render(e.jsx(qe.StrictMode,{children:e.jsx(ks,{children:e.jsx(Pn,{children:i?o:e.jsx(Es,{children:o})})})}))}export{fi as renderMobileApp};
11
+ `})]}):null},lr=({onOpenSessions:s,onOpenWorkspace:n,compactTitle:r=!1})=>{const[i,l]=t.useState(!1),[a,o]=t.useState(!1),j=t.useRef(null),p=Je(h=>h.currentDirectory),d=ue(h=>h.currentSessionId),R=ue(t.useCallback(h=>d?h.getDirectoryForSession(d):null,[d]))||p,v=Xn(d),T=ue(h=>!!h.newSessionDraft?.open),P=v?.title?.trim()||(d?Dt(v,"Untitled session"):"New session");t.useEffect(()=>{l(!1),o(!1)},[d,R]);const E=t.useCallback(()=>{l(!1),o(!1),s()},[s]),N=t.useCallback(h=>{l(f=>{const A=typeof h=="function"?h(f):h;return A&&o(!1),A})},[]),C=t.useCallback(()=>{o(h=>{const f=!h;return f&&l(!1),f})},[]);return e.jsxs(e.Fragment,{children:[e.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:e.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[e.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:E,style:{touchAction:"manipulation"},children:e.jsx(ce,{name:"list-unordered",className:"size-5"})}),e.jsx("button",{ref:j,type:"button",className:W("flex h-10 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",r?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":a,onClick:C,style:{touchAction:"manipulation"},children:e.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:P}),e.jsx(ce,{name:"arrow-down-s",className:W("size-4 shrink-0 text-muted-foreground transition-transform duration-150",a&&"rotate-180")})]})}),r?e.jsx("div",{className:"min-w-0 flex-1"}):null,e.jsx(on,{open:i,onOpenChange:N,currentSessionId:d,effectiveDirectory:R,isNewSessionDraftOpen:T}),e.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:()=>{l(!1),o(!1),n()},style:{touchAction:"manipulation"},children:e.jsx(ce,{name:"layout-right",className:"size-5"})})]})}),e.jsx(or,{open:a,onClose:()=>o(!1),anchorRef:j})]})},cr=({onActiveConnectionDeleted:s,onConnect:n})=>e.jsx(Os,{onConnect:n,onActiveConnectionDeleted:s,showDiagnostics:!0}),Ne=320,be="cubic-bezier(0.22, 1, 0.36, 1)",Lt=({side:s,enabled:n,open:r,drawerRef:i,scrimRef:l,onClose:a,widthRatio:o,prefersReducedMotion:j})=>{t.useEffect(()=>{if(!n||!r)return;const p=i.current,d=l.current;if(!p||!d)return;let b=!1,R=!1,v=!1,T=0,y=0,P=0,E=0;const N=j?0:Ne,C=s==="left"?"translateX(-100%)":"translateX(100%)",h=()=>({drawer:N?`transform ${N}ms ${be}`:"none",scrim:N?`opacity ${N}ms ${be}`:"none"}),f=()=>{const g=h();p.style.transition=g.drawer,d.style.transition=g.scrim,p.style.transform="none",d.style.opacity="1",d.style.pointerEvents="auto"},A=()=>{b=!1,R=!1,v=!1},w=()=>{if(!(b||R)){A();return}f(),A()},$=g=>{if(g.touches.length!==1){(b||R)&&w();return}if(ln(g.target,p,{excludeInteractive:!1}))return;p.style.transition&&p.style.transition!=="none"&&(p.style.transition="none",d.style.transition="none");const L=g.touches[0];T=L.clientX,y=L.clientY,P=Date.now(),E=p.offsetWidth||window.innerWidth*o,E<10&&(E=window.innerWidth*o),b=!0,R=!1,v=!1},G=g=>{if(!b)return;if(g.touches.length!==1){w();return}const L=g.touches[0],S=L.clientX-T,F=L.clientY-y;if(!v){if(Math.abs(S)<it&&Math.abs(F)<it)return;if(Math.abs(F)>Math.abs(S)*at||!ot(s,S)){b=!1;return}v=!0,R=!0,p.style.transition="none",d.style.transition="none"}if(!R)return;g.cancelable&&g.preventDefault();const U=lt(s,S,E);p.style.transform=cn(s,U),d.style.opacity=String(U)},B=(g,L,S)=>{if(!b)return;const F=g-T,U=L-y,te=Math.max(1,Date.now()-P),x=lt(s,F,E),k=dn({side:s,dx:F,dy:U,dt:te,progress:x,isDragging:R}),K=h();p.style.transition=K.drawer,d.style.transition=K.scrim,p.style.transform=k?C:"none",d.style.opacity=k?"0":"1",d.style.pointerEvents=k?"none":"auto",A(),k&&a()},_=g=>{const L=g.changedTouches[0];if(!L){w();return}const S=L.clientX-T,F=L.clientY-y,U=Math.abs(S)>=un&&Math.abs(F)<=Math.abs(S)*at&&ot(s,S);b&&(R||U)&&g.cancelable&&g.preventDefault(),B(L.clientX,L.clientY)},M=()=>{w()};return p.addEventListener("touchstart",$,{passive:!0}),p.addEventListener("touchmove",G,{passive:!1}),p.addEventListener("touchend",_,{passive:!1}),p.addEventListener("touchcancel",M,{passive:!0}),()=>{try{w()}catch{}p.removeEventListener("touchstart",$),p.removeEventListener("touchmove",G),p.removeEventListener("touchend",_),p.removeEventListener("touchcancel",M)}},[i,n,a,r,j,l,s,o])},ur=16,bt=t.memo(function({open:n,onOpenChange:r,variant:i="drawer",drawerRefExternal:l,scrimRefExternal:a,rootRefExternal:o}){const j=t.useRef(null),p=t.useCallback(()=>{const f=typeof document<"u"?document.activeElement:null;f instanceof HTMLElement&&j.current?.contains(f)&&f.blur(),r(!1)},[r]),[d,b]=t.useState(!1),R=t.useRef(null),v=t.useRef(null),T=l??R,y=a??v,P=t.useCallback(f=>{j.current=f,o&&(o.current=f)},[o]),E=t.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);t.useEffect(()=>{const f=j.current;if(!f||n)return;const A=document.activeElement;A&&f.contains(A)&&A.blur()},[n]),t.useEffect(()=>{if(i!=="sidebar"){if(n){const f=window.setTimeout(()=>b(!0),E?0:ur);return()=>window.clearTimeout(f)}b(!1)}},[n,E,i]),t.useEffect(()=>{if(i==="sidebar"||!n)return;const f=document.body.style.overflow;document.body.style.overflow="hidden";const A=w=>{w.key==="Escape"&&p()};return document.addEventListener("keydown",A),()=>{document.body.style.overflow=f,document.removeEventListener("keydown",A)}},[p,n,i]);const N=i==="sidebar",C=e.jsx(fn,{mobileVariant:!N,isVisible:n,allowReselect:!0,onSessionSelected:N?void 0:p,onNavigateAway:N?void 0:p});if(Lt({side:"left",enabled:i==="drawer",open:n,drawerRef:T,scrimRef:y,onClose:p,widthRatio:.72,prefersReducedMotion:E}),i==="sidebar")return e.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:C});if(typeof document>"u")return null;const h=E?0:Ne;return We.createPortal(e.jsxs("div",{ref:P,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none"},"data-mobile-sessions-root":"true",children:[e.jsx("button",{ref:y,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:p,tabIndex:n?0:-1,style:{opacity:d?1:0,transition:`opacity ${h}ms ${be}`},"data-mobile-sessions-scrim":"true"}),e.jsx("div",{ref:T,className:W("relative z-10 flex h-full w-[72%] max-w-[360px] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:d?"none":"translateX(-100%)",transition:h?`transform ${h}ms ${be}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:C})]}),document.body)}),xt="mobile-surface-root",Xe=16,ze=200,dr=()=>{if(typeof document>"u")return null;let s=document.getElementById(xt);return s||(s=document.createElement("div"),s.id=xt,document.body.appendChild(s)),s},Ke=({open:s,onClose:n,title:r,subtitle:i,trailing:l,disableEscapeDismiss:a=!1,headerless:o=!1,noHeaderBorder:j=!1,ariaLabel:p,variant:d="fullscreen",dialogAlign:b="chat",children:R})=>{const v=t.useRef(null),[T,y]=t.useState(!1),[P,E]=t.useState(!1),N=t.useRef(null),C=t.useRef(null),h=t.useRef(n);if(t.useEffect(()=>{h.current=n},[n]),typeof document<"u"&&!v.current&&(v.current=dr()),t.useEffect(()=>{if(!s){y(!1);return}const w=window.setTimeout(()=>y(!0),Xe);return()=>window.clearTimeout(w)},[s]),t.useEffect(()=>{if(!s){E(!1);return}const w=window.setTimeout(()=>E(!0),Xe+ze+80);return()=>window.clearTimeout(w)},[s]),t.useEffect(()=>{if(!s)return;const w=document.body.style.overflow;C.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const $=()=>{const _=N.current;if(!_)return;(_.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??_).focus({preventScroll:!0})},G=window.setTimeout($,Xe),B=_=>{if(_.key==="Escape"&&!a){h.current();return}if(_.key!=="Tab")return;const M=N.current;if(!M)return;const g=Array.from(M.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(U=>!U.hasAttribute("disabled")&&U.getAttribute("aria-hidden")!=="true");if(g.length===0){_.preventDefault(),M.focus({preventScroll:!0});return}const L=g[0],S=g[g.length-1],F=document.activeElement;_.shiftKey&&F===L?(_.preventDefault(),S.focus({preventScroll:!0})):!_.shiftKey&&F===S&&(_.preventDefault(),L.focus({preventScroll:!0}))};return document.addEventListener("keydown",B),()=>{window.clearTimeout(G),document.body.style.overflow=w,document.removeEventListener("keydown",B),C.current?.focus?.({preventScroll:!0}),C.current=null}},[a,s]),!s||!v.current)return null;const f=d==="dialog",A=e.jsxs("section",{ref:N,role:"dialog","aria-modal":"true","aria-label":p,tabIndex:-1,className:W("flex flex-col bg-background text-foreground",f?"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:f?{opacity:T?1:0,transform:T?"none":"scale(0.97)",transition:`opacity ${ze}ms ease-out, transform ${ze}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:T?"none":"translateX(100%)",transition:`transform ${ze}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{T&&w.target===w.currentTarget&&w.propertyName==="transform"&&E(!0)},children:[o?null:e.jsxs("header",{className:W("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!j&&"border-b border-border/70"),children:[e.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:e.jsx(ce,{name:"close",className:"size-5"})}),e.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[r?typeof r=="string"?e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:r}):r:null,i?typeof i=="string"?e.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:i}):i:null]}),l?e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:l}):null]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:P?e.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:R}):null}),e.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return f?We.createPortal(e.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:T?1:0,paddingLeft:b==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:b==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:n,children:e.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:w=>w.stopPropagation(),children:A})}),v.current):We.createPortal(A,v.current)},fr=t.lazy(()=>Me(()=>import("./FilesView-CjjPpE4c.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])).then(s=>({default:s.FilesView}))),hr=t.lazy(()=>Me(()=>import("./GitView-5fIq2nzM.js"),__vite__mapDeps([73,6,1,2,3,10,4,5,7,8,9,11,12,49,50,51,52,53,74,75,76,77,78,79,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,80,81,82,72,29,30])).then(s=>({default:s.GitView}))),pr=t.lazy(()=>Me(()=>import("./PullRequestsSurface-DPpb2RW_.js"),__vite__mapDeps([83,6,1,2,3,84,4,5,7,8,9,10,11,12,49,50,51,52,53,85,75,76,79,56,57,58,33,34,35,36,37,38,39,40,41,42,43,44,45,46,59,31,32,60,61,62,63,64,65,66,80,81,82,72,29,30])).then(s=>({default:s.PullRequestsSurface}))),mr=t.lazy(()=>Me(()=>import("./IssuesSurface-Dq5A_bWq.js"),__vite__mapDeps([86,1,2,3,84,4,5,6,7,8,9,10,11,12,49,50,51,52,53,85,75,76,87])).then(s=>({default:s.IssuesSurface}))),gt="mobile-surface-root",br=16,yt=t.memo(function({open:n,onClose:r,tab:i,onTabChange:l,pendingChangesDiff:a,variant:o="drawer",drawerRefExternal:j,scrimRefExternal:p,rootRefExternal:d,githubTabsAvailable:b=!1}){const R=t.useRef(null),v=t.useRef(null),T=t.useRef(null),y=t.useRef(null),P=j??v,E=p??T,N=d??y,C=t.useCallback(m=>{y.current=m,d&&(d.current=m)},[d]),h=t.useCallback(()=>{const m=typeof document<"u"?document.activeElement:null;m instanceof HTMLElement&&N.current?.contains(m)&&m.blur(),r()},[r]),[f,A]=t.useState(!1),[w,$]=t.useState(n),G=`mobile-workspace-tab-${t.useId()}`,B=t.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[_,M]=t.useState(()=>new Set),[g,L]=t.useState(null),[S,F]=t.useState(null);if(t.useEffect(()=>{n&&M(m=>{if(m.has(i))return m;const H=new Set(m);return H.add(i),H})},[n,i]),typeof document<"u"&&!R.current){let m=document.getElementById(gt);m||(m=document.createElement("div"),m.id=gt,document.body.appendChild(m)),R.current=m}if(t.useEffect(()=>{if(n){$(!0);const H=window.setTimeout(()=>A(!0),B?0:br);return()=>window.clearTimeout(H)}A(!1);const m=window.setTimeout(()=>$(!1),Ne+40);return()=>window.clearTimeout(m)},[n,B]),t.useEffect(()=>{if(!n)return;const m=document.body.style.overflow;o==="drawer"&&(document.body.style.overflow="hidden");const H=ne=>{ne.key==="Escape"&&i!=="terminal"&&h()};return document.addEventListener("keydown",H),()=>{o==="drawer"&&(document.body.style.overflow=m),document.removeEventListener("keydown",H)}},[h,n,i,o]),t.useEffect(()=>{const m=N.current;if(!m||n||o!=="drawer")return;const H=document.activeElement;H&&m.contains(H)&&H.blur()},[n,o]),Lt({side:"right",enabled:o==="drawer",open:n,drawerRef:P,scrimRef:E,onClose:h,widthRatio:1,prefersReducedMotion:B}),o==="drawer"&&!R.current)return null;const U=B?0:Ne,te=hn(b),x=B?{duration:0}:{type:"spring",stiffness:520,damping:40,mass:.8},k=e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 py-1 overflow-x-auto overflow-y-hidden scrollbar-none",role:"tablist","aria-label":"Workspace","data-no-drawer-swipe":"true",children:te.map(m=>{const H=i===m.id;return e.jsxs(He.button,{layout:"position",transition:x,type:"button",role:"tab","aria-selected":H,"aria-label":m.label,onClick:()=>l(m.id),className:W("relative flex min-h-[44px] items-center justify-center gap-1 rounded-lg py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",H?"min-w-0 shrink px-2.5 text-foreground":"size-11 shrink-0 text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[H?e.jsx(He.span,{layoutId:G,transition:x,className:"absolute inset-0 bg-interactive-selection",style:{borderRadius:8},"aria-hidden":"true"}):null,e.jsx(ce,{name:m.icon,className:"relative size-5 shrink-0"}),H?e.jsx(He.span,{initial:B?!1:{opacity:0,x:-4},animate:{opacity:1,x:0},transition:x,className:"relative truncate",children:m.label},m.id):null]},m.id)})}),K=e.jsxs(e.Fragment,{children:[o==="panel"?null:e.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2",children:[k,e.jsx("button",{type:"button",onClick:h,"aria-label":"Close workspace panel",className:"flex size-11 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/50",children:e.jsx(ce,{name:"close",className:"size-5"})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[_.has("changes")?e.jsx("div",{className:W("h-full",i!=="changes"&&"hidden"),children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(hr,{isActive:n&&i==="changes",chrome:"mobile",initialDiffPath:a?.path??null,initialDiffStaged:a?.staged===!0})})})},a?`changes:${a.path}:${a.staged}`:"changes"):null,_.has("files")?e.jsx("div",{className:W("h-full",i!=="files"&&"hidden"),children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(fr,{chrome:"mobile",mode:"editor-only",isVisible:n&&i==="files"})})})}):null,_.has("terminal")?e.jsx("div",{className:W("h-full",i!=="terminal"&&"hidden"),children:e.jsx(re,{children:e.jsx(pn,{visible:n&&i==="terminal"})})}):null,_.has("pull-requests")?e.jsx("div",{className:W("h-full",i!=="pull-requests"&&"hidden"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[e.jsx(ct,{icon:Le.find(m=>m.id==="pull-requests")?.icon,title:Le.find(m=>m.id==="pull-requests")?.label??"Pull requests",actions:e.jsx("div",{ref:m=>{L(m)},className:"flex items-center gap-1"})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(pr,{hideFilesTab:!0,headerActionsSlot:n&&i==="pull-requests"?g:null,headerActionsPresentation:"drawer"})})})})]})}):null,_.has("issues")?e.jsx("div",{className:W("h-full",i!=="issues"&&"hidden"),children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[e.jsx(ct,{icon:Le.find(m=>m.id==="issues")?.icon,title:Le.find(m=>m.id==="issues")?.label??"Issues",actions:e.jsx("div",{ref:m=>{F(m)},className:"flex items-center gap-1"})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(re,{children:e.jsx(t.Suspense,{fallback:null,children:e.jsx(mr,{headerActionsSlot:n&&i==="issues"?S:null,headerActionsPresentation:"drawer"})})})})]})}):null]})]});return o==="panel"?e.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:K}):We.createPortal(e.jsxs("div",{ref:C,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none",visibility:w?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[e.jsx("button",{ref:E,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:h,tabIndex:n?0:-1,style:{opacity:f?1:0,transition:U?`opacity ${U}ms ${be}`:"none"},"data-mobile-workspace-scrim":"true"}),e.jsx("section",{ref:P,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-full flex-col bg-sidebar",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:f?"none":"translateX(100%)",transition:U?`transform ${U}ms ${be}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:K})]}),R.current)}),xr="pichamber",gr=s=>s.replace(/^\/+|\/+$/g,""),yr=s=>{const n=gr(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...n]:n};function vr(s){if(typeof s!="string"||s.length===0)return null;let n;try{n=new URL(s)}catch{return null}if(n.protocol!==`${xr}:`)return null;const r=yr(n),i=(r[0]??"").toLowerCase(),l=r.slice(1),a=n.searchParams;switch(i){case"session":{const o=l[0]||a.get("id")||"";return o?{type:"session",sessionId:o,directory:a.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:a.get("dir")??void 0,projectId:a.get("project")??void 0,agent:a.get("agent")??void 0,model:a.get("model")??void 0};case"sessions":{const o=a.get("filter");return{type:"sessions",filter:o==="attention"||o==="recent"||o==="all"?o:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:l[0]||a.get("section")||void 0};case"changes":return{type:"changes",path:l.join("/")||a.get("path")||void 0,staged:a.get("staged")==="true"};case"view":{const o=(l[0]||"").toLowerCase();return o==="changes"?{type:"changes"}:o==="files"||o==="mcp"||o==="instances"||o==="update"?{type:"view",target:o}:null}default:return null}}let ee={},Ot=!1,De=null;const wr=s=>{switch(s.type){case"session":return ue.getState().setCurrentSession(s.sessionId,s.directory??null),!0;case"new-session":{const n=ue.getState();return n.openNewSessionDraft(),(s.directory||s.projectId)&&n.setNewSessionDraftTarget({directoryOverride:s.directory??null,projectId:s.projectId??null,selectedProjectId:s.projectId??null}),!0}case"sessions":return ee.openSessions?(ee.openSessions(s.filter),!0):!1;case"status":return ee.openSessions?(ee.openSessions(),!0):!1;case"view":return ee.openView?(ee.openView(s.target),!0):!1;case"changes":return ee.openChanges?(ee.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return ee.openSettings?(ee.openSettings(s.section),!0):!1}},Ze=()=>{if(!Ot||!De)return;const s=De;De=null,wr(s)||(De=s)},Sr=s=>{De=s,Ze()},jr=s=>{const n=vr(s);n&&Sr(n)},Rr=s=>{Ot=s,Ze()},kr=s=>{t.useEffect(()=>(ee=s,Ze(),()=>{ee===s&&(ee={})}),[s])},Er=s=>{const{ready:n}=s;t.useEffect(()=>{Rr(n)},[n]),t.useEffect(()=>{if(!Kt())return;let r=!1;const i=[];return Me(()=>import("./vendor-capacitor-app-NbQ-WiPS.js"),__vite__mapDeps([88,6,1,2,3])).then(async({App:l})=>{if(r)return;const a=await l.addListener("appUrlOpen",o=>{jr(o?.url)});if(r){a.remove();return}i.push(()=>{a.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(l=>l())}},[])},vt=s=>{const n=s.drawer.current,r=s.scrim.current,i=s.root.current;i&&(i.style.pointerEvents="auto",i.style.visibility="visible"),n&&(n.style.transition="none"),r&&(r.style.transition="none")},wt=(s,n,r)=>{const i=s.drawer.current,l=s.scrim.current;if(i&&(i.style.transform=r>=.999?"none":`translateX(${(n==="left"?r-1:1-r)*100}%)`),l){l.style.opacity=String(r);const a=r>.01?"auto":"none";l.style.pointerEvents!==a&&(l.style.pointerEvents=a)}},St=(s,n,r)=>{const i=r.drawer.current,l=r.scrim.current,a=r.root.current;i&&(i.style.transition=`transform ${Ne}ms ${be}`,i.style.transform=n?"none":s==="left"?"translateX(-100%)":"translateX(100%)"),l&&(l.style.transition=`opacity ${Ne}ms ${be}`,l.style.opacity=n?"1":"0",l.style.pointerEvents=n?"auto":"none"),a&&(a.style.pointerEvents=n?"auto":"none",a.style.visibility=n?"visible":"")},jt=s=>{const n=s.shell.current,r=s.inner.current;n&&(n.style.overflow="visible"),r&&(r.style.transition="none")},Rt=(s,n,r,i)=>{const l=s.inner.current;if(!l)return;const a=i==="left"?(n-1)*r:(1-n)*r;l.style.transform=n>=.999?"translateX(0)":`translateX(${a}px)`},kt=(s,n,r,i,l)=>{const a=s.shell.current,o=s.inner.current;return!a||!o?void 0:(o.style.transition="transform 200ms cubic-bezier(0.22, 1, 0.36, 1)",o.style.transform=n?"translateX(0)":`translateX(${i==="left"?-r:r}px)`,window.setTimeout(()=>{o.style.transition="",o.style.transform="",a.style.overflow=""},220))},Et=({side:s,isResizing:n,ariaLabel:r,handleProps:i})=>e.jsx("div",{className:W("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",s==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:e.jsx("div",{className:W("absolute inset-y-0 w-[3px] transition-colors",s==="left"?"right-0":"left-0",n&&"bg-[var(--interactive-border)]")})}),Cr=320,Nr=380,Ct=280,Tr=560,Ir=900;function Nt(s,n,r,i=Tr){const l=t.useRef(null),[a,o]=t.useState(()=>{if(typeof window>"u")return r;const h=Number.parseInt(window.localStorage.getItem(n)??"",10);return Number.isFinite(h)?Math.min(i,Math.max(Ct,h)):r}),[j,p]=t.useState(!1),d=t.useRef(0),b=t.useRef(a),R=t.useRef(null),v=t.useRef(null),T=t.useCallback(h=>Math.min(i,Math.max(Ct,Math.round(h))),[i]),y=t.useCallback(h=>{const f=l.current;f&&(f.style.width=`${h}px`,f.style.minWidth=`${h}px`,f.style.maxWidth=`${h}px`,f.style.setProperty("--oc-ipad-sidebar-width",`${h}px`))},[]),P=t.useCallback(h=>{try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}v.current=h.pointerId,d.current=h.clientX,b.current=a,R.current=a,p(!0),h.preventDefault()},[a]),E=t.useCallback(h=>{if(v.current!==h.pointerId)return;const f=h.clientX-d.current,A=T(b.current+(s==="left"?f:-f));R.current!==A&&(R.current=A,y(A))},[y,T,s]),N=t.useCallback(h=>{if(v.current!==h.pointerId)return;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const f=T(R.current??b.current);v.current=null,R.current=null,p(!1),o(f);try{window.localStorage.setItem(n,String(f))}catch{}},[T,n]),C=t.useMemo(()=>({onPointerDown:P,onPointerMove:E,onPointerUp:N,onPointerCancel:N}),[P,N,E]);return{asideRef:l,width:a,isResizing:j,handleProps:C}}const Pr=t.memo(Sn),Ar=({onActiveConnectionDeleted:s})=>{const[n,r]=t.useState(!1),[i,l]=t.useState(null),[a,o]=t.useState(!1),[j,p]=t.useState("changes"),d=t.useCallback(c=>{p(ut(c))},[]),b=j,[R,v]=t.useState("nav"),[T,y]=t.useState(null),P=t.useRef([]),E=t.useCallback(()=>{P.current.forEach(c=>window.clearTimeout(c)),P.current=[]},[]);t.useEffect(()=>()=>E(),[E]);const N=t.useRef(null),C=t.useRef(null),h=t.useRef(null),f=t.useRef(null),A=t.useRef(null),w=t.useRef(null),$=t.useRef(null),G=t.useRef(null),B=t.useRef(0),_=t.useRef(0),M=t.useCallback(c=>{E(),r(c)},[E]),g=t.useCallback(c=>{E(),o(c)},[E]),L=Ee(c=>c.setSettingsPage),S=Ee(c=>c.isArchivePageOpen),F=Ee(c=>c.setArchivePageOpen),U=Ce(c=>c.available),te=Ce(c=>c.runtimeType),x=t.useMemo(()=>_t(),[]),k=!x&&U&&(te==="desktop"||te==="web"),K=Kn()??"",m=K?Yt(K):"",H=Yn().github??null,ne=dt(c=>c.ensureScope);t.useEffect(()=>{!m||!H||ne(m,H)},[m,H,ne]);const xe=dt(c=>m?c.entriesByDirectory[m]??null:null),Te=t.useMemo(()=>qn(xe),[xe]),ie=Qn(Te);t.useEffect(()=>{!ie&&mn(j)&&p(bn(j))},[ie,j]);const fe=t.useCallback(()=>{l(null)},[]),X=t.useCallback(c=>{l(c)},[]),je=t.useCallback(()=>{g(!1)},[g]),ge=t.useCallback(c=>{v(c),X("settings")},[X]),{enabled:D,roomyForPanels:se}=Jn(),I=Zn()==="portrait",V=es(),O=Ee(c=>c.setSidebarOpen),z=Ee(c=>c.isSidebarOpen),J=t.useRef(!1);t.useLayoutEffect(()=>{D&&!J.current&&O(ts().roomyForPanels),!D&&J.current&&O(!1),J.current=D},[D,O]);const Re=t.useCallback(()=>{y(null),d("files"),g(!0)},[d,g]),ae=t.useCallback((c=null)=>{y(c),d("changes"),g(!0)},[d,g]),Y=Nt("left","pichamber.ipad.leftSidebarWidth",Cr),q=Nt("right","pichamber.ipad.rightSidebarWidth",Nr,Ir),ye=se,Z=ye&&a?q.width:0,Wt=xn(D&&z),Ie=D&&z?Y.width:0,Ut=t.useCallback(c=>{const Q=ut(c);a&&b===Q?g(!1):(d(Q),g(!0))},[a,b,d,g]),Bt=t.useCallback(()=>{g(!a)},[a,g]),Ht=t.useCallback(c=>{!c&&!se&&O(!1)},[se,O]);t.useEffect(()=>{if(typeof document>"u")return;const c=document.documentElement;return c.style.setProperty("--oc-chat-inset-left",`${Ie}px`),c.style.setProperty("--oc-chat-inset-right",`${Z}px`),()=>{c.style.removeProperty("--oc-chat-inset-left"),c.style.removeProperty("--oc-chat-inset-right")}},[Ie,Z]),t.useEffect(()=>{if(typeof document>"u")return;const c=D&&(I||V),Q=document.documentElement;return Q.classList.toggle("oc-keep-draft-starters",c),()=>Q.classList.remove("oc-keep-draft-starters")},[V,D,I]);const et=t.useCallback(()=>{M(!1),g(!1)},[M,g]),$t=t.useMemo(()=>({openChanges:({diffPath:c,staged:Q}={})=>{ae(c?{path:c,staged:Q===!0}:null)},openFiles:()=>Re(),openSettings:c=>{c&&L(c),ge(c?"page-content":"nav")},openInstances:x?()=>X("instances"):void 0,instanceLabel:x?ve():null,openUpdate:k?()=>X("update"):void 0,closeDrawers:et}),[et,ae,Re,ge,X,L,x,k]),Ft=t.useMemo(()=>({openSessions:()=>{D?O(!0):M(!0)},openView:c=>{if(c==="files"){Re();return}(c==="instances"||c==="update"||c==="mcp")&&X(c)},openChanges:({path:c,staged:Q}={})=>{ae(c?{path:c,staged:Q===!0}:null)},openSettings:c=>{c&&L(c),ge(c?"page-content":"nav")}}),[D,ae,Re,ge,X,L,M,O]);kr(Ft);const tt=t.useRef(null);gn(tt,{leftOpen:D?z:n,rightOpen:a,leftWidth:()=>D?Y.width:N.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>D?q.width:f.current?.offsetWidth||window.innerWidth,onLeftProgress:c=>{if(B.current=c,D){Rt({inner:$},c,Y.width,"left");return}wt({drawer:N,scrim:C},"left",c)},onRightProgress:c=>{if(_.current=c,D&&se){Rt({inner:G},c,q.width,"right");return}wt({drawer:f,scrim:A},"right",c)},onLeftOpen:()=>{D?O(!0):M(!0)},onLeftClose:()=>{D?O(!1):M(!1)},onRightOpen:()=>g(!0),onRightClose:()=>g(!1),onDragStart:c=>{if(E(),c==="left"){B.current=D?z?1:0:n?1:0,D?jt({shell:Y.asideRef,inner:$}):vt({drawer:N,scrim:C,root:h});return}_.current=a?1:0,D&&se?jt({shell:q.asideRef,inner:G}):vt({drawer:f,scrim:A,root:w})},onDragEnd:(c,Q)=>{if(c==="left"){const ke=typeof Q=="boolean"?Q:B.current>.5;if(B.current=ke?1:0,D){const nt=kt({shell:Y.asideRef,inner:$},ke,Y.width,"left");nt!==void 0&&P.current.push(nt)}else St("left",ke,{drawer:N,scrim:C,root:h});return}const Be=typeof Q=="boolean"?Q:_.current>.5;if(_.current=Be?1:0,D&&se){const ke=kt({shell:q.asideRef,inner:G},Be,q.width,"right");ke!==void 0&&P.current.push(ke)}else St("right",Be,{drawer:f,scrim:A,root:w})}});const Vt=t.useCallback(()=>S?(F(!1),!0):i?(fe(),!0):a?(je(),!0):n?(M(!1),!0):!1,[i,fe,je,S,n,F,M,a]);At(Vt);const Ue=D?"dialog":"fullscreen";return e.jsx(ns,{actions:$t,children:e.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:[D?e.jsxs("aside",{ref:Y.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!z&&"border-r-0"),style:{width:Ie,minWidth:Ie,maxWidth:Ie,"--oc-ipad-sidebar-width":`${Y.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!z,"data-page-scroll-lock":"true",children:[e.jsx("div",{ref:$,className:W("flex h-full shrink-0 flex-col",Y.isResizing&&"pointer-events-none",!z&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:Y.isResizing||Wt.slidIn?"translateX(0)":"translateX(-100%)",transition:Y.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:e.jsx(re,{children:e.jsx(bt,{open:z,variant:"sidebar",onOpenChange:Ht})})}),z?e.jsx(Et,{side:"left",isResizing:Y.isResizing,ariaLabel:"Resize left panel",handleProps:Y.handleProps}):null]}):null,e.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[D?e.jsxs(e.Fragment,{children:[e.jsx(yn,{}),e.jsx(vn,{onToggleRightDrawer:Bt,rightDrawerOpen:a,tabletWorkspaceTab:b,onSelectTabletWorkspaceTab:Ut,tabletGitHubTabsAvailable:ie})]}):e.jsx(lr,{onOpenSessions:()=>M(!0),onOpenWorkspace:()=>g(!0)}),e.jsx("main",{ref:tt,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:e.jsx("div",{className:"h-full w-full",children:e.jsx(re,{children:e.jsx(Pr,{})})})})]}),D?null:e.jsx(bt,{open:n,onOpenChange:M,drawerRefExternal:N,scrimRefExternal:C,rootRefExternal:h}),D?e.jsxs("aside",{ref:q.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!Z&&"border-l-0"),style:{width:Z,minWidth:Z,maxWidth:Z,"--oc-ipad-sidebar-width":`${q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!Z,"data-page-scroll-lock":"true",children:[e.jsx("div",{ref:G,className:W("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",q.isResizing&&"pointer-events-none",!Z&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:Z?"translateX(0)":"translateX(100%)",transition:q.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:e.jsx(re,{children:e.jsx(yt,{open:a,onClose:je,tab:b,onTabChange:d,pendingChangesDiff:T,variant:ye?"panel":"drawer",githubTabsAvailable:ie,drawerRefExternal:f,scrimRefExternal:A,rootRefExternal:w})})}),Z?e.jsx(Et,{side:"right",isResizing:q.isResizing,ariaLabel:"Resize right panel",handleProps:q.handleProps}):null]}):e.jsx(yt,{open:a,onClose:je,tab:b,onTabChange:d,pendingChangesDiff:T,githubTabsAvailable:ie,drawerRefExternal:f,scrimRefExternal:A,rootRefExternal:w}),i==="instances"&&x?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Servers",title:"Servers",children:e.jsx(cr,{onConnect:fe,onActiveConnectionDeleted:s})}):null,i==="settings"?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Settings",headerless:!0,children:e.jsx(re,{children:e.jsx(zs,{forceMobile:!D,isWindowed:!0,initialMobileStage:R,onClose:fe,onActiveConnectionDeleted:s})})}):null,i==="update"?e.jsx(Ke,{open:!0,variant:Ue,dialogAlign:"app",onClose:fe,ariaLabel:"Update",title:"Update",children:e.jsx(re,{children:e.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:e.jsx(Ws,{initialUpdateDialogOpen:!0})})})}):null,e.jsx(re,{children:e.jsx(wn,{})})]})})},Dr=8,zt=6e4,_r=6e4,Ye=[1e3,2e3,4e3,8e3,15e3,3e4,3e4,3e4],Mr=(s,n)=>{if(n?.offline||n?.hidden)return zt;if(s<=0)return Ye[0];const r=Math.min(s-1,Ye.length-1);return Ye[r]??3e4},oe=()=>typeof navigator<"u"&&typeof navigator.onLine=="boolean"?!navigator.onLine:!1,le=()=>typeof document<"u"&&typeof document.visibilityState=="string"?document.visibilityState==="hidden":!1;class Lr{constructor(n,r,i=()=>""){this.probe=n,this.callbacks=r,this.getRuntimeIdentity=i}probe;callbacks;getRuntimeIdentity;generation=0;attempt=0;timer=null;wakeCleanup=null;running=!1;exhausted=!1;probingGeneration=null;get currentGeneration(){return this.generation}get currentAttempt(){return this.attempt}get isRunning(){return this.running&&!this.exhausted}start(){he("recovery",{code:"start"}),this.startCycle(!1)}startCycle(n){this.clearTimer(),this.generation+=1,this.attempt=0,this.exhausted=!1,this.running=!0,n?this.runAttempt(this.generation):this.scheduleNext(this.generation)}retryNow(){if(this.exhausted){if(oe()||le())return;this.startCycle(!0);return}this.running&&(this.clearTimer(),this.runAttempt(this.generation))}cancel(){he("recovery",{code:"cancel"}),this.generation+=1,this.running=!1,this.exhausted=!1,this.attempt=0,this.probingGeneration=null,this.clearTimer()}async probeOnce(){return this.running||this.exhausted||this.probingGeneration!==null||oe()||le()?null:this.runGuardedProbe(this.generation)}async runGuardedProbe(n){this.probingGeneration=n;const r=this.getRuntimeIdentity();let i;try{i=await this.probe()}catch{i="unreachable"}finally{this.probingGeneration===n&&(this.probingGeneration=null)}return n!==this.generation||this.getRuntimeIdentity()!==r?null:i}settleTerminalOutcome(n){return n==="unreachable"?!1:(this.running=!1,this.exhausted=!1,this.clearTimer(),n==="needs-login"?this.callbacks.onAuthExpired():n==="no-connection"?this.callbacks.onNoConnection():this.callbacks.onHealthy(n),!0)}clearTimer(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.wakeCleanup&&(this.wakeCleanup(),this.wakeCleanup=null)}scheduleNext(n){if(n!==this.generation||!this.running||this.exhausted)return;if(this.attempt>=Dr){this.exhausted=!0,this.running=!1,this.callbacks.onExhausted(),this.scheduleExhaustedPoll(n);return}const r=this.attempt+1,i=Mr(r,{offline:oe(),hidden:le()});this.callbacks.onAttempt?.(r,i);const l=()=>{oe()||le()||n===this.generation&&(this.clearTimer(),this.runAttempt(n))},a=()=>l(),o=()=>{typeof document<"u"&&document.visibilityState==="visible"&&l()};typeof window<"u"&&window.addEventListener("online",a),typeof document<"u"&&document.addEventListener("visibilitychange",o),this.wakeCleanup=()=>{typeof window<"u"&&window.removeEventListener("online",a),typeof document<"u"&&document.removeEventListener("visibilitychange",o)},this.timer=setTimeout(()=>{if(this.timer=null,this.wakeCleanup?.(),this.wakeCleanup=null,!(n!==this.generation||!this.running||this.exhausted)){if(oe()||le()){this.scheduleNext(n);return}this.runAttempt(n)}},i)}async runAttempt(n){if(n!==this.generation||!this.running||this.exhausted||this.probingGeneration===n)return;if(oe()||le()){this.scheduleNext(n);return}const r=await this.runGuardedProbe(n);r===null||this.settleTerminalOutcome(r)||(this.attempt+=1,this.scheduleNext(n))}scheduleExhaustedPoll(n){if(n!==this.generation||!this.exhausted)return;this.clearTimer();const r=oe()||le()?zt:_r;this.timer=setTimeout(()=>{this.timer=null,this.runExhaustedPoll(n)},r)}async runExhaustedPoll(n){if(n!==this.generation||!this.exhausted)return;if(this.probingGeneration!==null||oe()||le()){this.scheduleExhaustedPoll(n);return}const r=await this.runGuardedProbe(n);r===null||!this.exhausted||this.settleTerminalOutcome(r)||this.scheduleExhaustedPoll(n)}}function Or({state:s,label:n,onRetry:r,onUseAnotherServer:i}){const l=n.trim()||"the server";return e.jsx("div",{role:"status","aria-live":"polite",className:"pointer-events-none fixed inset-x-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px)+10px)] z-40 flex justify-center px-4",children:s==="reconnecting"?e.jsxs("span",{className:"flex max-w-full items-center gap-2 rounded-full border border-border/70 bg-[var(--surface-elevated)] py-1.5 pl-2 pr-3 text-[var(--surface-elevated-foreground)] shadow-sm",children:[e.jsx(we,{width:20,height:20,isAnimated:!0}),e.jsx("span",{className:"truncate typography-ui-label",children:`Reconnecting to ${l}…`})]}):e.jsxs("div",{className:"pointer-events-auto flex w-full max-w-sm flex-col gap-3 rounded-xl border border-border/70 bg-[var(--surface-elevated)] p-3 text-[var(--surface-elevated-foreground)] shadow-sm",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"truncate typography-ui-label font-medium",children:`Can't reach ${l}`}),e.jsx("p",{className:"typography-meta text-muted-foreground [text-wrap:pretty]",children:"Its address may only work on another network. Still retrying in the background."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Se,{type:"button",variant:"ghost",size:"sm",onClick:i,children:"Use another server"}),e.jsx(Se,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Retry"})]})]})})}function zr(s=2500){const{uiFont:n}=ss(),[r,i]=t.useState(!1);return t.useEffect(()=>{let l=!1;const a=()=>{l||i(!0)},o=()=>{requestAnimationFrame(()=>requestAnimationFrame(a))},j=Promise.all([rs(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),Vs.catch(()=>{})]).then(()=>{}),p=new Promise(d=>{window.setTimeout(d,s)});return Promise.race([j,p]).then(o),()=>{l=!0}},[n,s]),r}const Wr=1e3,Ur=2;function Br({apis:s}){const n=pe(u=>u.initializeApp),r=pe(u=>u.isInitialized),i=pe(u=>u.isConnected),l=pe(u=>u.connectionPhase),a=pe(u=>u.providers.length),o=pe(u=>u.loadProviders),j=Je(u=>u.currentDirectory),p=ue(u=>u.error),d=ue(u=>u.clearError),b=Ee(u=>u.setIsMobile),[R,v]=t.useState(0),[T,y]=t.useState(0),[P,E]=t.useState(!1),[N,C]=t.useState("idle"),[h,f]=t.useState(0),A=is(),w=t.useRef(null),$=t.useRef(N);$.current=N;const[G,B]=t.useState("pending"),[_,M]=t.useState(null),g=t.useMemo(()=>ve(),[]),[,L]=t.useReducer(u=>u+1,0),S=t.useMemo(()=>_t(),[]),F=t.useRef(0),U=t.useRef(0),te=t.useRef(!1),[x,k]=t.useState(()=>S&&!!de());t.useEffect(()=>{const u=new Lr(()=>Us(),{onHealthy:I=>{if(he("recovery",{code:"success"}),C("idle"),f(0),me(!1),I==="unchanged"){Zt(),pe.getState().initializeApp();const V=pe.getState();V.providers.length===0&&V.loadProviders({source:"mobileApp:recovery"})}},onAuthExpired:()=>{he("recovery",{code:"auth-expired"}),C("idle"),f(0),me(!1),M({kind:"auth-expired",label:ve()??""}),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),v(I=>I+1)},onNoConnection:()=>{he("recovery",{code:"no-connection"}),C("idle"),f(0),me(!1),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),v(I=>I+1)},onExhausted:()=>{he("recovery",{code:"exhausted"}),C("exhausted")},onAttempt:I=>{he("recovery",{code:"attempt",detail:String(I)}),f(I)}},()=>`${Ae()}|${de()}`);return w.current=u,()=>{u.cancel(),w.current=null}},[]);const K=t.useCallback(()=>{if(!S||!de())return;const u=w.current;if(u){if(u.isRunning){u.retryNow();return}C("recovering"),f(0),me(!0),u.start()}},[S]),m=t.useCallback(()=>{w.current?.cancel(),C("idle"),f(0),me(!1),k(!1)},[]),H=t.useCallback(()=>{const u=w.current;if(u){if(u.isRunning){f(0),u.retryNow();return}$.current!=="exhausted"||oe()||(C("recovering"),f(0),me(!0),u.retryNow())}},[]),ne=t.useCallback(u=>{m(),u&&M(u),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),v(I=>I+1)},[m]),xe=t.useCallback(()=>{const u=Date.now();u-F.current>=Wr&&(F.current=u,window.dispatchEvent(new Event("pichamber:system-resume")))},[]),Te=t.useCallback(()=>{const u=de(),I=U.current+1;if(U.current=I,!u){if(te.current)return;te.current=!0,Ve().catch(()=>{}).finally(()=>{te.current=!1});return}if(w.current?.isRunning){w.current.retryNow(),xe();return}if($.current==="exhausted"){if(oe()||le())return;C("recovering"),f(0),me(!0),w.current?.start(),xe();return}if(oe()||le()){K();return}const V=()=>{n(),a===0&&o({source:"mobileApp:nativeResume"})},O=w.current;O&&(O.probeOnce().then(z=>{if(z!==null&&U.current===I){if(z==="no-connection"){ne(null);return}if(z==="needs-login"){ne({kind:"auth-expired",label:ve()??""});return}if(z==="unreachable"){K();return}z!=="switched"&&V()}}),xe())},[ne,xe,n,o,a,K]);as(),os(Te),t.useEffect(()=>qt(),[]),t.useEffect(()=>{if(!S)return;let u;const I=()=>{if(w.current?.isRunning){w.current.retryNow();return}if($.current==="exhausted"){if(le())return;C("recovering"),f(0),me(!0),w.current?.start();return}window.clearTimeout(u),u=window.setTimeout(()=>Te(),1500)};return window.addEventListener("online",I),()=>{window.removeEventListener("online",I),window.clearTimeout(u)}},[S,Te]),t.useEffect(()=>{if(S)return Qt(()=>{de()&&ne({kind:"auth-expired",label:ve()??""})})},[ne,S]),t.useEffect(()=>(rt(s),()=>rt(null)),[s]),t.useEffect(()=>Jt(u=>{if(!!u.runtimeKey&&u.runtimeKey===u.previousRuntimeKey){jn(),L();return}m(),Rn(u),y(V=>V+1),v(V=>V+1)}),[m]),t.useEffect(()=>{Tt()},[T]),t.useEffect(()=>{if(!S||i||de()){B("done");return}let u=!1;return B("attempting"),Ve().catch(()=>({status:"no-candidate"})).then(I=>{u||(he("auto-connect",{code:I.status}),I.status==="unreachable"?M({kind:"unreachable",label:I.label}):I.status==="needs-login"&&M({kind:"auth-expired",label:I.label}),B("done"))}),()=>{u=!0}},[]),t.useEffect(()=>{if(!S||!de()){k(!1);return}let u=!1;const I=O=>{O&&M(O),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),v(z=>z+1)},V=w.current;if(!V){k(!1);return}return(async()=>{try{const O=await V.probeOnce();if(u||O===null||O==="switched"||O==="unchanged")return;const z=ve();if(O==="needs-login"){I({kind:"auth-expired",label:z??""});return}if(O==="unreachable"){K();return}const J=await Ve().catch(()=>({status:"no-candidate"}));if(u||(he("auto-connect",{code:J.status}),J.status==="connected"))return;J.status==="needs-login"?I({kind:"auth-expired",label:J.label}):J.status==="unreachable"?I({kind:"unreachable",label:J.label}):I(null)}finally{u||k(!1)}})(),()=>{u=!0,k(!1)}},[K]),t.useEffect(()=>{b(!0)},[b]),t.useEffect(()=>{S&&!de()||n()},[R,n,S]),t.useEffect(()=>{i&&a===0&&o({source:"mobileApp:recovery"})},[i,o,a]);const ie=t.useRef(!1),[fe,X]=t.useState(S);t.useEffect(()=>{if(!S||!i||ie.current)return;if(ue.getState().currentSessionId){ie.current=!0,X(!1);return}const u=Ae(),I=ls(u);if(!I){ie.current=!0,X(!1);return}const V=Qe(I.directory??null);if(!V){ie.current=!0,X(!1);return}const O=_e();let z=0;try{z=O.getRuntimeGeneration()}catch{z=0}let J=!1;const Re=window.setTimeout(()=>X(!1),6e3);return(async()=>{let ae=null;try{ae=await cs([V])}catch{ae=null}if(J)return;if(!ae){X(!1);return}const Y=_e();let q=z;try{q=Y.getRuntimeGeneration()}catch{q=z}const ye=tr({persisted:I,persistedDirectory:V,stale:ae.stale,ready:ae.readyDirectories.has(V),catalog:ae.catalog,runtimeKey:Ae(),capturedRuntimeKey:u,storeIdentityMatches:Y===O,generationMatches:q===z});if(ye.action==="wait"){X(!1);return}if(ie.current=!0,ye.action==="clear"){us(u),X(!1);return}const Z=ue.getState();if(Ae()!==u||_e()!==O){X(!1);return}Z.currentSessionId||Z.setCurrentSession(ye.sessionId,ye.directory),X(!1)})(),()=>{J=!0,window.clearTimeout(Re)}},[R,i,S]),nr(j,i),t.useEffect(()=>{if(!p)return;const u=window.setTimeout(()=>d(),5e3);return()=>window.clearTimeout(u)},[d,p]),t.useEffect(()=>{if(S&&N!=="idle"){E(!1);return}if(S&&x){E(!1);return}if(!(!i&&(S?!!de():!0))){E(!1);return}const I=window.setTimeout(()=>{E(!0)},S?4e3:8e3);return()=>window.clearTimeout(I)},[i,S,R,N,T,x]),ds(),kn(),Er({ready:S&&i&&r});const je=zr(),ge=!i&&l==="reconnecting",D=!!de(),se=S&&D&&N!=="idle";return t.useEffect(()=>{se&&X(!1)},[se]),je?S&&!se&&(!D||!i&&!ge)?D?e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[e.jsx(we,{width:120,height:120,isAnimated:!P}),P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),e.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another server."})]}),e.jsx(Se,{type:"button",variant:"outline",onClick:()=>{ne(null)},children:"Use another server"})]}):null]})}):G!=="done"?e.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[e.jsx(we,{width:120,height:120,isAnimated:!0}),g?e.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[e.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),e.jsx("div",{className:"flex justify-center",children:e.jsx(fs,{text:g,showElapsed:!1})})]}):null]}):e.jsx(e.Fragment,{children:e.jsx(sr,{onConnected:()=>v(u=>u+1),notice:_})}):!S&&!i&&!ge?P?e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:e.jsxs("div",{className:"max-w-sm space-y-3",children:[e.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),e.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."})]})}):e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:e.jsx(we,{width:120,height:120,isAnimated:!0})}):e.jsx(re,{children:e.jsx(hs,{children:e.jsxs(ps,{apis:s,children:[e.jsx(ms,{}),e.jsx(bs,{}),e.jsx(En,{}),e.jsx(xs,{}),e.jsx(gs,{}),e.jsx(ys,{delayDuration:300,skipDelayDuration:150,children:e.jsxs(Cn,{children:[e.jsx(Nn,{}),e.jsxs("div",{className:"h-full bg-background text-foreground",children:[S&&fe&&i&&!se?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:e.jsx(we,{width:120,height:120,isAnimated:!0})}):null,e.jsx(vs,{embeddedBackgroundWorkEnabled:r&&!A}),se?e.jsx(Or,{state:N==="exhausted"||h>=Ur?"unreachable":"reconnecting",label:ve()??"",onRetry:H,onUseAnotherServer:()=>ne(null)}):null,e.jsx(er,{}),e.jsx(Ar,{onActiveConnectionDeleted:()=>{m(),Pe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),v(u=>u+1)}}),e.jsx(Tn,{}),e.jsx(In,{}),e.jsx(ws,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),e.jsx(Ss,{})]})]})})]})},T)}):e.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:e.jsx(we,{width:120,height:120,isAnimated:!0})})}const Hr=()=>{(async()=>{try{await Promise.all([Tt(),nn()])}catch(s){console.error("[mobile-main] settings init failed:",s)}Cs(),Ns(),Ts(),sn()})().finally(()=>{Gs()})};function hi(s){window.__PICHAMBER_SURFACE__="mobile",js(),Hr(),Zs(),Rs();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");const i=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",l=s??en();if(!l)throw new Error("Runtime APIs not registered");const a=i?{...l,notifications:{notify:async()=>!1,canNotify:()=>!1}}:l,o=e.jsx(Br,{apis:a});Gt.createRoot(n).render(e.jsx(qe.StrictMode,{children:e.jsx(ks,{children:e.jsx(Pn,{children:i?o:e.jsx(Es,{children:o})})})}))}export{hi as renderMobileApp};