shraga 0.1.120 → 0.1.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -256,8 +256,9 @@ sends heavy work to an external pod:
256
256
  offload: { gateway: 'http://pod.internal:4700', maxLocalFileMB: 25 /* default */ },
257
257
  ```
258
258
 
259
- When set, the prompt tells the agent to use the gateway, `share_file` routes media and files over
260
- `maxLocalFileMB` through it, heavy local Bash (ffmpeg encodes, remotion renders, starting mcp-video/mcp-audio)
259
+ When set, the prompt tells the agent to use the gateway, `share_file` routes files over `maxLocalFileMB`
260
+ through it (smaller files, media included, keep the box's own public link) — but only when the gateway's links
261
+ are public; a private/tailnet-only link is refused and the agent is told to send an attachment instead, heavy local Bash (ffmpeg encodes, remotion renders, starting mcp-video/mcp-audio)
261
262
  is refused, and agent subprocesses get `SHRAGA_OFFLOAD=1` / `SHRAGA_OFFLOAD_GATEWAY`. The gateway's HTTP
262
263
  contract is documented in `src/server/offload.ts`. Unset = none of this.
263
264
 
@@ -1904,7 +1904,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),bn=ve,At=je),rt===void
1904
1904
  `)},LM=function(){var e=parseInt(document.body.getAttribute(Cu)||"0",10);return isFinite(e)?e:0},ure=function(){b.useEffect(function(){return document.body.setAttribute(Cu,(LM()+1).toString()),function(){var e=LM()-1;e<=0?document.body.removeAttribute(Cu):document.body.setAttribute(Cu,e.toString())}},[])},dre=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;ure();var a=b.useMemo(function(){return sre(i)},[i]);return b.createElement(lre,{styles:cre(a,!t,i,n?"":"!important")})},o1=!1;if(typeof window<"u")try{var Ap=Object.defineProperty({},"passive",{get:function(){return o1=!0,!0}});window.addEventListener("test",Ap,Ap),window.removeEventListener("test",Ap,Ap)}catch{o1=!1}var nu=o1?{passive:!1}:!1,fre=function(e){return e.tagName==="TEXTAREA"},fz=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!fre(e)&&n[t]==="visible")},hre=function(e){return fz(e,"overflowY")},mre=function(e){return fz(e,"overflowX")},zM=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=hz(e,r);if(i){var a=mz(e,r),s=a[1],l=a[2];if(s>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},pre=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},gre=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},hz=function(e,t){return e==="v"?hre(t):mre(t)},mz=function(e,t){return e==="v"?pre(t):gre(t)},vre=function(e,t){return e==="h"&&t==="rtl"?-1:1},yre=function(e,t,n,r,i){var a=vre(e,window.getComputedStyle(t).direction),s=a*r,l=n.target,u=t.contains(l),d=!1,h=s>0,m=0,p=0;do{if(!l)break;var g=mz(e,l),w=g[0],x=g[1],E=g[2],_=x-E-a*w;(w||_)&&hz(e,l)&&(m+=_,p+=w);var k=l.parentNode;l=k&&k.nodeType===Node.DOCUMENT_FRAGMENT_NODE?k.host:k}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(h&&Math.abs(m)<1||!h&&Math.abs(p)<1)&&(d=!0),d},kp=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},$M=function(e){return[e.deltaX,e.deltaY]},BM=function(e){return e&&"current"in e?e.current:e},bre=function(e,t){return e[0]===t[0]&&e[1]===t[1]},xre=function(e){return`
1905
1905
  .block-interactivity-`.concat(e,` {pointer-events: none;}
1906
1906
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
1907
- `)},wre=0,ru=[];function Ere(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),i=b.useState(wre++)[0],a=b.useState(dz)[0],s=b.useRef(e);b.useEffect(function(){s.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=I7([e.lockRef.current],(e.shards||[]).map(BM),!0).filter(Boolean);return x.forEach(function(E){return E.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(E){return E.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=b.useCallback(function(x,E){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!s.current.allowPinchZoom;var _=kp(x),k=n.current,O="deltaX"in x?x.deltaX:k[0]-_[0],N="deltaY"in x?x.deltaY:k[1]-_[1],C,T=x.target,M=Math.abs(O)>Math.abs(N)?"h":"v";if("touches"in x&&M==="h"&&T.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,R=j?j===T||j.contains(T):!1;if(R)return!1;var H=zM(M,T);if(!H)return!0;if(H?C=M:(C=M==="v"?"h":"v",H=zM(M,T)),!H)return!1;if(!r.current&&"changedTouches"in x&&(O||N)&&(r.current=C),!C)return!0;var P=r.current||C;return yre(P,E,x,P==="h"?O:N)},[]),u=b.useCallback(function(x){var E=x;if(!(!ru.length||ru[ru.length-1]!==a)){var _="deltaY"in E?$M(E):kp(E),k=t.current.filter(function(C){return C.name===E.type&&(C.target===E.target||E.target===C.shadowParent)&&bre(C.delta,_)})[0];if(k&&k.should){E.cancelable&&E.preventDefault();return}if(!k){var O=(s.current.shards||[]).map(BM).filter(Boolean).filter(function(C){return C.contains(E.target)}),N=O.length>0?l(E,O[0]):!s.current.noIsolation;N&&E.cancelable&&E.preventDefault()}}},[]),d=b.useCallback(function(x,E,_,k){var O={name:x,delta:E,target:_,should:k,shadowParent:Sre(_)};t.current.push(O),setTimeout(function(){t.current=t.current.filter(function(N){return N!==O})},1)},[]),h=b.useCallback(function(x){n.current=kp(x),r.current=void 0},[]),m=b.useCallback(function(x){d(x.type,$M(x),x.target,l(x,e.lockRef.current))},[]),p=b.useCallback(function(x){d(x.type,kp(x),x.target,l(x,e.lockRef.current))},[]);b.useEffect(function(){return ru.push(a),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:p}),document.addEventListener("wheel",u,nu),document.addEventListener("touchmove",u,nu),document.addEventListener("touchstart",h,nu),function(){ru=ru.filter(function(x){return x!==a}),document.removeEventListener("wheel",u,nu),document.removeEventListener("touchmove",u,nu),document.removeEventListener("touchstart",h,nu)}},[]);var g=e.removeScrollBar,w=e.inert;return b.createElement(b.Fragment,null,w?b.createElement(a,{styles:xre(i)}):null,g?b.createElement(dre,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Sre(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const _re=Qne(uz,Ere);var vS=b.forwardRef(function(e,t){return b.createElement(Wv,xa({},e,{ref:t,sideCar:_re}))});vS.classNames=Wv.classNames;var Are=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},iu=new WeakMap,Op=new WeakMap,Np={},Lx=0,pz=function(e){return e&&(e.host||pz(e.parentNode))},kre=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=pz(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})},Ore=function(e,t,n,r){var i=kre(t,Array.isArray(e)?e:[e]);Np[n]||(Np[n]=new WeakMap);var a=Np[n],s=[],l=new Set,u=new Set(i),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};i.forEach(d);var h=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(p){if(l.has(p))h(p);else try{var g=p.getAttribute(r),w=g!==null&&g!=="false",x=(iu.get(p)||0)+1,E=(a.get(p)||0)+1;iu.set(p,x),a.set(p,E),s.push(p),x===1&&w&&Op.set(p,!0),E===1&&p.setAttribute(n,"true"),w||p.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",p,_)}})};return h(t),l.clear(),Lx++,function(){s.forEach(function(m){var p=iu.get(m)-1,g=a.get(m)-1;iu.set(m,p),a.set(m,g),p||(Op.has(m)||m.removeAttribute(r),Op.delete(m)),g||m.removeAttribute(n)}),Lx--,Lx||(iu=new WeakMap,iu=new WeakMap,Op=new WeakMap,Np={})}},gz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=Are(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),Ore(r,i,n,"aria-hidden")):function(){return null}},Yv="Dialog",[vz]=hL(Yv),[Nre,Ji]=vz(Yv),yz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,l=b.useRef(null),u=b.useRef(null),[d,h]=Sne({prop:r,defaultProp:i??!1,onChange:a,caller:Yv});return y.jsx(Nre,{scope:t,triggerRef:l,contentRef:u,contentId:Mx(),titleId:Mx(),descriptionId:Mx(),open:d,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(m=>!m),[h]),modal:s,children:n})};yz.displayName=Yv;var bz="DialogTrigger",xz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(bz,n),a=ui(t,i.triggerRef);return y.jsx(Fr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ES(i.open),...r,ref:a,onClick:Sr(e.onClick,i.onOpenToggle)})});xz.displayName=bz;var yS="DialogPortal",[Cre,wz]=vz(yS,{forceMount:void 0}),Ez=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Ji(yS,t);return y.jsx(Cre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Zs,{present:n||a.open,children:y.jsx(lz,{asChild:!0,container:i,children:s})}))})};Ez.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=wz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Pg,e.__scopeDialog);return a.modal?y.jsx(Zs,{present:r||a.open,children:y.jsx(Mre,{...i,ref:t})}):null});bS.displayName=Pg;var Tre=GE("DialogOverlay.RemoveScroll"),Mre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Pg,n),a=Mne(),s=ui(t,a);return y.jsx(vS,{as:Tre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Fr.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Uu="DialogContent",xS=b.forwardRef((e,t)=>{const n=wz(Uu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Uu,e.__scopeDialog);return y.jsx(Zs,{present:r||a.open,children:a.modal?y.jsx(Ire,{...i,ref:t}):y.jsx(Rre,{...i,ref:t})})});xS.displayName=Uu;var Ire=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(null),i=ui(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return gz(a)},[]),y.jsx(Sz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Sr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:Sr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:Sr(e.onFocusOutside,a=>a.preventDefault())})}),Rre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Sz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Sz=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Ji(Uu,n);return Hne(),y.jsx(y.Fragment,{children:y.jsx(oz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(iz,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ES(l.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),_z="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(_z,n);return y.jsx(Fr.h2,{id:i.titleId,...r,ref:t})});wS.displayName=_z;var Az="DialogDescription",Pre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Az,n);return y.jsx(Fr.p,{id:i.descriptionId,...r,ref:t})});Pre.displayName=Az;var kz="DialogClose",Oz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(kz,n);return y.jsx(Fr.button,{type:"button",...r,ref:t,onClick:Sr(e.onClick,()=>i.onOpenChange(!1))})});Oz.displayName=kz;function ES(e){return e?"open":"closed"}const Oo=yz,rd=xz,Dre=Ez,Nz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:Be("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}));Nz.displayName=bS.displayName;const Na=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Dre,{children:[y.jsx(Nz,{}),y.jsxs(xS,{ref:r,className:Be("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,y.jsxs(Oz,{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:[y.jsx(Bs,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Na.displayName=xS.displayName;function Us({className:e,...t}){return y.jsx("div",{className:Be("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:Be("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Tz({className:e,...t}){return y.jsx("div",{className:Be("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 No=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:Be("text-lg font-semibold leading-none tracking-tight",e),...t}));No.displayName=wS.displayName;const jre=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),Lre=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function zre(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 $re({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=b.useState(new Map),[a,s]=b.useState(()=>new Set),[l,u]=b.useState(null),[d,h]=b.useState(!1),[m,p]=b.useState("fit"),[g,w]=b.useState(null),[x,E]=b.useState(null),_=b.useRef(null),[k,O]=b.useState(null),[N,C]=b.useState(!1),[T,M]=b.useState([]),D=b.useCallback(async U=>{const K=await zre(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],R=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),V=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&V&&E({w:F,h:V})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,V=U.clientWidth-F,$=U.clientHeight-F,L=Math.min(V/K.w,$/K.h,1);w({scale:L,w:K.w,h:K.h})},[x]);b.useEffect(()=>{if(!(l!=null&&l.html)||m!=="fit"){w(null);return}const U=_.current;if(!U)return;const K=new ResizeObserver(()=>requestAnimationFrame(H));return K.observe(U),()=>K.disconnect()},[l==null?void 0:l.html,d,m,H]),b.useEffect(()=>{N&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(K=>K.json()).then(M).catch(()=>{})})},[N]);const P=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||D(U)),F})},G=(U,K)=>{const F=new URLSearchParams({path:U});return k&&F.set("token",k),K&&F.set("dl","1"),`/api/workspace/raw?${F}`},q=async U=>{var V;const K=await e();if(!K)return;O(K);const F=((V=U.split(".").pop())==null?void 0:V.toLowerCase())??"";if(F==="html"||F==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(jre.has(F)){u({path:U,content:"",binary:!1,image:!0});return}if(Lre.has(F)){u({path:U,content:"",binary:!1,html:!0});return}try{const $=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${K}`}});if(!$.ok)return;const L=await $.json();u({path:U,content:L.content,binary:!!L.binary})}catch{}},X=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const V=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>P(F.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+K*12},children:[y.jsx(Xs,{className:Be("w-3 h-3 shrink-0 transition-transform",a.has(F.path)&&"rotate-90")}),y.jsx(QG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}):y.jsxs("button",{onClick:()=>q(F.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+K*12+12},title:F.oneLiner||F.path,children:[y.jsx(UE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}),F.type==="dir"&&a.has(F.path)&&X(r.get(F.path)??[],K+1)]},F.path)})});return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),y.jsxs("div",{className:"flex items-center gap-0.5",children:[y.jsx("button",{onClick:()=>C(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:y.jsx(eV,{className:"w-3 h-3"})}),y.jsx("button",{onClick:()=>{D(""),a.forEach(U=>D(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:y.jsx(ed,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?y.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."}):X(j,0)}),y.jsx(Oo,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(Na,{className:Be(l!=null&&l.html?Be("!flex !flex-col !p-0 !gap-0 overflow-hidden",d?"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:[y.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(l==null?void 0:l.html)&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>p(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:m==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:m==="fit"?y.jsx(aV,{className:"w-4 h-4"}):y.jsx(dV,{className:"w-4 h-4"})}),y.jsx("button",{onClick:()=>h(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:d?"Restore":"Maximize",children:d?y.jsx(HE,{className:"w-4 h-4"}):y.jsx(FE,{className:"w-4 h-4"})})]}),l&&y.jsx("a",{href:G(l.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:y.jsx(lL,{className:"w-4 h-4"})})]}),y.jsx(Us,{className:Be((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(No,{className:"font-mono text-sm truncate pr-16",children:l==null?void 0:l.path})}),y.jsx("div",{ref:l!=null&&l.html?_:void 0,className:Be(l!=null&&l.html?Be("flex-1 min-h-0 bg-muted/10",m==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:l!=null&&l.html?m==="fit"?y.jsx("div",{style:g?{width:g.w*g.scale,height:g.h*g.scale}:{width:"100%",height:"100%"},children:y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white origin-top-left",title:l.path,onLoad:U=>{R(U.currentTarget),H()},style:g?{width:g.w,height:g.h,transform:`scale(${g.scale})`}:{width:"100%",height:"100%"}})}):y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white mx-auto block",title:l.path,onLoad:U=>R(U.currentTarget),style:{width:(x==null?void 0:x.w)||"100%",height:(x==null?void 0:x.h)||"100%"}}):l!=null&&l.image?y.jsx("div",{className:"flex items-center justify-center p-4",children:y.jsx("img",{src:G(l.path),alt:l.path,className:"max-w-full max-h-[70vh] object-contain"})}):l!=null&&l.binary?y.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):l!=null&&l.path.toLowerCase().endsWith(".md")||l!=null&&l.path.toLowerCase().endsWith(".markdown")?y.jsx("div",{className:"text-sm",children:y.jsx(d3,{remarkPlugins:[D3],rehypePlugins:[rz],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:l.content})}):y.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:l==null?void 0:l.content})})]})}),y.jsx(Oo,{open:N,onOpenChange:C,children:y.jsxs(Na,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Us,{children:y.jsx(No,{className:"text-sm",children:"Activity Log"})}),y.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[T.map(U=>y.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsx("span",{className:"text-sm text-foreground",children:U.message}),y.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Bre(U.date)})]}),U.files.length>0&&y.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(K=>y.jsx("span",{className:"inline-block mr-2 font-mono",children:K},K))})]},U.hash)),T.length===0&&y.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Bre(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"})}function ag(e,t=Date.now()){if(!e)return null;const n=new Date(e).getTime()-t;if(!Number.isFinite(n)||n<=0)return null;const r=Math.round(n/6e4);if(r<1)return"1m";if(r<60)return`${r}m`;const i=Math.floor(r/60),a=r%60;if(i<48)return a?`${i}h ${a}m`:`${i}h`;const s=Math.floor(i/24),l=i%24;return l?`${s}d ${l}h`:`${s}d`}const Ure=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function Fre(e,t=Date.now(),n=Date.now()){var m;const r=e.match(Ure);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(m=r[3])==null?void 0:m.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const l=new Date(t),u=new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const d=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),h=ag(u.toISOString(),n);return e.replace(r[0],`resets ${d}${h?` (in ${h})`:""}`)}var Hre=Object.defineProperty,id=(e,t)=>Hre(e,"name",{value:t,configurable:!0}),Mz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ds(e,t,{checkForDefaultPrevented:n=!0}={}){return id(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}id(Ds,"composeEventHandlers");function Kre(e){var t;if(!Mz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}id(Kre,"getOwnerWindow");function s1(e){if(!Mz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}id(s1,"getOwnerDocument");function Iz(e,t=!1){const{activeElement:n}=s1(e);if(!(n!=null&&n.nodeName))return null;if(Rz(n)&&n.contentDocument)return Iz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=s1(n).getElementById(r);if(i)return i}}return n}id(Iz,"getActiveElement");function Rz(e){return e.tagName==="IFRAME"}id(Rz,"isFrame");var qre=Object.defineProperty,SS=(e,t)=>qre(e,"name",{value:t,configurable:!0});function l1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}SS(l1,"setRef");function Pz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=l1(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():l1(e[i],null)}}}}SS(Pz,"composeRefs");function ad(...e){return b.useCallback(Pz(...e),e)}SS(ad,"useComposedRefs");var Gre=Object.defineProperty,Ni=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function Vre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ni(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ni(i,"useContext"),[r,i]}Ni(Vre,"createContext");function Dz(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ni(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ni(h,"useContext"),[d,h]}Ni(r,"createContext");const i=Ni(()=>{const a=n.map(s=>b.createContext(s));return Ni(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,jz(i,...t)]}Ni(Dz,"createContextScope");function jz(...e){const t=e[0];if(e.length===1)return t;const n=Ni(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ni(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ni(jz,"composeContextScopes");var Wre=Object.defineProperty,ea=(e,t)=>Wre(e,"name",{value:t,configurable:!0});function _S(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];c1(i)&&typeof Cp=="function"&&(i=Cp(i._payload)),b.Children.forEach(i,p=>{var g;if(Bz(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;c1(x)&&typeof Cp=="function"&&(x=Cp(x._payload)),s=Xre(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?$z(s):void 0,h=ad(r,d);if(!s){if(i||i===0)throw new Error(l?Jre(e):Qre(e));return i}const m=zz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ea(_S,"createSlot");var Lz=Symbol.for("radix.slottable");function Yre(e){const t=ea(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Lz,t}ea(Yre,"createSlottable");var Xre=ea((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function zz(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ea(zz,"mergeProps");function $z(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)}ea($z,"getElementRef");function Bz(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Lz}ea(Bz,"isSlottable");var Zre=Symbol.for("react.lazy");function c1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Zre&&"_payload"in e&&Uz(e._payload)}ea(c1,"isLazyComponent");function Uz(e){return typeof e=="object"&&e!==null&&"then"in e}ea(Uz,"isPromiseLike");var Qre=ea(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Jre=ea(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=ja[" use ".trim().toString()],eie=Object.defineProperty,tie=(e,t)=>eie(e,"name",{value:t,configurable:!0}),nie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Xv=nie.reduce((e,t)=>{const n=_S(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Fz(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}tie(Fz,"dispatchDiscreteCustomEvent");var rie=Object.defineProperty,iie=(e,t)=>rie(e,"name",{value:t,configurable:!0});function Zv(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}iie(Zv,"useCallbackRef");var aie=Object.defineProperty,qn=(e,t)=>aie(e,"name",{value:t,configurable:!0}),u1="dismissableLayer.update",oie="dismissableLayer.pointerDownOutside",sie="dismissableLayer.focusOutside",UM,Hz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),lie=b.forwardRef(qn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...h}=t,m=b.useContext(Hz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=ad(n,g),_=Array.from(m.layers),[k]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),O=k?_.indexOf(k):-1,N=p?_.indexOf(p):-1,C=m.layersWithOutsidePointerEventsDisabled.size>0,T=N>=O,M=b.useRef(!1),D=Kz(P=>{s==null||s(P),u==null||u(P),P.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(P=>{if(!(P instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(P));return T&&!G},[m.branches,T])}),j=qz(P=>{if(i&&M.current)return;const G=P.target;[...m.branches].some(X=>X.contains(G))||(l==null||l(P),u==null||u(P),P.defaultPrevented||d==null||d())},w),R=p?N===_.length-1:!1,H=Zv(P=>{P.key==="Escape"&&(a==null||a(P),!P.defaultPrevented&&d&&(P.preventDefault(),d()))});return b.useEffect(()=>{if(R)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,R,H]),b.useEffect(()=>{if(p)return r&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(UM=w.body.style.pointerEvents,w.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(p)),m.layers.add(p),d1(),()=>{r&&(m.layersWithOutsidePointerEventsDisabled.delete(p),m.layersWithOutsidePointerEventsDisabled.size===0&&(w.body.style.pointerEvents=UM))}},[p,w,r,m]),b.useEffect(()=>()=>{p&&(m.layers.delete(p),m.layersWithOutsidePointerEventsDisabled.delete(p),d1())},[p,m]),b.useEffect(()=>{const P=qn(()=>x({}),"handleUpdate");return document.addEventListener(u1,P),()=>document.removeEventListener(u1,P)},[]),y.jsx(Xv.div,{...h,ref:E,style:{pointerEvents:C?T?"auto":"none":void 0,...t.style},onFocusCapture:Ds(t.onFocusCapture,j.onFocusCapture),onBlurCapture:Ds(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:Ds(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function cie(){const e=b.useContext(Hz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}qn(cie,"useDismissableLayerSurface");var uie=qn(()=>!0,"IS_TRUE");function Kz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=uie}=t,l=Zv(e),u=b.useRef(!1),d=b.useRef(!1),h=b.useRef(new Map),m=b.useRef(()=>{});return b.useEffect(()=>{function p(){d.current=!1,i.current=!1,h.current.clear()}qn(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}qn(g,"isOutsideInteractionIntercepted");function w(O){if(!d.current)return;const N=O.target;N instanceof Node&&[...a].some(T=>T.contains(N))||h.current.set(O.type,!0),O.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}qn(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}qn(x,"handleInteractionBubble");const E=qn(O=>{if(O.target&&!u.current){let N=function(){n.removeEventListener("click",m.current);const T=g();p(),T||AS(oie,l,C,{discrete:!0})};if(qn(N,"handleAndDispatchPointerDownOutsideEvent"),!s(O.target)){n.removeEventListener("click",m.current),p(),u.current=!1;return}const C={originalEvent:O};d.current=!0,i.current=r&&O.button===0,h.current.clear(),!r||O.button!==0?N():(n.removeEventListener("click",m.current),m.current=N,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),p();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const O of _)n.addEventListener(O,w,!0),n.addEventListener(O,x);const k=window.setTimeout(()=>{n.addEventListener("pointerdown",E)},0);return()=>{window.clearTimeout(k),n.removeEventListener("pointerdown",E),n.removeEventListener("click",m.current);for(const O of _)n.removeEventListener(O,w,!0),n.removeEventListener(O,x)}},[n,l,r,i,a,s]),{onPointerDownCapture:qn(()=>u.current=!0,"onPointerDownCapture")}}qn(Kz,"usePointerDownOutside");function qz(e,t=globalThis==null?void 0:globalThis.document){const n=Zv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=qn(a=>{a.target&&!r.current&&AS(sie,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:qn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:qn(()=>r.current=!1,"onBlurCapture")}}qn(qz,"useFocusOutside");function d1(){const e=new CustomEvent(u1);document.dispatchEvent(e)}qn(d1,"dispatchUpdate");function AS(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?Fz(i,a):i.dispatchEvent(a)}qn(AS,"handleAndDispatchCustomEvent");var die=Object.defineProperty,kS=(e,t)=>die(e,"name",{value:t,configurable:!0}),Tp=0,da=null;function fie(e){return OS(),e.children}kS(fie,"FocusGuards");function OS(){b.useEffect(()=>{da||(da={start:f1(),end:f1()});const{start:e,end:t}=da;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(da==null||da.start.remove(),da==null||da.end.remove(),da=null),Tp=Math.max(0,Tp-1)}},[])}kS(OS,"useFocusGuards");function f1(){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}kS(f1,"createFocusGuard");var hie=Object.defineProperty,mie=(e,t)=>hie(e,"name",{value:t,configurable:!0});function h1(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}mie(h1,"useCallbackRef");var pie=Object.defineProperty,xr=(e,t)=>pie(e,"name",{value:t,configurable:!0}),zx="focusScope.autoFocusOnMount",$x="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},gie=b.forwardRef(xr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...l}=t,[u,d]=b.useState(null),h=h1(a),m=h1(s),p=b.useRef(null),g=ad(n,d),w=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(i){let E=function(N){if(w.paused||!u)return;const C=N.target;u.contains(C)?p.current=C:uo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const C=N.relatedTarget;C!==null&&(u.contains(C)||uo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const T of N)T.removedNodes.length>0&&uo(u)};xr(E,"handleFocusIn"),xr(_,"handleFocusOut"),xr(k,"handleMutations"),document.addEventListener("focusin",E),document.addEventListener("focusout",_);const O=new MutationObserver(k);return u&&O.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",E),document.removeEventListener("focusout",_),O.disconnect()}}},[i,u,w.paused]),b.useEffect(()=>{if(u){HM.add(w);const E=document.activeElement;if(!u.contains(E)){const k=new CustomEvent(zx,FM);u.addEventListener(zx,h),u.dispatchEvent(k),k.defaultPrevented||(Gz(Zz(NS(u)),{select:!0}),document.activeElement===E&&uo(u))}return()=>{u.removeEventListener(zx,h),setTimeout(()=>{const k=new CustomEvent($x,FM);u.addEventListener($x,m),u.dispatchEvent(k),k.defaultPrevented||uo(E??document.body,{select:!0}),u.removeEventListener($x,m),HM.remove(w)},0)}}},[u,h,m,w]);const x=b.useCallback(E=>{if(!r&&!i||w.paused)return;const _=E.key==="Tab"&&!E.altKey&&!E.ctrlKey&&!E.metaKey,k=document.activeElement;if(_&&k){const O=E.currentTarget,[N,C]=Vz(O);N&&C?!E.shiftKey&&k===C?(E.preventDefault(),r&&uo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&uo(C,{select:!0})):k===O&&E.preventDefault()}},[r,i,w.paused]);return y.jsx(Xv.div,{tabIndex:-1,...l,ref:g,onKeyDown:x})},"FocusScope"));function Gz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(uo(r,{select:t}),document.activeElement!==n)return}xr(Gz,"focusFirst");function Vz(e){const t=NS(e),n=m1(t,e),r=m1(t.reverse(),e);return[n,r]}xr(Vz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xr(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}xr(NS,"getTabbableCandidates");function m1(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Wz(r,{upTo:t})))return r}xr(m1,"findVisible");function Wz(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}xr(Wz,"isHidden");function Yz(e){return e instanceof HTMLInputElement&&"select"in e}xr(Yz,"isSelectableInput");function uo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Yz(e)&&t&&e.select()}}xr(uo,"focus");var HM=Xz();function Xz(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=p1(e,t),e.unshift(t)},remove(t){var n;e=p1(e,t),(n=e[0])==null||n.resume()}}}xr(Xz,"createFocusScopesStack");function p1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}xr(p1,"arrayRemove");function Zz(e){return e.filter(t=>t.tagName!=="A")}xr(Zz,"removeLinks");var vie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0}),xie=ja[" useId ".trim().toString()]||(()=>{}),wie=0;function Qz(e){const[t,n]=b.useState(xie());return vie(()=>{e||n(r=>r??String(wie++))},[e]),e||(t?`radix-${t}`:"")}bie(Qz,"useId");const Eie=["top","right","bottom","left"],Fs=Math.min,xo=Math.max,Dg=Math.round,Mp=Math.floor,wo=e=>({x:e,y:e}),Sie={left:"right",right:"left",bottom:"top",top:"bottom"};function Jz(e,t,n){return xo(e,Fs(t,n))}function Co(e,t){return typeof e=="function"?e(t):e}function Hs(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function wa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(wa(e))}function _ie(e,t,n){n===void 0&&(n=!1);const r=od(e),i=MS(e),a=TS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=jg(s)),[s,jg(s)]}function Aie(e){const t=jg(e);return[g1(e),t,g1(t)]}function g1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const KM=["left","right"],qM=["right","left"],kie=["top","bottom"],Oie=["bottom","top"];function Nie(e,t,n){switch(e){case"top":case"bottom":return n?t?qM:KM:t?KM:qM;case"left":case"right":return t?kie:Oie;default:return[]}}function Cie(e,t,n,r){const i=od(e);let a=Nie(Hs(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(g1)))),a}function jg(e){const t=Hs(e);return Sie[t]+e.slice(t.length)}function Tie(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 e$(e){return typeof e!="number"?Tie(e):{top:e,right:e,bottom:e,left:e}}function Lg(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 GM(e,t,n){let{reference:r,floating:i}=e;const a=wa(t),s=MS(t),l=TS(s),u=Hs(t),d=a==="y",h=r.x+r.width/2-i.width/2,m=r.y+r.height/2-i.height/2,p=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:m};break;case"left":g={x:r.x-i.width,y:m};break;default:g={x:r.x,y:r.y}}const w=od(t);return w&&(g[s]+=p*(w==="end"?1:-1)*(n&&d?-1:1)),g}async function Mie(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:m="floating",altBoundary:p=!1,padding:g=0}=Co(t,e),w=e$(g),E=l[p?m==="floating"?"reference":"floating":m],_=Lg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(E)))==null||n?E:E.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=m==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,O=await(a.getOffsetParent==null?void 0:a.getOffsetParent(l.floating)),N=await(a.isElement==null?void 0:a.isElement(O))&&await(a.getScale==null?void 0:a.getScale(O))||{x:1,y:1},C=Lg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:O,strategy:u}):k);return{top:(_.top-C.top+w.top)/N.y,bottom:(C.bottom-_.bottom+w.bottom)/N.y,left:(_.left-C.left+w.left)/N.x,right:(C.right-_.right+w.right)/N.x}}const Iie=50,Rie=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,l=s.detectOverflow?s:{...s,detectOverflow:Mie},u=await(s.isRTL==null?void 0:s.isRTL(t));let d=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:m}=GM(d,r,u),p=r,g=0;const w={};for(let x=0;x<a.length;x++){const E=a[x];if(!E)continue;const{name:_,fn:k}=E,{x:O,y:N,data:C,reset:T}=await k({x:h,y:m,initialPlacement:r,placement:p,strategy:i,middlewareData:w,rects:d,platform:l,elements:{reference:e,floating:t}});h=O??h,m=N??m,w[_]={...w[_],...C},T&&g<Iie&&(g++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(d=T.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:m}=GM(d,p,u)),x=-1)}return{x:h,y:m,placement:p,strategy:i,middlewareData:w}},Pie=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=Co(e,t)||{};if(d==null)return{};const m=e$(h),p={x:n,y:r},g=MS(i),w=TS(g),x=await s.getDimensions(d),E=g==="y",_=E?"top":"left",k=E?"bottom":"right",O=E?"clientHeight":"clientWidth",N=a.reference[w]+a.reference[g]-p[g]-a.floating[w],C=p[g]-a.reference[g],T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(d));let M=T?T[O]:0;(!M||!await(s.isElement==null?void 0:s.isElement(T)))&&(M=l.floating[O]||a.floating[w]);const D=N/2-C/2,j=M/2-x[w]/2-1,R=Fs(m[_],j),H=Fs(m[k],j),P=M-x[w]-H,G=M/2-x[w]/2+D,q=Jz(R,G,P),X=!u.arrow&&od(i)!=null&&G!==q&&a.reference[w]/2-(G<R?R:H)-x[w]/2<0,U=X?G<R?G-R:G-P:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...X&&{alignmentOffset:U}},reset:X}}}),Die=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:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:m=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...E}=Co(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Hs(i),k=wa(l),O=Hs(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),C=p||(O||!x?[jg(l)]:Aie(l)),T=w!=="none";!p&&T&&C.push(...Cie(l,x,w,N));const M=[l,...C],D=await u.detectOverflow(t,E),j=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&j.push(D[_]),m){const q=_ie(i,s,N);j.push(D[q[0]],D[q[1]])}if(R=[...R,{placement:i,overflows:j}],!j.every(q=>q<=0)){var H,P;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,X=M[q];if(X&&(!(m==="alignment"?k!==wa(X):!1)||R.every(F=>wa(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:R},reset:{placement:X}};let U=(P=R.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=R.filter(F=>{if(T){const V=wa(F.placement);return V===k||V==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(V=>V>0).reduce((V,$)=>V+$,0)]).sort((F,V)=>F[1]-V[1])[0])==null?void 0:G[0];K&&(U=K);break}case"initialPlacement":U=l;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function VM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WM(e){return Eie.some(t=>e[t]>=0)}const jie=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=Co(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),l=VM(s,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:WM(l)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),l=VM(s,n.floating);return{data:{escapedOffsets:l,escaped:WM(l)}}}default:return{}}}}},t$=new Set(["left","top"]);async function Lie(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Hs(n),l=od(n),u=wa(n)==="y",d=t$.has(s)?-1:1,h=a&&u?-1:1,m=Co(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:w}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return l&&typeof w=="number"&&(g=l==="end"?w*-1:w),u?{x:g*h,y:p*d}:{x:p*d,y:g*h}}const zie=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:l}=t,u=await Lie(t,e);return s===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},$ie=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:l=!1,limiter:u={fn:k=>{let{x:O,y:N}=k;return{x:O,y:N}}},...d}=Co(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=wa(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Jz(O+m[k==="y"?"top":"left"],O,O-m[k==="y"?"bottom":"right"]);s&&(w=E(g,w)),l&&(x=E(p,x));const _=u.fn({...t,[g]:w,[p]:x});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[g]:s,[p]:l}}}}}},Bie=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:l,middlewareData:u}=t,{offset:d=0,mainAxis:h=!0,crossAxis:m=!0}=Co(e,t),p={x:i,y:a},g=wa(s),w=CS(g);let x=p[w],E=p[g];const _=Co(d,t),k=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const C=w==="y"?"height":"width",T=l.reference[w]-l.floating[C]+k.mainAxis,M=l.reference[w]+l.reference[C]-k.mainAxis;x<T?x=T:x>M&&(x=M)}if(m){var O,N;const C=w==="y"?"width":"height",T=t$.has(Hs(s)),M=l.reference[g]-l.floating[C]+(T&&((O=u.offset)==null?void 0:O[g])||0)+(T?0:k.crossAxis),D=l.reference[g]+l.reference[C]+(T?0:((N=u.offset)==null?void 0:N[g])||0)-(T?k.crossAxis:0);E<M?E=M:E>D&&(E=D)}return{[w]:x,[g]:E}}}},Uie=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=()=>{},...l}=Co(e,t),u=await i.detectOverflow(t,l),d=Hs(n),h=od(n),m=wa(n)==="y",{width:p,height:g}=r.floating;let w,x;d==="top"||d==="bottom"?(w=d,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=d,w=h==="end"?"top":"bottom");const E=g-u.top-u.bottom,_=p-u.left-u.right,k=Fs(g-u[w],E),O=Fs(p-u[x],_),N=t.middlewareData.shift,C=!N;let T=k,M=O;N!=null&&N.enabled.x&&(M=_),N!=null&&N.enabled.y&&(T=E),C&&!h&&(m?M=p-2*xo(u.left,u.right):T=g-2*xo(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:T});const D=await i.getDimensions(a.floating);return p!==D.width||g!==D.height?{reset:{rects:!0}}:{}}}};function Qv(){return typeof window<"u"}function sd(e){return n$(e)?(e.nodeName||"").toLowerCase():"#document"}function Ur(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(n$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n$(e){return Qv()?e instanceof Node||e instanceof Ur(e).Node:!1}function Ca(e){return Qv()?e instanceof Element||e instanceof Ur(e).Element:!1}function Js(e){return Qv()?e instanceof HTMLElement||e instanceof Ur(e).HTMLElement:!1}function YM(e){return!Qv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ur(e).ShadowRoot}function Jv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ta(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fie(e){return/^(table|td|th)$/.test(sd(e))}function ey(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Hie=/transform|translate|scale|rotate|perspective|filter/,Kie=/paint|layout|strict|content/,Al=e=>!!e&&e!=="none";let Bx;function IS(e){const t=Ca(e)?Ta(e):e;return Al(t.transform)||Al(t.translate)||Al(t.scale)||Al(t.rotate)||Al(t.perspective)||!RS()&&(Al(t.backdropFilter)||Al(t.filter))||Hie.test(t.willChange||"")||Kie.test(t.contain||"")}function qie(e){let t=ec(e);for(;Js(t)&&!nh(t);){if(IS(t))return t;if(ey(t))return null;t=ec(t)}return null}function RS(){return Bx==null&&(Bx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Bx}function nh(e){return/^(html|body|#document)$/.test(sd(e))}function Ta(e){return Ur(e).getComputedStyle(e)}function ty(e){return Ca(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ec(e){if(sd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||jo(e);return YM(t)?t.host:t}function r$(e){const t=ec(e);return nh(t)?(e.ownerDocument||e).body:Js(t)&&Jv(t)?t:r$(t)}function rh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Ur(i);if(a){const l=v1(s);return t.concat(s,s.visualViewport||[],Jv(i)?i:[],l&&n?rh(l):[])}else return t.concat(i,rh(i,[],n))}function v1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i$(e){const t=Ta(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Js(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,l=Dg(n)!==a||Dg(r)!==s;return l&&(n=a,r=s),{width:n,height:r,$:l}}function PS(e){return Ca(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Js(t))return wo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=i$(t);let s=(a?Dg(n.width):n.width)/r,l=(a?Dg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}const Gie=wo(0);function a$(e){const t=Ur(e);return!RS()||!t.visualViewport?Gie:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Vie(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ur(e)}function tc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=wo(1);t&&(r?Ca(r)&&(s=Tu(r)):s=Tu(e));const l=Vie(a,n,r)?a$(a):wo(0);let u=(i.left+l.x)/s.x,d=(i.top+l.y)/s.y,h=i.width/s.x,m=i.height/s.y;if(a&&r){const p=Ur(a),g=Ca(r)?Ur(r):r;let w=p,x=v1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=Ta(x),O=_.left+(x.clientLeft+parseFloat(k.paddingLeft))*E.x,N=_.top+(x.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,m*=E.y,u+=O,d+=N,w=Ur(x),x=v1(w)}}return Lg({width:h,height:m,x:u,y:d})}function ny(e,t){const n=ty(e).scrollLeft;return t?t.left+n:tc(jo(e)).left+n}function o$(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ny(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Wie(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=jo(r),l=t?ey(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=wo(1);const h=wo(0),m=Js(r);if((m||!a)&&((sd(r)!=="body"||Jv(s))&&(u=ty(r)),m)){const g=tc(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?o$(s,u):wo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-u.scrollTop*d.y+h.y+p.y}}function Yie(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Xie(e){const t=ty(e),n=e.ownerDocument.body,r=xo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=xo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ny(e);const s=-t.scrollTop;return Ta(n).direction==="rtl"&&(a+=xo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Zie=25;function Qie(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Ur(e),a=jo(e),s=i.visualViewport;let l=a.clientWidth,u=a.clientHeight,d=0,h=0;if(s){const p=!RS()||t==="fixed";r?p||(d=-s.offsetLeft,h=-s.offsetTop):(l=s.width,u=s.height,p&&(d=s.offsetLeft,h=s.offsetTop))}if(ny(a)<=0){const p=a.ownerDocument,g=p.body,w=getComputedStyle(g),x=p.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,E=Math.abs(a.clientWidth-g.clientWidth-x),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?E/2:E;_<=Zie&&(l-=_)}return{width:l,height:u,x:d,y:h}}function Jie(e,t){const n=tc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Tu(e),s=e.clientWidth*a.x,l=e.clientHeight*a.y,u=i*a.x,d=r*a.y;return{width:s,height:l,x:u,y:d}}function XM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Qie(e,n,t);else if(t==="document")r=Xie(jo(e));else if(Ca(t))r=Jie(t,n);else{const i=a$(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Lg(r)}function eae(e,t){const n=t.get(e);if(n)return n;let r=rh(e,[],!1).filter(l=>Ca(l)&&sd(l)!=="body"),i=null;const a=Ta(e).position==="fixed";let s=a?ec(e):e;for(;Ca(s)&&!nh(s);){const l=Ta(s),u=IS(s),d=i?i.position:a?"fixed":"";!u&&(d==="fixed"||d==="absolute"&&l.position==="static")?r=r.filter(m=>m!==s):i=l,s=ec(s)}return t.set(e,r),r}function tae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?ey(t)?[]:eae(t,this._c):[].concat(n),r],l=XM(t,s[0],i);let u=l.top,d=l.right,h=l.bottom,m=l.left;for(let p=1;p<s.length;p++){const g=XM(t,s[p],i);u=xo(g.top,u),d=Fs(g.right,d),h=Fs(g.bottom,h),m=xo(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function nae(e){const{width:t,height:n}=i$(e);return{width:t,height:n}}function rae(e,t,n){const r=Js(t),i=jo(t),a=n==="fixed",s=tc(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=wo(0);if((r||!a)&&((sd(t)!=="body"||Jv(i))&&(l=ty(t)),r)){const p=tc(t,!0,a,t);u.x=p.x+t.clientLeft,u.y=p.y+t.clientTop}!r&&i&&(u.x=ny(i));const d=i&&!r&&!a?o$(i,l):wo(0),h=s.left+l.scrollLeft-u.x-d.x,m=s.top+l.scrollTop-u.y-d.y;return{x:h,y:m,width:s.width,height:s.height}}function Ux(e){return Ta(e).position==="static"}function ZM(e,t){if(!Js(e)||Ta(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function s$(e,t){const n=Ur(e);if(ey(e))return n;if(!Js(e)){let i=ec(e);for(;i&&!nh(i);){if(Ca(i)&&!Ux(i))return i;i=ec(i)}return n}let r=ZM(e,t);for(;r&&Fie(r)&&Ux(r);)r=ZM(r,t);return r&&nh(r)&&Ux(r)&&!IS(r)?n:r||qie(e)||n}const iae=async function(e){const t=this.getOffsetParent||s$,n=this.getDimensions,r=await n(e.floating);return{reference:rae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function aae(e){return Ta(e).direction==="rtl"}const oae={convertOffsetParentRelativeRectToViewportRelativeRect:Wie,getDocumentElement:jo,getClippingRect:tae,getOffsetParent:s$,getElementRects:iae,getClientRects:Yie,getDimensions:nae,getScale:Tu,isElement:Ca,isRTL:aae};function l$(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function sae(e,t,n){let r=null,i;const a=jo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function l(h,m){h===void 0&&(h=!1),m===void 0&&(m=1),s();const p=e.getBoundingClientRect(),{left:g,top:w,width:x,height:E}=p;if(h||t(),!x||!E)return;const _=Mp(w),k=Mp(a.clientWidth-(g+x)),O=Mp(a.clientHeight-(w+E)),N=Mp(g),T={rootMargin:-_+"px "+-k+"px "+-O+"px "+-N+"px",threshold:xo(0,Fs(1,m))||1};let M=!0;function D(j){const R=j[0].intersectionRatio;if(!l$(p,e.getBoundingClientRect()))return l();if(R!==m){if(!M)return l();R?l(!1,R):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(D,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,T)}r.observe(e)}const u=Ur(e),d=()=>l(n);return u.addEventListener("resize",d),l(!0),()=>{u.removeEventListener("resize",d),s()}}function lae(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=PS(e),h=i||a?[...d?rh(d):[],...t?rh(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const m=d&&l?sae(d,n,a):null;let p=-1,g=null;s&&(g=new ResizeObserver(_=>{let[k]=_;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var O;(O=g)==null||O.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let w,x=u?tc(e):null;u&&E();function E(){const _=tc(e);x&&!l$(x,_)&&n(),x=_,w=requestAnimationFrame(E)}return n(),()=>{var _;h.forEach(k=>{i&&k.removeEventListener("scroll",n),a&&k.removeEventListener("resize",n)}),m==null||m(),(_=g)==null||_.disconnect(),g=null,u&&cancelAnimationFrame(w)}}const cae=zie,uae=$ie,dae=Die,fae=Uie,hae=jie,QM=Pie,mae=Bie,pae=(e,t,n)=>{const r=new Map,i=n??{},a={...oae,...i.platform,_c:r};return Rie(e,t,{...i,platform:a})};var gae=typeof document<"u",vae=function(){},og=gae?b.useLayoutEffect:vae;function zg(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(!zg(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)&&!zg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function c$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=c$(e);return Math.round(t*n)/n}function Fx(e){const t=b.useRef(e);return og(()=>{t.current=e}),t}function yae(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,m]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=b.useState(r);zg(p,r)||g(r);const[w,x]=b.useState(null),[E,_]=b.useState(null),k=b.useCallback(F=>{F!==T.current&&(T.current=F,x(F))},[]),O=b.useCallback(F=>{F!==M.current&&(M.current=F,_(F))},[]),N=a||w,C=s||E,T=b.useRef(null),M=b.useRef(null),D=b.useRef(h),j=u!=null,R=Fx(u),H=Fx(i),P=Fx(d),G=b.useCallback(()=>{if(!T.current||!M.current)return;const F={placement:t,strategy:n,middleware:p};H.current&&(F.platform=H.current),pae(T.current,M.current,F).then(V=>{const $={...V,isPositioned:P.current!==!1};q.current&&!zg(D.current,$)&&(D.current=$,La.flushSync(()=>{m($)}))})},[p,t,n,H,P]);og(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,m(F=>({...F,isPositioned:!1})))},[d]);const q=b.useRef(!1);og(()=>(q.current=!0,()=>{q.current=!1}),[]),og(()=>{if(N&&(T.current=N),C&&(M.current=C),N&&C){if(R.current)return R.current(N,C,G);G()}},[N,C,G,R,j]);const X=b.useMemo(()=>({reference:T,floating:M,setReference:k,setFloating:O}),[k,O]),U=b.useMemo(()=>({reference:N,floating:C}),[N,C]),K=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!U.floating)return F;const V=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+V+"px, "+$+"px)",...c$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:X,elements:U,floatingStyles:K}),[h,G,X,U,K])}const bae=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?QM({element:r.current,padding:i}).fn(n):{}:r?QM({element:r,padding:i}).fn(n):{}}}},xae=(e,t)=>{const n=cae(e);return{name:n.name,fn:n.fn,options:[e,t]}},wae=(e,t)=>{const n=uae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eae=(e,t)=>({fn:mae(e).fn,options:[e,t]}),Sae=(e,t)=>{const n=dae(e);return{name:n.name,fn:n.fn,options:[e,t]}},_ae=(e,t)=>{const n=fae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aae=(e,t)=>{const n=hae(e);return{name:n.name,fn:n.fn,options:[e,t]}},kae=(e,t)=>{const n=bae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Oae=Object.defineProperty,DS=(e,t)=>Oae(e,"name",{value:t,configurable:!0});function y1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}DS(y1,"setRef");function u$(...e){return t=>{let n=!1;const r=e.map(i=>{const a=y1(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():y1(e[i],null)}}}}DS(u$,"composeRefs");function ry(...e){return b.useCallback(u$(...e),e)}DS(ry,"useComposedRefs");var Nae=Object.defineProperty,Ci=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function Cae(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ci(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ci(i,"useContext"),[r,i]}Ci(Cae,"createContext");function d$(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ci(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ci(h,"useContext"),[d,h]}Ci(r,"createContext");const i=Ci(()=>{const a=n.map(s=>b.createContext(s));return Ci(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,f$(i,...t)]}Ci(d$,"createContextScope");function f$(...e){const t=e[0];if(e.length===1)return t;const n=Ci(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ci(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ci(f$,"composeContextScopes");var Tae=Object.defineProperty,ta=(e,t)=>Tae(e,"name",{value:t,configurable:!0});function h$(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];b1(i)&&typeof Ip=="function"&&(i=Ip(i._payload)),b.Children.forEach(i,p=>{var g;if(v$(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;b1(x)&&typeof Ip=="function"&&(x=Ip(x._payload)),s=Iae(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?g$(s):void 0,h=ry(r,d);if(!s){if(i||i===0)throw new Error(l?Dae(e):Pae(e));return i}const m=p$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ta(h$,"createSlot");var m$=Symbol.for("radix.slottable");function Mae(e){const t=ta(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=m$,t}ta(Mae,"createSlottable");var Iae=ta((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function p$(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ta(p$,"mergeProps");function g$(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)}ta(g$,"getElementRef");function v$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===m$}ta(v$,"isSlottable");var Rae=Symbol.for("react.lazy");function b1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Rae&&"_payload"in e&&y$(e._payload)}ta(b1,"isLazyComponent");function y$(e){return typeof e=="object"&&e!==null&&"then"in e}ta(y$,"isPromiseLike");var Pae=ta(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Dae=ta(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=ja[" use ".trim().toString()],jae=Object.defineProperty,Lae=(e,t)=>jae(e,"name",{value:t,configurable:!0}),zae=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],b$=zae.reduce((e,t)=>{const n=h$(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $ae(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}Lae($ae,"dispatchDiscreteCustomEvent");var Bae=Object.defineProperty,Uae=(e,t)=>Bae(e,"name",{value:t,configurable:!0});function x$(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Uae(x$,"useCallbackRef");var Hx=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Fae=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Hae=Object.defineProperty,Kae=(e,t)=>Hae(e,"name",{value:t,configurable:!0});function w$(e){const[t,n]=b.useState(void 0);return Fae(()=>{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,l;if("borderBoxSize"in a){const u=a.borderBoxSize,d=Array.isArray(u)?u[0]:u;s=d.inlineSize,l=d.blockSize}else s=e.offsetWidth,l=e.offsetHeight;n({width:s,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Kae(w$,"useSize");var qae=Object.defineProperty,js=(e,t)=>qae(e,"name",{value:t,configurable:!0}),E$="Popper",[S$,_$]=d$(E$),[Gae,A$]=S$(E$),Vae=js(e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null),[a,s]=b.useState(void 0);return y.jsx(Gae,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),Wae="PopperAnchor",Yae=b.forwardRef(js(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=A$(Wae,r),l=b.useRef(null),u=s.onAnchorChange,d=b.useCallback(x=>{l.current=x,x&&u(x)},[u]),h=ry(n,d),m=b.useRef(null);b.useEffect(()=>{if(!i)return;const x=m.current;m.current=i.current,x!==m.current&&u(m.current)});const p=s.placementState&&iy(s.placementState),g=p==null?void 0:p[0],w=p==null?void 0:p[1];return i?null:y.jsx(b$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),k$="PopperContent",[Xae,cCe]=S$(k$),Zae=b.forwardRef(js(function(t,n){var fe,Ee,Te,de,nt,He,Ae;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:m=0,sticky:p="partial",hideWhenDetached:g=!1,updatePositionStrategy:w="optimized",onPlaced:x,...E}=t,_=A$(k$,r),[k,O]=b.useState(null),N=ry(n,O),[C,T]=b.useState(null),M=w$(C),D=(M==null?void 0:M.width)??0,j=(M==null?void 0:M.height)??0,R=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},P=Array.isArray(h)?h:[h],G=P.length>0,q={padding:H,boundary:P.filter(O$),altBoundary:G},{refs:X,floatingStyles:U,placement:K,isPositioned:F,middlewareData:V}=yae({strategy:"fixed",placement:R,whileElementsMounted:js((...De)=>lae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[xae({mainAxis:a+j,alignmentAxis:l}),d&&wae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Eae():void 0,...q}),d&&Sae({...q}),_ae({...q,apply:js(({elements:De,rects:Ht,availableWidth:un,availableHeight:Yn})=>{const{width:Or,height:ji}=Ht.reference,ir=De.floating.style;ir.setProperty("--radix-popper-available-width",`${un}px`),ir.setProperty("--radix-popper-available-height",`${Yn}px`),ir.setProperty("--radix-popper-anchor-width",`${Or}px`),ir.setProperty("--radix-popper-anchor-height",`${ji}px`)},"apply")}),C&&kae({element:C,padding:u}),Qae({arrowWidth:D,arrowHeight:j}),g&&Aae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Hx(()=>($(K),()=>{$(void 0)}),[K,$]);const[L,W]=iy(K),z=x$(x);Hx(()=>{F&&(z==null||z())},[F,z]);const ie=(fe=V.arrow)==null?void 0:fe.x,he=(Ee=V.arrow)==null?void 0:Ee.y,ge=((Te=V.arrow)==null?void 0:Te.centerOffset)!==0,[Se,ze]=b.useState();return Hx(()=>{k&&ze(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:X.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Se,"--radix-popper-transform-origin":[(de=V.transformOrigin)==null?void 0:de.x,(nt=V.transformOrigin)==null?void 0:nt.y].join(" "),...((He=V.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Xae,{scope:r,placedSide:L,placedAlign:W,onArrowChange:T,arrowX:ie,arrowY:he,shouldHideArrow:ge,children:y.jsx(b$.div,{"data-side":L,"data-align":W,...E,ref:N,style:{...E.style,animation:F?(Ae=E.style)==null?void 0:Ae.animation:"none"}})})})},"PopperContent"));function O$(e){return e!==null}js(O$,"isNotNull");var Qae=js(e=>({name:"transformOrigin",options:e,fn(t){var E,_,k;const{placement:n,rects:r,middlewareData:i}=t,s=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[d,h]=iy(n),m={start:"0%",center:"50%",end:"100%"}[h],p=(((_=i.arrow)==null?void 0:_.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let w="",x="";return d==="bottom"?(w=s?m:`${p}px`,x=`${-u}px`):d==="top"?(w=s?m:`${p}px`,x=`${r.floating.height+u}px`):d==="right"?(w=`${-u}px`,x=s?m:`${g}px`):d==="left"&&(w=`${r.floating.width+u}px`,x=s?m:`${g}px`),{data:{x:w,y:x}}}}),"transformOrigin");function iy(e){const[t,n="center"]=e.split("-");return[t,n]}js(iy,"getSideAndAlignFromPlacement");var Jae=Vae,eoe=Yae,toe=Zae,noe=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},roe=Object.defineProperty,ioe=(e,t)=>roe(e,"name",{value:t,configurable:!0}),aoe=b.forwardRef(ioe(function(t,n){var u;const{container:r,...i}=t,[a,s]=b.useState(!1);noe(()=>s(!0),[]);const l=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return l?La.createPortal(y.jsx(Xv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ooe=Object.defineProperty,To=(e,t)=>ooe(e,"name",{value:t,configurable:!0});function N$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}To(N$,"useStateMachine");var C$=To(e=>{const{present:t,children:n}=e,r=T$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=M$(r.ref,I$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function T$(e){const[t,n]=b.useState(),r=b.useRef(null),i=b.useRef(e),a=b.useRef("none"),s=b.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=N$(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{u==="mounted"?(a.current=s.current??bu(r.current),s.current=void 0):a.current="none"},[u]),eI(()=>{const h=r.current,m=i.current;if(m!==e){const g=a.current,w=bu(h);e?(s.current=w,d("MOUNT")):w==="none"||(h==null?void 0:h.display)==="none"?d("UNMOUNT"):d(m&&g!==w?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,d]),eI(()=>{if(t){let h;const m=t.ownerDocument.defaultView??window,p=To(w=>{const E=bu(r.current).includes(CSS.escape(w.animationName));if(w.target===t&&E&&(d("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),g=To(w=>{w.target===t&&(a.current=bu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{m.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:b.useCallback(h=>{if(h){const m=getComputedStyle(h);r.current=m,s.current=bu(m)}else r.current=null;n(h)},[])}}To(T$,"usePresence");function x1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}To(x1,"setRef");function M$(...e){const t=b.useRef(e);return t.current=e,b.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const l=x1(s,n);return!i&&typeof l=="function"&&(i=!0),l});if(i)return()=>{for(let s=0;s<a.length;s++){const l=a[s];typeof l=="function"?l():x1(r[s],null)}}},[])}To(M$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}To(bu,"getAnimationName");function I$(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)}To(I$,"getElementRef");var R$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,loe=(e,t)=>soe(e,"name",{value:t,configurable:!0}),tI=ja[" useEffectEvent ".trim().toString()],nI=ja[" useInsertionEffect ".trim().toString()];function P$(e){if(typeof tI=="function")return tI(e);const t=b.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof nI=="function"?nI(()=>{t.current=e}):R$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}loe(P$,"useEffectEvent");var coe=Object.defineProperty,Nh=(e,t)=>coe(e,"name",{value:t,configurable:!0}),uoe=ja[" useInsertionEffect ".trim().toString()]||R$;function D$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=j$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=L$(h)?h(e):h;p!==e&&((m=s.current)==null||m.call(s,p))}else a(h)},[l,e,a,s]);return[u,d]}Nh(D$,"useControllableState");function j$({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),i=b.useRef(n),a=b.useRef(t);return uoe(()=>{a.current=t},[t]),b.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}Nh(j$,"useUncontrolledState");function L$(e){return typeof e=="function"}Nh(L$,"isFunction");var rI=Symbol("RADIX:SYNC_STATE");function doe(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:l}=t,u=i!==void 0,d=P$(s),h=[{...n,state:a}];r&&h.push(r);const[m,p]=b.useReducer((E,_)=>{if(_.type===rI)return{...E,state:_.state};const k=e(E,_);return u&&!Object.is(k.state,E.state)&&d(k.state),k},...h),g=m.state,w=b.useRef(g);b.useEffect(()=>{w.current!==g&&(w.current=g,u||d(g))},[g,w,u]);const x=b.useMemo(()=>i!==void 0?{...m,state:i}:m,[m,i]);return b.useEffect(()=>{u&&!Object.is(i,m.state)&&p({type:rI,state:i})},[i,m.state,u]),[x,p]}Nh(doe,"useControllableStateReducer");var foe=Object.defineProperty,el=(e,t)=>foe(e,"name",{value:t,configurable:!0}),jS="Popover",[z$,uCe]=Dz(jS,[_$]),LS=_$(),[hoe,ld]=z$(jS),moe=el(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,l=LS(t),u=b.useRef(null),[d,h]=b.useState(!1),[m,p]=D$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(Jae,{...l,children:y.jsx(hoe,{scope:t,contentId:Qz(),triggerRef:u,open:m,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(g=>!g),[p]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),poe="PopoverTrigger",goe=b.forwardRef(el(function(t,n){const{__scopePopover:r,...i}=t,a=ld(poe,r),s=LS(r),l=ad(n,a.triggerRef),u=y.jsx(Xv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":zS(a.open),...i,ref:l,onClick:Ds(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(eoe,{asChild:!0,...s,children:u})},"PopoverTrigger")),$$="PopoverPortal",[voe,yoe]=z$($$,{forceMount:void 0}),boe=el(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=ld($$,t);return y.jsx(voe,{scope:t,forceMount:n,children:y.jsx(C$,{present:n||a.open,children:y.jsx(aoe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),ih="PopoverContent",xoe=b.forwardRef(el(function(t,n){const r=yoe(ih,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=ld(ih,t.__scopePopover);return y.jsx(C$,{present:i||s.open,children:s.modal?y.jsx(Eoe,{...a,ref:n}):y.jsx(Soe,{...a,ref:n})})},"PopoverContent")),woe=_S("PopoverContent.RemoveScroll"),Eoe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(null),a=ad(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return gz(l)},[]),y.jsx(vS,{as:woe,allowPinchZoom:!0,children:y.jsx(B$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ds(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Ds(t.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:Ds(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),Soe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx(B$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var l,u;(l=t.onCloseAutoFocus)==null||l.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 d,h;(d=t.onInteractOutside)==null||d.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const l=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),B$=b.forwardRef(el(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,...p}=t,g=ld(ih,r),w=LS(r);return OS(),y.jsx(gie,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:y.jsx(lie,{asChild:!0,disableOutsidePointerEvents:l,onInteractOutside:m,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onDismiss:()=>g.onOpenChange(!1),deferPointerDownOutside:!0,children:y.jsx(toe,{"data-state":zS(g.open),role:"dialog",id:g.contentId,...w,...p,ref:n,style:{...p.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 zS(e){return e?"open":"closed"}el(zS,"getState");var _oe=moe,Aoe=goe,koe=boe,U$=xoe;const Ooe=_oe,Noe=Aoe,F$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(koe,{children:y.jsx(U$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:Be("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})}));F$.displayName=U$.displayName;const H$=92,K$=96;function Kx(e){if(!Number.isFinite(e)||e<0)return"?";const t=["B","KB","MB","GB","TB","PB"];let n=0;for(;e>=1024&&n<t.length-1;)e/=1024,n++;return`${e<10&&n>0?e.toFixed(1):Math.round(e)} ${t[n]}`}const iI=3e5;function Coe({socket:e,getToken:t}){const[n,r]=b.useState([]);if(b.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]),b.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(l=>[...l,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return y.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:[y.jsx(sg,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),y.jsx(sg,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&y.jsx(sg,{label:"disk",value:i.disk,severity:Loe(i.disk),title:$oe(i)}),y.jsx(Toe,{getToken:t})]})}function Toe({getToken:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!0,i=0;const a=async()=>{var d;try{const h=await e();if(!h)return;i=Date.now();const m=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(m.status===204){n(null);return}if(m.status!==200)return;const p=await m.json();if(!r||!((d=p==null?void 0:p.limits)!=null&&d.length))return;n(p)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},l=()=>{document.visibilityState==="visible"&&Date.now()-i>=iI&&a()};s();const u=setInterval(s,iI);return document.addEventListener("visibilitychange",l),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",l)}},[e]),y.jsx(Moe,{usage:t})}function Moe({usage:e}){const t=e&&q$(e.limits),[n,r]=b.useState(w1),i=b.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=b.useCallback((l,u=0)=>{if(a(),!u){r(d=>oI(d,l));return}i.current=setTimeout(()=>{i.current=null,r(d=>oI(d,l))},u)},[]);return b.useEffect(()=>a,[]),!e||!t?null:y.jsxs(Ooe,{open:n.open,onOpenChange:l=>s(l?{type:"activate"}:{type:"dismiss"}),children:[y.jsx(Noe,{asChild:!0,children:y.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:l=>s({type:"pointerenter",pointerType:l.pointerType},Ioe),onPointerLeave:l=>s({type:"pointerleave",pointerType:l.pointerType},aI),children:y.jsx(sg,{label:"usage",value:t.percent,severity:t.severity})})}),y.jsx(F$,{onOpenAutoFocus:l=>l.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:l=>s({type:"pointerleave",pointerType:l.pointerType},aI),children:y.jsx(Roe,{usage:e})})]})}const Ioe=120,aI=80,w1={open:!1,byHover:!1};function oI(e,t){switch(t.type){case"pointerenter":return sI(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return sI(t.pointerType)&&e.byHover?w1:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return w1}}const sI=e=>e==="mouse"||e==="";function Roe({usage:e}){const t=q$(e.limits);return y.jsxs("div",{className:"text-[11px] leading-tight",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[y.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&y.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),y.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&y.jsx("span",{className:"truncate",title:e.account,children:e.account}),y.jsx("span",{className:Be("shrink-0",e.stale&&"text-amber-500"),children:Doe(e)})]}),e.stale&&e.error&&y.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,ag(e.retryAt??null)&&` · retrying in ${ag(e.retryAt??null)}`]}),y.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=ag(n.resetsAt),a=n===t;return y.jsxs("div",{"data-headline":a||void 0,className:Be("flex flex-col gap-1",!a&&"opacity-60"),children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsxs("span",{className:Be("truncate",a&&"font-medium"),children:[a&&y.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Poe(n)]}),y.jsxs("span",{className:Be("tabular-nums shrink-0",E1(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(G$,{value:n.percent,className:Be("w-full",E1(n.percent,n.severity))}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),y.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Poe(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function q$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Doe(e){const t=joe(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function joe(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 Loe(e){return e>=K$?"critical":e>=H$?"warning":"ok"}const zoe={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function E1(e,t){const n=t?zoe[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function $oe(e){const t=`warn at ${H$}%, critical at ${K$}%`;if(e.diskUsedBytes==null||e.diskTotalBytes==null)return`disk ${e.disk}% used — ${t}`;const n=Math.max(0,e.diskTotalBytes-e.diskUsedBytes);return`disk ${e.disk}% used — ${Kx(e.diskUsedBytes)} of ${Kx(e.diskTotalBytes)}, ${Kx(n)} free — ${t}`}function sg({label:e,value:t,series:n,title:r,severity:i}){const a=E1(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return y.jsxs("span",{className:"flex items-center gap-1",title:s,children:[y.jsx("span",{className:"uppercase tracking-wide",children:e}),n?y.jsx(Boe,{series:n,className:a}):y.jsx(G$,{value:t,className:a}),y.jsxs("span",{className:Be("tabular-nums",a),children:[t,"%"]})]})}function G$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return y.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Be("overflow-visible",t),preserveAspectRatio:"none",children:[y.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&y.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Boe({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,l)=>{const u=i>1?l/(i-1)*40:0,d=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${d.toFixed(1)}`}).join(" ");return y.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Be("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const kf=50;function Uoe({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=b.useState([]),[s,l]=b.useState(null),[u,d]=b.useState(!1),[h,m]=b.useState({}),p=b.useRef(new Set),g=b.useRef(null),w=b.useRef(null),x=b.useRef(t);x.current=t;const E=b.useRef(kf),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=kf);const k=b.useCallback(async(M,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const R=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!R.ok)return null;const H=await R.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,D,j)=>{const R=[];let H,P=null;for(;R.length<M;){const G={filter:D,limit:String(Math.min(kf,M-R.length))};H&&(G.before=H);const q=await k(G,j);if(!q)return null;if(R.push(...q.sessions),P=q.nextCursor,!P||!q.sessions.length)break;H=P}return{sessions:R,nextCursor:P}},[k]);b.useEffect(()=>{var D,j;(D=g.current)==null||D.abort(),(j=w.current)==null||j.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(R=>{!R||M.signal.aborted||(a(R.sessions),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var j;if(!s||u)return;(j=w.current)==null||j.abort();const M=new AbortController;w.current=M;const D=x.current;d(!0),k({filter:D,limit:String(kf),before:s},M.signal).then(R=>{!R||M.signal.aborted||D!==x.current||(a(H=>{const P=new Set(H.map(q=>q.sessionId)),G=[...H,...R.sessions.filter(q=>!P.has(q.sessionId))];return E.current=Math.max(kf,G.length),G}),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),C=b.useMemo(()=>{const M=new Map;for(const D of Object.values(h))M.set(D.sessionId,D);for(const D of i)M.set(D.sessionId,D);return M},[i,h]),T=r.join(",");return b.useEffect(()=>{const M=r.filter(j=>!!j&&!C.has(j)&&!p.current.has(j)).slice(0,200);if(!M.length)return;for(const j of M)p.current.add(j);let D=!1;return k({ids:M.join(",")}).then(j=>{!j||D||m(R=>{const H={...R};for(const P of j.sessions)H[P.sessionId]=P;return H})}).catch(()=>{}),()=>{D=!0}},[T,C,k]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:N}}const Of="0.1.120";function Foe(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 Nf="w-4 h-4 mt-0.5 shrink-0";function Hoe(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(iV,{className:`${Nf} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(KG,{className:`${Nf} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(JG,{className:`${Nf} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Gw,{className:`${Nf} text-yellow-400`}):y.jsx(Gw,{className:`${Nf} text-muted-foreground`})}function Koe(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}function qoe(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const lI="chats-filter",cI="chats-unread-filter";function Goe({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var F;const h=za(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),_=b.useRef(null);function k(V){p(V),localStorage.setItem(lI,V)}function O(){const V=!g;w(V),localStorage.setItem(cI,String(V))}const N=b.useMemo(()=>[t,...Object.keys(l)].filter(V=>!!V),[t,l]),{sessions:C,cursor:T,loading:M,byId:D,loadMore:j}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:N}),R=b.useMemo(()=>qoe(l,D,m),[l,D,m]),H=R.length,P=b.useMemo(()=>g?[...R].sort((V,$)=>$.lastModified-V.lastModified):C,[g,R,C]),G=t&&!P.some(V=>V.sessionId===t)?D.get(t):void 0;b.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,P,G]);const q=b.useRef(null),X=b.useRef(j);X.current=j,b.useEffect(()=>{const V=q.current;if(!V||!T||g)return;const $=new IntersectionObserver(L=>{L.some(W=>W.isIntersecting)&&X.current()},{rootMargin:"300px"});return $.observe(V),()=>$.disconnect()},[T,M,g]),b.useEffect(()=>{e().then(V=>V?fetch("/api/version",{headers:{Authorization:`Bearer ${V}`}}):null).then(V=>V==null?void 0:V.json()).then(V=>V&&E(V.version)).catch(()=>{})},[]);const U=!!x&&x!=="unknown"&&Of!=="dev"&&x!==Of;b.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${Of}, server runs v${x} — rebuild dist/client`)},[U,x]);function K(V){const $=l[V.sessionId],L=u.has(V.sessionId)||V.runStatus==="running"||V.scheduleRunStatus==="running",W=!L&&(!!V.lastStopReason||V.scheduleRunStatus==="error"||V.scheduleRunStatus==="aborted"),z=L?"border-amber-500":W?"border-red-500":$?"border-blue-500":"",ie=!!(L||W||$);return y.jsx("button",{ref:V.sessionId===t?_:void 0,onClick:()=>n(V.sessionId,V.title),className:Be("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ie?`rounded-r-lg border-l-[3px] ${z}`:"rounded-lg",t===V.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[Hoe(V),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:Be("block truncate text-sm leading-snug",$&&"font-semibold"),children:V.title||"New session"}),y.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Koe(V)||V.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:Foe(V.lastModified)})]})]})]})},V.sessionId)}return y.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[y.jsx("div",{className:"p-3",children:y.jsxs(we,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[y.jsx(ko,{className:"w-4 h-4"})," New Chat",y.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),y.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:y.jsx($re,{getToken:e,onRefresh:s,refreshKey:a})}),y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),y.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(V=>y.jsx("button",{onClick:()=>k(V),className:Be("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===V?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:V},V)),y.jsxs("button",{onClick:O,className:Be("text-[10px] px-1.5 rounded-full transition-colors leading-none",g?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",H>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(OL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[P.length===0&&!G&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:M?"Loading…":g?"No unread conversations":"No conversations yet"}),G&&K(G),P.map(K),!g&&T&&y.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:M?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[y.jsx(Coe,{socket:d??null,getToken:e}),(F=h.sidebarExtras)==null?void 0:F.call(h),x&&(U?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${Of}, the server runs v${x} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",Of," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ni(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 uI(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 V$(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(l=>l.type==="tool_use"&&l.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 Voe(e,t){const[n,r]=b.useState([]),[i,a]=b.useState(!1),[s,l]=b.useState([]),u=b.useRef(t.initialSessionId),d=b.useRef(!1),h=b.useRef(s);h.current=s;const m=b.useRef(t.getToken);m.current=t.getToken;const p=b.useRef(t.onNewSession);p.current=t.onNewSession;const g=b.useRef(t.onDirectivesChanged);g.current=t.onDirectivesChanged;const w=b.useRef(t.onParticipantsChanged);w.current=t.onParticipantsChanged;const x=b.useRef(t.onEvent);x.current=t.onEvent;const E=b.useRef(e);E.current=e;const _=b.useCallback(P=>P!=null&&P===u.current,[]),k=b.useCallback(async()=>{var G;const P=u.current;if(P)try{const X=await(await Ll(`/api/sessions/${P}/messages`,m.current)).json();r(nL(X)),a(!!X.busy),(G=w.current)==null||G.call(w,Array.isArray(X.participants)&&X.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const P=e.on(G=>{var X,U,K,F,V,$;(X=x.current)==null||X.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(L=>[...L,{id:Ms(),role:"assistant",blocks:[{type:"compact_marker",summary:q.summary??"",compactedCount:q.compactedCount??0}]}]):void 0;switch(G.type){case"thinking_delta":return _(G.sessionId)?r(L=>ni(L,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(L=>ni(L,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(L=>ni(L,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(L=>V$(L,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(L=>ni(L,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(L=>ni(L,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(L=>ni(L,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(L=>ni(L,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return d.current?(U=g.current)==null?void 0:U.call(g,G.directives):void 0;case"session_id":return!d.current||u.current?void 0:(u.current=G.sessionId,(K=p.current)==null?void 0:K.call(p,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(F=p.current)==null?void 0:F.call(p,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:Woe(r,G.event);case"session_messages_changed":G.sessionId===u.current&&k();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(W=>ni(W,{type:"text",text:`
1907
+ `)},wre=0,ru=[];function Ere(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),i=b.useState(wre++)[0],a=b.useState(dz)[0],s=b.useRef(e);b.useEffect(function(){s.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var x=I7([e.lockRef.current],(e.shards||[]).map(BM),!0).filter(Boolean);return x.forEach(function(E){return E.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),x.forEach(function(E){return E.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var l=b.useCallback(function(x,E){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!s.current.allowPinchZoom;var _=kp(x),k=n.current,O="deltaX"in x?x.deltaX:k[0]-_[0],N="deltaY"in x?x.deltaY:k[1]-_[1],C,T=x.target,M=Math.abs(O)>Math.abs(N)?"h":"v";if("touches"in x&&M==="h"&&T.type==="range")return!1;var D=window.getSelection(),j=D&&D.anchorNode,R=j?j===T||j.contains(T):!1;if(R)return!1;var H=zM(M,T);if(!H)return!0;if(H?C=M:(C=M==="v"?"h":"v",H=zM(M,T)),!H)return!1;if(!r.current&&"changedTouches"in x&&(O||N)&&(r.current=C),!C)return!0;var P=r.current||C;return yre(P,E,x,P==="h"?O:N)},[]),u=b.useCallback(function(x){var E=x;if(!(!ru.length||ru[ru.length-1]!==a)){var _="deltaY"in E?$M(E):kp(E),k=t.current.filter(function(C){return C.name===E.type&&(C.target===E.target||E.target===C.shadowParent)&&bre(C.delta,_)})[0];if(k&&k.should){E.cancelable&&E.preventDefault();return}if(!k){var O=(s.current.shards||[]).map(BM).filter(Boolean).filter(function(C){return C.contains(E.target)}),N=O.length>0?l(E,O[0]):!s.current.noIsolation;N&&E.cancelable&&E.preventDefault()}}},[]),d=b.useCallback(function(x,E,_,k){var O={name:x,delta:E,target:_,should:k,shadowParent:Sre(_)};t.current.push(O),setTimeout(function(){t.current=t.current.filter(function(N){return N!==O})},1)},[]),h=b.useCallback(function(x){n.current=kp(x),r.current=void 0},[]),m=b.useCallback(function(x){d(x.type,$M(x),x.target,l(x,e.lockRef.current))},[]),p=b.useCallback(function(x){d(x.type,kp(x),x.target,l(x,e.lockRef.current))},[]);b.useEffect(function(){return ru.push(a),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:p}),document.addEventListener("wheel",u,nu),document.addEventListener("touchmove",u,nu),document.addEventListener("touchstart",h,nu),function(){ru=ru.filter(function(x){return x!==a}),document.removeEventListener("wheel",u,nu),document.removeEventListener("touchmove",u,nu),document.removeEventListener("touchstart",h,nu)}},[]);var g=e.removeScrollBar,w=e.inert;return b.createElement(b.Fragment,null,w?b.createElement(a,{styles:xre(i)}):null,g?b.createElement(dre,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Sre(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const _re=Qne(uz,Ere);var vS=b.forwardRef(function(e,t){return b.createElement(Wv,xa({},e,{ref:t,sideCar:_re}))});vS.classNames=Wv.classNames;var Are=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},iu=new WeakMap,Op=new WeakMap,Np={},Lx=0,pz=function(e){return e&&(e.host||pz(e.parentNode))},kre=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=pz(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})},Ore=function(e,t,n,r){var i=kre(t,Array.isArray(e)?e:[e]);Np[n]||(Np[n]=new WeakMap);var a=Np[n],s=[],l=new Set,u=new Set(i),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};i.forEach(d);var h=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(p){if(l.has(p))h(p);else try{var g=p.getAttribute(r),w=g!==null&&g!=="false",x=(iu.get(p)||0)+1,E=(a.get(p)||0)+1;iu.set(p,x),a.set(p,E),s.push(p),x===1&&w&&Op.set(p,!0),E===1&&p.setAttribute(n,"true"),w||p.setAttribute(r,"true")}catch(_){console.error("aria-hidden: cannot operate on ",p,_)}})};return h(t),l.clear(),Lx++,function(){s.forEach(function(m){var p=iu.get(m)-1,g=a.get(m)-1;iu.set(m,p),a.set(m,g),p||(Op.has(m)||m.removeAttribute(r),Op.delete(m)),g||m.removeAttribute(n)}),Lx--,Lx||(iu=new WeakMap,iu=new WeakMap,Op=new WeakMap,Np={})}},gz=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=Are(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),Ore(r,i,n,"aria-hidden")):function(){return null}},Yv="Dialog",[vz]=hL(Yv),[Nre,Ji]=vz(Yv),yz=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,l=b.useRef(null),u=b.useRef(null),[d,h]=Sne({prop:r,defaultProp:i??!1,onChange:a,caller:Yv});return y.jsx(Nre,{scope:t,triggerRef:l,contentRef:u,contentId:Mx(),titleId:Mx(),descriptionId:Mx(),open:d,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(m=>!m),[h]),modal:s,children:n})};yz.displayName=Yv;var bz="DialogTrigger",xz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(bz,n),a=ui(t,i.triggerRef);return y.jsx(Fr.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":ES(i.open),...r,ref:a,onClick:Sr(e.onClick,i.onOpenToggle)})});xz.displayName=bz;var yS="DialogPortal",[Cre,wz]=vz(yS,{forceMount:void 0}),Ez=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Ji(yS,t);return y.jsx(Cre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Zs,{present:n||a.open,children:y.jsx(lz,{asChild:!0,container:i,children:s})}))})};Ez.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=wz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Pg,e.__scopeDialog);return a.modal?y.jsx(Zs,{present:r||a.open,children:y.jsx(Mre,{...i,ref:t})}):null});bS.displayName=Pg;var Tre=GE("DialogOverlay.RemoveScroll"),Mre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Pg,n),a=Mne(),s=ui(t,a);return y.jsx(vS,{as:Tre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Fr.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Uu="DialogContent",xS=b.forwardRef((e,t)=>{const n=wz(Uu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Ji(Uu,e.__scopeDialog);return y.jsx(Zs,{present:r||a.open,children:a.modal?y.jsx(Ire,{...i,ref:t}):y.jsx(Rre,{...i,ref:t})})});xS.displayName=Uu;var Ire=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(null),i=ui(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return gz(a)},[]),y.jsx(Sz,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Sr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:Sr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:Sr(e.onFocusOutside,a=>a.preventDefault())})}),Rre=b.forwardRef((e,t)=>{const n=Ji(Uu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Sz,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=e.onCloseAutoFocus)==null||s.call(e,a),a.defaultPrevented||(r.current||(l=n.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var u,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),Sz=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Ji(Uu,n);return Hne(),y.jsx(y.Fragment,{children:y.jsx(oz,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(iz,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ES(l.open),...s,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),_z="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(_z,n);return y.jsx(Fr.h2,{id:i.titleId,...r,ref:t})});wS.displayName=_z;var Az="DialogDescription",Pre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(Az,n);return y.jsx(Fr.p,{id:i.descriptionId,...r,ref:t})});Pre.displayName=Az;var kz="DialogClose",Oz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Ji(kz,n);return y.jsx(Fr.button,{type:"button",...r,ref:t,onClick:Sr(e.onClick,()=>i.onOpenChange(!1))})});Oz.displayName=kz;function ES(e){return e?"open":"closed"}const Oo=yz,rd=xz,Dre=Ez,Nz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:Be("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}));Nz.displayName=bS.displayName;const Na=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Dre,{children:[y.jsx(Nz,{}),y.jsxs(xS,{ref:r,className:Be("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,y.jsxs(Oz,{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:[y.jsx(Bs,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Na.displayName=xS.displayName;function Us({className:e,...t}){return y.jsx("div",{className:Be("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:Be("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Tz({className:e,...t}){return y.jsx("div",{className:Be("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 No=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:Be("text-lg font-semibold leading-none tracking-tight",e),...t}));No.displayName=wS.displayName;const jre=new Set(["png","jpg","jpeg","gif","webp","svg","ico","bmp","avif"]),Lre=new Set(["pdf","mp4","webm","mp3","ogg","wav"]);async function zre(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 $re({getToken:e,onRefresh:t,refreshKey:n}){const[r,i]=b.useState(new Map),[a,s]=b.useState(()=>new Set),[l,u]=b.useState(null),[d,h]=b.useState(!1),[m,p]=b.useState("fit"),[g,w]=b.useState(null),[x,E]=b.useState(null),_=b.useRef(null),[k,O]=b.useState(null),[N,C]=b.useState(!1),[T,M]=b.useState([]),D=b.useCallback(async U=>{const K=await zre(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{D(""),a.forEach(U=>D(U))},[D,n]);const j=r.get("")??[],R=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),V=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&V&&E({w:F,h:V})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,V=U.clientWidth-F,$=U.clientHeight-F,L=Math.min(V/K.w,$/K.h,1);w({scale:L,w:K.w,h:K.h})},[x]);b.useEffect(()=>{if(!(l!=null&&l.html)||m!=="fit"){w(null);return}const U=_.current;if(!U)return;const K=new ResizeObserver(()=>requestAnimationFrame(H));return K.observe(U),()=>K.disconnect()},[l==null?void 0:l.html,d,m,H]),b.useEffect(()=>{N&&e().then(U=>{U&&fetch("/api/data-sync/log",{headers:{Authorization:`Bearer ${U}`}}).then(K=>K.json()).then(M).catch(()=>{})})},[N]);const P=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||D(U)),F})},G=(U,K)=>{const F=new URLSearchParams({path:U});return k&&F.set("token",k),K&&F.set("dl","1"),`/api/workspace/raw?${F}`},q=async U=>{var V;const K=await e();if(!K)return;O(K);const F=((V=U.split(".").pop())==null?void 0:V.toLowerCase())??"";if(F==="html"||F==="htm"){u({path:U,content:"",binary:!1,html:!0});return}if(jre.has(F)){u({path:U,content:"",binary:!1,image:!0});return}if(Lre.has(F)){u({path:U,content:"",binary:!1,html:!0});return}try{const $=await fetch(`/api/workspace/file?path=${encodeURIComponent(U)}`,{headers:{Authorization:`Bearer ${K}`}});if(!$.ok)return;const L=await $.json();u({path:U,content:L.content,binary:!!L.binary})}catch{}},X=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const V=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>P(F.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+K*12},children:[y.jsx(Xs,{className:Be("w-3 h-3 shrink-0 transition-transform",a.has(F.path)&&"rotate-90")}),y.jsx(QG,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}):y.jsxs("button",{onClick:()=>q(F.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+K*12+12},title:F.oneLiner||F.path,children:[y.jsx(UE,{className:"w-3.5 h-3.5 shrink-0 text-muted-foreground"}),y.jsx("span",{className:"truncate",children:V})]}),F.type==="dir"&&a.has(F.path)&&X(r.get(F.path)??[],K+1)]},F.path)})});return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1 shrink-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Workspace"}),y.jsxs("div",{className:"flex items-center gap-0.5",children:[y.jsx("button",{onClick:()=>C(!0),className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Activity log",children:y.jsx(eV,{className:"w-3 h-3"})}),y.jsx("button",{onClick:()=>{D(""),a.forEach(U=>D(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:y.jsx(ed,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:j.length===0?y.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."}):X(j,0)}),y.jsx(Oo,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(Na,{className:Be(l!=null&&l.html?Be("!flex !flex-col !p-0 !gap-0 overflow-hidden",d?"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:[y.jsxs("div",{className:"absolute right-12 top-4 flex items-center gap-1.5 z-10",children:[(l==null?void 0:l.html)&&y.jsxs(y.Fragment,{children:[y.jsx("button",{onClick:()=>p(U=>U==="fit"?"scroll":"fit"),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:m==="fit"?"Switch to scrollable (1:1)":"Switch to scale-to-fit",children:m==="fit"?y.jsx(aV,{className:"w-4 h-4"}):y.jsx(dV,{className:"w-4 h-4"})}),y.jsx("button",{onClick:()=>h(U=>!U),className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:d?"Restore":"Maximize",children:d?y.jsx(HE,{className:"w-4 h-4"}):y.jsx(FE,{className:"w-4 h-4"})})]}),l&&y.jsx("a",{href:G(l.path,!0),download:!0,className:"rounded-sm opacity-70 hover:opacity-100 text-muted-foreground",title:"Download",children:y.jsx(lL,{className:"w-4 h-4"})})]}),y.jsx(Us,{className:Be((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(No,{className:"font-mono text-sm truncate pr-16",children:l==null?void 0:l.path})}),y.jsx("div",{ref:l!=null&&l.html?_:void 0,className:Be(l!=null&&l.html?Be("flex-1 min-h-0 bg-muted/10",m==="fit"?"overflow-hidden flex items-center justify-center":"overflow-auto"):"flex-1 min-h-0 overflow-y-auto"),children:l!=null&&l.html?m==="fit"?y.jsx("div",{style:g?{width:g.w*g.scale,height:g.h*g.scale}:{width:"100%",height:"100%"},children:y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white origin-top-left",title:l.path,onLoad:U=>{R(U.currentTarget),H()},style:g?{width:g.w,height:g.h,transform:`scale(${g.scale})`}:{width:"100%",height:"100%"}})}):y.jsx("iframe",{src:G(l.path),className:"border-0 bg-white mx-auto block",title:l.path,onLoad:U=>R(U.currentTarget),style:{width:(x==null?void 0:x.w)||"100%",height:(x==null?void 0:x.h)||"100%"}}):l!=null&&l.image?y.jsx("div",{className:"flex items-center justify-center p-4",children:y.jsx("img",{src:G(l.path),alt:l.path,className:"max-w-full max-h-[70vh] object-contain"})}):l!=null&&l.binary?y.jsx("p",{className:"text-sm text-muted-foreground",children:"(binary file — preview unavailable)"}):l!=null&&l.path.toLowerCase().endsWith(".md")||l!=null&&l.path.toLowerCase().endsWith(".markdown")?y.jsx("div",{className:"text-sm",children:y.jsx(d3,{remarkPlugins:[D3],rehypePlugins:[rz],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:l.content})}):y.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:l==null?void 0:l.content})})]})}),y.jsx(Oo,{open:N,onOpenChange:C,children:y.jsxs(Na,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Us,{children:y.jsx(No,{className:"text-sm",children:"Activity Log"})}),y.jsxs("div",{className:"overflow-y-auto flex-1 space-y-2",children:[T.map(U=>y.jsxs("div",{className:"border-b border-border/50 pb-2 last:border-0",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsx("span",{className:"text-sm text-foreground",children:U.message}),y.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:Bre(U.date)})]}),U.files.length>0&&y.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:U.files.map(K=>y.jsx("span",{className:"inline-block mr-2 font-mono",children:K},K))})]},U.hash)),T.length===0&&y.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No activity yet"})]})]})})]})}function Bre(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"})}function ag(e,t=Date.now()){if(!e)return null;const n=new Date(e).getTime()-t;if(!Number.isFinite(n)||n<=0)return null;const r=Math.round(n/6e4);if(r<1)return"1m";if(r<60)return`${r}m`;const i=Math.floor(r/60),a=r%60;if(i<48)return a?`${i}h ${a}m`:`${i}h`;const s=Math.floor(i/24),l=i%24;return l?`${s}d ${l}h`:`${s}d`}const Ure=/resets\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\s*\(UTC\)/i;function Fre(e,t=Date.now(),n=Date.now()){var m;const r=e.match(Ure);if(!r)return e;let i=Number(r[1]);const a=r[2]?Number(r[2]):0,s=(m=r[3])==null?void 0:m.toLowerCase();if(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0),i>23||a>59)return e;const l=new Date(t),u=new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate(),i,a));u.getTime()<=t&&u.setUTCDate(u.getUTCDate()+1);const d=u.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),h=ag(u.toISOString(),n);return e.replace(r[0],`resets ${d}${h?` (in ${h})`:""}`)}var Hre=Object.defineProperty,id=(e,t)=>Hre(e,"name",{value:t,configurable:!0}),Mz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Ds(e,t,{checkForDefaultPrevented:n=!0}={}){return id(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}id(Ds,"composeEventHandlers");function Kre(e){var t;if(!Mz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}id(Kre,"getOwnerWindow");function s1(e){if(!Mz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}id(s1,"getOwnerDocument");function Iz(e,t=!1){const{activeElement:n}=s1(e);if(!(n!=null&&n.nodeName))return null;if(Rz(n)&&n.contentDocument)return Iz(n.contentDocument.body,t);if(t){const r=n.getAttribute("aria-activedescendant");if(r){const i=s1(n).getElementById(r);if(i)return i}}return n}id(Iz,"getActiveElement");function Rz(e){return e.tagName==="IFRAME"}id(Rz,"isFrame");var qre=Object.defineProperty,SS=(e,t)=>qre(e,"name",{value:t,configurable:!0});function l1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}SS(l1,"setRef");function Pz(...e){return t=>{let n=!1;const r=e.map(i=>{const a=l1(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():l1(e[i],null)}}}}SS(Pz,"composeRefs");function ad(...e){return b.useCallback(Pz(...e),e)}SS(ad,"useComposedRefs");var Gre=Object.defineProperty,Ni=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function Vre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ni(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ni(i,"useContext"),[r,i]}Ni(Vre,"createContext");function Dz(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ni(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ni(h,"useContext"),[d,h]}Ni(r,"createContext");const i=Ni(()=>{const a=n.map(s=>b.createContext(s));return Ni(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,jz(i,...t)]}Ni(Dz,"createContextScope");function jz(...e){const t=e[0];if(e.length===1)return t;const n=Ni(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ni(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ni(jz,"composeContextScopes");var Wre=Object.defineProperty,ea=(e,t)=>Wre(e,"name",{value:t,configurable:!0});function _S(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];c1(i)&&typeof Cp=="function"&&(i=Cp(i._payload)),b.Children.forEach(i,p=>{var g;if(Bz(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;c1(x)&&typeof Cp=="function"&&(x=Cp(x._payload)),s=Xre(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?$z(s):void 0,h=ad(r,d);if(!s){if(i||i===0)throw new Error(l?Jre(e):Qre(e));return i}const m=zz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ea(_S,"createSlot");var Lz=Symbol.for("radix.slottable");function Yre(e){const t=ea(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=Lz,t}ea(Yre,"createSlottable");var Xre=ea((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function zz(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ea(zz,"mergeProps");function $z(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)}ea($z,"getElementRef");function Bz(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Lz}ea(Bz,"isSlottable");var Zre=Symbol.for("react.lazy");function c1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Zre&&"_payload"in e&&Uz(e._payload)}ea(c1,"isLazyComponent");function Uz(e){return typeof e=="object"&&e!==null&&"then"in e}ea(Uz,"isPromiseLike");var Qre=ea(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Jre=ea(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=ja[" use ".trim().toString()],eie=Object.defineProperty,tie=(e,t)=>eie(e,"name",{value:t,configurable:!0}),nie=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Xv=nie.reduce((e,t)=>{const n=_S(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Fz(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}tie(Fz,"dispatchDiscreteCustomEvent");var rie=Object.defineProperty,iie=(e,t)=>rie(e,"name",{value:t,configurable:!0});function Zv(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}iie(Zv,"useCallbackRef");var aie=Object.defineProperty,qn=(e,t)=>aie(e,"name",{value:t,configurable:!0}),u1="dismissableLayer.update",oie="dismissableLayer.pointerDownOutside",sie="dismissableLayer.focusOutside",UM,Hz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),lie=b.forwardRef(qn(function(t,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:s,onFocusOutside:l,onInteractOutside:u,onDismiss:d,...h}=t,m=b.useContext(Hz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=ad(n,g),_=Array.from(m.layers),[k]=[...m.layersWithOutsidePointerEventsDisabled].slice(-1),O=k?_.indexOf(k):-1,N=p?_.indexOf(p):-1,C=m.layersWithOutsidePointerEventsDisabled.size>0,T=N>=O,M=b.useRef(!1),D=Kz(P=>{s==null||s(P),u==null||u(P),P.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(P=>{if(!(P instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(P));return T&&!G},[m.branches,T])}),j=qz(P=>{if(i&&M.current)return;const G=P.target;[...m.branches].some(X=>X.contains(G))||(l==null||l(P),u==null||u(P),P.defaultPrevented||d==null||d())},w),R=p?N===_.length-1:!1,H=Zv(P=>{P.key==="Escape"&&(a==null||a(P),!P.defaultPrevented&&d&&(P.preventDefault(),d()))});return b.useEffect(()=>{if(R)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,R,H]),b.useEffect(()=>{if(p)return r&&(m.layersWithOutsidePointerEventsDisabled.size===0&&(UM=w.body.style.pointerEvents,w.body.style.pointerEvents="none"),m.layersWithOutsidePointerEventsDisabled.add(p)),m.layers.add(p),d1(),()=>{r&&(m.layersWithOutsidePointerEventsDisabled.delete(p),m.layersWithOutsidePointerEventsDisabled.size===0&&(w.body.style.pointerEvents=UM))}},[p,w,r,m]),b.useEffect(()=>()=>{p&&(m.layers.delete(p),m.layersWithOutsidePointerEventsDisabled.delete(p),d1())},[p,m]),b.useEffect(()=>{const P=qn(()=>x({}),"handleUpdate");return document.addEventListener(u1,P),()=>document.removeEventListener(u1,P)},[]),y.jsx(Xv.div,{...h,ref:E,style:{pointerEvents:C?T?"auto":"none":void 0,...t.style},onFocusCapture:Ds(t.onFocusCapture,j.onFocusCapture),onBlurCapture:Ds(t.onBlurCapture,j.onBlurCapture),onPointerDownCapture:Ds(t.onPointerDownCapture,D.onPointerDownCapture)})},"DismissableLayer"));function cie(){const e=b.useContext(Hz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}qn(cie,"useDismissableLayerSurface");var uie=qn(()=>!0,"IS_TRUE");function Kz(e,t){const{ownerDocument:n=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:s=uie}=t,l=Zv(e),u=b.useRef(!1),d=b.useRef(!1),h=b.useRef(new Map),m=b.useRef(()=>{});return b.useEffect(()=>{function p(){d.current=!1,i.current=!1,h.current.clear()}qn(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}qn(g,"isOutsideInteractionIntercepted");function w(O){if(!d.current)return;const N=O.target;N instanceof Node&&[...a].some(T=>T.contains(N))||h.current.set(O.type,!0),O.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}qn(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}qn(x,"handleInteractionBubble");const E=qn(O=>{if(O.target&&!u.current){let N=function(){n.removeEventListener("click",m.current);const T=g();p(),T||AS(oie,l,C,{discrete:!0})};if(qn(N,"handleAndDispatchPointerDownOutsideEvent"),!s(O.target)){n.removeEventListener("click",m.current),p(),u.current=!1;return}const C={originalEvent:O};d.current=!0,i.current=r&&O.button===0,h.current.clear(),!r||O.button!==0?N():(n.removeEventListener("click",m.current),m.current=N,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),p();u.current=!1},"handlePointerDown"),_=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const O of _)n.addEventListener(O,w,!0),n.addEventListener(O,x);const k=window.setTimeout(()=>{n.addEventListener("pointerdown",E)},0);return()=>{window.clearTimeout(k),n.removeEventListener("pointerdown",E),n.removeEventListener("click",m.current);for(const O of _)n.removeEventListener(O,w,!0),n.removeEventListener(O,x)}},[n,l,r,i,a,s]),{onPointerDownCapture:qn(()=>u.current=!0,"onPointerDownCapture")}}qn(Kz,"usePointerDownOutside");function qz(e,t=globalThis==null?void 0:globalThis.document){const n=Zv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=qn(a=>{a.target&&!r.current&&AS(sie,n,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,n]),{onFocusCapture:qn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:qn(()=>r.current=!1,"onBlurCapture")}}qn(qz,"useFocusOutside");function d1(){const e=new CustomEvent(u1);document.dispatchEvent(e)}qn(d1,"dispatchUpdate");function AS(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?Fz(i,a):i.dispatchEvent(a)}qn(AS,"handleAndDispatchCustomEvent");var die=Object.defineProperty,kS=(e,t)=>die(e,"name",{value:t,configurable:!0}),Tp=0,da=null;function fie(e){return OS(),e.children}kS(fie,"FocusGuards");function OS(){b.useEffect(()=>{da||(da={start:f1(),end:f1()});const{start:e,end:t}=da;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(da==null||da.start.remove(),da==null||da.end.remove(),da=null),Tp=Math.max(0,Tp-1)}},[])}kS(OS,"useFocusGuards");function f1(){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}kS(f1,"createFocusGuard");var hie=Object.defineProperty,mie=(e,t)=>hie(e,"name",{value:t,configurable:!0});function h1(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}mie(h1,"useCallbackRef");var pie=Object.defineProperty,xr=(e,t)=>pie(e,"name",{value:t,configurable:!0}),zx="focusScope.autoFocusOnMount",$x="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},gie=b.forwardRef(xr(function(t,n){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:s,...l}=t,[u,d]=b.useState(null),h=h1(a),m=h1(s),p=b.useRef(null),g=ad(n,d),w=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(i){let E=function(N){if(w.paused||!u)return;const C=N.target;u.contains(C)?p.current=C:uo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const C=N.relatedTarget;C!==null&&(u.contains(C)||uo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const T of N)T.removedNodes.length>0&&uo(u)};xr(E,"handleFocusIn"),xr(_,"handleFocusOut"),xr(k,"handleMutations"),document.addEventListener("focusin",E),document.addEventListener("focusout",_);const O=new MutationObserver(k);return u&&O.observe(u,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",E),document.removeEventListener("focusout",_),O.disconnect()}}},[i,u,w.paused]),b.useEffect(()=>{if(u){HM.add(w);const E=document.activeElement;if(!u.contains(E)){const k=new CustomEvent(zx,FM);u.addEventListener(zx,h),u.dispatchEvent(k),k.defaultPrevented||(Gz(Zz(NS(u)),{select:!0}),document.activeElement===E&&uo(u))}return()=>{u.removeEventListener(zx,h),setTimeout(()=>{const k=new CustomEvent($x,FM);u.addEventListener($x,m),u.dispatchEvent(k),k.defaultPrevented||uo(E??document.body,{select:!0}),u.removeEventListener($x,m),HM.remove(w)},0)}}},[u,h,m,w]);const x=b.useCallback(E=>{if(!r&&!i||w.paused)return;const _=E.key==="Tab"&&!E.altKey&&!E.ctrlKey&&!E.metaKey,k=document.activeElement;if(_&&k){const O=E.currentTarget,[N,C]=Vz(O);N&&C?!E.shiftKey&&k===C?(E.preventDefault(),r&&uo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&uo(C,{select:!0})):k===O&&E.preventDefault()}},[r,i,w.paused]);return y.jsx(Xv.div,{tabIndex:-1,...l,ref:g,onKeyDown:x})},"FocusScope"));function Gz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(uo(r,{select:t}),document.activeElement!==n)return}xr(Gz,"focusFirst");function Vz(e){const t=NS(e),n=m1(t,e),r=m1(t.reverse(),e);return[n,r]}xr(Vz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:xr(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}xr(NS,"getTabbableCandidates");function m1(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Wz(r,{upTo:t})))return r}xr(m1,"findVisible");function Wz(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}xr(Wz,"isHidden");function Yz(e){return e instanceof HTMLInputElement&&"select"in e}xr(Yz,"isSelectableInput");function uo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Yz(e)&&t&&e.select()}}xr(uo,"focus");var HM=Xz();function Xz(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=p1(e,t),e.unshift(t)},remove(t){var n;e=p1(e,t),(n=e[0])==null||n.resume()}}}xr(Xz,"createFocusScopesStack");function p1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}xr(p1,"arrayRemove");function Zz(e){return e.filter(t=>t.tagName!=="A")}xr(Zz,"removeLinks");var vie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0}),xie=ja[" useId ".trim().toString()]||(()=>{}),wie=0;function Qz(e){const[t,n]=b.useState(xie());return vie(()=>{e||n(r=>r??String(wie++))},[e]),e||(t?`radix-${t}`:"")}bie(Qz,"useId");const Eie=["top","right","bottom","left"],Fs=Math.min,xo=Math.max,Dg=Math.round,Mp=Math.floor,wo=e=>({x:e,y:e}),Sie={left:"right",right:"left",bottom:"top",top:"bottom"};function Jz(e,t,n){return xo(e,Fs(t,n))}function Co(e,t){return typeof e=="function"?e(t):e}function Hs(e){return e.split("-")[0]}function od(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function wa(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(wa(e))}function _ie(e,t,n){n===void 0&&(n=!1);const r=od(e),i=MS(e),a=TS(i);let s=i==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=jg(s)),[s,jg(s)]}function Aie(e){const t=jg(e);return[g1(e),t,g1(t)]}function g1(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const KM=["left","right"],qM=["right","left"],kie=["top","bottom"],Oie=["bottom","top"];function Nie(e,t,n){switch(e){case"top":case"bottom":return n?t?qM:KM:t?KM:qM;case"left":case"right":return t?kie:Oie;default:return[]}}function Cie(e,t,n,r){const i=od(e);let a=Nie(Hs(e),n==="start",r);return i&&(a=a.map(s=>s+"-"+i),t&&(a=a.concat(a.map(g1)))),a}function jg(e){const t=Hs(e);return Sie[t]+e.slice(t.length)}function Tie(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 e$(e){return typeof e!="number"?Tie(e):{top:e,right:e,bottom:e,left:e}}function Lg(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 GM(e,t,n){let{reference:r,floating:i}=e;const a=wa(t),s=MS(t),l=TS(s),u=Hs(t),d=a==="y",h=r.x+r.width/2-i.width/2,m=r.y+r.height/2-i.height/2,p=r[l]/2-i[l]/2;let g;switch(u){case"top":g={x:h,y:r.y-i.height};break;case"bottom":g={x:h,y:r.y+r.height};break;case"right":g={x:r.x+r.width,y:m};break;case"left":g={x:r.x-i.width,y:m};break;default:g={x:r.x,y:r.y}}const w=od(t);return w&&(g[s]+=p*(w==="end"?1:-1)*(n&&d?-1:1)),g}async function Mie(e,t){var n;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:s,elements:l,strategy:u}=e,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:m="floating",altBoundary:p=!1,padding:g=0}=Co(t,e),w=e$(g),E=l[p?m==="floating"?"reference":"floating":m],_=Lg(await a.getClippingRect({element:(n=await(a.isElement==null?void 0:a.isElement(E)))==null||n?E:E.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(l.floating)),boundary:d,rootBoundary:h,strategy:u})),k=m==="floating"?{x:r,y:i,width:s.floating.width,height:s.floating.height}:s.reference,O=await(a.getOffsetParent==null?void 0:a.getOffsetParent(l.floating)),N=await(a.isElement==null?void 0:a.isElement(O))&&await(a.getScale==null?void 0:a.getScale(O))||{x:1,y:1},C=Lg(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:k,offsetParent:O,strategy:u}):k);return{top:(_.top-C.top+w.top)/N.y,bottom:(C.bottom-_.bottom+w.bottom)/N.y,left:(_.left-C.left+w.left)/N.x,right:(C.right-_.right+w.right)/N.x}}const Iie=50,Rie=async(e,t,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:s}=n,l=s.detectOverflow?s:{...s,detectOverflow:Mie},u=await(s.isRTL==null?void 0:s.isRTL(t));let d=await s.getElementRects({reference:e,floating:t,strategy:i}),{x:h,y:m}=GM(d,r,u),p=r,g=0;const w={};for(let x=0;x<a.length;x++){const E=a[x];if(!E)continue;const{name:_,fn:k}=E,{x:O,y:N,data:C,reset:T}=await k({x:h,y:m,initialPlacement:r,placement:p,strategy:i,middlewareData:w,rects:d,platform:l,elements:{reference:e,floating:t}});h=O??h,m=N??m,w[_]={...w[_],...C},T&&g<Iie&&(g++,typeof T=="object"&&(T.placement&&(p=T.placement),T.rects&&(d=T.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:i}):T.rects),{x:h,y:m}=GM(d,p,u)),x=-1)}return{x:h,y:m,placement:p,strategy:i,middlewareData:w}},Pie=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:i,rects:a,platform:s,elements:l,middlewareData:u}=t,{element:d,padding:h=0}=Co(e,t)||{};if(d==null)return{};const m=e$(h),p={x:n,y:r},g=MS(i),w=TS(g),x=await s.getDimensions(d),E=g==="y",_=E?"top":"left",k=E?"bottom":"right",O=E?"clientHeight":"clientWidth",N=a.reference[w]+a.reference[g]-p[g]-a.floating[w],C=p[g]-a.reference[g],T=await(s.getOffsetParent==null?void 0:s.getOffsetParent(d));let M=T?T[O]:0;(!M||!await(s.isElement==null?void 0:s.isElement(T)))&&(M=l.floating[O]||a.floating[w]);const D=N/2-C/2,j=M/2-x[w]/2-1,R=Fs(m[_],j),H=Fs(m[k],j),P=M-x[w]-H,G=M/2-x[w]/2+D,q=Jz(R,G,P),X=!u.arrow&&od(i)!=null&&G!==q&&a.reference[w]/2-(G<R?R:H)-x[w]/2<0,U=X?G<R?G-R:G-P:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...X&&{alignmentOffset:U}},reset:X}}}),Die=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:l,platform:u,elements:d}=t,{mainAxis:h=!0,crossAxis:m=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:x=!0,...E}=Co(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=Hs(i),k=wa(l),O=Hs(l)===l,N=await(u.isRTL==null?void 0:u.isRTL(d.floating)),C=p||(O||!x?[jg(l)]:Aie(l)),T=w!=="none";!p&&T&&C.push(...Cie(l,x,w,N));const M=[l,...C],D=await u.detectOverflow(t,E),j=[];let R=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&j.push(D[_]),m){const q=_ie(i,s,N);j.push(D[q[0]],D[q[1]])}if(R=[...R,{placement:i,overflows:j}],!j.every(q=>q<=0)){var H,P;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,X=M[q];if(X&&(!(m==="alignment"?k!==wa(X):!1)||R.every(F=>wa(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:R},reset:{placement:X}};let U=(P=R.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:P.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=R.filter(F=>{if(T){const V=wa(F.placement);return V===k||V==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(V=>V>0).reduce((V,$)=>V+$,0)]).sort((F,V)=>F[1]-V[1])[0])==null?void 0:G[0];K&&(U=K);break}case"initialPlacement":U=l;break}if(i!==U)return{reset:{placement:U}}}return{}}}};function VM(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function WM(e){return Eie.some(t=>e[t]>=0)}const jie=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n,platform:r}=t,{strategy:i="referenceHidden",...a}=Co(e,t);switch(i){case"referenceHidden":{const s=await r.detectOverflow(t,{...a,elementContext:"reference"}),l=VM(s,n.reference);return{data:{referenceHiddenOffsets:l,referenceHidden:WM(l)}}}case"escaped":{const s=await r.detectOverflow(t,{...a,altBoundary:!0}),l=VM(s,n.floating);return{data:{escapedOffsets:l,escaped:WM(l)}}}default:return{}}}}},t$=new Set(["left","top"]);async function Lie(e,t){const{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),s=Hs(n),l=od(n),u=wa(n)==="y",d=t$.has(s)?-1:1,h=a&&u?-1:1,m=Co(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:w}=typeof m=="number"?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return l&&typeof w=="number"&&(g=l==="end"?w*-1:w),u?{x:g*h,y:p*d}:{x:p*d,y:g*h}}const zie=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:l}=t,u=await Lie(t,e);return s===((n=l.offset)==null?void 0:n.placement)&&(r=l.arrow)!=null&&r.alignmentOffset?{}:{x:i+u.x,y:a+u.y,data:{...u,placement:s}}}}},$ie=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:l=!1,limiter:u={fn:k=>{let{x:O,y:N}=k;return{x:O,y:N}}},...d}=Co(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=wa(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Jz(O+m[k==="y"?"top":"left"],O,O-m[k==="y"?"bottom":"right"]);s&&(w=E(g,w)),l&&(x=E(p,x));const _=u.fn({...t,[g]:w,[p]:x});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[g]:s,[p]:l}}}}}},Bie=function(e){return e===void 0&&(e={}),{options:e,fn(t){var n,r;const{x:i,y:a,placement:s,rects:l,middlewareData:u}=t,{offset:d=0,mainAxis:h=!0,crossAxis:m=!0}=Co(e,t),p={x:i,y:a},g=wa(s),w=CS(g);let x=p[w],E=p[g];const _=Co(d,t),k=typeof _=="number"?{mainAxis:_,crossAxis:0}:{mainAxis:(n=_.mainAxis)!=null?n:0,crossAxis:(r=_.crossAxis)!=null?r:0};if(h){const C=w==="y"?"height":"width",T=l.reference[w]-l.floating[C]+k.mainAxis,M=l.reference[w]+l.reference[C]-k.mainAxis;x<T?x=T:x>M&&(x=M)}if(m){var O,N;const C=w==="y"?"width":"height",T=t$.has(Hs(s)),M=l.reference[g]-l.floating[C]+(T&&((O=u.offset)==null?void 0:O[g])||0)+(T?0:k.crossAxis),D=l.reference[g]+l.reference[C]+(T?0:((N=u.offset)==null?void 0:N[g])||0)-(T?k.crossAxis:0);E<M?E=M:E>D&&(E=D)}return{[w]:x,[g]:E}}}},Uie=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=()=>{},...l}=Co(e,t),u=await i.detectOverflow(t,l),d=Hs(n),h=od(n),m=wa(n)==="y",{width:p,height:g}=r.floating;let w,x;d==="top"||d==="bottom"?(w=d,x=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(x=d,w=h==="end"?"top":"bottom");const E=g-u.top-u.bottom,_=p-u.left-u.right,k=Fs(g-u[w],E),O=Fs(p-u[x],_),N=t.middlewareData.shift,C=!N;let T=k,M=O;N!=null&&N.enabled.x&&(M=_),N!=null&&N.enabled.y&&(T=E),C&&!h&&(m?M=p-2*xo(u.left,u.right):T=g-2*xo(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:T});const D=await i.getDimensions(a.floating);return p!==D.width||g!==D.height?{reset:{rects:!0}}:{}}}};function Qv(){return typeof window<"u"}function sd(e){return n$(e)?(e.nodeName||"").toLowerCase():"#document"}function Ur(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function jo(e){var t;return(t=(n$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function n$(e){return Qv()?e instanceof Node||e instanceof Ur(e).Node:!1}function Ca(e){return Qv()?e instanceof Element||e instanceof Ur(e).Element:!1}function Js(e){return Qv()?e instanceof HTMLElement||e instanceof Ur(e).HTMLElement:!1}function YM(e){return!Qv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ur(e).ShadowRoot}function Jv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=Ta(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fie(e){return/^(table|td|th)$/.test(sd(e))}function ey(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const Hie=/transform|translate|scale|rotate|perspective|filter/,Kie=/paint|layout|strict|content/,Al=e=>!!e&&e!=="none";let Bx;function IS(e){const t=Ca(e)?Ta(e):e;return Al(t.transform)||Al(t.translate)||Al(t.scale)||Al(t.rotate)||Al(t.perspective)||!RS()&&(Al(t.backdropFilter)||Al(t.filter))||Hie.test(t.willChange||"")||Kie.test(t.contain||"")}function qie(e){let t=ec(e);for(;Js(t)&&!nh(t);){if(IS(t))return t;if(ey(t))return null;t=ec(t)}return null}function RS(){return Bx==null&&(Bx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Bx}function nh(e){return/^(html|body|#document)$/.test(sd(e))}function Ta(e){return Ur(e).getComputedStyle(e)}function ty(e){return Ca(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ec(e){if(sd(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||jo(e);return YM(t)?t.host:t}function r$(e){const t=ec(e);return nh(t)?(e.ownerDocument||e).body:Js(t)&&Jv(t)?t:r$(t)}function rh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=r$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=Ur(i);if(a){const l=v1(s);return t.concat(s,s.visualViewport||[],Jv(i)?i:[],l&&n?rh(l):[])}else return t.concat(i,rh(i,[],n))}function v1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function i$(e){const t=Ta(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Js(e),a=i?e.offsetWidth:n,s=i?e.offsetHeight:r,l=Dg(n)!==a||Dg(r)!==s;return l&&(n=a,r=s),{width:n,height:r,$:l}}function PS(e){return Ca(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Js(t))return wo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=i$(t);let s=(a?Dg(n.width):n.width)/r,l=(a?Dg(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!l||!Number.isFinite(l))&&(l=1),{x:s,y:l}}const Gie=wo(0);function a$(e){const t=Ur(e);return!RS()||!t.visualViewport?Gie:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Vie(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Ur(e)}function tc(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=wo(1);t&&(r?Ca(r)&&(s=Tu(r)):s=Tu(e));const l=Vie(a,n,r)?a$(a):wo(0);let u=(i.left+l.x)/s.x,d=(i.top+l.y)/s.y,h=i.width/s.x,m=i.height/s.y;if(a&&r){const p=Ur(a),g=Ca(r)?Ur(r):r;let w=p,x=v1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=Ta(x),O=_.left+(x.clientLeft+parseFloat(k.paddingLeft))*E.x,N=_.top+(x.clientTop+parseFloat(k.paddingTop))*E.y;u*=E.x,d*=E.y,h*=E.x,m*=E.y,u+=O,d+=N,w=Ur(x),x=v1(w)}}return Lg({width:h,height:m,x:u,y:d})}function ny(e,t){const n=ty(e).scrollLeft;return t?t.left+n:tc(jo(e)).left+n}function o$(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ny(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function Wie(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e;const a=i==="fixed",s=jo(r),l=t?ey(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=wo(1);const h=wo(0),m=Js(r);if((m||!a)&&((sd(r)!=="body"||Jv(s))&&(u=ty(r)),m)){const g=tc(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?o$(s,u):wo(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-u.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-u.scrollTop*d.y+h.y+p.y}}function Yie(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function Xie(e){const t=ty(e),n=e.ownerDocument.body,r=xo(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=xo(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ny(e);const s=-t.scrollTop;return Ta(n).direction==="rtl"&&(a+=xo(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:s}}const Zie=25;function Qie(e,t,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",i=Ur(e),a=jo(e),s=i.visualViewport;let l=a.clientWidth,u=a.clientHeight,d=0,h=0;if(s){const p=!RS()||t==="fixed";r?p||(d=-s.offsetLeft,h=-s.offsetTop):(l=s.width,u=s.height,p&&(d=s.offsetLeft,h=s.offsetTop))}if(ny(a)<=0){const p=a.ownerDocument,g=p.body,w=getComputedStyle(g),x=p.compatMode==="CSS1Compat"&&parseFloat(w.marginLeft)+parseFloat(w.marginRight)||0,E=Math.abs(a.clientWidth-g.clientWidth-x),_=getComputedStyle(a).scrollbarGutter==="stable both-edges"?E/2:E;_<=Zie&&(l-=_)}return{width:l,height:u,x:d,y:h}}function Jie(e,t){const n=tc(e,!0,t==="fixed"),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Tu(e),s=e.clientWidth*a.x,l=e.clientHeight*a.y,u=i*a.x,d=r*a.y;return{width:s,height:l,x:u,y:d}}function XM(e,t,n){let r;if(t==="viewport"||t==="layoutViewport")r=Qie(e,n,t);else if(t==="document")r=Xie(jo(e));else if(Ca(t))r=Jie(t,n);else{const i=a$(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Lg(r)}function eae(e,t){const n=t.get(e);if(n)return n;let r=rh(e,[],!1).filter(l=>Ca(l)&&sd(l)!=="body"),i=null;const a=Ta(e).position==="fixed";let s=a?ec(e):e;for(;Ca(s)&&!nh(s);){const l=Ta(s),u=IS(s),d=i?i.position:a?"fixed":"";!u&&(d==="fixed"||d==="absolute"&&l.position==="static")?r=r.filter(m=>m!==s):i=l,s=ec(s)}return t.set(e,r),r}function tae(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e;const s=[...n==="clippingAncestors"?ey(t)?[]:eae(t,this._c):[].concat(n),r],l=XM(t,s[0],i);let u=l.top,d=l.right,h=l.bottom,m=l.left;for(let p=1;p<s.length;p++){const g=XM(t,s[p],i);u=xo(g.top,u),d=Fs(g.right,d),h=Fs(g.bottom,h),m=xo(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function nae(e){const{width:t,height:n}=i$(e);return{width:t,height:n}}function rae(e,t,n){const r=Js(t),i=jo(t),a=n==="fixed",s=tc(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=wo(0);if((r||!a)&&((sd(t)!=="body"||Jv(i))&&(l=ty(t)),r)){const p=tc(t,!0,a,t);u.x=p.x+t.clientLeft,u.y=p.y+t.clientTop}!r&&i&&(u.x=ny(i));const d=i&&!r&&!a?o$(i,l):wo(0),h=s.left+l.scrollLeft-u.x-d.x,m=s.top+l.scrollTop-u.y-d.y;return{x:h,y:m,width:s.width,height:s.height}}function Ux(e){return Ta(e).position==="static"}function ZM(e,t){if(!Js(e)||Ta(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return jo(e)===n&&(n=n.ownerDocument.body),n}function s$(e,t){const n=Ur(e);if(ey(e))return n;if(!Js(e)){let i=ec(e);for(;i&&!nh(i);){if(Ca(i)&&!Ux(i))return i;i=ec(i)}return n}let r=ZM(e,t);for(;r&&Fie(r)&&Ux(r);)r=ZM(r,t);return r&&nh(r)&&Ux(r)&&!IS(r)?n:r||qie(e)||n}const iae=async function(e){const t=this.getOffsetParent||s$,n=this.getDimensions,r=await n(e.floating);return{reference:rae(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function aae(e){return Ta(e).direction==="rtl"}const oae={convertOffsetParentRelativeRectToViewportRelativeRect:Wie,getDocumentElement:jo,getClippingRect:tae,getOffsetParent:s$,getElementRects:iae,getClientRects:Yie,getDimensions:nae,getScale:Tu,isElement:Ca,isRTL:aae};function l$(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function sae(e,t,n){let r=null,i;const a=jo(e);function s(){var h;clearTimeout(i),(h=r)==null||h.disconnect(),r=null}function l(h,m){h===void 0&&(h=!1),m===void 0&&(m=1),s();const p=e.getBoundingClientRect(),{left:g,top:w,width:x,height:E}=p;if(h||t(),!x||!E)return;const _=Mp(w),k=Mp(a.clientWidth-(g+x)),O=Mp(a.clientHeight-(w+E)),N=Mp(g),T={rootMargin:-_+"px "+-k+"px "+-O+"px "+-N+"px",threshold:xo(0,Fs(1,m))||1};let M=!0;function D(j){const R=j[0].intersectionRatio;if(!l$(p,e.getBoundingClientRect()))return l();if(R!==m){if(!M)return l();R?l(!1,R):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(D,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(D,T)}r.observe(e)}const u=Ur(e),d=()=>l(n);return u.addEventListener("resize",d),l(!0),()=>{u.removeEventListener("resize",d),s()}}function lae(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:u=!1}=r,d=PS(e),h=i||a?[...d?rh(d):[],...t?rh(t):[]]:[];h.forEach(_=>{i&&_.addEventListener("scroll",n),a&&_.addEventListener("resize",n)});const m=d&&l?sae(d,n,a):null;let p=-1,g=null;s&&(g=new ResizeObserver(_=>{let[k]=_;k&&k.target===d&&g&&t&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var O;(O=g)==null||O.observe(t)})),n()}),d&&!u&&g.observe(d),t&&g.observe(t));let w,x=u?tc(e):null;u&&E();function E(){const _=tc(e);x&&!l$(x,_)&&n(),x=_,w=requestAnimationFrame(E)}return n(),()=>{var _;h.forEach(k=>{i&&k.removeEventListener("scroll",n),a&&k.removeEventListener("resize",n)}),m==null||m(),(_=g)==null||_.disconnect(),g=null,u&&cancelAnimationFrame(w)}}const cae=zie,uae=$ie,dae=Die,fae=Uie,hae=jie,QM=Pie,mae=Bie,pae=(e,t,n)=>{const r=new Map,i=n??{},a={...oae,...i.platform,_c:r};return Rie(e,t,{...i,platform:a})};var gae=typeof document<"u",vae=function(){},og=gae?b.useLayoutEffect:vae;function zg(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(!zg(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)&&!zg(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function c$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=c$(e);return Math.round(t*n)/n}function Fx(e){const t=b.useRef(e);return og(()=>{t.current=e}),t}function yae(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:s}={},transform:l=!0,whileElementsMounted:u,open:d}=e,[h,m]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=b.useState(r);zg(p,r)||g(r);const[w,x]=b.useState(null),[E,_]=b.useState(null),k=b.useCallback(F=>{F!==T.current&&(T.current=F,x(F))},[]),O=b.useCallback(F=>{F!==M.current&&(M.current=F,_(F))},[]),N=a||w,C=s||E,T=b.useRef(null),M=b.useRef(null),D=b.useRef(h),j=u!=null,R=Fx(u),H=Fx(i),P=Fx(d),G=b.useCallback(()=>{if(!T.current||!M.current)return;const F={placement:t,strategy:n,middleware:p};H.current&&(F.platform=H.current),pae(T.current,M.current,F).then(V=>{const $={...V,isPositioned:P.current!==!1};q.current&&!zg(D.current,$)&&(D.current=$,La.flushSync(()=>{m($)}))})},[p,t,n,H,P]);og(()=>{d===!1&&D.current.isPositioned&&(D.current.isPositioned=!1,m(F=>({...F,isPositioned:!1})))},[d]);const q=b.useRef(!1);og(()=>(q.current=!0,()=>{q.current=!1}),[]),og(()=>{if(N&&(T.current=N),C&&(M.current=C),N&&C){if(R.current)return R.current(N,C,G);G()}},[N,C,G,R,j]);const X=b.useMemo(()=>({reference:T,floating:M,setReference:k,setFloating:O}),[k,O]),U=b.useMemo(()=>({reference:N,floating:C}),[N,C]),K=b.useMemo(()=>{const F={position:n,left:0,top:0};if(!U.floating)return F;const V=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+V+"px, "+$+"px)",...c$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:X,elements:U,floatingStyles:K}),[h,G,X,U,K])}const bae=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?QM({element:r.current,padding:i}).fn(n):{}:r?QM({element:r,padding:i}).fn(n):{}}}},xae=(e,t)=>{const n=cae(e);return{name:n.name,fn:n.fn,options:[e,t]}},wae=(e,t)=>{const n=uae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eae=(e,t)=>({fn:mae(e).fn,options:[e,t]}),Sae=(e,t)=>{const n=dae(e);return{name:n.name,fn:n.fn,options:[e,t]}},_ae=(e,t)=>{const n=fae(e);return{name:n.name,fn:n.fn,options:[e,t]}},Aae=(e,t)=>{const n=hae(e);return{name:n.name,fn:n.fn,options:[e,t]}},kae=(e,t)=>{const n=bae(e);return{name:n.name,fn:n.fn,options:[e,t]}};var Oae=Object.defineProperty,DS=(e,t)=>Oae(e,"name",{value:t,configurable:!0});function y1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}DS(y1,"setRef");function u$(...e){return t=>{let n=!1;const r=e.map(i=>{const a=y1(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():y1(e[i],null)}}}}DS(u$,"composeRefs");function ry(...e){return b.useCallback(u$(...e),e)}DS(ry,"useComposedRefs");var Nae=Object.defineProperty,Ci=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function Cae(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Ci(a=>{const{children:s,...l}=a,u=b.useMemo(()=>l,Object.values(l));return y.jsx(n.Provider,{value:u,children:s})},"Provider");r.displayName=e+"Provider";function i(a,s={}){const{optional:l=!1}=s,u=b.useContext(n);if(u)return u;if(t!==void 0)return t;if(!l)throw new Error(`\`${a}\` must be used within \`${e}\``)}return Ci(i,"useContext"),[r,i]}Ci(Cae,"createContext");function d$(e,t=[]){let n=[];function r(a,s){const l=b.createContext(s);l.displayName=a+"Context";const u=n.length;n=[...n,s];const d=Ci(m=>{var _;const{scope:p,children:g,...w}=m,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useMemo(()=>w,Object.values(w));return y.jsx(x.Provider,{value:E,children:g})},"Provider");d.displayName=a+"Provider";function h(m,p,g={}){var _;const{optional:w=!1}=g,x=((_=p==null?void 0:p[e])==null?void 0:_[u])||l,E=b.useContext(x);if(E)return E;if(s!==void 0)return s;if(!w)throw new Error(`\`${m}\` must be used within \`${a}\``)}return Ci(h,"useContext"),[d,h]}Ci(r,"createContext");const i=Ci(()=>{const a=n.map(s=>b.createContext(s));return Ci(function(l){const u=(l==null?void 0:l[e])||a;return b.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])},"useScope")},"createScope");return i.scopeName=e,[r,f$(i,...t)]}Ci(d$,"createContextScope");function f$(...e){const t=e[0];if(e.length===1)return t;const n=Ci(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Ci(function(a){const s=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(a)[`__scope${d}`];return{...l,...m}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:s}),[s])},"useComposedScopes")},"createScope");return n.scopeName=t.scopeName,n}Ci(f$,"composeContextScopes");var Tae=Object.defineProperty,ta=(e,t)=>Tae(e,"name",{value:t,configurable:!0});function h$(e){const t=b.forwardRef((n,r)=>{let{children:i,...a}=n,s=null,l=!1;const u=[];b1(i)&&typeof Ip=="function"&&(i=Ip(i._payload)),b.Children.forEach(i,p=>{var g;if(v$(p)){l=!0;const w=p;let x="child"in w.props?w.props.child:w.props.children;b1(x)&&typeof Ip=="function"&&(x=Ip(x._payload)),s=Iae(w,x),u.push((g=s==null?void 0:s.props)==null?void 0:g.children)}else u.push(p)}),s?s=b.cloneElement(s,void 0,u):!l&&b.Children.count(i)===1&&b.isValidElement(i)&&(s=i);const d=s?g$(s):void 0,h=ry(r,d);if(!s){if(i||i===0)throw new Error(l?Dae(e):Pae(e));return i}const m=p$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}ta(h$,"createSlot");var m$=Symbol.for("radix.slottable");function Mae(e){const t=ta(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=m$,t}ta(Mae,"createSlottable");var Iae=ta((e,t)=>{if("child"in e.props){const n=e.props.child;return b.isValidElement(n)?b.cloneElement(n,void 0,e.props.children(n.props.children)):null}return b.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function p$(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]=(...l)=>{const u=a(...l);return i(...l),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...a}:r==="className"&&(n[r]=[i,a].filter(Boolean).join(" "))}return{...e,...n}}ta(p$,"mergeProps");function g$(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)}ta(g$,"getElementRef");function v$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===m$}ta(v$,"isSlottable");var Rae=Symbol.for("react.lazy");function b1(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Rae&&"_payload"in e&&y$(e._payload)}ta(b1,"isLazyComponent");function y$(e){return typeof e=="object"&&e!==null&&"then"in e}ta(y$,"isPromiseLike");var Pae=ta(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Dae=ta(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=ja[" use ".trim().toString()],jae=Object.defineProperty,Lae=(e,t)=>jae(e,"name",{value:t,configurable:!0}),zae=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],b$=zae.reduce((e,t)=>{const n=h$(`Primitive.${t}`),r=b.forwardRef((i,a)=>{const{asChild:s,...l}=i,u=s?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),y.jsx(u,{...l,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function $ae(e,t){e&&La.flushSync(()=>e.dispatchEvent(t))}Lae($ae,"dispatchDiscreteCustomEvent");var Bae=Object.defineProperty,Uae=(e,t)=>Bae(e,"name",{value:t,configurable:!0});function x$(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}Uae(x$,"useCallbackRef");var Hx=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Fae=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},Hae=Object.defineProperty,Kae=(e,t)=>Hae(e,"name",{value:t,configurable:!0});function w$(e){const[t,n]=b.useState(void 0);return Fae(()=>{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,l;if("borderBoxSize"in a){const u=a.borderBoxSize,d=Array.isArray(u)?u[0]:u;s=d.inlineSize,l=d.blockSize}else s=e.offsetWidth,l=e.offsetHeight;n({width:s,height:l})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}Kae(w$,"useSize");var qae=Object.defineProperty,js=(e,t)=>qae(e,"name",{value:t,configurable:!0}),E$="Popper",[S$,_$]=d$(E$),[Gae,A$]=S$(E$),Vae=js(e=>{const{__scopePopper:t,children:n}=e,[r,i]=b.useState(null),[a,s]=b.useState(void 0);return y.jsx(Gae,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:s,children:n})},"Popper"),Wae="PopperAnchor",Yae=b.forwardRef(js(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=A$(Wae,r),l=b.useRef(null),u=s.onAnchorChange,d=b.useCallback(x=>{l.current=x,x&&u(x)},[u]),h=ry(n,d),m=b.useRef(null);b.useEffect(()=>{if(!i)return;const x=m.current;m.current=i.current,x!==m.current&&u(m.current)});const p=s.placementState&&iy(s.placementState),g=p==null?void 0:p[0],w=p==null?void 0:p[1];return i?null:y.jsx(b$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),k$="PopperContent",[Xae,cCe]=S$(k$),Zae=b.forwardRef(js(function(t,n){var fe,Ee,Te,de,nt,He,Ae;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:s="center",alignOffset:l=0,arrowPadding:u=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:m=0,sticky:p="partial",hideWhenDetached:g=!1,updatePositionStrategy:w="optimized",onPlaced:x,...E}=t,_=A$(k$,r),[k,O]=b.useState(null),N=ry(n,O),[C,T]=b.useState(null),M=w$(C),D=(M==null?void 0:M.width)??0,j=(M==null?void 0:M.height)??0,R=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},P=Array.isArray(h)?h:[h],G=P.length>0,q={padding:H,boundary:P.filter(O$),altBoundary:G},{refs:X,floatingStyles:U,placement:K,isPositioned:F,middlewareData:V}=yae({strategy:"fixed",placement:R,whileElementsMounted:js((...De)=>lae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[xae({mainAxis:a+j,alignmentAxis:l}),d&&wae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Eae():void 0,...q}),d&&Sae({...q}),_ae({...q,apply:js(({elements:De,rects:Ht,availableWidth:un,availableHeight:Yn})=>{const{width:Or,height:ji}=Ht.reference,ir=De.floating.style;ir.setProperty("--radix-popper-available-width",`${un}px`),ir.setProperty("--radix-popper-available-height",`${Yn}px`),ir.setProperty("--radix-popper-anchor-width",`${Or}px`),ir.setProperty("--radix-popper-anchor-height",`${ji}px`)},"apply")}),C&&kae({element:C,padding:u}),Qae({arrowWidth:D,arrowHeight:j}),g&&Aae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Hx(()=>($(K),()=>{$(void 0)}),[K,$]);const[L,W]=iy(K),z=x$(x);Hx(()=>{F&&(z==null||z())},[F,z]);const ie=(fe=V.arrow)==null?void 0:fe.x,he=(Ee=V.arrow)==null?void 0:Ee.y,ge=((Te=V.arrow)==null?void 0:Te.centerOffset)!==0,[Se,ze]=b.useState();return Hx(()=>{k&&ze(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:X.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Se,"--radix-popper-transform-origin":[(de=V.transformOrigin)==null?void 0:de.x,(nt=V.transformOrigin)==null?void 0:nt.y].join(" "),...((He=V.hide)==null?void 0:He.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Xae,{scope:r,placedSide:L,placedAlign:W,onArrowChange:T,arrowX:ie,arrowY:he,shouldHideArrow:ge,children:y.jsx(b$.div,{"data-side":L,"data-align":W,...E,ref:N,style:{...E.style,animation:F?(Ae=E.style)==null?void 0:Ae.animation:"none"}})})})},"PopperContent"));function O$(e){return e!==null}js(O$,"isNotNull");var Qae=js(e=>({name:"transformOrigin",options:e,fn(t){var E,_,k;const{placement:n,rects:r,middlewareData:i}=t,s=((E=i.arrow)==null?void 0:E.centerOffset)!==0,l=s?0:e.arrowWidth,u=s?0:e.arrowHeight,[d,h]=iy(n),m={start:"0%",center:"50%",end:"100%"}[h],p=(((_=i.arrow)==null?void 0:_.x)??0)+l/2,g=(((k=i.arrow)==null?void 0:k.y)??0)+u/2;let w="",x="";return d==="bottom"?(w=s?m:`${p}px`,x=`${-u}px`):d==="top"?(w=s?m:`${p}px`,x=`${r.floating.height+u}px`):d==="right"?(w=`${-u}px`,x=s?m:`${g}px`):d==="left"&&(w=`${r.floating.width+u}px`,x=s?m:`${g}px`),{data:{x:w,y:x}}}}),"transformOrigin");function iy(e){const[t,n="center"]=e.split("-");return[t,n]}js(iy,"getSideAndAlignFromPlacement");var Jae=Vae,eoe=Yae,toe=Zae,noe=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},roe=Object.defineProperty,ioe=(e,t)=>roe(e,"name",{value:t,configurable:!0}),aoe=b.forwardRef(ioe(function(t,n){var u;const{container:r,...i}=t,[a,s]=b.useState(!1);noe(()=>s(!0),[]);const l=r||a&&((u=globalThis==null?void 0:globalThis.document)==null?void 0:u.body);return l?La.createPortal(y.jsx(Xv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ooe=Object.defineProperty,To=(e,t)=>ooe(e,"name",{value:t,configurable:!0});function N$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}To(N$,"useStateMachine");var C$=To(e=>{const{present:t,children:n}=e,r=T$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=M$(r.ref,I$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function T$(e){const[t,n]=b.useState(),r=b.useRef(null),i=b.useRef(e),a=b.useRef("none"),s=b.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=N$(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{u==="mounted"?(a.current=s.current??bu(r.current),s.current=void 0):a.current="none"},[u]),eI(()=>{const h=r.current,m=i.current;if(m!==e){const g=a.current,w=bu(h);e?(s.current=w,d("MOUNT")):w==="none"||(h==null?void 0:h.display)==="none"?d("UNMOUNT"):d(m&&g!==w?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,d]),eI(()=>{if(t){let h;const m=t.ownerDocument.defaultView??window,p=To(w=>{const E=bu(r.current).includes(CSS.escape(w.animationName));if(w.target===t&&E&&(d("ANIMATION_END"),!i.current)){const _=t.style.animationFillMode;t.style.animationFillMode="forwards",h=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=_)})}},"handleAnimationEnd"),g=To(w=>{w.target===t&&(a.current=bu(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{m.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:b.useCallback(h=>{if(h){const m=getComputedStyle(h);r.current=m,s.current=bu(m)}else r.current=null;n(h)},[])}}To(T$,"usePresence");function x1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}To(x1,"setRef");function M$(...e){const t=b.useRef(e);return t.current=e,b.useCallback(n=>{const r=t.current;let i=!1;const a=r.map(s=>{const l=x1(s,n);return!i&&typeof l=="function"&&(i=!0),l});if(i)return()=>{for(let s=0;s<a.length;s++){const l=a[s];typeof l=="function"?l():x1(r[s],null)}}},[])}To(M$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}To(bu,"getAnimationName");function I$(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)}To(I$,"getElementRef");var R$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,loe=(e,t)=>soe(e,"name",{value:t,configurable:!0}),tI=ja[" useEffectEvent ".trim().toString()],nI=ja[" useInsertionEffect ".trim().toString()];function P$(e){if(typeof tI=="function")return tI(e);const t=b.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof nI=="function"?nI(()=>{t.current=e}):R$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}loe(P$,"useEffectEvent");var coe=Object.defineProperty,Nh=(e,t)=>coe(e,"name",{value:t,configurable:!0}),uoe=ja[" useInsertionEffect ".trim().toString()]||R$;function D$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=j$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=L$(h)?h(e):h;p!==e&&((m=s.current)==null||m.call(s,p))}else a(h)},[l,e,a,s]);return[u,d]}Nh(D$,"useControllableState");function j$({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),i=b.useRef(n),a=b.useRef(t);return uoe(()=>{a.current=t},[t]),b.useEffect(()=>{var s;i.current!==n&&((s=a.current)==null||s.call(a,n),i.current=n)},[n,i]),[n,r,a]}Nh(j$,"useUncontrolledState");function L$(e){return typeof e=="function"}Nh(L$,"isFunction");var rI=Symbol("RADIX:SYNC_STATE");function doe(e,t,n,r){const{prop:i,defaultProp:a,onChange:s,caller:l}=t,u=i!==void 0,d=P$(s),h=[{...n,state:a}];r&&h.push(r);const[m,p]=b.useReducer((E,_)=>{if(_.type===rI)return{...E,state:_.state};const k=e(E,_);return u&&!Object.is(k.state,E.state)&&d(k.state),k},...h),g=m.state,w=b.useRef(g);b.useEffect(()=>{w.current!==g&&(w.current=g,u||d(g))},[g,w,u]);const x=b.useMemo(()=>i!==void 0?{...m,state:i}:m,[m,i]);return b.useEffect(()=>{u&&!Object.is(i,m.state)&&p({type:rI,state:i})},[i,m.state,u]),[x,p]}Nh(doe,"useControllableStateReducer");var foe=Object.defineProperty,el=(e,t)=>foe(e,"name",{value:t,configurable:!0}),jS="Popover",[z$,uCe]=Dz(jS,[_$]),LS=_$(),[hoe,ld]=z$(jS),moe=el(e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!1}=e,l=LS(t),u=b.useRef(null),[d,h]=b.useState(!1),[m,p]=D$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(Jae,{...l,children:y.jsx(hoe,{scope:t,contentId:Qz(),triggerRef:u,open:m,onOpenChange:p,onOpenToggle:b.useCallback(()=>p(g=>!g),[p]),hasCustomAnchor:d,onCustomAnchorAdd:b.useCallback(()=>h(!0),[]),onCustomAnchorRemove:b.useCallback(()=>h(!1),[]),modal:s,children:n})})},"Popover"),poe="PopoverTrigger",goe=b.forwardRef(el(function(t,n){const{__scopePopover:r,...i}=t,a=ld(poe,r),s=LS(r),l=ad(n,a.triggerRef),u=y.jsx(Xv.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":zS(a.open),...i,ref:l,onClick:Ds(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(eoe,{asChild:!0,...s,children:u})},"PopoverTrigger")),$$="PopoverPortal",[voe,yoe]=z$($$,{forceMount:void 0}),boe=el(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=ld($$,t);return y.jsx(voe,{scope:t,forceMount:n,children:y.jsx(C$,{present:n||a.open,children:y.jsx(aoe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),ih="PopoverContent",xoe=b.forwardRef(el(function(t,n){const r=yoe(ih,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=ld(ih,t.__scopePopover);return y.jsx(C$,{present:i||s.open,children:s.modal?y.jsx(Eoe,{...a,ref:n}):y.jsx(Soe,{...a,ref:n})})},"PopoverContent")),woe=_S("PopoverContent.RemoveScroll"),Eoe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(null),a=ad(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return gz(l)},[]),y.jsx(vS,{as:woe,allowPinchZoom:!0,children:y.jsx(B$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ds(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Ds(t.onPointerDownOutside,l=>{const u=l.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;s.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:Ds(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),Soe=b.forwardRef(el(function(t,n){const r=ld(ih,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx(B$,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var l,u;(l=t.onCloseAutoFocus)==null||l.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 d,h;(d=t.onInteractOutside)==null||d.call(t,s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const l=s.target;((h=r.triggerRef.current)==null?void 0:h.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&a.current&&s.preventDefault()}})},"PopoverContentNonModal")),B$=b.forwardRef(el(function(t,n){const{__scopePopover:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:s,disableOutsidePointerEvents:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:m,...p}=t,g=ld(ih,r),w=LS(r);return OS(),y.jsx(gie,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:s,children:y.jsx(lie,{asChild:!0,disableOutsidePointerEvents:l,onInteractOutside:m,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:h,onDismiss:()=>g.onOpenChange(!1),deferPointerDownOutside:!0,children:y.jsx(toe,{"data-state":zS(g.open),role:"dialog",id:g.contentId,...w,...p,ref:n,style:{...p.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 zS(e){return e?"open":"closed"}el(zS,"getState");var _oe=moe,Aoe=goe,koe=boe,U$=xoe;const Ooe=_oe,Noe=Aoe,F$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(koe,{children:y.jsx(U$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:Be("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})}));F$.displayName=U$.displayName;const H$=92,K$=96;function Kx(e){if(!Number.isFinite(e)||e<0)return"?";const t=["B","KB","MB","GB","TB","PB"];let n=0;for(;e>=1024&&n<t.length-1;)e/=1024,n++;return`${e<10&&n>0?e.toFixed(1):Math.round(e)} ${t[n]}`}const iI=3e5;function Coe({socket:e,getToken:t}){const[n,r]=b.useState([]);if(b.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]),b.useEffect(()=>{if(!e)return;const a=e.on(s=>{s.type==="stats"&&r(l=>[...l,s.sample].slice(-120))});return()=>{a()}},[e]),!n.length)return null;const i=n[n.length-1];return y.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:[y.jsx(sg,{label:"cpu",value:i.cpu,series:n.map(a=>a.cpu)}),y.jsx(sg,{label:"mem",value:i.mem,series:n.map(a=>a.mem)}),i.disk>=0&&y.jsx(sg,{label:"disk",value:i.disk,severity:Loe(i.disk),title:$oe(i)}),y.jsx(Toe,{getToken:t})]})}function Toe({getToken:e}){const[t,n]=b.useState(null);return b.useEffect(()=>{let r=!0,i=0;const a=async()=>{var d;try{const h=await e();if(!h)return;i=Date.now();const m=await fetch("/api/claude-usage",{headers:{Authorization:`Bearer ${h}`}});if(!r)return;if(m.status===204){n(null);return}if(m.status!==200)return;const p=await m.json();if(!r||!((d=p==null?void 0:p.limits)!=null&&d.length))return;n(p)}catch(h){console.warn("[MachineStats] claude usage poll failed",h)}},s=()=>{document.visibilityState==="visible"&&a()},l=()=>{document.visibilityState==="visible"&&Date.now()-i>=iI&&a()};s();const u=setInterval(s,iI);return document.addEventListener("visibilitychange",l),()=>{r=!1,clearInterval(u),document.removeEventListener("visibilitychange",l)}},[e]),y.jsx(Moe,{usage:t})}function Moe({usage:e}){const t=e&&q$(e.limits),[n,r]=b.useState(w1),i=b.useRef(null),a=()=>{i.current&&(clearTimeout(i.current),i.current=null)},s=b.useCallback((l,u=0)=>{if(a(),!u){r(d=>oI(d,l));return}i.current=setTimeout(()=>{i.current=null,r(d=>oI(d,l))},u)},[]);return b.useEffect(()=>a,[]),!e||!t?null:y.jsxs(Ooe,{open:n.open,onOpenChange:l=>s(l?{type:"activate"}:{type:"dismiss"}),children:[y.jsx(Noe,{asChild:!0,children:y.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:l=>s({type:"pointerenter",pointerType:l.pointerType},Ioe),onPointerLeave:l=>s({type:"pointerleave",pointerType:l.pointerType},aI),children:y.jsx(sg,{label:"usage",value:t.percent,severity:t.severity})})}),y.jsx(F$,{onOpenAutoFocus:l=>l.preventDefault(),onPointerEnter:()=>a(),onPointerLeave:l=>s({type:"pointerleave",pointerType:l.pointerType},aI),children:y.jsx(Roe,{usage:e})})]})}const Ioe=120,aI=80,w1={open:!1,byHover:!1};function oI(e,t){switch(t.type){case"pointerenter":return sI(t.pointerType)?{open:!0,byHover:!0}:e;case"pointerleave":return sI(t.pointerType)&&e.byHover?w1:e;case"activate":return{open:!0,byHover:!1};case"dismiss":return w1}}const sI=e=>e==="mouse"||e==="";function Roe({usage:e}){const t=q$(e.limits);return y.jsxs("div",{className:"text-[11px] leading-tight",children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2 pb-2 text-muted-foreground",children:[y.jsx("span",{className:"uppercase tracking-wide",children:"claude usage"}),e.subscriptionType&&y.jsxs("span",{className:"tabular-nums",children:[e.subscriptionType," plan"]})]}),y.jsxs("div",{className:"-mt-1 flex items-baseline justify-between gap-2 pb-2 text-[10px] text-muted-foreground",children:[e.account&&y.jsx("span",{className:"truncate",title:e.account,children:e.account}),y.jsx("span",{className:Be("shrink-0",e.stale&&"text-amber-500"),children:Doe(e)})]}),e.stale&&e.error&&y.jsxs("div",{"data-refresh-error":!0,className:"-mt-1 pb-2 text-[10px] text-amber-500 break-words",children:[e.error,ag(e.retryAt??null)&&` · retrying in ${ag(e.retryAt??null)}`]}),y.jsx("div",{className:"flex flex-col gap-3",children:e.limits.map((n,r)=>{const i=ag(n.resetsAt),a=n===t;return y.jsxs("div",{"data-headline":a||void 0,className:Be("flex flex-col gap-1",!a&&"opacity-60"),children:[y.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[y.jsxs("span",{className:Be("truncate",a&&"font-medium"),children:[a&&y.jsx("span",{className:"mr-1 text-muted-foreground","aria-hidden":!0,children:"▸"}),Poe(n)]}),y.jsxs("span",{className:Be("tabular-nums shrink-0",E1(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(G$,{value:n.percent,className:Be("w-full",E1(n.percent,n.severity))}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:i?`resets in ${i}`:"no reset reported"})]},`${n.kind}-${r}`)})}),y.jsx("div",{className:"mt-3 border-t pt-2 text-[10px] text-muted-foreground",children:"▸ is the window the strip is showing"})]})}function Poe(e){return e.scopeLabel?`${e.scopeLabel} window`:e.kind==="session"?"current session":e.kind==="weekly_all"?"all models":e.kind.replace(/_/g," ")}function q$(e){return e.reduce((t,n)=>!t||n.percent>t.percent?n:t,null)}function Doe(e){const t=joe(e.fetchedAt);return t?e.stale?`${t} old — refresh failed`:`updated ${t} ago`:e.stale?"last reading — refresh failed":"updated just now"}function joe(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 Loe(e){return e>=K$?"critical":e>=H$?"warning":"ok"}const zoe={critical:"text-red-500",exceeded:"text-red-500",warning:"text-amber-500",warn:"text-amber-500",ok:"text-emerald-500"};function E1(e,t){const n=t?zoe[t]:void 0;return n||(e>=90?"text-red-500":e>=75?"text-amber-500":"text-emerald-500")}function $oe(e){const t=`warn at ${H$}%, critical at ${K$}%`;if(e.diskUsedBytes==null||e.diskTotalBytes==null)return`disk ${e.disk}% used — ${t}`;const n=Math.max(0,e.diskTotalBytes-e.diskUsedBytes);return`disk ${e.disk}% used — ${Kx(e.diskUsedBytes)} of ${Kx(e.diskTotalBytes)}, ${Kx(n)} free — ${t}`}function sg({label:e,value:t,series:n,title:r,severity:i}){const a=E1(t,i),s=r??(n?`${e} ${t}% — last ${n.length} samples`:void 0);return y.jsxs("span",{className:"flex items-center gap-1",title:s,children:[y.jsx("span",{className:"uppercase tracking-wide",children:e}),n?y.jsx(Boe,{series:n,className:a}):y.jsx(G$,{value:t,className:a}),y.jsxs("span",{className:Be("tabular-nums",a),children:[t,"%"]})]})}function G$({value:e,className:t}){const i=Math.max(0,Math.min(100,e))/100*40;return y.jsxs("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Be("overflow-visible",t),preserveAspectRatio:"none",children:[y.jsx("rect",{x:0,y:12/2-2,width:40,height:4,rx:2,fill:"currentColor",opacity:.2}),i>0&&y.jsx("rect",{x:0,y:12/2-2,width:i,height:4,rx:2,fill:"currentColor"})]})}function Boe({series:e,className:t}){const i=e.length;if(i<2)return null;const a=e.map((s,l)=>{const u=i>1?l/(i-1)*40:0,d=12-Math.max(0,Math.min(100,s))/100*12;return`${u.toFixed(1)},${d.toFixed(1)}`}).join(" ");return y.jsx("svg",{width:40,height:12,viewBox:"0 0 40 12",className:Be("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const kf=50;function Uoe({getToken:e,filter:t,refreshKey:n,hydrateIds:r}){const[i,a]=b.useState([]),[s,l]=b.useState(null),[u,d]=b.useState(!1),[h,m]=b.useState({}),p=b.useRef(new Set),g=b.useRef(null),w=b.useRef(null),x=b.useRef(t);x.current=t;const E=b.useRef(kf),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=kf);const k=b.useCallback(async(M,D)=>{const j=await e();if(!j||D!=null&&D.aborted)return null;const R=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:D,headers:{Authorization:`Bearer ${j}`}});if(!R.ok)return null;const H=await R.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,D,j)=>{const R=[];let H,P=null;for(;R.length<M;){const G={filter:D,limit:String(Math.min(kf,M-R.length))};H&&(G.before=H);const q=await k(G,j);if(!q)return null;if(R.push(...q.sessions),P=q.nextCursor,!P||!q.sessions.length)break;H=P}return{sessions:R,nextCursor:P}},[k]);b.useEffect(()=>{var D,j;(D=g.current)==null||D.abort(),(j=w.current)==null||j.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(R=>{!R||M.signal.aborted||(a(R.sessions),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var j;if(!s||u)return;(j=w.current)==null||j.abort();const M=new AbortController;w.current=M;const D=x.current;d(!0),k({filter:D,limit:String(kf),before:s},M.signal).then(R=>{!R||M.signal.aborted||D!==x.current||(a(H=>{const P=new Set(H.map(q=>q.sessionId)),G=[...H,...R.sessions.filter(q=>!P.has(q.sessionId))];return E.current=Math.max(kf,G.length),G}),l(R.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),C=b.useMemo(()=>{const M=new Map;for(const D of Object.values(h))M.set(D.sessionId,D);for(const D of i)M.set(D.sessionId,D);return M},[i,h]),T=r.join(",");return b.useEffect(()=>{const M=r.filter(j=>!!j&&!C.has(j)&&!p.current.has(j)).slice(0,200);if(!M.length)return;for(const j of M)p.current.add(j);let D=!1;return k({ids:M.join(",")}).then(j=>{!j||D||m(R=>{const H={...R};for(const P of j.sessions)H[P.sessionId]=P;return H})}).catch(()=>{}),()=>{D=!0}},[T,C,k]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:N}}const Of="0.1.121";function Foe(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 Nf="w-4 h-4 mt-0.5 shrink-0";function Hoe(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(iV,{className:`${Nf} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(KG,{className:`${Nf} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(JG,{className:`${Nf} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Gw,{className:`${Nf} text-yellow-400`}):y.jsx(Gw,{className:`${Nf} text-muted-foreground`})}function Koe(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}function qoe(e,t,n){return Object.keys(e).map(r=>t.get(r)).filter(r=>!!r&&(n==="all"||r.mine!==!1))}const lI="chats-filter",cI="chats-unread-filter";function Goe({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var F;const h=za(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),_=b.useRef(null);function k(V){p(V),localStorage.setItem(lI,V)}function O(){const V=!g;w(V),localStorage.setItem(cI,String(V))}const N=b.useMemo(()=>[t,...Object.keys(l)].filter(V=>!!V),[t,l]),{sessions:C,cursor:T,loading:M,byId:D,loadMore:j}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:N}),R=b.useMemo(()=>qoe(l,D,m),[l,D,m]),H=R.length,P=b.useMemo(()=>g?[...R].sort((V,$)=>$.lastModified-V.lastModified):C,[g,R,C]),G=t&&!P.some(V=>V.sessionId===t)?D.get(t):void 0;b.useEffect(()=>{_.current&&_.current.scrollIntoView({block:"nearest"})},[t,P,G]);const q=b.useRef(null),X=b.useRef(j);X.current=j,b.useEffect(()=>{const V=q.current;if(!V||!T||g)return;const $=new IntersectionObserver(L=>{L.some(W=>W.isIntersecting)&&X.current()},{rootMargin:"300px"});return $.observe(V),()=>$.disconnect()},[T,M,g]),b.useEffect(()=>{e().then(V=>V?fetch("/api/version",{headers:{Authorization:`Bearer ${V}`}}):null).then(V=>V==null?void 0:V.json()).then(V=>V&&E(V.version)).catch(()=>{})},[]);const U=!!x&&x!=="unknown"&&Of!=="dev"&&x!==Of;b.useEffect(()=>{U&&console.warn(`[shraga] stale client bundle: built from v${Of}, server runs v${x} — rebuild dist/client`)},[U,x]);function K(V){const $=l[V.sessionId],L=u.has(V.sessionId)||V.runStatus==="running"||V.scheduleRunStatus==="running",W=!L&&(!!V.lastStopReason||V.scheduleRunStatus==="error"||V.scheduleRunStatus==="aborted"),z=L?"border-amber-500":W?"border-red-500":$?"border-blue-500":"",ie=!!(L||W||$);return y.jsx("button",{ref:V.sessionId===t?_:void 0,onClick:()=>n(V.sessionId,V.title),className:Be("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",ie?`rounded-r-lg border-l-[3px] ${z}`:"rounded-lg",t===V.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[Hoe(V),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:Be("block truncate text-sm leading-snug",$&&"font-semibold"),children:V.title||"New session"}),y.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[y.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:Koe(V)||V.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:Foe(V.lastModified)})]})]})]})},V.sessionId)}return y.jsxs("div",{className:"flex flex-col h-full bg-muted/30",children:[y.jsx("div",{className:"p-3",children:y.jsxs(we,{variant:"outline",size:"sm",className:"w-full gap-2 justify-start",onClick:r,title:"New Chat (Ctrl+N)",children:[y.jsx(ko,{className:"w-4 h-4"})," New Chat",y.jsx("span",{className:"ml-auto flex items-center gap-0.5 text-[10px] text-muted-foreground/50 font-mono",children:"⌃N"})]})}),y.jsx("div",{className:"border-b shrink-0 flex flex-col max-h-[40vh]",children:y.jsx($re,{getToken:e,onRefresh:s,refreshKey:a})}),y.jsxs("div",{className:"flex items-center justify-between px-3 pt-2 pb-1",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Chats"}),y.jsxs("div",{className:"flex gap-0.5",children:[["mine","all"].map(V=>y.jsx("button",{onClick:()=>k(V),className:Be("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===V?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:V},V)),y.jsxs("button",{onClick:O,className:Be("text-[10px] px-1.5 rounded-full transition-colors leading-none",g?"text-blue-600 dark:text-blue-400 font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:["unread",H>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(OL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[P.length===0&&!G&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:M?"Loading…":g?"No unread conversations":"No conversations yet"}),G&&K(G),P.map(K),!g&&T&&y.jsx("div",{ref:q,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:M?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[y.jsx(Coe,{socket:d??null,getToken:e}),(F=h.sidebarExtras)==null?void 0:F.call(h),x&&(U?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${Of}, the server runs v${x} — reload to update`,className:"text-[10px] text-amber-400 hover:text-amber-300 text-center underline decoration-dotted",children:["⚠️ stale page (v",Of," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ni(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 uI(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 V$(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(l=>l.type==="tool_use"&&l.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 Voe(e,t){const[n,r]=b.useState([]),[i,a]=b.useState(!1),[s,l]=b.useState([]),u=b.useRef(t.initialSessionId),d=b.useRef(!1),h=b.useRef(s);h.current=s;const m=b.useRef(t.getToken);m.current=t.getToken;const p=b.useRef(t.onNewSession);p.current=t.onNewSession;const g=b.useRef(t.onDirectivesChanged);g.current=t.onDirectivesChanged;const w=b.useRef(t.onParticipantsChanged);w.current=t.onParticipantsChanged;const x=b.useRef(t.onEvent);x.current=t.onEvent;const E=b.useRef(e);E.current=e;const _=b.useCallback(P=>P!=null&&P===u.current,[]),k=b.useCallback(async()=>{var G;const P=u.current;if(P)try{const X=await(await Ll(`/api/sessions/${P}/messages`,m.current)).json();r(nL(X)),a(!!X.busy),(G=w.current)==null||G.call(w,Array.isArray(X.participants)&&X.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const P=e.on(G=>{var X,U,K,F,V,$;(X=x.current)==null||X.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(L=>[...L,{id:Ms(),role:"assistant",blocks:[{type:"compact_marker",summary:q.summary??"",compactedCount:q.compactedCount??0}]}]):void 0;switch(G.type){case"thinking_delta":return _(G.sessionId)?r(L=>ni(L,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(L=>ni(L,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(L=>ni(L,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(L=>V$(L,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(L=>ni(L,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(L=>ni(L,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(L=>ni(L,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(L=>ni(L,{type:"question_request",id:G.id,questions:G.questions})):void 0;case"directives":return d.current?(U=g.current)==null?void 0:U.call(g,G.directives):void 0;case"session_id":return!d.current||u.current?void 0:(u.current=G.sessionId,(K=p.current)==null?void 0:K.call(p,G.sessionId));case"forked":return G.sourceSessionId!==u.current?void 0:(u.current=G.sessionId,(F=p.current)==null?void 0:F.call(p,G.sessionId));case"session_busy":G.sessionId===u.current&&a(G.busy);return;case"session_stream":return G.sessionId!==u.current?void 0:Woe(r,G.event);case"session_messages_changed":G.sessionId===u.current&&k();return;case"done":{if(G.sessionId!==u.current)return;G.stopReason==="max_turns_reached"&&r(W=>ni(W,{type:"text",text:`
1908
1908
 
1909
1909
  ---
1910
1910
  ⚠️ Reached the maximum number of steps for this turn. Send "continue" to pick up where I left off.`})),(V=p.current)==null||V.call(p,G.sessionId);const L=h.current;if(L.length>0){const W=L.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-BpRE_FwV.js"></script>
16
+ <script type="module" crossorigin src="/assets/index-Ctr73RPj.js"></script>
17
17
  <link rel="stylesheet" crossorigin href="/assets/index-_XEpjgJO.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.120",
3
+ "version": "0.1.121",
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",
@@ -7,11 +7,14 @@
7
7
  // gateway authenticates this box however it likes, e.g. network identity — no credential is sent from here):
8
8
  // POST {gateway}/media/ingest { source: '/uploads/<dir>/<file>' } → { file } | { async: true, jobId }
9
9
  // The gateway pulls `source` from THIS agent's authenticated `/uploads` route.
10
+ // GET {gateway}/media/health → { publicBase? } (origin minted links use; optional)
10
11
  // GET {gateway}/media/job?jobId=… → { status: queued|running|done|failed|cancelled, result?, error? }
11
12
  // An async ingest's `result.file` is the gateway-side path.
12
13
  // POST {gateway}/media/preview { file, expiresHours? } → { jobId } (job result.url = human preview link)
13
14
  // POST {gateway}/media/publish_url { file, expiresHours? } → { url } (link to the original bytes)
15
+ // POST {gateway}/media/cancel { jobId } (called when a job outlives our wait)
14
16
  // Every response may carry `ok: false` + `error`.
17
+ // share_file only hands out a gateway link a human can open: a private/tailnet link is refused (see isPublicUrl).
15
18
  import { randomUUID } from 'node:crypto';
16
19
  import { linkSync, copyFileSync, mkdirSync, rmSync } from 'node:fs';
17
20
  import path from 'node:path';
@@ -29,17 +32,39 @@ export function mediaKind(file: string): MediaKind | undefined {
29
32
  return VIDEO_EXT.has(ext) ? 'video' : AUDIO_EXT.has(ext) ? 'audio' : IMAGE_EXT.has(ext) ? 'image' : undefined;
30
33
  }
31
34
 
32
- /** Whether share_file must hand this file to the gateway instead of publishing it from the box. */
33
- export function shouldOffloadShare(file: string, bytes: number, cfg: OffloadSettings | undefined): boolean {
34
- return !!cfg && (!!mediaKind(file) || bytes > cfg.maxLocalFileMB * 1024 * 1024);
35
+ /** Whether share_file must hand this file to the gateway instead of publishing it from the box. Size is the only
36
+ * criterion: a small file (media included) is served from the box's own public origin, which every recipient can open. */
37
+ export function shouldOffloadShare(bytes: number, cfg: OffloadSettings | undefined): boolean {
38
+ return !!cfg && bytes > cfg.maxLocalFileMB * 1024 * 1024;
35
39
  }
36
40
 
41
+ /** Whether a link is reachable by an arbitrary recipient (a Slack teammate, an external) — not loopback, a private
42
+ * LAN (RFC1918 / link-local / ULA), the tailnet (100.64.0.0/10 CGNAT, http MagicDNS), or a bare/`.local` host.
43
+ * `https://*.ts.net` counts as public: that is Tailscale Funnel. */
44
+ export function isPublicUrl(url: string): boolean {
45
+ let u: URL;
46
+ try { u = new URL(url); } catch { return false; }
47
+ if (u.protocol !== 'https:' && u.protocol !== 'http:') return false;
48
+ const host = u.hostname.toLowerCase().replace(/^\[|\]$/g, '');
49
+ const v4 = host.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)?.slice(1).map(Number);
50
+ if (v4) {
51
+ const [a, b] = v4 as [number, number];
52
+ return !(a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127));
53
+ }
54
+ if (host.includes(':')) return !(host === '::1' || host === '::' || /^f[cd]/.test(host) || /^fe[89ab]/.test(host) || host.startsWith('::ffff:'));
55
+ if (!host.includes('.') || host === 'localhost' || /\.(localhost|local|internal|lan|home\.arpa)$/.test(host)) return false;
56
+ if (host.endsWith('.ts.net')) return u.protocol === 'https:';
57
+ return true;
58
+ }
59
+
60
+ export const OFFLOAD_PRIVATE_LINK_ERROR = 'This file is too large to share from this box, and the media pod has no public link origin yet (its links only open on the private network), so no link was made. Send the file as a Slack/email attachment instead, or ask an operator to publish it.';
61
+
37
62
  export class OffloadGatewayOptions {
38
63
  gateway = '';
39
64
  /** Cap for a single request. Bun's fetch otherwise cuts every request at an implicit 300s. */
40
65
  requestTimeoutMs = 60_000;
41
- /** Overall wait for an async ingest / preview job. */
42
- jobWaitMs = 20 * 60_000;
66
+ /** Overall wait for a preview job — share_file is an interactive tool call. An ingest waits longer, sized to the file. */
67
+ jobWaitMs = 5 * 60_000;
43
68
  pollMs = 3_000;
44
69
  /** Preview/link lifetime asked of the gateway. */
45
70
  expiresHours = 48;
@@ -54,13 +79,13 @@ export class OffloadGateway {
54
79
 
55
80
  private get o() { return this.options as OffloadGatewayOptions; }
56
81
 
57
- public async api(method: 'GET' | 'POST', route: string, body?: unknown): Promise<Record<string, any>> {
82
+ public async api(method: 'GET' | 'POST', route: string, body?: unknown, timeoutMs = this.o.requestTimeoutMs): Promise<Record<string, any>> {
58
83
  const url = `${this.o.gateway.replace(/\/+$/, '')}${route}`;
59
84
  const init = {
60
85
  method,
61
86
  headers: body ? { 'Content-Type': 'application/json' } : {},
62
87
  body: body ? JSON.stringify(body) : undefined,
63
- timeout: false, signal: AbortSignal.timeout(this.o.requestTimeoutMs), // explicit cap replaces Bun's implicit 300s
88
+ timeout: false, signal: AbortSignal.timeout(timeoutMs), // explicit cap replaces Bun's implicit 300s
64
89
  };
65
90
  const res = await this.o.fetch(url, init as RequestInit);
66
91
  const json = (await res.json().catch(() => ({}))) as Record<string, any>;
@@ -68,26 +93,42 @@ export class OffloadGateway {
68
93
  return json;
69
94
  }
70
95
 
71
- /** Poll a job to `done` and return its result. */
72
- public async waitJob(jobId: string): Promise<Record<string, any>> {
73
- for (const end = Date.now() + this.o.jobWaitMs; Date.now() < end;) {
96
+ /** Poll a job to `done` and return its result. A job that outlives `waitMs` is cancelled so it frees the pod. */
97
+ public async waitJob(jobId: string, waitMs = this.o.jobWaitMs): Promise<Record<string, any>> {
98
+ for (const end = Date.now() + waitMs; Date.now() < end;) {
74
99
  const j = await this.api('GET', `/media/job?jobId=${encodeURIComponent(jobId)}`);
75
100
  if (j.status === 'done') return (j.result ?? {}) as Record<string, any>;
76
101
  if (j.status === 'failed' || j.status === 'cancelled') throw new Error(`offload job ${jobId} ${j.status}: ${j.error ?? 'no error given'}`);
77
102
  await Bun.sleep(this.o.pollMs);
78
103
  }
79
- throw new Error(`offload job ${jobId} did not finish within ${Math.round(this.o.jobWaitMs / 60_000)}min`);
104
+ await this.api('POST', '/media/cancel', { jobId }).catch(e => console.error(`[offload] cancel of timed-out job ${jobId} failed: ${(e as Error).message}`));
105
+ throw new Error(`offload job ${jobId} did not finish within ${Math.round(waitMs / 1000)}s and was cancelled; no link was made. Send the file as an attachment instead, or retry later.`);
80
106
  }
81
107
 
82
- /** Have the gateway pull an agent `/uploads/...` path; returns the gateway-side file. */
83
- public async ingest(source: string): Promise<string> {
84
- let r = await this.api('POST', '/media/ingest', { source });
85
- if (r.async) r = await this.waitJob(String(r.jobId));
108
+ /** Have the gateway pull an agent `/uploads/...` path of `bytes`; returns the gateway-side file. The wait scales with
109
+ * the size (60s + 1s/MB) — the pull crosses the network, a flat cap cut large files off. */
110
+ public async ingest(source: string, bytes = 0): Promise<string> {
111
+ const waitMs = Math.max(this.o.requestTimeoutMs, 60_000 + Math.ceil(bytes / (1024 * 1024)) * 1000);
112
+ let r = await this.api('POST', '/media/ingest', { source }, waitMs);
113
+ if (r.async) r = await this.waitJob(String(r.jobId), Math.max(this.o.jobWaitMs, waitMs));
86
114
  if (!r.file) throw new Error(`offload ingest of ${source} returned no file: ${JSON.stringify(r)}`);
87
115
  return String(r.file);
88
116
  }
89
117
 
90
- /** Link for a gateway-side file: a transcoded preview for video, the original bytes otherwise. */
118
+ /** The gateway's advertised link origin, or undefined when it does not say (or cannot be asked). */
119
+ public async publicBase(): Promise<string | undefined> {
120
+ try {
121
+ const res = await this.o.fetch(`${this.o.gateway.replace(/\/+$/, '')}/media/health`, { signal: AbortSignal.timeout(this.o.requestTimeoutMs) });
122
+ const base = ((await res.json()) as Record<string, unknown>).publicBase; // health may be ok:false (degraded) and still say this
123
+ return typeof base === 'string' && base ? base : undefined;
124
+ } catch (e) {
125
+ console.warn(`[offload] could not read publicBase from ${this.o.gateway}/media/health: ${(e as Error).message}`);
126
+ return undefined;
127
+ }
128
+ }
129
+
130
+ /** Link for a gateway-side file: a transcoded preview for video, the original bytes otherwise (publish_url pins the
131
+ * file 7 days — inherent to that route and within the pod's normal retention, so harmless for a human share). */
91
132
  public async link(file: string, kind: MediaKind | undefined): Promise<string> {
92
133
  const expiresHours = this.o.expiresHours;
93
134
  if (kind === 'video') {
@@ -103,21 +144,30 @@ export class OffloadGateway {
103
144
 
104
145
  /** Stage `src` under `<dataDir>/uploads/<id>/` (hardlink, copy fallback), let the gateway ingest it, drop the
105
146
  * staging, and return a link. The staging exists only for the ingest, so the box's disk does not keep a copy. */
106
- public async share(src: string, dataDir: string, name: string): Promise<string> {
147
+ public async share(src: string, dataDir: string, name: string, bytes = 0): Promise<string> {
148
+ // Refuse before moving any bytes when the gateway says its links are private.
149
+ const base = await this.publicBase();
150
+ if (base && !isPublicUrl(base)) throw new OffloadPrivateLinkError(base);
107
151
  const id = `offload-${randomUUID()}`;
108
152
  const dir = path.join(dataDir, 'uploads', id);
109
153
  mkdirSync(dir, { recursive: true });
110
154
  try {
111
155
  const staged = path.join(dir, name);
112
156
  try { linkSync(src, staged); } catch { copyFileSync(src, staged); }
113
- const file = await this.ingest(`/uploads/${id}/${encodeURIComponent(name)}`);
114
- return await this.link(file, mediaKind(name));
157
+ const file = await this.ingest(`/uploads/${id}/${encodeURIComponent(name)}`, bytes);
158
+ const url = await this.link(file, mediaKind(name));
159
+ if (!isPublicUrl(url)) throw new OffloadPrivateLinkError(url);
160
+ return url;
115
161
  } finally {
116
162
  rmSync(dir, { recursive: true, force: true });
117
163
  }
118
164
  }
119
165
  }
120
166
 
167
+ export class OffloadPrivateLinkError extends Error {
168
+ public constructor(public readonly link: string) { super(OFFLOAD_PRIVATE_LINK_ERROR); }
169
+ }
170
+
121
171
  /** Env handed to agent subprocesses so scripts can tell they run on an offloading box. Empty when unset. */
122
172
  export function offloadEnv(cfg = getOffload()): Record<string, string> {
123
173
  return cfg ? { SHRAGA_OFFLOAD: '1', SHRAGA_OFFLOAD_GATEWAY: cfg.gateway, SHRAGA_OFFLOAD_MAX_LOCAL_FILE_MB: String(cfg.maxLocalFileMB) } : {};
@@ -131,7 +181,7 @@ export function buildOffloadContextBlock(cfg = getOffload()): string {
131
181
  `This box is LOW-RESOURCE. Heavy work runs on an external pod behind the gateway ${cfg.gateway} (use its MCP tools).`,
132
182
  `- Generation, rendering, encoding/transcoding, large downloads, and any file over ${cfg.maxLocalFileMB}MB go through the gateway tools — never locally.`,
133
183
  '- Never run local ffmpeg encodes or remotion renders, and never hand-start media servers (mcp-video/mcp-audio) here; such Bash commands are refused. ffprobe and analysis are fine.',
134
- '- To share media, use the gateway\'s preview tool, or share_file (it routes media and large files through the gateway).',
184
+ `- To share a file with people, use share_file. Files up to ${cfg.maxLocalFileMB}MB (media included) get a link from this box. Larger files go through the pod, but ONLY when the pod has a public link origin; otherwise share_file refuses — then send the file as a Slack/email attachment or ask an operator. Never hand people a gateway/pod link yourself (e.g. from its preview tool) unless it is a public https URL — tailnet/private links do not open for them.`,
135
185
  '</offload>',
136
186
  ].join('\n');
137
187
  }
@@ -139,15 +189,43 @@ export function buildOffloadContextBlock(cfg = getOffload()): string {
139
189
  // ── Heavy-command guard ─────────────────────────────────────────────────────────────────────────────
140
190
 
141
191
  /** Split a shell command into simple-command word lists on unquoted `; & | \n` (quote-aware, not a full shell parser;
142
- * `bash -c "…"` / `$(…)` are not unpacked — this is a guardrail against the obvious, not a sandbox). */
192
+ * `bash -c "…"` / `$(…)` are not unpacked — this is a guardrail against the obvious, not a sandbox). Redirections
193
+ * (`> f`, `2>&1`, `&>/dev/null`) are dropped, and heredoc bodies are skipped — they are data, not commands. */
143
194
  export function shellSegments(cmd: string): string[][] {
144
195
  const segs: string[][] = [];
196
+ const heredocs: string[] = [];
145
197
  let words: string[] = [], word = '', quote: string | null = null, inWord = false;
146
198
  const endWord = () => { if (inWord) words.push(word); word = ''; inWord = false; };
147
199
  const endSeg = () => { endWord(); if (words.length) segs.push(words); words = []; };
148
200
  for (let i = 0; i < cmd.length; i++) {
149
201
  const c = cmd[i]!;
150
202
  if (quote) { if (c === quote) quote = null; else if (c === '\\' && quote === '"' && i + 1 < cmd.length) word += cmd[++i]; else word += c; continue; }
203
+ if (c === '<' && cmd[i + 1] === '<' && cmd[i + 2] !== '<') { // heredoc: remember the delimiter, skip the body at the next newline
204
+ const m = cmd.slice(i + 2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);
205
+ if (m) { endWord(); heredocs.push(m[2]!); i += 1 + m[0].length; continue; }
206
+ }
207
+ if (c === '\n' && heredocs.length) {
208
+ endSeg();
209
+ for (const delim of heredocs.splice(0)) {
210
+ const end = cmd.slice(i + 1).search(new RegExp(`^[ \\t]*${delim}[ \\t]*$`, 'm'));
211
+ if (end < 0) { i = cmd.length; break; }
212
+ i += 1 + end + cmd.slice(i + 1 + end).indexOf(delim) + delim.length;
213
+ }
214
+ continue;
215
+ }
216
+ if (c === '>' || c === '<' || (c === '&' && cmd[i + 1] === '>')) { // redirection: drop the fd, the operator and its target
217
+ if (inWord && /^\d+$/.test(word)) { word = ''; inWord = false; } else endWord();
218
+ while (/[<>&]/.test(cmd[i + 1] ?? '')) i++;
219
+ if (/\d/.test(cmd[i + 1] ?? '') && cmd[i] === '&') { while (/\d/.test(cmd[i + 1] ?? '')) i++; continue; } // >&1
220
+ while (cmd[i + 1] === ' ' || cmd[i + 1] === '\t') i++;
221
+ let tq: string | null = null;
222
+ while (i + 1 < cmd.length) {
223
+ const t = cmd[i + 1]!;
224
+ if (tq) { if (t === tq) tq = null; } else if (t === '"' || t === "'") tq = t; else if (/[\s;&|()<>]/.test(t)) break;
225
+ i++;
226
+ }
227
+ continue;
228
+ }
151
229
  if (c === '"' || c === "'") { quote = c; inWord = true; }
152
230
  else if (c === '\\' && i + 1 < cmd.length) { word += cmd[++i]; inWord = true; }
153
231
  else if (c === ';' || c === '&' || c === '|' || c === '\n' || c === '(' || c === ')') endSeg();
@@ -161,6 +239,7 @@ export function shellSegments(cmd: string): string[][] {
161
239
  const WRAPPERS = new Set(['sudo', 'nice', 'nohup', 'exec', 'time', 'command', 'env', 'timeout']);
162
240
  const RUNNERS = new Set(['npx', 'bunx', 'pnpx']);
163
241
  const IMAGE_OUT = /\.(png|jpe?g|bmp|ppm|webp|gif|tiff?)$/i;
242
+ const AUDIO_OUT = /\.(wav|mp3|m4a|aac|flac|ogg|opus)$/i;
164
243
 
165
244
  /** ffmpeg argv (no binary) that encodes/transcodes a real output — vs analysis, stream copy, frame grabs, stdout. */
166
245
  function heavyFfmpeg(args: string[]): boolean {
@@ -171,6 +250,8 @@ function heavyFfmpeg(args: string[]): boolean {
171
250
  const frames = Number(val('-frames:v', '-vframes'));
172
251
  if (Number.isFinite(frames) && frames <= 2) return false;
173
252
  const out = args[args.length - 1]!;
253
+ // Audio-only extraction (`-vn`, or an audio-only output container) never touches a video encoder.
254
+ if (args.includes('-vn') || AUDIO_OUT.test(out)) return false;
174
255
  return !(out === '-' || out.startsWith('pipe:') || out === '/dev/null' || IMAGE_OUT.test(out));
175
256
  }
176
257
 
@@ -190,7 +271,7 @@ export function heavyLocalCommand(cmd: string): string | null {
190
271
  if (RUNNERS.has(bin) || ((bin === 'bun' || bin === 'pnpm' || bin === 'yarn') && rest[0] === 'x')) {
191
272
  if (bin !== 'npx' && bin !== 'bunx' && bin !== 'pnpx') rest = rest.slice(1);
192
273
  while (rest[0]?.startsWith('-')) rest = rest.slice(1);
193
- if (/^(@remotion\/cli|remotion)(@.*)?$/.test(rest[0] ?? '')) return 'a remotion command';
274
+ if (/^(@remotion\/cli|remotion)(@.*)?$/.test(rest[0] ?? '') && !rest.slice(1).some(a => /^(--help|-h|--version|-v|help|versions)$/.test(a))) return 'a remotion command';
194
275
  if (rest[0] === 'ffmpeg' && heavyFfmpeg(rest.slice(1))) return 'an ffmpeg encode';
195
276
  continue;
196
277
  }
@@ -10,7 +10,7 @@ import path from 'node:path';
10
10
  import { z } from 'zod/v4';
11
11
  import { DATA_DIR } from './paths.ts';
12
12
  import { getOffload, getPublicOrigin, type OffloadSettings } from './shraga-config.ts';
13
- import { OffloadGateway, shouldOffloadShare } from './offload.ts';
13
+ import { OffloadGateway, OffloadPrivateLinkError, shouldOffloadShare } from './offload.ts';
14
14
  import { WORKSPACE_DIR } from './workspace.ts';
15
15
  import { SHARE_SERVER, SHARE_TOOL, touchesSecretPath } from './security/enforce.ts';
16
16
 
@@ -25,7 +25,7 @@ export class FileSharerOptions {
25
25
  /** Largest file that may be published. */
26
26
  maxBytes: number = MAX_SHARE_BYTES;
27
27
  origin: () => string = getPublicOrigin;
28
- /** When set, media and files over `maxLocalFileMB` are shared through the offload gateway, not copied here. */
28
+ /** When set, files over `maxLocalFileMB` are shared through the offload gateway (only if it mints public links). */
29
29
  offload: () => OffloadSettings | undefined = getOffload;
30
30
  gateway: (cfg: OffloadSettings) => OffloadGateway = (cfg) => new OffloadGateway({ gateway: cfg.gateway });
31
31
  }
@@ -74,9 +74,15 @@ export class FileSharer {
74
74
  if ('error' in c) return { ok: false, error: c.error };
75
75
  const { src, bytes } = c;
76
76
  const safe = (name || path.basename(src)).normalize('NFKD').replace(/[^\w.-]+/g, '-').replace(/^[.-]+/, '').slice(-100) || 'file';
77
- // Low-resource box: media/large files never land in uploads/shared — the gateway ingests and links them.
78
- if (shouldOffloadShare(safe, bytes, offload)) {
79
- return { ok: true, url: await this.o.gateway(offload!).share(src, this.o.dataDir, safe), path: src, bytes, offloaded: true };
77
+ // Low-resource box: large files never land in uploads/shared — the gateway ingests and links them, but only a
78
+ // link the recipient can open is returned (a tailnet-only pod link is refused, not handed out).
79
+ if (shouldOffloadShare(bytes, offload)) {
80
+ try {
81
+ return { ok: true, url: await this.o.gateway(offload!).share(src, this.o.dataDir, safe, bytes), path: src, bytes, offloaded: true };
82
+ } catch (e) {
83
+ if (e instanceof OffloadPrivateLinkError) { console.warn(`[share] offload gateway link is not public (${e.link}); refusing`); return { ok: false, error: e.message }; }
84
+ throw e;
85
+ }
80
86
  }
81
87
  if (!origin) return { ok: false, error: 'This deployment has no public origin, so no share link can be made for this file. Send it as an attachment instead (e.g. Slack file upload).' };
82
88
  const fileName = `${randomBytes(16).toString('hex')}-${safe}`;
@@ -110,7 +116,7 @@ export function shareMcpServer(sharer = new FileSharer()) {
110
116
  version: '1.0.0',
111
117
  tools: [tool(
112
118
  SHARE_TOOL,
113
- 'Publish a local file (video, image, PDF, …) and get a public link to send the user. The ONLY valid way to make a file link — never construct share URLs by hand. Anyone with the link can open it (no login).',
119
+ 'Publish a local file (video, image, PDF, …) and get a public link to send the user. The ONLY valid way to make a file link — never construct share URLs by hand. Anyone with the link can open it (no login). If it refuses (e.g. the file is too large to link from here), send the file as a Slack/email attachment instead.',
114
120
  {
115
121
  file_path: z.string().min(1).describe('Absolute path of the file (must be under the workspace; move deliverables there first).'),
116
122
  name: z.string().max(200).optional().describe('Download name, e.g. "ad-v2.mp4". Defaults to the file name.'),