@app-vitals/agent-admin 1.93.1 → 1.95.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 +2 -2
- package/src/admin-ui-agent-setup.smoke.test.ts +60 -0
- package/src/admin-ui-github-auto-install.smoke.test.ts +1 -0
- package/src/admin-ui-pages.ts +76 -1
- package/src/admin-ui-pages.unit.test.ts +18 -0
- package/src/admin-ui.smoke.test.ts +1 -0
- package/src/admin-ui.ts +24 -0
- package/src/agent-setup.unit.test.ts +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.95.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@anthropic-ai/sdk": "0.137.0",
|
|
47
|
-
"@app-vitals/agent-lib": "1.
|
|
47
|
+
"@app-vitals/agent-lib": "1.95.0",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Smoke tests (app.request()) for GET /admin/agents/:id/setup (SWI-17.1). */
|
|
2
|
+
import { describe, expect, it } from "bun:test";
|
|
3
|
+
import {
|
|
4
|
+
AGENT_ID,
|
|
5
|
+
makeMockDeps,
|
|
6
|
+
makeSessionCookie,
|
|
7
|
+
SESSION_SECRET,
|
|
8
|
+
} from "./admin-ui.fixtures.ts";
|
|
9
|
+
import { createAdminUIApp } from "./admin-ui.ts";
|
|
10
|
+
|
|
11
|
+
function setup(env: Record<string, string>) {
|
|
12
|
+
return createAdminUIApp(
|
|
13
|
+
makeMockDeps({
|
|
14
|
+
agentEnvService: {
|
|
15
|
+
getByAgentId: async () => ({ env, secretKeys: [] }),
|
|
16
|
+
upsert: async () => {},
|
|
17
|
+
patch: async () => {},
|
|
18
|
+
deleteKey: async () => {},
|
|
19
|
+
getConfigBundle: async () => null,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const get = async (app: ReturnType<typeof setup>, cookie: string) =>
|
|
26
|
+
app.request(`/admin/agents/${AGENT_ID}/setup`, {
|
|
27
|
+
headers: { Cookie: `admin_session=${cookie}` },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("GET /admin/agents/:id/setup", () => {
|
|
31
|
+
it("lists outstanding steps for an unconnected agent", async () => {
|
|
32
|
+
const res = await get(setup({}), await makeSessionCookie(SESSION_SECRET));
|
|
33
|
+
expect(res.status).toBe(200);
|
|
34
|
+
const body = await res.text();
|
|
35
|
+
expect(body).toContain("Slack: not connected");
|
|
36
|
+
expect(body).toContain("GitHub: not connected");
|
|
37
|
+
expect(body).toContain(`/admin/agents/${AGENT_ID}/access`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("shows the all-done state when fully connected", async () => {
|
|
41
|
+
const res = await get(
|
|
42
|
+
setup({ SLACK_APP_TOKEN: "x", GH_APP_ID: "1" }),
|
|
43
|
+
await makeSessionCookie(SESSION_SECRET),
|
|
44
|
+
);
|
|
45
|
+
const body = await res.text();
|
|
46
|
+
expect(body).toContain("All set");
|
|
47
|
+
expect(body).toContain(`/admin/agents/${AGENT_ID}"`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("403s a user without agent access", async () => {
|
|
51
|
+
const cookie = await makeSessionCookie(
|
|
52
|
+
SESSION_SECRET,
|
|
53
|
+
"sub-2",
|
|
54
|
+
"member@example.com",
|
|
55
|
+
false,
|
|
56
|
+
);
|
|
57
|
+
const res = await get(setup({}), cookie);
|
|
58
|
+
expect(res.status).toBe(403);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -102,6 +102,7 @@ describe("admin UI — connect-github callback auto-install (SWI-16.1)", () => {
|
|
|
102
102
|
expect(res.status).toBe(200);
|
|
103
103
|
const html = await res.text();
|
|
104
104
|
expect(html).toContain("GitHub App installed!");
|
|
105
|
+
expect(html).toContain(`href="/admin/agents/${AGENT_ID}/setup"`);
|
|
105
106
|
expect(html).not.toContain("installations/new");
|
|
106
107
|
expect(installCalls).toEqual([
|
|
107
108
|
{
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -991,6 +991,76 @@ function renderConnectAction(
|
|
|
991
991
|
</details>`;
|
|
992
992
|
}
|
|
993
993
|
|
|
994
|
+
export interface AgentSetupStep {
|
|
995
|
+
id: "slack" | "github";
|
|
996
|
+
label: string;
|
|
997
|
+
connected: boolean;
|
|
998
|
+
/** Where the connect action lives (the agent's access section). */
|
|
999
|
+
href: string;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Setup steps derived from the agent's env keys, the same keys the agent
|
|
1004
|
+
* page connect cards hide on: SLACK_APP_TOKEN for Slack, GH_APP_ID or
|
|
1005
|
+
* GH_TOKEN for GitHub. Pure and stateless.
|
|
1006
|
+
*/
|
|
1007
|
+
export function deriveAgentSetupSteps(
|
|
1008
|
+
agentId: string,
|
|
1009
|
+
envVars: Record<string, unknown>,
|
|
1010
|
+
): AgentSetupStep[] {
|
|
1011
|
+
const href = agentSectionPath(agentId, "access");
|
|
1012
|
+
return [
|
|
1013
|
+
{
|
|
1014
|
+
id: "slack",
|
|
1015
|
+
label: "Connect Slack",
|
|
1016
|
+
connected: "SLACK_APP_TOKEN" in envVars,
|
|
1017
|
+
href,
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
id: "github",
|
|
1021
|
+
label: "Connect GitHub",
|
|
1022
|
+
connected: "GH_APP_ID" in envVars || "GH_TOKEN" in envVars,
|
|
1023
|
+
href,
|
|
1024
|
+
},
|
|
1025
|
+
];
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/** GET /admin/agents/:id/setup — checklist of outstanding Slack/GitHub steps. */
|
|
1029
|
+
export function renderAgentSetupPage(
|
|
1030
|
+
userName: string,
|
|
1031
|
+
agent: { id: string; name: string },
|
|
1032
|
+
steps: AgentSetupStep[],
|
|
1033
|
+
): string {
|
|
1034
|
+
const allDone = steps.every((s) => s.connected);
|
|
1035
|
+
const agentPath = agentSectionPath(agent.id);
|
|
1036
|
+
const rows = steps
|
|
1037
|
+
.map(
|
|
1038
|
+
(s) => `<li class="setup-step" data-step="${s.id}" data-connected="${s.connected}" style="display:flex;justify-content:space-between;align-items:center;padding:8px 0">
|
|
1039
|
+
<span>${s.connected ? "✅" : "⬜"} ${escapeHtml(s.id === "slack" ? "Slack" : "GitHub")}: ${s.connected ? "connected" : "not connected"}</span>
|
|
1040
|
+
${s.connected ? "" : `<a class="btn btn-primary" href="${escapeHtml(s.href)}">${escapeHtml(s.label)}</a>`}
|
|
1041
|
+
</li>`,
|
|
1042
|
+
)
|
|
1043
|
+
.join("\n");
|
|
1044
|
+
const doneHtml = allDone
|
|
1045
|
+
? `<div class="alert alert-success"><strong>All set.</strong> Slack and GitHub are connected. <a href="${escapeHtml(agentPath)}">Go to the agent page</a></div>`
|
|
1046
|
+
: "";
|
|
1047
|
+
return renderAdminPage({
|
|
1048
|
+
title: `Setup — ${agent.name} — Shipwright Admin`,
|
|
1049
|
+
body: `${renderAdminToolbar(userName, "/admin/agents")}
|
|
1050
|
+
<div class="vos-page">
|
|
1051
|
+
<div class="page-header">
|
|
1052
|
+
<h1 class="page-title">Set up ${escapeHtml(agent.name)}</h1>
|
|
1053
|
+
</div>
|
|
1054
|
+
<div class="card">
|
|
1055
|
+
${doneHtml}
|
|
1056
|
+
<ul style="list-style:none;padding:0;margin:0">
|
|
1057
|
+
${rows}
|
|
1058
|
+
</ul>
|
|
1059
|
+
</div>
|
|
1060
|
+
</div>`,
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
|
|
994
1064
|
export const AGENT_SECTIONS = [
|
|
995
1065
|
"general",
|
|
996
1066
|
"automation",
|
|
@@ -2464,8 +2534,13 @@ export function renderGithubAppInstalledPage(
|
|
|
2464
2534
|
alreadyStored?: boolean;
|
|
2465
2535
|
/** Enterprise auto-install: App was already installed on the org (created:false). */
|
|
2466
2536
|
orgAlreadyInstalled?: boolean;
|
|
2537
|
+
/** When set, the success path links back to the agent's setup page. */
|
|
2538
|
+
agentId?: string;
|
|
2467
2539
|
},
|
|
2468
2540
|
): string {
|
|
2541
|
+
const successLink = opts.agentId
|
|
2542
|
+
? `<a href="/admin/agents/${escapeHtml(opts.agentId)}/setup" class="btn btn-primary">Continue to setup →</a>`
|
|
2543
|
+
: `<a href="/admin/provision" class="btn btn-secondary">Back to Provisioning</a>`;
|
|
2469
2544
|
const bodyHtml = opts.success
|
|
2470
2545
|
? `<div class="alert alert-success">
|
|
2471
2546
|
${
|
|
@@ -2476,7 +2551,7 @@ export function renderGithubAppInstalledPage(
|
|
|
2476
2551
|
: "<strong>GitHub App installed!</strong> — installation ID stored."
|
|
2477
2552
|
}
|
|
2478
2553
|
</div>
|
|
2479
|
-
|
|
2554
|
+
${successLink}`
|
|
2480
2555
|
: `<div class="alert alert-error">${escapeHtml(opts.error ?? "GitHub App installation failed.")}</div>
|
|
2481
2556
|
<a href="/admin/provision" class="btn btn-secondary">Try again</a>`;
|
|
2482
2557
|
|
|
@@ -4689,4 +4689,22 @@ describe("GitHub App install pages (SWI-16.1)", () => {
|
|
|
4689
4689
|
}),
|
|
4690
4690
|
).toContain("already installed");
|
|
4691
4691
|
});
|
|
4692
|
+
|
|
4693
|
+
test("installed page links to setup on success only when agentId given", () => {
|
|
4694
|
+
const ok = renderGithubAppInstalledPage(USER_NAME, {
|
|
4695
|
+
success: true,
|
|
4696
|
+
agentId: "a<1>",
|
|
4697
|
+
});
|
|
4698
|
+
expect(ok).toContain('href="/admin/agents/a<1>/setup"');
|
|
4699
|
+
expect(
|
|
4700
|
+
renderGithubAppInstalledPage(USER_NAME, { success: true }),
|
|
4701
|
+
).toContain("Back to Provisioning");
|
|
4702
|
+
expect(
|
|
4703
|
+
renderGithubAppInstalledPage(USER_NAME, {
|
|
4704
|
+
success: false,
|
|
4705
|
+
error: "x",
|
|
4706
|
+
agentId: "a1",
|
|
4707
|
+
}),
|
|
4708
|
+
).not.toContain("/setup");
|
|
4709
|
+
});
|
|
4692
4710
|
});
|
|
@@ -5422,6 +5422,7 @@ describe("admin UI — GET /admin/agents/:id/connect-github/installed", () => {
|
|
|
5422
5422
|
expect(res.status).toBe(200);
|
|
5423
5423
|
const html = await res.text();
|
|
5424
5424
|
expect(html).toContain("alert-success");
|
|
5425
|
+
expect(html).toContain(`href="/admin/agents/${AGENT_ID}/setup"`);
|
|
5425
5426
|
expect(
|
|
5426
5427
|
patchCalls.some(
|
|
5427
5428
|
(c) =>
|
package/src/admin-ui.ts
CHANGED
|
@@ -80,9 +80,11 @@ import {
|
|
|
80
80
|
type AgentOption,
|
|
81
81
|
type AgentSection,
|
|
82
82
|
agentSectionPath,
|
|
83
|
+
deriveAgentSetupSteps,
|
|
83
84
|
isAgentSection,
|
|
84
85
|
type NewAgentTemplateItem,
|
|
85
86
|
renderAgentDetailPage,
|
|
87
|
+
renderAgentSetupPage,
|
|
86
88
|
renderAgentsPage,
|
|
87
89
|
renderChatMessageBubble,
|
|
88
90
|
renderChatPage,
|
|
@@ -2704,6 +2706,26 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2704
2706
|
agentDetailHandler,
|
|
2705
2707
|
);
|
|
2706
2708
|
|
|
2709
|
+
// Setup checklist: outstanding Slack/GitHub steps from real env state.
|
|
2710
|
+
app.get("/admin/agents/:id/setup", requireAuth, async (c) => {
|
|
2711
|
+
const agentId = c.req.param("id");
|
|
2712
|
+
const agent = await agentService.getDetail(agentId);
|
|
2713
|
+
if (!agent) {
|
|
2714
|
+
return new Response("Agent not found", { status: 404 });
|
|
2715
|
+
}
|
|
2716
|
+
if (!(await assertAgentAccess(agentId, c.var.userEmail, c.var.isAdmin))) {
|
|
2717
|
+
return new Response("Forbidden", { status: 403 });
|
|
2718
|
+
}
|
|
2719
|
+
const envResult = await agentEnvService.getByAgentId(agentId);
|
|
2720
|
+
return html(
|
|
2721
|
+
renderAgentSetupPage(
|
|
2722
|
+
c.var.userEmail,
|
|
2723
|
+
{ id: agent.id, name: agent.name },
|
|
2724
|
+
deriveAgentSetupSteps(agentId, envResult?.env ?? {}),
|
|
2725
|
+
),
|
|
2726
|
+
);
|
|
2727
|
+
});
|
|
2728
|
+
|
|
2707
2729
|
// ─── Env var mutations ────────────────────────────────────────────────────
|
|
2708
2730
|
|
|
2709
2731
|
app.post("/admin/agents/:id/envs", requireAuth, async (c) => {
|
|
@@ -4150,6 +4172,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4150
4172
|
renderGithubAppInstalledPage(userEmail, {
|
|
4151
4173
|
success: true,
|
|
4152
4174
|
orgAlreadyInstalled: !created,
|
|
4175
|
+
agentId,
|
|
4153
4176
|
}),
|
|
4154
4177
|
);
|
|
4155
4178
|
}
|
|
@@ -4214,6 +4237,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4214
4237
|
renderGithubAppInstalledPage(userEmail, {
|
|
4215
4238
|
success: true,
|
|
4216
4239
|
alreadyStored: result.alreadyStored,
|
|
4240
|
+
agentId,
|
|
4217
4241
|
}),
|
|
4218
4242
|
);
|
|
4219
4243
|
},
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { deriveAgentSetupSteps, renderAgentSetupPage } from "./admin-ui-pages.ts";
|
|
3
|
+
|
|
4
|
+
const state = (env: Record<string, unknown>) =>
|
|
5
|
+
Object.fromEntries(
|
|
6
|
+
deriveAgentSetupSteps("a1", env).map((s) => [s.id, s.connected]),
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
describe("deriveAgentSetupSteps", () => {
|
|
10
|
+
it.each([
|
|
11
|
+
[{}, false, false],
|
|
12
|
+
[{ SLACK_APP_TOKEN: "x" }, true, false],
|
|
13
|
+
[{ GH_APP_ID: "1" }, false, true],
|
|
14
|
+
[{ GH_TOKEN: "t" }, false, true],
|
|
15
|
+
[{ GH_APP_ID: "1", GH_TOKEN: "t" }, false, true],
|
|
16
|
+
[{ SLACK_APP_TOKEN: "x", GH_APP_ID: "1" }, true, true],
|
|
17
|
+
[{ SLACK_APP_TOKEN: "x", GH_TOKEN: "t" }, true, true],
|
|
18
|
+
])("env %j -> slack=%p github=%p", (env, slack, github) => {
|
|
19
|
+
expect(state(env)).toEqual({ slack, github });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("links each step to the agent's access section", () => {
|
|
23
|
+
for (const s of deriveAgentSetupSteps("a/1", {})) {
|
|
24
|
+
expect(s.href).toBe("/admin/agents/a%2F1/access");
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("renderAgentSetupPage", () => {
|
|
30
|
+
const agent = { id: "a1", name: "Bot <b>" };
|
|
31
|
+
it("shows connect links and no done state when incomplete", () => {
|
|
32
|
+
const html = renderAgentSetupPage("u@x.com", agent, deriveAgentSetupSteps("a1", { GH_TOKEN: "t" }));
|
|
33
|
+
expect(html).toContain("Slack: not connected");
|
|
34
|
+
expect(html).toContain("GitHub: connected");
|
|
35
|
+
expect(html).toContain('href="/admin/agents/a1/access"');
|
|
36
|
+
expect(html).not.toContain("All set");
|
|
37
|
+
expect(html).toContain("Bot <b>");
|
|
38
|
+
});
|
|
39
|
+
it("shows all-done state linking to the agent page", () => {
|
|
40
|
+
const html = renderAgentSetupPage("u@x.com", agent, deriveAgentSetupSteps("a1", { SLACK_APP_TOKEN: "x", GH_TOKEN: "t" }));
|
|
41
|
+
expect(html).toContain("All set");
|
|
42
|
+
expect(html).toContain('href="/admin/agents/a1"');
|
|
43
|
+
});
|
|
44
|
+
});
|