@tsplc/tmp-agent 0.0.0-stage → 0.6.3

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 (65) hide show
  1. package/README.md +26 -2
  2. package/dist/cli.js +4888 -0
  3. package/dist/cli.js.map +53 -0
  4. package/dist/client.js +514 -0
  5. package/dist/client.js.map +12 -0
  6. package/dist/index.js +3680 -0
  7. package/dist/index.js.map +41 -0
  8. package/package.json +61 -4
  9. package/src/access.ts +260 -0
  10. package/src/agent.ts +461 -0
  11. package/src/audit.ts +74 -0
  12. package/src/cli.ts +290 -0
  13. package/src/client.ts +407 -0
  14. package/src/codesys.ts +195 -0
  15. package/src/dashboard/index.ts +159 -0
  16. package/src/dashboard/ui/access.ts +191 -0
  17. package/src/dashboard/ui/actions.ts +207 -0
  18. package/src/dashboard/ui/api.ts +138 -0
  19. package/src/dashboard/ui/app.ts +41 -0
  20. package/src/dashboard/ui/approval.ts +131 -0
  21. package/src/dashboard/ui/audit.ts +115 -0
  22. package/src/dashboard/ui/contract.ts +19 -0
  23. package/src/dashboard/ui/dashboard.css +1332 -0
  24. package/src/dashboard/ui/deployment.ts +431 -0
  25. package/src/dashboard/ui/deployments.ts +319 -0
  26. package/src/dashboard/ui/details.ts +214 -0
  27. package/src/dashboard/ui/dom.ts +87 -0
  28. package/src/dashboard/ui/environment.ts +345 -0
  29. package/src/dashboard/ui/format.ts +124 -0
  30. package/src/dashboard/ui/logs.ts +126 -0
  31. package/src/dashboard/ui/main.ts +88 -0
  32. package/src/dashboard/ui/overlay.ts +144 -0
  33. package/src/dashboard/ui/shell.ts +185 -0
  34. package/src/dashboard/ui/source.ts +144 -0
  35. package/src/debugging.ts +142 -0
  36. package/src/deploy.ts +203 -0
  37. package/src/deployments/health.ts +98 -0
  38. package/src/deployments/retention.ts +44 -0
  39. package/src/deployments/routes.ts +281 -0
  40. package/src/deployments/runner.ts +900 -0
  41. package/src/deployments/store.ts +209 -0
  42. package/src/deployments/submission.ts +78 -0
  43. package/src/discovery.ts +90 -0
  44. package/src/environment.ts +214 -0
  45. package/src/errors.ts +12 -0
  46. package/src/index.ts +36 -0
  47. package/src/instance.ts +51 -0
  48. package/src/login.ts +267 -0
  49. package/src/logs.ts +115 -0
  50. package/src/maintenance.ts +303 -0
  51. package/src/operations.ts +149 -0
  52. package/src/processes.ts +41 -0
  53. package/src/protocol.ts +557 -0
  54. package/src/releases.ts +414 -0
  55. package/src/restarts.ts +96 -0
  56. package/src/routes.ts +128 -0
  57. package/src/secrets.ts +174 -0
  58. package/src/server-process.ts +264 -0
  59. package/src/service.ts +194 -0
  60. package/src/sessions.ts +58 -0
  61. package/src/state.ts +126 -0
  62. package/src/tailscale.ts +112 -0
  63. package/src/terminal.ts +57 -0
  64. package/src/transfer.ts +94 -0
  65. package/src/upgrade.ts +153 -0
