@tsplc/agent 0.5.9 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/cli.js +2660 -525
  2. package/dist/cli.js.map +32 -18
  3. package/dist/client.js +262 -37
  4. package/dist/client.js.map +4 -4
  5. package/dist/index.js +2325 -415
  6. package/dist/index.js.map +27 -14
  7. package/package.json +6 -5
  8. package/src/access.ts +276 -0
  9. package/src/agent.ts +130 -29
  10. package/src/audit.ts +64 -0
  11. package/src/cli.ts +81 -5
  12. package/src/client.ts +204 -36
  13. package/src/controller.ts +60 -0
  14. package/src/dashboard/index.ts +118 -0
  15. package/src/dashboard/ui/access.ts +192 -0
  16. package/src/dashboard/ui/actions.ts +192 -0
  17. package/src/dashboard/ui/api.ts +158 -0
  18. package/src/dashboard/ui/app.ts +41 -0
  19. package/src/dashboard/ui/approval.ts +132 -0
  20. package/src/dashboard/ui/audit.ts +115 -0
  21. package/src/dashboard/ui/contract.ts +19 -0
  22. package/src/dashboard/ui/dashboard.css +1332 -0
  23. package/src/dashboard/ui/deployment.ts +432 -0
  24. package/src/dashboard/ui/deployments.ts +317 -0
  25. package/src/dashboard/ui/details.ts +240 -0
  26. package/src/dashboard/ui/dom.ts +91 -0
  27. package/src/dashboard/ui/environment.ts +326 -0
  28. package/src/dashboard/ui/format.ts +118 -0
  29. package/src/dashboard/ui/logs.ts +127 -0
  30. package/src/dashboard/ui/main.ts +86 -0
  31. package/src/dashboard/ui/overlay.ts +146 -0
  32. package/src/dashboard/ui/shell.ts +192 -0
  33. package/src/dashboard/ui/source.ts +144 -0
  34. package/src/deploy.ts +174 -144
  35. package/src/deployments/health.ts +80 -0
  36. package/src/deployments/retention.ts +45 -0
  37. package/src/deployments/routes.ts +273 -0
  38. package/src/deployments/runner.ts +877 -0
  39. package/src/deployments/store.ts +233 -0
  40. package/src/environment.ts +284 -0
  41. package/src/index.ts +4 -0
  42. package/src/login.ts +17 -0
  43. package/src/operations.ts +6 -1
  44. package/src/protocol.ts +259 -2
  45. package/src/releases.ts +73 -1
  46. package/src/routes.ts +52 -0
  47. package/src/secrets.ts +74 -4
  48. package/src/server-process.ts +33 -16
  49. package/src/sessions.ts +58 -0
  50. package/src/state.ts +2 -0
  51. package/src/tailscale.ts +112 -0
