@pi-chamber/web 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DiagramView-0Iq1ak1I.js → DiagramView-BvrCkm_z.js} +1 -1
- package/dist/assets/{DiffView-DD1AFRi3.js → DiffView-DMvRLRN1.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-CoKwDovb.js → FileSaveConflictDialog-DGa9u43J.js} +1 -1
- package/dist/assets/{FilesView-B_BF39ef.js → FilesView-CNHu4RnC.js} +4 -4
- package/dist/assets/{GitView-LFEpCasf.js → GitView-Cbepz-bR.js} +3 -3
- package/dist/assets/{JsonTreeView-Cwjgvh4g.js → JsonTreeView-C2X5oXQm.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-_7kV1yNw.js → MarkdownRendererImpl-BanSCkPy.js} +2 -2
- package/dist/assets/{PatchDiff-DG43C1HW.js → PatchDiff-i_9BIlgo.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-DCFXPY3d.js → SessionSwitcherContent-DxS_rFuS.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-QY7FKuEQ.js → SessionSwitcherDropdown-AVghToww.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DGT31A3z.js → SessionUnreadDot-CDRZswx-.js} +1 -1
- package/dist/assets/SettingsView-hyAGp836.js +2 -0
- package/dist/assets/SettingsWindow-BfPUzBbq.js +1 -0
- package/dist/assets/{ToolOutputDialog-IlCrS6BR.js → ToolOutputDialog-CJ87b80H.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-D68JV0rR.js → ToolPartDiffPreview-bF486Lz1.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Bl-rAYeh.js → VirtualizedFileDiff-CFpvcZ1g.js} +1 -1
- package/dist/assets/{collapsible-BjniCdZ5.js → collapsible-DesjbW8a.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-FSOm2VrW.js → computeVirtualFileMetrics-CsAu9rOt.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-Bxb6AIPa.js → contextFileOpenGuard-rILslsBJ.js} +1 -1
- package/dist/assets/{gitStatusPredicates-DxolDpMd.js → gitStatusPredicates-D_31YElh.js} +1 -1
- package/dist/assets/index-BXgR2dKM.css +1 -0
- package/dist/assets/index-BZpvAhrX.js +8 -0
- package/dist/assets/{index-Dh58uD3I.js → index-CXLVW_GG.js} +1 -1
- package/dist/assets/{isDiffPlainText-D3_04XCh.js → isDiffPlainText-BX609Lau.js} +1 -1
- package/dist/assets/{isFilePlainText-CHouYQhH.js → isFilePlainText-FgBWqu9b.js} +1 -1
- package/dist/assets/{main-CH3EqGJI.js → main-C_pL2r_k.js} +2 -2
- package/dist/assets/{main-HzTrVvbB.js → main-tv2uysSs.js} +7 -7
- package/dist/assets/{markdownCore-DJU4KvHP.js → markdownCore-D3Ibaffd.js} +1 -1
- package/dist/assets/{miniChat-Ca3TpaaA.js → miniChat-B0xQlBzZ.js} +2 -2
- package/dist/assets/{mobile-lj4gpGsO.js → mobile-BmSlVuhn.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-C4xZzAnn.js +2 -0
- package/dist/assets/renderMobileApp-Bi8wTGd5.js +11 -0
- package/dist/assets/runtimeEndpointReset-B6_gFvBD.js +53 -0
- package/dist/assets/{runtimeSurface-CE_VNjdH.js → runtimeSurface-egSD9pqj.js} +1 -1
- package/dist/assets/{useAppFontEffects-BvFAP9zG.js → useAppFontEffects-C9QQrBIx.js} +104 -104
- package/dist/assets/{useFilesViewSearch-BD79p3A2.js → useFilesViewSearch-BTZutbn-.js} +2 -2
- package/dist/assets/{usePushVisibilityBeacon-CWg0j-Wg.js → usePushVisibilityBeacon-BZcHxSo-.js} +1 -1
- package/dist/assets/useSwitcherItems-Dw5tHQh8.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-CP3j3-xu.js → vendor-codemirror-language-data-0f_rLdj_.js} +2 -2
- package/dist/assets/{web-components-DWuadqra.js → web-components-CYngz9Ml.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +17 -3
- package/server/lib/client-auth/DOCUMENTATION.md +184 -0
- package/server/lib/client-auth/live-revocation.test.js +567 -0
- package/server/lib/client-auth/principal-tracker.js +383 -0
- package/server/lib/client-auth/principal-tracker.test.js +321 -0
- package/server/lib/client-auth/remote-clients.js +31 -0
- package/server/lib/client-auth/remote-clients.test.js +44 -0
- package/server/lib/pi/event-stream.js +269 -0
- package/server/lib/pi/event-stream.test.js +776 -0
- package/server/lib/pi/routes.js +76 -25
- package/server/lib/pi/routes.test.js +48 -4
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -4
- package/server/lib/pi/session-daemon/ipc-client.js +19 -15
- package/server/lib/pi/session-daemon/ipc-client.test.js +113 -1
- package/server/lib/pi/session-daemon/session-daemon-epoch.test.js +349 -0
- package/server/lib/pi/session-daemon/session-daemon.js +55 -6
- package/server/lib/pi/session-daemon/session-daemon.test.js +10 -4
- package/server/lib/pi/session-daemon/session-replay.test.js +8 -3
- package/server/lib/pi/session-daemon/supervisor.js +30 -5
- package/server/lib/pi/session-daemon/supervisor.test.js +4 -3
- package/server/lib/pi/ui-settings-store.js +1 -1
- package/server/lib/pi/ui-settings-store.test.js +3 -1
- package/server/lib/server/core-routes.js +11 -1
- package/server/lib/stt/DOCUMENTATION.md +2 -0
- package/server/lib/stt/runtime.js +39 -2
- package/server/lib/stt/runtime.test.js +53 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +48 -2
- package/server/lib/terminal/runtime.test.js +35 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +13 -4
- package/server/lib/ui-auth/ui-auth.js +98 -0
- package/server/lib/ui-auth/ui-auth.test.js +249 -0
- package/server/lib/workspace/host.js +3 -1
- package/dist/assets/SettingsView-eG-wN-yY.js +0 -2
- package/dist/assets/SettingsWindow-Dvnp8YrA.js +0 -1
- package/dist/assets/index-BpmGBboM.css +0 -1
- package/dist/assets/index-DZnzXhTs.js +0 -8
- package/dist/assets/renderElectronMiniChatApp-rUFfaD-T.js +0 -2
- package/dist/assets/renderMobileApp-CcWQ1sCf.js +0 -11
- package/dist/assets/runtimeEndpointReset-D2MmSbDk.js +0 -53
- package/dist/assets/useSwitcherItems-CazJ6Yox.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-QY7FKuEQ.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-BvFAP9zG.js","assets/index-DZnzXhTs.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BpmGBboM.css","assets/vendor-base-ui-CdaWtC7e.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-CE_VNjdH.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-CP3j3-xu.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-CNlncqrr.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,R as a,r as me,e as ye}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{m as K,n as J,Z as ge,z as Z,u as ie,aH as U,N as we,R as ve,v as le,q as je,x as be}from"./index-DZnzXhTs.js";import{u as Se,a as Ie,s as Ce}from"./usePushVisibilityBeacon-CWg0j-Wg.js";import{bE as Ne,I as V,aQ as De,a1 as Pe,a2 as Me,a4 as Ee,bF as ke,bG as _e,f as j,b0 as Le,a as ae,y as P,am as ce,bH as Oe,a9 as Te,aw as Re,bt as Ae,bh as Be,B as de,bx as Fe,bI as ue,bJ as ze,t as Ue,g as $e,H as We,E as He,K as Ge,R as Ke,W as Ve,T as Je,L as Qe,M as qe,bK as Xe,bu as Ze,Q as Ye,U as et,V as tt,X as rt}from"./useAppFontEffects-BvFAP9zG.js";import{_ as st}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-CdaWtC7e.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-CE_VNjdH.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CP3j3-xu.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";const nt=({mode:t,children:s})=>e.jsx(Ne.Provider,{value:t,children:s}),ot=ke,it=_e,at=({totalTokens:t,percentage:s,colorPercentage:n,contextLimit:c,outputLimit:i,size:u="default",isMobile:l=!1,hideIcon:D=!1,showPercentIcon:k=!1,className:f,valueClassName:p,percentIconClassName:_,onClick:M,pressed:O=!1,cacheRead:x,cacheWrite:C,cacheHitPercent:h})=>{const[b,o]=a.useState(!1),g=typeof n=="number"?n:s,m=ot(s)??0,y=it(g),Q=y==="critical"?"var(--status-error)":y==="warn"?"var(--status-warning)":"var(--status-success)",w=I=>I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toFixed(1).replace(/\.0$/,""),N=I=>I>=90?"text-status-error":I>=75?"text-status-warning":"text-status-success",E=20,$=3,W=(E-$)/2,se=2*Math.PI*W,q=se*(1-m/100),R=typeof i=="number"?Math.max(i,0):0,A=typeof x=="number"&&typeof C=="number",Y=A?Math.max(0,x):0,B=A?Math.max(0,C):0,L=typeof h=="number"&&Number.isFinite(h),T=[`Used tokens: ${w(t)}`,`Context limit: ${w(c)}`,`Output limit: ${w(R)}`,...A?[`Cache read: ${w(Y)}`,`Cache write: ${w(B)}`]:[],...L?[`Cache hit: ${h.toFixed(1)}%`]:[],`${Math.min(s,999).toFixed(1)}% used`],F=!l&&typeof M=="function",v=e.jsxs(e.Fragment,{children:[!l&&!D&&e.jsx(V,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:K("font-medium inline-flex items-center gap-1.5",p),children:k?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${E} ${E}`,className:K("h-3.5 w-3.5 -rotate-90",_),role:"progressbar","aria-valuenow":Math.round(m),"aria-valuemin":0,"aria-valuemax":100,children:[e.jsx("circle",{cx:E/2,cy:E/2,r:W,fill:"none",stroke:"var(--interactive-border)",strokeWidth:$}),e.jsx("circle",{cx:E/2,cy:E/2,r:W,fill:"none",stroke:Q,strokeWidth:$,strokeLinecap:"round",strokeDasharray:se,strokeDashoffset:q,className:"transition-[stroke-dashoffset,stroke] duration-300"})]}),e.jsxs("span",{className:"text-foreground",children:[Math.min(s,999).toFixed(1),"%"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:N(g),children:Math.min(s,999).toFixed(1)}),"%"]})})]}),S=K("app-region-no-drag flex items-center gap-1.5 select-none",u==="compact"?"typography-micro":"typography-meta",F?K("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",f),H=F?e.jsx("button",{type:"button",className:S,"aria-label":"Context usage","aria-pressed":O,onClick:M,children:v}):e.jsx("div",{className:S,"aria-label":"Context usage",onClick:l?()=>o(!0):void 0,children:v});return l?e.jsxs(e.Fragment,{children:[H,e.jsx(De,{open:b,onClose:()=>o(!1),title:"Context Usage",children:e.jsx("div",{className:"flex flex-col gap-1.5",children:e.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(t)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(c)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(R)})]}),A?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(Y)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(B)})]})]}):null,L?e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache hit"}),e.jsxs("span",{className:"typography-meta text-foreground font-medium",children:[h.toFixed(1),"%"]})]}):null,e.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e.jsxs("span",{className:K("typography-meta font-semibold",N(g)),children:[Math.min(s,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(Pe,{children:[e.jsx(Me,{asChild:!0,children:H}),e.jsx(Ee,{children:e.jsx("div",{className:"space-y-0.5",children:T.map(I=>e.jsx("p",{className:"typography-micro leading-tight",children:I},I))})})]})},ct=a.lazy(()=>st(()=>import("./SessionSwitcherDropdown-QY7FKuEQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79])).then(t=>({default:t.SessionSwitcherDropdown}))),lt=t=>{const s=typeof t=="string"?t.trim():"";if(!s)return"";const n=typeof window<"u"?window.__PICHAMBER_HOME__:"";if(n&&s===n)return"~";if(n&&s.startsWith(`${n}/`))return`~/${s.slice(n.length+1)}`;const c=s.split("/").filter(Boolean);return c.length<=3?s:`.../${c.slice(-3).join("/")}`},re=t=>{const s=typeof t=="string"?t.trim():"";if(!s)return"";const n=s.replace(/\\/g,"/");return n==="/"?"/":n.replace(/\/+$/,"")},dt=({mode:t})=>{const s=j(r=>r.currentSessionId),n=j(r=>!!r.newSessionDraft?.open),c=j(r=>r.newSessionDraft?.selectedProjectId??null),i=J(r=>r.currentDirectory),u=ae(r=>r.projects),l=ae(r=>r.getActiveProject()),D=P(r=>r.getCurrentModel),k=P(r=>r.providers),f=ce(),p=Oe(s??""),_=Te(),M=Re(r=>r.ensureStatus),O=j(r=>r.newSessionDraft?.open?re(r.newSessionDraft.directoryOverride??""):""),[x,C]=a.useState(!1),h=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,b=Number.isFinite(h)&&h>0,o=Ae(),g=b?h>=26?"h-12":h<=15?"h-14":"":"",m=a.useMemo(()=>s?f.find(r=>r.id===s)??null:null,[s,f]);a.useEffect(()=>{ge()&&Z("desktop_get_window_pinned").then(r=>{typeof r?.pinned=="boolean"&&C(r.pinned)})},[]);const y=m?.title?.trim()||(n||t==="draft"?"New session":"Session"),Q=re(m?.directory??null),w=re(i),N=Q||O||w,E=lt(N);a.useEffect(()=>{N&&M(N,_.git).catch(()=>{})},[M,N,_.git]);const $=a.useMemo(()=>{const r=N;return r?u.map(d=>({...d,normalizedPath:re(d.path)})).filter(d=>d.normalizedPath&&(d.normalizedPath===r||r.startsWith(`${d.normalizedPath}/`))).sort((d,G)=>G.path.length-d.path.length)[0]??null:null},[N,u]),W=a.useMemo(()=>{const r=$??l;if(!r)return E||"PiChamber";const d=r.label?.trim();return d||(r.path.split(/[\\/]/).filter(Boolean).at(-1)??r.path)},[l,E,$]),q=Be(N||null),R=q&&q!=="HEAD"?q:null,A=D(),Y=a.useMemo(()=>{for(let r=p.length-1;r>=0;r-=1){const d=p[r];if(d.role!=="assistant"||typeof d.providerID!="string"||typeof d.modelID!="string")continue;const te=k.find(X=>X.id===d.providerID)?.models.find(X=>X.id===d.modelID);if(te)return te}},[p,k]),B=A?.limit?A:Y,L=B&&typeof B.limit=="object"&&B.limit!==null?B.limit:null,T=L&&typeof L.context=="number"?L.context:0,F=L&&typeof L.output=="number"?L.output:0,v=a.useMemo(()=>{if(!s||p.length===0)return null;let r,d;for(let ne=p.length-1;ne>=0;ne-=1){const oe=p[ne];if(oe.role!=="assistant")continue;const z=oe.tokens;if(!z)continue;if(z.input+z.output+z.reasoning+(z.cache?.read??0)+(z.cache?.write??0)>0){r=z,d=oe.id;break}}if(!r)return null;const G=r.input+r.output+r.reasoning+(r.cache?.read??0)+(r.cache?.write??0),te=T>0?T:2e5,X=T>0?Math.round(G/T*100):0,xe=F>0?Math.round(r.output/F*100):void 0;return{totalTokens:G,percentage:X,contextLimit:T||0,outputLimit:F||void 0,normalizedOutput:xe,thresholdLimit:te,lastMessageId:d}},[T,s,p,F]),[S,H]=a.useState(null),I={WebkitAppRegion:"drag"},ee={WebkitAppRegion:"no-drag"};a.useEffect(()=>{if(!s){H(r=>r===null?r:null);return}if(v&&v.totalTokens>0){H(r=>r&&r.totalTokens===v.totalTokens&&r.percentage===v.percentage&&r.contextLimit===v.contextLimit&&(r.outputLimit??0)===(v.outputLimit??0)&&(r.normalizedOutput??0)===(v.normalizedOutput??0)&&r.thresholdLimit===v.thresholdLimit&&r.lastMessageId===v.lastMessageId?r:v);return}H(r=>r===null?r:null)},[v,s]);const pe=S&&S.contextLimit>0?Math.min(999,S.totalTokens/S.contextLimit*100):0,fe=a.useCallback(()=>{const r=!x;C(r),Z("desktop_set_window_pinned",{pinned:r}).catch(()=>{C(!r)})},[x]),he=a.useCallback(()=>{const r=s?{sessionId:s,directory:m?.directory??i??""}:{mode:"draft",directory:N||i||"",projectId:c};Z("desktop_focus_main_window",r).then(d=>d?.focused===!0?Z("desktop_close_current_window"):null)},[i,s,c,N,m]);return e.jsxs("header",{className:K("flex items-center gap-3 bg-background pr-3",b?"pl-[5.5rem]":"pl-3",o?"h-12":g||"min-h-14"),style:I,children:[e.jsx(me.Suspense,{fallback:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]}),children:e.jsx(ct,{children:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]})})}),e.jsx("div",{className:"min-w-0 flex-1"}),S&&S.totalTokens>0?e.jsx(at,{totalTokens:S.totalTokens,percentage:pe,colorPercentage:S.percentage,contextLimit:S.contextLimit,outputLimit:S.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:fe,"aria-label":x?"Unpin Mini Chat window":"Pin Mini Chat window",title:x?"Unpin window":"Pin above other windows",style:ee,children:x?e.jsx(V,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(V,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:he,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(V,{name:"external-link",className:"h-4 w-4"})}),e.jsx(Fe,{visible:o})]})},ut=({mode:t,autoOpenDraft:s=!1,unavailable:n=!1})=>{const c=j(i=>i.currentSessionId);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[e.jsx(dt,{mode:t}),e.jsx("main",{className:"min-h-0 flex-1",children:n?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:e.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Session unavailable"}),e.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:"This session could not be loaded. It may have been deleted, archived, or opened from a different project context."})]})}):e.jsx(nt,{mode:"mini-chat",children:e.jsx(Le,{autoOpenDraft:s},c??"no-session")})})]})},mt=()=>{const t=ie(i=>i.shortcutOverrides),s=J(i=>i.currentDirectory),n=ae(i=>i.getActiveProject()),c=j(i=>i.openNewSessionDraft);a.useEffect(()=>{const i=l=>ve(l,t),u=l=>{if(U(l,i("focus_input"))){l.preventDefault(),ue();return}if(we()&&U(l,i("new_mini_chat"))){l.preventDefault(),Z("desktop_open_draft_mini_chat_window",{directory:s||n?.path||"",projectId:n?.id??null})?.catch(f=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",f)});return}if(U(l,i("new_chat"))){l.preventDefault(),c({selectedProjectId:n?.id??null,directoryOverride:s||n?.path||null,preserveDirectoryOverride:!!(s||n?.path)}),ue();return}if(U(l,i("open_model_selector"))){l.preventDefault();const{isModelSelectorOpen:f,setModelSelectorOpen:p}=ie.getState();p(!f);return}if(U(l,i("cycle_thinking_variant"))){if(P.getState().getCurrentModelVariants().length===0)return;l.preventDefault(),ze(1).catch(()=>{Ue.error("Couldn't update thinking")});return}const D=U(l,i("cycle_favorite_model_forward")),k=U(l,i("cycle_favorite_model_backward"));if(D||k){const{favoriteModels:f,addRecentModel:p}=ie.getState();if(f.length===0)return;l.preventDefault();const{currentProviderId:_,currentModelId:M,setProvider:O,setModel:x}=P.getState(),C=f.findIndex(o=>o.providerID===_&&o.modelID===M),b=f[(C+(D?1:-1)+f.length)%f.length];O(b.providerID),x(b.modelID),p(b.providerID,b.modelID)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n?.id,n?.path,s,c,t])},pt="pichamber:mini-chat-presence",ft=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,s=t.get("mode")==="session"?"session":"draft",n=t.get("sessionId")?.trim()||null,c=t.get("directory")?.trim()||null,i=t.get("projectId")?.trim()||null;return{mode:s,sessionId:n,directory:c,projectId:i}},ht=({config:t})=>{const s=ce(),n=J(o=>o.currentDirectory),c=J(o=>o.setDirectory),i=j(o=>o.currentSessionId),u=j(o=>!!o.newSessionDraft?.open),l=j(o=>o.newSessionDraft?.open?o.newSessionDraft.bootstrapPendingDirectory??o.newSessionDraft.directoryOverride??"":""),D=j(o=>o.setCurrentSession),k=j(o=>o.openNewSessionDraft),f=P(o=>o.initializeApp),p=P(o=>o.isInitialized),_=P(o=>o.isConnected),M=P(o=>o.loadProviders),O=P(o=>o.providers.length),x=Ze();a.useEffect(()=>{f()},[f]),a.useEffect(()=>{if(p)return;let o=!0,g=0;const m=window.setInterval(()=>{if(o){if(g+=1,g>10){window.clearInterval(m);return}P.getState().isInitialized||P.getState().initializeApp()}},1e3);return()=>{o=!1,window.clearInterval(m)}},[p]);const C=a.useRef(!1);a.useEffect(()=>{if(!C.current&&t.mode==="session"&&t.directory){if(n===t.directory){C.current=!0;return}c(t.directory,{showOverlay:!1}),C.current=!0}},[t.directory,t.mode,n,c]),a.useEffect(()=>{t.mode!=="draft"||!u||i||!l||n===l||c(l,{showOverlay:!1})},[t.mode,n,i,l,u,c]),a.useEffect(()=>{_&&O===0&&M({source:"electronMiniChat:recovery"})},[_,M,O]);const h=a.useRef(!1);a.useEffect(()=>{if(h.current||t.mode!=="session"||!t.sessionId)return;if(i===t.sessionId){h.current=!0;return}if(i){h.current=!0;return}const o=s.find(m=>m.id===t.sessionId);if(!o){x.ensureSessionRenderable(t.sessionId);return}const g=o.directory??t.directory;D(t.sessionId,g),h.current=!0},[t,i,s,D,x]),a.useEffect(()=>{const o=g=>{const m=g.detail,y=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!y||j.getState().currentSessionId===y)return;const Q=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():s.find(w=>w.id===y)?.directory??null;x.ensureSessionRenderable(y),D(y,Q),h.current=!0};return window.addEventListener("pichamber:open-session",o),()=>window.removeEventListener("pichamber:open-session",o)},[s,D,x]),a.useEffect(()=>{t.mode!=="draft"||u||i||k({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,i,u,k]);const b=a.useRef(!1);return a.useEffect(()=>{if(b.current||!p)return;const o=()=>{if(b.current)return;b.current=!0;const y=typeof document<"u"?document.getElementById("initial-loading"):null;y&&(y.classList.add("fade-out"),window.setTimeout(()=>y.remove(),300))},g=t.mode==="session"?i===t.sessionId:u,m=window.setTimeout(o,g?100:1500);return()=>window.clearTimeout(m)},[p,t.mode,t.sessionId,i,u]),null},xt=()=>{const t=j(n=>n.currentSessionId),s=J(n=>n.currentDirectory);return a.useEffect(()=>{if(!t||!s||typeof BroadcastChannel>"u")return;const n=new BroadcastChannel(pt),c=l=>{n.postMessage({type:"mini-chat-session-presence",sessionId:t,directory:s,viewed:l})};c(!0);const i=window.setInterval(()=>c(!0),5e3),u=()=>c(!1);return window.addEventListener("beforeunload",u),()=>{window.clearInterval(i),window.removeEventListener("beforeunload",u),c(!1),n.close()}},[s,t]),null},yt=t=>{const s=ce(),n=j(u=>u.currentSessionId),[c,i]=a.useState(!1);return a.useEffect(()=>{if(t.mode!=="session"||!t.sessionId||n===t.sessionId){i(!1);return}if(s.some(l=>l.id===t.sessionId)){i(!1);return}const u=window.setTimeout(()=>i(!0),5e3);return()=>window.clearTimeout(u)},[t.mode,t.sessionId,n,s]),c};function gt({apis:t}){const s=a.useMemo(()=>ft(),[]),n=J(c=>c.currentDirectory);return a.useEffect(()=>{const c=n||s.directory;c&&$e().focusProject(c,null)},[s.directory,n]),a.useEffect(()=>(le(t),()=>le(null)),[t]),We(),mt(),Se({enabled:!0}),e.jsx(He,{children:e.jsx(Ge,{directory:n||s.directory,children:e.jsxs(Ke,{apis:t,children:[e.jsx(Ve,{}),e.jsx(Je,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(wt,{config:s}),e.jsx(Qe,{}),e.jsx(qe,{})]})})]})})})}const wt=({config:t})=>{const s=yt(t);return e.jsxs(e.Fragment,{children:[e.jsx(ht,{config:t}),e.jsx(xt,{}),e.jsx(Xe,{embeddedBackgroundWorkEnabled:!0}),e.jsx(ut,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:s})]})},vt=()=>{(async()=>{try{await Promise.all([be(),Ie()])}catch(t){console.error("[mini-chat-main] settings init failed:",t)}tt(),rt(),Ce()})()};function Jr(t){const s=t??je();if(!s)throw new Error("Runtime APIs not registered");vt();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");ye.createRoot(n).render(e.jsx(me.StrictMode,{children:e.jsx(Ye,{children:e.jsx(et,{children:e.jsx(gt,{apis:s})})})}))}export{Jr as renderElectronMiniChatApp};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-B_BF39ef.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DZnzXhTs.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BpmGBboM.css","assets/useAppFontEffects-BvFAP9zG.js","assets/vendor-base-ui-CdaWtC7e.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-CE_VNjdH.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-CP3j3-xu.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-CNlncqrr.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/FileSaveConflictDialog-CoKwDovb.js","assets/vendor-react-drawio-BYDptOsj.js","assets/runtimeEndpointReset-D2MmSbDk.js","assets/SessionUnreadDot-DGT31A3z.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/useFilesViewSearch-BD79p3A2.js","assets/JsonTreeView-Cwjgvh4g.js","assets/web-components-DWuadqra.js","assets/computeVirtualFileMetrics-FSOm2VrW.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/Virtualizer-BSHVMKgK.js","assets/isFilePlainText-CHouYQhH.js","assets/vendor-codemirror-search-BV44140v.js","assets/vendor-replit-codemirror-vim-DaSwPsXt.js","assets/GitView-LFEpCasf.js","assets/gitStatusPredicates-DxolDpMd.js","assets/VirtualizedFileDiff-Bl-rAYeh.js","assets/isDiffPlainText-D3_04XCh.js","assets/vendor-diff-C3JhlQdm.js","assets/collapsible-BjniCdZ5.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as ct,j as n,R as a,b as Ie,e as zn}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{u as fe,a as Ne,b as nn,d as Rt,i as X,e as de,s as Ee,f as Ke,r as sn,h as Un,j as Bn,k as rn,p as $n,l as Wn,m as W,n as an,o as Kn,q as ut,t as Fn,v as Nt,w as Hn,x as on,y as Vn}from"./index-DZnzXhTs.js";import{u as Xn,a as Gn,s as Jn}from"./usePushVisibilityBeacon-CWg0j-Wg.js";import{u as Te,a as qn,M as Qn,b as Yn,i as Zn,D as Pt,c as It,d as At,g as es,e as _t,f as ts,s as ns,S as ss,T as rs,h as as,j as os,k as is,H as ls,A as cs,C as us,r as ds,l as fs,m as ps,F as ms,n as hs,o as ys,W as bs,p as gs}from"./runtimeEndpointReset-D2MmSbDk.js";import{g as ze,l as xs,u as vs,a as ln,b as ws,c as ks,r as cn,d as Ss,t as rt,o as js,I as K,e as Ge,B as te,P as he,f as re,h as Cs,i as Es,j as Ts,k as Rs,E as ie,m as un,n as Ns,p as Ps,q as Is,s as As,v as _s,D as Ds,w as Ms,x as Os,y as Ce,z as Ls,A as zs,C as Us,F as Bs,G as $s,H as Ws,J as Ks,K as Fs,R as Hs,W as Vs,T as Xs,S as Gs,L as Js,M as qs,N as Qs,O as Ys,Q as Zs,U as er,V as tr,X as nr}from"./useAppFontEffects-BvFAP9zG.js";import{Capacitor as sr}from"./vendor-capacitor-core-B4EWRrHz.js";import{p as rr}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{_ as Ae}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as ar,A as or}from"./SettingsView-eG-wN-yY.js";import{f as ir,S as lr,a as cr,g as dn}from"./SessionUnreadDot-DGT31A3z.js";import{u as ur}from"./useSwitcherItems-CazJ6Yox.js";let fn=null,Dt=!1;const dr=new Promise(e=>{fn=e});function fr(){Dt||(Dt=!0,fn?.())}const pr=6,mr=e=>e.parentID??null,Mt=e=>{const t=e.replace(/\/+$/,"");return t.slice(t.lastIndexOf("/")+1)||t},hr=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),yr=(e,t)=>{if(!e)return"";let s=null,r=-1;for(const l of t){const o=hr(l.path);(e===o||e.startsWith(`${o}/`))&&o.length>r&&(s=l,r=o.length)}return s?s.label?.trim()||Mt(s.path):Mt(e)},br=()=>{const e=ze().getState().catalog,t=[];for(const f of e.byId.values())f.archived||t.push(xs(f));const s=vs.getState().index.session.unseenCount,r=fe.getState().notifyOnSubtasks,l=ln.getState().projects,o=ws.getState().ids,i=ks.getState().rankById;let c=0;const u=[];for(const f of t){const k=mr(f)!==null,v=(s[f.id]??0)>0&&(!k||r);v&&(c+=1),k||u.push({session:f,unread:v,project:yr(cn(f),l)})}u.sort((f,k)=>Ss(f.session,k.session,o,i));const d=u.slice(0,pr).map(({session:f,unread:k,project:j})=>({id:f.id,title:f.title??"",unread:k,project:j}));return{runtimeKey:Ne(),attentionCount:c,recentSessions:d}},gr="__PICHAMBER_WIDGET_SNAPSHOT__",xr=()=>{typeof window>"u"||(window[gr]=()=>{try{return JSON.stringify(br())}catch{return null}})},at="mobile-app-update-available",Ot="mobile-app-update-toast-dismissed-version",vr=()=>{const e=Te(o=>o.available),t=Te(o=>o.runtimeType),s=Te(o=>o.info?.version),r=Te(o=>o.info?.downloadUrl),l=ct.useRef(new Set);return ct.useEffect(()=>{if(nn()!=="android"||t!=="mobile"||!e||!s||!r){rt.dismiss(at);return}Rt().getItem(Ot)!==s&&(l.current.has(s)||(l.current.add(s),rt.info("PiChamber update available",{id:at,description:`Version ${s} is ready for Android.`,duration:1/0,icon:n.jsx(K,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{js(r)}},cancel:{label:"Dismiss",onClick:()=>{Rt().setItem(Ot,s),rt.dismiss(at)}}})))},[e,r,t,s]),null},wr=e=>{const{persisted:t,persistedDirectory:s,stale:r,ready:l,catalog:o,runtimeKey:i,capturedRuntimeKey:c,storeIdentityMatches:u,generationMatches:d}=e;if(!t||!s)return{action:"wait"};if(r||i!==c||!u||!d)return{action:"wait"};if(!l||!o)return{action:"wait"};const f=o.byId.get(t.sessionId);return!f||f.archived?{action:"clear"}:{action:"select",sessionId:f.id,directory:f.directory??s}},Je="pichamber.mobile.connections.v1",kr="pichamber.mobile.",Lt="pichamber.mobile.deviceId",pn=12,Sr=8e3,jr=2500,Cr=3e3,qe=2500,_e=15e3,Er=1500,Tr=5e3,Rr=()=>{try{const e=window.localStorage.getItem(Lt);if(e&&e.trim())return e.trim();const t=Ge();return window.localStorage.setItem(Lt,t),t}catch{return Ge()}},zt=()=>`mobile:${Rr()}`,Ut=()=>{try{const e=sr.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},mn=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:t=>t===e}},ve=e=>{const t=e.trim();if(!t)return"";const s=/^https?:\/\//i.test(t)?t:`http://${t}`,r=new URL(s);return r.hash="",r.search="",r.pathname=r.pathname.replace(/\/+$/,""),r.toString().replace(/\/+$/,"")},$e=e=>{try{return new URL(e).host}catch{return e}},De=e=>{try{return ve(e)}catch{return e.trim().replace(/\/+$/g,"")}},mt=(e,t)=>De(e)===De(t),ht=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,Nr=e=>`relay://${e.serverId}`,Ze=e=>e.candidates.filter(t=>t.kind==="direct"),ge=e=>{const t=e.candidates.find(s=>s.kind==="relay");return t&&t.kind==="relay"?t.relay:null},le=e=>{const t=Ze(e)[0];if(t)return t.url;const s=ge(e);return s?Nr(s):""},V=e=>{const t=ge(e);if(t)return ht(t);const s=Ze(e)[0];return s?De(s.url):""},Qe=(e,t)=>{const s=e.find(o=>o.kind==="relay"),r=s&&s.kind==="relay"?s.relay.serverId:null,l=new Set(e.filter(o=>o.kind==="direct").map(o=>De(o.url)));return t.some(o=>o.kind==="relay"?r!==null&&o.relay.serverId===r:l.has(De(o.url)))},yt=e=>{const t=(()=>{try{return ve(e)}catch{return""}})();return t?[{kind:"direct",url:t}]:[]},Bt=e=>{if(e.candidates&&e.candidates.length>0)return e.candidates;const t=[];return typeof e.url=="string"&&e.url.trim()&&!/^relay:\/\//i.test(e.url.trim())&&t.push(...yt(e.url)),e.relay&&t.push({kind:"relay",relay:e.relay}),t},bt=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;if(typeof t.relayUrl!="string"||!t.relayUrl.trim()||typeof t.serverId!="string"||!t.serverId.trim())return null;const s=t.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const r=s;return r.kty!=="EC"||r.crv!=="P-256"||typeof r.x!="string"||!r.x||typeof r.y!="string"||!r.y?null:{relayUrl:t.relayUrl,serverId:t.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:r.x,y:r.y}}},Pr=e=>{if(!e||typeof e!="object")return null;const t=e;if(t.kind==="direct")return typeof t.url=="string"&&t.url.trim()?{kind:"direct",url:t.url}:null;if(t.kind==="relay"){const s=bt(t.relay);return s?{kind:"relay",relay:s}:null}return null},Ir=e=>{if(e.mode==="relay"){const t=bt(e.relay);return t?[{kind:"relay",relay:t}]:[]}return typeof e.url=="string"?yt(e.url):[]},dt=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},we=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(Je)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const t=X();return e.flatMap(s=>{if(!s||typeof s!="object")return[];const r=s;if(typeof r.id!="string")return[];const l=Array.isArray(r.candidates)?r.candidates.map(Pr).filter(u=>!!u):Ir(r);if(l.length===0)return[];const o=typeof r.clientToken=="string"&&r.clientToken.trim()?r.clientToken:void 0,i=typeof r.label=="string"&&r.label.trim()?r.label:$e(le({candidates:l})),c={id:r.id,label:i,candidates:l,lastUsedAt:typeof r.lastUsedAt=="number"?r.lastUsedAt:0};return t?[{...c,hasToken:!!r.hasToken||!!o}]:[{...c,clientToken:o,hasToken:!!o}]}).sort((s,r)=>r.lastUsedAt-s.lastUsedAt)},gt=e=>{if(typeof window>"u")return;const t=X(),s=e.slice(0,pn).map(r=>{const l={id:r.id,label:r.label,candidates:r.candidates.map(dt),lastUsedAt:r.lastUsedAt};return t?{...l,hasToken:!!(r.hasToken||r.clientToken)}:{...l,clientToken:r.clientToken}});try{window.localStorage.setItem(Je,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},hn=(e,t)=>{const s=e.find(o=>t.id&&o.id===t.id||Qe(o.candidates,t.candidates)),r=X(),l={id:t.id||s?.id||Ge(),label:t.label,candidates:t.candidates,lastUsedAt:Date.now(),...r?{hasToken:t.hasToken??(!!t.clientToken||s?.hasToken||!1)}:{clientToken:t.clientToken??s?.clientToken,hasToken:!!(t.clientToken??s?.clientToken)}};return[l,...e.filter(o=>o.id!==l.id&&!Qe(o.candidates,t.candidates))].slice(0,pn)},xt=rr,Ar=0,vt=e=>`${kr}token.${encodeURIComponent(e)}`,_r=async(e,t)=>{let s;const r=new Promise(l=>{s=window.setTimeout(()=>l(t),Cr)});try{return await Promise.race([e.catch(()=>t),r])}finally{s!==void 0&&window.clearTimeout(s)}},wt=async(e,t,s)=>X()?_r(t().catch(r=>(console.warn(`[mobile-storage] ${e} failed`,r),s)),s):s,Fe=async e=>{const t=await wt("secure:read",async()=>(await xt.internalGetItem({prefixedKey:vt(e),sync:!1})).data,null);return typeof t=="string"&&t.trim()?t:void 0},ye=async(e,t)=>wt("secure:write",async()=>(await xt.internalSetItem({prefixedKey:vt(e),data:t,sync:!1,access:Ar}),!0),!1),Dr=async e=>{await wt("secure:delete",async()=>(await xt.internalRemoveItem({prefixedKey:vt(e),sync:!1}),!0),!1)},yn=async(e,t)=>{let s=0,r=0;return{records:await Promise.all(e.map(async o=>{if(!o||typeof o!="object")return o;const i=o,c=typeof i.url=="string"?i.url:null,u=typeof i.clientToken=="string"?i.clientToken.trim():"";if(!c||!u)return o;if(!await t(c,u))return r+=1,o;s+=1;const{clientToken:d,...f}=i;return{...f,hasToken:!0}})),migrated:s,failed:r}},bn=async()=>{if(typeof window>"u"||!X())return;let e;try{e=JSON.parse(window.localStorage.getItem(Je)||"[]")}catch{return}if(!Array.isArray(e)||e.filter(r=>!!r&&typeof r=="object"&&typeof r.url=="string"&&typeof r.clientToken=="string"&&!!r.clientToken.trim()).length===0)return;const s=await yn(e,async(r,l)=>{const o=De(r);return await ye(o,l)?await Fe(o)===l:!1});if(s.migrated>0)try{window.localStorage.setItem(Je,JSON.stringify(s.records))}catch(r){console.warn("[mobile-storage] failed to finalize secure token migration",r)}},gn=async()=>(await bn(),we()),He=async e=>{const t=hn(we(),e);return gt(t),X()&&e.clientToken&&await ye(V({candidates:e.candidates}),e.clientToken),t},xn=async e=>{const t=we(),s=t.find(l=>l.id===e)??null,r=t.filter(l=>l.id!==e);return gt(r),s&&X()&&await Dr(V(s)),r},kt=e=>{try{return JSON.stringify(e)}catch{return String(e)}},J=(e,t={})=>{console.info("[mobile-connect]",e,kt(t)),Bn("connect",{code:e,status:typeof t.status=="number"?t.status:void 0,detail:typeof t.reason=="string"?t.reason:typeof t.result=="string"?t.result:void 0})},Mr=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},Or=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},Lr=async(e,t)=>{if(!X())return null;try{const{CapacitorHttp:s}=await Ae(async()=>{const{CapacitorHttp:o}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:o}},[]),r=Object.fromEntries(new Headers(t?.headers).entries()),l=await s.request({url:e,method:t?.method||"GET",headers:r,data:Or(t?.body)});return{ok:l.status>=200&&l.status<300,status:l.status,source:"native-http",json:async()=>Mr(l.data)}}catch(s){return console.warn("[mobile-connect]","native-http failed",kt({url:e,error:s instanceof Error?s.message:String(s)})),null}},zr=async(e,t)=>{const s=await fetch(e,t).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",kt({url:e,error:r instanceof Error?r.message:String(r)})),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},pe=async(e,t,s)=>{let r;const l=new Promise(o=>{r=window.setTimeout(()=>{s?.(),o(null)},e)});try{return await Promise.race([t,l])}catch{return null}finally{r!==void 0&&window.clearTimeout(r)}},xe=async(e,t,s)=>{const r=s?.totalTimeoutMs??Sr,l=Date.now(),o=await pe(Math.min(jr,r),Lr(e,t));if(o)return o;const i=new AbortController,c=Math.max(500,r-(Date.now()-l));return pe(c,zr(e,{...t,signal:i.signal}),()=>i.abort())},et=async e=>{if(!e)return null;const t=await e.json().catch(()=>null);if(!t||typeof t!="object")return null;const s=t;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},Ur=async(e,t,s,r=_e,l)=>{const o=rn({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk}),i=c=>c==="ok"&&l?.keepTunnel?{outcome:c,tunnel:o}:(o.close(),{outcome:c});try{const c=t?{Authorization:`Bearer ${t}`}:void 0,u=await pe(r,o.fetch("/auth/session",{headers:c}).catch(()=>null));if(J("relay:session",{ok:u?.ok===!0,status:u?.status??null,hasToken:!!t}),!u)return i("unreachable");if(u.status===401)return i(t?"auth-failed":"needs-login");if(!u.ok&&u.status!==404)return i("auth-failed");const d=await et(u);return d&&d.disabled!==!0&&d.authenticated===!1?i(t?"auth-failed":"needs-login"):i("ok")}catch(c){throw o.close(),c}},Br=(e,t,s,r,l)=>{const o=typeof window<"u"?window.location.origin:"",i={relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk,...s?{grant:s}:{}};l&&Un(i,l),Ee({apiBaseUrl:o,clientToken:t,runtimeKey:r??ht(e),relay:i})},Ye=async(e,t,s)=>{const r=s?.fast?{totalTimeoutMs:qe}:void 0,l=ge({candidates:e})?.serverId??null,o=e.find(d=>d.kind==="relay")??null,i=e.filter(d=>d.kind==="direct"),c=async()=>{for(const d of i){const f=ve(d.url)||d.url,k=t?{Authorization:`Bearer ${t}`}:void 0,j=await xe(`${f}/health`,{method:"GET"},r);if(!j?.ok)continue;if(l){const _=await j.json().catch(()=>null),L=_&&typeof _=="object"?_.serverId:null;if(typeof L=="string"&&L&&L!==l){J("probe:server-id-mismatch",{url:f});continue}}const v=await xe(`${f}/auth/session`,{method:"GET",credentials:t?"omit":"include",headers:k},r);if(v?.status===401)return{status:"needs-login"};if(!v||!v.ok&&v.status!==404)continue;const h=await et(v);if(h&&h.disabled!==!0&&h.authenticated===!1)return{status:"needs-login"};const I=h?.disabled===!0;return!t&&X()&&!I&&h?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},u=async()=>{if(!o)return{status:"unreachable"};const{outcome:d,tunnel:f}=await Ur(o.relay,t,void 0,s?.fast?qe:void 0,{keepTunnel:!0});return d==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:f}}:d==="needs-login"||d==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?i.length===0?u():new Promise(d=>{let f=!1,k=!1,j,v=null,h=null;const I=T=>{T?.status==="ok"&&T.transport.kind==="relay"&&T.transport.tunnel?.close()},_=T=>{f||(f=!0,d(T))},L=()=>{k||f||(j!==void 0&&(window.clearTimeout(j),j=void 0),u().then(T=>{if(h=T,f||k){I(T);return}if(T.status==="ok"||T.status==="needs-login"){_(T);return}v&&_(v)}))};c().then(T=>{if(v=T,!f){if(T.status==="ok"||T.status==="needs-login"){k=!0,j!==void 0&&window.clearTimeout(j),I(h),_(T);return}if(h){_(h);return}L()}}),j=window.setTimeout(L,Er)}):c()},be=(e,t,s)=>{e.kind==="relay"?Br(e.relay,t,s?.grant,s?.runtimeKey,e.tunnel):Ee({apiBaseUrl:e.url,clientToken:t,runtimeKey:s?.runtimeKey}),jn()},Re=()=>{const e=we()[0];return e?.label?.trim()?e.label:null},Xe=async()=>{await bn();const e=we()[0];if(!e)return{status:"no-candidate"};let t;if(X()){if(!e.hasToken)return{status:"no-candidate"};if(t=await Fe(V(e)),!t)return{status:"no-candidate"}}else if(t=e.clientToken,!t)return{status:"no-candidate"};const s=await Ye(e.candidates,t,{fast:!0});return s.status==="needs-login"?{status:"needs-login",label:e.label}:s.status!=="ok"?{status:"unreachable",label:e.label}:(await He({id:e.id,label:e.label,candidates:e.candidates}),be(s.transport,t,{runtimeKey:V(e)}),{status:"connected"})},vn=async(e,t)=>{let s="";try{s=ve(e.url)}catch{return!1}if(!s)return!1;const r=e.clientToken?.trim()||void 0,l=r?{Authorization:`Bearer ${r}`}:void 0,o=t?.fast?{totalTimeoutMs:qe}:void 0;if(!(await xe(`${s}/health`,{method:"GET",headers:l},o))?.ok)return!1;const c=await xe(`${s}/auth/session`,{method:"GET",credentials:r?"omit":"include",headers:l},o);if(!c||!c.ok&&c.status!==404)return!1;const u=await et(c);return!(u&&u.disabled!==!0&&u.authenticated===!1)},$t=async e=>{const t=ge({candidates:e})?.serverId??null;for(const s of e){if(s.kind==="relay"){const o=rn(s.relay),i=await pe(_e,o.fetch("/health").catch(()=>null));if(J("establish:relay:health",{ok:i?.ok===!0,status:i?.status??null}),i?.ok)return{kind:"relay",relay:s.relay,tunnel:o};o.close();continue}const r=ve(s.url)||s.url,l=await xe(`${r}/health`,{method:"GET"});if(J("establish:direct:health",{ok:l?.ok===!0,status:l?.status??null}),!!l?.ok){if(t){const o=await l.json().catch(()=>null),i=o&&typeof o=="object"?o.serverId:null;if(typeof i=="string"&&i&&i!==t){J("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},$r=e=>[...e].sort((t,s)=>{const r=(t.priority??100)-(s.priority??100);if(r!==0)return r;const l=o=>o.type==="relay"?2:o.url.startsWith("https://")?0:1;return l(t)-l(s)}).flatMap(t=>{if(t.type==="relay"){const s=bt({relayUrl:t.relayUrl,serverId:t.serverId,hostEncPubJwk:t.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return yt(t.url)}),wn=async(e,t)=>{if(!Ke())return vn(e,t);const s=await pe(t?.fast?qe:_e,sn("/auth/session").then(l=>l).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const r=await et(s);return!(r&&r.disabled!==!0&&r.authenticated===!1)},Wr=e=>e.kind==="relay"?Ke():!Ke()&&mt(e.url,de()),kn=()=>{const e=Ne();return e?we().find(t=>V(t)===e)??null:null},ft=e=>{const t=Ne();return!!t&&V(e)===t},We=async()=>{const e=kn();if(!e)return"no-connection";let t;if(X()?t=e.hasToken?await Fe(V(e)):void 0:t=e.clientToken,!t)return"unreachable";const s=e.candidates.findIndex(c=>Wr(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),r=s>=0?e.candidates.slice(0,s):e.candidates,l=await Ye(r,t,{fast:!0});if(l.status==="ok")return await He({id:e.id,label:e.label,candidates:e.candidates}),be(l.transport,t,{runtimeKey:V(e)}),"switched";if(l.status==="needs-login")return"needs-login";if(s>=0&&await wn({url:de(),clientToken:t},{fast:!0}))return jn(),"unchanged";const o=s>=0?e.candidates.slice(s+1):[],i=await Ye(o,t,{fast:!0});return i.status==="ok"?(await He({id:e.id,label:e.label,candidates:e.candidates}),be(i.transport,t,{runtimeKey:V(e)}),"switched"):i.status==="needs-login"?"needs-login":"unreachable"};let ot=!1;const Sn=async()=>{if(ot)return"skipped";const e=kn();if(!e)return J("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const t=ge(e);if(!t)return J("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";ot=!0;try{const s=await pe(_e,sn("/api/client-auth/connection/candidates").then(d=>d).catch(()=>null));if(!s?.ok)return J("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const r=await s.json().catch(()=>null);if(!r||r.serverId!==t.serverId)return J("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const l=Array.isArray(r.candidates)?r.candidates:[],o=[];for(const d of l){if(!d||typeof d!="object")continue;const f=d;if(!(f.type!=="lan"||typeof f.url!="string"))try{const k=ve(f.url);k&&!o.includes(k)&&o.push(k)}catch{}}if(o.length===0)return J("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const i=Ze(e).filter(d=>d.url.startsWith("https://")),c=[...o.map(d=>({kind:"direct",url:d})),...i,{kind:"relay",relay:t}];return JSON.stringify(e.candidates.map(dt))===JSON.stringify(c.map(dt))?"unchanged":(J("candidates:refreshed",{lanCount:o.length}),await He({id:e.id,label:e.label,candidates:c}),"updated")}finally{ot=!1}},jn=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await Sn().catch(()=>"skipped");J("candidates:refresh-result",{result:e}),e==="updated"&&Ke()&&await We().catch(()=>null)})()},Tr)},St=e=>{const[t,s]=a.useState(()=>we()),[r,l]=a.useState(null),[o,i]=a.useState(null),[c,u]=a.useState(null),d=a.useRef(t),f=a.useRef(null),k=a.useRef(mn()),j=a.useCallback(y=>{d.current=y,s(y)},[]),v=a.useCallback(y=>{f.current=y,l(y)},[]),h=a.useCallback(y=>{f.current===y&&(f.current=null,l(null))},[]);a.useEffect(()=>{let y=!1;return gn().then(m=>{y||j(m)}),()=>{y=!0}},[j]);const I=a.useCallback(y=>{const m=hn(d.current,y);return j(m),gt(m),m},[j]),_=a.useCallback(async y=>{i(null),v("connect");try{const m=Bt(y);if(m.length===0){i("Enter a server URL.");return}const E=y.id?d.current.find(R=>R.id===y.id):d.current.find(R=>Qe(R.candidates,m)),M=y.label?.trim()||E?.label||$e(le({candidates:m})),N=y.relayGrant;let D=y.clientToken?.trim()||void 0;const g=!!D;D||(X()?E?.hasToken&&(D=await Fe(V({candidates:m}))):D=E?.clientToken),J("connect:start",{candidates:m.map(R=>R.kind),hasToken:!!D});const p=await Ye(m,D);if(J("connect:probe",{status:p.status}),p.status==="unreachable"){i("Could not reach that PiChamber server.");return}if(p.status==="needs-login"){I({id:E?.id,label:M,candidates:m}),u({id:E?.id??Ge(),label:M,candidates:m,relay:ge({candidates:m})??void 0,relayGrant:N});return}D&&g&&X()&&await ye(V({candidates:m}),D),I({id:E?.id,label:M,candidates:m,clientToken:D}),be(p.transport,D??null,{runtimeKey:V({candidates:m}),grant:N}),e()}catch(m){console.warn("[mobile-connect] connect threw",m),i("That server URL is not valid.")}finally{h("connect")}},[v,h,e,I]),L=a.useCallback(async y=>{if(f.current==="pairing")return;i(null),v("pairing");const m=$r(y.candidates);let E=null,M=!1;try{if(E=await $t(m),!E){i("Could not reach that PiChamber server.");return}const N=JSON.stringify({pairingId:y.pairingId,secret:y.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:Ut(),dedupeKey:zt()}),D={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:N},g=E.kind==="relay"?await pe(_e,E.tunnel.fetch("/api/client-auth/pairing/redeem",D).catch(()=>null)):await xe(`${E.url}/api/client-auth/pairing/redeem`,D);if(!g?.ok){i("This server needs a password or client token.");return}const p=await g.json().catch(()=>null),R=typeof p?.clientToken=="string"?p.clientToken.trim():"";if(!R){i("This server needs a password or client token.");return}const b=typeof p?.server?.label=="string"?p.server.label:"",A=y.label||b||$e(le({candidates:m}));if(X()&&!await ye(V({candidates:m}),R)){i("This server needs a password or client token.");return}I({label:A,candidates:m,clientToken:R}),be(E.kind==="relay"?{kind:"relay",relay:E.relay,tunnel:E.tunnel}:{kind:"direct",url:E.url},R,{runtimeKey:V({candidates:m})}),M=E.kind==="relay",e()}catch(N){console.warn("[mobile-connect] pairing threw",N),i("This server needs a password or client token.")}finally{!M&&E?.kind==="relay"&&E.tunnel.close(),h("pairing")}},[v,h,e,I]),T=a.useCallback(async y=>{if(!c||!y.trim()||f.current==="password")return;i(null),v("password");const m=k.current.begin(),E=()=>k.current.isCurrent(m),{id:M,label:N,candidates:D}=c;let g=null,p=!1;try{if(g=await $t(D),!E())return;if(!g){i("Could not reach that PiChamber server.");return}const R={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:y,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:Ut(),dedupeKey:zt()})};J("password:start",{transport:g.kind});const b=g.kind==="relay"?await pe(_e,g.tunnel.fetch("/auth/session",R).catch(()=>null)):await xe(`${g.url}/auth/session`,R);if(!E())return;if(J("password:done",{ok:b?.ok===!0,status:b?.status??null}),!b?.ok){i("Could not unlock that server. Check the password.");return}const A=await b.json().catch(()=>null);if(!E())return;const x=typeof A?.clientToken=="string"?A.clientToken.trim():"";if(J("password:token",{issued:!!x}),!x){if(g.kind==="direct"&&!X()){I({id:M,label:N,candidates:D}),u(null),be({kind:"direct",url:g.url},null,{runtimeKey:V({candidates:D})}),e();return}i("This server needs a password or client token.");return}if(X()&&(!E()||(await ye(V({candidates:D}),x),!E()))||!E()||(I({id:M,label:N,candidates:D,clientToken:x}),u(null),be(g.kind==="relay"?{kind:"relay",relay:g.relay,tunnel:g.tunnel}:{kind:"direct",url:g.url},x,{runtimeKey:V({candidates:D})}),p=g.kind==="relay",!E()))return;e()}catch(R){if(!E())return;console.warn("[mobile-connect] password threw",R),i("Could not unlock that server. Check the password.")}finally{!p&&g?.kind==="relay"&&g.tunnel.close(),E()&&h("password")}},[v,h,e,c,I]),S=a.useCallback(()=>{k.current.cancel(),h("password"),u(null),i(null)},[h]),C=a.useCallback(async y=>{i(null);let m=Bt(y);const E=y.id?d.current.find(g=>g.id===y.id)??null:null;if(E){const g=m.filter(b=>b.kind==="direct"),p=Ze(E).filter(b=>b.url.startsWith("https://")&&!g.some(A=>mt(A.url,b.url))),R=ge(E);m=[...g,...p,...R?[{kind:"relay",relay:R}]:[]]}if(m.length===0)return i("Enter a server URL."),null;const M=y.clientToken?.trim()||void 0,N=y.label?.trim()||$e(le({candidates:m}));if(X()){const g=V({candidates:m});if(M)await ye(g,M);else if(E?.hasToken){const p=V(E);if(p&&g&&p!==g){const R=await Fe(p);R&&await ye(g,R)}}}return I({id:y.id,label:N,candidates:m,clientToken:M}).find(g=>Qe(g.candidates,m))??null},[I]),B=a.useCallback(async y=>{const m=d.current.find(M=>M.id===y)??null,E=await xn(y);return j(E),m},[j]);return{connections:t,isBusy:r!==null,isPasswordBusy:r==="password",error:o,pendingConnection:c,connect:_,redeemPairingConnection:L,submitPassword:T,cancelPassword:S,saveConnection:C,removeConnection:B,setError:i}},za=Object.freeze(Object.defineProperty({__proto__:null,autoConnectLastInstance:Xe,connectionDisplayUrl:le,createMobilePasswordOperationTracker:mn,deleteMobileConnection:xn,getAutoConnectTargetLabel:Re,getConnectionLabel:$e,isActiveRuntimeConnection:ft,isSameConnectionUrl:mt,loadMobileConnections:gn,migrateLegacyInlineTokenRecords:yn,normalizeConnectionUrl:ve,refreshActiveConnectionCandidates:Sn,relayConnectionRuntimeKey:ht,reprobeActiveConnection:We,upsertMobileConnection:He,useMobileConnection:St,validateActiveRuntimeSession:wn,validateMobileConnectionSession:vn},Symbol.toStringTag,{value:"Module"})),Cn=()=>{if(typeof window>"u")return null;const t=window.Capacitor?.Plugins?.BarcodeScanner;return t&&(typeof t.scan=="function"||typeof t.startScan=="function")?t:null},Kr=()=>window.Capacitor?.getPlatform?.()==="android",En=e=>{const t=e.trim();if(!t)return null;if(/^pichamber:\/\//i.test(t)){const s=$n(t);return s?{pairing:s}:null}return/^https?:\/\//i.test(t)?{url:t}:null},Tn=(e,t)=>{const s=En(e);if(!s&&t?.pairingStringFallback){const r=Wn(e);if(r)return{status:"pairing",pairing:r}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Fr=async(e,t)=>{if(!e.startScan||!e.stopScan||!e.addListener)return{status:"unsupported"};if(t?.aborted)return{status:"cancelled"};let s,r,l=!1,o=()=>{};const i=new Promise(d=>{o=d}),c=d=>{l||(l=!0,o(d))},u=()=>c({status:"cancelled"});t?.addEventListener("abort",u,{once:!0});try{return(await Promise.allSettled([Promise.resolve(e.addListener("barcodesScanned",({barcodes:f})=>{const k=f?.[0],j=(k?.rawValue??k?.displayValue??"").trim();j&&c(Tn(j,{pairingStringFallback:!0}))})).then(f=>{s=f}),Promise.resolve(e.addListener("scanError",()=>c({status:"failed"}))).then(f=>{r=f})])).some(({status:f})=>f==="rejected")?c({status:"failed"}):l||e.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await i}finally{t?.removeEventListener("abort",u),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(r?.remove()),e.stopScan()])}},pt=()=>Cn()!==null,Rn=async e=>{const t=Cn();if(!t)return{status:"unsupported"};try{if(t.requestPermissions){const i=(await t.requestPermissions())?.camera;if(i&&i!=="granted"&&i!=="limited")return{status:"permission-denied"}}if(e?.signal?.aborted)return{status:"cancelled"};if(Kr())return Fr(t,e?.signal);if(!t.scan)return{status:"unsupported"};const r=(await t.scan({formats:["QR_CODE"]}))?.barcodes?.[0],l=(r?.rawValue??r?.displayValue??"").trim();return l?Tn(l):{status:"cancelled"}}catch{return{status:"failed"}}},Pe={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Ue="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",Nn=({onCancel:e})=>{const t=a.useRef(null);return a.useLayoutEffect(()=>{const s={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},r={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const l=new Map,o=c=>{!(c instanceof HTMLElement)||c===t.current||l.has(c)||(l.set(c,{opacity:c.style.opacity,pointerEvents:c.style.pointerEvents}),c.style.setProperty("opacity","0"),c.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(o);const i=new MutationObserver(c=>{c.forEach(u=>u.addedNodes.forEach(o))});return i.observe(document.body,{childList:!0}),()=>{i.disconnect(),l.forEach((c,u)=>{u.style.opacity=c.opacity,u.style.pointerEvents=c.pointerEvents}),s.value?document.documentElement.style.setProperty("background-color",s.value,s.priority):document.documentElement.style.removeProperty("background-color"),r.value?document.body.style.setProperty("background-color",r.value,r.priority):document.body.style.removeProperty("background-color")}},[]),a.useEffect(()=>{const s=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[e]),Ie.createPortal(n.jsxs("div",{ref:t,role:"dialog","aria-modal":"true","aria-label":"Scan QR code",className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[n.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),n.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}),n.jsxs(te,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[n.jsx(K,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},Pn=()=>Ie.createPortal(n.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[n.jsx(he,{width:96,height:96,isAnimated:!0}),n.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[n.jsx(K,{name:"loader-4",className:"size-[18px] animate-spin"}),n.jsx("span",{children:"Connecting..."})]})]}),document.body),Hr=({onConnected:e,notice:t=null})=>{const s=St(e),{connections:r,isBusy:l,isPasswordBusy:o,error:i,pendingConnection:c}=s,[u,d]=a.useState(""),[f,k]=a.useState(""),[j,v]=a.useState(""),[h,I]=a.useState(!1),[_,L]=a.useState(!1),T=a.useRef(null),S=a.useMemo(()=>pt(),[]),[C,B]=a.useState(()=>!pt()),[y,m]=a.useState(null),[E,M]=a.useState(""),N=a.useCallback(b=>{b.preventDefault(),s.connect({url:u,clientToken:j,label:f})},[j,s,f,u]),D=a.useCallback(b=>{if(/^pichamber:\/\//i.test(b.trim())){const A=En(b);if(A){if("pairing"in A){s.redeemPairingConnection(A.pairing);return}d(A.url),A.label&&k(A.label),A.clientToken&&v(A.clientToken);return}}d(b)},[s]),g=a.useCallback(async()=>{if(T.current||l)return;s.setError(null),I(!0);const b=new AbortController;T.current=b;try{const A=await Rn({signal:b.signal});switch(T.current===b&&(T.current=null,I(!1)),A.status){case"ok":L(!0),d(A.url),A.label&&k(A.label),A.clientToken&&v(A.clientToken),await s.connect({url:A.url,clientToken:A.clientToken,label:A.label});break;case"pairing":L(!0),await s.redeemPairingConnection(A.pairing);break;case"permission-denied":s.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":s.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":s.setError("QR scanning is only available in the installed mobile app.");break;case"failed":s.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{L(!1),T.current===b&&(T.current=null,I(!1))}},[s,l]);a.useEffect(()=>()=>T.current?.abort(),[]);const p=a.useCallback(b=>{b.preventDefault(),s.submitPassword(E)},[s,E]),R=a.useCallback(()=>{M(""),s.cancelPassword()},[s]);return n.jsxs(n.Fragment,{children:[h?n.jsx(Nn,{onCancel:()=>T.current?.abort()}):null,_?n.jsx(Pn,{}):null,n.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:n.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[n.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[n.jsx(he,{width:72,height:72,className:"size-[72px]"}),n.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),t?n.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:[n.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:n.jsx(K,{name:t.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),n.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:t.kind==="auth-expired"?`Access to ${t.label} has expired or was revoked. Sign in again.`:`Couldn't reach ${t.label}. Check that the server is running.`})]}):null,c?n.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:p,children:[n.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(K,{name:"lock",className:"size-[18px]"})}),n.jsxs("div",{className:"min-w-0 text-left",children:[n.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),n.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(b=>b.kind==="direct")?le(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Pe,value:E,onChange:b=>M(b.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Ue}),i?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:i}):null,n.jsx(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!E.trim(),children:o?"Connecting...":"Unlock and connect"}),n.jsx(te,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:R,children:"Use another server"})]}):n.jsxs("div",{className:"flex w-full flex-col gap-6",children:[S?n.jsxs("div",{className:"flex w-full flex-col gap-2",children:[n.jsxs(te,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{g()},disabled:h||l,children:[n.jsx(K,{name:"scan-2",className:W("size-[18px]",h&&"animate-pulse")}),l?"Connecting...":"Scan QR code"]}),n.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,i&&!C?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:i}):null,r.length>0?n.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[n.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved connections"}),n.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(b=>{const A=y===b.id;return n.jsxs("button",{type:"button",disabled:l,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{m(b.id),s.connect({id:b.id,candidates:b.candidates,clientToken:b.clientToken,label:b.label}).finally(()=>m(null))},children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(K,{name:"server",className:"size-[18px]"})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:b.label}),n.jsx("span",{className:W("block truncate typography-small",A?"text-foreground":"text-muted-foreground"),children:A?"Connecting...":b.candidates.some(x=>x.kind==="direct")?le(b):"via PiChamber Relay"})]}),A?n.jsx(K,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):n.jsx(K,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},b.id)})})]}):null,n.jsxs("div",{className:"flex w-full flex-col",children:[S?n.jsxs("button",{type:"button",onClick:()=>B(b=>!b),"aria-expanded":C,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:[n.jsx("span",{children:"Connect by address"}),n.jsx(K,{name:"arrow-down-s",className:W("size-4 transition-transform duration-200",C&&"rotate-180")})]}):null,n.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:C?"1fr":"0fr"},children:n.jsx("div",{className:"min-h-0 overflow-hidden",children:n.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:N,children:[n.jsx("input",{...Pe,value:u,onChange:b=>D(b.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:C?void 0:-1,className:W(Ue,"text-center")}),n.jsx("input",{value:f,onChange:b=>k(b.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:C?void 0:-1,className:W(Ue,"text-center")}),n.jsx("input",{...Pe,value:j,onChange:b=>v(b.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:C?void 0:-1,autoCapitalize:"none",className:W(Ue,"text-center")}),n.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."}),i?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:i}):null,n.jsx(te,{type:"submit",variant:S?"outline":"default",size:"lg",className:"h-12 w-full",disabled:l||h||!u.trim(),children:l?"Connecting...":"Connect"})]})})})]})]})]})})]})},Vr=10,Xr=(e,t)=>dn(e,t),Gr=({session:e,meta:t,active:s,onSelect:r})=>{const l=Cs(e.id),o=Es(e.id),i=l?.type??"idle",c=i==="busy"||i==="retry",u=!c&&o>0&&!s,d=Ts(e.id,c),f=c&&d,k=ir(e.time?.updated??e.time?.created??0);return n.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",s&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:r,style:{touchAction:"manipulation"},children:[n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[n.jsx("span",{className:W("block truncate typography-ui-label",s?"text-primary":"text-foreground"),children:Xr(e,"Untitled Session")}),t?n.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:t}):null]}),c?n.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):u?n.jsx(lr,{label:"Session complete"}):null,f?n.jsx(cr,{sessionId:e.id,running:c,className:"typography-micro"}):u?null:k?n.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:k}):null]})},Jr=({open:e,onClose:t,anchorRef:s})=>{const{panelRef:r,wrapperRef:l,shouldRender:o,isExiting:i,anchorLeft:c,isPopover:u}=qn({open:e,onClose:t,anchorRef:s}),d=re(h=>h.currentSessionId),f=re(h=>h.setCurrentSession),k=ln(h=>h.setActiveProjectIdOnly),j=ur(e||o,{maxParents:Vr}),v=a.useCallback(h=>{f(h.id,cn(h)),t()},[t,f]);return o?n.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:[n.jsx("div",{ref:r,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",u?"absolute origin-top-left":"mx-3 mt-2",i?"pointer-events-none":"pointer-events-auto"),style:{animation:`${i?"session-switcher-out":"session-switcher-in"} ${i?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))",...u?{top:8,left:c??8,width:`min(${Qn}px, calc(100% - 16px))`}:null},children:n.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:j.length===0?n.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):j.map(h=>{const I=h.node.session,_=[h.secondaryMeta?.projectLabel,h.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return n.jsx(Gr,{session:I,meta:_,active:I.id===d,onSelect:()=>{h.projectId&&k(h.projectId),v(I)}},I.id)})})}),n.jsx("style",{children:`
|
|
3
|
-
@keyframes session-switcher-in {
|
|
4
|
-
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
5
|
-
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
6
|
-
}
|
|
7
|
-
@keyframes session-switcher-out {
|
|
8
|
-
from { opacity: 1; transform: translateY(0) scale(1); }
|
|
9
|
-
to { opacity: 0; transform: translateY(-6px) scale(0.985); }
|
|
10
|
-
}
|
|
11
|
-
`})]}):null},qr=({onOpenSessions:e,onOpenWorkspace:t,compactTitle:s=!1})=>{const[r,l]=a.useState(!1),[o,i]=a.useState(!1),c=a.useRef(null),u=an(S=>S.currentDirectory),d=re(S=>S.currentSessionId),k=re(a.useCallback(S=>d?S.getDirectoryForSession(d):null,[d]))||u,j=Rs(d),v=re(S=>!!S.newSessionDraft?.open),I=j?.title?.trim()||(d?dn(j,"Untitled session"):"New session");a.useEffect(()=>{l(!1),i(!1)},[d,k]);const _=a.useCallback(()=>{l(!1),i(!1),e()},[e]),L=a.useCallback(S=>{l(C=>{const B=typeof S=="function"?S(C):S;return B&&i(!1),B})},[]),T=a.useCallback(()=>{i(S=>{const C=!S;return C&&l(!1),C})},[]);return n.jsxs(n.Fragment,{children:[n.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:n.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[n.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:_,style:{touchAction:"manipulation"},children:n.jsx(K,{name:"list-unordered",className:"size-5"})}),n.jsx("button",{ref:c,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",s?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":o,onClick:T,style:{touchAction:"manipulation"},children:n.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:I}),n.jsx(K,{name:"arrow-down-s",className:W("size-4 shrink-0 text-muted-foreground transition-transform duration-150",o&&"rotate-180")})]})}),s?n.jsx("div",{className:"min-w-0 flex-1"}):null,n.jsx(Yn,{open:r,onOpenChange:L,currentSessionId:d,effectiveDirectory:k,isNewSessionDraftOpen:v}),n.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),i(!1),t()},style:{touchAction:"manipulation"},children:n.jsx(K,{name:"layout-right",className:"size-5"})})]})}),n.jsx(Jr,{open:o,onClose:()=>i(!1),anchorRef:c})]})},Qr=({onActiveConnectionDeleted:e,onConnect:t})=>{const s=St(t),{connections:r,isBusy:l,isPasswordBusy:o,error:i,pendingConnection:c,connect:u,submitPassword:d,cancelPassword:f,saveConnection:k,removeConnection:j,setError:v}=s,[h,I]=a.useState(null),_=h?r.find(P=>P.id===h)??null:null,[L,T]=a.useState(null),[S,C]=a.useState(""),[B,y]=a.useState(""),[m,E]=a.useState(""),[M,N]=a.useState(""),[D,g]=a.useState(!1),[p,R]=a.useState(!1),[b,A]=a.useState(!1),[x,U]=a.useState(null),z=a.useRef(null),F=a.useMemo(()=>pt(),[]),[H,O]=a.useState(!1),[Y,ae]=a.useState(null),ne=a.useCallback(()=>{I(null),C(""),y(""),E(""),v(null),O(!1)},[v]),ue=a.useCallback(P=>{P.preventDefault(),k({id:h??void 0,url:S,label:B,clientToken:m}).then($=>{$&&ne()})},[m,h,B,ne,k,S]),q=a.useCallback(async()=>{if(z.current)return;v(null),g(!0);const P=new AbortController;z.current=P;try{const $=await Rn({signal:P.signal});switch(z.current===P&&(z.current=null,g(!1)),$.status){case"ok":C($.url),$.label&&y($.label),$.clientToken&&E($.clientToken),O(!0);break;case"pairing":R(!0),await s.redeemPairingConnection($.pairing);break;case"permission-denied":v("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":v("That QR code is not an PiChamber connection code.");break;case"unsupported":v("QR scanning is only available in the installed mobile app.");break;case"failed":v("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{R(!1),z.current===P&&(z.current=null,g(!1))}},[s,v]);a.useEffect(()=>()=>z.current?.abort(),[]);const Z=a.useCallback(P=>{P.preventDefault(),d(M)},[M,d]),Oe=a.useCallback(()=>{N(""),f()},[f]),ke=a.useCallback(async()=>{if(!b){U(null),A(!0);try{const P=await Kn();U(P==="copied"?"Diagnostics copied to the clipboard.":P==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{U("Diagnostics export was cancelled or unavailable.")}finally{A(!1)}}},[b]),Se=a.useCallback(P=>{T($=>$===P?null:P)},[]),Q=a.useCallback(P=>{T(null),h===P&&ne();const $=r.length===1;j(P).then(ce=>{ce&&($||ft(ce))&&e()})},[r.length,h,e,j,ne]),G=Ue;return c?n.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:n.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:Z,children:n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[n.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:n.jsx(K,{name:"lock",className:"size-[18px]"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),n.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(P=>P.kind==="direct")?le(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Pe,value:M,onChange:P=>N(P.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:G}),i?n.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:i}):null,n.jsx(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!M.trim(),children:o?"Connecting...":"Unlock and connect"}),n.jsx(te,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:Oe,children:"Use another server"})]})})}):n.jsxs(n.Fragment,{children:[D?n.jsx(Nn,{onCancel:()=>z.current?.abort()}):null,p?n.jsx(Pn,{}):null,n.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:n.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:n.jsxs("div",{className:"space-y-6",children:[r.length>0?n.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(P=>{const $=L===P.id,ce=ft(P),oe=Y===P.id,tt=oe?"Connecting...":ce?Ke()?"Connected · Private relay":"Connected · Local network":P.candidates.some(Le=>Le.kind==="direct")?le(P):"via PiChamber Relay";return n.jsxs("div",{className:W("flex items-center border-b border-border/70 transition-colors last:border-b-0",$&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[n.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{ce||(ae(P.id),u({id:P.id,candidates:P.candidates,clientToken:P.clientToken,label:P.label}).finally(()=>ae(null)))},disabled:l&&!oe||$,children:[n.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[n.jsx(K,{name:"server",className:"size-[18px]"}),ce?n.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:P.label}),n.jsx("span",{className:W("block truncate typography-small",ce&&!oe?"text-[var(--status-success)]":"text-muted-foreground"),children:tt})]}),oe?n.jsx(K,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),n.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[$?n.jsxs("button",{type:"button","aria-label":`Confirm deleting ${P.label}`,className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>Q(P.id),style:{touchAction:"manipulation"},children:[n.jsx(K,{name:"delete-bin",className:"size-[18px]"}),n.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):P.candidates.some(Le=>Le.kind==="direct")?n.jsx("button",{type:"button","aria-label":"Edit",className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{I(P.id),C(le(P)),y(P.label),E(P.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:n.jsx(K,{name:"edit",className:"size-[18px]"})}):null,n.jsx("button",{type:"button","aria-label":$?`Keep ${P.label}`:`Delete ${P.label}`,className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>Se(P.id),style:{touchAction:"manipulation"},children:n.jsx(K,{name:$?"close":"delete-bin",className:"size-[18px]"})})]})]},P.id)})}):n.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:"No saved connections yet."}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs(te,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{ke()},disabled:b,children:[n.jsx(K,{name:"download",className:"size-[18px]"}),b?"Preparing diagnostics…":"Export diagnostics"]}),x?n.jsx("p",{className:"px-1 text-center typography-small text-muted-foreground",children:x}):null]}),!H&&!_?n.jsxs("div",{className:"space-y-2",children:[F?n.jsxs(te,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{q()},disabled:D,children:[n.jsx(K,{name:"scan-2",className:W("size-[18px]",D&&"animate-pulse")}),"Scan QR code"]}):null,n.jsxs(te,{type:"button",variant:F?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),O(!0)},children:[n.jsx(K,{name:"add",className:"size-[18px]"}),"Add by address"]}),i?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:i}):null]}):n.jsxs("form",{className:"space-y-3",onSubmit:ue,children:[n.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[n.jsx("h3",{className:"typography-ui-label text-foreground",children:_?"Edit instance":"Add instance"}),n.jsx(te,{type:"button",variant:"ghost",size:"xs",onClick:ne,children:"Cancel"})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Server URL"}),n.jsx("input",{...Pe,value:S,onChange:P=>C(P.target.value),placeholder:"http://192.168.1.74:2606",type:"url",inputMode:"url",autoCapitalize:"none",className:G})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Name"}),n.jsx("input",{value:B,onChange:P=>y(P.target.value),placeholder:"Optional display name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:G})]}),n.jsxs("label",{className:"block space-y-1.5",children:[n.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Client token"}),n.jsx("input",{...Pe,value:m,onChange:P=>E(P.target.value),placeholder:"Paste access token",autoCapitalize:"none",className:G}),n.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."})]}),i?n.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:i}):null,n.jsx(te,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:_?"Save changes":"Save instance"})]})]})})})]})},Me=320,me="cubic-bezier(0.22, 1, 0.36, 1)",In=({side:e,enabled:t,open:s,drawerRef:r,scrimRef:l,onClose:o,widthRatio:i,prefersReducedMotion:c})=>{a.useEffect(()=>{if(!t||!s)return;const u=r.current,d=l.current;if(!u||!d)return;let f=!1,k=!1,j=!1,v=0,h=0,I=0,_=0;const L=c?0:Me,T=e==="left"?"translateX(-100%)":"translateX(100%)",S=()=>({drawer:L?`transform ${L}ms ${me}`:"none",scrim:L?`opacity ${L}ms ${me}`:"none"}),C=()=>{const g=S();u.style.transition=g.drawer,d.style.transition=g.scrim,u.style.transform="none",d.style.opacity="1",d.style.pointerEvents="auto"},B=()=>{f=!1,k=!1,j=!1},y=()=>{if(!(f||k)){B();return}C(),B()},m=g=>{if(g.touches.length!==1){(f||k)&&y();return}if(Zn(g.target,u,{excludeInteractive:!1}))return;u.style.transition&&u.style.transition!=="none"&&(u.style.transition="none",d.style.transition="none");const p=g.touches[0];v=p.clientX,h=p.clientY,I=Date.now(),_=u.offsetWidth||window.innerWidth*i,_<10&&(_=window.innerWidth*i),f=!0,k=!1,j=!1},E=g=>{if(!f)return;if(g.touches.length!==1){y();return}const p=g.touches[0],R=p.clientX-v,b=p.clientY-h;if(!j){if(Math.abs(R)<Pt&&Math.abs(b)<Pt)return;if(Math.abs(b)>Math.abs(R)*It||!At(e,R)){f=!1;return}j=!0,k=!0,u.style.transition="none",d.style.transition="none"}if(!k)return;g.cancelable&&g.preventDefault();const A=_t(e,R,_);u.style.transform=es(e,A),d.style.opacity=String(A)},M=(g,p,R)=>{if(!f)return;const b=g-v,A=p-h,x=Math.max(1,Date.now()-I),U=_t(e,b,_),z=ns({side:e,dx:b,dy:A,dt:x,progress:U,isDragging:k}),F=S();u.style.transition=F.drawer,d.style.transition=F.scrim,u.style.transform=z?T:"none",d.style.opacity=z?"0":"1",d.style.pointerEvents=z?"none":"auto",B(),z&&o()},N=g=>{const p=g.changedTouches[0];if(!p){y();return}const R=p.clientX-v,b=p.clientY-h,A=Math.abs(R)>=ts&&Math.abs(b)<=Math.abs(R)*It&&At(e,R);f&&(k||A)&&g.cancelable&&g.preventDefault(),M(p.clientX,p.clientY)},D=()=>{y()};return u.addEventListener("touchstart",m,{passive:!0}),u.addEventListener("touchmove",E,{passive:!1}),u.addEventListener("touchend",N,{passive:!1}),u.addEventListener("touchcancel",D,{passive:!0}),()=>{try{y()}catch{}u.removeEventListener("touchstart",m),u.removeEventListener("touchmove",E),u.removeEventListener("touchend",N),u.removeEventListener("touchcancel",D)}},[r,t,o,s,c,l,e,i])},Yr=16,Wt=a.memo(function({open:t,onOpenChange:s,variant:r="drawer",drawerRefExternal:l,scrimRefExternal:o,rootRefExternal:i}){const c=a.useRef(null),u=a.useCallback(()=>{const C=typeof document<"u"?document.activeElement:null;C instanceof HTMLElement&&c.current?.contains(C)&&C.blur(),s(!1)},[s]),[d,f]=a.useState(!1),k=a.useRef(null),j=a.useRef(null),v=l??k,h=o??j,I=a.useCallback(C=>{c.current=C,i&&(i.current=C)},[i]),_=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);a.useEffect(()=>{const C=c.current;if(!C||t)return;const B=document.activeElement;B&&C.contains(B)&&B.blur()},[t]),a.useEffect(()=>{if(r!=="sidebar"){if(t){const C=window.setTimeout(()=>f(!0),_?0:Yr);return()=>window.clearTimeout(C)}f(!1)}},[t,_,r]),a.useEffect(()=>{if(r==="sidebar"||!t)return;const C=document.body.style.overflow;document.body.style.overflow="hidden";const B=y=>{y.key==="Escape"&&u()};return document.addEventListener("keydown",B),()=>{document.body.style.overflow=C,document.removeEventListener("keydown",B)}},[u,t,r]);const L=r==="sidebar",T=n.jsx(ss,{mobileVariant:!L,isVisible:t,allowReselect:!0,onSessionSelected:L?void 0:u,onNavigateAway:L?void 0:u});if(In({side:"left",enabled:r==="drawer",open:t,drawerRef:v,scrimRef:h,onClose:u,widthRatio:.72,prefersReducedMotion:_}),r==="sidebar")return n.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:T});if(typeof document>"u")return null;const S=_?0:Me;return Ie.createPortal(n.jsxs("div",{ref:I,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none"},"data-mobile-sessions-root":"true",children:[n.jsx("button",{ref:h,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:u,tabIndex:t?0:-1,style:{opacity:d?1:0,transition:`opacity ${S}ms ${me}`},"data-mobile-sessions-scrim":"true"}),n.jsx("div",{ref:v,className:W("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:d?"none":"translateX(-100%)",transition:S?`transform ${S}ms ${me}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:T})]}),document.body)}),Kt="mobile-surface-root",it=16,Ve=200,Zr=()=>{if(typeof document>"u")return null;let e=document.getElementById(Kt);return e||(e=document.createElement("div"),e.id=Kt,document.body.appendChild(e)),e},lt=({open:e,onClose:t,title:s,subtitle:r,trailing:l,disableEscapeDismiss:o=!1,headerless:i=!1,noHeaderBorder:c=!1,ariaLabel:u,variant:d="fullscreen",dialogAlign:f="chat",children:k})=>{const j=a.useRef(null),[v,h]=a.useState(!1),[I,_]=a.useState(!1),L=a.useRef(null),T=a.useRef(null),S=a.useRef(t);if(a.useEffect(()=>{S.current=t},[t]),typeof document<"u"&&!j.current&&(j.current=Zr()),a.useEffect(()=>{if(!e){h(!1);return}const y=window.setTimeout(()=>h(!0),it);return()=>window.clearTimeout(y)},[e]),a.useEffect(()=>{if(!e){_(!1);return}const y=window.setTimeout(()=>_(!0),it+Ve+80);return()=>window.clearTimeout(y)},[e]),a.useEffect(()=>{if(!e)return;const y=document.body.style.overflow;T.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const m=()=>{const N=L.current;if(!N)return;(N.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??N).focus({preventScroll:!0})},E=window.setTimeout(m,it),M=N=>{if(N.key==="Escape"&&!o){S.current();return}if(N.key!=="Tab")return;const D=L.current;if(!D)return;const g=Array.from(D.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(A=>!A.hasAttribute("disabled")&&A.getAttribute("aria-hidden")!=="true");if(g.length===0){N.preventDefault(),D.focus({preventScroll:!0});return}const p=g[0],R=g[g.length-1],b=document.activeElement;N.shiftKey&&b===p?(N.preventDefault(),R.focus({preventScroll:!0})):!N.shiftKey&&b===R&&(N.preventDefault(),p.focus({preventScroll:!0}))};return document.addEventListener("keydown",M),()=>{window.clearTimeout(E),document.body.style.overflow=y,document.removeEventListener("keydown",M),T.current?.focus?.({preventScroll:!0}),T.current=null}},[o,e]),!e||!j.current)return null;const C=d==="dialog",B=n.jsxs("section",{ref:L,role:"dialog","aria-modal":"true","aria-label":u,tabIndex:-1,className:W("flex flex-col bg-background text-foreground",C?"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:C?{opacity:v?1:0,transform:v?"none":"scale(0.97)",transition:`opacity ${Ve}ms ease-out, transform ${Ve}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:`transform ${Ve}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:y=>{v&&y.target===y.currentTarget&&y.propertyName==="transform"&&_(!0)},children:[i?null:n.jsxs("header",{className:W("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[n.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:t,style:{touchAction:"manipulation"},children:n.jsx(K,{name:"close",className:"size-5"})}),n.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?n.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,r?typeof r=="string"?n.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:r}):r:null]}),l?n.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:l}):null]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:I?n.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:k}):null}),n.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return C?Ie.createPortal(n.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:v?1:0,paddingLeft:f==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:f==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:t,children:n.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:y=>y.stopPropagation(),children:B})}),j.current):Ie.createPortal(B,j.current)},ea=a.lazy(()=>Ae(()=>import("./FilesView-B_BF39ef.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122])).then(e=>({default:e.FilesView}))),ta=a.lazy(()=>Ae(()=>import("./GitView-LFEpCasf.js"),__vite__mapDeps([123,24,1,2,9,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,100,101,102,103,104,105,124,108,109,110,84,85,86,87,88,89,90,91,92,93,94,95,96,97,111,82,83,112,113,114,115,116,117,118,125,126,127,80,81,128])).then(e=>({default:e.GitView}))),Ft="mobile-surface-root",na=16,sa=[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal"}],Ht=a.memo(function({open:t,onClose:s,tab:r,onTabChange:l,pendingChangesDiff:o,variant:i="drawer",drawerRefExternal:c,scrimRefExternal:u,rootRefExternal:d}){const f=a.useRef(null),k=a.useRef(null),j=a.useRef(null),v=a.useRef(null),h=c??k,I=u??j,_=d??v,L=a.useCallback(p=>{v.current=p,d&&(d.current=p)},[d]),T=a.useCallback(()=>{const p=typeof document<"u"?document.activeElement:null;p instanceof HTMLElement&&_.current?.contains(p)&&p.blur(),s()},[s]),[S,C]=a.useState(!1),[B,y]=a.useState(t),m=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[E,M]=a.useState(()=>new Set);if(a.useEffect(()=>{t&&M(p=>{if(p.has(r))return p;const R=new Set(p);return R.add(r),R})},[t,r]),typeof document<"u"&&!f.current){let p=document.getElementById(Ft);p||(p=document.createElement("div"),p.id=Ft,document.body.appendChild(p)),f.current=p}if(a.useEffect(()=>{if(t){y(!0);const R=window.setTimeout(()=>C(!0),m?0:na);return()=>window.clearTimeout(R)}C(!1);const p=window.setTimeout(()=>y(!1),Me+40);return()=>window.clearTimeout(p)},[t,m]),a.useEffect(()=>{if(!t)return;const p=document.body.style.overflow;i==="drawer"&&(document.body.style.overflow="hidden");const R=b=>{b.key==="Escape"&&r!=="terminal"&&T()};return document.addEventListener("keydown",R),()=>{i==="drawer"&&(document.body.style.overflow=p),document.removeEventListener("keydown",R)}},[T,t,r,i]),a.useEffect(()=>{const p=_.current;if(!p||t||i!=="drawer")return;const R=document.activeElement;R&&p.contains(R)&&R.blur()},[t,i]),In({side:"right",enabled:i==="drawer",open:t,drawerRef:h,scrimRef:I,onClose:T,widthRatio:1,prefersReducedMotion:m}),i==="drawer"&&!f.current)return null;const N=m?0:Me,D=n.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",role:"tablist","aria-label":"Workspace","data-no-drawer-swipe":"true",children:sa.map(p=>{const R=r===p.id;return n.jsxs("button",{type:"button",role:"tab","aria-selected":R,onClick:()=>l(p.id),className:W("flex min-w-0 flex-1 items-center justify-center gap-1 rounded-lg px-1.5 py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",R?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(K,{name:p.icon,className:"size-5 shrink-0"}),n.jsx("span",{className:"truncate",children:p.label})]},p.id)})}),g=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2",children:[D,n.jsx("button",{type:"button",onClick:T,"aria-label":"Close workspace panel",className:"flex size-10 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:n.jsx(K,{name:"close",className:"size-5"})})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[E.has("changes")?n.jsx("div",{className:W("h-full",r!=="changes"&&"hidden"),children:n.jsx(ie,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(ta,{isActive:t&&r==="changes",chrome:"mobile",initialDiffPath:o?.path??null,initialDiffStaged:o?.staged===!0})})})},o?`changes:${o.path}:${o.staged}`:"changes"):null,E.has("files")?n.jsx("div",{className:W("h-full",r!=="files"&&"hidden"),children:n.jsx(ie,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(ea,{chrome:"mobile",mode:"editor-only",isVisible:t&&r==="files"})})})}):null,E.has("terminal")?n.jsx("div",{className:W("h-full",r!=="terminal"&&"hidden"),children:n.jsx(ie,{children:n.jsx(rs,{visible:t&&r==="terminal"})})}):null]})]});return i==="panel"?n.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:g}):Ie.createPortal(n.jsxs("div",{ref:L,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none",visibility:B?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[n.jsx("button",{ref:I,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:T,tabIndex:t?0:-1,style:{opacity:S?1:0,transition:N?`opacity ${N}ms ${me}`:"none"},"data-mobile-workspace-scrim":"true"}),n.jsx("section",{ref:h,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:S?"none":"translateX(100%)",transition:N?`transform ${N}ms ${me}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:g})]}),f.current)}),ra="pichamber",aa=e=>e.replace(/^\/+|\/+$/g,""),oa=e=>{const t=aa(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...t]:t};function ia(e){if(typeof e!="string"||e.length===0)return null;let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`${ra}:`)return null;const s=oa(t),r=(s[0]??"").toLowerCase(),l=s.slice(1),o=t.searchParams;switch(r){case"session":{const i=l[0]||o.get("id")||"";return i?{type:"session",sessionId:i,directory:o.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:o.get("dir")??void 0,projectId:o.get("project")??void 0,agent:o.get("agent")??void 0,model:o.get("model")??void 0};case"sessions":{const i=o.get("filter");return{type:"sessions",filter:i==="attention"||i==="recent"||i==="all"?i:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:l[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:l.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const i=(l[0]||"").toLowerCase();return i==="changes"?{type:"changes"}:i==="files"||i==="mcp"||i==="instances"||i==="update"?{type:"view",target:i}:null}default:return null}}let ee={},An=!1,Be=null;const la=e=>{switch(e.type){case"session":return re.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const t=re.getState();return t.openNewSessionDraft(),(e.directory||e.projectId)&&t.setNewSessionDraftTarget({directoryOverride:e.directory??null,projectId:e.projectId??null,selectedProjectId:e.projectId??null}),!0}case"sessions":return ee.openSessions?(ee.openSessions(e.filter),!0):!1;case"status":return ee.openSessions?(ee.openSessions(),!0):!1;case"view":return ee.openView?(ee.openView(e.target),!0):!1;case"changes":return ee.openChanges?(ee.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return ee.openSettings?(ee.openSettings(e.section),!0):!1}},jt=()=>{if(!An||!Be)return;const e=Be;Be=null,la(e)||(Be=e)},_n=e=>{Be=e,jt()},Vt=e=>{const t=ia(e);t&&_n(t)},ca=e=>{An=e,jt()},ua=e=>{a.useEffect(()=>(ee=e,jt(),()=>{ee===e&&(ee={})}),[e])},da=e=>{const{ready:t}=e;a.useEffect(()=>{ca(t)},[t]),a.useEffect(()=>{if(!X())return;let s=!1;const r=[];return Ae(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([129,24,130])).then(async({App:l})=>{if(s)return;const o=await l.addListener("appUrlOpen",i=>{Vt(i?.url)});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),Ae(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,130])).then(async({PushNotifications:l})=>{if(s)return;const o=await l.addListener("pushNotificationActionPerformed",i=>{const c=i?.notification?.data,u=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(u){Vt(u);return}const d=typeof c?.sessionId=="string"?c.sessionId:void 0;d&&_n({type:"session",sessionId:d})});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(l=>l())}},[])},Xt=e=>{const t=e.drawer.current,s=e.scrim.current,r=e.root.current;r&&(r.style.pointerEvents="auto",r.style.visibility="visible"),t&&(t.style.transition="none"),s&&(s.style.transition="none")},Gt=(e,t,s)=>{const r=e.drawer.current,l=e.scrim.current;if(r&&(r.style.transform=s>=.999?"none":`translateX(${(t==="left"?s-1:1-s)*100}%)`),l){l.style.opacity=String(s);const o=s>.01?"auto":"none";l.style.pointerEvents!==o&&(l.style.pointerEvents=o)}},Jt=(e,t,s)=>{const r=s.drawer.current,l=s.scrim.current,o=s.root.current;r&&(r.style.transition=`transform ${Me}ms ${me}`,r.style.transform=t?"none":e==="left"?"translateX(-100%)":"translateX(100%)"),l&&(l.style.transition=`opacity ${Me}ms ${me}`,l.style.opacity=t?"1":"0",l.style.pointerEvents=t?"auto":"none"),o&&(o.style.pointerEvents=t?"auto":"none",o.style.visibility=t?"visible":"")},qt=e=>{const t=e.shell.current,s=e.inner.current;t&&(t.style.overflow="visible"),s&&(s.style.transition="none")},Qt=(e,t,s,r)=>{const l=e.inner.current;if(!l)return;const o=r==="left"?(t-1)*s:(1-t)*s;l.style.transform=t>=.999?"translateX(0)":`translateX(${o}px)`},Yt=(e,t,s,r,l)=>{const o=e.shell.current,i=e.inner.current;return!o||!i?void 0:(i.style.transition="transform 200ms cubic-bezier(0.22, 1, 0.36, 1)",i.style.transform=t?"translateX(0)":`translateX(${r==="left"?-s:s}px)`,window.setTimeout(()=>{i.style.transition="",i.style.transform="",o.style.overflow=""},220))},Zt=({side:e,isResizing:t,ariaLabel:s,handleProps:r})=>n.jsx("div",{className:W("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",e==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":s,...r,children:n.jsx("div",{className:W("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",t&&"bg-[var(--interactive-border)]")})}),fa=320,pa=380,en=280,ma=560,ha=900;function tn(e,t,s,r=ma){const l=a.useRef(null),[o,i]=a.useState(()=>{if(typeof window>"u")return s;const S=Number.parseInt(window.localStorage.getItem(t)??"",10);return Number.isFinite(S)?Math.min(r,Math.max(en,S)):s}),[c,u]=a.useState(!1),d=a.useRef(0),f=a.useRef(o),k=a.useRef(null),j=a.useRef(null),v=a.useCallback(S=>Math.min(r,Math.max(en,Math.round(S))),[r]),h=a.useCallback(S=>{const C=l.current;C&&(C.style.width=`${S}px`,C.style.minWidth=`${S}px`,C.style.maxWidth=`${S}px`,C.style.setProperty("--oc-ipad-sidebar-width",`${S}px`))},[]),I=a.useCallback(S=>{try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}j.current=S.pointerId,d.current=S.clientX,f.current=o,k.current=o,u(!0),S.preventDefault()},[o]),_=a.useCallback(S=>{if(j.current!==S.pointerId)return;const C=S.clientX-d.current,B=v(f.current+(e==="left"?C:-C));k.current!==B&&(k.current=B,h(B))},[h,v,e]),L=a.useCallback(S=>{if(j.current!==S.pointerId)return;try{S.currentTarget.releasePointerCapture(S.pointerId)}catch{}const C=v(k.current??f.current);j.current=null,k.current=null,u(!1),i(C);try{window.localStorage.setItem(t,String(C))}catch{}},[v,t]),T=a.useMemo(()=>({onPointerDown:I,onPointerMove:_,onPointerUp:L,onPointerCancel:L}),[I,L,_]);return{asideRef:l,width:o,isResizing:c,handleProps:T}}const ya=a.memo(us),ba=({onActiveConnectionDeleted:e})=>{const[t,s]=a.useState(!1),[r,l]=a.useState(null),[o,i]=a.useState(!1),[c,u]=a.useState("changes"),[d,f]=a.useState("nav"),[k,j]=a.useState(null),v=a.useRef([]),h=a.useCallback(()=>{v.current.forEach(w=>window.clearTimeout(w)),v.current=[]},[]);a.useEffect(()=>()=>h(),[h]);const I=a.useRef(null),_=a.useRef(null),L=a.useRef(null),T=a.useRef(null),S=a.useRef(null),C=a.useRef(null),B=a.useRef(null),y=a.useRef(null),m=a.useRef(0),E=a.useRef(0),M=a.useCallback(w=>{h(),s(w)},[h]),N=a.useCallback(w=>{h(),i(w)},[h]),D=fe(w=>w.setSettingsPage),g=fe(w=>w.isArchivePageOpen),p=fe(w=>w.setArchivePageOpen),R=Te(w=>w.available),b=Te(w=>w.runtimeType),A=a.useMemo(()=>un(),[]),x=!A&&R&&(b==="desktop"||b==="web"),U=a.useCallback(()=>{l(null)},[]),z=a.useCallback(w=>{l(w)},[]),F=a.useCallback(()=>{N(!1)},[N]),H=a.useCallback(w=>{f(w),z("settings")},[z]),{enabled:O,roomyForPanels:Y}=Ns(),ne=Ps()==="portrait",ue=Is(),q=fe(w=>w.setSidebarOpen),Z=fe(w=>w.isSidebarOpen),Oe=a.useRef(!1);a.useLayoutEffect(()=>{O&&!Oe.current&&q(As().roomyForPanels),!O&&Oe.current&&q(!1),Oe.current=O},[O,q]);const ke=a.useCallback(()=>{j(null),u("files"),N(!0)},[N]),Se=a.useCallback((w=null)=>{j(w),u("changes"),N(!0)},[N]),Q=tn("left","pichamber.ipad.leftSidebarWidth",fa),G=tn("right","pichamber.ipad.rightSidebarWidth",pa,ha),P=Y,$=P&&o?G.width:0,ce=as(O&&Z),oe=O&&Z?Q.width:0,tt=a.useCallback(w=>{o&&c===w?N(!1):(u(w),N(!0))},[o,c,N]),Le=a.useCallback(()=>{N(!o)},[o,N]),Dn=a.useCallback(w=>{!w&&!Y&&q(!1)},[Y,q]);a.useEffect(()=>{if(typeof document>"u")return;const w=document.documentElement;return w.style.setProperty("--oc-chat-inset-left",`${oe}px`),w.style.setProperty("--oc-chat-inset-right",`${$}px`),()=>{w.style.removeProperty("--oc-chat-inset-left"),w.style.removeProperty("--oc-chat-inset-right")}},[oe,$]),a.useEffect(()=>{if(typeof document>"u")return;const w=O&&(ne||ue),se=document.documentElement;return se.classList.toggle("oc-keep-draft-starters",w),()=>se.classList.remove("oc-keep-draft-starters")},[ue,O,ne]);const Ct=a.useCallback(()=>{M(!1),N(!1)},[M,N]),Mn=a.useMemo(()=>({openChanges:({diffPath:w,staged:se}={})=>{Se(w?{path:w,staged:se===!0}:null)},openFiles:()=>ke(),openSettings:w=>{w&&D(w),H(w?"page-content":"nav")},openInstances:A?()=>z("instances"):void 0,instanceLabel:A?Re():null,openUpdate:x?()=>z("update"):void 0,closeDrawers:Ct}),[Ct,Se,ke,H,z,D,A,x]),On=a.useMemo(()=>({openSessions:()=>{O?q(!0):M(!0)},openView:w=>{if(w==="files"){ke();return}(w==="instances"||w==="update"||w==="mcp")&&z(w)},openChanges:({path:w,staged:se}={})=>{Se(w?{path:w,staged:se===!0}:null)},openSettings:w=>{w&&D(w),H(w?"page-content":"nav")}}),[O,Se,ke,H,z,D,M,q]);ua(On);const Et=a.useRef(null);os(Et,{leftOpen:O?Z:t,rightOpen:o,leftWidth:()=>O?Q.width:I.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>O?G.width:T.current?.offsetWidth||window.innerWidth,onLeftProgress:w=>{if(m.current=w,O){Qt({inner:B},w,Q.width,"left");return}Gt({drawer:I,scrim:_},"left",w)},onRightProgress:w=>{if(E.current=w,O&&Y){Qt({inner:y},w,G.width,"right");return}Gt({drawer:T,scrim:S},"right",w)},onLeftOpen:()=>{O?q(!0):M(!0)},onLeftClose:()=>{O?q(!1):M(!1)},onRightOpen:()=>N(!0),onRightClose:()=>N(!1),onDragStart:w=>{if(h(),w==="left"){m.current=O?Z?1:0:t?1:0,O?qt({shell:Q.asideRef,inner:B}):Xt({drawer:I,scrim:_,root:L});return}E.current=o?1:0,O&&Y?qt({shell:G.asideRef,inner:y}):Xt({drawer:T,scrim:S,root:C})},onDragEnd:(w,se)=>{if(w==="left"){const je=typeof se=="boolean"?se:m.current>.5;if(m.current=je?1:0,O){const Tt=Yt({shell:Q.asideRef,inner:B},je,Q.width,"left");Tt!==void 0&&v.current.push(Tt)}else Jt("left",je,{drawer:I,scrim:_,root:L});return}const st=typeof se=="boolean"?se:E.current>.5;if(E.current=st?1:0,O&&Y){const je=Yt({shell:G.asideRef,inner:y},st,G.width,"right");je!==void 0&&v.current.push(je)}else Jt("right",st,{drawer:T,scrim:S,root:C})}});const Ln=a.useCallback(()=>g?(p(!1),!0):r?(U(),!0):o?(F(),!0):t?(M(!1),!0):!1,[r,U,F,g,t,p,M,o]);_s(Ln);const nt=O?"dialog":"fullscreen";return n.jsx(Ds,{actions:Mn,children:n.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area relative flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[O?n.jsxs("aside",{ref:Q.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:oe,minWidth:oe,maxWidth:oe,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!Z,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:B,className:W("flex h-full shrink-0 flex-col",Q.isResizing&&"pointer-events-none",!Z&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:Q.isResizing||ce.slidIn?"translateX(0)":"translateX(-100%)",transition:Q.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx(ie,{children:n.jsx(Wt,{open:Z,variant:"sidebar",onOpenChange:Dn})})}),Z?n.jsx(Zt,{side:"left",isResizing:Q.isResizing,ariaLabel:"Resize left panel",handleProps:Q.handleProps}):null]}):null,n.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[O?n.jsxs(n.Fragment,{children:[n.jsx(is,{}),n.jsx(ls,{onToggleRightDrawer:Le,rightDrawerOpen:o,tabletWorkspaceTab:c,onSelectTabletWorkspaceTab:tt})]}):n.jsx(qr,{onOpenSessions:()=>M(!0),onOpenWorkspace:()=>N(!0)}),n.jsx("main",{ref:Et,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:n.jsx("div",{className:"h-full w-full",children:n.jsx(ie,{children:n.jsx(ya,{})})})})]}),O?null:n.jsx(Wt,{open:t,onOpenChange:M,drawerRefExternal:I,scrimRefExternal:_,rootRefExternal:L}),O?n.jsxs("aside",{ref:G.asideRef,className:W("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!$&&"border-l-0"),style:{width:$,minWidth:$,maxWidth:$,"--oc-ipad-sidebar-width":`${G.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!$,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:y,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",G.isResizing&&"pointer-events-none",!$&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:$?"translateX(0)":"translateX(100%)",transition:G.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx(ie,{children:n.jsx(Ht,{open:o,onClose:F,tab:c,onTabChange:u,pendingChangesDiff:k,variant:P?"panel":"drawer",drawerRefExternal:T,scrimRefExternal:S,rootRefExternal:C})})}),$?n.jsx(Zt,{side:"right",isResizing:G.isResizing,ariaLabel:"Resize right panel",handleProps:G.handleProps}):null]}):n.jsx(Ht,{open:o,onClose:F,tab:c,onTabChange:u,pendingChangesDiff:k,drawerRefExternal:T,scrimRefExternal:S,rootRefExternal:C}),r==="instances"&&A?n.jsx(lt,{open:!0,variant:nt,dialogAlign:"app",onClose:U,ariaLabel:"Instances",title:"Instances",children:n.jsx(Qr,{onConnect:U,onActiveConnectionDeleted:e})}):null,r==="settings"?n.jsx(lt,{open:!0,variant:nt,dialogAlign:"app",onClose:U,ariaLabel:"Settings",headerless:!0,children:n.jsx(ie,{children:n.jsx(ar,{forceMobile:!O,isWindowed:!0,initialMobileStage:d,onClose:U})})}):null,r==="update"?n.jsx(lt,{open:!0,variant:nt,dialogAlign:"app",onClose:U,ariaLabel:"Update",title:"Update",children:n.jsx(ie,{children:n.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:n.jsx(or,{initialUpdateDialogOpen:!0})})})}):null,n.jsx(ie,{children:n.jsx(cs,{})})]})})};function ga(e=2500){const{uiFont:t}=Ms(),[s,r]=a.useState(!1);return a.useEffect(()=>{let l=!1;const o=()=>{l||r(!0)},i=()=>{requestAnimationFrame(()=>requestAnimationFrame(o))},c=Promise.all([Os(t).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),dr.catch(()=>{})]).then(()=>{}),u=new Promise(d=>{window.setTimeout(d,e)});return Promise.race([c,u]).then(i),()=>{l=!0}},[t,e]),s}const xa=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},va=()=>{if(typeof window>"u")return!1;const t=window.Capacitor?.getPlatform?.();return t==="ios"||t==="android"},wa=e=>{const{enabled:t}=e,s=fe(l=>l.nativeNotificationsEnabled),r=a.useRef(null);a.useEffect(()=>{if(!t||!s||!va())return;let l=!1;const o=[];return Ae(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([131,130])).then(async({PushNotifications:i})=>{if(l)return;let c=await i.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await i.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const u=await i.addListener("registration",f=>{r.current=f.value,ut()?.push?.registerApnsToken?.({token:f.value,platform:nn(),environment:xa()})}),d=await i.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await i.register().catch(()=>{}),l){u.remove(),d.remove();return}o.push(()=>{u.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{l=!0,o.forEach(i=>i())}},[t,s]),a.useEffect(()=>{if(s)return;const l=r.current;if(!l)return;r.current=null,ut()?.push?.unregisterApnsToken?.({token:l})},[s])},ka=1e3;function Sa({apis:e}){const t=Ce(x=>x.initializeApp),s=Ce(x=>x.isInitialized),r=Ce(x=>x.isConnected),l=Ce(x=>x.connectionPhase),o=Ce(x=>x.providers.length),i=Ce(x=>x.loadProviders),c=an(x=>x.currentDirectory),u=re(x=>x.error),d=re(x=>x.clearError),f=fe(x=>x.setIsMobile),[k,j]=a.useState(0),[v,h]=a.useState(0),[I,_]=a.useState(!1),[L,T]=a.useState("pending"),[S,C]=a.useState(null),B=a.useMemo(()=>Re(),[]),[,y]=a.useReducer(x=>x+1,0),m=a.useMemo(()=>un(),[]),E=a.useRef(0),M=a.useRef(0),N=a.useCallback(()=>{const x=de(),U=M.current+1;if(M.current=U,!x){Xe();return}const z=()=>{t(),o===0&&i({source:"mobileApp:nativeResume"})},F=()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(O=>O+1)};We().then(O=>{if(M.current===U){if(O==="no-connection"){F();return}if(O==="needs-login"){C({kind:"auth-expired",label:Re()??""}),F();return}if(O==="unreachable"){window.setTimeout(()=>{M.current===U&&We().then(Y=>{if(M.current===U&&Y!=="switched"){if(Y==="unchanged"){z();return}Y==="needs-login"&&C({kind:"auth-expired",label:Re()??""}),F()}})},4e3);return}O!=="switched"&&z()}});const H=Date.now();H-E.current>=ka&&(E.current=H,window.dispatchEvent(new Event("pichamber:system-resume")))},[t,i,o]);Ls(),zs(N),a.useEffect(()=>Fn(),[]),a.useEffect(()=>{if(!m)return;let x;const U=()=>{window.clearTimeout(x),x=window.setTimeout(()=>N(),1500)};return window.addEventListener("online",U),()=>{window.removeEventListener("online",U),window.clearTimeout(x)}},[m,N]),a.useEffect(()=>(Nt(e),()=>Nt(null)),[e]),a.useEffect(()=>Hn(x=>{if(!!x.runtimeKey&&x.runtimeKey===x.previousRuntimeKey){ds(),y();return}fs(x),h(z=>z+1),j(z=>z+1)}),[]),a.useEffect(()=>{on()},[v]),a.useEffect(()=>{if(!m||r||de()){T("done");return}let x=!1;return T("attempting"),Xe().catch(()=>({status:"no-candidate"})).then(U=>{x||(U.status==="unreachable"?C({kind:"unreachable",label:U.label}):U.status==="needs-login"&&C({kind:"auth-expired",label:U.label}),T("done"))}),()=>{x=!0}},[]),a.useEffect(()=>{if(!m||!de())return;let x=!1;const U=z=>{z&&C(z),Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(F=>F+1)};return We().then(async z=>{if(x||z==="switched"||z==="unchanged")return;const F=Re();if(z==="needs-login"){U({kind:"auth-expired",label:F??""});return}if(z==="unreachable"){U(F?{kind:"unreachable",label:F}:null);return}const H=await Xe().catch(()=>({status:"no-candidate"}));x||H.status==="connected"||(H.status==="needs-login"?U({kind:"auth-expired",label:H.label}):H.status==="unreachable"?U({kind:"unreachable",label:H.label}):U(null))}),()=>{x=!0}},[]),a.useEffect(()=>{f(!0)},[f]),a.useEffect(()=>{m&&!de()||t()},[k,t,m]),a.useEffect(()=>{r&&o===0&&i({source:"mobileApp:recovery"})},[r,i,o]);const D=a.useRef(!1),[g,p]=a.useState(m);a.useEffect(()=>{if(!m||!r||D.current)return;if(re.getState().currentSessionId){D.current=!0,p(!1);return}const x=Ne(),U=Us(x);if(!U){D.current=!0,p(!1);return}const z=Vn(U.directory??null);if(!z){D.current=!0,p(!1);return}const F=ze();let H=0;try{H=F.getRuntimeGeneration()}catch{H=0}let O=!1;const Y=window.setTimeout(()=>p(!1),6e3);return(async()=>{let ae=null;try{ae=await Bs([z])}catch{ae=null}if(O)return;if(!ae){p(!1);return}const ne=ze();let ue=H;try{ue=ne.getRuntimeGeneration()}catch{ue=H}const q=wr({persisted:U,persistedDirectory:z,stale:ae.stale,ready:ae.readyDirectories.has(z),catalog:ae.catalog,runtimeKey:Ne(),capturedRuntimeKey:x,storeIdentityMatches:ne===F,generationMatches:ue===H});if(q.action==="wait"){p(!1);return}if(D.current=!0,q.action==="clear"){$s(x),p(!1);return}const Z=re.getState();if(Ne()!==x||ze()!==F){p(!1);return}Z.currentSessionId||Z.setCurrentSession(q.sessionId,q.directory),p(!1)})(),()=>{O=!0,window.clearTimeout(Y)}},[k,r,m]),a.useEffect(()=>{r&&ze().focusProject(c,null)},[c,r]),a.useEffect(()=>{if(!u)return;const x=window.setTimeout(()=>d(),5e3);return()=>window.clearTimeout(x)},[d,u]),a.useEffect(()=>{if(!(!r&&(m?!!de():!0))){_(!1);return}const U=window.setTimeout(()=>{_(!0)},m?4e3:8e3);return()=>window.clearTimeout(U)},[r,m,k,v]),Ws(),Xn({enabled:!0}),ps(),wa({enabled:m&&r}),da({ready:m&&r&&s});const R=ga(),b=!r&&l==="reconnecting";if(!R)return n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:n.jsx(he,{width:120,height:120,isAnimated:!0})});const A=!!de();return m&&(!A||!r&&!b)?A?n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:n.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[n.jsx(he,{width:120,height:120,isAnimated:!I}),I?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),n.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another instance."})]}),n.jsx(te,{type:"button",variant:"outline",onClick:()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(x=>x+1)},children:"Use another server"})]}):null]})}):L!=="done"?n.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[n.jsx(he,{width:120,height:120,isAnimated:!0}),B?n.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[n.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),n.jsx("div",{className:"flex justify-center",children:n.jsx(Ks,{text:B,showElapsed:!1})})]}):null]}):n.jsx(n.Fragment,{children:n.jsx(Hr,{onConnected:()=>j(x=>x+1),notice:S})}):!r&&!b?I?n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:n.jsxs("div",{className:"max-w-sm space-y-3",children:[n.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),n.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."})]})}):n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:n.jsx(he,{width:120,height:120,isAnimated:!0})}):n.jsx(ie,{children:n.jsx(Fs,{children:n.jsxs(Hs,{apis:e,children:[n.jsx(Vs,{}),n.jsx(Xs,{delayDuration:300,skipDelayDuration:150,children:n.jsxs(ms,{children:[n.jsx(hs,{}),n.jsxs("div",{className:"h-full bg-background text-foreground",children:[m&&g?n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:n.jsx(he,{width:120,height:120,isAnimated:!0})}):null,n.jsx(Gs,{embeddedBackgroundWorkEnabled:s}),n.jsx(vr,{}),n.jsx(ba,{onActiveConnectionDeleted:()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),j(x=>x+1)}}),n.jsx(ys,{}),n.jsx(bs,{}),n.jsx(Js,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),n.jsx(qs,{})]})]})})]})},v)})}const ja=()=>{(async()=>{try{await Promise.all([on(),Gn()])}catch(e){console.error("[mobile-main] settings init failed:",e)}tr(),nr(),Jn()})().finally(()=>{fr()})};function Ca(e){window.__PICHAMBER_SURFACE__="mobile",Qs(),ja(),xr(),Ys();const t=document.getElementById("root");if(!t)throw new Error("Root element not found");const r=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",l=e??ut();if(!l)throw new Error("Runtime APIs not registered");const o=r?{...l,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:l,i=n.jsx(Sa,{apis:o});zn.createRoot(t).render(n.jsx(ct.StrictMode,{children:n.jsx(Zs,{children:n.jsx(gs,{children:r?i:n.jsx(er,{children:i})})})}))}const Ua=Object.freeze(Object.defineProperty({__proto__:null,renderMobileApp:Ca},Symbol.toStringTag,{value:"Module"}));export{za as m,Ua as r};
|