@peers-app/peers-ui 0.34.10 → 0.34.12

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 (36) hide show
  1. package/dist/components/markdown-editor/link-plugin.d.ts +9 -5
  2. package/dist/components/markdown-editor/link-plugin.js +47 -22
  3. package/dist/components/markdown-render.js +21 -8
  4. package/dist/components/markdown-with-mentions.d.ts +6 -4
  5. package/dist/components/markdown-with-mentions.js +6 -4
  6. package/dist/host-shell/host-shell-consumer.d.ts +13 -5
  7. package/dist/host-shell/host-shell-consumer.js +31 -16
  8. package/dist/isolated-screens/frame-runtime.js +14 -15
  9. package/dist/links/app-link-prompt.d.ts +29 -0
  10. package/dist/links/app-link-prompt.js +102 -0
  11. package/dist/links/link-schemes.d.ts +30 -0
  12. package/dist/links/link-schemes.js +46 -0
  13. package/dist/links/peers-links.d.ts +33 -0
  14. package/dist/links/peers-links.js +124 -0
  15. package/dist/mentions/mention-chooser.d.ts +12 -0
  16. package/dist/mentions/mention-chooser.js +48 -13
  17. package/dist/root-layout/root-layout-host.js +10 -1
  18. package/dist/screens/invites/accept-invite.js +3 -4
  19. package/dist/screens/invites/invite-capture.d.ts +2 -7
  20. package/dist/screens/invites/invite-capture.js +8 -25
  21. package/dist/screens/monitoring/device-picker.d.ts +9 -8
  22. package/dist/screens/monitoring/device-picker.js +5 -4
  23. package/dist/screens/monitoring/devices-tab.d.ts +6 -0
  24. package/dist/screens/monitoring/devices-tab.js +74 -0
  25. package/dist/screens/monitoring/monitored-devices.d.ts +84 -0
  26. package/dist/screens/monitoring/monitored-devices.js +193 -0
  27. package/dist/screens/monitoring/monitoring-routes.d.ts +1 -1
  28. package/dist/screens/monitoring/monitoring-routes.js +1 -0
  29. package/dist/screens/monitoring/monitoring-screen.d.ts +4 -3
  30. package/dist/screens/monitoring/monitoring-screen.js +15 -7
  31. package/dist/screens/monitoring/overview-tab.d.ts +18 -0
  32. package/dist/screens/monitoring/overview-tab.js +19 -4
  33. package/dist/screens/monitoring/use-telemetry.d.ts +8 -10
  34. package/dist/screens/monitoring/use-telemetry.js +26 -27
  35. package/dist/screens/settings/settings-page.js +3 -1
  36. package/package.json +3 -3
