@app-vitals/agent-admin 1.52.1 → 1.53.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.52.1",
3
+ "version": "1.53.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -41,8 +41,8 @@
41
41
  "db:migrate": "prisma migrate deploy --schema=prisma/schema"
42
42
  },
43
43
  "dependencies": {
44
- "@anthropic-ai/sdk": "0.135.0",
45
- "@app-vitals/agent-lib": "1.52.1",
44
+ "@anthropic-ai/sdk": "0.137.0",
45
+ "@app-vitals/agent-lib": "1.53.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
@@ -50,6 +50,8 @@
50
50
  * (the composition root) is the only file that wires a concrete extension in.
51
51
  */
52
52
 
53
+ export { getSettingsNav } from "./admin-ui-settings-layout.ts";
54
+
53
55
  import type { PoolLike } from "@app-vitals/agent-lib/pool-observability";
54
56
  import type { ErrorCapturingClient } from "@app-vitals/agent-lib/sentry";
55
57
  import type { Hono } from "hono";
@@ -84,11 +84,11 @@ export function renderGithubUsernameRow(
84
84
  </td></tr>`;
85
85
  }
86
86
 
87
- /** The "Preview access" card; the button loads the fragment from the UI route. */
87
+ /** The "Preview access" fragment (rendered inside the GitHub card); the button loads the fragment from the UI route. */
88
88
  export function renderGithubAccessCard(agentId: string): string {
89
89
  const url = `/admin/agents/${escapeHtml(agentId)}/github-access`;
90
- return `<div class="card" id="github-access-card">
91
- <div class="card-title">Preview access</div>
90
+ return `<div id="github-access-card" style="margin-top:20px">
91
+ <div class="form-label" style="font-weight:600;margin-bottom:6px">Preview access</div>
92
92
  <p style="color:#6b7280;font-size:12px;margin:0 0 12px">Shows the repos this agent's GitHub user can reach. Read-only; nothing is stored.</p>
93
93
  <button type="button" class="btn btn-primary" id="github-access-btn" data-url="${url}">Preview access</button>
94
94
  <div id="github-access-result" style="margin-top:12px"></div>
@@ -121,7 +121,7 @@ export interface GithubSyncCardState {
121
121
  }
122
122
 
123
123
  /**
124
- * The Sync card shell; it loads its repos body from the UI route on page load.
124
+ * The GitHub sync fragment (rendered inside the GitHub card); it loads its repos body from the UI route on page load.
125
125
  * Without a GH_APP_ID or a bound username the button is replaced by the
126
126
  * reason (missing App id first).
127
127
  */
@@ -142,8 +142,8 @@ export function renderGithubSyncCard(
142
142
  const loader = state.hasAppId
143
143
  ? `<div id="github-installation-body">Loading...</div>`
144
144
  : "";
145
- return `<div class="card" id="github-installation-card" data-base-url="${base}">
146
- <div class="card-title">GitHub sync</div>
145
+ return `<div id="github-installation-card" data-base-url="${base}" style="margin-top:20px">
146
+ <div class="form-label" style="font-weight:600;margin-bottom:6px">GitHub sync</div>
147
147
  <p style="color:#6b7280;font-size:12px;margin:0 0 12px">Brings this agent's App installation and its repos in line with what the bound GitHub user can push to.</p>
148
148
  ${action}
149
149
  ${loader}
@@ -1036,7 +1036,7 @@ export const AGENT_POST_SECTIONS: Readonly<Record<string, AgentSection>> = {
1036
1036
  "/review-author-allowlist/delete": "access",
1037
1037
  "/patch-author-allowlist/add": "access",
1038
1038
  "/patch-author-allowlist/delete": "access",
1039
- // Shared by the Slack access card (access) and the Agent Policy card
1039
+ // Shared by the Slack card (access) and the Agent Policy card
1040
1040
  // (configuration); see settingsRedirectSection.
1041
1041
  "/settings": "configuration",
1042
1042
  "/crons": "automation",
@@ -1062,7 +1062,7 @@ export const AGENT_POST_SECTIONS: Readonly<Record<string, AgentSection>> = {
1062
1062
  };
1063
1063
 
1064
1064
  /**
1065
- * POST /settings serves two forms: Slack access (access section, carries
1065
+ * POST /settings serves two forms: Slack (access section, carries
1066
1066
  * restrictSlackToMembers) and Agent Policy (configuration section).
1067
1067
  */
1068
1068
  export function settingsRedirectSection(formData: FormData): AgentSection {
@@ -1090,7 +1090,7 @@ export function renderAgentDetailPage(
1090
1090
  /** Section to render (SGL-1.2). Defaults to "general". */
1091
1091
  section?: AgentSection;
1092
1092
  /**
1093
- * SSP-4.3: render the Members / Slack access / Danger Zone cards. Defaults
1093
+ * SSP-4.3: render the Members / Slack / GitHub / Danger Zone cards. Defaults
1094
1094
  * to isAdmin; the caller passes true for agent-access holders when
1095
1095
  * self-serve is enabled.
1096
1096
  */
@@ -1230,7 +1230,7 @@ export function renderAgentDetailPage(
1230
1230
 
1231
1231
  // "Connect later" actions (UAP-2.3) — each hidden once its AgentEnv key is
1232
1232
  // already set, mirroring the "Sync Manifest" visibility pattern.
1233
- const connectActionConfigs: ConnectActionConfig[] = [
1233
+ const slackConnectActionConfigs: ConnectActionConfig[] = [
1234
1234
  {
1235
1235
  envKey: "SLACK_APP_TOKEN",
1236
1236
  label: "Connect Slack",
@@ -1245,6 +1245,8 @@ export function renderAgentDetailPage(
1245
1245
  },
1246
1246
  ],
1247
1247
  },
1248
+ ];
1249
+ const githubConnectActionConfigs: ConnectActionConfig[] = [
1248
1250
  {
1249
1251
  envKey: "GH_APP_ID",
1250
1252
  label: "Set up GitHub App",
@@ -1296,17 +1298,25 @@ export function renderAgentDetailPage(
1296
1298
  ],
1297
1299
  },
1298
1300
  ];
1299
- const connectActions = [
1300
- ...connectActionConfigs.map((cfg) => renderConnectAction(envVars, cfg)),
1301
- renderAddAnotherOrgAction(agent.id, envVars),
1302
- ].filter(Boolean);
1303
-
1304
- const connectActionsHtml =
1305
- connectActions.length === 0
1301
+ const connectActionsDiv = (items: string[]): string =>
1302
+ items.length === 0
1306
1303
  ? ""
1307
1304
  : `<div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:16px">
1308
- ${connectActions.join("\n ")}
1305
+ ${items.join("\n ")}
1309
1306
  </div>`;
1307
+ const slackConnectActionsHtml = connectActionsDiv(
1308
+ slackConnectActionConfigs
1309
+ .map((cfg) => renderConnectAction(envVars, cfg))
1310
+ .filter(Boolean),
1311
+ );
1312
+ const githubConnectActionsHtml = connectActionsDiv(
1313
+ [
1314
+ ...githubConnectActionConfigs.map((cfg) =>
1315
+ renderConnectAction(envVars, cfg),
1316
+ ),
1317
+ renderAddAnotherOrgAction(agent.id, envVars),
1318
+ ].filter(Boolean),
1319
+ );
1310
1320
 
1311
1321
  // Top-level rows exclude any cron parented under another (e.g. shipwright-loop's
1312
1322
  // dev-task/review/patch/deploy phases) — those render nested beneath their
@@ -1816,10 +1826,10 @@ export function renderAgentDetailPage(
1816
1826
 
1817
1827
  const canManage = opts?.canManage ?? isAdmin;
1818
1828
 
1819
- const slackAccessSection = canManage
1829
+ const slackSection = canManage
1820
1830
  ? `<div class="card">
1821
- <div class="card-title">Slack access</div>
1822
- ${connectActionsHtml}
1831
+ <div class="card-title">Slack</div>
1832
+ ${slackConnectActionsHtml}
1823
1833
  <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/settings">
1824
1834
  <div class="form-group" style="display:flex;align-items:center;gap:6px">
1825
1835
  <input
@@ -2049,7 +2059,18 @@ export function renderAgentDetailPage(
2049
2059
  ${identityRow("Federation rule ID", agent.anthropicFederationRuleId, true)}
2050
2060
  ${showGithubIdentity ? renderGithubUsernameRow(agent.id, agent.githubUsername) : ""}
2051
2061
  </tbody></table>
2052
- </div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername }) : ""}`;
2062
+ </div>`;
2063
+
2064
+ // One GitHub card: connect actions plus (admin + enterprise GitHub) the
2065
+ // Preview access and GitHub sync fragments.
2066
+ const githubCardBody = `${githubConnectActionsHtml}${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername }) : ""}`;
2067
+ const githubSection =
2068
+ canManage && githubCardBody.trim() !== ""
2069
+ ? `<div class="card">
2070
+ <div class="card-title">GitHub</div>
2071
+ ${githubCardBody}
2072
+ </div>`
2073
+ : "";
2053
2074
 
