@peers-app/peers-ui 0.34.8 → 0.34.10

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 (79) hide show
  1. package/dist/apps-home/apps-home.js +6 -4
  2. package/dist/components/router.d.ts +1 -1
  3. package/dist/components/router.js +1 -1
  4. package/dist/screens/devices/devices-list.d.ts +5 -1
  5. package/dist/screens/devices/devices-list.js +12 -4
  6. package/dist/screens/identity/identity-routes.d.ts +2 -1
  7. package/dist/screens/identity/identity-routes.js +6 -1
  8. package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
  9. package/dist/screens/monitoring/alerts-tab.js +68 -0
  10. package/dist/screens/monitoring/badges.d.ts +25 -0
  11. package/dist/screens/monitoring/badges.js +68 -0
  12. package/dist/screens/monitoring/calls-tab.d.ts +30 -0
  13. package/dist/screens/monitoring/calls-tab.js +104 -0
  14. package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
  15. package/dist/screens/monitoring/charts/chart-math.js +200 -0
  16. package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
  17. package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
  18. package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
  19. package/dist/screens/monitoring/charts/line-chart.js +103 -0
  20. package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
  21. package/dist/screens/monitoring/charts/sparkline.js +61 -0
  22. package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
  23. package/dist/screens/monitoring/charts/use-width.js +31 -0
  24. package/dist/screens/monitoring/definition-forms.d.ts +113 -0
  25. package/dist/screens/monitoring/definition-forms.js +341 -0
  26. package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
  27. package/dist/screens/monitoring/definitions-tab.js +110 -0
  28. package/dist/screens/monitoring/device-picker.d.ts +22 -0
  29. package/dist/screens/monitoring/device-picker.js +29 -0
  30. package/dist/screens/monitoring/form-fields.d.ts +76 -0
  31. package/dist/screens/monitoring/form-fields.js +65 -0
  32. package/dist/screens/monitoring/format.d.ts +51 -0
  33. package/dist/screens/monitoring/format.js +150 -0
  34. package/dist/screens/monitoring/log-lines.d.ts +74 -0
  35. package/dist/screens/monitoring/log-lines.js +138 -0
  36. package/dist/screens/monitoring/log-row.d.ts +12 -0
  37. package/dist/screens/monitoring/log-row.js +23 -0
  38. package/dist/screens/monitoring/logs-tab.d.ts +15 -0
  39. package/dist/screens/monitoring/logs-tab.js +256 -0
  40. package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
  41. package/dist/screens/monitoring/metric-definition-form.js +50 -0
  42. package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
  43. package/dist/screens/monitoring/metrics-tab.js +149 -0
  44. package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
  45. package/dist/screens/monitoring/monitoring-routes.js +81 -0
  46. package/dist/screens/monitoring/monitoring-screen.d.ts +17 -0
  47. package/dist/screens/monitoring/monitoring-screen.js +63 -0
  48. package/dist/screens/monitoring/overview-tab.d.ts +33 -0
  49. package/dist/screens/monitoring/overview-tab.js +121 -0
  50. package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
  51. package/dist/screens/monitoring/telemetry-client.js +92 -0
  52. package/dist/screens/monitoring/trigger-form.d.ts +18 -0
  53. package/dist/screens/monitoring/trigger-form.js +71 -0
  54. package/dist/screens/monitoring/use-telemetry.d.ts +39 -0
  55. package/dist/screens/monitoring/use-telemetry.js +120 -0
  56. package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
  57. package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
  58. package/dist/system-apps/index.d.ts +1 -1
  59. package/dist/system-apps/index.js +5 -5
  60. package/dist/system-apps/monitoring.app.d.ts +6 -0
  61. package/dist/system-apps/monitoring.app.js +13 -0
  62. package/dist/tabs-layout/tabs-state.d.ts +4 -2
  63. package/dist/tabs-layout/tabs-state.js +23 -11
  64. package/dist/theme.css +32 -0
  65. package/package.json +3 -3
  66. package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
  67. package/dist/screens/console-logs/console-logs-list.js +0 -284
  68. package/dist/screens/console-logs/follow-newest.d.ts +0 -11
  69. package/dist/screens/console-logs/follow-newest.js +0 -17
  70. package/dist/screens/console-logs/log-display.d.ts +0 -12
  71. package/dist/screens/console-logs/log-display.js +0 -69
  72. package/dist/screens/console-logs/log-filters.d.ts +0 -10
  73. package/dist/screens/console-logs/log-filters.js +0 -8
  74. package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
  75. package/dist/screens/console-logs/mobile-log-card.js +0 -94
  76. package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
  77. package/dist/screens/console-logs/resizable-table-header.js +0 -62
  78. package/dist/system-apps/console-logs.app.d.ts +0 -2
  79. package/dist/system-apps/console-logs.app.js +0 -8
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Monitoring app routes: `monitoring/<section>`, with the device, trace and metric being looked at
4
+ * in the query, so a link opens the same view and every section keeps the chosen device.
5
+ *
6
+ * `console-logs`, Console Logs' old path, opens the Logs section (see `canonicalizeRoute`).
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MONITORING_LOGS_PATH = exports.MONITORING_SECTIONS = exports.LEGACY_CONSOLE_LOGS_PATH = exports.MONITORING_APP_PATH = void 0;
10
+ exports.parseMonitoringLocation = parseMonitoringLocation;
11
+ exports.monitoringPath = monitoringPath;
12
+ /** Top-level Monitoring path. Opening it lands on Overview. */
13
+ exports.MONITORING_APP_PATH = "monitoring";
14
+ /** The path Console Logs had, rewritten to {@link MONITORING_LOGS_PATH}. */
15
+ exports.LEGACY_CONSOLE_LOGS_PATH = "console-logs";
16
+ /** Monitoring's sections, in sidebar order. */
17
+ exports.MONITORING_SECTIONS = [
18
+ "overview",
19
+ "metrics",
20
+ "alerts",
21
+ "definitions",
22
+ "logs",
23
+ "calls",
24
+ ];
25
+ /** The Logs section's path, where `console-logs` lands. */
26
+ exports.MONITORING_LOGS_PATH = `${exports.MONITORING_APP_PATH}/logs`;
27
+ const SECTIONS = new Set(exports.MONITORING_SECTIONS);
28
+ /**
29
+ * Read a Monitoring route.
30
+ *
31
+ * @param raw - A route, with or without a leading `#` and a query.
32
+ * @returns Where it points, or `undefined` when it isn't a Monitoring route.
33
+ */
34
+ function parseMonitoringLocation(raw) {
35
+ const text = (raw ?? "").trim().replace(/^\/?#/, "");
36
+ const queryIndex = text.indexOf("?");
37
+ const pathname = (queryIndex >= 0 ? text.slice(0, queryIndex) : text)
38
+ .replace(/^\/+|\/+$/g, "")
39
+ .toLowerCase();
40
+ const query = new URLSearchParams(queryIndex >= 0 ? text.slice(queryIndex + 1) : "");
41
+ const parts = pathname.split("/").filter(Boolean);
42
+ let section;
43
+ if (parts[0] === exports.LEGACY_CONSOLE_LOGS_PATH) {
44
+ section = "logs";
45
+ }
46
+ else if (parts[0] === exports.MONITORING_APP_PATH) {
47
+ section = SECTIONS.has(parts[1] ?? "") ? parts[1] : "overview";
48
+ }
49
+ else {
50
+ return undefined;
51
+ }
52
+ const location = { section };
53
+ const deviceId = query.get("device")?.trim();
54
+ const traceId = query.get("trace")?.trim();
55
+ const metricId = query.get("metric")?.trim();
56
+ if (deviceId)
57
+ location.deviceId = deviceId;
58
+ if (traceId)
59
+ location.traceId = traceId;
60
+ if (metricId)
61
+ location.metricId = metricId;
62
+ return location;
63
+ }
64
+ /**
65
+ * Build a Monitoring route.
66
+ *
67
+ * @param location - The section, and the device, trace and metric to keep.
68
+ * @returns A route such as `monitoring/logs?device=…&trace=…`.
69
+ */
70
+ function monitoringPath(location) {
71
+ const query = new URLSearchParams();
72
+ if (location.deviceId)
73
+ query.set("device", location.deviceId);
74
+ if (location.traceId)
75
+ query.set("trace", location.traceId);
76
+ if (location.metricId)
77
+ query.set("metric", location.metricId);
78
+ const queryString = query.toString();
79
+ const path = `${exports.MONITORING_APP_PATH}/${location.section}`;
80
+ return queryString ? `${path}?${queryString}` : path;
81
+ }
@@ -0,0 +1,17 @@
1
+ import { type IMonitoringLocation, type MonitoringSectionId } from "./monitoring-routes";
2
+ /** What every section gets: where it is, and a way to go somewhere else in Monitoring. */
3
+ export interface MonitoringSectionProps {
4
+ location: IMonitoringLocation;
5
+ /** Go to another section or view, keeping the device unless `next` names one. */
6
+ navigate: (next: Partial<IMonitoringLocation> & {
7
+ section: MonitoringSectionId;
8
+ }) => void;
9
+ }
10
+ /**
11
+ * Monitoring: one of the user's devices' logs, metrics, calls and alerts, and the metric and
12
+ * trigger definitions behind them. The device picker applies to every section, and the route
13
+ * keeps the device, so a link opens the same view.
14
+ */
15
+ export declare function MonitoringScreen(props: {
16
+ path?: string;
17
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MonitoringScreen = MonitoringScreen;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const responsive_section_nav_1 = require("../../components/responsive-section-nav");
6
+ const globals_1 = require("../../globals");
7
+ const hooks_1 = require("../../hooks");
8
+ const ui_loader_1 = require("../../ui-router/ui-loader");
9
+ const alerts_tab_1 = require("./alerts-tab");
10
+ const calls_tab_1 = require("./calls-tab");
11
+ const definitions_tab_1 = require("./definitions-tab");
12
+ const device_picker_1 = require("./device-picker");
13
+ const logs_tab_1 = require("./logs-tab");
14
+ const metrics_tab_1 = require("./metrics-tab");
15
+ const monitoring_routes_1 = require("./monitoring-routes");
16
+ const overview_tab_1 = require("./overview-tab");
17
+ const use_telemetry_1 = require("./use-telemetry");
18
+ const SECTIONS = [
19
+ { id: "overview", label: "Overview", iconClassName: "bi-speedometer2" },
20
+ { id: "metrics", label: "Metrics", iconClassName: "bi-graph-up" },
21
+ { id: "alerts", label: "Alerts", iconClassName: "bi-bell" },
22
+ { id: "definitions", label: "Definitions", iconClassName: "bi-sliders" },
23
+ { id: "logs", label: "Logs", iconClassName: "bi-list-columns-reverse" },
24
+ { id: "calls", label: "Calls", iconClassName: "bi-arrow-left-right" },
25
+ ];
26
+ /**
27
+ * Monitoring: one of the user's devices' logs, metrics, calls and alerts, and the metric and
28
+ * trigger definitions behind them. The device picker applies to every section, and the route
29
+ * keeps the device, so a link opens the same view.
30
+ */
31
+ function MonitoringScreen(props) {
32
+ const [livePath] = (0, hooks_1.useObservable)(globals_1.mainContentPath);
33
+ const location = (0, monitoring_routes_1.parseMonitoringLocation)(props.path ?? livePath);
34
+ // A kept-mounted tab whose route is another app's shows (and reads) nothing.
35
+ if (!location)
36
+ return null;
37
+ const navigate = (next) => {
38
+ (0, globals_1.mainContentPath)((0, monitoring_routes_1.monitoringPath)({ deviceId: location.deviceId, ...next }));
39
+ };
40
+ const section = { location, navigate };
41
+ return ((0, jsx_runtime_1.jsx)(responsive_section_nav_1.ResponsiveSectionNav, { label: "Monitoring", sections: SECTIONS, activeSectionId: location.section, onSelect: (id) => navigate({ section: id }), toolbar: (0, jsx_runtime_1.jsx)(Toolbar, { location: location }), children: (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [location.section === "overview" ? (0, jsx_runtime_1.jsx)(overview_tab_1.OverviewTab, { ...section }) : null, location.section === "metrics" ? (0, jsx_runtime_1.jsx)(metrics_tab_1.MetricsTab, { ...section }) : null, location.section === "alerts" ? (0, jsx_runtime_1.jsx)(alerts_tab_1.AlertsTab, { ...section }) : null, location.section === "definitions" ? (0, jsx_runtime_1.jsx)(definitions_tab_1.DefinitionsTab, { ...section }) : null, location.section === "logs" ? (0, jsx_runtime_1.jsx)(logs_tab_1.LogsTab, { ...section }) : null, location.section === "calls" ? (0, jsx_runtime_1.jsx)(calls_tab_1.CallsTab, { ...section }) : null] }, location.deviceId ?? "this") }));
42
+ }
43
+ /** The title and the device picker; it reads the user's devices only while Monitoring is shown. */
44
+ function Toolbar(props) {
45
+ const { location } = props;
46
+ const devices = (0, use_telemetry_1.useMyDevices)();
47
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 border-bottom px-3 py-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "me-auto fw-semibold", children: "Monitoring" }), (0, jsx_runtime_1.jsx)(device_picker_1.DevicePicker, { devices: devices, deviceId: location.deviceId, onChange: (deviceId) => (0, globals_1.mainContentPath)((0, monitoring_routes_1.monitoringPath)({ section: location.section, deviceId })) })] }));
48
+ }
49
+ (0, ui_loader_1.registerInternalPeersUI)({
50
+ component: MonitoringScreen,
51
+ routes: [
52
+ {
53
+ isMatch: (_props, context) => {
54
+ const path = context.path.split("?")[0].toLowerCase();
55
+ return (path === monitoring_routes_1.MONITORING_APP_PATH ||
56
+ path.startsWith(`${monitoring_routes_1.MONITORING_APP_PATH}/`) ||
57
+ path === monitoring_routes_1.LEGACY_CONSOLE_LOGS_PATH);
58
+ },
59
+ uiCategory: "screen",
60
+ priority: 3,
61
+ },
62
+ ],
63
+ });
@@ -0,0 +1,33 @@
1
+ import { type IAlertEvent, type IAlertState, type IMetricQueryResult, type ITelemetryConsumer, type ITelemetryStatus } from "@peers-app/peers-sdk";
2
+ import type { MonitoringSectionProps } from "./monitoring-screen";
3
+ /** Metrics the Overview's tiles read. */
4
+ export declare const OVERVIEW_METRICS: {
5
+ readonly errors: "logs.errors";
6
+ readonly calls: "calls.duration";
7
+ readonly failedDials: "mesh.attempt.failures";
8
+ };
9
+ /** What the Overview reads, in one go. */
10
+ export interface IOverviewData {
11
+ errors?: IMetricQueryResult;
12
+ calls?: IMetricQueryResult;
13
+ failedDials?: IMetricQueryResult;
14
+ status?: ITelemetryStatus;
15
+ alerts?: {
16
+ triggers: IAlertState[];
17
+ events: IAlertEvent[];
18
+ };
19
+ }
20
+ /**
21
+ * Read everything the Overview shows: the last 24 hours of errors, calls and failed dials by hour,
22
+ * telemetry's own status, and the alerts. The calls leave out Monitoring's own reads, which would
23
+ * otherwise set their p95. One part failing leaves the rest.
24
+ *
25
+ * @param telemetry - The device's System Telemetry.
26
+ * @param now - The current time (for tests).
27
+ */
28
+ export declare function readOverview(telemetry: ITelemetryConsumer, now?: number): Promise<IOverviewData>;
29
+ /**
30
+ * Overview: errors, call latency, failed dials and the telemetry database's size over the last 24
31
+ * hours, then what's firing and the latest alerts.
32
+ */
33
+ export declare function OverviewTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OVERVIEW_METRICS = void 0;
4
+ exports.readOverview = readOverview;
5
+ exports.OverviewTab = OverviewTab;
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
8
+ const badges_1 = require("./badges");
9
+ const chart_math_1 = require("./charts/chart-math");
10
+ const sparkline_1 = require("./charts/sparkline");
11
+ const form_fields_1 = require("./form-fields");
12
+ const format_1 = require("./format");
13
+ const telemetry_client_1 = require("./telemetry-client");
14
+ const use_telemetry_1 = require("./use-telemetry");
15
+ /** Metrics the Overview's tiles read. */
16
+ exports.OVERVIEW_METRICS = {
17
+ errors: "logs.errors",
18
+ calls: "calls.duration",
19
+ failedDials: "mesh.attempt.failures",
20
+ };
21
+ /**
22
+ * Read everything the Overview shows: the last 24 hours of errors, calls and failed dials by hour,
23
+ * telemetry's own status, and the alerts. The calls leave out Monitoring's own reads, which would
24
+ * otherwise set their p95. One part failing leaves the rest.
25
+ *
26
+ * @param telemetry - The device's System Telemetry.
27
+ * @param now - The current time (for tests).
28
+ */
29
+ async function readOverview(telemetry, now = Date.now()) {
30
+ const from = now - peers_sdk_1.RESOLUTION_MS.day;
31
+ const range = { from, to: now, resolution: "hour" };
32
+ const [errors, calls, failedDials, status, alerts] = await Promise.allSettled([
33
+ telemetry.tools.queryMetric({ metricId: exports.OVERVIEW_METRICS.errors, ...range, stats: ["count"] }),
34
+ telemetry.tools.queryMetric({
35
+ metricId: exports.OVERVIEW_METRICS.calls,
36
+ ...range,
37
+ exclude: telemetry_client_1.OWN_READS,
38
+ stats: ["count", "p95"],
39
+ histogram: true,
40
+ }),
41
+ telemetry.tools.queryMetric({
42
+ metricId: exports.OVERVIEW_METRICS.failedDials,
43
+ ...range,
44
+ stats: ["count"],
45
+ }),
46
+ telemetry.tools.status({}),
47
+ telemetry.tools.alerts({ limit: 10 }),
48
+ ]);
49
+ const settled = [errors, calls, failedDials, status, alerts];
50
+ if (settled.every((result) => result.status === "rejected")) {
51
+ throw errors.reason;
52
+ }
53
+ const value = (result) => result.status === "fulfilled" ? result.value : undefined;
54
+ return {
55
+ errors: value(errors),
56
+ calls: value(calls),
57
+ failedDials: value(failedDials),
58
+ status: value(status),
59
+ alerts: value(alerts),
60
+ };
61
+ }
62
+ /**
63
+ * Overview: errors, call latency, failed dials and the telemetry database's size over the last 24
64
+ * hours, then what's firing and the latest alerts.
65
+ */
66
+ function OverviewTab(props) {
67
+ const { data, error, loading, readAt, refresh } = (0, use_telemetry_1.useTelemetryRead)(props.location.deviceId, (telemetry) => readOverview(telemetry), []);
68
+ const toolbar = ((0, jsx_runtime_1.jsx)("div", { className: "d-flex justify-content-end mb-2", children: (0, jsx_runtime_1.jsx)(form_fields_1.RefreshButton, { onClick: refresh, loading: loading, readAt: data ? readAt : undefined }) }));
69
+ if (!data && error) {
70
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [toolbar, (0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning", children: (0, telemetry_client_1.describeTelemetryError)(error) })] }));
71
+ }
72
+ if (!data)
73
+ return (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" });
74
+ const openMetric = (metricId) => props.navigate({ section: "metrics", metricId });
75
+ const errors = trendOf(data.errors, "count");
76
+ const dials = trendOf(data.failedDials, "count");
77
+ const callP95 = trendOf(data.calls, "p95");
78
+ const callCount = data.calls ? (0, chart_math_1.sumOf)(data.calls.points.map((p) => p.count)) : undefined;
79
+ const p95 = data.calls?.histogram ? (0, chart_math_1.percentileFromBins)(data.calls.histogram, 0.95) : undefined;
80
+ const active = (data.alerts?.triggers ?? []).filter((t) => t.state !== "ok" && !t.disabled);
81
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { opacity: loading ? 0.7 : 1, transition: "opacity 150ms" }, children: [toolbar, (0, jsx_runtime_1.jsxs)("div", { className: "row g-3 mb-4", children: [(0, jsx_runtime_1.jsx)(Tile, { label: "Errors, last 24 hours", value: data.errors ? (0, format_1.formatNumber)((0, chart_math_1.sumOf)(errors.values)) : "–", caption: "Error lines logged", trend: { ...errors, label: "Errors per hour", formatValue: format_1.formatNumber }, onOpen: () => openMetric(exports.OVERVIEW_METRICS.errors) }), (0, jsx_runtime_1.jsx)(Tile, { label: "Call p95, last 24 hours", value: (0, format_1.formatDuration)(p95), caption: callCount === undefined ? "Contract calls" : `${(0, format_1.formatNumber)(callCount)} calls`, trend: { ...callP95, label: "Call p95 per hour", formatValue: format_1.formatDuration }, onOpen: () => openMetric(exports.OVERVIEW_METRICS.calls) }), (0, jsx_runtime_1.jsx)(Tile, { label: "Failed dials, last 24 hours", value: data.failedDials ? (0, format_1.formatNumber)((0, chart_math_1.sumOf)(dials.values)) : "–", caption: "Connection attempts that failed", trend: { ...dials, label: "Failed dials per hour", formatValue: format_1.formatNumber }, onOpen: () => openMetric(exports.OVERVIEW_METRICS.failedDials) }), (0, jsx_runtime_1.jsx)(Tile, { label: "Telemetry database", value: (0, format_1.formatBytes)(data.status?.databaseBytes), caption: data.status
82
+ ? `${(0, format_1.formatNumber)(data.status.logRows)} log lines · ${(0, format_1.formatNumber)(data.status.rollupRows)} metric rows`
83
+ : "Size on disk" })] }), (0, jsx_runtime_1.jsx)(TelemetryHealth, { status: data.status, device: (0, telemetry_client_1.isThisDevice)(props.location.deviceId) ? "This device" : "That device" }), (0, jsx_runtime_1.jsxs)("h2", { className: "h6 d-flex align-items-center gap-2", children: ["Alerts", (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 ms-auto", onClick: () => props.navigate({ section: "alerts" }), children: "All alerts" })] }), !data.alerts ? ((0, jsx_runtime_1.jsx)("p", { className: "text-body-secondary small", children: "Couldn't read this device's alerts." })) : active.length === 0 ? ((0, jsx_runtime_1.jsxs)("p", { className: "text-body-secondary small", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle me-1", "aria-hidden": "true" }), "Nothing is firing."] })) : ((0, jsx_runtime_1.jsx)("ul", { className: "list-group mb-3", children: active.map((trigger) => ((0, jsx_runtime_1.jsxs)("li", { className: "list-group-item d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsx)(badges_1.AlertStateBadge, { state: trigger.state }), (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: trigger.description || trigger.triggerId }), (0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary", children: (0, format_1.formatAgo)(trigger.since) })] }, trigger.triggerId))) })), data.alerts && data.alerts.events.length > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h3", { className: "h6 text-body-secondary small mt-3", children: "Recent" }), (0, jsx_runtime_1.jsx)("ul", { className: "list-unstyled small", children: data.alerts.events.slice(0, 5).map((event) => ((0, jsx_runtime_1.jsxs)("li", { className: "d-flex gap-2 align-items-center mb-1", children: [(0, jsx_runtime_1.jsx)(badges_1.AlertStateBadge, { state: event.state }), (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1 text-truncate", children: event.detail || event.triggerId }), (0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary text-nowrap", children: (0, format_1.formatAgo)(event.at) })] }, `${event.triggerId}:${event.at}:${event.state}`))) })] })) : null] }));
84
+ }
85
+ /** A metric's last 24 hours by hour, as a sparkline draws it. */
86
+ function trendOf(result, stat) {
87
+ if (!result)
88
+ return { values: [], times: [] };
89
+ const data = (0, chart_math_1.toTimeSeries)(result, stat);
90
+ return { values: data.series[0]?.values ?? [], times: data.times };
91
+ }
92
+ function Tile(props) {
93
+ const { trend } = props;
94
+ const summary = trend ? (0, sparkline_1.describeTrend)(trend, trend.formatValue) : undefined;
95
+ const body = ((0, jsx_runtime_1.jsxs)("div", { className: "card-body", children: [(0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary", children: props.label }), (0, jsx_runtime_1.jsx)("div", { className: "fs-3 fw-semibold", children: props.value }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-end justify-content-between gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary", children: props.caption }), trend ? (0, jsx_runtime_1.jsx)(sparkline_1.Sparkline, { ...trend }) : null] })] }));
96
+ const name = [
97
+ `${props.label}: ${props.value}.`,
98
+ summary && trend ? `${trend.label}: ${summary}.` : "",
99
+ "Open in Metrics",
100
+ ];
101
+ return ((0, jsx_runtime_1.jsx)("div", { className: "col-12 col-sm-6 col-xl-3", children: props.onOpen ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "card h-100 w-100 text-start", onClick: props.onOpen, "aria-label": name.filter(Boolean).join(" "), children: body })) : ((0, jsx_runtime_1.jsx)("div", { className: "card h-100", children: body })) }));
102
+ }
103
+ /**
104
+ * Telemetry's own trouble: definitions the device shown switched off or refused, and lines it
105
+ * dropped. `device` names it as Definitions does: this device, or that one.
106
+ */
107
+ function TelemetryHealth(props) {
108
+ const { status, device } = props;
109
+ if (!status)
110
+ return null;
111
+ // Earlier telemetry v1 devices report stopped metrics only.
112
+ const { stopped, stoppedTriggers = [] } = status;
113
+ if (stopped.length === 0 && stoppedTriggers.length === 0 && status.droppedLines === 0) {
114
+ return null;
115
+ }
116
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-warning small", children: [stopped.length > 0 ? ((0, jsx_runtime_1.jsx)(StoppedList, { heading: `${device} switched off ${stopped.length === 1 ? "a metric" : `${stopped.length} metrics`}`, items: stopped.map((item) => ({ ...item, id: item.metricId })) })) : null, stoppedTriggers.length > 0 ? ((0, jsx_runtime_1.jsx)(StoppedList, { heading: `${device} refused ${stoppedTriggers.length === 1 ? "a trigger" : `${stoppedTriggers.length} triggers`}`, items: stoppedTriggers.map((item) => ({ ...item, id: item.triggerId })) })) : null, status.droppedLines > 0 ? ((0, jsx_runtime_1.jsxs)("div", { children: ["Log lines and calls dropped since startup \u00B7 ", (0, format_1.formatNumber)(status.droppedLines)] })) : null] }));
117
+ }
118
+ /** Definitions a device stopped, each with where it came from and why. */
119
+ function StoppedList(props) {
120
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "fw-semibold mb-1", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle-fill me-1", "aria-hidden": "true" }), props.heading] }), (0, jsx_runtime_1.jsx)("ul", { className: "mb-1", children: props.items.map((item) => ((0, jsx_runtime_1.jsxs)("li", { children: [(0, jsx_runtime_1.jsx)("code", { children: item.id }), item.origin ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [" ", (0, jsx_runtime_1.jsx)(badges_1.OriginBadge, { origin: item.origin, packageId: item.packageId })] })) : null, ": ", item.reason] }, `${item.origin ?? ""}:${item.packageId ?? ""}:${item.id}`))) })] }));
121
+ }
@@ -0,0 +1,48 @@
1
+ import { type ITelemetryConsumer } from "@peers-app/peers-sdk";
2
+ /**
3
+ * Monitoring's own reads as the call metrics label them: its calls to System Telemetry, made as it
4
+ * refreshes. Pass it as a query's `exclude` to leave them out of `calls.duration`.
5
+ */
6
+ export declare const OWN_READS: Readonly<Record<string, string>>;
7
+ /**
8
+ * Whether a device id names this device: no id, or this device's own.
9
+ *
10
+ * @param deviceId - The device being looked at.
11
+ */
12
+ export declare function isThisDevice(deviceId: string | undefined): boolean;
13
+ /**
14
+ * System Telemetry on this device, or on another of the user's devices. Another device's calls go
15
+ * through this device's host, which forwards them over the mesh; that device answers only its
16
+ * owner's devices (System Telemetry has no remote access level).
17
+ *
18
+ * @param deviceId - The device to read; omit for this device.
19
+ * @returns A consumer whose tools run on that device.
20
+ */
21
+ export declare function getTelemetry(deviceId?: string): Promise<ITelemetryConsumer>;
22
+ /**
23
+ * Why a telemetry call failed:
24
+ *
25
+ * - `unavailable`: the device runs a Peers version without telemetry.
26
+ * - `denied`: the device doesn't take this call from here (another device's `clearLogs`, say).
27
+ * - `unreachable`: the device isn't connected, or didn't answer.
28
+ * - `failed`: anything else, such as a definition the device refused to save.
29
+ */
30
+ export type TelemetryErrorKind = "unavailable" | "denied" | "unreachable" | "failed";
31
+ /**
32
+ * Classify a telemetry call's error, so a view can say what to do about it.
33
+ *
34
+ * @param error - What the call threw.
35
+ */
36
+ export declare function classifyTelemetryError(error: unknown): TelemetryErrorKind;
37
+ /**
38
+ * An error's text as the tool worded it.
39
+ *
40
+ * @param error - What a call threw.
41
+ */
42
+ export declare function errorText(error: unknown): string;
43
+ /**
44
+ * A sentence for a failed read, worded for its kind.
45
+ *
46
+ * @param error - What the call threw.
47
+ */
48
+ export declare function describeTelemetryError(error: unknown): string;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OWN_READS = void 0;
4
+ exports.isThisDevice = isThisDevice;
5
+ exports.getTelemetry = getTelemetry;
6
+ exports.classifyTelemetryError = classifyTelemetryError;
7
+ exports.errorText = errorText;
8
+ exports.describeTelemetryError = describeTelemetryError;
9
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
10
+ const local = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getTelemetryContractDefinition)());
11
+ /**
12
+ * Monitoring's own reads as the call metrics label them: its calls to System Telemetry, made as it
13
+ * refreshes. Pass it as a query's `exclude` to leave them out of `calls.duration`.
14
+ */
15
+ exports.OWN_READS = {
16
+ contract: (0, peers_sdk_1.getTelemetryContractDefinition)().name,
17
+ };
18
+ let remote;
19
+ /**
20
+ * Whether a device id names this device: no id, or this device's own.
21
+ *
22
+ * @param deviceId - The device being looked at.
23
+ */
24
+ function isThisDevice(deviceId) {
25
+ return !deviceId || deviceId === (0, peers_sdk_1.thisDeviceId)();
26
+ }
27
+ /**
28
+ * System Telemetry on this device, or on another of the user's devices. Another device's calls go
29
+ * through this device's host, which forwards them over the mesh; that device answers only its
30
+ * owner's devices (System Telemetry has no remote access level).
31
+ *
32
+ * @param deviceId - The device to read; omit for this device.
33
+ * @returns A consumer whose tools run on that device.
34
+ */
35
+ async function getTelemetry(deviceId) {
36
+ if (isThisDevice(deviceId)) {
37
+ return local.get();
38
+ }
39
+ const transport = (0, peers_sdk_1.getHostContractTransport)() ?? (await (0, peers_sdk_1.waitForHostContractTransport)({ timeoutMs: 5_000 }));
40
+ if (remote?.transport !== transport) {
41
+ remote?.consumer.dispose();
42
+ remote = {
43
+ transport,
44
+ consumer: (0, peers_sdk_1.createRemoteContractConsumer)((0, peers_sdk_1.getTelemetryContractDefinition)(), transport),
45
+ };
46
+ }
47
+ return remote.consumer.device(deviceId);
48
+ }
49
+ /**
50
+ * Classify a telemetry call's error, so a view can say what to do about it.
51
+ *
52
+ * @param error - What the call threw.
53
+ */
54
+ function classifyTelemetryError(error) {
55
+ const message = errorText(error);
56
+ if (/No contract provider registered|has no live resolver|no provider for/i.test(message)) {
57
+ return "unavailable";
58
+ }
59
+ if (/Permission denied/i.test(message)) {
60
+ return "denied";
61
+ }
62
+ if (message.includes(peers_sdk_1.CONNECTION_CLOSED_MESSAGE) ||
63
+ /not connected|not reachable|timed out|did not answer/i.test(message)) {
64
+ return "unreachable";
65
+ }
66
+ return "failed";
67
+ }
68
+ /**
69
+ * An error's text as the tool worded it.
70
+ *
71
+ * @param error - What a call threw.
72
+ */
73
+ function errorText(error) {
74
+ return error instanceof Error ? error.message : String(error);
75
+ }
76
+ /**
77
+ * A sentence for a failed read, worded for its kind.
78
+ *
79
+ * @param error - What the call threw.
80
+ */
81
+ function describeTelemetryError(error) {
82
+ switch (classifyTelemetryError(error)) {
83
+ case "unavailable":
84
+ return "This device runs a version of Peers without telemetry. Update it to see its logs and metrics.";
85
+ case "unreachable":
86
+ return `Couldn't reach this device: ${errorText(error)}`;
87
+ case "denied":
88
+ return `This device refused: ${errorText(error)}`;
89
+ default:
90
+ return errorText(error);
91
+ }
92
+ }
@@ -0,0 +1,18 @@
1
+ import type { IMetricInfo, ITriggerDefinition } from "@peers-app/peers-sdk";
2
+ /** Props for {@link TriggerForm}. */
3
+ export interface TriggerFormProps {
4
+ /** The trigger to edit; omit to create one. */
5
+ definition?: ITriggerDefinition;
6
+ /** The device's metrics, offered for the trigger's metric. */
7
+ metrics: IMetricInfo[];
8
+ /** Called once it's saved, with its id. */
9
+ onSaved: (triggerId: string) => void;
10
+ onCancel: () => void;
11
+ }
12
+ /**
13
+ * Create or edit one of the user's triggers: a condition on a metric, checked on each device as
14
+ * each minute closes, and what to do when it fires (notify, call a tool, or both). It's saved on
15
+ * this device and syncs to the user's other devices. A save the device refuses shows the reason as
16
+ * the device words it.
17
+ */
18
+ export declare function TriggerForm(props: TriggerFormProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TriggerForm = TriggerForm;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const definition_forms_1 = require("./definition-forms");
7
+ const form_fields_1 = require("./form-fields");
8
+ const telemetry_client_1 = require("./telemetry-client");
9
+ const STATS = [
10
+ { value: "count", label: "count" },
11
+ { value: "sum", label: "sum" },
12
+ { value: "avg", label: "average" },
13
+ { value: "min", label: "minimum" },
14
+ { value: "max", label: "maximum" },
15
+ { value: "last", label: "last" },
16
+ { value: "p50", label: "p50" },
17
+ { value: "p90", label: "p90" },
18
+ { value: "p95", label: "p95" },
19
+ { value: "p99", label: "p99" },
20
+ { value: "ratio", label: "ratio (share that matches)" },
21
+ ];
22
+ const OPS = [
23
+ { value: ">", label: "above (>)" },
24
+ { value: ">=", label: "at or above (≥)" },
25
+ { value: "<", label: "below (<)" },
26
+ { value: "<=", label: "at or below (≤)" },
27
+ ];
28
+ const LEVELS = [
29
+ { value: "priority", label: "Priority" },
30
+ { value: "quiet", label: "Quiet" },
31
+ { value: "loud", label: "Loud" },
32
+ ];
33
+ /**
34
+ * Create or edit one of the user's triggers: a condition on a metric, checked on each device as
35
+ * each minute closes, and what to do when it fires (notify, call a tool, or both). It's saved on
36
+ * this device and syncs to the user's other devices. A save the device refuses shows the reason as
37
+ * the device words it.
38
+ */
39
+ function TriggerForm(props) {
40
+ const editing = !!props.definition;
41
+ const [form, setForm] = (0, react_1.useState)(() => props.definition
42
+ ? (0, definition_forms_1.triggerDefinitionToForm)(props.definition)
43
+ : (0, definition_forms_1.emptyTriggerForm)(props.metrics[0]?.metricId));
44
+ const [error, setError] = (0, react_1.useState)();
45
+ const [saving, setSaving] = (0, react_1.useState)(false);
46
+ const set = (key) => (value) => setForm((prev) => ({ ...prev, [key]: value }));
47
+ const save = async () => {
48
+ const built = (0, definition_forms_1.toTriggerDefinition)(form);
49
+ if (built.error !== undefined) {
50
+ setError(built.error);
51
+ return;
52
+ }
53
+ setSaving(true);
54
+ setError(undefined);
55
+ try {
56
+ const telemetry = await (0, telemetry_client_1.getTelemetry)();
57
+ const result = await telemetry.tools.saveTriggerDefinition({ definition: built.definition });
58
+ props.onSaved(result.triggerId);
59
+ }
60
+ catch (cause) {
61
+ setError((0, telemetry_client_1.errorText)(cause));
62
+ }
63
+ finally {
64
+ setSaving(false);
65
+ }
66
+ };
67
+ return ((0, jsx_runtime_1.jsxs)("form", { className: "card card-body mb-3", "aria-label": editing ? `Edit trigger ${form.triggerId}` : "New trigger", onSubmit: (event) => {
68
+ event.preventDefault();
69
+ void save();
70
+ }, children: [(0, jsx_runtime_1.jsx)("h2", { className: "h6", children: editing ? `Edit ${form.triggerId}` : "New trigger" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-id", label: "Trigger id", value: form.triggerId, onChange: set("triggerId"), disabled: editing, monospace: true, placeholder: "sync.slow" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "col-md-6", children: [(0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-metric", label: "Metric", value: form.metricId, onChange: set("metricId"), monospace: true, list: "trigger-metrics" }), (0, jsx_runtime_1.jsx)("datalist", { id: "trigger-metrics", children: props.metrics.map((metric) => ((0, jsx_runtime_1.jsx)("option", { value: metric.metricId }, metric.metricId))) })] })] }), (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-description", label: "Description", value: form.description, onChange: set("description") }), (0, jsx_runtime_1.jsx)(form_fields_1.TextAreaField, { id: "trigger-where", label: "Only these series", value: form.where, onChange: set("where"), placeholder: "groupId = 00abc\u2026", hint: 'One "label = value" per line; leave empty for every series.' }), (0, jsx_runtime_1.jsx)("h3", { className: "h6 small text-body-secondary mt-2", children: "Condition" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-6 col-md-3", children: (0, jsx_runtime_1.jsx)(form_fields_1.SelectField, { id: "trigger-stat", label: "Statistic", value: form.stat, options: STATS, onChange: set("stat") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-6 col-md-3", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-window", label: "Over (minutes)", value: form.windowMinutes, onChange: set("windowMinutes"), inputMode: "numeric", hint: "1 to 60." }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-6 col-md-3", children: (0, jsx_runtime_1.jsx)(form_fields_1.SelectField, { id: "trigger-op", label: "Is", value: form.op, options: OPS, onChange: set("op") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-6 col-md-3", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-threshold", label: "Threshold", value: form.threshold, onChange: set("threshold"), inputMode: "decimal" }) })] }), form.stat === "ratio" ? ((0, jsx_runtime_1.jsx)(form_fields_1.TextAreaField, { id: "trigger-ratio-where", label: "Counted as matching", value: form.ratioWhere, onChange: set("ratioWhere"), placeholder: "outcome = error", hint: "The share of the window's count whose labels also equal these (0 to 1)." })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-min-count", label: "Ignore until the window holds", value: form.minCount, onChange: set("minCount"), inputMode: "numeric", hint: "Observations; optional." }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-for", label: "Fire after it holds for (minutes)", value: form.forMinutes, onChange: set("forMinutes"), inputMode: "numeric" }) })] }), (0, jsx_runtime_1.jsx)("h3", { className: "h6 small text-body-secondary mt-2", children: "When it fires" }), (0, jsx_runtime_1.jsx)(form_fields_1.CheckField, { id: "trigger-notify", label: "Notify me (taken back when it resolves)", checked: form.notify, onChange: set("notify") }), form.notify ? ((0, jsx_runtime_1.jsxs)("div", { className: "row g-2 ms-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-5", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-notify-title", label: "Title", value: form.notifyTitle, onChange: set("notifyTitle") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-5", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-notify-body", label: "Body", value: form.notifyBody, onChange: set("notifyBody") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-2", children: (0, jsx_runtime_1.jsx)(form_fields_1.SelectField, { id: "trigger-notify-level", label: "Level", value: form.notifyLevel, options: LEVELS, onChange: set("notifyLevel") }) })] })) : null, (0, jsx_runtime_1.jsx)(form_fields_1.CheckField, { id: "trigger-tool", label: "Call a tool (as you)", checked: form.tool, onChange: set("tool") }), form.tool ? ((0, jsx_runtime_1.jsxs)("div", { className: "ms-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-5", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-tool-contract", label: "Contract id", value: form.toolContractId, onChange: set("toolContractId"), monospace: true }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-2", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-tool-version", label: "Version", value: form.toolVersion, onChange: set("toolVersion"), inputMode: "numeric" }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-5", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-tool-name", label: "Tool", value: form.toolName, onChange: set("toolName"), monospace: true }) })] }), (0, jsx_runtime_1.jsx)(form_fields_1.TextAreaField, { id: "trigger-tool-args", label: "Arguments (JSON)", value: form.toolArgs, onChange: set("toolArgs"), rows: 3, placeholder: '{ "reason": "sync is slow" }' }), (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "trigger-tool-provider", label: "Provider package id", value: form.toolProviderPackageId, onChange: set("toolProviderPackageId"), monospace: true, hint: "Only when the contract has more than one provider." })] })) : null, (0, jsx_runtime_1.jsx)(form_fields_1.CheckField, { id: "trigger-disabled", label: "Off (kept, but not checked)", checked: form.disabled, onChange: set("disabled") }), error ? ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger small py-2", role: "alert", children: error })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-primary btn-sm", disabled: saving, children: saving ? "Saving…" : "Save" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", onClick: props.onCancel, children: "Cancel" }), (0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary align-self-center ms-auto", children: "Syncs to your other devices." })] })] }));
71
+ }
@@ -0,0 +1,39 @@
1
+ import { type ITelemetryConsumer } from "@peers-app/peers-sdk";
2
+ import { type DependencyList } from "react";
3
+ /** A telemetry read's state. */
4
+ export interface ITelemetryRead<T> {
5
+ /** The latest result; kept while a refresh runs, cleared on failure or when the device changes. */
6
+ data: T | undefined;
7
+ /** What the latest attempt threw, until one succeeds. */
8
+ error: unknown;
9
+ /** Whether a read is running. */
10
+ loading: boolean;
11
+ /** When `data` was read, epoch ms. */
12
+ readAt: number | undefined;
13
+ /** Read again now. */
14
+ refresh: () => void;
15
+ }
16
+ /**
17
+ * Read from a device's System Telemetry, again whenever `deps` change and, while the page is
18
+ * visible, `refreshMs` after the last read finished. A refresh keeps the last result on screen (a
19
+ * view dims it); a failed read clears it; a different device starts empty, so one device's numbers
20
+ * never show under another's name.
21
+ *
22
+ * @param deviceId - The device to read; omit for this device.
23
+ * @param read - The read, given the device's consumer.
24
+ * @param deps - What the read depends on, besides the device.
25
+ * @param refreshMs - Read again this often; omit to read only on change.
26
+ */
27
+ export declare function useTelemetryRead<T>(deviceId: string | undefined, read: (telemetry: ITelemetryConsumer) => Promise<T>, deps: DependencyList, refreshMs?: number): ITelemetryRead<T>;
28
+ /** One of the signed-in user's devices, as the device picker lists it. */
29
+ export interface IMyDevice {
30
+ deviceId: string;
31
+ /** Its name; empty when this device has none yet. */
32
+ name: string;
33
+ isThisDevice: boolean;
34
+ }
35
+ /**
36
+ * The signed-in user's devices: this one first, then the others by name. `undefined` until
37
+ * they're read. Whether one can be reached shows when Monitoring reads it.
38
+ */
39
+ export declare function useMyDevices(): IMyDevice[] | undefined;