@pi-chamber/web 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/assets/{DiagramEditor-DuGmiPZ5.js → DiagramEditor-BPDkGHsj.js} +1 -1
- package/dist/assets/DiagramView-D_EfDz2d.js +1 -0
- package/dist/assets/{DiffView-CBOrV4hS.js → DiffView-BmIVvheE.js} +2 -2
- package/dist/assets/FilesView-CJytSUAX.js +6 -0
- package/dist/assets/GitView-BNkzec7G.js +8 -0
- package/dist/assets/{JsonTreeView-CKWGm5MS.js → JsonTreeView-C1Kzaybf.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-qmKiFVpO.js +12 -0
- package/dist/assets/PatchDiff-D9JesZL1.js +1 -0
- package/dist/assets/{SessionSwitcherContent-z9VYCXrT.js → SessionSwitcherContent-DplV_ApH.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-DdgDKT6K.js +2 -0
- package/dist/assets/SessionUnreadDot-BdSDgvhC.js +1 -0
- package/dist/assets/SettingsView-z8uf0XyM.js +2 -0
- package/dist/assets/SettingsWindow-CPDmgNg2.js +1 -0
- package/dist/assets/ToolOutputDialog-DaF1xcM0.js +8 -0
- package/dist/assets/ToolPartDiffPreview-Di6Uo0Dt.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-DfaXovGB.js → VirtualizedFileDiff-wqcrY0yr.js} +3 -3
- package/dist/assets/collapsible-DBQnXTNm.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-Cr3jh0d6.js +3 -0
- package/dist/assets/contextFileOpenGuard-C_AOTYQD.js +1 -0
- package/dist/assets/gitStatusPredicates-BvPOjeOy.js +134 -0
- package/dist/assets/index-B8Wt2aN3.js +1 -0
- package/dist/assets/index-DIF8b4bh.css +1 -0
- package/dist/assets/index-jrfQYSvP.js +8 -0
- package/dist/assets/isDiffPlainText-L9uvgz2F.js +1 -0
- package/dist/assets/isFilePlainText-C4yk5BOo.js +1 -0
- package/dist/assets/main-C1OSzD-E.js +135 -0
- package/dist/assets/{main-DG1oZ0Wj.js → main-DCK6lLCo.js} +2 -2
- package/dist/assets/{markdownCore-DUjQU2i0.js → markdownCore-Czb_lINQ.js} +2 -2
- package/dist/assets/{miniChat-BEAtOkr9.js → miniChat-CXiSlptL.js} +2 -2
- package/dist/assets/{mobile-DOFBBQg2.js → mobile-D0HVxiyJ.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-BcG209a4.js +2 -0
- package/dist/assets/renderMobileApp-B5x_PWlc.js +11 -0
- package/dist/assets/runtimeEndpointReset-CUiPe6dQ.js +53 -0
- package/dist/assets/{runtimeSurface-CySRuLbN.js → runtimeSurface-vilE4xyj.js} +1 -1
- package/dist/assets/{useAppFontEffects-C4JL1x7k.js → useAppFontEffects-BP07Vl6M.js} +102 -103
- package/dist/assets/useFilesViewSearch-oxIKk-ea.js +7 -0
- package/dist/assets/usePushVisibilityBeacon-CChMvoTL.js +10 -0
- package/dist/assets/useSwitcherItems-_RSo3F-A.js +1 -0
- package/dist/assets/{vendor-base-ui-vkqQ2P9o.js → vendor-base-ui-CdaWtC7e.js} +1 -1
- package/dist/assets/vendor-beautiful-mermaid-D3YCkKz7.js +111 -0
- package/dist/assets/{vendor-codemirror-commands-DYppkHEk.js → vendor-codemirror-commands-CNlncqrr.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-C493X_9w.js → vendor-codemirror-language-data-BJrrV83E.js} +2 -2
- package/dist/assets/{vendor-replit-codemirror-vim-CGHHNQxC.js → vendor-replit-codemirror-vim-DaSwPsXt.js} +1 -1
- package/dist/assets/{web-components-B2Rw__yK.js → web-components-B5sMa_kC.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +17 -5
- package/server/lib/pi/session-daemon/prompt-operations.test.js +142 -0
- package/server/lib/pi/session-daemon/sdk-upgrade.test.js +157 -0
- package/server/lib/pi/session-daemon/session-daemon.js +230 -76
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +742 -0
- package/server/lib/pi/session-daemon/session-replay.js +98 -0
- package/server/lib/pi/session-daemon/session-replay.test.js +626 -0
- package/server/lib/pi/ui-settings-store.js +16 -10
- package/server/lib/pi/ui-settings-store.test.js +91 -0
- package/server/lib/stt/DOCUMENTATION.md +1 -1
- package/server/lib/stt/local/worker-client.js +11 -3
- package/server/lib/stt/local/worker-client.test.js +255 -0
- package/dist/assets/DiagramView-CHy1Glsl.js +0 -1
- package/dist/assets/FilesView-CK2YVs_W.js +0 -6
- package/dist/assets/GitView-BEFLOv_7.js +0 -8
- package/dist/assets/MarkdownRendererImpl-hE_nmSqe.js +0 -12
- package/dist/assets/PatchDiff-BagRxMON.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-icxJk_lT.js +0 -2
- package/dist/assets/SessionUnreadDot-Bv-5KguB.js +0 -1
- package/dist/assets/SettingsView-Ck0qxtKP.js +0 -2
- package/dist/assets/SettingsWindow-GQRL2CdD.js +0 -1
- package/dist/assets/ToolOutputDialog-CxJUXVZW.js +0 -8
- package/dist/assets/ToolPartDiffPreview-BXuLRWHT.js +0 -1
- package/dist/assets/collapsible-szfZ0Syc.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DG_E6iaN.js +0 -3
- package/dist/assets/contextFileOpenGuard-DPBE3ELv.js +0 -1
- package/dist/assets/gitStatusPredicates-OljV4Bb2.js +0 -134
- package/dist/assets/index-DNoEeZ2U.css +0 -1
- package/dist/assets/index-DmexVlTQ.js +0 -1
- package/dist/assets/index-KIdiBFJs.js +0 -8
- package/dist/assets/isDiffPlainText-aikgiqLb.js +0 -1
- package/dist/assets/isFilePlainText-D-Dl6LqX.js +0 -1
- package/dist/assets/main-BXdraZTZ.js +0 -135
- package/dist/assets/renderElectronMiniChatApp-B0K72YnS.js +0 -2
- package/dist/assets/renderMobileApp-Ca_BO_s4.js +0 -11
- package/dist/assets/runtimeEndpointReset-Cx2tsgTo.js +0 -54
- package/dist/assets/useFilesViewSearch-Du0DnmKs.js +0 -7
- package/dist/assets/usePushVisibilityBeacon-BnHxIv4r.js +0 -10
- package/dist/assets/useSwitcherItems-C91mwPJD.js +0 -1
- package/dist/assets/vendor-beautiful-mermaid-DneUawHp.js +0 -119
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-icxJk_lT.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-C4JL1x7k.js","assets/vendor-zustand-GVb4H8HE.js","assets/index-KIdiBFJs.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-DNoEeZ2U.css","assets/vendor-base-ui-vkqQ2P9o.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-CySRuLbN.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-C493X_9w.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.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 pe,e as we}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{c as V,f as q,o as ve,q as Y,u as oe,t as F,v as je,w as be,x as le,j as Se,y as Ie,z as Ce}from"./index-KIdiBFJs.js";import{u as Ne,a as Pe,s as De}from"./usePushVisibilityBeacon-BnHxIv4r.js";import{Q as Me,I as K,R as ke,S as _e,U as Ee,V as Le,W as Oe,X as Ae,k as S,Y as Te,c as ie,Z as w,_ as ae,$ as Re,j as Be,a0 as ze,a1 as Fe,a2 as Ue,a3 as de,a4 as ue,a5 as me,a6 as $e,a7 as We,t as He,G as Ge,a8 as Ve,a9 as Ke,aa as qe,ab as Je,ac as Qe,ad as Xe,ae as Ye,af as Ze,ag as et,ah as tt,ai as rt,aj as st,ak as nt,al as ot}from"./useAppFontEffects-C4JL1x7k.js";import{_ as it}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-vkqQ2P9o.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-CySRuLbN.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-C493X_9w.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.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 at=({mode:t,children:s})=>e.jsx(Me.Provider,{value:t,children:s}),ct=Oe,lt=Ae,dt=({totalTokens:t,percentage:s,colorPercentage:n,contextLimit:c,outputLimit:i,size:m="default",isMobile:l=!1,hideIcon:M=!1,showPercentIcon:L=!1,className:h,valueClassName:p,percentIconClassName:k,onClick:N,pressed:_=!1,cacheRead:y,cacheWrite:I,cacheHitPercent:v})=>{const[P,j]=a.useState(!1),E=typeof n=="number"?n:s,o=ct(s)??0,g=lt(E),x=g==="critical"?"var(--status-error)":g==="warn"?"var(--status-warning)":"var(--status-success)",d=b=>b>=1e6?`${(b/1e6).toFixed(1)}M`:b>=1e3?`${(b/1e3).toFixed(1)}K`:b.toFixed(1).replace(/\.0$/,""),U=b=>b>=90?"text-status-error":b>=75?"text-status-warning":"text-status-success",f=20,$=3,W=(f-$)/2,J=2*Math.PI*W,ce=J*(1-o/100),H=typeof i=="number"?Math.max(i,0):0,O=typeof y=="number"&&typeof I=="number",Q=O?Math.max(0,y):0,Z=O?Math.max(0,I):0,R=typeof v=="number"&&Number.isFinite(v),T=[`Used tokens: ${d(t)}`,`Context limit: ${d(c)}`,`Output limit: ${d(H)}`,...O?[`Cache read: ${d(Q)}`,`Cache write: ${d(Z)}`]:[],...R?[`Cache hit: ${v.toFixed(1)}%`]:[],`${Math.min(s,999).toFixed(1)}% used`],A=!l&&typeof N=="function",B=e.jsxs(e.Fragment,{children:[!l&&!M&&e.jsx(K,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:V("font-medium inline-flex items-center gap-1.5",p),children:L?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${f} ${f}`,className:V("h-3.5 w-3.5 -rotate-90",k),role:"progressbar","aria-valuenow":Math.round(o),"aria-valuemin":0,"aria-valuemax":100,children:[e.jsx("circle",{cx:f/2,cy:f/2,r:W,fill:"none",stroke:"var(--interactive-border)",strokeWidth:$}),e.jsx("circle",{cx:f/2,cy:f/2,r:W,fill:"none",stroke:x,strokeWidth:$,strokeLinecap:"round",strokeDasharray:J,strokeDashoffset:ce,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:U(E),children:Math.min(s,999).toFixed(1)}),"%"]})})]}),C=V("app-region-no-drag flex items-center gap-1.5 select-none",m==="compact"?"typography-micro":"typography-meta",A?V("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",h),D=A?e.jsx("button",{type:"button",className:C,"aria-label":"Context usage","aria-pressed":_,onClick:N,children:B}):e.jsx("div",{className:C,"aria-label":"Context usage",onClick:l?()=>j(!0):void 0,children:B});return l?e.jsxs(e.Fragment,{children:[D,e.jsx(ke,{open:P,onClose:()=>j(!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:d(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:d(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:d(H)})]}),O?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:d(Q)})]}),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:d(Z)})]})]}):null,R?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:[v.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:V("typography-meta font-semibold",U(E)),children:[Math.min(s,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(_e,{children:[e.jsx(Ee,{asChild:!0,children:D}),e.jsx(Le,{children:e.jsx("div",{className:"space-y-0.5",children:T.map(b=>e.jsx("p",{className:"typography-micro leading-tight",children:b},b))})})]})},ut=a.lazy(()=>it(()=>import("./SessionSwitcherDropdown-icxJk_lT.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}))),mt=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(/\/+$/,"")},pt=({mode:t})=>{const s=S(r=>r.currentSessionId),n=S(r=>!!r.newSessionDraft?.open),c=S(r=>r.newSessionDraft?.selectedProjectId??null),i=q(r=>r.currentDirectory),m=ie(r=>r.projects),l=ie(r=>r.getActiveProject()),M=w(r=>r.getCurrentModel),L=w(r=>r.providers),h=ae(),p=Re(s??""),k=Be(),N=ze(r=>r.ensureStatus),_=S(r=>r.newSessionDraft?.open?re(r.newSessionDraft.directoryOverride??""):""),[y,I]=a.useState(!1),v=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,P=Number.isFinite(v)&&v>0,{usesFramelessChrome:j,side:E}=Fe(),o=P?v>=26?"h-12":v<=15?"h-14":"":"",g=a.useMemo(()=>s?h.find(r=>r.id===s)??null:null,[s,h]);a.useEffect(()=>{ve()&&Y("desktop_get_window_pinned").then(r=>{typeof r?.pinned=="boolean"&&I(r.pinned)})},[]);const x=g?.title?.trim()||(n||t==="draft"?"New session":"Session"),d=re(g?.directory??null),U=re(i),f=d||_||U,$=mt(f);a.useEffect(()=>{f&&N(f,k.git).catch(()=>{})},[N,f,k.git]);const W=a.useMemo(()=>{const r=f;return r?m.map(u=>({...u,normalizedPath:re(u.path)})).filter(u=>u.normalizedPath&&(u.normalizedPath===r||r.startsWith(`${u.normalizedPath}/`))).sort((u,G)=>G.path.length-u.path.length)[0]??null:null},[f,m]),J=a.useMemo(()=>{const r=W??l;if(!r)return $||"PiChamber";const u=r.label?.trim();return u||(r.path.split(/[\\/]/).filter(Boolean).at(-1)??r.path)},[l,$,W]),H=Ue(f||null),O=H&&H!=="HEAD"?H:null,Q=M(),Z=a.useMemo(()=>{for(let r=p.length-1;r>=0;r-=1){const u=p[r];if(u.role!=="assistant"||typeof u.providerID!="string"||typeof u.modelID!="string")continue;const te=L.find(X=>X.id===u.providerID)?.models.find(X=>X.id===u.modelID);if(te)return te}},[p,L]),R=Q?.limit?Q:Z,T=R&&typeof R.limit=="object"&&R.limit!==null?R.limit:null,A=T&&typeof T.context=="number"?T.context:0,B=T&&typeof T.output=="number"?T.output:0,C=a.useMemo(()=>{if(!s||p.length===0)return null;let r,u;for(let se=p.length-1;se>=0;se-=1){const ne=p[se];if(ne.role!=="assistant")continue;const z=ne.tokens;if(!z)continue;if(z.input+z.output+z.reasoning+(z.cache?.read??0)+(z.cache?.write??0)>0){r=z,u=ne.id;break}}if(!r)return null;const G=r.input+r.output+r.reasoning+(r.cache?.read??0)+(r.cache?.write??0),te=A>0?A:2e5,X=A>0?Math.round(G/A*100):0,ge=B>0?Math.round(r.output/B*100):void 0;return{totalTokens:G,percentage:X,contextLimit:A||0,outputLimit:B||void 0,normalizedOutput:ge,thresholdLimit:te,lastMessageId:u}},[A,s,p,B]),[D,b]=a.useState(null),fe={WebkitAppRegion:"drag"},ee={WebkitAppRegion:"no-drag"};a.useEffect(()=>{if(!s){b(r=>r===null?r:null);return}if(C&&C.totalTokens>0){b(r=>r&&r.totalTokens===C.totalTokens&&r.percentage===C.percentage&&r.contextLimit===C.contextLimit&&(r.outputLimit??0)===(C.outputLimit??0)&&(r.normalizedOutput??0)===(C.normalizedOutput??0)&&r.thresholdLimit===C.thresholdLimit&&r.lastMessageId===C.lastMessageId?r:C);return}b(r=>r===null?r:null)},[C,s]);const he=D&&D.contextLimit>0?Math.min(999,D.totalTokens/D.contextLimit*100):0,xe=a.useCallback(()=>{const r=!y;I(r),Y("desktop_set_window_pinned",{pinned:r}).catch(()=>{I(!r)})},[y]),ye=a.useCallback(()=>{const r=s?{sessionId:s,directory:g?.directory??i??""}:{mode:"draft",directory:f||i||"",projectId:c};Y("desktop_focus_main_window",r).then(u=>u?.focused===!0?Y("desktop_close_current_window"):null)},[i,s,c,f,g]);return e.jsxs("header",{className:V("flex items-center gap-3 bg-background pr-3",P?"pl-[5.5rem]":"pl-3",j?"h-12":o||"min-h-14"),style:fe,children:[j&&E==="left"?e.jsx(de,{visible:!0,position:"left"}):null,e.jsx(pe.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:x}),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:J}),O?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(K,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:O})]}):null]})]}),children:e.jsx(ut,{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:x}),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:J}),O?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(K,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:O})]}):null]})]})})}),e.jsx("div",{className:"min-w-0 flex-1"}),D&&D.totalTokens>0?e.jsx(dt,{totalTokens:D.totalTokens,percentage:he,colorPercentage:D.percentage,contextLimit:D.contextLimit,outputLimit:D.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(ue,{type:"button",variant:"ghost",size:"icon",onClick:xe,"aria-label":y?"Unpin Mini Chat window":"Pin Mini Chat window",title:y?"Unpin window":"Pin above other windows",style:ee,children:y?e.jsx(K,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(K,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(ue,{type:"button",variant:"ghost",size:"icon",onClick:ye,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(K,{name:"external-link",className:"h-4 w-4"})}),e.jsx(de,{visible:j&&E==="right",position:"right"})]})},ft=({mode:t,autoOpenDraft:s=!1,unavailable:n=!1})=>{const c=S(i=>i.currentSessionId);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[e.jsx(pt,{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(at,{mode:"mini-chat",children:e.jsx(Te,{autoOpenDraft:s},c??"no-session")})})]})},ht=()=>{const t=oe(i=>i.shortcutOverrides),s=q(i=>i.currentDirectory),n=ie(i=>i.getActiveProject()),c=S(i=>i.openNewSessionDraft);a.useEffect(()=>{const i=l=>be(l,t),m=l=>{if(F(l,i("focus_input"))){l.preventDefault(),me();return}if(je()&&F(l,i("new_mini_chat"))){l.preventDefault(),Y("desktop_open_draft_mini_chat_window",{directory:s||n?.path||"",projectId:n?.id??null})?.catch(h=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",h)});return}if(F(l,i("new_chat"))){l.preventDefault(),c({selectedProjectId:n?.id??null,directoryOverride:s||n?.path||null,preserveDirectoryOverride:!!(s||n?.path)}),me();return}if(F(l,i("open_model_selector"))){l.preventDefault();const{isModelSelectorOpen:h,setModelSelectorOpen:p}=oe.getState();p(!h);return}if(F(l,i("cycle_thinking_variant"))){if(w.getState().getCurrentModelVariants().length===0)return;l.preventDefault(),$e(1).then(k=>{const N=S.getState().currentSessionId,_=w.getState().currentAgentName,y=w.getState().currentProviderId,I=w.getState().currentModelId;N&&_&&y&&I&&We.getState().saveAgentModelVariantForSession(N,_,y,I,k)}).catch(()=>{He.error("Couldn't update thinking")});return}const M=F(l,i("cycle_favorite_model_forward")),L=F(l,i("cycle_favorite_model_backward"));if(M||L){const{favoriteModels:h,addRecentModel:p}=oe.getState();if(h.length===0)return;l.preventDefault();const{currentProviderId:k,currentModelId:N,setProvider:_,setModel:y}=w.getState(),I=h.findIndex(j=>j.providerID===k&&j.modelID===N),P=h[(I+(M?1:-1)+h.length)%h.length];_(P.providerID),y(P.modelID),p(P.providerID,P.modelID)}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n?.id,n?.path,s,c,t])},xt="pichamber:mini-chat-presence",yt=()=>{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}},gt=({config:t})=>{const s=ae(),n=q(o=>o.currentDirectory),c=q(o=>o.setDirectory),i=S(o=>o.currentSessionId),m=S(o=>!!o.newSessionDraft?.open),l=S(o=>o.newSessionDraft?.open?o.newSessionDraft.bootstrapPendingDirectory??o.newSessionDraft.directoryOverride??"":""),M=S(o=>o.setCurrentSession),L=S(o=>o.openNewSessionDraft),h=w(o=>o.initializeApp),p=w(o=>o.isInitialized),k=w(o=>o.isConnected),N=w(o=>o.loadProviders),_=w(o=>o.loadAgents),y=w(o=>o.providers.length),I=w(o=>o.agents.length),v=tt();a.useEffect(()=>{h()},[h]),a.useEffect(()=>{if(p)return;let o=!0,g=0;const x=window.setInterval(()=>{if(o){if(g+=1,g>10){window.clearInterval(x);return}w.getState().isInitialized||w.getState().initializeApp()}},1e3);return()=>{o=!1,window.clearInterval(x)}},[p]);const P=a.useRef(!1);a.useEffect(()=>{if(!P.current&&t.mode==="session"&&t.directory){if(n===t.directory){P.current=!0;return}c(t.directory,{showOverlay:!1}),P.current=!0}},[t.directory,t.mode,n,c]),a.useEffect(()=>{t.mode!=="draft"||!m||i||!l||n===l||c(l,{showOverlay:!1})},[t.mode,n,i,l,m,c]),a.useEffect(()=>{k&&(y===0&&N({source:"electronMiniChat:recovery"}),I===0&&_({source:"electronMiniChat:recovery"}))},[I,k,_,N,y]);const j=a.useRef(!1);a.useEffect(()=>{if(j.current||t.mode!=="session"||!t.sessionId)return;if(i===t.sessionId){j.current=!0;return}if(i){j.current=!0;return}const o=s.find(x=>x.id===t.sessionId);if(!o){v.ensureSessionRenderable(t.sessionId);return}const g=o.directory??t.directory;M(t.sessionId,g),j.current=!0},[t,i,s,M,v]),a.useEffect(()=>{const o=g=>{const x=g.detail,d=typeof x?.sessionId=="string"?x.sessionId.trim():"";if(!d||S.getState().currentSessionId===d)return;const U=typeof x?.directory=="string"&&x.directory.trim().length>0?x.directory.trim():s.find(f=>f.id===d)?.directory??null;v.ensureSessionRenderable(d),M(d,U),j.current=!0};return window.addEventListener("pichamber:open-session",o),()=>window.removeEventListener("pichamber:open-session",o)},[s,M,v]),a.useEffect(()=>{t.mode!=="draft"||m||i||L({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,i,m,L]);const E=a.useRef(!1);return a.useEffect(()=>{if(E.current||!p)return;const o=()=>{if(E.current)return;E.current=!0;const d=typeof document<"u"?document.getElementById("initial-loading"):null;d&&(d.classList.add("fade-out"),window.setTimeout(()=>d.remove(),300))},g=t.mode==="session"?i===t.sessionId:m,x=window.setTimeout(o,g?100:1500);return()=>window.clearTimeout(x)},[p,t.mode,t.sessionId,i,m]),null},wt=()=>{const t=S(n=>n.currentSessionId),s=q(n=>n.currentDirectory);return a.useEffect(()=>{if(!t||!s||typeof BroadcastChannel>"u")return;const n=new BroadcastChannel(xt),c=l=>{n.postMessage({type:"mini-chat-session-presence",sessionId:t,directory:s,viewed:l})};c(!0);const i=window.setInterval(()=>c(!0),5e3),m=()=>c(!1);return window.addEventListener("beforeunload",m),()=>{window.clearInterval(i),window.removeEventListener("beforeunload",m),c(!1),n.close()}},[s,t]),null},vt=t=>{const s=ae(),n=S(m=>m.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 m=window.setTimeout(()=>i(!0),5e3);return()=>window.clearTimeout(m)},[t.mode,t.sessionId,n,s]),c};function jt({apis:t}){const s=a.useMemo(()=>yt(),[]),n=q(c=>c.currentDirectory);return a.useEffect(()=>{const c=n||s.directory;c&&Ge().focusProject(c,null)},[s.directory,n]),a.useEffect(()=>(le(t),()=>le(null)),[t]),Ve(),ht(),Ne({enabled:!0}),e.jsx(Ke,{children:e.jsx(qe,{directory:n||s.directory,children:e.jsxs(Je,{apis:t,children:[e.jsx(Qe,{}),e.jsx(Xe,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(bt,{config:s}),e.jsx(Ye,{}),e.jsx(Ze,{})]})})]})})})}const bt=({config:t})=>{const s=vt(t);return e.jsxs(e.Fragment,{children:[e.jsx(gt,{config:t}),e.jsx(wt,{}),e.jsx(et,{embeddedBackgroundWorkEnabled:!0}),e.jsx(ft,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:s})]})},St=()=>{Ie().then(async()=>{try{await Promise.all([Ce(),Pe()])}catch(t){console.error("[mini-chat-main] settings init failed:",t)}nt(),ot(),De()}).catch(t=>{console.error("[mini-chat-main] appearance init failed:",t)})};function Xr(t){const s=t??Se();if(!s)throw new Error("Runtime APIs not registered");St();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");we.createRoot(n).render(e.jsx(pe.StrictMode,{children:e.jsx(rt,{children:e.jsx(st,{children:e.jsx(jt,{apis:s})})})}))}export{Xr as renderElectronMiniChatApp};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-CK2YVs_W.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-KIdiBFJs.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-DNoEeZ2U.css","assets/useAppFontEffects-C4JL1x7k.js","assets/vendor-base-ui-vkqQ2P9o.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-CySRuLbN.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-C493X_9w.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.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/DiagramEditor-DuGmiPZ5.js","assets/vendor-react-drawio-BYDptOsj.js","assets/runtimeEndpointReset-Cx2tsgTo.js","assets/SessionUnreadDot-Bv-5KguB.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/useFilesViewSearch-Du0DnmKs.js","assets/JsonTreeView-CKWGm5MS.js","assets/web-components-B2Rw__yK.js","assets/computeVirtualFileMetrics-DG_E6iaN.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-D-Dl6LqX.js","assets/vendor-codemirror-search-BV44140v.js","assets/vendor-replit-codemirror-vim-CGHHNQxC.js","assets/GitView-BEFLOv_7.js","assets/gitStatusPredicates-OljV4Bb2.js","assets/VirtualizedFileDiff-DfaXovGB.js","assets/isDiffPlainText-aikgiqLb.js","assets/vendor-diff-C3JhlQdm.js","assets/collapsible-szfZ0Syc.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 it,j as n,R as a,b as Pe,e as On}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{u as le,h as Ye,m as tn,U as Tt,i as q,F as ue,V as Ee,W as $e,r as nn,X as zn,Y as Un,Z as sn,_ as Bn,$ as $n,c as B,f as rn,a0 as Wn,j as lt,a1 as Fn,x as Rt,a2 as Kn,z as an,y as Hn}from"./index-KIdiBFJs.js";import{u as Vn,a as Xn,s as Gn}from"./usePushVisibilityBeacon-BnHxIv4r.js";import{f as Te,g as Jn,M as qn,h as Yn,i as Qn,D as Nt,j as Pt,k as It,l as Zn,m as At,n as es,s as ts,S as ns,T as ss,o as rs,p as as,q as os,H as is,A as ls,r as cs,t as us,v as ds,w as fs,F as ps,x as ms,y as hs,W as ys,z as bs}from"./runtimeEndpointReset-Cx2tsgTo.js";import{bx as gs,by as xs,c as on,d as vs,e as ws,r as ft,g as ks,t as nt,aA as Ss,I as $,a4 as ee,bz as me,k as ae,l as js,m as Cs,bA as Es,bB as Ts,a9 as oe,bC as ln,bD as Rs,bE as Ns,bF as Ps,bG as Is,bH as As,bI as _s,bJ as Ds,bK as Ms,Z as ce,bL as Ls,bM as Os,bN as zs,bO as Us,bP as Bs,G as $s,a8 as Ws,bQ as Fs,aa as Ks,ab as Hs,ac as Vs,ad as Xs,bR as Gs,ae as Js,af as qs,bS as Ys,bT as Qs,ai as Zs,aj as er,ak as tr,al as nr}from"./useAppFontEffects-C4JL1x7k.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 Ie}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as ar,A as or}from"./SettingsView-Ck0qxtKP.js";import{f as ir,a as lr,S as cr,g as cn}from"./SessionUnreadDot-Bv-5KguB.js";import{u as ur}from"./useSwitcherItems-C91mwPJD.js";let un=null,_t=!1;const dr=new Promise(e=>{un=e});function fr(){_t||(_t=!0,un?.())}const pr=6,mr=e=>e.parentID??null,Dt=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()||Dt(s.path):Dt(e)},br=()=>{const e=gs.getState().activeSessions,t=xs.getState().index.session.unseenCount,s=le.getState().notifyOnSubtasks,r=on.getState().projects,l=vs.getState().ids,o=ws.getState().rankById;let i=0;const c=[];for(const u of e){const f=mr(u)!==null,T=(t[u.id]??0)>0&&(!f||s);T&&(i+=1),f||c.push({session:u,unread:T,project:yr(ft(u),r)})}c.sort((u,f)=>ks(u.session,f.session,l,o));const d=c.slice(0,pr).map(({session:u,unread:f,project:E})=>({id:u.id,title:u.title??"",unread:f,project:E}));return{runtimeKey:Ye(),attentionCount:i,recentSessions:d}},gr="__PICHAMBER_WIDGET_SNAPSHOT__",xr=()=>{typeof window>"u"||(window[gr]=()=>{try{return JSON.stringify(br())}catch{return null}})},st="mobile-app-update-available",Mt="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=it.useRef(new Set);return it.useEffect(()=>{if(tn()!=="android"||t!=="mobile"||!e||!s||!r){nt.dismiss(st);return}Tt().getItem(Mt)!==s&&(l.current.has(s)||(l.current.add(s),nt.info("PiChamber update available",{id:st,description:`Version ${s} is ready for Android.`,duration:1/0,icon:n.jsx($,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{Ss(r)}},cancel:{label:"Dismiss",onClick:()=>{Tt().setItem(Mt,s),nt.dismiss(st)}}})))},[e,r,t,s]),null},Xe="pichamber.mobile.connections.v1",wr="pichamber.mobile.",Lt="pichamber.mobile.deviceId",dn=12,kr=8e3,Sr=2500,jr=3e3,Ge=2500,Ae=15e3,Cr=1500,Er=5e3,Tr=()=>{try{const e=window.localStorage.getItem(Lt);if(e&&e.trim())return e.trim();const t=crypto.randomUUID();return window.localStorage.setItem(Lt,t),t}catch{return crypto.randomUUID()}},Ot=()=>`mobile:${Tr()}`,zt=()=>{try{const e=sr.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},fn=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:t=>t===e}},xe=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(/\/+$/,"")},Ue=e=>{try{return new URL(e).host}catch{return e}},_e=e=>{try{return xe(e)}catch{return e.trim().replace(/\/+$/g,"")}},pt=(e,t)=>_e(e)===_e(t),mt=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,Rr=e=>`relay://${e.serverId}`,Qe=e=>e.candidates.filter(t=>t.kind==="direct"),be=e=>{const t=e.candidates.find(s=>s.kind==="relay");return t&&t.kind==="relay"?t.relay:null},ie=e=>{const t=Qe(e)[0];if(t)return t.url;const s=be(e);return s?Rr(s):""},X=e=>{const t=be(e);if(t)return mt(t);const s=Qe(e)[0];return s?_e(s.url):""},Je=(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=>_e(o.url)));return t.some(o=>o.kind==="relay"?r!==null&&o.relay.serverId===r:l.has(_e(o.url)))},ht=e=>{const t=(()=>{try{return xe(e)}catch{return""}})();return t?[{kind:"direct",url:t}]:[]},Ut=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(...ht(e.url)),e.relay&&t.push({kind:"relay",relay:e.relay}),t},yt=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}}},Nr=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=yt(t.relay);return s?{kind:"relay",relay:s}:null}return null},Pr=e=>{if(e.mode==="relay"){const t=yt(e.relay);return t?[{kind:"relay",relay:t}]:[]}return typeof e.url=="string"?ht(e.url):[]},ct=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},ve=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(Xe)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const t=q();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(Nr).filter(d=>!!d):Pr(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:Ue(ie({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)},bt=e=>{if(typeof window>"u")return;const t=q(),s=e.slice(0,dn).map(r=>{const l={id:r.id,label:r.label,candidates:r.candidates.map(ct),lastUsedAt:r.lastUsedAt};return t?{...l,hasToken:!!(r.hasToken||r.clientToken)}:{...l,clientToken:r.clientToken}});try{window.localStorage.setItem(Xe,JSON.stringify(s))}catch(r){console.warn("[mobile-storage] failed to persist connection metadata",r)}},pn=(e,t)=>{const s=e.find(o=>t.id&&o.id===t.id||Je(o.candidates,t.candidates)),r=q(),l={id:t.id||s?.id||crypto.randomUUID(),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&&!Je(o.candidates,t.candidates))].slice(0,dn)},gt=rr,Ir=0,xt=e=>`${wr}token.${encodeURIComponent(e)}`,Ar=async(e,t)=>{let s;const r=new Promise(l=>{s=window.setTimeout(()=>l(t),jr)});try{return await Promise.race([e.catch(()=>t),r])}finally{s!==void 0&&window.clearTimeout(s)}},vt=async(e,t,s)=>q()?Ar(t().catch(r=>(console.warn(`[mobile-storage] ${e} failed`,r),s)),s):s,We=async e=>{const t=await vt("secure:read",async()=>(await gt.internalGetItem({prefixedKey:xt(e),sync:!1})).data,null);return typeof t=="string"&&t.trim()?t:void 0},he=async(e,t)=>vt("secure:write",async()=>(await gt.internalSetItem({prefixedKey:xt(e),data:t,sync:!1,access:Ir}),!0),!1),_r=async e=>{await vt("secure:delete",async()=>(await gt.internalRemoveItem({prefixedKey:xt(e),sync:!1}),!0),!1)},mn=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,d=typeof i.clientToken=="string"?i.clientToken.trim():"";if(!c||!d)return o;if(!await t(c,d))return r+=1,o;s+=1;const{clientToken:u,...f}=i;return{...f,hasToken:!0}})),migrated:s,failed:r}},hn=async()=>{if(typeof window>"u"||!q())return;let e;try{e=JSON.parse(window.localStorage.getItem(Xe)||"[]")}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 mn(e,async(r,l)=>{const o=_e(r);return await he(o,l)?await We(o)===l:!1});if(s.migrated>0)try{window.localStorage.setItem(Xe,JSON.stringify(s.records))}catch(r){console.warn("[mobile-storage] failed to finalize secure token migration",r)}},yn=async()=>(await hn(),ve()),Fe=async e=>{const t=pn(ve(),e);return bt(t),q()&&e.clientToken&&await he(X({candidates:e.candidates}),e.clientToken),t},bn=async e=>{const t=ve(),s=t.find(l=>l.id===e)??null,r=t.filter(l=>l.id!==e);return bt(r),s&&q()&&await _r(X(s)),r},wt=e=>{try{return JSON.stringify(e)}catch{return String(e)}},Y=(e,t={})=>{console.info("[mobile-connect]",e,wt(t)),Un("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})},Dr=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},Mr=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},Lr=async(e,t)=>{if(!q())return null;try{const{CapacitorHttp:s}=await Ie(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:Mr(t?.body)});return{ok:l.status>=200&&l.status<300,status:l.status,source:"native-http",json:async()=>Dr(l.data)}}catch(s){return console.warn("[mobile-connect]","native-http failed",wt({url:e,error:s instanceof Error?s.message:String(s)})),null}},Or=async(e,t)=>{const s=await fetch(e,t).catch(r=>(console.warn("[mobile-connect]","browser-fetch failed",wt({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},de=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)}},ge=async(e,t,s)=>{const r=s?.totalTimeoutMs??kr,l=Date.now(),o=await de(Math.min(Sr,r),Lr(e,t));if(o)return o;const i=new AbortController,c=Math.max(500,r-(Date.now()-l));return de(c,Or(e,{...t,signal:i.signal}),()=>i.abort())},Ze=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}},zr=async(e,t,s,r=Ae,l)=>{const o=sn({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,d=await de(r,o.fetch("/auth/session",{headers:c}).catch(()=>null));if(Y("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!t}),!d)return i("unreachable");if(d.status===401)return i(t?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return i("auth-failed");const u=await Ze(d);return u&&u.disabled!==!0&&u.authenticated===!1?i(t?"auth-failed":"needs-login"):i("ok")}catch(c){throw o.close(),c}},Ur=(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&&zn(i,l),Ee({apiBaseUrl:o,clientToken:t,runtimeKey:r??mt(e),relay:i})},qe=async(e,t,s)=>{const r=s?.fast?{totalTimeoutMs:Ge}:void 0,l=be({candidates:e})?.serverId??null,o=e.find(u=>u.kind==="relay")??null,i=e.filter(u=>u.kind==="direct"),c=async()=>{for(const u of i){const f=xe(u.url)||u.url,E=t?{Authorization:`Bearer ${t}`}:void 0,T=await ge(`${f}/health`,{method:"GET"},r);if(!T?.ok)continue;if(l){const _=await T.json().catch(()=>null),L=_&&typeof _=="object"?_.serverId:null;if(typeof L=="string"&&L&&L!==l){Y("probe:server-id-mismatch",{url:f});continue}}const w=await ge(`${f}/auth/session`,{method:"GET",credentials:t?"omit":"include",headers:E},r);if(w?.status===401)return{status:"needs-login"};if(!w||!w.ok&&w.status!==404)continue;const p=await Ze(w);if(p&&p.disabled!==!0&&p.authenticated===!1)return{status:"needs-login"};const A=p?.disabled===!0;return!t&&q()&&!A&&p?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},d=async()=>{if(!o)return{status:"unreachable"};const{outcome:u,tunnel:f}=await zr(o.relay,t,void 0,s?.fast?Ge:void 0,{keepTunnel:!0});return u==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:f}}:u==="needs-login"||u==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?i.length===0?d():new Promise(u=>{let f=!1,E=!1,T,w=null,p=null;const A=R=>{R?.status==="ok"&&R.transport.kind==="relay"&&R.transport.tunnel?.close()},_=R=>{f||(f=!0,u(R))},L=()=>{E||f||(T!==void 0&&(window.clearTimeout(T),T=void 0),d().then(R=>{if(p=R,f||E){A(R);return}if(R.status==="ok"||R.status==="needs-login"){_(R);return}w&&_(w)}))};c().then(R=>{if(w=R,!f){if(R.status==="ok"||R.status==="needs-login"){E=!0,T!==void 0&&window.clearTimeout(T),A(p),_(R);return}if(p){_(p);return}L()}}),T=window.setTimeout(L,Cr)}):c()},ye=(e,t,s)=>{e.kind==="relay"?Ur(e.relay,t,s?.grant,s?.runtimeKey,e.tunnel):Ee({apiBaseUrl:e.url,clientToken:t,runtimeKey:s?.runtimeKey}),kn()},Re=()=>{const e=ve()[0];return e?.label?.trim()?e.label:null},Ve=async()=>{await hn();const e=ve()[0];if(!e)return{status:"no-candidate"};let t;if(q()){if(!e.hasToken)return{status:"no-candidate"};if(t=await We(X(e)),!t)return{status:"no-candidate"}}else if(t=e.clientToken,!t)return{status:"no-candidate"};const s=await qe(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 Fe({id:e.id,label:e.label,candidates:e.candidates}),ye(s.transport,t,{runtimeKey:X(e)}),{status:"connected"})},gn=async(e,t)=>{let s="";try{s=xe(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:Ge}:void 0;if(!(await ge(`${s}/health`,{method:"GET",headers:l},o))?.ok)return!1;const c=await ge(`${s}/auth/session`,{method:"GET",credentials:r?"omit":"include",headers:l},o);if(!c||!c.ok&&c.status!==404)return!1;const d=await Ze(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},Bt=async e=>{const t=be({candidates:e})?.serverId??null;for(const s of e){if(s.kind==="relay"){const o=sn(s.relay),i=await de(Ae,o.fetch("/health").catch(()=>null));if(Y("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=xe(s.url)||s.url,l=await ge(`${r}/health`,{method:"GET"});if(Y("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){Y("establish:server-id-mismatch",{url:r});continue}}return{kind:"direct",url:r}}}return null},Br=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=yt({relayUrl:t.relayUrl,serverId:t.serverId,hostEncPubJwk:t.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return ht(t.url)}),xn=async(e,t)=>{if(!$e())return gn(e,t);const s=await de(t?.fast?Ge:Ae,nn("/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 Ze(s);return!(r&&r.disabled!==!0&&r.authenticated===!1)},$r=e=>e.kind==="relay"?$e():!$e()&&pt(e.url,ue()),vn=()=>{const e=Ye();return e?ve().find(t=>X(t)===e)??null:null},ut=e=>{const t=Ye();return!!t&&X(e)===t},Be=async()=>{const e=vn();if(!e)return"no-connection";let t;if(q()?t=e.hasToken?await We(X(e)):void 0:t=e.clientToken,!t)return"unreachable";const s=e.candidates.findIndex(c=>$r(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 qe(r,t,{fast:!0});if(l.status==="ok")return await Fe({id:e.id,label:e.label,candidates:e.candidates}),ye(l.transport,t,{runtimeKey:X(e)}),"switched";if(l.status==="needs-login")return"needs-login";if(s>=0&&await xn({url:ue(),clientToken:t},{fast:!0}))return kn(),"unchanged";const o=s>=0?e.candidates.slice(s+1):[],i=await qe(o,t,{fast:!0});return i.status==="ok"?(await Fe({id:e.id,label:e.label,candidates:e.candidates}),ye(i.transport,t,{runtimeKey:X(e)}),"switched"):i.status==="needs-login"?"needs-login":"unreachable"};let rt=!1;const wn=async()=>{if(rt)return"skipped";const e=vn();if(!e)return Y("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const t=be(e);if(!t)return Y("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";rt=!0;try{const s=await de(Ae,nn("/api/client-auth/connection/candidates").then(u=>u).catch(()=>null));if(!s?.ok)return Y("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 Y("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const l=Array.isArray(r.candidates)?r.candidates:[],o=[];for(const u of l){if(!u||typeof u!="object")continue;const f=u;if(!(f.type!=="lan"||typeof f.url!="string"))try{const E=xe(f.url);E&&!o.includes(E)&&o.push(E)}catch{}}if(o.length===0)return Y("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const i=Qe(e).filter(u=>u.url.startsWith("https://")),c=[...o.map(u=>({kind:"direct",url:u})),...i,{kind:"relay",relay:t}];return JSON.stringify(e.candidates.map(ct))===JSON.stringify(c.map(ct))?"unchanged":(Y("candidates:refreshed",{lanCount:o.length}),await Fe({id:e.id,label:e.label,candidates:c}),"updated")}finally{rt=!1}},kn=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await wn().catch(()=>"skipped");Y("candidates:refresh-result",{result:e}),e==="updated"&&$e()&&await Be().catch(()=>null)})()},Er)},kt=e=>{const[t,s]=a.useState(()=>ve()),[r,l]=a.useState(null),[o,i]=a.useState(null),[c,d]=a.useState(null),u=a.useRef(t),f=a.useRef(null),E=a.useRef(fn()),T=a.useCallback(m=>{u.current=m,s(m)},[]),w=a.useCallback(m=>{f.current=m,l(m)},[]),p=a.useCallback(m=>{f.current===m&&(f.current=null,l(null))},[]);a.useEffect(()=>{let m=!1;return yn().then(j=>{m||T(j)}),()=>{m=!0}},[T]);const A=a.useCallback(m=>{const j=pn(u.current,m);return T(j),bt(j),j},[T]),_=a.useCallback(async m=>{i(null),w("connect");try{const j=Ut(m);if(j.length===0){i("Enter a server URL.");return}const C=m.id?u.current.find(N=>N.id===m.id):u.current.find(N=>Je(N.candidates,j)),P=m.label?.trim()||C?.label||Ue(ie({candidates:j})),I=m.relayGrant;let D=m.clientToken?.trim()||void 0;const x=!!D;D||(q()?C?.hasToken&&(D=await We(X({candidates:j}))):D=C?.clientToken),Y("connect:start",{candidates:j.map(N=>N.kind),hasToken:!!D});const h=await qe(j,D);if(Y("connect:probe",{status:h.status}),h.status==="unreachable"){i("Could not reach that PiChamber server.");return}if(h.status==="needs-login"){A({id:C?.id,label:P,candidates:j}),d({id:C?.id??crypto.randomUUID(),label:P,candidates:j,relay:be({candidates:j})??void 0,relayGrant:I});return}D&&x&&q()&&await he(X({candidates:j}),D),A({id:C?.id,label:P,candidates:j,clientToken:D}),ye(h.transport,D??null,{runtimeKey:X({candidates:j}),grant:I}),e()}catch(j){console.warn("[mobile-connect] connect threw",j),i("That server URL is not valid.")}finally{p("connect")}},[w,p,e,A]),L=a.useCallback(async m=>{if(f.current==="pairing")return;i(null),w("pairing");const j=Br(m.candidates);let C=null,P=!1;try{if(C=await Bt(j),!C){i("Could not reach that PiChamber server.");return}const I=JSON.stringify({pairingId:m.pairingId,secret:m.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:zt(),dedupeKey:Ot()}),D={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:I},x=C.kind==="relay"?await de(Ae,C.tunnel.fetch("/api/client-auth/pairing/redeem",D).catch(()=>null)):await ge(`${C.url}/api/client-auth/pairing/redeem`,D);if(!x?.ok){i("This server needs a password or client token.");return}const h=await x.json().catch(()=>null),N=typeof h?.clientToken=="string"?h.clientToken.trim():"";if(!N){i("This server needs a password or client token.");return}const b=typeof h?.server?.label=="string"?h.server.label:"",M=m.label||b||Ue(ie({candidates:j}));if(q()&&!await he(X({candidates:j}),N)){i("This server needs a password or client token.");return}A({label:M,candidates:j,clientToken:N}),ye(C.kind==="relay"?{kind:"relay",relay:C.relay,tunnel:C.tunnel}:{kind:"direct",url:C.url},N,{runtimeKey:X({candidates:j})}),P=C.kind==="relay",e()}catch(I){console.warn("[mobile-connect] pairing threw",I),i("This server needs a password or client token.")}finally{!P&&C?.kind==="relay"&&C.tunnel.close(),p("pairing")}},[w,p,e,A]),R=a.useCallback(async m=>{if(!c||!m.trim()||f.current==="password")return;i(null),w("password");const j=E.current.begin(),C=()=>E.current.isCurrent(j),{id:P,label:I,candidates:D}=c;let x=null,h=!1;try{if(x=await Bt(D),!C())return;if(!x){i("Could not reach that PiChamber server.");return}const N={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:m,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:zt(),dedupeKey:Ot()})};Y("password:start",{transport:x.kind});const b=x.kind==="relay"?await de(Ae,x.tunnel.fetch("/auth/session",N).catch(()=>null)):await ge(`${x.url}/auth/session`,N);if(!C())return;if(Y("password:done",{ok:b?.ok===!0,status:b?.status??null}),!b?.ok){i("Could not unlock that server. Check the password.");return}const M=await b.json().catch(()=>null);if(!C())return;const F=typeof M?.clientToken=="string"?M.clientToken.trim():"";if(Y("password:token",{issued:!!F}),!F){if(x.kind==="direct"&&!q()){A({id:P,label:I,candidates:D}),d(null),ye({kind:"direct",url:x.url},null,{runtimeKey:X({candidates:D})}),e();return}i("This server needs a password or client token.");return}if(q()&&(!C()||(await he(X({candidates:D}),F),!C()))||!C()||(A({id:P,label:I,candidates:D,clientToken:F}),d(null),ye(x.kind==="relay"?{kind:"relay",relay:x.relay,tunnel:x.tunnel}:{kind:"direct",url:x.url},F,{runtimeKey:X({candidates:D})}),h=x.kind==="relay",!C()))return;e()}catch(N){if(!C())return;console.warn("[mobile-connect] password threw",N),i("Could not unlock that server. Check the password.")}finally{!h&&x?.kind==="relay"&&x.tunnel.close(),C()&&p("password")}},[w,p,e,c,A]),v=a.useCallback(()=>{E.current.cancel(),p("password"),d(null),i(null)},[p]),S=a.useCallback(async m=>{i(null);let j=Ut(m);const C=m.id?u.current.find(x=>x.id===m.id)??null:null;if(C){const x=j.filter(b=>b.kind==="direct"),h=Qe(C).filter(b=>b.url.startsWith("https://")&&!x.some(M=>pt(M.url,b.url))),N=be(C);j=[...x,...h,...N?[{kind:"relay",relay:N}]:[]]}if(j.length===0)return i("Enter a server URL."),null;const P=m.clientToken?.trim()||void 0,I=m.label?.trim()||Ue(ie({candidates:j}));if(q()){const x=X({candidates:j});if(P)await he(x,P);else if(C?.hasToken){const h=X(C);if(h&&x&&h!==x){const N=await We(h);N&&await he(x,N)}}}return A({id:m.id,label:I,candidates:j,clientToken:P}).find(x=>Je(x.candidates,j))??null},[A]),U=a.useCallback(async m=>{const j=u.current.find(P=>P.id===m)??null,C=await bn(m);return T(C),j},[T]);return{connections:t,isBusy:r!==null,isPasswordBusy:r==="password",error:o,pendingConnection:c,connect:_,redeemPairingConnection:L,submitPassword:R,cancelPassword:v,saveConnection:S,removeConnection:U,setError:i}},Oa=Object.freeze(Object.defineProperty({__proto__:null,autoConnectLastInstance:Ve,connectionDisplayUrl:ie,createMobilePasswordOperationTracker:fn,deleteMobileConnection:bn,getAutoConnectTargetLabel:Re,getConnectionLabel:Ue,isActiveRuntimeConnection:ut,isSameConnectionUrl:pt,loadMobileConnections:yn,migrateLegacyInlineTokenRecords:mn,normalizeConnectionUrl:xe,refreshActiveConnectionCandidates:wn,relayConnectionRuntimeKey:mt,reprobeActiveConnection:Be,upsertMobileConnection:Fe,useMobileConnection:kt,validateActiveRuntimeSession:xn,validateMobileConnectionSession:gn},Symbol.toStringTag,{value:"Module"})),Sn=()=>{if(typeof window>"u")return null;const t=window.Capacitor?.Plugins?.BarcodeScanner;return t&&(typeof t.scan=="function"||typeof t.startScan=="function")?t:null},Wr=()=>window.Capacitor?.getPlatform?.()==="android",jn=e=>{const t=e.trim();if(!t)return null;if(/^pichamber:\/\//i.test(t)){const s=Bn(t);return s?{pairing:s}:null}return/^https?:\/\//i.test(t)?{url:t}:null},Cn=(e,t)=>{const s=jn(e);if(!s&&t?.pairingStringFallback){const r=$n(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(u=>{o=u}),c=u=>{l||(l=!0,o(u))},d=()=>c({status:"cancelled"});t?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(e.addListener("barcodesScanned",({barcodes:f})=>{const E=f?.[0],T=(E?.rawValue??E?.displayValue??"").trim();T&&c(Cn(T,{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",d),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(r?.remove()),e.stopScan()])}},dt=()=>Sn()!==null,En=async e=>{const t=Sn();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(Wr())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?Cn(l):{status:"cancelled"}}catch{return{status:"failed"}}},Ne={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Oe="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",Tn=({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(d=>d.addedNodes.forEach(o))});return i.observe(document.body,{childList:!0}),()=>{i.disconnect(),l.forEach((c,d)=>{d.style.opacity=c.opacity,d.style.pointerEvents=c.pointerEvents}),s.value?document.documentElement.style.setProperty("background-color",s.value,s.priority):document.documentElement.style.removeProperty("background-color"),r.value?document.body.style.setProperty("background-color",r.value,r.priority):document.body.style.removeProperty("background-color")}},[]),a.useEffect(()=>{const s=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[e]),Pe.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(ee,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[n.jsx($,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},Rn=()=>Pe.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(me,{width:96,height:96,isAnimated:!0}),n.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[n.jsx($,{name:"loader-4",className:"size-[18px] animate-spin"}),n.jsx("span",{children:"Connecting..."})]})]}),document.body),Kr=({onConnected:e,notice:t=null})=>{const s=kt(e),{connections:r,isBusy:l,isPasswordBusy:o,error:i,pendingConnection:c}=s,[d,u]=a.useState(""),[f,E]=a.useState(""),[T,w]=a.useState(""),[p,A]=a.useState(!1),[_,L]=a.useState(!1),R=a.useRef(null),v=a.useMemo(()=>dt(),[]),[S,U]=a.useState(()=>!dt()),[m,j]=a.useState(null),[C,P]=a.useState(""),I=a.useCallback(b=>{b.preventDefault(),s.connect({url:d,clientToken:T,label:f})},[T,s,f,d]),D=a.useCallback(b=>{if(/^pichamber:\/\//i.test(b.trim())){const M=jn(b);if(M){if("pairing"in M){s.redeemPairingConnection(M.pairing);return}u(M.url),M.label&&E(M.label),M.clientToken&&w(M.clientToken);return}}u(b)},[s]),x=a.useCallback(async()=>{if(R.current||l)return;s.setError(null),A(!0);const b=new AbortController;R.current=b;try{const M=await En({signal:b.signal});switch(R.current===b&&(R.current=null,A(!1)),M.status){case"ok":L(!0),u(M.url),M.label&&E(M.label),M.clientToken&&w(M.clientToken),await s.connect({url:M.url,clientToken:M.clientToken,label:M.label});break;case"pairing":L(!0),await s.redeemPairingConnection(M.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),R.current===b&&(R.current=null,A(!1))}},[s,l]);a.useEffect(()=>()=>R.current?.abort(),[]);const h=a.useCallback(b=>{b.preventDefault(),s.submitPassword(C)},[s,C]),N=a.useCallback(()=>{P(""),s.cancelPassword()},[s]);return n.jsxs(n.Fragment,{children:[p?n.jsx(Tn,{onCancel:()=>R.current?.abort()}):null,_?n.jsx(Rn,{}):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(me,{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($,{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:h,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($,{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")?ie(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Ne,value:C,onChange:b=>P(b.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Oe}),i?n.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:i}):null,n.jsx(ee,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!C.trim(),children:o?"Connecting...":"Unlock and connect"}),n.jsx(ee,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:N,children:"Use another server"})]}):n.jsxs("div",{className:"flex w-full flex-col gap-6",children:[v?n.jsxs("div",{className:"flex w-full flex-col gap-2",children:[n.jsxs(ee,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{x()},disabled:p||l,children:[n.jsx($,{name:"scan-2",className:B("size-[18px]",p&&"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&&!S?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 M=m===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:()=>{j(b.id),s.connect({id:b.id,candidates:b.candidates,clientToken:b.clientToken,label:b.label}).finally(()=>j(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($,{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:B("block truncate typography-small",M?"text-foreground":"text-muted-foreground"),children:M?"Connecting...":b.candidates.some(F=>F.kind==="direct")?ie(b):"via PiChamber Relay"})]}),M?n.jsx($,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):n.jsx($,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},b.id)})})]}):null,n.jsxs("div",{className:"flex w-full flex-col",children:[v?n.jsxs("button",{type:"button",onClick:()=>U(b=>!b),"aria-expanded":S,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($,{name:"arrow-down-s",className:B("size-4 transition-transform duration-200",S&&"rotate-180")})]}):null,n.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:S?"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:I,children:[n.jsx("input",{...Ne,value:d,onChange:b=>D(b.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:S?void 0:-1,className:B(Oe,"text-center")}),n.jsx("input",{value:f,onChange:b=>E(b.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:S?void 0:-1,className:B(Oe,"text-center")}),n.jsx("input",{...Ne,value:T,onChange:b=>w(b.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:S?void 0:-1,autoCapitalize:"none",className:B(Oe,"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(ee,{type:"submit",variant:v?"outline":"default",size:"lg",className:"h-12 w-full",disabled:l||p||!d.trim(),children:l?"Connecting...":"Connect"})]})})})]})]})]})})]})},Hr=10,Vr=(e,t)=>cn(e,t),Xr=({session:e,meta:t,active:s,onSelect:r})=>{const l=js(e.id),o=Cs(e.id),i=l?.type??"idle",c=i==="busy"||i==="retry",d=!c&&o>0&&!s,u=Es(e.id,c),f=c&&u,E=ir(e.time?.updated??e.time?.created??0);return n.jsxs("button",{type:"button",className:B("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:B("block truncate typography-ui-label",s?"text-primary":"text-foreground"),children:Vr(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}):d?n.jsx(lr,{label:"Session complete"}):null,f?n.jsx(cr,{sessionId:e.id,running:c,className:"typography-micro"}):d?null:E?n.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:E}):null]})},Gr=({open:e,onClose:t,anchorRef:s})=>{const{panelRef:r,wrapperRef:l,shouldRender:o,isExiting:i,anchorLeft:c,isPopover:d}=Jn({open:e,onClose:t,anchorRef:s}),u=ae(p=>p.currentSessionId),f=ae(p=>p.setCurrentSession),E=on(p=>p.setActiveProjectIdOnly),T=ur(e||o,{maxParents:Hr}),w=a.useCallback(p=>{f(p.id,ft(p)),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:B("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",d?"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))",...d?{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:T.length===0?n.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):T.map(p=>{const A=p.node.session,_=[p.secondaryMeta?.projectLabel,p.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return n.jsx(Xr,{session:A,meta:_,active:A.id===u,onSelect:()=>{p.projectId&&E(p.projectId),w(A)}},A.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},Jr=({onOpenSessions:e,onOpenWorkspace:t,compactTitle:s=!1})=>{const[r,l]=a.useState(!1),[o,i]=a.useState(!1),c=a.useRef(null),d=rn(v=>v.currentDirectory),u=ae(v=>v.currentSessionId),E=ae(a.useCallback(v=>u?v.getDirectoryForSession(u):null,[u]))||d,T=Ts(u),w=ae(v=>!!v.newSessionDraft?.open),A=T?.title?.trim()||(u?cn(T,"Untitled session"):"New session");a.useEffect(()=>{l(!1),i(!1)},[u,E]);const _=a.useCallback(()=>{l(!1),i(!1),e()},[e]),L=a.useCallback(v=>{l(S=>{const U=typeof v=="function"?v(S):v;return U&&i(!1),U})},[]),R=a.useCallback(()=>{i(v=>{const S=!v;return S&&l(!1),S})},[]);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($,{name:"list-unordered",className:"size-5"})}),n.jsx("button",{ref:c,type:"button",className:B("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:R,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:A}),n.jsx($,{name:"arrow-down-s",className:B("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:u,effectiveDirectory:E,isNewSessionDraftOpen:w}),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($,{name:"layout-right",className:"size-5"})})]})}),n.jsx(Gr,{open:o,onClose:()=>i(!1),anchorRef:c})]})},qr=({onActiveConnectionDeleted:e,onConnect:t})=>{const s=kt(t),{connections:r,isBusy:l,isPasswordBusy:o,error:i,pendingConnection:c,connect:d,submitPassword:u,cancelPassword:f,saveConnection:E,removeConnection:T,setError:w}=s,[p,A]=a.useState(null),_=p?r.find(k=>k.id===p)??null:null,[L,R]=a.useState(null),[v,S]=a.useState(""),[U,m]=a.useState(""),[j,C]=a.useState(""),[P,I]=a.useState(""),[D,x]=a.useState(!1),[h,N]=a.useState(!1),[b,M]=a.useState(!1),[F,te]=a.useState(null),y=a.useRef(null),z=a.useMemo(()=>dt(),[]),[W,H]=a.useState(!1),[O,V]=a.useState(null),Q=a.useCallback(()=>{A(null),S(""),m(""),C(""),w(null),H(!1)},[w]),we=a.useCallback(k=>{k.preventDefault(),E({id:p??void 0,url:v,label:U,clientToken:j}).then(K=>{K&&Q()})},[j,p,U,Q,E,v]),Ke=a.useCallback(async()=>{if(y.current)return;w(null),x(!0);const k=new AbortController;y.current=k;try{const K=await En({signal:k.signal});switch(y.current===k&&(y.current=null,x(!1)),K.status){case"ok":S(K.url),K.label&&m(K.label),K.clientToken&&C(K.clientToken),H(!0);break;case"pairing":N(!0),await s.redeemPairingConnection(K.pairing);break;case"permission-denied":w("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":w("That QR code is not an PiChamber connection code.");break;case"unsupported":w("QR scanning is only available in the installed mobile app.");break;case"failed":w("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{N(!1),y.current===k&&(y.current=null,x(!1))}},[s,w]);a.useEffect(()=>()=>y.current?.abort(),[]);const ne=a.useCallback(k=>{k.preventDefault(),u(P)},[P,u]),se=a.useCallback(()=>{I(""),f()},[f]),Me=a.useCallback(async()=>{if(!b){te(null),M(!0);try{const k=await Wn();te(k==="copied"?"Diagnostics copied to the clipboard.":k==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{te("Diagnostics export was cancelled or unavailable.")}finally{M(!1)}}},[b]),ke=a.useCallback(k=>{R(K=>K===k?null:k)},[]),Se=a.useCallback(k=>{R(null),p===k&&Q();const K=r.length===1;T(k).then(J=>{J&&(K||ut(J))&&e()})},[r.length,p,e,T,Q]),G=Oe;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:ne,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($,{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(k=>k.kind==="direct")?ie(c):"via PiChamber Relay"})]})]}),n.jsx("input",{...Ne,value:P,onChange:k=>I(k.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(ee,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!P.trim(),children:o?"Connecting...":"Unlock and connect"}),n.jsx(ee,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:se,children:"Use another server"})]})})}):n.jsxs(n.Fragment,{children:[D?n.jsx(Tn,{onCancel:()=>y.current?.abort()}):null,h?n.jsx(Rn,{}):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(k=>{const K=L===k.id,J=ut(k),je=O===k.id,pe=je?"Connecting...":J?$e()?"Connected · Private relay":"Connected · Local network":k.candidates.some(Le=>Le.kind==="direct")?ie(k):"via PiChamber Relay";return n.jsxs("div",{className:B("flex items-center border-b border-border/70 transition-colors last:border-b-0",K&&"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:()=>{J||(V(k.id),d({id:k.id,candidates:k.candidates,clientToken:k.clientToken,label:k.label}).finally(()=>V(null)))},disabled:l&&!je||K,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($,{name:"server",className:"size-[18px]"}),J?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:k.label}),n.jsx("span",{className:B("block truncate typography-small",J&&!je?"text-[var(--status-success)]":"text-muted-foreground"),children:pe})]}),je?n.jsx($,{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:[K?n.jsxs("button",{type:"button","aria-label":`Confirm deleting ${k.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:()=>Se(k.id),style:{touchAction:"manipulation"},children:[n.jsx($,{name:"delete-bin",className:"size-[18px]"}),n.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):k.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:()=>{A(k.id),S(ie(k)),m(k.label),C(k.clientToken||""),w(null)},style:{touchAction:"manipulation"},children:n.jsx($,{name:"edit",className:"size-[18px]"})}):null,n.jsx("button",{type:"button","aria-label":K?`Keep ${k.label}`:`Delete ${k.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:()=>ke(k.id),style:{touchAction:"manipulation"},children:n.jsx($,{name:K?"close":"delete-bin",className:"size-[18px]"})})]})]},k.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(ee,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{Me()},disabled:b,children:[n.jsx($,{name:"download",className:"size-[18px]"}),b?"Preparing diagnostics…":"Export diagnostics"]}),F?n.jsx("p",{className:"px-1 text-center typography-small text-muted-foreground",children:F}):null]}),!W&&!_?n.jsxs("div",{className:"space-y-2",children:[z?n.jsxs(ee,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{Ke()},disabled:D,children:[n.jsx($,{name:"scan-2",className:B("size-[18px]",D&&"animate-pulse")}),"Scan QR code"]}):null,n.jsxs(ee,{type:"button",variant:z?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{w(null),H(!0)},children:[n.jsx($,{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:we,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(ee,{type:"button",variant:"ghost",size:"xs",onClick:Q,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",{...Ne,value:v,onChange:k=>S(k.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:U,onChange:k=>m(k.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",{...Ne,value:j,onChange:k=>C(k.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(ee,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:_?"Save changes":"Save instance"})]})]})})})]})},De=320,fe="cubic-bezier(0.22, 1, 0.36, 1)",Nn=({side:e,enabled:t,open:s,drawerRef:r,scrimRef:l,onClose:o,widthRatio:i,prefersReducedMotion:c})=>{a.useEffect(()=>{if(!t||!s)return;const d=r.current,u=l.current;if(!d||!u)return;let f=!1,E=!1,T=!1,w=0,p=0,A=0,_=0;const L=c?0:De,R=e==="left"?"translateX(-100%)":"translateX(100%)",v=()=>({drawer:L?`transform ${L}ms ${fe}`:"none",scrim:L?`opacity ${L}ms ${fe}`:"none"}),S=()=>{const x=v();d.style.transition=x.drawer,u.style.transition=x.scrim,d.style.transform="none",u.style.opacity="1",u.style.pointerEvents="auto"},U=()=>{f=!1,E=!1,T=!1},m=()=>{if(!(f||E)){U();return}S(),U()},j=x=>{if(x.touches.length!==1){(f||E)&&m();return}if(Qn(x.target,d,{excludeInteractive:!1}))return;d.style.transition&&d.style.transition!=="none"&&(d.style.transition="none",u.style.transition="none");const h=x.touches[0];w=h.clientX,p=h.clientY,A=Date.now(),_=d.offsetWidth||window.innerWidth*i,_<10&&(_=window.innerWidth*i),f=!0,E=!1,T=!1},C=x=>{if(!f)return;if(x.touches.length!==1){m();return}const h=x.touches[0],N=h.clientX-w,b=h.clientY-p;if(!T){if(Math.abs(N)<Nt&&Math.abs(b)<Nt)return;if(Math.abs(b)>Math.abs(N)*Pt||!It(e,N)){f=!1;return}T=!0,E=!0,d.style.transition="none",u.style.transition="none"}if(!E)return;x.cancelable&&x.preventDefault();const M=At(e,N,_);d.style.transform=Zn(e,M),u.style.opacity=String(M)},P=(x,h,N)=>{if(!f)return;const b=x-w,M=h-p,F=Math.max(1,Date.now()-A),te=At(e,b,_),y=ts({side:e,dx:b,dy:M,dt:F,progress:te,isDragging:E}),z=v();d.style.transition=z.drawer,u.style.transition=z.scrim,d.style.transform=y?R:"none",u.style.opacity=y?"0":"1",u.style.pointerEvents=y?"none":"auto",U(),y&&o()},I=x=>{const h=x.changedTouches[0];if(!h){m();return}const N=h.clientX-w,b=h.clientY-p,M=Math.abs(N)>=es&&Math.abs(b)<=Math.abs(N)*Pt&&It(e,N);f&&(E||M)&&x.cancelable&&x.preventDefault(),P(h.clientX,h.clientY)},D=()=>{m()};return d.addEventListener("touchstart",j,{passive:!0}),d.addEventListener("touchmove",C,{passive:!1}),d.addEventListener("touchend",I,{passive:!1}),d.addEventListener("touchcancel",D,{passive:!0}),()=>{try{m()}catch{}d.removeEventListener("touchstart",j),d.removeEventListener("touchmove",C),d.removeEventListener("touchend",I),d.removeEventListener("touchcancel",D)}},[r,t,o,s,c,l,e,i])},Yr=16,$t=a.memo(function({open:t,onOpenChange:s,variant:r="drawer",drawerRefExternal:l,scrimRefExternal:o,rootRefExternal:i}){const c=a.useRef(null),d=a.useCallback(()=>{const S=typeof document<"u"?document.activeElement:null;S instanceof HTMLElement&&c.current?.contains(S)&&S.blur(),s(!1)},[s]),[u,f]=a.useState(!1),E=a.useRef(null),T=a.useRef(null),w=l??E,p=o??T,A=a.useCallback(S=>{c.current=S,i&&(i.current=S)},[i]),_=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);a.useEffect(()=>{const S=c.current;if(!S||t)return;const U=document.activeElement;U&&S.contains(U)&&U.blur()},[t]),a.useEffect(()=>{if(r!=="sidebar"){if(t){const S=window.setTimeout(()=>f(!0),_?0:Yr);return()=>window.clearTimeout(S)}f(!1)}},[t,_,r]),a.useEffect(()=>{if(r==="sidebar"||!t)return;const S=document.body.style.overflow;document.body.style.overflow="hidden";const U=m=>{m.key==="Escape"&&d()};return document.addEventListener("keydown",U),()=>{document.body.style.overflow=S,document.removeEventListener("keydown",U)}},[d,t,r]);const L=r==="sidebar",R=n.jsx(ns,{mobileVariant:!L,isVisible:t,allowReselect:!0,onSessionSelected:L?void 0:d,onNavigateAway:L?void 0:d});if(Nn({side:"left",enabled:r==="drawer",open:t,drawerRef:w,scrimRef:p,onClose:d,widthRatio:.72,prefersReducedMotion:_}),r==="sidebar")return n.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:R});if(typeof document>"u")return null;const v=_?0:De;return Pe.createPortal(n.jsxs("div",{ref:A,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none"},"data-mobile-sessions-root":"true",children:[n.jsx("button",{ref:p,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:d,tabIndex:t?0:-1,style:{opacity:u?1:0,transition:`opacity ${v}ms ${fe}`},"data-mobile-sessions-scrim":"true"}),n.jsx("div",{ref:w,className:B("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:u?"none":"translateX(-100%)",transition:v?`transform ${v}ms ${fe}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:R})]}),document.body)}),Wt="mobile-surface-root",at=16,He=200,Qr=()=>{if(typeof document>"u")return null;let e=document.getElementById(Wt);return e||(e=document.createElement("div"),e.id=Wt,document.body.appendChild(e)),e},ot=({open:e,onClose:t,title:s,subtitle:r,trailing:l,disableEscapeDismiss:o=!1,headerless:i=!1,noHeaderBorder:c=!1,ariaLabel:d,variant:u="fullscreen",dialogAlign:f="chat",children:E})=>{const T=a.useRef(null),[w,p]=a.useState(!1),[A,_]=a.useState(!1),L=a.useRef(null),R=a.useRef(null),v=a.useRef(t);if(a.useEffect(()=>{v.current=t},[t]),typeof document<"u"&&!T.current&&(T.current=Qr()),a.useEffect(()=>{if(!e){p(!1);return}const m=window.setTimeout(()=>p(!0),at);return()=>window.clearTimeout(m)},[e]),a.useEffect(()=>{if(!e){_(!1);return}const m=window.setTimeout(()=>_(!0),at+He+80);return()=>window.clearTimeout(m)},[e]),a.useEffect(()=>{if(!e)return;const m=document.body.style.overflow;R.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const j=()=>{const I=L.current;if(!I)return;(I.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??I).focus({preventScroll:!0})},C=window.setTimeout(j,at),P=I=>{if(I.key==="Escape"&&!o){v.current();return}if(I.key!=="Tab")return;const D=L.current;if(!D)return;const x=Array.from(D.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(M=>!M.hasAttribute("disabled")&&M.getAttribute("aria-hidden")!=="true");if(x.length===0){I.preventDefault(),D.focus({preventScroll:!0});return}const h=x[0],N=x[x.length-1],b=document.activeElement;I.shiftKey&&b===h?(I.preventDefault(),N.focus({preventScroll:!0})):!I.shiftKey&&b===N&&(I.preventDefault(),h.focus({preventScroll:!0}))};return document.addEventListener("keydown",P),()=>{window.clearTimeout(C),document.body.style.overflow=m,document.removeEventListener("keydown",P),R.current?.focus?.({preventScroll:!0}),R.current=null}},[o,e]),!e||!T.current)return null;const S=u==="dialog",U=n.jsxs("section",{ref:L,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:B("flex flex-col bg-background text-foreground",S?"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:S?{opacity:w?1:0,transform:w?"none":"scale(0.97)",transition:`opacity ${He}ms ease-out, transform ${He}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:w?"none":"translateX(100%)",transition:`transform ${He}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:m=>{w&&m.target===m.currentTarget&&m.propertyName==="transform"&&_(!0)},children:[i?null:n.jsxs("header",{className:B("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($,{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:A?n.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:E}):null}),n.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return S?Pe.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:w?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:m=>m.stopPropagation(),children:U})}),T.current):Pe.createPortal(U,T.current)},Zr=a.lazy(()=>Ie(()=>import("./FilesView-CK2YVs_W.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}))),ea=a.lazy(()=>Ie(()=>import("./GitView-BEFLOv_7.js"),__vite__mapDeps([123,24,1,2,9,4,3,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",ta=16,na=[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal"}],Kt=a.memo(function({open:t,onClose:s,tab:r,onTabChange:l,pendingChangesDiff:o,variant:i="drawer",drawerRefExternal:c,scrimRefExternal:d,rootRefExternal:u}){const f=a.useRef(null),E=a.useRef(null),T=a.useRef(null),w=a.useRef(null),p=c??E,A=d??T,_=u??w,L=a.useCallback(h=>{w.current=h,u&&(u.current=h)},[u]),R=a.useCallback(()=>{const h=typeof document<"u"?document.activeElement:null;h instanceof HTMLElement&&_.current?.contains(h)&&h.blur(),s()},[s]),[v,S]=a.useState(!1),[U,m]=a.useState(t),j=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[C,P]=a.useState(()=>new Set);if(a.useEffect(()=>{t&&P(h=>{if(h.has(r))return h;const N=new Set(h);return N.add(r),N})},[t,r]),typeof document<"u"&&!f.current){let h=document.getElementById(Ft);h||(h=document.createElement("div"),h.id=Ft,document.body.appendChild(h)),f.current=h}if(a.useEffect(()=>{if(t){m(!0);const N=window.setTimeout(()=>S(!0),j?0:ta);return()=>window.clearTimeout(N)}S(!1);const h=window.setTimeout(()=>m(!1),De+40);return()=>window.clearTimeout(h)},[t,j]),a.useEffect(()=>{if(!t)return;const h=document.body.style.overflow;i==="drawer"&&(document.body.style.overflow="hidden");const N=b=>{b.key==="Escape"&&r!=="terminal"&&R()};return document.addEventListener("keydown",N),()=>{i==="drawer"&&(document.body.style.overflow=h),document.removeEventListener("keydown",N)}},[R,t,r,i]),a.useEffect(()=>{const h=_.current;if(!h||t||i!=="drawer")return;const N=document.activeElement;N&&h.contains(N)&&N.blur()},[t,i]),Nn({side:"right",enabled:i==="drawer",open:t,drawerRef:p,scrimRef:A,onClose:R,widthRatio:1,prefersReducedMotion:j}),i==="drawer"&&!f.current)return null;const I=j?0:De,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:na.map(h=>{const N=r===h.id;return n.jsxs("button",{type:"button",role:"tab","aria-selected":N,onClick:()=>l(h.id),className:B("flex min-w-0 flex-1 items-center justify-center gap-1 rounded-lg px-1.5 py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",N?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx($,{name:h.icon,className:"size-5 shrink-0"}),n.jsx("span",{className:"truncate",children:h.label})]},h.id)})}),x=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:R,"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($,{name:"close",className:"size-5"})})]}),n.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[C.has("changes")?n.jsx("div",{className:B("h-full",r!=="changes"&&"hidden"),children:n.jsx(oe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(ea,{isActive:t&&r==="changes",chrome:"mobile",initialDiffPath:o?.path??null,initialDiffStaged:o?.staged===!0})})})},o?`changes:${o.path}:${o.staged}`:"changes"):null,C.has("files")?n.jsx("div",{className:B("h-full",r!=="files"&&"hidden"),children:n.jsx(oe,{children:n.jsx(a.Suspense,{fallback:null,children:n.jsx(Zr,{chrome:"mobile",mode:"editor-only"})})})}):null,C.has("terminal")?n.jsx("div",{className:B("h-full",r!=="terminal"&&"hidden"),children:n.jsx(oe,{children:n.jsx(ss,{visible:t&&r==="terminal"})})}):null]})]});return i==="panel"?n.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:x}):Pe.createPortal(n.jsxs("div",{ref:L,className:"fixed inset-0 z-50",inert:!t,style:{pointerEvents:t?"auto":"none",visibility:U?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[n.jsx("button",{ref:A,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:R,tabIndex:t?0:-1,style:{opacity:v?1:0,transition:I?`opacity ${I}ms ${fe}`:"none"},"data-mobile-workspace-scrim":"true"}),n.jsx("section",{ref:p,role:"dialog","aria-modal":"true","aria-label":"Open workspace panel",className:"oc-keyboard-inset-surface absolute inset-y-0 right-0 z-10 flex h-full w-full flex-col bg-sidebar",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:I?`transform ${I}ms ${fe}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:x})]}),f.current)}),sa="pichamber",ra=e=>e.replace(/^\/+|\/+$/g,""),aa=e=>{const t=ra(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...t]:t};function oa(e){if(typeof e!="string"||e.length===0)return null;let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`${sa}:`)return null;const s=aa(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 Z={},Pn=!1,ze=null;const ia=e=>{switch(e.type){case"session":return ae.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const t=ae.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 Z.openSessions?(Z.openSessions(e.filter),!0):!1;case"status":return Z.openSessions?(Z.openSessions(),!0):!1;case"view":return Z.openView?(Z.openView(e.target),!0):!1;case"changes":return Z.openChanges?(Z.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return Z.openSettings?(Z.openSettings(e.section),!0):!1}},St=()=>{if(!Pn||!ze)return;const e=ze;ze=null,ia(e)||(ze=e)},In=e=>{ze=e,St()},Ht=e=>{const t=oa(e);t&&In(t)},la=e=>{Pn=e,St()},ca=e=>{a.useEffect(()=>(Z=e,St(),()=>{Z===e&&(Z={})}),[e])},ua=e=>{const{ready:t}=e;a.useEffect(()=>{la(t)},[t]),a.useEffect(()=>{if(!q())return;let s=!1;const r=[];return Ie(()=>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=>{Ht(i?.url)});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),Ie(()=>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,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){Ht(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&In({type:"session",sessionId:u})});if(s){o.remove();return}r.push(()=>{o.remove()})}).catch(()=>{}),()=>{s=!0,r.forEach(l=>l())}},[])},Vt=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")},Xt=(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)}},Gt=(e,t,s)=>{const r=s.drawer.current,l=s.scrim.current,o=s.root.current;r&&(r.style.transition=`transform ${De}ms ${fe}`,r.style.transform=t?"none":e==="left"?"translateX(-100%)":"translateX(100%)"),l&&(l.style.transition=`opacity ${De}ms ${fe}`,l.style.opacity=t?"1":"0",l.style.pointerEvents=t?"auto":"none"),o&&(o.style.pointerEvents=t?"auto":"none",o.style.visibility=t?"visible":"")},Jt=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))},Qt=({side:e,isResizing:t,ariaLabel:s,handleProps:r})=>n.jsx("div",{className:B("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:B("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",t&&"bg-[var(--interactive-border)]")})}),da=320,fa=380,Zt=280,pa=560,ma=900;function en(e,t,s,r=pa){const l=a.useRef(null),[o,i]=a.useState(()=>{if(typeof window>"u")return s;const v=Number.parseInt(window.localStorage.getItem(t)??"",10);return Number.isFinite(v)?Math.min(r,Math.max(Zt,v)):s}),[c,d]=a.useState(!1),u=a.useRef(0),f=a.useRef(o),E=a.useRef(null),T=a.useRef(null),w=a.useCallback(v=>Math.min(r,Math.max(Zt,Math.round(v))),[r]),p=a.useCallback(v=>{const S=l.current;S&&(S.style.width=`${v}px`,S.style.minWidth=`${v}px`,S.style.maxWidth=`${v}px`,S.style.setProperty("--oc-ipad-sidebar-width",`${v}px`))},[]),A=a.useCallback(v=>{try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}T.current=v.pointerId,u.current=v.clientX,f.current=o,E.current=o,d(!0),v.preventDefault()},[o]),_=a.useCallback(v=>{if(T.current!==v.pointerId)return;const S=v.clientX-u.current,U=w(f.current+(e==="left"?S:-S));E.current!==U&&(E.current=U,p(U))},[p,w,e]),L=a.useCallback(v=>{if(T.current!==v.pointerId)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const S=w(E.current??f.current);T.current=null,E.current=null,d(!1),i(S);try{window.localStorage.setItem(t,String(S))}catch{}},[w,t]),R=a.useMemo(()=>({onPointerDown:A,onPointerMove:_,onPointerUp:L,onPointerCancel:L}),[A,L,_]);return{asideRef:l,width:o,isResizing:c,handleProps:R}}const ha=a.memo(cs),ya=({onActiveConnectionDeleted:e})=>{const[t,s]=a.useState(!1),[r,l]=a.useState(null),[o,i]=a.useState(!1),[c,d]=a.useState("changes"),[u,f]=a.useState("nav"),[E,T]=a.useState(null),w=a.useRef([]),p=a.useCallback(()=>{w.current.forEach(g=>window.clearTimeout(g)),w.current=[]},[]);a.useEffect(()=>()=>p(),[p]);const A=a.useRef(null),_=a.useRef(null),L=a.useRef(null),R=a.useRef(null),v=a.useRef(null),S=a.useRef(null),U=a.useRef(null),m=a.useRef(null),j=a.useRef(0),C=a.useRef(0),P=a.useCallback(g=>{p(),s(g)},[p]),I=a.useCallback(g=>{p(),i(g)},[p]),D=le(g=>g.setSettingsPage),x=le(g=>g.isArchivePageOpen),h=le(g=>g.setArchivePageOpen),N=le(g=>g.wideChatLayoutEnabled),b=Te(g=>g.available),M=Te(g=>g.runtimeType),F=a.useMemo(()=>ln(),[]),te=!F&&b&&(M==="desktop"||M==="web"),y=a.useCallback(()=>{l(null)},[]),z=a.useCallback(g=>{l(g)},[]),W=a.useCallback(()=>{I(!1)},[I]),H=a.useCallback(g=>{f(g),z("settings")},[z]),{enabled:O,roomyForPanels:V}=Rs(),we=Ns()==="portrait",Ke=Ps(),ne=le(g=>g.setSidebarOpen),se=le(g=>g.isSidebarOpen),Me=a.useRef(!1);a.useLayoutEffect(()=>{O&&!Me.current&&ne(Is().roomyForPanels),!O&&Me.current&&ne(!1),Me.current=O},[O,ne]);const ke=a.useCallback(()=>{T(null),d("files"),I(!0)},[I]),Se=a.useCallback((g=null)=>{T(g),d("changes"),I(!0)},[I]),G=en("left","pichamber.ipad.leftSidebarWidth",da),k=en("right","pichamber.ipad.rightSidebarWidth",fa,ma),K=V,J=K&&o?k.width:0,je=rs(O&&se),pe=O&&se?G.width:0,Le=a.useCallback(g=>{o&&c===g?I(!1):(d(g),I(!0))},[o,c,I]),An=a.useCallback(()=>{I(!o)},[o,I]),_n=a.useCallback(g=>{!g&&!V&&ne(!1)},[V,ne]);a.useEffect(()=>{if(typeof document>"u")return;const g=document.documentElement;return g.style.setProperty("--oc-chat-inset-left",`${pe}px`),g.style.setProperty("--oc-chat-inset-right",`${J}px`),()=>{g.style.removeProperty("--oc-chat-inset-left"),g.style.removeProperty("--oc-chat-inset-right")}},[pe,J]),a.useEffect(()=>{if(typeof document>"u")return;const g=document.documentElement;return g.classList.toggle("wide-chat-layout",N),()=>g.classList.remove("wide-chat-layout")},[N]),a.useEffect(()=>{if(typeof document>"u")return;const g=O&&(we||Ke),re=document.documentElement;return re.classList.toggle("oc-keep-draft-starters",g),()=>re.classList.remove("oc-keep-draft-starters")},[Ke,O,we]);const jt=a.useCallback(()=>{P(!1),I(!1)},[P,I]),Dn=a.useMemo(()=>({openChanges:({diffPath:g,staged:re}={})=>{Se(g?{path:g,staged:re===!0}:null)},openFiles:()=>ke(),openSettings:g=>{g&&D(g),H(g?"page-content":"nav")},openInstances:F?()=>z("instances"):void 0,instanceLabel:F?Re():null,openUpdate:te?()=>z("update"):void 0,closeDrawers:jt}),[jt,Se,ke,H,z,D,F,te]),Mn=a.useMemo(()=>({openSessions:()=>{O?ne(!0):P(!0)},openView:g=>{if(g==="files"){ke();return}(g==="instances"||g==="update"||g==="mcp")&&z(g)},openChanges:({path:g,staged:re}={})=>{Se(g?{path:g,staged:re===!0}:null)},openSettings:g=>{g&&D(g),H(g?"page-content":"nav")}}),[O,Se,ke,H,z,D,P,ne]);ca(Mn);const Ct=a.useRef(null);as(Ct,{leftOpen:O?se:t,rightOpen:o,leftWidth:()=>O?G.width:A.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>O?k.width:R.current?.offsetWidth||window.innerWidth,onLeftProgress:g=>{if(j.current=g,O){qt({inner:U},g,G.width,"left");return}Xt({drawer:A,scrim:_},"left",g)},onRightProgress:g=>{if(C.current=g,O&&V){qt({inner:m},g,k.width,"right");return}Xt({drawer:R,scrim:v},"right",g)},onLeftOpen:()=>{O?ne(!0):P(!0)},onLeftClose:()=>{O?ne(!1):P(!1)},onRightOpen:()=>I(!0),onRightClose:()=>I(!1),onDragStart:g=>{if(p(),g==="left"){j.current=O?se?1:0:t?1:0,O?Jt({shell:G.asideRef,inner:U}):Vt({drawer:A,scrim:_,root:L});return}C.current=o?1:0,O&&V?Jt({shell:k.asideRef,inner:m}):Vt({drawer:R,scrim:v,root:S})},onDragEnd:(g,re)=>{if(g==="left"){const Ce=typeof re=="boolean"?re:j.current>.5;if(j.current=Ce?1:0,O){const Et=Yt({shell:G.asideRef,inner:U},Ce,G.width,"left");Et!==void 0&&w.current.push(Et)}else Gt("left",Ce,{drawer:A,scrim:_,root:L});return}const tt=typeof re=="boolean"?re:C.current>.5;if(C.current=tt?1:0,O&&V){const Ce=Yt({shell:k.asideRef,inner:m},tt,k.width,"right");Ce!==void 0&&w.current.push(Ce)}else Gt("right",tt,{drawer:R,scrim:v,root:S})}});const Ln=a.useCallback(()=>x?(h(!1),!0):r?(y(),!0):o?(W(),!0):t?(P(!1),!0):!1,[r,y,W,x,t,h,P,o]);As(Ln);const et=O?"dialog":"fullscreen";return n.jsx(_s,{actions:Dn,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:G.asideRef,className:B("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!se&&"border-r-0"),style:{width:pe,minWidth:pe,maxWidth:pe,"--oc-ipad-sidebar-width":`${G.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!se,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:U,className:B("flex h-full shrink-0 flex-col",G.isResizing&&"pointer-events-none",!se&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:G.isResizing||je.slidIn?"translateX(0)":"translateX(-100%)",transition:G.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx(oe,{children:n.jsx($t,{open:se,variant:"sidebar",onOpenChange:_n})})}),se?n.jsx(Qt,{side:"left",isResizing:G.isResizing,ariaLabel:"Resize left panel",handleProps:G.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(os,{}),n.jsx(is,{onToggleRightDrawer:An,rightDrawerOpen:o,tabletWorkspaceTab:c,onSelectTabletWorkspaceTab:Le})]}):n.jsx(Jr,{onOpenSessions:()=>P(!0),onOpenWorkspace:()=>I(!0)}),n.jsx("main",{ref:Ct,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(oe,{children:n.jsx(ha,{})})})})]}),O?null:n.jsx($t,{open:t,onOpenChange:P,drawerRefExternal:A,scrimRefExternal:_,rootRefExternal:L}),O?n.jsxs("aside",{ref:k.asideRef,className:B("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!J&&"border-l-0"),style:{width:J,minWidth:J,maxWidth:J,"--oc-ipad-sidebar-width":`${k.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!J,"data-page-scroll-lock":"true",children:[n.jsx("div",{ref:m,className:B("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",k.isResizing&&"pointer-events-none",!J&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:J?"translateX(0)":"translateX(100%)",transition:k.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(oe,{children:n.jsx(Kt,{open:o,onClose:W,tab:c,onTabChange:d,pendingChangesDiff:E,variant:K?"panel":"drawer",drawerRefExternal:R,scrimRefExternal:v,rootRefExternal:S})})}),J?n.jsx(Qt,{side:"right",isResizing:k.isResizing,ariaLabel:"Resize right panel",handleProps:k.handleProps}):null]}):n.jsx(Kt,{open:o,onClose:W,tab:c,onTabChange:d,pendingChangesDiff:E,drawerRefExternal:R,scrimRefExternal:v,rootRefExternal:S}),r==="instances"&&F?n.jsx(ot,{open:!0,variant:et,dialogAlign:"app",onClose:y,ariaLabel:"Instances",title:"Instances",children:n.jsx(qr,{onConnect:y,onActiveConnectionDeleted:e})}):null,r==="settings"?n.jsx(ot,{open:!0,variant:et,dialogAlign:"app",onClose:y,ariaLabel:"Settings",headerless:!0,children:n.jsx(oe,{children:n.jsx(ar,{forceMobile:!O,isWindowed:!0,initialMobileStage:u,onClose:y})})}):null,r==="update"?n.jsx(ot,{open:!0,variant:et,dialogAlign:"app",onClose:y,ariaLabel:"Update",title:"Update",children:n.jsx(oe,{children:n.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:n.jsx(or,{initialUpdateDialogOpen:!0})})})}):null,n.jsx(oe,{children:n.jsx(ls,{})})]})})};function ba(e=2500){const{uiFont:t}=Ds(),[s,r]=a.useState(!1);return a.useEffect(()=>{let l=!1;const o=()=>{l||r(!0)},i=()=>{requestAnimationFrame(()=>requestAnimationFrame(o))},c=Promise.all([Ms(t).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),dr.catch(()=>{})]).then(()=>{}),d=new Promise(u=>{window.setTimeout(u,e)});return Promise.race([c,d]).then(i),()=>{l=!0}},[t,e]),s}const ga=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},xa=()=>{if(typeof window>"u")return!1;const t=window.Capacitor?.getPlatform?.();return t==="ios"||t==="android"},va=e=>{const{enabled:t}=e,s=le(l=>l.nativeNotificationsEnabled),r=a.useRef(null);a.useEffect(()=>{if(!t||!s||!xa())return;let l=!1;const o=[];return Ie(()=>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 d=await i.addListener("registration",f=>{r.current=f.value,lt()?.push?.registerApnsToken?.({token:f.value,platform:tn(),environment:ga()})}),u=await i.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await i.register().catch(()=>{}),l){d.remove(),u.remove();return}o.push(()=>{d.remove()},()=>{u.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,lt()?.push?.unregisterApnsToken?.({token:l})},[s])},wa=1e3;function ka({apis:e}){const t=ce(y=>y.initializeApp),s=ce(y=>y.isInitialized),r=ce(y=>y.isConnected),l=ce(y=>y.connectionPhase),o=ce(y=>y.providers.length),i=ce(y=>y.agents.length),c=ce(y=>y.loadProviders),d=ce(y=>y.loadAgents),u=rn(y=>y.currentDirectory),f=ae(y=>y.error),E=ae(y=>y.clearError),T=le(y=>y.setIsMobile),[w,p]=a.useState(0),[A,_]=a.useState(0),[L,R]=a.useState(!1),[v,S]=a.useState("pending"),[U,m]=a.useState(null),j=a.useMemo(()=>Re(),[]),[,C]=a.useReducer(y=>y+1,0),P=a.useMemo(()=>ln(),[]),I=a.useRef(0),D=a.useRef(0),x=a.useCallback(()=>{const y=ue(),z=D.current+1;if(D.current=z,!y){Ve();return}const W=()=>{t(),o===0&&c({source:"mobileApp:nativeResume"}),i===0&&d({source:"mobileApp:nativeResume"})},H=()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),p(V=>V+1)};Be().then(V=>{if(D.current===z){if(V==="no-connection"){H();return}if(V==="needs-login"){m({kind:"auth-expired",label:Re()??""}),H();return}if(V==="unreachable"){window.setTimeout(()=>{D.current===z&&Be().then(Q=>{if(D.current===z&&Q!=="switched"){if(Q==="unchanged"){W();return}Q==="needs-login"&&m({kind:"auth-expired",label:Re()??""}),H()}})},4e3);return}V!=="switched"&&W()}});const O=Date.now();O-I.current>=wa&&(I.current=O,window.dispatchEvent(new Event("pichamber:system-resume")))},[i,t,d,c,o]);Ls(),Os(x),a.useEffect(()=>Fn(),[]),a.useEffect(()=>{if(!P)return;let y;const z=()=>{window.clearTimeout(y),y=window.setTimeout(()=>x(),1500)};return window.addEventListener("online",z),()=>{window.removeEventListener("online",z),window.clearTimeout(y)}},[P,x]),a.useEffect(()=>(Rt(e),()=>Rt(null)),[e]),a.useEffect(()=>Kn(y=>{if(!!y.runtimeKey&&y.runtimeKey===y.previousRuntimeKey){us(),C();return}ds(y),_(W=>W+1),p(W=>W+1)}),[]),a.useEffect(()=>{an()},[A]),a.useEffect(()=>{if(!P||r||ue()){S("done");return}let y=!1;return S("attempting"),Ve().catch(()=>({status:"no-candidate"})).then(z=>{y||(z.status==="unreachable"?m({kind:"unreachable",label:z.label}):z.status==="needs-login"&&m({kind:"auth-expired",label:z.label}),S("done"))}),()=>{y=!0}},[]),a.useEffect(()=>{if(!P||!ue())return;let y=!1;const z=W=>{W&&m(W),Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),p(H=>H+1)};return Be().then(async W=>{if(y||W==="switched"||W==="unchanged")return;const H=Re();if(W==="needs-login"){z({kind:"auth-expired",label:H??""});return}if(W==="unreachable"){z(H?{kind:"unreachable",label:H}:null);return}const O=await Ve().catch(()=>({status:"no-candidate"}));y||O.status==="connected"||(O.status==="needs-login"?z({kind:"auth-expired",label:O.label}):O.status==="unreachable"?z({kind:"unreachable",label:O.label}):z(null))}),()=>{y=!0}},[]),a.useEffect(()=>{T(!0)},[T]),a.useEffect(()=>{P&&!ue()||t()},[w,t,P]),a.useEffect(()=>{r&&(o===0&&c({source:"mobileApp:recovery"}),i===0&&d({source:"mobileApp:recovery"}))},[i,r,d,c,o]);const h=a.useRef(!1),[N,b]=a.useState(P);a.useEffect(()=>{if(!P||!r||h.current)return;if(ae.getState().currentSessionId){h.current=!0,b(!1);return}const y=Ye(),z=zs(y);if(!z){h.current=!0,b(!1);return}let W=!1;const H=window.setTimeout(()=>b(!1),6e3);return(async()=>{const O=await Us().catch(()=>null);if(W)return;if(!O){b(!1);return}h.current=!0;const V=O.activeSessions.find(we=>we.id===z.sessionId);if(!V){Bs(y),b(!1);return}const Q=ae.getState();Q.currentSessionId||Q.setCurrentSession(V.id,ft(V)??z.directory??void 0),b(!1)})(),()=>{W=!0,window.clearTimeout(H)}},[w,r,P]),a.useEffect(()=>{r&&$s().focusProject(u,null)},[u,r]),a.useEffect(()=>{if(!f)return;const y=window.setTimeout(()=>E(),5e3);return()=>window.clearTimeout(y)},[E,f]),a.useEffect(()=>{if(!(!r&&(P?!!ue():!0))){R(!1);return}const z=window.setTimeout(()=>{R(!0)},P?4e3:8e3);return()=>window.clearTimeout(z)},[r,P,w,A]),Ws(),Vn({enabled:!0}),fs(),va({enabled:P&&r}),ua({ready:P&&r&&s});const M=ba(),F=!r&&l==="reconnecting";if(!M)return n.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:n.jsx(me,{width:120,height:120,isAnimated:!0})});const te=!!ue();return P&&(!te||!r&&!F)?te?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(me,{width:120,height:120,isAnimated:!L}),L?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(ee,{type:"button",variant:"outline",onClick:()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),p(y=>y+1)},children:"Use another server"})]}):null]})}):v!=="done"?n.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[n.jsx(me,{width:120,height:120,isAnimated:!0}),j?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(Fs,{text:j,showElapsed:!1})})]}):null]}):n.jsx(n.Fragment,{children:n.jsx(Kr,{onConnected:()=>p(y=>y+1),notice:U})}):!r&&!F?L?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(me,{width:120,height:120,isAnimated:!0})}):n.jsx(oe,{children:n.jsx(Ks,{children:n.jsxs(Hs,{apis:e,children:[n.jsx(Vs,{}),n.jsx(Xs,{delayDuration:300,skipDelayDuration:150,children:n.jsxs(ps,{children:[n.jsx(ms,{}),n.jsxs("div",{className:"h-full bg-background text-foreground",children:[P&&N?n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:n.jsx(me,{width:120,height:120,isAnimated:!0})}):null,n.jsx(Gs,{embeddedBackgroundWorkEnabled:s}),n.jsx(vr,{}),n.jsx(ya,{onActiveConnectionDeleted:()=>{Ee({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),p(y=>y+1)}}),n.jsx(hs,{}),n.jsx(ys,{}),n.jsx(Js,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),n.jsx(qs,{})]})]})})]})},A)})}const Sa=()=>{Hn().then(async()=>{try{await Promise.all([an(),Xn()])}catch(e){console.error("[mobile-main] settings init failed:",e)}tr(),nr(),Gn()}).catch(e=>{console.error("[mobile-main] appearance init failed:",e)}).finally(()=>{fr()})};function ja(e){window.__PICHAMBER_SURFACE__="mobile",Ys(),Sa(),xr(),Qs();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??lt();if(!l)throw new Error("Runtime APIs not registered");const o=r?{...l,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:l,i=n.jsx(ka,{apis:o});On.createRoot(t).render(n.jsx(it.StrictMode,{children:n.jsx(Zs,{children:n.jsx(bs,{children:r?i:n.jsx(er,{children:i})})})}))}const za=Object.freeze(Object.defineProperty({__proto__:null,renderMobileApp:ja},Symbol.toStringTag,{value:"Module"}));export{Oa as m,za as r};
|