2054
2075
  // Only agents with a GitHub App can make API-signed commits. Checked state
2055
2076
  // is the SHIPWRIGHT_SIGNED_COMMITS env row; when the box is hidden the field
@@ -2084,7 +2105,7 @@ export function renderAgentDetailPage(
2084
2105
  ${agent.autoPostReviews ? "checked" : ""}
2085
2106
  />
2086
2107
  <!-- Hidden "false" fallback so an unchecked box still submits a
2087
- value (see the Slack access card's checkbox above for why). -->
2108
+ value (see the Slack card's checkbox above for why). -->
2088
2109
  <input type="hidden" name="autoPostReviews" value="false" />
2089
2110
  <label class="form-label" for="autoPostReviews" style="margin-bottom:0">Auto-post reviews</label>
2090
2111
  </div>
@@ -2233,7 +2254,7 @@ export function renderAgentDetailPage(
2233
2254
  ${dangerZoneSection}`,
2234
2255
  automation: cronJobsSection,
2235
2256
  configuration: `${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
2236
- access: `${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackAccessSection}${tokensSection}`,
2257
+ access: `${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackSection}${githubSection}${tokensSection}`,
2237
2258
  extensions: `${toolsSection}${pluginsSection}${marketplacesSection}`,
2238
2259
  };
2239
2260
 
@@ -1176,6 +1176,31 @@ describe("renderAgentDetailPage — connect-later actions", () => {
1176
1176
  expect(html).not.toContain("Connect Slack<");
1177
1177
  });
1178
1178
 
1179
+ test("GitHub card holds the connect-github forms; Slack card holds connect-slack and the restrict form but no GitHub actions", () => {
1180
+ const html = render({});
1181
+ const slackStart = html.indexOf('<div class="card-title">Slack</div>');
1182
+ const githubStart = html.indexOf('<div class="card-title">GitHub</div>');
1183
+ expect(slackStart).toBeGreaterThan(-1);
1184
+ expect(githubStart).toBeGreaterThan(-1);
1185
+ const cardEnd = (from: number) => {
1186
+ const next = html.indexOf('<div class="card">', from);
1187
+ return next === -1 ? html.length : next;
1188
+ };
1189
+ const slackCard = html.slice(slackStart, cardEnd(slackStart));
1190
+ const githubCard = html.slice(githubStart, cardEnd(githubStart));
1191
+ expect(slackCard).toContain("/connect-slack");
1192
+ expect(slackCard).toContain("Restrict Slack to members");
1193
+ expect(slackCard).not.toContain("connect-github");
1194
+ expect(slackCard).not.toContain("Set up GitHub App");
1195
+ expect(githubCard).toContain("Set up GitHub App");
1196
+ expect(githubCard).toContain("Use existing GitHub App");
1197
+ expect(githubCard).toContain("Add GitHub PAT");
1198
+ expect(githubCard).toContain("/connect-github");
1199
+ expect(githubCard).not.toContain("connect-slack");
1200
+ expect(githubCard).not.toContain("Restrict Slack");
1201
+ expect(html).not.toContain('<div class="card-title">Slack access</div>');
1202
+ });
1203
+
1179
1204
  test("Set up GitHub App (auto) action renders githubOrg plus the public-App checkbox", () => {
1180
1205
  const html = render({});
1181
1206
  const forms = html.match(
@@ -2291,7 +2316,7 @@ describe("renderAgentDetailPage — sections", () => {
2291
2316
  expect(html).not.toContain('id="ext-header"');
2292
2317
  });
2293
2318
 
2294
- test("Access renders identity, members, allowlists, slack access and tokens", () => {
2319
+ test("Access renders identity, members, allowlists, Slack, GitHub and tokens", () => {
2295
2320
  const html = render("access");
2296
2321
  expect(html).toContain("Owner &amp; identities");
2297
2322
  expect(html).toContain("member@example.com");
@@ -2302,7 +2327,9 @@ describe("renderAgentDetailPage — sections", () => {
2302
2327
  expect(html).toContain(
2303
2328
  'action="/admin/agents/agent-123/patch-author-allowlist/add"',
2304
2329
  );
2305
- expect(html).toContain('<div class="card-title">Slack access</div>');
2330
+ expect(html).toContain('<div class="card-title">Slack</div>');
2331
+ expect(html).toContain('<div class="card-title">GitHub</div>');
2332
+ expect(html).not.toContain('<div class="card-title">Slack access</div>');
2306
2333
  expect(html).toContain("Task Store Tokens");
2307
2334
  expect(html).toContain('action="/admin/agents/agent-123/tokens"');
2308
2335
  expect(html).not.toContain('<div class="card-title">Tools</div>');
@@ -2312,7 +2339,9 @@ describe("renderAgentDetailPage — sections", () => {
2312
2339
  test("Access hides members and Slack access when canManage is false", () => {
2313
2340
  const html = render("access", { canManage: false }, false);
2314
2341
  expect(html).not.toContain('action="/admin/agents/agent-123/members"');
2315
- expect(html).not.toContain('<div class="card-title">Slack access</div>');
2342
+ expect(html).not.toContain('<div class="card-title">Slack</div>');
2343
+ expect(html).not.toContain('<div class="card-title">GitHub</div>');
2344
+ expect(html).not.toContain("connect-github");
2316
2345
  expect(html).toContain("Task Store Tokens");
2317
2346
  });
2318
2347
 
@@ -4170,14 +4199,14 @@ describe("renderAgentDetailPage — canManage gating (SSP-4.3)", () => {
4170
4199
  test("non-admin without canManage: no Danger Zone / Slack access / Members cards", () => {
4171
4200
  const html = render(false);
4172
4201
  expect(html).not.toContain("Danger Zone");
4173
- expect(html).not.toContain('<div class="card-title">Slack access</div>');
4202
+ expect(html).not.toContain('<div class="card-title">Slack</div>');
4174
4203
  expect(html).not.toContain("/members");
4175
4204
  });
4176
4205
 
4177
4206
  test("non-admin with canManage: all three cards render", () => {
4178
4207
  const html = render(false, { canManage: true });
4179
4208
  expect(html).toContain("Danger Zone");
4180
- expect(html).toContain('<div class="card-title">Slack access</div>');
4209
+ expect(html).toContain('<div class="card-title">Slack</div>');
4181
4210
  expect(html).toContain(`/admin/agents/${AGENT.id}/members`);
4182
4211
  });
4183
4212
 
@@ -155,6 +155,32 @@ export function buildSettingsNav(
155
155
  return mergeSettingsNavItems(base, [...(opts.extraItems ?? [])]);
156
156
  }
157
157
 
158
+ /** The nav minus the Account item, for a viewer who has no account. */
159
+ export function withoutAccountItem(nav: SettingsNav): SettingsNav {
160
+ return {
161
+ sections: nav.sections.map((sec) => ({
162
+ ...sec,
163
+ items: sec.items.filter((i) => i.path !== SETTINGS_ACCOUNT_PATH),
164
+ })),
165
+ };
166
+ }
167
+
168
+ /** Request-context key under which the viewer-resolved nav is stored. */
169
+ export const SETTINGS_NAV_CONTEXT_KEY = "settingsNav";
170
+
171
+ /**
172
+ * The viewer-resolved settings nav for the current /admin/* request: every
173
+ * platform item whose route is registered plus all extension-contributed
174
+ * items, with the Account item omitted for a viewer without an account.
175
+ * Lets extension adminUiRoutes handlers render renderSettingsLayout without
176
+ * rebuilding a partial copy of the nav. Undefined outside the admin UI.
177
+ */
178
+ export function getSettingsNav(c: {
179
+ get(key: string): unknown;
180
+ }): SettingsNav | undefined {
181
+ return c.get(SETTINGS_NAV_CONTEXT_KEY) as SettingsNav | undefined;
182
+ }
183
+
158
184
  /** First nav item visible to the viewer, or undefined. */
159
185
  export function firstVisibleSettingsItem(
160
186
  nav: SettingsNav,
@@ -0,0 +1,166 @@
1
+ /**
2
+ * admin/src/admin-ui-settings-nav-context.smoke.test.ts
3
+ * An extension adminUiRoutes handler receives the viewer-resolved settings nav
4
+ * via getSettingsNav(c), mounted exactly as admin-boot does (after the UI app).
5
+ * Contract: each flag-gated platform item is present iff its route is
6
+ * registered.
7
+ */
8
+
9
+ import { describe, expect, it } from "bun:test";
10
+ import { Hono } from "hono";
11
+ import { mountRouteContributions } from "./admin-extension.ts";
12
+ import { makeMockDeps, makeSessionCookie } from "./admin-ui.fixtures.ts";
13
+ import { createAdminUIApp } from "./admin-ui.ts";
14
+ import {
15
+ getSettingsNav,
16
+ SETTINGS_ACCOUNT_PATH,
17
+ SETTINGS_ACCOUNTS_PATH,
18
+ SETTINGS_GHE_PATH,
19
+ SETTINGS_TEMPLATES_PATH,
20
+ type SettingsNav,
21
+ } from "./admin-ui-settings-layout.ts";
22
+
23
+ const ghe = async () =>
24
+ new Response(
25
+ JSON.stringify({ configured: false, installer: null, lookup: null }),
26
+ { status: 200, headers: { "Content-Type": "application/json" } },
27
+ );
28
+ const templateService = {
29
+ list: async () => [],
30
+ replace: async () => {
31
+ throw new Error("unused");
32
+ },
33
+ putItem: async () => {
34
+ throw new Error("unused");
35
+ },
36
+ deleteItem: async () => {},
37
+ delete: async () => {},
38
+ } as never;
39
+ const accountServices = (member: string | null) =>
40
+ ({
41
+ accounts: {
42
+ getByMemberEmail: async (e: string) =>
43
+ e === member ? ({ id: "acct-1", name: "Acme" } as never) : null,
44
+ listWithCounts: async () => [],
45
+ getWithCounts: async (id: string) => ({ id, name: "Acme" }),
46
+ },
47
+ members: {},
48
+ }) as never;
49
+ const selfServe = {
50
+ enabled: true,
51
+ contactEmail: "c@x.com",
52
+ defaultMaxAgents: 1,
53
+ };
54
+
55
+ const adminCookie = async () => `admin_session=${await makeSessionCookie()}`;
56
+
57
+ /** Reads the nav from inside an extension route; returns it as JSON. */
58
+ async function navSeenByExtension(
59
+ deps: Parameters<typeof makeMockDeps>[0],
60
+ cookie: string,
61
+ ): Promise<SettingsNav | undefined> {
62
+ const root = new Hono();
63
+ root.route("/", createAdminUIApp(makeMockDeps(deps)));
64
+ const ext = new Hono();
65
+ ext.get("/", (c) => c.json(getSettingsNav(c) ?? null));
66
+ mountRouteContributions(root, [{ path: "/admin/ext-page", app: ext }]);
67
+ const res = await root.request("/admin/ext-page", { headers: { cookie } });
68
+ expect(res.status).toBe(200);
69
+ return ((await res.json()) as SettingsNav | null) ?? undefined;
70
+ }
71
+
72
+ const paths = (nav: SettingsNav | undefined) =>
73
+ (nav?.sections ?? []).flatMap((s) => s.items.map((i) => i.path));
74
+
75
+ describe("getSettingsNav in extension adminUiRoutes", () => {
76
+ it("hands the extension the full nav incl. extension-contributed items", async () => {
77
+ const nav = await navSeenByExtension(
78
+ {
79
+ githubEnterpriseApi: ghe,
80
+ templateService,
81
+ selfServe,
82
+ accountServices: accountServices("admin@example.com"),
83
+ settingsNavItems: [
84
+ { section: "Platform", label: "Ext", path: "/admin/ext-page" },
85
+ ],
86
+ },
87
+ await adminCookie(),
88
+ );
89
+ expect(paths(nav)).toEqual([
90
+ SETTINGS_ACCOUNT_PATH,
91
+ SETTINGS_GHE_PATH,
92
+ SETTINGS_TEMPLATES_PATH,
93
+ SETTINGS_ACCOUNTS_PATH,
94
+ "/admin/ext-page",
95
+ ]);
96
+ });
97
+
98
+ it("omits the Account item for a viewer with no account", async () => {
99
+ const nav = await navSeenByExtension(
100
+ { templateService, selfServe, accountServices: accountServices(null) },
101
+ await adminCookie(),
102
+ );
103
+ expect(paths(nav)).not.toContain(SETTINGS_ACCOUNT_PATH);
104
+ expect(paths(nav)).toContain(SETTINGS_ACCOUNTS_PATH);
105
+ });
106
+
107
+ it("is undefined outside the admin UI app", async () => {
108
+ const app = new Hono();
109
+ app.get("/", (c) => c.json(getSettingsNav(c) ?? null));
110
+ expect(await (await app.request("/")).json()).toBeNull();
111
+ });
112
+ });
113
+
114
+ describe("contract: nav item present iff its route is registered", () => {
115
+ const cases: Array<{
116
+ name: string;
117
+ deps: Parameters<typeof makeMockDeps>[0];
118
+ path: string;
119
+ present: boolean;
120
+ }> = [
121
+ {
122
+ name: "GHE on",
123
+ deps: { githubEnterpriseApi: ghe },
124
+ path: SETTINGS_GHE_PATH,
125
+ present: true,
126
+ },
127
+ { name: "GHE off", deps: {}, path: SETTINGS_GHE_PATH, present: false },
128
+ {
129
+ name: "Templates on",
130
+ deps: { templateService },
131
+ path: SETTINGS_TEMPLATES_PATH,
132
+ present: true,
133
+ },
134
+ {
135
+ name: "Templates off",
136
+ deps: {},
137
+ path: SETTINGS_TEMPLATES_PATH,
138
+ present: false,
139
+ },
140
+ {
141
+ name: "Accounts on",
142
+ deps: {
143
+ selfServe,
144
+ accountServices: accountServices("admin@example.com"),
145
+ },
146
+ path: SETTINGS_ACCOUNTS_PATH,
147
+ present: true,
148
+ },
149
+ {
150
+ name: "Accounts off",
151
+ deps: {},
152
+ path: SETTINGS_ACCOUNTS_PATH,
153
+ present: false,
154
+ },
155
+ ];
156
+ for (const { name, deps, path, present } of cases) {
157
+ it(`${name}: ${path} ${present ? "present" : "absent"} and route ${present ? "registered" : "404"}`, async () => {
158
+ const cookie = await adminCookie();
159
+ const nav = await navSeenByExtension(deps, cookie);
160
+ expect(paths(nav).includes(path)).toBe(present);
161
+ const app = createAdminUIApp(makeMockDeps(deps));
162
+ const res = await app.request(path, { headers: { cookie } });
163
+ expect(res.status === 404).toBe(!present);
164
+ });
165
+ }
166
+ });
@@ -1044,6 +1044,21 @@ describe("admin UI — authenticated pages", () => {
1044
1044
  expect(
1045
1045
  html.split(`/admin/agents/${AGENT_ID}/connect-github`).length - 1,
1046
1046
  ).toBeGreaterThanOrEqual(2);
1047
+
1048
+ // Slack and GitHub connect actions live in separate cards.
1049
+ const slackStart = html.indexOf('<div class="card-title">Slack</div>');
1050
+ const githubStart = html.indexOf('<div class="card-title">GitHub</div>');
1051
+ expect(slackStart).toBeGreaterThan(-1);
1052
+ expect(githubStart).toBeGreaterThan(-1);
1053
+ expect(html).not.toContain('<div class="card-title">Slack access</div>');
1054
+ const slackEnd = html.indexOf('<div class="card">', slackStart);
1055
+ const slackCard = html.slice(
1056
+ slackStart,
1057
+ slackEnd === -1 ? html.length : slackEnd,
1058
+ );
1059
+ expect(slackCard).toContain("/connect-slack");
1060
+ expect(slackCard).not.toContain("/connect-github");
1061
+ expect(html.indexOf("/connect-github", githubStart)).toBeGreaterThan(-1);
1047
1062
  });
1048
1063
 
1049
1064
  it("SLACK_APP_TOKEN present: hides Connect Slack but still shows the GitHub actions", async () => {
@@ -1262,7 +1277,7 @@ describe("admin UI — authenticated pages", () => {
1262
1277
  expect(slackBlock).toContain('name="xoxpToken"');
1263
1278
  });
1264
1279
 
1265
- it("non-admin member viewer does not see the connect-later actions (Slack access card is admin-only)", async () => {
1280
+ it("non-admin member viewer does not see the connect-later actions (Slack and GitHub cards are admin-only)", async () => {
1266
1281
  const MEMBER_EMAIL = "member@example.com";
1267
1282
  const memberCookie = await makeSessionCookie(
1268
1283
  SESSION_SECRET,
@@ -2557,7 +2572,7 @@ describe("admin UI — agent policy fields", () => {
2557
2572
  );
2558
2573
  // Mirrors the Agent Policy card's <form> — it has no
2559
2574
  // restrictSlackToMembers input at all (that field lives in the separate
2560
- // Slack access card/form).
2575
+ // Slack card/form).
2561
2576
  const body = new URLSearchParams({
2562
2577
  autoPostReviews: "true",
2563
2578
  minConfidence: "80",
@@ -7787,7 +7802,7 @@ describe("admin UI — self-serve agent management (SSP-4.3)", () => {
7787
7802
  [true, true],
7788
7803
  [false, false],
7789
7804
  ] as const) {
7790
- it(`agent detail for an access holder ${shown ? "renders" : "hides"} Danger Zone / Slack access / Members cards when flag is ${enabled ? "on" : "off"}`, async () => {
7805
+ it(`agent detail for an access holder ${shown ? "renders" : "hides"} Danger Zone / Slack / Members cards when flag is ${enabled ? "on" : "off"}`, async () => {
7791
7806
  const cookie = await holderCookie();
7792
7807
  const app = createAdminUIApp(
7793
7808
  makeMockDeps({
@@ -7804,7 +7819,7 @@ describe("admin UI — self-serve agent management (SSP-4.3)", () => {
7804
7819
  expect(accessRes.status).toBe(200);
7805
7820
  const html = `${await res.text()}${await accessRes.text()}`;
7806
7821
  expect(html.includes("Danger Zone")).toBe(shown);
7807
- expect(html.includes('<div class="card-title">Slack access</div>')).toBe(
7822
+ expect(html.includes('<div class="card-title">Slack</div>')).toBe(
7808
7823
  shown,
7809
7824
  );
7810
7825
  expect(html.includes(`/admin/agents/${AGENT_ID}/members`)).toBe(shown);
package/src/admin-ui.ts CHANGED
@@ -42,22 +42,14 @@ import type { AccountOnboardingService } from "./account-onboarding.ts";
42
42
  import type { AccountService } from "./accounts.ts";
43
43
  import {
44
44
  type AgentDetailCardSlot,
45
- type SettingsNavContribution,
46
45
  renderAgentDetailCardSlots,
46
+ type SettingsNavContribution,
47
47
  } from "./admin-extension.ts";
48
48
  import { registerAccountRoutes } from "./admin-ui-account.ts";
49
49
  import { runWithSettingsNav } 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
- import {
53
- buildSettingsNav,
54
- firstVisibleSettingsItem,
55
- SETTINGS_ACCOUNT_PATH,
56
- } from "./admin-ui-settings-layout.ts";
57
52
  import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
58
- import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
59
- import type { AgentTemplateReconcileService } from "./agent-template-reconcile.ts";
60
- import type { AgentTemplateService } from "./agent-templates.ts";
61
53
  import {
62
54
  type GithubAccessPreviewView,
63
55
  renderGithubAccessError,
@@ -84,7 +76,7 @@ import {
84
76
  type AgentSection,
85
77
  agentSectionPath,
86
78
  isAgentSection,
87
- settingsRedirectSection,
79
+ type NewAgentTemplateItem,
88
80
  renderAgentDetailPage,
89
81
  renderAgentsPage,
90
82
  renderChatMessageBubble,
@@ -94,11 +86,19 @@ import {
94
86
  renderGithubAppInstallPage,
95
87
  renderGithubAppManifestRedirectPage,
96
88
  renderLoginPage,
97
- type NewAgentTemplateItem,
98
89
  renderNewLocalAgentPage,
99
90
  renderProvisionCompletePage,
100
91
  renderProvisionXappTokenPage,
92
+ settingsRedirectSection,
101
93
  } from "./admin-ui-pages.ts";
94
+ import {
95
+ buildSettingsNav,
96
+ firstVisibleSettingsItem,
97
+ SETTINGS_NAV_CONTEXT_KEY,
98
+ type SettingsNav,
99
+ withoutAccountItem,
100
+ } from "./admin-ui-settings-layout.ts";
101
+ import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
102
102
  import type { AgentCronJobService } from "./agent-cron-jobs.ts";
103
103
  import type { DeleteAgentFullyDeps } from "./agent-deletion.ts";
104
104
  import { deleteAgentFully } from "./agent-deletion.ts";
@@ -108,6 +108,8 @@ import type { AgentMarketplaceService } from "./agent-marketplaces.ts";
108
108
  import type { AgentMemberService } from "./agent-members.ts";
109
109
  import type { AgentPluginService } from "./agent-plugins.ts";
110
110
  import type { AgentProvisioner } from "./agent-provisioner.ts";
111
+ import type { AgentTemplateReconcileService } from "./agent-template-reconcile.ts";
112
+ import type { AgentTemplateService } from "./agent-templates.ts";
111
113
  import type { AgentTokenService } from "./agent-tokens.ts";
112
114
  import type { AgentToolService } from "./agent-tools.ts";
113
115
  import type { AgentService } from "./agents.ts";
@@ -169,7 +171,13 @@ import {
169
171
  SpecialtyTypes,
170
172
  } from "./specialty-types.ts";
171
173
 
172
- export type AdminUIEnv = { Variables: { userEmail: string; isAdmin: boolean } };
174
+ export type AdminUIEnv = {
175
+ Variables: {
176
+ userEmail: string;
177
+ isAdmin: boolean;
178
+ settingsNav?: SettingsNav;
179
+ };
180
+ };
173
181
 
174
182
  // ─── Types ────────────────────────────────────────────────────────────────────
175
183
 
@@ -949,6 +957,31 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
949
957
 
950
958
  const accountNavEnabled = Boolean(selfServe?.enabled && accountServices);
951
959
 
960
+ const settingsNav = buildSettingsNav({
961
+ githubEnterprise: Boolean(githubEnterpriseApi),
962
+ templates: Boolean(templateService),
963
+ accounts: accountNavEnabled,
964
+ extraItems: deps.settingsNavItems ?? [],
965
+ });
966
+
967
+ // Expose the viewer-resolved nav to every /admin/* handler registered after
968
+ // this point, including extension adminUiRoutes (mounted after this app).
969
+ app.use("/admin/*", async (c, next) => {
970
+ let nav = settingsNav;
971
+ if (accountNavEnabled && accountServices) {
972
+ const token = getCookie(c, SESSION_COOKIE);
973
+ const user = token ? await getSessionUser(token, sessionSecret) : null;
974
+ if (user) {
975
+ const account = await accountServices.accounts
976
+ .getByMemberEmail(user.email)
977
+ .catch(() => null);
978
+ if (!account) nav = withoutAccountItem(settingsNav);
979
+ }
980
+ }
981
+ c.set(SETTINGS_NAV_CONTEXT_KEY, nav);
982
+ await next();
983
+ });
984
+
952
985
  // GHE-1.4: the admin-only "Settings" toolbar entry.
953
986
  // SGL-2.2: shown to admins and to account members.
954
987
  if (githubEnterpriseApi || templateService || accountNavEnabled) {
@@ -3951,13 +3984,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
3951
3984
 
3952
3985
  // ─── Enterprise GitHub apps settings (GHE-1.4) ───────────────────────────
3953
3986
 
3954
- const settingsNav = buildSettingsNav({
3955
- githubEnterprise: Boolean(githubEnterpriseApi),
3956
- templates: Boolean(templateService),
3957
- accounts: accountNavEnabled,
3958
- extraItems: deps.settingsNavItems ?? [],
3959
- });
3960
-
3961
3987
  // SGL-2.2: /admin/settings lands on the first nav item the viewer can see.
3962
3988
  if (githubEnterpriseApi || templateService || accountNavEnabled) {
3963
3989
  app.get("/admin/settings", requireAuth, async (c) => {
@@ -3967,14 +3993,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
3967
3993
  const account = await accountServices.accounts
3968
3994
  .getByMemberEmail(c.var.userEmail)
3969
3995
  .catch(() => null);
3970
- if (!account) {
3971
- nav = {
3972
- sections: settingsNav.sections.map((sec) => ({
3973
- ...sec,
3974
- items: sec.items.filter((i) => i.path !== SETTINGS_ACCOUNT_PATH),
3975
- })),
3976
- };
3977
- }
3996
+ if (!account) nav = withoutAccountItem(settingsNav);
3978
3997
  }
3979
3998
  const first = firstVisibleSettingsItem(nav, c.var.isAdmin === true);
3980
3999
  if (!first) {
@@ -1 +1 @@
1
- 0.135.0
1
+ 0.137.0
package/src/server.ts CHANGED
@@ -8,58 +8,59 @@
8
8
  * - Agent runtime API at /agents/* (JSON, internal)
9
9
  */
10
10
 
11
- export { createAdminUIApp } from "./admin-ui.ts";
11
+ export { PrismaClient } from "../prisma/client/client.ts";
12
+ export type {
13
+ AdminExtension,
14
+ AdminExtensionContext,
15
+ SettingsNavContribution,
16
+ } from "./admin-extension.ts";
12
17
  export type { AdminUIDeps } from "./admin-ui.ts";
13
- export { createAdminApp } from "./agents-api.ts";
14
- export type { AdminDeps } from "./agents-api.ts";
15
- export { createAgentRuntimeApp } from "./api.ts";
18
+ export { createAdminUIApp } from "./admin-ui.ts";
16
19
  export type {
17
- AgentRuntimeDeps,
18
- AgentConfigResponse,
19
- AgentPlugin,
20
- } from "./api.ts";
21
- export { AgentEnvService } from "./agent-envs.ts";
22
- export type { AgentEnvBundle, AgentEnvEntry } from "./agent-envs.ts";
23
- export { AgentCronJobService } from "./agent-cron-jobs.ts";
20
+ RenderSettingsLayoutOptions,
21
+ SettingsNav,
22
+ SettingsNavItem,
23
+ SettingsNavSection,
24
+ } from "./admin-ui-settings-layout.ts";
25
+ export {
26
+ getSettingsNav,
27
+ mergeSettingsNavItems,
28
+ renderSettingsLayout,
29
+ } from "./admin-ui-settings-layout.ts";
24
30
  export type {
25
31
  AgentCronJob,
26
32
  CreateAgentCronJobInput,
27
33
  } from "./agent-cron-jobs.ts";
28
- export { AgentToolService } from "./agent-tools.ts";
29
- export type { AgentTool } from "./agent-tools.ts";
30
- export { AgentTokenService } from "./agent-tokens.ts";
31
- export type { AgentToken, AgentTokenValidated } from "./agent-tokens.ts";
32
- export { AgentPluginService } from "./agent-plugins.ts";
34
+ export { AgentCronJobService } from "./agent-cron-jobs.ts";
35
+ export type { AgentEnvBundle, AgentEnvEntry } from "./agent-envs.ts";
36
+ export { AgentEnvService } from "./agent-envs.ts";
33
37
  export type { AgentPlugin as AgentPluginRecord } from "./agent-plugins.ts";
34
- export { makeTokenCrypto, identityCrypto } from "./token-crypto.ts";
35
- export type { TokenCrypto } from "./token-crypto.ts";
38
+ export { AgentPluginService } from "./agent-plugins.ts";
39
+ export type { AgentToken, AgentTokenValidated } from "./agent-tokens.ts";
40
+ export { AgentTokenService } from "./agent-tokens.ts";
41
+ export type { AgentTool } from "./agent-tools.ts";
42
+ export { AgentToolService } from "./agent-tools.ts";
43
+ export type { AdminDeps } from "./agents-api.ts";
44
+ export { createAdminApp } from "./agents-api.ts";
45
+ export type {
46
+ AgentConfigResponse,
47
+ AgentPlugin,
48
+ AgentRuntimeDeps,
49
+ } from "./api.ts";
50
+ export { createAgentRuntimeApp } from "./api.ts";
36
51
  export {
37
52
  ApiError,
38
- NotFoundError,
39
- ConflictError,
53
+ BadGatewayError,
40
54
  BadRequestError,
55
+ ConflictError,
41
56
  ForbiddenError,
57
+ NotFoundError,
42
58
  UnprocessableEntityError,
43
- BadGatewayError,
44
59
  } from "./errors.ts";
45
- export { HttpSlackProvisioningClient } from "./slack-provisioning-client.ts";
46
- export type { SlackProvisioningClient } from "./slack-provisioning-client.ts";
47
- export { HttpGoogleAuthClient } from "./google-auth-client.ts";
48
60
  export type { GoogleAuthClient } from "./google-auth-client.ts";
49
- export { PrismaClient } from "../prisma/client/client.ts";
61
+ export { HttpGoogleAuthClient } from "./google-auth-client.ts";
50
62
  export { createAdminPrismaClient } from "./prisma-client.ts";
51
- export {
52
- renderSettingsLayout,
53
- mergeSettingsNavItems,
54
- } from "./admin-ui-settings-layout.ts";
55
- export type {
56
- SettingsNav,
57
- SettingsNavItem,
58
- SettingsNavSection,
59
- RenderSettingsLayoutOptions,
60
- } from "./admin-ui-settings-layout.ts";
61
- export type {
62
- AdminExtension,
63
- AdminExtensionContext,
64
- SettingsNavContribution,
65
- } from "./admin-extension.ts";
63
+ export type { SlackProvisioningClient } from "./slack-provisioning-client.ts";
64
+ export { HttpSlackProvisioningClient } from "./slack-provisioning-client.ts";
65
+ export type { TokenCrypto } from "./token-crypto.ts";
66
+ export { identityCrypto, makeTokenCrypto } from "./token-crypto.ts";