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