@juice-js/observability 1.1.0 → 1.2.0

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 (66) hide show
  1. package/README.md +4 -2
  2. package/fesm2022/juice-js-observability-agent.page-Vb7LDThl.mjs +1144 -0
  3. package/fesm2022/juice-js-observability-agent.page-Vb7LDThl.mjs.map +1 -0
  4. package/fesm2022/juice-js-observability-agents.page-Ch-tBwQO.mjs +413 -0
  5. package/fesm2022/juice-js-observability-agents.page-Ch-tBwQO.mjs.map +1 -0
  6. package/fesm2022/{juice-js-observability-alert.page-nEy5Gc6j.mjs → juice-js-observability-alert.page-2kfKksIG.mjs} +200 -4
  7. package/fesm2022/juice-js-observability-alert.page-2kfKksIG.mjs.map +1 -0
  8. package/fesm2022/{juice-js-observability-alerts.page-DUXXBanH.mjs → juice-js-observability-alerts.page-BNmez0Ak.mjs} +2 -2
  9. package/fesm2022/{juice-js-observability-alerts.page-DUXXBanH.mjs.map → juice-js-observability-alerts.page-BNmez0Ak.mjs.map} +1 -1
  10. package/fesm2022/juice-js-observability-approvals.page-DBLw-vl1.mjs +387 -0
  11. package/fesm2022/juice-js-observability-approvals.page-DBLw-vl1.mjs.map +1 -0
  12. package/fesm2022/juice-js-observability-incident.page-D2GvuIft.mjs +436 -0
  13. package/fesm2022/juice-js-observability-incident.page-D2GvuIft.mjs.map +1 -0
  14. package/fesm2022/juice-js-observability-incidents.page-DhC3BkBo.mjs +438 -0
  15. package/fesm2022/juice-js-observability-incidents.page-DhC3BkBo.mjs.map +1 -0
  16. package/fesm2022/juice-js-observability-load-runs.page-DVuO4zFp.mjs +349 -0
  17. package/fesm2022/juice-js-observability-load-runs.page-DVuO4zFp.mjs.map +1 -0
  18. package/fesm2022/{juice-js-observability-logs.page-i76xbJLH.mjs → juice-js-observability-logs.page-PXWQMcvL.mjs} +3 -3
  19. package/fesm2022/{juice-js-observability-logs.page-i76xbJLH.mjs.map → juice-js-observability-logs.page-PXWQMcvL.mjs.map} +1 -1
  20. package/fesm2022/{juice-js-observability-metrics.page-Cq5S0yGJ.mjs → juice-js-observability-metrics.page-Ctm_EEFb.mjs} +3 -3
  21. package/fesm2022/{juice-js-observability-metrics.page-Cq5S0yGJ.mjs.map → juice-js-observability-metrics.page-Ctm_EEFb.mjs.map} +1 -1
  22. package/fesm2022/juice-js-observability-notifications.page-CtcV3Ei4.mjs +758 -0
  23. package/fesm2022/juice-js-observability-notifications.page-CtcV3Ei4.mjs.map +1 -0
  24. package/fesm2022/{juice-js-observability-overview.page-DXZl_fUh.mjs → juice-js-observability-overview.page-BRGpTOyc.mjs} +3 -3
  25. package/fesm2022/{juice-js-observability-overview.page-DXZl_fUh.mjs.map → juice-js-observability-overview.page-BRGpTOyc.mjs.map} +1 -1
  26. package/fesm2022/{juice-js-observability-resource.page-CauDE6kK.mjs → juice-js-observability-resource.page-O4GGdirR.mjs} +2 -2
  27. package/fesm2022/{juice-js-observability-resource.page-CauDE6kK.mjs.map → juice-js-observability-resource.page-O4GGdirR.mjs.map} +1 -1
  28. package/fesm2022/{juice-js-observability-resources.page-CukW8vVc.mjs → juice-js-observability-resources.page-B_AVPpes.mjs} +2 -2
  29. package/fesm2022/{juice-js-observability-resources.page-CukW8vVc.mjs.map → juice-js-observability-resources.page-B_AVPpes.mjs.map} +1 -1
  30. package/fesm2022/juice-js-observability-rules.page-CARCWaw_.mjs +581 -0
  31. package/fesm2022/juice-js-observability-rules.page-CARCWaw_.mjs.map +1 -0
  32. package/fesm2022/juice-js-observability-service.page-DRj1GO0Q.mjs +1257 -0
  33. package/fesm2022/juice-js-observability-service.page-DRj1GO0Q.mjs.map +1 -0
  34. package/fesm2022/{juice-js-observability-services.page-B1huLe_a.mjs → juice-js-observability-services.page-BbFbbvyH.mjs} +3 -3
  35. package/fesm2022/{juice-js-observability-services.page-B1huLe_a.mjs.map → juice-js-observability-services.page-BbFbbvyH.mjs.map} +1 -1
  36. package/fesm2022/juice-js-observability-silences.page-CoTqfGxY.mjs +523 -0
  37. package/fesm2022/juice-js-observability-silences.page-CoTqfGxY.mjs.map +1 -0
  38. package/fesm2022/juice-js-observability-slo.page-l7TOat-D.mjs +414 -0
  39. package/fesm2022/juice-js-observability-slo.page-l7TOat-D.mjs.map +1 -0
  40. package/fesm2022/juice-js-observability-slos.page-DNG6g6_R.mjs +267 -0
  41. package/fesm2022/juice-js-observability-slos.page-DNG6g6_R.mjs.map +1 -0
  42. package/fesm2022/juice-js-observability-suggestions-eQK_z0Nd.mjs +367 -0
  43. package/fesm2022/juice-js-observability-suggestions-eQK_z0Nd.mjs.map +1 -0
  44. package/fesm2022/{juice-js-observability-telemetry-BftWSOaQ.mjs → juice-js-observability-telemetry-DVwUTHSz.mjs} +101 -91
  45. package/fesm2022/juice-js-observability-telemetry-DVwUTHSz.mjs.map +1 -0
  46. package/fesm2022/juice-js-observability-timeline.page-CFSigOgk.mjs +213 -0
  47. package/fesm2022/juice-js-observability-timeline.page-CFSigOgk.mjs.map +1 -0
  48. package/fesm2022/{juice-js-observability-topology.page-aMWEXyMB.mjs → juice-js-observability-topology.page-BDfNpiql.mjs} +56 -4
  49. package/fesm2022/juice-js-observability-topology.page-BDfNpiql.mjs.map +1 -0
  50. package/fesm2022/{juice-js-observability-trace.page-DUCWnZL5.mjs → juice-js-observability-trace.page-CdW09ADY.mjs} +10 -8
  51. package/fesm2022/juice-js-observability-trace.page-CdW09ADY.mjs.map +1 -0
  52. package/fesm2022/{juice-js-observability-traces.page-DXSDdeTH.mjs → juice-js-observability-traces.page-CMuItN_m.mjs} +3 -3
  53. package/fesm2022/{juice-js-observability-traces.page-DXSDdeTH.mjs.map → juice-js-observability-traces.page-CMuItN_m.mjs.map} +1 -1
  54. package/fesm2022/juice-js-observability.mjs +507 -110
  55. package/fesm2022/juice-js-observability.mjs.map +1 -1
  56. package/package.json +1 -1
  57. package/styles/_observability.scss +26 -3
  58. package/types/juice-js-observability.d.ts +623 -1
  59. package/fesm2022/juice-js-observability-alert.page-nEy5Gc6j.mjs.map +0 -1
  60. package/fesm2022/juice-js-observability-rules.page-Crb07uWm.mjs +0 -175
  61. package/fesm2022/juice-js-observability-rules.page-Crb07uWm.mjs.map +0 -1
  62. package/fesm2022/juice-js-observability-service.page-Dt8bN2Ry.mjs +0 -726
  63. package/fesm2022/juice-js-observability-service.page-Dt8bN2Ry.mjs.map +0 -1
  64. package/fesm2022/juice-js-observability-telemetry-BftWSOaQ.mjs.map +0 -1
  65. package/fesm2022/juice-js-observability-topology.page-aMWEXyMB.mjs.map +0 -1
  66. package/fesm2022/juice-js-observability-trace.page-DUCWnZL5.mjs.map +0 -1