@@ -0,0 +1,84 @@
1
+ import { type IDevice } from "@peers-app/peers-sdk";
2
+ /** A device Monitoring can read: one of the user's own, or another user's that lets them. */
3
+ export interface IMonitoredDevice {
4
+ deviceId: string;
5
+ /**
6
+ * What Monitoring calls it: the device's name, or for another user's device
7
+ * "<their name> · <device name>". Empty for this device when it has no name yet.
8
+ */
9
+ name: string;
10
+ isThisDevice: boolean;
11
+ /** Another user's device, which answered this user's System Telemetry call. */
12
+ isOthers?: boolean;
13
+ /** When one of the user's own devices last connected to this one. */
14
+ lastSeen?: Date;
15
+ }
16
+ /** Another user's device that's connected now and lets this user read its telemetry. */
17
+ export interface IReadableDevice {
18
+ deviceId: string;
19
+ userId: string;
20
+ /** Its user's name, as this device knows them. */
21
+ userName?: string;
22
+ /** The name the device reports. */
23
+ deviceName?: string;
24
+ }
25
+ /** A device's own name: the one given here, or else the one it reports. */
26
+ export declare function ownDeviceName(device: Pick<IDevice, "name" | "reportedName">): string;
27
+ /**
28
+ * Another user's device as Monitoring names it: "Blair · Laptop", or just "Kitchen" when the
29
+ * device is named after its user or has no name of its own.
30
+ *
31
+ * @param device - The device, with its user's name and its own.
32
+ */
33
+ export declare function othersDeviceLabel(device: Pick<IReadableDevice, "deviceId" | "userName" | "deviceName">): string;
34
+ /**
35
+ * The devices Monitoring lists: this one first, then the user's others by name, then other
36
+ * users' devices that let them read their telemetry, by name.
37
+ *
38
+ * @param input.thisDeviceId - This device's id.
39
+ * @param input.userId - The signed-in user.
40
+ * @param input.rows - The personal Devices table: the user's own devices, and names for others'.
41
+ * @param input.others - Other users' devices that answered.
42
+ */
43
+ export declare function buildMonitoredDevices(input: {
44
+ thisDeviceId: string | undefined;
45
+ userId: string;
46
+ rows: IDevice[];
47
+ others: IReadableDevice[];
48
+ }): IMonitoredDevice[];
49
+ /**
50
+ * A promise that rejects with "did not answer within …" when `promise` takes longer than `ms`.
51
+ * The wording reads as an unreachable device ({@link classifyTelemetryError}).
52
+ *
53
+ * @param promise - The call.
54
+ * @param ms - How long to wait.
55
+ */
56
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
57
+ /** How long an answer about another user's device is reused before it's asked again. */
58
+ export declare const PROBE_TTL_MS: number;
59
+ /**
60
+ * Whether another user's device lets this user read its telemetry: it answers System Telemetry's
61
+ * `status`, or says it runs a Peers version without it, which it only says once the call is
62
+ * allowed. A yes or no is kept for {@link PROBE_TTL_MS}, and calls made meanwhile share it; a
63
+ * device that didn't answer is asked again next time.
64
+ *
65
+ * @param deviceId - The device.
66
+ * @param fresh - Ask again, even if it answered recently.
67
+ */
68
+ export declare function canReadTelemetry(deviceId: string, fresh?: boolean): Promise<boolean>;
69
+ /** Forget every answer {@link canReadTelemetry} kept (for tests). */
70
+ export declare function resetTelemetryProbes(): void;
71
+ /**
72
+ * Other users' devices connected to this one that let this user read their telemetry. Only
73
+ * connected devices are asked, so a device that's offline, or reached only through the mesh, is
74
+ * left out until it connects. Empty when this device can't list its connections.
75
+ *
76
+ * Once `signal` is aborted, the pass stops waiting for the host link, lists no connections, and
77
+ * asks no device it hasn't asked yet. A question already on its way finishes, since another
78
+ * caller may be waiting on the same answer.
79
+ *
80
+ * @param userId - The signed-in user, whose own devices are left out.
81
+ * @param fresh - Ask every device again.
82
+ * @param signal - Ends the pass (Monitoring closed, or a newer pass started).
83
+ */
84
+ export declare function readableOthersDevices(userId: string, fresh?: boolean, signal?: AbortSignal): Promise<IReadableDevice[]>;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROBE_TTL_MS = void 0;
4
+ exports.ownDeviceName = ownDeviceName;
5
+ exports.othersDeviceLabel = othersDeviceLabel;
6
+ exports.buildMonitoredDevices = buildMonitoredDevices;
7
+ exports.withTimeout = withTimeout;
8
+ exports.canReadTelemetry = canReadTelemetry;
9
+ exports.resetTelemetryProbes = resetTelemetryProbes;
10
+ exports.readableOthersDevices = readableOthersDevices;
11
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
12
+ const telemetry_client_1 = require("./telemetry-client");
13
+ /** A device's own name: the one given here, or else the one it reports. */
14
+ function ownDeviceName(device) {
15
+ return device.name || device.reportedName || "";
16
+ }
17
+ /**
18
+ * Another user's device as Monitoring names it: "Blair · Laptop", or just "Kitchen" when the
19
+ * device is named after its user or has no name of its own.
20
+ *
21
+ * @param device - The device, with its user's name and its own.
22
+ */
23
+ function othersDeviceLabel(device) {
24
+ const user = device.userName?.trim();
25
+ const name = device.deviceName?.trim();
26
+ if (user && name && name.toLowerCase() !== user.toLowerCase())
27
+ return `${user} · ${name}`;
28
+ return user || name || device.deviceId;
29
+ }
30
+ /**
31
+ * The devices Monitoring lists: this one first, then the user's others by name, then other
32
+ * users' devices that let them read their telemetry, by name.
33
+ *
34
+ * @param input.thisDeviceId - This device's id.
35
+ * @param input.userId - The signed-in user.
36
+ * @param input.rows - The personal Devices table: the user's own devices, and names for others'.
37
+ * @param input.others - Other users' devices that answered.
38
+ */
39
+ function buildMonitoredDevices(input) {
40
+ const { thisDeviceId = "", userId, rows, others } = input;
41
+ const byName = (a, b) => a.name.localeCompare(b.name);
42
+ const mine = rows.filter((row) => row.userId === userId);
43
+ const thisRow = mine.find((row) => row.deviceId === thisDeviceId);
44
+ const own = mine
45
+ .filter((row) => row.deviceId !== thisDeviceId)
46
+ .map((row) => ({
47
+ deviceId: row.deviceId,
48
+ name: ownDeviceName(row) || row.deviceId,
49
+ isThisDevice: false,
50
+ lastSeen: row.lastSeen,
51
+ }))
52
+ .sort(byName);
53
+ const listed = new Set([thisDeviceId, ...own.map((device) => device.deviceId)]);
54
+ const known = new Map(rows.map((row) => [row.deviceId, row]));
55
+ const theirs = others
56
+ .filter((device) => device.userId !== userId && !listed.has(device.deviceId))
57
+ .map((device) => {
58
+ const row = known.get(device.deviceId);
59
+ return {
60
+ deviceId: device.deviceId,
61
+ name: othersDeviceLabel({
62
+ ...device,
63
+ deviceName: device.deviceName || (row ? ownDeviceName(row) : undefined),
64
+ }),
65
+ isThisDevice: false,
66
+ isOthers: true,
67
+ };
68
+ })
69
+ .sort(byName);
70
+ return [
71
+ { deviceId: thisDeviceId, name: thisRow ? ownDeviceName(thisRow) : "", isThisDevice: true },
72
+ ...own,
73
+ ...theirs,
74
+ ];
75
+ }
76
+ /**
77
+ * A promise that rejects with "did not answer within …" when `promise` takes longer than `ms`.
78
+ * The wording reads as an unreachable device ({@link classifyTelemetryError}).
79
+ *
80
+ * @param promise - The call.
81
+ * @param ms - How long to wait.
82
+ */
83
+ function withTimeout(promise, ms) {
84
+ let timer;
85
+ const timeout = new Promise((_, reject) => {
86
+ timer = setTimeout(() => reject(new Error(`did not answer within ${Math.round(ms / 1000)} seconds`)), ms);
87
+ });
88
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
89
+ }
90
+ /** How long an answer about another user's device is reused before it's asked again. */
91
+ exports.PROBE_TTL_MS = 10 * 60_000;
92
+ /** How long another user's device has to answer before it's left out this time. */
93
+ const PROBE_TIMEOUT_MS = 8_000;
94
+ const probes = new Map();
95
+ /**
96
+ * Whether another user's device lets this user read its telemetry: it answers System Telemetry's
97
+ * `status`, or says it runs a Peers version without it, which it only says once the call is
98
+ * allowed. A yes or no is kept for {@link PROBE_TTL_MS}, and calls made meanwhile share it; a
99
+ * device that didn't answer is asked again next time.
100
+ *
101
+ * @param deviceId - The device.
102
+ * @param fresh - Ask again, even if it answered recently.
103
+ */
104
+ async function canReadTelemetry(deviceId, fresh = false) {
105
+ const cached = probes.get(deviceId);
106
+ if (!fresh && cached && Date.now() - cached.at < exports.PROBE_TTL_MS) {
107
+ return (await cached.result) === "readable";
108
+ }
109
+ const entry = { at: Date.now(), result: probe(deviceId) };
110
+ probes.set(deviceId, entry);
111
+ const result = await entry.result;
112
+ if (result === "unknown" && probes.get(deviceId) === entry)
113
+ probes.delete(deviceId);
114
+ return result === "readable";
115
+ }
116
+ async function probe(deviceId) {
117
+ try {
118
+ await withTimeout((0, telemetry_client_1.getTelemetry)(deviceId).then((telemetry) => telemetry.tools.status({})), PROBE_TIMEOUT_MS);
119
+ return "readable";
120
+ }
121
+ catch (error) {
122
+ switch ((0, telemetry_client_1.classifyTelemetryError)(error)) {
123
+ case "unavailable":
124
+ return "readable";
125
+ case "denied":
126
+ return "denied";
127
+ default:
128
+ return "unknown";
129
+ }
130
+ }
131
+ }
132
+ /** Forget every answer {@link canReadTelemetry} kept (for tests). */
133
+ function resetTelemetryProbes() {
134
+ probes.clear();
135
+ }
136
+ /**
137
+ * Other users' devices connected to this one that let this user read their telemetry. Only
138
+ * connected devices are asked, so a device that's offline, or reached only through the mesh, is
139
+ * left out until it connects. Empty when this device can't list its connections.
140
+ *
141
+ * Once `signal` is aborted, the pass stops waiting for the host link, lists no connections, and
142
+ * asks no device it hasn't asked yet. A question already on its way finishes, since another
143
+ * caller may be waiting on the same answer.
144
+ *
145
+ * @param userId - The signed-in user, whose own devices are left out.
146
+ * @param fresh - Ask every device again.
147
+ * @param signal - Ends the pass (Monitoring closed, or a newer pass started).
148
+ */
149
+ async function readableOthersDevices(userId, fresh = false, signal) {
150
+ let connections;
151
+ try {
152
+ const transport = await (0, peers_sdk_1.waitForHostContractTransport)({ timeoutMs: 10_000, signal });
153
+ if (signal?.aborted)
154
+ return [];
155
+ connections = await listConnections(transport);
156
+ }
157
+ catch {
158
+ return [];
159
+ }
160
+ if (signal?.aborted)
161
+ return [];
162
+ const candidates = new Map();
163
+ for (const connection of connections) {
164
+ if (connection.userId === userId || candidates.has(connection.deviceId))
165
+ continue;
166
+ candidates.set(connection.deviceId, {
167
+ deviceId: connection.deviceId,
168
+ userId: connection.userId,
169
+ userName: connection.userName,
170
+ deviceName: connection.deviceName,
171
+ });
172
+ }
173
+ const answers = await Promise.all([...candidates.values()].map(async (device) => ({
174
+ device,
175
+ readable: await canReadTelemetry(device.deviceId, fresh),
176
+ })));
177
+ return answers.filter((answer) => answer.readable).map((answer) => answer.device);
178
+ }
179
+ /**
180
+ * This device's connections, asked through a consumer of Network Diagnostics' tools alone. The
181
+ * shared consumer (`getNetworkDiagnosticsConsumer`) also subscribes to the diagnostics `status`
182
+ * and reads it as it loads, which a closed Monitoring can't stop, and keeps that subscription
183
+ * until the host link changes. This one makes the single call, then lets go.
184
+ */
185
+ async function listConnections(transport) {
186
+ const diagnostics = (0, peers_sdk_1.createContractConsumer)({ ...(0, peers_sdk_1.getNetworkDiagnosticsContractDefinition)(), observables: [] }, transport);
187
+ try {
188
+ return (await diagnostics.tools.getConnections()).connections;
189
+ }
190
+ finally {
191
+ diagnostics.dispose();
192
+ }
193
+ }
@@ -9,7 +9,7 @@ export declare const MONITORING_APP_PATH = "monitoring";
9
9
  /** The path Console Logs had, rewritten to {@link MONITORING_LOGS_PATH}. */
