shraga 0.1.114 → 0.1.115
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.
|
@@ -1904,7 +1904,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),pn=ge,kt=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"},dz=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 dz(e,"overflowY")},mre=function(e){return dz(e,"overflowX")},zM=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=fz(e,r);if(i){var a=hz(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]},fz=function(e,t){return e==="v"?hre(t):mre(t)},hz=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=hz(e,l),w=g[0],x=g[1],E=g[2],_=x-E-a*w;(w||_)&&fz(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(uz)[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 j=window.getSelection(),L=j&&j.anchorNode,P=L?L===T||L.contains(T):!1;if(P)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 D=r.current||C;return yre(D,E,x,D==="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(cz,Ere);var vS=b.forwardRef(function(e,t){return b.createElement(Wv,ga({},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,mz=function(e){return e&&(e.host||mz(e.parentNode))},kre=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=mz(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={})}},pz=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",[gz]=fL(Yv),[Nre,Xi]=gz(Yv),vz=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})};vz.displayName=Yv;var yz="DialogTrigger",bz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(yz,n),a=ci(t,i.triggerRef);return y.jsx(Br.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:xr(e.onClick,i.onOpenToggle)})});bz.displayName=yz;var yS="DialogPortal",[Cre,xz]=gz(yS,{forceMount:void 0}),wz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Xi(yS,t);return y.jsx(Cre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Vs,{present:n||a.open,children:y.jsx(sz,{asChild:!0,container:i,children:s})}))})};wz.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=xz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xi(Pg,e.__scopeDialog);return a.modal?y.jsx(Vs,{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=Xi(Pg,n),a=Mne(),s=ci(t,a);return y.jsx(vS,{as:Tre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Br.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Bu="DialogContent",xS=b.forwardRef((e,t)=>{const n=xz(Bu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xi(Bu,e.__scopeDialog);return y.jsx(Vs,{present:r||a.open,children:a.modal?y.jsx(Ire,{...i,ref:t}):y.jsx(Rre,{...i,ref:t})})});xS.displayName=Bu;var Ire=b.forwardRef((e,t)=>{const n=Xi(Bu,e.__scopeDialog),r=b.useRef(null),i=ci(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return pz(a)},[]),y.jsx(Ez,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:xr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:xr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:xr(e.onFocusOutside,a=>a.preventDefault())})}),Rre=b.forwardRef((e,t)=>{const n=Xi(Bu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Ez,{...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()}})}),Ez=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Xi(Bu,n);return Hne(),y.jsx(y.Fragment,{children:y.jsx(az,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(rz,{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)})})})}),Sz="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(Sz,n);return y.jsx(Br.h2,{id:i.titleId,...r,ref:t})});wS.displayName=Sz;var _z="DialogDescription",Pre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(_z,n);return y.jsx(Br.p,{id:i.descriptionId,...r,ref:t})});Pre.displayName=_z;var Az="DialogClose",kz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(Az,n);return y.jsx(Br.button,{type:"button",...r,ref:t,onClick:xr(e.onClick,()=>i.onOpenChange(!1))})});kz.displayName=Az;function ES(e){return e?"open":"closed"}const So=vz,nd=bz,Dre=wz,Oz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:$e("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}));Oz.displayName=bS.displayName;const _a=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Dre,{children:[y.jsx(Oz,{}),y.jsxs(xS,{ref:r,className:$e("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(kz,{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(Zl,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_a.displayName=xS.displayName;function Ls({className:e,...t}){return y.jsx("div",{className:$e("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Nz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:$e("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{className:$e("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 _o=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:$e("text-lg font-semibold leading-none tracking-tight",e),...t}));_o.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([]),j=b.useCallback(async U=>{const K=await zre(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{j(""),a.forEach(U=>j(U))},[j,n]);const L=r.get("")??[],P=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),Q=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&Q&&E({w:F,h:Q})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,Q=U.clientWidth-F,$=U.clientHeight-F,R=Math.min(Q/K.w,$/K.h,1);w({scale:R,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 D=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||j(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 Q;const K=await e();if(!K)return;O(K);const F=((Q=U.split(".").pop())==null?void 0:Q.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 R=await $.json();u({path:U,content:R.content,binary:!!R.binary})}catch{}},Y=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const Q=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>D(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(Gs,{className:$e("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:Q})]}):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:Q})]}),F.type==="dir"&&a.has(F.path)&&Y(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:()=>{j(""),a.forEach(U=>j(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:y.jsx(Ju,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:L.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."}):Y(L,0)}),y.jsx(So,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(_a,{className:$e(l!=null&&l.html?$e("!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(sL,{className:"w-4 h-4"})})]}),y.jsx(Ls,{className:$e((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(_o,{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:$e(l!=null&&l.html?$e("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=>{P(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=>P(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(u3,{remarkPlugins:[P3],rehypePlugins:[nz],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(So,{open:N,onOpenChange:C,children:y.jsxs(_a,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Ls,{children:y.jsx(_o,{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,rd=(e,t)=>Hre(e,"name",{value:t,configurable:!0}),Tz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Is(e,t,{checkForDefaultPrevented:n=!0}={}){return rd(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}rd(Is,"composeEventHandlers");function Kre(e){var t;if(!Tz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}rd(Kre,"getOwnerWindow");function s1(e){if(!Tz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}rd(s1,"getOwnerDocument");function Mz(e,t=!1){const{activeElement:n}=s1(e);if(!(n!=null&&n.nodeName))return null;if(Iz(n)&&n.contentDocument)return Mz(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}rd(Mz,"getActiveElement");function Iz(e){return e.tagName==="IFRAME"}rd(Iz,"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 Rz(...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(Rz,"composeRefs");function id(...e){return b.useCallback(Rz(...e),e)}SS(id,"useComposedRefs");var Gre=Object.defineProperty,Oi=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function Vre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Oi(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 Oi(i,"useContext"),[r,i]}Oi(Vre,"createContext");function Pz(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=Oi(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 Oi(h,"useContext"),[d,h]}Oi(r,"createContext");const i=Oi(()=>{const a=n.map(s=>b.createContext(s));return Oi(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,Dz(i,...t)]}Oi(Pz,"createContextScope");function Dz(...e){const t=e[0];if(e.length===1)return t;const n=Oi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Oi(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}Oi(Dz,"composeContextScopes");var Wre=Object.defineProperty,Zi=(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($z(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?zz(s):void 0,h=id(r,d);if(!s){if(i||i===0)throw new Error(l?Jre(e):Qre(e));return i}const m=Lz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}Zi(_S,"createSlot");var jz=Symbol.for("radix.slottable");function Yre(e){const t=Zi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=jz,t}Zi(Yre,"createSlottable");var Xre=Zi((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 Lz(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}}Zi(Lz,"mergeProps");function zz(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)}Zi(zz,"getElementRef");function $z(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===jz}Zi($z,"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&&Bz(e._payload)}Zi(c1,"isLazyComponent");function Bz(e){return typeof e=="object"&&e!==null&&"then"in e}Zi(Bz,"isPromiseLike");var Qre=Zi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Jre=Zi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=Ia[" 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 Uz(e,t){e&&Ra.flushSync(()=>e.dispatchEvent(t))}tie(Uz,"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,Un=(e,t)=>aie(e,"name",{value:t,configurable:!0}),u1="dismissableLayer.update",oie="dismissableLayer.pointerDownOutside",sie="dismissableLayer.focusOutside",UM,Fz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),lie=b.forwardRef(Un(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(Fz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=id(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),j=Hz(D=>{s==null||s(D),u==null||u(D),D.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(D=>{if(!(D instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(D));return T&&!G},[m.branches,T])}),L=Kz(D=>{if(i&&M.current)return;const G=D.target;[...m.branches].some(Y=>Y.contains(G))||(l==null||l(D),u==null||u(D),D.defaultPrevented||d==null||d())},w),P=p?N===_.length-1:!1,H=Zv(D=>{D.key==="Escape"&&(a==null||a(D),!D.defaultPrevented&&d&&(D.preventDefault(),d()))});return b.useEffect(()=>{if(P)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,P,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 D=Un(()=>x({}),"handleUpdate");return document.addEventListener(u1,D),()=>document.removeEventListener(u1,D)},[]),y.jsx(Xv.div,{...h,ref:E,style:{pointerEvents:C?T?"auto":"none":void 0,...t.style},onFocusCapture:Is(t.onFocusCapture,L.onFocusCapture),onBlurCapture:Is(t.onBlurCapture,L.onBlurCapture),onPointerDownCapture:Is(t.onPointerDownCapture,j.onPointerDownCapture)})},"DismissableLayer"));function cie(){const e=b.useContext(Fz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}Un(cie,"useDismissableLayerSurface");var uie=Un(()=>!0,"IS_TRUE");function Hz(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()}Un(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}Un(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)}Un(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}Un(x,"handleInteractionBubble");const E=Un(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(Un(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:Un(()=>u.current=!0,"onPointerDownCapture")}}Un(Hz,"usePointerDownOutside");function Kz(e,t=globalThis==null?void 0:globalThis.document){const n=Zv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=Un(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:Un(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Un(()=>r.current=!1,"onBlurCapture")}}Un(Kz,"useFocusOutside");function d1(){const e=new CustomEvent(u1);document.dispatchEvent(e)}Un(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?Uz(i,a):i.dispatchEvent(a)}Un(AS,"handleAndDispatchCustomEvent");var die=Object.defineProperty,kS=(e,t)=>die(e,"name",{value:t,configurable:!0}),Tp=0,sa=null;function fie(e){return OS(),e.children}kS(fie,"FocusGuards");function OS(){b.useEffect(()=>{sa||(sa={start:f1(),end:f1()});const{start:e,end:t}=sa;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(sa==null||sa.start.remove(),sa==null||sa.end.remove(),sa=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,vr=(e,t)=>pie(e,"name",{value:t,configurable:!0}),zx="focusScope.autoFocusOnMount",$x="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},gie=b.forwardRef(vr(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=id(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:oo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const C=N.relatedTarget;C!==null&&(u.contains(C)||oo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const T of N)T.removedNodes.length>0&&oo(u)};vr(E,"handleFocusIn"),vr(_,"handleFocusOut"),vr(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||(qz(Xz(NS(u)),{select:!0}),document.activeElement===E&&oo(u))}return()=>{u.removeEventListener(zx,h),setTimeout(()=>{const k=new CustomEvent($x,FM);u.addEventListener($x,m),u.dispatchEvent(k),k.defaultPrevented||oo(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]=Gz(O);N&&C?!E.shiftKey&&k===C?(E.preventDefault(),r&&oo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&oo(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 qz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(oo(r,{select:t}),document.activeElement!==n)return}vr(qz,"focusFirst");function Gz(e){const t=NS(e),n=m1(t,e),r=m1(t.reverse(),e);return[n,r]}vr(Gz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:vr(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}vr(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}):Vz(r,{upTo:t})))return r}vr(m1,"findVisible");function Vz(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}vr(Vz,"isHidden");function Wz(e){return e instanceof HTMLInputElement&&"select"in e}vr(Wz,"isSelectableInput");function oo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Wz(e)&&t&&e.select()}}vr(oo,"focus");var HM=Yz();function Yz(){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()}}}vr(Yz,"createFocusScopesStack");function p1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}vr(p1,"arrayRemove");function Xz(e){return e.filter(t=>t.tagName!=="A")}vr(Xz,"removeLinks");var vie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0}),xie=Ia[" useId ".trim().toString()]||(()=>{}),wie=0;function Zz(e){const[t,n]=b.useState(xie());return vie(()=>{e||n(r=>r??String(wie++))},[e]),e||(t?`radix-${t}`:"")}bie(Zz,"useId");const Eie=["top","right","bottom","left"],zs=Math.min,go=Math.max,Dg=Math.round,Mp=Math.floor,vo=e=>({x:e,y:e}),Sie={left:"right",right:"left",bottom:"top",top:"bottom"};function Qz(e,t,n){return go(e,zs(t,n))}function Ao(e,t){return typeof e=="function"?e(t):e}function $s(e){return e.split("-")[0]}function ad(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function va(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(va(e))}function _ie(e,t,n){n===void 0&&(n=!1);const r=ad(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=ad(e);let a=Nie($s(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=$s(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 Jz(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=va(t),s=MS(t),l=TS(s),u=$s(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=ad(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}=Ao(t,e),w=Jz(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}=Ao(e,t)||{};if(d==null)return{};const m=Jz(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 j=N/2-C/2,L=M/2-x[w]/2-1,P=zs(m[_],L),H=zs(m[k],L),D=M-x[w]-H,G=M/2-x[w]/2+j,q=Qz(P,G,D),Y=!u.arrow&&ad(i)!=null&&G!==q&&a.reference[w]/2-(G<P?P:H)-x[w]/2<0,U=Y?G<P?G-P:G-D:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...Y&&{alignmentOffset:U}},reset:Y}}}),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}=Ao(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=$s(i),k=va(l),O=$s(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],j=await u.detectOverflow(t,E),L=[];let P=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&L.push(j[_]),m){const q=_ie(i,s,N);L.push(j[q[0]],j[q[1]])}if(P=[...P,{placement:i,overflows:L}],!L.every(q=>q<=0)){var H,D;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,Y=M[q];if(Y&&(!(m==="alignment"?k!==va(Y):!1)||P.every(F=>va(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:P},reset:{placement:Y}};let U=(D=P.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:D.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=P.filter(F=>{if(T){const Q=va(F.placement);return Q===k||Q==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(Q=>Q>0).reduce((Q,$)=>Q+$,0)]).sort((F,Q)=>F[1]-Q[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}=Ao(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{}}}}},e$=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=$s(n),l=ad(n),u=va(n)==="y",d=e$.has(s)?-1:1,h=a&&u?-1:1,m=Ao(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}=Ao(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=va(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Qz(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}=Ao(e,t),p={x:i,y:a},g=va(s),w=CS(g);let x=p[w],E=p[g];const _=Ao(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=e$.has($s(s)),M=l.reference[g]-l.floating[C]+(T&&((O=u.offset)==null?void 0:O[g])||0)+(T?0:k.crossAxis),j=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>j&&(E=j)}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}=Ao(e,t),u=await i.detectOverflow(t,l),d=$s(n),h=ad(n),m=va(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=zs(g-u[w],E),O=zs(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*go(u.left,u.right):T=g-2*go(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:T});const j=await i.getDimensions(a.floating);return p!==j.width||g!==j.height?{reset:{rects:!0}}:{}}}};function Qv(){return typeof window<"u"}function od(e){return t$(e)?(e.nodeName||"").toLowerCase():"#document"}function $r(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Io(e){var t;return(t=(t$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function t$(e){return Qv()?e instanceof Node||e instanceof $r(e).Node:!1}function Aa(e){return Qv()?e instanceof Element||e instanceof $r(e).Element:!1}function Ys(e){return Qv()?e instanceof HTMLElement||e instanceof $r(e).HTMLElement:!1}function YM(e){return!Qv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof $r(e).ShadowRoot}function Jv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ka(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fie(e){return/^(table|td|th)$/.test(od(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/,Sl=e=>!!e&&e!=="none";let Bx;function IS(e){const t=Aa(e)?ka(e):e;return Sl(t.transform)||Sl(t.translate)||Sl(t.scale)||Sl(t.rotate)||Sl(t.perspective)||!RS()&&(Sl(t.backdropFilter)||Sl(t.filter))||Hie.test(t.willChange||"")||Kie.test(t.contain||"")}function qie(e){let t=Jl(e);for(;Ys(t)&&!th(t);){if(IS(t))return t;if(ey(t))return null;t=Jl(t)}return null}function RS(){return Bx==null&&(Bx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Bx}function th(e){return/^(html|body|#document)$/.test(od(e))}function ka(e){return $r(e).getComputedStyle(e)}function ty(e){return Aa(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Jl(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||Io(e);return YM(t)?t.host:t}function n$(e){const t=Jl(e);return th(t)?(e.ownerDocument||e).body:Ys(t)&&Jv(t)?t:n$(t)}function nh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=n$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=$r(i);if(a){const l=v1(s);return t.concat(s,s.visualViewport||[],Jv(i)?i:[],l&&n?nh(l):[])}else return t.concat(i,nh(i,[],n))}function v1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function r$(e){const t=ka(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ys(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 Aa(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Ys(t))return vo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=r$(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=vo(0);function i$(e){const t=$r(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===$r(e)}function ec(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=vo(1);t&&(r?Aa(r)&&(s=Tu(r)):s=Tu(e));const l=Vie(a,n,r)?i$(a):vo(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=$r(a),g=Aa(r)?$r(r):r;let w=p,x=v1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=ka(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=$r(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:ec(Io(e)).left+n}function a$(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=Io(r),l=t?ey(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=vo(1);const h=vo(0),m=Ys(r);if((m||!a)&&((od(r)!=="body"||Jv(s))&&(u=ty(r)),m)){const g=ec(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?a$(s,u):vo(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=go(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=go(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ny(e);const s=-t.scrollTop;return ka(n).direction==="rtl"&&(a+=go(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=$r(e),a=Io(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=ec(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(Io(e));else if(Aa(t))r=Jie(t,n);else{const i=i$(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=nh(e,[],!1).filter(l=>Aa(l)&&od(l)!=="body"),i=null;const a=ka(e).position==="fixed";let s=a?Jl(e):e;for(;Aa(s)&&!th(s);){const l=ka(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=Jl(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=go(g.top,u),d=zs(g.right,d),h=zs(g.bottom,h),m=go(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function nae(e){const{width:t,height:n}=r$(e);return{width:t,height:n}}function rae(e,t,n){const r=Ys(t),i=Io(t),a=n==="fixed",s=ec(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=vo(0);if((r||!a)&&((od(t)!=="body"||Jv(i))&&(l=ty(t)),r)){const p=ec(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?a$(i,l):vo(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 ka(e).position==="static"}function ZM(e,t){if(!Ys(e)||ka(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Io(e)===n&&(n=n.ownerDocument.body),n}function o$(e,t){const n=$r(e);if(ey(e))return n;if(!Ys(e)){let i=Jl(e);for(;i&&!th(i);){if(Aa(i)&&!Ux(i))return i;i=Jl(i)}return n}let r=ZM(e,t);for(;r&&Fie(r)&&Ux(r);)r=ZM(r,t);return r&&th(r)&&Ux(r)&&!IS(r)?n:r||qie(e)||n}const iae=async function(e){const t=this.getOffsetParent||o$,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 ka(e).direction==="rtl"}const oae={convertOffsetParentRelativeRectToViewportRelativeRect:Wie,getDocumentElement:Io,getClippingRect:tae,getOffsetParent:o$,getElementRects:iae,getClientRects:Yie,getDimensions:nae,getScale:Tu,isElement:Aa,isRTL:aae};function s$(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=Io(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:go(0,zs(1,m))||1};let M=!0;function j(L){const P=L[0].intersectionRatio;if(!s$(p,e.getBoundingClientRect()))return l();if(P!==m){if(!M)return l();P?l(!1,P):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(j,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(j,T)}r.observe(e)}const u=$r(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?nh(d):[],...t?nh(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?ec(e):null;u&&E();function E(){const _=ec(e);x&&!s$(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 l$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=l$(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),j=b.useRef(h),L=u!=null,P=Fx(u),H=Fx(i),D=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(Q=>{const $={...Q,isPositioned:D.current!==!1};q.current&&!zg(j.current,$)&&(j.current=$,Ra.flushSync(()=>{m($)}))})},[p,t,n,H,D]);og(()=>{d===!1&&j.current.isPositioned&&(j.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(P.current)return P.current(N,C,G);G()}},[N,C,G,P,L]);const Y=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 Q=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+Q+"px, "+$+"px)",...l$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Q,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:Y,elements:U,floatingStyles:K}),[h,G,Y,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 c$(...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(c$,"composeRefs");function ry(...e){return b.useCallback(c$(...e),e)}DS(ry,"useComposedRefs");var Nae=Object.defineProperty,Ni=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function Cae(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(Cae,"createContext");function u$(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,d$(i,...t)]}Ni(u$,"createContextScope");function d$(...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(d$,"composeContextScopes");var Tae=Object.defineProperty,Qi=(e,t)=>Tae(e,"name",{value:t,configurable:!0});function f$(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(g$(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?p$(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=m$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}Qi(f$,"createSlot");var h$=Symbol.for("radix.slottable");function Mae(e){const t=Qi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=h$,t}Qi(Mae,"createSlottable");var Iae=Qi((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 m$(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}}Qi(m$,"mergeProps");function p$(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)}Qi(p$,"getElementRef");function g$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===h$}Qi(g$,"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&&v$(e._payload)}Qi(b1,"isLazyComponent");function v$(e){return typeof e=="object"&&e!==null&&"then"in e}Qi(v$,"isPromiseLike");var Pae=Qi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Dae=Qi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=Ia[" 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"],y$=zae.reduce((e,t)=>{const n=f$(`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&&Ra.flushSync(()=>e.dispatchEvent(t))}Lae($ae,"dispatchDiscreteCustomEvent");var Bae=Object.defineProperty,Uae=(e,t)=>Bae(e,"name",{value:t,configurable:!0});function b$(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(b$,"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 x$(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(x$,"useSize");var qae=Object.defineProperty,Rs=(e,t)=>qae(e,"name",{value:t,configurable:!0}),w$="Popper",[E$,S$]=u$(w$),[Gae,_$]=E$(w$),Vae=Rs(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(Rs(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=_$(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(y$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),A$="PopperContent",[Xae,sCe]=E$(A$),Zae=b.forwardRef(Rs(function(t,n){var pe,Ne,Ee,de,pt,qe,Ce;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$,r),[k,O]=b.useState(null),N=ry(n,O),[C,T]=b.useState(null),M=x$(C),j=(M==null?void 0:M.width)??0,L=(M==null?void 0:M.height)??0,P=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},D=Array.isArray(h)?h:[h],G=D.length>0,q={padding:H,boundary:D.filter(k$),altBoundary:G},{refs:Y,floatingStyles:U,placement:K,isPositioned:F,middlewareData:Q}=yae({strategy:"fixed",placement:P,whileElementsMounted:Rs((...De)=>lae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[xae({mainAxis:a+L,alignmentAxis:l}),d&&wae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Eae():void 0,...q}),d&&Sae({...q}),_ae({...q,apply:Rs(({elements:De,rects:zt,availableWidth:yn,availableHeight:_r})=>{const{width:qn,height:Hr}=zt.reference,ui=De.floating.style;ui.setProperty("--radix-popper-available-width",`${yn}px`),ui.setProperty("--radix-popper-available-height",`${_r}px`),ui.setProperty("--radix-popper-anchor-width",`${qn}px`),ui.setProperty("--radix-popper-anchor-height",`${Hr}px`)},"apply")}),C&&kae({element:C,padding:u}),Qae({arrowWidth:j,arrowHeight:L}),g&&Aae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Hx(()=>($(K),()=>{$(void 0)}),[K,$]);const[R,V]=iy(K),z=b$(x);Hx(()=>{F&&(z==null||z())},[F,z]);const ie=(pe=Q.arrow)==null?void 0:pe.x,me=(Ne=Q.arrow)==null?void 0:Ne.y,fe=((Ee=Q.arrow)==null?void 0:Ee.centerOffset)!==0,[_e,Ge]=b.useState();return Hx(()=>{k&&Ge(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:Y.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:_e,"--radix-popper-transform-origin":[(de=Q.transformOrigin)==null?void 0:de.x,(pt=Q.transformOrigin)==null?void 0:pt.y].join(" "),...((qe=Q.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Xae,{scope:r,placedSide:R,placedAlign:V,onArrowChange:T,arrowX:ie,arrowY:me,shouldHideArrow:fe,children:y.jsx(y$.div,{"data-side":R,"data-align":V,...E,ref:N,style:{...E.style,animation:F?(Ce=E.style)==null?void 0:Ce.animation:"none"}})})})},"PopperContent"));function k$(e){return e!==null}Rs(k$,"isNotNull");var Qae=Rs(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]}Rs(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?Ra.createPortal(y.jsx(Xv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ooe=Object.defineProperty,ko=(e,t)=>ooe(e,"name",{value:t,configurable:!0});function O$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}ko(O$,"useStateMachine");var N$=ko(e=>{const{present:t,children:n}=e,r=C$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=T$(r.ref,M$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function C$(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]=O$(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=ko(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=ko(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)},[])}}ko(C$,"usePresence");function x1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}ko(x1,"setRef");function T$(...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)}}},[])}ko(T$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}ko(bu,"getAnimationName");function M$(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)}ko(M$,"getElementRef");var I$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,loe=(e,t)=>soe(e,"name",{value:t,configurable:!0}),tI=Ia[" useEffectEvent ".trim().toString()],nI=Ia[" useInsertionEffect ".trim().toString()];function R$(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}):I$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}loe(R$,"useEffectEvent");var coe=Object.defineProperty,Nh=(e,t)=>coe(e,"name",{value:t,configurable:!0}),uoe=Ia[" useInsertionEffect ".trim().toString()]||I$;function P$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=D$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=j$(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(P$,"useControllableState");function D$({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(D$,"useUncontrolledState");function j$(e){return typeof e=="function"}Nh(j$,"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=R$(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,Xs=(e,t)=>foe(e,"name",{value:t,configurable:!0}),jS="Popover",[L$,lCe]=Pz(jS,[S$]),LS=S$(),[hoe,sd]=L$(jS),moe=Xs(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]=P$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(Jae,{...l,children:y.jsx(hoe,{scope:t,contentId:Zz(),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(Xs(function(t,n){const{__scopePopover:r,...i}=t,a=sd(poe,r),s=LS(r),l=id(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:Is(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(eoe,{asChild:!0,...s,children:u})},"PopoverTrigger")),z$="PopoverPortal",[voe,yoe]=L$(z$,{forceMount:void 0}),boe=Xs(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=sd(z$,t);return y.jsx(voe,{scope:t,forceMount:n,children:y.jsx(N$,{present:n||a.open,children:y.jsx(aoe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),rh="PopoverContent",xoe=b.forwardRef(Xs(function(t,n){const r=yoe(rh,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=sd(rh,t.__scopePopover);return y.jsx(N$,{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(Xs(function(t,n){const r=sd(rh,t.__scopePopover),i=b.useRef(null),a=id(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return pz(l)},[]),y.jsx(vS,{as:woe,allowPinchZoom:!0,children:y.jsx($$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Is(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Is(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:Is(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),Soe=b.forwardRef(Xs(function(t,n){const r=sd(rh,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx($$,{...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.forwardRef(Xs(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=sd(rh,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"}Xs(zS,"getState");var _oe=moe,Aoe=goe,koe=boe,B$=xoe;const Ooe=_oe,Noe=Aoe,U$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(koe,{children:y.jsx(B$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:$e("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})}));U$.displayName=B$.displayName;const F$=92,H$=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&&K$(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(U$,{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=K$(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:$e("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:$e("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:$e("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:$e("tabular-nums shrink-0",E1(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(q$,{value:n.percent,className:$e("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 K$(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>=H$?"critical":e>=F$?"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 ${F$}%, critical at ${H$}%`;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(q$,{value:t,className:a}),y.jsxs("span",{className:$e("tabular-nums",a),children:[t,"%"]})]})}function q$({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:$e("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:$e("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const Af=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(Af),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=Af);const k=b.useCallback(async(M,j)=>{const L=await e();if(!L||j!=null&&j.aborted)return null;const P=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:j,headers:{Authorization:`Bearer ${L}`}});if(!P.ok)return null;const H=await P.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,j,L)=>{const P=[];let H,D=null;for(;P.length<M;){const G={filter:j,limit:String(Math.min(Af,M-P.length))};H&&(G.before=H);const q=await k(G,L);if(!q)return null;if(P.push(...q.sessions),D=q.nextCursor,!D||!q.sessions.length)break;H=D}return{sessions:P,nextCursor:D}},[k]);b.useEffect(()=>{var j,L;(j=g.current)==null||j.abort(),(L=w.current)==null||L.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(P=>{!P||M.signal.aborted||(a(P.sessions),l(P.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var L;if(!s||u)return;(L=w.current)==null||L.abort();const M=new AbortController;w.current=M;const j=x.current;d(!0),k({filter:j,limit:String(Af),before:s},M.signal).then(P=>{!P||M.signal.aborted||j!==x.current||(a(H=>{const D=new Set(H.map(q=>q.sessionId)),G=[...H,...P.sessions.filter(q=>!D.has(q.sessionId))];return E.current=Math.max(Af,G.length),G}),l(P.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),C=b.useMemo(()=>{const M=new Map;for(const j of Object.values(h))M.set(j.sessionId,j);for(const j of i)M.set(j.sessionId,j);return M},[i,h]),T=r.join(",");return b.useEffect(()=>{const M=r.filter(L=>!!L&&!C.has(L)&&!p.current.has(L)).slice(0,200);if(!M.length)return;for(const L of M)p.current.add(L);let j=!1;return k({ids:M.join(",")}).then(L=>{!L||j||m(P=>{const H={...P};for(const D of L.sessions)H[D.sessionId]=D;return H})}).catch(()=>{}),()=>{j=!0}},[T,C,k]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:N}}const kf="0.1.114";async function $i(e,t,n){const r=await t();let i;try{i=await fetch(e,{...n,headers:{Authorization:`Bearer ${r??""}`,"Content-Type":"application/json",...n==null?void 0:n.headers}})}catch(a){throw $v(e,a),a}if(zv(e,i,n==null?void 0:n.expect),!i.ok){const a=await i.json().catch(()=>({}));throw Object.assign(new Error(a.error||`${i.status} ${i.statusText}`),{status:i.status})}return i.json()}function $S(e,t=!0){const[n,r]=b.useState();return b.useEffect(()=>{if(!t)return;let i=!0;return e().then(a=>{!a||!i||fetch("/api/config",{headers:{Authorization:`Bearer ${a}`}}).then(s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}).then(s=>{i&&r(!!s.isOwner)}).catch(s=>console.warn("[isOwner] load failed",s))}),()=>{i=!1}},[t,e]),n}function Foe(e){const t=$S(e),n=b.useCallback(async(r,i="GET",a)=>{try{return await $i(`/api/owner${r}`,e,{method:i,...a!==void 0?{body:JSON.stringify(a)}:{}})}catch(s){throw console.warn(`[owner] ${i} ${r} failed: ${(s==null?void 0:s.message)??s}`),s}},[e]);return{isOwner:t,call:n}}const G$=["user","email","slack","apikey","internal","anonymous"],wr="h-7 rounded-md border border-input bg-background px-2 text-xs",yr="h-7 text-xs",Tt="text-left font-medium text-muted-foreground px-2 py-1 whitespace-nowrap",Mt="px-2 py-1 align-top",sr="text-muted-foreground hover:text-foreground disabled:opacity-40 transition-colors",Kl=e=>new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),Hoe=e=>Object.entries(e).map(([t,n])=>`${t}=${Array.isArray(n)?n.join("|"):String(n)}`).join(" ");function ld(){const[e,t]=b.useState(null),[n,r]=b.useState(null);return{busy:e,error:n,run:async(a,s)=>{if(!e){t(a),r(null);try{await s()}catch(l){r((l==null?void 0:l.message)??String(l))}finally{t(null)}}}}}function Zs({error:e}){if(!e)return null;const t=/^Invalid policy: (.*)$/s.exec(e);return y.jsx("div",{className:"text-xs text-destructive border border-destructive/40 rounded-md p-2",children:t?y.jsxs(y.Fragment,{children:[y.jsx("p",{className:"font-medium",children:"Invalid policy — not saved:"}),y.jsx("ul",{className:"list-disc pl-4",children:t[1].split("; ").map((n,r)=>y.jsx("li",{children:n},r))})]}):e})}function V$({value:e,onChange:t,placeholder:n}){const r=(e??[]).join(", "),[i,a]=b.useState(r);return b.useEffect(()=>a(r),[r]),y.jsx(ht,{className:yr,value:i,placeholder:n,onChange:s=>a(s.target.value),onBlur:()=>t(i.split(",").map(s=>s.trim()).filter(Boolean))})}function W$(e,t,n=[]){return{canRevoke:r=>/^(user|internal):/.test(r)&&r!=="internal:agent-internal",canBlock:r=>!n.includes(r),revoke:async r=>{confirm(`Revoke every token issued to ${r}? They must sign in again.`)&&(await e("/tokens/revoke","POST",{principalId:r}),await t())},block:async r=>{const i=prompt(`Block ${r}? Reason (optional):`);i!==null&&(await e("/blocks","POST",{match:{id:r},until:null,reason:i}),await t())}}}const Koe=[["never",0],["1 day",1],["7 days",7],["30 days",30],["90 days",90]];function qoe({call:e,roles:t}){const[n,r]=b.useState(null),[i,a]=b.useState({label:"",role:"",days:0}),[s,l]=b.useState(null),{busy:u,error:d,run:h}=ld(),m=b.useCallback(async()=>r((await e("/api-keys")).keys),[e]);b.useEffect(()=>{h("load",m)},[m]);const p=()=>h("create",async()=>{const w=await e("/api-keys","POST",{label:i.label||"Unnamed",...i.role?{role:i.role}:{},...i.days?{expiresAt:Date.now()+i.days*864e5}:{}});l(w),a({label:"",role:"",days:0}),await m()}),g=w=>navigator.clipboard.writeText(w).catch(x=>console.warn("[owner] clipboard write failed",x));return y.jsxs("div",{className:"space-y-3",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-48`,placeholder:"label",value:i.label,onChange:w=>a({...i,label:w.target.value})}),y.jsxs("select",{className:wr,value:i.role,onChange:w=>a({...i,role:w.target.value}),title:"Role cap (never above the creator)",children:[y.jsx("option",{value:"",children:"role: creator's (uncapped)"}),t.map(w=>y.jsxs("option",{value:w,children:["role cap: ",w]},w))]}),y.jsx("select",{className:wr,value:i.days,onChange:w=>a({...i,days:Number(w.target.value)}),children:Koe.map(([w,x])=>y.jsxs("option",{value:x,children:["expires: ",w]},x))}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!u,onClick:p,children:[u==="create"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Create key"]})]}),s&&y.jsxs("div",{className:"border border-amber-500/50 bg-amber-500/10 rounded-lg p-2 space-y-1",children:[y.jsxs("p",{className:"text-xs font-medium",children:['Key "',s.label,`" — copy it now, it won't be shown again:`]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("code",{className:"text-xs font-mono break-all flex-1 select-all",children:s.key}),y.jsx("button",{className:sr,title:"Copy",onClick:()=>g(s.key),children:y.jsx(Bv,{className:"w-3.5 h-3.5"})}),y.jsx(we,{size:"sm",variant:"ghost",className:"h-6 text-xs",onClick:()=>l(null),children:"Done"})]})]}),y.jsx(Zs,{error:d}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Label"}),y.jsx("th",{className:Tt,children:"Key"}),y.jsx("th",{className:Tt,children:"Creator"}),y.jsx("th",{className:Tt,children:"Role"}),y.jsx("th",{className:Tt,children:"Created"}),y.jsx("th",{className:Tt,children:"Expires"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.map(w=>{const x=w.expiresAt!==void 0&&w.expiresAt<=Date.now();return y.jsxs("tr",{className:x?"opacity-50":"",children:[y.jsx("td",{className:Mt,children:w.label}),y.jsx("td",{className:`${Mt} font-mono`,children:w.keyPreview}),y.jsx("td",{className:Mt,children:w.email}),y.jsx("td",{className:Mt,children:w.role??y.jsx("span",{className:"text-muted-foreground",children:"creator's"})}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(w.createdAt)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:w.expiresAt?`${Kl(w.expiresAt)}${x?" (expired)":""}`:"never"}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Revoke",disabled:!!u,onClick:()=>{confirm(`Revoke key "${w.label}" (${w.keyPreview})?`)&&h(`rm-${w.id}`,async()=>{await e(`/api-keys/${w.id}`,"DELETE"),await m()})},children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},w.id)}),n&&!n.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:7,className:"text-center text-muted-foreground py-6",children:"No API keys."})})]})]})})]})}const Goe=({brokenAt:e,planted:t})=>[e&&!(e.reason==="not-regular-file"&&(t!=null&&t.length))?`chain broken at ${e.file||"audit dir"}${e.line?`:${e.line}`:""} (${e.reason})`:"",t!=null&&t.length?`planted entries (not regular files): ${t.join(", ")}`:""].filter(Boolean).join(" · ")||"chain verify failed",Voe=["auth.allow","auth.deny","role.resolve","turn.start","turn.end","tool.allow","tool.deny","guard.limit","guard.block","escalate","policy.change","policy.tamper","key.create","key.revoke","token.revoke","session.delete"],Woe=100;function Yoe({call:e,onOpenSession:t,onPolicyChange:n,ownerIds:r}){const[i,a]=b.useState({principal:"",type:"",from:"",to:""}),[s,l]=b.useState([]),[u,d]=b.useState(),[h,m]=b.useState(null),[p,g]=b.useState(new Set),{busy:w,error:x,run:E}=ld(),_=W$(e,n,r),k=(M,j,L)=>E(M,async()=>{try{await L()}catch(P){throw(P==null?void 0:P.status)!==404?P:(g(H=>new Set(H).add(j)),new Error("Conversation no longer exists"))}}),O=M=>{const j=new URLSearchParams({limit:String(Woe)});return i.principal.trim()&&j.set("principal",i.principal.trim()),i.type&&j.set("type",i.type),i.from&&j.set("from",new Date(i.from).toISOString()),i.to&&j.set("to",new Date(i.to).toISOString()),M&&j.set("cursor",M),e(`/audit?${j}`)},N=b.useCallback(()=>E("load",async()=>{const M=await O();l(M.items),d(M.nextCursor)}),[e,i]),C=()=>E("more",async()=>{const M=await O(u);l(j=>[...j,...M.items]),d(M.nextCursor)}),T=()=>E("verify",async()=>m(await e("/audit/verify")));return b.useEffect(()=>{N(),T()},[]),y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-56`,placeholder:"principal (exact id)",value:i.principal,onChange:M=>a({...i,principal:M.target.value}),onKeyDown:M=>M.key==="Enter"&&N()}),y.jsxs("select",{className:wr,value:i.type,onChange:M=>a({...i,type:M.target.value}),children:[y.jsx("option",{value:"",children:"all types"}),Voe.map(M=>y.jsx("option",{value:M,children:M},M))]}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"from"}),y.jsx("input",{type:"datetime-local",className:wr,value:i.from,onChange:M=>a({...i,from:M.target.value})}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"to"}),y.jsx("input",{type:"datetime-local",className:wr,value:i.to,onChange:M=>a({...i,to:M.target.value})}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!w,onClick:N,children:[w==="load"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Ju,{className:"w-3 h-3 mr-1"})," Search"]}),y.jsx("div",{className:"flex-1"}),h&&y.jsxs("button",{onClick:T,title:"Re-verify the hash chain",className:`flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border ${h.ok?"border-green-500/50 text-green-600 dark:text-green-400":"border-destructive text-destructive"}`,children:[h.ok?y.jsx(Sh,{className:"w-3.5 h-3.5"}):y.jsx(hV,{className:"w-3.5 h-3.5"}),h.ok?`chain verified · ${h.lines} lines`:Goe(h)]})]}),y.jsx(Zs,{error:x}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Time"}),y.jsx("th",{className:Tt,children:"Type"}),y.jsx("th",{className:Tt,children:"Principal"}),y.jsx("th",{className:Tt,children:"Role"}),y.jsx("th",{className:Tt,children:"Target / reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[s.map(M=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} whitespace-nowrap`,title:M.ts,children:Kl(M.ts)}),y.jsx("td",{className:`${Mt} font-mono whitespace-nowrap ${/deny|block|tamper/.test(M.type)?"text-destructive":""}`,children:M.type}),y.jsx("td",{className:`${Mt} font-mono break-all`,children:M.principal?y.jsx("button",{className:"hover:underline text-left",title:"Filter by this principal",onClick:()=>a({...i,principal:M.principal}),children:M.principal}):"—"}),y.jsx("td",{className:Mt,children:M.role??"—"}),y.jsx("td",{className:`${Mt} break-all`,children:[M.target,M.reason].filter(Boolean).join(" · ")||"—"}),y.jsxs("td",{className:`${Mt} whitespace-nowrap text-right`,children:[M.sessionId&&!p.has(M.sessionId)&&y.jsx("button",{className:`${sr} mr-2`,title:"Open session",disabled:!!w,onClick:()=>k("open",M.sessionId,()=>t(M.sessionId)),children:y.jsx(WG,{className:"w-3.5 h-3.5"})}),M.principal&&_.canRevoke(M.principal)&&y.jsx("button",{className:`${sr} mr-2`,title:"Revoke tokens",disabled:!!w,onClick:()=>E("rv",()=>_.revoke(M.principal)),children:y.jsx(cL,{className:"w-3.5 h-3.5"})}),M.principal&&_.canBlock(M.principal)&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Block principal",disabled:!!w,onClick:()=>E("bl",()=>_.block(M.principal)),children:y.jsx(oL,{className:"w-3.5 h-3.5"})})]})]},M.hash)),!s.length&&w!=="load"&&y.jsx("tr",{children:y.jsx("td",{colSpan:6,className:"text-center text-muted-foreground py-6",children:"No audit records match."})})]})]})}),u&&y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!!w,onClick:C,children:[w==="more"&&y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"})," Load older"]})]})}const au=e=>{const{blocklist:t,tokensValidAfter:n,...r}=e;return JSON.stringify(r)};function Y$(e,t,n){const[r,i]=b.useState(e),[a,s]=b.useState(()=>structuredClone(e.policy)),l=au(a)!==au(r.policy);b.useEffect(()=>{!l||au(e.policy)===au(a)?(i(e),s(structuredClone(e.policy))):au(e.policy)===au(r.policy)&&i(e)},[e]),b.useEffect(()=>{n==null||n(l)},[l,n]),b.useEffect(()=>()=>n==null?void 0:n(!1),[n]);const u=ld(),d=y.jsxs("div",{className:"flex items-center gap-2 sticky -bottom-3 z-10 -mx-3 -mb-3 px-3 pt-2 pb-3 bg-background border-t",children:[y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!l||!!u.busy,onClick:()=>u.run("save",()=>t(a,r.version)),children:[u.busy?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(qi,{className:"w-3 h-3 mr-1"})," Save policy"]}),y.jsxs(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",disabled:!l,onClick:()=>{i(e),s(structuredClone(e.policy))},children:[y.jsx(yV,{className:"w-3 h-3 mr-1"})," Discard"]}),l&&y.jsx("span",{className:"text-[10px] text-amber-500",children:"unsaved changes"})]});return{draft:a,setDraft:s,error:u.error,saveBar:d}}function Xoe({doc:e,save:t,onDirty:n}){const{draft:r,setDraft:i,error:a,saveBar:s}=Y$(e,t,n),[l,u]=b.useState(""),[d,h]=b.useState(""),m=Object.keys(r.profiles),p=(x,E)=>i(_=>({..._,roles:{..._.roles,[x]:{..._.roles[x],...E}}})),g=(x,E)=>i(_=>({..._,profiles:{..._.profiles,[x]:{..._.profiles[x],...E}}})),w=(x,E)=>Object.fromEntries(Object.entries(x).filter(([_])=>_!==E));return y.jsxs("div",{className:"space-y-4",children:[y.jsx(Zs,{error:a}),y.jsxs("section",{className:"space-y-2",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Roles"}),y.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Owners come only from the OWNERS env; this row only picks their rank and profile."}),y.jsx("div",{className:"border rounded-lg divide-y",children:Object.entries(r.roles).sort((x,E)=>E[1].rank-x[1].rank).map(([x,E])=>y.jsxs("div",{className:"flex items-center gap-2 p-2",children:[y.jsx("span",{className:"text-sm font-medium w-28 truncate",children:x}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"rank"}),y.jsx(ht,{type:"number",className:`${yr} w-20`,value:Number.isFinite(E.rank)?E.rank:"",onChange:_=>p(x,{rank:_.target.value===""?NaN:Number(_.target.value)})}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"profile"}),y.jsxs("select",{className:wr,value:E.profile,onChange:_=>p(x,{profile:_.target.value}),children:[!m.includes(E.profile)&&y.jsxs("option",{value:E.profile,children:[E.profile," (missing)"]}),m.map(_=>y.jsx("option",{value:_,children:_},_))]}),y.jsx("div",{className:"flex-1"}),x!=="owner"&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove role",onClick:()=>i(_=>({..._,roles:w(_.roles,x)})),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]},x))}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-40`,placeholder:"new role name",value:l,onChange:x=>u(x.target.value.trim())}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!l||l in r.roles,onClick:()=>{i(x=>({...x,roles:{...x.roles,[l]:{rank:10,profile:m.includes("none")?"none":m[0]}}})),u("")},children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add role"]}),y.jsx("div",{className:"flex-1"}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"default role"}),y.jsx("select",{className:wr,value:r.default,onChange:x=>i(E=>({...E,default:x.target.value})),children:Object.keys(r.roles).filter(x=>x!=="owner").map(x=>y.jsx("option",{value:x,children:x},x))})]})]}),y.jsxs("section",{className:"space-y-2",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Profiles"}),Object.entries(r.profiles).map(([x,E])=>y.jsxs("div",{className:"border rounded-lg p-3 space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-sm font-medium",children:x}),y.jsx("div",{className:"flex-1"}),y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove profile",onClick:()=>i(_=>({..._,profiles:w(_.profiles,x)})),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]}),y.jsxs("div",{className:"grid grid-cols-[4.5rem_1fr] gap-x-2 gap-y-1.5 items-center",children:[["tools","mcps","env"].map(_=>y.jsx(Rp,{label:_,children:y.jsx(V$,{value:E[_],onChange:k=>g(x,{[_]:k}),placeholder:'comma-separated, "*" = all'})},_)),y.jsx(Rp,{label:"rate",children:y.jsx(ht,{className:`${yr} w-28`,value:E.rate,placeholder:"120/h",onChange:_=>g(x,{rate:_.target.value.trim()})})}),y.jsx(Rp,{label:"readScope",children:y.jsx("select",{className:`${wr} w-28`,value:E.readScope,onChange:_=>g(x,{readScope:_.target.value}),children:["all","own","none"].map(_=>y.jsx("option",{value:_,children:_},_))})}),y.jsx(Rp,{label:"outbound",children:y.jsx("input",{type:"checkbox",className:"h-4 w-4 justify-self-start",checked:E.outbound,onChange:_=>g(x,{outbound:_.target.checked})})})]})]},x)),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-40`,placeholder:"new profile name",value:d,onChange:x=>h(x.target.value.trim())}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!d||d in r.profiles,onClick:()=>{i(x=>({...x,profiles:{...x.profiles,[d]:{tools:[],mcps:[],env:[],outbound:!1,readScope:"none",rate:"0"}}})),h("")},children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add profile"]})]})]}),s]})}function Rp({label:e,children:t}){return y.jsxs(y.Fragment,{children:[y.jsx("label",{className:"text-[11px] text-muted-foreground",children:e}),t]})}const Zoe=new Set(["kind","id","emailIn","domain","verified"]);function Qoe({doc:e,save:t,call:n,onDirty:r}){const{draft:i,setDraft:a,error:s,saveBar:l}=Y$(e,t,r),u=Object.keys(i.roles).filter(p=>p!=="owner"),d=p=>a(g=>({...g,bindings:p([...g.bindings])})),h=(p,g,w)=>d(x=>{const E={...x[p].match};return w===void 0||w===""||Array.isArray(w)&&!w.length?delete E[g]:E[g]=w,x[p]={...x[p],match:E},x}),m=(p,g)=>d(w=>{const[x]=w.splice(p,1);return w.splice(g,0,x),w});return y.jsxs("div",{className:"space-y-4",children:[y.jsx(Zs,{error:s}),y.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Ordered — the first matching binding decides the role; no match → default role ",y.jsx("b",{children:i.default}),"."]}),y.jsxs("div",{className:"space-y-2",children:[i.bindings.map((p,g)=>{const w=Object.entries(p.match).filter(([x])=>!Zoe.has(x));return y.jsxs("div",{className:"border rounded-lg p-2 space-y-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground w-5",children:["#",g+1]}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"role"}),y.jsxs("select",{className:wr,value:p.role,onChange:x=>d(E=>(E[g]={...E[g],role:x.target.value},E)),children:[!u.includes(p.role)&&y.jsxs("option",{value:p.role,children:[p.role," (invalid)"]}),u.map(x=>y.jsx("option",{value:x,children:x},x))]}),y.jsx("div",{className:"flex-1"}),y.jsx("button",{className:sr,title:"Move up",disabled:g===0,onClick:()=>m(g,g-1),children:y.jsx(HG,{className:"w-3.5 h-3.5"})}),y.jsx("button",{className:sr,title:"Move down",disabled:g===i.bindings.length-1,onClick:()=>m(g,g+1),children:y.jsx(FG,{className:"w-3.5 h-3.5"})}),y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove",onClick:()=>d(x=>x.filter((E,_)=>_!==g)),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]}),y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsxs("select",{className:wr,title:"kind",value:p.match.kind??"",onChange:x=>h(g,"kind",x.target.value),children:[y.jsx("option",{value:"",children:"any kind"}),G$.map(x=>y.jsx("option",{value:x,children:x},x))]}),y.jsxs("select",{className:wr,title:"verified",value:p.match.verified===void 0?"":String(p.match.verified),onChange:x=>h(g,"verified",x.target.value===""?void 0:x.target.value==="true"),children:[y.jsx("option",{value:"",children:"verified: any"}),y.jsx("option",{value:"true",children:"verified"}),y.jsx("option",{value:"false",children:"unverified"})]}),y.jsx(ht,{className:`${yr} w-40`,placeholder:"domain",value:p.match.domain??"",onChange:x=>h(g,"domain",x.target.value.trim())}),y.jsx(ht,{className:`${yr} w-48`,placeholder:"id (e.g. slack:U123)",value:p.match.id??"",onChange:x=>h(g,"id",x.target.value.trim())}),y.jsx("div",{className:"flex-1 min-w-48",children:y.jsx(V$,{value:p.match.emailIn,onChange:x=>h(g,"emailIn",x),placeholder:"emails (comma-separated)"})})]}),w.length>0&&y.jsxs("p",{className:"text-[10px] font-mono text-muted-foreground",children:["also matches: ",JSON.stringify(Object.fromEntries(w))]})]},g)}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!u.length,onClick:()=>d(p=>[...p,{match:{kind:"user"},role:u.includes("guest")?"guest":u[u.length-1]}]),children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add binding"]})]}),l,y.jsx(Joe,{call:n})]})}function Joe({call:e}){const[t,n]=b.useState({kind:"user",email:"",id:"",verified:!0,lane:"",role:""}),[r,i]=b.useState(null),{busy:a,error:s,run:l}=ld(),u=h=>{n(m=>({...m,...h})),i(null)},d=()=>l("test",async()=>{i(await e("/policy/test","POST",{kind:t.kind,verified:t.verified,...t.email?{email:t.email}:{},...t.id?{id:t.id}:{},...t.lane?{lane:t.lane}:{},...t.role?{role:t.role}:{}}))});return y.jsxs("section",{className:"border rounded-lg p-3 space-y-2 bg-muted/20",children:[y.jsxs("h3",{className:"text-xs font-medium flex items-center gap-1.5",children:[y.jsx(ZG,{className:"w-3.5 h-3.5"})," Test a principal ",y.jsx("span",{className:"text-muted-foreground font-normal",children:"(against the SAVED policy)"})]}),y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx("select",{className:wr,value:t.kind,onChange:h=>u({kind:h.target.value}),children:G$.map(h=>y.jsx("option",{value:h,children:h},h))}),y.jsx(ht,{className:`${yr} w-52`,placeholder:t.kind==="apikey"?"creator email":"email",value:t.email,onChange:h=>u({email:h.target.value.trim()})}),y.jsx(ht,{className:`${yr} w-32`,placeholder:"id (optional)",value:t.id,onChange:h=>u({id:h.target.value.trim()})}),t.kind==="internal"&&y.jsx(ht,{className:`${yr} w-28`,placeholder:"lane",value:t.lane,onChange:h=>u({lane:h.target.value.trim()})}),t.kind==="apikey"&&y.jsx(ht,{className:`${yr} w-28`,placeholder:"key role cap",value:t.role,onChange:h=>u({role:h.target.value.trim()})}),y.jsxs("label",{className:"flex items-center gap-1 text-xs",children:[y.jsx("input",{type:"checkbox",checked:t.verified,onChange:h=>u({verified:h.target.checked})})," verified"]}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!a,onClick:d,children:[a&&y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"})," Resolve"]})]}),y.jsx(Zs,{error:s}),r&&y.jsxs("p",{className:"text-xs font-mono",children:[r.principal," → role ",y.jsx("b",{children:r.role})," · rank ",r.rank," · profile ",y.jsx("b",{children:r.profile}),r.blocked&&y.jsxs("span",{className:"text-destructive",children:[" · BLOCKED",r.blocked.reason?` (${r.blocked.reason})`:""]})]})]})}const ese=[["permanent",0],["1 hour",3600],["24 hours",86400],["7 days",604800],["30 days",2592e3]];function tse({call:e,onPolicyChange:t}){const[n,r]=b.useState(null),[i,a]=b.useState({field:"id",value:"",ttl:0,reason:""}),{busy:s,error:l,run:u}=ld(),d=b.useCallback(async()=>r(await e("/blocks")),[e]);b.useEffect(()=>{u("load",d)},[d]);const h=()=>u("add",async()=>{const p=i.value.trim(),g=i.field==="emailIn"?{emailIn:[p]}:{[i.field]:p};await e("/blocks","POST",{match:g,until:i.ttl?Math.floor(Date.now()/1e3)+i.ttl:null,reason:i.reason}),a({...i,value:"",reason:""}),await Promise.all([d(),t()])}),m=p=>u("rm",async()=>{await e("/blocks","DELETE",p),await Promise.all([d(),t()])});return y.jsxs("div",{className:"space-y-4",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsxs("select",{className:wr,value:i.field,onChange:p=>a({...i,field:p.target.value}),children:[y.jsx("option",{value:"id",children:"principal id"}),y.jsx("option",{value:"emailIn",children:"email"}),y.jsx("option",{value:"domain",children:"domain"})]}),y.jsx(ht,{className:`${yr} w-56`,placeholder:i.field==="id"?"user:x@y.com / slack:U123":i.field==="domain"?"spam.tld":"x@y.com",value:i.value,onChange:p=>a({...i,value:p.target.value})}),y.jsx("select",{className:wr,value:i.ttl,onChange:p=>a({...i,ttl:Number(p.target.value)}),children:ese.map(([p,g])=>y.jsx("option",{value:g,children:p},g))}),y.jsx(ht,{className:`${yr} w-40`,placeholder:"reason",value:i.reason,onChange:p=>a({...i,reason:p.target.value})}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!s||!i.value.trim(),onClick:h,children:[s==="add"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Block"]}),y.jsx("button",{className:sr,title:"Refresh",onClick:()=>u("load",d),children:y.jsx(Ju,{className:`w-3.5 h-3.5 ${s==="load"?"animate-spin":""}`})})]}),y.jsx(Zs,{error:l}),y.jsxs("section",{className:"space-y-1",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Manual (policy)"}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Match"}),y.jsx("th",{className:Tt,children:"Until"}),y.jsx("th",{className:Tt,children:"Reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.manual.map(p=>{const g=p.until!==null&&p.until*1e3<=Date.now();return y.jsxs("tr",{className:g?"opacity-50":"",children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:Hoe(p.match)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:p.until===null?"permanent":`${Kl(p.until*1e3)}${g?" (expired)":""}`}),y.jsx("td",{className:Mt,children:p.reason||"—"}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove",disabled:!!s,onClick:()=>m({source:"manual",index:p.index,match:p.match}),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},p.index)}),n&&!n.manual.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:4,className:"text-center text-muted-foreground py-4",children:"No manual blocks."})})]})]})})]}),y.jsxs("section",{className:"space-y-1",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Automatic (guard)"}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Key"}),y.jsx("th",{className:Tt,children:"Since"}),y.jsx("th",{className:Tt,children:"Until"}),y.jsx("th",{className:Tt,children:"Reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.auto.map(p=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:p.key}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.at)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.until)}),y.jsx("td",{className:Mt,children:p.reason}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Clear",disabled:!!s,onClick:()=>m({source:"auto",key:p.key}),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},p.key)),n&&!n.auto.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:5,className:"text-center text-muted-foreground py-4",children:"No active auto-blocks."})})]})]})})]})]})}function nse({call:e,onPolicyChange:t,ownerIds:n}){const[r,i]=b.useState(7),[a,s]=b.useState(null),{busy:l,error:u,run:d}=ld(),h=W$(e,t,n),m=b.useCallback(()=>d("load",async()=>s(await e(`/principals?days=${r}`))),[e,r]);return b.useEffect(()=>{m()},[m]),y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-xs text-muted-foreground",children:"Seen in the audit, last"}),y.jsx("select",{className:wr,value:r,onChange:p=>i(Number(p.target.value)),children:[1,7,30,90].map(p=>y.jsxs("option",{value:p,children:[p," day",p>1?"s":""]},p))}),y.jsx("button",{className:sr,title:"Refresh",onClick:m,children:y.jsx(Ju,{className:`w-3.5 h-3.5 ${l==="load"?"animate-spin":""}`})}),(a==null?void 0:a.truncated)&&y.jsx("span",{className:"text-[10px] text-amber-500",children:"scan capped — older activity omitted"})]}),y.jsx(Zs,{error:u}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Principal"}),y.jsx("th",{className:Tt,children:"Kind"}),y.jsx("th",{className:Tt,children:"Last role"}),y.jsx("th",{className:Tt,children:"Last seen"}),y.jsx("th",{className:Tt,children:"Turns"}),y.jsx("th",{className:Tt,title:"Includes shadow (would-deny) verdicts",children:"Denies"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[a==null?void 0:a.principals.map(p=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:p.id}),y.jsx("td",{className:Mt,children:p.kind}),y.jsx("td",{className:Mt,children:p.lastRole??"—"}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.lastSeen)}),y.jsx("td",{className:Mt,children:p.turns}),y.jsx("td",{className:`${Mt} ${p.denies?"text-destructive":""}`,children:p.denies}),y.jsxs("td",{className:`${Mt} whitespace-nowrap text-right`,children:[h.canRevoke(p.id)&&y.jsx("button",{className:`${sr} mr-2`,title:"Revoke tokens",disabled:!!l,onClick:()=>d(`rv-${p.id}`,()=>h.revoke(p.id)),children:y.jsx(cL,{className:"w-3.5 h-3.5"})}),h.canBlock(p.id)&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Block",disabled:!!l,onClick:()=>d(`bl-${p.id}`,()=>h.block(p.id)),children:y.jsx(oL,{className:"w-3.5 h-3.5"})})]})]},p.id)),a&&!a.principals.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:7,className:"text-center text-muted-foreground py-6",children:"No principals in this window."})})]})]})})]})}const X$=[["roles","Roles & Profiles"],["bindings","Bindings"],["principals","Principals"],["keys","API keys"],["blocks","Blocklist"],["audit","Audit"]],Z$="owner-console-tab";function rse(){try{const e=localStorage.getItem(Z$);return X$.some(([t])=>t===e)?e:"roles"}catch{return"roles"}}function ise({call:e,onOpenSession:t,trigger:n}){const[r,i]=b.useState(!1),[a,s]=b.useState(rse),[l,u]=b.useState(null),[d,h]=b.useState(null),m=b.useCallback(async()=>{try{u(await e("/policy")),h(null)}catch(k){h((k==null?void 0:k.message)??String(k))}},[e]);b.useEffect(()=>{r&&m()},[r,m]);const p=async(k,O)=>{await e("/policy","PUT",{policy:k,version:O}),await m()},[g,w]=b.useState(!1),x=()=>!g||confirm("You have unsaved policy edits. Discard them?"),E=k=>{if(!(k===a||!x())){s(k);try{localStorage.setItem(Z$,k)}catch(O){console.warn("[owner] could not persist tab",O)}}},_=l?Object.keys(l.policy.roles).filter(k=>k!=="owner"):[];return y.jsxs(So,{open:r,onOpenChange:k=>{(k||x())&&i(k)},children:[y.jsx(nd,{asChild:!0,children:n}),y.jsxs(_a,{className:"max-w-[95vw] sm:max-w-5xl h-[85dvh] flex flex-col gap-0 p-0",children:[y.jsxs(Ls,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:[y.jsxs(_o,{className:"flex items-center gap-2",children:[y.jsx(Sh,{className:"w-4 h-4"})," Owner Console",y.jsx(we,{variant:"ghost",size:"icon",className:"h-6 w-6 ml-1",title:"Reload policy",onClick:m,children:y.jsx(Ju,{className:"w-3.5 h-3.5"})})]}),y.jsx("div",{className:"flex gap-1 overflow-x-auto pt-2",role:"tablist",children:X$.map(([k,O])=>y.jsx("button",{role:"tab","aria-selected":a===k,onClick:()=>E(k),className:$e("text-xs px-2.5 py-1 rounded-md whitespace-nowrap transition-colors",a===k?"bg-accent text-foreground font-medium":"text-muted-foreground hover:text-foreground"),children:O},k))})]}),y.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[y.jsx(Zs,{error:d}),l&&!l.valid&&y.jsx("p",{className:"text-xs text-destructive border border-destructive/40 rounded-md p-2",children:"The policy file is invalid — the server is failing closed (owners only). Saving a valid policy restores it."}),(a==="roles"||a==="bindings")&&!l&&!d&&y.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"Loading…"}),a==="roles"&&l&&y.jsx(Xoe,{doc:l,save:p,onDirty:w}),a==="bindings"&&l&&y.jsx(Qoe,{doc:l,save:p,call:e,onDirty:w}),a==="principals"&&y.jsx(nse,{call:e,onPolicyChange:m,ownerIds:(l==null?void 0:l.ownerIds)??[]}),a==="keys"&&y.jsx(qoe,{call:e,roles:_}),a==="blocks"&&y.jsx(tse,{call:e,onPolicyChange:m}),a==="audit"&&y.jsx(Yoe,{call:e,onPolicyChange:m,ownerIds:(l==null?void 0:l.ownerIds)??[],onOpenSession:async k=>{await t(k),i(!1)}})]})]})]})}function ase(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 Of="w-4 h-4 mt-0.5 shrink-0";function ose(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(iV,{className:`${Of} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(KG,{className:`${Of} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(JG,{className:`${Of} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Gw,{className:`${Of} text-yellow-400`}):y.jsx(Gw,{className:`${Of} text-muted-foreground`})}function sse(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 lse(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 cse({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var $;const h=Pa(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),{isOwner:_,call:k}=Foe(e),O=b.useRef(null);function N(R){p(R),localStorage.setItem(lI,R)}function C(){const R=!g;w(R),localStorage.setItem(cI,String(R))}const T=b.useMemo(()=>[t,...Object.keys(l)].filter(R=>!!R),[t,l]),{sessions:M,cursor:j,loading:L,byId:P,loadMore:H}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:T}),D=b.useMemo(()=>lse(l,P,m),[l,P,m]),G=D.length,q=b.useMemo(()=>g?[...D].sort((R,V)=>V.lastModified-R.lastModified):M,[g,D,M]),Y=t&&!q.some(R=>R.sessionId===t)?P.get(t):void 0;b.useEffect(()=>{O.current&&O.current.scrollIntoView({block:"nearest"})},[t,q,Y]);const U=b.useRef(null),K=b.useRef(H);K.current=H,b.useEffect(()=>{const R=U.current;if(!R||!j||g)return;const V=new IntersectionObserver(z=>{z.some(ie=>ie.isIntersecting)&&K.current()},{rootMargin:"300px"});return V.observe(R),()=>V.disconnect()},[j,L,g]),b.useEffect(()=>{e().then(R=>R?fetch("/api/version",{headers:{Authorization:`Bearer ${R}`}}):null).then(R=>R==null?void 0:R.json()).then(R=>R&&E(R.version)).catch(()=>{})},[]);const F=!!x&&x!=="unknown"&&kf!=="dev"&&x!==kf;b.useEffect(()=>{F&&console.warn(`[shraga] stale client bundle: built from v${kf}, server runs v${x} — rebuild dist/client`)},[F,x]);function Q(R){const V=l[R.sessionId],z=u.has(R.sessionId)||R.runStatus==="running"||R.scheduleRunStatus==="running",ie=!z&&(!!R.lastStopReason||R.scheduleRunStatus==="error"||R.scheduleRunStatus==="aborted"),me=z?"border-amber-500":ie?"border-red-500":V?"border-blue-500":"",fe=!!(z||ie||V);return y.jsx("button",{ref:R.sessionId===t?O:void 0,onClick:()=>n(R.sessionId,R.title),className:$e("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",fe?`rounded-r-lg border-l-[3px] ${me}`:"rounded-lg",t===R.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[ose(R),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:$e("block truncate text-sm leading-snug",V&&"font-semibold"),children:R.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:sse(R)||R.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:ase(R.lastModified)})]})]})]})},R.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(Eo,{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(R=>y.jsx("button",{onClick:()=>N(R),className:$e("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===R?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:R},R)),y.jsxs("button",{onClick:C,className:$e("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",G>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(kL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[q.length===0&&!Y&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:L?"Loading…":g?"No unread conversations":"No conversations yet"}),Y&&Q(Y),q.map(Q),!g&&j&&y.jsx("div",{ref:U,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:L?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[_&&y.jsx(ise,{call:k,onOpenSession:async R=>{await $i(`/api/sessions/${encodeURIComponent(R)}/meta`,e),n(R)},trigger:y.jsxs("button",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground transition-colors",title:"Roles, bindings, keys, blocklist, audit",children:[y.jsx(Sh,{className:"w-3.5 h-3.5"})," Owner Console"]})}),y.jsx(Coe,{socket:d??null,getToken:e}),($=h.sidebarExtras)==null?void 0:$.call(h),x&&(F?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${kf}, 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",kf," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ti(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:Ns(),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:Ns(),role:"assistant",blocks:[i]}]}function Q$(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 use(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(D=>D!=null&&D===u.current,[]),k=b.useCallback(async()=>{var G;const D=u.current;if(D)try{const Y=await(await Dl(`/api/sessions/${D}/messages`,m.current)).json();r(tL(Y)),a(!!Y.busy),(G=w.current)==null||G.call(w,Array.isArray(Y.participants)&&Y.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const D=e.on(G=>{var Y,U,K,F,Q,$;(Y=x.current)==null||Y.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(R=>[...R,{id:Ns(),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(R=>ti(R,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(R=>ti(R,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(R=>ti(R,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(R=>Q$(R,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(R=>ti(R,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(R=>ti(R,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(R=>ti(R,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(R=>ti(R,{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:dse(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(V=>ti(V,{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(uz)[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 j=window.getSelection(),L=j&&j.anchorNode,P=L?L===T||L.contains(T):!1;if(P)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 D=r.current||C;return yre(D,E,x,D==="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(cz,Ere);var vS=b.forwardRef(function(e,t){return b.createElement(Wv,ga({},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,mz=function(e){return e&&(e.host||mz(e.parentNode))},kre=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=mz(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={})}},pz=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",[gz]=fL(Yv),[Nre,Xi]=gz(Yv),vz=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})};vz.displayName=Yv;var yz="DialogTrigger",bz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(yz,n),a=ci(t,i.triggerRef);return y.jsx(Br.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:xr(e.onClick,i.onOpenToggle)})});bz.displayName=yz;var yS="DialogPortal",[Cre,xz]=gz(yS,{forceMount:void 0}),wz=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=Xi(yS,t);return y.jsx(Cre,{scope:t,forceMount:n,children:b.Children.map(r,s=>y.jsx(Vs,{present:n||a.open,children:y.jsx(sz,{asChild:!0,container:i,children:s})}))})};wz.displayName=yS;var Pg="DialogOverlay",bS=b.forwardRef((e,t)=>{const n=xz(Pg,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xi(Pg,e.__scopeDialog);return a.modal?y.jsx(Vs,{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=Xi(Pg,n),a=Mne(),s=ci(t,a);return y.jsx(vS,{as:Tre,allowPinchZoom:!0,shards:[i.contentRef],children:y.jsx(Br.div,{"data-state":ES(i.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Bu="DialogContent",xS=b.forwardRef((e,t)=>{const n=xz(Bu,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=Xi(Bu,e.__scopeDialog);return y.jsx(Vs,{present:r||a.open,children:a.modal?y.jsx(Ire,{...i,ref:t}):y.jsx(Rre,{...i,ref:t})})});xS.displayName=Bu;var Ire=b.forwardRef((e,t)=>{const n=Xi(Bu,e.__scopeDialog),r=b.useRef(null),i=ci(t,n.contentRef,r);return b.useEffect(()=>{const a=r.current;if(a)return pz(a)},[]),y.jsx(Ez,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:xr(e.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=n.triggerRef.current)==null||s.focus()}),onPointerDownOutside:xr(e.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:xr(e.onFocusOutside,a=>a.preventDefault())})}),Rre=b.forwardRef((e,t)=>{const n=Xi(Bu,e.__scopeDialog),r=b.useRef(!1),i=b.useRef(!1);return y.jsx(Ez,{...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()}})}),Ez=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=e,l=Xi(Bu,n);return Hne(),y.jsx(y.Fragment,{children:y.jsx(az,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:y.jsx(rz,{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)})})})}),Sz="DialogTitle",wS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(Sz,n);return y.jsx(Br.h2,{id:i.titleId,...r,ref:t})});wS.displayName=Sz;var _z="DialogDescription",Pre=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(_z,n);return y.jsx(Br.p,{id:i.descriptionId,...r,ref:t})});Pre.displayName=_z;var Az="DialogClose",kz=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Xi(Az,n);return y.jsx(Br.button,{type:"button",...r,ref:t,onClick:xr(e.onClick,()=>i.onOpenChange(!1))})});kz.displayName=Az;function ES(e){return e?"open":"closed"}const So=vz,nd=bz,Dre=wz,Oz=b.forwardRef(({className:e,...t},n)=>y.jsx(bS,{ref:n,className:$e("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}));Oz.displayName=bS.displayName;const _a=b.forwardRef(({className:e,children:t,...n},r)=>y.jsxs(Dre,{children:[y.jsx(Oz,{}),y.jsxs(xS,{ref:r,className:$e("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(kz,{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(Zl,{className:"h-4 w-4"}),y.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_a.displayName=xS.displayName;function Ls({className:e,...t}){return y.jsx("div",{className:$e("shrink-0 flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function Nz({className:e,...t}){return y.jsx("div",{"data-dialog-body":!0,className:$e("flex-1 min-h-0 overflow-y-auto -mx-4 px-4 sm:-mx-6 sm:px-6",e),...t})}function Cz({className:e,...t}){return y.jsx("div",{className:$e("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 _o=b.forwardRef(({className:e,...t},n)=>y.jsx(wS,{ref:n,className:$e("text-lg font-semibold leading-none tracking-tight",e),...t}));_o.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([]),j=b.useCallback(async U=>{const K=await zre(U,e);i(F=>new Map(F).set(U,K))},[e]);b.useEffect(()=>{j(""),a.forEach(U=>j(U))},[j,n]);const L=r.get("")??[],P=b.useCallback(U=>{try{const K=U.contentDocument;if(!(K!=null&&K.body))return;const F=Math.max(K.body.offsetWidth,K.body.scrollWidth),Q=Math.max(K.body.offsetHeight,K.body.scrollHeight);F&&Q&&E({w:F,h:Q})}catch{}},[]),H=b.useCallback(()=>{const U=_.current,K=x;if(!U||!K)return;const F=16,Q=U.clientWidth-F,$=U.clientHeight-F,R=Math.min(Q/K.w,$/K.h,1);w({scale:R,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 D=U=>{s(K=>{const F=new Set(K);return F.has(U)?F.delete(U):(F.add(U),r.has(U)||j(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 Q;const K=await e();if(!K)return;O(K);const F=((Q=U.split(".").pop())==null?void 0:Q.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 R=await $.json();u({path:U,content:R.content,binary:!!R.binary})}catch{}},Y=(U,K)=>y.jsx(y.Fragment,{children:U.map(F=>{const Q=F.path.split("/").pop();return y.jsxs("div",{children:[F.type==="dir"?y.jsxs("button",{onClick:()=>D(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(Gs,{className:$e("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:Q})]}):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:Q})]}),F.type==="dir"&&a.has(F.path)&&Y(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:()=>{j(""),a.forEach(U=>j(U)),t==null||t()},className:"p-0.5 rounded hover:bg-accent text-muted-foreground",title:"Refresh",children:y.jsx(Ju,{className:"w-3 h-3"})})]})]}),y.jsx("div",{className:"px-1 pb-2 overflow-y-auto min-h-0",children:L.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."}):Y(L,0)}),y.jsx(So,{open:!!l,onOpenChange:U=>{U||(u(null),h(!1),p("fit"),E(null))},children:y.jsxs(_a,{className:$e(l!=null&&l.html?$e("!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(sL,{className:"w-4 h-4"})})]}),y.jsx(Ls,{className:$e((l==null?void 0:l.html)&&"px-4 py-3 shrink-0 border-b"),children:y.jsx(_o,{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:$e(l!=null&&l.html?$e("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=>{P(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=>P(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(u3,{remarkPlugins:[P3],rehypePlugins:[nz],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(So,{open:N,onOpenChange:C,children:y.jsxs(_a,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[y.jsx(Ls,{children:y.jsx(_o,{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,rd=(e,t)=>Hre(e,"name",{value:t,configurable:!0}),Tz=!!(typeof window<"u"&&window.document&&window.document.createElement);function Is(e,t,{checkForDefaultPrevented:n=!0}={}){return rd(function(i){if(e==null||e(i),n===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}rd(Is,"composeEventHandlers");function Kre(e){var t;if(!Tz)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}rd(Kre,"getOwnerWindow");function s1(e){if(!Tz)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}rd(s1,"getOwnerDocument");function Mz(e,t=!1){const{activeElement:n}=s1(e);if(!(n!=null&&n.nodeName))return null;if(Iz(n)&&n.contentDocument)return Mz(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}rd(Mz,"getActiveElement");function Iz(e){return e.tagName==="IFRAME"}rd(Iz,"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 Rz(...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(Rz,"composeRefs");function id(...e){return b.useCallback(Rz(...e),e)}SS(id,"useComposedRefs");var Gre=Object.defineProperty,Oi=(e,t)=>Gre(e,"name",{value:t,configurable:!0});function Vre(e,t){const n=b.createContext(t);n.displayName=e+"Context";const r=Oi(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 Oi(i,"useContext"),[r,i]}Oi(Vre,"createContext");function Pz(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=Oi(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 Oi(h,"useContext"),[d,h]}Oi(r,"createContext");const i=Oi(()=>{const a=n.map(s=>b.createContext(s));return Oi(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,Dz(i,...t)]}Oi(Pz,"createContextScope");function Dz(...e){const t=e[0];if(e.length===1)return t;const n=Oi(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return Oi(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}Oi(Dz,"composeContextScopes");var Wre=Object.defineProperty,Zi=(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($z(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?zz(s):void 0,h=id(r,d);if(!s){if(i||i===0)throw new Error(l?Jre(e):Qre(e));return i}const m=Lz(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}Zi(_S,"createSlot");var jz=Symbol.for("radix.slottable");function Yre(e){const t=Zi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=jz,t}Zi(Yre,"createSlottable");var Xre=Zi((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 Lz(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}}Zi(Lz,"mergeProps");function zz(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)}Zi(zz,"getElementRef");function $z(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===jz}Zi($z,"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&&Bz(e._payload)}Zi(c1,"isLazyComponent");function Bz(e){return typeof e=="object"&&e!==null&&"then"in e}Zi(Bz,"isPromiseLike");var Qre=Zi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Jre=Zi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cp=Ia[" 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 Uz(e,t){e&&Ra.flushSync(()=>e.dispatchEvent(t))}tie(Uz,"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,Un=(e,t)=>aie(e,"name",{value:t,configurable:!0}),u1="dismissableLayer.update",oie="dismissableLayer.pointerDownOutside",sie="dismissableLayer.focusOutside",UM,Fz=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),lie=b.forwardRef(Un(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(Fz),[p,g]=b.useState(null),w=(p==null?void 0:p.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=b.useState({}),E=id(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),j=Hz(D=>{s==null||s(D),u==null||u(D),D.defaultPrevented||d==null||d()},{ownerDocument:w,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:M,dismissableSurfaces:m.dismissableSurfaces,shouldHandlePointerDownOutside:b.useCallback(D=>{if(!(D instanceof Node))return!1;const G=[...m.branches].some(q=>q.contains(D));return T&&!G},[m.branches,T])}),L=Kz(D=>{if(i&&M.current)return;const G=D.target;[...m.branches].some(Y=>Y.contains(G))||(l==null||l(D),u==null||u(D),D.defaultPrevented||d==null||d())},w),P=p?N===_.length-1:!1,H=Zv(D=>{D.key==="Escape"&&(a==null||a(D),!D.defaultPrevented&&d&&(D.preventDefault(),d()))});return b.useEffect(()=>{if(P)return w.addEventListener("keydown",H,{capture:!0}),()=>w.removeEventListener("keydown",H,{capture:!0})},[w,P,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 D=Un(()=>x({}),"handleUpdate");return document.addEventListener(u1,D),()=>document.removeEventListener(u1,D)},[]),y.jsx(Xv.div,{...h,ref:E,style:{pointerEvents:C?T?"auto":"none":void 0,...t.style},onFocusCapture:Is(t.onFocusCapture,L.onFocusCapture),onBlurCapture:Is(t.onBlurCapture,L.onBlurCapture),onPointerDownCapture:Is(t.onPointerDownCapture,j.onPointerDownCapture)})},"DismissableLayer"));function cie(){const e=b.useContext(Fz),[t,n]=b.useState(null);return b.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}Un(cie,"useDismissableLayerSurface");var uie=Un(()=>!0,"IS_TRUE");function Hz(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()}Un(p,"resetOutsideInteraction");function g(){return Array.from(h.current.values()).some(Boolean)}Un(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)}Un(w,"handleInteractionCapture");function x(O){d.current&&h.current.set(O.type,!1)}Un(x,"handleInteractionBubble");const E=Un(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(Un(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:Un(()=>u.current=!0,"onPointerDownCapture")}}Un(Hz,"usePointerDownOutside");function Kz(e,t=globalThis==null?void 0:globalThis.document){const n=Zv(e),r=b.useRef(!1);return b.useEffect(()=>{const i=Un(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:Un(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Un(()=>r.current=!1,"onBlurCapture")}}Un(Kz,"useFocusOutside");function d1(){const e=new CustomEvent(u1);document.dispatchEvent(e)}Un(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?Uz(i,a):i.dispatchEvent(a)}Un(AS,"handleAndDispatchCustomEvent");var die=Object.defineProperty,kS=(e,t)=>die(e,"name",{value:t,configurable:!0}),Tp=0,sa=null;function fie(e){return OS(),e.children}kS(fie,"FocusGuards");function OS(){b.useEffect(()=>{sa||(sa={start:f1(),end:f1()});const{start:e,end:t}=sa;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Tp++,()=>{Tp===1&&(sa==null||sa.start.remove(),sa==null||sa.end.remove(),sa=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,vr=(e,t)=>pie(e,"name",{value:t,configurable:!0}),zx="focusScope.autoFocusOnMount",$x="focusScope.autoFocusOnUnmount",FM={bubbles:!1,cancelable:!0},gie=b.forwardRef(vr(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=id(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:oo(p.current,{select:!0})},_=function(N){if(w.paused||!u)return;const C=N.relatedTarget;C!==null&&(u.contains(C)||oo(p.current,{select:!0}))},k=function(N){if(document.activeElement===document.body)for(const T of N)T.removedNodes.length>0&&oo(u)};vr(E,"handleFocusIn"),vr(_,"handleFocusOut"),vr(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||(qz(Xz(NS(u)),{select:!0}),document.activeElement===E&&oo(u))}return()=>{u.removeEventListener(zx,h),setTimeout(()=>{const k=new CustomEvent($x,FM);u.addEventListener($x,m),u.dispatchEvent(k),k.defaultPrevented||oo(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]=Gz(O);N&&C?!E.shiftKey&&k===C?(E.preventDefault(),r&&oo(N,{select:!0})):E.shiftKey&&k===N&&(E.preventDefault(),r&&oo(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 qz(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(oo(r,{select:t}),document.activeElement!==n)return}vr(qz,"focusFirst");function Gz(e){const t=NS(e),n=m1(t,e),r=m1(t.reverse(),e);return[n,r]}vr(Gz,"getTabbableEdges");function NS(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:vr(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}vr(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}):Vz(r,{upTo:t})))return r}vr(m1,"findVisible");function Vz(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}vr(Vz,"isHidden");function Wz(e){return e instanceof HTMLInputElement&&"select"in e}vr(Wz,"isSelectableInput");function oo(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Wz(e)&&t&&e.select()}}vr(oo,"focus");var HM=Yz();function Yz(){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()}}}vr(Yz,"createFocusScopesStack");function p1(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}vr(p1,"arrayRemove");function Xz(e){return e.filter(t=>t.tagName!=="A")}vr(Xz,"removeLinks");var vie=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},yie=Object.defineProperty,bie=(e,t)=>yie(e,"name",{value:t,configurable:!0}),xie=Ia[" useId ".trim().toString()]||(()=>{}),wie=0;function Zz(e){const[t,n]=b.useState(xie());return vie(()=>{e||n(r=>r??String(wie++))},[e]),e||(t?`radix-${t}`:"")}bie(Zz,"useId");const Eie=["top","right","bottom","left"],zs=Math.min,go=Math.max,Dg=Math.round,Mp=Math.floor,vo=e=>({x:e,y:e}),Sie={left:"right",right:"left",bottom:"top",top:"bottom"};function Qz(e,t,n){return go(e,zs(t,n))}function Ao(e,t){return typeof e=="function"?e(t):e}function $s(e){return e.split("-")[0]}function ad(e){return e.split("-")[1]}function CS(e){return e==="x"?"y":"x"}function TS(e){return e==="y"?"height":"width"}function va(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function MS(e){return CS(va(e))}function _ie(e,t,n){n===void 0&&(n=!1);const r=ad(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=ad(e);let a=Nie($s(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=$s(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 Jz(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=va(t),s=MS(t),l=TS(s),u=$s(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=ad(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}=Ao(t,e),w=Jz(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}=Ao(e,t)||{};if(d==null)return{};const m=Jz(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 j=N/2-C/2,L=M/2-x[w]/2-1,P=zs(m[_],L),H=zs(m[k],L),D=M-x[w]-H,G=M/2-x[w]/2+j,q=Qz(P,G,D),Y=!u.arrow&&ad(i)!=null&&G!==q&&a.reference[w]/2-(G<P?P:H)-x[w]/2<0,U=Y?G<P?G-P:G-D:0;return{[g]:p[g]+U,data:{[g]:q,centerOffset:G-q-U,...Y&&{alignmentOffset:U}},reset:Y}}}),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}=Ao(e,t);if((n=a.arrow)!=null&&n.alignmentOffset)return{};const _=$s(i),k=va(l),O=$s(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],j=await u.detectOverflow(t,E),L=[];let P=((r=a.flip)==null?void 0:r.overflows)||[];if(h&&L.push(j[_]),m){const q=_ie(i,s,N);L.push(j[q[0]],j[q[1]])}if(P=[...P,{placement:i,overflows:L}],!L.every(q=>q<=0)){var H,D;const q=(((H=a.flip)==null?void 0:H.index)||0)+1,Y=M[q];if(Y&&(!(m==="alignment"?k!==va(Y):!1)||P.every(F=>va(F.placement)===k?F.overflows[0]>0:!0)))return{data:{index:q,overflows:P},reset:{placement:Y}};let U=(D=P.filter(K=>K.overflows[0]<=0).sort((K,F)=>K.overflows[1]-F.overflows[1])[0])==null?void 0:D.placement;if(!U)switch(g){case"bestFit":{var G;const K=(G=P.filter(F=>{if(T){const Q=va(F.placement);return Q===k||Q==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(Q=>Q>0).reduce((Q,$)=>Q+$,0)]).sort((F,Q)=>F[1]-Q[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}=Ao(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{}}}}},e$=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=$s(n),l=ad(n),u=va(n)==="y",d=e$.has(s)?-1:1,h=a&&u?-1:1,m=Ao(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}=Ao(e,t),h={x:n,y:r},m=await a.detectOverflow(t,d),p=va(i),g=CS(p);let w=h[g],x=h[p];const E=(k,O)=>Qz(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}=Ao(e,t),p={x:i,y:a},g=va(s),w=CS(g);let x=p[w],E=p[g];const _=Ao(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=e$.has($s(s)),M=l.reference[g]-l.floating[C]+(T&&((O=u.offset)==null?void 0:O[g])||0)+(T?0:k.crossAxis),j=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>j&&(E=j)}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}=Ao(e,t),u=await i.detectOverflow(t,l),d=$s(n),h=ad(n),m=va(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=zs(g-u[w],E),O=zs(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*go(u.left,u.right):T=g-2*go(u.top,u.bottom)),await s({...t,availableWidth:M,availableHeight:T});const j=await i.getDimensions(a.floating);return p!==j.width||g!==j.height?{reset:{rects:!0}}:{}}}};function Qv(){return typeof window<"u"}function od(e){return t$(e)?(e.nodeName||"").toLowerCase():"#document"}function $r(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Io(e){var t;return(t=(t$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function t$(e){return Qv()?e instanceof Node||e instanceof $r(e).Node:!1}function Aa(e){return Qv()?e instanceof Element||e instanceof $r(e).Element:!1}function Ys(e){return Qv()?e instanceof HTMLElement||e instanceof $r(e).HTMLElement:!1}function YM(e){return!Qv()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof $r(e).ShadowRoot}function Jv(e){const{overflow:t,overflowX:n,overflowY:r,display:i}=ka(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!=="inline"&&i!=="contents"}function Fie(e){return/^(table|td|th)$/.test(od(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/,Sl=e=>!!e&&e!=="none";let Bx;function IS(e){const t=Aa(e)?ka(e):e;return Sl(t.transform)||Sl(t.translate)||Sl(t.scale)||Sl(t.rotate)||Sl(t.perspective)||!RS()&&(Sl(t.backdropFilter)||Sl(t.filter))||Hie.test(t.willChange||"")||Kie.test(t.contain||"")}function qie(e){let t=Jl(e);for(;Ys(t)&&!th(t);){if(IS(t))return t;if(ey(t))return null;t=Jl(t)}return null}function RS(){return Bx==null&&(Bx=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Bx}function th(e){return/^(html|body|#document)$/.test(od(e))}function ka(e){return $r(e).getComputedStyle(e)}function ty(e){return Aa(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Jl(e){if(od(e)==="html")return e;const t=e.assignedSlot||e.parentNode||YM(e)&&e.host||Io(e);return YM(t)?t.host:t}function n$(e){const t=Jl(e);return th(t)?(e.ownerDocument||e).body:Ys(t)&&Jv(t)?t:n$(t)}function nh(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const i=n$(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),s=$r(i);if(a){const l=v1(s);return t.concat(s,s.visualViewport||[],Jv(i)?i:[],l&&n?nh(l):[])}else return t.concat(i,nh(i,[],n))}function v1(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function r$(e){const t=ka(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=Ys(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 Aa(e)?e:e.contextElement}function Tu(e){const t=PS(e);if(!Ys(t))return vo(1);const n=t.getBoundingClientRect(),{width:r,height:i,$:a}=r$(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=vo(0);function i$(e){const t=$r(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===$r(e)}function ec(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const i=e.getBoundingClientRect(),a=PS(e);let s=vo(1);t&&(r?Aa(r)&&(s=Tu(r)):s=Tu(e));const l=Vie(a,n,r)?i$(a):vo(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=$r(a),g=Aa(r)?$r(r):r;let w=p,x=v1(w);for(;x&&g!==w;){const E=Tu(x),_=x.getBoundingClientRect(),k=ka(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=$r(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:ec(Io(e)).left+n}function a$(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=Io(r),l=t?ey(t.floating):!1;if(r===s||l&&a)return n;let u={scrollLeft:0,scrollTop:0},d=vo(1);const h=vo(0),m=Ys(r);if((m||!a)&&((od(r)!=="body"||Jv(s))&&(u=ty(r)),m)){const g=ec(r);d=Tu(r),h.x=g.x+r.clientLeft,h.y=g.y+r.clientTop}const p=s&&!m&&!a?a$(s,u):vo(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=go(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=go(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let a=-t.scrollLeft+ny(e);const s=-t.scrollTop;return ka(n).direction==="rtl"&&(a+=go(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=$r(e),a=Io(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=ec(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(Io(e));else if(Aa(t))r=Jie(t,n);else{const i=i$(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=nh(e,[],!1).filter(l=>Aa(l)&&od(l)!=="body"),i=null;const a=ka(e).position==="fixed";let s=a?Jl(e):e;for(;Aa(s)&&!th(s);){const l=ka(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=Jl(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=go(g.top,u),d=zs(g.right,d),h=zs(g.bottom,h),m=go(g.left,m)}return{width:d-m,height:h-u,x:m,y:u}}function nae(e){const{width:t,height:n}=r$(e);return{width:t,height:n}}function rae(e,t,n){const r=Ys(t),i=Io(t),a=n==="fixed",s=ec(e,!0,a,t);let l={scrollLeft:0,scrollTop:0};const u=vo(0);if((r||!a)&&((od(t)!=="body"||Jv(i))&&(l=ty(t)),r)){const p=ec(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?a$(i,l):vo(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 ka(e).position==="static"}function ZM(e,t){if(!Ys(e)||ka(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Io(e)===n&&(n=n.ownerDocument.body),n}function o$(e,t){const n=$r(e);if(ey(e))return n;if(!Ys(e)){let i=Jl(e);for(;i&&!th(i);){if(Aa(i)&&!Ux(i))return i;i=Jl(i)}return n}let r=ZM(e,t);for(;r&&Fie(r)&&Ux(r);)r=ZM(r,t);return r&&th(r)&&Ux(r)&&!IS(r)?n:r||qie(e)||n}const iae=async function(e){const t=this.getOffsetParent||o$,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 ka(e).direction==="rtl"}const oae={convertOffsetParentRelativeRectToViewportRelativeRect:Wie,getDocumentElement:Io,getClippingRect:tae,getOffsetParent:o$,getElementRects:iae,getClientRects:Yie,getDimensions:nae,getScale:Tu,isElement:Aa,isRTL:aae};function s$(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=Io(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:go(0,zs(1,m))||1};let M=!0;function j(L){const P=L[0].intersectionRatio;if(!s$(p,e.getBoundingClientRect()))return l();if(P!==m){if(!M)return l();P?l(!1,P):i=setTimeout(()=>{l(!1,1e-7)},1e3)}M=!1}try{r=new IntersectionObserver(j,{...T,root:a.ownerDocument})}catch{r=new IntersectionObserver(j,T)}r.observe(e)}const u=$r(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?nh(d):[],...t?nh(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?ec(e):null;u&&E();function E(){const _=ec(e);x&&!s$(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 l$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function JM(e,t){const n=l$(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),j=b.useRef(h),L=u!=null,P=Fx(u),H=Fx(i),D=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(Q=>{const $={...Q,isPositioned:D.current!==!1};q.current&&!zg(j.current,$)&&(j.current=$,Ra.flushSync(()=>{m($)}))})},[p,t,n,H,D]);og(()=>{d===!1&&j.current.isPositioned&&(j.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(P.current)return P.current(N,C,G);G()}},[N,C,G,P,L]);const Y=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 Q=JM(U.floating,h.x),$=JM(U.floating,h.y);return l?{...F,transform:"translate("+Q+"px, "+$+"px)",...l$(U.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:Q,top:$}},[n,l,U.floating,h.x,h.y]);return b.useMemo(()=>({...h,update:G,refs:Y,elements:U,floatingStyles:K}),[h,G,Y,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 c$(...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(c$,"composeRefs");function ry(...e){return b.useCallback(c$(...e),e)}DS(ry,"useComposedRefs");var Nae=Object.defineProperty,Ni=(e,t)=>Nae(e,"name",{value:t,configurable:!0});function Cae(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(Cae,"createContext");function u$(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,d$(i,...t)]}Ni(u$,"createContextScope");function d$(...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(d$,"composeContextScopes");var Tae=Object.defineProperty,Qi=(e,t)=>Tae(e,"name",{value:t,configurable:!0});function f$(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(g$(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?p$(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=m$(a,s.props??{});return s.type!==b.Fragment&&(m.ref=r?h:d),b.cloneElement(s,m)});return t.displayName=`${e}.Slot`,t}Qi(f$,"createSlot");var h$=Symbol.for("radix.slottable");function Mae(e){const t=Qi(n=>"child"in n?n.children(n.child):n.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=h$,t}Qi(Mae,"createSlottable");var Iae=Qi((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 m$(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}}Qi(m$,"mergeProps");function p$(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)}Qi(p$,"getElementRef");function g$(e){return b.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===h$}Qi(g$,"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&&v$(e._payload)}Qi(b1,"isLazyComponent");function v$(e){return typeof e=="object"&&e!==null&&"then"in e}Qi(v$,"isPromiseLike");var Pae=Qi(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Dae=Qi(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ip=Ia[" 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"],y$=zae.reduce((e,t)=>{const n=f$(`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&&Ra.flushSync(()=>e.dispatchEvent(t))}Lae($ae,"dispatchDiscreteCustomEvent");var Bae=Object.defineProperty,Uae=(e,t)=>Bae(e,"name",{value:t,configurable:!0});function b$(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(b$,"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 x$(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(x$,"useSize");var qae=Object.defineProperty,Rs=(e,t)=>qae(e,"name",{value:t,configurable:!0}),w$="Popper",[E$,S$]=u$(w$),[Gae,_$]=E$(w$),Vae=Rs(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(Rs(function(t,n){const{__scopePopper:r,virtualRef:i,...a}=t,s=_$(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(y$.div,{"data-radix-popper-side":g,"data-radix-popper-align":w,...a,ref:h})},"PopperAnchor")),A$="PopperContent",[Xae,sCe]=E$(A$),Zae=b.forwardRef(Rs(function(t,n){var pe,Ne,Ee,de,pt,qe,Ce;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$,r),[k,O]=b.useState(null),N=ry(n,O),[C,T]=b.useState(null),M=x$(C),j=(M==null?void 0:M.width)??0,L=(M==null?void 0:M.height)??0,P=i+(s!=="center"?"-"+s:""),H=typeof m=="number"?m:{top:0,right:0,bottom:0,left:0,...m},D=Array.isArray(h)?h:[h],G=D.length>0,q={padding:H,boundary:D.filter(k$),altBoundary:G},{refs:Y,floatingStyles:U,placement:K,isPositioned:F,middlewareData:Q}=yae({strategy:"fixed",placement:P,whileElementsMounted:Rs((...De)=>lae(...De,{animationFrame:w==="always"}),"whileElementsMounted"),elements:{reference:_.anchor},middleware:[xae({mainAxis:a+L,alignmentAxis:l}),d&&wae({mainAxis:!0,crossAxis:!1,limiter:p==="partial"?Eae():void 0,...q}),d&&Sae({...q}),_ae({...q,apply:Rs(({elements:De,rects:zt,availableWidth:yn,availableHeight:_r})=>{const{width:qn,height:Hr}=zt.reference,ui=De.floating.style;ui.setProperty("--radix-popper-available-width",`${yn}px`),ui.setProperty("--radix-popper-available-height",`${_r}px`),ui.setProperty("--radix-popper-anchor-width",`${qn}px`),ui.setProperty("--radix-popper-anchor-height",`${Hr}px`)},"apply")}),C&&kae({element:C,padding:u}),Qae({arrowWidth:j,arrowHeight:L}),g&&Aae({strategy:"referenceHidden",...q,boundary:G?q.boundary:void 0})]}),$=_.setPlacementState;Hx(()=>($(K),()=>{$(void 0)}),[K,$]);const[R,V]=iy(K),z=b$(x);Hx(()=>{F&&(z==null||z())},[F,z]);const ie=(pe=Q.arrow)==null?void 0:pe.x,me=(Ne=Q.arrow)==null?void 0:Ne.y,fe=((Ee=Q.arrow)==null?void 0:Ee.centerOffset)!==0,[_e,Ge]=b.useState();return Hx(()=>{k&&Ge(window.getComputedStyle(k).zIndex)},[k]),y.jsx("div",{ref:Y.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:F?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:_e,"--radix-popper-transform-origin":[(de=Q.transformOrigin)==null?void 0:de.x,(pt=Q.transformOrigin)==null?void 0:pt.y].join(" "),...((qe=Q.hide)==null?void 0:qe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:y.jsx(Xae,{scope:r,placedSide:R,placedAlign:V,onArrowChange:T,arrowX:ie,arrowY:me,shouldHideArrow:fe,children:y.jsx(y$.div,{"data-side":R,"data-align":V,...E,ref:N,style:{...E.style,animation:F?(Ce=E.style)==null?void 0:Ce.animation:"none"}})})})},"PopperContent"));function k$(e){return e!==null}Rs(k$,"isNotNull");var Qae=Rs(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]}Rs(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?Ra.createPortal(y.jsx(Xv.div,{...i,ref:n}),l):null},"Portal")),eI=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},ooe=Object.defineProperty,ko=(e,t)=>ooe(e,"name",{value:t,configurable:!0});function O$(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}ko(O$,"useStateMachine");var N$=ko(e=>{const{present:t,children:n}=e,r=C$(t),i=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),a=T$(r.ref,M$(i));return typeof n=="function"||r.isPresent?b.cloneElement(i,{ref:a}):null},"Presence");function C$(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]=O$(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=ko(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=ko(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)},[])}}ko(C$,"usePresence");function x1(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}ko(x1,"setRef");function T$(...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)}}},[])}ko(T$,"useStableComposedRefs");function bu(e){return(e==null?void 0:e.animationName)||"none"}ko(bu,"getAnimationName");function M$(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)}ko(M$,"getElementRef");var I$=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},soe=Object.defineProperty,loe=(e,t)=>soe(e,"name",{value:t,configurable:!0}),tI=Ia[" useEffectEvent ".trim().toString()],nI=Ia[" useInsertionEffect ".trim().toString()];function R$(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}):I$(()=>{t.current=e}),b.useMemo(()=>((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)}),[])}loe(R$,"useEffectEvent");var coe=Object.defineProperty,Nh=(e,t)=>coe(e,"name",{value:t,configurable:!0}),uoe=Ia[" useInsertionEffect ".trim().toString()]||I$;function P$({prop:e,defaultProp:t,onChange:n=Nh(()=>{},"onChange"),caller:r}){const[i,a,s]=D$({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:i,d=b.useCallback(h=>{var m;if(l){const p=j$(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(P$,"useControllableState");function D$({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(D$,"useUncontrolledState");function j$(e){return typeof e=="function"}Nh(j$,"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=R$(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,Xs=(e,t)=>foe(e,"name",{value:t,configurable:!0}),jS="Popover",[L$,lCe]=Pz(jS,[S$]),LS=S$(),[hoe,sd]=L$(jS),moe=Xs(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]=P$({prop:r,defaultProp:i??!1,onChange:a,caller:jS});return y.jsx(Jae,{...l,children:y.jsx(hoe,{scope:t,contentId:Zz(),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(Xs(function(t,n){const{__scopePopover:r,...i}=t,a=sd(poe,r),s=LS(r),l=id(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:Is(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?u:y.jsx(eoe,{asChild:!0,...s,children:u})},"PopoverTrigger")),z$="PopoverPortal",[voe,yoe]=L$(z$,{forceMount:void 0}),boe=Xs(e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=sd(z$,t);return y.jsx(voe,{scope:t,forceMount:n,children:y.jsx(N$,{present:n||a.open,children:y.jsx(aoe,{asChild:!0,container:i,children:r})})})},"PopoverPortal"),rh="PopoverContent",xoe=b.forwardRef(Xs(function(t,n){const r=yoe(rh,t.__scopePopover),{forceMount:i=r.forceMount,...a}=t,s=sd(rh,t.__scopePopover);return y.jsx(N$,{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(Xs(function(t,n){const r=sd(rh,t.__scopePopover),i=b.useRef(null),a=id(n,i),s=b.useRef(!1);return b.useEffect(()=>{const l=i.current;if(l)return pz(l)},[]),y.jsx(vS,{as:woe,allowPinchZoom:!0,children:y.jsx($$,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Is(t.onCloseAutoFocus,l=>{var u;l.preventDefault(),s.current||(u=r.triggerRef.current)==null||u.focus()}),onPointerDownOutside:Is(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:Is(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),Soe=b.forwardRef(Xs(function(t,n){const r=sd(rh,t.__scopePopover),i=b.useRef(!1),a=b.useRef(!1);return y.jsx($$,{...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.forwardRef(Xs(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=sd(rh,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"}Xs(zS,"getState");var _oe=moe,Aoe=goe,koe=boe,B$=xoe;const Ooe=_oe,Noe=Aoe,U$=b.forwardRef(({className:e,align:t="start",side:n="top",sideOffset:r=8,collisionPadding:i=8,...a},s)=>y.jsx(koe,{children:y.jsx(B$,{ref:s,align:t,side:n,sideOffset:r,collisionPadding:i,className:$e("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})}));U$.displayName=B$.displayName;const F$=92,H$=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&&K$(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(U$,{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=K$(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:$e("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:$e("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:$e("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:$e("tabular-nums shrink-0",E1(n.percent,n.severity)),children:[n.percent,"%"]})]}),y.jsx(q$,{value:n.percent,className:$e("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 K$(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>=H$?"critical":e>=F$?"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 ${F$}%, critical at ${H$}%`;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(q$,{value:t,className:a}),y.jsxs("span",{className:$e("tabular-nums",a),children:[t,"%"]})]})}function q$({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:$e("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:$e("overflow-visible",t),preserveAspectRatio:"none",children:y.jsx("polyline",{points:a,fill:"none",stroke:"currentColor",strokeWidth:1,strokeLinejoin:"round",strokeLinecap:"round"})})}const Af=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(Af),_=b.useRef(t);_.current!==t&&(_.current=t,E.current=Af);const k=b.useCallback(async(M,j)=>{const L=await e();if(!L||j!=null&&j.aborted)return null;const P=await fetch(`/api/sessions?${new URLSearchParams(M)}`,{signal:j,headers:{Authorization:`Bearer ${L}`}});if(!P.ok)return null;const H=await P.json();return Array.isArray(H==null?void 0:H.sessions)?H:null},[e]),O=b.useCallback(async(M,j,L)=>{const P=[];let H,D=null;for(;P.length<M;){const G={filter:j,limit:String(Math.min(Af,M-P.length))};H&&(G.before=H);const q=await k(G,L);if(!q)return null;if(P.push(...q.sessions),D=q.nextCursor,!D||!q.sessions.length)break;H=D}return{sessions:P,nextCursor:D}},[k]);b.useEffect(()=>{var j,L;(j=g.current)==null||j.abort(),(L=w.current)==null||L.abort();const M=new AbortController;return g.current=M,d(!0),p.current.clear(),m({}),O(E.current,t,M.signal).then(P=>{!P||M.signal.aborted||(a(P.sessions),l(P.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)}),()=>M.abort()},[O,t,n]);const N=b.useCallback(()=>{var L;if(!s||u)return;(L=w.current)==null||L.abort();const M=new AbortController;w.current=M;const j=x.current;d(!0),k({filter:j,limit:String(Af),before:s},M.signal).then(P=>{!P||M.signal.aborted||j!==x.current||(a(H=>{const D=new Set(H.map(q=>q.sessionId)),G=[...H,...P.sessions.filter(q=>!D.has(q.sessionId))];return E.current=Math.max(Af,G.length),G}),l(P.nextCursor))}).catch(()=>{}).finally(()=>{M.signal.aborted||d(!1)})},[s,u,k]),C=b.useMemo(()=>{const M=new Map;for(const j of Object.values(h))M.set(j.sessionId,j);for(const j of i)M.set(j.sessionId,j);return M},[i,h]),T=r.join(",");return b.useEffect(()=>{const M=r.filter(L=>!!L&&!C.has(L)&&!p.current.has(L)).slice(0,200);if(!M.length)return;for(const L of M)p.current.add(L);let j=!1;return k({ids:M.join(",")}).then(L=>{!L||j||m(P=>{const H={...P};for(const D of L.sessions)H[D.sessionId]=D;return H})}).catch(()=>{}),()=>{j=!0}},[T,C,k]),{sessions:i,cursor:s,loading:u,byId:C,loadMore:N}}const kf="0.1.115";async function $i(e,t,n){const r=await t();let i;try{i=await fetch(e,{...n,headers:{Authorization:`Bearer ${r??""}`,"Content-Type":"application/json",...n==null?void 0:n.headers}})}catch(a){throw $v(e,a),a}if(zv(e,i,n==null?void 0:n.expect),!i.ok){const a=await i.json().catch(()=>({}));throw Object.assign(new Error(a.error||`${i.status} ${i.statusText}`),{status:i.status})}return i.json()}function $S(e,t=!0){const[n,r]=b.useState();return b.useEffect(()=>{if(!t)return;let i=!0;return e().then(a=>{!a||!i||fetch("/api/config",{headers:{Authorization:`Bearer ${a}`}}).then(s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}).then(s=>{i&&r(!!s.isOwner)}).catch(s=>console.warn("[isOwner] load failed",s))}),()=>{i=!1}},[t,e]),n}function Foe(e){const t=$S(e),n=b.useCallback(async(r,i="GET",a)=>{try{return await $i(`/api/owner${r}`,e,{method:i,...a!==void 0?{body:JSON.stringify(a)}:{}})}catch(s){throw console.warn(`[owner] ${i} ${r} failed: ${(s==null?void 0:s.message)??s}`),s}},[e]);return{isOwner:t,call:n}}const G$=["user","email","slack","apikey","internal","anonymous"],wr="h-7 rounded-md border border-input bg-background px-2 text-xs",yr="h-7 text-xs",Tt="text-left font-medium text-muted-foreground px-2 py-1 whitespace-nowrap",Mt="px-2 py-1 align-top",sr="text-muted-foreground hover:text-foreground disabled:opacity-40 transition-colors",Kl=e=>new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),Hoe=e=>Object.entries(e).map(([t,n])=>`${t}=${Array.isArray(n)?n.join("|"):String(n)}`).join(" ");function ld(){const[e,t]=b.useState(null),[n,r]=b.useState(null);return{busy:e,error:n,run:async(a,s)=>{if(!e){t(a),r(null);try{await s()}catch(l){r((l==null?void 0:l.message)??String(l))}finally{t(null)}}}}}function Zs({error:e}){if(!e)return null;const t=/^Invalid policy: (.*)$/s.exec(e);return y.jsx("div",{className:"text-xs text-destructive border border-destructive/40 rounded-md p-2",children:t?y.jsxs(y.Fragment,{children:[y.jsx("p",{className:"font-medium",children:"Invalid policy — not saved:"}),y.jsx("ul",{className:"list-disc pl-4",children:t[1].split("; ").map((n,r)=>y.jsx("li",{children:n},r))})]}):e})}function V$({value:e,onChange:t,placeholder:n}){const r=(e??[]).join(", "),[i,a]=b.useState(r);return b.useEffect(()=>a(r),[r]),y.jsx(ht,{className:yr,value:i,placeholder:n,onChange:s=>a(s.target.value),onBlur:()=>t(i.split(",").map(s=>s.trim()).filter(Boolean))})}function W$(e,t,n=[]){return{canRevoke:r=>/^(user|internal):/.test(r)&&r!=="internal:agent-internal",canBlock:r=>!n.includes(r),revoke:async r=>{confirm(`Revoke every token issued to ${r}? They must sign in again.`)&&(await e("/tokens/revoke","POST",{principalId:r}),await t())},block:async r=>{const i=prompt(`Block ${r}? Reason (optional):`);i!==null&&(await e("/blocks","POST",{match:{id:r},until:null,reason:i}),await t())}}}const Koe=[["never",0],["1 day",1],["7 days",7],["30 days",30],["90 days",90]];function qoe({call:e,roles:t}){const[n,r]=b.useState(null),[i,a]=b.useState({label:"",role:"",days:0}),[s,l]=b.useState(null),{busy:u,error:d,run:h}=ld(),m=b.useCallback(async()=>r((await e("/api-keys")).keys),[e]);b.useEffect(()=>{h("load",m)},[m]);const p=()=>h("create",async()=>{const w=await e("/api-keys","POST",{label:i.label||"Unnamed",...i.role?{role:i.role}:{},...i.days?{expiresAt:Date.now()+i.days*864e5}:{}});l(w),a({label:"",role:"",days:0}),await m()}),g=w=>navigator.clipboard.writeText(w).catch(x=>console.warn("[owner] clipboard write failed",x));return y.jsxs("div",{className:"space-y-3",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-48`,placeholder:"label",value:i.label,onChange:w=>a({...i,label:w.target.value})}),y.jsxs("select",{className:wr,value:i.role,onChange:w=>a({...i,role:w.target.value}),title:"Role cap (never above the creator)",children:[y.jsx("option",{value:"",children:"role: creator's (uncapped)"}),t.map(w=>y.jsxs("option",{value:w,children:["role cap: ",w]},w))]}),y.jsx("select",{className:wr,value:i.days,onChange:w=>a({...i,days:Number(w.target.value)}),children:Koe.map(([w,x])=>y.jsxs("option",{value:x,children:["expires: ",w]},x))}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!u,onClick:p,children:[u==="create"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Create key"]})]}),s&&y.jsxs("div",{className:"border border-amber-500/50 bg-amber-500/10 rounded-lg p-2 space-y-1",children:[y.jsxs("p",{className:"text-xs font-medium",children:['Key "',s.label,`" — copy it now, it won't be shown again:`]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("code",{className:"text-xs font-mono break-all flex-1 select-all",children:s.key}),y.jsx("button",{className:sr,title:"Copy",onClick:()=>g(s.key),children:y.jsx(Bv,{className:"w-3.5 h-3.5"})}),y.jsx(we,{size:"sm",variant:"ghost",className:"h-6 text-xs",onClick:()=>l(null),children:"Done"})]})]}),y.jsx(Zs,{error:d}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Label"}),y.jsx("th",{className:Tt,children:"Key"}),y.jsx("th",{className:Tt,children:"Creator"}),y.jsx("th",{className:Tt,children:"Role"}),y.jsx("th",{className:Tt,children:"Created"}),y.jsx("th",{className:Tt,children:"Expires"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.map(w=>{const x=w.expiresAt!==void 0&&w.expiresAt<=Date.now();return y.jsxs("tr",{className:x?"opacity-50":"",children:[y.jsx("td",{className:Mt,children:w.label}),y.jsx("td",{className:`${Mt} font-mono`,children:w.keyPreview}),y.jsx("td",{className:Mt,children:w.email}),y.jsx("td",{className:Mt,children:w.role??y.jsx("span",{className:"text-muted-foreground",children:"creator's"})}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(w.createdAt)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:w.expiresAt?`${Kl(w.expiresAt)}${x?" (expired)":""}`:"never"}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Revoke",disabled:!!u,onClick:()=>{confirm(`Revoke key "${w.label}" (${w.keyPreview})?`)&&h(`rm-${w.id}`,async()=>{await e(`/api-keys/${w.id}`,"DELETE"),await m()})},children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},w.id)}),n&&!n.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:7,className:"text-center text-muted-foreground py-6",children:"No API keys."})})]})]})})]})}const Goe=({brokenAt:e,planted:t})=>[e&&!(e.reason==="not-regular-file"&&(t!=null&&t.length))?`chain broken at ${e.file||"audit dir"}${e.line?`:${e.line}`:""} (${e.reason})`:"",t!=null&&t.length?`planted entries (not regular files): ${t.join(", ")}`:""].filter(Boolean).join(" · ")||"chain verify failed",Voe=["auth.allow","auth.deny","role.resolve","turn.start","turn.end","tool.allow","tool.deny","guard.limit","guard.block","escalate","policy.change","policy.tamper","key.create","key.revoke","token.revoke","session.delete"],Woe=100;function Yoe({call:e,onOpenSession:t,onPolicyChange:n,ownerIds:r}){const[i,a]=b.useState({principal:"",type:"",from:"",to:""}),[s,l]=b.useState([]),[u,d]=b.useState(),[h,m]=b.useState(null),[p,g]=b.useState(new Set),{busy:w,error:x,run:E}=ld(),_=W$(e,n,r),k=(M,j,L)=>E(M,async()=>{try{await L()}catch(P){throw(P==null?void 0:P.status)!==404?P:(g(H=>new Set(H).add(j)),new Error("Conversation no longer exists"))}}),O=M=>{const j=new URLSearchParams({limit:String(Woe)});return i.principal.trim()&&j.set("principal",i.principal.trim()),i.type&&j.set("type",i.type),i.from&&j.set("from",new Date(i.from).toISOString()),i.to&&j.set("to",new Date(i.to).toISOString()),M&&j.set("cursor",M),e(`/audit?${j}`)},N=b.useCallback(()=>E("load",async()=>{const M=await O();l(M.items),d(M.nextCursor)}),[e,i]),C=()=>E("more",async()=>{const M=await O(u);l(j=>[...j,...M.items]),d(M.nextCursor)}),T=()=>E("verify",async()=>m(await e("/audit/verify")));return b.useEffect(()=>{N(),T()},[]),y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-56`,placeholder:"principal (exact id)",value:i.principal,onChange:M=>a({...i,principal:M.target.value}),onKeyDown:M=>M.key==="Enter"&&N()}),y.jsxs("select",{className:wr,value:i.type,onChange:M=>a({...i,type:M.target.value}),children:[y.jsx("option",{value:"",children:"all types"}),Voe.map(M=>y.jsx("option",{value:M,children:M},M))]}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"from"}),y.jsx("input",{type:"datetime-local",className:wr,value:i.from,onChange:M=>a({...i,from:M.target.value})}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"to"}),y.jsx("input",{type:"datetime-local",className:wr,value:i.to,onChange:M=>a({...i,to:M.target.value})}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!w,onClick:N,children:[w==="load"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Ju,{className:"w-3 h-3 mr-1"})," Search"]}),y.jsx("div",{className:"flex-1"}),h&&y.jsxs("button",{onClick:T,title:"Re-verify the hash chain",className:`flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border ${h.ok?"border-green-500/50 text-green-600 dark:text-green-400":"border-destructive text-destructive"}`,children:[h.ok?y.jsx(Sh,{className:"w-3.5 h-3.5"}):y.jsx(hV,{className:"w-3.5 h-3.5"}),h.ok?`chain verified · ${h.lines} lines`:Goe(h)]})]}),y.jsx(Zs,{error:x}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Time"}),y.jsx("th",{className:Tt,children:"Type"}),y.jsx("th",{className:Tt,children:"Principal"}),y.jsx("th",{className:Tt,children:"Role"}),y.jsx("th",{className:Tt,children:"Target / reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[s.map(M=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} whitespace-nowrap`,title:M.ts,children:Kl(M.ts)}),y.jsx("td",{className:`${Mt} font-mono whitespace-nowrap ${/deny|block|tamper/.test(M.type)?"text-destructive":""}`,children:M.type}),y.jsx("td",{className:`${Mt} font-mono break-all`,children:M.principal?y.jsx("button",{className:"hover:underline text-left",title:"Filter by this principal",onClick:()=>a({...i,principal:M.principal}),children:M.principal}):"—"}),y.jsx("td",{className:Mt,children:M.role??"—"}),y.jsx("td",{className:`${Mt} break-all`,children:[M.target,M.reason].filter(Boolean).join(" · ")||"—"}),y.jsxs("td",{className:`${Mt} whitespace-nowrap text-right`,children:[M.sessionId&&!p.has(M.sessionId)&&y.jsx("button",{className:`${sr} mr-2`,title:"Open session",disabled:!!w,onClick:()=>k("open",M.sessionId,()=>t(M.sessionId)),children:y.jsx(WG,{className:"w-3.5 h-3.5"})}),M.principal&&_.canRevoke(M.principal)&&y.jsx("button",{className:`${sr} mr-2`,title:"Revoke tokens",disabled:!!w,onClick:()=>E("rv",()=>_.revoke(M.principal)),children:y.jsx(cL,{className:"w-3.5 h-3.5"})}),M.principal&&_.canBlock(M.principal)&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Block principal",disabled:!!w,onClick:()=>E("bl",()=>_.block(M.principal)),children:y.jsx(oL,{className:"w-3.5 h-3.5"})})]})]},M.hash)),!s.length&&w!=="load"&&y.jsx("tr",{children:y.jsx("td",{colSpan:6,className:"text-center text-muted-foreground py-6",children:"No audit records match."})})]})]})}),u&&y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!!w,onClick:C,children:[w==="more"&&y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"})," Load older"]})]})}const au=e=>{const{blocklist:t,tokensValidAfter:n,...r}=e;return JSON.stringify(r)};function Y$(e,t,n){const[r,i]=b.useState(e),[a,s]=b.useState(()=>structuredClone(e.policy)),l=au(a)!==au(r.policy);b.useEffect(()=>{!l||au(e.policy)===au(a)?(i(e),s(structuredClone(e.policy))):au(e.policy)===au(r.policy)&&i(e)},[e]),b.useEffect(()=>{n==null||n(l)},[l,n]),b.useEffect(()=>()=>n==null?void 0:n(!1),[n]);const u=ld(),d=y.jsxs("div",{className:"flex items-center gap-2 sticky -bottom-3 z-10 -mx-3 -mb-3 px-3 pt-2 pb-3 bg-background border-t",children:[y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!l||!!u.busy,onClick:()=>u.run("save",()=>t(a,r.version)),children:[u.busy?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(qi,{className:"w-3 h-3 mr-1"})," Save policy"]}),y.jsxs(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",disabled:!l,onClick:()=>{i(e),s(structuredClone(e.policy))},children:[y.jsx(yV,{className:"w-3 h-3 mr-1"})," Discard"]}),l&&y.jsx("span",{className:"text-[10px] text-amber-500",children:"unsaved changes"})]});return{draft:a,setDraft:s,error:u.error,saveBar:d}}function Xoe({doc:e,save:t,onDirty:n}){const{draft:r,setDraft:i,error:a,saveBar:s}=Y$(e,t,n),[l,u]=b.useState(""),[d,h]=b.useState(""),m=Object.keys(r.profiles),p=(x,E)=>i(_=>({..._,roles:{..._.roles,[x]:{..._.roles[x],...E}}})),g=(x,E)=>i(_=>({..._,profiles:{..._.profiles,[x]:{..._.profiles[x],...E}}})),w=(x,E)=>Object.fromEntries(Object.entries(x).filter(([_])=>_!==E));return y.jsxs("div",{className:"space-y-4",children:[y.jsx(Zs,{error:a}),y.jsxs("section",{className:"space-y-2",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Roles"}),y.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Owners come only from the OWNERS env; this row only picks their rank and profile."}),y.jsx("div",{className:"border rounded-lg divide-y",children:Object.entries(r.roles).sort((x,E)=>E[1].rank-x[1].rank).map(([x,E])=>y.jsxs("div",{className:"flex items-center gap-2 p-2",children:[y.jsx("span",{className:"text-sm font-medium w-28 truncate",children:x}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"rank"}),y.jsx(ht,{type:"number",className:`${yr} w-20`,value:Number.isFinite(E.rank)?E.rank:"",onChange:_=>p(x,{rank:_.target.value===""?NaN:Number(_.target.value)})}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"profile"}),y.jsxs("select",{className:wr,value:E.profile,onChange:_=>p(x,{profile:_.target.value}),children:[!m.includes(E.profile)&&y.jsxs("option",{value:E.profile,children:[E.profile," (missing)"]}),m.map(_=>y.jsx("option",{value:_,children:_},_))]}),y.jsx("div",{className:"flex-1"}),x!=="owner"&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove role",onClick:()=>i(_=>({..._,roles:w(_.roles,x)})),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]},x))}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-40`,placeholder:"new role name",value:l,onChange:x=>u(x.target.value.trim())}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!l||l in r.roles,onClick:()=>{i(x=>({...x,roles:{...x.roles,[l]:{rank:10,profile:m.includes("none")?"none":m[0]}}})),u("")},children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add role"]}),y.jsx("div",{className:"flex-1"}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"default role"}),y.jsx("select",{className:wr,value:r.default,onChange:x=>i(E=>({...E,default:x.target.value})),children:Object.keys(r.roles).filter(x=>x!=="owner").map(x=>y.jsx("option",{value:x,children:x},x))})]})]}),y.jsxs("section",{className:"space-y-2",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Profiles"}),Object.entries(r.profiles).map(([x,E])=>y.jsxs("div",{className:"border rounded-lg p-3 space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-sm font-medium",children:x}),y.jsx("div",{className:"flex-1"}),y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove profile",onClick:()=>i(_=>({..._,profiles:w(_.profiles,x)})),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]}),y.jsxs("div",{className:"grid grid-cols-[4.5rem_1fr] gap-x-2 gap-y-1.5 items-center",children:[["tools","mcps","env"].map(_=>y.jsx(Rp,{label:_,children:y.jsx(V$,{value:E[_],onChange:k=>g(x,{[_]:k}),placeholder:'comma-separated, "*" = all'})},_)),y.jsx(Rp,{label:"rate",children:y.jsx(ht,{className:`${yr} w-28`,value:E.rate,placeholder:"120/h",onChange:_=>g(x,{rate:_.target.value.trim()})})}),y.jsx(Rp,{label:"readScope",children:y.jsx("select",{className:`${wr} w-28`,value:E.readScope,onChange:_=>g(x,{readScope:_.target.value}),children:["all","own","none"].map(_=>y.jsx("option",{value:_,children:_},_))})}),y.jsx(Rp,{label:"outbound",children:y.jsx("input",{type:"checkbox",className:"h-4 w-4 justify-self-start",checked:E.outbound,onChange:_=>g(x,{outbound:_.target.checked})})})]})]},x)),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(ht,{className:`${yr} w-40`,placeholder:"new profile name",value:d,onChange:x=>h(x.target.value.trim())}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!d||d in r.profiles,onClick:()=>{i(x=>({...x,profiles:{...x.profiles,[d]:{tools:[],mcps:[],env:[],outbound:!1,readScope:"none",rate:"0"}}})),h("")},children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add profile"]})]})]}),s]})}function Rp({label:e,children:t}){return y.jsxs(y.Fragment,{children:[y.jsx("label",{className:"text-[11px] text-muted-foreground",children:e}),t]})}const Zoe=new Set(["kind","id","emailIn","domain","verified"]);function Qoe({doc:e,save:t,call:n,onDirty:r}){const{draft:i,setDraft:a,error:s,saveBar:l}=Y$(e,t,r),u=Object.keys(i.roles).filter(p=>p!=="owner"),d=p=>a(g=>({...g,bindings:p([...g.bindings])})),h=(p,g,w)=>d(x=>{const E={...x[p].match};return w===void 0||w===""||Array.isArray(w)&&!w.length?delete E[g]:E[g]=w,x[p]={...x[p],match:E},x}),m=(p,g)=>d(w=>{const[x]=w.splice(p,1);return w.splice(g,0,x),w});return y.jsxs("div",{className:"space-y-4",children:[y.jsx(Zs,{error:s}),y.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Ordered — the first matching binding decides the role; no match → default role ",y.jsx("b",{children:i.default}),"."]}),y.jsxs("div",{className:"space-y-2",children:[i.bindings.map((p,g)=>{const w=Object.entries(p.match).filter(([x])=>!Zoe.has(x));return y.jsxs("div",{className:"border rounded-lg p-2 space-y-1.5",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground w-5",children:["#",g+1]}),y.jsx("label",{className:"text-[10px] text-muted-foreground",children:"role"}),y.jsxs("select",{className:wr,value:p.role,onChange:x=>d(E=>(E[g]={...E[g],role:x.target.value},E)),children:[!u.includes(p.role)&&y.jsxs("option",{value:p.role,children:[p.role," (invalid)"]}),u.map(x=>y.jsx("option",{value:x,children:x},x))]}),y.jsx("div",{className:"flex-1"}),y.jsx("button",{className:sr,title:"Move up",disabled:g===0,onClick:()=>m(g,g-1),children:y.jsx(HG,{className:"w-3.5 h-3.5"})}),y.jsx("button",{className:sr,title:"Move down",disabled:g===i.bindings.length-1,onClick:()=>m(g,g+1),children:y.jsx(FG,{className:"w-3.5 h-3.5"})}),y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove",onClick:()=>d(x=>x.filter((E,_)=>_!==g)),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})]}),y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsxs("select",{className:wr,title:"kind",value:p.match.kind??"",onChange:x=>h(g,"kind",x.target.value),children:[y.jsx("option",{value:"",children:"any kind"}),G$.map(x=>y.jsx("option",{value:x,children:x},x))]}),y.jsxs("select",{className:wr,title:"verified",value:p.match.verified===void 0?"":String(p.match.verified),onChange:x=>h(g,"verified",x.target.value===""?void 0:x.target.value==="true"),children:[y.jsx("option",{value:"",children:"verified: any"}),y.jsx("option",{value:"true",children:"verified"}),y.jsx("option",{value:"false",children:"unverified"})]}),y.jsx(ht,{className:`${yr} w-40`,placeholder:"domain",value:p.match.domain??"",onChange:x=>h(g,"domain",x.target.value.trim())}),y.jsx(ht,{className:`${yr} w-48`,placeholder:"id (e.g. slack:U123)",value:p.match.id??"",onChange:x=>h(g,"id",x.target.value.trim())}),y.jsx("div",{className:"flex-1 min-w-48",children:y.jsx(V$,{value:p.match.emailIn,onChange:x=>h(g,"emailIn",x),placeholder:"emails (comma-separated)"})})]}),w.length>0&&y.jsxs("p",{className:"text-[10px] font-mono text-muted-foreground",children:["also matches: ",JSON.stringify(Object.fromEntries(w))]})]},g)}),y.jsxs(we,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:!u.length,onClick:()=>d(p=>[...p,{match:{kind:"user"},role:u.includes("guest")?"guest":u[u.length-1]}]),children:[y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Add binding"]})]}),l,y.jsx(Joe,{call:n})]})}function Joe({call:e}){const[t,n]=b.useState({kind:"user",email:"",id:"",verified:!0,lane:"",role:""}),[r,i]=b.useState(null),{busy:a,error:s,run:l}=ld(),u=h=>{n(m=>({...m,...h})),i(null)},d=()=>l("test",async()=>{i(await e("/policy/test","POST",{kind:t.kind,verified:t.verified,...t.email?{email:t.email}:{},...t.id?{id:t.id}:{},...t.lane?{lane:t.lane}:{},...t.role?{role:t.role}:{}}))});return y.jsxs("section",{className:"border rounded-lg p-3 space-y-2 bg-muted/20",children:[y.jsxs("h3",{className:"text-xs font-medium flex items-center gap-1.5",children:[y.jsx(ZG,{className:"w-3.5 h-3.5"})," Test a principal ",y.jsx("span",{className:"text-muted-foreground font-normal",children:"(against the SAVED policy)"})]}),y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsx("select",{className:wr,value:t.kind,onChange:h=>u({kind:h.target.value}),children:G$.map(h=>y.jsx("option",{value:h,children:h},h))}),y.jsx(ht,{className:`${yr} w-52`,placeholder:t.kind==="apikey"?"creator email":"email",value:t.email,onChange:h=>u({email:h.target.value.trim()})}),y.jsx(ht,{className:`${yr} w-32`,placeholder:"id (optional)",value:t.id,onChange:h=>u({id:h.target.value.trim()})}),t.kind==="internal"&&y.jsx(ht,{className:`${yr} w-28`,placeholder:"lane",value:t.lane,onChange:h=>u({lane:h.target.value.trim()})}),t.kind==="apikey"&&y.jsx(ht,{className:`${yr} w-28`,placeholder:"key role cap",value:t.role,onChange:h=>u({role:h.target.value.trim()})}),y.jsxs("label",{className:"flex items-center gap-1 text-xs",children:[y.jsx("input",{type:"checkbox",checked:t.verified,onChange:h=>u({verified:h.target.checked})})," verified"]}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!a,onClick:d,children:[a&&y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"})," Resolve"]})]}),y.jsx(Zs,{error:s}),r&&y.jsxs("p",{className:"text-xs font-mono",children:[r.principal," → role ",y.jsx("b",{children:r.role})," · rank ",r.rank," · profile ",y.jsx("b",{children:r.profile}),r.blocked&&y.jsxs("span",{className:"text-destructive",children:[" · BLOCKED",r.blocked.reason?` (${r.blocked.reason})`:""]})]})]})}const ese=[["permanent",0],["1 hour",3600],["24 hours",86400],["7 days",604800],["30 days",2592e3]];function tse({call:e,onPolicyChange:t}){const[n,r]=b.useState(null),[i,a]=b.useState({field:"id",value:"",ttl:0,reason:""}),{busy:s,error:l,run:u}=ld(),d=b.useCallback(async()=>r(await e("/blocks")),[e]);b.useEffect(()=>{u("load",d)},[d]);const h=()=>u("add",async()=>{const p=i.value.trim(),g=i.field==="emailIn"?{emailIn:[p]}:{[i.field]:p};await e("/blocks","POST",{match:g,until:i.ttl?Math.floor(Date.now()/1e3)+i.ttl:null,reason:i.reason}),a({...i,value:"",reason:""}),await Promise.all([d(),t()])}),m=p=>u("rm",async()=>{await e("/blocks","DELETE",p),await Promise.all([d(),t()])});return y.jsxs("div",{className:"space-y-4",children:[y.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.jsxs("select",{className:wr,value:i.field,onChange:p=>a({...i,field:p.target.value}),children:[y.jsx("option",{value:"id",children:"principal id"}),y.jsx("option",{value:"emailIn",children:"email"}),y.jsx("option",{value:"domain",children:"domain"})]}),y.jsx(ht,{className:`${yr} w-56`,placeholder:i.field==="id"?"user:x@y.com / slack:U123":i.field==="domain"?"spam.tld":"x@y.com",value:i.value,onChange:p=>a({...i,value:p.target.value})}),y.jsx("select",{className:wr,value:i.ttl,onChange:p=>a({...i,ttl:Number(p.target.value)}),children:ese.map(([p,g])=>y.jsx("option",{value:g,children:p},g))}),y.jsx(ht,{className:`${yr} w-40`,placeholder:"reason",value:i.reason,onChange:p=>a({...i,reason:p.target.value})}),y.jsxs(we,{size:"sm",className:"h-7 text-xs",disabled:!!s||!i.value.trim(),onClick:h,children:[s==="add"?y.jsx(Gi,{className:"w-3 h-3 mr-1 animate-spin"}):y.jsx(Eo,{className:"w-3 h-3 mr-1"})," Block"]}),y.jsx("button",{className:sr,title:"Refresh",onClick:()=>u("load",d),children:y.jsx(Ju,{className:`w-3.5 h-3.5 ${s==="load"?"animate-spin":""}`})})]}),y.jsx(Zs,{error:l}),y.jsxs("section",{className:"space-y-1",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Manual (policy)"}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Match"}),y.jsx("th",{className:Tt,children:"Until"}),y.jsx("th",{className:Tt,children:"Reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.manual.map(p=>{const g=p.until!==null&&p.until*1e3<=Date.now();return y.jsxs("tr",{className:g?"opacity-50":"",children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:Hoe(p.match)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:p.until===null?"permanent":`${Kl(p.until*1e3)}${g?" (expired)":""}`}),y.jsx("td",{className:Mt,children:p.reason||"—"}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Remove",disabled:!!s,onClick:()=>m({source:"manual",index:p.index,match:p.match}),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},p.index)}),n&&!n.manual.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:4,className:"text-center text-muted-foreground py-4",children:"No manual blocks."})})]})]})})]}),y.jsxs("section",{className:"space-y-1",children:[y.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Automatic (guard)"}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Key"}),y.jsx("th",{className:Tt,children:"Since"}),y.jsx("th",{className:Tt,children:"Until"}),y.jsx("th",{className:Tt,children:"Reason"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[n==null?void 0:n.auto.map(p=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:p.key}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.at)}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.until)}),y.jsx("td",{className:Mt,children:p.reason}),y.jsx("td",{className:`${Mt} text-right`,children:y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Clear",disabled:!!s,onClick:()=>m({source:"auto",key:p.key}),children:y.jsx(Vi,{className:"w-3.5 h-3.5"})})})]},p.key)),n&&!n.auto.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:5,className:"text-center text-muted-foreground py-4",children:"No active auto-blocks."})})]})]})})]})]})}function nse({call:e,onPolicyChange:t,ownerIds:n}){const[r,i]=b.useState(7),[a,s]=b.useState(null),{busy:l,error:u,run:d}=ld(),h=W$(e,t,n),m=b.useCallback(()=>d("load",async()=>s(await e(`/principals?days=${r}`))),[e,r]);return b.useEffect(()=>{m()},[m]),y.jsxs("div",{className:"space-y-2",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("span",{className:"text-xs text-muted-foreground",children:"Seen in the audit, last"}),y.jsx("select",{className:wr,value:r,onChange:p=>i(Number(p.target.value)),children:[1,7,30,90].map(p=>y.jsxs("option",{value:p,children:[p," day",p>1?"s":""]},p))}),y.jsx("button",{className:sr,title:"Refresh",onClick:m,children:y.jsx(Ju,{className:`w-3.5 h-3.5 ${l==="load"?"animate-spin":""}`})}),(a==null?void 0:a.truncated)&&y.jsx("span",{className:"text-[10px] text-amber-500",children:"scan capped — older activity omitted"})]}),y.jsx(Zs,{error:u}),y.jsx("div",{className:"border rounded-lg overflow-x-auto",children:y.jsxs("table",{className:"w-full text-xs",children:[y.jsx("thead",{className:"bg-muted/40",children:y.jsxs("tr",{children:[y.jsx("th",{className:Tt,children:"Principal"}),y.jsx("th",{className:Tt,children:"Kind"}),y.jsx("th",{className:Tt,children:"Last role"}),y.jsx("th",{className:Tt,children:"Last seen"}),y.jsx("th",{className:Tt,children:"Turns"}),y.jsx("th",{className:Tt,title:"Includes shadow (would-deny) verdicts",children:"Denies"}),y.jsx("th",{className:Tt})]})}),y.jsxs("tbody",{className:"divide-y",children:[a==null?void 0:a.principals.map(p=>y.jsxs("tr",{children:[y.jsx("td",{className:`${Mt} font-mono break-all`,children:p.id}),y.jsx("td",{className:Mt,children:p.kind}),y.jsx("td",{className:Mt,children:p.lastRole??"—"}),y.jsx("td",{className:`${Mt} whitespace-nowrap`,children:Kl(p.lastSeen)}),y.jsx("td",{className:Mt,children:p.turns}),y.jsx("td",{className:`${Mt} ${p.denies?"text-destructive":""}`,children:p.denies}),y.jsxs("td",{className:`${Mt} whitespace-nowrap text-right`,children:[h.canRevoke(p.id)&&y.jsx("button",{className:`${sr} mr-2`,title:"Revoke tokens",disabled:!!l,onClick:()=>d(`rv-${p.id}`,()=>h.revoke(p.id)),children:y.jsx(cL,{className:"w-3.5 h-3.5"})}),h.canBlock(p.id)&&y.jsx("button",{className:`${sr} hover:text-destructive`,title:"Block",disabled:!!l,onClick:()=>d(`bl-${p.id}`,()=>h.block(p.id)),children:y.jsx(oL,{className:"w-3.5 h-3.5"})})]})]},p.id)),a&&!a.principals.length&&y.jsx("tr",{children:y.jsx("td",{colSpan:7,className:"text-center text-muted-foreground py-6",children:"No principals in this window."})})]})]})})]})}const X$=[["roles","Roles & Profiles"],["bindings","Bindings"],["principals","Principals"],["keys","API keys"],["blocks","Blocklist"],["audit","Audit"]],Z$="owner-console-tab";function rse(){try{const e=localStorage.getItem(Z$);return X$.some(([t])=>t===e)?e:"roles"}catch{return"roles"}}function ise({call:e,onOpenSession:t,trigger:n}){const[r,i]=b.useState(!1),[a,s]=b.useState(rse),[l,u]=b.useState(null),[d,h]=b.useState(null),m=b.useCallback(async()=>{try{u(await e("/policy")),h(null)}catch(k){h((k==null?void 0:k.message)??String(k))}},[e]);b.useEffect(()=>{r&&m()},[r,m]);const p=async(k,O)=>{await e("/policy","PUT",{policy:k,version:O}),await m()},[g,w]=b.useState(!1),x=()=>!g||confirm("You have unsaved policy edits. Discard them?"),E=k=>{if(!(k===a||!x())){s(k);try{localStorage.setItem(Z$,k)}catch(O){console.warn("[owner] could not persist tab",O)}}},_=l?Object.keys(l.policy.roles).filter(k=>k!=="owner"):[];return y.jsxs(So,{open:r,onOpenChange:k=>{(k||x())&&i(k)},children:[y.jsx(nd,{asChild:!0,children:n}),y.jsxs(_a,{className:"max-w-[95vw] sm:max-w-5xl h-[85dvh] flex flex-col gap-0 p-0",children:[y.jsxs(Ls,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:[y.jsxs(_o,{className:"flex items-center gap-2",children:[y.jsx(Sh,{className:"w-4 h-4"})," Owner Console",y.jsx(we,{variant:"ghost",size:"icon",className:"h-6 w-6 ml-1",title:"Reload policy",onClick:m,children:y.jsx(Ju,{className:"w-3.5 h-3.5"})})]}),y.jsx("div",{className:"flex gap-1 overflow-x-auto pt-2",role:"tablist",children:X$.map(([k,O])=>y.jsx("button",{role:"tab","aria-selected":a===k,onClick:()=>E(k),className:$e("text-xs px-2.5 py-1 rounded-md whitespace-nowrap transition-colors",a===k?"bg-accent text-foreground font-medium":"text-muted-foreground hover:text-foreground"),children:O},k))})]}),y.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[y.jsx(Zs,{error:d}),l&&!l.valid&&y.jsx("p",{className:"text-xs text-destructive border border-destructive/40 rounded-md p-2",children:"The policy file is invalid — the server is failing closed (owners only). Saving a valid policy restores it."}),(a==="roles"||a==="bindings")&&!l&&!d&&y.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"Loading…"}),a==="roles"&&l&&y.jsx(Xoe,{doc:l,save:p,onDirty:w}),a==="bindings"&&l&&y.jsx(Qoe,{doc:l,save:p,call:e,onDirty:w}),a==="principals"&&y.jsx(nse,{call:e,onPolicyChange:m,ownerIds:(l==null?void 0:l.ownerIds)??[]}),a==="keys"&&y.jsx(qoe,{call:e,roles:_}),a==="blocks"&&y.jsx(tse,{call:e,onPolicyChange:m}),a==="audit"&&y.jsx(Yoe,{call:e,onPolicyChange:m,ownerIds:(l==null?void 0:l.ownerIds)??[],onOpenSession:async k=>{await t(k),i(!1)}})]})]})]})}function ase(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 Of="w-4 h-4 mt-0.5 shrink-0";function ose(e){const t=e.slackContext;return(t==null?void 0:t.type)==="dm"?y.jsx(iV,{className:`${Of} text-purple-400`}):(t==null?void 0:t.type)==="mention"?y.jsx(KG,{className:`${Of} text-blue-400`}):(t==null?void 0:t.type)==="channel"?y.jsx(JG,{className:`${Of} text-green-400`}):e.sessionId.startsWith("slack-")?y.jsx(Gw,{className:`${Of} text-yellow-400`}):y.jsx(Gw,{className:`${Of} text-muted-foreground`})}function sse(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 lse(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 cse({getToken:e,activeSessionId:t,onSelect:n,onNew:r,refreshKey:i,workspaceRefreshKey:a,onRefreshWorkspace:s,unreads:l={},busySessions:u=new Set,socket:d}){var $;const h=Pa(),[m,p]=b.useState(()=>localStorage.getItem(lI)||"mine"),[g,w]=b.useState(()=>localStorage.getItem(cI)==="true"),[x,E]=b.useState(""),{isOwner:_,call:k}=Foe(e),O=b.useRef(null);function N(R){p(R),localStorage.setItem(lI,R)}function C(){const R=!g;w(R),localStorage.setItem(cI,String(R))}const T=b.useMemo(()=>[t,...Object.keys(l)].filter(R=>!!R),[t,l]),{sessions:M,cursor:j,loading:L,byId:P,loadMore:H}=Uoe({getToken:e,filter:m,refreshKey:i,hydrateIds:T}),D=b.useMemo(()=>lse(l,P,m),[l,P,m]),G=D.length,q=b.useMemo(()=>g?[...D].sort((R,V)=>V.lastModified-R.lastModified):M,[g,D,M]),Y=t&&!q.some(R=>R.sessionId===t)?P.get(t):void 0;b.useEffect(()=>{O.current&&O.current.scrollIntoView({block:"nearest"})},[t,q,Y]);const U=b.useRef(null),K=b.useRef(H);K.current=H,b.useEffect(()=>{const R=U.current;if(!R||!j||g)return;const V=new IntersectionObserver(z=>{z.some(ie=>ie.isIntersecting)&&K.current()},{rootMargin:"300px"});return V.observe(R),()=>V.disconnect()},[j,L,g]),b.useEffect(()=>{e().then(R=>R?fetch("/api/version",{headers:{Authorization:`Bearer ${R}`}}):null).then(R=>R==null?void 0:R.json()).then(R=>R&&E(R.version)).catch(()=>{})},[]);const F=!!x&&x!=="unknown"&&kf!=="dev"&&x!==kf;b.useEffect(()=>{F&&console.warn(`[shraga] stale client bundle: built from v${kf}, server runs v${x} — rebuild dist/client`)},[F,x]);function Q(R){const V=l[R.sessionId],z=u.has(R.sessionId)||R.runStatus==="running"||R.scheduleRunStatus==="running",ie=!z&&(!!R.lastStopReason||R.scheduleRunStatus==="error"||R.scheduleRunStatus==="aborted"),me=z?"border-amber-500":ie?"border-red-500":V?"border-blue-500":"",fe=!!(z||ie||V);return y.jsx("button",{ref:R.sessionId===t?O:void 0,onClick:()=>n(R.sessionId,R.title),className:$e("w-full text-left px-3 py-2.5 text-sm transition-colors hover:bg-accent/50 group",fe?`rounded-r-lg border-l-[3px] ${me}`:"rounded-lg",t===R.sessionId&&"bg-accent"),children:y.jsxs("div",{className:"flex items-start gap-2",children:[ose(R),y.jsxs("div",{className:"min-w-0 flex-1",children:[y.jsx("span",{className:$e("block truncate text-sm leading-snug",V&&"font-semibold"),children:R.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:sse(R)||R.userName}),y.jsx("span",{className:"text-[10px] text-muted-foreground/50",children:"·"}),y.jsx("span",{className:"text-[10px] text-muted-foreground",children:ase(R.lastModified)})]})]})]})},R.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(Eo,{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(R=>y.jsx("button",{onClick:()=>N(R),className:$e("text-[10px] px-1.5 rounded-full transition-colors capitalize leading-none",m===R?"text-foreground font-medium":"text-muted-foreground/60 hover:text-muted-foreground"),children:R},R)),y.jsxs("button",{onClick:C,className:$e("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",G>0&&y.jsx("span",{className:"inline-block w-1.5 h-1.5 ml-1 rounded-full bg-blue-500 align-middle"})]})]})]}),y.jsx(kL,{className:"flex-1",children:y.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[q.length===0&&!Y&&y.jsx("p",{className:"text-xs text-muted-foreground px-3 py-6 text-center",children:L?"Loading…":g?"No unread conversations":"No conversations yet"}),Y&&Q(Y),q.map(Q),!g&&j&&y.jsx("div",{ref:U,className:"py-3 text-center text-[11px] text-muted-foreground/60",children:L?"Loading older…":"···"})]})}),y.jsxs("div",{className:"px-4 py-2 flex flex-col items-center gap-1",children:[_&&y.jsx(ise,{call:k,onOpenSession:async R=>{await $i(`/api/sessions/${encodeURIComponent(R)}/meta`,e),n(R)},trigger:y.jsxs("button",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground transition-colors",title:"Roles, bindings, keys, blocklist, audit",children:[y.jsx(Sh,{className:"w-3.5 h-3.5"})," Owner Console"]})}),y.jsx(Coe,{socket:d??null,getToken:e}),($=h.sidebarExtras)==null?void 0:$.call(h),x&&(F?y.jsxs("button",{onClick:()=>location.reload(),title:`This page was built from v${kf}, 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",kf," → v",x,") · reload"]}):y.jsxs("div",{className:"text-[10px] text-muted-foreground/50 text-center",children:["v",x]}))]})]})}function ti(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:Ns(),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:Ns(),role:"assistant",blocks:[i]}]}function Q$(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 use(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(D=>D!=null&&D===u.current,[]),k=b.useCallback(async()=>{var G;const D=u.current;if(D)try{const Y=await(await Dl(`/api/sessions/${D}/messages`,m.current)).json();r(tL(Y)),a(!!Y.busy),(G=w.current)==null||G.call(w,Array.isArray(Y.participants)&&Y.participants.length>1)}catch{}},[]);b.useEffect(()=>{if(!e)return;const D=e.on(G=>{var Y,U,K,F,Q,$;(Y=x.current)==null||Y.call(x,G);const q=G;if(q.type==="compact_marker")return _(q.sessionId)?r(R=>[...R,{id:Ns(),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(R=>ti(R,{type:"thinking",text:G.text})):void 0;case"text_delta":return _(G.sessionId)?r(R=>ti(R,{type:"text",text:G.text})):void 0;case"tool_use":return _(G.sessionId)?r(R=>ti(R,{type:"tool_use",tool:G.tool,toolUseId:G.toolUseId,input:G.input})):void 0;case"tool_use_input":return _(G.sessionId)?r(R=>Q$(R,G.toolUseId,G.input)):void 0;case"tool_result":return _(G.sessionId)?r(R=>ti(R,{type:"tool_result",toolUseId:G.toolUseId,output:G.output})):void 0;case"tool_result_image":return _(G.sessionId)?r(R=>ti(R,{type:"image",src:G.dataUrl})):void 0;case"permission_request":return _(G.sessionId)?r(R=>ti(R,{type:"permission_request",id:G.id,tool:G.tool,input:G.input})):void 0;case"question_request":return _(G.sessionId)?r(R=>ti(R,{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:dse(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(V=>ti(V,{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.`})),(Q=p.current)==null||Q.call(p,G.sessionId);const R=h.current;if(R.length>0){const V=R.join(`
|
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
16
|
+
<script type="module" crossorigin src="/assets/index-CeGkHIed.js"></script>
|
|
17
17
|
<link rel="stylesheet" crossorigin href="/assets/index-CFxKc8dH.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.
|
|
3
|
+
"version": "0.1.115",
|
|
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",
|
package/src/server/workspace.ts
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { dataPath } from './paths.ts';
|
|
4
4
|
import { dataSync } from './data-sync.ts';
|
|
5
5
|
import { injectFile } from './file-inject.ts';
|
|
6
|
+
import { getPublicOrigin } from './shraga-config.ts';
|
|
6
7
|
|
|
7
8
|
export const WORKSPACE_DIR = process.env.WORKSPACE_DIR || dataPath('workspace');
|
|
8
9
|
|
|
@@ -163,6 +164,13 @@ export function readWorkspaceFile(relPath: string): { content: string; binary: b
|
|
|
163
164
|
return { content: readFileSync(resolved, 'utf-8'), binary: false };
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
/** How to hand a user a link to a file (video, image, PDF). Without it the agent invents share routes that don't exist. */
|
|
168
|
+
function shareFilesGuide(): string {
|
|
169
|
+
const origin = getPublicOrigin();
|
|
170
|
+
if (!origin) return 'SHARING FILES: this deployment has no public origin — send files as attachments (e.g. Slack file upload), never a made-up URL.';
|
|
171
|
+
return `SHARING FILES: to give a link to a file, copy it to ${dataPath('uploads/shared')}/<random-hex>-<name> and link ${origin}/uploads/shared/<random-hex>-<name> (public, no login). Before sending, verify the link with \`curl -sI\` returns 200 and the right content-type. Never invent other share routes.`;
|
|
172
|
+
}
|
|
173
|
+
|
|
166
174
|
export function buildWorkspaceContextBlock(): string {
|
|
167
175
|
const entries = listWorkspaceTree();
|
|
168
176
|
const lines: string[] = [];
|
|
@@ -189,6 +197,7 @@ export function buildWorkspaceContextBlock(): string {
|
|
|
189
197
|
'',
|
|
190
198
|
'Files explicitly @-mentioned by the user are already inlined below as <workspace-file> blocks. For anything else in the tree, read on demand.',
|
|
191
199
|
'',
|
|
200
|
+
shareFilesGuide(),
|
|
192
201
|
entries.length === 0
|
|
193
202
|
? 'Tree: (empty — feel free to create initial files like tasks.md, context.md, research/, etc.)'
|
|
194
203
|
: 'Tree (paths shown relative to workspace root):',
|