harper 5.0.18 → 5.0.19

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.
@@ -1,2 +1,2 @@
1
- import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{n as t,t as n}from"./button-V4IQ8FFq.js";import{Aa as r,Di as i,Fa as a,Li as o,Lr as s,Na as c,Pa as l,Sa as u,Ua as d,Wi as f,Yr as p,_ as m,a as h,b as g,c as _,d as v,f as y,g as b,gr as x,h as S,hr as C,i as w,ja as ee,ka as te,l as T,m as E,n as ne,o as re,p as D,r as ie,s as ae,t as oe,u as se,v as ce,xa as le,y as ue}from"./vendor-react-Dj1rnUQ4.js";import{g as de}from"./vendor-misc-DKMU5hOJ.js";import{a as fe,c as O,l as k,o as A,r as pe,s as j,u as M}from"./useInstanceClient-CdXj_Str.js";import{C as me,F as he,N as ge,P as _e,S as ve,T as ye,_ as be,c as N,d as xe,f as Se,g as Ce,h as we,l as Te,m as Ee,n as De,p as Oe,s as ke,t as Ae,u as je,v as Me,w as Ne,x as Pe}from"./index-Tv7e9k8K.js";var P=e(a(),1),F=l(),Fe=`studio:analytics:onboarding-dismissed:v1`;function Ie(){let[e,t]=(0,P.useState)(null);return(0,P.useEffect)(()=>{try{t(window.localStorage.getItem(Fe)===`1`)}catch{t(!0)}},[]),e===!1?(0,F.jsxs)(`div`,{role:`status`,className:`mb-3 flex items-start gap-3 rounded-md border border-border bg-muted/30 px-3 py-2 text-sm text-muted-foreground`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(`span`,{className:`font-medium text-foreground`,children:`Tip:`}),` Click a legend entry to isolate one node, `,(0,F.jsx)(`kbd`,{className:`rounded border border-border px-1 py-0.5 text-xs`,children:`⌘`}),` / `,(0,F.jsx)(`kbd`,{className:`rounded border border-border px-1 py-0.5 text-xs`,children:`Ctrl`}),`-click to compare a few. Bar segments and heatmap cells are clickable for drilldown.`]}),(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:()=>{try{window.localStorage.setItem(Fe,`1`)}catch{}t(!0)},"aria-label":`Dismiss tip`,className:`-mt-1 h-7 w-7 shrink-0`,children:(0,F.jsx)(x,{className:`h-4 w-4`})})]}):null}var Le=6e4,Re=60*Le,ze=24*Re,Be=[{id:`1h`,label:`Last 1 hour`,durationMs:Re,bucketMs:1*Le},{id:`6h`,label:`Last 6 hours`,durationMs:6*Re,bucketMs:1*Le},{id:`24h`,label:`Last 24 hours`,durationMs:ze,bucketMs:5*Le},{id:`7d`,label:`Last 7 days`,durationMs:7*ze,bucketMs:15*Le},{id:`30d`,label:`Last 30 days`,durationMs:30*ze,bucketMs:Re}];function Ve(e){let t=Be.find(t=>t.id===e);if(!t)throw Error(`Unknown preset: ${e}`);return t}var He=[{label:`Off`,value:0},{label:`30s`,value:3e4},{label:`60s`,value:6e4},{label:`5m`,value:3e5}],Ue=6e4,We=Ae;function Ge(){let e=c(),[t,n]=(0,P.useState)(!1),[r,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(()=>Date.now());return(0,P.useEffect)(()=>{let t=e.getQueryCache(),r=e=>Array.isArray(e.queryKey)&&e.queryKey[0]===We,a=()=>{let e=!1,a=null;for(let n of t.getAll())r(n)&&(n.state.fetchStatus===`fetching`&&(e=!0),n.state.dataUpdatedAt>0&&(a===null||n.state.dataUpdatedAt>a)&&(a=n.state.dataUpdatedAt));n(t=>t===e?t:e),i(e=>e===a?e:a)};a();let o=t.subscribe(e=>{!e?.query||!r(e.query)||a()});return()=>o()},[e]),(0,P.useEffect)(()=>{let e=!1,t,n=()=>{if(e)return;o(Date.now());let i=r===null?0:Date.now()-r,a=i<6e4?1e3:i<6e5?5e3:3e4;t=window.setTimeout(n,a)};return t=window.setTimeout(n,1e3),()=>{e=!0,t!==void 0&&window.clearTimeout(t)}},[r]),{isFetching:t,lastFetchedAt:r,now:a}}function Ke(e,t){if(e===null)return null;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<5)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function qe({presetId:e,onPresetChange:r,refreshMs:i,onRefreshChange:a,onManualRefresh:o}){let{isFetching:c,lastFetchedAt:l,now:u}=Ge(),d=Ke(l,u);return(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,F.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,title:l?new Date(l).toLocaleString():void 0,"aria-label":l?`Last updated ${new Date(l).toLocaleString()}`:void 0,children:[`Updated `,d]}),(0,F.jsxs)(Ee,{value:e,onValueChange:e=>r(e),children:[(0,F.jsx)(be,{className:`w-[180px]`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:Be.map(e=>(0,F.jsx)(Ce,{value:e.id,children:e.label},e.id))})]}),(0,F.jsxs)(Ee,{value:String(i),onValueChange:e=>a(Number(e)),children:[(0,F.jsx)(be,{className:`w-[100px]`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:He.map(e=>(0,F.jsx)(Ce,{value:String(e.value),children:e.label},e.value))})]}),(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:o,disabled:c,"aria-busy":c,"aria-label":c?`Refreshing…`:`Refresh now`,title:c?`Refreshing…`:`Refresh now`,children:(0,F.jsx)(s,{className:t(`h-4 w-4`,c&&`animate-spin`)})})]})}var Je=(0,P.createContext)(null);function Ye({value:e,children:t}){let n=(0,P.useMemo)(()=>e,[e.timeRange.startTime,e.timeRange.endTime,e.bucketMs,e.refreshIntervalMs,e.theme,e.instanceParams.entityId]);return(0,F.jsx)(Je.Provider,{value:n,children:t})}function I(){let e=(0,P.useContext)(Je);if(!e)throw Error(`useAnalyticsContext must be used inside <AnalyticsProvider>`);return e}var Xe=[`utilization`,`cpu-usage`,`memory`,`main-thread-utilization`],Ze=30*6e4;function Qe(e){let t=e?.response?.status??e?.status;return typeof t==`number`?t>=400&&t<500:!1}function $e(e){let t=ee({queryKey:[`analytics-capability`,e.entityId],queryFn:async()=>{let t=Date.now(),n=t-5*6e4,r=null;for(let i of Xe)try{return await e.instanceClient.post(`/`,{operation:`get_analytics`,metric:i,start_time:n,end_time:t}),!0}catch(e){if(r=e,!Qe(e))throw e}throw r instanceof Error?r:Error(`Analytics probe failed for all metrics`)},retry:2,retryDelay:e=>Math.min(1e3*2**e,8e3),staleTime:Ze,gcTime:Ze});return{supported:t.isSuccess===!0,error:t.error,isLoading:t.isLoading,retry:()=>{t.refetch()}}}function et(e){let t=e;for(;t;){let e=getComputedStyle(t).backgroundColor;if(e&&e!==`rgba(0, 0, 0, 0)`&&e!==`transparent`)return e;t=t.parentElement}let n=typeof document<`u`?getComputedStyle(document.body).backgroundColor:``;return n&&n!==`rgba(0, 0, 0, 0)`?n:`#ffffff`}async function tt(e,t=3){let n=await de(e,{pixelRatio:t,backgroundColor:et(e)});if(!n)throw Error(`Failed to capture chart as image`);return n}async function nt(e,t){let n=await tt(e),r=URL.createObjectURL(n);try{let e=document.createElement(`a`);e.href=r,e.download=t,e.click()}finally{URL.revokeObjectURL(r)}}async function rt(e){if(typeof ClipboardItem>`u`||!navigator.clipboard?.write)return!1;try{let t=await tt(e);return await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),!0}catch{return!1}}function it(e,t){return`${e.replace(/[^a-z0-9-]+/gi,`-`).replace(/(^-|-$)/g,``).toLowerCase()}-${new Date(t.endTime).toISOString().replace(/[:.]/g,`-`)}.png`}function at({captureRef:e,exportSlug:t}){let[r,i]=(0,P.useState)(!1);return(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:async()=>{if(r)return;let t=e.current;if(t){i(!0);try{await rt(t)?C.success(`Chart copied to clipboard`):C.error(`Could not copy chart`,{description:`Your browser blocked the clipboard write. Try Download or check site permissions.`})}catch(e){console.error(`[chart-copy] capture failed`,e),C.error(`Could not copy chart`,{description:e instanceof Error?e.message:`Unknown error`})}finally{i(!1)}}},"aria-disabled":r,"aria-busy":r,"aria-label":`Copy ${t} chart to clipboard`,children:(0,F.jsx)(o,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Copy to clipboard`})]})}function ot({captureRef:e,exportSlug:t}){let{timeRange:r}=I(),[a,o]=(0,P.useState)(!1);return(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:async()=>{if(a)return;let n=e.current;if(!n)return;o(!0);let i=it(t,r);try{await nt(n,i),C.success(`Saved ${i}`)}catch(e){console.error(`[chart-export] capture failed`,e),C.error(`Could not export chart`,{description:e instanceof Error?e.message:`Unknown error`})}finally{o(!1)}},"aria-disabled":a,"aria-busy":a,"aria-label":`Download ${t} as PNG`,children:(0,F.jsx)(i,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Download as PNG`})]})}function st({exportSlug:e,title:t,description:r,renderChart:i}){let[a,o]=(0,P.useState)(!1),s=(0,P.useRef)(null);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:()=>o(!0),"aria-label":`Expand ${e}`,children:(0,F.jsx)(p,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Expand`})]}),(0,F.jsx)(Pe,{open:a,onOpenChange:o,children:(0,F.jsxs)(ve,{className:`!max-w-[95vw] sm:!max-w-[95vw] h-[90vh] flex flex-col`,children:[(0,F.jsx)(Ne,{children:(0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-2 pr-6`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(ye,{children:t}),r&&(0,F.jsx)(me,{children:r})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(at,{captureRef:s,exportSlug:`${e}-expanded`}),(0,F.jsx)(ot,{captureRef:s,exportSlug:`${e}-expanded`})]})]})}),(0,F.jsx)(`div`,{ref:s,className:`flex-1 min-h-0 overflow-hidden flex flex-col`,children:i({fillParent:!0})})]})})]})}var ct=new Set([`time`,`node`]),lt=Object.freeze([]);function ut({metric:e,startTime:t,endTime:n,conditions:r,instanceParams:i,refetchIntervalMs:a=6e4,requiredFields:o,bucketMs:s}){let c=(0,P.useRef)(null);c.current===null&&(c.current=Math.floor(Math.random()*500));let l=ee({...De({metric:e,startTime:t,endTime:n,conditions:r,instanceParams:i,bucketMs:s}),staleTime:a>0?a:1/0,refetchInterval:a>0?a+c.current:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,placeholderData:d}),u=l.data??lt,{fieldKeys:f,missingFields:p}=(0,P.useMemo)(()=>{let e=new Set;for(let t of u)for(let n of Object.keys(t))ct.has(n)||e.add(n);let t=[];if(o&&u.length>0)for(let n of o)e.has(n)||t.push(n);return{fieldKeys:e,missingFields:t}},[u,o]);return(0,P.useEffect)(()=>{!l.isLoading&&u.length===0&&p.length>0&&console.warn(`[analytics] panel rendered empty with missing fields`,{metric:e,instanceId:i.entityId,missingFields:p})},[u.length,l.isLoading,e,i.entityId,p]),{data:u,isLoading:l.isLoading,isError:l.isError,error:l.error,isEmpty:u.length===0,fieldKeys:f,missingFields:p,refetch:l.refetch}}function dt(e,t,n){let r=new Map;for(let t of e){let e=typeof t.path==`string`?t.path:null;if(!e||typeof t.time!=`number`||!Number.isFinite(t.time))continue;let n=typeof t.count==`number`&&Number.isFinite(t.count)?t.count:0,i=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:0,a=r.get(e);a||(a=new Map,r.set(e,a));let o=a.get(t.time);o||(o={sumCount:0,sumTotal:0},a.set(t.time,o)),o.sumCount+=n,o.sumTotal+=i}return{series:[...r.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e);return{x:e,y:n.sumCount===0?null:1-n.sumTotal/n.sumCount,count:n.sumCount}})})),thresholds:[{value:.001,label:`0.1% error SLO`,direction:`above-is-bad`,minCount:1e3}]}}var ft={id:`error-rate`,title:`Error rate (≥1000 req)`,subtitle:`errored-request fraction — 1 − Σtotal/Σcount`,tab:`requests`,sourceMetric:`success`,recompute:dt,primitive:`line`,yAxis:{unit:``,formatter:`percent`}},pt=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`,`#79c0ff`,`#d2a8ff`,`#ffa657`,`#ff7b72`,`#7ee787`];function L(e,t){return pt[[...t].sort().indexOf(e)%pt.length]}function R({nodeIds:e,isActive:t,onClickNode:n,disabled:r}){return(0,F.jsxs)(`div`,{role:`group`,"aria-label":r?`Node filter (unavailable on this tab)`:`Node filter`,className:`flex flex-wrap justify-center gap-x-4 gap-y-1 pt-2 text-[11px]`,children:[r&&(0,F.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:`Per-node filter is unavailable on this tab. Buttons remain visible to preserve selection state.`}),e.map(i=>{let a=L(i,e),o=t(i);return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":o,"aria-disabled":r?`true`:void 0,title:r?`Per-node filter unavailable on this tab's panels`:void 0,onClick:e=>{r||n(i,e.ctrlKey||e.metaKey)},className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:r?{color:a,opacity:.5,cursor:`not-allowed`}:{color:a,opacity:o?1:.3},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:a}}),(0,F.jsx)(`span`,{children:i})]},i)})]})}function z(e){let[t,n]=(0,P.useState)(null);return{isActive:(0,P.useCallback)(e=>t===null||t.has(e),[t]),handleLegendClick:(0,P.useCallback)((t,r)=>{n(n=>{if(r){if(n===null)return new Set(e.filter(e=>e!==t));let r=new Set(n);if(r.has(t)){if(r.delete(t),r.size===0)return null}else if(r.add(t),r.size===e.length)return null;return r}return n!==null&&n.size===1&&n.has(t)?null:new Set([t])})},[e]),activeNodes:t}}var mt=[`#0d9488`,`#dc2626`,`#7c3aed`,`#d97706`,`#db2777`,`#0284c7`];function ht(e,t){let n=[...t].sort().indexOf(e);return mt[(n<0?0:n)%mt.length]}function B(e,t){let n=t.filter(e=>typeof e.value==`number`&&Number.isFinite(e.value));if(n.length===0)return null;let r=n.map(e=>e.value);switch(e){case`sum`:return r.reduce((e,t)=>e+t,0);case`mean`:return r.reduce((e,t)=>e+t,0)/r.length;case`max`:{let e=r[0];for(let t=1;t<r.length;t++)r[t]>e&&(e=r[t]);return e}case`min`:{let e=r[0];for(let t=1;t<r.length;t++)r[t]<e&&(e=r[t]);return e}case`last`:return r[r.length-1];case`p50`:return gt(r,.5);case`p95`:return gt(r,.95);case`p99`:return gt(r,.99);case`count-weighted-mean`:{let e=0,t=0;for(let r of n){let n=Number.isFinite(r.count)?r.count:1;e+=r.value*n,t+=n}return t===0?null:e/t}}}function gt(e,t){let n=[...e].sort((e,t)=>e-t);return n[Math.max(1,Math.ceil(t*n.length))-1]}function _t(e){return e===`count-weighted-mean`}function V(e,t){return _t(t)?e.endsWith(`(approx)`)?e:`${e} (approx)`:e}function vt(e,t){if(!t)return`ok`;if(e===void 0)return`suppress`;let{suppressBelow:n,greyBelow:r}=t;return n!==void 0&&e<n?r!==void 0&&e>=r?`grey`:`suppress`:r!==void 0&&e<r?`grey`:`ok`}function yt(e,t){switch(e.kind){case`const`:return e.value;case`ref`:{let n=t[e.field];return typeof n==`number`&&Number.isFinite(n)?n:null}case`op`:{let n=yt(e.left,t),r=yt(e.right,t);if(n===null||r===null)return null;switch(e.op){case`+`:return n+r;case`-`:return n-r;case`*`:return n*r;case`/`:return r===0?null:n/r;default:{let t=e.op;throw Error(`unknown op: ${String(t)}`)}}}default:throw Error(`unknown FieldExpr kind: ${e.kind}`)}}var bt={"percent-of-core":e=>e*100};function xt(e,t,n){if(t===null)return null;switch(e.kind){case`raw`:return t;case`scale`:return t*e.factor;case`rate`:return!Number.isFinite(n)||n<=0?null:t/n*1e3;case`ratio`:return t;case`compose`:{let r=t;for(let t of e.steps)if(r=xt(t,r,n),r===null)return null;return r}case`named`:{let n=bt[e.name];if(!n)throw Error(`unknown named transform: ${e.name}`);return n(t)}default:throw Error(`unknown transform kind: ${e.kind}`)}}function H(e,t,n,r,i){return e.series.kind===`field`?Et(e,e.series.fields,t,i?.perNode??!1,i?.snapToPeriod??!1):Tt(e,e.series,t,i?.perNode??!1,i?.snapToPeriod??!1)}function St(e,t,n){let r=0,i=t.period;return typeof i==`number`&&Number.isFinite(i)&&i>0&&(r=i),r<=0&&(r=e.bucket?.fallbackMs??6e4),Math.round(n/r)*r}function Ct(e,t){let n=e.timestamp??`time`;if(n===`time`){let e=t.time;return typeof e==`number`&&Number.isFinite(e)?e:null}if(n===`id`){let e=t.id;return typeof e==`number`&&Number.isFinite(e)?e:null}let r=t.time;if(typeof r==`number`&&Number.isFinite(r))return r;let i=t.id;return typeof i==`number`&&Number.isFinite(i)?i:null}function wt(e,t){let n=typeof e.field==`string`?typeof t[e.field]==`number`?t[e.field]:null:yt(e.field,t),r=typeof t.period==`number`?t.period:0;return xt(e.transform??{kind:`raw`},n,r)}function Tt(e,t,n,r,i){let a=new Map,o=new Map,s=new Set;for(let r of n){let n=r[t.dimension];if(typeof n!=`string`&&typeof n!=`number`)continue;let c=wt(t.field,r);if(c===null)continue;let l=Ct(e,r);if(l===null){let n=`${String(r[t.dimension])}|${String(r.time)}`;s.has(n)||(s.add(n),console.warn(`[runGroupBy] Dropping record with no resolvable timestamp:`,{dimension:r[t.dimension],time:r.time,id:r.id,timestamp:e.timestamp??`time`}));continue}let u=i?St(e,r,l):l,d=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:1,f=typeof r.node==`string`?r.node:`_no_node`;o.set(n,(o.get(n)??0)+d);let p=a.get(n);p||(p=new Map,a.set(n,p));let m=p.get(u);m||(m=new Map,p.set(u,m));let h=m.get(f);h||(h={items:[],totalCount:0},m.set(f,h)),h.items.push({value:c,count:d}),h.totalCount+=d}let c=t.field.aggregator?.temporal??e.aggregator.temporal,l=t.field.aggregator?.crossNode??e.aggregator.crossNode,u=c===`count-weighted-mean`||l===`count-weighted-mean`,d=[...o.entries()].sort((e,t)=>t[1]-e[1]),f=t.topN??1/0,p=d.slice(0,f),m=d.slice(f),h=[],g=0;for(let[n,i]of p){if(vt(i,e.confidence&&{greyBelow:e.confidence.greyBelow,suppressBelow:e.confidence.suppressBelow})===`suppress`){g++;continue}let o=a.get(n);if(!o)continue;let s=t.dimension===`node`;if(r&&!s){let e=new Map;for(let[t,n]of o)for(let[r,i]of n){let n=e.get(r);n||(n=new Map,e.set(r,n)),n.set(t,i)}for(let[t,r]of e){let e=[],i=[...r.keys()].sort((e,t)=>e-t);for(let t of i){let n=r.get(t),i=B(c,n.items);e.push({x:t,y:i,count:n.totalCount})}h.push({key:`${String(n)}|${t}`,label:V(t,c),points:e,approx:u})}}else{let e=[],t=[...o.keys()].sort((e,t)=>e-t);for(let n of t){let{y:t,count:r}=Dt(c,l,o.get(n));e.push({x:n,y:t,count:r})}h.push({key:String(n),label:V(String(n),c),points:e,approx:u})}}if(t.otherBucket&&m.length>0)if(vt(m.reduce((e,[,t])=>e+t,0),e.confidence&&{greyBelow:e.confidence.greyBelow,suppressBelow:e.confidence.suppressBelow})!==`suppress`){let e=new Map;for(let[t]of m){let n=a.get(t);if(n)for(let[t,r]of n){let n=e.get(t);n||(n=new Map,e.set(t,n));for(let[e,t]of r){let r=n.get(e);r||(r={items:[],totalCount:0},n.set(e,r));for(let e of t.items)r.items.push(e);r.totalCount+=t.totalCount}}}let t=[],n=[...e.keys()].sort((e,t)=>e-t);for(let r of n){let{y:n,count:i}=Dt(c,l,e.get(r));t.push({x:r,y:n,count:i})}h.push({key:`Other`,label:V(`Other`,c),points:t,approx:u})}else g++;return{series:h,thresholds:e.thresholds,...g>0?{suppressedSeriesCount:g}:{}}}function Et(e,t,n,r,i){let a=new Set;return{series:t.map(t=>{let o=new Map;for(let r of n){let n=Ct(e,r);if(n===null){let n=`${t.label}|${String(r.time)}`;a.has(n)||(a.add(n),console.warn(`[runFieldSpecs] Dropping record with no resolvable timestamp:`,{field:t.label,time:r.time,id:r.id,timestamp:e.timestamp??`time`}));continue}let s=wt(t,r);if(s===null)continue;let c=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:1,l=typeof r.node==`string`?r.node:`_no_node`,u=i?St(e,r,n):n,d=o.get(u);d||(d=new Map,o.set(u,d));let f=d.get(l);f||(f={items:[],totalCount:0},d.set(l,f)),f.items.push({value:s,count:c}),f.totalCount+=c}let s=t.aggregator?.temporal??e.aggregator.temporal,c=t.aggregator?.crossNode??e.aggregator.crossNode,l=s===`count-weighted-mean`||c===`count-weighted-mean`,u=typeof t.field==`string`?t.field:t.label;if(r){let e=new Map;for(let[t,n]of o)for(let[r,i]of n){let n=e.get(r);n||(n=new Map,e.set(r,n)),n.set(t,i)}let n=[];for(let[r,i]of e){let e=[],a=[...i.keys()].sort((e,t)=>e-t);for(let t of a){let n=i.get(t),r=B(s,n.items);e.push({x:t,y:r,count:n.totalCount})}n.push({key:`${u}|${r}`,label:V(`${t.label} — ${r}`,s),axis:t.axis,points:e,approx:l})}return n}let d=[],f=[...o.keys()].sort((e,t)=>e-t);for(let e of f){let{y:t,count:n}=Dt(s,c,o.get(e));d.push({x:e,y:t,count:n})}return[{key:u,label:V(t.label,s),axis:t.axis,points:d,approx:l}]}).flat(),thresholds:e.thresholds}}function Dt(e,t,n){let r=[],i=0;for(let[,t]of n){let n=B(e,t.items);typeof n==`number`&&Number.isFinite(n)&&r.push({value:n,count:t.totalCount}),i+=t.totalCount}return{y:B(t,r),count:i}}var Ot=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}),kt=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`});new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}),new Intl.DateTimeFormat(void 0,{timeZoneName:`short`});function At(e){return Ot.format(new Date(e))}function jt(e){return kt.format(new Date(e))}function U(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=1e3,r=Math.floor(Math.log(e)/Math.log(n)),i=e/n**r;return`${i.toFixed(+(i<10))} ${t[r]}`}function W(e,t,n){if(e==null||!Number.isFinite(e))return`—`;let r=Mt(e,t);return n?`${r}${n}`:r}function Mt(e,t){switch(t){case`percent`:return`${(e*100).toFixed(1)}%`;case`ms`:return`${e.toFixed(1)} ms`;case`count`:return`${e.toFixed(0)}`;case`count-si`:{let t=Math.abs(e);if(t<1e3)return`${e}`;let n=e<0?`-`:``,r=e=>{if(e>=10)return`${Math.round(e)}`;let t=e.toFixed(1);return t.endsWith(`.0`)?t.slice(0,-2):t};return t<1e6?`${n}${r(t/1e3)}k`:t<1e9?`${n}${r(t/1e6)}M`:`${n}${r(t/1e9)}B`}case`cores`:return`${e.toFixed(2)} cores`;case`bytes-si`:case`bytes-iec`:{let n=t===`bytes-iec`?1024:1e3,r=t===`bytes-iec`?[`B`,`KiB`,`MiB`,`GiB`,`TiB`]:[`B`,`KB`,`MB`,`GB`,`TB`],i=e,a=0;for(;Math.abs(i)>=n&&a<r.length-1;)i/=n,a++;return`${i.toFixed(1)} ${r[a]}`}default:return`${e}`}}var Nt={background:`var(--chart-tooltip-bg)`,color:`var(--chart-tooltip-fg)`,border:`1px solid var(--border)`,borderRadius:6,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.25)`,padding:8,fontSize:12},Pt={color:`var(--chart-tooltip-fg)`,opacity:.7,marginBottom:4,fontSize:11},Ft={color:`var(--chart-tooltip-fg)`};function It(e){return!!e&&typeof e==`object`&&`left`in e}function Lt(e){let t=e.series.map(e=>e.label);return`${t.length===1?`Chart of ${t[0]}`:`Chart with ${t.length} series: ${t.slice(0,5).join(`, `)}${t.length>5?`…`:``}`}${e.thresholds&&e.thresholds.length>0?`. ${e.thresholds.length} threshold${e.thresholds.length===1?``:`s`}.`:``}`}function G({data:e,theme:t,yAxis:n,height:r=240,ariaLabel:i,hideLegend:a,xDomain:o,fillParent:s}){if(e.series.length===0)return(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-(--color-text-secondary) text-sm p-4`,children:`No data in window`});let c=It(n),l=c?n.left:n,u=c?n.right:void 0,d=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`];return(0,F.jsx)(`div`,{role:`img`,"aria-label":i??Lt(e),style:s?{width:`100%`,height:`100%`,minHeight:0,flex:`1 1 auto`,display:`flex`,flexDirection:`column`}:{width:`100%`,height:r},children:(0,F.jsx)(`div`,{"aria-hidden":`true`,style:{width:`100%`,height:`100%`},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,children:(0,F.jsxs)(_,{margin:{top:12,right:12,bottom:8,left:8},children:[(0,F.jsx)(E,{stroke:`var(--chart-grid)`,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`x`,type:`number`,domain:o??[`dataMin`,`dataMax`],allowDataOverflow:!!o,allowDuplicatedCategory:!1,tickFormatter:At,tick:{fontSize:11}}),(0,F.jsx)(T,{yAxisId:`left`,tickFormatter:e=>W(e,l?.formatter,l?.unit),scale:l?.scale??`linear`,domain:l?.domain,tick:{fontSize:11},width:70}),c&&u?(0,F.jsx)(T,{yAxisId:`right`,orientation:`right`,tickFormatter:e=>W(e,u.formatter,u.unit),scale:u.scale??`linear`,domain:u.domain,tick:{fontSize:11},width:70}):null,(0,F.jsx)(m,{labelFormatter:e=>jt(Number(e)),formatter:(t,n)=>{let r=String(n),i=e.series.find(e=>e.label===r||e.key===r)?.axis===`right`?u:l;return[W(Number(t),i?.formatter,i?.unit),r]},contentStyle:Nt,labelStyle:Pt,itemStyle:Ft}),!a&&(0,F.jsx)(ce,{}),e.thresholds?.map((e,t)=>{let n=W(e.value,l?.formatter,l?.unit),r=e.direction===`above-is-bad`?`↑ bad`:`↓ bad`,i=`${e.label} (${n}, ${r})`,a=t%2==0?`insideTopRight`:`insideBottomRight`;return(0,F.jsx)(S,{yAxisId:`left`,y:e.value,stroke:e.direction===`above-is-bad`?`var(--color-error)`:`var(--color-success)`,strokeDasharray:`4 2`,label:{value:i,position:a,fontSize:11}},`th-${t}`)}),e.series.map((e,t)=>{let n=e.points.length<=5;return(0,F.jsx)(D,{data:e.points,type:`monotone`,dataKey:`y`,name:e.label,yAxisId:e.axis===`right`?`right`:`left`,stroke:e.color??d[t%d.length],strokeWidth:2,strokeOpacity:e.opacity??1,dot:n?{r:2}:!1,connectNulls:!1},e.key)})]})})})})}function Rt(e){let t=e.indexOf(`|`);return t===-1?null:e.slice(t+1)}function zt({panels:e,theme:t,minPanelWidth:n=320,panelHeight:r=240,xDomain:i,fillParent:a}){let o=(0,P.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.data.series){let n=Rt(e.key);n&&t.add(n)}return[...t].sort()},[e]),{isActive:s,handleLegendClick:c}=z(o),l=(0,P.useMemo)(()=>e.map(e=>({...e,data:{...e.data,series:e.data.series.filter(e=>{let t=Rt(e.key);return t===null||s(t)}).map(e=>{let t=Rt(e.key);return t?{...e,color:e.color??L(t,o)}:e})}})),[e,s,o]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`flex-1 min-h-0`,style:{display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(${n}px, 1fr))`,gap:`1rem`},children:l.map((e,n)=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{id:`sm-panel-${n}-title`,"data-testid":`small-multiple-title`,style:{fontSize:12,fontWeight:600,marginBottom:4},children:e.title}),(0,F.jsx)(G,{data:e.data,theme:t,yAxis:e.yAxis,xDomain:i,height:r,fillParent:a,ariaLabel:`${e.title}: chart with ${e.data.series.length} series`,hideLegend:!0})]},e.title))}),o.length>0&&(0,F.jsx)(R,{nodeIds:o,isActive:s,onClickNode:c})]})}function Bt(e){return[...e].sort((e,t)=>Vt(t)-Vt(e))}function Vt(e){return e.points.reduce((e,t)=>e+(typeof t.y==`number`?t.y:0),0)}function Ht(e){let t=e.series.map(e=>e.label);return t.length===0?`Empty stacked area chart`:`Stacked area chart with ${t.length} series: ${t.slice(0,5).join(`, `)}${t.length>5?`…`:``}`}function Ut({active:e,payload:t,label:n,formatter:r,unitSuffix:i}){if(!e||!t||t.length===0)return null;let a=t.reduce((e,t)=>e+(typeof t.value==`number`?t.value:0),0),o=r===`count-si`?`count`:r;return(0,F.jsxs)(`div`,{style:Nt,children:[(0,F.jsx)(`div`,{style:Pt,children:n===void 0?``:jt(Number(n))}),t.map(e=>(0,F.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:12},children:[(0,F.jsx)(`span`,{style:{color:e.color},children:e.name}),(0,F.jsx)(`span`,{children:W(typeof e.value==`number`?e.value:0,r,i)})]},e.dataKey)),t.length>1?(0,F.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:12,marginTop:4,paddingTop:4,borderTop:`1px solid var(--border)`,fontWeight:600},children:[(0,F.jsx)(`span`,{children:`Total`}),(0,F.jsx)(`span`,{children:W(a,o,i)})]}):null]})}function Wt({data:e,theme:t,yAxis:n,height:r=240,ariaLabel:i,xDomain:a,fillParent:o,lineOnly:s}){let c=(0,P.useMemo)(()=>Bt(e.series),[e.series]);if(e.series.length===0)return(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-(--color-text-secondary) text-sm p-4`,children:`No data in window`});let l=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`,`#79c0ff`],u=new Set;for(let t of e.series)for(let e of t.points)u.add(e.x);if(e.ceiling)for(let t of e.ceiling.points)u.add(t.x);let d=e.series.map(e=>{let t=new Map;for(let n of e.points)t.set(n.x,n.y);return t}),f=e.ceiling?new Map(e.ceiling.points.map(e=>[e.x,e.y])):null,p=e.series.map(()=>null),h=null,g=[...u].sort((e,t)=>e-t).map(t=>{let n={x:t};return e.series.forEach((e,r)=>{let i=d[r];i.has(t)&&(p[r]=i.get(t)??null),n[e.key]=p[r]}),f&&e.ceiling&&(f.has(t)&&(h=f.get(t)??null),n.__ceiling__=h),n}),_=n?.formatter,v=n?.unit,b=t===`dark`?.5:.35;return(0,F.jsx)(`div`,{role:`img`,"aria-label":i??Ht(e),style:o?{width:`100%`,height:`100%`,minHeight:0,flex:`1 1 auto`,display:`flex`,flexDirection:`column`}:{width:`100%`,height:r},children:(0,F.jsx)(`div`,{"aria-hidden":`true`,style:{width:`100%`,height:`100%`},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,children:(0,F.jsxs)(re,{data:g,children:[(0,F.jsx)(E,{stroke:`var(--chart-grid)`,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`x`,type:`number`,domain:a??[`dataMin`,`dataMax`],allowDataOverflow:!!a,tickFormatter:At,tick:{fontSize:11}}),(0,F.jsx)(T,{tickFormatter:e=>W(e,_,v),tick:{fontSize:11},width:70}),(0,F.jsx)(m,{content:(0,F.jsx)(Ut,{formatter:_,unitSuffix:v})}),(0,F.jsx)(ce,{}),c.map((e,t)=>(0,F.jsx)(y,{type:`monotone`,dataKey:e.key,name:e.label,stackId:`1`,stroke:e.color??l[t%l.length],strokeWidth:s?2:1,fill:s?`none`:e.color??l[t%l.length],fillOpacity:s?0:b,connectNulls:!1},e.key)),e.ceiling?(0,F.jsx)(D,{type:`monotone`,dataKey:`__ceiling__`,name:e.ceiling.label,stroke:`#8b949e`,strokeWidth:2,strokeDasharray:`6 3`,dot:!1}):null]})})})})}function Gt(e){let[t,n]=(0,P.useState)(null);return{isActive:(0,P.useCallback)(e=>t===null||t.has(e),[t]),handleClick:(0,P.useCallback)((t,r)=>{n(n=>{if(r){if(n===null)return new Set(e.filter(e=>e!==t));let r=new Set(n);if(r.has(t)){if(r.delete(t),r.size===0)return null}else if(r.add(t),r.size===e.length)return null;return r}return n!==null&&n.size===1&&n.has(t)?null:new Set([t])})},[e]),activeValues:(0,P.useMemo)(()=>t===null?e:e.filter(e=>t.has(e)),[t,e])}}function Kt({values:e,isActive:t,onClick:n,colorFor:r,ariaLabel:i=`Type filter`}){return e.length===0?null:(0,F.jsx)(`div`,{role:`group`,"aria-label":i,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:e.map(e=>{let i=t(e),a=r?r(e):`var(--color-text-secondary)`;return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":i,"data-testid":`type-filter-chip`,"data-value":e,title:`Click to solo · Ctrl-click to toggle`,onClick:t=>n(e,t.ctrlKey||t.metaKey),className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:{color:a,opacity:i?1:.55},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:a}}),(0,F.jsx)(`span`,{children:e})]},e)})})}function K({spec:e,typeField:t,records:n,timeRange:r,nodes:i,theme:a,viewMode:o=`aggregate`,fillParent:s}){let[c,l]=(0,P.useState)(o===`per-node`?`node`:`type`),u=(0,P.useMemo)(()=>{let e=new Set;for(let r of n){let n=r[t];typeof n==`string`&&e.add(n)}return[...e].sort()},[n,t]),{isActive:d,handleClick:f}=Gt(u),{isActive:p,handleLegendClick:m}=z(i),h=u.length>0&&u.every(d),g=i.every(e=>p(e)),_=!(h&&g),v=(0,P.useMemo)(()=>n.filter(e=>{let n=e[t];return!(typeof n==`string`&&!d(n)||typeof e.node==`string`&&!p(e.node))}),[n,t,d,p]),y=(0,P.useMemo)(()=>c!==`node`||e.series.kind!==`groupBy`?e:{...e,series:{...e.series,dimension:`node`}},[e,c]),b=(0,P.useMemo)(()=>H(y,v,r,i,{snapToPeriod:!0}),[y,v,r,i]),x=(0,P.useMemo)(()=>({...b,series:b.series.map(e=>({...e,color:e.color??(c===`node`?L(e.key,i):ht(e.key,u))}))}),[b,c,i,u]),S=(0,P.useMemo)(()=>c===`grid`?i.filter(p).map(t=>{let n=H(e,v.filter(e=>e.node===t),r,[t],{snapToPeriod:!0});return{title:t,data:{...n,series:n.series.map(e=>({...e,color:e.color??ht(e.key,u)}))},yAxis:e.yAxis}}):null,[c,i,p,v,e,r,u]),C=i.length>1,w=[r.startTime,r.endTime];return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(Kt,{values:u,isActive:d,onClick:f,colorFor:e=>ht(e,u),ariaLabel:t===`type`?`Traffic type`:t===`database`?`Database`:`Protocol`}),C&&(0,F.jsx)(Jt,{stackBy:c,onChange:l}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:c===`grid`&&S?(0,F.jsx)(zt,{panels:S,theme:a,xDomain:w,fillParent:s}):(0,F.jsx)(Wt,{data:x,theme:a,yAxis:e.yAxis,xDomain:w,fillParent:s,lineOnly:_})}),i.length>0&&(0,F.jsx)(R,{nodeIds:i,isActive:p,onClickNode:m})]})}var qt=[{value:`type`,label:`Type`},{value:`node`,label:`Node`},{value:`grid`,label:`Per-node grid`}];function Jt({stackBy:e,onChange:t}){let n=Math.max(0,qt.findIndex(t=>t.value===e)),r=e=>{e.key!==`ArrowRight`&&e.key!==`ArrowLeft`&&e.key!==`ArrowDown`&&e.key!==`ArrowUp`||(e.preventDefault(),t(qt[(n+(e.key===`ArrowRight`||e.key===`ArrowDown`?1:-1)+qt.length)%qt.length].value))};return(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Stack by`,className:`flex flex-wrap items-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:[(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:`Stack by:`}),qt.map((i,a)=>{let o=e===i.value;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":o,tabIndex:a===n?0:-1,onKeyDown:r,"data-testid":`stack-by-button`,"data-value":i.value,onClick:()=>t(i.value),className:`inline-flex items-center cursor-pointer border-none bg-transparent p-0 text-(--color-text-secondary)`,style:{opacity:o?1:.55},children:i.label},i.value)})]})}var Yt={title:`Messages received by type (inner)`,description:`Inbound message rate — cluster total across nodes. Internal spec used by mqtt-traffic-received.recompute; not registered.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`count`,label:`messages/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Xt={id:`mqtt-traffic-received`,title:`Messages received by type`,subtitle:`Inbound message rate. Type chips solo / Ctrl-toggle; viewMode flips type/node stack.`,tab:`traffic`,sourceMetric:`bytes-received`,recompute:(e,t,n,r)=>{let i=(r??`per-node`)===`per-node`,a=Yt;return i&&Yt.series.kind===`groupBy`&&(a={...Yt,series:{...Yt.series,dimension:`node`}}),H(a,e,t,n,{snapToPeriod:!0})},Renderer:e=>(0,F.jsx)(K,{spec:Yt,typeField:`type`,...e}),primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Zt={title:`Messages sent by type (inner)`,description:`Outbound message rate — cluster total across nodes. Internal spec used by mqtt-traffic-sent.recompute; not registered.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`count`,label:`messages/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Qt={id:`mqtt-traffic-sent`,title:`Messages sent by type`,subtitle:`Outbound message rate. Type chips solo / Ctrl-toggle; viewMode flips type/node stack.`,tab:`traffic`,sourceMetric:`bytes-sent`,recompute:(e,t,n,r)=>{let i=(r??`per-node`)===`per-node`,a=Zt;return i&&Zt.series.kind===`groupBy`&&(a={...Zt,series:{...Zt.series,dimension:`node`}}),H(a,e,t,n,{snapToPeriod:!0})},Renderer:e=>(0,F.jsx)(K,{spec:Zt,typeField:`type`,...e}),primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},$t=`var(--color-text-secondary)`;function en({dimensionValues:e,selected:t,onSelect:n,otherKey:r,colorFor:i,ariaLabel:a=`Dimension selector`}){let o=(0,P.useRef)([]);(0,P.useEffect)(()=>{o.current=o.current.slice(0,e.length)},[e.length]);let s=e.indexOf(t),c=s>=0?s:0;function l(t,r){if(t.key===`Enter`||t.key===` `){t.preventDefault(),n(e[r]);return}if(t.key!==`ArrowLeft`&&t.key!==`ArrowRight`&&t.key!==`ArrowDown`&&t.key!==`ArrowUp`)return;t.preventDefault();let i=e.length;if(i===0)return;let a=r;(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(a=(r+1)%i),(t.key===`ArrowLeft`||t.key===`ArrowUp`)&&(a=(r-1+i)%i),o.current[a]?.focus(),n(e[a])}return e.length===0&&!r?null:(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":a,"data-testid":`dimension-chip-row`,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:[e.map((e,r)=>{let a=e===t,s=i?i(e):$t;return(0,F.jsxs)(`button`,{ref:e=>{o.current[r]=e},type:`button`,role:`radio`,"aria-checked":a,tabIndex:r===c?0:-1,"data-testid":`dimension-chip`,"data-value":e,title:`Click to select`,onKeyDown:e=>l(e,r),onClick:()=>n(e),className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:{color:s,opacity:a?1:.55},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:s}}),(0,F.jsx)(`span`,{children:e})]},e)}),r&&(0,F.jsxs)(`span`,{"data-testid":`dimension-chip`,"data-value":r,"aria-disabled":`true`,title:`Aggregate of smaller buckets; not selectable.`,className:`inline-flex items-center gap-1.5 cursor-not-allowed`,style:{color:$t,opacity:.4},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:$t}}),(0,F.jsx)(`span`,{children:r})]})]})}function tn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function nn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,yAxis:a,thresholds:o,compute:s,fillParent:c}){let l=t?[t.startTime,t.endTime]:void 0,u=i===`per-node`,d=(0,P.useMemo)(()=>{let t=new Map;for(let n of e){let e=n.path;if(typeof e!=`string`)continue;let r=n.count,i=typeof r==`number`&&Number.isFinite(r)?r:0;t.set(e,(t.get(e)??0)+i)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e)},[e]),[f,p]=(0,P.useState)(``),m=d.includes(f)?f:u?d[0]??``:``,h=(0,P.useMemo)(()=>s(e,{perNode:u,selectedPath:m||null}),[e,u,m,s]),{isActive:g,handleLegendClick:_}=z(n),v=(0,P.useMemo)(()=>({...h,thresholds:o??h.thresholds,series:h.series.map(e=>u?{...e,label:tn(e.key),color:L(e.key,n)}:e).filter(e=>!u||g(e.key))}),[h,u,n,g,o]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[d.length>0&&(0,F.jsx)(en,{dimensionValues:d,selected:m,onSelect:p,ariaLabel:`Path`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:d.length>0?8:0},children:(0,F.jsx)(G,{data:v,theme:r,yAxis:a,xDomain:l,fillParent:c,hideLegend:u})}),u&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:g,onClickNode:_})]})}function rn(e,t,n){let r=new Map;for(let t of e){let e=typeof t.path==`string`?t.path:null;if(!e||typeof t.time!=`number`||!Number.isFinite(t.time))continue;let n=typeof t.count==`number`&&Number.isFinite(t.count)?t.count:0,i=typeof t.period==`number`&&t.period>0?t.period:6e4,a=r.get(e);a||(a=new Map,r.set(e,a));let o=a.get(t.time);o||(o={sumCount:0,period:i},a.set(t.time,o)),o.sumCount+=n}return{series:[...r.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e),r=n.period/1e3;return{x:e,y:r>0?n.sumCount/r:null,count:n.sumCount}})}))}}function an(e,{perNode:t,selectedPath:n}){if(t&&n){let t=new Map;for(let r of e){if(r.path!==n||typeof r.time!=`number`||!Number.isFinite(r.time))continue;let e=typeof r.node==`string`?r.node:`_no_node`,i=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:0,a=typeof r.period==`number`&&r.period>0?r.period:6e4,o=t.get(e);o||(o=new Map,t.set(e,o));let s=o.get(r.time);s||(s={sumCount:0,period:a},o.set(r.time,s)),s.sumCount+=i}return{series:[...t.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e),r=n.period/1e3;return{x:e,y:r>0?n.sumCount/r:null,count:n.sumCount}})}))}}return rn(n?e.filter(e=>e.path===n):e,{startTime:0,endTime:2**53-1},[])}var on={id:`request-rate`,title:`Request rate (req/s)`,subtitle:`Per-path req/s. Chip selects path; viewMode flips per-node lines / cluster aggregate.`,tab:`requests`,sourceMetric:`duration`,recompute:rn,Renderer:({records:e,timeRange:t,nodes:n,theme:r,viewMode:i})=>(0,F.jsx)(nn,{records:e,timeRange:t,nodes:n,theme:r,viewMode:i,yAxis:{unit:`/s`,formatter:`count-si`},compute:an}),primitive:`line`,yAxis:{unit:`/s`,formatter:`count-si`}};function sn(e,t,n){let r=new Map;for(let t of e){let e=typeof t.database==`string`?t.database:null;if(!e)continue;let n=typeof t.id==`number`?t.id:typeof t.time==`number`?t.time:null;if(n===null)continue;let i=typeof t.node==`string`?t.node:`_no_node`,a=typeof t.transactionLog==`number`&&Number.isFinite(t.transactionLog)?t.transactionLog:null;if(a===null)continue;let o=r.get(e);o||(o=new Map,r.set(e,o));let s=o.get(i);s||(s=[],o.set(i,s)),s.push({time:n,logBytes:a})}let i=6e4,a=[];for(let[e,t]of r.entries()){let n=new Map;for(let e of t.values()){e.sort((e,t)=>e.time-t.time);for(let t=1;t<e.length;t++){let r=e[t-1],a=e[t],o=a.time-r.time;if(o<=0)continue;let s=a.logBytes-r.logBytes;if(!Number.isFinite(s)||s<0)continue;let c=s*1e3/o;if(!Number.isFinite(c))continue;let l=o>=i?Math.round(a.time/i)*i:a.time;n.set(l,(n.get(l)??0)+c)}}let r=[...n.keys()].sort((e,t)=>e-t).map(e=>({x:e,y:n.get(e)}));a.push({key:e,label:e,points:r})}return{series:a}}var cn={"mqtt-traffic-sent":Qt,"mqtt-traffic-received":Xt,"request-rate":on,"error-rate":ft,"transaction-log-growth":{id:`transaction-log-growth`,title:`Transaction log growth`,subtitle:"Per-database transaction-log write rate (bytes/sec) — derived from `transactionLog` deltas in the database-size response.",tab:`storage`,sourceMetric:`database-size`,recompute:sn,primitive:`line`,yAxis:{unit:`/s`,formatter:`bytes-si`}}},ln={title:`Bytes received by type`,description:`Inbound byte rate (count × mean) — cluster total. Type chips solo / Ctrl-toggle.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:{kind:`op`,op:`*`,left:{kind:`ref`,field:`count`},right:{kind:`ref`,field:`mean`}},label:`bytes/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:`/s`,formatter:`bytes-si`}};function un(e){return(0,F.jsx)(K,{spec:ln,typeField:`type`,...e})}var dn={title:`Bytes sent by type`,description:`Outbound byte rate (count × mean) — cluster total. Type chips solo / Ctrl-toggle.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:{kind:`op`,op:`*`,left:{kind:`ref`,field:`count`},right:{kind:`ref`,field:`mean`}},label:`bytes/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:`/s`,formatter:`bytes-si`}};function fn(e){return(0,F.jsx)(K,{spec:dn,typeField:`type`,...e})}var pn=`var(--color-text-secondary)`;function mn({dimensionValues:e,selected:t,onSelect:n,otherKey:r,colorFor:i,ariaLabel:a=`Dimension selector`}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(0),f=(0,P.useId)(),p=(0,P.useId)(),m=(0,P.useRef)(null),h=(0,P.useRef)(null),g=(0,P.useRef)(null),_=e.filter(e=>e.toLowerCase().includes(c.toLowerCase()));(0,P.useEffect)(()=>{o?h.current?.focus():l(``)},[o]),(0,P.useEffect)(()=>{if(!o)return;let e=e=>{let t=e.target;t&&(g.current?.contains(t)||m.current?.contains(t)||s(!1))},t=e=>{e.key===`Escape`&&(s(!1),m.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,P.useEffect)(()=>{d(0)},[c]);function v(e){n(e),s(!1),m.current?.focus()}function y(e){if(e.key===`Escape`){e.preventDefault(),s(!1),m.current?.focus();return}if(e.key===`ArrowDown`){e.preventDefault(),d(e=>Math.min(e+1,Math.max(0,_.length-1)));return}if(e.key===`ArrowUp`){e.preventDefault(),d(e=>Math.max(0,e-1));return}e.key===`Enter`&&_[u]!==void 0&&(e.preventDefault(),v(_[u]))}return(0,F.jsxs)(`div`,{className:`relative pt-3`,children:[(0,F.jsxs)(`button`,{ref:m,type:`button`,"aria-label":a,"aria-expanded":o,"aria-controls":f,"aria-haspopup":`listbox`,onClick:()=>s(e=>!e),className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-primary)`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:i?i(t):pn}}),t||`— select —`,(0,F.jsx)(`span`,{"aria-hidden":!0,children:`▾`})]}),o&&(0,F.jsxs)(`div`,{ref:g,className:`absolute z-10 mt-1 w-72 rounded-md border border-(--color-border) bg-(--color-surface) p-2 shadow-lg`,children:[(0,F.jsx)(`input`,{ref:h,role:`combobox`,type:`text`,"aria-label":`Filter ${a}`,"aria-expanded":o,"aria-controls":f,"aria-autocomplete":`list`,"aria-activedescendant":_[u]===void 0?``:`${p}-${u}`,value:c,onChange:e=>l(e.target.value),onKeyDown:y,placeholder:`Filter…`,className:`mb-2 w-full rounded border border-(--color-border) px-2 py-1 text-xs`}),_.length===0&&(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`px-2 py-1 text-xs text-(--color-text-secondary)`,children:`No matches`}),(0,F.jsx)(`ul`,{id:f,role:`listbox`,className:`max-h-56 overflow-auto`,children:_.map((e,n)=>{let r=e===t,a=n===u,o=i?i(e):pn;return(0,F.jsxs)(`li`,{id:`${p}-${n}`,role:`option`,"aria-selected":r,"data-active":a?`true`:void 0,onMouseDown:t=>{t.preventDefault(),v(e)},className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs ${a?`bg-(--color-surface-alt)`:``} ${r?`font-semibold`:``}`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:o}}),(0,F.jsx)(`span`,{className:`truncate`,children:e})]},e)})}),r&&(0,F.jsxs)(`div`,{className:`mt-2 border-t border-(--color-border) pt-2 text-xs text-(--color-text-secondary)/60`,title:`Aggregate of smaller buckets; not selectable.`,children:[r,` (aggregate; not selectable)`]})]})]})}var hn=`Other`,gn=12;function _n(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function q({spec:e,records:t,timeRange:n,nodes:r,theme:i,ariaLabel:a=`Dimension`,viewMode:o=`per-node`,fillParent:s}){let c=o===`per-node`,l=e.quantileSelector?.fields,[u,d]=(0,P.useState)(e.quantileSelector?.default??``),f=l?.some(e=>e.field===u)?u:e.quantileSelector?.default??``,p=(0,P.useMemo)(()=>{if(!l||f===``||e.series.kind!==`groupBy`)return e;let t=l.find(e=>e.field===f);return t?{...e,series:{...e.series,field:{...e.series.field,field:t.field,label:t.label}}}:e},[e,l,f]),m=(0,P.useMemo)(()=>H(p,t,n,r,{perNode:c,snapToPeriod:!0}),[p,t,n,r,c]),h=(0,P.useMemo)(()=>{let e=new Set;for(let t of m.series){if(t.key===hn)continue;let n=t.key.indexOf(`|`);e.add(n===-1?t.key:t.key.slice(0,n))}return[...e]},[m.series]),g=m.series.some(e=>e.key===hn),[_,v]=(0,P.useState)(()=>h[0]??``),y=h.includes(_)?_:h[0]??``,{isActive:b,handleLegendClick:x}=z(r),S=(0,P.useMemo)(()=>{let e=`${y}|`,t=m.series.filter(t=>t.key===y||t.key.startsWith(e)).map(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n?{...e,label:_n(n),color:L(n,r)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||b(n)});return{...m,series:t}},[m,y,r,b]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[e.quantileSelector&&l&&l.length>1&&(0,F.jsx)(`div`,{role:`radiogroup`,"aria-label":`Quantile`,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:l.map(e=>{let t=e.field===f;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,"data-testid":`quantile-button`,"data-value":e.field,onClick:()=>d(e.field),className:`inline-flex items-center cursor-pointer border-none bg-transparent p-0 text-(--color-text-secondary)`,style:{opacity:t?1:.3},children:e.label},e.field)})}),h.length>gn?(0,F.jsx)(mn,{dimensionValues:h,selected:y,onSelect:v,otherKey:g?hn:void 0,ariaLabel:a}):(0,F.jsx)(en,{dimensionValues:h,selected:y,onSelect:v,otherKey:g?hn:void 0,ariaLabel:a}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:S,theme:i,yAxis:e.yAxis,xDomain:[n.startTime,n.endTime],fillParent:s,hideLegend:c})}),c&&r.length>0&&(0,F.jsx)(R,{nodeIds:r,isActive:b,onClickNode:x})]})}var vn={title:`Cache hit rate`,description:`Per-path cache-hit ratio (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,series:{kind:`groupBy`,dimension:`path`,field:{field:`ratio`,label:`hit ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`,domain:[0,1]}};function yn(e){return(0,F.jsx)(q,{spec:vn,...e,ariaLabel:`Path`})}var J=[{field:`p1`,label:`p1`},{field:`p10`,label:`p10`},{field:`p25`,label:`p25`},{field:`median`,label:`p50`},{field:`p75`,label:`p75`},{field:`p90`,label:`p90`},{field:`p95`,label:`p95`},{field:`p99`,label:`p99`},{field:`p999`,label:`p999`}],bn={title:`Cache miss resolution (p95)`,description:`Per-path time-to-resolve a cache miss (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 resolution (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function xn(e){return(0,F.jsx)(q,{spec:bn,...e,ariaLabel:`Path`})}var Sn=`pathMethod`,Cn=` · `,wn={title:`Connection success ratio`,description:`Per-(path, method) connection ratio (count-weighted-mean). MQTT thresholds: connect ≥0.99, disconnect ≥0.2.`,tab:`traffic`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:Sn,field:{field:`ratio`,label:`success ratio`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:100,suppressBelow:500},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.99,label:`connect`,direction:`below-is-bad`,minCount:1e3,scope:{path:`mqtt`,method:`connect`}},{value:.2,label:`disconnect`,direction:`below-is-bad`,minCount:500,scope:{path:`mqtt`,method:`disconnect`}}]};function Tn(e,t){return typeof e!=`string`&&typeof e!=`number`||typeof t!=`string`&&typeof t!=`number`?null:`${e}${Cn}${t}`}function En(e){let t=[];for(let n of e){let e=n.path,r=n.method,i=Tn(e,r);if(i===null)continue;let a=n.total,o=n.count,s=a===0&&typeof o==`number`&&o>0;t.push({...n,[Sn]:i,ratio:s?null:n.ratio})}return t}function Dn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function On({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,s=(0,P.useMemo)(()=>En(e),[e]),c=(0,P.useMemo)(()=>H(wn,s,t,n,{perNode:o,snapToPeriod:!0}),[s,t,n,o]),l=(0,P.useMemo)(()=>{let e=new Set;for(let t of c.series){let n=t.key.indexOf(`|`);e.add(n===-1?t.key:t.key.slice(0,n))}return[...e]},[c.series]),[u,d]=(0,P.useState)(()=>l[0]??``),f=l.includes(u)?u:l[0]??``,p=(0,P.useMemo)(()=>{if(!f)return null;let[e,t]=f.split(Cn);return{path:e,method:t}},[f]),{isActive:m,handleLegendClick:h}=z(n),g=(0,P.useMemo)(()=>{function e(e){if(!p)return!1;if(!e.scope)return!0;for(let[t,n]of Object.entries(e.scope))if(p[t]!==n)return!1;return!0}let t=`${f}|`,r=c.series.filter(e=>e.key===f||e.key.startsWith(t)).map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Dn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||m(n)});return{...c,series:r,thresholds:(c.thresholds??[]).filter(e)}},[c,f,p,n,m]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:l,selected:f,onSelect:d,ariaLabel:`Path · method`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:g,theme:r,yAxis:wn.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:m,onClickNode:h})]})}var kn={title:`Connections`,description:`Active sessions by type — chips solo / Ctrl-toggle. viewMode flips type/node stack.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`connections`,label:`connections`,aggregator:{temporal:`max`,crossNode:`sum`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`max`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:``,formatter:`count-si`}};function An(e){return(0,F.jsx)(K,{spec:kn,typeField:`type`,...e})}var jn={title:`CPU — by scope (harper vs user)`,description:`Per-path CPU utilization (count-weighted-mean) — chip selector picks scope; quantile selector picks percentile.`,tab:`health`,primaryDimension:`path`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`CPU %`}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},quantileSelector:{fields:J,default:`p95`}};function Mn(e){return(0,F.jsx)(q,{spec:jn,...e,ariaLabel:`Scope`})}var Nn={title:`Database size`,description:`Per-database size in bytes — chips solo / Ctrl-toggle databases; node legend filters by node.`,tab:`storage`,primaryDimension:`database`,series:{kind:`groupBy`,dimension:`database`,field:{field:`size`,label:`size (bytes)`}},timestamp:`id`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` B`,formatter:`bytes-si`}};function Pn(e){return(0,F.jsx)(K,{spec:Nn,typeField:`database`,...e,viewMode:e.viewMode??`aggregate`})}var Fn={title:`DB message p95`,description:`Per-table DB message p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 message (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function In(e){return(0,F.jsx)(q,{spec:Fn,...e,ariaLabel:`Table`})}var Ln={title:`DB read p95`,description:`Per-table DB read p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 read (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Rn(e){return(0,F.jsx)(q,{spec:Ln,...e,ariaLabel:`Table`})}var zn={title:`DB write p95`,description:`Per-table DB write p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 write (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Bn(e){return(0,F.jsx)(q,{spec:zn,...e,ariaLabel:`Table`})}var Vn={title:`Request duration (p95)`,description:`Per-path request duration p95 (count-weighted-mean) — top 10 paths + Other bucket.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 duration (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Hn(e){return(0,F.jsx)(q,{spec:Vn,...e,ariaLabel:`Path`})}var Y=[{key:`utilization`,label:`Utilization`,field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`active`},right:{kind:`op`,op:`+`,left:{kind:`ref`,field:`active`},right:{kind:`ref`,field:`idle`}}},yAxis:{unit:``,formatter:`percent`}},{key:`taskQueueLatency`,label:`Queue lag`,field:`taskQueueLatency`,yAxis:{unit:``,formatter:`ms`}},{key:`active`,label:`Active time`,field:`active`,yAxis:{unit:``,formatter:`ms`}},{key:`idle`,label:`Idle time`,field:`idle`,yAxis:{unit:``,formatter:`ms`}}],Un=Y.map(e=>e.key),Wn={title:`Main thread utilization`,description:`Per-node main-thread metrics — chip selector picks utilization / queue lag / active time / idle time.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[{field:Y[0].field,label:Y[0].label}]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`mean`},primitive:`line`,yAxis:Y[0].yAxis,layout:{colSpan:2}};function Gn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Kn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,[s,c]=(0,P.useState)(Y[0].key),l=Un.includes(s)?s:Y[0].key,u=Y.find(e=>e.key===l),d=(0,P.useMemo)(()=>H({...Wn,series:{kind:`field`,fields:[{field:u.field,label:u.label}]},yAxis:u.yAxis},e,t,n,{perNode:o,snapToPeriod:!0}),[u,e,t,n,o]),{isActive:f,handleLegendClick:p}=z(n),m=(0,P.useMemo)(()=>({...d,series:d.series.map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Gn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||f(n)})}),[d,n,f]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:Un.map(e=>Y.find(t=>t.key===e).label),selected:u.label,onSelect:e=>{let t=Y.find(t=>t.label===e);t&&c(t.key)},ariaLabel:`Main thread metric`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:m,theme:r,yAxis:u.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:f,onClickNode:p})]})}var qn=[{field:`heapUsed`,label:`heap used`},{field:`heapTotal`,label:`heap total`},{field:`external`,label:`external`},{field:`arrayBuffers`,label:`arrayBuffers`}],Jn={title:`Process memory`,description:`Per-node V8 memory — chip selector picks the field. Default heap used.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[...qn]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`mean`},primitive:`line`,yAxis:{unit:` B`,formatter:`bytes-si`}};function Yn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}var Xn=qn.map(e=>e.label);function Zn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,[s,c]=(0,P.useState)(qn[0].label),l=Xn.includes(s)?s:qn[0].label,u=qn.find(e=>e.label===l),d=(0,P.useMemo)(()=>H({...Jn,series:{kind:`field`,fields:[u]}},e,t,n,{perNode:o,snapToPeriod:!0}),[u,e,t,n,o]),{isActive:f,handleLegendClick:p}=z(n),m=(0,P.useMemo)(()=>({...d,series:d.series.map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Yn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||f(n)})}),[d,n,f]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:Xn,selected:l,onSelect:c,ariaLabel:`Memory field`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:m,theme:r,yAxis:Jn.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:f,onClickNode:p})]})}function Qn(e,t,n,r,i,a){if(t<=0)return a;let o=e-n-r*Math.max(0,t-1),s=Math.floor(o/t);return Math.max(i,Math.min(a,s))}var $n=[`#fef3c7`,`#fcd34d`,`#f59e0b`,`#dc2626`,`#7f1d1d`],er=[`#713f12`,`#b45309`,`#d97706`,`#f59e0b`,`#fef3c7`];function tr(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function nr(e){let t=e.replace(`#`,``),n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return .2126*tr(n)+.7152*tr(r)+.0722*tr(i)}function rr(e){let t=e.replace(`#`,``);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function ir(e,t,n){let r=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function ar(e,t){if(t<=0)return e[0];if(t>=1)return e[e.length-1];let n=t*(e.length-1),r=Math.floor(n),i=n-r,[a,o,s]=rr(e[r]),[c,l,u]=rr(e[r+1]);return ir(a+(c-a)*i,o+(l-o)*i,s+(u-s)*i)}function or(e,t,n){if(!e||e.value===null||e.value===void 0)return`absent`;let r=e.count??0;return r<t?`suppress`:r<n?`grey`:`ok`}function sr(e,t){return e.length>t?e.slice(0,t-1)+`…`:e}function cr(e,t,n,r,i,a,o){let s=`${e} → ${t}: `,c=o?` (approx)`:``;if(r===`absent`)return`${s}no data`;if(r===`suppress`)return`${s}insufficient samples (n<${a}), value hidden`;let l=n?.value??0,u=n?.count??0;return r===`grey`?`${s}${l} ${i} p95 (approx, low-confidence: ${u} samples below threshold)`:`${s}${l} ${i} p95${c}, ${u} samples`}function lr({stops:e,vmin:t,vmax:n,width:r,axis:i,approx:a}){let o=(0,P.useId)(),s=i?.unit??``,c=e=>W(e,i?.formatter),l=(t+n)/2,u=Math.max(200,Math.min(r,480));return(0,F.jsxs)(`svg`,{role:`img`,"aria-label":`${a?`p95 latency (count-weighted-mean, approx)`:`p95 latency`}: ${c(t)}–${c(n)} ${s}. Higher value = worse latency.`,width:u+80,height:40,style:{overflow:`visible`},children:[(0,F.jsx)(`defs`,{children:(0,F.jsx)(`linearGradient`,{id:o,x1:`0%`,x2:`100%`,y1:`0%`,y2:`0%`,children:e.map((t,n)=>(0,F.jsx)(`stop`,{offset:`${n/(e.length-1)*100}%`,stopColor:t},t+n))})}),(0,F.jsx)(`text`,{x:0,y:14,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:`low`}),(0,F.jsx)(`rect`,{x:30,y:0,width:u,height:12,fill:`url(#${o})`,"aria-hidden":`true`}),(0,F.jsx)(`text`,{x:30+u+4,y:14,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:`high`}),(0,F.jsx)(`text`,{x:30,y:30,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:c(t)}),(0,F.jsx)(`text`,{x:30+u/2,y:30,fontSize:10,fill:`currentColor`,textAnchor:`middle`,"aria-hidden":`true`,children:c(l)}),(0,F.jsx)(`text`,{x:30+u,y:30,fontSize:10,fill:`currentColor`,textAnchor:`end`,"aria-hidden":`true`,children:c(n)})]})}var ur=40,dr=80,X=4,fr=72,Z=200;function pr({data:e,theme:t,title:n,height:r}){let i=(0,P.useId)(),a=(0,P.useId)(),o=(0,P.useId)(),s=e.confidence?.greyBelow??0,c=e.confidence?.suppressBelow??0,l=t===`dark`?er:$n,u=e.approx===!0,d=e.axis?.unit??``,f=(0,P.useMemo)(()=>{let t=new Map;for(let n of e.cells)t.set(`${n.row}|${n.col}`,n);return t},[e.cells]),[p,m]=(0,P.useMemo)(()=>{if(e.valueRange)return[e.valueRange.min,e.valueRange.max];let t=1/0,n=-1/0;for(let r of e.cells)r.value!==null&&r.value!==void 0&&Number.isFinite(r.value)&&(r.value<t&&(t=r.value),r.value>n&&(n=r.value));return!Number.isFinite(t)||!Number.isFinite(n)?[0,1]:t===n?[t,t+1]:[t,n]},[e.cells,e.valueRange]),h=e.rows,g=e.cols,_=(0,P.useRef)(null),[v,y]=(0,P.useState)(dr),b=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{y(Qn(_.current?.clientWidth??0,g.length,Z,X,ur,dr))},[g.length]),(0,P.useEffect)(()=>{let e=_.current;if(!e)return;let t=new ResizeObserver(()=>{b.current!==null&&cancelAnimationFrame(b.current),b.current=requestAnimationFrame(()=>{b.current=null;let t=e.clientWidth;y(Qn(t,g.length,Z,X,ur,dr))})});return t.observe(e),()=>{t.disconnect(),b.current!==null&&cancelAnimationFrame(b.current)}},[g.length]);let x=g.length*v+(g.length-1)*X,S=h.length*v+(h.length-1)*X,C=Z+x+8,w=fr+S+8,[ee,te]=(0,P.useState)([0,0]),T=(0,P.useRef)(new Map),E=(0,P.useCallback)((e,t)=>{let n=T.current.get(`${e}|${t}`);n&&(te([e,t]),n.focus())},[]),ne=(0,P.useCallback)((e,t,n)=>{let r=e.key,i=!1,a=t,o=n;r===`ArrowRight`?(i=!0,o=Math.min(g.length-1,n+1)):r===`ArrowLeft`?(i=!0,o=Math.max(0,n-1)):r===`ArrowDown`?(i=!0,a=Math.min(h.length-1,t+1)):r===`ArrowUp`?(i=!0,a=Math.max(0,t-1)):r===`Home`?(i=!0,o=0):r===`End`?(i=!0,o=g.length-1):r===`PageUp`?(i=!0,a=Math.max(0,t-5)):r===`PageDown`&&(i=!0,a=Math.min(h.length-1,t+5)),i&&(e.preventDefault(),e.stopPropagation(),(a!==t||o!==n)&&E(a,o))},[h.length,g.length,E]),re=e=>e.startsWith(`#`)?nr(e)>.5?`#000000`:`#ffffff`:`#000000`;return(0,F.jsxs)(`div`,{style:{position:`relative`},children:[e.skippedRecordsCount>0?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning)`,background:`color-mix(in srgb, var(--color-warning) 12%, transparent)`,color:`currentColor`},children:`${e.skippedRecordsCount} record(s) omitted — source node unrecognized (cluster node list may be outdated).`},e.skippedRecordsCount):null,(0,F.jsx)(`p`,{id:i,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:n??`Heatmap`}),(0,F.jsx)(`p`,{id:a,"data-testid":`heatmap-desc`,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:`${u?`Cells show count-weighted-mean p95 latency (approx).`:`Cells show p95 latency.`} Cells with fewer than ${c} samples are blank; ${s}–${c-1} render grey.`}),(0,F.jsx)(`div`,{ref:_,style:{width:`100%`,display:`block`,overflowX:`auto`},children:(0,F.jsxs)(`svg`,{role:`grid`,"aria-labelledby":i,"aria-describedby":a,width:C,height:r??w,viewBox:`0 0 ${C} ${w}`,"data-cell-size":v,style:{overflow:`visible`,display:`block`},children:[(0,F.jsx)(`defs`,{children:(0,F.jsxs)(`pattern`,{id:o,patternUnits:`userSpaceOnUse`,width:8,height:8,patternTransform:`rotate(45)`,children:[(0,F.jsx)(`rect`,{width:8,height:8,fill:t===`dark`?`#1f2937`:`#f3f4f6`}),(0,F.jsx)(`line`,{x1:0,y1:0,x2:0,y2:8,stroke:t===`dark`?`#4b5563`:`#9ca3af`,strokeWidth:2})]})}),(0,F.jsxs)(`g`,{role:`row`,children:[(0,F.jsx)(`rect`,{x:0,y:0,width:Z,height:fr,fill:`transparent`,"aria-hidden":`true`}),g.map((e,t)=>{let n=Z+t*(v+X)+v/2,r=fr-8,i=v<56?8:20;return(0,F.jsx)(`g`,{role:`columnheader`,"aria-label":e,children:(0,F.jsxs)(`text`,{x:n,y:r,fontSize:11,textAnchor:`end`,transform:`rotate(-45, ${n}, ${r})`,fill:`currentColor`,children:[sr(e,i),(0,F.jsx)(`title`,{children:e})]})},e)})]}),h.map((e,n)=>{let r=fr+n*(v+X);return(0,F.jsxs)(`g`,{role:`row`,children:[(0,F.jsx)(`g`,{role:`rowheader`,"aria-label":e,children:(0,F.jsxs)(`text`,{x:Z-8,y:r+v/2+4,fontSize:12,textAnchor:`end`,fill:`currentColor`,children:[sr(e,24),(0,F.jsx)(`title`,{children:e})]})}),g.map((i,a)=>{let h=f.get(`${e}|${i}`),g=or(h,s,c),_=Z+a*(v+X),y=r,b=cr(e,i,h,g,d,c,u),x=ee[0]===n&&ee[1]===a,S=`transparent`,C,w=1,E,D=0;g===`absent`?(S=`transparent`,C=`3 3`,E=t===`dark`?`#4b5563`:`#9ca3af`,D=1):g===`suppress`?(S=`url(#${o})`,C=`3 3`,E=t===`dark`?`#4b5563`:`#9ca3af`,D=1):(S=ar(l,m>p?((h?.value??0)-p)/(m-p):0),g===`grey`&&(w=.55,C=`4 2`,E=t===`dark`?`#6b7280`:`#9ca3af`,D=1));let ie=re(g===`ok`||g===`grey`?ar(l,m>p?((h?.value??0)-p)/(m-p):0):`#808080`);return(0,F.jsxs)(`g`,{ref:e=>{e?T.current.set(`${n}|${a}`,e):T.current.delete(`${n}|${a}`)},role:`gridcell`,"aria-label":b,"data-confidence":g,tabIndex:x?0:-1,onKeyDown:e=>ne(e,n,a),onFocus:()=>te([n,a]),style:{outline:`none`,cursor:`default`},children:[(0,F.jsx)(`rect`,{x:_,y,width:v,height:v,rx:4,ry:4,style:{fill:S},opacity:w,stroke:E,strokeWidth:D,strokeDasharray:C,children:(0,F.jsx)(`title`,{children:b})}),x?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`rect`,{x:_-1,y:y-1,width:v+2,height:v+2,rx:5,ry:5,fill:`none`,stroke:ie,strokeWidth:1,pointerEvents:`none`}),(0,F.jsx)(`rect`,{x:_,y,width:v,height:v,rx:4,ry:4,fill:`none`,stroke:`var(--color-accent, #3b82f6)`,strokeWidth:1,pointerEvents:`none`})]}):null]},i)})]},e)})]})}),(0,F.jsx)(`div`,{style:{marginTop:8},children:(0,F.jsx)(lr,{stops:l,vmin:p,vmax:m,width:x,axis:e.axis,approx:u})})]})}function mr(e,t){if(typeof e!=`string`||e.length===0)return null;let n=[...t].sort((e,t)=>t.length-e.length);for(let t of n){if(!e.startsWith(t+`.`))continue;let n=e.slice(t.length+1),r=n.indexOf(`.`);if(r===-1)return null;let i=n.slice(0,r),a=n.slice(r+1);return i.length===0||a.length===0?null:{source:t,database:i,table:a}}let r=e.split(`.`);if(r.length<3)return null;let i=r[r.length-1],a=r[r.length-2],o=r.slice(0,-2).join(`.`);return!o||!a||!i?null:{source:o,database:a,table:i}}var hr={title:`Replication latency`,description:`Source → destination p95 latency, count-weighted-mean across the window. Approximate.`,tab:`replication`,primaryDimension:`path`,subDimension:`node`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 latency`}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`heatmap`,yAxis:{unit:``,formatter:`ms`}};function gr(e,t,n){return e===1?t:n}function _r(e,t,n){let r=0,i=[],a=new Set,o=new Set(t);for(let s of e){let e=mr(typeof s.path==`string`?s.path:``,t);if(!e){r++;continue}o.has(e.source)||a.add(e.source);let c=s[n],l=typeof c==`number`?c:NaN,u=typeof s.count==`number`?s.count:0;if(!Number.isFinite(l)){r++;continue}i.push({source:e.source,destination:s.node,value:l,count:u,time:typeof s.time==`number`?s.time:0})}return{parsed:i,skipped:r,unrecognizedSources:[...a].sort()}}function vr(e,t,n=`p95`){let{parsed:r,skipped:i,unrecognizedSources:a}=_r(e,t,n);if(r.length===0)return{rows:[],cols:[],cells:[],axis:{unit:``,formatter:`ms`},confidence:{greyBelow:40,suppressBelow:100},rowAxisLabel:`Source`,colAxisLabel:`Destination`,skippedRecordsCount:i,unrecognizedSources:a,approx:!0};let o=new Map,s=new Set,c=new Set;for(let e of r){s.add(e.source),c.add(e.destination);let t=`${e.source}|${e.destination}`,n=o.get(t);n||(n={items:[],totalCount:0},o.set(t,n)),n.items.push({value:e.value,count:e.count}),n.totalCount+=e.count}let l=[...s].sort(),u=[...c].sort(),d=!1,f=[];for(let e of l)for(let t of u){let n=o.get(`${e}|${t}`);n?(n.items.length>1&&(d=!0),f.push({row:e,col:t,value:B(`count-weighted-mean`,n.items),count:n.totalCount})):f.push({row:e,col:t,value:null,count:0})}return{rows:l,cols:u,cells:f,axis:{unit:``,formatter:`ms`},confidence:{greyBelow:40,suppressBelow:100},rowAxisLabel:`Source`,colAxisLabel:`Destination`,skippedRecordsCount:i,unrecognizedSources:a,approx:d}}function yr(e,t,n,r,i=`p95`){let a=[];for(let o of e){if(o.node!==n)continue;let e=mr(typeof o.path==`string`?o.path:``,r);if(!e||e.source!==t||typeof o.time!=`number`)continue;let s=o[i],c=typeof s==`number`?s:NaN;if(!Number.isFinite(c))continue;let l=typeof o.count==`number`?o.count:0;a.push({time:o.time,value:c,count:l})}let o=new Map,s=new Map;for(let e of a){let t=o.get(e.time);t||(t=[],o.set(e.time,t)),t.push({value:e.value,count:e.count}),s.set(e.time,(s.get(e.time)??0)+e.count)}let c=!1,l=[...o.keys()].sort((e,t)=>e-t),u=[];for(let e of l){let t=o.get(e);t.length>1&&(c=!0),u.push({x:e,y:B(`count-weighted-mean`,t),count:s.get(e)??0})}return{points:u,approx:c}}var br=12;function xr(e,t,n,r){let i=n.confidence?.greyBelow??0,a=n.confidence?.suppressBelow??1/0,o=[],s=0;for(let c of n.cells){let n=c.count??0;if(n===0)continue;if(n<i){s+=1;continue}let l=yr(e,c.row,c.col,t,r);if(l.points.length===0)continue;let u=`${c.row}→${c.col}`;n<a?o.push({key:u,label:u,points:l.points,approx:l.approx,opacity:.55}):o.push({key:u,label:u,points:l.points,approx:l.approx})}return{seriesData:{series:o},omittedPairsCount:s}}function Sr(e){let{records:t,nodes:n,theme:r,timeRange:i,fillParent:a}=e,[o,s]=(0,P.useState)(`p95`),c=(0,P.useMemo)(()=>vr(t,n,o),[t,n,o]);if(c.rows.length===0||c.cols.length===0)return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(Cr,{data:c,theme:r}),(0,F.jsx)(`div`,{children:`No data in window`})]});let l=c.rows.length*c.cols.length>br;if(c.rows.length<2||c.cols.length<2||l){let{seriesData:e,omittedPairsCount:s}=xr(t,n,c,o),u=c.confidence?.greyBelow??40,d=l?`Too many source-destination pairs for a heatmap — showing as lines.`:`Only one source node emitted data in this window. This is typical for clusters with a single write origin — each line below shows latency from that source to one destination.`,f=e.series.length===0&&s>0,p=e.series.length===0&&s===0,m={marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning, #f59e0b)`,background:r===`dark`?`#1f2937`:`#fffbeb`,color:`currentColor`};return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:4},children:`Showing as lines`}),c.skippedRecordsCount>0?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:c.unrecognizedSources&&c.unrecognizedSources.length>0?`${c.skippedRecordsCount} record(s) omitted (no value for the selected percentile). Sources recovered via heuristic: ${c.unrecognizedSources.join(`, `)}.`:`${c.skippedRecordsCount} record(s) omitted (no value for the selected percentile).`},c.skippedRecordsCount):null,s>0&&!f?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:`${s} source-destination ${gr(s,`pair`,`pairs`)} hidden — fewer than ${u} samples.`},s):null,(0,F.jsx)(`div`,{style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-info, #3b82f6)`,background:r===`dark`?`#0f172a`:`#eff6ff`,color:`currentColor`},children:d}),f?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:`No source-destination pairs cleared the confidence threshold (${u}+ samples). All ${s} ${gr(s,`pair`,`pairs`)} had fewer than ${u} samples in this window.`}):p?(0,F.jsx)(`div`,{children:`No data in window`}):(0,F.jsx)(`div`,{style:{marginTop:20},children:(0,F.jsx)(G,{data:e,theme:r,yAxis:c.axis,height:320,xDomain:[i.startTime,i.endTime],fillParent:a})})]})}return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(wr,{value:o,onChange:s}),(0,F.jsx)(Cr,{data:c,theme:r}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,F.jsx)(pr,{data:c,theme:r,title:`Replication latency`})})]})}function Cr({data:e,theme:t}){let n=e.skippedRecordsCount,r=e.unrecognizedSources??[];if(n===0&&r.length===0)return null;let i=[];return n>0&&i.push(`${n} record${n===1?``:`s`} omitted (no value for the selected percentile).`),r.length>0&&i.push(`Recovered ${r.length} source${r.length===1?``:`s`} not in the cluster snapshot: ${r.join(`, `)}.`),(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning, #f59e0b)`,background:t===`dark`?`#1f2937`:`#fffbeb`,color:`currentColor`},children:i.join(` `)},`${n}-${r.length}`)}function wr({value:e,onChange:t}){return(0,F.jsx)(`div`,{role:`radiogroup`,"aria-label":`Quantile`,className:`flex flex-wrap gap-1 pb-2`,children:J.map(n=>{let r=n.field===e;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r,"data-testid":`quantile-button`,"data-value":n.field,onClick:()=>t(n.field),className:`rounded px-2 py-0.5 text-[11px] ${r?`bg-(--color-accent)/20 text-(--color-text-primary) font-semibold`:`bg-(--color-bg-tertiary) text-(--color-text-secondary) hover:text-(--color-text-primary)`}`,children:n.label},n.field)})})}var Tr={title:`Resource usage`,description:`CPU + I/O + page faults + context switches per node — small-multiples view.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[{field:`cpuUtilization`,label:`Process CPU (cores used)`,aggregator:{temporal:`max`,crossNode:`max`},yAxis:{unit:``,formatter:`cores`}},{field:`fsWrite`,label:`Disk write (B/s)`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`sum`},yAxis:{unit:`/s`,formatter:`bytes-si`}},{field:`majorPageFault`,label:`Major page faults /s`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`max`},yAxis:{unit:`/s`,formatter:`count-si`}},{field:{kind:`op`,op:`+`,left:{kind:`ref`,field:`voluntaryContextSwitches`},right:{kind:`ref`,field:`involuntaryContextSwitches`}},label:`Context switches /s`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`max`},yAxis:{unit:`/s`,formatter:`count-si`}}]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`small-multiples`,yAxis:{unit:``,formatter:`count`},layout:{colSpan:2}},Er={title:`HTTP 200 ratio`,description:`Per-path 2xx ratio (mean across nodes; count-weighted across time). Threshold 99.9%, min count 1000.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`total`},right:{kind:`ref`,field:`count`}},label:`200 ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.999,label:`99.9% SLO`,direction:`below-is-bad`,minCount:1e3}]};function Dr(e){return(0,F.jsx)(q,{spec:Er,...e,ariaLabel:`Path`})}var Or={title:`Storage volume (available)`,description:`Per-node disk available bytes (latest snapshot in window; mean across nodes).`,tab:`storage`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`available`,label:`available (bytes)`}},timestamp:`id`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`mean`},primitive:`line`,yAxis:{unit:` B`,formatter:`bytes-si`}},kr={title:`Request success rate`,description:`Per-path success ratio (count-weighted-mean) — alert when ≥0.001 errors and Σcount ≥1000.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`total`},right:{kind:`ref`,field:`count`}},label:`success ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.999,label:`99.9% SLO`,direction:`below-is-bad`,minCount:1e3}]};function Ar(e){return(0,F.jsx)(q,{spec:kr,...e,ariaLabel:`Path`})}var jr={title:`TLS session reuse ratio`,description:`Fraction of TLS handshakes resumed via session ticket — higher is better.`,tab:`traffic`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`ratio`,label:`reuse ratio`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:20,suppressBelow:50},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.5,label:`50% reuse target`,direction:`below-is-bad`,minCount:50}]},Mr={title:`Transfer duration (p95)`,description:`Per-path transfer p95 (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 transfer (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Nr(e){return(0,F.jsx)(q,{spec:Mr,...e,ariaLabel:`Path`})}var Pr={"replication-latency":{spec:hr,Renderer:Sr},"bytes-sent":{spec:dn,Renderer:fn},"bytes-received":{spec:ln,Renderer:un},"resource-usage":{spec:Tr},connections:{spec:kn,Renderer:An},duration:{spec:Vn,Renderer:Hn},success:{spec:kr,Renderer:Ar},transfer:{spec:Mr,Renderer:Nr},"tls-reused":{spec:jr},connection:{spec:wn,Renderer:On},"cpu-usage":{spec:jn,Renderer:Mn},"db-read":{spec:Ln,Renderer:Rn},"db-write":{spec:zn,Renderer:Bn},"db-message":{spec:Fn,Renderer:In},response_200:{spec:Er,Renderer:Dr},utilization:{spec:{title:`Cluster utilization`,description:`Active / (active + idle) per node — count-weighted-mean across time.`,tab:`health`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`utilization`,label:`utilization`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`max`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`}}},"database-size":{spec:Nn,Renderer:Pn},"storage-volume":{spec:Or},memory:{spec:Jn,Renderer:Zn},"main-thread-utilization":{spec:Wn,Renderer:Kn},"cache-hit":{spec:vn,Renderer:yn},"cache-resolution":{spec:bn,Renderer:xn}},Fr={"request-rate":[`count`,`period`],"error-rate":[`count`,`errors`]};function Ir(e){let t=Fr[e];if(t)return t;if(cn[e])return[];let n=Pr[e];return n?.spec?Lr(n.spec):[]}function Lr(e){let t=new Set,n=e.series,r=!1;if(n.kind===`field`)for(let e of n.fields)zr(e,t),Rr(e.transform)&&(r=!0);else zr(n.field,t),Rr(n.field.transform)&&(r=!0),n.dimension&&n.dimension!==`node`&&t.add(n.dimension);return r&&t.add(`period`),[...t]}function Rr(e){if(!e)return!1;switch(e.kind){case`rate`:return!0;case`compose`:return e.steps.some(Rr);default:return!1}}function zr(e,t){Br(e.field,t)}function Br(e,t){if(typeof e==`string`){t.add(e);return}switch(e.kind){case`ref`:t.add(e.field);return;case`const`:return;case`op`:Br(e.left,t),Br(e.right,t);return}}var Vr=new Set([`time`,`node`,`id`,`period`,`metric`,`count`,`threadId`,`path`,`method`,`type`,`database`,`table`,`source`]),Hr=8;function Ur(e){let t=new Map;for(let n of e)for(let e of Object.keys(n))Vr.has(e)||typeof n[e]==`number`&&Number.isFinite(n[e])&&t.set(e,(t.get(e)??0)+1);let n=Math.max(1,Math.floor(e.length/2));return[...t.entries()].filter(([,e])=>e>=n).map(([e])=>e)}function Wr({metric:e,records:t,theme:n,hint:r}){let i=Ur(t),a=i.slice(0,Hr),o=i.length-a.length,s=a.map(e=>({title:e,data:{series:[{key:e,label:e,points:t.filter(t=>typeof t[e]==`number`).map(t=>({x:typeof t.time==`number`?t.time:0,y:t[e]}))}]}})),c=e.replace(/_/g,`-`);return(0,F.jsxs)(`div`,{children:[r&&(0,F.jsx)(`div`,{role:`status`,style:{fontSize:12,padding:`4px 8px`,marginBottom:8,background:`color-mix(in srgb, var(--color-text-secondary) 10%, transparent)`,color:`var(--color-text-secondary)`,border:`1px solid color-mix(in srgb, var(--color-text-secondary) 30%, transparent)`,borderRadius:4},children:r}),null,(0,F.jsx)(zt,{panels:s,theme:n}),o>0&&(0,F.jsx)(`div`,{style:{fontSize:11,marginTop:4,opacity:.7},children:`… and ${o} more fields not shown. Add a spec at src/lib/metricSpecs/${c}.ts to customize.`})]})}function Gr(e){let t=e.indexOf(`|`);return t===-1?e:e.slice(t+1)}function Kr({data:e,theme:t,yAxis:n,xDomain:r,fillParent:i}){let a=(0,P.useMemo)(()=>{let t=new Set;for(let n of e.series){let e=Gr(n.key);e&&t.add(e)}return[...t].sort()},[e]),{isActive:o,handleLegendClick:s}=z(a);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,F.jsx)(G,{data:(0,P.useMemo)(()=>({...e,series:e.series.filter(e=>{let t=Gr(e.key);return t===null||o(t)}).map(e=>{let t=Gr(e.key);return t?{...e,color:e.color??L(t,a)}:e})}),[e,o,a]),theme:t,yAxis:n,xDomain:r,fillParent:i,hideLegend:!0})}),a.length>0&&(0,F.jsx)(R,{nodeIds:a,isActive:o,onClickNode:s})]})}function qr(e,t,n,r,i,a){switch(e){case`line`:return(0,F.jsx)(Kr,{data:t,theme:n,yAxis:r,xDomain:i,fillParent:a});case`stacked-area`:return(0,F.jsx)(Wt,{data:t,theme:n,yAxis:r,xDomain:i,fillParent:a});case`small-multiples`:throw Error(`small-multiples is dispatched at the spec branch, not via renderPrimitive`);case`heatmap`:throw Error(`heatmap dispatch is via custom Renderer (replication-latency)`);default:throw Error(`Unknown primitive: ${e}`)}}var Jr=class extends P.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`[MetricRenderer] render failed; falling back:`,e)}render(){return this.state.failed?this.props.fallback:this.props.children}};function Yr({metric:e,records:t,window:n,nodes:r,theme:i,viewMode:a,fillParent:o}){let s=(0,F.jsx)(Wr,{metric:e,records:t,window:n,nodes:r,theme:i,hint:`Render failed — showing fallback.`}),c=[n.startTime,n.endTime],l,u=cn[e];if(u)if(u.Renderer)l=(0,F.jsx)(u.Renderer,{records:t,timeRange:n,nodes:r,theme:i,viewMode:a,fillParent:o});else{let e=u.recompute(t,n,r,a);l=qr(u.primitive,e,i,u.yAxis,c,o)}else{let s=Pr[e];if(s?.Renderer)l=(0,F.jsx)(s.Renderer,{records:t,timeRange:n,nodes:r,theme:i,viewMode:a,fillParent:o});else if(s?.spec){let e=(a??`per-node`)===`per-node`;if(s.spec.primitive===`small-multiples`){let a=s.spec,u=a.series;if(u.kind!==`field`)throw Error(`small-multiples requires kind='field' series source`);l=(0,F.jsx)(zt,{panels:u.fields.map(i=>{let o={...a,series:{kind:`field`,fields:[i]},aggregator:{temporal:i.aggregator?.temporal??a.aggregator.temporal,crossNode:i.aggregator?.crossNode??a.aggregator.crossNode}};return{title:i.label,data:H(o,t,n,r,{perNode:e,snapToPeriod:!0}),yAxis:i.yAxis??a.yAxis}}),theme:i,xDomain:c,fillParent:o})}else if(s.spec.primitive===`stacked-area`&&e&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension!==`node`)l=qr(`stacked-area`,H({...s.spec,series:{...s.spec.series,dimension:`node`}},t,n,r,{snapToPeriod:!0}),i,s.spec.yAxis,c,o);else if(s.spec.primitive===`line`&&!e&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension===`node`){let e=s.spec.series,a=H({...s.spec,series:{kind:`field`,fields:[{...e.field,label:`cluster`}]}},t,n,r,{snapToPeriod:!0});l=qr(s.spec.primitive,a,i,s.spec.yAxis,c,o)}else if(s.spec.primitive===`line`&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension!==`node`)l=qr(`line`,H(s.spec,t,n,r,{perNode:!1,snapToPeriod:!0}),i,s.spec.yAxis,c,o);else{let a=H(s.spec,t,n,r,{perNode:e,snapToPeriod:!0});l=qr(s.spec.primitive,a,i,s.spec.yAxis,c,o)}}else l=(0,F.jsx)(Wr,{metric:e,records:t,window:n,nodes:r,theme:i})}return(0,F.jsx)(Jr,{fallback:s,children:l},e)}var Xr=class extends P.Component{state={failed:!1};static getDerivedStateFromError(e){return{failed:!0,message:e instanceof Error?e.message:String(e)}}static getDerivedStateFromProps(e,t){return t.lastResetKey===e.resetKey?null:{failed:!1,message:void 0,lastResetKey:e.resetKey}}componentDidCatch(e){console.error(`[panel:${this.props.metric}] render failed`,e)}render(){return this.state.failed?(0,F.jsxs)(`div`,{className:`rounded-lg border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:[(0,F.jsx)(`div`,{className:`font-medium mb-1`,children:`Panel "${this.props.metric}" is unavailable`}),(0,F.jsx)(`div`,{className:`text-xs opacity-80`,children:this.state.message})]}):this.props.children}};function Q({metric:e,titleOverride:t}){let{timeRange:n}=I();return(0,F.jsx)(Xr,{metric:e,resetKey:`${n.startTime}-${n.endTime}`,children:(0,F.jsx)(Zr,{metric:e,titleOverride:t})})}function Zr({metric:e,titleOverride:t}){let{timeRange:n,bucketMs:r,refreshIntervalMs:i,theme:a,instanceParams:o}=I(),s=cn[e]?.sourceMetric??e,c=Ir(e),{data:l,isLoading:u,isError:d,error:f,isEmpty:p,missingFields:m,refetch:h}=ut({metric:s,startTime:n.startTime,endTime:n.endTime,instanceParams:o,refetchIntervalMs:i,bucketMs:r,requiredFields:c}),g=Pr[e],_=cn[e],v=t??g?.spec?.title??_?.title??e,y=g?.spec?.description??_?.subtitle,b=$r(l),x=(0,P.useRef)(null),S=!u&&!d&&!p,C=(t={fillParent:!1})=>(0,F.jsx)(Yr,{metric:e,records:l,window:n,nodes:b,theme:a,fillParent:t.fillParent});return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:v}),y&&(0,F.jsx)(O,{children:y})]}),S&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:e,title:v,description:y,renderChart:C}),(0,F.jsx)(at,{captureRef:x,exportSlug:e}),(0,F.jsx)(ot,{captureRef:x,exportSlug:e})]})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{ref:x,children:(0,F.jsx)(Qr,{isLoading:u,isError:d,error:f,isEmpty:p,missingFields:m,onRetry:h,children:C()})})})]})}function Qr({isLoading:e,isError:t,error:r,isEmpty:i,missingFields:a,onRetry:o,children:s}){return e?(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`}):t?(0,F.jsxs)(`div`,{className:`h-64 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive flex flex-col items-start justify-center gap-3`,children:[(0,F.jsx)(`div`,{children:`Failed to load: ${r?.message??`unknown error`}`}),(0,F.jsx)(n,{variant:`outline`,size:`sm`,onClick:o,children:`Retry`})]}):i?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:a.length>0?`No data — server response is missing required field(s): ${a.join(`, `)}.`:`No data in the selected time range.`}):(0,F.jsx)(F.Fragment,{children:s})}function $r(e){let t=new Set;for(let n of e)typeof n.node==`string`&&t.add(n.node);return[...t].sort()}var ei=[`db-read`,`db-write`,`db-message`];function ti(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:ei.map(e=>(0,F.jsx)(Q,{metric:e},e))})}var ni=[`resource-usage`,`memory`,`main-thread-utilization`,`cpu-usage`,`utilization`];function ri(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:ni.map(e=>(0,F.jsx)(Q,{metric:e},e))})}function ii({...e}){return(0,F.jsx)(w,{"data-slot":`accordion`,...e})}function ai({className:e,...n}){return(0,F.jsx)(ie,{"data-slot":`accordion-item`,className:t(`border-b last:border-b-0`,e),...n})}function oi({className:e,children:n,...r}){return(0,F.jsx)(ne,{className:`flex`,children:(0,F.jsxs)(h,{"data-slot":`accordion-trigger`,className:t(`focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180`,e),...r,children:[n,(0,F.jsx)(f,{className:`text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200`})]})})}function si({className:e,children:n,...r}){return(0,F.jsx)(oe,{"data-slot":`accordion-content`,className:`data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm`,...r,children:(0,F.jsx)(`div`,{className:t(`pt-0 pb-4`,e),children:n})})}function ci({entityId:e,instanceClient:t}){return te({queryKey:[e,`system_information`],queryFn:async()=>{let{data:e}=await t.post(`/`,{operation:`system_information`,attributes:[`network`,`disk`,`cpu`,`memory`,`system`]});return e}})}var li=new Date(2025,0).getTime(),ui=1440*60*1e3;function di(e){let t=[];for(let n in e){let r=e[n];t.push(...pi(n,r,0))}return t}function fi(e){return!!e.title}function pi(e,t,n,r){if(t&&Array.isArray(t)){let r=t;return[r.length>1&&{title:e,depth:n},...t.map((t,i)=>pi(r.length>1?String(i+1):e,t,n+1,e)).flat(1)].filter(fe)}if(mi(t)){let r=t;return[{title:e,depth:n},...Object.keys(t).map(t=>pi(String(t),r[t],n+1,e)).flat(1)]}return(e===`__updatedtime__`||e===`__createdtime__`)&&(e=e.replace(/_/g,``).replace(`time`,``)),typeof t==`number`?t>li&&t<Date.now()+ui?t=Se(Date.now()-t,t):r===`memory`?t=Oe(t):!e.startsWith(`raw`)&&e.toLowerCase().includes(`load`)&&(t=Math.round(t*10)/10+`%`):typeof t==`boolean`&&(t=t?`Yes`:`No`),[{name:e,value:String(t),depth:n}]}function mi(e){return!!e&&typeof e==`object`}function hi({instanceParams:e,isLocalStudio:t}){return(0,F.jsx)(P.Suspense,{fallback:(0,F.jsx)(gi,{}),children:t?(0,F.jsx)(_i,{instanceParams:e}):(0,F.jsx)(vi,{instanceParams:e})})}function gi(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[0,1,2,3].map(e=>(0,F.jsx)(`div`,{className:`h-40 rounded-lg bg-muted/30 animate-pulse`},e))})}function _i({instanceParams:e}){let{data:t}=r(ci(e));return(0,F.jsx)(yi,{data:t})}function vi({instanceParams:e}){let{data:t}=r(xe(e));return(0,F.jsx)(yi,{data:t})}function yi({data:e}){let t=(0,P.useMemo)(()=>xi(e),[e]);return(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsx)(ii,{type:`multiple`,defaultValue:t.slice(0,1).map(e=>e.title),children:t.map(e=>(0,F.jsxs)(ai,{value:e.title,children:[(0,F.jsx)(oi,{className:`text-base font-semibold`,children:e.title}),(0,F.jsx)(si,{children:(0,F.jsx)(bi,{section:e})})]},e.title))}),(0,F.jsxs)(`details`,{className:`rounded-lg border border-border bg-card`,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer px-4 py-2 text-sm text-muted-foreground hover:text-foreground`,children:`View raw JSON`}),(0,F.jsx)(`pre`,{className:`px-4 pb-4 text-xs overflow-auto max-h-96`,children:JSON.stringify(e,null,2)})]})]})}function bi({section:e}){return(0,F.jsxs)(`div`,{className:`space-y-3`,children:[e.rows.length>0&&(0,F.jsx)(A,{children:(0,F.jsx)(j,{className:`pt-4`,children:(0,F.jsx)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2 text-sm`,children:e.rows.map(e=>(0,F.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,F.jsx)(`dt`,{className:`text-muted-foreground`,children:e.name}),(0,F.jsx)(`dd`,{className:`font-mono text-right truncate`,title:e.value,children:e.value})]},e.name))})})}),e.subSections.map(e=>(0,F.jsxs)(`div`,{className:`pl-3 border-l border-border`,children:[(0,F.jsx)(`div`,{className:`text-sm font-semibold mb-2 text-muted-foreground`,children:e.title}),(0,F.jsx)(bi,{section:e})]},e.title))]})}function xi(e){let t=di(e),n=[],r=[],i=null;for(let e of t)if(fi(e)){for(;r.length>0&&r[r.length-1]._depth>=e.depth;)r.pop();let t={title:e.title,rows:[],subSections:[],_depth:e.depth};r.length===0?n.push(t):r[r.length-1].subSections.push(t),r.push(t)}else{let t=r[r.length-1];t?t.rows.push({name:e.name,value:e.value}):(i||(i={title:`General`,rows:[],subSections:[]},n.unshift(i)),i.rows.push({name:e.name,value:e.value}))}return n}function Si(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-4`,children:(0,F.jsx)(Q,{metric:`replication-latency`})})}var Ci=[`request-rate`,`error-rate`,`duration`,`success`,`transfer`,`response_200`,`cache-hit`,`cache-resolution`];function wi(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:Ci.map(e=>(0,F.jsx)(Q,{metric:e},e))})}var Ti=[`#e45756`,`#f58518`,`#eeca3b`,`#54a24b`,`#4c78a8`,`#b279a2`,`#9d755d`,`#17becf`,`#72b7b2`,`#bab0ac`],Ei=`#6b7280`;function Di(e){return Ti[e%Ti.length]}var Oi=`__other__`,ki=4096;function Ai(e){return Math.max(6e4,Math.ceil(e/90))}function ji(e){return`${e.database}.${e.table}`}function Mi(e){let t=e.map(e=>({database:e.database,table:e.table,tableKey:ji(e),node:e.node,time:e.id,size:e.size}));return t.sort((e,t)=>e.time-t.time),t}function Ni(e){let t=new Map,n=[];for(let r of e){let e=`${r.node}\0${r.tableKey}`;t.get(e)!==r.size&&(n.push(r),t.set(e,r.size))}return n}function Pi(e){let t=new Map,n=new Map;for(let t of e){let e=`${t.tableKey}\0${t.node}`,r=n.get(e);(r===void 0||t.size>r)&&n.set(e,t.size)}for(let[e,r]of n){let[n]=e.split(`\0`),i=t.get(n);(i===void 0||r>i)&&t.set(n,r)}let r=[...t.entries()].filter(([,e])=>e>ki);r.sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);let i=r.map(([e])=>e),a=[...t.keys()].filter(e=>!i.includes(e));if(a.sort((e,t)=>e.localeCompare(t)),i.length<=9)return{tableSet:i,hasOther:a.length>0,otherMembers:a};let o=i.slice(0,8),s=[...i.slice(8),...a];return{tableSet:o,hasOther:s.length>0,otherMembers:s}}function Fi(e,t,n){let r=new Map;for(let t of e){let e=`${t.node}\0${t.tableKey}`,n=r.get(e);(!n||t.time>=n.time)&&r.set(e,{size:t.size,time:t.time,tableKey:t.tableKey,node:t.node})}let i=new Set(t),a=new Map;for(let{size:e,tableKey:t,node:o}of r.values()){a.has(o)||a.set(o,{node:o,stacks:{},total:0});let r=a.get(o);r.total+=e,i.has(t)?r.stacks[t]=e:n&&(r.stacks[Oi]=(r.stacks.__other__??0)+e)}return[...a.values()].sort((e,t)=>e.node.localeCompare(t.node))}function Ii(e,t){let n=Ai(t.endTime-t.startTime);return function(r){let i=new Map,a=new Map;for(let o of e){if(o.tableKey!==r||o.time<t.startTime||o.time>t.endTime)continue;let e=t.startTime+Math.floor((o.time-t.startTime)/n)*n;i.has(e)||i.set(e,new Map);let s=i.get(e),c=s.get(o.node);(!c||o.time>=c.time)&&s.set(o.node,{size:o.size,time:o.time});let l=a.get(o.node)??0;o.time>l&&a.set(o.node,o.time)}let o=[],s=[...i.keys()].sort((e,t)=>e-t);for(let e of s){let t=i.get(e),n={};for(let[r,{size:i}]of t)e>(a.get(r)??0)||(n[r]=i);Object.keys(n).length>0&&o.push({time:e,values:n})}return o}}function Li(e,t){if(e.length===0)return null;let n=new Map;for(let t of e){let e=`${t.tableKey}\0${t.node}`,r=n.get(e);r||(r={min:t.size,max:t.size,distinctTimes:new Set},n.set(e,r)),t.size<r.min&&(r.min=t.size),t.size>r.max&&(r.max=t.size),r.distinctTimes.add(t.time)}let r=new Map;for(let[e,i]of n){let[n]=e.split(`\0`),a=i.distinctTimes.size>=2&&i.max>i.min,o=i.max-i.min,s=i.max>0?o/i.max:0,c=t===`bytes`?o:s,l=r.get(n);l?(c>l.delta&&(l.delta=c),i.max>l.maxSize&&(l.maxSize=i.max),a&&(l.hasDelta=!0)):r.set(n,{tableKey:n,delta:c,maxSize:i.max,hasDelta:a})}let i=[...r.values()],a=i.filter(e=>e.hasDelta);return a.length>0?(a.sort((e,t)=>t.delta===e.delta?e.tableKey.localeCompare(t.tableKey):t.delta-e.delta),a[0].tableKey):(i.sort((e,t)=>t.maxSize===e.maxSize?e.tableKey.localeCompare(t.tableKey):t.maxSize-e.maxSize),i[0]?.tableKey??null)}function Ri(e,t,n){return e===0?`upstream-empty`:t.length===0&&n?`all-other`:null}function zi(e,t){let n=Ni(Mi(e)),{tableSet:r,hasOther:i,otherMembers:a}=Pi(n),o=Fi(n,r,i),s=Ii(n,t),c=Ri(e.length,r,i),l=e.reduce((e,t)=>t.id>e?t.id:e,0),u=`${t.startTime}:${t.endTime}:${e.length}:${l}`;return{snapshot:{byNode:o,tableSet:r,hasOther:i,otherMembers:a},trend:s,defaultSelection:e=>Li(n,e),emptyCause:c,signature:u}}function Bi(e){let{points:t,node:n,windowMs:r,rankBy:i,formatBytes:a}=e,o=t.map(e=>e.values[n]).filter(e=>typeof e==`number`);if(o.length<2)return``;let s=o[0],c=o[0];for(let e of o)e<s&&(s=e),e>c&&(c=e);let l=c-s;if(l<=0)return``;if(i===`percent`)return`+${(c>0?l/c*100:0).toFixed(1)}%/window`;if(r<=0)return``;let u=l/(r/(1e3*60*60));return`+${a(l)} (${a(u)}/hr)`}function Vi(e){return{axisColor:`var(--chart-axis, #6b7280)`,gridColor:`var(--chart-grid, #e5e7eb)`,tooltipBg:`var(--chart-tooltip-bg, #ffffff)`,tooltipBorder:`var(--chart-grid, #d1d5db)`,textColor:`var(--chart-tooltip-fg, #1f2937)`}}function Hi({tableSet:e,hasOther:t,selectedTable:n,onSelectTable:r}){let i=(0,P.useRef)([]);(0,P.useEffect)(()=>{i.current=i.current.slice(0,e.length)},[e.length]);let a=n===null?-1:e.indexOf(n),o=a>=0?a:0;function s(t,n){if(t.key===`Enter`||t.key===` `){t.preventDefault(),r(e[n]);return}if(t.key!==`ArrowLeft`&&t.key!==`ArrowRight`&&t.key!==`ArrowDown`&&t.key!==`ArrowUp`)return;t.preventDefault();let a=e.length;if(a===0)return;let o=n;(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(o=(n+1)%a),(t.key===`ArrowLeft`||t.key===`ArrowUp`)&&(o=(n-1+a)%a),i.current[o]?.focus(),r(e[o])}return e.length===0&&!t?null:(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Table selector`,"data-testid":`table-size-chip-row`,className:`flex flex-wrap gap-2 pt-3`,children:[e.map((e,t)=>{let a=e===n,c=Di(t);return(0,F.jsxs)(`button`,{ref:e=>{i.current[t]=e},role:`radio`,"aria-checked":a,tabIndex:t===o?0:-1,"data-testid":`table-size-chip`,"data-table":e,onKeyDown:e=>s(e,t),onClick:()=>r(e),className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs ${a?`font-semibold text-(--color-text-primary)`:`border-(--color-border) text-(--color-text-secondary) hover:text-(--color-text-primary)`}`,style:{borderColor:a?c:void 0},children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:c}}),e]},e)}),t&&(0,F.jsxs)(`button`,{type:`button`,"aria-disabled":`true`,tabIndex:-1,"data-testid":`table-size-chip`,"data-table":`__other__`,title:`Aggregate of smaller tables; not selectable.`,className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border border-dashed border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-secondary)/60 cursor-not-allowed`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:`#6b7280`}}),`Other`]})]})}function Ui(e,t,n){return e.byNode.filter(e=>t(e.node)).map(e=>{let t={};return n.forEach((n,r)=>{t[`t_${r}`]=e.stacks[n]??0}),{node:e.node,...t,__total__:e.total}})}function Wi({snapshot:e,viewMode:t,theme:n,selectedTable:r,onChipSelect:i,onBarClick:a,allOtherHint:o}){let s=Vi(n),c=e.byNode.map(e=>e.node),{isActive:l,handleLegendClick:u}=z(c),d=t===`aggregate`;if(o)return(0,F.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-(--color-text-secondary)`,children:`All tables are small within this window — widen the range to see growth.`});let f=[...e.tableSet,...e.hasOther?[Oi]:[]],p=Ui(e,l,f),h=p.reduce((e,t)=>Math.max(e,t.__total__),0)||1;return(0,F.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,F.jsx)(`div`,{style:{width:`100%`,height:300},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,minWidth:0,children:(0,F.jsxs)(ae,{data:p,barCategoryGap:`20%`,children:[(0,F.jsx)(E,{stroke:s.gridColor,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`node`,stroke:s.axisColor,tick:{fontSize:11}}),(0,F.jsx)(T,{stroke:s.axisColor,tick:{fontSize:11},tickFormatter:e=>{let t=Number(e);return d?`${Math.round(t/h*100)}%`:U(t)},domain:d?[0,h]:[`auto`,`auto`]}),(0,F.jsx)(m,{contentStyle:{backgroundColor:s.tooltipBg,border:`1px solid ${s.tooltipBorder}`,borderRadius:8,fontSize:12},formatter:(e,t,n)=>{let r=String(t),i=r===`__other__`?`Other`:r,a=Number(e),o=n?.payload?.__total__??0,s=o>0?(a/o*100).toFixed(1):`0`;return[`${U(a)} (${s}% of node total ${U(o)})`,i]}}),f.map((e,t)=>{let n=e===`__other__`?Ei:Di(t),i=e===r;return(0,F.jsx)(v,{dataKey:`t_${t}`,name:e,stackId:`size`,fill:n,stroke:i?n:`transparent`,strokeWidth:i?2:0,onClick:()=>{e!==`__other__`&&a(e)},style:{cursor:e===`__other__`?`not-allowed`:`pointer`},children:p.map(t=>(0,F.jsx)(b,{"data-testid":`table-size-segment`,"data-table":e,"data-node":t.node},t.node))},e)})]})})}),(0,F.jsx)(R,{nodeIds:c,isActive:l,onClickNode:u}),(0,F.jsx)(Hi,{tableSet:e.tableSet,hasOther:e.hasOther,selectedTable:r,onSelectTable:i})]})}function Gi({derived:e,viewMode:t,theme:n,selectedTable:r,onChipSelect:i,manualSelection:a,range:o,clusterNodeIds:s,rankBy:c,onRankChange:l}){let u=Vi(n),d=(0,P.useMemo)(()=>r?e.trend(r):[],[e,r]),f=(0,P.useMemo)(()=>{let e=new Set;for(let t of d)for(let n of Object.keys(t.values))e.add(n);return[...e].sort()},[d]),{isActive:p,handleLegendClick:h}=z(f),g=Math.max(0,o.endTime-o.startTime),v=(0,P.useMemo)(()=>{let e=new Map;return f.forEach((t,n)=>e.set(t,`n_${n}`)),e},[f]),y=(0,P.useMemo)(()=>d.map(e=>{let t={};for(let[n,r]of v)t[r]=e.values[n]??null;return{time:e.time,...t}}),[d,v]);return r?(0,F.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,F.jsxs)(`div`,{"aria-live":`polite`,"data-testid":`table-size-trend-title`,className:`sr-only`,children:[`Trend selection: `,r,a?``:` (auto-selected — ${c===`bytes`?`largest bytes change`:`largest percent change`})`]}),!a&&(0,F.jsxs)(`div`,{className:`mb-1 text-[10px] text-(--color-text-secondary)`,children:[`Auto-selected by `,c===`bytes`?`largest bytes change`:`largest % change`]}),(0,F.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`text-[11px] text-(--color-text-secondary)`,children:`Rank by:`}),(0,F.jsxs)(`div`,{className:`inline-flex rounded border border-(--color-border) bg-(--color-bg-tertiary) p-0.5`,"data-testid":`table-size-rank-toggle`,children:[(0,F.jsx)(`button`,{type:`button`,"aria-pressed":c===`bytes`,onClick:()=>l(`bytes`),className:`rounded px-2 py-0.5 text-[11px] ${c===`bytes`?`bg-(--color-bg-secondary) text-(--color-text-primary)`:`text-(--color-text-secondary)`}`,children:`Bytes changed`}),(0,F.jsx)(`button`,{type:`button`,"aria-pressed":c===`percent`,onClick:()=>l(`percent`),className:`rounded px-2 py-0.5 text-[11px] ${c===`percent`?`bg-(--color-bg-secondary) text-(--color-text-primary)`:`text-(--color-text-secondary)`}`,children:`% change`})]})]}),(0,F.jsx)(`div`,{style:{width:`100%`,height:300},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,minWidth:0,children:(0,F.jsxs)(_,{data:y,children:[(0,F.jsx)(E,{stroke:u.gridColor,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`time`,type:`number`,domain:[o.startTime,o.endTime],allowDataOverflow:!0,tickFormatter:At,stroke:u.axisColor,tick:{fontSize:11},allowDuplicatedCategory:!1}),(0,F.jsx)(T,{stroke:u.axisColor,tick:{fontSize:11},tickFormatter:U,scale:t===`per-node`?`log`:`auto`,domain:t===`per-node`?[1,`auto`]:[`auto`,`auto`],allowDataOverflow:!0}),(0,F.jsx)(m,{contentStyle:{backgroundColor:u.tooltipBg,border:`1px solid ${u.tooltipBorder}`,borderRadius:8,fontSize:12},labelFormatter:e=>jt(Number(e)),formatter:e=>U(Number(e))}),f.filter(e=>p(e)).map(e=>(0,F.jsx)(D,{dataKey:v.get(e),name:`${e} ${Bi({points:d,node:e,windowMs:g,rankBy:c,formatBytes:U})}`.trim(),stroke:L(e,s),strokeWidth:2,dot:!1,type:`monotone`,connectNulls:!1},e))]})})}),(0,F.jsx)(R,{nodeIds:f,isActive:p,onClickNode:h}),(0,F.jsx)(Hi,{tableSet:e.snapshot.tableSet,hasOther:e.snapshot.hasOther,selectedTable:r,onSelectTable:i})]}):(0,F.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-(--color-text-secondary)`,children:`Select a table to view trend.`})}function Ki(e){return e.snapshot.byNode.map(e=>e.node)}function qi(){return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4`,children:[(0,F.jsx)(Xr,{metric:`table-size`,children:(0,F.jsx)(Ji,{})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsx)(Q,{metric:`database-size`}),(0,F.jsx)(Q,{metric:`transaction-log-growth`}),(0,F.jsx)(Q,{metric:`storage-volume`})]})]})}function Ji(){let{timeRange:e,bucketMs:t,refreshIntervalMs:n,theme:r,instanceParams:i}=I(),{data:a,isLoading:o,isError:s}=ut({metric:`table-size`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),c=(0,P.useMemo)(()=>{let e=a??[],t=[],n=0;for(let r of e)typeof r.id==`number`?t.push(r):typeof r.time==`number`?t.push({...r,id:r.time}):n++;return n>0&&console.warn(`[table-size] dropped rows missing both id and time`,{dropped:n,total:e.length}),t},[a]),l=(0,P.useMemo)(()=>zi(c,e),[c,e.startTime,e.endTime]),u=`bytes`,[d,f]=(0,P.useState)(null),p=(0,P.useRef)(null),m=(0,P.useRef)(null),h=(0,P.useMemo)(()=>d&&l.snapshot.tableSet.includes(d)?d:l.defaultSelection(u),[d,l]);if(o)return(0,F.jsxs)(A,{children:[(0,F.jsx)(k,{children:(0,F.jsx)(M,{children:`Table sizes`})}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`})})]});if(s)return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{children:[(0,F.jsx)(M,{children:`Table sizes`}),(0,F.jsx)(O,{children:`Per-table storage breakdown.`})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-32 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive flex items-center justify-center`,children:`Failed to load table-size data. Try a different time window or refresh.`})})]});if(l.emptyCause===`upstream-empty`)return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{children:[(0,F.jsx)(M,{children:`Table sizes`}),(0,F.jsx)(O,{children:`Per-table storage breakdown.`})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-32 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No table-size data in the selected window.`})})]});let g=e=>(0,F.jsx)(Wi,{snapshot:l.snapshot,viewMode:`per-node`,theme:r,selectedTable:h,onChipSelect:f,onBarClick:f,allOtherHint:l.emptyCause===`all-other`}),_=t=>h?(0,F.jsx)(Gi,{derived:l,viewMode:`per-node`,theme:r,selectedTable:h,onChipSelect:f,manualSelection:d!==null,range:e,clusterNodeIds:Ki(l),rankBy:u,onRankChange:()=>{}}):(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No table selected.`});return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsxs)(A,{ref:p,children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Table size — snapshot`}),(0,F.jsx)(O,{children:`Bytes per table, per node. Click a segment to pin the trend below.`})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`table-size-snapshot`,title:`Table size — snapshot`,description:`Bytes per table, per node.`,renderChart:g}),(0,F.jsx)(at,{captureRef:p,exportSlug:`table-size-snapshot`}),(0,F.jsx)(ot,{captureRef:p,exportSlug:`table-size-snapshot`})]})]}),(0,F.jsx)(j,{children:g()})]}),(0,F.jsxs)(A,{ref:m,children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Table size — trend`}),(0,F.jsx)(O,{children:h?`Growth of ${h} over the selected window.`:`Pick a table to see its trend.`})]}),h&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`table-size-trend`,title:`Table size — trend: ${h}`,description:`Growth of ${h} over the selected window.`,renderChart:_}),(0,F.jsx)(at,{captureRef:m,exportSlug:`table-size-trend`}),(0,F.jsx)(ot,{captureRef:m,exportSlug:`table-size-trend`})]})]}),(0,F.jsx)(j,{children:_()})]})]})}function Yi(){let{timeRange:e}=I();return(0,F.jsx)(Xr,{metric:`connections`,resetKey:`${e.startTime}-${e.endTime}`,children:(0,F.jsx)(Xi,{})})}function Xi(){let{timeRange:e,bucketMs:t,refreshIntervalMs:n,theme:r,instanceParams:i}=I(),a=(0,P.useRef)(null),o=ut({metric:`mqtt-connections`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),s=ut({metric:`ws-connections`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),c=o.isLoading||s.isLoading,l=o.isError||s.isError,u=o.error||s.error,d=(0,P.useMemo)(()=>{let e=[];for(let t of o.data)e.push({...t,type:`mqtt`});for(let t of s.data)e.push({...t,type:`ws`});return e},[o.data,s.data]),f=d.length===0,p=(0,P.useMemo)(()=>{let e=new Set;for(let t of d)typeof t.node==`string`&&e.add(t.node);return[...e].sort()},[d]),m=!c&&!l&&!f,h=(t={fillParent:!1})=>(0,F.jsx)(An,{records:d,timeRange:e,nodes:p,theme:r,fillParent:t.fillParent});return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Connections`}),(0,F.jsx)(O,{children:`Active MQTT + WebSocket sessions — chips solo / Ctrl-toggle.`})]}),m&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`connections`,title:`Connections`,description:`Active MQTT + WebSocket sessions.`,renderChart:h}),(0,F.jsx)(at,{captureRef:a,exportSlug:`connections`}),(0,F.jsx)(ot,{captureRef:a,exportSlug:`connections`})]})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{ref:a,children:c?(0,F.jsx)(`div`,{className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`}):l?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:`Failed to load: ${u?.message??`unknown error`}`}):f?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No active sessions in the selected time range.`}):h()})})]})}var Zi=[`mqtt-traffic-sent`,`mqtt-traffic-received`,`bytes-sent`,`bytes-received`,`tls-reused`,`connection`];function Qi(){return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsx)(Yi,{}),Zi.map(e=>(0,F.jsx)(Q,{metric:e},e))]})}var $i=[{id:`health`,label:`Health`},{id:`traffic`,label:`Traffic`},{id:`requests`,label:`Requests`},{id:`database`,label:`Database`},{id:`replication`,label:`Replication`},{id:`storage`,label:`Storage`},{id:`overview`,label:`Overview`}];function ea({instanceParams:e,isLocalStudio:t}){let n=$e(e);return n.isLoading?(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`px-4 py-8 text-sm text-muted-foreground`,children:`Checking analytics availability…`}):n.error?(0,F.jsxs)(`div`,{role:`alert`,className:`px-4 py-8 text-sm text-muted-foreground`,children:[(0,F.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Analytics unavailable on this instance.`}),(0,F.jsxs)(`p`,{children:[`The Harper instance returned an error from`,` `,(0,F.jsx)(`code`,{children:`get_analytics`}),`. Check that the instance is reachable and that analytics is enabled, then reload.`]})]}):(0,F.jsx)(ta,{instanceParams:e,isLocalStudio:t})}function ta({instanceParams:e,isLocalStudio:t}){let n=le(),r=u({strict:!1}),i=$i.some(e=>e.id===r.tab)?r.tab:`health`,a=r.range&&na.includes(r.range)?r.range:`1h`,o=r.refresh!==void 0&&ra.includes(Number(r.refresh))?Number(r.refresh):Ue,[s,c]=(0,P.useState)(0),{resolvedTheme:l}=g(),d=l===`dark`?`dark`:`light`,f=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:i,range:e,refresh:o}})},[n,i,o]),p=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:e,range:a,refresh:o}})},[n,a,o]),m=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:i,range:a,refresh:e}})},[n,i,a]);(0,P.useEffect)(()=>()=>{n({search:void 0,replace:!0})},[n]);let h=(0,P.useMemo)(()=>{let t=Ve(a),n=Date.now();return{timeRange:{startTime:n-t.durationMs,endTime:n},bucketMs:t.bucketMs,refreshIntervalMs:o,theme:d,instanceParams:e}},[a,o,d,e,s]),_=i===`overview`?null:(0,F.jsx)(qe,{presetId:a,onPresetChange:f,refreshMs:o,onRefreshChange:m,onManualRefresh:()=>c(e=>e+1)});return(0,F.jsx)(Ye,{value:h,children:(0,F.jsxs)(ke,{value:i,onValueChange:e=>p(e),className:`px-4 py-2`,children:[i!==`overview`&&(0,F.jsx)(Ie,{}),(0,F.jsx)(`div`,{className:`md:hidden mb-3`,children:(0,F.jsxs)(Ee,{value:i,onValueChange:e=>p(e),children:[(0,F.jsx)(be,{className:`w-full`,"aria-label":`Select status tab`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:$i.map(e=>(0,F.jsx)(Ce,{value:e.id,children:e.label},e.id))})]})}),(0,F.jsx)(Te,{className:`hidden md:inline-flex max-w-full overflow-x-auto mb-4`,children:$i.map(e=>(0,F.jsx)(je,{value:e.id,children:e.label},e.id))}),(0,F.jsx)(N,{value:`health`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(ri,{})})}),(0,F.jsx)(N,{value:`traffic`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(Qi,{})})}),(0,F.jsx)(N,{value:`requests`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(wi,{})})}),(0,F.jsx)(N,{value:`database`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(ti,{})})}),(0,F.jsx)(N,{value:`replication`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(Si,{})})}),(0,F.jsx)(N,{value:`storage`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(qi,{})})}),(0,F.jsx)(N,{value:`overview`,children:(0,F.jsx)(hi,{instanceParams:e,isLocalStudio:t})})]})})}function $({picker:e,children:t}){return(0,F.jsxs)(F.Fragment,{children:[e&&(0,F.jsx)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-2 mb-3 bg-background border-b border-border shadow-sm flex items-center justify-end gap-2`,children:e}),t]})}var na=[`1h`,`6h`,`24h`,`7d`,`30d`],ra=[0,3e4,6e4,3e5];function ia(){return(0,F.jsx)(ea,{instanceParams:pe(),isLocalStudio:!0})}export{ia as StatusIndex};
2
- //# sourceMappingURL=status-110CCE-v.js.map
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{n as t,t as n}from"./button-V4IQ8FFq.js";import{Aa as r,Di as i,Fa as a,Li as o,Lr as s,Na as c,Pa as l,Sa as u,Ua as d,Wi as f,Yr as p,_ as m,a as h,b as g,c as _,d as v,f as y,g as b,gr as x,h as S,hr as C,i as w,ja as ee,ka as te,l as T,m as E,n as ne,o as re,p as D,r as ie,s as ae,t as oe,u as se,v as ce,xa as le,y as ue}from"./vendor-react-Dj1rnUQ4.js";import{g as de}from"./vendor-misc-DKMU5hOJ.js";import{a as fe,c as O,l as k,o as A,r as pe,s as j,u as M}from"./useInstanceClient-CdXj_Str.js";import{C as me,F as he,N as ge,P as _e,S as ve,T as ye,_ as be,c as N,d as xe,f as Se,g as Ce,h as we,l as Te,m as Ee,n as De,p as Oe,s as ke,t as Ae,u as je,v as Me,w as Ne,x as Pe}from"./index-BIjBsaWw.js";var P=e(a(),1),F=l(),Fe=`studio:analytics:onboarding-dismissed:v1`;function Ie(){let[e,t]=(0,P.useState)(null);return(0,P.useEffect)(()=>{try{t(window.localStorage.getItem(Fe)===`1`)}catch{t(!0)}},[]),e===!1?(0,F.jsxs)(`div`,{role:`status`,className:`mb-3 flex items-start gap-3 rounded-md border border-border bg-muted/30 px-3 py-2 text-sm text-muted-foreground`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(`span`,{className:`font-medium text-foreground`,children:`Tip:`}),` Click a legend entry to isolate one node, `,(0,F.jsx)(`kbd`,{className:`rounded border border-border px-1 py-0.5 text-xs`,children:`⌘`}),` / `,(0,F.jsx)(`kbd`,{className:`rounded border border-border px-1 py-0.5 text-xs`,children:`Ctrl`}),`-click to compare a few. Bar segments and heatmap cells are clickable for drilldown.`]}),(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:()=>{try{window.localStorage.setItem(Fe,`1`)}catch{}t(!0)},"aria-label":`Dismiss tip`,className:`-mt-1 h-7 w-7 shrink-0`,children:(0,F.jsx)(x,{className:`h-4 w-4`})})]}):null}var Le=6e4,Re=60*Le,ze=24*Re,Be=[{id:`1h`,label:`Last 1 hour`,durationMs:Re,bucketMs:1*Le},{id:`6h`,label:`Last 6 hours`,durationMs:6*Re,bucketMs:1*Le},{id:`24h`,label:`Last 24 hours`,durationMs:ze,bucketMs:5*Le},{id:`7d`,label:`Last 7 days`,durationMs:7*ze,bucketMs:15*Le},{id:`30d`,label:`Last 30 days`,durationMs:30*ze,bucketMs:Re}];function Ve(e){let t=Be.find(t=>t.id===e);if(!t)throw Error(`Unknown preset: ${e}`);return t}var He=[{label:`Off`,value:0},{label:`30s`,value:3e4},{label:`60s`,value:6e4},{label:`5m`,value:3e5}],Ue=6e4,We=Ae;function Ge(){let e=c(),[t,n]=(0,P.useState)(!1),[r,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(()=>Date.now());return(0,P.useEffect)(()=>{let t=e.getQueryCache(),r=e=>Array.isArray(e.queryKey)&&e.queryKey[0]===We,a=()=>{let e=!1,a=null;for(let n of t.getAll())r(n)&&(n.state.fetchStatus===`fetching`&&(e=!0),n.state.dataUpdatedAt>0&&(a===null||n.state.dataUpdatedAt>a)&&(a=n.state.dataUpdatedAt));n(t=>t===e?t:e),i(e=>e===a?e:a)};a();let o=t.subscribe(e=>{!e?.query||!r(e.query)||a()});return()=>o()},[e]),(0,P.useEffect)(()=>{let e=!1,t,n=()=>{if(e)return;o(Date.now());let i=r===null?0:Date.now()-r,a=i<6e4?1e3:i<6e5?5e3:3e4;t=window.setTimeout(n,a)};return t=window.setTimeout(n,1e3),()=>{e=!0,t!==void 0&&window.clearTimeout(t)}},[r]),{isFetching:t,lastFetchedAt:r,now:a}}function Ke(e,t){if(e===null)return null;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<5)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function qe({presetId:e,onPresetChange:r,refreshMs:i,onRefreshChange:a,onManualRefresh:o}){let{isFetching:c,lastFetchedAt:l,now:u}=Ge(),d=Ke(l,u);return(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,F.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,title:l?new Date(l).toLocaleString():void 0,"aria-label":l?`Last updated ${new Date(l).toLocaleString()}`:void 0,children:[`Updated `,d]}),(0,F.jsxs)(Ee,{value:e,onValueChange:e=>r(e),children:[(0,F.jsx)(be,{className:`w-[180px]`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:Be.map(e=>(0,F.jsx)(Ce,{value:e.id,children:e.label},e.id))})]}),(0,F.jsxs)(Ee,{value:String(i),onValueChange:e=>a(Number(e)),children:[(0,F.jsx)(be,{className:`w-[100px]`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:He.map(e=>(0,F.jsx)(Ce,{value:String(e.value),children:e.label},e.value))})]}),(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:o,disabled:c,"aria-busy":c,"aria-label":c?`Refreshing…`:`Refresh now`,title:c?`Refreshing…`:`Refresh now`,children:(0,F.jsx)(s,{className:t(`h-4 w-4`,c&&`animate-spin`)})})]})}var Je=(0,P.createContext)(null);function Ye({value:e,children:t}){let n=(0,P.useMemo)(()=>e,[e.timeRange.startTime,e.timeRange.endTime,e.bucketMs,e.refreshIntervalMs,e.theme,e.instanceParams.entityId]);return(0,F.jsx)(Je.Provider,{value:n,children:t})}function I(){let e=(0,P.useContext)(Je);if(!e)throw Error(`useAnalyticsContext must be used inside <AnalyticsProvider>`);return e}var Xe=[`utilization`,`cpu-usage`,`memory`,`main-thread-utilization`],Ze=30*6e4;function Qe(e){let t=e?.response?.status??e?.status;return typeof t==`number`?t>=400&&t<500:!1}function $e(e){let t=ee({queryKey:[`analytics-capability`,e.entityId],queryFn:async()=>{let t=Date.now(),n=t-5*6e4,r=null;for(let i of Xe)try{return await e.instanceClient.post(`/`,{operation:`get_analytics`,metric:i,start_time:n,end_time:t}),!0}catch(e){if(r=e,!Qe(e))throw e}throw r instanceof Error?r:Error(`Analytics probe failed for all metrics`)},retry:2,retryDelay:e=>Math.min(1e3*2**e,8e3),staleTime:Ze,gcTime:Ze});return{supported:t.isSuccess===!0,error:t.error,isLoading:t.isLoading,retry:()=>{t.refetch()}}}function et(e){let t=e;for(;t;){let e=getComputedStyle(t).backgroundColor;if(e&&e!==`rgba(0, 0, 0, 0)`&&e!==`transparent`)return e;t=t.parentElement}let n=typeof document<`u`?getComputedStyle(document.body).backgroundColor:``;return n&&n!==`rgba(0, 0, 0, 0)`?n:`#ffffff`}async function tt(e,t=3){let n=await de(e,{pixelRatio:t,backgroundColor:et(e)});if(!n)throw Error(`Failed to capture chart as image`);return n}async function nt(e,t){let n=await tt(e),r=URL.createObjectURL(n);try{let e=document.createElement(`a`);e.href=r,e.download=t,e.click()}finally{URL.revokeObjectURL(r)}}async function rt(e){if(typeof ClipboardItem>`u`||!navigator.clipboard?.write)return!1;try{let t=await tt(e);return await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),!0}catch{return!1}}function it(e,t){return`${e.replace(/[^a-z0-9-]+/gi,`-`).replace(/(^-|-$)/g,``).toLowerCase()}-${new Date(t.endTime).toISOString().replace(/[:.]/g,`-`)}.png`}function at({captureRef:e,exportSlug:t}){let[r,i]=(0,P.useState)(!1);return(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:async()=>{if(r)return;let t=e.current;if(t){i(!0);try{await rt(t)?C.success(`Chart copied to clipboard`):C.error(`Could not copy chart`,{description:`Your browser blocked the clipboard write. Try Download or check site permissions.`})}catch(e){console.error(`[chart-copy] capture failed`,e),C.error(`Could not copy chart`,{description:e instanceof Error?e.message:`Unknown error`})}finally{i(!1)}}},"aria-disabled":r,"aria-busy":r,"aria-label":`Copy ${t} chart to clipboard`,children:(0,F.jsx)(o,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Copy to clipboard`})]})}function ot({captureRef:e,exportSlug:t}){let{timeRange:r}=I(),[a,o]=(0,P.useState)(!1);return(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:async()=>{if(a)return;let n=e.current;if(!n)return;o(!0);let i=it(t,r);try{await nt(n,i),C.success(`Saved ${i}`)}catch(e){console.error(`[chart-export] capture failed`,e),C.error(`Could not export chart`,{description:e instanceof Error?e.message:`Unknown error`})}finally{o(!1)}},"aria-disabled":a,"aria-busy":a,"aria-label":`Download ${t} as PNG`,children:(0,F.jsx)(i,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Download as PNG`})]})}function st({exportSlug:e,title:t,description:r,renderChart:i}){let[a,o]=(0,P.useState)(!1),s=(0,P.useRef)(null);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(ge,{children:[(0,F.jsx)(he,{asChild:!0,children:(0,F.jsx)(n,{variant:`ghost`,size:`icon`,onClick:()=>o(!0),"aria-label":`Expand ${e}`,children:(0,F.jsx)(p,{className:`h-4 w-4`})})}),(0,F.jsx)(_e,{side:`top`,children:`Expand`})]}),(0,F.jsx)(Pe,{open:a,onOpenChange:o,children:(0,F.jsxs)(ve,{className:`!max-w-[95vw] sm:!max-w-[95vw] h-[90vh] flex flex-col`,children:[(0,F.jsx)(Ne,{children:(0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-2 pr-6`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(ye,{children:t}),r&&(0,F.jsx)(me,{children:r})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(at,{captureRef:s,exportSlug:`${e}-expanded`}),(0,F.jsx)(ot,{captureRef:s,exportSlug:`${e}-expanded`})]})]})}),(0,F.jsx)(`div`,{ref:s,className:`flex-1 min-h-0 overflow-hidden flex flex-col`,children:i({fillParent:!0})})]})})]})}var ct=new Set([`time`,`node`]),lt=Object.freeze([]);function ut({metric:e,startTime:t,endTime:n,conditions:r,instanceParams:i,refetchIntervalMs:a=6e4,requiredFields:o,bucketMs:s}){let c=(0,P.useRef)(null);c.current===null&&(c.current=Math.floor(Math.random()*500));let l=ee({...De({metric:e,startTime:t,endTime:n,conditions:r,instanceParams:i,bucketMs:s}),staleTime:a>0?a:1/0,refetchInterval:a>0?a+c.current:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,placeholderData:d}),u=l.data??lt,{fieldKeys:f,missingFields:p}=(0,P.useMemo)(()=>{let e=new Set;for(let t of u)for(let n of Object.keys(t))ct.has(n)||e.add(n);let t=[];if(o&&u.length>0)for(let n of o)e.has(n)||t.push(n);return{fieldKeys:e,missingFields:t}},[u,o]);return(0,P.useEffect)(()=>{!l.isLoading&&u.length===0&&p.length>0&&console.warn(`[analytics] panel rendered empty with missing fields`,{metric:e,instanceId:i.entityId,missingFields:p})},[u.length,l.isLoading,e,i.entityId,p]),{data:u,isLoading:l.isLoading,isError:l.isError,error:l.error,isEmpty:u.length===0,fieldKeys:f,missingFields:p,refetch:l.refetch}}function dt(e,t,n){let r=new Map;for(let t of e){let e=typeof t.path==`string`?t.path:null;if(!e||typeof t.time!=`number`||!Number.isFinite(t.time))continue;let n=typeof t.count==`number`&&Number.isFinite(t.count)?t.count:0,i=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:0,a=r.get(e);a||(a=new Map,r.set(e,a));let o=a.get(t.time);o||(o={sumCount:0,sumTotal:0},a.set(t.time,o)),o.sumCount+=n,o.sumTotal+=i}return{series:[...r.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e);return{x:e,y:n.sumCount===0?null:1-n.sumTotal/n.sumCount,count:n.sumCount}})})),thresholds:[{value:.001,label:`0.1% error SLO`,direction:`above-is-bad`,minCount:1e3}]}}var ft={id:`error-rate`,title:`Error rate (≥1000 req)`,subtitle:`errored-request fraction — 1 − Σtotal/Σcount`,tab:`requests`,sourceMetric:`success`,recompute:dt,primitive:`line`,yAxis:{unit:``,formatter:`percent`}},pt=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`,`#79c0ff`,`#d2a8ff`,`#ffa657`,`#ff7b72`,`#7ee787`];function L(e,t){return pt[[...t].sort().indexOf(e)%pt.length]}function R({nodeIds:e,isActive:t,onClickNode:n,disabled:r}){return(0,F.jsxs)(`div`,{role:`group`,"aria-label":r?`Node filter (unavailable on this tab)`:`Node filter`,className:`flex flex-wrap justify-center gap-x-4 gap-y-1 pt-2 text-[11px]`,children:[r&&(0,F.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:`Per-node filter is unavailable on this tab. Buttons remain visible to preserve selection state.`}),e.map(i=>{let a=L(i,e),o=t(i);return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":o,"aria-disabled":r?`true`:void 0,title:r?`Per-node filter unavailable on this tab's panels`:void 0,onClick:e=>{r||n(i,e.ctrlKey||e.metaKey)},className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:r?{color:a,opacity:.5,cursor:`not-allowed`}:{color:a,opacity:o?1:.3},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:a}}),(0,F.jsx)(`span`,{children:i})]},i)})]})}function z(e){let[t,n]=(0,P.useState)(null);return{isActive:(0,P.useCallback)(e=>t===null||t.has(e),[t]),handleLegendClick:(0,P.useCallback)((t,r)=>{n(n=>{if(r){if(n===null)return new Set(e.filter(e=>e!==t));let r=new Set(n);if(r.has(t)){if(r.delete(t),r.size===0)return null}else if(r.add(t),r.size===e.length)return null;return r}return n!==null&&n.size===1&&n.has(t)?null:new Set([t])})},[e]),activeNodes:t}}var mt=[`#0d9488`,`#dc2626`,`#7c3aed`,`#d97706`,`#db2777`,`#0284c7`];function ht(e,t){let n=[...t].sort().indexOf(e);return mt[(n<0?0:n)%mt.length]}function B(e,t){let n=t.filter(e=>typeof e.value==`number`&&Number.isFinite(e.value));if(n.length===0)return null;let r=n.map(e=>e.value);switch(e){case`sum`:return r.reduce((e,t)=>e+t,0);case`mean`:return r.reduce((e,t)=>e+t,0)/r.length;case`max`:{let e=r[0];for(let t=1;t<r.length;t++)r[t]>e&&(e=r[t]);return e}case`min`:{let e=r[0];for(let t=1;t<r.length;t++)r[t]<e&&(e=r[t]);return e}case`last`:return r[r.length-1];case`p50`:return gt(r,.5);case`p95`:return gt(r,.95);case`p99`:return gt(r,.99);case`count-weighted-mean`:{let e=0,t=0;for(let r of n){let n=Number.isFinite(r.count)?r.count:1;e+=r.value*n,t+=n}return t===0?null:e/t}}}function gt(e,t){let n=[...e].sort((e,t)=>e-t);return n[Math.max(1,Math.ceil(t*n.length))-1]}function _t(e){return e===`count-weighted-mean`}function V(e,t){return _t(t)?e.endsWith(`(approx)`)?e:`${e} (approx)`:e}function vt(e,t){if(!t)return`ok`;if(e===void 0)return`suppress`;let{suppressBelow:n,greyBelow:r}=t;return n!==void 0&&e<n?r!==void 0&&e>=r?`grey`:`suppress`:r!==void 0&&e<r?`grey`:`ok`}function yt(e,t){switch(e.kind){case`const`:return e.value;case`ref`:{let n=t[e.field];return typeof n==`number`&&Number.isFinite(n)?n:null}case`op`:{let n=yt(e.left,t),r=yt(e.right,t);if(n===null||r===null)return null;switch(e.op){case`+`:return n+r;case`-`:return n-r;case`*`:return n*r;case`/`:return r===0?null:n/r;default:{let t=e.op;throw Error(`unknown op: ${String(t)}`)}}}default:throw Error(`unknown FieldExpr kind: ${e.kind}`)}}var bt={"percent-of-core":e=>e*100};function xt(e,t,n){if(t===null)return null;switch(e.kind){case`raw`:return t;case`scale`:return t*e.factor;case`rate`:return!Number.isFinite(n)||n<=0?null:t/n*1e3;case`ratio`:return t;case`compose`:{let r=t;for(let t of e.steps)if(r=xt(t,r,n),r===null)return null;return r}case`named`:{let n=bt[e.name];if(!n)throw Error(`unknown named transform: ${e.name}`);return n(t)}default:throw Error(`unknown transform kind: ${e.kind}`)}}function H(e,t,n,r,i){return e.series.kind===`field`?Et(e,e.series.fields,t,i?.perNode??!1,i?.snapToPeriod??!1):Tt(e,e.series,t,i?.perNode??!1,i?.snapToPeriod??!1)}function St(e,t,n){let r=0,i=t.period;return typeof i==`number`&&Number.isFinite(i)&&i>0&&(r=i),r<=0&&(r=e.bucket?.fallbackMs??6e4),Math.round(n/r)*r}function Ct(e,t){let n=e.timestamp??`time`;if(n===`time`){let e=t.time;return typeof e==`number`&&Number.isFinite(e)?e:null}if(n===`id`){let e=t.id;return typeof e==`number`&&Number.isFinite(e)?e:null}let r=t.time;if(typeof r==`number`&&Number.isFinite(r))return r;let i=t.id;return typeof i==`number`&&Number.isFinite(i)?i:null}function wt(e,t){let n=typeof e.field==`string`?typeof t[e.field]==`number`?t[e.field]:null:yt(e.field,t),r=typeof t.period==`number`?t.period:0;return xt(e.transform??{kind:`raw`},n,r)}function Tt(e,t,n,r,i){let a=new Map,o=new Map,s=new Set;for(let r of n){let n=r[t.dimension];if(typeof n!=`string`&&typeof n!=`number`)continue;let c=wt(t.field,r);if(c===null)continue;let l=Ct(e,r);if(l===null){let n=`${String(r[t.dimension])}|${String(r.time)}`;s.has(n)||(s.add(n),console.warn(`[runGroupBy] Dropping record with no resolvable timestamp:`,{dimension:r[t.dimension],time:r.time,id:r.id,timestamp:e.timestamp??`time`}));continue}let u=i?St(e,r,l):l,d=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:1,f=typeof r.node==`string`?r.node:`_no_node`;o.set(n,(o.get(n)??0)+d);let p=a.get(n);p||(p=new Map,a.set(n,p));let m=p.get(u);m||(m=new Map,p.set(u,m));let h=m.get(f);h||(h={items:[],totalCount:0},m.set(f,h)),h.items.push({value:c,count:d}),h.totalCount+=d}let c=t.field.aggregator?.temporal??e.aggregator.temporal,l=t.field.aggregator?.crossNode??e.aggregator.crossNode,u=c===`count-weighted-mean`||l===`count-weighted-mean`,d=[...o.entries()].sort((e,t)=>t[1]-e[1]),f=t.topN??1/0,p=d.slice(0,f),m=d.slice(f),h=[],g=0;for(let[n,i]of p){if(vt(i,e.confidence&&{greyBelow:e.confidence.greyBelow,suppressBelow:e.confidence.suppressBelow})===`suppress`){g++;continue}let o=a.get(n);if(!o)continue;let s=t.dimension===`node`;if(r&&!s){let e=new Map;for(let[t,n]of o)for(let[r,i]of n){let n=e.get(r);n||(n=new Map,e.set(r,n)),n.set(t,i)}for(let[t,r]of e){let e=[],i=[...r.keys()].sort((e,t)=>e-t);for(let t of i){let n=r.get(t),i=B(c,n.items);e.push({x:t,y:i,count:n.totalCount})}h.push({key:`${String(n)}|${t}`,label:V(t,c),points:e,approx:u})}}else{let e=[],t=[...o.keys()].sort((e,t)=>e-t);for(let n of t){let{y:t,count:r}=Dt(c,l,o.get(n));e.push({x:n,y:t,count:r})}h.push({key:String(n),label:V(String(n),c),points:e,approx:u})}}if(t.otherBucket&&m.length>0)if(vt(m.reduce((e,[,t])=>e+t,0),e.confidence&&{greyBelow:e.confidence.greyBelow,suppressBelow:e.confidence.suppressBelow})!==`suppress`){let e=new Map;for(let[t]of m){let n=a.get(t);if(n)for(let[t,r]of n){let n=e.get(t);n||(n=new Map,e.set(t,n));for(let[e,t]of r){let r=n.get(e);r||(r={items:[],totalCount:0},n.set(e,r));for(let e of t.items)r.items.push(e);r.totalCount+=t.totalCount}}}let t=[],n=[...e.keys()].sort((e,t)=>e-t);for(let r of n){let{y:n,count:i}=Dt(c,l,e.get(r));t.push({x:r,y:n,count:i})}h.push({key:`Other`,label:V(`Other`,c),points:t,approx:u})}else g++;return{series:h,thresholds:e.thresholds,...g>0?{suppressedSeriesCount:g}:{}}}function Et(e,t,n,r,i){let a=new Set;return{series:t.map(t=>{let o=new Map;for(let r of n){let n=Ct(e,r);if(n===null){let n=`${t.label}|${String(r.time)}`;a.has(n)||(a.add(n),console.warn(`[runFieldSpecs] Dropping record with no resolvable timestamp:`,{field:t.label,time:r.time,id:r.id,timestamp:e.timestamp??`time`}));continue}let s=wt(t,r);if(s===null)continue;let c=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:1,l=typeof r.node==`string`?r.node:`_no_node`,u=i?St(e,r,n):n,d=o.get(u);d||(d=new Map,o.set(u,d));let f=d.get(l);f||(f={items:[],totalCount:0},d.set(l,f)),f.items.push({value:s,count:c}),f.totalCount+=c}let s=t.aggregator?.temporal??e.aggregator.temporal,c=t.aggregator?.crossNode??e.aggregator.crossNode,l=s===`count-weighted-mean`||c===`count-weighted-mean`,u=typeof t.field==`string`?t.field:t.label;if(r){let e=new Map;for(let[t,n]of o)for(let[r,i]of n){let n=e.get(r);n||(n=new Map,e.set(r,n)),n.set(t,i)}let n=[];for(let[r,i]of e){let e=[],a=[...i.keys()].sort((e,t)=>e-t);for(let t of a){let n=i.get(t),r=B(s,n.items);e.push({x:t,y:r,count:n.totalCount})}n.push({key:`${u}|${r}`,label:V(`${t.label} — ${r}`,s),axis:t.axis,points:e,approx:l})}return n}let d=[],f=[...o.keys()].sort((e,t)=>e-t);for(let e of f){let{y:t,count:n}=Dt(s,c,o.get(e));d.push({x:e,y:t,count:n})}return[{key:u,label:V(t.label,s),axis:t.axis,points:d,approx:l}]}).flat(),thresholds:e.thresholds}}function Dt(e,t,n){let r=[],i=0;for(let[,t]of n){let n=B(e,t.items);typeof n==`number`&&Number.isFinite(n)&&r.push({value:n,count:t.totalCount}),i+=t.totalCount}return{y:B(t,r),count:i}}var Ot=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}),kt=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`});new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}),new Intl.DateTimeFormat(void 0,{timeZoneName:`short`});function At(e){return Ot.format(new Date(e))}function jt(e){return kt.format(new Date(e))}function U(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=1e3,r=Math.floor(Math.log(e)/Math.log(n)),i=e/n**r;return`${i.toFixed(+(i<10))} ${t[r]}`}function W(e,t,n){if(e==null||!Number.isFinite(e))return`—`;let r=Mt(e,t);return n?`${r}${n}`:r}function Mt(e,t){switch(t){case`percent`:return`${(e*100).toFixed(1)}%`;case`ms`:return`${e.toFixed(1)} ms`;case`count`:return`${e.toFixed(0)}`;case`count-si`:{let t=Math.abs(e);if(t<1e3)return`${e}`;let n=e<0?`-`:``,r=e=>{if(e>=10)return`${Math.round(e)}`;let t=e.toFixed(1);return t.endsWith(`.0`)?t.slice(0,-2):t};return t<1e6?`${n}${r(t/1e3)}k`:t<1e9?`${n}${r(t/1e6)}M`:`${n}${r(t/1e9)}B`}case`cores`:return`${e.toFixed(2)} cores`;case`bytes-si`:case`bytes-iec`:{let n=t===`bytes-iec`?1024:1e3,r=t===`bytes-iec`?[`B`,`KiB`,`MiB`,`GiB`,`TiB`]:[`B`,`KB`,`MB`,`GB`,`TB`],i=e,a=0;for(;Math.abs(i)>=n&&a<r.length-1;)i/=n,a++;return`${i.toFixed(1)} ${r[a]}`}default:return`${e}`}}var Nt={background:`var(--chart-tooltip-bg)`,color:`var(--chart-tooltip-fg)`,border:`1px solid var(--border)`,borderRadius:6,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.25)`,padding:8,fontSize:12},Pt={color:`var(--chart-tooltip-fg)`,opacity:.7,marginBottom:4,fontSize:11},Ft={color:`var(--chart-tooltip-fg)`};function It(e){return!!e&&typeof e==`object`&&`left`in e}function Lt(e){let t=e.series.map(e=>e.label);return`${t.length===1?`Chart of ${t[0]}`:`Chart with ${t.length} series: ${t.slice(0,5).join(`, `)}${t.length>5?`…`:``}`}${e.thresholds&&e.thresholds.length>0?`. ${e.thresholds.length} threshold${e.thresholds.length===1?``:`s`}.`:``}`}function G({data:e,theme:t,yAxis:n,height:r=240,ariaLabel:i,hideLegend:a,xDomain:o,fillParent:s}){if(e.series.length===0)return(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-(--color-text-secondary) text-sm p-4`,children:`No data in window`});let c=It(n),l=c?n.left:n,u=c?n.right:void 0,d=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`];return(0,F.jsx)(`div`,{role:`img`,"aria-label":i??Lt(e),style:s?{width:`100%`,height:`100%`,minHeight:0,flex:`1 1 auto`,display:`flex`,flexDirection:`column`}:{width:`100%`,height:r},children:(0,F.jsx)(`div`,{"aria-hidden":`true`,style:{width:`100%`,height:`100%`},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,children:(0,F.jsxs)(_,{margin:{top:12,right:12,bottom:8,left:8},children:[(0,F.jsx)(E,{stroke:`var(--chart-grid)`,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`x`,type:`number`,domain:o??[`dataMin`,`dataMax`],allowDataOverflow:!!o,allowDuplicatedCategory:!1,tickFormatter:At,tick:{fontSize:11}}),(0,F.jsx)(T,{yAxisId:`left`,tickFormatter:e=>W(e,l?.formatter,l?.unit),scale:l?.scale??`linear`,domain:l?.domain,tick:{fontSize:11},width:70}),c&&u?(0,F.jsx)(T,{yAxisId:`right`,orientation:`right`,tickFormatter:e=>W(e,u.formatter,u.unit),scale:u.scale??`linear`,domain:u.domain,tick:{fontSize:11},width:70}):null,(0,F.jsx)(m,{labelFormatter:e=>jt(Number(e)),formatter:(t,n)=>{let r=String(n),i=e.series.find(e=>e.label===r||e.key===r)?.axis===`right`?u:l;return[W(Number(t),i?.formatter,i?.unit),r]},contentStyle:Nt,labelStyle:Pt,itemStyle:Ft}),!a&&(0,F.jsx)(ce,{}),e.thresholds?.map((e,t)=>{let n=W(e.value,l?.formatter,l?.unit),r=e.direction===`above-is-bad`?`↑ bad`:`↓ bad`,i=`${e.label} (${n}, ${r})`,a=t%2==0?`insideTopRight`:`insideBottomRight`;return(0,F.jsx)(S,{yAxisId:`left`,y:e.value,stroke:e.direction===`above-is-bad`?`var(--color-error)`:`var(--color-success)`,strokeDasharray:`4 2`,label:{value:i,position:a,fontSize:11}},`th-${t}`)}),e.series.map((e,t)=>{let n=e.points.length<=5;return(0,F.jsx)(D,{data:e.points,type:`monotone`,dataKey:`y`,name:e.label,yAxisId:e.axis===`right`?`right`:`left`,stroke:e.color??d[t%d.length],strokeWidth:2,strokeOpacity:e.opacity??1,dot:n?{r:2}:!1,connectNulls:!1},e.key)})]})})})})}function Rt(e){let t=e.indexOf(`|`);return t===-1?null:e.slice(t+1)}function zt({panels:e,theme:t,minPanelWidth:n=320,panelHeight:r=240,xDomain:i,fillParent:a}){let o=(0,P.useMemo)(()=>{let t=new Set;for(let n of e)for(let e of n.data.series){let n=Rt(e.key);n&&t.add(n)}return[...t].sort()},[e]),{isActive:s,handleLegendClick:c}=z(o),l=(0,P.useMemo)(()=>e.map(e=>({...e,data:{...e.data,series:e.data.series.filter(e=>{let t=Rt(e.key);return t===null||s(t)}).map(e=>{let t=Rt(e.key);return t?{...e,color:e.color??L(t,o)}:e})}})),[e,s,o]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`flex-1 min-h-0`,style:{display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(${n}px, 1fr))`,gap:`1rem`},children:l.map((e,n)=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{id:`sm-panel-${n}-title`,"data-testid":`small-multiple-title`,style:{fontSize:12,fontWeight:600,marginBottom:4},children:e.title}),(0,F.jsx)(G,{data:e.data,theme:t,yAxis:e.yAxis,xDomain:i,height:r,fillParent:a,ariaLabel:`${e.title}: chart with ${e.data.series.length} series`,hideLegend:!0})]},e.title))}),o.length>0&&(0,F.jsx)(R,{nodeIds:o,isActive:s,onClickNode:c})]})}function Bt(e){return[...e].sort((e,t)=>Vt(t)-Vt(e))}function Vt(e){return e.points.reduce((e,t)=>e+(typeof t.y==`number`?t.y:0),0)}function Ht(e){let t=e.series.map(e=>e.label);return t.length===0?`Empty stacked area chart`:`Stacked area chart with ${t.length} series: ${t.slice(0,5).join(`, `)}${t.length>5?`…`:``}`}function Ut({active:e,payload:t,label:n,formatter:r,unitSuffix:i}){if(!e||!t||t.length===0)return null;let a=t.reduce((e,t)=>e+(typeof t.value==`number`?t.value:0),0),o=r===`count-si`?`count`:r;return(0,F.jsxs)(`div`,{style:Nt,children:[(0,F.jsx)(`div`,{style:Pt,children:n===void 0?``:jt(Number(n))}),t.map(e=>(0,F.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:12},children:[(0,F.jsx)(`span`,{style:{color:e.color},children:e.name}),(0,F.jsx)(`span`,{children:W(typeof e.value==`number`?e.value:0,r,i)})]},e.dataKey)),t.length>1?(0,F.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:12,marginTop:4,paddingTop:4,borderTop:`1px solid var(--border)`,fontWeight:600},children:[(0,F.jsx)(`span`,{children:`Total`}),(0,F.jsx)(`span`,{children:W(a,o,i)})]}):null]})}function Wt({data:e,theme:t,yAxis:n,height:r=240,ariaLabel:i,xDomain:a,fillParent:o,lineOnly:s}){let c=(0,P.useMemo)(()=>Bt(e.series),[e.series]);if(e.series.length===0)return(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`text-(--color-text-secondary) text-sm p-4`,children:`No data in window`});let l=[`#58a6ff`,`#3fb950`,`#f0883e`,`#bc8cff`,`#f778ba`,`#79c0ff`],u=new Set;for(let t of e.series)for(let e of t.points)u.add(e.x);if(e.ceiling)for(let t of e.ceiling.points)u.add(t.x);let d=e.series.map(e=>{let t=new Map;for(let n of e.points)t.set(n.x,n.y);return t}),f=e.ceiling?new Map(e.ceiling.points.map(e=>[e.x,e.y])):null,p=e.series.map(()=>null),h=null,g=[...u].sort((e,t)=>e-t).map(t=>{let n={x:t};return e.series.forEach((e,r)=>{let i=d[r];i.has(t)&&(p[r]=i.get(t)??null),n[e.key]=p[r]}),f&&e.ceiling&&(f.has(t)&&(h=f.get(t)??null),n.__ceiling__=h),n}),_=n?.formatter,v=n?.unit,b=t===`dark`?.5:.35;return(0,F.jsx)(`div`,{role:`img`,"aria-label":i??Ht(e),style:o?{width:`100%`,height:`100%`,minHeight:0,flex:`1 1 auto`,display:`flex`,flexDirection:`column`}:{width:`100%`,height:r},children:(0,F.jsx)(`div`,{"aria-hidden":`true`,style:{width:`100%`,height:`100%`},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,children:(0,F.jsxs)(re,{data:g,children:[(0,F.jsx)(E,{stroke:`var(--chart-grid)`,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`x`,type:`number`,domain:a??[`dataMin`,`dataMax`],allowDataOverflow:!!a,tickFormatter:At,tick:{fontSize:11}}),(0,F.jsx)(T,{tickFormatter:e=>W(e,_,v),tick:{fontSize:11},width:70}),(0,F.jsx)(m,{content:(0,F.jsx)(Ut,{formatter:_,unitSuffix:v})}),(0,F.jsx)(ce,{}),c.map((e,t)=>(0,F.jsx)(y,{type:`monotone`,dataKey:e.key,name:e.label,stackId:`1`,stroke:e.color??l[t%l.length],strokeWidth:s?2:1,fill:s?`none`:e.color??l[t%l.length],fillOpacity:s?0:b,connectNulls:!1},e.key)),e.ceiling?(0,F.jsx)(D,{type:`monotone`,dataKey:`__ceiling__`,name:e.ceiling.label,stroke:`#8b949e`,strokeWidth:2,strokeDasharray:`6 3`,dot:!1}):null]})})})})}function Gt(e){let[t,n]=(0,P.useState)(null);return{isActive:(0,P.useCallback)(e=>t===null||t.has(e),[t]),handleClick:(0,P.useCallback)((t,r)=>{n(n=>{if(r){if(n===null)return new Set(e.filter(e=>e!==t));let r=new Set(n);if(r.has(t)){if(r.delete(t),r.size===0)return null}else if(r.add(t),r.size===e.length)return null;return r}return n!==null&&n.size===1&&n.has(t)?null:new Set([t])})},[e]),activeValues:(0,P.useMemo)(()=>t===null?e:e.filter(e=>t.has(e)),[t,e])}}function Kt({values:e,isActive:t,onClick:n,colorFor:r,ariaLabel:i=`Type filter`}){return e.length===0?null:(0,F.jsx)(`div`,{role:`group`,"aria-label":i,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:e.map(e=>{let i=t(e),a=r?r(e):`var(--color-text-secondary)`;return(0,F.jsxs)(`button`,{type:`button`,"aria-pressed":i,"data-testid":`type-filter-chip`,"data-value":e,title:`Click to solo · Ctrl-click to toggle`,onClick:t=>n(e,t.ctrlKey||t.metaKey),className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:{color:a,opacity:i?1:.55},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:a}}),(0,F.jsx)(`span`,{children:e})]},e)})})}function K({spec:e,typeField:t,records:n,timeRange:r,nodes:i,theme:a,viewMode:o=`aggregate`,fillParent:s}){let[c,l]=(0,P.useState)(o===`per-node`?`node`:`type`),u=(0,P.useMemo)(()=>{let e=new Set;for(let r of n){let n=r[t];typeof n==`string`&&e.add(n)}return[...e].sort()},[n,t]),{isActive:d,handleClick:f}=Gt(u),{isActive:p,handleLegendClick:m}=z(i),h=u.length>0&&u.every(d),g=i.every(e=>p(e)),_=!(h&&g),v=(0,P.useMemo)(()=>n.filter(e=>{let n=e[t];return!(typeof n==`string`&&!d(n)||typeof e.node==`string`&&!p(e.node))}),[n,t,d,p]),y=(0,P.useMemo)(()=>c!==`node`||e.series.kind!==`groupBy`?e:{...e,series:{...e.series,dimension:`node`}},[e,c]),b=(0,P.useMemo)(()=>H(y,v,r,i,{snapToPeriod:!0}),[y,v,r,i]),x=(0,P.useMemo)(()=>({...b,series:b.series.map(e=>({...e,color:e.color??(c===`node`?L(e.key,i):ht(e.key,u))}))}),[b,c,i,u]),S=(0,P.useMemo)(()=>c===`grid`?i.filter(p).map(t=>{let n=H(e,v.filter(e=>e.node===t),r,[t],{snapToPeriod:!0});return{title:t,data:{...n,series:n.series.map(e=>({...e,color:e.color??ht(e.key,u)}))},yAxis:e.yAxis}}):null,[c,i,p,v,e,r,u]),C=i.length>1,w=[r.startTime,r.endTime];return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(Kt,{values:u,isActive:d,onClick:f,colorFor:e=>ht(e,u),ariaLabel:t===`type`?`Traffic type`:t===`database`?`Database`:`Protocol`}),C&&(0,F.jsx)(Jt,{stackBy:c,onChange:l}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:c===`grid`&&S?(0,F.jsx)(zt,{panels:S,theme:a,xDomain:w,fillParent:s}):(0,F.jsx)(Wt,{data:x,theme:a,yAxis:e.yAxis,xDomain:w,fillParent:s,lineOnly:_})}),i.length>0&&(0,F.jsx)(R,{nodeIds:i,isActive:p,onClickNode:m})]})}var qt=[{value:`type`,label:`Type`},{value:`node`,label:`Node`},{value:`grid`,label:`Per-node grid`}];function Jt({stackBy:e,onChange:t}){let n=Math.max(0,qt.findIndex(t=>t.value===e)),r=e=>{e.key!==`ArrowRight`&&e.key!==`ArrowLeft`&&e.key!==`ArrowDown`&&e.key!==`ArrowUp`||(e.preventDefault(),t(qt[(n+(e.key===`ArrowRight`||e.key===`ArrowDown`?1:-1)+qt.length)%qt.length].value))};return(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Stack by`,className:`flex flex-wrap items-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:[(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:`Stack by:`}),qt.map((i,a)=>{let o=e===i.value;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":o,tabIndex:a===n?0:-1,onKeyDown:r,"data-testid":`stack-by-button`,"data-value":i.value,onClick:()=>t(i.value),className:`inline-flex items-center cursor-pointer border-none bg-transparent p-0 text-(--color-text-secondary)`,style:{opacity:o?1:.55},children:i.label},i.value)})]})}var Yt={title:`Messages received by type (inner)`,description:`Inbound message rate — cluster total across nodes. Internal spec used by mqtt-traffic-received.recompute; not registered.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`count`,label:`messages/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Xt={id:`mqtt-traffic-received`,title:`Messages received by type`,subtitle:`Inbound message rate. Type chips solo / Ctrl-toggle; viewMode flips type/node stack.`,tab:`traffic`,sourceMetric:`bytes-received`,recompute:(e,t,n,r)=>{let i=(r??`per-node`)===`per-node`,a=Yt;return i&&Yt.series.kind===`groupBy`&&(a={...Yt,series:{...Yt.series,dimension:`node`}}),H(a,e,t,n,{snapToPeriod:!0})},Renderer:e=>(0,F.jsx)(K,{spec:Yt,typeField:`type`,...e}),primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Zt={title:`Messages sent by type (inner)`,description:`Outbound message rate — cluster total across nodes. Internal spec used by mqtt-traffic-sent.recompute; not registered.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`count`,label:`messages/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},Qt={id:`mqtt-traffic-sent`,title:`Messages sent by type`,subtitle:`Outbound message rate. Type chips solo / Ctrl-toggle; viewMode flips type/node stack.`,tab:`traffic`,sourceMetric:`bytes-sent`,recompute:(e,t,n,r)=>{let i=(r??`per-node`)===`per-node`,a=Zt;return i&&Zt.series.kind===`groupBy`&&(a={...Zt,series:{...Zt.series,dimension:`node`}}),H(a,e,t,n,{snapToPeriod:!0})},Renderer:e=>(0,F.jsx)(K,{spec:Zt,typeField:`type`,...e}),primitive:`stacked-area`,yAxis:{unit:` msg/s`,formatter:`count-si`}},$t=`var(--color-text-secondary)`;function en({dimensionValues:e,selected:t,onSelect:n,otherKey:r,colorFor:i,ariaLabel:a=`Dimension selector`}){let o=(0,P.useRef)([]);(0,P.useEffect)(()=>{o.current=o.current.slice(0,e.length)},[e.length]);let s=e.indexOf(t),c=s>=0?s:0;function l(t,r){if(t.key===`Enter`||t.key===` `){t.preventDefault(),n(e[r]);return}if(t.key!==`ArrowLeft`&&t.key!==`ArrowRight`&&t.key!==`ArrowDown`&&t.key!==`ArrowUp`)return;t.preventDefault();let i=e.length;if(i===0)return;let a=r;(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(a=(r+1)%i),(t.key===`ArrowLeft`||t.key===`ArrowUp`)&&(a=(r-1+i)%i),o.current[a]?.focus(),n(e[a])}return e.length===0&&!r?null:(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":a,"data-testid":`dimension-chip-row`,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:[e.map((e,r)=>{let a=e===t,s=i?i(e):$t;return(0,F.jsxs)(`button`,{ref:e=>{o.current[r]=e},type:`button`,role:`radio`,"aria-checked":a,tabIndex:r===c?0:-1,"data-testid":`dimension-chip`,"data-value":e,title:`Click to select`,onKeyDown:e=>l(e,r),onClick:()=>n(e),className:`inline-flex items-center gap-1.5 cursor-pointer border-none bg-transparent p-0`,style:{color:s,opacity:a?1:.55},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:s}}),(0,F.jsx)(`span`,{children:e})]},e)}),r&&(0,F.jsxs)(`span`,{"data-testid":`dimension-chip`,"data-value":r,"aria-disabled":`true`,title:`Aggregate of smaller buckets; not selectable.`,className:`inline-flex items-center gap-1.5 cursor-not-allowed`,style:{color:$t,opacity:.4},children:[(0,F.jsx)(`span`,{className:`inline-block h-[3px] w-3 rounded`,style:{backgroundColor:$t}}),(0,F.jsx)(`span`,{children:r})]})]})}function tn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function nn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,yAxis:a,thresholds:o,compute:s,fillParent:c}){let l=t?[t.startTime,t.endTime]:void 0,u=i===`per-node`,d=(0,P.useMemo)(()=>{let t=new Map;for(let n of e){let e=n.path;if(typeof e!=`string`)continue;let r=n.count,i=typeof r==`number`&&Number.isFinite(r)?r:0;t.set(e,(t.get(e)??0)+i)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e)},[e]),[f,p]=(0,P.useState)(``),m=d.includes(f)?f:u?d[0]??``:``,h=(0,P.useMemo)(()=>s(e,{perNode:u,selectedPath:m||null}),[e,u,m,s]),{isActive:g,handleLegendClick:_}=z(n),v=(0,P.useMemo)(()=>({...h,thresholds:o??h.thresholds,series:h.series.map(e=>u?{...e,label:tn(e.key),color:L(e.key,n)}:e).filter(e=>!u||g(e.key))}),[h,u,n,g,o]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[d.length>0&&(0,F.jsx)(en,{dimensionValues:d,selected:m,onSelect:p,ariaLabel:`Path`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:d.length>0?8:0},children:(0,F.jsx)(G,{data:v,theme:r,yAxis:a,xDomain:l,fillParent:c,hideLegend:u})}),u&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:g,onClickNode:_})]})}function rn(e,t,n){let r=new Map;for(let t of e){let e=typeof t.path==`string`?t.path:null;if(!e||typeof t.time!=`number`||!Number.isFinite(t.time))continue;let n=typeof t.count==`number`&&Number.isFinite(t.count)?t.count:0,i=typeof t.period==`number`&&t.period>0?t.period:6e4,a=r.get(e);a||(a=new Map,r.set(e,a));let o=a.get(t.time);o||(o={sumCount:0,period:i},a.set(t.time,o)),o.sumCount+=n}return{series:[...r.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e),r=n.period/1e3;return{x:e,y:r>0?n.sumCount/r:null,count:n.sumCount}})}))}}function an(e,{perNode:t,selectedPath:n}){if(t&&n){let t=new Map;for(let r of e){if(r.path!==n||typeof r.time!=`number`||!Number.isFinite(r.time))continue;let e=typeof r.node==`string`?r.node:`_no_node`,i=typeof r.count==`number`&&Number.isFinite(r.count)?r.count:0,a=typeof r.period==`number`&&r.period>0?r.period:6e4,o=t.get(e);o||(o=new Map,t.set(e,o));let s=o.get(r.time);s||(s={sumCount:0,period:a},o.set(r.time,s)),s.sumCount+=i}return{series:[...t.entries()].map(([e,t])=>({key:e,label:e,points:[...t.keys()].sort((e,t)=>e-t).map(e=>{let n=t.get(e),r=n.period/1e3;return{x:e,y:r>0?n.sumCount/r:null,count:n.sumCount}})}))}}return rn(n?e.filter(e=>e.path===n):e,{startTime:0,endTime:2**53-1},[])}var on={id:`request-rate`,title:`Request rate (req/s)`,subtitle:`Per-path req/s. Chip selects path; viewMode flips per-node lines / cluster aggregate.`,tab:`requests`,sourceMetric:`duration`,recompute:rn,Renderer:({records:e,timeRange:t,nodes:n,theme:r,viewMode:i})=>(0,F.jsx)(nn,{records:e,timeRange:t,nodes:n,theme:r,viewMode:i,yAxis:{unit:`/s`,formatter:`count-si`},compute:an}),primitive:`line`,yAxis:{unit:`/s`,formatter:`count-si`}};function sn(e,t,n){let r=new Map;for(let t of e){let e=typeof t.database==`string`?t.database:null;if(!e)continue;let n=typeof t.id==`number`?t.id:typeof t.time==`number`?t.time:null;if(n===null)continue;let i=typeof t.node==`string`?t.node:`_no_node`,a=typeof t.transactionLog==`number`&&Number.isFinite(t.transactionLog)?t.transactionLog:null;if(a===null)continue;let o=r.get(e);o||(o=new Map,r.set(e,o));let s=o.get(i);s||(s=[],o.set(i,s)),s.push({time:n,logBytes:a})}let i=6e4,a=[];for(let[e,t]of r.entries()){let n=new Map;for(let e of t.values()){e.sort((e,t)=>e.time-t.time);for(let t=1;t<e.length;t++){let r=e[t-1],a=e[t],o=a.time-r.time;if(o<=0)continue;let s=a.logBytes-r.logBytes;if(!Number.isFinite(s)||s<0)continue;let c=s*1e3/o;if(!Number.isFinite(c))continue;let l=o>=i?Math.round(a.time/i)*i:a.time;n.set(l,(n.get(l)??0)+c)}}let r=[...n.keys()].sort((e,t)=>e-t).map(e=>({x:e,y:n.get(e)}));a.push({key:e,label:e,points:r})}return{series:a}}var cn={"mqtt-traffic-sent":Qt,"mqtt-traffic-received":Xt,"request-rate":on,"error-rate":ft,"transaction-log-growth":{id:`transaction-log-growth`,title:`Transaction log growth`,subtitle:"Per-database transaction-log write rate (bytes/sec) — derived from `transactionLog` deltas in the database-size response.",tab:`storage`,sourceMetric:`database-size`,recompute:sn,primitive:`line`,yAxis:{unit:`/s`,formatter:`bytes-si`}}},ln={title:`Bytes received by type`,description:`Inbound byte rate (count × mean) — cluster total. Type chips solo / Ctrl-toggle.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:{kind:`op`,op:`*`,left:{kind:`ref`,field:`count`},right:{kind:`ref`,field:`mean`}},label:`bytes/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:`/s`,formatter:`bytes-si`}};function un(e){return(0,F.jsx)(K,{spec:ln,typeField:`type`,...e})}var dn={title:`Bytes sent by type`,description:`Outbound byte rate (count × mean) — cluster total. Type chips solo / Ctrl-toggle.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:{kind:`op`,op:`*`,left:{kind:`ref`,field:`count`},right:{kind:`ref`,field:`mean`}},label:`bytes/sec`,transform:{kind:`rate`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:`/s`,formatter:`bytes-si`}};function fn(e){return(0,F.jsx)(K,{spec:dn,typeField:`type`,...e})}var pn=`var(--color-text-secondary)`;function mn({dimensionValues:e,selected:t,onSelect:n,otherKey:r,colorFor:i,ariaLabel:a=`Dimension selector`}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(0),f=(0,P.useId)(),p=(0,P.useId)(),m=(0,P.useRef)(null),h=(0,P.useRef)(null),g=(0,P.useRef)(null),_=e.filter(e=>e.toLowerCase().includes(c.toLowerCase()));(0,P.useEffect)(()=>{o?h.current?.focus():l(``)},[o]),(0,P.useEffect)(()=>{if(!o)return;let e=e=>{let t=e.target;t&&(g.current?.contains(t)||m.current?.contains(t)||s(!1))},t=e=>{e.key===`Escape`&&(s(!1),m.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,P.useEffect)(()=>{d(0)},[c]);function v(e){n(e),s(!1),m.current?.focus()}function y(e){if(e.key===`Escape`){e.preventDefault(),s(!1),m.current?.focus();return}if(e.key===`ArrowDown`){e.preventDefault(),d(e=>Math.min(e+1,Math.max(0,_.length-1)));return}if(e.key===`ArrowUp`){e.preventDefault(),d(e=>Math.max(0,e-1));return}e.key===`Enter`&&_[u]!==void 0&&(e.preventDefault(),v(_[u]))}return(0,F.jsxs)(`div`,{className:`relative pt-3`,children:[(0,F.jsxs)(`button`,{ref:m,type:`button`,"aria-label":a,"aria-expanded":o,"aria-controls":f,"aria-haspopup":`listbox`,onClick:()=>s(e=>!e),className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-primary)`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:i?i(t):pn}}),t||`— select —`,(0,F.jsx)(`span`,{"aria-hidden":!0,children:`▾`})]}),o&&(0,F.jsxs)(`div`,{ref:g,className:`absolute z-10 mt-1 w-72 rounded-md border border-(--color-border) bg-(--color-surface) p-2 shadow-lg`,children:[(0,F.jsx)(`input`,{ref:h,role:`combobox`,type:`text`,"aria-label":`Filter ${a}`,"aria-expanded":o,"aria-controls":f,"aria-autocomplete":`list`,"aria-activedescendant":_[u]===void 0?``:`${p}-${u}`,value:c,onChange:e=>l(e.target.value),onKeyDown:y,placeholder:`Filter…`,className:`mb-2 w-full rounded border border-(--color-border) px-2 py-1 text-xs`}),_.length===0&&(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`px-2 py-1 text-xs text-(--color-text-secondary)`,children:`No matches`}),(0,F.jsx)(`ul`,{id:f,role:`listbox`,className:`max-h-56 overflow-auto`,children:_.map((e,n)=>{let r=e===t,a=n===u,o=i?i(e):pn;return(0,F.jsxs)(`li`,{id:`${p}-${n}`,role:`option`,"aria-selected":r,"data-active":a?`true`:void 0,onMouseDown:t=>{t.preventDefault(),v(e)},className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-xs ${a?`bg-(--color-surface-alt)`:``} ${r?`font-semibold`:``}`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:o}}),(0,F.jsx)(`span`,{className:`truncate`,children:e})]},e)})}),r&&(0,F.jsxs)(`div`,{className:`mt-2 border-t border-(--color-border) pt-2 text-xs text-(--color-text-secondary)/60`,title:`Aggregate of smaller buckets; not selectable.`,children:[r,` (aggregate; not selectable)`]})]})]})}var hn=`Other`,gn=12;function _n(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function q({spec:e,records:t,timeRange:n,nodes:r,theme:i,ariaLabel:a=`Dimension`,viewMode:o=`per-node`,fillParent:s}){let c=o===`per-node`,l=e.quantileSelector?.fields,[u,d]=(0,P.useState)(e.quantileSelector?.default??``),f=l?.some(e=>e.field===u)?u:e.quantileSelector?.default??``,p=(0,P.useMemo)(()=>{if(!l||f===``||e.series.kind!==`groupBy`)return e;let t=l.find(e=>e.field===f);return t?{...e,series:{...e.series,field:{...e.series.field,field:t.field,label:t.label}}}:e},[e,l,f]),m=(0,P.useMemo)(()=>H(p,t,n,r,{perNode:c,snapToPeriod:!0}),[p,t,n,r,c]),h=(0,P.useMemo)(()=>{let e=new Set;for(let t of m.series){if(t.key===hn)continue;let n=t.key.indexOf(`|`);e.add(n===-1?t.key:t.key.slice(0,n))}return[...e]},[m.series]),g=m.series.some(e=>e.key===hn),[_,v]=(0,P.useState)(()=>h[0]??``),y=h.includes(_)?_:h[0]??``,{isActive:b,handleLegendClick:x}=z(r),S=(0,P.useMemo)(()=>{let e=`${y}|`,t=m.series.filter(t=>t.key===y||t.key.startsWith(e)).map(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n?{...e,label:_n(n),color:L(n,r)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||b(n)});return{...m,series:t}},[m,y,r,b]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[e.quantileSelector&&l&&l.length>1&&(0,F.jsx)(`div`,{role:`radiogroup`,"aria-label":`Quantile`,className:`flex flex-wrap justify-center gap-x-3 gap-y-1 pt-2 text-[11px]`,children:l.map(e=>{let t=e.field===f;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,"data-testid":`quantile-button`,"data-value":e.field,onClick:()=>d(e.field),className:`inline-flex items-center cursor-pointer border-none bg-transparent p-0 text-(--color-text-secondary)`,style:{opacity:t?1:.3},children:e.label},e.field)})}),h.length>gn?(0,F.jsx)(mn,{dimensionValues:h,selected:y,onSelect:v,otherKey:g?hn:void 0,ariaLabel:a}):(0,F.jsx)(en,{dimensionValues:h,selected:y,onSelect:v,otherKey:g?hn:void 0,ariaLabel:a}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:S,theme:i,yAxis:e.yAxis,xDomain:[n.startTime,n.endTime],fillParent:s,hideLegend:c})}),c&&r.length>0&&(0,F.jsx)(R,{nodeIds:r,isActive:b,onClickNode:x})]})}var vn={title:`Cache hit rate`,description:`Per-path cache-hit ratio (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,series:{kind:`groupBy`,dimension:`path`,field:{field:`ratio`,label:`hit ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`,domain:[0,1]}};function yn(e){return(0,F.jsx)(q,{spec:vn,...e,ariaLabel:`Path`})}var J=[{field:`p1`,label:`p1`},{field:`p10`,label:`p10`},{field:`p25`,label:`p25`},{field:`median`,label:`p50`},{field:`p75`,label:`p75`},{field:`p90`,label:`p90`},{field:`p95`,label:`p95`},{field:`p99`,label:`p99`},{field:`p999`,label:`p999`}],bn={title:`Cache miss resolution (p95)`,description:`Per-path time-to-resolve a cache miss (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 resolution (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function xn(e){return(0,F.jsx)(q,{spec:bn,...e,ariaLabel:`Path`})}var Sn=`pathMethod`,Cn=` · `,wn={title:`Connection success ratio`,description:`Per-(path, method) connection ratio (count-weighted-mean). MQTT thresholds: connect ≥0.99, disconnect ≥0.2.`,tab:`traffic`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:Sn,field:{field:`ratio`,label:`success ratio`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:100,suppressBelow:500},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.99,label:`connect`,direction:`below-is-bad`,minCount:1e3,scope:{path:`mqtt`,method:`connect`}},{value:.2,label:`disconnect`,direction:`below-is-bad`,minCount:500,scope:{path:`mqtt`,method:`disconnect`}}]};function Tn(e,t){return typeof e!=`string`&&typeof e!=`number`||typeof t!=`string`&&typeof t!=`number`?null:`${e}${Cn}${t}`}function En(e){let t=[];for(let n of e){let e=n.path,r=n.method,i=Tn(e,r);if(i===null)continue;let a=n.total,o=n.count,s=a===0&&typeof o==`number`&&o>0;t.push({...n,[Sn]:i,ratio:s?null:n.ratio})}return t}function Dn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function On({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,s=(0,P.useMemo)(()=>En(e),[e]),c=(0,P.useMemo)(()=>H(wn,s,t,n,{perNode:o,snapToPeriod:!0}),[s,t,n,o]),l=(0,P.useMemo)(()=>{let e=new Set;for(let t of c.series){let n=t.key.indexOf(`|`);e.add(n===-1?t.key:t.key.slice(0,n))}return[...e]},[c.series]),[u,d]=(0,P.useState)(()=>l[0]??``),f=l.includes(u)?u:l[0]??``,p=(0,P.useMemo)(()=>{if(!f)return null;let[e,t]=f.split(Cn);return{path:e,method:t}},[f]),{isActive:m,handleLegendClick:h}=z(n),g=(0,P.useMemo)(()=>{function e(e){if(!p)return!1;if(!e.scope)return!0;for(let[t,n]of Object.entries(e.scope))if(p[t]!==n)return!1;return!0}let t=`${f}|`,r=c.series.filter(e=>e.key===f||e.key.startsWith(t)).map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Dn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||m(n)});return{...c,series:r,thresholds:(c.thresholds??[]).filter(e)}},[c,f,p,n,m]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:l,selected:f,onSelect:d,ariaLabel:`Path · method`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:g,theme:r,yAxis:wn.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:m,onClickNode:h})]})}var kn={title:`Connections`,description:`Active sessions by type — chips solo / Ctrl-toggle. viewMode flips type/node stack.`,tab:`traffic`,primaryDimension:`node`,subDimension:`type`,series:{kind:`groupBy`,dimension:`type`,field:{field:`connections`,label:`connections`,aggregator:{temporal:`max`,crossNode:`sum`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`max`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:``,formatter:`count-si`}};function An(e){return(0,F.jsx)(K,{spec:kn,typeField:`type`,...e})}var jn={title:`CPU — by scope (harper vs user)`,description:`Per-path CPU utilization (count-weighted-mean) — chip selector picks scope; quantile selector picks percentile.`,tab:`health`,primaryDimension:`path`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`CPU %`}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},quantileSelector:{fields:J,default:`p95`}};function Mn(e){return(0,F.jsx)(q,{spec:jn,...e,ariaLabel:`Scope`})}var Nn={title:`Database size`,description:`Per-database size in bytes — chips solo / Ctrl-toggle databases; node legend filters by node.`,tab:`storage`,primaryDimension:`database`,series:{kind:`groupBy`,dimension:`database`,field:{field:`size`,label:`size (bytes)`}},timestamp:`id`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`sum`},primitive:`stacked-area`,yAxis:{unit:` B`,formatter:`bytes-si`}};function Pn(e){return(0,F.jsx)(K,{spec:Nn,typeField:`database`,...e,viewMode:e.viewMode??`aggregate`})}var Fn={title:`DB message p95`,description:`Per-table DB message p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 message (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function In(e){return(0,F.jsx)(q,{spec:Fn,...e,ariaLabel:`Table`})}var Ln={title:`DB read p95`,description:`Per-table DB read p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 read (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Rn(e){return(0,F.jsx)(q,{spec:Ln,...e,ariaLabel:`Table`})}var zn={title:`DB write p95`,description:`Per-table DB write p95 (count-weighted-mean) — top 10 tables + Other.`,tab:`db-activity`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 write (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Bn(e){return(0,F.jsx)(q,{spec:zn,...e,ariaLabel:`Table`})}var Vn={title:`Request duration (p95)`,description:`Per-path request duration p95 (count-weighted-mean) — top 10 paths + Other bucket.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 duration (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Hn(e){return(0,F.jsx)(q,{spec:Vn,...e,ariaLabel:`Path`})}var Y=[{key:`utilization`,label:`Utilization`,field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`active`},right:{kind:`op`,op:`+`,left:{kind:`ref`,field:`active`},right:{kind:`ref`,field:`idle`}}},yAxis:{unit:``,formatter:`percent`}},{key:`taskQueueLatency`,label:`Queue lag`,field:`taskQueueLatency`,yAxis:{unit:``,formatter:`ms`}},{key:`active`,label:`Active time`,field:`active`,yAxis:{unit:``,formatter:`ms`}},{key:`idle`,label:`Idle time`,field:`idle`,yAxis:{unit:``,formatter:`ms`}}],Un=Y.map(e=>e.key),Wn={title:`Main thread utilization`,description:`Per-node main-thread metrics — chip selector picks utilization / queue lag / active time / idle time.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[{field:Y[0].field,label:Y[0].label}]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`mean`},primitive:`line`,yAxis:Y[0].yAxis,layout:{colSpan:2}};function Gn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Kn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,[s,c]=(0,P.useState)(Y[0].key),l=Un.includes(s)?s:Y[0].key,u=Y.find(e=>e.key===l),d=(0,P.useMemo)(()=>H({...Wn,series:{kind:`field`,fields:[{field:u.field,label:u.label}]},yAxis:u.yAxis},e,t,n,{perNode:o,snapToPeriod:!0}),[u,e,t,n,o]),{isActive:f,handleLegendClick:p}=z(n),m=(0,P.useMemo)(()=>({...d,series:d.series.map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Gn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||f(n)})}),[d,n,f]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:Un.map(e=>Y.find(t=>t.key===e).label),selected:u.label,onSelect:e=>{let t=Y.find(t=>t.label===e);t&&c(t.key)},ariaLabel:`Main thread metric`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:m,theme:r,yAxis:u.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:f,onClickNode:p})]})}var qn=[{field:`heapUsed`,label:`heap used`},{field:`heapTotal`,label:`heap total`},{field:`external`,label:`external`},{field:`arrayBuffers`,label:`arrayBuffers`}],Jn={title:`Process memory`,description:`Per-node V8 memory — chip selector picks the field. Default heap used.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[...qn]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`mean`},primitive:`line`,yAxis:{unit:` B`,formatter:`bytes-si`}};function Yn(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}var Xn=qn.map(e=>e.label);function Zn({records:e,timeRange:t,nodes:n,theme:r,viewMode:i=`per-node`,fillParent:a}){let o=i===`per-node`,[s,c]=(0,P.useState)(qn[0].label),l=Xn.includes(s)?s:qn[0].label,u=qn.find(e=>e.label===l),d=(0,P.useMemo)(()=>H({...Jn,series:{kind:`field`,fields:[u]}},e,t,n,{perNode:o,snapToPeriod:!0}),[u,e,t,n,o]),{isActive:f,handleLegendClick:p}=z(n),m=(0,P.useMemo)(()=>({...d,series:d.series.map(e=>{let t=e.key.indexOf(`|`),r=t===-1?``:e.key.slice(t+1);return r?{...e,label:Yn(r),color:L(r,n)}:e}).filter(e=>{let t=e.key.indexOf(`|`),n=t===-1?``:e.key.slice(t+1);return n===``||f(n)})}),[d,n,f]);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(en,{dimensionValues:Xn,selected:l,onSelect:c,ariaLabel:`Memory field`}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,style:{marginTop:8},children:(0,F.jsx)(G,{data:m,theme:r,yAxis:Jn.yAxis,xDomain:[t.startTime,t.endTime],fillParent:a,hideLegend:o})}),o&&n.length>0&&(0,F.jsx)(R,{nodeIds:n,isActive:f,onClickNode:p})]})}function Qn(e,t,n,r,i,a){if(t<=0)return a;let o=e-n-r*Math.max(0,t-1),s=Math.floor(o/t);return Math.max(i,Math.min(a,s))}var $n=[`#fef3c7`,`#fcd34d`,`#f59e0b`,`#dc2626`,`#7f1d1d`],er=[`#713f12`,`#b45309`,`#d97706`,`#f59e0b`,`#fef3c7`];function tr(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function nr(e){let t=e.replace(`#`,``),n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return .2126*tr(n)+.7152*tr(r)+.0722*tr(i)}function rr(e){let t=e.replace(`#`,``);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function ir(e,t,n){let r=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function ar(e,t){if(t<=0)return e[0];if(t>=1)return e[e.length-1];let n=t*(e.length-1),r=Math.floor(n),i=n-r,[a,o,s]=rr(e[r]),[c,l,u]=rr(e[r+1]);return ir(a+(c-a)*i,o+(l-o)*i,s+(u-s)*i)}function or(e,t,n){if(!e||e.value===null||e.value===void 0)return`absent`;let r=e.count??0;return r<t?`suppress`:r<n?`grey`:`ok`}function sr(e,t){return e.length>t?e.slice(0,t-1)+`…`:e}function cr(e,t,n,r,i,a,o){let s=`${e} → ${t}: `,c=o?` (approx)`:``;if(r===`absent`)return`${s}no data`;if(r===`suppress`)return`${s}insufficient samples (n<${a}), value hidden`;let l=n?.value??0,u=n?.count??0;return r===`grey`?`${s}${l} ${i} p95 (approx, low-confidence: ${u} samples below threshold)`:`${s}${l} ${i} p95${c}, ${u} samples`}function lr({stops:e,vmin:t,vmax:n,width:r,axis:i,approx:a}){let o=(0,P.useId)(),s=i?.unit??``,c=e=>W(e,i?.formatter),l=(t+n)/2,u=Math.max(200,Math.min(r,480));return(0,F.jsxs)(`svg`,{role:`img`,"aria-label":`${a?`p95 latency (count-weighted-mean, approx)`:`p95 latency`}: ${c(t)}–${c(n)} ${s}. Higher value = worse latency.`,width:u+80,height:40,style:{overflow:`visible`},children:[(0,F.jsx)(`defs`,{children:(0,F.jsx)(`linearGradient`,{id:o,x1:`0%`,x2:`100%`,y1:`0%`,y2:`0%`,children:e.map((t,n)=>(0,F.jsx)(`stop`,{offset:`${n/(e.length-1)*100}%`,stopColor:t},t+n))})}),(0,F.jsx)(`text`,{x:0,y:14,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:`low`}),(0,F.jsx)(`rect`,{x:30,y:0,width:u,height:12,fill:`url(#${o})`,"aria-hidden":`true`}),(0,F.jsx)(`text`,{x:30+u+4,y:14,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:`high`}),(0,F.jsx)(`text`,{x:30,y:30,fontSize:10,fill:`currentColor`,"aria-hidden":`true`,children:c(t)}),(0,F.jsx)(`text`,{x:30+u/2,y:30,fontSize:10,fill:`currentColor`,textAnchor:`middle`,"aria-hidden":`true`,children:c(l)}),(0,F.jsx)(`text`,{x:30+u,y:30,fontSize:10,fill:`currentColor`,textAnchor:`end`,"aria-hidden":`true`,children:c(n)})]})}var ur=40,dr=80,X=4,fr=72,Z=200;function pr({data:e,theme:t,title:n,height:r}){let i=(0,P.useId)(),a=(0,P.useId)(),o=(0,P.useId)(),s=e.confidence?.greyBelow??0,c=e.confidence?.suppressBelow??0,l=t===`dark`?er:$n,u=e.approx===!0,d=e.axis?.unit??``,f=(0,P.useMemo)(()=>{let t=new Map;for(let n of e.cells)t.set(`${n.row}|${n.col}`,n);return t},[e.cells]),[p,m]=(0,P.useMemo)(()=>{if(e.valueRange)return[e.valueRange.min,e.valueRange.max];let t=1/0,n=-1/0;for(let r of e.cells)r.value!==null&&r.value!==void 0&&Number.isFinite(r.value)&&(r.value<t&&(t=r.value),r.value>n&&(n=r.value));return!Number.isFinite(t)||!Number.isFinite(n)?[0,1]:t===n?[t,t+1]:[t,n]},[e.cells,e.valueRange]),h=e.rows,g=e.cols,_=(0,P.useRef)(null),[v,y]=(0,P.useState)(dr),b=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{y(Qn(_.current?.clientWidth??0,g.length,Z,X,ur,dr))},[g.length]),(0,P.useEffect)(()=>{let e=_.current;if(!e)return;let t=new ResizeObserver(()=>{b.current!==null&&cancelAnimationFrame(b.current),b.current=requestAnimationFrame(()=>{b.current=null;let t=e.clientWidth;y(Qn(t,g.length,Z,X,ur,dr))})});return t.observe(e),()=>{t.disconnect(),b.current!==null&&cancelAnimationFrame(b.current)}},[g.length]);let x=g.length*v+(g.length-1)*X,S=h.length*v+(h.length-1)*X,C=Z+x+8,w=fr+S+8,[ee,te]=(0,P.useState)([0,0]),T=(0,P.useRef)(new Map),E=(0,P.useCallback)((e,t)=>{let n=T.current.get(`${e}|${t}`);n&&(te([e,t]),n.focus())},[]),ne=(0,P.useCallback)((e,t,n)=>{let r=e.key,i=!1,a=t,o=n;r===`ArrowRight`?(i=!0,o=Math.min(g.length-1,n+1)):r===`ArrowLeft`?(i=!0,o=Math.max(0,n-1)):r===`ArrowDown`?(i=!0,a=Math.min(h.length-1,t+1)):r===`ArrowUp`?(i=!0,a=Math.max(0,t-1)):r===`Home`?(i=!0,o=0):r===`End`?(i=!0,o=g.length-1):r===`PageUp`?(i=!0,a=Math.max(0,t-5)):r===`PageDown`&&(i=!0,a=Math.min(h.length-1,t+5)),i&&(e.preventDefault(),e.stopPropagation(),(a!==t||o!==n)&&E(a,o))},[h.length,g.length,E]),re=e=>e.startsWith(`#`)?nr(e)>.5?`#000000`:`#ffffff`:`#000000`;return(0,F.jsxs)(`div`,{style:{position:`relative`},children:[e.skippedRecordsCount>0?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning)`,background:`color-mix(in srgb, var(--color-warning) 12%, transparent)`,color:`currentColor`},children:`${e.skippedRecordsCount} record(s) omitted — source node unrecognized (cluster node list may be outdated).`},e.skippedRecordsCount):null,(0,F.jsx)(`p`,{id:i,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:n??`Heatmap`}),(0,F.jsx)(`p`,{id:a,"data-testid":`heatmap-desc`,style:{position:`absolute`,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:0},children:`${u?`Cells show count-weighted-mean p95 latency (approx).`:`Cells show p95 latency.`} Cells with fewer than ${c} samples are blank; ${s}–${c-1} render grey.`}),(0,F.jsx)(`div`,{ref:_,style:{width:`100%`,display:`block`,overflowX:`auto`},children:(0,F.jsxs)(`svg`,{role:`grid`,"aria-labelledby":i,"aria-describedby":a,width:C,height:r??w,viewBox:`0 0 ${C} ${w}`,"data-cell-size":v,style:{overflow:`visible`,display:`block`},children:[(0,F.jsx)(`defs`,{children:(0,F.jsxs)(`pattern`,{id:o,patternUnits:`userSpaceOnUse`,width:8,height:8,patternTransform:`rotate(45)`,children:[(0,F.jsx)(`rect`,{width:8,height:8,fill:t===`dark`?`#1f2937`:`#f3f4f6`}),(0,F.jsx)(`line`,{x1:0,y1:0,x2:0,y2:8,stroke:t===`dark`?`#4b5563`:`#9ca3af`,strokeWidth:2})]})}),(0,F.jsxs)(`g`,{role:`row`,children:[(0,F.jsx)(`rect`,{x:0,y:0,width:Z,height:fr,fill:`transparent`,"aria-hidden":`true`}),g.map((e,t)=>{let n=Z+t*(v+X)+v/2,r=fr-8,i=v<56?8:20;return(0,F.jsx)(`g`,{role:`columnheader`,"aria-label":e,children:(0,F.jsxs)(`text`,{x:n,y:r,fontSize:11,textAnchor:`end`,transform:`rotate(-45, ${n}, ${r})`,fill:`currentColor`,children:[sr(e,i),(0,F.jsx)(`title`,{children:e})]})},e)})]}),h.map((e,n)=>{let r=fr+n*(v+X);return(0,F.jsxs)(`g`,{role:`row`,children:[(0,F.jsx)(`g`,{role:`rowheader`,"aria-label":e,children:(0,F.jsxs)(`text`,{x:Z-8,y:r+v/2+4,fontSize:12,textAnchor:`end`,fill:`currentColor`,children:[sr(e,24),(0,F.jsx)(`title`,{children:e})]})}),g.map((i,a)=>{let h=f.get(`${e}|${i}`),g=or(h,s,c),_=Z+a*(v+X),y=r,b=cr(e,i,h,g,d,c,u),x=ee[0]===n&&ee[1]===a,S=`transparent`,C,w=1,E,D=0;g===`absent`?(S=`transparent`,C=`3 3`,E=t===`dark`?`#4b5563`:`#9ca3af`,D=1):g===`suppress`?(S=`url(#${o})`,C=`3 3`,E=t===`dark`?`#4b5563`:`#9ca3af`,D=1):(S=ar(l,m>p?((h?.value??0)-p)/(m-p):0),g===`grey`&&(w=.55,C=`4 2`,E=t===`dark`?`#6b7280`:`#9ca3af`,D=1));let ie=re(g===`ok`||g===`grey`?ar(l,m>p?((h?.value??0)-p)/(m-p):0):`#808080`);return(0,F.jsxs)(`g`,{ref:e=>{e?T.current.set(`${n}|${a}`,e):T.current.delete(`${n}|${a}`)},role:`gridcell`,"aria-label":b,"data-confidence":g,tabIndex:x?0:-1,onKeyDown:e=>ne(e,n,a),onFocus:()=>te([n,a]),style:{outline:`none`,cursor:`default`},children:[(0,F.jsx)(`rect`,{x:_,y,width:v,height:v,rx:4,ry:4,style:{fill:S},opacity:w,stroke:E,strokeWidth:D,strokeDasharray:C,children:(0,F.jsx)(`title`,{children:b})}),x?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`rect`,{x:_-1,y:y-1,width:v+2,height:v+2,rx:5,ry:5,fill:`none`,stroke:ie,strokeWidth:1,pointerEvents:`none`}),(0,F.jsx)(`rect`,{x:_,y,width:v,height:v,rx:4,ry:4,fill:`none`,stroke:`var(--color-accent, #3b82f6)`,strokeWidth:1,pointerEvents:`none`})]}):null]},i)})]},e)})]})}),(0,F.jsx)(`div`,{style:{marginTop:8},children:(0,F.jsx)(lr,{stops:l,vmin:p,vmax:m,width:x,axis:e.axis,approx:u})})]})}function mr(e,t){if(typeof e!=`string`||e.length===0)return null;let n=[...t].sort((e,t)=>t.length-e.length);for(let t of n){if(!e.startsWith(t+`.`))continue;let n=e.slice(t.length+1),r=n.indexOf(`.`);if(r===-1)return null;let i=n.slice(0,r),a=n.slice(r+1);return i.length===0||a.length===0?null:{source:t,database:i,table:a}}let r=e.split(`.`);if(r.length<3)return null;let i=r[r.length-1],a=r[r.length-2],o=r.slice(0,-2).join(`.`);return!o||!a||!i?null:{source:o,database:a,table:i}}var hr={title:`Replication latency`,description:`Source → destination p95 latency, count-weighted-mean across the window. Approximate.`,tab:`replication`,primaryDimension:`path`,subDimension:`node`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 latency`}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`heatmap`,yAxis:{unit:``,formatter:`ms`}};function gr(e,t,n){return e===1?t:n}function _r(e,t,n){let r=0,i=[],a=new Set,o=new Set(t);for(let s of e){let e=mr(typeof s.path==`string`?s.path:``,t);if(!e){r++;continue}o.has(e.source)||a.add(e.source);let c=s[n],l=typeof c==`number`?c:NaN,u=typeof s.count==`number`?s.count:0;if(!Number.isFinite(l)){r++;continue}i.push({source:e.source,destination:s.node,value:l,count:u,time:typeof s.time==`number`?s.time:0})}return{parsed:i,skipped:r,unrecognizedSources:[...a].sort()}}function vr(e,t,n=`p95`){let{parsed:r,skipped:i,unrecognizedSources:a}=_r(e,t,n);if(r.length===0)return{rows:[],cols:[],cells:[],axis:{unit:``,formatter:`ms`},confidence:{greyBelow:40,suppressBelow:100},rowAxisLabel:`Source`,colAxisLabel:`Destination`,skippedRecordsCount:i,unrecognizedSources:a,approx:!0};let o=new Map,s=new Set,c=new Set;for(let e of r){s.add(e.source),c.add(e.destination);let t=`${e.source}|${e.destination}`,n=o.get(t);n||(n={items:[],totalCount:0},o.set(t,n)),n.items.push({value:e.value,count:e.count}),n.totalCount+=e.count}let l=[...s].sort(),u=[...c].sort(),d=!1,f=[];for(let e of l)for(let t of u){let n=o.get(`${e}|${t}`);n?(n.items.length>1&&(d=!0),f.push({row:e,col:t,value:B(`count-weighted-mean`,n.items),count:n.totalCount})):f.push({row:e,col:t,value:null,count:0})}return{rows:l,cols:u,cells:f,axis:{unit:``,formatter:`ms`},confidence:{greyBelow:40,suppressBelow:100},rowAxisLabel:`Source`,colAxisLabel:`Destination`,skippedRecordsCount:i,unrecognizedSources:a,approx:d}}function yr(e,t,n,r,i=`p95`){let a=[];for(let o of e){if(o.node!==n)continue;let e=mr(typeof o.path==`string`?o.path:``,r);if(!e||e.source!==t||typeof o.time!=`number`)continue;let s=o[i],c=typeof s==`number`?s:NaN;if(!Number.isFinite(c))continue;let l=typeof o.count==`number`?o.count:0;a.push({time:o.time,value:c,count:l})}let o=new Map,s=new Map;for(let e of a){let t=o.get(e.time);t||(t=[],o.set(e.time,t)),t.push({value:e.value,count:e.count}),s.set(e.time,(s.get(e.time)??0)+e.count)}let c=!1,l=[...o.keys()].sort((e,t)=>e-t),u=[];for(let e of l){let t=o.get(e);t.length>1&&(c=!0),u.push({x:e,y:B(`count-weighted-mean`,t),count:s.get(e)??0})}return{points:u,approx:c}}var br=12;function xr(e,t,n,r){let i=n.confidence?.greyBelow??0,a=n.confidence?.suppressBelow??1/0,o=[],s=0;for(let c of n.cells){let n=c.count??0;if(n===0)continue;if(n<i){s+=1;continue}let l=yr(e,c.row,c.col,t,r);if(l.points.length===0)continue;let u=`${c.row}→${c.col}`;n<a?o.push({key:u,label:u,points:l.points,approx:l.approx,opacity:.55}):o.push({key:u,label:u,points:l.points,approx:l.approx})}return{seriesData:{series:o},omittedPairsCount:s}}function Sr(e){let{records:t,nodes:n,theme:r,timeRange:i,fillParent:a}=e,[o,s]=(0,P.useState)(`p95`),c=(0,P.useMemo)(()=>vr(t,n,o),[t,n,o]);if(c.rows.length===0||c.cols.length===0)return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(Cr,{data:c,theme:r}),(0,F.jsx)(`div`,{children:`No data in window`})]});let l=c.rows.length*c.cols.length>br;if(c.rows.length<2||c.cols.length<2||l){let{seriesData:e,omittedPairsCount:s}=xr(t,n,c,o),u=c.confidence?.greyBelow??40,d=l?`Too many source-destination pairs for a heatmap — showing as lines.`:`Only one source node emitted data in this window. This is typical for clusters with a single write origin — each line below shows latency from that source to one destination.`,f=e.series.length===0&&s>0,p=e.series.length===0&&s===0,m={marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning, #f59e0b)`,background:r===`dark`?`#1f2937`:`#fffbeb`,color:`currentColor`};return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:4},children:`Showing as lines`}),c.skippedRecordsCount>0?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:c.unrecognizedSources&&c.unrecognizedSources.length>0?`${c.skippedRecordsCount} record(s) omitted (no value for the selected percentile). Sources recovered via heuristic: ${c.unrecognizedSources.join(`, `)}.`:`${c.skippedRecordsCount} record(s) omitted (no value for the selected percentile).`},c.skippedRecordsCount):null,s>0&&!f?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:`${s} source-destination ${gr(s,`pair`,`pairs`)} hidden — fewer than ${u} samples.`},s):null,(0,F.jsx)(`div`,{style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-info, #3b82f6)`,background:r===`dark`?`#0f172a`:`#eff6ff`,color:`currentColor`},children:d}),f?(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:m,children:`No source-destination pairs cleared the confidence threshold (${u}+ samples). All ${s} ${gr(s,`pair`,`pairs`)} had fewer than ${u} samples in this window.`}):p?(0,F.jsx)(`div`,{children:`No data in window`}):(0,F.jsx)(`div`,{style:{marginTop:20},children:(0,F.jsx)(G,{data:e,theme:r,yAxis:c.axis,height:320,xDomain:[i.startTime,i.endTime],fillParent:a})})]})}return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(wr,{value:o,onChange:s}),(0,F.jsx)(Cr,{data:c,theme:r}),(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,F.jsx)(pr,{data:c,theme:r,title:`Replication latency`})})]})}function Cr({data:e,theme:t}){let n=e.skippedRecordsCount,r=e.unrecognizedSources??[];if(n===0&&r.length===0)return null;let i=[];return n>0&&i.push(`${n} record${n===1?``:`s`} omitted (no value for the selected percentile).`),r.length>0&&i.push(`Recovered ${r.length} source${r.length===1?``:`s`} not in the cluster snapshot: ${r.join(`, `)}.`),(0,F.jsx)(`div`,{role:`status`,"aria-atomic":`true`,style:{marginBottom:8,padding:`4px 8px`,fontSize:12,borderLeft:`3px solid var(--color-warning, #f59e0b)`,background:t===`dark`?`#1f2937`:`#fffbeb`,color:`currentColor`},children:i.join(` `)},`${n}-${r.length}`)}function wr({value:e,onChange:t}){return(0,F.jsx)(`div`,{role:`radiogroup`,"aria-label":`Quantile`,className:`flex flex-wrap gap-1 pb-2`,children:J.map(n=>{let r=n.field===e;return(0,F.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r,"data-testid":`quantile-button`,"data-value":n.field,onClick:()=>t(n.field),className:`rounded px-2 py-0.5 text-[11px] ${r?`bg-(--color-accent)/20 text-(--color-text-primary) font-semibold`:`bg-(--color-bg-tertiary) text-(--color-text-secondary) hover:text-(--color-text-primary)`}`,children:n.label},n.field)})})}var Tr={title:`Resource usage`,description:`CPU + I/O + page faults + context switches per node — small-multiples view.`,tab:`health`,primaryDimension:`node`,series:{kind:`field`,fields:[{field:`cpuUtilization`,label:`Process CPU (cores used)`,aggregator:{temporal:`max`,crossNode:`max`},yAxis:{unit:``,formatter:`cores`}},{field:`fsWrite`,label:`Disk write (B/s)`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`sum`},yAxis:{unit:`/s`,formatter:`bytes-si`}},{field:`majorPageFault`,label:`Major page faults /s`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`max`},yAxis:{unit:`/s`,formatter:`count-si`}},{field:{kind:`op`,op:`+`,left:{kind:`ref`,field:`voluntaryContextSwitches`},right:{kind:`ref`,field:`involuntaryContextSwitches`}},label:`Context switches /s`,transform:{kind:`rate`},aggregator:{temporal:`sum`,crossNode:`max`},yAxis:{unit:`/s`,formatter:`count-si`}}]},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`sum`,crossNode:`sum`},primitive:`small-multiples`,yAxis:{unit:``,formatter:`count`},layout:{colSpan:2}},Er={title:`HTTP 200 ratio`,description:`Per-path 2xx ratio (mean across nodes; count-weighted across time). Threshold 99.9%, min count 1000.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`total`},right:{kind:`ref`,field:`count`}},label:`200 ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.999,label:`99.9% SLO`,direction:`below-is-bad`,minCount:1e3}]};function Dr(e){return(0,F.jsx)(q,{spec:Er,...e,ariaLabel:`Path`})}var Or={title:`Storage volume (available)`,description:`Per-node disk available bytes (latest snapshot in window; mean across nodes).`,tab:`storage`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`available`,label:`available (bytes)`}},timestamp:`id`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`last`,crossNode:`mean`},primitive:`line`,yAxis:{unit:` B`,formatter:`bytes-si`}},kr={title:`Request success rate`,description:`Per-path success ratio (count-weighted-mean) — alert when ≥0.001 errors and Σcount ≥1000.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:{kind:`op`,op:`/`,left:{kind:`ref`,field:`total`},right:{kind:`ref`,field:`count`}},label:`success ratio`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.999,label:`99.9% SLO`,direction:`below-is-bad`,minCount:1e3}]};function Ar(e){return(0,F.jsx)(q,{spec:kr,...e,ariaLabel:`Path`})}var jr={title:`TLS session reuse ratio`,description:`Fraction of TLS handshakes resumed via session ticket — higher is better.`,tab:`traffic`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`ratio`,label:`reuse ratio`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:20,suppressBelow:50},primitive:`line`,yAxis:{unit:``,formatter:`percent`},thresholds:[{value:.5,label:`50% reuse target`,direction:`below-is-bad`,minCount:50}]},Mr={title:`Transfer duration (p95)`,description:`Per-path transfer p95 (count-weighted-mean) — top 10 paths + Other.`,tab:`requests`,primaryDimension:`path`,subDimension:`method`,series:{kind:`groupBy`,dimension:`path`,field:{field:`p95`,label:`p95 transfer (ms)`},topN:10,otherBucket:!0},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`count-weighted-mean`,crossNode:`count-weighted-mean`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`ms`},quantileSelector:{fields:J,default:`p95`}};function Nr(e){return(0,F.jsx)(q,{spec:Mr,...e,ariaLabel:`Path`})}var Pr={"replication-latency":{spec:hr,Renderer:Sr},"bytes-sent":{spec:dn,Renderer:fn},"bytes-received":{spec:ln,Renderer:un},"resource-usage":{spec:Tr},connections:{spec:kn,Renderer:An},duration:{spec:Vn,Renderer:Hn},success:{spec:kr,Renderer:Ar},transfer:{spec:Mr,Renderer:Nr},"tls-reused":{spec:jr},connection:{spec:wn,Renderer:On},"cpu-usage":{spec:jn,Renderer:Mn},"db-read":{spec:Ln,Renderer:Rn},"db-write":{spec:zn,Renderer:Bn},"db-message":{spec:Fn,Renderer:In},response_200:{spec:Er,Renderer:Dr},utilization:{spec:{title:`Cluster utilization`,description:`Active / (active + idle) per node — count-weighted-mean across time.`,tab:`health`,primaryDimension:`node`,series:{kind:`groupBy`,dimension:`node`,field:{field:`utilization`,label:`utilization`,transform:{kind:`ratio`}}},timestamp:`time`,bucket:{source:`period-field`,fallbackMs:6e4},aggregator:{temporal:`mean`,crossNode:`max`},confidence:{field:`count`,greyBelow:40,suppressBelow:100},primitive:`line`,yAxis:{unit:``,formatter:`percent`}}},"database-size":{spec:Nn,Renderer:Pn},"storage-volume":{spec:Or},memory:{spec:Jn,Renderer:Zn},"main-thread-utilization":{spec:Wn,Renderer:Kn},"cache-hit":{spec:vn,Renderer:yn},"cache-resolution":{spec:bn,Renderer:xn}},Fr={"request-rate":[`count`,`period`],"error-rate":[`count`,`errors`]};function Ir(e){let t=Fr[e];if(t)return t;if(cn[e])return[];let n=Pr[e];return n?.spec?Lr(n.spec):[]}function Lr(e){let t=new Set,n=e.series,r=!1;if(n.kind===`field`)for(let e of n.fields)zr(e,t),Rr(e.transform)&&(r=!0);else zr(n.field,t),Rr(n.field.transform)&&(r=!0),n.dimension&&n.dimension!==`node`&&t.add(n.dimension);return r&&t.add(`period`),[...t]}function Rr(e){if(!e)return!1;switch(e.kind){case`rate`:return!0;case`compose`:return e.steps.some(Rr);default:return!1}}function zr(e,t){Br(e.field,t)}function Br(e,t){if(typeof e==`string`){t.add(e);return}switch(e.kind){case`ref`:t.add(e.field);return;case`const`:return;case`op`:Br(e.left,t),Br(e.right,t);return}}var Vr=new Set([`time`,`node`,`id`,`period`,`metric`,`count`,`threadId`,`path`,`method`,`type`,`database`,`table`,`source`]),Hr=8;function Ur(e){let t=new Map;for(let n of e)for(let e of Object.keys(n))Vr.has(e)||typeof n[e]==`number`&&Number.isFinite(n[e])&&t.set(e,(t.get(e)??0)+1);let n=Math.max(1,Math.floor(e.length/2));return[...t.entries()].filter(([,e])=>e>=n).map(([e])=>e)}function Wr({metric:e,records:t,theme:n,hint:r}){let i=Ur(t),a=i.slice(0,Hr),o=i.length-a.length,s=a.map(e=>({title:e,data:{series:[{key:e,label:e,points:t.filter(t=>typeof t[e]==`number`).map(t=>({x:typeof t.time==`number`?t.time:0,y:t[e]}))}]}})),c=e.replace(/_/g,`-`);return(0,F.jsxs)(`div`,{children:[r&&(0,F.jsx)(`div`,{role:`status`,style:{fontSize:12,padding:`4px 8px`,marginBottom:8,background:`color-mix(in srgb, var(--color-text-secondary) 10%, transparent)`,color:`var(--color-text-secondary)`,border:`1px solid color-mix(in srgb, var(--color-text-secondary) 30%, transparent)`,borderRadius:4},children:r}),null,(0,F.jsx)(zt,{panels:s,theme:n}),o>0&&(0,F.jsx)(`div`,{style:{fontSize:11,marginTop:4,opacity:.7},children:`… and ${o} more fields not shown. Add a spec at src/lib/metricSpecs/${c}.ts to customize.`})]})}function Gr(e){let t=e.indexOf(`|`);return t===-1?e:e.slice(t+1)}function Kr({data:e,theme:t,yAxis:n,xDomain:r,fillParent:i}){let a=(0,P.useMemo)(()=>{let t=new Set;for(let n of e.series){let e=Gr(n.key);e&&t.add(e)}return[...t].sort()},[e]),{isActive:o,handleLegendClick:s}=z(a);return(0,F.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,F.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,F.jsx)(G,{data:(0,P.useMemo)(()=>({...e,series:e.series.filter(e=>{let t=Gr(e.key);return t===null||o(t)}).map(e=>{let t=Gr(e.key);return t?{...e,color:e.color??L(t,a)}:e})}),[e,o,a]),theme:t,yAxis:n,xDomain:r,fillParent:i,hideLegend:!0})}),a.length>0&&(0,F.jsx)(R,{nodeIds:a,isActive:o,onClickNode:s})]})}function qr(e,t,n,r,i,a){switch(e){case`line`:return(0,F.jsx)(Kr,{data:t,theme:n,yAxis:r,xDomain:i,fillParent:a});case`stacked-area`:return(0,F.jsx)(Wt,{data:t,theme:n,yAxis:r,xDomain:i,fillParent:a});case`small-multiples`:throw Error(`small-multiples is dispatched at the spec branch, not via renderPrimitive`);case`heatmap`:throw Error(`heatmap dispatch is via custom Renderer (replication-latency)`);default:throw Error(`Unknown primitive: ${e}`)}}var Jr=class extends P.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`[MetricRenderer] render failed; falling back:`,e)}render(){return this.state.failed?this.props.fallback:this.props.children}};function Yr({metric:e,records:t,window:n,nodes:r,theme:i,viewMode:a,fillParent:o}){let s=(0,F.jsx)(Wr,{metric:e,records:t,window:n,nodes:r,theme:i,hint:`Render failed — showing fallback.`}),c=[n.startTime,n.endTime],l,u=cn[e];if(u)if(u.Renderer)l=(0,F.jsx)(u.Renderer,{records:t,timeRange:n,nodes:r,theme:i,viewMode:a,fillParent:o});else{let e=u.recompute(t,n,r,a);l=qr(u.primitive,e,i,u.yAxis,c,o)}else{let s=Pr[e];if(s?.Renderer)l=(0,F.jsx)(s.Renderer,{records:t,timeRange:n,nodes:r,theme:i,viewMode:a,fillParent:o});else if(s?.spec){let e=(a??`per-node`)===`per-node`;if(s.spec.primitive===`small-multiples`){let a=s.spec,u=a.series;if(u.kind!==`field`)throw Error(`small-multiples requires kind='field' series source`);l=(0,F.jsx)(zt,{panels:u.fields.map(i=>{let o={...a,series:{kind:`field`,fields:[i]},aggregator:{temporal:i.aggregator?.temporal??a.aggregator.temporal,crossNode:i.aggregator?.crossNode??a.aggregator.crossNode}};return{title:i.label,data:H(o,t,n,r,{perNode:e,snapToPeriod:!0}),yAxis:i.yAxis??a.yAxis}}),theme:i,xDomain:c,fillParent:o})}else if(s.spec.primitive===`stacked-area`&&e&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension!==`node`)l=qr(`stacked-area`,H({...s.spec,series:{...s.spec.series,dimension:`node`}},t,n,r,{snapToPeriod:!0}),i,s.spec.yAxis,c,o);else if(s.spec.primitive===`line`&&!e&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension===`node`){let e=s.spec.series,a=H({...s.spec,series:{kind:`field`,fields:[{...e.field,label:`cluster`}]}},t,n,r,{snapToPeriod:!0});l=qr(s.spec.primitive,a,i,s.spec.yAxis,c,o)}else if(s.spec.primitive===`line`&&s.spec.series.kind===`groupBy`&&s.spec.series.dimension!==`node`)l=qr(`line`,H(s.spec,t,n,r,{perNode:!1,snapToPeriod:!0}),i,s.spec.yAxis,c,o);else{let a=H(s.spec,t,n,r,{perNode:e,snapToPeriod:!0});l=qr(s.spec.primitive,a,i,s.spec.yAxis,c,o)}}else l=(0,F.jsx)(Wr,{metric:e,records:t,window:n,nodes:r,theme:i})}return(0,F.jsx)(Jr,{fallback:s,children:l},e)}var Xr=class extends P.Component{state={failed:!1};static getDerivedStateFromError(e){return{failed:!0,message:e instanceof Error?e.message:String(e)}}static getDerivedStateFromProps(e,t){return t.lastResetKey===e.resetKey?null:{failed:!1,message:void 0,lastResetKey:e.resetKey}}componentDidCatch(e){console.error(`[panel:${this.props.metric}] render failed`,e)}render(){return this.state.failed?(0,F.jsxs)(`div`,{className:`rounded-lg border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:[(0,F.jsx)(`div`,{className:`font-medium mb-1`,children:`Panel "${this.props.metric}" is unavailable`}),(0,F.jsx)(`div`,{className:`text-xs opacity-80`,children:this.state.message})]}):this.props.children}};function Q({metric:e,titleOverride:t}){let{timeRange:n}=I();return(0,F.jsx)(Xr,{metric:e,resetKey:`${n.startTime}-${n.endTime}`,children:(0,F.jsx)(Zr,{metric:e,titleOverride:t})})}function Zr({metric:e,titleOverride:t}){let{timeRange:n,bucketMs:r,refreshIntervalMs:i,theme:a,instanceParams:o}=I(),s=cn[e]?.sourceMetric??e,c=Ir(e),{data:l,isLoading:u,isError:d,error:f,isEmpty:p,missingFields:m,refetch:h}=ut({metric:s,startTime:n.startTime,endTime:n.endTime,instanceParams:o,refetchIntervalMs:i,bucketMs:r,requiredFields:c}),g=Pr[e],_=cn[e],v=t??g?.spec?.title??_?.title??e,y=g?.spec?.description??_?.subtitle,b=$r(l),x=(0,P.useRef)(null),S=!u&&!d&&!p,C=(t={fillParent:!1})=>(0,F.jsx)(Yr,{metric:e,records:l,window:n,nodes:b,theme:a,fillParent:t.fillParent});return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:v}),y&&(0,F.jsx)(O,{children:y})]}),S&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:e,title:v,description:y,renderChart:C}),(0,F.jsx)(at,{captureRef:x,exportSlug:e}),(0,F.jsx)(ot,{captureRef:x,exportSlug:e})]})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{ref:x,children:(0,F.jsx)(Qr,{isLoading:u,isError:d,error:f,isEmpty:p,missingFields:m,onRetry:h,children:C()})})})]})}function Qr({isLoading:e,isError:t,error:r,isEmpty:i,missingFields:a,onRetry:o,children:s}){return e?(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`}):t?(0,F.jsxs)(`div`,{className:`h-64 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive flex flex-col items-start justify-center gap-3`,children:[(0,F.jsx)(`div`,{children:`Failed to load: ${r?.message??`unknown error`}`}),(0,F.jsx)(n,{variant:`outline`,size:`sm`,onClick:o,children:`Retry`})]}):i?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:a.length>0?`No data — server response is missing required field(s): ${a.join(`, `)}.`:`No data in the selected time range.`}):(0,F.jsx)(F.Fragment,{children:s})}function $r(e){let t=new Set;for(let n of e)typeof n.node==`string`&&t.add(n.node);return[...t].sort()}var ei=[`db-read`,`db-write`,`db-message`];function ti(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:ei.map(e=>(0,F.jsx)(Q,{metric:e},e))})}var ni=[`resource-usage`,`memory`,`main-thread-utilization`,`cpu-usage`,`utilization`];function ri(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:ni.map(e=>(0,F.jsx)(Q,{metric:e},e))})}function ii({...e}){return(0,F.jsx)(w,{"data-slot":`accordion`,...e})}function ai({className:e,...n}){return(0,F.jsx)(ie,{"data-slot":`accordion-item`,className:t(`border-b last:border-b-0`,e),...n})}function oi({className:e,children:n,...r}){return(0,F.jsx)(ne,{className:`flex`,children:(0,F.jsxs)(h,{"data-slot":`accordion-trigger`,className:t(`focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180`,e),...r,children:[n,(0,F.jsx)(f,{className:`text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200`})]})})}function si({className:e,children:n,...r}){return(0,F.jsx)(oe,{"data-slot":`accordion-content`,className:`data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm`,...r,children:(0,F.jsx)(`div`,{className:t(`pt-0 pb-4`,e),children:n})})}function ci({entityId:e,instanceClient:t}){return te({queryKey:[e,`system_information`],queryFn:async()=>{let{data:e}=await t.post(`/`,{operation:`system_information`,attributes:[`network`,`disk`,`cpu`,`memory`,`system`]});return e}})}var li=new Date(2025,0).getTime(),ui=1440*60*1e3;function di(e){let t=[];for(let n in e){let r=e[n];t.push(...pi(n,r,0))}return t}function fi(e){return!!e.title}function pi(e,t,n,r){if(t&&Array.isArray(t)){let r=t;return[r.length>1&&{title:e,depth:n},...t.map((t,i)=>pi(r.length>1?String(i+1):e,t,n+1,e)).flat(1)].filter(fe)}if(mi(t)){let r=t;return[{title:e,depth:n},...Object.keys(t).map(t=>pi(String(t),r[t],n+1,e)).flat(1)]}return(e===`__updatedtime__`||e===`__createdtime__`)&&(e=e.replace(/_/g,``).replace(`time`,``)),typeof t==`number`?t>li&&t<Date.now()+ui?t=Se(Date.now()-t,t):r===`memory`?t=Oe(t):!e.startsWith(`raw`)&&e.toLowerCase().includes(`load`)&&(t=Math.round(t*10)/10+`%`):typeof t==`boolean`&&(t=t?`Yes`:`No`),[{name:e,value:String(t),depth:n}]}function mi(e){return!!e&&typeof e==`object`}function hi({instanceParams:e,isLocalStudio:t}){return(0,F.jsx)(P.Suspense,{fallback:(0,F.jsx)(gi,{}),children:t?(0,F.jsx)(_i,{instanceParams:e}):(0,F.jsx)(vi,{instanceParams:e})})}function gi(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[0,1,2,3].map(e=>(0,F.jsx)(`div`,{className:`h-40 rounded-lg bg-muted/30 animate-pulse`},e))})}function _i({instanceParams:e}){let{data:t}=r(ci(e));return(0,F.jsx)(yi,{data:t})}function vi({instanceParams:e}){let{data:t}=r(xe(e));return(0,F.jsx)(yi,{data:t})}function yi({data:e}){let t=(0,P.useMemo)(()=>xi(e),[e]);return(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsx)(ii,{type:`multiple`,defaultValue:t.slice(0,1).map(e=>e.title),children:t.map(e=>(0,F.jsxs)(ai,{value:e.title,children:[(0,F.jsx)(oi,{className:`text-base font-semibold`,children:e.title}),(0,F.jsx)(si,{children:(0,F.jsx)(bi,{section:e})})]},e.title))}),(0,F.jsxs)(`details`,{className:`rounded-lg border border-border bg-card`,children:[(0,F.jsx)(`summary`,{className:`cursor-pointer px-4 py-2 text-sm text-muted-foreground hover:text-foreground`,children:`View raw JSON`}),(0,F.jsx)(`pre`,{className:`px-4 pb-4 text-xs overflow-auto max-h-96`,children:JSON.stringify(e,null,2)})]})]})}function bi({section:e}){return(0,F.jsxs)(`div`,{className:`space-y-3`,children:[e.rows.length>0&&(0,F.jsx)(A,{children:(0,F.jsx)(j,{className:`pt-4`,children:(0,F.jsx)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2 text-sm`,children:e.rows.map(e=>(0,F.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,F.jsx)(`dt`,{className:`text-muted-foreground`,children:e.name}),(0,F.jsx)(`dd`,{className:`font-mono text-right truncate`,title:e.value,children:e.value})]},e.name))})})}),e.subSections.map(e=>(0,F.jsxs)(`div`,{className:`pl-3 border-l border-border`,children:[(0,F.jsx)(`div`,{className:`text-sm font-semibold mb-2 text-muted-foreground`,children:e.title}),(0,F.jsx)(bi,{section:e})]},e.title))]})}function xi(e){let t=di(e),n=[],r=[],i=null;for(let e of t)if(fi(e)){for(;r.length>0&&r[r.length-1]._depth>=e.depth;)r.pop();let t={title:e.title,rows:[],subSections:[],_depth:e.depth};r.length===0?n.push(t):r[r.length-1].subSections.push(t),r.push(t)}else{let t=r[r.length-1];t?t.rows.push({name:e.name,value:e.value}):(i||(i={title:`General`,rows:[],subSections:[]},n.unshift(i)),i.rows.push({name:e.name,value:e.value}))}return n}function Si(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-4`,children:(0,F.jsx)(Q,{metric:`replication-latency`})})}var Ci=[`request-rate`,`error-rate`,`duration`,`success`,`transfer`,`response_200`,`cache-hit`,`cache-resolution`];function wi(){return(0,F.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:Ci.map(e=>(0,F.jsx)(Q,{metric:e},e))})}var Ti=[`#e45756`,`#f58518`,`#eeca3b`,`#54a24b`,`#4c78a8`,`#b279a2`,`#9d755d`,`#17becf`,`#72b7b2`,`#bab0ac`],Ei=`#6b7280`;function Di(e){return Ti[e%Ti.length]}var Oi=`__other__`,ki=4096;function Ai(e){return Math.max(6e4,Math.ceil(e/90))}function ji(e){return`${e.database}.${e.table}`}function Mi(e){let t=e.map(e=>({database:e.database,table:e.table,tableKey:ji(e),node:e.node,time:e.id,size:e.size}));return t.sort((e,t)=>e.time-t.time),t}function Ni(e){let t=new Map,n=[];for(let r of e){let e=`${r.node}\0${r.tableKey}`;t.get(e)!==r.size&&(n.push(r),t.set(e,r.size))}return n}function Pi(e){let t=new Map,n=new Map;for(let t of e){let e=`${t.tableKey}\0${t.node}`,r=n.get(e);(r===void 0||t.size>r)&&n.set(e,t.size)}for(let[e,r]of n){let[n]=e.split(`\0`),i=t.get(n);(i===void 0||r>i)&&t.set(n,r)}let r=[...t.entries()].filter(([,e])=>e>ki);r.sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);let i=r.map(([e])=>e),a=[...t.keys()].filter(e=>!i.includes(e));if(a.sort((e,t)=>e.localeCompare(t)),i.length<=9)return{tableSet:i,hasOther:a.length>0,otherMembers:a};let o=i.slice(0,8),s=[...i.slice(8),...a];return{tableSet:o,hasOther:s.length>0,otherMembers:s}}function Fi(e,t,n){let r=new Map;for(let t of e){let e=`${t.node}\0${t.tableKey}`,n=r.get(e);(!n||t.time>=n.time)&&r.set(e,{size:t.size,time:t.time,tableKey:t.tableKey,node:t.node})}let i=new Set(t),a=new Map;for(let{size:e,tableKey:t,node:o}of r.values()){a.has(o)||a.set(o,{node:o,stacks:{},total:0});let r=a.get(o);r.total+=e,i.has(t)?r.stacks[t]=e:n&&(r.stacks[Oi]=(r.stacks.__other__??0)+e)}return[...a.values()].sort((e,t)=>e.node.localeCompare(t.node))}function Ii(e,t){let n=Ai(t.endTime-t.startTime);return function(r){let i=new Map,a=new Map;for(let o of e){if(o.tableKey!==r||o.time<t.startTime||o.time>t.endTime)continue;let e=t.startTime+Math.floor((o.time-t.startTime)/n)*n;i.has(e)||i.set(e,new Map);let s=i.get(e),c=s.get(o.node);(!c||o.time>=c.time)&&s.set(o.node,{size:o.size,time:o.time});let l=a.get(o.node)??0;o.time>l&&a.set(o.node,o.time)}let o=[],s=[...i.keys()].sort((e,t)=>e-t);for(let e of s){let t=i.get(e),n={};for(let[r,{size:i}]of t)e>(a.get(r)??0)||(n[r]=i);Object.keys(n).length>0&&o.push({time:e,values:n})}return o}}function Li(e,t){if(e.length===0)return null;let n=new Map;for(let t of e){let e=`${t.tableKey}\0${t.node}`,r=n.get(e);r||(r={min:t.size,max:t.size,distinctTimes:new Set},n.set(e,r)),t.size<r.min&&(r.min=t.size),t.size>r.max&&(r.max=t.size),r.distinctTimes.add(t.time)}let r=new Map;for(let[e,i]of n){let[n]=e.split(`\0`),a=i.distinctTimes.size>=2&&i.max>i.min,o=i.max-i.min,s=i.max>0?o/i.max:0,c=t===`bytes`?o:s,l=r.get(n);l?(c>l.delta&&(l.delta=c),i.max>l.maxSize&&(l.maxSize=i.max),a&&(l.hasDelta=!0)):r.set(n,{tableKey:n,delta:c,maxSize:i.max,hasDelta:a})}let i=[...r.values()],a=i.filter(e=>e.hasDelta);return a.length>0?(a.sort((e,t)=>t.delta===e.delta?e.tableKey.localeCompare(t.tableKey):t.delta-e.delta),a[0].tableKey):(i.sort((e,t)=>t.maxSize===e.maxSize?e.tableKey.localeCompare(t.tableKey):t.maxSize-e.maxSize),i[0]?.tableKey??null)}function Ri(e,t,n){return e===0?`upstream-empty`:t.length===0&&n?`all-other`:null}function zi(e,t){let n=Ni(Mi(e)),{tableSet:r,hasOther:i,otherMembers:a}=Pi(n),o=Fi(n,r,i),s=Ii(n,t),c=Ri(e.length,r,i),l=e.reduce((e,t)=>t.id>e?t.id:e,0),u=`${t.startTime}:${t.endTime}:${e.length}:${l}`;return{snapshot:{byNode:o,tableSet:r,hasOther:i,otherMembers:a},trend:s,defaultSelection:e=>Li(n,e),emptyCause:c,signature:u}}function Bi(e){let{points:t,node:n,windowMs:r,rankBy:i,formatBytes:a}=e,o=t.map(e=>e.values[n]).filter(e=>typeof e==`number`);if(o.length<2)return``;let s=o[0],c=o[0];for(let e of o)e<s&&(s=e),e>c&&(c=e);let l=c-s;if(l<=0)return``;if(i===`percent`)return`+${(c>0?l/c*100:0).toFixed(1)}%/window`;if(r<=0)return``;let u=l/(r/(1e3*60*60));return`+${a(l)} (${a(u)}/hr)`}function Vi(e){return{axisColor:`var(--chart-axis, #6b7280)`,gridColor:`var(--chart-grid, #e5e7eb)`,tooltipBg:`var(--chart-tooltip-bg, #ffffff)`,tooltipBorder:`var(--chart-grid, #d1d5db)`,textColor:`var(--chart-tooltip-fg, #1f2937)`}}function Hi({tableSet:e,hasOther:t,selectedTable:n,onSelectTable:r}){let i=(0,P.useRef)([]);(0,P.useEffect)(()=>{i.current=i.current.slice(0,e.length)},[e.length]);let a=n===null?-1:e.indexOf(n),o=a>=0?a:0;function s(t,n){if(t.key===`Enter`||t.key===` `){t.preventDefault(),r(e[n]);return}if(t.key!==`ArrowLeft`&&t.key!==`ArrowRight`&&t.key!==`ArrowDown`&&t.key!==`ArrowUp`)return;t.preventDefault();let a=e.length;if(a===0)return;let o=n;(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(o=(n+1)%a),(t.key===`ArrowLeft`||t.key===`ArrowUp`)&&(o=(n-1+a)%a),i.current[o]?.focus(),r(e[o])}return e.length===0&&!t?null:(0,F.jsxs)(`div`,{role:`radiogroup`,"aria-label":`Table selector`,"data-testid":`table-size-chip-row`,className:`flex flex-wrap gap-2 pt-3`,children:[e.map((e,t)=>{let a=e===n,c=Di(t);return(0,F.jsxs)(`button`,{ref:e=>{i.current[t]=e},role:`radio`,"aria-checked":a,tabIndex:t===o?0:-1,"data-testid":`table-size-chip`,"data-table":e,onKeyDown:e=>s(e,t),onClick:()=>r(e),className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs ${a?`font-semibold text-(--color-text-primary)`:`border-(--color-border) text-(--color-text-secondary) hover:text-(--color-text-primary)`}`,style:{borderColor:a?c:void 0},children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:c}}),e]},e)}),t&&(0,F.jsxs)(`button`,{type:`button`,"aria-disabled":`true`,tabIndex:-1,"data-testid":`table-size-chip`,"data-table":`__other__`,title:`Aggregate of smaller tables; not selectable.`,className:`inline-flex min-h-8 items-center gap-1.5 rounded-full border border-dashed border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-secondary)/60 cursor-not-allowed`,children:[(0,F.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:`#6b7280`}}),`Other`]})]})}function Ui(e,t,n){return e.byNode.filter(e=>t(e.node)).map(e=>{let t={};return n.forEach((n,r)=>{t[`t_${r}`]=e.stacks[n]??0}),{node:e.node,...t,__total__:e.total}})}function Wi({snapshot:e,viewMode:t,theme:n,selectedTable:r,onChipSelect:i,onBarClick:a,allOtherHint:o}){let s=Vi(n),c=e.byNode.map(e=>e.node),{isActive:l,handleLegendClick:u}=z(c),d=t===`aggregate`;if(o)return(0,F.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-(--color-text-secondary)`,children:`All tables are small within this window — widen the range to see growth.`});let f=[...e.tableSet,...e.hasOther?[Oi]:[]],p=Ui(e,l,f),h=p.reduce((e,t)=>Math.max(e,t.__total__),0)||1;return(0,F.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,F.jsx)(`div`,{style:{width:`100%`,height:300},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,minWidth:0,children:(0,F.jsxs)(ae,{data:p,barCategoryGap:`20%`,children:[(0,F.jsx)(E,{stroke:s.gridColor,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`node`,stroke:s.axisColor,tick:{fontSize:11}}),(0,F.jsx)(T,{stroke:s.axisColor,tick:{fontSize:11},tickFormatter:e=>{let t=Number(e);return d?`${Math.round(t/h*100)}%`:U(t)},domain:d?[0,h]:[`auto`,`auto`]}),(0,F.jsx)(m,{contentStyle:{backgroundColor:s.tooltipBg,border:`1px solid ${s.tooltipBorder}`,borderRadius:8,fontSize:12},formatter:(e,t,n)=>{let r=String(t),i=r===`__other__`?`Other`:r,a=Number(e),o=n?.payload?.__total__??0,s=o>0?(a/o*100).toFixed(1):`0`;return[`${U(a)} (${s}% of node total ${U(o)})`,i]}}),f.map((e,t)=>{let n=e===`__other__`?Ei:Di(t),i=e===r;return(0,F.jsx)(v,{dataKey:`t_${t}`,name:e,stackId:`size`,fill:n,stroke:i?n:`transparent`,strokeWidth:i?2:0,onClick:()=>{e!==`__other__`&&a(e)},style:{cursor:e===`__other__`?`not-allowed`:`pointer`},children:p.map(t=>(0,F.jsx)(b,{"data-testid":`table-size-segment`,"data-table":e,"data-node":t.node},t.node))},e)})]})})}),(0,F.jsx)(R,{nodeIds:c,isActive:l,onClickNode:u}),(0,F.jsx)(Hi,{tableSet:e.tableSet,hasOther:e.hasOther,selectedTable:r,onSelectTable:i})]})}function Gi({derived:e,viewMode:t,theme:n,selectedTable:r,onChipSelect:i,manualSelection:a,range:o,clusterNodeIds:s,rankBy:c,onRankChange:l}){let u=Vi(n),d=(0,P.useMemo)(()=>r?e.trend(r):[],[e,r]),f=(0,P.useMemo)(()=>{let e=new Set;for(let t of d)for(let n of Object.keys(t.values))e.add(n);return[...e].sort()},[d]),{isActive:p,handleLegendClick:h}=z(f),g=Math.max(0,o.endTime-o.startTime),v=(0,P.useMemo)(()=>{let e=new Map;return f.forEach((t,n)=>e.set(t,`n_${n}`)),e},[f]),y=(0,P.useMemo)(()=>d.map(e=>{let t={};for(let[n,r]of v)t[r]=e.values[n]??null;return{time:e.time,...t}}),[d,v]);return r?(0,F.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,F.jsxs)(`div`,{"aria-live":`polite`,"data-testid":`table-size-trend-title`,className:`sr-only`,children:[`Trend selection: `,r,a?``:` (auto-selected — ${c===`bytes`?`largest bytes change`:`largest percent change`})`]}),!a&&(0,F.jsxs)(`div`,{className:`mb-1 text-[10px] text-(--color-text-secondary)`,children:[`Auto-selected by `,c===`bytes`?`largest bytes change`:`largest % change`]}),(0,F.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`text-[11px] text-(--color-text-secondary)`,children:`Rank by:`}),(0,F.jsxs)(`div`,{className:`inline-flex rounded border border-(--color-border) bg-(--color-bg-tertiary) p-0.5`,"data-testid":`table-size-rank-toggle`,children:[(0,F.jsx)(`button`,{type:`button`,"aria-pressed":c===`bytes`,onClick:()=>l(`bytes`),className:`rounded px-2 py-0.5 text-[11px] ${c===`bytes`?`bg-(--color-bg-secondary) text-(--color-text-primary)`:`text-(--color-text-secondary)`}`,children:`Bytes changed`}),(0,F.jsx)(`button`,{type:`button`,"aria-pressed":c===`percent`,onClick:()=>l(`percent`),className:`rounded px-2 py-0.5 text-[11px] ${c===`percent`?`bg-(--color-bg-secondary) text-(--color-text-primary)`:`text-(--color-text-secondary)`}`,children:`% change`})]})]}),(0,F.jsx)(`div`,{style:{width:`100%`,height:300},children:(0,F.jsx)(ue,{width:`100%`,height:`100%`,minWidth:0,children:(0,F.jsxs)(_,{data:y,children:[(0,F.jsx)(E,{stroke:u.gridColor,strokeDasharray:`3 3`}),(0,F.jsx)(se,{dataKey:`time`,type:`number`,domain:[o.startTime,o.endTime],allowDataOverflow:!0,tickFormatter:At,stroke:u.axisColor,tick:{fontSize:11},allowDuplicatedCategory:!1}),(0,F.jsx)(T,{stroke:u.axisColor,tick:{fontSize:11},tickFormatter:U,scale:t===`per-node`?`log`:`auto`,domain:t===`per-node`?[1,`auto`]:[`auto`,`auto`],allowDataOverflow:!0}),(0,F.jsx)(m,{contentStyle:{backgroundColor:u.tooltipBg,border:`1px solid ${u.tooltipBorder}`,borderRadius:8,fontSize:12},labelFormatter:e=>jt(Number(e)),formatter:e=>U(Number(e))}),f.filter(e=>p(e)).map(e=>(0,F.jsx)(D,{dataKey:v.get(e),name:`${e} ${Bi({points:d,node:e,windowMs:g,rankBy:c,formatBytes:U})}`.trim(),stroke:L(e,s),strokeWidth:2,dot:!1,type:`monotone`,connectNulls:!1},e))]})})}),(0,F.jsx)(R,{nodeIds:f,isActive:p,onClickNode:h}),(0,F.jsx)(Hi,{tableSet:e.snapshot.tableSet,hasOther:e.snapshot.hasOther,selectedTable:r,onSelectTable:i})]}):(0,F.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-(--color-text-secondary)`,children:`Select a table to view trend.`})}function Ki(e){return e.snapshot.byNode.map(e=>e.node)}function qi(){return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4`,children:[(0,F.jsx)(Xr,{metric:`table-size`,children:(0,F.jsx)(Ji,{})}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsx)(Q,{metric:`database-size`}),(0,F.jsx)(Q,{metric:`transaction-log-growth`}),(0,F.jsx)(Q,{metric:`storage-volume`})]})]})}function Ji(){let{timeRange:e,bucketMs:t,refreshIntervalMs:n,theme:r,instanceParams:i}=I(),{data:a,isLoading:o,isError:s}=ut({metric:`table-size`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),c=(0,P.useMemo)(()=>{let e=a??[],t=[],n=0;for(let r of e)typeof r.id==`number`?t.push(r):typeof r.time==`number`?t.push({...r,id:r.time}):n++;return n>0&&console.warn(`[table-size] dropped rows missing both id and time`,{dropped:n,total:e.length}),t},[a]),l=(0,P.useMemo)(()=>zi(c,e),[c,e.startTime,e.endTime]),u=`bytes`,[d,f]=(0,P.useState)(null),p=(0,P.useRef)(null),m=(0,P.useRef)(null),h=(0,P.useMemo)(()=>d&&l.snapshot.tableSet.includes(d)?d:l.defaultSelection(u),[d,l]);if(o)return(0,F.jsxs)(A,{children:[(0,F.jsx)(k,{children:(0,F.jsx)(M,{children:`Table sizes`})}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`})})]});if(s)return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{children:[(0,F.jsx)(M,{children:`Table sizes`}),(0,F.jsx)(O,{children:`Per-table storage breakdown.`})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-32 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive flex items-center justify-center`,children:`Failed to load table-size data. Try a different time window or refresh.`})})]});if(l.emptyCause===`upstream-empty`)return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{children:[(0,F.jsx)(M,{children:`Table sizes`}),(0,F.jsx)(O,{children:`Per-table storage breakdown.`})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{className:`h-32 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No table-size data in the selected window.`})})]});let g=e=>(0,F.jsx)(Wi,{snapshot:l.snapshot,viewMode:`per-node`,theme:r,selectedTable:h,onChipSelect:f,onBarClick:f,allOtherHint:l.emptyCause===`all-other`}),_=t=>h?(0,F.jsx)(Gi,{derived:l,viewMode:`per-node`,theme:r,selectedTable:h,onChipSelect:f,manualSelection:d!==null,range:e,clusterNodeIds:Ki(l),rankBy:u,onRankChange:()=>{}}):(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No table selected.`});return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsxs)(A,{ref:p,children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Table size — snapshot`}),(0,F.jsx)(O,{children:`Bytes per table, per node. Click a segment to pin the trend below.`})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`table-size-snapshot`,title:`Table size — snapshot`,description:`Bytes per table, per node.`,renderChart:g}),(0,F.jsx)(at,{captureRef:p,exportSlug:`table-size-snapshot`}),(0,F.jsx)(ot,{captureRef:p,exportSlug:`table-size-snapshot`})]})]}),(0,F.jsx)(j,{children:g()})]}),(0,F.jsxs)(A,{ref:m,children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Table size — trend`}),(0,F.jsx)(O,{children:h?`Growth of ${h} over the selected window.`:`Pick a table to see its trend.`})]}),h&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`table-size-trend`,title:`Table size — trend: ${h}`,description:`Growth of ${h} over the selected window.`,renderChart:_}),(0,F.jsx)(at,{captureRef:m,exportSlug:`table-size-trend`}),(0,F.jsx)(ot,{captureRef:m,exportSlug:`table-size-trend`})]})]}),(0,F.jsx)(j,{children:_()})]})]})}function Yi(){let{timeRange:e}=I();return(0,F.jsx)(Xr,{metric:`connections`,resetKey:`${e.startTime}-${e.endTime}`,children:(0,F.jsx)(Xi,{})})}function Xi(){let{timeRange:e,bucketMs:t,refreshIntervalMs:n,theme:r,instanceParams:i}=I(),a=(0,P.useRef)(null),o=ut({metric:`mqtt-connections`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),s=ut({metric:`ws-connections`,startTime:e.startTime,endTime:e.endTime,instanceParams:i,refetchIntervalMs:n,bucketMs:t}),c=o.isLoading||s.isLoading,l=o.isError||s.isError,u=o.error||s.error,d=(0,P.useMemo)(()=>{let e=[];for(let t of o.data)e.push({...t,type:`mqtt`});for(let t of s.data)e.push({...t,type:`ws`});return e},[o.data,s.data]),f=d.length===0,p=(0,P.useMemo)(()=>{let e=new Set;for(let t of d)typeof t.node==`string`&&e.add(t.node);return[...e].sort()},[d]),m=!c&&!l&&!f,h=(t={fillParent:!1})=>(0,F.jsx)(An,{records:d,timeRange:e,nodes:p,theme:r,fillParent:t.fillParent});return(0,F.jsxs)(A,{children:[(0,F.jsxs)(k,{className:`flex flex-row items-start justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,F.jsx)(M,{children:`Connections`}),(0,F.jsx)(O,{children:`Active MQTT + WebSocket sessions — chips solo / Ctrl-toggle.`})]}),m&&(0,F.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,F.jsx)(st,{exportSlug:`connections`,title:`Connections`,description:`Active MQTT + WebSocket sessions.`,renderChart:h}),(0,F.jsx)(at,{captureRef:a,exportSlug:`connections`}),(0,F.jsx)(ot,{captureRef:a,exportSlug:`connections`})]})]}),(0,F.jsx)(j,{children:(0,F.jsx)(`div`,{ref:a,children:c?(0,F.jsx)(`div`,{className:`h-64 rounded-md bg-muted/30 animate-pulse`,"aria-label":`Loading`}):l?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:`Failed to load: ${u?.message??`unknown error`}`}):f?(0,F.jsx)(`div`,{className:`h-64 rounded-md border border-border bg-muted/20 p-4 text-sm text-muted-foreground flex items-center justify-center`,children:`No active sessions in the selected time range.`}):h()})})]})}var Zi=[`mqtt-traffic-sent`,`mqtt-traffic-received`,`bytes-sent`,`bytes-received`,`tls-reused`,`connection`];function Qi(){return(0,F.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-4`,children:[(0,F.jsx)(Yi,{}),Zi.map(e=>(0,F.jsx)(Q,{metric:e},e))]})}var $i=[{id:`health`,label:`Health`},{id:`traffic`,label:`Traffic`},{id:`requests`,label:`Requests`},{id:`database`,label:`Database`},{id:`replication`,label:`Replication`},{id:`storage`,label:`Storage`},{id:`overview`,label:`Overview`}];function ea({instanceParams:e,isLocalStudio:t}){let n=$e(e);return n.isLoading?(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`px-4 py-8 text-sm text-muted-foreground`,children:`Checking analytics availability…`}):n.error?(0,F.jsxs)(`div`,{role:`alert`,className:`px-4 py-8 text-sm text-muted-foreground`,children:[(0,F.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Analytics unavailable on this instance.`}),(0,F.jsxs)(`p`,{children:[`The Harper instance returned an error from`,` `,(0,F.jsx)(`code`,{children:`get_analytics`}),`. Check that the instance is reachable and that analytics is enabled, then reload.`]})]}):(0,F.jsx)(ta,{instanceParams:e,isLocalStudio:t})}function ta({instanceParams:e,isLocalStudio:t}){let n=le(),r=u({strict:!1}),i=$i.some(e=>e.id===r.tab)?r.tab:`health`,a=r.range&&na.includes(r.range)?r.range:`1h`,o=r.refresh!==void 0&&ra.includes(Number(r.refresh))?Number(r.refresh):Ue,[s,c]=(0,P.useState)(0),{resolvedTheme:l}=g(),d=l===`dark`?`dark`:`light`,f=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:i,range:e,refresh:o}})},[n,i,o]),p=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:e,range:a,refresh:o}})},[n,a,o]),m=(0,P.useCallback)(e=>{n({to:`.`,search:{tab:i,range:a,refresh:e}})},[n,i,a]);(0,P.useEffect)(()=>()=>{n({search:void 0,replace:!0})},[n]);let h=(0,P.useMemo)(()=>{let t=Ve(a),n=Date.now();return{timeRange:{startTime:n-t.durationMs,endTime:n},bucketMs:t.bucketMs,refreshIntervalMs:o,theme:d,instanceParams:e}},[a,o,d,e,s]),_=i===`overview`?null:(0,F.jsx)(qe,{presetId:a,onPresetChange:f,refreshMs:o,onRefreshChange:m,onManualRefresh:()=>c(e=>e+1)});return(0,F.jsx)(Ye,{value:h,children:(0,F.jsxs)(ke,{value:i,onValueChange:e=>p(e),className:`px-4 py-2`,children:[i!==`overview`&&(0,F.jsx)(Ie,{}),(0,F.jsx)(`div`,{className:`md:hidden mb-3`,children:(0,F.jsxs)(Ee,{value:i,onValueChange:e=>p(e),children:[(0,F.jsx)(be,{className:`w-full`,"aria-label":`Select status tab`,children:(0,F.jsx)(Me,{})}),(0,F.jsx)(we,{children:$i.map(e=>(0,F.jsx)(Ce,{value:e.id,children:e.label},e.id))})]})}),(0,F.jsx)(Te,{className:`hidden md:inline-flex max-w-full overflow-x-auto mb-4`,children:$i.map(e=>(0,F.jsx)(je,{value:e.id,children:e.label},e.id))}),(0,F.jsx)(N,{value:`health`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(ri,{})})}),(0,F.jsx)(N,{value:`traffic`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(Qi,{})})}),(0,F.jsx)(N,{value:`requests`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(wi,{})})}),(0,F.jsx)(N,{value:`database`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(ti,{})})}),(0,F.jsx)(N,{value:`replication`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(Si,{})})}),(0,F.jsx)(N,{value:`storage`,children:(0,F.jsx)($,{picker:_,children:(0,F.jsx)(qi,{})})}),(0,F.jsx)(N,{value:`overview`,children:(0,F.jsx)(hi,{instanceParams:e,isLocalStudio:t})})]})})}function $({picker:e,children:t}){return(0,F.jsxs)(F.Fragment,{children:[e&&(0,F.jsx)(`div`,{className:`sticky top-0 z-10 -mx-4 px-4 py-2 mb-3 bg-background border-b border-border shadow-sm flex items-center justify-end gap-2`,children:e}),t]})}var na=[`1h`,`6h`,`24h`,`7d`,`30d`],ra=[0,3e4,6e4,3e5];function ia(){return(0,F.jsx)(ea,{instanceParams:pe(),isLocalStudio:!0})}export{ia as StatusIndex};
2
+ //# sourceMappingURL=status-BrfTnnpt.js.map