@app-vitals/agent-admin 1.42.0 → 1.43.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-boot.ts +7 -5
- package/src/admin-ui-github-enterprise-pages.ts +1 -1
- package/src/admin-ui-templates-pages.ts +155 -0
- package/src/admin-ui-templates-pages.unit.test.ts +54 -0
- package/src/admin-ui-templates.smoke.test.ts +292 -0
- package/src/admin-ui-templates.ts +316 -0
- package/src/admin-ui.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.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.
|
|
45
|
+
"@app-vitals/agent-lib": "1.43.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -578,14 +578,15 @@ export async function startAdmin(
|
|
|
578
578
|
);
|
|
579
579
|
|
|
580
580
|
// 3b''. Agent templates API — /templates/* — admin or account-scoped (ATP-1.3)
|
|
581
|
+
const templateService = new AgentTemplateService(
|
|
582
|
+
prisma,
|
|
583
|
+
crypto,
|
|
584
|
+
specialtyRegistry,
|
|
585
|
+
);
|
|
581
586
|
root.route(
|
|
582
587
|
"/",
|
|
583
588
|
createAgentTemplatesApp({
|
|
584
|
-
templateService
|
|
585
|
-
prisma,
|
|
586
|
-
crypto,
|
|
587
|
-
specialtyRegistry,
|
|
588
|
-
),
|
|
589
|
+
templateService,
|
|
589
590
|
callerScopeResolver,
|
|
590
591
|
sessionSecret,
|
|
591
592
|
adminApiKeys,
|
|
@@ -639,6 +640,7 @@ export async function startAdmin(
|
|
|
639
640
|
anthropicFederationEnabled,
|
|
640
641
|
specialtyRegistry,
|
|
641
642
|
specialtyDefaults,
|
|
643
|
+
templateService,
|
|
642
644
|
serviceIntegrations,
|
|
643
645
|
chatService: deletionChatService,
|
|
644
646
|
slack: slackClient,
|
|
@@ -265,7 +265,7 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
265
265
|
title: "GitHub Enterprise — Settings — Shipwright Admin",
|
|
266
266
|
body: `${renderAdminToolbar(opts.userEmail, BASE)}
|
|
267
267
|
<div class="vos-page">
|
|
268
|
-
<div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1></div>
|
|
268
|
+
<div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1><a href="/admin/settings/templates" class="btn btn-secondary">Agent templates</a></div>
|
|
269
269
|
${error}${notice}${intro}
|
|
270
270
|
${appCard("installer", status.installer, opts.warnings)}
|
|
271
271
|
${appCard("lookup", status.lookup, opts.warnings)}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-templates-pages.ts
|
|
3
|
+
* Render function for the Settings > Templates editor (ATP-2.3).
|
|
4
|
+
* Pure string -> string; routes live in admin-ui-templates.ts.
|
|
5
|
+
*
|
|
6
|
+
* Secret env values arrive already masked ("***") from the template service;
|
|
7
|
+
* the page only ever echoes what it is given, and posting the mask back keeps
|
|
8
|
+
* the stored secret.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
12
|
+
import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
13
|
+
|
|
14
|
+
export const ADMIN_TEMPLATES_PATH = "/admin/settings/templates";
|
|
15
|
+
|
|
16
|
+
const BASE = ADMIN_TEMPLATES_PATH;
|
|
17
|
+
|
|
18
|
+
export interface TemplateScopeOption {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TemplateItemRow {
|
|
24
|
+
kind: "env" | "tool" | "plugin" | "cron";
|
|
25
|
+
key: string;
|
|
26
|
+
payload: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TemplatesPageOpts {
|
|
30
|
+
userEmail: string;
|
|
31
|
+
/** Accounts the caller may pick; the deployment-wide option is included only for admins. */
|
|
32
|
+
accountOptions: TemplateScopeOption[];
|
|
33
|
+
specialtyOptions: TemplateScopeOption[];
|
|
34
|
+
/** Selected scope ("" = deployment-wide / all types). */
|
|
35
|
+
accountId: string;
|
|
36
|
+
specialty: string;
|
|
37
|
+
/** Items of the template at the selected scope (empty when none exists yet). */
|
|
38
|
+
items: TemplateItemRow[];
|
|
39
|
+
templateExists: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
notice?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const str = (v: unknown): string => (typeof v === "string" ? v : "");
|
|
45
|
+
|
|
46
|
+
function options(opts: TemplateScopeOption[], selected: string): string {
|
|
47
|
+
return opts
|
|
48
|
+
.map(
|
|
49
|
+
(o) =>
|
|
50
|
+
`<option value="${escapeHtml(o.value)}"${o.value === selected ? " selected" : ""}>${escapeHtml(o.label)}</option>`,
|
|
51
|
+
)
|
|
52
|
+
.join("");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function scopePicker(o: TemplatesPageOpts): string {
|
|
56
|
+
return `<form method="GET" action="${BASE}" class="template-scope" style="display:flex;gap:8px;align-items:end;flex-wrap:wrap">
|
|
57
|
+
<label>Account <select name="accountId" class="form-input">${options(o.accountOptions, o.accountId)}</select></label>
|
|
58
|
+
<label>Agent type <select name="specialty" class="form-input">${options(o.specialtyOptions, o.specialty)}</select></label>
|
|
59
|
+
<button type="submit" class="btn btn-secondary">Open template</button>
|
|
60
|
+
</form>`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function scopeFields(o: TemplatesPageOpts): string {
|
|
64
|
+
return `<input type="hidden" name="accountId" value="${escapeHtml(o.accountId)}" /><input type="hidden" name="specialty" value="${escapeHtml(o.specialty)}" />`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const checked = (b: unknown, dflt = true) =>
|
|
68
|
+
(b === undefined ? dflt : b !== false) ? " checked" : "";
|
|
69
|
+
|
|
70
|
+
/** The editable fields of one item (shared by the existing-item and add forms). */
|
|
71
|
+
function itemFields(
|
|
72
|
+
kind: TemplateItemRow["kind"],
|
|
73
|
+
p: Record<string, unknown>,
|
|
74
|
+
): string {
|
|
75
|
+
switch (kind) {
|
|
76
|
+
case "env":
|
|
77
|
+
return `<label>Value <input name="value" class="form-input" autocomplete="off" value="${escapeHtml(str(p.value))}"/></label>
|
|
78
|
+
<label><input type="checkbox" name="secret" value="1"${p.secret === true ? " checked" : ""} /> Secret</label>`;
|
|
79
|
+
case "tool":
|
|
80
|
+
return `<label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
|
|
81
|
+
case "plugin":
|
|
82
|
+
return `<label>Version <input name="version" class="form-input" value="${escapeHtml(str(p.version))}" placeholder="latest" /></label>
|
|
83
|
+
<label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
|
|
84
|
+
case "cron":
|
|
85
|
+
return `<label>Schedule <input name="schedule" class="form-input" value="${escapeHtml(str(p.schedule))}" placeholder="0 9 * * 1-5" /></label>
|
|
86
|
+
<label>Prompt <textarea name="prompt" class="form-input" rows="2">${escapeHtml(str(p.prompt))}</textarea></label>
|
|
87
|
+
<label>Channel <input name="channel" class="form-input" value="${escapeHtml(str(p.channel))}" /></label>
|
|
88
|
+
<label>User <input name="user" class="form-input" value="${escapeHtml(str(p.user))}" /></label>
|
|
89
|
+
<label>Pre-check <input name="preCheck" class="form-input" value="${escapeHtml(str(p.preCheck))}" /></label>
|
|
90
|
+
<label><input type="checkbox" name="silent" value="1"${p.silent === true ? " checked" : ""} /> Silent</label>
|
|
91
|
+
<label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const KIND_COPY = {
|
|
96
|
+
env: { title: "Environment variables", key: "Name", ph: "MY_SETTING" },
|
|
97
|
+
tool: { title: "Tools", key: "Tool pattern", ph: "Bash(git *)" },
|
|
98
|
+
plugin: { title: "Plugins", key: "Plugin", ph: "shipwright@shipwright" },
|
|
99
|
+
cron: { title: "Crons", key: "Name", ph: "daily-digest" },
|
|
100
|
+
} as const;
|
|
101
|
+
|
|
102
|
+
function kindCard(o: TemplatesPageOpts, kind: TemplateItemRow["kind"]): string {
|
|
103
|
+
const copy = KIND_COPY[kind];
|
|
104
|
+
const rows = o.items
|
|
105
|
+
.filter((i) => i.kind === kind)
|
|
106
|
+
.map(
|
|
107
|
+
(
|
|
108
|
+
i,
|
|
109
|
+
) => `<form method="POST" action="${BASE}/items" class="template-item" data-kind="${kind}" data-key="${escapeHtml(i.key)}" style="display:grid;gap:6px;padding:8px 0;border-bottom:1px solid #e5e7eb">
|
|
110
|
+
${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" /><input type="hidden" name="key" value="${escapeHtml(i.key)}" />
|
|
111
|
+
<strong>${escapeHtml(i.key)}</strong>
|
|
112
|
+
${itemFields(kind, i.payload)}
|
|
113
|
+
<div style="display:flex;gap:8px"><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px">Save</button>
|
|
114
|
+
<button type="submit" formaction="${BASE}/items/delete" class="btn btn-danger" style="font-size:12px;padding:4px 10px">Remove</button></div>
|
|
115
|
+
</form>`,
|
|
116
|
+
)
|
|
117
|
+
.join("");
|
|
118
|
+
const empty = rows ? "" : `<p class="help-text empty-state">None yet.</p>`;
|
|
119
|
+
return `<div class="card" id="template-${kind}">
|
|
120
|
+
<div class="card-title">${copy.title}</div>
|
|
121
|
+
${rows}${empty}
|
|
122
|
+
<form method="POST" action="${BASE}/items" class="template-add" style="display:grid;gap:6px;margin-top:12px;max-width:480px">
|
|
123
|
+
${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" />
|
|
124
|
+
<label>${copy.key} <input name="key" class="form-input" required placeholder="${escapeHtml(copy.ph)}" /></label>
|
|
125
|
+
${itemFields(kind, {})}
|
|
126
|
+
<div><button type="submit" class="btn btn-primary">Add ${kind}</button></div>
|
|
127
|
+
</form>
|
|
128
|
+
</div>`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function renderTemplatesPage(o: TemplatesPageOpts): string {
|
|
132
|
+
const error = o.error
|
|
133
|
+
? `<div class="alert alert-error">${escapeHtml(o.error)}</div>`
|
|
134
|
+
: "";
|
|
135
|
+
const notice = o.notice
|
|
136
|
+
? `<div class="alert alert-success">${escapeHtml(o.notice)}</div>`
|
|
137
|
+
: "";
|
|
138
|
+
const del = o.templateExists
|
|
139
|
+
? `<form method="POST" action="${BASE}/delete" style="margin:8px 0">${scopeFields(o)}<button type="submit" class="btn btn-danger">Delete this template</button></form>`
|
|
140
|
+
: `<p class="help-text">No template exists for this scope yet. Adding an item creates it.</p>`;
|
|
141
|
+
return renderAdminPage({
|
|
142
|
+
title: "Templates — Settings — Shipwright Admin",
|
|
143
|
+
body: `${renderAdminToolbar(o.userEmail, BASE)}
|
|
144
|
+
<div class="vos-page">
|
|
145
|
+
<div class="page-header"><h1 class="page-title">Agent templates</h1></div>
|
|
146
|
+
${error}${notice}
|
|
147
|
+
<div class="card">
|
|
148
|
+
<p class="help-text">Default env vars, tools, plugins and crons for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.</p>
|
|
149
|
+
${scopePicker(o)}
|
|
150
|
+
${del}
|
|
151
|
+
</div>
|
|
152
|
+
${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}
|
|
153
|
+
</div>`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-templates-pages.unit.test.ts
|
|
3
|
+
* Unit tests for renderTemplatesPage (ATP-2.3).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from "bun:test";
|
|
7
|
+
import {
|
|
8
|
+
renderTemplatesPage,
|
|
9
|
+
type TemplatesPageOpts,
|
|
10
|
+
} from "./admin-ui-templates-pages.ts";
|
|
11
|
+
|
|
12
|
+
const base: TemplatesPageOpts = {
|
|
13
|
+
userEmail: "a@x.com",
|
|
14
|
+
accountOptions: [{ value: "", label: "Deployment-wide" }],
|
|
15
|
+
specialtyOptions: [{ value: "", label: "All agent types" }],
|
|
16
|
+
accountId: "",
|
|
17
|
+
specialty: "",
|
|
18
|
+
items: [],
|
|
19
|
+
templateExists: false,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe("renderTemplatesPage", () => {
|
|
23
|
+
it("renders a card per kind and an add form each", () => {
|
|
24
|
+
const html = renderTemplatesPage(base);
|
|
25
|
+
for (const k of ["env", "tool", "plugin", "cron"]) {
|
|
26
|
+
expect(html).toContain(`id="template-${k}"`);
|
|
27
|
+
}
|
|
28
|
+
expect(html).toContain("No template exists for this scope yet");
|
|
29
|
+
expect(html).not.toContain("Delete this template");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("escapes values and shows the selected scope", () => {
|
|
33
|
+
const html = renderTemplatesPage({
|
|
34
|
+
...base,
|
|
35
|
+
accountOptions: [{ value: "a1", label: "<b>Acme</b>" }],
|
|
36
|
+
accountId: "a1",
|
|
37
|
+
templateExists: true,
|
|
38
|
+
error: "<script>x</script>",
|
|
39
|
+
items: [
|
|
40
|
+
{
|
|
41
|
+
kind: "env",
|
|
42
|
+
key: "K",
|
|
43
|
+
payload: { value: "***", secret: true },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
expect(html).toContain("<b>Acme</b>");
|
|
48
|
+
expect(html).toContain('<option value="a1" selected>');
|
|
49
|
+
expect(html).toContain("<script>x</script>");
|
|
50
|
+
expect(html).toContain('value="***"');
|
|
51
|
+
expect(html).toContain("Delete this template");
|
|
52
|
+
expect(html).toMatch(/name="secret" value="1" checked/);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-templates.smoke.test.ts
|
|
3
|
+
* Smoke tests for /admin/settings/templates (ATP-2.3) via app.request(), over
|
|
4
|
+
* a stateful in-memory template service that reuses the real item validation
|
|
5
|
+
* (denylist, payload shapes) and secret masking. No DB, no network.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from "bun:test";
|
|
9
|
+
import type { MiddlewareHandler } from "hono";
|
|
10
|
+
import { Hono } from "hono";
|
|
11
|
+
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
12
|
+
import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
|
|
13
|
+
import {
|
|
14
|
+
type AgentTemplateService,
|
|
15
|
+
normalizeTemplateItem,
|
|
16
|
+
SECRET_MASK,
|
|
17
|
+
type TemplateActor,
|
|
18
|
+
type TemplateItemInput,
|
|
19
|
+
type TemplateView,
|
|
20
|
+
} from "./agent-templates.ts";
|
|
21
|
+
import type { CallerScope } from "./caller-scope.ts";
|
|
22
|
+
import { NotFoundError, UnprocessableEntityError } from "./errors.ts";
|
|
23
|
+
|
|
24
|
+
const now = new Date("2026-11-14T00:00:00Z");
|
|
25
|
+
const SPECIALTIES = ["specialist", "reviewer"];
|
|
26
|
+
|
|
27
|
+
function fakeService() {
|
|
28
|
+
const rows: TemplateView[] = [];
|
|
29
|
+
const secrets = new Map<string, string>();
|
|
30
|
+
let seq = 0;
|
|
31
|
+
const mask = (t: TemplateView): TemplateView => t;
|
|
32
|
+
const apply = (t: TemplateView, raw: TemplateItemInput) => {
|
|
33
|
+
const item = normalizeTemplateItem(raw);
|
|
34
|
+
const payload = { ...item.payload };
|
|
35
|
+
if (item.kind === "env" && payload.secret === true) {
|
|
36
|
+
secrets.set(`${t.id}:${item.key}`, String(payload.value));
|
|
37
|
+
payload.value = SECRET_MASK;
|
|
38
|
+
}
|
|
39
|
+
t.items = [
|
|
40
|
+
...t.items.filter((i) => !(i.kind === item.kind && i.key === item.key)),
|
|
41
|
+
{ kind: item.kind, key: item.key, payload, updatedAt: now },
|
|
42
|
+
];
|
|
43
|
+
};
|
|
44
|
+
const visible = (a: TemplateActor, t: TemplateView) =>
|
|
45
|
+
a.kind === "admin" || t.accountId === a.accountId;
|
|
46
|
+
const service: Pick<
|
|
47
|
+
AgentTemplateService,
|
|
48
|
+
"list" | "replace" | "putItem" | "deleteItem" | "delete"
|
|
49
|
+
> = {
|
|
50
|
+
async list(actor, f = {}) {
|
|
51
|
+
return rows
|
|
52
|
+
.filter((t) => visible(actor, t))
|
|
53
|
+
.filter((t) => f.accountId === undefined || t.accountId === f.accountId)
|
|
54
|
+
.filter((t) => f.specialty === undefined || t.specialty === f.specialty)
|
|
55
|
+
.map(mask);
|
|
56
|
+
},
|
|
57
|
+
async replace(actor, scope, items) {
|
|
58
|
+
const accountId =
|
|
59
|
+
actor.kind === "account" ? actor.accountId : (scope.accountId ?? null);
|
|
60
|
+
const specialty = scope.specialty ?? null;
|
|
61
|
+
if (specialty !== null && !SPECIALTIES.includes(specialty)) {
|
|
62
|
+
throw new UnprocessableEntityError(`unknown specialty ${specialty}`);
|
|
63
|
+
}
|
|
64
|
+
const t: TemplateView = {
|
|
65
|
+
id: `t${++seq}`,
|
|
66
|
+
accountId,
|
|
67
|
+
specialty,
|
|
68
|
+
createdAt: now,
|
|
69
|
+
updatedAt: now,
|
|
70
|
+
items: [],
|
|
71
|
+
};
|
|
72
|
+
for (const i of items) apply(t, i);
|
|
73
|
+
rows.push(t);
|
|
74
|
+
return { template: t, created: true };
|
|
75
|
+
},
|
|
76
|
+
async putItem(actor, id, input) {
|
|
77
|
+
const t = rows.find((r) => r.id === id && visible(actor, r));
|
|
78
|
+
if (!t) throw new NotFoundError("nope");
|
|
79
|
+
apply(t, input);
|
|
80
|
+
return t;
|
|
81
|
+
},
|
|
82
|
+
async deleteItem(actor, id, kind, key) {
|
|
83
|
+
const t = rows.find((r) => r.id === id && visible(actor, r));
|
|
84
|
+
if (!t) throw new NotFoundError("nope");
|
|
85
|
+
t.items = t.items.filter((i) => !(i.kind === kind && i.key === key));
|
|
86
|
+
},
|
|
87
|
+
async delete(actor, id) {
|
|
88
|
+
const i = rows.findIndex((r) => r.id === id && visible(actor, r));
|
|
89
|
+
if (i < 0) throw new NotFoundError("nope");
|
|
90
|
+
rows.splice(i, 1);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return { service, rows, secrets };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function setup(
|
|
97
|
+
opts: { isAdmin?: boolean; scope?: CallerScope } = {},
|
|
98
|
+
): { app: Hono<AdminUIEnv> } & ReturnType<typeof fakeService> {
|
|
99
|
+
const svc = fakeService();
|
|
100
|
+
const app = new Hono<AdminUIEnv>();
|
|
101
|
+
const requireAuth = (async (c, next) => {
|
|
102
|
+
c.set("userEmail", "u@x.com");
|
|
103
|
+
c.set("isAdmin", opts.isAdmin ?? true);
|
|
104
|
+
await next();
|
|
105
|
+
}) as MiddlewareHandler<AdminUIEnv>;
|
|
106
|
+
registerAdminTemplatesRoutes(app, {
|
|
107
|
+
requireAuth,
|
|
108
|
+
templateService: svc.service,
|
|
109
|
+
callerScopeResolver: async () =>
|
|
110
|
+
opts.scope ?? { kind: "scoped", accountId: null, agentIds: [] },
|
|
111
|
+
accounts: {
|
|
112
|
+
listWithCounts: async () =>
|
|
113
|
+
[
|
|
114
|
+
{ id: "acct-1", name: "Acme" },
|
|
115
|
+
{ id: "acct-2", name: "Globex" },
|
|
116
|
+
] as never,
|
|
117
|
+
getWithCounts: async (id: string) =>
|
|
118
|
+
({ id, name: id === "acct-1" ? "Acme" : "Globex" }) as never,
|
|
119
|
+
},
|
|
120
|
+
specialtyRegistry: {
|
|
121
|
+
listTypes: () =>
|
|
122
|
+
SPECIALTIES.map((name) => ({ name, displayName: `Type ${name}` })),
|
|
123
|
+
},
|
|
124
|
+
html: (content, o) =>
|
|
125
|
+
new Response(content, {
|
|
126
|
+
status: o?.status ?? 200,
|
|
127
|
+
headers: { "Content-Type": "text/html" },
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
return { app, ...svc };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const BASE = "/admin/settings/templates";
|
|
134
|
+
const form = (fields: Record<string, string>) => ({
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
137
|
+
body: new URLSearchParams(fields).toString(),
|
|
138
|
+
});
|
|
139
|
+
const member: CallerScope = {
|
|
140
|
+
kind: "scoped",
|
|
141
|
+
accountId: "acct-1",
|
|
142
|
+
agentIds: [],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
describe("/admin/settings/templates smoke", () => {
|
|
146
|
+
it("renders the page with the scope picker for an admin", async () => {
|
|
147
|
+
const { app } = setup();
|
|
148
|
+
const res = await app.request(BASE);
|
|
149
|
+
expect(res.status).toBe(200);
|
|
150
|
+
const html = await res.text();
|
|
151
|
+
expect(html).toContain("Deployment-wide");
|
|
152
|
+
expect(html).toContain("Acme");
|
|
153
|
+
expect(html).toContain("Globex");
|
|
154
|
+
expect(html).toContain("All agent types");
|
|
155
|
+
expect(html).toContain("Type reviewer");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("creates a deployment-wide secret env var and shows it masked", async () => {
|
|
159
|
+
const { app, rows, secrets } = setup();
|
|
160
|
+
const res = await app.request(
|
|
161
|
+
`${BASE}/items`,
|
|
162
|
+
form({
|
|
163
|
+
accountId: "",
|
|
164
|
+
specialty: "",
|
|
165
|
+
kind: "env",
|
|
166
|
+
key: "API_KEY",
|
|
167
|
+
value: "s3cr3t",
|
|
168
|
+
secret: "1",
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
expect(res.status).toBe(302);
|
|
172
|
+
expect(rows[0]).toMatchObject({ accountId: null, specialty: null });
|
|
173
|
+
expect(secrets.get("t1:API_KEY")).toBe("s3cr3t");
|
|
174
|
+
const page = await app.request(res.headers.get("location") as string);
|
|
175
|
+
const html = await page.text();
|
|
176
|
+
expect(html).toContain("API_KEY");
|
|
177
|
+
expect(html).toContain('value="***"');
|
|
178
|
+
expect(html).not.toContain("s3cr3t");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("updates, then removes an item, then deletes the template", async () => {
|
|
182
|
+
const { app, rows } = setup();
|
|
183
|
+
const scope = { accountId: "acct-2", specialty: "reviewer" };
|
|
184
|
+
await app.request(
|
|
185
|
+
`${BASE}/items`,
|
|
186
|
+
form({ ...scope, kind: "tool", key: "Bash", enabled: "1" }),
|
|
187
|
+
);
|
|
188
|
+
await app.request(
|
|
189
|
+
`${BASE}/items`,
|
|
190
|
+
form({ ...scope, kind: "plugin", key: "p@m", version: "1.2" }),
|
|
191
|
+
);
|
|
192
|
+
expect(rows).toHaveLength(1);
|
|
193
|
+
expect(rows[0]?.items.map((i) => i.key).sort()).toEqual(["Bash", "p@m"]);
|
|
194
|
+
const rm = await app.request(
|
|
195
|
+
`${BASE}/items/delete`,
|
|
196
|
+
form({ ...scope, kind: "tool", key: "Bash" }),
|
|
197
|
+
);
|
|
198
|
+
expect(rm.status).toBe(302);
|
|
199
|
+
expect(rows[0]?.items.map((i) => i.key)).toEqual(["p@m"]);
|
|
200
|
+
const del = await app.request(`${BASE}/delete`, form(scope));
|
|
201
|
+
expect(del.status).toBe(302);
|
|
202
|
+
expect(rows).toHaveLength(0);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("creates a cron item", async () => {
|
|
206
|
+
const { app, rows } = setup();
|
|
207
|
+
await app.request(
|
|
208
|
+
`${BASE}/items`,
|
|
209
|
+
form({
|
|
210
|
+
accountId: "",
|
|
211
|
+
specialty: "",
|
|
212
|
+
kind: "cron",
|
|
213
|
+
key: "digest",
|
|
214
|
+
schedule: "0 9 * * *",
|
|
215
|
+
prompt: "Summarize",
|
|
216
|
+
enabled: "1",
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
expect(rows[0]?.items[0]).toMatchObject({
|
|
220
|
+
kind: "cron",
|
|
221
|
+
key: "digest",
|
|
222
|
+
payload: { schedule: "0 9 * * *", prompt: "Summarize", enabled: true },
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("shows a denylisted env key error inline", async () => {
|
|
227
|
+
const { app, rows } = setup();
|
|
228
|
+
const res = await app.request(
|
|
229
|
+
`${BASE}/items`,
|
|
230
|
+
form({
|
|
231
|
+
accountId: "",
|
|
232
|
+
specialty: "",
|
|
233
|
+
kind: "env",
|
|
234
|
+
key: "SLACK_BOT_TOKEN",
|
|
235
|
+
value: "x",
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
expect(res.status).toBe(422);
|
|
239
|
+
const html = await res.text();
|
|
240
|
+
expect(html).toContain("alert-error");
|
|
241
|
+
expect(html).toContain("per-agent credential");
|
|
242
|
+
expect(rows).toHaveLength(0);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("shows an unknown specialty error inline", async () => {
|
|
246
|
+
const { app } = setup();
|
|
247
|
+
const res = await app.request(
|
|
248
|
+
`${BASE}/items`,
|
|
249
|
+
form({
|
|
250
|
+
accountId: "",
|
|
251
|
+
specialty: "ghost",
|
|
252
|
+
kind: "tool",
|
|
253
|
+
key: "Bash",
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
expect(res.status).toBe(422);
|
|
257
|
+
expect(await res.text()).toContain("unknown specialty ghost");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("offers an account member only their own account", async () => {
|
|
261
|
+
const { app } = setup({ isAdmin: false, scope: member });
|
|
262
|
+
const html = await (await app.request(BASE)).text();
|
|
263
|
+
expect(html).toContain("Acme");
|
|
264
|
+
expect(html).not.toContain("Globex");
|
|
265
|
+
expect(html).not.toContain("Deployment-wide");
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("pins member writes to their account and rejects other accounts", async () => {
|
|
269
|
+
const { app, rows } = setup({ isAdmin: false, scope: member });
|
|
270
|
+
const ok = await app.request(
|
|
271
|
+
`${BASE}/items`,
|
|
272
|
+
form({ accountId: "", specialty: "", kind: "tool", key: "Bash" }),
|
|
273
|
+
);
|
|
274
|
+
expect(ok.status).toBe(302);
|
|
275
|
+
expect(rows[0]?.accountId).toBe("acct-1");
|
|
276
|
+
const other = await app.request(
|
|
277
|
+
`${BASE}/items`,
|
|
278
|
+
form({ accountId: "acct-2", specialty: "", kind: "tool", key: "Bash" }),
|
|
279
|
+
);
|
|
280
|
+
expect(other.status).toBe(403);
|
|
281
|
+
expect((await app.request(`${BASE}?accountId=acct-2`)).status).toBe(403);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("403s a non-admin without an account", async () => {
|
|
285
|
+
const { app } = setup({ isAdmin: false });
|
|
286
|
+
expect((await app.request(BASE)).status).toBe(403);
|
|
287
|
+
expect(
|
|
288
|
+
(await app.request(`${BASE}/items`, form({ kind: "tool", key: "x" })))
|
|
289
|
+
.status,
|
|
290
|
+
).toBe(403);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-templates.ts
|
|
3
|
+
* GET/POST /admin/settings/templates — the Settings > Templates editor
|
|
4
|
+
* (ATP-2.3). A thin UI over AgentTemplateService (the same service behind the
|
|
5
|
+
* ATP-1.3 /templates API), called directly with the same actor rules: platform
|
|
6
|
+
* admins edit every scope (including deployment-wide); an account member sees
|
|
7
|
+
* and edits only their own account's scopes; everyone else gets 403. Service
|
|
8
|
+
* errors (denylisted env key, unknown specialty, bad payload) are shown inline.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Context, Hono, MiddlewareHandler } from "hono";
|
|
12
|
+
import { accountIdFromScope } from "./account-agent-create.ts";
|
|
13
|
+
import type { AccountService } from "./accounts.ts";
|
|
14
|
+
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
15
|
+
import {
|
|
16
|
+
ADMIN_TEMPLATES_PATH as BASE,
|
|
17
|
+
renderTemplatesPage,
|
|
18
|
+
type TemplateItemRow,
|
|
19
|
+
type TemplateScopeOption,
|
|
20
|
+
} from "./admin-ui-templates-pages.ts";
|
|
21
|
+
import {
|
|
22
|
+
AGENT_TEMPLATE_ITEM_KINDS,
|
|
23
|
+
type AgentTemplateItemKind,
|
|
24
|
+
} from "./agent-template-items.ts";
|
|
25
|
+
import type {
|
|
26
|
+
AgentTemplateService,
|
|
27
|
+
TemplateActor,
|
|
28
|
+
TemplateItemInput,
|
|
29
|
+
TemplateView,
|
|
30
|
+
} from "./agent-templates.ts";
|
|
31
|
+
import type { CallerScopeResolver } from "./caller-scope.ts";
|
|
32
|
+
import { ApiError, ForbiddenError } from "./errors.ts";
|
|
33
|
+
import type { SpecialtyTypeResolver } from "./specialty-types.ts";
|
|
34
|
+
|
|
35
|
+
export interface AdminTemplatesRouteDeps {
|
|
36
|
+
requireAuth: MiddlewareHandler<AdminUIEnv>;
|
|
37
|
+
templateService: Pick<
|
|
38
|
+
AgentTemplateService,
|
|
39
|
+
"list" | "replace" | "putItem" | "deleteItem" | "delete"
|
|
40
|
+
>;
|
|
41
|
+
callerScopeResolver: CallerScopeResolver;
|
|
42
|
+
/** Optional: without it admins can only pick deployment-wide. */
|
|
43
|
+
accounts?: Pick<AccountService, "listWithCounts" | "getWithCounts">;
|
|
44
|
+
specialtyRegistry: Pick<SpecialtyTypeResolver, "listTypes">;
|
|
45
|
+
html: (content: string, opts?: { status?: number }) => Response;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const NOTICES: Record<string, string> = {
|
|
49
|
+
saved: "Saved.",
|
|
50
|
+
removed: "Item removed.",
|
|
51
|
+
deleted: "Template deleted.",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const isKind = (v: string): v is AgentTemplateItemKind =>
|
|
55
|
+
(AGENT_TEMPLATE_ITEM_KINDS as readonly string[]).includes(v);
|
|
56
|
+
|
|
57
|
+
interface Scope {
|
|
58
|
+
/** "" = deployment-wide. */
|
|
59
|
+
accountId: string;
|
|
60
|
+
/** "" = every agent type. */
|
|
61
|
+
specialty: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function registerAdminTemplatesRoutes(
|
|
65
|
+
app: Hono<AdminUIEnv>,
|
|
66
|
+
deps: AdminTemplatesRouteDeps,
|
|
67
|
+
): void {
|
|
68
|
+
async function resolveActor(c: Context<AdminUIEnv>): Promise<TemplateActor> {
|
|
69
|
+
if (c.var.isAdmin === true) return { kind: "admin" };
|
|
70
|
+
const accountId = accountIdFromScope(
|
|
71
|
+
await deps.callerScopeResolver(c.var.userEmail, false),
|
|
72
|
+
);
|
|
73
|
+
if (accountId === null) {
|
|
74
|
+
throw new ForbiddenError("Admin or account access required");
|
|
75
|
+
}
|
|
76
|
+
return { kind: "account", accountId };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Account members are pinned to their account; naming another is 403. */
|
|
80
|
+
function resolveScope(
|
|
81
|
+
actor: TemplateActor,
|
|
82
|
+
accountId: string,
|
|
83
|
+
specialty: string,
|
|
84
|
+
): Scope {
|
|
85
|
+
if (actor.kind === "account") {
|
|
86
|
+
if (accountId !== "" && accountId !== actor.accountId) {
|
|
87
|
+
throw new ForbiddenError(
|
|
88
|
+
"cannot manage another account's or deployment-wide templates",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return { accountId: actor.accountId, specialty };
|
|
92
|
+
}
|
|
93
|
+
return { accountId, specialty };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function findTemplate(
|
|
97
|
+
actor: TemplateActor,
|
|
98
|
+
scope: Scope,
|
|
99
|
+
): Promise<TemplateView | undefined> {
|
|
100
|
+
const templates = await deps.templateService.list(actor, {
|
|
101
|
+
...(scope.accountId !== "" ? { accountId: scope.accountId } : {}),
|
|
102
|
+
...(scope.specialty !== "" ? { specialty: scope.specialty } : {}),
|
|
103
|
+
});
|
|
104
|
+
return templates.find(
|
|
105
|
+
(t) =>
|
|
106
|
+
(t.accountId ?? "") === scope.accountId &&
|
|
107
|
+
(t.specialty ?? "") === scope.specialty,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function accountOptions(
|
|
112
|
+
actor: TemplateActor,
|
|
113
|
+
): Promise<TemplateScopeOption[]> {
|
|
114
|
+
if (actor.kind === "account") {
|
|
115
|
+
const acct = await deps.accounts?.getWithCounts(actor.accountId);
|
|
116
|
+
return [{ value: actor.accountId, label: acct?.name ?? actor.accountId }];
|
|
117
|
+
}
|
|
118
|
+
const accounts = (await deps.accounts?.listWithCounts()) ?? [];
|
|
119
|
+
return [
|
|
120
|
+
{ value: "", label: "Deployment-wide (all accounts)" },
|
|
121
|
+
...accounts.map((a) => ({ value: a.id, label: a.name })),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function specialtyOptions(): TemplateScopeOption[] {
|
|
126
|
+
return [
|
|
127
|
+
{ value: "", label: "All agent types" },
|
|
128
|
+
...deps.specialtyRegistry
|
|
129
|
+
.listTypes()
|
|
130
|
+
.map((t) => ({ value: t.name, label: t.displayName })),
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function renderPage(
|
|
135
|
+
c: Context<AdminUIEnv>,
|
|
136
|
+
actor: TemplateActor,
|
|
137
|
+
scope: Scope,
|
|
138
|
+
flash: { error?: string; notice?: string; status?: number } = {},
|
|
139
|
+
): Promise<Response> {
|
|
140
|
+
const template = await findTemplate(actor, scope);
|
|
141
|
+
return deps.html(
|
|
142
|
+
renderTemplatesPage({
|
|
143
|
+
userEmail: c.var.userEmail,
|
|
144
|
+
accountOptions: await accountOptions(actor),
|
|
145
|
+
specialtyOptions: specialtyOptions(),
|
|
146
|
+
accountId: scope.accountId,
|
|
147
|
+
specialty: scope.specialty,
|
|
148
|
+
items: (template?.items ?? []) as TemplateItemRow[],
|
|
149
|
+
templateExists: template !== undefined,
|
|
150
|
+
...(flash.error ? { error: flash.error } : {}),
|
|
151
|
+
...(flash.notice ? { notice: flash.notice } : {}),
|
|
152
|
+
}),
|
|
153
|
+
{ status: flash.status ?? 200 },
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const field = (form: FormData, name: string) =>
|
|
158
|
+
(form.get(name)?.toString() ?? "").trim();
|
|
159
|
+
const flag = (form: FormData, name: string) => form.get(name) !== null;
|
|
160
|
+
const orNull = (v: string) => (v === "" ? null : v);
|
|
161
|
+
|
|
162
|
+
function itemFromForm(form: FormData): TemplateItemInput {
|
|
163
|
+
const kind = field(form, "kind");
|
|
164
|
+
if (!isKind(kind)) throw new ApiError(422, `unknown item kind ${kind}`);
|
|
165
|
+
const key = field(form, "key");
|
|
166
|
+
switch (kind) {
|
|
167
|
+
case "env":
|
|
168
|
+
return {
|
|
169
|
+
kind,
|
|
170
|
+
key,
|
|
171
|
+
// Not trimmed: a value's whitespace is the user's business.
|
|
172
|
+
payload: {
|
|
173
|
+
value: form.get("value")?.toString() ?? "",
|
|
174
|
+
secret: flag(form, "secret"),
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
case "tool":
|
|
178
|
+
return { kind, key, payload: { enabled: flag(form, "enabled") } };
|
|
179
|
+
case "plugin":
|
|
180
|
+
return {
|
|
181
|
+
kind,
|
|
182
|
+
key,
|
|
183
|
+
payload: {
|
|
184
|
+
version: orNull(field(form, "version")),
|
|
185
|
+
enabled: flag(form, "enabled"),
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
case "cron":
|
|
189
|
+
return {
|
|
190
|
+
kind,
|
|
191
|
+
key,
|
|
192
|
+
payload: {
|
|
193
|
+
schedule: field(form, "schedule"),
|
|
194
|
+
prompt: field(form, "prompt"),
|
|
195
|
+
channel: orNull(field(form, "channel")),
|
|
196
|
+
user: orNull(field(form, "user")),
|
|
197
|
+
preCheck: orNull(field(form, "preCheck")),
|
|
198
|
+
silent: flag(form, "silent"),
|
|
199
|
+
enabled: flag(form, "enabled"),
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Runs a mutation; service errors render inline, success redirects. */
|
|
206
|
+
async function mutate(
|
|
207
|
+
c: Context<AdminUIEnv>,
|
|
208
|
+
notice: string,
|
|
209
|
+
run: (actor: TemplateActor, scope: Scope, form: FormData) => Promise<void>,
|
|
210
|
+
): Promise<Response> {
|
|
211
|
+
let actor: TemplateActor;
|
|
212
|
+
try {
|
|
213
|
+
actor = await resolveActor(c);
|
|
214
|
+
} catch {
|
|
215
|
+
return new Response("Forbidden", { status: 403 });
|
|
216
|
+
}
|
|
217
|
+
let form: FormData;
|
|
218
|
+
try {
|
|
219
|
+
form = await c.req.formData();
|
|
220
|
+
} catch {
|
|
221
|
+
form = new FormData();
|
|
222
|
+
}
|
|
223
|
+
const requested = {
|
|
224
|
+
accountId: field(form, "accountId"),
|
|
225
|
+
specialty: field(form, "specialty"),
|
|
226
|
+
};
|
|
227
|
+
let scope: Scope;
|
|
228
|
+
try {
|
|
229
|
+
scope = resolveScope(actor, requested.accountId, requested.specialty);
|
|
230
|
+
} catch {
|
|
231
|
+
return new Response("Forbidden", { status: 403 });
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
await run(actor, scope, form);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
if (err instanceof ApiError && err.statusCode < 500) {
|
|
237
|
+
return renderPage(c, actor, scope, {
|
|
238
|
+
error: err.message,
|
|
239
|
+
status: err.statusCode,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
throw err;
|
|
243
|
+
}
|
|
244
|
+
const qs = new URLSearchParams({
|
|
245
|
+
...(scope.accountId !== "" ? { accountId: scope.accountId } : {}),
|
|
246
|
+
...(scope.specialty !== "" ? { specialty: scope.specialty } : {}),
|
|
247
|
+
notice,
|
|
248
|
+
});
|
|
249
|
+
return c.redirect(`${BASE}?${qs}`, 302);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
app.get(BASE, deps.requireAuth, async (c) => {
|
|
253
|
+
let actor: TemplateActor;
|
|
254
|
+
try {
|
|
255
|
+
actor = await resolveActor(c);
|
|
256
|
+
} catch {
|
|
257
|
+
return new Response("Forbidden", { status: 403 });
|
|
258
|
+
}
|
|
259
|
+
let scope: Scope;
|
|
260
|
+
try {
|
|
261
|
+
scope = resolveScope(
|
|
262
|
+
actor,
|
|
263
|
+
c.req.query("accountId")?.trim() ?? "",
|
|
264
|
+
c.req.query("specialty")?.trim() ?? "",
|
|
265
|
+
);
|
|
266
|
+
} catch {
|
|
267
|
+
return new Response("Forbidden", { status: 403 });
|
|
268
|
+
}
|
|
269
|
+
const key = c.req.query("notice");
|
|
270
|
+
return renderPage(c, actor, scope, {
|
|
271
|
+
...(key && NOTICES[key] ? { notice: NOTICES[key] } : {}),
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
app.post(`${BASE}/items`, deps.requireAuth, (c) =>
|
|
276
|
+
mutate(c, "saved", async (actor, scope, form) => {
|
|
277
|
+
const item = itemFromForm(form);
|
|
278
|
+
const template = await findTemplate(actor, scope);
|
|
279
|
+
if (template) {
|
|
280
|
+
await deps.templateService.putItem(actor, template.id, item);
|
|
281
|
+
} else {
|
|
282
|
+
await deps.templateService.replace(
|
|
283
|
+
actor,
|
|
284
|
+
{
|
|
285
|
+
accountId: scope.accountId === "" ? null : scope.accountId,
|
|
286
|
+
specialty: scope.specialty === "" ? null : scope.specialty,
|
|
287
|
+
},
|
|
288
|
+
[item],
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
app.post(`${BASE}/items/delete`, deps.requireAuth, (c) =>
|
|
295
|
+
mutate(c, "removed", async (actor, scope, form) => {
|
|
296
|
+
const kind = field(form, "kind");
|
|
297
|
+
if (!isKind(kind)) throw new ApiError(422, `unknown item kind ${kind}`);
|
|
298
|
+
const template = await findTemplate(actor, scope);
|
|
299
|
+
if (!template) throw new ApiError(404, "template not found");
|
|
300
|
+
await deps.templateService.deleteItem(
|
|
301
|
+
actor,
|
|
302
|
+
template.id,
|
|
303
|
+
kind,
|
|
304
|
+
field(form, "key"),
|
|
305
|
+
);
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
app.post(`${BASE}/delete`, deps.requireAuth, (c) =>
|
|
310
|
+
mutate(c, "deleted", async (actor, scope) => {
|
|
311
|
+
const template = await findTemplate(actor, scope);
|
|
312
|
+
if (!template) throw new ApiError(404, "template not found");
|
|
313
|
+
await deps.templateService.delete(actor, template.id);
|
|
314
|
+
}),
|
|
315
|
+
);
|
|
316
|
+
}
|
package/src/admin-ui.ts
CHANGED
|
@@ -52,6 +52,8 @@ import {
|
|
|
52
52
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
53
53
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
54
54
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
55
|
+
import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
|
|
56
|
+
import type { AgentTemplateService } from "./agent-templates.ts";
|
|
55
57
|
import {
|
|
56
58
|
type GithubAccessPreviewView,
|
|
57
59
|
renderGithubAccessError,
|
|
@@ -437,6 +439,14 @@ export interface AdminUIDeps {
|
|
|
437
439
|
* (additive): when absent the Settings page and its nav entry are not
|
|
438
440
|
* registered.
|
|
439
441
|
*/
|
|
442
|
+
/**
|
|
443
|
+
* ATP-2.3: the template service behind Settings > Templates. Optional;
|
|
444
|
+
* absent → no /admin/settings/templates routes.
|
|
445
|
+
*/
|
|
446
|
+
templateService?: Pick<
|
|
447
|
+
AgentTemplateService,
|
|
448
|
+
"list" | "replace" | "putItem" | "deleteItem" | "delete"
|
|
449
|
+
>;
|
|
440
450
|
githubEnterpriseApi?: (
|
|
441
451
|
path: string,
|
|
442
452
|
init?: RequestInit,
|
|
@@ -855,6 +865,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
855
865
|
accountCreatedNotifier,
|
|
856
866
|
accountServices,
|
|
857
867
|
githubEnterpriseApi,
|
|
868
|
+
templateService,
|
|
858
869
|
agentsApi,
|
|
859
870
|
specialtyRegistry = new SpecialtyTypes(),
|
|
860
871
|
specialtyDefaults,
|
|
@@ -3706,6 +3717,19 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3706
3717
|
});
|
|
3707
3718
|
}
|
|
3708
3719
|
|
|
3720
|
+
// ─── Template editor (ATP-2.3) ───────────────────────────────────────────
|
|
3721
|
+
|
|
3722
|
+
if (templateService) {
|
|
3723
|
+
registerAdminTemplatesRoutes(app, {
|
|
3724
|
+
requireAuth,
|
|
3725
|
+
templateService,
|
|
3726
|
+
callerScopeResolver,
|
|
3727
|
+
...(accountServices ? { accounts: accountServices.accounts } : {}),
|
|
3728
|
+
specialtyRegistry,
|
|
3729
|
+
html,
|
|
3730
|
+
});
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3709
3733
|
// ─── Account page (SSP-3.2) ───────────────────────────────────────────────
|
|
3710
3734
|
|
|
3711
3735
|
if (accountServices) {
|