@app-vitals/agent-admin 1.44.0 → 1.45.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.44.0",
3
+ "version": "1.45.0",
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.135.0",
45
- "@app-vitals/agent-lib": "1.44.0",
45
+ "@app-vitals/agent-lib": "1.45.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
@@ -0,0 +1,77 @@
1
+ /**
2
+ * admin/src/admin-ui-settings-layout.ts
3
+ * Shared settings page layout (SGL-1.1): toolbar + left sidebar nav + content
4
+ * pane. Returns body markup — callers wrap it with renderAdminPage.
5
+ * Styles live in baseStyles() between the "Settings layout" markers.
6
+ */
7
+
8
+ import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
9
+
10
+ export interface SettingsNavItem {
11
+ label: string;
12
+ path: string;
13
+ adminOnly?: boolean;
14
+ }
15
+
16
+ export interface SettingsNavSection {
17
+ label: string;
18
+ items: SettingsNavItem[];
19
+ }
20
+
21
+ export interface SettingsNav {
22
+ sections: SettingsNavSection[];
23
+ }
24
+
25
+ export interface RenderSettingsLayoutOptions {
26
+ userName: string;
27
+ /** Raw title; rendered as the escaped H1 of the content pane. */
28
+ title: string;
29
+ nav: SettingsNav;
30
+ /** Path of the active nav item. */
31
+ active: string;
32
+ /** Pre-rendered content markup (caller-owned, not escaped). */
33
+ body: string;
34
+ /** Toolbar active path; defaults to `active`. */
35
+ toolbarPath?: string;
36
+ /** Show adminOnly items. Default false. */
37
+ isAdmin?: boolean;
38
+ }
39
+
40
+ export function renderSettingsLayout(
41
+ opts: RenderSettingsLayoutOptions,
42
+ ): string {
43
+ const isAdmin = opts.isAdmin ?? false;
44
+ const sections = opts.nav.sections
45
+ .map((s) => ({
46
+ label: s.label,
47
+ items: s.items.filter((i) => isAdmin || !i.adminOnly),
48
+ }))
49
+ .filter((s) => s.items.length > 0);
50
+
51
+ const link = (i: SettingsNavItem): string => {
52
+ const current = i.path === opts.active;
53
+ return `<a class="settings-nav-link" href="${escapeHtml(i.path)}"${current ? ' aria-current="page"' : ""}>${escapeHtml(i.label)}</a>`;
54
+ };
55
+ const sectionsHtml = sections
56
+ .map(
57
+ (s) =>
58
+ `<div class="settings-nav-section"><div class="settings-nav-label">${escapeHtml(s.label)}</div>${s.items.map(link).join("")}</div>`,
59
+ )
60
+ .join("");
61
+
62
+ const activeLabel =
63
+ sections.flatMap((s) => s.items).find((i) => i.path === opts.active)
64
+ ?.label ?? opts.title;
65
+
66
+ return `${renderAdminToolbar(opts.userName, opts.toolbarPath ?? opts.active)}
67
+ <div class="vos-page">
68
+ <div class="settings-layout">
69
+ <nav class="settings-sidebar" aria-label="Settings">${sectionsHtml}</nav>
70
+ <details class="settings-nav-mobile"><summary>${escapeHtml(activeLabel)}</summary>${sectionsHtml}</details>
71
+ <main class="settings-content">
72
+ <h1>${escapeHtml(opts.title)}</h1>
73
+ ${opts.body}
74
+ </main>
75
+ </div>
76
+ </div>`;
77
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * admin/src/admin-ui-settings-layout.unit.test.ts
3
+ * Pure string assertions for renderSettingsLayout (SGL-1.1).
4
+ */
5
+
6
+ import { describe, expect, test } from "bun:test";
7
+ import {
8
+ renderSettingsLayout,
9
+ type SettingsNav,
10
+ } from "./admin-ui-settings-layout.ts";
11
+
12
+ const nav: SettingsNav = {
13
+ sections: [
14
+ {
15
+ label: "Account",
16
+ items: [
17
+ { label: "Profile", path: "/admin/settings/profile" },
18
+ { label: "Tokens", path: "/admin/settings/tokens" },
19
+ ],
20
+ },
21
+ {
22
+ label: "Admin",
23
+ items: [
24
+ { label: "Users", path: "/admin/settings/users", adminOnly: true },
25
+ ],
26
+ },
27
+ ],
28
+ };
29
+
30
+ const render = (over: Record<string, unknown> = {}) =>
31
+ renderSettingsLayout({
32
+ userName: "dan",
33
+ title: "Profile",
34
+ nav,
35
+ active: "/admin/settings/profile",
36
+ body: "<p>BODY</p>",
37
+ ...over,
38
+ });
39
+
40
+ describe("renderSettingsLayout", () => {
41
+ test("marks the active item with aria-current and only that item", () => {
42
+ const html = render();
43
+ const matches = html.match(/aria-current="page"/g) ?? [];
44
+ // one in desktop nav, one in mobile details
45
+ expect(matches.length).toBe(2);
46
+ expect(html).toMatch(
47
+ /<a [^>]*href="\/admin\/settings\/profile"[^>]*aria-current="page"/,
48
+ );
49
+ expect(html).not.toMatch(
50
+ /href="\/admin\/settings\/tokens"[^>]*aria-current/,
51
+ );
52
+ });
53
+
54
+ test("renders section labels, title H1, body and toolbar", () => {
55
+ const html = render();
56
+ expect(html).toContain("Account");
57
+ expect(html).toContain("<h1");
58
+ expect(html).toContain("Profile</h1>");
59
+ expect(html).toContain("<p>BODY</p>");
60
+ expect(html).toContain('class="vos-page');
61
+ expect(html).toContain("vos-toolbar");
62
+ });
63
+
64
+ test("filters adminOnly items and drops empty sections unless isAdmin", () => {
65
+ const html = render();
66
+ expect(html).not.toContain("Users");
67
+ expect(html).not.toContain(">Admin<");
68
+ const admin = render({ isAdmin: true });
69
+ expect(admin).toContain("Users");
70
+ expect(admin).toContain(">Admin<");
71
+ });
72
+
73
+ test("escapes title, labels, paths and active", () => {
74
+ const evil: SettingsNav = {
75
+ sections: [
76
+ {
77
+ label: "<s>sec</s>",
78
+ items: [{ label: "<b>x</b>", path: '/a"onclick="y' }],
79
+ },
80
+ ],
81
+ };
82
+ const html = render({
83
+ title: "<script>t</script>",
84
+ nav: evil,
85
+ active: '/a"onclick="y',
86
+ });
87
+ expect(html).not.toContain("<script>t");
88
+ expect(html).not.toContain("<b>x</b>");
89
+ expect(html).not.toContain("<s>sec");
90
+ expect(html).not.toContain('"onclick="y');
91
+ expect(html).toContain("&lt;script&gt;t&lt;/script&gt;");
92
+ });
93
+
94
+ test("renders desktop nav and mobile details with active label summary", () => {
95
+ const html = render();
96
+ expect(html).toContain('<nav class="settings-sidebar"');
97
+ expect(html).toContain('<details class="settings-nav-mobile"');
98
+ expect(html).toMatch(/<summary[^>]*>Profile<\/summary>/);
99
+ expect(html.match(/href="\/admin\/settings\/tokens"/g)?.length).toBe(2);
100
+ });
101
+
102
+ test("toolbarPath defaults to active", () => {
103
+ const withPath = render({ toolbarPath: "/admin/settings" });
104
+ expect(withPath).toContain("vos-toolbar");
105
+ });
106
+ });
@@ -636,6 +636,95 @@ export function baseStyles(): string {
636
636
  }
637
637
  }
