@pi-chamber/web 0.9.8-rc.1 → 0.9.8
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-BMBrrFLy.js → DiagramView-vaGEmGJn.js} +1 -1
- package/dist/assets/{DiffView-yVBxHkBI.js → DiffView-BUOaq70P.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-D0siEm8l.js → FileSaveConflictDialog-B3wIsdE1.js} +1 -1
- package/dist/assets/{FilesView-CkcKBKkT.js → FilesView-DPwCE-XA.js} +1 -1
- package/dist/assets/{GitView-CfuhQOfc.js → GitView-CGk98LhV.js} +3 -3
- package/dist/assets/{JsonTreeView-6kRdE1BO.js → JsonTreeView-HNtRoqVA.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CRWbN_Jc.js → MarkdownRendererImpl-DUYL-Wn3.js} +1 -1
- package/dist/assets/{PatchDiff-B0ssv8Aw.js → PatchDiff-Bluz53zj.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-NmfI4B0Z.js → SessionSwitcherContent-DDncCwpE.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DmE2hYTN.js → SessionSwitcherDropdown-Cw_g3ai3.js} +2 -2
- package/dist/assets/{SessionUnreadDot-LDTswryg.js → SessionUnreadDot-CT5M3-qK.js} +1 -1
- package/dist/assets/{SettingsView-D0iw6y_H.js → SettingsView-C26Mwkzp.js} +2 -2
- package/dist/assets/{SettingsWindow-BT2TzUBK.js → SettingsWindow-B_oA1yV4.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Bnl51bva.js → ToolOutputDialog-C3xiVDyE.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-DgPtLS_h.js → ToolPartDiffPreview-xrxYTK3l.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-D3zBpYIS.js → VirtualizedFileDiff-Bpgyk3yt.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-y2AJzpKw.js → computeVirtualFileMetrics-DPPmLfoR.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DYUFkrPT.js → contextFileOpenGuard-CV7L_UMk.js} +1 -1
- package/dist/assets/{gitStatusPredicates-CbFfOlbV.js → gitStatusPredicates-BTkHRMCD.js} +1 -1
- package/dist/assets/{index-DwJJarzh.js → index-C3PSe3Mq.js} +1 -1
- package/dist/assets/{isDiffPlainText-kXPOivsq.js → isDiffPlainText-Djb-erNZ.js} +1 -1
- package/dist/assets/{isFilePlainText-BBIPqnLo.js → isFilePlainText-BQ-Wnk8C.js} +1 -1
- package/dist/assets/{main-BshSYpnV.js → main-7I7_paNp.js} +3 -3
- package/dist/assets/{main-RrPyfmCA.js → main-Dpqrd5dA.js} +2 -2
- package/dist/assets/{markdownCore-BxXmpZtB.js → markdownCore-DOQQqV2i.js} +1 -1
- package/dist/assets/{miniChat-DRNgmC-q.js → miniChat-b1O4Yu1o.js} +2 -2
- package/dist/assets/{mobile-CdmgVKW4.js → mobile-BTpbHrim.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-B80Jqq8b.js → renderElectronMiniChatApp-Cisrg0Iv.js} +2 -2
- package/dist/assets/{renderMobileApp-CLcBvRiy.js → renderMobileApp-CSBtWiZ2.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-DHHCemOu.js → runtimeEndpointReset-sDOkJ0dT.js} +3 -3
- package/dist/assets/{useAppFontEffects-Dp6vM-Zr.js → useAppFontEffects-BH5qeSfx.js} +7 -7
- package/dist/assets/{useFilesViewSearch-Bc8PTYrg.js → useFilesViewSearch-Bdxwr4SZ.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-DMcKyNtE.js → usePushVisibilityBeacon-Czfhm8lw.js} +1 -1
- package/dist/assets/{useSwitcherItems-DEvsORZ_.js → useSwitcherItems-CiTeIjW3.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DLimsiRH.js → vendor-codemirror-language-data-BhPKX-r-.js} +2 -2
- package/dist/assets/{web-components-05Oa3k7a.js → web-components-CuVJfuw8.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/mini-chat.html +1 -1
- package/dist/mobile.html +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
import{_ as is}from"./vendor-vite-runtime-DD1OZmLC.js";import{r as Re,j as t,R as i,b as Zl}from"./vendor-react-B5Z1Mdn3.js";import{aP as Ps,aQ as ec,Q as tc,a1 as Mt,a2 as ze,a3 as $e,a4 as Ft,B as Me,I as D,a5 as Ge,a6 as Ot,a8 as tt,t as ie,a as dt,e as Ie,Z as Us,ad as ln,aR as yi,af as Kt,ag as Wt,ah as ls,ai as es,aj as cs,ak as Ss,aF as xs,aS as ys,g as Es,aT as sr,aU as ko,aV as Co,aW as tn,o as wi,ae as ps,aX as Ao,a7 as ws,aY as Sr,aZ as sc,a_ as nc,a$ as rc,b0 as oc,b1 as ic,b2 as jr,b3 as ac,x as $t,b4 as lc,b5 as cc,b6 as dc,b7 as vi,b8 as uc,b9 as fc,ba as Si,bb as ji,bc as ki,aC as kr,r as sn,m as Wr,ao as hc,ay as pc,aB as Ci,K as js,d as Hr,aa as zs,ax as Ai,bd as Wn,be as No,bf as ct,aD as Ni,bg as Ii,at as mc,f as Ri,i as gc,bh as bc,h as xc,bi as Is,b as Io,c as yc,bj as wc,u as vc,aE as Sc,aH as jc,bk as Cr,bl as kc,bm as Cc,aG as Ac,bn as Nc,bo as Ic,T as Rc,a9 as vs,al as Di,v as Dc,ab as Ec,bp as Pc,bq as Tc,j as Mc,br as Fc,bs as Ei,bt as Oc,bu as Lc,bv as Bc,bw as _c,bx as Uc,by as zc,bz as $c,bA as Gc,bB as Kc,bC as Wc}from"./useAppFontEffects-Dp6vM-Zr.js";import{Z as Ro,_ as Hc,$ as Do,a0 as Yc,i as Qc,a1 as qc,S as Vc,m as At,a2 as cn,b as Jc,a3 as Xc,R as Fs,a4 as Pi,a5 as Ti,a6 as Zc,a7 as ed,q as Os,K as td,a8 as sd,a9 as nd,aa as rd,ab as Vt,v as Jt,ac as od,ad as id,ae as ad,af as Yr,ag as ld,ah as cd,ai as dd,u as ce,o as _,aj as ud,B as Ce,ak as Ls,al as Tt,am as Eo,an as Ar,a as Qr,T as qr,U as Ln,ao as fd,ap as hd,aq as Mi,F as pd,Q as Fi,C as nn,ar as Nr,h as Ir,d as jn,as as md,at as gd,au as Po,av as Vs,aw as nr,ax as Rr,ay as ms,az as To,aA as Dr,aB as Oi,aC as Er,aD as bd,aE as xd,aF as yd,aG as wd,aH as vd,aI as Sd,aJ as jd,z as kd,aK as Cd,aL as Ad,Y as Li,P as Nd,J as Id}from"./index-CrqlVJXp.js";import{c as ks,d as Bi,p as Vr,u as Pr,a as Rd}from"./vendor-zustand-GVb4H8HE.js";import{g as as,b as Dd,c as _i,r as Ed,d as Ui,s as En,e as zi,h as dn,i as un,j as Pd,k as Td,l as Md,m as Mo,n as Hn,f as Fd,a as Od,S as Ld,t as Bd,o as _d}from"./SessionUnreadDot-LDTswryg.js";import{C as $i,a as Gi,M as Ki,b as Wi,c as Hi,d as Yi,S as Qi,D as Ud,e as zd,f as $d,g as Gd,h as Kd,i as Wd,j as Hd}from"./vendor-base-ui-C60wdVnS.js";import{c as qi,d as Tr,P as Yd,D as Vi,e as Ji,f as Qd,b as qd,a as Vd,T as Jd,M as Xd}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{u as Zd}from"./vendor-tanstack-react-virtual-2skouoFw.js";import{S as eu,v as tu,u as su}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as nu}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-xterm-xterm-CrXqRur4.js";import{usePermissionStore as ru}from"./permissionStore-iKN1K2_x.js";const ou="chat";function Xi(e){const s=new URLSearchParams;if(e.sessionId&&e.sessionId.trim().length>0&&s.set(Ps.SESSION,e.sessionId),e.isSettingsOpen){const n=e.settingsPath.trim().length>0?e.settingsPath:"home";return s.set(Ps.SETTINGS,n),s}return e.tab!==ou&&s.set(Ps.TAB,e.tab),e.tab==="diff"&&e.diffFile&&e.diffFile.trim().length>0&&s.set(Ps.FILE,e.diffFile),s}function iu(e,s){const n=typeof window<"u"?window.location.pathname:"/",r=n.startsWith("/session")||n.startsWith("/s/")?"/":n,o=e.toString();return o?`${r}?${o}`:r}function au(e){if(typeof window>"u")return!0;try{const s=new URLSearchParams(window.location.search),n=Xi(e),r=window.location.pathname.match(/^\/(?:session|s)\/([^/?#]+)/i),o=r?.[1]?decodeURIComponent(r[1].trim()):null;o&&!s.has(Ps.SESSION)&&s.set(Ps.SESSION,o);const a=[...s.entries()].sort((c,u)=>c[0].localeCompare(u[0])),l=[...n.entries()].sort((c,u)=>c[0].localeCompare(u[0]));if(a.length!==l.length)return!1;for(let c=0;c<a.length;c++)if(a[c][0]!==l[c][0]||a[c][1]!==l[c][1])return!1;return!0}catch{return!0}}function Mr(e,s={}){if(!(typeof window>"u")&&!(!s.force&&au(e)))try{const n=Xi(e),r=iu(n);s.replace?window.history.replaceState({...window.history.state,route:e},"",r):window.history.pushState({route:e},"",r)}catch{}}const lu=["typescript","javascript","tsx","jsx","json","markdown"],Zi={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Fo=null;const ea=()=>(Fo??=Promise.all([is(()=>import("./index-DwJJarzh.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])),is(()=>import("./workerFactory-tw7cIdmV.js"),[]),is(()=>import("./appThemeRegistry-gegrE2dq.js"),__vite__mapDeps([110,111,97,98,24,82,83,84,85,86,87,88,89,90,91,92,93,94,95]))]).then(([e,s,n])=>({WorkerPoolManager:e.WorkerPoolManager,workerFactory:s.workerFactory,ensurePierreThemeRegistered:n.ensurePierreThemeRegistered})),Fo),fn={},Oo=new Set,Fr=new Set;let Pn={light:"pierre-light",dark:"pierre-dark"};const cu=()=>{for(const e of Fr)e()},ta=(e,s)=>{s.setRenderOptions({theme:Pn,lineDiffType:Zi[e].lineDiffType})},Or=e=>{typeof window>"u"||Oo.has(e)||(Oo.add(e),ea().then(s=>{if(fn[e])return;const n=Zi[e],r=new s.WorkerPoolManager({workerFactory:s.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:lu,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),fn[e]=r,ta(e,r),cu()}))},du=e=>(Fr.add(e),()=>Fr.delete(e)),uu=e=>{if(!(Pn.light===e.light&&Pn.dark===e.dark)){Pn=e;for(const s of Object.keys(fn)){const n=fn[s];n&&ta(s,n)}}},hg=({children:e})=>{const s=ec(),n=Ro(!1),r=Ro(!0),o=s?.lightThemeId??n.metadata.id,a=s?.darkThemeId??r.metadata.id,l=s?.availableThemes.find(u=>u.metadata.id===o)??n,c=s?.availableThemes.find(u=>u.metadata.id===a)??r;return Re.useEffect(()=>{let u=!1;return ea().then(d=>{u||(d.ensurePierreThemeRegistered(l),d.ensurePierreThemeRegistered(c),uu({light:l.metadata.id,dark:c.metadata.id}))}),()=>{u=!0}},[c,l]),Re.useEffect(()=>{if(typeof window>"u")return;const u=()=>{Or("unified"),Or("split")};if(typeof window.requestIdleCallback=="function"){const f=window.requestIdleCallback(u,{timeout:5e3});return()=>window.cancelIdleCallback(f)}const d=window.setTimeout(u,2e3);return()=>window.clearTimeout(d)},[]),t.jsx(t.Fragment,{children:e})},pg=(e="unified")=>{const s=Re.useSyncExternalStore(du,()=>fn[e],()=>{});return Re.useEffect(()=>{Or(e)},[e]),s};function fu(){if(typeof window>"u")return"unknown";try{const{deviceType:e}=tc();return e}catch{return"unknown"}}function hu(){const e=typeof window<"u"?window.__PICHAMBER_ELECTRON__?.arch?.toLowerCase?.():void 0;if(e==="arm64"||e==="aarch64")return"arm64";if(e==="x64"||e==="amd64"||e==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const r=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return r.includes("aarch64")||r.includes("arm64")||r.includes("armv")?"arm64":r.includes("x86_64")||r.includes("x64")||r.includes("amd64")||r.includes("win64")?"x64":"unknown"}function pu(){const e=Jc();if(e==="android"||e==="ios")return e;if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function mu(e){const s=new URLSearchParams;return s.set("deviceClass",fu()),s.set("arch",hu()),s.set("platform",pu()),e==="desktop"?(s.set("appType","desktop-electron"),s.set("instanceMode",cn()?"local":"remote"),s):e==="mobile"?(s.set("appType","mobile-capacitor"),s.set("instanceMode","remote"),s):(s.set("appType","web"),s.set("instanceMode","unknown"),s)}async function rr(e,s){try{const n=mu(e);s&&n.set("currentVersion",s);const r=await At(`/api/pi/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"},priority:"low"});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const o=await r.json();return{available:o.available??!1,version:o.version,currentVersion:o.currentVersion??"unknown",body:o.body,releaseUrl:o.releaseUrl,downloadUrl:o.downloadUrl,nextSuggestedCheckInSec:typeof o.nextSuggestedCheckInSec=="number"&&Number.isFinite(o.nextSuggestedCheckInSec)?o.nextSuggestedCheckInSec:void 0,packageManager:o.packageManager,updateCommand:o.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function gu(){return Qc()?"mobile":qc()?"desktop":Vc()?"web":null}const Lo={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Tn=ks()((e,s)=>({...Lo,checkForUpdates:async()=>{const n=gu();if(!n)return null;e({checking:!0,error:null,runtimeType:n});try{let r=null,o=null;if(n==="desktop"){const a="0.9.8-rc.1",[l,c]=await Promise.allSettled([Do(),rr("desktop",a)]),u=l.status==="fulfilled"?l.value:null;return o=c.status==="fulfilled"?c.value?.nextSuggestedCheckInSec??null:null,e({checking:!1,available:u?.available??!1,info:u,lastChecked:Date.now(),nextCheckInSec:o}),o}else n==="web"?(r=await rr("web"),o=r?.nextSuggestedCheckInSec??null):n==="mobile"&&(r=await rr("mobile","0.9.8-rc.1"),o=r?.nextSuggestedCheckInSec??null);return e({checking:!1,available:r?.available??!1,info:r,lastChecked:Date.now(),nextCheckInSec:o}),o}catch(r){return e({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=s();if(!(r!=="desktop"||!n)){e({downloading:!0,error:null,progress:null});try{const o=await Do();if(!o?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(e(l=>({info:l.info?{...l.info,...o,body:l.info.body||o.body,available:l.info.available}:o})),!await Yc(l=>{e({progress:l})}))throw new Error("Desktop update only works on Local instance");e({downloading:!1,downloaded:!0})}catch(o){e({downloading:!1,error:o instanceof Error?o.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=s();if(!(r!=="desktop"||!n))try{if(!await Hc())throw new Error("Desktop restart only works on Local instance")}catch(o){e({error:o instanceof Error?o.message:"Failed to restart"})}},dismiss:()=>{e({available:!1,downloaded:!1,info:null})},reset:()=>{e(Lo)}})),bu={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3",fingerprint:"fingerprint"},xu={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function sa(e){return e&&xu[e]||"var(--primary)"}const Bo=({icon:e,className:s,colorToken:n})=>{const r=bu[e??"branch"]??"user-3";return t.jsx(D,{name:r,className:s,style:{color:sa(n)}})},yu=({activeProfile:e,identities:s,onSelect:n,isApplying:r,iconOnly:o=!1})=>{const a=r||s.length===0;return t.jsxs(Mt,{children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx(Ft,{asChild:!0,children:t.jsxs(Me,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:{color:sa(e?.color)},disabled:a,children:[r?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Bo,{icon:e?.icon,colorToken:e?.color,className:"size-4"}),!o&&t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:e?.name||"No identity"}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Ge,{sideOffset:8,children:"Git identity"})]}),t.jsx(Ot,{align:"end",className:"w-64",children:s.length===0?t.jsx("div",{className:"px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:"No profiles available to apply."})}):s.map(l=>{const c=e?.id===l.id;return t.jsx(tt,{onSelect:()=>n(l),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Bo,{icon:l.icon,colorToken:l.color,className:"size-4"}),t.jsxs("span",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:l.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:l.userEmail})]}),c?t.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},l.id)})})]})},wu=e=>e==="/",Bs=e=>e.replace(/\\/g,"/"),_s=e=>{if(!e||wu(e))return e;let s=e;for(;s.length>1&&s.endsWith("/");)s=s.slice(0,-1);return s},Ts=e=>e.endsWith("/"),Bn=e=>{const s=e.trim();return!s||Ts(s)?s:`${s}/`},Jr=e=>e.lastIndexOf("/"),na=e=>{if(Ts(e))return e;const s=Jr(e);return s<0?e:e.slice(0,s+1)},ra=e=>{const s=Jr(e);return e.slice(s+1)},oa=e=>{const s=_s(e.trim());if(!s||s==="~"||s==="~/"||s==="/")return null;const n=Jr(s);return n<0?null:s.startsWith("~/")&&n<=1?"~/":n===0?"/":`${s.slice(0,n)}/`},ia=e=>Ts(e)&&oa(e)!==null,vu=e=>{if(!ia(e))return null;const s=_s(e.trim());return ra(s)||s},Su=(e,s)=>`${na(e)}${s}/`,gs=e=>{if(!e)return null;const s=_s(Bs(e.trim()));return s?s.toLowerCase():null},_o=(e,s)=>{const n=e.trim();return n==="~"?s:n.startsWith("~/")?`${s}${n.slice(1)}`:n},ju=(e,s)=>{const n=_s(Bs(e.trim())),r=_s(Bs(s.trim()));if(!n)return"";if(!r)return Bn(n);if(n.toLowerCase()===r.toLowerCase())return"~/";const o=`${r}/`;return n.toLowerCase().startsWith(o.toLowerCase())?`~/${n.slice(r.length+1)}/`:Bn(n)},ku=e=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,Lr=e=>{if(!e)return;e.focus({preventScroll:!0});const s=e.value.length;e.setSelectionRange(s,s),e.scrollLeft=e.scrollWidth},Cu=async()=>Xc(),Au=()=>{const[e,s]=Re.useState(!1),[n,r]=Re.useState(!1);Re.useEffect(()=>{s(Fs()),r(Pi())},[]);const o=Re.useCallback(async c=>e?await Ti(c):{success:!0,path:c},[e]),a=Re.useCallback(async c=>e?await Zc():{success:!0},[e]),l=Re.useCallback(async c=>e?await ed():{success:!0},[e]);return{isDesktop:e,canRequestAccess:n,requestAccess:o,startAccessing:a,stopAccessing:l}};function Nu({open:e,addedProjectPaths:s,shouldSuppressAutoFocus:n}){const r=Os(se=>se.homeDirectory),{canRequestAccess:o,startAccessing:a}=Au(),l=i.useRef(null),c=i.useRef(new Map),[u,d]=i.useState(""),[f,h]=i.useState("~/"),[b,m]=i.useState([]),[g,p]=i.useState(!1),[v,x]=i.useState(!1),[I,y]=i.useState(null),[C,N]=i.useState(0),[A,j]=i.useState(0),[w,k]=i.useState(!1),[R,P]=i.useState(!1),[T,F]=i.useState("right"),B=i.useRef("~/"),G=u||r;i.useEffect(()=>{if(!e)return;h("~/"),m([]),j(0),k(!1),P(!1),B.current="~/",F("right"),n||requestAnimationFrame(()=>Lr(l.current));let se=!1;return(async()=>{const Q=await Cu();se||(d(Q||r||""),n||requestAnimationFrame(()=>Lr(l.current)))})(),()=>{se=!0}},[r,e,n]);const L=i.useMemo(()=>na(f),[f]),M=i.useMemo(()=>Ts(f)?"":ra(f),[f]),U=i.useMemo(()=>G?_o(L,G):"",[L,G]);i.useEffect(()=>{const se=B.current;se!==L&&(F(L.length>=se.length?"right":"left"),B.current=L)},[L]),i.useEffect(()=>{if(!e||!U){m([]),y(null);return}let se=!1;return p(!0),x(!1),y(null),td(U).then(de=>{if(se)return;x(!1),y(null);const Q=de.filter(me=>me.isDirectory).map(me=>({name:me.name,path:Bs(me.path)})).sort((me,Ue)=>me.name.localeCompare(Ue.name));m(Q)}).catch(de=>{if(!se){m([]);const Q=sd(de)?de.reason:"unknown";y(Q),x(Q==="not-found")}}).finally(()=>{se||p(!1)}),()=>{se=!0}},[U,C,e]);const W=i.useMemo(()=>{const se=M.toLowerCase(),de=R||M.startsWith(".");return b.filter(Q=>Q.name.toLowerCase().startsWith(se)&&(de||!Q.name.startsWith(".")))},[M,b,R]),ae=i.useMemo(()=>vu(f),[f]),q=i.useMemo(()=>oa(f),[f]),$=i.useMemo(()=>{const se=[],de=gs(U);ia(f)&&ae&&q&&se.push({type:"parent",value:"browse:up",name:ae,path:q,alreadyAdded:!!(de&&s.has(de))});for(const Q of W){const me=gs(Q.path);se.push({type:"directory",value:`browse:${Q.path}`,name:Q.name,path:Q.path,alreadyAdded:!!(me&&s.has(me))})}return se},[s,U,ae,W,q,f]);i.useEffect(()=>{j(0)},[f,$.length]);const ke=i.useMemo(()=>G?_s(_o(f,G)):"",[G,f]),ee=gs(ke),Pe=!!(ee&&s.has(ee)),_e=i.useMemo(()=>M?W.find(se=>se.name===M)??null:null,[M,W]),Y=!!(ke&&!Pe&&(I===null||I==="not-found")&&(Ts(f)&&v||!Ts(f)&&M.trim().length>0&&_e===null)),O=$[A]??null,z=!!O,J=i.useCallback(se=>{h(Bn(se))},[]),X=i.useCallback(se=>{h(Su(f,se.name))},[f]),ge=i.useCallback(se=>{if(se){if(se.type==="parent"){J(se.path);return}X(se)}},[J,X]),ve=i.useCallback(async se=>{const de=await a(se);if(!de.success)return ie.error("Failed to open directory",{description:de.error||"Desktop could not grant file access."}),!1;const Q=G?ju(se,G):Bn(Bs(se));return J(Q),!0},[J,G,a]),xe=i.useCallback(async()=>{if(!w){k(!0);try{if(Pi()){const de=await Ti(ke);if(!de.success||!de.path){de.error&&de.error!=="Directory selection cancelled"&&ie.error("Failed to select directory",{description:de.error});return}await ve(de.path);return}const se=await nd(ke);if(se.status==="cancelled")return;if(se.status!=="picked"){ie.error("Couldn't open a folder picker",{description:se.error});return}await ve(se.path)}catch(se){ie.error("Failed to select directory",{description:se instanceof Error?se.message:"Unknown error occurred."})}finally{k(!1)}}},[ve,w,ke]);return{inputRef:l,rowRefs:c,query:f,setQuery:h,isLoading:g,isBrowseDirectoryMissing:v,browseErrorReason:I,browseReloadKey:C,setBrowseReloadKey:N,highlightedIndex:A,setHighlightedIndex:j,isPickingLocation:w,showHidden:R,setShowHidden:P,folderEnterFrom:T,explorerRootDirectory:G,browseDirectoryDisplayPath:L,browseDirectoryAbsolutePath:U,browseFilterQuery:M,filteredEntries:W,rows:$,targetPath:ke,isAlreadyAdded:Pe,shouldCreateTarget:Y,highlightedRow:O,hasHighlightedBrowseItem:z,canRequestAccess:o,browseToDisplayPath:J,browseToEntry:X,executeRow:ge,applyPickedLocation:ve,handleBrowseLocation:xe}}const hs=ks()(Bi(Vr((e,s)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{e({selectedProfileId:n})},loadProfiles:async()=>{e({isLoading:!0});const n=s().profiles;try{const r=Jt()?.git,o=r?await r.getGitIdentities():await dd();return e({profiles:o,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),e({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=Jt()?.git,r=n?.getGlobalGitIdentity?await n.getGlobalGitIdentity():await cd();if(r&&r.userName&&r.userEmail){const o={id:"global",name:"Global Identity",userName:r.userName,userEmail:r.userEmail,authType:r.sshCommand?"ssh":void 0,sshKey:r.sshCommand?r.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"fingerprint"};e({globalIdentity:o})}else e({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),e({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=Jt()?.git,r=n?.discoverGitCredentials?await n.discoverGitCredentials():await ld();return e({discoveredCredentials:r}),!0}catch(n){return console.error("Failed to discover git credentials:",n),e({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const o=r.trim();return o.length>0?o:null};try{let r=null;if(r===null){const o=Jt()?.settings;if(o)try{const l=(await o.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const o=await At("/api/pi/ui-settings",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return e({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",o=r.length>0?r:"";return await Yr({defaultGitIdentityId:o}),e({defaultGitIdentityId:o.length>0?o:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};Vt("saving");const o=Jt()?.git;return o?await o.createGitIdentity(r):await ad(r),Vt("saved"),await s().loadProfiles(),!0}catch(r){return Vt("error"),console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const o=s().profiles.find(c=>c.id===n);if(!o)throw new Error("Profile not found");const a={...o,...r};Vt("saving");const l=Jt()?.git;return l?await l.updateGitIdentity(n,a):await id(n,a),Vt("saved"),await s().loadProfiles(),!0}catch(o){return Vt("error"),console.error("Failed to update git identity profile:",o),!1}},deleteProfile:async n=>{try{Vt("saving");const r=Jt()?.git;return r?await r.deleteGitIdentity(n):await od(n),Vt("saved"),s().selectedProfileId===n&&e({selectedProfileId:null}),await s().loadProfiles(),!0}catch(r){return Vt("error"),console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:o}=s();return n==="global"?o||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=s();return r.filter(o=>!n.some(a=>a.authType==="token"&&a.host===o.host))}}),{name:"git-identities-store",storage:rd(),partialize:e=>({selectedProfileId:e.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=hs);function Iu({open:e,onClose:s,isMobile:n,addedProjectPaths:r,targetPath:o,shouldCreateTarget:a,browseErrorReason:l,browseDirectoryAbsolutePath:c,isAlreadyAdded:u,isPickingLocation:d}){const f=dt(q=>q.addProject),h=ce(q=>q.setActiveMainTab),b=ce(q=>q.setSessionSwitcherOpen),m=Ie(q=>q.openNewSessionDraft),g=hs(q=>q.profiles),p=hs(q=>q.globalIdentity),v=hs(q=>q.defaultGitIdentityId),x=hs(q=>q.loadProfiles),I=hs(q=>q.loadGlobalIdentity),y=hs(q=>q.loadDefaultGitIdentityId),[C,N]=i.useState(!1),[A,j]=i.useState(!1),[w,k]=i.useState(""),[R,P]=i.useState(null);i.useEffect(()=>{e&&(N(!1),j(!1),k(""),P(null))},[e]),i.useEffect(()=>{e&&(x(),I(),y())},[y,x,I,e]);const T=i.useMemo(()=>{const q=new Map;p&&q.set(p.id,p);for(const $ of g)q.set($.id,$);return Array.from(q.values())},[g,p]);i.useEffect(()=>{if(!e||!A||R!==null)return;const q=typeof v=="string"?v.trim():"";if(q&&T.some(ke=>ke.id===q)){P(q);return}const $=T.find(ke=>ke.authType==="ssh"||ke.sshKey);$&&P($.id)},[T,v,A,e,R]);const F=i.useMemo(()=>T.find(q=>q.id===R)??null,[T,R]),B=i.useCallback((q,$)=>{h("chat"),n&&b(!1),m({selectedProjectId:q,directoryOverride:$}),s()},[n,s,m,h,b]),G=i.useCallback(async q=>{if(!q||C)return;const $=gs(q);if($&&r.has($))return;let ke=q;N(!0);try{const ee=!A&&a&&gs(q)===gs(o);if(A){const _e=w.trim();if(!_e){ie.error("Enter a repository URL before cloning.");return}const Y=await At("/api/fs/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:_e,destinationPath:q,gitIdentityId:F?.id??null})});if(!Y.ok)throw new Error("Failed to clone git repository");ke=(await Y.json()).path||q}else if(ee&&!(await At("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},query:c?{directory:c}:void 0,body:JSON.stringify({path:q})})).ok)throw new Error("Failed to select directory");const Pe=f(ke);if(!Pe){ie.error("Failed to add folder",{description:"Please select a valid directory path."});return}B(Pe.id,Pe.path)}catch(ee){ie.error("Failed to select directory",{description:ee instanceof Error?ee.message:"Unknown error occurred."})}finally{N(!1)}},[f,r,c,w,A,C,B,F?.id,a,o]),L=!C&&!d&&!u&&l!=="os-permission"&&l!=="invalid-response"&&l!=="unknown"&&!!o,M=L&&w.trim().length>0,U=A?M:L,W=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";return{isConfirming:C,isCloneMode:A,setIsCloneMode:j,cloneRemoteUrl:w,setCloneRemoteUrl:k,selectedGitIdentityId:R,setSelectedGitIdentityId:P,availableGitIdentities:T,selectedGitIdentity:F,canSubmit:U,submitActionLabel:u?"Already added":A?C?"Cloning...":"Clone & add":C?"Adding...":a?"Create & add":"Add folder",submitModifierLabel:W,finalizeSelection:G}}const Ru=({open:e,onOpenChange:s})=>{const n=dt(Q=>Q.projects),{isMobile:r,isTablet:o}=Us(),a=r||o,l=i.useMemo(()=>new Set(n.map(Q=>gs(Q.path)).filter(Q=>!!Q)),[n]),c=i.useCallback(()=>{s(!1)},[s]),{inputRef:u,rowRefs:d,query:f,setQuery:h,isLoading:b,browseErrorReason:m,setBrowseReloadKey:g,highlightedIndex:p,setHighlightedIndex:v,isPickingLocation:x,showHidden:I,setShowHidden:y,folderEnterFrom:C,browseDirectoryDisplayPath:N,browseDirectoryAbsolutePath:A,rows:j,targetPath:w,isAlreadyAdded:k,shouldCreateTarget:R,highlightedRow:P,hasHighlightedBrowseItem:T,canRequestAccess:F,executeRow:B,handleBrowseLocation:G}=Nu({open:e,addedProjectPaths:l,shouldSuppressAutoFocus:a}),{isConfirming:L,isCloneMode:M,setIsCloneMode:U,cloneRemoteUrl:W,setCloneRemoteUrl:ae,setSelectedGitIdentityId:q,availableGitIdentities:$,selectedGitIdentity:ke,canSubmit:ee,submitActionLabel:Pe,submitModifierLabel:_e,finalizeSelection:Y}=Iu({open:e,onClose:c,isMobile:r,addedProjectPaths:l,targetPath:w,shouldCreateTarget:R,browseErrorReason:m,browseDirectoryAbsolutePath:A,isAlreadyAdded:k,isPickingLocation:x});i.useLayoutEffect(()=>{const Q=u.current;Q&&(Q.scrollLeft=Q.scrollWidth)},[u,f]),i.useLayoutEffect(()=>{!e||a||Lr(u.current)},[u,e,a]),i.useLayoutEffect(()=>{const Q=j[p];Q&&d.current.get(Q.value)?.scrollIntoView({block:"nearest"})},[p,d,j]);const O=i.useCallback(Q=>{if(Q.key==="ArrowDown"){Q.preventDefault(),v(me=>Math.min(j.length-1,me+1));return}if(Q.key==="ArrowUp"){Q.preventDefault(),v(me=>Math.max(0,me-1));return}if(Q.key==="Enter"){if(Q.preventDefault(),ku(Q)){Y(w);return}T&&B(P);return}Q.key==="Backspace"&&f===""&&(Q.preventDefault(),c())},[B,Y,c,T,P,f,j.length,v,w]),z=t.jsxs("button",{type:"button",onClick:()=>y(Q=>!Q),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[I?t.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),"Show hidden"]}),J=t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(D,{name:"folder-3",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),t.jsx(ln,{ref:u,value:f,onChange:Q=>h(Bs(Q.target.value)),onKeyDown:O,placeholder:"Enter a folder path...",className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})]}),t.jsxs(Me,{variant:"outline",size:"xs",className:"h-8 shrink-0 gap-1 px-2",disabled:L||x,onMouseDown:Q=>Q.preventDefault(),onClick:()=>{G()},title:"Browse location","aria-label":"Browse location",children:[t.jsx(D,{name:"folder-open",className:"h-3.5 w-3.5"}),x?"Opening...":"Browse"]})]})}),X=j.some(Q=>Q.type==="parent"),ge=t.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:t.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 pb-1 pt-0.5",children:[t.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:"Directories"}),t.jsxs(Me,{variant:"ghost",size:"xs",className:"h-6 shrink-0 gap-1 text-muted-foreground","aria-pressed":M,disabled:L||x,onClick:()=>U(Q=>!Q),children:[t.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"}),"Clone"]})]}),M?t.jsxs("div",{className:"mb-2 space-y-1.5 px-2 pb-1",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Clone into the folder path above."}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ln,{value:W,onChange:Q=>ae(Q.target.value),placeholder:"Repository URL (HTTPS or SSH)",className:"min-w-0 flex-1 font-mono typography-ui-label",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),t.jsx(yu,{activeProfile:ke,identities:$,onSelect:Q=>q(Q.id),isApplying:L,iconOnly:!0})]})]}):null,k?t.jsx("p",{className:"px-2 pb-2 typography-meta text-muted-foreground",children:"This folder is already added. Open a subfolder to add that instead."}):null,t.jsx("div",{className:_("mt-3","animate-in fade-in-0 duration-200 motion-reduce:animate-none",C==="left"?"slide-in-from-left-2":"slide-in-from-right-2"),children:b?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"Loading directories..."}):m&&m!=="not-found"?t.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-10 text-center",children:[t.jsx("div",{className:"typography-ui-label text-status-error",children:m==="os-permission"?"PiChamber needs access to this folder.":"Could not load this folder."}),t.jsxs("div",{className:"flex items-center gap-2",children:[m==="os-permission"&&F?t.jsx(Me,{size:"xs",onClick:()=>{G()},disabled:x,children:"Grant access"}):null,t.jsx(Me,{variant:"outline",size:"xs",onClick:()=>g(Q=>Q+1),children:"Try again"})]})]}):j.length===0?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"No matching directories."}):t.jsx("div",{className:"space-y-0.5",children:j.map((Q,me)=>{const Ue=me===p,K=Q.type==="directory"&&X;return t.jsxs("button",{ref:Z=>{Z?d.current.set(Q.value,Z):d.current.delete(Q.value)},type:"button","aria-label":Q.type==="parent"?Q.alreadyAdded?`Go back from ${Q.name}, already added`:`Go back from ${Q.name}`:Q.alreadyAdded?`Open ${Q.name}, already added`:`Open ${Q.name}`,onMouseEnter:()=>v(me),onMouseDown:Z=>Z.preventDefault(),onClick:()=>B(Q),className:_("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ue&&"bg-interactive-selection text-interactive-selection-foreground",!Ue&&"hover:bg-interactive-hover/50"),children:[t.jsxs("span",{className:_("flex min-w-0 flex-1 items-center gap-2",K&&"pl-4"),children:[Q.type==="parent"?t.jsx(D,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(D,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Q.name})]}),Q.alreadyAdded?t.jsx("span",{className:_("inline-flex shrink-0 items-center rounded-md px-1.5 py-0.5 typography-meta font-medium",Ue?"bg-interactive-selection-foreground/15 text-interactive-selection-foreground":"bg-[var(--surface-muted)] text-foreground"),children:"Added"}):null,Q.type==="parent"?t.jsx(D,{name:"arrow-up-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"}):t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"})]},Q.value)})})},N)]})}),ve=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[J,ge]}),xe=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(D,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),"Navigate"]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Open folder"]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx("span",{children:_e}),t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Add folder"]})]}),se=t.jsx(Me,{size:r?"xs":"default",onClick:()=>{Y(w)},disabled:!ee,className:_(r&&"w-full flex-1"),children:Pe}),de=()=>t.jsxs(t.Fragment,{children:[r?null:xe,t.jsx("div",{className:_("flex w-full flex-row justify-end gap-2 sm:w-auto",r&&"justify-stretch"),children:se})]});return r?t.jsx(yi,{open:e,onClose:c,title:"Add folder",className:"h-[88dvh] max-h-[720px]",contentMaxHeightClassName:"flex-1",footer:t.jsx("div",{className:"flex flex-col gap-2",children:de()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:z}),ve]})}):t.jsx(Kt,{open:e,onOpenChange:s,children:t.jsxs(Wt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(ls,{className:"px-5 pb-2 pt-5",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx(es,{children:"Add folder"}),t.jsx(cs,{className:"mt-2",children:"Choose a folder from the path above, then add it."})]}),z]})}),t.jsx("div",{className:"min-h-0 flex-1 px-5 pb-0",children:ve}),t.jsx(Ss,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:de()})]})})},kn=e=>e?t.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:e}):void 0,mg=()=>{const[e,s]=i.useState(!1),[n,r]=i.useState(null),[o,a]=i.useState(!1),l=Ie(A=>A.deleteSession),c=Ie(A=>A.deleteSessions),u=ce(A=>A.showDeletionDialog),d=ce(A=>A.setShowDeletionDialog),{isMobile:f,isTablet:h,hasTouchInput:b}=Us(),m=f||h||b;i.useEffect(()=>ud(()=>{s(!1)}),[]);const g=i.useCallback(A=>{r({sessions:A.sessions,dateLabel:A.dateLabel})},[]),p=i.useCallback(()=>{r(null),a(!1)},[]),v=i.useCallback(async A=>{if(A.sessions.length===0)return;if(A.sessions.length===1){const R=A.sessions[0];await l(R.id)?ie.success("Session deleted"):ie.error("Failed to delete session");return}const j=A.sessions.map(R=>R.id),{deletedIds:w,failedIds:k}=await c(j);if(w.length>0){const R=k.length>0?k.length===1?`${k.length} session could not be deleted.`:`${k.length} sessions could not be deleted.`:A.dateLabel?`Removed all sessions from ${A.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:kn(R)})}k.length>0&&ie.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:kn("Please try again in a moment.")})},[l,c]);i.useEffect(()=>xs.onDeleteRequest(A=>{if(!u){v(A);return}g(A)}),[g,u,v]),i.useEffect(()=>xs.onDirectoryRequest(()=>{s(!0)}),[]);const x=i.useCallback(async()=>{if(n){a(!0);try{if(n.sessions.length===1){const A=n.sessions[0];if(!await l(A.id)){ie.error("Failed to delete session"),a(!1);return}ie.success("Session deleted",{action:{label:"OK",onClick:()=>{}}})}else{const A=n.sessions.map(R=>R.id),j=await c(A),w=j.deletedIds,k=j.failedIds;if(w.length>0){const R=k.length>0?k.length===1?`${k.length} session could not be deleted.`:`${k.length} sessions could not be deleted.`:n.dateLabel?`Removed all sessions from ${n.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:kn(R),action:{label:"OK",onClick:()=>{}}})}if(k.length>0&&(ie.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:kn("Please try again in a moment.")}),w.length===0)){a(!1);return}}p()}finally{a(!1)}}},[n,l,c,p]),I=n?n.sessions.length===1?n.dateLabel?`This action permanently removes 1 session from ${n.dateLabel}.`:"This action permanently removes 1 session.":n.dateLabel?`This action permanently removes ${n.sessions.length} sessions from ${n.dateLabel}.`:`This action permanently removes ${n.sessions.length} sessions.`:"",y=n?t.jsxs("div",{className:"space-y-2",children:[n.sessions.length>0&&t.jsx("div",{className:"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3",children:t.jsxs("ul",{className:"space-y-0.5",children:[n.sessions.slice(0,5).map(A=>t.jsx("li",{className:"typography-micro text-muted-foreground/80",children:t.jsx("span",{className:"truncate",children:as(A)})},A.id)),n.sessions.length>5&&t.jsx("li",{className:"typography-micro text-muted-foreground/70",children:`+${n.sessions.length-5} more`})]})}),t.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:"Worktree directories stay intact. Subsessions linked to the selected sessions will also be removed."})})]}):null,C=t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>d(!u),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!u,children:[u?t.jsx(D,{name:"checkbox-blank",className:"size-4"}):t.jsx(D,{name:"checkbox",className:"size-4 text-primary"}),"Never ask"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Me,{variant:"ghost",onClick:p,disabled:o,children:"Cancel"}),t.jsx(Me,{variant:"destructive",onClick:x,disabled:o,children:o?"Deleting…":n?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),N=n?.sessions.length===1?"Delete session":"Delete sessions";return t.jsxs(t.Fragment,{children:[m?t.jsx(yi,{open:!!n,onClose:()=>{o||p()},title:N,footer:t.jsx("div",{className:"flex justify-end gap-2",children:C}),children:t.jsxs("div",{className:"space-y-2 pb-2",children:[I&&t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:I}),y]})}):t.jsx(Kt,{open:!!n,onOpenChange:A=>{if(!A){if(o)return;p()}},children:t.jsxs(Wt,{className:"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2",children:[t.jsxs(ls,{children:[t.jsx(es,{children:N}),I&&t.jsx(cs,{children:I})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2",children:y}),t.jsx(Ss,{className:"mt-2 gap-2 pt-1 pb-1",children:C})]})}),t.jsx(Ru,{open:e,onOpenChange:s})]})},gg=()=>{const e=ys(s=>s.entries);return i.useEffect(()=>{for(const s of e.values())!s.receipt||s.notificationSent||(ys.getState().markNotificationSent(s.key),ie.success("Worktree ready",{id:`worktree-ready:${s.key}`,description:s.receipt.branch||s.receipt.path}))},[e]),null},Du=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"general",title:"General",group:"general",kind:"single",keywords:["general","startup","launch at login","autostart","tray","password","passkey","security","privacy","telemetry","transport","network","lan","binary","cli","diagnostics","performance"]},{slug:"projects",title:"Projects",group:"projects",kind:"single",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"]},{slug:"providers",title:"Providers",group:"agent",kind:"single",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"behavior",title:"Behavior",group:"agent",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"skills.installed",title:"Skills",group:"agent",kind:"single",keywords:["skill","skills","instructions","install","catalog"]},{slug:"git",title:"Git",group:"projects",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","oauth","prs","issues"]},{slug:"appearance",title:"Appearance",group:"general",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"dictation",title:"Dictation",group:"general",kind:"single",description:"Record speech and insert a final transcript into the composer.",keywords:["voice","speech","microphone","transcription","stt","whisper","parakeet"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"]},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"snippets",title:"Snippets",group:"agent",kind:"single",keywords:["snippet","snippets","text expansion"]},{slug:"prompt-templates",title:"Prompt templates",group:"agent",kind:"single",keywords:["prompt template","prompt templates","slash command","slash commands"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"tunnel",title:"External Tunnel",group:"projects",kind:"single",keywords:["tunnel","external","cloudflare","qr","remote","mobile","share"],isAvailable:()=>!1},{slug:"about",title:"About",group:"general",kind:"single",keywords:["about","version","updates","release","changelog","pi","pichamber","open source"]}],Eu={sessions:"sessions",skills:"skills.installed",providers:"providers","git-identities":"git",settings:"home"};function Pu(e){const s=e.trim().toLowerCase();return Du.find(n=>n.slug===s)??null}function Tu(e){const s=(e??"").trim().toLowerCase();if(!s)return"home";const n=Eu[s];if(n)return n;const r=Pu(s);return r?r.slug:"home"}function bg(e){switch(e){case"general":return"settings-3";case"projects":return"folders";case"remote-instances":return"computer";case"appearance":return"palette";case"chat":return"chat-ai-3";case"dictation":return"mic";case"snippets":return"chat-thread";case"prompt-templates":return"terminal";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"behavior":return"brain";case"skills.installed":return"book-open";case"git":return"git-branch";case"tunnel":return"home-office";case"about":return"information";case"home":return null;default:return"robot-2"}}function xg(){const e=i.useRef(!1),s=i.useRef(!1),n=Ie(f=>f.setCurrentSession),r=ce(f=>f.setActiveMainTab),o=ce(f=>f.setSettingsDialogOpen),a=ce(f=>f.setSettingsPage),l=ce(f=>f.navigateToDiff),c=i.useCallback(async f=>{if(!s.current){s.current=!0;try{if(f.sessionId){const h=Ie.getState().currentSessionId,b=Es().getState().selectedSessionId;if(f.sessionId!==h||f.sessionId!==b){const m=Ie.getState().getDirectoryForSession(f.sessionId);n(f.sessionId,m)}}if(f.settingsPath){a(Tu(f.settingsPath)),o(!0);return}ce.getState().isSettingsDialogOpen&&o(!1),f.tab&&r(f.tab),f.diffFile&&(f.tab==="diff"||!f.tab)&&l(f.diffFile)}finally{s.current=!1}}},[n,r,o,a,l]),u=i.useCallback(()=>{const f=Ie.getState(),h=Es().getState(),b=ce.getState();return{sessionId:sr({currentSessionId:f.currentSessionId,piSelectedSessionId:h.selectedSessionId,draft:f.newSessionDraft}),tab:b.activeMainTab,isSettingsOpen:b.isSettingsDialogOpen,settingsPath:b.settingsPage,diffFile:b.pendingDiffFile}},[]),d=i.useCallback((f={})=>{if(s.current)return;const h=u();Mr(h,f)},[u]);i.useEffect(()=>{if(e.current||(e.current=!0,!ko()))return;const f=Co();(async()=>(await c(f),Mr({...u(),sessionId:f.sessionId??sr({currentSessionId:Ie.getState().currentSessionId,piSelectedSessionId:Es().getState().selectedSessionId,draft:Ie.getState().newSessionDraft}),tab:f.tab??ce.getState().activeMainTab,settingsPath:f.settingsPath??ce.getState().settingsPage,diffFile:f.diffFile??ce.getState().pendingDiffFile},{replace:!0,force:!0})))()},[c,u]),i.useEffect(()=>{const f=()=>{const v=Ie.getState(),x=Es().getState();return sr({currentSessionId:v.currentSessionId,piSelectedSessionId:x.selectedSessionId,draft:v.newSessionDraft})};let h=f(),b=Ie.getState().newSessionDraft?.open===!0;const m=()=>{const v=Ie.getState(),x=f(),I=v.newSessionDraft?.open===!0;x===h&&I===b||s.current||(h=x,b=I,d({replace:!0}))},g=Ie.subscribe(()=>{m()}),p=Es().subscribe(()=>{m()});return()=>{g(),p()}},[d]),i.useEffect(()=>{let f=ce.getState().activeMainTab,h=ce.getState().isSettingsDialogOpen,b=ce.getState().settingsPage,m=ce.getState().pendingDiffFile;return ce.subscribe(p=>{if(s.current)return;const v=p.activeMainTab!==f,x=p.isSettingsDialogOpen!==h,I=p.settingsPage!==b,y=p.pendingDiffFile!==m&&p.activeMainTab==="diff";f=p.activeMainTab,h=p.isSettingsDialogOpen,b=p.settingsPage,m=p.pendingDiffFile,(v||x||I||y)&&d()})},[d]),i.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const h=Co();if(ko())c(h);else{const b=ce.getState();b.isSettingsDialogOpen&&o(!1),b.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",f),()=>{window.removeEventListener("popstate",f)}},[c,r,o])}function Mu(e=!0){const s=Tn(r=>r.checkForUpdates),n=i.useRef(s);i.useEffect(()=>{n.current=s},[s]),i.useEffect(()=>{if(!e)return;const r=3e3,o=3600*1e3,a=300*1e3,l=1440*60*1e3;let c=!1,u=null;const d=h=>{const b=Math.round(h*1e3);return Math.max(a,Math.min(l,b))},f=h=>{c||(u=window.setTimeout(async()=>{const b=await n.current(),m=typeof b=="number"&&Number.isFinite(b)?d(b):o;f(m)},h))};return f(r),()=>{c=!0,u!==null&&window.clearTimeout(u)}},[e])}function yg(){const e=tn(s=>s.connection==="ready",void 0,"chrome");return Mu(e),null}const Uo=12,Fu=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],Ou=({isActive:e,burstKey:s=0,className:n,durationMs:r=900,bursts:o=Fu,onComplete:a})=>{const l=Re.useRef(!1);Re.useEffect(()=>{!e&&l.current&&a?.(),e&&(l.current=!0)},[e,a]);const c=Re.useMemo(()=>Array.from({length:Uo},(u,d)=>{const f=Math.PI*2*d/Uo;return{x:Math.cos(f),y:Math.sin(f),delay:d*18}}),[]);return e?t.jsx("div",{className:_("fireworks-overlay pointer-events-none",n),"aria-hidden":"true","data-burst-key":s,children:o.map(u=>{const d={"--burst-delay":`${u.delay}ms`,"--burst-x":`${u.x}%`,"--burst-y":`${u.y}%`,"--firework-color":`var(${u.colorVar})`,"--firework-duration":`${r}ms`};return t.jsx("div",{className:"firework-burst",style:d,children:c.map((f,h)=>{const b=f.x*u.radius,m=f.y*u.radius,g={"--translate-x":`${b}px`,"--translate-y":`${m}px`,"--particle-delay":`${f.delay}ms`,color:`var(${u.colorVar})`};return t.jsx("span",{className:"firework-particle",style:g},`${u.id}-${h}-${s}`)})},`${u.id}-${s}`)})}):null},Lu=({durationMs:e=3400}={})=>{const[s,n]=Re.useState({isActive:!1,cycle:0}),r=Re.useRef(null),o=Re.useCallback(()=>{r.current&&(window.clearTimeout(r.current),r.current=null)},[]),a=Re.useCallback(()=>{o(),n(c=>c.isActive?{...c,isActive:!1}:c)},[o]),l=Re.useCallback(()=>{o(),n(c=>({isActive:!0,cycle:c.cycle+1})),r.current=window.setTimeout(()=>{n(c=>c.isActive?{...c,isActive:!1}:c),r.current=null},e)},[o,e]);return Re.useEffect(()=>()=>o(),[o]),{isActive:s.isActive,burstKey:s.cycle,triggerFireworks:l,dismissFireworks:a}},aa=i.createContext(void 0),wg=({children:e})=>{const{isActive:s,burstKey:n,triggerFireworks:r,dismissFireworks:o}=Lu(),a=i.useMemo(()=>({triggerFireworks:r,dismissFireworks:o}),[r,o]);return t.jsxs(aa.Provider,{value:a,children:[e,t.jsx(Ou,{isActive:s,burstKey:n})]})},Bu={triggerFireworks:()=>{},dismissFireworks:()=>{}},vg=()=>i.useContext(aa)??Bu,zo="https://github.com/RyderAsKing/PiChamber/releases";function _u(e){const s=new Date(`${e}T00:00:00`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(s)}function Uu(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function $o(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function zu(e,s){const n=e.split(".").map(o=>Number.parseInt(o,10)),r=s.split(".").map(o=>Number.parseInt(o,10));for(let o=0;o<3;o+=1){const a=Number.isFinite(n[o])?n[o]:0,l=Number.isFinite(r[o])?r[o]:0;if(a!==l)return l-a}return 0}function $u(e){const s=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=s.exec(e))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((o,a)=>{const l=n[a+1]?.start??e.length,c=e.slice(o.start,l).trim();return{version:o.version,date:o.date,start:o.start,end:l,raw:c}})}const Go=2e3,Gu=600*1e3;async function Ku(){try{const e=await At("/api/pi/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return e.ok?{success:!0,autoRestart:(await e.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await e.json().catch(()=>({}))).error||`Server error: ${e.status}`}}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Wu(){try{return(await At("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function Hu(e,s=Math.ceil(Gu/Go),n=Go){for(let r=0;r<s;r++){try{const o=await At("/api/pi/update-check",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);if(a&&a.available===!1||a&&typeof a.currentVersion=="string"&&typeof e=="string"&&a.currentVersion!==e)return!0}else if((o.status===401||o.status===403)&&await Wu())return!0}catch{}await new Promise(o=>setTimeout(o,n))}return!1}const la=({open:e,onOpenChange:s,info:n,downloading:r,downloaded:o,progress:a,error:l,onDownload:c,onRestart:u,runtimeType:d="desktop"})=>{const[f,h]=Re.useState(!1),[b,m]=Re.useState("idle"),[g,p]=Re.useState(null),v=n?.version?n.releaseUrl||`${zo}/tag/v${n.version}`:zo,x=n?.downloadUrl||v,I=a?.total?Math.round(a.downloaded/a.total*100):0,y=d==="web",C=d==="mobile",N=n?.updateCommand||"pichamber update";Re.useEffect(()=>{e||(m("idle"),p(null))},[e]);const A=async()=>{(await ws(N)).ok&&(h(!0),setTimeout(()=>h(!1),2e3))},j=Re.useCallback(async T=>{await wi(T)},[]),w=Re.useCallback(async()=>{m("updating"),p(null);const T=await Ku();if(!T.success){m("error"),p(T.error||"Update failed");return}T.autoRestart&&(m("restarting"),await new Promise(B=>setTimeout(B,2e3))),m("reconnecting"),await Hu(n?.currentVersion)?window.location.reload():(m("error"),p("Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update"))},[n?.currentVersion]),k=Re.useCallback(()=>{j(x)},[j,x]),R=b!=="idle"&&b!=="error",P=Re.useMemo(()=>{if(!n?.body)return null;const T=n.body.trim();if(!T)return null;const F=$u(T);return F.length===0?{kind:"raw",title:"What's new",content:$o(T)}:{kind:"sections",title:"What's new",sections:[...F].sort((G,L)=>zu(G.version,L.version)).map(G=>({version:G.version,dateLabel:_u(G.date),content:$o(Uu(G.raw)||T)}))}},[n?.body]);return t.jsx(Kt,{open:e,onOpenChange:R?void 0:s,children:t.jsxs(Wt,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(es,{className:"flex items-center gap-2.5",children:[t.jsx(D,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:b==="restarting"||b==="reconnecting"?"Updating PiChamber...":"Update Available"})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[y&&R&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(D,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&"Installing update...",b==="restarting"&&"Server restarting...",b==="reconnecting"&&"Waiting for server..."]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"The page will reload automatically when the update is complete."})]}),P&&!R&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(ps,{className:"max-h-[400px] p-0",fillContainer:!1,children:P.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:T=>{const B=T.target.closest("a");B&&B.href&&(T.preventDefault(),T.stopPropagation(),j(B.href))},children:t.jsx(Ao,{content:P.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:P.sections.map(T=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",T.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:T.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:F=>{const G=F.target.closest("a");G&&G.href&&(F.preventDefault(),F.stopPropagation(),j(G.href))},children:t.jsx(Ao,{content:T.content,disableLinkSafety:!0,enableFileReferences:!1})})]},T.version))})})}),y&&b==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(D,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:"Or update via terminal:"})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:N}),t.jsx("button",{onClick:A,className:_("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",f&&"text-[var(--status-success)]"),title:f?"Copied!":"Copy command",children:f?t.jsx(D,{name:"check",className:"h-4 w-4"}):t.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&!C&&r&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Downloading update payload..."}),t.jsxs("span",{className:"font-mono text-foreground",children:[I,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${I}%`}})})]}),(l||g)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:l||g})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!C&&!o&&!r&&t.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"download",className:"h-4 w-4"}),"Download Update"]}),!y&&!C&&r&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),"Downloading..."]}),!y&&!C&&o&&t.jsxs("button",{onClick:u,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"restart",className:"h-4 w-4"}),"Restart to Update"]}),C&&t.jsxs(Me,{onClick:k,size:"default",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),"Open update"]}),y&&!R&&t.jsxs("button",{onClick:w,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"download",className:"h-4 w-4"}),"Update Now"]}),y&&R&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),"Updating..."]})]})]})]})})},Yu=i.memo(function({checked:s,onChange:n,disabled:r=!1,ariaLabel:o,className:a,iconClassName:l}){const c=i.useCallback(d=>{d.preventDefault(),d.stopPropagation(),!r&&!s&&n()},[s,r,n]),u=i.useCallback(d=>{(d.key===" "||d.key==="Enter")&&(d.preventDefault(),!r&&!s&&n())},[s,r,n]);return t.jsx("button",{type:"button",role:"radio",onClick:c,onKeyDown:u,disabled:r,"aria-checked":s,"aria-label":o,className:_("group/radio relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full outline-none","transition-[background-color,box-shadow] duration-200 ease-out",s?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none hover:bg-[var(--primary-base)]":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)] hover:bg-[var(--interactive-hover)]","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50",a),children:t.jsx("span",{"aria-hidden":!0,className:_("block h-[5px] w-[5px] rounded-full bg-white",!s&&"opacity-0",l)})})}),hn=({children:e,className:s,contentClassName:n})=>{const[r,o]=i.useState(!1),a=i.useRef(null);return i.useEffect(()=>{if(!r)return;const l=c=>{const u=a.current;u&&c.target instanceof Node&&u.contains(c.target)||o(!1)};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[r]),t.jsxs(ze,{open:r,onOpenChange:o,children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{ref:a,type:"button","aria-label":"More information","aria-expanded":r,onClick:l=>{l.preventDefault(),l.stopPropagation(),o(c=>!c)},className:_("inline-flex h-5 w-5 shrink-0 cursor-help items-center justify-center rounded text-muted-foreground/60 hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",s),children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Ge,{sideOffset:8,className:_("max-w-sm",n),children:e})]})},Sg="w-full min-w-40 max-w-48",jg="settings",Qu="w-full min-w-40 max-w-48",kg="h-8 w-8 px-0 text-muted-foreground hover:text-foreground",qu="w-full max-w-[24rem]",Cg="min-w-0 flex-1",Ag="flex w-full min-w-0 items-center gap-2",Ng="typography-meta shrink-0 text-muted-foreground tabular-nums",ca="space-y-3.5",Vu="space-y-1.5",Ig="typography-settings-page-title text-muted-foreground",Ju="typography-settings-section-title text-foreground",da="typography-settings-group-title text-foreground",Xr="typography-settings-field-label text-foreground",Xu="typography-settings-description text-muted-foreground",pn="typography-meta text-muted-foreground",Rg="typography-meta font-medium text-foreground",Dg="typography-settings-section-title text-foreground",Zu=({title:e,description:s,titleAccessory:n,info:r,headerAction:o,children:a,divider:l=!0,className:c,contentClassName:u,settingsItem:d})=>{const f=e!=null||s!=null||o!=null||r!=null;return t.jsxs("section",{"data-settings-item":d,className:_("space-y-4",l?"border-t border-border/60 py-6":"pb-6",c),children:[f?t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[e!=null?t.jsxs("div",{className:"flex items-center gap-2",children:[typeof e=="string"||typeof e=="number"?t.jsx("h2",{className:Ju,children:e}):e,n,r!=null?t.jsx(hn,{children:r}):null]}):null,s!=null?t.jsx("div",{className:Xu,children:s}):null]}),o?t.jsx("div",{className:"shrink-0",children:o}):null]}):null,t.jsx("div",{className:_(u),children:a})]})},Eg=({children:e,className:s})=>t.jsx("div",{className:_("grid grid-cols-1 gap-6 @3xl:grid-cols-2 @3xl:gap-10",s),children:e}),ef=({children:e,className:s,as:n="h3"})=>t.jsx(n,{className:_(da,s),children:e}),Pg=({title:e,description:s,info:n,children:r,className:o,contentClassName:a,settingsItem:l})=>t.jsxs("div",{"data-settings-item":l,className:_("space-y-2",o),children:[e!=null||s!=null||n!=null?t.jsxs("div",{className:"space-y-0.5",children:[e!=null?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ef,{children:e}),n!=null?t.jsx(hn,{children:n}):null]}):null,s!=null?t.jsx("p",{className:pn,children:s}):null]}):null,t.jsx("div",{className:_(a),children:r})]}),rn=({label:e,description:s,info:n,descriptionPlacement:r="before",children:o,settingsItem:a,className:l,controlClassName:c})=>{const u=s!=null?t.jsx("p",{className:pn,children:s}):null;return t.jsxs("div",{"data-settings-item":a,className:_("space-y-2",l),children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:Xr,children:e}),n!=null?t.jsx(hn,{children:n}):null]}),r==="before"?u:null]}),t.jsx("div",{className:_("flex min-w-0 max-w-[24rem] items-center gap-2",c),children:o}),r==="after"?u:null]})},Tg=({label:e,description:s,info:n,children:r,settingsItem:o,className:a,controlClassName:l,alignEnd:c=!0})=>t.jsxs("div",{"data-settings-item":o,className:_("flex flex-col gap-2 py-0.5 @xl:flex-row @xl:items-center @xl:gap-8",a),children:[t.jsxs("div",{className:"min-w-0 @xl:w-56 @xl:shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:Xr,children:e}),n!=null?t.jsx(hn,{children:n}):null]}),s!=null?t.jsx("p",{className:_(pn,"mt-0.5"),children:s}):null]}),t.jsx("div",{className:_("flex min-w-0 flex-1 items-center gap-2 @xl:w-fit @xl:flex-none",c&&"@xl:justify-end",l),children:r})]}),Mg=({children:e,className:s,settingsItem:n})=>t.jsx("div",{"data-settings-item":n,className:_("pt-4",s),children:e}),tf=({checked:e,onChange:s,label:n,description:r,disabled:o=!1,ariaLabel:a,settingsItem:l,className:c,labelAccessory:u,info:d})=>{const f=()=>{o||s(!e)},h=r!=null;return t.jsxs("div",{"data-settings-item":l,className:_("group flex cursor-pointer gap-2 py-0.5",h?"items-start":"items-center",o&&"cursor-not-allowed opacity-60",c),role:"button",tabIndex:o?-1:0,"aria-pressed":e,"aria-disabled":o||void 0,onClick:f,onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),f())},children:[t.jsx(Sr,{checked:e,onChange:s,disabled:o,ariaLabel:a}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:Xr,children:n}),u,d!=null?t.jsx(hn,{children:d}):null]}),h?t.jsx("span",{className:pn,children:r}):null]})]})},Fg=({selected:e,onSelect:s,label:n,description:r,ariaLabel:o,disabled:a=!1,className:l})=>t.jsxs("div",{className:_("flex cursor-pointer gap-2 py-0.5",r!=null?"items-start":"items-center",a&&"cursor-not-allowed opacity-60",l),role:"button",tabIndex:a?-1:0,"aria-pressed":e,"aria-disabled":a||void 0,onClick:()=>{a||s()},onKeyDown:c=>{(c.key===" "||c.key==="Enter")&&(c.preventDefault(),a||s())},children:[t.jsx(Yu,{checked:e,onChange:s,disabled:a,ariaLabel:o,className:r!=null?"mt-0.5":void 0}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:_("typography-settings-field-label font-normal",e?"text-foreground":"text-foreground/50"),children:n}),r!=null?t.jsx("span",{className:pn,children:r}):null]})]}),Og=({"aria-label":e,children:s,className:n})=>t.jsx("div",{role:"radiogroup","aria-label":e,className:_(Vu,n),children:s});function Lg({value:e,options:s,onChange:n,className:r,"aria-label":o}){return t.jsx("div",{role:"group","aria-label":o,className:_("flex flex-wrap items-center gap-1",r),children:s.map(a=>t.jsx(Me,{type:"button",variant:"chip",size:"xs",disabled:a.disabled,"aria-pressed":e===a.value,className:"!font-normal",onClick:()=>n(a.value),children:a.label},a.value))})}class sf extends i.Component{constructor(s){super(s),this.state={hasError:!1}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}componentDidCatch(s,n){this.setState({error:s,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(sc,{className:"w-full max-w-md",children:[t.jsx(nc,{className:"text-center",children:t.jsxs(rc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(oc,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(Me,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(D,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function nf(e){return t.jsx(sf,{...e,texts:{title:"Chat Error",description:"The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data.",sessionLabel:"Session",detailsSummary:"Error details",resetAction:"Reset Chat",persistentHint:"If the problem persists, try refreshing the page."}})}const Bg=({active:e=!0})=>{const s=Ie(n=>n.currentSessionId);return t.jsx(nf,{sessionId:s||void 0,children:t.jsx(ic,{active:e},s??"no-session")})};function rf({onResizeStart:e,ariaLabel:s}){return t.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":s,onPointerDown:e,className:"pointer-events-auto -m-2 flex size-7 cursor-ns-resize items-end justify-end p-2 touch-none select-none",children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,children:t.jsx("path",{d:"M9.11111 2L2 9.11111M10 6.44444L6.44444 10",className:"stroke-muted-foreground",strokeLinecap:"round"})})})}const ua=Re.forwardRef(({className:e,outerClassName:s,scrollbarClassName:n,fillContainer:r=!1,useScrollShadow:o=!1,scrollShadowSize:a,hasError:l,resizedHeight:c,onResizeHeightChange:u,disabled:d,simple:f,endSlot:h,...b},m)=>{const g=Re.useRef(null),p=Re.useRef(null),[v,x]=Re.useState(null),I=c??v,y=Re.useCallback(N=>{const A=g.current;if(!A)return;p.current={startY:N.clientY,startHeight:A.getBoundingClientRect().height};const j=N.currentTarget;j.setPointerCapture(N.pointerId);const w=R=>{const P=p.current;if(!P)return;const T=P.startHeight+(R.clientY-P.startY),F=Math.max(82,T);u?u(F):x(F)},k=()=>{p.current=null,j.removeEventListener("pointermove",w),j.removeEventListener("pointerup",k),j.removeEventListener("pointercancel",k)};j.addEventListener("pointermove",w),j.addEventListener("pointerup",k),j.addEventListener("pointercancel",k),N.preventDefault()},[u]),C=Re.useCallback(N=>{if(N.target.closest('textarea, button, [role="separator"]'))return;const j=g.current?.querySelector("textarea");j&&document.activeElement!==j&&(N.preventDefault(),j.focus())},[]);return f?t.jsx(ps,{as:"textarea",ref:m,disableHorizontal:!0,fillContainer:r,useScrollShadow:o,scrollShadowSize:a,outerClassName:s,scrollbarClassName:n,className:_("block w-full appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","px-3 py-2 md:typography-ui-label","placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r?"[field-sizing:fixed]":"field-sizing-content",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:d,...b}):t.jsx("div",{ref:g,onPointerDown:C,style:I!==null?{height:`${I}px`}:void 0,className:_("group/textarea relative flex w-full flex-col rounded-[var(--radius-xl)] bg-[var(--surface-elevated)] pb-2.5","ring-1 ring-inset ring-border/60 transition duration-200 ease-out","hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)]","has-[[disabled]]:pointer-events-none has-[[disabled]]:bg-[var(--surface-subtle)] has-[[disabled]]:ring-transparent",!l&&["hover:[&:not(:focus-within)]:ring-transparent","focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]"],l&&["ring-[var(--status-error)]","focus-within:ring-2 focus-within:ring-[var(--status-error)]"],s),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col gap-2",children:[t.jsx("textarea",{ref:m,className:_("block w-full flex-1 min-h-0 appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","min-h-[82px] pl-3 pr-2.5 pt-2.5 md:typography-ui-label","focus-visible:outline-none disabled:cursor-not-allowed",!d&&["placeholder:select-none placeholder:text-muted-foreground placeholder:transition placeholder:duration-200 placeholder:ease-out","group-hover/textarea:placeholder:text-foreground/80","focus:placeholder:text-foreground/80"],d&&"text-muted-foreground/60 placeholder:text-muted-foreground/60",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:d,...b}),t.jsxs("div",{className:"flex items-center justify-end gap-1.5 pl-3 pr-2.5",children:[h,t.jsx(rf,{onResizeStart:y,ariaLabel:"Resize textarea"})]})]})})});ua.displayName="Textarea";const fa=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],on=Object.fromEntries(fa.map(e=>[e.key,e.Icon])),Br="pichamber:project-actions-updated",ha=e=>{const s=(e||"").trim().replace(/\\/g,"/");return s?s==="/"?"/":s.length>1?s.replace(/\/+$/,""):s:""},Xt=(e,s)=>`${ha(e)}::${s}`,pa=({title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,children:l,className:c,contentClassName:u,divider:d=!0})=>t.jsx(Zu,{title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,divider:d,className:c,contentClassName:u,children:l}),_r=e=>e.name.trim().length>0&&e.command.trim().length>0,of=e=>e.name.trim().length===0&&e.command.trim().length===0,af=e=>!_r(e)&&!of(e),lf=(e,s)=>e.some(r=>s.has(r.id)&&!_r(r))?{canPersist:!1,actions:e}:{canPersist:!0,actions:e.filter(_r)},cf=450,df=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,uf=()=>({id:df(),name:"",command:"",icon:"play"}),ff=({projectRef:e})=>{const[s,n]=i.useState([]),[r,o]=i.useState(!1),[a,l]=i.useState(null),[c,u]=i.useState(new Set),d=i.useRef(!1);i.useEffect(()=>{let x=!1;return o(!0),(async()=>{try{const I=await jr(e);if(x)return;n(I.actions),l(JSON.stringify({actions:I.actions})),u(new Set(I.actions.map(y=>y.id)))}catch{if(x)return;n([]),l(JSON.stringify({actions:[]})),u(new Set)}finally{x||o(!1)}})(),()=>{x=!0}},[e]);const f=i.useMemo(()=>lf(s,c),[s,c]),h=i.useMemo(()=>JSON.stringify({actions:f.actions}),[f.actions]),b=a!==null&&f.canPersist&&h!==a,m=i.useCallback(async x=>await ac(e,{actions:x,primaryActionId:null})?(l(JSON.stringify({actions:x})),u(new Set(x.map(y=>y.id))),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Br,{detail:{projectId:e.id}})),!0):(ie.error("Failed to save actions"),!1),[e]);i.useEffect(()=>{if(!b||r||d.current)return;const x=window.setTimeout(()=>{d.current||(d.current=!0,(async()=>{try{await m(f.actions)}finally{d.current=!1}})())},cf);return()=>{window.clearTimeout(x)}},[b,r,m,f.actions]);const g=i.useCallback(()=>{const x=uf();n(I=>[...I,x])},[]),p=i.useCallback(x=>{n(I=>I.filter(y=>y.id!==x))},[]),v=i.useCallback((x,I)=>{n(y=>y.map(C=>C.id===x?I(C):C))},[]);return t.jsx(pa,{title:"Actions",info:"Per-project commands shown in the header next to the project name.",settingsItem:"projects.actions",headerAction:t.jsxs(Me,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),"Add action"]}),contentClassName:"space-y-4",children:r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Loading..."}):s.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"No actions configured yet."}):t.jsx("div",{className:_("space-y-6",qu),children:s.map((x,I)=>{const y=x.icon||"play",C=on[y]||"play",N=x.name.trim()||`Action ${I+1}`,A=af(x);return t.jsxs("div",{className:ca,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:da,children:N}),t.jsx(Me,{type:"button",variant:"ghost",size:"xs",className:"h-8 w-8 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>p(x.id),"aria-label":`Delete ${N}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsxs(rn,{label:"Name",controlClassName:"w-full max-w-none",children:[t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":"Select icon",children:t.jsx(D,{name:C,className:"h-4 w-4"})})}),t.jsx(Ot,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:fa.map(j=>{const w=j.Icon,k=(x.icon||"play")===j.key;return t.jsx("button",{type:"button",onClick:()=>v(x.id,R=>({...R,icon:j.key})),className:_("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",k&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":`Icon ${j.label}`,children:t.jsx(D,{name:w,className:"h-4 w-4"})},j.key)})})})]}),t.jsx(ln,{value:x.name,onChange:j=>v(x.id,w=>({...w,name:j.target.value})),placeholder:"Action name",className:"h-8 min-w-0 flex-1 rounded-md px-3"})]}),t.jsx(rn,{label:"Command",controlClassName:"w-full max-w-none",children:t.jsx(ua,{value:x.command,onChange:j=>v(x.id,w=>({...w,command:j.target.value})),placeholder:"e.g. bun run lint",className:"min-h-[88px] w-full font-mono text-xs"})}),A?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Enter a name and command to save this action."}):null,t.jsx(tf,{checked:x.autoOpenUrl===!0,onChange:j=>v(x.id,w=>({...w,...j?{autoOpenUrl:!0}:{autoOpenUrl:void 0,openUrl:void 0}})),label:"Auto-open URL",info:"Opens a URL from command output, or a custom URL if you set one.",ariaLabel:`Auto-open URL for ${N}`}),x.autoOpenUrl===!0?t.jsx(t.Fragment,{children:t.jsx(rn,{label:"Custom URL",info:"Leave empty to use the best URL from command output.",controlClassName:"w-full max-w-none",children:t.jsx(ln,{value:x.openUrl||"",onChange:j=>v(x.id,w=>({...w,openUrl:j.target.value})),placeholder:"https://localhost:3000",className:"h-8 w-full rounded-md px-3"})})}):null]},x.id)})})})},hf={searchPlaceholder:"Search models",noResults:"No models found",favorites:"Favorites",recent:"Recent",favorite:"Favorite",unfavorite:"Unfavorite",capabilities:"Capabilities",capabilityToolCalling:"Tool calling",capabilityReasoning:"Reasoning",input:"Input",output:"Output",costPerMillion:"Cost ($/1M tokens)"},pf=({value:e,noneLabel:s,ariaLabel:n,disabled:r=!1,className:o,isModelAllowed:a,onChange:l})=>{const c=$t(w=>w.providers),u=$t(w=>w.modelsMetadata),d=ce(w=>w.hiddenModels),f=ce(w=>w.isFavoriteModel),h=ce(w=>w.toggleFavoriteModel),b=ce(w=>w.reorderFavoriteModel),{favoriteModelsList:m,recentModelsList:g}=lc(),[p,v]=i.useState(!1),[x,I]=i.useState("");i.useEffect(()=>{p||I("")},[p]);const y=e?c.find(w=>w.id===e.providerId):void 0,C=e&&y?(Array.isArray(y.models)?y.models:[]).find(w=>w.id===e.modelId):void 0,N=e?cc(C,e.modelId):s,A=i.useMemo(()=>e?d.filter(w=>!(w.providerID===e.providerId&&w.modelID===e.modelId)):d,[d,e]),j=i.useCallback(w=>{l({providerId:w.providerID,modelId:w.modelID}),v(!1)},[l]);return t.jsxs(Mt,{modal:!1,open:p,onOpenChange:w=>{r||v(w)},children:[t.jsx(Ft,{asChild:!0,disabled:r,children:t.jsxs("button",{type:"button","aria-label":n,disabled:r,className:_(vi({size:"default"}),Qu,"min-w-0",o),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e?.providerId?t.jsx(dc,{providerId:e.providerId,className:"size-4 shrink-0"}):null,t.jsx("span",{className:_("truncate",e?"text-foreground":"text-muted-foreground"),children:N})]}),t.jsx(D,{name:"arrow-down-s",className:"size-4 shrink-0"})]})}),t.jsx(Ot,{align:"start",portalToBody:!0,positionerClassName:"z-[80]",className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",children:t.jsx(uc,{providers:c,favoriteModels:m,recentModels:g,modelsMetadata:u,searchQuery:x,onSearchQueryChange:I,onSelect:j,labels:{...hf,notSelected:s},selectedModel:e?{providerID:e.providerId,modelID:e.modelId}:null,hiddenModels:A,isModelAllowed:a,includeNotSelected:!0,onSelectNone:()=>{l(null),v(!1)},disabled:r,autoFocus:!0,onEscape:()=>v(!1),isFavorite:w=>f(w.providerID,w.modelID),onToggleFavorite:w=>h(w.providerID,w.modelID),onReorderFavorite:(w,k)=>b(w.providerID,w.modelID,k.providerID,k.modelID),reorderFavoriteAriaLabel:"Reorder favorite",reorderFavoriteTitle:"Drag to reorder favorite"})})]})},or="w-full max-w-none",mf=({form:e})=>{const{name:s,setName:n,parsedDefaultModel:r,handleDefaultModelChange:o,project:a}=e,l=$t(c=>c.loadProviders);return i.useEffect(()=>{l({source:"projectSettings"})},[l]),a?t.jsx(pa,{title:"Project",divider:!1,children:t.jsxs("div",{className:ca,children:[t.jsx(rn,{label:"Name",settingsItem:"projects.name",controlClassName:or,children:t.jsx(ln,{value:s,onChange:c=>n(c.target.value),placeholder:"Project name","aria-label":"Project name",className:"h-8 w-full rounded-md px-3"})}),t.jsx(rn,{label:"Default model",info:"Used when starting a new chat in this project. Unset keeps the global session default.",settingsItem:"projects.default-model",controlClassName:or,children:t.jsx(pf,{value:r,noneLabel:"Use global default",ariaLabel:"Default model for new chats",className:or,onChange:c=>{if(!c){o("","");return}o(c.providerId,c.modelId)}})})]})}):null},gf=e=>{const[s,n]=i.useState(""),[r,o]=i.useState(void 0);i.useEffect(()=>{if(!e){n(""),o(void 0);return}n(e.label??""),o(e.defaultModel)},[e]);const a=i.useMemo(()=>fc(r),[r]),l=!!e&&(s.trim()!==(e?.label??"").trim()||(r??void 0)!==(e?.defaultModel??void 0)),c=i.useCallback((d,f)=>{o(d&&f?`${d}/${f}`:void 0)},[]),u=i.useCallback(async()=>{if(!e)return null;const d=s.trim();return d?{label:d,defaultModel:r??null}:null},[r,s,e]);return{name:s,setName:n,defaultModel:r,parsedDefaultModel:a,handleDefaultModelChange:c,hasChanges:l,prepareSaveData:u,project:e}},bf=450,xf=(e,s)=>{const{hasChanges:n,name:r,defaultModel:o,prepareSaveData:a}=e,l=i.useRef(!1);i.useEffect(()=>{if(!n||!r.trim()||l.current)return;const c=window.setTimeout(()=>{l.current||(l.current=!0,(async()=>{try{const u=await a();if(u)try{await s(u)}catch{ie.error("Failed to save project settings")}}finally{l.current=!1}})())},bf);return()=>{window.clearTimeout(c)}},[o,n,r,s,a])},yf=({project:e,onIdentitySave:s})=>{const n=gf(e),r=i.useMemo(()=>e?{id:e.id,path:e.path}:null,[e]),o=i.useCallback(async a=>{await s(a)},[s]);return xf(n,o),!e||!r?null:t.jsxs("div",{className:"space-y-0",children:[t.jsx(mf,{form:n}),t.jsx(ff,{projectRef:r})]})};function Zr({...e}){return t.jsx($i,{...e})}function eo({...e}){return t.jsx(Gi,{...e})}function to({className:e,positionerClassName:s,children:n,style:r,...o}){return t.jsx(Ki,{children:t.jsx(Wi,{className:_("app-region-no-drag z-50",s),children:t.jsx(Hi,{"data-slot":"dropdown-menu-content",style:{color:"var(--surface-elevated-foreground)",...r},className:_(Si,e),...o,children:n})})})}function Ms({className:e,...s}){return t.jsx(Yi,{className:_(ji,e),...s})}function ma({className:e,...s}){return t.jsx(Qi,{className:_(ki,e),...s})}const Cn=100;function _g(){const e=ce(w=>w.isArchivePageOpen),s=ce(w=>w.setArchivePageOpen),n=ce(w=>w.setActiveMainTab),r=Ie(w=>w.setCurrentSession),o=Ie(w=>w.unarchiveSession),a=Os(w=>w.homeDirectory),l=kr({archived:!0}),[c,u]=i.useState(""),[d,f]=i.useState(null),[h,b]=i.useState(Cn),m=c.trim().toLowerCase(),g=i.useMemo(()=>e?[...l].sort((w,k)=>(k.time?.archived??0)-(w.time?.archived??0)):[],[l,e]),p=i.useMemo(()=>{const w=new Map;for(const k of g){const R=Ce(sn(k))??"",P=w.get(R);if(P){P.sessions.push(k);continue}w.set(R,{directory:R,label:R?Ls(R,a)||R:"other projects",sessions:[k]})}return[...w.values()].sort((k,R)=>R.sessions.length-k.sessions.length)},[a,g]),v=i.useMemo(()=>m?g.filter(w=>(w.title??"").toLowerCase().includes(m)):d===null?g:p.find(w=>w.directory===d)?.sessions??[],[p,m,d,g]),x=v.slice(0,h),I=v.length-x.length,y=l.length,C=i.useCallback(w=>{f(w),b(Cn)},[]),N=i.useCallback(w=>{const k=Ce(sn(w));r(w.id,k??void 0),n("chat"),s(!1)},[n,r,s]),A=i.useCallback(w=>{o(w.id).then(k=>{k?ie.success("Session restored"):ie.error("Failed to restore session")})},[o]);if(!e)return null;const j=(w,k,R,P,T,F,B)=>t.jsxs("div",{className:"group/dir relative",children:[t.jsxs("button",{type:"button",onClick:T,title:F,className:_("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",B?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",P?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),t.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:R})]}),B?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>xs.requestDelete({sessions:B,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete all archived sessions in ${k}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),t.jsx(Ge,{side:"bottom",sideOffset:4,children:"Delete all archived sessions in this project"})]}):null]},w);return t.jsx(Ud,{open:e,onOpenChange:s,children:t.jsxs(zd,{children:[t.jsx($d,{className:"fixed inset-0 z-50 bg-black/25 dark:bg-black/40 transition-opacity duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0"}),t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 max-[640px]:p-2 pointer-events-none",children:t.jsxs(Gd,{className:"pointer-events-auto relative flex h-[min(84vh,720px)] max-h-[calc(100dvh-2rem)] w-[min(92vw,960px)] flex-col overflow-hidden rounded-2xl border border-border/80 bg-background shadow-2xl transition-all duration-150 data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 max-[640px]:h-[calc(100dvh-1rem)] max-[640px]:max-h-none max-[640px]:w-[calc(100vw-1rem)] max-[640px]:rounded-xl",children:[t.jsx(Kd,{className:"sr-only",children:"Archived sessions"}),t.jsx(Wd,{className:"sr-only",children:"Browse and restore archived sessions."}),t.jsx(Hd,{"aria-label":"Close archived sessions",className:"absolute right-3 top-3 z-10 inline-flex size-8 items-center justify-center rounded-md bg-background/80 text-muted-foreground backdrop-blur-sm hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:t.jsx(D,{name:"close",className:"size-4"})}),t.jsxs("div",{className:"flex min-h-0 flex-1",children:[t.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50 max-[640px]:w-40",children:t.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[j("__all__","All directories",y,d===null,()=>C(null)),p.map(w=>j(w.directory||"__none__",w.label,w.sessions.length,d===w.directory,()=>C(w.directory),w.directory||void 0,w.sessions))]})}),t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pr-12 pt-3",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(D,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx("input",{value:c,onChange:w=>{u(w.target.value),b(Cn)},placeholder:"Search archived sessions",className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:v.length===1?`${v.length} archived session`:`${v.length} archived sessions`})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-3",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-0.5",children:[x.length===0?t.jsx("div",{className:"py-10 text-center text-muted-foreground",children:t.jsx("p",{className:"typography-ui-label font-semibold",children:m?"No matching archived sessions":"No archived sessions"})}):x.map(w=>{const k=Ce(sn(w))??"",R=k?Ls(k,a)||k:null;return t.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>N(w),role:"button",tabIndex:0,onKeyDown:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),N(w))},children:[t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:as(w)}),m&&R?t.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:k,children:R}):null,t.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Dd(w.time?.archived??w.time?.updated??w.time?.created??Date.now())}),t.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A(w)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Restore ${as(w)}`,children:t.jsx(D,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),xs.requestDelete({sessions:[w],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete ${as(w)}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},w.id)}),I>0?t.jsx("button",{type:"button",onClick:()=>b(w=>w+Cn),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show more sessions"}):null]})})]})]})]})})]})})}const wf=e=>{if(!e||typeof e!="object")return{percent:0,hasInput:!1};const s=e.input??0,n=e.cache&&typeof e.cache=="object"?e.cache.read??0:0,r=e.cache&&typeof e.cache=="object"?e.cache.write??0:0,o=s+n+r;if(o<=0)return{percent:0,hasInput:!1};const a=Math.max(0,n);return{percent:Math.min(100,Math.max(0,a/o*100)),hasInput:!0}},vf=e=>{if(!e||typeof e!="object")return 0;const s=typeof e.input=="number"&&Number.isFinite(e.input)&&e.input>=0?e.input:0,n=typeof e.cacheRead=="number"&&Number.isFinite(e.cacheRead)&&e.cacheRead>=0?e.cacheRead:0,r=typeof e.cacheWrite=="number"&&Number.isFinite(e.cacheWrite)&&e.cacheWrite>=0?e.cacheWrite:0;return s+n+r},Gt=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,Sf=e=>{if(!e||typeof e!="object")return null;const s=Gt(e.input),n=Gt(e.output),r=Gt(e.cacheRead),o=Gt(e.cacheWrite);return{input:s,output:n,reasoning:null,cacheRead:r,cacheWrite:o,total:s+n+r+o}},Ko=e=>{const s=Sf(e.info.usage);if(s)return s;const n=e.info.tokens,r=n!==void 0?n:e.parts.find(f=>f.tokens!==void 0)?.tokens;if(typeof r=="number")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:Gt(r)};if(!r||typeof r!="object")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0};const o=r,a=Gt(o.input),l=Gt(o.output),c=Gt(o.reasoning),u=Gt(o.cache?.read),d=Gt(o.cache?.write);return{input:a,output:l,reasoning:c,cacheRead:u,cacheWrite:d,total:a+l+c+u+d}},ga=380,ir=8,jf=140;function kf({open:e,onClose:s,anchorRef:n,closeOnWheel:r=!1}){const o=i.useRef(null),a=i.useRef(null),[l,c]=i.useState(e),[u,d]=i.useState(!1),[f,h]=i.useState(null),{enabled:b}=Wr();return i.useLayoutEffect(()=>{if(!e||!b||!l)return;const m=()=>{const v=n.current?.getBoundingClientRect(),x=a.current?.getBoundingClientRect();if(!v||!x){h(null);return}const I=v.left-x.left;h(Math.min(Math.max(I,ir),Math.max(ir,x.width-ga-ir)))};m();const g=a.current;if(typeof ResizeObserver>"u"||!g)return;const p=new ResizeObserver(m);return p.observe(g),()=>p.disconnect()},[n,b,e,l]),i.useEffect(()=>{if(e){c(!0),d(!1);return}if(!l)return;d(!0);const m=window.setTimeout(()=>{c(!1),d(!1)},jf);return()=>window.clearTimeout(m)},[e,l]),i.useEffect(()=>{if(!e)return;const m=g=>{g.key==="Escape"&&s()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[s,e]),i.useEffect(()=>{if(!e)return;const m=g=>{const p=g.target;if(!(p instanceof Node)){s();return}o.current?.contains(p)||n.current?.contains(p)||s()};return document.addEventListener("pointerdown",m,!0),r&&document.addEventListener("wheel",m,!0),()=>{document.removeEventListener("pointerdown",m,!0),r&&document.removeEventListener("wheel",m,!0)}},[n,r,s,e]),{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:u,anchorLeft:f,isPopover:b&&f!==null}}const Wo=(e,s)=>{if(!e||typeof e!="object")return;const n=e[s];return typeof n=="number"&&Number.isFinite(n)?n:void 0},_n=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),An=({icon:e,iconNode:s,label:n,children:r})=>t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:s??(e?t.jsx(D,{name:e,className:"size-[18px]"}):null)}),t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:n}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:r})]}),Cf=({open:e,onClose:s,anchorRef:n,contextDisplay:r})=>{const{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:c,anchorLeft:u,isPopover:d}=kf({open:e,onClose:s,anchorRef:n,closeOnWheel:!0});return l?t.jsxs("div",{ref:a,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[t.jsx("div",{ref:o,role:"tooltip","aria-label":"Context usage for current conversation",className:_("overflow-y-auto overscroll-contain rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)] will-change-transform",d?"absolute origin-top-left":"mx-3 mt-2",c?"pointer-events-none":"pointer-events-auto"),style:{animation:`${c?"session-metadata-out":"session-metadata-in"} ${c?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...d?{top:8,left:u??8,width:`min(${ga}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsxs(t.Fragment,{children:[t.jsx(An,{iconNode:t.jsx(Ci,{percentage:r.percentage}),label:"Context",children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:_("font-semibold",r.colorClass),children:[r.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:r.tokens})]})}),r.cacheRead!==null&&r.cacheWrite!==null?t.jsxs(t.Fragment,{children:[t.jsx(An,{icon:"stack",label:"Cache read",children:t.jsx("span",{className:"tabular-nums",children:_n(r.cacheRead)})}),t.jsx(An,{icon:"edit",label:"Cache write",children:t.jsx("span",{className:"tabular-nums",children:_n(r.cacheWrite)})})]}):null,r.cacheHitPercent!==null?t.jsx(An,{icon:"check",label:"Cache hit",children:t.jsxs("span",{className:"tabular-nums",children:[r.cacheHitPercent.toFixed(1),"%"]})}):null]}):t.jsx("div",{className:"px-2.5 py-2 typography-meta text-muted-foreground",children:"Context usage is not available for this conversation yet."})})}),t.jsx("style",{children:`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-C3PSe3Mq.js","assets/useAppFontEffects-BH5qeSfx.js","assets/index-CrqlVJXp.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BXgR2dKM.css","assets/vendor-base-ui-C60wdVnS.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-Bkw82kL9.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-KLmnYDaG.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-C9kx2zfD.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-BhPKX-r-.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/computeVirtualFileMetrics-DPPmLfoR.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.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/isFilePlainText-BQ-Wnk8C.js","assets/isDiffPlainText-Djb-erNZ.js","assets/vendor-diff-C3JhlQdm.js","assets/vendor-lru_map-Cy8fTs3_.js","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/vendor-capacitor-keyboard-CYccoJjr.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/SessionSwitcherDropdown-Cw_g3ai3.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as is}from"./vendor-vite-runtime-DD1OZmLC.js";import{r as Re,j as t,R as i,b as Zl}from"./vendor-react-B5Z1Mdn3.js";import{aP as Ps,aQ as ec,Q as tc,a1 as Mt,a2 as ze,a3 as $e,a4 as Ft,B as Me,I as D,a5 as Ge,a6 as Ot,a8 as tt,t as ie,a as dt,e as Ie,Z as Us,ad as ln,aR as yi,af as Kt,ag as Wt,ah as ls,ai as es,aj as cs,ak as Ss,aF as xs,aS as ys,g as Es,aT as sr,aU as ko,aV as Co,aW as tn,o as wi,ae as ps,aX as Ao,a7 as ws,aY as Sr,aZ as sc,a_ as nc,a$ as rc,b0 as oc,b1 as ic,b2 as jr,b3 as ac,x as $t,b4 as lc,b5 as cc,b6 as dc,b7 as vi,b8 as uc,b9 as fc,ba as Si,bb as ji,bc as ki,aC as kr,r as sn,m as Wr,ao as hc,ay as pc,aB as Ci,K as js,d as Hr,aa as zs,ax as Ai,bd as Wn,be as No,bf as ct,aD as Ni,bg as Ii,at as mc,f as Ri,i as gc,bh as bc,h as xc,bi as Is,b as Io,c as yc,bj as wc,u as vc,aE as Sc,aH as jc,bk as Cr,bl as kc,bm as Cc,aG as Ac,bn as Nc,bo as Ic,T as Rc,a9 as vs,al as Di,v as Dc,ab as Ec,bp as Pc,bq as Tc,j as Mc,br as Fc,bs as Ei,bt as Oc,bu as Lc,bv as Bc,bw as _c,bx as Uc,by as zc,bz as $c,bA as Gc,bB as Kc,bC as Wc}from"./useAppFontEffects-BH5qeSfx.js";import{Z as Ro,_ as Hc,$ as Do,a0 as Yc,i as Qc,a1 as qc,S as Vc,m as At,a2 as cn,b as Jc,a3 as Xc,R as Fs,a4 as Pi,a5 as Ti,a6 as Zc,a7 as ed,q as Os,K as td,a8 as sd,a9 as nd,aa as rd,ab as Vt,v as Jt,ac as od,ad as id,ae as ad,af as Yr,ag as ld,ah as cd,ai as dd,u as ce,o as _,aj as ud,B as Ce,ak as Ls,al as Tt,am as Eo,an as Ar,a as Qr,T as qr,U as Ln,ao as fd,ap as hd,aq as Mi,F as pd,Q as Fi,C as nn,ar as Nr,h as Ir,d as jn,as as md,at as gd,au as Po,av as Vs,aw as nr,ax as Rr,ay as ms,az as To,aA as Dr,aB as Oi,aC as Er,aD as bd,aE as xd,aF as yd,aG as wd,aH as vd,aI as Sd,aJ as jd,z as kd,aK as Cd,aL as Ad,Y as Li,P as Nd,J as Id}from"./index-CrqlVJXp.js";import{c as ks,d as Bi,p as Vr,u as Pr,a as Rd}from"./vendor-zustand-GVb4H8HE.js";import{g as as,b as Dd,c as _i,r as Ed,d as Ui,s as En,e as zi,h as dn,i as un,j as Pd,k as Td,l as Md,m as Mo,n as Hn,f as Fd,a as Od,S as Ld,t as Bd,o as _d}from"./SessionUnreadDot-CT5M3-qK.js";import{C as $i,a as Gi,M as Ki,b as Wi,c as Hi,d as Yi,S as Qi,D as Ud,e as zd,f as $d,g as Gd,h as Kd,i as Wd,j as Hd}from"./vendor-base-ui-C60wdVnS.js";import{c as qi,d as Tr,P as Yd,D as Vi,e as Ji,f as Qd,b as qd,a as Vd,T as Jd,M as Xd}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{u as Zd}from"./vendor-tanstack-react-virtual-2skouoFw.js";import{S as eu,v as tu,u as su}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as nu}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-xterm-xterm-CrXqRur4.js";import{usePermissionStore as ru}from"./permissionStore-iKN1K2_x.js";const ou="chat";function Xi(e){const s=new URLSearchParams;if(e.sessionId&&e.sessionId.trim().length>0&&s.set(Ps.SESSION,e.sessionId),e.isSettingsOpen){const n=e.settingsPath.trim().length>0?e.settingsPath:"home";return s.set(Ps.SETTINGS,n),s}return e.tab!==ou&&s.set(Ps.TAB,e.tab),e.tab==="diff"&&e.diffFile&&e.diffFile.trim().length>0&&s.set(Ps.FILE,e.diffFile),s}function iu(e,s){const n=typeof window<"u"?window.location.pathname:"/",r=n.startsWith("/session")||n.startsWith("/s/")?"/":n,o=e.toString();return o?`${r}?${o}`:r}function au(e){if(typeof window>"u")return!0;try{const s=new URLSearchParams(window.location.search),n=Xi(e),r=window.location.pathname.match(/^\/(?:session|s)\/([^/?#]+)/i),o=r?.[1]?decodeURIComponent(r[1].trim()):null;o&&!s.has(Ps.SESSION)&&s.set(Ps.SESSION,o);const a=[...s.entries()].sort((c,u)=>c[0].localeCompare(u[0])),l=[...n.entries()].sort((c,u)=>c[0].localeCompare(u[0]));if(a.length!==l.length)return!1;for(let c=0;c<a.length;c++)if(a[c][0]!==l[c][0]||a[c][1]!==l[c][1])return!1;return!0}catch{return!0}}function Mr(e,s={}){if(!(typeof window>"u")&&!(!s.force&&au(e)))try{const n=Xi(e),r=iu(n);s.replace?window.history.replaceState({...window.history.state,route:e},"",r):window.history.pushState({route:e},"",r)}catch{}}const lu=["typescript","javascript","tsx","jsx","json","markdown"],Zi={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Fo=null;const ea=()=>(Fo??=Promise.all([is(()=>import("./index-C3PSe3Mq.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])),is(()=>import("./workerFactory-tw7cIdmV.js"),[]),is(()=>import("./appThemeRegistry-gegrE2dq.js"),__vite__mapDeps([110,111,97,98,24,82,83,84,85,86,87,88,89,90,91,92,93,94,95]))]).then(([e,s,n])=>({WorkerPoolManager:e.WorkerPoolManager,workerFactory:s.workerFactory,ensurePierreThemeRegistered:n.ensurePierreThemeRegistered})),Fo),fn={},Oo=new Set,Fr=new Set;let Pn={light:"pierre-light",dark:"pierre-dark"};const cu=()=>{for(const e of Fr)e()},ta=(e,s)=>{s.setRenderOptions({theme:Pn,lineDiffType:Zi[e].lineDiffType})},Or=e=>{typeof window>"u"||Oo.has(e)||(Oo.add(e),ea().then(s=>{if(fn[e])return;const n=Zi[e],r=new s.WorkerPoolManager({workerFactory:s.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:lu,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),fn[e]=r,ta(e,r),cu()}))},du=e=>(Fr.add(e),()=>Fr.delete(e)),uu=e=>{if(!(Pn.light===e.light&&Pn.dark===e.dark)){Pn=e;for(const s of Object.keys(fn)){const n=fn[s];n&&ta(s,n)}}},hg=({children:e})=>{const s=ec(),n=Ro(!1),r=Ro(!0),o=s?.lightThemeId??n.metadata.id,a=s?.darkThemeId??r.metadata.id,l=s?.availableThemes.find(u=>u.metadata.id===o)??n,c=s?.availableThemes.find(u=>u.metadata.id===a)??r;return Re.useEffect(()=>{let u=!1;return ea().then(d=>{u||(d.ensurePierreThemeRegistered(l),d.ensurePierreThemeRegistered(c),uu({light:l.metadata.id,dark:c.metadata.id}))}),()=>{u=!0}},[c,l]),Re.useEffect(()=>{if(typeof window>"u")return;const u=()=>{Or("unified"),Or("split")};if(typeof window.requestIdleCallback=="function"){const f=window.requestIdleCallback(u,{timeout:5e3});return()=>window.cancelIdleCallback(f)}const d=window.setTimeout(u,2e3);return()=>window.clearTimeout(d)},[]),t.jsx(t.Fragment,{children:e})},pg=(e="unified")=>{const s=Re.useSyncExternalStore(du,()=>fn[e],()=>{});return Re.useEffect(()=>{Or(e)},[e]),s};function fu(){if(typeof window>"u")return"unknown";try{const{deviceType:e}=tc();return e}catch{return"unknown"}}function hu(){const e=typeof window<"u"?window.__PICHAMBER_ELECTRON__?.arch?.toLowerCase?.():void 0;if(e==="arm64"||e==="aarch64")return"arm64";if(e==="x64"||e==="amd64"||e==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const r=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return r.includes("aarch64")||r.includes("arm64")||r.includes("armv")?"arm64":r.includes("x86_64")||r.includes("x64")||r.includes("amd64")||r.includes("win64")?"x64":"unknown"}function pu(){const e=Jc();if(e==="android"||e==="ios")return e;if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function mu(e){const s=new URLSearchParams;return s.set("deviceClass",fu()),s.set("arch",hu()),s.set("platform",pu()),e==="desktop"?(s.set("appType","desktop-electron"),s.set("instanceMode",cn()?"local":"remote"),s):e==="mobile"?(s.set("appType","mobile-capacitor"),s.set("instanceMode","remote"),s):(s.set("appType","web"),s.set("instanceMode","unknown"),s)}async function rr(e,s){try{const n=mu(e);s&&n.set("currentVersion",s);const r=await At(`/api/pi/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"},priority:"low"});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const o=await r.json();return{available:o.available??!1,version:o.version,currentVersion:o.currentVersion??"unknown",body:o.body,releaseUrl:o.releaseUrl,downloadUrl:o.downloadUrl,nextSuggestedCheckInSec:typeof o.nextSuggestedCheckInSec=="number"&&Number.isFinite(o.nextSuggestedCheckInSec)?o.nextSuggestedCheckInSec:void 0,packageManager:o.packageManager,updateCommand:o.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function gu(){return Qc()?"mobile":qc()?"desktop":Vc()?"web":null}const Lo={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Tn=ks()((e,s)=>({...Lo,checkForUpdates:async()=>{const n=gu();if(!n)return null;e({checking:!0,error:null,runtimeType:n});try{let r=null,o=null;if(n==="desktop"){const a="0.9.8",[l,c]=await Promise.allSettled([Do(),rr("desktop",a)]),u=l.status==="fulfilled"?l.value:null;return o=c.status==="fulfilled"?c.value?.nextSuggestedCheckInSec??null:null,e({checking:!1,available:u?.available??!1,info:u,lastChecked:Date.now(),nextCheckInSec:o}),o}else n==="web"?(r=await rr("web"),o=r?.nextSuggestedCheckInSec??null):n==="mobile"&&(r=await rr("mobile","0.9.8"),o=r?.nextSuggestedCheckInSec??null);return e({checking:!1,available:r?.available??!1,info:r,lastChecked:Date.now(),nextCheckInSec:o}),o}catch(r){return e({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=s();if(!(r!=="desktop"||!n)){e({downloading:!0,error:null,progress:null});try{const o=await Do();if(!o?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(e(l=>({info:l.info?{...l.info,...o,body:l.info.body||o.body,available:l.info.available}:o})),!await Yc(l=>{e({progress:l})}))throw new Error("Desktop update only works on Local instance");e({downloading:!1,downloaded:!0})}catch(o){e({downloading:!1,error:o instanceof Error?o.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=s();if(!(r!=="desktop"||!n))try{if(!await Hc())throw new Error("Desktop restart only works on Local instance")}catch(o){e({error:o instanceof Error?o.message:"Failed to restart"})}},dismiss:()=>{e({available:!1,downloaded:!1,info:null})},reset:()=>{e(Lo)}})),bu={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3",fingerprint:"fingerprint"},xu={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function sa(e){return e&&xu[e]||"var(--primary)"}const Bo=({icon:e,className:s,colorToken:n})=>{const r=bu[e??"branch"]??"user-3";return t.jsx(D,{name:r,className:s,style:{color:sa(n)}})},yu=({activeProfile:e,identities:s,onSelect:n,isApplying:r,iconOnly:o=!1})=>{const a=r||s.length===0;return t.jsxs(Mt,{children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx(Ft,{asChild:!0,children:t.jsxs(Me,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:{color:sa(e?.color)},disabled:a,children:[r?t.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(Bo,{icon:e?.icon,colorToken:e?.color,className:"size-4"}),!o&&t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:e?.name||"No identity"}),t.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Ge,{sideOffset:8,children:"Git identity"})]}),t.jsx(Ot,{align:"end",className:"w-64",children:s.length===0?t.jsx("div",{className:"px-2 py-1.5",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:"No profiles available to apply."})}):s.map(l=>{const c=e?.id===l.id;return t.jsx(tt,{onSelect:()=>n(l),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(Bo,{icon:l.icon,colorToken:l.color,className:"size-4"}),t.jsxs("span",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:l.name}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:l.userEmail})]}),c?t.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},l.id)})})]})},wu=e=>e==="/",Bs=e=>e.replace(/\\/g,"/"),_s=e=>{if(!e||wu(e))return e;let s=e;for(;s.length>1&&s.endsWith("/");)s=s.slice(0,-1);return s},Ts=e=>e.endsWith("/"),Bn=e=>{const s=e.trim();return!s||Ts(s)?s:`${s}/`},Jr=e=>e.lastIndexOf("/"),na=e=>{if(Ts(e))return e;const s=Jr(e);return s<0?e:e.slice(0,s+1)},ra=e=>{const s=Jr(e);return e.slice(s+1)},oa=e=>{const s=_s(e.trim());if(!s||s==="~"||s==="~/"||s==="/")return null;const n=Jr(s);return n<0?null:s.startsWith("~/")&&n<=1?"~/":n===0?"/":`${s.slice(0,n)}/`},ia=e=>Ts(e)&&oa(e)!==null,vu=e=>{if(!ia(e))return null;const s=_s(e.trim());return ra(s)||s},Su=(e,s)=>`${na(e)}${s}/`,gs=e=>{if(!e)return null;const s=_s(Bs(e.trim()));return s?s.toLowerCase():null},_o=(e,s)=>{const n=e.trim();return n==="~"?s:n.startsWith("~/")?`${s}${n.slice(1)}`:n},ju=(e,s)=>{const n=_s(Bs(e.trim())),r=_s(Bs(s.trim()));if(!n)return"";if(!r)return Bn(n);if(n.toLowerCase()===r.toLowerCase())return"~/";const o=`${r}/`;return n.toLowerCase().startsWith(o.toLowerCase())?`~/${n.slice(r.length+1)}/`:Bn(n)},ku=e=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,Lr=e=>{if(!e)return;e.focus({preventScroll:!0});const s=e.value.length;e.setSelectionRange(s,s),e.scrollLeft=e.scrollWidth},Cu=async()=>Xc(),Au=()=>{const[e,s]=Re.useState(!1),[n,r]=Re.useState(!1);Re.useEffect(()=>{s(Fs()),r(Pi())},[]);const o=Re.useCallback(async c=>e?await Ti(c):{success:!0,path:c},[e]),a=Re.useCallback(async c=>e?await Zc():{success:!0},[e]),l=Re.useCallback(async c=>e?await ed():{success:!0},[e]);return{isDesktop:e,canRequestAccess:n,requestAccess:o,startAccessing:a,stopAccessing:l}};function Nu({open:e,addedProjectPaths:s,shouldSuppressAutoFocus:n}){const r=Os(se=>se.homeDirectory),{canRequestAccess:o,startAccessing:a}=Au(),l=i.useRef(null),c=i.useRef(new Map),[u,d]=i.useState(""),[f,h]=i.useState("~/"),[b,m]=i.useState([]),[g,p]=i.useState(!1),[v,x]=i.useState(!1),[I,y]=i.useState(null),[C,N]=i.useState(0),[A,j]=i.useState(0),[w,k]=i.useState(!1),[R,P]=i.useState(!1),[T,F]=i.useState("right"),B=i.useRef("~/"),G=u||r;i.useEffect(()=>{if(!e)return;h("~/"),m([]),j(0),k(!1),P(!1),B.current="~/",F("right"),n||requestAnimationFrame(()=>Lr(l.current));let se=!1;return(async()=>{const Q=await Cu();se||(d(Q||r||""),n||requestAnimationFrame(()=>Lr(l.current)))})(),()=>{se=!0}},[r,e,n]);const L=i.useMemo(()=>na(f),[f]),M=i.useMemo(()=>Ts(f)?"":ra(f),[f]),U=i.useMemo(()=>G?_o(L,G):"",[L,G]);i.useEffect(()=>{const se=B.current;se!==L&&(F(L.length>=se.length?"right":"left"),B.current=L)},[L]),i.useEffect(()=>{if(!e||!U){m([]),y(null);return}let se=!1;return p(!0),x(!1),y(null),td(U).then(de=>{if(se)return;x(!1),y(null);const Q=de.filter(me=>me.isDirectory).map(me=>({name:me.name,path:Bs(me.path)})).sort((me,Ue)=>me.name.localeCompare(Ue.name));m(Q)}).catch(de=>{if(!se){m([]);const Q=sd(de)?de.reason:"unknown";y(Q),x(Q==="not-found")}}).finally(()=>{se||p(!1)}),()=>{se=!0}},[U,C,e]);const W=i.useMemo(()=>{const se=M.toLowerCase(),de=R||M.startsWith(".");return b.filter(Q=>Q.name.toLowerCase().startsWith(se)&&(de||!Q.name.startsWith(".")))},[M,b,R]),ae=i.useMemo(()=>vu(f),[f]),q=i.useMemo(()=>oa(f),[f]),$=i.useMemo(()=>{const se=[],de=gs(U);ia(f)&&ae&&q&&se.push({type:"parent",value:"browse:up",name:ae,path:q,alreadyAdded:!!(de&&s.has(de))});for(const Q of W){const me=gs(Q.path);se.push({type:"directory",value:`browse:${Q.path}`,name:Q.name,path:Q.path,alreadyAdded:!!(me&&s.has(me))})}return se},[s,U,ae,W,q,f]);i.useEffect(()=>{j(0)},[f,$.length]);const ke=i.useMemo(()=>G?_s(_o(f,G)):"",[G,f]),ee=gs(ke),Pe=!!(ee&&s.has(ee)),_e=i.useMemo(()=>M?W.find(se=>se.name===M)??null:null,[M,W]),Y=!!(ke&&!Pe&&(I===null||I==="not-found")&&(Ts(f)&&v||!Ts(f)&&M.trim().length>0&&_e===null)),O=$[A]??null,z=!!O,J=i.useCallback(se=>{h(Bn(se))},[]),X=i.useCallback(se=>{h(Su(f,se.name))},[f]),ge=i.useCallback(se=>{if(se){if(se.type==="parent"){J(se.path);return}X(se)}},[J,X]),ve=i.useCallback(async se=>{const de=await a(se);if(!de.success)return ie.error("Failed to open directory",{description:de.error||"Desktop could not grant file access."}),!1;const Q=G?ju(se,G):Bn(Bs(se));return J(Q),!0},[J,G,a]),xe=i.useCallback(async()=>{if(!w){k(!0);try{if(Pi()){const de=await Ti(ke);if(!de.success||!de.path){de.error&&de.error!=="Directory selection cancelled"&&ie.error("Failed to select directory",{description:de.error});return}await ve(de.path);return}const se=await nd(ke);if(se.status==="cancelled")return;if(se.status!=="picked"){ie.error("Couldn't open a folder picker",{description:se.error});return}await ve(se.path)}catch(se){ie.error("Failed to select directory",{description:se instanceof Error?se.message:"Unknown error occurred."})}finally{k(!1)}}},[ve,w,ke]);return{inputRef:l,rowRefs:c,query:f,setQuery:h,isLoading:g,isBrowseDirectoryMissing:v,browseErrorReason:I,browseReloadKey:C,setBrowseReloadKey:N,highlightedIndex:A,setHighlightedIndex:j,isPickingLocation:w,showHidden:R,setShowHidden:P,folderEnterFrom:T,explorerRootDirectory:G,browseDirectoryDisplayPath:L,browseDirectoryAbsolutePath:U,browseFilterQuery:M,filteredEntries:W,rows:$,targetPath:ke,isAlreadyAdded:Pe,shouldCreateTarget:Y,highlightedRow:O,hasHighlightedBrowseItem:z,canRequestAccess:o,browseToDisplayPath:J,browseToEntry:X,executeRow:ge,applyPickedLocation:ve,handleBrowseLocation:xe}}const hs=ks()(Bi(Vr((e,s)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{e({selectedProfileId:n})},loadProfiles:async()=>{e({isLoading:!0});const n=s().profiles;try{const r=Jt()?.git,o=r?await r.getGitIdentities():await dd();return e({profiles:o,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),e({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=Jt()?.git,r=n?.getGlobalGitIdentity?await n.getGlobalGitIdentity():await cd();if(r&&r.userName&&r.userEmail){const o={id:"global",name:"Global Identity",userName:r.userName,userEmail:r.userEmail,authType:r.sshCommand?"ssh":void 0,sshKey:r.sshCommand?r.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"fingerprint"};e({globalIdentity:o})}else e({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),e({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=Jt()?.git,r=n?.discoverGitCredentials?await n.discoverGitCredentials():await ld();return e({discoveredCredentials:r}),!0}catch(n){return console.error("Failed to discover git credentials:",n),e({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const o=r.trim();return o.length>0?o:null};try{let r=null;if(r===null){const o=Jt()?.settings;if(o)try{const l=(await o.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const o=await At("/api/pi/ui-settings",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return e({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",o=r.length>0?r:"";return await Yr({defaultGitIdentityId:o}),e({defaultGitIdentityId:o.length>0?o:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};Vt("saving");const o=Jt()?.git;return o?await o.createGitIdentity(r):await ad(r),Vt("saved"),await s().loadProfiles(),!0}catch(r){return Vt("error"),console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const o=s().profiles.find(c=>c.id===n);if(!o)throw new Error("Profile not found");const a={...o,...r};Vt("saving");const l=Jt()?.git;return l?await l.updateGitIdentity(n,a):await id(n,a),Vt("saved"),await s().loadProfiles(),!0}catch(o){return Vt("error"),console.error("Failed to update git identity profile:",o),!1}},deleteProfile:async n=>{try{Vt("saving");const r=Jt()?.git;return r?await r.deleteGitIdentity(n):await od(n),Vt("saved"),s().selectedProfileId===n&&e({selectedProfileId:null}),await s().loadProfiles(),!0}catch(r){return Vt("error"),console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:o}=s();return n==="global"?o||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=s();return r.filter(o=>!n.some(a=>a.authType==="token"&&a.host===o.host))}}),{name:"git-identities-store",storage:rd(),partialize:e=>({selectedProfileId:e.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=hs);function Iu({open:e,onClose:s,isMobile:n,addedProjectPaths:r,targetPath:o,shouldCreateTarget:a,browseErrorReason:l,browseDirectoryAbsolutePath:c,isAlreadyAdded:u,isPickingLocation:d}){const f=dt(q=>q.addProject),h=ce(q=>q.setActiveMainTab),b=ce(q=>q.setSessionSwitcherOpen),m=Ie(q=>q.openNewSessionDraft),g=hs(q=>q.profiles),p=hs(q=>q.globalIdentity),v=hs(q=>q.defaultGitIdentityId),x=hs(q=>q.loadProfiles),I=hs(q=>q.loadGlobalIdentity),y=hs(q=>q.loadDefaultGitIdentityId),[C,N]=i.useState(!1),[A,j]=i.useState(!1),[w,k]=i.useState(""),[R,P]=i.useState(null);i.useEffect(()=>{e&&(N(!1),j(!1),k(""),P(null))},[e]),i.useEffect(()=>{e&&(x(),I(),y())},[y,x,I,e]);const T=i.useMemo(()=>{const q=new Map;p&&q.set(p.id,p);for(const $ of g)q.set($.id,$);return Array.from(q.values())},[g,p]);i.useEffect(()=>{if(!e||!A||R!==null)return;const q=typeof v=="string"?v.trim():"";if(q&&T.some(ke=>ke.id===q)){P(q);return}const $=T.find(ke=>ke.authType==="ssh"||ke.sshKey);$&&P($.id)},[T,v,A,e,R]);const F=i.useMemo(()=>T.find(q=>q.id===R)??null,[T,R]),B=i.useCallback((q,$)=>{h("chat"),n&&b(!1),m({selectedProjectId:q,directoryOverride:$}),s()},[n,s,m,h,b]),G=i.useCallback(async q=>{if(!q||C)return;const $=gs(q);if($&&r.has($))return;let ke=q;N(!0);try{const ee=!A&&a&&gs(q)===gs(o);if(A){const _e=w.trim();if(!_e){ie.error("Enter a repository URL before cloning.");return}const Y=await At("/api/fs/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:_e,destinationPath:q,gitIdentityId:F?.id??null})});if(!Y.ok)throw new Error("Failed to clone git repository");ke=(await Y.json()).path||q}else if(ee&&!(await At("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},query:c?{directory:c}:void 0,body:JSON.stringify({path:q})})).ok)throw new Error("Failed to select directory");const Pe=f(ke);if(!Pe){ie.error("Failed to add folder",{description:"Please select a valid directory path."});return}B(Pe.id,Pe.path)}catch(ee){ie.error("Failed to select directory",{description:ee instanceof Error?ee.message:"Unknown error occurred."})}finally{N(!1)}},[f,r,c,w,A,C,B,F?.id,a,o]),L=!C&&!d&&!u&&l!=="os-permission"&&l!=="invalid-response"&&l!=="unknown"&&!!o,M=L&&w.trim().length>0,U=A?M:L,W=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";return{isConfirming:C,isCloneMode:A,setIsCloneMode:j,cloneRemoteUrl:w,setCloneRemoteUrl:k,selectedGitIdentityId:R,setSelectedGitIdentityId:P,availableGitIdentities:T,selectedGitIdentity:F,canSubmit:U,submitActionLabel:u?"Already added":A?C?"Cloning...":"Clone & add":C?"Adding...":a?"Create & add":"Add folder",submitModifierLabel:W,finalizeSelection:G}}const Ru=({open:e,onOpenChange:s})=>{const n=dt(Q=>Q.projects),{isMobile:r,isTablet:o}=Us(),a=r||o,l=i.useMemo(()=>new Set(n.map(Q=>gs(Q.path)).filter(Q=>!!Q)),[n]),c=i.useCallback(()=>{s(!1)},[s]),{inputRef:u,rowRefs:d,query:f,setQuery:h,isLoading:b,browseErrorReason:m,setBrowseReloadKey:g,highlightedIndex:p,setHighlightedIndex:v,isPickingLocation:x,showHidden:I,setShowHidden:y,folderEnterFrom:C,browseDirectoryDisplayPath:N,browseDirectoryAbsolutePath:A,rows:j,targetPath:w,isAlreadyAdded:k,shouldCreateTarget:R,highlightedRow:P,hasHighlightedBrowseItem:T,canRequestAccess:F,executeRow:B,handleBrowseLocation:G}=Nu({open:e,addedProjectPaths:l,shouldSuppressAutoFocus:a}),{isConfirming:L,isCloneMode:M,setIsCloneMode:U,cloneRemoteUrl:W,setCloneRemoteUrl:ae,setSelectedGitIdentityId:q,availableGitIdentities:$,selectedGitIdentity:ke,canSubmit:ee,submitActionLabel:Pe,submitModifierLabel:_e,finalizeSelection:Y}=Iu({open:e,onClose:c,isMobile:r,addedProjectPaths:l,targetPath:w,shouldCreateTarget:R,browseErrorReason:m,browseDirectoryAbsolutePath:A,isAlreadyAdded:k,isPickingLocation:x});i.useLayoutEffect(()=>{const Q=u.current;Q&&(Q.scrollLeft=Q.scrollWidth)},[u,f]),i.useLayoutEffect(()=>{!e||a||Lr(u.current)},[u,e,a]),i.useLayoutEffect(()=>{const Q=j[p];Q&&d.current.get(Q.value)?.scrollIntoView({block:"nearest"})},[p,d,j]);const O=i.useCallback(Q=>{if(Q.key==="ArrowDown"){Q.preventDefault(),v(me=>Math.min(j.length-1,me+1));return}if(Q.key==="ArrowUp"){Q.preventDefault(),v(me=>Math.max(0,me-1));return}if(Q.key==="Enter"){if(Q.preventDefault(),ku(Q)){Y(w);return}T&&B(P);return}Q.key==="Backspace"&&f===""&&(Q.preventDefault(),c())},[B,Y,c,T,P,f,j.length,v,w]),z=t.jsxs("button",{type:"button",onClick:()=>y(Q=>!Q),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[I?t.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),"Show hidden"]}),J=t.jsx("div",{className:"py-1.5",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(D,{name:"folder-3",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),t.jsx(ln,{ref:u,value:f,onChange:Q=>h(Bs(Q.target.value)),onKeyDown:O,placeholder:"Enter a folder path...",className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})]}),t.jsxs(Me,{variant:"outline",size:"xs",className:"h-8 shrink-0 gap-1 px-2",disabled:L||x,onMouseDown:Q=>Q.preventDefault(),onClick:()=>{G()},title:"Browse location","aria-label":"Browse location",children:[t.jsx(D,{name:"folder-open",className:"h-3.5 w-3.5"}),x?"Opening...":"Browse"]})]})}),X=j.some(Q=>Q.type==="parent"),ge=t.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:t.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 pb-1 pt-0.5",children:[t.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:"Directories"}),t.jsxs(Me,{variant:"ghost",size:"xs",className:"h-6 shrink-0 gap-1 text-muted-foreground","aria-pressed":M,disabled:L||x,onClick:()=>U(Q=>!Q),children:[t.jsx(D,{name:"git-repository",className:"h-3.5 w-3.5"}),"Clone"]})]}),M?t.jsxs("div",{className:"mb-2 space-y-1.5 px-2 pb-1",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Clone into the folder path above."}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ln,{value:W,onChange:Q=>ae(Q.target.value),placeholder:"Repository URL (HTTPS or SSH)",className:"min-w-0 flex-1 font-mono typography-ui-label",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),t.jsx(yu,{activeProfile:ke,identities:$,onSelect:Q=>q(Q.id),isApplying:L,iconOnly:!0})]})]}):null,k?t.jsx("p",{className:"px-2 pb-2 typography-meta text-muted-foreground",children:"This folder is already added. Open a subfolder to add that instead."}):null,t.jsx("div",{className:_("mt-3","animate-in fade-in-0 duration-200 motion-reduce:animate-none",C==="left"?"slide-in-from-left-2":"slide-in-from-right-2"),children:b?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"Loading directories..."}):m&&m!=="not-found"?t.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-10 text-center",children:[t.jsx("div",{className:"typography-ui-label text-status-error",children:m==="os-permission"?"PiChamber needs access to this folder.":"Could not load this folder."}),t.jsxs("div",{className:"flex items-center gap-2",children:[m==="os-permission"&&F?t.jsx(Me,{size:"xs",onClick:()=>{G()},disabled:x,children:"Grant access"}):null,t.jsx(Me,{variant:"outline",size:"xs",onClick:()=>g(Q=>Q+1),children:"Try again"})]})]}):j.length===0?t.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:"No matching directories."}):t.jsx("div",{className:"space-y-0.5",children:j.map((Q,me)=>{const Ue=me===p,K=Q.type==="directory"&&X;return t.jsxs("button",{ref:Z=>{Z?d.current.set(Q.value,Z):d.current.delete(Q.value)},type:"button","aria-label":Q.type==="parent"?Q.alreadyAdded?`Go back from ${Q.name}, already added`:`Go back from ${Q.name}`:Q.alreadyAdded?`Open ${Q.name}, already added`:`Open ${Q.name}`,onMouseEnter:()=>v(me),onMouseDown:Z=>Z.preventDefault(),onClick:()=>B(Q),className:_("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ue&&"bg-interactive-selection text-interactive-selection-foreground",!Ue&&"hover:bg-interactive-hover/50"),children:[t.jsxs("span",{className:_("flex min-w-0 flex-1 items-center gap-2",K&&"pl-4"),children:[Q.type==="parent"?t.jsx(D,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(D,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Q.name})]}),Q.alreadyAdded?t.jsx("span",{className:_("inline-flex shrink-0 items-center rounded-md px-1.5 py-0.5 typography-meta font-medium",Ue?"bg-interactive-selection-foreground/15 text-interactive-selection-foreground":"bg-[var(--surface-muted)] text-foreground"),children:"Added"}):null,Q.type==="parent"?t.jsx(D,{name:"arrow-up-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"}):t.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"})]},Q.value)})})},N)]})}),ve=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[J,ge]}),xe=t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(D,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),"Navigate"]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Open folder"]}),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx("span",{children:_e}),t.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Add folder"]})]}),se=t.jsx(Me,{size:r?"xs":"default",onClick:()=>{Y(w)},disabled:!ee,className:_(r&&"w-full flex-1"),children:Pe}),de=()=>t.jsxs(t.Fragment,{children:[r?null:xe,t.jsx("div",{className:_("flex w-full flex-row justify-end gap-2 sm:w-auto",r&&"justify-stretch"),children:se})]});return r?t.jsx(yi,{open:e,onClose:c,title:"Add folder",className:"h-[88dvh] max-h-[720px]",contentMaxHeightClassName:"flex-1",footer:t.jsx("div",{className:"flex flex-col gap-2",children:de()}),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsx("div",{className:"flex justify-end",children:z}),ve]})}):t.jsx(Kt,{open:e,onOpenChange:s,children:t.jsxs(Wt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(ls,{className:"px-5 pb-2 pt-5",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsx(es,{children:"Add folder"}),t.jsx(cs,{className:"mt-2",children:"Choose a folder from the path above, then add it."})]}),z]})}),t.jsx("div",{className:"min-h-0 flex-1 px-5 pb-0",children:ve}),t.jsx(Ss,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:de()})]})})},kn=e=>e?t.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:e}):void 0,mg=()=>{const[e,s]=i.useState(!1),[n,r]=i.useState(null),[o,a]=i.useState(!1),l=Ie(A=>A.deleteSession),c=Ie(A=>A.deleteSessions),u=ce(A=>A.showDeletionDialog),d=ce(A=>A.setShowDeletionDialog),{isMobile:f,isTablet:h,hasTouchInput:b}=Us(),m=f||h||b;i.useEffect(()=>ud(()=>{s(!1)}),[]);const g=i.useCallback(A=>{r({sessions:A.sessions,dateLabel:A.dateLabel})},[]),p=i.useCallback(()=>{r(null),a(!1)},[]),v=i.useCallback(async A=>{if(A.sessions.length===0)return;if(A.sessions.length===1){const R=A.sessions[0];await l(R.id)?ie.success("Session deleted"):ie.error("Failed to delete session");return}const j=A.sessions.map(R=>R.id),{deletedIds:w,failedIds:k}=await c(j);if(w.length>0){const R=k.length>0?k.length===1?`${k.length} session could not be deleted.`:`${k.length} sessions could not be deleted.`:A.dateLabel?`Removed all sessions from ${A.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:kn(R)})}k.length>0&&ie.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:kn("Please try again in a moment.")})},[l,c]);i.useEffect(()=>xs.onDeleteRequest(A=>{if(!u){v(A);return}g(A)}),[g,u,v]),i.useEffect(()=>xs.onDirectoryRequest(()=>{s(!0)}),[]);const x=i.useCallback(async()=>{if(n){a(!0);try{if(n.sessions.length===1){const A=n.sessions[0];if(!await l(A.id)){ie.error("Failed to delete session"),a(!1);return}ie.success("Session deleted",{action:{label:"OK",onClick:()=>{}}})}else{const A=n.sessions.map(R=>R.id),j=await c(A),w=j.deletedIds,k=j.failedIds;if(w.length>0){const R=k.length>0?k.length===1?`${k.length} session could not be deleted.`:`${k.length} sessions could not be deleted.`:n.dateLabel?`Removed all sessions from ${n.dateLabel}.`:void 0;ie.success(w.length===1?"Deleted {count} session":`Deleted ${w.length} sessions`,{description:kn(R),action:{label:"OK",onClick:()=>{}}})}if(k.length>0&&(ie.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:kn("Please try again in a moment.")}),w.length===0)){a(!1);return}}p()}finally{a(!1)}}},[n,l,c,p]),I=n?n.sessions.length===1?n.dateLabel?`This action permanently removes 1 session from ${n.dateLabel}.`:"This action permanently removes 1 session.":n.dateLabel?`This action permanently removes ${n.sessions.length} sessions from ${n.dateLabel}.`:`This action permanently removes ${n.sessions.length} sessions.`:"",y=n?t.jsxs("div",{className:"space-y-2",children:[n.sessions.length>0&&t.jsx("div",{className:"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3",children:t.jsxs("ul",{className:"space-y-0.5",children:[n.sessions.slice(0,5).map(A=>t.jsx("li",{className:"typography-micro text-muted-foreground/80",children:t.jsx("span",{className:"truncate",children:as(A)})},A.id)),n.sessions.length>5&&t.jsx("li",{className:"typography-micro text-muted-foreground/70",children:`+${n.sessions.length-5} more`})]})}),t.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:"Worktree directories stay intact. Subsessions linked to the selected sessions will also be removed."})})]}):null,C=t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>d(!u),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!u,children:[u?t.jsx(D,{name:"checkbox-blank",className:"size-4"}):t.jsx(D,{name:"checkbox",className:"size-4 text-primary"}),"Never ask"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Me,{variant:"ghost",onClick:p,disabled:o,children:"Cancel"}),t.jsx(Me,{variant:"destructive",onClick:x,disabled:o,children:o?"Deleting…":n?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),N=n?.sessions.length===1?"Delete session":"Delete sessions";return t.jsxs(t.Fragment,{children:[m?t.jsx(yi,{open:!!n,onClose:()=>{o||p()},title:N,footer:t.jsx("div",{className:"flex justify-end gap-2",children:C}),children:t.jsxs("div",{className:"space-y-2 pb-2",children:[I&&t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:I}),y]})}):t.jsx(Kt,{open:!!n,onOpenChange:A=>{if(!A){if(o)return;p()}},children:t.jsxs(Wt,{className:"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2",children:[t.jsxs(ls,{children:[t.jsx(es,{children:N}),I&&t.jsx(cs,{children:I})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2",children:y}),t.jsx(Ss,{className:"mt-2 gap-2 pt-1 pb-1",children:C})]})}),t.jsx(Ru,{open:e,onOpenChange:s})]})},gg=()=>{const e=ys(s=>s.entries);return i.useEffect(()=>{for(const s of e.values())!s.receipt||s.notificationSent||(ys.getState().markNotificationSent(s.key),ie.success("Worktree ready",{id:`worktree-ready:${s.key}`,description:s.receipt.branch||s.receipt.path}))},[e]),null},Du=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"general",title:"General",group:"general",kind:"single",keywords:["general","startup","launch at login","autostart","tray","password","passkey","security","privacy","telemetry","transport","network","lan","binary","cli","diagnostics","performance"]},{slug:"projects",title:"Projects",group:"projects",kind:"single",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"single",keywords:["ssh","remote","instances","tunnels","forwarding","connection"]},{slug:"providers",title:"Providers",group:"agent",kind:"single",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"behavior",title:"Behavior",group:"agent",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"skills.installed",title:"Skills",group:"agent",kind:"single",keywords:["skill","skills","instructions","install","catalog"]},{slug:"git",title:"Git",group:"projects",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","oauth","prs","issues"]},{slug:"appearance",title:"Appearance",group:"general",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"dictation",title:"Dictation",group:"general",kind:"single",description:"Record speech and insert a final transcript into the composer.",keywords:["voice","speech","microphone","transcription","stt","whisper","parakeet"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"]},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"snippets",title:"Snippets",group:"agent",kind:"single",keywords:["snippet","snippets","text expansion"]},{slug:"prompt-templates",title:"Prompt templates",group:"agent",kind:"single",keywords:["prompt template","prompt templates","slash command","slash commands"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"tunnel",title:"External Tunnel",group:"projects",kind:"single",keywords:["tunnel","external","cloudflare","qr","remote","mobile","share"],isAvailable:()=>!1},{slug:"about",title:"About",group:"general",kind:"single",keywords:["about","version","updates","release","changelog","pi","pichamber","open source"]}],Eu={sessions:"sessions",skills:"skills.installed",providers:"providers","git-identities":"git",settings:"home"};function Pu(e){const s=e.trim().toLowerCase();return Du.find(n=>n.slug===s)??null}function Tu(e){const s=(e??"").trim().toLowerCase();if(!s)return"home";const n=Eu[s];if(n)return n;const r=Pu(s);return r?r.slug:"home"}function bg(e){switch(e){case"general":return"settings-3";case"projects":return"folders";case"remote-instances":return"computer";case"appearance":return"palette";case"chat":return"chat-ai-3";case"dictation":return"mic";case"snippets":return"chat-thread";case"prompt-templates":return"terminal";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"behavior":return"brain";case"skills.installed":return"book-open";case"git":return"git-branch";case"tunnel":return"home-office";case"about":return"information";case"home":return null;default:return"robot-2"}}function xg(){const e=i.useRef(!1),s=i.useRef(!1),n=Ie(f=>f.setCurrentSession),r=ce(f=>f.setActiveMainTab),o=ce(f=>f.setSettingsDialogOpen),a=ce(f=>f.setSettingsPage),l=ce(f=>f.navigateToDiff),c=i.useCallback(async f=>{if(!s.current){s.current=!0;try{if(f.sessionId){const h=Ie.getState().currentSessionId,b=Es().getState().selectedSessionId;if(f.sessionId!==h||f.sessionId!==b){const m=Ie.getState().getDirectoryForSession(f.sessionId);n(f.sessionId,m)}}if(f.settingsPath){a(Tu(f.settingsPath)),o(!0);return}ce.getState().isSettingsDialogOpen&&o(!1),f.tab&&r(f.tab),f.diffFile&&(f.tab==="diff"||!f.tab)&&l(f.diffFile)}finally{s.current=!1}}},[n,r,o,a,l]),u=i.useCallback(()=>{const f=Ie.getState(),h=Es().getState(),b=ce.getState();return{sessionId:sr({currentSessionId:f.currentSessionId,piSelectedSessionId:h.selectedSessionId,draft:f.newSessionDraft}),tab:b.activeMainTab,isSettingsOpen:b.isSettingsDialogOpen,settingsPath:b.settingsPage,diffFile:b.pendingDiffFile}},[]),d=i.useCallback((f={})=>{if(s.current)return;const h=u();Mr(h,f)},[u]);i.useEffect(()=>{if(e.current||(e.current=!0,!ko()))return;const f=Co();(async()=>(await c(f),Mr({...u(),sessionId:f.sessionId??sr({currentSessionId:Ie.getState().currentSessionId,piSelectedSessionId:Es().getState().selectedSessionId,draft:Ie.getState().newSessionDraft}),tab:f.tab??ce.getState().activeMainTab,settingsPath:f.settingsPath??ce.getState().settingsPage,diffFile:f.diffFile??ce.getState().pendingDiffFile},{replace:!0,force:!0})))()},[c,u]),i.useEffect(()=>{const f=()=>{const v=Ie.getState(),x=Es().getState();return sr({currentSessionId:v.currentSessionId,piSelectedSessionId:x.selectedSessionId,draft:v.newSessionDraft})};let h=f(),b=Ie.getState().newSessionDraft?.open===!0;const m=()=>{const v=Ie.getState(),x=f(),I=v.newSessionDraft?.open===!0;x===h&&I===b||s.current||(h=x,b=I,d({replace:!0}))},g=Ie.subscribe(()=>{m()}),p=Es().subscribe(()=>{m()});return()=>{g(),p()}},[d]),i.useEffect(()=>{let f=ce.getState().activeMainTab,h=ce.getState().isSettingsDialogOpen,b=ce.getState().settingsPage,m=ce.getState().pendingDiffFile;return ce.subscribe(p=>{if(s.current)return;const v=p.activeMainTab!==f,x=p.isSettingsDialogOpen!==h,I=p.settingsPage!==b,y=p.pendingDiffFile!==m&&p.activeMainTab==="diff";f=p.activeMainTab,h=p.isSettingsDialogOpen,b=p.settingsPage,m=p.pendingDiffFile,(v||x||I||y)&&d()})},[d]),i.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const h=Co();if(ko())c(h);else{const b=ce.getState();b.isSettingsDialogOpen&&o(!1),b.activeMainTab!=="chat"&&r("chat")}};return window.addEventListener("popstate",f),()=>{window.removeEventListener("popstate",f)}},[c,r,o])}function Mu(e=!0){const s=Tn(r=>r.checkForUpdates),n=i.useRef(s);i.useEffect(()=>{n.current=s},[s]),i.useEffect(()=>{if(!e)return;const r=3e3,o=3600*1e3,a=300*1e3,l=1440*60*1e3;let c=!1,u=null;const d=h=>{const b=Math.round(h*1e3);return Math.max(a,Math.min(l,b))},f=h=>{c||(u=window.setTimeout(async()=>{const b=await n.current(),m=typeof b=="number"&&Number.isFinite(b)?d(b):o;f(m)},h))};return f(r),()=>{c=!0,u!==null&&window.clearTimeout(u)}},[e])}function yg(){const e=tn(s=>s.connection==="ready",void 0,"chrome");return Mu(e),null}const Uo=12,Fu=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],Ou=({isActive:e,burstKey:s=0,className:n,durationMs:r=900,bursts:o=Fu,onComplete:a})=>{const l=Re.useRef(!1);Re.useEffect(()=>{!e&&l.current&&a?.(),e&&(l.current=!0)},[e,a]);const c=Re.useMemo(()=>Array.from({length:Uo},(u,d)=>{const f=Math.PI*2*d/Uo;return{x:Math.cos(f),y:Math.sin(f),delay:d*18}}),[]);return e?t.jsx("div",{className:_("fireworks-overlay pointer-events-none",n),"aria-hidden":"true","data-burst-key":s,children:o.map(u=>{const d={"--burst-delay":`${u.delay}ms`,"--burst-x":`${u.x}%`,"--burst-y":`${u.y}%`,"--firework-color":`var(${u.colorVar})`,"--firework-duration":`${r}ms`};return t.jsx("div",{className:"firework-burst",style:d,children:c.map((f,h)=>{const b=f.x*u.radius,m=f.y*u.radius,g={"--translate-x":`${b}px`,"--translate-y":`${m}px`,"--particle-delay":`${f.delay}ms`,color:`var(${u.colorVar})`};return t.jsx("span",{className:"firework-particle",style:g},`${u.id}-${h}-${s}`)})},`${u.id}-${s}`)})}):null},Lu=({durationMs:e=3400}={})=>{const[s,n]=Re.useState({isActive:!1,cycle:0}),r=Re.useRef(null),o=Re.useCallback(()=>{r.current&&(window.clearTimeout(r.current),r.current=null)},[]),a=Re.useCallback(()=>{o(),n(c=>c.isActive?{...c,isActive:!1}:c)},[o]),l=Re.useCallback(()=>{o(),n(c=>({isActive:!0,cycle:c.cycle+1})),r.current=window.setTimeout(()=>{n(c=>c.isActive?{...c,isActive:!1}:c),r.current=null},e)},[o,e]);return Re.useEffect(()=>()=>o(),[o]),{isActive:s.isActive,burstKey:s.cycle,triggerFireworks:l,dismissFireworks:a}},aa=i.createContext(void 0),wg=({children:e})=>{const{isActive:s,burstKey:n,triggerFireworks:r,dismissFireworks:o}=Lu(),a=i.useMemo(()=>({triggerFireworks:r,dismissFireworks:o}),[r,o]);return t.jsxs(aa.Provider,{value:a,children:[e,t.jsx(Ou,{isActive:s,burstKey:n})]})},Bu={triggerFireworks:()=>{},dismissFireworks:()=>{}},vg=()=>i.useContext(aa)??Bu,zo="https://github.com/RyderAsKing/PiChamber/releases";function _u(e){const s=new Date(`${e}T00:00:00`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric"}).format(s)}function Uu(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function $o(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function zu(e,s){const n=e.split(".").map(o=>Number.parseInt(o,10)),r=s.split(".").map(o=>Number.parseInt(o,10));for(let o=0;o<3;o+=1){const a=Number.isFinite(n[o])?n[o]:0,l=Number.isFinite(r[o])?r[o]:0;if(a!==l)return l-a}return 0}function $u(e){const s=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=s.exec(e))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((o,a)=>{const l=n[a+1]?.start??e.length,c=e.slice(o.start,l).trim();return{version:o.version,date:o.date,start:o.start,end:l,raw:c}})}const Go=2e3,Gu=600*1e3;async function Ku(){try{const e=await At("/api/pi/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return e.ok?{success:!0,autoRestart:(await e.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await e.json().catch(()=>({}))).error||`Server error: ${e.status}`}}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Wu(){try{return(await At("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function Hu(e,s=Math.ceil(Gu/Go),n=Go){for(let r=0;r<s;r++){try{const o=await At("/api/pi/update-check",{method:"GET",headers:{Accept:"application/json"}});if(o.ok){const a=await o.json().catch(()=>null);if(a&&a.available===!1||a&&typeof a.currentVersion=="string"&&typeof e=="string"&&a.currentVersion!==e)return!0}else if((o.status===401||o.status===403)&&await Wu())return!0}catch{}await new Promise(o=>setTimeout(o,n))}return!1}const la=({open:e,onOpenChange:s,info:n,downloading:r,downloaded:o,progress:a,error:l,onDownload:c,onRestart:u,runtimeType:d="desktop"})=>{const[f,h]=Re.useState(!1),[b,m]=Re.useState("idle"),[g,p]=Re.useState(null),v=n?.version?n.releaseUrl||`${zo}/tag/v${n.version}`:zo,x=n?.downloadUrl||v,I=a?.total?Math.round(a.downloaded/a.total*100):0,y=d==="web",C=d==="mobile",N=n?.updateCommand||"pichamber update";Re.useEffect(()=>{e||(m("idle"),p(null))},[e]);const A=async()=>{(await ws(N)).ok&&(h(!0),setTimeout(()=>h(!1),2e3))},j=Re.useCallback(async T=>{await wi(T)},[]),w=Re.useCallback(async()=>{m("updating"),p(null);const T=await Ku();if(!T.success){m("error"),p(T.error||"Update failed");return}T.autoRestart&&(m("restarting"),await new Promise(B=>setTimeout(B,2e3))),m("reconnecting"),await Hu(n?.currentVersion)?window.location.reload():(m("error"),p("Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update"))},[n?.currentVersion]),k=Re.useCallback(()=>{j(x)},[j,x]),R=b!=="idle"&&b!=="error",P=Re.useMemo(()=>{if(!n?.body)return null;const T=n.body.trim();if(!T)return null;const F=$u(T);return F.length===0?{kind:"raw",title:"What's new",content:$o(T)}:{kind:"sections",title:"What's new",sections:[...F].sort((G,L)=>zu(G.version,L.version)).map(G=>({version:G.version,dateLabel:_u(G.date),content:$o(Uu(G.raw)||T)}))}},[n?.body]);return t.jsx(Kt,{open:e,onOpenChange:R?void 0:s,children:t.jsxs(Wt,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(es,{className:"flex items-center gap-2.5",children:[t.jsx(D,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:b==="restarting"||b==="reconnecting"?"Updating PiChamber...":"Update Available"})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[y&&R&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(D,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&"Installing update...",b==="restarting"&&"Server restarting...",b==="reconnecting"&&"Waiting for server..."]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"The page will reload automatically when the update is complete."})]}),P&&!R&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(ps,{className:"max-h-[400px] p-0",fillContainer:!1,children:P.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:T=>{const B=T.target.closest("a");B&&B.href&&(T.preventDefault(),T.stopPropagation(),j(B.href))},children:t.jsx(Ao,{content:P.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:P.sections.map(T=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",T.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:T.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:F=>{const G=F.target.closest("a");G&&G.href&&(F.preventDefault(),F.stopPropagation(),j(G.href))},children:t.jsx(Ao,{content:T.content,disableLinkSafety:!0,enableFileReferences:!1})})]},T.version))})})}),y&&b==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(D,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:"Or update via terminal:"})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:N}),t.jsx("button",{onClick:A,className:_("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",f&&"text-[var(--status-success)]"),title:f?"Copied!":"Copy command",children:f?t.jsx(D,{name:"check",className:"h-4 w-4"}):t.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&!C&&r&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Downloading update payload..."}),t.jsxs("span",{className:"font-mono text-foreground",children:[I,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${I}%`}})})]}),(l||g)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:l||g})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!C&&!o&&!r&&t.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"download",className:"h-4 w-4"}),"Download Update"]}),!y&&!C&&r&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),"Downloading..."]}),!y&&!C&&o&&t.jsxs("button",{onClick:u,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"restart",className:"h-4 w-4"}),"Restart to Update"]}),C&&t.jsxs(Me,{onClick:k,size:"default",children:[t.jsx(D,{name:"external-link",className:"h-4 w-4"}),"Open update"]}),y&&!R&&t.jsxs("button",{onClick:w,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(D,{name:"download",className:"h-4 w-4"}),"Update Now"]}),y&&R&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),"Updating..."]})]})]})]})})},Yu=i.memo(function({checked:s,onChange:n,disabled:r=!1,ariaLabel:o,className:a,iconClassName:l}){const c=i.useCallback(d=>{d.preventDefault(),d.stopPropagation(),!r&&!s&&n()},[s,r,n]),u=i.useCallback(d=>{(d.key===" "||d.key==="Enter")&&(d.preventDefault(),!r&&!s&&n())},[s,r,n]);return t.jsx("button",{type:"button",role:"radio",onClick:c,onKeyDown:u,disabled:r,"aria-checked":s,"aria-label":o,className:_("group/radio relative flex h-[14px] w-[14px] min-h-[14px] min-w-[14px] shrink-0 self-center items-center justify-center rounded-full outline-none","transition-[background-color,box-shadow] duration-200 ease-out",s?"bg-[color-mix(in_srgb,var(--primary-base)_80%,transparent)] shadow-none hover:bg-[var(--primary-base)]":"bg-[var(--surface-muted)] shadow-[inset_0_0_0_1px_var(--interactive-border)] hover:bg-[var(--interactive-hover)]","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50",a),children:t.jsx("span",{"aria-hidden":!0,className:_("block h-[5px] w-[5px] rounded-full bg-white",!s&&"opacity-0",l)})})}),hn=({children:e,className:s,contentClassName:n})=>{const[r,o]=i.useState(!1),a=i.useRef(null);return i.useEffect(()=>{if(!r)return;const l=c=>{const u=a.current;u&&c.target instanceof Node&&u.contains(c.target)||o(!1)};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[r]),t.jsxs(ze,{open:r,onOpenChange:o,children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{ref:a,type:"button","aria-label":"More information","aria-expanded":r,onClick:l=>{l.preventDefault(),l.stopPropagation(),o(c=>!c)},className:_("inline-flex h-5 w-5 shrink-0 cursor-help items-center justify-center rounded text-muted-foreground/60 hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",s),children:t.jsx(D,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Ge,{sideOffset:8,className:_("max-w-sm",n),children:e})]})},Sg="w-full min-w-40 max-w-48",jg="settings",Qu="w-full min-w-40 max-w-48",kg="h-8 w-8 px-0 text-muted-foreground hover:text-foreground",qu="w-full max-w-[24rem]",Cg="min-w-0 flex-1",Ag="flex w-full min-w-0 items-center gap-2",Ng="typography-meta shrink-0 text-muted-foreground tabular-nums",ca="space-y-3.5",Vu="space-y-1.5",Ig="typography-settings-page-title text-muted-foreground",Ju="typography-settings-section-title text-foreground",da="typography-settings-group-title text-foreground",Xr="typography-settings-field-label text-foreground",Xu="typography-settings-description text-muted-foreground",pn="typography-meta text-muted-foreground",Rg="typography-meta font-medium text-foreground",Dg="typography-settings-section-title text-foreground",Zu=({title:e,description:s,titleAccessory:n,info:r,headerAction:o,children:a,divider:l=!0,className:c,contentClassName:u,settingsItem:d})=>{const f=e!=null||s!=null||o!=null||r!=null;return t.jsxs("section",{"data-settings-item":d,className:_("space-y-4",l?"border-t border-border/60 py-6":"pb-6",c),children:[f?t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[e!=null?t.jsxs("div",{className:"flex items-center gap-2",children:[typeof e=="string"||typeof e=="number"?t.jsx("h2",{className:Ju,children:e}):e,n,r!=null?t.jsx(hn,{children:r}):null]}):null,s!=null?t.jsx("div",{className:Xu,children:s}):null]}),o?t.jsx("div",{className:"shrink-0",children:o}):null]}):null,t.jsx("div",{className:_(u),children:a})]})},Eg=({children:e,className:s})=>t.jsx("div",{className:_("grid grid-cols-1 gap-6 @3xl:grid-cols-2 @3xl:gap-10",s),children:e}),ef=({children:e,className:s,as:n="h3"})=>t.jsx(n,{className:_(da,s),children:e}),Pg=({title:e,description:s,info:n,children:r,className:o,contentClassName:a,settingsItem:l})=>t.jsxs("div",{"data-settings-item":l,className:_("space-y-2",o),children:[e!=null||s!=null||n!=null?t.jsxs("div",{className:"space-y-0.5",children:[e!=null?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(ef,{children:e}),n!=null?t.jsx(hn,{children:n}):null]}):null,s!=null?t.jsx("p",{className:pn,children:s}):null]}):null,t.jsx("div",{className:_(a),children:r})]}),rn=({label:e,description:s,info:n,descriptionPlacement:r="before",children:o,settingsItem:a,className:l,controlClassName:c})=>{const u=s!=null?t.jsx("p",{className:pn,children:s}):null;return t.jsxs("div",{"data-settings-item":a,className:_("space-y-2",l),children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:Xr,children:e}),n!=null?t.jsx(hn,{children:n}):null]}),r==="before"?u:null]}),t.jsx("div",{className:_("flex min-w-0 max-w-[24rem] items-center gap-2",c),children:o}),r==="after"?u:null]})},Tg=({label:e,description:s,info:n,children:r,settingsItem:o,className:a,controlClassName:l,alignEnd:c=!0})=>t.jsxs("div",{"data-settings-item":o,className:_("flex flex-col gap-2 py-0.5 @xl:flex-row @xl:items-center @xl:gap-8",a),children:[t.jsxs("div",{className:"min-w-0 @xl:w-56 @xl:shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:Xr,children:e}),n!=null?t.jsx(hn,{children:n}):null]}),s!=null?t.jsx("p",{className:_(pn,"mt-0.5"),children:s}):null]}),t.jsx("div",{className:_("flex min-w-0 flex-1 items-center gap-2 @xl:w-fit @xl:flex-none",c&&"@xl:justify-end",l),children:r})]}),Mg=({children:e,className:s,settingsItem:n})=>t.jsx("div",{"data-settings-item":n,className:_("pt-4",s),children:e}),tf=({checked:e,onChange:s,label:n,description:r,disabled:o=!1,ariaLabel:a,settingsItem:l,className:c,labelAccessory:u,info:d})=>{const f=()=>{o||s(!e)},h=r!=null;return t.jsxs("div",{"data-settings-item":l,className:_("group flex cursor-pointer gap-2 py-0.5",h?"items-start":"items-center",o&&"cursor-not-allowed opacity-60",c),role:"button",tabIndex:o?-1:0,"aria-pressed":e,"aria-disabled":o||void 0,onClick:f,onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),f())},children:[t.jsx(Sr,{checked:e,onChange:s,disabled:o,ariaLabel:a}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:Xr,children:n}),u,d!=null?t.jsx(hn,{children:d}):null]}),h?t.jsx("span",{className:pn,children:r}):null]})]})},Fg=({selected:e,onSelect:s,label:n,description:r,ariaLabel:o,disabled:a=!1,className:l})=>t.jsxs("div",{className:_("flex cursor-pointer gap-2 py-0.5",r!=null?"items-start":"items-center",a&&"cursor-not-allowed opacity-60",l),role:"button",tabIndex:a?-1:0,"aria-pressed":e,"aria-disabled":a||void 0,onClick:()=>{a||s()},onKeyDown:c=>{(c.key===" "||c.key==="Enter")&&(c.preventDefault(),a||s())},children:[t.jsx(Yu,{checked:e,onChange:s,disabled:a,ariaLabel:o,className:r!=null?"mt-0.5":void 0}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:_("typography-settings-field-label font-normal",e?"text-foreground":"text-foreground/50"),children:n}),r!=null?t.jsx("span",{className:pn,children:r}):null]})]}),Og=({"aria-label":e,children:s,className:n})=>t.jsx("div",{role:"radiogroup","aria-label":e,className:_(Vu,n),children:s});function Lg({value:e,options:s,onChange:n,className:r,"aria-label":o}){return t.jsx("div",{role:"group","aria-label":o,className:_("flex flex-wrap items-center gap-1",r),children:s.map(a=>t.jsx(Me,{type:"button",variant:"chip",size:"xs",disabled:a.disabled,"aria-pressed":e===a.value,className:"!font-normal",onClick:()=>n(a.value),children:a.label},a.value))})}class sf extends i.Component{constructor(s){super(s),this.state={hasError:!1}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}componentDidCatch(s,n){this.setState({error:s,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(sc,{className:"w-full max-w-md",children:[t.jsx(nc,{className:"text-center",children:t.jsxs(rc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(oc,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(Me,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(D,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function nf(e){return t.jsx(sf,{...e,texts:{title:"Chat Error",description:"The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data.",sessionLabel:"Session",detailsSummary:"Error details",resetAction:"Reset Chat",persistentHint:"If the problem persists, try refreshing the page."}})}const Bg=({active:e=!0})=>{const s=Ie(n=>n.currentSessionId);return t.jsx(nf,{sessionId:s||void 0,children:t.jsx(ic,{active:e},s??"no-session")})};function rf({onResizeStart:e,ariaLabel:s}){return t.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":s,onPointerDown:e,className:"pointer-events-auto -m-2 flex size-7 cursor-ns-resize items-end justify-end p-2 touch-none select-none",children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,children:t.jsx("path",{d:"M9.11111 2L2 9.11111M10 6.44444L6.44444 10",className:"stroke-muted-foreground",strokeLinecap:"round"})})})}const ua=Re.forwardRef(({className:e,outerClassName:s,scrollbarClassName:n,fillContainer:r=!1,useScrollShadow:o=!1,scrollShadowSize:a,hasError:l,resizedHeight:c,onResizeHeightChange:u,disabled:d,simple:f,endSlot:h,...b},m)=>{const g=Re.useRef(null),p=Re.useRef(null),[v,x]=Re.useState(null),I=c??v,y=Re.useCallback(N=>{const A=g.current;if(!A)return;p.current={startY:N.clientY,startHeight:A.getBoundingClientRect().height};const j=N.currentTarget;j.setPointerCapture(N.pointerId);const w=R=>{const P=p.current;if(!P)return;const T=P.startHeight+(R.clientY-P.startY),F=Math.max(82,T);u?u(F):x(F)},k=()=>{p.current=null,j.removeEventListener("pointermove",w),j.removeEventListener("pointerup",k),j.removeEventListener("pointercancel",k)};j.addEventListener("pointermove",w),j.addEventListener("pointerup",k),j.addEventListener("pointercancel",k),N.preventDefault()},[u]),C=Re.useCallback(N=>{if(N.target.closest('textarea, button, [role="separator"]'))return;const j=g.current?.querySelector("textarea");j&&document.activeElement!==j&&(N.preventDefault(),j.focus())},[]);return f?t.jsx(ps,{as:"textarea",ref:m,disableHorizontal:!0,fillContainer:r,useScrollShadow:o,scrollShadowSize:a,outerClassName:s,scrollbarClassName:n,className:_("block w-full appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","px-3 py-2 md:typography-ui-label","placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r?"[field-sizing:fixed]":"field-sizing-content",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:d,...b}):t.jsx("div",{ref:g,onPointerDown:C,style:I!==null?{height:`${I}px`}:void 0,className:_("group/textarea relative flex w-full flex-col rounded-[var(--radius-xl)] bg-[var(--surface-elevated)] pb-2.5","ring-1 ring-inset ring-border/60 transition duration-200 ease-out","hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)]","has-[[disabled]]:pointer-events-none has-[[disabled]]:bg-[var(--surface-subtle)] has-[[disabled]]:ring-transparent",!l&&["hover:[&:not(:focus-within)]:ring-transparent","focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]"],l&&["ring-[var(--status-error)]","focus-within:ring-2 focus-within:ring-[var(--status-error)]"],s),children:t.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col gap-2",children:[t.jsx("textarea",{ref:m,className:_("block w-full flex-1 min-h-0 appearance-none resize-none bg-transparent text-foreground typography-markdown outline-none","min-h-[82px] pl-3 pr-2.5 pt-2.5 md:typography-ui-label","focus-visible:outline-none disabled:cursor-not-allowed",!d&&["placeholder:select-none placeholder:text-muted-foreground placeholder:transition placeholder:duration-200 placeholder:ease-out","group-hover/textarea:placeholder:text-foreground/80","focus:placeholder:text-foreground/80"],d&&"text-muted-foreground/60 placeholder:text-muted-foreground/60",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:d,...b}),t.jsxs("div",{className:"flex items-center justify-end gap-1.5 pl-3 pr-2.5",children:[h,t.jsx(rf,{onResizeStart:y,ariaLabel:"Resize textarea"})]})]})})});ua.displayName="Textarea";const fa=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],on=Object.fromEntries(fa.map(e=>[e.key,e.Icon])),Br="pichamber:project-actions-updated",ha=e=>{const s=(e||"").trim().replace(/\\/g,"/");return s?s==="/"?"/":s.length>1?s.replace(/\/+$/,""):s:""},Xt=(e,s)=>`${ha(e)}::${s}`,pa=({title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,children:l,className:c,contentClassName:u,divider:d=!0})=>t.jsx(Zu,{title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,divider:d,className:c,contentClassName:u,children:l}),_r=e=>e.name.trim().length>0&&e.command.trim().length>0,of=e=>e.name.trim().length===0&&e.command.trim().length===0,af=e=>!_r(e)&&!of(e),lf=(e,s)=>e.some(r=>s.has(r.id)&&!_r(r))?{canPersist:!1,actions:e}:{canPersist:!0,actions:e.filter(_r)},cf=450,df=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,uf=()=>({id:df(),name:"",command:"",icon:"play"}),ff=({projectRef:e})=>{const[s,n]=i.useState([]),[r,o]=i.useState(!1),[a,l]=i.useState(null),[c,u]=i.useState(new Set),d=i.useRef(!1);i.useEffect(()=>{let x=!1;return o(!0),(async()=>{try{const I=await jr(e);if(x)return;n(I.actions),l(JSON.stringify({actions:I.actions})),u(new Set(I.actions.map(y=>y.id)))}catch{if(x)return;n([]),l(JSON.stringify({actions:[]})),u(new Set)}finally{x||o(!1)}})(),()=>{x=!0}},[e]);const f=i.useMemo(()=>lf(s,c),[s,c]),h=i.useMemo(()=>JSON.stringify({actions:f.actions}),[f.actions]),b=a!==null&&f.canPersist&&h!==a,m=i.useCallback(async x=>await ac(e,{actions:x,primaryActionId:null})?(l(JSON.stringify({actions:x})),u(new Set(x.map(y=>y.id))),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Br,{detail:{projectId:e.id}})),!0):(ie.error("Failed to save actions"),!1),[e]);i.useEffect(()=>{if(!b||r||d.current)return;const x=window.setTimeout(()=>{d.current||(d.current=!0,(async()=>{try{await m(f.actions)}finally{d.current=!1}})())},cf);return()=>{window.clearTimeout(x)}},[b,r,m,f.actions]);const g=i.useCallback(()=>{const x=uf();n(I=>[...I,x])},[]),p=i.useCallback(x=>{n(I=>I.filter(y=>y.id!==x))},[]),v=i.useCallback((x,I)=>{n(y=>y.map(C=>C.id===x?I(C):C))},[]);return t.jsx(pa,{title:"Actions",info:"Per-project commands shown in the header next to the project name.",settingsItem:"projects.actions",headerAction:t.jsxs(Me,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:[t.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),"Add action"]}),contentClassName:"space-y-4",children:r?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Loading..."}):s.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"No actions configured yet."}):t.jsx("div",{className:_("space-y-6",qu),children:s.map((x,I)=>{const y=x.icon||"play",C=on[y]||"play",N=x.name.trim()||`Action ${I+1}`,A=af(x);return t.jsxs("div",{className:ca,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:da,children:N}),t.jsx(Me,{type:"button",variant:"ghost",size:"xs",className:"h-8 w-8 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>p(x.id),"aria-label":`Delete ${N}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsxs(rn,{label:"Name",controlClassName:"w-full max-w-none",children:[t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":"Select icon",children:t.jsx(D,{name:C,className:"h-4 w-4"})})}),t.jsx(Ot,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:fa.map(j=>{const w=j.Icon,k=(x.icon||"play")===j.key;return t.jsx("button",{type:"button",onClick:()=>v(x.id,R=>({...R,icon:j.key})),className:_("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",k&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":`Icon ${j.label}`,children:t.jsx(D,{name:w,className:"h-4 w-4"})},j.key)})})})]}),t.jsx(ln,{value:x.name,onChange:j=>v(x.id,w=>({...w,name:j.target.value})),placeholder:"Action name",className:"h-8 min-w-0 flex-1 rounded-md px-3"})]}),t.jsx(rn,{label:"Command",controlClassName:"w-full max-w-none",children:t.jsx(ua,{value:x.command,onChange:j=>v(x.id,w=>({...w,command:j.target.value})),placeholder:"e.g. bun run lint",className:"min-h-[88px] w-full font-mono text-xs"})}),A?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Enter a name and command to save this action."}):null,t.jsx(tf,{checked:x.autoOpenUrl===!0,onChange:j=>v(x.id,w=>({...w,...j?{autoOpenUrl:!0}:{autoOpenUrl:void 0,openUrl:void 0}})),label:"Auto-open URL",info:"Opens a URL from command output, or a custom URL if you set one.",ariaLabel:`Auto-open URL for ${N}`}),x.autoOpenUrl===!0?t.jsx(t.Fragment,{children:t.jsx(rn,{label:"Custom URL",info:"Leave empty to use the best URL from command output.",controlClassName:"w-full max-w-none",children:t.jsx(ln,{value:x.openUrl||"",onChange:j=>v(x.id,w=>({...w,openUrl:j.target.value})),placeholder:"https://localhost:3000",className:"h-8 w-full rounded-md px-3"})})}):null]},x.id)})})})},hf={searchPlaceholder:"Search models",noResults:"No models found",favorites:"Favorites",recent:"Recent",favorite:"Favorite",unfavorite:"Unfavorite",capabilities:"Capabilities",capabilityToolCalling:"Tool calling",capabilityReasoning:"Reasoning",input:"Input",output:"Output",costPerMillion:"Cost ($/1M tokens)"},pf=({value:e,noneLabel:s,ariaLabel:n,disabled:r=!1,className:o,isModelAllowed:a,onChange:l})=>{const c=$t(w=>w.providers),u=$t(w=>w.modelsMetadata),d=ce(w=>w.hiddenModels),f=ce(w=>w.isFavoriteModel),h=ce(w=>w.toggleFavoriteModel),b=ce(w=>w.reorderFavoriteModel),{favoriteModelsList:m,recentModelsList:g}=lc(),[p,v]=i.useState(!1),[x,I]=i.useState("");i.useEffect(()=>{p||I("")},[p]);const y=e?c.find(w=>w.id===e.providerId):void 0,C=e&&y?(Array.isArray(y.models)?y.models:[]).find(w=>w.id===e.modelId):void 0,N=e?cc(C,e.modelId):s,A=i.useMemo(()=>e?d.filter(w=>!(w.providerID===e.providerId&&w.modelID===e.modelId)):d,[d,e]),j=i.useCallback(w=>{l({providerId:w.providerID,modelId:w.modelID}),v(!1)},[l]);return t.jsxs(Mt,{modal:!1,open:p,onOpenChange:w=>{r||v(w)},children:[t.jsx(Ft,{asChild:!0,disabled:r,children:t.jsxs("button",{type:"button","aria-label":n,disabled:r,className:_(vi({size:"default"}),Qu,"min-w-0",o),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e?.providerId?t.jsx(dc,{providerId:e.providerId,className:"size-4 shrink-0"}):null,t.jsx("span",{className:_("truncate",e?"text-foreground":"text-muted-foreground"),children:N})]}),t.jsx(D,{name:"arrow-down-s",className:"size-4 shrink-0"})]})}),t.jsx(Ot,{align:"start",portalToBody:!0,positionerClassName:"z-[80]",className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",children:t.jsx(uc,{providers:c,favoriteModels:m,recentModels:g,modelsMetadata:u,searchQuery:x,onSearchQueryChange:I,onSelect:j,labels:{...hf,notSelected:s},selectedModel:e?{providerID:e.providerId,modelID:e.modelId}:null,hiddenModels:A,isModelAllowed:a,includeNotSelected:!0,onSelectNone:()=>{l(null),v(!1)},disabled:r,autoFocus:!0,onEscape:()=>v(!1),isFavorite:w=>f(w.providerID,w.modelID),onToggleFavorite:w=>h(w.providerID,w.modelID),onReorderFavorite:(w,k)=>b(w.providerID,w.modelID,k.providerID,k.modelID),reorderFavoriteAriaLabel:"Reorder favorite",reorderFavoriteTitle:"Drag to reorder favorite"})})]})},or="w-full max-w-none",mf=({form:e})=>{const{name:s,setName:n,parsedDefaultModel:r,handleDefaultModelChange:o,project:a}=e,l=$t(c=>c.loadProviders);return i.useEffect(()=>{l({source:"projectSettings"})},[l]),a?t.jsx(pa,{title:"Project",divider:!1,children:t.jsxs("div",{className:ca,children:[t.jsx(rn,{label:"Name",settingsItem:"projects.name",controlClassName:or,children:t.jsx(ln,{value:s,onChange:c=>n(c.target.value),placeholder:"Project name","aria-label":"Project name",className:"h-8 w-full rounded-md px-3"})}),t.jsx(rn,{label:"Default model",info:"Used when starting a new chat in this project. Unset keeps the global session default.",settingsItem:"projects.default-model",controlClassName:or,children:t.jsx(pf,{value:r,noneLabel:"Use global default",ariaLabel:"Default model for new chats",className:or,onChange:c=>{if(!c){o("","");return}o(c.providerId,c.modelId)}})})]})}):null},gf=e=>{const[s,n]=i.useState(""),[r,o]=i.useState(void 0);i.useEffect(()=>{if(!e){n(""),o(void 0);return}n(e.label??""),o(e.defaultModel)},[e]);const a=i.useMemo(()=>fc(r),[r]),l=!!e&&(s.trim()!==(e?.label??"").trim()||(r??void 0)!==(e?.defaultModel??void 0)),c=i.useCallback((d,f)=>{o(d&&f?`${d}/${f}`:void 0)},[]),u=i.useCallback(async()=>{if(!e)return null;const d=s.trim();return d?{label:d,defaultModel:r??null}:null},[r,s,e]);return{name:s,setName:n,defaultModel:r,parsedDefaultModel:a,handleDefaultModelChange:c,hasChanges:l,prepareSaveData:u,project:e}},bf=450,xf=(e,s)=>{const{hasChanges:n,name:r,defaultModel:o,prepareSaveData:a}=e,l=i.useRef(!1);i.useEffect(()=>{if(!n||!r.trim()||l.current)return;const c=window.setTimeout(()=>{l.current||(l.current=!0,(async()=>{try{const u=await a();if(u)try{await s(u)}catch{ie.error("Failed to save project settings")}}finally{l.current=!1}})())},bf);return()=>{window.clearTimeout(c)}},[o,n,r,s,a])},yf=({project:e,onIdentitySave:s})=>{const n=gf(e),r=i.useMemo(()=>e?{id:e.id,path:e.path}:null,[e]),o=i.useCallback(async a=>{await s(a)},[s]);return xf(n,o),!e||!r?null:t.jsxs("div",{className:"space-y-0",children:[t.jsx(mf,{form:n}),t.jsx(ff,{projectRef:r})]})};function Zr({...e}){return t.jsx($i,{...e})}function eo({...e}){return t.jsx(Gi,{...e})}function to({className:e,positionerClassName:s,children:n,style:r,...o}){return t.jsx(Ki,{children:t.jsx(Wi,{className:_("app-region-no-drag z-50",s),children:t.jsx(Hi,{"data-slot":"dropdown-menu-content",style:{color:"var(--surface-elevated-foreground)",...r},className:_(Si,e),...o,children:n})})})}function Ms({className:e,...s}){return t.jsx(Yi,{className:_(ji,e),...s})}function ma({className:e,...s}){return t.jsx(Qi,{className:_(ki,e),...s})}const Cn=100;function _g(){const e=ce(w=>w.isArchivePageOpen),s=ce(w=>w.setArchivePageOpen),n=ce(w=>w.setActiveMainTab),r=Ie(w=>w.setCurrentSession),o=Ie(w=>w.unarchiveSession),a=Os(w=>w.homeDirectory),l=kr({archived:!0}),[c,u]=i.useState(""),[d,f]=i.useState(null),[h,b]=i.useState(Cn),m=c.trim().toLowerCase(),g=i.useMemo(()=>e?[...l].sort((w,k)=>(k.time?.archived??0)-(w.time?.archived??0)):[],[l,e]),p=i.useMemo(()=>{const w=new Map;for(const k of g){const R=Ce(sn(k))??"",P=w.get(R);if(P){P.sessions.push(k);continue}w.set(R,{directory:R,label:R?Ls(R,a)||R:"other projects",sessions:[k]})}return[...w.values()].sort((k,R)=>R.sessions.length-k.sessions.length)},[a,g]),v=i.useMemo(()=>m?g.filter(w=>(w.title??"").toLowerCase().includes(m)):d===null?g:p.find(w=>w.directory===d)?.sessions??[],[p,m,d,g]),x=v.slice(0,h),I=v.length-x.length,y=l.length,C=i.useCallback(w=>{f(w),b(Cn)},[]),N=i.useCallback(w=>{const k=Ce(sn(w));r(w.id,k??void 0),n("chat"),s(!1)},[n,r,s]),A=i.useCallback(w=>{o(w.id).then(k=>{k?ie.success("Session restored"):ie.error("Failed to restore session")})},[o]);if(!e)return null;const j=(w,k,R,P,T,F,B)=>t.jsxs("div",{className:"group/dir relative",children:[t.jsxs("button",{type:"button",onClick:T,title:F,className:_("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",B?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",P?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:k}),t.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:R})]}),B?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>xs.requestDelete({sessions:B,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete all archived sessions in ${k}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),t.jsx(Ge,{side:"bottom",sideOffset:4,children:"Delete all archived sessions in this project"})]}):null]},w);return t.jsx(Ud,{open:e,onOpenChange:s,children:t.jsxs(zd,{children:[t.jsx($d,{className:"fixed inset-0 z-50 bg-black/25 dark:bg-black/40 transition-opacity duration-150 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0"}),t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 max-[640px]:p-2 pointer-events-none",children:t.jsxs(Gd,{className:"pointer-events-auto relative flex h-[min(84vh,720px)] max-h-[calc(100dvh-2rem)] w-[min(92vw,960px)] flex-col overflow-hidden rounded-2xl border border-border/80 bg-background shadow-2xl transition-all duration-150 data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 max-[640px]:h-[calc(100dvh-1rem)] max-[640px]:max-h-none max-[640px]:w-[calc(100vw-1rem)] max-[640px]:rounded-xl",children:[t.jsx(Kd,{className:"sr-only",children:"Archived sessions"}),t.jsx(Wd,{className:"sr-only",children:"Browse and restore archived sessions."}),t.jsx(Hd,{"aria-label":"Close archived sessions",className:"absolute right-3 top-3 z-10 inline-flex size-8 items-center justify-center rounded-md bg-background/80 text-muted-foreground backdrop-blur-sm hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:t.jsx(D,{name:"close",className:"size-4"})}),t.jsxs("div",{className:"flex min-h-0 flex-1",children:[t.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50 max-[640px]:w-40",children:t.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[j("__all__","All directories",y,d===null,()=>C(null)),p.map(w=>j(w.directory||"__none__",w.label,w.sessions.length,d===w.directory,()=>C(w.directory),w.directory||void 0,w.sessions))]})}),t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pr-12 pt-3",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(D,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx("input",{value:c,onChange:w=>{u(w.target.value),b(Cn)},placeholder:"Search archived sessions",className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:v.length===1?`${v.length} archived session`:`${v.length} archived sessions`})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-3",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-0.5",children:[x.length===0?t.jsx("div",{className:"py-10 text-center text-muted-foreground",children:t.jsx("p",{className:"typography-ui-label font-semibold",children:m?"No matching archived sessions":"No archived sessions"})}):x.map(w=>{const k=Ce(sn(w))??"",R=k?Ls(k,a)||k:null;return t.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>N(w),role:"button",tabIndex:0,onKeyDown:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),N(w))},children:[t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:as(w)}),m&&R?t.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:k,children:R}):null,t.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Dd(w.time?.archived??w.time?.updated??w.time?.created??Date.now())}),t.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),A(w)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Restore ${as(w)}`,children:t.jsx(D,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),xs.requestDelete({sessions:[w],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":`Delete ${as(w)}`,children:t.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},w.id)}),I>0?t.jsx("button",{type:"button",onClick:()=>b(w=>w+Cn),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:"Show more sessions"}):null]})})]})]})]})})]})})}const wf=e=>{if(!e||typeof e!="object")return{percent:0,hasInput:!1};const s=e.input??0,n=e.cache&&typeof e.cache=="object"?e.cache.read??0:0,r=e.cache&&typeof e.cache=="object"?e.cache.write??0:0,o=s+n+r;if(o<=0)return{percent:0,hasInput:!1};const a=Math.max(0,n);return{percent:Math.min(100,Math.max(0,a/o*100)),hasInput:!0}},vf=e=>{if(!e||typeof e!="object")return 0;const s=typeof e.input=="number"&&Number.isFinite(e.input)&&e.input>=0?e.input:0,n=typeof e.cacheRead=="number"&&Number.isFinite(e.cacheRead)&&e.cacheRead>=0?e.cacheRead:0,r=typeof e.cacheWrite=="number"&&Number.isFinite(e.cacheWrite)&&e.cacheWrite>=0?e.cacheWrite:0;return s+n+r},Gt=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,Sf=e=>{if(!e||typeof e!="object")return null;const s=Gt(e.input),n=Gt(e.output),r=Gt(e.cacheRead),o=Gt(e.cacheWrite);return{input:s,output:n,reasoning:null,cacheRead:r,cacheWrite:o,total:s+n+r+o}},Ko=e=>{const s=Sf(e.info.usage);if(s)return s;const n=e.info.tokens,r=n!==void 0?n:e.parts.find(f=>f.tokens!==void 0)?.tokens;if(typeof r=="number")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:Gt(r)};if(!r||typeof r!="object")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0};const o=r,a=Gt(o.input),l=Gt(o.output),c=Gt(o.reasoning),u=Gt(o.cache?.read),d=Gt(o.cache?.write);return{input:a,output:l,reasoning:c,cacheRead:u,cacheWrite:d,total:a+l+c+u+d}},ga=380,ir=8,jf=140;function kf({open:e,onClose:s,anchorRef:n,closeOnWheel:r=!1}){const o=i.useRef(null),a=i.useRef(null),[l,c]=i.useState(e),[u,d]=i.useState(!1),[f,h]=i.useState(null),{enabled:b}=Wr();return i.useLayoutEffect(()=>{if(!e||!b||!l)return;const m=()=>{const v=n.current?.getBoundingClientRect(),x=a.current?.getBoundingClientRect();if(!v||!x){h(null);return}const I=v.left-x.left;h(Math.min(Math.max(I,ir),Math.max(ir,x.width-ga-ir)))};m();const g=a.current;if(typeof ResizeObserver>"u"||!g)return;const p=new ResizeObserver(m);return p.observe(g),()=>p.disconnect()},[n,b,e,l]),i.useEffect(()=>{if(e){c(!0),d(!1);return}if(!l)return;d(!0);const m=window.setTimeout(()=>{c(!1),d(!1)},jf);return()=>window.clearTimeout(m)},[e,l]),i.useEffect(()=>{if(!e)return;const m=g=>{g.key==="Escape"&&s()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[s,e]),i.useEffect(()=>{if(!e)return;const m=g=>{const p=g.target;if(!(p instanceof Node)){s();return}o.current?.contains(p)||n.current?.contains(p)||s()};return document.addEventListener("pointerdown",m,!0),r&&document.addEventListener("wheel",m,!0),()=>{document.removeEventListener("pointerdown",m,!0),r&&document.removeEventListener("wheel",m,!0)}},[n,r,s,e]),{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:u,anchorLeft:f,isPopover:b&&f!==null}}const Wo=(e,s)=>{if(!e||typeof e!="object")return;const n=e[s];return typeof n=="number"&&Number.isFinite(n)?n:void 0},_n=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),An=({icon:e,iconNode:s,label:n,children:r})=>t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:s??(e?t.jsx(D,{name:e,className:"size-[18px]"}):null)}),t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:n}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:r})]}),Cf=({open:e,onClose:s,anchorRef:n,contextDisplay:r})=>{const{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:c,anchorLeft:u,isPopover:d}=kf({open:e,onClose:s,anchorRef:n,closeOnWheel:!0});return l?t.jsxs("div",{ref:a,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[t.jsx("div",{ref:o,role:"tooltip","aria-label":"Context usage for current conversation",className:_("overflow-y-auto overscroll-contain rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)] will-change-transform",d?"absolute origin-top-left":"mx-3 mt-2",c?"pointer-events-none":"pointer-events-auto"),style:{animation:`${c?"session-metadata-out":"session-metadata-in"} ${c?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...d?{top:8,left:u??8,width:`min(${ga}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsxs(t.Fragment,{children:[t.jsx(An,{iconNode:t.jsx(Ci,{percentage:r.percentage}),label:"Context",children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:_("font-semibold",r.colorClass),children:[r.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:r.tokens})]})}),r.cacheRead!==null&&r.cacheWrite!==null?t.jsxs(t.Fragment,{children:[t.jsx(An,{icon:"stack",label:"Cache read",children:t.jsx("span",{className:"tabular-nums",children:_n(r.cacheRead)})}),t.jsx(An,{icon:"edit",label:"Cache write",children:t.jsx("span",{className:"tabular-nums",children:_n(r.cacheWrite)})})]}):null,r.cacheHitPercent!==null?t.jsx(An,{icon:"check",label:"Cache hit",children:t.jsxs("span",{className:"tabular-nums",children:[r.cacheHitPercent.toFixed(1),"%"]})}):null]}):t.jsx("div",{className:"px-2.5 py-2 typography-meta text-muted-foreground",children:"Context usage is not available for this conversation yet."})})}),t.jsx("style",{children:`
|
|
3
3
|
@keyframes session-metadata-in {
|
|
4
4
|
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
5
5
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
@@ -50,4 +50,4 @@ ${n}`:""}function Ra(e,s){const n="#".repeat(Math.min(s+1,6)),r=e.agent?` — ${
|
|
|
50
50
|
`):l.slice(0,-1).join(`
|
|
51
51
|
`);if(this.tail=a.endsWith(`
|
|
52
52
|
`)?"":(l[l.length-1]??"").slice(-1024),!c)return;const u=cm(c);if(!u||this.pendingUrls.has(u))return;const d=this.probeGeneration;this.pendingUrls.add(u),dm(u).then(f=>{if(this.pendingUrls.delete(u),!f||this.probeGeneration!==d)return;const h=pe.getState().getDirectoryState(s)?.tabs.find(b=>b.id===n);!h||h.previewUrlLocked||h.previewUrl===u||o(s,n,u,{locked:!1,autoOpened:!1})})}}const mm=(e,s)=>{if(s!=="ctrl")return null;const n=e.key,r=e.code??"",o=n.length===1&&/[a-zA-Z]/.test(n)?n.toUpperCase():r.startsWith("Key")&&r.length===4?r.slice(3).toUpperCase():null;return o&&o.length===1&&o>="A"&&o<="Z"?Oa(o):null};function gm({terminal:e,effectiveDirectory:s,activeTabId:n,terminalSessionId:r,terminalLifecycle:o,hasOpenedTerminalViewport:a,terminalHydrated:l,terminalShell:c,terminalLoginShell:u,terminalAppearanceRef:d,enableTabs:f,hasActiveContext:h,focusTerminalWhenWindowActive:b,tabs:m}){const g=pe(O=>O.ensureDirectory),p=pe(O=>O.setTabSessionId),v=pe(O=>O.setTabLifecycle),x=pe(O=>O.setConnecting),I=pe(O=>O.appendToBuffer),y=pe(O=>O.replaceBuffer),C=pe(O=>O.setTabPreviewUrl),[N,A]=i.useState(null),[j,w]=i.useState(!1),[k,R]=i.useState(!1),P=i.useRef(new Map),T=i.useRef(null),F=i.useRef(n),B=i.useRef(r),G=i.useRef(s),L=i.useRef(null),M=i.useRef(new Set),U=i.useRef(new Map),W=i.useRef(m),ae=i.useRef(l),q=i.useRef(a),$=i.useRef(e);W.current=m,ae.current=l,q.current=a,$.current=e;const ke=i.useCallback(()=>{const O=F.current;O&&U.current.get(O)?.reset()},[]);i.useEffect(()=>{B.current=r},[r]),i.useEffect(()=>{!r||!e.updateAppearance||e.updateAppearance(r,d.current).catch(()=>{})},[d,e,r]),i.useEffect(()=>{F.current=n},[n]),i.useEffect(()=>{G.current=s},[s]);const ee=i.useCallback(()=>{for(const O of P.current.values())try{O()}catch{}P.current.clear(),T.current=null,R(!1)},[]);i.useEffect(()=>()=>{ee(),B.current=null},[ee]);const Pe=i.useCallback((O,z,J)=>{let X=U.current.get(z);X||(X=new pm,U.current.set(z,X)),X.scan(O,z,J,C)},[C]),_e=i.useCallback((O,z,J)=>{if(P.current.has(J)){T.current=J;return}const X=Po(),ge=()=>Po()===X&&G.current===O&&pe.getState().getDirectoryState(O)?.tabs.find(xe=>xe.id===z)?.terminalSessionId===J,ve=e.connect(J,{onEvent:xe=>{if(ge())switch(xe.type){case"snapshot":{F.current===z&&B.current===J?(x(O,z,!1),A(null),w(!1),R(!1),b()):x(O,z,!1),y(O,z,xe.data??"",xe.sequence??0),Pe(O,z,xe.data??""),xe.status==="exited"&&v(O,z,"exited");break}case"reconnecting":{F.current===z&&(A(null),w(!1),R(!0));break}case"data":{xe.data&&(I(O,z,xe.data,xe.sequence,xe.replayData),Pe(O,z,xe.data));break}case"exit":{const se=typeof xe.exitCode=="number"?xe.exitCode:null,de=typeof xe.signal=="number"?xe.signal:null,me=!!pe.getState().getDirectoryState(O)?.tabs.find(Ue=>Ue.id===z)?.label?.startsWith("Action:");I(O,z,`\\r\\n[Process exited${se!==null?` with code ${se}`:""}${de!==null?` (signal ${de})`:""}]\\r\\n`),v(O,z,"exited"),F.current===z&&(x(O,z,!1),A(me?null:"Terminal session ended"),w(!1),R(!1));break}}},onError:(xe,se)=>{if(!ge())return;const de=F.current===z;if(!se){de&&(A(null),w(!1));return}if(xe.code==="SESSION_NOT_FOUND"&&!pe.getState().getDirectoryState(O)?.tabs.find(me=>me.id===z)?.label?.startsWith("Action:")){de&&(A(null),w(!1),x(O,z,!1),R(!1)),p(O,z,null),v(O,z,"idle");return}de&&(R(!1),A(`Connection failed: ${xe.message}`),w(!0),x(O,z,!1),v(O,z,"exited"),p(O,z,null))}});P.current.set(J,()=>ve.close()),T.current=J},[I,b,y,Pe,x,v,p,e]),Y=i.useMemo(()=>m.map(O=>`${O.id}:${O.terminalSessionId??""}`).join(","),[m]);return i.useEffect(()=>{if(!l||!a||!s)return;const O=s,z=new Set;for(const J of m)J.terminalSessionId&&(z.add(J.terminalSessionId),_e(O,J.id,J.terminalSessionId));for(const[J,X]of P.current)if(!z.has(J)){try{X()}catch{}P.current.delete(J)}},[Y,m,s,l,a,_e]),i.useEffect(()=>gd(()=>{if(!ae.current||!q.current)return;const O=G.current;if(!O)return;const z=[];for(const X of W.current){if(!X.terminalSessionId)continue;pe.getState().getDirectoryState(O)?.tabs.find(ve=>ve.id===X.id)?.terminalSessionId===X.terminalSessionId&&z.push({id:X.id,terminalSessionId:X.terminalSessionId})}if(P.current.clear(),T.current=null,z.length===0)return;R(!0),A(null),w(!1);for(const X of z)_e(O,X.id,X.terminalSessionId);const J=L.current;if(J)for(const X of z)$.current.resize({sessionId:X.terminalSessionId,...J}).catch(()=>{})}),[_e]),i.useEffect(()=>{let O=!1;if(!l||!a)return;if(!s){A(h?"No working directory available for terminal.":"Select a session to open the terminal.");return}return(async()=>{const J=s;if(!G.current||G.current!==J)return;if(!pe.getState().getDirectoryState(J)){g(J);return}const ge=pe.getState().getDirectoryState(J);if(!ge||ge.tabs.length===0)return;const ve=ge.activeTabId??ge.tabs[0]?.id??null;if(!ve)return;const xe=ge.tabs.find(K=>K.id===ve)??ge.tabs[0],se=xe?.terminalSessionId??null,de=xe?.lifecycle??"idle",Q=!!xe?.label?.startsWith("Action:"),me=pe.getState().getBuffer(J,ve),Ue=me.byteLength>0||me.chunks.length>0;if(!se){if(de==="exited"){x(J,ve,!1);return}if(Q&&Ue){x(J,ve,!1);return}const K=`${J}\0${ve}`;if(M.current.has(K))return;const Z=L.current??La;M.current.add(K),A(null),w(!1),R(!1),x(J,ve,!0);try{const ne=await e.createSession({cwd:J,sessionId:ve,cols:Z.cols,rows:Z.rows,shell:c,loginShell:u,...d.current});if(!pe.getState().getDirectoryState(J)?.tabs.find(Ne=>Ne.id===ve)){try{await e.close(ne.sessionId)}catch{}return}p(J,ve,ne.sessionId);const ye=L.current;ye&&(ye.cols!==Z.cols||ye.rows!==Z.rows)&&e.resize({sessionId:ne.sessionId,...ye}).catch(()=>{});return}catch(ne){const be=pe.getState().getDirectoryState(J)?.tabs.find(ye=>ye.id===ve);if(!be||be.terminalSessionId||(x(J,ve,!1),G.current!==J||F.current!==ve))return;A(ne instanceof Error?ne.message:"Failed to start terminal session"),w(!0),R(!1);return}finally{M.current.delete(K)}}!se||O||(B.current=se)})(),()=>{O=!0}},[h,s,r,o,n,a,f,l,g,x,v,p,e,u,c,d]),{connectionError:N,setConnectionError:A,isFatalError:j,setIsFatalError:w,isReconnectPending:k,setIsReconnectPending:R,terminalIdRef:B,lastViewportSizeRef:L,directoryRef:G,activeTabIdRef:F,disconnectStream:ee,resetTerminalPreviewScan:ke,startStream:_e}}function bm({terminal:e,terminalIdRef:s,isReconnectPending:n,setConnectionError:r,showQuickKeys:o,isTerminalVisible:a,lastViewportSizeRef:l,terminalSessionId:c,useTouchTerminalInput:u}){const[d,f]=i.useState(null),h=i.useRef(null),b=i.useCallback(()=>{u||h.current?.focus()},[u]),m=i.useCallback(()=>{u||typeof document<"u"&&!document.hasFocus()||h.current?.focus()},[u]);i.useEffect(()=>{!o&&d!==null&&f(null)},[o,d]),i.useEffect(()=>{!c&&d!==null&&f(null)},[c,d]);const g=i.useCallback(y=>{if(!y||n)return;let C=y,N=!1;d&&y.length>0&&(C=hm(y,d),N=!0);const A=s.current;A&&(e.sendInput(A,C).catch(j=>{n||r(j instanceof Error?j.message:"Failed to send input")}),N&&(f(null),b()))},[d,b,n,r,e,s]),p=i.useCallback((y,C)=>{const N=l.current;if((!N||N.cols!==y||N.rows!==C)&&(l.current={cols:y,rows:C}),!a)return;const A=s.current;A&&e.resize({sessionId:A,cols:y,rows:C}).catch(()=>{})},[a,l,e,s]),v=i.useCallback(y=>{f(C=>C===y?null:y),b()},[b]),x=i.useCallback(y=>{const C=fm(y,d);C&&(g(C),f(null),b())},[d,b,g]),I=i.useCallback(y=>{if(y.repeat)return;const C=y.key;if(!C||C==="Control"||C==="Meta"||C==="Alt"||C==="Shift")return;const N=C.length===1?C.toLowerCase():C;if(N in fi){y.preventDefault(),y.stopPropagation(),x(fi[N]);return}const A=mm(y,d);A&&(y.preventDefault(),y.stopPropagation(),g(A),f(null),b())},[d,b,x,g]);return i.useEffect(()=>{if(!(!o||!d||!c))return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[d,I,o,c]),{activeModifier:d,setActiveModifier:f,terminalControllerRef:h,focusTerminalController:b,focusTerminalWhenWindowActive:m,handleViewportInput:g,handleViewportResize:p,handleModifierToggle:v,handleMobileKeyPress:x}}function xm({terminal:e,effectiveDirectory:s,activeTabId:n,enableTabs:r,terminalShell:o,terminalLoginShell:a,terminalAppearanceRef:l,lastViewportSizeRef:c,directoryRef:u,activeTabIdRef:d,terminalIdRef:f,resetTerminalPreviewScan:h,startStream:b,setConnectionError:m,setIsFatalError:g,setIsReconnectPending:p}){const v=pe(T=>T.createTab),x=pe(T=>T.setActiveTab),I=pe(T=>T.closeTab),y=pe(T=>T.setTabSessionId),C=pe(T=>T.setTabLifecycle),[N,A]=i.useState(!1),j=i.useCallback(async()=>{if(!s||N)return;const T=pe.getState().getDirectoryState(s),F=n??T?.activeTabId??T?.tabs[0]?.id??null;if(!F)return;const B=T?.tabs.find(G=>G.id===F)?.terminalSessionId??null;if(!(!B||!e.restartSession)){A(!0),m(null),g(!1),p(!1),h();try{const G=c.current??La,L=await e.restartSession(B,{cwd:s,shell:o,loginShell:a,...G,...l.current});if(pe.getState().getDirectoryState(s)?.tabs.find(U=>U.id===F)?.terminalSessionId!==B||(y(s,F,L.sessionId),C(s,F,"running"),u.current!==s||d.current!==F))return;f.current=L.sessionId,b(s,F,L.sessionId)}catch(G){if(pe.getState().getDirectoryState(s)?.tabs.find(M=>M.id===F)?.terminalSessionId!==B||u.current!==s||d.current!==F)return;m(G instanceof Error?G.message:"Failed to restart terminal"),g(!1),p(!1),f.current=B,b(s,F,B)}finally{A(!1)}}},[n,d,u,s,r,N,c,h,m,g,p,C,y,b,e,l,f,a,o]),w=i.useCallback(async()=>{await j()},[j]),k=i.useCallback(()=>{if(!s)return;const T=v(s);x(s,T),m(null),g(!1),p(!1)},[v,s,x,m,g,p]),R=i.useCallback(T=>{s&&(x(s,T),m(null),g(!1),p(!1))},[s,x,m,g,p]),P=i.useCallback(T=>{if(!s)return;m(null),g(!1),p(!1);const F=pe.getState().getDirectoryState(s)?.tabs.find(B=>B.id===T)?.terminalSessionId;(async()=>{F&&await e.close(F),I(s,T)})().catch(B=>m(B instanceof Error?B.message:"Terminal session ended"))},[I,s,m,g,p,e]);return{isRestarting:N,handleRestart:j,handleHardRestart:w,handleCreateTab:k,handleSelectTab:R,handleCloseTab:P}}const Kg=({visible:e,onCloseView:s,terminalHeaderSlot:n})=>{const{terminal:r,runtime:o}=zs(),{currentTheme:a}=Di(),l=i.useRef({themeMode:"dark",terminalBackground:"",terminalForeground:""});l.current={themeMode:a.metadata.variant==="light"?"light":"dark",terminalBackground:a.colors.surface.background,terminalForeground:a.colors.syntax.base.foreground};const{monoFont:c}=Dc(),u=ce(te=>te.terminalFontSize),d=ce(te=>te.terminalShell),f=ce(te=>te.terminalLoginShells.includes(te.terminalShell)),{isMobile:h,isTablet:b,hasTouchOnlyPointer:m}=Us(),g=h||b,p=(g||m)&&o.platform==="web",v=!0,x=ce(te=>te.showTerminalQuickKeysOnDesktop),I=g||x,y=Ie(te=>te.currentSessionId),C=Ie(te=>te.newSessionDraft),N=y!==null||C?.open===!0,A=Ec()??null,j=pe(te=>A?te.sessions.get(A):void 0),w=pe(te=>te.hasHydrated),k=ce(te=>te.openContextPreview),R=i.useMemo(()=>j?j.activeTabId??j.tabs[0]?.id??null:null,[j,v]),P=i.useMemo(()=>{if(j)return R?j.tabs.find(te=>te.id===R)??j.tabs[0]:j.tabs[0]},[j,R]),T=i.useMemo(()=>(j?.tabs??[]).map(te=>({icon:(()=>{const Ee=te.iconKey?on[te.iconKey]??"terminal":"terminal";return t.jsx(D,{name:Ee,className:"h-4 w-4"})})(),id:te.id,label:te.label,title:te.label,closeLabel:"Close tab"})),[j?.tabs]),F=P?.terminalSessionId??null,B=P?.lifecycle??"idle",G=i.useMemo(()=>(j?.tabs??[]).map(te=>({id:te.id,terminalSessionId:te.terminalSessionId,label:te.label})),[j?.tabs]),L=P?.isConnecting??!1,M=P?.previewUrl??null,W=ce(te=>te.activeMainTab)==="terminal",ae=e??W,[q,$]=i.useState(ae);i.useEffect(()=>{ae&&$(!0)},[ae]);const{connectionError:ke,setConnectionError:ee,isFatalError:Pe,setIsFatalError:_e,isReconnectPending:Y,setIsReconnectPending:O,terminalIdRef:z,lastViewportSizeRef:J,directoryRef:X,activeTabIdRef:ge,resetTerminalPreviewScan:ve,startStream:xe}=gm({terminal:r,effectiveDirectory:A,activeTabId:R,terminalSessionId:F,terminalLifecycle:B,hasOpenedTerminalViewport:q,terminalHydrated:w,terminalShell:d,terminalLoginShell:f,terminalAppearanceRef:l,enableTabs:v,hasActiveContext:N,tabs:G,focusTerminalWhenWindowActive:()=>{!p&&typeof document<"u"&&document.hasFocus()&&de.current?.focus()}}),{activeModifier:se,terminalControllerRef:de,focusTerminalWhenWindowActive:Q,handleViewportInput:me,handleModifierToggle:Ue,handleMobileKeyPress:K}=bm({terminal:r,terminalIdRef:z,isReconnectPending:Y,setConnectionError:ee,showQuickKeys:I,isTerminalVisible:ae,lastViewportSizeRef:J,terminalSessionId:F,useTouchTerminalInput:p}),{isRestarting:Z,handleRestart:ne,handleHardRestart:be,handleCreateTab:ye,handleSelectTab:Ne,handleCloseTab:we}=xm({terminal:r,effectiveDirectory:A,activeTabId:R,enableTabs:v,terminalShell:d,terminalLoginShell:f,terminalAppearanceRef:l,lastViewportSizeRef:J,directoryRef:X,activeTabIdRef:ge,terminalIdRef:z,resetTerminalPreviewScan:ve,startStream:xe,setConnectionError:ee,setIsFatalError:_e,setIsReconnectPending:O});i.useEffect(()=>{if(!ae||p)return;if(typeof window>"u"){Q();return}const te=window.requestAnimationFrame(()=>{Q()});return()=>{window.cancelAnimationFrame(te)}},[R,Q,ae,p]);const re=i.useMemo(()=>{const te=Vs[nr].stack;if(typeof window>"u")return(Vs[c]??Vs[nr]).stack;const Le=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return Le&&Le.trim().length>0?Le.trim():(Vs[c]??Vs[nr]).stack??te},[c]),fe=i.useMemo(()=>zp(a),[a]),oe=`${A??"no-dir"}::${R??"no-tab"}`;if(i.useEffect(()=>{if(!ae||p)return;const te=de.current;if(!te)return;const Ee=()=>{te.fit()};if(typeof window<"u"){const Le=window.requestAnimationFrame(()=>{Ee(),Q()}),Je=[220,400].map(ut=>window.setTimeout(Ee,ut));return()=>{window.cancelAnimationFrame(Le),Je.forEach(ut=>window.clearTimeout(ut))}}Ee()},[Q,ae,p,de,oe,F]),i.useEffect(()=>{if(!ae||!p)return;let te=null;const Ee=()=>{te!==null&&window.cancelAnimationFrame(te),te=window.requestAnimationFrame(()=>{te=null,de.current?.fit()})};return window.addEventListener("oc:keyboard-settled",Ee),()=>{window.removeEventListener("oc:keyboard-settled",Ee),te!==null&&window.cancelAnimationFrame(te)}},[ae,de,oe,p]),!N)return t.jsx("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:"Select a session to open the terminal."});if(!A)return t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-sm text-muted-foreground",children:[t.jsx("p",{children:"No working directory available for this session."}),t.jsx("button",{onClick:ne,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Retry"})]});const Te=!F||L||Z||Y,We=q,Fe=j?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(em,{items:T,activeId:R,onSelect:Ne,onClose:we,onCreate:ye})}),t.jsx(Me,{type:"button",size:"xs",variant:"ghost",className:_("shrink-0",g?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:ye,title:"New tab","aria-label":"New tab",children:t.jsx(D,{name:"add",className:`${g?"h-[18px] w-[18px]":"h-4 w-4"}`})}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1 overflow-visible",children:[t.jsx(Me,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ne()},disabled:Z,title:"Restart terminal","aria-label":"Restart terminal",children:t.jsx(D,{name:"restart",className:"h-4 w-4"})}),M?t.jsxs(Me,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{A&&k(A,M)},title:"Open preview pane",children:[t.jsx(D,{name:"global",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"whitespace-nowrap",children:"Preview"})]}):null]})]}):null,De=t.jsx(tm,{isTouchTerminal:g,activeModifier:se,disabled:Te,onKeyPress:K,onModifierToggle:Ue});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-[var(--surface-background)]",children:[t.jsxs("div",{className:_("app-region-no-drag sticky top-0 z-20 shrink-0 bg-[var(--surface-background)] text-xs",g?"px-3 py-1.5":"pl-3 pr-1.5 py-1"),children:[Fe?n?Zl.createPortal(t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:Fe}),n):t.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[Fe,s?t.jsx(Me,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0",onClick:s,title:"Close terminal view","aria-label":"Close terminal view",children:t.jsx(D,{name:"close",className:"h-4 w-4"})}):null]}):null,!g&&I&&v&&j?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:De}):null,!g&&I&&!j?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:De}):null]}),t.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:fe.background},children:[t.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:We&&A&&j?j.tabs.map(te=>{const Ee=te.id===R;return t.jsx(Zp,{directory:A,tabId:te.id,sessionId:te.terminalSessionId,sessionKey:`${A}::${te.id}`,isActive:Ee,isTerminalVisible:ae,terminal:r,theme:fe,fontFamily:re,fontSize:u,enableTouchScroll:p,lastViewportSizeRef:J,onInput:me,controllerRef:de},te.id)}):null}),!Y&&ke&&t.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-[var(--status-error-background)] px-3 py-2 text-xs text-[var(--status-error-foreground)] flex items-center justify-between gap-2",children:[t.jsx("span",{children:ke}),Pe&&g&&t.jsx(Me,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:be,disabled:Z,title:"Force kill and create fresh session",type:"button",children:"Hard Restart"})]})]}),g&&I?t.jsx("div",{className:"shrink-0 overflow-x-auto border-t border-border/40 bg-[var(--surface-background)] px-2 pt-1.5 pb-[max(0.375rem,calc(var(--oc-app-bottom-safe,0px)-var(--oc-keyboard-inset,0px)))] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","data-no-drawer-swipe":"true",children:t.jsx("div",{className:"flex min-w-max items-center gap-1.5",children:De})}):null]})},ym=48,wm=96,gt=(e,...s)=>{try{e?.(...s)}catch{}},xr=(e,s)=>{if(typeof e=="function"){const n=e();return n>0?n:s}return typeof e=="number"&&e>0?e:s},Wg=(e,s)=>{const n=i.useRef(s);n.current=s;const r=s.enabled;i.useEffect(()=>{const o=e.current;if(!o||r===!1)return;const a=o.style.touchAction;o.style.touchAction="pan-x pan-y";const c=window.Capacitor?.getPlatform?.()==="android"?wm:ym;let u=!1,d=!1,f=!1,h=null,b=!1,m=0,g=0,p=0,v=0;const x=()=>{u=!1,d=!1,f=!1,h=null},I=()=>{const k=n.current,R=h,P=b;d&&R&&(gt(R==="left"?k.onLeftProgress:k.onRightProgress,P?1:0),gt(k.onDragEnd,R,P)),x()},y=()=>{I(),d||x()},C=k=>{const R=n.current;if(R.enabled===!1){d&&h?I():x();return}if(k.touches.length!==1){d&&h?I():x();return}const P=k.touches[0],T=o.getBoundingClientRect(),F=o.clientWidth,B=!!R.leftOpen,G=!!R.rightOpen,L=M=>Pp(M,o);if(B||G){if(L(k.target)){x();return}if(B&&G){const M=P.clientX<=T.left+c;P.clientX>=T.right-c?(h="right",b=!0):M?(h="left",b=!0):(h=B?"left":"right",b=!0)}else B?(h="left",b=!0):(h="right",b=!0);v=xr(h==="left"?R.leftWidth:R.rightWidth,F),v<10&&(v=F||window.innerWidth||320),v<10&&(v=320),u=!0}else{if(L(k.target)){x();return}h=null,b=!1,v=0,u=!0}m=P.clientX,g=P.clientY,p=Date.now(),d=!1,f=!1},N=k=>{if(!u)return;if(k.touches.length!==1){y();return}const R=k.touches[0],P=R.clientX-m,T=R.clientY-g;if(!f){if(Math.abs(P)<ii&&Math.abs(T)<ii)return;if(Math.abs(T)>Math.abs(P)*Xs){x();return}if(!h){const G=n.current;h=P>0?"left":"right",v=xr(h==="left"?G.leftWidth:G.rightWidth,o.clientWidth),v<10&&(v=window.innerWidth||320)}if(h==="left"){if(!b&&P<=0){x();return}if(b&&P>=0){x();return}}else{if(!b&&P>=0){x();return}if(b&&P<=0){x();return}}f=!0,d=!0,gt(n.current.onDragStart,h)}if(!d)return;k.cancelable&&k.preventDefault();const F=n.current,B=ai(h,b,P,v);gt(h==="left"?F.onLeftProgress:F.onRightProgress,B)},A=(k,R)=>{if(!u){x();return}const P=k-m,T=R-g;if(!h&&!b&&Math.abs(P)>=Fn&&Math.abs(T)<=Math.abs(P)*Xs){const U=n.current;h=P>0?"left":"right",v=xr(h==="left"?U.leftWidth:U.rightWidth,o.clientWidth),v<10&&(v=window.innerWidth||320)}if(!h){x();return}const F=Math.max(1,Date.now()-p),B=n.current;if(!d){const U=Math.abs(P),W=Math.abs(T);U>=Fn&&W<=U*Xs?h==="left"&&!b&&P>0?(gt(B.onLeftProgress,1),gt(B.onLeftOpen)):h==="right"&&!b&&P<0?(gt(B.onRightProgress,1),gt(B.onRightOpen)):gt(h==="left"?B.onLeftProgress:B.onRightProgress,b?1:0):gt(h==="left"?B.onLeftProgress:B.onRightProgress,b?1:0);const ae=h;x(),gt(B.onDragEnd,ae);return}const G=ai(h,b,P,v),L=Dp({side:h,isOpenAtStart:b,dx:P,dt:F,progress:G}),M=h;gt(M==="left"?L?B.onLeftOpen:B.onLeftClose:L?B.onRightOpen:B.onRightClose),x(),gt(B.onDragEnd,M,L)},j=k=>{const R=k.changedTouches[0];if(!R){x();return}const P=R.clientX-m,T=R.clientY-g;u&&(d||Math.abs(P)>=Fn&&Math.abs(T)<=Math.abs(P)*Xs)&&k.cancelable&&k.preventDefault(),A(R.clientX,R.clientY)},w=()=>{y()};return o.addEventListener("touchstart",C,{passive:!0}),o.addEventListener("touchmove",N,{passive:!1}),o.addEventListener("touchend",j,{passive:!1}),o.addEventListener("touchcancel",w,{passive:!0}),()=>{try{d&&h&&I()}catch{}o.style.touchAction=a,o.removeEventListener("touchstart",C),o.removeEventListener("touchmove",N),o.removeEventListener("touchend",j),o.removeEventListener("touchcancel",w)}},[e,r])};function Hg({className:e="h-5 w-5"}){return t.jsxs("span",{"aria-hidden":"true",className:`relative inline-block overflow-hidden rounded-[2px] ${e}`,children:[t.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),t.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),t.jsx(D,{name:"layout-column",className:"absolute inset-0 h-full w-full"})]})}function hi({size:e,className:s,style:n,...r}){return t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:s,style:{width:typeof e=="number"?`${e}px`:e,height:typeof e=="number"?`${e}px`:e,...n},...r,children:t.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"})})}const vm=({sessionDirectory:e,draftDirectory:s,isNewSessionDraftOpen:n})=>n?s:e,Sm=({activeProjectLabel:e,openDirectory:s,homeDirectory:n})=>Wn(s,n)?null:e,yr=()=>ms.filter(e=>Dr.has(e.id)).map(e=>({...Oi(e)})),jm=()=>{if(typeof window>"u")return Er;const e=window.localStorage.getItem("openInAppId");return e&&Rr(e)?e:Er};let wr=!1,Ds=!1,rs=!1,os=0,an=null;const pi=()=>{an&&(clearTimeout(an),an=null)},fs=ks()((e,s)=>({selectedAppId:jm(),availableApps:yr(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(wr||typeof window>"u")return;wr=!0;const n=(u,d=!0)=>{if(!Array.isArray(u)||u.length===0){e({availableApps:yr(),hasLoadedApps:d});return}const f=new Set(u.map(g=>g.name)),h=new Map(u.map(g=>[g.name,g.iconDataUrl??void 0])),m=ms.filter(g=>f.has(g.appName)||Dr.has(g.id)).map(g=>({...Oi(g),iconDataUrl:h.get(g.appName)}));e({availableApps:m,hasLoadedApps:!0})},r=async u=>{if(!Fs()||!cn()||Ds||s().hasLoadedApps&&!u)return;const f=ms.map(h=>h.appName);pi(),Ds=!0,rs=!1,e({isScanning:!0});try{const{apps:h,success:b,hasCache:m,isCacheStale:g}=await To(f,u),p=b&&!m&&h.length===0&&os<3;if(e({isCacheStale:m?g:!1}),n(h,b?!p:!1),b){if(p){const x=[800,1600,3200][os]??3200;os+=1,rs=!0,an=setTimeout(()=>{r()},x);return}os=0,rs=!1;return}if(os<3){const x=[1e3,3e3,7e3][os]??7e3;os+=1,rs=!0,an=setTimeout(()=>{r()},x)}}finally{Ds=!1,rs||e({isScanning:!1})}};r();const o=u=>{const d=u.detail,f=d&&typeof d.openInAppId=="string"&&d.openInAppId.length>0&&Rr(d.openInAppId)?d.openInAppId:null;f&&(window.localStorage.setItem("openInAppId",f),e({selectedAppId:f}))},a=()=>{r()},l=u=>{const d=u.detail;Array.isArray(d)&&(os=3,rs=!1,e({isScanning:!1,isCacheStale:!1}),n(d))};window.addEventListener("pichamber:settings-synced",o),window.addEventListener("pichamber:app-ready",a),window.addEventListener("pichamber:installed-apps-updated",l),window.__pichamberAppReady&&r(),window.setTimeout(()=>{s().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(wr||s().initialize(),!Fs()||!cn()||Ds||s().hasLoadedApps&&!n)return;const o=ms.map(a=>a.appName);pi(),n&&e({hasLoadedApps:!1}),Ds=!0,rs=!1,e({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:c}=await To(o,n),u=new Set(a.map(b=>b.name)),d=new Map(a.map(b=>[b.name,b.iconDataUrl??void 0])),h=ms.filter(b=>u.has(b.appName)||Dr.has(b.id)).map(b=>({...b,iconDataUrl:d.get(b.appName)}));e({availableApps:h.length>0?h:yr(),hasLoadedApps:h.length>0,isCacheStale:l?c:!1})}finally{Ds=!1,rs||e({isScanning:!1})}},selectApp:async n=>{Rr(n)&&(e({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Yr({openInAppId:n}))}})),km="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",Cm="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",vr=e=>({...e,fallbackIconDataUrl:e.id==="finder"&&window.__PICHAMBER_PLATFORM__==="darwin"?km:e.id==="terminal"?Cm:void 0}),mi=({label:e,iconDataUrl:s,fallbackIconDataUrl:n})=>{const[r,o]=i.useState(!1),a=e.trim().slice(0,1).toUpperCase()||"?",l=s||n;return l&&!r?t.jsx("img",{src:l,alt:"",className:"h-4 w-4 rounded-sm",onError:()=>o(!0)}):t.jsx("span",{className:_("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:a})},Am=({directory:e,className:s})=>{const n=fs(g=>g.selectedAppId),r=fs(g=>g.availableApps),o=fs(g=>g.isCacheStale),a=fs(g=>g.isScanning),l=fs(g=>g.initialize),c=fs(g=>g.loadInstalledApps),u=fs(g=>g.selectApp);i.useEffect(()=>{l()},[l]);const d=Fs()&&cn(),f=i.useMemo(()=>{const g=r.find(p=>p.id===n)??r.find(p=>p.id===Er)??r[0]??ms[0];return vr(g||ms[0])},[r,n]);if(!d||!e||r.length===0)return null;const h=async g=>{await bd(e,g.id,g.appName)||await Mi(e,g.appName)},b=async g=>{await u(g.id),await h(g)},m=async()=>{(await ws(e)).ok&&ie.success("Path copied to clipboard")};return t.jsxs("div",{className:_("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",s),children:[t.jsx("button",{type:"button",onClick:()=>{h(f)},className:_("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",a&&"animate-pulse"),"aria-label":`Open in ${f.label}`,children:t.jsx(mi,{label:f.label,iconDataUrl:f.iconDataUrl,fallbackIconDataUrl:f.fallbackIconDataUrl})}),t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:_("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),"aria-label":"Choose app to open",children:t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Ot,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{m()},children:[t.jsx(D,{name:"file-copy",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Copy Path"})]}),t.jsx(vs,{}),r.map(g=>{const p=vr(g);return t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{b(g)},children:[t.jsx(mi,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:p.fallbackIconDataUrl}),t.jsx("span",{className:"typography-ui-label text-foreground",children:g.label}),f.id===g.id?t.jsx(D,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},g.id)}),o?t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{c(!0)},children:[t.jsx(D,{name:"refresh",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]})]})},Nm="\x1B",Im=new RegExp(`${Nm}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Rm=/https?:\/\/[^\s<>'"`]+/gi,wt="__pichamber_auto_discover_preview__",Dm=15e3,Em=e=>{let s="";for(let n=0;n<e.length;n+=1){const r=e.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(s+=e[n])}return s},Pm=e=>{const s=(e||"").trim();if(!s)return null;const n=/^https?:\/\//i.test(s)?s:`http://${s}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Tm=e=>{const n=e.replace(Im,"").match(Rm);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&o.push({raw:a,parsed:l})}catch{}if(o.length>0){const a=l=>{const{parsed:c}=l,u=c.hostname.toLowerCase(),d=u==="localhost"||u==="127.0.0.1"||u==="0.0.0.0"||u==="::1",f=c.pathname||"/",h=f.split("/").filter(Boolean).length,b=f==="/"||f==="",m=!!(c.search||c.hash);let g=0;return d&&(g+=50),b&&(g+=30),g-=Math.min(h*5,20),m&&(g-=10),g};return o.sort((l,c)=>a(c)-a(l)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Mm=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Fm=["dev","start","preview","serve"];async function Om(e,s,n){if(!e)return null;const r=_m(s);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Um(n);if(o){const a=await zm(e);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Lm(e)){const o=await Bm(),a=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function Lm(e){const s=`${e}/index.html`,n=await Kn(s,e);return typeof n=="string"&&n.trim().length>0}async function Bm(){try{const e=await At("/api/system/free-port",{cache:"no-store"});if(!e.ok)return null;const s=await e.json().catch(()=>null),n=typeof s?.port=="number"?s.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function _m(e){for(const s of e){const n=`${s.name} ${s.command}`.toLowerCase();if(Fm.some(o=>n.includes(o)))return s}return null}function Um(e){for(const{pattern:s}of Mm)for(const n of Object.keys(e))if(s.test(n))return n;return null}async function zm(e){const s=await Kn(`${e}/package.json`,e);if(s)try{const r=JSON.parse(s),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const a=await Kn(`${e}/${r}`,e);if(typeof a=="string"&&a.trim().length>0)return o}return"npm"}async function Kn(e,s){if(s?.trim())try{const r=new URLSearchParams({path:e,directory:s,optional:"true"}),o=await At(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Jt()?.files;if(n?.readFile)try{const r=await n.readFile(e,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await At(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function $m(e){try{const s=await Kn(`${e}/package.json`,e);if(s==null)return null;const r=JSON.parse(s).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Gm=(e,s,n)=>new Promise(r=>{let o=!1,a=null,l=null;const c=u=>{o||(o=!0,l&&clearTimeout(l),a?.close(),r(u))};a=e.connect(s,{onEvent:u=>{(u.type==="exit"||u.type==="snapshot"&&u.status==="exited")&&c(!0)},onError:(u,d)=>{d&&c(!0)}}),o?a.close():l=setTimeout(()=>c(!1),n)});function Km({projectRef:e,directory:s,allowMobile:n=!1}){const{currentTheme:r}=Di(),{terminal:o}=zs(),{isMobile:a}=Us(),l=ce(K=>K.terminalShell),c=ce(K=>K.terminalLoginShells.includes(K.terminalShell)),u=ce(K=>K.setSettingsPage),d=ce(K=>K.setSettingsDialogOpen),f=ce(K=>K.setSettingsProjectsSelectedId),h=ce(K=>K.openContextPreview),b=pe(K=>K.ensureDirectory),m=pe(K=>K.setTabLabel),g=pe(K=>K.setTabIconKey),p=pe(K=>K.setActiveTab),v=pe(K=>K.setConnecting),x=pe(K=>K.setTabSessionId),I=pe(K=>K.setTabPreviewUrl),y=pe(K=>K.projectActionRuns),C=pe(K=>K.setProjectActionRun),N=pe(K=>K.updateProjectActionRunStatus),A=pe(K=>K.removeProjectActionRun),[j,w]=i.useState([]),[k,R]=i.useState(null),[P,T]=i.useState(!1),F=i.useRef({}),B=i.useRef({}),G=i.useRef({}),L=i.useRef({}),M=i.useRef(new Set),U=i.useRef(0),W=e?.id??null,ae=e?.path??"",q=i.useMemo(()=>W?{id:W,path:ae}:null,[W,ae]),$=i.useCallback(async K=>{await wi(K)},[]),ke=i.useCallback(async()=>{if(!q)return;const K=U.current+1;U.current=K,T(!0);try{const Z=await jr(q);if(U.current!==K)return;const ne=Z.actions;w(ne),R(be=>be===wt||be&&ne.some(ye=>ye.id===be)?be:null)}catch{if(U.current!==K)return}finally{U.current===K&&T(!1)}},[q]),ee=i.useMemo(()=>ha(s||q?.path||""),[s,q?.path]),Pe=i.useMemo(()=>k?j.find(K=>K.id===k)??null:null,[j,k]),_e=i.useMemo(()=>({id:wt,name:"Auto-discover",command:"",icon:"scan-2",autoOpenUrl:!0}),[]),Y=!a,O=i.useMemo(()=>Y?[_e,...j]:j,[j,_e,Y]);i.useEffect(()=>{ke()},[ke]),i.useEffect(()=>{if(typeof window>"u")return;const K=Z=>{const ne=Z.detail;W&&(ne?.projectId&&ne.projectId!==W||ke())};return window.addEventListener(Br,K),()=>{window.removeEventListener(Br,K)}},[ke,W]),i.useEffect(()=>{k&&(k===wt&&Y||j.some(K=>K.id===k)||R(null))},[j,Y,k]),i.useEffect(()=>{const K=()=>{const Z=pe.getState(),ne=Z.sessions,be=Z.projectActionRuns;for(const[ye,Ne]of Object.entries(be)){const re=ne.get(Ne.directory)?.tabs.find(Le=>Le.id===Ne.tabId);if(!re||re.terminalSessionId!==Ne.sessionId){A(ye);continue}const fe=B.current[ye]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};B.current[ye]=fe;const oe=O.find(Le=>Le.id===Ne.actionId),Te=Z.getBuffer(Ne.directory,Ne.tabId).chunks;if(!oe||Te.length===0)continue;const We=Te.filter(Le=>fe.lastSeenChunkId===null||Le.id>fe.lastSeenChunkId);if(We.length===0)continue;const Fe=We.map(Le=>Le.data).join(""),De=`${fe.tail}${Fe}`,te=!fe.openedUrl&&oe.autoOpenUrl===!0?Tm(De):null,Ee=We[We.length-1]?.id??fe.lastSeenChunkId;if(fe.lastSeenChunkId=Ee,fe.tail=De.slice(-512),te)if(fe.openedUrl=!0,fe.openInPreview){const Le=be[ye];Le&&(I(Le.directory,Le.tabId,te,{locked:!1,autoOpened:!1}),Le.status==="waiting-for-preview"&&N(ye,"running"),window.clearTimeout(L.current[ye]),delete L.current[ye],h(Le.directory,te))}else $(te),ie.success("Opened URL from action output");B.current[ye]=fe}for(const ye of Object.keys(B.current))be[ye]||(delete B.current[ye],window.clearTimeout(L.current[ye]),delete L.current[ye])};return K(),pe.subscribe((Z,ne)=>{(Z.sessions!==ne.sessions||Z.buffers!==ne.buffers)&&K()})},[O,h,$,y,A,I,N]);const z=i.useCallback(async(K,Z={})=>{if(!ee)throw new Error("No active directory");const ne=Xt(ee,K.id);b(ee);const be=pe.getState(),ye=be.getDirectoryState(ee);let Ne=F.current[ne]||null;const we=Ne?!!ye?.tabs.some(oe=>oe.id===Ne):!1;(!Ne||!we)&&(Ne=be.createTab(ee),F.current[ne]=Ne),m(ee,Ne,`Action: ${K.name}`),g(ee,Ne,K.icon||"play"),p(ee,Ne),Z.revealTerminal!==!1&&ce.getState().openContextPanelTab(ee,{mode:"terminal"});const fe=pe.getState().getDirectoryState(ee)?.tabs.find(oe=>oe.id===Ne);return{key:ne,tabId:Ne,sessionId:fe?.terminalSessionId??null}},[b,ee,p,g,m]),J=i.useCallback(async K=>{if(!n&&a)return;if(!ee){ie.error("No active directory for action");return}const Z=Xt(ee,K.id),ne=y[Z];if(!(ne&&ne.status==="running")&&!M.current.has(Z)){M.current.add(Z);try{const be=K.id===wt?await(async()=>{const[De,te]=await Promise.all([jr({id:q?.id??"",path:ee}),$m(ee)]),Ee=await Om(ee,De.actions,te);if(!Ee)throw new Error('No dev server command found. Configure a project action or add a "dev" script to package.json.');return{id:wt,name:"Auto-discover",command:Ee.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Ee.previewUrlHint||""}})():K,ye=be.autoOpenUrl===!0&&(be.openUrl||"").trim().length>0,Ne=!ye&&K.id!==wt,{key:we,tabId:re,sessionId:fe}=await z(be,{revealTerminal:Ne});let oe=fe;if(!oe){v(ee,re,!0);try{oe=(await o.createSession({cwd:ee,sessionId:re,shell:l,loginShell:c,themeMode:r.metadata.variant==="light"?"light":"dark",terminalBackground:r.colors.surface.background,terminalForeground:r.colors.syntax.base.foreground})).sessionId,x(ee,re,oe)}finally{v(ee,re,!1)}}if(!oe)throw new Error("Failed to create terminal session");G.current[we]?.(),v(ee,re,!0);const Te=o.connect(oe,{onEvent:De=>{De.type==="snapshot"&&(pe.getState().replaceBuffer(ee,re,De.data??"",De.sequence??0),pe.getState().setConnecting(ee,re,!1)),De.type==="data"&&typeof De.data=="string"&&De.data.length>0&&pe.getState().appendToBuffer(ee,re,De.data,De.sequence,De.replayData),De.type==="exit"&&(pe.getState().setTabLifecycle(ee,re,"exited"),pe.getState().setConnecting(ee,re,!1),pe.getState().removeProjectActionRun(we),delete B.current[we],G.current[we]?.(),delete G.current[we],window.clearTimeout(L.current[we]),delete L.current[we])},onError:(De,te)=>{pe.getState().setConnecting(ee,re,!1),te&&(pe.getState().setTabLifecycle(ee,re,"exited"),pe.getState().setTabSessionId(ee,re,null),pe.getState().removeProjectActionRun(we))}});G.current[we]=Te.close;const We=be.autoOpenUrl?Pm(be.openUrl):null;C({key:we,directory:ee,actionId:be.id,tabId:re,sessionId:oe,status:be.id===wt&&!We?"waiting-for-preview":"running"}),window.clearTimeout(L.current[we]),delete L.current[we],be.id===wt&&!We&&(L.current[we]=window.setTimeout(()=>{const De=pe.getState(),te=De.projectActionRuns[we];De.updateProjectActionRunStatus(we,"running"),te&&(De.setActiveTab(te.directory,te.tabId),ce.getState().openContextPanelTab(te.directory,{mode:"terminal"})),delete L.current[we]},Dm)),B.current[we]={lastSeenChunkId:null,openedUrl:!!We||ye,tail:"",openInPreview:be.id===wt};const Fe=Em(be.command.trim().replace(/\r\n|\r/g,`
|
|
53
|
-
`));await o.sendInput(oe,`${Fe}\r`),We?(I(ee,re,We,{locked:!0,autoOpened:!0}),h(ee,We),ie.success("Opened action URL")):ye?(I(ee,re,null,{locked:!0}),ie.error("Invalid custom URL format")):I(ee,re,null,{locked:!1,autoOpened:!1})}catch(be){A(Z),delete B.current[Z],G.current[Z]?.(),delete G.current[Z],window.clearTimeout(L.current[Z]),delete L.current[Z],ie.error(be instanceof Error?be.message:"Failed to run action")}finally{M.current.delete(Z)}}},[r.colors.surface.background,r.colors.syntax.base.foreground,r.metadata.variant,z,n,a,ee,c,l,h,y,A,v,C,I,x,q?.id,o]),X=i.useCallback(async K=>{const Z=Xt(ee,K.id),ne=y[Z];if(!ne)return;N(Z,"stopping");const be=Gm(o,ne.sessionId,1e3);try{await o.sendInput(ne.sessionId,"")}catch{}const ye=await be;if(pe.getState().getDirectoryState(ne.directory)?.tabs.find(re=>re.id===ne.tabId)?.terminalSessionId===ne.sessionId&&!ye){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:ne.sessionId})}catch{}else try{await o.close(ne.sessionId)}catch{}x(ne.directory,ne.tabId,null)}A(Z),delete B.current[Z],G.current[Z]?.(),delete G.current[Z],window.clearTimeout(L.current[Z]),delete L.current[Z]},[ee,y,A,x,o,N]),ge=i.useCallback(()=>{const K=Pe??O[0];if(!K)return;const Z=Xt(ee,K.id),ne=y[Z];if(ne?.status!=="stopping"){if(ne){X(K);return}J(K)}},[O,ee,J,y,Pe,X]),ve=i.useCallback((K,Z=!1)=>{if(R(K.id),!Z){J(K);return}const ne=Xt(ee,K.id),be=y[ne];if(be?.status!=="stopping"){if(be){X(K);return}J(K)}},[ee,J,y,X]),xe=i.useCallback(()=>{q?.id&&(f(q.id),u("projects"),d(!0))},[d,u,f,q?.id]),se=Pe??O[0]??null,de=se?y[Xt(ee,se.id)]:null,Q=pe(K=>de?K.sessions.get(de.directory)?.tabs.find(Z=>Z.id===de.tabId)?.previewUrl??null:null),me=!!((n||!a)&&q&&ee),Ue=Pe??O[0]??null;return{shouldRender:me,isLoading:P,normalizedDirectory:ee,resolvedSelected:Ue,displayActions:O,projectActionRuns:y,selectedRunPreviewUrl:Q,handlePrimaryClick:ge,handleSelectAction:ve,openProjectActionsSettings:xe,openContextPreview:h}}const gi=({projectRef:e,directory:s,className:n,compact:r=!1,allowMobile:o=!1})=>{const{shouldRender:a,isLoading:l,normalizedDirectory:c,resolvedSelected:u,displayActions:d,projectActionRuns:f,selectedRunPreviewUrl:h,handlePrimaryClick:b,handleSelectAction:m,openProjectActionsSettings:g,openContextPreview:p}=Km({projectRef:e,directory:s,allowMobile:o});if(!a||!u)return null;const v=u.icon||"play",x=u.id===wt?"scan-2":on[v]||"play",I=Xt(c,u.id),y=f[I],C=y?.status==="stopping",N=y?.status==="waiting-for-preview",A=!!(y&&h),j=()=>{!y||!h||p(y.directory,h)},w=u.id===wt;return r?t.jsxs("div",{className:"inline-flex items-center",children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",disabled:l||C,className:_("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:b,"aria-label":y?`Stop ${u.name}`:`Run ${u.name}`,children:C||N?t.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):y?t.jsx(D,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):t.jsx(D,{name:x,className:"h-5 w-5"})})}),w?t.jsx(Ge,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open Preview",onClick:j,children:t.jsx(D,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ge,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Choose project action",children:t.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),t.jsxs(Ot,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(tt,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(D,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(vs,{}),d.map(k=>{const R=k.icon||"play",P=k.id===wt?"scan-2":on[R]||"play",T=Xt(c,k.id),F=f[T],B=!!F,G=F?.status==="stopping";return t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{m(k,!0)},children:[t.jsx(D,{name:P,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),G||F?.status==="waiting-for-preview"?t.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):B?t.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]}):t.jsxs("div",{className:_("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,disabled:l||C,className:_("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":y?`Stop ${u.name}`:`Run ${u.name}`,children:t.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:C||N?t.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):y?t.jsx(D,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):t.jsx(D,{name:x,className:"h-4 w-4"})})})}),w?t.jsx(Ge,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:j,className:_(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":"Open Preview",children:t.jsx(D,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ge,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:_(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":"Choose project action",children:t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Ot,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(tt,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(D,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(vs,{}),d.map(k=>{const R=k.icon||"play",P=k.id===wt?"scan-2":on[R]||"play",T=Xt(c,k.id),F=f[T],B=!!F,G=F?.status==="stopping";return t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{m(k,!0)},children:[t.jsx(D,{name:P,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),G||F?.status==="waiting-for-preview"?t.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):B?t.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]})},Wm=i.memo(function({isMobile:s,githubAuthStatus:n,githubAccounts:r,githubAvatarUrl:o,githubLogin:a,isSwitchingGitHubAccount:l,handleGitHubAccountSwitch:c}){return!n?.connected||s?null:r.length>1?t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:_(mn,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),title:a?`GitHub: ${a}`:"GitHub connected",disabled:l,children:o?t.jsx("img",{src:o,alt:a?`${a} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),t.jsxs(Ot,{align:"end",className:"w-64",children:[t.jsx(Pc,{className:"typography-ui-header font-semibold text-foreground",children:"GitHub Accounts"}),t.jsx(vs,{}),r.map(u=>{const d=u.user,f=!!u.current,h=u.source==="gh-cli"?"CLI":"OAuth";return t.jsxs(tt,{className:"gap-2",disabled:l,onSelect:()=>{f||c(u.id)},children:[d?.avatarUrl?t.jsx("img",{src:d.avatarUrl,alt:d.login?`${d.login} avatar`:"GitHub avatar",className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:t.jsx(D,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:d?.name?.trim()||d?.login||"GitHub"}),d?.login?t.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[t.jsx("span",{className:"font-mono",children:d.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:h})]}):null]}),f?t.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]},u.id)})]})]}):t.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:a?`GitHub: ${a}`:"GitHub connected",children:o?t.jsx("img",{src:o,alt:a?`${a} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),Hm=i.memo(function({isDesktopApp:s,currentInstanceLabel:n,compactCurrentInstanceLabel:r,currentInstanceIsLocal:o,isDesktopServicesOpen:a,setIsDesktopServicesOpen:l,refreshCurrentInstanceLabel:c,shortcutLabel:u,remoteUpdateInfo:d,remoteUpdateChecking:f,remoteUpdateError:h,onOpenRemoteUpdate:b}){return t.jsxs(Mt,{open:a,onOpenChange:m=>{l(m),m&&c()},children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx(Ft,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":s?`Open instance, usage and MCP (current: ${n})`:"Open services, usage and MCP",className:_(mn,s?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[t.jsx(D,{name:"server",className:"h-[18px] w-[18px]"}),s?t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:r}):null]})})}),t.jsx(Ge,{children:t.jsx("p",{children:`Current instance: ${n} (${u("toggle_services_menu")})`})})]}),t.jsx(Ot,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:s?t.jsxs("div",{children:[o?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Remote instance update"}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:d?.available?`Version ${d.version||""} is available for this instance.`:f?"Looking for updates...":h||"This instance is up to date."})]}),d?.available?t.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:b,children:"Update"}):null]})}),t.jsx(Tc,{embedded:!0,open:a,onOpenChange:()=>{},onHostSwitched:()=>l(!1)})]}):null})]})}),Ym=({action:e,onClose:s,sessionTitle:n,onConfirm:r})=>t.jsx(Kt,{open:e!==null,onOpenChange:o=>{o||s()},children:t.jsxs(Wt,{showCloseButton:!1,className:"max-w-sm gap-5",children:[t.jsxs(ls,{children:[t.jsx(es,{children:e==="delete"?"Delete session?":"Archive session?"}),t.jsx(cs,{children:e==="delete"?`"${n}" will be permanently deleted.`:`"${n}" will be archived.`})]}),t.jsxs(Ss,{children:[t.jsx(Me,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),t.jsx(Me,{variant:"destructive",size:"sm",onClick:r,children:e==="delete"?"Delete":"Archive"})]})]})}),Qm=e=>{const s=e.trim();if(!s)return"";const n=s.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),a=`${r} ${o}`.trim();return n.length>2||a.length<s.length?`${a}...`:a}return s.length>12?`${s.slice(0,9).trimEnd()}...`:s},Js=e=>{if(!e)return"";const s=e.replace(/\\/g,"/");return s==="/"?"/":s.replace(/\/+$/,"")},qm=i.lazy(()=>is(()=>import("./SessionSwitcherDropdown-DmE2hYTN.js"),__vite__mapDeps([116,24,4,5,1,2,3,6,7,8,9,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])).then(e=>({default:e.SessionSwitcherDropdown}))),Yg=({onToggleLeftDrawer:e,onToggleRightDrawer:s,leftDrawerOpen:n,rightDrawerOpen:r,tabletWorkspaceTab:o,onSelectTabletWorkspaceTab:a})=>{Tt("ui.header.render");const l=ce(E=>E.setSessionSwitcherOpen),c=ce(E=>E.toggleSidebar),u=ce(E=>E.isSidebarOpen),d=ce(E=>E.activeMainTab),f=ce(E=>E.setActiveMainTab),h=ce(E=>E.shortcutOverrides);ce(E=>E.timeFormatPreference),zs();const b=Ie(E=>!!E.newSessionDraft?.open),m=Ie(E=>E.currentSessionId),g=Ri(m??""),p=Mc(m),v=i.useMemo(()=>{if(!p)return null;const E=p;return{title:p.title??null,directory:E.directory??null,created:p.time?.created??null,slug:E.slug??null,shareUrl:p.share?.url??null,parentId:p.parentID??null}},[p]),x=dt(Pr(E=>{if(!E.activeProjectId)return null;const le=E.projects.find(he=>he.id===E.activeProjectId);return le?{id:le.id,path:le.path,label:le.label}:null})),I=Os(E=>E.homeDirectory),y=i.useMemo(()=>{if(!x)return null;const E=x.label?.trim();if(E)return E;const le=x.path.split(/[\\/]/).filter(Boolean);return le[le.length-1]??null},[x]),{isMobile:C}=Us(),{enabled:N}=Wr(),A=!!(N&&a&&o!==void 0),j=i.useMemo(()=>[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"}],[]),[w,k]=i.useState(!1),R=null,P=i.useRef(null),[T,F]=i.useState(()=>typeof window>"u"?!1:Fs()),B=i.useMemo(()=>Fi(),[]),G=Fc(),[L,M]=i.useState(!1),U=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),W=Ei(),ae=i.useMemo(()=>{if(typeof window>"u")return null;const E=window.__PICHAMBER_MACOS_MAJOR__;if(typeof E=="number"&&Number.isFinite(E)&&E>0)return E;if(typeof navigator>"u")return null;const le=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!le)return null;const he=Number.parseInt(le[1],10),He=Number.parseInt(le[2],10);return Number.isNaN(he)?null:he===10?He:he},[]);Re.useEffect(()=>{typeof window>"u"||F(Fs())},[]);const q=ce(E=>E.isSessionSwitcherOpen),$=null,ke=null,ee=[],[Pe,_e]=i.useState(!1),[Y,O]=i.useState(!1),[z,J]=i.useState("Local"),[X,ge]=i.useState(!0),[ve,xe]=i.useState(!1),[se,de]=i.useState(null),[Q,me]=i.useState(!1),[Ue,K]=i.useState(null),Z=i.useMemo(()=>Qm(z),[z]),ne=i.useCallback(async()=>{if(!(typeof window>"u"||!T))try{if(cn()){J("Local"),ge(!0);return}ge(!1);const E=await xd(),le=yd(),he=wd([vd(le),...E.hosts]);if(he.id===Sd){J("Local"),ge(!0);return}J(jd(he.label.trim()||"Instance"))}catch{J("Local"),ge(!0)}},[T]);Re.useEffect(()=>(ne(),kd(()=>{ne()})),[ne]);const be=i.useCallback(async()=>{if(X){de(null),K(null);return}me(!0),K(null);try{const E=new URLSearchParams({appType:"web",instanceMode:"remote"}),le=await At(`/api/pi/update-check?${E.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!le.ok)throw new Error(`Server responded with ${le.status}`);const he=await le.json();de({available:he.available??!1,version:he.version,currentVersion:he.currentVersion??"unknown",body:he.body,nextSuggestedCheckInSec:typeof he.nextSuggestedCheckInSec=="number"?he.nextSuggestedCheckInSec:void 0,packageManager:he.packageManager,updateCommand:he.updateCommand})}catch(E){de(null),K(E instanceof Error?E.message:"Failed to check remote instance updates")}finally{me(!1)}},[X]);i.useEffect(()=>{de(null),K(null),xe(!1)},[X,z]),i.useEffect(()=>{if(!T||X)return;const E=3e3,le=3600*1e3;let he=!1,He=null;const Qt=Dt=>{He=window.setTimeout(()=>{if(he||typeof document<"u"&&document.visibilityState!=="visible"){Qt(le);return}be().finally(()=>{he||Qt(le)})},Dt)};return Qt(E),()=>{he=!0,He!==null&&window.clearTimeout(He)}},[be,X,z,T]);const ye=i.useCallback(()=>{if(se?.available){xe(!0);return}be()},[be,se?.available]),Ne=m?v??null:null,we=i.useRef(null),[re,fe]=i.useState(0);i.useEffect(()=>{if(!m){we.current&&(we.current=null,fe(He=>He+1));return}if(Ne){we.current={sessionId:m,session:Ne,expiresAt:Date.now()+2e3};return}const E=we.current;if(!E||E.sessionId!==m)return;const le=E.expiresAt-Date.now();if(le<=0){we.current=null,fe(He=>He+1);return}const he=window.setTimeout(()=>{we.current?.sessionId===m&&(we.current=null),fe(He=>He+1)},le);return()=>{window.clearTimeout(he)}},[m,Ne]);const oe=(()=>{if(Ne)return Ne;if(!m)return null;const E=we.current;return E&&E.sessionId===m&&E.expiresAt>Date.now()?E.session:null})(),Te=i.useMemo(()=>{const E=typeof oe?.directory=="string"?oe.directory:"";return Js(E||"")},[oe?.directory]),We=Ie(E=>E.newSessionDraft?.open?Js(E.newSessionDraft.directoryOverride??""):""),Fe=i.useMemo(()=>vm({sessionDirectory:Te,draftDirectory:We,isNewSessionDraftOpen:b}),[We,b,Te]),te=Ii(Fe||null),Ee=i.useMemo(()=>Sm({activeProjectLabel:y,openDirectory:Fe,homeDirectory:I}),[y,I,Fe]),Le=!!(Ee||te),Je=i.useMemo(()=>m?as(oe):Ee??"PiChamber",[oe,m,Ee]),ut=Oc(),Ve=Ie(E=>E.updateSessionTitle),Lt=Ie(E=>E.archiveSessions),Nt=Ie(E=>E.deleteSessions),[ft,It]=i.useState(!1),[bt,rt]=i.useState(!1),Xe=i.useRef(!1),[xt,vt]=i.useState(""),[Bt,ht]=i.useState(null),je=i.useRef(null);i.useEffect(()=>{Xe.current=!1,rt(!1),It(!1),vt(""),ht(null)},[m]);const Oe=i.useCallback(()=>{m&&(vt(oe?.title?.trim()||Je),It(!0))},[oe?.title,m,Je]),Se=i.useCallback(async()=>{if(!m)return;const E=xt.trim();E&&E!==oe?.title?.trim()&&await Ve(m,E),It(!1)},[oe?.title,m,xt,Ve]);i.useEffect(()=>{if(!ft)return;const E=le=>{const he=le.target;(!he||!je.current?.contains(he))&&Se()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[ft,Se]);const Be=i.useCallback(()=>{m&&ws(m).then(E=>{ie[E.ok?"success":"error"](E.ok?"Session ID copied":"Failed to copy session ID")}).catch(()=>ie.error("Failed to copy session ID"))},[m]),Ye=i.useCallback(async()=>{if(!m||!Fe){ie.error("Nothing to export");return}try{await ut.syncSession(m)}catch{ie.error("Failed to load the complete session history");return}const E=[];if(E.length===0){ie.error("Nothing to export");return}const le=Da(E,oe?.title??null),he=Ta(oe?.title??null);await Pa(le,he)||Ea(le,he),ie.success("Session exported")},[oe?.title,m,Fe,ut]);g?.type==="busy"||g?.type;const ot=i.useCallback(async()=>{if(!m||!Bt)return;const E=Lc(),le=[m];for(let Dt=0;Dt<le.length;Dt+=1){const Ys=le[Dt];for(const qt of E)qt.parentID===Ys&&!le.includes(qt.id)&&le.push(qt.id)}const he=Bt;if(ht(null),(he==="archive"?await Lt(le):await Nt(le)).failedIds.length>0){ie.error(he==="archive"?"Failed to archive session":"Failed to delete session");return}ie.success(he==="archive"?"Session archived":"Session deleted")},[Lt,m,Nt,Bt]),St=ce(E=>E.isArchivePageOpen),yt=i.useMemo(()=>St?{title:"Archive",subtitle:null}:null,[St]),Ze=i.useMemo(()=>Js(Fe||x?.path||""),[x?.path,Fe]),Rt=i.useCallback(()=>{Ze&&ws(Ze).then(E=>{ie[E.ok?"success":"error"](E.ok?"Working directory copied":"Failed to copy working directory")}).catch(()=>ie.error("Failed to copy working directory"))},[Ze]),Qe=i.useMemo(()=>x?{id:x.id,path:x.path}:null,[x]),Ht=i.useRef(null);i.useEffect(()=>{!Qe||!Ze||(Ht.current={projectRef:Qe,directory:Ze})},[Ze,Qe]);const pt=i.useMemo(()=>Qe&&Ze?{projectRef:Qe,directory:Ze}:Ht.current,[Ze,Qe]),Yt=i.useCallback(async E=>{},[]),_t=i.useCallback(()=>{if(typeof document>"u")return;const E=document.activeElement;if(!E)return;const le=E.tagName;(le==="INPUT"||le==="TEXTAREA"||le==="SELECT"||E.isContentEditable)&&E.blur()},[]),$s=i.useCallback(()=>{if(C){_t(),l(!q);return}c()},[_t,C,q,l,c]),ds=i.useCallback(()=>{nn("desktop_open_draft_mini_chat_window",{directory:Js(Fe||x?.path||""),projectId:x?.id??null,apiBaseUrl:Ir(),clientToken:Nr()}).catch(E=>{console.warn("[header] failed to open draft mini chat window",E)})},[x?.id,x?.path,Fe]),Gs=i.useCallback(()=>{if(b){ds();return}m&&nn("desktop_open_session_mini_chat_window",{sessionId:m,directory:Js(Fe||x?.path||""),apiBaseUrl:Ir(),clientToken:Nr()}).catch(E=>{console.warn("[header] failed to open session mini chat window",E)})},[x?.path,m,ds,b,Fe]),jt=mn,Ut=Nf,it=i.useMemo(()=>n?"sessions":A?r&&o?o:null:r?"git":d,[d,A,n,r,o]),ue=i.useCallback(()=>{n&&e&&e(),r&&s&&s(),!e&&q&&l(!1)},[q,n,e,s,r,l]),at=i.useCallback(()=>{e?.()},[e]),lt=i.useCallback(()=>{s?.()},[s]),mt=i.useMemo(()=>T&&U&&!L?"5.5rem":G?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":!T||W?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[T,L,U,G,W]);Re.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",mt)},[mt]);const ts=u?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",st=u?"0px":T&&W?"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)":N?"2.75rem":"2.5rem";Re.useEffect(()=>{if(!T||!U){M(!1);return}let E=!1;const le=async()=>{try{const He=await nn("desktop_is_window_fullscreen");E||M(He===!0)}catch{E||M(!1)}},he=()=>{le()};return le(),window.addEventListener("pichamber:window-resized",he),()=>{E=!0,window.removeEventListener("pichamber:window-resized",he)}},[T,U]);const gn=i.useMemo(()=>!T||!U||ae===null?"":ae>=26?"h-12":ae<=15?"h-14":"",[T,U,ae]),bn=i.useMemo(()=>{if(!(T&&!W))return{paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[T,W]),us=i.useCallback(()=>{if(typeof document>"u")return;const E=P.current?.getBoundingClientRect().height;E&&document.documentElement.style.setProperty("--oc-header-height",`${E}px`)},[]);Re.useEffect(()=>{if(typeof window>"u")return;us();const E=P.current;if(!E||typeof ResizeObserver>"u")return()=>{};let le=0;const he=()=>{le||(le=requestAnimationFrame(()=>{le=0,us()}))},He=new ResizeObserver(he);return He.observe(E),window.addEventListener("resize",he),window.addEventListener("orientationchange",he),()=>{le&&cancelAnimationFrame(le),He.disconnect(),window.removeEventListener("resize",he),window.removeEventListener("orientationchange",he)}},[us]),Re.useEffect(()=>{us()},[us,C,gn]);const Ks=i.useCallback(async E=>{const le=E.target;le.closest(".app-region-no-drag")||le.closest("button, a, input, select, textarea")||E.button===0&&T&&await Bc()},[T]),ss=i.useMemo(()=>C?[{id:"chat",label:"Chat",icon:"chat-4"},{id:"diff",label:"Diff",icon:"diff"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"},{id:"context",label:"Context",icon:"file-list-2"},{id:"diagram",label:"Diagram",icon:"file"}]:[],[C]),Yn=i.useCallback(E=>qr(Ln(E,h)),[h]);Re.useEffect(()=>{!C&&d!=="chat"&&d!=="terminal"&&d!=="diagram"&&f("chat")},[d,C,f]),Re.useEffect(()=>{const E=le=>{if(Cd(le)&&!le.shiftKey&&!le.altKey){const he=parseInt(le.key,10);he>=1&&he<=ss.length&&(le.preventDefault(),C&&(_t(),ue()),f(ss[he-1].id))}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[_t,ue,C,f,ss]),Re.useEffect(()=>{const E=le=>{const he=Ln("toggle_services_menu",h);if(Ad(le,he)){le.preventDefault(),Y?O(!1):(O(!0),ne());return}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[h,Y,ne]);const xn=E=>{const le=d===E.id,he=E.icon==="diff",He=he?null:E.icon,Qt=E.id==="chat",Dt=qt=>he?t.jsx(hi,{size:qt}):He?t.jsx(D,{name:He,className:`h-${qt/4} w-${qt/4}`}):null,Ys=t.jsxs("button",{type:"button",onClick:()=>f(E.id),className:_("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",le?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Qt&&!C&&"min-w-[100px] justify-center"),"aria-label":E.label,"aria-selected":le,role:"tab",children:[C?Dt(20):t.jsxs(t.Fragment,{children:[Dt(16),t.jsx("span",{className:"header-tab-label",children:E.label})]}),E.badge!==void 0&&E.badge>0&&t.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:E.badge})]});return t.jsx(i.Fragment,{children:Ys},E.id)},Ws=t.jsxs(t.Fragment,{children:[t.jsx(Am,{directory:Ze,className:"mr-1"}),T?t.jsx(Hm,{isDesktopApp:T,currentInstanceLabel:z,compactCurrentInstanceLabel:Z,currentInstanceIsLocal:X,isDesktopServicesOpen:Y,setIsDesktopServicesOpen:O,refreshCurrentInstanceLabel:ne,shortcutLabel:Yn,remoteUpdateInfo:se,remoteUpdateChecking:Q,remoteUpdateError:Ue,onOpenRemoteUpdate:ye}):null,t.jsx(Wm,{isMobile:C,githubAuthStatus:R,githubAccounts:ee,githubAvatarUrl:$,githubLogin:ke,isSwitchingGitHubAccount:Pe,handleGitHubAccountSwitch:Yt})]}),Cs=B&&(b||!!m),Qn=()=>t.jsxs("div",{onMouseDown:Ks,className:_("app-region-drag relative flex h-12 select-none items-center pr-3",gn),style:bn,role:"tablist","aria-label":"Main navigation",children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:ts}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:st}}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[yt?t.jsxs("div",{className:"mr-3 flex min-w-0 items-center gap-1.5 px-1 py-0.5 -my-0.5 text-left",children:[t.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:yt.title}),yt.subtitle?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),t.jsx("span",{className:"truncate typography-ui-label font-normal leading-tight text-muted-foreground/75 max-w-full",children:yt.subtitle})]}):null]}):t.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[u?null:t.jsx(i.Suspense,{fallback:t.jsx("button",{type:"button",className:jt,"aria-label":"Open session switcher",children:t.jsx(D,{name:"history",className:"h-[18px] w-[18px]"})}),children:t.jsx(qm,{align:"start",children:t.jsx("button",{type:"button",className:jt,"aria-label":"Open session switcher",children:t.jsx(D,{name:"history",className:"h-[18px] w-[18px]"})})})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 px-1",children:[ft?t.jsxs("form",{ref:je,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:E=>{E.preventDefault(),Se()},children:[t.jsx("input",{value:xt,onChange:E=>vt(E.target.value),autoFocus:!0,onKeyDown:E=>{E.stopPropagation(),E.key==="Escape"&&It(!1)},placeholder:"Rename",className:"min-w-0 flex-1 bg-transparent typography-ui-label font-normal leading-tight outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"submit","aria-label":"Save session name",title:"Save session name",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(D,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:()=>It(!1),"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(D,{name:"close",className:"size-4"})})]}):t.jsx("span",{className:"min-w-0 truncate typography-ui-label font-normal leading-tight text-foreground",children:b?"New session":Je}),Le?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate typography-ui-label font-normal leading-tight text-muted-foreground/75",children:[Ee?t.jsx("span",{className:"truncate",children:Ee}):null,te?t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[t.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),t.jsx("span",{className:"truncate",children:te})]}):null]})]}):null]}),t.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-center",children:m&&!b&&!ft?t.jsxs(Mt,{open:bt,onOpenChange:rt,onOpenChangeComplete:E=>{!E&&Xe.current&&(Xe.current=!1,Oe())},children:[t.jsx(Ft,{asChild:!0,children:t.jsx(Me,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":"Open session actions",children:t.jsx(D,{name:"more",className:"size-4"})})}),t.jsxs(Ot,{align:"end",className:"min-w-[190px]",children:[t.jsxs(tt,{onClick:()=>{Xe.current=!0},children:[t.jsx(D,{name:"pencil-ai",className:"mr-2 size-4"}),"Rename"]}),t.jsxs(tt,{onClick:Be,children:[t.jsx(D,{name:"file-copy",className:"mr-2 size-4"}),"Copy session ID"]}),t.jsxs(tt,{onClick:Rt,disabled:!Ze,children:[t.jsx(D,{name:"folder",className:"mr-2 size-4"}),"Copy working directory"]}),t.jsx(vs,{}),t.jsxs(tt,{onClick:()=>{Ye()},children:[t.jsx(D,{name:"download",className:"mr-2 size-4"}),"Export Markdown"]}),t.jsx(vs,{}),t.jsxs(tt,{onClick:()=>ht("archive"),children:[t.jsx(D,{name:"inbox-archive",className:"mr-2 size-4"}),"Archive"]}),t.jsxs(tt,{className:"text-destructive focus:text-destructive",onClick:()=>ht("delete"),children:[t.jsx(D,{name:"delete-bin",className:"mr-2 size-4"}),"Delete"]})]})]}):null})]}),ss.length>0&&t.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ss.map(E=>xn(E))}),t.jsx("div",{className:"flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(ba,{}),pt?t.jsx(gi,{projectRef:pt.projectRef,directory:pt.directory,className:"mr-1"}):null,t.jsx(If,{visible:Cs,title:b?"New Mini Chat Window":"Open Session in Mini Chat",ariaLabel:b?"Open a new Mini Chat window":"Open current session in Mini Chat",onClick:Gs,className:_(jt,"mr-1"),Icon:"picture-in-picture-2"}),Ws,t.jsx(_c,{visible:W})]})]})]}),qn=()=>t.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[N&&t.jsxs(t.Fragment,{children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:ts}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:st}})]}),!N&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e?t.jsx("button",{type:"button",onClick:at,className:_(Ut,it==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:t.jsx(D,{name:"layout-left",className:"h-5 w-5"})}):q?t.jsx("button",{type:"button",onClick:()=>l(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Back",children:t.jsx(D,{name:"arrow-left-s",className:"h-5 w-5"})}):t.jsx("button",{type:"button",onClick:$s,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Open sessions",children:t.jsx(D,{name:"play-list-add",className:"h-5 w-5"})}),!e&&q&&t.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),(!q||!!e)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:!A&&t.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain","data-no-drawer-swipe":"true",children:t.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:t.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":"Main navigation",children:ss.map(E=>{const le=d===E.id,he=E.icon==="diff",He=he?null:E.icon;return t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>{C&&(_t(),ue()),f(E.id)},"aria-label":E.label,"aria-selected":le,role:"tab",className:_(Ut,"relative rounded-lg",it===E.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[he?t.jsx(hi,{className:"h-5 w-5"}):He?t.jsx(D,{name:He,className:"h-5 w-5"}):null,E.badge!==void 0&&E.badge>0&&t.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:E.badge}),E.showDot&&t.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":"Changes available"})]})}),t.jsx(Ge,{children:t.jsx("p",{children:E.label})})]},E.id)})})})})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[A&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":"Workspace",children:j.map(E=>{const le=r&&o===E.id;return t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>{C&&(_t(),ue()),k(!1),a?.(E.id)},"aria-label":E.label,"aria-selected":le,role:"tab",className:_(Ut,"relative rounded-lg",le&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(D,{name:E.icon,className:"h-5 w-5"})})}),t.jsx(Ge,{children:t.jsx("p",{children:E.label})})]},E.id)})}),t.jsx(Af,{open:w,onOpenChange:k,currentSessionId:m,effectiveDirectory:Fe||null,isNewSessionDraftOpen:b})]}),pt&&t.jsx(gi,{projectRef:pt.projectRef,directory:pt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s&&!A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:lt,className:_(Ut,"relative",it==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:t.jsx(D,{name:"layout-right",className:"h-5 w-5"})})}),t.jsx(Ge,{children:t.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Hs=_("header-safe-area relative z-10 bg-background",C&&"border-b border-border/50");return t.jsxs(t.Fragment,{children:[t.jsx("header",{ref:P,className:Hs,style:{"--padding-scale":"1"},children:C?qn():Qn()}),t.jsx(Ym,{action:Bt,onClose:()=>ht(null),sessionTitle:Je,onConfirm:()=>{ot()}}),t.jsx(la,{open:ve,onOpenChange:xe,info:se,downloading:!1,downloaded:!1,progress:null,error:Ue,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})},bi="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",Vm="app-region-no-drag 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 disabled:pointer-events-none disabled:opacity-50",Qg=()=>{const e=ce(m=>m.isSidebarOpen),s=ce(m=>m.toggleSidebar),n=ce(m=>m.shortcutOverrides),r=i.useRef(null),o=i.useRef(null),a=qr(Ln("toggle_sidebar",n)),l=Ei(),{enabled:c}=Wr(),u=!e,d=l,f=u||d,h=d,b=i.useCallback(()=>{nn("desktop_show_app_menu").catch(m=>{console.warn("[titlebar] failed to open app menu",m)})},[]);return i.useEffect(()=>{if(typeof document>"u")return;const m=y=>{document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(y)}px`)},g=y=>{document.documentElement.style.setProperty("--oc-titlebar-overlay-width",`${Math.round(y)}px`)};if(!h)return;const p=o.current,v=r.current;if(!p||!v){m(0),g(0);return}const x=()=>{const y=Math.max(p.getBoundingClientRect().width,p.scrollWidth);m(y),g(v.getBoundingClientRect().width)};if(x(),typeof ResizeObserver>"u")return;const I=new ResizeObserver(x);return I.observe(p),I.observe(v),()=>{I.disconnect()}},[h]),f?t.jsx("div",{ref:r,className:"app-region-no-drag absolute left-0 z-40 flex select-none items-center pr-2",style:{top:"var(--oc-safe-area-top, 0px)",height:"calc(var(--oc-header-height, 3rem) - var(--oc-safe-area-top, 0px))",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},children:t.jsxs("div",{ref:o,className:"flex items-center gap-2",children:[d?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,"aria-label":"Open PiChamber menu",className:_(bi,"shrink-0"),children:t.jsx(D,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),t.jsx(Ge,{children:t.jsx("p",{children:"PiChamber menu"})})]}):null,u?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:s,"aria-label":"Open sessions",className:_(c?Vm:bi,"shrink-0"),children:t.jsx(D,{name:"layout-left",className:c?"size-[18px]":"h-[18px] w-[18px]"})})}),t.jsx(Ge,{children:t.jsx("p",{children:`Open sessions (${a})`})})]}):null]})}):null},xi=200,Jm="cubic-bezier(0.22, 1, 0.36, 1)",qg=e=>{const s=i.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[n,r]=i.useState(e),[o,a]=i.useState(e);return i.useLayoutEffect(()=>{if(s){a(e),r(e);return}if(e){a(!0),r(!1);let c=0;const u=window.requestAnimationFrame(()=>{c=window.requestAnimationFrame(()=>r(!0))});return()=>{window.cancelAnimationFrame(u),window.cancelAnimationFrame(c)}}r(!1);const l=window.setTimeout(()=>a(!1),xi);return()=>window.clearTimeout(l)},[e,s]),{slidIn:n,layoutVisible:o,prefersReducedMotion:s,transition:s?"none":`transform ${xi}ms ${Jm}`}},Vg=()=>{Li()},Jg=e=>{Ie.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ce.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),pe.getState().clearAll(),Li(),Os.getState().resetForRuntimeSwitch(),Uc.getState().resetForRuntimeSwitch(),zc.getState().resetForRuntimeSwitch(),$c(),Gc.getState().resetForRuntimeSwitch(),$t.setState({providers:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),dt.getState().resetForRuntimeSwitch(),Kc(),Wc(),ru.getState().reset(),Nd.getState().resetForRuntimeSwitch(),Ai.getState().resetForRuntimeSwitch(e.runtimeKey),Cr.getState().resetForRuntimeSwitch(e.runtimeKey),ys.getState().resetForRuntimeSwitch(e.runtimeKey),dh.getState().resetForRuntimeSwitch(),ct.getState().resetForRuntimeSwitch(e.runtimeKey),Id.getState().resetForRuntimeSwitch(e.runtimeKey),Ie.getState().restoreForRuntimeSwitch(e.runtimeKey),ce.getState().restoreForRuntimeSwitch(e.runtimeKey);const s=ce.getState();Mr({sessionId:Ie.getState().currentSessionId,tab:s.activeMainTab,isSettingsOpen:s.isSettingsDialogOpen,settingsPath:s.settingsPage,diffFile:s.pendingDiffFile},{replace:!0,force:!0})};export{yf as $,_g as A,Ko as B,Bg as C,ii as D,Hg as E,wg as F,Du as G,Yg as H,bg as I,fs as J,yu as K,hs as L,ga as M,vg as N,Zu as O,Tg as P,Qu as Q,jg as R,Ug as S,Kg as T,Dg as U,la as V,gg as W,Xr as X,Ig as Y,Xu as Z,ua as _,kf as a,Yu as a0,ef as a1,hn as a2,ca as a3,pn as a4,rn as a5,qu as a6,kg as a7,Vu as a8,Pg as a9,Og as aa,Fg as ab,tf as ac,Eg as ad,Mg as ae,Lg as af,Sg as ag,Cg as ah,Ag as ai,Ng as aj,pf as ak,Rg as al,Pu as am,Ju as an,Tu as ao,pg as ap,Af as b,Xs as c,Rp as d,zg as e,Fn as f,$g as g,qg as h,Pp as i,Wg as j,Qg as k,Jg as l,xg as m,yg as n,mg as o,hg as p,Zr as q,Vg as r,Gg as s,eo as t,Tn as u,to as v,Ms as w,ma as x,wf as y,vf as z};
|
|
53
|
+
`));await o.sendInput(oe,`${Fe}\r`),We?(I(ee,re,We,{locked:!0,autoOpened:!0}),h(ee,We),ie.success("Opened action URL")):ye?(I(ee,re,null,{locked:!0}),ie.error("Invalid custom URL format")):I(ee,re,null,{locked:!1,autoOpened:!1})}catch(be){A(Z),delete B.current[Z],G.current[Z]?.(),delete G.current[Z],window.clearTimeout(L.current[Z]),delete L.current[Z],ie.error(be instanceof Error?be.message:"Failed to run action")}finally{M.current.delete(Z)}}},[r.colors.surface.background,r.colors.syntax.base.foreground,r.metadata.variant,z,n,a,ee,c,l,h,y,A,v,C,I,x,q?.id,o]),X=i.useCallback(async K=>{const Z=Xt(ee,K.id),ne=y[Z];if(!ne)return;N(Z,"stopping");const be=Gm(o,ne.sessionId,1e3);try{await o.sendInput(ne.sessionId,"")}catch{}const ye=await be;if(pe.getState().getDirectoryState(ne.directory)?.tabs.find(re=>re.id===ne.tabId)?.terminalSessionId===ne.sessionId&&!ye){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:ne.sessionId})}catch{}else try{await o.close(ne.sessionId)}catch{}x(ne.directory,ne.tabId,null)}A(Z),delete B.current[Z],G.current[Z]?.(),delete G.current[Z],window.clearTimeout(L.current[Z]),delete L.current[Z]},[ee,y,A,x,o,N]),ge=i.useCallback(()=>{const K=Pe??O[0];if(!K)return;const Z=Xt(ee,K.id),ne=y[Z];if(ne?.status!=="stopping"){if(ne){X(K);return}J(K)}},[O,ee,J,y,Pe,X]),ve=i.useCallback((K,Z=!1)=>{if(R(K.id),!Z){J(K);return}const ne=Xt(ee,K.id),be=y[ne];if(be?.status!=="stopping"){if(be){X(K);return}J(K)}},[ee,J,y,X]),xe=i.useCallback(()=>{q?.id&&(f(q.id),u("projects"),d(!0))},[d,u,f,q?.id]),se=Pe??O[0]??null,de=se?y[Xt(ee,se.id)]:null,Q=pe(K=>de?K.sessions.get(de.directory)?.tabs.find(Z=>Z.id===de.tabId)?.previewUrl??null:null),me=!!((n||!a)&&q&&ee),Ue=Pe??O[0]??null;return{shouldRender:me,isLoading:P,normalizedDirectory:ee,resolvedSelected:Ue,displayActions:O,projectActionRuns:y,selectedRunPreviewUrl:Q,handlePrimaryClick:ge,handleSelectAction:ve,openProjectActionsSettings:xe,openContextPreview:h}}const gi=({projectRef:e,directory:s,className:n,compact:r=!1,allowMobile:o=!1})=>{const{shouldRender:a,isLoading:l,normalizedDirectory:c,resolvedSelected:u,displayActions:d,projectActionRuns:f,selectedRunPreviewUrl:h,handlePrimaryClick:b,handleSelectAction:m,openProjectActionsSettings:g,openContextPreview:p}=Km({projectRef:e,directory:s,allowMobile:o});if(!a||!u)return null;const v=u.icon||"play",x=u.id===wt?"scan-2":on[v]||"play",I=Xt(c,u.id),y=f[I],C=y?.status==="stopping",N=y?.status==="waiting-for-preview",A=!!(y&&h),j=()=>{!y||!h||p(y.directory,h)},w=u.id===wt;return r?t.jsxs("div",{className:"inline-flex items-center",children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",disabled:l||C,className:_("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:b,"aria-label":y?`Stop ${u.name}`:`Run ${u.name}`,children:C||N?t.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):y?t.jsx(D,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):t.jsx(D,{name:x,className:"h-5 w-5"})})}),w?t.jsx(Ge,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Open Preview",onClick:j,children:t.jsx(D,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ge,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Choose project action",children:t.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),t.jsxs(Ot,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(tt,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(D,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(vs,{}),d.map(k=>{const R=k.icon||"play",P=k.id===wt?"scan-2":on[R]||"play",T=Xt(c,k.id),F=f[T],B=!!F,G=F?.status==="stopping";return t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{m(k,!0)},children:[t.jsx(D,{name:P,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),G||F?.status==="waiting-for-preview"?t.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):B?t.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]}):t.jsxs("div",{className:_("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,disabled:l||C,className:_("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":y?`Stop ${u.name}`:`Run ${u.name}`,children:t.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:C||N?t.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):y?t.jsx(D,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):t.jsx(D,{name:x,className:"h-4 w-4"})})})}),w?t.jsx(Ge,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:j,className:_(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":"Open Preview",children:t.jsx(D,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ge,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:_(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":"Choose project action",children:t.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Ot,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(tt,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(D,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(vs,{}),d.map(k=>{const R=k.icon||"play",P=k.id===wt?"scan-2":on[R]||"play",T=Xt(c,k.id),F=f[T],B=!!F,G=F?.status==="stopping";return t.jsxs(tt,{className:"flex items-center gap-2",onClick:()=>{m(k,!0)},children:[t.jsx(D,{name:P,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),G||F?.status==="waiting-for-preview"?t.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):B?t.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]})},Wm=i.memo(function({isMobile:s,githubAuthStatus:n,githubAccounts:r,githubAvatarUrl:o,githubLogin:a,isSwitchingGitHubAccount:l,handleGitHubAccountSwitch:c}){return!n?.connected||s?null:r.length>1?t.jsxs(Mt,{children:[t.jsx(Ft,{asChild:!0,children:t.jsx("button",{type:"button",className:_(mn,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),title:a?`GitHub: ${a}`:"GitHub connected",disabled:l,children:o?t.jsx("img",{src:o,alt:a?`${a} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),t.jsxs(Ot,{align:"end",className:"w-64",children:[t.jsx(Pc,{className:"typography-ui-header font-semibold text-foreground",children:"GitHub Accounts"}),t.jsx(vs,{}),r.map(u=>{const d=u.user,f=!!u.current,h=u.source==="gh-cli"?"CLI":"OAuth";return t.jsxs(tt,{className:"gap-2",disabled:l,onSelect:()=>{f||c(u.id)},children:[d?.avatarUrl?t.jsx("img",{src:d.avatarUrl,alt:d.login?`${d.login} avatar`:"GitHub avatar",className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:t.jsx(D,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsx("span",{className:"truncate typography-ui-label text-foreground",children:d?.name?.trim()||d?.login||"GitHub"}),d?.login?t.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[t.jsx("span",{className:"font-mono",children:d.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:h})]}):null]}),f?t.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null]},u.id)})]})]}):t.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:a?`GitHub: ${a}`:"GitHub connected",children:o?t.jsx("img",{src:o,alt:a?`${a} avatar`:"GitHub avatar",className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):t.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),Hm=i.memo(function({isDesktopApp:s,currentInstanceLabel:n,compactCurrentInstanceLabel:r,currentInstanceIsLocal:o,isDesktopServicesOpen:a,setIsDesktopServicesOpen:l,refreshCurrentInstanceLabel:c,shortcutLabel:u,remoteUpdateInfo:d,remoteUpdateChecking:f,remoteUpdateError:h,onOpenRemoteUpdate:b}){return t.jsxs(Mt,{open:a,onOpenChange:m=>{l(m),m&&c()},children:[t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx(Ft,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":s?`Open instance, usage and MCP (current: ${n})`:"Open services, usage and MCP",className:_(mn,s?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[t.jsx(D,{name:"server",className:"h-[18px] w-[18px]"}),s?t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:r}):null]})})}),t.jsx(Ge,{children:t.jsx("p",{children:`Current instance: ${n} (${u("toggle_services_menu")})`})})]}),t.jsx(Ot,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:s?t.jsxs("div",{children:[o?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:"Remote instance update"}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:d?.available?`Version ${d.version||""} is available for this instance.`:f?"Looking for updates...":h||"This instance is up to date."})]}),d?.available?t.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:b,children:"Update"}):null]})}),t.jsx(Tc,{embedded:!0,open:a,onOpenChange:()=>{},onHostSwitched:()=>l(!1)})]}):null})]})}),Ym=({action:e,onClose:s,sessionTitle:n,onConfirm:r})=>t.jsx(Kt,{open:e!==null,onOpenChange:o=>{o||s()},children:t.jsxs(Wt,{showCloseButton:!1,className:"max-w-sm gap-5",children:[t.jsxs(ls,{children:[t.jsx(es,{children:e==="delete"?"Delete session?":"Archive session?"}),t.jsx(cs,{children:e==="delete"?`"${n}" will be permanently deleted.`:`"${n}" will be archived.`})]}),t.jsxs(Ss,{children:[t.jsx(Me,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),t.jsx(Me,{variant:"destructive",size:"sm",onClick:r,children:e==="delete"?"Delete":"Archive"})]})]})}),Qm=e=>{const s=e.trim();if(!s)return"";const n=s.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),a=`${r} ${o}`.trim();return n.length>2||a.length<s.length?`${a}...`:a}return s.length>12?`${s.slice(0,9).trimEnd()}...`:s},Js=e=>{if(!e)return"";const s=e.replace(/\\/g,"/");return s==="/"?"/":s.replace(/\/+$/,"")},qm=i.lazy(()=>is(()=>import("./SessionSwitcherDropdown-Cw_g3ai3.js"),__vite__mapDeps([116,24,4,5,1,2,3,6,7,8,9,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])).then(e=>({default:e.SessionSwitcherDropdown}))),Yg=({onToggleLeftDrawer:e,onToggleRightDrawer:s,leftDrawerOpen:n,rightDrawerOpen:r,tabletWorkspaceTab:o,onSelectTabletWorkspaceTab:a})=>{Tt("ui.header.render");const l=ce(E=>E.setSessionSwitcherOpen),c=ce(E=>E.toggleSidebar),u=ce(E=>E.isSidebarOpen),d=ce(E=>E.activeMainTab),f=ce(E=>E.setActiveMainTab),h=ce(E=>E.shortcutOverrides);ce(E=>E.timeFormatPreference),zs();const b=Ie(E=>!!E.newSessionDraft?.open),m=Ie(E=>E.currentSessionId),g=Ri(m??""),p=Mc(m),v=i.useMemo(()=>{if(!p)return null;const E=p;return{title:p.title??null,directory:E.directory??null,created:p.time?.created??null,slug:E.slug??null,shareUrl:p.share?.url??null,parentId:p.parentID??null}},[p]),x=dt(Pr(E=>{if(!E.activeProjectId)return null;const le=E.projects.find(he=>he.id===E.activeProjectId);return le?{id:le.id,path:le.path,label:le.label}:null})),I=Os(E=>E.homeDirectory),y=i.useMemo(()=>{if(!x)return null;const E=x.label?.trim();if(E)return E;const le=x.path.split(/[\\/]/).filter(Boolean);return le[le.length-1]??null},[x]),{isMobile:C}=Us(),{enabled:N}=Wr(),A=!!(N&&a&&o!==void 0),j=i.useMemo(()=>[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"}],[]),[w,k]=i.useState(!1),R=null,P=i.useRef(null),[T,F]=i.useState(()=>typeof window>"u"?!1:Fs()),B=i.useMemo(()=>Fi(),[]),G=Fc(),[L,M]=i.useState(!1),U=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),W=Ei(),ae=i.useMemo(()=>{if(typeof window>"u")return null;const E=window.__PICHAMBER_MACOS_MAJOR__;if(typeof E=="number"&&Number.isFinite(E)&&E>0)return E;if(typeof navigator>"u")return null;const le=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!le)return null;const he=Number.parseInt(le[1],10),He=Number.parseInt(le[2],10);return Number.isNaN(he)?null:he===10?He:he},[]);Re.useEffect(()=>{typeof window>"u"||F(Fs())},[]);const q=ce(E=>E.isSessionSwitcherOpen),$=null,ke=null,ee=[],[Pe,_e]=i.useState(!1),[Y,O]=i.useState(!1),[z,J]=i.useState("Local"),[X,ge]=i.useState(!0),[ve,xe]=i.useState(!1),[se,de]=i.useState(null),[Q,me]=i.useState(!1),[Ue,K]=i.useState(null),Z=i.useMemo(()=>Qm(z),[z]),ne=i.useCallback(async()=>{if(!(typeof window>"u"||!T))try{if(cn()){J("Local"),ge(!0);return}ge(!1);const E=await xd(),le=yd(),he=wd([vd(le),...E.hosts]);if(he.id===Sd){J("Local"),ge(!0);return}J(jd(he.label.trim()||"Instance"))}catch{J("Local"),ge(!0)}},[T]);Re.useEffect(()=>(ne(),kd(()=>{ne()})),[ne]);const be=i.useCallback(async()=>{if(X){de(null),K(null);return}me(!0),K(null);try{const E=new URLSearchParams({appType:"web",instanceMode:"remote"}),le=await At(`/api/pi/update-check?${E.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!le.ok)throw new Error(`Server responded with ${le.status}`);const he=await le.json();de({available:he.available??!1,version:he.version,currentVersion:he.currentVersion??"unknown",body:he.body,nextSuggestedCheckInSec:typeof he.nextSuggestedCheckInSec=="number"?he.nextSuggestedCheckInSec:void 0,packageManager:he.packageManager,updateCommand:he.updateCommand})}catch(E){de(null),K(E instanceof Error?E.message:"Failed to check remote instance updates")}finally{me(!1)}},[X]);i.useEffect(()=>{de(null),K(null),xe(!1)},[X,z]),i.useEffect(()=>{if(!T||X)return;const E=3e3,le=3600*1e3;let he=!1,He=null;const Qt=Dt=>{He=window.setTimeout(()=>{if(he||typeof document<"u"&&document.visibilityState!=="visible"){Qt(le);return}be().finally(()=>{he||Qt(le)})},Dt)};return Qt(E),()=>{he=!0,He!==null&&window.clearTimeout(He)}},[be,X,z,T]);const ye=i.useCallback(()=>{if(se?.available){xe(!0);return}be()},[be,se?.available]),Ne=m?v??null:null,we=i.useRef(null),[re,fe]=i.useState(0);i.useEffect(()=>{if(!m){we.current&&(we.current=null,fe(He=>He+1));return}if(Ne){we.current={sessionId:m,session:Ne,expiresAt:Date.now()+2e3};return}const E=we.current;if(!E||E.sessionId!==m)return;const le=E.expiresAt-Date.now();if(le<=0){we.current=null,fe(He=>He+1);return}const he=window.setTimeout(()=>{we.current?.sessionId===m&&(we.current=null),fe(He=>He+1)},le);return()=>{window.clearTimeout(he)}},[m,Ne]);const oe=(()=>{if(Ne)return Ne;if(!m)return null;const E=we.current;return E&&E.sessionId===m&&E.expiresAt>Date.now()?E.session:null})(),Te=i.useMemo(()=>{const E=typeof oe?.directory=="string"?oe.directory:"";return Js(E||"")},[oe?.directory]),We=Ie(E=>E.newSessionDraft?.open?Js(E.newSessionDraft.directoryOverride??""):""),Fe=i.useMemo(()=>vm({sessionDirectory:Te,draftDirectory:We,isNewSessionDraftOpen:b}),[We,b,Te]),te=Ii(Fe||null),Ee=i.useMemo(()=>Sm({activeProjectLabel:y,openDirectory:Fe,homeDirectory:I}),[y,I,Fe]),Le=!!(Ee||te),Je=i.useMemo(()=>m?as(oe):Ee??"PiChamber",[oe,m,Ee]),ut=Oc(),Ve=Ie(E=>E.updateSessionTitle),Lt=Ie(E=>E.archiveSessions),Nt=Ie(E=>E.deleteSessions),[ft,It]=i.useState(!1),[bt,rt]=i.useState(!1),Xe=i.useRef(!1),[xt,vt]=i.useState(""),[Bt,ht]=i.useState(null),je=i.useRef(null);i.useEffect(()=>{Xe.current=!1,rt(!1),It(!1),vt(""),ht(null)},[m]);const Oe=i.useCallback(()=>{m&&(vt(oe?.title?.trim()||Je),It(!0))},[oe?.title,m,Je]),Se=i.useCallback(async()=>{if(!m)return;const E=xt.trim();E&&E!==oe?.title?.trim()&&await Ve(m,E),It(!1)},[oe?.title,m,xt,Ve]);i.useEffect(()=>{if(!ft)return;const E=le=>{const he=le.target;(!he||!je.current?.contains(he))&&Se()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[ft,Se]);const Be=i.useCallback(()=>{m&&ws(m).then(E=>{ie[E.ok?"success":"error"](E.ok?"Session ID copied":"Failed to copy session ID")}).catch(()=>ie.error("Failed to copy session ID"))},[m]),Ye=i.useCallback(async()=>{if(!m||!Fe){ie.error("Nothing to export");return}try{await ut.syncSession(m)}catch{ie.error("Failed to load the complete session history");return}const E=[];if(E.length===0){ie.error("Nothing to export");return}const le=Da(E,oe?.title??null),he=Ta(oe?.title??null);await Pa(le,he)||Ea(le,he),ie.success("Session exported")},[oe?.title,m,Fe,ut]);g?.type==="busy"||g?.type;const ot=i.useCallback(async()=>{if(!m||!Bt)return;const E=Lc(),le=[m];for(let Dt=0;Dt<le.length;Dt+=1){const Ys=le[Dt];for(const qt of E)qt.parentID===Ys&&!le.includes(qt.id)&&le.push(qt.id)}const he=Bt;if(ht(null),(he==="archive"?await Lt(le):await Nt(le)).failedIds.length>0){ie.error(he==="archive"?"Failed to archive session":"Failed to delete session");return}ie.success(he==="archive"?"Session archived":"Session deleted")},[Lt,m,Nt,Bt]),St=ce(E=>E.isArchivePageOpen),yt=i.useMemo(()=>St?{title:"Archive",subtitle:null}:null,[St]),Ze=i.useMemo(()=>Js(Fe||x?.path||""),[x?.path,Fe]),Rt=i.useCallback(()=>{Ze&&ws(Ze).then(E=>{ie[E.ok?"success":"error"](E.ok?"Working directory copied":"Failed to copy working directory")}).catch(()=>ie.error("Failed to copy working directory"))},[Ze]),Qe=i.useMemo(()=>x?{id:x.id,path:x.path}:null,[x]),Ht=i.useRef(null);i.useEffect(()=>{!Qe||!Ze||(Ht.current={projectRef:Qe,directory:Ze})},[Ze,Qe]);const pt=i.useMemo(()=>Qe&&Ze?{projectRef:Qe,directory:Ze}:Ht.current,[Ze,Qe]),Yt=i.useCallback(async E=>{},[]),_t=i.useCallback(()=>{if(typeof document>"u")return;const E=document.activeElement;if(!E)return;const le=E.tagName;(le==="INPUT"||le==="TEXTAREA"||le==="SELECT"||E.isContentEditable)&&E.blur()},[]),$s=i.useCallback(()=>{if(C){_t(),l(!q);return}c()},[_t,C,q,l,c]),ds=i.useCallback(()=>{nn("desktop_open_draft_mini_chat_window",{directory:Js(Fe||x?.path||""),projectId:x?.id??null,apiBaseUrl:Ir(),clientToken:Nr()}).catch(E=>{console.warn("[header] failed to open draft mini chat window",E)})},[x?.id,x?.path,Fe]),Gs=i.useCallback(()=>{if(b){ds();return}m&&nn("desktop_open_session_mini_chat_window",{sessionId:m,directory:Js(Fe||x?.path||""),apiBaseUrl:Ir(),clientToken:Nr()}).catch(E=>{console.warn("[header] failed to open session mini chat window",E)})},[x?.path,m,ds,b,Fe]),jt=mn,Ut=Nf,it=i.useMemo(()=>n?"sessions":A?r&&o?o:null:r?"git":d,[d,A,n,r,o]),ue=i.useCallback(()=>{n&&e&&e(),r&&s&&s(),!e&&q&&l(!1)},[q,n,e,s,r,l]),at=i.useCallback(()=>{e?.()},[e]),lt=i.useCallback(()=>{s?.()},[s]),mt=i.useMemo(()=>T&&U&&!L?"5.5rem":G?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":!T||W?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[T,L,U,G,W]);Re.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",mt)},[mt]);const ts=u?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",st=u?"0px":T&&W?"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)":N?"2.75rem":"2.5rem";Re.useEffect(()=>{if(!T||!U){M(!1);return}let E=!1;const le=async()=>{try{const He=await nn("desktop_is_window_fullscreen");E||M(He===!0)}catch{E||M(!1)}},he=()=>{le()};return le(),window.addEventListener("pichamber:window-resized",he),()=>{E=!0,window.removeEventListener("pichamber:window-resized",he)}},[T,U]);const gn=i.useMemo(()=>!T||!U||ae===null?"":ae>=26?"h-12":ae<=15?"h-14":"",[T,U,ae]),bn=i.useMemo(()=>{if(!(T&&!W))return{paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[T,W]),us=i.useCallback(()=>{if(typeof document>"u")return;const E=P.current?.getBoundingClientRect().height;E&&document.documentElement.style.setProperty("--oc-header-height",`${E}px`)},[]);Re.useEffect(()=>{if(typeof window>"u")return;us();const E=P.current;if(!E||typeof ResizeObserver>"u")return()=>{};let le=0;const he=()=>{le||(le=requestAnimationFrame(()=>{le=0,us()}))},He=new ResizeObserver(he);return He.observe(E),window.addEventListener("resize",he),window.addEventListener("orientationchange",he),()=>{le&&cancelAnimationFrame(le),He.disconnect(),window.removeEventListener("resize",he),window.removeEventListener("orientationchange",he)}},[us]),Re.useEffect(()=>{us()},[us,C,gn]);const Ks=i.useCallback(async E=>{const le=E.target;le.closest(".app-region-no-drag")||le.closest("button, a, input, select, textarea")||E.button===0&&T&&await Bc()},[T]),ss=i.useMemo(()=>C?[{id:"chat",label:"Chat",icon:"chat-4"},{id:"diff",label:"Diff",icon:"diff"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"},{id:"context",label:"Context",icon:"file-list-2"},{id:"diagram",label:"Diagram",icon:"file"}]:[],[C]),Yn=i.useCallback(E=>qr(Ln(E,h)),[h]);Re.useEffect(()=>{!C&&d!=="chat"&&d!=="terminal"&&d!=="diagram"&&f("chat")},[d,C,f]),Re.useEffect(()=>{const E=le=>{if(Cd(le)&&!le.shiftKey&&!le.altKey){const he=parseInt(le.key,10);he>=1&&he<=ss.length&&(le.preventDefault(),C&&(_t(),ue()),f(ss[he-1].id))}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[_t,ue,C,f,ss]),Re.useEffect(()=>{const E=le=>{const he=Ln("toggle_services_menu",h);if(Ad(le,he)){le.preventDefault(),Y?O(!1):(O(!0),ne());return}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[h,Y,ne]);const xn=E=>{const le=d===E.id,he=E.icon==="diff",He=he?null:E.icon,Qt=E.id==="chat",Dt=qt=>he?t.jsx(hi,{size:qt}):He?t.jsx(D,{name:He,className:`h-${qt/4} w-${qt/4}`}):null,Ys=t.jsxs("button",{type:"button",onClick:()=>f(E.id),className:_("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",le?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Qt&&!C&&"min-w-[100px] justify-center"),"aria-label":E.label,"aria-selected":le,role:"tab",children:[C?Dt(20):t.jsxs(t.Fragment,{children:[Dt(16),t.jsx("span",{className:"header-tab-label",children:E.label})]}),E.badge!==void 0&&E.badge>0&&t.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:E.badge})]});return t.jsx(i.Fragment,{children:Ys},E.id)},Ws=t.jsxs(t.Fragment,{children:[t.jsx(Am,{directory:Ze,className:"mr-1"}),T?t.jsx(Hm,{isDesktopApp:T,currentInstanceLabel:z,compactCurrentInstanceLabel:Z,currentInstanceIsLocal:X,isDesktopServicesOpen:Y,setIsDesktopServicesOpen:O,refreshCurrentInstanceLabel:ne,shortcutLabel:Yn,remoteUpdateInfo:se,remoteUpdateChecking:Q,remoteUpdateError:Ue,onOpenRemoteUpdate:ye}):null,t.jsx(Wm,{isMobile:C,githubAuthStatus:R,githubAccounts:ee,githubAvatarUrl:$,githubLogin:ke,isSwitchingGitHubAccount:Pe,handleGitHubAccountSwitch:Yt})]}),Cs=B&&(b||!!m),Qn=()=>t.jsxs("div",{onMouseDown:Ks,className:_("app-region-drag relative flex h-12 select-none items-center pr-3",gn),style:bn,role:"tablist","aria-label":"Main navigation",children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:ts}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:st}}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[yt?t.jsxs("div",{className:"mr-3 flex min-w-0 items-center gap-1.5 px-1 py-0.5 -my-0.5 text-left",children:[t.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:yt.title}),yt.subtitle?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),t.jsx("span",{className:"truncate typography-ui-label font-normal leading-tight text-muted-foreground/75 max-w-full",children:yt.subtitle})]}):null]}):t.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[u?null:t.jsx(i.Suspense,{fallback:t.jsx("button",{type:"button",className:jt,"aria-label":"Open session switcher",children:t.jsx(D,{name:"history",className:"h-[18px] w-[18px]"})}),children:t.jsx(qm,{align:"start",children:t.jsx("button",{type:"button",className:jt,"aria-label":"Open session switcher",children:t.jsx(D,{name:"history",className:"h-[18px] w-[18px]"})})})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 px-1",children:[ft?t.jsxs("form",{ref:je,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:E=>{E.preventDefault(),Se()},children:[t.jsx("input",{value:xt,onChange:E=>vt(E.target.value),autoFocus:!0,onKeyDown:E=>{E.stopPropagation(),E.key==="Escape"&&It(!1)},placeholder:"Rename",className:"min-w-0 flex-1 bg-transparent typography-ui-label font-normal leading-tight outline-none placeholder:text-muted-foreground"}),t.jsx("button",{type:"submit","aria-label":"Save session name",title:"Save session name",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(D,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:()=>It(!1),"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(D,{name:"close",className:"size-4"})})]}):t.jsx("span",{className:"min-w-0 truncate typography-ui-label font-normal leading-tight text-foreground",children:b?"New session":Je}),Le?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-3 w-px shrink-0 bg-border"}),t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate typography-ui-label font-normal leading-tight text-muted-foreground/75",children:[Ee?t.jsx("span",{className:"truncate",children:Ee}):null,te?t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[t.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),t.jsx("span",{className:"truncate",children:te})]}):null]})]}):null]}),t.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-center",children:m&&!b&&!ft?t.jsxs(Mt,{open:bt,onOpenChange:rt,onOpenChangeComplete:E=>{!E&&Xe.current&&(Xe.current=!1,Oe())},children:[t.jsx(Ft,{asChild:!0,children:t.jsx(Me,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":"Open session actions",children:t.jsx(D,{name:"more",className:"size-4"})})}),t.jsxs(Ot,{align:"end",className:"min-w-[190px]",children:[t.jsxs(tt,{onClick:()=>{Xe.current=!0},children:[t.jsx(D,{name:"pencil-ai",className:"mr-2 size-4"}),"Rename"]}),t.jsxs(tt,{onClick:Be,children:[t.jsx(D,{name:"file-copy",className:"mr-2 size-4"}),"Copy session ID"]}),t.jsxs(tt,{onClick:Rt,disabled:!Ze,children:[t.jsx(D,{name:"folder",className:"mr-2 size-4"}),"Copy working directory"]}),t.jsx(vs,{}),t.jsxs(tt,{onClick:()=>{Ye()},children:[t.jsx(D,{name:"download",className:"mr-2 size-4"}),"Export Markdown"]}),t.jsx(vs,{}),t.jsxs(tt,{onClick:()=>ht("archive"),children:[t.jsx(D,{name:"inbox-archive",className:"mr-2 size-4"}),"Archive"]}),t.jsxs(tt,{className:"text-destructive focus:text-destructive",onClick:()=>ht("delete"),children:[t.jsx(D,{name:"delete-bin",className:"mr-2 size-4"}),"Delete"]})]})]}):null})]}),ss.length>0&&t.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ss.map(E=>xn(E))}),t.jsx("div",{className:"flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(ba,{}),pt?t.jsx(gi,{projectRef:pt.projectRef,directory:pt.directory,className:"mr-1"}):null,t.jsx(If,{visible:Cs,title:b?"New Mini Chat Window":"Open Session in Mini Chat",ariaLabel:b?"Open a new Mini Chat window":"Open current session in Mini Chat",onClick:Gs,className:_(jt,"mr-1"),Icon:"picture-in-picture-2"}),Ws,t.jsx(_c,{visible:W})]})]})]}),qn=()=>t.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[N&&t.jsxs(t.Fragment,{children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:ts}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:st}})]}),!N&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e?t.jsx("button",{type:"button",onClick:at,className:_(Ut,it==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:t.jsx(D,{name:"layout-left",className:"h-5 w-5"})}):q?t.jsx("button",{type:"button",onClick:()=>l(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Back",children:t.jsx(D,{name:"arrow-left-s",className:"h-5 w-5"})}):t.jsx("button",{type:"button",onClick:$s,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":"Open sessions",children:t.jsx(D,{name:"play-list-add",className:"h-5 w-5"})}),!e&&q&&t.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),(!q||!!e)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:!A&&t.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain","data-no-drawer-swipe":"true",children:t.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:t.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":"Main navigation",children:ss.map(E=>{const le=d===E.id,he=E.icon==="diff",He=he?null:E.icon;return t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>{C&&(_t(),ue()),f(E.id)},"aria-label":E.label,"aria-selected":le,role:"tab",className:_(Ut,"relative rounded-lg",it===E.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[he?t.jsx(hi,{className:"h-5 w-5"}):He?t.jsx(D,{name:He,className:"h-5 w-5"}):null,E.badge!==void 0&&E.badge>0&&t.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:E.badge}),E.showDot&&t.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":"Changes available"})]})}),t.jsx(Ge,{children:t.jsx("p",{children:E.label})})]},E.id)})})})})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[A&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":"Workspace",children:j.map(E=>{const le=r&&o===E.id;return t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>{C&&(_t(),ue()),k(!1),a?.(E.id)},"aria-label":E.label,"aria-selected":le,role:"tab",className:_(Ut,"relative rounded-lg",le&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(D,{name:E.icon,className:"h-5 w-5"})})}),t.jsx(Ge,{children:t.jsx("p",{children:E.label})})]},E.id)})}),t.jsx(Af,{open:w,onOpenChange:k,currentSessionId:m,effectiveDirectory:Fe||null,isNewSessionDraftOpen:b})]}),pt&&t.jsx(gi,{projectRef:pt.projectRef,directory:pt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s&&!A?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:lt,className:_(Ut,"relative",it==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:t.jsx(D,{name:"layout-right",className:"h-5 w-5"})})}),t.jsx(Ge,{children:t.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Hs=_("header-safe-area relative z-10 bg-background",C&&"border-b border-border/50");return t.jsxs(t.Fragment,{children:[t.jsx("header",{ref:P,className:Hs,style:{"--padding-scale":"1"},children:C?qn():Qn()}),t.jsx(Ym,{action:Bt,onClose:()=>ht(null),sessionTitle:Je,onConfirm:()=>{ot()}}),t.jsx(la,{open:ve,onOpenChange:xe,info:se,downloading:!1,downloaded:!1,progress:null,error:Ue,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})},bi="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",Vm="app-region-no-drag 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 disabled:pointer-events-none disabled:opacity-50",Qg=()=>{const e=ce(m=>m.isSidebarOpen),s=ce(m=>m.toggleSidebar),n=ce(m=>m.shortcutOverrides),r=i.useRef(null),o=i.useRef(null),a=qr(Ln("toggle_sidebar",n)),l=Ei(),{enabled:c}=Wr(),u=!e,d=l,f=u||d,h=d,b=i.useCallback(()=>{nn("desktop_show_app_menu").catch(m=>{console.warn("[titlebar] failed to open app menu",m)})},[]);return i.useEffect(()=>{if(typeof document>"u")return;const m=y=>{document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(y)}px`)},g=y=>{document.documentElement.style.setProperty("--oc-titlebar-overlay-width",`${Math.round(y)}px`)};if(!h)return;const p=o.current,v=r.current;if(!p||!v){m(0),g(0);return}const x=()=>{const y=Math.max(p.getBoundingClientRect().width,p.scrollWidth);m(y),g(v.getBoundingClientRect().width)};if(x(),typeof ResizeObserver>"u")return;const I=new ResizeObserver(x);return I.observe(p),I.observe(v),()=>{I.disconnect()}},[h]),f?t.jsx("div",{ref:r,className:"app-region-no-drag absolute left-0 z-40 flex select-none items-center pr-2",style:{top:"var(--oc-safe-area-top, 0px)",height:"calc(var(--oc-header-height, 3rem) - var(--oc-safe-area-top, 0px))",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},children:t.jsxs("div",{ref:o,className:"flex items-center gap-2",children:[d?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,"aria-label":"Open PiChamber menu",className:_(bi,"shrink-0"),children:t.jsx(D,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),t.jsx(Ge,{children:t.jsx("p",{children:"PiChamber menu"})})]}):null,u?t.jsxs(ze,{children:[t.jsx($e,{asChild:!0,children:t.jsx("button",{type:"button",onClick:s,"aria-label":"Open sessions",className:_(c?Vm:bi,"shrink-0"),children:t.jsx(D,{name:"layout-left",className:c?"size-[18px]":"h-[18px] w-[18px]"})})}),t.jsx(Ge,{children:t.jsx("p",{children:`Open sessions (${a})`})})]}):null]})}):null},xi=200,Jm="cubic-bezier(0.22, 1, 0.36, 1)",qg=e=>{const s=i.useMemo(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches,[]),[n,r]=i.useState(e),[o,a]=i.useState(e);return i.useLayoutEffect(()=>{if(s){a(e),r(e);return}if(e){a(!0),r(!1);let c=0;const u=window.requestAnimationFrame(()=>{c=window.requestAnimationFrame(()=>r(!0))});return()=>{window.cancelAnimationFrame(u),window.cancelAnimationFrame(c)}}r(!1);const l=window.setTimeout(()=>a(!1),xi);return()=>window.clearTimeout(l)},[e,s]),{slidIn:n,layoutVisible:o,prefersReducedMotion:s,transition:s?"none":`transform ${xi}ms ${Jm}`}},Vg=()=>{Li()},Jg=e=>{Ie.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ce.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),pe.getState().clearAll(),Li(),Os.getState().resetForRuntimeSwitch(),Uc.getState().resetForRuntimeSwitch(),zc.getState().resetForRuntimeSwitch(),$c(),Gc.getState().resetForRuntimeSwitch(),$t.setState({providers:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),dt.getState().resetForRuntimeSwitch(),Kc(),Wc(),ru.getState().reset(),Nd.getState().resetForRuntimeSwitch(),Ai.getState().resetForRuntimeSwitch(e.runtimeKey),Cr.getState().resetForRuntimeSwitch(e.runtimeKey),ys.getState().resetForRuntimeSwitch(e.runtimeKey),dh.getState().resetForRuntimeSwitch(),ct.getState().resetForRuntimeSwitch(e.runtimeKey),Id.getState().resetForRuntimeSwitch(e.runtimeKey),Ie.getState().restoreForRuntimeSwitch(e.runtimeKey),ce.getState().restoreForRuntimeSwitch(e.runtimeKey);const s=ce.getState();Mr({sessionId:Ie.getState().currentSessionId,tab:s.activeMainTab,isSettingsOpen:s.isSettingsDialogOpen,settingsPath:s.settingsPage,diffFile:s.pendingDiffFile},{replace:!0,force:!0})};export{yf as $,_g as A,Ko as B,Bg as C,ii as D,Hg as E,wg as F,Du as G,Yg as H,bg as I,fs as J,yu as K,hs as L,ga as M,vg as N,Zu as O,Tg as P,Qu as Q,jg as R,Ug as S,Kg as T,Dg as U,la as V,gg as W,Xr as X,Ig as Y,Xu as Z,ua as _,kf as a,Yu as a0,ef as a1,hn as a2,ca as a3,pn as a4,rn as a5,qu as a6,kg as a7,Vu as a8,Pg as a9,Og as aa,Fg as ab,tf as ac,Eg as ad,Mg as ae,Lg as af,Sg as ag,Cg as ah,Ag as ai,Ng as aj,pf as ak,Rg as al,Pu as am,Ju as an,Tu as ao,pg as ap,Af as b,Xs as c,Rp as d,zg as e,Fn as f,$g as g,qg as h,Pp as i,Wg as j,Qg as k,Jg as l,xg as m,yg as n,mg as o,hg as p,Zr as q,Vg as r,Gg as s,eo as t,Tn as u,to as v,Ms as w,ma as x,wf as y,vf as z};
|