@@ -0,0 +1,326 @@
1
+ import { errorMessage } from "../../errors";
2
+ import type {
3
+ EnvironmentEntry,
4
+ EnvironmentListing,
5
+ EnvironmentValue,
6
+ } from "../../protocol";
7
+ import { api } from "./api";
8
+ import { type App, attempt } from "./app";
9
+ import { badge, dot, empty, fill, h, pageHeader, type View } from "./dom";
10
+ import { confirm, dialog } from "./overlay";
11
+
12
+ /** A row of the Environment page: a plain variable or a secret, and where it stands. */
13
+ interface Variable {
14
+ name: string;
15
+ secret: boolean;
16
+ /** A plain variable's value on this PC, or the running release's when only it has one. */
17
+ value: string | null;
18
+ /** Whether this PC holds it, so it can be edited and deleted here. */
19
+ stored: boolean;
20
+ status: { tone: string; text: string };
21
+ }
22
+
23
+ const applied = { tone: "ok", text: "Running" };
24
+ const pending = { tone: "waiting", text: "Deploy to apply" };
25
+
26
+ /** A secret stands applied once the running release reads it; the next deployment picks up a new one. */
27
+ const secretStatus = (entry: EnvironmentEntry) => {
28
+ if (!entry.set) {
29
+ return { tone: "error", text: "Not set" };
30
+ }
31
+ return entry.declared ? applied : pending;
32
+ };
33
+
34
+ /** The label of a row's edit button. */
35
+ const editLabel = (variable: Variable) => {
36
+ if (!variable.stored) {
37
+ return "Set";
38
+ }
39
+ return variable.secret ? "Replace" : "Edit";
40
+ };
41
+
42
+ /** The page's rows: this PC's plain variables, what the running release has besides, and the secrets. */
43
+ const variables = ({
44
+ values,
45
+ variables: stored,
46
+ secrets,
47
+ }: EnvironmentListing): Variable[] => {
48
+ const secretNames = new Set(secrets.map(({ name }) => name));
49
+ const plain = [...new Set([...Object.keys(stored), ...Object.keys(values)])]
50
+ .filter((name) => !secretNames.has(name))
51
+ .sort()
52
+ .map((name): Variable => {
53
+ const value = stored[name];
54
+ if (value === undefined) {
55
+ return {
56
+ name,
57
+ secret: false,
58
+ value: values[name] ?? null,
59
+ stored: false,
60
+ status: { tone: "ok", text: "Running, not set on this PC" },
61
+ };
62
+ }
63
+ return {
64
+ name,
65
+ secret: false,
66
+ value,
67
+ stored: true,
68
+ status: values[name] === value ? applied : pending,
69
+ };
70
+ });
71
+ const secret = secrets.map(
72
+ (entry): Variable => ({
73
+ name: entry.name,
74
+ secret: true,
75
+ value: null,
76
+ stored: entry.set,
77
+ status: secretStatus(entry),
78
+ }),
79
+ );
80
+ return [...plain, ...secret];
81
+ };
82
+
83
+ /** Asks for a variable's value, and whether it is a secret, which is never shown again. */
84
+ const askValue = (variable: Variable | null) => {
85
+ const nameInput = h("input", {
86
+ class: "input mono",
87
+ placeholder: "NAME",
88
+ autocomplete: "off",
89
+ spellcheck: "false",
90
+ required: true,
91
+ pattern: "[A-Za-z_][A-Za-z0-9_]*",
92
+ });
93
+ const valueInput = h("input", {
94
+ class: "input mono",
95
+ type: variable?.secret ? "password" : "text",
96
+ autocomplete: "off",
97
+ spellcheck: "false",
98
+ placeholder: "Value",
99
+ value: variable && !variable.secret ? (variable.value ?? "") : "",
100
+ });
101
+ const secretInput = h("input", {
102
+ type: "checkbox",
103
+ checked: variable?.secret ?? false,
104
+ });
105
+ const note = h("p", { class: "muted" });
106
+ const describe = () => {
107
+ valueInput.type = secretInput.checked ? "password" : "text";
108
+ note.textContent = secretInput.checked
109
+ ? "Kept on this PC with Bun.secrets and never shown again. The PLC's program gets it at each deployment, the server when it starts."
110
+ : "Shown here. The next tsplc deploy builds the PLC's program with it and starts the server with it.";
111
+ };
112
+ secretInput.addEventListener("change", describe);
113
+ describe();
114
+ return dialog<{ name: string; change: EnvironmentValue }>({
115
+ title: variable ? `Set ${variable.name}` : "Add a variable",
116
+ body: [
117
+ variable
118
+ ? null
119
+ : h("label", { class: "field" }, h("span", {}, "Name"), nameInput),
120
+ h("label", { class: "field" }, h("span", {}, "Value"), valueInput),
121
+ h("label", { class: "check" }, secretInput, "Secret"),
122
+ note,
123
+ ],
124
+ actions: (close) => [
125
+ h(
126
+ "button",
127
+ {
128
+ class: "button primary",
129
+ onclick: () => {
130
+ const name = variable?.name ?? nameInput.value.trim();
131
+ if (!variable && (!name || !nameInput.checkValidity())) {
132
+ nameInput.reportValidity();
133
+ return;
134
+ }
135
+ close({
136
+ name,
137
+ change: { secret: secretInput.checked, value: valueInput.value },
138
+ });
139
+ },
140
+ },
141
+ "Save",
142
+ ),
143
+ ],
144
+ });
145
+ };
146
+
147
+ /** This PC's variables, plain and secret, and whether the running release has them. */
148
+ export const environmentView = (app: App): View => {
149
+ const admin = app.can("admin");
150
+ const body = h("tbody");
151
+ const table = h(
152
+ "table",
153
+ { class: "table" },
154
+ h(
155
+ "thead",
156
+ {},
157
+ h(
158
+ "tr",
159
+ {},
160
+ h("th", {}, "Name"),
161
+ h("th", {}, "Value"),
162
+ h("th", {}, "Status"),
163
+ admin ? h("th", {}, "") : null,
164
+ ),
165
+ ),
166
+ body,
167
+ );
168
+ const holder = h("div", {}, empty("Loading the environment…"));
169
+
170
+ const set = async (variable: Variable | null) => {
171
+ const entered = await askValue(variable);
172
+ if (
173
+ entered &&
174
+ (await attempt(
175
+ () => api.setEnvironment(entered.name, entered.change),
176
+ entered.change.secret
177
+ ? `Saved ${entered.name}. The next deployment applies it, and Restart server applies it to the server now.`
178
+ : `Saved ${entered.name}. Deploy to apply it to the PLC's program and the server.`,
179
+ )) !== null
180
+ ) {
181
+ await load();
182
+ }
183
+ };
184
+
185
+ const remove = async (variable: Variable) => {
186
+ const confirmed = await confirm({
187
+ title: `Delete ${variable.name}?`,
188
+ body: [
189
+ h(
190
+ "p",
191
+ {},
192
+ variable.secret
193
+ ? "A release that reads it can't deploy without it, and the server starts without it after the next restart."
194
+ : "The next deployment is built without it, unless tsplc.config.ts sets it.",
195
+ ),
196
+ ],
197
+ confirm: "Delete",
198
+ tone: "danger",
199
+ });
200
+ if (
201
+ confirmed &&
202
+ (await attempt(
203
+ () => api.deleteEnvironment(variable.name),
204
+ `Deleted ${variable.name}`,
205
+ )) !== null
206
+ ) {
207
+ await load();
208
+ }
209
+ };
210
+
211
+ const row = (variable: Variable) =>
212
+ h(
213
+ "tr",
214
+ {},
215
+ h(
216
+ "td",
217
+ {},
218
+ h("span", { class: "mono" }, variable.name),
219
+ variable.secret ? h("span", {}, " ", badge("Secret")) : null,
220
+ ),
221
+ h(
222
+ "td",
223
+ { class: "mono" },
224
+ variable.secret
225
+ ? h(
226
+ "span",
227
+ { class: "muted" },
228
+ variable.stored ? "••••••••" : "Not set",
229
+ )
230
+ : variable.value,
231
+ ),
232
+ h(
233
+ "td",
234
+ {},
235
+ h(
236
+ "span",
237
+ { class: "state" },
238
+ dot(variable.status.tone),
239
+ variable.status.text,
240
+ ),
241
+ ),
242
+ admin
243
+ ? h(
244
+ "td",
245
+ { class: "row-actions" },
246
+ h(
247
+ "button",
248
+ { class: "button small", onclick: () => void set(variable) },
249
+ editLabel(variable),
250
+ ),
251
+ variable.stored
252
+ ? h(
253
+ "button",
254
+ {
255
+ class: "button small danger-text",
256
+ onclick: () => void remove(variable),
257
+ },
258
+ "Delete",
259
+ )
260
+ : null,
261
+ )
262
+ : null,
263
+ );
264
+
265
+ const load = async () => {
266
+ try {
267
+ const rows = variables(await api.environment());
268
+ fill(body, ...rows.map(row));
269
+ fill(
270
+ holder,
271
+ rows.length
272
+ ? table
273
+ : empty(
274
+ "No variables yet. Add one, and the next deployment builds with it.",
275
+ ),
276
+ );
277
+ } catch (error) {
278
+ fill(holder, h("p", { class: "error-text" }, errorMessage(error)));
279
+ }
280
+ };
281
+
282
+ const restart = async () => {
283
+ const confirmed = await confirm({
284
+ title: "Restart the server?",
285
+ body: [
286
+ h(
287
+ "p",
288
+ {},
289
+ "The line's server stops and starts again with the running release's values and the secrets as they are now. The controller keeps running.",
290
+ ),
291
+ ],
292
+ confirm: "Restart",
293
+ tone: "primary",
294
+ });
295
+ if (confirmed) {
296
+ await attempt(() => api.restartServer(), "The server restarted");
297
+ }
298
+ };
299
+
300
+ void load();
301
+ return {
302
+ element: h(
303
+ "div",
304
+ { class: "page" },
305
+ pageHeader(
306
+ "Environment",
307
+ "The variables the PLC's program and the line's server read. tsplc deploy builds with them, over the values in tsplc.config.ts.",
308
+ app.can("deployer")
309
+ ? h(
310
+ "button",
311
+ { class: "button", onclick: () => void restart() },
312
+ "Restart server",
313
+ )
314
+ : null,
315
+ admin
316
+ ? h(
317
+ "button",
318
+ { class: "button primary", onclick: () => void set(null) },
319
+ "Add variable",
320
+ )
321
+ : null,
322
+ ),
323
+ holder,
324
+ ),
325
+ };
326
+ };
@@ -0,0 +1,118 @@
1
+ import { formatAge, formatDuration } from "@tsplc/debug/format";
2
+ import type {
3
+ DeploymentRecord,
4
+ DeploymentState,
5
+ GitSource,
6
+ } from "../../protocol";
7
+
8
+ export type Phase = DeploymentRecord["phases"][number];
9
+ export type PhaseName = Phase["name"];
10
+
11
+ /** How each state is shown, and whether the deployment has finished in it. */
12
+ export const states: Record<
13
+ DeploymentState,
14
+ {
15
+ label: string;
16
+ tone: "ok" | "error" | "active" | "waiting" | "idle";
17
+ finished: boolean;
18
+ }
19
+ > = {
20
+ queued: { label: "Queued", tone: "idle", finished: false },
21
+ building: { label: "Building", tone: "active", finished: false },
22
+ awaitingApproval: {
23
+ label: "Awaiting approval",
24
+ tone: "waiting",
25
+ finished: false,
26
+ },
27
+ applying: { label: "Applying", tone: "active", finished: false },
28
+ starting: { label: "Starting", tone: "active", finished: false },
29
+ verifying: { label: "Verifying", tone: "active", finished: false },
30
+ ready: { label: "Ready", tone: "ok", finished: true },
31
+ error: { label: "Error", tone: "error", finished: true },
32
+ canceled: { label: "Canceled", tone: "idle", finished: true },
33
+ };
34
+
35
+ export const phaseLabels: Record<PhaseName, string> = {
36
+ queue: "Queue",
37
+ build: "Build",
38
+ review: "Review",
39
+ apply: "Apply",
40
+ server: "Server",
41
+ health: "Health check",
42
+ };
43
+
44
+ /** A deployment can still be canceled: it hasn't started changing the controller. */
45
+ export const cancelable = (state: DeploymentState) =>
46
+ state === "queued" || state === "building" || state === "awaitingApproval";
47
+
48
+ const hour = 3_600_000;
49
+ const day = 86_400_000;
50
+
51
+ /** A length of time: the debugger's durations within an hour, then hours and minutes, since approval can wait for days. */
52
+ export const formatSpan = (ms: number) =>
53
+ ms < hour
54
+ ? formatDuration(ms)
55
+ : `${Math.floor(ms / hour)} h ${Math.floor((ms % hour) / 60_000)} min`;
56
+
57
+ /** How long before `now` `iso` was: the debugger's ages within a day, then days. A clock ahead of the browser's reads as now. */
58
+ export const formatAgo = (iso: string, now: number) => {
59
+ const elapsed = Math.max(0, now - Date.parse(iso));
60
+ return elapsed < day
61
+ ? formatAge(elapsed)
62
+ : `${Math.floor(elapsed / day)} d ago`;
63
+ };
64
+
65
+ /** A phase's length so far: to `now` while it runs. */
66
+ export const phaseDuration = (phase: Phase, now: number) =>
67
+ (phase.finishedAt === null ? now : Date.parse(phase.finishedAt)) -
68
+ Date.parse(phase.startedAt);
69
+
70
+ /**
71
+ * How long a deployment took, from its first phase to the end of its last, or to `now` while it
72
+ * hasn't finished; null before it has a phase.
73
+ */
74
+ export const deploymentDuration = (record: DeploymentRecord, now: number) => {
75
+ const [first] = record.phases;
76
+ if (!first) {
77
+ return null;
78
+ }
79
+ const end = states[record.state].finished
80
+ ? Math.max(
81
+ ...record.phases.map((phase) =>
82
+ Date.parse(phase.finishedAt ?? phase.startedAt),
83
+ ),
84
+ )
85
+ : now;
86
+ return Math.max(0, end - Date.parse(first.startedAt));
87
+ };
88
+
89
+ export const formatDeploymentDuration = (
90
+ record: DeploymentRecord,
91
+ now: number,
92
+ ) => {
93
+ const duration = deploymentDuration(record, now);
94
+ return duration === null ? "—" : formatSpan(duration);
95
+ };
96
+
97
+ /** A deployment id as a list shows it: without the `dpl_` prefix, to nine characters. */
98
+ export const shortId = (id: string) => id.replace(/^dpl_/, "").slice(0, 9);
99
+
100
+ export const shortCommit = (git: GitSource) => git.commit.slice(0, 7);
101
+
102
+ /** A date and time in the browser's locale, to the second. */
103
+ export const formatTimestamp = (iso: string) =>
104
+ new Date(iso).toLocaleString(undefined, {
105
+ dateStyle: "medium",
106
+ timeStyle: "medium",
107
+ });
108
+
109
+ /** A file size: bytes, then kB and MB. */
110
+ export const formatSize = (bytes: number) => {
111
+ if (bytes < 1000) {
112
+ return `${bytes} B`;
113
+ }
114
+ if (bytes < 1_000_000) {
115
+ return `${(bytes / 1000).toFixed(1)} kB`;
116
+ }
117
+ return `${(bytes / 1_000_000).toFixed(1)} MB`;
118
+ };
@@ -0,0 +1,127 @@
1
+ import { formatClock } from "@tsplc/debug/format";
2
+ import type { DeploymentLogLine } from "../../protocol";
3
+ import { empty, fill, h } from "./dom";
4
+ import { type PhaseName, phaseLabels } from "./format";
5
+
6
+ const allPhases = "all";
7
+
8
+ /**
9
+ * A deployment's log: lines coloured by level, filtered by phase and text, and kept scrolled to
10
+ * the newest line while following.
11
+ */
12
+ export const logViewer = (lines: readonly DeploymentLogLine[]) => {
13
+ const phase = h("select", { class: "input", "aria-label": "Phase" });
14
+ const search = h("input", {
15
+ class: "input search",
16
+ type: "search",
17
+ placeholder: "Search the log…",
18
+ });
19
+ const follow = h("input", { type: "checkbox", checked: true });
20
+ const count = h("span", { class: "muted mono count" });
21
+ const output = h("div", { class: "log", tabindex: 0 });
22
+ const shown: DeploymentLogLine[] = [];
23
+
24
+ const matches = (line: DeploymentLogLine) => {
25
+ const text = search.value.trim().toLowerCase();
26
+ return (
27
+ (phase.value === allPhases || line.phase === phase.value) &&
28
+ (!text || line.message.toLowerCase().includes(text))
29
+ );
30
+ };
31
+
32
+ const lineElement = (line: DeploymentLogLine) =>
33
+ h(
34
+ "div",
35
+ { class: `log-line l-${line.level}` },
36
+ h("span", { class: "log-seq" }, String(line.seq)),
37
+ h("time", { class: "log-time", title: line.at }, formatClock(line.at)),
38
+ h(
39
+ "span",
40
+ { class: "log-phase" },
41
+ line.phase ? phaseLabels[line.phase] : "",
42
+ ),
43
+ h("span", { class: "log-message" }, line.message),
44
+ );
45
+
46
+ const phasesSeen = () => [
47
+ ...new Set(lines.flatMap((line) => (line.phase ? [line.phase] : []))),
48
+ ];
49
+
50
+ const renderPhases = () => {
51
+ const selected = phase.value || allPhases;
52
+ const seen: PhaseName[] = phasesSeen();
53
+ if (phase.options.length === seen.length + 1) {
54
+ return;
55
+ }
56
+ fill(
57
+ phase,
58
+ h("option", { value: allPhases }, "All phases"),
59
+ ...seen.map((name) => h("option", { value: name }, phaseLabels[name])),
60
+ );
61
+ phase.value = selected;
62
+ };
63
+
64
+ const updateCount = () => {
65
+ count.textContent =
66
+ shown.length === lines.length
67
+ ? `${lines.length} lines`
68
+ : `${shown.length} of ${lines.length} lines`;
69
+ };
70
+
71
+ const scrollToEnd = () => {
72
+ if (follow.checked) {
73
+ output.scrollTop = output.scrollHeight;
74
+ }
75
+ };
76
+
77
+ const render = () => {
78
+ shown.splice(0, shown.length, ...lines.filter(matches));
79
+ fill(
80
+ output,
81
+ ...(shown.length
82
+ ? shown.map(lineElement)
83
+ : [empty(lines.length ? "No line matches." : "No log lines yet.")]),
84
+ );
85
+ updateCount();
86
+ scrollToEnd();
87
+ };
88
+
89
+ // Scrolling up stops following; scrolling back to the end follows again.
90
+ output.addEventListener("scroll", () => {
91
+ follow.checked =
92
+ output.scrollHeight - output.scrollTop - output.clientHeight < 24;
93
+ });
94
+ phase.addEventListener("change", render);
95
+ search.addEventListener("input", render);
96
+ follow.addEventListener("change", scrollToEnd);
97
+ renderPhases();
98
+ render();
99
+
100
+ return {
101
+ element: h(
102
+ "div",
103
+ { class: "log-viewer" },
104
+ h(
105
+ "div",
106
+ { class: "toolbar" },
107
+ search,
108
+ phase,
109
+ h("label", { class: "check" }, follow, "Follow"),
110
+ count,
111
+ ),
112
+ output,
113
+ ),
114
+ /** Shows lines added to `lines` since the last call. */
115
+ added: (added: readonly DeploymentLogLine[]) => {
116
+ renderPhases();
117
+ const matching = added.filter(matches);
118
+ if (matching.length && shown.length === 0) {
119
+ output.replaceChildren();
120
+ }
121
+ shown.push(...matching);
122
+ output.append(...matching.map(lineElement));
123
+ updateCount();
124
+ scrollToEnd();
125
+ },
126
+ };
127
+ };
@@ -0,0 +1,86 @@
1
+ import { errorMessage } from "../../errors";
2
+ import { accessView } from "./access";
3
+ import { ApiError, api } from "./api";
4
+ import { type App, createApp } from "./app";
5
+ import { auditView } from "./audit";
6
+ import { deploymentView } from "./deployment";
7
+ import { deploymentsView } from "./deployments";
8
+ import { h, type View } from "./dom";
9
+ import { environmentView } from "./environment";
10
+ import { shell, signInForm } from "./shell";
11
+
12
+ type Page = View & { navigate?(pathname: string): boolean };
13
+
14
+ const pageFor = (app: App, pathname: string): Page => {
15
+ if (pathname.startsWith("/deployments/")) {
16
+ return deploymentView(app, pathname);
17
+ }
18
+ if (pathname === "/environment") {
19
+ return environmentView(app);
20
+ }
21
+ if (pathname === "/audit") {
22
+ return auditView(app);
23
+ }
24
+ if (pathname === "/access") {
25
+ return accessView(app);
26
+ }
27
+ return deploymentsView(app);
28
+ };
29
+
30
+ const root = () => {
31
+ const element = document.getElementById("app");
32
+ if (!element) {
33
+ throw new Error("The page has no #app element");
34
+ }
35
+ return element;
36
+ };
37
+
38
+ const start = async () => {
39
+ const identity = await api.session().catch((error: unknown) => {
40
+ if (error instanceof ApiError && error.status === 401) {
41
+ return null;
42
+ }
43
+ throw error;
44
+ });
45
+ if (!identity) {
46
+ root().replaceChildren(signInForm(() => void start()));
47
+ return;
48
+ }
49
+ let page: Page | null = null;
50
+ const main = h("div", { class: "content" });
51
+ const show = (pathname: string) => {
52
+ top.setActive(pathname);
53
+ if (page?.navigate?.(pathname)) {
54
+ return;
55
+ }
56
+ page?.dispose?.();
57
+ page = pageFor(app, pathname);
58
+ main.replaceChildren(page.element);
59
+ scrollTo(0, 0);
60
+ };
61
+ const app = createApp(identity, (path) => {
62
+ if (path !== location.pathname) {
63
+ history.pushState(null, "", path);
64
+ }
65
+ show(path);
66
+ });
67
+ const top = shell(app);
68
+ root().replaceChildren(top.element, main);
69
+ addEventListener("popstate", () => show(location.pathname));
70
+ show(location.pathname);
71
+ };
72
+
73
+ start().catch((error: unknown) =>
74
+ root().replaceChildren(
75
+ h(
76
+ "div",
77
+ { class: "sign-in" },
78
+ h(
79
+ "div",
80
+ { class: "card" },
81
+ h("h1", {}, "The dashboard could not start"),
82
+ h("p", { class: "error-text" }, errorMessage(error)),
83
+ ),
84
+ ),
85
+ ),
86
+ );