@app-vitals/agent-admin 1.68.0 → 1.69.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.68.0",
3
+ "version": "1.69.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.137.0",
45
- "@app-vitals/agent-lib": "1.68.0",
45
+ "@app-vitals/agent-lib": "1.69.1",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
@@ -1,26 +1,38 @@
1
1
  /**
2
2
  * admin/src/admin-ui-account-nav.ts
3
- * Per-request "show the Settings nav entry" flag. renderAdminToolbar()
4
- * is called from dozens of page renderers; rather than thread a parameter
5
- * through all of them, an admin-ui middleware wraps each /admin/* request in
6
- * runWithAccountNav() and the toolbar reads the flag back. Outside any
7
- * context (tests, other services) the entry is hidden.
3
+ * Per-request toolbar audience. renderAdminToolbar() is called from dozens of
4
+ * page renderers; rather than thread a parameter through all of them, an
5
+ * admin-ui middleware wraps each /admin/* request in runWithToolbarAudience()
6
+ * and the toolbar reads it back. Outside any context (tests, other services)
7
+ * no audience is set and the toolbar renders its legacy default (no Settings).
8
8
  */
9
9
 
10
10
  import { AsyncLocalStorage } from "node:async_hooks";
11
+ import type { ToolbarAudience } from "@app-vitals/agent-lib/web/toolbar.ts";
11
12
 
