@app-vitals/agent-admin 1.46.0 → 1.47.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.
|
|
3
|
+
"version": "1.47.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.47.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-extension.ts
CHANGED
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
* agentDetailCards(ctx) — extra cards on the agent detail page, each placed
|
|
25
25
|
* in the header or the Configuration group
|
|
26
26
|
* backgroundPasses(ctx) — interval loops, started after the platform sweepers
|
|
27
|
+
* settingsNavItems(ctx) — extra settings-sidebar entries, each naming the
|
|
28
|
+
* section it joins (an unknown section is appended).
|
|
29
|
+
* Merged into the nav with mergeSettingsNavItems
|
|
30
|
+
* (admin-ui-settings-layout.ts, also exported from
|
|
31
|
+
* server.ts with renderSettingsLayout). A throwing
|
|
32
|
+
* hook is logged and contributes nothing
|
|
27
33
|
* specialtyDefaults(name) — a specialty's default crons/tools/plugins. Like
|
|
28
34
|
* serviceIntegrations it needs no context and is
|
|
29
35
|
* collected before the services are built; the cron
|
|
@@ -196,6 +202,15 @@ export interface AdminOpenApiContribution {
|
|
|
196
202
|
};
|
|
197
203
|
}
|
|
198
204
|
|
|
205
|
+
/** One settings-sidebar entry contributed by an extension. */
|
|
206
|
+
export interface SettingsNavContribution {
|
|
207
|
+
/** Label of the section to join; an unknown label appends a new section. */
|
|
208
|
+
section: string;
|
|
209
|
+
label: string;
|
|
210
|
+
path: string;
|
|
211
|
+
adminOnly?: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
199
214
|
export interface AdminExtension {
|
|
200
215
|
name?: string;
|
|
201
216
|
/** See the header: env-only, resolved before the provisioner is built. */
|
|
@@ -209,6 +224,7 @@ export interface AdminExtension {
|
|
|
209
224
|
adminUiRoutes?(ctx: AdminExtensionContext): AdminRouteContribution[];
|
|
210
225
|
agentDetailCards?(ctx: AdminExtensionContext): AgentDetailCardSlot[];
|
|
211
226
|
backgroundPasses?(ctx: AdminExtensionContext): AdminBackgroundPass[];
|
|
227
|
+
settingsNavItems?(ctx: AdminExtensionContext): SettingsNavContribution[];
|
|
212
228
|
openApi?(): AdminOpenApiContribution;
|
|
213
229
|
}
|
|
214
230
|
|
|
@@ -219,6 +235,7 @@ export const ADMIN_EXTENSION_HOOK_ORDER = [
|
|
|
219
235
|
"adminUiRoutes",
|
|
220
236
|
"agentDetailCards",
|
|
221
237
|
"backgroundPasses",
|
|
238
|
+
"settingsNavItems",
|
|
222
239
|
] as const;
|
|
223
240
|
|
|
224
241
|
export interface ResolvedAdminExtensions {
|
|
@@ -230,6 +247,7 @@ export interface ResolvedAdminExtensions {
|
|
|
230
247
|
adminUiRoutes: AdminRouteContribution[];
|
|
231
248
|
agentDetailCards: AgentDetailCardSlot[];
|
|
232
249
|
backgroundPasses: AdminBackgroundPass[];
|
|
250
|
+
settingsNavItems: SettingsNavContribution[];
|
|
233
251
|
}
|
|
234
252
|
|
|
235
253
|
/**
|
|
@@ -248,6 +266,17 @@ export function resolveAdminExtensions(
|
|
|
248
266
|
const adminUiRoutes = collect((ext) => ext.adminUiRoutes?.(ctx));
|
|
249
267
|
const agentDetailCards = collect((ext) => ext.agentDetailCards?.(ctx));
|
|
250
268
|
const backgroundPasses = collect((ext) => ext.backgroundPasses?.(ctx));
|
|
269
|
+
const settingsNavItems = extensions.flatMap((ext) => {
|
|
270
|
+
try {
|
|
271
|
+
return ext.settingsNavItems?.(ctx) ?? [];
|
|
272
|
+
} catch (err) {
|
|
273
|
+
console.error(
|
|
274
|
+
`[admin] extension "${ext.name ?? "unnamed"}" settingsNavItems failed:`,
|
|
275
|
+
err,
|
|
276
|
+
);
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
251
280
|
const agentPhaseMethodologyService = services
|
|
252
281
|
.map((s) => s.agentPhaseMethodologyService)
|
|
253
282
|
.filter((svc) => svc !== undefined)
|
|
@@ -265,6 +294,7 @@ export function resolveAdminExtensions(
|
|
|
265
294
|
adminUiRoutes,
|
|
266
295
|
agentDetailCards,
|
|
267
296
|
backgroundPasses,
|
|
297
|
+
settingsNavItems,
|
|
268
298
|
};
|
|
269
299
|
}
|
|
270
300
|
|
|
@@ -53,6 +53,7 @@ describe("resolveAdminExtensions", () => {
|
|
|
53
53
|
adminUiRoutes: [],
|
|
54
54
|
agentDetailCards: [],
|
|
55
55
|
backgroundPasses: [],
|
|
56
|
+
settingsNavItems: [],
|
|
56
57
|
});
|
|
57
58
|
});
|
|
58
59
|
|
|
@@ -88,6 +89,10 @@ describe("resolveAdminExtensions", () => {
|
|
|
88
89
|
calls.push(`${id}:backgroundPasses:${c === ctx}`);
|
|
89
90
|
return [];
|
|
90
91
|
},
|
|
92
|
+
settingsNavItems: (c) => {
|
|
93
|
+
calls.push(`${id}:settingsNavItems:${c === ctx}`);
|
|
94
|
+
return [];
|
|
95
|
+
},
|
|
91
96
|
openApi: () => {
|
|
92
97
|
calls.push(`${id}:openApi`);
|
|
93
98
|
return {};
|
|
@@ -105,16 +110,74 @@ describe("resolveAdminExtensions", () => {
|
|
|
105
110
|
expect(calls.some((c) => c.endsWith(":openApi"))).toBe(false);
|
|
106
111
|
});
|
|
107
112
|
|
|
108
|
-
it("pins the hook order: services first,
|
|
113
|
+
it("pins the hook order: services first, settings nav items last", () => {
|
|
109
114
|
expect([...ADMIN_EXTENSION_HOOK_ORDER]).toEqual([
|
|
110
115
|
"services",
|
|
111
116
|
"apiRoutes",
|
|
112
117
|
"adminUiRoutes",
|
|
113
118
|
"agentDetailCards",
|
|
114
119
|
"backgroundPasses",
|
|
120
|
+
"settingsNavItems",
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("settingsNavItems: concatenates in extension order and passes adminOnly through", () => {
|
|
125
|
+
const resolved = resolveAdminExtensions(
|
|
126
|
+
[
|
|
127
|
+
{
|
|
128
|
+
settingsNavItems: () => [
|
|
129
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
{},
|
|
133
|
+
{
|
|
134
|
+
settingsNavItems: (c) => [
|
|
135
|
+
{ section: c === ctx ? "B" : "?", label: "b1", path: "/b1" },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
ctx,
|
|
140
|
+
);
|
|
141
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
142
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
143
|
+
{ section: "B", label: "b1", path: "/b1" },
|
|
115
144
|
]);
|
|
116
145
|
});
|
|
117
146
|
|
|
147
|
+
it("settingsNavItems: a throwing hook is logged and skipped, others unaffected", () => {
|
|
148
|
+
const errSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
149
|
+
try {
|
|
150
|
+
const resolved = resolveAdminExtensions(
|
|
151
|
+
[
|
|
152
|
+
{
|
|
153
|
+
settingsNavItems: () => {
|
|
154
|
+
throw new Error("boom");
|
|
155
|
+
},
|
|
156
|
+
backgroundPasses: () => [
|
|
157
|
+
{
|
|
158
|
+
name: "p",
|
|
159
|
+
logPrefix: "[p]",
|
|
160
|
+
intervalMs: 1,
|
|
161
|
+
tick: async () => {},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
settingsNavItems: () => [{ section: "S", label: "l", path: "/l" }],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
ctx,
|
|
170
|
+
);
|
|
171
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
172
|
+
{ section: "S", label: "l", path: "/l" },
|
|
173
|
+
]);
|
|
174
|
+
expect(resolved.backgroundPasses).toHaveLength(1);
|
|
175
|
+
expect(errSpy).toHaveBeenCalledTimes(1);
|
|
176
|
+
} finally {
|
|
177
|
+
errSpy.mockRestore();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
118
181
|
it("concatenates list contributions in extension order", () => {
|
|
119
182
|
const app = new Hono();
|
|
120
183
|
const pass = (name: string): AdminBackgroundPass => ({
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
mergeSettingsNavItems,
|
|
4
|
+
renderSettingsLayout,
|
|
5
|
+
type SettingsNav,
|
|
6
|
+
} from "./admin-ui-settings-layout.ts";
|
|
7
|
+
|
|
8
|
+
const base = (): SettingsNav => ({
|
|
9
|
+
sections: [
|
|
10
|
+
{ label: "General", items: [{ label: "Profile", path: "/p" }] },
|
|
11
|
+
{ label: "Org", items: [{ label: "Members", path: "/m" }] },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("mergeSettingsNavItems", () => {
|
|
16
|
+
it("appends into the section with a matching label", () => {
|
|
17
|
+
const out = mergeSettingsNavItems(base(), [
|
|
18
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
19
|
+
]);
|
|
20
|
+
expect(out.sections.map((s) => s.label)).toEqual(["General", "Org"]);
|
|
21
|
+
expect(out.sections[0]?.items).toEqual([
|
|
22
|
+
{ label: "Profile", path: "/p" },
|
|
23
|
+
{ label: "Extra", path: "/x" },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("appends a new section at the end for an unknown label", () => {
|
|
28
|
+
const out = mergeSettingsNavItems(base(), [
|
|
29
|
+
{ section: "Coding", label: "A", path: "/a" },
|
|
30
|
+
{ section: "Coding", label: "B", path: "/b" },
|
|
31
|
+
]);
|
|
32
|
+
expect(out.sections.map((s) => s.label)).toEqual([
|
|
33
|
+
"General",
|
|
34
|
+
"Org",
|
|
35
|
+
"Coding",
|
|
36
|
+
]);
|
|
37
|
+
expect(out.sections[2]?.items.map((i) => i.label)).toEqual(["A", "B"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("does not mutate the input", () => {
|
|
41
|
+
const nav = base();
|
|
42
|
+
const snapshot = structuredClone(nav);
|
|
43
|
+
mergeSettingsNavItems(nav, [
|
|
44
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
45
|
+
{ section: "New", label: "N", path: "/n" },
|
|
46
|
+
]);
|
|
47
|
+
expect(nav).toEqual(snapshot);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("preserves adminOnly so non-admins do not see the item", () => {
|
|
51
|
+
const nav = mergeSettingsNavItems(base(), [
|
|
52
|
+
{ section: "Coding", label: "Secret", path: "/s", adminOnly: true },
|
|
53
|
+
]);
|
|
54
|
+
const render = (isAdmin: boolean) =>
|
|
55
|
+
renderSettingsLayout({
|
|
56
|
+
userName: "u",
|
|
57
|
+
title: "T",
|
|
58
|
+
nav,
|
|
59
|
+
active: "/p",
|
|
60
|
+
body: "",
|
|
61
|
+
isAdmin,
|
|
62
|
+
});
|
|
63
|
+
expect(render(false)).not.toContain("Secret");
|
|
64
|
+
expect(render(true)).toContain("Secret");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Styles live in baseStyles() between the "Settings layout" markers.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { SettingsNavContribution } from "./admin-extension.ts";
|
|
8
9
|
import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
9
10
|
|
|
10
11
|
export interface SettingsNavItem {
|
|
@@ -75,3 +76,26 @@ export function renderSettingsLayout(
|
|
|
75
76
|
</div>
|
|
76
77
|
</div>`;
|
|
77
78
|
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Appends contributed items into the section with the matching label (an
|
|
82
|
+
* unknown section is appended at the end). Pure: the input nav is not mutated.
|
|
83
|
+
*/
|
|
84
|
+
export function mergeSettingsNavItems(
|
|
85
|
+
nav: SettingsNav,
|
|
86
|
+
items: SettingsNavContribution[],
|
|
87
|
+
): SettingsNav {
|
|
88
|
+
const sections: SettingsNavSection[] = nav.sections.map((s) => ({
|
|
89
|
+
label: s.label,
|
|
90
|
+
items: [...s.items],
|
|
91
|
+
}));
|
|
92
|
+
for (const { section, ...item } of items) {
|
|
93
|
+
let target = sections.find((s) => s.label === section);
|
|
94
|
+
if (!target) {
|
|
95
|
+
target = { label: section, items: [] };
|
|
96
|
+
sections.push(target);
|
|
97
|
+
}
|
|
98
|
+
target.items.push(item);
|
|
99
|
+
}
|
|
100
|
+
return { sections };
|
|
101
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import * as server from "./server.ts";
|
|
3
|
+
|
|
4
|
+
describe("server.ts export surface", () => {
|
|
5
|
+
it("exports the settings layout helpers", () => {
|
|
6
|
+
expect(typeof server.renderSettingsLayout).toBe("function");
|
|
7
|
+
expect(typeof server.mergeSettingsNavItems).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("keeps existing exports", () => {
|
|
11
|
+
expect(typeof server.createAdminUIApp).toBe("function");
|
|
12
|
+
expect(typeof server.createAdminApp).toBe("function");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("type exports compile", () => {
|
|
16
|
+
const item: server.SettingsNavItem = { label: "l", path: "/l" };
|
|
17
|
+
const section: server.SettingsNavSection = { label: "s", items: [item] };
|
|
18
|
+
const nav: server.SettingsNav = { sections: [section] };
|
|
19
|
+
const c: server.SettingsNavContribution = {
|
|
20
|
+
section: "s",
|
|
21
|
+
label: "l",
|
|
22
|
+
path: "/l",
|
|
23
|
+
};
|
|
24
|
+
const ext: server.AdminExtension = { settingsNavItems: () => [c] };
|
|
25
|
+
const opts: server.RenderSettingsLayoutOptions = {
|
|
26
|
+
userName: "u",
|
|
27
|
+
title: "t",
|
|
28
|
+
nav,
|
|
29
|
+
active: "/l",
|
|
30
|
+
body: "",
|
|
31
|
+
};
|
|
32
|
+
expect(server.renderSettingsLayout(opts)).toContain("l");
|
|
33
|
+
expect(ext.settingsNavItems).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
package/src/server.ts
CHANGED
|
@@ -48,3 +48,18 @@ export { HttpGoogleAuthClient } from "./google-auth-client.ts";
|
|
|
48
48
|
export type { GoogleAuthClient } from "./google-auth-client.ts";
|
|
49
49
|
export { PrismaClient } from "../prisma/client/client.ts";
|
|
50
50
|
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";
|