@pi-chamber/web 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CommitSection-0zl1puqf.js → CommitSection-MZJqMxUT.js} +1 -1
- package/dist/assets/DiagramEditor-DmDE7OFs.js +1 -0
- package/dist/assets/DiagramView-DjMwKAR1.js +1 -0
- package/dist/assets/{DiffView-BoTz2Zqe.js → DiffView-C3F9al7D.js} +2 -2
- package/dist/assets/{FilesView-CVMNE9Pr.js → FilesView-DzboGeAe.js} +6 -6
- package/dist/assets/{GitView-DnsbCAWl.js → GitView-BfyNIPaR.js} +4 -4
- package/dist/assets/{JsonTreeView-Cn1Mk0Wf.js → JsonTreeView-CGH92Uqo.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DJKD8tNq.js → MarkdownRendererImpl-DAV0eoSb.js} +2 -2
- package/dist/assets/{PatchDiff-GdGq3IlM.js → PatchDiff-Dux9rNuF.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CdkAUt-S.js → PierreDiffViewer-9imQKDgh.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-BTzVmIop.js → SessionSwitcherContent-BL7f43TK.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-D86K7VFR.js +2 -0
- package/dist/assets/SessionUnreadDot-BfH_vRW9.js +1 -0
- package/dist/assets/SettingsView-CRYyy2nz.js +4 -0
- package/dist/assets/SettingsWindow-CAMrbwzB.js +1 -0
- package/dist/assets/{ToolOutputDialog-BHaf293m.js → ToolOutputDialog-D6AeevDV.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BTMXNcqG.js → ToolPartDiffPreview-Bkjc2WKO.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CRVvv23V.js → VirtualizedFileDiff-B2HHw9NH.js} +4 -4
- package/dist/assets/{WindowsWindowControls-CTtxXnD1.js → WindowsWindowControls-D1V7M-q1.js} +131 -126
- package/dist/assets/collapsible-IV1T6v7c.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-D1I8YrPV.js → computeVirtualFileMetrics-BxQbLxY-.js} +1 -1
- package/dist/assets/contextFileOpenGuard-xvnEr8Go.js +1 -0
- package/dist/assets/index--5Zr-fSk.js +8 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/{index-DbghctxK.js → index-Jd0py_uf.js} +1 -1
- package/dist/assets/{isDiffPlainText-BK9bF1l5.js → isDiffPlainText-BEflvkV4.js} +1 -1
- package/dist/assets/{isFilePlainText-Cua0RCRz.js → isFilePlainText-Byt9dFxj.js} +1 -1
- package/dist/assets/{main-CoA--JT-.js → main-DLedH1mh.js} +7 -7
- package/dist/assets/main-DOqxJvVh.js +2 -0
- package/dist/assets/markdownCore-U_gf0I8i.js +3 -0
- package/dist/assets/miniChat-BkwDDO9w.js +2 -0
- package/dist/assets/mobile-BrrYaFh4.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-IM1L48Ek.js +2 -0
- package/dist/assets/renderMobileApp-ChddJ_wj.js +14 -0
- package/dist/assets/{runtimeSurface-UriLeO95.js → runtimeSurface-D3p7a-uO.js} +1 -1
- package/dist/assets/{useInlineCommentController-5XANmO1k.js → useInlineCommentController-BASCWgsn.js} +2 -2
- package/dist/assets/usePanelSlide-UOz-oH7E.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-DAaVsdjo.js +10 -0
- package/dist/assets/{useSwitcherItems-Cc6Tx-LO.js → useSwitcherItems-CAx_SuxF.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DxpwplIe.js → vendor-codemirror-language-data-UQYGQ5y2.js} +2 -2
- package/dist/assets/{web-components-g7DKkne_.js → web-components-D08z3xzy.js} +4 -4
- package/dist/index.html +7 -4
- package/dist/mini-chat.html +6 -3
- package/dist/mobile.html +6 -3
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +2 -2
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/service.js +16 -53
- package/server/lib/git/service.test.js +40 -40
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +278 -5
- package/server/lib/pi/routes.test.js +0 -25
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +6 -3
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +304 -34
- package/server/lib/pi/session-daemon/session-daemon.test.js +89 -1
- package/server/lib/pi/small-model-generation.js +14 -1
- package/server/lib/pi/small-model-generation.test.js +20 -5
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/providers/openai-compatible-provider.test.js +1 -1
- package/server/lib/workspace/host.js +1 -1
- package/dist/assets/DiagramEditor-CFV_TjE2.js +0 -1
- package/dist/assets/DiagramView-0I4PZUpw.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DuPmnk3k.js +0 -2
- package/dist/assets/SessionUnreadDot-ogHL0INY.js +0 -1
- package/dist/assets/SettingsView-SHhVrRdh.js +0 -4
- package/dist/assets/SettingsWindow-D_D1qqLF.js +0 -1
- package/dist/assets/collapsible-BO4qEdib.js +0 -1
- package/dist/assets/contextFileOpenGuard-w5xG9Qz2.js +0 -1
- package/dist/assets/index-3zee2IYy.css +0 -1
- package/dist/assets/index-CI-cd-mw.js +0 -8
- package/dist/assets/main-BNJQ6mSF.js +0 -2
- package/dist/assets/markdownCore-BGlLZrb8.js +0 -3
- package/dist/assets/miniChat-DU2jFhXq.js +0 -2
- package/dist/assets/mobile-B3lJ_CJR.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-BfXYv3zl.js +0 -2
- package/dist/assets/renderMobileApp-Cd_F7yMe.js +0 -14
- package/dist/assets/usePanelSlide-CBZw2Cjo.js +0 -56
- package/dist/assets/useWindowTitle-Bf8ZNN_R.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderMobileApp-ChddJ_wj.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CNckGUMB.js","assets/vendor-katex-Cp579UoJ.css","assets/index--5Zr-fSk.js","assets/vendor-zustand-CnsBKjP5.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index--zDkVFU6.css","assets/usePushVisibilityBeacon-DAaVsdjo.js","assets/WindowsWindowControls-D1V7M-q1.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-base-ui-DL8r2fgQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/runtimeSurface-D3p7a-uO.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-E2vgV9K3.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-BUlYhQ3o.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BS2SpSAZ.js","assets/vendor-codemirror-lang-json-CqayksDf.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-Ba8JZ6fp.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-DK27qQri.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CvO36Y1p.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-UQYGQ5y2.js","assets/vendor-codemirror-lang-python-_2bIYTiJ.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-RrgJ8H_6.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-CW8w438f.js","assets/usePanelSlide-UOz-oH7E.js","assets/SessionUnreadDot-BfH_vRW9.js","assets/permissionStore-BRcQ9Jgt.js","assets/usePanelSlide-BV3KOtdA.css","assets/SettingsView-CRYyy2nz.js","assets/vendor-qrcode-COsmt6jn.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-IV1T6v7c.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/useSwitcherItems-CAx_SuxF.js","assets/CommitSection-MZJqMxUT.js","assets/PierreDiffViewer-9imQKDgh.js","assets/web-components-D08z3xzy.js","assets/computeVirtualFileMetrics-BxQbLxY-.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-B2HHw9NH.js","assets/isDiffPlainText-BEflvkV4.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-BASCWgsn.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-remixicon-react-CzPq62YO.js","assets/main-DLedH1mh.js","assets/contextFileOpenGuard-xvnEr8Go.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as a}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as m,g as f}from"./index--5Zr-fSk.js";import{r as w}from"./runtimeSurface-D3p7a-uO.js";import"./vendor-katex-CNckGUMB.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function _(t={}){const{immediate:r=!1,onNeedRefresh:i,onOfflineReady:n,onRegistered:s,onRegisteredSW:c,onRegisterError:d}=t;let o,u;const l=async(e=!0)=>{await u};async function p(){if("serviceWorker"in navigator){if(o=await a(async()=>{const{Workbox:e}=await import("./vendor-workbox-window-BIl4cyR9.js");return{Workbox:e}},[]).then(({Workbox:e})=>new e("/sw.js",{scope:"/",type:"classic"})).catch(e=>{d?.(e)}),!o)return;o.addEventListener("activated",e=>{(e.isUpdate||e.isExternal)&&window.location.reload()}),o.addEventListener("installed",e=>{e.isUpdate||n?.()}),o.register({immediate:r}).then(e=>{c?c("/sw.js",e):s?.(e)}).catch(e=>{d?.(e)})}}return u=p(),l}const v=w(),g=()=>!(!("serviceWorker"in navigator)||!window.isSecureContext||window.location.protocol!=="http:"&&window.location.protocol!=="https:"||document.prerendering||String(document.visibilityState)==="prerender"),S=t=>{let r=!1;const i=()=>{r||g()&&(r=!0,t())},n=()=>{setTimeout(i,0)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0}),(document.prerendering||String(document.visibilityState)==="prerender")&&document.addEventListener("visibilitychange",i,{once:!0})},E=()=>{S(()=>{try{_({onRegisterError(t){console.warn("[PWA] service worker registration skipped:",t)}})}catch(t){console.warn("[PWA] service worker registration skipped:",t)}})},R=async()=>{if(window.__PICHAMBER_RUNTIME_APIS__=m(),v==="mobile"){const{renderMobileApp:t}=await a(async()=>{const{renderMobileApp:r}=await import("./renderMobileApp-ChddJ_wj.js").then(i=>i.r);return{renderMobileApp:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129]));t();return}await f(),await a(()=>import("./main-DLedH1mh.js"),__vite__mapDeps([130,1,2,3,4,5,6,7,8,9,10,14,83,12,13,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,84,85,86,131]))};R();E();
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-katex-CNckGUMB.js","assets/vendor-katex-Cp579UoJ.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as E}from"./vendor-vite-runtime-DD1OZmLC.js";import{g as v,B as $}from"./vendor-marked-CX41MkDF.js";import{p}from"./vendor-dompurify-r8glNMJW.js";import{dV as C,dW as O,dX as I}from"./WindowsWindowControls-D1V7M-q1.js";import{p as P}from"./vendor-remend-BWYYytN3.js";const R=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),x=["script","style"],A=e=>v.lexer(e),H=e=>/^\[[^\]]+\]:\s+\S+/m.test(e)||/^\[\^[^\]]+\]:\s+/m.test(e),D=e=>{const t=e.match(/^[ \t]{0,3}(`{3,}|~{3,})/);if(!t)return!1;const n=t[1];if(!n)return!1;const r=n[0],s=n.length,a=e.trimEnd().split(`
|
|
3
|
+
`).at(-1)?.trim()??"";return!new RegExp(`^[\\t ]{0,3}${r}{${s},}[\\t ]*$`).test(a)},pe=e=>{const t=e.replace(/^\n+/,"");return!!(/^[ \t]{0,3}(`{3,}|~{3,})/.test(t)||/^[ \t]{0,3}(?:> |[-*+] |\d+[.)] )/.test(t))},N=e=>{try{return P(e,{linkMode:"text-only"})}catch{return e}},g=(e,t)=>[{raw:e,src:e,mode:t?"live":"full",highlight:!t}],y=(e,t)=>{let n=-1;for(let s=e.length-1;s>=0;s-=1)if(e[s]?.type!=="space"){n=s;break}if(n<0)return[];const r=[];for(let s=0;s<e.length;s+=1){const a=e[s];if(!a||a.type==="space")continue;const i=a.raw??"",c=t.markLastLive&&s===n,o=a.type==="code"&&D(i);r.push({raw:i,src:o||c?i:N(i),mode:c?"live":"full",highlight:!t.cheap&&!o})}return r},b=(e,t,n=A)=>[{raw:e,src:e,mode:"full",highlight:!0}],F=2;class G{constructor(t=A){this.lex=t}prevText="";frozenSrc="";frozenBlocks=[];cached=null;update(t){if(this.cached&&t===this.prevText)return this.cached;if(this.prevText&&!t.startsWith(this.prevText)&&(this.frozenSrc="",this.frozenBlocks=[]),this.prevText=t,H(t))return this.frozenSrc="",this.frozenBlocks=[],this.cached=g(t,!0),this.cached;this.frozenSrc&&!t.startsWith(this.frozenSrc)&&(this.frozenSrc="",this.frozenBlocks=[]);const n=t.slice(this.frozenSrc.length);let r;try{r=this.lex(n)}catch{return this.cached=g(t,!0),this.cached}const s=[];for(let o=0;o<r.length;o+=1)r[o]?.type!=="space"&&s.push(o);const a=Math.max(0,s.length-F);if(a>0){const o=(s[a-1]??-1)+1,l=r.slice(0,o),d=y(l,{markLastLive:!1,cheap:!0});this.frozenBlocks=[...this.frozenBlocks,...d],this.frozenSrc+=l.map(m=>m.raw??"").join(""),r=r.slice(o)}const i=y(r,{markLastLive:!0,cheap:!0}),c=i.length>0?[...this.frozenBlocks,...i]:this.frozenBlocks.length>0?this.frozenBlocks:g(t,!0);return this.cached=c,c}}const j=32,h=new Map,W=e=>{const t=h.get(e);if(t)return h.delete(e),h.set(e,t),t;const n=new G;for(h.set(e,n);h.size>j;){const r=h.keys().next().value;if(typeof r!="string")break;h.delete(r)}return n},_=e=>{h.delete(e)},me=(e,t)=>{if(!e||e.length===0||e.length!==t.length||t[t.length-1]?.mode!=="live"||e[e.length-1]?.mode!=="live")return!1;for(let r=0;r<t.length-1;r+=1){const s=e[r],a=t[r];if(!s||!a||s.mode!=="full"||a.mode!=="full"||s.raw!==a.raw)return!1}return!0},u=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">");let k=null;const q=()=>(k||(k=E(()=>import("./vendor-katex-CNckGUMB.js"),__vite__mapDeps([0,1])).then(e=>e.default??e)),k),w=async(e,t,n)=>{try{return(await q()).renderToString(e,{displayMode:n,throwOnError:!1})}catch{return t}},B={name:"inlineMath",level:"inline",start(e){const t=e.indexOf("\\(");return t<0?void 0:t},tokenizer(e){const t=/^\\\(([\s\S]+?)\\\)/.exec(e);if(t)return{type:"inlineMath",raw:t[0],text:t[1]??""}},async renderer(e){const t=e;return w(t.text,t.raw,!1)}},T={name:"blockMath",level:"block",start(e){const t=e.indexOf("\\[");return t<0?void 0:t},tokenizer(e){const t=/^\\\[([\s\S]+?)\\\]/.exec(e);if(t)return{type:"blockMath",raw:t[0],text:t[1]??""}},async renderer(e){const t=e;return w(t.text,t.raw,!0)}},X={html({text:e}){return R(e)},link({href:e,title:t,text:n}){const r=e??"";if(C(r))return`<span data-pichamber-agent-mention="true" class="text-primary">${n}</span>`;const a=O(r);if(a)return`<a href="${u(r)}" data-skill-name="${u(a)}" class="text-primary hover:underline">${n}</a>`;const i=t?` title="${u(t)}"`:"";return`<a href="${u(r)}"${i} class="external-link" target="_blank" rel="noopener noreferrer">${n}</a>`}},S={gfm:!0,breaks:!1,renderer:X},U=new $(S),V=new $({...S,async:!0,extensions:[B,T]});v.use({...S,extensions:[B,T]});const Z=async e=>{const t=e.split(/(\$\$[\s\S]*?\$\$)/g);return(await Promise.all(t.map(async r=>{const s=/^\$\$([\s\S]*?)\$\$$/.exec(r)?.[1];return s===void 0?r:w(s,r,!0)}))).join("")},J=async e=>{if(e.indexOf("$")===-1)return e;const t=/(<(?:pre|code|kbd)[^>]*>[\s\S]*?<\/(?:pre|code|kbd)>)/gi,n=e.split(t);return(await Promise.all(n.map(async(s,a)=>a%2===1?s:Z(s)))).join("")},Q=/<pre><code(?:\s+class="language-([^"]*)")?>([\s\S]*?)<\/code><\/pre>/g,Y=1200,K=(e,t)=>{let n=1;for(let r=0;r<e.length;r+=1)if(e.charCodeAt(r)===10&&++n>t)return!0;return!1},ee=e=>e.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/&/g,"&"),te=async e=>{const t=[...e.matchAll(Q)];if(t.length===0)return e;const n=Y;let r=e;for(const s of t){const[a,i,c]=s,o=(i||"text").toLowerCase();if(o==="mermaid")continue;const l=ee(c??"");if(K(l,n)){r=r.replace(a,()=>a.replace("<pre",`<pre data-md-lang="${o}"`));continue}const d=await I(l,o);if(d){const m=d.replace(/^<pre/,`<pre data-md-lang="${o}"`);r=r.replace(a,()=>m)}}return r},re={USE_PROFILES:{html:!0,mathMl:!0,svg:!0},ADD_TAGS:["svg","path","g","rect","line","polygon","polyline","circle","ellipse","text","tspan","defs","marker"],ADD_ATTR:["d","viewBox","preserveAspectRatio","xmlns","target","fill","stroke","stroke-width","transform","points","x","y","x1","y1","x2","y2","cx","cy","r","rx","ry","style"],FORBID_TAGS:[...x],FORBID_CONTENTS:[...x]};let z=!1;const ne=()=>{z||typeof window>"u"||!p.isSupported||(z=!0,p.addHook("afterSanitizeAttributes",e=>{e instanceof HTMLAnchorElement&&e.target==="_blank"&&e.setAttribute("rel","noopener noreferrer")}))},L=e=>p.isSupported?(ne(),p.sanitize(e,re)):"",se=240,f=new Map,ae=e=>{let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)},M=(e,t)=>{if(f.delete(e),f.set(e,t),f.size<=se)return;const n=f.keys().next().value;n&&f.delete(n)},oe=async e=>{const t=await V.parse(e.src),n=e.highlight?await J(t):t,r=e.highlight?await te(n):n;return L(r)},ie=e=>{if(!e)return"";const t=U.parse(e);return L(t)},ce=async(e,t,n)=>{if(!e)return n&&_(n),[];let r;return t?r=W(n).update(e):(_(n),r=b(e)),Promise.all(r.map(async(s,a)=>{if(s.mode==="live")return{id:`live:${a}`,html:"",mode:"live",raw:s.raw};const i=ae(s.raw),c=`${i}:${s.mode}:${s.highlight?1:0}`,o=`${n}:${a}:${s.mode}`,l=f.get(o);if(l&&l.hash===i)return M(o,l),{id:c,html:l.html,mode:s.mode,raw:s.raw};const d=await oe(s);return M(o,{hash:i,html:d}),{id:c,html:d,mode:s.mode,raw:s.raw}}))},ge=Object.freeze(Object.defineProperty({__proto__:null,renderMarkdownBlocks:ce,renderMarkdownSync:ie},Symbol.toStringTag,{value:"Module"}));export{ce as a,pe as b,me as i,ge as m,ie as r,W as s};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderElectronMiniChatApp-IM1L48Ek.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CNckGUMB.js","assets/vendor-katex-Cp579UoJ.css","assets/index--5Zr-fSk.js","assets/vendor-zustand-CnsBKjP5.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index--zDkVFU6.css","assets/usePushVisibilityBeacon-DAaVsdjo.js","assets/WindowsWindowControls-D1V7M-q1.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-base-ui-DL8r2fgQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/runtimeSurface-D3p7a-uO.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-E2vgV9K3.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-BUlYhQ3o.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BS2SpSAZ.js","assets/vendor-codemirror-lang-json-CqayksDf.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-Ba8JZ6fp.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-DK27qQri.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CvO36Y1p.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-UQYGQ5y2.js","assets/vendor-codemirror-lang-python-_2bIYTiJ.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-RrgJ8H_6.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-CW8w438f.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as o}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as t}from"./index--5Zr-fSk.js";import"./vendor-katex-CNckGUMB.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";window.__PICHAMBER_RUNTIME_APIS__=t();o(async()=>{const{renderElectronMiniChatApp:r}=await import("./renderElectronMiniChatApp-IM1L48Ek.js");return{renderElectronMiniChatApp:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(({renderElectronMiniChatApp:r})=>{r()});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/renderMobileApp-ChddJ_wj.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-katex-CNckGUMB.js","assets/vendor-katex-Cp579UoJ.css","assets/index--5Zr-fSk.js","assets/vendor-zustand-CnsBKjP5.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index--zDkVFU6.css","assets/usePushVisibilityBeacon-DAaVsdjo.js","assets/WindowsWindowControls-D1V7M-q1.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-base-ui-DL8r2fgQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/runtimeSurface-D3p7a-uO.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-E2vgV9K3.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-BUlYhQ3o.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BS2SpSAZ.js","assets/vendor-codemirror-lang-json-CqayksDf.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-Ba8JZ6fp.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-DK27qQri.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CvO36Y1p.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-UQYGQ5y2.js","assets/vendor-codemirror-lang-python-_2bIYTiJ.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-RrgJ8H_6.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-CW8w438f.js","assets/usePanelSlide-UOz-oH7E.js","assets/SessionUnreadDot-BfH_vRW9.js","assets/permissionStore-BRcQ9Jgt.js","assets/usePanelSlide-BV3KOtdA.css","assets/SettingsView-CRYyy2nz.js","assets/vendor-qrcode-COsmt6jn.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/collapsible-IV1T6v7c.js","assets/vendor-aparajita-capacitor-secure-storage-5IShChL0.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/useSwitcherItems-CAx_SuxF.js","assets/CommitSection-MZJqMxUT.js","assets/PierreDiffViewer-9imQKDgh.js","assets/web-components-D08z3xzy.js","assets/computeVirtualFileMetrics-BxQbLxY-.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-B2HHw9NH.js","assets/isDiffPlainText-BEflvkV4.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-BASCWgsn.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/vendor-remixicon-react-CzPq62YO.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as t}from"./vendor-vite-runtime-DD1OZmLC.js";import{c as i}from"./index--5Zr-fSk.js";import"./vendor-katex-CNckGUMB.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-react-DYyjh7Q0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";window.__PICHAMBER_RUNTIME_APIS__=i();t(async()=>{const{renderMobileApp:r}=await import("./renderMobileApp-ChddJ_wj.js").then(o=>o.r);return{renderMobileApp:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129])).then(({renderMobileApp:r})=>{r()});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-D86K7VFR.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/WindowsWindowControls-D1V7M-q1.js","assets/index--5Zr-fSk.js","assets/vendor-zustand-CnsBKjP5.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index--zDkVFU6.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-DL8r2fgQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/runtimeSurface-D3p7a-uO.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-E2vgV9K3.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-BUlYhQ3o.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BS2SpSAZ.js","assets/vendor-codemirror-lang-json-CqayksDf.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-Ba8JZ6fp.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-DK27qQri.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CvO36Y1p.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-UQYGQ5y2.js","assets/vendor-codemirror-lang-python-_2bIYTiJ.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-RrgJ8H_6.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-CW8w438f.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,R as a,r as pe,e as we}from"./vendor-react-DYyjh7Q0.js";import"./vendor-katex-CNckGUMB.js";import{m as K,n as Q,Z as ve,G as X,u as oe,aB as F,N as je,R as be,w as le,t as Se,z as Ie,y as Ce}from"./index--5Zr-fSk.js";import{u as Ne,a as Pe,s as De,b as Me,c as ke}from"./usePushVisibilityBeacon-DAaVsdjo.js";import{cr as Ee,I as V,bC as _e,T as Le,l as Oe,m as Te,cs as Ae,ct as Re,g as S,b6 as Be,b as ie,W as w,au as ae,cu as ze,w as Fe,C as Ue,ci as $e,bQ as We,co as de,B as ue,cv as me,cw as He,aK as Ge,t as Ke,a2 as Ve,a3 as Qe,Q as Je,a5 as Ze,a6 as qe,a7 as Xe,a8 as Ye,aa as et,ab as tt,cx as rt,bR as st,aj as nt,ak as ot,al as it}from"./WindowsWindowControls-D1V7M-q1.js";import{_ as at}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-CnsBKjP5.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-DL8r2fgQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-sVFnuruh.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-B7OScDIw.js";import"./runtimeSurface-D3p7a-uO.js";import"./vendor-dnd-kit-core-GipZW2tY.js";import"./vendor-dnd-kit-utilities-CrOcp0Bp.js";import"./vendor-dnd-kit-accessibility-Cv52zwWT.js";import"./vendor-dnd-kit-sortable-Ct2QxIHb.js";import"./vendor-cmdk-BCEUzcHE.js";import"./vendor-radix-ui-react-dialog-jX3Dld8c.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-D1GnwnP9.js";import"./vendor-radix-ui-react-context-CM4yFQ2I.js";import"./vendor-radix-ui-react-id-BcxRjnbX.js";import"./vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js";import"./vendor-radix-ui-react-use-controllable-state-C_ecoh35.js";import"./vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js";import"./vendor-radix-ui-react-primitive-CfpW6_IT.js";import"./vendor-radix-ui-react-slot-BxUc3Pvz.js";import"./vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js";import"./vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js";import"./vendor-radix-ui-react-focus-scope-C2K7lNPv.js";import"./vendor-radix-ui-react-portal-xlJWBfDg.js";import"./vendor-radix-ui-react-presence-Btn-Dp7L.js";import"./vendor-radix-ui-react-focus-guards-D5MZ0nQs.js";import"./vendor-react-remove-scroll-CfeMe0DL.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-C9YRs2nU.js";import"./vendor-react-style-singleton-B1H4bWSG.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-C-AuTczP.js";import"./vendor-use-callback-ref-CJB0R85I.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-E2vgV9K3.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-BUlYhQ3o.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BS2SpSAZ.js";import"./vendor-codemirror-lang-json-CqayksDf.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-Ba8JZ6fp.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-DK27qQri.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CvO36Y1p.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-UQYGQ5y2.js";import"./vendor-codemirror-lang-python-_2bIYTiJ.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-RrgJ8H_6.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-DJASDzNt.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-CW8w438f.js";const ct=({mode:t,children:s})=>e.jsx(Ee.Provider,{value:t,children:s}),lt=Ae,dt=Re,ut=({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:E=!1,cacheRead:g,cacheWrite:I,cacheHitPercent:v})=>{const[P,j]=a.useState(!1),_=typeof n=="number"?n:s,o=lt(s)??0,y=dt(_),x=y==="critical"?"var(--status-error)":y==="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 g=="number"&&typeof I=="number",Z=O?Math.max(0,g):0,Y=O?Math.max(0,I):0,R=typeof v=="number"&&Number.isFinite(v),A=[`Used tokens: ${d(t)}`,`Context limit: ${d(c)}`,`Output limit: ${d(H)}`,...O?[`Cache read: ${d(Z)}`,`Cache write: ${d(Y)}`]:[],...R?[`Cache hit: ${v.toFixed(1)}%`]:[],`${Math.min(s,999).toFixed(1)}% used`],T=!l&&typeof N=="function",B=e.jsxs(e.Fragment,{children:[!l&&!M&&e.jsx(V,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:K("font-medium inline-flex items-center gap-1.5",p),children:L?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${f} ${f}`,className:K("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(_),children:Math.min(s,999).toFixed(1)}),"%"]})})]}),C=K("app-region-no-drag flex items-center gap-1.5 select-none",m==="compact"?"typography-micro":"typography-meta",T?K("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",h),D=T?e.jsx("button",{type:"button",className:C,"aria-label":"Context usage","aria-pressed":E,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(_e,{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(Z)})]}),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(Y)})]})]}):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:K("typography-meta font-semibold",U(_)),children:[Math.min(s,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(Le,{children:[e.jsx(Oe,{asChild:!0,children:D}),e.jsx(Te,{children:e.jsx("div",{className:"space-y-0.5",children:A.map(b=>e.jsx("p",{className:"typography-micro leading-tight",children:b},b))})})]})},mt=a.lazy(()=>at(()=>import("./SessionSwitcherDropdown-D86K7VFR.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}))),pt=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(/\/+$/,"")},ft=({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=ze(s??""),k=Fe(),N=Ue(r=>r.ensureStatus),E=S(r=>r.newSessionDraft?.open?re(r.newSessionDraft.directoryOverride??""):""),[g,I]=a.useState(!1),v=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,P=Number.isFinite(v)&&v>0,{usesFramelessChrome:j,side:_}=$e(),o=P?v>=26?"h-12":v<=15?"h-14":"":"",y=a.useMemo(()=>s?h.find(r=>r.id===s)??null:null,[s,h]);a.useEffect(()=>{ve()&&X("desktop_get_window_pinned").then(r=>{typeof r?.pinned=="boolean"&&I(r.pinned)})},[]);const x=y?.title?.trim()||(n||t==="draft"?"New session":"Session"),d=re(y?.directory??null),U=re(i),f=d||E||U,$=pt(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=We(f||null),O=H&&H!=="HEAD"?H:null,Z=M(),Y=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(q=>q.id===u.providerID)?.models.find(q=>q.id===u.modelID);if(te)return te}},[p,L]),R=Z?.limit?Z:Y,A=R&&typeof R.limit=="object"&&R.limit!==null?R.limit:null,T=A&&typeof A.context=="number"?A.context:0,B=A&&typeof A.output=="number"?A.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=T>0?T:2e5,q=T>0?Math.round(G/T*100):0,ye=B>0?Math.round(r.output/B*100):void 0;return{totalTokens:G,percentage:q,contextLimit:T||0,outputLimit:B||void 0,normalizedOutput:ye,thresholdLimit:te,lastMessageId:u}},[T,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=!g;I(r),X("desktop_set_window_pinned",{pinned:r}).catch(()=>{I(!r)})},[g]),ge=a.useCallback(()=>{const r=s?{sessionId:s,directory:y?.directory??i??""}:{mode:"draft",directory:f||i||"",projectId:c};X("desktop_focus_main_window",r).then(u=>u?.focused===!0?X("desktop_close_current_window"):null)},[i,s,c,f,y]);return e.jsxs("header",{className:K("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&&_==="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(V,{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(mt,{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(V,{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(ut,{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":g?"Unpin Mini Chat window":"Pin Mini Chat window",title:g?"Unpin window":"Pin above other windows",style:ee,children:g?e.jsx(V,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(V,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(ue,{type:"button",variant:"ghost",size:"icon",onClick:ge,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(V,{name:"external-link",className:"h-4 w-4"})}),e.jsx(de,{visible:j&&_==="right",position:"right"})]})},ht=({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(ft,{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(ct,{mode:"mini-chat",children:e.jsx(Be,{autoOpenDraft:s},c??"no-session")})})]})},xt=()=>{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(),X("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(),He(1).then(k=>{const N=S.getState().currentSessionId,E=w.getState().currentAgentName,g=w.getState().currentProviderId,I=w.getState().currentModelId;N&&E&&g&&I&&Ge.getState().saveAgentModelVariantForSession(N,E,g,I,k)}).catch(()=>{Ke.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:E,setModel:g}=w.getState(),I=h.findIndex(j=>j.providerID===k&&j.modelID===N),P=h[(I+(M?1:-1)+h.length)%h.length];E(P.providerID),g(P.modelID),p(P.providerID,P.modelID)}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n?.id,n?.path,s,c,t])},gt="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}},wt=({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),E=w(o=>o.loadAgents),g=w(o=>o.providers.length),I=w(o=>o.agents.length),v=st();a.useEffect(()=>{h()},[h]),a.useEffect(()=>{if(p)return;let o=!0,y=0;const x=window.setInterval(()=>{if(o){if(y+=1,y>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&&(g===0&&N({source:"electronMiniChat:recovery"}),I===0&&E({source:"electronMiniChat:recovery"}))},[I,k,E,N,g]);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 y=o.directory??t.directory;M(t.sessionId,y),j.current=!0},[t,i,s,M,v]),a.useEffect(()=>{const o=y=>{const x=y.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 _=a.useRef(!1);return a.useEffect(()=>{if(_.current||!p)return;const o=()=>{if(_.current)return;_.current=!0;const d=typeof document<"u"?document.getElementById("initial-loading"):null;d&&(d.classList.add("fade-out"),window.setTimeout(()=>d.remove(),300))},y=t.mode==="session"?i===t.sessionId:m,x=window.setTimeout(o,y?100:1500);return()=>window.clearTimeout(x)},[p,t.mode,t.sessionId,i,m]),null},vt=()=>{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(gt),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},jt=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 bt({apis:t}){const s=a.useMemo(()=>yt(),[]),n=Q(c=>c.currentDirectory);return a.useEffect(()=>{const c=n||s.directory;c&&Ve().focusProject(c,null)},[s.directory,n]),a.useEffect(()=>(le(t),()=>le(null)),[t]),Qe(),xt(),Ne({enabled:!0}),e.jsx(Je,{children:e.jsx(Ze,{directory:n||s.directory,children:e.jsxs(qe,{apis:t,children:[e.jsx(Xe,{}),e.jsx(Ye,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(St,{config:s}),e.jsx(et,{}),e.jsx(tt,{})]})})]})})})}const St=({config:t})=>{const s=jt(t);return e.jsxs(e.Fragment,{children:[e.jsx(wt,{config:t}),e.jsx(vt,{}),e.jsx(rt,{embeddedBackgroundWorkEnabled:!0}),e.jsx(ht,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:s})]})},It=()=>{Ie().then(()=>{Promise.all([Ce(),Pe()]).catch(t=>{console.error("[mini-chat-main] settings init failed:",t)}),De(),Me(),ke()}).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");It();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(nt,{children:e.jsx(ot,{children:e.jsx(it,{children:e.jsx(bt,{apis:s})})})})}))}export{Xr as renderElectronMiniChatApp};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-C3F9al7D.js","assets/vendor-react-DYyjh7Q0.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index--5Zr-fSk.js","assets/vendor-zustand-CnsBKjP5.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index--zDkVFU6.css","assets/WindowsWindowControls-D1V7M-q1.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-base-ui-DL8r2fgQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-sVFnuruh.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-B7OScDIw.js","assets/runtimeSurface-D3p7a-uO.js","assets/vendor-dnd-kit-core-GipZW2tY.js","assets/vendor-dnd-kit-utilities-CrOcp0Bp.js","assets/vendor-dnd-kit-accessibility-Cv52zwWT.js","assets/vendor-dnd-kit-sortable-Ct2QxIHb.js","assets/vendor-cmdk-BCEUzcHE.js","assets/vendor-radix-ui-react-dialog-jX3Dld8c.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-D1GnwnP9.js","assets/vendor-radix-ui-react-context-CM4yFQ2I.js","assets/vendor-radix-ui-react-id-BcxRjnbX.js","assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js","assets/vendor-radix-ui-react-use-controllable-state-C_ecoh35.js","assets/vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js","assets/vendor-radix-ui-react-primitive-CfpW6_IT.js","assets/vendor-radix-ui-react-slot-BxUc3Pvz.js","assets/vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js","assets/vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js","assets/vendor-radix-ui-react-focus-scope-C2K7lNPv.js","assets/vendor-radix-ui-react-portal-xlJWBfDg.js","assets/vendor-radix-ui-react-presence-Btn-Dp7L.js","assets/vendor-radix-ui-react-focus-guards-D5MZ0nQs.js","assets/vendor-react-remove-scroll-CfeMe0DL.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-C9YRs2nU.js","assets/vendor-react-style-singleton-B1H4bWSG.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-C-AuTczP.js","assets/vendor-use-callback-ref-CJB0R85I.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-E2vgV9K3.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-BUlYhQ3o.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-BS2SpSAZ.js","assets/vendor-codemirror-lang-json-CqayksDf.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-Ba8JZ6fp.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-DK27qQri.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CvO36Y1p.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-UQYGQ5y2.js","assets/vendor-codemirror-lang-python-_2bIYTiJ.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-RrgJ8H_6.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-tanstack-react-virtual-IrbCBGJ4.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-DJASDzNt.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-CW8w438f.js","assets/PierreDiffViewer-9imQKDgh.js","assets/web-components-D08z3xzy.js","assets/computeVirtualFileMetrics-BxQbLxY-.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-B2HHw9NH.js","assets/isDiffPlainText-BEflvkV4.js","assets/vendor-diff-C3JhlQdm.js","assets/usePanelSlide-UOz-oH7E.js","assets/SessionUnreadDot-BfH_vRW9.js","assets/permissionStore-BRcQ9Jgt.js","assets/usePanelSlide-BV3KOtdA.css","assets/useInlineCommentController-BASCWgsn.js","assets/collapsible-IV1T6v7c.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/contextFileOpenGuard-xvnEr8Go.js","assets/FilesView-DzboGeAe.js","assets/vendor-codemirror-search-8kyQdB3f.js","assets/vendor-replit-codemirror-vim-BJY5fGLS.js","assets/JsonTreeView-CGH92Uqo.js","assets/Virtualizer-BxW2CJGB.js","assets/isFilePlainText-Byt9dFxj.js","assets/DiagramEditor-DmDE7OFs.js","assets/vendor-react-drawio-Boqanm0j.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 De,j as t,R as a,b as Ge,e as ys}from"./vendor-react-DYyjh7Q0.js";import"./vendor-katex-CNckGUMB.js";import{u as de,a as at,b as Dn,d as Kt,i as le,e as Ce,s as Fe,f as nt,r as Mn,h as bs,j as xs,k as _n,p as vs,l as ws,m as H,n as Ln,o as ks,q as js,t as Ct,v as Ss,w as Gt,x as Cs,y as zn,z as Ns}from"./index--5Zr-fSk.js";import{u as Es,a as Rs,s as Ts,b as Ps,c as As}from"./usePushVisibilityBeacon-DAaVsdjo.js";import{u as Be,M as Is,i as Ds,D as Ht,a as Vt,b as Xt,g as Ms,c as qt,d as _s,s as Ls,S as zs,e as Os,T as $s,P as Fs,r as Bs,f as Us,h as Ws,F as Ks,j as Gs,k as Hs,l as Vs,m as Xs,n as qs,H as Js,A as Qs,C as Ys,o as Zs}from"./usePanelSlide-UOz-oH7E.js";import{u as er,a as tr,b as On,c as nr,d as sr,r as Pt,e as rr,t as ie,o as ar,I as G,B as re,P as Ae,f as $n,g as ge,h as ir,i as or,j as lr,k as cr,F as Fn,T as ur,l as dr,m as fr,S as At,O as hr,D as Jt,n as Qt,p as Yt,q as Zt,s as en,v as tn,w as Bn,x as It,y as pr,z as mr,A as gr,C as je,E as yr,G as br,H as xr,J as vr,K as wr,L as kr,M as jr,N as Sr,Q as me,R as Cr,U as Nr,V as Er,W as Se,X as Rr,Y as Un,Z as Tr,_ as Pr,$ as Ar,a0 as Ir,a1 as Dr,a2 as Mr,a3 as _r,a4 as Lr,a5 as zr,a6 as Or,a7 as $r,a8 as Fr,a9 as Br,aa as Ur,ab as Wr,ac as Kr,ad as Gr,ae as Hr,af as Vr,ag as Xr,ah as qr,ai as Jr,aj as Qr,ak as Yr,al as Zr}from"./WindowsWindowControls-D1V7M-q1.js";import{S as ea,A as ta}from"./SettingsView-CRYyy2nz.js";import{_ as He}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as na}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as sa}from"./vendor-capacitor-core-B4EWRrHz.js";import{f as ra,S as aa,a as ia,s as Wn,b as Nt,c as Kn}from"./SessionUnreadDot-BfH_vRW9.js";import{u as oa}from"./useSwitcherItems-CAx_SuxF.js";import{u as la}from"./vendor-tanstack-react-virtual-IrbCBGJ4.js";import{C as ca}from"./CommitSection-MZJqMxUT.js";import{P as ua}from"./PierreDiffViewer-9imQKDgh.js";import{K as nn,P as da,d as fa,p as ha,U as pa,Z as ma,Q as ga,r as ya}from"./vendor-remixicon-react-CzPq62YO.js";let Gn=null,sn=!1;const ba=new Promise(e=>{Gn=e});function xa(){sn||(sn=!0,Gn?.())}const va=6,wa=e=>e.parentID??null,rn=e=>{const n=e.replace(/\/+$/,"");return n.slice(n.lastIndexOf("/")+1)||n},ka=e=>e.replace(/\\/g,"/").replace(/\/+$/,""),ja=(e,n)=>{if(!e)return"";let r=null,s=-1;for(const i of n){const o=ka(i.path);(e===o||e.startsWith(`${o}/`))&&o.length>s&&(r=i,s=o.length)}return r?r.label?.trim()||rn(r.path):rn(e)},Sa=()=>{const e=er.getState().activeSessions,n=tr.getState().index.session.unseenCount,r=de.getState().notifyOnSubtasks,s=On.getState().projects,i=nr.getState().ids,o=sr.getState().rankById;let l=0;const c=[];for(const d of e){const m=wa(d)!==null,R=(n[d.id]??0)>0&&(!m||r);R&&(l+=1),m||c.push({session:d,unread:R,project:ja(Pt(d),s)})}c.sort((d,m)=>rr(d.session,m.session,i,o));const u=c.slice(0,va).map(({session:d,unread:m,project:w})=>({id:d.id,title:d.title??"",unread:m,project:w}));return{runtimeKey:at(),attentionCount:l,recentSessions:u}},Ca="__PICHAMBER_WIDGET_SNAPSHOT__",Na=()=>{typeof window>"u"||(window[Ca]=()=>{try{return JSON.stringify(Sa())}catch{return null}})},xt="mobile-app-update-available",an="mobile-app-update-toast-dismissed-version",Ea=()=>{const e=Be(o=>o.available),n=Be(o=>o.runtimeType),r=Be(o=>o.info?.version),s=Be(o=>o.info?.downloadUrl),i=De.useRef(new Set);return De.useEffect(()=>{if(Dn()!=="android"||n!=="mobile"||!e||!r||!s){ie.dismiss(xt);return}Kt().getItem(an)!==r&&(i.current.has(r)||(i.current.add(r),ie.info("PiChamber update available",{id:xt,description:`Version ${r} is ready for Android.`,duration:1/0,icon:t.jsx(G,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:"Download",onClick:()=>{ar(s)}},cancel:{label:"Dismiss",onClick:()=>{Kt().setItem(an,r),ie.dismiss(xt)}}})))},[e,s,n,r]),null},dt="pichamber.mobile.connections.v1",Ra="pichamber.mobile.",on="pichamber.mobile.deviceId",Ta=()=>{try{const e=window.localStorage.getItem(on);if(e&&e.trim())return e.trim();const n=crypto.randomUUID();return window.localStorage.setItem(on,n),n}catch{return crypto.randomUUID()}},ln=()=>`mobile:${Ta()}`,cn=()=>{try{const e=sa.getPlatform();return e==="ios"||e==="android"?e:void 0}catch{return}},Hn=12,Pa=8e3,Aa=2500,Ia=3e3,ft=2500,Vn=()=>{let e=0;return{begin:()=>(e+=1,e),cancel:()=>{e+=1},isCurrent:n=>n===e}},ze=e=>{const n=e.trim();if(!n)return"";const r=/^https?:\/\//i.test(n)?n:`http://${n}`,s=new URL(r);return s.hash="",s.search="",s.pathname=s.pathname.replace(/\/+$/,""),s.toString().replace(/\/+$/,"")},Ze=e=>{try{return new URL(e).host}catch{return e}},Ve=e=>{try{return ze(e)}catch{return e.trim().replace(/\/+$/g,"")}},Dt=(e,n)=>Ve(e)===Ve(n),Mt=e=>`relay:${e.serverId}@${e.relayUrl.trim()}`,Da=e=>`relay://${e.serverId}`,mt=e=>e.candidates.filter(n=>n.kind==="direct"),_e=e=>{const n=e.candidates.find(r=>r.kind==="relay");return n&&n.kind==="relay"?n.relay:null},xe=e=>{const n=mt(e)[0];if(n)return n.url;const r=_e(e);return r?Da(r):""},oe=e=>{const n=_e(e);if(n)return Mt(n);const r=mt(e)[0];return r?Ve(r.url):""},ht=(e,n)=>{const r=e.find(o=>o.kind==="relay"),s=r&&r.kind==="relay"?r.relay.serverId:null,i=new Set(e.filter(o=>o.kind==="direct").map(o=>Ve(o.url)));return n.some(o=>o.kind==="relay"?s!==null&&o.relay.serverId===s:i.has(Ve(o.url)))},_t=e=>{const n=(()=>{try{return ze(e)}catch{return""}})();return n?[{kind:"direct",url:n}]:[]},un=e=>{if(e.candidates&&e.candidates.length>0)return e.candidates;const n=[];return typeof e.url=="string"&&e.url.trim()&&!/^relay:\/\//i.test(e.url.trim())&&n.push(..._t(e.url)),e.relay&&n.push({kind:"relay",relay:e.relay}),n},Lt=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;const n=e;if(typeof n.relayUrl!="string"||!n.relayUrl.trim()||typeof n.serverId!="string"||!n.serverId.trim())return null;const r=n.hostEncPubJwk;if(!r||typeof r!="object"||Array.isArray(r))return null;const s=r;return s.kty!=="EC"||s.crv!=="P-256"||typeof s.x!="string"||!s.x||typeof s.y!="string"||!s.y?null:{relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:s.x,y:s.y}}},gt=e=>{try{return JSON.stringify(e)}catch{return String(e)}},ce=(e,n={})=>{console.info("[mobile-connect]",e,gt(n)),xs("connect",{code:e,status:typeof n.status=="number"?n.status:void 0,detail:typeof n.reason=="string"?n.reason:typeof n.result=="string"?n.result:void 0})},Xe=(e,n={})=>{console.info("[mobile-storage]",e,gt(n))},Ma=e=>{if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}},_a=e=>{if(typeof e!="string")return e??void 0;try{return JSON.parse(e)}catch{return e}},La=async(e,n)=>{if(!le())return null;try{const{CapacitorHttp:r}=await He(async()=>{const{CapacitorHttp:o}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:o}},[]),s=Object.fromEntries(new Headers(n?.headers).entries()),i=await r.request({url:e,method:n?.method||"GET",headers:s,data:_a(n?.body)});return{ok:i.status>=200&&i.status<300,status:i.status,source:"native-http",json:async()=>Ma(i.data)}}catch(r){return console.warn("[mobile-connect]","native-http failed",gt({url:e,error:r instanceof Error?r.message:String(r)})),null}},za=async(e,n)=>{const r=await fetch(e,n).catch(s=>(console.warn("[mobile-connect]","browser-fetch failed",gt({url:e,error:s instanceof Error?s.message:String(s)})),null));return r?{ok:r.ok,status:r.status,source:"browser-fetch",json:()=>r.json()}:null},Ee=async(e,n,r)=>{let s;const i=new Promise(o=>{s=window.setTimeout(()=>{r?.(),o(null)},e)});try{return await Promise.race([n,i])}catch{return null}finally{s!==void 0&&window.clearTimeout(s)}},Le=async(e,n,r)=>{const s=r?.totalTimeoutMs??Pa,i=Date.now(),o=await Ee(Math.min(Aa,s),La(e,n));if(o)return o;const l=new AbortController,c=Math.max(500,s-(Date.now()-i));return Ee(c,za(e,{...n,signal:l.signal}),()=>l.abort())},yt=async e=>{if(!e)return null;const n=await e.json().catch(()=>null);if(!n||typeof n!="object")return null;const r=n;return{authenticated:typeof r.authenticated=="boolean"?r.authenticated:void 0,disabled:typeof r.disabled=="boolean"?r.disabled:void 0,scope:typeof r.scope=="string"?r.scope:void 0}},qe=15e3,Oa=async(e,n,r,s=qe,i)=>{const o=_n({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk}),l=c=>c==="ok"&&i?.keepTunnel?{outcome:c,tunnel:o}:(o.close(),{outcome:c});try{const c=n?{Authorization:`Bearer ${n}`}:void 0,u=await Ee(s,o.fetch("/auth/session",{headers:c}).catch(()=>null));if(ce("relay:session",{ok:u?.ok===!0,status:u?.status??null,hasToken:!!n}),!u)return l("unreachable");if(u.status===401)return l(n?"auth-failed":"needs-login");if(!u.ok&&u.status!==404)return l("auth-failed");const d=await yt(u);return d&&d.disabled!==!0&&d.authenticated===!1?l(n?"auth-failed":"needs-login"):l("ok")}catch(c){throw o.close(),c}},$a=(e,n,r,s,i)=>{const o=typeof window<"u"?window.location.origin:"",l={relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk,...r?{grant:r}:{}};i&&bs(l,i),Fe({apiBaseUrl:o,clientToken:n,runtimeKey:s??Mt(e),relay:l})},Fa=e=>{if(!e||typeof e!="object")return null;const n=e;if(n.kind==="direct")return typeof n.url=="string"&&n.url.trim()?{kind:"direct",url:n.url}:null;if(n.kind==="relay"){const r=Lt(n.relay);return r?{kind:"relay",relay:r}:null}return null},Ba=e=>{if(e.mode==="relay"){const n=Lt(e.relay);return n?[{kind:"relay",relay:n}]:[]}return typeof e.url=="string"?_t(e.url):[]},Oe=()=>{if(typeof window>"u")return[];let e;try{e=JSON.parse(window.localStorage.getItem(dt)||"[]")}catch{return[]}if(!Array.isArray(e))return[];const n=le();return e.flatMap(r=>{if(!r||typeof r!="object")return[];const s=r;if(typeof s.id!="string")return[];const i=Array.isArray(s.candidates)?s.candidates.map(Fa).filter(u=>!!u):Ba(s);if(i.length===0)return[];const o=typeof s.clientToken=="string"&&s.clientToken.trim()?s.clientToken:void 0,l=typeof s.label=="string"&&s.label.trim()?s.label:Ze(xe({candidates:i})),c={id:s.id,label:l,candidates:i,lastUsedAt:typeof s.lastUsedAt=="number"?s.lastUsedAt:0};return n?[{...c,hasToken:!!s.hasToken||!!o}]:[{...c,clientToken:o,hasToken:!!o}]}).sort((r,s)=>s.lastUsedAt-r.lastUsedAt)},Et=e=>e.kind==="relay"?{kind:"relay",relay:{relayUrl:e.relay.relayUrl,serverId:e.relay.serverId,hostEncPubJwk:e.relay.hostEncPubJwk}}:{kind:"direct",url:e.url},zt=e=>{if(typeof window>"u")return;const n=le(),r=e.slice(0,Hn).map(s=>{const i={id:s.id,label:s.label,candidates:s.candidates.map(Et),lastUsedAt:s.lastUsedAt};return n?{...i,hasToken:!!(s.hasToken||s.clientToken)}:{...i,clientToken:s.clientToken}});try{window.localStorage.setItem(dt,JSON.stringify(r))}catch(s){console.warn("[mobile-storage] failed to persist connection metadata",s)}},Xn=(e,n)=>{const r=e.find(o=>n.id&&o.id===n.id||ht(o.candidates,n.candidates)),s=le(),i={id:n.id||r?.id||crypto.randomUUID(),label:n.label,candidates:n.candidates,lastUsedAt:Date.now(),...s?{hasToken:n.hasToken??(!!n.clientToken||r?.hasToken||!1)}:{clientToken:n.clientToken??r?.clientToken,hasToken:!!(n.clientToken??r?.clientToken)}};return[i,...e.filter(o=>o.id!==i.id&&!ht(o.candidates,n.candidates))].slice(0,Hn)},Ot=na,Ua=0,$t=e=>`${Ra}token.${encodeURIComponent(e)}`,Wa=async(e,n)=>{let r;const s=new Promise(i=>{r=window.setTimeout(()=>i(n),Ia)});try{return await Promise.race([e.catch(()=>n),s])}finally{r!==void 0&&window.clearTimeout(r)}},Ft=async(e,n,r)=>le()?Wa(n().catch(s=>(console.warn(`[mobile-storage] ${e} failed`,s),r)),r):r,st=async e=>{Xe("secure:read-start",{key:e});const n=await Ft("secure:read",async()=>(await Ot.internalGetItem({prefixedKey:$t(e),sync:!1})).data,null),r=typeof n=="string"&&n.trim()?n:void 0;return Xe("secure:read",{key:e,hasToken:!!r}),r},Ie=async(e,n)=>{Xe("secure:write-start",{key:e});const r=await Ft("secure:write",async()=>(await Ot.internalSetItem({prefixedKey:$t(e),data:n,sync:!1,access:Ua}),!0),!1);return Xe("secure:write",{key:e,ok:r}),r},Ka=async e=>{await Ft("secure:delete",async()=>(await Ot.internalRemoveItem({prefixedKey:$t(e),sync:!1}),!0),!1)},qn=async(e,n)=>{let r=0,s=0;return{records:await Promise.all(e.map(async o=>{if(!o||typeof o!="object")return o;const l=o,c=typeof l.url=="string"?l.url:null,u=typeof l.clientToken=="string"?l.clientToken.trim():"";if(!c||!u)return o;if(!await n(c,u))return s+=1,o;r+=1;const{clientToken:d,...m}=l;return{...m,hasToken:!0}})),migrated:r,failed:s}},Jn=async()=>{if(typeof window>"u"||!le())return;let e;try{e=JSON.parse(window.localStorage.getItem(dt)||"[]")}catch{return}if(!Array.isArray(e))return;const n=e.filter(s=>!!s&&typeof s=="object"&&typeof s.url=="string"&&typeof s.clientToken=="string"&&!!s.clientToken.trim());if(n.length===0)return;Xe("secure:migrate-start",{count:n.length});const r=await qn(e,async(s,i)=>{const o=Ve(s);return await Ie(o,i)?await st(o)===i:!1});if(r.migrated>0)try{window.localStorage.setItem(dt,JSON.stringify(r.records))}catch(s){console.warn("[mobile-storage] failed to finalize secure token migration",s);return}Xe("secure:migrate-done",{migrated:r.migrated,failed:r.failed})},Qn=async()=>(await Jn(),Oe()),rt=async e=>{const n=Xn(Oe(),e);return zt(n),le()&&e.clientToken&&await Ie(oe({candidates:e.candidates}),e.clientToken),n},Yn=async e=>{const n=Oe(),r=n.find(i=>i.id===e)??null,s=n.filter(i=>i.id!==e);return zt(s),r&&le()&&await Ka(oe(r)),s},Ga=1500,pt=async(e,n,r)=>{const s=r?.fast?{totalTimeoutMs:ft}:void 0,i=_e({candidates:e})?.serverId??null,o=e.find(d=>d.kind==="relay")??null,l=e.filter(d=>d.kind==="direct"),c=async()=>{for(const d of l){const m=ze(d.url)||d.url,w=n?{Authorization:`Bearer ${n}`}:void 0,R=await Le(`${m}/health`,{method:"GET"},s);if(!R?.ok)continue;if(i){const B=await R.json().catch(()=>null),U=B&&typeof B=="object"?B.serverId:null;if(typeof U=="string"&&U&&U!==i){ce("probe:server-id-mismatch",{url:m});continue}}const E=await Le(`${m}/auth/session`,{method:"GET",credentials:n?"omit":"include",headers:w},s);if(E?.status===401)return{status:"needs-login"};if(!E||!E.ok&&E.status!==404)continue;const I=await yt(E);if(I&&I.disabled!==!0&&I.authenticated===!1)return{status:"needs-login"};const A=I?.disabled===!0;return!n&&le()&&!A&&I?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:m}}}return{status:"unreachable"}},u=async()=>{if(!o)return{status:"unreachable"};const{outcome:d,tunnel:m}=await Oa(o.relay,n,void 0,r?.fast?ft:void 0,{keepTunnel:!0});return d==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:m}}:d==="needs-login"||d==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?l.length===0?u():new Promise(d=>{let m=!1,w=!1,R,E=null,I=null;const A=h=>{h?.status==="ok"&&h.transport.kind==="relay"&&h.transport.tunnel?.close()},B=h=>{m||(m=!0,d(h))},U=()=>{w||m||(R!==void 0&&(window.clearTimeout(R),R=void 0),u().then(h=>{if(I=h,m||w){A(h);return}if(h.status==="ok"||h.status==="needs-login"){B(h);return}E&&B(E)}))};c().then(h=>{if(E=h,!m){if(h.status==="ok"||h.status==="needs-login"){w=!0,R!==void 0&&window.clearTimeout(R),A(I),B(h);return}if(I){B(I);return}U()}}),R=window.setTimeout(U,Ga)}):c()},Me=(e,n,r)=>{e.kind==="relay"?$a(e.relay,n,r?.grant,r?.runtimeKey,e.tunnel):Fe({apiBaseUrl:e.url,clientToken:n,runtimeKey:r?.runtimeKey}),ss()},Ue=()=>{const e=Oe()[0];return e?.label?.trim()?e.label:null},ut=async()=>{await Jn();const e=Oe()[0];if(!e)return{status:"no-candidate"};let n;if(le()){if(!e.hasToken)return{status:"no-candidate"};if(n=await st(oe(e)),!n)return{status:"no-candidate"}}else if(n=e.clientToken,!n)return{status:"no-candidate"};const r=await pt(e.candidates,n,{fast:!0});return r.status==="needs-login"?{status:"needs-login",label:e.label}:r.status!=="ok"?{status:"unreachable",label:e.label}:(await rt({id:e.id,label:e.label,candidates:e.candidates}),Me(r.transport,n,{runtimeKey:oe(e)}),{status:"connected"})},Zn=async(e,n)=>{let r="";try{r=ze(e.url)}catch{return!1}if(!r)return!1;const s=e.clientToken?.trim()||void 0,i=s?{Authorization:`Bearer ${s}`}:void 0,o=n?.fast?{totalTimeoutMs:ft}:void 0;if(!(await Le(`${r}/health`,{method:"GET",headers:i},o))?.ok)return!1;const c=await Le(`${r}/auth/session`,{method:"GET",credentials:s?"omit":"include",headers:i},o);if(!c||!c.ok&&c.status!==404)return!1;const u=await yt(c);return!(u&&u.disabled!==!0&&u.authenticated===!1)},Ha=e=>[...e].sort((n,r)=>{const s=(n.priority??100)-(r.priority??100);if(s!==0)return s;const i=o=>o.type==="relay"?2:o.url.startsWith("https://")?0:1;return i(n)-i(r)}).flatMap(n=>{if(n.type==="relay"){const r=Lt({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk});return r?[{kind:"relay",relay:r}]:[]}return _t(n.url)}),dn=async e=>{const n=_e({candidates:e})?.serverId??null;for(const r of e){if(r.kind==="relay"){const o=_n(r.relay),l=await Ee(qe,o.fetch("/health").catch(()=>null));if(ce("establish:relay:health",{ok:l?.ok===!0,status:l?.status??null}),l?.ok)return{kind:"relay",relay:r.relay,tunnel:o};o.close();continue}const s=ze(r.url)||r.url,i=await Le(`${s}/health`,{method:"GET"});if(ce("establish:direct:health",{ok:i?.ok===!0,status:i?.status??null}),!!i?.ok){if(n){const o=await i.json().catch(()=>null),l=o&&typeof o=="object"?o.serverId:null;if(typeof l=="string"&&l&&l!==n){ce("establish:server-id-mismatch",{url:s});continue}}return{kind:"direct",url:s}}}return null},es=async(e,n)=>{if(!nt())return Zn(e,n);const r=await Ee(n?.fast?ft:qe,Mn("/auth/session").then(i=>i).catch(()=>null));if(!r)return!0;if(r.status===401)return!1;if(!r.ok&&r.status!==404)return!0;const s=await yt(r);return!(s&&s.disabled!==!0&&s.authenticated===!1)},Va=e=>e.kind==="relay"?nt():!nt()&&Dt(e.url,Ce()),ts=()=>{const e=at();return e?Oe().find(n=>oe(n)===e)??null:null},Rt=e=>{const n=at();return!!n&&oe(e)===n},et=async()=>{const e=ts();if(!e)return"no-connection";let n;if(le()?n=e.hasToken?await st(oe(e)):void 0:n=e.clientToken,!n)return"unreachable";const r=e.candidates.findIndex(c=>Va(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),s=r>=0?e.candidates.slice(0,r):e.candidates,i=await pt(s,n,{fast:!0});if(i.status==="ok")return await rt({id:e.id,label:e.label,candidates:e.candidates}),Me(i.transport,n,{runtimeKey:oe(e)}),"switched";if(i.status==="needs-login")return"needs-login";if(r>=0&&await es({url:Ce(),clientToken:n},{fast:!0}))return ss(),"unchanged";const o=r>=0?e.candidates.slice(r+1):[],l=await pt(o,n,{fast:!0});return l.status==="ok"?(await rt({id:e.id,label:e.label,candidates:e.candidates}),Me(l.transport,n,{runtimeKey:oe(e)}),"switched"):l.status==="needs-login"?"needs-login":"unreachable"},Xa=5e3;let vt=!1;const ns=async()=>{if(vt)return"skipped";const e=ts();if(!e)return ce("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const n=_e(e);if(!n)return ce("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";vt=!0;try{const r=await Ee(qe,Mn("/api/client-auth/connection/candidates").then(d=>d).catch(()=>null));if(!r?.ok)return ce("candidates:refresh-skip",{reason:"fetch-failed",status:r?.status??null}),"skipped";const s=await r.json().catch(()=>null);if(!s||s.serverId!==n.serverId)return ce("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const i=Array.isArray(s.candidates)?s.candidates:[],o=[];for(const d of i){if(!d||typeof d!="object")continue;const m=d;if(!(m.type!=="lan"||typeof m.url!="string"))try{const w=ze(m.url);w&&!o.includes(w)&&o.push(w)}catch{}}if(o.length===0)return ce("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const l=mt(e).filter(d=>d.url.startsWith("https://")),c=[...o.map(d=>({kind:"direct",url:d})),...l,{kind:"relay",relay:n}];return JSON.stringify(e.candidates.map(Et))===JSON.stringify(c.map(Et))?"unchanged":(ce("candidates:refreshed",{lanCount:o.length}),await rt({id:e.id,label:e.label,candidates:c}),"updated")}finally{vt=!1}},ss=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const e=await ns().catch(()=>"skipped");ce("candidates:refresh-result",{result:e}),e==="updated"&&nt()&&await et().catch(()=>null)})()},Xa)},Bt=e=>{const[n,r]=a.useState(()=>Oe()),[s,i]=a.useState(null),[o,l]=a.useState(null),[c,u]=a.useState(null),d=a.useRef(n),m=a.useRef(null),w=a.useRef(Vn()),R=a.useCallback(g=>{d.current=g,r(g)},[]),E=a.useCallback(g=>{m.current=g,i(g)},[]),I=a.useCallback(g=>{m.current===g&&(m.current=null,i(null))},[]);a.useEffect(()=>{let g=!1;return Qn().then(k=>{g||R(k)}),()=>{g=!0}},[R]);const A=a.useCallback(g=>{const k=Xn(d.current,g);return R(k),zt(k),k},[R]),B=a.useCallback(async g=>{l(null),E("connect");try{const k=un(g);if(k.length===0){l("Enter a server URL.");return}const y=g.id?d.current.find(p=>p.id===g.id):d.current.find(p=>ht(p.candidates,k)),$=g.label?.trim()||y?.label||Ze(xe({candidates:k})),N=g.relayGrant;let F=g.clientToken?.trim()||void 0;const j=!!F;F||(le()?y?.hasToken&&(F=await st(oe({candidates:k}))):F=y?.clientToken),ce("connect:start",{candidates:k.map(p=>p.kind),hasToken:!!F});const S=await pt(k,F);if(ce("connect:probe",{status:S.status}),S.status==="unreachable"){l("Could not reach that PiChamber server.");return}if(S.status==="needs-login"){A({id:y?.id,label:$,candidates:k}),u({id:y?.id??crypto.randomUUID(),label:$,candidates:k,relay:_e({candidates:k})??void 0,relayGrant:N});return}F&&j&&le()&&await Ie(oe({candidates:k}),F),A({id:y?.id,label:$,candidates:k,clientToken:F}),Me(S.transport,F??null,{runtimeKey:oe({candidates:k}),grant:N}),e()}catch(k){console.warn("[mobile-connect] connect threw",k),l("That server URL is not valid.")}finally{I("connect")}},[E,I,e,A]),U=a.useCallback(async g=>{if(m.current==="pairing")return;l(null),E("pairing");const k=Ha(g.candidates);let y=null,$=!1;try{if(y=await dn(k),!y){l("Could not reach that PiChamber server.");return}const N=JSON.stringify({pairingId:g.pairingId,secret:g.secret,clientLabel:"PiChamber Mobile",clientKind:"mobile",deviceName:"PiChamber Mobile",devicePlatform:cn(),dedupeKey:ln()}),F={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:N},j=y.kind==="relay"?await Ee(qe,y.tunnel.fetch("/api/client-auth/pairing/redeem",F).catch(()=>null)):await Le(`${y.url}/api/client-auth/pairing/redeem`,F);if(!j?.ok){l("This server needs a password or client token.");return}const S=await j.json().catch(()=>null),p=typeof S?.clientToken=="string"?S.clientToken.trim():"";if(!p){l("This server needs a password or client token.");return}const v=typeof S?.server?.label=="string"?S.server.label:"",z=g.label||v||Ze(xe({candidates:k}));if(le()&&!await Ie(oe({candidates:k}),p)){l("This server needs a password or client token.");return}A({label:z,candidates:k,clientToken:p}),Me(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},p,{runtimeKey:oe({candidates:k})}),$=y.kind==="relay",e()}catch(N){console.warn("[mobile-connect] pairing threw",N),l("This server needs a password or client token.")}finally{!$&&y?.kind==="relay"&&y.tunnel.close(),I("pairing")}},[E,I,e,A]),h=a.useCallback(async g=>{if(!c||!g.trim()||m.current==="password")return;l(null),E("password");const k=w.current.begin(),y=()=>w.current.isCurrent(k),{id:$,label:N,candidates:F}=c;let j=null,S=!1;try{if(j=await dn(F),!y())return;if(!j){l("Could not reach that PiChamber server.");return}const p={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:g,trustDevice:!0,issueClientToken:!0,clientLabel:"PiChamber Mobile",clientKind:"mobile",devicePlatform:cn(),dedupeKey:ln()})};ce("password:start",{transport:j.kind});const v=j.kind==="relay"?await Ee(qe,j.tunnel.fetch("/auth/session",p).catch(()=>null)):await Le(`${j.url}/auth/session`,p);if(!y())return;if(ce("password:done",{ok:v?.ok===!0,status:v?.status??null}),!v?.ok){l("Could not unlock that server. Check the password.");return}const z=await v.json().catch(()=>null);if(!y())return;const q=typeof z?.clientToken=="string"?z.clientToken.trim():"";if(ce("password:token",{issued:!!q}),!q){if(j.kind==="direct"&&!le()){A({id:$,label:N,candidates:F}),u(null),Me({kind:"direct",url:j.url},null,{runtimeKey:oe({candidates:F})}),e();return}l("This server needs a password or client token.");return}if(le()&&(!y()||(await Ie(oe({candidates:F}),q),!y()))||!y()||(A({id:$,label:N,candidates:F,clientToken:q}),u(null),Me(j.kind==="relay"?{kind:"relay",relay:j.relay,tunnel:j.tunnel}:{kind:"direct",url:j.url},q,{runtimeKey:oe({candidates:F})}),S=j.kind==="relay",!y()))return;e()}catch(p){if(!y())return;console.warn("[mobile-connect] password threw",p),l("Could not unlock that server. Check the password.")}finally{!S&&j?.kind==="relay"&&j.tunnel.close(),y()&&I("password")}},[E,I,e,c,A]),b=a.useCallback(()=>{w.current.cancel(),I("password"),u(null),l(null)},[I]),D=a.useCallback(async g=>{l(null);let k=un(g);const y=g.id?d.current.find(j=>j.id===g.id)??null:null;if(y){const j=k.filter(v=>v.kind==="direct"),S=mt(y).filter(v=>v.url.startsWith("https://")&&!j.some(z=>Dt(z.url,v.url))),p=_e(y);k=[...j,...S,...p?[{kind:"relay",relay:p}]:[]]}if(k.length===0)return l("Enter a server URL."),null;const $=g.clientToken?.trim()||void 0,N=g.label?.trim()||Ze(xe({candidates:k}));if(le()){const j=oe({candidates:k});if($)await Ie(j,$);else if(y?.hasToken){const S=oe(y);if(S&&j&&S!==j){const p=await st(S);p&&await Ie(j,p)}}}return A({id:g.id,label:N,candidates:k,clientToken:$}).find(j=>ht(j.candidates,k))??null},[A]),O=a.useCallback(async g=>{const k=d.current.find($=>$.id===g)??null,y=await Yn(g);return R(y),k},[R]);return{connections:n,isBusy:s!==null,isPasswordBusy:s==="password",error:o,pendingConnection:c,connect:B,redeemPairingConnection:U,submitPassword:h,cancelPassword:b,saveConnection:D,removeConnection:O,setError:l}},ho=Object.freeze(Object.defineProperty({__proto__:null,autoConnectLastInstance:ut,connectionDisplayUrl:xe,createMobilePasswordOperationTracker:Vn,deleteMobileConnection:Yn,getAutoConnectTargetLabel:Ue,getConnectionLabel:Ze,isActiveRuntimeConnection:Rt,isSameConnectionUrl:Dt,loadMobileConnections:Qn,migrateLegacyInlineTokenRecords:qn,normalizeConnectionUrl:ze,refreshActiveConnectionCandidates:ns,relayConnectionRuntimeKey:Mt,reprobeActiveConnection:et,upsertMobileConnection:rt,useMobileConnection:Bt,validateActiveRuntimeSession:es,validateMobileConnectionSession:Zn},Symbol.toStringTag,{value:"Module"})),rs=()=>{if(typeof window>"u")return null;const n=window.Capacitor?.Plugins?.BarcodeScanner;return n&&(typeof n.scan=="function"||typeof n.startScan=="function")?n:null},qa=()=>window.Capacitor?.getPlatform?.()==="android",as=e=>{const n=e.trim();if(!n)return null;if(/^pichamber:\/\//i.test(n)){const r=vs(n);return r?{pairing:r}:null}return/^https?:\/\//i.test(n)?{url:n}:null},is=(e,n)=>{const r=as(e);if(!r&&n?.pairingStringFallback){const s=ws(e);if(s)return{status:"pairing",pairing:s}}return r?"pairing"in r?{status:"pairing",...r}:{status:"ok",...r}:{status:"invalid"}},Ja=async(e,n)=>{if(!e.startScan||!e.stopScan||!e.addListener)return{status:"unsupported"};if(n?.aborted)return{status:"cancelled"};let r,s,i=!1,o=()=>{};const l=new Promise(d=>{o=d}),c=d=>{i||(i=!0,o(d))},u=()=>c({status:"cancelled"});n?.addEventListener("abort",u,{once:!0});try{return(await Promise.allSettled([Promise.resolve(e.addListener("barcodesScanned",({barcodes:m})=>{const w=m?.[0],R=(w?.rawValue??w?.displayValue??"").trim();R&&c(is(R,{pairingStringFallback:!0}))})).then(m=>{r=m}),Promise.resolve(e.addListener("scanError",()=>c({status:"failed"}))).then(m=>{s=m})])).some(({status:m})=>m==="rejected")?c({status:"failed"}):i||e.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await l}finally{n?.removeEventListener("abort",u),await Promise.allSettled([Promise.resolve(r?.remove()),Promise.resolve(s?.remove()),e.stopScan()])}},Tt=()=>rs()!==null,os=async e=>{const n=rs();if(!n)return{status:"unsupported"};try{if(n.requestPermissions){const l=(await n.requestPermissions())?.camera;if(l&&l!=="granted"&&l!=="limited")return{status:"permission-denied"}}if(e?.signal?.aborted)return{status:"cancelled"};if(qa())return Ja(n,e?.signal);if(!n.scan)return{status:"unsupported"};const s=(await n.scan({formats:["QR_CODE"]}))?.barcodes?.[0],i=(s?.rawValue??s?.displayValue??"").trim();return i?is(i):{status:"cancelled"}}catch{return{status:"failed"}}},Ke={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Qe="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",ls=({onCancel:e})=>{const n=a.useRef(null);return a.useLayoutEffect(()=>{const r={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},s={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 i=new Map,o=c=>{!(c instanceof HTMLElement)||c===n.current||i.has(c)||(i.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 l=new MutationObserver(c=>{c.forEach(u=>u.addedNodes.forEach(o))});return l.observe(document.body,{childList:!0}),()=>{l.disconnect(),i.forEach((c,u)=>{u.style.opacity=c.opacity,u.style.pointerEvents=c.pointerEvents}),r.value?document.documentElement.style.setProperty("background-color",r.value,r.priority):document.documentElement.style.removeProperty("background-color"),s.value?document.body.style.setProperty("background-color",s.value,s.priority):document.body.style.removeProperty("background-color")}},[]),a.useEffect(()=>{const r=()=>{document.visibilityState==="hidden"&&e()};return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[e]),Ge.createPortal(t.jsxs("div",{ref:n,role:"dialog","aria-modal":"true","aria-label":"Scan QR code",className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}),t.jsxs(re,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:e,children:[t.jsx(G,{name:"close",className:"size-[18px]"}),"Cancel"]})]}),document.body)},cs=()=>Ge.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[t.jsx(Ae,{width:96,height:96,isAnimated:!0}),t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[t.jsx(G,{name:"loader-4",className:"size-[18px] animate-spin"}),t.jsx("span",{children:"Connecting..."})]})]}),document.body),Qa=({onConnected:e,notice:n=null})=>{const r=Bt(e),{connections:s,isBusy:i,isPasswordBusy:o,error:l,pendingConnection:c}=r,[u,d]=a.useState(""),[m,w]=a.useState(""),[R,E]=a.useState(""),[I,A]=a.useState(!1),[B,U]=a.useState(!1),h=a.useRef(null),b=a.useMemo(()=>Tt(),[]),[D,O]=a.useState(()=>!Tt()),[g,k]=a.useState(null),[y,$]=a.useState(""),N=a.useCallback(v=>{v.preventDefault(),r.connect({url:u,clientToken:R,label:m})},[R,r,m,u]),F=a.useCallback(v=>{if(/^pichamber:\/\//i.test(v.trim())){const z=as(v);if(z){if("pairing"in z){r.redeemPairingConnection(z.pairing);return}d(z.url),z.label&&w(z.label),z.clientToken&&E(z.clientToken);return}}d(v)},[r]),j=a.useCallback(async()=>{if(h.current||i)return;r.setError(null),A(!0);const v=new AbortController;h.current=v;try{const z=await os({signal:v.signal});switch(h.current===v&&(h.current=null,A(!1)),z.status){case"ok":U(!0),d(z.url),z.label&&w(z.label),z.clientToken&&E(z.clientToken),await r.connect({url:z.url,clientToken:z.clientToken,label:z.label});break;case"pairing":U(!0),await r.redeemPairingConnection(z.pairing);break;case"permission-denied":r.setError("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":r.setError("That QR code is not an PiChamber connection code.");break;case"unsupported":r.setError("QR scanning is only available in the installed mobile app.");break;case"failed":r.setError("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{U(!1),h.current===v&&(h.current=null,A(!1))}},[r,i]);a.useEffect(()=>()=>h.current?.abort(),[]);const S=a.useCallback(v=>{v.preventDefault(),r.submitPassword(y)},[r,y]),p=a.useCallback(()=>{$(""),r.cancelPassword()},[r]);return t.jsxs(t.Fragment,{children:[I?t.jsx(ls,{onCancel:()=>h.current?.abort()}):null,B?t.jsx(cs,{}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(Ae,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:"Connect to PiChamber"})]}),n?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(G,{name:n.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:n.kind==="auth-expired"?`Access to ${n.label} has expired or was revoked. Sign in again.`:`Couldn't reach ${n.label}. Check that the server is running.`})]}):null,c?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:S,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(G,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(v=>v.kind==="direct")?xe(c):"via PiChamber Relay"})]})]}),t.jsx("input",{...Ke,value:y,onChange:v=>$(v.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:Qe}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(re,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!y.trim(),children:o?"Connecting...":"Unlock and connect"}),t.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:p,children:"Use another server"})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[b?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(re,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{j()},disabled:I||i,children:[t.jsx(G,{name:"scan-2",className:H("size-[18px]",I&&"animate-pulse")}),i?"Connecting...":"Scan QR code"]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:"On your computer, open «Add a device» to show a QR code, then scan it here."})]}):null,l&&!D?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,s.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:"Saved connections"}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:s.map(v=>{const z=g===v.id;return t.jsxs("button",{type:"button",disabled:i,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:()=>{k(v.id),r.connect({id:v.id,candidates:v.candidates,clientToken:v.clientToken,label:v.label}).finally(()=>k(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(G,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:v.label}),t.jsx("span",{className:H("block truncate typography-small",z?"text-foreground":"text-muted-foreground"),children:z?"Connecting...":v.candidates.some(q=>q.kind==="direct")?xe(v):"via PiChamber Relay"})]}),z?t.jsx(G,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(G,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},v.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[b?t.jsxs("button",{type:"button",onClick:()=>O(v=>!v),"aria-expanded":D,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:"Connect by address"}),t.jsx(G,{name:"arrow-down-s",className:H("size-4 transition-transform duration-200",D&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:D?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:N,children:[t.jsx("input",{...Ke,value:u,onChange:v=>F(v.target.value),placeholder:"http://192.168.1.74:2606","aria-label":"Server URL",type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:D?void 0:-1,className:H(Qe,"text-center")}),t.jsx("input",{value:m,onChange:v=>w(v.target.value),placeholder:"Optional display name","aria-label":"Name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:D?void 0:-1,className:H(Qe,"text-center")}),t.jsx("input",{...Ke,value:R,onChange:v=>E(v.target.value),placeholder:"Paste access token","aria-label":"Client token",tabIndex:D?void 0:-1,autoCapitalize:"none",className:H(Qe,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(re,{type:"submit",variant:b?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||I||!u.trim(),children:i?"Connecting...":"Connect"})]})})})]})]})]})})]})},Ya=10,fn=380,Za=(e,n)=>e.title?.trim()||n,ei=({session:e,meta:n,active:r,onSelect:s})=>{const i=ir(e.id),o=or(e.id),l=i?.type??"idle",c=l==="busy"||l==="retry",u=!c&&o>0&&!r,d=lr(e.id,c),m=c&&d,w=ra(e.time?.updated??e.time?.created??0);return t.jsxs("button",{type:"button",className:H("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]"),onClick:s,style:{touchAction:"manipulation"},children:[t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:H("block truncate typography-ui-label",r?"text-primary":"text-foreground"),children:Za(e,"Untitled Session")}),n?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:n}):null]}),c?t.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-primary","aria-hidden":!0}):u?t.jsx(aa,{label:"Session complete"}):null,m?t.jsx(ia,{sessionId:e.id,running:c,className:"typography-micro"}):u?null:w?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:w}):null]})},ti=({open:e,onClose:n,anchorRef:r})=>{const s=a.useRef(null),[i,o]=a.useState(e),[l,c]=a.useState(!1),{enabled:u}=$n(),d=a.useRef(null),[m,w]=a.useState(null);a.useLayoutEffect(()=>{if(!e||!u||!i)return;const h=()=>{const O=r.current?.getBoundingClientRect(),g=d.current?.getBoundingClientRect();if(!O||!g){w(null);return}const k=O.left-g.left;w(Math.min(Math.max(k,8),Math.max(8,g.width-fn-8)))};h();const b=d.current;if(typeof ResizeObserver>"u"||!b)return;const D=new ResizeObserver(h);return D.observe(b),()=>D.disconnect()},[r,u,e,i]);const R=u&&m!==null,E=ge(h=>h.currentSessionId),I=ge(h=>h.setCurrentSession),A=On(h=>h.setActiveProjectIdOnly),B=oa(e||i,{maxParents:Ya});a.useEffect(()=>{if(e){o(!0),c(!1);return}if(!i)return;c(!0);const h=window.setTimeout(()=>{o(!1),c(!1)},140);return()=>window.clearTimeout(h)},[e,i]),a.useEffect(()=>{if(!e)return;const h=b=>{b.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[n,e]),a.useEffect(()=>{if(!e)return;const h=b=>{const D=b.target;if(!(D instanceof Node)){n();return}s.current?.contains(D)||r.current?.contains(D)||n()};return document.addEventListener("pointerdown",h,!0),()=>document.removeEventListener("pointerdown",h,!0)},[r,n,e]);const U=a.useCallback(h=>{I(h.id,Pt(h)),n()},[n,I]);return i?t.jsxs("div",{ref:d,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[t.jsx("div",{ref:s,role:"dialog","aria-label":"Open session switcher",className:H("flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",R?"absolute origin-top-left":"mx-3 mt-2",l?"pointer-events-none":"pointer-events-auto"),style:{animation:`${l?"session-switcher-out":"session-switcher-in"} ${l?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...R?{top:8,left:m??8,width:`min(${fn}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:B.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:"No recent sessions"}):B.map(h=>{const b=h.node.session,D=[h.secondaryMeta?.projectLabel,h.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(ei,{session:b,meta:D,active:b.id===E,onSelect:()=>{h.projectId&&A(h.projectId),U(b)}},b.id)})})}),t.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},ni=({onOpenSessions:e,onOpenWorkspace:n,compactTitle:r=!1})=>{const[s,i]=a.useState(!1),[o,l]=a.useState(!1),c=a.useRef(null),u=Ln(b=>b.currentDirectory),d=ge(b=>b.currentSessionId),w=ge(a.useCallback(b=>d?b.getDirectoryForSession(d):null,[d]))||u,R=cr(d),E=ge(b=>!!b.newSessionDraft?.open),A=R?.title?.trim()||(d?"Untitled session":"New session");a.useEffect(()=>{i(!1),l(!1)},[d,w]);const B=a.useCallback(()=>{i(!1),l(!1),e()},[e]),U=a.useCallback(b=>{i(D=>{const O=typeof b=="function"?b(D):b;return O&&l(!1),O})},[]),h=a.useCallback(()=>{l(b=>{const D=!b;return D&&i(!1),D})},[]);return t.jsxs(t.Fragment,{children:[t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open sessions and projects",onClick:B,style:{touchAction:"manipulation"},children:t.jsx(G,{name:"list-unordered",className:"size-5"})}),t.jsx("button",{ref:c,type:"button",className:H("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r?"shrink":"flex-1"),"aria-label":"Open session switcher","aria-haspopup":"dialog","aria-expanded":o,onClick:h,style:{touchAction:"manipulation"},children:t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:A}),t.jsx(G,{name:"arrow-down-s",className:H("size-4 shrink-0 text-muted-foreground transition-transform duration-150",o&&"rotate-180")})]})}),r?t.jsx("div",{className:"min-w-0 flex-1"}):null,t.jsx(Is,{open:s,onOpenChange:U,currentSessionId:d,effectiveDirectory:w,isNewSessionDraftOpen:E}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open workspace panel",onClick:()=>{i(!1),l(!1),n()},style:{touchAction:"manipulation"},children:t.jsx(G,{name:"layout-right",className:"size-5"})})]})}),t.jsx(ti,{open:o,onClose:()=>l(!1),anchorRef:c})]})},si=({onActiveConnectionDeleted:e,onConnect:n})=>{const r=Bt(n),{connections:s,isBusy:i,isPasswordBusy:o,error:l,pendingConnection:c,connect:u,submitPassword:d,cancelPassword:m,saveConnection:w,removeConnection:R,setError:E}=r,[I,A]=a.useState(null),B=I?s.find(_=>_.id===I)??null:null,[U,h]=a.useState(null),[b,D]=a.useState(""),[O,g]=a.useState(""),[k,y]=a.useState(""),[$,N]=a.useState(""),[F,j]=a.useState(!1),[S,p]=a.useState(!1),[v,z]=a.useState(!1),[q,Z]=a.useState(null),X=a.useRef(null),T=a.useMemo(()=>Tt(),[]),[V,J]=a.useState(!1),[f,x]=a.useState(null),M=a.useCallback(()=>{A(null),D(""),g(""),y(""),E(null),J(!1)},[E]),W=a.useCallback(_=>{_.preventDefault(),w({id:I??void 0,url:b,label:O,clientToken:k}).then(Y=>{Y&&M()})},[k,I,O,M,w,b]),ee=a.useCallback(async()=>{if(X.current)return;E(null),j(!0);const _=new AbortController;X.current=_;try{const Y=await os({signal:_.signal});switch(X.current===_&&(X.current=null,j(!1)),Y.status){case"ok":D(Y.url),Y.label&&g(Y.label),Y.clientToken&&y(Y.clientToken),J(!0);break;case"pairing":p(!0),await r.redeemPairingConnection(Y.pairing);break;case"permission-denied":E("Camera access is off. Enable it in Settings to scan a QR code.");break;case"invalid":E("That QR code is not an PiChamber connection code.");break;case"unsupported":E("QR scanning is only available in the installed mobile app.");break;case"failed":E("Could not scan that QR code. Try again or enter the URL manually.");break;default:break}}finally{p(!1),X.current===_&&(X.current=null,j(!1))}},[r,E]);a.useEffect(()=>()=>X.current?.abort(),[]);const Q=a.useCallback(_=>{_.preventDefault(),d($)},[$,d]),ae=a.useCallback(()=>{N(""),m()},[m]),Te=a.useCallback(async()=>{if(!v){Z(null),z(!0);try{const _=await ks();Z(_==="copied"?"Diagnostics copied to the clipboard.":_==="downloaded"?"Diagnostics downloaded.":"Diagnostics ready to share.")}catch{Z("Diagnostics export was cancelled or unavailable.")}finally{z(!1)}}},[v]),ue=a.useCallback(_=>{h(Y=>Y===_?null:_)},[]),ye=a.useCallback(_=>{h(null),I===_&&M();const Y=s.length===1;R(_).then(te=>{te&&(Y||Rt(te))&&e()})},[s.length,I,e,R,M]),se=Qe;return c?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:Q,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(G,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:c.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:c.candidates.some(_=>_.kind==="direct")?xe(c):"via PiChamber Relay"})]})]}),t.jsx("input",{...Ke,value:$,onChange:_=>N(_.target.value),placeholder:"PiChamber password","aria-label":"Password",type:"password",autoFocus:!0,className:se}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(re,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:o||!$.trim(),children:o?"Connecting...":"Unlock and connect"}),t.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:ae,children:"Use another server"})]})})}):t.jsxs(t.Fragment,{children:[F?t.jsx(ls,{onCancel:()=>X.current?.abort()}):null,S?t.jsx(cs,{}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[s.length>0?t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:s.map(_=>{const Y=U===_.id,te=Rt(_),we=f===_.id,ve=we?"Connecting...":te?nt()?"Connected · Private relay":"Connected · Local network":_.candidates.some(Pe=>Pe.kind==="direct")?xe(_):"via PiChamber Relay";return t.jsxs("div",{className:H("flex items-center border-b border-border/70 transition-colors last:border-b-0",Y&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{te||(x(_.id),u({id:_.id,candidates:_.candidates,clientToken:_.clientToken,label:_.label}).finally(()=>x(null)))},disabled:i&&!we||Y,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(G,{name:"server",className:"size-[18px]"}),te?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:_.label}),t.jsx("span",{className:H("block truncate typography-small",te&&!we?"text-[var(--status-success)]":"text-muted-foreground"),children:ve})]}),we?t.jsx(G,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[Y?t.jsxs("button",{type:"button","aria-label":`Confirm deleting ${_.label}`,className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>ye(_.id),style:{touchAction:"manipulation"},children:[t.jsx(G,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:"Delete"})]}):_.candidates.some(Pe=>Pe.kind==="direct")?t.jsx("button",{type:"button","aria-label":"Edit",className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{A(_.id),D(xe(_)),g(_.label),y(_.clientToken||""),E(null)},style:{touchAction:"manipulation"},children:t.jsx(G,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":Y?`Keep ${_.label}`:`Delete ${_.label}`,className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>ue(_.id),style:{touchAction:"manipulation"},children:t.jsx(G,{name:Y?"close":"delete-bin",className:"size-[18px]"})})]})]},_.id)})}):t.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:"No saved connections yet."}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs(re,{type:"button",variant:"outline",size:"lg",className:"h-12 w-full",onClick:()=>{Te()},disabled:v,children:[t.jsx(G,{name:"download",className:"size-[18px]"}),v?"Preparing diagnostics…":"Export diagnostics"]}),q?t.jsx("p",{className:"px-1 text-center typography-small text-muted-foreground",children:q}):null]}),!V&&!B?t.jsxs("div",{className:"space-y-2",children:[T?t.jsxs(re,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{ee()},disabled:F,children:[t.jsx(G,{name:"scan-2",className:H("size-[18px]",F&&"animate-pulse")}),"Scan QR code"]}):null,t.jsxs(re,{type:"button",variant:T?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{E(null),J(!0)},children:[t.jsx(G,{name:"add",className:"size-[18px]"}),"Add by address"]}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:W,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:B?"Edit instance":"Add instance"}),t.jsx(re,{type:"button",variant:"ghost",size:"xs",onClick:M,children:"Cancel"})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Server URL"}),t.jsx("input",{...Ke,value:b,onChange:_=>D(_.target.value),placeholder:"http://192.168.1.74:2606",type:"url",inputMode:"url",autoCapitalize:"none",className:se})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Name"}),t.jsx("input",{value:O,onChange:_=>g(_.target.value),placeholder:"Optional display name",autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:se})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:"Client token"}),t.jsx("input",{...Ke,value:k,onChange:_=>y(_.target.value),placeholder:"Paste access token",autoCapitalize:"none",className:se}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:"Only needed if your server requires a token instead of a password."})]}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(re,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:B?"Save changes":"Save instance"})]})]})})})]})},Je=320,Re="cubic-bezier(0.22, 1, 0.36, 1)",us=({side:e,enabled:n,open:r,drawerRef:s,scrimRef:i,onClose:o,widthRatio:l,prefersReducedMotion:c})=>{a.useEffect(()=>{if(!n||!r)return;const u=s.current,d=i.current;if(!u||!d)return;let m=!1,w=!1,R=!1,E=0,I=0,A=0,B=0;const U=c?0:Je,h=e==="left"?"translateX(-100%)":"translateX(100%)",b=()=>({drawer:U?`transform ${U}ms ${Re}`:"none",scrim:U?`opacity ${U}ms ${Re}`:"none"}),D=()=>{const j=b();u.style.transition=j.drawer,d.style.transition=j.scrim,u.style.transform="none",d.style.opacity="1",d.style.pointerEvents="auto"},O=()=>{m=!1,w=!1,R=!1},g=()=>{if(!(m||w)){O();return}D(),O()},k=j=>{if(j.touches.length!==1){(m||w)&&g();return}if(Ds(j.target,u,{excludeInteractive:!1}))return;u.style.transition&&u.style.transition!=="none"&&(u.style.transition="none",d.style.transition="none");const S=j.touches[0];E=S.clientX,I=S.clientY,A=Date.now(),B=u.offsetWidth||window.innerWidth*l,B<10&&(B=window.innerWidth*l),m=!0,w=!1,R=!1},y=j=>{if(!m)return;if(j.touches.length!==1){g();return}const S=j.touches[0],p=S.clientX-E,v=S.clientY-I;if(!R){if(Math.abs(p)<Ht&&Math.abs(v)<Ht)return;if(Math.abs(v)>Math.abs(p)*Vt||!Xt(e,p)){m=!1;return}R=!0,w=!0,u.style.transition="none",d.style.transition="none"}if(!w)return;j.cancelable&&j.preventDefault();const z=qt(e,p,B);u.style.transform=Ms(e,z),d.style.opacity=String(z)},$=(j,S,p)=>{if(!m)return;const v=j-E,z=S-I,q=Math.max(1,Date.now()-A),Z=qt(e,v,B),X=Ls({side:e,dx:v,dy:z,dt:q,progress:Z,isDragging:w}),T=b();u.style.transition=T.drawer,d.style.transition=T.scrim,u.style.transform=X?h:"none",d.style.opacity=X?"0":"1",d.style.pointerEvents=X?"none":"auto",O(),X&&o()},N=j=>{const S=j.changedTouches[0];if(!S){g();return}const p=S.clientX-E,v=S.clientY-I,z=Math.abs(p)>=_s&&Math.abs(v)<=Math.abs(p)*Vt&&Xt(e,p);m&&(w||z)&&j.cancelable&&j.preventDefault(),$(S.clientX,S.clientY)},F=()=>{g()};return u.addEventListener("touchstart",k,{passive:!0}),u.addEventListener("touchmove",y,{passive:!1}),u.addEventListener("touchend",N,{passive:!1}),u.addEventListener("touchcancel",F,{passive:!0}),()=>{try{g()}catch{}u.removeEventListener("touchstart",k),u.removeEventListener("touchmove",y),u.removeEventListener("touchend",N),u.removeEventListener("touchcancel",F)}},[s,n,o,r,c,i,e,l])},ri=16,hn=a.memo(function({open:n,onOpenChange:r,variant:s="drawer",drawerRefExternal:i,scrimRefExternal:o,rootRefExternal:l}){const c=a.useRef(null),u=a.useCallback(()=>{const y=typeof document<"u"?document.activeElement:null;y instanceof HTMLElement&&c.current?.contains(y)&&y.blur(),r(!1)},[r]),d=ge(y=>y.openNewSessionDraft),m=de(y=>y.setActiveMainTab),w=de(y=>y.setSessionSwitcherOpen),[R,E]=a.useState(!1),I=a.useRef(null),A=a.useRef(null),B=i??I,U=o??A,h=a.useCallback(y=>{c.current=y,l&&(l.current=y)},[l]),b=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]);a.useEffect(()=>{const y=c.current;if(!y||n)return;const $=document.activeElement;$&&y.contains($)&&$.blur()},[n]),a.useEffect(()=>{if(s!=="sidebar"){if(n){const y=window.setTimeout(()=>E(!0),b?0:ri);return()=>window.clearTimeout(y)}E(!1)}},[n,b,s]),a.useEffect(()=>{if(s==="sidebar"||!n)return;const y=document.body.style.overflow;document.body.style.overflow="hidden";const $=N=>{N.key==="Escape"&&u()};return document.addEventListener("keydown",$),()=>{document.body.style.overflow=y,document.removeEventListener("keydown",$)}},[u,n,s]);const D=a.useCallback(()=>{de.getState().closeMainSurfaces(),m("chat"),w(!1),d(),u()},[u,d,m,w]),O=s==="sidebar",g=t.jsx(zs,{mobileVariant:!O,isVisible:n,allowReselect:!0,onSessionSelected:O?void 0:u,onNavigateAway:O?void 0:u});if(us({side:"left",enabled:s==="drawer",open:n,drawerRef:B,scrimRef:U,onClose:u,widthRatio:.72,prefersReducedMotion:b}),s==="sidebar")return t.jsx("aside",{className:"relative flex h-full w-full flex-col bg-sidebar",children:g});if(typeof document>"u")return null;const k=b?0:Je;return Ge.createPortal(t.jsxs("div",{ref:h,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none"},"data-mobile-sessions-root":"true",children:[t.jsx("button",{ref:U,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close sessions",onClick:u,tabIndex:n?0:-1,style:{opacity:R?1:0,transition:`opacity ${k}ms ${Re}`},"data-mobile-sessions-scrim":"true"}),t.jsx("div",{ref:B,className:H("relative z-10 flex h-full w-[72%] max-w-[72%] flex-col bg-sidebar"),style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:R?"none":"translateX(-100%)",transition:k?`transform ${k}ms ${Re}`:"none",touchAction:"pan-x pan-y"},"data-mobile-sessions-drawer":"true",children:g}),t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 z-20 flex w-[28%] items-end justify-center",style:{paddingBottom:"calc(1rem + var(--oc-safe-area-bottom, 0px))"},children:n?t.jsx(re,{type:"button",variant:"outline",size:"lg",className:"pointer-events-auto size-12 rounded-full p-0 [corner-shape:round] supports-[corner-shape:squircle]:rounded-full",onClick:D,"aria-label":"New session",children:t.jsx(G,{name:"chat-new",className:"size-5"})}):null})]}),document.body)}),pn="mobile-surface-root",wt=16,lt=200,ai=()=>{if(typeof document>"u")return null;let e=document.getElementById(pn);return e||(e=document.createElement("div"),e.id=pn,document.body.appendChild(e)),e},kt=({open:e,onClose:n,title:r,subtitle:s,trailing:i,disableEscapeDismiss:o=!1,headerless:l=!1,noHeaderBorder:c=!1,ariaLabel:u,variant:d="fullscreen",dialogAlign:m="chat",children:w})=>{const R=a.useRef(null),[E,I]=a.useState(!1),[A,B]=a.useState(!1),U=a.useRef(null),h=a.useRef(null),b=a.useRef(n);if(a.useEffect(()=>{b.current=n},[n]),typeof document<"u"&&!R.current&&(R.current=ai()),a.useEffect(()=>{if(!e){I(!1);return}const g=window.setTimeout(()=>I(!0),wt);return()=>window.clearTimeout(g)},[e]),a.useEffect(()=>{if(!e){B(!1);return}const g=window.setTimeout(()=>B(!0),wt+lt+80);return()=>window.clearTimeout(g)},[e]),a.useEffect(()=>{if(!e)return;const g=document.body.style.overflow;h.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const k=()=>{const N=U.current;if(!N)return;(N.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??N).focus({preventScroll:!0})},y=window.setTimeout(k,wt),$=N=>{if(N.key==="Escape"&&!o){b.current();return}if(N.key!=="Tab")return;const F=U.current;if(!F)return;const j=Array.from(F.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(z=>!z.hasAttribute("disabled")&&z.getAttribute("aria-hidden")!=="true");if(j.length===0){N.preventDefault(),F.focus({preventScroll:!0});return}const S=j[0],p=j[j.length-1],v=document.activeElement;N.shiftKey&&v===S?(N.preventDefault(),p.focus({preventScroll:!0})):!N.shiftKey&&v===p&&(N.preventDefault(),S.focus({preventScroll:!0}))};return document.addEventListener("keydown",$),()=>{window.clearTimeout(y),document.body.style.overflow=g,document.removeEventListener("keydown",$),h.current?.focus?.({preventScroll:!0}),h.current=null}},[o,e]),!e||!R.current)return null;const D=d==="dialog",O=t.jsxs("section",{ref:U,role:"dialog","aria-modal":"true","aria-label":u,tabIndex:-1,className:H("flex flex-col bg-background text-foreground",D?"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:D?{opacity:E?1:0,transform:E?"none":"scale(0.97)",transition:`opacity ${lt}ms ease-out, transform ${lt}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:E?"none":"translateX(100%)",transition:`transform ${lt}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:g=>{E&&g.target===g.currentTarget&&g.propertyName==="transform"&&B(!0)},children:[l?null:t.jsxs("header",{className:H("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:n,style:{touchAction:"manipulation"},children:t.jsx(G,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[r?typeof r=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:r}):r:null,s?typeof s=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:s}):s:null]}),i?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:i}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:A?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:w}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return D?Ge.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:E?1:0,paddingLeft:m==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:m==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:n,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:g=>g.stopPropagation(),children:O})}),R.current):Ge.createPortal(O,R.current)},ds={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},ii=ds.M;function oi(e){const n=e.index?.trim(),r=e.working_dir?.trim();return n&&n!=="?"?n.charAt(0):r?r.charAt(0):n?.charAt(0)||r?.charAt(0)||"M"}function li(e){const n=oi(e);return ds[n]??ii}const ci=a.memo(function({file:n,actionLabel:r,actionSymbol:s,onAction:i,onViewDiff:o,onRevert:l,isReverting:c,stats:u,rowPaddingClassName:d,indentPx:m=0,actionAtStart:w=!1,showRevert:R=!0}){const E=De.useMemo(()=>li(n),[n]),I=E.description,A=u?.insertions??0,B=u?.deletions??0,U=De.useCallback(O=>{O.key===" "?(O.preventDefault(),i()):O.key==="Enter"&&(O.preventDefault(),o())},[i,o]),h=De.useCallback(O=>{O.preventDefault(),O.stopPropagation(),i()},[i]),b=De.useCallback(O=>{O.preventDefault(),O.stopPropagation(),l()},[l]),D=t.jsx("button",{type:"button",onClick:h,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":r,title:r,children:s});return t.jsxs("div",{className:`group flex items-center gap-2 py-1.5 cursor-pointer ${d??"px-3"}`,role:"button",tabIndex:0,onClick:o,onKeyDown:U,style:m>0?{paddingLeft:`${m}px`}:void 0,children:[w?D:null,t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:E.color},title:I,"aria-label":I,children:E.code}),t.jsx(Fn,{filePath:n.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const O=n.path.lastIndexOf("/");if(O===-1)return t.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:n.path,children:n.path});const g=n.path.slice(0,O),k=n.path.slice(O);return t.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:n.path,children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:g}),t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[t.jsx("span",{className:"text-muted-foreground",children:"/"}),t.jsx("span",{className:"text-foreground",children:k.slice(1)})]})]})})(),t.jsxs("span",{className:"shrink-0 typography-micro",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",A]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",B]})]}),R?t.jsxs(ur,{children:[t.jsx(dr,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,disabled:c,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${n.path}`,children:c?t.jsx(G,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(G,{name:"arrow-go-back",className:"size-3.5"})})}),t.jsx(fr,{sideOffset:8,children:"Revert changes"})]}):null,w?null:D]})}),mn=14,fs=e=>e.replace(/\\/g,"/").replace(/^\/+/,"").trim(),gn=(e,n)=>({id:`dir:${e}`,path:e,name:n,children:new Map,directFiles:[],files:[]}),ui=e=>{const n=gn("","");for(const r of e){const s=fs(r.path);if(!s)continue;const o=s.split("/").filter(Boolean).slice(0,-1);let l=n;if(l.files.push(r),o.length>0){let c="";for(const u of o){c=c?`${c}/${u}`:u;const d=l.children.get(u);if(d){d.files.push(r),l=d;continue}const m=gn(c,u);m.files.push(r),l.children.set(u,m),l=m}}l.directFiles.push(r)}return n},di=(e,n)=>{const r=[],s=(i,o)=>{const l=Array.from(i.children.values()).sort((u,d)=>u.path.localeCompare(d.path));for(const u of l)r.push({key:u.id,kind:"directory",depth:o,directory:u}),n.has(u.path)&&s(u,o+1);const c=[...i.directFiles].sort((u,d)=>u.path.localeCompare(d.path));for(const u of c)r.push({key:`file:${fs(u.path)}`,kind:"file",depth:o,file:u})};return s(e,0),r},fi=1e3,yn=34,jt=30,ct="pl-0 pr-2",St=(e,n)=>`${e} ${n}`,hi=({groups:e,diffStats:n,revertingPaths:r,isRevertingAll:s=!1,headerBackgroundClassName:i="bg-sidebar",onVisiblePathsChange:o,onRevertAll:l,onRevertDirectory:c})=>{const u=a.useRef(null),m=de(f=>f.gitChangesViewMode)==="tree",w=a.useMemo(()=>e.filter(f=>f.entries.length>0),[e]),[R,E]=a.useState(new Set),[I,A]=a.useState(new Set),[B,U]=a.useState(!1),[h,b]=a.useState(null),D=a.useMemo(()=>w.map(f=>ui(f.entries)),[w]),O=a.useMemo(()=>{const f=[];return w.forEach((x,M)=>{Array.from(D[M]?.children.values()??[]).forEach(W=>{f.push(St(x.id,W.path))})}),f},[D,w]);a.useEffect(()=>{m&&A(f=>{const x=new Set,M=new Set(O);return f.forEach(W=>{(W.slice(W.indexOf(" ")+1).includes("/")||M.has(W))&&x.add(W)}),O.forEach(W=>x.add(W)),x})},[m,O]);const g=a.useMemo(()=>{const f=[];return w.forEach((x,M)=>{if(f.push({type:"header",key:`header:${x.id}`,groupIndex:M}),!R.has(x.id)){if(m){const W=new Set;I.forEach(Q=>{Q.startsWith(`${x.id} `)&&W.add(Q.slice(x.id.length+1))}),di(D[M],W).forEach(Q=>{Q.kind==="file"?f.push({type:"file",key:`${x.id}:${Q.key}`,groupIndex:M,file:Q.file,depth:Q.depth}):f.push({type:"directory",key:`${x.id}:${Q.key}`,groupIndex:M,directory:Q.directory,depth:Q.depth})});return}x.entries.forEach(W=>{f.push({type:"file",key:`${x.id}:file:${W.path}`,groupIndex:M,file:W,depth:0})})}}),l&&w.length>0&&f.push({type:"revert-all",key:"revert-all"}),f},[R,I,m,l,D,w]),k=g.length,y=k>=fi,$=la({count:k,enabled:y,getScrollElement:()=>u.current,estimateSize:()=>yn,overscan:12,getItemKey:f=>g[f]?.key??f}),N=$.getVirtualItems(),F=a.useMemo(()=>{if(!y)return 0;const f=u.current?.scrollTop??0;return N.find(M=>M.end>f)?.index??0},[y,N,u]);a.useEffect(()=>{if(!o)return;const f=x=>x&&x.type==="file"?x.file.path:null;if(k===0){o([]);return}if(!y){const x=[];for(const M of g)if(M.type==="file"&&(x.push(M.file.path),x.length>=jt))break;o(x);return}o(g.slice(F,F+Math.ceil((u.current?.clientHeight??0)/yn)+jt).map(x=>f(x)).filter(x=>!!x).slice(0,jt))},[o,k,g,y,F]);const j=a.useCallback(f=>{E(x=>{const M=new Set(x);return M.has(f)?M.delete(f):M.add(f),M})},[]),S=a.useCallback((f,x)=>{A(M=>{const W=new Set(M),ee=St(f,x);return W.has(ee)?W.delete(ee):W.add(ee),W})},[]),p=a.useMemo(()=>{const f=new Set;return w.forEach(x=>x.entries.forEach(M=>f.add(M.path))),Array.from(f)},[w]),v=p.length,z=h?s||h.paths.some(f=>r.has(f)):!1,q=a.useCallback(async()=>{!l||s||p.length===0||(await l(p),U(!1))},[p,s,l]),Z=a.useCallback(async()=>{!c||!h||z||(await c(h.paths),b(null))},[z,c,h]),X=a.useCallback((f,x)=>{const M=R.has(f.id),W=f.entries.length;return t.jsxs("div",{className:H("sticky top-0 z-10 flex items-center gap-2 py-2",i,ct,!x&&"mt-1 border-t border-border/40"),children:[t.jsx("button",{type:"button",onClick:()=>f.onActionAll(f.entries.map(ee=>ee.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":f.actionAllLabel,title:f.actionAllLabel,children:f.actionSymbol}),t.jsxs("button",{type:"button",onClick:()=>j(f.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!M,children:[t.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:f.title}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:W}),t.jsx(G,{name:"arrow-down-s",className:H("size-3.5 shrink-0 text-muted-foreground transition-transform",M&&"-rotate-90")})]})]})},[R,i,j]),T=a.useCallback((f,x,M)=>{const W=I.has(St(f.id,x.path)),ee=x.files.map(ae=>ae.path),Q=s||ee.some(ae=>r.has(ae));return t.jsxs("div",{className:H("group flex items-center gap-2 py-1.5",ct),style:{paddingLeft:`${M*mn}px`},children:[t.jsxs("button",{type:"button",onClick:()=>S(f.id,x.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":W?`Collapse directory ${x.path}`:`Expand directory ${x.path}`,children:[W?t.jsx(G,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):t.jsx(G,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:x.path,children:x.name}),t.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:x.files.length})]}),f.showRevertActions!==!1&&c?t.jsx("button",{type:"button",onClick:()=>b({path:x.path,paths:ee,count:ee.length}),disabled:Q,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${x.path}`,title:"Revert folder changes",children:Q?t.jsx(G,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(G,{name:"arrow-go-back",className:"size-3.5"})}):null,t.jsx("button",{type:"button",onClick:()=>f.onActionAll(x.files.map(ae=>ae.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":f.actionSymbol==="+"?`Stage all changes in ${x.path}`:`Unstage all changes in ${x.path}`,title:f.actionSymbol==="+"?`Stage all changes in ${x.path}`:`Unstage all changes in ${x.path}`,children:f.actionSymbol})]})},[I,s,c,r,S]),V=a.useCallback((f,x)=>{if(f.type==="revert-all")return t.jsx("div",{className:H("flex justify-end py-2",ct),children:t.jsxs(re,{variant:"ghost",size:"sm",onClick:()=>U(!0),disabled:s,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[t.jsx(G,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const M=w[f.groupIndex];if(!M)return null;if(f.type==="header")return X(M,x);if(f.type==="directory")return T(M,f.directory,f.depth);const W=f.file;return t.jsx(ci,{file:W,actionLabel:M.getActionLabel(W.path),actionSymbol:M.actionSymbol,onAction:()=>M.onActionFile(W.path),stats:n?.[W.path],onViewDiff:()=>M.onViewDiff(W.path),onRevert:()=>M.onRevertFile(W.path),isReverting:r.has(W.path)||s,rowPaddingClassName:ct,indentPx:f.depth*mn,actionAtStart:!m,showRevert:M.showRevertActions!==!1})},[n,s,m,T,X,r,w]),J=a.useCallback(f=>{const x=g[f],M=g[f-1];return!x||!M||x.type!=="file"&&x.type!=="directory"||M.type!=="file"&&M.type!=="directory"?!1:M.groupIndex===x.groupIndex},[g]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[t.jsx(At,{ref:u,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:y?t.jsx("div",{style:{height:$.getTotalSize(),position:"relative"},children:N.map(f=>{const x=g[f.index];return x?t.jsx("div",{"data-index":f.index,ref:$.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${f.start}px)`},className:H(J(f.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:V(x,f.index===0)},x.key):null})}):t.jsx("div",{role:"list","aria-label":"Changed files",children:g.map((f,x)=>t.jsx("div",{className:H("relative",J(x)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:V(f,x===0)},f.key))})}),t.jsx(hr,{containerRef:u,disableHorizontal:!0})]}),t.jsx(Jt,{open:B,onOpenChange:f=>{!s&&!f&&U(!1)},children:t.jsxs(Qt,{className:"max-w-md",children:[t.jsxs(Yt,{children:[t.jsx(Zt,{children:"Revert all changes?"}),t.jsx(en,{children:v===1?`Revert ${v} changed file? This cannot be undone.`:`Revert ${v} changed files? This cannot be undone.`})]}),t.jsxs(tn,{children:[t.jsx(re,{variant:"outline",size:"sm",onClick:()=>U(!1),disabled:s,children:"Cancel"}),t.jsx(re,{variant:"destructive",size:"sm",onClick:()=>{q()},disabled:s,children:s?"Reverting...":"Revert all"})]})]})}),t.jsx(Jt,{open:!!h,onOpenChange:f=>{!z&&!f&&b(null)},children:t.jsxs(Qt,{className:"max-w-md",children:[t.jsxs(Yt,{children:[t.jsx(Zt,{children:"Revert folder changes?"}),t.jsx(en,{children:h?h.count===1?`This will discard local changes in ${h.count} file under ${h.path}.`:`This will discard local changes in ${h.count} files under ${h.path}.`:null})]}),t.jsxs(tn,{children:[t.jsx(re,{variant:"outline",size:"sm",onClick:()=>b(null),disabled:z,children:"Cancel"}),t.jsx(re,{variant:"destructive",size:"sm",onClick:()=>{Z()},disabled:z||!h,children:z?"Reverting...":"Revert folder"})]})]})})]})},pi=kr(()=>He(()=>import("./DiffView-C3F9al7D.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])).then(e=>({default:e.DiffView}))),mi=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),gi=e=>{const n=e.index?.trim();return!!(n&&n!=="?")},yi=e=>{const n=e.working_dir?.trim(),r=e.index?.trim();return!!(n||r==="?")},bn=(e,n)=>n?`${e}\0staged`:e,bi=({onClose:e,initialDiffPath:n,initialDiffStaged:r=!1})=>{const{git:s}=Bn(),i=mi(It()??null),o=pr(i||null),l=mr(i||null),c=gr(i||null),u=je(C=>C.setActiveDirectory),d=je(C=>C.ensureAll),m=je(C=>C.fetchStatus),w=je(C=>C.fetchBranches),R=je(C=>C.prefetchDiffs),E=je(C=>C.getDiff),I=je(C=>C.setDiff),[A,B]=a.useState(()=>n?{type:"diff",path:n,staged:r}:{type:"list"});a.useEffect(()=>{n&&B(C=>C.type==="diff"&&C.path===n&&C.staged===r?C:{type:"diff",path:n,staged:r})},[n,r]);const[U,h]=a.useState(null),[b,D]=a.useState(null),[O,g]=a.useState(""),[k,y]=a.useState(new Set),[$,N]=a.useState(!1),[F,j]=a.useState(!1),[S,p]=a.useState([]),[v,z]=a.useState([]),[q,Z]=a.useState([]),[X,T]=a.useState(null),[V,J]=a.useState(null),[f,x]=a.useState(0),M=a.useMemo(()=>{const C=o?.files??[],L=new Map;for(const K of C)L.set(K.path,K);return Array.from(L.values()).sort((K,ne)=>K.path.localeCompare(ne.path))},[o?.files]),W=a.useMemo(()=>M.filter(gi),[M]),ee=a.useMemo(()=>M.filter(yi),[M]),Q=a.useMemo(()=>{if(q.length>0)return q;const C=o?.tracking?.includes("/")?o.tracking.split("/")[0]:null;return C||X?[{name:C||"origin",fetchUrl:X??"",pushUrl:X??""}]:[]},[X,q,o?.tracking]),ae=je(a.useCallback(C=>!i||A.type!=="diff"?null:C.directories.get(i)?.diffCache.get(bn(A.path,A.staged))??null,[i,A])),Te=a.useMemo(()=>A.type!=="diff"?null:M.find(C=>C.path===A.path)??null,[M,A]),ue=a.useCallback(async(C=!0)=>{if(i)try{await Promise.all([m(i,s),w(i,s)])}catch(L){C&&ie.error(L instanceof Error?L.message:"Failed to refresh repository")}},[i,w,m,s]),ye=a.useCallback(async()=>{if(!i){Z([]),T(null);return}try{const[C,L]=await Promise.all([s.getRemotes(i).catch(()=>[]),s.getRemoteUrl?s.getRemoteUrl(i).catch(()=>null):Promise.resolve(null)]);Z(C),T(L)}catch{Z([]),T(null)}},[i,s]);a.useEffect(()=>{i&&(u(i),d(i,s))},[i,d,s,u]),a.useEffect(()=>{ye()},[ye]),a.useEffect(()=>{if(!i||M.length===0)return;const C=Array.from(new Set([...W.map(K=>K.path),...v,...M.slice(0,20).map(K=>K.path)])).filter(Boolean);if(C.length===0)return;const L=window.setTimeout(()=>{R(i,s,C,{maxFiles:40})},120);return()=>window.clearTimeout(L)},[M,i,s,R,W,v]),a.useEffect(()=>{if(A.type!=="diff"){J(null);return}const C=bn(A.path,A.staged);if(!i||E(i,C)){J(null);return}let L=!1;const K=at();return J(null),s.getGitFileDiff(i,{path:A.path,staged:A.staged||void 0}).then(ne=>{L||I(i,C,{original:ne.original??"",modified:ne.modified??"",isBinary:ne.isBinary},K)}).catch(ne=>{L||J(ne instanceof Error?ne.message:String(ne))}),()=>{L=!0}},[i,f,E,s,A,I]);const se=async(C,L)=>{if(i){h(C);try{const K=ne=>{const be=`${ne.name}/`,P=o?.tracking?.startsWith(be)?o.tracking.slice(be.length):void 0;return{remote:ne.name,branch:P,rebase:!0}};if(C==="fetch"){if(!L)throw new Error("No remote available");await s.gitFetch(i,{remote:L.name}),ie.success(`Fetched from ${L.name}`)}else if(C==="sync"){if(!L)throw new Error("No remote available");await s.gitFetch(i,{remote:L.name});const ne=await s.getGitStatus(i);if((ne.behind??0)>0){if((ne.files?.length??0)>0){ie.error("Commit or stash your changes before syncing");return}await s.gitPull(i,K(L))}((await s.getGitStatus(i)).ahead??0)>0&&await s.gitPush(i),ie.success("Already up to date")}await ue(!1),await ye()}catch(K){ie.error(K instanceof Error?K.message:"Sync Changes failed")}finally{h(null)}}},_=a.useCallback(async(C,L)=>{if(!(!i||C.length===0))try{L==="stage"?C.length>1?await yr(i,C):await br(i,C[0]):C.length>1?await xr(i,C):await vr(i,C[0]),await ue(!1)}catch(K){ie.error(K instanceof Error?K.message:L==="stage"?"Failed to stage changes":"Failed to unstage changes")}},[i,ue]),Y=a.useCallback((C,L=!1)=>{B({type:"diff",path:C,staged:L})},[]),te=a.useCallback(async C=>{if(i){y(L=>new Set(L).add(C));try{await s.revertGitFile(i,C),ie.success(`Reverted ${C}`),await ue(!1)}catch(L){ie.error(L instanceof Error?L.message:"Failed to revert changes")}finally{y(L=>{const K=new Set(L);return K.delete(C),K})}}},[i,s,ue]),we=a.useCallback(async C=>{if(!i||C.length===0||$)return;const L=Array.from(new Set(C));N(!0),y(new Set(L));try{await Promise.all(L.map(K=>s.revertGitFile(i,K))),await ue(!1),ie.success(L.length===1?`Reverted ${L.length} file`:`Reverted ${L.length} files`)}catch(K){ie.error(K instanceof Error?K.message:"Failed to revert changes")}finally{y(new Set),N(!1)}},[i,s,$,ue]),ve=a.useCallback(C=>{const L=C.map(K=>K.trim()).filter(Boolean);if(L.length===0){p([]);return}g(K=>`${K.trim()}${K.trim()?`
|
|
12
|
+
|
|
13
|
+
`:""}${L.join(`
|
|
14
|
+
`)}`.trim()),p([])},[]),Pe=a.useCallback(async()=>{if(!i)return;const C=W.map(L=>L.path).sort();if(C.length===0){ie.error("Select at least one file to describe");return}j(!0);try{const{message:L}=await wr(i,C);g(L.subject?.trim()??""),p(Array.isArray(L.highlights)?L.highlights:[])}catch(L){ie.error(L instanceof Error?L.message:"Failed to generate commit message")}finally{j(!1)}},[i,W]),it=async(C={})=>{if(!i)return;if(!O.trim()){ie.error("Enter a commit message");return}const L=W.map(K=>K.path).sort();if(L.length===0){ie.error("Select at least one file to commit");return}D(C.pushAfter?"commitAndPush":"commit");try{if(await s.createGitCommit(i,O.trim(),{files:L}),ie.success("Commit created"),g(""),p([]),C.pushAfter){const K=o?.tracking?.split("/")[0],ne=Q.find(ke=>ke.name===K)??Q[0];if(!ne)throw new Error("No remote available");h("sync");const be=`${ne.name}/`,P=o?.tracking?.startsWith(be)?o.tracking.slice(be.length):void 0;await s.gitFetch(i,{remote:ne.name}),((await s.getGitStatus(i)).behind??0)>0&&await s.gitPull(i,{remote:ne.name,branch:P,rebase:!0}),((await s.getGitStatus(i)).ahead??0)>0&&await s.gitPush(i),await ue(!1),await ye()}else await ue(!1)}catch(K){ie.error(K instanceof Error?K.message:"Failed to create commit")}finally{D(null),C.pushAfter&&h(null)}},bt=a.useMemo(()=>{const C=[];return W.length>0&&C.push({id:"staged",title:"Staged",entries:W,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:L=>`Unstage ${L}`,onActionFile:L=>{_([L],"unstage")},onActionAll:L=>{_(L,"unstage")},onViewDiff:L=>Y(L,!0),onRevertFile:te,showRevertActions:!1,accent:!0}),ee.length>0&&C.push({id:"unstaged",title:"Changes",entries:ee,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:L=>`Stage ${L}`,onActionFile:L=>{_([L],"stage")},onActionAll:L=>{_(L,"stage")},onViewDiff:L=>Y(L,!1),onRevertFile:te}),C},[te,Y,_,W,ee]),$e=C=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsx("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:t.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:o?.current||i||""})}),t.jsx("div",{className:"min-h-0 flex-1",children:C})]});return i?c&&l===null?$e(t.jsx(Ne,{loading:!0,message:"Checking repository..."})):l===!1?$e(t.jsx(a.Suspense,{fallback:t.jsx(Ne,{loading:!0,message:"Loading last turn changes..."}),children:t.jsx(pi,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):A.type==="diff"?t.jsx(xi,{path:A.path,diff:ae,fileExists:!!Te,error:V,onBack:()=>B({type:"list"}),onRetry:()=>x(C=>C+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:e,style:{touchAction:"manipulation"},children:t.jsx(G,{name:"close",className:"size-4"})}):null,t.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:o?.current||i}),t.jsx(Os,{syncAction:U,remotes:Q,onFetch:C=>{se("fetch",C)},onSync:C=>{se("sync",C)},disabled:b!==null||c,aheadCount:o?.ahead??0,behindCount:o?.behind??0,trackingRemoteName:o?.tracking?.split("/")[0],hasUncommittedChanges:M.length>0})]}),M.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-3 pt-2",children:t.jsx(hi,{groups:bt,diffStats:o?.diffStats,revertingPaths:k,onRevertAll:we,isRevertingAll:$,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:z})}),t.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:t.jsx(ca,{stagedCount:W.length,commitMessage:O,onCommitMessageChange:g,generatedHighlights:S,onInsertHighlights:ve,onGenerateMessage:Pe,isGeneratingMessage:F,onCommit:()=>{it({pushAfter:!1})},onCommitAndPush:()=>{it({pushAfter:!0})},commitAction:b,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ne,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):$e(t.jsx(Ne,{message:"Select a session or directory to view Git status"}))},Ne=({message:e,description:n,loading:r=!1,icon:s=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[r?t.jsx(G,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,s?t.jsx(G,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e}),n?t.jsx("p",{className:"typography-meta text-muted-foreground",children:n}):null]})}),xi=({path:e,diff:n,fileExists:r,error:s,onBack:i,onRetry:o})=>{const l=a.useMemo(()=>jr(e)||"text",[e]);return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:i,children:t.jsx(G,{name:"arrow-left",className:"size-4"})}),t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:e})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r?s?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:s}),t.jsx(re,{type:"button",size:"sm",variant:"outline",onClick:o,children:"Retry"})]})}):n?n.isBinary?t.jsx(Ne,{icon:!0,message:"Content of this file cannot be viewed."}):Sr(e)?t.jsx(Ne,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):t.jsx(At,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(ua,{original:n.original,modified:n.modified,language:l,fileName:e,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ne,{loading:!0,message:"Loading diff..."}):t.jsx(Ne,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},fe=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),We=e=>{const n=fe(e);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},hs=e=>{const n=fe(e);if(!n||n==="/")return null;const r=n.lastIndexOf("/");if(r<0)return null;if(r===0)return"/";const s=n.slice(0,r);return/^[A-Za-z]:$/.test(s)?`${s}/`:s},xn=(e,n)=>{const r=fe(e),s=fe(n);return!r||!s?!1:r===s||r.startsWith(`${s}/`)},vn=(e,n)=>{const r=fe(e);if(!r)return fe(n);if(r.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(r))return r;const s=fe(n);return s?`${s}/${r}`:r},vi=(e,n)=>{const r=fe(e),s=fe(n);if(!r||r===s)return!1;const i=hs(r);return i?s&&xn(r,s)?xn(i,s):!0:!1},wi=a.lazy(()=>He(()=>import("./FilesView-DzboGeAe.js"),__vite__mapDeps([120,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,121,122,123,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,124,125,117,118,126,127,115,116])).then(e=>({default:e.FilesView}))),ki=(e,n)=>{const r=fe(e),s=fe(n);return!s||r===s?We(r):r.startsWith(`${s}/`)?r.slice(s.length+1):r},ji=e=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)return"";if(e<1024)return`${e} B`;const n=["KB","MB","GB"];let r=e/1024;for(const s of n){if(r<1024||s===n[n.length-1])return`${r.toFixed(r>=10?0:1)} ${s}`;r/=1024}return""},Si=({onClose:e})=>{const{files:n}=Bn(),r=js(p=>p.setSelectedPath),s=fe(It()??null),[i,o]=a.useState(()=>({type:"browser",directory:s})),[l,c]=a.useState([]),[u,d]=a.useState(!1),[m,w]=a.useState(null),[R,E]=a.useState(""),[I,A]=a.useState([]),[B,U]=a.useState(!1),h=a.useRef(0);a.useEffect(()=>{s&&o(p=>p.type==="browser"&&p.directory?p:{type:"browser",directory:s})},[s]);const b=i.type==="browser"?i.directory:i.returnDirectory,D=a.useCallback(async p=>{if(!p)return;const v=h.current+1;h.current=v,d(!0),w(null);try{const z=await n.listDirectory(p);if(h.current!==v)return;c(z.entries.slice().sort((Z,X)=>Z.isDirectory!==X.isDirectory?Z.isDirectory?-1:1:Z.name.localeCompare(X.name)));const q=fe(z.directory);q&&q!==fe(p)&&o(Z=>Z.type==="browser"&&Z.directory!==q?{type:"browser",directory:q}:Z)}catch(z){if(h.current!==v)return;c([]),w(z instanceof Error?z.message:"Failed to load files")}finally{h.current===v&&d(!1)}},[n]);a.useEffect(()=>{i.type==="browser"&&D(i.directory)},[D,i]),a.useEffect(()=>{if(i.type!=="browser")return;const p=R.trim();if(!p){A([]),U(!1);return}let v=!1;const z=window.setTimeout(()=>{U(!0),n.search({directory:i.directory,query:p,maxResults:40}).then(q=>{v||A(q)}).catch(()=>{v||A([])}).finally(()=>{v||U(!1)})},250);return()=>{v=!0,window.clearTimeout(z)}},[n,R,i]);const O=p=>{E(""),o({type:"browser",directory:p})},g=p=>{r(s,p),o({type:"file",path:p,returnDirectory:b||s})},k=de(p=>p.pendingFileFocusPath),y=de(p=>p.pendingFileNavigation);if(a.useEffect(()=>{const p=fe(y?.path??k??"");!p||!s||p!==s&&!p.startsWith(`${s}/`)||(r(s,p),o({type:"file",path:p,returnDirectory:s}),k&&de.getState().setPendingFileFocusPath(null))},[k,y,s,r]),!s)return t.jsx(tt,{message:"Select a project to browse files."});if(i.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:()=>o({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(nn,{className:"size-4"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:We(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(me,{children:t.jsx(a.Suspense,{fallback:t.jsx(tt,{loading:!0,message:"Loading..."}),children:t.jsx(wi,{mode:"editor-only"})})})})]});const $=i.directory===s?"Project files":We(i.directory),N=R.trim()?I:[],F=vi(i.directory,s)?hs(i.directory):null,j=!!F&&!R.trim(),S=F===s?"Project files":We(F??"");return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:e,style:{touchAction:"manipulation"},children:t.jsx(da,{className:"size-4"})}):null,j&&F?t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":`Back to ${We(F)}`,onClick:()=>O(F),style:{touchAction:"manipulation"},children:t.jsx(nn,{className:"size-4"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:$})}),t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Refresh files",onClick:()=>{D(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(fa,{className:H("size-4",u&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-3 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(ha,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Cr,{value:R,onChange:p=>E(p.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),t.jsx(At,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:m?t.jsx(tt,{message:m}):R.trim()?t.jsx(Ci,{results:N,isSearching:B,onOpenFile:g}):t.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[j&&F?t.jsxs("button",{type:"button",className:Wn,"aria-label":`Up one level to ${S}`,onClick:()=>O(F),style:{touchAction:"manipulation"},children:[t.jsx(G,{name:"arrow-left",className:H(Nt(!0),"text-muted-foreground")}),t.jsx("span",{className:H(Kn(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,l.length===0&&!u?t.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,l.map(p=>t.jsx(ps,{name:p.name,path:p.path,directory:p.isDirectory,meta:p.isDirectory?void 0:ji(p.size),onClick:()=>p.isDirectory?O(vn(p.path,i.directory||s)):g(vn(p.path,i.directory||s))},p.path))]})})]})},ps=({name:e,path:n,directory:r,meta:s,onClick:i})=>t.jsxs("button",{type:"button",className:Wn,onClick:i,style:{touchAction:"manipulation"},children:[r?t.jsx(ga,{className:H(Nt(!0),"text-primary/80")}):t.jsx(Fn,{filePath:n,className:Nt(!0)}),t.jsx("span",{className:H(Kn(!0),"flex-1 text-foreground"),children:e}),s?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:s}):null,r?t.jsx(ya,{className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),Ci=({results:e,isSearching:n,onOpenFile:r})=>{const s=fe(It()??null);return n?t.jsx(tt,{loading:!0,message:"Loading..."}):e.length===0?t.jsx(tt,{message:"No files found."}):t.jsx("div",{className:"flex w-full min-w-0 flex-col",children:e.map(i=>t.jsx(ps,{name:We(i.path),path:i.path,directory:!1,meta:ki(i.path,s),onClick:()=>r(i.path)},i.path))})},tt=({message:e,loading:n=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[n?t.jsx(pa,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ma,{className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),wn="mobile-surface-root",Ni=16,Ei=[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal"},{id:"notes",label:"Notes",icon:"sticky-note"}],kn=a.memo(function({open:n,onClose:r,tab:s,onTabChange:i,pendingChangesDiff:o,variant:l="drawer",drawerRefExternal:c,scrimRefExternal:u,rootRefExternal:d}){const m=a.useRef(null),w=a.useRef(null),R=a.useRef(null),E=a.useRef(null),I=c??w,A=u??R,B=d??E,U=a.useCallback(S=>{E.current=S,d&&(d.current=S)},[d]),h=a.useCallback(()=>{const S=typeof document<"u"?document.activeElement:null;S instanceof HTMLElement&&B.current?.contains(S)&&S.blur(),r()},[r]),[b,D]=a.useState(!1),[O,g]=a.useState(n),k=a.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[y,$]=a.useState(()=>new Set);if(a.useEffect(()=>{n&&$(S=>{if(S.has(s))return S;const p=new Set(S);return p.add(s),p})},[n,s]),typeof document<"u"&&!m.current){let S=document.getElementById(wn);S||(S=document.createElement("div"),S.id=wn,document.body.appendChild(S)),m.current=S}if(a.useEffect(()=>{if(n){g(!0);const p=window.setTimeout(()=>D(!0),k?0:Ni);return()=>window.clearTimeout(p)}D(!1);const S=window.setTimeout(()=>g(!1),Je+40);return()=>window.clearTimeout(S)},[n,k]),a.useEffect(()=>{if(!n)return;const S=document.body.style.overflow;l==="drawer"&&(document.body.style.overflow="hidden");const p=v=>{v.key==="Escape"&&s!=="terminal"&&h()};return document.addEventListener("keydown",p),()=>{l==="drawer"&&(document.body.style.overflow=S),document.removeEventListener("keydown",p)}},[h,n,s,l]),a.useEffect(()=>{const S=B.current;if(!S||n||l!=="drawer")return;const p=document.activeElement;p&&S.contains(p)&&p.blur()},[n,l]),us({side:"right",enabled:l==="drawer",open:n,drawerRef:I,scrimRef:A,onClose:h,widthRatio:1,prefersReducedMotion:k}),l==="drawer"&&!m.current)return null;const N=k?0:Je,F=t.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:Ei.map(S=>{const p=s===S.id;return t.jsxs("button",{type:"button",role:"tab","aria-selected":p,onClick:()=>i(S.id),className:H("flex min-w-0 flex-1 items-center justify-center gap-1 rounded-lg px-1.5 py-2 typography-ui-label transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",p?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(G,{name:S.icon,className:"size-4 shrink-0"}),t.jsx("span",{className:"truncate",children:S.label})]},S.id)})}),j=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-2",children:[F,t.jsx("button",{type:"button",onClick:h,"aria-label":"Close workspace panel",className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:t.jsx(G,{name:"close",className:"size-4"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y.has("changes")?t.jsx("div",{className:H("h-full",s!=="changes"&&"hidden"),children:t.jsx(me,{children:t.jsx(bi,{initialDiffPath:o?.path??null,initialDiffStaged:o?.staged===!0})})},o?`changes:${o.path}:${o.staged}`:"changes"):null,y.has("files")?t.jsx("div",{className:H("h-full",s!=="files"&&"hidden"),children:t.jsx(me,{children:t.jsx(Si,{})})}):null,y.has("terminal")?t.jsx("div",{className:H("h-full",s!=="terminal"&&"hidden"),children:t.jsx(me,{children:t.jsx($s,{visible:n&&s==="terminal"})})}):null,y.has("notes")?t.jsx("div",{className:H("h-full",s!=="notes"&&"hidden"),children:t.jsx(me,{children:t.jsx(Fs,{onActionComplete:h})})}):null]})]});return l==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:j}):Ge.createPortal(t.jsxs("div",{ref:U,className:"fixed inset-0 z-50",inert:!n,style:{pointerEvents:n?"auto":"none",visibility:O?"visible":"hidden"},"data-mobile-workspace-root":"true",children:[t.jsx("button",{ref:A,type:"button",className:"absolute inset-0 cursor-default bg-black/70","aria-label":"Close workspace panel",onClick:h,tabIndex:n?0:-1,style:{opacity:b?1:0,transition:N?`opacity ${N}ms ${Re}`:"none"},"data-mobile-workspace-scrim":"true"}),t.jsx("section",{ref:I,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:b?"none":"translateX(100%)",transition:N?`transform ${N}ms ${Re}`:"none",touchAction:"pan-x pan-y"},"data-mobile-workspace-drawer":"true",children:j})]}),m.current)});function Ri(e=2500){const{uiFont:n}=Nr(),[r,s]=a.useState(!1);return a.useEffect(()=>{let i=!1;const o=()=>{i||s(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(o))},c=Promise.all([Er(n).catch(()=>{}),document.fonts?.ready?.then(()=>{}).catch(()=>{})??Promise.resolve(),ba.catch(()=>{})]).then(()=>{}),u=new Promise(d=>{window.setTimeout(d,e)});return Promise.race([c,u]).then(l),()=>{i=!0}},[n,e]),r}const Ti="pichamber",Pi=e=>e.replace(/^\/+|\/+$/g,""),Ai=e=>{const n=Pi(e.pathname).split("/").filter(Boolean);return e.host?[e.host,...n]:n};function Ii(e){if(typeof e!="string"||e.length===0)return null;let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`${Ti}:`)return null;const r=Ai(n),s=(r[0]??"").toLowerCase(),i=r.slice(1),o=n.searchParams;switch(s){case"session":{const l=i[0]||o.get("id")||"";return l?{type:"session",sessionId:l,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 l=o.get("filter");return{type:"sessions",filter:l==="attention"||l==="recent"||l==="all"?l:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:i[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:i.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const l=(i[0]||"").toLowerCase();return l==="changes"?{type:"changes"}:l==="files"||l==="mcp"||l==="instances"||l==="update"?{type:"view",target:l}:null}default:return null}}let he={},ms=!1,Ye=null;const Di=e=>{switch(e.type){case"session":return ge.getState().setCurrentSession(e.sessionId,e.directory??null),!0;case"new-session":{const n=ge.getState();return n.openNewSessionDraft(),(e.directory||e.projectId)&&n.setNewSessionDraftTarget({directoryOverride:e.directory??null,projectId:e.projectId??null,selectedProjectId:e.projectId??null}),!0}case"sessions":return he.openSessions?(he.openSessions(e.filter),!0):!1;case"status":return he.openSessions?(he.openSessions(),!0):!1;case"view":return he.openView?(he.openView(e.target),!0):!1;case"changes":return he.openChanges?(he.openChanges({path:e.path,staged:e.staged}),!0):!1;case"settings":return he.openSettings?(he.openSettings(e.section),!0):!1}},Ut=()=>{if(!ms||!Ye)return;const e=Ye;Ye=null,Di(e)||(Ye=e)},gs=e=>{Ye=e,Ut()},jn=e=>{const n=Ii(e);n&&gs(n)},Mi=e=>{ms=e,Ut()},_i=e=>{a.useEffect(()=>(he=e,Ut(),()=>{he===e&&(he={})}),[e])},Li=e=>{const{ready:n}=e;a.useEffect(()=>{Mi(n)},[n]),a.useEffect(()=>{if(!le())return;let r=!1;const s=[];return He(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([128,11,129])).then(async({App:i})=>{if(r)return;const o=await i.addListener("appUrlOpen",l=>{jn(l?.url)});if(r){o.remove();return}s.push(()=>{o.remove()})}).catch(()=>{}),He(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([130,129])).then(async({PushNotifications:i})=>{if(r)return;const o=await i.addListener("pushNotificationActionPerformed",l=>{const c=l?.notification?.data,u=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(u){jn(u);return}const d=typeof c?.sessionId=="string"?c.sessionId:void 0;d&&gs({type:"session",sessionId:d})});if(r){o.remove();return}s.push(()=>{o.remove()})}).catch(()=>{}),()=>{r=!0,s.forEach(i=>i())}},[])},Sn=e=>{const n=e.drawer.current,r=e.scrim.current,s=e.root.current;s&&(s.style.pointerEvents="auto",s.style.visibility="visible"),n&&(n.style.transition="none"),r&&(r.style.transition="none")},Cn=(e,n,r)=>{const s=e.drawer.current,i=e.scrim.current;if(s&&(s.style.transform=r>=.999?"none":`translateX(${(n==="left"?r-1:1-r)*100}%)`),i){i.style.opacity=String(r);const o=r>.01?"auto":"none";i.style.pointerEvents!==o&&(i.style.pointerEvents=o)}},Nn=(e,n,r)=>{const s=r.drawer.current,i=r.scrim.current,o=r.root.current;s&&(s.style.transition=`transform ${Je}ms ${Re}`,s.style.transform=n?"none":e==="left"?"translateX(-100%)":"translateX(100%)"),i&&(i.style.transition=`opacity ${Je}ms ${Re}`,i.style.opacity=n?"1":"0",i.style.pointerEvents=n?"auto":"none"),o&&(o.style.pointerEvents=n?"auto":"none",o.style.visibility=n?"visible":"")},En=e=>{const n=e.shell.current,r=e.inner.current;n&&(n.style.overflow="visible"),r&&(r.style.transition="none")},Rn=(e,n,r,s)=>{const i=e.inner.current;if(!i)return;const o=s==="left"?(n-1)*r:(1-n)*r;i.style.transform=n>=.999?"translateX(0)":`translateX(${o}px)`},Tn=(e,n,r,s,i)=>{const o=e.shell.current,l=e.inner.current;return!o||!l?void 0:(l.style.transition="transform 200ms cubic-bezier(0.22, 1, 0.36, 1)",l.style.transform=n?"translateX(0)":`translateX(${s==="left"?-r:r}px)`,window.setTimeout(()=>{l.style.transition="",l.style.transform="",o.style.overflow=""},220))},zi=()=>{if(typeof window>"u")return;const e=window.__PICHAMBER_APNS_ENV__;if(e==="development")return"sandbox";if(e==="production")return"production"},Oi=()=>{if(typeof window>"u")return!1;const n=window.Capacitor?.getPlatform?.();return n==="ios"||n==="android"},$i=e=>{const{enabled:n}=e,r=de(i=>i.nativeNotificationsEnabled),s=a.useRef(null);a.useEffect(()=>{if(!n||!r||!Oi())return;let i=!1;const o=[];return He(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([130,129])).then(async({PushNotifications:l})=>{if(i)return;let c=await l.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await l.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const u=await l.addListener("registration",m=>{s.current=m.value,Ct()?.push?.registerApnsToken?.({token:m.value,platform:Dn(),environment:zi()})}),d=await l.addListener("registrationError",m=>{console.warn("[Push] APNs registration error:",m)});if(await l.register().catch(()=>{}),i){u.remove(),d.remove();return}o.push(()=>{u.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{i=!0,o.forEach(l=>l())}},[n,r]),a.useEffect(()=>{if(r)return;const i=s.current;if(!i)return;s.current=null,Ct()?.push?.unregisterApnsToken?.({token:i})},[r])},Pn=({side:e,isResizing:n,ariaLabel:r,handleProps:s})=>t.jsx("div",{className:H("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",e==="left"?"right-0":"left-0"),role:"separator","aria-orientation":"vertical","aria-label":r,...s,children:t.jsx("div",{className:H("absolute inset-y-0 w-[3px] transition-colors",e==="left"?"right-0":"left-0",n&&"bg-[var(--interactive-border)]")})}),Fi=320,Bi=380,An=280,Ui=560,Wi=900;function In(e,n,r,s=Ui){const i=a.useRef(null),[o,l]=a.useState(()=>{if(typeof window>"u")return r;const b=Number.parseInt(window.localStorage.getItem(n)??"",10);return Number.isFinite(b)?Math.min(s,Math.max(An,b)):r}),[c,u]=a.useState(!1),d=a.useRef(0),m=a.useRef(o),w=a.useRef(null),R=a.useRef(null),E=a.useCallback(b=>Math.min(s,Math.max(An,Math.round(b))),[s]),I=a.useCallback(b=>{const D=i.current;D&&(D.style.width=`${b}px`,D.style.minWidth=`${b}px`,D.style.maxWidth=`${b}px`,D.style.setProperty("--oc-ipad-sidebar-width",`${b}px`))},[]),A=a.useCallback(b=>{try{b.currentTarget.setPointerCapture(b.pointerId)}catch{}R.current=b.pointerId,d.current=b.clientX,m.current=o,w.current=o,u(!0),b.preventDefault()},[o]),B=a.useCallback(b=>{if(R.current!==b.pointerId)return;const D=b.clientX-d.current,O=E(m.current+(e==="left"?D:-D));w.current!==O&&(w.current=O,I(O))},[I,E,e]),U=a.useCallback(b=>{if(R.current!==b.pointerId)return;try{b.currentTarget.releasePointerCapture(b.pointerId)}catch{}const D=E(w.current??m.current);R.current=null,w.current=null,u(!1),l(D);try{window.localStorage.setItem(n,String(D))}catch{}},[E,n]),h=a.useMemo(()=>({onPointerDown:A,onPointerMove:B,onPointerUp:U,onPointerCancel:U}),[A,U,B]);return{asideRef:i,width:o,isResizing:c,handleProps:h}}const Ki=1e3,Gi=a.memo(Ys),Hi=({onActiveConnectionDeleted:e})=>{const[n,r]=a.useState(!1),[s,i]=a.useState(null),[o,l]=a.useState(!1),[c,u]=a.useState("changes"),[d,m]=a.useState("nav"),[w,R]=a.useState(null),E=a.useRef([]),I=a.useCallback(()=>{E.current.forEach(P=>window.clearTimeout(P)),E.current=[]},[]);a.useEffect(()=>()=>I(),[I]);const A=a.useRef(null),B=a.useRef(null),U=a.useRef(null),h=a.useRef(null),b=a.useRef(null),D=a.useRef(null),O=a.useRef(null),g=a.useRef(null),k=a.useRef(0),y=a.useRef(0),$=a.useCallback(P=>{I(),r(P)},[I]),N=a.useCallback(P=>{I(),l(P)},[I]),F=de(P=>P.setSettingsPage),j=de(P=>P.isArchivePageOpen),S=de(P=>P.setArchivePageOpen),p=de(P=>P.wideChatLayoutEnabled),v=Be(P=>P.available),z=Be(P=>P.runtimeType),q=a.useMemo(()=>Un(),[]),Z=!q&&v&&(z==="desktop"||z==="web"),X=a.useCallback(()=>{i(null)},[]),T=a.useCallback(P=>{i(P)},[]),V=a.useCallback(()=>{N(!1)},[N]),J=a.useCallback(P=>{m(P),T("settings")},[T]),{enabled:f,roomyForPanels:x}=$n(),W=Kr()==="portrait",ee=Gr(),Q=de(P=>P.setSidebarOpen),ae=de(P=>P.isSidebarOpen),Te=a.useRef(!1);a.useLayoutEffect(()=>{f&&!Te.current&&Q(Hr().roomyForPanels),!f&&Te.current&&Q(!1),Te.current=f},[f,Q]);const ue=a.useCallback(()=>{R(null),u("files"),N(!0)},[N]),ye=a.useCallback((P=null)=>{R(P),u("changes"),N(!0)},[N]),se=In("left","pichamber.ipad.leftSidebarWidth",Fi),_=In("right","pichamber.ipad.rightSidebarWidth",Bi,Wi),Y=x,te=Y&&o?_.width:0,we=Vs(f&&ae),ve=f&&ae?se.width:0,Pe=a.useCallback(P=>{o&&c===P?N(!1):(u(P),N(!0))},[o,c,N]),it=a.useCallback(()=>{N(!o)},[o,N]),bt=a.useCallback(P=>{!P&&!x&&Q(!1)},[x,Q]);a.useEffect(()=>{if(typeof document>"u")return;const P=document.documentElement;return P.style.setProperty("--oc-chat-inset-left",`${ve}px`),P.style.setProperty("--oc-chat-inset-right",`${te}px`),()=>{P.style.removeProperty("--oc-chat-inset-left"),P.style.removeProperty("--oc-chat-inset-right")}},[ve,te]),a.useEffect(()=>{if(typeof document>"u")return;const P=document.documentElement;return P.classList.toggle("wide-chat-layout",p),()=>P.classList.remove("wide-chat-layout")},[p]),a.useEffect(()=>{if(typeof document>"u")return;const P=f&&(W||ee),pe=document.documentElement;return pe.classList.toggle("oc-keep-draft-starters",P),()=>pe.classList.remove("oc-keep-draft-starters")},[ee,f,W]);const $e=a.useCallback(()=>{$(!1),N(!1)},[$,N]),C=a.useMemo(()=>({openChanges:({diffPath:P,staged:pe}={})=>{ye(P?{path:P,staged:pe===!0}:null)},openFiles:()=>ue(),openSettings:P=>{P&&F(P),J(P?"page-content":"nav")},openInstances:q?()=>T("instances"):void 0,instanceLabel:q?Ue():null,openUpdate:Z?()=>T("update"):void 0,closeDrawers:$e}),[$e,ye,ue,J,T,F,q,Z]),L=a.useMemo(()=>({openSessions:()=>{f?Q(!0):$(!0)},openView:P=>{if(P==="files"){ue();return}(P==="instances"||P==="update"||P==="mcp")&&T(P)},openChanges:({path:P,staged:pe}={})=>{ye(P?{path:P,staged:pe===!0}:null)},openSettings:P=>{P&&F(P),J(P?"page-content":"nav")}}),[f,ye,ue,J,T,F,$,Q]);_i(L);const K=a.useRef(null);Xs(K,{leftOpen:f?ae:n,rightOpen:o,leftWidth:()=>f?se.width:A.current?.offsetWidth||window.innerWidth*.72,rightWidth:()=>f?_.width:h.current?.offsetWidth||window.innerWidth,onLeftProgress:P=>{if(k.current=P,f){Rn({inner:O},P,se.width,"left");return}Cn({drawer:A,scrim:B},"left",P)},onRightProgress:P=>{if(y.current=P,f&&x){Rn({inner:g},P,_.width,"right");return}Cn({drawer:h,scrim:b},"right",P)},onLeftOpen:()=>{f?Q(!0):$(!0)},onLeftClose:()=>{f?Q(!1):$(!1)},onRightOpen:()=>N(!0),onRightClose:()=>N(!1),onDragStart:P=>{if(I(),P==="left"){k.current=f?ae?1:0:n?1:0,f?En({shell:se.asideRef,inner:O}):Sn({drawer:A,scrim:B,root:U});return}y.current=o?1:0,f&&x?En({shell:_.asideRef,inner:g}):Sn({drawer:h,scrim:b,root:D})},onDragEnd:(P,pe)=>{if(P==="left"){const ke=typeof pe=="boolean"?pe:k.current>.5;if(k.current=ke?1:0,f){const Wt=Tn({shell:se.asideRef,inner:O},ke,se.width,"left");Wt!==void 0&&E.current.push(Wt)}else Nn("left",ke,{drawer:A,scrim:B,root:U});return}const ot=typeof pe=="boolean"?pe:y.current>.5;if(y.current=ot?1:0,f&&x){const ke=Tn({shell:_.asideRef,inner:g},ot,_.width,"right");ke!==void 0&&E.current.push(ke)}else Nn("right",ot,{drawer:h,scrim:b,root:D})}});const ne=a.useCallback(()=>j?(S(!1),!0):s?(X(),!0):o?(V(),!0):n?($(!1),!0):!1,[s,X,V,j,n,S,$,o]);Vr(ne);const be=f?"dialog":"fullscreen";return t.jsx(Xr,{actions:C,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area relative flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[f?t.jsxs("aside",{ref:se.asideRef,className:H("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-sidebar motion-reduce:transition-none",!ae&&"border-r-0"),style:{width:ve,minWidth:ve,maxWidth:ve,"--oc-ipad-sidebar-width":`${se.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!ae,"data-page-scroll-lock":"true",children:[t.jsx("div",{ref:O,className:H("flex h-full shrink-0 flex-col",se.isResizing&&"pointer-events-none",!ae&&"pointer-events-none select-none"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:se.isResizing||we.slidIn?"translateX(0)":"translateX(-100%)",transition:se.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:t.jsx(me,{children:t.jsx(hn,{open:ae,variant:"sidebar",onOpenChange:bt})})}),ae?t.jsx(Pn,{side:"left",isResizing:se.isResizing,ariaLabel:"Resize left panel",handleProps:se.handleProps}):null]}):null,t.jsxs("div",{className:"relative flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[f?t.jsxs(t.Fragment,{children:[t.jsx(qs,{}),t.jsx(Js,{onToggleRightDrawer:it,rightDrawerOpen:o,tabletWorkspaceTab:c,onSelectTabletWorkspaceTab:Pe})]}):t.jsx(ni,{onOpenSessions:()=>$(!0),onOpenWorkspace:()=>N(!0)}),t.jsx("main",{ref:K,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:t.jsx("div",{className:"h-full w-full",children:t.jsx(me,{children:t.jsx(Gi,{})})})})]}),f?null:t.jsx(hn,{open:n,onOpenChange:$,drawerRefExternal:A,scrimRefExternal:B,rootRefExternal:U}),f?t.jsxs("aside",{ref:_.asideRef,className:H("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background motion-reduce:transition-none",!te&&"border-l-0"),style:{width:te,minWidth:te,maxWidth:te,"--oc-ipad-sidebar-width":`${_.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)"},inert:!te,"data-page-scroll-lock":"true",children:[t.jsx("div",{ref:g,className:H("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",_.isResizing&&"pointer-events-none",!te&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden",transform:te?"translateX(0)":"translateX(100%)",transition:_.isResizing?"none":"transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:t.jsx(me,{children:t.jsx(kn,{open:o,onClose:V,tab:c,onTabChange:u,pendingChangesDiff:w,variant:Y?"panel":"drawer",drawerRefExternal:h,scrimRefExternal:b,rootRefExternal:D})})}),te?t.jsx(Pn,{side:"right",isResizing:_.isResizing,ariaLabel:"Resize right panel",handleProps:_.handleProps}):null]}):t.jsx(kn,{open:o,onClose:V,tab:c,onTabChange:u,pendingChangesDiff:w,drawerRefExternal:h,scrimRefExternal:b,rootRefExternal:D}),s==="instances"&&q?t.jsx(kt,{open:!0,variant:be,dialogAlign:"app",onClose:X,ariaLabel:"Instances",title:"Instances",children:t.jsx(si,{onConnect:X,onActiveConnectionDeleted:e})}):null,s==="settings"?t.jsx(kt,{open:!0,variant:be,dialogAlign:"app",onClose:X,ariaLabel:"Settings",headerless:!0,children:t.jsx(me,{children:t.jsx(ea,{forceMobile:!f,isWindowed:!0,initialMobileStage:d,onClose:X})})}):null,s==="update"?t.jsx(kt,{open:!0,variant:be,dialogAlign:"app",onClose:X,ariaLabel:"Update",title:"Update",children:t.jsx(me,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(ta,{initialUpdateDialogOpen:!0})})})}):null,t.jsx(me,{children:t.jsx(Qs,{})})]})})};function Vi({apis:e}){const n=Se(T=>T.initializeApp),r=Se(T=>T.isInitialized),s=Se(T=>T.isConnected),i=Se(T=>T.connectionPhase),o=Se(T=>T.providers.length),l=Se(T=>T.agents.length),c=Se(T=>T.loadProviders),u=Se(T=>T.loadAgents),d=Ln(T=>T.currentDirectory),m=ge(T=>T.error),w=ge(T=>T.clearError),R=de(T=>T.setIsMobile),E=Rr(T=>T.refreshStatus),[I,A]=a.useState(0),[B,U]=a.useState(0),[h,b]=a.useState(!1),[D,O]=a.useState("pending"),[g,k]=a.useState(null),y=a.useMemo(()=>Ue(),[]),[,$]=a.useReducer(T=>T+1,0),N=a.useMemo(()=>Un(),[]),F=a.useRef(0),j=a.useRef(0),S=a.useCallback(()=>{const T=Ce(),V=j.current+1;if(j.current=V,!T){ut();return}const J=()=>{n(),E(e.github,{force:!0}),o===0&&c({source:"mobileApp:nativeResume"}),l===0&&u({source:"mobileApp:nativeResume"})},f=()=>{Fe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),A(M=>M+1)};et().then(M=>{if(j.current===V){if(M==="no-connection"){f();return}if(M==="needs-login"){k({kind:"auth-expired",label:Ue()??""}),f();return}if(M==="unreachable"){window.setTimeout(()=>{j.current===V&&et().then(W=>{if(j.current===V&&W!=="switched"){if(W==="unchanged"){J();return}W==="needs-login"&&k({kind:"auth-expired",label:Ue()??""}),f()}})},4e3);return}M!=="switched"&&J()}});const x=Date.now();x-F.current>=Ki&&(F.current=x,window.dispatchEvent(new Event("pichamber:system-resume")))},[l,e.github,n,u,c,o,E]);Tr(),Pr(S),a.useEffect(()=>Ss(),[]),a.useEffect(()=>{if(!N)return;let T;const V=()=>{window.clearTimeout(T),T=window.setTimeout(()=>S(),1500)};return window.addEventListener("online",V),()=>{window.removeEventListener("online",V),window.clearTimeout(T)}},[N,S]),a.useEffect(()=>(Gt(e),()=>Gt(null)),[e]),a.useEffect(()=>Cs(T=>{if(!!T.runtimeKey&&T.runtimeKey===T.previousRuntimeKey){Bs(),$();return}Us(T),U(J=>J+1),A(J=>J+1)}),[]),a.useEffect(()=>{zn()},[B]),a.useEffect(()=>{if(!N||s||Ce()){O("done");return}let T=!1;return O("attempting"),ut().catch(()=>({status:"no-candidate"})).then(V=>{T||(V.status==="unreachable"?k({kind:"unreachable",label:V.label}):V.status==="needs-login"&&k({kind:"auth-expired",label:V.label}),O("done"))}),()=>{T=!0}},[]),a.useEffect(()=>{if(!N||!Ce())return;let T=!1;const V=J=>{J&&k(J),Fe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),A(f=>f+1)};return et().then(async J=>{if(T||J==="switched"||J==="unchanged")return;const f=Ue();if(J==="needs-login"){V({kind:"auth-expired",label:f??""});return}if(J==="unreachable"){V(f?{kind:"unreachable",label:f}:null);return}const x=await ut().catch(()=>({status:"no-candidate"}));T||x.status==="connected"||(x.status==="needs-login"?V({kind:"auth-expired",label:x.label}):x.status==="unreachable"?V({kind:"unreachable",label:x.label}):V(null))}),()=>{T=!0}},[]),a.useEffect(()=>{R(!0)},[R]),a.useEffect(()=>{N&&!Ce()||n()},[I,n,N]),a.useEffect(()=>{s&&(o===0&&c({source:"mobileApp:recovery"}),l===0&&u({source:"mobileApp:recovery"}))},[l,s,u,c,o]);const p=a.useRef(!1),[v,z]=a.useState(N);a.useEffect(()=>{if(!N||!s||p.current)return;if(ge.getState().currentSessionId){p.current=!0,z(!1);return}const T=at(),V=Ar(T);if(!V){p.current=!0,z(!1);return}let J=!1;const f=window.setTimeout(()=>z(!1),6e3);return(async()=>{const x=await Ir().catch(()=>null);if(J)return;if(!x){z(!1);return}p.current=!0;const M=x.activeSessions.find(ee=>ee.id===V.sessionId);if(!M){Dr(T),z(!1);return}const W=ge.getState();W.currentSessionId||W.setCurrentSession(M.id,Pt(M)??V.directory??void 0),z(!1)})(),()=>{J=!0,window.clearTimeout(f)}},[I,s,N]),a.useEffect(()=>{s&&Mr().focusProject(d,null)},[d,s]),a.useEffect(()=>{s&&E(e.github,{force:!0})},[e.github,s,E]),a.useEffect(()=>{if(!m)return;const T=window.setTimeout(()=>w(),5e3);return()=>window.clearTimeout(T)},[w,m]),a.useEffect(()=>{if(!(!s&&(N?!!Ce():!0))){b(!1);return}const V=window.setTimeout(()=>{b(!0)},N?4e3:8e3);return()=>window.clearTimeout(V)},[s,N,I,B]),_r(),Es({enabled:!0}),Ws(),$i({enabled:N&&s}),Li({ready:N&&s&&r});const q=Ri(),Z=!s&&i==="reconnecting";if(!q)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Ae,{width:120,height:120,isAnimated:!0})});const X=!!Ce();return N&&(!X||!s&&!Z)?X?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Ae,{width:120,height:120,isAnimated:!h}),h?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),t.jsx("p",{className:"typography-body text-muted-foreground",children:"Could not connect to the saved server. Check that it is running, or pick another instance."})]}),t.jsx(re,{type:"button",variant:"outline",onClick:()=>{Fe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),A(T=>T+1)},children:"Use another server"})]}):null]})}):D!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(Ae,{width:120,height:120,isAnimated:!0}),y?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:"Connecting to device:"}),t.jsxs("p",{className:"typography-small text-foreground",children:[y,t.jsx(Lr,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Qa,{onConnected:()=>A(T=>T+1),notice:g})}):!s&&!Z?h?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:"Unable to reach server"}),t.jsx("p",{className:"typography-body text-muted-foreground",children:"We could not verify the UI session. If you're opening PiChamber from another device on your local network, make sure Desktop Network Access is enabled on the desktop app and use the LAN address shown in Settings."})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Ae,{width:120,height:120,isAnimated:!0})}):t.jsx(me,{children:t.jsx(zr,{children:t.jsxs(Or,{apis:e,children:[t.jsx($r,{}),t.jsx(Fr,{delayDuration:300,skipDelayDuration:150,children:t.jsxs(Ks,{children:[t.jsx(Gs,{}),t.jsxs("div",{className:"h-full bg-background text-foreground",children:[N&&v?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(Ae,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Br,{embeddedBackgroundWorkEnabled:r}),t.jsx(Ea,{}),t.jsx(Hi,{onActiveConnectionDeleted:()=>{Fe({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),A(T=>T+1)}}),t.jsx(Hs,{}),t.jsx(Ur,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),t.jsx(Wr,{})]})]})})]})},B)})}const Xi=()=>{Ns().then(()=>{Promise.all([zn(),Rs()]).catch(e=>{console.error("[mobile-main] settings init failed:",e)}),Ts(),Ps(),As()}).catch(e=>{console.error("[mobile-main] appearance init failed:",e)}).finally(()=>{xa()})};function qi(e){window.__PICHAMBER_SURFACE__="mobile",qr(),Xi(),Na(),Jr();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");const s=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",i=e??Ct();if(!i)throw new Error("Runtime APIs not registered");const o=s?{...i,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:i,l=t.jsx(Vi,{apis:o});ys.createRoot(n).render(t.jsx(De.StrictMode,{children:t.jsx(Qr,{children:t.jsx(Yr,{children:t.jsx(Zs,{children:s?l:t.jsx(Zr,{children:l})})})})}))}const po=Object.freeze(Object.defineProperty({__proto__:null,renderMobileApp:qi},Symbol.toStringTag,{value:"Module"}));export{ho as m,po as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i,
|
|
1
|
+
import{i,O as s}from"./index--5Zr-fSk.js";const n="pichamber-mobile-layout",a=e=>e==="default"?"default":"new",c=()=>{if(typeof window>"u")return"new";try{return a(window.localStorage.getItem(n))}catch{return"new"}},l=e=>{if(typeof window>"u")return!1;try{return window.localStorage.setItem(n,e),!0}catch{return!1}},d=768,u=()=>{if(typeof window>"u")return!1;const e=typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(hover: none)").matches:!1,t=typeof navigator<"u"?navigator.maxTouchPoints??0:0;return e||t>0},r=()=>{if(typeof window>"u")return"desktop";const e=window.__PICHAMBER_SURFACE__;if(e==="mobile"||e==="desktop")return e;const t=new URLSearchParams(window.location.search).get("surface");if(t==="mobile"||t==="desktop")return t;if(i())return"mobile";if(s())return"desktop";const o=Math.min(window.innerWidth||Number.POSITIVE_INFINITY,window.screen?.width||Number.POSITIVE_INFINITY);return Number.isFinite(o)&&o<=d&&u()&&c()==="new"?"mobile":"desktop"},m=()=>{const e=r();return typeof window<"u"&&(window.__PICHAMBER_SURFACE__=e),e},h=()=>r()==="mobile";export{c as g,h as i,m as r,l as s};
|