10
10
  export declare const LEGACY_CONSOLE_LOGS_PATH = "console-logs";
11
11
  /** Monitoring's sections, in sidebar order. */
12
- export declare const MONITORING_SECTIONS: readonly ["overview", "metrics", "alerts", "definitions", "logs", "calls"];
12
+ export declare const MONITORING_SECTIONS: readonly ["overview", "devices", "metrics", "alerts", "definitions", "logs", "calls"];
13
13
  /** One of Monitoring's sections. */
14
14
  export type MonitoringSectionId = (typeof MONITORING_SECTIONS)[number];
15
15
  /** The Logs section's path, where `console-logs` lands. */
@@ -16,6 +16,7 @@ exports.LEGACY_CONSOLE_LOGS_PATH = "console-logs";
16
16
  /** Monitoring's sections, in sidebar order. */
17
17
  exports.MONITORING_SECTIONS = [
18
18
  "overview",
19
+ "devices",
19
20
  "metrics",
20
21
  "alerts",
21
22
  "definitions",
@@ -8,9 +8,10 @@ export interface MonitoringSectionProps {
8
8
  }) => void;
9
9
  }
10
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.
11
+ * Monitoring: a device's logs, metrics, calls and alerts, and the metric and trigger definitions
12
+ * behind them, for this device, the user's others, and other users' devices that let them read
13
+ * them. The device picker applies to every section but All devices, which lists them all, and
14
+ * the route keeps the device, so a link opens the same view.
14
15
  */
