rigscope 0.1.5 → 0.1.6

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.
Files changed (108) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +3 -3
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +6 -6
  5. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  6. package/.next/server/app/_global-error.html +1 -1
  7. package/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  12. package/.next/server/app/_not-found.html +1 -1
  13. package/.next/server/app/_not-found.rsc +2 -2
  14. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  15. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  16. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  17. package/.next/server/app/administration/page.js +1 -1
  18. package/.next/server/app/administration/page.js.nft.json +1 -1
  19. package/.next/server/app/administration/page_client-reference-manifest.js +1 -1
  20. package/.next/server/app/administration.html +1 -1
  21. package/.next/server/app/administration.rsc +6 -6
  22. package/.next/server/app/administration.segments/_full.segment.rsc +6 -6
  23. package/.next/server/app/administration.segments/_tree.segment.rsc +2 -2
  24. package/.next/server/app/administration.segments/administration/__PAGE__.segment.rsc +6 -6
  25. package/.next/server/app/alerts/page.js +1 -1
  26. package/.next/server/app/alerts/page.js.nft.json +1 -1
  27. package/.next/server/app/alerts/page_client-reference-manifest.js +1 -1
  28. package/.next/server/app/alerts.html +1 -1
  29. package/.next/server/app/alerts.rsc +6 -6
  30. package/.next/server/app/alerts.segments/_full.segment.rsc +6 -6
  31. package/.next/server/app/alerts.segments/_tree.segment.rsc +2 -2
  32. package/.next/server/app/alerts.segments/alerts/__PAGE__.segment.rsc +6 -6
  33. package/.next/server/app/connections/page.js +1 -1
  34. package/.next/server/app/connections/page.js.nft.json +1 -1
  35. package/.next/server/app/connections/page_client-reference-manifest.js +1 -1
  36. package/.next/server/app/connections.html +1 -1
  37. package/.next/server/app/connections.rsc +6 -6
  38. package/.next/server/app/connections.segments/_full.segment.rsc +6 -6
  39. package/.next/server/app/connections.segments/_tree.segment.rsc +2 -2
  40. package/.next/server/app/connections.segments/connections/__PAGE__.segment.rsc +6 -6
  41. package/.next/server/app/history/page.js +2 -2
  42. package/.next/server/app/history/page.js.nft.json +1 -1
  43. package/.next/server/app/history/page_client-reference-manifest.js +1 -1
  44. package/.next/server/app/history.html +1 -1
  45. package/.next/server/app/history.rsc +26 -22
  46. package/.next/server/app/history.segments/_full.segment.rsc +26 -22
  47. package/.next/server/app/history.segments/_tree.segment.rsc +2 -2
  48. package/.next/server/app/history.segments/history/__PAGE__.segment.rsc +23 -20
  49. package/.next/server/app/index.html +1 -1
  50. package/.next/server/app/index.rsc +6 -6
  51. package/.next/server/app/index.segments/__PAGE__.segment.rsc +6 -6
  52. package/.next/server/app/index.segments/_full.segment.rsc +6 -6
  53. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  54. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  55. package/.next/server/app/login.html +1 -1
  56. package/.next/server/app/login.rsc +2 -2
  57. package/.next/server/app/login.segments/_full.segment.rsc +2 -2
  58. package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
  59. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
  60. package/.next/server/app/machines/[machineId]/page.js +1 -1
  61. package/.next/server/app/machines/[machineId]/page.js.nft.json +1 -1
  62. package/.next/server/app/machines/[machineId]/page_client-reference-manifest.js +1 -1
  63. package/.next/server/app/page.js +1 -1
  64. package/.next/server/app/page.js.nft.json +1 -1
  65. package/.next/server/app/page_client-reference-manifest.js +1 -1
  66. package/.next/server/app/processes/page.js +2 -2
  67. package/.next/server/app/processes/page.js.nft.json +1 -1
  68. package/.next/server/app/processes/page_client-reference-manifest.js +1 -1
  69. package/.next/server/app/processes.html +1 -1
  70. package/.next/server/app/processes.rsc +21 -19
  71. package/.next/server/app/processes.segments/_full.segment.rsc +21 -19
  72. package/.next/server/app/processes.segments/_tree.segment.rsc +2 -2
  73. package/.next/server/app/processes.segments/processes/__PAGE__.segment.rsc +21 -19
  74. package/.next/server/app-paths-manifest.json +3 -3
  75. package/.next/server/chunks/168.js +1 -1
  76. package/.next/server/chunks/350.js +1 -0
  77. package/.next/server/chunks/751.js +1 -1
  78. package/.next/server/chunks/894.js +2 -2
  79. package/.next/server/middleware-build-manifest.js +1 -1
  80. package/.next/server/pages/404.html +1 -1
  81. package/.next/server/pages/500.html +1 -1
  82. package/.next/static/chunks/103-976549d31902404e.js +1 -0
  83. package/.next/static/chunks/408-9fdba9e4e956ef08.js +1 -0
  84. package/.next/static/chunks/944-a7fe1d96f1d20531.js +1 -0
  85. package/.next/static/chunks/app/administration/page-b62f6610cda5381f.js +1 -0
  86. package/.next/static/chunks/app/alerts/{page-2548b2ab0c057953.js → page-3445bc100ee03d4e.js} +1 -1
  87. package/.next/static/chunks/app/connections/{page-07113bf16cb352e7.js → page-75abd16fc495fcbd.js} +1 -1
  88. package/.next/static/chunks/app/history/page-a25ba8fab7bd7cb9.js +3 -0
  89. package/.next/static/chunks/app/machines/[machineId]/{page-0b89e4393a137c4d.js → page-89143e71c34b542b.js} +1 -1
  90. package/.next/static/chunks/app/{page-c68554c93016dd13.js → page-9c9c89166eee4c92.js} +1 -1
  91. package/.next/static/chunks/app/processes/page-3fdebd2f98b52044.js +3 -0
  92. package/.next/static/css/f5d3162842dcac31.css +1 -0
  93. package/CHANGELOG.md +12 -0
  94. package/dist/collector.cjs +1 -1
  95. package/dist/hub.cjs +1 -1
  96. package/docs/installation.md +3 -3
  97. package/docs/releasing.md +12 -12
  98. package/package.json +1 -1
  99. package/.next/server/chunks/721.js +0 -1
  100. package/.next/static/chunks/103-13ec30dcc059b9d3.js +0 -1
  101. package/.next/static/chunks/157-0d36ebf66af048ac.js +0 -1
  102. package/.next/static/chunks/408-29f55984738967db.js +0 -1
  103. package/.next/static/chunks/app/administration/page-4b16b19bb6a39c36.js +0 -1
  104. package/.next/static/chunks/app/history/page-69ea64476ee5db85.js +0 -3
  105. package/.next/static/chunks/app/processes/page-b6d97d119f10e2a1.js +0 -3
  106. package/.next/static/css/fb3ad9534f4681e6.css +0 -1
  107. /package/.next/static/{oxwySrJXqXq8O6_7AzZGe → KBskG-P4uSZx1zfnYp1nL}/_buildManifest.js +0 -0
  108. /package/.next/static/{oxwySrJXqXq8O6_7AzZGe → KBskG-P4uSZx1zfnYp1nL}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[484],{438:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]])},1461:(e,t,r)=>{"use strict";r.d(t,{AlertsView:()=>L});var s=r(5155),n=r(2115),l=r(5798),a=r(7241),i=r(828),o=r(7422);let d=(0,r(8698).A)("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);var u=r(257),c=r(4173),m=r(3440),x=r(940),h=r(802),p=r(6582),b=r(7586),f=r(9939),g=r(7348);let y=[{value:"above",label:"At or above threshold",needsThreshold:!0},{value:"below",label:"At or below threshold",needsThreshold:!0},{value:"stale",label:"No receipt within cadence threshold",needsThreshold:!1},{value:"unavailable",label:"Reading unavailable",needsThreshold:!1}],v={"cpu.usage":{label:"CPU usage",unit:"percent",resource:"none"},"cpu.core":{label:"CPU core usage",unit:"percent",resource:"required"},"cpu.temperature":{label:"CPU temperature",unit:"celsius",resource:"none"},"cpu.power":{label:"CPU package power",unit:"watts",resource:"none"},"cpu.iowait":{label:"CPU I/O wait",unit:"percent",resource:"none"},"cpu.pressure":{label:"CPU pressure",unit:"percent",resource:"none"},"memory.used":{label:"Memory used",unit:"bytes",resource:"none"},"memory.total":{label:"Memory total",unit:"bytes",resource:"none"},"memory.usage":{label:"Memory usage",unit:"percent",resource:"none"},"memory.pressure.some":{label:"Memory pressure (some)",unit:"percent",resource:"none"},"memory.pressure.full":{label:"Memory pressure (full)",unit:"percent",resource:"none"},"swap.used":{label:"Swap used",unit:"bytes",resource:"none"},"swap.total":{label:"Swap total",unit:"bytes",resource:"none"},"gpu.utilization":{label:"GPU utilization",unit:"percent",resource:"required"},"gpu.memory.used":{label:"GPU memory used",unit:"bytes",resource:"required"},"gpu.memory.total":{label:"GPU memory total",unit:"bytes",resource:"required"},"gpu.temperature":{label:"GPU temperature",unit:"celsius",resource:"required"},"gpu.power":{label:"GPU power",unit:"watts",resource:"required"},"io.pressure.some":{label:"I/O pressure (some)",unit:"percent",resource:"none"},"io.pressure.full":{label:"I/O pressure (full)",unit:"percent",resource:"none"},"fs.used":{label:"Filesystem used",unit:"bytes",resource:"required"},"fs.total":{label:"Filesystem total",unit:"bytes",resource:"required"},"fs.usage":{label:"Filesystem usage",unit:"percent",resource:"required"},"fs.inodes.usage":{label:"Filesystem inode usage",unit:"percent",resource:"required"},"disk.read":{label:"Disk read",unit:"bytes_per_second",resource:"required"},"disk.write":{label:"Disk write",unit:"bytes_per_second",resource:"required"},"disk.read.latency":{label:"Disk read latency",unit:"milliseconds",resource:"required"},"disk.write.latency":{label:"Disk write latency",unit:"milliseconds",resource:"required"},"disk.utilization":{label:"Disk utilization",unit:"percent",resource:"required"},"net.rx":{label:"Network receive",unit:"bytes_per_second",resource:"required"},"net.tx":{label:"Network transmit",unit:"bytes_per_second",resource:"required"}};function j(e){return"required"===v[e].resource}function w(e){let t=["B","KiB","MiB","GiB","TiB"],r=Math.max(0,e),s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;return 0===s?`${Math.round(r)} ${t[s]}`:`${r.toFixed(1)} ${t[s]}`}function N(e,t){if(null===t||!Number.isFinite(t))return"—";switch(v[e].unit){case"percent":return`${Math.round(100*t)/100}%`;case"bytes":return w(t);case"bytes_per_second":return`${w(t)}/s`;case"celsius":return`${Math.round(t)} \xb0C`;case"watts":return`${Math.round(t)} W`;case"milliseconds":return`${Math.round(10*t)/10} ms`}}function k(e){return y.find(t=>t.value===e)?.label??e}function C(e,t){return`${v[e].label}${t?` (${t})`:""}`}let S=[{id:"sustained-high-cpu",label:"Sustained high CPU",ruleName:"Sustained high CPU",metric:"cpu.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"none",description:"Suggests CPU at or above 90% for 5 minutes."},{id:"memory-nearly-full",label:"Memory nearly full",ruleName:"Memory nearly full",metric:"memory.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"none",description:"Suggests memory usage at or above 90% for 5 minutes."},{id:"disk-nearly-full",label:"Disk nearly full",ruleName:"Disk nearly full",metric:"fs.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"filesystem",description:"Suggests filesystem usage at or above 90% for 5 minutes."},{id:"inode-capacity-low",label:"Inode capacity low",ruleName:"Inode capacity low",metric:"fs.inodes.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"filesystem",description:"Suggests inode usage at or above 90% for 5 minutes."},{id:"gpu-hot",label:"GPU hot",ruleName:"GPU hot",metric:"gpu.temperature",condition:"above",threshold:85,durationMs:6e4,resourceKind:"gpu",description:"Suggests GPU temperature at or above 85 \xb0C for 1 minute."},{id:"cpu-hot",label:"CPU hot",ruleName:"CPU hot",metric:"cpu.temperature",condition:"above",threshold:90,durationMs:6e4,resourceKind:"none",description:"Suggests CPU temperature at or above 90 \xb0C for 1 minute."},{id:"collector-offline",label:"Collector offline",ruleName:"Collector offline",metric:"cpu.usage",condition:"stale",threshold:null,durationMs:0,resourceKind:"none",description:"Uses the existing stale condition and the collector's advertised cadence."},{id:"memory-pressure",label:"Memory pressure",ruleName:"Memory pressure",metric:"memory.pressure.some",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests memory pressure at or above 10% for 1 minute."},{id:"io-pressure",label:"I/O pressure",ruleName:"I/O pressure",metric:"io.pressure.some",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests I/O pressure at or above 10% for 1 minute."},{id:"cpu-pressure",label:"CPU pressure",ruleName:"CPU pressure",metric:"cpu.pressure",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests CPU pressure at or above 10% for 1 minute."},{id:"high-io-wait",label:"High I/O wait",ruleName:"High I/O wait",metric:"cpu.iowait",condition:"above",threshold:20,durationMs:3e5,resourceKind:"none",description:"Suggests CPU I/O wait at or above 20% for 5 minutes."},{id:"disk-busy",label:"Disk busy",ruleName:"Disk busy",metric:"disk.utilization",condition:"above",threshold:90,durationMs:3e5,resourceKind:"disk",description:"Suggests disk utilization at or above 90% for 5 minutes."},{id:"slow-disk-reads",label:"Slow disk reads",ruleName:"Slow disk reads",metric:"disk.read.latency",condition:"above",threshold:100,durationMs:3e5,resourceKind:"disk",description:"Suggests read latency at or above 100 ms for 5 minutes."}],M={cpu:"CPU",memory:"Memory",swap:"Swap",gpus:"GPU",disks:"Disk",network:"Network"};function P(e){return{kind:"unavailable",reason:e}}function T(){return{kind:"waiting",reason:"Waiting for the first metrics sample."}}function U(e,t){if(null===e||"object"!=typeof e)return null;let r=e[t];return"number"==typeof r&&Number.isFinite(r)?r:null}function $(e,t){return"ok"===e.disks.status?e.disks.filesystems.find(e=>e.id===t):void 0}function A(e,t){return"ok"===e.disks.status?e.disks.devices.find(e=>e.id===t):void 0}function I(e,t,r){return null===U(e,t)?P(`${r} is not reported by this collector.`):{kind:"ready"}}function E(e,t,r,s,n){let l="ready"===r.kind&&void 0!==t?{name:e.ruleName,machineId:t.machineId,metric:e.metric,resourceId:n,condition:e.condition,threshold:e.threshold,durationMs:e.durationMs,enabled:!0}:null;return{preset:e,status:r,resourceId:n,resources:s,input:l}}function F(e,t){if(!t||!j(e))return[];let r=t.inventory;return void 0===r?[]:"cpu.core"===e?Array.from({length:Math.min(r.cpu.logicalCores,256)},(e,t)=>({value:`core:${t}`,label:`Core ${t}`})):e.startsWith("gpu.")?r.gpus.filter(e=>"supported"===e.telemetry).map(e=>({value:e.id,label:e.name})):e.startsWith("fs.")?r.filesystems.map(e=>({value:e.id,label:`${e.mountPoint} (${e.fsType})`})):e.startsWith("disk.")?r.disks.map(e=>({value:e.id,label:e.name})):e.startsWith("net.")?r.network.map(e=>({value:e.id,label:e.name})):[]}function D({machines:e,rule:t,busy:r,onSave:l,onCancel:a}){let i=e[0]?.machineId??"",[o,d]=(0,n.useState)(""),[u,c]=(0,n.useState)(i),[m,x]=(0,n.useState)("cpu.usage"),[h,p]=(0,n.useState)(""),[b,f]=(0,n.useState)("above"),[g,w]=(0,n.useState)("80"),[N,k]=(0,n.useState)("0"),[C,O]=(0,n.useState)(!0),[R,W]=(0,n.useState)(""),[q,_]=(0,n.useState)(""),[K,L]=(0,n.useState)(null),[G,Z]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(null===t){d(""),c(e[0]?.machineId??""),x("cpu.usage"),p(""),f("above"),w("80"),k("0"),O(!0),W(""),_(""),L(null);return}d(t.name),c(t.machineId),x(t.metric),p(t.resourceId),f(t.condition),w(null===t.threshold?"":String(t.threshold)),k(String(t.durationMs/1e3)),O(t.enabled),W(function(e){if(null===e)return"";let t=new Date(e);if(!Number.isFinite(t.getTime()))return"";let r=e=>String(e).padStart(2,"0");return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}T${r(t.getHours())}:${r(t.getMinutes())}`}(t.maintenanceUntil)),_(""),L(null)},[t]),(0,n.useEffect)(()=>{null===t&&""===u&&void 0!==e[0]&&c(e[0].machineId)},[e,t,u]);let z=e.find(e=>e.machineId===u),H=void 0!==z&&void 0===z.metrics,B=null===t?S.map(e=>(function(e,t){let{resources:r,resourceId:s}=function(e,t){if("none"===e||void 0===t)return{resources:[],resourceId:""};if("filesystem"===e){let e=t.filesystems.map(e=>({value:e.id,label:`${e.mountPoint} (${e.fsType})`})),r=t.filesystems.find(e=>"/"===e.mountPoint)??t.filesystems[0];return{resources:e,resourceId:r?.id??""}}if("gpu"===e){let e=t.gpus.filter(e=>"supported"===e.telemetry);return{resources:e.map(e=>({value:e.id,label:e.name})),resourceId:e[0]?.id??""}}return{resources:t.disks.map(e=>({value:e.id,label:e.name})),resourceId:t.disks[0]?.id??""}}(e.resourceKind,t?.inventory);return void 0===t?E(e,t,P("Choose a machine."),r,s):"none"!==e.resourceKind&&""===s?E(e,t,P(function(e){switch(e){case"filesystem":return"No filesystems are reported by this machine.";case"gpu":return"No telemetry-capable GPU is reported by this machine.";case"disk":return"No disks are reported by this machine.";case"none":return"No resource is available."}}(e.resourceKind)),r,s):E(e,t,function(e,t,r){var s;if("stale"===e.condition)return{kind:"ready"};let n=function(e,t){let r=e.inventory?.capabilities[t];if(r?.status==="unsupported"||r?.status==="withheld")return P(`${M[t]} metrics are not shared with this hub.`);let s=e.metrics?.payload;return void 0===s?T():"unavailable"===function(e,t){switch(t){case"cpu":return e.cpu;case"memory":return e.memory;case"swap":return e.swap;case"gpus":return e.gpus;case"disks":return e.disks;case"network":return e.network}}(s,t).status?P(`${M[t]} readings are unavailable on this machine.`):null}(t,(s=e.metric).startsWith("cpu.")?"cpu":s.startsWith("memory.")?"memory":s.startsWith("swap.")?"swap":s.startsWith("gpu.")?"gpus":s.startsWith("io.")||s.startsWith("fs.")||s.startsWith("disk.")?"disks":"network");if(null!==n)return n;let l=t.metrics?.payload;if(void 0===l)return T();switch(e.metric){case"cpu.usage":default:return{kind:"ready"};case"cpu.temperature":return I(l.cpu,"temperatureC","CPU temperature");case"cpu.power":return I(l.cpu,"powerWatts","CPU package power");case"cpu.iowait":return I(l.cpu,"iowaitPercent","CPU I/O wait");case"cpu.pressure":return I(l.cpu,"pressureSomePercent","CPU pressure");case"memory.usage":{let e=l.memory;if("ok"!==e.status||!(e.totalBytes>0))return P("Memory total is not reported by this machine.");return{kind:"ready"}}case"memory.pressure.some":return I(l.memory,"pressureSomePercent","Memory pressure");case"memory.pressure.full":return I(l.memory,"pressureFullPercent","Memory full pressure");case"io.pressure.some":return I(l.disks,"pressureSomePercent","I/O pressure");case"io.pressure.full":return I(l.disks,"pressureFullPercent","I/O full pressure");case"fs.usage":{let e=$(l,r);if(void 0===e)return P("The latest sample does not include this filesystem.");if("ok"!==e.status||!(e.totalBytes>0))return P("Filesystem size is not reported for this filesystem.");return{kind:"ready"}}case"fs.inodes.usage":{let e=$(l,r);if(void 0===e)return P("The latest sample does not include this filesystem.");if("ok"!==e.status)return P("This filesystem is unavailable in the latest sample.");let t=U(e,"inodesUsed"),s=U(e,"inodesTotal");if(null===t||null===s||s<=0)return P("Inode usage is not reported for this filesystem.");return{kind:"ready"}}case"gpu.temperature":{let e="ok"===l.gpus.status?l.gpus.devices.find(e=>e.id===r):void 0;if(void 0===e)return P("The latest sample does not include this GPU.");if("ok"!==e.status)return P("This GPU is unavailable in the latest sample.");return I(e,"temperatureC","GPU temperature")}case"disk.utilization":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"ioUtilizationPercent","Disk utilization")}case"disk.read.latency":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"readLatencyMs","Disk read latency")}case"disk.write.latency":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"writeLatencyMs","Disk write latency")}}}(e,t,s),r,s)})(e,z)):[],J=""===q?null:B.find(e=>e.preset.id===q)??null;(0,n.useEffect)(()=>{H&&null===t&&"stale"!==b&&f("stale")},[H,t,b]);let V=F(m,z),Y="above"===b||"below"===b,Q=j(m),X=r||G||0===e.length,ee=async e=>{if(e.preventDefault(),L(null),""===o.trim())return void L("Give the rule a name.");if(""===u)return void L("Choose a machine.");if(H&&"stale"!==b)return void L("No metrics have been received from this machine yet, so value and unavailable rules cannot be evaluated against it. Use a stale rule, or wait until the machine reports metrics.");if(Q&&""===h.trim())return void L("Choose or enter the metric's resource.");let r=Number(N);if(""===N.trim()||!Number.isInteger(r)||r<0||1e3*r>864e5)return void L("Duration must be a whole number of seconds from 0 to 86400.");let s=null;if(Y&&(""===g.trim()||!Number.isFinite(s=Number(g))))return void L("Enter a numeric threshold.");let n=function(e){if(""===e.trim())return null;let t=new Date(e);return Number.isFinite(t.getTime())?t.toISOString():null}(R);Z(!0);try{await l({...null===t?{}:{id:t.id},name:o.trim(),machineId:u,metric:m,resourceId:Q?h.trim():"",condition:b,threshold:Y?s:null,durationMs:1e3*r,enabled:C,maintenanceUntil:n})}catch(e){L(e instanceof Error?e.message:"Could not save the rule.")}finally{Z(!1)}};return(0,s.jsxs)("form",{onSubmit:e=>void ee(e),"aria-busy":G,className:"flex flex-col gap-4",children:[0===e.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"No machines available."}):null,null===t?(0,s.jsxs)("div",{className:"border-b border-border pb-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-preset",className:"text-xs text-muted-foreground",children:"Warning preset"}),(0,s.jsxs)("select",{id:"alert-rule-preset",value:q,onChange:e=>_(e.target.value),disabled:X,"aria-describedby":"alert-rule-preset-note",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[(0,s.jsx)("option",{value:"",children:"Choose a preset…"}),B.map(e=>(0,s.jsxs)("option",{value:e.preset.id,children:[e.preset.label,"ready"===e.status.kind?"":"waiting"===e.status.kind?" — waiting for metrics":" — unavailable"]},e.preset.id))]})]}),(0,s.jsx)("button",{type:"button",onClick:()=>{if(null===J||null===J.input)return;let e=J.input;d(e.name),c(e.machineId),x(e.metric),p(e.resourceId??""),f(e.condition),w(null===e.threshold||void 0===e.threshold?"":String(e.threshold)),k(String(e.durationMs/1e3)),L(null)},disabled:X||J?.status.kind!=="ready",className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Use preset"})]}),(0,s.jsx)("p",{id:"alert-rule-preset-note","aria-live":"polite",className:"mt-1.5 text-xs text-muted-foreground",children:null!==J&&"ready"!==J.status.kind?J.status.reason:""})]}):null,(0,s.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,s.jsxs)("div",{className:"sm:col-span-2",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-name",className:"text-xs text-muted-foreground",children:"Rule name"}),(0,s.jsx)("input",{id:"alert-rule-name",value:o,onChange:e=>d(e.target.value),maxLength:128,disabled:X,placeholder:"CPU sustained high",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-machine",className:"text-xs text-muted-foreground",children:"Machine"}),(0,s.jsxs)("select",{id:"alert-rule-machine",value:u,onChange:r=>{var s;let n,l;return s=r.target.value,_(""),c(s),void 0!==(n=e.find(e=>e.machineId===s))&&void 0===n.metrics&&null===t&&f("stale"),l=F(m,n),void(j(m)&&p(l[0]?.value??""))},disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[""===u||e.some(e=>e.machineId===u)?null:(0,s.jsxs)("option",{value:u,children:[u," (current)"]}),e.map(e=>(0,s.jsx)("option",{value:e.machineId,children:e.displayName?.trim()||e.hostname||e.machineId},e.machineId))]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-metric",className:"text-xs text-muted-foreground",children:"Metric"}),(0,s.jsx)("select",{id:"alert-rule-metric",value:m,onChange:e=>{var t;let r;return x(t=e.target.value),r=F(t,z),void p(j(t)?r[0]?.value??"":"")},disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:Object.keys(v).map(e=>({value:e,label:v[e].label})).map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]}),Q?(0,s.jsxs)("div",{className:"sm:col-span-2",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-resource",className:"text-xs text-muted-foreground",children:"Resource"}),V.length>0?(0,s.jsxs)("select",{id:"alert-rule-resource",value:h,onChange:e=>p(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[""===h||V.some(e=>e.value===h)?null:(0,s.jsxs)("option",{value:h,children:[h," (current)"]}),V.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]}):(0,s.jsx)("input",{id:"alert-rule-resource",value:h,onChange:e=>p(e.target.value),maxLength:256,disabled:X,placeholder:"cpu.core"===m?"core:0":m.startsWith("gpu.")?"gpu:GPU-…":m.startsWith("fs.")?"fs:/":m.startsWith("disk.")?"disk:sda":m.startsWith("net.")?"net:eno1":"Resource id",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}):null,(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-condition",className:"text-xs text-muted-foreground",children:"Condition"}),(0,s.jsx)("select",{id:"alert-rule-condition",value:b,onChange:e=>f(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:y.map(e=>(0,s.jsx)("option",{value:e.value,disabled:H&&"stale"!==e.value,children:e.label},e.value))}),H?(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Waiting for metrics."}):null]}),Y?(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"alert-rule-threshold",className:"text-xs text-muted-foreground",children:["Threshold (",function(e){switch(v[e].unit){case"percent":return"percent (0–100)";case"bytes":return"bytes";case"bytes_per_second":return"bytes per second";case"celsius":return"degrees Celsius";case"watts":return"watts";case"milliseconds":return"milliseconds"}}(m),")"]}),(0,s.jsx)("input",{id:"alert-rule-threshold",type:"number",step:"any",value:g,onChange:e=>w(e.target.value),disabled:X,className:"tnum mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}):null,(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-duration",className:"text-xs text-muted-foreground",children:"Must hold for (seconds)"}),(0,s.jsx)("input",{id:"alert-rule-duration",type:"number",min:0,max:86400,step:1,value:N,onChange:e=>k(e.target.value),disabled:X,className:"tnum mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-maintenance",className:"text-xs text-muted-foreground",children:"Maintenance until (optional)"}),(0,s.jsx)("input",{id:"alert-rule-maintenance",type:"datetime-local",value:R,onChange:e=>W(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-foreground sm:col-span-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:C,onChange:e=>O(e.target.checked),disabled:X,className:"h-4 w-4 rounded border-border accent-[var(--accent)]"}),"Rule enabled"]})]}),K?(0,s.jsx)("p",{role:"alert",className:"rounded-md bg-crit-soft px-3 py-2 text-xs text-foreground",children:K}):null,(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{type:"submit",disabled:X,className:"rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90 disabled:opacity-50",children:G?"Saving…":null===t?"Create rule":"Save rule"}),null!==t?(0,s.jsx)("button",{type:"button",onClick:a,disabled:G,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"}):null]})]})}function O({status:e,busy:t,onConfigure:r,onClear:l,onTest:a}){let[i,o]=(0,n.useState)(""),[d,u]=(0,n.useState)(""),[c,m]=(0,n.useState)(""),[x,h]=(0,n.useState)(!0),[p,b]=(0,n.useState)(null),[f,g]=(0,n.useState)(null),[y,v]=(0,n.useState)(!1),[j,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),C=(0,n.useRef)(null),S=(0,n.useRef)(null),M=(0,n.useRef)(null);(0,n.useEffect)(()=>{null!==j&&C.current?.focus()},[j]),(0,n.useEffect)(()=>{e.configured||(w(null),k(null))},[e.configured]);let P=async e=>{v(!0),b(null),w(null),k(null);try{await r(e),o(""),u(""),m(""),h(!0)}catch(e){b(e instanceof Error?e.message:"Could not configure the webhook.")}finally{v(!1)}},T=async t=>{t.preventDefault();let r=(()=>{let e;b(null),g(null);let t=i.trim();if(""===t)return b("Enter the webhook URL."),null;if(""!==d.trim())try{let t=JSON.parse(d);if(null===t||"object"!=typeof t||Array.isArray(t))throw Error("not an object");for(let[r,s]of(e={},Object.entries(t))){if("string"!=typeof s)throw Error("header values must be strings");e[r]=s}}catch{return b("Headers must be a JSON object with string values."),null}return{url:t,...void 0===e?{}:{headers:e},secret:""===c.trim()?null:c,enabled:x}})();if(null!==r){if(e.configured){k(r),w("replace");return}await P(r)}},U=async()=>{v(!0),b(null),g(null),w(null);try{await l(),o(""),u(""),m("")}catch(e){b(e instanceof Error?e.message:"Could not clear the webhook.")}finally{v(!1)}},$=async()=>{"clear"===j?await U():"replace"===j&&null!==N&&await P(N)},A=async()=>{b(null),v(!0);try{g(await a())}catch(e){b(e instanceof Error?e.message:"Could not test the webhook.")}finally{v(!1)}},I=t||y||null!==j,E=e.configured&&"loopback-http"===e.transport;return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-xs",children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Configured"}),(0,s.jsx)("dd",{className:"text-foreground",children:e.configured?e.enabled?"Enabled":"Disabled":"Not configured"}),(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Transport"}),(0,s.jsx)("dd",{className:"text-foreground",children:"https"===e.transport?"HTTPS":"loopback-http"===e.transport?"Loopback HTTP test sink":"—"}),(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Last test"}),(0,s.jsx)("dd",{className:"text-foreground",children:null===e.lastTestAt?"Never":`${!0===e.lastTestOk?"Passed":"Failed"} \xb7 ${new Date(e.lastTestAt).toLocaleString()}`}),e.lastError?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Last error"}),(0,s.jsx)("dd",{className:"text-warn",children:e.lastError})]}):null]}),(0,s.jsxs)("form",{onSubmit:e=>void T(e),className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-url",className:"text-xs text-muted-foreground",children:e.configured?"Replace webhook URL":"Webhook URL"}),(0,s.jsx)("input",{id:"alert-webhook-url",type:"url",required:!0,value:i,onChange:e=>o(e.target.value),maxLength:2048,disabled:I,placeholder:"https://receiver.example/alerts",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-headers",className:"text-xs text-muted-foreground",children:"Headers (JSON, optional)"}),(0,s.jsx)("textarea",{id:"alert-webhook-headers",value:d,onChange:e=>u(e.target.value),rows:2,disabled:I,placeholder:'{"x-channel": "monitoring"}',className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-secret",className:"text-xs text-muted-foreground",children:"Signing secret (optional)"}),(0,s.jsx)("input",{id:"alert-webhook-secret",type:"password",value:c,onChange:e=>m(e.target.value),maxLength:256,disabled:I,placeholder:"Blank clears the signature",autoComplete:"new-password",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-foreground",children:[(0,s.jsx)("input",{type:"checkbox",checked:x,onChange:e=>h(e.target.checked),disabled:I,className:"h-4 w-4 rounded border-border accent-[var(--accent)]"}),"Webhook enabled"]}),p?(0,s.jsx)("p",{role:"alert",className:"rounded-md bg-crit-soft px-3 py-2 text-xs text-foreground",children:p}):null,(0,s.jsx)("p",{role:"status",className:f?`rounded-md px-3 py-2 text-xs ${f.ok?"bg-ok-soft text-foreground":"bg-warn-soft text-foreground"}`:"sr-only",children:f?`Test ${f.ok?"delivered":"failed"}${null!==f.status?` (HTTP ${f.status})`:""}${f.error?` — ${f.error}`:""}.`:""}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{ref:S,type:"submit",disabled:I||""===i.trim(),className:"rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90 disabled:opacity-50",children:e.configured?"Replace webhook":"Configure webhook"}),(0,s.jsx)("button",{ref:M,type:"button",onClick:()=>{b(null),w("clear")},disabled:I||!e.configured,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Clear webhook"}),(0,s.jsx)("button",{type:"button",onClick:()=>void A(),disabled:I||!E,title:E?"Send one explicit test message to the configured loopback sink":"Test delivery is available only for a configured loopback HTTP sink",className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Send test"})]}),null!==j?(0,s.jsxs)("div",{role:"group","aria-label":"Confirm webhook change",className:"rounded-md bg-warn-soft px-3 py-3",children:[(0,s.jsx)("p",{className:"text-xs text-foreground",children:"clear"===j?"Clear the configured webhook? Future incidents will not be delivered until a webhook is configured again.":"Replace the configured webhook? The stored URL, headers and secret will be overwritten."}),(0,s.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{ref:C,type:"button",onClick:()=>void $(),disabled:y,className:`rounded-md px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors disabled:opacity-50 ${"clear"===j?"bg-crit":"bg-accent hover:bg-accent/90"}`,children:"clear"===j?"Confirm clear":"Confirm replace"}),(0,s.jsx)("button",{type:"button",onClick:()=>{let e="clear"===j?M.current:S.current;w(null),k(null),e?.focus()},disabled:y,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"})]})]}):null]})]})}function R(e){if(null===e)return"—";let t=new Date(e);return Number.isFinite(t.getTime())?t.toLocaleString():e}function W({tone:e,children:t}){return(0,s.jsx)("span",{className:`tnum inline-flex items-center rounded-full px-2 py-0.5 text-xs ${"ok"===e?"bg-ok-soft text-ok":"warn"===e?"bg-warn-soft text-warn":"crit"===e?"bg-crit-soft text-crit":"border border-border text-muted-foreground"}`,children:t})}function q({incident:e,now:t}){let r="open"===e.status;return(0,s.jsx)("li",{className:"border-b border-border py-3 last:border-b-0",children:(0,s.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)(W,{tone:r?"crit":"ok",children:r?"Open":"Recovered"}),(0,s.jsx)("span",{className:"truncate text-sm font-medium",children:e.ruleName}),(0,s.jsx)("span",{className:"tnum text-xs text-muted-foreground",children:e.machineId})]}),(0,s.jsx)("p",{className:"mt-1 max-w-2xl text-sm",children:e.message}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:[C(e.metric,e.resourceId)," \xb7 started"," ",(0,b.nV)((0,b.A4)(e.startedAt,t)),null!==e.resolvedAt?` \xb7 recovered ${(0,b.nV)((0,b.A4)(e.resolvedAt,t))}`:""]})]}),(0,s.jsxs)("dl",{className:"tnum grid shrink-0 grid-cols-2 gap-x-4 gap-y-1 text-xs text-muted-foreground",children:[(0,s.jsx)("dt",{children:"Started value"}),(0,s.jsx)("dd",{className:"text-right text-foreground",children:N(e.metric,e.startedValue)}),(0,s.jsx)("dt",{children:"Recovered value"}),(0,s.jsx)("dd",{className:"text-right text-foreground",children:N(e.metric,e.resolvedValue)})]})]})})}function _({rule:e,admin:t,busy:r,confirmingDelete:n,onEdit:i,onRequestDelete:o,onCancelDelete:d,onConfirmDelete:u}){var c,m;let x=(c=e.condition,y.find(e=>e.value===c)?.needsThreshold)?`${k(e.condition)} ${N(e.metric,e.threshold)}`:k(e.condition),h=e.enabled?"firing"===e.state?"crit":"pending"===e.state?"warn":"ok":"muted",p=e.enabled?"firing"===e.state?"Firing":"pending"===e.state?"Pending":"OK":"Disabled";return(0,s.jsxs)("li",{className:"border-b border-border py-3 last:border-b-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:"truncate text-sm font-medium",children:e.name}),(0,s.jsx)(W,{tone:h,children:p})]}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:[e.machineId," \xb7 ",C(e.metric,e.resourceId)]}),(0,s.jsxs)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[x," \xb7 holds ",!Number.isFinite(m=e.durationMs)||m<=0?"Immediately":m<6e4?`${Math.round(m/1e3)} s`:m<36e5?`${Math.round(m/6e4)} min`:`${Math.round(m/36e5)} h`,e.pendingSince?` \xb7 pending since ${R(e.pendingSince)}`:""]}),e.maintenanceUntil?(0,s.jsxs)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Maintenance until ",R(e.maintenanceUntil)]}):null]}),t?(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[(0,s.jsxs)("button",{type:"button",onClick:i,disabled:r||n,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:[(0,s.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0}),"Edit"]}),(0,s.jsxs)("button",{type:"button",onClick:o,disabled:r||n,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-crit transition-colors hover:bg-crit-soft disabled:opacity-50",children:[(0,s.jsx)(a.A,{className:"h-3 w-3","aria-hidden":!0}),"Delete"]})]}):null]}),n?(0,s.jsxs)("div",{role:"group","aria-label":"Confirm rule deletion",className:"mt-3 rounded-md bg-warn-soft px-3 py-2.5",children:[(0,s.jsxs)("p",{className:"text-xs text-foreground",children:["Delete “",e.name,"”? Its incident history stays, but the rule stops evaluating."]}),(0,s.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,s.jsx)("button",{type:"button",autoFocus:!0,onClick:()=>void u(),disabled:r,className:"rounded-md bg-crit px-2.5 py-1 text-xs font-medium text-accent-foreground transition-colors disabled:opacity-50",children:"Confirm delete"}),(0,s.jsx)("button",{type:"button",onClick:d,disabled:r,className:"rounded-md border border-border px-2.5 py-1 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"})]})]}):null]})}function K({notification:e}){let t="failed"===e.status?"crit":"delivered"===e.status?"ok":"warn";return(0,s.jsxs)("li",{className:"border-b border-border py-2 last:border-b-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 text-xs",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)(W,{tone:t,children:e.status}),(0,s.jsx)("span",{className:"text-foreground",children:e.event}),(0,s.jsxs)("span",{className:"tnum text-muted-foreground",children:["attempt ",e.attempts,"/",e.maxAttempts]})]}),(0,s.jsx)("span",{className:"tnum text-muted-foreground",children:R(e.createdAt)})]}),e.lastError?(0,s.jsx)("p",{className:"mt-1 text-xs text-warn",children:e.lastError}):null,(0,s.jsx)("p",{className:"tnum mt-0.5 truncate font-mono text-xs text-muted-foreground",children:e.id})]})}function L(){let{session:e,machines:t}=(0,f.M)(),r=(0,p.x)(),l=(0,g.c)(),a="signed-in"===e.kind?e.user.csrfToken:null,b="signed-in"===e.kind&&!0===e.user.admin,[y,v]=(0,n.useState)(null),[j,w]=(0,n.useState)(!0),[N,k]=(0,n.useState)(null),[C,S]=(0,n.useState)(null),[M,P]=(0,n.useState)(null),[T,U]=(0,n.useState)(null),[$,A]=(0,n.useState)(!1),I=b&&(null===y||y.canAdmin),E=(0,n.useCallback)(async()=>{if(null!==a){w(!0),k(null);try{let e=await fetch("/api/alerts",{headers:{Accept:"application/json"},cache:"no-store",credentials:"same-origin"}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not load alerts (${e.status}).`);v(t)}catch(e){k(e instanceof Error?e.message:"Could not load alerts.")}finally{w(!1)}}},[a]);(0,n.useEffect)(()=>{null!==a&&E()},[a,E]);let F=(0,n.useCallback)(async(e,t)=>{if(null===a)throw Error("Sign in required.");A(!0),k(null);try{let r=await fetch(e,{...t,cache:"no-store",credentials:"same-origin",headers:{Accept:"application/json","Content-Type":"application/json","x-csrf-token":a,...t.headers??{}}}),s=await r.json().catch(()=>({}));if(!r.ok)throw Error(s.error??`Request failed (${r.status}).`);return s}finally{A(!1)}},[a]),R=async e=>{await F("/api/alerts/rules",{method:"POST",body:JSON.stringify(e)}),P(null),S(e.id?"Rule saved.":"Rule created."),await E()},W=async e=>{try{await F(`/api/alerts/rules?id=${encodeURIComponent(e.id)}`,{method:"DELETE"}),M?.id===e.id&&P(null),U(null),S("Rule deleted."),await E()}catch(e){k(e instanceof Error?e.message:"Could not delete the rule.")}},L=async e=>{await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"configure",...e})}),S("Webhook configured."),await E()},G=async()=>{await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"clear"})}),S("Webhook cleared."),await E()},Z=async()=>{let e=await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"test"})});return v(t=>null===t?t:{...t,webhook:e.status}),S(e.result.ok?"Webhook test delivered.":"Webhook test failed."),e.result},z=y?.incidents??[],H=z.filter(e=>"open"===e.status).length,B=y?.rules??[],J=y?.notifications,V=j&&null===y;return(0,s.jsx)(c.G,{title:"Alerts",headerRight:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.$E,{}),(0,s.jsx)(h.B,{})]}),children:r||(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(p.E,{}),(0,s.jsx)("div",{className:"mb-4 flex flex-wrap items-center justify-end gap-3",children:(0,s.jsxs)("button",{type:"button",onClick:()=>void E(),disabled:j,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:[(0,s.jsx)(i.A,{className:`h-3.5 w-3.5 ${j?"animate-spin":""}`,"aria-hidden":!0}),"Refresh"]})}),(0,s.jsx)("p",{role:"status",className:C?"mb-4 text-xs text-muted-foreground":"sr-only",children:C??""}),N?(0,s.jsx)("p",{role:"alert",className:"mb-4 rounded-lg bg-crit-soft px-4 py-2.5 text-xs text-foreground",children:N}):null,V?(0,s.jsx)(m.Z,{title:"Alerts",className:"mt-8",children:(0,s.jsx)(m.p,{icon:i.A,note:"Loading alert rules and incidents…"})}):null===y?(0,s.jsx)(m.Z,{title:"Alerts unavailable",className:"mt-8",children:(0,s.jsx)(m.p,{icon:o.A,note:"Alert state could not be loaded."})}):(0,s.jsxs)("div",{className:I?"grid gap-5 xl:grid-cols-[minmax(0,1fr)_24rem]":"flex flex-col gap-5",children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-5",children:[(0,s.jsx)(m.Z,{title:"Incidents and recoveries",action:(0,s.jsxs)("span",{children:[H," open \xb7 ",z.length," recent"]}),children:0===z.length?(0,s.jsx)(m.p,{icon:d,note:"No incidents."}):(0,s.jsx)("ul",{className:"flex flex-col",children:z.map(e=>(0,s.jsx)(q,{incident:e,now:l},e.id))})}),(0,s.jsx)(m.Z,{title:"Rules",action:(0,s.jsxs)("span",{children:[B.length," configured"]}),children:0===B.length?(0,s.jsx)(m.p,{icon:u.A,note:"No rules."}):(0,s.jsx)("ul",{className:"flex flex-col",children:B.map(e=>(0,s.jsx)(_,{rule:e,admin:I,busy:$,confirmingDelete:T===e.id,onEdit:()=>{U(null),P(e)},onRequestDelete:()=>U(e.id),onCancelDelete:()=>U(null),onConfirmDelete:()=>W(e)},e.id))})}),(0,s.jsx)(m.Z,{title:"Notifications",action:(0,s.jsxs)("span",{children:[J?.pending??0," pending \xb7 ",J?.failed??0," failed"]}),children:void 0===J||0===J.recent.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"No notifications."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("dl",{className:"grid grid-cols-3 gap-3 border-b border-border pb-3 text-xs",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Pending"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.pending})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Delivered"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.delivered})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Failed"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.failed})]})]}),(0,s.jsx)("ul",{className:"mt-1 flex flex-col",children:J.recent.slice(0,10).map(e=>(0,s.jsx)(K,{notification:e},e.id))})]})})]}),I?(0,s.jsxs)("aside",{className:"flex min-w-0 flex-col gap-5",children:[(0,s.jsx)(m.Z,{title:null===M?"New rule":"Edit rule",action:null===M?null:(0,s.jsx)("button",{type:"button",onClick:()=>P(null),className:"text-xs text-muted-foreground hover:text-foreground",children:"New instead"}),children:(0,s.jsx)(D,{machines:t,rule:M,busy:$,onSave:R,onCancel:()=>P(null)})}),(0,s.jsx)(m.Z,{title:"Webhook",children:(0,s.jsx)(O,{status:y.webhook,busy:$,onConfigure:L,onClear:G,onTest:Z})})]}):null]})]})})}},2865:(e,t,r)=>{Promise.resolve().then(r.bind(r,1461))},5798:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]])},6582:(e,t,r)=>{"use strict";r.d(t,{E:()=>f,x:()=>b});var s=r(5155),n=r(8500),l=r.n(n),a=r(828),i=r(6914),o=r(7029),d=r(438),u=r(7422),c=r(1735),m=r(3440),x=r(9939);function h(e){return(0,s.jsxs)("button",{type:"button",onClick:e.onClick,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,s.jsx)(a.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.children]})}function p(e){return(0,s.jsx)(l(),{href:e.href,className:e.primary?"inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90":"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:e.children})}function b(){let{session:e,phase:t,retryConnection:r}=(0,x.M)();switch(e.kind){case"restoring":return(0,s.jsx)(m.Z,{title:"Checking session",className:"mx-auto my-12 max-w-md",children:(0,s.jsx)(m.p,{icon:i.A,note:"Checking your session…"})});case"restore-failed":return(0,s.jsxs)(m.Z,{title:"Hub unreachable",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:o.A,note:"The hub is unreachable right now."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(h,{onClick:r,children:"Check again"})})]});case"signed-out":if("expired"===t)return(0,s.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]});return(0,s.jsxs)(m.Z,{title:"Sign in required",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:i.A,note:"Sign in required."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]});case"auth-unavailable":return(0,s.jsx)(m.Z,{title:"Sign-in unavailable",className:"mx-auto my-12 max-w-md",children:(0,s.jsx)(m.p,{icon:u.A,note:"Browser sign-in is not configured on this hub."})})}return"expired"===t?(0,s.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]}):"no-permission"===t?(0,s.jsxs)(m.Z,{title:"No permission",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:u.A,note:`You are signed in as ${e.user.username}, but this hub grants no machine view to this account.`}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(h,{onClick:r,children:"Check again"})})]}):null}function f(){let{phase:e,retryConnection:t}=(0,x.M)();return"reconnecting"!==e&&"disconnected"!==e&&"connecting"!==e?null:"connecting"===e?(0,s.jsxs)("div",{role:"status",className:"mb-5 flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,s.jsx)(a.A,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),"Connecting to the live feed — waiting for the first snapshot."]}):(0,s.jsxs)("div",{role:"status",className:"mb-5 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,s.jsx)(c.A,{className:"h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,s.jsxs)("span",{children:["Connection lost — values below are ",(0,s.jsx)("strong",{className:"font-medium text-foreground",children:"last known"}),", not live measurements","reconnecting"===e?" — retrying with backoff…":" — retries stopped."]}),"disconnected"===e?(0,s.jsx)(h,{onClick:t,children:"Retry now"}):null]})}},7241:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])}},e=>{e.O(0,[157,939,103,441,794,358],()=>e(e.s=2865)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[484],{438:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]])},1461:(e,t,r)=>{"use strict";r.d(t,{AlertsView:()=>L});var s=r(5155),n=r(2115),l=r(5798),a=r(7241),i=r(828),o=r(7422);let d=(0,r(8698).A)("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);var u=r(257),c=r(4173),m=r(3440),x=r(940),h=r(802),p=r(6582),b=r(7586),f=r(9939),g=r(7348);let y=[{value:"above",label:"At or above threshold",needsThreshold:!0},{value:"below",label:"At or below threshold",needsThreshold:!0},{value:"stale",label:"No receipt within cadence threshold",needsThreshold:!1},{value:"unavailable",label:"Reading unavailable",needsThreshold:!1}],v={"cpu.usage":{label:"CPU usage",unit:"percent",resource:"none"},"cpu.core":{label:"CPU core usage",unit:"percent",resource:"required"},"cpu.temperature":{label:"CPU temperature",unit:"celsius",resource:"none"},"cpu.power":{label:"CPU package power",unit:"watts",resource:"none"},"cpu.iowait":{label:"CPU I/O wait",unit:"percent",resource:"none"},"cpu.pressure":{label:"CPU pressure",unit:"percent",resource:"none"},"memory.used":{label:"Memory used",unit:"bytes",resource:"none"},"memory.total":{label:"Memory total",unit:"bytes",resource:"none"},"memory.usage":{label:"Memory usage",unit:"percent",resource:"none"},"memory.pressure.some":{label:"Memory pressure (some)",unit:"percent",resource:"none"},"memory.pressure.full":{label:"Memory pressure (full)",unit:"percent",resource:"none"},"swap.used":{label:"Swap used",unit:"bytes",resource:"none"},"swap.total":{label:"Swap total",unit:"bytes",resource:"none"},"gpu.utilization":{label:"GPU utilization",unit:"percent",resource:"required"},"gpu.memory.used":{label:"GPU memory used",unit:"bytes",resource:"required"},"gpu.memory.total":{label:"GPU memory total",unit:"bytes",resource:"required"},"gpu.temperature":{label:"GPU temperature",unit:"celsius",resource:"required"},"gpu.power":{label:"GPU power",unit:"watts",resource:"required"},"io.pressure.some":{label:"I/O pressure (some)",unit:"percent",resource:"none"},"io.pressure.full":{label:"I/O pressure (full)",unit:"percent",resource:"none"},"fs.used":{label:"Filesystem used",unit:"bytes",resource:"required"},"fs.total":{label:"Filesystem total",unit:"bytes",resource:"required"},"fs.usage":{label:"Filesystem usage",unit:"percent",resource:"required"},"fs.inodes.usage":{label:"Filesystem inode usage",unit:"percent",resource:"required"},"disk.read":{label:"Disk read",unit:"bytes_per_second",resource:"required"},"disk.write":{label:"Disk write",unit:"bytes_per_second",resource:"required"},"disk.read.latency":{label:"Disk read latency",unit:"milliseconds",resource:"required"},"disk.write.latency":{label:"Disk write latency",unit:"milliseconds",resource:"required"},"disk.utilization":{label:"Disk utilization",unit:"percent",resource:"required"},"net.rx":{label:"Network receive",unit:"bytes_per_second",resource:"required"},"net.tx":{label:"Network transmit",unit:"bytes_per_second",resource:"required"}};function j(e){return"required"===v[e].resource}function w(e){let t=["B","KiB","MiB","GiB","TiB"],r=Math.max(0,e),s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s+=1;return 0===s?`${Math.round(r)} ${t[s]}`:`${r.toFixed(1)} ${t[s]}`}function N(e,t){if(null===t||!Number.isFinite(t))return"—";switch(v[e].unit){case"percent":return`${Math.round(100*t)/100}%`;case"bytes":return w(t);case"bytes_per_second":return`${w(t)}/s`;case"celsius":return`${Math.round(t)} \xb0C`;case"watts":return`${Math.round(t)} W`;case"milliseconds":return`${Math.round(10*t)/10} ms`}}function k(e){return y.find(t=>t.value===e)?.label??e}function C(e,t){return`${v[e].label}${t?` (${t})`:""}`}let S=[{id:"sustained-high-cpu",label:"Sustained high CPU",ruleName:"Sustained high CPU",metric:"cpu.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"none",description:"Suggests CPU at or above 90% for 5 minutes."},{id:"memory-nearly-full",label:"Memory nearly full",ruleName:"Memory nearly full",metric:"memory.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"none",description:"Suggests memory usage at or above 90% for 5 minutes."},{id:"disk-nearly-full",label:"Disk nearly full",ruleName:"Disk nearly full",metric:"fs.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"filesystem",description:"Suggests filesystem usage at or above 90% for 5 minutes."},{id:"inode-capacity-low",label:"Inode capacity low",ruleName:"Inode capacity low",metric:"fs.inodes.usage",condition:"above",threshold:90,durationMs:3e5,resourceKind:"filesystem",description:"Suggests inode usage at or above 90% for 5 minutes."},{id:"gpu-hot",label:"GPU hot",ruleName:"GPU hot",metric:"gpu.temperature",condition:"above",threshold:85,durationMs:6e4,resourceKind:"gpu",description:"Suggests GPU temperature at or above 85 \xb0C for 1 minute."},{id:"cpu-hot",label:"CPU hot",ruleName:"CPU hot",metric:"cpu.temperature",condition:"above",threshold:90,durationMs:6e4,resourceKind:"none",description:"Suggests CPU temperature at or above 90 \xb0C for 1 minute."},{id:"collector-offline",label:"Collector offline",ruleName:"Collector offline",metric:"cpu.usage",condition:"stale",threshold:null,durationMs:0,resourceKind:"none",description:"Uses the existing stale condition and the collector's advertised cadence."},{id:"memory-pressure",label:"Memory pressure",ruleName:"Memory pressure",metric:"memory.pressure.some",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests memory pressure at or above 10% for 1 minute."},{id:"io-pressure",label:"I/O pressure",ruleName:"I/O pressure",metric:"io.pressure.some",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests I/O pressure at or above 10% for 1 minute."},{id:"cpu-pressure",label:"CPU pressure",ruleName:"CPU pressure",metric:"cpu.pressure",condition:"above",threshold:10,durationMs:6e4,resourceKind:"none",description:"Suggests CPU pressure at or above 10% for 1 minute."},{id:"high-io-wait",label:"High I/O wait",ruleName:"High I/O wait",metric:"cpu.iowait",condition:"above",threshold:20,durationMs:3e5,resourceKind:"none",description:"Suggests CPU I/O wait at or above 20% for 5 minutes."},{id:"disk-busy",label:"Disk busy",ruleName:"Disk busy",metric:"disk.utilization",condition:"above",threshold:90,durationMs:3e5,resourceKind:"disk",description:"Suggests disk utilization at or above 90% for 5 minutes."},{id:"slow-disk-reads",label:"Slow disk reads",ruleName:"Slow disk reads",metric:"disk.read.latency",condition:"above",threshold:100,durationMs:3e5,resourceKind:"disk",description:"Suggests read latency at or above 100 ms for 5 minutes."}],M={cpu:"CPU",memory:"Memory",swap:"Swap",gpus:"GPU",disks:"Disk",network:"Network"};function P(e){return{kind:"unavailable",reason:e}}function T(){return{kind:"waiting",reason:"Waiting for the first metrics sample."}}function U(e,t){if(null===e||"object"!=typeof e)return null;let r=e[t];return"number"==typeof r&&Number.isFinite(r)?r:null}function $(e,t){return"ok"===e.disks.status?e.disks.filesystems.find(e=>e.id===t):void 0}function A(e,t){return"ok"===e.disks.status?e.disks.devices.find(e=>e.id===t):void 0}function I(e,t,r){return null===U(e,t)?P(`${r} is not reported by this collector.`):{kind:"ready"}}function E(e,t,r,s,n){let l="ready"===r.kind&&void 0!==t?{name:e.ruleName,machineId:t.machineId,metric:e.metric,resourceId:n,condition:e.condition,threshold:e.threshold,durationMs:e.durationMs,enabled:!0}:null;return{preset:e,status:r,resourceId:n,resources:s,input:l}}function F(e,t){if(!t||!j(e))return[];let r=t.inventory;return void 0===r?[]:"cpu.core"===e?Array.from({length:Math.min(r.cpu.logicalCores,256)},(e,t)=>({value:`core:${t}`,label:`Core ${t}`})):e.startsWith("gpu.")?r.gpus.filter(e=>"supported"===e.telemetry).map(e=>({value:e.id,label:e.name})):e.startsWith("fs.")?r.filesystems.map(e=>({value:e.id,label:`${e.mountPoint} (${e.fsType})`})):e.startsWith("disk.")?r.disks.map(e=>({value:e.id,label:e.name})):e.startsWith("net.")?r.network.map(e=>({value:e.id,label:e.name})):[]}function D({machines:e,rule:t,busy:r,onSave:l,onCancel:a}){let i=e[0]?.machineId??"",[o,d]=(0,n.useState)(""),[u,c]=(0,n.useState)(i),[m,x]=(0,n.useState)("cpu.usage"),[h,p]=(0,n.useState)(""),[b,f]=(0,n.useState)("above"),[g,w]=(0,n.useState)("80"),[N,k]=(0,n.useState)("0"),[C,O]=(0,n.useState)(!0),[R,W]=(0,n.useState)(""),[q,_]=(0,n.useState)(""),[K,L]=(0,n.useState)(null),[G,Z]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(null===t){d(""),c(e[0]?.machineId??""),x("cpu.usage"),p(""),f("above"),w("80"),k("0"),O(!0),W(""),_(""),L(null);return}d(t.name),c(t.machineId),x(t.metric),p(t.resourceId),f(t.condition),w(null===t.threshold?"":String(t.threshold)),k(String(t.durationMs/1e3)),O(t.enabled),W(function(e){if(null===e)return"";let t=new Date(e);if(!Number.isFinite(t.getTime()))return"";let r=e=>String(e).padStart(2,"0");return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}T${r(t.getHours())}:${r(t.getMinutes())}`}(t.maintenanceUntil)),_(""),L(null)},[t]),(0,n.useEffect)(()=>{null===t&&""===u&&void 0!==e[0]&&c(e[0].machineId)},[e,t,u]);let z=e.find(e=>e.machineId===u),H=void 0!==z&&void 0===z.metrics,B=null===t?S.map(e=>(function(e,t){let{resources:r,resourceId:s}=function(e,t){if("none"===e||void 0===t)return{resources:[],resourceId:""};if("filesystem"===e){let e=t.filesystems.map(e=>({value:e.id,label:`${e.mountPoint} (${e.fsType})`})),r=t.filesystems.find(e=>"/"===e.mountPoint)??t.filesystems[0];return{resources:e,resourceId:r?.id??""}}if("gpu"===e){let e=t.gpus.filter(e=>"supported"===e.telemetry);return{resources:e.map(e=>({value:e.id,label:e.name})),resourceId:e[0]?.id??""}}return{resources:t.disks.map(e=>({value:e.id,label:e.name})),resourceId:t.disks[0]?.id??""}}(e.resourceKind,t?.inventory);return void 0===t?E(e,t,P("Choose a machine."),r,s):"none"!==e.resourceKind&&""===s?E(e,t,P(function(e){switch(e){case"filesystem":return"No filesystems are reported by this machine.";case"gpu":return"No telemetry-capable GPU is reported by this machine.";case"disk":return"No disks are reported by this machine.";case"none":return"No resource is available."}}(e.resourceKind)),r,s):E(e,t,function(e,t,r){var s;if("stale"===e.condition)return{kind:"ready"};let n=function(e,t){let r=e.inventory?.capabilities[t];if(r?.status==="unsupported"||r?.status==="withheld")return P(`${M[t]} metrics are not shared with this hub.`);let s=e.metrics?.payload;return void 0===s?T():"unavailable"===function(e,t){switch(t){case"cpu":return e.cpu;case"memory":return e.memory;case"swap":return e.swap;case"gpus":return e.gpus;case"disks":return e.disks;case"network":return e.network}}(s,t).status?P(`${M[t]} readings are unavailable on this machine.`):null}(t,(s=e.metric).startsWith("cpu.")?"cpu":s.startsWith("memory.")?"memory":s.startsWith("swap.")?"swap":s.startsWith("gpu.")?"gpus":s.startsWith("io.")||s.startsWith("fs.")||s.startsWith("disk.")?"disks":"network");if(null!==n)return n;let l=t.metrics?.payload;if(void 0===l)return T();switch(e.metric){case"cpu.usage":default:return{kind:"ready"};case"cpu.temperature":return I(l.cpu,"temperatureC","CPU temperature");case"cpu.power":return I(l.cpu,"powerWatts","CPU package power");case"cpu.iowait":return I(l.cpu,"iowaitPercent","CPU I/O wait");case"cpu.pressure":return I(l.cpu,"pressureSomePercent","CPU pressure");case"memory.usage":{let e=l.memory;if("ok"!==e.status||!(e.totalBytes>0))return P("Memory total is not reported by this machine.");return{kind:"ready"}}case"memory.pressure.some":return I(l.memory,"pressureSomePercent","Memory pressure");case"memory.pressure.full":return I(l.memory,"pressureFullPercent","Memory full pressure");case"io.pressure.some":return I(l.disks,"pressureSomePercent","I/O pressure");case"io.pressure.full":return I(l.disks,"pressureFullPercent","I/O full pressure");case"fs.usage":{let e=$(l,r);if(void 0===e)return P("The latest sample does not include this filesystem.");if("ok"!==e.status||!(e.totalBytes>0))return P("Filesystem size is not reported for this filesystem.");return{kind:"ready"}}case"fs.inodes.usage":{let e=$(l,r);if(void 0===e)return P("The latest sample does not include this filesystem.");if("ok"!==e.status)return P("This filesystem is unavailable in the latest sample.");let t=U(e,"inodesUsed"),s=U(e,"inodesTotal");if(null===t||null===s||s<=0)return P("Inode usage is not reported for this filesystem.");return{kind:"ready"}}case"gpu.temperature":{let e="ok"===l.gpus.status?l.gpus.devices.find(e=>e.id===r):void 0;if(void 0===e)return P("The latest sample does not include this GPU.");if("ok"!==e.status)return P("This GPU is unavailable in the latest sample.");return I(e,"temperatureC","GPU temperature")}case"disk.utilization":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"ioUtilizationPercent","Disk utilization")}case"disk.read.latency":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"readLatencyMs","Disk read latency")}case"disk.write.latency":{let e=A(l,r);if(void 0===e)return P("The latest sample does not include this disk.");if("ok"!==e.status)return P("This disk is unavailable in the latest sample.");return I(e,"writeLatencyMs","Disk write latency")}}}(e,t,s),r,s)})(e,z)):[],J=""===q?null:B.find(e=>e.preset.id===q)??null;(0,n.useEffect)(()=>{H&&null===t&&"stale"!==b&&f("stale")},[H,t,b]);let V=F(m,z),Y="above"===b||"below"===b,Q=j(m),X=r||G||0===e.length,ee=async e=>{if(e.preventDefault(),L(null),""===o.trim())return void L("Give the rule a name.");if(""===u)return void L("Choose a machine.");if(H&&"stale"!==b)return void L("No metrics have been received from this machine yet, so value and unavailable rules cannot be evaluated against it. Use a stale rule, or wait until the machine reports metrics.");if(Q&&""===h.trim())return void L("Choose or enter the metric's resource.");let r=Number(N);if(""===N.trim()||!Number.isInteger(r)||r<0||1e3*r>864e5)return void L("Duration must be a whole number of seconds from 0 to 86400.");let s=null;if(Y&&(""===g.trim()||!Number.isFinite(s=Number(g))))return void L("Enter a numeric threshold.");let n=function(e){if(""===e.trim())return null;let t=new Date(e);return Number.isFinite(t.getTime())?t.toISOString():null}(R);Z(!0);try{await l({...null===t?{}:{id:t.id},name:o.trim(),machineId:u,metric:m,resourceId:Q?h.trim():"",condition:b,threshold:Y?s:null,durationMs:1e3*r,enabled:C,maintenanceUntil:n})}catch(e){L(e instanceof Error?e.message:"Could not save the rule.")}finally{Z(!1)}};return(0,s.jsxs)("form",{onSubmit:e=>void ee(e),"aria-busy":G,className:"flex flex-col gap-4",children:[0===e.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"No machines available."}):null,null===t?(0,s.jsxs)("div",{className:"border-b border-border pb-4",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-preset",className:"text-xs text-muted-foreground",children:"Warning preset"}),(0,s.jsxs)("select",{id:"alert-rule-preset",value:q,onChange:e=>_(e.target.value),disabled:X,"aria-describedby":"alert-rule-preset-note",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[(0,s.jsx)("option",{value:"",children:"Choose a preset…"}),B.map(e=>(0,s.jsxs)("option",{value:e.preset.id,children:[e.preset.label,"ready"===e.status.kind?"":"waiting"===e.status.kind?" — waiting for metrics":" — unavailable"]},e.preset.id))]})]}),(0,s.jsx)("button",{type:"button",onClick:()=>{if(null===J||null===J.input)return;let e=J.input;d(e.name),c(e.machineId),x(e.metric),p(e.resourceId??""),f(e.condition),w(null===e.threshold||void 0===e.threshold?"":String(e.threshold)),k(String(e.durationMs/1e3)),L(null)},disabled:X||J?.status.kind!=="ready",className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Use preset"})]}),(0,s.jsx)("p",{id:"alert-rule-preset-note","aria-live":"polite",className:"mt-1.5 text-xs text-muted-foreground",children:null!==J&&"ready"!==J.status.kind?J.status.reason:""})]}):null,(0,s.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,s.jsxs)("div",{className:"sm:col-span-2",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-name",className:"text-xs text-muted-foreground",children:"Rule name"}),(0,s.jsx)("input",{id:"alert-rule-name",value:o,onChange:e=>d(e.target.value),maxLength:128,disabled:X,placeholder:"CPU sustained high",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-machine",className:"text-xs text-muted-foreground",children:"Machine"}),(0,s.jsxs)("select",{id:"alert-rule-machine",value:u,onChange:r=>{var s;let n,l;return s=r.target.value,_(""),c(s),void 0!==(n=e.find(e=>e.machineId===s))&&void 0===n.metrics&&null===t&&f("stale"),l=F(m,n),void(j(m)&&p(l[0]?.value??""))},disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[""===u||e.some(e=>e.machineId===u)?null:(0,s.jsxs)("option",{value:u,children:[u," (current)"]}),e.map(e=>(0,s.jsx)("option",{value:e.machineId,children:e.displayName?.trim()||e.hostname||e.machineId},e.machineId))]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-metric",className:"text-xs text-muted-foreground",children:"Metric"}),(0,s.jsx)("select",{id:"alert-rule-metric",value:m,onChange:e=>{var t;let r;return x(t=e.target.value),r=F(t,z),void p(j(t)?r[0]?.value??"":"")},disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:Object.keys(v).map(e=>({value:e,label:v[e].label})).map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]}),Q?(0,s.jsxs)("div",{className:"sm:col-span-2",children:[(0,s.jsx)("label",{htmlFor:"alert-rule-resource",className:"text-xs text-muted-foreground",children:"Resource"}),V.length>0?(0,s.jsxs)("select",{id:"alert-rule-resource",value:h,onChange:e=>p(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:[""===h||V.some(e=>e.value===h)?null:(0,s.jsxs)("option",{value:h,children:[h," (current)"]}),V.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]}):(0,s.jsx)("input",{id:"alert-rule-resource",value:h,onChange:e=>p(e.target.value),maxLength:256,disabled:X,placeholder:"cpu.core"===m?"core:0":m.startsWith("gpu.")?"gpu:GPU-…":m.startsWith("fs.")?"fs:/":m.startsWith("disk.")?"disk:sda":m.startsWith("net.")?"net:eno1":"Resource id",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}):null,(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-condition",className:"text-xs text-muted-foreground",children:"Condition"}),(0,s.jsx)("select",{id:"alert-rule-condition",value:b,onChange:e=>f(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground",children:y.map(e=>(0,s.jsx)("option",{value:e.value,disabled:H&&"stale"!==e.value,children:e.label},e.value))}),H?(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Waiting for metrics."}):null]}),Y?(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"alert-rule-threshold",className:"text-xs text-muted-foreground",children:["Threshold (",function(e){switch(v[e].unit){case"percent":return"percent (0–100)";case"bytes":return"bytes";case"bytes_per_second":return"bytes per second";case"celsius":return"degrees Celsius";case"watts":return"watts";case"milliseconds":return"milliseconds"}}(m),")"]}),(0,s.jsx)("input",{id:"alert-rule-threshold",type:"number",step:"any",value:g,onChange:e=>w(e.target.value),disabled:X,className:"tnum mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}):null,(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-duration",className:"text-xs text-muted-foreground",children:"Must hold for (seconds)"}),(0,s.jsx)("input",{id:"alert-rule-duration",type:"number",min:0,max:86400,step:1,value:N,onChange:e=>k(e.target.value),disabled:X,className:"tnum mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-rule-maintenance",className:"text-xs text-muted-foreground",children:"Maintenance until (optional)"}),(0,s.jsx)("input",{id:"alert-rule-maintenance",type:"datetime-local",value:R,onChange:e=>W(e.target.value),disabled:X,className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-foreground sm:col-span-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:C,onChange:e=>O(e.target.checked),disabled:X,className:"h-4 w-4 rounded border-border accent-[var(--accent)]"}),"Rule enabled"]})]}),K?(0,s.jsx)("p",{role:"alert",className:"rounded-md bg-crit-soft px-3 py-2 text-xs text-foreground",children:K}):null,(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{type:"submit",disabled:X,className:"rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90 disabled:opacity-50",children:G?"Saving…":null===t?"Create rule":"Save rule"}),null!==t?(0,s.jsx)("button",{type:"button",onClick:a,disabled:G,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"}):null]})]})}function O({status:e,busy:t,onConfigure:r,onClear:l,onTest:a}){let[i,o]=(0,n.useState)(""),[d,u]=(0,n.useState)(""),[c,m]=(0,n.useState)(""),[x,h]=(0,n.useState)(!0),[p,b]=(0,n.useState)(null),[f,g]=(0,n.useState)(null),[y,v]=(0,n.useState)(!1),[j,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),C=(0,n.useRef)(null),S=(0,n.useRef)(null),M=(0,n.useRef)(null);(0,n.useEffect)(()=>{null!==j&&C.current?.focus()},[j]),(0,n.useEffect)(()=>{e.configured||(w(null),k(null))},[e.configured]);let P=async e=>{v(!0),b(null),w(null),k(null);try{await r(e),o(""),u(""),m(""),h(!0)}catch(e){b(e instanceof Error?e.message:"Could not configure the webhook.")}finally{v(!1)}},T=async t=>{t.preventDefault();let r=(()=>{let e;b(null),g(null);let t=i.trim();if(""===t)return b("Enter the webhook URL."),null;if(""!==d.trim())try{let t=JSON.parse(d);if(null===t||"object"!=typeof t||Array.isArray(t))throw Error("not an object");for(let[r,s]of(e={},Object.entries(t))){if("string"!=typeof s)throw Error("header values must be strings");e[r]=s}}catch{return b("Headers must be a JSON object with string values."),null}return{url:t,...void 0===e?{}:{headers:e},secret:""===c.trim()?null:c,enabled:x}})();if(null!==r){if(e.configured){k(r),w("replace");return}await P(r)}},U=async()=>{v(!0),b(null),g(null),w(null);try{await l(),o(""),u(""),m("")}catch(e){b(e instanceof Error?e.message:"Could not clear the webhook.")}finally{v(!1)}},$=async()=>{"clear"===j?await U():"replace"===j&&null!==N&&await P(N)},A=async()=>{b(null),v(!0);try{g(await a())}catch(e){b(e instanceof Error?e.message:"Could not test the webhook.")}finally{v(!1)}},I=t||y||null!==j,E=e.configured&&"loopback-http"===e.transport;return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsxs)("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-xs",children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Configured"}),(0,s.jsx)("dd",{className:"text-foreground",children:e.configured?e.enabled?"Enabled":"Disabled":"Not configured"}),(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Transport"}),(0,s.jsx)("dd",{className:"text-foreground",children:"https"===e.transport?"HTTPS":"loopback-http"===e.transport?"Loopback HTTP test sink":"—"}),(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Last test"}),(0,s.jsx)("dd",{className:"text-foreground",children:null===e.lastTestAt?"Never":`${!0===e.lastTestOk?"Passed":"Failed"} \xb7 ${new Date(e.lastTestAt).toLocaleString()}`}),e.lastError?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Last error"}),(0,s.jsx)("dd",{className:"text-warn",children:e.lastError})]}):null]}),(0,s.jsxs)("form",{onSubmit:e=>void T(e),className:"flex flex-col gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-url",className:"text-xs text-muted-foreground",children:e.configured?"Replace webhook URL":"Webhook URL"}),(0,s.jsx)("input",{id:"alert-webhook-url",type:"url",required:!0,value:i,onChange:e=>o(e.target.value),maxLength:2048,disabled:I,placeholder:"https://receiver.example/alerts",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-headers",className:"text-xs text-muted-foreground",children:"Headers (JSON, optional)"}),(0,s.jsx)("textarea",{id:"alert-webhook-headers",value:d,onChange:e=>u(e.target.value),rows:2,disabled:I,placeholder:'{"x-channel": "monitoring"}',className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground placeholder:text-muted-foreground"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"alert-webhook-secret",className:"text-xs text-muted-foreground",children:"Signing secret (optional)"}),(0,s.jsx)("input",{id:"alert-webhook-secret",type:"password",value:c,onChange:e=>m(e.target.value),maxLength:256,disabled:I,placeholder:"Blank clears the signature",autoComplete:"new-password",className:"mt-1 w-full rounded-md border border-border bg-card px-2.5 py-1.5 text-sm text-foreground"})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-foreground",children:[(0,s.jsx)("input",{type:"checkbox",checked:x,onChange:e=>h(e.target.checked),disabled:I,className:"h-4 w-4 rounded border-border accent-[var(--accent)]"}),"Webhook enabled"]}),p?(0,s.jsx)("p",{role:"alert",className:"rounded-md bg-crit-soft px-3 py-2 text-xs text-foreground",children:p}):null,(0,s.jsx)("p",{role:"status",className:f?`rounded-md px-3 py-2 text-xs ${f.ok?"bg-ok-soft text-foreground":"bg-warn-soft text-foreground"}`:"sr-only",children:f?`Test ${f.ok?"delivered":"failed"}${null!==f.status?` (HTTP ${f.status})`:""}${f.error?` — ${f.error}`:""}.`:""}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{ref:S,type:"submit",disabled:I||""===i.trim(),className:"rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90 disabled:opacity-50",children:e.configured?"Replace webhook":"Configure webhook"}),(0,s.jsx)("button",{ref:M,type:"button",onClick:()=>{b(null),w("clear")},disabled:I||!e.configured,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Clear webhook"}),(0,s.jsx)("button",{type:"button",onClick:()=>void A(),disabled:I||!E,title:E?"Send one explicit test message to the configured loopback sink":"Test delivery is available only for a configured loopback HTTP sink",className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Send test"})]}),null!==j?(0,s.jsxs)("div",{role:"group","aria-label":"Confirm webhook change",className:"rounded-md bg-warn-soft px-3 py-3",children:[(0,s.jsx)("p",{className:"text-xs text-foreground",children:"clear"===j?"Clear the configured webhook? Future incidents will not be delivered until a webhook is configured again.":"Replace the configured webhook? The stored URL, headers and secret will be overwritten."}),(0,s.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,s.jsx)("button",{ref:C,type:"button",onClick:()=>void $(),disabled:y,className:`rounded-md px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors disabled:opacity-50 ${"clear"===j?"bg-crit":"bg-accent hover:bg-accent/90"}`,children:"clear"===j?"Confirm clear":"Confirm replace"}),(0,s.jsx)("button",{type:"button",onClick:()=>{let e="clear"===j?M.current:S.current;w(null),k(null),e?.focus()},disabled:y,className:"rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"})]})]}):null]})]})}function R(e){if(null===e)return"—";let t=new Date(e);return Number.isFinite(t.getTime())?t.toLocaleString():e}function W({tone:e,children:t}){return(0,s.jsx)("span",{className:`tnum inline-flex items-center rounded-full px-2 py-0.5 text-xs ${"ok"===e?"bg-ok-soft text-ok":"warn"===e?"bg-warn-soft text-warn":"crit"===e?"bg-crit-soft text-crit":"border border-border text-muted-foreground"}`,children:t})}function q({incident:e,now:t}){let r="open"===e.status;return(0,s.jsx)("li",{className:"border-b border-border py-3 last:border-b-0",children:(0,s.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)(W,{tone:r?"crit":"ok",children:r?"Open":"Recovered"}),(0,s.jsx)("span",{className:"truncate text-sm font-medium",children:e.ruleName}),(0,s.jsx)("span",{className:"tnum text-xs text-muted-foreground",children:e.machineId})]}),(0,s.jsx)("p",{className:"mt-1 max-w-2xl text-sm",children:e.message}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:[C(e.metric,e.resourceId)," \xb7 started"," ",(0,b.nV)((0,b.A4)(e.startedAt,t)),null!==e.resolvedAt?` \xb7 recovered ${(0,b.nV)((0,b.A4)(e.resolvedAt,t))}`:""]})]}),(0,s.jsxs)("dl",{className:"tnum grid shrink-0 grid-cols-2 gap-x-4 gap-y-1 text-xs text-muted-foreground",children:[(0,s.jsx)("dt",{children:"Started value"}),(0,s.jsx)("dd",{className:"text-right text-foreground",children:N(e.metric,e.startedValue)}),(0,s.jsx)("dt",{children:"Recovered value"}),(0,s.jsx)("dd",{className:"text-right text-foreground",children:N(e.metric,e.resolvedValue)})]})]})})}function _({rule:e,admin:t,busy:r,confirmingDelete:n,onEdit:i,onRequestDelete:o,onCancelDelete:d,onConfirmDelete:u}){var c,m;let x=(c=e.condition,y.find(e=>e.value===c)?.needsThreshold)?`${k(e.condition)} ${N(e.metric,e.threshold)}`:k(e.condition),h=e.enabled?"firing"===e.state?"crit":"pending"===e.state?"warn":"ok":"muted",p=e.enabled?"firing"===e.state?"Firing":"pending"===e.state?"Pending":"OK":"Disabled";return(0,s.jsxs)("li",{className:"border-b border-border py-3 last:border-b-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("span",{className:"truncate text-sm font-medium",children:e.name}),(0,s.jsx)(W,{tone:h,children:p})]}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-muted-foreground",children:[e.machineId," \xb7 ",C(e.metric,e.resourceId)]}),(0,s.jsxs)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[x," \xb7 holds ",!Number.isFinite(m=e.durationMs)||m<=0?"Immediately":m<6e4?`${Math.round(m/1e3)} s`:m<36e5?`${Math.round(m/6e4)} min`:`${Math.round(m/36e5)} h`,e.pendingSince?` \xb7 pending since ${R(e.pendingSince)}`:""]}),e.maintenanceUntil?(0,s.jsxs)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Maintenance until ",R(e.maintenanceUntil)]}):null]}),t?(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[(0,s.jsxs)("button",{type:"button",onClick:i,disabled:r||n,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:[(0,s.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0}),"Edit"]}),(0,s.jsxs)("button",{type:"button",onClick:o,disabled:r||n,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-crit transition-colors hover:bg-crit-soft disabled:opacity-50",children:[(0,s.jsx)(a.A,{className:"h-3 w-3","aria-hidden":!0}),"Delete"]})]}):null]}),n?(0,s.jsxs)("div",{role:"group","aria-label":"Confirm rule deletion",className:"mt-3 rounded-md bg-warn-soft px-3 py-2.5",children:[(0,s.jsxs)("p",{className:"text-xs text-foreground",children:["Delete “",e.name,"”? Its incident history stays, but the rule stops evaluating."]}),(0,s.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,s.jsx)("button",{type:"button",autoFocus:!0,onClick:()=>void u(),disabled:r,className:"rounded-md bg-crit px-2.5 py-1 text-xs font-medium text-accent-foreground transition-colors disabled:opacity-50",children:"Confirm delete"}),(0,s.jsx)("button",{type:"button",onClick:d,disabled:r,className:"rounded-md border border-border px-2.5 py-1 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Cancel"})]})]}):null]})}function K({notification:e}){let t="failed"===e.status?"crit":"delivered"===e.status?"ok":"warn";return(0,s.jsxs)("li",{className:"border-b border-border py-2 last:border-b-0",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 text-xs",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)(W,{tone:t,children:e.status}),(0,s.jsx)("span",{className:"text-foreground",children:e.event}),(0,s.jsxs)("span",{className:"tnum text-muted-foreground",children:["attempt ",e.attempts,"/",e.maxAttempts]})]}),(0,s.jsx)("span",{className:"tnum text-muted-foreground",children:R(e.createdAt)})]}),e.lastError?(0,s.jsx)("p",{className:"mt-1 text-xs text-warn",children:e.lastError}):null,(0,s.jsx)("p",{className:"tnum mt-0.5 truncate font-mono text-xs text-muted-foreground",children:e.id})]})}function L(){let{session:e,machines:t}=(0,f.M)(),r=(0,p.x)(),l=(0,g.c)(),a="signed-in"===e.kind?e.user.csrfToken:null,b="signed-in"===e.kind&&!0===e.user.admin,[y,v]=(0,n.useState)(null),[j,w]=(0,n.useState)(!0),[N,k]=(0,n.useState)(null),[C,S]=(0,n.useState)(null),[M,P]=(0,n.useState)(null),[T,U]=(0,n.useState)(null),[$,A]=(0,n.useState)(!1),I=b&&(null===y||y.canAdmin),E=(0,n.useCallback)(async()=>{if(null!==a){w(!0),k(null);try{let e=await fetch("/api/alerts",{headers:{Accept:"application/json"},cache:"no-store",credentials:"same-origin"}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not load alerts (${e.status}).`);v(t)}catch(e){k(e instanceof Error?e.message:"Could not load alerts.")}finally{w(!1)}}},[a]);(0,n.useEffect)(()=>{null!==a&&E()},[a,E]);let F=(0,n.useCallback)(async(e,t)=>{if(null===a)throw Error("Sign in required.");A(!0),k(null);try{let r=await fetch(e,{...t,cache:"no-store",credentials:"same-origin",headers:{Accept:"application/json","Content-Type":"application/json","x-csrf-token":a,...t.headers??{}}}),s=await r.json().catch(()=>({}));if(!r.ok)throw Error(s.error??`Request failed (${r.status}).`);return s}finally{A(!1)}},[a]),R=async e=>{await F("/api/alerts/rules",{method:"POST",body:JSON.stringify(e)}),P(null),S(e.id?"Rule saved.":"Rule created."),await E()},W=async e=>{try{await F(`/api/alerts/rules?id=${encodeURIComponent(e.id)}`,{method:"DELETE"}),M?.id===e.id&&P(null),U(null),S("Rule deleted."),await E()}catch(e){k(e instanceof Error?e.message:"Could not delete the rule.")}},L=async e=>{await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"configure",...e})}),S("Webhook configured."),await E()},G=async()=>{await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"clear"})}),S("Webhook cleared."),await E()},Z=async()=>{let e=await F("/api/alerts/webhook",{method:"POST",body:JSON.stringify({action:"test"})});return v(t=>null===t?t:{...t,webhook:e.status}),S(e.result.ok?"Webhook test delivered.":"Webhook test failed."),e.result},z=y?.incidents??[],H=z.filter(e=>"open"===e.status).length,B=y?.rules??[],J=y?.notifications,V=j&&null===y;return(0,s.jsx)(c.G,{title:"Alerts",headerRight:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.$E,{}),(0,s.jsx)(h.B,{})]}),children:r||(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(p.E,{}),(0,s.jsx)("div",{className:"mb-4 flex flex-wrap items-center justify-end gap-3",children:(0,s.jsxs)("button",{type:"button",onClick:()=>void E(),disabled:j,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:[(0,s.jsx)(i.A,{className:`h-3.5 w-3.5 ${j?"animate-spin":""}`,"aria-hidden":!0}),"Refresh"]})}),(0,s.jsx)("p",{role:"status",className:C?"mb-4 text-xs text-muted-foreground":"sr-only",children:C??""}),N?(0,s.jsx)("p",{role:"alert",className:"mb-4 rounded-lg bg-crit-soft px-4 py-2.5 text-xs text-foreground",children:N}):null,V?(0,s.jsx)(m.Z,{title:"Alerts",className:"mt-8",children:(0,s.jsx)(m.p,{icon:i.A,note:"Loading alert rules and incidents…"})}):null===y?(0,s.jsx)(m.Z,{title:"Alerts unavailable",className:"mt-8",children:(0,s.jsx)(m.p,{icon:o.A,note:"Alert state could not be loaded."})}):(0,s.jsxs)("div",{className:I?"grid gap-5 xl:grid-cols-[minmax(0,1fr)_24rem]":"flex flex-col gap-5",children:[(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-5",children:[(0,s.jsx)(m.Z,{title:"Incidents and recoveries",action:(0,s.jsxs)("span",{children:[H," open \xb7 ",z.length," recent"]}),children:0===z.length?(0,s.jsx)(m.p,{icon:d,note:"No incidents."}):(0,s.jsx)("ul",{className:"flex flex-col",children:z.map(e=>(0,s.jsx)(q,{incident:e,now:l},e.id))})}),(0,s.jsx)(m.Z,{title:"Rules",action:(0,s.jsxs)("span",{children:[B.length," configured"]}),children:0===B.length?(0,s.jsx)(m.p,{icon:u.A,note:"No rules."}):(0,s.jsx)("ul",{className:"flex flex-col",children:B.map(e=>(0,s.jsx)(_,{rule:e,admin:I,busy:$,confirmingDelete:T===e.id,onEdit:()=>{U(null),P(e)},onRequestDelete:()=>U(e.id),onCancelDelete:()=>U(null),onConfirmDelete:()=>W(e)},e.id))})}),(0,s.jsx)(m.Z,{title:"Notifications",action:(0,s.jsxs)("span",{children:[J?.pending??0," pending \xb7 ",J?.failed??0," failed"]}),children:void 0===J||0===J.recent.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"No notifications."}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("dl",{className:"grid grid-cols-3 gap-3 border-b border-border pb-3 text-xs",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Pending"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.pending})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Delivered"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.delivered})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{className:"text-muted-foreground",children:"Failed"}),(0,s.jsx)("dd",{className:"tnum text-foreground",children:J.failed})]})]}),(0,s.jsx)("ul",{className:"mt-1 flex flex-col",children:J.recent.slice(0,10).map(e=>(0,s.jsx)(K,{notification:e},e.id))})]})})]}),I?(0,s.jsxs)("aside",{className:"flex min-w-0 flex-col gap-5",children:[(0,s.jsx)(m.Z,{title:null===M?"New rule":"Edit rule",action:null===M?null:(0,s.jsx)("button",{type:"button",onClick:()=>P(null),className:"text-xs text-muted-foreground hover:text-foreground",children:"New instead"}),children:(0,s.jsx)(D,{machines:t,rule:M,busy:$,onSave:R,onCancel:()=>P(null)})}),(0,s.jsx)(m.Z,{title:"Webhook",children:(0,s.jsx)(O,{status:y.webhook,busy:$,onConfigure:L,onClear:G,onTest:Z})})]}):null]})]})})}},2865:(e,t,r)=>{Promise.resolve().then(r.bind(r,1461))},5798:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]])},6582:(e,t,r)=>{"use strict";r.d(t,{E:()=>f,x:()=>b});var s=r(5155),n=r(8500),l=r.n(n),a=r(828),i=r(6914),o=r(7029),d=r(438),u=r(7422),c=r(1735),m=r(3440),x=r(9939);function h(e){return(0,s.jsxs)("button",{type:"button",onClick:e.onClick,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,s.jsx)(a.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.children]})}function p(e){return(0,s.jsx)(l(),{href:e.href,className:e.primary?"inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90":"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:e.children})}function b(){let{session:e,phase:t,retryConnection:r}=(0,x.M)();switch(e.kind){case"restoring":return(0,s.jsx)(m.Z,{title:"Checking session",className:"mx-auto my-12 max-w-md",children:(0,s.jsx)(m.p,{icon:i.A,note:"Checking your session…"})});case"restore-failed":return(0,s.jsxs)(m.Z,{title:"Hub unreachable",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:o.A,note:"The hub is unreachable right now."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(h,{onClick:r,children:"Check again"})})]});case"signed-out":if("expired"===t)return(0,s.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]});return(0,s.jsxs)(m.Z,{title:"Sign in required",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:i.A,note:"Sign in required."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]});case"auth-unavailable":return(0,s.jsx)(m.Z,{title:"Sign-in unavailable",className:"mx-auto my-12 max-w-md",children:(0,s.jsx)(m.p,{icon:u.A,note:"Browser sign-in is not configured on this hub."})})}return"expired"===t?(0,s.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(p,{href:"/login",primary:!0,children:"Sign in"})})]}):"no-permission"===t?(0,s.jsxs)(m.Z,{title:"No permission",className:"mx-auto my-12 max-w-md",children:[(0,s.jsx)(m.p,{icon:u.A,note:`You are signed in as ${e.user.username}, but this hub grants no machine view to this account.`}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(h,{onClick:r,children:"Check again"})})]}):null}function f(){let{phase:e,retryConnection:t}=(0,x.M)();return"reconnecting"!==e&&"disconnected"!==e&&"connecting"!==e?null:"connecting"===e?(0,s.jsxs)("div",{role:"status",className:"mb-5 flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,s.jsx)(a.A,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),"Connecting to the live feed — waiting for the first snapshot."]}):(0,s.jsxs)("div",{role:"status",className:"mb-5 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,s.jsx)(c.A,{className:"h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,s.jsxs)("span",{children:["Connection lost — values below are ",(0,s.jsx)("strong",{className:"font-medium text-foreground",children:"last known"}),", not live measurements","reconnecting"===e?" — retrying with backoff…":" — retries stopped."]}),"disconnected"===e?(0,s.jsx)(h,{onClick:t,children:"Retry now"}):null]})}},7241:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(8698).A)("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])}},e=>{e.O(0,[944,939,103,441,794,358],()=>e(e.s=2865)),_N_E=e.O()}]);
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[572],{3092:(e,s,t)=>{"use strict";t.d(s,{A:()=>n});let n=(0,t(8698).A)("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]])},3612:(e,s,t)=>{"use strict";t.d(s,{A:()=>n});let n=(0,t(8698).A)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},5773:(e,s,t)=>{"use strict";t.d(s,{ConnectionsView:()=>A});var n=t(5155),a=t(8500),l=t.n(a),r=t(438),d=t(3092),i=t(3612),c=t(7233),x=t(4173),o=t(3440),m=t(940),u=t(802),h=t(6576),g=t(6582),f=t(7586),p=t(9939),j=t(7348),N=t(2241);function b(e){if(null===e)return"—";let s=new Date(e);return Number.isFinite(s.getTime())?s.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"medium"}):e}function v({capability:e}){var s;return(0,n.jsxs)("li",{className:"rounded-md border border-border bg-card-strong/30 px-2 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-foreground",children:e.label}),(0,n.jsx)("span",{className:`tnum rounded-full px-1.5 py-0.5 text-xs ${"supported"===(s=e.status)?"bg-ok-soft text-ok":"unsupported"===s?"bg-warn-soft text-warn":"border border-border text-muted-foreground"}`,children:e.status})]}),e.reason?(0,n.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:e.reason}):null]})}function y({view:e,now:s}){return(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[(0,n.jsxs)("span",{className:"tnum inline-flex items-center gap-1.5 text-sm",children:[(0,n.jsx)("span",{"aria-hidden":!0,className:`inline-block h-2 w-2 shrink-0 rounded-full ${e.connected?"bg-ok":"bg-crit"}`}),e.connected?"Connected":"Disconnected"]}),(0,n.jsxs)("span",{className:"tnum text-xs text-muted-foreground",children:["Interval ",null===e.cadenceMs?"unknown":(0,f.$)(e.cadenceMs)]}),(0,n.jsxs)("span",{className:"tnum text-xs text-muted-foreground",children:["Updated ",(0,f.nV)((0,f.A4)(e.lastReceivedAt,s))]}),"stale"===e.freshness?(0,n.jsx)(h.vw,{text:"stale",title:`No update for over ${(0,f.$)(e.thresholdMs)}`}):"unknown"===e.freshness?(0,n.jsx)(h.vw,{text:"no sample",title:"No receipt timestamp is available yet"}):null]})}function w({view:e}){if(null===e.delivery)return(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"Delivery status unavailable."});let s=e.delivery;return(0,n.jsxs)("dl",{className:"grid gap-x-6 gap-y-2 sm:grid-cols-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Backlog records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.pendingRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Backlog bytes"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:(0,f.z3)(s.pendingBytes)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"In-flight records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.inFlightRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Oldest pending"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:b(s.oldestPendingCapturedAt)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Last acknowledgment"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:null===s.lastAckAt?"No acknowledgment yet":b(s.lastAckAt)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Dropped / gap records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.droppedRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Replaying"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.replaying?"Yes":"No"})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Status captured"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:b(e.deliveryCapturedAt)})]})]})}function k({view:e,now:s}){return(0,n.jsx)(o.Z,{title:e.name,action:(0,n.jsx)(l(),{href:`/machines/${encodeURIComponent(e.machineId)}`,className:"text-xs text-accent hover:underline",children:"Open machine"}),children:(0,n.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,n.jsx)(y,{view:e,now:s}),(0,n.jsxs)("section",{"aria-label":`${e.name} delivery`,children:[(0,n.jsxs)("h3",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[(0,n.jsx)(r.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Delivery"]}),(0,n.jsx)("div",{className:"mt-2",children:(0,n.jsx)(w,{view:e})})]}),(0,n.jsxs)("section",{"aria-label":`${e.name} collection failures`,className:"border-t border-border pt-4",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:"Collection failures"}),null===e.delivery?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Failure status unavailable."}):0===e.failures.length?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"None"}):(0,n.jsx)("ul",{className:"mt-2 flex flex-col gap-1.5",children:e.failures.map((e,s)=>(0,n.jsxs)("li",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-foreground",children:e.metric}),e.resourceId?(0,n.jsxs)("span",{className:"tnum font-mono text-xs text-muted-foreground",children:[" \xb7 ",e.resourceId]}):null,(0,n.jsxs)("span",{className:"text-muted-foreground",children:[" — ",e.reason]})]},`${e.metric}\0${e.resourceId??""}\0${e.reason}\0${s}`))})]}),(0,n.jsxs)("section",{"aria-label":`${e.name} capabilities`,className:"border-t border-border pt-4",children:[(0,n.jsxs)("h3",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[(0,n.jsx)(d.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Capabilities"]}),null===e.capabilities?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Capabilities unavailable."}):(0,n.jsx)("ul",{className:"mt-2 grid gap-1.5 sm:grid-cols-2 xl:grid-cols-3",children:e.capabilities.map(e=>(0,n.jsx)(v,{capability:e},e.key))})]})]})})}function A(){let{phase:e,machines:s,session:t}=(0,p.M)(),a=(0,g.x)(),r=(0,j.c)(),d=(0,N.cy)(s,r);return(0,n.jsx)(x.G,{title:"Connections",headerRight:(0,n.jsxs)(n.Fragment,{children:["signed-in"===t.kind&&t.user.admin?(0,n.jsxs)(l(),{href:"/administration#collectors",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs hover:bg-card-strong",children:[(0,n.jsx)(i.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Add machine"]}):null,(0,n.jsx)(m.$E,{}),(0,n.jsx)(u.B,{})]}),children:a||(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(g.E,{}),("live"===e||"reconnecting"===e||"disconnected"===e)&&0===s.length?(0,n.jsx)(o.Z,{title:"No collectors",className:"mt-8",children:(0,n.jsx)(o.p,{icon:c.A,note:"No collectors are connected to this hub in your authorized scope."})}):null,0===d.length&&"connecting"===e?(0,n.jsx)(o.Z,{title:"Waiting for collector status",className:"mt-8",children:(0,n.jsx)(o.p,{icon:c.A,note:"Waiting for the first snapshot…"})}):null,d.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h2",{className:"mb-4 text-sm font-medium tracking-tight",children:"Collectors"}),(0,n.jsx)("div",{className:"grid gap-5 xl:grid-cols-[repeat(auto-fit,minmax(30rem,1fr))]",children:d.map(e=>(0,n.jsx)(k,{view:e,now:r},e.machineId))})]}):null]})})}},6351:(e,s,t)=>{Promise.resolve().then(t.bind(t,5773))}},e=>{e.O(0,[157,939,103,130,441,794,358],()=>e(e.s=6351)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[572],{3092:(e,s,t)=>{"use strict";t.d(s,{A:()=>n});let n=(0,t(8698).A)("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]])},3612:(e,s,t)=>{"use strict";t.d(s,{A:()=>n});let n=(0,t(8698).A)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},5773:(e,s,t)=>{"use strict";t.d(s,{ConnectionsView:()=>A});var n=t(5155),a=t(8500),l=t.n(a),r=t(438),d=t(3092),i=t(3612),c=t(7233),x=t(4173),o=t(3440),m=t(940),u=t(802),h=t(6576),g=t(6582),f=t(7586),p=t(9939),j=t(7348),N=t(2241);function b(e){if(null===e)return"—";let s=new Date(e);return Number.isFinite(s.getTime())?s.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"medium"}):e}function v({capability:e}){var s;return(0,n.jsxs)("li",{className:"rounded-md border border-border bg-card-strong/30 px-2 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-foreground",children:e.label}),(0,n.jsx)("span",{className:`tnum rounded-full px-1.5 py-0.5 text-xs ${"supported"===(s=e.status)?"bg-ok-soft text-ok":"unsupported"===s?"bg-warn-soft text-warn":"border border-border text-muted-foreground"}`,children:e.status})]}),e.reason?(0,n.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:e.reason}):null]})}function y({view:e,now:s}){return(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[(0,n.jsxs)("span",{className:"tnum inline-flex items-center gap-1.5 text-sm",children:[(0,n.jsx)("span",{"aria-hidden":!0,className:`inline-block h-2 w-2 shrink-0 rounded-full ${e.connected?"bg-ok":"bg-crit"}`}),e.connected?"Connected":"Disconnected"]}),(0,n.jsxs)("span",{className:"tnum text-xs text-muted-foreground",children:["Interval ",null===e.cadenceMs?"unknown":(0,f.$)(e.cadenceMs)]}),(0,n.jsxs)("span",{className:"tnum text-xs text-muted-foreground",children:["Updated ",(0,f.nV)((0,f.A4)(e.lastReceivedAt,s))]}),"stale"===e.freshness?(0,n.jsx)(h.vw,{text:"stale",title:`No update for over ${(0,f.$)(e.thresholdMs)}`}):"unknown"===e.freshness?(0,n.jsx)(h.vw,{text:"no sample",title:"No receipt timestamp is available yet"}):null]})}function w({view:e}){if(null===e.delivery)return(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"Delivery status unavailable."});let s=e.delivery;return(0,n.jsxs)("dl",{className:"grid gap-x-6 gap-y-2 sm:grid-cols-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Backlog records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.pendingRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Backlog bytes"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:(0,f.z3)(s.pendingBytes)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"In-flight records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.inFlightRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Oldest pending"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:b(s.oldestPendingCapturedAt)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Last acknowledgment"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:null===s.lastAckAt?"No acknowledgment yet":b(s.lastAckAt)})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Dropped / gap records"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.droppedRecords})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Replaying"}),(0,n.jsx)("dd",{className:"tnum text-xs text-foreground",children:s.replaying?"Yes":"No"})]}),(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,n.jsx)("dt",{className:"text-xs text-muted-foreground",children:"Status captured"}),(0,n.jsx)("dd",{className:"tnum text-right text-xs text-foreground",children:b(e.deliveryCapturedAt)})]})]})}function k({view:e,now:s}){return(0,n.jsx)(o.Z,{title:e.name,action:(0,n.jsx)(l(),{href:`/machines/${encodeURIComponent(e.machineId)}`,className:"text-xs text-accent hover:underline",children:"Open machine"}),children:(0,n.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,n.jsx)(y,{view:e,now:s}),(0,n.jsxs)("section",{"aria-label":`${e.name} delivery`,children:[(0,n.jsxs)("h3",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[(0,n.jsx)(r.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Delivery"]}),(0,n.jsx)("div",{className:"mt-2",children:(0,n.jsx)(w,{view:e})})]}),(0,n.jsxs)("section",{"aria-label":`${e.name} collection failures`,className:"border-t border-border pt-4",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:"Collection failures"}),null===e.delivery?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Failure status unavailable."}):0===e.failures.length?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"None"}):(0,n.jsx)("ul",{className:"mt-2 flex flex-col gap-1.5",children:e.failures.map((e,s)=>(0,n.jsxs)("li",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-foreground",children:e.metric}),e.resourceId?(0,n.jsxs)("span",{className:"tnum font-mono text-xs text-muted-foreground",children:[" \xb7 ",e.resourceId]}):null,(0,n.jsxs)("span",{className:"text-muted-foreground",children:[" — ",e.reason]})]},`${e.metric}\0${e.resourceId??""}\0${e.reason}\0${s}`))})]}),(0,n.jsxs)("section",{"aria-label":`${e.name} capabilities`,className:"border-t border-border pt-4",children:[(0,n.jsxs)("h3",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[(0,n.jsx)(d.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Capabilities"]}),null===e.capabilities?(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Capabilities unavailable."}):(0,n.jsx)("ul",{className:"mt-2 grid gap-1.5 sm:grid-cols-2 xl:grid-cols-3",children:e.capabilities.map(e=>(0,n.jsx)(v,{capability:e},e.key))})]})]})})}function A(){let{phase:e,machines:s,session:t}=(0,p.M)(),a=(0,g.x)(),r=(0,j.c)(),d=(0,N.cy)(s,r);return(0,n.jsx)(x.G,{title:"Connections",headerRight:(0,n.jsxs)(n.Fragment,{children:["signed-in"===t.kind&&t.user.admin?(0,n.jsxs)(l(),{href:"/administration#collectors",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs hover:bg-card-strong",children:[(0,n.jsx)(i.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Add machine"]}):null,(0,n.jsx)(m.$E,{}),(0,n.jsx)(u.B,{})]}),children:a||(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(g.E,{}),("live"===e||"reconnecting"===e||"disconnected"===e)&&0===s.length?(0,n.jsx)(o.Z,{title:"No collectors",className:"mt-8",children:(0,n.jsx)(o.p,{icon:c.A,note:"No collectors are connected to this hub in your authorized scope."})}):null,0===d.length&&"connecting"===e?(0,n.jsx)(o.Z,{title:"Waiting for collector status",className:"mt-8",children:(0,n.jsx)(o.p,{icon:c.A,note:"Waiting for the first snapshot…"})}):null,d.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h2",{className:"mb-4 text-sm font-medium tracking-tight",children:"Collectors"}),(0,n.jsx)("div",{className:"grid gap-5 xl:grid-cols-[repeat(auto-fit,minmax(30rem,1fr))]",children:d.map(e=>(0,n.jsx)(k,{view:e,now:r},e.machineId))})]}):null]})})}},6351:(e,s,t)=>{Promise.resolve().then(t.bind(t,5773))}},e=>{e.O(0,[944,939,103,130,441,794,358],()=>e(e.s=6351)),_N_E=e.O()}]);
@@ -0,0 +1,3 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[429],{1:(e,t,s)=>{"use strict";s.d(t,{PE:()=>o,UR:()=>d,kg:()=>l,uW:()=>c});let r=/^[\u0009\u000a\u000d ]*[=+\-@]/,n=/^[\u0009\u000a\u000d]/;function i(e){if(null==e)return"";if("number"==typeof e)return Number.isFinite(e)?String(e):"";if("boolean"==typeof e)return e?"true":"false";let t=0===e.length?e:r.test(e)||n.test(e)?`'${e}`:e;return/[",\t\r\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function a(e){return e.map(i).join(",")}function l(e){return`${e.map(a).join("\r\n")}\r
2
+ `}function o(e,t,s){if("u"<typeof document)return;let r=new Blob([t],{type:s}),n=URL.createObjectURL(r),i=document.createElement("a");i.href=n,i.download=e,i.rel="noopener",i.style.display="none",document.body.append(i),i.click(),i.remove(),globalThis.setTimeout(()=>URL.revokeObjectURL(n),0)}let d="text/csv;charset=utf-8",c="application/json;charset=utf-8"},438:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});let r=(0,s(8698).A)("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]])},2727:(e,t,s)=>{Promise.resolve().then(s.bind(s,2939)),Promise.resolve().then(s.bind(s,1721)),Promise.resolve().then(s.bind(s,9904)),Promise.resolve().then(s.bind(s,2701)),Promise.resolve().then(s.bind(s,2394))},2910:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});let r=(0,s(8698).A)("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]])},2939:(e,t,s)=>{"use strict";s.d(t,{HistoryView:()=>eI});var r=s(5155),n=s(8500),i=s.n(n),a=s(2115),l=s(7422),o=s(3896),d=s(1735),c=s(7029),u=s(828),m=s(4173),h=s(3440),p=s(940),x=s(802),g=s(6582),f=s(9939),b=s(8664),y=s(4567),j=s(592);let v=j.U8,N=/^core:(\d+)$/;function w(e){let t=N.exec(e);if(null===t)return null;let s=Number(t[1]);return!Number.isSafeInteger(s)||s<0||s>=j.U8?null:s}function k(e){return[...new Set(e)].sort((e,t)=>(w(e)??0)-(w(t)??0))}function M(e,t=[]){var s;let r=e?.metrics?.payload.cpu,n=new Set(!Number.isFinite(s=Math.max(e?.inventory?.cpu.logicalCores??0,r?.status==="ok"?r.perCore.length:0))?[]:Array.from({length:Math.min(j.U8,Math.max(0,Math.floor(s)))},(e,t)=>`core:${t}`));for(let e of t)"cpu.core"===e.metric&&null!==w(e.resourceId)&&n.add(e.resourceId);return k([...n])}function $(e,t){let s=new Set(t);if(null===e)return k(t).slice(0,v);let r=[];for(let t of e)if(s.has(t)&&null!==w(t)&&(r.push(t),r.length>=v))break;return k(r)}function C(e){let t=w(e);return null===t?e:`Core ${t}`}var I=s(7726);function A(e){if("string"!=typeof e||0===e.length)return null;let t=Date.parse(e);return Number.isFinite(t)?t:null}var S=s(5078),P=s(2910),R=s(9942),U=s(8698);let L=(0,U.A)("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),T=(0,U.A)("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);var _=s(6114);let B=Object.freeze([]),z=new Set(y.H9.map(e=>e.metric)),D=e=>"boolean"==typeof e?e:null,E=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e)?e.slice(0,1e3):null,F=e=>S.pI.some(t=>t.id===e)?e:null,O=e=>"string"==typeof e&&(""===e||e.split(",").every(e=>z.has(e)))?e:null,H=/^core:\d+$/,Z=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e&&H.test(e))?[...new Set(e)].slice(0,j.U8):null;function G(e,t){return(0,_.u)(`history.hidden.${t}.${e}`,B,E)}function q(e){return(0,_.u)(`history.cores.${e}`,null,Z)}let V=e=>"bytes"===e||"percent"===e?e:null;function W(e,t){return(0,_.u)(`history.units.${t}.${e}`,"bytes",V)}let K="peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:[outline-color:var(--focus)]";function Y({label:e,action:t}){return(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2.5",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:e}),(0,r.jsx)("span",{"aria-hidden":!0,className:"h-px min-w-0 flex-1 bg-border"}),t]})}let J="inline-flex min-h-8 items-center gap-1.5 rounded-md border border-transparent px-2.5 text-xs transition-colors",X=`${J} ${K} bg-selected text-foreground`,Q=`${J} ${K} bg-card-strong text-muted-foreground hover:text-foreground`;function ee(e){let{machine:t,range:s,selectedMetrics:n,catalog:i,catalogError:a,gpuCards:l,hiddenCards:o,autoRefresh:d,loading:c,manualRefreshing:m,statusText:h,onRangeChange:p,onToggleMetric:x,onSetMetrics:g,onToggleCard:f,onToggleAutoRefresh:b,onRefresh:j}=e,[v,N]=(0,_.u)("history.controlsOpen",!1,D,"session"),w=new Set(n),k=y.H9.filter(({metric:e})=>(0,y.yv)(t,e).available&&(null===i||void 0!==i[e])).map(({metric:e})=>e),I=new Set(k),A=(e,t)=>{let s=new Set(n);for(let r of e)t&&I.has(r)?s.add(r):t||s.delete(r);g([...s])},U=n.some(e=>e.startsWith("gpu.")),B=w.has("cpu.core"),[z,E]=q(t?.machineId??""),F=B?M(t):[],O=$(z,F),H=new Set(O);return(0,r.jsxs)("section",{"aria-labelledby":"history-query-heading","aria-busy":c,className:"mb-5 min-w-0 rounded-xl border border-border bg-card",children:[(0,r.jsx)("h2",{id:"history-query-heading",className:"sr-only",children:"History query"}),(0,r.jsxs)("div",{className:"flex flex-wrap items-end gap-x-5 gap-y-4 p-4 md:p-5",children:[(0,r.jsxs)("fieldset",{className:"flex min-w-0 flex-col gap-1.5",children:[(0,r.jsx)("legend",{className:"mb-1.5 text-xs text-muted-foreground",children:"Time range"}),(0,r.jsx)("div",{className:"inline-flex flex-wrap rounded-lg border border-border bg-background p-0.5",children:S.pI.map(e=>{let t=s===e.id;return(0,r.jsxs)("label",{className:"cursor-pointer",children:[(0,r.jsx)("input",{type:"radio",name:"history-range",value:e.id,checked:t,onChange:()=>p(e.id),className:"peer sr-only"}),(0,r.jsxs)("span",{className:`inline-flex min-h-8 items-center rounded-md px-2.5 text-xs transition-colors ${K} ${t?"bg-selected font-medium text-foreground":"text-muted-foreground hover:text-foreground"}`,children:[e.shortLabel,(0,r.jsxs)("span",{className:"sr-only",children:[" — ",e.label]})]})]},e.id)})})]}),(0,r.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-2 sm:ml-auto",children:[(0,r.jsx)("p",{className:"order-first w-full text-xs text-muted-foreground sm:order-none sm:w-auto",children:h}),(0,r.jsxs)("button",{type:"button",onClick:j,disabled:m,className:"inline-flex min-h-8 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-60",children:[(0,r.jsx)(u.A,{className:`h-3.5 w-3.5 ${m?"animate-spin":""}`,"aria-hidden":!0}),"Refresh"]}),(0,r.jsxs)("button",{type:"button",onClick:b,"aria-pressed":d,className:`inline-flex min-h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs transition-colors ${d?"border-accent/40 bg-selected text-foreground":"border-border bg-background text-muted-foreground hover:bg-card-strong hover:text-foreground"}`,children:[d?(0,r.jsx)(P.A,{className:"h-3.5 w-3.5","aria-hidden":!0}):(0,r.jsx)(R.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),d?"Pause":"Resume"]})]})]}),(0,r.jsxs)("div",{className:"border-t border-border px-4 py-4 md:px-5",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,r.jsxs)("button",{type:"button","aria-expanded":v,"aria-controls":"history-metric-options",onClick:()=>N(!v),className:"inline-flex min-h-8 items-center gap-1.5 rounded-md text-sm font-medium",children:["Metrics ",(0,r.jsxs)("span",{className:"tnum text-xs font-normal text-muted-foreground",children:[w.size," selected"]}),(0,r.jsx)(L,{"aria-hidden":!0,className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${v?"rotate-180":""}`})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:()=>A(k,!0),disabled:k.every(e=>w.has(e)),className:"inline-flex min-h-8 items-center rounded-md border border-border bg-background px-2.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Select all"}),(0,r.jsx)("button",{type:"button",onClick:()=>g([]),disabled:0===w.size,className:"inline-flex min-h-8 items-center rounded-md border border-border bg-background px-2.5 text-xs text-foreground transition-colors hover:bg-card-strong disabled:opacity-50",children:"Unselect all"})]})]}),(0,r.jsx)("div",{id:"history-metric-options",hidden:!v,children:(0,r.jsxs)("div",{className:"mt-4 min-w-0 md:col-span-2",children:[(0,r.jsx)("div",{className:"min-w-0",children:(0,r.jsx)("div",{className:"grid gap-x-6 gap-y-5 md:grid-cols-2 xl:grid-cols-3",children:y.P$.map(e=>(0,r.jsxs)("fieldset",{className:`min-w-0 ${"disk"===e.id?"xl:col-span-2":""}`,children:[(0,r.jsx)("legend",{className:"sr-only",children:e.label}),(0,r.jsx)(Y,{label:e.label,action:(0,r.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,r.jsx)("button",{type:"button","aria-label":`Select all ${e.label} metrics`,onClick:()=>A(e.metrics,!0),disabled:e.metrics.filter(e=>I.has(e)).every(e=>w.has(e)),className:"min-h-6 rounded-sm text-xs text-muted-foreground hover:text-foreground hover:underline disabled:opacity-50",children:"All"}),(0,r.jsx)("button",{type:"button","aria-label":`Unselect all ${e.label} metrics`,onClick:()=>A(e.metrics,!1),disabled:!e.metrics.some(e=>w.has(e)),className:"min-h-6 rounded-sm text-xs text-muted-foreground hover:text-foreground hover:underline disabled:opacity-50",children:"None"})]})}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:e.metrics.map(e=>{var s;let n=(0,y.oB)(e);if(null===n)return null;let a=(0,y.yv)(t,e),l=null===i||void 0!==i[e],o=a.available&&l,d=w.has(e),c=(0,y.Lf)(n,0);return(0,r.jsxs)("label",{className:o?"cursor-pointer":"cursor-not-allowed",title:a.available?l?n.description:"This hub does not record this metric.":a.reason??void 0,children:[(0,r.jsx)("input",{type:"checkbox",checked:d,onChange:()=>x(e),disabled:!o&&!d,className:"peer sr-only","aria-label":n.label}),(0,r.jsxs)("span",{className:`${!o?d?`${J} ${K} bg-card-strong text-muted-foreground line-through`:`${J} text-muted-foreground opacity-50`:d?X:Q}`,children:[(0,r.jsx)("span",{"aria-hidden":!0,className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border border-current",style:{color:c.color},children:d?(0,r.jsx)(T,{className:"h-3 w-3",strokeWidth:3}):null}),(s=n.label,({"cpu.usage":"Usage","cpu.core":"Per-core","cpu.iowait":"I/O wait","cpu.pressure":"Pressure","cpu.temperature":"Temperature","cpu.power":"Package power","memory.used":"Used bytes","memory.usage":"Usage %","swap.used":"Swap","memory.pressure.some":"Pressure (some)","memory.pressure.full":"Pressure (full)","gpu.utilization":"Utilization","gpu.memory.used":"VRAM","gpu.temperature":"Temperature","gpu.power":"Power","fs.used":"Space used","fs.usage":"Capacity %","fs.inodes.usage":"Inodes %","net.rx":"Received","net.tx":"Sent"})[e]??s)]})]},e)})}),"gpu"===e.id&&U&&l.length>0?(0,r.jsxs)("fieldset",{className:"mt-4 border-t border-border pt-3",children:[(0,r.jsx)("legend",{className:"sr-only",children:"GPU cards"}),(0,r.jsx)(Y,{label:"GPU cards"}),(0,r.jsx)("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:l.map((e,t)=>{let s=e.id,n=!o.has(s);return(0,r.jsxs)("label",{className:"cursor-pointer",children:[(0,r.jsx)("input",{type:"checkbox",checked:n,onChange:()=>f(s),className:"peer sr-only"}),(0,r.jsxs)("span",{className:n?X:Q,children:[(0,r.jsx)("span",{className:"tnum text-xs text-muted-foreground",children:t+1}),e.label]})]},e.id)})})]}):null,"cpu"===e.id&&B?(0,r.jsxs)("fieldset",{className:"mt-4 border-t border-border pt-3",children:[(0,r.jsx)("legend",{className:"sr-only",children:"CPU cores"}),(0,r.jsx)(Y,{label:`CPU cores \xb7 ${O.length} / ${F.length}`,action:(0,r.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:()=>E(null),disabled:O.length===F.length,className:"min-h-6 rounded-sm text-xs text-muted-foreground hover:text-foreground disabled:opacity-50",children:"All cores"}),(0,r.jsx)("button",{type:"button",onClick:()=>E([]),disabled:0===O.length,"aria-label":"Unselect all CPU cores",className:"min-h-6 rounded-sm text-xs text-muted-foreground hover:text-foreground disabled:opacity-50",children:"None"})]})}),0===F.length?(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Core count unavailable."}):(0,r.jsxs)("details",{className:"mt-2",children:[(0,r.jsxs)("summary",{className:"inline-flex min-h-8 cursor-pointer items-center gap-1 rounded-md text-xs text-muted-foreground hover:text-foreground",children:["Choose cores ",(0,r.jsx)(L,{className:"h-3.5 w-3.5","aria-hidden":!0})]}),(0,r.jsx)("div",{className:"mt-2 grid max-h-48 grid-cols-3 gap-1.5 overflow-y-auto p-1",children:F.map(e=>{let t=H.has(e);return(0,r.jsxs)("label",{className:"min-w-0 cursor-pointer",children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>{var s;return s=!t,void E(t=>{let r=$(t,F);return s?r.includes(e)?t:[...r,e]:r.filter(t=>t!==e)})},className:"peer sr-only"}),(0,r.jsxs)("span",{className:`${t?X:Q} w-full px-1.5`,children:[(0,r.jsx)("span",{"aria-hidden":!0,className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border border-current",children:t?(0,r.jsx)(T,{className:"h-3 w-3"}):null}),C(e)]})]},e)})})]})]}):null]},e.id))})}),a?(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:a}):null]})})]})]})}var et=s(9429),es=s(7284),er=s(6304),en=s(4150);let ei="grid grid-cols-[3rem_minmax(0,1fr)_4.5rem] items-center gap-2 sm:grid-cols-[3.5rem_minmax(0,1fr)_4.5rem_3rem]";function ea({title:e,series:t,fromMs:s,toMs:n,stepMs:i,gaps:l,hiddenKeys:o,onToggleSeries:d}){let[c,u]=(0,a.useState)(!1),m=(0,a.useMemo)(()=>t.filter(e=>!o.has(e.key)),[t,o]),h=(0,en.Au)({series:m,fromMs:s,toMs:n,stepMs:i,gaps:l}),p=(0,a.useMemo)(()=>{let e=t.map(e=>{let t=Array(10).fill("");return(function(e,t,s,r=120){let n=Array(r).fill(null),i=Math.max(1,s-t);for(let a of e){if(a.t<t||a.t>s)continue;let e=a.max??a.avg;if(null===e||!Number.isFinite(e))continue;let l=Math.min(r-1,Math.floor((a.t-t)/i*r));n[l]=Math.max(n[l]??0,Math.min(100,Math.max(0,e)))}return n})(e.points,s,n,120).forEach((e,s)=>{if(null===e)return;let r=Math.min(9,Math.floor(e/10));t[r]+=`M${s},1h1v16h-1z`}),{...e,stats:(0,I.T6)(e.points),paths:t}});return c&&e.sort((e,t)=>(t.stats.max??-1)-(e.stats.max??-1)),e},[t,s,n,c]),x=p.filter(e=>!o.has(e.key)).reduce((e,t)=>null!==t.stats.max&&(e?.stats.max===null||null===e||t.stats.max>e.stats.max)?t:e,null),g=null===h.timeMs?null:(0,S.r6)(h.timeMs),f=Math.max(1,n-s),b=(0,I.$z)(l,s,n);return(0,r.jsxs)("figure",{className:"min-w-0 lg:col-span-full",onPointerLeave:e=>{"mouse"===e.pointerType&&h.clear()},children:[(0,r.jsxs)("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[(0,r.jsx)("h3",{className:"text-xs font-medium text-foreground",children:e}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:[x?(0,r.jsxs)("span",{className:"tnum text-muted-foreground",children:["Peak \xb7 ",x.label," ",(0,r.jsx)("span",{className:"text-foreground",children:(0,S.dd)(x.stats.max,"percent")})]}):null,(0,r.jsx)("button",{type:"button","aria-pressed":c,onClick:()=>u(!c),className:`min-h-8 rounded-md border border-border px-2 ${c?"bg-selected text-foreground":"bg-background text-muted-foreground hover:text-foreground"}`,children:"Busiest first"})]})]}),(0,r.jsxs)("div",{className:`${ei} mb-1 min-h-4 whitespace-nowrap text-xs leading-4 text-muted-foreground`,"aria-hidden":!0,children:[(0,r.jsx)("span",{children:"Core"}),(0,r.jsx)("span",{className:"truncate",children:null!==g?(0,r.jsx)("span",{className:"tnum",children:g}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"sm:hidden",children:"History"}),(0,r.jsx)("span",{className:"hidden sm:inline",children:"Peak usage over time"})]})}),(0,r.jsx)("span",{className:"hidden text-right sm:block",children:null!==g?"At cursor":"Last"}),(0,r.jsxs)("span",{className:"text-right",children:[(0,r.jsx)("span",{className:"hidden sm:inline",children:"Peak"}),(0,r.jsx)("span",{className:"sm:hidden",children:null!==g?"At cursor":"Peak"})]})]}),(0,r.jsx)("p",{id:`${h.id}-instructions`,className:"sr-only",children:"Focus a core chart and use Left and Right arrows to inspect recorded bucket peaks, Home or End to jump, and Escape to dismiss."}),(0,r.jsx)("div",{role:"region","aria-label":"Per-core history rows",tabIndex:0,className:"max-h-96 overflow-y-auto rounded-md",children:0===p.length?(0,r.jsx)("p",{className:"py-8 text-center text-xs text-muted-foreground",children:"No stored per-core readings."}):p.map(e=>{let t=!o.has(e.key),a=null===h.timeMs?null:(0,er.bO)(e.points,h.timeMs,i,l),c=a?.max??a?.avg??null;return(0,r.jsxs)("div",{className:`${ei} min-h-7 border-b border-border/40 text-xs`,children:[(0,r.jsxs)("label",{className:"inline-flex min-h-7 cursor-pointer items-center rounded-sm",children:[(0,r.jsx)("input",{type:"checkbox",checked:t,onChange:()=>d(e.key),className:"peer sr-only"}),(0,r.jsx)("span",{className:`${t?"text-foreground":"text-muted-foreground line-through"} rounded-sm peer-focus-visible:outline-2 peer-focus-visible:outline-accent`,children:e.label})]}),(0,r.jsxs)("svg",{viewBox:"0 0 120 18",preserveAspectRatio:"none",role:"img","aria-label":`${e.label}: ${null!==g?`${(0,S.dd)(c,"percent")} at ${g}`:`latest ${(0,S.dd)(e.stats.latest,"percent")}`}, peak ${(0,S.dd)(e.stats.max,"percent")}${t?"":", hidden"}`,"aria-describedby":`${h.id}-instructions`,tabIndex:t?0:void 0,onPointerDown:t?e=>{if("mouse"===e.pointerType)return;e.currentTarget.setPointerCapture(e.pointerId);let t=e.currentTarget.getBoundingClientRect();h.inspect((0,er.yk)(e.clientX,t.left,t.width,s,n))}:void 0,onPointerCancel:h.clear,onContextMenu:e=>e.preventDefault(),onPointerMove:t?e=>{let t=e.currentTarget.getBoundingClientRect();h.inspect((0,er.yk)(e.clientX,t.left,t.width,s,n))}:void 0,onFocus:h.onFocus,onBlur:h.clear,onKeyDown:h.onKeyDown,className:`h-7 w-full touch-pan-y select-none cursor-crosshair rounded-sm focus-visible:outline-2 focus-visible:outline-accent ${t?"":"opacity-20"}`,children:[(0,r.jsx)("title",{children:`${e.label} \xb7 Last ${(0,S.dd)(e.stats.latest,"percent")} \xb7 Peak ${(0,S.dd)(e.stats.max,"percent")}`}),t?e.paths.map((e,t)=>e?(0,r.jsx)("path",{d:e,fill:t<5?"var(--cpu)":t<8?"var(--warn)":"var(--crit)",opacity:t<5?.15+.17*t:.65+t%5*.07},t):null):null,b.map(e=>(0,r.jsx)("rect",{x:(e.fromMs-s)/f*120,width:(e.toMs-e.fromMs)/f*120,y:0,height:18,fill:"var(--card)"},`${e.fromMs}-${e.toMs}`)),null!==h.timeMs?(0,r.jsx)("line",{"aria-hidden":!0,x1:(h.timeMs-s)/f*120,x2:(h.timeMs-s)/f*120,y1:0,y2:18,stroke:"var(--foreground)",strokeWidth:"1",vectorEffect:"non-scaling-stroke",pointerEvents:"none"}):null]}),(0,r.jsx)("span",{className:"tnum hidden text-right text-muted-foreground sm:block",children:t?(0,S.dd)(null!==h.timeMs?c:e.stats.latest,"percent"):"—"}),(0,r.jsxs)("span",{className:`tnum text-right ${t&&(e.stats.max??0)>=80?"text-crit":"text-muted-foreground"}`,children:[(0,r.jsx)("span",{className:"hidden sm:inline",children:t?(0,S.dd)(e.stats.max,"percent"):"—"}),(0,r.jsx)("span",{className:"sm:hidden",children:t?(0,S.dd)(null!==h.timeMs?c:e.stats.max,"percent"):"—"})]})]},e.key)})}),(0,r.jsxs)("div",{className:`${ei} mt-2 text-xs text-muted-foreground`,"aria-hidden":!0,children:[(0,r.jsx)("span",{}),(0,r.jsx)("div",{className:"flex justify-between gap-2 tnum",children:(0,I.Cf)(s,n,3).map((e,t)=>(0,r.jsx)("span",{className:1===t?"hidden sm:inline":"",children:(0,S.O5)(e,f)},e))}),(0,r.jsx)("span",{className:"hidden sm:block"}),(0,r.jsx)("span",{})]}),(0,r.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[[{label:"0–49%",color:"var(--cpu)"},{label:"50–79%",color:"var(--warn)"},{label:"80–100%",color:"var(--crit)"}].map(e=>(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,r.jsx)("span",{"aria-hidden":!0,className:"h-2 w-4 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.label)),(0,r.jsx)("span",{children:"No fill \xb7 no reading"})]})]})}function el(e,t){return`${e}\0${t}`}function eo(e,t,s,r,n){let i=(0,y.oB)(s);return null===i?[]:e.series.filter(e=>e.metric===s&&(void 0===r||e.resourceId===r)).map((e,r)=>{let a=(0,y.Lf)(i,r),l=n?.(e,i,r)??(0,y.bP)(t,s,e.resourceId);return{key:el(e.metric,e.resourceId),label:l,metric:e.metric,resourceId:e.resourceId,color:a.color,dash:a.dash,points:e.points}})}function ed(e){let{machine:t,result:s,selectedMetrics:n,hiddenCards:i,hiddenSeries:a,onToggleSeries:l}=e,[o]=q(t.machineId),d=$(o,M(t,s.series)),c=function(e){let{machine:t,result:s,selectedMetrics:r,hiddenCards:n,coreIds:i}=e,a=new Set(r),l=[];if(["cpu.usage","cpu.core","cpu.temperature","cpu.power","cpu.iowait","cpu.pressure"].filter(e=>a.has(e)).length>0){let e=[],r=["cpu.usage","cpu.iowait","cpu.pressure"].filter(e=>a.has(e));if(r.length>0&&e.push({key:"cpu.usage",title:r.length>1?"Usage & stalls":(0,y.oB)(r[0]).label,unit:"percent",series:r.flatMap(e=>eo(s,t,e,void 0,(t,s)=>"cpu.pressure"===e?"Pressure (some)":s.shortLabel)),emptyMessage:"No stored CPU readings in this range."}),a.has("cpu.core")){let r=(0,y.oB)("cpu.core"),n=M(t,s.series),a=i??$(null,n),l=function(e,t){let s=(0,y.oB)("cpu.core");if(null===s)return[];let r=new Map(e.series.filter(e=>"cpu.core"===e.metric).map(e=>[e.resourceId,e]));return t.flatMap((e,t)=>{let n=r.get(e),i=(0,y.Lf)(s,t);return[{key:el("cpu.core",e),label:C(e),metric:"cpu.core",resourceId:e,color:i.color,dash:i.dash,points:n?.points??[]}]})}(s,a),o=n.length>a.length;e.push({key:"cpu.core",title:o?`Per-core usage \xb7 ${a.length} of ${n.length}`:"Per-core usage",unit:r.unit,series:l,emptyMessage:0===n.length?"No stored per-core readings in this range.":0===a.length?"No CPU cores are selected. Choose cores under Metrics.":"No stored per-core readings for the selected cores in this range."})}if(a.has("cpu.temperature")){let r=(0,y.oB)("cpu.temperature");e.push({key:"cpu.temperature",title:"Temperature",unit:r.unit,series:eo(s,t,"cpu.temperature"),emptyMessage:"No stored CPU temperature readings in this range."})}if(a.has("cpu.power")){let r=(0,y.oB)("cpu.power");e.push({key:"cpu.power",title:"Package power",unit:r.unit,series:eo(s,t,"cpu.power"),emptyMessage:"No stored CPU package power readings in this range."})}l.push({key:"cpu",title:"CPU",charts:e})}if(["memory.used","memory.usage","memory.pressure.some","memory.pressure.full","swap.used"].filter(e=>a.has(e)).length>0){let e=[],r=["memory.used","memory.usage"].filter(e=>a.has(e));if(r.length>0){let n=r.map(e=>({unit:(0,y.oB)(e).unit,series:eo(s,t,e,void 0,()=>"RAM")}));e.push({key:"memory.capacity",title:"RAM",...n[0],unitGroup:"memory",views:n,emptyMessage:"No stored memory readings in this range."})}a.has("swap.used")&&e.push({key:"swap.used",title:"Swap",unit:"bytes",series:eo(s,t,"swap.used"),emptyMessage:"No stored swap readings in this range."});let n=["memory.pressure.some","memory.pressure.full"].filter(e=>a.has(e));if(n.length>0){let r=(0,y.oB)(n[0]),i=n.flatMap(e=>eo(s,t,e,void 0,(t,s)=>"memory.pressure.some"===e?"Some":"memory.pressure.full"===e?"Full":s.shortLabel));e.push({key:"memory.pressure",title:"Memory pressure",unit:r.unit,series:i,emptyMessage:"No stored memory pressure in this range."})}l.push({key:"memory",title:"Memory",charts:e})}let o=["gpu.utilization","gpu.memory.used","gpu.temperature","gpu.power"].filter(e=>a.has(e));if(o.length>0){let e=(0,y.ue)(t,s.series),r=e.filter(e=>!n.has(e.id));for(let n of(0===r.length&&l.push({key:"gpu-empty",title:"GPU",charts:[{key:"gpu-empty",title:"Per-card history",unit:"percent",series:[],emptyMessage:e.length>0?"All GPU cards are hidden. Re-enable a card under Metrics to see its panels.":"No supported GPU cards or stored GPU history in this range."}]}),r)){let e=o.map(e=>{let r=(0,y.oB)(e),i=function(e,t,s,r){return eo(e,t,s,r,(e,t)=>"gpu.utilization"===s?"Utilization":"gpu.memory.used"===s?"VRAM used":t.shortLabel).map(e=>({...e}))}(s,t,e,n.id),a="gpu.memory.used"===e&&null!==n.totalBytes?`of ${(0,S.dd)(n.totalBytes,"bytes")}`:void 0;return{key:`${n.id}-${e}`,title:r.shortLabel,unit:r.unit,series:i,emptyMessage:`No stored ${r.shortLabel.toLowerCase()} readings for this card in this range.`,note:a}});l.push({key:`gpu-${n.id}`,title:`GPU ${n.index+1}${n.label?` \xb7 ${n.label}`:""}`,charts:e})}}if(["fs.used","fs.usage","fs.inodes.usage"].filter(e=>a.has(e)).length>0){let e=[],r=["fs.used","fs.usage"].filter(e=>a.has(e));if(r.length>0){let n=r.map(e=>({unit:(0,y.oB)(e).unit,series:eo(s,t,e)}));e.push({key:"fs.capacity",title:"Capacity used",...n[0],unitGroup:"filesystem",views:n,emptyMessage:"No stored filesystem usage in this range."})}if(a.has("fs.inodes.usage")){let r=(0,y.oB)("fs.inodes.usage");e.push({key:"fs.inodes.usage",title:"Inodes used",unit:r.unit,series:eo(s,t,"fs.inodes.usage"),emptyMessage:"No stored inode usage in this range."})}l.push({key:"filesystems",title:"Filesystems",charts:e})}let d=["disk.read","disk.write"].filter(e=>a.has(e));if(d.length>0){let e=d.flatMap(e=>{let r=(0,y.oB)(e);return eo(s,t,e,void 0,s=>`${(0,y.bP)(t,e,s.resourceId)} ${r.shortLabel.toLowerCase()}`)});l.push({key:"disk",title:"Disk throughput",charts:[{key:"disk",title:"Read and write",unit:"bytes_per_second",series:e,emptyMessage:"No stored disk throughput in this range."}]})}let c=["disk.read.latency","disk.write.latency"].filter(e=>a.has(e)),u=["io.pressure.some","io.pressure.full"].filter(e=>a.has(e));if(c.length>0||u.length>0||a.has("disk.utilization")){let e=[];if(c.length>0){let r=c.flatMap(e=>{let r=(0,y.oB)(e);return eo(s,t,e,void 0,s=>`${(0,y.bP)(t,e,s.resourceId)} ${r.shortLabel.toLowerCase()}`)}),n=(0,y.oB)(c[0]);e.push({key:"disk.latency",title:"Latency",unit:n.unit,series:r,emptyMessage:"No stored disk latency in this range."})}if(a.has("disk.utilization")){let r=(0,y.oB)("disk.utilization");e.push({key:"disk.utilization",title:"Utilization",unit:r.unit,series:eo(s,t,"disk.utilization"),emptyMessage:"No stored disk utilization in this range."})}if(u.length>0){let r=(0,y.oB)(u[0]),n=u.flatMap(e=>eo(s,t,e,void 0,(t,s)=>"io.pressure.some"===e?"Some":"io.pressure.full"===e?"Full":s.shortLabel));e.push({key:"io.pressure",title:"I/O pressure",unit:r.unit,series:n,emptyMessage:"No stored I/O pressure in this range."})}l.push({key:"disk-health",title:"Disk health",charts:e})}let m=["net.rx","net.tx"].filter(e=>a.has(e));if(m.length>0){let e=m.flatMap(e=>{let r=(0,y.oB)(e);return eo(s,t,e,void 0,s=>`${(0,y.bP)(t,e,s.resourceId)} ${r.shortLabel.toLowerCase()}`)});l.push({key:"network",title:"Network throughput",charts:[{key:"network",title:"Received and sent",unit:"bytes_per_second",series:e,emptyMessage:"No stored network throughput in this range."}]})}return l}({machine:t,result:s,selectedMetrics:n,hiddenCards:i,coreIds:d});return(0,r.jsx)(en._C,{children:(0,r.jsx)("div",{className:"grid grid-cols-1 gap-5",children:c.map(n=>{let i=n.charts.find(e=>"cpu.core"===e.key&&e.series.length>4),o=i?[...n.charts.filter(e=>e!==i),i]:n.charts,d=i&&4===o.length?"grid gap-6 lg:grid-cols-2 xl:grid-cols-3":o.length>1&&!(i&&2===o.length)?"grid gap-6 lg:grid-cols-2":"flex flex-col gap-6";return(0,r.jsx)(h.Z,{title:n.title,children:(0,r.jsx)("div",{className:d,children:o.map((n,d)=>{let c=n.unitGroup,u=c?e.capacityUnits[c]:void 0,m=n.views?.find(e=>e.unit===u)??n.views?.[0]??n,h=n===i||!i&&o.length%2==1&&d===o.length-1;return"cpu.core"===n.key&&n.series.length>8?(0,r.jsx)(ea,{title:n.title,series:n.series,fromMs:s.fromMs,toMs:s.toMs,gaps:s.gaps,stepMs:(0,I.jl)(s.stepMs,s.tier,t.expectedIntervalMs),hiddenKeys:a,onToggleSeries:l},n.key):(0,r.jsx)(es.t,{title:n.title,unit:m.unit,series:m.series,fromMs:s.fromMs,toMs:s.toMs,stepMs:(0,I.jl)(s.stepMs,s.tier,t.expectedIntervalMs),gaps:s.gaps,hiddenKeys:a,onToggleSeries:l,emptyMessage:n.emptyMessage,note:n.note,action:c&&n.views&&n.views.length>1?(0,r.jsx)("div",{role:"group","aria-label":`${n.title} units`,className:"inline-flex rounded-md border border-border bg-background p-0.5",children:n.views.map(t=>(0,r.jsx)("button",{type:"button","aria-pressed":t.unit===m.unit,onClick:()=>e.onCapacityUnitChange(c,t.unit),className:`min-h-7 rounded px-2 text-xs transition-colors ${t.unit===m.unit?"bg-selected text-foreground":"text-muted-foreground hover:text-foreground"}`,children:"bytes"===t.unit?"Bytes":"%"},t.unit))}):void 0,maxDrawPoints:"cpu.core"===n.key?150:void 0,className:h?"lg:col-span-full":void 0},n.key)})})},n.key)})})},`${t.machineId}|${s.toMs-s.fromMs}`)}var ec=s(1),eu=s(7499);let em={raw:"raw samples","1m":"1-minute rollups","1h":"1-hour rollups"};function eh(e){return e.displayName?.trim()||e.hostname.trim()||e.machineId}function ep(e,t){return`${e}\0${t}`}function ex(e){let t=new Set(e.selectedMetrics),s=new Set((0,y.ue)(e.machine,e.result.series).filter(t=>!e.hiddenCards.has(t.id)).map(e=>e.id));return e.result.series.filter(r=>!(!t.has(r.metric)||e.hiddenSeries.has(ep(r.metric,r.resourceId))||"cpu.core"===r.metric&&void 0!==e.coreIds&&!e.coreIds.includes(r.resourceId)||r.metric.startsWith("gpu.")&&""!==r.resourceId&&!s.has(r.resourceId)))}function eg(e){return new Date(e).toISOString()}function ef(e){return(0,y.oB)(e)?.label??e}function eb(e){return ex(e).map(t=>({metric:t.metric,label:ef(t.metric),resourceId:t.resourceId,resourceLabel:(0,y.bP)(e.machine,t.metric,t.resourceId),unit:t.unit,unitLabel:(0,y.RL)(t.unit),stats:(0,I.T6)(t.points),points:t.points.map(t=>{let s=Math.min(e.result.toMs,t.t+e.result.stepMs),r=null!==t.min||null!==t.max||null!==t.avg;return{t:t.t,tIso:eg(t.t),bucketStartMs:t.t,bucketStartIso:eg(t.t),bucketEndMs:s,bucketEndIso:eg(s),min:t.min,max:t.max,avg:t.avg,state:r?"recorded":"unavailable"}})}))}function ey(e){return(0,I.$z)(e.result.gaps,e.result.fromMs,e.result.toMs).map(e=>({...e,fromIso:eg(e.fromMs),toIso:eg(e.toMs)}))}function ej(e){let t=new Set(e.result.series.map(e=>e.metric));return e.selectedMetrics.filter(e=>!t.has(e))}function ev(e){let t=new Set(e.selectedMetrics),s=new Set(ex(e).map(e=>ep(e.metric,e.resourceId)));return e.result.series.filter(e=>t.has(e.metric)&&!s.has(ep(e.metric,e.resourceId))).length}function eN(e,t){let s=e.result,r=["Only the visible series from the loaded History result are included; this export does not query more data."];"raw"!==s.tier&&r.push(`Values are ${em[s.tier]}, not individual raw samples.`),s.truncated&&r.push("The loaded result is partial: the hub limited or shortened this history query.");let n=ey(e);n.length>0&&r.push(`${n.length} recorded data gap${1===n.length?"":"s"} included.`),t.length>0&&r.push(`Selected metrics without stored data: ${t.join(", ")}.`);let i=ev(e);return i>0&&r.push(`${i} selected series hidden in this view were not exported.`),r}let ew=["record_type","metric","metric_label","resource_id","resource_label","unit","bucket_start_ms","bucket_start_iso","bucket_end_ms","bucket_end_iso","min","max","avg","value_state","gap_kind","gap_reason","gap_dropped_records"],ek="inline-flex min-h-7 items-center rounded-md border border-border bg-background px-2 text-xs text-foreground transition-colors hover:bg-card-strong disabled:cursor-not-allowed disabled:opacity-50";function eM(e){let[t,s]=(0,a.useState)(null),n=ex(e).length,i=t=>{let r=Date.now(),n={...e,exportedAt:r};try{let e,i,a,l,o,d,c,u,m=function(e,t,s=Date.now()){return(0,eu.Y8)("history",eh(e.machine),s,t)}(n,t,r),h="csv"===t?function(e){let t,s,r,n,i,a,l=e.exportedAt??Date.now(),o=(t=(0,S.ly)(e.range),s=e.result,r=ex(e),n=ej(e),i=ey(e),a=e.selectedMetrics.map(ef).join("; "),[["Rigscope History export"],["Scope","Visible series from the loaded History result"],["Machine",eh(e.machine)],["Machine ID",e.machine.machineId],["Query",a],["Range",`${t.label} (${eg(s.fromMs)} – ${eg(s.toMs)})`],["Resolution",`${em[s.tier]} \xb7 ${s.stepMs} ms buckets`],["Loaded at",eg(e.loadedAt)],["Exported at",eg(l)],["Partial",s.truncated?"true":"false"],["Gaps",String(i.length)],["Visible series",String(r.length)],["Selected without stored data",n.length>0?n.join(", "):"none"],["Note",eN(e,n).join(" ")],[]]);for(let t of(o.push([...ew]),eb(e)))for(let e of t.points)o.push(["bucket",t.metric,t.label,t.resourceId,t.resourceLabel,t.unit,e.bucketStartMs,e.bucketStartIso,e.bucketEndMs,e.bucketEndIso,e.min,e.max,e.avg,e.state,"","",""]);for(let t of ey(e))o.push(["gap","","","","","",t.fromMs,t.fromIso,t.toMs,t.toIso,"","","","gap",t.kind,t.reason??"",t.droppedRecords??""]);return(0,ec.kg)(o)}(n):(e=n.exportedAt??Date.now(),i=(0,S.ly)(n.range),a=n.result,l=eb(n),o=ej(n),d=ey(n),c=ev(n),u={app:"Rigscope",kind:"history",exportedAt:eg(e),scope:{description:"Visible series from the loaded History result",machine:{id:n.machine.machineId,name:eh(n.machine),hostname:n.machine.hostname,connected:n.machine.connected,lastReceivedAt:n.machine.lastReceivedAt},query:{range:{id:i.id,label:i.label,fromMs:a.fromMs,fromIso:eg(a.fromMs),toMs:a.toMs,toIso:eg(a.toMs)},selectedMetrics:[...n.selectedMetrics],visibleSeries:l.length,hiddenSeriesCount:c}},resolution:{tier:a.tier,label:em[a.tier],stepMs:a.stepMs,expectedIntervalMs:n.machine.expectedIntervalMs??null},loadedAt:eg(n.loadedAt),partial:a.truncated,gaps:d,series:l.map(e=>({metric:e.metric,label:e.label,resourceId:e.resourceId,resourceLabel:e.resourceLabel,unit:e.unit,unitLabel:e.unitLabel,summary:{points:e.stats.count,min:e.stats.min,max:e.stats.max,averageOfBucketAverages:e.stats.avg,latest:e.stats.latest,latestAt:null===e.stats.latestT?null:eg(e.stats.latestT),firstAt:null===e.stats.firstT?null:eg(e.stats.firstT),lastAt:null===e.stats.lastT?null:eg(e.stats.lastT)},points:e.points})),missingData:o.map(e=>({metric:e,label:ef(e),reason:"No stored series in the loaded result."})),notes:eN(n,o)},`${JSON.stringify(u,null,2)}
3
+ `);(0,ec.PE)(m,h,"csv"===t?ec.UR:ec.uW),s(null)}catch{s("The history export could not be created.")}};return(0,r.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Export visible",(0,r.jsx)("span",{className:"sr-only",children:` (${n} series from the loaded result)`})]}),(0,r.jsx)("button",{type:"button",onClick:()=>i("csv"),"aria-label":"Download visible history as CSV",title:"Download the visible series from this loaded result as CSV",className:ek,children:"CSV"}),(0,r.jsx)("button",{type:"button",onClick:()=>i("json"),"aria-label":"Download visible history as JSON",title:"Download the visible series from this loaded result as JSON",className:ek,children:"JSON"}),null!==t?(0,r.jsxs)("span",{role:"status",className:"inline-flex items-center gap-1 text-xs text-warn",children:[(0,r.jsx)(d.A,{className:"h-3 w-3","aria-hidden":!0}),t]}):null]})}function e$(e){return e.displayName?.trim()||e.hostname.trim()||e.machineId}function eC(){return(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-5 xl:grid-cols-2","aria-busy":"true",children:[(0,r.jsx)(h.Z,{title:"Loading stored history",children:(0,r.jsx)("div",{className:"h-40 animate-pulse rounded-lg bg-card-strong","aria-hidden":!0})}),(0,r.jsx)(h.Z,{title:"Preparing charts",children:(0,r.jsx)("div",{className:"h-40 animate-pulse rounded-lg bg-card-strong","aria-hidden":!0})})]})}function eI(){let e,t,s,n,{session:j,phase:v,machines:N,retryConnection:w}=(0,f.M)(),k=(0,g.x)(),{machine:C,machineId:P,requestedMachineId:R}=(0,b.JG)("history"),[U,L]=W(P,"memory"),[T,B]=W(P,"filesystem"),z={memory:U,filesystem:T},[E,H]=(0,_.u)("history.range","10m",F),[Z,V]=(0,_.u)(`history.metrics.${P}`,null,O),[K]=q(P),Y=M(C),J=$(K,Y),[X,Q]=G(P,"cards"),[es,er]=G(P,"series"),en=(0,a.useMemo)(()=>new Set(X),[X]),ei=(0,a.useMemo)(()=>new Set(es),[es]),[ea,el]=(0,_.u)("history.autoRefresh",!0,D,"session"),[eo,ec]=(0,a.useState)(null),[eu,em]=(0,a.useState)(null),[eh,ep]=(0,a.useState)(0),ex=(0,a.useRef)(null),[eg,ef]=(0,a.useState)(null),[eb,ey]=(0,a.useState)(Date.now);(0,a.useEffect)(()=>{if(void 0===C){ex.current=null,ef(null);return}let e=ex.current,t={connected:C.connected,lastReceivedAt:C.lastReceivedAt},s=e?.machineId===C.machineId?e.point:null;ef(e=>{let r=function(e,t,s,r){let n=e.findIndex(e=>null===e.toMs);if(!s.connected){if(n>=0)return e;let i=[...e,{fromMs:A(s.lastReceivedAt)??A(t?.lastReceivedAt??null)??r,toMs:null}];return i.length>64?i.slice(i.length-64):i}if(n<0||null===t||t.connected)return e;let i=e[n],a=A(s.lastReceivedAt),l=null!==a&&a>i.fromMs?a:Math.max(i.fromMs,r);return e.map((e,t)=>t===n?{fromMs:e.fromMs,toMs:l}:e)}(e?.machineId===C.machineId?e.outages:[],s,t,Date.now());return e?.machineId===C.machineId&&e.outages===r?e:{machineId:C.machineId,outages:r}}),t.connected&&s?.connected!==!1||ey(Date.now()),ex.current={machineId:C.machineId,point:t}},[C?.machineId,C?.connected,C?.lastReceivedAt]),(0,a.useEffect)(()=>{if(C?.connected!==!1||!ea)return;let e=window.setInterval(()=>{"visible"===document.visibilityState&&ey(Date.now())},1e3);return()=>window.clearInterval(e)},[C?.machineId,C?.connected,ea]);let ej=(0,a.useMemo)(()=>void 0===C?"":(0,y.er)(C).join(","),[C?.machineId,C?.inventory,C?.metrics?.payload.gpus]),ev=Z??ej,eN=""===ev?[]:ev.split(","),ew="signed-in"===j.kind&&void 0!==C&&""!==P&&""!==ev;(0,a.useEffect)(()=>{if(""===P){ec(null),em(null);return}let e=new AbortController;return ec(null),em(null),fetch(`/api/history/metrics?machineId=${encodeURIComponent(P)}`,{signal:e.signal,cache:"no-store",headers:{Accept:"application/json"}}).then(async t=>{if(!t.ok){if(401===t.status||403===t.status||404===t.status)return;throw Error(`catalog ${t.status}`)}let s=await t.json();if(null===s||"object"!=typeof s||!("metrics"in s))throw Error("catalog shape");let r=s.metrics;if(null===r||"object"!=typeof r)throw Error("catalog shape");let n=Object.create(null);for(let[e,t]of Object.entries(r))null!==t&&"object"==typeof t&&"string"==typeof t.unit&&(n[e]={unit:t.unit});e.signal.aborted||ec(n)}).catch(()=>{e.signal.aborted||em("The hub's metric catalog could not be loaded; standard metric names are shown.")}),()=>e.abort()},[P]);let{data:ek,error:eI,loading:eA,manualRefreshing:eS}=(0,et.n)({machineId:P,metricsKey:ev,coreIdsKey:eN.includes("cpu.core")&&J.length!==Y.length?J.join(","):void 0,range:E,enabled:ew,autoRefresh:ea,refreshNonce:eh});(0,a.useEffect)(()=>{eI?.kind==="rate-limited"&&el(!1)},[eI?.kind,el]);let eP=(0,a.useMemo)(()=>{if(!ek||eg?.machineId!==P||0===eg.outages.length)return ek;let e=ek.result,t=Math.max(e.toMs,...eg.outages.map(e=>e.toMs??eb)),s=e.fromMs+t-e.toMs;return{...ek,result:{...e,fromMs:s,toMs:t,gaps:(0,I.$z)([...e.gaps,...function(e,t,s){if(!Number.isFinite(t)||!Number.isFinite(s)||s<=t)return[];let r=[];for(let n of e){let e=Math.max(t,n.fromMs),i=Math.min(s,n.toMs??s);Number.isFinite(e)&&Number.isFinite(i)&&!(i<=e)&&r.push({fromMs:e,toMs:i,kind:"missing",reason:null===n.toMs?"collector disconnected":"collector outage"})}var n=r;let i=n.filter(e=>Number.isFinite(e.fromMs)&&Number.isFinite(e.toMs)&&e.toMs>e.fromMs).map(e=>({...e})).sort((e,t)=>e.fromMs-t.fromMs||e.toMs-t.toMs),a=[];for(let e of i){let t=a.at(-1);if(void 0!==t&&e.fromMs<=t.toMs){t.toMs=Math.max(t.toMs,e.toMs),"dropped"===e.kind&&(t.kind="dropped"),void 0===t.reason&&void 0!==e.reason&&(t.reason=e.reason),void 0===t.droppedRecords&&void 0!==e.droppedRecords&&(t.droppedRecords=e.droppedRecords);continue}a.push(e)}return a}(eg.outages,s,t)],s,t)}}},[ek,P,eg,eb]),eR=eP?.result??null,eU=void 0===C?[]:(0,y.ue)(C,eR?.series??[]),eL=(0,S.ly)(E),eT=null!==eI?null!==eP?`${"rate-limited"===eI.kind?"Refresh paused":"Refresh failed"} \xb7 ${(0,S.ei)(eP.loadedAt)}`:"History unavailable":null!==eP?`Updated ${(0,S.ei)(eP.loadedAt)}`:eA?"Loading…":"",e_=ew&&null===eP&&null===eI,eB=N.length,ez="disconnected"===v;return(0,r.jsx)(m.G,{title:"History",machineId:P,machineView:"history",headerRight:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(p.$E,{}),(0,r.jsx)(x.B,{})]}),children:k||(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"sr-only",children:eI?.message??""}),(0,r.jsx)(ee,{machine:C,range:E,selectedMetrics:eN,catalog:eo,catalogError:eu,gpuCards:eU,hiddenCards:en,autoRefresh:ea,loading:eA,manualRefreshing:eS,statusText:eT,onRangeChange:H,onToggleMetric:e=>{let t=new Set(eN);t.has(e)?t.delete(e):t.add(e),V([...t].sort().join(","))},onSetMetrics:e=>V([...new Set(e)].sort().join(",")),onToggleCard:e=>{Q(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),[...s]})},onToggleAutoRefresh:()=>el(e=>!e),onRefresh:()=>ep(e=>e+1)}),"reconnecting"===v||"disconnected"===v?(0,r.jsxs)("div",{role:"status",className:"mb-4 flex items-start gap-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(d.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,r.jsxs)("span",{children:["Live feed ","disconnected"===v?"disconnected":"reconnecting"," \xb7 stored history available"]}),"disconnected"===v?(0,r.jsxs)("button",{type:"button",onClick:w,className:"ml-auto inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,r.jsx)(u.A,{className:"h-3 w-3","aria-hidden":!0}),"Retry now"]}):null]}):null,void 0===C?ez?(0,r.jsxs)(h.Z,{title:"Hub disconnected",className:"mx-auto mt-3 max-w-xl",children:[(0,r.jsx)(h.p,{icon:c.A,note:"The hub is unreachable, so the authorized machine list is unavailable."}),(0,r.jsx)("div",{className:"mt-2 flex justify-center",children:(0,r.jsxs)("button",{type:"button",onClick:w,className:"inline-flex min-h-8 items-center gap-1.5 rounded-md border border-border px-3 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Check again"]})})]}):0!==eB||ez||"idle"!==v&&"connecting"!==v&&"reconnecting"!==v?0===eB?(0,r.jsx)(h.Z,{title:"No machines",className:"mx-auto mt-3 max-w-xl",children:(0,r.jsx)(h.p,{icon:o.A,note:"No machines are available in your authorized fleet."})}):(0,r.jsxs)(h.Z,{title:"Machine not found",className:"mx-auto mt-3 max-w-xl",children:[(0,r.jsx)(h.p,{icon:o.A,note:"This machine is unavailable or outside your access."}),R?(0,r.jsxs)("p",{className:"tnum mt-2 text-center text-xs text-muted-foreground",children:["Requested identifier: ",R]}):null,(0,r.jsx)("div",{className:"mt-2 flex justify-center",children:(0,r.jsx)(i(),{href:"/",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:"Back to fleet"})})]}):(0,r.jsx)(h.Z,{title:"Waiting for machines",className:"mx-auto mt-3 max-w-xl",children:(0,r.jsx)(h.p,{icon:o.A,note:"Waiting for the hub to report your authorized machines…"})}):0===eN.length?(0,r.jsx)(h.Z,{title:"No metrics selected",className:"mx-auto mt-3 max-w-xl",children:(0,r.jsx)(h.p,{icon:o.A,note:""===ej?"No metric families are shared with this hub.":"Choose at least one metric above to draw history."})}):null!==eI&&null===eP?(t=(e=function(e){switch(e.kind){case"unauthorized":return{title:"Session ended",note:"Your session is no longer accepted, so stored history is hidden.",icon:l.A};case"denied":return{title:"History access denied",note:e.message,icon:l.A};case"missing":return{title:"Machine unavailable",note:e.message,icon:o.A};case"rate-limited":return{title:"History requests limited",note:e.message,icon:d.A};case"unavailable":return{title:"History unavailable",note:e.message,icon:c.A};case"network":return{title:"Hub unreachable",note:"The hub could not be reached for stored history.",icon:c.A};case"invalid":return{title:"Unexpected history response",note:e.message,icon:d.A}}}(eI)).icon,(0,r.jsxs)(h.Z,{title:e.title,className:"mx-auto mt-3 max-w-xl",children:[(0,r.jsx)(h.p,{icon:t,note:e.note}),(0,r.jsxs)("div",{className:"mt-2 flex flex-wrap justify-center gap-2",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>ep(e=>e+1),className:"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Try again"]}),"unauthorized"===eI.kind?(0,r.jsx)(i(),{href:"/login",className:"inline-flex items-center rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90",children:"Sign in"}):null]})]})):(eA||e_)&&null===eP?(0,r.jsx)(eC,{}):null===eP?(0,r.jsx)(h.Z,{title:"History",className:"mx-auto mt-3 max-w-xl",children:(0,r.jsx)(h.p,{icon:o.A,note:"No stored history has arrived yet."})}):(n="raw"===(s=eP.result).tier?"raw samples":"1m"===s.tier?"1-minute rollups":"1-hour rollups",(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"mb-3 flex flex-wrap items-baseline gap-x-4 gap-y-1 text-xs text-muted-foreground",children:[(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-foreground",children:[(0,r.jsx)("span",{"aria-hidden":!0,className:`inline-block h-2 w-2 shrink-0 rounded-full ${C.connected?"bg-ok":"bg-crit"}`}),e$(C)]}),(0,r.jsxs)("span",{children:[(0,S.r6)(s.fromMs)," – ",(0,S.r6)(s.toMs)]}),(0,r.jsxs)("span",{className:"tnum",title:n,children:[(0,S.I_)(s.stepMs)," buckets"]}),(0,r.jsx)("div",{className:"ml-auto self-center",children:(0,r.jsx)(eM,{machine:C,result:s,range:E,selectedMetrics:(0,y.Cv)(eN,z),hiddenCards:en,hiddenSeries:ei,coreIds:J,loadedAt:eP.loadedAt})})]}),s.truncated?(0,r.jsxs)("div",{role:"status",className:"mb-4 flex items-start gap-2 rounded-lg bg-warn-soft px-4 py-2.5 text-xs text-foreground",children:[(0,r.jsx)(d.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,r.jsx)("span",{children:"Partial history \xb7 narrow the range for more detail."})]}):null,s.gaps.length>0?(0,r.jsxs)("details",{className:"mb-4 max-w-3xl text-xs text-muted-foreground",children:[(0,r.jsxs)("summary",{className:"inline-flex min-h-8 cursor-pointer items-center gap-2 rounded-md text-warn",children:[(0,r.jsx)(d.A,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,r.jsxs)("span",{children:[(0,r.jsx)("strong",{className:"font-medium",children:"Data gaps:"})," ",(0,S.fH)(s.gaps,s.fromMs,s.toMs)]})]}),(0,r.jsxs)("ul",{className:"mt-1.5 flex flex-col gap-1",children:[s.gaps.slice(0,20).map(e=>(0,r.jsxs)("li",{className:"tnum text-xs",children:[(0,S.r6)(e.fromMs)," – ",(0,S.r6)(e.toMs)," (",(0,S.I_)(e.toMs-e.fromMs),"):"," ","dropped"===e.kind?"dropped":"missed",e.reason?` \xb7 ${e.reason}`:"",void 0!==e.droppedRecords?` \xb7 ${e.droppedRecords} record${1===e.droppedRecords?"":"s"}`:""]},`${e.fromMs}-${e.toMs}-${e.kind}`)),s.gaps.length>20?(0,r.jsxs)("li",{className:"text-xs text-muted-foreground",children:["…and ",s.gaps.length-20," more."]}):null]})]}):null,0===s.series.length?(0,r.jsx)(h.Z,{title:"No stored points",className:"mx-auto max-w-xl",children:(0,r.jsx)(h.p,{icon:o.A,note:`No stored readings for ${void 0===C?"this machine":e$(C)} in ${eL.label.toLowerCase()}.`})}):(0,r.jsx)(ed,{machine:C,result:s,selectedMetrics:eN,hiddenCards:en,hiddenSeries:ei,onToggleSeries:e=>{er(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),[...s]})},capacityUnits:z,onCapacityUnitChange:(e,t)=>("memory"===e?L:B)(t)})]}))]})})}},6582:(e,t,s)=>{"use strict";s.d(t,{E:()=>f,x:()=>g});var r=s(5155),n=s(8500),i=s.n(n),a=s(828),l=s(6914),o=s(7029),d=s(438),c=s(7422),u=s(1735),m=s(3440),h=s(9939);function p(e){return(0,r.jsxs)("button",{type:"button",onClick:e.onClick,className:"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:[(0,r.jsx)(a.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.children]})}function x(e){return(0,r.jsx)(i(),{href:e.href,className:e.primary?"inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground transition-colors hover:bg-accent/90":"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground transition-colors hover:bg-card-strong",children:e.children})}function g(){let{session:e,phase:t,retryConnection:s}=(0,h.M)();switch(e.kind){case"restoring":return(0,r.jsx)(m.Z,{title:"Checking session",className:"mx-auto my-12 max-w-md",children:(0,r.jsx)(m.p,{icon:l.A,note:"Checking your session…"})});case"restore-failed":return(0,r.jsxs)(m.Z,{title:"Hub unreachable",className:"mx-auto my-12 max-w-md",children:[(0,r.jsx)(m.p,{icon:o.A,note:"The hub is unreachable right now."}),(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(p,{onClick:s,children:"Check again"})})]});case"signed-out":if("expired"===t)return(0,r.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,r.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(x,{href:"/login",primary:!0,children:"Sign in"})})]});return(0,r.jsxs)(m.Z,{title:"Sign in required",className:"mx-auto my-12 max-w-md",children:[(0,r.jsx)(m.p,{icon:l.A,note:"Sign in required."}),(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(x,{href:"/login",primary:!0,children:"Sign in"})})]});case"auth-unavailable":return(0,r.jsx)(m.Z,{title:"Sign-in unavailable",className:"mx-auto my-12 max-w-md",children:(0,r.jsx)(m.p,{icon:c.A,note:"Browser sign-in is not configured on this hub."})})}return"expired"===t?(0,r.jsxs)(m.Z,{title:"Session ended",className:"mx-auto my-12 max-w-md",children:[(0,r.jsx)(m.p,{icon:d.A,note:"Your session ended."}),(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(x,{href:"/login",primary:!0,children:"Sign in"})})]}):"no-permission"===t?(0,r.jsxs)(m.Z,{title:"No permission",className:"mx-auto my-12 max-w-md",children:[(0,r.jsx)(m.p,{icon:c.A,note:`You are signed in as ${e.user.username}, but this hub grants no machine view to this account.`}),(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(p,{onClick:s,children:"Check again"})})]}):null}function f(){let{phase:e,retryConnection:t}=(0,h.M)();return"reconnecting"!==e&&"disconnected"!==e&&"connecting"!==e?null:"connecting"===e?(0,r.jsxs)("div",{role:"status",className:"mb-5 flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(a.A,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),"Connecting to the live feed — waiting for the first snapshot."]}):(0,r.jsxs)("div",{role:"status",className:"mb-5 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border border-border bg-card px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 shrink-0 text-warn","aria-hidden":!0}),(0,r.jsxs)("span",{children:["Connection lost — values below are ",(0,r.jsx)("strong",{className:"font-medium text-foreground",children:"last known"}),", not live measurements","reconnecting"===e?" — retrying with backoff…":" — retries stopped."]}),"disconnected"===e?(0,r.jsx)(p,{onClick:t,children:"Retry now"}):null]})}},7499:(e,t,s)=>{"use strict";function r(e,t,s,r){return`rigscope-${e}-${function(e,t="machine"){let s=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48).replace(/-+$/g,"");return s.length>0?s:t}(t)}-${!Number.isFinite(s)?"unknown-time":new Date(s).toISOString().replace(/[-:]/g,"").replace(/\.\d{3}Z$/,"Z")}.${r}`}s.d(t,{Y8:()=>r})},9942:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});let r=(0,s(8698).A)("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]])}},e=>{e.O(0,[944,939,103,408,441,794,358],()=>e(e.s=2727)),_N_E=e.O()}]);