12
- interface NavFlags {
13
- /** The "Settings" entry (admins and account members). */
13
+ export interface ToolbarViewer {
14
+ audience: ToolbarAudience;
15
+ /**
16
+ * Show Settings even though the audience's manifest hides it. Account members
17
+ * (SGL-2.2) keep their Settings entry; the manifest lists it admin-only.
18
+ */
14
19
  showSettings: boolean;
15
20
  }
16
21
 
17
- const storage = new AsyncLocalStorage<NavFlags>();
22
+ const storage = new AsyncLocalStorage<ToolbarViewer>();
18
23
 
19
- /** Wrap a request so the toolbar shows (or hides) the admin Settings entry. */
20
- export function runWithSettingsNav<T>(showSettings: boolean, fn: () => T): T {
21
- return storage.run({ showSettings }, fn);
24
+ /** Wrap a request so the toolbar renders for the given audience. */
25
+ export function runWithToolbarAudience<T>(
26
+ audience: ToolbarAudience,
27
+ fn: () => T,
28
+ opts: { showSettings?: boolean } = {},
29
+ ): T {
30
+ return storage.run(
31
+ { audience, showSettings: audience === "admin" || !!opts.showSettings },
32
+ fn,
33
+ );
22
34
  }
23
35
 
24
- export function shouldShowSettingsNav(): boolean {
25
- return storage.getStore()?.showSettings === true;
36
+ export function currentToolbarViewer(): ToolbarViewer | undefined {
37
+ return storage.getStore();
26
38
  }
@@ -1,24 +1,67 @@
1
1
  /**
2
2
  * admin/src/admin-ui-account-nav.unit.test.ts
3
- * Flag plumbing for the toolbar Settings entry.
3
+ * Audience plumbing for the admin toolbar.
4
4
  */
5
5
 
6
6
  import { describe, expect, test } from "bun:test";
7
7
  import {
8
- runWithSettingsNav,
9
- shouldShowSettingsNav,
8
+ currentToolbarViewer,
9
+ runWithToolbarAudience,
10
10
  } from "./admin-ui-account-nav.ts";
11
+ import { renderAdminToolbar } from "./admin-ui-styles.ts";
11
12
 
12
- describe("settings-nav flag", () => {
13
- test("hidden outside any context", () => {
14
- expect(shouldShowSettingsNav()).toBe(false);
15
- });
16
- test("reflects the wrapper value, including nested", () => {
17
- runWithSettingsNav(true, () => {
18
- expect(shouldShowSettingsNav()).toBe(true);
19
- runWithSettingsNav(false, () => {
20
- expect(shouldShowSettingsNav()).toBe(false);
13
+ describe("toolbar audience context", () => {
14
+ test("no viewer outside any context", () => {
15
+ expect(currentToolbarViewer()).toBeUndefined();
16
+ });
17
+ test("admin audience implies Settings; nested contexts override", () => {
18
+ runWithToolbarAudience("admin", () => {
19
+ expect(currentToolbarViewer()).toEqual({
20
+ audience: "admin",
21
+ showSettings: true,
22
+ });
23
+ runWithToolbarAudience("member", () => {
24
+ expect(currentToolbarViewer()?.audience).toBe("member");
25
+ expect(currentToolbarViewer()?.showSettings).toBe(false);
21
26
  });
22
27
  });
23
28
  });
29
+ test("member keeps Settings only with the account opt-in", () => {
30
+ runWithToolbarAudience("member", () => {
31
+ expect(currentToolbarViewer()?.showSettings).toBe(true);
32
+ }, { showSettings: true });
33
+ });
34
+ });
35
+
36
+ describe("renderAdminToolbar audience mapping", () => {
37
+ const settings = 'href="/admin/settings"';
38
+ test("outside a context: legacy output, no Settings", () => {
39
+ const html = renderAdminToolbar("a@x.com");
40
+ expect(html).not.toContain(settings);
41
+ expect(html).toContain("Agents");
42
+ });
43
+ test("admin sees Settings", () => {
44
+ expect(
45
+ runWithToolbarAudience("admin", () => renderAdminToolbar("a@x.com")),
46
+ ).toContain(settings);
47
+ });
48
+ test("plain member does not see Settings but sees the other items", () => {
49
+ const html = runWithToolbarAudience("member", () =>
50
+ renderAdminToolbar("a@x.com"),
51
+ );
52
+ expect(html).not.toContain(settings);
53
+ expect(html).toContain("/admin/sessions");
54
+ });
55
+ test("account member keeps Settings (SGL-2.2)", () => {
56
+ const html = runWithToolbarAudience(
57
+ "member",
58
+ () => renderAdminToolbar("a@x.com"),
59
+ { showSettings: true },
60
+ );
61
+ expect(html).toContain(settings);
62
+ });
63
+ test("audience output matches legacy flag output", () => {
64
+ const base = runWithToolbarAudience("admin", () => renderAdminToolbar("a"));
65
+ expect(base).toContain("Queue &amp; Activity");
66
+ });
24
67
  });
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { describe, expect, test } from "bun:test";
8
- import { runWithSettingsNav } from "./admin-ui-account-nav.ts";
8
+ import { runWithToolbarAudience } from "./admin-ui-account-nav.ts";
9
9
  import {
10
10
  type GheApp,
11
11
  renderGithubEnterpriseSettingsPage,
@@ -236,7 +236,9 @@ describe("renderGithubEnterpriseSettingsPage", () => {
236
236
  describe("toolbar Settings entry", () => {
237
237
  test("hidden outside a settings-nav context, shown inside one", () => {
238
238
  expect(renderAdminToolbar("a@x.com")).not.toContain("/admin/settings");
239
- const html = runWithSettingsNav(true, () => renderAdminToolbar("a@x.com"));
239
+ const html = runWithToolbarAudience("admin", () =>
240
+ renderAdminToolbar("a@x.com"),
241
+ );
240
242
  expect(html).toContain('href="/admin/settings" class="vos-nav-link');
241
243
  });
242
244
  });
@@ -3,7 +3,7 @@ import {
3
3
  renderShipwrightToolbar,
4
4
  baseStyles as toolbarBaseStyles,
5
5
  } from "@app-vitals/agent-lib/web/toolbar.ts";
6
- import { shouldShowSettingsNav } from "./admin-ui-account-nav.ts";
6
+ import { currentToolbarViewer } from "./admin-ui-account-nav.ts";
7
7
 
8
8
  export { escapeHtml };
9
9
 
@@ -684,11 +684,13 @@ export function baseStyles(): string {
684
684
  }
685
685
 
686
686
  export function renderAdminToolbar(userName: string, activePath = ""): string {
687
+ const viewer = currentToolbarViewer();
687
688
  return renderShipwrightToolbar({
688
689
  userName,
689
690
  activePath,
690
691
  logoutAction: "/admin/logout",
691
692
  metricsUrl: process.env.METRICS_DASHBOARD_URL ?? "/dashboard",
692
- showSettings: shouldShowSettingsNav(),
693
+ audience: viewer?.audience,
694
+ showSettings: viewer?.showSettings,
693
695
  });
694
696
  }
package/src/admin-ui.ts CHANGED
@@ -46,7 +46,7 @@ import {
46
46
  type SettingsNavContribution,
47
47
  } from "./admin-extension.ts";
48
48
  import { registerAccountRoutes } from "./admin-ui-account.ts";
49
- import { runWithSettingsNav } from "./admin-ui-account-nav.ts";
49
+ import { runWithToolbarAudience } from "./admin-ui-account-nav.ts";
50
50
  import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
51
51
  import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
52
52
  import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
@@ -1021,8 +1021,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1021
1021
  app.use("/admin/*", async (c, next) => {
1022
1022
  const token = getCookie(c, SESSION_COOKIE);
1023
1023
  const user = token ? await getSessionUser(token, sessionSecret) : null;
1024
- let show = user?.isAdmin === true;
1025
- if (user && !show && accountServices) {
1024
+ const isAdmin = user?.isAdmin === true;
1025
+ let show = false; // member with an account keeps Settings (SGL-2.2)
1026
+ if (user && !isAdmin && accountServices) {
1026
1027
  try {
1027
1028
  show =
1028
1029
  (await accountServices.accounts.getByMemberEmail(user.email)) !==
@@ -1031,7 +1032,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
1031
1032
  // nav is cosmetic — never fail the page over the lookup
1032
1033
  }
1033
1034
  }
1034
- return runWithSettingsNav(show, () => next());
1035
+ return runWithToolbarAudience(
1036
+ isAdmin ? "admin" : "member",
1037
+ () => next(),
1038
+ { showSettings: show },
1039
+ );
1035
1040
  });
1036
1041
  }
1037
1042