15
16
  export declare function MonitoringScreen(props: {
16
17
  path?: string;
@@ -10,6 +10,7 @@ const alerts_tab_1 = require("./alerts-tab");
10
10
  const calls_tab_1 = require("./calls-tab");
11
11
  const definitions_tab_1 = require("./definitions-tab");
12
12
  const device_picker_1 = require("./device-picker");
13
+ const devices_tab_1 = require("./devices-tab");
13
14
  const logs_tab_1 = require("./logs-tab");
14
15
  const metrics_tab_1 = require("./metrics-tab");
15
16
  const monitoring_routes_1 = require("./monitoring-routes");
@@ -17,6 +18,7 @@ const overview_tab_1 = require("./overview-tab");
17
18
  const use_telemetry_1 = require("./use-telemetry");
18
19
  const SECTIONS = [
19
20
  { id: "overview", label: "Overview", iconClassName: "bi-speedometer2" },
21
+ { id: "devices", label: "All devices", iconClassName: "bi-pc-display-horizontal" },
20
22
  { id: "metrics", label: "Metrics", iconClassName: "bi-graph-up" },
21
23
  { id: "alerts", label: "Alerts", iconClassName: "bi-bell" },
22
24
  { id: "definitions", label: "Definitions", iconClassName: "bi-sliders" },
@@ -24,9 +26,10 @@ const SECTIONS = [
24
26
  { id: "calls", label: "Calls", iconClassName: "bi-arrow-left-right" },
25
27
  ];
26
28
  /**
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.
29
+ * Monitoring: a device's logs, metrics, calls and alerts, and the metric and trigger definitions
30
+ * behind them, for this device, the user's others, and other users' devices that let them read
31
+ * them. The device picker applies to every section but All devices, which lists them all, and
32
+ * the route keeps the device, so a link opens the same view.
30
33
  */
31
34
  function MonitoringScreen(props) {
32
35
  const [livePath] = (0, hooks_1.useObservable)(globals_1.mainContentPath);
@@ -38,13 +41,18 @@ function MonitoringScreen(props) {
38
41
  (0, globals_1.mainContentPath)((0, monitoring_routes_1.monitoringPath)({ deviceId: location.deviceId, ...next }));
39
42
  };
40
43
  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") }));
44
+ 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 === "devices" ? (0, jsx_runtime_1.jsx)(devices_tab_1.DevicesTab, { ...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
45
  }
43
- /** The title and the device picker; it reads the user's devices only while Monitoring is shown. */
46
+ /** The title and, outside All devices, the device picker. */
44
47
  function Toolbar(props) {
45
48
  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 })) })] }));
