shraga 0.1.75 → 0.1.77

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.
@@ -1844,7 +1844,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),hn=pe,kt=je),nt===void
1844
1844
  `)},QN=function(){var e=parseInt(document.body.getAttribute(uu)||"0",10);return isFinite(e)?e:0},Kte=function(){y.useEffect(function(){return document.body.setAttribute(uu,(QN()+1).toString()),function(){var e=QN()-1;e<=0?document.body.removeAttribute(uu):document.body.setAttribute(uu,e.toString())}},[])},qte=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;Kte();var a=y.useMemo(function(){return Ute(i)},[i]);return y.createElement(Fte,{styles:Hte(a,!t,i,n?"":"!important")})},kw=!1;if(typeof window<"u")try{var am=Object.defineProperty({},"passive",{get:function(){return kw=!0,!0}});window.addEventListener("test",am,am),window.removeEventListener("test",am,am)}catch{kw=!1}var $c=kw?{passive:!1}:!1,Gte=function(e){return e.tagName==="TEXTAREA"},bz=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Gte(e)&&n[t]==="visible")},Vte=function(e){return bz(e,"overflowY")},Wte=function(e){return bz(e,"overflowX")},JN=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=xz(e,r);if(i){var a=wz(e,r),s=a[1],c=a[2];if(s>c)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Yte=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Xte=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},xz=function(e,t){return e==="v"?Vte(t):Wte(t)},wz=function(e,t){return e==="v"?Yte(t):Xte(t)},Zte=function(e,t){return e==="h"&&t==="rtl"?-1:1},Qte=function(e,t,n,r,i){var a=Zte(e,window.getComputedStyle(t).direction),s=a*r,c=n.target,u=t.contains(c),f=!1,h=s>0,p=0,m=0;do{if(!c)break;var v=wz(e,c),x=v[0],b=v[1],S=v[2],_=b-S-a*x;(x||_)&&xz(e,c)&&(p+=_,m+=x);var O=c.parentNode;c=O&&O.nodeType===Node.DOCUMENT_FRAGMENT_NODE?O.host:O}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(h&&Math.abs(p)<1||!h&&Math.abs(m)<1)&&(f=!0),f},om=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},eM=function(e){return[e.deltaX,e.deltaY]},tM=function(e){return e&&"current"in e?e.current:e},Jte=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ene=function(e){return`
1845
1845
  .block-interactivity-`.concat(e,` {pointer-events: none;}
