@pi-chamber/web 1.0.2-rc.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DiagramView-GUJij-1P.js → DiagramView-C3jwAdba.js} +1 -1
- package/dist/assets/{DiffView-BZ487Bhh.js → DiffView-CqPv7nw1.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Ci6WdSiS.js → FileSaveConflictDialog-BDHl1ERM.js} +1 -1
- package/dist/assets/{FilesView-DBiWEo71.js → FilesView-DjD5jjcd.js} +1 -1
- package/dist/assets/{GitView-DVyhqN5s.js → GitView-D_TzczhS.js} +3 -3
- package/dist/assets/{JsonTreeView-BaU7aAUq.js → JsonTreeView-BTMtZylb.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-6NBJLtEr.js → MarkdownRendererImpl-DnZhLsfY.js} +1 -1
- package/dist/assets/{PatchDiff-CvptevA2.js → PatchDiff-D4jQKTZA.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-Cqp5FVCP.js → SessionSwitcherContent-BX6P7l8U.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-CRVJU16x.js → SessionSwitcherDropdown-DGvRKfRw.js} +2 -2
- package/dist/assets/{SessionUnreadDot-CsFxImPI.js → SessionUnreadDot-CPTTyo0r.js} +1 -1
- package/dist/assets/SettingsView-CD0EfMno.js +2 -0
- package/dist/assets/{SettingsWindow-geMUhnxd.js → SettingsWindow-MrdvHysy.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BLGl2mNt.js → ToolOutputDialog-9UTlcthG.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-BVeL1IuE.js → ToolPartDiffPreview-D_HifNve.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-9kAZ96se.js → VirtualizedFileDiff-CvqZNzUR.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-C8vH0vcM.js → computeVirtualFileMetrics-B1Zc3P5v.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-B6e3cTcl.js → contextFileOpenGuard-CJZHfvjH.js} +1 -1
- package/dist/assets/{gitStatusPredicates-B6w5GMNU.js → gitStatusPredicates-C7tetvAB.js} +1 -1
- package/dist/assets/{index-BifnX1Mp.js → index-DYXaDVnz.js} +1 -1
- package/dist/assets/{isDiffPlainText-BepQ1JHv.js → isDiffPlainText-DMMH-XmY.js} +1 -1
- package/dist/assets/{isFilePlainText-CA1KFaTm.js → isFilePlainText-DcCgFOGI.js} +1 -1
- package/dist/assets/{main-dhVDQIHu.js → main-BZu7VLeY.js} +2 -2
- package/dist/assets/{main-TzeSIx1W.js → main-DvtT25LM.js} +3 -3
- package/dist/assets/{markdownCore-BztwD2c9.js → markdownCore-D6HZ46BO.js} +1 -1
- package/dist/assets/{miniChat-smqdx0Y7.js → miniChat-CLS1HbGi.js} +2 -2
- package/dist/assets/{mobile-BV-WCEiE.js → mobile-BuCJ5Obm.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-DKmb9oa7.js → renderElectronMiniChatApp-BtREv0kE.js} +2 -2
- package/dist/assets/{renderMobileApp-D3dtjeaE.js → renderMobileApp-UF8ITb8A.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-C1EENUlq.js → runtimeEndpointReset-BcdDES-U.js} +3 -3
- package/dist/assets/{useAppFontEffects-Dq7xKVjh.js → useAppFontEffects-SHxBpd4f.js} +7 -7
- package/dist/assets/{useFilesViewSearch-Bvlo7C3a.js → useFilesViewSearch-CJ6yYAoc.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-BY4xtozp.js → usePushVisibilityBeacon-mnTxlkQZ.js} +1 -1
- package/dist/assets/{useSwitcherItems-CkE242zK.js → useSwitcherItems-DWUNXYMV.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Bv6kN79m.js → vendor-codemirror-language-data-B4enwgcI.js} +2 -2
- package/dist/assets/{web-components-CCiRgoOw.js → web-components-ldhQxnFE.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
- package/dist/assets/SettingsView-ppaIrPry.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
import{_ as cs}from"./vendor-vite-runtime-DD1OZmLC.js";import{r as Ae,j as t,R as i,b as tc}from"./vendor-react-B5Z1Mdn3.js";import{aQ as Ts,aR as sc,a2 as It,a3 as $e,a4 as Ge,a5 as Rt,B as Te,I as R,a6 as Ke,a7 as Dt,a9 as ot,t as oe,a as pt,f as De,_ as $s,ae as fn,aS as Si,ag as Yt,ah as qt,ai as fs,aj as es,ak as hs,al as ks,aG as Ss,aT as js,g as Ms,aU as lr,aV as Do,aW as Eo,aX as on,e as Mn,o as ji,af as xs,aY as Po,a8 as us,aZ as Nr,a_ as nc,a$ as rc,b0 as oc,b1 as ic,b2 as ac,b3 as Ir,b4 as lc,y as Wt,b5 as cc,b6 as dc,b7 as uc,b8 as Ci,b9 as fc,ba as hc,bb as ki,bc as Ai,bd as Ni,aD as Rr,r as an,n as Jr,ap as pc,az as mc,aC as Ii,L as As,d as Xr,ab as Gs,ay as Ri,be as Vn,bf as Mo,bg as ht,aE as Di,bh as Ei,au as gc,h as Pi,j as bc,bi as xc,i as yc,bj as Ds,b as To,c as vc,bk as wc,u as Sc,aF as jc,aI as Cc,bl as Dr,bm as kc,bn as Ac,aH as Nc,bo as Ic,bp as Rc,T as Dc,aa as Cs,am as Mi,w as Ec,ac as Pc,bq as Mc,br as Tc,k as Fc,bs as Oc,bt as Ti,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,bD as Hc}from"./useAppFontEffects-Dq7xKVjh.js";import{Z as Fo,_ as Yc,R as Ls,$ as Fi,a0 as Oi,a1 as qc,a2 as Qc,u as Bs,K as Vc,a3 as Jc,a4 as Xc,a5 as Zc,a6 as Vt,v as Jt,a7 as ed,a8 as td,a9 as sd,aa as Zr,m as Ct,ab as nd,ac as rd,ad as od,t as ce,o as $,ae as id,f as qe,B as ke,af as _s,ag as _t,ah as Oo,ai as Er,a as eo,T as to,U as Un,aj as ad,ak as ld,al as Li,F as cd,Q as Bi,C as ln,am as Pr,h as Mr,d as kn,an as dd,ao as ud,ap as Lo,aq as en,ar as cr,as as Tr,at as zn,au as ys,av as Bo,aw as Fr,ax as _i,ay as Or,az as fd,z as Ui,aA as hd,aB as pd,aC as md,aD as gd,aE as bd,aF as xd,aG as yd,aH as vd,Y as zi,P as wd,J as Sd}from"./index-CpSdU-d4.js";import{c as Ks,d as $i,p as so,u as Lr,a as jd}from"./vendor-zustand-GVb4H8HE.js";import{g as ds,b as Cd,c as Gi,r as kd,d as Ki,s as Tn,e as Wi,h as hn,i as pn,j as Ad,k as Nd,l as Id,m as _o,n as Jn,f as Rd,a as Dd,S as Ed,t as Pd,o as Md}from"./SessionUnreadDot-CsFxImPI.js";import{C as Hi,a as Yi,M as qi,b as Qi,c as Vi,d as Ji,S as Xi,D as Td,e as Fd,f as Od,g as Ld,h as Bd,i as _d,j as Ud}from"./vendor-base-ui-DXSHfszQ.js";import{c as Zi,d as Br,P as zd,D as ea,e as ta,f as $d,b as Gd,a as Kd,T as Wd,M as Hd}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{u as Yd}from"./vendor-tanstack-react-virtual-2skouoFw.js";import{S as qd,v as Qd,u as Vd}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as Jd}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-xterm-xterm-CrXqRur4.js";import{usePermissionStore as Xd}from"./permissionStore-iKN1K2_x.js";const Zd="chat";function sa(e){const s=new URLSearchParams;if(e.sessionId&&e.sessionId.trim().length>0&&s.set(Ts.SESSION,e.sessionId),e.isSettingsOpen){const n=e.settingsPath.trim().length>0?e.settingsPath:"home";return s.set(Ts.SETTINGS,n),s}return e.tab!==Zd&&s.set(Ts.TAB,e.tab),e.tab==="diff"&&e.diffFile&&e.diffFile.trim().length>0&&s.set(Ts.FILE,e.diffFile),s}function eu(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 tu(e){if(typeof window>"u")return!0;try{const s=new URLSearchParams(window.location.search),n=sa(e),r=window.location.pathname.match(/^\/(?:session|s)\/([^/?#]+)/i),o=r?.[1]?decodeURIComponent(r[1].trim()):null;o&&!s.has(Ts.SESSION)&&s.set(Ts.SESSION,o);const a=[...s.entries()].sort((c,d)=>c[0].localeCompare(d[0])),l=[...n.entries()].sort((c,d)=>c[0].localeCompare(d[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 _r(e,s={}){if(!(typeof window>"u")&&!(!s.force&&tu(e)))try{const n=sa(e),r=eu(n);s.replace?window.history.replaceState({...window.history.state,route:e},"",r):window.history.pushState({route:e},"",r)}catch{}}const su=["typescript","javascript","tsx","jsx","json","markdown"],na={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Uo=null;const ra=()=>(Uo??=Promise.all([cs(()=>import("./index-BifnX1Mp.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])),cs(()=>import("./workerFactory-tw7cIdmV.js"),[]),cs(()=>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})),Uo),mn={},zo=new Set,Ur=new Set;let Fn={light:"pierre-light",dark:"pierre-dark"};const nu=()=>{for(const e of Ur)e()},oa=(e,s)=>{s.setRenderOptions({theme:Fn,lineDiffType:na[e].lineDiffType})},zr=e=>{typeof window>"u"||zo.has(e)||(zo.add(e),ra().then(s=>{if(mn[e])return;const n=na[e],r=new s.WorkerPoolManager({workerFactory:s.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:su,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),mn[e]=r,oa(e,r),nu()}))},ru=e=>(Ur.add(e),()=>Ur.delete(e)),ou=e=>{if(!(Fn.light===e.light&&Fn.dark===e.dark)){Fn=e;for(const s of Object.keys(mn)){const n=mn[s];n&&oa(s,n)}}},ng=({children:e})=>{const s=sc(),n=Fo(!1),r=Fo(!0),o=s?.lightThemeId??n.metadata.id,a=s?.darkThemeId??r.metadata.id,l=s?.availableThemes.find(d=>d.metadata.id===o)??n,c=s?.availableThemes.find(d=>d.metadata.id===a)??r;return Ae.useEffect(()=>{let d=!1;return ra().then(u=>{d||(u.ensurePierreThemeRegistered(l),u.ensurePierreThemeRegistered(c),ou({light:l.metadata.id,dark:c.metadata.id}))}),()=>{d=!0}},[c,l]),Ae.useEffect(()=>{if(typeof window>"u")return;const d=()=>{zr("unified"),zr("split")};if(typeof window.requestIdleCallback=="function"){const f=window.requestIdleCallback(d,{timeout:5e3});return()=>window.cancelIdleCallback(f)}const u=window.setTimeout(d,2e3);return()=>window.clearTimeout(u)},[]),t.jsx(t.Fragment,{children:e})},rg=(e="unified")=>{const s=Ae.useSyncExternalStore(ru,()=>mn[e],()=>{});return Ae.useEffect(()=>{zr(e)},[e]),s},iu={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3",fingerprint:"fingerprint"},au={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 ia(e){return e&&au[e]||"var(--primary)"}const $o=({icon:e,className:s,colorToken:n})=>{const r=iu[e??"branch"]??"user-3";return t.jsx(R,{name:r,className:s,style:{color:ia(n)}})},lu=({activeProfile:e,identities:s,onSelect:n,isApplying:r,iconOnly:o=!1})=>{const a=r||s.length===0;return t.jsxs(It,{children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs(Te,{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:ia(e?.color)},disabled:a,children:[r?t.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx($o,{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(R,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Ke,{sideOffset:8,children:"Git identity"})]}),t.jsx(Dt,{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(ot,{onSelect:()=>n(l),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx($o,{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(R,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},l.id)})})]})},cu=e=>e==="/",Us=e=>e.replace(/\\/g,"/"),zs=e=>{if(!e||cu(e))return e;let s=e;for(;s.length>1&&s.endsWith("/");)s=s.slice(0,-1);return s},Fs=e=>e.endsWith("/"),$n=e=>{const s=e.trim();return!s||Fs(s)?s:`${s}/`},no=e=>e.lastIndexOf("/"),aa=e=>{if(Fs(e))return e;const s=no(e);return s<0?e:e.slice(0,s+1)},la=e=>{const s=no(e);return e.slice(s+1)},ca=e=>{const s=zs(e.trim());if(!s||s==="~"||s==="~/"||s==="/")return null;const n=no(s);return n<0?null:s.startsWith("~/")&&n<=1?"~/":n===0?"/":`${s.slice(0,n)}/`},da=e=>Fs(e)&&ca(e)!==null,du=e=>{if(!da(e))return null;const s=zs(e.trim());return la(s)||s},uu=(e,s)=>`${aa(e)}${s}/`,vs=e=>{if(!e)return null;const s=zs(Us(e.trim()));return s?s.toLowerCase():null},Go=(e,s)=>{const n=e.trim();return n==="~"?s:n.startsWith("~/")?`${s}${n.slice(1)}`:n},fu=(e,s)=>{const n=zs(Us(e.trim())),r=zs(Us(s.trim()));if(!n)return"";if(!r)return $n(n);if(n.toLowerCase()===r.toLowerCase())return"~/";const o=`${r}/`;return n.toLowerCase().startsWith(o.toLowerCase())?`~/${n.slice(r.length+1)}/`:$n(n)},hu=e=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,$r=e=>{if(!e)return;e.focus({preventScroll:!0});const s=e.value.length;e.setSelectionRange(s,s),e.scrollLeft=e.scrollWidth},pu=async()=>Yc(),mu=()=>{const[e,s]=Ae.useState(!1),[n,r]=Ae.useState(!1);Ae.useEffect(()=>{s(Ls()),r(Fi())},[]);const o=Ae.useCallback(async c=>e?await Oi(c):{success:!0,path:c},[e]),a=Ae.useCallback(async c=>e?await qc():{success:!0},[e]),l=Ae.useCallback(async c=>e?await Qc():{success:!0},[e]);return{isDesktop:e,canRequestAccess:n,requestAccess:o,startAccessing:a,stopAccessing:l}};function gu({open:e,addedProjectPaths:s,shouldSuppressAutoFocus:n}){const r=Bs(re=>re.homeDirectory),{canRequestAccess:o,startAccessing:a}=mu(),l=i.useRef(null),c=i.useRef(new Map),[d,u]=i.useState(""),[f,h]=i.useState("~/"),[b,p]=i.useState([]),[g,m]=i.useState(!1),[w,x]=i.useState(!1),[I,v]=i.useState(null),[A,j]=i.useState(0),[N,C]=i.useState(0),[y,k]=i.useState(!1),[D,M]=i.useState(!1),[B,_]=i.useState("right"),K=i.useRef("~/"),V=d||r;i.useEffect(()=>{if(!e)return;h("~/"),p([]),C(0),k(!1),M(!1),K.current="~/",_("right"),n||requestAnimationFrame(()=>$r(l.current));let re=!1;return(async()=>{const H=await pu();re||(u(H||r||""),n||requestAnimationFrame(()=>$r(l.current)))})(),()=>{re=!0}},[r,e,n]);const O=i.useMemo(()=>aa(f),[f]),T=i.useMemo(()=>Fs(f)?"":la(f),[f]),P=i.useMemo(()=>V?Go(O,V):"",[O,V]);i.useEffect(()=>{const re=K.current;re!==O&&(_(O.length>=re.length?"right":"left"),K.current=O)},[O]),i.useEffect(()=>{if(!e||!P){p([]),v(null);return}let re=!1;return m(!0),x(!1),v(null),Vc(P).then(ae=>{if(re)return;x(!1),v(null);const H=ae.filter(me=>me.isDirectory).map(me=>({name:me.name,path:Us(me.path)})).sort((me,Ue)=>me.name.localeCompare(Ue.name));p(H)}).catch(ae=>{if(!re){p([]);const H=Jc(ae)?ae.reason:"unknown";v(H),x(H==="not-found")}}).finally(()=>{re||m(!1)}),()=>{re=!0}},[P,A,e]);const U=i.useMemo(()=>{const re=T.toLowerCase(),ae=D||T.startsWith(".");return b.filter(H=>H.name.toLowerCase().startsWith(re)&&(ae||!H.name.startsWith(".")))},[T,b,D]),ne=i.useMemo(()=>du(f),[f]),W=i.useMemo(()=>ca(f),[f]),G=i.useMemo(()=>{const re=[],ae=vs(P);da(f)&&ne&&W&&re.push({type:"parent",value:"browse:up",name:ne,path:W,alreadyAdded:!!(ae&&s.has(ae))});for(const H of U){const me=vs(H.path);re.push({type:"directory",value:`browse:${H.path}`,name:H.name,path:H.path,alreadyAdded:!!(me&&s.has(me))})}return re},[s,P,ne,U,W,f]);i.useEffect(()=>{C(0)},[f,G.length]);const Ne=i.useMemo(()=>V?zs(Go(f,V)):"",[V,f]),ee=vs(Ne),Fe=!!(ee&&s.has(ee)),_e=i.useMemo(()=>T?U.find(re=>re.name===T)??null:null,[T,U]),q=!!(Ne&&!Fe&&(I===null||I==="not-found")&&(Fs(f)&&w||!Fs(f)&&T.trim().length>0&&_e===null)),F=G[N]??null,z=!!F,Q=i.useCallback(re=>{h($n(re))},[]),se=i.useCallback(re=>{h(uu(f,re.name))},[f]),Se=i.useCallback(re=>{if(re){if(re.type==="parent"){Q(re.path);return}se(re)}},[Q,se]),ge=i.useCallback(async re=>{const ae=await a(re);if(!ae.success)return oe.error("Failed to open directory",{description:ae.error||"Desktop could not grant file access."}),!1;const H=V?fu(re,V):$n(Us(re));return Q(H),!0},[Q,V,a]),we=i.useCallback(async()=>{if(!y){k(!0);try{if(Fi()){const ae=await Oi(Ne);if(!ae.success||!ae.path){ae.error&&ae.error!=="Directory selection cancelled"&&oe.error("Failed to select directory",{description:ae.error});return}await ge(ae.path);return}const re=await Xc(Ne);if(re.status==="cancelled")return;if(re.status!=="picked"){oe.error("Couldn't open a folder picker",{description:re.error});return}await ge(re.path)}catch(re){oe.error("Failed to select directory",{description:re instanceof Error?re.message:"Unknown error occurred."})}finally{k(!1)}}},[ge,y,Ne]);return{inputRef:l,rowRefs:c,query:f,setQuery:h,isLoading:g,isBrowseDirectoryMissing:w,browseErrorReason:I,browseReloadKey:A,setBrowseReloadKey:j,highlightedIndex:N,setHighlightedIndex:C,isPickingLocation:y,showHidden:D,setShowHidden:M,folderEnterFrom:B,explorerRootDirectory:V,browseDirectoryDisplayPath:O,browseDirectoryAbsolutePath:P,browseFilterQuery:T,filteredEntries:U,rows:G,targetPath:Ne,isAlreadyAdded:Fe,shouldCreateTarget:q,highlightedRow:F,hasHighlightedBrowseItem:z,canRequestAccess:o,browseToDisplayPath:Q,browseToEntry:se,executeRow:Se,applyPickedLocation:ge,handleBrowseLocation:we}}const bs=Ks()($i(so((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 od();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 rd();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 nd();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 Ct("/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 Zr({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 sd(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 td(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 ed(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:Zc(),partialize:e=>({selectedProfileId:e.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=bs);function bu({open:e,onClose:s,isMobile:n,addedProjectPaths:r,targetPath:o,shouldCreateTarget:a,browseErrorReason:l,browseDirectoryAbsolutePath:c,isAlreadyAdded:d,isPickingLocation:u}){const f=pt(W=>W.addProject),h=ce(W=>W.setActiveMainTab),b=ce(W=>W.setSessionSwitcherOpen),p=De(W=>W.openNewSessionDraft),g=bs(W=>W.profiles),m=bs(W=>W.globalIdentity),w=bs(W=>W.defaultGitIdentityId),x=bs(W=>W.loadProfiles),I=bs(W=>W.loadGlobalIdentity),v=bs(W=>W.loadDefaultGitIdentityId),[A,j]=i.useState(!1),[N,C]=i.useState(!1),[y,k]=i.useState(""),[D,M]=i.useState(null);i.useEffect(()=>{e&&(j(!1),C(!1),k(""),M(null))},[e]),i.useEffect(()=>{e&&(x(),I(),v())},[v,x,I,e]);const B=i.useMemo(()=>{const W=new Map;m&&W.set(m.id,m);for(const G of g)W.set(G.id,G);return Array.from(W.values())},[g,m]);i.useEffect(()=>{if(!e||!N||D!==null)return;const W=typeof w=="string"?w.trim():"";if(W&&B.some(Ne=>Ne.id===W)){M(W);return}const G=B.find(Ne=>Ne.authType==="ssh"||Ne.sshKey);G&&M(G.id)},[B,w,N,e,D]);const _=i.useMemo(()=>B.find(W=>W.id===D)??null,[B,D]),K=i.useCallback((W,G)=>{h("chat"),n&&b(!1),p({selectedProjectId:W,directoryOverride:G}),s()},[n,s,p,h,b]),V=i.useCallback(async W=>{if(!W||A)return;const G=vs(W);if(G&&r.has(G))return;let Ne=W;j(!0);try{const ee=!N&&a&&vs(W)===vs(o);if(N){const _e=y.trim();if(!_e){oe.error("Enter a repository URL before cloning.");return}const q=await Ct("/api/fs/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:_e,destinationPath:W,gitIdentityId:_?.id??null})});if(!q.ok)throw new Error("Failed to clone git repository");Ne=(await q.json()).path||W}else if(ee&&!(await Ct("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},query:c?{directory:c}:void 0,body:JSON.stringify({path:W})})).ok)throw new Error("Failed to select directory");const Fe=f(Ne);if(!Fe){oe.error("Failed to add folder",{description:"Please select a valid directory path."});return}K(Fe.id,Fe.path)}catch(ee){oe.error("Failed to select directory",{description:ee instanceof Error?ee.message:"Unknown error occurred."})}finally{j(!1)}},[f,r,c,y,N,A,K,_?.id,a,o]),O=!A&&!u&&!d&&l!=="os-permission"&&l!=="invalid-response"&&l!=="unknown"&&!!o,T=O&&y.trim().length>0,P=N?T:O,U=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";return{isConfirming:A,isCloneMode:N,setIsCloneMode:C,cloneRemoteUrl:y,setCloneRemoteUrl:k,selectedGitIdentityId:D,setSelectedGitIdentityId:M,availableGitIdentities:B,selectedGitIdentity:_,canSubmit:P,submitActionLabel:d?"Already added":N?A?"Cloning...":"Clone & add":A?"Adding...":a?"Create & add":"Add folder",submitModifierLabel:U,finalizeSelection:V}}const xu=({open:e,onOpenChange:s})=>{const n=pt(H=>H.projects),{isMobile:r,isTablet:o}=$s(),a=r||o,l=i.useMemo(()=>new Set(n.map(H=>vs(H.path)).filter(H=>!!H)),[n]),c=i.useCallback(()=>{s(!1)},[s]),{inputRef:d,rowRefs:u,query:f,setQuery:h,isLoading:b,browseErrorReason:p,setBrowseReloadKey:g,highlightedIndex:m,setHighlightedIndex:w,isPickingLocation:x,showHidden:I,setShowHidden:v,folderEnterFrom:A,browseDirectoryDisplayPath:j,browseDirectoryAbsolutePath:N,rows:C,targetPath:y,isAlreadyAdded:k,shouldCreateTarget:D,highlightedRow:M,hasHighlightedBrowseItem:B,canRequestAccess:_,executeRow:K,handleBrowseLocation:V}=gu({open:e,addedProjectPaths:l,shouldSuppressAutoFocus:a}),{isConfirming:O,isCloneMode:T,setIsCloneMode:P,cloneRemoteUrl:U,setCloneRemoteUrl:ne,setSelectedGitIdentityId:W,availableGitIdentities:G,selectedGitIdentity:Ne,canSubmit:ee,submitActionLabel:Fe,submitModifierLabel:_e,finalizeSelection:q}=bu({open:e,onClose:c,isMobile:r,addedProjectPaths:l,targetPath:y,shouldCreateTarget:D,browseErrorReason:p,browseDirectoryAbsolutePath:N,isAlreadyAdded:k,isPickingLocation:x});i.useLayoutEffect(()=>{const H=d.current;H&&(H.scrollLeft=H.scrollWidth)},[d,f]),i.useLayoutEffect(()=>{!e||a||$r(d.current)},[d,e,a]),i.useLayoutEffect(()=>{const H=C[m];H&&u.current.get(H.value)?.scrollIntoView({block:"nearest"})},[m,u,C]);const F=i.useCallback(H=>{if(H.key==="ArrowDown"){H.preventDefault(),w(me=>Math.min(C.length-1,me+1));return}if(H.key==="ArrowUp"){H.preventDefault(),w(me=>Math.max(0,me-1));return}if(H.key==="Enter"){if(H.preventDefault(),hu(H)){q(y);return}B&&K(M);return}H.key==="Backspace"&&f===""&&(H.preventDefault(),c())},[K,q,c,B,M,f,C.length,w,y]),z=t.jsxs("button",{type:"button",onClick:()=>v(H=>!H),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(R,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}),"Show hidden"]}),Q=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(R,{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(fn,{ref:d,value:f,onChange:H=>h(Us(H.target.value)),onKeyDown:F,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(Te,{variant:"outline",size:"xs",className:"h-8 shrink-0 gap-1 px-2",disabled:O||x,onMouseDown:H=>H.preventDefault(),onClick:()=>{V()},title:"Browse location","aria-label":"Browse location",children:[t.jsx(R,{name:"folder-open",className:"h-3.5 w-3.5"}),x?"Opening...":"Browse"]})]})}),se=C.some(H=>H.type==="parent"),Se=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(Te,{variant:"ghost",size:"xs",className:"h-6 shrink-0 gap-1 text-muted-foreground","aria-pressed":T,disabled:O||x,onClick:()=>P(H=>!H),children:[t.jsx(R,{name:"git-repository",className:"h-3.5 w-3.5"}),"Clone"]})]}),T?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(fn,{value:U,onChange:H=>ne(H.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(lu,{activeProfile:Ne,identities:G,onSelect:H=>W(H.id),isApplying:O,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",A==="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..."}):p&&p!=="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:p==="os-permission"?"PiChamber needs access to this folder.":"Could not load this folder."}),t.jsxs("div",{className:"flex items-center gap-2",children:[p==="os-permission"&&_?t.jsx(Te,{size:"xs",onClick:()=>{V()},disabled:x,children:"Grant access"}):null,t.jsx(Te,{variant:"outline",size:"xs",onClick:()=>g(H=>H+1),children:"Try again"})]})]}):C.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:C.map((H,me)=>{const Ue=me===m,L=H.type==="directory"&&se;return t.jsxs("button",{ref:X=>{X?u.current.set(H.value,X):u.current.delete(H.value)},type:"button","aria-label":H.type==="parent"?H.alreadyAdded?`Go back from ${H.name}, already added`:`Go back from ${H.name}`:H.alreadyAdded?`Open ${H.name}, already added`:`Open ${H.name}`,onMouseEnter:()=>w(me),onMouseDown:X=>X.preventDefault(),onClick:()=>K(H),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",L&&"pl-4"),children:[H.type==="parent"?t.jsx(R,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(R,{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:H.name})]}),H.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,H.type==="parent"?t.jsx(R,{name:"arrow-up-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"}):t.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"})]},H.value)})})},j)]})}),ge=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[Q,Se]}),we=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(R,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(R,{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(R,{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(R,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Add folder"]})]}),re=t.jsx(Te,{size:r?"xs":"default",onClick:()=>{q(y)},disabled:!ee,className:$(r&&"w-full flex-1"),children:Fe}),ae=()=>t.jsxs(t.Fragment,{children:[r?null:we,t.jsx("div",{className:$("flex w-full flex-row justify-end gap-2 sm:w-auto",r&&"justify-stretch"),children:re})]});return r?t.jsx(Si,{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:ae()}),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}),ge]})}):t.jsx(Yt,{open:e,onOpenChange:s,children:t.jsxs(qt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(fs,{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(hs,{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:ge}),t.jsx(ks,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:ae()})]})})},An=e=>e?t.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:e}):void 0,og=()=>{const[e,s]=i.useState(!1),[n,r]=i.useState(null),[o,a]=i.useState(!1),l=De(N=>N.deleteSession),c=De(N=>N.deleteSessions),d=ce(N=>N.showDeletionDialog),u=ce(N=>N.setShowDeletionDialog),{isMobile:f,isTablet:h,hasTouchInput:b}=$s(),p=f||h||b;i.useEffect(()=>id(()=>{s(!1)}),[]);const g=i.useCallback(N=>{r({sessions:N.sessions,dateLabel:N.dateLabel})},[]),m=i.useCallback(()=>{r(null),a(!1)},[]),w=i.useCallback(async N=>{if(N.sessions.length===0)return;if(N.sessions.length===1){const D=N.sessions[0];await l(D.id)?oe.success("Session deleted"):oe.error("Failed to delete session");return}const C=N.sessions.map(D=>D.id),{deletedIds:y,failedIds:k}=await c(C);if(y.length>0){const D=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;oe.success(y.length===1?"Deleted {count} session":`Deleted ${y.length} sessions`,{description:An(D)})}k.length>0&&oe.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:An("Please try again in a moment.")})},[l,c]);i.useEffect(()=>Ss.onDeleteRequest(N=>{if(!d){w(N);return}g(N)}),[g,d,w]),i.useEffect(()=>Ss.onDirectoryRequest(()=>{s(!0)}),[]);const x=i.useCallback(async()=>{if(n){a(!0);try{if(n.sessions.length===1){const N=n.sessions[0];if(!await l(N.id)){oe.error("Failed to delete session"),a(!1);return}oe.success("Session deleted",{action:{label:"OK",onClick:()=>{}}})}else{const N=n.sessions.map(D=>D.id),C=await c(N),y=C.deletedIds,k=C.failedIds;if(y.length>0){const D=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;oe.success(y.length===1?"Deleted {count} session":`Deleted ${y.length} sessions`,{description:An(D),action:{label:"OK",onClick:()=>{}}})}if(k.length>0&&(oe.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:An("Please try again in a moment.")}),y.length===0)){a(!1);return}}m()}finally{a(!1)}}},[n,l,c,m]),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.`:"",v=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(N=>t.jsx("li",{className:"typography-micro text-muted-foreground/80",children:t.jsx("span",{className:"truncate",children:ds(N)})},N.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,A=t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>u(!d),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":!d,children:[d?t.jsx(R,{name:"checkbox-blank",className:"size-4"}):t.jsx(R,{name:"checkbox",className:"size-4 text-primary"}),"Never ask"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Te,{variant:"ghost",onClick:m,disabled:o,children:"Cancel"}),t.jsx(Te,{variant:"destructive",onClick:x,disabled:o,children:o?"Deleting…":n?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),j=n?.sessions.length===1?"Delete session":"Delete sessions";return t.jsxs(t.Fragment,{children:[p?t.jsx(Si,{open:!!n,onClose:()=>{o||m()},title:j,footer:t.jsx("div",{className:"flex justify-end gap-2",children:A}),children:t.jsxs("div",{className:"space-y-2 pb-2",children:[I&&t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:I}),v]})}):t.jsx(Yt,{open:!!n,onOpenChange:N=>{if(!N){if(o)return;m()}},children:t.jsxs(qt,{className:"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2",children:[t.jsxs(fs,{children:[t.jsx(es,{children:j}),I&&t.jsx(hs,{children:I})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2",children:v}),t.jsx(ks,{className:"mt-2 gap-2 pt-1 pb-1",children:A})]})}),t.jsx(xu,{open:e,onOpenChange:s})]})},ig=()=>{const e=js(s=>s.entries);return i.useEffect(()=>{for(const s of e.values())!s.receipt||s.notificationSent||(js.getState().markNotificationSent(s.key),oe.success("Worktree ready",{id:`worktree-ready:${s.key}`,description:s.receipt.branch||s.receipt.path}))},[e]),null},yu=[{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"]}],vu={sessions:"sessions",skills:"skills.installed",providers:"providers","git-identities":"git",settings:"home"};function wu(e){const s=e.trim().toLowerCase();return yu.find(n=>n.slug===s)??null}function Su(e){const s=(e??"").trim().toLowerCase();if(!s)return"home";const n=vu[s];if(n)return n;const r=wu(s);return r?r.slug:"home"}function ag(e){switch(e){case"general":return"equalizer";case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"brush";case"chat":return"chat-1";case"dictation":return"voiceprint";case"snippets":return"sticky-note";case"prompt-templates":return"terminal-box";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"history";case"providers":return"cloud";case"behavior":return"brain";case"skills.installed":return"puzzle";case"git":return"git-repository";case"tunnel":return"global";case"about":return"pichamber";case"home":return null;default:return"robot-2"}}function lg(){const e=i.useRef(!1),s=i.useRef(!1),n=De(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=De.getState().currentSessionId,b=Ms().getState().selectedSessionId;if(f.sessionId!==h||f.sessionId!==b){const p=De.getState().getDirectoryForSession(f.sessionId);n(f.sessionId,p)}}if(f.settingsPath){a(Su(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]),d=i.useCallback(()=>{const f=De.getState(),h=Ms().getState(),b=ce.getState();return{sessionId:lr({currentSessionId:f.currentSessionId,piSelectedSessionId:h.selectedSessionId,draft:f.newSessionDraft}),tab:b.activeMainTab,isSettingsOpen:b.isSettingsDialogOpen,settingsPath:b.settingsPage,diffFile:b.pendingDiffFile}},[]),u=i.useCallback((f={})=>{if(s.current)return;const h=d();_r(h,f)},[d]);i.useEffect(()=>{if(e.current||(e.current=!0,!Do()))return;const f=Eo();(async()=>(await c(f),_r({...d(),sessionId:f.sessionId??lr({currentSessionId:De.getState().currentSessionId,piSelectedSessionId:Ms().getState().selectedSessionId,draft:De.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,d]),i.useEffect(()=>{const f=()=>{const w=De.getState(),x=Ms().getState();return lr({currentSessionId:w.currentSessionId,piSelectedSessionId:x.selectedSessionId,draft:w.newSessionDraft})};let h=f(),b=De.getState().newSessionDraft?.open===!0;const p=()=>{const w=De.getState(),x=f(),I=w.newSessionDraft?.open===!0;x===h&&I===b||s.current||(h=x,b=I,u({replace:!0}))},g=De.subscribe(()=>{p()}),m=Ms().subscribe(()=>{p()});return()=>{g(),m()}},[u]),i.useEffect(()=>{let f=ce.getState().activeMainTab,h=ce.getState().isSettingsDialogOpen,b=ce.getState().settingsPage,p=ce.getState().pendingDiffFile;return ce.subscribe(m=>{if(s.current)return;const w=m.activeMainTab!==f,x=m.isSettingsDialogOpen!==h,I=m.settingsPage!==b,v=m.pendingDiffFile!==p&&m.activeMainTab==="diff";f=m.activeMainTab,h=m.isSettingsDialogOpen,b=m.settingsPage,p=m.pendingDiffFile,(w||x||I||v)&&u()})},[u]),i.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const h=Eo();if(Do())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 ju(e=!0){const s=Mn(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,d=null;const u=h=>{const b=Math.round(h*1e3);return Math.max(a,Math.min(l,b))},f=h=>{c||(d=window.setTimeout(async()=>{const b=await n.current(),p=typeof b=="number"&&Number.isFinite(b)?u(b):o;f(p)},h))};return f(r),()=>{c=!0,d!==null&&window.clearTimeout(d)}},[e])}function cg(){const e=on(s=>s.connection==="ready",void 0,"chrome");return ju(e),null}const Ko=12,Cu=[{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"}],ku=({isActive:e,burstKey:s=0,className:n,durationMs:r=900,bursts:o=Cu,onComplete:a})=>{const l=Ae.useRef(!1);Ae.useEffect(()=>{!e&&l.current&&a?.(),e&&(l.current=!0)},[e,a]);const c=Ae.useMemo(()=>Array.from({length:Ko},(d,u)=>{const f=Math.PI*2*u/Ko;return{x:Math.cos(f),y:Math.sin(f),delay:u*18}}),[]);return e?t.jsx("div",{className:$("fireworks-overlay pointer-events-none",n),"aria-hidden":"true","data-burst-key":s,children:o.map(d=>{const u={"--burst-delay":`${d.delay}ms`,"--burst-x":`${d.x}%`,"--burst-y":`${d.y}%`,"--firework-color":`var(${d.colorVar})`,"--firework-duration":`${r}ms`};return t.jsx("div",{className:"firework-burst",style:u,children:c.map((f,h)=>{const b=f.x*d.radius,p=f.y*d.radius,g={"--translate-x":`${b}px`,"--translate-y":`${p}px`,"--particle-delay":`${f.delay}ms`,color:`var(${d.colorVar})`};return t.jsx("span",{className:"firework-particle",style:g},`${d.id}-${h}-${s}`)})},`${d.id}-${s}`)})}):null},Au=({durationMs:e=3400}={})=>{const[s,n]=Ae.useState({isActive:!1,cycle:0}),r=Ae.useRef(null),o=Ae.useCallback(()=>{r.current&&(window.clearTimeout(r.current),r.current=null)},[]),a=Ae.useCallback(()=>{o(),n(c=>c.isActive?{...c,isActive:!1}:c)},[o]),l=Ae.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 Ae.useEffect(()=>()=>o(),[o]),{isActive:s.isActive,burstKey:s.cycle,triggerFireworks:l,dismissFireworks:a}},ua=i.createContext(void 0),dg=({children:e})=>{const{isActive:s,burstKey:n,triggerFireworks:r,dismissFireworks:o}=Au(),a=i.useMemo(()=>({triggerFireworks:r,dismissFireworks:o}),[r,o]);return t.jsxs(ua.Provider,{value:a,children:[e,t.jsx(ku,{isActive:s,burstKey:n})]})},Nu={triggerFireworks:()=>{},dismissFireworks:()=>{}},ug=()=>i.useContext(ua)??Nu,Gn=2e3,fa=600*1e3;async function Iu(){try{const e=await Ct("/api/pi/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});if(!e.ok){const n=await e.json().catch(()=>({}));return{success:!1,error:n.error||`Server error: ${e.status}`,commands:Array.isArray(n.commands)?n.commands.filter(r=>typeof r=="string"):void 0}}const s=await e.json().catch(()=>({}));return{success:!0,autoRestart:s.autoRestart!==!1,jobId:typeof s.jobId=="string"?s.jobId:void 0,channel:s.channel==="rc"?"rc":s.channel==="stable"?"stable":void 0,targetVersion:typeof s.targetVersion=="string"?s.targetVersion:void 0}}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Ru(e,s=Math.ceil(fa/Gn),n=Gn,r=qe()){for(let o=0;o<s;o++){if(qe()!==r)return{applied:!1,stale:!0};try{const a=await Ct("/api/pi/update-check",{method:"GET",headers:{Accept:"application/json"}});if(qe()!==r)return{applied:!1,stale:!0};if(a.ok){const l=await a.json().catch(()=>null);if(qe()!==r)return{applied:!1,stale:!0};if(typeof l?.error=="string"&&l.error.length>0)return{applied:!1,error:l.error};if(l&&l.available===!1)return{applied:!0};if(l&&typeof l.currentVersion=="string"&&typeof e=="string"&&l.currentVersion!==e)return{applied:!0}}else if(a.status===401||a.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."}}catch{if(qe()!==r)return{applied:!1,stale:!0}}await new Promise(a=>setTimeout(a,n))}return{applied:!1}}async function Du(e,s,n=Math.ceil(fa/Gn),r=Gn,o=qe()){for(let a=0;a<n;a++){if(qe()!==o)return{applied:!1,stale:!0};try{const l=await Ct(`/api/pi/update-install/${encodeURIComponent(e)}`,{method:"GET",headers:{Accept:"application/json"}});if(qe()!==o)return{applied:!1,stale:!0};if(l.ok){const c=await l.json().catch(()=>null);if(qe()!==o)return{applied:!1,stale:!0};if(c?.state==="complete")return{applied:!0};if(c?.state==="failed")return{applied:!1,error:c.error||"Update failed"};c?.state==="restarting"?s("restarting"):(c?.state==="queued"||c?.state==="installing"||c?.state==="verifying")&&s("updating")}else{if(l.status===401||l.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."};if(l.status===404)return{applied:!1,error:"The server lost the update status. Check the installed version or run: pichamber update"};if(l.status===503){const c=await l.json().catch(()=>null);if(qe()!==o)return{applied:!1,stale:!0};if(c?.error==="Update status is unavailable")return{applied:!1,error:c.error};s("reconnecting")}else s("reconnecting")}}catch{if(qe()!==o)return{applied:!1,stale:!0};s("reconnecting")}await new Promise(l=>setTimeout(l,r))}return{applied:!1}}const Wo="https://github.com/RyderAsKing/PiChamber/releases";function Eu(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 Pu(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Ho(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Mu(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 Tu(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 ha=({open:e,onOpenChange:s,info:n,downloading:r,downloaded:o,progress:a,error:l,onDownload:c,onRestart:d,runtimeType:u="desktop"})=>{const[f,h]=Ae.useState(null),[b,p]=Ae.useState("idle"),[g,m]=Ae.useState(null),[w,x]=Ae.useState(null),[I,v]=Ae.useState({}),A=n?.version?n.releaseUrl||`${Wo}/tag/v${n.version}`:Wo,j=n?.downloadUrl||A,N=a?.total?Math.round(a.downloaded/a.total*100):0,C=u==="web",y=u==="mobile",k=n?.updateCommand||"pichamber update",D=I.version||n?.version,M=I.channel||n?.channel;Ae.useEffect(()=>{e||(p("idle"),m(null),x(null),v({}))},[e]);const B=async(P=k)=>{(await us(P)).ok&&(h(P),setTimeout(()=>h(null),2e3))},_=Ae.useCallback(async P=>{await ji(P)},[]),K=Ae.useCallback(async()=>{const P=qe();p("updating"),m(null),x(null),v({});const U=await Iu();if(qe()!==P)return;if(!U.success){p("error"),m(U.error||"Update failed"),x(U.commands??null);return}if(v({version:U.targetVersion,channel:U.channel}),U.jobId){const W=await Du(U.jobId,G=>{qe()===P&&p(G)},void 0,void 0,P);if(W.stale||qe()!==P)return;if(W.applied){window.location.reload();return}p("error"),m(W.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update");return}p(U.autoRestart?"restarting":"reconnecting");const ne=await Ru(n?.currentVersion,void 0,void 0,P);if(!(ne.stale||qe()!==P)){if(ne.applied){window.location.reload();return}p("error"),m(ne.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update")}},[n?.currentVersion]),V=Ae.useCallback(()=>{_(j)},[_,j]),O=b!=="idle"&&b!=="error",T=Ae.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const U=Tu(P);return U.length===0?{kind:"raw",title:"What's new",content:Ho(P)}:{kind:"sections",title:"What's new",sections:[...U].sort((W,G)=>Mu(W.version,G.version)).map(W=>({version:W.version,dateLabel:Eu(W.date),content:Ho(Pu(W.raw)||P)}))}},[n?.body]);return t.jsx(Yt,{open:e,onOpenChange:O?void 0:s,children:t.jsxs(qt,{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(R,{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||D)&&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&&D&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),D&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:D})]}),C&&M&&t.jsx("span",{className:"ml-3 typography-meta text-muted-foreground",children:M==="rc"?"RC subscription":"Stable subscription"})]}),t.jsxs("div",{className:"space-y-2",children:[C&&O&&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(R,{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."})]}),T&&!O&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(xs,{className:"max-h-[400px] p-0",fillContainer:!1,children:T.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:P=>{const ne=P.target.closest("a");ne&&ne.href&&(P.preventDefault(),P.stopPropagation(),_(ne.href))},children:t.jsx(Po,{content:T.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:T.sections.map(P=>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",P.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.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:U=>{const W=U.target.closest("a");W&&W.href&&(U.preventDefault(),U.stopPropagation(),_(W.href))},children:t.jsx(Po,{content:P.content,disableLinkSafety:!0,enableFileReferences:!1})})]},P.version))})})}),(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})}),C&&b==="error"&&(w??[k]).length>0&&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(R,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:w?"Run these commands:":"Or update via terminal:"})]}),(w??[k]).map(P=>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:P}),t.jsx(Te,{variant:"ghost",size:"icon",onClick:()=>{B(P)},className:f===P?"text-[var(--status-success)]":void 0,title:f===P?"Copied!":"Copy command","aria-label":f===P?"Copied!":"Copy command",children:f===P?t.jsx(R,{name:"check",className:"h-4 w-4"}):t.jsx(R,{name:"clipboard",className:"h-4 w-4"})})]},P))]}),!C&&!y&&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:[N,"%"]})]}),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:`${N}%`}})})]})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:A,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(R,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!C&&!y&&!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(R,{name:"download",className:"h-4 w-4"}),"Download Update"]}),!C&&!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(R,{name:"loader",className:"h-4 w-4 animate-spin"}),"Downloading..."]}),!C&&!y&&o&&t.jsxs("button",{onClick:d,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(R,{name:"restart",className:"h-4 w-4"}),"Restart to Update"]}),y&&t.jsxs(Te,{onClick:V,size:"default",children:[t.jsx(R,{name:"external-link",className:"h-4 w-4"}),"Open update"]}),C&&!O&&t.jsxs("button",{onClick:K,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(R,{name:"download",className:"h-4 w-4"}),"Update Now"]}),C&&O&&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(R,{name:"loader",className:"h-4 w-4 animate-spin"}),"Updating..."]})]})]})]})})},Fu=i.memo(function({checked:s,onChange:n,disabled:r=!1,ariaLabel:o,className:a,iconClassName:l}){const c=i.useCallback(u=>{u.preventDefault(),u.stopPropagation(),!r&&!s&&n()},[s,r,n]),d=i.useCallback(u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),!r&&!s&&n())},[s,r,n]);return t.jsx("button",{type:"button",role:"radio",onClick:c,onKeyDown:d,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)})})}),gn=({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 d=a.current;d&&c.target instanceof Node&&d.contains(c.target)||o(!1)};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[r]),t.jsxs($e,{open:r,onOpenChange:o,children:[t.jsx(Ge,{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(R,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Ke,{sideOffset:8,className:$("max-w-sm",n),children:e})]})},fg="w-full min-w-40 max-w-48",hg="settings",Ou="w-full min-w-40 max-w-48",pg="h-8 w-8 px-0 text-muted-foreground hover:text-foreground",Lu="w-full max-w-[24rem]",mg="min-w-0 flex-1",gg="flex w-full min-w-0 items-center gap-2",bg="typography-meta shrink-0 text-muted-foreground tabular-nums",pa="space-y-3.5",Bu="space-y-1.5",xg="typography-settings-page-title text-muted-foreground",_u="typography-settings-section-title text-foreground",ma="typography-settings-group-title text-foreground",ro="typography-settings-field-label text-foreground",Uu="typography-settings-description text-muted-foreground",bn="typography-meta text-muted-foreground",yg="typography-meta font-medium text-foreground",vg="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:d,settingsItem:u})=>{const f=e!=null||s!=null||o!=null||r!=null;return t.jsxs("section",{"data-settings-item":u,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:_u,children:e}):e,n,r!=null?t.jsx(gn,{children:r}):null]}):null,s!=null?t.jsx("div",{className:Uu,children:s}):null]}),o?t.jsx("div",{className:"shrink-0",children:o}):null]}):null,t.jsx("div",{className:$(d),children:a})]})},wg=({children:e,className:s})=>t.jsx("div",{className:$("grid grid-cols-1 gap-6 @3xl:grid-cols-2 @3xl:gap-10",s),children:e}),$u=({children:e,className:s,as:n="h3"})=>t.jsx(n,{className:$(ma,s),children:e}),Sg=({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($u,{children:e}),n!=null?t.jsx(gn,{children:n}):null]}):null,s!=null?t.jsx("p",{className:bn,children:s}):null]}):null,t.jsx("div",{className:$(a),children:r})]}),cn=({label:e,description:s,info:n,descriptionPlacement:r="before",children:o,settingsItem:a,className:l,controlClassName:c})=>{const d=s!=null?t.jsx("p",{className:bn,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:ro,children:e}),n!=null?t.jsx(gn,{children:n}):null]}),r==="before"?d:null]}),t.jsx("div",{className:$("flex min-w-0 max-w-[24rem] items-center gap-2",c),children:o}),r==="after"?d:null]})},jg=({label:e,description:s,info:n,children:r,settingsItem:o,className:a,labelClassName:l,controlClassName:c,alignEnd:d=!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",l),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:ro,children:e}),n!=null?t.jsx(gn,{children:n}):null]}),s!=null?t.jsx("p",{className:$(bn,"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",d&&"@xl:justify-end",c),children:r})]}),Cg=({children:e,className:s,settingsItem:n})=>t.jsx("div",{"data-settings-item":n,className:$("pt-4",s),children:e}),Gu=({checked:e,onChange:s,label:n,description:r,disabled:o=!1,ariaLabel:a,settingsItem:l,className:c,labelAccessory:d,info:u})=>{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(Nr,{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:ro,children:n}),d,u!=null?t.jsx(gn,{children:u}):null]}),h?t.jsx("span",{className:bn,children:r}):null]})]})},kg=({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(Fu,{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:bn,children:r}):null]})]}),Ag=({"aria-label":e,children:s,className:n})=>t.jsx("div",{role:"radiogroup","aria-label":e,className:$(Bu,n),children:s});function Ng({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(Te,{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))})}const Gr="pichamber:server-update-channel-changed",Ig=()=>{typeof window<"u"&&window.dispatchEvent(new Event(Gr))},Ku=e=>typeof window>"u"?()=>{}:(window.addEventListener(Gr,e),()=>window.removeEventListener(Gr,e));class Wu 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(nc,{className:"w-full max-w-md",children:[t.jsx(rc,{className:"text-center",children:t.jsxs(oc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(R,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(ic,{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(Te,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(R,{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 Hu(e){return t.jsx(Wu,{...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 Rg=({active:e=!0})=>{const s=De(n=>n.currentSessionId);return t.jsx(Hu,{sessionId:s||void 0,children:t.jsx(ac,{active:e},s??"no-session")})};function Yu({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 ga=Ae.forwardRef(({className:e,outerClassName:s,scrollbarClassName:n,fillContainer:r=!1,useScrollShadow:o=!1,scrollShadowSize:a,hasError:l,resizedHeight:c,onResizeHeightChange:d,disabled:u,simple:f,endSlot:h,...b},p)=>{const g=Ae.useRef(null),m=Ae.useRef(null),[w,x]=Ae.useState(null),I=c??w,v=Ae.useCallback(j=>{const N=g.current;if(!N)return;m.current={startY:j.clientY,startHeight:N.getBoundingClientRect().height};const C=j.currentTarget;C.setPointerCapture(j.pointerId);const y=D=>{const M=m.current;if(!M)return;const B=M.startHeight+(D.clientY-M.startY),_=Math.max(82,B);d?d(_):x(_)},k=()=>{m.current=null,C.removeEventListener("pointermove",y),C.removeEventListener("pointerup",k),C.removeEventListener("pointercancel",k)};C.addEventListener("pointermove",y),C.addEventListener("pointerup",k),C.addEventListener("pointercancel",k),j.preventDefault()},[d]),A=Ae.useCallback(j=>{if(j.target.closest('textarea, button, [role="separator"]'))return;const C=g.current?.querySelector("textarea");C&&document.activeElement!==C&&(j.preventDefault(),C.focus())},[]);return f?t.jsx(xs,{as:"textarea",ref:p,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:u,...b}):t.jsx("div",{ref:g,onPointerDown:A,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:p,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",!u&&["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"],u&&"text-muted-foreground/60 placeholder:text-muted-foreground/60",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:u,...b}),t.jsxs("div",{className:"flex items-center justify-end gap-1.5 pl-3 pr-2.5",children:[h,t.jsx(Yu,{onResizeStart:v,ariaLabel:"Resize textarea"})]})]})})});ga.displayName="Textarea";const ba=[{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"}],dn=Object.fromEntries(ba.map(e=>[e.key,e.Icon])),Kr="pichamber:project-actions-updated",xa=e=>{const s=(e||"").trim().replace(/\\/g,"/");return s?s==="/"?"/":s.length>1?s.replace(/\/+$/,""):s:""},Xt=(e,s)=>`${xa(e)}::${s}`,ya=({title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,children:l,className:c,contentClassName:d,divider:u=!0})=>t.jsx(zu,{title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,divider:u,className:c,contentClassName:d,children:l}),Wr=e=>e.name.trim().length>0&&e.command.trim().length>0,qu=e=>e.name.trim().length===0&&e.command.trim().length===0,Qu=e=>!Wr(e)&&!qu(e),Vu=(e,s)=>e.some(r=>s.has(r.id)&&!Wr(r))?{canPersist:!1,actions:e}:{canPersist:!0,actions:e.filter(Wr)},Ju=450,Xu=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Zu=()=>({id:Xu(),name:"",command:"",icon:"play"}),ef=({projectRef:e})=>{const[s,n]=i.useState([]),[r,o]=i.useState(!1),[a,l]=i.useState(null),[c,d]=i.useState(new Set),u=i.useRef(!1);i.useEffect(()=>{let x=!1;return o(!0),(async()=>{try{const I=await Ir(e);if(x)return;n(I.actions),l(JSON.stringify({actions:I.actions})),d(new Set(I.actions.map(v=>v.id)))}catch{if(x)return;n([]),l(JSON.stringify({actions:[]})),d(new Set)}finally{x||o(!1)}})(),()=>{x=!0}},[e]);const f=i.useMemo(()=>Vu(s,c),[s,c]),h=i.useMemo(()=>JSON.stringify({actions:f.actions}),[f.actions]),b=a!==null&&f.canPersist&&h!==a,p=i.useCallback(async x=>await lc(e,{actions:x,primaryActionId:null})?(l(JSON.stringify({actions:x})),d(new Set(x.map(v=>v.id))),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Kr,{detail:{projectId:e.id}})),!0):(oe.error("Failed to save actions"),!1),[e]);i.useEffect(()=>{if(!b||r||u.current)return;const x=window.setTimeout(()=>{u.current||(u.current=!0,(async()=>{try{await p(f.actions)}finally{u.current=!1}})())},Ju);return()=>{window.clearTimeout(x)}},[b,r,p,f.actions]);const g=i.useCallback(()=>{const x=Zu();n(I=>[...I,x])},[]),m=i.useCallback(x=>{n(I=>I.filter(v=>v.id!==x))},[]),w=i.useCallback((x,I)=>{n(v=>v.map(A=>A.id===x?I(A):A))},[]);return t.jsx(ya,{title:"Actions",info:"Per-project commands shown in the header next to the project name.",settingsItem:"projects.actions",headerAction:t.jsxs(Te,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:[t.jsx(R,{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",Lu),children:s.map((x,I)=>{const v=x.icon||"play",A=dn[v]||"play",j=x.name.trim()||`Action ${I+1}`,N=Qu(x);return t.jsxs("div",{className:pa,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:ma,children:j}),t.jsx(Te,{type:"button",variant:"ghost",size:"xs",className:"h-8 w-8 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>m(x.id),"aria-label":`Delete ${j}`,children:t.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsxs(cn,{label:"Name",controlClassName:"w-full max-w-none",children:[t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:A,className:"h-4 w-4"})})}),t.jsx(Dt,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:ba.map(C=>{const y=C.Icon,k=(x.icon||"play")===C.key;return t.jsx("button",{type:"button",onClick:()=>w(x.id,D=>({...D,icon:C.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 ${C.label}`,children:t.jsx(R,{name:y,className:"h-4 w-4"})},C.key)})})})]}),t.jsx(fn,{value:x.name,onChange:C=>w(x.id,y=>({...y,name:C.target.value})),placeholder:"Action name",className:"h-8 min-w-0 flex-1 rounded-md px-3"})]}),t.jsx(cn,{label:"Command",controlClassName:"w-full max-w-none",children:t.jsx(ga,{value:x.command,onChange:C=>w(x.id,y=>({...y,command:C.target.value})),placeholder:"e.g. bun run lint",className:"min-h-[88px] w-full font-mono text-xs"})}),N?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Enter a name and command to save this action."}):null,t.jsx(Gu,{checked:x.autoOpenUrl===!0,onChange:C=>w(x.id,y=>({...y,...C?{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 ${j}`}),x.autoOpenUrl===!0?t.jsx(t.Fragment,{children:t.jsx(cn,{label:"Custom URL",info:"Leave empty to use the best URL from command output.",controlClassName:"w-full max-w-none",children:t.jsx(fn,{value:x.openUrl||"",onChange:C=>w(x.id,y=>({...y,openUrl:C.target.value})),placeholder:"https://localhost:3000",className:"h-8 w-full rounded-md px-3"})})}):null]},x.id)})})})},tf={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)"},sf=({value:e,noneLabel:s,ariaLabel:n,disabled:r=!1,className:o,isModelAllowed:a,onChange:l})=>{const c=Wt(y=>y.providers),d=Wt(y=>y.modelsMetadata),u=ce(y=>y.hiddenModels),f=ce(y=>y.isFavoriteModel),h=ce(y=>y.toggleFavoriteModel),b=ce(y=>y.reorderFavoriteModel),{favoriteModelsList:p,recentModelsList:g}=cc(),[m,w]=i.useState(!1),[x,I]=i.useState("");i.useEffect(()=>{m||I("")},[m]);const v=e?c.find(y=>y.id===e.providerId):void 0,A=e&&v?(Array.isArray(v.models)?v.models:[]).find(y=>y.id===e.modelId):void 0,j=e?dc(A,e.modelId):s,N=i.useMemo(()=>e?u.filter(y=>!(y.providerID===e.providerId&&y.modelID===e.modelId)):u,[u,e]),C=i.useCallback(y=>{l({providerId:y.providerID,modelId:y.modelID}),w(!1)},[l]);return t.jsxs(It,{modal:!1,open:m,onOpenChange:y=>{r||w(y)},children:[t.jsx(Rt,{asChild:!0,disabled:r,children:t.jsxs("button",{type:"button","aria-label":n,disabled:r,className:$(Ci({size:"default"}),Ou,"min-w-0",o),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e?.providerId?t.jsx(uc,{providerId:e.providerId,className:"size-4 shrink-0"}):null,t.jsx("span",{className:$("truncate",e?"text-foreground":"text-muted-foreground"),children:j})]}),t.jsx(R,{name:"arrow-down-s",className:"size-4 shrink-0"})]})}),t.jsx(Dt,{align:"start",portalToBody:!0,positionerClassName:"z-[80]",className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",children:t.jsx(fc,{providers:c,favoriteModels:p,recentModels:g,modelsMetadata:d,searchQuery:x,onSearchQueryChange:I,onSelect:C,labels:{...tf,notSelected:s},selectedModel:e?{providerID:e.providerId,modelID:e.modelId}:null,hiddenModels:N,isModelAllowed:a,includeNotSelected:!0,onSelectNone:()=>{l(null),w(!1)},disabled:r,autoFocus:!0,onEscape:()=>w(!1),isFavorite:y=>f(y.providerID,y.modelID),onToggleFavorite:y=>h(y.providerID,y.modelID),onReorderFavorite:(y,k)=>b(y.providerID,y.modelID,k.providerID,k.modelID),reorderFavoriteAriaLabel:"Reorder favorite",reorderFavoriteTitle:"Drag to reorder favorite"})})]})},dr="w-full max-w-none",nf=({form:e})=>{const{name:s,setName:n,parsedDefaultModel:r,handleDefaultModelChange:o,project:a}=e,l=Wt(c=>c.loadProviders);return i.useEffect(()=>{l({source:"projectSettings"})},[l]),a?t.jsx(ya,{title:"Project",divider:!1,children:t.jsxs("div",{className:pa,children:[t.jsx(cn,{label:"Name",settingsItem:"projects.name",controlClassName:dr,children:t.jsx(fn,{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(cn,{label:"Default model",info:"Used when starting a new chat in this project. Unset keeps the global session default.",settingsItem:"projects.default-model",controlClassName:dr,children:t.jsx(sf,{value:r,noneLabel:"Use global default",ariaLabel:"Default model for new chats",className:dr,onChange:c=>{if(!c){o("","");return}o(c.providerId,c.modelId)}})})]})}):null},rf=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(()=>hc(r),[r]),l=!!e&&(s.trim()!==(e?.label??"").trim()||(r??void 0)!==(e?.defaultModel??void 0)),c=i.useCallback((u,f)=>{o(u&&f?`${u}/${f}`:void 0)},[]),d=i.useCallback(async()=>{if(!e)return null;const u=s.trim();return u?{label:u,defaultModel:r??null}:null},[r,s,e]);return{name:s,setName:n,defaultModel:r,parsedDefaultModel:a,handleDefaultModelChange:c,hasChanges:l,prepareSaveData:d,project:e}},of=450,af=(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 d=await a();if(d)try{await s(d)}catch{oe.error("Failed to save project settings")}}finally{l.current=!1}})())},of);return()=>{window.clearTimeout(c)}},[o,n,r,s,a])},lf=({project:e,onIdentitySave:s})=>{const n=rf(e),r=i.useMemo(()=>e?{id:e.id,path:e.path}:null,[e]),o=i.useCallback(async a=>{await s(a)},[s]);return af(n,o),!e||!r?null:t.jsxs("div",{className:"space-y-0",children:[t.jsx(nf,{form:n}),t.jsx(ef,{projectRef:r})]})};function oo({...e}){return t.jsx(Hi,{...e})}function io({...e}){return t.jsx(Yi,{...e})}function ao({className:e,positionerClassName:s,children:n,style:r,...o}){return t.jsx(qi,{children:t.jsx(Qi,{className:$("app-region-no-drag z-50",s),children:t.jsx(Vi,{"data-slot":"dropdown-menu-content",style:{color:"var(--surface-elevated-foreground)",...r},className:$(ki,e),...o,children:n})})})}function Os({className:e,...s}){return t.jsx(Ji,{className:$(Ai,e),...s})}function va({className:e,...s}){return t.jsx(Xi,{className:$(Ni,e),...s})}const Nn=100;function Dg(){const e=ce(y=>y.isArchivePageOpen),s=ce(y=>y.setArchivePageOpen),n=ce(y=>y.setActiveMainTab),r=De(y=>y.setCurrentSession),o=De(y=>y.unarchiveSession),a=Bs(y=>y.homeDirectory),l=Rr({archived:!0}),[c,d]=i.useState(""),[u,f]=i.useState(null),[h,b]=i.useState(Nn),p=c.trim().toLowerCase(),g=i.useMemo(()=>e?[...l].sort((y,k)=>(k.time?.archived??0)-(y.time?.archived??0)):[],[l,e]),m=i.useMemo(()=>{const y=new Map;for(const k of g){const D=ke(an(k))??"",M=y.get(D);if(M){M.sessions.push(k);continue}y.set(D,{directory:D,label:D?_s(D,a)||D:"other projects",sessions:[k]})}return[...y.values()].sort((k,D)=>D.sessions.length-k.sessions.length)},[a,g]),w=i.useMemo(()=>p?g.filter(y=>(y.title??"").toLowerCase().includes(p)):u===null?g:m.find(y=>y.directory===u)?.sessions??[],[m,p,u,g]),x=w.slice(0,h),I=w.length-x.length,v=l.length,A=i.useCallback(y=>{f(y),b(Nn)},[]),j=i.useCallback(y=>{const k=ke(an(y));r(y.id,k??void 0),n("chat"),s(!1)},[n,r,s]),N=i.useCallback(y=>{o(y.id).then(k=>{k?oe.success("Session restored"):oe.error("Failed to restore session")})},[o]);if(!e)return null;const C=(y,k,D,M,B,_,K)=>t.jsxs("div",{className:"group/dir relative",children:[t.jsxs("button",{type:"button",onClick:B,title:_,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",K?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",M?"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:D})]}),K?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>Ss.requestDelete({sessions:K,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(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),t.jsx(Ke,{side:"bottom",sideOffset:4,children:"Delete all archived sessions in this project"})]}):null]},y);return t.jsx(Td,{open:e,onOpenChange:s,children:t.jsxs(Fd,{children:[t.jsx(Od,{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(Ld,{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(Bd,{className:"sr-only",children:"Archived sessions"}),t.jsx(_d,{className:"sr-only",children:"Browse and restore archived sessions."}),t.jsx(Ud,{"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(R,{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:[C("__all__","All directories",v,u===null,()=>A(null)),m.map(y=>C(y.directory||"__none__",y.label,y.sessions.length,u===y.directory,()=>A(y.directory),y.directory||void 0,y.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(R,{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:y=>{d(y.target.value),b(Nn)},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:w.length===1?`${w.length} archived session`:`${w.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:p?"No matching archived sessions":"No archived sessions"})}):x.map(y=>{const k=ke(an(y))??"",D=k?_s(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:()=>j(y),role:"button",tabIndex:0,onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),j(y))},children:[t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ds(y)}),p&&D?t.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:k,children:D}):null,t.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Cd(y.time?.archived??y.time?.updated??y.time?.created??Date.now())}),t.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),N(y)},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 ${ds(y)}`,children:t.jsx(R,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),Ss.requestDelete({sessions:[y],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 ${ds(y)}`,children:t.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},y.id)}),I>0?t.jsx("button",{type:"button",onClick:()=>b(y=>y+Nn),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 cf=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}},df=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},Ht=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,uf=e=>{if(!e||typeof e!="object")return null;const s=Ht(e.input),n=Ht(e.output),r=Ht(e.cacheRead),o=Ht(e.cacheWrite);return{input:s,output:n,reasoning:null,cacheRead:r,cacheWrite:o,total:s+n+r+o}},Yo=e=>{const s=uf(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:Ht(r)};if(!r||typeof r!="object")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0};const o=r,a=Ht(o.input),l=Ht(o.output),c=Ht(o.reasoning),d=Ht(o.cache?.read),u=Ht(o.cache?.write);return{input:a,output:l,reasoning:c,cacheRead:d,cacheWrite:u,total:a+l+c+d+u}},wa=380,ur=8,ff=140;function hf({open:e,onClose:s,anchorRef:n,closeOnWheel:r=!1}){const o=i.useRef(null),a=i.useRef(null),[l,c]=i.useState(e),[d,u]=i.useState(!1),[f,h]=i.useState(null),{enabled:b}=Jr();return i.useLayoutEffect(()=>{if(!e||!b||!l)return;const p=()=>{const w=n.current?.getBoundingClientRect(),x=a.current?.getBoundingClientRect();if(!w||!x){h(null);return}const I=w.left-x.left;h(Math.min(Math.max(I,ur),Math.max(ur,x.width-wa-ur)))};p();const g=a.current;if(typeof ResizeObserver>"u"||!g)return;const m=new ResizeObserver(p);return m.observe(g),()=>m.disconnect()},[n,b,e,l]),i.useEffect(()=>{if(e){c(!0),u(!1);return}if(!l)return;u(!0);const p=window.setTimeout(()=>{c(!1),u(!1)},ff);return()=>window.clearTimeout(p)},[e,l]),i.useEffect(()=>{if(!e)return;const p=g=>{g.key==="Escape"&&s()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s,e]),i.useEffect(()=>{if(!e)return;const p=g=>{const m=g.target;if(!(m instanceof Node)){s();return}o.current?.contains(m)||n.current?.contains(m)||s()};return document.addEventListener("pointerdown",p,!0),r&&document.addEventListener("wheel",p,!0),()=>{document.removeEventListener("pointerdown",p,!0),r&&document.removeEventListener("wheel",p,!0)}},[n,r,s,e]),{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:d,anchorLeft:f,isPopover:b&&f!==null}}const qo=(e,s)=>{if(!e||typeof e!="object")return;const n=e[s];return typeof n=="number"&&Number.isFinite(n)?n:void 0},Kn=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),In=({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(R,{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})]}),pf=({open:e,onClose:s,anchorRef:n,contextDisplay:r})=>{const{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:c,anchorLeft:d,isPopover:u}=hf({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",u?"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))",...u?{top:8,left:d??8,width:`min(${wa}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsxs(t.Fragment,{children:[t.jsx(In,{iconNode:t.jsx(Ii,{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(In,{icon:"stack",label:"Cache read",children:t.jsx("span",{className:"tabular-nums",children:Kn(r.cacheRead)})}),t.jsx(In,{icon:"edit",label:"Cache write",children:t.jsx("span",{className:"tabular-nums",children:Kn(r.cacheWrite)})})]}):null,r.cacheHitPercent!==null?t.jsx(In,{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-DYXaDVnz.js","assets/useAppFontEffects-SHxBpd4f.js","assets/index-CpSdU-d4.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-Dwz16owi.css","assets/vendor-base-ui-DXSHfszQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-Bm6cRkok.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-B4enwgcI.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-B1Zc3P5v.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-DcCgFOGI.js","assets/isDiffPlainText-DMMH-XmY.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-DGvRKfRw.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as cs}from"./vendor-vite-runtime-DD1OZmLC.js";import{r as Ae,j as t,R as i,b as tc}from"./vendor-react-B5Z1Mdn3.js";import{aQ as Ts,aR as sc,a2 as It,a3 as $e,a4 as Ge,a5 as Rt,B as Te,I as R,a6 as Ke,a7 as Dt,a9 as ot,t as oe,a as pt,f as De,_ as $s,ae as fn,aS as Si,ag as Yt,ah as qt,ai as fs,aj as es,ak as hs,al as ks,aG as Ss,aT as js,g as Ms,aU as lr,aV as Do,aW as Eo,aX as on,e as Mn,o as ji,af as xs,aY as Po,a8 as us,aZ as Nr,a_ as nc,a$ as rc,b0 as oc,b1 as ic,b2 as ac,b3 as Ir,b4 as lc,y as Wt,b5 as cc,b6 as dc,b7 as uc,b8 as Ci,b9 as fc,ba as hc,bb as ki,bc as Ai,bd as Ni,aD as Rr,r as an,n as Jr,ap as pc,az as mc,aC as Ii,L as As,d as Xr,ab as Gs,ay as Ri,be as Vn,bf as Mo,bg as ht,aE as Di,bh as Ei,au as gc,h as Pi,j as bc,bi as xc,i as yc,bj as Ds,b as To,c as vc,bk as wc,u as Sc,aF as jc,aI as Cc,bl as Dr,bm as kc,bn as Ac,aH as Nc,bo as Ic,bp as Rc,T as Dc,aa as Cs,am as Mi,w as Ec,ac as Pc,bq as Mc,br as Tc,k as Fc,bs as Oc,bt as Ti,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,bD as Hc}from"./useAppFontEffects-SHxBpd4f.js";import{Z as Fo,_ as Yc,R as Ls,$ as Fi,a0 as Oi,a1 as qc,a2 as Qc,u as Bs,K as Vc,a3 as Jc,a4 as Xc,a5 as Zc,a6 as Vt,v as Jt,a7 as ed,a8 as td,a9 as sd,aa as Zr,m as Ct,ab as nd,ac as rd,ad as od,t as ce,o as $,ae as id,f as qe,B as ke,af as _s,ag as _t,ah as Oo,ai as Er,a as eo,T as to,U as Un,aj as ad,ak as ld,al as Li,F as cd,Q as Bi,C as ln,am as Pr,h as Mr,d as kn,an as dd,ao as ud,ap as Lo,aq as en,ar as cr,as as Tr,at as zn,au as ys,av as Bo,aw as Fr,ax as _i,ay as Or,az as fd,z as Ui,aA as hd,aB as pd,aC as md,aD as gd,aE as bd,aF as xd,aG as yd,aH as vd,Y as zi,P as wd,J as Sd}from"./index-CpSdU-d4.js";import{c as Ks,d as $i,p as so,u as Lr,a as jd}from"./vendor-zustand-GVb4H8HE.js";import{g as ds,b as Cd,c as Gi,r as kd,d as Ki,s as Tn,e as Wi,h as hn,i as pn,j as Ad,k as Nd,l as Id,m as _o,n as Jn,f as Rd,a as Dd,S as Ed,t as Pd,o as Md}from"./SessionUnreadDot-CPTTyo0r.js";import{C as Hi,a as Yi,M as qi,b as Qi,c as Vi,d as Ji,S as Xi,D as Td,e as Fd,f as Od,g as Ld,h as Bd,i as _d,j as Ud}from"./vendor-base-ui-DXSHfszQ.js";import{c as Zi,d as Br,P as zd,D as ea,e as ta,f as $d,b as Gd,a as Kd,T as Wd,M as Hd}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{u as Yd}from"./vendor-tanstack-react-virtual-2skouoFw.js";import{S as qd,v as Qd,u as Vd}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as Jd}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-xterm-xterm-CrXqRur4.js";import{usePermissionStore as Xd}from"./permissionStore-iKN1K2_x.js";const Zd="chat";function sa(e){const s=new URLSearchParams;if(e.sessionId&&e.sessionId.trim().length>0&&s.set(Ts.SESSION,e.sessionId),e.isSettingsOpen){const n=e.settingsPath.trim().length>0?e.settingsPath:"home";return s.set(Ts.SETTINGS,n),s}return e.tab!==Zd&&s.set(Ts.TAB,e.tab),e.tab==="diff"&&e.diffFile&&e.diffFile.trim().length>0&&s.set(Ts.FILE,e.diffFile),s}function eu(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 tu(e){if(typeof window>"u")return!0;try{const s=new URLSearchParams(window.location.search),n=sa(e),r=window.location.pathname.match(/^\/(?:session|s)\/([^/?#]+)/i),o=r?.[1]?decodeURIComponent(r[1].trim()):null;o&&!s.has(Ts.SESSION)&&s.set(Ts.SESSION,o);const a=[...s.entries()].sort((c,d)=>c[0].localeCompare(d[0])),l=[...n.entries()].sort((c,d)=>c[0].localeCompare(d[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 _r(e,s={}){if(!(typeof window>"u")&&!(!s.force&&tu(e)))try{const n=sa(e),r=eu(n);s.replace?window.history.replaceState({...window.history.state,route:e},"",r):window.history.pushState({route:e},"",r)}catch{}}const su=["typescript","javascript","tsx","jsx","json","markdown"],na={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Uo=null;const ra=()=>(Uo??=Promise.all([cs(()=>import("./index-DYXaDVnz.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])),cs(()=>import("./workerFactory-tw7cIdmV.js"),[]),cs(()=>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})),Uo),mn={},zo=new Set,Ur=new Set;let Fn={light:"pierre-light",dark:"pierre-dark"};const nu=()=>{for(const e of Ur)e()},oa=(e,s)=>{s.setRenderOptions({theme:Fn,lineDiffType:na[e].lineDiffType})},zr=e=>{typeof window>"u"||zo.has(e)||(zo.add(e),ra().then(s=>{if(mn[e])return;const n=na[e],r=new s.WorkerPoolManager({workerFactory:s.workerFactory,poolSize:n.poolSize,totalASTLRUCacheSize:n.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:su,lineDiffType:n.lineDiffType,preferredHighlighter:"shiki-wasm"});r.initialize(),mn[e]=r,oa(e,r),nu()}))},ru=e=>(Ur.add(e),()=>Ur.delete(e)),ou=e=>{if(!(Fn.light===e.light&&Fn.dark===e.dark)){Fn=e;for(const s of Object.keys(mn)){const n=mn[s];n&&oa(s,n)}}},ng=({children:e})=>{const s=sc(),n=Fo(!1),r=Fo(!0),o=s?.lightThemeId??n.metadata.id,a=s?.darkThemeId??r.metadata.id,l=s?.availableThemes.find(d=>d.metadata.id===o)??n,c=s?.availableThemes.find(d=>d.metadata.id===a)??r;return Ae.useEffect(()=>{let d=!1;return ra().then(u=>{d||(u.ensurePierreThemeRegistered(l),u.ensurePierreThemeRegistered(c),ou({light:l.metadata.id,dark:c.metadata.id}))}),()=>{d=!0}},[c,l]),Ae.useEffect(()=>{if(typeof window>"u")return;const d=()=>{zr("unified"),zr("split")};if(typeof window.requestIdleCallback=="function"){const f=window.requestIdleCallback(d,{timeout:5e3});return()=>window.cancelIdleCallback(f)}const u=window.setTimeout(d,2e3);return()=>window.clearTimeout(u)},[]),t.jsx(t.Fragment,{children:e})},rg=(e="unified")=>{const s=Ae.useSyncExternalStore(ru,()=>mn[e],()=>{});return Ae.useEffect(()=>{zr(e)},[e]),s},iu={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3",fingerprint:"fingerprint"},au={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 ia(e){return e&&au[e]||"var(--primary)"}const $o=({icon:e,className:s,colorToken:n})=>{const r=iu[e??"branch"]??"user-3";return t.jsx(R,{name:r,className:s,style:{color:ia(n)}})},lu=({activeProfile:e,identities:s,onSelect:n,isApplying:r,iconOnly:o=!1})=>{const a=r||s.length===0;return t.jsxs(It,{children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs(Te,{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:ia(e?.color)},disabled:a,children:[r?t.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx($o,{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(R,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),t.jsx(Ke,{sideOffset:8,children:"Git identity"})]}),t.jsx(Dt,{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(ot,{onSelect:()=>n(l),children:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx($o,{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(R,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},l.id)})})]})},cu=e=>e==="/",Us=e=>e.replace(/\\/g,"/"),zs=e=>{if(!e||cu(e))return e;let s=e;for(;s.length>1&&s.endsWith("/");)s=s.slice(0,-1);return s},Fs=e=>e.endsWith("/"),$n=e=>{const s=e.trim();return!s||Fs(s)?s:`${s}/`},no=e=>e.lastIndexOf("/"),aa=e=>{if(Fs(e))return e;const s=no(e);return s<0?e:e.slice(0,s+1)},la=e=>{const s=no(e);return e.slice(s+1)},ca=e=>{const s=zs(e.trim());if(!s||s==="~"||s==="~/"||s==="/")return null;const n=no(s);return n<0?null:s.startsWith("~/")&&n<=1?"~/":n===0?"/":`${s.slice(0,n)}/`},da=e=>Fs(e)&&ca(e)!==null,du=e=>{if(!da(e))return null;const s=zs(e.trim());return la(s)||s},uu=(e,s)=>`${aa(e)}${s}/`,vs=e=>{if(!e)return null;const s=zs(Us(e.trim()));return s?s.toLowerCase():null},Go=(e,s)=>{const n=e.trim();return n==="~"?s:n.startsWith("~/")?`${s}${n.slice(1)}`:n},fu=(e,s)=>{const n=zs(Us(e.trim())),r=zs(Us(s.trim()));if(!n)return"";if(!r)return $n(n);if(n.toLowerCase()===r.toLowerCase())return"~/";const o=`${r}/`;return n.toLowerCase().startsWith(o.toLowerCase())?`~/${n.slice(r.length+1)}/`:$n(n)},hu=e=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,$r=e=>{if(!e)return;e.focus({preventScroll:!0});const s=e.value.length;e.setSelectionRange(s,s),e.scrollLeft=e.scrollWidth},pu=async()=>Yc(),mu=()=>{const[e,s]=Ae.useState(!1),[n,r]=Ae.useState(!1);Ae.useEffect(()=>{s(Ls()),r(Fi())},[]);const o=Ae.useCallback(async c=>e?await Oi(c):{success:!0,path:c},[e]),a=Ae.useCallback(async c=>e?await qc():{success:!0},[e]),l=Ae.useCallback(async c=>e?await Qc():{success:!0},[e]);return{isDesktop:e,canRequestAccess:n,requestAccess:o,startAccessing:a,stopAccessing:l}};function gu({open:e,addedProjectPaths:s,shouldSuppressAutoFocus:n}){const r=Bs(re=>re.homeDirectory),{canRequestAccess:o,startAccessing:a}=mu(),l=i.useRef(null),c=i.useRef(new Map),[d,u]=i.useState(""),[f,h]=i.useState("~/"),[b,p]=i.useState([]),[g,m]=i.useState(!1),[w,x]=i.useState(!1),[I,v]=i.useState(null),[A,j]=i.useState(0),[N,C]=i.useState(0),[y,k]=i.useState(!1),[D,M]=i.useState(!1),[B,_]=i.useState("right"),K=i.useRef("~/"),V=d||r;i.useEffect(()=>{if(!e)return;h("~/"),p([]),C(0),k(!1),M(!1),K.current="~/",_("right"),n||requestAnimationFrame(()=>$r(l.current));let re=!1;return(async()=>{const H=await pu();re||(u(H||r||""),n||requestAnimationFrame(()=>$r(l.current)))})(),()=>{re=!0}},[r,e,n]);const O=i.useMemo(()=>aa(f),[f]),T=i.useMemo(()=>Fs(f)?"":la(f),[f]),P=i.useMemo(()=>V?Go(O,V):"",[O,V]);i.useEffect(()=>{const re=K.current;re!==O&&(_(O.length>=re.length?"right":"left"),K.current=O)},[O]),i.useEffect(()=>{if(!e||!P){p([]),v(null);return}let re=!1;return m(!0),x(!1),v(null),Vc(P).then(ae=>{if(re)return;x(!1),v(null);const H=ae.filter(me=>me.isDirectory).map(me=>({name:me.name,path:Us(me.path)})).sort((me,Ue)=>me.name.localeCompare(Ue.name));p(H)}).catch(ae=>{if(!re){p([]);const H=Jc(ae)?ae.reason:"unknown";v(H),x(H==="not-found")}}).finally(()=>{re||m(!1)}),()=>{re=!0}},[P,A,e]);const U=i.useMemo(()=>{const re=T.toLowerCase(),ae=D||T.startsWith(".");return b.filter(H=>H.name.toLowerCase().startsWith(re)&&(ae||!H.name.startsWith(".")))},[T,b,D]),ne=i.useMemo(()=>du(f),[f]),W=i.useMemo(()=>ca(f),[f]),G=i.useMemo(()=>{const re=[],ae=vs(P);da(f)&&ne&&W&&re.push({type:"parent",value:"browse:up",name:ne,path:W,alreadyAdded:!!(ae&&s.has(ae))});for(const H of U){const me=vs(H.path);re.push({type:"directory",value:`browse:${H.path}`,name:H.name,path:H.path,alreadyAdded:!!(me&&s.has(me))})}return re},[s,P,ne,U,W,f]);i.useEffect(()=>{C(0)},[f,G.length]);const Ne=i.useMemo(()=>V?zs(Go(f,V)):"",[V,f]),ee=vs(Ne),Fe=!!(ee&&s.has(ee)),_e=i.useMemo(()=>T?U.find(re=>re.name===T)??null:null,[T,U]),q=!!(Ne&&!Fe&&(I===null||I==="not-found")&&(Fs(f)&&w||!Fs(f)&&T.trim().length>0&&_e===null)),F=G[N]??null,z=!!F,Q=i.useCallback(re=>{h($n(re))},[]),se=i.useCallback(re=>{h(uu(f,re.name))},[f]),Se=i.useCallback(re=>{if(re){if(re.type==="parent"){Q(re.path);return}se(re)}},[Q,se]),ge=i.useCallback(async re=>{const ae=await a(re);if(!ae.success)return oe.error("Failed to open directory",{description:ae.error||"Desktop could not grant file access."}),!1;const H=V?fu(re,V):$n(Us(re));return Q(H),!0},[Q,V,a]),we=i.useCallback(async()=>{if(!y){k(!0);try{if(Fi()){const ae=await Oi(Ne);if(!ae.success||!ae.path){ae.error&&ae.error!=="Directory selection cancelled"&&oe.error("Failed to select directory",{description:ae.error});return}await ge(ae.path);return}const re=await Xc(Ne);if(re.status==="cancelled")return;if(re.status!=="picked"){oe.error("Couldn't open a folder picker",{description:re.error});return}await ge(re.path)}catch(re){oe.error("Failed to select directory",{description:re instanceof Error?re.message:"Unknown error occurred."})}finally{k(!1)}}},[ge,y,Ne]);return{inputRef:l,rowRefs:c,query:f,setQuery:h,isLoading:g,isBrowseDirectoryMissing:w,browseErrorReason:I,browseReloadKey:A,setBrowseReloadKey:j,highlightedIndex:N,setHighlightedIndex:C,isPickingLocation:y,showHidden:D,setShowHidden:M,folderEnterFrom:B,explorerRootDirectory:V,browseDirectoryDisplayPath:O,browseDirectoryAbsolutePath:P,browseFilterQuery:T,filteredEntries:U,rows:G,targetPath:Ne,isAlreadyAdded:Fe,shouldCreateTarget:q,highlightedRow:F,hasHighlightedBrowseItem:z,canRequestAccess:o,browseToDisplayPath:Q,browseToEntry:se,executeRow:Se,applyPickedLocation:ge,handleBrowseLocation:we}}const bs=Ks()($i(so((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 od();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 rd();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 nd();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 Ct("/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 Zr({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 sd(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 td(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 ed(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:Zc(),partialize:e=>({selectedProfileId:e.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=bs);function bu({open:e,onClose:s,isMobile:n,addedProjectPaths:r,targetPath:o,shouldCreateTarget:a,browseErrorReason:l,browseDirectoryAbsolutePath:c,isAlreadyAdded:d,isPickingLocation:u}){const f=pt(W=>W.addProject),h=ce(W=>W.setActiveMainTab),b=ce(W=>W.setSessionSwitcherOpen),p=De(W=>W.openNewSessionDraft),g=bs(W=>W.profiles),m=bs(W=>W.globalIdentity),w=bs(W=>W.defaultGitIdentityId),x=bs(W=>W.loadProfiles),I=bs(W=>W.loadGlobalIdentity),v=bs(W=>W.loadDefaultGitIdentityId),[A,j]=i.useState(!1),[N,C]=i.useState(!1),[y,k]=i.useState(""),[D,M]=i.useState(null);i.useEffect(()=>{e&&(j(!1),C(!1),k(""),M(null))},[e]),i.useEffect(()=>{e&&(x(),I(),v())},[v,x,I,e]);const B=i.useMemo(()=>{const W=new Map;m&&W.set(m.id,m);for(const G of g)W.set(G.id,G);return Array.from(W.values())},[g,m]);i.useEffect(()=>{if(!e||!N||D!==null)return;const W=typeof w=="string"?w.trim():"";if(W&&B.some(Ne=>Ne.id===W)){M(W);return}const G=B.find(Ne=>Ne.authType==="ssh"||Ne.sshKey);G&&M(G.id)},[B,w,N,e,D]);const _=i.useMemo(()=>B.find(W=>W.id===D)??null,[B,D]),K=i.useCallback((W,G)=>{h("chat"),n&&b(!1),p({selectedProjectId:W,directoryOverride:G}),s()},[n,s,p,h,b]),V=i.useCallback(async W=>{if(!W||A)return;const G=vs(W);if(G&&r.has(G))return;let Ne=W;j(!0);try{const ee=!N&&a&&vs(W)===vs(o);if(N){const _e=y.trim();if(!_e){oe.error("Enter a repository URL before cloning.");return}const q=await Ct("/api/fs/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:_e,destinationPath:W,gitIdentityId:_?.id??null})});if(!q.ok)throw new Error("Failed to clone git repository");Ne=(await q.json()).path||W}else if(ee&&!(await Ct("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},query:c?{directory:c}:void 0,body:JSON.stringify({path:W})})).ok)throw new Error("Failed to select directory");const Fe=f(Ne);if(!Fe){oe.error("Failed to add folder",{description:"Please select a valid directory path."});return}K(Fe.id,Fe.path)}catch(ee){oe.error("Failed to select directory",{description:ee instanceof Error?ee.message:"Unknown error occurred."})}finally{j(!1)}},[f,r,c,y,N,A,K,_?.id,a,o]),O=!A&&!u&&!d&&l!=="os-permission"&&l!=="invalid-response"&&l!=="unknown"&&!!o,T=O&&y.trim().length>0,P=N?T:O,U=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";return{isConfirming:A,isCloneMode:N,setIsCloneMode:C,cloneRemoteUrl:y,setCloneRemoteUrl:k,selectedGitIdentityId:D,setSelectedGitIdentityId:M,availableGitIdentities:B,selectedGitIdentity:_,canSubmit:P,submitActionLabel:d?"Already added":N?A?"Cloning...":"Clone & add":A?"Adding...":a?"Create & add":"Add folder",submitModifierLabel:U,finalizeSelection:V}}const xu=({open:e,onOpenChange:s})=>{const n=pt(H=>H.projects),{isMobile:r,isTablet:o}=$s(),a=r||o,l=i.useMemo(()=>new Set(n.map(H=>vs(H.path)).filter(H=>!!H)),[n]),c=i.useCallback(()=>{s(!1)},[s]),{inputRef:d,rowRefs:u,query:f,setQuery:h,isLoading:b,browseErrorReason:p,setBrowseReloadKey:g,highlightedIndex:m,setHighlightedIndex:w,isPickingLocation:x,showHidden:I,setShowHidden:v,folderEnterFrom:A,browseDirectoryDisplayPath:j,browseDirectoryAbsolutePath:N,rows:C,targetPath:y,isAlreadyAdded:k,shouldCreateTarget:D,highlightedRow:M,hasHighlightedBrowseItem:B,canRequestAccess:_,executeRow:K,handleBrowseLocation:V}=gu({open:e,addedProjectPaths:l,shouldSuppressAutoFocus:a}),{isConfirming:O,isCloneMode:T,setIsCloneMode:P,cloneRemoteUrl:U,setCloneRemoteUrl:ne,setSelectedGitIdentityId:W,availableGitIdentities:G,selectedGitIdentity:Ne,canSubmit:ee,submitActionLabel:Fe,submitModifierLabel:_e,finalizeSelection:q}=bu({open:e,onClose:c,isMobile:r,addedProjectPaths:l,targetPath:y,shouldCreateTarget:D,browseErrorReason:p,browseDirectoryAbsolutePath:N,isAlreadyAdded:k,isPickingLocation:x});i.useLayoutEffect(()=>{const H=d.current;H&&(H.scrollLeft=H.scrollWidth)},[d,f]),i.useLayoutEffect(()=>{!e||a||$r(d.current)},[d,e,a]),i.useLayoutEffect(()=>{const H=C[m];H&&u.current.get(H.value)?.scrollIntoView({block:"nearest"})},[m,u,C]);const F=i.useCallback(H=>{if(H.key==="ArrowDown"){H.preventDefault(),w(me=>Math.min(C.length-1,me+1));return}if(H.key==="ArrowUp"){H.preventDefault(),w(me=>Math.max(0,me-1));return}if(H.key==="Enter"){if(H.preventDefault(),hu(H)){q(y);return}B&&K(M);return}H.key==="Backspace"&&f===""&&(H.preventDefault(),c())},[K,q,c,B,M,f,C.length,w,y]),z=t.jsxs("button",{type:"button",onClick:()=>v(H=>!H),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(R,{name:"checkbox",className:"h-4 w-4 text-primary"}):t.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}),"Show hidden"]}),Q=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(R,{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(fn,{ref:d,value:f,onChange:H=>h(Us(H.target.value)),onKeyDown:F,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(Te,{variant:"outline",size:"xs",className:"h-8 shrink-0 gap-1 px-2",disabled:O||x,onMouseDown:H=>H.preventDefault(),onClick:()=>{V()},title:"Browse location","aria-label":"Browse location",children:[t.jsx(R,{name:"folder-open",className:"h-3.5 w-3.5"}),x?"Opening...":"Browse"]})]})}),se=C.some(H=>H.type==="parent"),Se=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(Te,{variant:"ghost",size:"xs",className:"h-6 shrink-0 gap-1 text-muted-foreground","aria-pressed":T,disabled:O||x,onClick:()=>P(H=>!H),children:[t.jsx(R,{name:"git-repository",className:"h-3.5 w-3.5"}),"Clone"]})]}),T?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(fn,{value:U,onChange:H=>ne(H.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(lu,{activeProfile:Ne,identities:G,onSelect:H=>W(H.id),isApplying:O,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",A==="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..."}):p&&p!=="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:p==="os-permission"?"PiChamber needs access to this folder.":"Could not load this folder."}),t.jsxs("div",{className:"flex items-center gap-2",children:[p==="os-permission"&&_?t.jsx(Te,{size:"xs",onClick:()=>{V()},disabled:x,children:"Grant access"}):null,t.jsx(Te,{variant:"outline",size:"xs",onClick:()=>g(H=>H+1),children:"Try again"})]})]}):C.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:C.map((H,me)=>{const Ue=me===m,L=H.type==="directory"&&se;return t.jsxs("button",{ref:X=>{X?u.current.set(H.value,X):u.current.delete(H.value)},type:"button","aria-label":H.type==="parent"?H.alreadyAdded?`Go back from ${H.name}, already added`:`Go back from ${H.name}`:H.alreadyAdded?`Open ${H.name}, already added`:`Open ${H.name}`,onMouseEnter:()=>w(me),onMouseDown:X=>X.preventDefault(),onClick:()=>K(H),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",L&&"pl-4"),children:[H.type==="parent"?t.jsx(R,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):t.jsx(R,{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:H.name})]}),H.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,H.type==="parent"?t.jsx(R,{name:"arrow-up-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"}):t.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80","aria-hidden":"true"})]},H.value)})})},j)]})}),ge=t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[Q,Se]}),we=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(R,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),t.jsx(R,{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(R,{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(R,{name:"corner-down-left",className:"h-3.5 w-3.5"}),"Add folder"]})]}),re=t.jsx(Te,{size:r?"xs":"default",onClick:()=>{q(y)},disabled:!ee,className:$(r&&"w-full flex-1"),children:Fe}),ae=()=>t.jsxs(t.Fragment,{children:[r?null:we,t.jsx("div",{className:$("flex w-full flex-row justify-end gap-2 sm:w-auto",r&&"justify-stretch"),children:re})]});return r?t.jsx(Si,{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:ae()}),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}),ge]})}):t.jsx(Yt,{open:e,onOpenChange:s,children:t.jsxs(qt,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[t.jsx(fs,{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(hs,{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:ge}),t.jsx(ks,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:ae()})]})})},An=e=>e?t.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:e}):void 0,og=()=>{const[e,s]=i.useState(!1),[n,r]=i.useState(null),[o,a]=i.useState(!1),l=De(N=>N.deleteSession),c=De(N=>N.deleteSessions),d=ce(N=>N.showDeletionDialog),u=ce(N=>N.setShowDeletionDialog),{isMobile:f,isTablet:h,hasTouchInput:b}=$s(),p=f||h||b;i.useEffect(()=>id(()=>{s(!1)}),[]);const g=i.useCallback(N=>{r({sessions:N.sessions,dateLabel:N.dateLabel})},[]),m=i.useCallback(()=>{r(null),a(!1)},[]),w=i.useCallback(async N=>{if(N.sessions.length===0)return;if(N.sessions.length===1){const D=N.sessions[0];await l(D.id)?oe.success("Session deleted"):oe.error("Failed to delete session");return}const C=N.sessions.map(D=>D.id),{deletedIds:y,failedIds:k}=await c(C);if(y.length>0){const D=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;oe.success(y.length===1?"Deleted {count} session":`Deleted ${y.length} sessions`,{description:An(D)})}k.length>0&&oe.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:An("Please try again in a moment.")})},[l,c]);i.useEffect(()=>Ss.onDeleteRequest(N=>{if(!d){w(N);return}g(N)}),[g,d,w]),i.useEffect(()=>Ss.onDirectoryRequest(()=>{s(!0)}),[]);const x=i.useCallback(async()=>{if(n){a(!0);try{if(n.sessions.length===1){const N=n.sessions[0];if(!await l(N.id)){oe.error("Failed to delete session"),a(!1);return}oe.success("Session deleted",{action:{label:"OK",onClick:()=>{}}})}else{const N=n.sessions.map(D=>D.id),C=await c(N),y=C.deletedIds,k=C.failedIds;if(y.length>0){const D=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;oe.success(y.length===1?"Deleted {count} session":`Deleted ${y.length} sessions`,{description:An(D),action:{label:"OK",onClick:()=>{}}})}if(k.length>0&&(oe.error(k.length===1?`Failed to delete ${k.length} session`:`Failed to delete ${k.length} sessions`,{description:An("Please try again in a moment.")}),y.length===0)){a(!1);return}}m()}finally{a(!1)}}},[n,l,c,m]),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.`:"",v=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(N=>t.jsx("li",{className:"typography-micro text-muted-foreground/80",children:t.jsx("span",{className:"truncate",children:ds(N)})},N.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,A=t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>u(!d),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":!d,children:[d?t.jsx(R,{name:"checkbox-blank",className:"size-4"}):t.jsx(R,{name:"checkbox",className:"size-4 text-primary"}),"Never ask"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Te,{variant:"ghost",onClick:m,disabled:o,children:"Cancel"}),t.jsx(Te,{variant:"destructive",onClick:x,disabled:o,children:o?"Deleting…":n?.sessions.length===1?"Delete session":"Delete sessions"})]})]}),j=n?.sessions.length===1?"Delete session":"Delete sessions";return t.jsxs(t.Fragment,{children:[p?t.jsx(Si,{open:!!n,onClose:()=>{o||m()},title:j,footer:t.jsx("div",{className:"flex justify-end gap-2",children:A}),children:t.jsxs("div",{className:"space-y-2 pb-2",children:[I&&t.jsx("p",{className:"typography-meta text-muted-foreground/80",children:I}),v]})}):t.jsx(Yt,{open:!!n,onOpenChange:N=>{if(!N){if(o)return;m()}},children:t.jsxs(qt,{className:"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2",children:[t.jsxs(fs,{children:[t.jsx(es,{children:j}),I&&t.jsx(hs,{children:I})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2",children:v}),t.jsx(ks,{className:"mt-2 gap-2 pt-1 pb-1",children:A})]})}),t.jsx(xu,{open:e,onOpenChange:s})]})},ig=()=>{const e=js(s=>s.entries);return i.useEffect(()=>{for(const s of e.values())!s.receipt||s.notificationSent||(js.getState().markNotificationSent(s.key),oe.success("Worktree ready",{id:`worktree-ready:${s.key}`,description:s.receipt.branch||s.receipt.path}))},[e]),null},yu=[{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"]}],vu={sessions:"sessions",skills:"skills.installed",providers:"providers","git-identities":"git",settings:"home"};function wu(e){const s=e.trim().toLowerCase();return yu.find(n=>n.slug===s)??null}function Su(e){const s=(e??"").trim().toLowerCase();if(!s)return"home";const n=vu[s];if(n)return n;const r=wu(s);return r?r.slug:"home"}function ag(e){switch(e){case"general":return"equalizer";case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"brush";case"chat":return"chat-1";case"dictation":return"voiceprint";case"snippets":return"sticky-note";case"prompt-templates":return"terminal-box";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"history";case"providers":return"cloud";case"behavior":return"brain";case"skills.installed":return"puzzle";case"git":return"git-repository";case"tunnel":return"global";case"about":return"pichamber";case"home":return null;default:return"robot-2"}}function lg(){const e=i.useRef(!1),s=i.useRef(!1),n=De(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=De.getState().currentSessionId,b=Ms().getState().selectedSessionId;if(f.sessionId!==h||f.sessionId!==b){const p=De.getState().getDirectoryForSession(f.sessionId);n(f.sessionId,p)}}if(f.settingsPath){a(Su(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]),d=i.useCallback(()=>{const f=De.getState(),h=Ms().getState(),b=ce.getState();return{sessionId:lr({currentSessionId:f.currentSessionId,piSelectedSessionId:h.selectedSessionId,draft:f.newSessionDraft}),tab:b.activeMainTab,isSettingsOpen:b.isSettingsDialogOpen,settingsPath:b.settingsPage,diffFile:b.pendingDiffFile}},[]),u=i.useCallback((f={})=>{if(s.current)return;const h=d();_r(h,f)},[d]);i.useEffect(()=>{if(e.current||(e.current=!0,!Do()))return;const f=Eo();(async()=>(await c(f),_r({...d(),sessionId:f.sessionId??lr({currentSessionId:De.getState().currentSessionId,piSelectedSessionId:Ms().getState().selectedSessionId,draft:De.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,d]),i.useEffect(()=>{const f=()=>{const w=De.getState(),x=Ms().getState();return lr({currentSessionId:w.currentSessionId,piSelectedSessionId:x.selectedSessionId,draft:w.newSessionDraft})};let h=f(),b=De.getState().newSessionDraft?.open===!0;const p=()=>{const w=De.getState(),x=f(),I=w.newSessionDraft?.open===!0;x===h&&I===b||s.current||(h=x,b=I,u({replace:!0}))},g=De.subscribe(()=>{p()}),m=Ms().subscribe(()=>{p()});return()=>{g(),m()}},[u]),i.useEffect(()=>{let f=ce.getState().activeMainTab,h=ce.getState().isSettingsDialogOpen,b=ce.getState().settingsPage,p=ce.getState().pendingDiffFile;return ce.subscribe(m=>{if(s.current)return;const w=m.activeMainTab!==f,x=m.isSettingsDialogOpen!==h,I=m.settingsPage!==b,v=m.pendingDiffFile!==p&&m.activeMainTab==="diff";f=m.activeMainTab,h=m.isSettingsDialogOpen,b=m.settingsPage,p=m.pendingDiffFile,(w||x||I||v)&&u()})},[u]),i.useEffect(()=>{if(typeof window>"u")return;const f=()=>{const h=Eo();if(Do())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 ju(e=!0){const s=Mn(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,d=null;const u=h=>{const b=Math.round(h*1e3);return Math.max(a,Math.min(l,b))},f=h=>{c||(d=window.setTimeout(async()=>{const b=await n.current(),p=typeof b=="number"&&Number.isFinite(b)?u(b):o;f(p)},h))};return f(r),()=>{c=!0,d!==null&&window.clearTimeout(d)}},[e])}function cg(){const e=on(s=>s.connection==="ready",void 0,"chrome");return ju(e),null}const Ko=12,Cu=[{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"}],ku=({isActive:e,burstKey:s=0,className:n,durationMs:r=900,bursts:o=Cu,onComplete:a})=>{const l=Ae.useRef(!1);Ae.useEffect(()=>{!e&&l.current&&a?.(),e&&(l.current=!0)},[e,a]);const c=Ae.useMemo(()=>Array.from({length:Ko},(d,u)=>{const f=Math.PI*2*u/Ko;return{x:Math.cos(f),y:Math.sin(f),delay:u*18}}),[]);return e?t.jsx("div",{className:$("fireworks-overlay pointer-events-none",n),"aria-hidden":"true","data-burst-key":s,children:o.map(d=>{const u={"--burst-delay":`${d.delay}ms`,"--burst-x":`${d.x}%`,"--burst-y":`${d.y}%`,"--firework-color":`var(${d.colorVar})`,"--firework-duration":`${r}ms`};return t.jsx("div",{className:"firework-burst",style:u,children:c.map((f,h)=>{const b=f.x*d.radius,p=f.y*d.radius,g={"--translate-x":`${b}px`,"--translate-y":`${p}px`,"--particle-delay":`${f.delay}ms`,color:`var(${d.colorVar})`};return t.jsx("span",{className:"firework-particle",style:g},`${d.id}-${h}-${s}`)})},`${d.id}-${s}`)})}):null},Au=({durationMs:e=3400}={})=>{const[s,n]=Ae.useState({isActive:!1,cycle:0}),r=Ae.useRef(null),o=Ae.useCallback(()=>{r.current&&(window.clearTimeout(r.current),r.current=null)},[]),a=Ae.useCallback(()=>{o(),n(c=>c.isActive?{...c,isActive:!1}:c)},[o]),l=Ae.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 Ae.useEffect(()=>()=>o(),[o]),{isActive:s.isActive,burstKey:s.cycle,triggerFireworks:l,dismissFireworks:a}},ua=i.createContext(void 0),dg=({children:e})=>{const{isActive:s,burstKey:n,triggerFireworks:r,dismissFireworks:o}=Au(),a=i.useMemo(()=>({triggerFireworks:r,dismissFireworks:o}),[r,o]);return t.jsxs(ua.Provider,{value:a,children:[e,t.jsx(ku,{isActive:s,burstKey:n})]})},Nu={triggerFireworks:()=>{},dismissFireworks:()=>{}},ug=()=>i.useContext(ua)??Nu,Gn=2e3,fa=600*1e3;async function Iu(){try{const e=await Ct("/api/pi/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});if(!e.ok){const n=await e.json().catch(()=>({}));return{success:!1,error:n.error||`Server error: ${e.status}`,commands:Array.isArray(n.commands)?n.commands.filter(r=>typeof r=="string"):void 0}}const s=await e.json().catch(()=>({}));return{success:!0,autoRestart:s.autoRestart!==!1,jobId:typeof s.jobId=="string"?s.jobId:void 0,channel:s.channel==="rc"?"rc":s.channel==="stable"?"stable":void 0,targetVersion:typeof s.targetVersion=="string"?s.targetVersion:void 0}}catch(e){return{success:!1,error:e instanceof Error?e.message:void 0}}}async function Ru(e,s=Math.ceil(fa/Gn),n=Gn,r=qe()){for(let o=0;o<s;o++){if(qe()!==r)return{applied:!1,stale:!0};try{const a=await Ct("/api/pi/update-check",{method:"GET",headers:{Accept:"application/json"}});if(qe()!==r)return{applied:!1,stale:!0};if(a.ok){const l=await a.json().catch(()=>null);if(qe()!==r)return{applied:!1,stale:!0};if(typeof l?.error=="string"&&l.error.length>0)return{applied:!1,error:l.error};if(l&&l.available===!1)return{applied:!0};if(l&&typeof l.currentVersion=="string"&&typeof e=="string"&&l.currentVersion!==e)return{applied:!0}}else if(a.status===401||a.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."}}catch{if(qe()!==r)return{applied:!1,stale:!0}}await new Promise(a=>setTimeout(a,n))}return{applied:!1}}async function Du(e,s,n=Math.ceil(fa/Gn),r=Gn,o=qe()){for(let a=0;a<n;a++){if(qe()!==o)return{applied:!1,stale:!0};try{const l=await Ct(`/api/pi/update-install/${encodeURIComponent(e)}`,{method:"GET",headers:{Accept:"application/json"}});if(qe()!==o)return{applied:!1,stale:!0};if(l.ok){const c=await l.json().catch(()=>null);if(qe()!==o)return{applied:!1,stale:!0};if(c?.state==="complete")return{applied:!0};if(c?.state==="failed")return{applied:!1,error:c.error||"Update failed"};c?.state==="restarting"?s("restarting"):(c?.state==="queued"||c?.state==="installing"||c?.state==="verifying")&&s("updating")}else{if(l.status===401||l.status===403)return{applied:!1,error:"Authentication was lost while following the update. Reauthenticate to check its status."};if(l.status===404)return{applied:!1,error:"The server lost the update status. Check the installed version or run: pichamber update"};if(l.status===503){const c=await l.json().catch(()=>null);if(qe()!==o)return{applied:!1,stale:!0};if(c?.error==="Update status is unavailable")return{applied:!1,error:c.error};s("reconnecting")}else s("reconnecting")}}catch{if(qe()!==o)return{applied:!1,stale:!0};s("reconnecting")}await new Promise(l=>setTimeout(l,r))}return{applied:!1}}const Wo="https://github.com/RyderAsKing/PiChamber/releases";function Eu(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 Pu(e){return e.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Ho(e){return e.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function Mu(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 Tu(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 ha=({open:e,onOpenChange:s,info:n,downloading:r,downloaded:o,progress:a,error:l,onDownload:c,onRestart:d,runtimeType:u="desktop"})=>{const[f,h]=Ae.useState(null),[b,p]=Ae.useState("idle"),[g,m]=Ae.useState(null),[w,x]=Ae.useState(null),[I,v]=Ae.useState({}),A=n?.version?n.releaseUrl||`${Wo}/tag/v${n.version}`:Wo,j=n?.downloadUrl||A,N=a?.total?Math.round(a.downloaded/a.total*100):0,C=u==="web",y=u==="mobile",k=n?.updateCommand||"pichamber update",D=I.version||n?.version,M=I.channel||n?.channel;Ae.useEffect(()=>{e||(p("idle"),m(null),x(null),v({}))},[e]);const B=async(P=k)=>{(await us(P)).ok&&(h(P),setTimeout(()=>h(null),2e3))},_=Ae.useCallback(async P=>{await ji(P)},[]),K=Ae.useCallback(async()=>{const P=qe();p("updating"),m(null),x(null),v({});const U=await Iu();if(qe()!==P)return;if(!U.success){p("error"),m(U.error||"Update failed"),x(U.commands??null);return}if(v({version:U.targetVersion,channel:U.channel}),U.jobId){const W=await Du(U.jobId,G=>{qe()===P&&p(G)},void 0,void 0,P);if(W.stale||qe()!==P)return;if(W.applied){window.location.reload();return}p("error"),m(W.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update");return}p(U.autoRestart?"restarting":"reconnecting");const ne=await Ru(n?.currentVersion,void 0,void 0,P);if(!(ne.stale||qe()!==P)){if(ne.applied){window.location.reload();return}p("error"),m(ne.error||"Update is taking longer than expected. Wait a bit and refresh, or run: pichamber update")}},[n?.currentVersion]),V=Ae.useCallback(()=>{_(j)},[_,j]),O=b!=="idle"&&b!=="error",T=Ae.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const U=Tu(P);return U.length===0?{kind:"raw",title:"What's new",content:Ho(P)}:{kind:"sections",title:"What's new",sections:[...U].sort((W,G)=>Mu(W.version,G.version)).map(W=>({version:W.version,dateLabel:Eu(W.date),content:Ho(Pu(W.raw)||P)}))}},[n?.body]);return t.jsx(Yt,{open:e,onOpenChange:O?void 0:s,children:t.jsxs(qt,{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(R,{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||D)&&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&&D&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),D&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:D})]}),C&&M&&t.jsx("span",{className:"ml-3 typography-meta text-muted-foreground",children:M==="rc"?"RC subscription":"Stable subscription"})]}),t.jsxs("div",{className:"space-y-2",children:[C&&O&&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(R,{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."})]}),T&&!O&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(xs,{className:"max-h-[400px] p-0",fillContainer:!1,children:T.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:P=>{const ne=P.target.closest("a");ne&&ne.href&&(P.preventDefault(),P.stopPropagation(),_(ne.href))},children:t.jsx(Po,{content:T.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:T.sections.map(P=>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",P.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.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:U=>{const W=U.target.closest("a");W&&W.href&&(U.preventDefault(),U.stopPropagation(),_(W.href))},children:t.jsx(Po,{content:P.content,disableLinkSafety:!0,enableFileReferences:!1})})]},P.version))})})}),(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})}),C&&b==="error"&&(w??[k]).length>0&&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(R,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:w?"Run these commands:":"Or update via terminal:"})]}),(w??[k]).map(P=>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:P}),t.jsx(Te,{variant:"ghost",size:"icon",onClick:()=>{B(P)},className:f===P?"text-[var(--status-success)]":void 0,title:f===P?"Copied!":"Copy command","aria-label":f===P?"Copied!":"Copy command",children:f===P?t.jsx(R,{name:"check",className:"h-4 w-4"}):t.jsx(R,{name:"clipboard",className:"h-4 w-4"})})]},P))]}),!C&&!y&&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:[N,"%"]})]}),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:`${N}%`}})})]})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:A,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(R,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!C&&!y&&!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(R,{name:"download",className:"h-4 w-4"}),"Download Update"]}),!C&&!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(R,{name:"loader",className:"h-4 w-4 animate-spin"}),"Downloading..."]}),!C&&!y&&o&&t.jsxs("button",{onClick:d,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(R,{name:"restart",className:"h-4 w-4"}),"Restart to Update"]}),y&&t.jsxs(Te,{onClick:V,size:"default",children:[t.jsx(R,{name:"external-link",className:"h-4 w-4"}),"Open update"]}),C&&!O&&t.jsxs("button",{onClick:K,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(R,{name:"download",className:"h-4 w-4"}),"Update Now"]}),C&&O&&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(R,{name:"loader",className:"h-4 w-4 animate-spin"}),"Updating..."]})]})]})]})})},Fu=i.memo(function({checked:s,onChange:n,disabled:r=!1,ariaLabel:o,className:a,iconClassName:l}){const c=i.useCallback(u=>{u.preventDefault(),u.stopPropagation(),!r&&!s&&n()},[s,r,n]),d=i.useCallback(u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),!r&&!s&&n())},[s,r,n]);return t.jsx("button",{type:"button",role:"radio",onClick:c,onKeyDown:d,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)})})}),gn=({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 d=a.current;d&&c.target instanceof Node&&d.contains(c.target)||o(!1)};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[r]),t.jsxs($e,{open:r,onOpenChange:o,children:[t.jsx(Ge,{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(R,{name:"information",className:"h-3.5 w-3.5"})})}),t.jsx(Ke,{sideOffset:8,className:$("max-w-sm",n),children:e})]})},fg="w-full min-w-40 max-w-48",hg="settings",Ou="w-full min-w-40 max-w-48",pg="h-8 w-8 px-0 text-muted-foreground hover:text-foreground",Lu="w-full max-w-[24rem]",mg="min-w-0 flex-1",gg="flex w-full min-w-0 items-center gap-2",bg="typography-meta shrink-0 text-muted-foreground tabular-nums",pa="space-y-3.5",Bu="space-y-1.5",xg="typography-settings-page-title text-muted-foreground",_u="typography-settings-section-title text-foreground",ma="typography-settings-group-title text-foreground",ro="typography-settings-field-label text-foreground",Uu="typography-settings-description text-muted-foreground",bn="typography-meta text-muted-foreground",yg="typography-meta font-medium text-foreground",vg="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:d,settingsItem:u})=>{const f=e!=null||s!=null||o!=null||r!=null;return t.jsxs("section",{"data-settings-item":u,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:_u,children:e}):e,n,r!=null?t.jsx(gn,{children:r}):null]}):null,s!=null?t.jsx("div",{className:Uu,children:s}):null]}),o?t.jsx("div",{className:"shrink-0",children:o}):null]}):null,t.jsx("div",{className:$(d),children:a})]})},wg=({children:e,className:s})=>t.jsx("div",{className:$("grid grid-cols-1 gap-6 @3xl:grid-cols-2 @3xl:gap-10",s),children:e}),$u=({children:e,className:s,as:n="h3"})=>t.jsx(n,{className:$(ma,s),children:e}),Sg=({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($u,{children:e}),n!=null?t.jsx(gn,{children:n}):null]}):null,s!=null?t.jsx("p",{className:bn,children:s}):null]}):null,t.jsx("div",{className:$(a),children:r})]}),cn=({label:e,description:s,info:n,descriptionPlacement:r="before",children:o,settingsItem:a,className:l,controlClassName:c})=>{const d=s!=null?t.jsx("p",{className:bn,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:ro,children:e}),n!=null?t.jsx(gn,{children:n}):null]}),r==="before"?d:null]}),t.jsx("div",{className:$("flex min-w-0 max-w-[24rem] items-center gap-2",c),children:o}),r==="after"?d:null]})},jg=({label:e,description:s,info:n,children:r,settingsItem:o,className:a,labelClassName:l,controlClassName:c,alignEnd:d=!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",l),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:ro,children:e}),n!=null?t.jsx(gn,{children:n}):null]}),s!=null?t.jsx("p",{className:$(bn,"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",d&&"@xl:justify-end",c),children:r})]}),Cg=({children:e,className:s,settingsItem:n})=>t.jsx("div",{"data-settings-item":n,className:$("pt-4",s),children:e}),Gu=({checked:e,onChange:s,label:n,description:r,disabled:o=!1,ariaLabel:a,settingsItem:l,className:c,labelAccessory:d,info:u})=>{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(Nr,{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:ro,children:n}),d,u!=null?t.jsx(gn,{children:u}):null]}),h?t.jsx("span",{className:bn,children:r}):null]})]})},kg=({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(Fu,{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:bn,children:r}):null]})]}),Ag=({"aria-label":e,children:s,className:n})=>t.jsx("div",{role:"radiogroup","aria-label":e,className:$(Bu,n),children:s});function Ng({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(Te,{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))})}const Gr="pichamber:server-update-channel-changed",Ig=()=>{typeof window<"u"&&window.dispatchEvent(new Event(Gr))},Ku=e=>typeof window>"u"?()=>{}:(window.addEventListener(Gr,e),()=>window.removeEventListener(Gr,e));class Wu 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(nc,{className:"w-full max-w-md",children:[t.jsx(rc,{className:"text-center",children:t.jsxs(oc,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(R,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(ic,{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(Te,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(R,{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 Hu(e){return t.jsx(Wu,{...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 Rg=({active:e=!0})=>{const s=De(n=>n.currentSessionId);return t.jsx(Hu,{sessionId:s||void 0,children:t.jsx(ac,{active:e},s??"no-session")})};function Yu({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 ga=Ae.forwardRef(({className:e,outerClassName:s,scrollbarClassName:n,fillContainer:r=!1,useScrollShadow:o=!1,scrollShadowSize:a,hasError:l,resizedHeight:c,onResizeHeightChange:d,disabled:u,simple:f,endSlot:h,...b},p)=>{const g=Ae.useRef(null),m=Ae.useRef(null),[w,x]=Ae.useState(null),I=c??w,v=Ae.useCallback(j=>{const N=g.current;if(!N)return;m.current={startY:j.clientY,startHeight:N.getBoundingClientRect().height};const C=j.currentTarget;C.setPointerCapture(j.pointerId);const y=D=>{const M=m.current;if(!M)return;const B=M.startHeight+(D.clientY-M.startY),_=Math.max(82,B);d?d(_):x(_)},k=()=>{m.current=null,C.removeEventListener("pointermove",y),C.removeEventListener("pointerup",k),C.removeEventListener("pointercancel",k)};C.addEventListener("pointermove",y),C.addEventListener("pointerup",k),C.addEventListener("pointercancel",k),j.preventDefault()},[d]),A=Ae.useCallback(j=>{if(j.target.closest('textarea, button, [role="separator"]'))return;const C=g.current?.querySelector("textarea");C&&document.activeElement!==C&&(j.preventDefault(),C.focus())},[]);return f?t.jsx(xs,{as:"textarea",ref:p,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:u,...b}):t.jsx("div",{ref:g,onPointerDown:A,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:p,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",!u&&["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"],u&&"text-muted-foreground/60 placeholder:text-muted-foreground/60",e),spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",disabled:u,...b}),t.jsxs("div",{className:"flex items-center justify-end gap-1.5 pl-3 pr-2.5",children:[h,t.jsx(Yu,{onResizeStart:v,ariaLabel:"Resize textarea"})]})]})})});ga.displayName="Textarea";const ba=[{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"}],dn=Object.fromEntries(ba.map(e=>[e.key,e.Icon])),Kr="pichamber:project-actions-updated",xa=e=>{const s=(e||"").trim().replace(/\\/g,"/");return s?s==="/"?"/":s.length>1?s.replace(/\/+$/,""):s:""},Xt=(e,s)=>`${xa(e)}::${s}`,ya=({title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,children:l,className:c,contentClassName:d,divider:u=!0})=>t.jsx(zu,{title:e,description:s,info:n,settingsItem:r,titleAccessory:o,headerAction:a,divider:u,className:c,contentClassName:d,children:l}),Wr=e=>e.name.trim().length>0&&e.command.trim().length>0,qu=e=>e.name.trim().length===0&&e.command.trim().length===0,Qu=e=>!Wr(e)&&!qu(e),Vu=(e,s)=>e.some(r=>s.has(r.id)&&!Wr(r))?{canPersist:!1,actions:e}:{canPersist:!0,actions:e.filter(Wr)},Ju=450,Xu=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,Zu=()=>({id:Xu(),name:"",command:"",icon:"play"}),ef=({projectRef:e})=>{const[s,n]=i.useState([]),[r,o]=i.useState(!1),[a,l]=i.useState(null),[c,d]=i.useState(new Set),u=i.useRef(!1);i.useEffect(()=>{let x=!1;return o(!0),(async()=>{try{const I=await Ir(e);if(x)return;n(I.actions),l(JSON.stringify({actions:I.actions})),d(new Set(I.actions.map(v=>v.id)))}catch{if(x)return;n([]),l(JSON.stringify({actions:[]})),d(new Set)}finally{x||o(!1)}})(),()=>{x=!0}},[e]);const f=i.useMemo(()=>Vu(s,c),[s,c]),h=i.useMemo(()=>JSON.stringify({actions:f.actions}),[f.actions]),b=a!==null&&f.canPersist&&h!==a,p=i.useCallback(async x=>await lc(e,{actions:x,primaryActionId:null})?(l(JSON.stringify({actions:x})),d(new Set(x.map(v=>v.id))),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Kr,{detail:{projectId:e.id}})),!0):(oe.error("Failed to save actions"),!1),[e]);i.useEffect(()=>{if(!b||r||u.current)return;const x=window.setTimeout(()=>{u.current||(u.current=!0,(async()=>{try{await p(f.actions)}finally{u.current=!1}})())},Ju);return()=>{window.clearTimeout(x)}},[b,r,p,f.actions]);const g=i.useCallback(()=>{const x=Zu();n(I=>[...I,x])},[]),m=i.useCallback(x=>{n(I=>I.filter(v=>v.id!==x))},[]),w=i.useCallback((x,I)=>{n(v=>v.map(A=>A.id===x?I(A):A))},[]);return t.jsx(ya,{title:"Actions",info:"Per-project commands shown in the header next to the project name.",settingsItem:"projects.actions",headerAction:t.jsxs(Te,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:[t.jsx(R,{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",Lu),children:s.map((x,I)=>{const v=x.icon||"play",A=dn[v]||"play",j=x.name.trim()||`Action ${I+1}`,N=Qu(x);return t.jsxs("div",{className:pa,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:ma,children:j}),t.jsx(Te,{type:"button",variant:"ghost",size:"xs",className:"h-8 w-8 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>m(x.id),"aria-label":`Delete ${j}`,children:t.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),t.jsxs(cn,{label:"Name",controlClassName:"w-full max-w-none",children:[t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:A,className:"h-4 w-4"})})}),t.jsx(Dt,{align:"start",className:"w-56 p-2",children:t.jsx("div",{className:"grid grid-cols-6 gap-1",children:ba.map(C=>{const y=C.Icon,k=(x.icon||"play")===C.key;return t.jsx("button",{type:"button",onClick:()=>w(x.id,D=>({...D,icon:C.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 ${C.label}`,children:t.jsx(R,{name:y,className:"h-4 w-4"})},C.key)})})})]}),t.jsx(fn,{value:x.name,onChange:C=>w(x.id,y=>({...y,name:C.target.value})),placeholder:"Action name",className:"h-8 min-w-0 flex-1 rounded-md px-3"})]}),t.jsx(cn,{label:"Command",controlClassName:"w-full max-w-none",children:t.jsx(ga,{value:x.command,onChange:C=>w(x.id,y=>({...y,command:C.target.value})),placeholder:"e.g. bun run lint",className:"min-h-[88px] w-full font-mono text-xs"})}),N?t.jsx("p",{className:"typography-meta text-muted-foreground",children:"Enter a name and command to save this action."}):null,t.jsx(Gu,{checked:x.autoOpenUrl===!0,onChange:C=>w(x.id,y=>({...y,...C?{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 ${j}`}),x.autoOpenUrl===!0?t.jsx(t.Fragment,{children:t.jsx(cn,{label:"Custom URL",info:"Leave empty to use the best URL from command output.",controlClassName:"w-full max-w-none",children:t.jsx(fn,{value:x.openUrl||"",onChange:C=>w(x.id,y=>({...y,openUrl:C.target.value})),placeholder:"https://localhost:3000",className:"h-8 w-full rounded-md px-3"})})}):null]},x.id)})})})},tf={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)"},sf=({value:e,noneLabel:s,ariaLabel:n,disabled:r=!1,className:o,isModelAllowed:a,onChange:l})=>{const c=Wt(y=>y.providers),d=Wt(y=>y.modelsMetadata),u=ce(y=>y.hiddenModels),f=ce(y=>y.isFavoriteModel),h=ce(y=>y.toggleFavoriteModel),b=ce(y=>y.reorderFavoriteModel),{favoriteModelsList:p,recentModelsList:g}=cc(),[m,w]=i.useState(!1),[x,I]=i.useState("");i.useEffect(()=>{m||I("")},[m]);const v=e?c.find(y=>y.id===e.providerId):void 0,A=e&&v?(Array.isArray(v.models)?v.models:[]).find(y=>y.id===e.modelId):void 0,j=e?dc(A,e.modelId):s,N=i.useMemo(()=>e?u.filter(y=>!(y.providerID===e.providerId&&y.modelID===e.modelId)):u,[u,e]),C=i.useCallback(y=>{l({providerId:y.providerID,modelId:y.modelID}),w(!1)},[l]);return t.jsxs(It,{modal:!1,open:m,onOpenChange:y=>{r||w(y)},children:[t.jsx(Rt,{asChild:!0,disabled:r,children:t.jsxs("button",{type:"button","aria-label":n,disabled:r,className:$(Ci({size:"default"}),Ou,"min-w-0",o),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e?.providerId?t.jsx(uc,{providerId:e.providerId,className:"size-4 shrink-0"}):null,t.jsx("span",{className:$("truncate",e?"text-foreground":"text-muted-foreground"),children:j})]}),t.jsx(R,{name:"arrow-down-s",className:"size-4 shrink-0"})]})}),t.jsx(Dt,{align:"start",portalToBody:!0,positionerClassName:"z-[80]",className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",children:t.jsx(fc,{providers:c,favoriteModels:p,recentModels:g,modelsMetadata:d,searchQuery:x,onSearchQueryChange:I,onSelect:C,labels:{...tf,notSelected:s},selectedModel:e?{providerID:e.providerId,modelID:e.modelId}:null,hiddenModels:N,isModelAllowed:a,includeNotSelected:!0,onSelectNone:()=>{l(null),w(!1)},disabled:r,autoFocus:!0,onEscape:()=>w(!1),isFavorite:y=>f(y.providerID,y.modelID),onToggleFavorite:y=>h(y.providerID,y.modelID),onReorderFavorite:(y,k)=>b(y.providerID,y.modelID,k.providerID,k.modelID),reorderFavoriteAriaLabel:"Reorder favorite",reorderFavoriteTitle:"Drag to reorder favorite"})})]})},dr="w-full max-w-none",nf=({form:e})=>{const{name:s,setName:n,parsedDefaultModel:r,handleDefaultModelChange:o,project:a}=e,l=Wt(c=>c.loadProviders);return i.useEffect(()=>{l({source:"projectSettings"})},[l]),a?t.jsx(ya,{title:"Project",divider:!1,children:t.jsxs("div",{className:pa,children:[t.jsx(cn,{label:"Name",settingsItem:"projects.name",controlClassName:dr,children:t.jsx(fn,{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(cn,{label:"Default model",info:"Used when starting a new chat in this project. Unset keeps the global session default.",settingsItem:"projects.default-model",controlClassName:dr,children:t.jsx(sf,{value:r,noneLabel:"Use global default",ariaLabel:"Default model for new chats",className:dr,onChange:c=>{if(!c){o("","");return}o(c.providerId,c.modelId)}})})]})}):null},rf=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(()=>hc(r),[r]),l=!!e&&(s.trim()!==(e?.label??"").trim()||(r??void 0)!==(e?.defaultModel??void 0)),c=i.useCallback((u,f)=>{o(u&&f?`${u}/${f}`:void 0)},[]),d=i.useCallback(async()=>{if(!e)return null;const u=s.trim();return u?{label:u,defaultModel:r??null}:null},[r,s,e]);return{name:s,setName:n,defaultModel:r,parsedDefaultModel:a,handleDefaultModelChange:c,hasChanges:l,prepareSaveData:d,project:e}},of=450,af=(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 d=await a();if(d)try{await s(d)}catch{oe.error("Failed to save project settings")}}finally{l.current=!1}})())},of);return()=>{window.clearTimeout(c)}},[o,n,r,s,a])},lf=({project:e,onIdentitySave:s})=>{const n=rf(e),r=i.useMemo(()=>e?{id:e.id,path:e.path}:null,[e]),o=i.useCallback(async a=>{await s(a)},[s]);return af(n,o),!e||!r?null:t.jsxs("div",{className:"space-y-0",children:[t.jsx(nf,{form:n}),t.jsx(ef,{projectRef:r})]})};function oo({...e}){return t.jsx(Hi,{...e})}function io({...e}){return t.jsx(Yi,{...e})}function ao({className:e,positionerClassName:s,children:n,style:r,...o}){return t.jsx(qi,{children:t.jsx(Qi,{className:$("app-region-no-drag z-50",s),children:t.jsx(Vi,{"data-slot":"dropdown-menu-content",style:{color:"var(--surface-elevated-foreground)",...r},className:$(ki,e),...o,children:n})})})}function Os({className:e,...s}){return t.jsx(Ji,{className:$(Ai,e),...s})}function va({className:e,...s}){return t.jsx(Xi,{className:$(Ni,e),...s})}const Nn=100;function Dg(){const e=ce(y=>y.isArchivePageOpen),s=ce(y=>y.setArchivePageOpen),n=ce(y=>y.setActiveMainTab),r=De(y=>y.setCurrentSession),o=De(y=>y.unarchiveSession),a=Bs(y=>y.homeDirectory),l=Rr({archived:!0}),[c,d]=i.useState(""),[u,f]=i.useState(null),[h,b]=i.useState(Nn),p=c.trim().toLowerCase(),g=i.useMemo(()=>e?[...l].sort((y,k)=>(k.time?.archived??0)-(y.time?.archived??0)):[],[l,e]),m=i.useMemo(()=>{const y=new Map;for(const k of g){const D=ke(an(k))??"",M=y.get(D);if(M){M.sessions.push(k);continue}y.set(D,{directory:D,label:D?_s(D,a)||D:"other projects",sessions:[k]})}return[...y.values()].sort((k,D)=>D.sessions.length-k.sessions.length)},[a,g]),w=i.useMemo(()=>p?g.filter(y=>(y.title??"").toLowerCase().includes(p)):u===null?g:m.find(y=>y.directory===u)?.sessions??[],[m,p,u,g]),x=w.slice(0,h),I=w.length-x.length,v=l.length,A=i.useCallback(y=>{f(y),b(Nn)},[]),j=i.useCallback(y=>{const k=ke(an(y));r(y.id,k??void 0),n("chat"),s(!1)},[n,r,s]),N=i.useCallback(y=>{o(y.id).then(k=>{k?oe.success("Session restored"):oe.error("Failed to restore session")})},[o]);if(!e)return null;const C=(y,k,D,M,B,_,K)=>t.jsxs("div",{className:"group/dir relative",children:[t.jsxs("button",{type:"button",onClick:B,title:_,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",K?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",M?"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:D})]}),K?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>Ss.requestDelete({sessions:K,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(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),t.jsx(Ke,{side:"bottom",sideOffset:4,children:"Delete all archived sessions in this project"})]}):null]},y);return t.jsx(Td,{open:e,onOpenChange:s,children:t.jsxs(Fd,{children:[t.jsx(Od,{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(Ld,{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(Bd,{className:"sr-only",children:"Archived sessions"}),t.jsx(_d,{className:"sr-only",children:"Browse and restore archived sessions."}),t.jsx(Ud,{"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(R,{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:[C("__all__","All directories",v,u===null,()=>A(null)),m.map(y=>C(y.directory||"__none__",y.label,y.sessions.length,u===y.directory,()=>A(y.directory),y.directory||void 0,y.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(R,{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:y=>{d(y.target.value),b(Nn)},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:w.length===1?`${w.length} archived session`:`${w.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:p?"No matching archived sessions":"No archived sessions"})}):x.map(y=>{const k=ke(an(y))??"",D=k?_s(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:()=>j(y),role:"button",tabIndex:0,onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),j(y))},children:[t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ds(y)}),p&&D?t.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:k,children:D}):null,t.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Cd(y.time?.archived??y.time?.updated??y.time?.created??Date.now())}),t.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),N(y)},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 ${ds(y)}`,children:t.jsx(R,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),Ss.requestDelete({sessions:[y],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 ${ds(y)}`,children:t.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},y.id)}),I>0?t.jsx("button",{type:"button",onClick:()=>b(y=>y+Nn),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 cf=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}},df=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},Ht=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:0,uf=e=>{if(!e||typeof e!="object")return null;const s=Ht(e.input),n=Ht(e.output),r=Ht(e.cacheRead),o=Ht(e.cacheWrite);return{input:s,output:n,reasoning:null,cacheRead:r,cacheWrite:o,total:s+n+r+o}},Yo=e=>{const s=uf(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:Ht(r)};if(!r||typeof r!="object")return{input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0};const o=r,a=Ht(o.input),l=Ht(o.output),c=Ht(o.reasoning),d=Ht(o.cache?.read),u=Ht(o.cache?.write);return{input:a,output:l,reasoning:c,cacheRead:d,cacheWrite:u,total:a+l+c+d+u}},wa=380,ur=8,ff=140;function hf({open:e,onClose:s,anchorRef:n,closeOnWheel:r=!1}){const o=i.useRef(null),a=i.useRef(null),[l,c]=i.useState(e),[d,u]=i.useState(!1),[f,h]=i.useState(null),{enabled:b}=Jr();return i.useLayoutEffect(()=>{if(!e||!b||!l)return;const p=()=>{const w=n.current?.getBoundingClientRect(),x=a.current?.getBoundingClientRect();if(!w||!x){h(null);return}const I=w.left-x.left;h(Math.min(Math.max(I,ur),Math.max(ur,x.width-wa-ur)))};p();const g=a.current;if(typeof ResizeObserver>"u"||!g)return;const m=new ResizeObserver(p);return m.observe(g),()=>m.disconnect()},[n,b,e,l]),i.useEffect(()=>{if(e){c(!0),u(!1);return}if(!l)return;u(!0);const p=window.setTimeout(()=>{c(!1),u(!1)},ff);return()=>window.clearTimeout(p)},[e,l]),i.useEffect(()=>{if(!e)return;const p=g=>{g.key==="Escape"&&s()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s,e]),i.useEffect(()=>{if(!e)return;const p=g=>{const m=g.target;if(!(m instanceof Node)){s();return}o.current?.contains(m)||n.current?.contains(m)||s()};return document.addEventListener("pointerdown",p,!0),r&&document.addEventListener("wheel",p,!0),()=>{document.removeEventListener("pointerdown",p,!0),r&&document.removeEventListener("wheel",p,!0)}},[n,r,s,e]),{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:d,anchorLeft:f,isPopover:b&&f!==null}}const qo=(e,s)=>{if(!e||typeof e!="object")return;const n=e[s];return typeof n=="number"&&Number.isFinite(n)?n:void 0},Kn=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),In=({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(R,{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})]}),pf=({open:e,onClose:s,anchorRef:n,contextDisplay:r})=>{const{panelRef:o,wrapperRef:a,shouldRender:l,isExiting:c,anchorLeft:d,isPopover:u}=hf({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",u?"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))",...u?{top:8,left:d??8,width:`min(${wa}px, calc(100% - 16px))`}:null},children:t.jsx("div",{className:"space-y-1",children:r?t.jsxs(t.Fragment,{children:[t.jsx(In,{iconNode:t.jsx(Ii,{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(In,{icon:"stack",label:"Cache read",children:t.jsx("span",{className:"tabular-nums",children:Kn(r.cacheRead)})}),t.jsx(In,{icon:"edit",label:"Cache write",children:t.jsx("span",{className:"tabular-nums",children:Kn(r.cacheWrite)})})]}):null,r.cacheHitPercent!==null?t.jsx(In,{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 Ta(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 d=Jp(c);if(!d||this.pendingUrls.has(d))return;const u=this.probeGeneration;this.pendingUrls.add(d),Xp(d).then(f=>{if(this.pendingUrls.delete(d),!f||this.probeGeneration!==u)return;const h=he.getState().getDirectoryState(s)?.tabs.find(b=>b.id===n);!h||h.previewUrlLocked||h.previewUrl===d||o(s,n,d,{locked:!1,autoOpened:!1})})}}const nm=(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"?za(o):null};function rm({terminal:e,effectiveDirectory:s,activeTabId:n,terminalSessionId:r,terminalLifecycle:o,hasOpenedTerminalViewport:a,terminalHydrated:l,terminalShell:c,terminalLoginShell:d,terminalAppearanceRef:u,enableTabs:f,hasActiveContext:h,focusTerminalWhenWindowActive:b,tabs:p}){const g=he(F=>F.ensureDirectory),m=he(F=>F.setTabSessionId),w=he(F=>F.setTabLifecycle),x=he(F=>F.setConnecting),I=he(F=>F.appendToBuffer),v=he(F=>F.replaceBuffer),A=he(F=>F.setTabPreviewUrl),[j,N]=i.useState(null),[C,y]=i.useState(!1),[k,D]=i.useState(!1),M=i.useRef(new Map),B=i.useRef(null),_=i.useRef(n),K=i.useRef(r),V=i.useRef(s),O=i.useRef(null),T=i.useRef(new Set),P=i.useRef(new Map),U=i.useRef(p),ne=i.useRef(l),W=i.useRef(a),G=i.useRef(e);U.current=p,ne.current=l,W.current=a,G.current=e;const Ne=i.useCallback(()=>{const F=_.current;F&&P.current.get(F)?.reset()},[]);i.useEffect(()=>{K.current=r},[r]),i.useEffect(()=>{!r||!e.updateAppearance||e.updateAppearance(r,u.current).catch(()=>{})},[u,e,r]),i.useEffect(()=>{_.current=n},[n]),i.useEffect(()=>{V.current=s},[s]);const ee=i.useCallback(()=>{for(const F of M.current.values())try{F()}catch{}M.current.clear(),B.current=null,D(!1)},[]);i.useEffect(()=>()=>{ee(),K.current=null},[ee]);const Fe=i.useCallback((F,z,Q)=>{let se=P.current.get(z);se||(se=new sm,P.current.set(z,se)),se.scan(F,z,Q,A)},[A]),_e=i.useCallback((F,z,Q)=>{if(M.current.has(Q)){B.current=Q;return}const se=Lo(),Se=()=>Lo()===se&&V.current===F&&he.getState().getDirectoryState(F)?.tabs.find(we=>we.id===z)?.terminalSessionId===Q,ge=e.connect(Q,{onEvent:we=>{if(Se())switch(we.type){case"snapshot":{_.current===z&&K.current===Q?(x(F,z,!1),N(null),y(!1),D(!1),b()):x(F,z,!1),v(F,z,we.data??"",we.sequence??0),Fe(F,z,we.data??""),we.status==="exited"&&w(F,z,"exited");break}case"reconnecting":{_.current===z&&(N(null),y(!1),D(!0));break}case"data":{we.data&&(I(F,z,we.data,we.sequence,we.replayData),Fe(F,z,we.data));break}case"exit":{const re=typeof we.exitCode=="number"?we.exitCode:null,ae=typeof we.signal=="number"?we.signal:null,me=!!he.getState().getDirectoryState(F)?.tabs.find(Ue=>Ue.id===z)?.label?.startsWith("Action:");I(F,z,`\\r\\n[Process exited${re!==null?` with code ${re}`:""}${ae!==null?` (signal ${ae})`:""}]\\r\\n`),w(F,z,"exited"),_.current===z&&(x(F,z,!1),N(me?null:"Terminal session ended"),y(!1),D(!1));break}}},onError:(we,re)=>{if(!Se())return;const ae=_.current===z;if(!re){ae&&(N(null),y(!1));return}if(we.code==="SESSION_NOT_FOUND"&&!he.getState().getDirectoryState(F)?.tabs.find(me=>me.id===z)?.label?.startsWith("Action:")){ae&&(N(null),y(!1),x(F,z,!1),D(!1)),m(F,z,null),w(F,z,"idle");return}ae&&(D(!1),N(`Connection failed: ${we.message}`),y(!0),x(F,z,!1),w(F,z,"exited"),m(F,z,null))}});M.current.set(Q,()=>ge.close()),B.current=Q},[I,b,v,Fe,x,w,m,e]),q=i.useMemo(()=>p.map(F=>`${F.id}:${F.terminalSessionId??""}`).join(","),[p]);return i.useEffect(()=>{if(!l||!a||!s)return;const F=s,z=new Set;for(const Q of p)Q.terminalSessionId&&(z.add(Q.terminalSessionId),_e(F,Q.id,Q.terminalSessionId));for(const[Q,se]of M.current)if(!z.has(Q)){try{se()}catch{}M.current.delete(Q)}},[q,p,s,l,a,_e]),i.useEffect(()=>ud(()=>{if(!ne.current||!W.current)return;const F=V.current;if(!F)return;const z=[];for(const se of U.current){if(!se.terminalSessionId)continue;he.getState().getDirectoryState(F)?.tabs.find(ge=>ge.id===se.id)?.terminalSessionId===se.terminalSessionId&&z.push({id:se.id,terminalSessionId:se.terminalSessionId})}if(M.current.clear(),B.current=null,z.length===0)return;D(!0),N(null),y(!1);for(const se of z)_e(F,se.id,se.terminalSessionId);const Q=O.current;if(Q)for(const se of z)G.current.resize({sessionId:se.terminalSessionId,...Q}).catch(()=>{})}),[_e]),i.useEffect(()=>{let F=!1;if(!l||!a)return;if(!s){N(h?"No working directory available for terminal.":"Select a session to open the terminal.");return}return(async()=>{const Q=s;if(!V.current||V.current!==Q)return;if(!he.getState().getDirectoryState(Q)){g(Q);return}const Se=he.getState().getDirectoryState(Q);if(!Se||Se.tabs.length===0)return;const ge=Se.activeTabId??Se.tabs[0]?.id??null;if(!ge)return;const we=Se.tabs.find(L=>L.id===ge)??Se.tabs[0],re=we?.terminalSessionId??null,ae=we?.lifecycle??"idle",H=!!we?.label?.startsWith("Action:"),me=he.getState().getBuffer(Q,ge),Ue=me.byteLength>0||me.chunks.length>0;if(!re){if(ae==="exited"){x(Q,ge,!1);return}if(H&&Ue){x(Q,ge,!1);return}const L=`${Q}\0${ge}`;if(T.current.has(L))return;const X=O.current??$a;T.current.add(L),N(null),y(!1),D(!1),x(Q,ge,!0);try{const ue=await e.createSession({cwd:Q,sessionId:ge,cols:X.cols,rows:X.rows,shell:c,loginShell:d,...u.current});if(!he.getState().getDirectoryState(Q)?.tabs.find(Re=>Re.id===ge)){try{await e.close(ue.sessionId)}catch{}return}m(Q,ge,ue.sessionId);const je=O.current;je&&(je.cols!==X.cols||je.rows!==X.rows)&&e.resize({sessionId:ue.sessionId,...je}).catch(()=>{});return}catch(ue){const fe=he.getState().getDirectoryState(Q)?.tabs.find(je=>je.id===ge);if(!fe||fe.terminalSessionId||(x(Q,ge,!1),V.current!==Q||_.current!==ge))return;N(ue instanceof Error?ue.message:"Failed to start terminal session"),y(!0),D(!1);return}finally{T.current.delete(L)}}!re||F||(K.current=re)})(),()=>{F=!0}},[h,s,r,o,n,a,f,l,g,x,w,m,e,d,c,u]),{connectionError:j,setConnectionError:N,isFatalError:C,setIsFatalError:y,isReconnectPending:k,setIsReconnectPending:D,terminalIdRef:K,lastViewportSizeRef:O,directoryRef:V,activeTabIdRef:_,disconnectStream:ee,resetTerminalPreviewScan:Ne,startStream:_e}}function om({terminal:e,terminalIdRef:s,isReconnectPending:n,setConnectionError:r,showQuickKeys:o,isTerminalVisible:a,lastViewportSizeRef:l,terminalSessionId:c,useTouchTerminalInput:d}){const[u,f]=i.useState(null),h=i.useRef(null),b=i.useCallback(()=>{d||h.current?.focus()},[d]),p=i.useCallback(()=>{d||typeof document<"u"&&!document.hasFocus()||h.current?.focus()},[d]);i.useEffect(()=>{!o&&u!==null&&f(null)},[o,u]),i.useEffect(()=>{!c&&u!==null&&f(null)},[c,u]);const g=i.useCallback(v=>{if(!v||n)return;let A=v,j=!1;u&&v.length>0&&(A=tm(v,u),j=!0);const N=s.current;N&&(e.sendInput(N,A).catch(C=>{n||r(C instanceof Error?C.message:"Failed to send input")}),j&&(f(null),b()))},[u,b,n,r,e,s]),m=i.useCallback((v,A)=>{const j=l.current;if((!j||j.cols!==v||j.rows!==A)&&(l.current={cols:v,rows:A}),!a)return;const N=s.current;N&&e.resize({sessionId:N,cols:v,rows:A}).catch(()=>{})},[a,l,e,s]),w=i.useCallback(v=>{f(A=>A===v?null:v),b()},[b]),x=i.useCallback(v=>{const A=em(v,u);A&&(g(A),f(null),b())},[u,b,g]),I=i.useCallback(v=>{if(v.repeat)return;const A=v.key;if(!A||A==="Control"||A==="Meta"||A==="Alt"||A==="Shift")return;const j=A.length===1?A.toLowerCase():A;if(j in mi){v.preventDefault(),v.stopPropagation(),x(mi[j]);return}const N=nm(v,u);N&&(v.preventDefault(),v.stopPropagation(),g(N),f(null),b())},[u,b,x,g]);return i.useEffect(()=>{if(!(!o||!u||!c))return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[u,I,o,c]),{activeModifier:u,setActiveModifier:f,terminalControllerRef:h,focusTerminalController:b,focusTerminalWhenWindowActive:p,handleViewportInput:g,handleViewportResize:m,handleModifierToggle:w,handleMobileKeyPress:x}}function im({terminal:e,effectiveDirectory:s,activeTabId:n,enableTabs:r,terminalShell:o,terminalLoginShell:a,terminalAppearanceRef:l,lastViewportSizeRef:c,directoryRef:d,activeTabIdRef:u,terminalIdRef:f,resetTerminalPreviewScan:h,startStream:b,setConnectionError:p,setIsFatalError:g,setIsReconnectPending:m}){const w=he(B=>B.createTab),x=he(B=>B.setActiveTab),I=he(B=>B.closeTab),v=he(B=>B.setTabSessionId),A=he(B=>B.setTabLifecycle),[j,N]=i.useState(!1),C=i.useCallback(async()=>{if(!s||j)return;const B=he.getState().getDirectoryState(s),_=n??B?.activeTabId??B?.tabs[0]?.id??null;if(!_)return;const K=B?.tabs.find(V=>V.id===_)?.terminalSessionId??null;if(!(!K||!e.restartSession)){N(!0),p(null),g(!1),m(!1),h();try{const V=c.current??$a,O=await e.restartSession(K,{cwd:s,shell:o,loginShell:a,...V,...l.current});if(he.getState().getDirectoryState(s)?.tabs.find(P=>P.id===_)?.terminalSessionId!==K||(v(s,_,O.sessionId),A(s,_,"running"),d.current!==s||u.current!==_))return;f.current=O.sessionId,b(s,_,O.sessionId)}catch(V){if(he.getState().getDirectoryState(s)?.tabs.find(T=>T.id===_)?.terminalSessionId!==K||d.current!==s||u.current!==_)return;p(V instanceof Error?V.message:"Failed to restart terminal"),g(!1),m(!1),f.current=K,b(s,_,K)}finally{N(!1)}}},[n,u,d,s,r,j,c,h,p,g,m,A,v,b,e,l,f,a,o]),y=i.useCallback(async()=>{await C()},[C]),k=i.useCallback(()=>{if(!s)return;const B=w(s);x(s,B),p(null),g(!1),m(!1)},[w,s,x,p,g,m]),D=i.useCallback(B=>{s&&(x(s,B),p(null),g(!1),m(!1))},[s,x,p,g,m]),M=i.useCallback(B=>{if(!s)return;p(null),g(!1),m(!1);const _=he.getState().getDirectoryState(s)?.tabs.find(K=>K.id===B)?.terminalSessionId;(async()=>{_&&await e.close(_),I(s,B)})().catch(K=>p(K instanceof Error?K.message:"Terminal session ended"))},[I,s,p,g,m,e]);return{isRestarting:j,handleRestart:C,handleHardRestart:y,handleCreateTab:k,handleSelectTab:D,handleCloseTab:M}}const Fg=({visible:e,onCloseView:s,terminalHeaderSlot:n})=>{const{terminal:r,runtime:o}=Gs(),{currentTheme:a}=Mi(),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}=Ec(),d=ce(te=>te.terminalFontSize),u=ce(te=>te.terminalShell),f=ce(te=>te.terminalLoginShells.includes(te.terminalShell)),{isMobile:h,isTablet:b,hasTouchOnlyPointer:p}=$s(),g=h||b,m=(g||p)&&o.platform==="web",w=!0,x=ce(te=>te.showTerminalQuickKeysOnDesktop),I=g||x,v=De(te=>te.currentSessionId),A=De(te=>te.newSessionDraft),j=v!==null||A?.open===!0,N=Pc()??null,C=he(te=>N?te.sessions.get(N):void 0),y=he(te=>te.hasHydrated),k=ce(te=>te.openContextPreview),D=i.useMemo(()=>C?C.activeTabId??C.tabs[0]?.id??null:null,[C,w]),M=i.useMemo(()=>{if(C)return D?C.tabs.find(te=>te.id===D)??C.tabs[0]:C.tabs[0]},[C,D]),B=i.useMemo(()=>(C?.tabs??[]).map(te=>({icon:(()=>{const Ce=te.iconKey?dn[te.iconKey]??"terminal":"terminal";return t.jsx(R,{name:Ce,className:"h-4 w-4"})})(),id:te.id,label:te.label,title:te.label,closeLabel:"Close tab"})),[C?.tabs]),_=M?.terminalSessionId??null,K=M?.lifecycle??"idle",V=i.useMemo(()=>(C?.tabs??[]).map(te=>({id:te.id,terminalSessionId:te.terminalSessionId,label:te.label})),[C?.tabs]),O=M?.isConnecting??!1,T=M?.previewUrl??null,U=ce(te=>te.activeMainTab)==="terminal",ne=e??U,[W,G]=i.useState(ne);i.useEffect(()=>{ne&&G(!0)},[ne]);const{connectionError:Ne,setConnectionError:ee,isFatalError:Fe,setIsFatalError:_e,isReconnectPending:q,setIsReconnectPending:F,terminalIdRef:z,lastViewportSizeRef:Q,directoryRef:se,activeTabIdRef:Se,resetTerminalPreviewScan:ge,startStream:we}=rm({terminal:r,effectiveDirectory:N,activeTabId:D,terminalSessionId:_,terminalLifecycle:K,hasOpenedTerminalViewport:W,terminalHydrated:y,terminalShell:u,terminalLoginShell:f,terminalAppearanceRef:l,enableTabs:w,hasActiveContext:j,tabs:V,focusTerminalWhenWindowActive:()=>{!m&&typeof document<"u"&&document.hasFocus()&&ae.current?.focus()}}),{activeModifier:re,terminalControllerRef:ae,focusTerminalWhenWindowActive:H,handleViewportInput:me,handleModifierToggle:Ue,handleMobileKeyPress:L}=om({terminal:r,terminalIdRef:z,isReconnectPending:q,setConnectionError:ee,showQuickKeys:I,isTerminalVisible:ne,lastViewportSizeRef:Q,terminalSessionId:_,useTouchTerminalInput:m}),{isRestarting:X,handleRestart:ue,handleHardRestart:fe,handleCreateTab:je,handleSelectTab:Re,handleCloseTab:be}=im({terminal:r,effectiveDirectory:N,activeTabId:D,enableTabs:w,terminalShell:u,terminalLoginShell:f,terminalAppearanceRef:l,lastViewportSizeRef:Q,directoryRef:se,activeTabIdRef:Se,terminalIdRef:z,resetTerminalPreviewScan:ge,startStream:we,setConnectionError:ee,setIsFatalError:_e,setIsReconnectPending:F});i.useEffect(()=>{if(!ne||m)return;if(typeof window>"u"){H();return}const te=window.requestAnimationFrame(()=>{H()});return()=>{window.cancelAnimationFrame(te)}},[D,H,ne,m]);const Z=i.useMemo(()=>{const te=en[cr].stack;if(typeof window>"u")return(en[c]??en[cr]).stack;const Be=window.getComputedStyle(document.documentElement).getPropertyValue("--font-family-mono");return Be&&Be.trim().length>0?Be.trim():(en[c]??en[cr]).stack??te},[c]),pe=i.useMemo(()=>Rp(a),[a]),le=`${N??"no-dir"}::${D??"no-tab"}`;if(i.useEffect(()=>{if(!ne||m)return;const te=ae.current;if(!te)return;const Ce=()=>{te.fit()};if(typeof window<"u"){const Be=window.requestAnimationFrame(()=>{Ce(),H()}),vt=[220,400].map(Je=>window.setTimeout(Ce,Je));return()=>{window.cancelAnimationFrame(Be),vt.forEach(Je=>window.clearTimeout(Je))}}Ce()},[H,ne,m,ae,le,_]),i.useEffect(()=>{if(!ne||!m)return;let te=null;const Ce=()=>{te!==null&&window.cancelAnimationFrame(te),te=window.requestAnimationFrame(()=>{te=null,ae.current?.fit()})};return window.addEventListener("oc:keyboard-settled",Ce),()=>{window.removeEventListener("oc:keyboard-settled",Ce),te!==null&&window.cancelAnimationFrame(te)}},[ne,ae,le,m]),!j)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(!N)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:ue,className:"rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:"Retry"})]});const Le=!_||O||X||q,He=W,Ee=C?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx($p,{items:B,activeId:D,onSelect:Re,onClose:be,onCreate:je})}),t.jsx(Te,{type:"button",size:"xs",variant:"ghost",className:$("shrink-0",g?"h-8 w-8 p-0":"h-7 w-7 p-0"),onClick:je,title:"New tab","aria-label":"New tab",children:t.jsx(R,{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(Te,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ue()},disabled:X,title:"Restart terminal","aria-label":"Restart terminal",children:t.jsx(R,{name:"restart",className:"h-4 w-4"})}),T?t.jsxs(Te,{type:"button",size:"xs",variant:"outline",className:"h-6 shrink-0 gap-1 px-2",onClick:()=>{N&&k(N,T)},title:"Open preview pane",children:[t.jsx(R,{name:"global",className:"h-3.5 w-3.5 shrink-0"}),t.jsx("span",{className:"whitespace-nowrap",children:"Preview"})]}):null]})]}):null,Pe=t.jsx(Gp,{isTouchTerminal:g,activeModifier:re,disabled:Le,onKeyPress:L,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:[Ee?n?tc.createPortal(t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:Ee}),n):t.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1",children:[Ee,s?t.jsx(Te,{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(R,{name:"close",className:"h-4 w-4"})}):null]}):null,!g&&I&&w&&C?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1 pl-1 pr-1",children:Pe}):null,!g&&I&&!C?t.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:Pe}):null]}),t.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{backgroundColor:pe.background},children:[t.jsx("div",{className:"h-full w-full box-border pl-4 pr-1.5 pt-3 pb-4",children:He&&N&&C?C.tabs.map(te=>{const Ce=te.id===D;return t.jsx(zp,{directory:N,tabId:te.id,sessionId:te.terminalSessionId,sessionKey:`${N}::${te.id}`,isActive:Ce,isTerminalVisible:ne,terminal:r,theme:pe,fontFamily:Z,fontSize:d,enableTouchScroll:m,lastViewportSizeRef:Q,onInput:me,controllerRef:ae},te.id)}):null}),!q&&Ne&&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:Ne}),Fe&&g&&t.jsx(Te,{size:"sm",variant:"secondary",className:"h-6 px-2 py-0 text-xs",onClick:fe,disabled:X,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:Pe})}):null]})},am=48,lm=96,yt=(e,...s)=>{try{e?.(...s)}catch{}},jr=(e,s)=>{if(typeof e=="function"){const n=e();return n>0?n:s}return typeof e=="number"&&e>0?e:s},Og=(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"?lm:am;let d=!1,u=!1,f=!1,h=null,b=!1,p=0,g=0,m=0,w=0;const x=()=>{d=!1,u=!1,f=!1,h=null},I=()=>{const k=n.current,D=h,M=b;u&&D&&(yt(D==="left"?k.onLeftProgress:k.onRightProgress,M?1:0),yt(k.onDragEnd,D,M)),x()},v=()=>{I(),u||x()},A=k=>{const D=n.current;if(D.enabled===!1){u&&h?I():x();return}if(k.touches.length!==1){u&&h?I():x();return}const M=k.touches[0],B=o.getBoundingClientRect(),_=o.clientWidth,K=!!D.leftOpen,V=!!D.rightOpen,O=T=>vp(T,o);if(K||V){if(O(k.target)){x();return}if(K&&V){const T=M.clientX<=B.left+c;M.clientX>=B.right-c?(h="right",b=!0):T?(h="left",b=!0):(h=K?"left":"right",b=!0)}else K?(h="left",b=!0):(h="right",b=!0);w=jr(h==="left"?D.leftWidth:D.rightWidth,_),w<10&&(w=_||window.innerWidth||320),w<10&&(w=320),d=!0}else{if(O(k.target)){x();return}h=null,b=!1,w=0,d=!0}p=M.clientX,g=M.clientY,m=Date.now(),u=!1,f=!1},j=k=>{if(!d)return;if(k.touches.length!==1){v();return}const D=k.touches[0],M=D.clientX-p,B=D.clientY-g;if(!f){if(Math.abs(M)<ci&&Math.abs(B)<ci)return;if(Math.abs(B)>Math.abs(M)*sn){x();return}if(!h){const V=n.current;h=M>0?"left":"right",w=jr(h==="left"?V.leftWidth:V.rightWidth,o.clientWidth),w<10&&(w=window.innerWidth||320)}if(h==="left"){if(!b&&M<=0){x();return}if(b&&M>=0){x();return}}else{if(!b&&M>=0){x();return}if(b&&M<=0){x();return}}f=!0,u=!0,yt(n.current.onDragStart,h)}if(!u)return;k.cancelable&&k.preventDefault();const _=n.current,K=di(h,b,M,w);yt(h==="left"?_.onLeftProgress:_.onRightProgress,K)},N=(k,D)=>{if(!d){x();return}const M=k-p,B=D-g;if(!h&&!b&&Math.abs(M)>=Ln&&Math.abs(B)<=Math.abs(M)*sn){const P=n.current;h=M>0?"left":"right",w=jr(h==="left"?P.leftWidth:P.rightWidth,o.clientWidth),w<10&&(w=window.innerWidth||320)}if(!h){x();return}const _=Math.max(1,Date.now()-m),K=n.current;if(!u){const P=Math.abs(M),U=Math.abs(B);P>=Ln&&U<=P*sn?h==="left"&&!b&&M>0?(yt(K.onLeftProgress,1),yt(K.onLeftOpen)):h==="right"&&!b&&M<0?(yt(K.onRightProgress,1),yt(K.onRightOpen)):yt(h==="left"?K.onLeftProgress:K.onRightProgress,b?1:0):yt(h==="left"?K.onLeftProgress:K.onRightProgress,b?1:0);const ne=h;x(),yt(K.onDragEnd,ne);return}const V=di(h,b,M,w),O=xp({side:h,isOpenAtStart:b,dx:M,dt:_,progress:V}),T=h;yt(T==="left"?O?K.onLeftOpen:K.onLeftClose:O?K.onRightOpen:K.onRightClose),x(),yt(K.onDragEnd,T,O)},C=k=>{const D=k.changedTouches[0];if(!D){x();return}const M=D.clientX-p,B=D.clientY-g;d&&(u||Math.abs(M)>=Ln&&Math.abs(B)<=Math.abs(M)*sn)&&k.cancelable&&k.preventDefault(),N(D.clientX,D.clientY)},y=()=>{v()};return o.addEventListener("touchstart",A,{passive:!0}),o.addEventListener("touchmove",j,{passive:!1}),o.addEventListener("touchend",C,{passive:!1}),o.addEventListener("touchcancel",y,{passive:!0}),()=>{try{u&&h&&I()}catch{}o.style.touchAction=a,o.removeEventListener("touchstart",A),o.removeEventListener("touchmove",j),o.removeEventListener("touchend",C),o.removeEventListener("touchcancel",y)}},[e,r])};function Lg({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(R,{name:"layout-column",className:"absolute inset-0 h-full w-full"})]})}function gi({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 cm=({sessionDirectory:e,draftDirectory:s,isNewSessionDraftOpen:n})=>n?s:e,dm=({activeProjectLabel:e,openDirectory:s,homeDirectory:n})=>Vn(s,n)?null:e,Cr=()=>ys.filter(e=>Fr.has(e.id)).map(e=>({..._i(e)})),um=()=>{if(typeof window>"u")return Or;const e=window.localStorage.getItem("openInAppId");return e&&Tr(e)?e:Or};let kr=!1,Ps=!1,as=!1,ls=0,un=null;const bi=()=>{un&&(clearTimeout(un),un=null)},gs=Ks()((e,s)=>({selectedAppId:um(),availableApps:Cr(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(kr||typeof window>"u")return;kr=!0;const n=(d,u=!0)=>{if(!Array.isArray(d)||d.length===0){e({availableApps:Cr(),hasLoadedApps:u});return}const f=new Set(d.map(g=>g.name)),h=new Map(d.map(g=>[g.name,g.iconDataUrl??void 0])),p=ys.filter(g=>f.has(g.appName)||Fr.has(g.id)).map(g=>({..._i(g),iconDataUrl:h.get(g.appName)}));e({availableApps:p,hasLoadedApps:!0})},r=async d=>{if(!Ls()||!zn()||Ps||s().hasLoadedApps&&!d)return;const f=ys.map(h=>h.appName);bi(),Ps=!0,as=!1,e({isScanning:!0});try{const{apps:h,success:b,hasCache:p,isCacheStale:g}=await Bo(f,d),m=b&&!p&&h.length===0&&ls<3;if(e({isCacheStale:p?g:!1}),n(h,b?!m:!1),b){if(m){const x=[800,1600,3200][ls]??3200;ls+=1,as=!0,un=setTimeout(()=>{r()},x);return}ls=0,as=!1;return}if(ls<3){const x=[1e3,3e3,7e3][ls]??7e3;ls+=1,as=!0,un=setTimeout(()=>{r()},x)}}finally{Ps=!1,as||e({isScanning:!1})}};r();const o=d=>{const u=d.detail,f=u&&typeof u.openInAppId=="string"&&u.openInAppId.length>0&&Tr(u.openInAppId)?u.openInAppId:null;f&&(window.localStorage.setItem("openInAppId",f),e({selectedAppId:f}))},a=()=>{r()},l=d=>{const u=d.detail;Array.isArray(u)&&(ls=3,as=!1,e({isScanning:!1,isCacheStale:!1}),n(u))};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(kr||s().initialize(),!Ls()||!zn()||Ps||s().hasLoadedApps&&!n)return;const o=ys.map(a=>a.appName);bi(),n&&e({hasLoadedApps:!1}),Ps=!0,as=!1,e({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:c}=await Bo(o,n),d=new Set(a.map(b=>b.name)),u=new Map(a.map(b=>[b.name,b.iconDataUrl??void 0])),h=ys.filter(b=>d.has(b.appName)||Fr.has(b.id)).map(b=>({...b,iconDataUrl:u.get(b.appName)}));e({availableApps:h.length>0?h:Cr(),hasLoadedApps:h.length>0,isCacheStale:l?c:!1})}finally{Ps=!1,as||e({isScanning:!1})}},selectApp:async n=>{Tr(n)&&(e({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Zr({openInAppId:n}))}})),fm="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",hm="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",Ar=e=>({...e,fallbackIconDataUrl:e.id==="finder"&&window.__PICHAMBER_PLATFORM__==="darwin"?fm:e.id==="terminal"?hm:void 0}),xi=({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})},pm=({directory:e,className:s})=>{const n=gs(g=>g.selectedAppId),r=gs(g=>g.availableApps),o=gs(g=>g.isCacheStale),a=gs(g=>g.isScanning),l=gs(g=>g.initialize),c=gs(g=>g.loadInstalledApps),d=gs(g=>g.selectApp);i.useEffect(()=>{l()},[l]);const u=Ls()&&zn(),f=i.useMemo(()=>{const g=r.find(m=>m.id===n)??r.find(m=>m.id===Or)??r[0]??ys[0];return Ar(g||ys[0])},[r,n]);if(!u||!e||r.length===0)return null;const h=async g=>{await fd(e,g.id,g.appName)||await Li(e,g.appName)},b=async g=>{await d(g.id),await h(g)},p=async()=>{(await us(e)).ok&&oe.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(xi,{label:f.label,iconDataUrl:f.iconDataUrl,fallbackIconDataUrl:f.fallbackIconDataUrl})}),t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Dt,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{p()},children:[t.jsx(R,{name:"file-copy",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Copy Path"})]}),t.jsx(Cs,{}),r.map(g=>{const m=Ar(g);return t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{b(g)},children:[t.jsx(xi,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:m.fallbackIconDataUrl}),t.jsx("span",{className:"typography-ui-label text-foreground",children:g.label}),f.id===g.id?t.jsx(R,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},g.id)}),o?t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{c(!0)},children:[t.jsx(R,{name:"refresh",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]})]})},mm="\x1B",gm=new RegExp(`${mm}\\[[0-9;?]*[ -/]*[@-~]`,"g"),bm=/https?:\/\/[^\s<>'"`]+/gi,jt="__pichamber_auto_discover_preview__",xm=15e3,ym=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},vm=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}},wm=e=>{const n=e.replace(gm,"").match(bm);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,d=c.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",f=c.pathname||"/",h=f.split("/").filter(Boolean).length,b=f==="/"||f==="",p=!!(c.search||c.hash);let g=0;return u&&(g+=50),b&&(g+=30),g-=Math.min(h*5,20),p&&(g-=10),g};return o.sort((l,c)=>a(c)-a(l)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Sm=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],jm=["dev","start","preview","serve"];async function Cm(e,s,n){if(!e)return null;const r=Nm(s);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Im(n);if(o){const a=await Rm(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 km(e)){const o=await Am(),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 km(e){const s=`${e}/index.html`,n=await Qn(s,e);return typeof n=="string"&&n.trim().length>0}async function Am(){try{const e=await Ct("/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 Nm(e){for(const s of e){const n=`${s.name} ${s.command}`.toLowerCase();if(jm.some(o=>n.includes(o)))return s}return null}function Im(e){for(const{pattern:s}of Sm)for(const n of Object.keys(e))if(s.test(n))return n;return null}async function Rm(e){const s=await Qn(`${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 Qn(`${e}/${r}`,e);if(typeof a=="string"&&a.trim().length>0)return o}return"npm"}async function Qn(e,s){if(s?.trim())try{const r=new URLSearchParams({path:e,directory:s,optional:"true"}),o=await Ct(`/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 Ct(`/api/fs/read?path=${encodeURIComponent(e)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Dm(e){try{const s=await Qn(`${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 Em=(e,s,n)=>new Promise(r=>{let o=!1,a=null,l=null;const c=d=>{o||(o=!0,l&&clearTimeout(l),a?.close(),r(d))};a=e.connect(s,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&c(!0)},onError:(d,u)=>{u&&c(!0)}}),o?a.close():l=setTimeout(()=>c(!1),n)});function Pm({projectRef:e,directory:s,allowMobile:n=!1}){const{currentTheme:r}=Mi(),{terminal:o}=Gs(),{isMobile:a}=$s(),l=ce(L=>L.terminalShell),c=ce(L=>L.terminalLoginShells.includes(L.terminalShell)),d=ce(L=>L.setSettingsPage),u=ce(L=>L.setSettingsDialogOpen),f=ce(L=>L.setSettingsProjectsSelectedId),h=ce(L=>L.openContextPreview),b=he(L=>L.ensureDirectory),p=he(L=>L.setTabLabel),g=he(L=>L.setTabIconKey),m=he(L=>L.setActiveTab),w=he(L=>L.setConnecting),x=he(L=>L.setTabSessionId),I=he(L=>L.setTabPreviewUrl),v=he(L=>L.projectActionRuns),A=he(L=>L.setProjectActionRun),j=he(L=>L.updateProjectActionRunStatus),N=he(L=>L.removeProjectActionRun),[C,y]=i.useState([]),[k,D]=i.useState(null),[M,B]=i.useState(!1),_=i.useRef({}),K=i.useRef({}),V=i.useRef({}),O=i.useRef({}),T=i.useRef(new Set),P=i.useRef(0),U=e?.id??null,ne=e?.path??"",W=i.useMemo(()=>U?{id:U,path:ne}:null,[U,ne]),G=i.useCallback(async L=>{await ji(L)},[]),Ne=i.useCallback(async()=>{if(!W)return;const L=P.current+1;P.current=L,B(!0);try{const X=await Ir(W);if(P.current!==L)return;const ue=X.actions;y(ue),D(fe=>fe===jt||fe&&ue.some(je=>je.id===fe)?fe:null)}catch{if(P.current!==L)return}finally{P.current===L&&B(!1)}},[W]),ee=i.useMemo(()=>xa(s||W?.path||""),[s,W?.path]),Fe=i.useMemo(()=>k?C.find(L=>L.id===k)??null:null,[C,k]),_e=i.useMemo(()=>({id:jt,name:"Auto-discover",command:"",icon:"scan-2",autoOpenUrl:!0}),[]),q=!a,F=i.useMemo(()=>q?[_e,...C]:C,[C,_e,q]);i.useEffect(()=>{Ne()},[Ne]),i.useEffect(()=>{if(typeof window>"u")return;const L=X=>{const ue=X.detail;U&&(ue?.projectId&&ue.projectId!==U||Ne())};return window.addEventListener(Kr,L),()=>{window.removeEventListener(Kr,L)}},[Ne,U]),i.useEffect(()=>{k&&(k===jt&&q||C.some(L=>L.id===k)||D(null))},[C,q,k]),i.useEffect(()=>{const L=()=>{const X=he.getState(),ue=X.sessions,fe=X.projectActionRuns;for(const[je,Re]of Object.entries(fe)){const Z=ue.get(Re.directory)?.tabs.find(Be=>Be.id===Re.tabId);if(!Z||Z.terminalSessionId!==Re.sessionId){N(je);continue}const pe=K.current[je]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};K.current[je]=pe;const le=F.find(Be=>Be.id===Re.actionId),Le=X.getBuffer(Re.directory,Re.tabId).chunks;if(!le||Le.length===0)continue;const He=Le.filter(Be=>pe.lastSeenChunkId===null||Be.id>pe.lastSeenChunkId);if(He.length===0)continue;const Ee=He.map(Be=>Be.data).join(""),Pe=`${pe.tail}${Ee}`,te=!pe.openedUrl&&le.autoOpenUrl===!0?wm(Pe):null,Ce=He[He.length-1]?.id??pe.lastSeenChunkId;if(pe.lastSeenChunkId=Ce,pe.tail=Pe.slice(-512),te)if(pe.openedUrl=!0,pe.openInPreview){const Be=fe[je];Be&&(I(Be.directory,Be.tabId,te,{locked:!1,autoOpened:!1}),Be.status==="waiting-for-preview"&&j(je,"running"),window.clearTimeout(O.current[je]),delete O.current[je],h(Be.directory,te))}else G(te),oe.success("Opened URL from action output");K.current[je]=pe}for(const je of Object.keys(K.current))fe[je]||(delete K.current[je],window.clearTimeout(O.current[je]),delete O.current[je])};return L(),he.subscribe((X,ue)=>{(X.sessions!==ue.sessions||X.buffers!==ue.buffers)&&L()})},[F,h,G,v,N,I,j]);const z=i.useCallback(async(L,X={})=>{if(!ee)throw new Error("No active directory");const ue=Xt(ee,L.id);b(ee);const fe=he.getState(),je=fe.getDirectoryState(ee);let Re=_.current[ue]||null;const be=Re?!!je?.tabs.some(le=>le.id===Re):!1;(!Re||!be)&&(Re=fe.createTab(ee),_.current[ue]=Re),p(ee,Re,`Action: ${L.name}`),g(ee,Re,L.icon||"play"),m(ee,Re),X.revealTerminal!==!1&&ce.getState().openContextPanelTab(ee,{mode:"terminal"});const pe=he.getState().getDirectoryState(ee)?.tabs.find(le=>le.id===Re);return{key:ue,tabId:Re,sessionId:pe?.terminalSessionId??null}},[b,ee,m,g,p]),Q=i.useCallback(async L=>{if(!n&&a)return;if(!ee){oe.error("No active directory for action");return}const X=Xt(ee,L.id),ue=v[X];if(!(ue&&ue.status==="running")&&!T.current.has(X)){T.current.add(X);try{const fe=L.id===jt?await(async()=>{const[Pe,te]=await Promise.all([Ir({id:W?.id??"",path:ee}),Dm(ee)]),Ce=await Cm(ee,Pe.actions,te);if(!Ce)throw new Error('No dev server command found. Configure a project action or add a "dev" script to package.json.');return{id:jt,name:"Auto-discover",command:Ce.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Ce.previewUrlHint||""}})():L,je=fe.autoOpenUrl===!0&&(fe.openUrl||"").trim().length>0,Re=!je&&L.id!==jt,{key:be,tabId:Z,sessionId:pe}=await z(fe,{revealTerminal:Re});let le=pe;if(!le){w(ee,Z,!0);try{le=(await o.createSession({cwd:ee,sessionId:Z,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,Z,le)}finally{w(ee,Z,!1)}}if(!le)throw new Error("Failed to create terminal session");V.current[be]?.(),w(ee,Z,!0);const Le=o.connect(le,{onEvent:Pe=>{Pe.type==="snapshot"&&(he.getState().replaceBuffer(ee,Z,Pe.data??"",Pe.sequence??0),he.getState().setConnecting(ee,Z,!1)),Pe.type==="data"&&typeof Pe.data=="string"&&Pe.data.length>0&&he.getState().appendToBuffer(ee,Z,Pe.data,Pe.sequence,Pe.replayData),Pe.type==="exit"&&(he.getState().setTabLifecycle(ee,Z,"exited"),he.getState().setConnecting(ee,Z,!1),he.getState().removeProjectActionRun(be),delete K.current[be],V.current[be]?.(),delete V.current[be],window.clearTimeout(O.current[be]),delete O.current[be])},onError:(Pe,te)=>{he.getState().setConnecting(ee,Z,!1),te&&(he.getState().setTabLifecycle(ee,Z,"exited"),he.getState().setTabSessionId(ee,Z,null),he.getState().removeProjectActionRun(be))}});V.current[be]=Le.close;const He=fe.autoOpenUrl?vm(fe.openUrl):null;A({key:be,directory:ee,actionId:fe.id,tabId:Z,sessionId:le,status:fe.id===jt&&!He?"waiting-for-preview":"running"}),window.clearTimeout(O.current[be]),delete O.current[be],fe.id===jt&&!He&&(O.current[be]=window.setTimeout(()=>{const Pe=he.getState(),te=Pe.projectActionRuns[be];Pe.updateProjectActionRunStatus(be,"running"),te&&(Pe.setActiveTab(te.directory,te.tabId),ce.getState().openContextPanelTab(te.directory,{mode:"terminal"})),delete O.current[be]},xm)),K.current[be]={lastSeenChunkId:null,openedUrl:!!He||je,tail:"",openInPreview:fe.id===jt};const Ee=ym(fe.command.trim().replace(/\r\n|\r/g,`
|
|
53
|
-
`));await o.sendInput(le,`${Ee}\r`),He?(I(ee,Z,He,{locked:!0,autoOpened:!0}),h(ee,He),oe.success("Opened action URL")):je?(I(ee,Z,null,{locked:!0}),oe.error("Invalid custom URL format")):I(ee,Z,null,{locked:!1,autoOpened:!1})}catch(fe){N(X),delete K.current[X],V.current[X]?.(),delete V.current[X],window.clearTimeout(O.current[X]),delete O.current[X],oe.error(fe instanceof Error?fe.message:"Failed to run action")}finally{T.current.delete(X)}}},[r.colors.surface.background,r.colors.syntax.base.foreground,r.metadata.variant,z,n,a,ee,c,l,h,v,N,w,A,I,x,W?.id,o]),se=i.useCallback(async L=>{const X=Xt(ee,L.id),ue=v[X];if(!ue)return;j(X,"stopping");const fe=Em(o,ue.sessionId,1e3);try{await o.sendInput(ue.sessionId,"")}catch{}const je=await fe;if(he.getState().getDirectoryState(ue.directory)?.tabs.find(Z=>Z.id===ue.tabId)?.terminalSessionId===ue.sessionId&&!je){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:ue.sessionId})}catch{}else try{await o.close(ue.sessionId)}catch{}x(ue.directory,ue.tabId,null)}N(X),delete K.current[X],V.current[X]?.(),delete V.current[X],window.clearTimeout(O.current[X]),delete O.current[X]},[ee,v,N,x,o,j]),Se=i.useCallback(()=>{const L=Fe??F[0];if(!L)return;const X=Xt(ee,L.id),ue=v[X];if(ue?.status!=="stopping"){if(ue){se(L);return}Q(L)}},[F,ee,Q,v,Fe,se]),ge=i.useCallback((L,X=!1)=>{if(D(L.id),!X){Q(L);return}const ue=Xt(ee,L.id),fe=v[ue];if(fe?.status!=="stopping"){if(fe){se(L);return}Q(L)}},[ee,Q,v,se]),we=i.useCallback(()=>{W?.id&&(f(W.id),d("projects"),u(!0))},[u,d,f,W?.id]),re=Fe??F[0]??null,ae=re?v[Xt(ee,re.id)]:null,H=he(L=>ae?L.sessions.get(ae.directory)?.tabs.find(X=>X.id===ae.tabId)?.previewUrl??null:null),me=!!((n||!a)&&W&&ee),Ue=Fe??F[0]??null;return{shouldRender:me,isLoading:M,normalizedDirectory:ee,resolvedSelected:Ue,displayActions:F,projectActionRuns:v,selectedRunPreviewUrl:H,handlePrimaryClick:Se,handleSelectAction:ge,openProjectActionsSettings:we,openContextPreview:h}}const yi=({projectRef:e,directory:s,className:n,compact:r=!1,allowMobile:o=!1})=>{const{shouldRender:a,isLoading:l,normalizedDirectory:c,resolvedSelected:d,displayActions:u,projectActionRuns:f,selectedRunPreviewUrl:h,handlePrimaryClick:b,handleSelectAction:p,openProjectActionsSettings:g,openContextPreview:m}=Pm({projectRef:e,directory:s,allowMobile:o});if(!a||!d)return null;const w=d.icon||"play",x=d.id===jt?"scan-2":dn[w]||"play",I=Xt(c,d.id),v=f[I],A=v?.status==="stopping",j=v?.status==="waiting-for-preview",N=!!(v&&h),C=()=>{!v||!h||m(v.directory,h)},y=d.id===jt;return r?t.jsxs("div",{className:"inline-flex items-center",children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",disabled:l||A,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":v?`Stop ${d.name}`:`Run ${d.name}`,children:A||j?t.jsx(R,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):v?t.jsx(R,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):t.jsx(R,{name:x,className:"h-5 w-5"})})}),y?t.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),N?t.jsxs($e,{children:[t.jsx(Ge,{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:C,children:t.jsx(R,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),t.jsxs(Dt,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(ot,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(R,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(Cs,{}),u.map(k=>{const D=k.icon||"play",M=k.id===jt?"scan-2":dn[D]||"play",B=Xt(c,k.id),_=f[B],K=!!_,V=_?.status==="stopping";return t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{p(k,!0)},children:[t.jsx(R,{name:M,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),V||_?.status==="waiting-for-preview"?t.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?t.jsx(R,{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($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,disabled:l||A,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":v?`Stop ${d.name}`:`Run ${d.name}`,children:t.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:A||j?t.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):v?t.jsx(R,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):t.jsx(R,{name:x,className:"h-4 w-4"})})})}),y?t.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),N?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:C,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(R,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Dt,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(ot,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(R,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(Cs,{}),u.map(k=>{const D=k.icon||"play",M=k.id===jt?"scan-2":dn[D]||"play",B=Xt(c,k.id),_=f[B],K=!!_,V=_?.status==="stopping";return t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{p(k,!0)},children:[t.jsx(R,{name:M,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),V||_?.status==="waiting-for-preview"?t.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?t.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]})},Bt={docker:"docker",windows:"windows",ubuntu:"ubuntu-fill",arch:"arch-linux",nixos:"nixos",fedora:"fedora",debian:"debian",centos:"centos-fill",linux:"terminal-box",darwin:"apple",unknown:"server"};function _n(e){return e?.deploymentKind==="docker"?{name:Bt.docker,color:"#2496ED"}:e?.serverPlatform==="win32"?{name:Bt.windows,color:"#0078D4"}:e?.serverPlatform==="linux"?e.serverDistribution==="ubuntu"?{name:Bt.ubuntu,color:"#E95420"}:e.serverDistribution==="arch"?{name:Bt.arch,color:"#1793D1"}:e.serverDistribution==="nixos"?{name:Bt.nixos,color:"#5277C3"}:e.serverDistribution==="fedora"?{name:Bt.fedora,color:"#51A2DA"}:e.serverDistribution==="debian"?{name:Bt.debian,color:"#A81D33"}:e.serverDistribution==="centos"?{name:Bt.centos,color:"#932279"}:{name:Bt.linux}:e?.serverPlatform==="darwin"?{name:Bt.darwin}:{name:Bt.unknown}}const Mm=e=>e?.deploymentKind==="docker"?"Docker":e?.serverPlatform==="win32"?"Windows":e?.serverPlatform==="darwin"?"macOS":e?.serverPlatform==="linux"?typeof e.serverDistribution=="string"&&e.serverDistribution.trim()?{ubuntu:"Ubuntu",arch:"Arch Linux",nixos:"NixOS",fedora:"Fedora",debian:"Debian",centos:"CentOS"}[e.serverDistribution]??"Linux":"Linux":"Server";function Tm({open:e,onOpenChange:s}){const[n,r]=i.useState(null),o=i.useCallback(async()=>{const u=qe();try{const f=await Ct("/api/version");if(!f.ok)throw new Error("Version request failed");const h=await f.json().catch(()=>null);u===qe()&&r(h)}catch{u===qe()&&r(null)}},[]);i.useEffect(()=>(o(),Ui(()=>{o()})),[o]);const a=_n(n),l=Mm(n),c=typeof n?.pichamberVersion=="string"?n.pichamberVersion:null,d=typeof window<"u"?window.location.origin:"";return t.jsxs(It,{open:e,onOpenChange:u=>{s(u),u&&o()},children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":"Show connected server information",className:$(Ws,"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5"),children:[t.jsx(R,{name:a.name,className:"h-[18px] w-[18px] shrink-0",style:a.color?{color:a.color}:void 0}),t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:"This server"})]})})}),t.jsx(Ke,{children:t.jsx("p",{children:"Connected server information"})})]}),t.jsxs(Dt,{align:"end",className:"w-80 max-w-[calc(100vw-2rem)] p-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[t.jsx(R,{name:a.name,className:"size-5 shrink-0",style:a.color?{color:a.color}:void 0}),t.jsx("div",{className:"truncate typography-ui-label font-medium text-foreground",children:l})]}),c?t.jsx("div",{className:"shrink-0 typography-micro text-muted-foreground",children:`v${c}`}):null]}),t.jsx("div",{className:"mt-3 border-t border-[var(--interactive-border)] pt-3 typography-micro",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx("span",{className:"shrink-0 text-muted-foreground",children:"Address"}),t.jsxs("button",{type:"button",className:"ml-auto flex min-w-0 items-center gap-1.5 rounded px-1 py-0.5 text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:`Copy ${d}`,"aria-label":"Copy server address",onClick:()=>{us(d).then(u=>{u.ok?oe.success("Server address copied"):oe.error("Could not copy server address")})},children:[t.jsx("span",{className:"block max-w-[30ch] truncate font-mono",children:d}),t.jsx(R,{name:"file-copy",className:"size-3.5 shrink-0 text-muted-foreground"})]})]})})]})]})}const Fm=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(It,{children:[t.jsx(Rt,{asChild:!0,children:t.jsx("button",{type:"button",className:$(Ws,"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(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),t.jsxs(Dt,{align:"end",className:"w-64",children:[t.jsx(Mc,{className:"typography-ui-header font-semibold text-foreground",children:"GitHub Accounts"}),t.jsx(Cs,{}),r.map(d=>{const u=d.user,f=!!d.current,h=d.source==="gh-cli"?"CLI":"OAuth";return t.jsxs(ot,{className:"gap-2",disabled:l,onSelect:()=>{f||c(d.id)},children:[u?.avatarUrl?t.jsx("img",{src:u.avatarUrl,alt:u.login?`${u.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(R,{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:u?.name?.trim()||u?.login||"GitHub"}),u?.login?t.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[t.jsx("span",{className:"font-mono",children:u.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:h})]}):null]}),f?t.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},d.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(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),Om=i.memo(function({isDesktopApp:s,currentInstanceLabel:n,compactCurrentInstanceLabel:r,currentInstanceIsLocal:o,currentInstanceIcon:a,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,shortcutLabel:u,remoteUpdateInfo:f,remoteUpdateChecking:h,remoteUpdateError:b,onOpenRemoteUpdate:p}){return t.jsxs(It,{open:l,onOpenChange:g=>{c(g),g&&d()},children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":s?`Open instance, usage and MCP (current: ${n})`:"Open services, usage and MCP",className:$(Ws,s?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[t.jsx(R,{name:a.name,className:"h-[18px] w-[18px]",style:a.color?{color:a.color}:void 0}),s?t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:r}):null]})})}),t.jsx(Ke,{children:t.jsx("p",{children:`Current instance: ${n} (${u("toggle_services_menu")})`})})]}),t.jsx(Dt,{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:f?.available?`Version ${f.version||""} is available for this instance.`:h?"Looking for updates...":b||"This instance is up to date."})]}),f?.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:p,children:"Update"}):null]})}),t.jsx(Tc,{embedded:!0,open:l,onOpenChange:()=>{},onHostSwitched:()=>c(!1)})]}):null})]})}),Lm=({action:e,onClose:s,sessionTitle:n,onConfirm:r})=>t.jsx(Yt,{open:e!==null,onOpenChange:o=>{o||s()},children:t.jsxs(qt,{showCloseButton:!1,className:"max-w-sm gap-5",children:[t.jsxs(fs,{children:[t.jsx(es,{children:e==="delete"?"Delete session?":"Archive session?"}),t.jsx(hs,{children:e==="delete"?`"${n}" will be permanently deleted.`:`"${n}" will be archived.`})]}),t.jsxs(ks,{children:[t.jsx(Te,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),t.jsx(Te,{variant:"destructive",size:"sm",onClick:r,children:e==="delete"?"Delete":"Archive"})]})]})}),Bm=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},tn=e=>{if(!e)return"";const s=e.replace(/\\/g,"/");return s==="/"?"/":s.replace(/\/+$/,"")},_m=i.lazy(()=>cs(()=>import("./SessionSwitcherDropdown-CRVJU16x.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}))),Bg=({onToggleLeftDrawer:e,onToggleRightDrawer:s,leftDrawerOpen:n,rightDrawerOpen:r,tabletWorkspaceTab:o,onSelectTabletWorkspaceTab:a})=>{_t("ui.header.render");const l=ce(E=>E.setSessionSwitcherOpen),c=ce(E=>E.toggleSidebar),d=ce(E=>E.isSidebarOpen),u=ce(E=>E.activeMainTab),f=ce(E=>E.setActiveMainTab),h=ce(E=>E.shortcutOverrides);ce(E=>E.timeFormatPreference),Gs();const b=De(E=>!!E.newSessionDraft?.open),p=De(E=>E.currentSessionId),g=Pi(p??""),m=Fc(p),w=i.useMemo(()=>{if(!m)return null;const E=m;return{title:m.title??null,directory:E.directory??null,created:m.time?.created??null,slug:E.slug??null,shareUrl:m.share?.url??null,parentId:m.parentID??null}},[m]),x=pt(Lr(E=>{if(!E.activeProjectId)return null;const ie=E.projects.find(ye=>ye.id===E.activeProjectId);return ie?{id:ie.id,path:ie.path,label:ie.label}:null})),I=Bs(E=>E.homeDirectory),v=i.useMemo(()=>{if(!x)return null;const E=x.label?.trim();if(E)return E;const ie=x.path.split(/[\\/]/).filter(Boolean);return ie[ie.length-1]??null},[x]),{isMobile:A}=$s(),{enabled:j}=Jr(),N=!!(j&&a&&o!==void 0),C=i.useMemo(()=>[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"}],[]),[y,k]=i.useState(!1),D=null,M=i.useRef(null),[B,_]=i.useState(()=>typeof window>"u"?!1:Ls()),K=i.useMemo(()=>Bi(),[]),V=Oc(),[O,T]=i.useState(!1),P=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),U=Ti(),ne=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 ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const ye=Number.parseInt(ie[1],10),ze=Number.parseInt(ie[2],10);return Number.isNaN(ye)?null:ye===10?ze:ye},[]);Ae.useEffect(()=>{typeof window>"u"||_(Ls())},[]);const W=ce(E=>E.isSessionSwitcherOpen),G=null,Ne=null,ee=[],[Fe,_e]=i.useState(!1),[q,F]=i.useState(!1),[z,Q]=i.useState("Local"),[se,Se]=i.useState(!0),[ge,we]=i.useState(()=>_n(null)),[re,ae]=i.useState(!1),[H,me]=i.useState(null),[Ue,L]=i.useState(!1),[X,ue]=i.useState(null),fe=i.useRef(0),je=i.useMemo(()=>Bm(z),[z]),Re=i.useCallback(async()=>{if(typeof window>"u"||!B)return;const E=qe(),ie=()=>qe()===E;try{const ye=await Ct("/api/version");if(!ie())return;const ze=ye.ok?await ye.json().catch(()=>null):null;if(!ie())return;if(we(_n(ze)),zn()){Q("Local"),Se(!0);return}Se(!1);const bt=await hd();if(!ie())return;const Qe=pd(),os=md([gd(Qe),...bt.hosts]);if(os.id===bd){Q("Local"),Se(!0);return}Q(xd(os.label.trim()||"Instance"))}catch{ie()&&(Q("Local"),Se(!0),we(_n(null)))}},[B]);Ae.useEffect(()=>(Re(),Ui(()=>{fe.current+=1,me(null),ue(null),L(!1),ae(!1),Re()})),[Re]);const be=i.useCallback(async()=>{const E=fe.current+1;fe.current=E;const ie=qe(),ye=()=>fe.current===E&&qe()===ie;if(se){me(null),ue(null);return}L(!0),ue(null);try{const ze=new URLSearchParams({appType:"web",instanceMode:"remote"}),bt=await Ct(`/api/pi/update-check?${ze.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!bt.ok)throw new Error(`Server responded with ${bt.status}`);const Qe=await bt.json();if(!ye())return;me({available:Qe.available??!1,version:Qe.version,currentVersion:Qe.currentVersion??"unknown",body:Qe.body,nextSuggestedCheckInSec:typeof Qe.nextSuggestedCheckInSec=="number"?Qe.nextSuggestedCheckInSec:void 0,packageManager:Qe.packageManager,updateCommand:Qe.updateCommand,channel:Qe.channel==="rc"?"rc":"stable"})}catch(ze){if(!ye())return;me(null),ue(ze instanceof Error?ze.message:"Failed to check remote instance updates")}finally{ye()&&L(!1)}},[se]);i.useEffect(()=>Ku(()=>{se||be()}),[be,se]),i.useEffect(()=>{fe.current+=1,me(null),ue(null),L(!1),ae(!1)},[se,z]),i.useEffect(()=>{if(!B||se)return;const E=3e3,ie=3600*1e3;let ye=!1,ze=null;const bt=Qe=>{ze=window.setTimeout(()=>{if(ye||typeof document<"u"&&document.visibilityState!=="visible"){bt(ie);return}be().finally(()=>{ye||bt(ie)})},Qe)};return bt(E),()=>{ye=!0,ze!==null&&window.clearTimeout(ze)}},[be,se,z,B]);const Z=i.useCallback(()=>{if(H?.available){ae(!0);return}be()},[be,H?.available]),pe=p?w??null:null,le=i.useRef(null),[Le,He]=i.useState(0);i.useEffect(()=>{if(!p){le.current&&(le.current=null,He(ze=>ze+1));return}if(pe){le.current={sessionId:p,session:pe,expiresAt:Date.now()+2e3};return}const E=le.current;if(!E||E.sessionId!==p)return;const ie=E.expiresAt-Date.now();if(ie<=0){le.current=null,He(ze=>ze+1);return}const ye=window.setTimeout(()=>{le.current?.sessionId===p&&(le.current=null),He(ze=>ze+1)},ie);return()=>{window.clearTimeout(ye)}},[p,pe]);const Ee=(()=>{if(pe)return pe;if(!p)return null;const E=le.current;return E&&E.sessionId===p&&E.expiresAt>Date.now()?E.session:null})(),Pe=i.useMemo(()=>{const E=typeof Ee?.directory=="string"?Ee.directory:"";return tn(E||"")},[Ee?.directory]),te=De(E=>E.newSessionDraft?.open?tn(E.newSessionDraft.directoryOverride??""):""),Ce=i.useMemo(()=>cm({sessionDirectory:Pe,draftDirectory:te,isNewSessionDraftOpen:b}),[te,b,Pe]),vt=Ei(Ce||null),Je=i.useMemo(()=>dm({activeProjectLabel:v,openDirectory:Ce,homeDirectory:I}),[v,I,Ce]),et=!!(Je||vt),Et=i.useMemo(()=>p?ds(Ee):Je??"PiChamber",[Ee,p,Je]),kt=Lc(),ts=De(E=>E.updateSessionTitle),mt=De(E=>E.archiveSessions),at=De(E=>E.deleteSessions),[Xe,lt]=i.useState(!1),[Ut,ss]=i.useState(!1),wt=i.useRef(!1),[ve,Oe]=i.useState(""),[xe,Me]=i.useState(null),Ye=i.useRef(null);i.useEffect(()=>{wt.current=!1,ss(!1),lt(!1),Oe(""),Me(null)},[p]);const ct=i.useCallback(()=>{p&&(Oe(Ee?.title?.trim()||Et),lt(!0))},[Ee?.title,p,Et]),St=i.useCallback(async()=>{if(!p)return;const E=ve.trim();E&&E!==Ee?.title?.trim()&&await ts(p,E),lt(!1)},[Ee?.title,p,ve,ts]);i.useEffect(()=>{if(!Xe)return;const E=ie=>{const ye=ie.target;(!ye||!Ye.current?.contains(ye))&&St()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[Xe,St]);const zt=i.useCallback(()=>{p&&us(p).then(E=>{oe[E.ok?"success":"error"](E.ok?"Session ID copied":"Failed to copy session ID")}).catch(()=>oe.error("Failed to copy session ID"))},[p]),ps=i.useCallback(async()=>{if(!p||!Ce){oe.error("Nothing to export");return}try{await kt.syncSession(p)}catch{oe.error("Failed to load the complete session history");return}const E=[];if(E.length===0){oe.error("Nothing to export");return}const ie=Fa(E,Ee?.title??null),ye=Ba(Ee?.title??null);await La(ie,ye)||Oa(ie,ye),oe.success("Session exported")},[Ee?.title,p,Ce,kt]);g?.type==="busy"||g?.type;const Pt=i.useCallback(async()=>{if(!p||!xe)return;const E=Bc(),ie=[p];for(let Qe=0;Qe<ie.length;Qe+=1){const os=ie[Qe];for(const xt of E)xt.parentID===os&&!ie.includes(xt.id)&&ie.push(xt.id)}const ye=xe;if(Me(null),(ye==="archive"?await mt(ie):await at(ie)).failedIds.length>0){oe.error(ye==="archive"?"Failed to archive session":"Failed to delete session");return}oe.success(ye==="archive"?"Session archived":"Session deleted")},[mt,p,at,xe]),tt=ce(E=>E.isArchivePageOpen),Mt=i.useMemo(()=>tt?{title:"Archive",subtitle:null}:null,[tt]),Ze=i.useMemo(()=>tn(Ce||x?.path||""),[x?.path,Ce]),Qt=i.useCallback(()=>{Ze&&us(Ze).then(E=>{oe[E.ok?"success":"error"](E.ok?"Working directory copied":"Failed to copy working directory")}).catch(()=>oe.error("Failed to copy working directory"))},[Ze]),$t=i.useMemo(()=>x?{id:x.id,path:x.path}:null,[x]),Ns=i.useRef(null);i.useEffect(()=>{!$t||!Ze||(Ns.current={projectRef:$t,directory:Ze})},[Ze,$t]);const Tt=i.useMemo(()=>$t&&Ze?{projectRef:$t,directory:Ze}:Ns.current,[Ze,$t]),Hs=i.useCallback(async E=>{},[]),dt=i.useCallback(()=>{if(typeof document>"u")return;const E=document.activeElement;if(!E)return;const ie=E.tagName;(ie==="INPUT"||ie==="TEXTAREA"||ie==="SELECT"||E.isContentEditable)&&E.blur()},[]),ms=i.useCallback(()=>{if(A){dt(),l(!W);return}c()},[dt,A,W,l,c]),gt=i.useCallback(()=>{ln("desktop_open_draft_mini_chat_window",{directory:tn(Ce||x?.path||""),projectId:x?.id??null,apiBaseUrl:Mr(),clientToken:Pr()}).catch(E=>{console.warn("[header] failed to open draft mini chat window",E)})},[x?.id,x?.path,Ce]),de=i.useCallback(()=>{if(b){gt();return}p&&ln("desktop_open_session_mini_chat_window",{sessionId:p,directory:tn(Ce||x?.path||""),apiBaseUrl:Mr(),clientToken:Pr()}).catch(E=>{console.warn("[header] failed to open session mini chat window",E)})},[x?.path,p,gt,b,Ce]),nt=Ws,st=gf,ut=i.useMemo(()=>n?"sessions":N?r&&o?o:null:r?"git":u,[u,N,n,r,o]),Gt=i.useCallback(()=>{n&&e&&e(),r&&s&&s(),!e&&W&&l(!1)},[W,n,e,s,r,l]),ft=i.useCallback(()=>{e?.()},[e]),Xn=i.useCallback(()=>{s?.()},[s]),Ys=i.useMemo(()=>B&&P&&!O?"5.5rem":V?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":!B||U?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[B,O,P,V,U]);Ae.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Ys)},[Ys]);const xn=d?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Is=d?"0px":B&&U?"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)":j?"2.75rem":"2.5rem";Ae.useEffect(()=>{if(!B||!P){T(!1);return}let E=!1;const ie=async()=>{try{const ze=await ln("desktop_is_window_fullscreen");E||T(ze===!0)}catch{E||T(!1)}},ye=()=>{ie()};return ie(),window.addEventListener("pichamber:window-resized",ye),()=>{E=!0,window.removeEventListener("pichamber:window-resized",ye)}},[B,P]);const yn=i.useMemo(()=>!B||!P||ne===null?"":ne>=26?"h-12":ne<=15?"h-14":"",[B,P,ne]),Zn=i.useMemo(()=>{if(!(B&&!U))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))"}},[B,U]),ns=i.useCallback(()=>{if(typeof document>"u")return;const E=M.current?.getBoundingClientRect().height;E&&document.documentElement.style.setProperty("--oc-header-height",`${E}px`)},[]);Ae.useEffect(()=>{if(typeof window>"u")return;ns();const E=M.current;if(!E||typeof ResizeObserver>"u")return()=>{};let ie=0;const ye=()=>{ie||(ie=requestAnimationFrame(()=>{ie=0,ns()}))},ze=new ResizeObserver(ye);return ze.observe(E),window.addEventListener("resize",ye),window.addEventListener("orientationchange",ye),()=>{ie&&cancelAnimationFrame(ie),ze.disconnect(),window.removeEventListener("resize",ye),window.removeEventListener("orientationchange",ye)}},[ns]),Ae.useEffect(()=>{ns()},[ns,A,yn]);const qs=i.useCallback(async E=>{const ie=E.target;ie.closest(".app-region-no-drag")||ie.closest("button, a, input, select, textarea")||E.button===0&&B&&await _c()},[B]),Ft=i.useMemo(()=>A?[{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"}]:[],[A]),er=i.useCallback(E=>to(Un(E,h)),[h]);Ae.useEffect(()=>{!A&&u!=="chat"&&u!=="terminal"&&u!=="diagram"&&f("chat")},[u,A,f]),Ae.useEffect(()=>{const E=ie=>{if(yd(ie)&&!ie.shiftKey&&!ie.altKey){const ye=parseInt(ie.key,10);ye>=1&&ye<=Ft.length&&(ie.preventDefault(),A&&(dt(),Gt()),f(Ft[ye-1].id))}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[dt,Gt,A,f,Ft]),Ae.useEffect(()=>{const E=ie=>{const ye=Un("toggle_services_menu",h);if(vd(ie,ye)){ie.preventDefault(),q?F(!1):(F(!0),Re());return}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[h,q,Re]);const tr=E=>{const ie=u===E.id,ye=E.icon==="diff",ze=ye?null:E.icon,bt=E.id==="chat",Qe=xt=>ye?t.jsx(gi,{size:xt}):ze?t.jsx(R,{name:ze,className:`h-${xt/4} w-${xt/4}`}):null,os=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",ie?"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",bt&&!A&&"min-w-[100px] justify-center"),"aria-label":E.label,"aria-selected":ie,role:"tab",children:[A?Qe(20):t.jsxs(t.Fragment,{children:[Qe(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:os},E.id)},Qs=t.jsxs(t.Fragment,{children:[t.jsx(pm,{directory:Ze,className:"mr-1"}),B?t.jsx(Om,{isDesktopApp:B,currentInstanceLabel:z,compactCurrentInstanceLabel:je,currentInstanceIsLocal:se,currentInstanceIcon:ge,isDesktopServicesOpen:q,setIsDesktopServicesOpen:F,refreshCurrentInstanceLabel:Re,shortcutLabel:er,remoteUpdateInfo:H,remoteUpdateChecking:Ue,remoteUpdateError:X,onOpenRemoteUpdate:Z}):t.jsx(Tm,{open:q,onOpenChange:F}),t.jsx(Fm,{isMobile:A,githubAuthStatus:D,githubAccounts:ee,githubAvatarUrl:G,githubLogin:Ne,isSwitchingGitHubAccount:Fe,handleGitHubAccountSwitch:Hs})]}),Vs=K&&(b||!!p),vn=()=>t.jsxs("div",{onMouseDown:qs,className:$("app-region-drag relative flex h-12 select-none items-center pr-3",yn),style:Zn,role:"tablist","aria-label":"Main navigation",children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:xn}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Is}}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Mt?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:Mt.title}),Mt.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:Mt.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:[d?null:t.jsx(i.Suspense,{fallback:t.jsx("button",{type:"button",className:nt,"aria-label":"Open session switcher",children:t.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})}),children:t.jsx(_m,{align:"start",children:t.jsx("button",{type:"button",className:nt,"aria-label":"Open session switcher",children:t.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 px-1",children:[Xe?t.jsxs("form",{ref:Ye,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:E=>{E.preventDefault(),St()},children:[t.jsx("input",{value:ve,onChange:E=>Oe(E.target.value),autoFocus:!0,onKeyDown:E=>{E.stopPropagation(),E.key==="Escape"&<(!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(R,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:()=>lt(!1),"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(R,{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":Et}),et?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:[Je?t.jsx("span",{className:"truncate",children:Je}):null,vt?t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[t.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),t.jsx("span",{className:"truncate",children:vt})]}):null]})]}):null]}),t.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-center",children:p&&!b&&!Xe?t.jsxs(It,{open:Ut,onOpenChange:ss,onOpenChangeComplete:E=>{!E&&wt.current&&(wt.current=!1,ct())},children:[t.jsx(Rt,{asChild:!0,children:t.jsx(Te,{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(R,{name:"more",className:"size-4"})})}),t.jsxs(Dt,{align:"end",className:"min-w-[190px]",children:[t.jsxs(ot,{onClick:()=>{wt.current=!0},children:[t.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),"Rename"]}),t.jsxs(ot,{onClick:zt,children:[t.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),"Copy session ID"]}),t.jsxs(ot,{onClick:Qt,disabled:!Ze,children:[t.jsx(R,{name:"folder",className:"mr-2 size-4"}),"Copy working directory"]}),t.jsx(Cs,{}),t.jsxs(ot,{onClick:()=>{ps()},children:[t.jsx(R,{name:"download",className:"mr-2 size-4"}),"Export Markdown"]}),t.jsx(Cs,{}),t.jsxs(ot,{onClick:()=>Me("archive"),children:[t.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),"Archive"]}),t.jsxs(ot,{className:"text-destructive focus:text-destructive",onClick:()=>Me("delete"),children:[t.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),"Delete"]})]})]}):null})]}),Ft.length>0&&t.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ft.map(E=>tr(E))}),t.jsx("div",{className:"flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(Sa,{}),Tt?t.jsx(yi,{projectRef:Tt.projectRef,directory:Tt.directory,className:"mr-1"}):null,t.jsx(bf,{visible:Vs,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:de,className:$(nt,"mr-1"),Icon:"picture-in-picture-2"}),Qs,t.jsx(Uc,{visible:U})]})]})]}),rs=()=>t.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[j&&t.jsxs(t.Fragment,{children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:xn}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Is}})]}),!j&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e?t.jsx("button",{type:"button",onClick:ft,className:$(st,ut==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:t.jsx(R,{name:"layout-left",className:"h-5 w-5"})}):W?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(R,{name:"arrow-left-s",className:"h-5 w-5"})}):t.jsx("button",{type:"button",onClick:ms,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(R,{name:"play-list-add",className:"h-5 w-5"})}),!e&&W&&t.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),(!W||!!e)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:!N&&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:Ft.map(E=>{const ie=u===E.id,ye=E.icon==="diff",ze=ye?null:E.icon;return t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>{A&&(dt(),Gt()),f(E.id)},"aria-label":E.label,"aria-selected":ie,role:"tab",className:$(st,"relative rounded-lg",ut===E.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[ye?t.jsx(gi,{className:"h-5 w-5"}):ze?t.jsx(R,{name:ze,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(Ke,{children:t.jsx("p",{children:E.label})})]},E.id)})})})})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[N&&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:C.map(E=>{const ie=r&&o===E.id;return t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>{A&&(dt(),Gt()),k(!1),a?.(E.id)},"aria-label":E.label,"aria-selected":ie,role:"tab",className:$(st,"relative rounded-lg",ie&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(R,{name:E.icon,className:"h-5 w-5"})})}),t.jsx(Ke,{children:t.jsx("p",{children:E.label})})]},E.id)})}),t.jsx(mf,{open:y,onOpenChange:k,currentSessionId:p,effectiveDirectory:Ce||null,isNewSessionDraftOpen:b})]}),Tt&&t.jsx(yi,{projectRef:Tt.projectRef,directory:Tt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s&&!N?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:Xn,className:$(st,"relative",ut==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:t.jsx(R,{name:"layout-right",className:"h-5 w-5"})})}),t.jsx(Ke,{children:t.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Js=$("header-safe-area relative z-10 bg-background",A&&"border-b border-border/50");return t.jsxs(t.Fragment,{children:[t.jsx("header",{ref:M,className:Js,style:{"--padding-scale":"1"},children:A?rs():vn()}),t.jsx(Lm,{action:xe,onClose:()=>Me(null),sessionTitle:Et,onConfirm:()=>{Pt()}}),t.jsx(ha,{open:re,onOpenChange:ae,info:H,downloading:!1,downloaded:!1,progress:null,error:X,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})},vi="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",Um="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",_g=()=>{const e=ce(p=>p.isSidebarOpen),s=ce(p=>p.toggleSidebar),n=ce(p=>p.shortcutOverrides),r=i.useRef(null),o=i.useRef(null),a=to(Un("toggle_sidebar",n)),l=Ti(),{enabled:c}=Jr(),d=!e,u=l,f=d||u,h=u,b=i.useCallback(()=>{ln("desktop_show_app_menu").catch(p=>{console.warn("[titlebar] failed to open app menu",p)})},[]);return i.useEffect(()=>{if(typeof document>"u")return;const p=v=>{document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(v)}px`)},g=v=>{document.documentElement.style.setProperty("--oc-titlebar-overlay-width",`${Math.round(v)}px`)};if(!h)return;const m=o.current,w=r.current;if(!m||!w){p(0),g(0);return}const x=()=>{const v=Math.max(m.getBoundingClientRect().width,m.scrollWidth);p(v),g(w.getBoundingClientRect().width)};if(x(),typeof ResizeObserver>"u")return;const I=new ResizeObserver(x);return I.observe(m),I.observe(w),()=>{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:[u?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,"aria-label":"Open PiChamber menu",className:$(vi,"shrink-0"),children:t.jsx(R,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),t.jsx(Ke,{children:t.jsx("p",{children:"PiChamber menu"})})]}):null,d?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:s,"aria-label":"Open sessions",className:$(c?Um:vi,"shrink-0"),children:t.jsx(R,{name:"layout-left",className:c?"size-[18px]":"h-[18px] w-[18px]"})})}),t.jsx(Ke,{children:t.jsx("p",{children:`Open sessions (${a})`})})]}):null]})}):null},wi=200,zm="cubic-bezier(0.22, 1, 0.36, 1)",Ug=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 d=window.requestAnimationFrame(()=>{c=window.requestAnimationFrame(()=>r(!0))});return()=>{window.cancelAnimationFrame(d),window.cancelAnimationFrame(c)}}r(!1);const l=window.setTimeout(()=>a(!1),wi);return()=>window.clearTimeout(l)},[e,s]),{slidIn:n,layoutVisible:o,prefersReducedMotion:s,transition:s?"none":`transform ${wi}ms ${zm}`}},zg=()=>{zi()},$g=e=>{De.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ce.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),he.getState().clearAll(),zi(),Bs.getState().resetForRuntimeSwitch(),zc.getState().resetForRuntimeSwitch(),$c.getState().resetForRuntimeSwitch(),Gc(),Kc.getState().resetForRuntimeSwitch(),Wt.setState({providers:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),pt.getState().resetForRuntimeSwitch(),Wc(),Hc(),Xd.getState().reset(),wd.getState().resetForRuntimeSwitch(),Ri.getState().resetForRuntimeSwitch(e.runtimeKey),Dr.getState().resetForRuntimeSwitch(e.runtimeKey),js.getState().resetForRuntimeSwitch(e.runtimeKey),Zf.getState().resetForRuntimeSwitch(),ht.getState().resetForRuntimeSwitch(e.runtimeKey),Sd.getState().resetForRuntimeSwitch(e.runtimeKey),De.getState().restoreForRuntimeSwitch(e.runtimeKey),ce.getState().restoreForRuntimeSwitch(e.runtimeKey);const s=ce.getState();_r({sessionId:De.getState().currentSessionId,tab:s.activeMainTab,isSettingsOpen:s.isSettingsDialogOpen,settingsPath:s.settingsPage,diffFile:s.pendingDiffFile},{replace:!0,force:!0})};export{lf as $,Dg as A,Lg as B,Rg as C,ci as D,yu as E,dg as F,ag as G,Bg as H,gs as I,lu as J,bs as K,ug as L,wa as M,zu as N,jg as O,Ou as P,hg as Q,Ig as R,Eg as S,Fg as T,vg as U,ha as V,ig as W,ro as X,xg as Y,Uu as Z,ga as _,mf as a,Fu as a0,$u as a1,gn as a2,pa as a3,bn as a4,cn as a5,Lu as a6,pg as a7,Bu as a8,Sg as a9,Ag as aa,kg as ab,Gu as ac,wg as ad,Cg as ae,Ng as af,fg as ag,mg as ah,gg as ai,bg as aj,sf as ak,yg as al,wu as am,_u as an,Su as ao,rg as ap,sn as b,bp as c,Pg as d,Ln as e,Ug as f,Mg as g,Og as h,vp as i,_g as j,$g as k,lg as l,cg as m,og as n,ng as o,oo as p,io as q,zg as r,Tg as s,ao as t,hf as u,Os as v,va as w,cf as x,df as y,Yo as z};
|
|
53
|
+
`));await o.sendInput(le,`${Ee}\r`),He?(I(ee,Z,He,{locked:!0,autoOpened:!0}),h(ee,He),oe.success("Opened action URL")):je?(I(ee,Z,null,{locked:!0}),oe.error("Invalid custom URL format")):I(ee,Z,null,{locked:!1,autoOpened:!1})}catch(fe){N(X),delete K.current[X],V.current[X]?.(),delete V.current[X],window.clearTimeout(O.current[X]),delete O.current[X],oe.error(fe instanceof Error?fe.message:"Failed to run action")}finally{T.current.delete(X)}}},[r.colors.surface.background,r.colors.syntax.base.foreground,r.metadata.variant,z,n,a,ee,c,l,h,v,N,w,A,I,x,W?.id,o]),se=i.useCallback(async L=>{const X=Xt(ee,L.id),ue=v[X];if(!ue)return;j(X,"stopping");const fe=Em(o,ue.sessionId,1e3);try{await o.sendInput(ue.sessionId,"")}catch{}const je=await fe;if(he.getState().getDirectoryState(ue.directory)?.tabs.find(Z=>Z.id===ue.tabId)?.terminalSessionId===ue.sessionId&&!je){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:ue.sessionId})}catch{}else try{await o.close(ue.sessionId)}catch{}x(ue.directory,ue.tabId,null)}N(X),delete K.current[X],V.current[X]?.(),delete V.current[X],window.clearTimeout(O.current[X]),delete O.current[X]},[ee,v,N,x,o,j]),Se=i.useCallback(()=>{const L=Fe??F[0];if(!L)return;const X=Xt(ee,L.id),ue=v[X];if(ue?.status!=="stopping"){if(ue){se(L);return}Q(L)}},[F,ee,Q,v,Fe,se]),ge=i.useCallback((L,X=!1)=>{if(D(L.id),!X){Q(L);return}const ue=Xt(ee,L.id),fe=v[ue];if(fe?.status!=="stopping"){if(fe){se(L);return}Q(L)}},[ee,Q,v,se]),we=i.useCallback(()=>{W?.id&&(f(W.id),d("projects"),u(!0))},[u,d,f,W?.id]),re=Fe??F[0]??null,ae=re?v[Xt(ee,re.id)]:null,H=he(L=>ae?L.sessions.get(ae.directory)?.tabs.find(X=>X.id===ae.tabId)?.previewUrl??null:null),me=!!((n||!a)&&W&&ee),Ue=Fe??F[0]??null;return{shouldRender:me,isLoading:M,normalizedDirectory:ee,resolvedSelected:Ue,displayActions:F,projectActionRuns:v,selectedRunPreviewUrl:H,handlePrimaryClick:Se,handleSelectAction:ge,openProjectActionsSettings:we,openContextPreview:h}}const yi=({projectRef:e,directory:s,className:n,compact:r=!1,allowMobile:o=!1})=>{const{shouldRender:a,isLoading:l,normalizedDirectory:c,resolvedSelected:d,displayActions:u,projectActionRuns:f,selectedRunPreviewUrl:h,handlePrimaryClick:b,handleSelectAction:p,openProjectActionsSettings:g,openContextPreview:m}=Pm({projectRef:e,directory:s,allowMobile:o});if(!a||!d)return null;const w=d.icon||"play",x=d.id===jt?"scan-2":dn[w]||"play",I=Xt(c,d.id),v=f[I],A=v?.status==="stopping",j=v?.status==="waiting-for-preview",N=!!(v&&h),C=()=>{!v||!h||m(v.directory,h)},y=d.id===jt;return r?t.jsxs("div",{className:"inline-flex items-center",children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",disabled:l||A,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":v?`Stop ${d.name}`:`Run ${d.name}`,children:A||j?t.jsx(R,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):v?t.jsx(R,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):t.jsx(R,{name:x,className:"h-5 w-5"})})}),y?t.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),N?t.jsxs($e,{children:[t.jsx(Ge,{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:C,children:t.jsx(R,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),t.jsxs(Dt,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(ot,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(R,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(Cs,{}),u.map(k=>{const D=k.icon||"play",M=k.id===jt?"scan-2":dn[D]||"play",B=Xt(c,k.id),_=f[B],K=!!_,V=_?.status==="stopping";return t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{p(k,!0)},children:[t.jsx(R,{name:M,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),V||_?.status==="waiting-for-preview"?t.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?t.jsx(R,{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($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,disabled:l||A,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":v?`Stop ${d.name}`:`Run ${d.name}`,children:t.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:A||j?t.jsx(R,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):v?t.jsx(R,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):t.jsx(R,{name:x,className:"h-4 w-4"})})})}),y?t.jsx(Ke,{sideOffset:6,children:"Automatically discover and run the development server"}):null]}),N?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:C,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(R,{name:"global",className:"h-4 w-4"})})}),t.jsx(Ke,{sideOffset:6,children:"Open Preview"})]}):null,t.jsxs(It,{children:[t.jsx(Rt,{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(R,{name:"arrow-down-s",className:"h-4 w-4"})})}),t.jsxs(Dt,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[t.jsxs(ot,{className:"flex items-center gap-2",onClick:g,children:[t.jsx(R,{name:"add",className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Add new action"})]}),t.jsx(Cs,{}),u.map(k=>{const D=k.icon||"play",M=k.id===jt?"scan-2":dn[D]||"play",B=Xt(c,k.id),_=f[B],K=!!_,V=_?.status==="stopping";return t.jsxs(ot,{className:"flex items-center gap-2",onClick:()=>{p(k,!0)},children:[t.jsx(R,{name:M,className:"h-4 w-4"}),t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:k.name}),V||_?.status==="waiting-for-preview"?t.jsx(R,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):K?t.jsx(R,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},k.id)})]})]})]})},Bt={docker:"docker",windows:"windows",ubuntu:"ubuntu-fill",arch:"arch-linux",nixos:"nixos",fedora:"fedora",debian:"debian",centos:"centos-fill",linux:"terminal-box",darwin:"apple",unknown:"server"};function _n(e){return e?.deploymentKind==="docker"?{name:Bt.docker,color:"#2496ED"}:e?.serverPlatform==="win32"?{name:Bt.windows,color:"#0078D4"}:e?.serverPlatform==="linux"?e.serverDistribution==="ubuntu"?{name:Bt.ubuntu,color:"#E95420"}:e.serverDistribution==="arch"?{name:Bt.arch,color:"#1793D1"}:e.serverDistribution==="nixos"?{name:Bt.nixos,color:"#5277C3"}:e.serverDistribution==="fedora"?{name:Bt.fedora,color:"#51A2DA"}:e.serverDistribution==="debian"?{name:Bt.debian,color:"#A81D33"}:e.serverDistribution==="centos"?{name:Bt.centos,color:"#932279"}:{name:Bt.linux}:e?.serverPlatform==="darwin"?{name:Bt.darwin}:{name:Bt.unknown}}const Mm=e=>e?.deploymentKind==="docker"?"Docker":e?.serverPlatform==="win32"?"Windows":e?.serverPlatform==="darwin"?"macOS":e?.serverPlatform==="linux"?typeof e.serverDistribution=="string"&&e.serverDistribution.trim()?{ubuntu:"Ubuntu",arch:"Arch Linux",nixos:"NixOS",fedora:"Fedora",debian:"Debian",centos:"CentOS"}[e.serverDistribution]??"Linux":"Linux":"Server";function Tm({open:e,onOpenChange:s}){const[n,r]=i.useState(null),o=i.useCallback(async()=>{const u=qe();try{const f=await Ct("/api/version");if(!f.ok)throw new Error("Version request failed");const h=await f.json().catch(()=>null);u===qe()&&r(h)}catch{u===qe()&&r(null)}},[]);i.useEffect(()=>(o(),Ui(()=>{o()})),[o]);const a=_n(n),l=Mm(n),c=typeof n?.pichamberVersion=="string"?n.pichamberVersion:null,d=typeof window<"u"?window.location.origin:"";return t.jsxs(It,{open:e,onOpenChange:u=>{s(u),u&&o()},children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":"Show connected server information",className:$(Ws,"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5"),children:[t.jsx(R,{name:a.name,className:"h-[18px] w-[18px] shrink-0",style:a.color?{color:a.color}:void 0}),t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:"This server"})]})})}),t.jsx(Ke,{children:t.jsx("p",{children:"Connected server information"})})]}),t.jsxs(Dt,{align:"end",className:"w-80 max-w-[calc(100vw-2rem)] p-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[t.jsx(R,{name:a.name,className:"size-5 shrink-0",style:a.color?{color:a.color}:void 0}),t.jsx("div",{className:"truncate typography-ui-label font-medium text-foreground",children:l})]}),c?t.jsx("div",{className:"shrink-0 typography-micro text-muted-foreground",children:`v${c}`}):null]}),t.jsx("div",{className:"mt-3 border-t border-[var(--interactive-border)] pt-3 typography-micro",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx("span",{className:"shrink-0 text-muted-foreground",children:"Address"}),t.jsxs("button",{type:"button",className:"ml-auto flex min-w-0 items-center gap-1.5 rounded px-1 py-0.5 text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:`Copy ${d}`,"aria-label":"Copy server address",onClick:()=>{us(d).then(u=>{u.ok?oe.success("Server address copied"):oe.error("Could not copy server address")})},children:[t.jsx("span",{className:"block max-w-[30ch] truncate font-mono",children:d}),t.jsx(R,{name:"file-copy",className:"size-3.5 shrink-0 text-muted-foreground"})]})]})})]})]})}const Fm=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(It,{children:[t.jsx(Rt,{asChild:!0,children:t.jsx("button",{type:"button",className:$(Ws,"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(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),t.jsxs(Dt,{align:"end",className:"w-64",children:[t.jsx(Mc,{className:"typography-ui-header font-semibold text-foreground",children:"GitHub Accounts"}),t.jsx(Cs,{}),r.map(d=>{const u=d.user,f=!!d.current,h=d.source==="gh-cli"?"CLI":"OAuth";return t.jsxs(ot,{className:"gap-2",disabled:l,onSelect:()=>{f||c(d.id)},children:[u?.avatarUrl?t.jsx("img",{src:u.avatarUrl,alt:u.login?`${u.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(R,{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:u?.name?.trim()||u?.login||"GitHub"}),u?.login?t.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[t.jsx("span",{className:"font-mono",children:u.login}),t.jsx("span",{className:"mx-1 opacity-50",children:"·"}),t.jsx("span",{children:h})]}):null]}),f?t.jsx(R,{name:"check",className:"h-4 w-4 text-primary"}):null]},d.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(R,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"})})}),Om=i.memo(function({isDesktopApp:s,currentInstanceLabel:n,compactCurrentInstanceLabel:r,currentInstanceIsLocal:o,currentInstanceIcon:a,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,shortcutLabel:u,remoteUpdateInfo:f,remoteUpdateChecking:h,remoteUpdateError:b,onOpenRemoteUpdate:p}){return t.jsxs(It,{open:l,onOpenChange:g=>{c(g),g&&d()},children:[t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx(Rt,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":s?`Open instance, usage and MCP (current: ${n})`:"Open services, usage and MCP",className:$(Ws,s?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8"),children:[t.jsx(R,{name:a.name,className:"h-[18px] w-[18px]",style:a.color?{color:a.color}:void 0}),s?t.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:r}):null]})})}),t.jsx(Ke,{children:t.jsx("p",{children:`Current instance: ${n} (${u("toggle_services_menu")})`})})]}),t.jsx(Dt,{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:f?.available?`Version ${f.version||""} is available for this instance.`:h?"Looking for updates...":b||"This instance is up to date."})]}),f?.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:p,children:"Update"}):null]})}),t.jsx(Tc,{embedded:!0,open:l,onOpenChange:()=>{},onHostSwitched:()=>c(!1)})]}):null})]})}),Lm=({action:e,onClose:s,sessionTitle:n,onConfirm:r})=>t.jsx(Yt,{open:e!==null,onOpenChange:o=>{o||s()},children:t.jsxs(qt,{showCloseButton:!1,className:"max-w-sm gap-5",children:[t.jsxs(fs,{children:[t.jsx(es,{children:e==="delete"?"Delete session?":"Archive session?"}),t.jsx(hs,{children:e==="delete"?`"${n}" will be permanently deleted.`:`"${n}" will be archived.`})]}),t.jsxs(ks,{children:[t.jsx(Te,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),t.jsx(Te,{variant:"destructive",size:"sm",onClick:r,children:e==="delete"?"Delete":"Archive"})]})]})}),Bm=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},tn=e=>{if(!e)return"";const s=e.replace(/\\/g,"/");return s==="/"?"/":s.replace(/\/+$/,"")},_m=i.lazy(()=>cs(()=>import("./SessionSwitcherDropdown-DGvRKfRw.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}))),Bg=({onToggleLeftDrawer:e,onToggleRightDrawer:s,leftDrawerOpen:n,rightDrawerOpen:r,tabletWorkspaceTab:o,onSelectTabletWorkspaceTab:a})=>{_t("ui.header.render");const l=ce(E=>E.setSessionSwitcherOpen),c=ce(E=>E.toggleSidebar),d=ce(E=>E.isSidebarOpen),u=ce(E=>E.activeMainTab),f=ce(E=>E.setActiveMainTab),h=ce(E=>E.shortcutOverrides);ce(E=>E.timeFormatPreference),Gs();const b=De(E=>!!E.newSessionDraft?.open),p=De(E=>E.currentSessionId),g=Pi(p??""),m=Fc(p),w=i.useMemo(()=>{if(!m)return null;const E=m;return{title:m.title??null,directory:E.directory??null,created:m.time?.created??null,slug:E.slug??null,shareUrl:m.share?.url??null,parentId:m.parentID??null}},[m]),x=pt(Lr(E=>{if(!E.activeProjectId)return null;const ie=E.projects.find(ye=>ye.id===E.activeProjectId);return ie?{id:ie.id,path:ie.path,label:ie.label}:null})),I=Bs(E=>E.homeDirectory),v=i.useMemo(()=>{if(!x)return null;const E=x.label?.trim();if(E)return E;const ie=x.path.split(/[\\/]/).filter(Boolean);return ie[ie.length-1]??null},[x]),{isMobile:A}=$s(),{enabled:j}=Jr(),N=!!(j&&a&&o!==void 0),C=i.useMemo(()=>[{id:"changes",label:"Changes",icon:"git-branch"},{id:"files",label:"Files",icon:"file-text"},{id:"terminal",label:"Terminal",icon:"terminal-box"}],[]),[y,k]=i.useState(!1),D=null,M=i.useRef(null),[B,_]=i.useState(()=>typeof window>"u"?!1:Ls()),K=i.useMemo(()=>Bi(),[]),V=Oc(),[O,T]=i.useState(!1),P=i.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),U=Ti(),ne=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 ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const ye=Number.parseInt(ie[1],10),ze=Number.parseInt(ie[2],10);return Number.isNaN(ye)?null:ye===10?ze:ye},[]);Ae.useEffect(()=>{typeof window>"u"||_(Ls())},[]);const W=ce(E=>E.isSessionSwitcherOpen),G=null,Ne=null,ee=[],[Fe,_e]=i.useState(!1),[q,F]=i.useState(!1),[z,Q]=i.useState("Local"),[se,Se]=i.useState(!0),[ge,we]=i.useState(()=>_n(null)),[re,ae]=i.useState(!1),[H,me]=i.useState(null),[Ue,L]=i.useState(!1),[X,ue]=i.useState(null),fe=i.useRef(0),je=i.useMemo(()=>Bm(z),[z]),Re=i.useCallback(async()=>{if(typeof window>"u"||!B)return;const E=qe(),ie=()=>qe()===E;try{const ye=await Ct("/api/version");if(!ie())return;const ze=ye.ok?await ye.json().catch(()=>null):null;if(!ie())return;if(we(_n(ze)),zn()){Q("Local"),Se(!0);return}Se(!1);const bt=await hd();if(!ie())return;const Qe=pd(),os=md([gd(Qe),...bt.hosts]);if(os.id===bd){Q("Local"),Se(!0);return}Q(xd(os.label.trim()||"Instance"))}catch{ie()&&(Q("Local"),Se(!0),we(_n(null)))}},[B]);Ae.useEffect(()=>(Re(),Ui(()=>{fe.current+=1,me(null),ue(null),L(!1),ae(!1),Re()})),[Re]);const be=i.useCallback(async()=>{const E=fe.current+1;fe.current=E;const ie=qe(),ye=()=>fe.current===E&&qe()===ie;if(se){me(null),ue(null);return}L(!0),ue(null);try{const ze=new URLSearchParams({appType:"web",instanceMode:"remote"}),bt=await Ct(`/api/pi/update-check?${ze.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!bt.ok)throw new Error(`Server responded with ${bt.status}`);const Qe=await bt.json();if(!ye())return;me({available:Qe.available??!1,version:Qe.version,currentVersion:Qe.currentVersion??"unknown",body:Qe.body,nextSuggestedCheckInSec:typeof Qe.nextSuggestedCheckInSec=="number"?Qe.nextSuggestedCheckInSec:void 0,packageManager:Qe.packageManager,updateCommand:Qe.updateCommand,channel:Qe.channel==="rc"?"rc":"stable"})}catch(ze){if(!ye())return;me(null),ue(ze instanceof Error?ze.message:"Failed to check remote instance updates")}finally{ye()&&L(!1)}},[se]);i.useEffect(()=>Ku(()=>{se||be()}),[be,se]),i.useEffect(()=>{fe.current+=1,me(null),ue(null),L(!1),ae(!1)},[se,z]),i.useEffect(()=>{if(!B||se)return;const E=3e3,ie=3600*1e3;let ye=!1,ze=null;const bt=Qe=>{ze=window.setTimeout(()=>{if(ye||typeof document<"u"&&document.visibilityState!=="visible"){bt(ie);return}be().finally(()=>{ye||bt(ie)})},Qe)};return bt(E),()=>{ye=!0,ze!==null&&window.clearTimeout(ze)}},[be,se,z,B]);const Z=i.useCallback(()=>{if(H?.available){ae(!0);return}be()},[be,H?.available]),pe=p?w??null:null,le=i.useRef(null),[Le,He]=i.useState(0);i.useEffect(()=>{if(!p){le.current&&(le.current=null,He(ze=>ze+1));return}if(pe){le.current={sessionId:p,session:pe,expiresAt:Date.now()+2e3};return}const E=le.current;if(!E||E.sessionId!==p)return;const ie=E.expiresAt-Date.now();if(ie<=0){le.current=null,He(ze=>ze+1);return}const ye=window.setTimeout(()=>{le.current?.sessionId===p&&(le.current=null),He(ze=>ze+1)},ie);return()=>{window.clearTimeout(ye)}},[p,pe]);const Ee=(()=>{if(pe)return pe;if(!p)return null;const E=le.current;return E&&E.sessionId===p&&E.expiresAt>Date.now()?E.session:null})(),Pe=i.useMemo(()=>{const E=typeof Ee?.directory=="string"?Ee.directory:"";return tn(E||"")},[Ee?.directory]),te=De(E=>E.newSessionDraft?.open?tn(E.newSessionDraft.directoryOverride??""):""),Ce=i.useMemo(()=>cm({sessionDirectory:Pe,draftDirectory:te,isNewSessionDraftOpen:b}),[te,b,Pe]),vt=Ei(Ce||null),Je=i.useMemo(()=>dm({activeProjectLabel:v,openDirectory:Ce,homeDirectory:I}),[v,I,Ce]),et=!!(Je||vt),Et=i.useMemo(()=>p?ds(Ee):Je??"PiChamber",[Ee,p,Je]),kt=Lc(),ts=De(E=>E.updateSessionTitle),mt=De(E=>E.archiveSessions),at=De(E=>E.deleteSessions),[Xe,lt]=i.useState(!1),[Ut,ss]=i.useState(!1),wt=i.useRef(!1),[ve,Oe]=i.useState(""),[xe,Me]=i.useState(null),Ye=i.useRef(null);i.useEffect(()=>{wt.current=!1,ss(!1),lt(!1),Oe(""),Me(null)},[p]);const ct=i.useCallback(()=>{p&&(Oe(Ee?.title?.trim()||Et),lt(!0))},[Ee?.title,p,Et]),St=i.useCallback(async()=>{if(!p)return;const E=ve.trim();E&&E!==Ee?.title?.trim()&&await ts(p,E),lt(!1)},[Ee?.title,p,ve,ts]);i.useEffect(()=>{if(!Xe)return;const E=ie=>{const ye=ie.target;(!ye||!Ye.current?.contains(ye))&&St()};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[Xe,St]);const zt=i.useCallback(()=>{p&&us(p).then(E=>{oe[E.ok?"success":"error"](E.ok?"Session ID copied":"Failed to copy session ID")}).catch(()=>oe.error("Failed to copy session ID"))},[p]),ps=i.useCallback(async()=>{if(!p||!Ce){oe.error("Nothing to export");return}try{await kt.syncSession(p)}catch{oe.error("Failed to load the complete session history");return}const E=[];if(E.length===0){oe.error("Nothing to export");return}const ie=Fa(E,Ee?.title??null),ye=Ba(Ee?.title??null);await La(ie,ye)||Oa(ie,ye),oe.success("Session exported")},[Ee?.title,p,Ce,kt]);g?.type==="busy"||g?.type;const Pt=i.useCallback(async()=>{if(!p||!xe)return;const E=Bc(),ie=[p];for(let Qe=0;Qe<ie.length;Qe+=1){const os=ie[Qe];for(const xt of E)xt.parentID===os&&!ie.includes(xt.id)&&ie.push(xt.id)}const ye=xe;if(Me(null),(ye==="archive"?await mt(ie):await at(ie)).failedIds.length>0){oe.error(ye==="archive"?"Failed to archive session":"Failed to delete session");return}oe.success(ye==="archive"?"Session archived":"Session deleted")},[mt,p,at,xe]),tt=ce(E=>E.isArchivePageOpen),Mt=i.useMemo(()=>tt?{title:"Archive",subtitle:null}:null,[tt]),Ze=i.useMemo(()=>tn(Ce||x?.path||""),[x?.path,Ce]),Qt=i.useCallback(()=>{Ze&&us(Ze).then(E=>{oe[E.ok?"success":"error"](E.ok?"Working directory copied":"Failed to copy working directory")}).catch(()=>oe.error("Failed to copy working directory"))},[Ze]),$t=i.useMemo(()=>x?{id:x.id,path:x.path}:null,[x]),Ns=i.useRef(null);i.useEffect(()=>{!$t||!Ze||(Ns.current={projectRef:$t,directory:Ze})},[Ze,$t]);const Tt=i.useMemo(()=>$t&&Ze?{projectRef:$t,directory:Ze}:Ns.current,[Ze,$t]),Hs=i.useCallback(async E=>{},[]),dt=i.useCallback(()=>{if(typeof document>"u")return;const E=document.activeElement;if(!E)return;const ie=E.tagName;(ie==="INPUT"||ie==="TEXTAREA"||ie==="SELECT"||E.isContentEditable)&&E.blur()},[]),ms=i.useCallback(()=>{if(A){dt(),l(!W);return}c()},[dt,A,W,l,c]),gt=i.useCallback(()=>{ln("desktop_open_draft_mini_chat_window",{directory:tn(Ce||x?.path||""),projectId:x?.id??null,apiBaseUrl:Mr(),clientToken:Pr()}).catch(E=>{console.warn("[header] failed to open draft mini chat window",E)})},[x?.id,x?.path,Ce]),de=i.useCallback(()=>{if(b){gt();return}p&&ln("desktop_open_session_mini_chat_window",{sessionId:p,directory:tn(Ce||x?.path||""),apiBaseUrl:Mr(),clientToken:Pr()}).catch(E=>{console.warn("[header] failed to open session mini chat window",E)})},[x?.path,p,gt,b,Ce]),nt=Ws,st=gf,ut=i.useMemo(()=>n?"sessions":N?r&&o?o:null:r?"git":u,[u,N,n,r,o]),Gt=i.useCallback(()=>{n&&e&&e(),r&&s&&s(),!e&&W&&l(!1)},[W,n,e,s,r,l]),ft=i.useCallback(()=>{e?.()},[e]),Xn=i.useCallback(()=>{s?.()},[s]),Ys=i.useMemo(()=>B&&P&&!O?"5.5rem":V?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":!B||U?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[B,O,P,V,U]);Ae.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Ys)},[Ys]);const xn=d?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Is=d?"0px":B&&U?"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)":j?"2.75rem":"2.5rem";Ae.useEffect(()=>{if(!B||!P){T(!1);return}let E=!1;const ie=async()=>{try{const ze=await ln("desktop_is_window_fullscreen");E||T(ze===!0)}catch{E||T(!1)}},ye=()=>{ie()};return ie(),window.addEventListener("pichamber:window-resized",ye),()=>{E=!0,window.removeEventListener("pichamber:window-resized",ye)}},[B,P]);const yn=i.useMemo(()=>!B||!P||ne===null?"":ne>=26?"h-12":ne<=15?"h-14":"",[B,P,ne]),Zn=i.useMemo(()=>{if(!(B&&!U))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))"}},[B,U]),ns=i.useCallback(()=>{if(typeof document>"u")return;const E=M.current?.getBoundingClientRect().height;E&&document.documentElement.style.setProperty("--oc-header-height",`${E}px`)},[]);Ae.useEffect(()=>{if(typeof window>"u")return;ns();const E=M.current;if(!E||typeof ResizeObserver>"u")return()=>{};let ie=0;const ye=()=>{ie||(ie=requestAnimationFrame(()=>{ie=0,ns()}))},ze=new ResizeObserver(ye);return ze.observe(E),window.addEventListener("resize",ye),window.addEventListener("orientationchange",ye),()=>{ie&&cancelAnimationFrame(ie),ze.disconnect(),window.removeEventListener("resize",ye),window.removeEventListener("orientationchange",ye)}},[ns]),Ae.useEffect(()=>{ns()},[ns,A,yn]);const qs=i.useCallback(async E=>{const ie=E.target;ie.closest(".app-region-no-drag")||ie.closest("button, a, input, select, textarea")||E.button===0&&B&&await _c()},[B]),Ft=i.useMemo(()=>A?[{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"}]:[],[A]),er=i.useCallback(E=>to(Un(E,h)),[h]);Ae.useEffect(()=>{!A&&u!=="chat"&&u!=="terminal"&&u!=="diagram"&&f("chat")},[u,A,f]),Ae.useEffect(()=>{const E=ie=>{if(yd(ie)&&!ie.shiftKey&&!ie.altKey){const ye=parseInt(ie.key,10);ye>=1&&ye<=Ft.length&&(ie.preventDefault(),A&&(dt(),Gt()),f(Ft[ye-1].id))}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[dt,Gt,A,f,Ft]),Ae.useEffect(()=>{const E=ie=>{const ye=Un("toggle_services_menu",h);if(vd(ie,ye)){ie.preventDefault(),q?F(!1):(F(!0),Re());return}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[h,q,Re]);const tr=E=>{const ie=u===E.id,ye=E.icon==="diff",ze=ye?null:E.icon,bt=E.id==="chat",Qe=xt=>ye?t.jsx(gi,{size:xt}):ze?t.jsx(R,{name:ze,className:`h-${xt/4} w-${xt/4}`}):null,os=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",ie?"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",bt&&!A&&"min-w-[100px] justify-center"),"aria-label":E.label,"aria-selected":ie,role:"tab",children:[A?Qe(20):t.jsxs(t.Fragment,{children:[Qe(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:os},E.id)},Qs=t.jsxs(t.Fragment,{children:[t.jsx(pm,{directory:Ze,className:"mr-1"}),B?t.jsx(Om,{isDesktopApp:B,currentInstanceLabel:z,compactCurrentInstanceLabel:je,currentInstanceIsLocal:se,currentInstanceIcon:ge,isDesktopServicesOpen:q,setIsDesktopServicesOpen:F,refreshCurrentInstanceLabel:Re,shortcutLabel:er,remoteUpdateInfo:H,remoteUpdateChecking:Ue,remoteUpdateError:X,onOpenRemoteUpdate:Z}):t.jsx(Tm,{open:q,onOpenChange:F}),t.jsx(Fm,{isMobile:A,githubAuthStatus:D,githubAccounts:ee,githubAvatarUrl:G,githubLogin:Ne,isSwitchingGitHubAccount:Fe,handleGitHubAccountSwitch:Hs})]}),Vs=K&&(b||!!p),vn=()=>t.jsxs("div",{onMouseDown:qs,className:$("app-region-drag relative flex h-12 select-none items-center pr-3",yn),style:Zn,role:"tablist","aria-label":"Main navigation",children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:xn}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Is}}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Mt?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:Mt.title}),Mt.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:Mt.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:[d?null:t.jsx(i.Suspense,{fallback:t.jsx("button",{type:"button",className:nt,"aria-label":"Open session switcher",children:t.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})}),children:t.jsx(_m,{align:"start",children:t.jsx("button",{type:"button",className:nt,"aria-label":"Open session switcher",children:t.jsx(R,{name:"history",className:"h-[18px] w-[18px]"})})})}),t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 px-1",children:[Xe?t.jsxs("form",{ref:Ye,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:E=>{E.preventDefault(),St()},children:[t.jsx("input",{value:ve,onChange:E=>Oe(E.target.value),autoFocus:!0,onKeyDown:E=>{E.stopPropagation(),E.key==="Escape"&<(!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(R,{name:"check",className:"size-4"})}),t.jsx("button",{type:"button",onClick:()=>lt(!1),"aria-label":"Cancel renaming session",title:"Cancel renaming session",className:"shrink-0 text-muted-foreground hover:text-foreground",children:t.jsx(R,{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":Et}),et?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:[Je?t.jsx("span",{className:"truncate",children:Je}):null,vt?t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[t.jsx(R,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),t.jsx("span",{className:"truncate",children:vt})]}):null]})]}):null]}),t.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-center",children:p&&!b&&!Xe?t.jsxs(It,{open:Ut,onOpenChange:ss,onOpenChangeComplete:E=>{!E&&wt.current&&(wt.current=!1,ct())},children:[t.jsx(Rt,{asChild:!0,children:t.jsx(Te,{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(R,{name:"more",className:"size-4"})})}),t.jsxs(Dt,{align:"end",className:"min-w-[190px]",children:[t.jsxs(ot,{onClick:()=>{wt.current=!0},children:[t.jsx(R,{name:"pencil-ai",className:"mr-2 size-4"}),"Rename"]}),t.jsxs(ot,{onClick:zt,children:[t.jsx(R,{name:"file-copy",className:"mr-2 size-4"}),"Copy session ID"]}),t.jsxs(ot,{onClick:Qt,disabled:!Ze,children:[t.jsx(R,{name:"folder",className:"mr-2 size-4"}),"Copy working directory"]}),t.jsx(Cs,{}),t.jsxs(ot,{onClick:()=>{ps()},children:[t.jsx(R,{name:"download",className:"mr-2 size-4"}),"Export Markdown"]}),t.jsx(Cs,{}),t.jsxs(ot,{onClick:()=>Me("archive"),children:[t.jsx(R,{name:"inbox-archive",className:"mr-2 size-4"}),"Archive"]}),t.jsxs(ot,{className:"text-destructive focus:text-destructive",onClick:()=>Me("delete"),children:[t.jsx(R,{name:"delete-bin",className:"mr-2 size-4"}),"Delete"]})]})]}):null})]}),Ft.length>0&&t.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ft.map(E=>tr(E))}),t.jsx("div",{className:"flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(Sa,{}),Tt?t.jsx(yi,{projectRef:Tt.projectRef,directory:Tt.directory,className:"mr-1"}):null,t.jsx(bf,{visible:Vs,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:de,className:$(nt,"mr-1"),Icon:"picture-in-picture-2"}),Qs,t.jsx(Uc,{visible:U})]})]})]}),rs=()=>t.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[j&&t.jsxs(t.Fragment,{children:[t.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch",style:{width:xn}}),t.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch",style:{width:Is}})]}),!j&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e?t.jsx("button",{type:"button",onClick:ft,className:$(st,ut==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":n?"Close sessions":"Open sessions",children:t.jsx(R,{name:"layout-left",className:"h-5 w-5"})}):W?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(R,{name:"arrow-left-s",className:"h-5 w-5"})}):t.jsx("button",{type:"button",onClick:ms,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(R,{name:"play-list-add",className:"h-5 w-5"})}),!e&&W&&t.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:"Sessions"})]}),(!W||!!e)&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:!N&&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:Ft.map(E=>{const ie=u===E.id,ye=E.icon==="diff",ze=ye?null:E.icon;return t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsxs("button",{type:"button",onClick:()=>{A&&(dt(),Gt()),f(E.id)},"aria-label":E.label,"aria-selected":ie,role:"tab",className:$(st,"relative rounded-lg",ut===E.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[ye?t.jsx(gi,{className:"h-5 w-5"}):ze?t.jsx(R,{name:ze,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(Ke,{children:t.jsx("p",{children:E.label})})]},E.id)})})})})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[N&&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:C.map(E=>{const ie=r&&o===E.id;return t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:()=>{A&&(dt(),Gt()),k(!1),a?.(E.id)},"aria-label":E.label,"aria-selected":ie,role:"tab",className:$(st,"relative rounded-lg",ie&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(R,{name:E.icon,className:"h-5 w-5"})})}),t.jsx(Ke,{children:t.jsx("p",{children:E.label})})]},E.id)})}),t.jsx(mf,{open:y,onOpenChange:k,currentSessionId:p,effectiveDirectory:Ce||null,isNewSessionDraftOpen:b})]}),Tt&&t.jsx(yi,{projectRef:Tt.projectRef,directory:Tt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s&&!N?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:Xn,className:$(st,"relative",ut==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:t.jsx(R,{name:"layout-right",className:"h-5 w-5"})})}),t.jsx(Ke,{children:t.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Js=$("header-safe-area relative z-10 bg-background",A&&"border-b border-border/50");return t.jsxs(t.Fragment,{children:[t.jsx("header",{ref:M,className:Js,style:{"--padding-scale":"1"},children:A?rs():vn()}),t.jsx(Lm,{action:xe,onClose:()=>Me(null),sessionTitle:Et,onConfirm:()=>{Pt()}}),t.jsx(ha,{open:re,onOpenChange:ae,info:H,downloading:!1,downloaded:!1,progress:null,error:X,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})},vi="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",Um="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",_g=()=>{const e=ce(p=>p.isSidebarOpen),s=ce(p=>p.toggleSidebar),n=ce(p=>p.shortcutOverrides),r=i.useRef(null),o=i.useRef(null),a=to(Un("toggle_sidebar",n)),l=Ti(),{enabled:c}=Jr(),d=!e,u=l,f=d||u,h=u,b=i.useCallback(()=>{ln("desktop_show_app_menu").catch(p=>{console.warn("[titlebar] failed to open app menu",p)})},[]);return i.useEffect(()=>{if(typeof document>"u")return;const p=v=>{document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(v)}px`)},g=v=>{document.documentElement.style.setProperty("--oc-titlebar-overlay-width",`${Math.round(v)}px`)};if(!h)return;const m=o.current,w=r.current;if(!m||!w){p(0),g(0);return}const x=()=>{const v=Math.max(m.getBoundingClientRect().width,m.scrollWidth);p(v),g(w.getBoundingClientRect().width)};if(x(),typeof ResizeObserver>"u")return;const I=new ResizeObserver(x);return I.observe(m),I.observe(w),()=>{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:[u?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:b,"aria-label":"Open PiChamber menu",className:$(vi,"shrink-0"),children:t.jsx(R,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),t.jsx(Ke,{children:t.jsx("p",{children:"PiChamber menu"})})]}):null,d?t.jsxs($e,{children:[t.jsx(Ge,{asChild:!0,children:t.jsx("button",{type:"button",onClick:s,"aria-label":"Open sessions",className:$(c?Um:vi,"shrink-0"),children:t.jsx(R,{name:"layout-left",className:c?"size-[18px]":"h-[18px] w-[18px]"})})}),t.jsx(Ke,{children:t.jsx("p",{children:`Open sessions (${a})`})})]}):null]})}):null},wi=200,zm="cubic-bezier(0.22, 1, 0.36, 1)",Ug=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 d=window.requestAnimationFrame(()=>{c=window.requestAnimationFrame(()=>r(!0))});return()=>{window.cancelAnimationFrame(d),window.cancelAnimationFrame(c)}}r(!1);const l=window.setTimeout(()=>a(!1),wi);return()=>window.clearTimeout(l)},[e,s]),{slidIn:n,layoutVisible:o,prefersReducedMotion:s,transition:s?"none":`transform ${wi}ms ${zm}`}},zg=()=>{zi()},$g=e=>{De.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),ce.getState().prepareForRuntimeSwitch(e.previousRuntimeKey),he.getState().clearAll(),zi(),Bs.getState().resetForRuntimeSwitch(),zc.getState().resetForRuntimeSwitch(),$c.getState().resetForRuntimeSwitch(),Gc(),Kc.getState().resetForRuntimeSwitch(),Wt.setState({providers:[],isConnected:!1,isInitialized:!1,connectionPhase:"connecting",lastDisconnectReason:null}),pt.getState().resetForRuntimeSwitch(),Wc(),Hc(),Xd.getState().reset(),wd.getState().resetForRuntimeSwitch(),Ri.getState().resetForRuntimeSwitch(e.runtimeKey),Dr.getState().resetForRuntimeSwitch(e.runtimeKey),js.getState().resetForRuntimeSwitch(e.runtimeKey),Zf.getState().resetForRuntimeSwitch(),ht.getState().resetForRuntimeSwitch(e.runtimeKey),Sd.getState().resetForRuntimeSwitch(e.runtimeKey),De.getState().restoreForRuntimeSwitch(e.runtimeKey),ce.getState().restoreForRuntimeSwitch(e.runtimeKey);const s=ce.getState();_r({sessionId:De.getState().currentSessionId,tab:s.activeMainTab,isSettingsOpen:s.isSettingsDialogOpen,settingsPath:s.settingsPage,diffFile:s.pendingDiffFile},{replace:!0,force:!0})};export{lf as $,Dg as A,Lg as B,Rg as C,ci as D,yu as E,dg as F,ag as G,Bg as H,gs as I,lu as J,bs as K,ug as L,wa as M,zu as N,jg as O,Ou as P,hg as Q,Ig as R,Eg as S,Fg as T,vg as U,ha as V,ig as W,ro as X,xg as Y,Uu as Z,ga as _,mf as a,Fu as a0,$u as a1,gn as a2,pa as a3,bn as a4,cn as a5,Lu as a6,pg as a7,Bu as a8,Sg as a9,Ag as aa,kg as ab,Gu as ac,wg as ad,Cg as ae,Ng as af,fg as ag,mg as ah,gg as ai,bg as aj,sf as ak,yg as al,wu as am,_u as an,Su as ao,rg as ap,sn as b,bp as c,Pg as d,Ln as e,Ug as f,Mg as g,Og as h,vp as i,_g as j,$g as k,lg as l,cg as m,og as n,ng as o,oo as p,io as q,zg as r,Tg as s,ao as t,hf as u,Os as v,va as w,cf as x,df as y,Yo as z};
|