@@ -0,0 +1,207 @@
1
+ import type { DeploymentMode, DeploymentRecord } from "../../protocol";
2
+ import { api } from "./api";
3
+ import { type App, attempt, deploymentHref } from "./app";
4
+ import { h } from "./dom";
5
+ import { cancelable, isFinished, shortId, shortRelease } from "./format";
6
+ import { confirm, dialog, type MenuItem, toast } from "./overlay";
7
+
8
+ /**
9
+ * Resets the controller's application, warm or cold as chosen, and starts it again: CODESYS's
10
+ * "Reset warm" or "Reset cold" then "Start", for clearing a state the application got stuck in.
11
+ */
12
+ export const restartController = async (
13
+ /** Told when the restart is sent and when the agent has answered. */
14
+ running: (busy: boolean) => void,
15
+ ) => {
16
+ const reset = await dialog<"warm" | "cold" | null>({
17
+ title: "Reset and start the application?",
18
+ body: [
19
+ h(
20
+ "p",
21
+ {},
22
+ "The application stops, its variables go back to their initial values, and it starts again with the same code. The line stops for a moment.",
23
+ ),
24
+ h(
25
+ "p",
26
+ { class: "muted" },
27
+ "A warm reset keeps retain variables; a cold reset resets them too.",
28
+ ),
29
+ ],
30
+ actions: (close) => [
31
+ h("button", { class: "button", onclick: () => close(null) }, "Cancel"),
32
+ h(
33
+ "button",
34
+ { class: "button danger", onclick: () => close("cold") },
35
+ "Reset cold and start",
36
+ ),
37
+ h(
38
+ "button",
39
+ { class: "button primary", onclick: () => close("warm") },
40
+ "Reset warm and start",
41
+ ),
42
+ ],
43
+ });
44
+ if (!reset) {
45
+ return;
46
+ }
47
+ running(true);
48
+ try {
49
+ await attempt(() => api.restartController({ reset }), {
50
+ done: `Reset ${reset}; the application runs again`,
51
+ });
52
+ } finally {
53
+ running(false);
54
+ }
55
+ };
56
+
57
+ /** Deploys a deployment's release again, applied at once or reviewed first, then opens the new one. */
58
+ export const redeploy = async (app: App, record: DeploymentRecord) => {
59
+ const mode = await dialog<DeploymentMode>({
60
+ title: "Redeploy",
61
+ body: [
62
+ h(
63
+ "p",
64
+ {},
65
+ "Deploy the release of ",
66
+ h("code", {}, shortId(record.id)),
67
+ " again as a new deployment.",
68
+ ),
69
+ h(
70
+ "p",
71
+ { class: "muted" },
72
+ "Apply runs it as soon as it is its turn. Review checks what an online change would do first, and waits for someone to approve it.",
73
+ ),
74
+ ],
75
+ actions: (close) => [
76
+ h(
77
+ "button",
78
+ { class: "button", onclick: () => close("review") },
79
+ "Review first",
80
+ ),
81
+ h(
82
+ "button",
83
+ { class: "button primary", onclick: () => close("apply") },
84
+ "Redeploy",
85
+ ),
86
+ ],
87
+ });
88
+ if (!mode) {
89
+ return;
90
+ }
91
+ const created = await attempt(() => api.redeploy(record.id, mode), {
92
+ done: null,
93
+ });
94
+ if (created) {
95
+ app.navigate(deploymentHref(created.id));
96
+ }
97
+ };
98
+
99
+ /** Deploys a deployment's release again as an online change, after a confirmation, then opens the new one. */
100
+ export const rollback = async (app: App, record: DeploymentRecord) => {
101
+ const confirmed = await confirm({
102
+ title: "Roll back to this deployment?",
103
+ body: [
104
+ h(
105
+ "p",
106
+ {},
107
+ "A new deployment applies the release of ",
108
+ h("code", {}, shortId(record.id)),
109
+ ` (${shortRelease(record.release)}) to the controller as an online change, and starts its server.`,
110
+ ),
111
+ h(
112
+ "p",
113
+ { class: "muted" },
114
+ "If an online change can't apply it, the deployment waits for approval of a full download rather than stopping the line by itself.",
115
+ ),
116
+ ],
117
+ confirm: "Roll back",
118
+ tone: "primary",
119
+ });
120
+ if (!confirmed) {
121
+ return;
122
+ }
123
+ const created = await attempt(() => api.rollback(record.id), {
124
+ done: null,
125
+ });
126
+ if (created) {
127
+ app.navigate(deploymentHref(created.id));
128
+ }
129
+ };
130
+
131
+ export const cancel = async (record: DeploymentRecord) => {
132
+ const confirmed = await confirm({
133
+ title: "Cancel this deployment?",
134
+ body: [
135
+ h(
136
+ "p",
137
+ {},
138
+ "The controller is left as it is; nothing of this deployment is applied.",
139
+ ),
140
+ ],
141
+ confirm: "Cancel deployment",
142
+ tone: "danger",
143
+ });
144
+ if (confirmed) {
145
+ await attempt(() => api.cancel(record.id), { done: "Deployment canceled" });
146
+ }
147
+ };
148
+
149
+ /**
150
+ * Which of a deployment's actions the agent takes now, as its runner decides: cancel before it
151
+ * applies, redeploy once it finished, and roll back to one that ran healthy but doesn't run now.
152
+ */
153
+ export const deploymentActions = (
154
+ record: DeploymentRecord,
155
+ { current }: { current: boolean },
156
+ ) => ({
157
+ cancel: cancelable(record.state),
158
+ redeploy: isFinished(record.state),
159
+ rollback: record.state === "ready" && !current,
160
+ });
161
+
162
+ /** A deployment's actions, as a menu offers them: only the ones the signed-in role may take. */
163
+ export const deploymentMenu = (
164
+ app: App,
165
+ record: DeploymentRecord,
166
+ { current, open }: { current: boolean; open: boolean },
167
+ ): MenuItem[] => {
168
+ const deployer = app.can("deployer");
169
+ const allowed = deploymentActions(record, { current });
170
+ const items: MenuItem[] = [];
171
+ if (open) {
172
+ items.push({
173
+ label: "Open",
174
+ run: () => app.navigate(deploymentHref(record.id)),
175
+ });
176
+ }
177
+ if (deployer) {
178
+ items.push(
179
+ {
180
+ label: "Redeploy…",
181
+ run: () => void redeploy(app, record),
182
+ disabled: !allowed.redeploy,
183
+ },
184
+ {
185
+ label: "Rollback to this…",
186
+ run: () => void rollback(app, record),
187
+ disabled: !allowed.rollback,
188
+ },
189
+ );
190
+ if (allowed.cancel) {
191
+ items.push({
192
+ label: "Cancel…",
193
+ run: () => void cancel(record),
194
+ tone: "danger",
195
+ });
196
+ }
197
+ }
198
+ items.push("separator", {
199
+ label: "Copy id",
200
+ run: () =>
201
+ void navigator.clipboard.writeText(record.id).then(
202
+ () => toast("Copied the deployment id", "ok"),
203
+ () => toast("The browser refused the clipboard", "error"),
204
+ ),
205
+ });
206
+ return items;
207
+ };
@@ -0,0 +1,138 @@
1
+ import {
2
+ type ControllerRestart,
3
+ controllerRestartPath,
4
+ type controllerRestartReplySchema,
5
+ refusalMessage,
6
+ } from "@tsplc/server/plant-agent";
7
+ import type { z } from "zod";
8
+ import type {
9
+ AccessConfig,
10
+ AgentStatus,
11
+ Audit,
12
+ DeploymentLogLine,
13
+ DeploymentMode,
14
+ DeploymentRecord,
15
+ deploymentCreatedSchema,
16
+ deploymentListSchema,
17
+ deploymentSourceSchema,
18
+ EnvironmentListing,
19
+ EnvironmentValue,
20
+ Identity,
21
+ } from "../../protocol";
22
+ import { contract } from "./contract";
23
+ import { encodePath } from "./format";
24
+
25
+ export type DeploymentList = z.infer<typeof deploymentListSchema>;
26
+ type DeploymentCreated = z.infer<typeof deploymentCreatedSchema>;
27
+
28
+ export type SourceFile = z.infer<
29
+ typeof deploymentSourceSchema
30
+ >["files"][number];
31
+
32
+ /** A refused or failed request, with the agent's message. */
33
+ export class ApiError extends Error {
34
+ constructor(
35
+ readonly status: number,
36
+ message: string,
37
+ ) {
38
+ super(message);
39
+ }
40
+ }
41
+
42
+ const failure = async (response: Response) =>
43
+ new ApiError(response.status, await refusalMessage(response));
44
+
45
+ let version: string | null = null;
46
+
47
+ /** The tsPLC version of the agent, as its last answer named it. */
48
+ export const agentVersion = () => version;
49
+
50
+ /** Sends `json` as the body, if given. */
51
+ const call = async (
52
+ method: "GET" | "POST" | "PUT" | "DELETE",
53
+ path: string,
54
+ json?: unknown,
55
+ ) => {
56
+ const response = await fetch(path, {
57
+ method,
58
+ credentials: "same-origin",
59
+ // A signed-in browser must mark what it changes, so another site can't make it send one.
60
+ headers: {
61
+ ...(method !== "GET" && { [contract.dashboardHeader]: "1" }),
62
+ ...(json !== undefined && { "Content-Type": "application/json" }),
63
+ },
64
+ body: json === undefined ? null : JSON.stringify(json),
65
+ });
66
+ version = response.headers.get(contract.agentVersionHeader) ?? version;
67
+ if (!response.ok) {
68
+ throw await failure(response);
69
+ }
70
+ return response;
71
+ };
72
+
73
+ const get = async (path: string) => (await call("GET", path)).json();
74
+ /** A change's answer, which some routes leave empty. */
75
+ const send = async (
76
+ method: "POST" | "PUT" | "DELETE",
77
+ path: string,
78
+ json?: unknown,
79
+ ) => {
80
+ const text = await (await call(method, path, json)).text();
81
+ return text ? JSON.parse(text) : null;
82
+ };
83
+
84
+ const deploymentPath = (id: string) =>
85
+ `${contract.deploymentsApiPath}/${encodeURIComponent(id)}`;
86
+
87
+ export const api = {
88
+ session: (): Promise<Identity> => get("/api/session"),
89
+ signIn: (token: string): Promise<unknown> =>
90
+ send("POST", "/api/session", { token }),
91
+ signOut: (): Promise<unknown> => send("DELETE", "/api/session"),
92
+ status: (): Promise<AgentStatus> => get(contract.statusPath),
93
+
94
+ deployments: (): Promise<DeploymentList> => get(contract.deploymentsApiPath),
95
+ deployment: (id: string): Promise<DeploymentRecord> =>
96
+ get(deploymentPath(id)),
97
+ logs: async (id: string, after: number): Promise<DeploymentLogLine[]> =>
98
+ (await get(`${deploymentPath(id)}/logs?after=${after}`)).lines,
99
+ approve: (
100
+ id: string,
101
+ approval: { download: boolean },
102
+ ): Promise<DeploymentRecord> =>
103
+ send("POST", `${deploymentPath(id)}/approve`, approval),
104
+ cancel: (id: string): Promise<DeploymentRecord> =>
105
+ send("POST", `${deploymentPath(id)}/cancel`),
106
+ redeploy: (id: string, mode: DeploymentMode): Promise<DeploymentCreated> =>
107
+ send("POST", `${deploymentPath(id)}/redeploy`, { mode }),
108
+ rollback: (id: string): Promise<DeploymentCreated> =>
109
+ send("POST", `${deploymentPath(id)}/rollback`),
110
+ source: async (id: string): Promise<SourceFile[]> =>
111
+ (await get(`${deploymentPath(id)}/source`)).files,
112
+ sourceFile: async (id: string, path: string) =>
113
+ (
114
+ await call("GET", `${deploymentPath(id)}/source/${encodePath(path)}`)
115
+ ).text(),
116
+ /** The URL of a deployment's live events, from the log line after `after`. */
117
+ eventsUrl: (id: string, after: number) =>
118
+ `${deploymentPath(id)}/events?after=${after}`,
119
+
120
+ environment: (): Promise<EnvironmentListing> => get("/api/environment"),
121
+ setEnvironment: (
122
+ name: string,
123
+ change: EnvironmentValue,
124
+ ): Promise<EnvironmentListing> =>
125
+ send("PUT", `/api/environment/${encodeURIComponent(name)}`, change),
126
+ deleteEnvironment: (name: string): Promise<EnvironmentListing> =>
127
+ send("DELETE", `/api/environment/${encodeURIComponent(name)}`),
128
+ restartServer: (): Promise<unknown> => send("POST", "/api/server/restart"),
129
+ restartController: (
130
+ restart: ControllerRestart,
131
+ ): Promise<z.infer<typeof controllerRestartReplySchema>> =>
132
+ send("POST", controllerRestartPath, restart),
133
+
134
+ audit: (limit: number): Promise<Audit[]> => get(`/api/audit?limit=${limit}`),
135
+ access: (): Promise<AccessConfig> => get("/api/access"),
136
+ saveAccess: (access: AccessConfig): Promise<AccessConfig> =>
137
+ send("PUT", "/api/access", access),
138
+ };
@@ -0,0 +1,41 @@
1
+ import { errorMessage } from "../../errors";
2
+ import type { Identity, Role } from "../../protocol";
3
+ import { allows, contract } from "./contract";
4
+ import { toast } from "./overlay";
5
+
6
+ /** What every page is given: who is signed in, and how to move between pages. */
7
+ export interface App {
8
+ identity: Identity;
9
+ /** Whether the signed-in role includes `required`. */
10
+ can(required: Role): boolean;
11
+ navigate(path: string): void;
12
+ }
13
+
14
+ export const createApp = (
15
+ identity: Identity,
16
+ navigate: (path: string) => void,
17
+ ): App => ({
18
+ identity,
19
+ can: (required) => allows(identity.role, required),
20
+ navigate,
21
+ });
22
+
23
+ /** Runs a change, telling the user how it went: `done`, if any, on success, the agent's message on failure. */
24
+ export const attempt = async <T>(
25
+ run: () => Promise<T>,
26
+ { done }: { done: string | null },
27
+ ): Promise<T | null> => {
28
+ try {
29
+ const result = await run();
30
+ if (done) {
31
+ toast(done, "ok");
32
+ }
33
+ return result;
34
+ } catch (error) {
35
+ toast(errorMessage(error), "error");
36
+ return null;
37
+ }
38
+ };
39
+
40
+ export const deploymentHref = (id: string, tab = "") =>
41
+ `${contract.deploymentPages}${encodeURIComponent(id)}${tab ? `/${tab}` : ""}`;
@@ -0,0 +1,131 @@
1
+ import type { DeploymentRecord } from "../../protocol";
2
+ import { cancel } from "./actions";
3
+ import { api } from "./api";
4
+ import { type App, attempt } from "./app";
5
+ import { h } from "./dom";
6
+
7
+ /**
8
+ * What a deployment waiting in `awaitingApproval` asks of a deployer. A full download stops the
9
+ * line, so approving one takes an explicit acknowledgement first.
10
+ */
11
+ export const approvalBanner = (
12
+ app: App,
13
+ record: DeploymentRecord,
14
+ onChanged: () => void,
15
+ ) => {
16
+ const { approval } = record;
17
+ if (record.state !== "awaitingApproval" || !approval) {
18
+ return null;
19
+ }
20
+ const deployer = app.can("deployer");
21
+ const cancelButton = h(
22
+ "button",
23
+ {
24
+ class: "button",
25
+ onclick: () => void cancel(record).then(onChanged),
26
+ },
27
+ "Cancel deployment",
28
+ );
29
+ if (approval.reason === "review") {
30
+ return h(
31
+ "section",
32
+ { class: "banner t-waiting" },
33
+ h(
34
+ "div",
35
+ { class: "banner-text" },
36
+ h("h3", {}, "Waiting for review"),
37
+ h("p", {}, approval.message),
38
+ h(
39
+ "p",
40
+ { class: "muted" },
41
+ record.findings.length
42
+ ? `The online-change check found ${record.findings.length} ${record.findings.length === 1 ? "thing" : "things"} to look at: see Changes.`
43
+ : "The online-change check found nothing to report.",
44
+ ),
45
+ ),
46
+ deployer
47
+ ? h(
48
+ "div",
49
+ { class: "banner-actions" },
50
+ cancelButton,
51
+ h(
52
+ "button",
53
+ {
54
+ class: "button primary",
55
+ onclick: () =>
56
+ void attempt(
57
+ () => api.approve(record.id, { download: false }),
58
+ { done: "Approved: the deployment applies now" },
59
+ ).then(onChanged),
60
+ },
61
+ "Approve and apply",
62
+ ),
63
+ )
64
+ : h("p", { class: "muted" }, "A deployer must approve it."),
65
+ );
66
+ }
67
+ const refusals = record.findings.filter((finding) => finding.refuses);
68
+ const acknowledge = h("input", { type: "checkbox" });
69
+ const approve = h(
70
+ "button",
71
+ {
72
+ class: "button danger",
73
+ disabled: true,
74
+ onclick: () =>
75
+ void attempt(() => api.approve(record.id, { download: true }), {
76
+ done: "Approved: the full download starts now",
77
+ }).then(onChanged),
78
+ },
79
+ "Approve full download",
80
+ );
81
+ acknowledge.addEventListener("change", () => {
82
+ approve.disabled = !acknowledge.checked;
83
+ });
84
+ return h(
85
+ "section",
86
+ { class: "banner t-error" },
87
+ h(
88
+ "div",
89
+ { class: "banner-text" },
90
+ h("h3", {}, "A full download stops the line"),
91
+ h("p", {}, approval.message),
92
+ h(
93
+ "p",
94
+ {},
95
+ "An online change can't apply this release. A full download stops the PLC application, and the line with it, until the download has finished and the application runs again.",
96
+ ),
97
+ refusals.length
98
+ ? h(
99
+ "ul",
100
+ { class: "refusals" },
101
+ ...refusals.map((finding) =>
102
+ h(
103
+ "li",
104
+ {},
105
+ h(
106
+ "span",
107
+ { class: "mono" },
108
+ finding.variable
109
+ ? `${finding.object}.${finding.variable}`
110
+ : finding.object,
111
+ ),
112
+ ": ",
113
+ finding.advice,
114
+ ),
115
+ ),
116
+ )
117
+ : null,
118
+ deployer
119
+ ? h(
120
+ "label",
121
+ { class: "check acknowledge" },
122
+ acknowledge,
123
+ "I understand that approving stops the line while the controller downloads.",
124
+ )
125
+ : null,
126
+ ),
127
+ deployer
128
+ ? h("div", { class: "banner-actions" }, cancelButton, approve)
129
+ : h("p", { class: "muted" }, "A deployer must approve it."),
130
+ );
131
+ };
@@ -0,0 +1,115 @@
1
+ import { errorMessage } from "../../errors";
2
+ import type { Audit } from "../../protocol";
3
+ import { api } from "./api";
4
+ import { contract } from "./contract";
5
+ import { empty, fill, h, pageHeader, type View } from "./dom";
6
+ import { formatAgo, formatTimestamp, shortRelease, userAtHost } from "./format";
7
+
8
+ const limits = [contract.auditLimits.default, contract.auditLimits.max];
9
+
10
+ const values = (entries: Record<string, string>) => {
11
+ const pairs = Object.entries(entries);
12
+ if (!pairs.length) {
13
+ return h("span", { class: "muted" }, "—");
14
+ }
15
+ return h(
16
+ "div",
17
+ { class: "values" },
18
+ ...pairs.map(([expression, value]) =>
19
+ h(
20
+ "div",
21
+ { class: "mono" },
22
+ expression,
23
+ value ? h("span", { class: "muted" }, ` = ${value}`) : null,
24
+ ),
25
+ ),
26
+ );
27
+ };
28
+
29
+ const row = (entry: Audit, now: number) =>
30
+ h(
31
+ "tr",
32
+ { class: entry.error ? "failed" : "" },
33
+ h(
34
+ "td",
35
+ { class: "nowrap", title: formatTimestamp(entry.at) },
36
+ formatAgo(entry.at, now),
37
+ ),
38
+ h("td", { class: "mono nowrap" }, entry.command),
39
+ h("td", {}, values(entry.values)),
40
+ h(
41
+ "td",
42
+ {},
43
+ entry.previous
44
+ ? values(entry.previous)
45
+ : h("span", { class: "muted" }, "—"),
46
+ ),
47
+ h("td", { class: "nowrap" }, userAtHost(entry) || "—"),
48
+ h(
49
+ "td",
50
+ { class: "mono nowrap" },
51
+ entry.release ? shortRelease(entry.release) : "—",
52
+ ),
53
+ h("td", { class: "error-text" }, entry.error ?? ""),
54
+ );
55
+
56
+ /** What was changed on the controller through the agent's login, newest first. */
57
+ export const auditView = (): View => {
58
+ const limit = h(
59
+ "select",
60
+ { class: "input", "aria-label": "Entries" },
61
+ ...limits.map((value) => h("option", { value }, `Last ${value}`)),
62
+ );
63
+ const holder = h("div", {}, empty("Loading the audit log…"));
64
+
65
+ const load = async () => {
66
+ try {
67
+ const entries = await api.audit(Number(limit.value));
68
+ const now = Date.now();
69
+ fill(
70
+ holder,
71
+ entries.length
72
+ ? h(
73
+ "table",
74
+ { class: "table" },
75
+ h(
76
+ "thead",
77
+ {},
78
+ h(
79
+ "tr",
80
+ {},
81
+ ...[
82
+ "When",
83
+ "Command",
84
+ "Values",
85
+ "Before",
86
+ "By",
87
+ "Release",
88
+ "Error",
89
+ ].map((label) => h("th", {}, label)),
90
+ ),
91
+ ),
92
+ h("tbody", {}, ...entries.map((entry) => row(entry, now))),
93
+ )
94
+ : empty("Nothing has been written or forced through the agent yet."),
95
+ );
96
+ } catch (error) {
97
+ fill(holder, h("p", { class: "error-text" }, errorMessage(error)));
98
+ }
99
+ };
100
+ limit.addEventListener("change", () => void load());
101
+ void load();
102
+
103
+ return {
104
+ element: h(
105
+ "div",
106
+ { class: "page" },
107
+ pageHeader(
108
+ "Audit",
109
+ "Writes, forces and resets through the agent's login, newest first.",
110
+ limit,
111
+ ),
112
+ holder,
113
+ ),
114
+ };
115
+ };
@@ -0,0 +1,19 @@
1
+ import type { Role } from "../../protocol";
2
+ import type { DashboardContract } from "..";
3
+
4
+ /**
5
+ * What the bundle needs from the agent's own modules at run time, put in by `createDashboard`. The
6
+ * bundle can't import protocol.ts, whose other schemas load the agent's Node-only packages, so it is
7
+ * given the owners' answers instead, and trusts the agent's replies to have protocol.ts's types.
8
+ * `dashboardHeader` comes this way too: importing `@tsplc/debug/api` would add the debugger's
9
+ * schemas, a fifth of the bundle, for one name.
10
+ */
11
+ declare const TSPLC_CONTRACT: DashboardContract;
12
+
13
+ export const contract = TSPLC_CONTRACT;
14
+
15
+ /** Whether `role` includes `required`, as protocol.ts's `allows` answered it. */
16
+ export const allows = (role: Role, required: Role) =>
17
+ contract.permissions[role]?.[required] === true;
18
+
19
+ export type PagePath = DashboardContract["pages"][number]["path"];