1846
1846
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
1847
- `)},tne=0,Bc=[];function nne(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),i=y.useState(tne++)[0],a=y.useState(yz)[0],s=y.useRef(e);y.useEffect(function(){s.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var b=CH([e.lockRef.current],(e.shards||[]).map(tM),!0).filter(Boolean);return b.forEach(function(S){return S.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),b.forEach(function(S){return S.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var c=y.useCallback(function(b,S){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!s.current.allowPinchZoom;var _=om(b),O=n.current,k="deltaX"in b?b.deltaX:O[0]-_[0],C="deltaY"in b?b.deltaY:O[1]-_[1],N,T=b.target,R=Math.abs(k)>Math.abs(C)?"h":"v";if("touches"in b&&R==="h"&&T.type==="range")return!1;var L=window.getSelection(),D=L&&L.anchorNode,P=D?D===T||D.contains(T):!1;if(P)return!1;var B=JN(R,T);if(!B)return!0;if(B?N=R:(N=R==="v"?"h":"v",B=JN(R,T)),!B)return!1;if(!r.current&&"changedTouches"in b&&(k||C)&&(r.current=N),!N)return!0;var I=r.current||N;return Qte(I,S,b,I==="h"?k:C)},[]),u=y.useCallback(function(b){var S=b;if(!(!Bc.length||Bc[Bc.length-1]!==a)){var _="deltaY"in S?eM(S):om(S),O=t.current.filter(function(N){return N.name===S.type&&(N.target===S.target||S.target===N.shadowParent)&&Jte(N.delta,_)})[0];if(O&&O.should){S.cancelable&&S.preventDefault();return}if(!O){var k=(s.current.shards||[]).map(tM).filter(Boolean).filter(function(N){return N.contains(S.target)}),C=k.length>0?c(S,k[0]):!s.current.noIsolation;C&&S.cancelable&&S.preventDefault()}}},[]),f=y.useCallback(function(b,S,_,O){var k={name:b,delta:S,target:_,should:O,shadowParent:rne(_)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(C){return C!==k})},1)},[]),h=y.useCallback(function(b){n.current=om(b),r.current=void 0},[]),p=y.useCallback(function(b){f(b.type,eM(b),b.target,c(b,e.lockRef.current))},[]),m=y.useCallback(function(b){f(b.type,om(b),b.target,c(b,e.lockRef.current))},[]);y.useEffect(function(){return Bc.push(a),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",u,$c),document.addEventListener("touchmove",u,$c),document.addEventListener("touchstart",h,$c),function(){Bc=Bc.filter(function(b){return b!==a}),document.removeEventListener("wheel",u,$c),document.removeEventListener("touchmove",u,$c),document.removeEventListener("touchstart",h,$c)}},[]);var v=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(a,{styles:ene(i)}):null,v?y.createElement(qte,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function rne(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ine=Ite(vz,nne);var jE=y.forwardRef(function(e,t){return y.createElement(bv,aa({},e,{ref:t,sideCar:ine}))});jE.classNames=bv.classNames;var ane=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Uc=new WeakMap,sm=new WeakMap,lm={},lx=0,Ez=function(e){return e&&(e.host||Ez(e.parentNode))},one=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Ez(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},sne=function(e,t,n,r){var i=one(t,Array.isArray(e)?e:[e]);lm[n]||(lm[n]=new WeakMap);var a=lm[n],s=[],c=new Set,u=new Set(i),f=function(p){!p||c.has(p)||(c.add(p),f(p.parentNode))};i.forEach(f);var h=function(p){!p||u.has(p)||Array.prototype.forEach.call(p.children,function(m){if(c.has(m))h(m);else try{var v=m.getAttribute(r),x=v!==null&&v!=="false",b=(Uc.get(m)||0)+1,S=(a.get(m)||0)+1;Uc.set(m,b),a.set(m,S),s.push(m),b===1&&x&&sm.set(m,!0),S===1&&m.setAttribute(n,"true"),x||m.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",m,_)}})};return h(t),c.clear(),lx++,function(){s.forEach(function(p){var m=Uc.get(p)-1,v=a.get(p)-1;Uc.set(p,m),a.set(p,v),m||(sm.has(p)||p.removeAttribute(r),sm.delete(p)),v||p.removeAttribute(n)}),lx--,lx||(Uc=new WeakMap,Uc=new WeakMap,sm=new WeakMap,lm={})}},Sz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=ane(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),sne(r,i,n,"aria-hidden")):function(){return null}},xv="Dialog",[_z]=xj(xv),[lne,$i]=_z(xv),Az=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,c=y.useRef(null),u=y.useRef(null),[f,h]=rte({prop:r,defaultProp:i??!1,onChange:a,caller:xv});return E.jsx(lne,{scope:t,triggerRef:c,contentRef:u,contentId:nx(),titleId:nx(),descriptionId:nx(),open:f,onOpenChange:h,onOpenToggle:y.useCallback(()=>h(p=>!p),[h]),modal:s,children:n})};Az.displayName=xv;var kz="DialogTrigger",Oz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(kz,n),a=ei(t,i.triggerRef);return E.jsx(Pr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":UE(i.open),...r,ref:a,onClick:vr(e.onClick,i.onOpenToggle)})});Oz.displayName=kz;var LE="DialogPortal",[cne,Cz]=_z(LE,{forceMount:void 0}),Tz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=$i(LE,t);return E.jsx(cne,{scope:t,forceMount:n,children:y.Children.map(r,s=>E.jsx(Rs,{present:n||a.open,children:E.jsx(mz,{asChild:!0,container:i,children:s})}))})};Tz.displayName=LE;var cg="DialogOverlay",zE=y.forwardRef((e,t)=>{const n=Cz(cg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=$i(cg,e.__scopeDialog);return a.modal?E.jsx(Rs,{present:r||a.open,children:E.jsx(fne,{...i,ref:t})}):null});zE.displayName=cg;var une=fE("DialogOverlay.RemoveScroll"),fne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(cg,n),a=fte(),s=ei(t,a);return E.jsx(jE,{as:une,allowPinchZoom:!0,shards:[i.contentRef],children:E.jsx(Pr.div,{"data-state":UE(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),wu="DialogContent",$E=y.forwardRef((e,t)=>{const n=Cz(wu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=$i(wu,e.__scopeDialog);return E.jsx(Rs,{present:r||a.open,children:a.modal?E.jsx(dne,{...i,ref:t}):E.jsx(hne,{...i,ref:t})})});$E.displayName=wu;var dne=y.forwardRef((e,t)=>{const n=$i(wu,e.__scopeDialog),r=y.useRef(null),i=ei(t,n.contentRef,r);return y.useEffect(()=>{const a=r.current;if(a)return Sz(a)},[]),E.jsx(Nz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:vr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:vr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,c=s.button===0&&s.ctrlKey===!0;(s.button===2||c)&&a.preventDefault()}),onFocusOutside:vr(e.onFocusOutside,a=>a.preventDefault())})}),hne=y.forwardRef((e,t)=>{const n=$i(wu,e.__scopeDialog),r=y.useRef(!1),i=y.useRef(!1);return E.jsx(Nz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,c;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,f;(u=e.onInteractOutside)==null||u.call(e,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=a.target;((f=n.triggerRef.current)==null?void 0:f.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Nz=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,c=$i(wu,n);return Ste(),E.jsx(E.Fragment,{children:E.jsx(hz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:E.jsx(fz,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":UE(c.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Mz="DialogTitle",BE=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Mz,n);return E.jsx(Pr.h2,{id:i.titleId,...r,ref:t})});BE.displayName=Mz;var Iz="DialogDescription",pne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Iz,n);return E.jsx(Pr.p,{id:i.descriptionId,...r,ref:t})});pne.displayName=Iz;var Rz="DialogClose",Pz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Rz,n);return E.jsx(Pr.button,{type:"button",...r,ref:t,onClick:vr(e.onClick,()=>i.onOpenChange(!1))})});Pz.displayName=Rz;function UE(e){return e?"open":"closed"}const Es=Az,oh=Oz,mne=Tz,Dz=y.forwardRef(({className:e,...t},n)=>E.jsx(zE,{ref:n,className:He("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Dz.displayName=zE.displayName;const uo=y.forwardRef(({className:e,children:t,...n},r)=>E.jsxs(mne,{children:[E.jsx(Dz,{}),E.jsxs($E,{ref:r,className:He("fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-lg max-h-[85dvh] overflow-y-auto translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-4 sm:p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",e),...n,children:[t,E.jsxs(Pz,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[E.jsx(Rl,{className:"h-4 w-4"}),E.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));uo.displayName=$E.displayName;function Dl({className:e,...t}){return E.jsx("div",{className:He("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function jz({className:e,...t}){return E.jsx("div",{"data-dialog-body":!0,className:He("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Lz({className:e,...t}){return E.jsx("div",{className:He("shrink-0 -mx-4 px-4 pt-3 border-t sm:-mx-6 sm:px-6","flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const Ss=y.forwardRef(({className:e,...t},n)=>E.jsx(BE,{ref:n,className:He("text-lg font-semibold leading-none tracking-tight",e),...t}));Ss.displayName=BE.displayName;const gne=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),vne=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function yne(e,t){const n=await t();if(!n)return[];const r=await fetch(`/api/workspace/ls?path=${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${n}`}});return r.ok?(await r.json()).entries??[]:[]}function bne({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=y.useState(new Map),[a,s]=y.useState(()=>new Set),[c,u]=y.useState(null),[f,h]=y.useState(!1),[p,m]=y.useState("fit"),[v,x]=y.useState(null),[b,S]=y.useState(null),_=y.useRef(null),[O,k]=y.useState(null),[C,N]=y.useState(!1),[T,R]=y.useState([]),L=y.useCallback(async $=>{const q=await yne($,e);i(K=>new Map(K).set($,q))},[e]);y.useEffect(()=>{L(""),a.forEach($=>L($))},[L,n]);const D=r.get("")??[],P=y.useCallback($=>{try{const q=$.contentDocument;if(!(q!=null&&q.body))return;const K=Math.max(q.body.offsetWidth,q.body.scrollWidth),Z=Math.max(q.body.offsetHeight,q.body.scrollHeight);K&&Z&&S({w:K,h:Z})}catch{}},[]),B=y.useCallback(()=>{const $=_.current,q=b;if(!$||!q)return;const K=16,Z=$.clientWidth-K,j=$.clientHeight-K,H=Math.min(Z/q.w,j/q.h,1);x({scale:H,w:q.w,h:q.h})},[b]);y.useEffect(()=>{if(!(c!=null&&c.html)||p!=="fit"){x(null);return}const $=_.current;if(!$)return;const q=new ResizeObserver(()=>requestAnimationFrame(B));return q.observe($),()=>q.disconnect()},[c==null?void 0:c.html,f,p,B]),y.useEffect(()=>{C&&e().then($=>{$&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${$}`}}).then(q=>q.json()).then(R).catch(()=>{})})},[C]);const I=$=>{s(q=>{const K=new Set(q);return K.has($)?K.delete($):(K.add($),r.has($)||L($)),K})},U=($,q)=>{const K=new URLSearchParams({path:$});return O&&K.set("token",O),q&&K.set("dl","1"),`/api/workspace/raw?${K}`},V=async $=>{var Z;const q=await e();if(!q)return;k(q);const K=((Z=$.split(".").pop())==null?void 0:Z.toLowerCase())??"";if(K==="html"||K==="htm"){u({path:$,content:"",binary:!1,html:!0});return}if(gne.has(K)){u({path:$,content:"",binary:!1,image:!0});return}if(vne.has(K)){u({path:$,content:"",binary:!1,html:!0});return}try{const j=await fetch(`/api/workspace/file?path=${encodeURIComponent($)}`,{headers:{Authorization:`Bearer ${q}`}});if(!j.ok)return;const H=await j.json();u({path:$,content:H.content,binary:!!H.binary})}catch{}},G=($,q)=>E.jsx(E.Fragment,{children:$.map(K=>{const Z=K.path.split("/").pop();return E.jsxs("div",{children:[K.type==="dir"?E.jsxs("button",{onClick:()=>I(K.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+q*12},children:[E.jsx(Is,{className:He("w-3 h-3 shrink-0 transition-transform",a.has(K.path)&&"rotate-90")}),E.jsx(Lq,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),E.jsx("span",{className:"truncate",children:Z})]}):E.jsxs("button",{onClick:()=>V(K.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+q*12+12},title:K.oneLiner||K.path,children:[E.jsx(oE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),E.jsx("span",{className:"truncate",children:Z})]}),K.type==="dir"&&a.has(K.path)&&G(r.get(K.path)??[],q+1)]},K.path)})});return E.jsxs(E.Fragment,{children:[E.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),E.jsxs("div",{className:"flex items-center gap-0.5",children:[E.jsx("button",{onClick:()=>N(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:E.jsx($q,{className:"w-3 h-3"})}),E.jsx("button",{onClick:()=>{L(""),a.forEach($=>L($)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:E.jsx(Wq,{className:"w-3 h-3"})})]})]}),E.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:D.length===0?E.jsx("p",{className:"text-xs text-muted-foreground px-3 py-2",children:"Empty. Drop .md files into data/workspace/ or ask the agent to create some."}):G(D,0)}),E.jsx(Es,{open:!!c,onOpenChange:$=>{$||(u(null),h(!1),m("fit"),S(null))},children:E.jsxs(uo,{className:He(c!=null&&c.html?He("!flex !flex-col !p-0 !gap-0 overflow-hidden",f?"max-w-none w-[100vw] h-[100vh] rounded-none border-0":"max-w-[90vw] w-[90vw] h-[85vh]"):"max-w-3xl max-h-[80vh] !flex !flex-col overflow-hidden"),children:[E.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(c==null?void 0:c.html)&&E.jsxs(E.Fragment,{children:[E.jsx("button",{onClick:()=>m($=>$==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:p==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:p==="fit"?E.jsx(Kq,{className:"w-4 h-4"}):E.jsx(Xq,{className:"w-4 h-4"})}),E.jsx("button",{onClick:()=>h($=>!$),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:f?"Restore":"Maximize",children:f?E.jsx(lE,{className:"w-4 h-4"}):E.jsx(sE,{className:"w-4 h-4"})})]}),c&&E.jsx("a",{href:U(c.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:E.jsx(mj,{className:"w-4 h-4"})})]}),E.jsx(Dl,{className:He((c==null?void 0:c.html)&&"px-4 py-3 shrink-0 border-b"),children:E.jsx(Ss,{className:"font-mono text-sm truncate pr-16",children:c==null?void 0:c.path})}),E.jsx("div",{ref:c!=null&&c.html?_:void 0,className:He(c!=null&&c.html?He("flex-1 min-h-0 bg-muted/10",p==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:c!=null&&c.html?p==="fit"?E.jsx("div",{style:v?{width:v.w*v.scale,height:v.h*v.scale}:{width:"100%",height:"100%"},children:E.jsx("iframe",{src:U(c.path),className:"border-0 bg-white origin-top-left",title:c.path,onLoad:$=>{P($.currentTarget),B()},style:v?{width:v.w,height:v.h,transform:`scale(${v.scale})`}:{width:"100%",height:"100%"}})}):E.jsx("iframe",{src:U(c.path),className:"border-0 bg-white mx-auto block",title:c.path,onLoad:$=>P($.currentTarget),style:{width:(b==null?void 0:b.w)||"100%",height:(b==null?void 0:b.h)||"100%"}}):c!=null&&c.image?E.jsx("div",{className:"flex items-center justify-center p-4",children:E.jsx("img",{src:U(c.path),alt:c.path,className:"max-w-full max-h-[70vh] object-contain"})}):c!=null&&c.binary?E.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):c!=null&&c.path.toLowerCase().endsWith(".md")||c!=null&&c.path.toLowerCase().endsWith(".markdown")?E.jsx("div",{className:"text-sm",children:E.jsx(yL,{remarkPlugins:[FL],rehypePlugins:[uz],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none",children:c.content})}):E.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:c==null?void 0:c.content})})]})}),E.jsx(Es,{open:C,onOpenChange:N,children:E.jsxs(uo,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[E.jsx(Dl,{children:E.jsx(Ss,{className:"text-sm",children:"Activity Log"})}),E.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[T.map($=>E.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[E.jsx("span",{className:"text-sm text-foreground",children:$.message}),E.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:xne($.date)})]}),$.files.length>0&&E.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:$.files.map(q=>E.jsx("span",{className:"inline-block mr-2 font-mono",children:q},q))})]},$.hash)),T.length===0&&E.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function xne(e){const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/6e4);if(i<60)return`${i}m ago`;const a=Math.floor(i/60);return a<24?`${a}h ago`:t.toLocaleDateString(void 0,{month:"short",day:"numeric"})}var wne=Object.defineProperty,ju=(e,t)=>wne(e,"name",{value:t,configurable:!0}),zz=!!(typeof window<"u"&&window.document&&window.document.createElement);function ys(e,t,{checkForDefaultPrevented:n=!0}={}){return ju(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}ju(ys,"composeEventHandlers");function Ene(e){var t;if(!zz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}ju(Ene,"getOwnerWindow");function Ow(e){if(!zz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}ju(Ow,"getOwnerDocument");function $z(e,t=!1){const{activeElement:n}=Ow(e);if(!(n!=null&&n.nodeName))return null;if(Bz(n)&&n.contentDocument)return $z(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=Ow(n).getElementById(r);if(i)return i}}return n}ju($z,"getActiveElement");function Bz(e){return e.tagName==="IFRAME"}ju(Bz,"isFrame");var Sne=Object.defineProperty,FE=(e,t)=>Sne(e,"name",{value:t,configurable:!0});function Cw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}FE(Cw,"setRef");function Uz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=Cw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Cw(e[i],null)}}}}FE(Uz,"composeRefs");function Lu(...e){return y.useCallback(Uz(...e),e)}FE(Lu,"useComposedRefs");var _ne=Object.defineProperty,bi=(e,t)=>_ne(e,"name",{value:t,configurable:!0});function Ane(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=bi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return E.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return bi(i,"useContext"),[r,i]}bi(Ane,"createContext");function Fz(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=bi(p=>{var _;const{scope:m,children:v,...x}=p,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return E.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function h(p,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${p}\` must be used within \`${a}\``)}return bi(h,"useContext"),[f,h]}bi(r,"createContext");const i=bi(()=>{const a=n.map(s=>y.createContext(s));return bi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,Hz(i,...t)]}bi(Fz,"createContextScope");function Hz(...e){const t=e[0];if(e.length===1)return t;const n=bi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return bi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const p=u(a)[`__scope${f}`];return{...c,...p}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}bi(Hz,"composeContextScopes");var kne=Object.defineProperty,Bi=(e,t)=>kne(e,"name",{value:t,configurable:!0});function HE(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Tw(i)&&typeof cm=="function"&&(i=cm(i._payload)),y.Children.forEach(i,m=>{var v;if(Vz(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Tw(b)&&typeof cm=="function"&&(b=cm(b._payload)),s=Cne(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?Gz(s):void 0,h=Lu(r,f);if(!s){if(i||i===0)throw new Error(c?Mne(e):Nne(e));return i}const p=qz(a,s.props??{});return s.type!==y.Fragment&&(p.ref=r?h:f),y.cloneElement(s,p)});return t.displayName=`${e}.Slot`,t}Bi(HE,"createSlot");var Kz=Symbol.for("radix.slottable");function One(e){const t=Bi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Kz,t}Bi(One,"createSlottable");var Cne=Bi((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function qz(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Bi(qz,"mergeProps");function Gz(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Bi(Gz,"getElementRef");function Vz(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Kz}Bi(Vz,"isSlottable");var Tne=Symbol.for("react.lazy");function Tw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Tne&&"_payload"in e&&Wz(e._payload)}Bi(Tw,"isLazyComponent");function Wz(e){return typeof e=="object"&&e!==null&&"then"in e}Bi(Wz,"isPromiseLike");var Nne=Bi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Mne=Bi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),cm=wa[" use ".trim().toString()],Ine=Object.defineProperty,Rne=(e,t)=>Ine(e,"name",{value:t,configurable:!0}),Pne=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],wv=Pne.reduce((e,t)=>{const n=HE(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),E.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Yz(e,t){e&&Ea.flushSync(()=>e.dispatchEvent(t))}Rne(Yz,"dispatchDiscreteCustomEvent");var Dne=Object.defineProperty,jne=(e,t)=>Dne(e,"name",{value:t,configurable:!0});function Ev(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}jne(Ev,"useCallbackRef");var Lne=Object.defineProperty,Fn=(e,t)=>Lne(e,"name",{value:t,configurable:!0}),Nw="dismissableLayer.update",zne="dismissableLayer.pointerDownOutside",$ne="dismissableLayer.focusOutside",nM,Xz=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Bne=y.forwardRef(Fn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:c,onInteractOutside:u,onDismiss:f,...h}=t,p=y.useContext(Xz),[m,v]=y.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=y.useState({}),S=Lu(n,v),_=Array.from(p.layers),[O]=[...p.layersWithOutsidePointerEventsDisabled].slice(-1),k=O?_.indexOf(O):-1,C=m?_.indexOf(m):-1,N=p.layersWithOutsidePointerEventsDisabled.size>0,T=C>=k,R=y.useRef(!1),L=Zz(I=>{s==null||s(I),u==null||u(I),I.defaultPrevented||f==null||f()},{ownerDocument:x,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:p.dismissableSurfaces,shouldHandlePointerDownOutside:y.useCallback(I=>{if(!(I instanceof Node))return!1;const U=[...p.branches].some(V=>V.contains(I));return T&&!U},[p.branches,T])}),D=Qz(I=>{if(i&&R.current)return;const U=I.target;[...p.branches].some(G=>G.contains(U))||(c==null||c(I),u==null||u(I),I.defaultPrevented||f==null||f())},x),P=m?C===_.length-1:!1,B=Ev(I=>{I.key==="Escape"&&(a==null||a(I),!I.defaultPrevented&&f&&(I.preventDefault(),f()))});return y.useEffect(()=>{if(P)return x.addEventListener("keydown",B,{capture:!0}),()=>x.removeEventListener("keydown",B,{capture:!0})},[x,P,B]),y.useEffect(()=>{if(m)return r&&(p.layersWithOutsidePointerEventsDisabled.size===0&&(nM=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),p.layersWithOutsidePointerEventsDisabled.add(m)),p.layers.add(m),Mw(),()=>{r&&(p.layersWithOutsidePointerEventsDisabled.delete(m),p.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=nM))}},[m,x,r,p]),y.useEffect(()=>()=>{m&&(p.layers.delete(m),p.layersWithOutsidePointerEventsDisabled.delete(m),Mw())},[m,p]),y.useEffect(()=>{const I=Fn(()=>b({}),"handleUpdate");return document.addEventListener(Nw,I),()=>document.removeEventListener(Nw,I)},[]),E.jsx(wv.div,{...h,ref:S,style:{pointerEvents:N?T?"auto":"none":void 0,...t.style},onFocusCapture:ys(t.onFocusCapture,D.onFocusCapture),onBlurCapture:ys(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:ys(t.onPointerDownCapture,L.onPointerDownCapture)})},"DismissableLayer"));function Une(){const e=y.useContext(Xz),[t,n]=y.useState(null);return y.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}Fn(Une,"useDismissableLayerSurface");var Fne=Fn(()=>!0,"IS_TRUE");function Zz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=Fne}=t,c=Ev(e),u=y.useRef(!1),f=y.useRef(!1),h=y.useRef(new Map),p=y.useRef(()=>{});return y.useEffect(()=>{function m(){f.current=!1,i.current=!1,h.current.clear()}Fn(m,"resetOutsideInteraction");function v(){return Array.from(h.current.values()).some(Boolean)}Fn(v,"isOutsideInteractionIntercepted");function x(k){if(!f.current)return;const C=k.target;C instanceof Node&&[...a].some(T=>T.contains(C))||h.current.set(k.type,!0),k.type==="click"&&window.setTimeout(()=>{f.current&&p.current()},0)}Fn(x,"handleInteractionCapture");function b(k){f.current&&h.current.set(k.type,!1)}Fn(b,"handleInteractionBubble");const S=Fn(k=>{if(k.target&&!u.current){let C=function(){n.removeEventListener("click",p.current);const T=v();m(),T||KE(zne,c,N,{discrete:!0})};if(Fn(C,"handleAndDispatchPointerDownOutsideEvent"),!s(k.target)){n.removeEventListener("click",p.current),m(),u.current=!1;return}const N={originalEvent:k};f.current=!0,i.current=r&&k.button===0,h.current.clear(),!r||k.button!==0?C():(n.removeEventListener("click",p.current),p.current=C,n.addEventListener("click",p.current,{once:!0}))}else n.removeEventListener("click",p.current),m();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const k of _)n.addEventListener(k,x,!0),n.addEventListener(k,b);const O=window.setTimeout(()=>{n.addEventListener("pointerdown",S)},0);return()=>{window.clearTimeout(O),n.removeEventListener("pointerdown",S),n.removeEventListener("click",p.current);for(const k of _)n.removeEventListener(k,x,!0),n.removeEventListener(k,b)}},[n,c,r,i,a,s]),{onPointerDownCapture:Fn(()=>u.current=!0,"onPointerDownCapture")}}Fn(Zz,"usePointerDownOutside");function Qz(e,t=globalThis==null?void 0:globalThis.document){const n=Ev(e),r=y.useRef(!1);return y.useEffect(()=>{const i=Fn(a=>{a.target&&!r.current&&KE($ne,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:Fn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Fn(()=>r.current=!1,"onBlurCapture")}}Fn(Qz,"useFocusOutside");function Mw(){const e=new CustomEvent(Nw);document.dispatchEvent(e)}Fn(Mw,"dispatchUpdate");function KE(e,t,n,{discrete:r}){const i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?Yz(i,a):i.dispatchEvent(a)}Fn(KE,"handleAndDispatchCustomEvent");var Hne=Object.defineProperty,qE=(e,t)=>Hne(e,"name",{value:t,configurable:!0}),um=0,Xi=null;function Kne(e){return GE(),e.children}qE(Kne,"FocusGuards");function GE(){y.useEffect(()=>{Xi||(Xi={start:Iw(),end:Iw()});const{start:e,end:t}=Xi;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),um++,()=>{um===1&&(Xi==null||Xi.start.remove(),Xi==null||Xi.end.remove(),Xi=null),um=Math.max(0,um-1)}},[])}qE(GE,"useFocusGuards");function Iw(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}qE(Iw,"createFocusGuard");var qne=Object.defineProperty,Gne=(e,t)=>qne(e,"name",{value:t,configurable:!0});function Rw(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Gne(Rw,"useCallbackRef");var Vne=Object.defineProperty,mr=(e,t)=>Vne(e,"name",{value:t,configurable:!0}),cx="focusScope.autoFocusOnMount",ux="focusScope.autoFocusOnUnmount",rM={bubbles:!1,cancelable:!0},Wne=y.forwardRef(mr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...c}=t,[u,f]=y.useState(null),h=Rw(a),p=Rw(s),m=y.useRef(null),v=Lu(n,f),x=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(i){let S=function(C){if(x.paused||!u)return;const N=C.target;u.contains(N)?m.current=N:Ya(m.current,{select:!0})},_=function(C){if(x.paused||!u)return;const N=C.relatedTarget;N!==null&&(u.contains(N)||Ya(m.current,{select:!0}))},O=function(C){if(document.activeElement===document.body)for(const T of C)T.removedNodes.length>0&&Ya(u)};mr(S,"handleFocusIn"),mr(_,"handleFocusOut"),mr(O,"handleMutations"),document.addEventListener("focusin",S),document.addEventListener("focusout",_);const k=new MutationObserver(O);return u&&k.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",_),k.disconnect()}}},[i,u,x.paused]),y.useEffect(()=>{if(u){iM.add(x);const S=document.activeElement;if(!u.contains(S)){const O=new CustomEvent(cx,rM);u.addEventListener(cx,h),u.dispatchEvent(O),O.defaultPrevented||(Jz(i3(VE(u)),{select:!0}),document.activeElement===S&&Ya(u))}return()=>{u.removeEventListener(cx,h),setTimeout(()=>{const O=new CustomEvent(ux,rM);u.addEventListener(ux,p),u.dispatchEvent(O),O.defaultPrevented||Ya(S??document.body,{select:!0}),u.removeEventListener(ux,p),iM.remove(x)},0)}}},[u,h,p,x]);const b=y.useCallback(S=>{if(!r&&!i||x.paused)return;const _=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,O=document.activeElement;if(_&&O){const k=S.currentTarget,[C,N]=e3(k);C&&N?!S.shiftKey&&O===N?(S.preventDefault(),r&&Ya(C,{select:!0})):S.shiftKey&&O===C&&(S.preventDefault(),r&&Ya(N,{select:!0})):O===k&&S.preventDefault()}},[r,i,x.paused]);return E.jsx(wv.div,{tabIndex:-1,...c,ref:v,onKeyDown:b})},"FocusScope"));function Jz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Ya(r,{select:t}),document.activeElement!==n)return}mr(Jz,"focusFirst");function e3(e){const t=VE(e),n=Pw(t,e),r=Pw(t.reverse(),e);return[n,r]}mr(e3,"getTabbableEdges");function VE(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:mr(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}mr(VE,"getTabbableCandidates");function Pw(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):t3(r,{upTo:t})))return r}mr(Pw,"findVisible");function t3(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}mr(t3,"isHidden");function n3(e){return e instanceof HTMLInputElement&&"select"in e}mr(n3,"isSelectableInput");function Ya(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&n3(e)&&t&&e.select()}}mr(Ya,"focus");var iM=r3();function r3(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Dw(e,t),e.unshift(t)},remove(t){var n;e=Dw(e,t),(n=e[0])==null||n.resume()}}}mr(r3,"createFocusScopesStack");function Dw(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}mr(Dw,"arrayRemove");function i3(e){return e.filter(t=>t.tagName!=="A")}mr(i3,"removeLinks");var Yne=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Xne=Object.defineProperty,Zne=(e,t)=>Xne(e,"name",{value:t,configurable:!0}),Qne=wa[" useId ".trim().toString()]||(()=>{}),Jne=0;function a3(e){const[t,n]=y.useState(Qne());return Yne(()=>{e||n(r=>r??String(Jne++))},[e]),e||(t?`radix-${t}`:"")}Zne(a3,"useId");const ere=["top","right","bottom","left"],_s=Math.min,io=Math.max,ug=Math.round,fm=Math.floor,ao=e=>({x:e,y:e}),tre={left:"right",right:"left",bottom:"top",top:"bottom"};function o3(e,t,n){return io(e,_s(t,n))}function fo(e,t){return typeof e=="function"?e(t):e}function As(e){return e.split("-")[0]}function zu(e){return e.split("-")[1]}function WE(e){return e==="x"?"y":"x"}function YE(e){return e==="y"?"height":"width"}function oa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function XE(e){return WE(oa(e))}function nre(e,t,n){n===void 0&&(n=!1);const r=zu(e),i=XE(e),a=YE(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=fg(s)),[s,fg(s)]}function rre(e){const t=fg(e);return[jw(e),t,jw(t)]}function jw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const aM=["left","right"],oM=["right","left"],ire=["top","bottom"],are=["bottom","top"];function ore(e,t,n){switch(e){case"top":case"bottom":return n?t?oM:aM:t?aM:oM;case"left":case"right":return t?ire:are;default:return[]}}function sre(e,t,n,r){const i=zu(e);let a=ore(As(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(jw)))),a}function fg(e){const t=As(e);return tre[t]+e.slice(t.length)}function lre(e){var t,n,r,i;return{top:(t=e.top)!=null?t:0,right:(n=e.right)!=null?n:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function s3(e){return typeof e!="number"?lre(e):{top:e,right:e,bottom:e,left:e}}function dg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function sM(e,t,n){let{reference:r,floating:i}=e;const a=oa(t),s=XE(t),c=YE(s),u=As(t),f=a==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,m=r[c]/2-i[c]/2;let v;switch(u){case"top":v={x:h,y:r.y-i.height};break;case"bottom":v={x:h,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}const x=zu(t);return x&&(v[s]+=m*(x==="end"?1:-1)*(n&&f?-1:1)),v}async function cre(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:c,strategy:u}=e,{boundary:f="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:m=!1,padding:v=0}=fo(t,e),x=s3(v),S=c[m?p==="floating"?"reference":"floating":p],_=dg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(S)))==null||n?S:S.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(c.floating)),boundary:f,rootBoundary:h,strategy:u})),O=p==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,k=await(a.getOffsetParent==null?void 0:a.getOffsetParent(c.floating)),C=await(a.isElement==null?void 0:a.isElement(k))&&await(a.getScale==null?void 0:a.getScale(k))||{x:1,y:1},N=dg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:O,offsetParent:k,strategy:u}):O);return{top:(_.top-N.top+x.top)/C.y,bottom:(N.bottom-_.bottom+x.bottom)/C.y,left:(_.left-N.left+x.left)/C.x,right:(N.right-_.right+x.right)/C.x}}const ure=50,fre=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:cre},u=await(s.isRTL==null?void 0:s.isRTL(t));let f=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=sM(f,r,u),m=r,v=0;const x={};for(let b=0;b<a.length;b++){const S=a[b];if(!S)continue;const{name:_,fn:O}=S,{x:k,y:C,data:N,reset:T}=await O({x:h,y:p,initialPlacement:r,placement:m,strategy:i,middlewareData:x,rects:f,platform:c,elements:{reference:e,floating:t}});h=k??h,p=C??p,x[_]={...x[_],...N},T&&v<ure&&(v++,typeof T=="object"&&(T.placement&&(m=T.placement),T.rects&&(f=T.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=sM(f,m,u)),b=-1)}return{x:h,y:p,placement:m,strategy:i,middlewareData:x}},dre=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:c,middlewareData:u}=t,{element:f,padding:h=0}=fo(e,t)||{};if(f==null)return{};const p=s3(h),m={x:n,y:r},v=XE(i),x=YE(v),b=await s.getDimensions(f),S=v==="y",_=S?"top":"left",O=S?"bottom":"right",k=S?"clientHeight":"clientWidth",C=a.reference[x]+a.reference[v]-m[v]-a.floating[x],N=m[v]-a.reference[v],T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let R=T?T[k]:0;(!R||!await(s.isElement==null?void 0:s.isElement(T)))&&(R=c.floating[k]||a.floating[x]);const L=C/2-N/2,D=R/2-b[x]/2-1,P=_s(p[_],D),B=_s(p[O],D),I=R-b[x]-B,U=R/2-b[x]/2+L,V=o3(P,U,I),G=!u.arrow&&zu(i)!=null&&U!==V&&a.reference[x]/2-(U<P?P:B)-b[x]/2<0,$=G?U<P?U-P:U-I:0;return{[v]:m[v]+$,data:{[v]:V,centerOffset:U-V-$,...G&&{alignmentOffset:$}},reset:G}}}),hre=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:a,rects:s,initialPlacement:c,platform:u,elements:f}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:m,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:b=!0,...S}=fo(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=As(i),O=oa(c),k=As(c)===c,C=await(u.isRTL==null?void 0:u.isRTL(f.floating)),N=m||(k||!b?[fg(c)]:rre(c)),T=x!=="none";!m&&T&&N.push(...sre(c,b,x,C));const R=[c,...N],L=await u.detectOverflow(t,S),D=[];let P=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&D.push(L[_]),p){const V=nre(i,s,C);D.push(L[V[0]],L[V[1]])}if(P=[...P,{placement:i,overflows:D}],!D.every(V=>V<=0)){var B,I;const V=(((B=a.flip)==null?void 0:B.index)||0)+1,G=R[V];if(G&&(!(p==="alignment"?O!==oa(G):!1)||P.every(K=>oa(K.placement)===O?K.overflows[0]>0:!0)))return{data:{index:V,overflows:P},reset:{placement:G}};let $=(I=P.filter(q=>q.overflows[0]<=0).sort((q,K)=>q.overflows[1]-K.overflows[1])[0])==null?void 0:I.placement;if(!$)switch(v){case"bestFit":{var U;const q=(U=P.filter(K=>{if(T){const Z=oa(K.placement);return Z===O||Z==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(Z=>Z>0).reduce((Z,j)=>Z+j,0)]).sort((K,Z)=>K[1]-Z[1])[0])==null?void 0:U[0];q&&($=q);break}case"initialPlacement":$=c;break}if(i!==$)return{reset:{placement:$}}}return{}}}};function lM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function cM(e){return ere.some(t=>e[t]>=0)}const pre=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=fo(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),c=lM(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:cM(c)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),c=lM(s,n.floating);return{data:{escapedOffsets:c,escaped:cM(c)}}}default:return{}}}}},l3=new Set(["left","top"]);async function mre(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=As(n),c=zu(n),u=oa(n)==="y",f=l3.has(s)?-1:1,h=a&&u?-1:1,p=fo(t,e);let{mainAxis:m,crossAxis:v,alignmentAxis:x}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return c&&typeof x=="number"&&(v=c==="end"?x*-1:x),u?{x:v*h,y:m*f}:{x:m*f,y:v*h}}const gre=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:a,placement:s,middlewareData:c}=t,u=await mre(t,e);return s===((n=c.offset)==null?void 0:n.placement)&&(r=c.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},vre=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:a}=t,{mainAxis:s=!0,crossAxis:c=!1,limiter:u={fn:O=>{let{x:k,y:C}=O;return{x:k,y:C}}},...f}=fo(e,t),h={x:n,y:r},p=await a.detectOverflow(t,f),m=oa(i),v=WE(m);let x=h[v],b=h[m];const S=(O,k)=>o3(k+p[O==="y"?"top":"left"],k,k-p[O==="y"?"bottom":"right"]);s&&(x=S(v,x)),c&&(b=S(m,b));const _=u.fn({...t,[v]:x,[m]:b});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[v]:s,[m]:c}}}}}},yre=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:c,middlewareData:u}=t,{offset:f=0,mainAxis:h=!0,crossAxis:p=!0}=fo(e,t),m={x:i,y:a},v=oa(s),x=WE(v);let b=m[x],S=m[v];const _=fo(f,t),O=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const N=x==="y"?"height":"width",T=c.reference[x]-c.floating[N]+O.mainAxis,R=c.reference[x]+c.reference[N]-O.mainAxis;b<T?b=T:b>R&&(b=R)}if(p){var k,C;const N=x==="y"?"width":"height",T=l3.has(As(s)),R=c.reference[v]-c.floating[N]+(T&&((k=u.offset)==null?void 0:k[v])||0)+(T?0:O.crossAxis),L=c.reference[v]+c.reference[N]+(T?0:((C=u.offset)==null?void 0:C[v])||0)-(T?O.crossAxis:0);S<R?S=R:S>L&&(S=L)}return{[x]:b,[v]:S}}}},bre=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:i,elements:a}=t,{apply:s=()=>{},...c}=fo(e,t),u=await i.detectOverflow(t,c),f=As(n),h=zu(n),p=oa(n)==="y",{width:m,height:v}=r.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=h==="end"?"top":"bottom");const S=v-u.top-u.bottom,_=m-u.left-u.right,O=_s(v-u[x],S),k=_s(m-u[b],_),C=t.middlewareData.shift,N=!C;let T=O,R=k;C!=null&&C.enabled.x&&(R=_),C!=null&&C.enabled.y&&(T=S),N&&!h&&(p?R=m-2*io(u.left,u.right):T=v-2*io(u.top,u.bottom)),await s({...t,availableWidth:R,availableHeight:T});const L=await i.getDimensions(a.floating);return m!==L.width||v!==L.height?{reset:{rects:!0}}:{}}}};function Sv(){return typeof window<"u"}function $u(e){return c3(e)?(e.nodeName||"").toLowerCase():"#document"}function Rr(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function bo(e){var t;return(t=(c3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function c3(e){return Sv()?e instanceof Node||e instanceof Rr(e).Node:!1}function pa(e){return Sv()?e instanceof Element||e instanceof Rr(e).Element:!1}function Ds(e){return Sv()?e instanceof HTMLElement||e instanceof Rr(e).HTMLElement:!1}function uM(e){return!Sv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rr(e).ShadowRoot}function _v(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ma(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function xre(e){return/^(table|td|th)$/.test($u(e))}function Av(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const wre=/transform|translate|scale|rotate|perspective|filter/,Ere=/paint|layout|strict|content/,ll=e=>!!e&&e!=="none";let fx;function ZE(e){const t=pa(e)?ma(e):e;return ll(t.transform)||ll(t.translate)||ll(t.scale)||ll(t.rotate)||ll(t.perspective)||!QE()&&(ll(t.backdropFilter)||ll(t.filter))||wre.test(t.willChange||"")||Ere.test(t.contain||"")}function Sre(e){let t=jl(e);for(;Ds(t)&&!Pd(t);){if(ZE(t))return t;if(Av(t))return null;t=jl(t)}return null}function QE(){return fx==null&&(fx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),fx}function Pd(e){return/^(html|body|#document)$/.test($u(e))}function ma(e){return Rr(e).getComputedStyle(e)}function kv(e){return pa(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jl(e){if($u(e)==="html")return e;const t=e.assignedSlot||e.parentNode||uM(e)&&e.host||bo(e);return uM(t)?t.host:t}function u3(e){const t=jl(e);return Pd(t)?(e.ownerDocument||e).body:Ds(t)&&_v(t)?t:u3(t)}function Dd(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=u3(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Rr(i);if(a){const c=Lw(s);return t.concat(s,s.visualViewport||[],_v(i)?i:[],c&&n?Dd(c):[])}else return t.concat(i,Dd(i,[],n))}function Lw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function f3(e){const t=ma(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ds(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,c=ug(n)!==a||ug(r)!==s;return c&&(n=a,r=s),{width:n,height:r,$:c}}function JE(e){return pa(e)?e:e.contextElement}function fu(e){const t=JE(e);if(!Ds(t))return ao(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=f3(t);let s=(a?ug(n.width):n.width)/r,c=(a?ug(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const _re=ao(0);function d3(e){const t=Rr(e);return!QE()||!t.visualViewport?_re:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Are(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Rr(e)}function Ll(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=JE(e);let s=ao(1);t&&(r?pa(r)&&(s=fu(r)):s=fu(e));const c=Are(a,n,r)?d3(a):ao(0);let u=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,h=i.width/s.x,p=i.height/s.y;if(a&&r){const m=Rr(a),v=pa(r)?Rr(r):r;let x=m,b=Lw(x);for(;b&&v!==x;){const S=fu(b),_=b.getBoundingClientRect(),O=ma(b),k=_.left+(b.clientLeft+parseFloat(O.paddingLeft))*S.x,C=_.top+(b.clientTop+parseFloat(O.paddingTop))*S.y;u*=S.x,f*=S.y,h*=S.x,p*=S.y,u+=k,f+=C,x=Rr(b),b=Lw(x)}}return dg({width:h,height:p,x:u,y:f})}function Ov(e,t){const n=kv(e).scrollLeft;return t?t.left+n:Ll(bo(e)).left+n}function h3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ov(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function kre(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=bo(r),c=t?Av(t.floating):!1;if(r===s||c&&a)return n;let u={scrollLeft:0,scrollTop:0},f=ao(1);const h=ao(0),p=Ds(r);if((p||!a)&&(($u(r)!=="body"||_v(s))&&(u=kv(r)),p)){const v=Ll(r);f=fu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const m=s&&!p&&!a?h3(s,u):ao(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-u.scrollLeft*f.x+h.x+m.x,y:n.y*f.y-u.scrollTop*f.y+h.y+m.y}}function Ore(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Cre(e){const t=kv(e),n=e.ownerDocument.body,r=io(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=io(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+Ov(e);const s=-t.scrollTop;return ma(n).direction==="rtl"&&(a+=io(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Tre=25;function Nre(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Rr(e),a=bo(e),s=i.visualViewport;let c=a.clientWidth,u=a.clientHeight,f=0,h=0;if(s){const m=!QE()||t==="fixed";r?m||(f=-s.offsetLeft,h=-s.offsetTop):(c=s.width,u=s.height,m&&(f=s.offsetLeft,h=s.offsetTop))}if(Ov(a)<=0){const m=a.ownerDocument,v=m.body,x=getComputedStyle(v),b=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,S=Math.abs(a.clientWidth-v.clientWidth-b),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?S/2:S;_<=Tre&&(c-=_)}return{width:c,height:u,x:f,y:h}}function Mre(e,t){const n=Ll(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=fu(e),s=e.clientWidth*a.x,c=e.clientHeight*a.y,u=i*a.x,f=r*a.y;return{width:s,height:c,x:u,y:f}}function fM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Nre(e,n,t);else if(t==="document")r=Cre(bo(e));else if(pa(t))r=Mre(t,n);else{const i=d3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return dg(r)}function Ire(e,t){const n=t.get(e);if(n)return n;let r=Dd(e,[],!1).filter(c=>pa(c)&&$u(c)!=="body"),i=null;const a=ma(e).position==="fixed";let s=a?jl(e):e;for(;pa(s)&&!Pd(s);){const c=ma(s),u=ZE(s),f=i?i.position:a?"fixed":"";!u&&(f==="fixed"||f==="absolute"&&c.position==="static")?r=r.filter(p=>p!==s):i=c,s=jl(s)}return t.set(e,r),r}function Rre(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?Av(t)?[]:Ire(t,this._c):[].concat(n),r],c=fM(t,s[0],i);let u=c.top,f=c.right,h=c.bottom,p=c.left;for(let m=1;m<s.length;m++){const v=fM(t,s[m],i);u=io(v.top,u),f=_s(v.right,f),h=_s(v.bottom,h),p=io(v.left,p)}return{width:f-p,height:h-u,x:p,y:u}}function Pre(e){const{width:t,height:n}=f3(e);return{width:t,height:n}}function Dre(e,t,n){const r=Ds(t),i=bo(t),a=n==="fixed",s=Ll(e,!0,a,t);let c={scrollLeft:0,scrollTop:0};const u=ao(0);if((r||!a)&&(($u(t)!=="body"||_v(i))&&(c=kv(t)),r)){const m=Ll(t,!0,a,t);u.x=m.x+t.clientLeft,u.y=m.y+t.clientTop}!r&&i&&(u.x=Ov(i));const f=i&&!r&&!a?h3(i,c):ao(0),h=s.left+c.scrollLeft-u.x-f.x,p=s.top+c.scrollTop-u.y-f.y;return{x:h,y:p,width:s.width,height:s.height}}function dx(e){return ma(e).position==="static"}function dM(e,t){if(!Ds(e)||ma(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return bo(e)===n&&(n=n.ownerDocument.body),n}function p3(e,t){const n=Rr(e);if(Av(e))return n;if(!Ds(e)){let i=jl(e);for(;i&&!Pd(i);){if(pa(i)&&!dx(i))return i;i=jl(i)}return n}let r=dM(e,t);for(;r&&xre(r)&&dx(r);)r=dM(r,t);return r&&Pd(r)&&dx(r)&&!ZE(r)?n:r||Sre(e)||n}const jre=async function(e){const t=this.getOffsetParent||p3,n=this.getDimensions,r=await n(e.floating);return{reference:Dre(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Lre(e){return ma(e).direction==="rtl"}const zre={convertOffsetParentRelativeRectToViewportRelativeRect:kre,getDocumentElement:bo,getClippingRect:Rre,getOffsetParent:p3,getElementRects:jre,getClientRects:Ore,getDimensions:Pre,getScale:fu,isElement:pa,isRTL:Lre};function m3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $re(e,t,n){let r=null,i;const a=bo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function c(h,p){h===void 0&&(h=!1),p===void 0&&(p=1),s();const m=e.getBoundingClientRect(),{left:v,top:x,width:b,height:S}=m;if(h||t(),!b||!S)return;const _=fm(x),O=fm(a.clientWidth-(v+b)),k=fm(a.clientHeight-(x+S)),C=fm(v),T={rootMargin:-_+"px "+-O+"px "+-k+"px "+-C+"px",threshold:io(0,_s(1,p))||1};let R=!0;function L(D){const P=D[0].intersectionRatio;if(!m3(m,e.getBoundingClientRect()))return c();if(P!==p){if(!R)return c();P?c(!1,P):i=setTimeout(()=>{c(!1,1e-7)},1e3)}R=!1}try{r=new IntersectionObserver(L,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(L,T)}r.observe(e)}const u=Rr(e),f=()=>c(n);return u.addEventListener("resize",f),c(!0),()=>{u.removeEventListener("resize",f),s()}}function Bre(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,f=JE(e),h=i||a?[...f?Dd(f):[],...t?Dd(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const p=f&&c?$re(f,n,a):null;let m=-1,v=null;s&&(v=new ResizeObserver(_=>{let[O]=_;O&&O.target===f&&v&&t&&(v.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var k;(k=v)==null||k.observe(t)})),n()}),f&&!u&&v.observe(f),t&&v.observe(t));let x,b=u?Ll(e):null;u&&S();function S(){const _=Ll(e);b&&!m3(b,_)&&n(),b=_,x=requestAnimationFrame(S)}return n(),()=>{var _;h.forEach(O=>{i&&O.removeEventListener("scroll",n),a&&O.removeEventListener("resize",n)}),p==null||p(),(_=v)==null||_.disconnect(),v=null,u&&cancelAnimationFrame(x)}}const Ure=gre,Fre=vre,Hre=hre,Kre=bre,qre=pre,hM=dre,Gre=yre,Vre=(e,t,n)=>{const r=new Map,i=n??{},a={...zre,...i.platform,_c:r};return fre(e,t,{...i,platform:a})};var Wre=typeof document<"u",Yre=function(){},zm=Wre?y.useLayoutEffect:Yre;function hg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!hg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!hg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function g3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function pM(e,t){const n=g3(e);return Math.round(t*n)/n}function hx(e){const t=y.useRef(e);return zm(()=>{t.current=e}),t}function Xre(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:c=!0,whileElementsMounted:u,open:f}=e,[h,p]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,v]=y.useState(r);hg(m,r)||v(r);const[x,b]=y.useState(null),[S,_]=y.useState(null),O=y.useCallback(K=>{K!==T.current&&(T.current=K,b(K))},[]),k=y.useCallback(K=>{K!==R.current&&(R.current=K,_(K))},[]),C=a||x,N=s||S,T=y.useRef(null),R=y.useRef(null),L=y.useRef(h),D=u!=null,P=hx(u),B=hx(i),I=hx(f),U=y.useCallback(()=>{if(!T.current||!R.current)return;const K={placement:t,strategy:n,middleware:m};B.current&&(K.platform=B.current),Vre(T.current,R.current,K).then(Z=>{const j={...Z,isPositioned:I.current!==!1};V.current&&!hg(L.current,j)&&(L.current=j,Ea.flushSync(()=>{p(j)}))})},[m,t,n,B,I]);zm(()=>{f===!1&&L.current.isPositioned&&(L.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[f]);const V=y.useRef(!1);zm(()=>(V.current=!0,()=>{V.current=!1}),[]),zm(()=>{if(C&&(T.current=C),N&&(R.current=N),C&&N){if(P.current)return P.current(C,N,U);U()}},[C,N,U,P,D]);const G=y.useMemo(()=>({reference:T,floating:R,setReference:O,setFloating:k}),[O,k]),$=y.useMemo(()=>({reference:C,floating:N}),[C,N]),q=y.useMemo(()=>{const K={position:n,left:0,top:0};if(!$.floating)return K;const Z=pM($.floating,h.x),j=pM($.floating,h.y);return c?{...K,transform:"translate("+Z+"px, "+j+"px)",...g3($.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Z,top:j}},[n,c,$.floating,h.x,h.y]);return y.useMemo(()=>({...h,update:U,refs:G,elements:$,floatingStyles:q}),[h,U,G,$,q])}const Zre=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?hM({element:r.current,padding:i}).fn(n):{}:r?hM({element:r,padding:i}).fn(n):{}}}},Qre=(e,t)=>{const n=Ure(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jre=(e,t)=>{const n=Fre(e);return{name:n.name,fn:n.fn,options:[e,t]}},eie=(e,t)=>({fn:Gre(e).fn,options:[e,t]}),tie=(e,t)=>{const n=Hre(e);return{name:n.name,fn:n.fn,options:[e,t]}},nie=(e,t)=>{const n=Kre(e);return{name:n.name,fn:n.fn,options:[e,t]}},rie=(e,t)=>{const n=qre(e);return{name:n.name,fn:n.fn,options:[e,t]}},iie=(e,t)=>{const n=Zre(e);return{name:n.name,fn:n.fn,options:[e,t]}};var aie=Object.defineProperty,eS=(e,t)=>aie(e,"name",{value:t,configurable:!0});function zw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}eS(zw,"setRef");function v3(...e){return t=>{let n=!1;const r=e.map(i=>{const a=zw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():zw(e[i],null)}}}}eS(v3,"composeRefs");function Cv(...e){return y.useCallback(v3(...e),e)}eS(Cv,"useComposedRefs");var oie=Object.defineProperty,xi=(e,t)=>oie(e,"name",{value:t,configurable:!0});function sie(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=xi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return E.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return xi(i,"useContext"),[r,i]}xi(sie,"createContext");function y3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=xi(p=>{var _;const{scope:m,children:v,...x}=p,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return E.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function h(p,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${p}\` must be used within \`${a}\``)}return xi(h,"useContext"),[f,h]}xi(r,"createContext");const i=xi(()=>{const a=n.map(s=>y.createContext(s));return xi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,b3(i,...t)]}xi(y3,"createContextScope");function b3(...e){const t=e[0];if(e.length===1)return t;const n=xi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return xi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const p=u(a)[`__scope${f}`];return{...c,...p}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}xi(b3,"composeContextScopes");var lie=Object.defineProperty,Ui=(e,t)=>lie(e,"name",{value:t,configurable:!0});function x3(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];$w(i)&&typeof dm=="function"&&(i=dm(i._payload)),y.Children.forEach(i,m=>{var v;if(_3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;$w(b)&&typeof dm=="function"&&(b=dm(b._payload)),s=uie(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?S3(s):void 0,h=Cv(r,f);if(!s){if(i||i===0)throw new Error(c?hie(e):die(e));return i}const p=E3(a,s.props??{});return s.type!==y.Fragment&&(p.ref=r?h:f),y.cloneElement(s,p)});return t.displayName=`${e}.Slot`,t}Ui(x3,"createSlot");var w3=Symbol.for("radix.slottable");function cie(e){const t=Ui(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=w3,t}Ui(cie,"createSlottable");var uie=Ui((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function E3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Ui(E3,"mergeProps");function S3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Ui(S3,"getElementRef");function _3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===w3}Ui(_3,"isSlottable");var fie=Symbol.for("react.lazy");function $w(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===fie&&"_payload"in e&&A3(e._payload)}Ui($w,"isLazyComponent");function A3(e){return typeof e=="object"&&e!==null&&"then"in e}Ui(A3,"isPromiseLike");var die=Ui(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),hie=Ui(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),dm=wa[" use ".trim().toString()],pie=Object.defineProperty,mie=(e,t)=>pie(e,"name",{value:t,configurable:!0}),gie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],k3=gie.reduce((e,t)=>{const n=x3(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),E.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function vie(e,t){e&&Ea.flushSync(()=>e.dispatchEvent(t))}mie(vie,"dispatchDiscreteCustomEvent");var yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0});function O3(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}bie(O3,"useCallbackRef");var px=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},xie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},wie=Object.defineProperty,Eie=(e,t)=>wie(e,"name",{value:t,configurable:!0});function C3(e){const[t,n]=y.useState(void 0);return xie(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let s,c;if("borderBoxSize"in a){const u=a.borderBoxSize,f=Array.isArray(u)?u[0]:u;s=f.inlineSize,c=f.blockSize}else s=e.offsetWidth,c=e.offsetHeight;n({width:s,height:c})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Eie(C3,"useSize");var Sie=Object.defineProperty,bs=(e,t)=>Sie(e,"name",{value:t,configurable:!0}),T3="Popper",[N3,M3]=y3(T3),[_ie,I3]=N3(T3),Aie=bs(e=>{const{__scopePopper:t,children:n}=e,[r,i]=y.useState(null),[a,s]=y.useState(void 0);return E.jsx(_ie,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),kie="PopperAnchor",Oie=y.forwardRef(bs(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=I3(kie,r),c=y.useRef(null),u=s.onAnchorChange,f=y.useCallback(b=>{c.current=b,b&&u(b)},[u]),h=Cv(n,f),p=y.useRef(null);y.useEffect(()=>{if(!i)return;const b=p.current;p.current=i.current,b!==p.current&&u(p.current)});const m=s.placementState&&Tv(s.placementState),v=m==null?void 0:m[0],x=m==null?void 0:m[1];return i?null:E.jsx(k3.div,{"data-radix-popper-side":v,"data-radix-popper-align":x,...a,ref:h})},"PopperAnchor")),R3="PopperContent",[Cie,nOe]=N3(R3),Tie=y.forwardRef(bs(function(t,n){var fe,ke,we,ue,ht,qe,_e;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:c=0,arrowPadding:u=0,avoidCollisions:f=!0,collisionBoundary:h=[],collisionPadding:p=0,sticky:m="partial",hideWhenDetached:v=!1,updatePositionStrategy:x="optimized",onPlaced:b,...S}=t,_=I3(R3,r),[O,k]=y.useState(null),C=Cv(n,k),[N,T]=y.useState(null),R=C3(N),L=(R==null?void 0:R.width)??0,D=(R==null?void 0:R.height)??0,P=i+(s!=="center"?"-"+s:""),B=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},I=Array.isArray(h)?h:[h],U=I.length>0,V={padding:B,boundary:I.filter(P3),altBoundary:U},{refs:G,floatingStyles:$,placement:q,isPositioned:K,middlewareData:Z}=Xre({strategy:"fixed",placement:P,whileElementsMounted:bs((...De)=>Bre(...De,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[Qre({mainAxis:a+D,alignmentAxis:c}),f&&Jre({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?eie():void 0,...V}),f&&tie({...V}),nie({...V,apply:bs(({elements:De,rects:Kt,availableWidth:kn,availableHeight:zn})=>{const{width:ur,height:Oi}=Kt.reference,ti=De.floating.style;ti.setProperty("--radix-popper-available-width",`${kn}px`),ti.setProperty("--radix-popper-available-height",`${zn}px`),ti.setProperty("--radix-popper-anchor-width",`${ur}px`),ti.setProperty("--radix-popper-anchor-height",`${Oi}px`)},"apply")}),N&&iie({element:N,padding:u}),Nie({arrowWidth:L,arrowHeight:D}),v&&rie({strategy:"referenceHidden",...V,boundary:U?V.boundary:void 0})]}),j=_.setPlacementState;px(()=>(j(q),()=>{j(void 0)}),[q,j]);const[H,ee]=Tv(q),F=O3(b);px(()=>{K&&(F==null||F())},[K,F]);const de=(fe=Z.arrow)==null?void 0:fe.x,be=(ke=Z.arrow)==null?void 0:ke.y,ge=((we=Z.arrow)==null?void 0:we.centerOffset)!==0,[Ie,We]=y.useState();return px(()=>{O&&We(window.getComputedStyle(O).zIndex)},[O]),E.jsx("div",{ref:G.setFloating,"data-radix-popper-content-wrapper":"",style:{...$,transform:K?$.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ie,"--radix-popper-transform-origin":[(ue=Z.transformOrigin)==null?void 0:ue.x,(ht=Z.transformOrigin)==null?void 0:ht.y].join(" "),...((qe=Z.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:E.jsx(Cie,{scope:r,placedSide:H,placedAlign:ee,onArrowChange:T,arrowX:de,arrowY:be,shouldHideArrow:ge,children:E.jsx(k3.div,{"data-side":H,"data-align":ee,...S,ref:C,style:{...S.style,animation:K?(_e=S.style)==null?void 0:_e.animation:"none"}})})})},"PopperContent"));function P3(e){return e!==null}bs(P3,"isNotNull");var Nie=bs(e=>({name:"transformOrigin",options:e,fn(t){var S,_,O;const{placement:n,rects:r,middlewareData:i}=t,s=((S=i.arrow)==null?void 0:S.centerOffset)!==0,c=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[f,h]=Tv(n),p={start:"0%",center:"50%",end:"100%"}[h],m=(((_=i.arrow)==null?void 0:_.x)??0)+c/2,v=(((O=i.arrow)==null?void 0:O.y)??0)+u/2;let x="",b="";return f==="bottom"?(x=s?p:`${m}px`,b=`${-u}px`):f==="top"?(x=s?p:`${m}px`,b=`${r.floating.height+u}px`):f==="right"?(x=`${-u}px`,b=s?p:`${v}px`):f==="left"&&(x=`${r.floating.width+u}px`,b=s?p:`${v}px`),{data:{x,y:b}}}}),"transformOrigin");function Tv(e){const[t,n="center"]=e.split("-");return[t,n]}bs(Tv,"getSideAndAlignFromPlacement");var Mie=Aie,Iie=Oie,Rie=Tie,Pie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Die=Object.defineProperty,jie=(e,t)=>Die(e,"name",{value:t,configurable:!0}),Lie=y.forwardRef(jie(function(t,n){var u;const{container:r,...i}=t,[a,s]=y.useState(!1);Pie(()=>s(!0),[]);const c=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return c?Ea.createPortal(E.jsx(wv.div,{...i,ref:n}),c):null},"Portal")),mM=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},zie=Object.defineProperty,ho=(e,t)=>zie(e,"name",{value:t,configurable:!0});function D3(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}ho(D3,"useStateMachine");var j3=ho(e=>{const{present:t,children:n}=e,r=L3(t),i=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),a=z3(r.ref,$3(i));return typeof n=="function"||r.isPresent?y.cloneElement(i,{ref:a}):null},"Presence");function L3(e){const[t,n]=y.useState(),r=y.useRef(null),i=y.useRef(e),a=y.useRef("none"),s=y.useRef(void 0),c=e?"mounted":"unmounted",[u,f]=D3(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{u==="mounted"?(a.current=s.current??eu(r.current),s.current=void 0):a.current="none"},[u]),mM(()=>{const h=r.current,p=i.current;if(p!==e){const v=a.current,x=eu(h);e?(s.current=x,f("MOUNT")):x==="none"||(h==null?void 0:h.display)==="none"?f("UNMOUNT"):f(p&&v!==x?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,f]),mM(()=>{if(t){let h;const p=t.ownerDocument.defaultView??window,m=ho(x=>{const S=eu(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&S&&(f("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=p.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),v=ho(x=>{x.target===t&&(a.current=eu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",v),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{p.clearTimeout(h),t.removeEventListener("animationstart",v),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(h=>{if(h){const p=getComputedStyle(h);r.current=p,s.current=eu(p)}else r.current=null;n(h)},[])}}ho(L3,"usePresence");function Bw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}ho(Bw,"setRef");function z3(...e){const t=y.useRef(e);return t.current=e,y.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const c=Bw(s,n);return!i&&typeof c=="function"&&(i=!0),c});if(i)return()=>{for(let s=0;s<a.length;s++){const c=a[s];typeof c=="function"?c():Bw(r[s],null)}}},[])}ho(z3,"useStableComposedRefs");function eu(e){return(e==null?void 0:e.animationName)||"none"}ho(eu,"getAnimationName");function $3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}ho($3,"getElementRef");var B3=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},$ie=Object.defineProperty,Bie=(e,t)=>$ie(e,"name",{value:t,configurable:!0}),gM=wa[" useEffectEvent ".trim().toString()],vM=wa[" useInsertionEffect ".trim().toString()];function U3(e){if(typeof gM=="function")return gM(e);const t=y.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof vM=="function"?vM(()=>{t.current=e}):B3(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Bie(U3,"useEffectEvent");var Uie=Object.defineProperty,sh=(e,t)=>Uie(e,"name",{value:t,configurable:!0}),Fie=wa[" useInsertionEffect ".trim().toString()]||B3;function F3({prop:e,defaultProp:t,onChange:n=sh(()=>{},"onChange"),caller:r}){const[i,a,s]=H3({defaultProp:t,onChange:n}),c=e!==void 0,u=c?e:i,f=y.useCallback(h=>{var p;if(c){const m=K3(h)?h(e):h;m!==e&&((p=s.current)==null||p.call(s,m))}else a(h)},[c,e,a,s]);return[u,f]}sh(F3,"useControllableState");function H3({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),i=y.useRef(n),a=y.useRef(t);return Fie(()=>{a.current=t},[t]),y.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}sh(H3,"useUncontrolledState");function K3(e){return typeof e=="function"}sh(K3,"isFunction");var yM=Symbol("RADIX:SYNC_STATE");function Hie(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:c}=t,u=i!==void 0,f=U3(s),h=[{...n,state:a}];r&&h.push(r);const[p,m]=y.useReducer((S,_)=>{if(_.type===yM)return{...S,state:_.state};const O=e(S,_);return u&&!Object.is(O.state,S.state)&&f(O.state),O},...h),v=p.state,x=y.useRef(v);y.useEffect(()=>{x.current!==v&&(x.current=v,u||f(v))},[v,x,u]);const b=y.useMemo(()=>i!==void 0?{...p,state:i}:p,[p,i]);return y.useEffect(()=>{u&&!Object.is(i,p.state)&&m({type:yM,state:i})},[i,p.state,u]),[b,m]}sh(Hie,"useControllableStateReducer");var Kie=Object.defineProperty,js=(e,t)=>Kie(e,"name",{value:t,configurable:!0}),tS="Popover",[q3,rOe]=Fz(tS,[M3]),nS=M3(),[qie,Bu]=q3(tS),Gie=js(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,c=nS(t),u=y.useRef(null),[f,h]=y.useState(!1),[p,m]=F3({prop:r,defaultProp:i??!1,onChange:a,caller:tS});return E.jsx(Mie,{...c,children:E.jsx(qie,{scope:t,contentId:a3(),triggerRef:u,open:p,onOpenChange:m,onOpenToggle:y.useCallback(()=>m(v=>!v),[m]),hasCustomAnchor:f,onCustomAnchorAdd:y.useCallback(()=>h(!0),[]),onCustomAnchorRemove:y.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),Vie="PopoverTrigger",Wie=y.forwardRef(js(function(t,n){const{__scopePopover:r,...i}=t,a=Bu(Vie,r),s=nS(r),c=Lu(n,a.triggerRef),u=E.jsx(wv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":rS(a.open),...i,ref:c,onClick:ys(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:E.jsx(Iie,{asChild:!0,...s,children:u})},"PopoverTrigger")),G3="PopoverPortal",[Yie,Xie]=q3(G3,{forceMount:void 0}),Zie=js(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Bu(G3,t);return E.jsx(Yie,{scope:t,forceMount:n,children:E.jsx(j3,{present:n||a.open,children:E.jsx(Lie,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),jd="PopoverContent",Qie=y.forwardRef(js(function(t,n){const r=Xie(jd,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=Bu(jd,t.__scopePopover);return E.jsx(j3,{present:i||s.open,children:s.modal?E.jsx(eae,{...a,ref:n}):E.jsx(tae,{...a,ref:n})})},"PopoverContent")),Jie=HE("PopoverContent.RemoveScroll"),eae=y.forwardRef(js(function(t,n){const r=Bu(jd,t.__scopePopover),i=y.useRef(null),a=Lu(n,i),s=y.useRef(!1);return y.useEffect(()=>{const c=i.current;if(c)return Sz(c)},[]),E.jsx(jE,{as:Jie,allowPinchZoom:!0,children:E.jsx(V3,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ys(t.onCloseAutoFocus,c=>{var u;c.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:ys(t.onPointerDownOutside,c=>{const u=c.detail.originalEvent,f=u.button===0&&u.ctrlKey===!0,h=u.button===2||f;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:ys(t.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),tae=y.forwardRef(js(function(t,n){const r=Bu(jd,t.__scopePopover),i=y.useRef(!1),a=y.useRef(!1);return E.jsx(V3,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var c,u;(c=t.onCloseAutoFocus)==null||c.call(t,s),s.defaultPrevented||(i.current||(u=r.triggerRef.current)==null||u.focus(),s.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:s=>{var f,h;(f=t.onInteractOutside)==null||f.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const c=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),V3=y.forwardRef(js(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:c,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:p,...m}=t,v=Bu(jd,r),x=nS(r);return GE(),E.jsx(Wne,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:E.jsx(Bne,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:p,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:h,onDismiss:()=>v.onOpenChange(!1),deferPointerDownOutside:!0,children:E.jsx(Rie,{"data-state":rS(v.open),role:"dialog",id:v.contentId,...x,...m,ref:n,style:{...m.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})},"PopoverContentImpl"));function rS(e){return e?"open":"closed"}js(rS,"getState");var nae=Gie,rae=Wie,iae=Zie,W3=Qie;const aae=nae,oae=rae,Y3=y.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>E.jsx(iae,{children:E.jsx(W3,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:He("z-50 w-64 max-w-[calc(100vw-1rem)] rounded-md border bg-card p-3 text-card-foreground shadow-md outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...a})}));Y3.displayName=W3.displayName;const bM=3e5;function sae({socket:e,getToken:t}){const[n,r]=y.useState([]);if(y.useEffect(()=>{t().then(a=>a?fetch("/api/stats",{headers:{Authorization:`Bearer ${a}`}}):null).then(a=>a==null?void 0:a.json()).then(a=>(a==null?void 0:a.samples)&&r(a.samples)).catch(a=>console.warn("[MachineStats] seed failed",a))},[t]),y.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(c=>[...c,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return E.jsxs("div",{className:"w-full flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/60",children:[E.jsx(Hw,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),E.jsx(Hw,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),E.jsx(lae,{getToken:t})]})}function lae({getToken:e}){const[t,n]=y.useState(null);return y.useEffect(()=>{let r=!0,i=0;const a=async()=>{var f;try{const h=await e();if(!h)return;i=Date.now();const p=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(p.status===204){n(null);return}if(p.status!==200)return;const m=await p.json();if(!r||!((f=m==null?void 0:m.limits)!=null&&f.length))return;n(m)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},c=()=>{document.visibilityState==="visible"&&Date.now()-i>=bM&&a()};s();const u=setInterval(s,bM);return document.addEventListener("visibilitychange",c),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",c)}},[e]),E.jsx(cae,{usage:t})}function cae({usage:e}){const t=e&&X3(e.limits),[n,r]=y.useState(Uw),i=y.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=y.useCallback((c,u=0)=>{if(a(),!u){r(f=>wM(f,c));return}i.current=setTimeout(()=>{i.current=null,r(f=>wM(f,c))},u)},[]);return y.useEffect(()=>a,[]),!e||!t?null:E.jsxs(aae,{open:n.open,onOpenChange:c=>s(c?{type:"activate"}:{type:"dismiss"}),children:[E.jsx(oae,{asChild:!0,children:E.jsx("button",{type:"button","aria-label":"claude usage breakdown",className:"cursor-default rounded-sm outline-none focus-visible:ring-1 focus-visible:ring-ring",onPointerEnter:c=>s({type:"pointerenter",pointerType:c.pointerType},uae),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},xM),children:E.jsx(Hw,{label:"usage",value:t.percent,severity:t.severity})})}),E.jsx(Y3,{onOpenAutoFocus:c=>c.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},xM),children:E.jsx(fae,{usage:e})})]})}const uae=120,xM=80,Uw={open:!1,byHover:!1};function wM(e,t){switch(t.type){case"pointerenter":return EM(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return EM(t.pointerType)&&e.byHover?Uw:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return Uw}}const EM=e=>e==="mouse"||e==="";function fae({usage:e}){const t=X3(e.limits);return E.jsxs("div",{className:"text-[11px] leading-tight",children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[E.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&E.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),E.jsx("div",{className:"-mt-1 pb-2 text-[10px] text-muted-foreground",children:hae(e)}),E.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=mae(n.resetsAt),a=n===t;return E.jsxs("div",{"data-headline":a||void 0,className:He("flex flex-col gap-1",!a&&"opacity-60"),children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[E.jsxs("span",{className:He("truncate",a&&"font-medium"),children:[a&&E.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),dae(n)]}),E.jsxs("span",{className:He("tabular-nums shrink-0",Fw(n.percent,n.severity)),children:[n.percent,"%"]})]}),E.jsx(Z3,{value:n.percent,className:He("w-full",Fw(n.percent,n.severity))}),E.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),E.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function dae(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function X3(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function hae(e){const t=pae(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function pae(e){if(!e)return null;const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t))return null;const n=Math.round(Math.max(0,t)/6e4);if(n<1)return null;if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;return r<24?i?`${r}h ${i}m`:`${r}h`:`${Math.floor(r/24)}d`}function mae(e){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t)||t<=0)return null;const n=Math.round(t/6e4);if(n<1)return"1m";if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;if(r<48)return i?`${r}h ${i}m`:`${r}h`;const a=Math.floor(r/24),s=r%24;return s?`${a}d ${s}h`:`${a}d`}const gae={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500"};function Fw(e,t){const n=t?gae[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function Hw({label:e,value:t,series:n,title:r,severity:i}){const a=Fw(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return E.jsxs("span",{className:"flex items-center gap-1",title:s,children:[E.jsx("span",{className:"uppercase tracking-wide",children:e}),n?E.jsx(vae,{series:n,className:a}):E.jsx(Z3,{value:t,className:a}),E.jsxs("span",{className:He("tabular-nums",a),children:[t,"%"]})]})}function Z3({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return E.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:He("overflow-visible",t),preserveAspectRatio:"none",children:[E.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&E.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function vae({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,c)=>{const u=i>1?c/(i-1)*40:0,f=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${f.toFixed(1)}`}).join(" ");return E.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:He("overflow-visible",t),preserveAspectRatio:"none",children:E.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}function yae(e,t,n){var r;return!!(e.uid===t||(r=e.visibleTo)!=null&&r.includes(n.toLowerCase()))}function bae(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const rd="w-4 h-4 mt-0.5 shrink-0";function xae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?E.jsx(Hq,{className:`${rd} text-purple-400`}):(t==null?void 0:t.type)==="mention"?E.jsx(Mq,{className:`${rd} text-blue-400`}):(t==null?void 0:t.type)==="channel"?E.jsx(zq,{className:`${rd} text-green-400`}):e.sessionId.startsWith("slack-")?E.jsx(dw,{className:`${rd} text-yellow-400`}):E.jsx(dw,{className:`${rd} text-muted-foreground`})}function wae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?`DM${t.userName?` · ${t.userName}`:""}`:(t==null?void 0:t.type)==="mention"?`@mention${t.channelName?` · #${t.channelName}`:""}`:(t==null?void 0:t.type)==="channel"?`#${t.channelName||"channel"}`:e.sessionId.startsWith("slack-")?"Slack":null}const SM="chats-filter",_M="chats-unread-filter";function Eae({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,userUid:c,userEmail:u,unreads:f={},busySessions:h=new Set,socket:p}){var I;const m=Sa(),[v,x]=y.useState([]),[b,S]=y.useState(()=>localStorage.getItem(SM)||"mine"),[_,O]=y.useState(()=>localStorage.getItem(_M)==="true"),[k,C]=y.useState(""),N=y.useRef(null),T=y.useRef(null);function R(U){S(U),localStorage.setItem(SM,U)}function L(){const U=!_;O(U),localStorage.setItem(_M,String(U))}const D=y.useMemo(()=>v.filter(U=>b==="all"||yae(U,c,u)),[v,b,c,u]),P=y.useMemo(()=>D.filter(U=>f[U.sessionId]).length,[D,f]),B=y.useMemo(()=>_?D.filter(U=>f[U.sessionId]):D,[D,_,f]);return y.useEffect(()=>{e().then(U=>U?fetch("/api/version",{headers:{Authorization:`Bearer ${U}`}}):null).then(U=>U==null?void 0:U.json()).then(U=>U&&C(U.version)).catch(()=>{})},[]),y.useEffect(()=>{var V;(V=N.current)==null||V.abort();const U=new AbortController;return N.current=U,e().then(G=>{!G||U.signal.aborted||fetch("/api/sessions",{signal:U.signal,headers:{Authorization:`Bearer ${G}`}}).then($=>$.ok?$.json():[]).then($=>{Array.isArray($)&&x($)}).catch(()=>{})}),()=>U.abort()},[e,i]),y.useEffect(()=>{T.current&&T.current.scrollIntoView({block:"nearest"})},[t]),E.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[E.jsx("div",{className:"p-3",children:E.jsxs(Re,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[E.jsx(fv,{className:"w-4 h-4"})," New Chat",E.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),E.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:E.jsx(bne,{getToken:e,onRefresh:s,refreshKey:a})}),E.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),E.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(U=>E.jsx("button",{onClick:()=>R(U),className:He("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",b===U?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:U},U)),E.jsxs("button",{onClick:L,className:He("text-[10px] px-1.5 rounded-full transition-colors leading-none",_?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",P>0&&E.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),E.jsx(Pj,{className:"flex-1",children:E.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[B.length===0&&E.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:_?"No unread conversations":v.length===0?"No conversations yet":"No conversations match this filter"}),B.map(U=>{const V=f[U.sessionId],G=h.has(U.sessionId)||U.runStatus==="running"||U.scheduleRunStatus==="running",$=!G&&(!!U.lastStopReason||U.scheduleRunStatus==="error"||U.scheduleRunStatus==="aborted"),q=G?"border-amber-500":$?"border-red-500":V?"border-blue-500":"",K=!!(G||$||V);return E.jsx("button",{ref:U.sessionId===t?T:void 0,onClick:()=>n(U.sessionId,U.title),className:He("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",K?`rounded-r-lg border-l-[3px] ${q}`:"rounded-lg",t===U.sessionId&&"bg-accent"),children:E.jsxs("div",{className:"flex items-start gap-2",children:[xae(U),E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsx("span",{className:He("block truncate text-sm leading-snug",V&&"font-semibold"),children:U.title||"New session"}),E.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:wae(U)||U.userName}),E.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),E.jsx("span",{className:"text-[10px] text-muted-foreground",children:bae(U.lastModified)})]})]})]})},U.sessionId)})]})}),E.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[E.jsx(sae,{socket:p??null,getToken:e}),(I=m.sidebarExtras)==null?void 0:I.call(m),k&&E.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",k]})]})]})}function gi(e,t){const n=e[e.length-1];if((n==null?void 0:n.role)==="assistant"){if(t.type==="text"||t.type==="thinking"){const r=[...n.blocks],i=r[r.length-1];return(i==null?void 0:i.type)===t.type?(r[r.length-1]={...i,text:i.text+t.text},[...e.slice(0,-1),{...n,blocks:r}]):[...e.slice(0,-1),{...n,blocks:[...r,t]}]}return[...e.slice(0,-1),{...n,blocks:[...n.blocks,t]}]}return[...e,{id:ms(),role:"assistant",blocks:[t]}]}function AM(e,t,n="text"){const r=e[e.length-1],i={type:n,text:t};return(r==null?void 0:r.role)==="assistant"?[...e.slice(0,-1),{...r,blocks:[...r.blocks,i]}]:[...e,{id:ms(),role:"assistant",blocks:[i]}]}function Q3(e,t,n){for(let r=e.length-1;r>=0;r--){const i=e[r];if(i.role!=="assistant")continue;const a=i.blocks.findIndex(c=>c.type==="tool_use"&&c.toolUseId===t);if(a===-1)continue;const s=[...i.blocks];return s[a]={...s[a],input:n},[...e.slice(0,r),{...i,blocks:s},...e.slice(r+1)]}return e}function Sae(e,t){const[n,r]=y.useState([]),[i,a]=y.useState(!1),[s,c]=y.useState([]),u=y.useRef(t.initialSessionId),f=y.useRef(!1),h=y.useRef(s);h.current=s;const p=y.useRef(t.getToken);p.current=t.getToken;const m=y.useRef(t.onNewSession);m.current=t.onNewSession;const v=y.useRef(t.onDirectivesChanged);v.current=t.onDirectivesChanged;const x=y.useRef(t.onParticipantsChanged);x.current=t.onParticipantsChanged;const b=y.useRef(t.onEvent);b.current=t.onEvent;const S=y.useRef(e);S.current=e;const _=y.useCallback(I=>I!=null&&I===u.current,[]),O=y.useCallback(async()=>{var U;const I=u.current;if(I)try{const G=await(await bl(`/api/sessions/${I}/messages`,p.current)).json();r(uj(G)),a(!!G.busy),(U=x.current)==null||U.call(x,Array.isArray(G.participants)&&G.participants.length>1)}catch{}},[]);y.useEffect(()=>{if(!e)return;const I=e.on(U=>{var G,$,q,K,Z,j;(G=b.current)==null||G.call(b,U);const V=U;if(V.type==="compact_marker")return _(V.sessionId)?r(H=>[...H,{id:ms(),role:"assistant",blocks:[{type:"compact_marker",summary:V.summary??"",compactedCount:V.compactedCount??0}]}]):void 0;switch(U.type){case"thinking_delta":return _(U.sessionId)?r(H=>gi(H,{type:"thinking",text:U.text})):void 0;case"text_delta":return _(U.sessionId)?r(H=>gi(H,{type:"text",text:U.text})):void 0;case"tool_use":return _(U.sessionId)?r(H=>gi(H,{type:"tool_use",tool:U.tool,toolUseId:U.toolUseId,input:U.input})):void 0;case"tool_use_input":return _(U.sessionId)?r(H=>Q3(H,U.toolUseId,U.input)):void 0;case"tool_result":return _(U.sessionId)?r(H=>gi(H,{type:"tool_result",toolUseId:U.toolUseId,output:U.output})):void 0;case"tool_result_image":return _(U.sessionId)?r(H=>gi(H,{type:"image",src:U.dataUrl})):void 0;case"permission_request":return _(U.sessionId)?r(H=>gi(H,{type:"permission_request",id:U.id,tool:U.tool,input:U.input})):void 0;case"question_request":return _(U.sessionId)?r(H=>gi(H,{type:"question_request",id:U.id,questions:U.questions})):void 0;case"directives":return f.current?($=v.current)==null?void 0:$.call(v,U.directives):void 0;case"session_id":return!f.current||u.current?void 0:(u.current=U.sessionId,(q=m.current)==null?void 0:q.call(m,U.sessionId));case"forked":return U.sourceSessionId!==u.current?void 0:(u.current=U.sessionId,(K=m.current)==null?void 0:K.call(m,U.sessionId));case"session_busy":U.sessionId===u.current&&a(U.busy);return;case"session_stream":return U.sessionId!==u.current?void 0:_ae(r,U.event);case"session_messages_changed":U.sessionId===u.current&&O();return;case"done":{if(U.sessionId!==u.current)return;U.stopReason==="max_turns_reached"&&r(ee=>gi(ee,{type:"text",text:`
1847
+ `)},tne=0,Bc=[];function nne(e){var t=y.useRef([]),n=y.useRef([0,0]),r=y.useRef(),i=y.useState(tne++)[0],a=y.useState(yz)[0],s=y.useRef(e);y.useEffect(function(){s.current=e},[e]),y.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var b=CH([e.lockRef.current],(e.shards||[]).map(tM),!0).filter(Boolean);return b.forEach(function(S){return S.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),b.forEach(function(S){return S.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var c=y.useCallback(function(b,S){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!s.current.allowPinchZoom;var _=om(b),O=n.current,k="deltaX"in b?b.deltaX:O[0]-_[0],C="deltaY"in b?b.deltaY:O[1]-_[1],N,T=b.target,R=Math.abs(k)>Math.abs(C)?"h":"v";if("touches"in b&&R==="h"&&T.type==="range")return!1;var L=window.getSelection(),D=L&&L.anchorNode,P=D?D===T||D.contains(T):!1;if(P)return!1;var B=JN(R,T);if(!B)return!0;if(B?N=R:(N=R==="v"?"h":"v",B=JN(R,T)),!B)return!1;if(!r.current&&"changedTouches"in b&&(k||C)&&(r.current=N),!N)return!0;var I=r.current||N;return Qte(I,S,b,I==="h"?k:C)},[]),u=y.useCallback(function(b){var S=b;if(!(!Bc.length||Bc[Bc.length-1]!==a)){var _="deltaY"in S?eM(S):om(S),O=t.current.filter(function(N){return N.name===S.type&&(N.target===S.target||S.target===N.shadowParent)&&Jte(N.delta,_)})[0];if(O&&O.should){S.cancelable&&S.preventDefault();return}if(!O){var k=(s.current.shards||[]).map(tM).filter(Boolean).filter(function(N){return N.contains(S.target)}),C=k.length>0?c(S,k[0]):!s.current.noIsolation;C&&S.cancelable&&S.preventDefault()}}},[]),f=y.useCallback(function(b,S,_,O){var k={name:b,delta:S,target:_,should:O,shadowParent:rne(_)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(C){return C!==k})},1)},[]),h=y.useCallback(function(b){n.current=om(b),r.current=void 0},[]),p=y.useCallback(function(b){f(b.type,eM(b),b.target,c(b,e.lockRef.current))},[]),m=y.useCallback(function(b){f(b.type,om(b),b.target,c(b,e.lockRef.current))},[]);y.useEffect(function(){return Bc.push(a),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",u,$c),document.addEventListener("touchmove",u,$c),document.addEventListener("touchstart",h,$c),function(){Bc=Bc.filter(function(b){return b!==a}),document.removeEventListener("wheel",u,$c),document.removeEventListener("touchmove",u,$c),document.removeEventListener("touchstart",h,$c)}},[]);var v=e.removeScrollBar,x=e.inert;return y.createElement(y.Fragment,null,x?y.createElement(a,{styles:ene(i)}):null,v?y.createElement(qte,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function rne(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ine=Ite(vz,nne);var jE=y.forwardRef(function(e,t){return y.createElement(bv,aa({},e,{ref:t,sideCar:ine}))});jE.classNames=bv.classNames;var ane=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Uc=new WeakMap,sm=new WeakMap,lm={},lx=0,Ez=function(e){return e&&(e.host||Ez(e.parentNode))},one=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Ez(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},sne=function(e,t,n,r){var i=one(t,Array.isArray(e)?e:[e]);lm[n]||(lm[n]=new WeakMap);var a=lm[n],s=[],c=new Set,u=new Set(i),f=function(p){!p||c.has(p)||(c.add(p),f(p.parentNode))};i.forEach(f);var h=function(p){!p||u.has(p)||Array.prototype.forEach.call(p.children,function(m){if(c.has(m))h(m);else try{var v=m.getAttribute(r),x=v!==null&&v!=="false",b=(Uc.get(m)||0)+1,S=(a.get(m)||0)+1;Uc.set(m,b),a.set(m,S),s.push(m),b===1&&x&&sm.set(m,!0),S===1&&m.setAttribute(n,"true"),x||m.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",m,_)}})};return h(t),c.clear(),lx++,function(){s.forEach(function(p){var m=Uc.get(p)-1,v=a.get(p)-1;Uc.set(p,m),a.set(p,v),m||(sm.has(p)||p.removeAttribute(r),sm.delete(p)),v||p.removeAttribute(n)}),lx--,lx||(Uc=new WeakMap,Uc=new WeakMap,sm=new WeakMap,lm={})}},Sz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=ane(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),sne(r,i,n,"aria-hidden")):function(){return null}},xv="Dialog",[_z]=xj(xv),[lne,$i]=_z(xv),Az=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,c=y.useRef(null),u=y.useRef(null),[f,h]=rte({prop:r,defaultProp:i??!1,onChange:a,caller:xv});return E.jsx(lne,{scope:t,triggerRef:c,contentRef:u,contentId:nx(),titleId:nx(),descriptionId:nx(),open:f,onOpenChange:h,onOpenToggle:y.useCallback(()=>h(p=>!p),[h]),modal:s,children:n})};Az.displayName=xv;var kz="DialogTrigger",Oz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(kz,n),a=ei(t,i.triggerRef);return E.jsx(Pr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":UE(i.open),...r,ref:a,onClick:vr(e.onClick,i.onOpenToggle)})});Oz.displayName=kz;var LE="DialogPortal",[cne,Cz]=_z(LE,{forceMount:void 0}),Tz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=$i(LE,t);return E.jsx(cne,{scope:t,forceMount:n,children:y.Children.map(r,s=>E.jsx(Rs,{present:n||a.open,children:E.jsx(mz,{asChild:!0,container:i,children:s})}))})};Tz.displayName=LE;var cg="DialogOverlay",zE=y.forwardRef((e,t)=>{const n=Cz(cg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=$i(cg,e.__scopeDialog);return a.modal?E.jsx(Rs,{present:r||a.open,children:E.jsx(fne,{...i,ref:t})}):null});zE.displayName=cg;var une=fE("DialogOverlay.RemoveScroll"),fne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(cg,n),a=fte(),s=ei(t,a);return E.jsx(jE,{as:une,allowPinchZoom:!0,shards:[i.contentRef],children:E.jsx(Pr.div,{"data-state":UE(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),wu="DialogContent",$E=y.forwardRef((e,t)=>{const n=Cz(wu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=$i(wu,e.__scopeDialog);return E.jsx(Rs,{present:r||a.open,children:a.modal?E.jsx(dne,{...i,ref:t}):E.jsx(hne,{...i,ref:t})})});$E.displayName=wu;var dne=y.forwardRef((e,t)=>{const n=$i(wu,e.__scopeDialog),r=y.useRef(null),i=ei(t,n.contentRef,r);return y.useEffect(()=>{const a=r.current;if(a)return Sz(a)},[]),E.jsx(Nz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:vr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:vr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,c=s.button===0&&s.ctrlKey===!0;(s.button===2||c)&&a.preventDefault()}),onFocusOutside:vr(e.onFocusOutside,a=>a.preventDefault())})}),hne=y.forwardRef((e,t)=>{const n=$i(wu,e.__scopeDialog),r=y.useRef(!1),i=y.useRef(!1);return E.jsx(Nz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,c;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(c=n.triggerRef.current)==null||c.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,f;(u=e.onInteractOutside)==null||u.call(e,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=a.target;((f=n.triggerRef.current)==null?void 0:f.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Nz=y.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,c=$i(wu,n);return Ste(),E.jsx(E.Fragment,{children:E.jsx(hz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:E.jsx(fz,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":UE(c.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Mz="DialogTitle",BE=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Mz,n);return E.jsx(Pr.h2,{id:i.titleId,...r,ref:t})});BE.displayName=Mz;var Iz="DialogDescription",pne=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Iz,n);return E.jsx(Pr.p,{id:i.descriptionId,...r,ref:t})});pne.displayName=Iz;var Rz="DialogClose",Pz=y.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=$i(Rz,n);return E.jsx(Pr.button,{type:"button",...r,ref:t,onClick:vr(e.onClick,()=>i.onOpenChange(!1))})});Pz.displayName=Rz;function UE(e){return e?"open":"closed"}const Es=Az,oh=Oz,mne=Tz,Dz=y.forwardRef(({className:e,...t},n)=>E.jsx(zE,{ref:n,className:He("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Dz.displayName=zE.displayName;const uo=y.forwardRef(({className:e,children:t,...n},r)=>E.jsxs(mne,{children:[E.jsx(Dz,{}),E.jsxs($E,{ref:r,className:He("fixed left-[50%] top-[50%] z-50 flex flex-col w-[calc(100vw-2rem)] max-w-lg max-h-[85dvh] overflow-y-auto translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-4 sm:p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",e),...n,children:[t,E.jsxs(Pz,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[E.jsx(Rl,{className:"h-4 w-4"}),E.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));uo.displayName=$E.displayName;function Dl({className:e,...t}){return E.jsx("div",{className:He("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function jz({className:e,...t}){return E.jsx("div",{"data-dialog-body":!0,className:He("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Lz({className:e,...t}){return E.jsx("div",{className:He("shrink-0 -mx-4 px-4 pt-3 border-t sm:-mx-6 sm:px-6","flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const Ss=y.forwardRef(({className:e,...t},n)=>E.jsx(BE,{ref:n,className:He("text-lg font-semibold leading-none tracking-tight",e),...t}));Ss.displayName=BE.displayName;const gne=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),vne=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function yne(e,t){const n=await t();if(!n)return[];const r=await fetch(`/api/workspace/ls?path=${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${n}`}});return r.ok?(await r.json()).entries??[]:[]}function bne({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=y.useState(new Map),[a,s]=y.useState(()=>new Set),[c,u]=y.useState(null),[f,h]=y.useState(!1),[p,m]=y.useState("fit"),[v,x]=y.useState(null),[b,S]=y.useState(null),_=y.useRef(null),[O,k]=y.useState(null),[C,N]=y.useState(!1),[T,R]=y.useState([]),L=y.useCallback(async $=>{const q=await yne($,e);i(K=>new Map(K).set($,q))},[e]);y.useEffect(()=>{L(""),a.forEach($=>L($))},[L,n]);const D=r.get("")??[],P=y.useCallback($=>{try{const q=$.contentDocument;if(!(q!=null&&q.body))return;const K=Math.max(q.body.offsetWidth,q.body.scrollWidth),Z=Math.max(q.body.offsetHeight,q.body.scrollHeight);K&&Z&&S({w:K,h:Z})}catch{}},[]),B=y.useCallback(()=>{const $=_.current,q=b;if(!$||!q)return;const K=16,Z=$.clientWidth-K,j=$.clientHeight-K,H=Math.min(Z/q.w,j/q.h,1);x({scale:H,w:q.w,h:q.h})},[b]);y.useEffect(()=>{if(!(c!=null&&c.html)||p!=="fit"){x(null);return}const $=_.current;if(!$)return;const q=new ResizeObserver(()=>requestAnimationFrame(B));return q.observe($),()=>q.disconnect()},[c==null?void 0:c.html,f,p,B]),y.useEffect(()=>{C&&e().then($=>{$&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${$}`}}).then(q=>q.json()).then(R).catch(()=>{})})},[C]);const I=$=>{s(q=>{const K=new Set(q);return K.has($)?K.delete($):(K.add($),r.has($)||L($)),K})},U=($,q)=>{const K=new URLSearchParams({path:$});return O&&K.set("token",O),q&&K.set("dl","1"),`/api/workspace/raw?${K}`},V=async $=>{var Z;const q=await e();if(!q)return;k(q);const K=((Z=$.split(".").pop())==null?void 0:Z.toLowerCase())??"";if(K==="html"||K==="htm"){u({path:$,content:"",binary:!1,html:!0});return}if(gne.has(K)){u({path:$,content:"",binary:!1,image:!0});return}if(vne.has(K)){u({path:$,content:"",binary:!1,html:!0});return}try{const j=await fetch(`/api/workspace/file?path=${encodeURIComponent($)}`,{headers:{Authorization:`Bearer ${q}`}});if(!j.ok)return;const H=await j.json();u({path:$,content:H.content,binary:!!H.binary})}catch{}},G=($,q)=>E.jsx(E.Fragment,{children:$.map(K=>{const Z=K.path.split("/").pop();return E.jsxs("div",{children:[K.type==="dir"?E.jsxs("button",{onClick:()=>I(K.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+q*12},children:[E.jsx(Is,{className:He("w-3 h-3 shrink-0 transition-transform",a.has(K.path)&&"rotate-90")}),E.jsx(Lq,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),E.jsx("span",{className:"truncate",children:Z})]}):E.jsxs("button",{onClick:()=>V(K.path),className:"w-full flex items-center gap-1 px-2 py-1 rounded hover:bg-accent/50 text-left text-sm",style:{paddingLeft:8+q*12+12},title:K.oneLiner||K.path,children:[E.jsx(oE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),E.jsx("span",{className:"truncate",children:Z})]}),K.type==="dir"&&a.has(K.path)&&G(r.get(K.path)??[],q+1)]},K.path)})});return E.jsxs(E.Fragment,{children:[E.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),E.jsxs("div",{className:"flex items-center gap-0.5",children:[E.jsx("button",{onClick:()=>N(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:E.jsx($q,{className:"w-3 h-3"})}),E.jsx("button",{onClick:()=>{L(""),a.forEach($=>L($)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:E.jsx(Wq,{className:"w-3 h-3"})})]})]}),E.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:D.length===0?E.jsx("p",{className:"text-xs text-muted-foreground px-3 py-2",children:"Empty. Drop .md files into data/workspace/ or ask the agent to create some."}):G(D,0)}),E.jsx(Es,{open:!!c,onOpenChange:$=>{$||(u(null),h(!1),m("fit"),S(null))},children:E.jsxs(uo,{className:He(c!=null&&c.html?He("!flex !flex-col !p-0 !gap-0 overflow-hidden",f?"max-w-none w-[100vw] h-[100vh] rounded-none border-0":"max-w-[90vw] w-[90vw] h-[85vh]"):"max-w-3xl max-h-[80vh] !flex !flex-col overflow-hidden"),children:[E.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(c==null?void 0:c.html)&&E.jsxs(E.Fragment,{children:[E.jsx("button",{onClick:()=>m($=>$==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:p==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:p==="fit"?E.jsx(Kq,{className:"w-4 h-4"}):E.jsx(Xq,{className:"w-4 h-4"})}),E.jsx("button",{onClick:()=>h($=>!$),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:f?"Restore":"Maximize",children:f?E.jsx(lE,{className:"w-4 h-4"}):E.jsx(sE,{className:"w-4 h-4"})})]}),c&&E.jsx("a",{href:U(c.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:E.jsx(mj,{className:"w-4 h-4"})})]}),E.jsx(Dl,{className:He((c==null?void 0:c.html)&&"px-4 py-3 shrink-0 border-b"),children:E.jsx(Ss,{className:"font-mono text-sm truncate pr-16",children:c==null?void 0:c.path})}),E.jsx("div",{ref:c!=null&&c.html?_:void 0,className:He(c!=null&&c.html?He("flex-1 min-h-0 bg-muted/10",p==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:c!=null&&c.html?p==="fit"?E.jsx("div",{style:v?{width:v.w*v.scale,height:v.h*v.scale}:{width:"100%",height:"100%"},children:E.jsx("iframe",{src:U(c.path),className:"border-0 bg-white origin-top-left",title:c.path,onLoad:$=>{P($.currentTarget),B()},style:v?{width:v.w,height:v.h,transform:`scale(${v.scale})`}:{width:"100%",height:"100%"}})}):E.jsx("iframe",{src:U(c.path),className:"border-0 bg-white mx-auto block",title:c.path,onLoad:$=>P($.currentTarget),style:{width:(b==null?void 0:b.w)||"100%",height:(b==null?void 0:b.h)||"100%"}}):c!=null&&c.image?E.jsx("div",{className:"flex items-center justify-center p-4",children:E.jsx("img",{src:U(c.path),alt:c.path,className:"max-w-full max-h-[70vh] object-contain"})}):c!=null&&c.binary?E.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):c!=null&&c.path.toLowerCase().endsWith(".md")||c!=null&&c.path.toLowerCase().endsWith(".markdown")?E.jsx("div",{className:"text-sm",children:E.jsx(yL,{remarkPlugins:[FL],rehypePlugins:[uz],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none",children:c.content})}):E.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:c==null?void 0:c.content})})]})}),E.jsx(Es,{open:C,onOpenChange:N,children:E.jsxs(uo,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[E.jsx(Dl,{children:E.jsx(Ss,{className:"text-sm",children:"Activity Log"})}),E.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[T.map($=>E.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[E.jsx("span",{className:"text-sm text-foreground",children:$.message}),E.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:xne($.date)})]}),$.files.length>0&&E.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:$.files.map(q=>E.jsx("span",{className:"inline-block mr-2 font-mono",children:q},q))})]},$.hash)),T.length===0&&E.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function xne(e){const t=new Date(e),r=new Date().getTime()-t.getTime(),i=Math.floor(r/6e4);if(i<60)return`${i}m ago`;const a=Math.floor(i/60);return a<24?`${a}h ago`:t.toLocaleDateString(void 0,{month:"short",day:"numeric"})}var wne=Object.defineProperty,ju=(e,t)=>wne(e,"name",{value:t,configurable:!0}),zz=!!(typeof window<"u"&&window.document&&window.document.createElement);function ys(e,t,{checkForDefaultPrevented:n=!0}={}){return ju(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}ju(ys,"composeEventHandlers");function Ene(e){var t;if(!zz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}ju(Ene,"getOwnerWindow");function Ow(e){if(!zz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}ju(Ow,"getOwnerDocument");function $z(e,t=!1){const{activeElement:n}=Ow(e);if(!(n!=null&&n.nodeName))return null;if(Bz(n)&&n.contentDocument)return $z(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=Ow(n).getElementById(r);if(i)return i}}return n}ju($z,"getActiveElement");function Bz(e){return e.tagName==="IFRAME"}ju(Bz,"isFrame");var Sne=Object.defineProperty,FE=(e,t)=>Sne(e,"name",{value:t,configurable:!0});function Cw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}FE(Cw,"setRef");function Uz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=Cw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Cw(e[i],null)}}}}FE(Uz,"composeRefs");function Lu(...e){return y.useCallback(Uz(...e),e)}FE(Lu,"useComposedRefs");var _ne=Object.defineProperty,bi=(e,t)=>_ne(e,"name",{value:t,configurable:!0});function Ane(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=bi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return E.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return bi(i,"useContext"),[r,i]}bi(Ane,"createContext");function Fz(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=bi(p=>{var _;const{scope:m,children:v,...x}=p,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return E.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function h(p,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${p}\` must be used within \`${a}\``)}return bi(h,"useContext"),[f,h]}bi(r,"createContext");const i=bi(()=>{const a=n.map(s=>y.createContext(s));return bi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,Hz(i,...t)]}bi(Fz,"createContextScope");function Hz(...e){const t=e[0];if(e.length===1)return t;const n=bi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return bi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const p=u(a)[`__scope${f}`];return{...c,...p}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}bi(Hz,"composeContextScopes");var kne=Object.defineProperty,Bi=(e,t)=>kne(e,"name",{value:t,configurable:!0});function HE(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];Tw(i)&&typeof cm=="function"&&(i=cm(i._payload)),y.Children.forEach(i,m=>{var v;if(Vz(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;Tw(b)&&typeof cm=="function"&&(b=cm(b._payload)),s=Cne(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?Gz(s):void 0,h=Lu(r,f);if(!s){if(i||i===0)throw new Error(c?Mne(e):Nne(e));return i}const p=qz(a,s.props??{});return s.type!==y.Fragment&&(p.ref=r?h:f),y.cloneElement(s,p)});return t.displayName=`${e}.Slot`,t}Bi(HE,"createSlot");var Kz=Symbol.for("radix.slottable");function One(e){const t=Bi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Kz,t}Bi(One,"createSlottable");var Cne=Bi((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function qz(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Bi(qz,"mergeProps");function Gz(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Bi(Gz,"getElementRef");function Vz(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Kz}Bi(Vz,"isSlottable");var Tne=Symbol.for("react.lazy");function Tw(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Tne&&"_payload"in e&&Wz(e._payload)}Bi(Tw,"isLazyComponent");function Wz(e){return typeof e=="object"&&e!==null&&"then"in e}Bi(Wz,"isPromiseLike");var Nne=Bi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Mne=Bi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),cm=wa[" use ".trim().toString()],Ine=Object.defineProperty,Rne=(e,t)=>Ine(e,"name",{value:t,configurable:!0}),Pne=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],wv=Pne.reduce((e,t)=>{const n=HE(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),E.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Yz(e,t){e&&Ea.flushSync(()=>e.dispatchEvent(t))}Rne(Yz,"dispatchDiscreteCustomEvent");var Dne=Object.defineProperty,jne=(e,t)=>Dne(e,"name",{value:t,configurable:!0});function Ev(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}jne(Ev,"useCallbackRef");var Lne=Object.defineProperty,Fn=(e,t)=>Lne(e,"name",{value:t,configurable:!0}),Nw="dismissableLayer.update",zne="dismissableLayer.pointerDownOutside",$ne="dismissableLayer.focusOutside",nM,Xz=y.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Bne=y.forwardRef(Fn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:c,onInteractOutside:u,onDismiss:f,...h}=t,p=y.useContext(Xz),[m,v]=y.useState(null),x=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=y.useState({}),S=Lu(n,v),_=Array.from(p.layers),[O]=[...p.layersWithOutsidePointerEventsDisabled].slice(-1),k=O?_.indexOf(O):-1,C=m?_.indexOf(m):-1,N=p.layersWithOutsidePointerEventsDisabled.size>0,T=C>=k,R=y.useRef(!1),L=Zz(I=>{s==null||s(I),u==null||u(I),I.defaultPrevented||f==null||f()},{ownerDocument:x,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:p.dismissableSurfaces,shouldHandlePointerDownOutside:y.useCallback(I=>{if(!(I instanceof Node))return!1;const U=[...p.branches].some(V=>V.contains(I));return T&&!U},[p.branches,T])}),D=Qz(I=>{if(i&&R.current)return;const U=I.target;[...p.branches].some(G=>G.contains(U))||(c==null||c(I),u==null||u(I),I.defaultPrevented||f==null||f())},x),P=m?C===_.length-1:!1,B=Ev(I=>{I.key==="Escape"&&(a==null||a(I),!I.defaultPrevented&&f&&(I.preventDefault(),f()))});return y.useEffect(()=>{if(P)return x.addEventListener("keydown",B,{capture:!0}),()=>x.removeEventListener("keydown",B,{capture:!0})},[x,P,B]),y.useEffect(()=>{if(m)return r&&(p.layersWithOutsidePointerEventsDisabled.size===0&&(nM=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),p.layersWithOutsidePointerEventsDisabled.add(m)),p.layers.add(m),Mw(),()=>{r&&(p.layersWithOutsidePointerEventsDisabled.delete(m),p.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=nM))}},[m,x,r,p]),y.useEffect(()=>()=>{m&&(p.layers.delete(m),p.layersWithOutsidePointerEventsDisabled.delete(m),Mw())},[m,p]),y.useEffect(()=>{const I=Fn(()=>b({}),"handleUpdate");return document.addEventListener(Nw,I),()=>document.removeEventListener(Nw,I)},[]),E.jsx(wv.div,{...h,ref:S,style:{pointerEvents:N?T?"auto":"none":void 0,...t.style},onFocusCapture:ys(t.onFocusCapture,D.onFocusCapture),onBlurCapture:ys(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:ys(t.onPointerDownCapture,L.onPointerDownCapture)})},"DismissableLayer"));function Une(){const e=y.useContext(Xz),[t,n]=y.useState(null);return y.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}Fn(Une,"useDismissableLayerSurface");var Fne=Fn(()=>!0,"IS_TRUE");function Zz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=Fne}=t,c=Ev(e),u=y.useRef(!1),f=y.useRef(!1),h=y.useRef(new Map),p=y.useRef(()=>{});return y.useEffect(()=>{function m(){f.current=!1,i.current=!1,h.current.clear()}Fn(m,"resetOutsideInteraction");function v(){return Array.from(h.current.values()).some(Boolean)}Fn(v,"isOutsideInteractionIntercepted");function x(k){if(!f.current)return;const C=k.target;C instanceof Node&&[...a].some(T=>T.contains(C))||h.current.set(k.type,!0),k.type==="click"&&window.setTimeout(()=>{f.current&&p.current()},0)}Fn(x,"handleInteractionCapture");function b(k){f.current&&h.current.set(k.type,!1)}Fn(b,"handleInteractionBubble");const S=Fn(k=>{if(k.target&&!u.current){let C=function(){n.removeEventListener("click",p.current);const T=v();m(),T||KE(zne,c,N,{discrete:!0})};if(Fn(C,"handleAndDispatchPointerDownOutsideEvent"),!s(k.target)){n.removeEventListener("click",p.current),m(),u.current=!1;return}const N={originalEvent:k};f.current=!0,i.current=r&&k.button===0,h.current.clear(),!r||k.button!==0?C():(n.removeEventListener("click",p.current),p.current=C,n.addEventListener("click",p.current,{once:!0}))}else n.removeEventListener("click",p.current),m();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const k of _)n.addEventListener(k,x,!0),n.addEventListener(k,b);const O=window.setTimeout(()=>{n.addEventListener("pointerdown",S)},0);return()=>{window.clearTimeout(O),n.removeEventListener("pointerdown",S),n.removeEventListener("click",p.current);for(const k of _)n.removeEventListener(k,x,!0),n.removeEventListener(k,b)}},[n,c,r,i,a,s]),{onPointerDownCapture:Fn(()=>u.current=!0,"onPointerDownCapture")}}Fn(Zz,"usePointerDownOutside");function Qz(e,t=globalThis==null?void 0:globalThis.document){const n=Ev(e),r=y.useRef(!1);return y.useEffect(()=>{const i=Fn(a=>{a.target&&!r.current&&KE($ne,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:Fn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Fn(()=>r.current=!1,"onBlurCapture")}}Fn(Qz,"useFocusOutside");function Mw(){const e=new CustomEvent(Nw);document.dispatchEvent(e)}Fn(Mw,"dispatchUpdate");function KE(e,t,n,{discrete:r}){const i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?Yz(i,a):i.dispatchEvent(a)}Fn(KE,"handleAndDispatchCustomEvent");var Hne=Object.defineProperty,qE=(e,t)=>Hne(e,"name",{value:t,configurable:!0}),um=0,Xi=null;function Kne(e){return GE(),e.children}qE(Kne,"FocusGuards");function GE(){y.useEffect(()=>{Xi||(Xi={start:Iw(),end:Iw()});const{start:e,end:t}=Xi;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),um++,()=>{um===1&&(Xi==null||Xi.start.remove(),Xi==null||Xi.end.remove(),Xi=null),um=Math.max(0,um-1)}},[])}qE(GE,"useFocusGuards");function Iw(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}qE(Iw,"createFocusGuard");var qne=Object.defineProperty,Gne=(e,t)=>qne(e,"name",{value:t,configurable:!0});function Rw(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Gne(Rw,"useCallbackRef");var Vne=Object.defineProperty,mr=(e,t)=>Vne(e,"name",{value:t,configurable:!0}),cx="focusScope.autoFocusOnMount",ux="focusScope.autoFocusOnUnmount",rM={bubbles:!1,cancelable:!0},Wne=y.forwardRef(mr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...c}=t,[u,f]=y.useState(null),h=Rw(a),p=Rw(s),m=y.useRef(null),v=Lu(n,f),x=y.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;y.useEffect(()=>{if(i){let S=function(C){if(x.paused||!u)return;const N=C.target;u.contains(N)?m.current=N:Ya(m.current,{select:!0})},_=function(C){if(x.paused||!u)return;const N=C.relatedTarget;N!==null&&(u.contains(N)||Ya(m.current,{select:!0}))},O=function(C){if(document.activeElement===document.body)for(const T of C)T.removedNodes.length>0&&Ya(u)};mr(S,"handleFocusIn"),mr(_,"handleFocusOut"),mr(O,"handleMutations"),document.addEventListener("focusin",S),document.addEventListener("focusout",_);const k=new MutationObserver(O);return u&&k.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",S),document.removeEventListener("focusout",_),k.disconnect()}}},[i,u,x.paused]),y.useEffect(()=>{if(u){iM.add(x);const S=document.activeElement;if(!u.contains(S)){const O=new CustomEvent(cx,rM);u.addEventListener(cx,h),u.dispatchEvent(O),O.defaultPrevented||(Jz(i3(VE(u)),{select:!0}),document.activeElement===S&&Ya(u))}return()=>{u.removeEventListener(cx,h),setTimeout(()=>{const O=new CustomEvent(ux,rM);u.addEventListener(ux,p),u.dispatchEvent(O),O.defaultPrevented||Ya(S??document.body,{select:!0}),u.removeEventListener(ux,p),iM.remove(x)},0)}}},[u,h,p,x]);const b=y.useCallback(S=>{if(!r&&!i||x.paused)return;const _=S.key==="Tab"&&!S.altKey&&!S.ctrlKey&&!S.metaKey,O=document.activeElement;if(_&&O){const k=S.currentTarget,[C,N]=e3(k);C&&N?!S.shiftKey&&O===N?(S.preventDefault(),r&&Ya(C,{select:!0})):S.shiftKey&&O===C&&(S.preventDefault(),r&&Ya(N,{select:!0})):O===k&&S.preventDefault()}},[r,i,x.paused]);return E.jsx(wv.div,{tabIndex:-1,...c,ref:v,onKeyDown:b})},"FocusScope"));function Jz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Ya(r,{select:t}),document.activeElement!==n)return}mr(Jz,"focusFirst");function e3(e){const t=VE(e),n=Pw(t,e),r=Pw(t.reverse(),e);return[n,r]}mr(e3,"getTabbableEdges");function VE(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:mr(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)t.push(n.currentNode);return t}mr(VE,"getTabbableCandidates");function Pw(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):t3(r,{upTo:t})))return r}mr(Pw,"findVisible");function t3(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}mr(t3,"isHidden");function n3(e){return e instanceof HTMLInputElement&&"select"in e}mr(n3,"isSelectableInput");function Ya(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&n3(e)&&t&&e.select()}}mr(Ya,"focus");var iM=r3();function r3(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Dw(e,t),e.unshift(t)},remove(t){var n;e=Dw(e,t),(n=e[0])==null||n.resume()}}}mr(r3,"createFocusScopesStack");function Dw(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}mr(Dw,"arrayRemove");function i3(e){return e.filter(t=>t.tagName!=="A")}mr(i3,"removeLinks");var Yne=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Xne=Object.defineProperty,Zne=(e,t)=>Xne(e,"name",{value:t,configurable:!0}),Qne=wa[" useId ".trim().toString()]||(()=>{}),Jne=0;function a3(e){const[t,n]=y.useState(Qne());return Yne(()=>{e||n(r=>r??String(Jne++))},[e]),e||(t?`radix-${t}`:"")}Zne(a3,"useId");const ere=["top","right","bottom","left"],_s=Math.min,io=Math.max,ug=Math.round,fm=Math.floor,ao=e=>({x:e,y:e}),tre={left:"right",right:"left",bottom:"top",top:"bottom"};function o3(e,t,n){return io(e,_s(t,n))}function fo(e,t){return typeof e=="function"?e(t):e}function As(e){return e.split("-")[0]}function zu(e){return e.split("-")[1]}function WE(e){return e==="x"?"y":"x"}function YE(e){return e==="y"?"height":"width"}function oa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function XE(e){return WE(oa(e))}function nre(e,t,n){n===void 0&&(n=!1);const r=zu(e),i=XE(e),a=YE(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=fg(s)),[s,fg(s)]}function rre(e){const t=fg(e);return[jw(e),t,jw(t)]}function jw(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const aM=["left","right"],oM=["right","left"],ire=["top","bottom"],are=["bottom","top"];function ore(e,t,n){switch(e){case"top":case"bottom":return n?t?oM:aM:t?aM:oM;case"left":case"right":return t?ire:are;default:return[]}}function sre(e,t,n,r){const i=zu(e);let a=ore(As(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(jw)))),a}function fg(e){const t=As(e);return tre[t]+e.slice(t.length)}function lre(e){var t,n,r,i;return{top:(t=e.top)!=null?t:0,right:(n=e.right)!=null?n:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function s3(e){return typeof e!="number"?lre(e):{top:e,right:e,bottom:e,left:e}}function dg(e){const{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function sM(e,t,n){let{reference:r,floating:i}=e;const a=oa(t),s=XE(t),c=YE(s),u=As(t),f=a==="y",h=r.x+r.width/2-i.width/2,p=r.y+r.height/2-i.height/2,m=r[c]/2-i[c]/2;let v;switch(u){case"top":v={x:h,y:r.y-i.height};break;case"bottom":v={x:h,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:p};break;case"left":v={x:r.x-i.width,y:p};break;default:v={x:r.x,y:r.y}}const x=zu(t);return x&&(v[s]+=m*(x==="end"?1:-1)*(n&&f?-1:1)),v}async function cre(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:c,strategy:u}=e,{boundary:f="clippingAncestors",rootBoundary:h="viewport",elementContext:p="floating",altBoundary:m=!1,padding:v=0}=fo(t,e),x=s3(v),S=c[m?p==="floating"?"reference":"floating":p],_=dg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(S)))==null||n?S:S.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(c.floating)),boundary:f,rootBoundary:h,strategy:u})),O=p==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,k=await(a.getOffsetParent==null?void 0:a.getOffsetParent(c.floating)),C=await(a.isElement==null?void 0:a.isElement(k))&&await(a.getScale==null?void 0:a.getScale(k))||{x:1,y:1},N=dg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:O,offsetParent:k,strategy:u}):O);return{top:(_.top-N.top+x.top)/C.y,bottom:(N.bottom-_.bottom+x.bottom)/C.y,left:(_.left-N.left+x.left)/C.x,right:(N.right-_.right+x.right)/C.x}}const ure=50,fre=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,c=s.detectOverflow?s:{...s,detectOverflow:cre},u=await(s.isRTL==null?void 0:s.isRTL(t));let f=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:p}=sM(f,r,u),m=r,v=0;const x={};for(let b=0;b<a.length;b++){const S=a[b];if(!S)continue;const{name:_,fn:O}=S,{x:k,y:C,data:N,reset:T}=await O({x:h,y:p,initialPlacement:r,placement:m,strategy:i,middlewareData:x,rects:f,platform:c,elements:{reference:e,floating:t}});h=k??h,p=C??p,x[_]={...x[_],...N},T&&v<ure&&(v++,typeof T=="object"&&(T.placement&&(m=T.placement),T.rects&&(f=T.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:p}=sM(f,m,u)),b=-1)}return{x:h,y:p,placement:m,strategy:i,middlewareData:x}},dre=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:c,middlewareData:u}=t,{element:f,padding:h=0}=fo(e,t)||{};if(f==null)return{};const p=s3(h),m={x:n,y:r},v=XE(i),x=YE(v),b=await s.getDimensions(f),S=v==="y",_=S?"top":"left",O=S?"bottom":"right",k=S?"clientHeight":"clientWidth",C=a.reference[x]+a.reference[v]-m[v]-a.floating[x],N=m[v]-a.reference[v],T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(f));let R=T?T[k]:0;(!R||!await(s.isElement==null?void 0:s.isElement(T)))&&(R=c.floating[k]||a.floating[x]);const L=C/2-N/2,D=R/2-b[x]/2-1,P=_s(p[_],D),B=_s(p[O],D),I=R-b[x]-B,U=R/2-b[x]/2+L,V=o3(P,U,I),G=!u.arrow&&zu(i)!=null&&U!==V&&a.reference[x]/2-(U<P?P:B)-b[x]/2<0,$=G?U<P?U-P:U-I:0;return{[v]:m[v]+$,data:{[v]:V,centerOffset:U-V-$,...G&&{alignmentOffset:$}},reset:G}}}),hre=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:i,middlewareData:a,rects:s,initialPlacement:c,platform:u,elements:f}=t,{mainAxis:h=!0,crossAxis:p=!0,fallbackPlacements:m,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:b=!0,...S}=fo(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=As(i),O=oa(c),k=As(c)===c,C=await(u.isRTL==null?void 0:u.isRTL(f.floating)),N=m||(k||!b?[fg(c)]:rre(c)),T=x!=="none";!m&&T&&N.push(...sre(c,b,x,C));const R=[c,...N],L=await u.detectOverflow(t,S),D=[];let P=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&D.push(L[_]),p){const V=nre(i,s,C);D.push(L[V[0]],L[V[1]])}if(P=[...P,{placement:i,overflows:D}],!D.every(V=>V<=0)){var B,I;const V=(((B=a.flip)==null?void 0:B.index)||0)+1,G=R[V];if(G&&(!(p==="alignment"?O!==oa(G):!1)||P.every(K=>oa(K.placement)===O?K.overflows[0]>0:!0)))return{data:{index:V,overflows:P},reset:{placement:G}};let $=(I=P.filter(q=>q.overflows[0]<=0).sort((q,K)=>q.overflows[1]-K.overflows[1])[0])==null?void 0:I.placement;if(!$)switch(v){case"bestFit":{var U;const q=(U=P.filter(K=>{if(T){const Z=oa(K.placement);return Z===O||Z==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(Z=>Z>0).reduce((Z,j)=>Z+j,0)]).sort((K,Z)=>K[1]-Z[1])[0])==null?void 0:U[0];q&&($=q);break}case"initialPlacement":$=c;break}if(i!==$)return{reset:{placement:$}}}return{}}}};function lM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function cM(e){return ere.some(t=>e[t]>=0)}const pre=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=fo(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),c=lM(s,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:cM(c)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),c=lM(s,n.floating);return{data:{escapedOffsets:c,escaped:cM(c)}}}default:return{}}}}},l3=new Set(["left","top"]);async function mre(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=As(n),c=zu(n),u=oa(n)==="y",f=l3.has(s)?-1:1,h=a&&u?-1:1,p=fo(t,e);let{mainAxis:m,crossAxis:v,alignmentAxis:x}=typeof p=="number"?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return c&&typeof x=="number"&&(v=c==="end"?x*-1:x),u?{x:v*h,y:m*f}:{x:m*f,y:v*h}}const gre=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:i,y:a,placement:s,middlewareData:c}=t,u=await mre(t,e);return s===((n=c.offset)==null?void 0:n.placement)&&(r=c.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},vre=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:i,platform:a}=t,{mainAxis:s=!0,crossAxis:c=!1,limiter:u={fn:O=>{let{x:k,y:C}=O;return{x:k,y:C}}},...f}=fo(e,t),h={x:n,y:r},p=await a.detectOverflow(t,f),m=oa(i),v=WE(m);let x=h[v],b=h[m];const S=(O,k)=>o3(k+p[O==="y"?"top":"left"],k,k-p[O==="y"?"bottom":"right"]);s&&(x=S(v,x)),c&&(b=S(m,b));const _=u.fn({...t,[v]:x,[m]:b});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[v]:s,[m]:c}}}}}},yre=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:c,middlewareData:u}=t,{offset:f=0,mainAxis:h=!0,crossAxis:p=!0}=fo(e,t),m={x:i,y:a},v=oa(s),x=WE(v);let b=m[x],S=m[v];const _=fo(f,t),O=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const N=x==="y"?"height":"width",T=c.reference[x]-c.floating[N]+O.mainAxis,R=c.reference[x]+c.reference[N]-O.mainAxis;b<T?b=T:b>R&&(b=R)}if(p){var k,C;const N=x==="y"?"width":"height",T=l3.has(As(s)),R=c.reference[v]-c.floating[N]+(T&&((k=u.offset)==null?void 0:k[v])||0)+(T?0:O.crossAxis),L=c.reference[v]+c.reference[N]+(T?0:((C=u.offset)==null?void 0:C[v])||0)-(T?O.crossAxis:0);S<R?S=R:S>L&&(S=L)}return{[x]:b,[v]:S}}}},bre=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:i,elements:a}=t,{apply:s=()=>{},...c}=fo(e,t),u=await i.detectOverflow(t,c),f=As(n),h=zu(n),p=oa(n)==="y",{width:m,height:v}=r.floating;let x,b;f==="top"||f==="bottom"?(x=f,b=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(b=f,x=h==="end"?"top":"bottom");const S=v-u.top-u.bottom,_=m-u.left-u.right,O=_s(v-u[x],S),k=_s(m-u[b],_),C=t.middlewareData.shift,N=!C;let T=O,R=k;C!=null&&C.enabled.x&&(R=_),C!=null&&C.enabled.y&&(T=S),N&&!h&&(p?R=m-2*io(u.left,u.right):T=v-2*io(u.top,u.bottom)),await s({...t,availableWidth:R,availableHeight:T});const L=await i.getDimensions(a.floating);return m!==L.width||v!==L.height?{reset:{rects:!0}}:{}}}};function Sv(){return typeof window<"u"}function $u(e){return c3(e)?(e.nodeName||"").toLowerCase():"#document"}function Rr(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function bo(e){var t;return(t=(c3(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function c3(e){return Sv()?e instanceof Node||e instanceof Rr(e).Node:!1}function pa(e){return Sv()?e instanceof Element||e instanceof Rr(e).Element:!1}function Ds(e){return Sv()?e instanceof HTMLElement||e instanceof Rr(e).HTMLElement:!1}function uM(e){return!Sv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rr(e).ShadowRoot}function _v(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ma(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function xre(e){return/^(table|td|th)$/.test($u(e))}function Av(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const wre=/transform|translate|scale|rotate|perspective|filter/,Ere=/paint|layout|strict|content/,ll=e=>!!e&&e!=="none";let fx;function ZE(e){const t=pa(e)?ma(e):e;return ll(t.transform)||ll(t.translate)||ll(t.scale)||ll(t.rotate)||ll(t.perspective)||!QE()&&(ll(t.backdropFilter)||ll(t.filter))||wre.test(t.willChange||"")||Ere.test(t.contain||"")}function Sre(e){let t=jl(e);for(;Ds(t)&&!Pd(t);){if(ZE(t))return t;if(Av(t))return null;t=jl(t)}return null}function QE(){return fx==null&&(fx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),fx}function Pd(e){return/^(html|body|#document)$/.test($u(e))}function ma(e){return Rr(e).getComputedStyle(e)}function kv(e){return pa(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function jl(e){if($u(e)==="html")return e;const t=e.assignedSlot||e.parentNode||uM(e)&&e.host||bo(e);return uM(t)?t.host:t}function u3(e){const t=jl(e);return Pd(t)?(e.ownerDocument||e).body:Ds(t)&&_v(t)?t:u3(t)}function Dd(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=u3(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Rr(i);if(a){const c=Lw(s);return t.concat(s,s.visualViewport||[],_v(i)?i:[],c&&n?Dd(c):[])}else return t.concat(i,Dd(i,[],n))}function Lw(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function f3(e){const t=ma(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ds(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,c=ug(n)!==a||ug(r)!==s;return c&&(n=a,r=s),{width:n,height:r,$:c}}function JE(e){return pa(e)?e:e.contextElement}function fu(e){const t=JE(e);if(!Ds(t))return ao(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=f3(t);let s=(a?ug(n.width):n.width)/r,c=(a?ug(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const _re=ao(0);function d3(e){const t=Rr(e);return!QE()||!t.visualViewport?_re:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Are(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Rr(e)}function Ll(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=JE(e);let s=ao(1);t&&(r?pa(r)&&(s=fu(r)):s=fu(e));const c=Are(a,n,r)?d3(a):ao(0);let u=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,h=i.width/s.x,p=i.height/s.y;if(a&&r){const m=Rr(a),v=pa(r)?Rr(r):r;let x=m,b=Lw(x);for(;b&&v!==x;){const S=fu(b),_=b.getBoundingClientRect(),O=ma(b),k=_.left+(b.clientLeft+parseFloat(O.paddingLeft))*S.x,C=_.top+(b.clientTop+parseFloat(O.paddingTop))*S.y;u*=S.x,f*=S.y,h*=S.x,p*=S.y,u+=k,f+=C,x=Rr(b),b=Lw(x)}}return dg({width:h,height:p,x:u,y:f})}function Ov(e,t){const n=kv(e).scrollLeft;return t?t.left+n:Ll(bo(e)).left+n}function h3(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ov(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function kre(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=bo(r),c=t?Av(t.floating):!1;if(r===s||c&&a)return n;let u={scrollLeft:0,scrollTop:0},f=ao(1);const h=ao(0),p=Ds(r);if((p||!a)&&(($u(r)!=="body"||_v(s))&&(u=kv(r)),p)){const v=Ll(r);f=fu(r),h.x=v.x+r.clientLeft,h.y=v.y+r.clientTop}const m=s&&!p&&!a?h3(s,u):ao(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-u.scrollLeft*f.x+h.x+m.x,y:n.y*f.y-u.scrollTop*f.y+h.y+m.y}}function Ore(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Cre(e){const t=kv(e),n=e.ownerDocument.body,r=io(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=io(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+Ov(e);const s=-t.scrollTop;return ma(n).direction==="rtl"&&(a+=io(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Tre=25;function Nre(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Rr(e),a=bo(e),s=i.visualViewport;let c=a.clientWidth,u=a.clientHeight,f=0,h=0;if(s){const m=!QE()||t==="fixed";r?m||(f=-s.offsetLeft,h=-s.offsetTop):(c=s.width,u=s.height,m&&(f=s.offsetLeft,h=s.offsetTop))}if(Ov(a)<=0){const m=a.ownerDocument,v=m.body,x=getComputedStyle(v),b=m.compatMode==="CSS1Compat"&&parseFloat(x.marginLeft)+parseFloat(x.marginRight)||0,S=Math.abs(a.clientWidth-v.clientWidth-b),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?S/2:S;_<=Tre&&(c-=_)}return{width:c,height:u,x:f,y:h}}function Mre(e,t){const n=Ll(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=fu(e),s=e.clientWidth*a.x,c=e.clientHeight*a.y,u=i*a.x,f=r*a.y;return{width:s,height:c,x:u,y:f}}function fM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Nre(e,n,t);else if(t==="document")r=Cre(bo(e));else if(pa(t))r=Mre(t,n);else{const i=d3(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return dg(r)}function Ire(e,t){const n=t.get(e);if(n)return n;let r=Dd(e,[],!1).filter(c=>pa(c)&&$u(c)!=="body"),i=null;const a=ma(e).position==="fixed";let s=a?jl(e):e;for(;pa(s)&&!Pd(s);){const c=ma(s),u=ZE(s),f=i?i.position:a?"fixed":"";!u&&(f==="fixed"||f==="absolute"&&c.position==="static")?r=r.filter(p=>p!==s):i=c,s=jl(s)}return t.set(e,r),r}function Rre(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?Av(t)?[]:Ire(t,this._c):[].concat(n),r],c=fM(t,s[0],i);let u=c.top,f=c.right,h=c.bottom,p=c.left;for(let m=1;m<s.length;m++){const v=fM(t,s[m],i);u=io(v.top,u),f=_s(v.right,f),h=_s(v.bottom,h),p=io(v.left,p)}return{width:f-p,height:h-u,x:p,y:u}}function Pre(e){const{width:t,height:n}=f3(e);return{width:t,height:n}}function Dre(e,t,n){const r=Ds(t),i=bo(t),a=n==="fixed",s=Ll(e,!0,a,t);let c={scrollLeft:0,scrollTop:0};const u=ao(0);if((r||!a)&&(($u(t)!=="body"||_v(i))&&(c=kv(t)),r)){const m=Ll(t,!0,a,t);u.x=m.x+t.clientLeft,u.y=m.y+t.clientTop}!r&&i&&(u.x=Ov(i));const f=i&&!r&&!a?h3(i,c):ao(0),h=s.left+c.scrollLeft-u.x-f.x,p=s.top+c.scrollTop-u.y-f.y;return{x:h,y:p,width:s.width,height:s.height}}function dx(e){return ma(e).position==="static"}function dM(e,t){if(!Ds(e)||ma(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return bo(e)===n&&(n=n.ownerDocument.body),n}function p3(e,t){const n=Rr(e);if(Av(e))return n;if(!Ds(e)){let i=jl(e);for(;i&&!Pd(i);){if(pa(i)&&!dx(i))return i;i=jl(i)}return n}let r=dM(e,t);for(;r&&xre(r)&&dx(r);)r=dM(r,t);return r&&Pd(r)&&dx(r)&&!ZE(r)?n:r||Sre(e)||n}const jre=async function(e){const t=this.getOffsetParent||p3,n=this.getDimensions,r=await n(e.floating);return{reference:Dre(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Lre(e){return ma(e).direction==="rtl"}const zre={convertOffsetParentRelativeRectToViewportRelativeRect:kre,getDocumentElement:bo,getClippingRect:Rre,getOffsetParent:p3,getElementRects:jre,getClientRects:Ore,getDimensions:Pre,getScale:fu,isElement:pa,isRTL:Lre};function m3(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $re(e,t,n){let r=null,i;const a=bo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function c(h,p){h===void 0&&(h=!1),p===void 0&&(p=1),s();const m=e.getBoundingClientRect(),{left:v,top:x,width:b,height:S}=m;if(h||t(),!b||!S)return;const _=fm(x),O=fm(a.clientWidth-(v+b)),k=fm(a.clientHeight-(x+S)),C=fm(v),T={rootMargin:-_+"px "+-O+"px "+-k+"px "+-C+"px",threshold:io(0,_s(1,p))||1};let R=!0;function L(D){const P=D[0].intersectionRatio;if(!m3(m,e.getBoundingClientRect()))return c();if(P!==p){if(!R)return c();P?c(!1,P):i=setTimeout(()=>{c(!1,1e-7)},1e3)}R=!1}try{r=new IntersectionObserver(L,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(L,T)}r.observe(e)}const u=Rr(e),f=()=>c(n);return u.addEventListener("resize",f),c(!0),()=>{u.removeEventListener("resize",f),s()}}function Bre(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,f=JE(e),h=i||a?[...f?Dd(f):[],...t?Dd(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const p=f&&c?$re(f,n,a):null;let m=-1,v=null;s&&(v=new ResizeObserver(_=>{let[O]=_;O&&O.target===f&&v&&t&&(v.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var k;(k=v)==null||k.observe(t)})),n()}),f&&!u&&v.observe(f),t&&v.observe(t));let x,b=u?Ll(e):null;u&&S();function S(){const _=Ll(e);b&&!m3(b,_)&&n(),b=_,x=requestAnimationFrame(S)}return n(),()=>{var _;h.forEach(O=>{i&&O.removeEventListener("scroll",n),a&&O.removeEventListener("resize",n)}),p==null||p(),(_=v)==null||_.disconnect(),v=null,u&&cancelAnimationFrame(x)}}const Ure=gre,Fre=vre,Hre=hre,Kre=bre,qre=pre,hM=dre,Gre=yre,Vre=(e,t,n)=>{const r=new Map,i=n??{},a={...zre,...i.platform,_c:r};return fre(e,t,{...i,platform:a})};var Wre=typeof document<"u",Yre=function(){},zm=Wre?y.useLayoutEffect:Yre;function hg(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!hg(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!hg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function g3(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function pM(e,t){const n=g3(e);return Math.round(t*n)/n}function hx(e){const t=y.useRef(e);return zm(()=>{t.current=e}),t}function Xre(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:c=!0,whileElementsMounted:u,open:f}=e,[h,p]=y.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,v]=y.useState(r);hg(m,r)||v(r);const[x,b]=y.useState(null),[S,_]=y.useState(null),O=y.useCallback(K=>{K!==T.current&&(T.current=K,b(K))},[]),k=y.useCallback(K=>{K!==R.current&&(R.current=K,_(K))},[]),C=a||x,N=s||S,T=y.useRef(null),R=y.useRef(null),L=y.useRef(h),D=u!=null,P=hx(u),B=hx(i),I=hx(f),U=y.useCallback(()=>{if(!T.current||!R.current)return;const K={placement:t,strategy:n,middleware:m};B.current&&(K.platform=B.current),Vre(T.current,R.current,K).then(Z=>{const j={...Z,isPositioned:I.current!==!1};V.current&&!hg(L.current,j)&&(L.current=j,Ea.flushSync(()=>{p(j)}))})},[m,t,n,B,I]);zm(()=>{f===!1&&L.current.isPositioned&&(L.current.isPositioned=!1,p(K=>({...K,isPositioned:!1})))},[f]);const V=y.useRef(!1);zm(()=>(V.current=!0,()=>{V.current=!1}),[]),zm(()=>{if(C&&(T.current=C),N&&(R.current=N),C&&N){if(P.current)return P.current(C,N,U);U()}},[C,N,U,P,D]);const G=y.useMemo(()=>({reference:T,floating:R,setReference:O,setFloating:k}),[O,k]),$=y.useMemo(()=>({reference:C,floating:N}),[C,N]),q=y.useMemo(()=>{const K={position:n,left:0,top:0};if(!$.floating)return K;const Z=pM($.floating,h.x),j=pM($.floating,h.y);return c?{...K,transform:"translate("+Z+"px, "+j+"px)",...g3($.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Z,top:j}},[n,c,$.floating,h.x,h.y]);return y.useMemo(()=>({...h,update:U,refs:G,elements:$,floatingStyles:q}),[h,U,G,$,q])}const Zre=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:i}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?hM({element:r.current,padding:i}).fn(n):{}:r?hM({element:r,padding:i}).fn(n):{}}}},Qre=(e,t)=>{const n=Ure(e);return{name:n.name,fn:n.fn,options:[e,t]}},Jre=(e,t)=>{const n=Fre(e);return{name:n.name,fn:n.fn,options:[e,t]}},eie=(e,t)=>({fn:Gre(e).fn,options:[e,t]}),tie=(e,t)=>{const n=Hre(e);return{name:n.name,fn:n.fn,options:[e,t]}},nie=(e,t)=>{const n=Kre(e);return{name:n.name,fn:n.fn,options:[e,t]}},rie=(e,t)=>{const n=qre(e);return{name:n.name,fn:n.fn,options:[e,t]}},iie=(e,t)=>{const n=Zre(e);return{name:n.name,fn:n.fn,options:[e,t]}};var aie=Object.defineProperty,eS=(e,t)=>aie(e,"name",{value:t,configurable:!0});function zw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}eS(zw,"setRef");function v3(...e){return t=>{let n=!1;const r=e.map(i=>{const a=zw(i,t);return!n&&typeof a=="function"&&(n=!0),a});if(n)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():zw(e[i],null)}}}}eS(v3,"composeRefs");function Cv(...e){return y.useCallback(v3(...e),e)}eS(Cv,"useComposedRefs");var oie=Object.defineProperty,xi=(e,t)=>oie(e,"name",{value:t,configurable:!0});function sie(e,t){const n=y.createContext(t);n.displayName=e+"Context";const r=xi(a=>{const{children:s,...c}=a,u=y.useMemo(()=>c,Object.values(c));return E.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:c=!1}=s,u=y.useContext(n);if(u)return u;if(t!==void 0)return t;if(!c)throw new Error(`\`${a}\` must be used within \`${e}\``)}return xi(i,"useContext"),[r,i]}xi(sie,"createContext");function y3(e,t=[]){let n=[];function r(a,s){const c=y.createContext(s);c.displayName=a+"Context";const u=n.length;n=[...n,s];const f=xi(p=>{var _;const{scope:m,children:v,...x}=p,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useMemo(()=>x,Object.values(x));return E.jsx(b.Provider,{value:S,children:v})},"Provider");f.displayName=a+"Provider";function h(p,m,v={}){var _;const{optional:x=!1}=v,b=((_=m==null?void 0:m[e])==null?void 0:_[u])||c,S=y.useContext(b);if(S)return S;if(s!==void 0)return s;if(!x)throw new Error(`\`${p}\` must be used within \`${a}\``)}return xi(h,"useContext"),[f,h]}xi(r,"createContext");const i=xi(()=>{const a=n.map(s=>y.createContext(s));return xi(function(c){const u=(c==null?void 0:c[e])||a;return y.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])},"useScope")},"createScope");return i.scopeName=e,[r,b3(i,...t)]}xi(y3,"createContextScope");function b3(...e){const t=e[0];if(e.length===1)return t;const n=xi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return xi(function(a){const s=r.reduce((c,{useScope:u,scopeName:f})=>{const p=u(a)[`__scope${f}`];return{...c,...p}},{});return y.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}xi(b3,"composeContextScopes");var lie=Object.defineProperty,Ui=(e,t)=>lie(e,"name",{value:t,configurable:!0});function x3(e){const t=y.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,c=!1;const u=[];$w(i)&&typeof dm=="function"&&(i=dm(i._payload)),y.Children.forEach(i,m=>{var v;if(_3(m)){c=!0;const x=m;let b="child"in x.props?x.props.child:x.props.children;$w(b)&&typeof dm=="function"&&(b=dm(b._payload)),s=uie(x,b),u.push((v=s==null?void 0:s.props)==null?void 0:v.children)}else u.push(m)}),s?s=y.cloneElement(s,void 0,u):!c&&y.Children.count(i)===1&&y.isValidElement(i)&&(s=i);const f=s?S3(s):void 0,h=Cv(r,f);if(!s){if(i||i===0)throw new Error(c?hie(e):die(e));return i}const p=E3(a,s.props??{});return s.type!==y.Fragment&&(p.ref=r?h:f),y.cloneElement(s,p)});return t.displayName=`${e}.Slot`,t}Ui(x3,"createSlot");var w3=Symbol.for("radix.slottable");function cie(e){const t=Ui(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=w3,t}Ui(cie,"createSlottable");var uie=Ui((e,t)=>{if("child"in e.props){const n=e.props.child;return y.isValidElement(n)?y.cloneElement(n,void 0,e.props.children(n.props.children)):null}return y.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function E3(e,t){const n={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...c)=>{const u=a(...c);return i(...c),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}Ui(E3,"mergeProps");function S3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Ui(S3,"getElementRef");function _3(e){return y.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===w3}Ui(_3,"isSlottable");var fie=Symbol.for("react.lazy");function $w(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===fie&&"_payload"in e&&A3(e._payload)}Ui($w,"isLazyComponent");function A3(e){return typeof e=="object"&&e!==null&&"then"in e}Ui(A3,"isPromiseLike");var die=Ui(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),hie=Ui(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),dm=wa[" use ".trim().toString()],pie=Object.defineProperty,mie=(e,t)=>pie(e,"name",{value:t,configurable:!0}),gie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],k3=gie.reduce((e,t)=>{const n=x3(`Primitive.${t}`),r=y.forwardRef((i,a)=>{const{asChild:s,...c}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),E.jsx(u,{...c,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function vie(e,t){e&&Ea.flushSync(()=>e.dispatchEvent(t))}mie(vie,"dispatchDiscreteCustomEvent");var yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0});function O3(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}bie(O3,"useCallbackRef");var px=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},xie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},wie=Object.defineProperty,Eie=(e,t)=>wie(e,"name",{value:t,configurable:!0});function C3(e){const[t,n]=y.useState(void 0);return xie(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let s,c;if("borderBoxSize"in a){const u=a.borderBoxSize,f=Array.isArray(u)?u[0]:u;s=f.inlineSize,c=f.blockSize}else s=e.offsetWidth,c=e.offsetHeight;n({width:s,height:c})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Eie(C3,"useSize");var Sie=Object.defineProperty,bs=(e,t)=>Sie(e,"name",{value:t,configurable:!0}),T3="Popper",[N3,M3]=y3(T3),[_ie,I3]=N3(T3),Aie=bs(e=>{const{__scopePopper:t,children:n}=e,[r,i]=y.useState(null),[a,s]=y.useState(void 0);return E.jsx(_ie,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),kie="PopperAnchor",Oie=y.forwardRef(bs(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=I3(kie,r),c=y.useRef(null),u=s.onAnchorChange,f=y.useCallback(b=>{c.current=b,b&&u(b)},[u]),h=Cv(n,f),p=y.useRef(null);y.useEffect(()=>{if(!i)return;const b=p.current;p.current=i.current,b!==p.current&&u(p.current)});const m=s.placementState&&Tv(s.placementState),v=m==null?void 0:m[0],x=m==null?void 0:m[1];return i?null:E.jsx(k3.div,{"data-radix-popper-side":v,"data-radix-popper-align":x,...a,ref:h})},"PopperAnchor")),R3="PopperContent",[Cie,nOe]=N3(R3),Tie=y.forwardRef(bs(function(t,n){var fe,ke,we,ue,ht,qe,_e;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:c=0,arrowPadding:u=0,avoidCollisions:f=!0,collisionBoundary:h=[],collisionPadding:p=0,sticky:m="partial",hideWhenDetached:v=!1,updatePositionStrategy:x="optimized",onPlaced:b,...S}=t,_=I3(R3,r),[O,k]=y.useState(null),C=Cv(n,k),[N,T]=y.useState(null),R=C3(N),L=(R==null?void 0:R.width)??0,D=(R==null?void 0:R.height)??0,P=i+(s!=="center"?"-"+s:""),B=typeof p=="number"?p:{top:0,right:0,bottom:0,left:0,...p},I=Array.isArray(h)?h:[h],U=I.length>0,V={padding:B,boundary:I.filter(P3),altBoundary:U},{refs:G,floatingStyles:$,placement:q,isPositioned:K,middlewareData:Z}=Xre({strategy:"fixed",placement:P,whileElementsMounted:bs((...De)=>Bre(...De,{animationFrame:x==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[Qre({mainAxis:a+D,alignmentAxis:c}),f&&Jre({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?eie():void 0,...V}),f&&tie({...V}),nie({...V,apply:bs(({elements:De,rects:Kt,availableWidth:kn,availableHeight:zn})=>{const{width:ur,height:Oi}=Kt.reference,ti=De.floating.style;ti.setProperty("--radix-popper-available-width",`${kn}px`),ti.setProperty("--radix-popper-available-height",`${zn}px`),ti.setProperty("--radix-popper-anchor-width",`${ur}px`),ti.setProperty("--radix-popper-anchor-height",`${Oi}px`)},"apply")}),N&&iie({element:N,padding:u}),Nie({arrowWidth:L,arrowHeight:D}),v&&rie({strategy:"referenceHidden",...V,boundary:U?V.boundary:void 0})]}),j=_.setPlacementState;px(()=>(j(q),()=>{j(void 0)}),[q,j]);const[H,ee]=Tv(q),F=O3(b);px(()=>{K&&(F==null||F())},[K,F]);const de=(fe=Z.arrow)==null?void 0:fe.x,be=(ke=Z.arrow)==null?void 0:ke.y,ge=((we=Z.arrow)==null?void 0:we.centerOffset)!==0,[Ie,We]=y.useState();return px(()=>{O&&We(window.getComputedStyle(O).zIndex)},[O]),E.jsx("div",{ref:G.setFloating,"data-radix-popper-content-wrapper":"",style:{...$,transform:K?$.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ie,"--radix-popper-transform-origin":[(ue=Z.transformOrigin)==null?void 0:ue.x,(ht=Z.transformOrigin)==null?void 0:ht.y].join(" "),...((qe=Z.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:E.jsx(Cie,{scope:r,placedSide:H,placedAlign:ee,onArrowChange:T,arrowX:de,arrowY:be,shouldHideArrow:ge,children:E.jsx(k3.div,{"data-side":H,"data-align":ee,...S,ref:C,style:{...S.style,animation:K?(_e=S.style)==null?void 0:_e.animation:"none"}})})})},"PopperContent"));function P3(e){return e!==null}bs(P3,"isNotNull");var Nie=bs(e=>({name:"transformOrigin",options:e,fn(t){var S,_,O;const{placement:n,rects:r,middlewareData:i}=t,s=((S=i.arrow)==null?void 0:S.centerOffset)!==0,c=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[f,h]=Tv(n),p={start:"0%",center:"50%",end:"100%"}[h],m=(((_=i.arrow)==null?void 0:_.x)??0)+c/2,v=(((O=i.arrow)==null?void 0:O.y)??0)+u/2;let x="",b="";return f==="bottom"?(x=s?p:`${m}px`,b=`${-u}px`):f==="top"?(x=s?p:`${m}px`,b=`${r.floating.height+u}px`):f==="right"?(x=`${-u}px`,b=s?p:`${v}px`):f==="left"&&(x=`${r.floating.width+u}px`,b=s?p:`${v}px`),{data:{x,y:b}}}}),"transformOrigin");function Tv(e){const[t,n="center"]=e.split("-");return[t,n]}bs(Tv,"getSideAndAlignFromPlacement");var Mie=Aie,Iie=Oie,Rie=Tie,Pie=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},Die=Object.defineProperty,jie=(e,t)=>Die(e,"name",{value:t,configurable:!0}),Lie=y.forwardRef(jie(function(t,n){var u;const{container:r,...i}=t,[a,s]=y.useState(!1);Pie(()=>s(!0),[]);const c=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return c?Ea.createPortal(E.jsx(wv.div,{...i,ref:n}),c):null},"Portal")),mM=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},zie=Object.defineProperty,ho=(e,t)=>zie(e,"name",{value:t,configurable:!0});function D3(e,t){return y.useReducer((n,r)=>t[n][r]??n,e)}ho(D3,"useStateMachine");var j3=ho(e=>{const{present:t,children:n}=e,r=L3(t),i=typeof n=="function"?n({present:r.isPresent}):y.Children.only(n),a=z3(r.ref,$3(i));return typeof n=="function"||r.isPresent?y.cloneElement(i,{ref:a}):null},"Presence");function L3(e){const[t,n]=y.useState(),r=y.useRef(null),i=y.useRef(e),a=y.useRef("none"),s=y.useRef(void 0),c=e?"mounted":"unmounted",[u,f]=D3(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return y.useEffect(()=>{u==="mounted"?(a.current=s.current??eu(r.current),s.current=void 0):a.current="none"},[u]),mM(()=>{const h=r.current,p=i.current;if(p!==e){const v=a.current,x=eu(h);e?(s.current=x,f("MOUNT")):x==="none"||(h==null?void 0:h.display)==="none"?f("UNMOUNT"):f(p&&v!==x?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,f]),mM(()=>{if(t){let h;const p=t.ownerDocument.defaultView??window,m=ho(x=>{const S=eu(r.current).includes(CSS.escape(x.animationName));if(x.target===t&&S&&(f("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=p.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),v=ho(x=>{x.target===t&&(a.current=eu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",v),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{p.clearTimeout(h),t.removeEventListener("animationstart",v),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:y.useCallback(h=>{if(h){const p=getComputedStyle(h);r.current=p,s.current=eu(p)}else r.current=null;n(h)},[])}}ho(L3,"usePresence");function Bw(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}ho(Bw,"setRef");function z3(...e){const t=y.useRef(e);return t.current=e,y.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const c=Bw(s,n);return!i&&typeof c=="function"&&(i=!0),c});if(i)return()=>{for(let s=0;s<a.length;s++){const c=a[s];typeof c=="function"?c():Bw(r[s],null)}}},[])}ho(z3,"useStableComposedRefs");function eu(e){return(e==null?void 0:e.animationName)||"none"}ho(eu,"getAnimationName");function $3(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}ho($3,"getElementRef");var B3=globalThis!=null&&globalThis.document?y.useLayoutEffect:()=>{},$ie=Object.defineProperty,Bie=(e,t)=>$ie(e,"name",{value:t,configurable:!0}),gM=wa[" useEffectEvent ".trim().toString()],vM=wa[" useInsertionEffect ".trim().toString()];function U3(e){if(typeof gM=="function")return gM(e);const t=y.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof vM=="function"?vM(()=>{t.current=e}):B3(()=>{t.current=e}),y.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Bie(U3,"useEffectEvent");var Uie=Object.defineProperty,sh=(e,t)=>Uie(e,"name",{value:t,configurable:!0}),Fie=wa[" useInsertionEffect ".trim().toString()]||B3;function F3({prop:e,defaultProp:t,onChange:n=sh(()=>{},"onChange"),caller:r}){const[i,a,s]=H3({defaultProp:t,onChange:n}),c=e!==void 0,u=c?e:i,f=y.useCallback(h=>{var p;if(c){const m=K3(h)?h(e):h;m!==e&&((p=s.current)==null||p.call(s,m))}else a(h)},[c,e,a,s]);return[u,f]}sh(F3,"useControllableState");function H3({defaultProp:e,onChange:t}){const[n,r]=y.useState(e),i=y.useRef(n),a=y.useRef(t);return Fie(()=>{a.current=t},[t]),y.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}sh(H3,"useUncontrolledState");function K3(e){return typeof e=="function"}sh(K3,"isFunction");var yM=Symbol("RADIX:SYNC_STATE");function Hie(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:c}=t,u=i!==void 0,f=U3(s),h=[{...n,state:a}];r&&h.push(r);const[p,m]=y.useReducer((S,_)=>{if(_.type===yM)return{...S,state:_.state};const O=e(S,_);return u&&!Object.is(O.state,S.state)&&f(O.state),O},...h),v=p.state,x=y.useRef(v);y.useEffect(()=>{x.current!==v&&(x.current=v,u||f(v))},[v,x,u]);const b=y.useMemo(()=>i!==void 0?{...p,state:i}:p,[p,i]);return y.useEffect(()=>{u&&!Object.is(i,p.state)&&m({type:yM,state:i})},[i,p.state,u]),[b,m]}sh(Hie,"useControllableStateReducer");var Kie=Object.defineProperty,js=(e,t)=>Kie(e,"name",{value:t,configurable:!0}),tS="Popover",[q3,rOe]=Fz(tS,[M3]),nS=M3(),[qie,Bu]=q3(tS),Gie=js(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,c=nS(t),u=y.useRef(null),[f,h]=y.useState(!1),[p,m]=F3({prop:r,defaultProp:i??!1,onChange:a,caller:tS});return E.jsx(Mie,{...c,children:E.jsx(qie,{scope:t,contentId:a3(),triggerRef:u,open:p,onOpenChange:m,onOpenToggle:y.useCallback(()=>m(v=>!v),[m]),hasCustomAnchor:f,onCustomAnchorAdd:y.useCallback(()=>h(!0),[]),onCustomAnchorRemove:y.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),Vie="PopoverTrigger",Wie=y.forwardRef(js(function(t,n){const{__scopePopover:r,...i}=t,a=Bu(Vie,r),s=nS(r),c=Lu(n,a.triggerRef),u=E.jsx(wv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":rS(a.open),...i,ref:c,onClick:ys(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:E.jsx(Iie,{asChild:!0,...s,children:u})},"PopoverTrigger")),G3="PopoverPortal",[Yie,Xie]=q3(G3,{forceMount:void 0}),Zie=js(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Bu(G3,t);return E.jsx(Yie,{scope:t,forceMount:n,children:E.jsx(j3,{present:n||a.open,children:E.jsx(Lie,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),jd="PopoverContent",Qie=y.forwardRef(js(function(t,n){const r=Xie(jd,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=Bu(jd,t.__scopePopover);return E.jsx(j3,{present:i||s.open,children:s.modal?E.jsx(eae,{...a,ref:n}):E.jsx(tae,{...a,ref:n})})},"PopoverContent")),Jie=HE("PopoverContent.RemoveScroll"),eae=y.forwardRef(js(function(t,n){const r=Bu(jd,t.__scopePopover),i=y.useRef(null),a=Lu(n,i),s=y.useRef(!1);return y.useEffect(()=>{const c=i.current;if(c)return Sz(c)},[]),E.jsx(jE,{as:Jie,allowPinchZoom:!0,children:E.jsx(V3,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ys(t.onCloseAutoFocus,c=>{var u;c.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:ys(t.onPointerDownOutside,c=>{const u=c.detail.originalEvent,f=u.button===0&&u.ctrlKey===!0,h=u.button===2||f;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:ys(t.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),tae=y.forwardRef(js(function(t,n){const r=Bu(jd,t.__scopePopover),i=y.useRef(!1),a=y.useRef(!1);return E.jsx(V3,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var c,u;(c=t.onCloseAutoFocus)==null||c.call(t,s),s.defaultPrevented||(i.current||(u=r.triggerRef.current)==null||u.focus(),s.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:s=>{var f,h;(f=t.onInteractOutside)==null||f.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const c=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),V3=y.forwardRef(js(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:c,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:h,onInteractOutside:p,...m}=t,v=Bu(jd,r),x=nS(r);return GE(),E.jsx(Wne,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:E.jsx(Bne,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:p,onEscapeKeyDown:u,onPointerDownOutside:f,onFocusOutside:h,onDismiss:()=>v.onOpenChange(!1),deferPointerDownOutside:!0,children:E.jsx(Rie,{"data-state":rS(v.open),role:"dialog",id:v.contentId,...x,...m,ref:n,style:{...m.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})},"PopoverContentImpl"));function rS(e){return e?"open":"closed"}js(rS,"getState");var nae=Gie,rae=Wie,iae=Zie,W3=Qie;const aae=nae,oae=rae,Y3=y.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>E.jsx(iae,{children:E.jsx(W3,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:He("z-50 w-64 max-w-[calc(100vw-1rem)] rounded-md border bg-card p-3 text-card-foreground shadow-md outline-none","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...a})}));Y3.displayName=W3.displayName;const bM=3e5;function sae({socket:e,getToken:t}){const[n,r]=y.useState([]);if(y.useEffect(()=>{t().then(a=>a?fetch("/api/stats",{headers:{Authorization:`Bearer ${a}`}}):null).then(a=>a==null?void 0:a.json()).then(a=>(a==null?void 0:a.samples)&&r(a.samples)).catch(a=>console.warn("[MachineStats] seed failed",a))},[t]),y.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(c=>[...c,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return E.jsxs("div",{className:"w-full flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[10px] text-muted-foreground/60",children:[E.jsx(Hw,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),E.jsx(Hw,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),E.jsx(lae,{getToken:t})]})}function lae({getToken:e}){const[t,n]=y.useState(null);return y.useEffect(()=>{let r=!0,i=0;const a=async()=>{var f;try{const h=await e();if(!h)return;i=Date.now();const p=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(p.status===204){n(null);return}if(p.status!==200)return;const m=await p.json();if(!r||!((f=m==null?void 0:m.limits)!=null&&f.length))return;n(m)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},c=()=>{document.visibilityState==="visible"&&Date.now()-i>=bM&&a()};s();const u=setInterval(s,bM);return document.addEventListener("visibilitychange",c),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",c)}},[e]),E.jsx(cae,{usage:t})}function cae({usage:e}){const t=e&&X3(e.limits),[n,r]=y.useState(Uw),i=y.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=y.useCallback((c,u=0)=>{if(a(),!u){r(f=>wM(f,c));return}i.current=setTimeout(()=>{i.current=null,r(f=>wM(f,c))},u)},[]);return y.useEffect(()=>a,[]),!e||!t?null:E.jsxs(aae,{open:n.open,onOpenChange:c=>s(c?{type:"activate"}:{type:"dismiss"}),children:[E.jsx(oae,{asChild:!0,children:E.jsx("button",{type:"button","aria-label":"claude usage breakdown",className:"cursor-default rounded-sm outline-none focus-visible:ring-1 focus-visible:ring-ring",onPointerEnter:c=>s({type:"pointerenter",pointerType:c.pointerType},uae),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},xM),children:E.jsx(Hw,{label:"usage",value:t.percent,severity:t.severity})})}),E.jsx(Y3,{onOpenAutoFocus:c=>c.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:c=>s({type:"pointerleave",pointerType:c.pointerType},xM),children:E.jsx(fae,{usage:e})})]})}const uae=120,xM=80,Uw={open:!1,byHover:!1};function wM(e,t){switch(t.type){case"pointerenter":return EM(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return EM(t.pointerType)&&e.byHover?Uw:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return Uw}}const EM=e=>e==="mouse"||e==="";function fae({usage:e}){const t=X3(e.limits);return E.jsxs("div",{className:"text-[11px] leading-tight",children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[E.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&E.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),E.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&E.jsx("span",{className:"truncate",title:e.account,children:e.account}),E.jsx("span",{className:"shrink-0",children:hae(e)})]}),E.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=mae(n.resetsAt),a=n===t;return E.jsxs("div",{"data-headline":a||void 0,className:He("flex flex-col gap-1",!a&&"opacity-60"),children:[E.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[E.jsxs("span",{className:He("truncate",a&&"font-medium"),children:[a&&E.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),dae(n)]}),E.jsxs("span",{className:He("tabular-nums shrink-0",Fw(n.percent,n.severity)),children:[n.percent,"%"]})]}),E.jsx(Z3,{value:n.percent,className:He("w-full",Fw(n.percent,n.severity))}),E.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),E.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function dae(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function X3(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function hae(e){const t=pae(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function pae(e){if(!e)return null;const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t))return null;const n=Math.round(Math.max(0,t)/6e4);if(n<1)return null;if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;return r<24?i?`${r}h ${i}m`:`${r}h`:`${Math.floor(r/24)}d`}function mae(e){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t)||t<=0)return null;const n=Math.round(t/6e4);if(n<1)return"1m";if(n<60)return`${n}m`;const r=Math.floor(n/60),i=n%60;if(r<48)return i?`${r}h ${i}m`:`${r}h`;const a=Math.floor(r/24),s=r%24;return s?`${a}d ${s}h`:`${a}d`}const gae={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500"};function Fw(e,t){const n=t?gae[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function Hw({label:e,value:t,series:n,title:r,severity:i}){const a=Fw(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return E.jsxs("span",{className:"flex items-center gap-1",title:s,children:[E.jsx("span",{className:"uppercase tracking-wide",children:e}),n?E.jsx(vae,{series:n,className:a}):E.jsx(Z3,{value:t,className:a}),E.jsxs("span",{className:He("tabular-nums",a),children:[t,"%"]})]})}function Z3({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return E.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:He("overflow-visible",t),preserveAspectRatio:"none",children:[E.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&E.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function vae({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,c)=>{const u=i>1?c/(i-1)*40:0,f=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${f.toFixed(1)}`}).join(" ");return E.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:He("overflow-visible",t),preserveAspectRatio:"none",children:E.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}function yae(e,t,n){var r;return!!(e.uid===t||(r=e.visibleTo)!=null&&r.includes(n.toLowerCase()))}function bae(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}const rd="w-4 h-4 mt-0.5 shrink-0";function xae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?E.jsx(Hq,{className:`${rd} text-purple-400`}):(t==null?void 0:t.type)==="mention"?E.jsx(Mq,{className:`${rd} text-blue-400`}):(t==null?void 0:t.type)==="channel"?E.jsx(zq,{className:`${rd} text-green-400`}):e.sessionId.startsWith("slack-")?E.jsx(dw,{className:`${rd} text-yellow-400`}):E.jsx(dw,{className:`${rd} text-muted-foreground`})}function wae(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?`DM${t.userName?` · ${t.userName}`:""}`:(t==null?void 0:t.type)==="mention"?`@mention${t.channelName?` · #${t.channelName}`:""}`:(t==null?void 0:t.type)==="channel"?`#${t.channelName||"channel"}`:e.sessionId.startsWith("slack-")?"Slack":null}const SM="chats-filter",_M="chats-unread-filter";function Eae({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,userUid:c,userEmail:u,unreads:f={},busySessions:h=new Set,socket:p}){var I;const m=Sa(),[v,x]=y.useState([]),[b,S]=y.useState(()=>localStorage.getItem(SM)||"mine"),[_,O]=y.useState(()=>localStorage.getItem(_M)==="true"),[k,C]=y.useState(""),N=y.useRef(null),T=y.useRef(null);function R(U){S(U),localStorage.setItem(SM,U)}function L(){const U=!_;O(U),localStorage.setItem(_M,String(U))}const D=y.useMemo(()=>v.filter(U=>b==="all"||yae(U,c,u)),[v,b,c,u]),P=y.useMemo(()=>D.filter(U=>f[U.sessionId]).length,[D,f]),B=y.useMemo(()=>_?D.filter(U=>f[U.sessionId]):D,[D,_,f]);return y.useEffect(()=>{e().then(U=>U?fetch("/api/version",{headers:{Authorization:`Bearer ${U}`}}):null).then(U=>U==null?void 0:U.json()).then(U=>U&&C(U.version)).catch(()=>{})},[]),y.useEffect(()=>{var V;(V=N.current)==null||V.abort();const U=new AbortController;return N.current=U,e().then(G=>{!G||U.signal.aborted||fetch("/api/sessions",{signal:U.signal,headers:{Authorization:`Bearer ${G}`}}).then($=>$.ok?$.json():[]).then($=>{Array.isArray($)&&x($)}).catch(()=>{})}),()=>U.abort()},[e,i]),y.useEffect(()=>{T.current&&T.current.scrollIntoView({block:"nearest"})},[t]),E.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[E.jsx("div",{className:"p-3",children:E.jsxs(Re,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[E.jsx(fv,{className:"w-4 h-4"})," New Chat",E.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),E.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:E.jsx(bne,{getToken:e,onRefresh:s,refreshKey:a})}),E.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[E.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),E.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(U=>E.jsx("button",{onClick:()=>R(U),className:He("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",b===U?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:U},U)),E.jsxs("button",{onClick:L,className:He("text-[10px] px-1.5 rounded-full transition-colors leading-none",_?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",P>0&&E.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),E.jsx(Pj,{className:"flex-1",children:E.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[B.length===0&&E.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:_?"No unread conversations":v.length===0?"No conversations yet":"No conversations match this filter"}),B.map(U=>{const V=f[U.sessionId],G=h.has(U.sessionId)||U.runStatus==="running"||U.scheduleRunStatus==="running",$=!G&&(!!U.lastStopReason||U.scheduleRunStatus==="error"||U.scheduleRunStatus==="aborted"),q=G?"border-amber-500":$?"border-red-500":V?"border-blue-500":"",K=!!(G||$||V);return E.jsx("button",{ref:U.sessionId===t?T:void 0,onClick:()=>n(U.sessionId,U.title),className:He("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",K?`rounded-r-lg border-l-[3px] ${q}`:"rounded-lg",t===U.sessionId&&"bg-accent"),children:E.jsxs("div",{className:"flex items-start gap-2",children:[xae(U),E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsx("span",{className:He("block truncate text-sm leading-snug",V&&"font-semibold"),children:U.title||"New session"}),E.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[E.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:wae(U)||U.userName}),E.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),E.jsx("span",{className:"text-[10px] text-muted-foreground",children:bae(U.lastModified)})]})]})]})},U.sessionId)})]})}),E.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[E.jsx(sae,{socket:p??null,getToken:e}),(I=m.sidebarExtras)==null?void 0:I.call(m),k&&E.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",k]})]})]})}function gi(e,t){const n=e[e.length-1];if((n==null?void 0:n.role)==="assistant"){if(t.type==="text"||t.type==="thinking"){const r=[...n.blocks],i=r[r.length-1];return(i==null?void 0:i.type)===t.type?(r[r.length-1]={...i,text:i.text+t.text},[...e.slice(0,-1),{...n,blocks:r}]):[...e.slice(0,-1),{...n,blocks:[...r,t]}]}return[...e.slice(0,-1),{...n,blocks:[...n.blocks,t]}]}return[...e,{id:ms(),role:"assistant",blocks:[t]}]}function AM(e,t,n="text"){const r=e[e.length-1],i={type:n,text:t};return(r==null?void 0:r.role)==="assistant"?[...e.slice(0,-1),{...r,blocks:[...r.blocks,i]}]:[...e,{id:ms(),role:"assistant",blocks:[i]}]}function Q3(e,t,n){for(let r=e.length-1;r>=0;r--){const i=e[r];if(i.role!=="assistant")continue;const a=i.blocks.findIndex(c=>c.type==="tool_use"&&c.toolUseId===t);if(a===-1)continue;const s=[...i.blocks];return s[a]={...s[a],input:n},[...e.slice(0,r),{...i,blocks:s},...e.slice(r+1)]}return e}function Sae(e,t){const[n,r]=y.useState([]),[i,a]=y.useState(!1),[s,c]=y.useState([]),u=y.useRef(t.initialSessionId),f=y.useRef(!1),h=y.useRef(s);h.current=s;const p=y.useRef(t.getToken);p.current=t.getToken;const m=y.useRef(t.onNewSession);m.current=t.onNewSession;const v=y.useRef(t.onDirectivesChanged);v.current=t.onDirectivesChanged;const x=y.useRef(t.onParticipantsChanged);x.current=t.onParticipantsChanged;const b=y.useRef(t.onEvent);b.current=t.onEvent;const S=y.useRef(e);S.current=e;const _=y.useCallback(I=>I!=null&&I===u.current,[]),O=y.useCallback(async()=>{var U;const I=u.current;if(I)try{const G=await(await bl(`/api/sessions/${I}/messages`,p.current)).json();r(uj(G)),a(!!G.busy),(U=x.current)==null||U.call(x,Array.isArray(G.participants)&&G.participants.length>1)}catch{}},[]);y.useEffect(()=>{if(!e)return;const I=e.on(U=>{var G,$,q,K,Z,j;(G=b.current)==null||G.call(b,U);const V=U;if(V.type==="compact_marker")return _(V.sessionId)?r(H=>[...H,{id:ms(),role:"assistant",blocks:[{type:"compact_marker",summary:V.summary??"",compactedCount:V.compactedCount??0}]}]):void 0;switch(U.type){case"thinking_delta":return _(U.sessionId)?r(H=>gi(H,{type:"thinking",text:U.text})):void 0;case"text_delta":return _(U.sessionId)?r(H=>gi(H,{type:"text",text:U.text})):void 0;case"tool_use":return _(U.sessionId)?r(H=>gi(H,{type:"tool_use",tool:U.tool,toolUseId:U.toolUseId,input:U.input})):void 0;case"tool_use_input":return _(U.sessionId)?r(H=>Q3(H,U.toolUseId,U.input)):void 0;case"tool_result":return _(U.sessionId)?r(H=>gi(H,{type:"tool_result",toolUseId:U.toolUseId,output:U.output})):void 0;case"tool_result_image":return _(U.sessionId)?r(H=>gi(H,{type:"image",src:U.dataUrl})):void 0;case"permission_request":return _(U.sessionId)?r(H=>gi(H,{type:"permission_request",id:U.id,tool:U.tool,input:U.input})):void 0;case"question_request":return _(U.sessionId)?r(H=>gi(H,{type:"question_request",id:U.id,questions:U.questions})):void 0;case"directives":return f.current?($=v.current)==null?void 0:$.call(v,U.directives):void 0;case"session_id":return!f.current||u.current?void 0:(u.current=U.sessionId,(q=m.current)==null?void 0:q.call(m,U.sessionId));case"forked":return U.sourceSessionId!==u.current?void 0:(u.current=U.sessionId,(K=m.current)==null?void 0:K.call(m,U.sessionId));case"session_busy":U.sessionId===u.current&&a(U.busy);return;case"session_stream":return U.sessionId!==u.current?void 0:_ae(r,U.event);case"session_messages_changed":U.sessionId===u.current&&O();return;case"done":{if(U.sessionId!==u.current)return;U.stopReason==="max_turns_reached"&&r(ee=>gi(ee,{type:"text",text:`
1848
1848
 
1849
1849
  ---
1850
1850
  ⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.`})),(Z=m.current)==null||Z.call(m,U.sessionId);const H=h.current;if(H.length>0){const ee=H.join(`
@@ -13,7 +13,7 @@
13
13
  <link rel="preconnect" href="https://fonts.googleapis.com" />
14
14
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
15
15
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
16
- <script type="module" crossorigin src="/assets/index-DUX31_SP.js"></script>
16
+ <script type="module" crossorigin src="/assets/index-h0IKxLlQ.js"></script>
17
17
  <link rel="stylesheet" crossorigin href="/assets/index-J2NH6FvE.css">
18
18
  </head>
19
19
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shraga",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "description": "The teammate you delegate coding to — a self-hostable, multi-user AI coding agent web UI (Claude Code, with a pluggable engine seam).",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -15,6 +15,8 @@ export interface UsageLimit {
15
15
  }
16
16
  export interface Usage {
17
17
  subscriptionType: string | null;
18
+ /** The Claude account whose quota this is (email, else display name). */
19
+ account?: string | null;
18
20
  limits: UsageLimit[];
19
21
  /** When the server last actually read these numbers from upstream (ISO). */
20
22
  fetchedAt?: string;
@@ -213,7 +215,10 @@ export function UsageCard({ usage }: { usage: Usage }) {
213
215
  <span className="uppercase tracking-wide">claude usage</span>
214
216
  {usage.subscriptionType && <span className="tabular-nums">{usage.subscriptionType} plan</span>}
215
217
  </div>
216
- <div className="-mt-1 pb-2 text-[10px] text-muted-foreground">{ageLabel(usage)}</div>
218
+ <div className="-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground">
219
+ {usage.account && <span className="truncate" title={usage.account}>{usage.account}</span>}
220
+ <span className="shrink-0">{ageLabel(usage)}</span>
221
+ </div>
217
222
  <div className="flex flex-col gap-3">
218
223
  {usage.limits.map((l, i) => {
219
224
  const until = untilLabel(l.resetsAt);
@@ -21,7 +21,7 @@ import express from 'express';
21
21
  import { WebSocketServer, WebSocket } from 'ws';
22
22
  import { requireAuth, verifyBearer, authenticateToken, AUTH_PROVIDER, localLogin, addLocalUser, localUserCount } from './auth.ts';
23
23
  import { getMcpConfig, getRawMcpConfig, getResolvedMcpConfig, getGlobalMcpConfig, saveMcpConfig, maskEnvValues, mergeWithOriginal, type McpConfig } from './mcp.ts';
24
- import { streamChat, consumeStream, getAgentConfig, saveAgentConfig, getClaudeAuthSource, type AgentConfig, type PermissionHandler, type QuestionHandler, type QuestionAnswers, type AttachmentMeta, type WsEvent } from './claude.ts';
24
+ import { streamChat, consumeStream, getAgentConfig, saveAgentConfig, getClaudeAuthSource, type AgentConfig, type PermissionHandler, type QuestionHandler, type QuestionAnswers, type AttachmentMeta, type WsEvent, MAX_TURNS_NOTICE } from './claude.ts';
25
25
  import { mountFeatures, registerFeature, resumeFeatureSession, collectFeatureFlags, collectSidecarRoutes } from './features.ts';
26
26
  import { registerSpaCatchAll } from './spa-catchall.ts';
27
27
  import { slackFeature } from './slack/feature.ts';
@@ -576,7 +576,7 @@ app.get('/api/schedules/:id/runs', requireAuth, (req, res) => {
576
576
  */
577
577
  type RunChatTurnResult =
578
578
  | { status: 'busy' }
579
- | { sessionId: string; text: string; blocks: ConvBlock[] }
579
+ | { sessionId: string; text: string; blocks: ConvBlock[]; stopReason?: string }
580
580
  | { sessionId: string; error: string };
581
581
 
582
582
  async function runChatTurn(
@@ -604,6 +604,14 @@ async function runChatTurn(
604
604
  appendMessage(sid, { id: crypto.randomUUID(), role: 'user', blocks: [{ type: 'text', text: prompt }], channel: 'api', senderName: userName });
605
605
  setRunStatus(sid, 'running', 'web');
606
606
 
607
+ let stopReason: string | undefined;
608
+ const onEvent = (ev: WsEvent) => {
609
+ // consumeStream() drops the `done` event's stopReason, so every non-WS transport lost the fact
610
+ // that the turn was TRUNCATED and returned the partial answer as if it were complete.
611
+ if (ev.type === 'done') stopReason = (ev as any).stopReason;
612
+ hooks?.onEvent?.(ev);
613
+ };
614
+
607
615
  try {
608
616
  const blocks = await consumeStream(streamChat({
609
617
  prompt,
@@ -615,7 +623,7 @@ async function runChatTurn(
615
623
  abortController,
616
624
  context: opts.context ?? { source: 'api', user: userEmail },
617
625
  onPermissionRequest: async () => ({ allow: true }),
618
- }), hooks?.onEvent);
626
+ }), onEvent);
619
627
  if (blocks.length) {
620
628
  appendMessage(sid, { id: crypto.randomUUID(), role: 'assistant', blocks });
621
629
  }
@@ -623,7 +631,7 @@ async function runChatTurn(
623
631
  const meta = getSession(sid);
624
632
  notifyUnread(uid, sid, text.slice(0, 120) || '(completed)', 'response', meta?.title);
625
633
  broadcast({ type: 'session_messages_changed', sessionId: sid });
626
- return { sessionId: sid, text, blocks };
634
+ return { sessionId: sid, text, blocks, stopReason };
627
635
  } catch (err: any) {
628
636
  console.error(`[chat-turn] error:`, err.message);
629
637
  return { sessionId: sid, error: err.message };
@@ -1460,7 +1468,7 @@ async function runStream(ws: WebSocket, session: WsSession, sid: string, promptT
1460
1468
  } else if (event.type === 'done') {
1461
1469
  stopReason = event.stopReason ?? 'end_turn';
1462
1470
  if (stopReason === 'max_turns_reached') {
1463
- assistantBlocks.push({ type: 'text', text: '\n\n---\n⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.' });
1471
+ assistantBlocks.push({ type: 'text', text: MAX_TURNS_NOTICE });
1464
1472
  }
1465
1473
  if (!assistantText && !thinkingText && assistantBlocks.length === 0 && !event.builtinHandled) {
1466
1474
  const fallback = '⚠️ No response was generated. Try rephrasing or sending again.';
@@ -31,6 +31,9 @@ export interface ClaudeUsageLimit {
31
31
 
32
32
  export interface ClaudeUsage {
33
33
  subscriptionType: string | null;
34
+ /** Which Claude account these numbers belong to (email, else display name). A box can be signed in
35
+ * as somebody other than the person reading the gauge — say whose quota this is. */
36
+ account: string | null;
34
37
  limits: ClaudeUsageLimit[];
35
38
  /** When these numbers were actually read from upstream (ISO). The client labels the gauge with it. */
36
39
  fetchedAt: string;
@@ -42,6 +45,8 @@ export interface ClaudeUsage {
42
45
  export class ClaudeUsageOptions {
43
46
  credentialsPath = path.join(homedir(), '.claude', '.credentials.json');
44
47
  endpoint = 'https://api.anthropic.com/api/oauth/usage';
48
+ /** Claude Code's own config, the only place the signed-in account's identity is written. */
49
+ accountPath = path.join(homedir(), '.claude.json');
45
50
  /** How long a completed upstream result (success OR failure) is reused for. Concurrent callers are
46
51
  * deduped separately onto one in-flight request, so a reload storm or a wall of open tabs costs at
47
52
  * most one upstream call per window — this endpoint answers 429 aggressively. Failures are cached
@@ -50,8 +55,12 @@ export class ClaudeUsageOptions {
50
55
  timeoutMs = 8_000;
51
56
  /** A 429 is not a transient blip here: retrying it on the ordinary TTL is what keeps a box wedged in
52
57
  * the penalty box all day (25 straight 429s on prod). Each consecutive 429 climbs this ladder and a
53
- * success drops back to the first rung; a `Retry-After` header wins over the rung when it is longer. */
54
- rateLimitBackoffMs = [60_000, 300_000, 900_000, 1_800_000];
58
+ * success drops back to the first rung; a `Retry-After` header wins over the rung when it is longer.
59
+ * Capped at 15m, not 30m: on a busy box (many CLI sessions sharing one account quota) upstream can
60
+ * answer 429 for hours with a ~73s Retry-After, and every attempt is a chance at the first reading
61
+ * that unhides the gauge. A failed attempt no longer costs the user anything — the last known-good
62
+ * reading stays on screen — so a slightly shorter ceiling is the better trade. */
63
+ rateLimitBackoffMs = [60_000, 300_000, 600_000, 900_000];
55
64
  /** macOS stores Claude Code's OAuth credentials in the login Keychain and writes NO credentials
56
65
  * file, so on darwin an absent file is not proof of an API-key deployment — we look there second.
57
66
  * Linux keeps the file as the only source; we never shell out there. */
@@ -199,7 +208,7 @@ export class ClaudeUsageReader {
199
208
  return null;
200
209
  }
201
210
  this.rateLimitStreak = 0;
202
- return { subscriptionType: creds.subscriptionType, limits };
211
+ return { subscriptionType: creds.subscriptionType, account: await this.readAccount(), limits };
203
212
  } catch (err) {
204
213
  console.warn(`${TAG} usage lookup failed:`, (err as Error).message);
205
214
  return null;
@@ -253,6 +262,18 @@ export class ClaudeUsageReader {
253
262
  return parseCredentials(secret, 'keychain');
254
263
  }
255
264
 
265
+ /** Whose account this box is signed in as. Identity only — never a token, and never fatal: an
266
+ * unreadable config just means the card omits the line. */
267
+ private async readAccount(): Promise<string | null> {
268
+ try {
269
+ const account = JSON.parse(await readFile(this.options.accountPath, 'utf8'))?.oauthAccount;
270
+ return account?.emailAddress ?? account?.displayName ?? null;
271
+ } catch (err) {
272
+ console.debug(`${TAG} could not read the signed-in account: ${(err as Error).message}`);
273
+ return null;
274
+ }
275
+ }
276
+
256
277
  /** The configured path first, then any sibling `.credentials*.json` the CLI may have written. */
257
278
  private async credentialFiles(): Promise<string[]> {
258
279
  const configured = this.options.credentialsPath;
@@ -13,6 +13,7 @@ import {
13
13
  getSkill,
14
14
  getMcpCommandPrompt,
15
15
  parseSkillFrontmatter,
16
+ resolveSkillTurns,
16
17
  } from './skills.ts';
17
18
 
18
19
  import { buildWorkspaceContextBlock, expandWorkspaceMentions } from './workspace.ts';
@@ -306,6 +307,22 @@ export async function* streamChat(opts: {
306
307
  const newTriggerNames = discoveryEnabled ? matchTriggeredSkillNames(effectivePrompt, opts.context) : [];
307
308
  const triggeredNames = [...new Set([...stickyNames, ...newTriggerNames])];
308
309
  const triggeredSkills = skillInjectionBlocks(triggeredNames);
310
+
311
+ // Per-skill turn budget. Resolved HERE, once every invoked skill is known (the slash command and
312
+ // the triggered/sticky set), and GAP-FILLING only: an inline `[turns:N]` or a session-pinned
313
+ // value already sits in `directives` and is left alone. The global `config.maxTurns` is applied
314
+ // later still, by the engine (`directives.turns ?? config.maxTurns`), so a skill budget slots
315
+ // cleanly between the two without touching the global default.
316
+ // NOTE the deliberate asymmetry with `model` above, which OVERWRITES an inline directive: a
317
+ // long-running skill needs a floor, not the last word — the human who typed `[turns:5]` to probe
318
+ // it cheaply must still get 5.
319
+ if (!directives.turns) {
320
+ const skillTurns = resolveSkillTurns([slashCmd?.command, ...triggeredNames]);
321
+ if (skillTurns) {
322
+ directives.turns = skillTurns;
323
+ console.log(`[claude] Directives: ${JSON.stringify(directives)} (turns from skill frontmatter)`);
324
+ }
325
+ }
309
326
  const workspaceTree = buildWorkspaceContextBlock();
310
327
  const contact = opts.userEmail ? contacts.find({ email: opts.userEmail }) : null;
311
328
  const userBlock = contacts.formatUserBlock(contact);
@@ -366,6 +383,10 @@ export async function* streamChat(opts: {
366
383
  });
367
384
  }
368
385
 
386
+ /** The notice appended to a turn that ran out of steps. Shared so every transport says the same
387
+ * thing — the MCP path said NOTHING at all, so a truncated turn arrived looking finished. */
388
+ export const MAX_TURNS_NOTICE = '\n\n---\n⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.';
389
+
369
390
  export async function consumeStream(stream: AsyncGenerator<WsEvent>, onEvent?: (ev: WsEvent) => void): Promise<ConvBlock[]> {
370
391
  let text = '';
371
392
  let thinking = '';
@@ -10,7 +10,7 @@ import { listSkills, getSkill, saveSkill } from './skills.ts';
10
10
  import { getAllSessions, loadConversation, isSessionLocked } from './sessions.ts';
11
11
  import * as scheduler from './scheduler/index.ts';
12
12
  import { buildReport } from './downtime.ts';
13
- import { getAgentConfig } from './claude.ts';
13
+ import { getAgentConfig, MAX_TURNS_NOTICE } from './claude.ts';
14
14
  import { validateApiKey } from './api-keys.ts';
15
15
  import { verifyMcpToken } from './auth.ts';
16
16
  import { makeProgressEmitter } from './mcp-progress.ts';
@@ -19,7 +19,7 @@ import type { WsEvent } from './claude.ts';
19
19
 
20
20
  export type RunChatTurnResult =
21
21
  | { status: 'busy' }
22
- | { sessionId: string; text: string; blocks: unknown[] }
22
+ | { sessionId: string; text: string; blocks: unknown[]; stopReason?: string }
23
23
  | { sessionId: string; error: string };
24
24
 
25
25
  export type RunChatTurn = (
@@ -318,7 +318,16 @@ export function createShragaMcp(deps: McpServerDeps) {
318
318
  const result = await deps.runChatTurn(turn, { onEvent: makeProgressEmitter(captureMcpProgress()) });
319
319
  if ('status' in result) return json({ error: 'Session is already processing a request' }, { status: 409 });
320
320
  if ('error' in result) return json({ error: result.error, sessionId: result.sessionId }, { status: 500 });
321
- return json({ sessionId: result.sessionId, text: result.text, blocks: result.blocks });
321
+ // A turn that hit the step ceiling is a PARTIAL answer. Without this the MCP caller got the
322
+ // partial text and no signal at all, which is what "the agent stalled" reports actually were.
323
+ const truncated = result.stopReason === 'max_turns_reached';
324
+ return json({
325
+ sessionId: result.sessionId,
326
+ text: truncated ? result.text + MAX_TURNS_NOTICE : result.text,
327
+ blocks: result.blocks,
328
+ ...(result.stopReason ? { stopReason: result.stopReason } : {}),
329
+ ...(truncated ? { truncated: true } : {}),
330
+ });
322
331
  } catch (e) { return json({ error: errMessage(e) }, { status: 500 }); }
323
332
  });
324
333
 
@@ -18,6 +18,9 @@ export interface SkillMeta {
18
18
  model?: string;
19
19
  allowedTools?: string[];
20
20
  argumentHint?: string;
21
+ /** Per-skill turn budget. Gap-fills `directives.turns` for the turn that invokes the skill —
22
+ * inline `[turns:N]` and a session-pinned value both still win. Capped at MAX_SKILL_TURNS. */
23
+ turns?: number;
21
24
  triggers?: string[];
22
25
  expires?: string;
23
26
  origin?: string;
@@ -26,6 +29,24 @@ export interface SkillMeta {
26
29
  managedBy?: string;
27
30
  }
28
31
 
32
+ /** Ceiling on a skill's self-declared turn budget. A skill file is data — it is edited without a
33
+ * deploy and shipped by rsync — so an unbounded number there is an unattended spend hazard. 300 is
34
+ * one step above the 250 the video-ad pipeline needs in practice, so no real skill is clipped,
35
+ * while a typo'd `turns: 30000` costs a bounded worst case instead of an open-ended one. A human
36
+ * typing `[turns:N]` inline is NOT capped — that is a deliberate, attended choice. */
37
+ export const MAX_SKILL_TURNS = 300;
38
+
39
+ /** Largest turn budget declared by any of the named skills, clamped to MAX_SKILL_TURNS. */
40
+ export function resolveSkillTurns(names: (string | undefined)[]): number | undefined {
41
+ let best = 0;
42
+ for (const name of names) {
43
+ if (!name) continue;
44
+ const t = getSkill(name)?.meta.turns;
45
+ if (t && t > best) best = t;
46
+ }
47
+ return best ? Math.min(best, MAX_SKILL_TURNS) : undefined;
48
+ }
49
+
29
50
  export function isExpired(meta: SkillMeta): boolean {
30
51
  if (!meta.expires) return false;
31
52
  return new Date(meta.expires).getTime() < Date.now();
@@ -61,6 +82,7 @@ export function parseSkillFrontmatter(content: string): { meta: SkillMeta; body:
61
82
  if (key === 'model') meta.model = val;
62
83
  if (key === 'allowed-tools') meta.allowedTools = val.split(',').map(s => s.trim());
63
84
  if (key === 'argument-hint') meta.argumentHint = val;
85
+ if ((key === 'turns' || key === 'max-turns') && /^\d+$/.test(val)) meta.turns = parseInt(val, 10);
64
86
  if (key === 'triggers' && val) {
65
87
  try { meta.triggers = JSON.parse(val); } catch {
66
88
  meta.triggers = val.split(',').map(s => s.trim());