638
638
 
639
+ /* ─── Settings layout ─── */
640
+ .settings-layout {
641
+ display: flex;
642
+ align-items: flex-start;
643
+ gap: 32px;
644
+ }
645
+ .settings-sidebar {
646
+ flex: 0 0 260px;
647
+ width: 260px;
648
+ padding-right: 16px;
649
+ border-right: 1px solid #e8e8ee;
650
+ }
651
+ .settings-nav-mobile { display: none; }
652
+ .settings-nav-section { margin-bottom: 16px; }
653
+ .settings-nav-label {
654
+ font-size: 12px;
655
+ font-weight: 600;
656
+ color: #6b7280;
657
+ text-transform: uppercase;
658
+ letter-spacing: 0.04em;
659
+ padding: 0 12px 6px;
660
+ margin-bottom: 6px;
661
+ border-bottom: 1px solid #e8e8ee;
662
+ }
663
+ .settings-nav-link {
664
+ display: block;
665
+ padding: 6px 12px;
666
+ border-radius: 6px;
667
+ font-size: 14px;
668
+ color: #1a1a2e;
669
+ text-decoration: none;
670
+ }
671
+ .settings-nav-link:hover { background: #f7f7fb; }
672
+ .settings-nav-link[aria-current="page"] {
673
+ background: #eef2ff;
674
+ color: #4f46e5;
675
+ font-weight: 600;
676
+ }
677
+ .settings-content { flex: 1 1 auto; min-width: 0; }
678
+ .settings-content h1 {
679
+ font-size: 24px;
680
+ font-weight: 600;
681
+ color: #1a1a2e;
682
+ margin: 0 0 24px;
683
+ padding-bottom: 12px;
684
+ border-bottom: 1px solid #e8e8ee;
685
+ }
686
+ .settings-section-title {
687
+ font-size: 18px;
688
+ font-weight: 600;
689
+ color: #1a1a2e;
690
+ margin: 32px 0 16px;
691
+ padding-bottom: 8px;
692
+ border-bottom: 1px solid #e8e8ee;
693
+ }
694
+ .settings-danger-zone {
695
+ border: 1px solid #dc2626;
696
+ background: #fff;
697
+ border-radius: 8px;
698
+ padding: 16px 20px;
699
+ margin-top: 16px;
700
+ }
701
+ .settings-danger-zone > .settings-section-title {
702
+ color: #dc2626;
703
+ margin-top: 0;
704
+ border-bottom-color: #fee2e2;
705
+ }
706
+ @media (max-width: ${BREAKPOINT_MOBILE_MAX}px) {
707
+ .settings-layout { flex-direction: column; gap: 16px; }
708
+ .settings-sidebar { display: none; }
709
+ .settings-nav-mobile {
710
+ display: block;
711
+ width: 100%;
712
+ border: 1px solid #e8e8ee;
713
+ border-radius: 8px;
714
+ background: #fff;
715
+ }
716
+ .settings-nav-mobile summary {
717
+ padding: 12px;
718
+ min-height: 44px;
719
+ box-sizing: border-box;
720
+ cursor: pointer;
721
+ font-weight: 600;
722
+ color: #4f46e5;
723
+ }
724
+ .settings-nav-mobile .settings-nav-link { padding: 12px; }
725
+ }
726
+ /* ─── /Settings layout ─── */
727
+
639
728
  /* ─── Tablet band (641–${BREAKPOINT_TABLET_MAX}px) ──────────────── */
640
729
  @media (min-width: ${BREAKPOINT_MOBILE_MAX + 1}px) and (max-width: ${BREAKPOINT_TABLET_MAX}px) {
641
730
  .vos-page {
@@ -101,3 +101,75 @@ describe("baseStyles — AXR-1.1 shared explore board component classes", () =>
101
101
  expect(css).toContain(".badge-warning");
102
102
  });
103
103
  });
