@app-vitals/agent-admin 1.49.0 → 1.51.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/e2e/agents-page.e2e.ts +61 -21
- package/e2e/marketplaces-section.e2e.ts +5 -24
- package/e2e/plugins-section.e2e.ts +6 -27
- package/package.json +2 -2
- package/src/admin-ui-account-nav.ts +3 -14
- package/src/admin-ui-account-nav.unit.test.ts +5 -14
- package/src/admin-ui-account-pages.ts +21 -10
- package/src/admin-ui-account-pages.unit.test.ts +12 -12
- package/src/admin-ui-account.smoke.test.ts +4 -0
- package/src/admin-ui-account.ts +5 -0
- package/src/admin-ui-accounts-pages.ts +36 -16
- package/src/admin-ui-accounts-pages.unit.test.ts +29 -0
- package/src/admin-ui-accounts.smoke.test.ts +2 -0
- package/src/admin-ui-accounts.ts +10 -1
- package/src/admin-ui-agent-sections.unit.test.ts +95 -0
- package/src/admin-ui-agent-template.smoke.test.ts +22 -16
- package/src/admin-ui-github-identity-pages.unit.test.ts +22 -1
- package/src/admin-ui-github-identity.smoke.test.ts +1 -1
- package/src/admin-ui-installation-repos.smoke.test.ts +7 -7
- package/src/admin-ui-pages.ts +137 -110
- package/src/admin-ui-pages.unit.test.ts +166 -225
- package/src/admin-ui-settings-layout.ts +24 -6
- package/src/admin-ui-settings.smoke.test.ts +28 -0
- package/src/admin-ui-styles.ts +1 -70
- package/src/admin-ui.smoke.test.ts +171 -69
- package/src/admin-ui.ts +211 -131
|
@@ -136,3 +136,32 @@ describe("renderAgentsPage Account column", () => {
|
|
|
136
136
|
expect(html).not.toContain("<th>Account</th>");
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
describe("accounts pages in the settings shell (SGL-2.3)", () => {
|
|
141
|
+
test("list page renders in the layout with Accounts active", () => {
|
|
142
|
+
const html = renderAccountsListPage({
|
|
143
|
+
userEmail: "a@x.com",
|
|
144
|
+
accounts: [],
|
|
145
|
+
owners: new Map(),
|
|
146
|
+
});
|
|
147
|
+
expect(html).toContain("settings-sidebar");
|
|
148
|
+
expect(html).toContain(
|
|
149
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("detail page puts Suspend in the shared danger box", () => {
|
|
154
|
+
const html = renderAccountDetailPage({
|
|
155
|
+
userEmail: "a@x.com",
|
|
156
|
+
account,
|
|
157
|
+
agents: [],
|
|
158
|
+
members: [],
|
|
159
|
+
invites: [],
|
|
160
|
+
});
|
|
161
|
+
expect(html).toContain("settings-danger-zone");
|
|
162
|
+
expect(html).toContain("/admin/accounts/a1/suspend");
|
|
163
|
+
expect(html).toContain(
|
|
164
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -250,6 +250,8 @@ describe("/admin/accounts", () => {
|
|
|
250
250
|
const body = await res.text();
|
|
251
251
|
expect(body).toContain("Acme");
|
|
252
252
|
expect(body).toContain("owner@x.com");
|
|
253
|
+
expect(body).toContain("settings-sidebar");
|
|
254
|
+
expect(body).toContain('href="/admin/accounts" aria-current="page"');
|
|
253
255
|
});
|
|
254
256
|
|
|
255
257
|
it("403 for non-admin on every route", async () => {
|
package/src/admin-ui-accounts.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
renderAccountDetailPage,
|
|
24
24
|
renderAccountsListPage,
|
|
25
25
|
} from "./admin-ui-accounts-pages.ts";
|
|
26
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
26
27
|
import { reconcileAgentAfterAccountChange } from "./agent-account-assignment.ts";
|
|
27
28
|
import type { AgentProvisioner } from "./agent-provisioner.ts";
|
|
28
29
|
import type { AgentService } from "./agents.ts";
|
|
@@ -46,6 +47,8 @@ export interface AdminAccountsRouteDeps {
|
|
|
46
47
|
/** SSP-5.3: assign/unassign agents (admin only). */
|
|
47
48
|
agents: Pick<AgentService, "getDetail" | "updateFields">;
|
|
48
49
|
provisioner: Pick<AgentProvisioner, "reconcile">;
|
|
50
|
+
/** Settings sidebar nav (SGL-2.3). */
|
|
51
|
+
settingsNav?: SettingsNav;
|
|
49
52
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -82,7 +85,12 @@ export function registerAdminAccountsRoutes(
|
|
|
82
85
|
}),
|
|
83
86
|
);
|
|
84
87
|
return deps.html(
|
|
85
|
-
renderAccountsListPage({
|
|
88
|
+
renderAccountsListPage({
|
|
89
|
+
userEmail: c.var.userEmail,
|
|
90
|
+
accounts,
|
|
91
|
+
owners,
|
|
92
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
93
|
+
}),
|
|
86
94
|
);
|
|
87
95
|
});
|
|
88
96
|
|
|
@@ -107,6 +115,7 @@ export function registerAdminAccountsRoutes(
|
|
|
107
115
|
members,
|
|
108
116
|
invites,
|
|
109
117
|
error,
|
|
118
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
110
119
|
}),
|
|
111
120
|
{ status },
|
|
112
121
|
);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import {
|
|
4
|
+
AGENT_POST_SECTIONS,
|
|
5
|
+
AGENT_SECTIONS,
|
|
6
|
+
agentSectionPath,
|
|
7
|
+
} from "./admin-ui-pages.ts";
|
|
8
|
+
|
|
9
|
+
const source = readFileSync(new URL("./admin-ui.ts", import.meta.url), "utf8");
|
|
10
|
+
|
|
11
|
+
interface Handler {
|
|
12
|
+
route: string;
|
|
13
|
+
suffix: string;
|
|
14
|
+
body: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Every `app.<method>("/admin/agents/:id/...")` registration with its body. */
|
|
18
|
+
function agentHandlers(method: "post" | "get"): Handler[] {
|
|
19
|
+
const re = /app\.(get|post)\(\s*"(\/admin\/agents\/:id(\/[^"]*)?)"/g;
|
|
20
|
+
const hits = [...source.matchAll(re)];
|
|
21
|
+
const all = [...source.matchAll(/\n {2}app\.(get|post|put|delete)\(/g)];
|
|
22
|
+
return hits
|
|
23
|
+
.filter((m) => m[1] === method)
|
|
24
|
+
.map((m) => {
|
|
25
|
+
const start = m.index ?? 0;
|
|
26
|
+
const next = all.find((a) => (a.index ?? 0) > start);
|
|
27
|
+
return {
|
|
28
|
+
route: m[2] as string,
|
|
29
|
+
suffix: (m[3] ?? "") as string,
|
|
30
|
+
body: source.slice(start, next?.index ?? source.length),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("agent POST handler to section table (SGL-1.3)", () => {
|
|
36
|
+
const posts = agentHandlers("post");
|
|
37
|
+
|
|
38
|
+
test("scan finds the registered handlers", () => {
|
|
39
|
+
expect(posts.length).toBeGreaterThan(25);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("every POST /admin/agents/:id/* handler has a section entry", () => {
|
|
43
|
+
const missing = posts
|
|
44
|
+
.map((h) => h.suffix)
|
|
45
|
+
.filter((s) => s !== "" && !(s in AGENT_POST_SECTIONS));
|
|
46
|
+
expect(missing).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("the table has no stale entries", () => {
|
|
50
|
+
const registered = new Set(posts.map((h) => h.suffix));
|
|
51
|
+
const stale = Object.keys(AGENT_POST_SECTIONS).filter(
|
|
52
|
+
(k) => !registered.has(k),
|
|
53
|
+
);
|
|
54
|
+
expect(stale).toEqual([]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("table values are real sections", () => {
|
|
58
|
+
for (const s of Object.values(AGENT_POST_SECTIONS)) {
|
|
59
|
+
expect(AGENT_SECTIONS).toContain(s);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("no handler redirects to a bare /admin/agents/:id path", () => {
|
|
64
|
+
expect(source).not.toMatch(
|
|
65
|
+
/`\/admin\/agents\/\$\{(agentId|result\.agentId)\}(\?|`)/,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("each handler's redirects use the section its card lives in", () => {
|
|
70
|
+
const bad: string[] = [];
|
|
71
|
+
for (const h of posts) {
|
|
72
|
+
const expected = AGENT_POST_SECTIONS[h.suffix];
|
|
73
|
+
if (!expected || h.suffix === "/settings") continue;
|
|
74
|
+
for (const m of h.body.matchAll(
|
|
75
|
+
/agentSectionPath\(\s*[\w.]+,\s*"(\w+)"/g,
|
|
76
|
+
)) {
|
|
77
|
+
if (m[1] !== expected) bad.push(`${h.suffix}: ${m[1]} != ${expected}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
expect(bad).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("error/success/warning params survive on every section", () => {
|
|
84
|
+
for (const section of AGENT_SECTIONS) {
|
|
85
|
+
const p = agentSectionPath("a1", section, {
|
|
86
|
+
error: "bad thing",
|
|
87
|
+
success: "ok",
|
|
88
|
+
});
|
|
89
|
+
const url = new URL(p, "http://x");
|
|
90
|
+
expect(url.searchParams.get("error")).toBe("bad thing");
|
|
91
|
+
expect(url.searchParams.get("success")).toBe("ok");
|
|
92
|
+
expect(url.pathname).toBe(agentSectionPath("a1", section));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -139,15 +139,24 @@ const post = (
|
|
|
139
139
|
},
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
/** Concatenated HTML of every agent section page (the template UI is spread across them). */
|
|
143
|
+
async function allSectionsHtml(
|
|
144
|
+
app: ReturnType<typeof createAdminUIApp>,
|
|
145
|
+
): Promise<string> {
|
|
146
|
+
const pages = await Promise.all(
|
|
147
|
+
["", "/automation", "/configuration", "/extensions"].map(async (s) =>
|
|
148
|
+
(await get(app, `/admin/agents/${AGENT_ID}${s}`)).text(),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
return pages.join("\n");
|
|
152
|
+
}
|
|
153
|
+
|
|
142
154
|
describe("agent page template badges (ATP-2.4)", () => {
|
|
143
155
|
it("marks every env, tool, plugin and cron as inherited or custom", async () => {
|
|
144
156
|
const { api } = fakeAgentsApi();
|
|
145
|
-
const html = await (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`/admin/agents/${AGENT_ID}`,
|
|
149
|
-
)
|
|
150
|
-
).text();
|
|
157
|
+
const html = await allSectionsHtml(
|
|
158
|
+
createAdminUIApp(detailDeps({ agentsApi: api })),
|
|
159
|
+
);
|
|
151
160
|
// 1 env + 1 tool + 1 plugin + 1 cron inherited; 1 env + 1 tool custom.
|
|
152
161
|
expect(html.match(/data-source="template"/g)).toHaveLength(4);
|
|
153
162
|
expect(html.match(/data-source="custom"/g)).toHaveLength(2);
|
|
@@ -184,13 +193,13 @@ describe("agent page template badges (ATP-2.4)", () => {
|
|
|
184
193
|
},
|
|
185
194
|
}),
|
|
186
195
|
);
|
|
187
|
-
const before = await (
|
|
196
|
+
const before = await allSectionsHtml(app);
|
|
188
197
|
expect(before).toContain('data-source="template"');
|
|
189
198
|
await post(app, `/admin/agents/${AGENT_ID}/envs`, {
|
|
190
199
|
key: "TPL_KEY",
|
|
191
200
|
value: "mine",
|
|
192
201
|
});
|
|
193
|
-
const after = await (
|
|
202
|
+
const after = await allSectionsHtml(app);
|
|
194
203
|
expect(after).not.toContain('data-source="template"');
|
|
195
204
|
expect(after).toContain('data-source="custom"');
|
|
196
205
|
});
|
|
@@ -200,7 +209,7 @@ describe("detach / reattach (ATP-2.4)", () => {
|
|
|
200
209
|
it("attached agent offers Detach; POST calls the detach endpoint", async () => {
|
|
201
210
|
const { api, calls } = fakeAgentsApi();
|
|
202
211
|
const app = createAdminUIApp(detailDeps({ agentsApi: api }));
|
|
203
|
-
const html = await (
|
|
212
|
+
const html = await allSectionsHtml(app);
|
|
204
213
|
expect(html).toContain(`/admin/agents/${AGENT_ID}/template/detach`);
|
|
205
214
|
expect(html).not.toContain(`/template/reattach`);
|
|
206
215
|
|
|
@@ -221,7 +230,7 @@ describe("detach / reattach (ATP-2.4)", () => {
|
|
|
221
230
|
const app = createAdminUIApp(
|
|
222
231
|
detailDeps({ agentsApi: api, detached: true }),
|
|
223
232
|
);
|
|
224
|
-
const html = await (
|
|
233
|
+
const html = await allSectionsHtml(app);
|
|
225
234
|
expect(html).toContain("Detached from template");
|
|
226
235
|
expect(html).toContain(`/admin/agents/${AGENT_ID}/template/reattach`);
|
|
227
236
|
expect(html).not.toContain(`/template/detach`);
|
|
@@ -257,12 +266,9 @@ describe("detach / reattach (ATP-2.4)", () => {
|
|
|
257
266
|
describe("reset to template (ATP-2.4)", () => {
|
|
258
267
|
it("custom rows get a per-item reset; template rows do not", async () => {
|
|
259
268
|
const { api } = fakeAgentsApi();
|
|
260
|
-
const html = await (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
`/admin/agents/${AGENT_ID}`,
|
|
264
|
-
)
|
|
265
|
-
).text();
|
|
269
|
+
const html = await allSectionsHtml(
|
|
270
|
+
createAdminUIApp(detailDeps({ agentsApi: api })),
|
|
271
|
+
);
|
|
266
272
|
// custom env MINE and custom tool Bash(ls:*) -> 2 per-item resets, plus
|
|
267
273
|
// the agent-wide reset.
|
|
268
274
|
expect(html.match(/name="kind" value="(env|tool)"/g)).toHaveLength(2);
|
|
@@ -11,7 +11,28 @@ import {
|
|
|
11
11
|
renderGithubAccessResult,
|
|
12
12
|
renderGithubUsernameRow,
|
|
13
13
|
} from "./admin-ui-github-identity-pages.ts";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
AGENT_SECTIONS,
|
|
16
|
+
type AgentDetail,
|
|
17
|
+
renderAgentDetailPage as renderAgentDetailSection,
|
|
18
|
+
} from "./admin-ui-pages.ts";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Renders every agent detail section (SGL-1.2) concatenated, so card-level
|
|
22
|
+
* assertions don't depend on which section a card lives in. Pass
|
|
23
|
+
* `opts.section` to render a single section instead.
|
|
24
|
+
*/
|
|
25
|
+
function renderAgentDetailPage(
|
|
26
|
+
...args: Parameters<typeof renderAgentDetailSection>
|
|
27
|
+
): string {
|
|
28
|
+
const opts = args[9];
|
|
29
|
+
if (opts?.section) return renderAgentDetailSection(...args);
|
|
30
|
+
return AGENT_SECTIONS.map((section) => {
|
|
31
|
+
const a = [...args] as typeof args;
|
|
32
|
+
a[9] = { ...opts, section };
|
|
33
|
+
return renderAgentDetailSection(...a);
|
|
34
|
+
}).join("\n");
|
|
35
|
+
}
|
|
15
36
|
|
|
16
37
|
const AGENT: AgentDetail = {
|
|
17
38
|
id: "agent-123",
|
|
@@ -82,7 +82,7 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
82
82
|
);
|
|
83
83
|
});
|
|
84
84
|
const get = (app: ReturnType<typeof setup>["app"], cookie: string) =>
|
|
85
|
-
app.request(`/admin/agents/${AGENT_ID}`, {
|
|
85
|
+
app.request(`/admin/agents/${AGENT_ID}/access`, {
|
|
86
86
|
headers: { Cookie: `admin_session=${cookie}` },
|
|
87
87
|
});
|
|
88
88
|
const post = (
|
|
@@ -118,7 +118,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
118
118
|
describe("card presence", () => {
|
|
119
119
|
it("shows the Sync button and no input when both Apps are configured", async () => {
|
|
120
120
|
const { app } = setup({ agentsApi: () => json(INSTALLED) });
|
|
121
|
-
const html = await (await get(app, "")).text();
|
|
121
|
+
const html = await (await get(app, "/access")).text();
|
|
122
122
|
expect(html).toContain('id="github-installation-card"');
|
|
123
123
|
expect(html).toContain('id="github-sync-btn"');
|
|
124
124
|
const card = html.slice(html.indexOf('id="github-installation-card"'));
|
|
@@ -134,7 +134,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
134
134
|
lookup: null,
|
|
135
135
|
},
|
|
136
136
|
});
|
|
137
|
-
const html = await (await get(app, "")).text();
|
|
137
|
+
const html = await (await get(app, "/access")).text();
|
|
138
138
|
expect(html).not.toContain("github-installation-card");
|
|
139
139
|
});
|
|
140
140
|
|
|
@@ -146,7 +146,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
146
146
|
lookup: { role: "lookup" },
|
|
147
147
|
},
|
|
148
148
|
});
|
|
149
|
-
const html = await (await get(app, "")).text();
|
|
149
|
+
const html = await (await get(app, "/access")).text();
|
|
150
150
|
expect(html).not.toContain("github-installation-card");
|
|
151
151
|
});
|
|
152
152
|
|
|
@@ -154,20 +154,20 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
154
154
|
const { app } = setup({
|
|
155
155
|
enterprise: { configured: false, installer: null, lookup: null },
|
|
156
156
|
});
|
|
157
|
-
const html = await (await get(app, "")).text();
|
|
157
|
+
const html = await (await get(app, "/access")).text();
|
|
158
158
|
expect(html).not.toContain("github-installation-card");
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
it("shows the missing-App-id reason, not the button, with no GH_APP_ID", async () => {
|
|
162
162
|
const { app } = setup({ env: { FOO: "bar" } });
|
|
163
|
-
const html = await (await get(app, "")).text();
|
|
163
|
+
const html = await (await get(app, "/access")).text();
|
|
164
164
|
expect(html).toContain('data-reason="missing-app-id"');
|
|
165
165
|
expect(html).not.toContain('id="github-sync-btn"');
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it("shows the no-username reason, not the button, with no bound user", async () => {
|
|
169
169
|
const { app } = setup({ username: null });
|
|
170
|
-
const html = await (await get(app, "")).text();
|
|
170
|
+
const html = await (await get(app, "/access")).text();
|
|
171
171
|
expect(html).toContain('data-reason="no-username"');
|
|
172
172
|
expect(html).not.toContain('id="github-sync-btn"');
|
|
173
173
|
});
|
|
@@ -409,7 +409,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
409
409
|
repos: ["acme/api", "ACME/Web", "other/gone"],
|
|
410
410
|
agentsApi: api,
|
|
411
411
|
});
|
|
412
|
-
const html = await (await get(app, "")).text();
|
|
412
|
+
const html = await (await get(app, "/configuration")).text();
|
|
413
413
|
expect(html).toContain('id="repos-uncovered-warning"');
|
|
414
414
|
expect(html).toContain("other/gone");
|
|
415
415
|
expect(html.match(/data-uncovered="1"/g)?.length).toBe(1);
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
uncoveredRepos,
|
|
23
23
|
} from "./admin-ui-installation-repos-pages.ts";
|
|
24
24
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
25
|
+
import { renderSettingsLayout } from "./admin-ui-settings-layout.ts";
|
|
25
26
|
import {
|
|
26
27
|
BREAKPOINT_MOBILE_MAX,
|
|
27
28
|
escapeHtml,
|
|
@@ -973,31 +974,99 @@ function renderConnectAction(
|
|
|
973
974
|
</details>`;
|
|
974
975
|
}
|
|
975
976
|
|
|
977
|
+
export const AGENT_SECTIONS = [
|
|
978
|
+
"general",
|
|
979
|
+
"automation",
|
|
980
|
+
"configuration",
|
|
981
|
+
"access",
|
|
982
|
+
"extensions",
|
|
983
|
+
] as const;
|
|
984
|
+
export type AgentSection = (typeof AGENT_SECTIONS)[number];
|
|
985
|
+
|
|
986
|
+
export function isAgentSection(value: string): value is AgentSection {
|
|
987
|
+
return (AGENT_SECTIONS as readonly string[]).includes(value);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
const AGENT_SECTION_LABELS: Record<AgentSection, string> = {
|
|
991
|
+
general: "General",
|
|
992
|
+
automation: "Automation",
|
|
993
|
+
configuration: "Configuration",
|
|
994
|
+
access: "Access",
|
|
995
|
+
extensions: "Extensions",
|
|
996
|
+
};
|
|
997
|
+
|
|
976
998
|
/**
|
|
977
|
-
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
* auto-open behavior for any group.
|
|
982
|
-
*
|
|
983
|
-
* `stat` is a short, pre-formatted, trusted (non-user-controlled) string
|
|
984
|
-
* (e.g. "5 system · 7 custom") rendered flush-right in the summary row.
|
|
985
|
-
* `name` (also trusted/static) is the group title, rendered flush-left.
|
|
986
|
-
* The toggle indicator (▸/▾) is a `::before` on the `.group-title` span
|
|
987
|
-
* itself — NOT on the flex `.group-summary` — so it stays part of that one
|
|
988
|
-
* flex child instead of becoming its own third flex item, which would break
|
|
989
|
-
* the flush-left/flush-right 2-sided layout into an uneven 3-way split.
|
|
999
|
+
* Path of one agent detail section (SGL-1.2). General is the bare agent path,
|
|
1000
|
+
* so existing links and redirects to /admin/agents/:id keep landing there.
|
|
1001
|
+
* `query` params (e.g. error / success / warning) are URL-encoded and appended
|
|
1002
|
+
* so post-action redirects keep their banner on the section that owns the card.
|
|
990
1003
|
*/
|
|
991
|
-
function
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1004
|
+
export function agentSectionPath(
|
|
1005
|
+
agentId: string,
|
|
1006
|
+
section: AgentSection = "general",
|
|
1007
|
+
query?: Record<string, string | undefined>,
|
|
1008
|
+
): string {
|
|
1009
|
+
const base = `/admin/agents/${encodeURIComponent(agentId)}`;
|
|
1010
|
+
const path = section === "general" ? base : `${base}/${section}`;
|
|
1011
|
+
const qs = Object.entries(query ?? {})
|
|
1012
|
+
.filter((e): e is [string, string] => e[1] !== undefined)
|
|
1013
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
1014
|
+
.join("&");
|
|
1015
|
+
return qs ? `${path}?${qs}` : path;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Section each POST /admin/agents/:id/* handler redirects back to (SGL-1.3):
|
|
1020
|
+
* the section whose card renders the handler's form. Keys are the route path
|
|
1021
|
+
* after `/admin/agents/:id`. A unit test scans admin-ui.ts so a new handler
|
|
1022
|
+
* cannot be added without an entry here.
|
|
1023
|
+
*/
|
|
1024
|
+
export const AGENT_POST_SECTIONS: Readonly<Record<string, AgentSection>> = {
|
|
1025
|
+
"/github-username": "access",
|
|
1026
|
+
"/github-sync/apply-confirmed": "access",
|
|
1027
|
+
"/repos/remove-confirmed": "configuration",
|
|
1028
|
+
"/envs": "configuration",
|
|
1029
|
+
"/template/detach": "configuration",
|
|
1030
|
+
"/template/reattach": "configuration",
|
|
1031
|
+
"/template/reset": "configuration",
|
|
1032
|
+
"/envs/delete": "configuration",
|
|
1033
|
+
"/repos/add": "configuration",
|
|
1034
|
+
"/repos/delete": "configuration",
|
|
1035
|
+
"/review-author-allowlist/add": "access",
|
|
1036
|
+
"/review-author-allowlist/delete": "access",
|
|
1037
|
+
"/patch-author-allowlist/add": "access",
|
|
1038
|
+
"/patch-author-allowlist/delete": "access",
|
|
1039
|
+
// Shared by the Slack access card (access) and the Agent Policy card
|
|
1040
|
+
// (configuration); see settingsRedirectSection.
|
|
1041
|
+
"/settings": "configuration",
|
|
1042
|
+
"/crons": "automation",
|
|
1043
|
+
"/crons/:cronId/toggle": "automation",
|
|
1044
|
+
"/crons/:cronId/update": "automation",
|
|
1045
|
+
"/crons/:cronId/delete": "automation",
|
|
1046
|
+
"/tools": "extensions",
|
|
1047
|
+
"/tools/:toolId/toggle": "extensions",
|
|
1048
|
+
"/tools/:toolId/delete": "extensions",
|
|
1049
|
+
"/marketplaces": "extensions",
|
|
1050
|
+
"/marketplaces/delete": "extensions",
|
|
1051
|
+
"/plugins": "extensions",
|
|
1052
|
+
"/plugins/delete": "extensions",
|
|
1053
|
+
"/tokens": "access",
|
|
1054
|
+
"/tokens/:tokenId/revoke": "access",
|
|
1055
|
+
"/sync-manifest": "general",
|
|
1056
|
+
"/connect-slack": "access",
|
|
1057
|
+
"/connect-slack/app-token": "access",
|
|
1058
|
+
"/connect-github": "access",
|
|
1059
|
+
"/members": "access",
|
|
1060
|
+
"/members/delete": "access",
|
|
1061
|
+
"/delete": "general",
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* POST /settings serves two forms: Slack access (access section, carries
|
|
1066
|
+
* restrictSlackToMembers) and Agent Policy (configuration section).
|
|
1067
|
+
*/
|
|
1068
|
+
export function settingsRedirectSection(formData: FormData): AgentSection {
|
|
1069
|
+
return formData.has("restrictSlackToMembers") ? "access" : "configuration";
|
|
1001
1070
|
}
|
|
1002
1071
|
|
|
1003
1072
|
export function renderAgentDetailPage(
|
|
@@ -1018,6 +1087,8 @@ export function renderAgentDetailPage(
|
|
|
1018
1087
|
userName: string,
|
|
1019
1088
|
isAdmin: boolean,
|
|
1020
1089
|
opts?: {
|
|
1090
|
+
/** Section to render (SGL-1.2). Defaults to "general". */
|
|
1091
|
+
section?: AgentSection;
|
|
1021
1092
|
/**
|
|
1022
1093
|
* SSP-4.3: render the Members / Slack access / Danger Zone cards. Defaults
|
|
1023
1094
|
* to isAdmin; the caller passes true for agent-access holders when
|
|
@@ -2070,8 +2141,8 @@ export function renderAgentDetailPage(
|
|
|
2070
2141
|
|
|
2071
2142
|
const dangerZoneSection = canManage
|
|
2072
2143
|
? `<!-- Danger Zone -->
|
|
2073
|
-
<div class="
|
|
2074
|
-
<div class="
|
|
2144
|
+
<div class="settings-danger-zone">
|
|
2145
|
+
<div class="settings-section-title">Danger Zone</div>
|
|
2075
2146
|
<p style="font-size:13px;color:#6b7280;margin-bottom:16px">
|
|
2076
2147
|
Deleting this agent permanently removes all its data (env vars, crons, tools, tokens, plugins, members)
|
|
2077
2148
|
and terminates its pod. This action cannot be undone.
|
|
@@ -2091,24 +2162,8 @@ export function renderAgentDetailPage(
|
|
|
2091
2162
|
</div>`
|
|
2092
2163
|
: "";
|
|
2093
2164
|
|
|
2094
|
-
// ─── Accordion groups (AGA-1.1) ────────────────────────────────────────
|
|
2095
|
-
// The cards below are grouped into 4 collapsed-by-default
|
|
2096
|
-
// <details class="group"> sections. Grouping is purely presentational —
|
|
2097
|
-
// every card's internal markup/ids/form actions are unchanged, they're
|
|
2098
|
-
// just composed into a new order. Agent Policy (added after this task was
|
|
2099
|
-
// originally scoped) lands in Configuration alongside Env Vars/Repos since
|
|
2100
|
-
// it is agent-level configuration, as do extension cards placed there
|
|
2101
|
-
// (the coding extension's Phase Methodology card) — this keeps every card
|
|
2102
|
-
// inside exactly one of the 4 groups, with no stray bare cards besides
|
|
2103
|
-
// Danger Zone.
|
|
2104
|
-
const automationStat = `${systemCrons.length} system · ${customCrons.length} custom`;
|
|
2105
|
-
const configurationStat = `${Object.keys(envVars).length} env vars · ${agent.repos.length} repos`;
|
|
2106
|
-
const activeTokenCount = tokens.filter((t) => !t.revokedAt).length;
|
|
2107
|
-
const accessStat = `${members.length} members · ${activeTokenCount} active tokens`;
|
|
2108
|
-
const pluginsToolsStat = `${tools.length} tools · ${plugins.length} plugins`;
|
|
2109
|
-
|
|
2110
2165
|
// ─── Stat strip (AGA-1.2) ──────────────────────────────────────────────
|
|
2111
|
-
// 4-tile stat strip rendered
|
|
2166
|
+
// 4-tile stat strip rendered on the General section. Each tile
|
|
2112
2167
|
// derives its count from parameters already passed into this function.
|
|
2113
2168
|
const cronsActiveCount = topLevelCrons.filter((c) => c.enabled).length;
|
|
2114
2169
|
const missingEnvVarsCount = agent.missingRequiredEnv.length;
|
|
@@ -2134,64 +2189,15 @@ export function renderAgentDetailPage(
|
|
|
2134
2189
|
</div>
|
|
2135
2190
|
</div>`;
|
|
2136
2191
|
|
|
2137
|
-
const
|
|
2138
|
-
"Automation",
|
|
2139
|
-
automationStat,
|
|
2140
|
-
cronJobsSection,
|
|
2141
|
-
);
|
|
2142
|
-
const configurationGroup = renderGroup(
|
|
2143
|
-
"Configuration",
|
|
2144
|
-
configurationStat,
|
|
2145
|
-
`${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
|
|
2146
|
-
);
|
|
2147
|
-
const accessGroup = renderGroup(
|
|
2148
|
-
"Access",
|
|
2149
|
-
accessStat,
|
|
2150
|
-
`${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackAccessSection}${tokensSection}`,
|
|
2151
|
-
);
|
|
2152
|
-
const pluginsToolsGroup = renderGroup(
|
|
2153
|
-
"Plugins & Tools",
|
|
2154
|
-
pluginsToolsStat,
|
|
2155
|
-
`${toolsSection}${pluginsSection}${marketplacesSection}`,
|
|
2156
|
-
);
|
|
2157
|
-
|
|
2158
|
-
const expandCollapseControls = `
|
|
2159
|
-
<div style="display:flex;gap:8px;margin-bottom:16px">
|
|
2160
|
-
<button type="button" class="btn btn-secondary" id="expand-all-btn">Expand all</button>
|
|
2161
|
-
<button type="button" class="btn btn-secondary" id="collapse-all-btn">Collapse all</button>
|
|
2162
|
-
</div>
|
|
2163
|
-
<script>
|
|
2164
|
-
(function() {
|
|
2165
|
-
var expandBtn = document.getElementById('expand-all-btn');
|
|
2166
|
-
var collapseBtn = document.getElementById('collapse-all-btn');
|
|
2167
|
-
if (expandBtn) {
|
|
2168
|
-
expandBtn.addEventListener('click', function() {
|
|
2169
|
-
document.querySelectorAll('.group').forEach(function(el) {
|
|
2170
|
-
el.open = true;
|
|
2171
|
-
});
|
|
2172
|
-
});
|
|
2173
|
-
}
|
|
2174
|
-
if (collapseBtn) {
|
|
2175
|
-
collapseBtn.addEventListener('click', function() {
|
|
2176
|
-
document.querySelectorAll('.group').forEach(function(el) {
|
|
2177
|
-
el.open = false;
|
|
2178
|
-
});
|
|
2179
|
-
});
|
|
2180
|
-
}
|
|
2181
|
-
})();
|
|
2182
|
-
</script>
|
|
2183
|
-
`;
|
|
2192
|
+
const section = opts?.section ?? "general";
|
|
2184
2193
|
|
|
2185
|
-
|
|
2186
|
-
title: `${agent.name} — Shipwright Admin`,
|
|
2187
|
-
body: `${renderAdminToolbar(userName, "/admin/agents")}
|
|
2188
|
-
<div class="vos-page">
|
|
2189
|
-
<div class="page-header">
|
|
2194
|
+
const headerInfoHtml = `<div class="page-header">
|
|
2190
2195
|
<div>
|
|
2191
2196
|
<a href="/admin/agents" style="font-size:13px;color:#6b7280;text-decoration:none">← Agents</a>
|
|
2192
|
-
<
|
|
2193
|
-
|
|
2194
|
-
|
|
2197
|
+
<div style="margin-top:4px">
|
|
2198
|
+
<span style="font-size:13px;color:#6b7280">Type: <span class="mono">${escapeHtml(agent.specialty)}</span></span>
|
|
2199
|
+
${agent.slackId ? `<span style="font-size:13px;color:#6b7280">Slack ID: <span class="mono">${escapeHtml(agent.slackId)}</span></span>` : ""}
|
|
2200
|
+
</div>
|
|
2195
2201
|
</div>
|
|
2196
2202
|
${
|
|
2197
2203
|
agent.slackId
|
|
@@ -2216,24 +2222,45 @@ export function renderAgentDetailPage(
|
|
|
2216
2222
|
</div>`
|
|
2217
2223
|
: ""
|
|
2218
2224
|
}
|
|
2219
|
-
</div
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
${newTokenHtml}
|
|
2225
|
+
</div>`;
|
|
2226
|
+
|
|
2227
|
+
const sectionBodies: Record<AgentSection, string> = {
|
|
2228
|
+
general: `${headerInfoHtml}
|
|
2224
2229
|
${(opts?.extensionCardsHtml ?? []).join("\n ")}
|
|
2225
2230
|
|
|
2226
2231
|
${statStripHtml}
|
|
2227
2232
|
|
|
2228
|
-
${
|
|
2229
|
-
|
|
2230
|
-
${
|
|
2231
|
-
${
|
|
2232
|
-
${
|
|
2233
|
-
|
|
2234
|
-
${dangerZoneSection}
|
|
2233
|
+
${dangerZoneSection}`,
|
|
2234
|
+
automation: cronJobsSection,
|
|
2235
|
+
configuration: `${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
|
|
2236
|
+
access: `${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackAccessSection}${tokensSection}`,
|
|
2237
|
+
extensions: `${toolsSection}${pluginsSection}${marketplacesSection}`,
|
|
2238
|
+
};
|
|
2235
2239
|
|
|
2236
|
-
|
|
2240
|
+
return renderAdminPage({
|
|
2241
|
+
title: `${agent.name} — Shipwright Admin`,
|
|
2242
|
+
body: renderSettingsLayout({
|
|
2243
|
+
userName,
|
|
2244
|
+
title: agent.name,
|
|
2245
|
+
nav: {
|
|
2246
|
+
sections: [
|
|
2247
|
+
{
|
|
2248
|
+
label: "Agent",
|
|
2249
|
+
items: AGENT_SECTIONS.map((k) => ({
|
|
2250
|
+
label: AGENT_SECTION_LABELS[k],
|
|
2251
|
+
path: agentSectionPath(agent.id, k),
|
|
2252
|
+
})),
|
|
2253
|
+
},
|
|
2254
|
+
],
|
|
2255
|
+
},
|
|
2256
|
+
active: agentSectionPath(agent.id, section),
|
|
2257
|
+
toolbarPath: "/admin/agents",
|
|
2258
|
+
body: `${errorHtml}
|
|
2259
|
+
${successHtml}
|
|
2260
|
+
${warningHtml}
|
|
2261
|
+
${newTokenHtml}
|
|
2262
|
+
${sectionBodies[section]}`,
|
|
2263
|
+
}),
|
|
2237
2264
|
});
|
|
2238
2265
|
}
|
|
2239
2266
|
|