@@ -0,0 +1,1144 @@
1
+ import { ApiService, ApprovalCount, ContextService, LinkPipe } from "./juice-js-observability.mjs";
2
+ import { b as copyText, c as ContextBar, g as AgoPipe, h as apiResource, o as problemText, y as ReasonPipe } from "./juice-js-observability-telemetry-DVwUTHSz.mjs";
3
+ import * as i0 from "@angular/core";
4
+ import { ChangeDetectionStrategy, Component, computed, effect, inject, input, signal, untracked } from "@angular/core";
5
+ import { RouterLink } from "@angular/router";
6
+ import { DatePipe } from "@angular/common";
7
+ import * as i1 from "@angular/forms";
8
+ import { FormsModule } from "@angular/forms";
9
+ import * as i2 from "@angular/material/button";
10
+ import { MatButtonModule } from "@angular/material/button";
11
+ import { MatFormFieldModule } from "@angular/material/form-field";
12
+ import * as i5 from "@angular/material/input";
13
+ import { MatInputModule } from "@angular/material/input";
14
+ import * as i6 from "@angular/material/progress-bar";
15
+ import { MatProgressBarModule } from "@angular/material/progress-bar";
16
+ import * as i4 from "@angular/material/select";
17
+ import { MatSelectModule } from "@angular/material/select";
18
+ import * as i3 from "@angular/material/checkbox";
19
+ import { MatCheckboxModule } from "@angular/material/checkbox";
20
+ const WAITING = ["Pending", "Delivered"];
21
+ const LABELS = {
22
+ "host.summary": "Host summary",
23
+ "disk.usage": "Disk usage",
24
+ "tcp.reachability": "TCP reachability",
25
+ "agent.update": "Update the agent",
26
+ "service.restart": "Restart a service",
27
+ "files.cleanup": "Clean up old files",
28
+ "diagnostics.bundle": "Diagnostic bundle"
29
+ };
30
+ const PARAMETER_LABELS = {
31
+ pathPrefix: "Only under this path",
32
+ host: "Host",
33
+ port: "Port",
34
+ timeoutMs: "Wait (ms)",
35
+ service: "Service",
36
+ folder: "Folder",
37
+ keepHours: "Keep files from the last (hours)",
38
+ dryRun: "Dry run: only report what would go",
39
+ logLines: "Lines from each log"
40
+ };
41
+ function formatBytes(bytes) {
42
+ if (bytes === null || bytes === void 0) return "—";
43
+ const units = [
44
+ "B",
45
+ "KB",
46
+ "MB",
47
+ "GB",
48
+ "TB",
49
+ "PB"
50
+ ];
51
+ let value = bytes;
52
+ let unit = 0;
53
+ while (value >= 1024 && unit < units.length - 1) {
54
+ value /= 1024;
55
+ unit++;
56
+ }
57
+ return `${value < 10 && unit > 0 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
58
+ }
59
+ function formatUptime(seconds) {
60
+ const days = Math.floor(seconds / 86400);
61
+ const hours = Math.floor(seconds % 86400 / 3600);
62
+ return days > 0 ? `${days} d ${hours} h` : hours > 0 ? `${hours} h ${Math.floor(seconds % 3600 / 60)} min` : `${Math.floor(seconds / 60)} min`;
63
+ }
64
+ var AgentPage = class AgentPage {
65
+ ctx = inject(ContextService);
66
+ api = inject(ApiService);
67
+ approvalCount = inject(ApprovalCount);
68
+ id = input.required(...ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []);
69
+ action = signal("host.summary", ...ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []);
70
+ values = signal({}, ...ngDevMode ? [{ debugName: "values" }] : /* istanbul ignore next */ []);
71
+ issuing = signal(false, ...ngDevMode ? [{ debugName: "issuing" }] : /* istanbul ignore next */ []);
72
+ issueError = signal("", ...ngDevMode ? [{ debugName: "issueError" }] : /* istanbul ignore next */ []);
73
+ confirming = signal(false, ...ngDevMode ? [{ debugName: "confirming" }] : /* istanbul ignore next */ []);
74
+ revoking = signal(false, ...ngDevMode ? [{ debugName: "revoking" }] : /* istanbul ignore next */ []);
75
+ revokeError = signal("", ...ngDevMode ? [{ debugName: "revokeError" }] : /* istanbul ignore next */ []);
76
+ version = "";
77
+ reason = "";
78
+ requestReason = "";
79
+ watchHost = false;
80
+ issued = signal("", ...ngDevMode ? [{ debugName: "issued" }] : /* istanbul ignore next */ []);
81
+ needsApproval = computed(() => (this.selected()?.approval ?? "None") !== "None", ...ngDevMode ? [{ debugName: "needsApproval" }] : /* istanbul ignore next */ []);
82
+ requests = apiResource({
83
+ params: () => this.id(),
84
+ stream: ({ params }) => this.api.actionRequests({
85
+ agentId: params,
86
+ limit: 20
87
+ })
88
+ });
89
+ requestList = computed(() => this.requests.value()?.items ?? [], ...ngDevMode ? [{ debugName: "requestList" }] : /* istanbul ignore next */ []);
90
+ creating = signal(false, ...ngDevMode ? [{ debugName: "creating" }] : /* istanbul ignore next */ []);
91
+ reenrollError = signal("", ...ngDevMode ? [{ debugName: "reenrollError" }] : /* istanbul ignore next */ []);
92
+ token = signal(null, ...ngDevMode ? [{ debugName: "token" }] : /* istanbul ignore next */ []);
93
+ copied = signal("", ...ngDevMode ? [{ debugName: "copied" }] : /* istanbul ignore next */ []);
94
+ everyone = apiResource({
95
+ params: () => this.agent.value()?.status === "Revoked" || void 0,
96
+ stream: () => this.api.agents(true)
97
+ });
98
+ successor = computed(() => {
99
+ const revoked = this.agent.value();
100
+ if (!revoked?.revokedAt) return void 0;
101
+ return (this.everyone.value()?.items ?? []).find((a) => a.status === "Active" && a.hostname === revoked.hostname && Date.parse(a.enrolledAt) > Date.parse(revoked.revokedAt));
102
+ }, ...ngDevMode ? [{ debugName: "successor" }] : /* istanbul ignore next */ []);
103
+ actions = apiResource({
104
+ params: () => this.id(),
105
+ stream: ({ params }) => this.api.agentActions(params)
106
+ });
107
+ actionList = computed(() => this.actions.value()?.items ?? [], ...ngDevMode ? [{ debugName: "actionList" }] : /* istanbul ignore next */ []);
108
+ selected = computed(() => this.actionList().find((a) => a.name === this.action()), ...ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []);
109
+ agent = apiResource({
110
+ params: () => this.id(),
111
+ stream: ({ params }) => this.api.agent(params)
112
+ });
113
+ error = computed(() => problemText(this.agent.error()), ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
114
+ commands = apiResource({
115
+ params: () => this.id(),
116
+ stream: ({ params }) => this.api.agentCommands(params)
117
+ });
118
+ commandsError = computed(() => problemText(this.commands.error()), ...ngDevMode ? [{ debugName: "commandsError" }] : /* istanbul ignore next */ []);
119
+ packages = apiResource({
120
+ params: () => this.action() === "agent.update" || void 0,
121
+ stream: () => this.api.agentPackages()
122
+ });
123
+ older = signal(null, ...ngDevMode ? [{ debugName: "older" }] : /* istanbul ignore next */ []);
124
+ allCommands = computed(() => {
125
+ const first = this.commands.value()?.items ?? [];
126
+ const seen = new Set(first.map((c) => c.id));
127
+ return [...first, ...(this.older()?.items ?? []).filter((c) => !seen.has(c.id))];
128
+ }, ...ngDevMode ? [{ debugName: "allCommands" }] : /* istanbul ignore next */ []);
129
+ nextCursor = computed(() => this.older() ? this.older().cursor : this.commands.value()?.nextCursor ?? null, ...ngDevMode ? [{ debugName: "nextCursor" }] : /* istanbul ignore next */ []);
130
+ constructor() {
131
+ effect(() => {
132
+ const list = this.actionList();
133
+ if (list.length === 0) return;
134
+ const current = list.find((a) => a.name === untracked(this.action));
135
+ if (!current || current.permitted === false) this.choose((list.find((a) => a.permitted !== false) ?? list[0]).name);
136
+ else if (Object.keys(untracked(this.values)).length === 0) this.choose(current.name);
137
+ });
138
+ effect((onCleanup) => {
139
+ const running = this.allCommands().some((c) => this.waiting(c));
140
+ const deciding = this.requestList().some((r) => r.state === "Pending");
141
+ if (!running && !deciding) return;
142
+ const timer = setTimeout(() => {
143
+ this.commands.reload();
144
+ this.agent.reload();
145
+ this.requests.reload();
146
+ }, running ? 2e3 : 5e3);
147
+ onCleanup(() => clearTimeout(timer));
148
+ });
149
+ }
150
+ waiting(c) {
151
+ return WAITING.includes(c.state) && new Date(c.expiresAt).getTime() > Date.now();
152
+ }
153
+ describe(c) {
154
+ const p = c.parameters ?? {};
155
+ switch (c.action) {
156
+ case "disk.usage": return p["pathPrefix"] ? `under ${p["pathPrefix"]}` : "all filesystems";
157
+ case "tcp.reachability": return `${p["host"]}:${p["port"]}, wait ${p["timeoutMs"]} ms`;
158
+ case "agent.update": return `to ${p["version"]}`;
159
+ default: return Object.entries(p).map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`).join(", ");
160
+ }
161
+ }
162
+ label(name) {
163
+ return LABELS[name] ?? name;
164
+ }
165
+ title(p) {
166
+ const words = PARAMETER_LABELS[p.name] ?? p.name.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase());
167
+ return p.required || p.type === "boolean" ? words : `${words} (optional)`;
168
+ }
169
+ choose(name) {
170
+ this.action.set(name);
171
+ this.issueError.set("");
172
+ const defaults = {};
173
+ for (const p of this.actionList().find((a) => a.name === name)?.parameters ?? []) if (p.default !== null) defaults[p.name] = p.type === "integer" ? Number(p.default) : p.type === "boolean" ? p.default === "true" : p.default;
174
+ else if (p.required && p.allowed?.length === 1) defaults[p.name] = p.allowed[0];
175
+ this.values.set(defaults);
176
+ }
177
+ set(name, value) {
178
+ this.values.update((v) => ({
179
+ ...v,
180
+ [name]: value
181
+ }));
182
+ }
183
+ flat(result) {
184
+ if (!result || typeof result !== "object" || Array.isArray(result)) return null;
185
+ const entries = Object.entries(result);
186
+ return entries.every(([, v]) => v === null || [
187
+ "string",
188
+ "number",
189
+ "boolean"
190
+ ].includes(typeof v)) ? entries.map(([k, v]) => [k, v === null ? "—" : String(v)]) : null;
191
+ }
192
+ summary(c) {
193
+ return c.result;
194
+ }
195
+ bundle(c) {
196
+ return c.result;
197
+ }
198
+ downloading = signal(null, ...ngDevMode ? [{ debugName: "downloading" }] : /* istanbul ignore next */ []);
199
+ downloadErrors = signal({}, ...ngDevMode ? [{ debugName: "downloadErrors" }] : /* istanbul ignore next */ []);
200
+ download(b) {
201
+ this.downloading.set(b.bundleId);
202
+ this.downloadErrors.update((e) => ({
203
+ ...e,
204
+ [b.bundleId]: ""
205
+ }));
206
+ this.api.downloadBundle(this.id(), b.bundleId).subscribe({
207
+ next: (response) => {
208
+ this.downloading.set(null);
209
+ const name = /filename="?([^";]+)"?/.exec(response.headers.get("content-disposition") ?? "")?.[1] ?? `juice-bundle-${b.bundleId}.zip`;
210
+ const url = URL.createObjectURL(response.body);
211
+ const link = document.createElement("a");
212
+ link.href = url;
213
+ link.download = name;
214
+ link.click();
215
+ setTimeout(() => URL.revokeObjectURL(url), 1e4);
216
+ },
217
+ error: (e) => {
218
+ this.downloading.set(null);
219
+ const reason = e?.status === 404 ? "The bundle is gone: bundles are kept 14 days by default." : e?.status === 403 ? "Downloading a bundle takes an operator or an admin: its log excerpts can say more than the rest of the Console." : problemText(e);
220
+ this.downloadErrors.update((errors) => ({
221
+ ...errors,
222
+ [b.bundleId]: reason
223
+ }));
224
+ }
225
+ });
226
+ }
227
+ disk(c) {
228
+ return c.result;
229
+ }
230
+ tcp(c) {
231
+ return c.result;
232
+ }
233
+ shown = 8;
234
+ expanded = signal(/* @__PURE__ */ new Set(), ...ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []);
235
+ toggle(id) {
236
+ this.expanded.update((s) => {
237
+ const next = new Set(s);
238
+ if (!next.delete(id)) next.add(id);
239
+ return next;
240
+ });
241
+ }
242
+ fullestFirst(d, all) {
243
+ const free = (f) => f.totalBytes > 0 ? f.availableBytes / f.totalBytes : 1;
244
+ const sizable = (f) => Number(f.totalBytes >= 1024 ** 3);
245
+ const sorted = [...d.filesystems].sort((a, b) => Number(this.low(b)) - Number(this.low(a)) || sizable(b) - sizable(a) || free(a) - free(b));
246
+ return all ? sorted : sorted.slice(0, this.shown);
247
+ }
248
+ low(f) {
249
+ return f.totalBytes >= 1024 ** 3 && f.availableBytes / f.totalBytes < .1;
250
+ }
251
+ bytes(n) {
252
+ return formatBytes(n);
253
+ }
254
+ uptime(s) {
255
+ return formatUptime(s);
256
+ }
257
+ json(v) {
258
+ return JSON.stringify(v, null, 2);
259
+ }
260
+ parameters() {
261
+ if (this.action() === "agent.update") return { version: this.version };
262
+ const values = this.values();
263
+ const out = {};
264
+ for (const p of this.selected()?.parameters ?? []) {
265
+ const v = values[p.name];
266
+ if (p.type === "boolean") {
267
+ if (v === true || p.required) out[p.name] = v === true;
268
+ continue;
269
+ }
270
+ if (v === void 0 || v === null || v === "") continue;
271
+ out[p.name] = p.type === "integer" ? Number(v) : String(v).trim();
272
+ }
273
+ return out;
274
+ }
275
+ verificationText(verification) {
276
+ switch (verification) {
277
+ case "Verifying": return "Watching health for recovery";
278
+ case "Verified": return "Recovery confirmed by health";
279
+ case "NotVerified": return "Recovery not confirmed";
280
+ default: return verification;
281
+ }
282
+ }
283
+ approvalText(policy) {
284
+ switch (policy) {
285
+ case "None": return "runs when asked";
286
+ case "Admin": return "needs an admin: an admin's request runs at once, an operator's waits for an admin to approve it";
287
+ default: return "needs a second person: an admin other than whoever asks approves it";
288
+ }
289
+ }
290
+ issue() {
291
+ const action = this.action();
292
+ this.issuing.set(true);
293
+ this.issueError.set("");
294
+ this.issued.set("");
295
+ const failed = (e) => {
296
+ this.issuing.set(false);
297
+ this.issueError.set(e.status === 403 ? "Asking an agent needs the operator or admin role." : problemText(e));
298
+ };
299
+ if (!this.needsApproval()) {
300
+ this.api.issueCommand(this.id(), action, this.parameters()).subscribe({
301
+ next: () => {
302
+ this.issuing.set(false);
303
+ this.commands.reload();
304
+ },
305
+ error: failed
306
+ });
307
+ return;
308
+ }
309
+ const host = this.watchHost && this.selected()?.changing ? this.agent.value()?.resourceId : null;
310
+ this.api.requestAction(this.id(), action, this.parameters(), this.requestReason.trim(), host ? {
311
+ type: "Host",
312
+ id: host
313
+ } : null).subscribe({
314
+ next: (r) => {
315
+ this.issuing.set(false);
316
+ this.requestReason = "";
317
+ this.issued.set(r.state !== "Issued" ? "Requested: it runs once approved, on the Approvals page." : r.policy === "None" ? "Needs no approval as asked: running." : "Approved by your role: running.");
318
+ this.requests.reload();
319
+ this.commands.reload();
320
+ this.approvalCount.refresh();
321
+ },
322
+ error: failed
323
+ });
324
+ }
325
+ cancelRequest(id) {
326
+ this.api.cancelRequest(id).subscribe({
327
+ next: () => {
328
+ this.requests.reload();
329
+ this.approvalCount.refresh();
330
+ },
331
+ error: (e) => this.issueError.set(problemText(e))
332
+ });
333
+ }
334
+ loadOlder() {
335
+ const cursor = this.nextCursor();
336
+ if (!cursor) return;
337
+ this.api.agentCommands(this.id(), cursor).subscribe({
338
+ next: (page) => this.older.update((o) => ({
339
+ items: [...o?.items ?? [], ...page.items],
340
+ cursor: page.nextCursor
341
+ })),
342
+ error: (e) => this.issueError.set(problemText(e))
343
+ });
344
+ }
345
+ reenroll(hostname) {
346
+ this.creating.set(true);
347
+ this.reenrollError.set("");
348
+ this.copied.set("");
349
+ this.api.createEnrollmentToken(`re-enroll ${hostname}`, 60).subscribe({
350
+ next: (t) => {
351
+ this.creating.set(false);
352
+ this.token.set(t);
353
+ },
354
+ error: (e) => {
355
+ this.creating.set(false);
356
+ this.reenrollError.set(e.status === 403 ? "Enrolling an agent needs the admin role." : problemText(e));
357
+ }
358
+ });
359
+ }
360
+ copy(text) {
361
+ copyText(text, document.querySelector("[data-testid=reenroll-token-value]")).then((done) => this.copied.set(done));
362
+ }
363
+ revoke() {
364
+ if (!this.confirming()) {
365
+ this.confirming.set(true);
366
+ return;
367
+ }
368
+ this.revoking.set(true);
369
+ this.revokeError.set("");
370
+ this.api.revokeAgent(this.id(), this.reason.trim()).subscribe({
371
+ next: () => {
372
+ this.revoking.set(false);
373
+ this.confirming.set(false);
374
+ this.agent.reload();
375
+ this.commands.reload();
376
+ },
377
+ error: (e) => {
378
+ this.revoking.set(false);
379
+ this.revokeError.set(e.status === 403 ? "Revoking an agent needs the admin role." : problemText(e));
380
+ }
381
+ });
382
+ }
383
+ static ɵfac = i0.ɵɵngDeclareFactory({
384
+ minVersion: "12.0.0",
385
+ version: "22.2.4",
386
+ ngImport: i0,
387
+ type: AgentPage,
388
+ deps: [],
389
+ target: i0.ɵɵFactoryTarget.Component
390
+ });
391
+ static ɵcmp = i0.ɵɵngDeclareComponent({
392
+ minVersion: "17.0.0",
393
+ version: "22.2.4",
394
+ type: AgentPage,
395
+ isStandalone: true,
396
+ selector: "ng-component",
397
+ inputs: { id: {
398
+ classPropertyName: "id",
399
+ publicName: "id",
400
+ isSignal: true,
401
+ isRequired: true,
402
+ transformFunction: null
403
+ } },
404
+ ngImport: i0,
405
+ template: `
406
+ <jc-context-bar>
407
+ <a [routerLink]="['agents'] | jcLink" [queryParams]="ctx.keep()" class="jc-crumb">Agents</a><span class="jc-crumb-sep">›</span>
408
+ <h1>{{ agent.value()?.hostname ?? '…' }}</h1>
409
+ </jc-context-bar>
410
+ @if (agent.isLoading() && !agent.value()) { <mat-progress-bar mode="indeterminate" /> }
411
+ @if (agent.error()) { <p class="jc-error">{{ error() }}</p> }
412
+ @if (agent.value(); as a) {
413
+ <div class="jc-summary" data-testid="agent-summary">
414
+ <span class="jc-badge" data-testid="agent-state" [class.jc-health-healthy]="a.online" [class.jc-health-offline]="!a.online && a.status === 'Active'" [class.jc-health-none]="a.status !== 'Active'">
415
+ {{ a.status !== 'Active' ? a.status : a.online ? 'Online' : 'Not calling in' }}</span>
416
+ <span>{{ a.operatingSystem }}</span>
417
+ <span>version <span class="jc-mono" data-testid="agent-version">{{ a.version }}</span></span>
418
+ <span class="jc-muted">last seen {{ a.lastSeenAt | ago }}</span>
419
+ @if (a.resourceId) { <a [routerLink]="['resources', a.resourceId] | jcLink" [queryParams]="ctx.keep()">Host resource</a> }
420
+ </div>
421
+ <p class="jc-muted jc-small">Enrolled {{ a.enrolledAt | date: 'MMM d, y, HH:mm' }} by {{ a.enrolledBy }}. Certificate valid until {{ a.certificateNotAfter | date: 'MMM d, HH:mm' }}; the agent renews it when a third is left.</p>
422
+ @if (a.status !== 'Active') {
423
+ <p class="jc-notice" data-testid="agent-revoked">Revoked {{ a.revokedAt | date: 'MMM d, y, HH:mm' }} by {{ a.revokedBy }}: {{ a.revokeReason }}. The platform refuses its certificate for good.</p>
424
+ @if (successor(); as s) {
425
+ <p data-testid="agent-successor">{{ a.hostname }} enrolled again {{ s.enrolledAt | date: 'MMM d, HH:mm' }} as <a [routerLink]="['agents', s.id] | jcLink" [queryParams]="ctx.keep()">a new agent</a>.</p>
426
+ } @else {
427
+ <section class="jc-card" data-testid="reenroll">
428
+ <h2>Bring this host back</h2>
429
+ <p class="jc-muted jc-small">The host comes back as a new agent, with a new key: this one stays revoked, with its history. It needs a new token from an admin, put on the host.</p>
430
+ <button mat-flat-button type="button" data-testid="reenroll-create" [disabled]="creating()" (click)="reenroll(a.hostname)">Create a token for {{ a.hostname }}</button>
431
+ @if (reenrollError()) { <span class="jc-error" data-testid="reenroll-error"> {{ reenrollError() }}</span> }
432
+ @if (token(); as t) {
433
+ <div class="jc-notice" data-testid="reenroll-token">
434
+ <p>Replace the token in the agent's token file (<span class="jc-mono">Agent:EnrollmentTokenFile</span>) with this one. It works once, until {{ t.expiresAt | date: 'MMM d, HH:mm' }}, and <strong>won't be shown again</strong>.</p>
435
+ <p class="jc-row"><span class="jc-mono" data-testid="reenroll-token-value">{{ t.token }}</span>
436
+ <button mat-button type="button" (click)="copy(t.token)">{{ copied() === 'copied' ? 'Copied' : copied() === 'selected' ? 'Selected: press Ctrl+C' : 'Copy' }}</button></p>
437
+ <p>The agent notices it within seconds, sets its old identity aside and enrolls again: nothing else on the host changes. An agent from before 9 November doesn't: clear its data directory's identity files and restart it.</p>
438
+ </div>
439
+ }
440
+ </section>
441
+ }
442
+ } @else {
443
+ <section class="jc-card">
444
+ <h2>Ask the agent</h2>
445
+ <form class="jc-form" data-testid="command-form" (ngSubmit)="issue()">
446
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Action</mat-label>
447
+ <mat-select name="action" data-testid="command-action" [ngModel]="action()" (ngModelChange)="choose($event)">
448
+ @for (o of actionList(); track o.name) {
449
+ <mat-option [value]="o.name" [disabled]="o.permitted === false" [attr.data-testid]="'action-' + o.name">
450
+ {{ label(o.name) }}@if (o.custom) { <span class="jc-muted"> · custom</span> }@if (o.permitted === false) { <span class="jc-muted"> · not allowed on this host</span> }
451
+ </mat-option>
452
+ }
453
+ </mat-select>
454
+ </mat-form-field>
455
+ @if (action() === 'agent.update') {
456
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-md"><mat-label>Version</mat-label>
457
+ <mat-select name="version" data-testid="command-version" [(ngModel)]="version">
458
+ @for (p of packages.value()?.items ?? []; track p.version) { <mat-option [value]="p.version">{{ p.version }}</mat-option> }
459
+ </mat-select>
460
+ </mat-form-field>
461
+ @if (packages.value()?.items?.length === 0) { <span class="jc-muted jc-small">No signed packages are offered: see Agents:PackageDirectory.</span> }
462
+ } @else {
463
+ @for (p of selected()?.parameters ?? []; track p.name) {
464
+ @if (p.type === 'boolean') {
465
+ <mat-checkbox [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [ngModel]="values()[p.name] === true" (ngModelChange)="set(p.name, $event)">{{ title(p) }}</mat-checkbox>
466
+ } @else if (p.allowed?.length) {
467
+ <mat-form-field subscriptSizing="dynamic" [class.jc-field-md]="p.type !== 'string'" [class.jc-field-wide]="p.type === 'string'"><mat-label>{{ title(p) }}</mat-label>
468
+ <mat-select [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [ngModel]="values()[p.name] ?? ''" (ngModelChange)="set(p.name, $event)">
469
+ @if (!p.required) { <mat-option value="">Any</mat-option> }
470
+ @for (v of p.allowed; track v) { <mat-option [value]="v">{{ v }}</mat-option> }
471
+ </mat-select>
472
+ </mat-form-field>
473
+ } @else {
474
+ <mat-form-field subscriptSizing="dynamic" [class.jc-field-sm]="p.type === 'integer'" [class.jc-field-wide]="p.type === 'string'"><mat-label>{{ title(p) }}</mat-label>
475
+ <input matInput [type]="p.type === 'integer' ? 'number' : 'text'" [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [attr.min]="p.minimum" [attr.max]="p.maximum"
476
+ [attr.maxlength]="p.maxLength" [placeholder]="p.description ?? ''" [ngModel]="values()[p.name] ?? ''" (ngModelChange)="set(p.name, $event)">
477
+ </mat-form-field>
478
+ }
479
+ }
480
+ }
481
+ @if (needsApproval()) {
482
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Why (for whoever approves it)</mat-label>
483
+ <input matInput name="requestReason" data-testid="request-reason" maxlength="500" [(ngModel)]="requestReason">
484
+ </mat-form-field>
485
+ @if (selected()?.changing && agent.value()?.resourceId) {
486
+ <mat-checkbox name="watchHost" data-testid="request-watch-host" [(ngModel)]="watchHost">Fix this host's health: run only while it's unhealthy, and confirm recovery after</mat-checkbox>
487
+ }
488
+ }
489
+ <div class="jc-form-actions">
490
+ <button mat-flat-button type="submit" data-testid="command-issue" [disabled]="issuing() || selected()?.permitted === false">{{ needsApproval() ? 'Request' : action() === 'agent.update' ? 'Update' : 'Run' }}</button>
491
+ @if (issueError()) { <span class="jc-error" data-testid="command-error">{{ issueError() }}</span> }
492
+ @if (issued()) { <span class="jc-muted" data-testid="command-issued">{{ issued() }}</span> }
493
+ </div>
494
+ @if (selected(); as s) {
495
+ <div class="jc-muted jc-small jc-form-actions" data-testid="command-hint">
496
+ <div>{{ s.description }} <span data-testid="command-approval">{{ s.risk }} risk: {{ approvalText(s.approval) }}.</span></div>
497
+ @if (s.limits.length) { <div data-testid="command-limits">On this host: {{ s.limits.join('; ') }}.</div> }
498
+ </div>
499
+ }
500
+ </form>
501
+ @if (actions.value(); as list) {
502
+ @if (!list.reportedAt) {
503
+ <p class="jc-notice" data-testid="actions-not-reported">This agent doesn't report what its host allows (it's older than this platform): the list shows the built-in actions, and one its host doesn't permit comes back <strong>Rejected</strong>.</p>
504
+ } @else {
505
+ <p class="jc-muted jc-small">As the agent reported {{ list.reportedAt | ago }}, when it started. Its host still checks every command.</p>
506
+ }
507
+ }
508
+ </section>
509
+ }
510
+
511
+ @if (requestList().length) {
512
+ <section class="jc-card" data-testid="requests">
513
+ <h2>Requests</h2>
514
+ <table class="jc-table">
515
+ <thead><tr><th>Asked</th><th>Action</th><th>By, and why</th><th>State</th><th>Decided</th><th></th></tr></thead>
516
+ <tbody>
517
+ @for (r of requestList(); track r.id) {
518
+ <tr [attr.data-testid]="'request-' + r.id">
519
+ <td class="jc-nowrap">{{ r.requestedAt | date: 'MMM d, HH:mm:ss' }}</td>
520
+ <td><strong>{{ r.action }}</strong><div class="jc-muted jc-small">{{ r.risk }} risk</div></td>
521
+ <td>{{ r.requestedBy }}<div class="jc-small">{{ r.reason }}</div></td>
522
+ <td class="jc-nowrap"><span class="jc-badge" [class.jc-health-degraded]="r.state === 'Pending'" [class.jc-health-healthy]="r.state === 'Issued'"
523
+ [class.jc-health-none]="r.state !== 'Pending' && r.state !== 'Issued'" data-testid="request-state">{{ r.state === 'Pending' ? 'Waiting for approval' : r.state }}</span>
524
+ @if (r.state === 'Pending') { <div class="jc-muted jc-small">until {{ r.expiresAt | date: 'HH:mm' }}</div> }
525
+ @if (r.verification && r.verification !== 'None') {
526
+ <div class="jc-small" data-testid="request-verification" [class.jc-error]="r.verification === 'NotVerified'" [title]="r.verificationNote ?? ''">{{ verificationText(r.verification) }}</div>
527
+ }</td>
528
+ <td class="jc-small">@if (r.decidedBy) { {{ r.decidedBy }}, {{ r.decidedAt | date: 'HH:mm' }} }@if (r.comment) { <div>{{ r.comment }}</div> }</td>
529
+ <td class="jc-row-actions">@if (r.state === 'Pending') { <button mat-button type="button" [attr.data-testid]="'request-cancel-' + r.id" (click)="cancelRequest(r.id)">Cancel</button> }</td>
530
+ </tr>
531
+ }
532
+ </tbody>
533
+ </table>
534
+ </section>
535
+ }
536
+
537
+ <section class="jc-card" data-testid="commands">
538
+ <h2>Commands</h2>
539
+ @if (commands.error()) { <p class="jc-error">{{ commandsError() }}</p> }
540
+ <table class="jc-table">
541
+ <thead><tr><th>Issued</th><th>Action</th><th>By</th><th>State</th><th>Answer</th></tr></thead>
542
+ <tbody>
543
+ @for (c of allCommands(); track c.id) {
544
+ <tr [attr.data-testid]="'command-' + c.id">
545
+ <td class="jc-nowrap">{{ c.issuedAt | date: 'MMM d, HH:mm:ss' }}</td>
546
+ <td><strong>{{ c.action }}</strong>@if (describe(c); as d) { <div class="jc-small jc-mono">{{ d }}</div> }</td>
547
+ <td>{{ c.issuedBy }}</td>
548
+ <td class="jc-nowrap">
549
+ <span class="jc-badge" [class.jc-health-healthy]="c.state === 'Succeeded'" [class.jc-health-unhealthy]="c.state === 'Failed' || c.state === 'Rejected'"
550
+ [class.jc-health-degraded]="waiting(c)" [class.jc-health-none]="c.state === 'Expired' || c.state === 'Cancelled'" data-testid="command-state">{{ c.state }}</span>
551
+ @if (c.durationMs !== null) { <div class="jc-muted jc-small">{{ c.durationMs }} ms</div> }
552
+ </td>
553
+ <td class="jc-small" data-testid="command-answer">
554
+ @if (c.reason) { <div [class.jc-bad]="c.state !== 'Succeeded'">{{ c.reason | reason }}</div> }
555
+ @if (c.state === 'Succeeded' && c.result) {
556
+ @switch (c.action) {
557
+ @case ('host.summary') {
558
+ @if (summary(c); as h) {
559
+ <div>{{ h.hostname }} · {{ h.operatingSystem }} {{ h.architecture }} · up {{ uptime(h.uptimeSeconds) }}</div>
560
+ <div>{{ h.processorCount }} CPUs@if (h.loadAverage) { · load {{ h.loadAverage.join(' ') }} }@if (h.memoryTotalBytes) { · memory {{ bytes(h.memoryAvailableBytes) }} of {{ bytes(h.memoryTotalBytes) }} available }</div>
561
+ }
562
+ }
563
+ @case ('disk.usage') {
564
+ @if (disk(c); as d) {
565
+ <table class="jc-kv" data-testid="disk-result">
566
+ @for (f of fullestFirst(d, expanded().has(c.id)); track f.mountPoint) {
567
+ <tr [class.jc-bad]="low(f)">
568
+ <td class="jc-mono">{{ f.mountPoint }}</td><td>{{ f.format }}</td><td class="jc-nowrap">{{ bytes(f.availableBytes) }} free of {{ bytes(f.totalBytes) }}</td>
569
+ </tr>
570
+ } @empty { <tr><td class="jc-muted">No filesystems there.</td></tr> }
571
+ </table>
572
+ @if (d.filesystems.length > shown) {
573
+ <button mat-button type="button" [attr.data-testid]="'disk-toggle-' + c.id" (click)="toggle(c.id)">
574
+ {{ expanded().has(c.id) ? 'Show the fullest ' + shown : 'Show all ' + d.filesystems.length }}</button>
575
+ }
576
+ @if (d.truncated) { <div class="jc-muted">More filesystems than the agent reports at once.</div> }
577
+ }
578
+ }
579
+ @case ('tcp.reachability') {
580
+ @if (tcp(c); as t) {
581
+ @if (t.reachable) { <div>Reachable at {{ t.address }} in {{ t.elapsedMs }} ms</div> }
582
+ @else { <div class="jc-bad">Not reachable after {{ t.elapsedMs }} ms: {{ t.error }}</div> }
583
+ }
584
+ }
585
+ @case ('diagnostics.bundle') {
586
+ @if (bundle(c); as b) {
587
+ <div data-testid="bundle-result">{{ bytes(b.sizeBytes) }} zip: {{ b.entries.length }} files@if (b.redacted) { · {{ b.redacted }} {{ b.redacted === 1 ? 'value' : 'values' }} redacted }
588
+ <button mat-button type="button" [attr.data-testid]="'bundle-download-' + c.id" [disabled]="downloading() === b.bundleId" (click)="download(b)">Download</button>
589
+ </div>
590
+ @for (s of b.skipped; track s) { <div class="jc-muted">Left out: {{ s }}</div> }
591
+ @if (downloadErrors()[b.bundleId]; as e) { <div class="jc-error" [attr.data-testid]="'bundle-error-' + c.id">{{ e }}</div> }
592
+ }
593
+ }
594
+ @default {
595
+ @if (flat(c.result); as rows) {
596
+ <table class="jc-kv" data-testid="custom-result">@for (r of rows; track r[0]) { <tr><td>{{ r[0] }}</td><td class="jc-mono">{{ r[1] }}</td></tr> }</table>
597
+ } @else { <pre class="jc-mono" style="white-space: pre-wrap; margin: 0" data-testid="custom-result">{{ json(c.result) }}</pre> }
598
+ }
599
+ }
600
+ }
601
+ @if (waiting(c)) { <div class="jc-muted">{{ c.state === 'Pending' ? 'Waiting for the agent to call in' : 'Handed to the agent' }}, until {{ c.expiresAt | date: 'HH:mm:ss' }}</div> }
602
+ </td>
603
+ </tr>
604
+ } @empty { <tr><td colspan="5" class="jc-muted">Nothing asked yet.</td></tr> }
605
+ </tbody>
606
+ </table>
607
+ @if (nextCursor()) { <button mat-button type="button" data-testid="commands-older" (click)="loadOlder()">Older</button> }
608
+ </section>
609
+
610
+ @if (a.status === 'Active') {
611
+ <section class="jc-card">
612
+ <h2>Revoke</h2>
613
+ <p class="jc-muted jc-small">The agent stops at its next call: the platform refuses its certificate from then on, and commands still waiting are cancelled. It can't be undone; the host would enroll again with a new token.</p>
614
+ <form class="jc-form" (ngSubmit)="revoke()">
615
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Why</mat-label><input matInput name="reason" data-testid="revoke-reason" [(ngModel)]="reason" maxlength="500" (ngModelChange)="confirming.set(false)"></mat-form-field>
616
+ @if (confirming()) {
617
+ <button mat-flat-button color="warn" type="submit" data-testid="revoke-confirm" [disabled]="revoking()">Revoke {{ a.hostname }}</button>
618
+ <button mat-button type="button" (click)="confirming.set(false)">Cancel</button>
619
+ } @else {
620
+ <button mat-stroked-button type="submit" data-testid="revoke" [disabled]="!reason.trim()">Revoke</button>
621
+ }
622
+ @if (revokeError()) { <span class="jc-error" data-testid="revoke-error">{{ revokeError() }}</span> }
623
+ </form>
624
+ </section>
625
+ }
626
+ }`,
627
+ isInline: true,
628
+ dependencies: [
629
+ {
630
+ kind: "directive",
631
+ type: RouterLink,
632
+ selector: "[routerLink]",
633
+ inputs: [
634
+ "target",
635
+ "queryParams",
636
+ "fragment",
637
+ "queryParamsHandling",
638
+ "state",
639
+ "info",
640
+ "relativeTo",
641
+ "preserveFragment",
642
+ "skipLocationChange",
643
+ "replaceUrl",
644
+ "browserUrl",
645
+ "routerLink"
646
+ ]
647
+ },
648
+ {
649
+ kind: "ngmodule",
650
+ type: FormsModule
651
+ },
652
+ {
653
+ kind: "directive",
654
+ type: i1.ɵNgNoValidate,
655
+ selector: "form:not([ngNoForm]):not([ngNativeValidate])"
656
+ },
657
+ {
658
+ kind: "directive",
659
+ type: i1.DefaultValueAccessor,
660
+ selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
661
+ },
662
+ {
663
+ kind: "directive",
664
+ type: i1.NgControlStatus,
665
+ selector: "[formControlName],[ngModel],[formControl]"
666
+ },
667
+ {
668
+ kind: "directive",
669
+ type: i1.NgControlStatusGroup,
670
+ selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
671
+ },
672
+ {
673
+ kind: "directive",
674
+ type: i1.MaxLengthValidator,
675
+ selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]",
676
+ inputs: ["maxlength"]
677
+ },
678
+ {
679
+ kind: "directive",
680
+ type: i1.NgModel,
681
+ selector: "[ngModel]:not([formControlName]):not([formControl])",
682
+ inputs: [
683
+ "name",
684
+ "disabled",
685
+ "ngModel",
686
+ "ngModelOptions"
687
+ ],
688
+ outputs: ["ngModelChange"],
689
+ exportAs: ["ngModel"]
690
+ },
691
+ {
692
+ kind: "directive",
693
+ type: i1.NgForm,
694
+ selector: "form:not([ngNoForm]):not([formGroup]):not([formArray]),ng-form,[ngForm]",
695
+ inputs: ["ngFormOptions"],
696
+ outputs: ["ngSubmit"],
697
+ exportAs: ["ngForm"]
698
+ },
699
+ {
700
+ kind: "ngmodule",
701
+ type: MatButtonModule
702
+ },
703
+ {
704
+ kind: "component",
705
+ type: i2.MatButton,
706
+ selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ",
707
+ inputs: ["matButton"],
708
+ exportAs: ["matButton", "matAnchor"]
709
+ },
710
+ {
711
+ kind: "ngmodule",
712
+ type: MatCheckboxModule
713
+ },
714
+ {
715
+ kind: "component",
716
+ type: i3.MatCheckbox,
717
+ selector: "mat-checkbox",
718
+ inputs: [
719
+ "aria-label",
720
+ "aria-labelledby",
721
+ "aria-describedby",
722
+ "aria-expanded",
723
+ "aria-controls",
724
+ "aria-owns",
725
+ "id",
726
+ "required",
727
+ "labelPosition",
728
+ "name",
729
+ "value",
730
+ "disableRipple",
731
+ "tabIndex",
732
+ "color",
733
+ "disabledInteractive",
734
+ "checked",
735
+ "disabled",
736
+ "indeterminate"
737
+ ],
738
+ outputs: ["change", "indeterminateChange"],
739
+ exportAs: ["matCheckbox"]
740
+ },
741
+ {
742
+ kind: "ngmodule",
743
+ type: MatFormFieldModule
744
+ },
745
+ {
746
+ kind: "component",
747
+ type: i4.MatFormField,
748
+ selector: "mat-form-field",
749
+ inputs: [
750
+ "hideRequiredMarker",
751
+ "color",
752
+ "floatLabel",
753
+ "appearance",
754
+ "subscriptSizing",
755
+ "hintLabel"
756
+ ],
757
+ exportAs: ["matFormField"]
758
+ },
759
+ {
760
+ kind: "directive",
761
+ type: i4.MatLabel,
762
+ selector: "mat-label"
763
+ },
764
+ {
765
+ kind: "ngmodule",
766
+ type: MatInputModule
767
+ },
768
+ {
769
+ kind: "directive",
770
+ type: i5.MatInput,
771
+ selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]",
772
+ inputs: [
773
+ "disabled",
774
+ "id",
775
+ "placeholder",
776
+ "name",
777
+ "required",
778
+ "type",
779
+ "errorStateMatcher",
780
+ "aria-describedby",
781
+ "value",
782
+ "readonly",
783
+ "disabledInteractive"
784
+ ],
785
+ exportAs: ["matInput"]
786
+ },
787
+ {
788
+ kind: "ngmodule",
789
+ type: MatProgressBarModule
790
+ },
791
+ {
792
+ kind: "component",
793
+ type: i6.MatProgressBar,
794
+ selector: "mat-progress-bar",
795
+ inputs: [
796
+ "color",
797
+ "value",
798
+ "bufferValue",
799
+ "mode"
800
+ ],
801
+ outputs: ["animationEnd"],
802
+ exportAs: ["matProgressBar"]
803
+ },
804
+ {
805
+ kind: "ngmodule",
806
+ type: MatSelectModule
807
+ },
808
+ {
809
+ kind: "component",
810
+ type: i4.MatSelect,
811
+ selector: "mat-select",
812
+ inputs: [
813
+ "aria-describedby",
814
+ "panelClass",
815
+ "disabled",
816
+ "disableRipple",
817
+ "tabIndex",
818
+ "hideSingleSelectionIndicator",
819
+ "placeholder",
820
+ "required",
821
+ "multiple",
822
+ "disableOptionCentering",
823
+ "compareWith",
824
+ "value",
825
+ "aria-label",
826
+ "aria-labelledby",
827
+ "errorStateMatcher",
828
+ "typeaheadDebounceInterval",
829
+ "sortComparator",
830
+ "id",
831
+ "panelWidth",
832
+ "canSelectNullableOptions"
833
+ ],
834
+ outputs: [
835
+ "openedChange",
836
+ "opened",
837
+ "closed",
838
+ "selectionChange",
839
+ "valueChange"
840
+ ],
841
+ exportAs: ["matSelect"]
842
+ },
843
+ {
844
+ kind: "component",
845
+ type: i4.MatOption,
846
+ selector: "mat-option",
847
+ inputs: [
848
+ "value",
849
+ "id",
850
+ "disabled"
851
+ ],
852
+ outputs: ["onSelectionChange"],
853
+ exportAs: ["matOption"]
854
+ },
855
+ {
856
+ kind: "component",
857
+ type: ContextBar,
858
+ selector: "jc-context-bar"
859
+ },
860
+ {
861
+ kind: "pipe",
862
+ type: LinkPipe,
863
+ name: "jcLink"
864
+ },
865
+ {
866
+ kind: "pipe",
867
+ type: DatePipe,
868
+ name: "date"
869
+ },
870
+ {
871
+ kind: "pipe",
872
+ type: AgoPipe,
873
+ name: "ago"
874
+ },
875
+ {
876
+ kind: "pipe",
877
+ type: ReasonPipe,
878
+ name: "reason"
879
+ }
880
+ ],
881
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
882
+ });
883
+ };
884
+ i0.ɵɵngDeclareClassMetadata({
885
+ minVersion: "12.0.0",
886
+ version: "22.2.4",
887
+ ngImport: i0,
888
+ type: AgentPage,
889
+ decorators: [{
890
+ type: Component,
891
+ args: [{
892
+ changeDetection: ChangeDetectionStrategy.OnPush,
893
+ imports: [
894
+ LinkPipe,
895
+ RouterLink,
896
+ DatePipe,
897
+ FormsModule,
898
+ MatButtonModule,
899
+ MatCheckboxModule,
900
+ MatFormFieldModule,
901
+ MatInputModule,
902
+ MatProgressBarModule,
903
+ MatSelectModule,
904
+ ContextBar,
905
+ AgoPipe,
906
+ ReasonPipe
907
+ ],
908
+ template: `
909
+ <jc-context-bar>
910
+ <a [routerLink]="['agents'] | jcLink" [queryParams]="ctx.keep()" class="jc-crumb">Agents</a><span class="jc-crumb-sep">›</span>
911
+ <h1>{{ agent.value()?.hostname ?? '…' }}</h1>
912
+ </jc-context-bar>
913
+ @if (agent.isLoading() && !agent.value()) { <mat-progress-bar mode="indeterminate" /> }
914
+ @if (agent.error()) { <p class="jc-error">{{ error() }}</p> }
915
+ @if (agent.value(); as a) {
916
+ <div class="jc-summary" data-testid="agent-summary">
917
+ <span class="jc-badge" data-testid="agent-state" [class.jc-health-healthy]="a.online" [class.jc-health-offline]="!a.online && a.status === 'Active'" [class.jc-health-none]="a.status !== 'Active'">
918
+ {{ a.status !== 'Active' ? a.status : a.online ? 'Online' : 'Not calling in' }}</span>
919
+ <span>{{ a.operatingSystem }}</span>
920
+ <span>version <span class="jc-mono" data-testid="agent-version">{{ a.version }}</span></span>
921
+ <span class="jc-muted">last seen {{ a.lastSeenAt | ago }}</span>
922
+ @if (a.resourceId) { <a [routerLink]="['resources', a.resourceId] | jcLink" [queryParams]="ctx.keep()">Host resource</a> }
923
+ </div>
924
+ <p class="jc-muted jc-small">Enrolled {{ a.enrolledAt | date: 'MMM d, y, HH:mm' }} by {{ a.enrolledBy }}. Certificate valid until {{ a.certificateNotAfter | date: 'MMM d, HH:mm' }}; the agent renews it when a third is left.</p>
925
+ @if (a.status !== 'Active') {
926
+ <p class="jc-notice" data-testid="agent-revoked">Revoked {{ a.revokedAt | date: 'MMM d, y, HH:mm' }} by {{ a.revokedBy }}: {{ a.revokeReason }}. The platform refuses its certificate for good.</p>
927
+ @if (successor(); as s) {
928
+ <p data-testid="agent-successor">{{ a.hostname }} enrolled again {{ s.enrolledAt | date: 'MMM d, HH:mm' }} as <a [routerLink]="['agents', s.id] | jcLink" [queryParams]="ctx.keep()">a new agent</a>.</p>
929
+ } @else {
930
+ <section class="jc-card" data-testid="reenroll">
931
+ <h2>Bring this host back</h2>
932
+ <p class="jc-muted jc-small">The host comes back as a new agent, with a new key: this one stays revoked, with its history. It needs a new token from an admin, put on the host.</p>
933
+ <button mat-flat-button type="button" data-testid="reenroll-create" [disabled]="creating()" (click)="reenroll(a.hostname)">Create a token for {{ a.hostname }}</button>
934
+ @if (reenrollError()) { <span class="jc-error" data-testid="reenroll-error"> {{ reenrollError() }}</span> }
935
+ @if (token(); as t) {
936
+ <div class="jc-notice" data-testid="reenroll-token">
937
+ <p>Replace the token in the agent's token file (<span class="jc-mono">Agent:EnrollmentTokenFile</span>) with this one. It works once, until {{ t.expiresAt | date: 'MMM d, HH:mm' }}, and <strong>won't be shown again</strong>.</p>
938
+ <p class="jc-row"><span class="jc-mono" data-testid="reenroll-token-value">{{ t.token }}</span>
939
+ <button mat-button type="button" (click)="copy(t.token)">{{ copied() === 'copied' ? 'Copied' : copied() === 'selected' ? 'Selected: press Ctrl+C' : 'Copy' }}</button></p>
940
+ <p>The agent notices it within seconds, sets its old identity aside and enrolls again: nothing else on the host changes. An agent from before 9 November doesn't: clear its data directory's identity files and restart it.</p>
941
+ </div>
942
+ }
943
+ </section>
944
+ }
945
+ } @else {
946
+ <section class="jc-card">
947
+ <h2>Ask the agent</h2>
948
+ <form class="jc-form" data-testid="command-form" (ngSubmit)="issue()">
949
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Action</mat-label>
950
+ <mat-select name="action" data-testid="command-action" [ngModel]="action()" (ngModelChange)="choose($event)">
951
+ @for (o of actionList(); track o.name) {
952
+ <mat-option [value]="o.name" [disabled]="o.permitted === false" [attr.data-testid]="'action-' + o.name">
953
+ {{ label(o.name) }}@if (o.custom) { <span class="jc-muted"> · custom</span> }@if (o.permitted === false) { <span class="jc-muted"> · not allowed on this host</span> }
954
+ </mat-option>
955
+ }
956
+ </mat-select>
957
+ </mat-form-field>
958
+ @if (action() === 'agent.update') {
959
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-md"><mat-label>Version</mat-label>
960
+ <mat-select name="version" data-testid="command-version" [(ngModel)]="version">
961
+ @for (p of packages.value()?.items ?? []; track p.version) { <mat-option [value]="p.version">{{ p.version }}</mat-option> }
962
+ </mat-select>
963
+ </mat-form-field>
964
+ @if (packages.value()?.items?.length === 0) { <span class="jc-muted jc-small">No signed packages are offered: see Agents:PackageDirectory.</span> }
965
+ } @else {
966
+ @for (p of selected()?.parameters ?? []; track p.name) {
967
+ @if (p.type === 'boolean') {
968
+ <mat-checkbox [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [ngModel]="values()[p.name] === true" (ngModelChange)="set(p.name, $event)">{{ title(p) }}</mat-checkbox>
969
+ } @else if (p.allowed?.length) {
970
+ <mat-form-field subscriptSizing="dynamic" [class.jc-field-md]="p.type !== 'string'" [class.jc-field-wide]="p.type === 'string'"><mat-label>{{ title(p) }}</mat-label>
971
+ <mat-select [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [ngModel]="values()[p.name] ?? ''" (ngModelChange)="set(p.name, $event)">
972
+ @if (!p.required) { <mat-option value="">Any</mat-option> }
973
+ @for (v of p.allowed; track v) { <mat-option [value]="v">{{ v }}</mat-option> }
974
+ </mat-select>
975
+ </mat-form-field>
976
+ } @else {
977
+ <mat-form-field subscriptSizing="dynamic" [class.jc-field-sm]="p.type === 'integer'" [class.jc-field-wide]="p.type === 'string'"><mat-label>{{ title(p) }}</mat-label>
978
+ <input matInput [type]="p.type === 'integer' ? 'number' : 'text'" [name]="p.name" [attr.data-testid]="'command-param-' + p.name" [attr.min]="p.minimum" [attr.max]="p.maximum"
979
+ [attr.maxlength]="p.maxLength" [placeholder]="p.description ?? ''" [ngModel]="values()[p.name] ?? ''" (ngModelChange)="set(p.name, $event)">
980
+ </mat-form-field>
981
+ }
982
+ }
983
+ }
984
+ @if (needsApproval()) {
985
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Why (for whoever approves it)</mat-label>
986
+ <input matInput name="requestReason" data-testid="request-reason" maxlength="500" [(ngModel)]="requestReason">
987
+ </mat-form-field>
988
+ @if (selected()?.changing && agent.value()?.resourceId) {
989
+ <mat-checkbox name="watchHost" data-testid="request-watch-host" [(ngModel)]="watchHost">Fix this host's health: run only while it's unhealthy, and confirm recovery after</mat-checkbox>
990
+ }
991
+ }
992
+ <div class="jc-form-actions">
993
+ <button mat-flat-button type="submit" data-testid="command-issue" [disabled]="issuing() || selected()?.permitted === false">{{ needsApproval() ? 'Request' : action() === 'agent.update' ? 'Update' : 'Run' }}</button>
994
+ @if (issueError()) { <span class="jc-error" data-testid="command-error">{{ issueError() }}</span> }
995
+ @if (issued()) { <span class="jc-muted" data-testid="command-issued">{{ issued() }}</span> }
996
+ </div>
997
+ @if (selected(); as s) {
998
+ <div class="jc-muted jc-small jc-form-actions" data-testid="command-hint">
999
+ <div>{{ s.description }} <span data-testid="command-approval">{{ s.risk }} risk: {{ approvalText(s.approval) }}.</span></div>
1000
+ @if (s.limits.length) { <div data-testid="command-limits">On this host: {{ s.limits.join('; ') }}.</div> }
1001
+ </div>
1002
+ }
1003
+ </form>
1004
+ @if (actions.value(); as list) {
1005
+ @if (!list.reportedAt) {
1006
+ <p class="jc-notice" data-testid="actions-not-reported">This agent doesn't report what its host allows (it's older than this platform): the list shows the built-in actions, and one its host doesn't permit comes back <strong>Rejected</strong>.</p>
1007
+ } @else {
1008
+ <p class="jc-muted jc-small">As the agent reported {{ list.reportedAt | ago }}, when it started. Its host still checks every command.</p>
1009
+ }
1010
+ }
1011
+ </section>
1012
+ }
1013
+
1014
+ @if (requestList().length) {
1015
+ <section class="jc-card" data-testid="requests">
1016
+ <h2>Requests</h2>
1017
+ <table class="jc-table">
1018
+ <thead><tr><th>Asked</th><th>Action</th><th>By, and why</th><th>State</th><th>Decided</th><th></th></tr></thead>
1019
+ <tbody>
1020
+ @for (r of requestList(); track r.id) {
1021
+ <tr [attr.data-testid]="'request-' + r.id">
1022
+ <td class="jc-nowrap">{{ r.requestedAt | date: 'MMM d, HH:mm:ss' }}</td>
1023
+ <td><strong>{{ r.action }}</strong><div class="jc-muted jc-small">{{ r.risk }} risk</div></td>
1024
+ <td>{{ r.requestedBy }}<div class="jc-small">{{ r.reason }}</div></td>
1025
+ <td class="jc-nowrap"><span class="jc-badge" [class.jc-health-degraded]="r.state === 'Pending'" [class.jc-health-healthy]="r.state === 'Issued'"
1026
+ [class.jc-health-none]="r.state !== 'Pending' && r.state !== 'Issued'" data-testid="request-state">{{ r.state === 'Pending' ? 'Waiting for approval' : r.state }}</span>
1027
+ @if (r.state === 'Pending') { <div class="jc-muted jc-small">until {{ r.expiresAt | date: 'HH:mm' }}</div> }
1028
+ @if (r.verification && r.verification !== 'None') {
1029
+ <div class="jc-small" data-testid="request-verification" [class.jc-error]="r.verification === 'NotVerified'" [title]="r.verificationNote ?? ''">{{ verificationText(r.verification) }}</div>
1030
+ }</td>
1031
+ <td class="jc-small">@if (r.decidedBy) { {{ r.decidedBy }}, {{ r.decidedAt | date: 'HH:mm' }} }@if (r.comment) { <div>{{ r.comment }}</div> }</td>
1032
+ <td class="jc-row-actions">@if (r.state === 'Pending') { <button mat-button type="button" [attr.data-testid]="'request-cancel-' + r.id" (click)="cancelRequest(r.id)">Cancel</button> }</td>
1033
+ </tr>
1034
+ }
1035
+ </tbody>
1036
+ </table>
1037
+ </section>
1038
+ }
1039
+
1040
+ <section class="jc-card" data-testid="commands">
1041
+ <h2>Commands</h2>
1042
+ @if (commands.error()) { <p class="jc-error">{{ commandsError() }}</p> }
1043
+ <table class="jc-table">
1044
+ <thead><tr><th>Issued</th><th>Action</th><th>By</th><th>State</th><th>Answer</th></tr></thead>
1045
+ <tbody>
1046
+ @for (c of allCommands(); track c.id) {
1047
+ <tr [attr.data-testid]="'command-' + c.id">
1048
+ <td class="jc-nowrap">{{ c.issuedAt | date: 'MMM d, HH:mm:ss' }}</td>
1049
+ <td><strong>{{ c.action }}</strong>@if (describe(c); as d) { <div class="jc-small jc-mono">{{ d }}</div> }</td>
1050
+ <td>{{ c.issuedBy }}</td>
1051
+ <td class="jc-nowrap">
1052
+ <span class="jc-badge" [class.jc-health-healthy]="c.state === 'Succeeded'" [class.jc-health-unhealthy]="c.state === 'Failed' || c.state === 'Rejected'"
1053
+ [class.jc-health-degraded]="waiting(c)" [class.jc-health-none]="c.state === 'Expired' || c.state === 'Cancelled'" data-testid="command-state">{{ c.state }}</span>
1054
+ @if (c.durationMs !== null) { <div class="jc-muted jc-small">{{ c.durationMs }} ms</div> }
1055
+ </td>
1056
+ <td class="jc-small" data-testid="command-answer">
1057
+ @if (c.reason) { <div [class.jc-bad]="c.state !== 'Succeeded'">{{ c.reason | reason }}</div> }
1058
+ @if (c.state === 'Succeeded' && c.result) {
1059
+ @switch (c.action) {
1060
+ @case ('host.summary') {
1061
+ @if (summary(c); as h) {
1062
+ <div>{{ h.hostname }} · {{ h.operatingSystem }} {{ h.architecture }} · up {{ uptime(h.uptimeSeconds) }}</div>
1063
+ <div>{{ h.processorCount }} CPUs@if (h.loadAverage) { · load {{ h.loadAverage.join(' ') }} }@if (h.memoryTotalBytes) { · memory {{ bytes(h.memoryAvailableBytes) }} of {{ bytes(h.memoryTotalBytes) }} available }</div>
1064
+ }
1065
+ }
1066
+ @case ('disk.usage') {
1067
+ @if (disk(c); as d) {
1068
+ <table class="jc-kv" data-testid="disk-result">
1069
+ @for (f of fullestFirst(d, expanded().has(c.id)); track f.mountPoint) {
1070
+ <tr [class.jc-bad]="low(f)">
1071
+ <td class="jc-mono">{{ f.mountPoint }}</td><td>{{ f.format }}</td><td class="jc-nowrap">{{ bytes(f.availableBytes) }} free of {{ bytes(f.totalBytes) }}</td>
1072
+ </tr>
1073
+ } @empty { <tr><td class="jc-muted">No filesystems there.</td></tr> }
1074
+ </table>
1075
+ @if (d.filesystems.length > shown) {
1076
+ <button mat-button type="button" [attr.data-testid]="'disk-toggle-' + c.id" (click)="toggle(c.id)">
1077
+ {{ expanded().has(c.id) ? 'Show the fullest ' + shown : 'Show all ' + d.filesystems.length }}</button>
1078
+ }
1079
+ @if (d.truncated) { <div class="jc-muted">More filesystems than the agent reports at once.</div> }
1080
+ }
1081
+ }
1082
+ @case ('tcp.reachability') {
1083
+ @if (tcp(c); as t) {
1084
+ @if (t.reachable) { <div>Reachable at {{ t.address }} in {{ t.elapsedMs }} ms</div> }
1085
+ @else { <div class="jc-bad">Not reachable after {{ t.elapsedMs }} ms: {{ t.error }}</div> }
1086
+ }
1087
+ }
1088
+ @case ('diagnostics.bundle') {
1089
+ @if (bundle(c); as b) {
1090
+ <div data-testid="bundle-result">{{ bytes(b.sizeBytes) }} zip: {{ b.entries.length }} files@if (b.redacted) { · {{ b.redacted }} {{ b.redacted === 1 ? 'value' : 'values' }} redacted }
1091
+ <button mat-button type="button" [attr.data-testid]="'bundle-download-' + c.id" [disabled]="downloading() === b.bundleId" (click)="download(b)">Download</button>
1092
+ </div>
1093
+ @for (s of b.skipped; track s) { <div class="jc-muted">Left out: {{ s }}</div> }
1094
+ @if (downloadErrors()[b.bundleId]; as e) { <div class="jc-error" [attr.data-testid]="'bundle-error-' + c.id">{{ e }}</div> }
1095
+ }
1096
+ }
1097
+ @default {
1098
+ @if (flat(c.result); as rows) {
1099
+ <table class="jc-kv" data-testid="custom-result">@for (r of rows; track r[0]) { <tr><td>{{ r[0] }}</td><td class="jc-mono">{{ r[1] }}</td></tr> }</table>
1100
+ } @else { <pre class="jc-mono" style="white-space: pre-wrap; margin: 0" data-testid="custom-result">{{ json(c.result) }}</pre> }
1101
+ }
1102
+ }
1103
+ }
1104
+ @if (waiting(c)) { <div class="jc-muted">{{ c.state === 'Pending' ? 'Waiting for the agent to call in' : 'Handed to the agent' }}, until {{ c.expiresAt | date: 'HH:mm:ss' }}</div> }
1105
+ </td>
1106
+ </tr>
1107
+ } @empty { <tr><td colspan="5" class="jc-muted">Nothing asked yet.</td></tr> }
1108
+ </tbody>
1109
+ </table>
1110
+ @if (nextCursor()) { <button mat-button type="button" data-testid="commands-older" (click)="loadOlder()">Older</button> }
1111
+ </section>
1112
+
1113
+ @if (a.status === 'Active') {
1114
+ <section class="jc-card">
1115
+ <h2>Revoke</h2>
1116
+ <p class="jc-muted jc-small">The agent stops at its next call: the platform refuses its certificate from then on, and commands still waiting are cancelled. It can't be undone; the host would enroll again with a new token.</p>
1117
+ <form class="jc-form" (ngSubmit)="revoke()">
1118
+ <mat-form-field subscriptSizing="dynamic" class="jc-field-wide"><mat-label>Why</mat-label><input matInput name="reason" data-testid="revoke-reason" [(ngModel)]="reason" maxlength="500" (ngModelChange)="confirming.set(false)"></mat-form-field>
1119
+ @if (confirming()) {
1120
+ <button mat-flat-button color="warn" type="submit" data-testid="revoke-confirm" [disabled]="revoking()">Revoke {{ a.hostname }}</button>
1121
+ <button mat-button type="button" (click)="confirming.set(false)">Cancel</button>
1122
+ } @else {
1123
+ <button mat-stroked-button type="submit" data-testid="revoke" [disabled]="!reason.trim()">Revoke</button>
1124
+ }
1125
+ @if (revokeError()) { <span class="jc-error" data-testid="revoke-error">{{ revokeError() }}</span> }
1126
+ </form>
1127
+ </section>
1128
+ }
1129
+ }`
1130
+ }]
1131
+ }],
1132
+ ctorParameters: () => [],
1133
+ propDecorators: { id: [{
1134
+ type: i0.Input,
1135
+ args: [{
1136
+ isSignal: true,
1137
+ alias: "id",
1138
+ required: true
1139
+ }]
1140
+ }] }
1141
+ });
1142
+ export { AgentPage };
1143
+
1144
+ //# sourceMappingURL=juice-js-observability-agent.page-Vb7LDThl.mjs.map