var gt=Object.defineProperty;var vt=(t,s,n)=>s in t?gt(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var me=(t,s,n)=>vt(t,typeof s!="symbol"?s+"":s,n);import{r as jt,g as yt,a as h,b as _t,L as bt,U as ye,T as re,S as ae,A as ne,W as Nt,d as wt,e as kt,f as St,h as Ct,i as Ge,j as Et,k as Ye,F as Rt,l as Lt,C as Tt,m as Pt,n as $t,R as zt}from"./icons-G_aW_LLg.js";import{r as It,R as Pe,a as At,P as Dt,b as Ot,c as Bt,d as Ft,A as Ut,C as Wt,X as Mt,Y as qt,T as Vt,e as Ht}from"./charts-BNPC6VHN.js";import"./d3-vendor-CqUrYQfI.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=n(a);fetch(a.href,i)}})();var pe={exports:{}},J={};/**
 * @license React
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var $e;function Jt(){if($e)return J;$e=1;var t=jt(),s=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function o(m,l,c){var d,u={},f=null,j=null;c!==void 0&&(f=""+c),l.key!==void 0&&(f=""+l.key),l.ref!==void 0&&(j=l.ref);for(d in l)r.call(l,d)&&!i.hasOwnProperty(d)&&(u[d]=l[d]);if(m&&m.defaultProps)for(d in l=m.defaultProps,l)u[d]===void 0&&(u[d]=l[d]);return{$$typeof:s,type:m,key:f,ref:j,props:u,_owner:a.current}}return J.Fragment=n,J.jsx=o,J.jsxs=o,J}var ze;function Kt(){return ze||(ze=1,pe.exports=Jt()),pe.exports}var e=Kt(),te={},Ie;function Gt(){if(Ie)return te;Ie=1;var t=It();return te.createRoot=t.createRoot,te.hydrateRoot=t.hydrateRoot,te}var Yt=Gt();const Xt=yt(Yt);/**
 * @remix-run/router v1.23.2
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function Q(){return Q=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Q.apply(this,arguments)}var A;(function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"})(A||(A={}));const Ae="popstate";function Qt(t){t===void 0&&(t={});function s(r,a){let{pathname:i,search:o,hash:m}=r.location;return _e("",{pathname:i,search:o,hash:m},a.state&&a.state.usr||null,a.state&&a.state.key||"default")}function n(r,a){return typeof a=="string"?a:ie(a)}return es(s,n,null,t)}function w(t,s){if(t===!1||t===null||typeof t>"u")throw new Error(s)}function Se(t,s){if(!t){typeof console<"u"&&console.warn(s);try{throw new Error(s)}catch{}}}function Zt(){return Math.random().toString(36).substr(2,8)}function De(t,s){return{usr:t.state,key:t.key,idx:s}}function _e(t,s,n,r){return n===void 0&&(n=null),Q({pathname:typeof t=="string"?t:t.pathname,search:"",hash:""},typeof s=="string"?q(s):s,{state:n,key:s&&s.key||r||Zt()})}function ie(t){let{pathname:s="/",search:n="",hash:r=""}=t;return n&&n!=="?"&&(s+=n.charAt(0)==="?"?n:"?"+n),r&&r!=="#"&&(s+=r.charAt(0)==="#"?r:"#"+r),s}function q(t){let s={};if(t){let n=t.indexOf("#");n>=0&&(s.hash=t.substr(n),t=t.substr(0,n));let r=t.indexOf("?");r>=0&&(s.search=t.substr(r),t=t.substr(0,r)),t&&(s.pathname=t)}return s}function es(t,s,n,r){r===void 0&&(r={});let{window:a=document.defaultView,v5Compat:i=!1}=r,o=a.history,m=A.Pop,l=null,c=d();c==null&&(c=0,o.replaceState(Q({},o.state,{idx:c}),""));function d(){return(o.state||{idx:null}).idx}function u(){m=A.Pop;let v=d(),g=v==null?null:v-c;c=v,l&&l({action:m,location:_.location,delta:g})}function f(v,g){m=A.Push;let p=_e(_.location,v,g);c=d()+1;let x=De(p,c),b=_.createHref(p);try{o.pushState(x,"",b)}catch(N){if(N instanceof DOMException&&N.name==="DataCloneError")throw N;a.location.assign(b)}i&&l&&l({action:m,location:_.location,delta:1})}function j(v,g){m=A.Replace;let p=_e(_.location,v,g);c=d();let x=De(p,c),b=_.createHref(p);o.replaceState(x,"",b),i&&l&&l({action:m,location:_.location,delta:0})}function y(v){let g=a.location.origin!=="null"?a.location.origin:a.location.href,p=typeof v=="string"?v:ie(v);return p=p.replace(/ $/,"%20"),w(g,"No window.location.(origin|href) available to create URL for href: "+p),new URL(p,g)}let _={get action(){return m},get location(){return t(a,o)},listen(v){if(l)throw new Error("A history only accepts one active listener");return a.addEventListener(Ae,u),l=v,()=>{a.removeEventListener(Ae,u),l=null}},createHref(v){return s(a,v)},createURL:y,encodeLocation(v){let g=y(v);return{pathname:g.pathname,search:g.search,hash:g.hash}},push:f,replace:j,go(v){return o.go(v)}};return _}var Oe;(function(t){t.data="data",t.deferred="deferred",t.redirect="redirect",t.error="error"})(Oe||(Oe={}));function ts(t,s,n){return n===void 0&&(n="/"),ss(t,s,n)}function ss(t,s,n,r){let a=typeof s=="string"?q(s):s,i=M(a.pathname||"/",n);if(i==null)return null;let o=Xe(t);ns(o);let m=null;for(let l=0;m==null&&l<o.length;++l){let c=ps(i);m=hs(o[l],c)}return m}function Xe(t,s,n,r){s===void 0&&(s=[]),n===void 0&&(n=[]),r===void 0&&(r="");let a=(i,o,m)=>{let l={relativePath:m===void 0?i.path||"":m,caseSensitive:i.caseSensitive===!0,childrenIndex:o,route:i};l.relativePath.startsWith("/")&&(w(l.relativePath.startsWith(r),'Absolute route path "'+l.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),l.relativePath=l.relativePath.slice(r.length));let c=D([r,l.relativePath]),d=n.concat(l);i.children&&i.children.length>0&&(w(i.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+c+'".')),Xe(i.children,s,d,c)),!(i.path==null&&!i.index)&&s.push({path:c,score:ds(c,i.index),routesMeta:d})};return t.forEach((i,o)=>{var m;if(i.path===""||!((m=i.path)!=null&&m.includes("?")))a(i,o);else for(let l of Qe(i.path))a(i,o,l)}),s}function Qe(t){let s=t.split("/");if(s.length===0)return[];let[n,...r]=s,a=n.endsWith("?"),i=n.replace(/\?$/,"");if(r.length===0)return a?[i,""]:[i];let o=Qe(r.join("/")),m=[];return m.push(...o.map(l=>l===""?i:[i,l].join("/"))),a&&m.push(...o),m.map(l=>t.startsWith("/")&&l===""?"/":l)}function ns(t){t.sort((s,n)=>s.score!==n.score?n.score-s.score:us(s.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}const rs=/^:[\w-]+$/,as=3,is=2,ls=1,os=10,cs=-2,Be=t=>t==="*";function ds(t,s){let n=t.split("/"),r=n.length;return n.some(Be)&&(r+=cs),s&&(r+=is),n.filter(a=>!Be(a)).reduce((a,i)=>a+(rs.test(i)?as:i===""?ls:os),r)}function us(t,s){return t.length===s.length&&t.slice(0,-1).every((r,a)=>r===s[a])?t[t.length-1]-s[s.length-1]:0}function hs(t,s,n){let{routesMeta:r}=t,a={},i="/",o=[];for(let m=0;m<r.length;++m){let l=r[m],c=m===r.length-1,d=i==="/"?s:s.slice(i.length)||"/",u=be({path:l.relativePath,caseSensitive:l.caseSensitive,end:c},d),f=l.route;if(!u)return null;Object.assign(a,u.params),o.push({params:a,pathname:D([i,u.pathname]),pathnameBase:js(D([i,u.pathnameBase])),route:f}),u.pathnameBase!=="/"&&(i=D([i,u.pathnameBase]))}return o}function be(t,s){typeof t=="string"&&(t={path:t,caseSensitive:!1,end:!0});let[n,r]=ms(t.path,t.caseSensitive,t.end),a=s.match(n);if(!a)return null;let i=a[0],o=i.replace(/(.)\/+$/,"$1"),m=a.slice(1);return{params:r.reduce((c,d,u)=>{let{paramName:f,isOptional:j}=d;if(f==="*"){let _=m[u]||"";o=i.slice(0,i.length-_.length).replace(/(.)\/+$/,"$1")}const y=m[u];return j&&!y?c[f]=void 0:c[f]=(y||"").replace(/%2F/g,"/"),c},{}),pathname:i,pathnameBase:o,pattern:t}}function ms(t,s,n){s===void 0&&(s=!1),n===void 0&&(n=!0),Se(t==="*"||!t.endsWith("*")||t.endsWith("/*"),'Route path "'+t+'" will be treated as if it were '+('"'+t.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+t.replace(/\*$/,"/*")+'".'));let r=[],a="^"+t.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(o,m,l)=>(r.push({paramName:m,isOptional:l!=null}),l?"/?([^\\/]+)?":"/([^\\/]+)"));return t.endsWith("*")?(r.push({paramName:"*"}),a+=t==="*"||t==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?a+="\\/*$":t!==""&&t!=="/"&&(a+="(?:(?=\\/|$))"),[new RegExp(a,s?void 0:"i"),r]}function ps(t){try{return t.split("/").map(s=>decodeURIComponent(s).replace(/\//g,"%2F")).join("/")}catch(s){return Se(!1,'The URL path "'+t+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+s+").")),t}}function M(t,s){if(s==="/")return t;if(!t.toLowerCase().startsWith(s.toLowerCase()))return null;let n=s.endsWith("/")?s.length-1:s.length,r=t.charAt(n);return r&&r!=="/"?null:t.slice(n)||"/"}const fs=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,xs=t=>fs.test(t);function gs(t,s){s===void 0&&(s="/");let{pathname:n,search:r="",hash:a=""}=typeof t=="string"?q(t):t,i;if(n)if(xs(n))i=n;else{if(n.includes("//")){let o=n;n=n.replace(/\/\/+/g,"/"),Se(!1,"Pathnames cannot have embedded double slashes - normalizing "+(o+" -> "+n))}n.startsWith("/")?i=Fe(n.substring(1),"/"):i=Fe(n,s)}else i=s;return{pathname:i,search:ys(r),hash:_s(a)}}function Fe(t,s){let n=s.replace(/\/+$/,"").split("/");return t.split("/").forEach(a=>{a===".."?n.length>1&&n.pop():a!=="."&&n.push(a)}),n.length>1?n.join("/"):"/"}function fe(t,s,n,r){return"Cannot include a '"+t+"' character in a manually specified "+("`to."+s+"` field ["+JSON.stringify(r)+"].  Please separate it out to the ")+("`to."+n+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function vs(t){return t.filter((s,n)=>n===0||s.route.path&&s.route.path.length>0)}function Ce(t,s){let n=vs(t);return s?n.map((r,a)=>a===n.length-1?r.pathname:r.pathnameBase):n.map(r=>r.pathnameBase)}function Ee(t,s,n,r){r===void 0&&(r=!1);let a;typeof t=="string"?a=q(t):(a=Q({},t),w(!a.pathname||!a.pathname.includes("?"),fe("?","pathname","search",a)),w(!a.pathname||!a.pathname.includes("#"),fe("#","pathname","hash",a)),w(!a.search||!a.search.includes("#"),fe("#","search","hash",a)));let i=t===""||a.pathname==="",o=i?"/":a.pathname,m;if(o==null)m=n;else{let u=s.length-1;if(!r&&o.startsWith("..")){let f=o.split("/");for(;f[0]==="..";)f.shift(),u-=1;a.pathname=f.join("/")}m=u>=0?s[u]:"/"}let l=gs(a,m),c=o&&o!=="/"&&o.endsWith("/"),d=(i||o===".")&&n.endsWith("/");return!l.pathname.endsWith("/")&&(c||d)&&(l.pathname+="/"),l}const D=t=>t.join("/").replace(/\/\/+/g,"/"),js=t=>t.replace(/\/+$/,"").replace(/^\/*/,"/"),ys=t=>!t||t==="?"?"":t.startsWith("?")?t:"?"+t,_s=t=>!t||t==="#"?"":t.startsWith("#")?t:"#"+t;function bs(t){return t!=null&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.internal=="boolean"&&"data"in t}const Ze=["post","put","patch","delete"];new Set(Ze);const Ns=["get",...Ze];new Set(Ns);/**
 * React Router v6.30.3
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function Z(){return Z=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Z.apply(this,arguments)}const de=h.createContext(null),et=h.createContext(null),T=h.createContext(null),ue=h.createContext(null),L=h.createContext({outlet:null,matches:[],isDataRoute:!1}),tt=h.createContext(null);function ws(t,s){let{relative:n}=s===void 0?{}:s;V()||w(!1);let{basename:r,navigator:a}=h.useContext(T),{hash:i,pathname:o,search:m}=he(t,{relative:n}),l=o;return r!=="/"&&(l=o==="/"?r:D([r,o])),a.createHref({pathname:l,search:m,hash:i})}function V(){return h.useContext(ue)!=null}function U(){return V()||w(!1),h.useContext(ue).location}function st(t){h.useContext(T).static||h.useLayoutEffect(t)}function nt(){let{isDataRoute:t}=h.useContext(L);return t?Fs():ks()}function ks(){V()||w(!1);let t=h.useContext(de),{basename:s,future:n,navigator:r}=h.useContext(T),{matches:a}=h.useContext(L),{pathname:i}=U(),o=JSON.stringify(Ce(a,n.v7_relativeSplatPath)),m=h.useRef(!1);return st(()=>{m.current=!0}),h.useCallback(function(c,d){if(d===void 0&&(d={}),!m.current)return;if(typeof c=="number"){r.go(c);return}let u=Ee(c,JSON.parse(o),i,d.relative==="path");t==null&&s!=="/"&&(u.pathname=u.pathname==="/"?s:D([s,u.pathname])),(d.replace?r.replace:r.push)(u,d.state,d)},[s,r,o,i,t])}const Ss=h.createContext(null);function Cs(t){let s=h.useContext(L).outlet;return s&&h.createElement(Ss.Provider,{value:t},s)}function Es(){let{matches:t}=h.useContext(L),s=t[t.length-1];return s?s.params:{}}function he(t,s){let{relative:n}=s===void 0?{}:s,{future:r}=h.useContext(T),{matches:a}=h.useContext(L),{pathname:i}=U(),o=JSON.stringify(Ce(a,r.v7_relativeSplatPath));return h.useMemo(()=>Ee(t,JSON.parse(o),i,n==="path"),[t,o,i,n])}function Rs(t,s){return Ls(t,s)}function Ls(t,s,n,r){V()||w(!1);let{navigator:a}=h.useContext(T),{matches:i}=h.useContext(L),o=i[i.length-1],m=o?o.params:{};o&&o.pathname;let l=o?o.pathnameBase:"/";o&&o.route;let c=U(),d;if(s){var u;let v=typeof s=="string"?q(s):s;l==="/"||(u=v.pathname)!=null&&u.startsWith(l)||w(!1),d=v}else d=c;let f=d.pathname||"/",j=f;if(l!=="/"){let v=l.replace(/^\//,"").split("/");j="/"+f.replace(/^\//,"").split("/").slice(v.length).join("/")}let y=ts(t,{pathname:j}),_=Is(y&&y.map(v=>Object.assign({},v,{params:Object.assign({},m,v.params),pathname:D([l,a.encodeLocation?a.encodeLocation(v.pathname).pathname:v.pathname]),pathnameBase:v.pathnameBase==="/"?l:D([l,a.encodeLocation?a.encodeLocation(v.pathnameBase).pathname:v.pathnameBase])})),i,n,r);return s&&_?h.createElement(ue.Provider,{value:{location:Z({pathname:"/",search:"",hash:"",state:null,key:"default"},d),navigationType:A.Pop}},_):_}function Ts(){let t=Bs(),s=bs(t)?t.status+" "+t.statusText:t instanceof Error?t.message:JSON.stringify(t),n=t instanceof Error?t.stack:null,a={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return h.createElement(h.Fragment,null,h.createElement("h2",null,"Unexpected Application Error!"),h.createElement("h3",{style:{fontStyle:"italic"}},s),n?h.createElement("pre",{style:a},n):null,null)}const Ps=h.createElement(Ts,null);class $s extends h.Component{constructor(s){super(s),this.state={location:s.location,revalidation:s.revalidation,error:s.error}}static getDerivedStateFromError(s){return{error:s}}static getDerivedStateFromProps(s,n){return n.location!==s.location||n.revalidation!=="idle"&&s.revalidation==="idle"?{error:s.error,location:s.location,revalidation:s.revalidation}:{error:s.error!==void 0?s.error:n.error,location:n.location,revalidation:s.revalidation||n.revalidation}}componentDidCatch(s,n){console.error("React Router caught the following error during render",s,n)}render(){return this.state.error!==void 0?h.createElement(L.Provider,{value:this.props.routeContext},h.createElement(tt.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function zs(t){let{routeContext:s,match:n,children:r}=t,a=h.useContext(de);return a&&a.static&&a.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(a.staticContext._deepestRenderedBoundaryId=n.route.id),h.createElement(L.Provider,{value:s},r)}function Is(t,s,n,r){var a;if(s===void 0&&(s=[]),n===void 0&&(n=null),r===void 0&&(r=null),t==null){var i;if(!n)return null;if(n.errors)t=n.matches;else if((i=r)!=null&&i.v7_partialHydration&&s.length===0&&!n.initialized&&n.matches.length>0)t=n.matches;else return null}let o=t,m=(a=n)==null?void 0:a.errors;if(m!=null){let d=o.findIndex(u=>u.route.id&&(m==null?void 0:m[u.route.id])!==void 0);d>=0||w(!1),o=o.slice(0,Math.min(o.length,d+1))}let l=!1,c=-1;if(n&&r&&r.v7_partialHydration)for(let d=0;d<o.length;d++){let u=o[d];if((u.route.HydrateFallback||u.route.hydrateFallbackElement)&&(c=d),u.route.id){let{loaderData:f,errors:j}=n,y=u.route.loader&&f[u.route.id]===void 0&&(!j||j[u.route.id]===void 0);if(u.route.lazy||y){l=!0,c>=0?o=o.slice(0,c+1):o=[o[0]];break}}}return o.reduceRight((d,u,f)=>{let j,y=!1,_=null,v=null;n&&(j=m&&u.route.id?m[u.route.id]:void 0,_=u.route.errorElement||Ps,l&&(c<0&&f===0?(Us("route-fallback"),y=!0,v=null):c===f&&(y=!0,v=u.route.hydrateFallbackElement||null)));let g=s.concat(o.slice(0,f+1)),p=()=>{let x;return j?x=_:y?x=v:u.route.Component?x=h.createElement(u.route.Component,null):u.route.element?x=u.route.element:x=d,h.createElement(zs,{match:u,routeContext:{outlet:d,matches:g,isDataRoute:n!=null},children:x})};return n&&(u.route.ErrorBoundary||u.route.errorElement||f===0)?h.createElement($s,{location:n.location,revalidation:n.revalidation,component:_,error:j,children:p(),routeContext:{outlet:null,matches:g,isDataRoute:!0}}):p()},null)}var rt=(function(t){return t.UseBlocker="useBlocker",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t})(rt||{}),at=(function(t){return t.UseBlocker="useBlocker",t.UseLoaderData="useLoaderData",t.UseActionData="useActionData",t.UseRouteError="useRouteError",t.UseNavigation="useNavigation",t.UseRouteLoaderData="useRouteLoaderData",t.UseMatches="useMatches",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t.UseRouteId="useRouteId",t})(at||{});function As(t){let s=h.useContext(de);return s||w(!1),s}function Ds(t){let s=h.useContext(et);return s||w(!1),s}function Os(t){let s=h.useContext(L);return s||w(!1),s}function it(t){let s=Os(),n=s.matches[s.matches.length-1];return n.route.id||w(!1),n.route.id}function Bs(){var t;let s=h.useContext(tt),n=Ds(),r=it();return s!==void 0?s:(t=n.errors)==null?void 0:t[r]}function Fs(){let{router:t}=As(rt.UseNavigateStable),s=it(at.UseNavigateStable),n=h.useRef(!1);return st(()=>{n.current=!0}),h.useCallback(function(a,i){i===void 0&&(i={}),n.current&&(typeof a=="number"?t.navigate(a):t.navigate(a,Z({fromRouteId:s},i)))},[t,s])}const Ue={};function Us(t,s,n){Ue[t]||(Ue[t]=!0)}function Ws(t,s){t==null||t.v7_startTransition,t==null||t.v7_relativeSplatPath}function Ms(t){let{to:s,replace:n,state:r,relative:a}=t;V()||w(!1);let{future:i,static:o}=h.useContext(T),{matches:m}=h.useContext(L),{pathname:l}=U(),c=nt(),d=Ee(s,Ce(m,i.v7_relativeSplatPath),l,a==="path"),u=JSON.stringify(d);return h.useEffect(()=>c(JSON.parse(u),{replace:n,state:r,relative:a}),[c,u,a,n,r]),null}function qs(t){return Cs(t.context)}function I(t){w(!1)}function Vs(t){let{basename:s="/",children:n=null,location:r,navigationType:a=A.Pop,navigator:i,static:o=!1,future:m}=t;V()&&w(!1);let l=s.replace(/^\/*/,"/"),c=h.useMemo(()=>({basename:l,navigator:i,static:o,future:Z({v7_relativeSplatPath:!1},m)}),[l,m,i,o]);typeof r=="string"&&(r=q(r));let{pathname:d="/",search:u="",hash:f="",state:j=null,key:y="default"}=r,_=h.useMemo(()=>{let v=M(d,l);return v==null?null:{location:{pathname:v,search:u,hash:f,state:j,key:y},navigationType:a}},[l,d,u,f,j,y,a]);return _==null?null:h.createElement(T.Provider,{value:c},h.createElement(ue.Provider,{children:n,value:_}))}function Hs(t){let{children:s,location:n}=t;return Rs(Ne(s),n)}new Promise(()=>{});function Ne(t,s){s===void 0&&(s=[]);let n=[];return h.Children.forEach(t,(r,a)=>{if(!h.isValidElement(r))return;let i=[...s,a];if(r.type===h.Fragment){n.push.apply(n,Ne(r.props.children,i));return}r.type!==I&&w(!1),!r.props.index||!r.props.children||w(!1);let o={id:r.props.id||i.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(o.children=Ne(r.props.children,i)),n.push(o)}),n}/**
 * React Router DOM v6.30.3
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */function le(){return le=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},le.apply(this,arguments)}function lt(t,s){if(t==null)return{};var n={},r=Object.keys(t),a,i;for(i=0;i<r.length;i++)a=r[i],!(s.indexOf(a)>=0)&&(n[a]=t[a]);return n}function Js(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}function Ks(t,s){return t.button===0&&(!s||s==="_self")&&!Js(t)}const Gs=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],Ys=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],Xs="6";try{window.__reactRouterVersion=Xs}catch{}const Qs=h.createContext({isTransitioning:!1}),Zs="startTransition",We=_t[Zs];function en(t){let{basename:s,children:n,future:r,window:a}=t,i=h.useRef();i.current==null&&(i.current=Qt({window:a,v5Compat:!0}));let o=i.current,[m,l]=h.useState({action:o.action,location:o.location}),{v7_startTransition:c}=r||{},d=h.useCallback(u=>{c&&We?We(()=>l(u)):l(u)},[l,c]);return h.useLayoutEffect(()=>o.listen(d),[o,d]),h.useEffect(()=>Ws(r),[r]),h.createElement(Vs,{basename:s,children:n,location:m.location,navigationType:m.action,navigator:o,future:r})}const tn=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",sn=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,O=h.forwardRef(function(s,n){let{onClick:r,relative:a,reloadDocument:i,replace:o,state:m,target:l,to:c,preventScrollReset:d,viewTransition:u}=s,f=lt(s,Gs),{basename:j}=h.useContext(T),y,_=!1;if(typeof c=="string"&&sn.test(c)&&(y=c,tn))try{let x=new URL(window.location.href),b=c.startsWith("//")?new URL(x.protocol+c):new URL(c),N=M(b.pathname,j);b.origin===x.origin&&N!=null?c=N+b.search+b.hash:_=!0}catch{}let v=ws(c,{relative:a}),g=an(c,{replace:o,state:m,target:l,preventScrollReset:d,relative:a,viewTransition:u});function p(x){r&&r(x),x.defaultPrevented||g(x)}return h.createElement("a",le({},f,{href:y||v,onClick:_||i?r:p,ref:n,target:l}))}),nn=h.forwardRef(function(s,n){let{"aria-current":r="page",caseSensitive:a=!1,className:i="",end:o=!1,style:m,to:l,viewTransition:c,children:d}=s,u=lt(s,Ys),f=he(l,{relative:u.relative}),j=U(),y=h.useContext(et),{navigator:_,basename:v}=h.useContext(T),g=y!=null&&ln(f)&&c===!0,p=_.encodeLocation?_.encodeLocation(f).pathname:f.pathname,x=j.pathname,b=y&&y.navigation&&y.navigation.location?y.navigation.location.pathname:null;a||(x=x.toLowerCase(),b=b?b.toLowerCase():null,p=p.toLowerCase()),b&&v&&(b=M(b,v)||b);const N=p!=="/"&&p.endsWith("/")?p.length-1:p.length;let S=x===p||!o&&x.startsWith(p)&&x.charAt(N)==="/",P=b!=null&&(b===p||!o&&b.startsWith(p)&&b.charAt(p.length)==="/"),W={isActive:S,isPending:P,isTransitioning:g},F=S?r:void 0,E;typeof i=="function"?E=i(W):E=[i,S?"active":null,P?"pending":null,g?"transitioning":null].filter(Boolean).join(" ");let H=typeof m=="function"?m(W):m;return h.createElement(O,le({},u,{"aria-current":F,className:E,ref:n,style:H,to:l,viewTransition:c}),typeof d=="function"?d(W):d)});var we;(function(t){t.UseScrollRestoration="useScrollRestoration",t.UseSubmit="useSubmit",t.UseSubmitFetcher="useSubmitFetcher",t.UseFetcher="useFetcher",t.useViewTransitionState="useViewTransitionState"})(we||(we={}));var Me;(function(t){t.UseFetcher="useFetcher",t.UseFetchers="useFetchers",t.UseScrollRestoration="useScrollRestoration"})(Me||(Me={}));function rn(t){let s=h.useContext(de);return s||w(!1),s}function an(t,s){let{target:n,replace:r,state:a,preventScrollReset:i,relative:o,viewTransition:m}=s===void 0?{}:s,l=nt(),c=U(),d=he(t,{relative:o});return h.useCallback(u=>{if(Ks(u,n)){u.preventDefault();let f=r!==void 0?r:ie(c)===ie(d);l(t,{replace:f,state:a,preventScrollReset:i,relative:o,viewTransition:m})}},[c,l,d,r,a,n,t,i,o,m])}function ln(t,s){s===void 0&&(s={});let n=h.useContext(Qs);n==null&&w(!1);let{basename:r}=rn(we.useViewTransitionState),a=he(t,{relative:s.relative});if(!n.isTransitioning)return!1;let i=M(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=M(n.nextLocation.pathname,r)||n.nextLocation.pathname;return be(a.pathname,o)!=null||be(a.pathname,i)!=null}let Y=null;function ot(t){Y=t,sessionStorage.setItem("ahp_token",t)}function Re(){return Y||(Y=sessionStorage.getItem("ahp_token")),Y}function ct(){Y=null,sessionStorage.removeItem("ahp_token")}class dt extends Error{constructor(){super(...arguments);me(this,"name","AuthError")}}class ut extends Error{constructor(s,n){super(n),this.status=s,this.name="ApiError"}}async function $(t,s){const n=Re(),r={"Content-Type":"application/json",...(s==null?void 0:s.headers)||{}};n&&(r.Authorization=`Bearer ${n}`);const a=await fetch(t,{...s,headers:r});if(a.status===401)throw ct(),new dt("Unauthorized");if(!a.ok)throw new ut(a.status,await a.text());return a.json()}const R={health:()=>$("/health"),summary:t=>$(`/report/summary${t?`?window_seconds=${t}`:""}`),sessions:async t=>{const s=new URLSearchParams;return t!=null&&t.sort&&s.set("sort",t.sort),t!=null&&t.limit&&s.set("limit",String(t.limit)),t!=null&&t.min_risk&&s.set("min_risk",t.min_risk),(await $(`/report/sessions?${s}`)).sessions??[]},sessionRisk:t=>$(`/report/session/${t}/risk`),sessionReplay:async(t,s)=>(await $(`/report/session/${t}${s?`?limit=${s}`:""}`)).records??[],alerts:async t=>{const s=new URLSearchParams;return t!=null&&t.severity&&s.set("severity",t.severity),(t==null?void 0:t.acknowledged)!==void 0&&s.set("acknowledged",String(t.acknowledged)),t!=null&&t.limit&&s.set("limit",String(t.limit)),(await $(`/report/alerts?${s}`)).alerts??[]},acknowledgeAlert:t=>$(`/report/alerts/${t}/acknowledge`,{method:"POST"}),resolve:(t,s,n)=>$("/ahp/resolve",{method:"POST",body:JSON.stringify({approval_id:t,decision:s,reason:n||""})})};function on(){const[t,s]=h.useState(null),[n,r]=h.useState(!1),a=h.useCallback(async()=>{r(!0);try{await R.summary(),s(!0)}catch(m){m instanceof dt?s(!1):s(!0)}finally{r(!1)}},[]),i=h.useCallback(async m=>{ot(m),await a()},[a]),o=h.useCallback(()=>{ct(),s(!1)},[]);return{authenticated:t,checking:n,check:a,login:i,logout:o,hasToken:!!Re()}}function cn(t){return t<60?`${Math.floor(t)}s`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h ${Math.floor(t%3600/60)}m`:`${Math.floor(t/86400)}d ${Math.floor(t%86400/3600)}h`}function K(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function xe(t){const s=Object.entries(t).sort(([n,r],[a,i])=>i.cost_usd-r.cost_usd||i.calls-r.calls||n.localeCompare(a))[0];return(s==null?void 0:s[0])??null}function dn(t){const s=[xe(t.by_provider),xe(t.by_tier),xe(t.by_status)].filter(Boolean).join("/");return[`LLM usage ${t.total_calls.toLocaleString()} calls`,K(t.total_cost_usd),s].filter(Boolean).join(" · ")}function un(){const[t,s]=h.useState(null),[n,r]=h.useState("checking"),a=t==null?void 0:t.budget_exhaustion_event,i=t!=null&&t.llm_usage_snapshot?dn(t.llm_usage_snapshot):null;return h.useEffect(()=>{const o=async()=>{try{const l=await R.health();s(l),r("online")}catch{r("offline"),s(null)}};o();const m=setInterval(o,3e4);return()=>clearInterval(m)},[]),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,fontSize:"0.75rem"},children:[t&&n==="online"&&e.jsxs("span",{className:"text-muted mono",style:{fontSize:"0.68rem"},children:[cn(t.uptime_seconds)," uptime · ",t.trajectory_count.toLocaleString()," events ·",i&&e.jsxs(e.Fragment,{children:[" ","· ",i]})," ","Daily budget ",K(t.budget.daily_budget_usd)," · Spend ",K(t.budget.daily_spend_usd)," · Remaining ",t.budget.remaining_usd===null?"Unlimited":K(t.budget.remaining_usd)," ·"," ",t.budget.exhausted?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--color-block)",fontWeight:700},children:"BUDGET EXHAUSTED"}),e.jsx("span",{style:{color:"var(--color-text-muted)"},children:" · Operator action required"}),a&&e.jsxs("span",{style:{color:"var(--color-text-muted)"},children:[" ","· ",a.provider," / ",a.tier," / ",K(a.cost_usd)]})]}):"Active"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{className:`status-dot ${n}`}),e.jsx("span",{className:"mono",style:{fontSize:"0.68rem",fontWeight:600,color:n==="online"?"var(--color-allow)":n==="offline"?"var(--color-block)":"var(--color-defer)"},children:n==="online"?"CONNECTED":n==="offline"?"DISCONNECTED":"CHECKING…"})]})]})}class hn extends h.Component{constructor(){super(...arguments);me(this,"state",{error:null})}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){console.error("[ClawSentry UI]",n,r.componentStack)}render(){return this.state.error?e.jsxs("div",{style:{padding:40},children:[e.jsx("h3",{style:{color:"var(--color-block)",marginBottom:12},children:"Page Error"}),e.jsx("pre",{style:{color:"var(--color-text-muted)",fontSize:"0.75rem",background:"var(--color-surface-raised)",padding:16,borderRadius:"var(--radius)",overflow:"auto",marginBottom:16},children:this.state.error.message}),e.jsx("button",{className:"btn",onClick:()=>this.setState({error:null}),children:"Dismiss"})]}):this.props.children}}const mn=[{to:"/",icon:bt,label:"Dashboard"},{to:"/sessions",icon:ye,label:"Sessions"},{to:"/alerts",icon:re,label:"Alerts"},{to:"/defer",icon:ae,label:"DEFER Panel"}],pn={"/":"Security Console","/sessions":"Session Inventory","/alerts":"Alerts","/defer":"DEFER Panel"};function fn(){var n;const t=U(),s=((n=Object.entries(pn).sort(([r],[a])=>a.length-r.length).find(([r])=>t.pathname.startsWith(r)))==null?void 0:n[1])??"ClawSentry";return e.jsxs("div",{className:"app-layout",children:[e.jsxs("aside",{className:"sidebar",children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsx("div",{className:"sidebar-logo",children:"CLAWSENTRY"}),e.jsx("div",{className:"subtitle",children:"Security Operations Console"})]}),e.jsx("nav",{className:"sidebar-nav",children:mn.map(({to:r,icon:a,label:i})=>e.jsxs(nn,{to:r,end:r==="/",className:({isActive:o})=>`nav-link${o?" active":""}`,children:[e.jsx(a,{}),i]},r))}),e.jsx("div",{className:"sidebar-footer",children:"Framework / Workspace / Session"})]}),e.jsxs("div",{className:"main-content",children:[e.jsxs("div",{className:"topbar",children:[e.jsx("span",{className:"topbar-title",children:s}),e.jsx(un,{})]}),e.jsx("div",{className:"page-content fade-in",children:e.jsx(hn,{children:e.jsx(qs,{})})})]})]})}function xn({onLogin:t}){const[s,n]=h.useState(""),r=a=>{a.preventDefault(),s.trim()&&t(s.trim())};return e.jsx("div",{className:"login-container",children:e.jsxs("div",{className:"login-card",children:[e.jsx("h2",{children:"CLAWSENTRY"}),e.jsx("div",{className:"subtitle",children:"Enter your AHP auth token to connect"}),e.jsxs("form",{onSubmit:r,children:[e.jsx("input",{type:"password",className:"login-input",placeholder:"CS_AUTH_TOKEN",value:s,onChange:a=>n(a.target.value),autoFocus:!0}),e.jsx("button",{type:"submit",className:"btn btn-primary",style:{width:"100%",marginTop:16,padding:"10px 14px"},children:"Connect"})]})]})})}function se({label:t,value:s,accent:n="purple",icon:r,subtext:a}){return e.jsx("div",{className:`card metric-card accent-${n}`,children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"metric-value",children:s}),e.jsx("div",{className:"metric-label",children:t}),a&&e.jsx("div",{className:"metric-subtext",children:a})]}),r&&e.jsx("div",{style:{color:"var(--color-text-muted)",opacity:.6},children:r})]})})}function Le(t,s){const n=new URLSearchParams,r=Re();r&&n.set("token",r),t!=null&&t.length&&n.set("types",t.join(","));const a=`/report/stream?${n}`;return new EventSource(a)}function ht(t,s,n){let r=null,a=0,i=null,o=!1;const m=10;function l(){if(!o){s.onStatusChange("connecting"),r=Le(t),r.onopen=()=>{a=0,s.onStatusChange("connected")},r.onerror=()=>{if(o)return;if(r==null||r.close(),r=null,a>=m){s.onStatusChange("error",`Failed after ${m} retries`);return}const c=Math.min(1e3*2**a,3e4);a++,s.onStatusChange("disconnected",`Reconnecting in ${Math.round(c/1e3)}s...`),i=setTimeout(l,c)};for(const c of t)r.addEventListener(c,d=>{try{s.onEvent(c,JSON.parse(d.data))}catch{}})}}return l(),()=>{o=!0,i&&clearTimeout(i),r==null||r.close(),r=null}}function mt({decision:t}){const s=`badge badge-${t}`;return e.jsx("span",{className:s,children:t})}function C({level:t}){const s=`badge badge-risk-${t}`;return e.jsx("span",{className:s,children:t})}function ee({icon:t,title:s,subtitle:n}){return e.jsxs("div",{className:"empty-state",children:[e.jsx("div",{className:"empty-state-icon",children:t}),e.jsx("div",{className:"empty-state-title",children:s}),n&&e.jsx("div",{className:"empty-state-subtitle",children:n})]})}const qe=["decision","alert","trajectory_alert","post_action_finding","pattern_candidate","pattern_evolved","defer_pending","defer_resolved","budget_exhausted","session_enforcement_change"],gn=["alert","trajectory_alert","post_action_finding","defer_pending","defer_resolved","budget_exhausted","session_enforcement_change"],oe=80,pt={decision:"Decision",alert:"Alert",trajectory_alert:"Trajectory",post_action_finding:"Finding",pattern_candidate:"Pattern Candidate",pattern_evolved:"Pattern Evolved",defer_pending:"Defer Pending",defer_resolved:"Defer Resolved",budget_exhausted:"Budget Exhausted",session_enforcement_change:"Enforcement"},vn={decision:{color:"var(--color-accent-secondary)",bg:"rgba(96,165,250,0.12)",border:"rgba(96,165,250,0.2)"},alert:{color:"var(--color-block)",bg:"rgba(239,68,68,0.12)",border:"rgba(239,68,68,0.2)"},trajectory_alert:{color:"var(--color-risk-high)",bg:"rgba(249,115,22,0.12)",border:"rgba(249,115,22,0.2)"},post_action_finding:{color:"var(--color-defer)",bg:"rgba(245,158,11,0.12)",border:"rgba(245,158,11,0.2)"},pattern_candidate:{color:"var(--color-accent)",bg:"rgba(167,139,250,0.12)",border:"rgba(167,139,250,0.2)"},pattern_evolved:{color:"#34d399",bg:"rgba(52,211,153,0.12)",border:"rgba(52,211,153,0.2)"},defer_pending:{color:"var(--color-defer)",bg:"rgba(245,158,11,0.12)",border:"rgba(245,158,11,0.2)"},defer_resolved:{color:"#34d399",bg:"rgba(52,211,153,0.12)",border:"rgba(52,211,153,0.2)"},budget_exhausted:{color:"var(--color-block)",bg:"rgba(239,68,68,0.12)",border:"rgba(239,68,68,0.2)"},session_enforcement_change:{color:"var(--color-block)",bg:"rgba(239,68,68,0.12)",border:"rgba(239,68,68,0.2)"}};function Ve(t,s){const n=[s,...t],r=Math.max(0,n.length-oe);return{items:n.slice(0,oe),dropped:r}}function jn(t,s){const n=[...s,...t],r=Math.max(0,n.length-oe);return{items:n.slice(0,oe),dropped:r}}function yn(t,s,n){const r=s==="all"||t.type===s,a=!n||gn.includes(t.type);return r&&a}function _n({tier:t}){const s=t.toUpperCase(),n=s==="L3"?"badge-tier-l3":s==="L2"?"badge-tier-l2":"badge-tier-l1";return e.jsx("span",{className:`badge ${n}`,children:s})}function bn({type:t}){const s=vn[t];return e.jsx("span",{className:"badge",style:{color:s.color,background:s.bg,borderColor:s.border},children:pt[t]})}function Nn({status:t,detail:s}){if(t==="connected")return null;const n=t==="connecting"||t==="disconnected"?"var(--color-defer)":"var(--color-block)",r=t==="error"?e.jsx(Nt,{size:10}):e.jsx(wt,{size:10}),a=t==="connecting"?"Connecting...":t==="disconnected"?s||"Reconnecting...":s||"Connection failed";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"4px 10px",fontSize:"0.65rem",color:n,borderBottom:"1px solid var(--color-border)"},children:[r,e.jsx("span",{className:"mono",children:a})]})}function z({sessionId:t}){return t?e.jsx(O,{to:`/sessions/${t}`,className:"mono",style:{color:"var(--color-accent)",textDecoration:"none",fontSize:"0.68rem"},children:t.length>12?`${t.slice(0,12)}...`:t}):null}function ge({patternId:t}){return e.jsx("span",{className:"mono",style:{fontSize:"0.72rem",color:"var(--color-text-secondary)"},children:t})}function wn(t){var n;if(!t)return null;const s=[];return(n=t.retained_sources)!=null&&n.length&&s.push(t.retained_sources.filter(Boolean).join(", ")),typeof t.tool_calls_count=="number"&&s.push(`${t.tool_calls_count} tool call(s)`),s.length>0?s.join(" · "):null}function kn({event:t}){switch(t.type){case"decision":{const s=wn(t.evidence_summary);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"mono",style:{fontSize:"0.8rem",fontWeight:500},children:t.tool_name}),e.jsx(mt,{decision:t.decision}),e.jsx(C,{level:t.risk_level}),e.jsx(_n,{tier:t.actual_tier}),e.jsx(z,{sessionId:t.session_id})]}),t.command&&e.jsx("div",{className:"cmd-snippet",style:{marginTop:6},children:t.command}),t.reason&&e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.reason}),t.trigger_detail&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["Trigger pattern: ",e.jsx("span",{className:"mono",children:t.trigger_detail})]}),t.l3_requested!==void 0&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["L3 requested: ",e.jsx("span",{className:"mono",children:t.l3_requested?"yes":"no"})]}),t.l3_available!==void 0&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["L3 available: ",e.jsx("span",{className:"mono",children:t.l3_available?"yes":"no"})]}),t.l3_reason_code&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["L3 reason code: ",e.jsx("span",{className:"mono",children:t.l3_reason_code})]}),t.l3_state&&t.l3_state!=="completed"&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["L3 state: ",e.jsx("span",{className:"mono",children:t.l3_state})]}),t.l3_reason&&t.l3_state&&t.l3_state!=="completed"&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["L3 reason: ",e.jsx("span",{className:"mono",children:t.l3_reason})]}),s&&e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:["Evidence: ",e.jsx("span",{className:"mono",children:s})]})]})}case"alert":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"mono",style:{fontSize:"0.78rem",fontWeight:600},children:t.metric}),e.jsx("span",{className:"badge badge-block",children:t.severity}),e.jsx(z,{sessionId:t.session_id})]}),e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.message})]});case"trajectory_alert":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx(ge,{patternId:t.sequence_id}),e.jsx(C,{level:t.risk_level}),e.jsx("span",{className:"badge badge-defer",children:t.handling}),e.jsx(z,{sessionId:t.session_id})]}),e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.reason})]});case"post_action_finding":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"badge badge-defer",children:t.tier}),e.jsx("span",{className:"badge badge-modify",children:t.handling}),e.jsxs("span",{className:"mono",style:{fontSize:"0.72rem"},children:["score ",t.score.toFixed(2)]}),e.jsx(z,{sessionId:t.session_id})]}),e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.patterns_matched.length>0?`Matched: ${t.patterns_matched.join(", ")}`:`Framework: ${t.source_framework}`})]});case"pattern_candidate":return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx(ge,{patternId:t.pattern_id}),e.jsx("span",{className:"badge badge-modify",children:t.status}),e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.68rem"},children:t.source_framework}),e.jsx(z,{sessionId:t.session_id})]});case"pattern_evolved":return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx(ge,{patternId:t.pattern_id}),e.jsx("span",{className:"badge badge-allow",children:t.result})]});case"defer_pending":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"mono",style:{fontSize:"0.78rem",fontWeight:500},children:t.tool_name}),e.jsx("span",{className:"badge badge-defer",children:"pending"}),e.jsxs("span",{className:"mono text-muted",style:{fontSize:"0.68rem"},children:[t.timeout_s,"s"]}),e.jsx(z,{sessionId:t.session_id})]}),t.command&&e.jsx("div",{className:"cmd-snippet",style:{marginTop:6},children:t.command}),t.reason&&e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.reason})]});case"defer_resolved":return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:`badge ${t.resolved_decision==="allow"?"badge-allow":"badge-block"}`,children:t.resolved_decision}),e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.68rem"},children:t.approval_id}),e.jsx(z,{sessionId:t.session_id}),t.resolved_reason&&e.jsx("span",{className:"text-secondary",style:{fontSize:"0.73rem"},children:t.resolved_reason})]});case"budget_exhausted":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"badge badge-block",children:"Budget exhausted"}),e.jsx("span",{className:"mono",style:{fontSize:"0.78rem",fontWeight:500},children:"Provider"}),e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.72rem"},children:t.provider}),e.jsx("span",{className:"mono",style:{fontSize:"0.78rem",fontWeight:500},children:"Tier"}),e.jsx("span",{className:"badge badge-defer",children:t.tier}),e.jsx("span",{className:"mono",style:{fontSize:"0.78rem",fontWeight:500},children:"Cost"}),e.jsxs("span",{className:"mono text-muted",style:{fontSize:"0.72rem"},children:["$",t.cost_usd.toFixed(2)]})]}),e.jsxs("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:["Budget exhausted: ",e.jsx("span",{className:"mono",children:t.budget.exhausted?"yes":"no"})," · ","Daily spend ",e.jsxs("span",{className:"mono",children:["$",t.budget.daily_spend_usd.toFixed(2)]})," / ",e.jsxs("span",{className:"mono",children:["$",t.budget.daily_budget_usd.toFixed(2)]}),t.budget.remaining_usd!==null&&e.jsxs(e.Fragment,{children:[" · ","Remaining ",e.jsxs("span",{className:"mono",children:["$",t.budget.remaining_usd.toFixed(2)]})]})]})]});case"session_enforcement_change":return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:`badge ${t.state==="released"?"badge-allow":"badge-block"}`,children:t.state}),t.action&&e.jsx("span",{className:"badge badge-defer",children:t.action}),e.jsx(z,{sessionId:t.session_id})]}),(t.reason||t.high_risk_count!==void 0)&&e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:6},children:t.reason||`${t.high_risk_count} high-risk event(s)`})]})}}function Sn(){const[t,s]=h.useState([]),[n,r]=h.useState([]),[a,i]=h.useState(0),[o,m]=h.useState(0),[l,c]=h.useState(!1),[d,u]=h.useState("all"),[f,j]=h.useState(!1),[y,_]=h.useState("connecting"),[v,g]=h.useState(),p=h.useRef(!1);h.useEffect(()=>{p.current=l},[l]),h.useEffect(()=>ht(qe,{onEvent:(S,P)=>{const W={...P,type:S};if(p.current){i(F=>F+1),r(F=>{const E=Ve(F,W);return E.dropped>0&&m(H=>H+E.dropped),E.items});return}s(F=>{const E=Ve(F,W);return E.dropped>0&&m(H=>H+E.dropped),E.items})},onStatusChange:(S,P)=>{_(S),g(P)}}),[]);function x(){if(!l){c(!0);return}n.length>0&&s(N=>{const S=jn(N,n);return S.dropped>0&&m(P=>P+S.dropped),S.items}),r([]),i(0),c(!1)}const b=t.filter(N=>yn(N,d,f));return e.jsxs("div",{className:"card",style:{height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{className:"card-header",children:[e.jsx(ne,{size:12}),"Live Activity Feed",y==="connected"&&e.jsx("span",{style:{marginLeft:4,color:"#22c55e",fontSize:"0.5rem"},children:"●"}),t.length>0&&e.jsxs("span",{className:"mono",style:{marginLeft:"auto",color:"var(--color-text-muted)",fontSize:"0.65rem"},children:[b.length,"/",t.length," events"]})]}),e.jsx(Nn,{status:y,detail:v}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:8,padding:"10px 14px",borderBottom:"1px solid var(--color-border)",alignItems:"center"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.68rem"},children:"Type"}),e.jsxs("select",{value:d,onChange:N=>u(N.target.value),className:"input",style:{width:"auto",minWidth:140,padding:"6px 10px",fontSize:"0.72rem"},children:[e.jsx("option",{value:"all",children:"All events"}),qe.map(N=>e.jsx("option",{value:N,children:pt[N]},N))]})]}),e.jsx("button",{type:"button",className:`badge ${f?"badge-block":""}`,style:{cursor:"pointer",background:f?"rgba(239,68,68,0.12)":"transparent"},onClick:()=>j(N=>!N),children:"High priority only"}),e.jsx("button",{type:"button",className:`badge ${l?"badge-defer":""}`,style:{cursor:"pointer",background:l?"rgba(245,158,11,0.12)":"transparent"},onClick:x,children:l?"Resume feed":"Pause feed"})]}),(a>0||o>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:10,padding:"8px 14px",borderBottom:"1px solid var(--color-border)",fontSize:"0.7rem",color:"var(--color-text-secondary)"},children:[a>0&&e.jsxs("span",{className:"mono",children:["Feed paused · ",a," buffered while paused"]}),o>0&&e.jsxs("span",{className:"mono",children:[o," older events hidden by feed cap"]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",maxHeight:420},children:t.length===0?e.jsx(ee,{icon:e.jsx(ne,{size:20}),title:"Waiting for activity",subtitle:y==="connected"?"Decisions, alerts, enforcement, defer actions, and pattern evolution events will appear here":"Establishing connection to gateway..."}):b.length===0?e.jsx(ee,{icon:e.jsx(ne,{size:20}),title:"No events match current filters",subtitle:"Adjust the event type filter or disable high priority only to widen the feed."}):b.map((N,S)=>e.jsxs("div",{className:"slide-in",style:{padding:"10px 14px",borderBottom:"1px solid var(--color-border)",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.65rem",minWidth:60},children:new Date(N.timestamp).toLocaleTimeString()}),e.jsx(bn,{type:N.type})]}),e.jsx(kn,{event:N})]},`${N.type}-${N.timestamp}-${S}`))})]})}function X({rows:t=3,height:s}){return e.jsxs("div",{className:"card",style:s?{height:s}:void 0,children:[e.jsx("div",{className:"skeleton skeleton-text-sm",style:{width:"40%",marginBottom:12}}),Array.from({length:t}).map((n,r)=>e.jsx("div",{className:"skeleton skeleton-text",style:{width:`${70+r%3*10}%`,marginBottom:8}},r))]})}function ke(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function Cn(t,s){return`${t.toLocaleString()} in / ${s.toLocaleString()} out`}function En(t){return Object.entries(t).sort(([s,n],[r,a])=>a.cost_usd-n.cost_usd||a.calls-n.calls||s.localeCompare(r)).slice(0,3)}function Rn(t){return t?t.total_calls>0||t.total_input_tokens>0||t.total_output_tokens>0||t.total_cost_usd>0||Object.keys(t.by_provider).length>0||Object.keys(t.by_tier).length>0||Object.keys(t.by_status).length>0:!1}function ve(t,s){const n=En(s);return e.jsxs("article",{className:"framework-panel",children:[e.jsx("div",{className:"framework-panel-top",children:e.jsxs("div",{children:[e.jsx("h3",{children:t}),e.jsx("p",{children:n.length?`${n.length} highlighted`:"No entries"})]})}),e.jsx("div",{className:"framework-workspace-list",children:n.map(([r,a],i)=>e.jsxs("div",{className:"framework-workspace-row",style:{alignItems:"flex-start"},children:[e.jsxs("div",{style:{display:"grid",gap:4},children:[e.jsx("strong",{children:r}),e.jsxs("span",{children:[a.calls.toLocaleString()," calls · ",Cn(a.input_tokens,a.output_tokens)," ·"," ",ke(a.cost_usd)]})]}),e.jsxs("span",{className:"mono",style:{color:"var(--color-text-muted)",fontSize:"0.72rem"},children:["#",i+1]})]},r))})]})}function Ln({snapshot:t}){if(!Rn(t))return e.jsxs("section",{className:"card section-card",style:{marginBottom:18},children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"LLM telemetry"}),e.jsx("h2",{children:"LLM usage drill-down"})]}),e.jsx("span",{className:"section-meta",children:"Snapshot unavailable"})]}),e.jsx("div",{className:"empty-inline",children:"No LLM usage snapshot available."})]});const s=t.total_input_tokens+t.total_output_tokens;return e.jsxs("section",{className:"card section-card",style:{marginBottom:18},children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"LLM telemetry"}),e.jsx("h2",{children:"LLM usage drill-down"})]}),e.jsxs("span",{className:"section-meta",children:[t.total_calls.toLocaleString()," calls · ",ke(t.total_cost_usd)]})]}),e.jsxs("div",{className:"framework-panel-metrics",style:{marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("span",{children:"Total calls"}),e.jsx("strong",{children:t.total_calls.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Total tokens"}),e.jsx("strong",{children:s.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Total cost"}),e.jsx("strong",{children:ke(t.total_cost_usd)})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:14},children:[ve("Top providers",t.by_provider),ve("Top tiers",t.by_tier),ve("Top statuses",t.by_status)]})]})}const Tn=["critical","high","medium","low"];function k(t){const s=String(t||"low").toLowerCase();return Tn.indexOf(s)}function Pn(t){return t||"unknown"}function Te(t){if(!t)return"Unknown Workspace";const n=t.replace(/\/+$/,"").split("/").filter(Boolean);return n[n.length-1]||t}function B(t){if(!t)return"No activity";const s=Date.now()-new Date(t).getTime();if(!Number.isFinite(s)||s<0)return"Just now";const n=Math.floor(s/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function ce(t){if(!t)return"idle";const s=(Date.now()-new Date(t).getTime())/6e4;return s<=2?"hot":s<=15?"warm":"idle"}function ft(t){const s=new Map;for(const r of t){const a=Pn(r.source_framework),i=r.workspace_root||"";s.has(a)||s.set(a,new Map);const o=s.get(a),m=i||`unknown:${r.session_id}`,l=o.get(m)||[];l.push(r),o.set(m,l)}return Array.from(s.entries()).map(([r,a])=>{var c;const i=Array.from(a.entries()).map(([d,u])=>{var v,g,p;const f=[...u].sort((x,b)=>{const N=k(x.current_risk_level)-k(b.current_risk_level);return N!==0?N:new Date(b.last_event_at).getTime()-new Date(x.last_event_at).getTime()}),j=((v=f[0])==null?void 0:v.current_risk_level)||"low",y=f.map(x=>x.last_event_at).sort((x,b)=>new Date(b).getTime()-new Date(x).getTime())[0]||"",_=Array.from(new Set(f.map(x=>x.caller_adapter).filter(Boolean)));return{key:d,workspaceRoot:((g=f[0])==null?void 0:g.workspace_root)||"",workspaceLabel:Te(((p=f[0])==null?void 0:p.workspace_root)||""),framework:r,callerAdapters:_,sessionCount:f.length,highRiskSessionCount:f.filter(x=>k(x.current_risk_level)<=1).length,criticalSessionCount:f.filter(x=>x.current_risk_level==="critical").length,totalEvents:f.reduce((x,b)=>x+b.event_count,0),latestActivityAt:y,highestRisk:j,sessions:f}}).sort((d,u)=>{const f=k(d.highestRisk)-k(u.highestRisk);return f!==0?f:new Date(u.latestActivityAt).getTime()-new Date(d.latestActivityAt).getTime()}),o=i.flatMap(d=>d.sessions),m=o.map(d=>d.last_event_at).sort((d,u)=>new Date(u).getTime()-new Date(d).getTime())[0]||"",l=((c=i[0])==null?void 0:c.highestRisk)||"low";return{framework:r,sessionCount:o.length,workspaceCount:i.length,highRiskSessionCount:o.filter(d=>k(d.current_risk_level)<=1).length,totalEvents:o.reduce((d,u)=>d+u.event_count,0),latestActivityAt:m,highestRisk:l,workspaces:i}}).sort((r,a)=>{const i=k(r.highestRisk)-k(a.highestRisk);return i!==0?i:new Date(a.latestActivityAt).getTime()-new Date(r.latestActivityAt).getTime()})}function He(t){return t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`}function G(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function je(t){const s=Object.entries(t).sort(([n,r],[a,i])=>i.cost_usd-r.cost_usd||i.calls-r.calls||n.localeCompare(a))[0];return(s==null?void 0:s[0])??null}function $n(t){const s=[je(t.by_provider),je(t.by_tier),je(t.by_status)].filter(Boolean).join("/");return[`LLM usage ${t.total_calls.toLocaleString()} calls`,G(t.total_cost_usd),s].filter(Boolean).join(" · ")}function zn({framework:t,count:s}){return e.jsxs("span",{className:"framework-chip",children:[e.jsx("span",{children:t}),e.jsx("strong",{children:s})]})}function In(){var g;const[t,s]=h.useState(null),[n,r]=h.useState(null),[a,i]=h.useState([]),[o,m]=h.useState(!0),l=n==null?void 0:n.budget_exhaustion_event,c=(t==null?void 0:t.llm_usage_snapshot)??(n==null?void 0:n.llm_usage_snapshot)??null;h.useEffect(()=>{const p=()=>Promise.all([R.summary().then(s),R.health().then(r),R.sessions({sort:"risk_level",limit:120}).then(i)]).catch(()=>{}).finally(()=>m(!1));p();const x=setInterval(p,1e4);return()=>clearInterval(x)},[]);const d=ft(a),u=d.reduce((p,x)=>p+x.workspaceCount,0),f=a.filter(p=>p.current_risk_level==="critical").length,j=a.filter(p=>k(p.current_risk_level)<=1).length,y=t?((t.by_decision.block||0)/Math.max(t.total_records,1)*100).toFixed(1):"—",_=[...a].sort((p,x)=>{const b=k(p.current_risk_level)-k(x.current_risk_level);return b!==0?b:new Date(x.last_event_at).getTime()-new Date(p.last_event_at).getTime()}).slice(0,6),v=d.flatMap(p=>p.workspaces.map(x=>({...x,framework:p.framework}))).sort((p,x)=>{const b=k(p.highestRisk)-k(x.highestRisk);return b!==0?b:new Date(x.latestActivityAt).getTime()-new Date(p.latestActivityAt).getTime()}).slice(0,6);return o?e.jsxs("div",{children:[e.jsx("div",{className:"metric-grid",style:{marginBottom:20},children:[0,1,2,3].map(p=>e.jsx(X,{rows:2,height:104},p))}),e.jsxs("div",{className:"dashboard-grid dashboard-grid-primary",children:[e.jsx(X,{rows:8,height:430}),e.jsx(X,{rows:8,height:430})]})]}):e.jsxs("div",{className:"dashboard-shell",children:[e.jsxs("section",{className:"hero-banner",children:[e.jsxs("div",{children:[e.jsx("p",{className:"eyebrow",children:"Security Console"}),e.jsx("h1",{children:"Cross-framework session coverage for live agent operations."}),e.jsx("p",{className:"hero-copy",children:"Track every framework, every workspace, and every session from one monitoring surface. High-risk workspaces rise to the top automatically, while live runtime events stay visible."}),e.jsx("div",{className:"hero-chip-row",children:Object.entries((t==null?void 0:t.by_source_framework)||{}).map(([p,x])=>e.jsx(zn,{framework:p,count:x},p))})]}),e.jsxs("div",{className:"hero-panel",children:[e.jsxs("div",{className:"hero-panel-header",children:[e.jsx(kt,{size:14}),"Current posture"]}),e.jsxs("div",{className:"hero-panel-body",children:[e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"Critical sessions"}),e.jsx("strong",{children:f})]}),e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"High-risk workspaces"}),e.jsx("strong",{children:v.filter(p=>k(p.highestRisk)<=1).length})]}),e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"Gateway uptime"}),e.jsx("strong",{children:n?He(n.uptime_seconds):"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"LLM usage"}),e.jsx("strong",{children:c?`${c.total_calls.toLocaleString()} calls`:"—"}),e.jsx("div",{className:"mono",style:{fontSize:"0.72rem",color:"var(--color-text-muted)"},children:c?$n(c):"Usage snapshot unavailable"})]}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx("span",{className:"hero-panel-label",children:"Daily budget"}),e.jsx("strong",{children:n?G(n.budget.daily_budget_usd):"—"}),e.jsx("div",{className:"mono",style:{fontSize:"0.72rem",color:"var(--color-text-muted)"},children:n?e.jsxs(e.Fragment,{children:["Spend ",G(n.budget.daily_spend_usd)," · Remaining"," ",n.budget.remaining_usd===null?"Unlimited":G(n.budget.remaining_usd)," ·"," ","Exhausted ",n.budget.exhausted?"Yes":"No"]}):"Budget snapshot unavailable"}),n&&(n.budget.exhausted||l)&&e.jsx("div",{className:"mono",style:{marginTop:8,padding:"8px 10px",borderRadius:10,border:"1px solid rgba(239,68,68,0.3)",background:"rgba(239,68,68,0.08)",color:"var(--color-text)",fontSize:"0.72rem",lineHeight:1.45},children:l?e.jsxs(e.Fragment,{children:[e.jsx("strong",{style:{color:"var(--color-block)"},children:"Budget exhaustion event"}),e.jsx("span",{children:" · Operator attention required"}),e.jsxs("div",{style:{color:"var(--color-text-muted)"},children:[l.provider," · ",l.tier," · ",G(l.cost_usd)]})]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{style:{color:"var(--color-block)"},children:"Budget exhaustion event"}),e.jsx("span",{children:" · Operator attention required"})]})})]})]})]})]}),e.jsxs("div",{className:"metric-grid",style:{marginBottom:20},children:[e.jsx(se,{label:"Tracked Sessions",value:a.length.toLocaleString(),accent:"purple",icon:e.jsx(St,{size:20}),subtext:`${u} workspaces across ${d.length} frameworks`}),e.jsx(se,{label:"High-Risk Sessions",value:j.toLocaleString(),accent:"red",icon:e.jsx(re,{size:20}),subtext:`${f} critical right now`}),e.jsx(se,{label:"Block Rate",value:`${y}%`,accent:"amber",icon:e.jsx(ae,{size:20}),subtext:`${((g=t==null?void 0:t.by_decision)==null?void 0:g.block)??0} blocks in current window`}),e.jsx(se,{label:"Live Events",value:((n==null?void 0:n.trajectory_count)??0).toLocaleString(),accent:"blue",icon:e.jsx(ne,{size:20}),subtext:n?`${He(n.uptime_seconds)} uptime`:void 0})]}),e.jsx(Ln,{snapshot:c}),e.jsxs("div",{className:"dashboard-grid dashboard-grid-primary",children:[e.jsxs("section",{className:"card section-card",children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Coverage"}),e.jsx("h2",{children:"Framework Coverage"})]}),e.jsx(O,{to:"/sessions",className:"section-link",children:"Open session inventory"})]}),e.jsxs("div",{className:"framework-coverage-grid",children:[d.map(p=>e.jsxs("article",{className:"framework-panel",children:[e.jsxs("div",{className:"framework-panel-top",children:[e.jsxs("div",{children:[e.jsx("h3",{children:p.framework}),e.jsxs("p",{children:[p.workspaceCount," workspaces"]})]}),e.jsx(C,{level:p.highestRisk})]}),e.jsxs("div",{className:"framework-panel-metrics",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Sessions"}),e.jsx("strong",{children:p.sessionCount})]}),e.jsxs("div",{children:[e.jsx("span",{children:"High risk"}),e.jsx("strong",{children:p.highRiskSessionCount})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Events"}),e.jsx("strong",{children:p.totalEvents})]})]}),e.jsx("div",{className:"framework-workspace-list",children:p.workspaces.slice(0,3).map(x=>e.jsxs("div",{className:"framework-workspace-row",children:[e.jsxs("div",{children:[e.jsx("strong",{children:x.workspaceLabel}),e.jsx("span",{children:B(x.latestActivityAt)})]}),e.jsx(C,{level:x.highestRisk})]},x.key))})]},p.framework)),d.length===0&&e.jsx("div",{className:"empty-inline",children:"No framework activity yet."})]})]}),e.jsx(Sn,{})]}),e.jsxs("div",{className:"dashboard-grid dashboard-grid-secondary",children:[e.jsxs("section",{className:"card section-card",children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Workspaces"}),e.jsx("h2",{children:"Workspace Risk Board"})]}),e.jsxs("span",{className:"section-meta",children:[v.length," prioritized"]})]}),e.jsxs("div",{className:"workspace-board",children:[v.map(p=>e.jsxs("article",{className:"workspace-card",children:[e.jsxs("div",{className:"workspace-card-top",children:[e.jsxs("div",{children:[e.jsx("p",{className:"workspace-framework",children:p.framework}),e.jsx("h3",{children:p.workspaceLabel})]}),e.jsx(C,{level:p.highestRisk})]}),e.jsx("p",{className:"workspace-root mono",children:p.workspaceRoot||"workspace_root unavailable"}),e.jsxs("div",{className:"workspace-stats",children:[e.jsxs("span",{children:[p.sessionCount," sessions"]}),e.jsxs("span",{children:[p.highRiskSessionCount," high risk"]}),e.jsxs("span",{children:[p.totalEvents," events"]})]}),e.jsxs("div",{className:"workspace-footer",children:[e.jsx("span",{className:`activity-pill activity-pill-${ce(p.latestActivityAt)}`,children:B(p.latestActivityAt)}),e.jsx("span",{className:"mono",children:p.callerAdapters.join(", ")||"adapter n/a"})]})]},p.key)),v.length===0&&e.jsx("div",{className:"empty-inline",children:"No workspace telemetry yet."})]})]}),e.jsxs("section",{className:"card section-card",children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Escalation queue"}),e.jsx("h2",{children:"Priority Sessions"})]}),e.jsx(O,{to:"/sessions",className:"section-link",children:"Review all sessions"})]}),e.jsxs("div",{className:"priority-session-list",children:[_.map(p=>e.jsxs(O,{to:`/sessions/${p.session_id}`,className:"priority-session-row",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"priority-session-top",children:[e.jsx("strong",{children:Te(p.workspace_root)}),e.jsx(C,{level:p.current_risk_level})]}),e.jsxs("p",{className:"priority-session-meta",children:[p.source_framework," · ",p.event_count," events · ",p.high_risk_event_count," high-risk"]}),e.jsx("p",{className:"priority-session-id mono",children:p.session_id})]}),e.jsx("div",{className:"priority-session-side",children:e.jsx("span",{className:`activity-pill activity-pill-${ce(p.last_event_at)}`,children:B(p.last_event_at)})})]},p.session_id)),_.length===0&&e.jsx("div",{className:"empty-inline",children:"No active sessions to prioritize."})]})]})]})]})}const An={allow:"#32c48d",block:"#ef4444",defer:"#f59e0b",modify:"#5ea5ff"};function Dn({dist:t}){const s=Object.values(t).reduce((n,r)=>n+r,0);return s===0?e.jsx("span",{className:"text-muted mono",children:"—"}):e.jsx("div",{className:"verdict-bar verdict-bar-wide",children:Object.entries(t).map(([n,r])=>r>0?e.jsx("div",{className:"verdict-bar-segment",style:{width:`${r/s*100}%`,background:An[n]||"#475569"},title:`${n}: ${r}`},n):null)})}function On({score:t}){const s=t>=.75?"#ef4444":t>=.5?"#f97316":t>=.25?"#f59e0b":"#32c48d";return e.jsxs("div",{className:"score-bar-wrap",children:[e.jsx("div",{className:"score-bar score-bar-wide",children:e.jsx("div",{className:"score-bar-fill",style:{width:`${t*100}%`,background:s}})}),e.jsx("span",{className:"mono",style:{color:s},children:t.toFixed(2)})]})}function Bn(){const[t,s]=h.useState([]),[n,r]=h.useState(!0),[a,i]=h.useState(""),[o,m]=h.useState(""),[l,c]=h.useState(""),[d,u]=h.useState(0),f=h.useDeferredValue(l.trim().toLowerCase()),j=h.useRef(null);h.useEffect(()=>{const g=async()=>{r(!0);try{const b=await R.sessions({sort:"risk_level",limit:200,min_risk:a||void 0});s(b)}catch{}r(!1)};g();const p=ht(["decision","session_start","session_risk_change","session_enforcement_change"],{onEvent:()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{g()},500)},onStatusChange:()=>{}}),x=setInterval(g,3e4);return()=>{p(),clearInterval(x),j.current&&clearTimeout(j.current)}},[a,d]);const y=Array.from(new Set(t.map(g=>g.source_framework))).sort(),_=t.filter(g=>o&&g.source_framework!==o?!1:f?[g.session_id,g.agent_id,g.source_framework,g.workspace_root,g.caller_adapter].join(" ").toLowerCase().includes(f):!0),v=ft(_);return e.jsxs("div",{className:"sessions-shell",children:[e.jsxs("section",{className:"card sessions-toolbar",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Inventory"}),e.jsxs("h2",{className:"section-header",style:{marginBottom:0},children:[e.jsx(ye,{size:18,style:{color:"var(--color-accent)"}}),"Framework Overview"]}),e.jsx("p",{className:"toolbar-subtitle",children:"Grouped by framework and workspace so concurrent agent sessions stay distinguishable."})]}),e.jsxs("div",{className:"toolbar-controls",children:[e.jsxs("label",{className:"search-box",children:[e.jsx(Ct,{size:14}),e.jsx("input",{value:l,onChange:g=>c(g.target.value),placeholder:"Search session, framework, workspace, agent"})]}),e.jsxs("select",{value:o,onChange:g=>m(g.target.value),children:[e.jsx("option",{value:"",children:"All Frameworks"}),y.map(g=>e.jsx("option",{value:g,children:g},g))]}),e.jsxs("select",{value:a,onChange:g=>i(g.target.value),children:[e.jsx("option",{value:"",children:"All Risk Levels"}),e.jsx("option",{value:"medium",children:"Medium+"}),e.jsx("option",{value:"high",children:"High+"}),e.jsx("option",{value:"critical",children:"Critical Only"})]}),e.jsxs("button",{className:"btn",onClick:()=>u(g=>g+1),disabled:n,children:[e.jsx(Ge,{size:13,style:n?{animation:"spin 1s linear infinite"}:void 0}),"Refresh"]})]})]}),e.jsx("div",{className:"framework-overview-grid",children:v.map(g=>e.jsxs("article",{className:"framework-overview-card",children:[e.jsxs("div",{className:"framework-panel-top",children:[e.jsxs("div",{children:[e.jsx("h3",{children:g.framework}),e.jsxs("p",{children:[g.workspaceCount," workspaces"]})]}),e.jsx(C,{level:g.highestRisk})]}),e.jsxs("div",{className:"framework-panel-metrics",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Sessions"}),e.jsx("strong",{children:g.sessionCount})]}),e.jsxs("div",{children:[e.jsx("span",{children:"High risk"}),e.jsx("strong",{children:g.highRiskSessionCount})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Events"}),e.jsx("strong",{children:g.totalEvents})]})]})]},g.framework))}),e.jsxs("div",{className:"framework-stack",children:[v.map(g=>e.jsxs("section",{className:"card framework-section",children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Framework"}),e.jsx("h2",{children:g.framework})]}),e.jsxs("div",{className:"framework-section-meta",children:[e.jsxs("span",{children:[g.sessionCount," sessions"]}),e.jsxs("span",{children:[g.workspaceCount," workspaces"]}),e.jsx("span",{children:B(g.latestActivityAt)})]})]}),e.jsx("div",{className:"workspace-grid",children:g.workspaces.map(p=>e.jsxs("article",{className:"workspace-section",children:[e.jsxs("div",{className:"workspace-section-top",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"workspace-section-title",children:[e.jsx("h3",{children:p.workspaceLabel}),e.jsx(C,{level:p.highestRisk})]}),e.jsx("p",{className:"workspace-root mono",children:p.workspaceRoot||"workspace_root unavailable"})]}),e.jsxs("div",{className:"workspace-section-meta",children:[e.jsx("span",{className:`activity-pill activity-pill-${ce(p.latestActivityAt)}`,children:B(p.latestActivityAt)}),e.jsxs("span",{children:[p.sessionCount," sessions"]})]})]}),e.jsxs("div",{className:"workspace-summary-row",children:[e.jsxs("span",{children:[p.highRiskSessionCount," high-risk"]}),e.jsxs("span",{children:[p.totalEvents," events"]}),e.jsx("span",{children:p.callerAdapters.join(", ")||"adapter n/a"})]}),e.jsx("div",{className:"session-card-stack",children:p.sessions.map(x=>e.jsxs(O,{to:`/sessions/${x.session_id}`,className:"session-card-row",children:[e.jsxs("div",{className:"session-card-main",children:[e.jsxs("div",{className:"session-card-head",children:[e.jsx("span",{className:"mono session-card-id",children:x.session_id}),e.jsx(C,{level:x.current_risk_level})]}),e.jsxs("p",{className:"session-card-meta",children:[x.agent_id||"unknown agent"," · ",x.caller_adapter]}),e.jsx(Dn,{dist:x.decision_distribution})]}),e.jsxs("div",{className:"session-card-side",children:[e.jsx(On,{score:x.cumulative_score}),e.jsxs("div",{className:"session-card-statline",children:[e.jsxs("span",{children:[x.event_count," events"]}),e.jsxs("span",{children:[x.high_risk_event_count," high-risk"]})]}),e.jsx("span",{className:`activity-pill activity-pill-${ce(x.last_event_at)}`,children:B(x.last_event_at)})]})]},x.session_id))})]},p.key))})]},g.framework)),v.length===0&&!n&&e.jsx("div",{className:"card",children:e.jsx(ee,{icon:e.jsx(ye,{size:20}),title:"No sessions found",subtitle:"Sessions will appear here once frameworks start sending monitored activity."})})]})]})}const Fn={d1:"Tool risk",d2:"Target sensitivity",d3:"Data flow",d4:"Frequency",d5:"Context"},Un={background:"#101825",border:"1px solid rgba(96, 165, 250, 0.18)",borderRadius:16,fontSize:12,color:"#f6f8fb",boxShadow:"0 18px 40px rgba(3, 11, 25, 0.34)"};function Wn(t){const s=t.toLowerCase();return s.includes("shell")||s.includes("command")?"shell":s.includes("file")||s.includes("path")?"file":s.includes("network")||s.includes("url")?"network":s.includes("secret")||s.includes("credential")||s.includes("data")?"data":"default"}function Mn({hint:t}){return e.jsx("span",{className:`hint-tag hint-tag-${Wn(t)}`,children:t})}function Je({tier:t}){const s=t.toUpperCase(),n=s==="L3"?"badge-tier-l3":s==="L2"?"badge-tier-l2":"badge-tier-l1";return e.jsx("span",{className:`badge ${n}`,children:s})}function qn({ms:t}){const s=t<100?"latency-fast":t<3e3?"latency-medium":"latency-slow";return e.jsxs("span",{className:`latency-badge ${s}`,children:[t,"ms"]})}function Vn(){const{sessionId:t}=Es(),[s,n]=h.useState(null),[r,a]=h.useState([]),[i,o]=h.useState(!0);if(h.useEffect(()=>{t&&(o(!0),Promise.all([R.sessionRisk(t),R.sessionReplay(t)]).then(([c,d])=>{n(c),a(d)}).catch(()=>{}).finally(()=>o(!1)))},[t]),i)return e.jsxs("div",{children:[e.jsx("div",{style:{height:24,marginBottom:20}}),e.jsx("div",{className:"session-detail-grid",children:[0,1,2].map(c=>e.jsx(X,{rows:4,height:220},c))}),e.jsx(X,{rows:8,height:320})]});const m=s?Object.entries(s.dimensions_latest).map(([c,d])=>({dimension:Fn[c]||c,value:d,fullMark:1})):[],l=(s==null?void 0:s.risk_timeline.map(c=>({time:new Date(c.occurred_at).toLocaleTimeString(),score:Number(c.composite_score.toFixed(3))})))??[];return e.jsxs("div",{className:"session-detail-shell",children:[e.jsxs(O,{to:"/sessions",className:"back-link",children:[e.jsx(Et,{size:13}),"Back to session inventory"]}),e.jsxs("section",{className:"session-hero",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Session detail"}),e.jsx("h1",{children:Te((s==null?void 0:s.workspace_root)||"")}),e.jsxs("p",{className:"hero-copy",children:[(s==null?void 0:s.source_framework)||"unknown"," · ",(s==null?void 0:s.caller_adapter)||"unknown adapter"," · last seen ",s?B(s.last_event_at):"recently"]}),e.jsxs("div",{className:"hero-chip-row",children:[s&&e.jsx(C,{level:s.current_risk_level}),s&&e.jsxs("span",{className:"framework-chip",children:[e.jsx("span",{children:"Agent"}),e.jsx("strong",{children:s.agent_id})]}),s&&e.jsxs("span",{className:"framework-chip",children:[e.jsx("span",{children:"Events"}),e.jsx("strong",{children:s.event_count})]})]})]}),e.jsxs("div",{className:"hero-panel",children:[e.jsxs("div",{className:"hero-panel-header",children:[e.jsx(Ye,{size:14}),"Session risk posture"]}),e.jsxs("div",{className:"hero-panel-body",children:[e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"Cumulative score"}),e.jsx("strong",{children:(s==null?void 0:s.cumulative_score.toFixed(2))??"0.00"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"High-risk events"}),e.jsx("strong",{children:(s==null?void 0:s.high_risk_event_count)??0})]}),e.jsxs("div",{children:[e.jsx("span",{className:"hero-panel-label",children:"First event"}),e.jsx("strong",{children:s?B(s.first_event_at):"—"})]})]})]})]}),e.jsxs("div",{className:"session-detail-grid",children:[e.jsxs("section",{className:"card section-card",children:[e.jsx("div",{className:"section-card-header",children:e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Identity"}),e.jsx("h2",{children:"Workspace context"})]})}),e.jsxs("div",{className:"detail-meta-list",children:[e.jsxs("div",{className:"detail-meta-item",children:[e.jsx(Rt,{size:15}),e.jsxs("div",{children:[e.jsx("span",{children:"Workspace root"}),e.jsx("strong",{className:"mono",children:(s==null?void 0:s.workspace_root)||"Unavailable"})]})]}),e.jsxs("div",{className:"detail-meta-item",children:[e.jsx(Lt,{size:15}),e.jsxs("div",{children:[e.jsx("span",{children:"Transcript path"}),e.jsx("strong",{className:"mono",children:(s==null?void 0:s.transcript_path)||"Unavailable"})]})]}),e.jsxs("div",{className:"detail-pill-row",children:[e.jsxs("span",{className:"framework-chip",children:[e.jsx("span",{children:"Framework"}),e.jsx("strong",{children:(s==null?void 0:s.source_framework)||"unknown"})]}),e.jsxs("span",{className:"framework-chip",children:[e.jsx("span",{children:"Adapter"}),e.jsx("strong",{children:(s==null?void 0:s.caller_adapter)||"unknown"})]})]})]})]}),e.jsxs("section",{className:"card section-card",children:[e.jsx("div",{className:"section-card-header",children:e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Dimensions"}),e.jsx("h2",{children:"Risk composition"})]})}),e.jsx("div",{style:{height:280},children:m.length>0?e.jsx(Pe,{children:e.jsxs(At,{data:m,children:[e.jsx(Dt,{stroke:"rgba(120, 196, 255, 0.12)"}),e.jsx(Ot,{dataKey:"dimension",tick:{fill:"#89a4bd",fontSize:10}}),e.jsx(Bt,{tick:{fill:"#55708a",fontSize:9},domain:[0,1]}),e.jsx(Ft,{dataKey:"value",stroke:"#5ea5ff",fill:"#5ea5ff",fillOpacity:.2,strokeWidth:2})]})}):e.jsx("p",{className:"empty-inline",children:"No dimension data yet."})})]}),e.jsxs("section",{className:"card section-card",children:[e.jsx("div",{className:"section-card-header",children:e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Signals"}),e.jsx("h2",{children:"Observed indicators"})]})}),e.jsx("div",{className:"detail-pill-row",style:{marginBottom:16},children:Object.entries((s==null?void 0:s.actual_tier_distribution)||{}).map(([c,d])=>e.jsxs("span",{children:[e.jsx(Je,{tier:c})," ",e.jsx("span",{className:"mono",children:d})]},c))}),e.jsxs("div",{className:"detail-list-block",children:[e.jsx("span",{className:"detail-list-label",children:"Tools used"}),e.jsx("div",{className:"detail-pill-row",children:s!=null&&s.tools_used.length?s.tools_used.map(c=>e.jsx("span",{className:"cmd-snippet",children:c},c)):e.jsx("span",{className:"empty-inline",children:"No tool usage recorded."})})]}),e.jsxs("div",{className:"detail-list-block",children:[e.jsx("span",{className:"detail-list-label",children:"Risk hints"}),e.jsx("div",{className:"detail-pill-row",children:s!=null&&s.risk_hints_seen.length?s.risk_hints_seen.map(c=>e.jsx(Mn,{hint:c},c)):e.jsx("span",{className:"empty-inline",children:"No risk hints recorded."})})]})]})]}),e.jsxs("section",{className:"card section-card",style:{marginBottom:18},children:[e.jsx("div",{className:"section-card-header",children:e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Timeline"}),e.jsx("h2",{children:"Risk score over time"})]})}),e.jsx("div",{style:{height:240},children:l.length>0?e.jsx(Pe,{children:e.jsxs(Ut,{data:l,margin:{top:8,right:8,bottom:0,left:-12},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"riskGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#5ea5ff",stopOpacity:.34}),e.jsx("stop",{offset:"95%",stopColor:"#5ea5ff",stopOpacity:0})]})}),e.jsx(Wt,{strokeDasharray:"3 3",stroke:"rgba(120, 196, 255, 0.08)"}),e.jsx(Mt,{dataKey:"time",tick:{fill:"#89a4bd",fontSize:10},axisLine:!1,tickLine:!1}),e.jsx(qt,{tick:{fill:"#89a4bd",fontSize:10},axisLine:!1,tickLine:!1,domain:[0,1]}),e.jsx(Vt,{contentStyle:Un}),e.jsx(Ht,{type:"monotone",dataKey:"score",stroke:"#5ea5ff",strokeWidth:2,fill:"url(#riskGradient)",dot:{fill:"#5ea5ff",r:3,strokeWidth:0},activeDot:{r:5,fill:"#5ea5ff"}})]})}):e.jsx("p",{className:"empty-inline",children:"No timeline data yet."})})]}),e.jsxs("section",{className:"card section-card",children:[e.jsxs("div",{className:"section-card-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Replay"}),e.jsx("h2",{children:"Decision timeline"})]}),e.jsxs("span",{className:"section-meta",children:[r.length," events"]})]}),e.jsxs("div",{className:"decision-timeline",children:[r.map((c,d)=>{var f,j,y,_;const u=typeof((f=c.event)==null?void 0:f.input)=="string"?c.event.input:"";return e.jsxs("div",{className:"decision-timeline-row",children:[e.jsx("span",{className:"mono decision-timeline-time",children:new Date(c.recorded_at).toLocaleTimeString()}),e.jsxs("div",{className:"decision-timeline-main",children:[e.jsxs("div",{className:"decision-timeline-badges",children:[e.jsx(mt,{decision:c.decision.decision}),e.jsx(C,{level:c.risk_snapshot.risk_level}),e.jsx(Je,{tier:c.meta.actual_tier}),e.jsx("span",{className:"cmd-snippet",children:String(((j=c.event)==null?void 0:j.tool_name)||"unknown")}),e.jsx(qn,{ms:c.decision.decision_latency_ms})]}),u&&e.jsx("div",{className:"cmd-snippet",style:{maxWidth:"100%"},children:u.slice(0,180)}),c.decision.reason&&e.jsx("p",{className:"priority-session-meta",children:String(c.decision.reason)}),((y=c.l3_trace)==null?void 0:y.trigger_detail)&&e.jsxs("p",{className:"priority-session-meta",children:["Trigger detail: ",e.jsx("span",{className:"mono",children:(_=c.l3_trace)==null?void 0:_.trigger_detail})]}),c.meta.l3_requested!==void 0&&e.jsxs("p",{className:"priority-session-meta",children:["L3 requested: ",e.jsx("span",{className:"mono",children:c.meta.l3_requested?"yes":"no"})]}),c.meta.l3_available!==void 0&&e.jsxs("p",{className:"priority-session-meta",children:["L3 available: ",e.jsx("span",{className:"mono",children:c.meta.l3_available?"yes":"no"})]}),c.meta.l3_reason_code&&e.jsxs("p",{className:"priority-session-meta",children:["L3 reason code: ",e.jsx("span",{className:"mono",children:c.meta.l3_reason_code})]}),c.meta.l3_state&&c.meta.l3_state!=="completed"&&e.jsxs("p",{className:"priority-session-meta",children:["L3 state: ",e.jsx("span",{className:"mono",children:c.meta.l3_state})]}),c.meta.l3_reason&&c.meta.l3_state&&c.meta.l3_state!=="completed"&&e.jsxs("p",{className:"priority-session-meta",children:["L3 reason: ",e.jsx("span",{className:"mono",children:c.meta.l3_reason})]})]})]},`${c.recorded_at}-${d}`)}),r.length===0&&e.jsx("div",{className:"empty-inline",children:"No trajectory records yet."})]})]})]})}const Hn={low:"var(--color-allow)",medium:"var(--color-defer)",high:"var(--color-block)",critical:"var(--color-block)"};function xt(t){return t==="warning"?"medium":t==="info"?"low":t==="critical"||t==="high"||t==="medium"||t==="low"?t:"low"}function Jn(t){return{...t,severity:xt(t.severity)}}const Ke=(t,s,n)=>!(s&&t.severity!==s||n!==void 0&&t.acknowledged!==n);function Kn(){const[t,s]=h.useState([]),[n,r]=h.useState(!0),[a,i]=h.useState(""),[o,m]=h.useState(void 0),l=h.useCallback(async()=>{r(!0);try{const u=await R.alerts({severity:a||void 0,acknowledged:o,limit:100});s(u.map(Jn))}catch{}r(!1)},[a,o]);h.useEffect(()=>{l()},[l]),h.useEffect(()=>{const u=setInterval(l,3e4);return()=>clearInterval(u)},[l]),h.useEffect(()=>{const u=Le(["alert"]);return u.addEventListener("alert",f=>{try{const j=JSON.parse(f.data),y={alert_id:j.alert_id,severity:xt(j.severity),metric:j.metric,session_id:j.session_id,message:j.message,details:{},triggered_at:j.timestamp,acknowledged:!1,acknowledged_by:null,acknowledged_at:null};s(_=>Ke(y,a,o)?[y,..._]:_)}catch{}}),()=>u.close()},[a,o]);const c=async u=>{try{await R.acknowledgeAlert(u),s(f=>f.map(j=>j.alert_id===u?{...j,acknowledged:!0,acknowledged_by:"dashboard",acknowledged_at:new Date().toISOString()}:j).filter(j=>Ke(j,a,o)))}catch{}},d=t.filter(u=>!u.acknowledged).length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[e.jsxs("h2",{className:"section-header",style:{marginBottom:0},children:[e.jsx(re,{size:18,style:{color:"var(--color-defer)"}}),"Alerts Workbench",d>0&&e.jsxs("span",{className:"badge badge-defer",style:{marginLeft:4},children:[d," open"]})]}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("select",{value:a,onChange:u=>i(u.target.value),children:[e.jsx("option",{value:"",children:"All Severities"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"critical",children:"Critical"})]}),e.jsxs("select",{value:o===void 0?"":String(o),onChange:u=>m(u.target.value===""?void 0:u.target.value==="true"),children:[e.jsx("option",{value:"",children:"All Status"}),e.jsx("option",{value:"false",children:"Unacknowledged"}),e.jsx("option",{value:"true",children:"Acknowledged"})]}),e.jsx("button",{className:"btn",onClick:l,disabled:n,children:e.jsx(Ge,{size:13,style:n?{animation:"spin 1s linear infinite"}:void 0})})]})]}),e.jsx("div",{className:"card",style:{padding:0,overflow:"hidden"},children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Severity"}),e.jsx("th",{children:"Metric"}),e.jsx("th",{children:"Session"}),e.jsx("th",{children:"Message"}),e.jsx("th",{children:"Triggered"}),e.jsx("th",{children:"Status"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.map(u=>e.jsxs("tr",{style:u.acknowledged?{opacity:.45}:void 0,children:[e.jsx("td",{children:e.jsx("span",{className:"mono",style:{fontSize:"0.72rem",fontWeight:700,color:Hn[u.severity]||"var(--color-text)",textTransform:"uppercase",letterSpacing:"0.05em"},children:u.severity})}),e.jsx("td",{className:"mono",style:{fontSize:"0.78rem"},children:u.metric}),e.jsx("td",{children:e.jsx(O,{to:`/sessions/${u.session_id}`,style:{color:"var(--color-accent)",textDecoration:"none",fontFamily:"var(--font-mono)",fontSize:"0.72rem"},children:(u.session_id??"").length>12?(u.session_id??"").slice(0,12)+"…":u.session_id??"—"})}),e.jsx("td",{className:"text-secondary",style:{fontSize:"0.78rem",maxWidth:280,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.message}),e.jsx("td",{className:"mono text-muted",style:{fontSize:"0.68rem"},children:new Date(u.triggered_at).toLocaleString()}),e.jsx("td",{children:u.acknowledged?e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--color-allow)",fontSize:"0.72rem"},children:[e.jsx(Tt,{size:13})," ACK"]}):e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--color-defer)",fontSize:"0.72rem"},children:[e.jsx(Pt,{size:13})," OPEN"]})}),e.jsx("td",{children:!u.acknowledged&&e.jsx("button",{className:"btn btn-primary",style:{padding:"3px 10px",fontSize:"0.68rem"},onClick:()=>c(u.alert_id),children:"Acknowledge"})})]},u.alert_id)),t.length===0&&!n&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,style:{padding:0,border:"none"},children:e.jsx(ee,{icon:e.jsx(re,{size:20}),title:"No alerts",subtitle:"Alerts will appear here when risk thresholds are exceeded"})})})]})]})})]})}function Gn({expiresAt:t,totalSeconds:s=30,onExpired:n}){const[r,a]=h.useState(()=>Math.max(0,t-Date.now()/1e3));if(h.useEffect(()=>{const y=setInterval(()=>{const _=Math.max(0,t-Date.now()/1e3);a(_),_<=0&&(clearInterval(y),n==null||n())},500);return()=>clearInterval(y)},[t,n]),r<=0)return e.jsx("span",{className:"mono",style:{fontSize:"0.75rem",color:"var(--color-block)",fontWeight:700},children:"EXPIRED"});const o=r<10?"var(--color-block)":"var(--color-defer)",m=Math.min(1,r/s),l=16,c=2*Math.PI*l,d=m*c,u=Math.floor(r/60),f=Math.floor(r%60),j=u>0?`${u}:${String(f).padStart(2,"0")}`:`${f}s`;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("svg",{width:40,height:40,style:{transform:"rotate(-90deg)"},children:[e.jsx("circle",{cx:20,cy:20,r:l,fill:"none",stroke:"rgba(255,255,255,0.08)",strokeWidth:3}),e.jsx("circle",{cx:20,cy:20,r:l,fill:"none",stroke:o,strokeWidth:3,strokeDasharray:`${d} ${c}`,strokeLinecap:"round",style:{transition:"stroke-dasharray 0.5s ease, stroke 0.3s ease"}})]}),e.jsx("span",{className:"mono",style:{fontSize:"0.85rem",fontWeight:700,color:o,minWidth:32},children:j})]})}function Yn(){const[t,s]=h.useState([]),[n,r]=h.useState(!0);h.useEffect(()=>{const l=Le(["defer_pending","defer_resolved"]);return l.addEventListener("defer_pending",c=>{try{const d=JSON.parse(c.data);s(u=>{if(u.some(j=>j.approval_id===d.approval_id))return u;const f=d.timeout_s>0?Date.parse(d.timestamp)/1e3+d.timeout_s:void 0;return[{approval_id:d.approval_id,session_id:d.session_id,tool_name:d.tool_name,command:d.command,reason:d.reason,timestamp:d.timestamp,expires_at:f,status:"pending"},...u]})}catch{}}),l.addEventListener("defer_resolved",c=>{try{const d=JSON.parse(c.data);s(u=>u.map(f=>f.approval_id===d.approval_id?{...f,status:d.resolved_decision==="block"?"denied":"allowed",reason:d.resolved_reason||f.reason,timestamp:d.timestamp}:f))}catch{}}),()=>l.close()},[]);const a=h.useCallback(async(l,c)=>{try{await R.resolve(l,c,c==="deny"?"operator denied via dashboard":""),s(d=>d.map(u=>u.approval_id===l?{...u,status:c==="allow-once"?"allowed":"denied"}:u))}catch(d){d instanceof ut&&d.status===503&&r(!1)}},[]),i=h.useCallback(l=>{s(c=>c.map(d=>d.approval_id===l&&d.status==="pending"?{...d,status:"expired"}:d))},[]),o=t.filter(l=>l.status==="pending"),m=t.filter(l=>l.status!=="pending");return e.jsxs("div",{children:[e.jsxs("h2",{className:"section-header",children:[e.jsx(ae,{size:18,style:{color:"var(--color-accent)"}}),"DEFER Interactive Panel",o.length>0&&e.jsxs("span",{className:"badge badge-defer",style:{marginLeft:4},children:[o.length," pending"]})]}),!n&&e.jsx("div",{className:"card",style:{marginBottom:16,borderColor:"rgba(245,158,11,0.3)",background:"rgba(245,158,11,0.05)"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--color-defer)",fontSize:"0.83rem"},children:[e.jsx(Ye,{size:15}),"Resolve not available — OpenClaw enforcement is not connected"]})}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("div",{className:"text-muted mono",style:{fontSize:"0.68rem",marginBottom:10,textTransform:"uppercase",letterSpacing:"0.1em"},children:["Pending (",o.length,")"]}),o.length===0?e.jsx("div",{className:"card",children:e.jsx(ee,{icon:e.jsx(ae,{size:20}),title:"No pending DEFER decisions",subtitle:"DEFER decisions will appear here in real-time when agents require approval"})}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:o.map(l=>{const d=(l.expires_at?l.expires_at-Date.now()/1e3:999)<10;return e.jsx("div",{className:`card fade-in ${d?"defer-card-critical":"defer-card-pending"}`,style:{borderLeftWidth:3,borderLeftStyle:"solid",borderLeftColor:d?"var(--color-block)":"var(--color-defer)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:16},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx("span",{className:"mono",style:{fontSize:"0.88rem",fontWeight:600},children:l.tool_name}),l.risk_level&&e.jsx(C,{level:l.risk_level})]}),e.jsx("div",{className:"cmd-snippet",style:{maxWidth:"100%",marginBottom:l.reason?6:0},children:l.command||"—"}),l.reason&&e.jsx("div",{className:"text-secondary",style:{fontSize:"0.73rem",marginTop:4},children:l.reason})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:10,flexShrink:0},children:[l.expires_at?e.jsx(Gn,{expiresAt:l.expires_at,onExpired:()=>i(l.approval_id)}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx($t,{size:13,className:"text-muted"}),e.jsx("span",{className:"mono text-muted",style:{fontSize:"0.72rem"},children:"No timeout"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:"btn btn-allow",onClick:()=>a(l.approval_id,"allow-once"),disabled:!n,children:"Allow"}),e.jsx("button",{className:"btn btn-deny",onClick:()=>a(l.approval_id,"deny"),disabled:!n,children:"Deny"})]})]})]})},l.approval_id)})})]}),m.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-muted mono",style:{fontSize:"0.68rem",marginBottom:10,textTransform:"uppercase",letterSpacing:"0.1em"},children:["Resolved (",m.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map(l=>e.jsxs("div",{className:"card",style:{opacity:.45,padding:"9px 14px",display:"flex",alignItems:"center",gap:10,fontSize:"0.78rem"},children:[e.jsx("span",{className:`badge ${l.status==="allowed"?"badge-allow":l.status==="denied"?"badge-block":"badge-defer"}`,children:l.status}),e.jsx("span",{className:"mono",children:l.tool_name}),e.jsx("span",{className:"cmd-snippet",style:{flex:1},children:l.command||"—"}),e.jsx("span",{className:"text-muted mono",style:{fontSize:"0.68rem"},children:new Date(l.timestamp).toLocaleTimeString()})]},l.approval_id))})]})]})}function Xn(){const{authenticated:t,check:s,login:n}=on(),[r,a]=h.useState(!1);return h.useEffect(()=>{const i=new URLSearchParams(window.location.search),o=i.get("token");if(o){ot(o),i.delete("token");const m=i.toString()?`${window.location.pathname}?${i.toString()}`:window.location.pathname;window.history.replaceState({},"",m)}a(!0)},[]),h.useEffect(()=>{r&&s()},[r,s]),!r||t===null?e.jsx("div",{className:"login-container",children:e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("span",{className:"status-dot checking",style:{width:12,height:12}}),e.jsx("p",{className:"text-muted mono",style:{marginTop:12,fontSize:"0.8rem"},children:"Connecting..."})]})}):t===!1?e.jsx(xn,{onLogin:n}):e.jsx(en,{basename:"/ui",children:e.jsx(Hs,{children:e.jsxs(I,{element:e.jsx(fn,{}),children:[e.jsx(I,{index:!0,element:e.jsx(In,{})}),e.jsx(I,{path:"sessions",element:e.jsx(Bn,{})}),e.jsx(I,{path:"sessions/:sessionId",element:e.jsx(Vn,{})}),e.jsx(I,{path:"alerts",element:e.jsx(Kn,{})}),e.jsx(I,{path:"defer",element:e.jsx(Yn,{})}),e.jsx(I,{path:"*",element:e.jsx(Ms,{to:"/",replace:!0})})]})})})}Xt.createRoot(document.getElementById("root")).render(e.jsx(zt.StrictMode,{children:e.jsx(Xn,{})}));
