@app-vitals/agent-admin 1.71.0 → 1.72.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.72.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"./openapi-schemas": "./src/openapi-schemas.ts",
|
|
23
23
|
"./prisma-client": "./src/prisma-client.ts",
|
|
24
24
|
"./specialty-types": "./src/specialty-types.ts",
|
|
25
|
+
"./brand-tokens.json": "./src/brand-tokens.json",
|
|
25
26
|
"./theme-tokens.json": "./src/theme-tokens.json",
|
|
26
27
|
"./*": "./src/*.ts",
|
|
27
28
|
"./prisma/client/*": "./prisma/client/*",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"@anthropic-ai/sdk": "0.137.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
46
|
+
"@app-vitals/agent-lib": "1.72.0",
|
|
46
47
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
48
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
49
|
"@prisma/client": "^7.10.0",
|
|
@@ -12,11 +12,6 @@ import type { ToolbarAudience } from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
|
12
12
|
|
|
13
13
|
export interface ToolbarViewer {
|
|
14
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
|
-
*/
|
|
19
|
-
showSettings: boolean;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
const storage = new AsyncLocalStorage<ToolbarViewer>();
|
|
@@ -25,12 +20,8 @@ const storage = new AsyncLocalStorage<ToolbarViewer>();
|
|
|
25
20
|
export function runWithToolbarAudience<T>(
|
|
26
21
|
audience: ToolbarAudience,
|
|
27
22
|
fn: () => T,
|
|
28
|
-
opts: { showSettings?: boolean } = {},
|
|
29
23
|
): T {
|
|
30
|
-
return storage.run(
|
|
31
|
-
{ audience, showSettings: audience === "admin" || !!opts.showSettings },
|
|
32
|
-
fn,
|
|
33
|
-
);
|
|
24
|
+
return storage.run({ audience }, fn);
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
export function currentToolbarViewer(): ToolbarViewer | undefined {
|
|
@@ -14,53 +14,38 @@ describe("toolbar audience context", () => {
|
|
|
14
14
|
test("no viewer outside any context", () => {
|
|
15
15
|
expect(currentToolbarViewer()).toBeUndefined();
|
|
16
16
|
});
|
|
17
|
-
test("
|
|
17
|
+
test("nested contexts override", () => {
|
|
18
18
|
runWithToolbarAudience("admin", () => {
|
|
19
|
-
expect(currentToolbarViewer()).toEqual({
|
|
20
|
-
audience: "admin",
|
|
21
|
-
showSettings: true,
|
|
22
|
-
});
|
|
19
|
+
expect(currentToolbarViewer()).toEqual({ audience: "admin" });
|
|
23
20
|
runWithToolbarAudience("member", () => {
|
|
24
21
|
expect(currentToolbarViewer()?.audience).toBe("member");
|
|
25
|
-
expect(currentToolbarViewer()?.showSettings).toBe(false);
|
|
26
22
|
});
|
|
27
23
|
});
|
|
28
24
|
});
|
|
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
25
|
});
|
|
35
26
|
|
|
36
27
|
describe("renderAdminToolbar audience mapping", () => {
|
|
37
28
|
const settings = 'href="/admin/settings"';
|
|
38
|
-
test("outside a context:
|
|
29
|
+
test("outside a context: renders the member audience", () => {
|
|
39
30
|
const html = renderAdminToolbar("a@x.com");
|
|
40
|
-
expect(html).not.toContain(settings);
|
|
41
31
|
expect(html).toContain("Agents");
|
|
32
|
+
expect(html).toBe(
|
|
33
|
+
runWithToolbarAudience("member", () => renderAdminToolbar("a@x.com")),
|
|
34
|
+
);
|
|
42
35
|
});
|
|
43
36
|
test("admin sees Settings", () => {
|
|
44
37
|
expect(
|
|
45
38
|
runWithToolbarAudience("admin", () => renderAdminToolbar("a@x.com")),
|
|
46
39
|
).toContain(settings);
|
|
47
40
|
});
|
|
48
|
-
test("
|
|
41
|
+
test("member does not see Settings but sees the other items", () => {
|
|
49
42
|
const html = runWithToolbarAudience("member", () =>
|
|
50
43
|
renderAdminToolbar("a@x.com"),
|
|
51
44
|
);
|
|
52
45
|
expect(html).not.toContain(settings);
|
|
53
46
|
expect(html).toContain("/admin/sessions");
|
|
54
47
|
});
|
|
55
|
-
test("
|
|
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", () => {
|
|
48
|
+
test("admin sees Queue & Activity", () => {
|
|
64
49
|
const base = runWithToolbarAudience("admin", () => renderAdminToolbar("a"));
|
|
65
50
|
expect(base).toContain("Queue & Activity");
|
|
66
51
|
});
|
package/src/admin-ui-styles.ts
CHANGED
|
@@ -690,7 +690,6 @@ export function renderAdminToolbar(userName: string, activePath = ""): string {
|
|
|
690
690
|
activePath,
|
|
691
691
|
logoutAction: "/admin/logout",
|
|
692
692
|
metricsUrl: process.env.METRICS_DASHBOARD_URL ?? "/dashboard",
|
|
693
|
-
audience: viewer?.audience,
|
|
694
|
-
showSettings: viewer?.showSettings,
|
|
693
|
+
audience: viewer?.audience ?? "member",
|
|
695
694
|
});
|
|
696
695
|
}
|
package/src/admin-ui.ts
CHANGED
|
@@ -1010,8 +1010,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1010
1010
|
await next();
|
|
1011
1011
|
});
|
|
1012
1012
|
|
|
1013
|
-
// GHE-1.4:
|
|
1014
|
-
// SGL-2.2: shown to admins and to account members.
|
|
1013
|
+
// GHE-1.4: per-request toolbar audience; TOOLBAR_NAV_ITEMS decides visibility.
|
|
1015
1014
|
if (
|
|
1016
1015
|
githubEnterpriseApi ||
|
|
1017
1016
|
templateService ||
|
|
@@ -1022,20 +1021,21 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1022
1021
|
const token = getCookie(c, SESSION_COOKIE);
|
|
1023
1022
|
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
1024
1023
|
const isAdmin = user?.isAdmin === true;
|
|
1025
|
-
let
|
|
1024
|
+
let hasAccount = false; // member with an account keeps Settings (SGL-2.2)
|
|
1026
1025
|
if (user && !isAdmin && accountServices) {
|
|
1027
1026
|
try {
|
|
1028
|
-
|
|
1027
|
+
hasAccount =
|
|
1029
1028
|
(await accountServices.accounts.getByMemberEmail(user.email)) !==
|
|
1030
1029
|
null;
|
|
1031
1030
|
} catch {
|
|
1032
1031
|
// nav is cosmetic — never fail the page over the lookup
|
|
1033
1032
|
}
|
|
1034
1033
|
}
|
|
1034
|
+
// Account members (SGL-2.2) get the `admin` audience: the manifest lists
|
|
1035
|
+
// Settings admin-only, and members with an account keep it.
|
|
1035
1036
|
return runWithToolbarAudience(
|
|
1036
|
-
isAdmin ? "admin" : "member",
|
|
1037
|
+
isAdmin || hasAccount ? "admin" : "member",
|
|
1037
1038
|
() => next(),
|
|
1038
|
-
{ showSettings: show },
|
|
1039
1039
|
);
|
|
1040
1040
|
});
|
|
1041
1041
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "The admin UI's actual current palette (light theme): toolbar base from lib/web/toolbar.ts plus the status/badge families from admin-ui-styles.ts. color + font only. Kept separate from theme-tokens.json, which stays PWA-chrome-only.",
|
|
3
|
+
"color": {
|
|
4
|
+
"bg": { "page": "#f7f7fb", "surface": "#ffffff", "subtle": "#f3f4f6", "muted": "#f9fafb" },
|
|
5
|
+
"border": { "default": "#e8e8ee", "strong": "#d1d5db", "subtle": "#f3f4f6" },
|
|
6
|
+
"text": { "heading": "#1a1a2e", "body": "#374151", "muted": "#6b7280", "faint": "#9ca3af" },
|
|
7
|
+
"brand": { "default": "#4f46e5", "strong": "#4338ca", "bg": "#eef2ff", "border": "#c7d2fe" },
|
|
8
|
+
"primary": { "default": "#1a1a2e", "hover": "#2d2d4e", "text": "#ffffff" },
|
|
9
|
+
"success": { "bg": "#d1fae5", "text": "#065f46", "border": "#a7f3d0" },
|
|
10
|
+
"warning": { "bg": "#fef3c7", "text": "#92400e", "border": "#fde68a" },
|
|
11
|
+
"danger": { "default": "#dc2626", "bg": "#fee2e2", "border": "#fecaca" },
|
|
12
|
+
"info": { "bg": "#dbeafe", "text": "#1e40af" },
|
|
13
|
+
"violet": { "bg": "#ede9fe", "text": "#5b21b6" },
|
|
14
|
+
"teal": { "bg": "#ccfbf1", "text": "#0f766e" }
|
|
15
|
+
},
|
|
16
|
+
"font": {
|
|
17
|
+
"family": {
|
|
18
|
+
"sans": "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/brand-tokens.unit.test.ts
|
|
3
|
+
* brand-tokens.json must be valid JSON in the agreed color(+font)-only schema
|
|
4
|
+
* and be exported from the package's exports map.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, it } from "bun:test";
|
|
8
|
+
import pkg from "../package.json";
|
|
9
|
+
import tokens from "./brand-tokens.json";
|
|
10
|
+
|
|
11
|
+
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
12
|
+
|
|
13
|
+
function leaves(node: unknown, path: string[] = []): [string, unknown][] {
|
|
14
|
+
if (node !== null && typeof node === "object") {
|
|
15
|
+
return Object.entries(node).flatMap(([k, v]) => leaves(v, [...path, k]));
|
|
16
|
+
}
|
|
17
|
+
return [[path.join("."), node]];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("brand-tokens.json", () => {
|
|
21
|
+
it("has only color and font top-level groups (plus $comment)", () => {
|
|
22
|
+
expect(Object.keys(tokens).filter((k) => k !== "$comment")).toEqual([
|
|
23
|
+
"color",
|
|
24
|
+
"font",
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("every color leaf is a 6-digit hex string", () => {
|
|
29
|
+
const colors = leaves(tokens.color);
|
|
30
|
+
expect(colors.length).toBeGreaterThan(0);
|
|
31
|
+
for (const [path, value] of colors) {
|
|
32
|
+
expect(typeof value, path).toBe("string");
|
|
33
|
+
expect(value as string, path).toMatch(HEX);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("every font leaf is a non-empty string", () => {
|
|
38
|
+
for (const [path, value] of leaves(tokens.font)) {
|
|
39
|
+
expect(typeof value, path).toBe("string");
|
|
40
|
+
expect((value as string).length, path).toBeGreaterThan(0);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("covers the status/badge families", () => {
|
|
45
|
+
for (const k of ["success", "warning", "danger", "info", "violet", "teal"]) {
|
|
46
|
+
expect(Object.keys(tokens.color), k).toContain(k);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("is exported via the package exports map", () => {
|
|
51
|
+
expect(
|
|
52
|
+
(pkg.exports as Record<string, string>)["./brand-tokens.json"],
|
|
53
|
+
).toBe("./src/brand-tokens.json");
|
|
54
|
+
});
|
|
55
|
+
});
|