@peers-app/peers-ui 0.34.9 → 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.
- package/dist/apps-home/apps-home.js +6 -4
- package/dist/components/router.d.ts +1 -1
- package/dist/components/router.js +1 -1
- package/dist/screens/identity/identity-routes.d.ts +2 -1
- package/dist/screens/identity/identity-routes.js +6 -1
- package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
- package/dist/screens/monitoring/alerts-tab.js +68 -0
- package/dist/screens/monitoring/badges.d.ts +25 -0
- package/dist/screens/monitoring/badges.js +68 -0
- package/dist/screens/monitoring/calls-tab.d.ts +30 -0
- package/dist/screens/monitoring/calls-tab.js +104 -0
- package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
- package/dist/screens/monitoring/charts/chart-math.js +200 -0
- package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
- package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
- package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
- package/dist/screens/monitoring/charts/line-chart.js +103 -0
- package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
- package/dist/screens/monitoring/charts/sparkline.js +61 -0
- package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
- package/dist/screens/monitoring/charts/use-width.js +31 -0
- package/dist/screens/monitoring/definition-forms.d.ts +113 -0
- package/dist/screens/monitoring/definition-forms.js +341 -0
- package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
- package/dist/screens/monitoring/definitions-tab.js +110 -0
- package/dist/screens/monitoring/device-picker.d.ts +22 -0
- package/dist/screens/monitoring/device-picker.js +29 -0
- package/dist/screens/monitoring/form-fields.d.ts +76 -0
- package/dist/screens/monitoring/form-fields.js +65 -0
- package/dist/screens/monitoring/format.d.ts +51 -0
- package/dist/screens/monitoring/format.js +150 -0
- package/dist/screens/monitoring/log-lines.d.ts +74 -0
- package/dist/screens/monitoring/log-lines.js +138 -0
- package/dist/screens/monitoring/log-row.d.ts +12 -0
- package/dist/screens/monitoring/log-row.js +23 -0
- package/dist/screens/monitoring/logs-tab.d.ts +15 -0
- package/dist/screens/monitoring/logs-tab.js +256 -0
- package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
- package/dist/screens/monitoring/metric-definition-form.js +50 -0
- package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
- package/dist/screens/monitoring/metrics-tab.js +149 -0
- package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
- package/dist/screens/monitoring/monitoring-routes.js +81 -0
- package/dist/screens/monitoring/monitoring-screen.d.ts +17 -0
- package/dist/screens/monitoring/monitoring-screen.js +63 -0
- package/dist/screens/monitoring/overview-tab.d.ts +33 -0
- package/dist/screens/monitoring/overview-tab.js +121 -0
- package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
- package/dist/screens/monitoring/telemetry-client.js +92 -0
- package/dist/screens/monitoring/trigger-form.d.ts +18 -0
- package/dist/screens/monitoring/trigger-form.js +71 -0
- package/dist/screens/monitoring/use-telemetry.d.ts +39 -0
- package/dist/screens/monitoring/use-telemetry.js +120 -0
- package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
- package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
- package/dist/system-apps/index.d.ts +1 -1
- package/dist/system-apps/index.js +5 -5
- package/dist/system-apps/monitoring.app.d.ts +6 -0
- package/dist/system-apps/monitoring.app.js +13 -0
- package/dist/tabs-layout/tabs-state.d.ts +4 -2
- package/dist/tabs-layout/tabs-state.js +23 -11
- package/dist/theme.css +32 -0
- package/package.json +3 -3
- package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
- package/dist/screens/console-logs/console-logs-list.js +0 -284
- package/dist/screens/console-logs/follow-newest.d.ts +0 -11
- package/dist/screens/console-logs/follow-newest.js +0 -17
- package/dist/screens/console-logs/log-display.d.ts +0 -12
- package/dist/screens/console-logs/log-display.js +0 -69
- package/dist/screens/console-logs/log-filters.d.ts +0 -10
- package/dist/screens/console-logs/log-filters.js +0 -8
- package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
- package/dist/screens/console-logs/mobile-log-card.js +0 -94
- package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
- package/dist/screens/console-logs/resizable-table-header.js +0 -62
- package/dist/system-apps/console-logs.app.d.ts +0 -2
- package/dist/system-apps/console-logs.app.js +0 -8
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { IMetricDefinition, ITriggerDefinition, LogLevel, MetricKind, MetricStat, TelemetryScalar } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The metric and trigger forms' fields as the inputs hold them (text), and the conversions to and
|
|
4
|
+
* from definitions. The forms check only what they must to build a definition; System Telemetry
|
|
5
|
+
* checks the rest when it saves, and its words are what the person sees.
|
|
6
|
+
*/
|
|
7
|
+
/** A metric definition's form fields. */
|
|
8
|
+
export interface IMetricForm {
|
|
9
|
+
metricId: string;
|
|
10
|
+
description: string;
|
|
11
|
+
unit: string;
|
|
12
|
+
kind: MetricKind;
|
|
13
|
+
event: string;
|
|
14
|
+
levels: LogLevel[];
|
|
15
|
+
source: string;
|
|
16
|
+
packageId: string;
|
|
17
|
+
process: string;
|
|
18
|
+
/** One `path = value` per line. */
|
|
19
|
+
where: string;
|
|
20
|
+
/** Paths, separated by commas. */
|
|
21
|
+
has: string;
|
|
22
|
+
messagePrefix: string;
|
|
23
|
+
messageContains: string;
|
|
24
|
+
messagePattern: string;
|
|
25
|
+
messageFlags: string;
|
|
26
|
+
value: string;
|
|
27
|
+
/** Up to four paths, separated by commas. */
|
|
28
|
+
labels: string;
|
|
29
|
+
disabled: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A trigger's form fields. */
|
|
32
|
+
export interface ITriggerForm {
|
|
33
|
+
triggerId: string;
|
|
34
|
+
description: string;
|
|
35
|
+
metricId: string;
|
|
36
|
+
/** One `label = value` per line. */
|
|
37
|
+
where: string;
|
|
38
|
+
stat: MetricStat | "ratio";
|
|
39
|
+
ratioWhere: string;
|
|
40
|
+
windowMinutes: string;
|
|
41
|
+
op: ITriggerDefinition["op"];
|
|
42
|
+
threshold: string;
|
|
43
|
+
minCount: string;
|
|
44
|
+
forMinutes: string;
|
|
45
|
+
notify: boolean;
|
|
46
|
+
notifyTitle: string;
|
|
47
|
+
notifyBody: string;
|
|
48
|
+
notifyLevel: "priority" | "loud" | "quiet";
|
|
49
|
+
tool: boolean;
|
|
50
|
+
toolContractId: string;
|
|
51
|
+
toolVersion: string;
|
|
52
|
+
toolName: string;
|
|
53
|
+
/** The tool's arguments, as JSON. */
|
|
54
|
+
toolArgs: string;
|
|
55
|
+
toolProviderPackageId: string;
|
|
56
|
+
disabled: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** A conversion's result: the definition, or why the form can't make one. */
|
|
59
|
+
export type FormResult<T> = {
|
|
60
|
+
definition: T;
|
|
61
|
+
error?: undefined;
|
|
62
|
+
} | {
|
|
63
|
+
definition?: undefined;
|
|
64
|
+
error: string;
|
|
65
|
+
};
|
|
66
|
+
/** An empty metric form, for a new definition. */
|
|
67
|
+
export declare function emptyMetricForm(): IMetricForm;
|
|
68
|
+
/** An empty trigger form, for a new trigger. */
|
|
69
|
+
export declare function emptyTriggerForm(metricId?: string): ITriggerForm;
|
|
70
|
+
/**
|
|
71
|
+
* Read `path = value` lines. A value that reads as a number, `true`, `false` or `null` becomes
|
|
72
|
+
* one; quote it (`"42"`) to keep it text.
|
|
73
|
+
*
|
|
74
|
+
* @param text - The lines.
|
|
75
|
+
* @param scalars - Turn numbers and the like into values (metric `where`); otherwise keep text.
|
|
76
|
+
* @returns The pairs, or the line that isn't a pair.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parsePairs(text: string, scalars: boolean): {
|
|
79
|
+
pairs: Record<string, TelemetryScalar>;
|
|
80
|
+
} | {
|
|
81
|
+
error: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Write pairs as `path = value` lines, quoting text that would otherwise read as a number or the
|
|
85
|
+
* like.
|
|
86
|
+
*
|
|
87
|
+
* @param pairs - The pairs, if any.
|
|
88
|
+
*/
|
|
89
|
+
export declare function formatPairs(pairs: Record<string, TelemetryScalar> | undefined): string;
|
|
90
|
+
/**
|
|
91
|
+
* Build a metric definition from its form.
|
|
92
|
+
*
|
|
93
|
+
* @param form - The form's fields.
|
|
94
|
+
*/
|
|
95
|
+
export declare function toMetricDefinition(form: IMetricForm): FormResult<IMetricDefinition>;
|
|
96
|
+
/**
|
|
97
|
+
* A metric definition's form, to edit it.
|
|
98
|
+
*
|
|
99
|
+
* @param definition - The saved definition.
|
|
100
|
+
*/
|
|
101
|
+
export declare function metricDefinitionToForm(definition: IMetricDefinition): IMetricForm;
|
|
102
|
+
/**
|
|
103
|
+
* Build a trigger from its form.
|
|
104
|
+
*
|
|
105
|
+
* @param form - The form's fields.
|
|
106
|
+
*/
|
|
107
|
+
export declare function toTriggerDefinition(form: ITriggerForm): FormResult<ITriggerDefinition>;
|
|
108
|
+
/**
|
|
109
|
+
* A trigger's form, to edit it.
|
|
110
|
+
*
|
|
111
|
+
* @param definition - The saved trigger.
|
|
112
|
+
*/
|
|
113
|
+
export declare function triggerDefinitionToForm(definition: ITriggerDefinition): ITriggerForm;
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emptyMetricForm = emptyMetricForm;
|
|
4
|
+
exports.emptyTriggerForm = emptyTriggerForm;
|
|
5
|
+
exports.parsePairs = parsePairs;
|
|
6
|
+
exports.formatPairs = formatPairs;
|
|
7
|
+
exports.toMetricDefinition = toMetricDefinition;
|
|
8
|
+
exports.metricDefinitionToForm = metricDefinitionToForm;
|
|
9
|
+
exports.toTriggerDefinition = toTriggerDefinition;
|
|
10
|
+
exports.triggerDefinitionToForm = triggerDefinitionToForm;
|
|
11
|
+
/** An empty metric form, for a new definition. */
|
|
12
|
+
function emptyMetricForm() {
|
|
13
|
+
return {
|
|
14
|
+
metricId: "",
|
|
15
|
+
description: "",
|
|
16
|
+
unit: "",
|
|
17
|
+
kind: "count",
|
|
18
|
+
event: "",
|
|
19
|
+
levels: [],
|
|
20
|
+
source: "",
|
|
21
|
+
packageId: "",
|
|
22
|
+
process: "",
|
|
23
|
+
where: "",
|
|
24
|
+
has: "",
|
|
25
|
+
messagePrefix: "",
|
|
26
|
+
messageContains: "",
|
|
27
|
+
messagePattern: "",
|
|
28
|
+
messageFlags: "",
|
|
29
|
+
value: "",
|
|
30
|
+
labels: "",
|
|
31
|
+
disabled: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** An empty trigger form, for a new trigger. */
|
|
35
|
+
function emptyTriggerForm(metricId = "") {
|
|
36
|
+
return {
|
|
37
|
+
triggerId: "",
|
|
38
|
+
description: "",
|
|
39
|
+
metricId,
|
|
40
|
+
where: "",
|
|
41
|
+
stat: "count",
|
|
42
|
+
ratioWhere: "",
|
|
43
|
+
windowMinutes: "5",
|
|
44
|
+
op: ">",
|
|
45
|
+
threshold: "",
|
|
46
|
+
minCount: "",
|
|
47
|
+
forMinutes: "1",
|
|
48
|
+
notify: true,
|
|
49
|
+
notifyTitle: "",
|
|
50
|
+
notifyBody: "",
|
|
51
|
+
notifyLevel: "priority",
|
|
52
|
+
tool: false,
|
|
53
|
+
toolContractId: "",
|
|
54
|
+
toolVersion: "1",
|
|
55
|
+
toolName: "",
|
|
56
|
+
toolArgs: "",
|
|
57
|
+
toolProviderPackageId: "",
|
|
58
|
+
disabled: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Read `path = value` lines. A value that reads as a number, `true`, `false` or `null` becomes
|
|
63
|
+
* one; quote it (`"42"`) to keep it text.
|
|
64
|
+
*
|
|
65
|
+
* @param text - The lines.
|
|
66
|
+
* @param scalars - Turn numbers and the like into values (metric `where`); otherwise keep text.
|
|
67
|
+
* @returns The pairs, or the line that isn't a pair.
|
|
68
|
+
*/
|
|
69
|
+
function parsePairs(text, scalars) {
|
|
70
|
+
const pairs = Object.create(null);
|
|
71
|
+
for (const raw of text.split("\n")) {
|
|
72
|
+
const line = raw.trim();
|
|
73
|
+
if (!line)
|
|
74
|
+
continue;
|
|
75
|
+
const at = line.indexOf("=");
|
|
76
|
+
if (at <= 0)
|
|
77
|
+
return { error: `"${line}" isn't a "name = value" pair` };
|
|
78
|
+
const name = line.slice(0, at).trim();
|
|
79
|
+
const value = line.slice(at + 1).trim();
|
|
80
|
+
pairs[name] = scalars ? toScalar(value) : unquote(value);
|
|
81
|
+
}
|
|
82
|
+
return { pairs };
|
|
83
|
+
}
|
|
84
|
+
function unquote(value) {
|
|
85
|
+
return /^".*"$/.test(value) ? value.slice(1, -1) : value;
|
|
86
|
+
}
|
|
87
|
+
function toScalar(value) {
|
|
88
|
+
if (/^".*"$/.test(value))
|
|
89
|
+
return value.slice(1, -1);
|
|
90
|
+
if (value === "true")
|
|
91
|
+
return true;
|
|
92
|
+
if (value === "false")
|
|
93
|
+
return false;
|
|
94
|
+
if (value === "null")
|
|
95
|
+
return null;
|
|
96
|
+
if (value !== "" && Number.isFinite(Number(value)))
|
|
97
|
+
return Number(value);
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Write pairs as `path = value` lines, quoting text that would otherwise read as a number or the
|
|
102
|
+
* like.
|
|
103
|
+
*
|
|
104
|
+
* @param pairs - The pairs, if any.
|
|
105
|
+
*/
|
|
106
|
+
function formatPairs(pairs) {
|
|
107
|
+
if (!pairs)
|
|
108
|
+
return "";
|
|
109
|
+
return Object.entries(pairs)
|
|
110
|
+
.map(([name, value]) => {
|
|
111
|
+
const text = typeof value === "string" && (value.trim() !== value || toScalar(value) !== value)
|
|
112
|
+
? `"${value}"`
|
|
113
|
+
: String(value);
|
|
114
|
+
return `${name} = ${text}`;
|
|
115
|
+
})
|
|
116
|
+
.join("\n");
|
|
117
|
+
}
|
|
118
|
+
function list(text) {
|
|
119
|
+
return text
|
|
120
|
+
.split(",")
|
|
121
|
+
.map((part) => part.trim())
|
|
122
|
+
.filter(Boolean);
|
|
123
|
+
}
|
|
124
|
+
function optionalText(text) {
|
|
125
|
+
const trimmed = text.trim();
|
|
126
|
+
return trimmed ? trimmed : undefined;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build a metric definition from its form.
|
|
130
|
+
*
|
|
131
|
+
* @param form - The form's fields.
|
|
132
|
+
*/
|
|
133
|
+
function toMetricDefinition(form) {
|
|
134
|
+
const where = parsePairs(form.where, true);
|
|
135
|
+
if ("error" in where)
|
|
136
|
+
return { error: `Where: ${where.error}` };
|
|
137
|
+
const match = {};
|
|
138
|
+
const event = optionalText(form.event);
|
|
139
|
+
if (event)
|
|
140
|
+
match.event = event;
|
|
141
|
+
if (form.levels.length)
|
|
142
|
+
match.levels = [...form.levels];
|
|
143
|
+
const source = optionalText(form.source);
|
|
144
|
+
if (source)
|
|
145
|
+
match.source = source;
|
|
146
|
+
const packageId = optionalText(form.packageId);
|
|
147
|
+
if (packageId)
|
|
148
|
+
match.packageId = packageId;
|
|
149
|
+
const process = optionalText(form.process);
|
|
150
|
+
if (process)
|
|
151
|
+
match.process = process;
|
|
152
|
+
if (Object.keys(where.pairs).length)
|
|
153
|
+
match.where = where.pairs;
|
|
154
|
+
const has = list(form.has);
|
|
155
|
+
if (has.length)
|
|
156
|
+
match.has = has;
|
|
157
|
+
const message = {};
|
|
158
|
+
if (form.messagePrefix)
|
|
159
|
+
message.prefix = form.messagePrefix;
|
|
160
|
+
if (form.messageContains)
|
|
161
|
+
message.contains = form.messageContains;
|
|
162
|
+
if (form.messagePattern)
|
|
163
|
+
message.pattern = form.messagePattern;
|
|
164
|
+
if (form.messageFlags.trim())
|
|
165
|
+
message.flags = form.messageFlags.trim();
|
|
166
|
+
if (Object.keys(message).length)
|
|
167
|
+
match.message = message;
|
|
168
|
+
const definition = {
|
|
169
|
+
metricId: form.metricId.trim(),
|
|
170
|
+
description: form.description.trim(),
|
|
171
|
+
kind: form.kind,
|
|
172
|
+
match,
|
|
173
|
+
};
|
|
174
|
+
const unit = optionalText(form.unit);
|
|
175
|
+
if (unit)
|
|
176
|
+
definition.unit = unit;
|
|
177
|
+
const value = optionalText(form.value);
|
|
178
|
+
if (value)
|
|
179
|
+
definition.value = value;
|
|
180
|
+
const labels = list(form.labels);
|
|
181
|
+
if (labels.length)
|
|
182
|
+
definition.labels = labels;
|
|
183
|
+
if (form.disabled)
|
|
184
|
+
definition.disabled = true;
|
|
185
|
+
return { definition };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A metric definition's form, to edit it.
|
|
189
|
+
*
|
|
190
|
+
* @param definition - The saved definition.
|
|
191
|
+
*/
|
|
192
|
+
function metricDefinitionToForm(definition) {
|
|
193
|
+
const match = definition.match ?? {};
|
|
194
|
+
return {
|
|
195
|
+
metricId: definition.metricId,
|
|
196
|
+
description: definition.description ?? "",
|
|
197
|
+
unit: definition.unit ?? "",
|
|
198
|
+
kind: definition.kind,
|
|
199
|
+
event: match.event ?? "",
|
|
200
|
+
levels: [...(match.levels ?? [])],
|
|
201
|
+
source: match.source ?? "",
|
|
202
|
+
packageId: match.packageId ?? "",
|
|
203
|
+
process: match.process ?? "",
|
|
204
|
+
where: formatPairs(match.where),
|
|
205
|
+
has: (match.has ?? []).join(", "),
|
|
206
|
+
messagePrefix: match.message?.prefix ?? "",
|
|
207
|
+
messageContains: match.message?.contains ?? "",
|
|
208
|
+
messagePattern: match.message?.pattern ?? "",
|
|
209
|
+
messageFlags: match.message?.flags ?? "",
|
|
210
|
+
value: definition.value ?? "",
|
|
211
|
+
labels: (definition.labels ?? []).join(", "),
|
|
212
|
+
disabled: !!definition.disabled,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function numberField(text, name, optional) {
|
|
216
|
+
const trimmed = text.trim();
|
|
217
|
+
if (!trimmed)
|
|
218
|
+
return optional ? undefined : { error: `${name} needs a number` };
|
|
219
|
+
const value = Number(trimmed);
|
|
220
|
+
return Number.isFinite(value) ? value : { error: `${name} isn't a number: "${trimmed}"` };
|
|
221
|
+
}
|
|
222
|
+
function isError(value) {
|
|
223
|
+
return typeof value === "object" && value !== null && "error" in value;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Build a trigger from its form.
|
|
227
|
+
*
|
|
228
|
+
* @param form - The form's fields.
|
|
229
|
+
*/
|
|
230
|
+
function toTriggerDefinition(form) {
|
|
231
|
+
const where = parsePairs(form.where, false);
|
|
232
|
+
if ("error" in where)
|
|
233
|
+
return { error: `Series: ${where.error}` };
|
|
234
|
+
const ratioWhere = parsePairs(form.stat === "ratio" ? form.ratioWhere : "", false);
|
|
235
|
+
if ("error" in ratioWhere)
|
|
236
|
+
return { error: `Counted as failing: ${ratioWhere.error}` };
|
|
237
|
+
const windowMinutes = numberField(form.windowMinutes, "Window", false);
|
|
238
|
+
if (isError(windowMinutes))
|
|
239
|
+
return windowMinutes;
|
|
240
|
+
const threshold = numberField(form.threshold, "Threshold", false);
|
|
241
|
+
if (isError(threshold))
|
|
242
|
+
return threshold;
|
|
243
|
+
const minCount = numberField(form.minCount, "Minimum count", true);
|
|
244
|
+
if (isError(minCount))
|
|
245
|
+
return minCount;
|
|
246
|
+
const forMinutes = numberField(form.forMinutes, "For", true);
|
|
247
|
+
if (isError(forMinutes))
|
|
248
|
+
return forMinutes;
|
|
249
|
+
const action = {};
|
|
250
|
+
if (form.notify) {
|
|
251
|
+
action.notify = { title: form.notifyTitle.trim(), level: form.notifyLevel };
|
|
252
|
+
const body = optionalText(form.notifyBody);
|
|
253
|
+
if (body)
|
|
254
|
+
action.notify.body = body;
|
|
255
|
+
}
|
|
256
|
+
if (form.tool) {
|
|
257
|
+
let args;
|
|
258
|
+
if (form.toolArgs.trim()) {
|
|
259
|
+
try {
|
|
260
|
+
args = JSON.parse(form.toolArgs);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
return { error: `Tool arguments aren't valid JSON: ${error.message}` };
|
|
264
|
+
}
|
|
265
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
266
|
+
return { error: "Tool arguments must be a JSON object" };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const version = numberField(form.toolVersion, "Tool contract version", false);
|
|
270
|
+
if (isError(version))
|
|
271
|
+
return version;
|
|
272
|
+
action.tool = {
|
|
273
|
+
contractId: form.toolContractId.trim(),
|
|
274
|
+
version: version,
|
|
275
|
+
toolName: form.toolName.trim(),
|
|
276
|
+
};
|
|
277
|
+
if (args)
|
|
278
|
+
action.tool.args = args;
|
|
279
|
+
const provider = optionalText(form.toolProviderPackageId);
|
|
280
|
+
if (provider)
|
|
281
|
+
action.tool.providerPackageId = provider;
|
|
282
|
+
}
|
|
283
|
+
const definition = {
|
|
284
|
+
triggerId: form.triggerId.trim(),
|
|
285
|
+
description: form.description.trim(),
|
|
286
|
+
metricId: form.metricId.trim(),
|
|
287
|
+
stat: form.stat,
|
|
288
|
+
windowMinutes: windowMinutes,
|
|
289
|
+
op: form.op,
|
|
290
|
+
threshold: threshold,
|
|
291
|
+
action,
|
|
292
|
+
};
|
|
293
|
+
if (Object.keys(where.pairs).length)
|
|
294
|
+
definition.where = where.pairs;
|
|
295
|
+
if (form.stat === "ratio" && Object.keys(ratioWhere.pairs).length) {
|
|
296
|
+
definition.ratioWhere = ratioWhere.pairs;
|
|
297
|
+
}
|
|
298
|
+
if (minCount !== undefined)
|
|
299
|
+
definition.minCount = minCount;
|
|
300
|
+
if (forMinutes !== undefined)
|
|
301
|
+
definition.forMinutes = forMinutes;
|
|
302
|
+
if (form.disabled)
|
|
303
|
+
definition.disabled = true;
|
|
304
|
+
return { definition };
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* A trigger's form, to edit it.
|
|
308
|
+
*
|
|
309
|
+
* @param definition - The saved trigger.
|
|
310
|
+
*/
|
|
311
|
+
function triggerDefinitionToForm(definition) {
|
|
312
|
+
const empty = emptyTriggerForm(definition.metricId);
|
|
313
|
+
const notify = definition.action?.notify;
|
|
314
|
+
const tool = definition.action?.tool;
|
|
315
|
+
return {
|
|
316
|
+
...empty,
|
|
317
|
+
triggerId: definition.triggerId,
|
|
318
|
+
description: definition.description ?? "",
|
|
319
|
+
where: formatPairs(definition.where),
|
|
320
|
+
stat: definition.stat,
|
|
321
|
+
ratioWhere: formatPairs(definition.ratioWhere),
|
|
322
|
+
windowMinutes: String(definition.windowMinutes),
|
|
323
|
+
op: definition.op,
|
|
324
|
+
threshold: String(definition.threshold),
|
|
325
|
+
minCount: definition.minCount === undefined ? "" : String(definition.minCount),
|
|
326
|
+
forMinutes: definition.forMinutes === undefined ? "" : String(definition.forMinutes),
|
|
327
|
+
notify: !!notify,
|
|
328
|
+
notifyTitle: notify?.title ?? "",
|
|
329
|
+
notifyBody: notify?.body ?? "",
|
|
330
|
+
// A notification saved without a level notifies at "loud" (the device's default), so editing
|
|
331
|
+
// it mustn't turn it into "priority".
|
|
332
|
+
notifyLevel: notify ? (notify.level ?? "loud") : empty.notifyLevel,
|
|
333
|
+
tool: !!tool,
|
|
334
|
+
toolContractId: tool?.contractId ?? "",
|
|
335
|
+
toolVersion: tool ? String(tool.version) : "1",
|
|
336
|
+
toolName: tool?.toolName ?? "",
|
|
337
|
+
toolArgs: tool?.args ? JSON.stringify(tool.args, null, 2) : "",
|
|
338
|
+
toolProviderPackageId: tool?.providerPackageId ?? "",
|
|
339
|
+
disabled: !!definition.disabled,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IMetricDefinitionInfo, ITriggerDefinitionInfo } from "@peers-app/peers-sdk";
|
|
2
|
+
import type { MonitoringSectionProps } from "./monitoring-screen";
|
|
3
|
+
/**
|
|
4
|
+
* Definitions: every metric and trigger the device runs, Peers', packages' and the user's, with
|
|
5
|
+
* where each came from and why the device switched one off. The user's own can be created, edited
|
|
6
|
+
* and deleted here; they sync to all of the user's devices.
|
|
7
|
+
*/
|
|
8
|
+
export declare function DefinitionsTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* What lines a metric reads, briefly: its event, levels, source, data paths and text match.
|
|
11
|
+
*
|
|
12
|
+
* @param definition - The metric definition.
|
|
13
|
+
*/
|
|
14
|
+
export declare function describeMatch(definition: IMetricDefinitionInfo): string;
|
|
15
|
+
/**
|
|
16
|
+
* What a trigger does when it fires.
|
|
17
|
+
*
|
|
18
|
+
* @param definition - The trigger.
|
|
19
|
+
*/
|
|
20
|
+
export declare function describeAction(definition: ITriggerDefinitionInfo): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefinitionsTab = DefinitionsTab;
|
|
4
|
+
exports.describeMatch = describeMatch;
|
|
5
|
+
exports.describeAction = describeAction;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const alerts_tab_1 = require("./alerts-tab");
|
|
9
|
+
const badges_1 = require("./badges");
|
|
10
|
+
const metric_definition_form_1 = require("./metric-definition-form");
|
|
11
|
+
const telemetry_client_1 = require("./telemetry-client");
|
|
12
|
+
const trigger_form_1 = require("./trigger-form");
|
|
13
|
+
const use_telemetry_1 = require("./use-telemetry");
|
|
14
|
+
/**
|
|
15
|
+
* Definitions: every metric and trigger the device runs, Peers', packages' and the user's, with
|
|
16
|
+
* where each came from and why the device switched one off. The user's own can be created, edited
|
|
17
|
+
* and deleted here; they sync to all of the user's devices.
|
|
18
|
+
*/
|
|
19
|
+
function DefinitionsTab(props) {
|
|
20
|
+
const deviceId = props.location.deviceId;
|
|
21
|
+
const definitions = (0, use_telemetry_1.useTelemetryRead)(deviceId, (t) => t.tools.listDefinitions({}), []);
|
|
22
|
+
const metrics = (0, use_telemetry_1.useTelemetryRead)(deviceId, async (t) => (await t.tools.listMetrics({})).metrics, []);
|
|
23
|
+
const [editing, setEditing] = (0, react_1.useState)({ kind: "none" });
|
|
24
|
+
const [deleteError, setDeleteError] = (0, react_1.useState)();
|
|
25
|
+
const remove = async (kind, id) => {
|
|
26
|
+
if (!confirm(`Delete the ${kind} ${id}? It's deleted on all your devices.`))
|
|
27
|
+
return;
|
|
28
|
+
setDeleteError(undefined);
|
|
29
|
+
try {
|
|
30
|
+
const telemetry = await (0, telemetry_client_1.getTelemetry)();
|
|
31
|
+
if (kind === "metric")
|
|
32
|
+
await telemetry.tools.deleteMetricDefinition({ metricId: id });
|
|
33
|
+
else
|
|
34
|
+
await telemetry.tools.deleteTriggerDefinition({ triggerId: id });
|
|
35
|
+
definitions.refresh();
|
|
36
|
+
// The trigger form suggests metrics from this list.
|
|
37
|
+
if (kind === "metric")
|
|
38
|
+
metrics.refresh();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
setDeleteError((0, telemetry_client_1.errorText)(error));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const saved = () => {
|
|
45
|
+
setEditing((current) => (current === editing ? { kind: "none" } : current));
|
|
46
|
+
definitions.refresh();
|
|
47
|
+
// The trigger form suggests metrics from this list.
|
|
48
|
+
if (editing.kind === "metric")
|
|
49
|
+
metrics.refresh();
|
|
50
|
+
};
|
|
51
|
+
if (!definitions.data && definitions.error) {
|
|
52
|
+
return (0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning", children: (0, telemetry_client_1.describeTelemetryError)(definitions.error) });
|
|
53
|
+
}
|
|
54
|
+
if (!definitions.data)
|
|
55
|
+
return (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" });
|
|
56
|
+
const { metrics: metricDefinitions, triggers } = definitions.data;
|
|
57
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: { opacity: definitions.loading ? 0.7 : 1, transition: "opacity 150ms" }, children: [editing.kind === "none" ? ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2 mb-3", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-primary btn-sm", onClick: () => setEditing({ kind: "metric" }), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-plus-lg me-1", "aria-hidden": "true" }), "New metric"] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary btn-sm", onClick: () => setEditing({ kind: "trigger" }), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-plus-lg me-1", "aria-hidden": "true" }), "New trigger"] })] })) : null, !(0, telemetry_client_1.isThisDevice)(deviceId) && editing.kind !== "none" ? ((0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary", children: "Saved on this device; it reaches the device you're looking at when they sync." })) : null, editing.kind === "metric" ? ((0, jsx_runtime_1.jsx)(metric_definition_form_1.MetricDefinitionForm, { definition: editing.definition, onSaved: saved, onCancel: () => setEditing({ kind: "none" }) }, editing.definition?.metricId)) : null, editing.kind === "trigger" ? ((0, jsx_runtime_1.jsx)(trigger_form_1.TriggerForm, { definition: editing.definition, metrics: metrics.data ?? [], onSaved: saved, onCancel: () => setEditing({ kind: "none" }) }, editing.definition?.triggerId)) : null, deleteError ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger small", children: deleteError }) : null, (0, jsx_runtime_1.jsx)("h2", { className: "h6", children: "Metrics" }), (0, jsx_runtime_1.jsx)("div", { className: "table-responsive mb-4", children: (0, jsx_runtime_1.jsxs)("table", { className: "table table-sm table-hover small align-middle", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { children: "Metric" }), (0, jsx_runtime_1.jsx)("th", { children: "Kind" }), (0, jsx_runtime_1.jsx)("th", { children: "Reads" }), (0, jsx_runtime_1.jsx)("th", { children: "From" }), (0, jsx_runtime_1.jsx)("th", {})] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: metricDefinitions.map((definition) => ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsxs)("td", { children: [(0, jsx_runtime_1.jsx)("code", { children: definition.metricId }), (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: definition.description }), definition.stoppedReason ? ((0, jsx_runtime_1.jsxs)("div", { className: "text-warning-emphasis", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle-fill me-1", "aria-hidden": "true" }), "Switched off on ", (0, telemetry_client_1.isThisDevice)(deviceId) ? "this" : "that", " device:", " ", definition.stoppedReason] })) : null, definition.disabled ? (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Off" }) : null] }), (0, jsx_runtime_1.jsxs)("td", { className: "text-nowrap", children: [definition.kind, definition.unit ? ` (${definition.unit})` : ""] }), (0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)("code", { className: "small", children: describeMatch(definition) }) }), (0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)(badges_1.OriginBadge, { origin: definition.origin, packageId: definition.originPackageId }) }), (0, jsx_runtime_1.jsx)("td", { className: "text-end text-nowrap", children: (0, jsx_runtime_1.jsx)(OwnActions, { own: definition.origin === "user", onEdit: () => setEditing({ kind: "metric", definition }), onDelete: () => void remove("metric", definition.metricId) }) })] }, `${definition.origin}:${definition.originPackageId ?? ""}:${definition.metricId}`))) })] }) }), (0, jsx_runtime_1.jsx)("h2", { className: "h6", children: "Triggers" }), triggers.length === 0 ? ((0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary", children: "No triggers yet." })) : ((0, jsx_runtime_1.jsx)("div", { className: "table-responsive", children: (0, jsx_runtime_1.jsxs)("table", { className: "table table-sm table-hover small align-middle", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { children: "Trigger" }), (0, jsx_runtime_1.jsx)("th", { children: "Condition" }), (0, jsx_runtime_1.jsx)("th", { children: "Does" }), (0, jsx_runtime_1.jsx)("th", { children: "From" }), (0, jsx_runtime_1.jsx)("th", {})] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: triggers.map((definition) => ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsxs)("td", { children: [(0, jsx_runtime_1.jsx)("code", { children: definition.triggerId }), (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: definition.description }), definition.stoppedReason ? ((0, jsx_runtime_1.jsxs)("div", { className: "text-warning-emphasis", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle-fill me-1", "aria-hidden": "true" }), "Refused on ", (0, telemetry_client_1.isThisDevice)(deviceId) ? "this" : "that", " device:", " ", definition.stoppedReason] })) : null, definition.disabled ? (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Off" }) : null] }), (0, jsx_runtime_1.jsxs)("td", { children: [(0, jsx_runtime_1.jsx)("code", { children: definition.metricId }), " ", (0, alerts_tab_1.describeCondition)(definition)] }), (0, jsx_runtime_1.jsx)("td", { children: describeAction(definition) }), (0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)(badges_1.OriginBadge, { origin: definition.origin, packageId: definition.originPackageId }) }), (0, jsx_runtime_1.jsx)("td", { className: "text-end text-nowrap", children: (0, jsx_runtime_1.jsx)(OwnActions, { own: definition.origin === "user", onEdit: () => setEditing({ kind: "trigger", definition }), onDelete: () => void remove("trigger", definition.triggerId) }) })] }, `${definition.origin}:${definition.originPackageId ?? ""}:${definition.triggerId}`))) })] }) }))] }));
|
|
58
|
+
}
|
|
59
|
+
function OwnActions(props) {
|
|
60
|
+
if (!props.own)
|
|
61
|
+
return null;
|
|
62
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 me-2", onClick: props.onEdit, children: "Edit" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-danger", onClick: props.onDelete, children: "Delete" })] }));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* What lines a metric reads, briefly: its event, levels, source, data paths and text match.
|
|
66
|
+
*
|
|
67
|
+
* @param definition - The metric definition.
|
|
68
|
+
*/
|
|
69
|
+
function describeMatch(definition) {
|
|
70
|
+
const match = definition.match ?? {};
|
|
71
|
+
const parts = [];
|
|
72
|
+
if (match.event)
|
|
73
|
+
parts.push(`event ${match.event}`);
|
|
74
|
+
if (match.levels?.length)
|
|
75
|
+
parts.push(match.levels.join("|"));
|
|
76
|
+
if (match.source)
|
|
77
|
+
parts.push(`source ${match.source}`);
|
|
78
|
+
if (match.packageId)
|
|
79
|
+
parts.push(`package ${match.packageId}`);
|
|
80
|
+
if (match.process)
|
|
81
|
+
parts.push(`process ${match.process}`);
|
|
82
|
+
for (const [path, value] of Object.entries(match.where ?? {}))
|
|
83
|
+
parts.push(`${path}=${String(value)}`);
|
|
84
|
+
for (const path of match.has ?? [])
|
|
85
|
+
parts.push(`has ${path}`);
|
|
86
|
+
if (match.message?.prefix)
|
|
87
|
+
parts.push(`starts "${match.message.prefix}"`);
|
|
88
|
+
if (match.message?.contains)
|
|
89
|
+
parts.push(`contains "${match.message.contains}"`);
|
|
90
|
+
if (match.message?.pattern)
|
|
91
|
+
parts.push(`/${match.message.pattern}/${match.message.flags ?? ""}`);
|
|
92
|
+
if (definition.value)
|
|
93
|
+
parts.push(`value ${definition.value}`);
|
|
94
|
+
if (definition.labels?.length)
|
|
95
|
+
parts.push(`by ${definition.labels.join(", ")}`);
|
|
96
|
+
return parts.join(" · ") || "every line";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a trigger does when it fires.
|
|
100
|
+
*
|
|
101
|
+
* @param definition - The trigger.
|
|
102
|
+
*/
|
|
103
|
+
function describeAction(definition) {
|
|
104
|
+
const parts = [];
|
|
105
|
+
if (definition.action?.notify)
|
|
106
|
+
parts.push(`Notify: ${definition.action.notify.title}`);
|
|
107
|
+
if (definition.action?.tool)
|
|
108
|
+
parts.push(`Call ${definition.action.tool.toolName}`);
|
|
109
|
+
return parts.join("; ") || "Nothing";
|
|
110
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IMyDevice } from "./use-telemetry";
|
|
2
|
+
/** Props for {@link DevicePicker}. */
|
|
3
|
+
export interface DevicePickerProps {
|
|
4
|
+
/** The user's devices, this one first; `undefined` while loading. */
|
|
5
|
+
devices: IMyDevice[] | undefined;
|
|
6
|
+
/** The device being looked at; omitted for this device. */
|
|
7
|
+
deviceId: string | undefined;
|
|
8
|
+
/** Called with the chosen device, or `undefined` for this device. */
|
|
9
|
+
onChange: (deviceId: string | undefined) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Which of the user's devices Monitoring reads: this one, or another, through this device's host.
|
|
13
|
+
* Every device is listed; one that can't be reached says so when a section reads it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function DevicePicker(props: DevicePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* A device's line in the picker: "Mac (this device)", "This device" when it has no name, and
|
|
18
|
+
* another device's name (or id).
|
|
19
|
+
*
|
|
20
|
+
* @param device - One of the user's devices.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deviceLabel(device: IMyDevice): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DevicePicker = DevicePicker;
|
|
4
|
+
exports.deviceLabel = deviceLabel;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
/**
|
|
7
|
+
* Which of the user's devices Monitoring reads: this one, or another, through this device's host.
|
|
8
|
+
* Every device is listed; one that can't be reached says so when a section reads it.
|
|
9
|
+
*/
|
|
10
|
+
function DevicePicker(props) {
|
|
11
|
+
const devices = props.devices ?? [];
|
|
12
|
+
const selected = devices.find((d) => d.deviceId === props.deviceId);
|
|
13
|
+
const value = props.deviceId ?? devices[0]?.deviceId ?? "";
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: "monitoring-device", className: "small text-body-secondary text-nowrap mb-0", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-laptop me-1", "aria-hidden": "true" }), "Device"] }), (0, jsx_runtime_1.jsxs)("select", { id: "monitoring-device", className: "form-select form-select-sm", style: { maxWidth: 280 }, value: value, disabled: !props.devices, onChange: (event) => {
|
|
15
|
+
const device = devices.find((d) => d.deviceId === event.target.value);
|
|
16
|
+
props.onChange(!device || device.isThisDevice ? undefined : device.deviceId);
|
|
17
|
+
}, children: [props.deviceId && !selected ? ((0, jsx_runtime_1.jsx)("option", { value: props.deviceId, children: props.deviceId })) : null, devices.map((device) => ((0, jsx_runtime_1.jsx)("option", { value: device.deviceId, children: deviceLabel(device) }, device.deviceId)))] })] }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A device's line in the picker: "Mac (this device)", "This device" when it has no name, and
|
|
21
|
+
* another device's name (or id).
|
|
22
|
+
*
|
|
23
|
+
* @param device - One of the user's devices.
|
|
24
|
+
*/
|
|
25
|
+
function deviceLabel(device) {
|
|
26
|
+
if (device.isThisDevice)
|
|
27
|
+
return device.name ? `${device.name} (this device)` : "This device";
|
|
28
|
+
return device.name || device.deviceId;
|
|
29
|
+
}
|