104
+
105
+ describe("baseStyles — SGL-1.1 settings layout", () => {
106
+ const css = baseStyles();
107
+ const start = css.indexOf("/* ─── Settings layout ─── */");
108
+ const end = css.indexOf("/* ─── /Settings layout ─── */");
109
+ const block = css.slice(start, end);
110
+
111
+ test("marker-delimited block exists with the new classes", () => {
112
+ expect(start).toBeGreaterThan(-1);
113
+ expect(end).toBeGreaterThan(start);
114
+ for (const cls of [
115
+ ".settings-sidebar",
116
+ ".settings-nav-mobile",
117
+ ".settings-content",
118
+ ".settings-section-title",
119
+ ".settings-danger-zone",
120
+ ]) {
121
+ expect(block).toContain(cls);
122
+ }
123
+ });
124
+
125
+ test("mobile media block references the settings classes", () => {
126
+ const media = block.slice(
127
+ block.indexOf(`@media (max-width: ${BREAKPOINT_MOBILE_MAX}px)`),
128
+ );
129
+ expect(media).toContain(".settings-sidebar");
130
+ expect(media).toContain(".settings-nav-mobile");
131
+ });
132
+
133
+ test("uses only allowed hex colors", () => {
134
+ const allowed = new Set(
135
+ [
136
+ "#1a1a2e",
137
+ "#4f46e5",
138
+ "#eef2ff",
139
+ "#e8e8ee",
140
+ "#f7f7fb",
141
+ "#dc2626",
142
+ "#fee2e2",
143
+ "#6b7280",
144
+ "#fff",
145
+ "#f3f4f6",
146
+ "#065f46",
147
+ "#0f766e",
148
+ "#22c55e",
149
+ "#2d2d4e",
150
+ "#374151",
151
+ "#4338ca",
152
+ "#5b21b6",
153
+ "#92400e",
154
+ "#9ca3af",
155
+ "#a7f3d0",
156
+ "#c7d2fe",
157
+ "#ccfbf1",
158
+ "#d1d5db",
159
+ "#d1fae5",
160
+ "#e5e7eb",
161
+ "#ede9fe",
162
+ "#ef4444",
163
+ "#f59e0b",
164
+ "#f9fafb",
165
+ "#fafafa",
166
+ "#fde68a",
167
+ "#fecaca",
168
+ "#fef3c7",
169
+ ].map((c) => c.toLowerCase()),
170
+ );
171
+ const found = block.match(/#[0-9a-fA-F]{3,8}\b/g) ?? [];
172
+ expect(found.length).toBeGreaterThan(0);
173
+ for (const c of found) expect(allowed.has(c.toLowerCase())).toBe(true);
174
+ });
175
+ });