@pi-chamber/web 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/lib/cli-paths.js +22 -6
- package/dist/assets/{DiagramEditor-DoEOH0hY.js → DiagramEditor-DuGmiPZ5.js} +1 -1
- package/dist/assets/{DiagramView-y9Ystuhv.js → DiagramView-CV-iReyY.js} +1 -1
- package/dist/assets/{DiffView-ScM4XoqZ.js → DiffView-DVd1MLPB.js} +1 -1
- package/dist/assets/{FilesView-CjkhMFqJ.js → FilesView-CPnW4I90.js} +1 -1
- package/dist/assets/{GitView-Bqi6H8I-.js → GitView-Dj_7hgX_.js} +3 -3
- package/dist/assets/{JsonTreeView-DWhlH6NK.js → JsonTreeView-Cyy0lEZR.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CEOKZ1qH.js → MarkdownRendererImpl-BXN78Wu_.js} +1 -1
- package/dist/assets/{PatchDiff-ClnfJJ2J.js → PatchDiff-C7dA3U29.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-e6JzUXD_.js → SessionSwitcherContent-dr3g9DR7.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-C4etG8dv.js → SessionSwitcherDropdown-C3zdd82V.js} +2 -2
- package/dist/assets/{SessionUnreadDot-BVTSwRiG.js → SessionUnreadDot-qeik5qtT.js} +1 -1
- package/dist/assets/{SettingsView-C0S0Sx-S.js → SettingsView-C57uV1YS.js} +2 -2
- package/dist/assets/{SettingsWindow-Cy9tmnMg.js → SettingsWindow-Bbay2W76.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Csrc0Uk2.js → ToolOutputDialog-CRTiN1CH.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-6oH6KD44.js → ToolPartDiffPreview-CqnNcLPk.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DJNcTQNp.js → VirtualizedFileDiff-iqwryMNU.js} +1 -1
- package/dist/assets/{collapsible-DxgVLhi9.js → collapsible-szfZ0Syc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-B-WoeBMW.js → computeVirtualFileMetrics-Bbugxxtp.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DQ4U9xRH.js → contextFileOpenGuard-BC3ie230.js} +1 -1
- package/dist/assets/{gitStatusPredicates-CIFSGjJs.js → gitStatusPredicates-DbThKVSf.js} +1 -1
- package/dist/assets/{index-D2C3q2xD.js → index-KIdiBFJs.js} +1 -1
- package/dist/assets/{index-DmNPBaSo.js → index-v6K3L94m.js} +1 -1
- package/dist/assets/{isDiffPlainText-CrvpUauF.js → isDiffPlainText-Dl0RBjPZ.js} +1 -1
- package/dist/assets/{isFilePlainText-CKvhS32g.js → isFilePlainText-CbrmvrM6.js} +1 -1
- package/dist/assets/{main-CjM7g4Gq.js → main-4PkIvzf4.js} +3 -3
- package/dist/assets/{main-BFv8slLp.js → main-DMyWi0qs.js} +2 -2
- package/dist/assets/{markdownCore-DKrraAqT.js → markdownCore-BD5WkOKU.js} +1 -1
- package/dist/assets/{miniChat-hQnLS5mt.js → miniChat-CLMNhna4.js} +2 -2
- package/dist/assets/{mobile-DuXOBGs_.js → mobile-rWMDwhtQ.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-ClJBZVGy.js → renderElectronMiniChatApp-BRhGNRJ8.js} +2 -2
- package/dist/assets/{renderMobileApp-DofX2wjB.js → renderMobileApp-DLy2YoQg.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-BZeYg6eN.js → runtimeEndpointReset-Z9YtcHxZ.js} +15 -15
- package/dist/assets/{runtimeSurface-C7CBxDbh.js → runtimeSurface-CySRuLbN.js} +1 -1
- package/dist/assets/{useAppFontEffects-Cs0f1dKn.js → useAppFontEffects-DfuJVB15.js} +85 -85
- package/dist/assets/{useFilesViewSearch-D1hcbBEc.js → useFilesViewSearch-BZBHrZ90.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-DqHkuVS5.js → usePushVisibilityBeacon-BxTkEajM.js} +1 -1
- package/dist/assets/{useSwitcherItems-BEoW7LlC.js → useSwitcherItems-jITqE8PV.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B8Ac62S_.js → vendor-codemirror-language-data-CDdfwzlS.js} +2 -2
- package/dist/assets/{web-components-Dy-Tz_LJ.js → web-components-C9wXMuCp.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +2 -2
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/server/lib/pi/routes.js +35 -1
- package/server/lib/pi/routes.test.js +53 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +4 -4
- package/server/lib/pi/session-daemon/ipc-client.js +20 -9
- package/server/lib/pi/session-daemon/ipc-client.test.js +88 -0
- package/server/lib/pi/session-daemon/ipc-protocol.js +9 -0
- package/server/lib/pi/session-daemon/session-daemon.js +127 -26
- package/server/lib/pi/session-daemon/session-daemon.test.js +141 -0
- package/server/lib/pi/ui-settings-store.js +130 -25
- package/server/lib/pi/ui-settings-store.test.js +58 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-
|
|
2
|
-
import{R as r,j as e,r as Ce,e as Fn}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{u as ee,c as ce,r as tt,q as en,H as Bn,F as tn,R as nn,h as zn,E as Un,M as Hn,a3 as Re,N as Vn,O as Kn,J as Te,K as Xn,a4 as qn,a5 as Gn,a6 as Et,a7 as Ve,f as Yn,d as Jn,v as Qn,b as Zn,l as er,a8 as rn,w as sn,a9 as tr,aa as nr,ab as rr,a2 as sr,z as or,j as on,x as ar}from"./index-D2C3q2xD.js";import{_ as Ee}from"./vendor-vite-runtime-DD1OZmLC.js";import{o as ir,C as lr,a as cr,b as dr,c as ur,d as hr,T as an,B as pr,E as fr,G as mr,p as gr,z as xr,x as wr,y as yr,H as Tt,r as _t,A as Dt,S as At,q as br,v as vr,w as jr,F as Sr,W as Cr}from"./runtimeEndpointReset-BZeYg6eN.js";import{b8 as st,I as q,a9 as Ne,bU as ot,k as Se,t as je,bV as kr,a4 as ge,aA as nt,bz as ln,b5 as mt,D as Nr,S as Oe,U as $e,a as Pr,V as We,b as Rr,A as gt,bo as Er,bp as Tr,j as xt,aF as Ge,ba as cn,bi as Mt,as as _r,aU as wt,aV as yt,bk as bt,bl as vt,bm as jt,bn as Dr,aR as Ar,bt as Mr,_ as Ir,bc as dn,Z as Ie,bW as Ke,bX as un,bY as hn,aX as Lr,bZ as ht,b_ as Or,b$ as De,b9 as pn,c0 as $r,c1 as St,c2 as Wr,a0 as fn,a7 as Fr,c3 as Br,c4 as zr,c5 as It,u as Ur,d as Hr,e as Vr,c6 as Kr,c as Lt,s as Xr,r as at,bd as qr,c7 as Gr,f as Yr,c8 as Jr,c9 as Qr,ca as Zr,cb as es,cc as Ue,cd as He,ce as ts,ak as ns,al as rs,ab as ss,aa as os,ad as as,a8 as is,bR as ls,ac as cs,ae as ds,af as us,ai as hs,aj as ps}from"./useAppFontEffects-Cs0f1dKn.js";import{v as mn,g as gn}from"./contextFileOpenGuard-DQ4U9xRH.js";import{g as xn,l as fs,e as ms,f as gs,h as xs,u as ws}from"./useFilesViewSearch-D1hcbBEc.js";import{c as wn,d as pt,P as ys,D as yn,e as bn,f as bs,T as vs,M as js}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{S as vn,h as Ss,u as jn,a as Cs,v as ks}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as Sn}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import{g as Cn}from"./SessionUnreadDot-BVTSwRiG.js";import{u as Ot,a as Ye,m as $t}from"./vendor-framer-motion-CfplGuM0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-C7CBxDbh.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B8Ac62S_.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";const Ns=280,Wt=4,Ps=({transform:t})=>({...t,y:0}),Rs=({id:t,children:n,className:s})=>{const{attributes:a,listeners:o,setNodeRef:m,transform:x,transition:u,isDragging:p}=jn({id:t});return e.jsx("div",{ref:m,"data-sortable-tab-id":t,style:{transform:Sn.Transform.toString(x),transition:u},className:ce("h-full rounded-md",s,p&&"opacity-50"),...a,...o,children:n})},Es=({id:t,children:n,className:s})=>e.jsx("div",{className:ce("h-full",s),"data-sortable-tab-id":t,children:n}),Ts=({items:t,activeId:n,onSelect:s,onClose:a,onReorder:o,layoutMode:m="scrollable",variant:x="default",activePillInsetClassName:u,activePillButtonClassName:p,inactiveTabsIconOnly:g=!1,animateActivePill:v,activePillLowercase:f=!0,nonCompositedIndicator:l=!1,className:T})=>{const c=ee(k=>k.isMobile),{isTablet:S}=st(),j=c||S,P=r.useRef(null),[R,O]=r.useState({left:!1,right:!1}),te=r.useMemo(()=>t.map(k=>k.id),[t]),F=m==="scrollable",re=x==="default",z=x==="active-pill",b=z||x==="animated",G=re,H=b||G,$=z&&F,V=b,ne=v??b,E=typeof o=="function",Q=E?Rs:Es,C=r.useRef(new Map),[M,U]=r.useState(null),[L,K]=r.useState(!1),[se,he]=r.useState(null),ue=r.useRef(!1),be=r.useRef(0),fe=r.useRef(n),xe=r.useRef(null),pe=r.useMemo(()=>{if(!H||!se||!n||se===n)return 0;const k=t.findIndex(ie=>ie.id===se),Y=t.findIndex(ie=>ie.id===n);return k<0||Y<0?0:k>Y?Wt:-Wt},[n,t,se,H]),I=wn(pt(ys,{activationConstraint:{distance:8}})),W=r.useCallback((k,Y)=>!k||!Y?k===Y:Math.abs(k.left-Y.left)<.5&&Math.abs(k.top-Y.top)<.5&&Math.abs(k.width-Y.width)<.5&&Math.abs(k.height-Y.height)<.5,[]),w=r.useCallback((k,Y)=>{if(Y){C.current.set(k,Y);return}C.current.delete(k)},[]),A=r.useCallback(()=>{if(!H||!n){U(J=>J===null?J:null);return}const k=P.current,Y=C.current.get(n);if(!k||!Y){U(J=>J===null?J:null);return}let ie=0,_=0,oe=Y;for(;oe&&oe!==k;)ie+=oe.offsetLeft,_+=oe.offsetTop,oe=oe.offsetParent;const ae={left:ie,top:_,width:Y.offsetWidth,height:Y.offsetHeight};U(J=>W(J,ae)?J:ae)},[n,W,H]),X=r.useCallback(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k){O({left:!1,right:!1});return}O({left:k.scrollLeft>2,right:k.scrollLeft+k.clientWidth<k.scrollWidth-2})},[F]);r.useEffect(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k)return;X(),k.addEventListener("scroll",X,{passive:!0});const Y=new ResizeObserver(X);return Y.observe(k),()=>{k.removeEventListener("scroll",X),Y.disconnect()}},[F,t.length,X]),r.useEffect(()=>{if(!H){U(null);return}A();const k=P.current;if(!k)return;const Y=new ResizeObserver(()=>{performance.now()-be.current>Ns&&K(!1),A()});if(Y.observe(k),n){const ie=C.current.get(n);ie&&Y.observe(ie)}return()=>{Y.disconnect()}},[n,t.length,A,H]),r.useLayoutEffect(()=>{A()});const de=te.join("\0");r.useLayoutEffect(()=>{if(!H){ue.current=!1,K(!1);return}const k=xe.current!==de;if(xe.current=de,!ue.current){ue.current=!0,fe.current=n;return}const Y=fe.current!==n;if(fe.current=n,!Y||k){K(!1);return}be.current=performance.now(),K(!0)},[n,de,H]),r.useEffect(()=>{if(!F||!n)return;const k=P.current;if(!k)return;const Y=window.requestAnimationFrame(()=>{const ie=typeof window.CSS?.escape=="function"?window.CSS.escape(n):n.replace(/"/g,'\\"'),_=k.querySelector(`[data-sortable-tab-id="${ie}"]`);_&&(_.scrollIntoView({block:"nearest",inline:"nearest"}),X())});return()=>{window.cancelAnimationFrame(Y)}},[n,F,t.length,X]);const me=r.useCallback(k=>{if(!o)return;const{active:Y,over:ie}=k;!ie||Y.id===ie.id||o(String(Y.id),String(ie.id))},[o]),we=e.jsxs("div",{className:ce("relative flex h-full min-w-0 flex-1",T),children:[F&&R.left?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,F&&R.right?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e.jsxs("div",{ref:P,className:ce("relative flex h-full min-w-0 flex-1",b?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",b&&"@container/pill-tabs",b&&"pill-tabs__track",b&&(u??"gap-0.5 py-0.5"),G&&"items-center overflow-y-hidden",V&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_4%,transparent)] p-0.5 gap-0.5",F?"overflow-x-auto scrollbar-none":"overflow-x-hidden"),style:F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,role:"tablist","aria-label":"Tabs",children:[b&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-[color-mix(in_srgb,var(--foreground)_7%,transparent)]","shadow-[0_1px_2px_color-mix(in_srgb,var(--foreground)_10%,transparent),0_2px_6px_color-mix(in_srgb,var(--foreground)_6%,transparent)]",ne&&L&&(l?"pill-tabs__indicator--is-animated-layout":"pill-tabs__indicator--is-animated")),style:l?{left:`${M.left+pe}px`,top:`${M.top}px`,width:`${M.width}px`,height:`${M.height}px`}:{transform:`translate3d(${M.left+pe}px, ${M.top}px, 0)`,width:`${M.width}px`,height:`${M.height}px`}}):null,G&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",L&&"underline-tabs__indicator--is-animated"),style:{transform:`translate3d(${M.left+pe}px, 0, 0)`,width:`${M.width}px`},"aria-hidden":!0}):null,t.map(k=>{const Y=k.id===n,ie=g&&b&&!Y&&!!k.icon,_=!ie,oe=!!k.icon,ae=g&&b&&Y&&!F&&!$,J=k.closable!==!1&&!!a,B=J&&!!k.icon,h=F||$?void 0:b?ae?"flex-none basis-auto":c?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",i=J?N=>{N.button===1&&(N.preventDefault(),N.stopPropagation(),a?.(k.id))}:void 0,D=J?N=>{N.button===1&&N.preventDefault()}:void 0,d=N=>oe?e.jsxs("span",{className:N,children:[e.jsx("span",{className:ce("flex items-center justify-center transition-opacity",B&&(j?"opacity-0":"group-hover:opacity-0")),children:k.icon}),B?e.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",j?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:le=>le.stopPropagation(),onClick:le=>{le.stopPropagation(),a?.(k.id)},"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null;return e.jsx(Q,{id:k.id,className:h,children:e.jsxs("div",{ref:N=>w(k.id,N),onAuxClick:i,onMouseDown:D,className:ce("group flex h-full min-w-0 flex-nowrap items-center",F||$?"shrink-0":b?"w-full":"w-full min-w-0",b?"relative z-10 bg-transparent":Y?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y,"aria-label":ie?k.title??k.label:void 0,onClick:()=>s(k.id),onPointerDown:H?()=>{K(!0),he(k.id)}:void 0,onPointerUp:H?()=>he(null):void 0,onPointerLeave:H?()=>he(null):void 0,onPointerCancel:H?()=>he(null):void 0,className:ce(b?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",b&&f?"lowercase":null,b&&(ie?"gap-0":"gap-1.5"),b?$?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":ie?"px-2 !min-w-0 text-center":ae?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",b?p??(z?c?"h-[38px]":"h-[31px]":"h-7"):null,b?Y?"text-foreground":"text-muted-foreground hover:text-foreground":null,b?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:k.title??k.label,children:b?e.jsxs(e.Fragment,{children:[d("relative flex h-4 w-4 shrink-0 items-center justify-center"),_?e.jsx("span",{className:"animated-tabs__label truncate",children:k.label}):null]}):e.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[d(ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Y?"text-[var(--primary-base)]":"text-muted-foreground")),e.jsx("span",{className:"truncate leading-[1.2]",children:k.label})]})}),J&&!B?e.jsx("button",{type:"button",onPointerDown:N=>{N.stopPropagation()},onClick:N=>{N.stopPropagation(),a?.(k.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",b?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",b?Y?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Y?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3 w-3"})}):null]})},k.id)})]})]});return E?e.jsxs(yn,{sensors:I,collisionDetection:bn,onDragEnd:me,modifiers:[Ps],children:[e.jsx(vn,{items:te,strategy:Ss,children:we}),e.jsx(bs,{dropAnimation:null})]}):we},Ft=280,Bt=280,zt=500,_s=({isOpen:t,isMobile:n,children:s,className:a,topBar:o})=>{const m=ee(y=>y.sidebarWidth),x=ee(y=>y.setSidebarWidth),[u,p]=r.useState(!1),g=r.useRef(0),v=r.useRef(m||Ft),f=r.useRef(null),l=r.useRef(null),T=r.useRef(null),c=r.useCallback(y=>Math.min(zt,Math.max(Bt,y)),[]),S=r.useCallback(y=>{const b=T.current;b&&(b.style.width=`${y}px`,b.style.minWidth=`${y}px`,b.style.maxWidth=`${y}px`,b.style.setProperty("--oc-left-sidebar-width",`${y}px`))},[]);r.useEffect(()=>{n&&u&&p(!1)},[n,u]),r.useEffect(()=>{u||(f.current=null,l.current=null)},[u]);const j=ir(t);if(n)return null;const P=Math.min(zt,Math.max(Bt,m||Ft)),R=j.layoutVisible?P:0,O=y=>{if(t){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{}l.current=y.pointerId,p(!0),g.current=y.clientX,v.current=R,f.current=R,S(R),y.preventDefault()}},te=y=>{if(n||!u||l.current!==y.pointerId)return;const b=y.clientX-g.current,G=c(v.current+b);f.current!==G&&(f.current=G,S(G))},F=y=>{if(l.current!==y.pointerId||n)return;try{y.currentTarget.releasePointerCapture(y.pointerId)}catch{}const b=c(f.current??R);l.current=null,f.current=null,p(!1),x(b)},re=u?f.current??R:R,z=u?re:R;return e.jsxs("aside",{ref:T,className:ce("relative flex h-full overflow-hidden motion-reduce:transition-none","bg-sidebar",a),style:{width:`${z}px`,minWidth:`${z}px`,maxWidth:`${z}px`,"--oc-left-sidebar-width":`${u?re:P}px`,overflowX:"clip",transform:u||j.slidIn?"translateX(0)":"translateX(-100%)",transition:u?"none":j.transition},"aria-hidden":!t||z===0,children:[t&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&e.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:O,onPointerMove:te,onPointerUp:F,onPointerCancel:F,role:"separator","aria-orientation":"vertical","aria-label":"Resize left panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full shrink-0 flex-col",u&&"pointer-events-none",!t&&"pointer-events-none select-none"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(Ne,{children:s})})]})]})},Ds=t=>{if(!t||typeof t!="object")return!1;const n=t;return typeof n.x=="number"&&typeof n.y=="number"},Ut=t=>!t||typeof t!="object"?!1:Object.values(t).every(n=>typeof n=="string"),Be=t=>{if(!t||typeof t!="object")return!1;const n=t,s=n.bounds;return typeof n.tag=="string"&&typeof n.text=="string"&&typeof n.selector=="string"&&typeof n.path=="string"&&!!s&&typeof s?.x=="number"&&typeof s?.y=="number"&&typeof s?.width=="number"&&typeof s?.height=="number"&&Ds(n.center)&&Ut(n.attributes)&&Ut(n.computedStyle)&&Array.isArray(n.ancestry)},Ct=({pageUrl:t,viewport:n,devicePixelRatio:s,target:a,screenshotAttached:o,intro:m})=>{const x=a.text.trim(),u=Object.entries(a.attributes).map(([T,c])=>`${T}="${c}"`).join(" "),p=a.computedStyle,g=a.bounds,v=a.center,f=m.replace(/[.:]+$/g,""),l=a.ancestry.map(T=>T.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${n.width}x${n.height}, DPR ${s}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${a.tag}`,x?`Text: ${x}`:null,`- Selector: ${a.selector}`,`- Path: ${a.path}`,l?`- Ancestry: ${l}`:null,u?`- Attributes: ${u}`:null,`- Bounds: x=${Math.round(g.x)}, y=${Math.round(g.y)}, width=${Math.round(g.width)}, height=${Math.round(g.height)}`,`- Center: x=${Math.round(v.x)}, y=${Math.round(v.y)}`,`Styles: display=${p.display}; position=${p.position}; font=${p.fontWeight} ${p.fontSize} / ${p.lineHeight} ${p.fontFamily}; color=${p.color}; background=${p.backgroundColor}; z-index=${p.zIndex}`].filter(T=>typeof T=="string").join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-DVd1MLPB.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-KIdiBFJs.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-DNoEeZ2U.css","assets/useAppFontEffects-DfuJVB15.js","assets/vendor-base-ui-vkqQ2P9o.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-CySRuLbN.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-CDdfwzlS.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/gitStatusPredicates-DbThKVSf.js","assets/web-components-C9wXMuCp.js","assets/computeVirtualFileMetrics-Bbugxxtp.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/VirtualizedFileDiff-iqwryMNU.js","assets/isDiffPlainText-Dl0RBjPZ.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-Z9YtcHxZ.js","assets/SessionUnreadDot-qeik5qtT.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/contextFileOpenGuard-BC3ie230.js","assets/FilesView-CPnW4I90.js","assets/DiagramEditor-DuGmiPZ5.js","assets/vendor-react-drawio-BYDptOsj.js","assets/useFilesViewSearch-BZBHrZ90.js","assets/JsonTreeView-Cyy0lEZR.js","assets/Virtualizer-BSHVMKgK.js","assets/isFilePlainText-CbrmvrM6.js","assets/vendor-codemirror-search-BV44140v.js","assets/vendor-replit-codemirror-vim-CGHHNQxC.js","assets/GitView-Dj_7hgX_.js","assets/collapsible-szfZ0Syc.js","assets/DiagramView-CV-iReyY.js","assets/SettingsView-C57uV1YS.js","assets/vendor-qrcode-B0KNSajT.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/SettingsWindow-Bbay2W76.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as r,j as e,r as Ce,e as Fn}from"./vendor-react-B5Z1Mdn3.js";import"./vendor-katex-CNckGUMB.js";import{u as ee,c as ce,r as tt,q as en,H as Bn,F as tn,R as nn,h as zn,E as Un,M as Hn,a3 as Re,N as Vn,O as Kn,J as Te,K as Xn,a4 as qn,a5 as Gn,a6 as Et,a7 as Ve,f as Yn,d as Jn,v as Qn,b as Zn,l as er,a8 as rn,w as sn,a9 as tr,aa as nr,ab as rr,a2 as sr,z as or,j as on,x as ar}from"./index-KIdiBFJs.js";import{_ as Ee}from"./vendor-vite-runtime-DD1OZmLC.js";import{o as ir,C as lr,a as cr,b as dr,c as ur,d as hr,T as an,B as pr,E as fr,G as mr,p as gr,z as xr,x as wr,y as yr,H as Tt,r as _t,A as Dt,S as At,q as br,v as vr,w as jr,F as Sr,W as Cr}from"./runtimeEndpointReset-Z9YtcHxZ.js";import{b8 as st,I as q,a9 as Ne,bU as ot,k as Se,t as je,bV as kr,a4 as ge,aA as nt,bz as ln,b5 as mt,D as Nr,S as Oe,U as $e,a as Pr,V as We,b as Rr,A as gt,bo as Er,bp as Tr,j as xt,aF as Ge,ba as cn,bi as Mt,as as _r,aU as wt,aV as yt,bk as bt,bl as vt,bm as jt,bn as Dr,aR as Ar,bt as Mr,_ as Ir,bc as dn,Z as Ie,bW as Ke,bX as un,bY as hn,aX as Lr,bZ as ht,b_ as Or,b$ as De,b9 as pn,c0 as $r,c1 as St,c2 as Wr,a0 as fn,a7 as Fr,c3 as Br,c4 as zr,c5 as It,u as Ur,d as Hr,e as Vr,c6 as Kr,c as Lt,s as Xr,r as at,bd as qr,c7 as Gr,f as Yr,c8 as Jr,c9 as Qr,ca as Zr,cb as es,cc as Ue,cd as He,ce as ts,ak as ns,al as rs,ab as ss,aa as os,ad as as,a8 as is,bR as ls,ac as cs,ae as ds,af as us,ai as hs,aj as ps}from"./useAppFontEffects-DfuJVB15.js";import{v as mn,g as gn}from"./contextFileOpenGuard-BC3ie230.js";import{g as xn,l as fs,e as ms,f as gs,h as xs,u as ws}from"./useFilesViewSearch-BZBHrZ90.js";import{c as wn,d as pt,P as ys,D as yn,e as bn,f as bs,T as vs,M as js}from"./vendor-dnd-kit-core-C9qcAm_1.js";import{S as vn,h as Ss,u as jn,a as Cs,v as ks}from"./vendor-dnd-kit-sortable-D8ozj8M-.js";import{C as Sn}from"./vendor-dnd-kit-utilities-DTY1C6ST.js";import{g as Cn}from"./SessionUnreadDot-qeik5qtT.js";import{u as Ot,a as Ye,m as $t}from"./vendor-framer-motion-CfplGuM0.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-CySRuLbN.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CDdfwzlS.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";const Ns=280,Wt=4,Ps=({transform:t})=>({...t,y:0}),Rs=({id:t,children:n,className:s})=>{const{attributes:a,listeners:o,setNodeRef:m,transform:x,transition:u,isDragging:p}=jn({id:t});return e.jsx("div",{ref:m,"data-sortable-tab-id":t,style:{transform:Sn.Transform.toString(x),transition:u},className:ce("h-full rounded-md",s,p&&"opacity-50"),...a,...o,children:n})},Es=({id:t,children:n,className:s})=>e.jsx("div",{className:ce("h-full",s),"data-sortable-tab-id":t,children:n}),Ts=({items:t,activeId:n,onSelect:s,onClose:a,onReorder:o,layoutMode:m="scrollable",variant:x="default",activePillInsetClassName:u,activePillButtonClassName:p,inactiveTabsIconOnly:g=!1,animateActivePill:v,activePillLowercase:f=!0,nonCompositedIndicator:l=!1,className:T})=>{const c=ee(k=>k.isMobile),{isTablet:S}=st(),j=c||S,P=r.useRef(null),[R,O]=r.useState({left:!1,right:!1}),te=r.useMemo(()=>t.map(k=>k.id),[t]),F=m==="scrollable",re=x==="default",z=x==="active-pill",b=z||x==="animated",G=re,H=b||G,$=z&&F,V=b,ne=v??b,E=typeof o=="function",Q=E?Rs:Es,C=r.useRef(new Map),[M,U]=r.useState(null),[L,K]=r.useState(!1),[se,he]=r.useState(null),ue=r.useRef(!1),be=r.useRef(0),fe=r.useRef(n),xe=r.useRef(null),pe=r.useMemo(()=>{if(!H||!se||!n||se===n)return 0;const k=t.findIndex(ie=>ie.id===se),Y=t.findIndex(ie=>ie.id===n);return k<0||Y<0?0:k>Y?Wt:-Wt},[n,t,se,H]),I=wn(pt(ys,{activationConstraint:{distance:8}})),W=r.useCallback((k,Y)=>!k||!Y?k===Y:Math.abs(k.left-Y.left)<.5&&Math.abs(k.top-Y.top)<.5&&Math.abs(k.width-Y.width)<.5&&Math.abs(k.height-Y.height)<.5,[]),w=r.useCallback((k,Y)=>{if(Y){C.current.set(k,Y);return}C.current.delete(k)},[]),A=r.useCallback(()=>{if(!H||!n){U(J=>J===null?J:null);return}const k=P.current,Y=C.current.get(n);if(!k||!Y){U(J=>J===null?J:null);return}let ie=0,_=0,oe=Y;for(;oe&&oe!==k;)ie+=oe.offsetLeft,_+=oe.offsetTop,oe=oe.offsetParent;const ae={left:ie,top:_,width:Y.offsetWidth,height:Y.offsetHeight};U(J=>W(J,ae)?J:ae)},[n,W,H]),X=r.useCallback(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k){O({left:!1,right:!1});return}O({left:k.scrollLeft>2,right:k.scrollLeft+k.clientWidth<k.scrollWidth-2})},[F]);r.useEffect(()=>{if(!F){O({left:!1,right:!1});return}const k=P.current;if(!k)return;X(),k.addEventListener("scroll",X,{passive:!0});const Y=new ResizeObserver(X);return Y.observe(k),()=>{k.removeEventListener("scroll",X),Y.disconnect()}},[F,t.length,X]),r.useEffect(()=>{if(!H){U(null);return}A();const k=P.current;if(!k)return;const Y=new ResizeObserver(()=>{performance.now()-be.current>Ns&&K(!1),A()});if(Y.observe(k),n){const ie=C.current.get(n);ie&&Y.observe(ie)}return()=>{Y.disconnect()}},[n,t.length,A,H]),r.useLayoutEffect(()=>{A()});const de=te.join("\0");r.useLayoutEffect(()=>{if(!H){ue.current=!1,K(!1);return}const k=xe.current!==de;if(xe.current=de,!ue.current){ue.current=!0,fe.current=n;return}const Y=fe.current!==n;if(fe.current=n,!Y||k){K(!1);return}be.current=performance.now(),K(!0)},[n,de,H]),r.useEffect(()=>{if(!F||!n)return;const k=P.current;if(!k)return;const Y=window.requestAnimationFrame(()=>{const ie=typeof window.CSS?.escape=="function"?window.CSS.escape(n):n.replace(/"/g,'\\"'),_=k.querySelector(`[data-sortable-tab-id="${ie}"]`);_&&(_.scrollIntoView({block:"nearest",inline:"nearest"}),X())});return()=>{window.cancelAnimationFrame(Y)}},[n,F,t.length,X]);const me=r.useCallback(k=>{if(!o)return;const{active:Y,over:ie}=k;!ie||Y.id===ie.id||o(String(Y.id),String(ie.id))},[o]),we=e.jsxs("div",{className:ce("relative flex h-full min-w-0 flex-1",T),children:[F&&R.left?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,F&&R.right?e.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",b?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e.jsxs("div",{ref:P,className:ce("relative flex h-full min-w-0 flex-1",b?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",b&&"@container/pill-tabs",b&&"pill-tabs__track",b&&(u??"gap-0.5 py-0.5"),G&&"items-center overflow-y-hidden",V&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_4%,transparent)] p-0.5 gap-0.5",F?"overflow-x-auto scrollbar-none":"overflow-x-hidden"),style:F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,role:"tablist","aria-label":"Tabs",children:[b&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-[color-mix(in_srgb,var(--foreground)_7%,transparent)]","shadow-[0_1px_2px_color-mix(in_srgb,var(--foreground)_10%,transparent),0_2px_6px_color-mix(in_srgb,var(--foreground)_6%,transparent)]",ne&&L&&(l?"pill-tabs__indicator--is-animated-layout":"pill-tabs__indicator--is-animated")),style:l?{left:`${M.left+pe}px`,top:`${M.top}px`,width:`${M.width}px`,height:`${M.height}px`}:{transform:`translate3d(${M.left+pe}px, ${M.top}px, 0)`,width:`${M.width}px`,height:`${M.height}px`}}):null,G&&M?e.jsx("div",{className:ce("pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",L&&"underline-tabs__indicator--is-animated"),style:{transform:`translate3d(${M.left+pe}px, 0, 0)`,width:`${M.width}px`},"aria-hidden":!0}):null,t.map(k=>{const Y=k.id===n,ie=g&&b&&!Y&&!!k.icon,_=!ie,oe=!!k.icon,ae=g&&b&&Y&&!F&&!$,J=k.closable!==!1&&!!a,B=J&&!!k.icon,h=F||$?void 0:b?ae?"flex-none basis-auto":c?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",i=J?N=>{N.button===1&&(N.preventDefault(),N.stopPropagation(),a?.(k.id))}:void 0,D=J?N=>{N.button===1&&N.preventDefault()}:void 0,d=N=>oe?e.jsxs("span",{className:N,children:[e.jsx("span",{className:ce("flex items-center justify-center transition-opacity",B&&(j?"opacity-0":"group-hover:opacity-0")),children:k.icon}),B?e.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",j?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:le=>le.stopPropagation(),onClick:le=>{le.stopPropagation(),a?.(k.id)},"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null;return e.jsx(Q,{id:k.id,className:h,children:e.jsxs("div",{ref:N=>w(k.id,N),onAuxClick:i,onMouseDown:D,className:ce("group flex h-full min-w-0 flex-nowrap items-center",F||$?"shrink-0":b?"w-full":"w-full min-w-0",b?"relative z-10 bg-transparent":Y?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Y,"aria-label":ie?k.title??k.label:void 0,onClick:()=>s(k.id),onPointerDown:H?()=>{K(!0),he(k.id)}:void 0,onPointerUp:H?()=>he(null):void 0,onPointerLeave:H?()=>he(null):void 0,onPointerCancel:H?()=>he(null):void 0,className:ce(b?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",b&&f?"lowercase":null,b&&(ie?"gap-0":"gap-1.5"),b?$?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":ie?"px-2 !min-w-0 text-center":ae?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",b?p??(z?c?"h-[38px]":"h-[31px]":"h-7"):null,b?Y?"text-foreground":"text-muted-foreground hover:text-foreground":null,b?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:k.title??k.label,children:b?e.jsxs(e.Fragment,{children:[d("relative flex h-4 w-4 shrink-0 items-center justify-center"),_?e.jsx("span",{className:"animated-tabs__label truncate",children:k.label}):null]}):e.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[d(ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Y?"text-[var(--primary-base)]":"text-muted-foreground")),e.jsx("span",{className:"truncate leading-[1.2]",children:k.label})]})}),J&&!B?e.jsx("button",{type:"button",onPointerDown:N=>{N.stopPropagation()},onClick:N=>{N.stopPropagation(),a?.(k.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",b?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",b?Y?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Y?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":k.closeLabel??`Close ${k.label} tab`,title:k.closeLabel??`Close ${k.label} tab`,children:e.jsx(q,{name:"close",className:"h-3 w-3"})}):null]})},k.id)})]})]});return E?e.jsxs(yn,{sensors:I,collisionDetection:bn,onDragEnd:me,modifiers:[Ps],children:[e.jsx(vn,{items:te,strategy:Ss,children:we}),e.jsx(bs,{dropAnimation:null})]}):we},Ft=280,Bt=280,zt=500,_s=({isOpen:t,isMobile:n,children:s,className:a,topBar:o})=>{const m=ee(y=>y.sidebarWidth),x=ee(y=>y.setSidebarWidth),[u,p]=r.useState(!1),g=r.useRef(0),v=r.useRef(m||Ft),f=r.useRef(null),l=r.useRef(null),T=r.useRef(null),c=r.useCallback(y=>Math.min(zt,Math.max(Bt,y)),[]),S=r.useCallback(y=>{const b=T.current;b&&(b.style.width=`${y}px`,b.style.minWidth=`${y}px`,b.style.maxWidth=`${y}px`,b.style.setProperty("--oc-left-sidebar-width",`${y}px`))},[]);r.useEffect(()=>{n&&u&&p(!1)},[n,u]),r.useEffect(()=>{u||(f.current=null,l.current=null)},[u]);const j=ir(t);if(n)return null;const P=Math.min(zt,Math.max(Bt,m||Ft)),R=j.layoutVisible?P:0,O=y=>{if(t){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{}l.current=y.pointerId,p(!0),g.current=y.clientX,v.current=R,f.current=R,S(R),y.preventDefault()}},te=y=>{if(n||!u||l.current!==y.pointerId)return;const b=y.clientX-g.current,G=c(v.current+b);f.current!==G&&(f.current=G,S(G))},F=y=>{if(l.current!==y.pointerId||n)return;try{y.currentTarget.releasePointerCapture(y.pointerId)}catch{}const b=c(f.current??R);l.current=null,f.current=null,p(!1),x(b)},re=u?f.current??R:R,z=u?re:R;return e.jsxs("aside",{ref:T,className:ce("relative flex h-full overflow-hidden motion-reduce:transition-none","bg-sidebar",a),style:{width:`${z}px`,minWidth:`${z}px`,maxWidth:`${z}px`,"--oc-left-sidebar-width":`${u?re:P}px`,overflowX:"clip",transform:u||j.slidIn?"translateX(0)":"translateX(-100%)",transition:u?"none":j.transition},"aria-hidden":!t||z===0,children:[t&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&e.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",u&&"bg-[var(--interactive-border)]"),onPointerDown:O,onPointerMove:te,onPointerUp:F,onPointerCancel:F,role:"separator","aria-orientation":"vertical","aria-label":"Resize left panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full shrink-0 flex-col",u&&"pointer-events-none",!t&&"pointer-events-none select-none"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(Ne,{children:s})})]})]})},Ds=t=>{if(!t||typeof t!="object")return!1;const n=t;return typeof n.x=="number"&&typeof n.y=="number"},Ut=t=>!t||typeof t!="object"?!1:Object.values(t).every(n=>typeof n=="string"),Be=t=>{if(!t||typeof t!="object")return!1;const n=t,s=n.bounds;return typeof n.tag=="string"&&typeof n.text=="string"&&typeof n.selector=="string"&&typeof n.path=="string"&&!!s&&typeof s?.x=="number"&&typeof s?.y=="number"&&typeof s?.width=="number"&&typeof s?.height=="number"&&Ds(n.center)&&Ut(n.attributes)&&Ut(n.computedStyle)&&Array.isArray(n.ancestry)},Ct=({pageUrl:t,viewport:n,devicePixelRatio:s,target:a,screenshotAttached:o,intro:m})=>{const x=a.text.trim(),u=Object.entries(a.attributes).map(([T,c])=>`${T}="${c}"`).join(" "),p=a.computedStyle,g=a.bounds,v=a.center,f=m.replace(/[.:]+$/g,""),l=a.ancestry.map(T=>T.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${n.width}x${n.height}, DPR ${s}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${a.tag}`,x?`Text: ${x}`:null,`- Selector: ${a.selector}`,`- Path: ${a.path}`,l?`- Ancestry: ${l}`:null,u?`- Attributes: ${u}`:null,`- Bounds: x=${Math.round(g.x)}, y=${Math.round(g.y)}, width=${Math.round(g.width)}, height=${Math.round(g.height)}`,`- Center: x=${Math.round(v.x)}, y=${Math.round(v.y)}`,`Styles: display=${p.display}; position=${p.position}; font=${p.fontWeight} ${p.fontSize} / ${p.lineHeight} ${p.fontFamily}; color=${p.color}; background=${p.backgroundColor}; z-index=${p.zIndex}`].filter(T=>typeof T=="string").join(`
|
|
3
3
|
`)},Pe=new Map,As=3e4,kt=t=>{const n=Pe.get(t);return n?n.expiresAt-Date.now()<=As?(Pe.delete(t),null):n:null},Ms=t=>{try{return new URL(t).origin}catch{return t}},ze="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",it=new Map;function kn(t){const n="#ffffff",s=t.defaultView??window;try{const a=t.body?s.getComputedStyle(t.body).backgroundColor:"";if(a&&a!=="rgba(0, 0, 0, 0)"&&a!=="transparent")return a;const o=s.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return n}const Nn=t=>new Promise((n,s)=>{const a=new FileReader;a.onloadend=()=>n(typeof a.result=="string"?a.result:ze),a.onerror=()=>s(a.error??new Error("Failed to read image blob")),a.readAsDataURL(t)}),Is=async(t,n=.82)=>{const s=await new Promise(a=>t.toBlob(a,"image/jpeg",n));return s&&(await Nn(s)).split(",",2)[1]||""},lt=async(t,n)=>{try{const s=await fetch(t,{credentials:n});return s.ok?await Nn(await s.blob()):null}catch{return null}},Ls=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const n=t.origin,s=kt(n);if(s)return`${s.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const a=it.get(n),o=a??(async()=>{try{const x=await tt("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!x.ok)return Pe.delete(n),null;const u=await x.json(),p=typeof u.proxyBasePath=="string"?u.proxyBasePath:"",g=typeof u.expiresAt=="number"?u.expiresAt:0;if(!p)return Pe.delete(n),null;const v={proxyBasePath:p,expiresAt:g};return Pe.set(n,v),v}catch{return Pe.delete(n),null}finally{it.delete(n)}})();a||it.set(n,o);const m=await o;return m?`${m.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Pn=async(t,n)=>{if(!t||t.startsWith("data:"))return t;try{const s=new URL(t,n.baseURI);if(s.origin===window.location.origin||s.protocol!=="http:"&&s.protocol!=="https:")return await lt(s.toString(),"include")??ze;const a=await Ls(s),o=a?await lt(a,"include"):null;return o||(await lt(s.toString(),"omit")??ze)}catch{return ze}},Os=async(t,n)=>{if(!t||t==="none"||!t.includes("url("))return t;const s=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let a=t;for(const o of s){const m=o[2]||"";if(!m||m.startsWith("data:"))continue;const x=await Pn(m,n);a=a.replace(o[0],`url("${x}")`)}return a},Ht=t=>t.complete?Promise.resolve():new Promise(n=>{t.addEventListener("load",()=>n(),{once:!0}),t.addEventListener("error",()=>n(),{once:!0})}),Rn=t=>{const n=t.style.cssText;return()=>{t.style.cssText=n}},$s=t=>{const n=Number.parseFloat(t.lineHeight);if(Number.isFinite(n)&&n>0)return n;const s=Number.parseFloat(t.fontSize);return Number.isFinite(s)&&s>0?s*1.2:16},Ws=(t,n,s)=>{const a=[],o=t.defaultView??window,x=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const u of x){const p=u.textContent?.replace(/\s+/g," ").trim()??"";if(!p||!p.includes(" "))continue;const g=u.getBoundingClientRect();if(g.width<=0||g.height<=0||g.right<0||g.bottom<0||g.left>n||g.top>s)continue;const v=o.getComputedStyle(u);if(v.display==="none"||v.visibility==="hidden"||Number(v.opacity)===0)continue;const f=v.getPropertyValue("text-wrap"),l=v.getPropertyValue("text-wrap-mode"),T=v.whiteSpace.includes("nowrap")||f==="nowrap"||l==="nowrap",c=g.height<=$s(v)*1.7;!T&&(!c||g.width>n*.72)||(a.push(Rn(u)),u.style.whiteSpace="nowrap",u.style.overflowWrap="normal",u.style.wordBreak="normal",u.style.setProperty("text-wrap","nowrap"),u.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let u=a.length-1;u>=0;u-=1)a[u]?.()}},Fs=(t,n,s,a)=>{const o=[],m=t.defaultView??window,x=m.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,u=m.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,p=Array.from(t.querySelectorAll("*")).filter(g=>{const v=m.getComputedStyle(g);if(v.position!=="fixed"||v.display==="none"||v.visibility==="hidden"||Number(v.opacity)===0)return!1;const f=g.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=n&&f.top<=s}).filter((g,v,f)=>!f.some((l,T)=>T<v&&l.contains(g)));for(const g of p){const v=g.getBoundingClientRect(),f=m.getComputedStyle(g),l=Math.ceil(v.width)+8,T=Math.ceil(v.height)+2;a?.add(g),o.push(Rn(g)),g.style.position="absolute",g.style.top=`${v.top+u}px`,g.style.left=`${v.left+x}px`,g.style.right="auto",g.style.bottom="auto",g.style.width=`${l}px`,g.style.minWidth=`${l}px`,g.style.height=`${T}px`,g.style.minHeight=`${T}px`,g.style.margin="0",g.style.boxSizing="border-box",g.style.transform="none",f.zIndex!=="auto"&&(g.style.zIndex=f.zIndex)}return()=>{for(let g=o.length-1;g>=0;g-=1)o[g]?.()}},En=async(t,n,s,a={})=>{const o=[],m=t.defaultView??window,x=f=>{if(f===t.documentElement||f===t.body)return!0;try{const l=f.getBoundingClientRect();return l.width>0&&l.height>0&&l.right>=0&&l.bottom>=0&&l.left<=n&&l.top<=s}catch{return!1}};if(a.applyLayoutWorkarounds){const f=new WeakSet;o.push(Fs(t,n,s,f)),o.push(Ws(t,n,s))}const u=new Map;for(const f of Array.from(t.images))u.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const p=Array.from(t.querySelectorAll("picture"));for(const f of p){const l=Array.from(f.querySelectorAll("source"));if(l.length===0)continue;const T=l.map(c=>({source:c,srcset:c.getAttribute("srcset"),sizes:c.getAttribute("sizes")}));o.push(()=>{for(const c of T)c.srcset===null?c.source.removeAttribute("srcset"):c.source.setAttribute("srcset",c.srcset),c.sizes===null?c.source.removeAttribute("sizes"):c.source.setAttribute("sizes",c.sizes)});for(const c of l)c.removeAttribute("srcset"),c.removeAttribute("sizes")}const g=Array.from(t.images).filter(f=>x(f));await Promise.all(g.map(async f=>{const l=u.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!l)return;await Ht(f);const T=await Pn(l,t),c={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{c.src===null?f.removeAttribute("src"):f.setAttribute("src",c.src),c.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",c.srcset),c.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",c.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",T||ze),await Ht(f)}));const v=Array.from(t.querySelectorAll("*")).filter(x);return await Promise.all(v.map(async f=>{const l=m.getComputedStyle(f).backgroundImage;if(!l||l==="none"||!l.includes("url("))return;const T=await Os(l,t);if(T===l)return;const c=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=c}),f.style.backgroundImage=T})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}},Bs=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Qe=(...t)=>{Bs()&&console.info("[preview-capture]",...t)},Tn=(t,n=8)=>{const s=[];try{const a=t.querySelectorAll("*");for(const o of a){const m=o.scrollTop||0,x=o.scrollLeft||0;if(m<=0&&x<=0)continue;const u=o.tagName.toLowerCase(),p=o.id?`#${o.id}`:"",g=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(s.push({selector:`${u}${p}${g}`,scrollTop:m,scrollLeft:x,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),s.length>=n)break}}catch{}return s},Xe="data-oc-fixed-pin",zs=(t,n,s)=>{if(n<=0&&s<=0)return()=>{};const a=t.defaultView;if(!a)return()=>{};const o=[],m=[];try{for(const x of t.querySelectorAll("*")){if(a.getComputedStyle(x).position!=="fixed")continue;const u=x.getBoundingClientRect();if(!(u.width>0&&u.height>0))continue;x.setAttribute(Xe,JSON.stringify({top:u.top+s,left:u.left+n,width:u.width,height:u.height})),o.push(x);const p=x.tagName.toLowerCase(),g=typeof x.className=="string"&&x.className?`.${x.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";m.push({selector:`${p}${g}`,top:Math.round(u.top),left:Math.round(u.left),width:Math.round(u.width),height:Math.round(u.height)})}}catch{}return Qe("tagged fixed elements",m),()=>{for(const x of o)try{x.removeAttribute(Xe)}catch{}}},Us={name:"oc-fixed-pin",afterClone(t){const n=t?.clone;if(!(!n||typeof n.querySelectorAll!="function"))for(const s of n.querySelectorAll(`[${Xe}]`)){let a;try{a=JSON.parse(s.getAttribute(Xe)||"")}catch{continue}s.style.setProperty("position","absolute","important"),s.style.setProperty("top",`${a.top}px`,"important"),s.style.setProperty("left",`${a.left}px`,"important"),s.style.setProperty("right","auto","important"),s.style.setProperty("bottom","auto","important"),s.style.setProperty("width",`${a.width}px`,"important"),s.style.setProperty("height",`${a.height}px`,"important"),s.removeAttribute(Xe)}}},Fe="data-oc-scroll-pin",Hs=t=>{const n=[],s=Tn(t,64);try{const m=t.documentElement,x=t.body;for(const u of t.querySelectorAll("*")){const p=u.scrollTop||0,g=u.scrollLeft||0;if(p<=0&&g<=0)continue;const v=u!==m&&u!==x;v&&u.setAttribute(Fe,JSON.stringify({top:p,left:g})),n.push({el:u,top:p,left:g,tagged:v})}}catch{}return{reapply:()=>{for(const m of n)try{m.el.scrollHeight,m.el.scrollTop!==m.top&&(m.el.scrollTop=m.top),m.el.scrollLeft!==m.left&&(m.el.scrollLeft=m.left)}catch{}},cleanup:()=>{for(const m of n)if(m.tagged)try{m.el.removeAttribute(Fe)}catch{}},snapshot:s}},Vs={name:"oc-nested-scroll",afterClone(t){const n=t?.clone;if(!n||typeof n.querySelectorAll!="function")return;const s=n.ownerDocument;if(s)for(const a of n.querySelectorAll(`[${Fe}]`)){let o;try{o=JSON.parse(a.getAttribute(Fe)||"")}catch{a.removeAttribute(Fe);continue}const m=`translate(${-o.left}px, ${-o.top}px)`,x=a.children.length===1&&a.firstElementChild instanceof HTMLElement&&a.firstElementChild.style.willChange==="transform"?a.firstElementChild:null;if(x)x.style.transform=m;else{a.style.overflow="hidden";const u=s.createElement("div");for(u.style.transform=m,u.style.willChange="transform",u.style.display="inline-block",u.style.width="100%";a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u)}a.removeAttribute(Fe)}}},_n=async(t,n)=>{if(typeof window<"u")try{const s=t.getBoundingClientRect(),a=await en("desktop_capture_page_rect",{x:s.left,y:s.top,width:s.width,height:s.height});if(!a)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((c,S)=>{o.onload=()=>c(),o.onerror=()=>S(new Error("Failed to load desktop preview screenshot")),o.src=`data:${a.mime};base64,${a.base64}`});const m=Math.max(1,o.naturalWidth||a.width||Math.floor(s.width)),x=Math.max(1,o.naturalHeight||a.height||Math.floor(s.height)),p=Math.min(1,1200/m),g=document.createElement("canvas");g.width=Math.floor(m*p),g.height=Math.floor(x*p);const v=g.getContext("2d");if(!v)return null;v.scale(p,p),v.drawImage(o,0,0,m,x);const f=m/Math.max(1,s.width),l=x/Math.max(1,s.height);v.fillStyle="rgba(37, 99, 235, 0.28)",v.strokeStyle="rgb(37, 99, 235)",v.lineWidth=Math.max(2,2*f),v.fillRect(n.bounds.x*f,n.bounds.y*l,n.bounds.width*f,n.bounds.height*l),v.strokeRect(n.bounds.x*f,n.bounds.y*l,n.bounds.width*f,n.bounds.height*l);const T=await new Promise(c=>g.toBlob(c,"image/jpeg",.82));return T?new File([T],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(s){return console.warn("[preview] failed to capture annotation screenshot:",s),null}return await Xs(t,n)},Nt=async(t,n,s,a,o,m)=>{if(!t)return null;try{const x=new Image;await new Promise((j,P)=>{x.onload=()=>j(),x.onerror=()=>P(new Error("Failed to load desktop browser screenshot")),x.src=`data:image/jpeg;base64,${t}`});const u=Math.max(1,x.naturalWidth||n),p=Math.max(1,x.naturalHeight||s),v=Math.min(1,1200/u),f=document.createElement("canvas");f.width=Math.floor(u*v),f.height=Math.floor(p*v);const l=f.getContext("2d");if(!l)return null;l.scale(v,v),l.drawImage(x,0,0,u,p);const T=u/Math.max(1,a||u),c=p/Math.max(1,o||p);l.fillStyle="rgba(37, 99, 235, 0.14)",l.strokeStyle="rgb(37, 99, 235)",l.lineWidth=Math.max(2,2*T),l.fillRect(m.bounds.x*T,m.bounds.y*c,m.bounds.width*T,m.bounds.height*c),l.strokeRect(m.bounds.x*T,m.bounds.y*c,m.bounds.width*T,m.bounds.height*c);const S=await new Promise(j=>f.toBlob(j,"image/jpeg",.82));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}};async function Ks(t,n){try{const s=t.contentWindow,a=t.contentDocument??s?.document,o=a?.documentElement;if(!s||!a||!o)return null;const m=t.getBoundingClientRect(),x=Math.max(1,Math.ceil(s.innerWidth||t.clientWidth||m.width)),u=Math.max(1,Math.ceil(s.innerHeight||t.clientHeight||m.height)),p=a.body,g=a.scrollingElement instanceof HTMLElement?a.scrollingElement:null,v=s.scrollX||0,f=s.scrollY||0,l=s.pageXOffset||0,T=s.pageYOffset||0,c=s.visualViewport?.pageLeft||s.visualViewport?.offsetLeft||0,S=s.visualViewport?.pageTop||s.visualViewport?.offsetTop||0,j=o.scrollLeft||0,P=o.scrollTop||0,R=p?.scrollLeft||0,O=p?.scrollTop||0,te=g?.scrollLeft||0,F=g?.scrollTop||0,re=Math.max(v,l,c,j,R,te),z=Math.max(f,T,S,P,O,F);Qe("scroll sources",{windowScrollX:v,windowScrollY:f,pageScrollX:l,pageScrollY:T,visualViewportScrollX:c,visualViewportScrollY:S,rootScrollX:j,rootScrollY:P,bodyScrollX:R,bodyScrollY:O,scrollingElementScrollX:te,scrollingElementScrollY:F,scrollingElementTag:g?.tagName?.toLowerCase()??null,resolvedScrollX:re,resolvedScrollY:z,nestedScrolledElements:Tn(a)});const y=Math.max(x,o.scrollWidth||0,p?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),b=Math.max(u,o.scrollHeight||0,p?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),G=Math.min(2,Math.max(1,window.devicePixelRatio||1)),H=o.style.scrollBehavior,$=p?.style.scrollBehavior??"";o.style.scrollBehavior="auto",p&&(p.style.scrollBehavior="auto");const V=Hs(a);Qe("nested scroll snapshot",V.snapshot);let ne=()=>{},E=()=>{};try{await a.fonts?.ready.catch(()=>{}),ne=await En(a,x,u,{applyLayoutWorkarounds:!1}),s.scrollTo(re,z),E=zs(a,re,z),V.reapply();const{snapdom:Q}=await Ee(async()=>{const{snapdom:w}=await import("./vendor-zumer-snapdom-Btyu_Xi2.js");return{snapdom:w}},[]),C={backgroundColor:kn(a),cache:"disabled",dpr:G,embedFonts:!0,fast:!1,height:b,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[Us,Vs],quality:.82,width:y},U=await(await Q(o,C)).toCanvas();if(!U.width||!U.height)return null;const L=U.width/Math.max(1,y),K=U.height/Math.max(1,b),se=Math.min(U.width,Math.max(1,Math.round(x*L))),he=Math.min(U.height,Math.max(1,Math.round(u*K))),ue=Math.max(0,U.width-se),be=Math.max(0,U.height-he),fe=Math.min(ue,Math.max(0,Math.round(re*L))),xe=Math.min(be,Math.max(0,Math.round(z*K)));Qe("capture geometry",{viewportWidth:x,viewportHeight:u,captureWidth:y,captureHeight:b,canvasWidth:U.width,canvasHeight:U.height,xScale:L,yScale:K,sourceX:fe,sourceY:xe,sourceWidth:se,sourceHeight:he});const pe=a.createElement("canvas");pe.width=se,pe.height=he;const I=pe.getContext("2d");if(!I)return null;I.drawImage(U,fe,xe,se,he,0,0,se,he);const W=await Is(pe,.82);return W?await Nt(W,x,u,x,u,n):null}finally{E(),V.cleanup(),ne(),s.scrollTo(re,z),V.reapply(),o.style.scrollBehavior=H,p&&(p.style.scrollBehavior=$)}}catch(s){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",s),null}}async function Xs(t,n){const s=await Ks(t,n);if(s)return s;try{const a=t.contentWindow,o=t.contentDocument??a?.document,m=o?.documentElement;if(!a||!o||!m)return null;const x=t.getBoundingClientRect(),u=Math.max(1,Math.ceil(a.innerWidth||t.clientWidth||x.width)),p=Math.max(1,Math.ceil(a.innerHeight||t.clientHeight||x.height)),g=a.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,v=a.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,l=Math.max(p,m.scrollHeight||0,f?.scrollHeight||0),T=Math.min(2,Math.max(1,window.devicePixelRatio||1)),c=m.style.scrollBehavior,S=f?.style.scrollBehavior??"";m.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let j="",P=()=>{};try{await o.fonts?.ready.catch(()=>{}),P=await En(o,u,p,{applyLayoutWorkarounds:!0}),a.scrollTo(g,v);const{getFontEmbedCSS:O,toJpeg:te}=await Ee(async()=>{const{getFontEmbedCSS:re,toJpeg:z}=await import("./vendor-html-to-image-BeoRn2gJ.js");return{getFontEmbedCSS:re,toJpeg:z}},[]),F=await O(m).catch(()=>"");j=await te(m,{quality:.82,pixelRatio:T,width:u,height:p,backgroundColor:kn(o),imagePlaceholder:ze,fontEmbedCSS:F||void 0,style:{transform:`translate(${-g}px, ${-v}px)`,transformOrigin:"top left",minWidth:`${u}px`,minHeight:`${l}px`},cacheBust:!0})}finally{P(),a.scrollTo(g,v),m.style.scrollBehavior=c,f&&(f.style.scrollBehavior=S)}const R=j.split(",",2)[1]||"";return R?await Nt(R,u,p,u,p,n):null}catch(a){return console.warn("[preview] failed to capture iframe DOM screenshot:",a),null}}const Vt=200,qs=(t,n)=>n==="all"?!0:n==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":n==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",rt=t=>{const n=ot.getState();n.setPendingSyntheticParts([...n.pendingSyntheticParts??[],{text:t,synthetic:!0}])},Dn=async t=>{const n=await t.json().catch(()=>({}));if(!t.ok)return{ok:!1,message:typeof n.error=="string"?n.error:`HTTP ${t.status}`};const s=typeof n.proxyBasePath=="string"?n.proxyBasePath:"",a=typeof n.previewToken=="string"?n.previewToken:"";return!s||!a?{ok:!1,message:"Could not start preview proxy."}:{ok:!0,target:{proxyBasePath:s,previewToken:a,expiresAt:typeof n.expiresAt=="number"?n.expiresAt:0}}},An=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Kt=(t,n,s)=>{t.postMessage(s,An(n))},Gs=t=>{if(!t)return t;try{const n=new URL(t);return n.searchParams.delete("oc_preview_token"),n.searchParams.delete("oc_client_token"),n.searchParams.delete("oc_url_token"),n.toString()}catch{return t}},Xt=t=>{if(!t)return t;try{const n=new URL(t);return n.searchParams.delete("ocPreview"),n.searchParams.delete("oc_preview_token"),n.searchParams.delete("oc_client_token"),n.searchParams.delete("oc_url_token"),n.toString()}catch{return t}};function Mn(t){const[n,s]=r.useState("");return r.useEffect(()=>{if(!t){s("");return}let a=!1;return s(""),Bn(tn()).then(o=>{!a&&o&&s(t)}).catch(()=>{}),()=>{a=!0}},[t]),n}const In=`new Promise((resolve) => {
|
|
4
4
|
const existing = document.getElementById('__pichamber_desktop_browser_overlay');
|
|
5
5
|
if (existing) existing.remove();
|
|
@@ -132,4 +132,4 @@ ${ae.details}`:"";return`[${J}] [${ae.level}] ${ae.message}${B}`}).join(`
|
|
|
132
132
|
${J.details}`:"";return`[${B}] [${J.level}] ${J.message}${h}`}).join(`
|
|
133
133
|
`);rt(`These are browser console logs from the dev server running for this project.
|
|
134
134
|
|
|
135
|
-
${oe}${ae}`),je.success("Preview console attached to chat")},[P,z,b,K,y,t]),[W,w]=r.useState("unknown"),A=r.useRef(0),X=r.useRef(0),de=r.useRef(""),me=r.useRef(""),we=15e3;r.useEffect(()=>{if(!L){w("unknown"),de.current="",A.current=0,X.current=0;return}let _=!1,oe=null;de.current!==E&&(de.current=E,A.current=Date.now(),X.current=0);const ae=J=>{oe=setTimeout(()=>{_||o()},J)};return w("unknown"),(async()=>{const B=await(async()=>{try{return await tt(L,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(_)return;if(!B){w("unreachable"),ae(5e3);return}const h=fo(B.headers,me.current===E);if(h!=="none"){if(Pe.delete(E),h==="retry-registration")me.current=E,p({status:"loading"}),x();else{const d=await B.json().catch(()=>({}));if(_)return;const N=typeof d?.error=="string"?d.error:`HTTP ${B.status}`;p({status:"error",message:N})}return}if(B.status!==502){me.current="",w("reachable");return}const i=A.current||Date.now();if(Date.now()-i<we){w("starting"),X.current+=1;const d=X.current,N=Math.min(2e3,250*Math.pow(2,Math.min(4,d)));ae(N);return}w("unreachable"),ae(5e3)})(),()=>{_=!0,oe&&clearTimeout(oe)}},[E,L,a]);const k=$&&u.status==="ready"&&(W==="unknown"||W==="starting"),Y=$&&u.status==="ready"&&W==="unreachable",ie=r.useCallback(_=>{if(!$||u.status!=="ready"||typeof window>"u")return;const oe=_.currentTarget.contentWindow;if(oe)try{const ae=oe.location,J=An(L);if(ae.origin!==J||ae.pathname.startsWith(u.proxyBasePath))return;const B=`${u.proxyBasePath}${ae.pathname}${ae.search}${ae.hash}`;oe.location.replace(B)}catch{}},[$,L,u]);return e.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[e.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:se||t,children:se||t||"No preview URL"}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>o(),title:"Reload preview","aria-label":"Reload preview",disabled:!K,children:e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{C&&nt(C)},title:"Open in browser","aria-label":"Open in browser",disabled:!C,children:e.jsx(q,{name:"external-link",className:"h-3.5 w-3.5"})}),$?e.jsx(ge,{type:"button",size:"sm",variant:O?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>te(_=>!_),title:"Inspect preview element","aria-label":"Inspect preview element",disabled:!f,children:e.jsx(q,{name:"cursor",className:"h-3.5 w-3.5"})}):null,$?e.jsxs(ge,{type:"button",size:"sm",variant:T?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>c(_=>!_),title:f?"Open preview console":"Waiting for preview console","aria-label":f?"Open preview console":"Waiting for preview console",disabled:!f&&P.length===0,children:[e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"}),fe>0?e.jsx("span",{className:"typography-micro text-status-error",children:fe}):null]}):null]}),e.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[k?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Starting dev server..."}),e.jsx("div",{className:"text-xs opacity-70",children:"Waiting for the server to accept connections."})]}):Y?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Dev server is not responding."}),e.jsx("div",{className:"text-xs opacity-70",children:"Make sure your dev server is still running, then retry."}),e.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:()=>o(),children:"Retry"})]}):K&&(!$||W==="reachable")?e.jsxs("div",{className:"relative h-full w-full",children:[e.jsx("iframe",{ref:g,src:K,title:"Preview",className:"h-full w-full border-0",style:{colorScheme:Q},onLoad:ie,sandbox:$?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${K}:${a}`),O&&F?e.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:F.bounds.x,top:F.bounds.y,width:F.bounds.width,height:F.bounds.height},children:e.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[F.tag,F.text?` · ${F.text}`:""]})}):null]}):he?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Connecting preview proxy..."}):ue?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[e.jsx("div",{children:"Could not start preview proxy."}),u.status==="error"?e.jsx("div",{className:"text-center text-xs opacity-70",children:u.message}):null]}):e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Preview needs a valid http(s) URL."}),T?e.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[e.jsx("div",{className:"typography-ui-label text-foreground",children:"Preview console"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:I,disabled:P.length===0,children:"Attach"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:pe,disabled:P.length===0,children:"Copy"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:()=>R([]),disabled:P.length===0,children:"Clear"})]})]}),e.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(_=>e.jsx(ge,{type:"button",size:"xs",variant:S===_?"secondary":"ghost",onClick:()=>j(_),children:_==="all"?"All":_==="errors"?"Errors":_==="warnings"?"Warnings":"Logs"},_))}),e.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:P.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No preview console events yet."}):xe.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No events match this filter."}):xe.map(_=>e.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:ce("shrink-0 uppercase",_.level==="error"||_.level==="runtime"||_.level==="resource"?"text-status-error":_.level==="warn"?"text-status-warning":"text-muted-foreground"),children:_.level}),e.jsx("span",{className:"min-w-0 break-words text-foreground",children:_.message})]})},_.id))})]}):null]})]})},Rt=t=>t,ft=t=>{const n=Rt(t).type;return typeof n=="string"?n:""},go=t=>{const n=Rt(t).tool;return typeof n=="string"?n:""},xo=t=>{const n=Rt(t).text;return typeof n=="string"?n:""},wo=t=>{const n=ft(t);return n==="tool"?go(t).trim().toLowerCase()||"tool":n||"unknown"},yo=t=>{if(t.length===0)return"";const n=[];for(const s of t){const a=wo(s);n.includes(a)||n.push(a)}return n.join(" + ")},bo=t=>t.replace(/\s+/g," ").trim(),vo=t=>{for(const s of t)if(ft(s)==="text"){const a=bo(xo(s));if(a.length===0)continue;return a}const n=t.filter(s=>ft(s)!=="text").length;return n===0?"":`${n} attachment${n===1?"":"s"}`},jo=(t,n,s)=>`${s(t)} / ${s(n)}`,So=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Co=(t,n)=>{if(!t||!Number.isFinite(t))return"-";const s=So(n);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:s===!1?"2-digit":"numeric",minute:"2-digit",...s===void 0?{}:{hour12:s}})},ko={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},et={user:0,assistant:0,tool:0,other:0},No=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,dt=t=>ht(t),Po=(...t)=>{for(const n of t)if(typeof n=="string"&&n.trim().length>0)return n;return""},ke=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((n,s)=>n+ke(s),0):t&&typeof t=="object"?Object.values(t).reduce((n,s)=>n+ke(s),0):0,Ro=(t,n)=>{const s=t,a=typeof s.type=="string"?s.type:"";if(a==="reasoning")return{...et,assistant:ke(s.text)+ke(s.content)};const o=Po(s.text,s.content,s.value,s.source?.value,s.source?.text?.value);return a==="tool"||n==="tool"?{user:0,assistant:0,tool:ke(s.input)+ke(s.output)+ke(s.error)+ke(s.call?.input)+ke(s.call?.output)+ke(s.call?.error)+ke(s.raw)+Math.round(ke(s.metadata)*.25)+Math.round(ke(s.state)*.1),other:0}:n==="user"?{user:o.length,assistant:0,tool:0,other:0}:n==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Yt=(t,n)=>({user:t.user+n.user,assistant:t.assistant+n.assistant,tool:t.tool+n.tool,other:t.other+n.other}),Eo=t=>{const n=Ke(t.info);return n.isUser?"user":n.role==="assistant"?"assistant":n.role==="tool"?"tool":"other"},To=(t,n)=>{if(t.length===0)return{...et};const s=t.reduce((a,o)=>{const m=Eo(o);let x={...et};for(const u of o.parts)x=Yt(x,Ro(u,m));return Yt(a,x)},{...et});return s.user+=n.length,{user:Math.ceil(s.user/4),assistant:Math.ceil(s.assistant/4),tool:Math.ceil(s.tool/4),other:Math.ceil(s.other/4)}},Ae=t=>t.toLocaleString("en-US"),_o=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),Do=(t,n)=>!t||!Number.isFinite(t)?"-":Or(t,n,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Ao=(t,n,s)=>{const a=t.find(m=>m.id===n),o=a?.models?.find(m=>m.id===s);return{providerName:a?.name||n||"-",modelName:o?.name||s||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Mo=()=>{const t=ee(c=>c.timeFormatPreference),[n,s]=r.useState({}),{value:a,show:o,clear:m}=Mr(null,2e3),x=Se(c=>c.currentSessionId),u=Se(c=>c.currentSessionDirectory),p=Ir(),g=dn(x??""),v=Ie(c=>c.providers);r.useEffect(()=>{s(c=>Object.keys(c).length>0?{}:c),m()},[m,u,x]);const f=r.useCallback(async(c,S)=>{(await gt(S)).ok?o(c):m()},[m,o]),l=r.useMemo(()=>{const c=x?p.find(L=>L.id===x)??null:null,S=g.filter(L=>Ke(L.info).role==="assistant"),j=g.filter(L=>Ke(L.info).isUser);let P=null;for(let L=S.length-1;L>=0;L-=1){const K=S[L];if(dt(K).total>0){P=K;break}}const R=P?dt(P):ko,O=P?.info?.usage,te=un({input:R.input,cache:{read:R.cacheRead,write:R.cacheWrite}}),F=S.reduce((L,K)=>{const se=No(K.info.cost);return L+se},0),re=P?.info?.model??null,z=Ao(v,re?.providerID||"",re?.modelID||""),y=z.contextLimit,b=O?hn(O):R.total,G=y&&y>0?Math.min(999,b/y*100):0,H=[...g].reverse().find(L=>Ke(L.info).isUser&&typeof L.info.system=="string")?.info?.system||"",$=To(g,H),V=$.user,ne=$.assistant,E=$.tool,Q=O?0:Math.max(0,R.input-V-ne-E),C=V+ne+E+Q,M=g[0]?.info?.time?.created,U=g.length>0?g[g.length-1]?.info?.time?.created:null;return{sessionTitle:Cn(c),messagesCount:g.length,userMessagesCount:j.length,assistantMessagesCount:S.length,createdAt:c?.time?.created??M??null,lastActivityAt:U??c?.time?.created??null,providerModel:z,tokenBreakdown:R,usagePercent:G,cacheHitRate:te,totalAssistantCost:F,contextLimit:y,contextWindowTokens:b,hasUsage:O!==void 0,breakdown:{user:V,assistant:ne,tool:E,other:Q},breakdownTotal:C}},[x,v,g,p]);if(!x)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:"Open a session to inspect context."});const T=[{key:"user",label:"User",value:l.breakdown.user,color:"var(--status-success)"},{key:"assistant",label:"Assistant",value:l.breakdown.assistant,color:"var(--primary-base)"},{key:"tool",label:"Tool Calls",value:l.breakdown.tool,color:"var(--status-warning)"},...l.hasUsage?[]:[{key:"other",label:"Other",value:l.breakdown.other,color:"var(--surface-muted-foreground)"}]];return e.jsx("div",{className:"h-full overflow-y-auto bg-background",children:e.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:l.sessionTitle}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[e.jsxs("span",{children:[l.providerModel.providerName," / ",l.providerModel.modelName]}),l.createdAt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:Do(l.createdAt,t)})]})]})]}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Context"}),e.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ae(l.contextWindowTokens),l.contextLimit?` / ${Ae(l.contextLimit)}`:""]})]}),e.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:l.usagePercent>0&&e.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,l.usagePercent)}%`,backgroundColor:l.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}})}),e.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:`${l.usagePercent.toFixed(1)}% used`})]}),e.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:[{label:"Messages",value:Ae(l.messagesCount)},{label:"User",value:Ae(l.userMessagesCount)},{label:"Assistant",value:Ae(l.assistantMessagesCount)},{label:"Cost",value:_o(l.totalAssistantCost)}].map(c=>e.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value})]},c.label))}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:"Last Assistant Message"}),e.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:"Input",value:l.tokenBreakdown.input,format:"count"},{label:"Output",value:l.tokenBreakdown.output,format:"count"},{label:"Reasoning",value:l.tokenBreakdown.reasoning,format:"count"},{label:"Cache Read",value:l.tokenBreakdown.cacheRead,format:"count"},{label:"Cache Write",value:l.tokenBreakdown.cacheWrite,format:"count"},{label:"Cache Hit",value:l.cacheHitRate.hasInput?l.cacheHitRate.percent:null,format:"percent"}].map(c=>e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value!==null&&c.value!==void 0?c.format==="percent"?`${c.value.toFixed(1)}%`:Ae(c.value):"—"})]},c.label))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:T.map(c=>c.value<=0||l.breakdownTotal<=0?null:e.jsx("div",{style:{width:`${c.value/l.breakdownTotal*100}%`,backgroundColor:c.color}},c.key))}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:T.map(c=>{const S=l.breakdownTotal>0?c.value/l.breakdownTotal*100:0;return e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:c.color}}),e.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[c.label," ",e.jsxs("span",{className:"tabular-nums",children:[S.toFixed(0),"%"]})]})]},c.key)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground",children:"Raw Messages"}),e.jsx("div",{className:"mt-2.5 space-y-1",children:[...g].reverse().map(c=>{const j=Ke(c.info).role,P=j==="assistant",R=j==="user",O=n[c.info.id]===!0,te=a===c.info.id,F=c.info.time?.created??null,re=yo(c.parts),z=P?dt({info:c.info,parts:c.parts}):null,y=R?vo(c.parts):"",b=Co(F,t),G=re||"—",H=z?jo(z.input,z.output,Ae):"",$=j||"unknown",V=re?`${$}: ${re}`:$,ne=O?JSON.stringify({info:c.info,parts:c.parts},null,2):"";return e.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[e.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":O,onClick:()=>{s(E=>({...E,[c.info.id]:E[c.info.id]!==!0}))},children:e.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:P?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[R?e.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",y]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:P?G:V}),P&&e.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:H})]}),e.jsx("span",{className:"text-right text-muted-foreground",children:b})]})}),O&&e.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:e.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[e.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:e.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:E=>{E.stopPropagation(),f(c.info.id,ne)},"aria-label":te?"Copied":"Copy JSON",title:te?"Copied":"Copy",children:te?e.jsx(q,{name:"check",className:"size-3.5"}):e.jsx(q,{name:"file-copy",className:"size-3.5"})})}),e.jsx(Lr,{language:"json",code:ne,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},c.info.id)})})]})]})})},Io=De(()=>Ee(()=>import("./DiffView-ScM4XoqZ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),Lo=De(()=>Ee(()=>import("./FilesView-CjkhMFqJ.js"),__vite__mapDeps([120,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),Oo=De(()=>Ee(()=>import("./GitView-Bqi6H8I-.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),$o=380,Wo=1400,On=600,Fo=100,Bo=24,Jt=t=>Number.isFinite(t)?Math.min(Wo,Math.max($o,Math.round(t))):On,zo=t=>{const n=t?.parentElement?.clientWidth;return!n||n<=0?null:n},Uo=(t,n)=>{if(!t)return"";const s=t.replace(/\\/g,"/"),a=n.replace(/\\/g,"/").replace(/\/+$/,"");return a&&s.startsWith(a+"/")?s.slice(a.length+1):s},$n=(t,n=null)=>t==="file"?"Files":t==="diff"?"Changes":t==="preview"?"Preview":t==="browser"?"Browser":t==="git"?St(n).label:t==="terminal"?"Terminal":"Context",Ho=t=>{if(!t)return null;const n=t.replace(/\\/g,"/").trim();if(!n)return null;const s=n.split("/").filter(Boolean);return s.length===0?n:s[s.length-1]||null},Vo=(t,n=null)=>{if(t.label)return t.label;if(t.mode==="file")return Ho(t.targetPath)||"Files";if(t.mode==="preview"){const s=t.targetPath;if(s)try{const a=new URL(s);return a.host||a.hostname||"Preview"}catch{}return"Preview"}return t.mode==="diff"?"Changes":$n(t.mode,n)},Qt=(t,n=null)=>{if(t.mode==="file")return t.targetPath?e.jsx(mt,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return e.jsx(pr,{className:"h-3.5 w-3.5"});if(t.mode==="git")return e.jsx(q,{name:St(n).icon,className:"h-3.5 w-3.5"});if(t.mode==="terminal")return e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="context")return e.jsx(q,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="preview")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5"})},Ko=(t,n)=>t.length<=n?t:`${t.slice(0,n-3)}...`,Xo=()=>{const t=Ge()??"",n=r.useMemo(()=>Re(t),[t]),s=ee(d=>n?d.contextPanelByDirectory[n]:void 0),a=ee(d=>d.closeContextPanel),o=ee(d=>d.closeContextPanelTab),m=ee(d=>d.openContextPanelTab),x=ee(d=>d.toggleContextPanelExpanded),u=ee(d=>d.setContextPanelWidth),p=ee(d=>d.setActiveContextPanelTab),g=ee(d=>d.reorderContextPanelTabs),v=Te(d=>d.setSelectedPath),f=ee(d=>d.openContextPreview),l=ee(d=>d.contextEditorTreeVisible),T=ee(d=>d.toggleContextEditorTree),c=r.useMemo(()=>s?.tabs??[],[s?.tabs]),S=c.find(d=>d.id===s?.activeTabId)??c[c.length-1]??null,j=!!(s?.isOpen&&S),P=!!(j&&s?.expanded),[R,O]=r.useState(null),te=s?.width,F=Wr,re=R??(typeof window<"u"?window.innerWidth:On*2),z=Jt(te??Math.round(F*re)),y=pn(n||null),[b,G]=r.useState(!1),[H,$]=r.useState(null),[V,ne]=r.useState(null),[E,Q]=r.useState(null),C=r.useRef(0),M=r.useRef(z),U=r.useRef(null),L=r.useRef(null),K=r.useRef(null),se=r.useRef(!1);r.useLayoutEffect(()=>{const d=K.current?.parentElement;if(!d||typeof ResizeObserver>"u")return;const N=new ResizeObserver(()=>{O(d.clientWidth||null)});return N.observe(d),O(d.clientWidth||null),()=>N.disconnect()},[]),r.useEffect(()=>{if(!j||se.current){se.current=j;return}const d=window.requestAnimationFrame(()=>{K.current?.focus({preventScroll:!0})});return se.current=!0,()=>window.cancelAnimationFrame(d)},[j]);const he=r.useRef(null),ue=r.useRef(null),be=r.useCallback(()=>{ue.current=null;const d=K.current,N=U.current;!d||N===null||d.style.setProperty("--oc-context-panel-width",`${N}px`)},[]);r.useEffect(()=>()=>{ue.current!==null&&clearTimeout(ue.current)},[]);const fe=r.useCallback(d=>{const N=Jt(d),le=he.current;return le===null?N:Math.min(N,Math.max(1,le))},[]),xe=r.useCallback(d=>{!j||P||!n||(L.current=d.pointerId,G(!0),C.current=d.clientX,M.current=z,U.current=z,he.current=zo(K.current),document.documentElement.style.cursor="col-resize",d.preventDefault())},[n,P,j,z]),pe=r.useCallback(()=>{const d=fe(U.current??z);U.current=null,he.current=null,ue.current!==null&&(clearTimeout(ue.current),ue.current=null),document.documentElement.style.cursor="",n&&u(n,d),G(!1),L.current=null},[fe,n,u,z]);r.useEffect(()=>{if(!b)return;const d=Z=>{if(L.current!==Z.pointerId)return;const ye=C.current-Z.clientX,ve=fe(M.current+ye);U.current!==ve&&(U.current=ve,ue.current===null&&(ue.current=setTimeout(be,Fo)))},N=Z=>{L.current===Z.pointerId&&pe()},le=()=>{pe()};return window.addEventListener("pointermove",d),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N),window.addEventListener("blur",le),()=>{window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),window.removeEventListener("blur",le)}},[be,fe,pe,b]),r.useEffect(()=>{b||(U.current=null,document.documentElement.style.cursor="")},[b]);const I=r.useCallback(()=>{n&&a(n)},[a,n]),W=r.useCallback(()=>{n&&x(n)},[n,x]),w=r.useCallback(d=>{d.key==="Escape"&&($r(d.target)||(d.preventDefault(),d.stopPropagation(),I()))},[I]);r.useEffect(()=>{if(!(!n||!S)&&S.mode==="file"&&S.targetPath){v(n,S.targetPath,{allowOutsideRoot:!0});return}},[S,n,v]);const A=r.useCallback(d=>{!n||S?.mode!=="diff"||m(n,{mode:"diff",targetPath:S.targetPath,stagedDiff:d==="staged",diffScope:d})},[S,n,m]),X=S?.mode==="file"||S?.mode==="preview",de=r.useMemo(()=>S?c.filter(d=>d.mode===S.mode):[],[S,c]),me=r.useMemo(()=>de.map(d=>{const N=Vo(d,y),le=Ko(N,Bo),Z=Uo(d.targetPath,t);return{id:d.id,label:le,icon:Qt(d,y),title:Z?`${N}: ${Z}`:N,closeLabel:`Close ${le} tab`}}),[de,t,y]),we=S?.mode==="context"?e.jsx(Mo,{}):S?.mode==="git"?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Oo,{isActive:j,gitHeaderSlot:S?.mode==="git"?V:null})}):S?.mode==="preview"?e.jsx(mo,{rawUrl:S.targetPath??"",onNavigate:d=>f(t,d)}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"Preview"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Use Project Actions or a terminal Preview button to open a preview."})]}),k=r.useMemo(()=>c.filter(d=>d.mode==="browser"),[c]),Y=r.useMemo(()=>c.filter(d=>d.mode==="diff"),[c]),ie=r.useMemo(()=>c.some(d=>d.mode==="terminal"),[c]),_=r.useMemo(()=>c.some(d=>d.mode==="file"),[c]),oe=r.useMemo(()=>c.some(d=>d.mode==="file"&&d.targetPath),[c]),ae=S?.mode==="file",J=S?.mode==="terminal",B=S?.mode==="git",h=S?.mode==="diff",i=e.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[X?e.jsx(Ts,{items:me,activeId:S?.id??null,onSelect:d=>{n&&p(n,d)},onClose:d=>{n&&o(n,d)},onReorder:(d,N)=>{n&&g(n,d,N)},layoutMode:"scrollable",variant:"default"}):J?e.jsx("div",{ref:d=>{$(d)},className:"flex min-w-0 flex-1 items-center px-1"}):B?e.jsx("div",{ref:d=>{ne(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):h?e.jsx("div",{ref:d=>{Q(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[S?Qt(S,y):null,e.jsx("span",{className:"truncate typography-ui-label text-foreground",children:S?$n(S.mode,y):null})]}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[ae?e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:T,className:"h-7 w-7 p-0",title:"Toggle file tree","aria-label":"Toggle file tree","aria-pressed":l,children:e.jsx(q,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:W,className:"h-7 w-7 p-0",title:P?"Collapse panel":"Expand panel","aria-label":P?"Collapse panel":"Expand panel",children:P?e.jsx(q,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):e.jsx(q,{name:"fullscreen",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:I,className:"h-7 w-7 p-0",title:"Close panel","aria-label":"Close panel",children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})})]})]}),D=j?P?{"--oc-context-panel-width":R!==null?`${R}px`:"100%",width:R!==null?`${R}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${z}px`}:{"--oc-context-panel-width":`${z}px`,width:0,maxWidth:"100%",overflowX:"clip"};return e.jsxs("aside",{ref:K,"data-context-panel":"true",tabIndex:-1,inert:!j||void 0,className:ce("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!j&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:w,style:D,children:[j&&!P&&e.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),j&&e.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&e.jsx("div",{className:ce("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",b&&"bg-[var(--interactive-border)]"),onPointerDown:xe,role:"separator","aria-orientation":"vertical","aria-label":"Resize context panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!j&&"pointer-events-none select-none opacity-0"),style:{width:P?R!==null?`${R}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!j,children:[i,e.jsxs("div",{className:ce("relative min-h-0 flex-1 overflow-hidden",b&&"pointer-events-none"),children:[_?e.jsxs("div",{className:ce("absolute inset-0 flex",ae?"flex":"hidden"),children:[e.jsx("div",{className:"h-full min-w-0 flex-1",children:oe?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Lo,{mode:"editor-only"})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"No file open"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Pick a file from the tree to start editing."})]})}),e.jsx(uo,{visible:l})]}):null,k.map(d=>e.jsx("div",{className:ce("absolute inset-0",S?.id!==d.id&&"hidden"),children:e.jsx(eo,{initialUrl:d.targetPath??"",directory:n,tabID:d.id})},d.id)),j?Y.filter(d=>S?.id===d.id).map(d=>e.jsx("div",{className:"absolute inset-0",children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(Io,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:d.diffScope??(d.stagedDiff?"staged":"working"),onDiffScopeChange:A,targetFilePath:d.targetPath,flushContent:!0,toolbarSlot:h?E:null})})},d.id)):null,ie?e.jsx("div",{className:ce("absolute inset-0",S?.mode==="terminal"?"block":"hidden"),children:e.jsx(an,{visible:j&&S?.mode==="terminal",terminalHeaderSlot:J?H:null})}):null,j&&!ae&&S?.mode!=="browser"&&S?.mode!=="diff"&&S?.mode!=="terminal"?we:null]})]})]})},qo=150,Go=500,Yo=[],Me=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t),Je=(t,n)=>{if(!t||typeof t!="object")return;const s=t[n];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Jo=t=>t>99?"99+":String(t),Qo=t=>t>=90?"text-[var(--status-error)]":t>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Zo=({surface:t,isActive:n,showActivityDot:s,label:a,description:o,badgeCount:m,badgeAriaLabel:x,badgeDescription:u,orderNumber:p,showOrderNumber:g,onSelect:v,chartPercentage:f,chartDetails:l})=>{const{attributes:T,listeners:c,setNodeRef:S,transform:j,transition:P,isDragging:R}=jn({id:t.id}),O=m!=null&&m>0?Jo(m):null;return e.jsx("div",{ref:S,style:{transform:Sn.Translate.toString(j),transition:P},className:ce("relative",R&&"z-10 opacity-70"),children:e.jsxs(Oe,{delayDuration:qo,children:[e.jsx($e,{asChild:!0,children:e.jsxs("button",{type:"button",...T,...c,onClick:()=>v(t),"aria-label":x??a,"aria-pressed":n,className:ce("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",n?"text-primary":"text-muted-foreground hover:text-foreground"),children:[t.id==="context"&&typeof f=="number"?e.jsx(It,{percentage:f,className:"size-[18px] -rotate-90"}):e.jsx(q,{name:t.icon,className:"h-[18px] w-[18px]"}),g&&p!=null?e.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:p===10?"0":p}):O?e.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:O}):s?e.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null]})}),e.jsx(We,{side:"left",sideOffset:8,className:t.id==="context"&&l?"p-0 border-0 bg-transparent shadow-none":void 0,children:t.id==="context"&&l?e.jsx("div",{className:"w-[300px] overflow-hidden rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[e.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:e.jsx(It,{percentage:l.percentage,className:"size-[18px] -rotate-90"})}),e.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:a}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:l.hasData?e.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[e.jsxs("span",{className:ce("font-semibold",Qo(l.percentage)),children:[l.percentage.toFixed(1),"%"]}),e.jsx("span",{className:"text-muted-foreground",children:`${Me(l.totalTokens)}/${Me(l.contextLimit)}`})]}):e.jsx("span",{className:"typography-micro text-muted-foreground",children:"No data yet"})})]}),l.hasData?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.totalTokens)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.contextLimit)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.outputLimit)})]}),typeof l.cacheRead=="number"&&typeof l.cacheWrite=="number"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheRead)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheWrite)})]})]}):null,typeof l.cacheHitPercent=="number"?e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache hit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:`${l.cacheHitPercent.toFixed(1)}%`})]}):null]}):e.jsx("div",{className:"px-2.5 py-2 typography-micro text-muted-foreground",children:o})]})}):e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{children:a}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:o}),u?e.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null]})})]})})},ea=()=>{const t=Ge(),n=t?qn(t):"",s=ee(w=>n?w.contextPanelByDirectory[n]:void 0),a=ee(w=>w.contextRailOrder),o=ee(w=>w.setContextRailOrder),m=ee(w=>w.openContextSurface),x=ee(w=>w.shortcutOverrides),{screenWidth:u}=st(),{git:p}=xt(),g=cn(n||null),v=pn(n||null),f=fn(w=>w.ensureStatus);r.useEffect(()=>{n&&f(n,p)},[n,f,p]);const l=r.useMemo(()=>Gn("switch_context_surface",x),[x]),[T,c]=r.useState(!1);r.useEffect(()=>{const w=new Set;let A=null,X=!1;const de=ie=>ie.length===1&&ie>="0"&&ie<="9",me=()=>{Et(l,w)?!X&&A===null&&(A=setTimeout(()=>c(!0),Go)):(X=!1,A!==null&&(clearTimeout(A),A=null),c(!1))},we=ie=>{if(w.add(ie.key.toLowerCase()),de(ie.key)&&Et(l,w)){X=!0,A!==null&&(clearTimeout(A),A=null),c(!1);return}me()},k=ie=>{w.delete(ie.key.toLowerCase()),me()},Y=()=>{w.clear(),X=!1,A!==null&&(clearTimeout(A),A=null),c(!1)};return window.addEventListener("keydown",we,!0),window.addEventListener("keyup",k,!0),window.addEventListener("blur",Y),()=>{window.removeEventListener("keydown",we,!0),window.removeEventListener("keyup",k,!0),window.removeEventListener("blur",Y),A!==null&&clearTimeout(A)}},[l]);const S=wn(pt(js,{activationConstraint:{distance:8}}),pt(vs,{activationConstraint:{delay:200,tolerance:6}})),j=s?.tabs??Yo,P=j.find(w=>w.id===s?.activeTabId)??null,R=s?.isOpen?P?.mode??null:null,O=g?.files.length??0,te=Se(w=>w.currentSessionId),F=Se(w=>!!w.newSessionDraft?.open),re=Ie(w=>w.providers),z=Ie(w=>w.currentProviderId),y=Ie(w=>w.currentModelId),b=Ie(w=>w.getCurrentModel()),G=Ie(w=>w.getModelMetadata);Ie(w=>w.modelsMetadata.size);const H=Fr(r.useCallback(w=>te?w.sessionModelSelections.get(te)??null:null,[te])),$=dn(te??""),V=r.useMemo(()=>{for(let w=$.length-1;w>=0;w-=1){const A=$[w];if(A?.info.role==="assistant")try{if(ht(A).total>0)return A}catch{continue}}return null},[$]),E=r.useMemo(()=>{for(let w=$.length-1;w>=0;w-=1){const A=$[w]?.info;if(A.role!=="user")continue;const X=A.model,de=X?.providerID??X?.providerId,me=X?.modelID??X?.modelId;if(typeof de=="string"&&de.trim()&&typeof me=="string"&&me.trim())return{providerID:de,modelID:me}}return null},[$])??(()=>{const w=V?.info.model,A=w?.providerID??w?.providerId,X=w?.modelID??w?.modelId;return A&&X?{providerID:A,modelID:X}:null})()??(H?{providerID:H.providerId,modelID:H.modelId}:null)??(z&&y?{providerID:z,modelID:y}:null),C=(E?re.find(w=>w.id===E.providerID):void 0)?.models.find(w=>w.id===E?.modelID),M=E?G(E.providerID,E.modelID):void 0,U=Je(C?.limit,"context")??M?.limit?.context??Je(b?.limit,"context")??0,L=Je(C?.limit,"output")??M?.limit?.output??Je(b?.limit,"output")??0,K=V?(()=>{try{return ht(V)}catch{return null}})():null,se=V?.info?.usage,he=se?hn(se):K?.total??0,ue=!F&&he>0&&U>0?Math.min(he/U*100,999):0,be=ue,fe=K?un({input:K.input,cache:{read:K.cacheRead,write:K.cacheWrite}}):null,xe=fe?.hasInput?fe.percent:null,pe=r.useMemo(()=>{const w=!!V&&he>0&&U>0;return{percentage:ue,totalTokens:he,contextLimit:U,outputLimit:L,cacheRead:K?.cacheRead??null,cacheWrite:K?.cacheWrite??null,cacheHitPercent:xe,hasData:w}},[K,xe,U,V,L,ue,he]),I=r.useMemo(()=>Br({railOrder:a,tabs:j}),[a,u,j]),W=r.useCallback(w=>{const{active:A,over:X}=w;if(!X||A.id===X.id)return;const de=zr(ee.getState().contextRailOrder).map(k=>k.id),me=de.indexOf(A.id),we=de.indexOf(X.id);me===-1||we===-1||o(Cs(de,me,we))},[o]);return n?e.jsx("nav",{"aria-label":"Panel surfaces",className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:e.jsx(yn,{sensors:S,collisionDetection:bn,onDragEnd:W,children:e.jsx(vn,{items:I.map(w=>w.id),strategy:ks,children:I.map((w,A)=>{const X=w.id==="git"?St(v):null,de=X?{...w,...X}:w,me=de.label,we=w.id==="git"&&v===!0?O:0,k=we>0?we:null,Y=w.id==="context";return e.jsx(Zo,{surface:de,isActive:R===w.mode,showActivityDot:!1,label:me,description:de.description,badgeCount:k,badgeAriaLabel:k!==null?k===1?`${me}, ${k} changed file`:`${me}, ${k} changed files`:null,badgeDescription:k!==null?k===1?`${k} changed file`:`${k} changed files`:null,chartPercentage:Y?be:void 0,chartDetails:Y?pe:void 0,orderNumber:A+1,showOrderNumber:T,onSelect:ie=>m(n,ie.mode)},w.id)})})})}):null},ta=(t,n)=>!t||n.length===0?"":JSON.stringify([t,n]),na=(t,n,s,a)=>!s||a!==s||t.length===0?[]:Ve(t,n,o=>o.name,{limit:10,threshold:.4}),ra=new Set,ut=t=>{if(!t)return"";const n=t.replace(/\\/g,"/"),s=n.startsWith("//");let a=n.replace(/\/+/g,"/");s&&!a.startsWith("//")&&(a=`/${a}`);const o=a==="/",m=/^[A-Za-z]:\/$/.test(a);return!o&&!m&&(a=a.replace(/\/+$/,"")),a},sa=()=>{const t=ee(h=>h.isCommandPaletteOpen),n=ee(h=>h.setCommandPaletteOpen),s=ee(h=>h.setActiveMainTab),a=ee(h=>h.setSettingsDialogOpen),o=ee(h=>h.setSettingsPage),m=ee(h=>h.setSessionSwitcherOpen),x=ee(h=>h.toggleSidebar),u=ee(h=>h.openContextOverview),p=ee(h=>h.openContextSurface),g=ee(h=>h.openContextFile),v=ee(h=>h.shortcutOverrides),f=Se(h=>h.openNewSessionDraft),l=Se(h=>h.setCurrentSession),T=Ur({archived:!1}),c=Hr(r.useCallback(h=>t?h.ids:ra,[t])),S=Vr(r.useCallback(h=>t?h.rankById:Kr,[t])),j=Yn(h=>h.currentDirectory),P=Lt(h=>h.getActiveProject()),R=Lt(h=>h.projects),O=Ge(),te=Jn(h=>h.searchFiles),{files:F,git:re}=xt(),z=fn(h=>h.ensureStatus),{isMobile:y}=st(),b=r.useMemo(()=>O?ut(O):null,[O]),[G,H]=r.useState(""),V=Xr(G,200).trim(),ne=G.trim();r.useEffect(()=>{t&&H("")},[t]),r.useEffect(()=>{if(!t||!re)return;const h=setTimeout(()=>{const i=new Set;for(const D of T){const d=at(D);!d||i.has(d)||(i.add(d),z(d,re))}},0);return()=>clearTimeout(h)},[t,T,re,z]);const E=r.useCallback(()=>n(!1),[n]),Q=r.useCallback(h=>()=>{E(),h()},[E]),C=r.useMemo(()=>{const h=[{id:"new-session",title:"New Session",icon:e.jsx(q,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:"New Session",onSelect:Q(()=>{s("chat"),m(!1),f()})},{id:"add-project",title:"Add Project",icon:e.jsx(q,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:"Add Project",onSelect:Q(()=>{qr.requestDirectoryDialog()})},{id:"toggle-sidebar",title:y?"Show Session Switcher":"Toggle Sidebar",icon:e.jsx(q,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:y?"Show Session Switcher":"Toggle Sidebar",onSelect:Q(()=>{if(y){const{isSessionSwitcherOpen:i}=ee.getState();m(!i)}else x()})},{id:"toggle-terminal",title:"Toggle Terminal",icon:e.jsx(q,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:"Toggle Terminal",onSelect:Q(()=>{j&&p(j,"terminal")})},{id:"context-usage",title:"Show Context Usage",icon:e.jsx(q,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:"Show Context Usage",onSelect:Q(()=>{j&&u(j)})},{id:"open-settings",title:"Open Settings...",icon:e.jsx(q,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:"Open Settings...",onSelect:Q(()=>a(!0))}];return Qn()&&h.splice(1,0,{id:"new-mini-chat",title:"New Mini Chat Window",icon:e.jsx(q,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:"New Mini Chat Window",onSelect:Q(()=>{en("desktop_open_draft_mini_chat_window",{directory:ut(j||P?.path||""),projectId:P?.id??null}).catch(i=>{console.warn("[command-palette] failed to open draft mini chat window",i)})})}),h},[Q,y,s,m,f,x,p,j,u,a,P?.id,P?.path]),M=r.useMemo(()=>{const h=Zn();return{isWeb:!h&&er(),isDesktop:h,isMobile:y}},[y]),U=r.useMemo(()=>fr.filter(h=>h.slug!=="home").filter(h=>h.isAvailable?h.isAvailable(M):!0).map(h=>{const i=mr(h.slug)??"settings-3",D=(h.keywords??[]).join(" ");return{id:`settings:${h.slug}`,title:h.title,icon:e.jsx(q,{name:i,className:"mr-2 h-4 w-4"}),searchText:`${h.title} ${h.group} ${D}`,onSelect:Q(()=>{o(h.slug),a(!0)})}}),[M,Q,o,a]),L=r.useMemo(()=>Gr(T,c,S),[T,c,S]),K=Yr(),se=r.useCallback((h,i)=>i&&K.get(i)?.trim()||null,[K]),[he,ue]=r.useState([]),[be,fe]=r.useState(""),xe=ta(b,V);r.useEffect(()=>{if(!t){ue([]),fe("");return}if(!xe){ue([]),fe("");return}if(!b){ue([]),fe("");return}let h=!1;return te(b,V,10,{type:"file"}).then(i=>{h||(ue(i.map(D=>({path:ut(D.path),name:D.name,relativePath:D.relativePath}))),fe(xe))}).catch(()=>{h||(ue([]),fe(xe))}),()=>{h=!0}},[t,b,V,xe,te]);const pe=ne.length>0,I=r.useMemo(()=>pe?Ve(C,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):C.map(h=>({item:h,score:0})),[C,ne,pe]),W=r.useMemo(()=>pe?Ve(U,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):[],[U,ne,pe]),w=r.useMemo(()=>pe?Ve(L,ne,h=>h.title||"",{limit:7,threshold:.2}):L.slice(0,5).map(h=>({item:h,score:0})),[L,ne,pe]),A=r.useMemo(()=>t?na(he,V,xe,be):[],[t,he,be,xe,V]),X=t&&xe.length>0&&be!==xe,de=r.useMemo(()=>{if(!pe)return[];const h=R.map(i=>({...i,displayName:i.label||i.path.split("/").pop()||i.path,searchText:`${i.label||""} ${i.path}`}));return Ve(h,ne,i=>i.searchText,{limit:7,threshold:.4})},[R,ne,pe]),me=I.map(h=>h.item),we=W.map(h=>h.item),k=w.map(h=>h.item),Y=pe?A.map(h=>h.item):[],ie=pe?de.map(h=>h.item):[],_=r.useMemo(()=>{if(!pe)return["commands","sessions"];const h=D=>D.length?D[0].score:1/0,i=[{key:"commands",score:h(I)},{key:"settings",score:h(W)},{key:"sessions",score:h(w)},{key:"files",score:h(A)},{key:"projects",score:h(de)}];return i.sort((D,d)=>D.score-d.score),i.map(D=>D.key)},[pe,I,W,w,A,de]),oe=r.useCallback(h=>{E(),l(h.id,at(h))},[E,l]),ae=r.useCallback(async h=>{if(!b)return;const i=await mn(F,h,{directory:b});if(!i.ok){je.error(gn(i.reason));return}g(b,h),E()},[b,F,g,E]),J=r.useCallback((h,i)=>{E(),f({selectedProjectId:h,directoryOverride:i})},[E,f]),B=r.useCallback(h=>rn(sn(h,v)),[v]);return e.jsxs(wt,{open:t,onOpenChange:n,children:[e.jsxs(bt,{className:"sr-only",children:[e.jsx(vt,{children:"Command Palette"}),e.jsx(jt,{children:"Search files, sessions, and commands."})]}),e.jsx(yt,{className:"overflow-hidden p-0",showCloseButton:!0,children:e.jsxs(Jr,{shouldFilter:!1,className:"[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta",children:[e.jsx(Qr,{value:G,onValueChange:H,placeholder:"Search files, sessions, commands..."}),e.jsxs(Zr,{children:[e.jsx(es,{children:"No results found."}),_.map(h=>h==="commands"&&me.length>0?e.jsx(Ue,{children:me.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title}),i.shortcutId?e.jsx(ts,{children:B(i.shortcutId)}):null]},i.id))},"commands"):h==="settings"&&we.length>0?e.jsx(Ue,{children:we.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title})]},i.id))},"settings"):h==="sessions"&&k.length>0?e.jsx(Ue,{children:k.map(i=>{const D=Cn(i),d=at(i),N=se(i.id,d);return e.jsxs(He,{value:`session:${i.id}`,onSelect:()=>oe(i),children:[e.jsx(q,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),N?e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[e.jsx(q,{name:"git-branch",className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[160px]",children:N})]}):null]},i.id)})},"sessions"):h==="files"&&Y.length>0?e.jsx(Ue,{children:Y.map(i=>{const D=tr(i.relativePath||i.name,{maxLength:80});return e.jsxs(He,{value:`file:${i.path}`,onSelect:()=>{ae(i.path)},children:[e.jsx(mt,{filePath:i.path,className:"mr-2 size-4 shrink-0"}),e.jsx("span",{className:"truncate","aria-label":i.relativePath,children:D})]},`file:${i.path}`)})},"files"):h==="projects"&&ie.length>0?e.jsx(Ue,{children:ie.map(i=>{const D=i.displayName;return e.jsxs(He,{value:`project:${i.id}`,onSelect:()=>J(i.id,i.path),children:[e.jsx(q,{name:"folder",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),e.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:i.path})]},`project:${i.id}`)})},"projects"):null),X?e.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:"Searching files..."}):null]})]})})]})},oa=(t,n,s)=>rr(t)?rn(sn(t,s)):n,aa=()=>{const t=ee(m=>m.isHelpDialogOpen),n=ee(m=>m.setHelpDialogOpen),s=ee(m=>m.shortcutOverrides),a=nr(),o=[{categoryKey:"Navigation & Commands",items:[{id:"open_command_palette",descriptionKey:"Open Command Palette",icon:"command",keys:""},{id:"open_help",descriptionKey:"Show Keyboard Shortcuts (this dialog)",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"Toggle Session Sidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"Add Selection to Chat",icon:"add",keys:""},{id:"open_model_selector",descriptionKey:"Open Model Selector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"Navigate Models (in picker)",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"Adjust Thinking Mode (in picker, when supported)",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"Cycle thinking (global shortcut)",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${a} + N`],descriptionKey:"New Window (desktop only)",icon:"window"}]},{categoryKey:"Session Management",items:[{id:"new_chat",descriptionKey:"Create New Session",icon:"add",keys:""},{id:"focus_input",descriptionKey:"Focus Chat Input",icon:"text",keys:""},{id:"cycle_session_folder",descriptionKey:"Cycle session folder",icon:"folder-open",keys:""},{id:"cycle_draft_folder",descriptionKey:"Cycle draft folder",icon:"folder-3",keys:""},{id:"open_timeline_dialog",descriptionKey:"Open conversation timeline",icon:"history",keys:""},{id:"abort_run",descriptionKey:"Abort active run (double press)",icon:"close-circle",keys:""}]},{categoryKey:"Panels",items:[{id:"open_right_sidebar",descriptionKey:"Open right sidebar",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{keys:[`${a} + 1...0`],descriptionKey:"Switch Context Panel Surface (number key)",icon:"layout-right"}]},{categoryKey:"Interface",items:[{id:"cycle_theme",descriptionKey:"Cycle Theme (Light → Dark → System)",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"Open Settings",icon:"settings-3",keys:""}]}];return e.jsx(wt,{open:t,onOpenChange:n,children:e.jsxs(yt,{className:"w-[92vw] max-w-[1120px] h-[84vh] max-h-[900px] flex flex-col overflow-hidden",children:[e.jsxs(bt,{children:[e.jsxs(vt,{className:"flex items-center gap-2",children:[e.jsx(q,{name:"command",className:"h-5 w-5"}),"Keyboard Shortcuts"]}),e.jsx(jt,{children:"Use these keyboard shortcuts to navigate PiChamber efficiently"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-3 pr-1",children:e.jsx("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-x-10",children:o.map(m=>e.jsxs("div",{className:"min-w-0 break-inside-avoid",children:[e.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:m.categoryKey}),e.jsx("div",{className:"space-y-1",children:m.items.map(x=>{const u=x.id?oa(x.id,Array.isArray(x.keys)?x.keys[0]:x.keys,s):Array.isArray(x.keys)?x.keys:x.keys.split(" / ");return e.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[x.icon&&e.jsx(q,{name:x.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"typography-meta",children:x.descriptionKey})]}),e.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(u)?u:[u]).map((p,g)=>e.jsxs(r.Fragment,{children:[g>0&&e.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:"or"}),e.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:p})]},`${p}-${g}`))})]},x.id||x.descriptionKey)})})]},m.categoryKey))})})]})})},ia=r.createContext(null),la=({children:t,value:n})=>e.jsx(ia.Provider,{value:n,children:t}),Zt=De(()=>Ee(()=>import("./GitView-Bqi6H8I-.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),ca=De(()=>Ee(()=>import("./DiffView-ScM4XoqZ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),da=De(()=>Ee(()=>import("./FilesView-CjkhMFqJ.js"),__vite__mapDeps([120,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),ua=De(()=>Ee(()=>import("./DiagramView-y9Ystuhv.js"),__vite__mapDeps([131,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,121,122])).then(t=>({default:t.DiagramView}))),ha=De(()=>Ee(()=>import("./SettingsView-C0S0Sx-S.js").then(t=>t.a),__vite__mapDeps([132,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsView}))),pa=De(()=>Ee(()=>import("./SettingsWindow-Cy9tmnMg.js"),__vite__mapDeps([135,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,132,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsWindow}))),fa=()=>{const t=ee(C=>C.isSidebarOpen),n=ee(C=>C.activeMainTab),s=ee(C=>C.setIsMobile),a=ee(C=>C.isSessionSwitcherOpen),o=ee(C=>C.isSettingsDialogOpen),m=ee(C=>C.setSettingsDialogOpen),[x,u]=r.useState(!1);r.useEffect(()=>{o&&u(!0)},[o]),r.useEffect(()=>{const C=()=>ee.getState().closeMainSurfaces(),M=Se.subscribe((L,K)=>{const se=!!L.currentSessionId&&L.currentSessionId!==K.currentSessionId,he=!!L.newSessionDraft?.open&&L.newSessionDraft!==K.newSessionDraft;(se||he)&&C()}),U=ee.subscribe((L,K)=>{L.activeMainTab!==K.activeMainTab&&C()});return()=>{M(),U()}},[]);const{isMobile:p}=st(),g=r.useRef(!1),[v,f]=r.useState(!1),[l,T]=r.useState(!1),[c,S]=r.useState(!1),[j,P]=r.useState(!1),R=r.useCallback(C=>{f(C),ee.getState().setSessionSwitcherOpen(C)},[]),O=r.useRef(typeof window>"u"?0:window.innerWidth),te=r.useRef(null),F=r.useRef(!1),re=r.useRef(!1),z=r.useRef(!1),y=r.useRef(null),b=r.useRef(null),G=Ot(-O.current),H=Ce.useRef(0),$=Ot(O.current),V=Ce.useRef(0);Ce.useEffect(()=>{p&&(H.current=window.innerWidth,V.current=window.innerWidth)},[p]),Ce.useEffect(()=>{if(!p)return;const C=()=>{const M=window.innerWidth;H.current=M,V.current=M,v||G.get()<-10&&G.set(-M),l||$.get()>10&&$.set(M)};return window.addEventListener("resize",C),window.addEventListener("orientationchange",C),()=>{window.removeEventListener("resize",C),window.removeEventListener("orientationchange",C)}},[p,G,$,v,l]),Ce.useEffect(()=>{if(!p){S(!1);return}v&&S(!0);const C=H.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye(G,v?0:-C,{type:"spring",stiffness:400,damping:35,mass:.8});return y.current=M,()=>M.stop()},[v,p,G]),Ce.useEffect(()=>{if(!p){P(!1);return}l&&P(!0);const C=V.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye($,l?0:C,{type:"spring",stiffness:400,damping:35,mass:.8});return b.current=M,()=>M.stop()},[p,l,$]),Ce.useEffect(()=>{if(p)return G.on("change",C=>{const M=H.current||O.current,U=v||C>-M+.5;S(L=>L===U?L:U)})},[p,G,v]),Ce.useEffect(()=>{if(p)return $.on("change",C=>{const M=V.current||O.current,U=l||C<M-.5;P(L=>L===U?L:U)})},[p,l,$]),Ce.useEffect(()=>{p&&!a&&v&&R(!1)},[a,p,v,R]),Ce.useEffect(()=>{if(!p){g.current=!1;return}g.current||(g.current=!0,R(!1),T(!1))},[p,R]),Ce.useEffect(()=>{if(!p||n!=="chat"||v||l||o)return;let C=!1,M;const U=L=>{M=window.setTimeout(()=>{if(C)return;const K=Se.getState(),se=ee.getState();if(!(se.activeMainTab!=="chat"||se.isSettingsDialogOpen||K.currentSessionId||K.newSessionDraft?.open)){if(K.isLoading){U(250);return}K.openNewSessionDraft({automatic:!0})}},L)};return U(500),()=>{C=!0,M!==void 0&&window.clearTimeout(M)}},[n,p,o,v,l]),Ce.useEffect(()=>{!p||!o||(R(!1),T(!1))},[p,o,R]),r.useEffect(()=>{ee.getState().isMobile!==p&&s(p)},[p,s]);const ne=r.useCallback(()=>{v&&R(!1),T(!l)},[v,l,R]);gr(te,{enabled:p,leftOpen:v,rightOpen:l,leftWidth:()=>H.current||O.current||(typeof window<"u"?window.innerWidth:0),rightWidth:()=>V.current||O.current||(typeof window<"u"?window.innerWidth:0),onLeftProgress:C=>{const M=H.current||O.current||(typeof window<"u"?window.innerWidth:0);G.set(M*(C-1))},onRightProgress:C=>{const M=V.current||O.current||(typeof window<"u"?window.innerWidth:0);$.set(M*(1-C))},onLeftOpen:()=>{l&&T(!1),R(!0)},onLeftClose:()=>R(!1),onRightOpen:()=>{v&&R(!1),T(!0)},onRightClose:()=>T(!1),onDragStart:C=>{F.current=!0,C==="left"?(re.current=v,y.current?.stop(),c||S(!0)):(z.current=l,b.current?.stop(),j||P(!0))},onDragEnd:(C,M)=>{if(F.current=!1,C==="left"&&typeof M=="boolean"){const U=re.current;if(M===U){const L=H.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye(G,U?0:-L,{type:"spring",stiffness:400,damping:35,mass:.8});y.current=K}}if(C==="right"&&typeof M=="boolean"){const U=z.current;if(M===U){const L=V.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye($,U?0:L,{type:"spring",stiffness:400,damping:35,mass:.8});b.current=K}}}});const E=r.useMemo(()=>{if(!p&&n!=="terminal"&&n!=="diagram"||p&&n==="git"&&(l||j))return null;switch(n){case"git":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:!0})});case"diff":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ca,{})});case"terminal":return e.jsx(an,{onCloseView:()=>ee.getState().setActiveMainTab("chat")});case"files":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(da,{})});case"diagram":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ua,{})});default:return null}},[n,p,j,l]),Q=n==="chat";return e.jsxs(xr,{children:[e.jsx(wr,{}),e.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",p?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[e.jsx(sa,{}),e.jsx(aa,{}),e.jsx(yr,{}),p?e.jsxs(la,{value:{leftDrawerOpen:v,rightDrawerOpen:l,toggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},toggleRightDrawer:ne,leftDrawerX:G,rightDrawerX:$,leftDrawerWidth:H,rightDrawerWidth:V,setMobileLeftDrawerOpen:R,setRightSidebarOpen:T},children:[!o&&e.jsx(Tt,{onToggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},onToggleRightDrawer:()=>{ne()},leftDrawerOpen:v,rightDrawerOpen:l}),e.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",o&&"hidden"),children:e.jsxs("main",{ref:te,className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!c&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:G},"aria-hidden":!v,children:e.jsx(Ne,{children:e.jsx(At,{mobileVariant:!0,isVisible:c})})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!j&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:$},"aria-hidden":!l,children:e.jsx(Ne,{children:l||j?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:l})}):null})})]})}),o&&e.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:e.jsx(Ne,{children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(ha,{onClose:()=>m(!1)})})})})]}):e.jsxs(e.Fragment,{children:[e.jsx(br,{}),e.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[e.jsx(_s,{isOpen:t,isMobile:p,children:e.jsx(At,{isVisible:t})}),e.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx(Tt,{}),e.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:e.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:e.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[e.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})})]}),e.jsx(Xo,{})]})})}),e.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:e.jsx(Ne,{children:e.jsx(ea,{})})})]})]})]}),x?e.jsx(r.Suspense,{fallback:null,children:e.jsx(pa,{open:o,onOpenChange:m})}):null]})]})]})},ma=()=>(is(),jr(),e.jsxs(Sr,{children:[e.jsx(ls,{embeddedBackgroundWorkEnabled:!0}),e.jsx(cs,{}),e.jsx(fa,{}),e.jsx(Cr,{}),e.jsx(ds,{}),e.jsx(us,{})]}));function ga({apis:t}){const n=t??on(),[s,a]=r.useState(0);return r.useEffect(()=>sr(o=>{o.runtimeKey!==o.previousRuntimeKey&&(vr(o),a(m=>m+1))}),[]),r.useEffect(()=>{let o=!0,m=null,x=null;return or().then(()=>{o&&(m=ns(),x=rs())}),()=>{o=!1,m?.(),x?.()}},[s]),r.useEffect(()=>{n&&ar(n)},[n]),n?e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground",children:e.jsx(ss,{apis:n,children:e.jsx(os,{children:e.jsx(as,{children:e.jsx(ma,{})})},s)})})}):e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground"})})}const Wn=document.getElementById("root");if(!Wn)throw new Error("Root element not found");Fn.createRoot(Wn).render(e.jsx(Ce.StrictMode,{children:e.jsx(hs,{children:e.jsx(ps,{children:e.jsx(ga,{apis:on()??void 0})})})}));
|
|
135
|
+
${oe}${ae}`),je.success("Preview console attached to chat")},[P,z,b,K,y,t]),[W,w]=r.useState("unknown"),A=r.useRef(0),X=r.useRef(0),de=r.useRef(""),me=r.useRef(""),we=15e3;r.useEffect(()=>{if(!L){w("unknown"),de.current="",A.current=0,X.current=0;return}let _=!1,oe=null;de.current!==E&&(de.current=E,A.current=Date.now(),X.current=0);const ae=J=>{oe=setTimeout(()=>{_||o()},J)};return w("unknown"),(async()=>{const B=await(async()=>{try{return await tt(L,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(_)return;if(!B){w("unreachable"),ae(5e3);return}const h=fo(B.headers,me.current===E);if(h!=="none"){if(Pe.delete(E),h==="retry-registration")me.current=E,p({status:"loading"}),x();else{const d=await B.json().catch(()=>({}));if(_)return;const N=typeof d?.error=="string"?d.error:`HTTP ${B.status}`;p({status:"error",message:N})}return}if(B.status!==502){me.current="",w("reachable");return}const i=A.current||Date.now();if(Date.now()-i<we){w("starting"),X.current+=1;const d=X.current,N=Math.min(2e3,250*Math.pow(2,Math.min(4,d)));ae(N);return}w("unreachable"),ae(5e3)})(),()=>{_=!0,oe&&clearTimeout(oe)}},[E,L,a]);const k=$&&u.status==="ready"&&(W==="unknown"||W==="starting"),Y=$&&u.status==="ready"&&W==="unreachable",ie=r.useCallback(_=>{if(!$||u.status!=="ready"||typeof window>"u")return;const oe=_.currentTarget.contentWindow;if(oe)try{const ae=oe.location,J=An(L);if(ae.origin!==J||ae.pathname.startsWith(u.proxyBasePath))return;const B=`${u.proxyBasePath}${ae.pathname}${ae.search}${ae.hash}`;oe.location.replace(B)}catch{}},[$,L,u]);return e.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[e.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:se||t,children:se||t||"No preview URL"}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>o(),title:"Reload preview","aria-label":"Reload preview",disabled:!K,children:e.jsx(q,{name:"refresh",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{C&&nt(C)},title:"Open in browser","aria-label":"Open in browser",disabled:!C,children:e.jsx(q,{name:"external-link",className:"h-3.5 w-3.5"})}),$?e.jsx(ge,{type:"button",size:"sm",variant:O?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>te(_=>!_),title:"Inspect preview element","aria-label":"Inspect preview element",disabled:!f,children:e.jsx(q,{name:"cursor",className:"h-3.5 w-3.5"})}):null,$?e.jsxs(ge,{type:"button",size:"sm",variant:T?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>c(_=>!_),title:f?"Open preview console":"Waiting for preview console","aria-label":f?"Open preview console":"Waiting for preview console",disabled:!f&&P.length===0,children:[e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"}),fe>0?e.jsx("span",{className:"typography-micro text-status-error",children:fe}):null]}):null]}),e.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[k?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Starting dev server..."}),e.jsx("div",{className:"text-xs opacity-70",children:"Waiting for the server to accept connections."})]}):Y?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[e.jsx("div",{children:"Dev server is not responding."}),e.jsx("div",{className:"text-xs opacity-70",children:"Make sure your dev server is still running, then retry."}),e.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:()=>o(),children:"Retry"})]}):K&&(!$||W==="reachable")?e.jsxs("div",{className:"relative h-full w-full",children:[e.jsx("iframe",{ref:g,src:K,title:"Preview",className:"h-full w-full border-0",style:{colorScheme:Q},onLoad:ie,sandbox:$?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${K}:${a}`),O&&F?e.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:F.bounds.x,top:F.bounds.y,width:F.bounds.width,height:F.bounds.height},children:e.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[F.tag,F.text?` · ${F.text}`:""]})}):null]}):he?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Connecting preview proxy..."}):ue?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[e.jsx("div",{children:"Could not start preview proxy."}),u.status==="error"?e.jsx("div",{className:"text-center text-xs opacity-70",children:u.message}):null]}):e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:"Preview needs a valid http(s) URL."}),T?e.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[e.jsx("div",{className:"typography-ui-label text-foreground",children:"Preview console"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:I,disabled:P.length===0,children:"Attach"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:pe,disabled:P.length===0,children:"Copy"}),e.jsx(ge,{type:"button",size:"xs",variant:"ghost",onClick:()=>R([]),disabled:P.length===0,children:"Clear"})]})]}),e.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(_=>e.jsx(ge,{type:"button",size:"xs",variant:S===_?"secondary":"ghost",onClick:()=>j(_),children:_==="all"?"All":_==="errors"?"Errors":_==="warnings"?"Warnings":"Logs"},_))}),e.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:P.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No preview console events yet."}):xe.length===0?e.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:"No events match this filter."}):xe.map(_=>e.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:ce("shrink-0 uppercase",_.level==="error"||_.level==="runtime"||_.level==="resource"?"text-status-error":_.level==="warn"?"text-status-warning":"text-muted-foreground"),children:_.level}),e.jsx("span",{className:"min-w-0 break-words text-foreground",children:_.message})]})},_.id))})]}):null]})]})},Rt=t=>t,ft=t=>{const n=Rt(t).type;return typeof n=="string"?n:""},go=t=>{const n=Rt(t).tool;return typeof n=="string"?n:""},xo=t=>{const n=Rt(t).text;return typeof n=="string"?n:""},wo=t=>{const n=ft(t);return n==="tool"?go(t).trim().toLowerCase()||"tool":n||"unknown"},yo=t=>{if(t.length===0)return"";const n=[];for(const s of t){const a=wo(s);n.includes(a)||n.push(a)}return n.join(" + ")},bo=t=>t.replace(/\s+/g," ").trim(),vo=t=>{for(const s of t)if(ft(s)==="text"){const a=bo(xo(s));if(a.length===0)continue;return a}const n=t.filter(s=>ft(s)!=="text").length;return n===0?"":`${n} attachment${n===1?"":"s"}`},jo=(t,n,s)=>`${s(t)} / ${s(n)}`,So=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Co=(t,n)=>{if(!t||!Number.isFinite(t))return"-";const s=So(n);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:s===!1?"2-digit":"numeric",minute:"2-digit",...s===void 0?{}:{hour12:s}})},ko={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},et={user:0,assistant:0,tool:0,other:0},No=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,dt=t=>ht(t),Po=(...t)=>{for(const n of t)if(typeof n=="string"&&n.trim().length>0)return n;return""},ke=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((n,s)=>n+ke(s),0):t&&typeof t=="object"?Object.values(t).reduce((n,s)=>n+ke(s),0):0,Ro=(t,n)=>{const s=t,a=typeof s.type=="string"?s.type:"";if(a==="reasoning")return{...et,assistant:ke(s.text)+ke(s.content)};const o=Po(s.text,s.content,s.value,s.source?.value,s.source?.text?.value);return a==="tool"||n==="tool"?{user:0,assistant:0,tool:ke(s.input)+ke(s.output)+ke(s.error)+ke(s.call?.input)+ke(s.call?.output)+ke(s.call?.error)+ke(s.raw)+Math.round(ke(s.metadata)*.25)+Math.round(ke(s.state)*.1),other:0}:n==="user"?{user:o.length,assistant:0,tool:0,other:0}:n==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Yt=(t,n)=>({user:t.user+n.user,assistant:t.assistant+n.assistant,tool:t.tool+n.tool,other:t.other+n.other}),Eo=t=>{const n=Ke(t.info);return n.isUser?"user":n.role==="assistant"?"assistant":n.role==="tool"?"tool":"other"},To=(t,n)=>{if(t.length===0)return{...et};const s=t.reduce((a,o)=>{const m=Eo(o);let x={...et};for(const u of o.parts)x=Yt(x,Ro(u,m));return Yt(a,x)},{...et});return s.user+=n.length,{user:Math.ceil(s.user/4),assistant:Math.ceil(s.assistant/4),tool:Math.ceil(s.tool/4),other:Math.ceil(s.other/4)}},Ae=t=>t.toLocaleString("en-US"),_o=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),Do=(t,n)=>!t||!Number.isFinite(t)?"-":Or(t,n,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Ao=(t,n,s)=>{const a=t.find(m=>m.id===n),o=a?.models?.find(m=>m.id===s);return{providerName:a?.name||n||"-",modelName:o?.name||s||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},Mo=()=>{const t=ee(c=>c.timeFormatPreference),[n,s]=r.useState({}),{value:a,show:o,clear:m}=Mr(null,2e3),x=Se(c=>c.currentSessionId),u=Se(c=>c.currentSessionDirectory),p=Ir(),g=dn(x??""),v=Ie(c=>c.providers);r.useEffect(()=>{s(c=>Object.keys(c).length>0?{}:c),m()},[m,u,x]);const f=r.useCallback(async(c,S)=>{(await gt(S)).ok?o(c):m()},[m,o]),l=r.useMemo(()=>{const c=x?p.find(L=>L.id===x)??null:null,S=g.filter(L=>Ke(L.info).role==="assistant"),j=g.filter(L=>Ke(L.info).isUser);let P=null;for(let L=S.length-1;L>=0;L-=1){const K=S[L];if(dt(K).total>0){P=K;break}}const R=P?dt(P):ko,O=P?.info?.usage,te=un({input:R.input,cache:{read:R.cacheRead,write:R.cacheWrite}}),F=S.reduce((L,K)=>{const se=No(K.info.cost);return L+se},0),re=P?.info?.model??null,z=Ao(v,re?.providerID||"",re?.modelID||""),y=z.contextLimit,b=O?hn(O):R.total,G=y&&y>0?Math.min(999,b/y*100):0,H=[...g].reverse().find(L=>Ke(L.info).isUser&&typeof L.info.system=="string")?.info?.system||"",$=To(g,H),V=$.user,ne=$.assistant,E=$.tool,Q=O?0:Math.max(0,R.input-V-ne-E),C=V+ne+E+Q,M=g[0]?.info?.time?.created,U=g.length>0?g[g.length-1]?.info?.time?.created:null;return{sessionTitle:Cn(c),messagesCount:g.length,userMessagesCount:j.length,assistantMessagesCount:S.length,createdAt:c?.time?.created??M??null,lastActivityAt:U??c?.time?.created??null,providerModel:z,tokenBreakdown:R,usagePercent:G,cacheHitRate:te,totalAssistantCost:F,contextLimit:y,contextWindowTokens:b,hasUsage:O!==void 0,breakdown:{user:V,assistant:ne,tool:E,other:Q},breakdownTotal:C}},[x,v,g,p]);if(!x)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:"Open a session to inspect context."});const T=[{key:"user",label:"User",value:l.breakdown.user,color:"var(--status-success)"},{key:"assistant",label:"Assistant",value:l.breakdown.assistant,color:"var(--primary-base)"},{key:"tool",label:"Tool Calls",value:l.breakdown.tool,color:"var(--status-warning)"},...l.hasUsage?[]:[{key:"other",label:"Other",value:l.breakdown.other,color:"var(--surface-muted-foreground)"}]];return e.jsx("div",{className:"h-full overflow-y-auto bg-background",children:e.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:l.sessionTitle}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[e.jsxs("span",{children:[l.providerModel.providerName," / ",l.providerModel.modelName]}),l.createdAt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:Do(l.createdAt,t)})]})]})]}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Context"}),e.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ae(l.contextWindowTokens),l.contextLimit?` / ${Ae(l.contextLimit)}`:""]})]}),e.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:l.usagePercent>0&&e.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,l.usagePercent)}%`,backgroundColor:l.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}})}),e.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:`${l.usagePercent.toFixed(1)}% used`})]}),e.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:[{label:"Messages",value:Ae(l.messagesCount)},{label:"User",value:Ae(l.userMessagesCount)},{label:"Assistant",value:Ae(l.assistantMessagesCount)},{label:"Cost",value:_o(l.totalAssistantCost)}].map(c=>e.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value})]},c.label))}),e.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[e.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:"Last Assistant Message"}),e.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:"Input",value:l.tokenBreakdown.input,format:"count"},{label:"Output",value:l.tokenBreakdown.output,format:"count"},{label:"Reasoning",value:l.tokenBreakdown.reasoning,format:"count"},{label:"Cache Read",value:l.tokenBreakdown.cacheRead,format:"count"},{label:"Cache Write",value:l.tokenBreakdown.cacheWrite,format:"count"},{label:"Cache Hit",value:l.cacheHitRate.hasInput?l.cacheHitRate.percent:null,format:"percent"}].map(c=>e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c.label}),e.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:c.value!==null&&c.value!==void 0?c.format==="percent"?`${c.value.toFixed(1)}%`:Ae(c.value):"—"})]},c.label))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:T.map(c=>c.value<=0||l.breakdownTotal<=0?null:e.jsx("div",{style:{width:`${c.value/l.breakdownTotal*100}%`,backgroundColor:c.color}},c.key))}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:T.map(c=>{const S=l.breakdownTotal>0?c.value/l.breakdownTotal*100:0;return e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:c.color}}),e.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[c.label," ",e.jsxs("span",{className:"tabular-nums",children:[S.toFixed(0),"%"]})]})]},c.key)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"typography-micro text-muted-foreground",children:"Raw Messages"}),e.jsx("div",{className:"mt-2.5 space-y-1",children:[...g].reverse().map(c=>{const j=Ke(c.info).role,P=j==="assistant",R=j==="user",O=n[c.info.id]===!0,te=a===c.info.id,F=c.info.time?.created??null,re=yo(c.parts),z=P?dt({info:c.info,parts:c.parts}):null,y=R?vo(c.parts):"",b=Co(F,t),G=re||"—",H=z?jo(z.input,z.output,Ae):"",$=j||"unknown",V=re?`${$}: ${re}`:$,ne=O?JSON.stringify({info:c.info,parts:c.parts},null,2):"";return e.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[e.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":O,onClick:()=>{s(E=>({...E,[c.info.id]:E[c.info.id]!==!0}))},children:e.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:P?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[R?e.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",y]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:P?G:V}),P&&e.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:H})]}),e.jsx("span",{className:"text-right text-muted-foreground",children:b})]})}),O&&e.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:e.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[e.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:e.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:E=>{E.stopPropagation(),f(c.info.id,ne)},"aria-label":te?"Copied":"Copy JSON",title:te?"Copied":"Copy",children:te?e.jsx(q,{name:"check",className:"size-3.5"}):e.jsx(q,{name:"file-copy",className:"size-3.5"})})}),e.jsx(Lr,{language:"json",code:ne,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},c.info.id)})})]})]})})},Io=De(()=>Ee(()=>import("./DiffView-DVd1MLPB.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),Lo=De(()=>Ee(()=>import("./FilesView-CPnW4I90.js"),__vite__mapDeps([120,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),Oo=De(()=>Ee(()=>import("./GitView-Dj_7hgX_.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),$o=380,Wo=1400,On=600,Fo=100,Bo=24,Jt=t=>Number.isFinite(t)?Math.min(Wo,Math.max($o,Math.round(t))):On,zo=t=>{const n=t?.parentElement?.clientWidth;return!n||n<=0?null:n},Uo=(t,n)=>{if(!t)return"";const s=t.replace(/\\/g,"/"),a=n.replace(/\\/g,"/").replace(/\/+$/,"");return a&&s.startsWith(a+"/")?s.slice(a.length+1):s},$n=(t,n=null)=>t==="file"?"Files":t==="diff"?"Changes":t==="preview"?"Preview":t==="browser"?"Browser":t==="git"?St(n).label:t==="terminal"?"Terminal":"Context",Ho=t=>{if(!t)return null;const n=t.replace(/\\/g,"/").trim();if(!n)return null;const s=n.split("/").filter(Boolean);return s.length===0?n:s[s.length-1]||null},Vo=(t,n=null)=>{if(t.label)return t.label;if(t.mode==="file")return Ho(t.targetPath)||"Files";if(t.mode==="preview"){const s=t.targetPath;if(s)try{const a=new URL(s);return a.host||a.hostname||"Preview"}catch{}return"Preview"}return t.mode==="diff"?"Changes":$n(t.mode,n)},Qt=(t,n=null)=>{if(t.mode==="file")return t.targetPath?e.jsx(mt,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return e.jsx(pr,{className:"h-3.5 w-3.5"});if(t.mode==="git")return e.jsx(q,{name:St(n).icon,className:"h-3.5 w-3.5"});if(t.mode==="terminal")return e.jsx(q,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="context")return e.jsx(q,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="preview")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return e.jsx(q,{name:"global",className:"h-3.5 w-3.5"})},Ko=(t,n)=>t.length<=n?t:`${t.slice(0,n-3)}...`,Xo=()=>{const t=Ge()??"",n=r.useMemo(()=>Re(t),[t]),s=ee(d=>n?d.contextPanelByDirectory[n]:void 0),a=ee(d=>d.closeContextPanel),o=ee(d=>d.closeContextPanelTab),m=ee(d=>d.openContextPanelTab),x=ee(d=>d.toggleContextPanelExpanded),u=ee(d=>d.setContextPanelWidth),p=ee(d=>d.setActiveContextPanelTab),g=ee(d=>d.reorderContextPanelTabs),v=Te(d=>d.setSelectedPath),f=ee(d=>d.openContextPreview),l=ee(d=>d.contextEditorTreeVisible),T=ee(d=>d.toggleContextEditorTree),c=r.useMemo(()=>s?.tabs??[],[s?.tabs]),S=c.find(d=>d.id===s?.activeTabId)??c[c.length-1]??null,j=!!(s?.isOpen&&S),P=!!(j&&s?.expanded),[R,O]=r.useState(null),te=s?.width,F=Wr,re=R??(typeof window<"u"?window.innerWidth:On*2),z=Jt(te??Math.round(F*re)),y=pn(n||null),[b,G]=r.useState(!1),[H,$]=r.useState(null),[V,ne]=r.useState(null),[E,Q]=r.useState(null),C=r.useRef(0),M=r.useRef(z),U=r.useRef(null),L=r.useRef(null),K=r.useRef(null),se=r.useRef(!1);r.useLayoutEffect(()=>{const d=K.current?.parentElement;if(!d||typeof ResizeObserver>"u")return;const N=new ResizeObserver(()=>{O(d.clientWidth||null)});return N.observe(d),O(d.clientWidth||null),()=>N.disconnect()},[]),r.useEffect(()=>{if(!j||se.current){se.current=j;return}const d=window.requestAnimationFrame(()=>{K.current?.focus({preventScroll:!0})});return se.current=!0,()=>window.cancelAnimationFrame(d)},[j]);const he=r.useRef(null),ue=r.useRef(null),be=r.useCallback(()=>{ue.current=null;const d=K.current,N=U.current;!d||N===null||d.style.setProperty("--oc-context-panel-width",`${N}px`)},[]);r.useEffect(()=>()=>{ue.current!==null&&clearTimeout(ue.current)},[]);const fe=r.useCallback(d=>{const N=Jt(d),le=he.current;return le===null?N:Math.min(N,Math.max(1,le))},[]),xe=r.useCallback(d=>{!j||P||!n||(L.current=d.pointerId,G(!0),C.current=d.clientX,M.current=z,U.current=z,he.current=zo(K.current),document.documentElement.style.cursor="col-resize",d.preventDefault())},[n,P,j,z]),pe=r.useCallback(()=>{const d=fe(U.current??z);U.current=null,he.current=null,ue.current!==null&&(clearTimeout(ue.current),ue.current=null),document.documentElement.style.cursor="",n&&u(n,d),G(!1),L.current=null},[fe,n,u,z]);r.useEffect(()=>{if(!b)return;const d=Z=>{if(L.current!==Z.pointerId)return;const ye=C.current-Z.clientX,ve=fe(M.current+ye);U.current!==ve&&(U.current=ve,ue.current===null&&(ue.current=setTimeout(be,Fo)))},N=Z=>{L.current===Z.pointerId&&pe()},le=()=>{pe()};return window.addEventListener("pointermove",d),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N),window.addEventListener("blur",le),()=>{window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),window.removeEventListener("blur",le)}},[be,fe,pe,b]),r.useEffect(()=>{b||(U.current=null,document.documentElement.style.cursor="")},[b]);const I=r.useCallback(()=>{n&&a(n)},[a,n]),W=r.useCallback(()=>{n&&x(n)},[n,x]),w=r.useCallback(d=>{d.key==="Escape"&&($r(d.target)||(d.preventDefault(),d.stopPropagation(),I()))},[I]);r.useEffect(()=>{if(!(!n||!S)&&S.mode==="file"&&S.targetPath){v(n,S.targetPath,{allowOutsideRoot:!0});return}},[S,n,v]);const A=r.useCallback(d=>{!n||S?.mode!=="diff"||m(n,{mode:"diff",targetPath:S.targetPath,stagedDiff:d==="staged",diffScope:d})},[S,n,m]),X=S?.mode==="file"||S?.mode==="preview",de=r.useMemo(()=>S?c.filter(d=>d.mode===S.mode):[],[S,c]),me=r.useMemo(()=>de.map(d=>{const N=Vo(d,y),le=Ko(N,Bo),Z=Uo(d.targetPath,t);return{id:d.id,label:le,icon:Qt(d,y),title:Z?`${N}: ${Z}`:N,closeLabel:`Close ${le} tab`}}),[de,t,y]),we=S?.mode==="context"?e.jsx(Mo,{}):S?.mode==="git"?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Oo,{isActive:j,gitHeaderSlot:S?.mode==="git"?V:null})}):S?.mode==="preview"?e.jsx(mo,{rawUrl:S.targetPath??"",onNavigate:d=>f(t,d)}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"Preview"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Use Project Actions or a terminal Preview button to open a preview."})]}),k=r.useMemo(()=>c.filter(d=>d.mode==="browser"),[c]),Y=r.useMemo(()=>c.filter(d=>d.mode==="diff"),[c]),ie=r.useMemo(()=>c.some(d=>d.mode==="terminal"),[c]),_=r.useMemo(()=>c.some(d=>d.mode==="file"),[c]),oe=r.useMemo(()=>c.some(d=>d.mode==="file"&&d.targetPath),[c]),ae=S?.mode==="file",J=S?.mode==="terminal",B=S?.mode==="git",h=S?.mode==="diff",i=e.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[X?e.jsx(Ts,{items:me,activeId:S?.id??null,onSelect:d=>{n&&p(n,d)},onClose:d=>{n&&o(n,d)},onReorder:(d,N)=>{n&&g(n,d,N)},layoutMode:"scrollable",variant:"default"}):J?e.jsx("div",{ref:d=>{$(d)},className:"flex min-w-0 flex-1 items-center px-1"}):B?e.jsx("div",{ref:d=>{ne(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):h?e.jsx("div",{ref:d=>{Q(d)},className:"flex min-w-0 flex-1 items-center overflow-hidden px-1"}):e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[S?Qt(S,y):null,e.jsx("span",{className:"truncate typography-ui-label text-foreground",children:S?$n(S.mode,y):null})]}),e.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[ae?e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:T,className:"h-7 w-7 p-0",title:"Toggle file tree","aria-label":"Toggle file tree","aria-pressed":l,children:e.jsx(q,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:W,className:"h-7 w-7 p-0",title:P?"Collapse panel":"Expand panel","aria-label":P?"Collapse panel":"Expand panel",children:P?e.jsx(q,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):e.jsx(q,{name:"fullscreen",className:"h-3.5 w-3.5"})}),e.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:I,className:"h-7 w-7 p-0",title:"Close panel","aria-label":"Close panel",children:e.jsx(q,{name:"close",className:"h-3.5 w-3.5"})})]})]}),D=j?P?{"--oc-context-panel-width":R!==null?`${R}px`:"100%",width:R!==null?`${R}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${z}px`}:{"--oc-context-panel-width":`${z}px`,width:0,maxWidth:"100%",overflowX:"clip"};return e.jsxs("aside",{ref:K,"data-context-panel":"true",tabIndex:-1,inert:!j||void 0,className:ce("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!j&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:w,style:D,children:[j&&!P&&e.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),j&&e.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&e.jsx("div",{className:ce("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",b&&"bg-[var(--interactive-border)]"),onPointerDown:xe,role:"separator","aria-orientation":"vertical","aria-label":"Resize context panel"}),e.jsxs("div",{className:ce("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!j&&"pointer-events-none select-none opacity-0"),style:{width:P?R!==null?`${R}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!j,children:[i,e.jsxs("div",{className:ce("relative min-h-0 flex-1 overflow-hidden",b&&"pointer-events-none"),children:[_?e.jsxs("div",{className:ce("absolute inset-0 flex",ae?"flex":"hidden"),children:[e.jsx("div",{className:"h-full min-w-0 flex-1",children:oe?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Lo,{mode:"editor-only"})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(q,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),e.jsx("div",{className:"typography-ui-header text-foreground",children:"No file open"}),e.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:"Pick a file from the tree to start editing."})]})}),e.jsx(uo,{visible:l})]}):null,k.map(d=>e.jsx("div",{className:ce("absolute inset-0",S?.id!==d.id&&"hidden"),children:e.jsx(eo,{initialUrl:d.targetPath??"",directory:n,tabID:d.id})},d.id)),j?Y.filter(d=>S?.id===d.id).map(d=>e.jsx("div",{className:"absolute inset-0",children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(Io,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:d.diffScope??(d.stagedDiff?"staged":"working"),onDiffScopeChange:A,targetFilePath:d.targetPath,flushContent:!0,toolbarSlot:h?E:null})})},d.id)):null,ie?e.jsx("div",{className:ce("absolute inset-0",S?.mode==="terminal"?"block":"hidden"),children:e.jsx(an,{visible:j&&S?.mode==="terminal",terminalHeaderSlot:J?H:null})}):null,j&&!ae&&S?.mode!=="browser"&&S?.mode!=="diff"&&S?.mode!=="terminal"?we:null]})]})]})},qo=150,Go=500,Yo=[],Me=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t),Je=(t,n)=>{if(!t||typeof t!="object")return;const s=t[n];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Jo=t=>t>99?"99+":String(t),Qo=t=>t>=90?"text-[var(--status-error)]":t>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",Zo=({surface:t,isActive:n,showActivityDot:s,label:a,description:o,badgeCount:m,badgeAriaLabel:x,badgeDescription:u,orderNumber:p,showOrderNumber:g,onSelect:v,chartPercentage:f,chartDetails:l})=>{const{attributes:T,listeners:c,setNodeRef:S,transform:j,transition:P,isDragging:R}=jn({id:t.id}),O=m!=null&&m>0?Jo(m):null;return e.jsx("div",{ref:S,style:{transform:Sn.Translate.toString(j),transition:P},className:ce("relative",R&&"z-10 opacity-70"),children:e.jsxs(Oe,{delayDuration:qo,children:[e.jsx($e,{asChild:!0,children:e.jsxs("button",{type:"button",...T,...c,onClick:()=>v(t),"aria-label":x??a,"aria-pressed":n,className:ce("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",n?"text-primary":"text-muted-foreground hover:text-foreground"),children:[t.id==="context"&&typeof f=="number"?e.jsx(It,{percentage:f,className:"size-[18px] -rotate-90"}):e.jsx(q,{name:t.icon,className:"h-[18px] w-[18px]"}),g&&p!=null?e.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:p===10?"0":p}):O?e.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:O}):s?e.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null]})}),e.jsx(We,{side:"left",sideOffset:8,className:t.id==="context"&&l?"p-0 border-0 bg-transparent shadow-none":void 0,children:t.id==="context"&&l?e.jsx("div",{className:"w-[300px] overflow-hidden rounded-lg border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_8px_24px_rgb(0_0_0_/_0.18)]",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[e.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:e.jsx(It,{percentage:l.percentage,className:"size-[18px] -rotate-90"})}),e.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:a}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:l.hasData?e.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[e.jsxs("span",{className:ce("font-semibold",Qo(l.percentage)),children:[l.percentage.toFixed(1),"%"]}),e.jsx("span",{className:"text-muted-foreground",children:`${Me(l.totalTokens)}/${Me(l.contextLimit)}`})]}):e.jsx("span",{className:"typography-micro text-muted-foreground",children:"No data yet"})})]}),l.hasData?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.totalTokens)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.contextLimit)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.outputLimit)})]}),typeof l.cacheRead=="number"&&typeof l.cacheWrite=="number"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheRead)})]}),e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:Me(l.cacheWrite)})]})]}):null,typeof l.cacheHitPercent=="number"?e.jsxs("div",{className:"flex justify-between rounded-xl px-2.5 py-1.5 typography-micro",children:[e.jsx("span",{className:"text-muted-foreground",children:"Cache hit"}),e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:`${l.cacheHitPercent.toFixed(1)}%`})]}):null]}):e.jsx("div",{className:"px-2.5 py-2 typography-micro text-muted-foreground",children:o})]})}):e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{children:a}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:o}),u?e.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null]})})]})})},ea=()=>{const t=Ge(),n=t?qn(t):"",s=ee(w=>n?w.contextPanelByDirectory[n]:void 0),a=ee(w=>w.contextRailOrder),o=ee(w=>w.setContextRailOrder),m=ee(w=>w.openContextSurface),x=ee(w=>w.shortcutOverrides),{screenWidth:u}=st(),{git:p}=xt(),g=cn(n||null),v=pn(n||null),f=fn(w=>w.ensureStatus);r.useEffect(()=>{n&&f(n,p)},[n,f,p]);const l=r.useMemo(()=>Gn("switch_context_surface",x),[x]),[T,c]=r.useState(!1);r.useEffect(()=>{const w=new Set;let A=null,X=!1;const de=ie=>ie.length===1&&ie>="0"&&ie<="9",me=()=>{Et(l,w)?!X&&A===null&&(A=setTimeout(()=>c(!0),Go)):(X=!1,A!==null&&(clearTimeout(A),A=null),c(!1))},we=ie=>{if(w.add(ie.key.toLowerCase()),de(ie.key)&&Et(l,w)){X=!0,A!==null&&(clearTimeout(A),A=null),c(!1);return}me()},k=ie=>{w.delete(ie.key.toLowerCase()),me()},Y=()=>{w.clear(),X=!1,A!==null&&(clearTimeout(A),A=null),c(!1)};return window.addEventListener("keydown",we,!0),window.addEventListener("keyup",k,!0),window.addEventListener("blur",Y),()=>{window.removeEventListener("keydown",we,!0),window.removeEventListener("keyup",k,!0),window.removeEventListener("blur",Y),A!==null&&clearTimeout(A)}},[l]);const S=wn(pt(js,{activationConstraint:{distance:8}}),pt(vs,{activationConstraint:{delay:200,tolerance:6}})),j=s?.tabs??Yo,P=j.find(w=>w.id===s?.activeTabId)??null,R=s?.isOpen?P?.mode??null:null,O=g?.files.length??0,te=Se(w=>w.currentSessionId),F=Se(w=>!!w.newSessionDraft?.open),re=Ie(w=>w.providers),z=Ie(w=>w.currentProviderId),y=Ie(w=>w.currentModelId),b=Ie(w=>w.getCurrentModel()),G=Ie(w=>w.getModelMetadata);Ie(w=>w.modelsMetadata.size);const H=Fr(r.useCallback(w=>te?w.sessionModelSelections.get(te)??null:null,[te])),$=dn(te??""),V=r.useMemo(()=>{for(let w=$.length-1;w>=0;w-=1){const A=$[w];if(A?.info.role==="assistant")try{if(ht(A).total>0)return A}catch{continue}}return null},[$]),E=r.useMemo(()=>{for(let w=$.length-1;w>=0;w-=1){const A=$[w]?.info;if(A.role!=="user")continue;const X=A.model,de=X?.providerID??X?.providerId,me=X?.modelID??X?.modelId;if(typeof de=="string"&&de.trim()&&typeof me=="string"&&me.trim())return{providerID:de,modelID:me}}return null},[$])??(()=>{const w=V?.info.model,A=w?.providerID??w?.providerId,X=w?.modelID??w?.modelId;return A&&X?{providerID:A,modelID:X}:null})()??(H?{providerID:H.providerId,modelID:H.modelId}:null)??(z&&y?{providerID:z,modelID:y}:null),C=(E?re.find(w=>w.id===E.providerID):void 0)?.models.find(w=>w.id===E?.modelID),M=E?G(E.providerID,E.modelID):void 0,U=Je(C?.limit,"context")??M?.limit?.context??Je(b?.limit,"context")??0,L=Je(C?.limit,"output")??M?.limit?.output??Je(b?.limit,"output")??0,K=V?(()=>{try{return ht(V)}catch{return null}})():null,se=V?.info?.usage,he=se?hn(se):K?.total??0,ue=!F&&he>0&&U>0?Math.min(he/U*100,999):0,be=ue,fe=K?un({input:K.input,cache:{read:K.cacheRead,write:K.cacheWrite}}):null,xe=fe?.hasInput?fe.percent:null,pe=r.useMemo(()=>{const w=!!V&&he>0&&U>0;return{percentage:ue,totalTokens:he,contextLimit:U,outputLimit:L,cacheRead:K?.cacheRead??null,cacheWrite:K?.cacheWrite??null,cacheHitPercent:xe,hasData:w}},[K,xe,U,V,L,ue,he]),I=r.useMemo(()=>Br({railOrder:a,tabs:j}),[a,u,j]),W=r.useCallback(w=>{const{active:A,over:X}=w;if(!X||A.id===X.id)return;const de=zr(ee.getState().contextRailOrder).map(k=>k.id),me=de.indexOf(A.id),we=de.indexOf(X.id);me===-1||we===-1||o(Cs(de,me,we))},[o]);return n?e.jsx("nav",{"aria-label":"Panel surfaces",className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:e.jsx(yn,{sensors:S,collisionDetection:bn,onDragEnd:W,children:e.jsx(vn,{items:I.map(w=>w.id),strategy:ks,children:I.map((w,A)=>{const X=w.id==="git"?St(v):null,de=X?{...w,...X}:w,me=de.label,we=w.id==="git"&&v===!0?O:0,k=we>0?we:null,Y=w.id==="context";return e.jsx(Zo,{surface:de,isActive:R===w.mode,showActivityDot:!1,label:me,description:de.description,badgeCount:k,badgeAriaLabel:k!==null?k===1?`${me}, ${k} changed file`:`${me}, ${k} changed files`:null,badgeDescription:k!==null?k===1?`${k} changed file`:`${k} changed files`:null,chartPercentage:Y?be:void 0,chartDetails:Y?pe:void 0,orderNumber:A+1,showOrderNumber:T,onSelect:ie=>m(n,ie.mode)},w.id)})})})}):null},ta=(t,n)=>!t||n.length===0?"":JSON.stringify([t,n]),na=(t,n,s,a)=>!s||a!==s||t.length===0?[]:Ve(t,n,o=>o.name,{limit:10,threshold:.4}),ra=new Set,ut=t=>{if(!t)return"";const n=t.replace(/\\/g,"/"),s=n.startsWith("//");let a=n.replace(/\/+/g,"/");s&&!a.startsWith("//")&&(a=`/${a}`);const o=a==="/",m=/^[A-Za-z]:\/$/.test(a);return!o&&!m&&(a=a.replace(/\/+$/,"")),a},sa=()=>{const t=ee(h=>h.isCommandPaletteOpen),n=ee(h=>h.setCommandPaletteOpen),s=ee(h=>h.setActiveMainTab),a=ee(h=>h.setSettingsDialogOpen),o=ee(h=>h.setSettingsPage),m=ee(h=>h.setSessionSwitcherOpen),x=ee(h=>h.toggleSidebar),u=ee(h=>h.openContextOverview),p=ee(h=>h.openContextSurface),g=ee(h=>h.openContextFile),v=ee(h=>h.shortcutOverrides),f=Se(h=>h.openNewSessionDraft),l=Se(h=>h.setCurrentSession),T=Ur({archived:!1}),c=Hr(r.useCallback(h=>t?h.ids:ra,[t])),S=Vr(r.useCallback(h=>t?h.rankById:Kr,[t])),j=Yn(h=>h.currentDirectory),P=Lt(h=>h.getActiveProject()),R=Lt(h=>h.projects),O=Ge(),te=Jn(h=>h.searchFiles),{files:F,git:re}=xt(),z=fn(h=>h.ensureStatus),{isMobile:y}=st(),b=r.useMemo(()=>O?ut(O):null,[O]),[G,H]=r.useState(""),V=Xr(G,200).trim(),ne=G.trim();r.useEffect(()=>{t&&H("")},[t]),r.useEffect(()=>{if(!t||!re)return;const h=setTimeout(()=>{const i=new Set;for(const D of T){const d=at(D);!d||i.has(d)||(i.add(d),z(d,re))}},0);return()=>clearTimeout(h)},[t,T,re,z]);const E=r.useCallback(()=>n(!1),[n]),Q=r.useCallback(h=>()=>{E(),h()},[E]),C=r.useMemo(()=>{const h=[{id:"new-session",title:"New Session",icon:e.jsx(q,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:"New Session",onSelect:Q(()=>{s("chat"),m(!1),f()})},{id:"add-project",title:"Add Project",icon:e.jsx(q,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:"Add Project",onSelect:Q(()=>{qr.requestDirectoryDialog()})},{id:"toggle-sidebar",title:y?"Show Session Switcher":"Toggle Sidebar",icon:e.jsx(q,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:y?"Show Session Switcher":"Toggle Sidebar",onSelect:Q(()=>{if(y){const{isSessionSwitcherOpen:i}=ee.getState();m(!i)}else x()})},{id:"toggle-terminal",title:"Toggle Terminal",icon:e.jsx(q,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:"Toggle Terminal",onSelect:Q(()=>{j&&p(j,"terminal")})},{id:"context-usage",title:"Show Context Usage",icon:e.jsx(q,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:"Show Context Usage",onSelect:Q(()=>{j&&u(j)})},{id:"open-settings",title:"Open Settings...",icon:e.jsx(q,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:"Open Settings...",onSelect:Q(()=>a(!0))}];return Qn()&&h.splice(1,0,{id:"new-mini-chat",title:"New Mini Chat Window",icon:e.jsx(q,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:"New Mini Chat Window",onSelect:Q(()=>{en("desktop_open_draft_mini_chat_window",{directory:ut(j||P?.path||""),projectId:P?.id??null}).catch(i=>{console.warn("[command-palette] failed to open draft mini chat window",i)})})}),h},[Q,y,s,m,f,x,p,j,u,a,P?.id,P?.path]),M=r.useMemo(()=>{const h=Zn();return{isWeb:!h&&er(),isDesktop:h,isMobile:y}},[y]),U=r.useMemo(()=>fr.filter(h=>h.slug!=="home").filter(h=>h.isAvailable?h.isAvailable(M):!0).map(h=>{const i=mr(h.slug)??"settings-3",D=(h.keywords??[]).join(" ");return{id:`settings:${h.slug}`,title:h.title,icon:e.jsx(q,{name:i,className:"mr-2 h-4 w-4"}),searchText:`${h.title} ${h.group} ${D}`,onSelect:Q(()=>{o(h.slug),a(!0)})}}),[M,Q,o,a]),L=r.useMemo(()=>Gr(T,c,S),[T,c,S]),K=Yr(),se=r.useCallback((h,i)=>i&&K.get(i)?.trim()||null,[K]),[he,ue]=r.useState([]),[be,fe]=r.useState(""),xe=ta(b,V);r.useEffect(()=>{if(!t){ue([]),fe("");return}if(!xe){ue([]),fe("");return}if(!b){ue([]),fe("");return}let h=!1;return te(b,V,10,{type:"file"}).then(i=>{h||(ue(i.map(D=>({path:ut(D.path),name:D.name,relativePath:D.relativePath}))),fe(xe))}).catch(()=>{h||(ue([]),fe(xe))}),()=>{h=!0}},[t,b,V,xe,te]);const pe=ne.length>0,I=r.useMemo(()=>pe?Ve(C,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):C.map(h=>({item:h,score:0})),[C,ne,pe]),W=r.useMemo(()=>pe?Ve(U,ne,h=>h.searchText,{limit:7,noFuzzy:!0}):[],[U,ne,pe]),w=r.useMemo(()=>pe?Ve(L,ne,h=>h.title||"",{limit:7,threshold:.2}):L.slice(0,5).map(h=>({item:h,score:0})),[L,ne,pe]),A=r.useMemo(()=>t?na(he,V,xe,be):[],[t,he,be,xe,V]),X=t&&xe.length>0&&be!==xe,de=r.useMemo(()=>{if(!pe)return[];const h=R.map(i=>({...i,displayName:i.label||i.path.split("/").pop()||i.path,searchText:`${i.label||""} ${i.path}`}));return Ve(h,ne,i=>i.searchText,{limit:7,threshold:.4})},[R,ne,pe]),me=I.map(h=>h.item),we=W.map(h=>h.item),k=w.map(h=>h.item),Y=pe?A.map(h=>h.item):[],ie=pe?de.map(h=>h.item):[],_=r.useMemo(()=>{if(!pe)return["commands","sessions"];const h=D=>D.length?D[0].score:1/0,i=[{key:"commands",score:h(I)},{key:"settings",score:h(W)},{key:"sessions",score:h(w)},{key:"files",score:h(A)},{key:"projects",score:h(de)}];return i.sort((D,d)=>D.score-d.score),i.map(D=>D.key)},[pe,I,W,w,A,de]),oe=r.useCallback(h=>{E(),l(h.id,at(h))},[E,l]),ae=r.useCallback(async h=>{if(!b)return;const i=await mn(F,h,{directory:b});if(!i.ok){je.error(gn(i.reason));return}g(b,h),E()},[b,F,g,E]),J=r.useCallback((h,i)=>{E(),f({selectedProjectId:h,directoryOverride:i})},[E,f]),B=r.useCallback(h=>rn(sn(h,v)),[v]);return e.jsxs(wt,{open:t,onOpenChange:n,children:[e.jsxs(bt,{className:"sr-only",children:[e.jsx(vt,{children:"Command Palette"}),e.jsx(jt,{children:"Search files, sessions, and commands."})]}),e.jsx(yt,{className:"overflow-hidden p-0",showCloseButton:!0,children:e.jsxs(Jr,{shouldFilter:!1,className:"[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta",children:[e.jsx(Qr,{value:G,onValueChange:H,placeholder:"Search files, sessions, commands..."}),e.jsxs(Zr,{children:[e.jsx(es,{children:"No results found."}),_.map(h=>h==="commands"&&me.length>0?e.jsx(Ue,{children:me.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title}),i.shortcutId?e.jsx(ts,{children:B(i.shortcutId)}):null]},i.id))},"commands"):h==="settings"&&we.length>0?e.jsx(Ue,{children:we.map(i=>e.jsxs(He,{value:i.id,onSelect:i.onSelect,children:[i.icon,e.jsx("span",{children:i.title})]},i.id))},"settings"):h==="sessions"&&k.length>0?e.jsx(Ue,{children:k.map(i=>{const D=Cn(i),d=at(i),N=se(i.id,d);return e.jsxs(He,{value:`session:${i.id}`,onSelect:()=>oe(i),children:[e.jsx(q,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),N?e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[e.jsx(q,{name:"git-branch",className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[160px]",children:N})]}):null]},i.id)})},"sessions"):h==="files"&&Y.length>0?e.jsx(Ue,{children:Y.map(i=>{const D=tr(i.relativePath||i.name,{maxLength:80});return e.jsxs(He,{value:`file:${i.path}`,onSelect:()=>{ae(i.path)},children:[e.jsx(mt,{filePath:i.path,className:"mr-2 size-4 shrink-0"}),e.jsx("span",{className:"truncate","aria-label":i.relativePath,children:D})]},`file:${i.path}`)})},"files"):h==="projects"&&ie.length>0?e.jsx(Ue,{children:ie.map(i=>{const D=i.displayName;return e.jsxs(He,{value:`project:${i.id}`,onSelect:()=>J(i.id,i.path),children:[e.jsx(q,{name:"folder",className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"truncate",children:D}),e.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:i.path})]},`project:${i.id}`)})},"projects"):null),X?e.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:"Searching files..."}):null]})]})})]})},oa=(t,n,s)=>rr(t)?rn(sn(t,s)):n,aa=()=>{const t=ee(m=>m.isHelpDialogOpen),n=ee(m=>m.setHelpDialogOpen),s=ee(m=>m.shortcutOverrides),a=nr(),o=[{categoryKey:"Navigation & Commands",items:[{id:"open_command_palette",descriptionKey:"Open Command Palette",icon:"command",keys:""},{id:"open_help",descriptionKey:"Show Keyboard Shortcuts (this dialog)",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"Toggle Session Sidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"Add Selection to Chat",icon:"add",keys:""},{id:"open_model_selector",descriptionKey:"Open Model Selector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"Navigate Models (in picker)",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"Adjust Thinking Mode (in picker, when supported)",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"Cycle thinking (global shortcut)",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${a} + N`],descriptionKey:"New Window (desktop only)",icon:"window"}]},{categoryKey:"Session Management",items:[{id:"new_chat",descriptionKey:"Create New Session",icon:"add",keys:""},{id:"focus_input",descriptionKey:"Focus Chat Input",icon:"text",keys:""},{id:"cycle_session_folder",descriptionKey:"Cycle session folder",icon:"folder-open",keys:""},{id:"cycle_draft_folder",descriptionKey:"Cycle draft folder",icon:"folder-3",keys:""},{id:"open_timeline_dialog",descriptionKey:"Open conversation timeline",icon:"history",keys:""},{id:"abort_run",descriptionKey:"Abort active run (double press)",icon:"close-circle",keys:""}]},{categoryKey:"Panels",items:[{id:"open_right_sidebar",descriptionKey:"Open right sidebar",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{keys:[`${a} + 1...0`],descriptionKey:"Switch Context Panel Surface (number key)",icon:"layout-right"}]},{categoryKey:"Interface",items:[{id:"cycle_theme",descriptionKey:"Cycle Theme (Light → Dark → System)",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"Open Settings",icon:"settings-3",keys:""}]}];return e.jsx(wt,{open:t,onOpenChange:n,children:e.jsxs(yt,{className:"w-[92vw] max-w-[1120px] h-[84vh] max-h-[900px] flex flex-col overflow-hidden",children:[e.jsxs(bt,{children:[e.jsxs(vt,{className:"flex items-center gap-2",children:[e.jsx(q,{name:"command",className:"h-5 w-5"}),"Keyboard Shortcuts"]}),e.jsx(jt,{children:"Use these keyboard shortcuts to navigate PiChamber efficiently"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-3 pr-1",children:e.jsx("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-x-10",children:o.map(m=>e.jsxs("div",{className:"min-w-0 break-inside-avoid",children:[e.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:m.categoryKey}),e.jsx("div",{className:"space-y-1",children:m.items.map(x=>{const u=x.id?oa(x.id,Array.isArray(x.keys)?x.keys[0]:x.keys,s):Array.isArray(x.keys)?x.keys:x.keys.split(" / ");return e.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[x.icon&&e.jsx(q,{name:x.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"typography-meta",children:x.descriptionKey})]}),e.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(u)?u:[u]).map((p,g)=>e.jsxs(r.Fragment,{children:[g>0&&e.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:"or"}),e.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:p})]},`${p}-${g}`))})]},x.id||x.descriptionKey)})})]},m.categoryKey))})})]})})},ia=r.createContext(null),la=({children:t,value:n})=>e.jsx(ia.Provider,{value:n,children:t}),Zt=De(()=>Ee(()=>import("./GitView-Dj_7hgX_.js"),__vite__mapDeps([129,24,1,2,9,4,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,117,118,130])).then(t=>({default:t.GitView}))),ca=De(()=>Ee(()=>import("./DiffView-DVd1MLPB.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(t=>({default:t.DiffView}))),da=De(()=>Ee(()=>import("./FilesView-CPnW4I90.js"),__vite__mapDeps([120,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,117,118,99,100,84,85,86,87,88,89,90,91,92,93,94,95,96,97,121,122,111,112,113,114,115,116,123,124,81,82,83,98,101,102,103,104,105,106,107,125,126,127,128])).then(t=>({default:t.FilesView}))),ua=De(()=>Ee(()=>import("./DiagramView-CV-iReyY.js"),__vite__mapDeps([131,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,121,122])).then(t=>({default:t.DiagramView}))),ha=De(()=>Ee(()=>import("./SettingsView-C57uV1YS.js").then(t=>t.a),__vite__mapDeps([132,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsView}))),pa=De(()=>Ee(()=>import("./SettingsWindow-Bbay2W76.js"),__vite__mapDeps([135,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,132,111,112,113,114,115,116,133,134,130])).then(t=>({default:t.SettingsWindow}))),fa=()=>{const t=ee(C=>C.isSidebarOpen),n=ee(C=>C.activeMainTab),s=ee(C=>C.setIsMobile),a=ee(C=>C.isSessionSwitcherOpen),o=ee(C=>C.isSettingsDialogOpen),m=ee(C=>C.setSettingsDialogOpen),[x,u]=r.useState(!1);r.useEffect(()=>{o&&u(!0)},[o]),r.useEffect(()=>{const C=()=>ee.getState().closeMainSurfaces(),M=Se.subscribe((L,K)=>{const se=!!L.currentSessionId&&L.currentSessionId!==K.currentSessionId,he=!!L.newSessionDraft?.open&&L.newSessionDraft!==K.newSessionDraft;(se||he)&&C()}),U=ee.subscribe((L,K)=>{L.activeMainTab!==K.activeMainTab&&C()});return()=>{M(),U()}},[]);const{isMobile:p}=st(),g=r.useRef(!1),[v,f]=r.useState(!1),[l,T]=r.useState(!1),[c,S]=r.useState(!1),[j,P]=r.useState(!1),R=r.useCallback(C=>{f(C),ee.getState().setSessionSwitcherOpen(C)},[]),O=r.useRef(typeof window>"u"?0:window.innerWidth),te=r.useRef(null),F=r.useRef(!1),re=r.useRef(!1),z=r.useRef(!1),y=r.useRef(null),b=r.useRef(null),G=Ot(-O.current),H=Ce.useRef(0),$=Ot(O.current),V=Ce.useRef(0);Ce.useEffect(()=>{p&&(H.current=window.innerWidth,V.current=window.innerWidth)},[p]),Ce.useEffect(()=>{if(!p)return;const C=()=>{const M=window.innerWidth;H.current=M,V.current=M,v||G.get()<-10&&G.set(-M),l||$.get()>10&&$.set(M)};return window.addEventListener("resize",C),window.addEventListener("orientationchange",C),()=>{window.removeEventListener("resize",C),window.removeEventListener("orientationchange",C)}},[p,G,$,v,l]),Ce.useEffect(()=>{if(!p){S(!1);return}v&&S(!0);const C=H.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye(G,v?0:-C,{type:"spring",stiffness:400,damping:35,mass:.8});return y.current=M,()=>M.stop()},[v,p,G]),Ce.useEffect(()=>{if(!p){P(!1);return}l&&P(!0);const C=V.current||O.current||(typeof window<"u"?window.innerWidth:0),M=Ye($,l?0:C,{type:"spring",stiffness:400,damping:35,mass:.8});return b.current=M,()=>M.stop()},[p,l,$]),Ce.useEffect(()=>{if(p)return G.on("change",C=>{const M=H.current||O.current,U=v||C>-M+.5;S(L=>L===U?L:U)})},[p,G,v]),Ce.useEffect(()=>{if(p)return $.on("change",C=>{const M=V.current||O.current,U=l||C<M-.5;P(L=>L===U?L:U)})},[p,l,$]),Ce.useEffect(()=>{p&&!a&&v&&R(!1)},[a,p,v,R]),Ce.useEffect(()=>{if(!p){g.current=!1;return}g.current||(g.current=!0,R(!1),T(!1))},[p,R]),Ce.useEffect(()=>{if(!p||n!=="chat"||v||l||o)return;let C=!1,M;const U=L=>{M=window.setTimeout(()=>{if(C)return;const K=Se.getState(),se=ee.getState();if(!(se.activeMainTab!=="chat"||se.isSettingsDialogOpen||K.currentSessionId||K.newSessionDraft?.open)){if(K.isLoading){U(250);return}K.openNewSessionDraft({automatic:!0})}},L)};return U(500),()=>{C=!0,M!==void 0&&window.clearTimeout(M)}},[n,p,o,v,l]),Ce.useEffect(()=>{!p||!o||(R(!1),T(!1))},[p,o,R]),r.useEffect(()=>{ee.getState().isMobile!==p&&s(p)},[p,s]);const ne=r.useCallback(()=>{v&&R(!1),T(!l)},[v,l,R]);gr(te,{enabled:p,leftOpen:v,rightOpen:l,leftWidth:()=>H.current||O.current||(typeof window<"u"?window.innerWidth:0),rightWidth:()=>V.current||O.current||(typeof window<"u"?window.innerWidth:0),onLeftProgress:C=>{const M=H.current||O.current||(typeof window<"u"?window.innerWidth:0);G.set(M*(C-1))},onRightProgress:C=>{const M=V.current||O.current||(typeof window<"u"?window.innerWidth:0);$.set(M*(1-C))},onLeftOpen:()=>{l&&T(!1),R(!0)},onLeftClose:()=>R(!1),onRightOpen:()=>{v&&R(!1),T(!0)},onRightClose:()=>T(!1),onDragStart:C=>{F.current=!0,C==="left"?(re.current=v,y.current?.stop(),c||S(!0)):(z.current=l,b.current?.stop(),j||P(!0))},onDragEnd:(C,M)=>{if(F.current=!1,C==="left"&&typeof M=="boolean"){const U=re.current;if(M===U){const L=H.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye(G,U?0:-L,{type:"spring",stiffness:400,damping:35,mass:.8});y.current=K}}if(C==="right"&&typeof M=="boolean"){const U=z.current;if(M===U){const L=V.current||O.current||(typeof window<"u"?window.innerWidth:0),K=Ye($,U?0:L,{type:"spring",stiffness:400,damping:35,mass:.8});b.current=K}}}});const E=r.useMemo(()=>{if(!p&&n!=="terminal"&&n!=="diagram"||p&&n==="git"&&(l||j))return null;switch(n){case"git":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:!0})});case"diff":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ca,{})});case"terminal":return e.jsx(an,{onCloseView:()=>ee.getState().setActiveMainTab("chat")});case"files":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(da,{})});case"diagram":return e.jsx(r.Suspense,{fallback:null,children:e.jsx(ua,{})});default:return null}},[n,p,j,l]),Q=n==="chat";return e.jsxs(xr,{children:[e.jsx(wr,{}),e.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",p?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[e.jsx(sa,{}),e.jsx(aa,{}),e.jsx(yr,{}),p?e.jsxs(la,{value:{leftDrawerOpen:v,rightDrawerOpen:l,toggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},toggleRightDrawer:ne,leftDrawerX:G,rightDrawerX:$,leftDrawerWidth:H,rightDrawerWidth:V,setMobileLeftDrawerOpen:R,setRightSidebarOpen:T},children:[!o&&e.jsx(Tt,{onToggleLeftDrawer:()=>{const C=!v;l&&T(!1),R(C)},onToggleRightDrawer:()=>{ne()},leftDrawerOpen:v,rightDrawerOpen:l}),e.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",o&&"hidden"),children:e.jsxs("main",{ref:te,className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",style:{touchAction:"pan-x pan-y"},children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!c&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:G},"aria-hidden":!v,children:e.jsx(Ne,{children:e.jsx(At,{mobileVariant:!0,isVisible:c})})}),e.jsx($t.div,{className:ce("absolute inset-0 z-20 bg-sidebar",!j&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:$},"aria-hidden":!l,children:e.jsx(Ne,{children:l||j?e.jsx(r.Suspense,{fallback:null,children:e.jsx(Zt,{isActive:l})}):null})})]})}),o&&e.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:e.jsx(Ne,{children:e.jsx(r.Suspense,{fallback:null,children:e.jsx(ha,{onClose:()=>m(!1)})})})})]}):e.jsxs(e.Fragment,{children:[e.jsx(br,{}),e.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[e.jsx(_s,{isOpen:t,isMobile:p,children:e.jsx(At,{isVisible:t})}),e.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx(Tt,{}),e.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[e.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:e.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:e.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[e.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[e.jsx("div",{className:ce("absolute inset-0",!Q&&"invisible"),children:e.jsx(Ne,{children:e.jsx(_t,{active:Q&&!o})})}),E&&e.jsx("div",{className:"absolute inset-0",children:e.jsx(Ne,{children:E})}),e.jsx(Ne,{children:e.jsx(Dt,{})})]}),e.jsx(Xo,{})]})})}),e.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:e.jsx(Ne,{children:e.jsx(ea,{})})})]})]})]}),x?e.jsx(r.Suspense,{fallback:null,children:e.jsx(pa,{open:o,onOpenChange:m})}):null]})]})]})},ma=()=>(is(),jr(),e.jsxs(Sr,{children:[e.jsx(ls,{embeddedBackgroundWorkEnabled:!0}),e.jsx(cs,{}),e.jsx(fa,{}),e.jsx(Cr,{}),e.jsx(ds,{}),e.jsx(us,{})]}));function ga({apis:t}){const n=t??on(),[s,a]=r.useState(0);return r.useEffect(()=>sr(o=>{o.runtimeKey!==o.previousRuntimeKey&&(vr(o),a(m=>m+1))}),[]),r.useEffect(()=>{let o=!0,m=null,x=null;return or().then(()=>{o&&(m=ns(),x=rs())}),()=>{o=!1,m?.(),x?.()}},[s]),r.useEffect(()=>{n&&ar(n)},[n]),n?e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground",children:e.jsx(ss,{apis:n,children:e.jsx(os,{children:e.jsx(as,{children:e.jsx(ma,{})})},s)})})}):e.jsx(Ne,{children:e.jsx("div",{className:"h-full w-full overflow-hidden bg-background text-foreground"})})}const Wn=document.getElementById("root");if(!Wn)throw new Error("Root element not found");Fn.createRoot(Wn).render(e.jsx(Ce.StrictMode,{children:e.jsx(hs,{children:e.jsx(ps,{children:e.jsx(ga,{apis:on()??void 0})})})}));
|