49
+ 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" }), location.section === "devices" ? null : (0, jsx_runtime_1.jsx)(ToolbarPicker, { location: location })] }));
50
+ }
51
+ /** The device picker; it reads the devices only while it's shown. */
52
+ function ToolbarPicker(props) {
53
+ const { location } = props;
54
+ const devices = (0, use_telemetry_1.useMonitoredDevices)();
55
+ return ((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
56
  }
49
57
  (0, ui_loader_1.registerInternalPeersUI)({
50
58
  component: MonitoringScreen,
@@ -26,6 +26,24 @@ export interface IOverviewData {
26
26
  * @param now - The current time (for tests).
27
27
  */
28
28
  export declare function readOverview(telemetry: ITelemetryConsumer, now?: number): Promise<IOverviewData>;
29
+ /** The Overview's headline numbers, as its tiles and the All devices section show them. */
30
+ export interface IOverviewSummary {
31
+ /** Error lines in the last 24 hours; undefined when they couldn't be read. */
32
+ errors?: number;
33
+ /** Calls in the last 24 hours, and their p95 in ms. */
34
+ callCount?: number;
35
+ p95?: number;
36
+ /** Triggers firing or pending now (enabled ones); undefined when alerts couldn't be read. */
37
+ active?: IAlertState[];
38
+ /** The telemetry database's size on disk. */
39
+ databaseBytes?: number;
40
+ }
41
+ /**
42
+ * Work out the Overview's headline numbers from what {@link readOverview} read.
43
+ *
44
+ * @param data - The Overview's reads.
45
+ */
46
+ export declare function summarizeOverview(data: IOverviewData): IOverviewSummary;
29
47
  /**
30
48
  * Overview: errors, call latency, failed dials and the telemetry database's size over the last 24
31
49
  * hours, then what's firing and the latest alerts.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OVERVIEW_METRICS = void 0;
4
4
  exports.readOverview = readOverview;
5
+ exports.summarizeOverview = summarizeOverview;
5
6
  exports.OverviewTab = OverviewTab;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
8
  const peers_sdk_1 = require("@peers-app/peers-sdk");
@@ -59,6 +60,20 @@ async function readOverview(telemetry, now = Date.now()) {
59
60
  alerts: value(alerts),
60
61
  };
61
62
  }
63
+ /**
64
+ * Work out the Overview's headline numbers from what {@link readOverview} read.
65
+ *
66
+ * @param data - The Overview's reads.
67
+ */
68
+ function summarizeOverview(data) {
69
+ return {
70
+ errors: data.errors?.points.reduce((total, point) => total + point.count, 0),
71
+ callCount: data.calls ? (0, chart_math_1.sumOf)(data.calls.points.map((p) => p.count)) : undefined,
72
+ p95: data.calls?.histogram ? (0, chart_math_1.percentileFromBins)(data.calls.histogram, 0.95) : undefined,
73
+ active: data.alerts?.triggers.filter((t) => t.state !== "ok" && !t.disabled),
74
+ databaseBytes: data.status?.databaseBytes,
75
+ };
76
+ }
62
77
  /**
63
78
  * Overview: errors, call latency, failed dials and the telemetry database's size over the last 24
64
79
  * hours, then what's firing and the latest alerts.
@@ -75,10 +90,10 @@ function OverviewTab(props) {
75
90
  const errors = trendOf(data.errors, "count");
76
91
  const dials = trendOf(data.failedDials, "count");
77
92
  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
93
+ const summary = summarizeOverview(data);
94
+ const { callCount, p95 } = summary;
95
+ const active = summary.active ?? [];
96
+ 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: summary.errors === undefined ? "–" : (0, format_1.formatNumber)(summary.errors), 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)(summary.databaseBytes), caption: data.status
82
97
  ? `${(0, format_1.formatNumber)(data.status.logRows)} log lines · ${(0, format_1.formatNumber)(data.status.rollupRows)} metric rows`
83
98
  : "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
99
  }
@@ -1,5 +1,6 @@
1
1
  import { type ITelemetryConsumer } from "@peers-app/peers-sdk";
2
2
  import { type DependencyList } from "react";
3
+ import { type IMonitoredDevice } from "./monitored-devices";
3
4
  /** A telemetry read's state. */
4
5
  export interface ITelemetryRead<T> {
5
6
  /** The latest result; kept while a refresh runs, cleared on failure or when the device changes. */
@@ -25,15 +26,12 @@ export interface ITelemetryRead<T> {
25
26
  * @param refreshMs - Read again this often; omit to read only on change.
26
27
  */
27
28
  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
29
  /**
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.
30
+ * The devices Monitoring lists ({@link buildMonitoredDevices}): this one first, the user's others
31
+ * by name, then other users' connected devices that let them read their telemetry. `undefined`
32
+ * until the user's own are read; others' join the list once they've answered. Whether one of the
33
+ * user's own can be reached shows when Monitoring reads it.
34
+ *
35
+ * @param round - Ask other users' devices again whenever this changes (after the first).
38
36
  */
39
- export declare function useMyDevices(): IMyDevice[] | undefined;
37
+ export declare function useMonitoredDevices(round?: number): IMonitoredDevice[] | undefined;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTelemetryRead = useTelemetryRead;
4
- exports.useMyDevices = useMyDevices;
4
+ exports.useMonitoredDevices = useMonitoredDevices;
5
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
6
6
  const react_1 = require("react");
7
7
  const hooks_1 = require("../../hooks");
8
- const devices_list_1 = require("../devices/devices-list");
8
+ const monitored_devices_1 = require("./monitored-devices");
9
9
  const telemetry_client_1 = require("./telemetry-client");
10
10
  /**
11
11
  * Read from a device's System Telemetry, again whenever `deps` change and, while the page is
@@ -73,22 +73,27 @@ function useTelemetryRead(deviceId, read, deps, refreshMs) {
73
73
  };
74
74
  }
75
75
  /**
76
- * The signed-in user's devices: this one first, then the others by name. `undefined` until
77
- * they're read. Whether one can be reached shows when Monitoring reads it.
76
+ * The devices Monitoring lists ({@link buildMonitoredDevices}): this one first, the user's others
77
+ * by name, then other users' connected devices that let them read their telemetry. `undefined`
78
+ * until the user's own are read; others' join the list once they've answered. Whether one of the
79
+ * user's own can be reached shows when Monitoring reads it.
80
+ *
81
+ * @param round - Ask other users' devices again whenever this changes (after the first).
78
82
  */
79
- function useMyDevices() {
83
+ function useMonitoredDevices(round = 0) {
80
84
  const userContext = (0, hooks_1.usePromise)(peers_sdk_1.getUserContext);
81
85
  const [thisId] = (0, hooks_1.useObservable)(peers_sdk_1.thisDeviceId);
82
- const [devices, setDevices] = (0, react_1.useState)();
86
+ const [rows, setRows] = (0, react_1.useState)();
87
+ const [others, setOthers] = (0, react_1.useState)([]);
83
88
  (0, react_1.useEffect)(() => {
84
89
  if (!userContext)
85
90
  return;
86
91
  let disposed = false;
87
92
  const table = (0, peers_sdk_1.Devices)(userContext.userDataContext);
88
93
  const load = async () => {
89
- const rows = await table.list();
94
+ const list = await table.list();
90
95
  if (!disposed)
91
- setDevices((0, devices_list_1.devicesForUser)(rows, userContext.userId));
96
+ setRows(list);
92
97
  };
93
98
  void load();
94
99
  const subscription = table.dataChanged.subscribe(() => void load());
@@ -97,24 +102,18 @@ function useMyDevices() {
97
102
  subscription.unsubscribe();
98
103
  };
99
104
  }, [userContext]);
100
- if (!devices)
101
- return undefined;
102
- const mine = devices.find((d) => d.deviceId === thisId);
103
- const others = devices
104
- .filter((d) => d.deviceId !== thisId)
105
- .sort((a, b) => (a.name ?? "").localeCompare(b.name ?? ""));
106
- const list = [];
107
- list.push({
108
- deviceId: thisId ?? "",
109
- name: mine?.name ?? "",
110
- isThisDevice: true,
111
- });
112
- for (const device of others) {
113
- list.push({
114
- deviceId: device.deviceId,
115
- name: device.name || device.deviceId,
116
- isThisDevice: false,
105
+ (0, react_1.useEffect)(() => {
106
+ if (!userContext)
107
+ return;
108
+ // Leaving Monitoring, or a new round, ends this pass: it asks no device it hasn't asked yet.
109
+ const pass = new AbortController();
110
+ void (0, monitored_devices_1.readableOthersDevices)(userContext.userId, round > 0, pass.signal).then((list) => {
111
+ if (!pass.signal.aborted)
112
+ setOthers(list);
117
113
  });
118
- }
119
- return list;
114
+ return () => pass.abort();
115
+ }, [userContext, round]);
116
+ return (0, react_1.useMemo)(() => userContext && rows
117
+ ? (0, monitored_devices_1.buildMonitoredDevices)({ thisDeviceId: thisId, userId: userContext.userId, rows, others })
118
+ : undefined, [userContext, rows, others, thisId]);
120
119
  }
@@ -43,6 +43,7 @@ const tabs_1 = require("../../components/tabs");
43
43
  const tooltip_1 = require("../../components/tooltip");
44
44
  const globals = __importStar(require("../../globals"));
45
45
  const hooks_1 = require("../../hooks");
46
+ const app_link_prompt_1 = require("../../links/app-link-prompt");
46
47
  const layout_picker_1 = require("../../root-layout/layout-picker");
47
48
  const identity_ipc_1 = require("../device-pairing/identity-ipc");
48
49
  const context_files_1 = require("../files/context-files");
@@ -73,6 +74,7 @@ const SettingsPage = () => {
73
74
  },
74
75
  {
75
76
  name: "Advanced",
77
+ lazy: true,
76
78
  content: (0, jsx_runtime_1.jsx)(AdvancedSettingsTab, {}),
77
79
  },
78
80
  {
@@ -93,7 +95,7 @@ const AppearanceSettingsTab = () => {
93
95
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Appearance" }), (0, jsx_runtime_1.jsx)("div", { className: "mb-3", children: (0, jsx_runtime_1.jsx)(color_mode_dropdown_1.ColorModeDropdown, {}) }), (0, jsx_runtime_1.jsx)("div", { className: "mb-3", children: (0, jsx_runtime_1.jsx)(layout_picker_1.LayoutPicker, {}) })] }));
94
96
  };
95
97
  const AdvancedSettingsTab = () => {
96
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Advanced Settings" }), (0, jsx_runtime_1.jsx)(PackagesRootDirectory, {}), (0, jsx_runtime_1.jsx)(ReloadPackagesOnPageRefresh, {}), (0, jsx_runtime_1.jsx)(ResetDeviceSyncInfos, {}), (0, jsx_runtime_1.jsx)(DeleteLocalDatabase, {}), (0, jsx_runtime_1.jsx)(CleanupOldDataDir, {}), (0, jsx_runtime_1.jsx)(ResetChangeTracking, {})] }));
98
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Advanced Settings" }), (0, jsx_runtime_1.jsx)(app_link_prompt_1.AlwaysOpenLinksSetting, {}), (0, jsx_runtime_1.jsx)(PackagesRootDirectory, {}), (0, jsx_runtime_1.jsx)(ReloadPackagesOnPageRefresh, {}), (0, jsx_runtime_1.jsx)(ResetDeviceSyncInfos, {}), (0, jsx_runtime_1.jsx)(DeleteLocalDatabase, {}), (0, jsx_runtime_1.jsx)(CleanupOldDataDir, {}), (0, jsx_runtime_1.jsx)(ResetChangeTracking, {})] }));
97
99
  };
98
100
  const ProfileSection = () => {
99
101
  const me = (0, hooks_1.usePromise)(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.34.10",
3
+ "version": "0.34.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-ui.git"
@@ -36,7 +36,7 @@
36
36
  "lint:fix": "biome check --write ."
37
37
  },
38
38
  "peerDependencies": {
39
- "@peers-app/peers-sdk": "^0.34.10",
39
+ "@peers-app/peers-sdk": "^0.34.12",
40
40
  "bootstrap": "^5.3.3",
41
41
  "react": "^18.0.0",
42
42
  "react-dom": "^18.0.0"
@@ -47,7 +47,7 @@
47
47
  "@babel/preset-react": "^7.24.1",
48
48
  "@babel/preset-typescript": "^7.27.1",
49
49
  "@biomejs/biome": "2.3.11",
50
- "@peers-app/peers-sdk": "0.34.10",
50
+ "@peers-app/peers-sdk": "0.34.12",
51
51
  "@testing-library/dom": "^10.4.0",
52
52
  "@testing-library/jest-dom": "^6.6.3",
53
53
  "@testing-library/react": "^16.3.0",